Complete the code to start a merge operation on the target DataFrame.
deltaTable = DeltaTable.forName(spark, [1])The DeltaTable.forName method requires the target table name as a string to perform merge operations.
Complete the code to specify the merge condition between target and source DataFrames.
deltaTable.alias("t").merge(source.alias("s"), [1])
The merge condition should match rows based on a unique key, usually an ID column.
Fix the error in the merge update clause to set the target's name to source's name.
whenMatchedUpdate = deltaTable.whenMatchedUpdate(set = [1])The set parameter expects a dictionary mapping target columns to source columns without quotes around the source column variable.
Fill both blanks to complete the merge operation with update and insert actions.
deltaTable.merge(source.alias("s"), "t.id = s.id") .whenMatchedUpdate(set = [1]) .whenNotMatchedInsert(values = [2]) .execute()
For update, the set dictionary maps target columns to source columns without quotes around source variables. For insert, the values dictionary must include all columns with source variables.
Fill all three blanks to create a dictionary comprehension for updating only columns with non-null source values.
update_dict = {col: s[col] for col in source.columns if s[col] [1] None and col != [2]
deltaTable.merge(source.alias("s"), "t.id = s.id")
.whenMatchedUpdate(set = update_dict)
.whenNotMatchedInsert(values = [3])
.execute()The dictionary comprehension filters out columns where the source value is None and excludes the 'id' column from update. The insert values dictionary includes all columns.
