Skip to content

fix: disambiguate Iceberg scans that share a metadata_location - #5180

Merged
mbutrovich merged 2 commits into
apache:mainfrom
mbutrovich:disambiguate_iceberg_scans
Jul 31, 2026
Merged

fix: disambiguate Iceberg scans that share a metadata_location#5180
mbutrovich merged 2 commits into
apache:mainfrom
mbutrovich:disambiguate_iceberg_scans

Conversation

@mbutrovich

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

No linked issue. Found via TestMergeOnReadMerge#testSelfMerge failing on Iceberg 1.8.1 / Spark 3.4 CI in #4752.

Rationale for this change

PlanDataInjector keys a native Iceberg scan's planning data (schema, file scan tasks, pools) by the scan's metadata_location alone. 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/testSelfMergeWithCaching failing on Iceberg 1.8.1 / Spark 3.4 CI with CometNativeException: Column index N is out of bound once 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?

  • Add scan_hash_code to IcebergScanCommon (native/proto), set from Iceberg's own SparkScan.hashCode(), which already folds in pushed filters, snapshot, branch, and read schema.
  • IcebergPlanDataInjector.getKey, PlanDataInjector.findAllPlanData's Iceberg case, and CometIcebergNativeScanExec.doExecuteColumnar now key on (metadata_location, scan_hash_code) instead of metadata_location alone.

How are these changes tested?

  • New tests in PlanDataInjectorSuite construct two Iceberg scan operators sharing a metadata_location with different scan_hash_codes and assert each receives its own planning data rather than the other's.
  • Verified against the original regression: reproduced TestMergeOnReadMerge#testSelfMerge and testSelfMergeWithCaching failing on Iceberg 1.8.1 / Spark 3.4 without this fix, and passing with it applied.

@parthchandra parthchandra left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: getKey on an Iceberg op always returns Some, so .getOrElse(metadataLocation) never actually fires. probably safe to have it though.

@mbutrovich
mbutrovich merged commit d2a61bd into apache:main Jul 31, 2026
147 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants