Hisoka-X commented on code in PR #42398:
URL: https://github.com/apache/spark/pull/42398#discussion_r1370043175
##########
sql/core/src/test/scala/org/apache/spark/sql/DataFrameAggregateSuite.scala:
##########
@@ -603,6 +603,41 @@ class DataFrameAggregateSuite extends QueryTest
)
}
+ test("listagg function") {
+ // normal case
+ val df = Seq(("a", "b"), ("b", "c"), ("c", "d")).toDF("a", "b")
+ checkAnswer(
+ df.selectExpr("listagg(a)", "listagg(b)"),
+ Seq(Row("a,b,c", "b,c,d"))
+ )
+ checkAnswer(
+ df.select(listagg($"a"), listagg($"b")),
+ Seq(Row("a,b,c", "b,c,d"))
+ )
+
+ // distinct case
+ val df2 = Seq(("a", "b"), ("a", "b"), ("b", "d")).toDF("a", "b")
+ checkAnswer(
+ df2.select(listagg_distinct($"a"), listagg_distinct($"b")),
+ Seq(Row("a,b", "b,d"))
+ )
+
+ // null case
+ val df3 = Seq(("a", "b", null), ("a", "b", null), (null, null,
null)).toDF("a", "b", "c")
+ checkAnswer(
+ df3.select(listagg_distinct($"a"), listagg($"a"),
listagg_distinct($"b"), listagg($"b"),
+ listagg($"c")),
+ Seq(Row("a", "a,a", "b", "b,b", ""))
+ )
+
+ // custom delimiter
+ val df4 = Seq(("a", "b"), ("b", "c"), ("c", "d")).toDF("a", "b")
+ checkAnswer(
+ df4.selectExpr("listagg(a, '|')", "listagg(b, '|')"),
+ Seq(Row("a|b|c", "b|c|d"))
+ )
+ }
Review Comment:
here
https://github.com/apache/spark/pull/42398/files#diff-7de447aae84ff6752e962b088c3f62e552db3b58a4be52b69ea65da82cba6c27R198-R200
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]