cloud-fan commented on code in PR #39508:
URL: https://github.com/apache/spark/pull/39508#discussion_r1066895886


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala:
##########
@@ -1760,82 +1736,13 @@ class Analyzer(override val catalogManager: 
CatalogManager)
           Project(child.output, newFilter)
         }
 
-      // Same as Filter, Sort can host both grouping expressions/aggregate 
functions and missing
-      // attributes as well.
-      case s @ Sort(orders, _, child) if !s.resolved || 
s.missingInput.nonEmpty =>
-        val resolvedNoOuter = orders.map(resolveExpressionByPlanOutput(_, 
child))
-        val resolvedWithAgg = resolvedNoOuter.map(resolveColWithAgg(_, child))
-        val (newOrder, newChild) = 
resolveExprsAndAddMissingAttrs(resolvedWithAgg, child)
-        // Outer reference has lowermost priority. See the doc of 
`ResolveReferences`.
-        val ordering = newOrder.map(e => 
resolveOuterRef(e).asInstanceOf[SortOrder])
-        if (child.output == newChild.output) {
-          s.copy(order = ordering)
-        } else {
-          // Add missing attributes and then project them away.
-          val newSort = s.copy(order = ordering, child = newChild)
-          Project(child.output, newSort)
-        }
+      case s: Sort if !s.resolved || s.missingInput.nonEmpty => 
ResolveReferencesInSort(s)
 
       case q: LogicalPlan =>
         logTrace(s"Attempting to resolve 
${q.simpleString(conf.maxToStringFields)}")
         q.mapExpressions(resolveExpressionByPlanChildren(_, q, allowOuter = 
true))
     }
 
-    /**
-     * This method tries to resolve expressions and find missing attributes 
recursively.
-     * Specifically, when the expressions used in `Sort` or `Filter` contain 
unresolved attributes
-     * or resolved attributes which are missing from child output. This method 
tries to find the
-     * missing attributes and add them into the projection.
-     */
-    private def resolveExprsAndAddMissingAttrs(

Review Comment:
   these functions are pulled out to `ColumnResolutionHelper` without actual 
changes.



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