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