將一組基於來源資料表的更新、插入與刪除合併到目標資料表中。
語法
mergeInto(table: str, condition: Column)
參數
| 參數 | 類型 | 說明 |
|---|---|---|
table |
str | 要合併到的目標資料表名稱。 |
condition |
資料行 | 判斷目標資料表中某列是否與來源資料框中的一列相符的條件。 |
退貨
MergeIntoWriter: MergeIntoWriter 以進一步指定如何將來源資料框合併到目標資料表。
Examples
from pyspark.sql.functions import expr
source = spark.createDataFrame(
[(14, "Tom"), (23, "Alice"), (16, "Bob")], ["id", "name"])
(source.mergeInto("target", "id")
.whenMatched().update({ "name": source.name })
.whenNotMatched().insertAll()
.whenNotMatchedBySource().delete()
.merge())