Weijun-H commented on code in PR #21847:
URL: https://github.com/apache/datafusion/pull/21847#discussion_r3142912040


##########
datafusion/functions/src/string/chr.rs:
##########
@@ -32,31 +33,46 @@ use datafusion_macros::user_doc;
 /// Returns the character with the given code.
 /// chr(65) = 'A'
 fn chr_array(integer_array: &Int64Array) -> Result<ArrayRef> {
-    let mut builder = GenericStringBuilder::<i32>::with_capacity(
-        integer_array.len(),
-        // 1 byte per character, assuming that is the common case
-        integer_array.len(),
+    let len = integer_array.len();
+    let mut builder = GenericStringArrayBuilder::<i32>::with_capacity(
+        len, // 1 byte per character, assuming that is the common case
+        len,
     );
 
     let mut buf = [0u8; 4];
+    let nulls = integer_array.nulls();
 
-    for integer in integer_array {
-        match integer {
-            Some(integer) => {
-                if let Ok(u) = u32::try_from(integer)
-                    && let Some(c) = core::char::from_u32(u)
-                {
-                    builder.append_value(c.encode_utf8(&mut buf));
-                    continue;
-                }
-
-                return exec_err!("invalid Unicode scalar value: {integer}");
+    if let Some(n) = nulls {
+        for i in 0..len {
+            if n.is_null(i) {
+                builder.append_placeholder();

Review Comment:
   Could we add an explicit assertion in `test_chr_normal` that the `None` 
input remains NULL, e.g. `assert!(string_array.is_null(7))`? The test currently 
checks `value(7) == ""`, which would also pass if this path accidentally 
produced a non-null empty string.
   



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