@@ -129,8 +129,8 @@ class Analyzer(catalog: Catalog, registry: FunctionRegistry, caseSensitive: Bool
129
129
*/
130
130
object ResolveSortReferences extends Rule [LogicalPlan ] {
131
131
def apply (plan : LogicalPlan ): LogicalPlan = plan transformUp {
132
- case s@ Sort (ordering, p@ Project (projectList, child)) if ! s.resolved && p.resolved =>
133
- val unresolved = ordering.flatMap(_.collect { case UnresolvedAttribute (name) => name})
132
+ case s @ Sort (ordering, p @ Project (projectList, child)) if ! s.resolved && p.resolved =>
133
+ val unresolved = ordering.flatMap(_.collect { case UnresolvedAttribute (name) => name })
134
134
val resolved = unresolved.flatMap(child.resolveChildren)
135
135
val requiredAttributes = resolved.collect { case a : Attribute => a }.toSet
136
136
@@ -143,19 +143,19 @@ class Analyzer(catalog: Catalog, registry: FunctionRegistry, caseSensitive: Bool
143
143
} else {
144
144
s // Nothing we can do here. Return original plan.
145
145
}
146
- case s@ Sort (ordering, a@ Aggregate (grouping, aggs, child)) if ! s.resolved && a.resolved =>
147
- val unresolved = ordering.flatMap(_.collect { case UnresolvedAttribute (name) => name})
146
+ case s @ Sort (ordering, a @ Aggregate (grouping, aggs, child)) if ! s.resolved && a.resolved =>
147
+ val unresolved = ordering.flatMap(_.collect { case UnresolvedAttribute (name) => name })
148
148
// A small hack to create an object that will allow us to resolve any references that
149
149
// refer to named expressions that are present in the grouping expressions.
150
150
val groupingRelation = LocalRelation (
151
- grouping.collect { case ne : NamedExpression => ne.toAttribute}
151
+ grouping.collect { case ne : NamedExpression => ne.toAttribute }
152
152
)
153
153
154
154
logWarning(s " Grouping expressions: $groupingRelation" )
155
155
val resolved = unresolved.flatMap(groupingRelation.resolve).toSet
156
156
val missingInAggs = resolved -- a.outputSet
157
157
logWarning(s " Resolved: $resolved Missing in aggs: $missingInAggs" )
158
- if (missingInAggs.nonEmpty) {
158
+ if (missingInAggs.nonEmpty) {
159
159
// Add missing grouping exprs and then project them away after the sort.
160
160
Project (a.output,
161
161
Sort (ordering,
0 commit comments