alamb commented on code in PR #11330:
URL: https://github.com/apache/arrow-rs/pull/11330#discussion_r4169905362
##########
parquet/src/arrow/push_decoder/reader_builder/mod.rs:
##########
@@ -178,6 +180,10 @@ pub(crate) struct RowGroupReaderBuilder {
/// The underlying data store
buffers: PushBuffers,
+
+ /// What each decoding stage fetches. Kept here because the filter is
+ /// moved out of the builder while a row group is decoded.
+ stages: Arc<StageSchedule>,
Review Comment:
Why is this Arc'd when the rest of the fields are not? It seems like the Arc
just adds overhead 🤔
##########
parquet/src/arrow/in_memory_row_group.rs:
##########
@@ -205,6 +175,122 @@ impl InMemoryRowGroup<'_> {
}
}
+/// The leaf columns in `projection` that are not yet read, in column order.
+///
+/// A decoding stage of a row group does not fetch a column that an earlier
+/// stage of the same row group read.
+pub(crate) fn columns_to_fetch<'a>(
+ projection: &'a ProjectionMask,
+ num_columns: usize,
+ is_read: impl Fn(usize) -> bool + 'a,
+) -> impl Iterator<Item = usize> + 'a {
+ (0..num_columns).filter(move |&idx| projection.leaf_included(idx) &&
!is_read(idx))
+}
+
+/// The selection that [`InMemoryRowGroup::fetch_ranges`] uses to choose the
+/// pages of column `idx`: `expanded_selection` (the selection expanded to
+/// batch boundaries) if `cache_mask` includes the column, else `selection`.
+pub(crate) fn column_selection<'a>(
+ selection: Option<&'a RowSelection>,
+ expanded_selection: Option<&'a RowSelection>,
+ cache_mask: Option<&ProjectionMask>,
+ idx: usize,
+) -> Option<&'a RowSelection> {
+ match expanded_selection {
+ Some(expanded) if cache_mask.is_some_and(|mask|
mask.leaf_included(idx)) => Some(expanded),
+ _ => selection,
+ }
+}
+
+/// What [`InMemoryRowGroup::fetch_ranges`] fetches for one column chunk.
+///
+/// This is the one place that decides which bytes of a column chunk are
+/// requested, so other users of this rule cannot differ from the decoder.
+#[derive(Debug, Clone, PartialEq, Eq)]
+pub(crate) enum ColumnFetch<'a> {
Review Comment:
this is a nice encapsulation
##########
parquet/src/arrow/push_decoder/reader_builder/stages.rs:
##########
@@ -0,0 +1,91 @@
+// 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.
+
+//! [`StageSchedule`]: what each decoding stage of a row group fetches.
+
+use crate::arrow::ProjectionMask;
+
+/// A decoding stage of a row group.
+///
+/// The decoder evaluates the [`RowFilter`] predicates in order, then decodes
+/// the output columns.
+///
+/// [`RowFilter`]: crate::arrow::arrow_reader::RowFilter
+#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
+pub(crate) enum Stage {
+ /// Evaluation of the predicate at this index in the `RowFilter`.
+ Predicate(usize),
+ /// Decoding of the output columns.
+ Projection,
+}
+
+/// The columns that each decoding stage of a row group fetches.
+///
+/// A stage does not fetch a column that an earlier stage of the same row
+/// group read (see [`columns_to_fetch`]).
+///
+/// [`columns_to_fetch`]: crate::arrow::in_memory_row_group::columns_to_fetch
+#[derive(Debug)]
+pub(crate) struct StageSchedule {
+ /// Columns in the output.
+ projection: ProjectionMask,
+ /// Columns each predicate reads, in evaluation order.
+ predicate_projections: Vec<ProjectionMask>,
+ /// Predicate columns whose decoded values are cached for the output, if
+ /// any.
+ cache_projection: Option<ProjectionMask>,
+}
+
+/// What one decoding stage fetches.
+#[derive(Debug, Clone, Copy)]
+pub(crate) struct StageFetch<'a> {
Review Comment:
This feels like a lot of abstraction for what is essentially a single check
.
--
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]