Skip to content

Commit 6cfadd2

Browse files
committed
Actually, this issue has been fixed by 3684fd2.
1 parent d42b707 commit 6cfadd2

File tree

4 files changed

+19
-17
lines changed

4 files changed

+19
-17
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -209,10 +209,10 @@ class Analyzer(catalog: Catalog,
209209

210210
aggregateExprs.find { e =>
211211
!isValidAggregateExpression(e.transform {
212-
// Should trim aliases. These aliases can be introduced while resolving unnamed
213-
// expressions like `GetField` and UDF calls, and when a user explicitly assigns
214-
// an alias to a grouping expression in the SELECT clause.
215-
case a: Alias => a.child
212+
// Should trim aliases around `GetField`s. These aliases are introduced while
213+
// resolving struct field accesses, because `GetField` is not a `NamedExpression`.
214+
// (Should we just turn `GetField` into a `NamedExpression`?)
215+
case Alias(g: GetField, _) => g
216216
})
217217
}.foreach { e =>
218218
throw new TreeNodeException(plan, s"Expression not in GROUP BY: $e")

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/planning/patterns.scala

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,6 @@ object PartialAggregation {
143143
// referenced in the second aggregation.
144144
val namedGroupingExpressions: Map[Expression, NamedExpression] = groupingExpressions.map {
145145
case n: NamedExpression => (n, n)
146-
// TODO: When a UDF is used in the group by clause, for example, GROUP BY YEAR(...),
147-
// PartialGroup will not be a proper name.
148146
case other => (other, Alias(other, "PartialGroup")())
149147
}.toMap
150148

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

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -997,17 +997,6 @@ class SQLQuerySuite extends QueryTest with BeforeAndAfterAll {
997997
dropTempTable("data")
998998
}
999999

1000-
test("SPARK-4296 Grouping field with UDF as sub expression") {
1001-
registerFunction("triple", (_: Int) * 3)
1002-
jsonRDD(sparkContext.makeRDD("""{"a": 1}""" :: Nil)).registerTempTable("data")
1003-
checkAnswer(sql("SELECT triple(a) FROM data GROUP BY triple(a)"), 3)
1004-
dropTempTable("data")
1005-
1006-
jsonRDD(sparkContext.makeRDD("""{"a": 1}""" :: Nil)).registerTempTable("data")
1007-
checkAnswer(sql("SELECT triple(a) + 1 FROM data GROUP BY triple(a) + 1"), 4)
1008-
dropTempTable("data")
1009-
}
1010-
10111000
test("SPARK-4432 Fix attribute reference resolution error when using ORDER BY") {
10121001
checkAnswer(
10131002
sql("SELECT a + b FROM testData2 ORDER BY a"),

sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/SQLQuerySuite.scala

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,4 +214,19 @@ class SQLQuerySuite extends QueryTest {
214214
Seq.empty[Row])
215215
}
216216
}
217+
218+
test("SPARK-4296 Grouping field with Hive UDF as sub expression") {
219+
val rdd = sparkContext.makeRDD("""{"a": "str", "b":"1", "c":"1970-01-01 00:00:00"}""" :: Nil)
220+
jsonRDD(rdd).registerTempTable("data")
221+
checkAnswer(
222+
sql("SELECT concat(a, '-', b), year(c) FROM data GROUP BY concat(a, '-', b), year(c)"),
223+
Seq(Seq("str-1", 1970)))
224+
225+
dropTempTable("data")
226+
227+
jsonRDD(rdd).registerTempTable("data")
228+
checkAnswer(sql("SELECT year(c) + 1 FROM data GROUP BY year(c) + 1"), Seq(Seq(1971)))
229+
230+
dropTempTable("data")
231+
}
217232
}

0 commit comments

Comments
 (0)