yangshangqing95 opened a new issue, #17761:
URL: https://github.com/apache/iceberg/issues/17761

   ### Apache Iceberg version
   
   1.11.0 (latest release)
   
   ### Query engine
   
   None
   
   ### Please describe the bug 🐞
   
   ## Description
   
   The `metadata_log_entries` table derives `latest_*` fields from the current 
table history. After snapshots are expired, the current snapshot log may be 
truncated, causing historical metadata entries to incorrectly return `null` for 
snapshot details.
   
   ## Reproduction
   
   ```sql
   CREATE TABLE local.demo.metadata_log_bug (id BIGINT)
   USING iceberg;
   
   INSERT INTO local.demo.metadata_log_bug VALUES (1);
   INSERT INTO local.demo.metadata_log_bug VALUES (2);
   INSERT INTO local.demo.metadata_log_bug VALUES (3);
   
   CREATE TABLE local.demo.metadata_log_bug_before
   USING parquet
   AS SELECT * FROM local.demo.metadata_log_bug.metadata_log_entries;
   
   CALL local.system.expire_snapshots(
     table => 'local.demo.metadata_log_bug',
     snapshot_ids => ARRAY(<middle_snapshot_id>)
   );
   
   SELECT
     before.file,
     before.latest_snapshot_id AS snapshot_id_before,
     after.latest_snapshot_id AS snapshot_id_after
   FROM local.demo.metadata_log_bug_before before
   JOIN local.demo.metadata_log_bug.metadata_log_entries after
     ON before.file = after.file
   WHERE NOT (
     before.latest_snapshot_id <=> after.latest_snapshot_id
   );
   ```
   
   ## Current behavior
   
   Historical entries corresponding to expired or truncated snapshots return 
`null` for `latest_snapshot_id`, `latest_schema_id`, and 
`latest_sequence_number`.
   
   ## Expected behavior
   
   The `latest_*` fields should remain stable and be derived from the metadata 
file referenced by each entry.
   
   ### Willingness to contribute
   
   - [x] 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


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to