use vortex_array::dtype::DType;
use vortex_array::dtype::FieldName;
use vortex_array::scalar::NumericOperator;
use vortex_array::scalar_fn::EmptyOptions;
use vortex_array::scalar_fn::builtin::boolean::Boolean;
use vortex_array::scalar_fn::builtin::cast::Cast;
use vortex_array::scalar_fn::builtin::compare::Compare;
use vortex_array::scalar_fn::builtin::fill_null::FillNull;
use vortex_array::scalar_fn::builtin::get_item::GetItem;
use vortex_array::scalar_fn::builtin::is_not_null::IsNotNull;
use vortex_array::scalar_fn::builtin::mask::Mask;
use vortex_array::scalar_fn::builtin::not::Not;
use vortex_array::scalar_fn::builtin::numeric::Numeric;
use vortex_array::scalar_fn::builtin::operators::BooleanOperator;
use vortex_array::scalar_fn::builtin::operators::CompareOperator;
use vortex_error::VortexResult;
use crate::Expression;
use crate::ScalarFnExprExt;
pub trait ExprBuiltins: Sized {
fn cast(&self, dtype: DType) -> VortexResult<Expression>;
fn fill_null(&self, fill_value: Expression) -> VortexResult<Expression>;
fn get_item(&self, field_name: impl Into<FieldName>) -> VortexResult<Expression>;
fn is_not_null(&self) -> VortexResult<Expression>;
fn mask(&self, mask: Expression) -> VortexResult<Expression>;
fn not(&self) -> VortexResult<Expression>;
fn compare(&self, rhs: Expression, op: CompareOperator) -> VortexResult<Expression>;
fn boolean(&self, rhs: Expression, op: BooleanOperator) -> VortexResult<Expression>;
fn numeric(&self, rhs: Expression, op: NumericOperator) -> VortexResult<Expression>;
}
impl ExprBuiltins for Expression {
fn cast(&self, dtype: DType) -> VortexResult<Expression> {
Cast.try_new_expr(dtype, [self.clone()])
}
fn fill_null(&self, fill_value: Expression) -> VortexResult<Expression> {
FillNull.try_new_expr(EmptyOptions, [self.clone(), fill_value])
}
fn get_item(&self, field_name: impl Into<FieldName>) -> VortexResult<Expression> {
GetItem.try_new_expr(field_name.into(), [self.clone()])
}
fn is_not_null(&self) -> VortexResult<Expression> {
IsNotNull.try_new_expr(EmptyOptions, [self.clone()])
}
fn mask(&self, mask: Expression) -> VortexResult<Expression> {
Mask.try_new_expr(EmptyOptions, [self.clone(), mask])
}
fn not(&self) -> VortexResult<Expression> {
Not.try_new_expr(EmptyOptions, [self.clone()])
}
fn compare(&self, rhs: Expression, op: CompareOperator) -> VortexResult<Expression> {
Compare.try_new_expr(op, [self.clone(), rhs])
}
fn boolean(&self, rhs: Expression, op: BooleanOperator) -> VortexResult<Expression> {
Boolean.try_new_expr(op, [self.clone(), rhs])
}
fn numeric(&self, rhs: Expression, op: NumericOperator) -> VortexResult<Expression> {
Numeric.try_new_expr(op, [self.clone(), rhs])
}
}