Repository navigation
Cherry-pick apache/datafusion#26790 - #225
Merged
alexanderbianchi merged 1 commit intoNov 24, 2026
Merged
alexanderbianchi merged 1 commit into
alexanderbianchi merged 1 commit into
Conversation
ahmed-mez
approved these changes
Nov 24, 2026
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## branch-55 #225 +/- ##
==========================================
Coverage 81.22% 81.22%
==========================================
Files 1112 1112
Lines 390954 391023 +69
Branches 390954 391023 +69
==========================================
+ Hits 317539 317604 +65
+ Misses 54446 54445 -1
- Partials 18969 18974 +5 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Base automatically changed from
alex.bianchi/cherry-pick/apache-pr-24389-20261124
to
branch-55
November 24, 2026 14:28
Related to apache#17261. Complements the fast path for equal schemas added in Benchmark coverage is reviewed in apache#26791. This PR is stacked on its benchmark-only commit `cfc6594b5`; the [optimization-only diff](apache/datafusion@cfc6594...c5f9d3e) contains the schema change and regression test. Constructing a union with unequal input schemas can take quadratic time in the number of children. The fallback merges every input's field metadata before checking whether that candidate field is nullable. With non-nullable fields, the same full merge is repeated for every child. Select the first nullable field (or the first field when none are nullable) before merging metadata. This makes the fallback linear in child count for a fixed number of fields and metadata entries per input. The shared helper also serves `InterleaveExec`. - Merge metadata once per output field, preserving the selected field, leftmost name, and existing metadata conflict precedence. - Add a test that constructs and executes unions with non-nullable inputs, first/middle/last nullable inputs, conflicting and distinct metadata keys, and checks output rows. Benchmarks use upstream `c18e5d974` plus the benchmark extension, Rust 1.99.1, `release-nonlto`, and an Apple M5 Pro. The table averages two interleaved runs per binary, with 20 Criterion samples per run. Schemas have 10 fields and two metadata entries per field. | Non-nullable schema case | Children | Upstream | Patched | Speedup | | --- | ---: | ---: | ---: | ---: | | Last child's metadata differs | 10 | 141 µs | 62 µs | 2.3× | | Last child's metadata differs | 100 | 9.24 ms | 0.66 ms | 14.1× | | Last child's metadata differs | 1,000 | 877 ms | 7.40 ms | 118.6× | | Field names differ | 10 | 140 µs | 60 µs | 2.3× | | Field names differ | 100 | 9.38 ms | 0.66 ms | 14.3× | | Field names differ | 1,000 | 866 ms | 7.36 ms | 117.6× | The controls with nullable fields or equal schemas at 4,000 children varied from -0.8% to +6.3% on this shared machine. Background builds affected some measurements, so the larger SQL cases with sorted unions were also checked in a tighter alternating sequence, with four runs per binary: | SQL planning case | Upstream | Patched | Change | | --- | ---: | ---: | ---: | | 50 columns, Int64 | 38.61 ms | 38.40 ms | -0.5% | | 50 columns, UInt64 | 139.48 ms | 139.63 ms | +0.1% | These results establish the constructor improvement independently of workloads. The original extended logical-planning benchmark only calls logical optimization and does not exercise this physical schema helper. To run the benchmark cases from apache#26791: ```sh cargo bench --profile release-nonlto -p datafusion-physical-plan --bench union_schema -- union_exec_try_new_non_nullable ``` Faster construction of unions and interleaves with unequal schemas and non-nullable fields. Schema behavior and public APIs are preserved. AI assistance: OpenAI Codex. (cherry picked from commit 7ca68cf) Ported to branch-55 (arrow 59): arrow::datatypes::Metadata does not exist there, so the new test builds field metadata as a HashMap<String, String>, and the unused Field import is dropped. (cherry picked from commit 0c03aae) (cherry picked from commit 83e6630)
alexanderbianchi
force-pushed
the
alex.bianchi/cherry-pick/apache-pr-26790-20261124
branch
from
November 24, 2026 14:28
7dce033 to
e46e643
Compare
alexanderbianchi
deleted the
alex.bianchi/cherry-pick/apache-pr-26790-20261124
branch
November 24, 2026 14:28
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?
Backport of apache#26790 to
branch-55.Rationale for this change
When UNION inputs differ and fields are non-nullable, constructing the output schema can repeat the same field metadata merge for many candidate inputs.
What changes are included in this PR?
Select the first nullable field (or first field if none are nullable) before merging metadata once per output column. Preserve metadata precedence; use a
HashMapfor the Arrow 59 test fixture. Stacked on #224 because it extends the preceding change'sunion_schemaimplementation and benchmark.Are these changes tested?
All 22
datafusion-physical-planunion::testspassed on this branch, including the metadata/nullability cases. The benchmark target compiled. Workspace formatting passed.Are there any user-facing changes?
Planning performance only; no change to output schemas or rows. No local timing claim.