Microsoft
DP-700 · Question #47
You have the following code segment: def loading_pattern_sample(df_source): try: deltatable = DeltaTable.forName(spark, target_table) except Exception as e: df_source.write.format('delta').mode('overw
Sign in or unlock DP-700 to reveal the answer and full explanation for question #47. The question stem and answer options stay visible for context.
Design and implement data ingestion and transformation
Question
You have the following code segment:
def loading_pattern_sample(df_source):
try:
deltatable = DeltaTable.forName(spark, target_table)
except Exception as e:
df_source.write.format('delta').mode('overwrite').saveAsTable(f'{target_table}')
except Exception as e:
print(f'load for table {target_table} failed with error: {str(e)}')
return
try:
change_detection_columns = [col for col in df_source.columns if col not in candidate_key]
match_condition = ' AND '.join([f'target.{col} = source.{col}' for col in candidate_key])
update_condition = ' OR '.join([f'target.{col} != source.{col}' for col in change_detection_columns])
update_expr = {col: f'source.{col}' for col in df_source.columns}
merge_operation = deltatable.alias('target').merge(
source=df_source.alias('source'),
condition=match_condition
).whenMatchedUpdate(
condition=update_condition,
set=update_expr
).whenNotMatchedInsertAll()
merge_operation.execute()
except Exception as e:
print(f'insert operation for table {target_table} failed with error: {str(e)}')
return
Based on the code, does the loading pattern support both full and incremental loading requirements?
Options
- AYes
- BNo
Unlock DP-700 to see the answer
You've previewed enough free DP-700 questions. Unlock DP-700 for full answers, explanations, the timed quiz mode, progress tracking, and the master PDF. Question stem and options stay visible so you can still see what's on the exam.
Topics
#Delta Lake#Incremental Loading#Data Ingestion#Merge Operation