summaryrefslogtreecommitdiffstats
path: root/sqlglot/helper.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-08 08:11:53 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-08 08:12:02 +0000
commit8d36f5966675e23bee7026ba37ae0647fbf47300 (patch)
treedf4227bbb3b07cb70df87237bcff03c8efd7822d /sqlglot/helper.py
parentReleasing debian version 22.2.0-1. (diff)
downloadsqlglot-8d36f5966675e23bee7026ba37ae0647fbf47300.tar.xz
sqlglot-8d36f5966675e23bee7026ba37ae0647fbf47300.zip
Merging upstream version 23.7.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'sqlglot/helper.py')
-rw-r--r--sqlglot/helper.py16
1 files changed, 12 insertions, 4 deletions
diff --git a/sqlglot/helper.py b/sqlglot/helper.py
index 0d4547f..0187c51 100644
--- a/sqlglot/helper.py
+++ b/sqlglot/helper.py
@@ -181,7 +181,7 @@ def apply_index_offset(
annotate_types(expression)
if t.cast(exp.DataType, expression.type).this in exp.DataType.INTEGER_TYPES:
logger.warning("Applying array index offset (%s)", offset)
- expression = simplify(exp.Add(this=expression, expression=exp.Literal.number(offset)))
+ expression = simplify(expression + offset)
return [expression]
return expressions
@@ -204,13 +204,13 @@ def while_changing(expression: Expression, func: t.Callable[[Expression], E]) ->
The transformed expression.
"""
while True:
- for n, *_ in reversed(tuple(expression.walk())):
+ for n in reversed(tuple(expression.walk())):
n._hash = hash(n)
start = hash(expression)
expression = func(expression)
- for n, *_ in expression.walk():
+ for n in expression.walk():
n._hash = None
if start == hash(expression):
break
@@ -317,8 +317,16 @@ def find_new_name(taken: t.Collection[str], base: str) -> str:
def is_int(text: str) -> bool:
+ return is_type(text, int)
+
+
+def is_float(text: str) -> bool:
+ return is_type(text, float)
+
+
+def is_type(text: str, target_type: t.Type) -> bool:
try:
- int(text)
+ target_type(text)
return True
except ValueError:
return False