Merging upstream version 17.2.0.
Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
parent
06c5965633
commit
ff2afd7448
91 changed files with 42856 additions and 42624 deletions
|
@ -105,6 +105,7 @@ class TypeAnnotator(metaclass=_TypeAnnotator):
|
|||
exp.CurrentDate,
|
||||
exp.Date,
|
||||
exp.DateAdd,
|
||||
exp.DateFromParts,
|
||||
exp.DateStrToDate,
|
||||
exp.DateSub,
|
||||
exp.DateTrunc,
|
||||
|
|
|
@ -220,25 +220,6 @@ def _expand_group_by(scope: Scope):
|
|||
group.set("expressions", _expand_positional_references(scope, group.expressions))
|
||||
expression.set("group", group)
|
||||
|
||||
# group by expressions cannot be simplified, for example
|
||||
# select x + 1 + 1 FROM y GROUP BY x + 1 + 1
|
||||
# the projection must exactly match the group by key
|
||||
groups = set(group.expressions)
|
||||
group.meta["final"] = True
|
||||
|
||||
for e in expression.selects:
|
||||
for node, *_ in e.walk():
|
||||
if node in groups:
|
||||
e.meta["final"] = True
|
||||
break
|
||||
|
||||
having = expression.args.get("having")
|
||||
if having:
|
||||
for node, *_ in having.walk():
|
||||
if node in groups:
|
||||
having.meta["final"] = True
|
||||
break
|
||||
|
||||
|
||||
def _expand_order_by(scope: Scope, resolver: Resolver):
|
||||
order = scope.expression.args.get("order")
|
||||
|
|
|
@ -8,6 +8,9 @@ from sqlglot import exp
|
|||
from sqlglot.generator import cached_generator
|
||||
from sqlglot.helper import first, while_changing
|
||||
|
||||
# Final means that an expression should not be simplified
|
||||
FINAL = "final"
|
||||
|
||||
|
||||
def simplify(expression):
|
||||
"""
|
||||
|
@ -27,8 +30,29 @@ def simplify(expression):
|
|||
|
||||
generate = cached_generator()
|
||||
|
||||
# group by expressions cannot be simplified, for example
|
||||
# select x + 1 + 1 FROM y GROUP BY x + 1 + 1
|
||||
# the projection must exactly match the group by key
|
||||
for group in expression.find_all(exp.Group):
|
||||
select = group.parent
|
||||
groups = set(group.expressions)
|
||||
group.meta[FINAL] = True
|
||||
|
||||
for e in select.selects:
|
||||
for node, *_ in e.walk():
|
||||
if node in groups:
|
||||
e.meta[FINAL] = True
|
||||
break
|
||||
|
||||
having = select.args.get("having")
|
||||
if having:
|
||||
for node, *_ in having.walk():
|
||||
if node in groups:
|
||||
having.meta[FINAL] = True
|
||||
break
|
||||
|
||||
def _simplify(expression, root=True):
|
||||
if expression.meta.get("final"):
|
||||
if expression.meta.get(FINAL):
|
||||
return expression
|
||||
node = expression
|
||||
node = rewrite_between(node)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue