peng128 commented on code in PR #3057:
URL: https://github.com/apache/calcite/pull/3057#discussion_r1113758573
##########
core/src/main/java/org/apache/calcite/rel/rel2sql/SqlImplementor.java:
##########
@@ -1809,6 +1816,13 @@ private boolean needNewSubQuery(
return true;
}
+ if (rel instanceof Project
+ && clauses.contains(Clause.ORDER_BY)
+ && dialect.getConformance().isSortByOrdinal()) {
+ // Cannot merge a Project that contains sort by ordinal under it.
+ return hasSortByOrdinal();
+ }
Review Comment:
We found test case LatticeTest#testSum is failed in slow test.
These code is to fix it.
The reason of test case failure is that the project will be merged when the
sub-relnode is sort(change by
[CALCITE-4901](https://issues.apache.org/jira/browse/CALCITE-4901)).
For example,
If the relNode is
```
JdbcProject(C=[$1])
JdbcSort(sort0=[$1], dir0=[DESC], fetch=[1])
JdbcAggregate(group=[{0}], C=[$SUM0($7)])
JdbcTableScan(table=[[foodmart, sales_fact_1997]])
```
The result after merge project is
```
SELECT SUM(`sales_fact_1997`.`unit_sales`) AS `C`
FROM `foodmart`.`sales_fact_1997` AS `sales_fact_1997`
GROUP BY `sales_fact_1997`.`product_id`
ORDER BY 2 DESC
```
it's a incorrect sql, we want
```
SELECT `C` FROM (
SELECT `sales_fact_1997`.`product_id`, SUM(`sales_fact_1997`.`unit_sales`)
AS `C`
FROM `foodmart`.`sales_fact_1997` AS `sales_fact_1997`
GROUP BY `sales_fact_1997`.`product_id`
ORDER BY 2 DESC) t
```
So, these code to find out whether there is sort by original under project.
And don't merge project when there is sort by original under project.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]