vortex_arrow/executor/
primitive.rs1use std::sync::Arc;
5
6use arrow_array::ArrayRef as ArrowArrayRef;
7use arrow_array::ArrowPrimitiveType;
8use arrow_array::PrimitiveArray as ArrowPrimitiveArray;
9use vortex_array::ArrayRef;
10use vortex_array::ExecutionCtx;
11use vortex_array::arrays::PrimitiveArray;
12use vortex_array::builtins::ArrayBuiltins;
13use vortex_array::dtype::DType;
14use vortex_array::dtype::NativePType;
15use vortex_array::dtype::Nullability;
16use vortex_error::VortexResult;
17
18use crate::null_buffer::to_null_buffer;
19
20pub fn canonical_primitive_to_arrow<T: ArrowPrimitiveType>(
22 array: PrimitiveArray,
23 ctx: &mut ExecutionCtx,
24) -> VortexResult<ArrowArrayRef>
25where
26 T::Native: NativePType,
27{
28 let validity = array
29 .as_ref()
30 .validity()?
31 .execute_mask(array.as_ref().len(), ctx)?;
32 let null_buffer = to_null_buffer(validity);
33 let buffer = array.into_buffer::<T::Native>().into_arrow_scalar_buffer();
34 Ok(Arc::new(ArrowPrimitiveArray::<T>::new(buffer, null_buffer)))
35}
36
37pub(super) fn to_arrow_primitive<T: ArrowPrimitiveType>(
38 array: ArrayRef,
39 ctx: &mut ExecutionCtx,
40) -> VortexResult<ArrowArrayRef>
41where
42 T::Native: NativePType,
43{
44 let array = array.cast(DType::Primitive(T::Native::PTYPE, Nullability::Nullable))?;
46 let primitive = array.execute::<PrimitiveArray>(ctx)?;
47 canonical_primitive_to_arrow::<T>(primitive, ctx)
48}