Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions parquet/src/arrow/arrow_reader/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ use arrow_select::filter::filter_record_batch;
pub use filter::{ArrowPredicate, ArrowPredicateFn, RowFilter};
use selection::MaskCursor;
pub use selection::{
MaskRunIter, RowSelection, RowSelectionCursor, RowSelectionIter, RowSelectionPolicy,
RowSelector,
MaskRunIter, RowSelection, RowSelectionCursor, RowSelectionPolicy, RowSelector,
};
use std::fmt::{Debug, Formatter};
use std::sync::Arc;
Expand Down
11 changes: 6 additions & 5 deletions parquet/src/arrow/arrow_reader/selection/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ use boolean::{
pub(crate) use cursor::{LoadedRowRanges, MaskCursor, RowSelectionStrategy};
pub use cursor::{RowSelectionCursor, RowSelectionPolicy};
use ranges::{expand_to_batch_boundaries_from_selectors, scan_ranges_from_selectors};
pub use selector::{RowSelectionIter, RowSelector};
pub use selector::RowSelector;
use selector::{limit_selectors, offset_selectors, split_off_selectors};

/// [`RowSelection`] represents selecting a subset of rows
Expand Down Expand Up @@ -605,18 +605,19 @@ impl RowSelection {
}
}

/// Returns a borrowed iterator yielding the [`RowSelector`]s for this selection.
/// Returns an iterator over the [`RowSelector`]s for this
/// [`RowSelection`].
///
/// 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.
pub fn iter(&self) -> RowSelectionIter<'_> {
pub fn iter(&self) -> impl Iterator<Item = &RowSelector> {
match &self.inner {
RowSelectionInner::Selectors(s) => RowSelectionIter::new(s),
RowSelectionInner::Mask(m) => RowSelectionIter::new(m.selectors()),
RowSelectionInner::Selectors(s) => s.iter(),
RowSelectionInner::Mask(m) => m.selectors().iter(),
}
}

Expand Down
53 changes: 0 additions & 53 deletions parquet/src/arrow/arrow_reader/selection/selector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,59 +55,6 @@ impl RowSelector {
}
}

/// Borrowed iterator over the [`RowSelector`]s of a
/// [`RowSelection`](crate::arrow::arrow_reader::RowSelection).
#[derive(Debug)]
pub struct RowSelectionIter<'a>(std::slice::Iter<'a, RowSelector>);

impl<'a> RowSelectionIter<'a> {
pub(super) fn new(selectors: &'a [RowSelector]) -> Self {
Self(selectors.iter())
}
}

impl<'a> Iterator for RowSelectionIter<'a> {
type Item = &'a RowSelector;

#[inline]
fn next(&mut self) -> Option<Self::Item> {
self.0.next()
}

#[inline]
fn size_hint(&self) -> (usize, Option<usize>) {
self.0.size_hint()
}

#[inline]
fn count(self) -> usize {
self.0.count()
}

#[inline]
fn nth(&mut self, n: usize) -> Option<Self::Item> {
self.0.nth(n)
}

#[inline]
fn last(self) -> Option<Self::Item> {
self.0.last()
}

#[inline]
fn fold<B, F>(self, init: B, f: F) -> B
where
F: FnMut(B, Self::Item) -> B,
{
self.0.fold(init, f)
}
}

impl ExactSizeIterator for RowSelectionIter<'_> {}

// once it returns None, it will continue returning None
impl std::iter::FusedIterator for RowSelectionIter<'_> {}

/// Splits `selectors` at the first `row_count` rows, returning `(head, tail)`.
pub(super) fn split_off_selectors(
mut selectors: Vec<RowSelector>,
Expand Down
Loading