假设我们有一个嵌套的PySpark dataframe df,其模式如下:
root
|-- a1: string (nullable = true)
|-- a2: string (nullable = true)
|-- arr1: array (nullable = true)
| |-- element: struct (containsNull = true)
| | |-- dt1: date (nullable = true)
| | |-- dt2: date (nullable = true)
| | |-- dt_indicator: boolean (nullable = true)假设我们有一个过程,在两个扁平的数据帧df1和df2中用以下模式将嵌套的数据frames扁平:
df1模式
root
|-- a1: string (nullable = true)
|-- a2: string (nullable = true)和
df2模式
|-- dt1: date (nullable = true)
|-- dt2: date (nullable = true)
|-- dt_indicator: boolean (nullable = true)有办法保持df2对df1的依赖吗?例如,如果a1发生变化,那么dt1和dt2可能会发生变化。在单个PySpark数据帧中很容易做到这一点。您能使用两个扁平的PySpark数据帧来完成这个任务吗?
发布于 2021-12-12 08:26:26
由于df1和df2是从df派生的,所以对df1所做的更改不会反映到df2上。
如果您通过引入一个df并在df1和df2中包含这个ID来唯一地标识monotonically_increasing_id中的行,那么您可以使用这个ID通过一个连接传播条件。
也就是说,在df上应用依赖转换,然后提取df1和df2,以避免不必要的连接,这将是有益的。
https://stackoverflow.com/questions/70320421
复制相似问题