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 executor;
15mod iter;
16mod null_buffer;
17mod record_batch;
18
19pub use array::*;
20pub(crate) use compute::warm_up_vtable;
21pub use datum::*;
22pub use executor::*;
23pub use iter::*;
24
25use crate::arrow::compute::ToArrowOptions;
26
27pub trait FromArrowArray<A> {
28    fn from_arrow(array: A, nullable: bool) -> Self;
29}
30
31pub trait IntoArrowArray {
32    fn into_arrow_preferred(self) -> VortexResult<ArrowArrayRef>;
33
34    fn into_arrow(self, data_type: &DataType) -> VortexResult<ArrowArrayRef>;
35}
36
37impl IntoArrowArray for crate::ArrayRef {
38    /// Convert this [`crate::ArrayRef`] into an Arrow [`crate::ArrayRef`] by using the array's
39    /// preferred Arrow [`DataType`].
40    fn into_arrow_preferred(self) -> VortexResult<ArrowArrayRef> {
41        compute::to_arrow_opts(&self, &ToArrowOptions { arrow_type: None })
42    }
43
44    fn into_arrow(self, data_type: &DataType) -> VortexResult<ArrowArrayRef> {
45        compute::to_arrow_opts(
46            &self,
47            &ToArrowOptions {
48                arrow_type: Some(data_type.clone()),
49            },
50        )
51    }
52}