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

ArrayIndexOutOfBoundsException when deducing collation

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 1.0.0-incubating
    • Fix Version/s: 1.1.0-incubating
    • Component/s: None
    • Labels:
      None

      Description

      If a subquery has an ORDER BY on a column that is not in the SELECT list and the outer query does another ORDER BY, Calcite encounters an ArrayIndexOutOfBoundException when deducing collation.

      In PlannerTest, I created a simple test by first adding the following traits:

      	    List<RelTraitDef> traitDefs = new ArrayList<RelTraitDef>();
      	    traitDefs.add(ConventionTraitDef.INSTANCE);
      	    traitDefs.add(RelCollationTraitDef.INSTANCE);
      

      And ran the following query:

      select t.psPartkey from (select ps.psPartkey from `tpch`.`partsupp` ps order by ps.psSupplyCost) t order by t.psPartkey"
      
      java.lang.ArrayIndexOutOfBoundsException: -1
      	at org.apache.calcite.rex.RexProgram.deduceCollations(RexProgram.java:589)
      	at org.apache.calcite.rex.RexProgram.getCollations(RexProgram.java:558)
      	at org.apache.calcite.plan.RelOptUtil.createProject(RelOptUtil.java:2685)
      	at org.apache.calcite.plan.RelOptUtil.createProject(RelOptUtil.java:2623)
      	at org.apache.calcite.sql2rel.SqlToRelConverter.convertSelectList(SqlToRelConverter.java:3571)
      	at org.apache.calcite.sql2rel.SqlToRelConverter.convertSelectImpl(SqlToRelConverter.java:613)
      	at org.apache.calcite.sql2rel.SqlToRelConverter.convertSelect(SqlToRelConverter.java:568)
      	at org.apache.calcite.sql2rel.SqlToRelConverter.convertQueryRecursive(SqlToRelConverter.java:2929)
      	at org.apache.calcite.sql2rel.SqlToRelConverter.convertQuery(SqlToRelConverter.java:526)
      	at org.apache.calcite.prepare.PlannerImpl.convert(PlannerImpl.java:189)
      

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                julianhyde Julian Hyde
                Reporter:
                amansinha100 Aman Sinha
              • Votes:
                0 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: