diff --git a/core/src/main/java/org/apache/calcite/sql2rel/SqlToRelConverter.java b/core/src/main/java/org/apache/calcite/sql2rel/SqlToRelConverter.java index 977a986cf40..f0dc70c0f1c 100644 --- a/core/src/main/java/org/apache/calcite/sql2rel/SqlToRelConverter.java +++ b/core/src/main/java/org/apache/calcite/sql2rel/SqlToRelConverter.java @@ -3402,9 +3402,6 @@ protected final void createAggImpl( for (SqlNode e : r.groupExprList) { aggConverter.addGroupExpr(e); } - for (SqlNode e : r.measureExprList) { - aggConverter.addMeasureExpr(e); - } final RexNode havingExpr; final PairList projects = PairList.of(); diff --git a/core/src/test/java/org/apache/calcite/test/SqlToRelConverterTest.java b/core/src/test/java/org/apache/calcite/test/SqlToRelConverterTest.java index 2e7efba9fdf..a38ebf0b3be 100644 --- a/core/src/test/java/org/apache/calcite/test/SqlToRelConverterTest.java +++ b/core/src/test/java/org/apache/calcite/test/SqlToRelConverterTest.java @@ -4690,6 +4690,23 @@ void checkUserDefinedOrderByOver(NullCollation nullCollation) { .ok(); } + /** Test case for: + * [CALCITE-6013] + * Unnecessary measures added as projects during rel construction. + */ + @Test void testAvoidUnnecessaryMeasureProject() { + final String sql = "select deptno\n" + + "from empm\n" + + "group by deptno"; + fixture() + .withFactory(c -> + c.withOperatorTable(t -> + SqlValidatorTest.operatorTableFor(SqlLibrary.CALCITE))) + .withCatalogReader(MockCatalogReaderExtended::create) + .withSql(sql) + .ok(); + } + /** Test case for: * [CALCITE-3310] * Approximate and exact aggregate calls are recognized as the same diff --git a/core/src/test/resources/org/apache/calcite/test/SqlToRelConverterTest.xml b/core/src/test/resources/org/apache/calcite/test/SqlToRelConverterTest.xml index 1085b724fa2..b914e14dc74 100644 --- a/core/src/test/resources/org/apache/calcite/test/SqlToRelConverterTest.xml +++ b/core/src/test/resources/org/apache/calcite/test/SqlToRelConverterTest.xml @@ -521,6 +521,20 @@ LogicalProject(EXPR$0=[ROW(ITEM(ITEM(ITEM(ITEM($3, 0), 'detail'), 'skills'), 0). + + + + + + + + @@ -4502,7 +4516,7 @@ group by deptno]]>