Используйте concat,concat_ws,collect_set
для указания разделителя в Spark SQL .
Example:
val df=Seq(("a",1),("a",3),("b",2)).toDF("id","sa")
df.createOrReplaceTempView("tmp")
spark.sql("""select concat('[', //concat with opening bracket
concat_ws(';', //custom delimiter
collect_set(sa)),
concat(']') //concat with closing bracket
) as cnct_deli
from tmp
group by id""").show()
Result:
+---------+
|cnct_deli|
+---------+
| [2]|
| [1;3]|
+---------+