Skip to content

Commit 8ad6897

Browse files
committed
bug gix
1 parent 3d4515f commit 8ad6897

File tree

2 files changed

+14
-13
lines changed

2 files changed

+14
-13
lines changed

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,7 @@ class Analyzer(
630630

631631
// Try resolving the ordering as though it is in the aggregate clause.
632632
try {
633-
val unresolvedSortOrders = sortOrder.filterNot(_.resolved)
633+
val unresolvedSortOrders = sortOrder.filter(s => !s.resolved || containsAggregate(s))
634634
val aliasedOrdering = unresolvedSortOrders.map(o => Alias(o.child, "aggOrder")())
635635
val aggregatedOrdering = aggregate.copy(aggregateExpressions = aliasedOrdering)
636636
val resolvedAggregate: Aggregate = execute(aggregatedOrdering).asInstanceOf[Aggregate]
@@ -664,10 +664,11 @@ class Analyzer(
664664
}
665665
}
666666

667-
val sortOrdersMap = unresolvedSortOrders.map(
668-
new TreeNodeRef(_)).zip(evaluatedOrderings).toMap
669-
val finalSortOrders = sortOrder.map(
670-
s => sortOrdersMap.getOrElse(new TreeNodeRef(s), s))
667+
val sortOrdersMap = unresolvedSortOrders
668+
.map(new TreeNodeRef(_))
669+
.zip(evaluatedOrderings)
670+
.toMap
671+
val finalSortOrders = sortOrder.map(s => sortOrdersMap.getOrElse(new TreeNodeRef(s), s))
671672

672673
// Since we don't rely on sort.resolved as the stop condition for this rule,
673674
// we need to check this and prevent applying this rule multiple times

sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/analysis/AnalysisSuite.scala

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -220,21 +220,21 @@ class AnalysisSuite extends AnalysisTest {
220220
// checkUDF(udf4, expected4)
221221
}
222222

223-
test("SPARK-11863 mixture of aliases and real columns in orderby clause - tpcds 19,55,71") {
223+
test("SPARK-11863 mixture of aliases and real columns in order by clause - tpcds 19,55,71") {
224224
val a = testRelation2.output(0)
225225
val c = testRelation2.output(2)
226226
val alias1 = a.as("a1")
227227
val alias2 = c.as("a2")
228228
val alias3 = count(a).as("a3")
229229

230-
val plan = testRelation2.
231-
groupBy('a, 'c) ('a.as("a1"), 'c.as("a2"), count('a).as("a3")).
232-
orderBy('a1.asc, 'c.asc)
230+
val plan = testRelation2
231+
.groupBy('a, 'c)('a.as("a1"), 'c.as("a2"), count('a).as("a3"))
232+
.orderBy('a1.asc, 'c.asc)
233233

234-
val expected = testRelation2.
235-
groupBy(a, c) (alias1, alias2, alias3).
236-
orderBy(alias1.toAttribute.asc, alias2.toAttribute.asc).
237-
select(alias1.toAttribute, alias2.toAttribute, alias3.toAttribute)
234+
val expected = testRelation2
235+
.groupBy(a, c)(alias1, alias2, alias3)
236+
.orderBy(alias1.toAttribute.asc, alias2.toAttribute.asc)
237+
.select(alias1.toAttribute, alias2.toAttribute, alias3.toAttribute)
238238
checkAnalysis(plan, expected)
239239
}
240240

0 commit comments

Comments
 (0)