maropu commented on a change in pull request #27058: [SPARK-30395][SQL] When 
one or more DISTINCT aggregate expressions operate on the same field, the 
DISTINCT aggregate expression allows the use of the FILTER clause
URL: https://github.com/apache/spark/pull/27058#discussion_r366140268
 
 

 ##########
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/CheckAnalysis.scala
 ##########
 @@ -207,6 +207,26 @@ trait CheckAnalysis extends PredicateHelper {
                 s"of type ${condition.dataType.catalogString} is not a 
boolean.")
 
           case Aggregate(groupingExprs, aggregateExprs, child) =>
+            val distinctAggregateExprs = aggregateExprs.flatMap(_.collect {
+              case ae: AggregateExpression if ae.isDistinct => ae
+            })
+            val distinctAggGroups = distinctAggregateExprs.groupBy { e =>
+              val unfoldableChildren = 
e.aggregateFunction.children.filter(!_.foldable).toSet
+              if (unfoldableChildren.nonEmpty) {
+                unfoldableChildren
+              } else {
+                e.aggregateFunction.children.take(1).toSet
 
 Review comment:
   Since this is duplicate code with `RewriteDistinctAggregates`, how about 
defining a helper function to extract distinct aggregate groups? e.g., 
`RewriteDistinctAggregates.extractDistinctAggregates`. I think it is difficult 
to understand this logic without [the 
comments](https://github.com/apache/spark/blob/master/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/RewriteDistinctAggregates.scala#L177-L183).

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

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

Reply via email to