Skip to main content

vortex_arrow/executor/
null.rs

1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright the Vortex contributors
3
4use std::sync::Arc;
5
6use arrow_array::ArrayRef as ArrowArrayRef;
7use arrow_array::NullArray as ArrowNullArray;
8use vortex_array::ArrayRef;
9use vortex_array::ExecutionCtx;
10use vortex_array::arrays::NullArray;
11use vortex_array::dtype::DType;
12use vortex_error::VortexResult;
13use vortex_error::vortex_ensure;
14
15/// Convert a canonical NullArray directly to Arrow.
16pub fn canonical_null_to_arrow(array: &NullArray) -> ArrowArrayRef {
17    Arc::new(ArrowNullArray::new(array.len()))
18}
19
20pub(super) fn to_arrow_null(
21    array: ArrayRef,
22    ctx: &mut ExecutionCtx,
23) -> VortexResult<ArrowArrayRef> {
24    vortex_ensure!(
25        matches!(array.dtype(), DType::Null),
26        "Cannot convert Vortex array with dtype {} to an Arrow Null array",
27        array.dtype()
28    );
29    let null_array = array.execute::<NullArray>(ctx)?;
30    Ok(canonical_null_to_arrow(&null_array))
31}