uros-b commented on code in PR #57629:
URL: https://github.com/apache/spark/pull/57629#discussion_r3689569135


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/InsertMapSortExpression.scala:
##########
@@ -42,8 +45,16 @@ object InsertMapSortInGroupingExpressions extends 
Rule[LogicalPlan] {
     if (!plan.containsPattern(AGGREGATE)) {
       return plan
     }
+    val normalizeDistinctAggregates =
+      conf.getConf(SQLConf.INSERT_MAP_SORT_IN_DISTINCT_AGGREGATES_ENABLED)
     val shouldRewrite = plan.exists {

Review Comment:
   This fast path now runs a full collect over every Aggregate's aggregate 
expressions for any query containing an aggregate, even when there's no map 
anywhere in the plan. Before, it only looked at groupingExpressions.dataType. 
Short-circuiting on the grouping expressions keeps the common case as cheap as 
it was:
   ```
   case agg: Aggregate =>
     agg.groupingExpressions.exists(mapTypeExistsRecursively) ||
       (normalizeDistinctAggregates &&
         
distinctAggregateChildren(agg.aggregateExpressions).exists(mapTypeExistsRecursively))
   ```



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