You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@paimon.apache.org by "QuakeWang (via GitHub)" <gi...@apache.org> on 2026/04/05 12:06:58 UTC

[PR] feat: push down filters to parquet read path [paimon-rust]

QuakeWang opened a new pull request, #208:
URL: https://github.com/apache/paimon-rust/pull/208

   <!--
   Thank you very much for contributing to Paimon Rust - we are happy that you want to help us improve it. To help the community review your contribution in the best possible way, please go through the checklist below, which will get the contribution into a shape in which it can be best reviewed.
   
   ## Contribution Checklist
   
     - Make sure that the pull request corresponds to a [GitHub issue](https://github.com/apache/paimon-rust/issues). Exceptions are made for typos in documentation or comments, which need no issue.
   
     - Fill out the template below to describe the changes contributed by the pull request. That will give reviewers the context they need to do the review.
   
     - Make sure that the change passes the automated tests, i.e., `cargo test` passes.
   
     - Each pull request should address only one issue, not mix up code from multiple issues.
   
   **(The sections below can be removed for hotfixes or typos)**
   -->
   
   ### Purpose
   
   <!-- Linking this pull request to the issue -->
   
   Subtask of #173
   
     Push translated predicates down to the regular Parquet data read path.
   
     This PR keeps the scope limited to:
     - preserve pushed predicates from the DataFusion scan to execute
     - pass reader pruning predicates through `TableRead` / `ArrowReader`
     - apply row-group pruning and native Parquet row filtering on the regular Parquet read path
   
     Out of scope:
     - `data_evolution` read-side predicate pushdown
     - exact fallback filtering inside the reader
     - non-Parquet read paths
   
   <!-- What is the purpose of the change -->
   
   ### Brief change log
   
   <!-- Please describe the changes made in this pull request and explain how they address the issue -->
   
     - preserve pushed predicates in DataFusion `scan()` and reuse them in `execute()`
     - extend `ReadBuilder` / `TableRead` to carry reader pruning predicates
     - add filtering helpers for field mapping and stats-based pruning
     - add reader-side row-group pruning and native Parquet `RowFilter` for the regular Parquet read path
     - intersect predicate-based row selection with deletion-vector row selection
   
   ### Tests
   
   <!-- List unit tests or integration cases to verify this change -->
   
   ### API and Format
   
   <!-- Does this change affect API or storage format -->
   
   ### Documentation
   
   <!-- Does this change introduce a new feature or require documentation updates -->
   


-- 
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: issues-unsubscribe@paimon.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat: push down filters to parquet read path [paimon-rust]

Posted by "JingsongLi (via GitHub)" <gi...@apache.org>.
JingsongLi commented on code in PR #208:
URL: https://github.com/apache/paimon-rust/pull/208#discussion_r3037567872


##########
crates/paimon/src/table/read_builder.rs:
##########
@@ -99,7 +103,7 @@ impl<'a> ReadBuilder<'a> {
             Some(projected) => self.resolve_projected_fields(projected)?,
         };
 
-        Ok(TableRead::new(self.table, read_type))
+        Ok(TableRead::new(self.table, read_type).with_optional_filter(self.filter.clone()))

Review Comment:
   It is better to just pass data_predicates in `new`.



-- 
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: issues-unsubscribe@paimon.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat: push down filters to parquet read path [paimon-rust]

Posted by "JingsongLi (via GitHub)" <gi...@apache.org>.
JingsongLi commented on code in PR #208:
URL: https://github.com/apache/paimon-rust/pull/208#discussion_r3036880332


##########
crates/integrations/datafusion/src/physical_plan/scan.rs:
##########
@@ -226,4 +277,156 @@ mod tests {
             table_schema,
         )
     }
