Skip to content

Commit b19b73c

Browse files
committed
fixed an issue in star expansion for group by
1 parent dacf2d8 commit b19b73c

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,7 @@ class Analyzer(
403403
} else {
404404
val expanded = a.aggregateExpressions.flatMap {
405405
case s: Star => s.expand(a.child, resolver)
406+
case u @ UnresolvedAlias(_: Star, _) => expandStarExpression(u.child, a.child) :: Nil
406407
case o if containsStar(o :: Nil) => expandStarExpression(o, a.child) :: Nil
407408
case o => o :: Nil
408409
}.map(_.asInstanceOf[NamedExpression])

sql/core/src/test/scala/org/apache/spark/sql/SQLQuerySuite.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -547,10 +547,10 @@ class SQLQuerySuite extends QueryTest with SharedSQLContext {
547547
test("Group By Ordinal: spark.sql.groupByOrdinal=false") {
548548
withSQLConf(SQLConf.GROUP_BY_ORDINAL.key -> "false") {
549549
// If spark.sql.groupByOrdinal=false, ignore the position number.
550-
// intercept[AnalysisException] {
551-
// sql("SELECT a, sum(b) FROM testData2 GROUP BY 1")
552-
// }
553-
// // '*' is not allowed to use in the select list when users specify ordinals in group by
550+
intercept[AnalysisException] {
551+
sql("SELECT a, sum(b) FROM testData2 GROUP BY 1")
552+
}
553+
// '*' is not allowed to use in the select list when users specify ordinals in group by
554554
checkAnswer(
555555
sql("SELECT * FROM testData2 GROUP BY a, b, 1"),
556556
sql("SELECT * FROM testData2 GROUP BY a, b"))

0 commit comments

Comments
 (0)