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


##########
datafusion/functions/src/string/chr.rs:
##########
@@ -119,7 +119,47 @@ impl ScalarUDFImpl for ChrFunc {
     }
 
     fn invoke_with_args(&self, args: ScalarFunctionArgs) -> 
Result<ColumnarValue> {
-        make_scalar_function(chr, vec![])(&args.args)
+        let return_type = args.return_field.data_type();
+        let [arg] = take_function_args(self.name(), args.args)?;
+
+        match arg {

Review Comment:
   ```rust
   match arg {
       ColumnarValue::Scalar(ScalarValue::Int64(Some(code_point))) => {
           if let Ok(u) = u32::try_from(code_point)
               && let Some(c) = core::char::from_u32(u)
           {
               Ok(ColumnarValue::Scalar(ScalarValue::Utf8(Some(
                      c.to_string(),
                   ))))
               } else {
                   exec_err!("invalid Unicode scalar value: {code_point}")
               }
       }
       ColumnarValue::Scalar(ScalarValue::Int64(None)) => {
           Ok(ColumnarValue::Scalar(ScalarValue::Utf8(None)))
       }
       ColumnarValue::Array(array) => {
           Ok(ColumnarValue::Array(chr(&[array])?))
       }
       _ => internal_err!("..."),
   }
   ```
   
   - Easier to fold into match like this since we accept only one datatype; 
also unnecessary to double check the array datatype
   - Also worth looking into refactoring `chr()` function; no reason to pass in 
a slice when we can just pass the array



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