sqlglotc 30.30.0__tar.gz → 30.32.0__tar.gz
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.
- {sqlglotc-30.30.0/sqlglotc.egg-info → sqlglotc-30.32.0}/PKG-INFO +2 -2
- {sqlglotc-30.30.0 → sqlglotc-30.32.0}/sqlglot/expressions/aggregate.py +8 -1
- {sqlglotc-30.30.0 → sqlglotc-30.32.0}/sqlglot/expressions/array.py +1 -0
- {sqlglotc-30.30.0 → sqlglotc-30.32.0}/sqlglot/expressions/core.py +41 -3
- {sqlglotc-30.30.0 → sqlglotc-30.32.0}/sqlglot/expressions/properties.py +4 -0
- {sqlglotc-30.30.0 → sqlglotc-30.32.0}/sqlglot/expressions/query.py +9 -2
- {sqlglotc-30.30.0 → sqlglotc-30.32.0}/sqlglot/expressions/string.py +2 -0
- {sqlglotc-30.30.0 → sqlglotc-30.32.0}/sqlglot/expressions/temporal.py +15 -3
- {sqlglotc-30.30.0 → sqlglotc-30.32.0}/sqlglot/generator.py +168 -27
- {sqlglotc-30.30.0 → sqlglotc-30.32.0}/sqlglot/generators/athena.py +1 -1
- {sqlglotc-30.30.0 → sqlglotc-30.32.0}/sqlglot/generators/bigquery.py +55 -4
- {sqlglotc-30.30.0 → sqlglotc-30.32.0}/sqlglot/generators/clickhouse.py +37 -3
- {sqlglotc-30.30.0 → sqlglotc-30.32.0}/sqlglot/generators/databricks.py +66 -1
- {sqlglotc-30.30.0 → sqlglotc-30.32.0}/sqlglot/generators/dremio.py +1 -1
- {sqlglotc-30.30.0 → sqlglotc-30.32.0}/sqlglot/generators/drill.py +1 -1
- {sqlglotc-30.30.0 → sqlglotc-30.32.0}/sqlglot/generators/druid.py +3 -3
- {sqlglotc-30.30.0 → sqlglotc-30.32.0}/sqlglot/generators/duckdb.py +109 -26
- sqlglotc-30.32.0/sqlglot/generators/dune.py +16 -0
- {sqlglotc-30.30.0 → sqlglotc-30.32.0}/sqlglot/generators/exasol.py +17 -14
- {sqlglotc-30.30.0 → sqlglotc-30.32.0}/sqlglot/generators/hive.py +26 -3
- {sqlglotc-30.30.0 → sqlglotc-30.32.0}/sqlglot/generators/mysql.py +9 -3
- {sqlglotc-30.30.0 → sqlglotc-30.32.0}/sqlglot/generators/oracle.py +18 -3
- {sqlglotc-30.30.0 → sqlglotc-30.32.0}/sqlglot/generators/postgres.py +13 -3
- {sqlglotc-30.30.0 → sqlglotc-30.32.0}/sqlglot/generators/presto.py +14 -3
- {sqlglotc-30.30.0 → sqlglotc-30.32.0}/sqlglot/generators/redshift.py +20 -5
- {sqlglotc-30.30.0 → sqlglotc-30.32.0}/sqlglot/generators/singlestore.py +0 -1
- {sqlglotc-30.30.0 → sqlglotc-30.32.0}/sqlglot/generators/snowflake.py +20 -6
- {sqlglotc-30.30.0 → sqlglotc-30.32.0}/sqlglot/generators/spark.py +12 -0
- {sqlglotc-30.30.0 → sqlglotc-30.32.0}/sqlglot/generators/spark2.py +9 -1
- {sqlglotc-30.30.0 → sqlglotc-30.32.0}/sqlglot/generators/sqlite.py +43 -2
- {sqlglotc-30.30.0 → sqlglotc-30.32.0}/sqlglot/generators/tableau.py +1 -1
- {sqlglotc-30.30.0 → sqlglotc-30.32.0}/sqlglot/generators/teradata.py +29 -1
- {sqlglotc-30.30.0 → sqlglotc-30.32.0}/sqlglot/generators/trino.py +1 -0
- {sqlglotc-30.30.0 → sqlglotc-30.32.0}/sqlglot/generators/tsql.py +23 -2
- {sqlglotc-30.30.0 → sqlglotc-30.32.0}/sqlglot/optimizer/annotate_types.py +2 -0
- {sqlglotc-30.30.0 → sqlglotc-30.32.0}/sqlglot/optimizer/qualify_columns.py +136 -28
- {sqlglotc-30.30.0 → sqlglotc-30.32.0}/sqlglot/optimizer/qualify_tables.py +2 -2
- {sqlglotc-30.30.0 → sqlglotc-30.32.0}/sqlglot/optimizer/resolver.py +59 -10
- {sqlglotc-30.30.0 → sqlglotc-30.32.0}/sqlglot/optimizer/scope.py +17 -2
- {sqlglotc-30.30.0 → sqlglotc-30.32.0}/sqlglot/optimizer/simplify.py +56 -10
- {sqlglotc-30.30.0 → sqlglotc-30.32.0}/sqlglot/parser.py +94 -39
- {sqlglotc-30.30.0 → sqlglotc-30.32.0}/sqlglot/parsers/bigquery.py +26 -6
- {sqlglotc-30.30.0 → sqlglotc-30.32.0}/sqlglot/parsers/clickhouse.py +16 -1
- {sqlglotc-30.30.0 → sqlglotc-30.32.0}/sqlglot/parsers/duckdb.py +14 -2
- {sqlglotc-30.30.0 → sqlglotc-30.32.0}/sqlglot/parsers/exasol.py +5 -5
- {sqlglotc-30.30.0 → sqlglotc-30.32.0}/sqlglot/parsers/hive.py +1 -0
- {sqlglotc-30.30.0 → sqlglotc-30.32.0}/sqlglot/parsers/mysql.py +6 -0
- {sqlglotc-30.30.0 → sqlglotc-30.32.0}/sqlglot/parsers/oracle.py +8 -3
- {sqlglotc-30.30.0 → sqlglotc-30.32.0}/sqlglot/parsers/postgres.py +19 -10
- {sqlglotc-30.30.0 → sqlglotc-30.32.0}/sqlglot/parsers/presto.py +15 -2
- {sqlglotc-30.30.0 → sqlglotc-30.32.0}/sqlglot/parsers/snowflake.py +19 -4
- {sqlglotc-30.30.0 → sqlglotc-30.32.0}/sqlglot/parsers/spark.py +5 -0
- {sqlglotc-30.30.0 → sqlglotc-30.32.0}/sqlglot/parsers/spark2.py +6 -0
- {sqlglotc-30.30.0 → sqlglotc-30.32.0}/sqlglot/parsers/sqlite.py +22 -2
- {sqlglotc-30.30.0 → sqlglotc-30.32.0}/sqlglot/parsers/teradata.py +167 -12
- {sqlglotc-30.30.0 → sqlglotc-30.32.0}/sqlglot/tokenizer_core.py +17 -2
- {sqlglotc-30.30.0 → sqlglotc-30.32.0/sqlglotc.egg-info}/PKG-INFO +2 -2
- {sqlglotc-30.30.0 → sqlglotc-30.32.0}/sqlglotc.egg-info/requires.txt +1 -1
- sqlglotc-30.32.0/sqlglotc.egg-info/scm_version.json +8 -0
- sqlglotc-30.30.0/sqlglot/generators/dune.py +0 -14
- sqlglotc-30.30.0/sqlglotc.egg-info/scm_version.json +0 -8
- {sqlglotc-30.30.0 → sqlglotc-30.32.0}/MANIFEST.in +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.32.0}/pyproject.toml +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.32.0}/setup.cfg +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.32.0}/setup.py +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.32.0}/sqlglot/anonymize.py +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.32.0}/sqlglot/errors.py +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.32.0}/sqlglot/executor/table.py +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.32.0}/sqlglot/expressions/builders.py +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.32.0}/sqlglot/expressions/constraints.py +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.32.0}/sqlglot/expressions/datatypes.py +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.32.0}/sqlglot/expressions/ddl.py +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.32.0}/sqlglot/expressions/dml.py +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.32.0}/sqlglot/expressions/functions.py +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.32.0}/sqlglot/expressions/json.py +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.32.0}/sqlglot/expressions/math.py +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.32.0}/sqlglot/generators/dax.py +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.32.0}/sqlglot/generators/doris.py +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.32.0}/sqlglot/generators/fabric.py +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.32.0}/sqlglot/generators/materialize.py +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.32.0}/sqlglot/generators/prql.py +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.32.0}/sqlglot/generators/python.py +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.32.0}/sqlglot/generators/risingwave.py +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.32.0}/sqlglot/generators/solr.py +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.32.0}/sqlglot/generators/starrocks.py +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.32.0}/sqlglot/helper.py +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.32.0}/sqlglot/lineage.py +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.32.0}/sqlglot/optimizer/canonicalize_internal_names.py +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.32.0}/sqlglot/optimizer/isolate_table_selects.py +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.32.0}/sqlglot/optimizer/normalize_identifiers.py +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.32.0}/sqlglot/optimizer/qualify.py +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.32.0}/sqlglot/parsers/athena.py +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.32.0}/sqlglot/parsers/base.py +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.32.0}/sqlglot/parsers/databricks.py +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.32.0}/sqlglot/parsers/dax.py +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.32.0}/sqlglot/parsers/doris.py +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.32.0}/sqlglot/parsers/dremio.py +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.32.0}/sqlglot/parsers/drill.py +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.32.0}/sqlglot/parsers/druid.py +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.32.0}/sqlglot/parsers/dune.py +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.32.0}/sqlglot/parsers/fabric.py +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.32.0}/sqlglot/parsers/materialize.py +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.32.0}/sqlglot/parsers/prql.py +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.32.0}/sqlglot/parsers/redshift.py +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.32.0}/sqlglot/parsers/risingwave.py +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.32.0}/sqlglot/parsers/singlestore.py +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.32.0}/sqlglot/parsers/solr.py +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.32.0}/sqlglot/parsers/starrocks.py +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.32.0}/sqlglot/parsers/tableau.py +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.32.0}/sqlglot/parsers/trino.py +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.32.0}/sqlglot/parsers/tsql.py +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.32.0}/sqlglot/serde.py +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.32.0}/sqlglot/time.py +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.32.0}/sqlglot/trie.py +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.32.0}/sqlglotc.egg-info/SOURCES.txt +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.32.0}/sqlglotc.egg-info/dependency_links.txt +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.32.0}/sqlglotc.egg-info/scm_file_list.json +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.32.0}/sqlglotc.egg-info/top_level.txt +0 -0
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: sqlglotc
|
|
3
|
-
Version: 30.
|
|
3
|
+
Version: 30.32.0
|
|
4
4
|
Summary: mypyc-compiled extensions for sqlglot
|
|
5
5
|
Author-email: Toby Mao <toby.mao@gmail.com>
|
|
6
6
|
License-Expression: MIT
|
|
7
7
|
Project-URL: Homepage, https://sqlglot.com/
|
|
8
8
|
Project-URL: Repository, https://github.com/tobymao/sqlglot
|
|
9
9
|
Requires-Python: >=3.10
|
|
10
|
-
Requires-Dist: sqlglot==30.
|
|
10
|
+
Requires-Dist: sqlglot==30.32.0
|
|
11
11
|
Provides-Extra: dev
|
|
12
12
|
Requires-Dist: setuptools>=61.0; extra == "dev"
|
|
13
13
|
Requires-Dist: setuptools_scm>=10.2; extra == "dev"
|
|
@@ -138,7 +138,12 @@ class FirstValue(Expression, AggFunc):
|
|
|
138
138
|
|
|
139
139
|
|
|
140
140
|
class GroupConcat(Expression, AggFunc):
|
|
141
|
-
arg_types = {
|
|
141
|
+
arg_types = {
|
|
142
|
+
"this": True,
|
|
143
|
+
"separator": False,
|
|
144
|
+
"on_overflow": False,
|
|
145
|
+
"null_separator_is_empty": False,
|
|
146
|
+
}
|
|
142
147
|
|
|
143
148
|
|
|
144
149
|
class Grouping(Expression, AggFunc):
|
|
@@ -322,6 +327,8 @@ class Sum(Expression, AggFunc):
|
|
|
322
327
|
|
|
323
328
|
|
|
324
329
|
class Variance(Expression, AggFunc):
|
|
330
|
+
# single_value_returns_zero: Oracle's VARIANCE returns 0 instead of NULL for a single value
|
|
331
|
+
arg_types = {"this": True, "single_value_returns_zero": False}
|
|
325
332
|
_sql_names = ["VARIANCE", "VARIANCE_SAMP", "VAR_SAMP"]
|
|
326
333
|
|
|
327
334
|
|
|
@@ -46,6 +46,7 @@ TABLE_PARTS = ("this", "db", "catalog")
|
|
|
46
46
|
COLUMN_PARTS = ("this", "table", "db", "catalog")
|
|
47
47
|
POSITION_META_KEYS: tuple[str, ...] = ("line", "col", "start", "end")
|
|
48
48
|
UNITTEST: bool = "unittest" in sys.modules or "pytest" in sys.modules
|
|
49
|
+
_IMMUTABLE_META_TYPES: frozenset[type] = frozenset((int, str, bool, float, type(None)))
|
|
49
50
|
|
|
50
51
|
|
|
51
52
|
@trait
|
|
@@ -1014,7 +1015,11 @@ class Expression(Expr):
|
|
|
1014
1015
|
if node._type is not None:
|
|
1015
1016
|
copy._type = deepcopy(node._type)
|
|
1016
1017
|
if node._meta is not None:
|
|
1017
|
-
|
|
1018
|
+
# Positions and flags are immutable, so only other values need a deep copy
|
|
1019
|
+
meta = copy._meta = dict(node._meta)
|
|
1020
|
+
for k, v in meta.items():
|
|
1021
|
+
if type(v) not in _IMMUTABLE_META_TYPES:
|
|
1022
|
+
meta[k] = deepcopy(v)
|
|
1018
1023
|
if node._hash is not None:
|
|
1019
1024
|
copy._hash = node._hash
|
|
1020
1025
|
|
|
@@ -2240,7 +2245,7 @@ class LTE(Expression, Binary, Predicate):
|
|
|
2240
2245
|
|
|
2241
2246
|
|
|
2242
2247
|
class Mod(Expression, Binary):
|
|
2243
|
-
|
|
2248
|
+
arg_types = {"this": True, "expression": True, "safe": False}
|
|
2244
2249
|
|
|
2245
2250
|
|
|
2246
2251
|
class Mul(Expression, Binary):
|
|
@@ -2289,6 +2294,10 @@ class Paren(Unary):
|
|
|
2289
2294
|
return self.this.name
|
|
2290
2295
|
|
|
2291
2296
|
|
|
2297
|
+
class Pos(Unary):
|
|
2298
|
+
pass
|
|
2299
|
+
|
|
2300
|
+
|
|
2292
2301
|
class Neg(Unary):
|
|
2293
2302
|
def to_py(self) -> int | Decimal:
|
|
2294
2303
|
if self.is_number:
|
|
@@ -2301,7 +2310,8 @@ class AtIndex(Expression):
|
|
|
2301
2310
|
|
|
2302
2311
|
|
|
2303
2312
|
class AtTimeZone(Expression):
|
|
2304
|
-
|
|
2313
|
+
# session_zone: a zoneless operand is read in the session time zone (e.g. Presto, Trino)
|
|
2314
|
+
arg_types = {"this": True, "zone": True, "session_zone": False}
|
|
2305
2315
|
|
|
2306
2316
|
|
|
2307
2317
|
class FromTimeZone(Expression):
|
|
@@ -2317,6 +2327,34 @@ class FormatPhrase(Expression):
|
|
|
2317
2327
|
|
|
2318
2328
|
arg_types = {"this": True, "format": True}
|
|
2319
2329
|
|
|
2330
|
+
@property
|
|
2331
|
+
def name(self) -> str:
|
|
2332
|
+
return self.this.name
|
|
2333
|
+
|
|
2334
|
+
@property
|
|
2335
|
+
def output_name(self) -> str:
|
|
2336
|
+
return self.this.output_name
|
|
2337
|
+
|
|
2338
|
+
|
|
2339
|
+
class TeradataTitle(Expression):
|
|
2340
|
+
"""A Teradata TITLE display heading, which does not rename the expression."""
|
|
2341
|
+
|
|
2342
|
+
arg_types = {"this": True, "title": True}
|
|
2343
|
+
|
|
2344
|
+
@property
|
|
2345
|
+
def name(self) -> str:
|
|
2346
|
+
return self.this.name
|
|
2347
|
+
|
|
2348
|
+
@property
|
|
2349
|
+
def output_name(self) -> str:
|
|
2350
|
+
return self.this.output_name
|
|
2351
|
+
|
|
2352
|
+
|
|
2353
|
+
class TeradataNamed(Alias):
|
|
2354
|
+
"""A Teradata NAMED alias on a subexpression; projections use ordinary Alias."""
|
|
2355
|
+
|
|
2356
|
+
arg_types = {"this": True, "alias": True}
|
|
2357
|
+
|
|
2320
2358
|
|
|
2321
2359
|
class Between(Expression, Predicate):
|
|
2322
2360
|
arg_types = {"this": True, "low": True, "high": True, "symmetric": False}
|
|
@@ -493,7 +493,9 @@ class BitString(Expression, Condition):
|
|
|
493
493
|
|
|
494
494
|
|
|
495
495
|
class HexString(Expression, Condition):
|
|
496
|
-
|
|
496
|
+
"""Encoded hexadecimal data, binary by default or integer/character when flagged."""
|
|
497
|
+
|
|
498
|
+
arg_types = {"this": True, "is_integer": False, "is_character": False}
|
|
497
499
|
is_primitive = True
|
|
498
500
|
|
|
499
501
|
|
|
@@ -706,6 +708,8 @@ class Join(Expression):
|
|
|
706
708
|
"pivots": False,
|
|
707
709
|
}
|
|
708
710
|
|
|
711
|
+
QUALIFIERS: t.ClassVar[tuple[str, ...]] = ("on", "using", "side", "kind", "method", "nearest")
|
|
712
|
+
|
|
709
713
|
@property
|
|
710
714
|
def method(self) -> str:
|
|
711
715
|
return self.text("method").upper()
|
|
@@ -1489,7 +1493,10 @@ class Select(Expression, Query):
|
|
|
1489
1493
|
except ParseError:
|
|
1490
1494
|
expression = maybe_parse(expression, into=(Join, Expr), **parse_args)
|
|
1491
1495
|
|
|
1492
|
-
join = expression if isinstance(expression, Join) else Join(this=expression)
|
|
1496
|
+
join = expression if isinstance(expression, Join) else Join(this=expression, kind="CROSS")
|
|
1497
|
+
|
|
1498
|
+
if join.kind == "CROSS" and (on or using or join_type):
|
|
1499
|
+
join.set("kind", None)
|
|
1493
1500
|
|
|
1494
1501
|
if isinstance(join.this, Select):
|
|
1495
1502
|
join.this.replace(join.this.subquery())
|
|
@@ -438,6 +438,7 @@ class RegexpExtract(Expression, Func):
|
|
|
438
438
|
"null_if_pos_overflow": False,
|
|
439
439
|
"null_if_no_match": False,
|
|
440
440
|
"empty_if_group_missing": False,
|
|
441
|
+
"inferred_group": False,
|
|
441
442
|
}
|
|
442
443
|
|
|
443
444
|
|
|
@@ -449,6 +450,7 @@ class RegexpExtractAll(Expression, Func):
|
|
|
449
450
|
"parameters": False,
|
|
450
451
|
"position": False,
|
|
451
452
|
"occurrence": False,
|
|
453
|
+
"inferred_group": False,
|
|
452
454
|
}
|
|
453
455
|
|
|
454
456
|
|
|
@@ -135,7 +135,7 @@ class TimestampAdd(Expression, Func, TimeUnit):
|
|
|
135
135
|
|
|
136
136
|
class TimestampDiff(Expression, Func, TimeUnit):
|
|
137
137
|
_sql_names = ["TIMESTAMPDIFF", "TIMESTAMP_DIFF"]
|
|
138
|
-
arg_types = {"this": True, "expression": True, "unit": False}
|
|
138
|
+
arg_types = {"this": True, "expression": True, "unit": False, "boundary_for_date": False}
|
|
139
139
|
|
|
140
140
|
|
|
141
141
|
class TimestampSub(Expression, Func, TimeUnit):
|
|
@@ -163,7 +163,13 @@ class DatetimeTrunc(Expression, Func, TimeUnit):
|
|
|
163
163
|
|
|
164
164
|
|
|
165
165
|
class DateTrunc(Expression, Func):
|
|
166
|
-
arg_types = {
|
|
166
|
+
arg_types = {
|
|
167
|
+
"unit": True,
|
|
168
|
+
"this": True,
|
|
169
|
+
"zone": False,
|
|
170
|
+
"input_type_preserved": False,
|
|
171
|
+
"century_from_zero": False,
|
|
172
|
+
}
|
|
167
173
|
|
|
168
174
|
def __init__(self, **args):
|
|
169
175
|
# Across most dialects it's safe to unabbreviate the unit (e.g. 'Q' -> 'QUARTER') except Oracle
|
|
@@ -188,7 +194,13 @@ class DateTrunc(Expression, Func):
|
|
|
188
194
|
|
|
189
195
|
|
|
190
196
|
class TimestampTrunc(Expression, Func, TimeUnit):
|
|
191
|
-
arg_types = {
|
|
197
|
+
arg_types = {
|
|
198
|
+
"this": True,
|
|
199
|
+
"unit": True,
|
|
200
|
+
"zone": False,
|
|
201
|
+
"input_type_preserved": False,
|
|
202
|
+
"century_from_zero": False,
|
|
203
|
+
}
|
|
192
204
|
|
|
193
205
|
|
|
194
206
|
class TimeSlice(Expression, Func, TimeUnit):
|
|
@@ -48,15 +48,8 @@ def unsupported_args(
|
|
|
48
48
|
def decorator(func: GeneratorMethod) -> GeneratorMethod:
|
|
49
49
|
@wraps(func)
|
|
50
50
|
def _func(generator: G, expression: E) -> str:
|
|
51
|
-
expression_name = expression.__class__.__name__
|
|
52
|
-
dialect_name = generator.dialect.__class__.__name__
|
|
53
|
-
|
|
54
51
|
for arg_name, diagnostic in diagnostic_by_arg.items():
|
|
55
|
-
|
|
56
|
-
diagnostic = diagnostic or UNSUPPORTED_TEMPLATE.format(
|
|
57
|
-
arg_name, expression_name, dialect_name
|
|
58
|
-
)
|
|
59
|
-
generator.unsupported(diagnostic)
|
|
52
|
+
generator._warn_unsupported_arg(expression, arg_name, diagnostic)
|
|
60
53
|
|
|
61
54
|
return func(generator, expression)
|
|
62
55
|
|
|
@@ -298,6 +291,7 @@ class Generator:
|
|
|
298
291
|
exp.WithProcedureOptions: lambda self, e: f"WITH {self.expressions(e, flat=True)}",
|
|
299
292
|
exp.WithSchemaBindingProperty: lambda self, e: f"WITH SCHEMA {self.sql(e, 'this')}",
|
|
300
293
|
exp.WithOperator: lambda self, e: f"{self.sql(e, 'this')} WITH {self.sql(e, 'op')}",
|
|
294
|
+
exp.WithoutRowidProperty: lambda *_: "WITHOUT ROWID",
|
|
301
295
|
exp.ForceProperty: lambda *_: "FORCE",
|
|
302
296
|
}
|
|
303
297
|
|
|
@@ -309,6 +303,9 @@ class Generator:
|
|
|
309
303
|
# Window functions that support NULLS FIRST/LAST
|
|
310
304
|
WINDOW_FUNCS_WITH_NULL_ORDERING: t.ClassVar[tuple[type[exp.Expression], ...]] = ()
|
|
311
305
|
|
|
306
|
+
# Window functions that require an ORDER BY in their window specification
|
|
307
|
+
WINDOW_FUNCS_REQUIRING_ORDER: t.ClassVar[tuple[type[exp.Expression], ...]] = ()
|
|
308
|
+
|
|
312
309
|
# Whether ignore nulls is inside the agg or outside.
|
|
313
310
|
# FIRST(x IGNORE NULLS) OVER vs FIRST (x) IGNORE NULLS OVER
|
|
314
311
|
IGNORE_NULLS_IN_FUNC = False
|
|
@@ -378,6 +375,12 @@ class Generator:
|
|
|
378
375
|
# Whether top-k distance/similarity joins are supported
|
|
379
376
|
SUPPORTS_NEAREST_JOIN = False
|
|
380
377
|
|
|
378
|
+
# Whether MATCH_CONDITION in ASOF joins is supported
|
|
379
|
+
SUPPORTS_MATCH_CONDITION = False
|
|
380
|
+
|
|
381
|
+
# Whether ASOF JOIN MATCH_CONDITION should be folded into the ON clause
|
|
382
|
+
MATCH_CONDITION_IN_ON = False
|
|
383
|
+
|
|
381
384
|
# Whether table hints should be generated
|
|
382
385
|
TABLE_HINTS = True
|
|
383
386
|
|
|
@@ -415,7 +418,7 @@ class Generator:
|
|
|
415
418
|
NVL2_SUPPORTED = True
|
|
416
419
|
|
|
417
420
|
# https://cloud.google.com/bigquery/docs/reference/standard-sql/query-syntax
|
|
418
|
-
SELECT_KINDS: tuple[str, ...] = ("STRUCT", "VALUE")
|
|
421
|
+
SELECT_KINDS: t.ClassVar[tuple[str, ...]] = ("STRUCT", "VALUE")
|
|
419
422
|
|
|
420
423
|
# Whether VALUES statements can be used as derived tables.
|
|
421
424
|
# MySQL 5 and Redshift do not allow this, so when False, it will convert
|
|
@@ -625,6 +628,12 @@ class Generator:
|
|
|
625
628
|
# The function name of the exp.ArraySize expression
|
|
626
629
|
ARRAY_SIZE_NAME: str = "ARRAY_LENGTH"
|
|
627
630
|
|
|
631
|
+
# Override for sample variance; otherwise use the expression's function name.
|
|
632
|
+
VARIANCE_NAME: str = ""
|
|
633
|
+
|
|
634
|
+
# Whether VARIANCE natively returns zero for a single non-NULL value.
|
|
635
|
+
VARIANCE_RETURNS_ZERO_ON_SINGLE_VALUE = False
|
|
636
|
+
|
|
628
637
|
# The syntax to use when altering the type of a column
|
|
629
638
|
ALTER_SET_TYPE = "SET DATA TYPE"
|
|
630
639
|
|
|
@@ -637,6 +646,9 @@ class Generator:
|
|
|
637
646
|
# Whether a multi-argument DECODE(...) function is supported. If not, a CASE expression is generated
|
|
638
647
|
SUPPORTS_DECODE_CASE = True
|
|
639
648
|
|
|
649
|
+
# Whether CHR / CHAR accepts multiple code points, e.g. CHAR(72, 105). If not, the calls are concatenated
|
|
650
|
+
SUPPORTS_MULTI_ARG_CHR = True
|
|
651
|
+
|
|
640
652
|
# Whether SYMMETRIC and ASYMMETRIC flags are supported with BETWEEN expression
|
|
641
653
|
SUPPORTS_BETWEEN_FLAGS = False
|
|
642
654
|
|
|
@@ -746,8 +758,8 @@ class Generator:
|
|
|
746
758
|
exp.DictRange: exp.Properties.Location.POST_SCHEMA,
|
|
747
759
|
exp.DictProperty: exp.Properties.Location.POST_SCHEMA,
|
|
748
760
|
exp.DynamicProperty: exp.Properties.Location.POST_CREATE,
|
|
749
|
-
exp.DistKeyProperty: exp.Properties.Location.
|
|
750
|
-
exp.DistStyleProperty: exp.Properties.Location.
|
|
761
|
+
exp.DistKeyProperty: exp.Properties.Location.UNSUPPORTED,
|
|
762
|
+
exp.DistStyleProperty: exp.Properties.Location.UNSUPPORTED,
|
|
751
763
|
exp.EmptyProperty: exp.Properties.Location.POST_SCHEMA,
|
|
752
764
|
exp.EncodeProperty: exp.Properties.Location.POST_EXPRESSION,
|
|
753
765
|
exp.EngineProperty: exp.Properties.Location.POST_SCHEMA,
|
|
@@ -812,7 +824,7 @@ class Generator:
|
|
|
812
824
|
exp.SharingProperty: exp.Properties.Location.POST_EXPRESSION,
|
|
813
825
|
exp.SequenceProperties: exp.Properties.Location.POST_EXPRESSION,
|
|
814
826
|
exp.TriggerProperties: exp.Properties.Location.POST_EXPRESSION,
|
|
815
|
-
exp.SortKeyProperty: exp.Properties.Location.
|
|
827
|
+
exp.SortKeyProperty: exp.Properties.Location.UNSUPPORTED,
|
|
816
828
|
exp.SqlReadWriteProperty: exp.Properties.Location.POST_SCHEMA,
|
|
817
829
|
exp.SqlSecurityProperty: exp.Properties.Location.POST_SCHEMA,
|
|
818
830
|
exp.StabilityProperty: exp.Properties.Location.POST_SCHEMA,
|
|
@@ -838,6 +850,7 @@ class Generator:
|
|
|
838
850
|
exp.WithProcedureOptions: exp.Properties.Location.POST_SCHEMA,
|
|
839
851
|
exp.WithSchemaBindingProperty: exp.Properties.Location.POST_SCHEMA,
|
|
840
852
|
exp.WithSystemVersioningProperty: exp.Properties.Location.POST_SCHEMA,
|
|
853
|
+
exp.WithoutRowidProperty: exp.Properties.Location.UNSUPPORTED,
|
|
841
854
|
exp.ForceProperty: exp.Properties.Location.POST_CREATE,
|
|
842
855
|
}
|
|
843
856
|
|
|
@@ -1051,6 +1064,17 @@ class Generator:
|
|
|
1051
1064
|
expression = sqlglot.transforms.move_ctes_to_top_level(expression)
|
|
1052
1065
|
return expression
|
|
1053
1066
|
|
|
1067
|
+
def _warn_unsupported_arg(
|
|
1068
|
+
self, expression: exp.Expr, arg_name: str, diagnostic: str | None = None
|
|
1069
|
+
) -> None:
|
|
1070
|
+
if expression.args.get(arg_name):
|
|
1071
|
+
self.unsupported(
|
|
1072
|
+
diagnostic
|
|
1073
|
+
or UNSUPPORTED_TEMPLATE.format(
|
|
1074
|
+
arg_name, expression.__class__.__name__, self.dialect.__class__.__name__
|
|
1075
|
+
)
|
|
1076
|
+
)
|
|
1077
|
+
|
|
1054
1078
|
def unsupported(self, message: str) -> None:
|
|
1055
1079
|
if self.unsupported_level == ErrorLevel.IMMEDIATE:
|
|
1056
1080
|
raise UnsupportedError(message)
|
|
@@ -1658,6 +1682,11 @@ class Generator:
|
|
|
1658
1682
|
def hexstring_sql(
|
|
1659
1683
|
self, expression: exp.HexString, binary_function_repr: str | None = None
|
|
1660
1684
|
) -> str:
|
|
1685
|
+
if expression.args.get("is_character"):
|
|
1686
|
+
self.unsupported("Hexadecimal character literals are only supported in Teradata")
|
|
1687
|
+
this = expression.this.replace("'", "''")
|
|
1688
|
+
return f"'{this}'XC"
|
|
1689
|
+
|
|
1661
1690
|
this = self.sql(expression, "this")
|
|
1662
1691
|
is_integer_type = expression.args.get("is_integer")
|
|
1663
1692
|
|
|
@@ -2072,7 +2101,13 @@ class Generator:
|
|
|
2072
2101
|
return f"{this} FILTER({where})"
|
|
2073
2102
|
|
|
2074
2103
|
def per_sql(self, expression: exp.Per) -> str:
|
|
2075
|
-
|
|
2104
|
+
keys = ", ".join(
|
|
2105
|
+
f"{self.sql(key, 'this')} {self.sql(key, 'with_fill')}"
|
|
2106
|
+
if isinstance(key, exp.Ordered) and key.args.get("with_fill")
|
|
2107
|
+
else self.sql(key)
|
|
2108
|
+
for key in expression.expressions
|
|
2109
|
+
)
|
|
2110
|
+
return f"{self.sql(expression, 'this')} PER ({keys})"
|
|
2076
2111
|
|
|
2077
2112
|
def hint_sql(self, expression: exp.Hint) -> str:
|
|
2078
2113
|
if not self.QUERY_HINTS:
|
|
@@ -2695,16 +2730,20 @@ class Generator:
|
|
|
2695
2730
|
in_exprs = expression.fields[0].expressions
|
|
2696
2731
|
step = len(columns) // len(in_exprs)
|
|
2697
2732
|
|
|
2698
|
-
|
|
2699
|
-
|
|
2700
|
-
|
|
2701
|
-
|
|
2733
|
+
suffix = ""
|
|
2734
|
+
if len(expression.expressions) != 1 or expression.expressions[0].alias:
|
|
2735
|
+
# Derive the per-value suffix from the first stored column vs the first IN-list value.
|
|
2736
|
+
# This correctly handles dialects (e.g. Spark single-agg) that ignore agg aliases.
|
|
2737
|
+
first_base = (
|
|
2738
|
+
in_exprs[0].sql() if src_identify_pivot_strings else in_exprs[0].alias_or_name
|
|
2739
|
+
)
|
|
2740
|
+
first_stored = columns[0].name
|
|
2702
2741
|
|
|
2703
|
-
|
|
2704
|
-
|
|
2705
|
-
|
|
2742
|
+
# exit if only suffix matches, not prefix. (e.g. BigQuery, which cannot be fixed)
|
|
2743
|
+
if not first_stored.startswith(first_base):
|
|
2744
|
+
return None
|
|
2706
2745
|
|
|
2707
|
-
|
|
2746
|
+
suffix = first_stored[len(first_base) :]
|
|
2708
2747
|
|
|
2709
2748
|
# Whether the target dialect would append an agg-name suffix for this pivot.
|
|
2710
2749
|
# Spark single-agg uniquely drops the agg alias entirely.
|
|
@@ -3009,6 +3048,17 @@ class Generator:
|
|
|
3009
3048
|
return f"PRIOR {self.sql(expression, 'this')}"
|
|
3010
3049
|
|
|
3011
3050
|
def join_sql(self, expression: exp.Join, join_op: str | None = None) -> str:
|
|
3051
|
+
if (
|
|
3052
|
+
match_condition := expression.args.get("match_condition")
|
|
3053
|
+
) and not self.SUPPORTS_MATCH_CONDITION:
|
|
3054
|
+
if self.MATCH_CONDITION_IN_ON and not expression.args.get("using"):
|
|
3055
|
+
expression = expression.on(match_condition)
|
|
3056
|
+
expression.set("match_condition", None)
|
|
3057
|
+
# Snowflake ASOF joins preserve unmatched left rows.
|
|
3058
|
+
expression.set("side", "LEFT")
|
|
3059
|
+
else:
|
|
3060
|
+
self.unsupported("MATCH_CONDITION is not supported")
|
|
3061
|
+
|
|
3012
3062
|
if not self.SEMI_ANTI_JOIN_WITH_SIDE and expression.kind in ("SEMI", "ANTI"):
|
|
3013
3063
|
side = None
|
|
3014
3064
|
else:
|
|
@@ -3717,9 +3767,28 @@ class Generator:
|
|
|
3717
3767
|
return f"{self.seg('WHERE')}{self.sep()}{this}"
|
|
3718
3768
|
|
|
3719
3769
|
def window_sql(self, expression: exp.Window) -> str:
|
|
3770
|
+
if (
|
|
3771
|
+
isinstance(expression.this, exp.Variance)
|
|
3772
|
+
and expression.this.args.get("single_value_returns_zero")
|
|
3773
|
+
and expression.text("over") != "KEEP"
|
|
3774
|
+
and not self.VARIANCE_RETURNS_ZERO_ON_SINGLE_VALUE
|
|
3775
|
+
):
|
|
3776
|
+
return self.variance_sql(expression.this, window=expression)
|
|
3777
|
+
|
|
3720
3778
|
this = self.sql(expression, "this")
|
|
3721
3779
|
partition = self.partition_by_sql(expression)
|
|
3722
3780
|
order = expression.args.get("order")
|
|
3781
|
+
if not order and self.WINDOW_FUNCS_REQUIRING_ORDER and not expression.args.get("alias"):
|
|
3782
|
+
func = expression.this
|
|
3783
|
+
if isinstance(func, (exp.IgnoreNulls, exp.RespectNulls)):
|
|
3784
|
+
func = func.this
|
|
3785
|
+
if isinstance(func, self.WINDOW_FUNCS_REQUIRING_ORDER):
|
|
3786
|
+
# Without an ordering all rows of a partition are peers, which is
|
|
3787
|
+
# also the case when ordering by the partition keys themselves
|
|
3788
|
+
partition_by = expression.args.get("partition_by")
|
|
3789
|
+
order = exp.Order(
|
|
3790
|
+
expressions=[e.copy() for e in partition_by] if partition_by else [exp.null()]
|
|
3791
|
+
)
|
|
3723
3792
|
order = self.order_sql(order, flat=True) if order else ""
|
|
3724
3793
|
spec = self.sql(expression, "spec")
|
|
3725
3794
|
alias = self.sql(expression, "alias")
|
|
@@ -3826,7 +3895,17 @@ class Generator:
|
|
|
3826
3895
|
return f"ANY {this}"
|
|
3827
3896
|
|
|
3828
3897
|
def exists_sql(self, expression: exp.Exists) -> str:
|
|
3829
|
-
|
|
3898
|
+
predicate = expression.expression
|
|
3899
|
+
if not predicate:
|
|
3900
|
+
return f"EXISTS{self.wrap(expression)}"
|
|
3901
|
+
|
|
3902
|
+
# Spark's EXISTS(array, lambda)
|
|
3903
|
+
if self.CAN_IMPLEMENT_ARRAY_ANY:
|
|
3904
|
+
filtered = exp.ArrayFilter(this=expression.this, expression=predicate)
|
|
3905
|
+
return self.sql(exp.paren(exp.ArraySize(this=filtered).neq(0)))
|
|
3906
|
+
|
|
3907
|
+
self.unsupported("EXISTS with a lambda predicate is unsupported")
|
|
3908
|
+
return self.function_fallback_sql(expression)
|
|
3830
3909
|
|
|
3831
3910
|
def case_sql(self, expression: exp.Case) -> str:
|
|
3832
3911
|
this = self.sql(expression, "this")
|
|
@@ -4047,6 +4126,14 @@ class Generator:
|
|
|
4047
4126
|
fmt = self.sql(expression, "format")
|
|
4048
4127
|
return f"{this} (FORMAT {fmt})"
|
|
4049
4128
|
|
|
4129
|
+
def teradatatitle_sql(self, expression: exp.TeradataTitle) -> str:
|
|
4130
|
+
self.unsupported("Teradata TITLE display headings are not supported")
|
|
4131
|
+
return self.sql(expression, "this")
|
|
4132
|
+
|
|
4133
|
+
def teradatanamed_sql(self, expression: exp.TeradataNamed) -> str:
|
|
4134
|
+
self.unsupported("Teradata NAMED on subexpressions is not supported")
|
|
4135
|
+
return self.sql(expression, "this")
|
|
4136
|
+
|
|
4050
4137
|
def _jsonobject_sql(
|
|
4051
4138
|
self, expression: exp.JSONObject | exp.JSONObjectAgg, name: str = ""
|
|
4052
4139
|
) -> str:
|
|
@@ -4225,6 +4312,9 @@ class Generator:
|
|
|
4225
4312
|
sql = self.seg(self.indent(self.sql(expression, "this")), sep="")
|
|
4226
4313
|
return f"({sql}{self.seg(')', sep='')}"
|
|
4227
4314
|
|
|
4315
|
+
def pos_sql(self, expression: exp.Pos) -> str:
|
|
4316
|
+
return f"+{self.sql(expression, 'this')}"
|
|
4317
|
+
|
|
4228
4318
|
def neg_sql(self, expression: exp.Neg) -> str:
|
|
4229
4319
|
# This makes sure we don't convert "- - 5" to "--5", which is a comment
|
|
4230
4320
|
this_sql = self.sql(expression, "this")
|
|
@@ -4685,11 +4775,14 @@ class Generator:
|
|
|
4685
4775
|
return self.func("CONCAT", *(exp.cast(e, exp.DType.TEXT) for e in expression.flatten()))
|
|
4686
4776
|
return self.binary(expression, "||")
|
|
4687
4777
|
|
|
4778
|
+
def nullif_zero_divisor(self, expression: exp.Div | exp.Mod) -> None:
|
|
4779
|
+
if not self.dialect.SAFE_DIVISION and expression.args.get("safe"):
|
|
4780
|
+
divisor = expression.right
|
|
4781
|
+
divisor.replace(exp.Nullif(this=divisor.copy(), expression=exp.Literal.number(0)))
|
|
4782
|
+
|
|
4688
4783
|
def div_sql(self, expression: exp.Div) -> str:
|
|
4689
4784
|
l, r = expression.left, expression.right
|
|
4690
|
-
|
|
4691
|
-
if not self.dialect.SAFE_DIVISION and expression.args.get("safe"):
|
|
4692
|
-
r.replace(exp.Nullif(this=r.copy(), expression=exp.Literal.number(0)))
|
|
4785
|
+
self.nullif_zero_divisor(expression)
|
|
4693
4786
|
|
|
4694
4787
|
if self.dialect.TYPED_DIVISION and not expression.args.get("typed"):
|
|
4695
4788
|
if not l.is_type(*exp.DataType.REAL_TYPES) and not r.is_type(*exp.DataType.REAL_TYPES):
|
|
@@ -4703,8 +4796,8 @@ class Generator:
|
|
|
4703
4796
|
if all(e.is_int or isinstance(e, exp.Cast) for e in (l, r)) and (
|
|
4704
4797
|
expression.args.get("safe") or not self.SAFE_INT_DIVISION
|
|
4705
4798
|
):
|
|
4706
|
-
return self.sql(exp.IntDiv(this=l, expression=
|
|
4707
|
-
return self._truncated_div_sql(l,
|
|
4799
|
+
return self.sql(exp.IntDiv(this=l, expression=expression.right))
|
|
4800
|
+
return self._truncated_div_sql(l, expression.right)
|
|
4708
4801
|
|
|
4709
4802
|
return self.binary(expression, "/")
|
|
4710
4803
|
|
|
@@ -4828,6 +4921,7 @@ class Generator:
|
|
|
4828
4921
|
return self.binary(expression, "<=")
|
|
4829
4922
|
|
|
4830
4923
|
def mod_sql(self, expression: exp.Mod) -> str:
|
|
4924
|
+
self.nullif_zero_divisor(expression)
|
|
4831
4925
|
this = self.sql(expression, "this")
|
|
4832
4926
|
expr = self.sql(expression, "expression")
|
|
4833
4927
|
sql = f"{this} {self.maybe_comment(self.MOD_OPERATOR, comments=expression.comments)} {expr}"
|
|
@@ -6084,6 +6178,9 @@ class Generator:
|
|
|
6084
6178
|
)
|
|
6085
6179
|
|
|
6086
6180
|
def slice_sql(self, expression: exp.Slice) -> str:
|
|
6181
|
+
if "[" in self.dialect.tokenizer_class._IDENTIFIERS:
|
|
6182
|
+
self.unsupported("Slices are not supported")
|
|
6183
|
+
|
|
6087
6184
|
step = self.sql(expression, "step")
|
|
6088
6185
|
# An omitted end is written as `-` before a step, since `::` is the cast operator
|
|
6089
6186
|
end = self.sql(expression.expression) or ("-" if step else "")
|
|
@@ -6222,6 +6319,36 @@ class Generator:
|
|
|
6222
6319
|
self.unsupported("ARRAY_SORT only sorts ascending with NULLs last")
|
|
6223
6320
|
return self.func("ARRAY_SORT", expression.this, expression.expression)
|
|
6224
6321
|
|
|
6322
|
+
def variance_sql(self, expression: exp.Variance, window: exp.Window | None = None) -> str:
|
|
6323
|
+
this = expression.this
|
|
6324
|
+
name = self.VARIANCE_NAME or self.function_name(expression)
|
|
6325
|
+
if not expression.args.get("single_value_returns_zero"):
|
|
6326
|
+
return self.func(name, this)
|
|
6327
|
+
|
|
6328
|
+
node: exp.Expr = expression
|
|
6329
|
+
while node.parent and not isinstance(node.parent, (exp.Window, exp.AggFunc, exp.Select)):
|
|
6330
|
+
node = node.parent
|
|
6331
|
+
if window is None and isinstance(node.parent, exp.Window) and node.arg_key == "this":
|
|
6332
|
+
self.unsupported("VARIANCE returning 0 for a single value is not supported in a window")
|
|
6333
|
+
return self.func(name, this)
|
|
6334
|
+
|
|
6335
|
+
expression.set("single_value_returns_zero", None)
|
|
6336
|
+
count: exp.Expr
|
|
6337
|
+
variance: exp.Expr = expression
|
|
6338
|
+
if window:
|
|
6339
|
+
count = window.copy()
|
|
6340
|
+
count.set("this", exp.Count(this=count.this.this))
|
|
6341
|
+
variance = window
|
|
6342
|
+
else:
|
|
6343
|
+
count = exp.Count(this=this.copy())
|
|
6344
|
+
|
|
6345
|
+
return self.sql(
|
|
6346
|
+
exp.case(count, copy=False)
|
|
6347
|
+
.when(0, exp.null(), copy=False)
|
|
6348
|
+
.when(1, 0, copy=False)
|
|
6349
|
+
.else_(variance, copy=False)
|
|
6350
|
+
)
|
|
6351
|
+
|
|
6225
6352
|
def arraysize_sql(self, expression: exp.ArraySize) -> str:
|
|
6226
6353
|
dim = expression.expression
|
|
6227
6354
|
|
|
@@ -6640,7 +6767,21 @@ class Generator:
|
|
|
6640
6767
|
|
|
6641
6768
|
return name
|
|
6642
6769
|
|
|
6770
|
+
def datetrunc_sql(self, expression: exp.DateTrunc) -> str:
|
|
6771
|
+
self._warn_unsupported_arg(expression, "century_from_zero")
|
|
6772
|
+
unit = expression.unit
|
|
6773
|
+
if unit.is_string and unit.name.upper() in ("WEEK_OF_MONTH", "WEEK_OF_YEAR"):
|
|
6774
|
+
self.unsupported(f"Unexpected interval unit: {unit.name}")
|
|
6775
|
+
|
|
6776
|
+
return self.function_fallback_sql(expression)
|
|
6777
|
+
|
|
6643
6778
|
def chr_sql(self, expression: exp.Chr, name: str = "CHR") -> str:
|
|
6779
|
+
args = expression.expressions
|
|
6780
|
+
if len(args) > 1 and not self.SUPPORTS_MULTI_ARG_CHR:
|
|
6781
|
+
# CHAR(72, 105) -> CHR(72) || CHR(105)
|
|
6782
|
+
chars: list[exp.Expr] = [exp.Chr(expressions=[arg.copy()]) for arg in args]
|
|
6783
|
+
return self.sql(reduce(lambda x, y: exp.DPipe(this=x, expression=y), chars))
|
|
6784
|
+
|
|
6644
6785
|
this = self.expressions(expression)
|
|
6645
6786
|
charset = self.sql(expression, "charset")
|
|
6646
6787
|
using = f" USING {charset}" if charset else ""
|
|
@@ -127,7 +127,7 @@ class AthenaTrinoGenerator(TrinoGenerator):
|
|
|
127
127
|
|
|
128
128
|
|
|
129
129
|
class AthenaGenerator(AthenaTrinoGenerator):
|
|
130
|
-
SELECT_KINDS
|
|
130
|
+
SELECT_KINDS = ()
|
|
131
131
|
SUPPORTS_DECODE_CASE = False
|
|
132
132
|
|
|
133
133
|
AFTER_HAVING_MODIFIER_TRANSFORMS = generator.AFTER_HAVING_MODIFIER_TRANSFORMS
|