ostronaut commented on code in PR #49144:
URL: https://github.com/apache/spark/pull/49144#discussion_r1904196842


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/InsertMapSortExpression.scala:
##########
@@ -77,15 +71,56 @@ object InsertMapSortInGroupingExpressions extends 
Rule[LogicalPlan] {
             }.asInstanceOf[NamedExpression]
         }
         val newChild = Project(child.output ++ exprToMapSort.values, child)
-        val newAgg = Aggregate(newGroupingKeys, newAggregateExprs, newChild)
+        val newAgg = Aggregate(newGroupingKeys, newAggregateExprs, newChild, 
hint)
         newAgg -> agg.output.zip(newAgg.output)
     }
   }
+}
+
+/**
+ * Adds [[MapSort]] to [[RepartitionByExpression]] expressions containing map 
columns,
+ * as the key/value pairs need to be in the correct order before 
repartitioning:
+ *
+ * SELECT * FROM TABLE DISTRIBUTE BY map_column =>
+ * SELECT * FROM TABLE DISTRIBUTE BY map_sort(map_column)
+ */
+object InsertMapSortInRepartitionExpressions extends Rule[LogicalPlan] {

Review Comment:
   initially i wanted to do the same, but logic for 
`InsertMapSortInGroupingExpressions` and 
`InsertMapSortInRepartitionExpressions` is quite different: Grouping produced 
new output after applying the changes, while Repartition only updates existing 
`RepartitionByExpression` by replacing `partitionExpressions`. 
   Also, there is a dependency between `InsertMapSortInGroupingExpressions` and 
`PullOutGroupingExpressions`, as mentioned in [this 
comment](https://github.com/apache/spark/blob/master/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/Optimizer.scala#L320).
   For those reasons i decided to split them into separate Rules. But if you 
think performance saving from reduced traverse will be significant, we can 
combine those sure.



-- 
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: reviews-unsubscr...@spark.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to