1
0
Fork 0

Adding upstream version 23.16.0.

Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
Daniel Baumann 2025-02-13 21:34:56 +01:00
parent 9d7e0ff7aa
commit b6ae88ec81
Signed by: daniel
GPG key ID: FBB4F0E80A80222F
93 changed files with 64106 additions and 59061 deletions

View file

@ -105,7 +105,14 @@ def eliminate_qualify(expression: exp.Expression) -> exp.Expression:
select.replace(exp.alias_(select, alias))
taken.add(alias)
outer_selects = exp.select(*[select.alias_or_name for select in expression.selects])
def _select_alias_or_name(select: exp.Expression) -> str | exp.Column:
alias_or_name = select.alias_or_name
identifier = select.args.get("alias") or select.this
if isinstance(identifier, exp.Identifier):
return exp.column(alias_or_name, quoted=identifier.args.get("quoted"))
return alias_or_name
outer_selects = exp.select(*list(map(_select_alias_or_name, expression.selects)))
qualify_filters = expression.args["qualify"].pop().this
expression_by_alias = {
select.alias: select.this
@ -465,19 +472,28 @@ def move_ctes_to_top_level(expression: exp.Expression) -> exp.Expression:
TODO: handle name clashes whilst moving CTEs (it can get quite tricky & costly).
"""
top_level_with = expression.args.get("with")
for node in expression.find_all(exp.With):
if node.parent is expression:
for inner_with in expression.find_all(exp.With):
if inner_with.parent is expression:
continue
inner_with = node.pop()
if not top_level_with:
top_level_with = inner_with
top_level_with = inner_with.pop()
expression.set("with", top_level_with)
else:
if inner_with.recursive:
top_level_with.set("recursive", True)
top_level_with.set("expressions", inner_with.expressions + top_level_with.expressions)
parent_cte = inner_with.find_ancestor(exp.CTE)
inner_with.pop()
if parent_cte:
i = top_level_with.expressions.index(parent_cte)
top_level_with.expressions[i:i] = inner_with.expressions
top_level_with.set("expressions", top_level_with.expressions)
else:
top_level_with.set(
"expressions", top_level_with.expressions + inner_with.expressions
)
return expression