nerdexam
Databricks

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

Building and Managing Data Pipelines with Delta Live Tables

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

CERTIFIED-DATA-ENGINEER-PROFESSIONAL question #117 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)
  • A
    83% (29)
  • B
    3% (1)
  • C
    3% (1)
  • D
    11% (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

#Delta Live Tables (DLT)#Parameterized Pipelines#Configuration Management#Data Engineering Best Practices

Community Discussion

No community discussion yet for this question.

Full CERTIFIED-DATA-ENGINEER-PROFESSIONAL Practice