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…
The correct answer is A. Yes. The code is designed to handle the initial creation of the Delta table if it does not already exist, ensuring that the loading process can proceed without manual table setup.
Question
Options
- AYes
- BNo
How the community answered
(29 responses)- A83% (24)
- B17% (5)
Why each option
The code is designed to handle the initial creation of the Delta table if it does not already exist, ensuring that the loading process can proceed without manual table setup.
The initial `try-except` block correctly implements an idempotent mechanism where it first attempts to load an existing Delta table using `DeltaTable.forName`. If this operation fails (e.g., because the table does not exist), the `except` block then creates the table using `df_source.write.format('delta').mode('overwrite').saveAsTable`, ensuring the table is available for subsequent merge operations.
The statement is true because the code explicitly includes logic to create the target Delta table if it does not already exist, making the loading process more robust.
Concept tested: Idempotent Delta table creation for loading
Source: https://docs.delta.io/latest/api/python/index.html#delta.tables.DeltaTable.forName
Topics
Community Discussion
No community discussion yet for this question.