Repository navigation
fix(scd2)!: preserve NULL values in historical rows - #6115
Arthur031221 wants to merge 1 commit into
Conversation
|
Anything else you need from me on this one? |
Vamsi-klu
left a comment
There was a problem hiding this comment.
The explicit target-existence marker preserves historical NULLs without using a nullable key or validity timestamp as the existence test. The case-insensitive collision handling also covers both source columns and prefixed target columns.
Validation at bf1d818a passed 36 targeted SCD tests, including the DuckDB executions. All four new NULL-history regression cases fail against the base production code and pass with this change. No blocking issue found. GitHub currently reports 29 successful checks and 5 skipped checks.
A release note would help clarify that this prevents future history corruption; it does not reconstruct historical values already overwritten by earlier runs.
|
@Arthur031221 Thanks for the PR! We'll take a look at this soon. Apologies for our late response. Please keep in mind that you can ping us when you feel the PR needs immediate attention |
Select target values using an explicit row-existence flag carried into the SCD2 join. Choose a flag alias that does not overlap source or prefixed target columns, including case-insensitive names. Co-authored-by: Nicholas <71755971+ionnich@users.noreply.github.com> Signed-off-by: Arthur031221 <levi74108520963@gmail.com>
bf1d818 to
ce8316a
Compare
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
mday-io
left a comment
There was a problem hiding this comment.
This needs a few changes before we can merge. The fix itself is right.
- The fix also changes how current rows behave, not just history. On main, if the current row has a NULL and the next load sends a value without changing
updated_ator the check columns, the NULL is overwritten in place. With this PR it stays NULL until a tracked change arrives. That's the behavior we want: it matches how other untracked changes work and how dbt snapshots behave. But rows written after an upgrade will differ, so please add!to the title (fix(scd2)!: ...) and add an upgrade note to the description. The note should say that these columns no longer fill in on the current row, and that users who need them recorded should bumpupdated_atwhen the late value arrives, or add the column tocheck_columns. - Please cut
test_scd_type_2_marker_collisiondown to one case, e.g.T__EXISTS,TEXT,scd_type_2_by_time, SQL input. If the marker is hard-coded tot__exists, all 16 cases fail together, so the other 15 don't catch anything extra. - Please drop the
use_dataframeparametrization fromtest_scd_type_2_marker_collisionandtest_scd_type_2_null_valid_from. The DataFrame source goes through the same SCD query, so it doesn't reach anything the SQL input misses.
Description
Users running SCD_TYPE_2_BY_TIME or SCD_TYPE_2_BY_COLUMN models lost historical NULL values when a later source row supplied a value for the same key.
updated_rowsusedCOALESCE(target, source), so a NULL target fell through to the new source value. It now uses the target row's existence flag to keep its values, including NULL. The existence check also preserves target payloads when a key or validity timestamp is NULL. Its alias is chosen to avoid source and prefixed target column names.This builds on the code @ionnich posted in issue #5332. Fixes #5332.
Upgrade note
A later load no longer fills in a NULL on an existing row of an SCD Type 2 model. The value is recorded only when the load creates a new version of the row. This includes NULLs in a newly added column. To record a late value in a
SCD_TYPE_2_BY_TIMEmodel, moveupdated_atforward when the value arrives. In aSCD_TYPE_2_BY_COLUMNmodel, add the column tocheck_columns.Test Plan
make fast-test,make style,make doc-test, andmake benchmark-cipassed on Linux with Python 3.12.3. The four history regression cases cover both SCD2 kinds with SQL and Pandas inputs. They fail against upstream production source and pass with the fix. Four additional cases verify that removing a source key preserves the key and payload of an existing target row whose validity timestamp is NULL. Sixteen additional cases cover TEXT and BOOLEAN columns that collide with internal flag names, including case-insensitive names. The collision cases pass against upstream, fail with a constant flag name, and pass with the fix. All 24 added SCD2 regression cases pass with the fix.Checklist
make styleand fixed any issuesmake fast-test)git commit -s) per the DCOCo-authored-by: Nicholas 71755971+ionnich@users.noreply.github.com
Summary by CodeRabbit
NULL, rather than replaced with source values.