@@ -52,7 +52,7 @@ use datafusion_physical_expr_common::sort_expr::{
5252use datafusion_physical_optimizer:: enforce_distribution:: * ;
5353use datafusion_physical_optimizer:: enforce_sorting:: EnforceSorting ;
5454use datafusion_physical_optimizer:: output_requirements:: OutputRequirements ;
55- use datafusion_physical_optimizer:: PhysicalOptimizerRule ;
55+ use datafusion_physical_optimizer:: { OptimizerContext , PhysicalOptimizerRule } ;
5656use datafusion_physical_plan:: aggregates:: {
5757 AggregateExec , AggregateMode , PhysicalGroupBy ,
5858} ;
@@ -489,7 +489,9 @@ impl TestConfig {
489489 ) -> Result < Arc < dyn ExecutionPlan > > {
490490 // Add the ancillary output requirements operator at the start:
491491 let optimizer = OutputRequirements :: new_add_mode ( ) ;
492- let mut optimized = optimizer. optimize ( plan. clone ( ) , & self . config ) ?;
492+ let session_config = SessionConfig :: from ( self . config . clone ( ) ) ;
493+ let optimizer_context = OptimizerContext :: new ( session_config. clone ( ) ) ;
494+ let mut optimized = optimizer. optimize_plan ( plan. clone ( ) , & optimizer_context) ?;
493495
494496 // This file has 2 rules that use tree node, apply these rules to original plan consecutively
495497 // After these operations tree nodes should be in a consistent state.
@@ -525,21 +527,25 @@ impl TestConfig {
525527 }
526528
527529 for run in optimizers_to_run {
530+ let session_config = SessionConfig :: from ( self . config . clone ( ) ) ;
531+ let optimizer_context = OptimizerContext :: new ( session_config. clone ( ) ) ;
528532 optimized = match run {
529533 Run :: Distribution => {
530534 let optimizer = EnforceDistribution :: new ( ) ;
531- optimizer. optimize ( optimized, & self . config ) ?
535+ optimizer. optimize_plan ( optimized, & optimizer_context ) ?
532536 }
533537 Run :: Sorting => {
534538 let optimizer = EnforceSorting :: new ( ) ;
535- optimizer. optimize ( optimized, & self . config ) ?
539+ optimizer. optimize_plan ( optimized, & optimizer_context ) ?
536540 }
537541 } ;
538542 }
539543
540544 // Remove the ancillary output requirements operator when done:
541545 let optimizer = OutputRequirements :: new_remove_mode ( ) ;
542- let optimized = optimizer. optimize ( optimized, & self . config ) ?;
546+ let session_config = SessionConfig :: from ( self . config . clone ( ) ) ;
547+ let optimizer_context = OptimizerContext :: new ( session_config. clone ( ) ) ;
548+ let optimized = optimizer. optimize_plan ( optimized, & optimizer_context) ?;
543549
544550 Ok ( optimized)
545551 }
@@ -3372,7 +3378,10 @@ SortRequiredExec: [a@0 ASC]
33723378 config. execution . target_partitions = 10 ;
33733379 config. optimizer . enable_round_robin_repartition = true ;
33743380 config. optimizer . prefer_existing_sort = false ;
3375- let dist_plan = EnforceDistribution :: new ( ) . optimize ( physical_plan, & config) ?;
3381+ let session_config = SessionConfig :: from ( config) ;
3382+ let optimizer_context = OptimizerContext :: new ( session_config. clone ( ) ) ;
3383+ let dist_plan =
3384+ EnforceDistribution :: new ( ) . optimize_plan ( physical_plan, & optimizer_context) ?;
33763385 // Since at the start of the rule ordering requirement is not satisfied
33773386 // EnforceDistribution rule doesn't satisfy this requirement either.
33783387 assert_plan ! ( dist_plan, @r"
@@ -3408,7 +3417,10 @@ SortRequiredExec: [a@0 ASC]
34083417 config. execution . target_partitions = 10 ;
34093418 config. optimizer . enable_round_robin_repartition = true ;
34103419 config. optimizer . prefer_existing_sort = false ;
3411- let dist_plan = EnforceDistribution :: new ( ) . optimize ( physical_plan, & config) ?;
3420+ let session_config = SessionConfig :: from ( config) ;
3421+ let optimizer_context = OptimizerContext :: new ( session_config. clone ( ) ) ;
3422+ let dist_plan =
3423+ EnforceDistribution :: new ( ) . optimize_plan ( physical_plan, & optimizer_context) ?;
34123424 // Since at the start of the rule ordering requirement is satisfied
34133425 // EnforceDistribution rule satisfy this requirement also.
34143426 assert_plan ! ( dist_plan, @r"
0 commit comments