fix(plugin-iceberg): Ignore row lineage stats in Parquet and ORC #28746
<!-- Generated by sourcery-ai[bot]: start review_guide -->
Reviewer's Guide
The PR prevents Parquet row-group and ORC stripe pruning from using incomplete row-lineage statistics, safely removes lineage predicates from Iceberg metadata scans, and updates Java/native scan construction and extensive tests to preserve correct stored and inherited lineage behavior.
Sequence diagram for preserving inherited Iceberg row lineage rows
sequenceDiagram
participant Query
participant IcebergPageSourceProvider
participant ParquetORCReader
participant File
Query->>IcebergPageSourceProvider: getParquetTupleDomain()
IcebergPageSourceProvider->>IcebergPageSourceProvider: isRowLineageColumn()
IcebergPageSourceProvider->>ParquetORCReader: Read without row-lineage statistics predicates
ParquetORCReader->>File: Scan row groups or stripes
File-->>ParquetORCReader: Stored and inherited lineage values
ParquetORCReader-->>Query: Matching rows
File-Level Changes
| Change | Details | Files |
| ------ | ------- | ----- |
| Exclude row-lineage predicates from file-level statistics pruning while preserving their physical-value reads. | <ul><li>Add a shared isRowLineageColumn() check for _row_id and _last_updated_sequence_number.</li><li>Remove lineage domains from Parquet row-group and ORC stripe predicates so inherited values cannot be skipped.</li><li>Strip lineage constraints before Iceberg delete-file expression binding to avoid metadata-column failures.</li></ul> | presto-iceberg/src/main/java/com/facebook/presto/iceberg/IcebergColumnHandle.java<br/>presto-iceberg/src/main/java/com/facebook/presto/iceberg/IcebergPageSourceProvider.java<br/>presto-iceberg/src/main/java/com/facebook/presto/iceberg/IcebergUtil.java<br/>presto-iceberg/src/main/java/com/facebook/presto/iceberg/TableStatisticsMaker.java |
| Expand row-lineage coverage with mixed stored/inherited data and format-specific pruning scenarios. | <ul><li>Refactor shared tests to run with filter pushdown enabled or disabled and compare native results with the Java engine where applicable.</li><li>Add Parquet and ORC tests for predicates on inherited and stored lineage values, null checks, combined predicates, compaction, deletes, and statistics planning.</li><li>Add helpers that create V3 files, compaction rewrites, equality deletes, mixed lineage files, and direct Parquet/ORC test data.</li></ul> | presto-iceberg/src/test/java/com/facebook/presto/iceberg/TestIcebergRowLineage.java<br/>presto-iceberg/src/test/java/com/facebook/presto/iceberg/TestIcebergRowLineageBase.java<br/>presto-native-tests/src/test/java/com/facebook/presto/nativetests/iceberg/TestIcebergV3RowLineage.java |
| Ensure native Iceberg scans include projected lineage columns in physical data columns without incorrectly treating them as filter columns. | <ul><li>Pass TableScan assignments into connector table-handle conversion.</li><li>Track lineage handles separately from predicate handles and add their field IDs to the final data-column layout.</li><li>Preserve lineage filters when a column is both filtered and projected.</li></ul> | presto-native-execution/presto_cpp/main/connectors/IcebergPrestoToVeloxConnector.cpp<br/>presto-native-execution/presto_cpp/main/connectors/IcebergPrestoToVeloxConnector.h<br/>presto-native-execution/presto_cpp/main/connectors/PrestoToVeloxConnector.h<br/>presto-native-execution/presto_cpp/main/types/PrestoToVeloxQueryPlan.cpp |
| Add native connector tests for lineage column assignment and field-ID propagation. | <ul><li>Verify projected-only lineage columns are returned as data columns but absent from filter handles.</li><li>Verify filtered-and-projected lineage columns are included once with the correct Iceberg field ID.</li></ul> | presto-native-execution/presto_cpp/main/types/tests/PrestoToVeloxConnectorTest.cpp |
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 -->
🟡 Medium · Self-derived row IDs mask errors
When the Java test runs with consistently incorrect row-lineage values, in testLineagePredicateCombinedWithRegularColumn, evenRowIds is built from the same readIdAndRowId results used by the predicate at line 736, so incorrect but consistently read-and-filtered row IDs satisfy the assertion; the base class's engine comparison is a no-op.
Derive the expected row IDs independently from Iceberg file metadata and assert the projected values before using them in the predicate.
<details>
<summary>Prompt for AI agents</summary>
~~~markdown
In presto-iceberg/src/test/java/com/facebook/presto/iceberg/TestIcebergRowLineageBase.java at lines 724-728:
Self-derived row IDs mask errors
When the Java test runs with consistently incorrect row-lineage values, in testLineagePredicateCombinedWithRegularColumn, evenRowIds is built from the same readIdAndRowId results used by the predicate at line 736, so incorrect but consistently read-and-filtered row IDs satisfy the assertion; the base class's engine comparison is a no-op.
Derive the expected row IDs independently from Iceberg file metadata and assert the projected values before using them in the predicate.
~~~
</details>
Hey - I've found 1 issue
<details>
<summary>Prompt for AI Agents</summary>
~~~markdown
Please address the comments from this code review:
Individual Comments
Comment 1
<location path="presto-iceberg/src/test/java/com/facebook/presto/iceberg/TestIcebergRowLineageBase.java" line_range="724-728" />
<code_context>
+ long rowId1 = valueForId(idAndRowId, 1);
+ long sequenceNumber2 = valueForId(readIdAndSequenceNumber(session, tableName), 2);
+ ImmutableList.Builder<Integer> evenRowIds = ImmutableList.builder();
+ for (long[] row : idAndRowId) {
+ if (row[1] % 2 == 0) {
+ evenRowIds.add((int) row[0]);
+ }
+ }
+
</code_context>
<issue_to_address>
Self-derived row IDs mask errors
When the Java test runs with consistently incorrect row-lineage values, in testLineagePredicateCombinedWithRegularColumn, evenRowIds is built from the same readIdAndRowId results used by the predicate at line 736, so incorrect but consistently read-and-filtered row IDs satisfy the assertion; the base class's engine comparison is a no-op.
Derive the expected row IDs independently from Iceberg file metadata and assert the projected values before using them in the predicate.
</issue_to_address>
~~~
</details>
***
<details>
<summary>Sourcery is free for open source - if you like our reviews please consider sharing them ✨</summary>
</details>
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.
Same comments from previous PR apply.
This is more understandable as MixedLineageTuple
Thanks @Joe-Abraham
Thank you @aditi-pandit
aditi-pandit
Joe-Abraham
Description
A query filtering on
_row_idor_last_updated_sequence_numbercould miss rows that inherit their value from the data file. For example, a compacted file can hold row 1 with a stored_row_idof 0 and row 2 with a null_row_idthat inherits 3. The row group statistics cover only the stored value 0, soskipped the row group and returned no rows.
Row lineage columns are now left out of the predicates handed to the Parquet and ORC readers, so their statistics no longer prune row groups or stripes.
Motivation and Context
Files that mix stored and inherited lineage values come from compaction or from an UPDATE/MERGE that preserves row lineage. Filtering on a lineage column over such a file silently dropped rows.
Impact
No public API or configuration changes. Predicates on row lineage columns no longer prune Parquet row groups or ORC stripes.
Test Plan
The tests build a mixed file through the Iceberg API and commit it as an overwrite. Parquet uses Iceberg's writer; ORC uses the ORC writer from hive-apache with Iceberg field ids. The mixed-file assertions on
_last_updated_sequence_numberalso need the split pruning fix, so they come in the next PR.Contributor checklist
Release Notes
Summary by Sourcery
Fix Iceberg row lineage filtering so inherited values are not skipped by Parquet or ORC statistics-based pruning.
Bug Fixes:
_row_idand_last_updated_sequence_numbervalues return the expected rows.Enhancements:
Tests: