@@ -859,15 +859,7 @@ fn expr_normalize(ctx: &Box<PlanNormalizeContext>, expr: &Expr) -> Result<Box<Ex
859859 expr,
860860 list,
861861 negated,
862- } => in_list_expr_normalize (
863- optimizer,
864- expr,
865- list,
866- * negated,
867- schema,
868- remapped_columns,
869- optimizer_config,
870- ) ,
862+ } => in_list_expr_normalize ( ctx, expr, list, * negated) ,
871863
872864 Expr :: InSubquery {
873865 expr,
@@ -1021,20 +1013,20 @@ fn binary_expr_normalize(
10211013 // and cast the `DATE` to `TIMESTAMP` to match the types.
10221014 match ( & left_type, & right_type) {
10231015 ( DataType :: Timestamp ( _, _) , DataType :: Date32 ) => {
1024- let new_right = evaluate_expr ( optimizer , right. cast_to ( & left_type, schema) ?) ?;
1025- return Ok ( Expr :: BinaryExpr {
1016+ let new_right = evaluate_expr ( ctx , right. cast_to ( & left_type, ctx . schema ) ?) ?;
1017+ return Ok ( Box :: new ( Expr :: BinaryExpr {
10261018 left,
10271019 op,
1028- right : Box :: new ( new_right) ,
1029- } ) ;
1020+ right : new_right,
1021+ } ) ) ;
10301022 }
10311023 ( DataType :: Date32 , DataType :: Timestamp ( _, _) ) => {
1032- let new_left = evaluate_expr ( optimizer , left. cast_to ( & right_type, schema) ?) ?;
1033- return Ok ( Expr :: BinaryExpr {
1034- left : Box :: new ( new_left) ,
1024+ let new_left = evaluate_expr ( ctx , left. cast_to ( & right_type, ctx . schema ) ?) ?;
1025+ return Ok ( Box :: new ( Expr :: BinaryExpr {
1026+ left : new_left,
10351027 op,
10361028 right,
1037- } ) ;
1029+ } ) ) ;
10381030 }
10391031 _ => ( ) ,
10401032 } ;
@@ -1121,57 +1113,47 @@ fn binary_expr_cast_literal(op: &Operator, other_type: &DataType) -> Option<Data
11211113/// - IN list expressions where expression being tested is `TIMESTAMP`
11221114/// and values are `DATE` to values casted to `TIMESTAMP`
11231115fn in_list_expr_normalize (
1124- optimizer : & PlanNormalize ,
1116+ ctx : & Box < PlanNormalizeContext > ,
11251117 expr : & Expr ,
11261118 list : & [ Expr ] ,
11271119 negated : bool ,
1128- schema : & DFSchema ,
1129- remapped_columns : & HashMap < Column , Column > ,
1130- optimizer_config : & OptimizerConfig ,
1131- ) -> Result < Expr > {
1132- let expr = Box :: new ( expr_normalize (
1133- optimizer,
1134- expr,
1135- schema,
1136- remapped_columns,
1137- optimizer_config,
1138- ) ?) ;
1139- let expr_type = expr. get_type ( schema) ?;
1120+ ) -> Result < Box < Expr > > {
1121+ let expr = expr_normalize ( ctx, expr) ?;
1122+ let expr_type = expr. get_type ( ctx. schema ) ?;
11401123 let expr_is_timestamp = matches ! ( expr_type, DataType :: Timestamp ( _, _) ) ;
11411124 let list = list
11421125 . iter ( )
11431126 . map ( |list_expr| {
1144- let list_expr_normalized = expr_normalize (
1145- optimizer,
1146- list_expr,
1147- schema,
1148- remapped_columns,
1149- optimizer_config,
1150- ) ?;
1127+ let list_expr_normalized = expr_normalize_stack ( ctx, list_expr) ?;
11511128 if !expr_is_timestamp {
11521129 return Ok ( list_expr_normalized) ;
11531130 }
1154- let list_expr_type = list_expr_normalized. get_type ( schema) ?;
1131+
1132+ let list_expr_type = list_expr_normalized. get_type ( ctx. schema ) ?;
11551133 if !matches ! ( list_expr_type, DataType :: Date32 ) {
11561134 return Ok ( list_expr_normalized) ;
11571135 }
1158- evaluate_expr ( optimizer, list_expr_normalized. cast_to ( & expr_type, schema) ?)
1136+
1137+ evaluate_expr_stacked ( ctx, list_expr_normalized. cast_to ( & expr_type, ctx. schema ) ?)
11591138 } )
11601139 . collect :: < Result < Vec < _ > > > ( ) ?;
1161- Ok ( Expr :: InList {
1140+
1141+ Ok ( Box :: new ( Expr :: InList {
11621142 expr,
11631143 list,
11641144 negated,
1165- } )
1145+ } ) )
11661146}
11671147
1168- /// Evaluates an expression to a constant if possible.
1169- fn evaluate_expr ( ctx : & Box < PlanNormalizeContext > , expr : Expr ) -> Result < Box < Expr > > {
1148+ fn evaluate_expr_stacked ( ctx : & Box < PlanNormalizeContext > , expr : Expr ) -> Result < Expr > {
11701149 let execution_props = & ctx. optimizer . cube_ctx . state . execution_props ;
11711150 let mut const_evaluator = ConstEvaluator :: new ( execution_props) ;
1172- let expr = expr. rewrite ( & mut const_evaluator) ?;
1151+ expr. rewrite ( & mut const_evaluator)
1152+ }
11731153
1174- Ok ( Box :: new ( expr) )
1154+ /// Evaluates an expression to a constant if possible.
1155+ fn evaluate_expr ( ctx : & Box < PlanNormalizeContext > , expr : Expr ) -> Result < Box < Expr > > {
1156+ Ok ( Box :: new ( evaluate_expr_stacked ( ctx, expr) ?) )
11751157}
11761158
11771159#[ cfg( test) ]
@@ -1223,7 +1205,7 @@ mod tests {
12231205 . expect ( "Failed to build plan" ) ;
12241206
12251207 // Create a deeply nested OR expression (should cause stack overflow)
1226- let deeply_nested_filter = create_deeply_nested_or_expr ( "value" , 100 ) ;
1208+ let deeply_nested_filter = create_deeply_nested_or_expr ( "value" , 96 ) ;
12271209
12281210 // Build the plan with the filter
12291211 let plan = LogicalPlanBuilder :: from ( table_scan)
0 commit comments