stefankandic commented on code in PR #45549:
URL: https://github.com/apache/spark/pull/45549#discussion_r1535340224
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/Optimizer.scala:
##########
@@ -2469,3 +2470,25 @@ object RemoveRepetitionFromGroupExpressions extends
Rule[LogicalPlan] {
}
}
}
+
+/**
+ * Adds MapSort to group expressions containing map columns, as the key/value
paris need to be
+ * in the correct order before grouping:
+ * SELECT COUNT(*) FROM TABLE GROUP BY map_column =>
+ * SELECT COUNT(*) FROM TABLE GROUP BY map_sort(map_column)
+ */
+object InsertMapSortInGroupingExpressions extends Rule[LogicalPlan] {
+ override def apply(plan: LogicalPlan): LogicalPlan =
plan.transformWithPruning(
+ _.containsPattern(AGGREGATE), ruleId) {
+ case a @ Aggregate(groupingExpr, x, b) =>
+ val newGrouping = groupingExpr.map { expr =>
+ (expr, expr.dataType) match {
Review Comment:
i know i'm the one who suggested it but on a second thought it would
probably be more readable to just say
```
if (!expr.instanceOf[MapSort] && expr.dataType.instanceOf[MapType]) {
MapSort(expr)
else {
expr
}
```
but I'm fine if you want to keep it as is.
Or even just simplify it even further if we put it inside a once only batch
--
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]