Skip to content

Commit

Permalink
[CALCITE-6013] RelBuilder should simplify plan by pruning unused meas…
Browse files Browse the repository at this point in the history
…ures
  • Loading branch information
tanclary committed Oct 24, 2023
1 parent e8b6480 commit 425a94d
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<RexNode, String> projects = PairList.of();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4690,6 +4690,23 @@ void checkUserDefinedOrderByOver(NullCollation nullCollation) {
.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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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>
Expand Down

0 comments on commit 425a94d

Please sign in to comment.