fix: [branch-54] keep EmptyExec partition count intact across stage serialization (backport of #2062) - #2132
Merged
andygrove merged 1 commit intoJul 22, 2026
Conversation
…apache#2062) The adaptive planner's PropagateEmptyExecRule collapses a provably empty sub-plan into an EmptyExec that inherits the partition count of the node it replaces, and the scheduler sizes a stage's task count from that count. datafusion-proto encodes an EmptyExec as its schema alone, so the node decodes on the executor with a single partition. A stage built from a multi-partition EmptyExec therefore launches N tasks against a plan that can only execute partition 0, and every task above it fails with: Internal("Assertion failed: partition < self.partitions: EmptyExec invalid partition 1 (expected less than 1)") Rewrite multi-partition EmptyExec nodes into a round-robin RepartitionExec over a single-partition EmptyExec when a stage plan is built for the wire. The plan is equivalent and a RepartitionExec carries its partitioning through serialization. The rewrite runs after all physical optimizer rules, so no later rule can collapse it, and it is a no-op for the static planner, which never produces a multi-partition EmptyExec. Fixes the assertion for all 15 affected TPC-DS queries at SF1.
andygrove
marked this pull request as ready for review
July 22, 2026 02:56
phillipleblanc
approved these changes
Jul 22, 2026
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 #2062 to
branch-54. The issue it fixes is #2047.Rationale for this change
With adaptive execution enabled (
ballista.planner.adaptive.enabled=true), 15 TPC-DS queries fail on54.xwith:The adaptive planner's
PropagateEmptyExecRulecollapses a provably empty sub-plan into anEmptyExecthat inherits the partition count of the node it replaced, and the scheduler sizes a stage's task count from that count.datafusion-protoencodes anEmptyExecas its schema alone —EmptyExecNodehas no partitions field, and the decoder rebuilds the node withEmptyExec::new(schema), which defaults to one partition. So a stage built from anEmptyExecwith N partitions launches N tasks against a plan that, once it reaches the executor, can only execute partition 0. Every task above partition 0 then trips the assertion.What changes are included in this PR?
A clean cherry-pick of 0f6ec8c, unmodified.
Multi-partition
EmptyExecnodes are rewritten into a round-robinRepartitionExecover a single-partitionEmptyExecwhen a stage plan is built for the wire. The plan is equivalent, and aRepartitionExeccarries its partitioning through serialization. The rewrite runs after all physical optimizer rules, so no later rule can collapse it.Tests added by the original PR, all passing on the
branch-54base:serde::test::empty_exec_partition_count_is_lost_by_datafusion_proto— pins the underlyingdatafusion-protobehavior this works aroundplanner::test::multi_partition_empty_exec_is_rewritten_for_the_wireplanner::test::single_partition_empty_exec_is_left_aloneAre there any user-facing changes?
Queries that previously failed with the
EmptyExec invalid partitionassertion under AQE now run. No public API, config, or proto/wire format changes, so this is not a breaking change.The rewrite is a no-op for the static planner, which never produces a multi-partition
EmptyExec. I verified that explicitly: the TPC-H plan-stability suite passes with the goldens untouched, so static plan shapes are unaffected and only the adaptive path changes.cargo fmt --check, clippy onballista-core/ballista-schedulerwith--all-targets --all-features, and the fullballista-core+ballista-schedulertest suites are clean.