fix: disambiguate Iceberg scans that share a metadata_location - #5180
Merged
Conversation
parthchandra
approved these changes
Jul 31, 2026
parthchandra
left a comment
Contributor
There was a problem hiding this comment.
Awesome fix Matt. Thank you!
Approved pending ci.
| // Key by the same (metadata_location, scan_hash_code) pair PlanDataInjector.injectPlanData | ||
| // looks up via IcebergPlanDataInjector.getKey (see the scan_hash_code field comment in | ||
| // operator.proto for why metadata_location alone cannot identify a scan). | ||
| val injectorKey = IcebergPlanDataInjector.getKey(nativeOp).getOrElse(metadataLocation) |
Contributor
There was a problem hiding this comment.
nit: getKey on an Iceberg op always returns Some, so .getOrElse(metadataLocation) never actually fires. probably safe to have it though.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Which issue does this PR close?
No linked issue. Found via
TestMergeOnReadMerge#testSelfMergefailing on Iceberg 1.8.1 / Spark 3.4 CI in #4752.Rationale for this change
PlanDataInjectorkeys a native Iceberg scan's planning data (schema, file scan tasks, pools) by the scan'smetadata_locationalone. A query can read the same table twice within one native plan (a self-join, or a self-merge's target and source reads) via two scans that are logically different: different projected columns, or different pushed filters. Both scans compute the same key, so one scan's serialized data silently overwrites the other's, and the wrong data gets injected into one of the two scan operators.This surfaced as
TestMergeOnReadMerge#testSelfMerge/testSelfMergeWithCachingfailing on Iceberg 1.8.1 / Spark 3.4 CI withCometNativeException: Column index N is out of boundonce metadata columns (_file,_pos,_spec_id,_partition) stopped forcing a fallback to Spark. The underlying collision is not specific to that feature: any two native Iceberg scans of the same table with different pushed filters or projections, landing in one native plan without an intervening shuffle, can hit it.What changes are included in this PR?
scan_hash_codetoIcebergScanCommon(native/proto), set from Iceberg's ownSparkScan.hashCode(), which already folds in pushed filters, snapshot, branch, and read schema.IcebergPlanDataInjector.getKey,PlanDataInjector.findAllPlanData's Iceberg case, andCometIcebergNativeScanExec.doExecuteColumnarnow key on(metadata_location, scan_hash_code)instead ofmetadata_locationalone.How are these changes tested?
PlanDataInjectorSuiteconstruct two Iceberg scan operators sharing ametadata_locationwith differentscan_hash_codes and assert each receives its own planning data rather than the other's.TestMergeOnReadMerge#testSelfMergeandtestSelfMergeWithCachingfailing on Iceberg 1.8.1 / Spark 3.4 without this fix, and passing with it applied.