+
+    fn write_int_parquet_file(

Review Comment:
   There are two write_int_parquet_file, can you extract a test utility for this?



-- 
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: issues-unsubscribe@paimon.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat: push down filters to parquet read path [paimon-rust]

Posted by "JingsongLi (via GitHub)" <gi...@apache.org>.
JingsongLi commented on code in PR #208:
URL: https://github.com/apache/paimon-rust/pull/208#discussion_r3037571046


##########
crates/paimon/src/arrow/filtering.rs:
##########
@@ -0,0 +1,275 @@
+// 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::schema_evolution::create_index_mapping;
+use crate::spec::{
+    field_idx_to_partition_idx, DataField, DataType, Datum, Predicate, PredicateOperator,
+};
+use std::cmp::Ordering;
+
+pub(crate) trait StatsAccessor {
+    fn row_count(&self) -> i64;
+    fn null_count(&self, index: usize) -> Option<i64>;
+    fn min_value(&self, index: usize, data_type: &DataType) -> Option<Datum>;
+    fn max_value(&self, index: usize, data_type: &DataType) -> Option<Datum>;
+}
+
+pub(crate) fn reader_pruning_predicates(
+    filter: Predicate,
+    fields: &[DataField],
+    partition_keys: &[String],
+) -> Vec<Predicate> {
+    let partition_mapping = field_idx_to_partition_idx(fields, partition_keys);
+    filter
+        .split_and()
+        .into_iter()
+        .filter(|predicate| {
+            !predicate_contains_partition_field(predicate, &partition_mapping)
+                && predicate_supported_for_reader_pruning(predicate)
+        })
+        .collect()
+}
+
+pub(crate) fn build_field_mapping(
+    table_fields: &[DataField],
+    file_fields: &[DataField],
+) -> Vec<Option<usize>> {
+    normalize_field_mapping(
+        create_index_mapping(table_fields, file_fields),
+        table_fields.len(),
+    )
+}
+
+pub(crate) fn predicates_may_match_with_schema<T: StatsAccessor>(
+    predicates: &[Predicate],
+    stats: &T,
+    field_mapping: &[Option<usize>],
+    file_fields: &[DataField],
+) -> bool {
+    predicates.iter().all(|predicate| {
+        predicate_may_match_with_schema(predicate, stats, field_mapping, file_fields)
+    })
+}
+
+fn predicate_contains_partition_field(
+    predicate: &Predicate,
+    partition_mapping: &[Option<usize>],
+) -> bool {
+    match predicate {
+        Predicate::Leaf { index, .. } => partition_mapping.get(*index).is_some_and(Option::is_some),
+        Predicate::And(children) | Predicate::Or(children) => children
+            .iter()
+            .any(|child| predicate_contains_partition_field(child, partition_mapping)),
+        Predicate::Not(inner) => predicate_contains_partition_field(inner, partition_mapping),
+        Predicate::AlwaysTrue | Predicate::AlwaysFalse => false,
+    }
+}
+
+fn predicate_supported_for_reader_pruning(predicate: &Predicate) -> bool {
+    match predicate {
+        Predicate::AlwaysFalse => true,
+        Predicate::Leaf { op, .. } => {
+            matches!(
+                op,
+                PredicateOperator::IsNull
+                    | PredicateOperator::IsNotNull
+                    | PredicateOperator::Eq
+                    | PredicateOperator::NotEq
+                    | PredicateOperator::Lt
+                    | PredicateOperator::LtEq
+                    | PredicateOperator::Gt
+                    | PredicateOperator::GtEq
+                    | PredicateOperator::In
+                    | PredicateOperator::NotIn
+            )
+        }
+        Predicate::AlwaysTrue | Predicate::And(_) | Predicate::Or(_) | Predicate::Not(_) => false,
+    }
+}
+
+fn predicate_may_match_with_schema<T: StatsAccessor>(
+    predicate: &Predicate,
+    stats: &T,
+    field_mapping: &[Option<usize>],
+    file_fields: &[DataField],
+) -> bool {
+    match predicate {
+        Predicate::AlwaysTrue => true,
+        Predicate::AlwaysFalse => false,
+        Predicate::And(children) => children
+            .iter()
+            .all(|child| predicate_may_match_with_schema(child, stats, field_mapping, file_fields)),
+        Predicate::Or(_) | Predicate::Not(_) => true,
+        Predicate::Leaf {
+            index,
+            data_type,
+            op,
+            literals,
+            ..
+        } => match field_mapping.get(*index).copied().flatten() {
+            Some(file_index) => {
+                let Some(file_field) = file_fields.get(file_index) else {
+                    return true;
+                };
+                data_leaf_may_match(
+                    file_index,
+                    file_field.data_type(),
+                    data_type,
+                    *op,
+                    literals,
+                    stats,
+                )
+            }
+            None => missing_field_may_match(*op, stats.row_count()),
+        },
+    }
+}
+
+fn data_leaf_may_match<T: StatsAccessor>(

Review Comment:
   We alread have data_leaf_may_match in stats_filter, we should do some refactor to reuse it.



-- 
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: issues-unsubscribe@paimon.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat: push down filters to parquet read path [paimon-rust]

Posted by "JingsongLi (via GitHub)" <gi...@apache.org>.
JingsongLi commented on code in PR #208:
URL: https://github.com/apache/paimon-rust/pull/208#discussion_r3036878596


##########
crates/integrations/datafusion/src/physical_plan/scan.rs:
##########
@@ -145,9 +163,31 @@ impl ExecutionPlan for PaimonTableScan {
             ))
         };
 
+        let stream = futures::stream::once(fut).try_flatten();
+
+        // Enforce the final LIMIT at the DataFusion execution layer.
+        let limited_stream: Pin<Box<dyn Stream<Item = DFResult<RecordBatch>> + Send>> =

Review Comment:
   Why add this code back?



-- 
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: issues-unsubscribe@paimon.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat: push down filters to parquet read path [paimon-rust]

Posted by "QuakeWang (via GitHub)" <gi...@apache.org>.
QuakeWang commented on code in PR #208:
URL: https://github.com/apache/paimon-rust/pull/208#discussion_r3036922780


##########
crates/integrations/datafusion/src/physical_plan/scan.rs:
##########
@@ -226,4 +277,156 @@ mod tests {
             table_schema,
         )
     }
+
+    fn write_int_parquet_file(
+        path: &std::path::Path,
+        columns: Vec<(&str, Vec<i32>)>,
+        max_row_group_size: Option<usize>,
+    ) {
+        let schema = Arc::new(ArrowSchema::new(
+            columns
+                .iter()
+                .map(|(name, _)| Field::new(*name, ArrowDataType::Int32, false))
+                .collect::<Vec<_>>(),
+        ));
+        let arrays: Vec<Arc<dyn datafusion::arrow::array::Array>> = columns
+            .iter()
+            .map(|(_, values)| {
+                Arc::new(Int32Array::from(values.clone()))
+                    as Arc<dyn datafusion::arrow::array::Array>
+            })
+            .collect();
+        let batch =
+            datafusion::arrow::record_batch::RecordBatch::try_new(schema.clone(), arrays).unwrap();
+
+        let props = max_row_group_size.map(|size| {
+            WriterProperties::builder()
+                .set_max_row_group_size(size)
+                .build()
+        });
+        let file = File::create(path).unwrap();
+        let mut writer = ArrowWriter::try_new(file, schema, props).unwrap();
+        writer.write(&batch).unwrap();
+        writer.close().unwrap();
+    }
+
+    fn local_file_path(path: &std::path::Path) -> String {
+        let normalized = path.to_string_lossy().replace('\\', "/");
+        if normalized.starts_with('/') {
+            format!("file:{normalized}")
+        } else {
+            format!("file:/{normalized}")
+        }
+    }
+
+    fn test_data_file(file_name: &str, row_count: i64) -> DataFileMeta {

Review Comment:
   Fixed. I extracted the shared parquet read test fixtures into a common test utility and removed the duplicated test_data_file helper.



-- 
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: issues-unsubscribe@paimon.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat: push down filters to parquet read path [paimon-rust]

Posted by "JingsongLi (via GitHub)" <gi...@apache.org>.
JingsongLi commented on code in PR #208:
URL: https://github.com/apache/paimon-rust/pull/208#discussion_r3036879789


##########
crates/integrations/datafusion/src/physical_plan/scan.rs:
##########
@@ -226,4 +277,156 @@ mod tests {
             table_schema,
         )
     }
+
+    fn write_int_parquet_file(
+        path: &std::path::Path,
+        columns: Vec<(&str, Vec<i32>)>,
+        max_row_group_size: Option<usize>,
+    ) {
+        let schema = Arc::new(ArrowSchema::new(
+            columns
+                .iter()
+                .map(|(name, _)| Field::new(*name, ArrowDataType::Int32, false))
+                .collect::<Vec<_>>(),
+        ));
+        let arrays: Vec<Arc<dyn datafusion::arrow::array::Array>> = columns
+            .iter()
+            .map(|(_, values)| {
+                Arc::new(Int32Array::from(values.clone()))
+                    as Arc<dyn datafusion::arrow::array::Array>
+            })
+            .collect();
+        let batch =
+            datafusion::arrow::record_batch::RecordBatch::try_new(schema.clone(), arrays).unwrap();
+
+        let props = max_row_group_size.map(|size| {
+            WriterProperties::builder()
+                .set_max_row_group_size(size)
+                .build()
+        });
+        let file = File::create(path).unwrap();
+        let mut writer = ArrowWriter::try_new(file, schema, props).unwrap();
+        writer.write(&batch).unwrap();
+        writer.close().unwrap();
+    }
+
+    fn local_file_path(path: &std::path::Path) -> String {
+        let normalized = path.to_string_lossy().replace('\\', "/");
+        if normalized.starts_with('/') {
+            format!("file:{normalized}")
+        } else {
+            format!("file:/{normalized}")
+        }
+    }
+
+    fn test_data_file(file_name: &str, row_count: i64) -> DataFileMeta {

Review Comment:
   There are two `test_data_file`, can you extract a test utility for this?



-- 
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: issues-unsubscribe@paimon.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat: push down filters to parquet read path [paimon-rust]

Posted by "QuakeWang (via GitHub)" <gi...@apache.org>.
QuakeWang commented on code in PR #208:
URL: https://github.com/apache/paimon-rust/pull/208#discussion_r3036922456


##########
crates/integrations/datafusion/src/physical_plan/scan.rs:
##########
@@ -145,9 +163,31 @@ impl ExecutionPlan for PaimonTableScan {
             ))
         };
 
+        let stream = futures::stream::once(fut).try_flatten();
+
+        // Enforce the final LIMIT at the DataFusion execution layer.
+        let limited_stream: Pin<Box<dyn Stream<Item = DFResult<RecordBatch>> + Send>> =

Review Comment:
   Sorry. This was reintroduced during the upstream merge by mistake 😅. I removed the extra limit enforcement in execute() and kept limit only as a planning hint.



-- 
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: issues-unsubscribe@paimon.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat: push down filters to parquet read path [paimon-rust]

Posted by "QuakeWang (via GitHub)" <gi...@apache.org>.
QuakeWang commented on code in PR #208:
URL: https://github.com/apache/paimon-rust/pull/208#discussion_r3036923034


##########
crates/integrations/datafusion/src/physical_plan/scan.rs:
##########
@@ -226,4 +277,156 @@ mod tests {
             table_schema,
         )
     }
+
+    fn write_int_parquet_file(

Review Comment:
   Fixed together with the shared test utility extraction. write_int_parquet_file is now reused from the common test fixture module.



-- 
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: issues-unsubscribe@paimon.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat: push down filters to parquet read path [paimon-rust]

Posted by "JingsongLi (via GitHub)" <gi...@apache.org>.
JingsongLi commented on PR #208:
URL: https://github.com/apache/paimon-rust/pull/208#issuecomment-4189835049

   @QuakeWang Please rebase master.


-- 
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: issues-unsubscribe@paimon.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat: push down filters to parquet read path [paimon-rust]

Posted by "JingsongLi (via GitHub)" <gi...@apache.org>.
JingsongLi merged PR #208:
URL: https://github.com/apache/paimon-rust/pull/208


-- 
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: issues-unsubscribe@paimon.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat: push down filters to parquet read path [paimon-rust]

Posted by "JingsongLi (via GitHub)" <gi...@apache.org>.
JingsongLi commented on code in PR #208:
URL: https://github.com/apache/paimon-rust/pull/208#discussion_r3037566640


##########
crates/paimon/src/table/read_builder.rs:
##########
@@ -67,8 +68,11 @@ impl<'a> ReadBuilder<'a> {
     /// Stats pruning is per file. Files with a different `schema_id`,
     /// incompatible stats layout, or inconclusive stats are kept.
     ///
-    /// [`TableRead`] does not evaluate row-level filters; callers must apply
-    /// any remaining predicates themselves.
+    /// [`TableRead`] may use supported non-partition data predicates only on
+    /// the regular Parquet read path for conservative row-group pruning and
+    /// native Parquet row filtering. Unsupported predicates, non-Parquet
+    /// reads, and data-evolution reads remain residual and should still be
+    /// applied by the caller if exact filtering semantics are required.
     pub fn with_filter(&mut self, filter: Predicate) -> &mut Self {
         self.filter = Some(filter);

Review Comment:
   Maybe here we can just split filter to partition_predicate and data_predicates, and just pass them to TableScan and TableRead.



-- 
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: issues-unsubscribe@paimon.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org