@@ -508,26 +508,49 @@ impl DataFusionPlanner {
508508 self . plan_error ( & format ! ( "Failed to scan node source '{}'" , label) , e)
509509 } ) ?;
510510
511- // Apply property filters using unqualified names (before aliasing)
512- for ( k, v) in properties. iter ( ) {
513- let lit_expr =
514- self . to_df_value_expr ( & crate :: ast:: ValueExpression :: Literal ( v. clone ( ) ) ) ;
515- let filter_expr = Expr :: BinaryExpr ( BinaryExpr {
516- left : Box :: new ( col ( k) ) ,
517- op : Operator :: Eq ,
518- right : Box :: new ( lit_expr) ,
519- } ) ;
520- builder = builder. filter ( filter_expr) . map_err ( |e| {
521- self . plan_error ( & format ! ( "Failed to apply filter on property '{}'" , k) , e)
522- } ) ?;
511+ // Combine property filters into single predicate for efficiency
512+ if !properties. is_empty ( ) {
513+ let filter_exprs: Vec < Expr > = properties
514+ . iter ( )
515+ . map ( |( k, v) | {
516+ let lit_expr = self
517+ . to_df_value_expr ( & crate :: ast:: ValueExpression :: Literal ( v. clone ( ) ) ) ;
518+ Expr :: BinaryExpr ( BinaryExpr {
519+ left : Box :: new ( col ( k) ) ,
520+ op : Operator :: Eq ,
521+ right : Box :: new ( lit_expr) ,
522+ } )
523+ } )
524+ . collect ( ) ;
525+
526+ // Combine with AND if multiple filters
527+ let combined_filter = filter_exprs
528+ . into_iter ( )
529+ . reduce ( |acc, expr| {
530+ Expr :: BinaryExpr ( BinaryExpr {
531+ left : Box :: new ( acc) ,
532+ op : Operator :: And ,
533+ right : Box :: new ( expr) ,
534+ } )
535+ } )
536+ . unwrap ( ) ;
537+
538+ builder = builder
539+ . filter ( combined_filter)
540+ . map_err ( |e| self . plan_error ( "Failed to apply property filters" , e) ) ?;
523541 }
524542
525543 // Create qualified column aliases: variable__property
544+ // Optimization: Pre-allocate string capacity to reduce allocations
526545 let qualified_exprs: Vec < Expr > = schema
527546 . fields ( )
528547 . iter ( )
529548 . map ( |field| {
530- let qualified_name = format ! ( "{}__{}" , variable, field. name( ) ) ;
549+ let mut qualified_name =
550+ String :: with_capacity ( variable. len ( ) + field. name ( ) . len ( ) + 2 ) ;
551+ qualified_name. push_str ( variable) ;
552+ qualified_name. push_str ( "__" ) ;
553+ qualified_name. push_str ( field. name ( ) ) ;
531554 col ( field. name ( ) ) . alias ( & qualified_name)
532555 } )
533556 . collect ( ) ;
0 commit comments