Macro arrow_array::downcast_run_end_index
source · macro_rules! downcast_run_end_index { ($($data_type:expr),+ => ($m:path $(, $args:tt)*), $($p:pat => $fallback:expr $(,)*)*) => { ... }; }
Expand description
Given one or more expressions evaluating to an integer DataType
invokes the provided macro
m
with the corresponding integer RunEndIndexType
, followed by any additional arguments
macro_rules! run_end_size_helper {
($t:ty, $o:ty) => {
std::mem::size_of::<<$t as ArrowPrimitiveType>::Native>() as $o
};
}
fn run_end_index_size(t: &DataType) -> u8 {
match t {
DataType::RunEndEncoded(k, _) => downcast_run_end_index! {
k.data_type() => (run_end_size_helper, u8),
_ => unreachable!(),
},
_ => u8::MAX,
}
}
assert_eq!(run_end_index_size(&DataType::RunEndEncoded(Arc::new(Field::new("a", DataType::Int32, false)), Arc::new(Field::new("b", DataType::Utf8, true)))), 4);
assert_eq!(run_end_index_size(&DataType::RunEndEncoded(Arc::new(Field::new("a", DataType::Int64, false)), Arc::new(Field::new("b", DataType::Utf8, true)))), 8);
assert_eq!(run_end_index_size(&DataType::RunEndEncoded(Arc::new(Field::new("a", DataType::Int16, false)), Arc::new(Field::new("b", DataType::Utf8, true)))), 2);