Skip to content

Commit b091f2f

Browse files
authored
Fix(trino): Correctly render exp.LocationProperty in CREATE TABLE / CREATE SCHEMA (#4659)
1 parent bae0489 commit b091f2f

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

sqlglot/dialects/trino.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,17 @@ def _parse_json_query(self) -> exp.JSONExtract:
5757
)
5858

5959
class Generator(Presto.Generator):
60+
PROPERTIES_LOCATION = {
61+
**Presto.Generator.PROPERTIES_LOCATION,
62+
exp.LocationProperty: exp.Properties.Location.POST_WITH,
63+
}
64+
6065
TRANSFORMS = {
6166
**Presto.Generator.TRANSFORMS,
6267
exp.ArraySum: lambda self,
6368
e: f"REDUCE({self.sql(e, 'this')}, 0, (acc, x) -> acc + x, acc -> acc)",
6469
exp.ArrayUniqueAgg: lambda self, e: f"ARRAY_AGG(DISTINCT {self.sql(e, 'this')})",
70+
exp.LocationProperty: lambda self, e: self.property_sql(e),
6571
exp.Merge: merge_without_target_sql,
6672
exp.TimeStrToTime: lambda self, e: timestrtotime_sql(self, e, include_precision=True),
6773
exp.Trim: trim_sql,

tests/dialects/test_trino.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ def test_ddl(self):
8585
self.validate_identity(
8686
"ALTER VIEW people SET AUTHORIZATION alice", check_command_warning=True
8787
)
88+
self.validate_identity("CREATE SCHEMA foo WITH (LOCATION='s3://bucket/foo')")
89+
self.validate_identity(
90+
"CREATE TABLE foo.bar WITH (LOCATION='s3://bucket/foo/bar') AS SELECT 1"
91+
)
8892

8993
def test_analyze(self):
9094
self.validate_identity("ANALYZE tbl")

0 commit comments

Comments
 (0)