Вы можете выполнить Left Join
на customer1 таблице, затем используя coalesce
на customer2 таблице, чтобы получить first non null value
для customername
столбца.
Пример :
scala> val customer1=Seq((1,"shiva","9994323565"),(2,"Mani","9994323567"),(3,"Sneha","9994323568")).toDF("customerid","customername","contact")
scala> val customer2=Seq((1,"shivamoorthy","9994323565"),(2,"Manikandan","9994323567")).toDF("customerid","customername","contact")
scala> customer1.as("c1")
.join(customer2.as("c2"),$"c1.customerid" === $"c2.customerid","left")
.selectExpr("c1.customerid",
"coalesce(c2.customername,c1.customername) as customername")
.show()
Результат:
+----------+------------+
|customerid|customername|
+----------+------------+
| 1|shivamoorthy|
| 2| Manikandan|
| 3| Sneha|
+----------+------------+