MCPcopy Create free account
hub / github.com/apache/datafusion / replace_view

Function replace_view

datafusion/functions/src/string/replace.rs:162–201  ·  view source on GitHub ↗
(args: &[ArrayRef])

Source from the content-addressed store, hash-verified

160}
161
162fn replace_view(args: &[ArrayRef]) -> Result<ArrayRef> {
163 let string_array = as_string_view_array(&args[0])?;
164 let from_array = as_string_view_array(&args[1])?;
165 let to_array = as_string_view_array(&args[2])?;
166
167 let len = string_array.len();
168 let mut builder = GenericStringArrayBuilder::<i32>::with_capacity(len, 0);
169 let nulls = NullBuffer::union_many([
170 string_array.nulls(),
171 from_array.nulls(),
172 to_array.nulls(),
173 ]);
174
175 // Hoist the nulls.is_some() check out of the loop. LLVM does not always
176 // unswitch this loop on its own (the Utf8View body is large enough to
177 // exceed its cost-benefit threshold).
178 if let Some(nulls_ref) = nulls.as_ref() {
179 for i in 0..len {
180 if nulls_ref.is_null(i) {
181 builder.append_placeholder();
182 continue;
183 }
184 // SAFETY: union of input nulls is non-null at i, so each input is too.
185 let string = unsafe { string_array.value_unchecked(i) };
186 let from = unsafe { from_array.value_unchecked(i) };
187 let to = unsafe { to_array.value_unchecked(i) };
188 apply_replace(&mut builder, string, from, to);
189 }
190 } else {
191 for i in 0..len {
192 // SAFETY: i < len, and no input has a null buffer.
193 let string = unsafe { string_array.value_unchecked(i) };
194 let from = unsafe { from_array.value_unchecked(i) };
195 let to = unsafe { to_array.value_unchecked(i) };
196 apply_replace(&mut builder, string, from, to);
197 }
198 }
199
200 Ok(Arc::new(builder.finish(nulls)?) as ArrayRef)
201}
202
203/// Replaces all occurrences in string of substring from with substring to.
204/// replace('abcdefabcdef', 'cd', 'XX') = 'abXXefabXXef'

Callers

nothing calls this directly

Calls 9

as_string_view_arrayFunction · 0.85
apply_replaceFunction · 0.85
newFunction · 0.85
append_placeholderMethod · 0.80
lenMethod · 0.45
nullsMethod · 0.45
as_refMethod · 0.45
is_nullMethod · 0.45
finishMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…