JiajunBernoulli commented on code in PR #2997:
URL: https://github.com/apache/calcite/pull/2997#discussion_r1052093557
##########
core/src/main/java/org/apache/calcite/rel/rel2sql/RelToSqlConverter.java:
##########
@@ -868,19 +867,35 @@ public Result visit(Sort e) {
if (hasTrickyRollup(e, aggregate)) {
// MySQL 5 does not support standard "GROUP BY ROLLUP(x, y)", only
// the non-standard "GROUP BY x, y WITH ROLLUP".
- // It does not allow "WITH ROLLUP" in combination with "ORDER BY",
- // but "GROUP BY x, y WITH ROLLUP" implicitly sorts by x, y,
+ List<Integer> rollupList =
Aggregate.Group.getRollup(aggregate.getGroupSets());
+ List<Integer> sortList = e.getCollation()
+ .getFieldCollations()
+ .stream()
+ .map(f -> aggregate.getGroupSet().nth(f.getFieldIndex()))
+ .collect(Collectors.toList());
+ // "GROUP BY x, y WITH ROLLUP" implicitly sorts by x, y,
// so skip the ORDER BY.
- final Set<Integer> groupList = new LinkedHashSet<>();
- for (RelFieldCollation fc : e.collation.getFieldCollations()) {
- groupList.add(aggregate.getGroupSet().nth(fc.getFieldIndex()));
- }
- groupList.addAll(Aggregate.Group.getRollup(aggregate.getGroupSets()));
+ boolean isImplicitlySort = rollupList.subList(0,
sortList.size()).equals(sortList);
Review Comment:
I didn't have this consciousness before, thank you for letting me learn.
--
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]