/// `take` implementation for string arrays
`take` implementation for string arrays
` take ` implementation for string arrays
fn take_string<OffsetSize, IndexType>(
    array: &GenericStringArray<OffsetSize>,
    indices: &PrimitiveArray<IndexType>,
) -> Result<GenericStringArray<OffsetSize>>
where
    OffsetSize: Zero + AddAssign + StringOffsetSizeTrait,
    IndexType: ArrowNumericType,
    IndexType::Native: ToPrimitive,
{
    let data_len = indices.len();
    let bytes_offset = (data_len + 1) * std::mem::size_of::<OffsetSize>();
    let mut offsets_buffer = MutableBuffer::from_len_zeroed(bytes_offset);
    let offsets = offsets_buffer.typed_data_mut();
    let mut values = MutableBuffer::new(0);
    let mut length_so_far = OffsetSize::zero();
    offsets[0] = length_so_far;
    let nulls;
    if array.null_count() == 0 && indices.null_count() == 0 {
        for (i, offset) in offsets.iter_mut().skip(1).enumerate() {
            let index = ToPrimitive::to_usize(&indices.value(i)).ok_or_else(|| {
                ArrowError::ComputeError("Cast to usize failed".to_string())
            })?;
            let s = array.value(index);
            length_so_far += OffsetSize::from_usize(s.len()).unwrap();
            values.extend_from_slice(s.as_bytes());
            *offset = length_so_far;
        }
        nulls = None
    } else if indices.null_count() == 0 {
        let num_bytes = bit_util::ceil(data_len, 8);
        let mut null_buf = MutableBuffer::new(num_bytes).with_bitset(num_bytes, true);
        let null_slice = null_buf.as_slice_mut();
        for (i, offset) in offsets.iter_mut().skip(1).enumerate() {
            let index = ToPrimitive::to_usize(&indices.value(i)).ok_or_else(|| {
                ArrowError::ComputeError("Cast to usize failed".to_string())
            })?;
            if array.is_valid(index) {
                let s = array.value(index);
                length_so_far += OffsetSize::from_usize(s.len()).unwrap();
                values.extend_from_slice(s.as_bytes());
            } else {
                bit_util::unset_bit(null_slice, i);
            }
            *offset = length_so_far;
        }
        nulls = Some(null_buf.into());
    } else if array.null_count() == 0 {
        for (i, offset) in offsets.iter_mut().skip(1).enumerate() {
            if indices.is_valid(i) {
                let index =
                    ToPrimitive::to_usize(&indices.value(i)).ok_or_else(|| {
                        ArrowError::ComputeError("Cast to usize failed".to_string())
                    })?;
                let s = array.value(index);
                length_so_far += OffsetSize::from_usize(s.len()).unwrap();
                values.extend_from_slice(s.as_bytes());
            }
            *offset = length_so_far;
        }
        nulls = indices.data_ref().null_buffer().cloned();
    } else {
        let num_bytes = bit_util::ceil(data_len, 8);
        let mut null_buf = MutableBuffer::new(num_bytes).with_bitset(num_bytes, true);
        let null_slice = null_buf.as_slice_mut();
        for (i, offset) in offsets.iter_mut().skip(1).enumerate() {
            let index = ToPrimitive::to_usize(&indices.value(i)).ok_or_else(|| {
                ArrowError::ComputeError("Cast to usize failed".to_string())
            })?;
            if array.is_valid(index) && indices.is_valid(i) {
                let s = array.value(index);
                length_so_far += OffsetSize::from_usize(s.len()).unwrap();
                values.extend_from_slice(s.as_bytes());
            } else {
                // set null bit
                bit_util::unset_bit(null_slice, i);
            }
            *offset = length_so_far;
        }
        nulls = match indices.data_ref().null_buffer() {
            Some(buffer) => {
                Some(buffer_bin_and(buffer, 0, &null_buf.into(), 0, data_len))
            }
            None => Some(null_buf.into()),
        };
    }
    let mut data = ArrayData::builder(<OffsetSize as StringOffsetSizeTrait>::DATA_TYPE)
        .len(data_len)
        .add_buffer(offsets_buffer.into())
        .add_buffer(values.into());
    if let Some(null_buffer) = nulls {
        data = data.null_bit_buffer(null_buffer);
    }
    Ok(GenericStringArray::<OffsetSize>::from(data.build()))
}
fn take_string < OffsetSize , IndexType > ( array : & GenericStringArray < OffsetSize > , indices : & PrimitiveArray < IndexType > , ) -> Result < GenericStringArray < OffsetSize > > where OffsetSize : Zero + AddAssign + StringOffsetSizeTrait , IndexType : ArrowNumericType , IndexType :: Native : ToPrimitive , { let data_len = indices . len ( ) ; let bytes_offset = ( data_len + 1 ) * std :: mem :: size_of :: < OffsetSize > ( ) ; let mut offsets_buffer = MutableBuffer :: from_len_zeroed ( bytes_offset ) ; let offsets = offsets_buffer . typed_data_mut ( ) ; let mut values = MutableBuffer :: new ( 0 ) ; let mut length_so_far = OffsetSize :: zero ( ) ; offsets [ 0 ] = length_so_far ; let nulls ; if array . null_count ( ) == 0 && indices . null_count ( ) == 0 { for ( i , offset ) in offsets . iter_mut ( ) . skip ( 1 ) . enumerate ( ) { let index = ToPrimitive :: to_usize ( & indices . value ( i ) ) . ok_or_else ( | | { ArrowError :: ComputeError ( " " . to_string ( ) ) } ) ? ; let s = array . value ( index ) ; length_so_far += OffsetSize :: from_usize ( s . len ( ) ) . unwrap ( ) ; values . extend_from_slice ( s . as_bytes ( ) ) ; * offset = length_so_far ; } nulls = None } else if indices . null_count ( ) == 0 { let num_bytes = bit_util :: ceil ( data_len , 8 ) ; let mut null_buf = MutableBuffer :: new ( num_bytes ) . with_bitset ( num_bytes , true ) ; let null_slice = null_buf . as_slice_mut ( ) ; for ( i , offset ) in offsets . iter_mut ( ) . skip ( 1 ) . enumerate ( ) { let index = ToPrimitive :: to_usize ( & indices . value ( i ) ) . ok_or_else ( | | { ArrowError :: ComputeError ( " " . to_string ( ) ) } ) ? ; if array . is_valid ( index ) { let s = array . value ( index ) ; length_so_far += OffsetSize :: from_usize ( s . len ( ) ) . unwrap ( ) ; values . extend_from_slice ( s . as_bytes ( ) ) ; } else { bit_util :: unset_bit ( null_slice , i ) ; } * offset = length_so_far ; } nulls = Some ( null_buf . into ( ) ) ; } else if array . null_count ( ) == 0 { for ( i , offset ) in offsets . iter_mut ( ) . skip ( 1 ) . enumerate ( ) { if indices . is_valid ( i ) { let index = ToPrimitive :: to_usize ( & indices . value ( i ) ) . ok_or_else ( | | { ArrowError :: ComputeError ( " " . to_string ( ) ) } ) ? ; let s = array . value ( index ) ; length_so_far += OffsetSize :: from_usize ( s . len ( ) ) . unwrap ( ) ; values . extend_from_slice ( s . as_bytes ( ) ) ; } * offset = length_so_far ; } nulls = indices . data_ref ( ) . null_buffer ( ) . cloned ( ) ; } else { let num_bytes = bit_util :: ceil ( data_len , 8 ) ; let mut null_buf = MutableBuffer :: new ( num_bytes ) . with_bitset ( num_bytes , true ) ; let null_slice = null_buf . as_slice_mut ( ) ; for ( i , offset ) in offsets . iter_mut ( ) . skip ( 1 ) . enumerate ( ) { let index = ToPrimitive :: to_usize ( & indices . value ( i ) ) . ok_or_else ( | | { ArrowError :: ComputeError ( " " . to_string ( ) ) } ) ? ; if array . is_valid ( index ) && indices . is_valid ( i ) { let s = array . value ( index ) ; length_so_far += OffsetSize :: from_usize ( s . len ( ) ) . unwrap ( ) ; values . extend_from_slice ( s . as_bytes ( ) ) ; } else { // set null bit bit_util :: unset_bit ( null_slice , i ) ; } * offset = length_so_far ; } nulls = match indices . data_ref ( ) . null_buffer ( ) { Some ( buffer ) => { Some ( buffer_bin_and ( buffer , 0 , & null_buf . into ( ) , 0 , data_len ) ) } None => Some ( null_buf . into ( ) ) , } ; } let mut data = ArrayData :: builder ( < OffsetSize as StringOffsetSizeTrait > :: DATA_TYPE ) . len ( data_len ) . add_buffer ( offsets_buffer . into ( ) ) . add_buffer ( values . into ( ) ) ; if let Some ( null_buffer ) = nulls { data = data . null_bit_buffer ( null_buffer ) ; } Ok ( GenericStringArray :: < OffsetSize > :: from ( data . build ( ) ) ) }
`take` implementation for string arrays
` take ` implementation for string arrays
array
&GenericStringArray<OffsetSize>
indices
&PrimitiveArray<IndexType>