I have two hive tables A and B and their respective data frames df_a and df_b
A
+----+----- +-----------+
| id | name | mobile1 |
+----+----- +-----------+
| 1 | Matt | 123456798 |
+----+----- +-----------+
| 2 | John | 123456798 |
+----+----- +-----------+
| 3 | Lena | |
+----+----- +-----------+
B
+----+----- +-----------+
| id | name | mobile2 |
+----+----- +-----------+
| 3 | Lena | 123456798 |
+----+----- +-----------+
And want to perform an operation similar to
select A.name, nvl(nvl(A.mobile1, B.mobile2), 0) from A left outer join B on A.id = B.id
So far I've come up with
df_a.join(df_b, df_a("id") <=> df_b("id"), "left_outer").select(?)
I can't figure out how to conditionally select either mobile1 or mobile2 or 0 like I did in the Hive query.
Could someone please help me with this? I'm using Spark 1.5.