Skip to content

Commit

Permalink
Fix: fill in missing implementation details for replace(None) (#3166)
Browse files Browse the repository at this point in the history
  • Loading branch information
georgesittas committed Mar 19, 2024
1 parent cdbe39e commit 5e18d49
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
4 changes: 2 additions & 2 deletions sqlglot/expressions.py
Expand Up @@ -621,7 +621,7 @@ def replace(self, expression):
return expression

key = self.arg_key
value = parent.args[key]
value = parent.args.get(key)

if isinstance(value, list):
index = self.index
Expand All @@ -639,7 +639,7 @@ def replace(self, expression):
else:
value[index] = expression
parent._set_parent(key, expression, index=index)
else:
elif value is not None:
if expression is None:
parent.args.pop(key)
else:
Expand Down
3 changes: 3 additions & 0 deletions tests/test_optimizer.py
Expand Up @@ -342,6 +342,9 @@ def test_pushdown_projection(self):
def test_simplify(self):
self.check_file("simplify", simplify, set_dialect=True)

expression = parse_one("SELECT a, c, b FROM table1 WHERE 1 = 1")
self.assertEqual(simplify(simplify(expression.find(exp.Where))).sql(), "WHERE TRUE")

expression = parse_one("TRUE AND TRUE AND TRUE")
self.assertEqual(exp.true(), optimizer.simplify.simplify(expression))
self.assertEqual(exp.true(), optimizer.simplify.simplify(expression.this))
Expand Down

0 comments on commit 5e18d49

Please sign in to comment.