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

After calling RelBuilder.aggregate, cannot lookup field by name

    XMLWordPrintableJSON

    Details

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

      Description

      In RelBuilder, can't get group field by name: "field [ENAME] not found;".

      The regression is spotted in 1.22.0 RC 3. The test works fine in 1.21.0 branch.
      RelBuilderTest:

        @Test public void testGetGroupFieldByName() {
            final Function<RelBuilder, RelNode> f = builder -> {
                RelBuilder aggregated = builder.scan("EMP")
                    .project(builder.field("EMPNO"), builder.field("ENAME"), builder.field("SAL"))
                    .aggregate(
                        builder.groupKey(builder.field("ENAME")),
                        builder.sum(builder.field("SAL"))
                    );
                RexInputRef groupFieldReference = aggregated.field("ENAME");
                assertThat(groupFieldReference.getIndex(), is(0));
                return aggregated.build();
            };
      
            final String expected =
                "LogicalAggregate(group=[{1}], agg#0=[SUM($2)])\n" +
                "  LogicalProject(EMPNO=[$0], ENAME=[$1], SAL=[$5])\n" +
                "    LogicalTableScan(table=[[scott, EMP]])\n";
            assertThat(f.apply(createBuilder(c -> c)), hasTree(expected));
        }
      

      Error (1.22.0 RC 3):

      field [ENAME] not found; input fields are: [EMPNO, $f1]
      java.lang.IllegalArgumentException: field [ENAME] not found; input fields are: [EMPNO, $f1]
      	at org.apache.calcite.tools.RelBuilder.field(RelBuilder.java:402)
      	at org.apache.calcite.tools.RelBuilder.field(RelBuilder.java:385)
      	at org.apache.calcite.test.RelBuilderTest.lambda$testGetGroupFieldByName$15(RelBuilderTest.java:990)
      	at org.apache.calcite.test.RelBuilderTest.testGetGroupFieldByName(RelBuilderTest.java:999)
      	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                julianhyde Julian Hyde
                Reporter:
                anha Anton Haidai
              • Votes:
                0 Vote for this issue
                Watchers:
                8 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 0.5h
                  0.5h