Merging upstream version 26.10.1.
Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
parent
f2e3d707cd
commit
273cfbc19c
66 changed files with 79349 additions and 76628 deletions
|
@ -117,7 +117,7 @@ def simplify(
|
|||
node = flatten(node)
|
||||
node = simplify_connectors(node, root)
|
||||
node = remove_complements(node, root)
|
||||
node = simplify_coalesce(node)
|
||||
node = simplify_coalesce(node, dialect)
|
||||
node.parent = expression.parent
|
||||
node = simplify_literals(node, root)
|
||||
node = simplify_equality(node)
|
||||
|
@ -775,7 +775,7 @@ def _is_constant(expression: exp.Expression) -> bool:
|
|||
return isinstance(expression, exp.CONSTANTS) or _is_date_literal(expression)
|
||||
|
||||
|
||||
def simplify_coalesce(expression):
|
||||
def simplify_coalesce(expression: exp.Expression, dialect: DialectType) -> exp.Expression:
|
||||
# COALESCE(x) -> x
|
||||
if (
|
||||
isinstance(expression, exp.Coalesce)
|
||||
|
@ -785,6 +785,12 @@ def simplify_coalesce(expression):
|
|||
):
|
||||
return expression.this
|
||||
|
||||
# We can't convert `COALESCE(x, 1) = 2` into `NOT x IS NULL AND x = 2` for redshift,
|
||||
# because they are not always equivalent. For example, if `x` is `NULL` and it comes
|
||||
# from a table, then the result is `NULL`, despite `FALSE AND NULL` evaluating to `FALSE`
|
||||
if dialect == "redshift":
|
||||
return expression
|
||||
|
||||
if not isinstance(expression, COMPARISONS):
|
||||
return expression
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue