Description
Apache Iceberg version
0.9.0
Please describe the bug 🐞
Hello,
I am currently using v0.9.0rc3 and trying to evolve the schema for an existing non-empty table living the aws glue catalog.
It seems that
table.update_schema().add_column("col_name", StringType()).commit()will successfully add the column to the glue catalog table however, this will cause the table to become corrupt and no longer useable.
Trying to query it from Athena gives the following :
[ErrorCode: INTERNAL_ERROR_QUERY_ENGINE] Amazon Athena experienced an internal error while executing this query. Please contact AWS support for further assistance. You will not be charged for this query. We apologize for the inconvenience.
I raise the issue with AWS support and tried to do a
https://docs.aws.amazon.com/athena/latest/ug/querying-iceberg-alter-table-add-columns.html
on another table and it works fine.
It seems that something from pyiceberg is currently causing the table to become corrupt maybe ?
For reference
table.update_schema().delete_column("col_name").commit()causes no harm and the table is updated automatically in the catalog and querying it works fine as well.
I will maybe try to provide a follow-up once AWS support shares their feedback on the matter.
Please feel free to close this issue if it can be confirmed that the issue is on AWS's side solely.
Willingness to contribute
- I can contribute a fix for this bug independently
- I would be willing to contribute a fix for this bug with guidance from the Iceberg community
- I cannot contribute a fix for this bug at this time
Activity
mwa28 commentedon Jul 1, 2025
As of 2025-07-01, support has replied with the following :
jayceslesar commentedon Jul 1, 2025
I am unable to reproduce with the following on
v0.9.0rc3or onmain-- can you provide some more details if possible?Let me know if there are any modifications I should make to the following:
mwa28 commentedon Jul 2, 2025
Interesting, here is AWS support's take on the matter:
followed by query executing
After the optimization operation, Athena detected the table as corrupted.
mwa28 commentedon Jul 2, 2025
Maybe try to add a few more columns and remove some and maybe add a partition column to your tests ? See the above AWS support's test that causes the corruption from their side as well. The table got corrupt after an optimize from their side on a partition. My table has partitioning as well.
It seems that even through the glue catalog in the console you can corrupt the table not just with pyiceberg and apparently it is a known issue which is awful given that they do not put out a disclaimer anywhere on this topic.
jayceslesar commentedon Jul 2, 2025
Will need to do some more testing on the pyiceberg side but agreed that is frustrating from AWS.
Thank you for the detailed information!
mwa28 commentedon Jul 2, 2025
I figured it out, it is not a simple schema update from outside Athena that causes corruption but rather deleting the column that was set as Sort Order Key.
This behavior is not allowed within Athena via
as it gives :
Meanwhile with pyiceberg it is allowed. Here is my test :
I will update the issue title to match my findings.
[-]Adding a column to an existing table corrupts it in the glue catalog table[/-][+]Pyiceberg allows dropping the sort order column and causes table corruption on AWS Glue Catalog [/+]jayceslesar commentedon Jul 2, 2025
Nice, I was able to reproduce and also confirm that trino sees it as corrupted! Good find
jayceslesar commentedon Jul 2, 2025
Here is what the metadata looks like before:
{ "location": "s3://my-bucket/jayce-test-again", "table-uuid": "c467f3f1-f0d3-4b1d-a1d4-d1981ec3bce2", "last-updated-ms": 1751474855599, "last-column-id": 2, "schemas": [ { "type": "struct", "fields": [ { "id": 1, "name": "col_1", "type": "string", "required": true }, { "id": 2, "name": "col_2", "type": "string", "required": true } ], "schema-id": 0, "identifier-field-ids": [ 1 ] } ], "current-schema-id": 0, "partition-specs": [ { "spec-id": 0, "fields": [] } ], "default-spec-id": 0, "last-partition-id": 999, "properties": { "write.format.default": "parquet", "write.target-file-size-bytes": "134217728", "write.metadata.delete-after-commit.enabled": "true", "write.metadata.previous-versions-max": "5" }, "snapshots": [], "snapshot-log": [], "metadata-log": [], "sort-orders": [ { "order-id": 1, "fields": [ { "source-id": 2, "transform": "identity", "direction": "asc", "null-order": "nulls-first" } ] } ], "default-sort-order-id": 1, "refs": {}, "statistics": [], "format-version": 2, "last-sequence-number": 0 }And after the removal of the column (corrupted)
{ "location": "s3://my-bucket/jayce-test-again", "table-uuid": "c467f3f1-f0d3-4b1d-a1d4-d1981ec3bce2", "last-updated-ms": 1751474858863, "last-column-id": 2, "schemas": [ { "type": "struct", "fields": [ { "id": 1, "name": "col_1", "type": "string", "required": true }, { "id": 2, "name": "col_2", "type": "string", "required": true } ], "schema-id": 0, "identifier-field-ids": [ 1 ] }, { "type": "struct", "fields": [ { "id": 1, "name": "col_1", "type": "string", "required": true } ], "schema-id": 1, "identifier-field-ids": [ 1 ] } ], "current-schema-id": 1, "partition-specs": [ { "spec-id": 0, "fields": [] } ], "default-spec-id": 0, "last-partition-id": 999, "properties": { "write.format.default": "parquet", "write.target-file-size-bytes": "134217728", "write.metadata.delete-after-commit.enabled": "true", "write.metadata.previous-versions-max": "5" }, "snapshots": [], "snapshot-log": [], "metadata-log": [ { "metadata-file": "s3://my-bucket/jayce-test-again/metadata/00000-eec106a1-7c00-434e-9a95-fbe8df8f269a.metadata.json", "timestamp-ms": 1751474855599 } ], "sort-orders": [ { "order-id": 1, "fields": [ { "source-id": 2, "transform": "identity", "direction": "asc", "null-order": "nulls-first" } ] } ], "default-sort-order-id": 1, "refs": {}, "statistics": [], "format-version": 2, "last-sequence-number": 0 }geruh commentedon Jul 2, 2025
Hey @mwa28 nice find! Seems to be an issue with PyIceberg. The Java library throws a validation exception when dropping a column that is used for the sort order.
https://github.com/apache/iceberg/blob/main/core/src/test/java/org/apache/iceberg/TestSortOrder.java#L304-L314
jayceslesar commentedon Jul 2, 2025
@geruh thanks for linking -- I think we should look at that test suite and see what other operations throw errors and incorporate those into the test suite here! @mwa28 what do you think?
mwa28 commentedon Jul 2, 2025
That's actually really interesting to know !
Yes it seems on this file alone there are 7 occurrences of
assertThatThrownByand it would be much smarter to do it this way.geruh commentedon Jul 2, 2025
Currently, this behavior can also be observed with partitioning, where it's possible to drop a field used for partitioning and then define a PartitionSpec using a non-existent column name. A part of this fix can be to add validation during the construction of new table metadata to ensure that the schema includes all fields referenced in the sort order and partitioning.
We could potentially implement a check similar to the compatibility methods shown here:
https://github.com/apache/iceberg/blob/b38573dcfb4a5467a70c28573a2d39874718a2a1/core/src/main/java/org/apache/iceberg/TableMetadata.java#L1557
geruh commentedon Jul 10, 2025
Hi @mwa28, have you started working on this? It would be great to get it in before the next release. If not, I can take it up.
mwa28 commentedon Jul 11, 2025
Hello @geruh, no sorry I haven't had the time. Go ahead if you want, I would like to see it in the next release as well.
kevinjqliu commentedon Jul 25, 2025
as we have a more comprehensive set of features to add for validations, i want to defer this to the next release and not block the 0.10 release
gabeiglio commentedon Sep 1, 2025
@geruh wondering if you have started work on this? If not I'm happy to take this on. We have seen internally a few instances of this case. (Dropping source field from an active (non-void) partition spec)
geruh commentedon Sep 1, 2025
@gabeiglio yeah for sure!
Fokko commentedon Jan 25, 2026
I see that this issue is still referenced for 0.10 and it looks pretty important (since it potentially can brick tables). Should we follow up on the open PR by @gabeiglio ?
gabeiglio commentedon Jan 26, 2026
Updated the PR 👍🏽 @Fokko
Block schema field drop if it is reference by an active partition or …