summaryrefslogtreecommitdiffstats
path: root/sqlglot/helper.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2023-04-03 07:31:50 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2023-04-03 07:31:50 +0000
commit1fb60a37d31eacbac62ddafde51b829522925694 (patch)
tree5c04a33630f7a2cd4cff248e965053f97ec3e4ac /sqlglot/helper.py
parentAdding upstream version 11.4.1. (diff)
downloadsqlglot-c703ca34b712703c6eff83923bcbfeadc6c73564.tar.xz
sqlglot-c703ca34b712703c6eff83923bcbfeadc6c73564.zip
Adding upstream version 11.4.5.upstream/11.4.5
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'sqlglot/helper.py')
-rw-r--r--sqlglot/helper.py11
1 files changed, 7 insertions, 4 deletions
diff --git a/sqlglot/helper.py b/sqlglot/helper.py
index 6eff974..d44d7dd 100644
--- a/sqlglot/helper.py
+++ b/sqlglot/helper.py
@@ -59,7 +59,7 @@ def ensure_list(value):
"""
if value is None:
return []
- elif isinstance(value, (list, tuple)):
+ if isinstance(value, (list, tuple)):
return list(value)
return [value]
@@ -162,9 +162,7 @@ def camel_to_snake_case(name: str) -> str:
return CAMEL_CASE_PATTERN.sub("_", name).upper()
-def while_changing(
- expression: t.Optional[Expression], func: t.Callable[[t.Optional[Expression]], E]
-) -> E:
+def while_changing(expression: Expression, func: t.Callable[[Expression], E]) -> E:
"""
Applies a transformation to a given expression until a fix point is reached.
@@ -176,8 +174,13 @@ def while_changing(
The transformed expression.
"""
while True:
+ for n, *_ in reversed(tuple(expression.walk())):
+ n._hash = hash(n)
start = hash(expression)
expression = func(expression)
+
+ for n, *_ in expression.walk():
+ n._hash = None
if start == hash(expression):
break
return expression