【发布时间】:2017-03-13 07:52:51
【问题描述】:
我有两个配置单元表A 和B 以及它们各自的数据框df_a 和df_b
A
+----+----- +-----------+
| id | name | mobile1 |
+----+----- +-----------+
| 1 | Matt | 123456798 |
+----+----- +-----------+
| 2 | John | 123456798 |
+----+----- +-----------+
| 3 | Lena | |
+----+----- +-----------+
B
+----+----- +-----------+
| id | name | mobile2 |
+----+----- +-----------+
| 3 | Lena | 123456798 |
+----+----- +-----------+
并且想要执行类似的操作
select A.name, nvl(nvl(A.mobile1, B.mobile2), 0) from A left outer join B on A.id = B.id
到目前为止,我想出了
df_a.join(df_b, df_a("id") <=> df_b("id"), "left_outer").select(?)
我不知道如何像在 Hive 查询中那样有条件地选择 mobile1 或 mobile2 或 0。
有人可以帮我解决这个问题吗?我正在使用 Spark 1.5。
【问题讨论】:
-
预期输出是什么?
-
@mtoto 这不是我写的确切查询,但我正在尝试检查表 A (df_a) 是否没有 moile no,那么它应该从表 B (df_b )。如果仍未找到,则将 0 设为手机号
标签: scala hadoop apache-spark hive