fix(optimizer): handle ColumnDef in typed table alias columns#7542
Merged
georgesittas merged 1 commit intomainfrom Apr 22, 2026
Merged
fix(optimizer): handle ColumnDef in typed table alias columns#7542georgesittas merged 1 commit intomainfrom
georgesittas merged 1 commit intomainfrom
Conversation
e3eaf1d to
58c0dbe
Compare
58c0dbe to
38e2646
Compare
qualify_tables._set_alias called exp.to_identifier() on every column, which rejects ColumnDef nodes produced by typed table-function signatures like FROM fn() AS t(col INT). Route only strings through to_identifier and copy any other expression (Identifier, ColumnDef) to preserve the existing copy-before-reparent semantics. Widens the columns/function_columns type annotations to include exp.ColumnDef so mypyc's runtime type checks accept it.
38e2646 to
93e1b52
Compare
Contributor
SQLGlot Integration Test ResultsComparing:
By Dialect
Overallmain: 113234 total, 112044 passed (pass rate: 98.9%), sqlglot version: sqlglot:fix/qualify-tables-typed-alias-columns: 101035 total, 101035 passed (pass rate: 100.0%), sqlglot version: Transitions: Dialect pair changes: 0 previous results not found, 3 current results not found ✅ 32 test(s) passed |
georgesittas
approved these changes
Apr 22, 2026
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
qualify_tables._set_aliasunconditionally calledexp.to_identifier(c)on every entry inTableAlias.columns, which only acceptsstr/Identifier. Typed table-function signatures likeFROM fn() AS t(col INT)produceColumnDefnodes and trippedValueError: Name needs to be a string or an Identifier, got: <class '...ColumnDef'>when the column-assignment branch ran (e.g. undercanonicalize_table_aliases=True).to_identifier; copy any other expression (Identifier,ColumnDef) to preserve the original copy-before-reparent semantics.Repro (before):
After:
SELECT * FROM JSON_TO_RECORDSET(z) AS _0("rank" INT)Test plan
test_qualify_tables_copies_typed_alias_columnsexercises theColumnDefpath viacanonicalize_table_aliases=Trueand asserts the column is preserved asColumnDef, is a different object than the original (the copy check), and has identical SQL.python -m unittest tests.test_optimizer— 77 tests pass.