use crate::array::*;
use crate::datatypes::*;
mod binary;
pub use binary::GrowableBinary;
mod boolean;
pub use boolean::GrowableBoolean;
mod fixed_binary;
pub use fixed_binary::GrowableFixedSizeBinary;
mod null;
pub use null::GrowableNull;
mod primitive;
pub use primitive::GrowablePrimitive;
mod list;
pub use list::GrowableList;
mod structure;
pub use structure::GrowableStruct;
mod fixed_size_list;
pub use fixed_size_list::GrowableFixedSizeList;
mod utf8;
pub use utf8::GrowableUtf8;
mod dictionary;
pub use dictionary::GrowableDictionary;
mod binview;
pub use binview::GrowableBinaryViewArray;
mod utils;
pub trait Growable<'a> {
unsafe fn extend(&mut self, index: usize, start: usize, len: usize);
unsafe fn extend_copies(&mut self, index: usize, start: usize, len: usize, copies: usize) {
for _ in 0..copies {
self.extend(index, start, len)
}
}
fn extend_validity(&mut self, additional: usize);
fn len(&self) -> usize;
fn as_arc(&mut self) -> Arc<dyn Array> {
self.as_box().into()
}
fn as_box(&mut self) -> Box<dyn Array>;
}
macro_rules! dyn_growable {
($ty:ty, $arrays:expr, $use_validity:expr, $capacity:expr) => {{
let arrays = $arrays
.iter()
.map(|array| array.as_any().downcast_ref().unwrap())
.collect::<Vec<_>>();
Box::new(<$ty>::new(arrays, $use_validity, $capacity))
}};
}
pub fn make_growable<'a>(
arrays: &[&'a dyn Array],
use_validity: bool,
capacity: usize,
) -> Box<dyn Growable<'a> + 'a> {
assert!(!arrays.is_empty());
let data_type = arrays[0].data_type();
use PhysicalType::*;
match data_type.to_physical_type() {
Null => Box::new(null::GrowableNull::new(data_type.clone())),
Boolean => dyn_growable!(boolean::GrowableBoolean, arrays, use_validity, capacity),
Primitive(primitive) => with_match_primitive_type_full!(primitive, |$T| {
dyn_growable!(primitive::GrowablePrimitive::<$T>, arrays, use_validity, capacity)
}),
Utf8 => dyn_growable!(utf8::GrowableUtf8::<i32>, arrays, use_validity, capacity),
LargeUtf8 => dyn_growable!(utf8::GrowableUtf8::<i64>, arrays, use_validity, capacity),
Binary => dyn_growable!(
binary::GrowableBinary::<i32>,
arrays,
use_validity,
capacity
),
LargeBinary => dyn_growable!(
binary::GrowableBinary::<i64>,
arrays,
use_validity,
capacity
),
FixedSizeBinary => dyn_growable!(
fixed_binary::GrowableFixedSizeBinary,
arrays,
use_validity,
capacity
),
List => dyn_growable!(list::GrowableList::<i32>, arrays, use_validity, capacity),
LargeList => dyn_growable!(list::GrowableList::<i64>, arrays, use_validity, capacity),
Struct => dyn_growable!(structure::GrowableStruct, arrays, use_validity, capacity),
FixedSizeList => dyn_growable!(
fixed_size_list::GrowableFixedSizeList,
arrays,
use_validity,
capacity
),
BinaryView => {
dyn_growable!(
binview::GrowableBinaryViewArray::<[u8]>,
arrays,
use_validity,
capacity
)
},
Utf8View => {
dyn_growable!(
binview::GrowableBinaryViewArray::<str>,
arrays,
use_validity,
capacity
)
},
Dictionary(key_type) => {
match_integer_type!(key_type, |$T| {
let arrays = arrays
.iter()
.map(|array| {
array
.as_any()
.downcast_ref::<DictionaryArray<$T>>()
.unwrap()
})
.collect::<Vec<_>>();
Box::new(dictionary::GrowableDictionary::<$T>::new(
&arrays,
use_validity,
capacity,
))
})
},
Union | Map => unimplemented!(),
}
}