Skip to content

Commit c00d517

Browse files
yhuaimarmbrus
authored andcommitted
[SPARK-4296][SQL] Trims aliases when resolving and checking aggregate expressions
I believe that SPARK-4296 has been fixed by 3684fd2. I am adding tests based apache#3910 (change the udf to HiveUDF instead). Author: Yin Huai <[email protected]> Author: Cheng Lian <[email protected]> Closes apache#4010 from yhuai/SPARK-4296-yin and squashes the following commits: 6343800 [Yin Huai] Merge remote-tracking branch 'upstream/master' into SPARK-4296-yin 6cfadd2 [Yin Huai] Actually, this issue has been fixed by 3684fd2. d42b707 [Yin Huai] Update comment. 8b3a274 [Yin Huai] Since expressions in grouping expressions can have aliases, which can be used by the outer query block, revert this change. 443538d [Cheng Lian] Trims aliases when resolving and checking aggregate expressions
1 parent c1b3eeb commit c00d517

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

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
@@ -267,4 +267,19 @@ class SQLQuerySuite extends QueryTest {
267267
sql("DROP TABLE nullValuesInInnerComplexTypes")
268268
dropTempTable("testTable")
269269
}
270+
271+
test("SPARK-4296 Grouping field with Hive UDF as sub expression") {
272+
val rdd = sparkContext.makeRDD( """{"a": "str", "b":"1", "c":"1970-01-01 00:00:00"}""" :: Nil)
273+
jsonRDD(rdd).registerTempTable("data")
274+
checkAnswer(
275+
sql("SELECT concat(a, '-', b), year(c) FROM data GROUP BY concat(a, '-', b), year(c)"),
276+
Row("str-1", 1970))
277+
278+
dropTempTable("data")
279+
280+
jsonRDD(rdd).registerTempTable("data")
281+
checkAnswer(sql("SELECT year(c) + 1 FROM data GROUP BY year(c) + 1"), Row(1971))
282+
283+
dropTempTable("data")
284+
}
270285
}

0 commit comments

Comments
 (0)