我有一个带有单个数组struct column的dataframe,我想在其中拆分嵌套的值并作为逗号分隔的字符串添加新列示例dataframe:tests
{id:1,name:foo},{id:2,name:bar}
预期结果Dataframe
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`));
1条答案
按热度按时间sf6xfgos1#
取决于您使用的spark版本。假设Dataframe方案如下
Spark3.0.0
Spark2.4.0+
Spark<2.4
输出: