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 1 commit
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
Next Next commit
Add ParquetRecordBatchReaderBuilder (#2427)
  • Loading branch information
tustvold committed Aug 12, 2022
commit aeee9f8048ac5a58a3f180e787fab42c1683d751
49 changes: 46 additions & 3 deletions parquet/src/arrow/array_reader/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,49 @@ impl RowGroupCollection for Arc<dyn FileReader> {
}
}

pub(crate) struct FileReaderRowGroupCollection {
reader: Arc<dyn FileReader>,
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 {
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 +210,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
Loading