Skip to main content

RowSelection

Struct RowSelection 

Source
pub struct RowSelection {
    inner: RowSelectionInner,
}
Expand description

RowSelection represents selecting a subset of rows when scanning a parquet file.

This is applied prior to reading column data, and can therefore be used to skip IO to fetch data into memory

A typical use-case would be using the PageIndex to filter out rows that don’t satisfy a predicate

Depending on the pattern of rows to be selected, RowSelection has either a bitmap or an RLE (RowSelector) based implementation.

§Example

use parquet::arrow::arrow_reader::{RowSelection, RowSelector};

let selectors = vec![
    RowSelector::skip(5),
    RowSelector::select(5),
    RowSelector::select(5),
    RowSelector::skip(5),
];

// Creating a selection will combine adjacent selectors
let selection: RowSelection = selectors.into();

let expected = vec![
    RowSelector::skip(5),
    RowSelector::select(10),
    RowSelector::skip(5),
];

let actual: Vec<RowSelector> = selection.into();
assert_eq!(actual, expected);

// you can also create a selection from consecutive ranges
let ranges = vec![5..10, 10..15];
let selection =
  RowSelection::from_consecutive_ranges(ranges.into_iter(), 20);
let actual: Vec<RowSelector> = selection.into();
assert_eq!(actual, expected);

// or directly from a packed bitmap, when the upstream producer already
// has one. The bitmap is kept as-is rather than run-length-encoded.
use arrow_buffer::BooleanBuffer;
let mask = BooleanBuffer::from(vec![true, false, true, true]);
let selection = RowSelection::from_boolean_buffer(mask);
assert_eq!(selection.row_count(), 3);

An RLE (RowSelector) backed RowSelection maintains the following invariants (they do not apply to the bitmap backed implementation):

Fields§

§inner: RowSelectionInner

Implementations§

Source§

impl RowSelection

Source

fn from_selectors(selectors: Vec<RowSelector>) -> Self

Not pub: unlike From<Vec<RowSelector>>, this performs no validation/normalization of the selectors (e.g. combining adjacent selectors), so callers must uphold the invariants themselves.

Source

pub fn from_boolean_buffer(mask: BooleanBuffer) -> Self

Create a RowSelection from a packed [BooleanBuffer].

Each set bit selects a row, each unset bit skips one. Unlike Self::from_filters, the bitmap is kept as-is rather than eagerly run-length-encoded. Self::iter materializes and caches the RLE form on first use; use MaskRunIter to stream the RLE form directly from the bitmap.

Source

fn from_mask_selection(mask: MaskSelection) -> Self

Source

pub fn as_mask(&self) -> Option<&BooleanBuffer>

Returns the underlying mask if this selection is mask-backed.

Public so that engines composing selections (e.g. DataFusion’s ParquetAccessPlan::into_overall_row_selection) can concatenate mask-backed selections without materialising the RLE form.

Source

pub(crate) fn into_inner(self) -> RowSelectionInner

Consume the selection and return its internal storage.

Source

pub(crate) fn auto_selection_strategy( &self, threshold: usize, ) -> RowSelectionStrategy

Choose the automatic materialisation strategy without converting between selector and mask backing.

Source

fn into_selectors_vec(self) -> Vec<RowSelector>

Source

pub fn from_filters(filters: &[BooleanArray]) -> Self

Creates a RowSelection from a slice of [BooleanArray]

§Panic

Panics if any of the [BooleanArray] contain nulls

Source

pub fn from_consecutive_ranges<I: Iterator<Item = Range<usize>>>( ranges: I, total_rows: usize, ) -> Self

Creates a RowSelection from an iterator of consecutive ranges to keep

Source

pub fn scan_ranges(&self, page_locations: &[PageLocation]) -> Vec<Range<u64>>

Given an offset index, return the byte ranges for all data pages selected by self

This is useful for determining what byte ranges to fetch from underlying storage

Note: this method does not make any effort to combine consecutive ranges, nor coalesce ranges that are close together. This is instead delegated to the IO subsystem to optimise, e.g. ObjectStore::get_ranges

Source

pub(crate) fn row_ranges_for_selected_pages( &self, page_locations: &[PageLocation], total_rows: usize, ) -> Vec<Range<usize>>

