Description
When executing a query created with RelBuilder.values() that includes a projection, it will fail if it has been executed after another query which accesses an underlying data store (in this case, the SCOTT HSQL database).
Interesting, if you first perform the values query, then access the data store, and then perform the values query again, it works fine. It seems like in this case, the query is executed directly in-memory.
The test case pasted below fails with the exception:
org.apache.calcite.test.RelBuilderBugTest testRelBuilderProjectBug(org.apache.calcite.test.RelBuilderBugTest) Time elapsed: 0.186 sec <<< ERROR! java.sql.SQLException: exception while executing query: while executing SQL [SELECT "a" FROM (VALUES ('X', 1), ('Y', 2))] at org.apache.calcite.test.RelBuilderBugTest.testRelBuilderProjectBug(RelBuilderBugTest.java:65) Caused by: java.lang.RuntimeException: while executing SQL [SELECT "a" FROM (VALUES ('X', 1), ('Y', 2))] at org.apache.calcite.test.RelBuilderBugTest.testRelBuilderProjectBug(RelBuilderBugTest.java:65) Caused by: java.sql.SQLSyntaxErrorException: user lacks privilege or object not found: a at org.apache.calcite.test.RelBuilderBugTest.testRelBuilderProjectBug(RelBuilderBugTest.java:65) Caused by: org.hsqldb.HsqlException: user lacks privilege or object not found: a at org.apache.calcite.test.RelBuilderBugTest.testRelBuilderProjectBug(RelBuilderBugTest.java:65)
However, it only fails when run individually with:
mvn test -pl core -Dtest=RelBuilderBugTest
When run as part of the entire test suite, it passes, making one suspect that there might be some global state issue at play.
package org.apache.calcite.test; import org.apache.calcite.adapter.jdbc.JdbcSchema; import org.apache.calcite.jdbc.CalciteConnection; import org.apache.calcite.rel.RelNode; import org.apache.calcite.tools.FrameworkConfig; import org.apache.calcite.tools.Frameworks; import org.apache.calcite.tools.RelBuilder; import org.apache.calcite.tools.RelRunner; import org.junit.Test; import java.sql.Connection; import java.sql.DriverManager; import java.util.Properties; import javax.sql.DataSource; /** Test case for a RelBuilder bug */ public class RelBuilderBugTest { /** Tests a bug view. */ @Test public void testRelBuilderProjectBug() throws Exception { Class.forName("org.apache.calcite.jdbc.Driver"); Connection connection = DriverManager .getConnection("jdbc:calcite:", new Properties()); CalciteConnection conn = connection.unwrap(CalciteConnection.class); DataSource source = JdbcSchema.dataSource("jdbc:hsqldb:res:scott", "org.hsqldb.jdbcDriver", "SCOTT", "TIGER"); JdbcSchema schema = JdbcSchema.create(conn.getRootSchema(), "SCOTT", source, null, null); conn.getRootSchema().add("SCOTT", schema); FrameworkConfig config = Frameworks.newConfigBuilder() .defaultSchema(conn.getRootSchema()) .build(); RelBuilder builder = RelBuilder.create(config); RelRunner runner = conn.unwrap(RelRunner.class); RelNode values = builder.values(new String[]{"a", "b"}, "X", 1, "Y", 2) .project(builder.field("a")).build(); // run this *before* the scott query and it works fine // runner.prepare(values).executeQuery(); runner.prepare(builder.scan("SCOTT", "EMP").build()).executeQuery(); builder.clear(); // running this after the scott query causes the exception runner.prepare(values).executeQuery(); } }
Attachments
Issue Links
- is related to
-
CALCITE-1536 Initialize cluster before planner
- Open