summaryrefslogtreecommitdiffstats
path: root/sqlglot/optimizer/expand_laterals.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2023-06-02 23:59:40 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2023-06-02 23:59:46 +0000
commit20739a12c39121a9e7ad3c9a2469ec5a6876199d (patch)
treec000de91c59fd29b2d9beecf9f93b84e69727f37 /sqlglot/optimizer/expand_laterals.py
parentReleasing debian version 12.2.0-1. (diff)
downloadsqlglot-20739a12c39121a9e7ad3c9a2469ec5a6876199d.tar.xz
sqlglot-20739a12c39121a9e7ad3c9a2469ec5a6876199d.zip
Merging upstream version 15.0.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'sqlglot/optimizer/expand_laterals.py')
-rw-r--r--sqlglot/optimizer/expand_laterals.py34
1 files changed, 0 insertions, 34 deletions
diff --git a/sqlglot/optimizer/expand_laterals.py b/sqlglot/optimizer/expand_laterals.py
deleted file mode 100644
index 5b2f706..0000000
--- a/sqlglot/optimizer/expand_laterals.py
+++ /dev/null
@@ -1,34 +0,0 @@
-from __future__ import annotations
-
-import typing as t
-
-from sqlglot import exp
-
-
-def expand_laterals(expression: exp.Expression) -> exp.Expression:
- """
- Expand lateral column alias references.
-
- This assumes `qualify_columns` as already run.
-
- Example:
- >>> import sqlglot
- >>> sql = "SELECT x.a + 1 AS b, b + 1 AS c FROM x"
- >>> expression = sqlglot.parse_one(sql)
- >>> expand_laterals(expression).sql()
- 'SELECT x.a + 1 AS b, x.a + 1 + 1 AS c FROM x'
-
- Args:
- expression: expression to optimize
- Returns:
- optimized expression
- """
- for select in expression.find_all(exp.Select):
- alias_to_expression: t.Dict[str, exp.Expression] = {}
- for projection in select.expressions:
- for column in projection.find_all(exp.Column):
- if not column.table and column.name in alias_to_expression:
- column.replace(alias_to_expression[column.name].copy())
- if isinstance(projection, exp.Alias):
- alias_to_expression[projection.alias] = projection.this
- return expression