sqlglotc 30.27.0__tar.gz → 30.29.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.29.0}/PKG-INFO +2 -2
- {sqlglotc-30.27.0 → sqlglotc-30.29.0}/setup.py +5 -1
- {sqlglotc-30.27.0 → sqlglotc-30.29.0}/sqlglot/expressions/builders.py +8 -1
- {sqlglotc-30.27.0 → sqlglotc-30.29.0}/sqlglot/expressions/core.py +4 -1
- {sqlglotc-30.27.0 → sqlglotc-30.29.0}/sqlglot/expressions/properties.py +5 -1
- {sqlglotc-30.27.0 → sqlglotc-30.29.0}/sqlglot/expressions/query.py +1 -0
- {sqlglotc-30.27.0 → sqlglotc-30.29.0}/sqlglot/expressions/temporal.py +8 -1
- {sqlglotc-30.27.0 → sqlglotc-30.29.0}/sqlglot/generator.py +11 -3
- {sqlglotc-30.27.0 → sqlglotc-30.29.0}/sqlglot/generators/bigquery.py +42 -0
- {sqlglotc-30.27.0 → sqlglotc-30.29.0}/sqlglot/generators/duckdb.py +13 -8
- {sqlglotc-30.27.0 → sqlglotc-30.29.0}/sqlglot/generators/oracle.py +6 -2
- {sqlglotc-30.27.0 → sqlglotc-30.29.0}/sqlglot/generators/snowflake.py +5 -0
- {sqlglotc-30.27.0 → sqlglotc-30.29.0}/sqlglot/generators/sqlite.py +6 -0
- {sqlglotc-30.27.0 → sqlglotc-30.29.0}/sqlglot/parser.py +2 -1
- {sqlglotc-30.27.0 → sqlglotc-30.29.0}/sqlglot/parsers/oracle.py +11 -2
- {sqlglotc-30.27.0 → sqlglotc-30.29.0}/sqlglot/parsers/snowflake.py +5 -0
- {sqlglotc-30.27.0 → sqlglotc-30.29.0}/sqlglot/parsers/sqlite.py +33 -0
- {sqlglotc-30.27.0 → sqlglotc-30.29.0/sqlglotc.egg-info}/PKG-INFO +2 -2
- {sqlglotc-30.27.0 → sqlglotc-30.29.0}/sqlglotc.egg-info/requires.txt +1 -1
- sqlglotc-30.29.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.29.0}/MANIFEST.in +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.29.0}/pyproject.toml +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.29.0}/setup.cfg +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.29.0}/sqlglot/anonymize.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.29.0}/sqlglot/errors.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.29.0}/sqlglot/executor/table.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.29.0}/sqlglot/expressions/aggregate.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.29.0}/sqlglot/expressions/array.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.29.0}/sqlglot/expressions/constraints.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.29.0}/sqlglot/expressions/datatypes.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.29.0}/sqlglot/expressions/ddl.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.29.0}/sqlglot/expressions/dml.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.29.0}/sqlglot/expressions/functions.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.29.0}/sqlglot/expressions/json.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.29.0}/sqlglot/expressions/math.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.29.0}/sqlglot/expressions/string.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.29.0}/sqlglot/generators/athena.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.29.0}/sqlglot/generators/clickhouse.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.29.0}/sqlglot/generators/databricks.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.29.0}/sqlglot/generators/dax.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.29.0}/sqlglot/generators/doris.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.29.0}/sqlglot/generators/dremio.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.29.0}/sqlglot/generators/drill.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.29.0}/sqlglot/generators/druid.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.29.0}/sqlglot/generators/dune.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.29.0}/sqlglot/generators/exasol.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.29.0}/sqlglot/generators/fabric.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.29.0}/sqlglot/generators/hive.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.29.0}/sqlglot/generators/materialize.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.29.0}/sqlglot/generators/mysql.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.29.0}/sqlglot/generators/postgres.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.29.0}/sqlglot/generators/presto.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.29.0}/sqlglot/generators/prql.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.29.0}/sqlglot/generators/python.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.29.0}/sqlglot/generators/redshift.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.29.0}/sqlglot/generators/risingwave.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.29.0}/sqlglot/generators/singlestore.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.29.0}/sqlglot/generators/solr.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.29.0}/sqlglot/generators/spark.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.29.0}/sqlglot/generators/spark2.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.29.0}/sqlglot/generators/starrocks.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.29.0}/sqlglot/generators/tableau.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.29.0}/sqlglot/generators/teradata.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.29.0}/sqlglot/generators/trino.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.29.0}/sqlglot/generators/tsql.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.29.0}/sqlglot/helper.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.29.0}/sqlglot/lineage.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.29.0}/sqlglot/optimizer/annotate_types.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.29.0}/sqlglot/optimizer/canonicalize_internal_names.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.29.0}/sqlglot/optimizer/isolate_table_selects.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.29.0}/sqlglot/optimizer/normalize_identifiers.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.29.0}/sqlglot/optimizer/qualify.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.29.0}/sqlglot/optimizer/qualify_columns.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.29.0}/sqlglot/optimizer/qualify_tables.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.29.0}/sqlglot/optimizer/resolver.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.29.0}/sqlglot/optimizer/scope.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.29.0}/sqlglot/optimizer/simplify.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.29.0}/sqlglot/parsers/athena.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.29.0}/sqlglot/parsers/base.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.29.0}/sqlglot/parsers/bigquery.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.29.0}/sqlglot/parsers/clickhouse.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.29.0}/sqlglot/parsers/databricks.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.29.0}/sqlglot/parsers/dax.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.29.0}/sqlglot/parsers/doris.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.29.0}/sqlglot/parsers/dremio.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.29.0}/sqlglot/parsers/drill.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.29.0}/sqlglot/parsers/druid.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.29.0}/sqlglot/parsers/duckdb.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.29.0}/sqlglot/parsers/dune.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.29.0}/sqlglot/parsers/exasol.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.29.0}/sqlglot/parsers/fabric.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.29.0}/sqlglot/parsers/hive.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.29.0}/sqlglot/parsers/materialize.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.29.0}/sqlglot/parsers/mysql.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.29.0}/sqlglot/parsers/postgres.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.29.0}/sqlglot/parsers/presto.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.29.0}/sqlglot/parsers/prql.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.29.0}/sqlglot/parsers/redshift.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.29.0}/sqlglot/parsers/risingwave.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.29.0}/sqlglot/parsers/singlestore.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.29.0}/sqlglot/parsers/solr.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.29.0}/sqlglot/parsers/spark.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.29.0}/sqlglot/parsers/spark2.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.29.0}/sqlglot/parsers/starrocks.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.29.0}/sqlglot/parsers/tableau.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.29.0}/sqlglot/parsers/teradata.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.29.0}/sqlglot/parsers/trino.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.29.0}/sqlglot/parsers/tsql.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.29.0}/sqlglot/serde.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.29.0}/sqlglot/time.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.29.0}/sqlglot/tokenizer_core.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.29.0}/sqlglot/trie.py +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.29.0}/sqlglotc.egg-info/SOURCES.txt +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.29.0}/sqlglotc.egg-info/dependency_links.txt +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.29.0}/sqlglotc.egg-info/scm_file_list.json +0 -0
- {sqlglotc-30.27.0 → sqlglotc-30.29.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.29.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.29.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
|
)
|
|
@@ -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:
|
|
@@ -222,6 +222,10 @@ class OutputModelProperty(Property):
|
|
|
222
222
|
arg_types = {"this": True}
|
|
223
223
|
|
|
224
224
|
|
|
225
|
+
class InteractiveProperty(Property):
|
|
226
|
+
arg_types = {}
|
|
227
|
+
|
|
228
|
+
|
|
225
229
|
class IsolatedLoadingProperty(Property):
|
|
226
230
|
arg_types = {"no": False, "concurrent": False, "target": False}
|
|
227
231
|
|
|
@@ -520,7 +524,7 @@ class UsingProperty(Property):
|
|
|
520
524
|
|
|
521
525
|
|
|
522
526
|
class TemporaryProperty(Property):
|
|
523
|
-
arg_types = {"this": False}
|
|
527
|
+
arg_types = {"this": False, "scoped": False}
|
|
524
528
|
|
|
525
529
|
|
|
526
530
|
class VirtualProperty(Property):
|
|
@@ -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
|
|
|
@@ -765,6 +765,7 @@ class Generator:
|
|
|
765
765
|
exp.IcebergProperty: exp.Properties.Location.POST_CREATE,
|
|
766
766
|
exp.IncludeProperty: exp.Properties.Location.POST_SCHEMA,
|
|
767
767
|
exp.InputModelProperty: exp.Properties.Location.POST_SCHEMA,
|
|
768
|
+
exp.InteractiveProperty: exp.Properties.Location.UNSUPPORTED,
|
|
768
769
|
exp.IsolatedLoadingProperty: exp.Properties.Location.POST_NAME,
|
|
769
770
|
exp.JournalProperty: exp.Properties.Location.POST_NAME,
|
|
770
771
|
exp.LanguageProperty: exp.Properties.Location.POST_SCHEMA,
|
|
@@ -2862,7 +2863,8 @@ class Generator:
|
|
|
2862
2863
|
else values
|
|
2863
2864
|
)
|
|
2864
2865
|
values = self.query_modifiers(expression, values)
|
|
2865
|
-
|
|
2866
|
+
pivots = self.expressions(expression, key="pivots", sep="", flat=True)
|
|
2867
|
+
return f"{values} AS {alias}{pivots}" if alias else f"{values}{pivots}"
|
|
2866
2868
|
|
|
2867
2869
|
# Converts `VALUES...` expression into a series of select unions.
|
|
2868
2870
|
alias_node = expression.args.get("alias")
|
|
@@ -2885,11 +2887,17 @@ class Generator:
|
|
|
2885
2887
|
# the deep nesting of the resulting exp.Unions. If this is a problem, either increase
|
|
2886
2888
|
# `sys.setrecursionlimit` to avoid RecursionErrors, or don't set `pretty`.
|
|
2887
2889
|
query = reduce(lambda x, y: exp.union(x, y, distinct=False, copy=False), selects)
|
|
2888
|
-
|
|
2890
|
+
for key in ("order", "limit", "offset"):
|
|
2891
|
+
if value := expression.args.get(key):
|
|
2892
|
+
query.set(key, value.pop())
|
|
2893
|
+
subquery = query.subquery(alias_node and alias_node.this, copy=False)
|
|
2894
|
+
subquery.set("pivots", expression.args.pop("pivots", None))
|
|
2895
|
+
return self.subquery_sql(subquery)
|
|
2889
2896
|
|
|
2890
2897
|
alias = f" AS {self.sql(alias_node, 'this')}" if alias_node else ""
|
|
2891
2898
|
unions = " UNION ALL ".join(self.sql(select) for select in selects)
|
|
2892
|
-
|
|
2899
|
+
pivots = self.expressions(expression, key="pivots", sep="", flat=True)
|
|
2900
|
+
return f"({self.query_modifiers(expression, unions)}){alias}{pivots}"
|
|
2893
2901
|
|
|
2894
2902
|
def var_sql(self, expression: exp.Var) -> str:
|
|
2895
2903
|
return self.sql(expression, "this")
|
|
@@ -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":
|
|
@@ -111,7 +111,7 @@ def _apply_base64_alphabet_replacements(
|
|
|
111
111
|
reverse: bool = False,
|
|
112
112
|
) -> exp.Expr:
|
|
113
113
|
"""
|
|
114
|
-
|
|
114
|
+
Translate base64 alphabet characters without cascading replacements.
|
|
115
115
|
|
|
116
116
|
Base64 alphabet can be 1-3 chars: 1st = index 62 ('+'), 2nd = index 63 ('/'), 3rd = padding ('=').
|
|
117
117
|
zip truncates to the shorter string, so 1-char alphabet only replaces '+', 2-char replaces '+/', etc.
|
|
@@ -123,14 +123,19 @@ def _apply_base64_alphabet_replacements(
|
|
|
123
123
|
If True, replace custom with default (decode)
|
|
124
124
|
"""
|
|
125
125
|
if isinstance(alphabet, exp.Literal) and alphabet.is_string:
|
|
126
|
+
source, target = "", ""
|
|
126
127
|
for default_char, new_char in zip("+/=", alphabet.this):
|
|
127
128
|
if new_char != default_char:
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
129
|
+
source += default_char
|
|
130
|
+
target += new_char
|
|
131
|
+
if source:
|
|
132
|
+
if reverse:
|
|
133
|
+
source, target = target, source
|
|
134
|
+
result = exp.Translate(
|
|
135
|
+
this=result,
|
|
136
|
+
from_=exp.Literal.string(source),
|
|
137
|
+
to=exp.Literal.string(target),
|
|
138
|
+
)
|
|
134
139
|
return result
|
|
135
140
|
|
|
136
141
|
|
|
@@ -139,7 +144,7 @@ def _base64_decode_sql(self: DuckDBGenerator, expression: exp.Expr, to_string: b
|
|
|
139
144
|
Transpile Snowflake BASE64_DECODE_STRING/BINARY to DuckDB.
|
|
140
145
|
|
|
141
146
|
DuckDB uses FROM_BASE64() which returns BLOB. For string output, wrap with DECODE().
|
|
142
|
-
Custom alphabets require
|
|
147
|
+
Custom alphabets require TRANSLATE() to convert to standard base64.
|
|
143
148
|
"""
|
|
144
149
|
input_expr = expression.this
|
|
145
150
|
alphabet = expression.args.get("alphabet")
|
|
@@ -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,
|
|
@@ -128,6 +128,12 @@ class SQLiteGenerator(generator.Generator):
|
|
|
128
128
|
exp.DType.VARBINARY: "BLOB",
|
|
129
129
|
}
|
|
130
130
|
|
|
131
|
+
def nullsafeeq_sql(self, expression: exp.NullSafeEQ) -> str:
|
|
132
|
+
return self.binary(expression, "IS")
|
|
133
|
+
|
|
134
|
+
def nullsafeneq_sql(self, expression: exp.NullSafeNEQ) -> str:
|
|
135
|
+
return self.binary(expression, "IS NOT")
|
|
136
|
+
|
|
131
137
|
TOKEN_MAPPING = {
|
|
132
138
|
TokenType.AUTO_INCREMENT: "AUTOINCREMENT",
|
|
133
139
|
}
|
|
@@ -3637,7 +3637,7 @@ class Parser:
|
|
|
3637
3637
|
style: str | None = (
|
|
3638
3638
|
self._prev.text.upper() if self._match_texts(self.DESCRIBE_STYLES) else None
|
|
3639
3639
|
)
|
|
3640
|
-
if self._match(TokenType.DOT):
|
|
3640
|
+
if (kind is not None or style is not None) and self._match(TokenType.DOT):
|
|
3641
3641
|
style = None
|
|
3642
3642
|
self._retreat(self._index - 2)
|
|
3643
3643
|
|
|
@@ -5211,6 +5211,7 @@ class Parser:
|
|
|
5211
5211
|
return unnest
|
|
5212
5212
|
|
|
5213
5213
|
if values := self._parse_derived_table_values():
|
|
5214
|
+
values.set("pivots", self._parse_pivots())
|
|
5214
5215
|
return values
|
|
5215
5216
|
|
|
5216
5217
|
if subquery := self._parse_select(table=True, consume_pipe=consume_pipe):
|
|
@@ -13,11 +13,20 @@ if t.TYPE_CHECKING:
|
|
|
13
13
|
from sqlglot.dialects.dialect import Dialect
|
|
14
14
|
|
|
15
15
|
|
|
16
|
+
def _build_str_to_time(exp_class: type[E]) -> t.Callable[[list, Dialect], E]:
|
|
17
|
+
def _builder(args: list, dialect: Dialect) -> E:
|
|
18
|
+
expression = build_formatted_time(exp_class)(args, dialect)
|
|
19
|
+
expression.set("nlsparam", seq_get(args, 2))
|
|
20
|
+
return expression
|
|
21
|
+
|
|
22
|
+
return _builder
|
|
23
|
+
|
|
24
|
+
|
|
16
25
|
def _build_to_timestamp(args: list, dialect: Dialect) -> exp.StrToTime | exp.Anonymous:
|
|
17
26
|
if len(args) == 1:
|
|
18
27
|
return exp.Anonymous(this="TO_TIMESTAMP", expressions=args)
|
|
19
28
|
|
|
20
|
-
return
|
|
29
|
+
return _build_str_to_time(exp.StrToTime)(args, dialect)
|
|
21
30
|
|
|
22
31
|
|
|
23
32
|
class OracleParser(parser.Parser):
|
|
@@ -59,7 +68,7 @@ class OracleParser(parser.Parser):
|
|
|
59
68
|
"SQUARE": lambda args: exp.Pow(this=seq_get(args, 0), expression=exp.Literal.number(2)),
|
|
60
69
|
"TO_CHAR": build_timetostr_or_tochar,
|
|
61
70
|
"TO_TIMESTAMP": _build_to_timestamp,
|
|
62
|
-
"TO_DATE":
|
|
71
|
+
"TO_DATE": _build_str_to_time(exp.StrToDate),
|
|
63
72
|
"TRUNC": lambda args, dialect: build_trunc(
|
|
64
73
|
args, dialect, date_trunc_unabbreviate=False, default_date_trunc_unit="DD"
|
|
65
74
|
),
|
|
@@ -785,12 +785,17 @@ class SnowflakeParser(parser.Parser):
|
|
|
785
785
|
**parser.Parser.PROPERTY_PARSERS,
|
|
786
786
|
"CREDENTIALS": lambda self: self._parse_credentials_property(),
|
|
787
787
|
"FILE_FORMAT": lambda self: self._parse_file_format_property(),
|
|
788
|
+
"INTERACTIVE": lambda self: self.expression(exp.InteractiveProperty()),
|
|
788
789
|
"LOCATION": lambda self: self._parse_location_property(),
|
|
789
790
|
"ROW": lambda self: (
|
|
790
791
|
self._parse_row_access_policy()
|
|
791
792
|
if self._match_text_seq("ACCESS", "POLICY")
|
|
792
793
|
else self._parse_row()
|
|
793
794
|
),
|
|
795
|
+
"SCOPED": lambda self: (
|
|
796
|
+
self._match_texts(("TEMP", "TEMPORARY"))
|
|
797
|
+
and self.expression(exp.TemporaryProperty(scoped=True))
|
|
798
|
+
),
|
|
794
799
|
"TAG": lambda self: self._parse_tag(),
|
|
795
800
|
"USING": lambda self: (
|
|
796
801
|
self._match_text_seq("TEMPLATE")
|
|
@@ -7,6 +7,12 @@ from sqlglot.parser import IsPredicatePrecedence, binary_range_parser
|
|
|
7
7
|
from sqlglot.tokens import Token, TokenType
|
|
8
8
|
|
|
9
9
|
|
|
10
|
+
def _build_date(args: list) -> exp.Date | exp.Anonymous:
|
|
11
|
+
if len(args) <= 1:
|
|
12
|
+
return exp.Date.from_arg_list(args)
|
|
13
|
+
return exp.Anonymous(this="DATE", expressions=args)
|
|
14
|
+
|
|
15
|
+
|
|
10
16
|
def _build_strftime(args: list) -> exp.Anonymous | exp.TimeToStr:
|
|
11
17
|
if len(args) == 1:
|
|
12
18
|
args.append(exp.CurrentTimestamp())
|
|
@@ -89,6 +95,7 @@ class SQLiteParser(parser.Parser):
|
|
|
89
95
|
|
|
90
96
|
FUNCTIONS = {
|
|
91
97
|
**parser.Parser.FUNCTIONS,
|
|
98
|
+
"DATE": _build_date,
|
|
92
99
|
"DATETIME": lambda args: exp.Anonymous(this="DATETIME", expressions=args),
|
|
93
100
|
"EDITDIST3": exp.Levenshtein.from_arg_list,
|
|
94
101
|
"JSON_EXTRACT": _build_json_extract,
|
|
@@ -125,6 +132,32 @@ class SQLiteParser(parser.Parser):
|
|
|
125
132
|
TokenType.MATCH: binary_range_parser(exp.Match),
|
|
126
133
|
}
|
|
127
134
|
|
|
135
|
+
def _parse_is(self, this: exp.Expr | None) -> exp.Expr | None:
|
|
136
|
+
"""SQLite's IS / IS NOT is a null-safe equality against any expression.
|
|
137
|
+
|
|
138
|
+
Other dialects only accept NULL, TRUE, FALSE or UNKNOWN on the right
|
|
139
|
+
side, so anything else is parsed as IS [NOT] DISTINCT FROM; each
|
|
140
|
+
transpiler then emits the syntax it supports (SQLite keeps IS / IS
|
|
141
|
+
NOT) (#8855).
|
|
142
|
+
"""
|
|
143
|
+
this = super()._parse_is(this)
|
|
144
|
+
|
|
145
|
+
is_node = this
|
|
146
|
+
wrapped_in_not = False
|
|
147
|
+
if isinstance(this, exp.Not) and isinstance(this.this, exp.Is):
|
|
148
|
+
is_node = this.this
|
|
149
|
+
wrapped_in_not = True
|
|
150
|
+
|
|
151
|
+
if isinstance(is_node, exp.Is):
|
|
152
|
+
rhs = is_node.expression.unnest()
|
|
153
|
+
if isinstance(rhs, (exp.Null, exp.Boolean)):
|
|
154
|
+
is_node.set("expression", rhs)
|
|
155
|
+
else:
|
|
156
|
+
cls = exp.NullSafeNEQ if wrapped_in_not else exp.NullSafeEQ
|
|
157
|
+
this = cls(this=is_node.this, expression=is_node.expression)
|
|
158
|
+
|
|
159
|
+
return this
|
|
160
|
+
|
|
128
161
|
def _parse_is_rhs(self, distinct: bool = False) -> exp.Expr | None:
|
|
129
162
|
# Ordering comparisons bind above IS, but range predicates bind below it.
|
|
130
163
|
this = self._parse_bitwise()
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: sqlglotc
|
|
3
|
-
Version: 30.
|
|
3
|
+
Version: 30.29.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.29.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"
|
|
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
|
|
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
|