tustvold commented on code in PR #1977: URL: https://github.com/apache/arrow-rs/pull/1977#discussion_r911963350
########## parquet/src/file/page_index/filer_offset_index.rs: ########## @@ -0,0 +1,293 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +use crate::file::page_index::range::{Range, RowRanges}; +use parquet_format::PageLocation; + +/// Returns the filtered offset index containing only the pages which are overlapping with rowRanges. +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct FilterOffsetIndex { + // read from parquet file which before the footer. + offset_index: Vec<PageLocation>, + + // use to keep needed page index. Review Comment: Why is this necessary? ########## parquet/src/file/serialized_reader.rs: ########## @@ -82,6 +91,27 @@ impl ChunkReader for Bytes { let start = start as usize; Ok(self.slice(start..start + length).reader()) } + + fn get_multi_range_read( + &self, + start_list: Vec<usize>, + length_list: Vec<usize>, + ) -> Result<Self::T> { + if start_list.len() != length_list.len() { + return Err(general_err!( + "Actual start_list size doesn't match the length_list size ({} vs {})", + start_list.len(), + length_list.len() + )); + } else { + let mut combine_vec: Vec<u8> = vec![]; + for (start, length) in start_list.into_iter().zip(length_list.into_iter()) { + combine_vec.extend(self.slice(start..start + length).to_vec()); + } + let reader = Bytes::copy_from_slice(combine_vec.as_slice()).reader(); Review Comment: This adds an additional copy of all the page bytes, which is definitely not ideal... ########## parquet/src/file/reader.rs: ########## @@ -48,6 +49,14 @@ pub trait ChunkReader: Length + Send + Sync { /// get a serialy readeable slice of the current reader /// This should fail if the slice exceeds the current bounds fn get_read(&self, start: u64, length: usize) -> Result<Self::T>; + + /// get a serially readable slice of the current reader + /// This should fail if the slice exceeds the current bounds + fn get_multi_range_read( Review Comment: As discussed on #1955 I'm not a fan of this, I would much rather the page reader reads pages, than skipping byte ranges behind its back. It also changes the semantics of how a column chunk is read, as it now buffers in memory an extra time ########## parquet/src/arrow/arrow_reader.rs: ########## @@ -88,10 +98,15 @@ impl ArrowReaderOptions { /// /// Set `skip_arrow_metadata` to true, to skip decoding this - pub fn with_skip_arrow_metadata(self, skip_arrow_metadata: bool) -> Self { - Self { - skip_arrow_metadata, - } + pub fn with_skip_arrow_metadata(mut self, skip_arrow_metadata: bool) -> Self { + self.skip_arrow_metadata = skip_arrow_metadata; + self Review Comment: ```suggestion { skip_arrow_metadata, ..self } ``` And same below ########## parquet/src/arrow/arrow_reader.rs: ########## @@ -130,17 +145,73 @@ impl ArrowReader for ParquetFileArrowReader { mask: ProjectionMask, batch_size: usize, ) -> Result<ParquetRecordBatchReader> { - let array_reader = build_array_reader( - self.file_reader - .metadata() - .file_metadata() - .schema_descr_ptr(), - Arc::new(self.get_schema()?), - mask, - Box::new(self.file_reader.clone()), - )?; + if self.options.selected_rows.is_some() { + let ranges = &self.options.selected_rows.as_ref().unwrap().clone(); Review Comment: ```suggestion if let Some(ranges) = self.options.selected_rows.as_ref() ``` ########## parquet/src/arrow/arrow_reader.rs: ########## @@ -68,11 +70,19 @@ pub trait ArrowReader { mask: ProjectionMask, batch_size: usize, ) -> Result<Self::RecordReader>; + + fn get_record_reader_by_columns_and_row_ranges( Review Comment: Do we need this, or is the ArrowReaderOptions sufficient? ########## parquet/src/file/metadata.rs: ########## @@ -55,8 +55,8 @@ use crate::schema::types::{ pub struct ParquetMetaData { file_metadata: FileMetaData, row_groups: Vec<RowGroupMetaData>, - page_indexes: Option<Vec<Index>>, - offset_indexes: Option<Vec<Vec<PageLocation>>>, + page_indexes: Option<Vec<Vec<Index>>>, Review Comment: ```suggestion /// Page index for all pages in each column chunk page_indexes: Option<Vec<Vec<Index>>>, ``` Or something like that, same for the below -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
