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

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

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 1.14.0
    • Fix Version/s: 1.15.0
    • Component/s: core
    • Labels:
      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.

        Issue Links

          Activity

          Hide
          julianhyde Julian Hyde added a comment -

          Resolved in release 1.15.0 (2017-12-11).

          Show
          julianhyde Julian Hyde added a comment - Resolved in release 1.15.0 (2017-12-11).
          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/2773c484 ; thanks for the PR, Pawel Ruchaj !
          Hide
          julianhyde Julian Hyde added a comment -

          I didn't notice your pull request, and wrote my own fix. I don't agree with your change to RelMetadataQuery: callers should not give column ordinals out of range.

          My fix is in my scratch branch https://github.com/julianhyde/calcite/commits/scratch, commit https://github.com/julianhyde/calcite/commit/59a343a63f3b1a64663fc2a21a1ffef525e98132. I will commit to master after 1.14 is released.

          Show
          julianhyde Julian Hyde added a comment - I didn't notice your pull request, and wrote my own fix. I don't agree with your change to RelMetadataQuery: callers should not give column ordinals out of range. My fix is in my scratch branch https://github.com/julianhyde/calcite/commits/scratch , commit https://github.com/julianhyde/calcite/commit/59a343a63f3b1a64663fc2a21a1ffef525e98132 . I will commit to master after 1.14 is released.

            People

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

              Dates

              • Created:
                Updated:
                Resolved:

                Development