@@ -207,6 +207,12 @@ pub struct Batch {
207207 pub items : Vec < ExecutionResult > ,
208208}
209209
210+ impl Default for Batch {
211+ fn default ( ) -> Self {
212+ Self :: new ( )
213+ }
214+ }
215+
210216impl Batch {
211217 pub fn new ( ) -> Self {
212218 Batch {
@@ -269,10 +275,10 @@ impl<'a> Iterator for FlattenOperator<'a> {
269275 type Item = ExecutionResult ;
270276 fn next ( & mut self ) -> Option < Self :: Item > {
271277 loop {
272- if let Some ( iter) = & mut self . current_batch {
273- if let Some ( item) = iter. next ( ) {
274- return Some ( item ) ;
275- }
278+ if let Some ( iter) = & mut self . current_batch
279+ && let Some ( item) = iter. next ( )
280+ {
281+ return Some ( item ) ;
276282 }
277283 // Need next batch
278284 if let Some ( batch) = self . input . next ( ) {
@@ -372,62 +378,61 @@ impl<'a> BatchFilterOperator<'a> {
372378 }
373379
374380 fn filter_batch ( & mut self , batch : & mut Batch ) {
375- if let Expression :: Binary { left, op, right } = & self . predicate {
376- if let ( Expression :: FieldReference ( _, _) , Expression :: Literal ( Value :: Number ( n) ) ) =
381+ if let Expression :: Binary { left, op, right } = & self . predicate
382+ && let ( Expression :: FieldReference ( _, _) , Expression :: Literal ( Value :: Number ( n) ) ) =
377383 ( left. as_ref ( ) , right. as_ref ( ) )
378- {
379- let threshold = match n {
380- jsonb_schema:: Number :: Float64 ( f) => * f,
381- jsonb_schema:: Number :: Int64 ( i) => * i as f64 ,
382- jsonb_schema:: Number :: UInt64 ( u) => * u as f64 ,
383- _ => {
384- self . fallback_filter ( batch) ;
385- return ;
386- }
387- } ;
384+ {
385+ let threshold = match n {
386+ jsonb_schema:: Number :: Float64 ( f) => * f,
387+ jsonb_schema:: Number :: Int64 ( i) => * i as f64 ,
388+ jsonb_schema:: Number :: UInt64 ( u) => * u as f64 ,
389+ _ => {
390+ self . fallback_filter ( batch) ;
391+ return ;
392+ }
393+ } ;
388394
389- // Recycle buffers
390- self . buf_values . clear ( ) ;
391- self . buf_valid . clear ( ) ;
392-
393- for item in & batch. items {
394- let maybe_f = match item {
395- ExecutionResult :: Value ( _, v) => match evaluate_expression ( left, v) {
396- Value :: Number ( n) => get_f64_from_number ( & n) ,
397- _ => None ,
398- } ,
399- ExecutionResult :: Lazy ( doc) => evaluate_to_f64_lazy ( left, doc) ,
400- } ;
395+ // Recycle buffers
396+ self . buf_values . clear ( ) ;
397+ self . buf_valid . clear ( ) ;
398+
399+ for item in & batch. items {
400+ let maybe_f = match item {
401+ ExecutionResult :: Value ( _, v) => match evaluate_expression ( left, v) {
402+ Value :: Number ( n) => get_f64_from_number ( & n) ,
403+ _ => None ,
404+ } ,
405+ ExecutionResult :: Lazy ( doc) => evaluate_to_f64_lazy ( left, doc) ,
406+ } ;
401407
402- if let Some ( f) = maybe_f {
403- self . buf_values . push ( f) ;
404- self . buf_valid . push ( true ) ;
405- } else {
406- self . buf_values . push ( 0.0 ) ;
407- self . buf_valid . push ( false ) ;
408- }
408+ if let Some ( f) = maybe_f {
409+ self . buf_values . push ( f) ;
410+ self . buf_valid . push ( true ) ;
411+ } else {
412+ self . buf_values . push ( 0.0 ) ;
413+ self . buf_valid . push ( false ) ;
409414 }
410-
411- let mut i = 0 ;
412- let buf_values = & self . buf_values ;
413- let buf_valid = & self . buf_valid ;
414-
415- batch. items . retain ( |_| {
416- let valid = buf_valid[ i] ;
417- let val = buf_values[ i] ;
418- let keep = match op {
419- BinaryOperator :: Gt => valid && val > threshold,
420- BinaryOperator :: Lt => valid && val < threshold,
421- BinaryOperator :: Gte => valid && val >= threshold,
422- BinaryOperator :: Lte => valid && val <= threshold,
423- BinaryOperator :: Eq => valid && ( val - threshold) . abs ( ) < f64:: EPSILON ,
424- _ => false ,
425- } ;
426- i += 1 ;
427- keep
428- } ) ;
429- return ;
430415 }
416+
417+ let mut i = 0 ;
418+ let buf_values = & self . buf_values ;
419+ let buf_valid = & self . buf_valid ;
420+
421+ batch. items . retain ( |_| {
422+ let valid = buf_valid[ i] ;
423+ let val = buf_values[ i] ;
424+ let keep = match op {
425+ BinaryOperator :: Gt => valid && val > threshold,
426+ BinaryOperator :: Lt => valid && val < threshold,
427+ BinaryOperator :: Gte => valid && val >= threshold,
428+ BinaryOperator :: Lte => valid && val <= threshold,
429+ BinaryOperator :: Eq => valid && ( val - threshold) . abs ( ) < f64:: EPSILON ,
430+ _ => false ,
431+ } ;
432+ i += 1 ;
433+ keep
434+ } ) ;
435+ return ;
431436 }
432437 self . fallback_filter ( batch) ;
433438 }
@@ -525,13 +530,13 @@ fn is_vectorizable(plan: &LogicalPlan) -> bool {
525530 LogicalPlan :: Scan { .. } => true ,
526531 LogicalPlan :: Filter { input, predicate } => {
527532 let simple_pred = if let Expression :: Binary { left, op : _, right } = predicate {
528- if let ( Expression :: FieldReference ( _ , _ ) , Expression :: Literal ( Value :: Number ( _ ) ) ) =
529- ( left. as_ref ( ) , right. as_ref ( ) )
530- {
531- true
532- } else {
533- false
534- }
533+ matches ! (
534+ ( left. as_ref( ) , right. as_ref( ) ) ,
535+ (
536+ Expression :: FieldReference ( _ , _ ) ,
537+ Expression :: Literal ( Value :: Number ( _ ) )
538+ )
539+ )
535540 } else {
536541 false
537542 } ;
0 commit comments