polars_arrow/legacy/
conversion.rs1use crate::array::{ArrayRef, PrimitiveArray, StructArray};
2use crate::datatypes::{ArrowDataType, Field};
3use crate::record_batch::RecordBatchT;
4use crate::types::NativeType;
5
6pub fn chunk_to_struct(chunk: RecordBatchT<ArrayRef>, fields: Vec<Field>) -> StructArray {
7 let dtype = ArrowDataType::Struct(fields);
8 StructArray::new(dtype, chunk.len(), chunk.into_arrays(), None)
9}
10
11pub fn primitive_to_vec<T: NativeType>(arr: ArrayRef) -> Option<Vec<T>> {
20 let arr_ref = arr.as_any().downcast_ref::<PrimitiveArray<T>>().unwrap();
21 let buffer = arr_ref.values().clone();
22 drop(arr); buffer.into_mut().right()
24}