CERTIFIED-DATA-ENGINEER-PROFESSIONAL · Question #117
A data engineer wants to reflector the following DLT code, which includes multiple definition with very similar code: In an attempt to programmatically create these tables using a parameterized table
The correct answer is A. Convert the list of configuration values to a dictionary of table settings, using table names as. This is a classic Python late-binding closure problem in loops. When DLT table definitions are created inside a for loop using a loop variable, all the generated table functions capture the same variable reference. By the time the pipeline evaluates the functions, the loop variab
Question
A data engineer wants to reflector the following DLT code, which includes multiple definition with very similar code:
In an attempt to programmatically create these tables using a parameterized table definition, the data engineer writes the following code. The pipeline runs an update with this refactored code, but generates a different DAG showing incorrect configuration values for tables. How can the data engineer fix this?
Exhibit
Options
- AConvert the list of configuration values to a dictionary of table settings, using table names as
- BConvert the list of configuration values to a dictionary of table settings, using different input the for
- CLoad the configuration values for these tables from a separate file, located at a path provided by a
- DWrap the loop inside another table definition, using generalized names and properties to replace
How the community answered
(35 responses)- A83% (29)
- B3% (1)
- C3% (1)
- D11% (4)
Explanation
This is a classic Python late-binding closure problem in loops. When DLT table definitions are created inside a for loop using a loop variable, all the generated table functions capture the same variable reference. By the time the pipeline evaluates the functions, the loop variable holds its final value, causing all tables to use the same (last) configuration. The fix is to convert the configuration list to a dictionary keyed by table name, so each table definition captures an immutable key lookup rather than a shared loop variable. This ensures each table receives its own correct configuration values when the DAG is evaluated.
Topics
Community Discussion
No community discussion yet for this question.
