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

Function concat_internal

datafusion/functions-nested/src/concat.rs:384–450  ·  view source on GitHub ↗
(args: &[ArrayRef])

Source from the content-addressed store, hash-verified

382}
383
384fn concat_internal<O: OffsetSizeTrait>(args: &[ArrayRef]) -> Result<ArrayRef> {
385 let args = align_array_dimensions::<O>(args.to_vec())?;
386
387 let list_arrays = args
388 .iter()
389 .map(|arg| as_generic_list_array::<O>(arg))
390 .collect::<Result<Vec<_>>>()?;
391 let row_count = list_arrays[0].len();
392
393 // Extract underlying values ArrayData from each list array for MutableArrayData.
394 let values_data: Vec<ArrayData> =
395 list_arrays.iter().map(|la| la.values().to_data()).collect();
396 let values_data_refs: Vec<&ArrayData> = values_data.iter().collect();
397
398 // Estimate capacity as the sum of all values arrays' lengths.
399 let total_capacity: usize = values_data.iter().map(|d| d.len()).sum();
400
401 let mut mutable = MutableArrayData::with_capacities(
402 values_data_refs,
403 false,
404 Capacities::Array(total_capacity),
405 );
406 let mut offsets: Vec<O> = Vec::with_capacity(row_count + 1);
407 offsets.push(O::zero());
408
409 // Compute the output null buffer: a row is null only if null in ALL input
410 // arrays. This is the bitwise OR of validity bits (valid if valid in ANY
411 // input). If any array has no null buffer (all valid), no output row can be
412 // null.
413 let nulls = list_arrays
414 .iter()
415 .filter_map(|la| la.nulls())
416 .collect::<Vec<_>>();
417 let valid = if nulls.len() == list_arrays.len() {
418 nulls
419 .iter()
420 .map(|n| n.inner().clone())
421 .reduce(|a, b| &a | &b)
422 .map(NullBuffer::new)
423 } else {
424 None
425 };
426
427 for row_idx in 0..row_count {
428 for (arr_idx, list_array) in list_arrays.iter().enumerate() {
429 if list_array.is_null(row_idx) {
430 continue;
431 }
432 let start = list_array.offsets()[row_idx].to_usize().unwrap();
433 let end = list_array.offsets()[row_idx + 1].to_usize().unwrap();
434 if start < end {
435 mutable.extend(arr_idx, start, end);
436 }
437 }
438 offsets.push(O::usize_as(mutable.len()));
439 }
440
441 let data_type = list_arrays[0].value_type();

Callers

nothing calls this directly

Calls 15

newFunction · 0.85
make_arrayFunction · 0.85
to_vecMethod · 0.80
collectMethod · 0.80
sumMethod · 0.80
offsetsMethod · 0.80
value_typeMethod · 0.80
mapMethod · 0.45
iterMethod · 0.45
lenMethod · 0.45
valuesMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…