Jefffrey commented on code in PR #17179:
URL: https://github.com/apache/datafusion/pull/17179#discussion_r2292713269


##########
datafusion/spark/src/function/misc/bitmap_count.rs:
##########
@@ -0,0 +1,175 @@
+// 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::any::Any;
+use std::sync::Arc;
+
+use arrow::array::{
+    Array, ArrayRef, BinaryArray, BinaryViewArray, FixedSizeBinaryArray, 
Int64Array,
+    LargeBinaryArray,
+};
+use arrow::datatypes::DataType;
+use arrow::datatypes::DataType::{
+    Binary, BinaryView, FixedSizeBinary, Int64, LargeBinary,
+};
+use datafusion_common::utils::take_function_args;
+use datafusion_common::Result;
+use datafusion_common::{exec_err, internal_datafusion_err, DataFusionError};
+use datafusion_expr::function::Hint;
+use datafusion_expr::ScalarFunctionArgs;
+use datafusion_expr::{ColumnarValue, ScalarUDFImpl, Signature, Volatility};
+use datafusion_functions::utils::make_scalar_function;
+use datafusion_functions::{downcast_arg, downcast_named_arg};
+
+#[derive(Debug)]
+pub struct BitmapCount {
+    signature: Signature,
+}
+
+impl Default for BitmapCount {
+    fn default() -> Self {
+        Self::new()
+    }
+}
+
+impl BitmapCount {
+    pub fn new() -> Self {
+        Self {
+            signature: Signature::any(1, Volatility::Immutable),
+        }
+    }
+}
+
+impl ScalarUDFImpl for BitmapCount {
+    fn as_any(&self) -> &dyn Any {
+        self
+    }
+
+    fn name(&self) -> &str {
+        "bitmap_count"
+    }
+
+    fn signature(&self) -> &Signature {
+        &self.signature
+    }
+
+    fn return_type(&self, arg_types: &[DataType]) -> Result<DataType> {
+        match arg_types.first() {
+            Some(Binary | BinaryView | FixedSizeBinary(_) | LargeBinary) => 
Ok(Int64),

Review Comment:
   Good point; did a bit of looking and stumbled upon this:
   
   
https://github.com/apache/datafusion/blob/a0248a98b8d2c593d4e723cf6bb03d76d480b776/datafusion/expr-common/src/signature.rs#L42-L45
   
   So I think you can use like so:
   
   ```rust
       pub fn new() -> Self {
           Self {
               signature: Signature::one_of(
                   vec![
                       TypeSignature::Exact(vec![Binary]),
                       TypeSignature::Exact(vec![BinaryView]),
                       TypeSignature::Exact(vec![LargeBinary]),
                       
TypeSignature::Exact(vec![FixedSizeBinary(FIXED_SIZE_LIST_WILDCARD)]),
                   ],
                   Volatility::Immutable,
               ),
           }
       }
   ```
   
   Do note you'll need to export `FIXED_SIZE_LIST_WILDCARD` here like is done 
for `TIMEZONE_WILDCARD` so it can be imported:
   
   
https://github.com/apache/datafusion/blob/a0248a98b8d2c593d4e723cf6bb03d76d480b776/datafusion/expr/src/lib.rs#L85-L88
   
   And would be good to have a few test cases of different sizes for 
`FixedSizeBinary` to ensure this works, as well as some negative cases to 
ensure providing a type like `Utf8` would fail as expected



-- 
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: github-unsubscr...@datafusion.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org
For additional commands, e-mail: github-h...@datafusion.apache.org

Reply via email to