martin-g commented on code in PR #18836:
URL: https://github.com/apache/datafusion/pull/18836#discussion_r2546092715


##########
datafusion/sqllogictest/test_files/spark/bitwise/bit_get.slt:
##########
@@ -69,7 +69,17 @@ SELECT bit_get(NULL, 0);
 ----
 NULL
 
+query I
+SELECT bit_get(NULL::int, 0);
+----
+NULL
+
 query I
 SELECT bit_get(11, NULL);
 ----
 NULL
+
+query I
+SELECT bit_get(11, NULL::int);
+----
+NULL

Review Comment:
   Ideas for tests that explicitly use different integer types to verify 
coercion:
   ```
   SELECT bit_get(CAST(11 AS TINYINT), 0);
   SELECT bit_get(CAST(11 AS BIGINT), 0);
   SELECT bit_get(11, CAST(3 AS BIGINT)); -- Test coercion of position arg
   ```



##########
datafusion/spark/src/function/bitwise/bit_get.rs:
##########
@@ -130,164 +108,13 @@ fn spark_bit_get_inner<T: ArrowPrimitiveType>(
     Ok(result)
 }
 
-pub fn spark_bit_get(args: &[ArrayRef]) -> Result<ArrayRef> {
-    if args.len() != 2 {
-        return exec_err!("`bit_get` expects exactly two arguments");
-    }
-
-    if args[1].data_type() != &Int32 {
-        return exec_err!("`bit_get` expects Int32 as the second argument");
-    }
-
-    let pos_arg = args[1].as_primitive::<Int32Type>();
-
-    let ret = match &args[0].data_type() {
-        Int64 => {
-            let value_arg = args[0].as_primitive::<Int64Type>();
-            spark_bit_get_inner(value_arg, pos_arg)
-        }
-        Int32 => {
-            let value_arg = args[0].as_primitive::<Int32Type>();
-            spark_bit_get_inner(value_arg, pos_arg)
-        }
-        Int16 => {
-            let value_arg = args[0].as_primitive::<Int16Type>();
-            spark_bit_get_inner(value_arg, pos_arg)
-        }
-        Int8 => {
-            let value_arg = args[0].as_primitive::<Int8Type>();
-            spark_bit_get_inner(value_arg, pos_arg)
-        }
-        UInt64 => {
-            let value_arg = args[0].as_primitive::<UInt64Type>();
-            spark_bit_get_inner(value_arg, pos_arg)
-        }
-        UInt32 => {
-            let value_arg = args[0].as_primitive::<UInt32Type>();
-            spark_bit_get_inner(value_arg, pos_arg)
-        }
-        UInt16 => {
-            let value_arg = args[0].as_primitive::<UInt16Type>();
-            spark_bit_get_inner(value_arg, pos_arg)
-        }
-        UInt8 => {
-            let value_arg = args[0].as_primitive::<UInt8Type>();
-            spark_bit_get_inner(value_arg, pos_arg)
-        }
-        _ => {
-            exec_err!(
-                "`bit_get` expects Int64, Int32, Int16, or Int8 as the first 
argument"
-            )
-        }
-    }?;
+fn spark_bit_get(args: &[ArrayRef]) -> Result<ArrayRef> {
+    let [value, position] = take_function_args("bit_get", args)?;
+    let pos_arg = position.as_primitive::<Int32Type>();

Review Comment:
   Is this safe to be done ? 
   From the other PR few days ago we know that `position` could be `Null` here.
   
   ```suggestion
       let pos_arg = position.as_primitive_opt::<Int32Type>()
   +        .ok_or_else(|| internal_err!("Expected Int32 for position 
argument"))?;
   ```



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