Uploaded image for project: 'Hive'
  1. Hive
  2. HIVE-28560

AssertionError in SqlImplementor when query over JDBC table contains LIMIT

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 4.1.0
    • 4.1.0
    • CBO, JDBC
    • Security Level: Public (Viewable by anyone)

    Description

      To reproduce this, we need to create tpcds tables in postgres. q_test_tpcds_tables.sql contains create scripts for 3 tables. Copy this to hive/data/scripts/ directory.

      Add test.qto ql/src/test/queries/clientpositive/ and run 

      mvn test -pl itests/qtest  -Pitests -Dtest=TestMiniLlapLocalCliDriver -Dtest.output.overwrite=true -Dqfile=test.q

      When there's a limit 100 at the end, we can see the following error stack

      [INFO] Running org.apache.hadoop.hive.cli.TestMiniLlapLocalCliDriver
      [ERROR] Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 14.393 s <<< FAILURE! - in org.apache.hadoop.hive.cli.TestMiniLlapLocalCliDriver
      [ERROR] org.apache.hadoop.hive.cli.TestMiniLlapLocalCliDriver.testCliDriver[test]  Time elapsed: 6.735 s  <<< FAILURE!
      java.lang.AssertionError
          at org.apache.calcite.rel.rel2sql.SqlImplementor$Result.builder(SqlImplementor.java:1429)
          at org.apache.calcite.rel.rel2sql.SqlImplementor$Result.builder(SqlImplementor.java:1397)
          at org.apache.hadoop.hive.ql.optimizer.calcite.rules.jdbc.HiveJdbcImplementor.visit(HiveJdbcImplementor.java:91)
          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
          at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
          at java.lang.reflect.Method.invoke(Method.java:498)
          at org.apache.calcite.util.ReflectUtil$2.invoke(ReflectUtil.java:524)
          at org.apache.calcite.rel.rel2sql.RelToSqlConverter.dispatch(RelToSqlConverter.java:131)
          at org.apache.calcite.rel.rel2sql.RelToSqlConverter.visitInput(RelToSqlConverter.java:139)
          at org.apache.calcite.rel.rel2sql.SqlImplementor.visitInput(SqlImplementor.java:163)
          at org.apache.calcite.rel.rel2sql.SqlImplementor.visitInput(SqlImplementor.java:157)
          at org.apache.hadoop.hive.ql.optimizer.calcite.rules.jdbc.HiveJdbcImplementor.visit(HiveJdbcImplementor.java:55)
          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
          at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
          at java.lang.reflect.Method.invoke(Method.java:498)
          at org.apache.calcite.util.ReflectUtil$2.invoke(ReflectUtil.java:524)
          at org.apache.calcite.rel.rel2sql.RelToSqlConverter.dispatch(RelToSqlConverter.java:131)
          at org.apache.calcite.rel.rel2sql.RelToSqlConverter.visitInput(RelToSqlConverter.java:139)
          at org.apache.calcite.rel.rel2sql.SqlImplementor.visitInput(SqlImplementor.java:163)
          at org.apache.calcite.rel.rel2sql.SqlImplementor.visitInput(SqlImplementor.java:151)
          at org.apache.calcite.rel.rel2sql.SqlImplementor.visitRoot(SqlImplementor.java:131)
          at org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.jdbc.HiveJdbcConverter.generateSql(HiveJdbcConverter.java:117)
          at org.apache.hadoop.hive.ql.optimizer.calcite.translator.ASTBuilder.table(ASTBuilder.java:138)
          at org.apache.hadoop.hive.ql.optimizer.calcite.translator.ASTConverter.convertSource(ASTConverter.java:538)
          at org.apache.hadoop.hive.ql.optimizer.calcite.translator.ASTConverter.convert(ASTConverter.java:270)
          at org.apache.hadoop.hive.ql.optimizer.calcite.translator.ASTConverter.convertSource(ASTConverter.java:595)
          at org.apache.hadoop.hive.ql.optimizer.calcite.translator.ASTConverter.convert(ASTConverter.java:270)
          at org.apache.hadoop.hive.ql.optimizer.calcite.translator.ASTConverter.convert(ASTConverter.java:135)
          at org.apache.hadoop.hive.ql.parse.CalcitePlanner.getOptimizedAST(CalcitePlanner.java:1400)
          at org.apache.hadoop.hive.ql.parse.CalcitePlanner.genOPTree(CalcitePlanner.java:592)
          at org.apache.hadoop.hive.ql.parse.SemanticAnalyzer.analyzeInternal(SemanticAnalyzer.java:13164)
          at org.apache.hadoop.hive.ql.parse.CalcitePlanner.analyzeInternal(CalcitePlanner.java:466)
          at org.apache.hadoop.hive.ql.parse.BaseSemanticAnalyzer.analyze(BaseSemanticAnalyzer.java:332)
          at org.apache.hadoop.hive.ql.parse.ExplainSemanticAnalyzer.analyzeInternal(ExplainSemanticAnalyzer.java:180)
          at org.apache.hadoop.hive.ql.parse.BaseSemanticAnalyzer.analyze(BaseSemanticAnalyzer.java:332)
          at org.apache.hadoop.hive.ql.Compiler.analyze(Compiler.java:224)
          at org.apache.hadoop.hive.ql.Compiler.compile(Compiler.java:109)
          at org.apache.hadoop.hive.ql.Driver.compile(Driver.java:499)
          at org.apache.hadoop.hive.ql.Driver.compileInternal(Driver.java:451)
          at org.apache.hadoop.hive.ql.Driver.compileAndRespond(Driver.java:415)
          at org.apache.hadoop.hive.ql.Driver.compileAndRespond(Driver.java:409)
          at org.apache.hadoop.hive.ql.reexec.ReExecDriver.compileAndRespond(ReExecDriver.java:121)
          at org.apache.hadoop.hive.ql.reexec.ReExecDriver.run(ReExecDriver.java:229)
          at org.apache.hadoop.hive.cli.CliDriver.processLocalCmd(CliDriver.java:257)
          at org.apache.hadoop.hive.cli.CliDriver.processCmd1(CliDriver.java:201)
          at org.apache.hadoop.hive.cli.CliDriver.processCmd(CliDriver.java:127)
          at org.apache.hadoop.hive.cli.CliDriver.processLine(CliDriver.java:425)
          at org.apache.hadoop.hive.cli.CliDriver.processLine(CliDriver.java:356)
          at org.apache.hadoop.hive.ql.QTestUtil.executeClientInternal(QTestUtil.java:732)
          at org.apache.hadoop.hive.ql.QTestUtil.executeClient(QTestUtil.java:702)
          at org.apache.hadoop.hive.cli.control.CoreCliDriver.runTest(CoreCliDriver.java:116)
          at org.apache.hadoop.hive.cli.control.CliAdapter.runTest(CliAdapter.java:157)
          at org.apache.hadoop.hive.cli.TestMiniLlapLocalCliDriver.testCliDriver(TestMiniLlapLocalCliDriver.java:62)

      The issue here seems to be that at this point the expectedRel in SqlImplementor is a Project because Projects were added above this line, however, e is a Sort.

       

      The issue can also be reproduced with a minimal test case of

      --! qt:database:postgres:q_test_country_table.sql
      
      CREATE EXTERNAL TABLE country (id int, name varchar(20))
      STORED BY 'org.apache.hive.storage.jdbc.JdbcStorageHandler'
      TBLPROPERTIES (
          "hive.sql.database.type" = "POSTGRES",
          "hive.sql.jdbc.driver" = "org.postgresql.Driver",
          "hive.sql.jdbc.url" = "jdbc:postgresql://localhost:5432/qtestDB",
          "hive.sql.dbcp.username" = "qtestuser",
          "hive.sql.dbcp.password" = "qtestpassword",
          "hive.sql.table" = "country");
      
      EXPLAIN CBO SELECT * FROM country ORDER BY id LIMIT 2;
      EXPLAIN SELECT * FROM country ORDER BY id LIMIT 2;
      SELECT * FROM country ORDER BY id LIMIT 2;

      We can remove the overridden visit(Sort) in HiveJdbcImplementor and instead rely on Calcite's implementation to fix this issue.

       

      Attachments

        1. test.q
          4 kB
          Soumyakanti Das
        2. q_test_tpcds_tables.sql
          2 kB
          Soumyakanti Das

        Issue Links

          Activity

            People

              soumyakanti.das Soumyakanti Das
              soumyakanti.das Soumyakanti Das
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: