neilconway commented on code in PR #21849:
URL: https://github.com/apache/datafusion/pull/21849#discussion_r3150188225
##########
datafusion/functions/src/string/replace.rs:
##########
@@ -160,25 +162,29 @@ fn replace_view(args: &[ArrayRef]) -> Result<ArrayRef> {
let from_array = as_string_view_array(&args[1])?;
let to_array = as_string_view_array(&args[2])?;
- let mut builder = GenericStringBuilder::<i32>::new();
+ let len = string_array.len();
+ let mut builder = GenericStringArrayBuilder::<i32>::with_capacity(len, 0);
let mut buffer = String::new();
+ let nulls = NullBuffer::union(
+ NullBuffer::union(string_array.nulls(), from_array.nulls()).as_ref(),
+ to_array.nulls(),
+ );
- for ((string, from), to) in string_array
- .iter()
- .zip(from_array.iter())
- .zip(to_array.iter())
- {
- match (string, from, to) {
- (Some(string), Some(from), Some(to)) => {
- buffer.clear();
- replace_into_string(&mut buffer, string, from, to);
- builder.append_value(&buffer);
- }
- _ => builder.append_null(),
+ for i in 0..len {
+ if nulls.as_ref().is_some_and(|n| n.is_null(i)) {
Review Comment:
Yep; I've been doing this in some cases but not always. Having Claude look
at the generated assembly, seems like LLVM does the hoist / loop duplication
for us for the `replace` + Utf8/LargeUtf8 case, but not for Utf8View.
--
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]