Returns the complete row ranges of the pages selected by Self::scan_ranges.

Source

pub fn split_off(&mut self, row_count: usize) -> Self

Splits off the first row_count from this RowSelection

Source

pub fn and_then(&self, other: &Self) -> Self

returns a RowSelection representing rows that are selected in both input RowSelections.

This is equivalent to the logical AND / conjunction of the two selections.

§Example

If N means the row is not selected, and Y means it is selected:

self:     NNNNNNNNNNNNYYYYYYYYYYYYYYYYYYYYYYNNNYYYYY
other:                YYYYYNNNNYYYYYYYYYYYYY   YYNNN

returned: NNNNNNNNNNNNYYYYYNNNNYYYYYYYYYYYYYNNNYYNNN
§Panics

Panics if other does not have a length equal to the number of rows selected by this RowSelection

Source

pub fn intersection(&self, other: &Self) -> Self

Compute the intersection of two RowSelection For example: self: NNYYYYNNYYNYN other: NYNNNNNNY

returned: NNNNNNNNYYNYN

Source

pub fn union(&self, other: &Self) -> Self

Compute the union of two RowSelection For example: self: NNYYYYNNYYNYN other: NYNNNNNNN

returned: NYYYYYNNYYNYN

Source

pub fn selects_any(&self) -> bool

Returns true if this RowSelection selects any rows

Source

pub(crate) fn trim(self) -> Self

Trims this RowSelection removing any trailing skips

Source

pub(crate) fn offset(self, offset: usize) -> Self

Applies an offset to this RowSelection, skipping the first offset selected rows

Source

pub(crate) fn limit(self, limit: usize) -> Self

Limit this RowSelection to only select limit rows

Source

pub fn iter(&self) -> RowSelectionIter<'_>

Returns a borrowed iterator yielding the RowSelectors for this selection.

Mask-backed selections materialize a Vec<RowSelector> cache on first call (one allocation, O(set_slices) work) so the iterator can hand out &RowSelector; the cache is not copied on clone. For single-pass walks over mask-backed selections, prefer streaming directly via Self::as_mask + MaskRunIter::new — that path is allocation-free and avoids populating the cache.

Source

pub fn row_count(&self) -> usize

Returns the number of selected rows

Source

pub fn skipped_row_count(&self) -> usize

Returns the number of de-selected rows

Source

pub(crate) fn expand_to_batch_boundaries( &self, batch_size: usize, total_rows: usize, ) -> Self

Expands the selection to align with batch boundaries. This is needed when using cached array readers to ensure that the cached data covers full batches.

Trait Implementations§

Source§

impl Clone for RowSelection

Source§

fn clone(&self) -> RowSelection

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 RowSelection

Source§

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

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

impl Default for RowSelection

Source§

fn default() -> RowSelection

Returns the “default value” for a type. Read more
Source§

impl Eq for RowSelection

Source§

impl From<BooleanBuffer> for RowSelection

Source§

fn from(mask: BooleanBuffer) -> Self

Converts to this type from the input type.
Source§

impl From<RowSelection> for Vec<RowSelector>

Source§

fn from(r: RowSelection) -> Self

Converts to this type from the input type.
Source§

impl From<RowSelection> for VecDeque<RowSelector>

Source§

fn from(r: RowSelection) -> Self

Converts to this type from the input type.
Source§

impl From<Vec<RowSelector>> for RowSelection

Source§

fn from(selectors: Vec<RowSelector>) -> Self

Converts to this type from the input type.
Source§

impl FromIterator<RowSelection> for RowSelection

Source§

fn from_iter<T: IntoIterator<Item = RowSelection>>(iter: T) -> Self

Concatenate multiple RowSelections in iterator order.

When every input is mask-backed the result stays mask-backed (BooleanBuffers are appended); otherwise falls back to flattening through the per-RowSelector form.

Source§

impl FromIterator<RowSelector> for RowSelection

Source§

fn from_iter<T: IntoIterator<Item = RowSelector>>(iter: T) -> Self

Creates a value from an iterator. Read more
Source§

impl PartialEq for RowSelection

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

Auto Trait Implementations§

Blanket Implementations§

§

impl<T> Allocation for T
where T: RefUnwindSafe + Send + Sync,

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
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
§

impl<T> Ungil for T
where T: Send,

§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V