mihaibudiu commented on code in PR #4983:
URL: https://github.com/apache/calcite/pull/4983#discussion_r3350708869
##########
core/src/main/java/org/apache/calcite/rel/rules/AggregateExpandDistinctAggregatesRule.java:
##########
@@ -315,11 +325,15 @@ private static RelBuilder
convertSingletonDistinct(RelBuilder relBuilder,
final ImmutableBitSet originalGroupSet = aggregate.getGroupSet();
// Add the distinct aggregate column(s) to the group-by columns,
- // if not already a part of the group-by
+ // if not already a part of the group-by. Also add any ORDER BY columns.
final NavigableSet<Integer> bottomGroups = new
TreeSet<>(aggregate.getGroupSet().asList());
for (AggregateCall aggCall : originalAggCalls) {
if (aggCall.isDistinct()) {
bottomGroups.addAll(aggCall.getArgList());
+ // Also include ORDER BY columns from WITHIN GROUP
+ for (RelFieldCollation fc : aggCall.collation.getFieldCollations()) {
Review Comment:
I think this is a better approach.
Can this add the same column twice? Is that a problem?
--
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]