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

Function adjust_offsets_for_slice

datafusion/common/src/utils/mod.rs:1102–1117  ·  view source on GitHub ↗

If `list` is sliced, returns an adjusted offset buffer so that it points to the sliced portion of the list values, and not the whole list values

(
    list: &GenericListArray<O>,
)

Source from the content-addressed store, hash-verified

1100/// If `list` is sliced, returns an adjusted offset buffer so that
1101/// it points to the sliced portion of the list values, and not the whole list values
1102pub fn adjust_offsets_for_slice<O: OffsetSizeTrait>(
1103 list: &GenericListArray<O>,
1104) -> OffsetBuffer<O> {
1105 let offsets = list.offsets();
1106
1107 if let (Some(first), Some(last)) = (offsets.first(), offsets.last())
1108 && (!first.is_zero() || last.as_usize() != list.values().len())
1109 {
1110 let offsets = offsets.iter().map(|offset| *offset - *first).collect();
1111
1112 //todo: use unsafe Offset::new_unchecked?
1113 return OffsetBuffer::new(offsets);
1114 }
1115
1116 offsets.clone()
1117}
1118
1119/// For lists and large lists, truncates the sublist of null values
1120/// Otherwise returns an error

Callers 2

invoke_with_argsMethod · 0.85
invoke_with_argsMethod · 0.85

Calls 11

newFunction · 0.85
offsetsMethod · 0.80
lastMethod · 0.80
collectMethod · 0.80
firstMethod · 0.45
as_usizeMethod · 0.45
lenMethod · 0.45
valuesMethod · 0.45
mapMethod · 0.45
iterMethod · 0.45
cloneMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…