summaryrefslogtreecommitdiffstats
path: root/sqlglot/optimizer/simplify.py
diff options
context:
space:
mode:
Diffstat (limited to 'sqlglot/optimizer/simplify.py')
-rw-r--r--sqlglot/optimizer/simplify.py26
1 files changed, 14 insertions, 12 deletions
diff --git a/sqlglot/optimizer/simplify.py b/sqlglot/optimizer/simplify.py
index d5b9119..90357dd 100644
--- a/sqlglot/optimizer/simplify.py
+++ b/sqlglot/optimizer/simplify.py
@@ -104,7 +104,6 @@ def simplify(
if root:
expression.replace(node)
-
return node
expression = while_changing(expression, _simplify)
@@ -174,16 +173,20 @@ def simplify_not(expression):
if isinstance(this, exp.Paren):
condition = this.unnest()
if isinstance(condition, exp.And):
- return exp.or_(
- exp.not_(condition.left, copy=False),
- exp.not_(condition.right, copy=False),
- copy=False,
+ return exp.paren(
+ exp.or_(
+ exp.not_(condition.left, copy=False),
+ exp.not_(condition.right, copy=False),
+ copy=False,
+ )
)
if isinstance(condition, exp.Or):
- return exp.and_(
- exp.not_(condition.left, copy=False),
- exp.not_(condition.right, copy=False),
- copy=False,
+ return exp.paren(
+ exp.and_(
+ exp.not_(condition.left, copy=False),
+ exp.not_(condition.right, copy=False),
+ copy=False,
+ )
)
if is_null(condition):
return exp.null()
@@ -490,7 +493,7 @@ def simplify_equality(expression: exp.Expression) -> exp.Expression:
if isinstance(expression, COMPARISONS):
l, r = expression.left, expression.right
- if not l.__class__ in INVERSE_OPS:
+ if l.__class__ not in INVERSE_OPS:
return expression
if r.is_number:
@@ -714,8 +717,7 @@ def simplify_concat(expression):
"""Reduces all groups that contain string literals by concatenating them."""
if not isinstance(expression, CONCATS) or (
# We can't reduce a CONCAT_WS call if we don't statically know the separator
- isinstance(expression, exp.ConcatWs)
- and not expression.expressions[0].is_string
+ isinstance(expression, exp.ConcatWs) and not expression.expressions[0].is_string
):
return expression