neilconway commented on code in PR #20635:
URL: https://github.com/apache/datafusion/pull/20635#discussion_r2878759106


##########
datafusion/functions/src/datetime/to_char.rs:
##########
@@ -221,117 +216,95 @@ fn to_char_scalar(
         };
     }
 
-    let format_options = match build_format_options(data_type, format) {
-        Ok(value) => value,
-        Err(value) => return value,
-    };
-
+    let format_options = build_format_options(data_type, format)?;
     let formatter = ArrayFormatter::try_new(array.as_ref(), &format_options)?;
-    let formatted: Result<Vec<Option<String>>, ArrowError> = (0..array.len())
-        .map(|i| {
-            if array.is_null(i) {
-                Ok(None)
-            } else {
-                formatter.value(i).try_to_string().map(Some)
-            }
-        })
-        .collect();
-
-    if let Ok(formatted) = formatted {
-        if is_scalar_expression {
-            Ok(ColumnarValue::Scalar(ScalarValue::Utf8(
-                formatted.first().unwrap().clone(),
-            )))
+
+    let fmt_len = format.map_or(20, |f| f.len() + 10);

Review Comment:
   Thanks, good idea! We can actually move `NULL` / `Option` handling out of 
this function entirely, which simplifies the code overall.
   
   The `+ 10` is just an arbitrary guess, I added a comment.



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