singhpk234 commented on a change in pull request #35924:
URL: https://github.com/apache/spark/pull/35924#discussion_r831779684
##########
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:
[question] can we handle aliasing as well.
For ex : `df.sort(a, b).select(col('a').as('x'))`
--
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]