@@ -468,6 +468,11 @@ impl RewriteRules for MemberRules {
468468 }
469469}
470470
471+ enum ColumnToSearch {
472+ Var ( & ' static str ) ,
473+ DefaultCount ,
474+ }
475+
471476impl MemberRules {
472477 pub fn new (
473478 meta_context : Arc < MetaContext > ,
@@ -535,8 +540,8 @@ impl MemberRules {
535540 )
536541 } ;
537542
538- let find_matching_old_member_with_count =
539- |name : & str , column_expr : String , default_count : bool | {
543+ let find_matching_old_member =
544+ |name : & str , column_expr : String , column_to_search : ColumnToSearch | {
540545 transforming_rewrite (
541546 & format ! (
542547 "member-pushdown-replacer-column-find-matching-old-member-{}" ,
@@ -554,19 +559,14 @@ impl MemberRules {
554559 ) ,
555560 self . transform_find_matching_old_member (
556561 "?member_pushdown_replacer_alias_to_cube" ,
557- "?column" ,
562+ column_to_search ,
558563 "?old_members" ,
559564 "?terminal_member" ,
560565 "?filtered_member_pushdown_replacer_alias_to_cube" ,
561- default_count,
562566 ) ,
563567 )
564568 } ;
565569
566- let find_matching_old_member = |name : & str , column_expr : String | {
567- find_matching_old_member_with_count ( name, column_expr, false )
568- } ;
569-
570570 if self . config_obj . push_down_pull_up_split ( ) {
571571 rules. extend ( replacer_flat_push_down_node_substitute_rules (
572572 "member-pushdown-replacer-aggregate-group" ,
@@ -606,36 +606,44 @@ impl MemberRules {
606606 member_replacer_fn,
607607 ) ) ;
608608 }
609- rules. push ( find_matching_old_member ( "column" , column_expr ( "?column" ) ) ) ;
609+ rules. push ( find_matching_old_member (
610+ "column" ,
611+ column_expr ( "?column" ) ,
612+ ColumnToSearch :: Var ( "?column" ) ,
613+ ) ) ;
610614 rules. push ( find_matching_old_member (
611615 "alias" ,
612616 alias_expr ( column_expr ( "?column" ) , "?alias" ) ,
617+ ColumnToSearch :: Var ( "?column" ) ,
613618 ) ) ;
614619 rules. push ( find_matching_old_member (
615620 "agg-fun" ,
616621 agg_fun_expr ( "?fun_name" , vec ! [ column_expr( "?column" ) ] , "?distinct" ) ,
622+ ColumnToSearch :: Var ( "?column" ) ,
617623 ) ) ;
618624 rules. push ( find_matching_old_member (
619625 "agg-fun-alias" ,
620626 alias_expr (
621627 agg_fun_expr ( "?fun_name" , vec ! [ column_expr( "?column" ) ] , "?distinct" ) ,
622628 "?alias" ,
623629 ) ,
630+ ColumnToSearch :: Var ( "?column" ) ,
624631 ) ) ;
625632 rules. push ( find_matching_old_member (
626633 "udaf-fun" ,
627634 udaf_expr ( MEASURE_UDAF_NAME , vec ! [ column_expr( "?column" ) ] ) ,
635+ ColumnToSearch :: Var ( "?column" ) ,
628636 ) ) ;
629- rules. push ( find_matching_old_member_with_count (
637+ rules. push ( find_matching_old_member (
630638 "agg-fun-default-count" ,
631639 agg_fun_expr (
632640 "Count" ,
633641 vec ! [ literal_expr( "?any" ) ] ,
634642 "AggregateFunctionExprDistinct:false" ,
635643 ) ,
636- true ,
644+ ColumnToSearch :: DefaultCount ,
637645 ) ) ;
638- rules. push ( find_matching_old_member_with_count (
646+ rules. push ( find_matching_old_member (
639647 "agg-fun-default-count-alias" ,
640648 alias_expr (
641649 agg_fun_expr (
@@ -645,7 +653,7 @@ impl MemberRules {
645653 ) ,
646654 "?alias" ,
647655 ) ,
648- true ,
656+ ColumnToSearch :: DefaultCount ,
649657 ) ) ;
650658 rules. push ( find_matching_old_member (
651659 "agg-fun-with-cast" ,
@@ -655,13 +663,15 @@ impl MemberRules {
655663 vec ! [ cast_expr( column_expr( "?column" ) , "?data_type" ) ] ,
656664 "?distinct" ,
657665 ) ,
666+ ColumnToSearch :: Var ( "?column" ) ,
658667 ) ) ;
659668 rules. push ( find_matching_old_member (
660669 "date-trunc" ,
661670 self . fun_expr (
662671 "DateTrunc" ,
663672 vec ! [ literal_expr( "?granularity" ) , column_expr( "?column" ) ] ,
664673 ) ,
674+ ColumnToSearch :: Var ( "?column" ) ,
665675 ) ) ;
666676 rules. push ( find_matching_old_member (
667677 "date-trunc-with-alias" ,
@@ -673,6 +683,7 @@ impl MemberRules {
673683 ) ,
674684 "?original_alias" ,
675685 ) ,
686+ ColumnToSearch :: Var ( "?column" ) ,
676687 ) ) ;
677688 Self :: measure_rewrites (
678689 & mut rules,
@@ -1947,15 +1958,17 @@ impl MemberRules {
19471958 fn transform_find_matching_old_member (
19481959 & self ,
19491960 member_pushdown_replacer_alias_to_cube_var : & ' static str ,
1950- column_var : & ' static str ,
1961+ column_to_search : ColumnToSearch ,
19511962 old_members_var : & ' static str ,
19521963 terminal_member : & ' static str ,
19531964 filtered_member_pushdown_replacer_alias_to_cube_var : & ' static str ,
1954- default_count : bool ,
19551965 ) -> impl Fn ( & mut CubeEGraph , & mut Subst ) -> bool {
19561966 let member_pushdown_replacer_alias_to_cube_var =
19571967 var ! ( member_pushdown_replacer_alias_to_cube_var) ;
1958- let column_var = var ! ( column_var) ;
1968+ let column_var = match column_to_search {
1969+ ColumnToSearch :: Var ( column_var) => Some ( var ! ( column_var) ) ,
1970+ ColumnToSearch :: DefaultCount => None ,
1971+ } ;
19591972 let old_members_var = var ! ( old_members_var) ;
19601973 let terminal_member = var ! ( terminal_member) ;
19611974 let filtered_member_pushdown_replacer_alias_to_cube_var =
@@ -1969,12 +1982,11 @@ impl MemberRules {
19691982 . cloned ( )
19701983 . collect ( ) ;
19711984 for alias_to_cube in alias_to_cubes {
1972- let column_iter = if default_count {
1973- vec ! [ Column :: from_name( Self :: default_count_measure_name( ) ) ]
1974- } else {
1975- var_iter ! ( egraph[ subst[ column_var] ] , ColumnExprColumn )
1985+ let column_iter = match column_var {
1986+ Some ( column_var) => var_iter ! ( egraph[ subst[ column_var] ] , ColumnExprColumn )
19761987 . cloned ( )
1977- . collect ( )
1988+ . collect ( ) ,
1989+ None => vec ! [ Column :: from_name( Self :: default_count_measure_name( ) ) ] ,
19781990 } ;
19791991 for alias_column in column_iter {
19801992 let alias_name = expr_column_name ( & Expr :: Column ( alias_column) , & None ) ;
0 commit comments