pub(super) fn take_value_indices_from_list<IndexType, OffsetType>(
    list: &GenericListArray<OffsetType::Native>,
    indices: &PrimitiveArray<IndexType>,
) -> Result<(PrimitiveArray<OffsetType>, Vec<OffsetType::Native>)>
where
    IndexType: ArrowNumericType,
    IndexType::Native: ToPrimitive,
    OffsetType: ArrowNumericType,
    OffsetType::Native: OffsetSizeTrait + Add + Zero + One,
    PrimitiveArray<OffsetType>: From<Vec<Option<OffsetType::Native>>>,
{
    // TODO: benchmark this function, there might be a faster unsafe alternative
    // get list array's offsets
    let offsets: Vec<OffsetType::Native> =
        (0..=list.len()).map(|i| list.value_offset(i)).collect();

    let mut new_offsets = Vec::with_capacity(indices.len());
    let mut values = Vec::new();
    let mut current_offset = OffsetType::Native::zero();
    // add first offset
    new_offsets.push(OffsetType::Native::zero());
    // compute the value indices, and set offsets accordingly
    for i in 0..indices.len() {
        if indices.is_valid(i) {
            let ix = ToPrimitive::to_usize(&indices.value(i)).ok_or_else(|| {
                ArrowError::ComputeError("Cast to usize failed".to_string())
            })?;
            let start = offsets[ix];
            let end = offsets[ix + 1];
            current_offset = current_offset + (end - start);
            new_offsets.push(current_offset);

            let mut curr = start;

            // if start == end, this slot is empty
            while curr < end {
                values.push(Some(curr));
                curr = curr + OffsetType::Native::one();
            }
        } else {
            new_offsets.push(current_offset);
        }
    }

    Ok((PrimitiveArray::<OffsetType>::from(values), new_offsets))
}
/// Takes/filters a list array's inner data using the offsets of the list array.
///
/// Where a list array has indices `[0,2,5,10]`, taking indices of `[2,0]` returns
/// an array of the indices `[5..10, 0..2]` and offsets `[0,5,7]` (5 elements and 2
/// elements)
Takes/filters a list array's inner data using the offsets of the list array.
Takes / filters a list array ' s inner data using the offsets of the list array .
pub(super) fn take_value_indices_from_list<IndexType, OffsetType>(
    list: &GenericListArray<OffsetType::Native>,
    indices: &PrimitiveArray<IndexType>,
) -> Result<(PrimitiveArray<OffsetType>, Vec<OffsetType::Native>)>
where
    IndexType: ArrowNumericType,
    IndexType::Native: ToPrimitive,
    OffsetType: ArrowNumericType,
    OffsetType::Native: OffsetSizeTrait + Add + Zero + One,
    PrimitiveArray<OffsetType>: From<Vec<Option<OffsetType::Native>>>,
{
    // TODO: benchmark this function, there might be a faster unsafe alternative
    // get list array's offsets
    let offsets: Vec<OffsetType::Native> =
        (0..=list.len()).map(|i| list.value_offset(i)).collect();
    let mut new_offsets = Vec::with_capacity(indices.len());
    let mut values = Vec::new();
    let mut current_offset = OffsetType::Native::zero();
    // add first offset
    new_offsets.push(OffsetType::Native::zero());
    // compute the value indices, and set offsets accordingly
    for i in 0..indices.len() {
        if indices.is_valid(i) {
            let ix = ToPrimitive::to_usize(&indices.value(i)).ok_or_else(|| {
                ArrowError::ComputeError("Cast to usize failed".to_string())
            })?;
            let start = offsets[ix];
            let end = offsets[ix + 1];
            current_offset = current_offset + (end - start);
            new_offsets.push(current_offset);
            let mut curr = start;
            // if start == end, this slot is empty
            while curr < end {
                values.push(Some(curr));
                curr = curr + OffsetType::Native::one();
            }
        } else {
            new_offsets.push(current_offset);
        }
    }
    Ok((PrimitiveArray::<OffsetType>::from(values), new_offsets))
}
pub ( super ) fn take_value_indices_from_list < IndexType , OffsetType > ( list : & GenericListArray < OffsetType :: Native > , indices : & PrimitiveArray < IndexType > , ) -> Result < ( PrimitiveArray < OffsetType > , Vec < OffsetType :: Native > ) > where IndexType : ArrowNumericType , IndexType :: Native : ToPrimitive , OffsetType : ArrowNumericType , OffsetType :: Native : OffsetSizeTrait + Add + Zero + One , PrimitiveArray < OffsetType > : From < Vec < Option < OffsetType :: Native > > > , { // TODO: benchmark this function, there might be a faster unsafe alternative // get list array's offsets let offsets : Vec < OffsetType :: Native > = ( 0 ..= list . len ( ) ) . map ( | i | list . value_offset ( i ) ) . collect ( ) ; let mut new_offsets = Vec :: with_capacity ( indices . len ( ) ) ; let mut values = Vec :: new ( ) ; let mut current_offset = OffsetType :: Native :: zero ( ) ; // add first offset new_offsets . push ( OffsetType :: Native :: zero ( ) ) ; // compute the value indices, and set offsets accordingly for i in 0 .. indices . len ( ) { if indices . is_valid ( i ) { let ix = ToPrimitive :: to_usize ( & indices . value ( i ) ) . ok_or_else ( | | { ArrowError :: ComputeError ( " " . to_string ( ) ) } ) ? ; let start = offsets [ ix ] ; let end = offsets [ ix + 1 ] ; current_offset = current_offset + ( end - start ) ; new_offsets . push ( current_offset ) ; let mut curr = start ; // if start == end, this slot is empty while curr < end { values . push ( Some ( curr ) ) ; curr = curr + OffsetType :: Native :: one ( ) ; } } else { new_offsets . push ( current_offset ) ; } } Ok ( ( PrimitiveArray :: < OffsetType > :: from ( values ) , new_offsets ) ) }
Takes/filters a list array's inner data using the offsets of the list array.
Takes / filters a list array ' s inner data using the offsets of the list array .
list
&GenericListArray<OffsetType::Native>
indices
&PrimitiveArray<IndexType>
list
&GenericListArray<OffsetType::Native>
indices
&PrimitiveArray<IndexType>