Uploaded image for project: 'Calcite'
  1. Calcite
  2. CALCITE-1996

Executing RelBuilder.values with a projection sometimes fails

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 1.14.0
    • Fix Version/s: 1.15.0
    • Component/s: core
    • Labels:
      None
    • Environment:

      MacOS 10.12.6

      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:

      JUnit Test Output
       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.

      RelBuilderBugTest.java
      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

            Activity

              People

              • Assignee:
                julianhyde Julian Hyde
                Reporter:
                mprudhom Marc Prud'hommeaux
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: