sqlglotc 30.27.0__tar.gz → 30.30.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.27.0/sqlglotc.egg-info → sqlglotc-30.30.0}/PKG-INFO +2 -2
- {sqlglotc-30.27.0 → sqlglotc-30.30.0}/setup.py +5 -1
- {sqlglotc-30.27.0 → sqlglotc-30.30.0}/sqlglot/expressions/aggregate.py +2 -2
- {sqlglotc-30.27.0 → sqlglotc-30.30.0}/sqlglot/expressions/builders.py +8 -1
- {sqlglotc-30.27.0 → sqlglotc-30.30.0}/sqlglot/expressions/core.py +4 -1
- {sqlglotc-30.27.0 → sqlglotc-30.30.0}/sqlglot/expressions/properties.py +13 -1
- {sqlglotc-30.27.0 → sqlglotc-30.30.0}/sqlglot/expressions/query.py +22 -9
- {sqlglotc-30.27.0 → sqlglotc-30.30.0}/sqlglot/expressions/string.py +3 -1
- {sqlglotc-30.27.0 → sqlglotc-30.30.0}/sqlglot/expressions/temporal.py +9 -2
- {sqlglotc-30.27.0 → sqlglotc-30.30.0}/sqlglot/generator.py +34 -4
- {sqlglotc-30.27.0 → sqlglotc-30.30.0}/sqlglot/generators/bigquery.py +42 -0
- {sqlglotc-30.27.0 → sqlglotc-30.30.0}/sqlglot/generators/databricks.py +21 -0
- {sqlglotc-30.27.0 → sqlglotc-30.30.0}/sqlglot/generators/duckdb.py +57 -25
- {sqlglotc-30.27.0 → sqlglotc-30.30.0}/sqlglot/generators/oracle.py +6 -2
- {sqlglotc-30.27.0 → sqlglotc-30.30.0}/sqlglot/generators/snowflake.py +12 -8
- {sqlglotc-30.27.0 → sqlglotc-30.30.0}/sqlglot/generators/spark2.py +4 -0
- {sqlglotc-30.27.0 → sqlglotc-30.30.0}/sqlglot/generators/sqlite.py +7 -1
- {sqlglotc-30.27.0 → sqlglotc-30.30.0}/sqlglot/optimizer/annotate_types.py +11 -5
- {sqlglotc-30.27.0 → sqlglotc-30.30.0}/sqlglot/optimizer/qualify_columns.py +49 -15
- {sqlglotc-30.27.0 → sqlglotc-30.30.0}/sqlglot/optimizer/scope.py +21 -1
- {sqlglotc-30.27.0 → sqlglotc-30.30.0}/sqlglot/parser.py +41 -6
- {sqlglotc-30.27.0 → sqlglotc-30.30.0}/sqlglot/parsers/base.py +2 -0
- {sqlglotc-30.27.0 → sqlglotc-30.30.0}/sqlglot/parsers/bigquery.py +5 -1
- {sqlglotc-30.27.0 → sqlglotc-30.30.0}/sqlglot/parsers/duckdb.py +12 -0
- {sqlglotc-30.27.0 → sqlglotc-30.30.0}/sqlglot/parsers/hive.py +5 -7
- {sqlglotc-30.27.0 → sqlglotc-30.30.0}/sqlglot/parsers/mysql.py +2 -0
- {sqlglotc-30.27.0 → sqlglotc-30.30.0}/sqlglot/parsers/oracle.py +11 -2
- {sqlglotc-30.27.0 → sqlglotc-30.30.0}/sqlglot/parsers/postgres.py +2 -0
- {sqlglotc-30.27.0 → sqlglotc-30.30.0}/sqlglot/parsers/presto.py +2 -0
- {sqlglotc-30.27.0 → sqlglotc-30.30.0}/sqlglot/parsers/snowflake.py +18 -1
- {sqlglotc-30.27.0 → sqlglotc-30.30.0}/sqlglot/parsers/spark2.py +13 -0
- {sqlglotc-30.27.0 → sqlglotc-30.30.0}/sqlglot/parsers/sqlite.py +33 -0
- {sqlglotc-30.27.0 → sqlglotc-30.30.0}/sqlglot/parsers/starrocks.py +3 -0
- {sqlglotc-30.27.0 → sqlglotc-30.30.0}/sqlglot/tokenizer_core.py +16 -2
- {sqlglotc-30.27.0 → sqlglotc-30.30.0/sqlglotc.egg-info}/PKG-INFO +2 -2
- {sqlglotc-30.27.0 → sqlglotc-30.30.0}/sqlglotc.egg-info/requires.txt +1 -1
- sqlglotc-30.30.0/sqlglotc.egg-info/scm_version.json +8 -0
- sqlglotc-30.27.0/sqlglotc.egg-info/scm_version.json +0 -8
- {sqlglotc-30.27.0 → sqlglotc-30.30.0}/MANIFEST.in +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.30.0}/pyproject.toml +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.30.0}/setup.cfg +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.30.0}/sqlglot/anonymize.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.30.0}/sqlglot/errors.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.30.0}/sqlglot/executor/table.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.30.0}/sqlglot/expressions/array.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.30.0}/sqlglot/expressions/constraints.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.30.0}/sqlglot/expressions/datatypes.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.30.0}/sqlglot/expressions/ddl.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.30.0}/sqlglot/expressions/dml.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.30.0}/sqlglot/expressions/functions.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.30.0}/sqlglot/expressions/json.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.30.0}/sqlglot/expressions/math.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.30.0}/sqlglot/generators/athena.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.30.0}/sqlglot/generators/clickhouse.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.30.0}/sqlglot/generators/dax.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.30.0}/sqlglot/generators/doris.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.30.0}/sqlglot/generators/dremio.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.30.0}/sqlglot/generators/drill.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.30.0}/sqlglot/generators/druid.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.30.0}/sqlglot/generators/dune.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.30.0}/sqlglot/generators/exasol.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.30.0}/sqlglot/generators/fabric.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.30.0}/sqlglot/generators/hive.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.30.0}/sqlglot/generators/materialize.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.30.0}/sqlglot/generators/mysql.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.30.0}/sqlglot/generators/postgres.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.30.0}/sqlglot/generators/presto.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.30.0}/sqlglot/generators/prql.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.30.0}/sqlglot/generators/python.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.30.0}/sqlglot/generators/redshift.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.30.0}/sqlglot/generators/risingwave.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.30.0}/sqlglot/generators/singlestore.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.30.0}/sqlglot/generators/solr.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.30.0}/sqlglot/generators/spark.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.30.0}/sqlglot/generators/starrocks.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.30.0}/sqlglot/generators/tableau.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.30.0}/sqlglot/generators/teradata.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.30.0}/sqlglot/generators/trino.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.30.0}/sqlglot/generators/tsql.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.30.0}/sqlglot/helper.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.30.0}/sqlglot/lineage.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.30.0}/sqlglot/optimizer/canonicalize_internal_names.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.30.0}/sqlglot/optimizer/isolate_table_selects.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.30.0}/sqlglot/optimizer/normalize_identifiers.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.30.0}/sqlglot/optimizer/qualify.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.30.0}/sqlglot/optimizer/qualify_tables.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.30.0}/sqlglot/optimizer/resolver.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.30.0}/sqlglot/optimizer/simplify.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.30.0}/sqlglot/parsers/athena.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.30.0}/sqlglot/parsers/clickhouse.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.30.0}/sqlglot/parsers/databricks.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.30.0}/sqlglot/parsers/dax.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.30.0}/sqlglot/parsers/doris.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.30.0}/sqlglot/parsers/dremio.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.30.0}/sqlglot/parsers/drill.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.30.0}/sqlglot/parsers/druid.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.30.0}/sqlglot/parsers/dune.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.30.0}/sqlglot/parsers/exasol.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.30.0}/sqlglot/parsers/fabric.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.30.0}/sqlglot/parsers/materialize.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.30.0}/sqlglot/parsers/prql.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.30.0}/sqlglot/parsers/redshift.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.30.0}/sqlglot/parsers/risingwave.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.30.0}/sqlglot/parsers/singlestore.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.30.0}/sqlglot/parsers/solr.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.30.0}/sqlglot/parsers/spark.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.30.0}/sqlglot/parsers/tableau.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.30.0}/sqlglot/parsers/teradata.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.30.0}/sqlglot/parsers/trino.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.30.0}/sqlglot/parsers/tsql.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.30.0}/sqlglot/serde.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.30.0}/sqlglot/time.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.30.0}/sqlglot/trie.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.30.0}/sqlglotc.egg-info/SOURCES.txt +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.30.0}/sqlglotc.egg-info/dependency_links.txt +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.30.0}/sqlglotc.egg-info/scm_file_list.json +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.30.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.30.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.30.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"
|
|
@@ -189,7 +189,11 @@ setup(
|
|
|
189
189
|
packages=[],
|
|
190
190
|
install_requires=_sqlglot_requirement(),
|
|
191
191
|
ext_modules=mypycify(
|
|
192
|
-
_source_paths(),
|
|
192
|
+
_source_paths(),
|
|
193
|
+
opt_level=os.environ.get("MYPYC_OPT", "2"),
|
|
194
|
+
debug_level="0",
|
|
195
|
+
separate=True,
|
|
196
|
+
verbose=True,
|
|
193
197
|
),
|
|
194
198
|
cmdclass={"build_ext": build_ext, "sdist": sdist},
|
|
195
199
|
)
|
|
@@ -180,7 +180,7 @@ class LogicalOr(Expression, AggFunc):
|
|
|
180
180
|
|
|
181
181
|
|
|
182
182
|
class Max(Expression, AggFunc):
|
|
183
|
-
arg_types = {"this": True, "expressions": False}
|
|
183
|
+
arg_types = {"this": True, "expressions": False, "count": False}
|
|
184
184
|
is_var_len_args = True
|
|
185
185
|
|
|
186
186
|
|
|
@@ -189,7 +189,7 @@ class Median(Expression, AggFunc):
|
|
|
189
189
|
|
|
190
190
|
|
|
191
191
|
class Min(Expression, AggFunc):
|
|
192
|
-
arg_types = {"this": True, "expressions": False}
|
|
192
|
+
arg_types = {"this": True, "expressions": False, "count": False}
|
|
193
193
|
is_var_len_args = True
|
|
194
194
|
|
|
195
195
|
|
|
@@ -824,7 +824,7 @@ def normalize_table_name(table: str | Table, dialect: DialectType = None, copy:
|
|
|
824
824
|
def replace_tables(
|
|
825
825
|
expression: E, mapping: dict[str, str], dialect: DialectType = None, copy: bool = True
|
|
826
826
|
) -> E:
|
|
827
|
-
"""Replace all tables in expression according to the mapping.
|
|
827
|
+
"""Replace all FROM sources (tables, views, table functions...) in expression according to the mapping.
|
|
828
828
|
|
|
829
829
|
Args:
|
|
830
830
|
expression: expression node to be transformed and replaced.
|
|
@@ -845,6 +845,10 @@ def replace_tables(
|
|
|
845
845
|
|
|
846
846
|
def _replace_tables(node: Expr) -> Expr:
|
|
847
847
|
if isinstance(node, Table) and node.meta_get("replace") is not False:
|
|
848
|
+
call = node.this
|
|
849
|
+
if isinstance(call, Func) and not isinstance(call, Anonymous):
|
|
850
|
+
return node
|
|
851
|
+
|
|
848
852
|
original = normalize_table_name(node, dialect=dialect)
|
|
849
853
|
new_name = mapping.get(original)
|
|
850
854
|
|
|
@@ -854,6 +858,9 @@ def replace_tables(
|
|
|
854
858
|
**{k: v for k, v in node.args.items() if k not in TABLE_PARTS},
|
|
855
859
|
dialect=dialect,
|
|
856
860
|
)
|
|
861
|
+
if isinstance(call, Anonymous):
|
|
862
|
+
call.set("this", table.this)
|
|
863
|
+
table.set("this", call)
|
|
857
864
|
table.add_comments([original])
|
|
858
865
|
return table
|
|
859
866
|
return node
|
|
@@ -933,7 +933,10 @@ class Expression(Expr):
|
|
|
933
933
|
|
|
934
934
|
@property
|
|
935
935
|
def is_int(self) -> bool:
|
|
936
|
-
|
|
936
|
+
try:
|
|
937
|
+
return self.is_number and isinstance(self.to_py(), int)
|
|
938
|
+
except ValueError:
|
|
939
|
+
return False
|
|
937
940
|
|
|
938
941
|
@property
|
|
939
942
|
def is_star(self) -> bool:
|
|
@@ -210,6 +210,10 @@ class IcebergProperty(Property):
|
|
|
210
210
|
arg_types = {}
|
|
211
211
|
|
|
212
212
|
|
|
213
|
+
class IgnoreGrantsProperty(Property):
|
|
214
|
+
arg_types = {}
|
|
215
|
+
|
|
216
|
+
|
|
213
217
|
class InheritsProperty(Property):
|
|
214
218
|
arg_types = {"expressions": True}
|
|
215
219
|
|
|
@@ -222,6 +226,10 @@ class OutputModelProperty(Property):
|
|
|
222
226
|
arg_types = {"this": True}
|
|
223
227
|
|
|
224
228
|
|
|
229
|
+
class InteractiveProperty(Property):
|
|
230
|
+
arg_types = {}
|
|
231
|
+
|
|
232
|
+
|
|
225
233
|
class IsolatedLoadingProperty(Property):
|
|
226
234
|
arg_types = {"no": False, "concurrent": False, "target": False}
|
|
227
235
|
|
|
@@ -330,6 +338,10 @@ class OnCommitProperty(Property):
|
|
|
330
338
|
arg_types = {"delete": False}
|
|
331
339
|
|
|
332
340
|
|
|
341
|
+
class OptionsProperty(Property):
|
|
342
|
+
arg_types = {"expressions": True}
|
|
343
|
+
|
|
344
|
+
|
|
333
345
|
class PartitionedByProperty(Property):
|
|
334
346
|
arg_types = {"this": True}
|
|
335
347
|
|
|
@@ -520,7 +532,7 @@ class UsingProperty(Property):
|
|
|
520
532
|
|
|
521
533
|
|
|
522
534
|
class TemporaryProperty(Property):
|
|
523
|
-
arg_types = {"this": False}
|
|
535
|
+
arg_types = {"this": False, "scoped": False}
|
|
524
536
|
|
|
525
537
|
|
|
526
538
|
class VirtualProperty(Property):
|
|
@@ -1111,15 +1111,27 @@ class SetOperation(Expression, Query):
|
|
|
1111
1111
|
|
|
1112
1112
|
@property
|
|
1113
1113
|
def named_selects(self) -> list[str]:
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1114
|
+
names = []
|
|
1115
|
+
stack: list[Expr] = [self]
|
|
1116
|
+
by_name = False
|
|
1117
|
+
|
|
1118
|
+
while stack:
|
|
1119
|
+
expr = stack.pop()
|
|
1120
|
+
if not isinstance(expr, SetOperation):
|
|
1121
|
+
names.extend(t.cast(Selectable, expr).named_selects)
|
|
1122
|
+
continue
|
|
1123
|
+
|
|
1124
|
+
while isinstance(expr, SetOperation):
|
|
1125
|
+
if expr.args.get("by_name"):
|
|
1126
|
+
by_name = True
|
|
1127
|
+
stack.append(expr.expression.unnest())
|
|
1128
|
+
stack.append(expr.this.unnest())
|
|
1129
|
+
break
|
|
1130
|
+
expr = expr.this.unnest()
|
|
1131
|
+
else:
|
|
1132
|
+
names.extend(_named_selects(expr))
|
|
1133
|
+
|
|
1134
|
+
return list(dict.fromkeys(names)) if by_name else names
|
|
1123
1135
|
|
|
1124
1136
|
@property
|
|
1125
1137
|
def is_star(self) -> bool:
|
|
@@ -1168,6 +1180,7 @@ class Values(Expression, UDTF):
|
|
|
1168
1180
|
"order": False,
|
|
1169
1181
|
"limit": False,
|
|
1170
1182
|
"offset": False,
|
|
1183
|
+
"pivots": False,
|
|
1171
1184
|
}
|
|
1172
1185
|
|
|
1173
1186
|
|
|
@@ -435,7 +435,9 @@ class RegexpExtract(Expression, Func):
|
|
|
435
435
|
"occurrence": False,
|
|
436
436
|
"parameters": False,
|
|
437
437
|
"group": False,
|
|
438
|
-
"null_if_pos_overflow": False,
|
|
438
|
+
"null_if_pos_overflow": False,
|
|
439
|
+
"null_if_no_match": False,
|
|
440
|
+
"empty_if_group_missing": False,
|
|
439
441
|
}
|
|
440
442
|
|
|
441
443
|
|
|
@@ -192,7 +192,7 @@ class TimestampTrunc(Expression, Func, TimeUnit):
|
|
|
192
192
|
|
|
193
193
|
|
|
194
194
|
class TimeSlice(Expression, Func, TimeUnit):
|
|
195
|
-
arg_types = {"this": True, "expression": True, "unit": True, "kind": False}
|
|
195
|
+
arg_types = {"this": True, "expression": True, "unit": True, "kind": False, "origin": False}
|
|
196
196
|
|
|
197
197
|
|
|
198
198
|
class TimeTrunc(Expression, Func, TimeUnit):
|
|
@@ -454,7 +454,13 @@ class ParseTime(Expression, Func):
|
|
|
454
454
|
|
|
455
455
|
|
|
456
456
|
class StrToDate(Expression, Func):
|
|
457
|
-
arg_types = {
|
|
457
|
+
arg_types = {
|
|
458
|
+
"this": True,
|
|
459
|
+
"format": False,
|
|
460
|
+
"safe": False,
|
|
461
|
+
"default_year": False,
|
|
462
|
+
"nlsparam": False,
|
|
463
|
+
}
|
|
458
464
|
|
|
459
465
|
|
|
460
466
|
class StrToTime(Expression, Func):
|
|
@@ -465,6 +471,7 @@ class StrToTime(Expression, Func):
|
|
|
465
471
|
"safe": False,
|
|
466
472
|
"target_type": False,
|
|
467
473
|
"default_year": False,
|
|
474
|
+
"nlsparam": False,
|
|
468
475
|
}
|
|
469
476
|
|
|
470
477
|
|
|
@@ -202,6 +202,7 @@ class Generator:
|
|
|
202
202
|
exp.HeapProperty: lambda *_: "HEAP",
|
|
203
203
|
exp.HybridProperty: lambda *_: "HYBRID",
|
|
204
204
|
exp.IcebergProperty: lambda *_: "ICEBERG",
|
|
205
|
+
exp.IgnoreGrantsProperty: lambda *_: "IGNORE GRANTS",
|
|
205
206
|
exp.InheritsProperty: lambda self, e: f"INHERITS ({self.expressions(e, flat=True)})",
|
|
206
207
|
exp.InlineLengthColumnConstraint: lambda self, e: f"INLINE LENGTH {self.sql(e, 'this')}",
|
|
207
208
|
exp.InputModelProperty: lambda self, e: f"INPUT{self.sql(e, 'this')}",
|
|
@@ -350,7 +351,7 @@ class Generator:
|
|
|
350
351
|
# Whether limit and fetch are supported (possible values: "ALL", "LIMIT", "FETCH")
|
|
351
352
|
LIMIT_FETCH = "ALL"
|
|
352
353
|
|
|
353
|
-
# Whether limit and fetch allows
|
|
354
|
+
# Whether limit and fetch allows expressions or just limits
|
|
354
355
|
LIMIT_ONLY_LITERALS = False
|
|
355
356
|
|
|
356
357
|
# Whether a table is allowed to be renamed with a db
|
|
@@ -763,8 +764,10 @@ class Generator:
|
|
|
763
764
|
exp.HybridProperty: exp.Properties.Location.POST_CREATE,
|
|
764
765
|
exp.InheritsProperty: exp.Properties.Location.POST_SCHEMA,
|
|
765
766
|
exp.IcebergProperty: exp.Properties.Location.POST_CREATE,
|
|
767
|
+
exp.IgnoreGrantsProperty: exp.Properties.Location.POST_SCHEMA,
|
|
766
768
|
exp.IncludeProperty: exp.Properties.Location.POST_SCHEMA,
|
|
767
769
|
exp.InputModelProperty: exp.Properties.Location.POST_SCHEMA,
|
|
770
|
+
exp.InteractiveProperty: exp.Properties.Location.UNSUPPORTED,
|
|
768
771
|
exp.IsolatedLoadingProperty: exp.Properties.Location.POST_NAME,
|
|
769
772
|
exp.JournalProperty: exp.Properties.Location.POST_NAME,
|
|
770
773
|
exp.LanguageProperty: exp.Properties.Location.POST_SCHEMA,
|
|
@@ -781,6 +784,7 @@ class Generator:
|
|
|
781
784
|
exp.NoPrimaryIndexProperty: exp.Properties.Location.POST_EXPRESSION,
|
|
782
785
|
exp.OnProperty: exp.Properties.Location.POST_SCHEMA,
|
|
783
786
|
exp.OnCommitProperty: exp.Properties.Location.POST_EXPRESSION,
|
|
787
|
+
exp.OptionsProperty: exp.Properties.Location.UNSUPPORTED,
|
|
784
788
|
exp.Order: exp.Properties.Location.POST_SCHEMA,
|
|
785
789
|
exp.OutputModelProperty: exp.Properties.Location.POST_SCHEMA,
|
|
786
790
|
exp.PartitionedByProperty: exp.Properties.Location.POST_WITH,
|
|
@@ -2862,7 +2866,8 @@ class Generator:
|
|
|
2862
2866
|
else values
|
|
2863
2867
|
)
|
|
2864
2868
|
values = self.query_modifiers(expression, values)
|
|
2865
|
-
|
|
2869
|
+
pivots = self.expressions(expression, key="pivots", sep="", flat=True)
|
|
2870
|
+
return f"{values} AS {alias}{pivots}" if alias else f"{values}{pivots}"
|
|
2866
2871
|
|
|
2867
2872
|
# Converts `VALUES...` expression into a series of select unions.
|
|
2868
2873
|
alias_node = expression.args.get("alias")
|
|
@@ -2885,11 +2890,17 @@ class Generator:
|
|
|
2885
2890
|
# the deep nesting of the resulting exp.Unions. If this is a problem, either increase
|
|
2886
2891
|
# `sys.setrecursionlimit` to avoid RecursionErrors, or don't set `pretty`.
|
|
2887
2892
|
query = reduce(lambda x, y: exp.union(x, y, distinct=False, copy=False), selects)
|
|
2888
|
-
|
|
2893
|
+
for key in ("order", "limit", "offset"):
|
|
2894
|
+
if value := expression.args.get(key):
|
|
2895
|
+
query.set(key, value.pop())
|
|
2896
|
+
subquery = query.subquery(alias_node and alias_node.this, copy=False)
|
|
2897
|
+
subquery.set("pivots", expression.args.pop("pivots", None))
|
|
2898
|
+
return self.subquery_sql(subquery)
|
|
2889
2899
|
|
|
2890
2900
|
alias = f" AS {self.sql(alias_node, 'this')}" if alias_node else ""
|
|
2891
2901
|
unions = " UNION ALL ".join(self.sql(select) for select in selects)
|
|
2892
|
-
|
|
2902
|
+
pivots = self.expressions(expression, key="pivots", sep="", flat=True)
|
|
2903
|
+
return f"({self.query_modifiers(expression, unions)}){alias}{pivots}"
|
|
2893
2904
|
|
|
2894
2905
|
def var_sql(self, expression: exp.Var) -> str:
|
|
2895
2906
|
return self.sql(expression, "this")
|
|
@@ -6045,6 +6056,14 @@ class Generator:
|
|
|
6045
6056
|
|
|
6046
6057
|
return array_agg_sql
|
|
6047
6058
|
|
|
6059
|
+
@unsupported_args("count")
|
|
6060
|
+
def min_sql(self, expression: exp.Min) -> str:
|
|
6061
|
+
return self.function_fallback_sql(expression)
|
|
6062
|
+
|
|
6063
|
+
@unsupported_args("count")
|
|
6064
|
+
def max_sql(self, expression: exp.Max) -> str:
|
|
6065
|
+
return self.function_fallback_sql(expression)
|
|
6066
|
+
|
|
6048
6067
|
def arrayagg_sql(self, expression: exp.ArrayAgg) -> str:
|
|
6049
6068
|
array_agg = self.function_fallback_sql(expression)
|
|
6050
6069
|
column_expr = expression.this
|
|
@@ -6053,6 +6072,17 @@ class Generator:
|
|
|
6053
6072
|
|
|
6054
6073
|
return self._add_arrayagg_null_filter(array_agg, expression, column_expr)
|
|
6055
6074
|
|
|
6075
|
+
def timeslice_sql(self, expression: exp.TimeSlice) -> str:
|
|
6076
|
+
# Only the SQLGlot dialect serializes the internal origin for round-tripping.
|
|
6077
|
+
origin = expression.args.get("origin") if self.dialect == "" else None
|
|
6078
|
+
kind = expression.args.get("kind")
|
|
6079
|
+
if origin is not None and kind is None:
|
|
6080
|
+
kind = exp.Literal.string("START")
|
|
6081
|
+
|
|
6082
|
+
return self.func(
|
|
6083
|
+
"TIME_SLICE", expression.this, expression.expression, expression.unit, kind, origin
|
|
6084
|
+
)
|
|
6085
|
+
|
|
6056
6086
|
def slice_sql(self, expression: exp.Slice) -> str:
|
|
6057
6087
|
step = self.sql(expression, "step")
|
|
6058
6088
|
# An omitted end is written as `-` before a step, since `::` is the cast operator
|
|
@@ -30,9 +30,13 @@ from sqlglot.dialects.dialect import (
|
|
|
30
30
|
groupconcat_sql,
|
|
31
31
|
sha2_digest_sql,
|
|
32
32
|
)
|
|
33
|
+
from sqlglot.errors import ErrorLevel
|
|
33
34
|
from sqlglot.generator import unsupported_args
|
|
34
35
|
from sqlglot.helper import seq_get
|
|
35
36
|
|
|
37
|
+
if t.TYPE_CHECKING:
|
|
38
|
+
from sqlglot.dialects.dialect import DialectType
|
|
39
|
+
|
|
36
40
|
logger = logging.getLogger("sqlglot")
|
|
37
41
|
|
|
38
42
|
JSON_EXTRACT_TYPE = t.Union[exp.JSONExtract, exp.JSONExtractScalar, exp.JSONExtractArray]
|
|
@@ -683,6 +687,44 @@ class BigQueryGenerator(generator.Generator):
|
|
|
683
687
|
"within",
|
|
684
688
|
}
|
|
685
689
|
|
|
690
|
+
def __init__(
|
|
691
|
+
self,
|
|
692
|
+
pretty: bool | int | None = None,
|
|
693
|
+
identify: str | bool = False,
|
|
694
|
+
normalize: bool = False,
|
|
695
|
+
pad: int = 2,
|
|
696
|
+
indent: int = 2,
|
|
697
|
+
normalize_functions: str | bool | None = None,
|
|
698
|
+
unsupported_level: ErrorLevel = ErrorLevel.WARN,
|
|
699
|
+
max_unsupported: int = 3,
|
|
700
|
+
leading_comma: bool = False,
|
|
701
|
+
max_text_width: int = 80,
|
|
702
|
+
comments: bool = True,
|
|
703
|
+
dialect: DialectType = None,
|
|
704
|
+
) -> None:
|
|
705
|
+
super().__init__(
|
|
706
|
+
pretty=pretty,
|
|
707
|
+
identify=identify,
|
|
708
|
+
normalize=normalize,
|
|
709
|
+
pad=pad,
|
|
710
|
+
indent=indent,
|
|
711
|
+
normalize_functions=normalize_functions,
|
|
712
|
+
unsupported_level=unsupported_level,
|
|
713
|
+
max_unsupported=max_unsupported,
|
|
714
|
+
leading_comma=leading_comma,
|
|
715
|
+
max_text_width=max_text_width,
|
|
716
|
+
comments=comments,
|
|
717
|
+
dialect=dialect,
|
|
718
|
+
)
|
|
719
|
+
|
|
720
|
+
self._escaped_identifier_end = r"\`"
|
|
721
|
+
|
|
722
|
+
# Escape existing backslashes before introducing new escape sequences.
|
|
723
|
+
self._identifier_escaped_sequences = {
|
|
724
|
+
**self._identifier_escaped_sequences,
|
|
725
|
+
**self.dialect.ESCAPED_SEQUENCES,
|
|
726
|
+
}
|
|
727
|
+
|
|
686
728
|
def frombase_sql(self, expression: exp.FromBase) -> str:
|
|
687
729
|
# Hex is the only base BigQuery can cast from, and the sign goes before the prefix, e.g. -0xff
|
|
688
730
|
if expression.expression.name != "16":
|
|
@@ -10,6 +10,16 @@ from sqlglot.dialects.dialect import (
|
|
|
10
10
|
from sqlglot.generators.spark import SparkGenerator
|
|
11
11
|
|
|
12
12
|
|
|
13
|
+
TIMESTAMP_TYPES = {
|
|
14
|
+
exp.DType.DATETIME,
|
|
15
|
+
exp.DType.TIME,
|
|
16
|
+
exp.DType.TIMESTAMP,
|
|
17
|
+
exp.DType.TIMESTAMPNTZ,
|
|
18
|
+
exp.DType.TIMESTAMPLTZ,
|
|
19
|
+
exp.DType.TIMESTAMPTZ,
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
|
|
13
23
|
class DatabricksGenerator(SparkGenerator):
|
|
14
24
|
TABLESAMPLE_SEED_KEYWORD = "REPEATABLE"
|
|
15
25
|
COPY_PARAMS_ARE_WRAPPED = False
|
|
@@ -70,6 +80,17 @@ class DatabricksGenerator(SparkGenerator):
|
|
|
70
80
|
exp.DType.NULL: "VOID",
|
|
71
81
|
}
|
|
72
82
|
|
|
83
|
+
def datatype_sql(self, expression: exp.DataType) -> str:
|
|
84
|
+
# Databricks only supports a timestamp precision of 6 (microseconds) or 7 to 9
|
|
85
|
+
# (nanoseconds), so drop any other precision it would reject, e.g. TIMESTAMP(0)
|
|
86
|
+
if expression.this in TIMESTAMP_TYPES and expression.expressions:
|
|
87
|
+
param = expression.expressions[0]
|
|
88
|
+
param = param.this if isinstance(param, exp.DataTypeParam) else param
|
|
89
|
+
if param.is_int and not 6 <= param.to_py() <= 9:
|
|
90
|
+
expression.set("expressions", None)
|
|
91
|
+
|
|
92
|
+
return super().datatype_sql(expression)
|
|
93
|
+
|
|
73
94
|
def create_sql(self, expression: exp.Create) -> str:
|
|
74
95
|
body = expression.expression
|
|
75
96
|
if (
|
|
@@ -24,6 +24,7 @@ from sqlglot.dialects.dialect import (
|
|
|
24
24
|
getbit_sql,
|
|
25
25
|
groupconcat_sql,
|
|
26
26
|
inline_array_unless_query,
|
|
27
|
+
map_date_part,
|
|
27
28
|
months_between_sql,
|
|
28
29
|
no_datetime_sql,
|
|
29
30
|
no_comment_column_constraint_sql,
|
|
@@ -111,7 +112,7 @@ def _apply_base64_alphabet_replacements(
|
|
|
111
112
|
reverse: bool = False,
|
|
112
113
|
) -> exp.Expr:
|
|
113
114
|
"""
|
|
114
|
-
|
|
115
|
+
Translate base64 alphabet characters without cascading replacements.
|
|
115
116
|
|
|
116
117
|
Base64 alphabet can be 1-3 chars: 1st = index 62 ('+'), 2nd = index 63 ('/'), 3rd = padding ('=').
|
|
117
118
|
zip truncates to the shorter string, so 1-char alphabet only replaces '+', 2-char replaces '+/', etc.
|
|
@@ -123,14 +124,19 @@ def _apply_base64_alphabet_replacements(
|
|
|
123
124
|
If True, replace custom with default (decode)
|
|
124
125
|
"""
|
|
125
126
|
if isinstance(alphabet, exp.Literal) and alphabet.is_string:
|
|
127
|
+
source, target = "", ""
|
|
126
128
|
for default_char, new_char in zip("+/=", alphabet.this):
|
|
127
129
|
if new_char != default_char:
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
130
|
+
source += default_char
|
|
131
|
+
target += new_char
|
|
132
|
+
if source:
|
|
133
|
+
if reverse:
|
|
134
|
+
source, target = target, source
|
|
135
|
+
result = exp.Translate(
|
|
136
|
+
this=result,
|
|
137
|
+
from_=exp.Literal.string(source),
|
|
138
|
+
to=exp.Literal.string(target),
|
|
139
|
+
)
|
|
134
140
|
return result
|
|
135
141
|
|
|
136
142
|
|
|
@@ -139,7 +145,7 @@ def _base64_decode_sql(self: DuckDBGenerator, expression: exp.Expr, to_string: b
|
|
|
139
145
|
Transpile Snowflake BASE64_DECODE_STRING/BINARY to DuckDB.
|
|
140
146
|
|
|
141
147
|
DuckDB uses FROM_BASE64() which returns BLOB. For string output, wrap with DECODE().
|
|
142
|
-
Custom alphabets require
|
|
148
|
+
Custom alphabets require TRANSLATE() to convert to standard base64.
|
|
143
149
|
"""
|
|
144
150
|
input_expr = expression.this
|
|
145
151
|
alphabet = expression.args.get("alphabet")
|
|
@@ -1765,6 +1771,8 @@ class DuckDBGenerator(generator.Generator):
|
|
|
1765
1771
|
exp.MakeInterval: lambda self, e: no_make_interval_sql(self, e, sep=" "),
|
|
1766
1772
|
exp.Initcap: _initcap_sql,
|
|
1767
1773
|
exp.MD5Digest: lambda self, e: self.func("UNHEX", self.func("MD5", e.this)),
|
|
1774
|
+
exp.Max: rename_func("MAX"),
|
|
1775
|
+
exp.Min: rename_func("MIN"),
|
|
1768
1776
|
exp.SHA: lambda self, e: _sha_sql(self, e, "SHA1"),
|
|
1769
1777
|
exp.SHA1Digest: lambda self, e: _sha_sql(self, e, "SHA1", is_binary=True),
|
|
1770
1778
|
exp.SHA2: lambda self, e: _sha_sql(self, e, "SHA256"),
|
|
@@ -2418,32 +2426,37 @@ class DuckDBGenerator(generator.Generator):
|
|
|
2418
2426
|
Transform Snowflake's TIME_SLICE to DuckDB's time_bucket.
|
|
2419
2427
|
|
|
2420
2428
|
Snowflake: TIME_SLICE(date_expr, slice_length, 'UNIT' [, 'START'|'END'])
|
|
2421
|
-
DuckDB: time_bucket(INTERVAL 'slice_length' UNIT, date_expr)
|
|
2429
|
+
DuckDB: time_bucket(INTERVAL 'slice_length' UNIT, date_expr, origin)
|
|
2422
2430
|
|
|
2423
|
-
|
|
2424
|
-
|
|
2431
|
+
Snowflake aligns slices to the 1970-01-01 epoch, so an explicit origin is
|
|
2432
|
+
required because DuckDB's default origin differs. For 'END' kind, add the
|
|
2433
|
+
interval to get the next slice's start; for DATE input, cast back to DATE.
|
|
2425
2434
|
"""
|
|
2426
2435
|
date_expr = expression.this
|
|
2427
2436
|
slice_length = expression.expression
|
|
2428
|
-
unit
|
|
2437
|
+
# Normalize unit aliases (e.g. W/WK/WOY -> WEEK) so the interval and origin agree
|
|
2438
|
+
unit = map_date_part(expression.unit, self.dialect)
|
|
2429
2439
|
kind = expression.text("kind").upper()
|
|
2430
2440
|
|
|
2431
|
-
# Create INTERVAL expression: INTERVAL 'N' UNIT
|
|
2432
2441
|
interval_expr = exp.Interval(this=slice_length, unit=unit)
|
|
2433
2442
|
|
|
2434
|
-
|
|
2435
|
-
|
|
2443
|
+
origin = expression.args.get("origin")
|
|
2444
|
+
if origin is None:
|
|
2445
|
+
# Snowflake aligns to 1970-01-01; WEEK to the Monday of the epoch week (WEEK_START=0)
|
|
2446
|
+
origin = exp.Literal.string(
|
|
2447
|
+
"1969-12-29" if unit and unit.name.upper() == "WEEK" else "1970-01-01"
|
|
2448
|
+
)
|
|
2449
|
+
# A DATE origin keeps a DATE input a DATE; DuckDB widens it for TIMESTAMP inputs
|
|
2450
|
+
time_bucket_expr = exp.func(
|
|
2451
|
+
"time_bucket", interval_expr, date_expr, exp.cast(origin, exp.DType.DATE)
|
|
2452
|
+
)
|
|
2436
2453
|
|
|
2437
|
-
|
|
2438
|
-
if not kind == "END":
|
|
2439
|
-
# For 'START', return time_bucket directly
|
|
2454
|
+
if kind != "END":
|
|
2440
2455
|
return self.sql(time_bucket_expr)
|
|
2441
2456
|
|
|
2442
|
-
# For 'END', add the interval to get end of slice
|
|
2443
2457
|
add_expr = exp.Add(this=time_bucket_expr, expression=interval_expr.copy())
|
|
2444
2458
|
|
|
2445
|
-
#
|
|
2446
|
-
# DuckDB converts DATE to TIMESTAMP when adding intervals
|
|
2459
|
+
# DuckDB widens DATE to TIMESTAMP when adding intervals, so cast back
|
|
2447
2460
|
if date_expr.is_type(exp.DType.DATE):
|
|
2448
2461
|
return self.sql(exp.cast(add_expr, exp.DType.DATE))
|
|
2449
2462
|
|
|
@@ -4325,6 +4338,7 @@ class DuckDBGenerator(generator.Generator):
|
|
|
4325
4338
|
position = expression.args.get("position")
|
|
4326
4339
|
occurrence = expression.args.get("occurrence")
|
|
4327
4340
|
null_if_pos_overflow = expression.args.get("null_if_pos_overflow")
|
|
4341
|
+
null_if_no_match = expression.args.get("null_if_no_match")
|
|
4328
4342
|
|
|
4329
4343
|
# Handle Snowflake's 'e' flag: it enables capture group extraction
|
|
4330
4344
|
# In DuckDB, this is controlled by the group parameter directly
|
|
@@ -4353,7 +4367,7 @@ class DuckDBGenerator(generator.Generator):
|
|
|
4353
4367
|
is_extract_all = isinstance(expression, exp.RegexpExtractAll)
|
|
4354
4368
|
non_single_occurrence = occurrence and (not occurrence.is_int or occurrence.to_py() > 1)
|
|
4355
4369
|
|
|
4356
|
-
if is_extract_all or non_single_occurrence:
|
|
4370
|
+
if is_extract_all or non_single_occurrence or null_if_no_match:
|
|
4357
4371
|
name = "REGEXP_EXTRACT_ALL"
|
|
4358
4372
|
else:
|
|
4359
4373
|
name = "REGEXP_EXTRACT"
|
|
@@ -4365,9 +4379,27 @@ class DuckDBGenerator(generator.Generator):
|
|
|
4365
4379
|
# Array slicing for REGEXP_EXTRACT_ALL with occurrence
|
|
4366
4380
|
if is_extract_all and non_single_occurrence:
|
|
4367
4381
|
result = exp.Bracket(this=result, expressions=[exp.Slice(this=occurrence)])
|
|
4368
|
-
|
|
4369
|
-
|
|
4370
|
-
|
|
4382
|
+
elif not is_extract_all and (non_single_occurrence or null_if_no_match):
|
|
4383
|
+
# Non-participating capture group yields [NULL] in DuckDB; Snowflake returns '' on a match
|
|
4384
|
+
if (
|
|
4385
|
+
expression.args.get("empty_if_group_missing")
|
|
4386
|
+
and group
|
|
4387
|
+
and not (group.is_int and group.to_py() == 0)
|
|
4388
|
+
):
|
|
4389
|
+
result = exp.Transform(
|
|
4390
|
+
this=result,
|
|
4391
|
+
expression=exp.Lambda(
|
|
4392
|
+
this=exp.Coalesce(
|
|
4393
|
+
this=exp.column("x"), expressions=[exp.Literal.string("")]
|
|
4394
|
+
),
|
|
4395
|
+
expressions=[exp.to_identifier("x")],
|
|
4396
|
+
),
|
|
4397
|
+
)
|
|
4398
|
+
return self.func(
|
|
4399
|
+
"ARRAY_EXTRACT",
|
|
4400
|
+
result,
|
|
4401
|
+
occurrence if non_single_occurrence else exp.Literal.number(1),
|
|
4402
|
+
)
|
|
4371
4403
|
|
|
4372
4404
|
return self.sql(result)
|
|
4373
4405
|
|
|
@@ -89,8 +89,12 @@ class OracleGenerator(generator.Generator):
|
|
|
89
89
|
exp.StrPosition: lambda self, e: strposition_sql(
|
|
90
90
|
self, e, func_name="INSTR", supports_position=True, supports_occurrence=True
|
|
91
91
|
),
|
|
92
|
-
exp.StrToTime: lambda self, e: self.func(
|
|
93
|
-
|
|
92
|
+
exp.StrToTime: lambda self, e: self.func(
|
|
93
|
+
"TO_TIMESTAMP", e.this, self.format_time(e), e.args.get("nlsparam")
|
|
94
|
+
),
|
|
95
|
+
exp.StrToDate: lambda self, e: self.func(
|
|
96
|
+
"TO_DATE", e.this, self.format_time(e), e.args.get("nlsparam")
|
|
97
|
+
),
|
|
94
98
|
exp.Subquery: lambda self, e: self.subquery_sql(e, sep=" "),
|
|
95
99
|
exp.Substring: rename_func("SUBSTR"),
|
|
96
100
|
exp.Table: lambda self, e: self.table_sql(e, sep=" "),
|
|
@@ -499,6 +499,7 @@ class SnowflakeGenerator(generator.Generator):
|
|
|
499
499
|
exp.GetExtract: rename_func("GET"),
|
|
500
500
|
exp.GroupConcat: lambda self, e: groupconcat_sql(self, e, sep=""),
|
|
501
501
|
exp.If: if_sql(name="IFF", false_value="NULL"),
|
|
502
|
+
exp.InteractiveProperty: lambda *_: "INTERACTIVE",
|
|
502
503
|
exp.JSONArray: lambda self, e: self.func(
|
|
503
504
|
"TO_VARIANT", self.func("ARRAY_CONSTRUCT", *e.expressions)
|
|
504
505
|
),
|
|
@@ -577,6 +578,9 @@ class SnowflakeGenerator(generator.Generator):
|
|
|
577
578
|
exp.StrtokToArray: rename_func("STRTOK_TO_ARRAY"),
|
|
578
579
|
exp.Stuff: rename_func("INSERT"),
|
|
579
580
|
exp.StPoint: rename_func("ST_MAKEPOINT"),
|
|
581
|
+
exp.TemporaryProperty: lambda _, e: (
|
|
582
|
+
"SCOPED TEMPORARY" if e.args.get("scoped") else "TEMPORARY"
|
|
583
|
+
),
|
|
580
584
|
exp.TimeAdd: date_delta_sql("TIMEADD"),
|
|
581
585
|
exp.TimeSlice: lambda self, e: self.func(
|
|
582
586
|
"TIME_SLICE",
|
|
@@ -648,6 +652,7 @@ class SnowflakeGenerator(generator.Generator):
|
|
|
648
652
|
PROPERTIES_LOCATION = {
|
|
649
653
|
**generator.Generator.PROPERTIES_LOCATION,
|
|
650
654
|
exp.CredentialsProperty: exp.Properties.Location.POST_WITH,
|
|
655
|
+
exp.InteractiveProperty: exp.Properties.Location.POST_CREATE,
|
|
651
656
|
exp.LocationProperty: exp.Properties.Location.POST_WITH,
|
|
652
657
|
exp.PartitionedByProperty: exp.Properties.Location.POST_SCHEMA,
|
|
653
658
|
exp.RowAccessProperty: exp.Properties.Location.POST_SCHEMA,
|
|
@@ -1008,23 +1013,22 @@ class SnowflakeGenerator(generator.Generator):
|
|
|
1008
1013
|
|
|
1009
1014
|
def createable_sql(self, expression: exp.Create, locations: defaultdict) -> str:
|
|
1010
1015
|
is_materialized = expression.find(exp.MaterializedProperty)
|
|
1011
|
-
|
|
1016
|
+
grants_property = expression.find(exp.CopyGrantsProperty, exp.IgnoreGrantsProperty)
|
|
1012
1017
|
|
|
1013
|
-
if expression.kind == "VIEW" and is_materialized and
|
|
1014
|
-
#
|
|
1015
|
-
#
|
|
1016
|
-
# We default CopyGrantsProperty to POST_SCHEMA which means we need to output it POST_NAME if a materialized view is detected
|
|
1018
|
+
if expression.kind == "VIEW" and is_materialized and grants_property:
|
|
1019
|
+
# Materialized views require COPY/IGNORE GRANTS before the column list,
|
|
1020
|
+
# whereas normal views use the default POST_SCHEMA location.
|
|
1017
1021
|
# ref: https://docs.snowflake.com/en/sql-reference/sql/create-materialized-view#syntax
|
|
1018
1022
|
# ref: https://docs.snowflake.com/en/sql-reference/sql/create-view#syntax
|
|
1019
1023
|
post_schema_properties = locations[exp.Properties.Location.POST_SCHEMA]
|
|
1020
|
-
post_schema_properties.pop(post_schema_properties.index(
|
|
1024
|
+
post_schema_properties.pop(post_schema_properties.index(grants_property))
|
|
1021
1025
|
|
|
1022
1026
|
this_name = self.sql(expression.this, "this")
|
|
1023
|
-
|
|
1027
|
+
grants = self.sql(grants_property)
|
|
1024
1028
|
this_schema = self.schema_columns_sql(expression.this)
|
|
1025
1029
|
this_schema = f"{self.sep()}{this_schema}" if this_schema else ""
|
|
1026
1030
|
|
|
1027
|
-
return f"{this_name}{self.sep()}{
|
|
1031
|
+
return f"{this_name}{self.sep()}{grants}{this_schema}"
|
|
1028
1032
|
|
|
1029
1033
|
return super().createable_sql(expression, locations)
|
|
1030
1034
|
|