Skip to content

fix(transforms): apply case conversion to column keys in inject_missing_columns#321

Open
ota2000 wants to merge 1 commit intoz3z1ma:mainfrom
ota2000:ota2000/fix/inject-missing-columns-case-conversion
Open

fix(transforms): apply case conversion to column keys in inject_missing_columns#321
ota2000 wants to merge 1 commit intoz3z1ma:mainfrom
ota2000:ota2000/fix/inject-missing-columns-case-conversion

Conversation

@ota2000
Copy link

@ota2000 ota2000 commented Feb 14, 2026

Summary

Fix incorrect alphabetical sort order on the first run when output-to-lower is enabled with Snowflake.

Problem

When using --output-to-lower with sort-by: alphabetical, newly added columns were not sorted correctly on the first run (a second run was required). The root cause was that inject_missing_columns() used the normalized column name from the database (uppercase for Snowflake) as the dictionary key in node.columns. The subsequent sort_columns_alphabetically() compared by lowercase, but the keys themselves remained uppercase, resulting in incorrect ordering.

Fix

Apply output-to-lower / output-to-upper case conversion to both the dictionary key and the column name at injection time in inject_missing_columns(), so that subsequent sorting produces the correct order from the first execution.

  • Column name case conversion uses _get_setting_for_node (respects per-node settings, consistent with sort_columns_alphabetically and sync_operations)
  • Data type case conversion remains using context.settings directly (unchanged from previous behavior)

Tests

  • test_inject_missing_columns_applies_output_to_lower: verifies uppercase DB columns are added with lowercase keys when output_to_lower=True
  • test_inject_missing_columns_with_lower_then_sort_alphabetically: end-to-end test verifying inject + sort produces correct alphabetical order on first run

Closes #309

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.
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.

CLI flag --output-to-lower on Snowflake database does not respect alphabetical sort order on adding new columns

1 participant