use std::any::TypeId;
use crate::func::def::{FunctionDef, ParameterBindingProvider, Parameters};
use crate::operator::Operator;
use crate::types::matcher::{ExactMatcher, IntervalMatcher, NumericMatcher, OrMatcher};
use crate::types::range::Range;
use crate::types::{Type, TIMESTAMP};
#[derive(Default, Clone)]
pub struct UnaryMinus;
impl FunctionDef for UnaryMinus {
fn name(&self) -> &'static str {
Operator::Minus.str()
}
fn parameters(&self) -> Parameters {
Parameters::new().with(
"x",
OrMatcher::default()
.with(NumericMatcher::default())
.with(IntervalMatcher::default()),
)
}
fn return_type(&self, bindings: &dyn ParameterBindingProvider) -> anyhow::Result<Type> {
Ok(bindings.get_by_index(0)?.typ().clone())
}
fn type_id(&self) -> TypeId {
TypeId::of::<Self>()
}
}
#[derive(Default, Clone)]
pub struct UnaryPlus;
impl FunctionDef for UnaryPlus {
fn name(&self) -> &'static str {
Operator::Plus.str()
}
fn parameters(&self) -> Parameters {
Parameters::new().with("x", NumericMatcher::default())
}
fn return_type(&self, bindings: &dyn ParameterBindingProvider) -> anyhow::Result<Type> {
Ok(bindings.get_by_index(0)?.typ().clone())
}
fn type_id(&self) -> TypeId {
TypeId::of::<Self>()
}
}
#[derive(Default, Clone)]
pub struct UnaryRangePrefix;
impl FunctionDef for UnaryRangePrefix {
fn name(&self) -> &'static str {
Operator::Range.str()
}
fn parameters(&self) -> Parameters {
Parameters::new().with(
"x",
OrMatcher::default()
.with(NumericMatcher::default())
.with(IntervalMatcher::default())
.with(ExactMatcher::of(TIMESTAMP)),
)
}
fn return_type(&self, bindings: &dyn ParameterBindingProvider) -> anyhow::Result<Type> {
Ok(Range::new(bindings.get_by_index(0)?.typ().clone()).into())
}
fn type_id(&self) -> TypeId {
TypeId::of::<Self>()
}
}
#[derive(Default, Clone)]
pub struct UnaryRangePostfix;
impl FunctionDef for UnaryRangePostfix {
fn name(&self) -> &'static str {
Operator::Range.str()
}
fn parameters(&self) -> Parameters {
Parameters::new().with(
"x",
OrMatcher::default()
.with(NumericMatcher::default())
.with(IntervalMatcher::default())
.with(ExactMatcher::of(TIMESTAMP)),
)
}
fn return_type(&self, bindings: &dyn ParameterBindingProvider) -> anyhow::Result<Type> {
Ok(Range::new(bindings.get_by_index(0)?.typ().clone()).into())
}
fn type_id(&self) -> TypeId {
TypeId::of::<Self>()
}
}