【发布时间】:2020-06-22 10:18:42
【问题描述】:
我有一个带有单个数组结构列的数据框,我想在其中拆分嵌套值并添加为逗号分隔的字符串新列 示例数据框: 测试
{id:1,name:foo},{id:2,name:bar}
预期结果数据框
tests tests_id tests_name
[id:1,name:foo],[id:2,name:bar] 1, 2 foo, bar
我尝试了以下代码,但出现错误
df.withColumn("tests_name", concat_ws(",", explode(col("tests.name"))))
错误:
org.apache.spark.sql.AnalysisException: Generators are not supported when it's nested in expressions, but got: concat_ws(,, explode(tests.name AS `name`));
【问题讨论】:
-
能分享一下dataframe的schema吗,你用的是什么版本的spark?
标签: scala apache-spark pyspark apache-spark-sql explode