You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2022/03/22 10:43:33 UTC

[GitHub] [spark] ulysses-you commented on a change in pull request #35924: [SPARK-38578][SQL] Avoid unnecessary sort in FileFormatWriter if user has specified sort in AQE

ulysses-you commented on a change in pull request #35924:
URL: https://github.com/apache/spark/pull/35924#discussion_r832025751



##########
File path: sql/core/src/main/scala/org/apache/spark/sql/execution/adaptive/AQEUtils.scala
##########
@@ -57,4 +58,24 @@ object AQEUtils {
       }
     case _ => Some(UnspecifiedDistribution)
   }
+
+  // Analyze the given plan and calculate the required ordering of this plan w.r.t. the
+  // user-specified sort.
+  def getRequiredOrdering(p: SparkPlan): Seq[SortOrder] = p match {
+    case f: FilterExec => getRequiredOrdering(f.child)
+    case c: CollectMetricsExec => getRequiredOrdering(c.child)
+    // We do not need to care whether the sort is global or not, since the output partitioning
+    // is ensured by requiredDistribution.
+    case s: SortExec => s.outputOrdering
+    case p: ProjectExec =>
+      val requiredOrdering = getRequiredOrdering(p.child)
+      // avoid case `df.sort(a, b).select(c)`
+      if (requiredOrdering.forall(e => p.projectList.exists(_.semanticEquals(e)))) {
+        requiredOrdering

Review comment:
       This case has already converted which do not need to add back sort. Added some tests.




-- 
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-unsubscribe@spark.apache.org

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



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