Dandandan commented on code in PR #14700:
URL: https://github.com/apache/datafusion/pull/14700#discussion_r1957866816


##########
datafusion/functions/src/string/chr.rs:
##########
@@ -36,26 +36,40 @@ use datafusion_macros::user_doc;
 pub fn chr(args: &[ArrayRef]) -> Result<ArrayRef> {
     let integer_array = as_int64_array(&args[0])?;
 
-    // first map is the iterator, second is for the `Option<_>`
-    let result = integer_array
-        .iter()
-        .map(|integer: Option<i64>| {
-            integer
-                .map(|integer| {
-                    if integer == 0 {
-                        exec_err!("null character not permitted.")
-                    } else {
-                        match core::char::from_u32(integer as u32) {
-                            Some(integer) => Ok(integer.to_string()),
-                            None => {
-                                exec_err!("requested character too large for 
encoding.")
-                            }
+    let mut builder = GenericStringBuilder::<i32>::with_capacity(
+        integer_array.len(),
+        // This assumes the maximum length of a single character is 4 bytes,
+        // which might be overly pessimistic
+        integer_array.len() * 4,

Review Comment:
   Maybe it can assume 1 or 2 bytes instead? This means max 4 (or 2 when 
assuming 2 bytes) allocations per array and in common cases 1-2.



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