Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix(athena): Case sensitivity in CTAS property names #4171

Merged
merged 1 commit into from
Sep 28, 2024

Conversation

erindru
Copy link
Collaborator

@erindru erindru commented Sep 27, 2024

It turns out Athena table properties are case sensitive on the Trino engine and need to be lowercase.

CREATE TABLE "test_table" WITH (PARTITIONED_BY=ARRAY['ds'], ...) AS SELECT ...

Fails with Table properties [PARTITIONED_BY] are not supported.

CREATE TABLE "test_table" WITH (partitioned_by=ARRAY['ds'], ...) AS SELECT ...

Succeeds

@@ -132,6 +132,7 @@ class Generator(Trino.Generator):
TRANSFORMS = {
**Trino.Generator.TRANSFORMS,
exp.FileFormatProperty: lambda self, e: f"format={self.sql(e, 'this')}",
exp.PartitionedByProperty: lambda self, e: f"partitioned_by={self.sql(e, 'this')}",
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that the actual reason for the uppercasing is because the Properties.NAME_TO_PROPERTY map hardcodes everything to uppercase.

Since we already had a transform to lowercase exp.FileFormatProperty, I added one for exp.PartitionedByProperty since most of the properties in Properties.NAME_TO_PROPERTY arent relevant for Athena

@@ -62,8 +62,12 @@ def test_ddl(self):

# CTAS goes to the Trino engine, where the table properties cant be encased in single quotes like they can for Hive
# ref: https://docs.aws.amazon.com/athena/latest/ug/create-table-as.html#ctas-table-properties
# They're also case sentitive and need to be lowercase, otherwise you get eg "Table properties [FORMAT] are not supported."
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small typo on "sensitive".

A personal nit, feel free to ignore: I'd consider merging this comment with the first one, I think this would read a bit better e.g.

CTAS goes to the Trino engine, where the table properties:
- Must not be single quoted (Hive case)
- Must be generated in lower case as their resolution is case-sensitive

ref: ....

@georgesittas georgesittas merged commit 81df4e1 into main Sep 28, 2024
6 checks passed
@georgesittas georgesittas deleted the erin/athena-ctas-case-sensitivity branch September 28, 2024 14:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants