Skip to content

Commit

Permalink
Fix: qualify column in func with equality
Browse files Browse the repository at this point in the history
  • Loading branch information
tobymao committed Jun 30, 2023
1 parent d4e0e0e commit 3005306
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
11 changes: 8 additions & 3 deletions sqlglot/optimizer/scope.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,14 +268,19 @@ def columns(self):
self._columns = []
for column in columns + external_columns:
ancestor = column.find_ancestor(
exp.Select, exp.Qualify, exp.Order, exp.Having, exp.Hint
exp.Select, exp.Qualify, exp.Order, exp.Having, exp.Hint, exp.Table
)
if (
not ancestor
or column.table
or isinstance(ancestor, exp.Select)
or (isinstance(ancestor, exp.Order) and isinstance(ancestor.parent, exp.Window))
or (column.name not in named_selects and not isinstance(ancestor, exp.Hint))
or (
isinstance(ancestor, exp.Order)
and (
isinstance(ancestor.parent, exp.Window)
or column.name not in named_selects
)
)
):
self._columns.append(column)

Expand Down
5 changes: 0 additions & 5 deletions sqlglot/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -3322,11 +3322,6 @@ def _parse_lambda(self, alias: bool = False) -> t.Optional[exp.Expression]:
else:
this = self._parse_select_or_expression(alias=alias)

if isinstance(this, exp.EQ):
left = this.this
if isinstance(left, exp.Column):
left.replace(exp.var(left.text("this")))

return self._parse_limit(self._parse_order(self._parse_respect_or_ignore_nulls(this)))

def _parse_schema(self, this: t.Optional[exp.Expression] = None) -> t.Optional[exp.Expression]:
Expand Down
1 change: 1 addition & 0 deletions tests/fixtures/identity.sql
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ REGEXP_LIKE('new york', '.')
REGEXP_SPLIT('new york', '.')
SPLIT('new york', '.')
X((y AS z)).1
X(a.b = 1)
(x AS y, y AS z)
REPLACE(1)
DATE(x) = DATE(y)
Expand Down

0 comments on commit 3005306

Please sign in to comment.