alamb commented on code in PR #7997: URL: https://github.com/apache/arrow-rs/pull/7997#discussion_r2437175161
########## parquet/src/arrow/in_memory_row_group.rs: ########## @@ -0,0 +1,296 @@ +// 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::arrow::ProjectionMask; +use crate::arrow::array_reader::RowGroups; +use crate::arrow::arrow_reader::RowSelection; +use crate::column::page::{PageIterator, PageReader}; +use crate::errors::ParquetError; +use crate::file::metadata::ParquetMetaData; +use crate::file::page_index::offset_index::OffsetIndexMetaData; +use crate::file::reader::{ChunkReader, Length, SerializedPageReader}; +use bytes::{Buf, Bytes}; +use std::ops::Range; +use std::sync::Arc; + +/// An in-memory collection of column chunks +#[derive(Debug)] +pub(crate) struct InMemoryRowGroup<'a> { + pub(crate) offset_index: Option<&'a [OffsetIndexMetaData]>, + /// Column chunks for this row group + pub(crate) column_chunks: Vec<Option<Arc<ColumnChunkData>>>, + pub(crate) row_count: usize, + pub(crate) row_group_idx: usize, + pub(crate) metadata: &'a ParquetMetaData, +} + +/// What ranges to fetch for the columns in this row group +#[derive(Debug)] +pub(crate) struct FetchRanges { + /// The byte ranges to fetch + pub(crate) ranges: Vec<Range<u64>>, + /// If `Some`, the start offsets of each page for each column chunk + pub(crate) page_start_offsets: Option<Vec<Vec<u64>>>, +} + +impl InMemoryRowGroup<'_> { + /// Returns the byte ranges to fetch for the columns specified in + /// `projection` and `selection`. + pub(crate) fn fetch_ranges( + &self, + projection: &ProjectionMask, + selection: Option<&RowSelection>, + batch_size: usize, + cache_mask: Option<&ProjectionMask>, + ) -> FetchRanges { + let metadata = self.metadata.row_group(self.row_group_idx); + if let Some((selection, offset_index)) = selection.zip(self.offset_index) { + let expanded_selection = + selection.expand_to_batch_boundaries(batch_size, self.row_count); + + // If we have a `RowSelection` and an `OffsetIndex` then only fetch pages required for the + // `RowSelection` + let mut page_start_offsets: Vec<Vec<u64>> = vec![]; Review Comment: I looked into this -- the number of elements in the outer vec is (self.column_chunks().len() * self.columns) for all non null column chunks and columns included in the iterator. We could figure out the precise allocation by doing a first pass. I'll see what that looks like -- 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]
