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


##########
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:
   this doesn't work unfortunately
   ```
   1. query failed: DataFusion error: Error during planning: Failed to coerce 
arguments to satisfy a call to 'bitmap_count' function: coercion from 
[FixedSizeBinary(2)] to the signature OneOf([Exact([Binary]), 
Exact([BinaryView]), Exact([LargeBinary]), 
Exact([FixedSizeBinary(-2147483648)])]) failed No function matches the given 
name and argument types 'bitmap_count(FixedSizeBinary(2))'. You might need to 
add explicit type casts.
           Candidate functions:
           bitmap_count(Binary)
           bitmap_count(BinaryView)
           bitmap_count(LargeBinary)
           bitmap_count(FixedSizeBinary(-2147483648))
   [SQL] SELECT bitmap_count(arrow_cast(a, 'FixedSizeBinary(2)')) FROM (VALUES 
(X'1010'), (X'0AB0'), (X'FFFF'), (NULL)) AS t(a);
   at 
/home/x/datafusion/datafusion/sqllogictest/test_files/spark/bitmap/bitmap_count.slt:55
   ```
   tried also 0 and other consts
   it only works when the  input type fixed size equals to this const
   
   I suppose adding a designated const and a branch to implement the coersion 
is needed here:
   
https://github.com/apache/datafusion/blob/a0248a98b8d2c593d4e723cf6bb03d76d480b776/datafusion/expr/src/type_coercion/functions.rs#L877-L889



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