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

Function primitive_array_min_max

datafusion/functions-nested/src/min_max.rs:245–283  ·  view source on GitHub ↗

Computes min or max for each row of a primitive ListArray.

(
    list_array: &GenericListArray<O>,
    is_min: bool,
)

Source from the content-addressed store, hash-verified

243
244/// Computes min or max for each row of a primitive ListArray.
245fn primitive_array_min_max<O: OffsetSizeTrait, T: ArrowPrimitiveType>(
246 list_array: &GenericListArray<O>,
247 is_min: bool,
248) -> Result<ArrayRef> {
249 let values_array = list_array.values().as_primitive::<T>();
250 let values_slice = values_array.values();
251 let values_nulls = values_array.nulls();
252 let mut result_builder = PrimitiveBuilder::<T>::with_capacity(list_array.len())
253 .with_data_type(values_array.data_type().clone());
254
255 for (row, w) in list_array.offsets().windows(2).enumerate() {
256 let row_result = if list_array.is_null(row) {
257 None
258 } else {
259 let start = w[0].as_usize();
260 let end = w[1].as_usize();
261 let len = end - start;
262
263 match len {
264 0 => None,
265 _ if len < ARROW_COMPUTE_THRESHOLD => {
266 scalar_min_max::<T>(values_slice, values_nulls, start, end, is_min)
267 }
268 _ => {
269 let slice = values_array.slice(start, len);
270 if is_min {
271 arrow::compute::min::<T>(&slice)
272 } else {
273 arrow::compute::max::<T>(&slice)
274 }
275 }
276 }
277 };
278
279 result_builder.append_option(row_result);
280 }
281
282 Ok(Arc::new(result_builder.finish()) as ArrayRef)
283}
284
285/// Computes min or max for a single list row by directly scanning a slice of
286/// the flat values buffer.

Callers

nothing calls this directly

Calls 12

newFunction · 0.85
with_data_typeMethod · 0.80
offsetsMethod · 0.80
sliceMethod · 0.80
valuesMethod · 0.45
nullsMethod · 0.45
lenMethod · 0.45
cloneMethod · 0.45
data_typeMethod · 0.45
is_nullMethod · 0.45
as_usizeMethod · 0.45
finishMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…