You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@calcite.apache.org by "Pavel Gubin (JIRA)" <ji...@apache.org> on 2017/09/12 09:55:00 UTC

[jira] [Created] (CALCITE-1980) java.lang.IndexOutOfBoundsException when building aggregate on top of project

Pavel Gubin created CALCITE-1980:
------------------------------------

             Summary: java.lang.IndexOutOfBoundsException when building aggregate on top of project
                 Key: CALCITE-1980
                 URL: https://issues.apache.org/jira/browse/CALCITE-1980
             Project: Calcite
          Issue Type: Bug
          Components: core
    Affects Versions: 1.14.0
            Reporter: Pavel Gubin
            Assignee: Julian Hyde


The following test in RelBuilderTest:

{code:java}
  @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));
  }
{code}

throws the following exception: 

{noformat}
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)
{noformat}

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.



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)