vortex_array/arrow/compute/to_arrow/
mod.rs1use std::any::Any;
5
6use arrow_array::ArrayRef as ArrowArrayRef;
7use arrow_schema::DataType;
8use vortex_error::VortexResult;
9use vortex_error::vortex_ensure;
10
11use crate::Array;
12use crate::LEGACY_SESSION;
13use crate::VortexSessionExecute;
14use crate::arrow::ArrowArrayExecutor;
15use crate::compute::Options;
16
17#[deprecated(note = "Use ArrowArrayExecutor::execute_arrow instead")]
25#[expect(deprecated)]
26pub fn to_arrow_preferred(array: &dyn Array) -> VortexResult<ArrowArrayRef> {
27 to_arrow_opts(array, &ToArrowOptions { arrow_type: None })
28}
29
30#[deprecated(note = "Use ArrowArrayExecutor::execute_arrow instead")]
32pub fn to_arrow(array: &dyn Array, arrow_type: &DataType) -> VortexResult<ArrowArrayRef> {
33 let mut ctx = LEGACY_SESSION.create_execution_ctx();
34 array.to_array().execute_arrow(Some(arrow_type), &mut ctx)
35}
36
37#[deprecated(note = "Use ArrowArrayExecutor::execute_arrow instead")]
38#[expect(deprecated)]
39pub fn to_arrow_opts(array: &dyn Array, options: &ToArrowOptions) -> VortexResult<ArrowArrayRef> {
40 let data_type = if let Some(data_type) = &options.arrow_type {
41 data_type.clone()
42 } else {
43 array.dtype().to_arrow_dtype()?
44 };
45 let arrow = to_arrow(array, &data_type)?;
46
47 vortex_ensure!(
48 &data_type == arrow.data_type(),
49 "to arrow returned array with data_type {}, expected {}",
50 arrow.data_type(),
51 data_type
52 );
53
54 Ok(arrow)
55}
56
57pub struct ToArrowOptions {
58 pub arrow_type: Option<DataType>,
60}
61
62impl Options for ToArrowOptions {
63 fn as_any(&self) -> &dyn Any {
64 self
65 }
66}