vortex_array/arrow/
mod.rs

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