Github user viirya commented on a diff in the pull request:
https://github.com/apache/spark/pull/11298#discussion_r53902128
--- Diff:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala
---
@@ -607,14 +607,21 @@ class Analyzer(
def apply(plan: LogicalPlan): LogicalPlan = plan resolveOperators {
// Skip sort with aggregate. This will be handled in
ResolveAggregateFunctions
case sa @ Sort(_, _, child: Aggregate) => sa
-
+ case sa @ Sort(_, _, _)
+ if sa.order.exists(so =>
ResolveAggregateFunctions.containsAggregate(so.child)) => sa
case s @ Sort(order, _, child) if !s.resolved && child.resolved =>
try {
val newOrder = order.map(resolveExpressionRecursively(_,
child).asInstanceOf[SortOrder])
val requiredAttrs = AttributeSet(newOrder).filter(_.resolved)
val missingAttrs = requiredAttrs -- child.outputSet
- if (missingAttrs.nonEmpty) {
- // Add missing attributes and then project them away after the
sort.
+ // resolve the unresolved functions for knowing if they are
aggregate functions
+ val evaluatedSort =
+ ResolveFunctions.resolveFunctions(Sort(newOrder, s.global,
child)).asInstanceOf[Sort]
+ if (evaluatedSort.order.exists(so =>
+ ResolveAggregateFunctions.containsAggregate(so.child))) {
+ // Skip sort with aggregate. This will be handled in
ResolveAggregateFunctions
+ s.copy(order = evaluatedSort.order)
+ } else if (missingAttrs.nonEmpty) {
--- End diff --
Looks like if the sort order has non empty missingAttrs, it will be ignored
now.
---
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]