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

IndexOutOfBoundsException when using LATERAL TABLE with more than one field

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.13.0
    • Component/s: core
    • Labels:
      None

      Description

      add a test case in SqlToRelConverterTest

      @Test public void testCollectionTableWithLateral3() {
          sql("select * from dept, lateral table(DEDUP(dept.deptno, dept.name))").ok();
        }
      

      I get an exception:

      java.lang.IndexOutOfBoundsException: Index: 1, Size: 1

      at java.util.ArrayList.rangeCheck(ArrayList.java:635)
      at java.util.ArrayList.get(ArrayList.java:411)
      at org.apache.calcite.sql2rel.SqlToRelConverter$LookupContext.findRel(SqlToRelConverter.java:4894)
      at org.apache.calcite.sql2rel.SqlToRelConverter$Blackboard.lookup(SqlToRelConverter.java:4122)
      at org.apache.calcite.sql2rel.SqlToRelConverter$Blackboard.lookupExp(SqlToRelConverter.java:4072)
      at org.apache.calcite.sql2rel.SqlToRelConverter.convertIdentifier(SqlToRelConverter.java:3419)
      at org.apache.calcite.sql2rel.SqlToRelConverter.access$1800(SqlToRelConverter.java:207)
      at org.apache.calcite.sql2rel.SqlToRelConverter$Blackboard.visit(SqlToRelConverter.java:4435)
      at org.apache.calcite.sql2rel.SqlToRelConverter$Blackboard.visit(SqlToRelConverter.java:3794)
      at org.apache.calcite.sql.SqlIdentifier.accept(SqlIdentifier.java:344)
      at org.apache.calcite.sql2rel.SqlToRelConverter$Blackboard.convertExpression(SqlToRelConverter.java:4328)
      at org.apache.calcite.sql2rel.StandardConvertletTable$11.convertCall(StandardConvertletTable.java:257)
      at org.apache.calcite.sql2rel.SqlNodeToRexConverterImpl.convertCall(SqlNodeToRexConverterImpl.java:61)
      at org.apache.calcite.sql2rel.SqlToRelConverter$Blackboard.visit(SqlToRelConverter.java:4426)
      at org.apache.calcite.sql2rel.SqlToRelConverter$Blackboard.visit(SqlToRelConverter.java:3794)
      at org.apache.calcite.sql.SqlCall.accept(SqlCall.java:137)
      at org.apache.calcite.sql2rel.SqlToRelConverter$Blackboard.convertExpression(SqlToRelConverter.java:4328)
      at org.apache.calcite.sql2rel.SqlToRelConverter.convertSelectList(SqlToRelConverter.java:3634)
      at org.apache.calcite.sql2rel.SqlToRelConverter.convertSelectImpl(SqlToRelConverter.java:659)
      at org.apache.calcite.sql2rel.SqlToRelConverter.convertSelect(SqlToRelConverter.java:616)
      at org.apache.calcite.sql2rel.SqlToRelConverter.convertQueryRecursive(SqlToRelConverter.java:2951)
      at org.apache.calcite.sql2rel.SqlToRelConverter.convertQuery(SqlToRelConverter.java:552)
      at org.apache.calcite.test.SqlToRelTestBase$TesterImpl.convertSqlToRel(SqlToRelTestBase.java:564)
      at org.apache.calcite.test.SqlToRelTestBase$TesterImpl.assertConvertsTo(SqlToRelTestBase.java:673)
      at org.apache.calcite.test.SqlToRelConverterTest$Sql.convertsTo(SqlToRelConverterTest.java:2413)
      at org.apache.calcite.test.SqlToRelConverterTest$Sql.ok(SqlToRelConverterTest.java:2409)
      at org.apache.calcite.test.SqlToRelConverterTest.testCollectionTableWithLateral3(SqlToRelConverterTest.java:896)

        Activity

        Hide
        godfreyhe godfrey he added a comment - - edited

        when a UDF or UDTF use more than one fields on LATERAL TABLE, there are more than one the correlation names also in SqlToRelConverterTest#getCorrelationUse method. The LogicalTableFunctionScan instance is changed(duplicated a new one, the code is in below), so it can not be found in LookupContext when doing flatten, and get IndexOutOfBoundsException.

        if (correlNames.size() > 1) {
              // The same table was referenced more than once.
              // So we deduplicate
              r = DeduplicateCorrelateVariables.go(rexBuilder, correlNames.get(0),
                  Util.skip(correlNames), r0);
            }
        
        Show
        godfreyhe godfrey he added a comment - - edited when a UDF or UDTF use more than one fields on LATERAL TABLE, there are more than one the correlation names also in SqlToRelConverterTest#getCorrelationUse method. The LogicalTableFunctionScan instance is changed(duplicated a new one, the code is in below), so it can not be found in LookupContext when doing flatten, and get IndexOutOfBoundsException. if (correlNames.size() > 1) { // The same table was referenced more than once. // So we deduplicate r = DeduplicateCorrelateVariables.go(rexBuilder, correlNames.get(0), Util.skip(correlNames), r0); }
        Hide
        julianhyde Julian Hyde added a comment -

        Good find! If you have a fix please submit a pull request with a test case.

        Show
        julianhyde Julian Hyde added a comment - Good find! If you have a fix please submit a pull request with a test case.
        Hide
        godfreyhe godfrey he added a comment -

        hi Julian Hyde, I submit a PR https://github.com/apache/calcite/pull/415

        Looking forward to your advice, thanks.

        Show
        godfreyhe godfrey he added a comment - hi Julian Hyde , I submit a PR https://github.com/apache/calcite/pull/415 Looking forward to your advice, thanks.
        Hide
        julianhyde Julian Hyde added a comment -
        Show
        julianhyde Julian Hyde added a comment - Fixed in http://git-wip-us.apache.org/repos/asf/calcite/commit/14ee9f35 . Thanks for the PR, godfrey he !
        Hide
        jcamachorodriguez Jesus Camacho Rodriguez added a comment -

        Resolved in release 1.13.0 (2017-06-26).

        Show
        jcamachorodriguez Jesus Camacho Rodriguez added a comment - Resolved in release 1.13.0 (2017-06-26).

          People

          • Assignee:
            julianhyde Julian Hyde
            Reporter:
            godfreyhe godfrey he
          • Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development