@@ -6,23 +6,25 @@ use std::fmt::Formatter;
66use prost:: Message ;
77use vortex_dtype:: DType ;
88use vortex_dtype:: DType :: Bool ;
9- use vortex_error:: vortex_bail;
109use vortex_error:: VortexExpect ;
1110use vortex_error:: VortexResult ;
11+ use vortex_error:: vortex_bail;
1212use vortex_proto:: expr as pb;
13+ use vortex_vector:: Datum ;
1314
14- use crate :: compute :: between as between_compute ;
15+ use crate :: ArrayRef ;
1516use crate :: compute:: BetweenOptions ;
16- use crate :: expr:: expression:: Expression ;
17- use crate :: expr:: exprs:: binary:: Binary ;
18- use crate :: expr:: exprs:: operators:: Operator ;
17+ use crate :: compute:: between as between_compute;
1918use crate :: expr:: Arity ;
2019use crate :: expr:: ChildName ;
20+ use crate :: expr:: ExecutionArgs ;
2121use crate :: expr:: ExprId ;
2222use crate :: expr:: StatsCatalog ;
2323use crate :: expr:: VTable ;
2424use crate :: expr:: VTableExt ;
25- use crate :: ArrayRef ;
25+ use crate :: expr:: expression:: Expression ;
26+ use crate :: expr:: exprs:: binary:: Binary ;
27+ use crate :: expr:: exprs:: operators:: Operator ;
2628
2729/// An optimized scalar expression to compute whether values fall between two bounds.
2830///
@@ -54,9 +56,9 @@ impl VTable for Between {
5456 ) )
5557 }
5658
57- fn deserialize ( & self , metadata : & [ u8 ] ) -> VortexResult < Option < Self :: Options > > {
59+ fn deserialize ( & self , metadata : & [ u8 ] ) -> VortexResult < Self :: Options > {
5860 let opts = pb:: BetweenOpts :: decode ( metadata) ?;
59- Ok ( Some ( BetweenOptions {
61+ Ok ( BetweenOptions {
6062 lower_strict : if opts. lower_strict {
6163 crate :: compute:: StrictComparison :: Strict
6264 } else {
@@ -67,17 +69,11 @@ impl VTable for Between {
6769 } else {
6870 crate :: compute:: StrictComparison :: NonStrict
6971 } ,
70- } ) )
72+ } )
7173 }
7274
73- fn validate ( & self , expr : & ExpressionView < Self > ) -> VortexResult < ( ) > {
74- if expr. children ( ) . len ( ) != 3 {
75- vortex_bail ! (
76- "Between expression requires exactly 3 children, got {}" ,
77- expr. children( ) . len( )
78- ) ;
79- }
80- Ok ( ( ) )
75+ fn arity ( & self , _options : & Self :: Options ) -> Arity {
76+ Arity :: Exact ( 3 )
8177 }
8278
8379 fn child_name ( & self , _instance : & Self :: Options , child_idx : usize ) -> ChildName {
@@ -89,8 +85,12 @@ impl VTable for Between {
8985 }
9086 }
9187
92- fn fmt_sql ( & self , expr : & ExpressionView < Self > , f : & mut Formatter < ' _ > ) -> std:: fmt:: Result {
93- let options = expr. data ( ) ;
88+ fn fmt_sql (
89+ & self ,
90+ options : & Self :: Options ,
91+ expr : & Expression ,
92+ f : & mut Formatter < ' _ > ,
93+ ) -> std:: fmt:: Result {
9494 let lower_op = if options. lower_strict . is_strict ( ) {
9595 "<"
9696 } else {
@@ -104,18 +104,18 @@ impl VTable for Between {
104104 write ! (
105105 f,
106106 "({} {} {} {} {})" ,
107- expr. lower ( ) ,
107+ expr. child ( 1 ) ,
108108 lower_op,
109- expr. child( ) ,
109+ expr. child( 0 ) ,
110110 upper_op,
111- expr. upper ( )
111+ expr. child ( 2 )
112112 )
113113 }
114114
115- fn return_dtype ( & self , expr : & ExpressionView < Self > , scope : & DType ) -> VortexResult < DType > {
116- let arr_dt = expr . child ( ) . return_dtype ( scope ) ? ;
117- let lower_dt = expr . lower ( ) . return_dtype ( scope ) ? ;
118- let upper_dt = expr . upper ( ) . return_dtype ( scope ) ? ;
115+ fn return_dtype ( & self , options : & Self :: Options , arg_dtypes : & [ DType ] ) -> VortexResult < DType > {
116+ let arr_dt = & arg_dtypes [ 0 ] ;
117+ let lower_dt = & arg_dtypes [ 1 ] ;
118+ let upper_dt = & arg_dtypes [ 2 ] ;
119119
120120 if !arr_dt. eq_ignore_nullability ( & lower_dt) {
121121 vortex_bail ! (
@@ -137,56 +137,45 @@ impl VTable for Between {
137137 ) )
138138 }
139139
140- fn evaluate ( & self , expr : & ExpressionView < Self > , scope : & ArrayRef ) -> VortexResult < ArrayRef > {
141- let arr = expr. child ( ) . evaluate ( scope) ?;
142- let lower = expr. lower ( ) . evaluate ( scope) ?;
143- let upper = expr. upper ( ) . evaluate ( scope) ?;
144- between_compute ( & arr, & lower, & upper, expr. data ( ) )
140+ fn evaluate (
141+ & self ,
142+ options : & Self :: Options ,
143+ expr : & Expression ,
144+ scope : & ArrayRef ,
145+ ) -> VortexResult < ArrayRef > {
146+ let arr = expr. child ( 0 ) . evaluate ( scope) ?;
147+ let lower = expr. child ( 1 ) . evaluate ( scope) ?;
148+ let upper = expr. child ( 2 ) . evaluate ( scope) ?;
149+ between_compute ( & arr, & lower, & upper, options)
150+ }
151+
152+ fn execute ( & self , data : & Self :: Options , args : ExecutionArgs ) -> VortexResult < Datum > {
153+ todo ! ( )
145154 }
146155
147156 fn stat_falsification (
148157 & self ,
149- _options : & Self :: Options ,
158+ options : & Self :: Options ,
150159 expr : & Expression ,
151160 catalog : & dyn StatsCatalog ,
152161 ) -> Option < Expression > {
153- expr. to_binary_expr ( ) . stat_falsification ( catalog)
154- }
155-
156- fn is_null_sensitive ( & self , _instance : & Self :: Options ) -> bool {
157- false
158- }
159-
160- fn arity ( & self , _options : & Self :: Options ) -> Arity {
161- Arity :: Exact ( 3 )
162- }
163- }
164-
165- impl ExpressionView < ' _ , Between > {
166- pub fn child ( & self ) -> & Expression {
167- & self . children ( ) [ 0 ]
168- }
169-
170- pub fn lower ( & self ) -> & Expression {
171- & self . children ( ) [ 1 ]
172- }
173-
174- pub fn upper ( & self ) -> & Expression {
175- & self . children ( ) [ 2 ]
176- }
177-
178- pub fn to_binary_expr ( & self ) -> Expression {
179- let options = self . data ( ) ;
180- let arr = self . children ( ) [ 0 ] . clone ( ) ;
181- let lower = self . children ( ) [ 1 ] . clone ( ) ;
182- let upper = self . children ( ) [ 2 ] . clone ( ) ;
162+ let arr = expr. child ( 0 ) . clone ( ) ;
163+ let lower = expr. child ( 1 ) . clone ( ) ;
164+ let upper = expr. child ( 2 ) . clone ( ) ;
183165
184166 let lhs = Binary . new_expr (
185167 options. lower_strict . to_operator ( ) . into ( ) ,
186168 [ lower, arr. clone ( ) ] ,
187169 ) ;
188170 let rhs = Binary . new_expr ( options. upper_strict . to_operator ( ) . into ( ) , [ arr, upper] ) ;
189- Binary . new_expr ( Operator :: And , [ lhs, rhs] )
171+
172+ Binary
173+ . new_expr ( Operator :: And , [ lhs, rhs] )
174+ . stat_falsification ( catalog)
175+ }
176+
177+ fn is_null_sensitive ( & self , _instance : & Self :: Options ) -> bool {
178+ false
190179 }
191180}
192181
0 commit comments