morrySnow commented on code in PR #65206:
URL: https://github.com/apache/doris/pull/65206#discussion_r3628783493


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/NormalizeAggregate.java:
##########
@@ -447,6 +449,28 @@ private LogicalPlan normalizeAgg(LogicalAggregate<Plan> 
aggregate, Optional<Logi
                 having.get().withChildren(new 
LogicalProject<>(bottomProjectsBuilder.build(), newAggregate)));
     }
 
+    private List<NamedExpression> 
normalizeMultiColumnDistinctCount(List<NamedExpression> aggregateOutput) {
+        // Multi-column distinct counts treat arguments as a set. Remove 
duplicates and canonicalize equivalent
+        // counts to the first argument order so the structural equality used 
below can share one aggregate result.
+        Map<ImmutableSet<Expression>, Count> distinctArgumentsToCount = new 
HashMap<>();
+        return ExpressionUtils.rewriteDownShortCircuit(aggregateOutput, 
expression -> {
+            if (!(expression instanceof Count)) {
+                return expression;
+            }
+            Count count = (Count) expression;
+            if (!count.isDistinct() || count.arity() <= 1) {
+                return count;
+            }
+            ImmutableSet<Expression> distinctArguments = 
ImmutableSet.copyOf(count.getDistinctArguments());
+            Count normalizedCount = 
distinctArgumentsToCount.get(distinctArguments);
+            if (normalizedCount == null) {
+                normalizedCount = count.withDistinctAndChildren(true, 
ImmutableList.copyOf(distinctArguments));

Review Comment:
   it is ok



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/NormalizeAggregate.java:
##########
@@ -447,6 +449,28 @@ private LogicalPlan normalizeAgg(LogicalAggregate<Plan> 
aggregate, Optional<Logi
                 having.get().withChildren(new 
LogicalProject<>(bottomProjectsBuilder.build(), newAggregate)));
     }
 
+    private List<NamedExpression> 
normalizeMultiColumnDistinctCount(List<NamedExpression> aggregateOutput) {
+        // Multi-column distinct counts treat arguments as a set. Remove 
duplicates and canonicalize equivalent
+        // counts to the first argument order so the structural equality used 
below can share one aggregate result.
+        Map<ImmutableSet<Expression>, Count> distinctArgumentsToCount = new 
HashMap<>();
+        return ExpressionUtils.rewriteDownShortCircuit(aggregateOutput, 
expression -> {

Review Comment:
   it is ok



-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to