Skip to content

Missing size rewrite in rewrite_table_path for delete file #12554

Closed

Description

@jotarada

Apache Iceberg version

1.8.1 (latest release)

Query engine

None

Please describe the bug 🐞

I think this a bug produced by 11555
While running rewrite_table_path and moving the data with a delete file i got the error

Error: TrinoExternalError(type=EXTERNAL, name=ICEBERG_CANNOT_OPEN_SPLIT,
 message="Error opening Iceberg split gs://buket/dir/data/id_trunc_2=3e/20250305_141051_06175_fjupa-4a03af2a-12c4-4f27-881b-bc15f459b13c.parquet 
 (offset=0, length=1187): Read 1187 tail bytes of file 
 gs://buket/dir/data/id_trunc_2=3e/20250305_141051_06175_fjupa-4a03af2a-12c4-4f27-881b-bc15f459b13c.parquet failed: Incorrect file size (1187) for file (end of stream not reached): gs://buket/dir/data/id_trunc_2=3e/20250305_141051_06175_fjupa-4a03af2a-12c4-4f27-881b-bc15f459b13c.parquet", query_id=20250317_151116_30308_u8j29)

Seems like this happens because the file 20250305_141051_06175_fjupa-4a03af2a-12c4-4f27-881b-bc15f459b13c.parquet was rewritten (is a delete file) but the info on the manifest was not

 "file_sequence_number": null,
  "data_file": {
    "content": 1,
    "file_path": "gs://buket/dir/data/id_trunc_2=3e/20250305_141051_06175_fjupa-4a03af2a-12c4-4f27-881b-bc15f459b13c.parquet",
    "file_format": "PARQUET",
    "partition": {
      "id_trunc_2": {
        "string": "3e"
      }
    },
    "record_count": 1,
    "file_size_in_bytes": 1187,
    "column_sizes": {
      "array": [
        {
          "key": 2147483546,
          "value": 199
        },
        {
          "key": 2147483545,
          "value": 27
        }
      ]
    },

1187 was the size of the parquet file before rewritten, the new size is 1799, but that value is not updated

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

  1. jotarada commented on Mar 17, 2025

    @jotarada
    Author

    @szehon-ho Can you have a look?

  2. dramaticlly commented on Mar 18, 2025

    @dramaticlly
    Contributor

    I can help take a look

  3. dramaticlly commented on Mar 28, 2025

    @dramaticlly
    Contributor
  4. szehon-ho commented on Mar 28, 2025

    @szehon-ho
    Member

    Yea I see, I guess its because the filePath will be different size in the rewritten delete file than the original delete file, so delete file size is wrong..

    Originally I had it so we write the delete file first and then delete manifest, but we changed it to make the writing delete file parallel. I already fixed the upper and lower bounds for delete manifest (https://github.com/apache/iceberg/blob/main/core/src/main/java/org/apache/iceberg/RewriteTablePathUtil.java#L396) , but the size is something I missed to fix (and is harder). We might need a large refactor to fix this (write the delete file first in one Spark job, and then delete manifest in another Spark job). @flyrain any thoughts?

  5. suisenkotoba commented on Apr 17, 2025

    @suisenkotoba

    Hi I am planning to use this procedure rewrite_table_path for iceberg table migration to other location. I am wondering if this bug is also happening in other iceberg versions

  6. adrians commented on Jul 24, 2025

    @adrians

    I found a similar problem with a table migrated using rewrite_table_path when querying using Impala.

    Basically Impala reads the manifest-list, gets the list of manifest-files and their sizes, and since the manifest-files were rewritten for the new path (don't have the same exact size as in the original table, as the file-contant has changed) and the manifest-list does not contain the updated sizes, Impala throws an error (the actual manifest-file sizes doesn't match the expected manifest-file size as declared in the manifest-list).

    Hive and Spark query-engines don't check the manifest-file length, but Impala does.

    Impala error-message:

    AnalysisException: Failed to load metadata for table: '...'
    CAUSED BY: TableLoadingException: Could not load table ... from catalog
    CAUSED BY: TException: TGetPartialCatalogObjectResponse(status:TStatus(status_code:GENERAL, error_msgs:[IcebergTableLoadingException: Error loading metadata for Iceberg table ...
    CAUSED BY: UncheckedIOException: Failed to open input stream for file ...-m2.avro:
    java.io.IOException:
    Expected to read 730455 bytes, but only 729310 bytes read.
    CAUSED BY:
    IOException:
    Expected to read 730455 bytes, but only 729310 bytes read.]), lookup_status:OK)
    

    It seems that the logical flow should be

    flowchart LR
    A["<b>Rewrite delete files</b><br>- Update paths for data-files"]-->B["<b>Rewrite the manifest files</b><br>- Update paths for data-files<br>- Update paths and sizes for delete-files"]-->C["<b>Rewrite the manifest-lists</b><br>- Update paths and sizes for manifest-files"]
    
    Loading
  7. github-actions commented on Jan 21, 2026

    @github-actions

    This issue has been automatically marked as stale because it has been open for 180 days with no activity. It will be closed in next 14 days if no further activity occurs. To permanently prevent this issue from being considered stale, add the label 'not-stale', but commenting on the issue is preferred when possible.

  8. github-actions commented on Feb 4, 2026

    @github-actions

    This issue has been closed because it has not received any activity in the last 14 days since being marked as 'stale'

  9. benjibuiltit commented on Feb 10, 2026

    @benjibuiltit

    I'm encountering this same issue executing rewrite_table_path procedure via Google Dataproc running Iceberg 1.10.1

    When I go to query the migrated data via Trino, I encounter the same issue @adrians reported regarding varying file lengths.

    Component Version
    Iceberg rewrite_table_path writer 1.10.1
    Trino Iceberg connector reader 1.9.1 (via Trino 476)
    Dataproc Runtime 3.0 (Spark 4.0, Java 17)
  10. mbutrovich commented on Feb 26, 2026

    @mbutrovich
    Contributor

    DataFusion Comet is now hitting this as well after a recent improvement to iceberg-rust to avoid a stat() call on delete files by using the file_size_in_bytes from the manifest (apache/iceberg-rust#2175). After a table rewrite, the file_size_in_bytes is wrong which causes the file reader to fail. I can work around it by having Comet issue a stat() but it's unfortunate to give up this optimization.

  11. steveloughran commented on Apr 10, 2026

    @steveloughran
    Contributor

    a lot of object store client skip that HEAD request, trusting the metadata. Looks like it doesn't hold here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions