This is an automated email from the ASF dual-hosted git repository.
tanner pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/calcite.git
The following commit(s) were added to refs/heads/main by this push:
new 425a94d420 [CALCITE-6013] RelBuilder should simplify plan by pruning
unused measures
425a94d420 is described below
commit 425a94d420daf320a6f597816da0c0d8b6c485b3
Author: Tanner Clary <[email protected]>
AuthorDate: Mon Sep 18 11:12:23 2023 -0700
[CALCITE-6013] RelBuilder should simplify plan by pruning unused measures
---
.../org/apache/calcite/sql2rel/SqlToRelConverter.java | 3 ---
.../org/apache/calcite/test/SqlToRelConverterTest.java | 17 +++++++++++++++++
.../org/apache/calcite/test/SqlToRelConverterTest.xml | 16 +++++++++++++++-
3 files changed, 32 insertions(+), 4 deletions(-)
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 977a986cf4..f0dc70c0f1 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 @@ public class SqlToRelConverter {
for (SqlNode e : r.groupExprList) {
aggConverter.addGroupExpr(e);
}
- for (SqlNode e : r.measureExprList) {
- aggConverter.addMeasureExpr(e);
- }
final RexNode havingExpr;
final PairList<RexNode, String> 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 2e7efba9fd..a38ebf0b3b 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 @@ class SqlToRelConverterTest extends SqlToRelTestBase {
.ok();
}
+ /** Test case for:
+ * <a
href="https://issues.apache.org/jira/browse/CALCITE-6013">[CALCITE-6013]
+ * Unnecessary measures added as projects during rel construction</a>.
+ */
+ @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:
* <a
href="https://issues.apache.org/jira/browse/CALCITE-3310">[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 1085b724fa..b914e14dc7 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).
<![CDATA[
LogicalProject(EXPR$0=[ITEM(ITEM($3, 1).DETAIL.SKILLS, +(2, 3)).DESC])
LogicalTableScan(table=[[CATALOG, SALES, DEPT_NESTED]])
+]]>
+ </Resource>
+ </TestCase>
+ <TestCase name="testAvoidUnnecessaryMeasureProject">
+ <Resource name="sql">
+ <![CDATA[select deptno
+from empm
+group by deptno]]>
+ </Resource>
+ <Resource name="plan">
+ <![CDATA[
+LogicalAggregate(group=[{0}])
+ LogicalProject(DEPTNO=[$7])
+ LogicalTableScan(table=[[CATALOG, SALES, EMPM]])
]]>
</Resource>
</TestCase>
@@ -4502,7 +4516,7 @@ group by deptno]]>
<Resource name="plan">
<![CDATA[
LogicalAggregate(group=[{0}], C=[AGGREGATE($1)])
- LogicalProject(DEPTNO=[$7], COUNT_PLUS_100=[$9], COUNT_TIMES_100=[$10])
+ LogicalProject(DEPTNO=[$7], COUNT_PLUS_100=[$9])
LogicalTableScan(table=[[CATALOG, SALES, EMPM]])
]]>
</Resource>