我需要弄平一个数据框,以便与Spark(Scala)中的另一个数据框一起加入。
基本上我的两个数据范围有以下模式:
df1
root
|-- field1: string (nullable = true)
|-- field2: long (nullable = true)
|-- field3: long (nullable = true)
|-- field4: long (nullable = true)
|-- field5: integer (nullable = true)
|-- field6: timestamp (nullable = true)
|-- field7: long (nullable = true)
|-- field8: long (nullable = true)
|-- field9: long (nullable = true)
|-- field10: integer (nullable = true)
df2
root
|-- field1: long (nullable = true)
|-- field2: long (nullable = true)
|-- field3: string (nullable = true)
|-- field4: integer (nullable = true)
|-- field5: array (nullable = true)
| |-- element: struct (containsNull = true)
| | |-- field6: long (nullable = true)
| | |-- field7: integer (nullable = true)
| | |-- field8: array (nullable = true)
| | | |-- element: struct (containsNull = true)
| | | | |-- field9: string (nullable = true)
| | | | |-- field10: integer (nullable = true)
|-- field11: timestamp (nullable = true)
老实说,我不知道如何使DF2弄平。最后,我需要在df.field4 = df2.field9
上加入2个数据范围我正在使用2.1.0
我的第一个想法是使用爆炸,但是在Spark 2.1.0中已经弃用了,有人对我有线索吗?
我的错误爆炸功能仍在spark 2.1.0中可用。
谢谢
您可以找到下面的代码:
val DF2Exploded1 = DF2.select(DF2("*"), functions.explode(DF2("field5"))
.alias("field5_exploded"))
val DF2Exploded2 = DF2Exploded1.select(DF2Exploded1("*"), functions.explode(DF2Exploded1("field5_exploded.field8"))
.alias("field8_exploded"))