@@ -17,26 +17,78 @@ use crate::ArrayRef;
1717use crate :: arrays:: ScalarFnArrayExt ;
1818use crate :: expr:: Expression ;
1919use crate :: expr:: ScalarFnExprExt ;
20+ use crate :: expr:: functions:: EmptyOptions ;
2021
2122pub mod cast;
2223pub mod is_null;
23- mod mask;
24+ pub mod mask;
2425pub mod not;
2526
2627/// A collection of built-in scalar functions that can be applied to expressions or arrays.
27- pub trait BuiltinScalarFns : Sized {
28+ pub trait ExprBuiltins : Sized {
2829 /// Cast to the given data type.
29- fn cast ( & self , dtype : DType ) -> VortexResult < Self > ;
30+ fn cast ( & self , dtype : DType ) -> VortexResult < Expression > ;
31+
32+ /// Is null check.
33+ fn is_null ( & self ) -> VortexResult < Expression > ;
34+
35+ /// Boolean negation.
36+ fn not ( & self ) -> VortexResult < Expression > ;
37+
38+ /// Mask the expression using the given boolean mask.
39+ /// The resulting expression's validity is the intersection of the original expression's
40+ /// validity.
41+ fn mask ( & self , mask : Expression ) -> VortexResult < Expression > ;
3042}
3143
32- impl BuiltinScalarFns for Expression {
44+ impl ExprBuiltins for Expression {
3345 fn cast ( & self , dtype : DType ) -> VortexResult < Expression > {
3446 cast:: CastFn . try_new_expr ( dtype, [ self . clone ( ) ] )
3547 }
48+
49+ fn is_null ( & self ) -> VortexResult < Expression > {
50+ is_null:: IsNullFn . try_new_expr ( EmptyOptions , [ self . clone ( ) ] )
51+ }
52+
53+ fn not ( & self ) -> VortexResult < Expression > {
54+ not:: NotFn . try_new_expr ( EmptyOptions , [ self . clone ( ) ] )
55+ }
56+
57+ fn mask ( & self , mask : Expression ) -> VortexResult < Expression > {
58+ mask:: MaskFn . try_new_expr ( EmptyOptions , [ self . clone ( ) , mask] )
59+ }
3660}
3761
38- impl BuiltinScalarFns for ArrayRef {
39- fn cast ( & self , dtype : DType ) -> VortexResult < Self > {
62+ pub trait ArrayBuiltins : Sized {
63+ /// Cast to the given data type.
64+ fn cast ( & self , dtype : DType ) -> VortexResult < ArrayRef > ;
65+
66+ /// Is null check.
67+ fn is_null ( & self ) -> VortexResult < ArrayRef > ;
68+
69+ /// Boolean negation.
70+ fn not ( & self ) -> VortexResult < ArrayRef > ;
71+
72+ /// Mask the array using the given boolean mask.
73+ /// The resulting array's validity is the intersection of the original array's validity
74+ /// and the mask's validity.
75+ fn mask ( & self , mask : & ArrayRef ) -> VortexResult < ArrayRef > ;
76+ }
77+
78+ impl ArrayBuiltins for ArrayRef {
79+ fn cast ( & self , dtype : DType ) -> VortexResult < ArrayRef > {
4080 cast:: CastFn . try_new_array ( self . len ( ) , dtype, [ self . clone ( ) ] )
4181 }
82+
83+ fn is_null ( & self ) -> VortexResult < ArrayRef > {
84+ is_null:: IsNullFn . try_new_array ( self . len ( ) , EmptyOptions , [ self . clone ( ) ] )
85+ }
86+
87+ fn not ( & self ) -> VortexResult < ArrayRef > {
88+ not:: NotFn . try_new_array ( self . len ( ) , EmptyOptions , [ self . clone ( ) ] )
89+ }
90+
91+ fn mask ( & self , mask : & ArrayRef ) -> VortexResult < ArrayRef > {
92+ mask:: MaskFn . try_new_array ( self . len ( ) , EmptyOptions , [ self . clone ( ) , mask. clone ( ) ] )
93+ }
4294}
0 commit comments