sqlglot 27.4.1__py3-none-any.whl → 27.5.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- sqlglot/_version.py +2 -2
- sqlglot/dialects/duckdb.py +1 -0
- sqlglot/dialects/exasol.py +44 -3
- sqlglot/dialects/materialize.py +1 -0
- sqlglot/dialects/oracle.py +0 -4
- sqlglot/dialects/postgres.py +0 -2
- sqlglot/dialects/redshift.py +1 -0
- sqlglot/dialects/risingwave.py +1 -0
- sqlglot/dialects/singlestore.py +1141 -0
- sqlglot/dialects/snowflake.py +0 -8
- sqlglot/expressions.py +7 -11
- sqlglot/generator.py +37 -10
- sqlglot/optimizer/eliminate_joins.py +3 -0
- sqlglot/optimizer/scope.py +6 -0
- sqlglot/parser.py +24 -8
- sqlglot/tokens.py +5 -2
- sqlglot/transforms.py +1 -1
- {sqlglot-27.4.1.dist-info → sqlglot-27.5.1.dist-info}/METADATA +1 -24
- {sqlglot-27.4.1.dist-info → sqlglot-27.5.1.dist-info}/RECORD +22 -22
- {sqlglot-27.4.1.dist-info → sqlglot-27.5.1.dist-info}/licenses/LICENSE +1 -1
- {sqlglot-27.4.1.dist-info → sqlglot-27.5.1.dist-info}/WHEEL +0 -0
- {sqlglot-27.4.1.dist-info → sqlglot-27.5.1.dist-info}/top_level.txt +0 -0
sqlglot/_version.py
CHANGED
sqlglot/dialects/duckdb.py
CHANGED
sqlglot/dialects/exasol.py
CHANGED
|
@@ -1,17 +1,25 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import typing as t
|
|
4
|
+
|
|
2
5
|
from sqlglot import exp, generator, parser, tokens
|
|
6
|
+
from sqlglot.dialects.clickhouse import timestamptrunc_sql
|
|
3
7
|
from sqlglot.dialects.dialect import (
|
|
4
8
|
Dialect,
|
|
5
|
-
rename_func,
|
|
6
9
|
binary_from_function,
|
|
7
10
|
build_formatted_time,
|
|
8
|
-
|
|
11
|
+
rename_func,
|
|
9
12
|
strposition_sql,
|
|
13
|
+
timestrtotime_sql,
|
|
14
|
+
unit_to_str,
|
|
10
15
|
)
|
|
11
|
-
from sqlglot.helper import seq_get
|
|
12
16
|
from sqlglot.generator import unsupported_args
|
|
17
|
+
from sqlglot.helper import seq_get
|
|
13
18
|
from sqlglot.tokens import TokenType
|
|
14
19
|
|
|
20
|
+
if t.TYPE_CHECKING:
|
|
21
|
+
from sqlglot.dialects.dialect import DialectType
|
|
22
|
+
|
|
15
23
|
|
|
16
24
|
def _sha2_sql(self: Exasol.Generator, expression: exp.SHA2) -> str:
|
|
17
25
|
length = expression.text("length")
|
|
@@ -19,6 +27,25 @@ def _sha2_sql(self: Exasol.Generator, expression: exp.SHA2) -> str:
|
|
|
19
27
|
return self.func(func_name, expression.this)
|
|
20
28
|
|
|
21
29
|
|
|
30
|
+
# https://docs.exasol.com/db/latest/sql_references/functions/alphabeticallistfunctions/trunc%5Bate%5D%20(datetime).htm
|
|
31
|
+
# https://docs.exasol.com/db/latest/sql_references/functions/alphabeticallistfunctions/trunc%5Bate%5D%20(number).htm
|
|
32
|
+
def _build_trunc(args: t.List[exp.Expression], dialect: DialectType) -> exp.Expression:
|
|
33
|
+
first, second = seq_get(args, 0), seq_get(args, 1)
|
|
34
|
+
|
|
35
|
+
if not first or not second:
|
|
36
|
+
return exp.Anonymous(this="TRUNC", expressions=args)
|
|
37
|
+
|
|
38
|
+
if not first.type:
|
|
39
|
+
from sqlglot.optimizer.annotate_types import annotate_types
|
|
40
|
+
|
|
41
|
+
first = annotate_types(first, dialect=dialect)
|
|
42
|
+
|
|
43
|
+
if first.is_type(exp.DataType.Type.DATE, exp.DataType.Type.TIMESTAMP) and second.is_string:
|
|
44
|
+
return exp.DateTrunc(this=first, unit=second)
|
|
45
|
+
|
|
46
|
+
return exp.Anonymous(this="TRUNC", expressions=args)
|
|
47
|
+
|
|
48
|
+
|
|
22
49
|
class Exasol(Dialect):
|
|
23
50
|
TIME_MAPPING = {
|
|
24
51
|
"yyyy": "%Y",
|
|
@@ -63,12 +90,17 @@ class Exasol(Dialect):
|
|
|
63
90
|
"BIT_NOT": lambda args: exp.BitwiseNot(this=seq_get(args, 0)),
|
|
64
91
|
"BIT_LSHIFT": binary_from_function(exp.BitwiseLeftShift),
|
|
65
92
|
"BIT_RSHIFT": binary_from_function(exp.BitwiseRightShift),
|
|
93
|
+
# https://docs.exasol.com/db/latest/sql_references/functions/alphabeticallistfunctions/date_trunc.htm#DATE_TRUNC
|
|
94
|
+
"DATE_TRUNC": lambda args: exp.TimestampTrunc(
|
|
95
|
+
this=seq_get(args, 1), unit=seq_get(args, 0)
|
|
96
|
+
),
|
|
66
97
|
"EVERY": lambda args: exp.All(this=seq_get(args, 0)),
|
|
67
98
|
"EDIT_DISTANCE": exp.Levenshtein.from_arg_list,
|
|
68
99
|
"HASH_SHA": exp.SHA.from_arg_list,
|
|
69
100
|
"HASH_SHA1": exp.SHA.from_arg_list,
|
|
70
101
|
"HASH_MD5": exp.MD5.from_arg_list,
|
|
71
102
|
"HASHTYPE_MD5": exp.MD5Digest.from_arg_list,
|
|
103
|
+
"REGEXP_SUBSTR": exp.RegexpExtract.from_arg_list,
|
|
72
104
|
"REGEXP_REPLACE": lambda args: exp.RegexpReplace(
|
|
73
105
|
this=seq_get(args, 0),
|
|
74
106
|
expression=seq_get(args, 1),
|
|
@@ -82,6 +114,8 @@ class Exasol(Dialect):
|
|
|
82
114
|
"HASH_SHA512": lambda args: exp.SHA2(
|
|
83
115
|
this=seq_get(args, 0), length=exp.Literal.number(512)
|
|
84
116
|
),
|
|
117
|
+
"TRUNC": _build_trunc,
|
|
118
|
+
"TRUNCATE": _build_trunc,
|
|
85
119
|
"VAR_POP": exp.VariancePop.from_arg_list,
|
|
86
120
|
"APPROXIMATE_COUNT_DISTINCT": exp.ApproxDistinct.from_arg_list,
|
|
87
121
|
"TO_CHAR": build_formatted_time(exp.ToChar, "exasol"),
|
|
@@ -155,12 +189,18 @@ class Exasol(Dialect):
|
|
|
155
189
|
exp.BitwiseXor: rename_func("BIT_XOR"),
|
|
156
190
|
# https://docs.exasol.com/db/latest/sql_references/functions/alphabeticallistfunctions/every.htm
|
|
157
191
|
exp.All: rename_func("EVERY"),
|
|
192
|
+
exp.DateTrunc: lambda self, e: self.func("TRUNC", e.this, unit_to_str(e)),
|
|
193
|
+
exp.DatetimeTrunc: timestamptrunc_sql(),
|
|
158
194
|
# https://docs.exasol.com/db/latest/sql_references/functions/alphabeticallistfunctions/edit_distance.htm#EDIT_DISTANCE
|
|
159
195
|
exp.Levenshtein: unsupported_args("ins_cost", "del_cost", "sub_cost", "max_dist")(
|
|
160
196
|
rename_func("EDIT_DISTANCE")
|
|
161
197
|
),
|
|
162
198
|
# https://docs.exasol.com/db/latest/sql_references/functions/alphabeticallistfunctions/mod.htm
|
|
163
199
|
exp.Mod: rename_func("MOD"),
|
|
200
|
+
# https://docs.exasol.com/db/latest/sql_references/functions/alphabeticallistfunctions/regexp_substr.htm
|
|
201
|
+
exp.RegexpExtract: unsupported_args("parameters", "group")(
|
|
202
|
+
rename_func("REGEXP_SUBSTR")
|
|
203
|
+
),
|
|
164
204
|
# https://docs.exasol.com/db/latest/sql_references/functions/alphabeticallistfunctions/regexp_replace.htm
|
|
165
205
|
exp.RegexpReplace: unsupported_args("modifiers")(rename_func("REGEXP_REPLACE")),
|
|
166
206
|
# https://docs.exasol.com/db/latest/sql_references/functions/alphabeticallistfunctions/var_pop.htm
|
|
@@ -175,6 +215,7 @@ class Exasol(Dialect):
|
|
|
175
215
|
exp.TsOrDsToDate: lambda self, e: self.func("TO_DATE", e.this, self.format_time(e)),
|
|
176
216
|
exp.TimeToStr: lambda self, e: self.func("TO_CHAR", e.this, self.format_time(e)),
|
|
177
217
|
exp.TimeStrToTime: timestrtotime_sql,
|
|
218
|
+
exp.TimestampTrunc: timestamptrunc_sql(),
|
|
178
219
|
exp.StrToTime: lambda self, e: self.func("TO_DATE", e.this, self.format_time(e)),
|
|
179
220
|
exp.CurrentUser: lambda *_: "CURRENT_USER",
|
|
180
221
|
exp.AtTimeZone: lambda self, e: self.func(
|
sqlglot/dialects/materialize.py
CHANGED
sqlglot/dialects/oracle.py
CHANGED
|
@@ -52,10 +52,6 @@ class Oracle(Dialect):
|
|
|
52
52
|
# https://docs.oracle.com/database/121/SQLRF/sql_elements004.htm#SQLRF00212
|
|
53
53
|
# https://docs.python.org/3/library/datetime.html#strftime-and-strptime-format-codes
|
|
54
54
|
TIME_MAPPING = {
|
|
55
|
-
"AM": "%p", # Meridian indicator with or without periods
|
|
56
|
-
"A.M.": "%p", # Meridian indicator with or without periods
|
|
57
|
-
"PM": "%p", # Meridian indicator with or without periods
|
|
58
|
-
"P.M.": "%p", # Meridian indicator with or without periods
|
|
59
55
|
"D": "%u", # Day of week (1-7)
|
|
60
56
|
"DAY": "%A", # name of day
|
|
61
57
|
"DD": "%d", # day of month (1-31)
|
sqlglot/dialects/postgres.py
CHANGED
sqlglot/dialects/redshift.py
CHANGED
|
@@ -161,6 +161,7 @@ class Redshift(Postgres):
|
|
|
161
161
|
SUPPORTS_MEDIAN = True
|
|
162
162
|
ALTER_SET_TYPE = "TYPE"
|
|
163
163
|
SUPPORTS_DECODE_CASE = True
|
|
164
|
+
SUPPORTS_BETWEEN_FLAGS = False
|
|
164
165
|
|
|
165
166
|
# Redshift doesn't have `WITH` as part of their with_properties so we remove it
|
|
166
167
|
WITH_PROPERTIES_PREFIX = " "
|