Skip to content

fix: keep JSON-equivalent ARROW:extension:metadata across UNION - #26823

Open
ump45nose wants to merge 1 commit into
apache:mainfrom
ump45nose:fix/26810-union-extension-metadata-json
Open

ump45nose wants to merge 1 commit into
apache:mainfrom
ump45nose:fix/26810-union-extension-metadata-json

Conversation

@ump45nose

Copy link
Copy Markdown
Contributor

Important

Fork CI setup: For pull requests from a fork to main, enable workflows in your fork's Actions tab before you push.
See the fork CI setup guide.

Which issue does this PR close?

Rationale for this change

intersect_metadata_for_union keeps a metadata key only when every UNION branch has the same string value. Arrow stores extension-type metadata under ARROW:extension:metadata as a JSON document, and different writers (or even the same writer with different formatting) can serialize the same logical metadata with different whitespace or key order. Those branches then disagree as strings, so the key is dropped and the union field loses its extension metadata even though the JSON values are equivalent.

What changes are included in this PR?

  • Compare ARROW:extension:metadata as parsed JSON (via serde_json::Value) when intersecting metadata for UNION; other keys still require byte-identical strings.
  • Keep the first branch's serialization when the JSON values agree.
  • Unit tests for equivalent JSON kept and genuinely different JSON dropped.

Ideal longer-term would be a typed equality check on the decoded extension metadata (DFExtensionType), but there is no such API yet; JSON equality matches the repro in #26810.

What is the testing strategy for this PR?

  • cargo test -p datafusion-expr intersect_metadata --lib (covers the existing intersection cases plus extension_metadata_json_equivalent_kept and extension_metadata_json_different_dropped).

Are there any user-facing changes?

Bug fix only: UNION of columns whose ARROW:extension:metadata differs only in JSON formatting now retains that metadata. No public API change.

AI assistance

AI tooling helped draft the patch and tests; I reviewed the approach against #26810 and the existing string intersection logic, and ran the tests above.

intersect_metadata_for_union compared metadata values as raw strings, so
extension metadata that differed only in whitespace or key order was
dropped from the union field. Compare ARROW:extension:metadata as parsed
JSON so equivalent serializations agree.

Closes apache#26810.
@github-actions github-actions Bot added the logical-expr Logical plan and expressions label Oct 27, 2026
@alamb alamb added the Prolific Author author opened PRs or issues in more than 20 repositories in the last 30 days label Oct 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

logical-expr Logical plan and expressions Prolific Author author opened PRs or issues in more than 20 repositories in the last 30 days

Projects

None yet

Development

Successfully merging this pull request may close these issues.

intersect_metadata_for_union() is too strict for extension types with JSON metadata serialization

2 participants