fix(plugin-iceberg): Fix delete stats with row lineage predicates #28744
<!-- 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
---
<details>
<summary>Tips and commands</summary>
Interacting with Sourcery
@sourcery-ai review on the pull request.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.@sourcery-ai anywhere in the pullrequest 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.@sourcery-ai summary anywhere inthe 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.
@sourcery-ai guide on the pullrequest to (re-)generate the reviewer's guide at any time.
@sourcery-ai resolve on thepull request to resolve all Sourcery comments. Useful if you've already
addressed all the comments and don't want to see them anymore.
@sourcery-ai dismiss on the pullrequest 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:
summary, the reviewer's guide, and others.
Getting Help
</details>
<!-- Generated by sourcery-ai[bot]: end review_guide -->
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.
Please add a comment here that Id is the first column of the sql string.
This isn't a particularly reusable function and seems to be used in only the above function. Please can you combine it.
This comment is not needed.
@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
@sourcery-ai summary
Thanks @Joe-Abraham
@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.
@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
@aditi-pandit, I did a rebase to fix the conflict, could you please have a relook?
Thanks @Joe-Abraham
aditi-pandit
Joe-Abraham
Description
On a table with equality deletes, a query that filters on
_row_idor_last_updated_sequence_numberfailed 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.getNonMetadataColumnConstraintsfirst, which the data table statistics already do.Part of #28743.
Motivation and Context
With
ignore_stats_calculator_failures=false, these queries failed. With the defaulttrue, 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=falseso a statistics failure fails the query.SHOW STATScannot test this: it rejects predicates the connector does not enforce, and lineage predicates are also filtered row by row.Contributor checklist
Release Notes
Summary by Sourcery
Prevent row lineage predicates from breaking Iceberg query planning and statistics calculation for tables with equality deletes.
Bug Fixes:
Tests: