adriangb commented on code in PR #24526:
URL: https://github.com/apache/datafusion/pull/24526#discussion_r3863364356
##########
datafusion/datasource-parquet/src/opener/mod.rs:
##########
@@ -1814,10 +1817,12 @@ fn create_initial_plan(
pub(crate) fn build_page_pruning_predicate(
predicate: &Arc<dyn PhysicalExpr>,
file_schema: &SchemaRef,
+ max_in_list_size: usize,
) -> Arc<PagePruningAccessPlanFilter> {
- Arc::new(PagePruningAccessPlanFilter::new(
+ Arc::new(PagePruningAccessPlanFilter::new_with_max_in_list_size(
Review Comment:
This seems to me like the kind of thing where we would want a
`PagePruningAccessPlanFilterBuilder` in the future if we add any more options /
constructors. But maybe this is fine for now.
##########
datafusion/datasource-parquet/src/page_filter.rs:
##########
@@ -138,15 +138,25 @@ impl PagePruningResult {
impl PagePruningAccessPlanFilter {
/// Create a new [`PagePruningAccessPlanFilter`] from a physical
- /// expression.
+ /// expression, using the default `IN (...)` pruning limit.
#[expect(clippy::needless_pass_by_value)]
pub fn new(expr: &Arc<dyn PhysicalExpr>, schema: SchemaRef) -> Self {
+ Self::new_with_max_in_list_size(expr, &schema, MAX_IN_LIST_SIZE)
+ }
+
+ /// Create a page filter using the same `IN (...)` limit as row-group
pruning.
+ pub(crate) fn new_with_max_in_list_size(
+ expr: &Arc<dyn PhysicalExpr>,
+ schema: &SchemaRef,
+ max_in_list_size: usize,
+ ) -> Self {
// extract any single column predicates
let predicates = split_conjunction(expr)
.into_iter()
.filter_map(|predicate| {
let pp = match PruningPredicateBuilder::new()
- .with_file_schema(Arc::clone(&schema))
+ .with_file_schema(Arc::clone(schema))
+ .with_max_in_list_size(max_in_list_size)
Review Comment:
Indeed seems like this is all a thin wrapper around a builder, might be a
sign...
##########
datafusion/pruning/src/string_in_list.rs:
##########
@@ -0,0 +1,225 @@
+// 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 std::fmt::{self, Display, Formatter};
+use std::hash::{Hash, Hasher};
+use std::sync::Arc;
+
+use arrow::array::{Array, AsArray, BooleanArray};
+use arrow::compute::cast;
+use arrow::datatypes::{DataType, Schema};
+use arrow::record_batch::RecordBatch;
+use datafusion_common::{Result, assert_eq_or_internal_err};
+use datafusion_physical_expr::{PhysicalExpr, PhysicalExprRef};
+use datafusion_physical_plan::ColumnarValue;
+
+/// Tests whether a sorted string domain intersects an inclusive statistics
interval.
+/// This expression is used only for pruning; the original IN remains the row
filter.
+#[derive(Debug, Eq)]
+pub(crate) struct StringInListPruningExpr {
+ min: PhysicalExprRef,
+ max: PhysicalExprRef,
+ values: Arc<[String]>,
+}
+
+impl StringInListPruningExpr {
+ pub(crate) fn new(
+ min: PhysicalExprRef,
+ max: PhysicalExprRef,
+ mut values: Vec<String>,
+ ) -> Self {
+ values.sort_unstable();
+ values.dedup();
+ Self {
+ min,
+ max,
+ values: values.into(),
+ }
+ }
+}
+
+impl PartialEq for StringInListPruningExpr {
+ fn eq(&self, other: &Self) -> bool {
+ self.min.eq(&other.min) && self.max.eq(&other.max) && self.values ==
other.values
+ }
+}
+
+impl Hash for StringInListPruningExpr {
+ fn hash<H: Hasher>(&self, state: &mut H) {
+ self.min.hash(state);
+ self.max.hash(state);
+ self.values.hash(state);
+ }
+}
Review Comment:
These both walk every value. It might be worth measuring what impact that
has at the extremes, it would depend on how much these expression trees are
walk / if there's any dedup or expression optimization run on them. We could
always build a digest of the values upfront. Probably fine to leave for now.
##########
datafusion/pruning/src/string_in_list.rs:
##########
@@ -0,0 +1,225 @@
+// 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 std::fmt::{self, Display, Formatter};
+use std::hash::{Hash, Hasher};
+use std::sync::Arc;
+
+use arrow::array::{Array, AsArray, BooleanArray};
+use arrow::compute::cast;
+use arrow::datatypes::{DataType, Schema};
+use arrow::record_batch::RecordBatch;
+use datafusion_common::{Result, assert_eq_or_internal_err};
+use datafusion_physical_expr::{PhysicalExpr, PhysicalExprRef};
+use datafusion_physical_plan::ColumnarValue;
+
+/// Tests whether a sorted string domain intersects an inclusive statistics
interval.
+/// This expression is used only for pruning; the original IN remains the row
filter.
+#[derive(Debug, Eq)]
+pub(crate) struct StringInListPruningExpr {
+ min: PhysicalExprRef,
+ max: PhysicalExprRef,
+ values: Arc<[String]>,
Review Comment:
Have we analyzed if this is the best representation? E.g. could we use a
`StringArray` instead?
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]