A data engineer must maintain a Type 2 slowly changing customer dimension in a Lakeflow Spark Declarative Pipeline, so that each change to a customer produces a new versioned row with validity boundaries while prior versions are retained. The source is a CDC feed with a sequenceNum ordering column and an operation column. Which configuration of the APPLY CHANGES INTO (AUTO CDC) API correctly produces the SCD Type 2 history?
Show answer & explanation
Correct answer: E
WHY E: APPLY CHANGES INTO ... KEYS (customer_id) SEQUENCE BY sequenceNum STORED AS SCD TYPE 2 is the idiomatic Lakeflow/DLT construct for SCD Type 2: it keys on the business key, orders changes by the sequence column, and automatically maintains historical versions with validity boundary columns. WHY NOT B: STORED AS SCD TYPE 1 overwrites in place; Change Data Feed records changes for downstream consumers but does not turn a Type 1 dimension into a queryable Type 2 history with validity columns. WHY NOT C: The AUTO CDC/APPLY CHANGES API natively supports STORED AS SCD TYPE 2, so hand-coded MERGE is unnecessary; the premise that only Type 1 is supported is false. WHY NOT D: SEQUENCE BY is required to order CDC changes correctly; omitting it is not how Type 2 ordering works and would leave change ordering undefined. WHY NOT A: The sequence column must NOT be part of KEYS; keys identify the business entity, and adding sequenceNum to the key would make every change a separate entity, breaking the dimension.