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

java.lang.IndexOutOfBoundsException when building aggregate on top of project

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.14.0
    • 1.15.0
    • core
    • None

    Description

      The following test in RelBuilderTest:

        @Test public void testAggregateProjectWithAliases() {
          final RelBuilder builder = RelBuilder.create(config().build());
          RelNode root =
              builder.scan("EMP")
                  .project(builder.field("DEPTNO"))
                  .aggregate(builder.groupKey(builder.alias(builder.field("DEPTNO"), "departmentNo")))
                  .build();
          final String expected = ""
              + "LogicalAggregate(group=[{1}])\n" +
              "  LogicalProject(DEPTNO=[$0], departmentNo=[$0])\n" +
              "    LogicalProject(DEPTNO=[$7])\n" +
              "      LogicalTableScan(table=[[scott, EMP]])\n";
          assertThat(str(root), is(expected));
        }
      

      throws the following exception:

      java.lang.IndexOutOfBoundsException: index (1) must be less than size (1)
      
      	at com.google.common.base.Preconditions.checkElementIndex(Preconditions.java:310)
      	at com.google.common.base.Preconditions.checkElementIndex(Preconditions.java:293)
      	at com.google.common.collect.SingletonImmutableList.get(SingletonImmutableList.java:41)
      	at org.apache.calcite.rel.metadata.RelMdColumnUniqueness.areColumnsUnique(RelMdColumnUniqueness.java:206)
      	at GeneratedMetadataHandler_ColumnUniqueness.areColumnsUnique_$(Unknown Source)
      	at GeneratedMetadataHandler_ColumnUniqueness.areColumnsUnique(Unknown Source)
      	at org.apache.calcite.rel.metadata.RelMetadataQuery.areColumnsUnique(RelMetadataQuery.java:542)
      	at org.apache.calcite.rel.metadata.RelMetadataQuery.areColumnsUnique(RelMetadataQuery.java:522)
      	at org.apache.calcite.tools.RelBuilder.aggregate(RelBuilder.java:1067)
      	at org.apache.calcite.tools.RelBuilder.aggregate(RelBuilder.java:1046)
      	at org.apache.calcite.test.RelBuilderTest.testAggregateProjectWithAliases(RelBuilderTest.java:668)
      	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.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
      	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
      	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
      	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
      	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
      	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
      	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
      	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
      	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
      	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
      	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
      	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
      	at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
      	at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
      

      It is caused by the fact RelBuilder can check uniqueness on non-existing columns if groupKey in aggregate contains something more elaborate than a reference to the column in the underlying node. In this case it's an column alias but can also be some expression.

      Attachments

        Issue Links

          Activity

            People

              julianhyde Julian Hyde
              Pavel Gubin Pavel Gubin
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: