-
Notifications
You must be signed in to change notification settings - Fork 114
Leave unset storage values out of the Glue table parameters #890
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -243,12 +243,14 @@ def list_databases(self, catalog_name: str | None) -> list[AthenaDatabase]: | |
| def table_metadata(table: Mapping[str, Any]) -> AthenaTableMetadata: | ||
| """Build the metadata Athena reports for a Glue table. | ||
|
|
||
| Athena flattens the storage descriptor into the table parameters: the | ||
| location and formats are always present, the SerDe library whenever | ||
| the descriptor has SerDe information, and SerDe parameters with a | ||
| ``serde.param.`` prefix. The Glue description is not the table comment. | ||
| Glue keeps an Iceberg table's dropped and renamed columns, marked as | ||
| not current, which Athena leaves out. | ||
| Athena flattens the storage descriptor into the table parameters, | ||
| replacing parameters of the same name: the location and formats, the | ||
| SerDe library whenever the descriptor has SerDe information, and SerDe | ||
| parameters with a ``serde.param.`` prefix. A value the descriptor | ||
| leaves unset is left out rather than reported as None; an empty string | ||
| is kept. The Glue description is not the table comment. Glue keeps an | ||
| Iceberg table's dropped and renamed columns, marked as not current, | ||
| which Athena leaves out. | ||
|
|
||
| Args: | ||
| table: A ``Table`` from a Glue ``GetTable`` or ``GetTables`` response. | ||
|
|
@@ -257,16 +259,23 @@ def table_metadata(table: Mapping[str, Any]) -> AthenaTableMetadata: | |
| The table's metadata as Athena reports it. | ||
| """ | ||
| descriptor = table.get("StorageDescriptor") or {} | ||
| parameters = dict(table.get("Parameters") or {}) | ||
| parameters["location"] = descriptor.get("Location") | ||
| parameters["inputformat"] = descriptor.get("InputFormat") | ||
| parameters["outputformat"] = descriptor.get("OutputFormat") | ||
| serde = descriptor.get("SerdeInfo") or {} | ||
| storage = { | ||
| "location": descriptor.get("Location"), | ||
| "inputformat": descriptor.get("InputFormat"), | ||
| "outputformat": descriptor.get("OutputFormat"), | ||
| } | ||
| if "SerdeInfo" in descriptor: | ||
| serde = descriptor["SerdeInfo"] | ||
| parameters["serde.serialization.lib"] = serde.get("SerializationLibrary") | ||
| parameters.update( | ||
| {f"serde.param.{k}": v for k, v in (serde.get("Parameters") or {}).items()} | ||
| ) | ||
| storage["serde.serialization.lib"] = serde.get("SerializationLibrary") | ||
| parameters = dict(table.get("Parameters") or {}) | ||
| for key, value in storage.items(): | ||
| if value is None: | ||
| parameters.pop(key, None) | ||
|
Member
Author
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. Self-review of the repair, round one (implementation behavior): CLEAN Scope: Equivalence check: master's Callers: the same Tests: the |
||
| else: | ||
| parameters[key] = value | ||
| parameters.update( | ||
| {f"serde.param.{k}": v for k, v in (serde.get("Parameters") or {}).items()} | ||
| ) | ||
|
|
||
| def column(c: Mapping[str, Any]) -> dict[str, Any]: | ||
| return {k: c[k] for k in ("Name", "Type", "Comment") if k in c} | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -210,7 +210,8 @@ def column(name, current): | |
| "serde.param.field.delim": "\t", | ||
| }, | ||
| ), | ||
| # A view has empty SerDe information, which Athena still reports. | ||
| # A view has no formats and empty SerDe information; Athena reports | ||
| # only its empty location. | ||
| ( | ||
| { | ||
| "Parameters": {"comment": "Presto View", "presto_view": "true"}, | ||
|
|
@@ -220,12 +221,9 @@ def column(name, current): | |
| "comment": "Presto View", | ||
| "presto_view": "true", | ||
| "location": "", | ||
| "inputformat": None, | ||
| "outputformat": None, | ||
| "serde.serialization.lib": None, | ||
| }, | ||
| ), | ||
| # An Iceberg table has none, and Athena reports no SerDe library. | ||
| # An Iceberg table has no formats and no SerDe information. | ||
| ( | ||
| { | ||
| "Parameters": {"table_type": "ICEBERG", "metadata_location": "s3://m"}, | ||
|
|
@@ -235,16 +233,44 @@ def column(name, current): | |
| "table_type": "ICEBERG", | ||
| "metadata_location": "s3://m", | ||
| "location": "s3://bucket/iceberg", | ||
| "inputformat": None, | ||
| "outputformat": None, | ||
| }, | ||
| ), | ||
| # An S3 Tables table has empty formats, which Athena reports. | ||
| ( | ||
| { | ||
| "Parameters": {"table_type": "ICEBERG"}, | ||
| "StorageDescriptor": { | ||
| "Location": "s3://bucket--table-s3", | ||
| "InputFormat": "", | ||
| "OutputFormat": "", | ||
| }, | ||
| }, | ||
| { | ||
| "table_type": "ICEBERG", | ||
| "location": "s3://bucket--table-s3", | ||
|
Member
Author
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. Self-review round two (claims, callers, operations): FINDINGS (PR description only, corrected) Scope: base Claims checked:
Existing callers: Documentation: Operations: no request is added or removed; only the conversion of responses already fetched changes. Evidence limits: 34 Glue-related tests passed locally against AWS at this head, and the full suite will run once the PR is Ready. The |
||
| "inputformat": "", | ||
| "outputformat": "", | ||
| }, | ||
| ), | ||
| # The descriptor replaces table parameters of the same name, also | ||
| # when it leaves the value unset. | ||
| ( | ||
| { | ||
| "Parameters": { | ||
| "location": "s3://table-parameter", | ||
| "inputformat": "TableParameterInputFormat", | ||
| "serde.serialization.lib": "TableParameterSerDe", | ||
| }, | ||
| "StorageDescriptor": {"Location": "", "SerdeInfo": {}}, | ||
| }, | ||
| {"location": ""}, | ||
| ), | ||
| ], | ||
| ids=["hive", "view", "iceberg"], | ||
| ids=["hive", "view", "iceberg", "s3_tables", "table_parameter_collision"], | ||
| ) | ||
| def test_table_metadata(self, table, expected_parameters): | ||
| # Glue responses measured against GetTableMetadata for the same tables in | ||
| # #786; Athena flattens them this way. | ||
| # #786 and #887; Athena flattens them this way. | ||
| table = { | ||
| "Name": "t", | ||
| "TableType": "EXTERNAL_TABLE", | ||
|
|
||
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.
Self-review of the repair, round two (claims): CLEAN
Scope: the same range-diff, the repair commit message, the new docstring, the thread reply, and the PR body.
storagealways has the three keys, and the SerDe key only if"SerdeInfo" in descriptor). "A value the descriptor leaves unset is left out rather than reported as None; an empty string is kept" matches theis Nonebranch and theview/s3_tablescases.