cloud-fan commented on a change in pull request #34334:
URL: https://github.com/apache/spark/pull/34334#discussion_r733385010



##########
File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/PullOutComplexExpressions.scala
##########
@@ -75,6 +83,26 @@ object PullOutGroupingExpressions extends Rule[LogicalPlan] {
         } else {
           a
         }
+
+      case s: Sort if s.resolved && s.global =>
+        val complexSortingExpressionMap = 
mutable.LinkedHashMap.empty[Expression, NamedExpression]
+        s.order.map(_.child).foreach {
+          case e if !e.foldable && e.children.nonEmpty =>
+            complexSortingExpressionMap.put(e.canonicalized, Alias(e, 
"_sortingexpression")())
+          case o => o
+        }
+        if (complexSortingExpressionMap.nonEmpty) {
+          val newSortExpressions: Seq[SortOrder] = s.order.map { s =>
+            val newChild = 
complexSortingExpressionMap.get(s.child.canonicalized).map(_.toAttribute)
+              .getOrElse(s.child)
+            s.copy(child = newChild)
+          }
+          val newChild = Project(s.child.output ++ 
complexSortingExpressionMap.values, s.child)

Review comment:
       don't the extra columns increase the output data size and likely slow 
down the shuffle?




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