vortex_array/arrow/
record_batch.rs1use arrow_array::RecordBatch;
5use arrow_array::cast::AsArray;
6use vortex_error::{VortexError, VortexResult, vortex_bail, vortex_ensure};
7
8use crate::arrow::compute::to_arrow_preferred;
9use crate::{Array, Canonical};
10
11impl TryFrom<&dyn Array> for RecordBatch {
12 type Error = VortexError;
13
14 fn try_from(value: &dyn Array) -> VortexResult<Self> {
15 let Canonical::Struct(struct_array) = value.to_canonical() else {
16 vortex_bail!("RecordBatch can only be constructed from ")
17 };
18
19 vortex_ensure!(
20 struct_array.all_valid(),
21 "RecordBatch can only be constructed from StructArray with no nulls"
22 );
23
24 let array_ref = to_arrow_preferred(struct_array.as_ref())?;
25 Ok(RecordBatch::from(array_ref.as_struct()))
26 }
27}