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