Skip to main content

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 convert;
11mod datum;
12mod executor;
13mod iter;
14mod null_buffer;
15mod record_batch;
16
17pub use datum::*;
18pub use executor::*;
19pub use iter::*;
20
21use crate::LEGACY_SESSION;
22use crate::VortexSessionExecute;
23
24pub trait FromArrowArray<A> {
25    fn from_arrow(array: A, nullable: bool) -> VortexResult<Self>
26    where
27        Self: Sized;
28}
29
30pub trait IntoArrowArray {
31    fn into_arrow_preferred(self) -> VortexResult<ArrowArrayRef>;
32
33    fn into_arrow(self, data_type: &DataType) -> VortexResult<ArrowArrayRef>;
34}
35
36impl IntoArrowArray for crate::ArrayRef {
37    /// Convert this [`crate::ArrayRef`] into an Arrow [`crate::ArrayRef`] by using the array's
38    /// preferred (cheapest) Arrow [`DataType`].
39    fn into_arrow_preferred(self) -> VortexResult<ArrowArrayRef> {
40        self.execute_arrow(None, &mut LEGACY_SESSION.create_execution_ctx())
41    }
42
43    fn into_arrow(self, data_type: &DataType) -> VortexResult<ArrowArrayRef> {
44        self.execute_arrow(Some(data_type), &mut LEGACY_SESSION.create_execution_ctx())
45    }
46}