@@ -13,9 +13,11 @@ use vortex_dtype::DType;
1313use vortex_dtype:: FieldName ;
1414use vortex_error:: VortexResult ;
1515use vortex_scalar:: Scalar ;
16+ use vortex_session:: VortexSession ;
1617
1718use crate :: Array ;
1819use crate :: ArrayRef ;
20+ use crate :: ExecutionCtx ;
1921use crate :: IntoArray ;
2022use crate :: arrays:: ConstantArray ;
2123use crate :: arrays:: ScalarFnArrayExt ;
@@ -28,6 +30,7 @@ use crate::expr::IsNull;
2830use crate :: expr:: Mask ;
2931use crate :: expr:: Not ;
3032use crate :: expr:: VTableExt ;
33+ use crate :: expr:: Zip ;
3134use crate :: optimizer:: ArrayOptimizer ;
3235
3336/// A collection of built-in scalar functions that can be applied to expressions or arrays.
@@ -51,6 +54,9 @@ pub trait ExprBuiltins: Sized {
5154
5255 /// Boolean negation.
5356 fn not ( & self ) -> VortexResult < Expression > ;
57+
58+ /// Conditional selection: `result[i] = if mask[i] then self[i] else if_false[i]`.
59+ fn zip ( & self , if_false : Expression , mask : Expression ) -> VortexResult < Expression > ;
5460}
5561
5662impl ExprBuiltins for Expression {
@@ -77,6 +83,10 @@ impl ExprBuiltins for Expression {
7783 fn not ( & self ) -> VortexResult < Expression > {
7884 Not . try_new_expr ( EmptyOptions , [ self . clone ( ) ] )
7985 }
86+
87+ fn zip ( & self , if_false : Expression , mask : Expression ) -> VortexResult < Expression > {
88+ Zip . try_new_expr ( EmptyOptions , [ self . clone ( ) , if_false, mask] )
89+ }
8090}
8191
8292pub trait ArrayBuiltins : Sized {
@@ -99,6 +109,9 @@ pub trait ArrayBuiltins: Sized {
99109
100110 /// Boolean negation.
101111 fn not ( & self ) -> VortexResult < ArrayRef > ;
112+
113+ /// Conditional selection: `result[i] = if mask[i] then self[i] else if_false[i]`.
114+ fn zip ( & self , if_false : ArrayRef , mask : ArrayRef ) -> VortexResult < ArrayRef > ;
102115}
103116
104117impl ArrayBuiltins for ArrayRef {
@@ -141,4 +154,11 @@ impl ArrayBuiltins for ArrayRef {
141154 Not . try_new_array ( self . len ( ) , EmptyOptions , [ self . clone ( ) ] ) ?
142155 . optimize ( )
143156 }
157+
158+ fn zip ( & self , if_false : ArrayRef , mask : ArrayRef ) -> VortexResult < ArrayRef > {
159+ let scalar_fn =
160+ Zip . try_new_array ( self . len ( ) , EmptyOptions , [ self . clone ( ) , if_false, mask] ) ?;
161+ let mut ctx = ExecutionCtx :: new ( VortexSession :: empty ( ) ) ;
162+ scalar_fn. execute :: < ArrayRef > ( & mut ctx)
163+ }
144164}
0 commit comments