1
0
Fork 0

Merging upstream version 11.5.2.

Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
Daniel Baumann 2025-02-13 15:50:57 +01:00
parent b9525af810
commit 9782c88c58
Signed by: daniel
GPG key ID: FBB4F0E80A80222F
106 changed files with 25262 additions and 24200 deletions

View file

@ -143,12 +143,12 @@ def _expand_alias_refs(scope, resolver):
selects = {}
# Replace references to select aliases
def transform(node, *_):
def transform(node, source_first=True):
if isinstance(node, exp.Column) and not node.table:
table = resolver.get_table(node.name)
# Source columns get priority over select aliases
if table:
if source_first and table:
node.set("table", table)
return node
@ -163,16 +163,21 @@ def _expand_alias_refs(scope, resolver):
select = select.this
return select.copy()
node.set("table", table)
elif isinstance(node, exp.Expression) and not isinstance(node, exp.Subqueryable):
exp.replace_children(node, transform, source_first)
return node
for select in scope.expression.selects:
select.transform(transform, copy=False)
transform(select)
for modifier in ("where", "group"):
part = scope.expression.args.get(modifier)
if part:
part.transform(transform, copy=False)
for modifier, source_first in (
("where", True),
("group", True),
("having", False),
):
transform(scope.expression.args.get(modifier), source_first=source_first)
def _expand_group_by(scope, resolver):

View file

@ -347,8 +347,9 @@ def _simplify_binary(expression, a, b):
if isinstance(expression, exp.Mul):
return exp.Literal.number(a * b)
if isinstance(expression, exp.Div):
# engines have differing int div behavior so intdiv is not safe
if isinstance(a, int) and isinstance(b, int):
return exp.Literal.number(a // b)
return None
return exp.Literal.number(a / b)
boolean = eval_boolean(expression, a, b)
@ -491,7 +492,7 @@ def _flat_simplify(expression, simplifier, root=True):
if result:
queue.remove(b)
queue.append(result)
queue.appendleft(result)
break
else:
operands.append(a)