Skip to content

Commit

Permalink
fix(athena): Fix CREATE TABLE properties, STRING data type (#3129)
Browse files Browse the repository at this point in the history
  • Loading branch information
VaggelisD committed Mar 12, 2024
1 parent 0ea849b commit 94b5a2f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
25 changes: 25 additions & 0 deletions sqlglot/dialects/athena.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

from sqlglot import exp
from sqlglot.dialects.trino import Trino
from sqlglot.tokens import TokenType

Expand All @@ -10,3 +11,27 @@ class Parser(Trino.Parser):
**Trino.Parser.STATEMENT_PARSERS,
TokenType.USING: lambda self: self._parse_as_command(self._prev),
}

class Generator(Trino.Generator):
PROPERTIES_LOCATION = {
**Trino.Generator.PROPERTIES_LOCATION,
exp.LocationProperty: exp.Properties.Location.POST_SCHEMA,
}

TYPE_MAPPING = {
**Trino.Generator.TYPE_MAPPING,
exp.DataType.Type.TEXT: "STRING",
}

TRANSFORMS = {
**Trino.Generator.TRANSFORMS,
exp.FileFormatProperty: lambda self, e: f"'FORMAT'={self.sql(e, 'this')}",
}

def property_sql(self, expression: exp.Property) -> str:
return (
f"{self.property_name(expression, string_key=True)}={self.sql(expression, 'value')}"
)

def with_properties(self, properties: exp.Properties) -> str:
return self.properties(properties, prefix=self.seg("TBLPROPERTIES"))
4 changes: 4 additions & 0 deletions tests/dialects/test_athena.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,7 @@ def test_athena(self):
some_function(1)""",
check_command_warning=True,
)

self.validate_identity(
"CREATE TABLE IF NOT EXISTS t (name STRING) LOCATION 's3://bucket/tmp/mytable/' TBLPROPERTIES ('table_type'='iceberg', 'FORMAT'='parquet')"
)

0 comments on commit 94b5a2f

Please sign in to comment.