vortex_array/scalar_fns/
mod.rs1use vortex_dtype::DType;
13use vortex_dtype::FieldName;
14use vortex_error::VortexResult;
15
16use crate::Array;
17use crate::ArrayRef;
18use crate::arrays::ScalarFnArrayExt;
19use crate::expr::Expression;
20use crate::expr::ScalarFnExprExt;
21use crate::expr::functions::EmptyOptions;
22
23pub mod binary;
24pub mod cast;
25pub mod get_item;
26pub mod is_null;
27pub mod mask;
28pub mod not;
29
30pub trait ExprBuiltins: Sized {
32 fn cast(&self, dtype: DType) -> VortexResult<Expression>;
34
35 fn get_item(&self, field_name: impl Into<FieldName>) -> VortexResult<Expression>;
37
38 fn is_null(&self) -> VortexResult<Expression>;
40
41 fn mask(&self, mask: Expression) -> VortexResult<Expression>;
45
46 fn not(&self) -> VortexResult<Expression>;
48}
49
50impl ExprBuiltins for Expression {
51 fn cast(&self, dtype: DType) -> VortexResult<Expression> {
52 cast::CastFn.try_new_expr(dtype, [self.clone()])
53 }
54
55 fn get_item(&self, field_name: impl Into<FieldName>) -> VortexResult<Expression> {
56 get_item::GetItemFn.try_new_expr(field_name.into(), [self.clone()])
57 }
58
59 fn is_null(&self) -> VortexResult<Expression> {
60 is_null::IsNullFn.try_new_expr(EmptyOptions, [self.clone()])
61 }
62
63 fn mask(&self, mask: Expression) -> VortexResult<Expression> {
64 mask::MaskFn.try_new_expr(EmptyOptions, [self.clone(), mask])
65 }
66
67 fn not(&self) -> VortexResult<Expression> {
68 not::NotFn.try_new_expr(EmptyOptions, [self.clone()])
69 }
70}
71
72pub trait ArrayBuiltins: Sized {
73 fn cast(&self, dtype: DType) -> VortexResult<ArrayRef>;
75
76 fn get_item(&self, field_name: impl Into<FieldName>) -> VortexResult<ArrayRef>;
78
79 fn is_null(&self) -> VortexResult<ArrayRef>;
81
82 fn mask(&self, mask: &ArrayRef) -> VortexResult<ArrayRef>;
86
87 fn not(&self) -> VortexResult<ArrayRef>;
89}
90
91impl ArrayBuiltins for ArrayRef {
92 fn cast(&self, dtype: DType) -> VortexResult<ArrayRef> {
93 cast::CastFn.try_new_array(self.len(), dtype, [self.clone()])
94 }
95
96 fn get_item(&self, field_name: impl Into<FieldName>) -> VortexResult<ArrayRef> {
97 get_item::GetItemFn.try_new_array(self.len(), field_name.into(), [self.clone()])
98 }
99
100 fn is_null(&self) -> VortexResult<ArrayRef> {
101 is_null::IsNullFn.try_new_array(self.len(), EmptyOptions, [self.clone()])
102 }
103
104 fn mask(&self, mask: &ArrayRef) -> VortexResult<ArrayRef> {
105 mask::MaskFn.try_new_array(self.len(), EmptyOptions, [self.clone(), mask.clone()])
106 }
107
108 fn not(&self) -> VortexResult<ArrayRef> {
109 not::NotFn.try_new_array(self.len(), EmptyOptions, [self.clone()])
110 }
111}