Github user gatorsmile commented on a diff in the pull request:

    https://github.com/apache/spark/pull/11153#discussion_r52627258
  
    --- Diff: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala
 ---
    @@ -572,98 +572,64 @@ class Analyzer(
           // Skip sort with aggregate. This will be handled in 
ResolveAggregateFunctions
           case sa @ Sort(_, _, child: Aggregate) => sa
     
    -      case s @ Sort(_, _, child) if !s.resolved && child.resolved =>
    -        val (newOrdering, missingResolvableAttrs) = 
collectResolvableMissingAttrs(s.order, child)
    -
    -        if (missingResolvableAttrs.isEmpty) {
    -          val unresolvableAttrs = s.order.filterNot(_.resolved)
    -          logDebug(s"Failed to find $unresolvableAttrs in 
${child.output.mkString(", ")}")
    -          s // Nothing we can do here. Return original plan.
    -        } else {
    -          // Add the missing attributes into projectList of Project/Window 
or
    -          //   aggregateExpressions of Aggregate, if they are in the 
inputSet
    -          //   but not in the outputSet of the plan.
    -          val newChild = child transformUp {
    -            case p: Project =>
    -              p.copy(projectList = p.projectList ++
    -                missingResolvableAttrs.filter((p.inputSet -- 
p.outputSet).contains))
    -            case w: Window =>
    -              w.copy(projectList = w.projectList ++
    -                missingResolvableAttrs.filter((w.inputSet -- 
w.outputSet).contains))
    -            case a: Aggregate =>
    -              val resolvableAttrs = 
missingResolvableAttrs.filter(a.groupingExpressions.contains)
    -              val notResolvedAttrs = 
resolvableAttrs.filterNot(a.aggregateExpressions.contains)
    -              val newAggregateExpressions = a.aggregateExpressions ++ 
notResolvedAttrs
    -              a.copy(aggregateExpressions = newAggregateExpressions)
    -            case o => o
    -          }
    -
    +      case s @ Sort(order, _, child) if !s.resolved && child.resolved =>
    +        val newOrder = order.map(resolveExpressionRecursively(_, 
child).asInstanceOf[SortOrder])
    +        val requiredAttrs = AttributeSet(newOrder).filter(_.resolved)
    +        val missingAttrs = requiredAttrs -- child.outputSet
    --- End diff --
    
    Since this solution could skip `Subquery`, we might need to add/change 
`qualifiers` for the missingAttrs, if necessary.  


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to