@@ -93,11 +93,7 @@ pub async fn plan_hilbert_sql(
9393 optimize ( opt_ctx, plan) . await
9494}
9595
96- pub fn replace_with_constant (
97- expr : & SExpr ,
98- variables : & VecDeque < Scalar > ,
99- total_partitions : u16 ,
100- ) -> SExpr {
96+ pub fn replace_with_constant ( expr : & SExpr , variables : & VecDeque < Scalar > , partitions : u16 ) -> SExpr {
10197 #[ recursive:: recursive]
10298 fn visit_expr_column ( expr : & mut ScalarExpr , variables : & mut VecDeque < Scalar > ) {
10399 match expr {
@@ -124,11 +120,11 @@ pub fn replace_with_constant(
124120 fn replace_with_constant_into_child (
125121 s_expr : & SExpr ,
126122 variables : & mut VecDeque < Scalar > ,
127- total_partitions : u16 ,
123+ partitions : u16 ,
128124 ) -> SExpr {
129125 let mut s_expr = s_expr. clone ( ) ;
130126 s_expr. plan = match s_expr. plan . as_ref ( ) {
131- RelOperator :: EvalScalar ( expr) => {
127+ RelOperator :: EvalScalar ( expr) if !variables . is_empty ( ) => {
132128 let mut expr = expr. clone ( ) ;
133129 for item in & mut expr. items {
134130 visit_expr_column ( & mut item. scalar , variables) ;
@@ -137,12 +133,10 @@ pub fn replace_with_constant(
137133 }
138134 RelOperator :: Aggregate ( aggr) => {
139135 let mut aggr = aggr. clone ( ) ;
140- if aggr. aggregate_functions . len ( ) == 1 {
141- let mut agg_func = aggr. aggregate_functions [ 0 ] . clone ( ) ;
142- if let ScalarExpr :: AggregateFunction ( func) = & mut agg_func. scalar {
136+ for item in & mut aggr. aggregate_functions {
137+ if let ScalarExpr :: AggregateFunction ( func) = & mut item. scalar {
143138 if func. func_name == "range_bound" {
144- func. params [ 0 ] = Scalar :: Number ( NumberScalar :: UInt16 ( total_partitions) ) ;
145- aggr. aggregate_functions = vec ! [ agg_func] ;
139+ func. params [ 0 ] = Scalar :: Number ( NumberScalar :: UInt16 ( partitions) ) ;
146140 }
147141 }
148142 }
@@ -157,9 +151,7 @@ pub fn replace_with_constant(
157151 let mut children = Vec :: with_capacity ( s_expr. children . len ( ) ) ;
158152 for child in s_expr. children . iter ( ) {
159153 children. push ( Arc :: new ( replace_with_constant_into_child (
160- child,
161- variables,
162- total_partitions,
154+ child, variables, partitions,
163155 ) ) ) ;
164156 }
165157 s_expr. children = children;
@@ -168,5 +160,5 @@ pub fn replace_with_constant(
168160 }
169161
170162 let mut variables = variables. clone ( ) ;
171- replace_with_constant_into_child ( expr, & mut variables, total_partitions )
163+ replace_with_constant_into_child ( expr, & mut variables, partitions )
172164}
0 commit comments