fix(table_diff): resolve key and skip column names against engine-reported casing - #6110
Open
akshayram1 wants to merge 1 commit into
Open
akshayram1 wants to merge 1 commit into
akshayram1 wants to merge 1 commit into
Conversation
…orted casing User-supplied `on` and `skip_columns` names are normalized with the connection dialect, which lowercases them on engines like BigQuery and DuckDB, while `adapter.columns()` reports the stored casing. Exact lookups then failed with a KeyError for keys and silently ignored skip columns. Resolve each name against the source and target schemas: an exact match wins, otherwise a unique case-insensitive match is used. Ambiguous names and missing key columns raise a clear SQLMeshError. Also stop mutating the caller's `on` expression. Fixes SQLMesh#6067 Signed-off-by: Akshay Chame <akshaychame2@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
Fixes #6067.
TableDiffnormalizes user-suppliedonandskip_columnsnames with the connection dialect. On BigQuery and DuckDB that lowercases them, butadapter.columns()returns the stored casing (for exampleKEY1). The exact dict lookups then fail:onkeys raiseKeyError: 'key1'in_key_expression.skip_columnsare silently not skipped.This PR follows option 2 from the issue: resolve each user-supplied name against the engine-reported schema.
SQLMeshErrorsaying the name is ambiguous.SQLMeshErrorthat lists the available columns, instead of aKeyError.Names are resolved separately for the source and target tables, so their casing can differ (for example
KEY1vskey1). This covers the list form ofon, the expression form (s.KEY1 = t.KEY1) andskip_columns.key_columnsnow works on a copy of theonexpression, so it no longer changes the expression the caller passed in.Test Plan
New DuckDB tests in
tests/core/test_table_diff.py:on.onexpression not being changed.The first new tests failed before the fix (8 of 8). After the fix,
tests/core/test_table_diff.pypasses: 28 tests.make fast-test: 2621 passed. 6 failed, all intests/core/test_connection_config.py::*pyodbc*. They fail the same way on unmodifiedmainin my local environment, becauseunixodbcisn't installed (libodbc.2.dylibnot loaded), so they are unrelated to this change.Known gap: the tests only run on DuckDB. I didn't run anything against a case-sensitive engine such as Postgres or Snowflake. Resolved names go through the existing
quote_identifierspass, so uppercase columns should be emitted quoted there, but no test proves it.Checklist
make styleand fixed any issuesmake fast-test): everything passes except the 6 local pyodbc failures described abovegit commit -s) per the DCO