Skip to content

fix(transforms): use case-insensitive column comparison when output case settings are active#322

Open
ota2000 wants to merge 2 commits intoz3z1ma:mainfrom
ota2000:ota2000/fix/case-insensitive-column-comparison
Open

fix(transforms): use case-insensitive column comparison when output case settings are active#322
ota2000 wants to merge 2 commits intoz3z1ma:mainfrom
ota2000:ota2000/fix/case-insensitive-column-comparison

Conversation

@ota2000
Copy link

@ota2000 ota2000 commented Feb 14, 2026

Summary

Fix broken idempotency in inject_missing_columns, remove_columns_not_in_database, and synchronize_data_types when output-to-upper or output-to-lower is 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 DB
  • synchronize_data_types: fails to match columns, skipping data type sync

Additionally, inject_missing_columns used context.settings.output_to_upper/lower directly for data_type case conversion instead of the already-resolved node-level settings.

Fix

When output-to-upper or output-to-lower is 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-insensitive current_columns membership check + use resolved node-level settings for data_type
  • remove_columns_not_in_database: case-insensitive set difference between current and incoming keys
  • synchronize_data_types: fallback to lowercase lookup when direct incoming_columns.get() fails

Tests

  • test_inject_missing_columns_idempotent_with_output_to_upper_on_postgres: verifies no re-addition on second run
  • test_remove_columns_not_in_database_with_output_to_upper_on_postgres: verifies valid columns are not removed
  • test_remove_columns_not_in_database_removes_truly_extra_columns: verifies truly stale columns are still removed
  • test_synchronize_data_types_with_output_to_upper_on_postgres: verifies data type sync succeeds

Depends on #321

Closes #320

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: normalize_column_name does not account for output case settings on non-Snowflake DBs

1 participant