-
Notifications
You must be signed in to change notification settings - Fork 114
fix: render Hive STRUCT syntax in table column DDL #870
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
Merged
laughingman7743
merged 4 commits into
pyathena-dev:master
from
mvanhorn:fix/855-struct-column-ddl
Sep 29, 2026
+301
−32
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
27674e0
fix: render Hive STRUCT syntax in table column DDL
mvanhorn af04b14
refactor: rename the Hive DDL flag and drop per-test cleanup
mvanhorn 954cc9b
test: fold struct column DDL tests into TestAthenaDDLCompiler
mvanhorn 29d894a
Merge branch 'master' into fix/855-struct-column-ddl
laughingman7743 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3496,8 +3496,8 @@ def test_create_table_with_map_types(self, engine): | |
|
|
||
| # Verify MAP types are correctly compiled | ||
| assert "attributes MAP<STRING, STRING>" in ddl_string | ||
| assert "metrics MAP<STRING, INTEGER>" in ddl_string | ||
| assert "complex_map MAP<STRING, ROW(value STRING, count INTEGER)>" in ddl_string | ||
| assert "metrics MAP<STRING, INT>" in ddl_string | ||
| assert "complex_map MAP<STRING, STRUCT<value:STRING, count:INT>>" in ddl_string | ||
| assert "nested_map MAP<STRING, ARRAY<STRING>>" in ddl_string | ||
|
|
||
| def test_create_table_with_struct_types(self, engine): | ||
|
|
@@ -3539,12 +3539,12 @@ def test_create_table_with_struct_types(self, engine): | |
| ddl_string = str(create_ddl) | ||
|
|
||
| # Verify STRUCT types are correctly compiled | ||
| assert "user_info ROW(name STRING, age INTEGER, email STRING)" in ddl_string | ||
| assert "user_info STRUCT<name:STRING, age:INT, email:STRING>" in ddl_string | ||
| assert ( | ||
| "nested_struct ROW(personal ROW(first_name STRING, last_name STRING), " | ||
| "preferences MAP<STRING, STRING>)" in ddl_string | ||
| "nested_struct STRUCT<personal:STRUCT<first_name:STRING, last_name:STRING>, " | ||
| "preferences:MAP<STRING, STRING>>" in ddl_string | ||
| ) | ||
| assert "struct_with_array ROW(tags ARRAY<STRING>, scores ARRAY<INT>)" in ddl_string | ||
| assert "struct_with_array STRUCT<tags:ARRAY<STRING>, scores:ARRAY<INT>>" in ddl_string | ||
|
|
||
| def test_create_table_with_complex_nested_types(self, engine): | ||
| """Test DDL compilation for complex nested combinations of ARRAY, MAP, and STRUCT.""" | ||
|
|
@@ -3582,6 +3582,57 @@ def test_create_table_with_complex_nested_types(self, engine): | |
| ) | ||
| assert expected_type in ddl_string | ||
|
|
||
| def test_external_parquet_struct_columns_round_trip(self, engine): | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I ran this against real Athena in the maintainer's AWS account on af04b14 (Python 3.13.1, SQLAlchemy 2.0.46, boto3/botocore 1.43.102).
So the fix is confirmed on real Athena, and the only remaining change is folding |
||
| """Create a Parquet table of top-level and MAP-nested STRUCTs and read the fields back.""" | ||
| _, conn = engine | ||
| table_name = "test_external_parquet_struct_columns" | ||
| location = f"{ENV.s3_staging_dir}{ENV.schema}/{table_name}/" | ||
| table = Table( | ||
| table_name, | ||
| MetaData(schema=ENV.schema), | ||
| Column( | ||
| "profile", | ||
| AthenaStruct( | ||
| ("name", types.String), | ||
| ("age", types.Integer), | ||
| ( | ||
| "address", | ||
| AthenaStruct(("city", types.String), ("zip", types.Integer)), | ||
| ), | ||
| ), | ||
| ), | ||
| Column( | ||
| "labels", | ||
| AthenaMap( | ||
| types.String, | ||
| AthenaStruct(("value", types.String), ("count", types.Integer)), | ||
| ), | ||
| ), | ||
| awsathena_location=location, | ||
| awsathena_file_format="PARQUET", | ||
| ) | ||
| ddl = str(CreateTable(table).compile(dialect=conn.dialect)) | ||
| assert "profile STRUCT<name:STRING, age:INT, address:STRUCT<city:STRING, zip:INT>>" in ddl | ||
| assert "labels MAP<STRING, STRUCT<value:STRING, count:INT>>" in ddl | ||
| table.create(bind=conn) | ||
| conn.execute( | ||
| text( | ||
| f"INSERT INTO {ENV.schema}.{table_name} VALUES (" | ||
| "CAST(ROW('Ada', 36, ROW('London', 12345)) AS " | ||
| "ROW(name VARCHAR, age INTEGER, address ROW(city VARCHAR, zip INTEGER))), " | ||
| "MAP(ARRAY['home'], ARRAY[CAST(ROW('Lovelace', 2) AS " | ||
| "ROW(value VARCHAR, count INTEGER))]))" | ||
| ) | ||
| ) | ||
| row = conn.execute( | ||
| text( | ||
| "SELECT profile.name, profile.age, profile.address.city, " | ||
| "profile.address.zip, labels['home'].value, labels['home'].count " | ||
| f"FROM {ENV.schema}.{table_name}" | ||
| ) | ||
| ).one() | ||
| assert tuple(row) == ("Ada", 36, "London", 12345, "Lovelace", 2) | ||
|
|
||
| def test_sqlalchemy_execute_with_execution_options_callback(self, engine): | ||
| """Test callback functionality through SQLAlchemy execution_options.""" | ||
| engine, conn = engine | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This live test is the right way to prove the fix, but the PR has no record that it, or any other AWS check, has run. As requested in #855 and required by
docs/contributing.md, please run the liveCREATE TABLEand read-back in your own AWS account, on the commit before the fix and on the fixed commit, and record the results in TEST. Include the tested commit, the Python and dependency versions, the exact commands, the passed/failed/skipped counts, and whether each result came from real AWS. The current TEST section lists planned steps; it is not a validation record.WHAT and WHY also contain the same text. WHY should point to #855 and the scope agreed there.
External-fork PRs are not run in the project's AWS CI.