pub struct CoalesceRule { /* private fields */ }Expand description
Merges partitions whose memory_bytes falls below min_partition_bytes.
When coalescing is beneficial (i.e. the advised group count is smaller than
the current partition count), apply rewrites the physical plan by appending
a NodeOp::CoalescePartitions node that signals downstream operators to
merge the output into target_partitions partitions.
Implementations§
Source§impl CoalesceRule
impl CoalesceRule
Sourcepub fn new(min_partition_bytes: u64) -> Self
pub fn new(min_partition_bytes: u64) -> Self
Create a new CoalesceRule with the given minimum partition byte threshold.
Uses the default target_partition_bytes of 128 MiB and no parallelism
floor; see Self::with_min_partitions.
Sourcepub fn with_target_partition_bytes(self, target_partition_bytes: u64) -> Self
pub fn with_target_partition_bytes(self, target_partition_bytes: u64) -> Self
Set a custom target_partition_bytes (bytes per merged output partition).
Sourcepub fn target_partition_bytes(&self) -> u64
pub fn target_partition_bytes(&self) -> u64
Return the configured target_partition_bytes.
Sourcepub fn with_min_partitions(self, min_partitions: usize) -> Self
pub fn with_min_partitions(self, min_partitions: usize) -> Self
Never coalesce below min_partitions partitions.
Sizing partitions purely by bytes answers “how big should a partition
be” and never asks “how many workers are there”. A stage whose whole
output is under target_partition_bytes collapses to a single group,
so it runs as one task on one core — measured live on TPC-H q2 at
SF100, where four stages coalesced to 1 partition and the cluster sat
at one busy core per executor with eight of nine slots idle. Bytes were
small; the work over them was not, and coalescing cannot see that.
Callers pass the live slot count so the floor tracks the actual
cluster. This mirrors Spark’s coalescePartitions.parallelismFirst,
which shrinks the advisory partition size for the same reason.
The floor is advisory in one direction only: it never raises the partition count above what the stage already has, because coalescing may only merge.
Sourcepub fn min_partitions(&self) -> usize
pub fn min_partitions(&self) -> usize
Return the configured parallelism floor.
Sourcepub fn advise(&self, stats: &[RuntimeStats]) -> CoalesceAdvice
pub fn advise(&self, stats: &[RuntimeStats]) -> CoalesceAdvice
Compute coalesce advice from per-partition stats, without modifying the plan.
Partitions are sorted by memory_bytes (ascending) before grouping so
that all small partitions cluster together regardless of their original
execution order. Without sorting, a large partition sitting between two
small ones would prevent them from coalescing (Spark’s AQE sorts before
coalescing for the same reason). Each group of small partitions is
capped at target_partition_bytes. Large partitions are always singleton
groups.
Each group contains the original partition indices (not sorted indices), so callers can map groups back to the original execution order.
Example: [small(0), big(1), small(2)] → [[0,2], [1]] (2 groups)
vs. the old consecutive-only approach: [[0], [1], [2]] (3 groups, no gain)
Trait Implementations§
Source§impl AqeRule for CoalesceRule
impl AqeRule for CoalesceRule
Source§fn apply(
&self,
plan: &PhysicalPlan,
stats: &[RuntimeStats],
) -> Option<PhysicalPlan>
fn apply( &self, plan: &PhysicalPlan, stats: &[RuntimeStats], ) -> Option<PhysicalPlan>
Compute coalesce advice and, when beneficial, rewrite the plan.
When advise() produces fewer groups than the current partition count,
stamps coalesced_partition_count on the plan and appends a
NodeOp::CoalescePartitions node carrying the computed target count.
Auto Trait Implementations§
impl Freeze for CoalesceRule
impl RefUnwindSafe for CoalesceRule
impl Send for CoalesceRule
impl Sync for CoalesceRule
impl Unpin for CoalesceRule
impl UnsafeUnpin for CoalesceRule
impl UnwindSafe for CoalesceRule
Blanket Implementations§
impl<T> Allocation for T
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request