summaryrefslogtreecommitdiffstats
path: root/sqlglot/optimizer/qualify_columns.py
diff options
context:
space:
mode:
Diffstat (limited to 'sqlglot/optimizer/qualify_columns.py')
-rw-r--r--sqlglot/optimizer/qualify_columns.py20
1 files changed, 7 insertions, 13 deletions
diff --git a/sqlglot/optimizer/qualify_columns.py b/sqlglot/optimizer/qualify_columns.py
index 5c27bc3..ef589c9 100644
--- a/sqlglot/optimizer/qualify_columns.py
+++ b/sqlglot/optimizer/qualify_columns.py
@@ -35,11 +35,11 @@ def qualify_columns(
Args:
expression: Expression to qualify.
schema: Database schema.
- expand_alias_refs: Whether or not to expand references to aliases.
- expand_stars: Whether or not to expand star queries. This is a necessary step
+ expand_alias_refs: Whether to expand references to aliases.
+ expand_stars: Whether to expand star queries. This is a necessary step
for most of the optimizer's rules to work; do not set to False unless you
know what you're doing!
- infer_schema: Whether or not to infer the schema if missing.
+ infer_schema: Whether to infer the schema if missing.
Returns:
The qualified expression.
@@ -164,12 +164,7 @@ def _expand_using(scope: Scope, resolver: Resolver) -> t.Dict[str, t.Any]:
table = table or source_table
conditions.append(
- exp.condition(
- exp.EQ(
- this=exp.column(identifier, table=table),
- expression=exp.column(identifier, table=join_table),
- )
- )
+ exp.column(identifier, table=table).eq(exp.column(identifier, table=join_table))
)
# Set all values in the dict to None, because we only care about the key ordering
@@ -449,10 +444,9 @@ def _expand_stars(
continue
for name in columns:
+ if name in columns_to_exclude or name in coalesced_columns:
+ continue
if name in using_column_tables and table in using_column_tables[name]:
- if name in coalesced_columns:
- continue
-
coalesced_columns.add(name)
tables = using_column_tables[name]
coalesce = [exp.column(name, table=table) for table in tables]
@@ -464,7 +458,7 @@ def _expand_stars(
copy=False,
)
)
- elif name not in columns_to_exclude:
+ else:
alias_ = replace_columns.get(table_id, {}).get(name, name)
column = exp.column(name, table=table)
new_selections.append(