sqlglot 27.4.0__py3-none-any.whl → 27.5.0__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 CHANGED
@@ -17,5 +17,5 @@ __version__: str
17
17
  __version_tuple__: VERSION_TUPLE
18
18
  version_tuple: VERSION_TUPLE
19
19
 
20
- __version__ = version = '27.4.0'
21
- __version_tuple__ = version_tuple = (27, 4, 0)
20
+ __version__ = version = '27.5.0'
21
+ __version_tuple__ = version_tuple = (27, 5, 0)
@@ -378,11 +378,13 @@ def _annotate_array(self: TypeAnnotator, expression: exp.Array) -> exp.Array:
378
378
  and (query_type := select.meta.get("query_type")) is not None
379
379
  and query_type.is_type(exp.DataType.Type.STRUCT)
380
380
  and len(query_type.expressions) == 1
381
+ and isinstance(col_def := query_type.expressions[0], exp.ColumnDef)
382
+ and (projection_type := col_def.kind) is not None
383
+ and not projection_type.is_type(exp.DataType.Type.UNKNOWN)
381
384
  ):
382
- projection_type = query_type.expressions[0].kind.copy()
383
385
  array_type = exp.DataType(
384
386
  this=exp.DataType.Type.ARRAY,
385
- expressions=[projection_type],
387
+ expressions=[projection_type.copy()],
386
388
  nested=True,
387
389
  )
388
390
  return self._annotate_with_type(expression, array_type)
@@ -665,6 +665,7 @@ class DuckDB(Dialect):
665
665
  ARRAY_CONCAT_IS_VAR_LEN = False
666
666
  ARRAY_SIZE_DIM_REQUIRED = False
667
667
  NORMALIZE_EXTRACT_DATE_PARTS = True
668
+ SUPPORTS_LIKE_QUANTIFIERS = False
668
669
 
669
670
  TRANSFORMS = {
670
671
  **generator.Generator.TRANSFORMS,
@@ -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
- timestrtotime_sql,
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(
@@ -51,6 +51,7 @@ class Materialize(Postgres):
51
51
 
52
52
  class Generator(Postgres.Generator):
53
53
  SUPPORTS_CREATE_TABLE_LIKE = False
54
+ SUPPORTS_BETWEEN_FLAGS = False
54
55
 
55
56
  TRANSFORMS = {
56
57
  **Postgres.Generator.TRANSFORMS,
@@ -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)
@@ -274,8 +274,6 @@ class Postgres(Dialect):
274
274
  TABLESAMPLE_SIZE_IS_PERCENT = True
275
275
 
276
276
  TIME_MAPPING = {
277
- "AM": "%p",
278
- "PM": "%p",
279
277
  "d": "%u", # 1-based day of week
280
278
  "D": "%u", # 1-based day of week
281
279
  "dd": "%d", # day of month
@@ -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 = " "
@@ -61,6 +61,7 @@ class RisingWave(Postgres):
61
61
 
62
62
  class Generator(Postgres.Generator):
63
63
  LOCKING_READS_SUPPORTED = False
64
+ SUPPORTS_BETWEEN_FLAGS = False
64
65
 
65
66
  TRANSFORMS = {
66
67
  **Postgres.Generator.TRANSFORMS,