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