Skip to content
Open
Show file tree
Hide file tree
Changes from 21 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
31 changes: 7 additions & 24 deletions parquet/benches/arrow_statistics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,33 +226,16 @@ fn criterion_benchmark(c: &mut Criterion) {
.unwrap();

if data_page_row_count_limit.is_some() {
let column_page_index = reader
let page_index = reader
.metadata()
.column_index()
.expect("File should have column page indices");
.page_index()
.expect("File should have page indices");

let column_offset_index = reader
.metadata()
.offset_index()
.expect("File should have column offset indices");

let _ = converter.data_page_mins(
column_page_index,
column_offset_index,
&row_group_indices,
);
let _ = converter.data_page_maxes(
column_page_index,
column_offset_index,
&row_group_indices,
);
let _ = converter.data_page_null_counts(
column_page_index,
column_offset_index,
&row_group_indices,
);
let _ = converter.data_page_mins(page_index, &row_group_indices);
let _ = converter.data_page_maxes(page_index, &row_group_indices);
let _ = converter.data_page_null_counts(page_index, &row_group_indices);
let _ = converter.data_page_row_counts(
column_offset_index,
page_index,
row_groups,
&row_group_indices,
);
Expand Down
27 changes: 19 additions & 8 deletions parquet/src/arrow/arrow_reader/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1313,12 +1313,11 @@ impl<T: ChunkReader + 'static> ReaderPageIterator<T> {
fn next_page_reader(&self, rg_idx: usize) -> Result<SerializedPageReader<T>> {
let rg = self.metadata.row_group(rg_idx);
let column_chunk_metadata = rg.column(self.column_idx);
let offset_index = self.metadata.offset_index();
// `offset_index` may not exist and `i[rg_idx]` will be empty.
// To avoid `i[rg_idx][self.column_idx`] panic, we need to filter out empty `i[rg_idx]`.
let page_locations = offset_index
.filter(|i| !i[rg_idx].is_empty())
.map(|i| i[rg_idx][self.column_idx].page_locations.clone());
let page_locations = self
.metadata
.page_index()
.map(|i| i.page_locations(rg_idx, self.column_idx).cloned())

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this clone is unfortunate (it clones all the page locations into a new Vec) -- I realize it is what the previous code did, but I wonder if there is some way to avoid it

It may also be related to

Where @zhuqi-lucas and others have been looking for a way to load some but not all page indexes (or load them on demand, from a cache, etc).

Maybe it is time to sprinkle on some Arc 🤔

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Let me see what I can do here...tracing the page_locations down it looks like they are copied once again deep down in the page reader. Might be able to pass a reference here instead.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Where @zhuqi-lucas and others have been looking for a way to load some but not all page indexes (or load them on demand, from a cache, etc).

I think the new form will help with that...I envision a builder that starts out with empty vecs sized with num_row_groups and num_columns. Individual cells can then be populated based on what it needed for a given use. We can pop back and forth between page index and page index builder if need be.

.unwrap_or(None);
let total_rows = rg.num_rows() as usize;
let reader = self.reader.clone();

Expand Down Expand Up @@ -4686,7 +4685,19 @@ pub(crate) mod tests {
ArrowReaderOptions::new().with_page_index_policy(PageIndexPolicy::Required),
)
.unwrap();
assert!(!builder.metadata().offset_index().unwrap()[0].is_empty());
let page_index = builder
.metadata()
.page_index()
.expect("page index should be present");
let num_columns = builder.metadata().row_group(0).num_columns();
let offset_indexes = page_index.offset_indexes_for_rowgroup(0);
assert!(offset_indexes.is_some_and(|ois| ois.len() == num_columns));
let column_indexes = page_index.offset_indexes_for_rowgroup(0);
assert!(column_indexes.is_some_and(|cis| cis.len() == num_columns));
assert!(page_index.offset_index(0, 0).is_some());
assert!(page_index.column_index(0, 0).is_some());
assert!(page_index.page_locations(0, 0).is_some());
assert_eq!(page_index.num_data_pages(0, 0), Some(325));
let reader = builder.build().unwrap();
let batches = reader.collect::<Result<Vec<_>, _>>().unwrap();
assert_eq!(batches.len(), 8);
Expand All @@ -4703,7 +4714,7 @@ pub(crate) mod tests {
.unwrap();
// Although `Vec<Vec<PageLoacation>>` of each row group is empty,
// we should read the file successfully.
assert!(builder.metadata().offset_index().is_none());
assert!(builder.metadata().page_index().is_none());
let reader = builder.build().unwrap();
let batches = reader.collect::<Result<Vec<_>, _>>().unwrap();
assert_eq!(batches.len(), 1);
Expand Down
Loading
Loading