1use vortex_array::dtype::DType;
7use vortex_array::dtype::FieldName;
8use vortex_array::scalar::NumericOperator;
9use vortex_array::scalar_fn::EmptyOptions;
10use vortex_array::scalar_fn::builtin::boolean::Boolean;
11use vortex_array::scalar_fn::builtin::cast::Cast;
12use vortex_array::scalar_fn::builtin::compare::Compare;
13use vortex_array::scalar_fn::builtin::fill_null::FillNull;
14use vortex_array::scalar_fn::builtin::get_item::GetItem;
15use vortex_array::scalar_fn::builtin::is_not_null::IsNotNull;
16use vortex_array::scalar_fn::builtin::mask::Mask;
17use vortex_array::scalar_fn::builtin::not::Not;
18use vortex_array::scalar_fn::builtin::numeric::Numeric;
19use vortex_array::scalar_fn::builtin::operators::BooleanOperator;
20use vortex_array::scalar_fn::builtin::operators::CompareOperator;
21use vortex_error::VortexResult;
22
23use crate::Expression;
24use crate::ScalarFnExprExt;
25
26pub trait ExprBuiltins: Sized {
28 fn cast(&self, dtype: DType) -> VortexResult<Expression>;
30
31 fn fill_null(&self, fill_value: Expression) -> VortexResult<Expression>;
33
34 fn get_item(&self, field_name: impl Into<FieldName>) -> VortexResult<Expression>;
36
37 fn is_not_null(&self) -> VortexResult<Expression>;
39
40 fn mask(&self, mask: Expression) -> VortexResult<Expression>;
44
45 fn not(&self) -> VortexResult<Expression>;
47
48 fn compare(&self, rhs: Expression, op: CompareOperator) -> VortexResult<Expression>;
52
53 fn boolean(&self, rhs: Expression, op: BooleanOperator) -> VortexResult<Expression>;
55
56 fn numeric(&self, rhs: Expression, op: NumericOperator) -> VortexResult<Expression>;
58}
59
60impl ExprBuiltins for Expression {
61 fn cast(&self, dtype: DType) -> VortexResult<Expression> {
62 Cast.try_new_expr(dtype, [self.clone()])
63 }
64
65 fn fill_null(&self, fill_value: Expression) -> VortexResult<Expression> {
66 FillNull.try_new_expr(EmptyOptions, [self.clone(), fill_value])
67 }
68
69 fn get_item(&self, field_name: impl Into<FieldName>) -> VortexResult<Expression> {
70 GetItem.try_new_expr(field_name.into(), [self.clone()])
71 }
72
73 fn is_not_null(&self) -> VortexResult<Expression> {
74 IsNotNull.try_new_expr(EmptyOptions, [self.clone()])
75 }
76
77 fn mask(&self, mask: Expression) -> VortexResult<Expression> {
78 Mask.try_new_expr(EmptyOptions, [self.clone(), mask])
79 }
80
81 fn not(&self) -> VortexResult<Expression> {
82 Not.try_new_expr(EmptyOptions, [self.clone()])
83 }
84
85 fn compare(&self, rhs: Expression, op: CompareOperator) -> VortexResult<Expression> {
86 Compare.try_new_expr(op, [self.clone(), rhs])
87 }
88
89 fn boolean(&self, rhs: Expression, op: BooleanOperator) -> VortexResult<Expression> {
90 Boolean.try_new_expr(op, [self.clone(), rhs])
91 }
92
93 fn numeric(&self, rhs: Expression, op: NumericOperator) -> VortexResult<Expression> {
94 Numeric.try_new_expr(op, [self.clone(), rhs])
95 }
96}