pub struct RangePartitioning { /* private fields */ }Expand description
Physical range partitioning.
RangePartitioning describes an ordered key space with sampled split points.
orderingdefines the partitioning key and ordering.samplesare the maximum-resolution split points supplied by the caller.- The effective
split_pointsare derived from those samples for the selected partition count; the count itself issplit_points.len() + 1and is not stored separately.
Comparisons use the lexicographic order defined by ordering, including
ASC/DESC and null ordering. Samples must be strictly ordered according
to that ordering, and each sample must have one value per ordering
expression. See SplitPoint for the shared boundary convention.
When partition_count is smaller than Self::max_partition_count, the
samples are evenly down-sampled to derive the effective split points. This
allows planners to reduce or later restore the number of partitions without
losing the original distribution sample.
Like other user-specified data properties such as sortedness, if a source declares range partitioning, it is responsible for placing each row in the partition described by the split points. DataFusion will not validate this is upheld.
For a single range key:
ordering = [date ASC NULLS LAST]
split_points = [
(2022-01-01),
(2023-01-01),
]
partition 0: date before 2022-01-01
partition 1: date between 2022-01-01 (inclusive) and 2023-01-01 (exclusive)
partition 2: date at/after 2023-01-01The same model extends to compound keys.
For ordering = [time ASC, city ASC], split points are ordered
lexicographically by (time, city):
ordering = [time ASC NULLS LAST, city ASC NULLS LAST]
split_points = [
(2022, Allston),
(2023, Allston),
]
partition 0: keys before (2022, Allston)
partition 1: keys between (2022, Allston) and (2023, Allston)
partition 2: keys at/after (2023, Allston)Equality includes retained samples, since they determine which future scales
are possible. Use Self::has_same_layout to compare only the current layout.
Implementations§
Source§impl RangePartitioning
impl RangePartitioning
Sourcepub fn new(ordering: LexOrdering, split_points: Vec<SplitPoint>) -> Self
👎Deprecated since 56.0.0: Use RangePartitioning::try_new or try_new_with_samples instead
pub fn new(ordering: LexOrdering, split_points: Vec<SplitPoint>) -> Self
Use RangePartitioning::try_new or try_new_with_samples instead
Creates range partitioning metadata without validating split points.
Use Self::try_new to validate exact boundaries, or
Self::try_new_with_samples to retain additional samples for scaling up.
Sourcepub fn try_new(
ordering: LexOrdering,
split_points: Vec<SplitPoint>,
) -> Result<Self>
pub fn try_new( ordering: LexOrdering, split_points: Vec<SplitPoint>, ) -> Result<Self>
Creates range partitioning metadata and validates split point shape and ordering.
The exact boundaries are also the retained samples. This allows scaling
down and back up to the original count, but not beyond it. Prefer
Self::try_new_with_samples when additional sample points are available.
Sourcepub fn try_new_with_samples(
ordering: LexOrdering,
samples: Vec<SplitPoint>,
partition_count: usize,
) -> Result<Self>
pub fn try_new_with_samples( ordering: LexOrdering, samples: Vec<SplitPoint>, partition_count: usize, ) -> Result<Self>
Creates sample-backed range partitioning and validates the sample shape, ordering, and target partition count.
partition_count must be at least one and no larger than
samples.len() + 1. When it is smaller than that maximum, the samples
are evenly down-sampled to derive the effective split points.
For a single range key:
ordering = [key ASC NULLS LAST]
samples = [(10), (20), (30), (40), (50)]
partition_count = 3
split_points = [(20), (40)]
partition 0: key before 20
partition 1: key between 20 (inclusive) and 40 (exclusive)
partition 2: key at/after 40
scale(5): split_points = [(20), (30), (40), (50)]
scale(7): None (at most 6 partitions)Retain at least maximum_expected_partitions - 1 distinct samples to
support that many partitions later. Small inputs may not have enough
distinct values to do so.
Sourcepub fn ordering(&self) -> &LexOrdering
pub fn ordering(&self) -> &LexOrdering
Returns the ordering that defines the range key.
Sourcepub fn samples(&self) -> &[SplitPoint]
pub fn samples(&self) -> &[SplitPoint]
Returns the maximum-resolution sample points.
Sourcepub fn split_points(&self) -> &[SplitPoint]
pub fn split_points(&self) -> &[SplitPoint]
Returns the effective split points between partitions.
Sourcepub fn partition_count(&self) -> usize
pub fn partition_count(&self) -> usize
Returns the number of partitions.
Sourcepub fn max_partition_count(&self) -> usize
pub fn max_partition_count(&self) -> usize
Returns the largest partition count supported by the stored samples.
Sourcepub fn has_same_layout(&self, other: &Self) -> bool
pub fn has_same_layout(&self, other: &Self) -> bool
Whether two range partitionings have the same current key ordering and effective boundaries, irrespective of their retained samples.
This does not imply equal scaling capacity. In particular, a plan that combines inputs must not use this comparison to inherit one input’s samples for all inputs. Structural equality is required for that use case.
Sourcepub fn scale(&self, target_partitions: usize) -> Option<Self>
pub fn scale(&self, target_partitions: usize) -> Option<Self>
Returns this range partitioning scaled to target_partitions.
Scaling retains the original samples, so a range partitioning that was
scaled down can later be scaled back up to Self::max_partition_count.
Returns None when target_partitions is zero or the retained samples do
not support that many partitions. Insufficient samples are an expected
condition; callers should retain the layout or choose another partitioning.
This method changes metadata only; the caller must ensure that the actual
row distribution matches the resulting boundaries.
Sourcepub fn is_compatible_with_expressions(
&self,
exprs: &[Arc<dyn PhysicalExpr>],
schema: &Schema,
) -> bool
pub fn is_compatible_with_expressions( &self, exprs: &[Arc<dyn PhysicalExpr>], schema: &Schema, ) -> bool
Checks whether the types of the given expressions match the data types of the split points in this range partitioning.
Trait Implementations§
Source§impl Clone for RangePartitioning
impl Clone for RangePartitioning
Source§impl Debug for RangePartitioning
impl Debug for RangePartitioning
Source§impl Display for RangePartitioning
impl Display for RangePartitioning
Source§impl PartialEq for RangePartitioning
impl PartialEq for RangePartitioning
impl StructuralPartialEq for RangePartitioning
Auto Trait Implementations§
impl !RefUnwindSafe for RangePartitioning
impl !UnwindSafe for RangePartitioning
impl Forget for RangePartitioning
impl Freeze for RangePartitioning
impl Move for RangePartitioning
impl Send for RangePartitioning
impl Sync for RangePartitioning
impl Unpin for RangePartitioning
impl UnsafeUnpin for RangePartitioning
Blanket Implementations§
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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 more