vortex_array/arrow/
mod.rs

1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright the Vortex contributors
3
4//! Utilities to work with `Arrow` data and types.
5
6use arrow_array::ArrayRef as ArrowArrayRef;
7use arrow_schema::DataType;
8use vortex_error::VortexResult;
9
10mod array;
11pub mod compute;
12mod convert;
13mod datum;
14mod iter;
15mod record_batch;
16
17pub use array::*;
18pub(crate) use compute::warm_up_vtable;
19pub use datum::*;
20pub use iter::*;
21
22use crate::arrow::compute::ToArrowOptions;
23
24pub trait FromArrowArray<A> {
25    fn from_arrow(array: A, nullable: bool) -> Self;
26}
27
28pub trait IntoArrowArray {
29    fn into_arrow_preferred(self) -> VortexResult<ArrowArrayRef>;
30
31    fn into_arrow(self, data_type: &DataType) -> VortexResult<ArrowArrayRef>;
32}
33
34impl IntoArrowArray for crate::ArrayRef {
35    /// Convert this [`crate::ArrayRef`] into an Arrow [`crate::ArrayRef`] by using the array's preferred
36    /// Arrow [`DataType`].
37    fn into_arrow_preferred(self) -> VortexResult<ArrowArrayRef> {
38        compute::to_arrow_opts(&self, &ToArrowOptions { arrow_type: None })
39    }
40
41    fn into_arrow(self, data_type: &DataType) -> VortexResult<ArrowArrayRef> {
42        compute::to_arrow_opts(
43            &self,
44            &ToArrowOptions {
45                arrow_type: Some(data_type.clone()),
46            },
47        )
48    }
49}