fix(scd2): preserve NULL values in historical rows - #6115
Open
Arthur031221 wants to merge 1 commit into
Open
Arthur031221 wants to merge 1 commit into
Arthur031221 wants to merge 1 commit into
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.
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