fix(native): Return stored row lineage values for projected columns #28745
<!-- Generated by sourcery-ai[bot]: start review_guide -->
Reviewer's Guide
Fixes native Iceberg row-lineage projections by carrying assignment-only metadata columns into Velox data-column metadata with correct field IDs, allowing stored values to be read consistently with filtered queries; the PR also broadens shared native/Java coverage and removes metadata predicates before equality-delete statistics planning.
Sequence diagram for native Iceberg row-lineage projection handling
sequenceDiagram
participant Scan as TableScanNode
participant Plan as VeloxQueryPlanConverter
participant Connector as IcebergPrestoToVeloxConnector
participant Reader as VeloxIcebergReader
Scan->>Plan: toVeloxQueryPlan()
Plan->>Connector: toVeloxTableHandle(tableHandle, assignments, exprConverter, typeParser)
Connector->>Connector: toIcebergColumnHandle(column)
Connector->>Reader: Build finalDataColumns with lineage field IDs
Reader-->>Scan: Return stored _row_id or _last_updated_sequence_number values
File-Level Changes
| Change | Details | Files |
| ------ | ------- | ----- |
| Pass projected scan assignments into native connector table-handle conversion and preserve requested Iceberg row-lineage columns as data columns. | <ul><li>Added an assignment-aware table-handle conversion overload with a default fallback for other connectors.</li><li>Collected row-lineage handles from both predicates and scan assignments, deduplicating columns while keeping projected-only lineage columns out of filter columns.</li><li>Populated lineage data-column field IDs so Velox can read stored physical values instead of synthesizing inherited values.</li></ul> | presto-native-execution/presto_cpp/main/connectors/PrestoToVeloxConnector.h<br/>presto-native-execution/presto_cpp/main/connectors/IcebergPrestoToVeloxConnector.h<br/>presto-native-execution/presto_cpp/main/connectors/IcebergPrestoToVeloxConnector.cpp<br/>presto-native-execution/presto_cpp/main/types/PrestoToVeloxQueryPlan.cpp |
| Add focused native connector conversion coverage for projected and filtered row-lineage columns. | <ul><li>Verify projected _row_id and _last_updated_sequence_number columns receive Iceberg field IDs without becoming filter columns.</li><li>Verify a lineage column present in both predicate and projection is represented once and remains a filter column.</li></ul> | presto-native-execution/presto_cpp/main/types/tests/PrestoToVeloxConnectorTest.cpp |
| Expand shared Iceberg row-lineage tests to validate stored values, inherited values, predicate behavior, deletes, statistics, and split pruning across workers. | <ul><li>Moved Java row-lineage predicate and compaction tests into the shared base and parameterized them for filter pushdown.</li><li>Added projection-versus-filter consistency coverage for stored lineage values, plus stored/inherited _row_id predicates and mixed regular-column predicates.</li><li>Added equality-delete and statistics-planning coverage, while retaining V2, compaction, split-pruning, and disjoint-range scenarios.</li><li>Refactored test helpers to run with explicit sessions, compare native results with the Java engine, and create physical Iceberg files containing lineage values.</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 |
| Prevent metadata-column predicates from reaching Iceberg equality-delete file expression binding. | <ul><li>Strip metadata-column constraints before requesting equality delete files, avoiding Iceberg expression binder failures for lineage predicates.</li></ul> | presto-iceberg/src/main/java/com/facebook/presto/iceberg/TableStatisticsMaker.java |
Possibly linked issues
_row_id and _last_updated_sequence_number, directly implementing and correcting row lineage read support tracked by the issue.---
<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 -->
🟠 High · Lineage-only projections miss stored values
When a query projects only _row_id or _last_updated_sequence_number and the layout has no regular data columns, the lineage-column loop is skipped, leaving finalDataColumns unset, so the reader cannot load stored lineage fields and returns synthesized values instead.
Build finalDataColumns when either regular data columns or requested lineage columns are present.
<details>
<summary>Prompt for AI agents</summary>
~~~markdown
In presto-native-execution/presto_cpp/main/connectors/IcebergPrestoToVeloxConnector.cpp at line 242:
Lineage-only projections miss stored values
When a query projects only _row_id or _last_updated_sequence_number and the layout has no regular data columns, the lineage-column loop is skipped, leaving finalDataColumns unset, so the reader cannot load stored lineage fields and returns synthesized values instead.
Build finalDataColumns when either regular data columns or requested lineage columns are present.
~~~
</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-native-execution/presto_cpp/main/connectors/IcebergPrestoToVeloxConnector.cpp" line_range="242" />
<code_context>
+ for (const auto& handle : lineageColumnHandles) {
+ if (std::find(names.begin(), names.end(), handle->name()) ==
+ names.end()) {
</code_context>
<issue_to_address>
Lineage-only projections miss stored values
When a query projects only _row_id or _last_updated_sequence_number and the layout has no regular data columns, the lineage-column loop is skipped, leaving finalDataColumns unset, so the reader cannot load stored lineage fields and returns synthesized values instead.
Build finalDataColumns when either regular data columns or requested lineage columns are present.
</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 6 days and 19 hours by commenting @sourcery-ai review. Upgrade to get a review now.
This comment isn't needed.
Can you take the hard-coded values"2", "two" as parameters to this function ?
All these functions have rows with 2 columns: id and value. So they are not generic. Please can you change the names and add a comment reflecting that.
Can you search if we have any generic function in the code base for this ?
sortedIds can be a local function.
Thanks @Joe-Abraham. Have bunch of cleanup comments for your test code.
Thanks @aditi-pandit, I have addressed your feedback, can you please have a relook?
Sourcery's one finding (lineage-only projections with no regular data columns) doesn't apply. dataColumns is the table's schema columns, not the projection, so it is non-empty for any real table. Sourcery's summary also mentions a TableStatisticsMaker change that is not in the final file list, so that part is stale.
Thanks @Joe-Abraham
aditi-pandit
Joe-Abraham
Description
On native workers, a query that reads
_row_idor_last_updated_sequence_numberwithout filtering on it returned inherited values. For example:SELECT id, "_row_id" FROM t
returned
first_row_idplus the row's position, even for rows that store their own_row_id. Compaction and row-preserving UPDATE or MERGE write such rows. The same query with a filter on_row_idreturned the stored values.The reader returns stored values only for lineage columns in the table handle's data columns. The Iceberg connector added them there only when a predicate used them.
PrestoToVeloxConnector::toVeloxTableHandlenow has an overload that receives the scan's column assignments. The Iceberg connector uses it to add projected lineage columns to the data columns, with their field IDs. Projected columns stay out of the filter columns.The Velox side of the fix, which applies row lineage filters after inherited values are filled in, is facebookincubator/velox#18435. The pinned Velox commit already includes it.
Motivation and Context
On native workers, a query that projected a row lineage column returned different values from the same query filtered on that column.
Impact
No public API or configuration changes.
Test Plan
The shared row lineage tests in
TestIcebergRowLineageBasenow takepushdown_filter_enabledas a parameter.TestIcebergV3RowLineagein presto-native-tests runs them on native workers with pushdown on and off. It compares each query with the same query on Java workers, which run with pushdown off.Contributor checklist
Release Notes
Summary by Sourcery
Return stored Iceberg row-lineage values consistently for native projections and predicates.
Bug Fixes:
_row_idand_last_updated_sequence_numbervalues when lineage columns are projected without predicates.Enhancements:
Tests: