/// `take` implementation for boolean arrays
`take` implementation for boolean arrays
` take ` implementation for boolean arrays
fn take_boolean<IndexType>(
    values: &BooleanArray,
    indices: &PrimitiveArray<IndexType>,
) -> Result<BooleanArray>
where
    IndexType: ArrowNumericType,
    IndexType::Native: ToPrimitive,
{
    let data_len = indices.len();
    let num_byte = bit_util::ceil(data_len, 8);
    let mut val_buf = MutableBuffer::from_len_zeroed(num_byte);
    let val_slice = val_buf.as_slice_mut();
    let null_count = values.null_count();
    let nulls;
    if null_count == 0 {
        (0..data_len).try_for_each::<_, Result<()>>(|i| {
            let index = ToPrimitive::to_usize(&indices.value(i)).ok_or_else(|| {
                ArrowError::ComputeError("Cast to usize failed".to_string())
            })?;
            if values.value(index) {
                bit_util::set_bit(val_slice, i);
            }
            Ok(())
        })?;
        nulls = indices.data_ref().null_buffer().cloned();
    } else {
        let mut null_buf = MutableBuffer::new(num_byte).with_bitset(num_byte, true);
        let null_slice = null_buf.as_slice_mut();
        (0..data_len).try_for_each::<_, Result<()>>(|i| {
            let index = ToPrimitive::to_usize(&indices.value(i)).ok_or_else(|| {
                ArrowError::ComputeError("Cast to usize failed".to_string())
            })?;
            if values.is_null(index) {
                bit_util::unset_bit(null_slice, i);
            } else if values.value(index) {
                bit_util::set_bit(val_slice, i);
            }
            Ok(())
        })?;
        nulls = match indices.data_ref().null_buffer() {
            Some(buffer) => Some(buffer_bin_and(
                buffer,
                indices.offset(),
                &null_buf.into(),
                0,
                indices.len(),
            )),
            None => Some(null_buf.into()),
        };
    }
    let data = ArrayData::new(
        DataType::Boolean,
        indices.len(),
        None,
        nulls,
        0,
        vec![val_buf.into()],
        vec![],
    );
    Ok(BooleanArray::from(data))
}
fn take_boolean < IndexType > ( values : & BooleanArray , indices : & PrimitiveArray < IndexType > , ) -> Result < BooleanArray > where IndexType : ArrowNumericType , IndexType :: Native : ToPrimitive , { let data_len = indices . len ( ) ; let num_byte = bit_util :: ceil ( data_len , 8 ) ; let mut val_buf = MutableBuffer :: from_len_zeroed ( num_byte ) ; let val_slice = val_buf . as_slice_mut ( ) ; let null_count = values . null_count ( ) ; let nulls ; if null_count == 0 { ( 0 .. data_len ) . try_for_each :: < _ , Result < ( ) > > ( | i | { let index = ToPrimitive :: to_usize ( & indices . value ( i ) ) . ok_or_else ( | | { ArrowError :: ComputeError ( " " . to_string ( ) ) } ) ? ; if values . value ( index ) { bit_util :: set_bit ( val_slice , i ) ; } Ok ( ( ) ) } ) ? ; nulls = indices . data_ref ( ) . null_buffer ( ) . cloned ( ) ; } else { let mut null_buf = MutableBuffer :: new ( num_byte ) . with_bitset ( num_byte , true ) ; let null_slice = null_buf . as_slice_mut ( ) ; ( 0 .. data_len ) . try_for_each :: < _ , Result < ( ) > > ( | i | { let index = ToPrimitive :: to_usize ( & indices . value ( i ) ) . ok_or_else ( | | { ArrowError :: ComputeError ( " " . to_string ( ) ) } ) ? ; if values . is_null ( index ) { bit_util :: unset_bit ( null_slice , i ) ; } else if values . value ( index ) { bit_util :: set_bit ( val_slice , i ) ; } Ok ( ( ) ) } ) ? ; nulls = match indices . data_ref ( ) . null_buffer ( ) { Some ( buffer ) => Some ( buffer_bin_and ( buffer , indices . offset ( ) , & null_buf . into ( ) , 0 , indices . len ( ) , ) ) , None => Some ( null_buf . into ( ) ) , } ; } let data = ArrayData :: new ( DataType :: Boolean , indices . len ( ) , None , nulls , 0 , vec ! [ val_buf into ( ) ] , vec ! [ ] , ) ; Ok ( BooleanArray :: from ( data ) ) }
`take` implementation for boolean arrays
` take ` implementation for boolean arrays
values
&BooleanArray
indices
&PrimitiveArray<IndexType>