kosiew commented on code in PR #23013:
URL: https://github.com/apache/datafusion/pull/23013#discussion_r3511244545


##########
datafusion/physical-expr/src/expressions/in_list/transform.rs:
##########
@@ -0,0 +1,169 @@
+// 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.
+
+//! Type transformation utilities for InList filters.
+//!
+//! Some filters only depend on fixed-width value bit patterns. For those 
cases,
+//! compatible primitive arrays can be reinterpreted to the filter's unsigned
+//! storage type without copying values.
+
+use std::mem::size_of;
+use std::sync::Arc;
+
+use arrow::array::{Array, ArrayRef, BooleanArray, PrimitiveArray};
+use arrow::buffer::ScalarBuffer;
+use arrow::datatypes::{ArrowPrimitiveType, DataType};
+use datafusion_common::{Result, exec_datafusion_err};
+
+use super::primitive_filter::{BitmapFilter, BitmapFilterType};
+use super::static_filter::{StaticFilter, handle_dictionary};
+
+/// Bitmap filter for signed 1-byte and 2-byte primitive arrays.
+///
+/// The bitmap implementation is keyed by an unsigned primitive type (`UInt8` 
or
+/// `UInt16`). This wrapper keeps the original array type, such as `Int8`, and
+/// only reinterprets values as the unsigned type when probing the bitmap.
+struct ReinterpretedBitmap<T: BitmapFilterType> {
+    expected_data_type: DataType,
+    inner: BitmapFilter<T>,
+}
+
+impl<T: BitmapFilterType> StaticFilter for ReinterpretedBitmap<T> {
+    fn null_count(&self) -> usize {
+        self.inner.null_count()
+    }
+
+    fn contains(&self, v: &dyn Array, negated: bool) -> Result<BooleanArray> {
+        handle_dictionary!(self, v, negated);
+
+        if v.data_type() != &self.expected_data_type {

Review Comment:
   Nice work preserving the original logical array type through the wrapper. 
Could we also add a small regression test that builds an `Int8` or `Int16` 
backed filter, probes it with the corresponding unsigned type (`UInt8` or 
`UInt16`), and asserts that it returns an error? That behavior is an important 
part of the contract, and having a focused test would help prevent future 
regressions.



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