Skip to content

fix(plugin-iceberg): Fix failed delete operation after expire_snapshots#28083

Draft
hantangwangd wants to merge 1 commit into
prestodb:masterfrom
hantangwangd:fix_failed_delete_after_expire_snapshots
Draft

fix(plugin-iceberg): Fix failed delete operation after expire_snapshots#28083
hantangwangd wants to merge 1 commit into
prestodb:masterfrom
hantangwangd:fix_failed_delete_after_expire_snapshots

Conversation

@hantangwangd

@hantangwangd hantangwangd commented Jun 29, 2026

Copy link
Copy Markdown
Member

Description

Motivation and Context

Impact

Test Plan

Contributor checklist

  • Please make sure your submission complies with our contributing guide, in particular code style and commit standards.
  • PR description addresses the issue accurately and concisely. If the change is non-trivial, a GitHub Issue is referenced.
  • Documented new properties (with its default value), SQL syntax, functions, or other functionality.
  • If release notes are required, they follow the release notes guidelines.
  • Adequate tests were added if applicable.
  • CI passed.
  • If adding new dependencies, verified they have an OpenSSF Scorecard score of 5.0 or higher (or obtained explicit TSC approval for lower scores).

Release Notes

== NO RELEASE NOTE ==

Summary by Sourcery

Ensure Iceberg deletes succeed after snapshots have been expired by validating row delta operations against the correct snapshot.

Bug Fixes:

  • Fix delete operations on Iceberg tables that fail after running the expire_snapshots procedure by validating from the appropriate snapshot.

Enhancements:

  • Expose getTimestampString helper for reuse in tests and procedures.

Tests:

  • Add a distributed Iceberg test verifying delete behavior after expire_snapshots retains only the newest snapshot.

@sourcery-ai

sourcery-ai Bot commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Reviewer's Guide

Adds snapshot validation to Iceberg delete operations after expire_snapshots and introduces tests to ensure deletes succeed using the latest snapshot, including exposing a timestamp helper for reuse.

Sequence diagram for Iceberg delete with snapshot validation

sequenceDiagram
    actor User
    participant IcebergAbstractMetadata
    participant IcebergTableHandle
    participant IcebergTable
    participant RowDelta

    User->>IcebergAbstractMetadata: finishDeleteWithOutput(session, handle)
    IcebergAbstractMetadata->>IcebergAbstractMetadata: getIcebergTable(session, handle.getSchemaTableName())
    IcebergAbstractMetadata->>IcebergTable: newRowDelta()
    IcebergAbstractMetadata->>IcebergTableHandle: getIcebergTableName()
    IcebergTableHandle-->>IcebergAbstractMetadata: getSnapshotId()
    IcebergAbstractMetadata->>IcebergTable: snapshot(snapshotId)
    IcebergTable-->>IcebergAbstractMetadata: Snapshot
    IcebergAbstractMetadata->>RowDelta: validateFromSnapshot(snapshotId)
    IcebergAbstractMetadata->>IcebergTableHandle: getBranchName()
    IcebergTableHandle-->>IcebergAbstractMetadata: branchName
    IcebergAbstractMetadata->>RowDelta: toBranch(branchName)
    IcebergAbstractMetadata-->>User: ConnectorOutputMetadata
Loading

File-Level Changes

Change Details Files
Validate Iceberg row delete operations against a specific snapshot when available to prevent failures after snapshot expiration.
  • Retrieve the Iceberg table for the delete handle and create a new RowDelta operation.
  • If the delete handle carries a snapshot id, switch the table context to that snapshot and set RowDelta.validateFromSnapshot using its snapshot id.
  • Preserve branch handling by routing RowDelta operations to the appropriate branch when branch information is present.
  • Keep existing delete completion and commit logic unchanged aside from the new validation step.
presto-iceberg/src/main/java/com/facebook/presto/iceberg/IcebergAbstractMetadata.java
Add an integration test that verifies delete operations succeed after snapshots are expired, using the plugin-iceberg expire_snapshots procedure.
  • Create a test table, insert initial data to create the first snapshot, then insert additional data to create a second snapshot.
  • Query the snapshots system table to assert that two snapshots exist and capture their snapshot ids.
  • Call system.expire_snapshots to expire older snapshots, retaining only the latest snapshot and verify via the snapshots table.
  • Execute a delete statement that targets rows based on column predicates and assert both the affected row count and the final table contents.
  • Ensure cleanup of the test table in a finally block.
presto-iceberg/src/test/java/com/facebook/presto/iceberg/IcebergDistributedTestBase.java
Expose a timestamp formatting utility for reuse in tests involving procedures that require timestamp arguments.
  • Change the visibility of getTimestampString from private to public so it can be reused outside its current test class.
  • Maintain the implementation that converts a UTC epoch millisecond value and a zone id into a formatted LocalDateTime string.
presto-iceberg/src/test/java/com/facebook/presto/iceberg/procedure/TestRemoveOrphanFilesProcedureBase.java

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@hantangwangd hantangwangd force-pushed the fix_failed_delete_after_expire_snapshots branch from 0d43e29 to a1e1ca5 Compare June 29, 2026 13:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant