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


##########
datafusion/spark/src/function/hash/sha2.rs:
##########
@@ -65,25 +69,44 @@ impl ScalarUDFImpl for SparkSha2 {
         &self.signature
     }
 
-    fn return_type(&self, arg_types: &[DataType]) -> Result<DataType> {
-        if arg_types[1].is_null() {
-            return Ok(DataType::Null);
-        }
-        Ok(match arg_types[0] {
-            DataType::Utf8View
-            | DataType::LargeUtf8
-            | DataType::Utf8
-            | DataType::Binary
-            | DataType::BinaryView
-            | DataType::LargeBinary => DataType::Utf8,
-            DataType::Null => DataType::Null,
-            _ => {
-                return exec_err!(
-                    "{} function can only accept strings or binary arrays.",
-                    self.name()
-                );
+    fn return_type(&self, _arg_types: &[DataType]) -> Result<DataType> {
+        internal_err!("return_field_from_args should be used instead")
+    }
+
+    fn return_field_from_args(&self, args: ReturnFieldArgs) -> 
Result<FieldRef> {
+        let arg_types: Vec<_> = args
+            .arg_fields
+            .iter()
+            .map(|field| field.data_type().clone())
+            .collect();
+
+        let data_type = if arg_types[1].is_null() {
+            DataType::Null
+        } else {
+            match arg_types[0] {
+                DataType::Utf8View
+                | DataType::LargeUtf8
+                | DataType::Utf8
+                | DataType::Binary
+                | DataType::BinaryView
+                | DataType::LargeBinary => DataType::Utf8,
+                DataType::Null => DataType::Null,
+                _ => {
+                    return exec_err!(
+                        "{} function can only accept strings or binary 
arrays.",
+                        self.name()
+                    );
+                }
             }
-        })
+        };
+
+        let nullable = args.arg_fields.iter().any(|f| f.is_nullable())
+            || args
+                .scalar_arguments
+                .iter()
+                .any(|scalar| scalar.is_some_and(|s| s.is_null()));

Review Comment:
   I think this should also check that the second argument's (bit_length) value 
is one of the supported ones (0, 224, 256, 384, or 512), because for invalid 
values it returns `ScalarValue::Utf8(None)` at 
https://github.com/ShashidharM0118/datafusion/blob/54561641ae94d9100d267477511127745ac51f60/datafusion/spark/src/function/hash/sha2.rs#L246



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