use arrow_array::{downcast_primitive, ArrayRef};
use arrow_schema::SchemaRef;
use datafusion_common::Result;
use datafusion_physical_expr::EmitTo;
mod primitive;
use primitive::GroupValuesPrimitive;
mod row;
use row::GroupValuesRows;
pub trait GroupValues: Send {
fn intern(&mut self, cols: &[ArrayRef], groups: &mut Vec<usize>) -> Result<()>;
fn size(&self) -> usize;
fn is_empty(&self) -> bool;
fn len(&self) -> usize;
fn emit(&mut self, emit_to: EmitTo) -> Result<Vec<ArrayRef>>;
}
pub fn new_group_values(schema: SchemaRef) -> Result<Box<dyn GroupValues>> {
if schema.fields.len() == 1 {
let d = schema.fields[0].data_type();
macro_rules! downcast_helper {
($t:ty, $d:ident) => {
return Ok(Box::new(GroupValuesPrimitive::<$t>::new($d.clone())))
};
}
downcast_primitive! {
d => (downcast_helper, d),
_ => {}
}
}
Ok(Box::new(GroupValuesRows::try_new(schema)?))
}