sqlglotc 30.4.2__tar.gz → 30.5.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.
Potentially problematic release.
This version of sqlglotc might be problematic. Click here for more details.
- {sqlglotc-30.4.2/sqlglotc.egg-info → sqlglotc-30.5.0}/PKG-INFO +1 -1
- {sqlglotc-30.4.2 → sqlglotc-30.5.0}/sqlglot/expressions/constraints.py +4 -0
- {sqlglotc-30.4.2 → sqlglotc-30.5.0}/sqlglot/expressions/ddl.py +4 -0
- {sqlglotc-30.4.2 → sqlglotc-30.5.0}/sqlglot/expressions/dml.py +4 -1
- {sqlglotc-30.4.2 → sqlglotc-30.5.0}/sqlglot/expressions/functions.py +18 -0
- {sqlglotc-30.4.2 → sqlglotc-30.5.0}/sqlglot/expressions/math.py +6 -1
- {sqlglotc-30.4.2 → sqlglotc-30.5.0}/sqlglot/expressions/string.py +1 -1
- {sqlglotc-30.4.2 → sqlglotc-30.5.0}/sqlglot/generator.py +33 -5
- {sqlglotc-30.4.2 → sqlglotc-30.5.0}/sqlglot/generators/bigquery.py +3 -0
- {sqlglotc-30.4.2 → sqlglotc-30.5.0}/sqlglot/generators/clickhouse.py +26 -0
- {sqlglotc-30.4.2 → sqlglotc-30.5.0}/sqlglot/generators/duckdb.py +122 -3
- {sqlglotc-30.4.2 → sqlglotc-30.5.0}/sqlglot/generators/oracle.py +1 -0
- {sqlglotc-30.4.2 → sqlglotc-30.5.0}/sqlglot/generators/snowflake.py +5 -1
- {sqlglotc-30.4.2 → sqlglotc-30.5.0}/sqlglot/generators/spark.py +1 -0
- {sqlglotc-30.4.2 → sqlglotc-30.5.0}/sqlglot/generators/starrocks.py +8 -0
- {sqlglotc-30.4.2 → sqlglotc-30.5.0}/sqlglot/parser.py +27 -2
- {sqlglotc-30.4.2 → sqlglotc-30.5.0}/sqlglot/parsers/bigquery.py +3 -0
- {sqlglotc-30.4.2 → sqlglotc-30.5.0}/sqlglot/parsers/clickhouse.py +18 -0
- {sqlglotc-30.4.2 → sqlglotc-30.5.0}/sqlglot/parsers/databricks.py +1 -0
- {sqlglotc-30.4.2 → sqlglotc-30.5.0}/sqlglot/parsers/doris.py +5 -0
- {sqlglotc-30.4.2 → sqlglotc-30.5.0}/sqlglot/parsers/duckdb.py +1 -0
- {sqlglotc-30.4.2 → sqlglotc-30.5.0}/sqlglot/parsers/mysql.py +10 -0
- {sqlglotc-30.4.2 → sqlglotc-30.5.0}/sqlglot/parsers/snowflake.py +22 -9
- {sqlglotc-30.4.2 → sqlglotc-30.5.0}/sqlglot/parsers/spark.py +1 -0
- {sqlglotc-30.4.2 → sqlglotc-30.5.0}/sqlglot/parsers/starrocks.py +10 -1
- {sqlglotc-30.4.2 → sqlglotc-30.5.0/sqlglotc.egg-info}/PKG-INFO +1 -1
- {sqlglotc-30.4.2 → sqlglotc-30.5.0}/MANIFEST.in +0 -0
- {sqlglotc-30.4.2 → sqlglotc-30.5.0}/pyproject.toml +0 -0
- {sqlglotc-30.4.2 → sqlglotc-30.5.0}/setup.cfg +0 -0
- {sqlglotc-30.4.2 → sqlglotc-30.5.0}/setup.py +0 -0
- {sqlglotc-30.4.2 → sqlglotc-30.5.0}/sqlglot/errors.py +0 -0
- {sqlglotc-30.4.2 → sqlglotc-30.5.0}/sqlglot/executor/table.py +0 -0
- {sqlglotc-30.4.2 → sqlglotc-30.5.0}/sqlglot/expressions/aggregate.py +0 -0
- {sqlglotc-30.4.2 → sqlglotc-30.5.0}/sqlglot/expressions/array.py +0 -0
- {sqlglotc-30.4.2 → sqlglotc-30.5.0}/sqlglot/expressions/builders.py +0 -0
- {sqlglotc-30.4.2 → sqlglotc-30.5.0}/sqlglot/expressions/core.py +0 -0
- {sqlglotc-30.4.2 → sqlglotc-30.5.0}/sqlglot/expressions/datatypes.py +0 -0
- {sqlglotc-30.4.2 → sqlglotc-30.5.0}/sqlglot/expressions/json.py +0 -0
- {sqlglotc-30.4.2 → sqlglotc-30.5.0}/sqlglot/expressions/properties.py +0 -0
- {sqlglotc-30.4.2 → sqlglotc-30.5.0}/sqlglot/expressions/query.py +0 -0
- {sqlglotc-30.4.2 → sqlglotc-30.5.0}/sqlglot/expressions/temporal.py +0 -0
- {sqlglotc-30.4.2 → sqlglotc-30.5.0}/sqlglot/generators/athena.py +0 -0
- {sqlglotc-30.4.2 → sqlglotc-30.5.0}/sqlglot/generators/databricks.py +0 -0
- {sqlglotc-30.4.2 → sqlglotc-30.5.0}/sqlglot/generators/doris.py +0 -0
- {sqlglotc-30.4.2 → sqlglotc-30.5.0}/sqlglot/generators/dremio.py +0 -0
- {sqlglotc-30.4.2 → sqlglotc-30.5.0}/sqlglot/generators/drill.py +0 -0
- {sqlglotc-30.4.2 → sqlglotc-30.5.0}/sqlglot/generators/druid.py +0 -0
- {sqlglotc-30.4.2 → sqlglotc-30.5.0}/sqlglot/generators/dune.py +0 -0
- {sqlglotc-30.4.2 → sqlglotc-30.5.0}/sqlglot/generators/exasol.py +0 -0
- {sqlglotc-30.4.2 → sqlglotc-30.5.0}/sqlglot/generators/fabric.py +0 -0
- {sqlglotc-30.4.2 → sqlglotc-30.5.0}/sqlglot/generators/hive.py +0 -0
- {sqlglotc-30.4.2 → sqlglotc-30.5.0}/sqlglot/generators/materialize.py +0 -0
- {sqlglotc-30.4.2 → sqlglotc-30.5.0}/sqlglot/generators/mysql.py +0 -0
- {sqlglotc-30.4.2 → sqlglotc-30.5.0}/sqlglot/generators/postgres.py +0 -0
- {sqlglotc-30.4.2 → sqlglotc-30.5.0}/sqlglot/generators/presto.py +0 -0
- {sqlglotc-30.4.2 → sqlglotc-30.5.0}/sqlglot/generators/prql.py +0 -0
- {sqlglotc-30.4.2 → sqlglotc-30.5.0}/sqlglot/generators/redshift.py +0 -0
- {sqlglotc-30.4.2 → sqlglotc-30.5.0}/sqlglot/generators/risingwave.py +0 -0
- {sqlglotc-30.4.2 → sqlglotc-30.5.0}/sqlglot/generators/singlestore.py +0 -0
- {sqlglotc-30.4.2 → sqlglotc-30.5.0}/sqlglot/generators/solr.py +0 -0
- {sqlglotc-30.4.2 → sqlglotc-30.5.0}/sqlglot/generators/spark2.py +0 -0
- {sqlglotc-30.4.2 → sqlglotc-30.5.0}/sqlglot/generators/sqlite.py +0 -0
- {sqlglotc-30.4.2 → sqlglotc-30.5.0}/sqlglot/generators/tableau.py +0 -0
- {sqlglotc-30.4.2 → sqlglotc-30.5.0}/sqlglot/generators/teradata.py +0 -0
- {sqlglotc-30.4.2 → sqlglotc-30.5.0}/sqlglot/generators/trino.py +0 -0
- {sqlglotc-30.4.2 → sqlglotc-30.5.0}/sqlglot/generators/tsql.py +0 -0
- {sqlglotc-30.4.2 → sqlglotc-30.5.0}/sqlglot/helper.py +0 -0
- {sqlglotc-30.4.2 → sqlglotc-30.5.0}/sqlglot/optimizer/annotate_types.py +0 -0
- {sqlglotc-30.4.2 → sqlglotc-30.5.0}/sqlglot/optimizer/isolate_table_selects.py +0 -0
- {sqlglotc-30.4.2 → sqlglotc-30.5.0}/sqlglot/optimizer/normalize_identifiers.py +0 -0
- {sqlglotc-30.4.2 → sqlglotc-30.5.0}/sqlglot/optimizer/qualify.py +0 -0
- {sqlglotc-30.4.2 → sqlglotc-30.5.0}/sqlglot/optimizer/qualify_columns.py +0 -0
- {sqlglotc-30.4.2 → sqlglotc-30.5.0}/sqlglot/optimizer/qualify_tables.py +0 -0
- {sqlglotc-30.4.2 → sqlglotc-30.5.0}/sqlglot/optimizer/resolver.py +0 -0
- {sqlglotc-30.4.2 → sqlglotc-30.5.0}/sqlglot/optimizer/scope.py +0 -0
- {sqlglotc-30.4.2 → sqlglotc-30.5.0}/sqlglot/optimizer/simplify.py +0 -0
- {sqlglotc-30.4.2 → sqlglotc-30.5.0}/sqlglot/parsers/athena.py +0 -0
- {sqlglotc-30.4.2 → sqlglotc-30.5.0}/sqlglot/parsers/base.py +0 -0
- {sqlglotc-30.4.2 → sqlglotc-30.5.0}/sqlglot/parsers/dremio.py +0 -0
- {sqlglotc-30.4.2 → sqlglotc-30.5.0}/sqlglot/parsers/drill.py +0 -0
- {sqlglotc-30.4.2 → sqlglotc-30.5.0}/sqlglot/parsers/druid.py +0 -0
- {sqlglotc-30.4.2 → sqlglotc-30.5.0}/sqlglot/parsers/dune.py +0 -0
- {sqlglotc-30.4.2 → sqlglotc-30.5.0}/sqlglot/parsers/exasol.py +0 -0
- {sqlglotc-30.4.2 → sqlglotc-30.5.0}/sqlglot/parsers/fabric.py +0 -0
- {sqlglotc-30.4.2 → sqlglotc-30.5.0}/sqlglot/parsers/hive.py +0 -0
- {sqlglotc-30.4.2 → sqlglotc-30.5.0}/sqlglot/parsers/materialize.py +0 -0
- {sqlglotc-30.4.2 → sqlglotc-30.5.0}/sqlglot/parsers/oracle.py +0 -0
- {sqlglotc-30.4.2 → sqlglotc-30.5.0}/sqlglot/parsers/postgres.py +0 -0
- {sqlglotc-30.4.2 → sqlglotc-30.5.0}/sqlglot/parsers/presto.py +0 -0
- {sqlglotc-30.4.2 → sqlglotc-30.5.0}/sqlglot/parsers/prql.py +0 -0
- {sqlglotc-30.4.2 → sqlglotc-30.5.0}/sqlglot/parsers/redshift.py +0 -0
- {sqlglotc-30.4.2 → sqlglotc-30.5.0}/sqlglot/parsers/risingwave.py +0 -0
- {sqlglotc-30.4.2 → sqlglotc-30.5.0}/sqlglot/parsers/singlestore.py +0 -0
- {sqlglotc-30.4.2 → sqlglotc-30.5.0}/sqlglot/parsers/solr.py +0 -0
- {sqlglotc-30.4.2 → sqlglotc-30.5.0}/sqlglot/parsers/spark2.py +0 -0
- {sqlglotc-30.4.2 → sqlglotc-30.5.0}/sqlglot/parsers/sqlite.py +0 -0
- {sqlglotc-30.4.2 → sqlglotc-30.5.0}/sqlglot/parsers/tableau.py +0 -0
- {sqlglotc-30.4.2 → sqlglotc-30.5.0}/sqlglot/parsers/teradata.py +0 -0
- {sqlglotc-30.4.2 → sqlglotc-30.5.0}/sqlglot/parsers/trino.py +0 -0
- {sqlglotc-30.4.2 → sqlglotc-30.5.0}/sqlglot/parsers/tsql.py +0 -0
- {sqlglotc-30.4.2 → sqlglotc-30.5.0}/sqlglot/schema.py +0 -0
- {sqlglotc-30.4.2 → sqlglotc-30.5.0}/sqlglot/serde.py +0 -0
- {sqlglotc-30.4.2 → sqlglotc-30.5.0}/sqlglot/time.py +0 -0
- {sqlglotc-30.4.2 → sqlglotc-30.5.0}/sqlglot/tokenizer_core.py +0 -0
- {sqlglotc-30.4.2 → sqlglotc-30.5.0}/sqlglot/trie.py +0 -0
- {sqlglotc-30.4.2 → sqlglotc-30.5.0}/sqlglotc.egg-info/SOURCES.txt +0 -0
- {sqlglotc-30.4.2 → sqlglotc-30.5.0}/sqlglotc.egg-info/dependency_links.txt +0 -0
- {sqlglotc-30.4.2 → sqlglotc-30.5.0}/sqlglotc.egg-info/requires.txt +0 -0
- {sqlglotc-30.4.2 → sqlglotc-30.5.0}/sqlglotc.egg-info/top_level.txt +0 -0
|
@@ -79,6 +79,7 @@ class Delete(Expression, DML):
|
|
|
79
79
|
"limit": False,
|
|
80
80
|
"tables": False, # Multiple-Table Syntax (MySQL)
|
|
81
81
|
"cluster": False, # Clickhouse
|
|
82
|
+
"hint": False,
|
|
82
83
|
}
|
|
83
84
|
|
|
84
85
|
def delete(
|
|
@@ -282,7 +283,8 @@ class LoadData(Expression):
|
|
|
282
283
|
"this": True,
|
|
283
284
|
"local": False,
|
|
284
285
|
"overwrite": False,
|
|
285
|
-
"inpath":
|
|
286
|
+
"inpath": False,
|
|
287
|
+
"files": False,
|
|
286
288
|
"partition": False,
|
|
287
289
|
"input_format": False,
|
|
288
290
|
"serde": False,
|
|
@@ -300,6 +302,7 @@ class Update(Expression, DML):
|
|
|
300
302
|
"order": False,
|
|
301
303
|
"limit": False,
|
|
302
304
|
"options": False,
|
|
305
|
+
"hint": False,
|
|
303
306
|
}
|
|
304
307
|
|
|
305
308
|
def table(
|
|
@@ -321,6 +321,24 @@ class AIClassify(Expression, Func):
|
|
|
321
321
|
_sql_names = ["AI_CLASSIFY"]
|
|
322
322
|
|
|
323
323
|
|
|
324
|
+
class AIEmbed(Expression, Func):
|
|
325
|
+
arg_types = {"expressions": True}
|
|
326
|
+
is_var_len_args = True
|
|
327
|
+
_sql_names = ["AI_EMBED"]
|
|
328
|
+
|
|
329
|
+
|
|
330
|
+
class AISimilarity(Expression, Func):
|
|
331
|
+
arg_types = {"expressions": True}
|
|
332
|
+
is_var_len_args = True
|
|
333
|
+
_sql_names = ["AI_SIMILARITY"]
|
|
334
|
+
|
|
335
|
+
|
|
336
|
+
class AIGenerate(Expression, Func):
|
|
337
|
+
arg_types = {"expressions": True}
|
|
338
|
+
is_var_len_args = True
|
|
339
|
+
_sql_names = ["AI_GENERATE"]
|
|
340
|
+
|
|
341
|
+
|
|
324
342
|
class FeaturesAtTime(Expression, Func):
|
|
325
343
|
arg_types = {"this": True, "time": False, "num_rows": False, "ignore_feature_nulls": False}
|
|
326
344
|
|
|
@@ -108,7 +108,12 @@ class EuclideanDistance(Expression, Func):
|
|
|
108
108
|
|
|
109
109
|
|
|
110
110
|
class JarowinklerSimilarity(Expression, Func):
|
|
111
|
-
arg_types = {
|
|
111
|
+
arg_types = {
|
|
112
|
+
"this": True,
|
|
113
|
+
"expression": True,
|
|
114
|
+
"case_insensitive": False,
|
|
115
|
+
"integer_scale": False,
|
|
116
|
+
}
|
|
112
117
|
|
|
113
118
|
|
|
114
119
|
class ManhattanDistance(Expression, Func):
|
|
@@ -220,7 +220,7 @@ class Stuff(Expression, Func):
|
|
|
220
220
|
|
|
221
221
|
class Substring(Expression, Func):
|
|
222
222
|
_sql_names = ["SUBSTRING", "SUBSTR"]
|
|
223
|
-
arg_types = {"this": True, "start": False, "length": False}
|
|
223
|
+
arg_types = {"this": True, "start": False, "length": False, "zero_start": False}
|
|
224
224
|
|
|
225
225
|
|
|
226
226
|
class SubstringIndex(Expression, Func):
|
|
@@ -234,6 +234,7 @@ class Generator:
|
|
|
234
234
|
exp.ProjectionPolicyColumnConstraint: lambda self, e: (
|
|
235
235
|
f"PROJECTION POLICY {self.sql(e, 'this')}"
|
|
236
236
|
),
|
|
237
|
+
exp.InvisibleColumnConstraint: lambda self, e: "INVISIBLE",
|
|
237
238
|
exp.ZeroFillColumnConstraint: lambda self, e: "ZEROFILL",
|
|
238
239
|
exp.Put: lambda self, e: self.get_put_sql(e),
|
|
239
240
|
exp.RemoteWithConnectionModelProperty: lambda self, e: (
|
|
@@ -320,6 +321,9 @@ class Generator:
|
|
|
320
321
|
# Whether MERGE ... WHEN MATCHED BY SOURCE is allowed
|
|
321
322
|
MATCHED_BY_SOURCE = True
|
|
322
323
|
|
|
324
|
+
# Whether MERGE ... WHEN MATCHED/NOT MATCHED THEN UPDATE/INSERT ... WHERE is supported
|
|
325
|
+
SUPPORTS_MERGE_WHERE = False
|
|
326
|
+
|
|
323
327
|
# Whether the INTERVAL expression works only with values like '1 day'
|
|
324
328
|
SINGLE_STRING_INTERVAL = False
|
|
325
329
|
|
|
@@ -1681,6 +1685,7 @@ class Generator:
|
|
|
1681
1685
|
return f"{local}DIRECTORY {self.sql(expression, 'this')}{row_format}"
|
|
1682
1686
|
|
|
1683
1687
|
def delete_sql(self, expression: exp.Delete) -> str:
|
|
1688
|
+
hint = self.sql(expression, "hint")
|
|
1684
1689
|
this = self.sql(expression, "this")
|
|
1685
1690
|
this = f" FROM {this}" if this else ""
|
|
1686
1691
|
using = self.expressions(expression, key="using")
|
|
@@ -1697,7 +1702,7 @@ class Generator:
|
|
|
1697
1702
|
expression_sql = f"{this}{using}{cluster}{where}{returning}{order}{limit}"
|
|
1698
1703
|
else:
|
|
1699
1704
|
expression_sql = f"{returning}{this}{using}{cluster}{where}{order}{limit}"
|
|
1700
|
-
return self.prepend_ctes(expression, f"DELETE{tables}{expression_sql}")
|
|
1705
|
+
return self.prepend_ctes(expression, f"DELETE{hint}{tables}{expression_sql}")
|
|
1701
1706
|
|
|
1702
1707
|
def drop_sql(self, expression: exp.Drop) -> str:
|
|
1703
1708
|
this = self.sql(expression, "this")
|
|
@@ -2463,6 +2468,7 @@ class Generator:
|
|
|
2463
2468
|
return (join_sql, "")
|
|
2464
2469
|
|
|
2465
2470
|
def update_sql(self, expression: exp.Update) -> str:
|
|
2471
|
+
hint = self.sql(expression, "hint")
|
|
2466
2472
|
this = self.sql(expression, "this")
|
|
2467
2473
|
join_sql, from_sql = self._update_from_joins_sql(expression)
|
|
2468
2474
|
set_sql = self.expressions(expression, flat=True)
|
|
@@ -2476,7 +2482,7 @@ class Generator:
|
|
|
2476
2482
|
expression_sql = f"{returning}{from_sql}{where_sql}"
|
|
2477
2483
|
options = self.expressions(expression, key="options")
|
|
2478
2484
|
options = f" OPTION({options})" if options else ""
|
|
2479
|
-
sql = f"UPDATE {this}{join_sql} SET {set_sql}{expression_sql}{order}{limit}{options}"
|
|
2485
|
+
sql = f"UPDATE{hint} {this}{join_sql} SET {set_sql}{expression_sql}{order}{limit}{options}"
|
|
2480
2486
|
return self.prepend_ctes(expression, sql)
|
|
2481
2487
|
|
|
2482
2488
|
def values_sql(self, expression: exp.Values, values_as_table: bool = True) -> str:
|
|
@@ -2811,10 +2817,20 @@ class Generator:
|
|
|
2811
2817
|
return self._replace_line_breaks(text).replace(delimiter, escaped_delimiter)
|
|
2812
2818
|
|
|
2813
2819
|
def loaddata_sql(self, expression: exp.LoadData) -> str:
|
|
2820
|
+
is_overwrite = expression.args.get("overwrite")
|
|
2821
|
+
overwrite = " OVERWRITE" if is_overwrite else ""
|
|
2822
|
+
this = self.sql(expression, "this")
|
|
2823
|
+
|
|
2824
|
+
files = expression.args.get("files")
|
|
2825
|
+
if files:
|
|
2826
|
+
files_sql = self.expressions(files, flat=True)
|
|
2827
|
+
files_sql = f"FILES{self.wrap(files_sql)}"
|
|
2828
|
+
this = f" {this}" if is_overwrite else f" INTO TABLE {this}"
|
|
2829
|
+
return f"LOAD DATA{overwrite}{this} FROM {files_sql}"
|
|
2830
|
+
|
|
2814
2831
|
local = " LOCAL" if expression.args.get("local") else ""
|
|
2815
2832
|
inpath = f" INPATH {self.sql(expression, 'inpath')}"
|
|
2816
|
-
|
|
2817
|
-
this = f" INTO TABLE {self.sql(expression, 'this')}"
|
|
2833
|
+
this = f" INTO TABLE {this}"
|
|
2818
2834
|
partition = self.sql(expression, "partition")
|
|
2819
2835
|
partition = f" {partition}" if partition else ""
|
|
2820
2836
|
input_format = self.sql(expression, "input_format")
|
|
@@ -4448,9 +4464,16 @@ class Generator:
|
|
|
4448
4464
|
else:
|
|
4449
4465
|
expressions_sql = self.expressions(then_expression)
|
|
4450
4466
|
then = f"UPDATE SET{self.sep()}{expressions_sql}" if expressions_sql else "UPDATE"
|
|
4451
|
-
|
|
4452
4467
|
else:
|
|
4453
4468
|
then = self.sql(then_expression)
|
|
4469
|
+
|
|
4470
|
+
if isinstance(then_expression, (exp.Insert, exp.Update)):
|
|
4471
|
+
where = self.sql(then_expression, "where")
|
|
4472
|
+
if where and not self.SUPPORTS_MERGE_WHERE:
|
|
4473
|
+
kind = "INSERT" if isinstance(then_expression, exp.Insert) else "UPDATE"
|
|
4474
|
+
self.unsupported(f"WHERE clause in MERGE {kind} is not supported")
|
|
4475
|
+
where = ""
|
|
4476
|
+
then = f"{then}{where}"
|
|
4454
4477
|
return f"WHEN {matched}{source}{condition} THEN {then}"
|
|
4455
4478
|
|
|
4456
4479
|
def whens_sql(self, expression: exp.Whens) -> str:
|
|
@@ -5899,3 +5922,8 @@ class Generator:
|
|
|
5899
5922
|
def usingproperty_sql(self, expression: exp.UsingProperty) -> str:
|
|
5900
5923
|
kind = expression.args.get("kind")
|
|
5901
5924
|
return f"USING {kind} {self.sql(expression, 'this')}"
|
|
5925
|
+
|
|
5926
|
+
def renameindex_sql(self, expression: exp.RenameIndex) -> str:
|
|
5927
|
+
this = self.sql(expression, "this")
|
|
5928
|
+
to = self.sql(expression, "to")
|
|
5929
|
+
return f"RENAME INDEX {this} TO {to}"
|
|
@@ -272,6 +272,9 @@ class BigQueryGenerator(generator.Generator):
|
|
|
272
272
|
|
|
273
273
|
TRANSFORMS = {
|
|
274
274
|
**generator.Generator.TRANSFORMS,
|
|
275
|
+
exp.AIEmbed: rename_func("EMBED"),
|
|
276
|
+
exp.AIGenerate: rename_func("GENERATE"),
|
|
277
|
+
exp.AISimilarity: rename_func("SIMILARITY"),
|
|
275
278
|
exp.ApproxTopK: rename_func("APPROX_TOP_COUNT"),
|
|
276
279
|
exp.ApproxDistinct: rename_func("APPROX_COUNT_DISTINCT"),
|
|
277
280
|
exp.ArgMax: arg_max_or_min_no_count("MAX_BY"),
|
|
@@ -416,6 +416,32 @@ class ClickHouseGenerator(generator.Generator):
|
|
|
416
416
|
exp.DType.MULTIPOLYGON,
|
|
417
417
|
}
|
|
418
418
|
|
|
419
|
+
def groupconcat_sql(self, expression: exp.GroupConcat) -> str:
|
|
420
|
+
this = expression.this
|
|
421
|
+
separator = expression.args.get("separator")
|
|
422
|
+
|
|
423
|
+
if isinstance(this, exp.Limit) and this.this:
|
|
424
|
+
limit = this
|
|
425
|
+
this = limit.this.pop()
|
|
426
|
+
return self.sql(
|
|
427
|
+
exp.ParameterizedAgg(
|
|
428
|
+
this="groupConcat",
|
|
429
|
+
params=[this],
|
|
430
|
+
expressions=[separator, limit.expression],
|
|
431
|
+
)
|
|
432
|
+
)
|
|
433
|
+
|
|
434
|
+
if separator:
|
|
435
|
+
return self.sql(
|
|
436
|
+
exp.ParameterizedAgg(
|
|
437
|
+
this="groupConcat",
|
|
438
|
+
params=[this],
|
|
439
|
+
expressions=[separator],
|
|
440
|
+
)
|
|
441
|
+
)
|
|
442
|
+
|
|
443
|
+
return self.func("groupConcat", this)
|
|
444
|
+
|
|
419
445
|
def offset_sql(self, expression: exp.Offset) -> str:
|
|
420
446
|
offset = super().offset_sql(expression)
|
|
421
447
|
|
|
@@ -24,7 +24,6 @@ from sqlglot.dialects.dialect import (
|
|
|
24
24
|
getbit_sql,
|
|
25
25
|
groupconcat_sql,
|
|
26
26
|
inline_array_unless_query,
|
|
27
|
-
jarowinkler_similarity,
|
|
28
27
|
months_between_sql,
|
|
29
28
|
no_datetime_sql,
|
|
30
29
|
no_comment_column_constraint_sql,
|
|
@@ -1537,7 +1536,6 @@ class DuckDBGenerator(generator.Generator):
|
|
|
1537
1536
|
exp.BitwiseOrAgg: _bitwise_agg_sql,
|
|
1538
1537
|
exp.BitwiseRightShift: _bitshift_sql,
|
|
1539
1538
|
exp.BitwiseXorAgg: _bitwise_agg_sql,
|
|
1540
|
-
exp.ByteLength: lambda self, e: self.func("OCTET_LENGTH", e.this),
|
|
1541
1539
|
exp.CommentColumnConstraint: no_comment_column_constraint_sql,
|
|
1542
1540
|
exp.Corr: lambda self, e: self._corr_sql(e),
|
|
1543
1541
|
exp.CosineDistance: rename_func("LIST_COSINE_DISTANCE"),
|
|
@@ -1609,7 +1607,6 @@ class DuckDBGenerator(generator.Generator):
|
|
|
1609
1607
|
),
|
|
1610
1608
|
exp.Ceil: _ceil_floor,
|
|
1611
1609
|
exp.Floor: _ceil_floor,
|
|
1612
|
-
exp.JarowinklerSimilarity: jarowinkler_similarity("JARO_WINKLER_SIMILARITY"),
|
|
1613
1610
|
exp.JSONBExists: rename_func("JSON_EXISTS"),
|
|
1614
1611
|
exp.JSONExtract: _arrow_json_extract_sql,
|
|
1615
1612
|
exp.JSONExtractArray: _json_extract_value_array_sql,
|
|
@@ -2259,6 +2256,47 @@ class DuckDBGenerator(generator.Generator):
|
|
|
2259
2256
|
self.unsupported("DuckDB does not support the COMPRESS() function")
|
|
2260
2257
|
return self.function_fallback_sql(expression)
|
|
2261
2258
|
|
|
2259
|
+
def encrypt_sql(self, expression: exp.Encrypt) -> str:
|
|
2260
|
+
self.unsupported("ENCRYPT is not supported in DuckDB")
|
|
2261
|
+
return self.function_fallback_sql(expression)
|
|
2262
|
+
|
|
2263
|
+
def decrypt_sql(self, expression: exp.Decrypt) -> str:
|
|
2264
|
+
func_name = "TRY_DECRYPT" if expression.args.get("safe") else "DECRYPT"
|
|
2265
|
+
self.unsupported(f"{func_name} is not supported in DuckDB")
|
|
2266
|
+
return self.function_fallback_sql(expression)
|
|
2267
|
+
|
|
2268
|
+
def decryptraw_sql(self, expression: exp.DecryptRaw) -> str:
|
|
2269
|
+
func_name = "TRY_DECRYPT_RAW" if expression.args.get("safe") else "DECRYPT_RAW"
|
|
2270
|
+
self.unsupported(f"{func_name} is not supported in DuckDB")
|
|
2271
|
+
return self.function_fallback_sql(expression)
|
|
2272
|
+
|
|
2273
|
+
def encryptraw_sql(self, expression: exp.EncryptRaw) -> str:
|
|
2274
|
+
self.unsupported("ENCRYPT_RAW is not supported in DuckDB")
|
|
2275
|
+
return self.function_fallback_sql(expression)
|
|
2276
|
+
|
|
2277
|
+
def parseurl_sql(self, expression: exp.ParseUrl) -> str:
|
|
2278
|
+
self.unsupported("PARSE_URL is not supported in DuckDB")
|
|
2279
|
+
return self.function_fallback_sql(expression)
|
|
2280
|
+
|
|
2281
|
+
def parseip_sql(self, expression: exp.ParseIp) -> str:
|
|
2282
|
+
self.unsupported("PARSE_IP is not supported in DuckDB")
|
|
2283
|
+
return self.function_fallback_sql(expression)
|
|
2284
|
+
|
|
2285
|
+
def jarowinklersimilarity_sql(self, expression: exp.JarowinklerSimilarity) -> str:
|
|
2286
|
+
this = expression.this
|
|
2287
|
+
expr = expression.expression
|
|
2288
|
+
|
|
2289
|
+
if expression.args.get("case_insensitive"):
|
|
2290
|
+
this = exp.Upper(this=this)
|
|
2291
|
+
expr = exp.Upper(this=expr)
|
|
2292
|
+
|
|
2293
|
+
result = exp.func("JARO_WINKLER_SIMILARITY", this, expr)
|
|
2294
|
+
|
|
2295
|
+
if expression.args.get("integer_scale"):
|
|
2296
|
+
result = exp.cast(result * 100, "INTEGER")
|
|
2297
|
+
|
|
2298
|
+
return self.sql(result)
|
|
2299
|
+
|
|
2262
2300
|
def nthvalue_sql(self, expression: exp.NthValue) -> str:
|
|
2263
2301
|
from_first = expression.args.get("from_first", True)
|
|
2264
2302
|
if not from_first:
|
|
@@ -2293,6 +2331,17 @@ class DuckDBGenerator(generator.Generator):
|
|
|
2293
2331
|
replacements = {"seed": seed_value, "length": length}
|
|
2294
2332
|
return f"({self.sql(exp.replace_placeholders(self.RANDSTR_TEMPLATE, **replacements))})"
|
|
2295
2333
|
|
|
2334
|
+
@unsupported_args("finish")
|
|
2335
|
+
def reduce_sql(self, expression: exp.Reduce) -> str:
|
|
2336
|
+
array_arg = expression.this
|
|
2337
|
+
initial_value = expression.args.get("initial")
|
|
2338
|
+
merge_lambda = expression.args.get("merge")
|
|
2339
|
+
|
|
2340
|
+
if merge_lambda:
|
|
2341
|
+
merge_lambda.set("colon", True)
|
|
2342
|
+
|
|
2343
|
+
return self.func("list_reduce", array_arg, merge_lambda, initial_value)
|
|
2344
|
+
|
|
2296
2345
|
def zipf_sql(self, expression: exp.Zipf) -> str:
|
|
2297
2346
|
"""
|
|
2298
2347
|
Transpile Snowflake's ZIPF to DuckDB using CDF-based inverse sampling.
|
|
@@ -2431,6 +2480,10 @@ class DuckDBGenerator(generator.Generator):
|
|
|
2431
2480
|
from_ = f" FROM {from_}" if from_ else ""
|
|
2432
2481
|
return f"SHOW {expression.name}{from_}"
|
|
2433
2482
|
|
|
2483
|
+
def soundex_sql(self, expression: exp.Soundex) -> str:
|
|
2484
|
+
self.unsupported("SOUNDEX is not supported in DuckDB")
|
|
2485
|
+
return self.func("SOUNDEX", expression.this)
|
|
2486
|
+
|
|
2434
2487
|
def sortarray_sql(self, expression: exp.SortArray) -> str:
|
|
2435
2488
|
arr = expression.this
|
|
2436
2489
|
asc = expression.args.get("asc")
|
|
@@ -2504,6 +2557,20 @@ class DuckDBGenerator(generator.Generator):
|
|
|
2504
2557
|
|
|
2505
2558
|
return strposition_sql(self, expression)
|
|
2506
2559
|
|
|
2560
|
+
def substring_sql(self, expression: exp.Substring) -> str:
|
|
2561
|
+
if expression.args.get("zero_start"):
|
|
2562
|
+
start = expression.args.get("start")
|
|
2563
|
+
length = expression.args.get("length")
|
|
2564
|
+
|
|
2565
|
+
if start := expression.args.get("start"):
|
|
2566
|
+
start = exp.If(this=start.eq(0), true=exp.Literal.number(1), false=start)
|
|
2567
|
+
if length := expression.args.get("length"):
|
|
2568
|
+
length = exp.If(this=length < 0, true=exp.Literal.number(0), false=length)
|
|
2569
|
+
|
|
2570
|
+
return self.func("SUBSTRING", expression.this, start, length)
|
|
2571
|
+
|
|
2572
|
+
return self.function_fallback_sql(expression)
|
|
2573
|
+
|
|
2507
2574
|
def strtotime_sql(self, expression: exp.StrToTime) -> str:
|
|
2508
2575
|
# Check if target_type requires TIMESTAMPTZ (for LTZ/TZ variants)
|
|
2509
2576
|
target_type = expression.args.get("target_type")
|
|
@@ -3229,6 +3296,10 @@ class DuckDBGenerator(generator.Generator):
|
|
|
3229
3296
|
)
|
|
3230
3297
|
)
|
|
3231
3298
|
|
|
3299
|
+
def arrayunionagg_sql(self, expression: exp.ArrayUnionAgg) -> str:
|
|
3300
|
+
self.unsupported("ARRAY_UNION_AGG is not supported in DuckDB")
|
|
3301
|
+
return self.function_fallback_sql(expression)
|
|
3302
|
+
|
|
3232
3303
|
def arraydistinct_sql(self, expression: exp.ArrayDistinct) -> str:
|
|
3233
3304
|
arr = expression.this
|
|
3234
3305
|
func = self.func("LIST_DISTINCT", arr)
|
|
@@ -3396,6 +3467,44 @@ class DuckDBGenerator(generator.Generator):
|
|
|
3396
3467
|
def rtrimmedlength_sql(self, expression: exp.RtrimmedLength) -> str:
|
|
3397
3468
|
return self.func("LENGTH", exp.Trim(this=expression.this, position="TRAILING"))
|
|
3398
3469
|
|
|
3470
|
+
def stuff_sql(self, expression: exp.Stuff) -> str:
|
|
3471
|
+
base = expression.this
|
|
3472
|
+
start = expression.args["start"]
|
|
3473
|
+
length = expression.args["length"]
|
|
3474
|
+
insertion = expression.expression
|
|
3475
|
+
is_binary = _is_binary(base)
|
|
3476
|
+
|
|
3477
|
+
if is_binary:
|
|
3478
|
+
# DuckDB's SUBSTRING doesn't accept BLOB; operate on the HEX string instead
|
|
3479
|
+
# (each byte = 2 hex chars), then UNHEX back to BLOB
|
|
3480
|
+
base = exp.Hex(this=base)
|
|
3481
|
+
insertion = exp.Hex(this=insertion)
|
|
3482
|
+
left = exp.Substring(
|
|
3483
|
+
this=base.copy(),
|
|
3484
|
+
start=exp.Literal.number(1),
|
|
3485
|
+
length=(start.copy() - exp.Literal.number(1)) * exp.Literal.number(2),
|
|
3486
|
+
)
|
|
3487
|
+
right = exp.Substring(
|
|
3488
|
+
this=base.copy(),
|
|
3489
|
+
start=((start + length) - exp.Literal.number(1)) * exp.Literal.number(2)
|
|
3490
|
+
+ exp.Literal.number(1),
|
|
3491
|
+
)
|
|
3492
|
+
else:
|
|
3493
|
+
left = exp.Substring(
|
|
3494
|
+
this=base.copy(),
|
|
3495
|
+
start=exp.Literal.number(1),
|
|
3496
|
+
length=start.copy() - exp.Literal.number(1),
|
|
3497
|
+
)
|
|
3498
|
+
right = exp.Substring(this=base.copy(), start=start + length)
|
|
3499
|
+
result: exp.Expr = exp.DPipe(
|
|
3500
|
+
this=exp.DPipe(this=left, expression=insertion), expression=right
|
|
3501
|
+
)
|
|
3502
|
+
|
|
3503
|
+
if is_binary:
|
|
3504
|
+
result = exp.Unhex(this=result)
|
|
3505
|
+
|
|
3506
|
+
return self.sql(result)
|
|
3507
|
+
|
|
3399
3508
|
def rand_sql(self, expression: exp.Rand) -> str:
|
|
3400
3509
|
seed = expression.this
|
|
3401
3510
|
if seed is not None:
|
|
@@ -3416,6 +3525,16 @@ class DuckDBGenerator(generator.Generator):
|
|
|
3416
3525
|
# Default DuckDB behavior - just return RANDOM() as float
|
|
3417
3526
|
return "RANDOM()"
|
|
3418
3527
|
|
|
3528
|
+
def bytelength_sql(self, expression: exp.ByteLength) -> str:
|
|
3529
|
+
arg = expression.this
|
|
3530
|
+
|
|
3531
|
+
# Check if it's a text type (handles both literals and annotated expressions)
|
|
3532
|
+
if arg.is_type(*exp.DataType.TEXT_TYPES):
|
|
3533
|
+
return self.func("OCTET_LENGTH", exp.Encode(this=arg))
|
|
3534
|
+
|
|
3535
|
+
# Default: pass through as-is (conservative for DuckDB, handles binary and unannotated)
|
|
3536
|
+
return self.func("OCTET_LENGTH", arg)
|
|
3537
|
+
|
|
3419
3538
|
def base64encode_sql(self, expression: exp.Base64Encode) -> str:
|
|
3420
3539
|
# DuckDB TO_BASE64 requires BLOB input
|
|
3421
3540
|
# Snowflake BASE64_ENCODE accepts both VARCHAR and BINARY - for VARCHAR it implicitly
|
|
@@ -497,6 +497,9 @@ class SnowflakeGenerator(generator.Generator):
|
|
|
497
497
|
exp.GetExtract: rename_func("GET"),
|
|
498
498
|
exp.GroupConcat: lambda self, e: groupconcat_sql(self, e, sep=""),
|
|
499
499
|
exp.If: if_sql(name="IFF", false_value="NULL"),
|
|
500
|
+
exp.JSONArray: lambda self, e: self.func(
|
|
501
|
+
"TO_VARIANT", self.func("ARRAY_CONSTRUCT", *e.expressions)
|
|
502
|
+
),
|
|
500
503
|
exp.JSONExtractArray: _json_extract_value_array_sql,
|
|
501
504
|
exp.JSONExtractScalar: lambda self, e: self.func(
|
|
502
505
|
"JSON_EXTRACT_PATH_TEXT", e.this, e.expression
|
|
@@ -640,6 +643,7 @@ class SnowflakeGenerator(generator.Generator):
|
|
|
640
643
|
TYPE_MAPPING = {
|
|
641
644
|
**generator.Generator.TYPE_MAPPING,
|
|
642
645
|
exp.DType.BIGDECIMAL: "DOUBLE",
|
|
646
|
+
exp.DType.JSON: "VARIANT",
|
|
643
647
|
exp.DType.NESTED: "OBJECT",
|
|
644
648
|
exp.DType.STRUCT: "OBJECT",
|
|
645
649
|
exp.DType.TEXT: "VARCHAR",
|
|
@@ -863,7 +867,7 @@ class SnowflakeGenerator(generator.Generator):
|
|
|
863
867
|
def rowaccessproperty_sql(self, expression: exp.RowAccessProperty) -> str:
|
|
864
868
|
if not expression.this:
|
|
865
869
|
return "ROW ACCESS"
|
|
866
|
-
on = f" ON ({self.expressions(expression, flat=True)})"
|
|
870
|
+
on = f" ON ({self.expressions(expression, flat=True)})" if expression.expressions else ""
|
|
867
871
|
return f"WITH ROW ACCESS POLICY {self.sql(expression, 'this')}{on}"
|
|
868
872
|
|
|
869
873
|
def describe_sql(self, expression: exp.Describe) -> str:
|
|
@@ -119,6 +119,7 @@ class SparkGenerator(Spark2Generator):
|
|
|
119
119
|
f"PARTITIONED BY {self.wrap(self.expressions(sqls=[_normalize_partition(e) for e in e.this.expressions], skip_first=True))}"
|
|
120
120
|
),
|
|
121
121
|
exp.SafeAdd: rename_func("TRY_ADD"),
|
|
122
|
+
exp.SafeDivide: rename_func("TRY_DIVIDE"),
|
|
122
123
|
exp.SafeMultiply: rename_func("TRY_MULTIPLY"),
|
|
123
124
|
exp.SafeSubtract: rename_func("TRY_SUBTRACT"),
|
|
124
125
|
exp.StartsWith: rename_func("STARTSWITH"),
|
|
@@ -100,6 +100,14 @@ class StarRocksGenerator(MySQLGenerator):
|
|
|
100
100
|
exp.JSONExtract: arrow_json_extract_sql,
|
|
101
101
|
exp.Property: property_sql,
|
|
102
102
|
exp.RegexpLike: rename_func("REGEXP"),
|
|
103
|
+
# Inherited from MySQL, minus operations StarRocks supports natively
|
|
104
|
+
# (QUALIFY, FULL OUTER JOIN, SEMI/ANTI JOIN)
|
|
105
|
+
exp.Select: transforms.preprocess(
|
|
106
|
+
[
|
|
107
|
+
transforms.eliminate_distinct_on,
|
|
108
|
+
transforms.unnest_generate_date_array_using_recursive_cte,
|
|
109
|
+
]
|
|
110
|
+
),
|
|
103
111
|
exp.SchemaCommentProperty: lambda self, e: self.naked_property(e),
|
|
104
112
|
exp.SqlSecurityProperty: lambda self, e: f"SECURITY {self.sql(e.this)}",
|
|
105
113
|
exp.StDistance: st_distance_sphere,
|
|
@@ -291,12 +291,15 @@ class Parser:
|
|
|
291
291
|
max_errors: Maximum number of error messages to include in a raised ParseError.
|
|
292
292
|
This is only relevant if error_level is ErrorLevel.RAISE.
|
|
293
293
|
Default: 3
|
|
294
|
+
max_nodes: Maximum number of AST nodes to prevent memory exhaustion.
|
|
295
|
+
Set to -1 (default) to disable the check.
|
|
294
296
|
"""
|
|
295
297
|
|
|
296
298
|
__slots__ = (
|
|
297
299
|
"error_level",
|
|
298
300
|
"error_message_context",
|
|
299
301
|
"max_errors",
|
|
302
|
+
"max_nodes",
|
|
300
303
|
"dialect",
|
|
301
304
|
"sql",
|
|
302
305
|
"errors",
|
|
@@ -310,6 +313,7 @@ class Parser:
|
|
|
310
313
|
"_chunks",
|
|
311
314
|
"_chunk_index",
|
|
312
315
|
"_tokens_size",
|
|
316
|
+
"_node_count",
|
|
313
317
|
)
|
|
314
318
|
|
|
315
319
|
FUNCTIONS: t.ClassVar[dict[str, t.Callable]] = {
|
|
@@ -1825,11 +1829,13 @@ class Parser:
|
|
|
1825
1829
|
error_level: ErrorLevel | None = None,
|
|
1826
1830
|
error_message_context: int = 100,
|
|
1827
1831
|
max_errors: int = 3,
|
|
1832
|
+
max_nodes: int = -1,
|
|
1828
1833
|
dialect: DialectType = None,
|
|
1829
1834
|
):
|
|
1830
1835
|
self.error_level: ErrorLevel = error_level or ErrorLevel.IMMEDIATE
|
|
1831
1836
|
self.error_message_context: int = error_message_context
|
|
1832
1837
|
self.max_errors: int = max_errors
|
|
1838
|
+
self.max_nodes: int = max_nodes
|
|
1833
1839
|
self.dialect: t.Any = _resolve_dialect(dialect)
|
|
1834
1840
|
self.sql: str = ""
|
|
1835
1841
|
self.errors: list[ParseError] = []
|
|
@@ -1843,6 +1849,7 @@ class Parser:
|
|
|
1843
1849
|
self._pipe_cte_counter: int = 0
|
|
1844
1850
|
self._chunks: list[list[Token]] = []
|
|
1845
1851
|
self._chunk_index: i64 = 0
|
|
1852
|
+
self._node_count: int = 0
|
|
1846
1853
|
|
|
1847
1854
|
def reset(self) -> None:
|
|
1848
1855
|
self.sql = ""
|
|
@@ -1857,6 +1864,7 @@ class Parser:
|
|
|
1857
1864
|
self._pipe_cte_counter = 0
|
|
1858
1865
|
self._chunks = []
|
|
1859
1866
|
self._chunk_index = 0
|
|
1867
|
+
self._node_count = 0
|
|
1860
1868
|
|
|
1861
1869
|
def _advance(self, times: i64 = 1) -> None:
|
|
1862
1870
|
index = self._index + times
|
|
@@ -1971,6 +1979,10 @@ class Parser:
|
|
|
1971
1979
|
self.errors.append(error)
|
|
1972
1980
|
|
|
1973
1981
|
def validate_expression(self, expression: E, args: list | None = None) -> E:
|
|
1982
|
+
if self.max_nodes > -1:
|
|
1983
|
+
self._node_count += 1
|
|
1984
|
+
if self._node_count > self.max_nodes:
|
|
1985
|
+
self.raise_error(f"Maximum number of AST nodes ({self.max_nodes}) exceeded")
|
|
1974
1986
|
if self.error_level != ErrorLevel.IGNORE:
|
|
1975
1987
|
for error_message in expression.error_messages(args):
|
|
1976
1988
|
self.raise_error(error_message)
|
|
@@ -3558,6 +3570,8 @@ class Parser:
|
|
|
3558
3570
|
local=local,
|
|
3559
3571
|
overwrite=overwrite,
|
|
3560
3572
|
inpath=inpath,
|
|
3573
|
+
files=self._match_text_seq("FROM", "FILES")
|
|
3574
|
+
and exp.Properties(expressions=self._parse_wrapped_properties()),
|
|
3561
3575
|
partition=self._parse_partition(),
|
|
3562
3576
|
input_format=self._match_text_seq("INPUTFORMAT") and self._parse_string(),
|
|
3563
3577
|
serde=self._match_text_seq("SERDE") and self._parse_string(),
|
|
@@ -3566,6 +3580,8 @@ class Parser:
|
|
|
3566
3580
|
return self._parse_as_command(self._prev)
|
|
3567
3581
|
|
|
3568
3582
|
def _parse_delete(self) -> exp.Delete:
|
|
3583
|
+
hint = self._parse_hint()
|
|
3584
|
+
|
|
3569
3585
|
# This handles MySQL's "Multiple-Table Syntax"
|
|
3570
3586
|
# https://dev.mysql.com/doc/refman/8.0/en/delete.html
|
|
3571
3587
|
tables = None
|
|
@@ -3576,6 +3592,7 @@ class Parser:
|
|
|
3576
3592
|
|
|
3577
3593
|
return self.expression(
|
|
3578
3594
|
exp.Delete(
|
|
3595
|
+
hint=hint,
|
|
3579
3596
|
tables=tables,
|
|
3580
3597
|
this=self._match(TokenType.FROM) and self._parse_table(joins=True),
|
|
3581
3598
|
using=self._match(TokenType.USING)
|
|
@@ -3589,7 +3606,9 @@ class Parser:
|
|
|
3589
3606
|
)
|
|
3590
3607
|
|
|
3591
3608
|
def _parse_update(self) -> exp.Update:
|
|
3609
|
+
hint = self._parse_hint()
|
|
3592
3610
|
kwargs: dict[str, object] = {
|
|
3611
|
+
"hint": hint,
|
|
3593
3612
|
"this": self._parse_table(joins=True, alias_tokens=self.UPDATE_ALIAS_TOKENS),
|
|
3594
3613
|
}
|
|
3595
3614
|
while self._curr:
|
|
@@ -7243,7 +7262,11 @@ class Parser:
|
|
|
7243
7262
|
return result
|
|
7244
7263
|
|
|
7245
7264
|
def _parse_unique_key(self) -> exp.Expr | None:
|
|
7246
|
-
if
|
|
7265
|
+
if (
|
|
7266
|
+
self._curr
|
|
7267
|
+
and self._curr.token_type != TokenType.IDENTIFIER
|
|
7268
|
+
and self._curr.text.upper() in self.CONSTRAINT_PARSERS
|
|
7269
|
+
):
|
|
7247
7270
|
return None
|
|
7248
7271
|
return self._parse_id_var(any_token=False)
|
|
7249
7272
|
|
|
@@ -8926,6 +8949,7 @@ class Parser:
|
|
|
8926
8949
|
if self._match_text_seq("ROW")
|
|
8927
8950
|
else self._parse_value(values=False),
|
|
8928
8951
|
expression=self._match_text_seq("VALUES") and self._parse_value(),
|
|
8952
|
+
where=self._parse_where(),
|
|
8929
8953
|
)
|
|
8930
8954
|
)
|
|
8931
8955
|
elif self._match(TokenType.UPDATE):
|
|
@@ -8936,7 +8960,8 @@ class Parser:
|
|
|
8936
8960
|
then = self.expression(
|
|
8937
8961
|
exp.Update(
|
|
8938
8962
|
expressions=self._match(TokenType.SET)
|
|
8939
|
-
and self._parse_csv(self._parse_equality)
|
|
8963
|
+
and self._parse_csv(self._parse_equality),
|
|
8964
|
+
where=self._parse_where(),
|
|
8940
8965
|
)
|
|
8941
8966
|
)
|
|
8942
8967
|
elif self._match(TokenType.DELETE):
|
|
@@ -199,7 +199,9 @@ class BigQueryParser(parser.Parser):
|
|
|
199
199
|
"DATETIME_SUB": build_date_delta_with_interval(exp.DatetimeSub),
|
|
200
200
|
"DIV": binary_from_function(exp.IntDiv),
|
|
201
201
|
"EDIT_DISTANCE": _build_levenshtein,
|
|
202
|
+
"EMBED": exp.AIEmbed.from_arg_list,
|
|
202
203
|
"FORMAT_DATE": _build_format_time(exp.TsOrDsToDate),
|
|
204
|
+
"GENERATE": exp.AIGenerate.from_arg_list,
|
|
203
205
|
"GENERATE_ARRAY": exp.GenerateSeries.from_arg_list,
|
|
204
206
|
"JSON_EXTRACT_SCALAR": _build_extract_json_with_default_path(exp.JSONExtractScalar),
|
|
205
207
|
"JSON_EXTRACT_ARRAY": _build_extract_json_with_default_path(exp.JSONExtractArray),
|
|
@@ -238,6 +240,7 @@ class BigQueryParser(parser.Parser):
|
|
|
238
240
|
this=seq_get(args, 0), length=exp.Literal.number(256)
|
|
239
241
|
),
|
|
240
242
|
"SHA512": lambda args: exp.SHA2(this=seq_get(args, 0), length=exp.Literal.number(512)),
|
|
243
|
+
"SIMILARITY": exp.AISimilarity.from_arg_list,
|
|
241
244
|
"SPLIT": lambda args: exp.Split(
|
|
242
245
|
# https://cloud.google.com/bigquery/docs/reference/standard-sql/string_functions#split
|
|
243
246
|
this=seq_get(args, 0),
|
|
@@ -126,6 +126,7 @@ AGG_FUNCTIONS = {
|
|
|
126
126
|
"deltaSumTimestamp",
|
|
127
127
|
"groupArray",
|
|
128
128
|
"groupArrayLast",
|
|
129
|
+
"groupConcat",
|
|
129
130
|
"groupUniqArray",
|
|
130
131
|
"groupArrayInsertAt",
|
|
131
132
|
"groupArrayMovingAvg",
|
|
@@ -362,6 +363,7 @@ class ClickHouseParser(parser.Parser):
|
|
|
362
363
|
FUNCTION_PARSERS = {
|
|
363
364
|
**{k: v for k, v in parser.Parser.FUNCTION_PARSERS.items() if k != "MATCH"},
|
|
364
365
|
"ARRAYJOIN": lambda self: self.expression(exp.Explode(this=self._parse_expression())),
|
|
366
|
+
"GROUPCONCAT": lambda self: self._parse_group_concat(),
|
|
365
367
|
"QUANTILE": lambda self: self._parse_quantile(),
|
|
366
368
|
"MEDIAN": lambda self: self._parse_quantile(),
|
|
367
369
|
"COLUMNS": lambda self: self._parse_columns(),
|
|
@@ -729,6 +731,22 @@ class ClickHouseParser(parser.Parser):
|
|
|
729
731
|
|
|
730
732
|
return None
|
|
731
733
|
|
|
734
|
+
def _parse_group_concat(self) -> exp.GroupConcat:
|
|
735
|
+
args = self._parse_csv(self._parse_lambda)
|
|
736
|
+
params = self._parse_func_params()
|
|
737
|
+
|
|
738
|
+
if params:
|
|
739
|
+
# groupConcat(sep [, limit])(expr)
|
|
740
|
+
separator = seq_get(args, 0)
|
|
741
|
+
limit = seq_get(args, 1)
|
|
742
|
+
this: exp.Expr | None = seq_get(params, 0)
|
|
743
|
+
if limit is not None:
|
|
744
|
+
this = exp.Limit(this=this, expression=limit)
|
|
745
|
+
return self.expression(exp.GroupConcat(this=this, separator=separator))
|
|
746
|
+
|
|
747
|
+
# groupConcat(expr)
|
|
748
|
+
return self.expression(exp.GroupConcat(this=seq_get(args, 0)))
|
|
749
|
+
|
|
732
750
|
def _parse_quantile(self) -> exp.Quantile:
|
|
733
751
|
this = self._parse_lambda()
|
|
734
752
|
params = self._parse_func_params()
|
|
@@ -2,6 +2,7 @@ from __future__ import annotations
|
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
from sqlglot import exp
|
|
5
|
+
from sqlglot.dialects.dialect import build_date_delta_with_interval
|
|
5
6
|
from sqlglot.helper import seq_get
|
|
6
7
|
from sqlglot.parsers.mysql import MySQLParser
|
|
7
8
|
from sqlglot.tokens import TokenType
|
|
@@ -26,11 +27,15 @@ def _build_date_trunc(args: list[exp.Expr]) -> exp.Expr:
|
|
|
26
27
|
class DorisParser(MySQLParser):
|
|
27
28
|
FUNCTIONS = {
|
|
28
29
|
**MySQLParser.FUNCTIONS,
|
|
30
|
+
"ADDDATE": build_date_delta_with_interval(exp.DateAdd, default_unit="DAY"),
|
|
29
31
|
"COLLECT_SET": exp.ArrayUniqueAgg.from_arg_list,
|
|
32
|
+
"DATE_ADD": build_date_delta_with_interval(exp.DateAdd, default_unit="DAY"),
|
|
33
|
+
"DATE_SUB": build_date_delta_with_interval(exp.DateSub, default_unit="DAY"),
|
|
30
34
|
"DATE_TRUNC": _build_date_trunc,
|
|
31
35
|
"L2_DISTANCE": exp.EuclideanDistance.from_arg_list,
|
|
32
36
|
"MONTHS_ADD": exp.AddMonths.from_arg_list,
|
|
33
37
|
"REGEXP": exp.RegexpLike.from_arg_list,
|
|
38
|
+
"SUBDATE": build_date_delta_with_interval(exp.DateSub, default_unit="DAY"),
|
|
34
39
|
"TO_DATE": exp.TsOrDsToDate.from_arg_list,
|
|
35
40
|
}
|
|
36
41
|
|
|
@@ -130,6 +130,7 @@ class DuckDBParser(parser.Parser):
|
|
|
130
130
|
),
|
|
131
131
|
"JARO_WINKLER_SIMILARITY": exp.JarowinklerSimilarity.from_arg_list,
|
|
132
132
|
"JSON": exp.ParseJSON.from_arg_list,
|
|
133
|
+
"JSON_ARRAY": lambda args: exp.JSONArray(expressions=args),
|
|
133
134
|
"JSON_EXTRACT_PATH": parser.build_extract_json_with_path(exp.JSONExtract),
|
|
134
135
|
"JSON_EXTRACT_STRING": parser.build_extract_json_with_path(exp.JSONExtractScalar),
|
|
135
136
|
"LIST_APPEND": exp.ArrayAppend.from_arg_list,
|
|
@@ -247,11 +247,13 @@ class MySQLParser(parser.Parser):
|
|
|
247
247
|
"KEY": lambda self: self._parse_index_constraint(),
|
|
248
248
|
"SPATIAL": lambda self: self._parse_index_constraint(kind="SPATIAL"),
|
|
249
249
|
"ZEROFILL": lambda self: self.expression(exp.ZeroFillColumnConstraint()),
|
|
250
|
+
"INVISIBLE": lambda self: self.expression(exp.InvisibleColumnConstraint()),
|
|
250
251
|
}
|
|
251
252
|
|
|
252
253
|
ALTER_PARSERS = {
|
|
253
254
|
**parser.Parser.ALTER_PARSERS,
|
|
254
255
|
"MODIFY": lambda self: self._parse_alter_table_alter(),
|
|
256
|
+
"AUTO_INCREMENT": lambda self: self._parse_property_assignment(exp.AutoIncrementProperty),
|
|
255
257
|
}
|
|
256
258
|
|
|
257
259
|
ALTER_ALTER_PARSERS = {
|
|
@@ -300,6 +302,14 @@ class MySQLParser(parser.Parser):
|
|
|
300
302
|
VALUES_FOLLOWED_BY_PAREN = False
|
|
301
303
|
SUPPORTS_PARTITION_SELECTION = True
|
|
302
304
|
|
|
305
|
+
def _parse_alter_table_rename(self):
|
|
306
|
+
if self._match_texts(("INDEX", "KEY")):
|
|
307
|
+
old = self._parse_field(any_token=True)
|
|
308
|
+
self._match_text_seq("TO")
|
|
309
|
+
new = self._parse_field(any_token=True)
|
|
310
|
+
return self.expression(exp.RenameIndex(this=old, to=new))
|
|
311
|
+
return super()._parse_alter_table_rename()
|
|
312
|
+
|
|
303
313
|
def _parse_generated_as_identity(
|
|
304
314
|
self,
|
|
305
315
|
) -> (
|
|
@@ -539,6 +539,7 @@ class SnowflakeParser(parser.Parser):
|
|
|
539
539
|
this=seq_get(args, 0),
|
|
540
540
|
expression=seq_get(args, 1),
|
|
541
541
|
case_insensitive=True,
|
|
542
|
+
integer_scale=True,
|
|
542
543
|
),
|
|
543
544
|
"MD5_HEX": exp.MD5.from_arg_list,
|
|
544
545
|
"MD5_BINARY": exp.MD5Digest.from_arg_list,
|
|
@@ -726,6 +727,7 @@ class SnowflakeParser(parser.Parser):
|
|
|
726
727
|
"OBJECT_CONSTRUCT_KEEP_NULL": lambda self: self._parse_json_object(),
|
|
727
728
|
"LISTAGG": lambda self: self._parse_string_agg(),
|
|
728
729
|
"SEMANTIC_VIEW": lambda self: self._parse_semantic_view(),
|
|
730
|
+
"SUBSTR": lambda self: self._parse_substring(),
|
|
729
731
|
}
|
|
730
732
|
FUNCTION_PARSERS = {k: v for k, v in FUNCTION_PARSERS.items() if k != "TRIM"}
|
|
731
733
|
|
|
@@ -978,15 +980,21 @@ class SnowflakeParser(parser.Parser):
|
|
|
978
980
|
return super()._parse_with_property()
|
|
979
981
|
|
|
980
982
|
def _parse_row_access_policy(self) -> exp.RowAccessProperty:
|
|
981
|
-
policy
|
|
982
|
-
if
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
)
|
|
989
|
-
|
|
983
|
+
# GET_DDL outputs #unknown_policy when the user lacks privileges to see the policy name
|
|
984
|
+
if self._match(TokenType.HASH):
|
|
985
|
+
policy: exp.Expr | None = self._parse_var(any_token=True)
|
|
986
|
+
if policy:
|
|
987
|
+
policy = exp.Var(this=f"#{policy.name}")
|
|
988
|
+
expressions = None
|
|
989
|
+
else:
|
|
990
|
+
policy = self._parse_column()
|
|
991
|
+
if isinstance(policy, exp.Column):
|
|
992
|
+
policy = policy.to_dot()
|
|
993
|
+
if not self._match(TokenType.ON):
|
|
994
|
+
self.raise_error("Expected ON after ROW ACCESS POLICY name")
|
|
995
|
+
expressions = self._parse_wrapped_csv(self._parse_id_var)
|
|
996
|
+
|
|
997
|
+
return self.expression(exp.RowAccessProperty(this=policy, expressions=expressions))
|
|
990
998
|
|
|
991
999
|
def _parse_create(self) -> exp.Create | exp.Command:
|
|
992
1000
|
expression = super()._parse_create()
|
|
@@ -1284,6 +1292,11 @@ class SnowflakeParser(parser.Parser):
|
|
|
1284
1292
|
result.set("clamp_position", True)
|
|
1285
1293
|
return result
|
|
1286
1294
|
|
|
1295
|
+
def _parse_substring(self) -> exp.Substring:
|
|
1296
|
+
result = super()._parse_substring()
|
|
1297
|
+
result.set("zero_start", True)
|
|
1298
|
+
return result
|
|
1299
|
+
|
|
1287
1300
|
def _parse_window(self, this: exp.Expr | None, alias: bool = False) -> exp.Expr | None:
|
|
1288
1301
|
if isinstance(this, exp.NthValue):
|
|
1289
1302
|
if self._match_text_seq("FROM"):
|
|
@@ -87,6 +87,7 @@ class SparkParser(Spark2Parser):
|
|
|
87
87
|
"TIMESTAMPADD": _build_dateadd,
|
|
88
88
|
"TIMESTAMPDIFF": build_date_delta(exp.TimestampDiff),
|
|
89
89
|
"TRY_ADD": exp.SafeAdd.from_arg_list,
|
|
90
|
+
"TRY_DIVIDE": exp.SafeDivide.from_arg_list,
|
|
90
91
|
"TRY_MULTIPLY": exp.SafeMultiply.from_arg_list,
|
|
91
92
|
"TRY_SUBTRACT": exp.SafeSubtract.from_arg_list,
|
|
92
93
|
"DATEDIFF": _build_datediff,
|
|
@@ -2,14 +2,23 @@ from __future__ import annotations
|
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
from sqlglot import exp
|
|
5
|
-
from sqlglot.dialects.dialect import build_timestamp_trunc
|
|
5
|
+
from sqlglot.dialects.dialect import build_date_delta_with_interval, build_timestamp_trunc
|
|
6
6
|
from sqlglot.helper import seq_get
|
|
7
7
|
from sqlglot.parsers.mysql import MySQLParser
|
|
8
|
+
from sqlglot.tokens import TokenType
|
|
8
9
|
|
|
9
10
|
|
|
10
11
|
class StarRocksParser(MySQLParser):
|
|
12
|
+
# StarRocks supports LEFT SEMI JOIN and LEFT ANTI JOIN natively
|
|
13
|
+
# https://docs.starrocks.io/docs/sql-reference/sql-statements/table_bucket_part_index/SELECT/SELECT_JOIN/
|
|
14
|
+
TABLE_ALIAS_TOKENS = MySQLParser.TABLE_ALIAS_TOKENS - {TokenType.ANTI, TokenType.SEMI}
|
|
15
|
+
|
|
11
16
|
FUNCTIONS = {
|
|
12
17
|
**MySQLParser.FUNCTIONS,
|
|
18
|
+
"ADDDATE": build_date_delta_with_interval(exp.DateAdd, default_unit="DAY"),
|
|
19
|
+
"DATE_ADD": build_date_delta_with_interval(exp.DateAdd, default_unit="DAY"),
|
|
20
|
+
"DATE_SUB": build_date_delta_with_interval(exp.DateSub, default_unit="DAY"),
|
|
21
|
+
"SUBDATE": build_date_delta_with_interval(exp.DateSub, default_unit="DAY"),
|
|
13
22
|
"DATE_TRUNC": build_timestamp_trunc,
|
|
14
23
|
"DATEDIFF": lambda args: exp.DateDiff(
|
|
15
24
|
this=seq_get(args, 0), expression=seq_get(args, 1), unit=exp.Literal.string("DAY")
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|