Skip to content

fix(expressions): wrap string alias in TableAlias in to_table()#7352

Open
Tigeneric wants to merge 1 commit intotobymao:mainfrom
Tigeneric:fix/to-table-alias
Open

fix(expressions): wrap string alias in TableAlias in to_table()#7352
Tigeneric wants to merge 1 commit intotobymao:mainfrom
Tigeneric:fix/to-table-alias

Conversation

@Tigeneric
Copy link

Problem

to_table() passes alias as a raw string via table.set(k, v), but qualify_columns expects TableAlias(this=Identifier(...)). This causes qualify_columns to fail on AST-built queries with table aliases.

Repro:

from sqlglot import exp
from sqlglot.optimizer.qualify_columns import qualify_columns

table = exp.to_table("foo", alias="bar")
select = exp.Select().select("*").from_(table)
qualify_columns(select, schema={"foo": {"id": "INT"}})
# TypeError — alias is str, not TableAlias

Fix

Wraps string alias in TableAlias(this=to_identifier(v)) before table.set() — same pattern already used in table_() (line 513).

2-line change, no behavior change for non-string aliases.

to_table() passes alias as raw string via table.set(k, v), but
qualify_columns expects TableAlias(this=Identifier(...)). This causes
qualify_columns to fail on AST-built queries with table aliases.

Wraps string alias in TableAlias(this=to_identifier(v)) before
table.set() — same pattern already used in table_().
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.

1 participant