/// `take` implementation for list arrays
///
/// Calculates the index and indexed offset for the inner array,
/// applying `take` on the inner array, then reconstructing a list array
/// with the indexed offsets
`take` implementation for list arrays
Calculates the index and indexed offset for the inner array,
applying `take` on the inner array, then reconstructing a list array
with the indexed offsets
` take ` implementation for list arrays Calculates the index and indexed offset for the inner array applying ` take ` on the inner array then reconstructing a list array with the indexed offsets
fn take_list<IndexType, OffsetType>(
    values: &GenericListArray<OffsetType::Native>,
    indices: &PrimitiveArray<IndexType>,
) -> Result<GenericListArray<OffsetType::Native>>
where
    IndexType: ArrowNumericType,
    IndexType::Native: ToPrimitive,
    OffsetType: ArrowNumericType,
    OffsetType::Native: ToPrimitive + OffsetSizeTrait,
    PrimitiveArray<OffsetType>: From<Vec<Option<OffsetType::Native>>>,
{
    // TODO: Some optimizations can be done here such as if it is
    // taking the whole list or a contiguous sublist
    let (list_indices, offsets) =
        take_value_indices_from_list::<IndexType, OffsetType>(values, indices)?;
    let taken = take_impl::<OffsetType>(values.values().as_ref(), &list_indices, None)?;
    // determine null count and null buffer, which are a function of `values` and `indices`
    let mut null_count = 0;
    let num_bytes = bit_util::ceil(indices.len(), 8);
    let mut null_buf = MutableBuffer::new(num_bytes).with_bitset(num_bytes, true);
    {
        let null_slice = null_buf.as_slice_mut();
        offsets[..].windows(2).enumerate().for_each(
            |(i, window): (usize, &[OffsetType::Native])| {
                if window[0] == window[1] {
                    // offsets are equal, slot is null
                    bit_util::unset_bit(null_slice, i);
                    null_count += 1;
                }
            },
        );
    }
    let value_offsets = Buffer::from_slice_ref(&offsets);
    // create a new list with taken data and computed null information
    let list_data = ArrayDataBuilder::new(values.data_type().clone())
        .len(indices.len())
        .null_bit_buffer(null_buf.into())
        .offset(0)
        .add_child_data(taken.data().clone())
        .add_buffer(value_offsets)
        .build();
    Ok(GenericListArray::<OffsetType::Native>::from(list_data))
}
fn take_list < IndexType , OffsetType > ( values : & GenericListArray < OffsetType :: Native > , indices : & PrimitiveArray < IndexType > , ) -> Result < GenericListArray < OffsetType :: Native > > where IndexType : ArrowNumericType , IndexType :: Native : ToPrimitive , OffsetType : ArrowNumericType , OffsetType :: Native : ToPrimitive + OffsetSizeTrait , PrimitiveArray < OffsetType > : From < Vec < Option < OffsetType :: Native > > > , { // TODO: Some optimizations can be done here such as if it is // taking the whole list or a contiguous sublist let ( list_indices , offsets ) = take_value_indices_from_list :: < IndexType , OffsetType > ( values , indices ) ? ; let taken = take_impl :: < OffsetType > ( values . values ( ) . as_ref ( ) , & list_indices , None ) ? ; // determine null count and null buffer, which are a function of `values` and `indices` let mut null_count = 0 ; let num_bytes = bit_util :: ceil ( indices . len ( ) , 8 ) ; let mut null_buf = MutableBuffer :: new ( num_bytes ) . with_bitset ( num_bytes , true ) ; { let null_slice = null_buf . as_slice_mut ( ) ; offsets [ .. ] . windows ( 2 ) . enumerate ( ) . for_each ( | ( i , window ) : ( usize , & [ OffsetType :: Native ] ) | { if window [ 0 ] == window [ 1 ] { // offsets are equal, slot is null bit_util :: unset_bit ( null_slice , i ) ; null_count += 1 ; } } , ) ; } let value_offsets = Buffer :: from_slice_ref ( & offsets ) ; // create a new list with taken data and computed null information let list_data = ArrayDataBuilder :: new ( values . data_type ( ) . clone ( ) ) . len ( indices . len ( ) ) . null_bit_buffer ( null_buf . into ( ) ) . offset ( 0 ) . add_child_data ( taken . data ( ) . clone ( ) ) . add_buffer ( value_offsets ) . build ( ) ; Ok ( GenericListArray :: < OffsetType :: Native > :: from ( list_data ) ) }
`take` implementation for list arrays
Calculates the index and indexed offset for the inner array,
applying `take` on the inner array, then reconstructing a list array
with the indexed offsets
` take ` implementation for list arrays Calculates the index and indexed offset for the inner array applying ` take ` on the inner array then reconstructing a list array with the indexed offsets
values
&GenericListArray<OffsetType::Native>
indices
&PrimitiveArray<IndexType>