← Back to Pull requests

fix(plugin-iceberg): Fix delete stats with row lineage predicates #28744

Merged
Joe-Abraham merged 2 files (137 lines) on Nov 02, 2026 17:56 UTC
View on GitHub
Joe-Abraham Joe-Abraham commented on Oct 30, 2026 02:44 UTC
Author

Description

On a table with equality deletes, a query that filters on _row_id or _last_updated_sequence_number failed during statistics calculation with:

Cannot find field '_row_id' in struct

The equality delete scan looks up its delete files using the data scan's predicate. Iceberg cannot bind row lineage columns against the table schema. The predicate now goes through IcebergUtil.getNonMetadataColumnConstraints first, which the data table statistics already do.

Part of #28743.

Motivation and Context

With ignore_stats_calculator_failures=false, these queries failed. With the default true, they were planned without statistics.

Impact

No public API or configuration changes.

Test Plan

The tests use AUTOMATIC join distribution so the planner computes statistics for the equality delete scan. They also set ignore_stats_calculator_failures=false so a statistics failure fails the query. SHOW STATS cannot test this: it rejects predicates the connector does not enforce, and lineage predicates are also filtered row by row.

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

    == RELEASE NOTES ==
    
    Iceberg Connector Changes
    * Fix statistics calculation failing for queries that filter on ``_row_id`` or ``_last_updated_sequence_number`` on tables with equality deletes.
    

    Summary by Sourcery

    Prevent row lineage predicates from breaking Iceberg query planning and statistics calculation for tables with equality deletes.

    Bug Fixes:

  • Fix Iceberg statistics calculation for queries filtering on row lineage metadata columns when equality deletes are present.
  • Tests:

  • Add coverage for row lineage predicates, deleted rows, and equality-delete statistics planning with statistics failures surfaced.
  • Diff: 137 lines (+126 / -11) across 2 files Reviewer: aditi-pandit Review duration: 5232m
    All Vouch review confidence checks passed
    Residual risk 0.05 = Change Risk (0.34) × (1 − Review Confidence (0.86)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.34 · 137 lines diff across 2 files
    0.34
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.76 · 5 substantive comment(s)
    0.76
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 50%
    85%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.295
    Real PR Conversation Timeline
    14 items
    sourcery-ai[bot] sourcery-ai[bot] commented on Oct 30, 2026 02:44 UTC
    Bot

    <!-- Generated by sourcery-ai[bot]: start review_guide -->

    Reviewer's Guide

    Fixes Iceberg equality-delete statistics planning for predicates on row-lineage metadata columns by removing those constraints before Iceberg delete-file binding, and adds cross-engine native/Java coverage across filter-pushdown modes, including strict statistics-failure scenarios.

    Sequence diagram for Iceberg equality-delete statistics planning

    sequenceDiagram
        participant Planner
        participant TableStatisticsMaker
        participant IcebergUtil
        participant Iceberg
    
        Planner->>TableStatisticsMaker: getEqualityDeleteTableSummary
        TableStatisticsMaker->>IcebergUtil: getNonMetadataColumnConstraints(intersection)
        IcebergUtil-->>TableStatisticsMaker: data-column constraints
        TableStatisticsMaker->>IcebergUtil: getDeleteFiles(snapshotId, constraints, partitionSpecId, equalityFieldIds, runtimeStats)
        IcebergUtil->>Iceberg: bind constraints to delete-file schema
        Iceberg-->>IcebergUtil: delete files
        IcebergUtil-->>TableStatisticsMaker: delete-file statistics
    

    Flow diagram for row-lineage predicate handling

    flowchart TD
        Query[Query filters on _row_id or _last_updated_sequence_number]
        Constraints[Data scan predicate with metadata constraints]
        Strip[IcebergUtil.getNonMetadataColumnConstraints]
        DeleteStats[Plan equality-delete statistics]
        Failure[Iceberg schema binding failure]
    
        Query --> Constraints
        Constraints --> Strip
        Strip --> DeleteStats
        Constraints -. metadata constraints retained .-> Failure
    

    File-Level Changes

    | Change | Details | Files |
    | ------ | ------- | ----- |
    | Strip row-lineage metadata constraints before planning equality-delete files. | <ul><li>Filter delete-file planning with non-metadata column constraints so Iceberg’s schema binder does not see _row_id or _last_updated_sequence_number.</li><li>Preserve data-scan predicate behavior while avoiding statistics-calculation failures for lineage filters.</li></ul> | presto-iceberg/src/main/java/com/facebook/presto/iceberg/TableStatisticsMaker.java |
    | Expand row-lineage coverage to validate equality deletes, statistics planning, and filter pushdown modes. | <ul><li>Parameterize row-lineage tests by pushdown_filter_enabled.</li><li>Add tests for deleted rows and EXPLAIN/statistics planning with lineage predicates under automatic join distribution and strict statistics failures.</li><li>Create Iceberg data and equality-delete files directly, and improve session-aware assertions and teardown helpers.</li></ul> | presto-iceberg/src/test/java/com/facebook/presto/iceberg/TestIcebergRowLineageBase.java |
    | Run the row-lineage suite on native workers with pushdown enabled and disabled, comparing results with Java workers. | <ul><li>Add native-side data-provider cases for both pushdown settings.</li><li>Compare native query results against a Java expected runner configured with pushdown disabled.</li></ul> | presto-native-tests/src/test/java/com/facebook/presto/nativetests/iceberg/TestIcebergV3RowLineage.java |

    Possibly linked issues

  • #28287: This PR is explicitly part 1 of #28287 and fixes its equality-delete statistics failure for lineage predicates.
  • ---

    <details>
    <summary>Tips and commands</summary>

    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

  • [Contact our support team](mailto:support@sourcery.ai) for questions or feedback.

  • Visit our documentation for detailed guides and information.

  • Keep in touch with the Sourcery team by following us on X/Twitter, LinkedIn or GitHub.
  • </details>

    <!-- Generated by sourcery-ai[bot]: end review_guide -->

    sourcery-ai[bot] sourcery-ai[bot] commented on Oct 30, 2026 02:46 UTC
    Reviewer

    Hey - I've reviewed your changes and they look great!

    ***

    <details>
    <summary>Sourcery is free for open source - if you like our reviews please consider sharing them ✨</summary>

  • X

  • Mastodon

  • LinkedIn

  • Facebook
  • </details>

    sourcery-ai[bot] sourcery-ai[bot] commented on Oct 30, 2026 07:49 UTC
    Bot

    Sorry @Joe-Abraham, you've used your own review budget of 250,000 diff characters for the last 7 days.

    You can request another review in 3 days and 22 hours by commenting @sourcery-ai review. Upgrade to get a review now.

    aditi-pandit aditi-pandit commented on code on Oct 30, 2026 16:03 UTC
    Code Review
    presto-iceberg/src/test/java/com/facebook/presto/iceberg/TestIcebergRowLineage.java:1
    @@ -366,4 +454,85 @@ private int completedSplitsFor(String sql)
                     .getQueryStats();
             return stats.getCompletedSplits();
         }
    +
    +    private void assertIdsForQuery(Session session, String sql, List<Integer> expectedIds)

    Please add a comment here that Id is the first column of the sql string.

    aditi-pandit aditi-pandit commented on code on Oct 30, 2026 16:04 UTC
    Code Review
    presto-iceberg/src/test/java/com/facebook/presto/iceberg/TestIcebergRowLineage.java:1
    @@ -366,4 +454,85 @@ private int completedSplitsFor(String sql)
                     .getQueryStats();
             return stats.getCompletedSplits();
         }
    +
    +    private void assertIdsForQuery(Session session, String sql, List<Integer> expectedIds)
    +    {
    +        assertEquals(sortedIdsOf(computeActual(session, sql)), ImmutableList.sortedCopyOf(expectedIds), "rows for \"" + sql + "\"");
    +    }
    +
    +    private static List<Integer> sortedIdsOf(MaterializedResult result)

    This isn't a particularly reusable function and seems to be used in only the above function. Please can you combine it.

    aditi-pandit aditi-pandit commented on code on Oct 30, 2026 16:09 UTC
    Code Review
    presto-iceberg/src/test/java/com/facebook/presto/iceberg/TestIcebergRowLineage.java:1
    @@ -366,4 +454,85 @@ private int completedSplitsFor(String sql)
                     .getQueryStats();
             return stats.getCompletedSplits();
         }
    +
    +    private void assertIdsForQuery(Session session, String sql, List<Integer> expectedIds)
    +    {
    +        assertEquals(sortedIdsOf(computeActual(session, sql)), ImmutableList.sortedCopyOf(expectedIds), "rows for \"" + sql + "\"");
    +    }
    +
    +    private static List<Integer> sortedIdsOf(MaterializedResult result)
    +    {
    +        List<Integer> ids = new ArrayList<>();
    +        for (MaterializedRow row : result.getMaterializedRows()) {
    +            ids.add((Integer) row.getField(0));
    +        }
    +        ids.sort(Integer::compare);
    +        return ids;
    +    }
    +
    +    private List<long[]> readIdAndLongColumn(Session session, String tableName, String column)
    +    {
    +        List<long[]> rows = new ArrayList<>();
    +        for (MaterializedRow row : computeActual(session, "SELECT id, \"" + column + "\" FROM " + tableName).getMaterializedRows()) {
    +            rows.add(new long[] {(Integer) row.getField(0), (Long) row.getField(1)});
    +        }
    +        return rows;
    +    }
    +
    +    private static long valueForId(List<long[]> rows, int id)
    +    {
    +        for (long[] row : rows) {
    +            if (row[0] == id) {
    +                return row[1];
    +            }
    +        }
    +        throw new AssertionError("id not found: " + id);
    +    }
    +
    +    private static List<DataFile> dataFiles(Table table)
    +            throws Exception
    +    {
    +        List<DataFile> files = new ArrayList<>();
    +        try (CloseableIterable<FileScanTask> tasks = table.newScan().includeColumnStats().planFiles()) {
    +            for (FileScanTask task : tasks) {
    +                files.add(task.file());
    +            }
    +        }
    +        return files;
    +    }
    +
    +    /**

    This comment is not needed.

    aditi-pandit aditi-pandit commented on Oct 30, 2026 16:13 UTC
    Reviewer

    @Joe-Abraham : The code comments are minor. Please also state that a v3 reader is expected to read v2 equality delete files for backwards compatibility

    Joe-Abraham Joe-Abraham commented on Oct 30, 2026 16:39 UTC
    Author

    @sourcery-ai summary

    aditi-pandit aditi-pandit commented on Oct 30, 2026 17:00 UTC
    Reviewer

    Thanks @Joe-Abraham

    aditi-pandit aditi-pandit commented on Oct 30, 2026 21:01 UTC
    Contributor

    @Joe-Abraham : Seems like there is a test failure as well

    TestNativeIcebergV3SpecFeaturesParquet.testEqualityDeletes failed; the other 850 tests passed. The key error was IO can not write FileMetaData(...) while writing the Parquet equality-delete file. This points to a code or test-data issue in Parquet metadata writing, not a runner or infrastructure failure.

    Joe-Abraham Joe-Abraham commented on Oct 31, 2026 02:35 UTC
    Author

    @aditi-pandit, it seems the test failure is CI issue, the rerun is passing https://github.com/prestodb/presto/actions/runs/41091788966/job/124402838234?pr=28744

    Joe-Abraham Joe-Abraham commented on Oct 31, 2026 02:39 UTC
    Author

    @aditi-pandit, I did a rebase to fix the conflict, could you please have a relook?

    aditi-pandit aditi-pandit approved these changes on Nov 02, 2026 17:56 UTC
    Approved Reviewer

    Thanks @Joe-Abraham

    Reviewers
    Assignees
    Joe-Abraham Joe-Abraham
    Labels
    risk: low confidence: 85.6% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 33.9% (LOW) · Higher = larger blast radius
    33.9%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 85.6% · Lower = rushed or shallow review
    85.6%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 4.9% · Safe to merge
    4.9%