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:
Since this path now relies on preserving the input null bitmap via
`finish(nulls.cloned())`, could we add an explicit assertion that the NULL slot
remains NULL? `test_chr_normal` currently includes a `None` input, but only
checks `value(i) == ""`, which would also pass if the result accidentally
became 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]