sqlglotc 30.30.0__tar.gz → 30.31.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {sqlglotc-30.30.0/sqlglotc.egg-info → sqlglotc-30.31.0}/PKG-INFO +2 -2
- {sqlglotc-30.30.0 → sqlglotc-30.31.0}/sqlglot/expressions/core.py +23 -1
- {sqlglotc-30.30.0 → sqlglotc-30.31.0}/sqlglot/expressions/properties.py +4 -0
- {sqlglotc-30.30.0 → sqlglotc-30.31.0}/sqlglot/generator.py +28 -9
- {sqlglotc-30.30.0 → sqlglotc-30.31.0}/sqlglot/generators/bigquery.py +1 -0
- {sqlglotc-30.30.0 → sqlglotc-30.31.0}/sqlglot/generators/clickhouse.py +13 -0
- {sqlglotc-30.30.0 → sqlglotc-30.31.0}/sqlglot/generators/druid.py +2 -2
- {sqlglotc-30.30.0 → sqlglotc-30.31.0}/sqlglot/generators/duckdb.py +6 -4
- {sqlglotc-30.30.0 → sqlglotc-30.31.0}/sqlglot/generators/exasol.py +2 -1
- {sqlglotc-30.30.0 → sqlglotc-30.31.0}/sqlglot/generators/oracle.py +2 -1
- {sqlglotc-30.30.0 → sqlglotc-30.31.0}/sqlglot/generators/postgres.py +7 -1
- {sqlglotc-30.30.0 → sqlglotc-30.31.0}/sqlglot/generators/redshift.py +7 -0
- {sqlglotc-30.30.0 → sqlglotc-30.31.0}/sqlglot/generators/spark2.py +1 -1
- {sqlglotc-30.30.0 → sqlglotc-30.31.0}/sqlglot/generators/sqlite.py +29 -0
- {sqlglotc-30.30.0 → sqlglotc-30.31.0}/sqlglot/generators/teradata.py +10 -0
- {sqlglotc-30.30.0 → sqlglotc-30.31.0}/sqlglot/optimizer/qualify_columns.py +83 -15
- {sqlglotc-30.30.0 → sqlglotc-30.31.0}/sqlglot/optimizer/resolver.py +46 -10
- {sqlglotc-30.30.0 → sqlglotc-30.31.0}/sqlglot/optimizer/simplify.py +15 -2
- {sqlglotc-30.30.0 → sqlglotc-30.31.0}/sqlglot/parser.py +37 -23
- {sqlglotc-30.30.0 → sqlglotc-30.31.0}/sqlglot/parsers/presto.py +8 -1
- {sqlglotc-30.30.0 → sqlglotc-30.31.0}/sqlglot/parsers/spark.py +5 -0
- {sqlglotc-30.30.0 → sqlglotc-30.31.0}/sqlglot/parsers/sqlite.py +8 -0
- {sqlglotc-30.30.0 → sqlglotc-30.31.0}/sqlglot/parsers/teradata.py +56 -12
- {sqlglotc-30.30.0 → sqlglotc-30.31.0/sqlglotc.egg-info}/PKG-INFO +2 -2
- {sqlglotc-30.30.0 → sqlglotc-30.31.0}/sqlglotc.egg-info/requires.txt +1 -1
- sqlglotc-30.31.0/sqlglotc.egg-info/scm_version.json +8 -0
- sqlglotc-30.30.0/sqlglotc.egg-info/scm_version.json +0 -8
- {sqlglotc-30.30.0 → sqlglotc-30.31.0}/MANIFEST.in +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.31.0}/pyproject.toml +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.31.0}/setup.cfg +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.31.0}/setup.py +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.31.0}/sqlglot/anonymize.py +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.31.0}/sqlglot/errors.py +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.31.0}/sqlglot/executor/table.py +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.31.0}/sqlglot/expressions/aggregate.py +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.31.0}/sqlglot/expressions/array.py +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.31.0}/sqlglot/expressions/builders.py +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.31.0}/sqlglot/expressions/constraints.py +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.31.0}/sqlglot/expressions/datatypes.py +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.31.0}/sqlglot/expressions/ddl.py +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.31.0}/sqlglot/expressions/dml.py +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.31.0}/sqlglot/expressions/functions.py +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.31.0}/sqlglot/expressions/json.py +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.31.0}/sqlglot/expressions/math.py +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.31.0}/sqlglot/expressions/query.py +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.31.0}/sqlglot/expressions/string.py +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.31.0}/sqlglot/expressions/temporal.py +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.31.0}/sqlglot/generators/athena.py +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.31.0}/sqlglot/generators/databricks.py +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.31.0}/sqlglot/generators/dax.py +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.31.0}/sqlglot/generators/doris.py +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.31.0}/sqlglot/generators/dremio.py +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.31.0}/sqlglot/generators/drill.py +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.31.0}/sqlglot/generators/dune.py +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.31.0}/sqlglot/generators/fabric.py +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.31.0}/sqlglot/generators/hive.py +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.31.0}/sqlglot/generators/materialize.py +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.31.0}/sqlglot/generators/mysql.py +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.31.0}/sqlglot/generators/presto.py +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.31.0}/sqlglot/generators/prql.py +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.31.0}/sqlglot/generators/python.py +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.31.0}/sqlglot/generators/risingwave.py +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.31.0}/sqlglot/generators/singlestore.py +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.31.0}/sqlglot/generators/snowflake.py +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.31.0}/sqlglot/generators/solr.py +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.31.0}/sqlglot/generators/spark.py +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.31.0}/sqlglot/generators/starrocks.py +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.31.0}/sqlglot/generators/tableau.py +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.31.0}/sqlglot/generators/trino.py +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.31.0}/sqlglot/generators/tsql.py +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.31.0}/sqlglot/helper.py +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.31.0}/sqlglot/lineage.py +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.31.0}/sqlglot/optimizer/annotate_types.py +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.31.0}/sqlglot/optimizer/canonicalize_internal_names.py +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.31.0}/sqlglot/optimizer/isolate_table_selects.py +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.31.0}/sqlglot/optimizer/normalize_identifiers.py +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.31.0}/sqlglot/optimizer/qualify.py +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.31.0}/sqlglot/optimizer/qualify_tables.py +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.31.0}/sqlglot/optimizer/scope.py +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.31.0}/sqlglot/parsers/athena.py +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.31.0}/sqlglot/parsers/base.py +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.31.0}/sqlglot/parsers/bigquery.py +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.31.0}/sqlglot/parsers/clickhouse.py +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.31.0}/sqlglot/parsers/databricks.py +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.31.0}/sqlglot/parsers/dax.py +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.31.0}/sqlglot/parsers/doris.py +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.31.0}/sqlglot/parsers/dremio.py +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.31.0}/sqlglot/parsers/drill.py +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.31.0}/sqlglot/parsers/druid.py +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.31.0}/sqlglot/parsers/duckdb.py +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.31.0}/sqlglot/parsers/dune.py +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.31.0}/sqlglot/parsers/exasol.py +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.31.0}/sqlglot/parsers/fabric.py +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.31.0}/sqlglot/parsers/hive.py +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.31.0}/sqlglot/parsers/materialize.py +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.31.0}/sqlglot/parsers/mysql.py +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.31.0}/sqlglot/parsers/oracle.py +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.31.0}/sqlglot/parsers/postgres.py +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.31.0}/sqlglot/parsers/prql.py +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.31.0}/sqlglot/parsers/redshift.py +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.31.0}/sqlglot/parsers/risingwave.py +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.31.0}/sqlglot/parsers/singlestore.py +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.31.0}/sqlglot/parsers/snowflake.py +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.31.0}/sqlglot/parsers/solr.py +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.31.0}/sqlglot/parsers/spark2.py +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.31.0}/sqlglot/parsers/starrocks.py +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.31.0}/sqlglot/parsers/tableau.py +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.31.0}/sqlglot/parsers/trino.py +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.31.0}/sqlglot/parsers/tsql.py +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.31.0}/sqlglot/serde.py +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.31.0}/sqlglot/time.py +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.31.0}/sqlglot/tokenizer_core.py +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.31.0}/sqlglot/trie.py +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.31.0}/sqlglotc.egg-info/SOURCES.txt +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.31.0}/sqlglotc.egg-info/dependency_links.txt +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.31.0}/sqlglotc.egg-info/scm_file_list.json +0 -0
- {sqlglotc-30.30.0 → sqlglotc-30.31.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.31.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.31.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"
|
|
@@ -2240,7 +2240,7 @@ class LTE(Expression, Binary, Predicate):
|
|
|
2240
2240
|
|
|
2241
2241
|
|
|
2242
2242
|
class Mod(Expression, Binary):
|
|
2243
|
-
|
|
2243
|
+
arg_types = {"this": True, "expression": True, "safe": False}
|
|
2244
2244
|
|
|
2245
2245
|
|
|
2246
2246
|
class Mul(Expression, Binary):
|
|
@@ -2317,6 +2317,28 @@ class FormatPhrase(Expression):
|
|
|
2317
2317
|
|
|
2318
2318
|
arg_types = {"this": True, "format": True}
|
|
2319
2319
|
|
|
2320
|
+
@property
|
|
2321
|
+
def name(self) -> str:
|
|
2322
|
+
return self.this.name
|
|
2323
|
+
|
|
2324
|
+
@property
|
|
2325
|
+
def output_name(self) -> str:
|
|
2326
|
+
return self.this.output_name
|
|
2327
|
+
|
|
2328
|
+
|
|
2329
|
+
class TeradataTitle(Expression):
|
|
2330
|
+
"""A Teradata TITLE display heading, which does not rename the expression."""
|
|
2331
|
+
|
|
2332
|
+
arg_types = {"this": True, "title": True}
|
|
2333
|
+
|
|
2334
|
+
@property
|
|
2335
|
+
def name(self) -> str:
|
|
2336
|
+
return self.this.name
|
|
2337
|
+
|
|
2338
|
+
@property
|
|
2339
|
+
def output_name(self) -> str:
|
|
2340
|
+
return self.this.output_name
|
|
2341
|
+
|
|
2320
2342
|
|
|
2321
2343
|
class Between(Expression, Predicate):
|
|
2322
2344
|
arg_types = {"this": True, "low": True, "high": True, "symmetric": False}
|
|
@@ -298,6 +298,7 @@ class Generator:
|
|
|
298
298
|
exp.WithProcedureOptions: lambda self, e: f"WITH {self.expressions(e, flat=True)}",
|
|
299
299
|
exp.WithSchemaBindingProperty: lambda self, e: f"WITH SCHEMA {self.sql(e, 'this')}",
|
|
300
300
|
exp.WithOperator: lambda self, e: f"{self.sql(e, 'this')} WITH {self.sql(e, 'op')}",
|
|
301
|
+
exp.WithoutRowidProperty: lambda *_: "WITHOUT ROWID",
|
|
301
302
|
exp.ForceProperty: lambda *_: "FORCE",
|
|
302
303
|
}
|
|
303
304
|
|
|
@@ -746,8 +747,8 @@ class Generator:
|
|
|
746
747
|
exp.DictRange: exp.Properties.Location.POST_SCHEMA,
|
|
747
748
|
exp.DictProperty: exp.Properties.Location.POST_SCHEMA,
|
|
748
749
|
exp.DynamicProperty: exp.Properties.Location.POST_CREATE,
|
|
749
|
-
exp.DistKeyProperty: exp.Properties.Location.
|
|
750
|
-
exp.DistStyleProperty: exp.Properties.Location.
|
|
750
|
+
exp.DistKeyProperty: exp.Properties.Location.UNSUPPORTED,
|
|
751
|
+
exp.DistStyleProperty: exp.Properties.Location.UNSUPPORTED,
|
|
751
752
|
exp.EmptyProperty: exp.Properties.Location.POST_SCHEMA,
|
|
752
753
|
exp.EncodeProperty: exp.Properties.Location.POST_EXPRESSION,
|
|
753
754
|
exp.EngineProperty: exp.Properties.Location.POST_SCHEMA,
|
|
@@ -812,7 +813,7 @@ class Generator:
|
|
|
812
813
|
exp.SharingProperty: exp.Properties.Location.POST_EXPRESSION,
|
|
813
814
|
exp.SequenceProperties: exp.Properties.Location.POST_EXPRESSION,
|
|
814
815
|
exp.TriggerProperties: exp.Properties.Location.POST_EXPRESSION,
|
|
815
|
-
exp.SortKeyProperty: exp.Properties.Location.
|
|
816
|
+
exp.SortKeyProperty: exp.Properties.Location.UNSUPPORTED,
|
|
816
817
|
exp.SqlReadWriteProperty: exp.Properties.Location.POST_SCHEMA,
|
|
817
818
|
exp.SqlSecurityProperty: exp.Properties.Location.POST_SCHEMA,
|
|
818
819
|
exp.StabilityProperty: exp.Properties.Location.POST_SCHEMA,
|
|
@@ -838,6 +839,7 @@ class Generator:
|
|
|
838
839
|
exp.WithProcedureOptions: exp.Properties.Location.POST_SCHEMA,
|
|
839
840
|
exp.WithSchemaBindingProperty: exp.Properties.Location.POST_SCHEMA,
|
|
840
841
|
exp.WithSystemVersioningProperty: exp.Properties.Location.POST_SCHEMA,
|
|
842
|
+
exp.WithoutRowidProperty: exp.Properties.Location.UNSUPPORTED,
|
|
841
843
|
exp.ForceProperty: exp.Properties.Location.POST_CREATE,
|
|
842
844
|
}
|
|
843
845
|
|
|
@@ -2072,7 +2074,13 @@ class Generator:
|
|
|
2072
2074
|
return f"{this} FILTER({where})"
|
|
2073
2075
|
|
|
2074
2076
|
def per_sql(self, expression: exp.Per) -> str:
|
|
2075
|
-
|
|
2077
|
+
keys = ", ".join(
|
|
2078
|
+
f"{self.sql(key, 'this')} {self.sql(key, 'with_fill')}"
|
|
2079
|
+
if isinstance(key, exp.Ordered) and key.args.get("with_fill")
|
|
2080
|
+
else self.sql(key)
|
|
2081
|
+
for key in expression.expressions
|
|
2082
|
+
)
|
|
2083
|
+
return f"{self.sql(expression, 'this')} PER ({keys})"
|
|
2076
2084
|
|
|
2077
2085
|
def hint_sql(self, expression: exp.Hint) -> str:
|
|
2078
2086
|
if not self.QUERY_HINTS:
|
|
@@ -4047,6 +4055,10 @@ class Generator:
|
|
|
4047
4055
|
fmt = self.sql(expression, "format")
|
|
4048
4056
|
return f"{this} (FORMAT {fmt})"
|
|
4049
4057
|
|
|
4058
|
+
def teradatatitle_sql(self, expression: exp.TeradataTitle) -> str:
|
|
4059
|
+
self.unsupported("Teradata TITLE display headings are not supported")
|
|
4060
|
+
return self.sql(expression, "this")
|
|
4061
|
+
|
|
4050
4062
|
def _jsonobject_sql(
|
|
4051
4063
|
self, expression: exp.JSONObject | exp.JSONObjectAgg, name: str = ""
|
|
4052
4064
|
) -> str:
|
|
@@ -4685,11 +4697,14 @@ class Generator:
|
|
|
4685
4697
|
return self.func("CONCAT", *(exp.cast(e, exp.DType.TEXT) for e in expression.flatten()))
|
|
4686
4698
|
return self.binary(expression, "||")
|
|
4687
4699
|
|
|
4700
|
+
def nullif_zero_divisor(self, expression: exp.Div | exp.Mod) -> None:
|
|
4701
|
+
if not self.dialect.SAFE_DIVISION and expression.args.get("safe"):
|
|
4702
|
+
divisor = expression.right
|
|
4703
|
+
divisor.replace(exp.Nullif(this=divisor.copy(), expression=exp.Literal.number(0)))
|
|
4704
|
+
|
|
4688
4705
|
def div_sql(self, expression: exp.Div) -> str:
|
|
4689
4706
|
l, r = expression.left, expression.right
|
|
4690
|
-
|
|
4691
|
-
if not self.dialect.SAFE_DIVISION and expression.args.get("safe"):
|
|
4692
|
-
r.replace(exp.Nullif(this=r.copy(), expression=exp.Literal.number(0)))
|
|
4707
|
+
self.nullif_zero_divisor(expression)
|
|
4693
4708
|
|
|
4694
4709
|
if self.dialect.TYPED_DIVISION and not expression.args.get("typed"):
|
|
4695
4710
|
if not l.is_type(*exp.DataType.REAL_TYPES) and not r.is_type(*exp.DataType.REAL_TYPES):
|
|
@@ -4703,8 +4718,8 @@ class Generator:
|
|
|
4703
4718
|
if all(e.is_int or isinstance(e, exp.Cast) for e in (l, r)) and (
|
|
4704
4719
|
expression.args.get("safe") or not self.SAFE_INT_DIVISION
|
|
4705
4720
|
):
|
|
4706
|
-
return self.sql(exp.IntDiv(this=l, expression=
|
|
4707
|
-
return self._truncated_div_sql(l,
|
|
4721
|
+
return self.sql(exp.IntDiv(this=l, expression=expression.right))
|
|
4722
|
+
return self._truncated_div_sql(l, expression.right)
|
|
4708
4723
|
|
|
4709
4724
|
return self.binary(expression, "/")
|
|
4710
4725
|
|
|
@@ -4828,6 +4843,7 @@ class Generator:
|
|
|
4828
4843
|
return self.binary(expression, "<=")
|
|
4829
4844
|
|
|
4830
4845
|
def mod_sql(self, expression: exp.Mod) -> str:
|
|
4846
|
+
self.nullif_zero_divisor(expression)
|
|
4831
4847
|
this = self.sql(expression, "this")
|
|
4832
4848
|
expr = self.sql(expression, "expression")
|
|
4833
4849
|
sql = f"{this} {self.maybe_comment(self.MOD_OPERATOR, comments=expression.comments)} {expr}"
|
|
@@ -6084,6 +6100,9 @@ class Generator:
|
|
|
6084
6100
|
)
|
|
6085
6101
|
|
|
6086
6102
|
def slice_sql(self, expression: exp.Slice) -> str:
|
|
6103
|
+
if "[" in self.dialect.tokenizer_class._IDENTIFIERS:
|
|
6104
|
+
self.unsupported("Slices are not supported")
|
|
6105
|
+
|
|
6087
6106
|
step = self.sql(expression, "step")
|
|
6088
6107
|
# An omitted end is written as `-` before a step, since `::` is the cast operator
|
|
6089
6108
|
end = self.sql(expression.expression) or ("-" if step else "")
|
|
@@ -779,6 +779,7 @@ class BigQueryGenerator(generator.Generator):
|
|
|
779
779
|
return self.func("DATE_TRUNC", expression.this, unit_sql, expression.args.get("zone"))
|
|
780
780
|
|
|
781
781
|
def mod_sql(self, expression: exp.Mod) -> str:
|
|
782
|
+
self.nullif_zero_divisor(expression)
|
|
782
783
|
this = expression.this
|
|
783
784
|
expr = expression.expression
|
|
784
785
|
return self.func(
|
|
@@ -769,6 +769,19 @@ class ClickHouseGenerator(generator.Generator):
|
|
|
769
769
|
else:
|
|
770
770
|
values_as_table = True
|
|
771
771
|
|
|
772
|
+
# An unparenthesized VALUES in FROM is the values() table function, which takes a single
|
|
773
|
+
# argument list, so a multi-row VALUES relation must be parenthesized to parse
|
|
774
|
+
if (
|
|
775
|
+
values_as_table
|
|
776
|
+
and len(expression.expressions) > 1
|
|
777
|
+
and (alias or isinstance(expression.parent, (exp.From, exp.Join, exp.Table)))
|
|
778
|
+
):
|
|
779
|
+
values = f"(VALUES{self.seg('')}{self.expressions(expression)})"
|
|
780
|
+
values = self.query_modifiers(expression, values)
|
|
781
|
+
pivots = self.expressions(expression, key="pivots", sep="", flat=True)
|
|
782
|
+
alias_sql = self.sql(alias)
|
|
783
|
+
return f"{values} AS {alias_sql}{pivots}" if alias_sql else f"{values}{pivots}"
|
|
784
|
+
|
|
772
785
|
return super().values_sql(expression, values_as_table=values_as_table)
|
|
773
786
|
|
|
774
787
|
def timestamptrunc_sql(self, expression: exp.DateTrunc | exp.TimestampTrunc) -> str:
|
|
@@ -2,7 +2,7 @@ from __future__ import annotations
|
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
from sqlglot import exp, generator
|
|
5
|
-
from sqlglot.dialects.dialect import
|
|
5
|
+
from sqlglot.dialects.dialect import mod_func_sql
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
class DruidGenerator(generator.Generator):
|
|
@@ -25,6 +25,6 @@ class DruidGenerator(generator.Generator):
|
|
|
25
25
|
TRANSFORMS = {
|
|
26
26
|
**generator.Generator.TRANSFORMS,
|
|
27
27
|
exp.CurrentTimestamp: lambda *_: "CURRENT_TIMESTAMP",
|
|
28
|
-
exp.Mod:
|
|
28
|
+
exp.Mod: mod_func_sql,
|
|
29
29
|
exp.Array: lambda self, e: f"ARRAY[{self.expressions(e)}]",
|
|
30
30
|
}
|
|
@@ -1255,8 +1255,8 @@ def _build_capitalization_sql(
|
|
|
1255
1255
|
if delimiters_sql == "''":
|
|
1256
1256
|
return f"UPPER(LEFT({value_to_split}, 1)) || LOWER(SUBSTRING({value_to_split}, 2))"
|
|
1257
1257
|
|
|
1258
|
-
delim_regex_sql = f"
|
|
1259
|
-
split_regex_sql = f"
|
|
1258
|
+
delim_regex_sql = f"'[' || {delimiters_sql} || ']'"
|
|
1259
|
+
split_regex_sql = f"'([' || {delimiters_sql} || ']+|[^' || {delimiters_sql} || ']+)'"
|
|
1260
1260
|
|
|
1261
1261
|
# REGEXP_EXTRACT_ALL produces a list of string segments, alternating between delimiter and non-delimiter segments.
|
|
1262
1262
|
# We do not know whether the first segment is a delimiter or not, so we check the first character of the string
|
|
@@ -1269,15 +1269,17 @@ def _build_capitalization_sql(
|
|
|
1269
1269
|
self.func(
|
|
1270
1270
|
"LIST_TRANSFORM",
|
|
1271
1271
|
self.func("REGEXP_EXTRACT_ALL", value_to_split, split_regex_sql),
|
|
1272
|
-
"
|
|
1272
|
+
"LAMBDA seg, idx : CASE WHEN idx % 2 = 0 THEN UPPER(LEFT(seg, 1)) || LOWER(SUBSTRING(seg, 2)) ELSE seg END",
|
|
1273
1273
|
),
|
|
1274
|
+
dialect=self.dialect,
|
|
1274
1275
|
)
|
|
1275
1276
|
.else_(
|
|
1276
1277
|
self.func(
|
|
1277
1278
|
"LIST_TRANSFORM",
|
|
1278
1279
|
self.func("REGEXP_EXTRACT_ALL", value_to_split, split_regex_sql),
|
|
1279
|
-
"
|
|
1280
|
+
"LAMBDA seg, idx : CASE WHEN idx % 2 = 1 THEN UPPER(LEFT(seg, 1)) || LOWER(SUBSTRING(seg, 2)) ELSE seg END",
|
|
1280
1281
|
),
|
|
1282
|
+
dialect=self.dialect,
|
|
1281
1283
|
),
|
|
1282
1284
|
"''",
|
|
1283
1285
|
)
|
|
@@ -7,6 +7,7 @@ from sqlglot.dialects.dialect import (
|
|
|
7
7
|
DATE_ADD_OR_SUB,
|
|
8
8
|
Dialect,
|
|
9
9
|
groupconcat_sql,
|
|
10
|
+
mod_func_sql,
|
|
10
11
|
no_last_day_sql,
|
|
11
12
|
rename_func,
|
|
12
13
|
strposition_sql,
|
|
@@ -356,7 +357,7 @@ class ExasolGenerator(generator.Generator):
|
|
|
356
357
|
rename_func("EDIT_DISTANCE")
|
|
357
358
|
),
|
|
358
359
|
# https://docs.exasol.com/db/latest/sql_references/functions/alphabeticallistfunctions/mod.htm
|
|
359
|
-
exp.Mod:
|
|
360
|
+
exp.Mod: mod_func_sql,
|
|
360
361
|
# https://docs.exasol.com/db/latest/sql_references/functions/alphabeticallistfunctions/from_posix_time.htm
|
|
361
362
|
exp.UnixToTime: lambda self, e: self.func("FROM_POSIX_TIME", e.this),
|
|
362
363
|
# https://docs.exasol.com/db/latest/sql_references/functions/alphabeticallistfunctions/rank.htm
|
|
@@ -3,6 +3,7 @@ from __future__ import annotations
|
|
|
3
3
|
from sqlglot import exp, generator, transforms
|
|
4
4
|
from sqlglot.dialects.dialect import (
|
|
5
5
|
groupconcat_sql,
|
|
6
|
+
mod_func_sql,
|
|
6
7
|
no_ilike_sql,
|
|
7
8
|
nth_value_from_sql,
|
|
8
9
|
rename_func,
|
|
@@ -77,7 +78,7 @@ class OracleGenerator(generator.Generator):
|
|
|
77
78
|
exp.ILike: no_ilike_sql,
|
|
78
79
|
exp.LogicalOr: rename_func("MAX"),
|
|
79
80
|
exp.LogicalAnd: rename_func("MIN"),
|
|
80
|
-
exp.Mod:
|
|
81
|
+
exp.Mod: mod_func_sql,
|
|
81
82
|
exp.NthValue: nth_value_from_sql,
|
|
82
83
|
exp.Rand: rename_func("DBMS_RANDOM.VALUE"),
|
|
83
84
|
exp.Select: transforms.preprocess(
|
|
@@ -318,6 +318,12 @@ class PostgresGenerator(generator.Generator):
|
|
|
318
318
|
|
|
319
319
|
return sql
|
|
320
320
|
|
|
321
|
+
def star_sql(self, expression: exp.Star) -> str:
|
|
322
|
+
if self.STAR_EXCEPT == "EXCEPT" and expression.args.get("except_"):
|
|
323
|
+
self.unsupported("PostgreSQL does not support EXCEPT in the SELECT projection")
|
|
324
|
+
|
|
325
|
+
return super().star_sql(expression)
|
|
326
|
+
|
|
321
327
|
TYPE_MAPPING = {
|
|
322
328
|
**generator.Generator.TYPE_MAPPING,
|
|
323
329
|
exp.DType.TINYINT: "SMALLINT",
|
|
@@ -397,7 +403,7 @@ class PostgresGenerator(generator.Generator):
|
|
|
397
403
|
"REGEXP_REPLACE",
|
|
398
404
|
e.this,
|
|
399
405
|
e.expression,
|
|
400
|
-
e.args.get("replacement"),
|
|
406
|
+
e.args.get("replacement") or exp.Literal.string(""),
|
|
401
407
|
e.args.get("position"),
|
|
402
408
|
e.args.get("occurrence"),
|
|
403
409
|
regexp_replace_global_modifier(e),
|
|
@@ -44,6 +44,13 @@ class RedshiftGenerator(PostgresGenerator):
|
|
|
44
44
|
# Redshift doesn't have `WITH` as part of their with_properties so we remove it
|
|
45
45
|
WITH_PROPERTIES_PREFIX = " "
|
|
46
46
|
|
|
47
|
+
PROPERTIES_LOCATION = {
|
|
48
|
+
**PostgresGenerator.PROPERTIES_LOCATION,
|
|
49
|
+
exp.DistKeyProperty: exp.Properties.Location.POST_SCHEMA,
|
|
50
|
+
exp.DistStyleProperty: exp.Properties.Location.POST_SCHEMA,
|
|
51
|
+
exp.SortKeyProperty: exp.Properties.Location.POST_SCHEMA,
|
|
52
|
+
}
|
|
53
|
+
|
|
47
54
|
TYPE_MAPPING = {
|
|
48
55
|
**PostgresGenerator.TYPE_MAPPING,
|
|
49
56
|
exp.DType.BINARY: "VARBYTE",
|
|
@@ -190,12 +190,17 @@ class SQLiteGenerator(generator.Generator):
|
|
|
190
190
|
# can be transpiled to SQLite, so we explicitly override them accordingly
|
|
191
191
|
exp.LikeProperty: exp.Properties.Location.POST_SCHEMA,
|
|
192
192
|
exp.ModuleProperty: exp.Properties.Location.POST_SCHEMA,
|
|
193
|
+
exp.StrictProperty: exp.Properties.Location.POST_SCHEMA,
|
|
193
194
|
exp.TemporaryProperty: exp.Properties.Location.POST_CREATE,
|
|
194
195
|
exp.VirtualProperty: exp.Properties.Location.POST_CREATE,
|
|
196
|
+
exp.WithoutRowidProperty: exp.Properties.Location.POST_SCHEMA,
|
|
195
197
|
}
|
|
196
198
|
|
|
197
199
|
LIMIT_FETCH = "LIMIT"
|
|
198
200
|
|
|
201
|
+
def root_properties(self, properties: exp.Properties) -> str:
|
|
202
|
+
return self.expressions(properties, indent=False, sep=", ")
|
|
203
|
+
|
|
199
204
|
def offset_limit_modifiers(
|
|
200
205
|
self, expression: exp.Expr, fetch: bool, limit: exp.Fetch | exp.Limit | None
|
|
201
206
|
) -> list[str]:
|
|
@@ -287,6 +292,30 @@ class SQLiteGenerator(generator.Generator):
|
|
|
287
292
|
modifier = f"{modifier} {unit.name}" if unit else modifier
|
|
288
293
|
return self.func("DATE", expression.this, exp.Literal.string(modifier))
|
|
289
294
|
|
|
295
|
+
def datesub_sql(self, expression: exp.DateSub) -> str:
|
|
296
|
+
# SQLite has no DATE_SUB, so add the negated amount instead
|
|
297
|
+
amount = expression.expression
|
|
298
|
+
unit = expression.args.get("unit")
|
|
299
|
+
if isinstance(amount, exp.Interval):
|
|
300
|
+
unit = unit or amount.unit
|
|
301
|
+
amount = amount.this
|
|
302
|
+
|
|
303
|
+
amount = amount.unnest()
|
|
304
|
+
negated: exp.Expr
|
|
305
|
+
if isinstance(amount, exp.Neg):
|
|
306
|
+
negated = amount.this
|
|
307
|
+
elif isinstance(amount, exp.Literal):
|
|
308
|
+
text = amount.name.removeprefix("+")
|
|
309
|
+
negated = exp.Literal.string(text[1:] if text.startswith("-") else f"-{text}")
|
|
310
|
+
else:
|
|
311
|
+
negated = exp.Neg(
|
|
312
|
+
this=amount
|
|
313
|
+
if isinstance(amount, (exp.Column, exp.Func))
|
|
314
|
+
else exp.paren(amount, copy=False)
|
|
315
|
+
)
|
|
316
|
+
|
|
317
|
+
return self.dateadd_sql(exp.DateAdd(this=expression.this, expression=negated, unit=unit))
|
|
318
|
+
|
|
290
319
|
def cast_sql(self, expression: exp.Cast, safe_prefix: str | None = None) -> str:
|
|
291
320
|
if expression.is_type("date"):
|
|
292
321
|
return self.func("DATE", expression.this)
|
|
@@ -98,10 +98,20 @@ class TeradataGenerator(generator.Generator):
|
|
|
98
98
|
exp.Quarter: lambda self, e: self.sql(exp.Extract(this="QUARTER", expression=e.this)),
|
|
99
99
|
}
|
|
100
100
|
|
|
101
|
+
def execute_sql(self, expression: exp.Execute) -> str:
|
|
102
|
+
if expression.args.get("return_status"):
|
|
103
|
+
self.unsupported("Teradata EXECUTE does not support a return status")
|
|
104
|
+
this = self.sql(expression, "this")
|
|
105
|
+
arguments = f"({self.expressions(expression, flat=True)})" if expression.expressions else ""
|
|
106
|
+
return f"EXECUTE {this}{arguments}"
|
|
107
|
+
|
|
101
108
|
def currenttimestamp_sql(self, expression: exp.CurrentTimestamp) -> str:
|
|
102
109
|
prefix, suffix = ("(", ")") if expression.this else ("", "")
|
|
103
110
|
return self.func("CURRENT_TIMESTAMP", expression.this, prefix=prefix, suffix=suffix)
|
|
104
111
|
|
|
112
|
+
def teradatatitle_sql(self, expression: exp.TeradataTitle) -> str:
|
|
113
|
+
return f"{self.sql(expression, 'this')} (TITLE {self.sql(expression, 'title')})"
|
|
114
|
+
|
|
105
115
|
def cast_sql(self, expression: exp.Cast, safe_prefix: str | None = None) -> str:
|
|
106
116
|
if expression.to.this == exp.DType.UNKNOWN and expression.args.get("format"):
|
|
107
117
|
# We don't actually want to print the unknown type in CAST(<value> AS FORMAT <format>)
|
|
@@ -6,7 +6,7 @@ import typing as t
|
|
|
6
6
|
from collections import Counter
|
|
7
7
|
|
|
8
8
|
from sqlglot import alias, exp
|
|
9
|
-
from sqlglot.dialects.dialect import Dialect, DialectType, UsingColumnOrder
|
|
9
|
+
from sqlglot.dialects.dialect import AliasPrecedence, Dialect, DialectType, UsingColumnOrder
|
|
10
10
|
from sqlglot.errors import OptimizeError, highlight_sql
|
|
11
11
|
from sqlglot.optimizer.annotate_types import TypeAnnotator
|
|
12
12
|
from sqlglot.optimizer.resolver import Resolver
|
|
@@ -131,7 +131,7 @@ def qualify_columns(
|
|
|
131
131
|
|
|
132
132
|
# DISTINCT ON and ORDER BY follow the same rules (tested in DuckDB, Postgres, ClickHouse)
|
|
133
133
|
# https://www.postgresql.org/docs/current/sql-select.html#SQL-DISTINCT
|
|
134
|
-
_expand_order_by_and_distinct_on(scope, resolver)
|
|
134
|
+
_expand_order_by_and_distinct_on(scope, resolver, using_column_tables)
|
|
135
135
|
|
|
136
136
|
if dialect.ANNOTATE_ALL_SCOPES:
|
|
137
137
|
annotator.annotate_scope(scope)
|
|
@@ -390,6 +390,7 @@ def _expand_alias_refs(
|
|
|
390
390
|
if not node or (expand_only_groupby and not is_group_by):
|
|
391
391
|
return
|
|
392
392
|
|
|
393
|
+
precedence = dialect.column_alias_precedence(node)
|
|
393
394
|
for column in walk_in_scope(node, prune=lambda node: node.is_star):
|
|
394
395
|
if not isinstance(column, exp.Column):
|
|
395
396
|
continue
|
|
@@ -429,8 +430,8 @@ def _expand_alias_refs(
|
|
|
429
430
|
node.parts[0].name in projections
|
|
430
431
|
for node in alias_expr.find_all(exp.Column)
|
|
431
432
|
)
|
|
432
|
-
prefer_column =
|
|
433
|
-
if table and
|
|
433
|
+
prefer_column = precedence in (AliasPrecedence.SOURCE, AliasPrecedence.MERGED_SOURCE)
|
|
434
|
+
if table and precedence == AliasPrecedence.GROUPED_SOURCE:
|
|
434
435
|
prefer_column = (
|
|
435
436
|
isinstance(column.find_ancestor(exp.AggFunc, exp.Having), exp.AggFunc)
|
|
436
437
|
or (table.name, column.name) in grouped_columns
|
|
@@ -502,8 +503,8 @@ def _expand_alias_refs(
|
|
|
502
503
|
replace_columns(expression.args.get("group"), literal_index=True)
|
|
503
504
|
|
|
504
505
|
if (
|
|
505
|
-
|
|
506
|
-
and
|
|
506
|
+
(having := expression.args.get("having"))
|
|
507
|
+
and dialect.column_alias_precedence(having) == AliasPrecedence.GROUPED_SOURCE
|
|
507
508
|
and (group := expression.args.get("group"))
|
|
508
509
|
):
|
|
509
510
|
# Only standalone grouping columns shadow HAVING aliases, not columns inside expressions.
|
|
@@ -555,7 +556,9 @@ def _expand_group_by(scope: Scope, dialect: Dialect) -> None:
|
|
|
555
556
|
expression.set("group", group)
|
|
556
557
|
|
|
557
558
|
|
|
558
|
-
def _expand_order_by_and_distinct_on(
|
|
559
|
+
def _expand_order_by_and_distinct_on(
|
|
560
|
+
scope: Scope, resolver: Resolver, using_column_tables: dict[str, dict[str, t.Any]]
|
|
561
|
+
) -> None:
|
|
559
562
|
expression = scope.expression
|
|
560
563
|
|
|
561
564
|
if not isinstance(expression, exp.Selectable):
|
|
@@ -567,9 +570,11 @@ def _expand_order_by_and_distinct_on(scope: Scope, resolver: Resolver) -> None:
|
|
|
567
570
|
expr: exp.Expr = expression
|
|
568
571
|
|
|
569
572
|
for modifier_key in ("order", "distinct"):
|
|
570
|
-
|
|
571
|
-
if isinstance(
|
|
572
|
-
|
|
573
|
+
clause = expr.args.get(modifier_key)
|
|
574
|
+
if not isinstance(clause, exp.Expr):
|
|
575
|
+
continue
|
|
576
|
+
|
|
577
|
+
modifier = clause.args.get("on") if isinstance(clause, exp.Distinct) else clause
|
|
573
578
|
|
|
574
579
|
if not isinstance(modifier, exp.Expr):
|
|
575
580
|
continue
|
|
@@ -584,12 +589,28 @@ def _expand_order_by_and_distinct_on(scope: Scope, resolver: Resolver) -> None:
|
|
|
584
589
|
scope, modifier_expressions, resolver.dialect, alias_names=alias_names
|
|
585
590
|
),
|
|
586
591
|
):
|
|
587
|
-
|
|
588
|
-
|
|
592
|
+
precedence = resolver.dialect.column_alias_precedence(clause, original)
|
|
593
|
+
prefer_column = precedence in (AliasPrecedence.SOURCE, AliasPrecedence.MERGED_SOURCE)
|
|
594
|
+
for node in (original,) if prefer_column else find_all_in_scope(original, exp.AggFunc):
|
|
595
|
+
for col in find_all_in_scope(node, exp.Column):
|
|
589
596
|
if not col.table:
|
|
590
|
-
if
|
|
597
|
+
if prefer_column and (tables := using_column_tables.get(col.name)):
|
|
598
|
+
if precedence == AliasPrecedence.SOURCE and any(
|
|
599
|
+
col.name in resolver.get_source_columns(source)
|
|
600
|
+
for source in scope.selected_sources
|
|
601
|
+
if source not in tables
|
|
602
|
+
):
|
|
603
|
+
raise OptimizeError(f"Ambiguous column: {col.name}")
|
|
604
|
+
col.replace(
|
|
605
|
+
exp.func(
|
|
606
|
+
"coalesce", *[exp.column(col.name, table) for table in tables]
|
|
607
|
+
)
|
|
608
|
+
)
|
|
609
|
+
elif table := resolver.get_table(col):
|
|
591
610
|
col.set("table", table)
|
|
592
611
|
col.meta.pop("dot_parts", None)
|
|
612
|
+
elif prefer_column and col.name in resolver.all_columns:
|
|
613
|
+
raise OptimizeError(f"Ambiguous column: {col.name}")
|
|
593
614
|
|
|
594
615
|
if original is not expanded:
|
|
595
616
|
original.replace(expanded)
|
|
@@ -605,6 +626,8 @@ def _expand_order_by_and_distinct_on(scope: Scope, resolver: Resolver) -> None:
|
|
|
605
626
|
continue
|
|
606
627
|
node.replace(exp.column(replacement.alias_or_name))
|
|
607
628
|
|
|
629
|
+
scope.clear_column_cache()
|
|
630
|
+
|
|
608
631
|
|
|
609
632
|
def _same_dot_parts(left: exp.Expr, right: exp.Expr) -> bool:
|
|
610
633
|
"""Compare original path spellings in structurally equal expressions."""
|
|
@@ -901,6 +924,43 @@ def _qualify_positional_column(
|
|
|
901
924
|
return False
|
|
902
925
|
|
|
903
926
|
|
|
927
|
+
def _get_outer_column_table(column: exp.Column, resolver: Resolver) -> exp.Identifier | None:
|
|
928
|
+
column_name = column.name
|
|
929
|
+
scope = resolver.scope
|
|
930
|
+
shadowing_sources = set(scope.selected_sources)
|
|
931
|
+
|
|
932
|
+
# Correlated columns can reach this scope from a descendant with shadowing aliases.
|
|
933
|
+
if id(column) not in scope.column_index:
|
|
934
|
+
column_scope: Scope | None = next(
|
|
935
|
+
(inner for inner in scope.traverse() if id(column) in inner.column_index), None
|
|
936
|
+
)
|
|
937
|
+
while column_scope and column_scope is not scope:
|
|
938
|
+
shadowing_sources.update(column_scope.selected_sources)
|
|
939
|
+
column_scope = column_scope.parent
|
|
940
|
+
|
|
941
|
+
for outer_resolver in resolver.outer_resolvers():
|
|
942
|
+
source_columns = outer_resolver._get_all_source_columns()
|
|
943
|
+
# A LATERAL's scope already holds the preceding sources it can reference.
|
|
944
|
+
if scope.is_subquery:
|
|
945
|
+
join = scope.expression.find_ancestor(exp.Join, exp.Select)
|
|
946
|
+
if (
|
|
947
|
+
isinstance(join, exp.Join)
|
|
948
|
+
and join.find_ancestor(exp.Select) is outer_resolver.scope.expression
|
|
949
|
+
):
|
|
950
|
+
source_columns = outer_resolver._get_available_source_columns(join, join_group=True)
|
|
951
|
+
|
|
952
|
+
if any(column_name in columns for columns in source_columns.values()):
|
|
953
|
+
table = outer_resolver.get_table(column, source_columns)
|
|
954
|
+
|
|
955
|
+
# A source in between with the same name would capture the qualified column
|
|
956
|
+
return table if table and table.name not in shadowing_sources else None
|
|
957
|
+
|
|
958
|
+
scope = outer_resolver.scope
|
|
959
|
+
shadowing_sources.update(source_columns)
|
|
960
|
+
|
|
961
|
+
return None
|
|
962
|
+
|
|
963
|
+
|
|
904
964
|
def _qualify_columns(
|
|
905
965
|
scope: Scope,
|
|
906
966
|
resolver: Resolver,
|
|
@@ -975,8 +1035,16 @@ def _qualify_columns(
|
|
|
975
1035
|
and column_name in scope.selected_sources
|
|
976
1036
|
and not resolver.has_unknown_sources
|
|
977
1037
|
):
|
|
978
|
-
|
|
979
|
-
|
|
1038
|
+
outer_table = (
|
|
1039
|
+
_get_outer_column_table(column, resolver)
|
|
1040
|
+
if resolver.dialect.OUTER_COLUMNS_SHADOW_TABLE_ALIASES
|
|
1041
|
+
else None
|
|
1042
|
+
)
|
|
1043
|
+
if outer_table:
|
|
1044
|
+
column.set("table", outer_table)
|
|
1045
|
+
else:
|
|
1046
|
+
# BigQuery and Postgres allow tables to be referenced as columns, treating them as structs/records
|
|
1047
|
+
scope.replace(column, exp.TableColumn(this=column.this))
|
|
980
1048
|
|
|
981
1049
|
pivots = scope.pivots
|
|
982
1050
|
|