Skip to content

Fix: qualify all columns in the table diff source/target query scope#4133

Merged
georgesittas merged 1 commit intomainfrom
jo/improve_table_diff
Apr 14, 2025
Merged

Fix: qualify all columns in the table diff source/target query scope#4133
georgesittas merged 1 commit intomainfrom
jo/improve_table_diff

Conversation

@georgesittas
Copy link
Contributor

@georgesittas georgesittas commented Apr 13, 2025

See #4132 (comment) for context. My theory there wasn't correct after all. I had a hunch about this and verified it just now: the updated test currently fails in main, due to the same "= not defined for the STRUCT type" bug.

For example, the source query contains a projection that we create using the following property method:

self.source_key_expression.as_(SQLMESH_JOIN_KEY_COL)

The source_key_expression property ends up calling _key_expression (definition), which returns an expression with unqualified columns. If any of those columns has the same name as the source table, it'll again end up being treated as a STRUCT...

The reason I had reverted the find_all approach in my previous PR was to avoid any weird edge cases, e.g. if a user passed in a custom filter using the where kwarg, and that contained a subquery that scanned a different table, we didn't want the columns in that subquery to have their table overwritten (or set to the incorrect table).

This PR ensures we won't encounter this problem by using find_all_in_scope instead, which only modifies the top-level scope's Columns.

@georgesittas georgesittas requested a review from tobymao April 13, 2025 23:43
@georgesittas georgesittas force-pushed the jo/improve_table_diff branch from e4b8bf4 to dbb434b Compare April 13, 2025 23:55
@georgesittas georgesittas merged commit a533c1d into main Apr 14, 2025
22 checks passed
@georgesittas georgesittas deleted the jo/improve_table_diff branch April 14, 2025 09:38
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.

2 participants