如何在Spark中对嵌套的数据框进行平面映射 [英] How to flatmap a nested Dataframe in Spark
本文介绍了如何在Spark中对嵌套的数据框进行平面映射的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有嵌套的字符串,如下所示.我想对它们进行平面映射以在Spark中产生唯一的行
I have nested string like as shown below. I want to flat map them to produce unique rows in Spark
我的数据框具有
A,B,"x,y,z",D
我想将其转换为产生类似的输出
I want to convert it to produce output like
A,B,x,D
A,B,y,D
A,B,z,D
我该怎么做.
基本上我该如何做平面映射并在数据框内应用任何功能
Basically how can i do flat map and apply any function inside the Dataframe
谢谢
推荐答案
Spark 2.0 +
Dataset.flatMap
:
val ds = df.as[(String, String, String, String)]
ds.flatMap {
case (x1, x2, x3, x4) => x3.split(",").map((x1, x2, _, x4))
}.toDF
Spark 1.3 + .
查看全文