fix(transforms): use case-insensitive column comparison when output case settings are active#322
Open
ota2000 wants to merge 2 commits 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.
…tings are active When output-to-upper or output-to-lower is enabled on non-Snowflake DBs, normalize_column_name is case-preserving, causing mismatches between case-converted node column names and DB-derived incoming column names. This breaks idempotency in inject_missing_columns (re-adds existing columns), remove_columns_not_in_database (incorrectly removes valid columns), and synchronize_data_types (fails to match columns for type sync). Fix by lowercasing both sides of the comparison when case conversion is active. Also fix inject_missing_columns data_type case conversion to use resolved node-level settings instead of global context.settings. Closes z3z1ma#320
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 broken idempotency in
inject_missing_columns,remove_columns_not_in_database, andsynchronize_data_typeswhenoutput-to-upperoroutput-to-loweris active on non-Snowflake databases.Problem
normalize_column_name()is case-preserving on non-Snowflake DBs (e.g., PostgreSQL). When combined with output case settings, the column name comparison between case-converted node columns and DB-derived incoming columns fails:inject_missing_columns: re-adds existing columns on every run (e.g.,"zebra" not in {"ZEBRA"})remove_columns_not_in_database: incorrectly removes valid columns that exist in the DBsynchronize_data_types: fails to match columns, skipping data type syncAdditionally,
inject_missing_columnsusedcontext.settings.output_to_upper/lowerdirectly fordata_typecase conversion instead of the already-resolved node-level settings.Fix
When
output-to-upperoroutput-to-loweris active, normalize both sides of the comparison to lowercase. This ensures case-converted column keys match DB-derived normalized names regardless of the adapter type.inject_missing_columns: case-insensitivecurrent_columnsmembership check + use resolved node-level settings fordata_typeremove_columns_not_in_database: case-insensitive set difference between current and incoming keyssynchronize_data_types: fallback to lowercase lookup when directincoming_columns.get()failsTests
test_inject_missing_columns_idempotent_with_output_to_upper_on_postgres: verifies no re-addition on second runtest_remove_columns_not_in_database_with_output_to_upper_on_postgres: verifies valid columns are not removedtest_remove_columns_not_in_database_removes_truly_extra_columns: verifies truly stale columns are still removedtest_synchronize_data_types_with_output_to_upper_on_postgres: verifies data type sync succeedsDepends on #321
Closes #320