sunchao commented on code in PR #24526:
URL: https://github.com/apache/datafusion/pull/24526#discussion_r3866800177


##########
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:
   Not yet: the current benchmark compares compact pruning with the per-value 
expression tree, not alternative domain representations. `Arc<[String]>` makes 
sorting/deduplication straightforward and lets `with_new_children` share the 
prepared domain. `StringArray`/`LargeStringArray` would pack the bytes and 
offsets contiguously and is worth comparing for construction cost, allocations, 
and lookup locality. I don't have evidence that the current representation is 
optimal; I'd keep that measurement and any resulting change as a follow-up.



##########
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:
   Agreed. Hashing traverses the domain, and equality can do so too. The 
existing benchmark measures complete predicate construction and pruning 
evaluation; it does not isolate repeated hashing/equality during expression 
rewrites. I'll leave this unchanged here as suggested. A follow-up should 
measure large and long-string domains; a cached digest could avoid repeated 
hashing, while equality must still compare values when digests match so 
collisions cannot equate different predicates.



-- 
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]

Reply via email to