Skip to main content

RangePartitioning

Struct RangePartitioning 

Source
pub struct RangePartitioning { /* private fields */ }
Expand description

Physical range partitioning.

RangePartitioning describes an ordered key space with sampled split points.

  • ordering defines the partitioning key and ordering.
  • samples are the maximum-resolution split points supplied by the caller.
  • The effective split_points are derived from those samples for the selected partition count; the count itself is split_points.len() + 1 and 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-01

The 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

Source

pub fn new(ordering: LexOrdering, split_points: Vec<SplitPoint>) -> Self

👎Deprecated since 56.0.0:

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.

Source

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.

Source

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.

Source

pub fn ordering(&self) -> &LexOrdering

Returns the ordering that defines the range key.

Source

pub fn samples(&self) -> &[SplitPoint]

Returns the maximum-resolution sample points.

Source

pub fn split_points(&self) -> &[SplitPoint]

Returns the effective split points between partitions.

Source

pub fn partition_count(&self) -> usize

Returns the number of partitions.

Source

pub fn max_partition_count(&self) -> usize

Returns the largest partition count supported by the stored samples.

Source

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.

Source

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.

Source

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.

Source

pub fn adapt( &self, exprs: &[Arc<dyn PhysicalExpr>], schema: &Schema, ) -> Option<Self>

Adapts this range partitioning to the given expressions, preserving split points and sort options. Returns None if exprs count doesn’t match ordering length or expression types don’t match split points.

Trait Implementations§

Source§

impl Clone for RangePartitioning

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for RangePartitioning

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for RangePartitioning

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for RangePartitioning

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for RangePartitioning

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.