fix(transforms): apply case conversion to column keys in inject_missing_columns#321
Open
ota2000 wants to merge 1 commit intoz3z1ma:mainfrom
Open
Conversation
When output-to-lower is enabled with Snowflake, newly injected columns had uppercase dictionary keys from the database while sort used lowercase comparison, causing incorrect alphabetical order on the first run. Convert column keys and names at injection time based on output-to-lower and output-to-upper settings so that subsequent sorting works correctly from the first execution.
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.
Summary
Fix incorrect alphabetical sort order on the first run when
output-to-loweris enabled with Snowflake.Problem
When using
--output-to-lowerwithsort-by: alphabetical, newly added columns were not sorted correctly on the first run (a second run was required). The root cause was thatinject_missing_columns()used the normalized column name from the database (uppercase for Snowflake) as the dictionary key innode.columns. The subsequentsort_columns_alphabetically()compared by lowercase, but the keys themselves remained uppercase, resulting in incorrect ordering.Fix
Apply
output-to-lower/output-to-uppercase conversion to both the dictionary key and the column name at injection time ininject_missing_columns(), so that subsequent sorting produces the correct order from the first execution._get_setting_for_node(respects per-node settings, consistent withsort_columns_alphabeticallyandsync_operations)context.settingsdirectly (unchanged from previous behavior)Tests
test_inject_missing_columns_applies_output_to_lower: verifies uppercase DB columns are added with lowercase keys whenoutput_to_lower=Truetest_inject_missing_columns_with_lower_then_sort_alphabetically: end-to-end test verifying inject + sort produces correct alphabetical order on first runCloses #309