マージイントゥ
ソーステーブルに基づいて行われた一連の更新、挿入、削除をターゲットテーブルにマージします。
構文
mergeInto(table: str, condition: Column)
パラメーター
パラメーター | Type | 説明 |
|---|---|---|
| str | マージ先のターゲットテーブル名。 |
| 列 | 対象テーブルの行が対象DataFrameの行と一致するかどうかを決定する条件。 |
戻り値
MergeIntoWriter: MergeIntoWriter を使用して、ソース DataFrame をターゲット テーブルにマージする方法をさらに指定します。
例
Python
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())