Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ParquetRecordBatchReaderBuilder (#2427) #2435

Merged
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
53 changes: 50 additions & 3 deletions parquet/src/arrow/array_reader/mod.rs
Expand Up @@ -124,6 +124,53 @@ impl RowGroupCollection for Arc<dyn FileReader> {
}
}

pub(crate) struct FileReaderRowGroupCollection {
/// The underling file reader
reader: Arc<dyn FileReader>,
/// Optional list of row group indices to scan
row_groups: Option<Vec<usize>>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would help to document what usize means here -- I assume it is the index of the row group within the parquet file? And that if this is None, all row groups will be read?

}

impl FileReaderRowGroupCollection {
/// Creates a new [`RowGroupCollection`] from a `FileReader` and an optional
/// list of row group indexes to scan
pub fn new(reader: Arc<dyn FileReader>, row_groups: Option<Vec<usize>>) -> Self {
Self { reader, row_groups }
}
}

impl RowGroupCollection for FileReaderRowGroupCollection {
fn schema(&self) -> SchemaDescPtr {
self.reader.metadata().file_metadata().schema_descr_ptr()
}

fn num_rows(&self) -> usize {
match &self.row_groups {
None => self.reader.metadata().file_metadata().num_rows() as usize,
Some(row_groups) => {
let meta = self.reader.metadata().row_groups();
row_groups
.iter()
.map(|x| meta[*x].num_rows() as usize)
.sum()
}
}
}

fn column_chunks(&self, i: usize) -> Result<Box<dyn PageIterator>> {
let iterator = match &self.row_groups {
Some(row_groups) => FilePageIterator::with_row_groups(
i,
Box::new(row_groups.clone().into_iter()),
Arc::clone(&self.reader),
)?,
None => FilePageIterator::new(i, Arc::clone(&self.reader))?,
};

Ok(Box::new(iterator))
}
}

/// Uses `record_reader` to read up to `batch_size` records from `pages`
///
/// Returns the number of records read, which can be less than `batch_size` if
Expand Down Expand Up @@ -167,9 +214,9 @@ fn skip_records<V, CV>(
pages: &mut dyn PageIterator,
batch_size: usize,
) -> Result<usize>
where
V: ValuesBuffer + Default,
CV: ColumnValueDecoder<Slice = V::Slice>,
where
V: ValuesBuffer + Default,
CV: ColumnValueDecoder<Slice = V::Slice>,
{
let mut records_skipped = 0usize;
while records_skipped < batch_size {
Expand Down