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

Function general_array_slice

datafusion/functions-nested/src/extract.rs:613–690  ·  view source on GitHub ↗
(
    array: &GenericListArray<O>,
    from_array: &Int64Array,
    to_array: &Int64Array,
    stride: Option<&Int64Array>,
)

Source from the content-addressed store, hash-verified

611}
612
613fn general_array_slice<O: OffsetSizeTrait>(
614 array: &GenericListArray<O>,
615 from_array: &Int64Array,
616 to_array: &Int64Array,
617 stride: Option<&Int64Array>,
618) -> Result<ArrayRef>
619where
620 i64: TryInto<O>,
621{
622 let values = array.values();
623 let original_data = values.to_data();
624 let capacity = Capacities::Array(original_data.len());
625
626 let mut mutable =
627 MutableArrayData::with_capacities(vec![&original_data], true, capacity);
628
629 // We have the slice syntax compatible with DuckDB v0.8.1.
630 // The rule `adjusted_from_index` and `adjusted_to_index` follows the rule of array_slice in duckdb.
631
632 let mut offsets = vec![O::usize_as(0)];
633
634 let nulls = combine_input_nulls(array, from_array, to_array, stride);
635
636 for (row_index, offset_window) in array.offsets().windows(2).enumerate() {
637 let start = offset_window[0];
638 let end = offset_window[1];
639 let len = end - start;
640
641 if nulls.as_ref().is_some_and(|n| n.is_null(row_index)) {
642 mutable.extend_nulls(1);
643 offsets.push(offsets[row_index] + O::usize_as(1));
644 continue;
645 }
646
647 // Empty arrays always return an empty array.
648 if len == O::usize_as(0) {
649 offsets.push(offsets[row_index]);
650 continue;
651 }
652
653 let slice_plan = compute_slice_plan::<O>(
654 len,
655 from_array.value(row_index),
656 to_array.value(row_index),
657 stride.map(|s| s.value(row_index)),
658 )?;
659
660 match slice_plan {
661 SlicePlan::Empty => offsets.push(offsets[row_index]),
662 SlicePlan::Contiguous {
663 start: rel_start,
664 len: slice_len,
665 } => {
666 let start_index = (start + rel_start).to_usize().unwrap();
667 let end_index = (start + rel_start + slice_len).to_usize().unwrap();
668 mutable.extend(0, start_index, end_index);
669 offsets.push(offsets[row_index] + slice_len);
670 }

Callers

nothing calls this directly

Calls 14

combine_input_nullsFunction · 0.85
newFunction · 0.85
make_arrayFunction · 0.85
offsetsMethod · 0.80
value_typeMethod · 0.80
valuesMethod · 0.45
lenMethod · 0.45
as_refMethod · 0.45
is_nullMethod · 0.45
pushMethod · 0.45
valueMethod · 0.45
mapMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…