更新时间:2023-11-18 23:22:58
您可以使用 collect_list
或 collect_set
函数:
You can use collect_list
or collect_set
functions:
import org.apache.spark.sql.functions.{collect_list, collect_set}
df.groupBy($"label").agg(collect_list($"term").alias("term"))
在 Spark
2.0 它需要 HiveContext
并且在 Spark 2.0+ 中你必须在 SessionBuilder
中启用 hive 支持.请参阅在 Spark SQL 中使用 collect_list 和 collect_set
In Spark < 2.0 it requires HiveContext
and in Spark 2.0+ you have to enable hive support in SessionBuilder
. See Use collect_list and collect_set in Spark SQL