use crate::Expr;
use crate::{
AccumulatorFunctionImplementation, ReturnTypeFunction, Signature, StateTypeFunction,
};
use std::fmt::{self, Debug, Formatter};
use std::sync::Arc;
#[derive(Clone)]
pub struct AggregateUDF {
pub name: String,
pub signature: Signature,
pub return_type: ReturnTypeFunction,
pub accumulator: AccumulatorFunctionImplementation,
pub state_type: StateTypeFunction,
}
impl Debug for AggregateUDF {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
f.debug_struct("AggregateUDF")
.field("name", &self.name)
.field("signature", &self.signature)
.field("fun", &"<FUNC>")
.finish()
}
}
impl PartialEq for AggregateUDF {
fn eq(&self, other: &Self) -> bool {
self.name == other.name && self.signature == other.signature
}
}
impl Eq for AggregateUDF {}
impl std::hash::Hash for AggregateUDF {
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
self.name.hash(state);
self.signature.hash(state);
}
}
impl AggregateUDF {
pub fn new(
name: &str,
signature: &Signature,
return_type: &ReturnTypeFunction,
accumulator: &AccumulatorFunctionImplementation,
state_type: &StateTypeFunction,
) -> Self {
Self {
name: name.to_owned(),
signature: signature.clone(),
return_type: return_type.clone(),
accumulator: accumulator.clone(),
state_type: state_type.clone(),
}
}
pub fn call(&self, args: Vec<Expr>) -> Expr {
Expr::AggregateUDF {
fun: Arc::new(self.clone()),
args,
filter: None,
}
}
}