【发布时间】:2021-12-26 12:12:00
【问题描述】:
假设我有以下 2 个要合并的表:
+---------+-------+---+---+---+
|month_key|account|ch1|ch2|ch5|
+---------+-------+---+---+---+
| Aug| abc| 0| 1| 1|
+---------+-------+---+---+---+
+---------+-------+---+---+---+
|month_key|account|ch3|ch4|ch5|
+---------+-------+---+---+---+
| Sept| bcd| 1| 1| 0|
+---------+-------+---+---+---+
我如何在进行并集时保留所有列?我这样做时得到以下结果:
df1.union(df2).show()
+---------+-------+---+---+---+
|month_key|account|ch1|ch2|ch5|
+---------+-------+---+---+---+
| Aug| abc| 0| 1| 1|
| Sept| bcd| 1| 1| 0|
+---------+-------+---+---+---+
在我的实际数据集中,我将拥有数百个通道,如果我需要列出所有常见列,我认为很难使用 join。
我使用的是 spark 版本 2.4.3。
我知道 unionByName 可以用于 spark 3.0 及更高版本,但有替代方案吗?
感谢您的帮助。
【问题讨论】:
-
This article 将为您提供您正在寻找的确切见解
标签: pyspark