@@ -3,7 +3,7 @@ use crate::config_extension_ext::{
33 set_distributed_option_extension, set_distributed_option_extension_from_headers,
44} ;
55use crate :: events:: {
6- DesiredTaskCountHandler , DesiredTaskCountHandlers , RouteTasksHandler , RouteTasksHandlers ,
6+ Event , EventHandlerChainGeneric , Handler , RouteTasksHandler , RouteTasksHandlers ,
77 ScaleUpLeafNodeHandler , ScaleUpLeafNodeHandlers ,
88} ;
99use crate :: passthrough_headers:: set_passthrough_headers;
@@ -575,6 +575,7 @@ pub trait DistributedExt: Sized {
575575 /// in-place mutation.
576576 fn set_distributed_local_worker_context ( & mut self , local_worker_context : LocalWorkerContext ) ;
577577
578+ /// TODO:
578579 /// Registers a handler that supplies desired or maximum task-count hints for plan nodes.
579580 /// The distributed planner reconciles these hints when choosing each stage's task count.
580581 ///
@@ -591,25 +592,14 @@ pub trait DistributedExt: Sized {
591592 /// }
592593 ///
593594 /// SessionStateBuilder::new()
594- /// .with_distributed_desired_task_count_handler (handle_custom_desired_task_count);
595+ /// .with_distributed_event_handler (handle_custom_desired_task_count);
595596 /// ```
596597 ///
597598 /// ```text
598599 /// ┌────────────────┐
599600 /// │CustomDataSource│──────────▶ 3 desired tasks
600601 /// └────────────────┘
601602 /// ```
602- fn with_distributed_desired_task_count_handler < T : DesiredTaskCountHandler > (
603- self ,
604- handler : T ,
605- ) -> Self ;
606-
607- /// Same as [DistributedExt::with_distributed_desired_task_count_handler] but with an
608- /// in-place mutation.
609- fn set_distributed_desired_task_count_handler < T : DesiredTaskCountHandler > (
610- & mut self ,
611- handler : T ,
612- ) ;
613603
614604 /// Registers a handler that can replace leaf nodes with distributed variants once the
615605 /// distributed planner has decided a final task count.
@@ -690,6 +680,12 @@ pub trait DistributedExt: Sized {
690680 /// Same as [DistributedExt::with_distributed_route_tasks_handler] but with an in-place
691681 /// mutation.
692682 fn set_distributed_route_tasks_handler < T : RouteTasksHandler > ( & mut self , handler : T ) ;
683+
684+ // Sets a handler for the event type E
685+ //
686+
687+ fn with_distributed_event_handler < E : Event , H : Handler < E > > ( self , handler : H ) -> Self ;
688+ fn set_distributed_event_handler < E : Event , H : Handler < E > > ( & mut self , handler : H ) ;
693689}
694690
695691/// Trait to have a unified interface for getting structs & properties from SessionConfig that are used in distributed context.
@@ -854,10 +850,6 @@ impl DistributedExt for SessionConfig {
854850 self . set_extension ( Arc :: new ( local_worker_context) ) ;
855851 }
856852
857- fn set_distributed_desired_task_count_handler < H : DesiredTaskCountHandler > ( & mut self , h : H ) {
858- DesiredTaskCountHandlers :: push_custom ( self , Arc :: new ( h) )
859- }
860-
861853 fn set_distributed_scale_up_leaf_node_handler < H : ScaleUpLeafNodeHandler > ( & mut self , h : H ) {
862854 ScaleUpLeafNodeHandlers :: push_custom ( self , Arc :: new ( h) ) ;
863855 }
@@ -866,6 +858,10 @@ impl DistributedExt for SessionConfig {
866858 RouteTasksHandlers :: push_custom ( self , Arc :: new ( h) ) ;
867859 }
868860
861+ fn set_distributed_event_handler < E : Event , H : Handler < E > > ( & mut self , h : H ) {
862+ EventHandlerChainGeneric :: < E > :: push_custom ( self , Arc :: new ( h) ) ;
863+ }
864+
869865 delegate ! {
870866 to self {
871867 #[ call( set_distributed_option_extension) ]
@@ -958,20 +954,21 @@ impl DistributedExt for SessionConfig {
958954 #[ expr( $; self ) ]
959955 fn with_distributed_local_worker_context( mut self , local_worker_context: LocalWorkerContext ) -> Self ;
960956
961- #[ call( set_distributed_desired_task_count_handler) ]
962- #[ expr( $; self ) ]
963- fn with_distributed_desired_task_count_handler<H : DesiredTaskCountHandler >( mut self , h: H ) -> Self ;
964-
965957 #[ call( set_distributed_scale_up_leaf_node_handler) ]
966958 #[ expr( $; self ) ]
967959 fn with_distributed_scale_up_leaf_node_handler<H : ScaleUpLeafNodeHandler >( mut self , h: H ) -> Self ;
968960
969961 #[ call( set_distributed_route_tasks_handler) ]
970962 #[ expr( $; self ) ]
971963 fn with_distributed_route_tasks_handler<H : RouteTasksHandler >( mut self , h: H ) -> Self ;
964+
965+ #[ call( set_distributed_event_handler) ]
966+ #[ expr( $; self ) ]
967+ fn with_distributed_event_handler<E : Event , H : Handler <E >>( mut self , h: H ) -> Self ;
972968 }
973969 }
974970}
971+
975972impl DistributedGetterExt for SessionConfig {
976973 fn get_distributed_worker_resolver ( & self ) -> Result < Arc < dyn WorkerResolver > , DataFusionError > {
977974 get_distributed_worker_resolver ( self )
@@ -1098,11 +1095,6 @@ impl DistributedExt for SessionStateBuilder {
10981095 #[ expr( $; self ) ]
10991096 fn with_distributed_local_worker_context( mut self , local_worker_context: LocalWorkerContext ) -> Self ;
11001097
1101- fn set_distributed_desired_task_count_handler<H : DesiredTaskCountHandler >( & mut self , h: H ) ;
1102- #[ call( set_distributed_desired_task_count_handler) ]
1103- #[ expr( $; self ) ]
1104- fn with_distributed_desired_task_count_handler<H : DesiredTaskCountHandler >( mut self , h: H ) -> Self ;
1105-
11061098 fn set_distributed_scale_up_leaf_node_handler<H : ScaleUpLeafNodeHandler >( & mut self , h: H ) ;
11071099 #[ call( set_distributed_scale_up_leaf_node_handler) ]
11081100 #[ expr( $; self ) ]
@@ -1112,6 +1104,11 @@ impl DistributedExt for SessionStateBuilder {
11121104 #[ call( set_distributed_route_tasks_handler) ]
11131105 #[ expr( $; self ) ]
11141106 fn with_distributed_route_tasks_handler<H : RouteTasksHandler >( mut self , h: H ) -> Self ;
1107+
1108+ fn set_distributed_event_handler<E : Event , H : Handler <E >>( & mut self , h: H ) ;
1109+ #[ call( set_distributed_event_handler) ]
1110+ #[ expr( $; self ) ]
1111+ fn with_distributed_event_handler<E : Event , H : Handler <E >>( mut self , h: H ) -> Self ;
11151112 }
11161113 }
11171114}
@@ -1243,11 +1240,6 @@ impl DistributedExt for SessionState {
12431240 #[ expr( $; self ) ]
12441241 fn with_distributed_local_worker_context( mut self , local_worker_context: LocalWorkerContext ) -> Self ;
12451242
1246- fn set_distributed_desired_task_count_handler<H : DesiredTaskCountHandler >( & mut self , h: H ) ;
1247- #[ call( set_distributed_desired_task_count_handler) ]
1248- #[ expr( $; self ) ]
1249- fn with_distributed_desired_task_count_handler<H : DesiredTaskCountHandler >( mut self , h: H ) -> Self ;
1250-
12511243 fn set_distributed_scale_up_leaf_node_handler<H : ScaleUpLeafNodeHandler >( & mut self , h: H ) ;
12521244 #[ call( set_distributed_scale_up_leaf_node_handler) ]
12531245 #[ expr( $; self ) ]
@@ -1257,6 +1249,11 @@ impl DistributedExt for SessionState {
12571249 #[ call( set_distributed_route_tasks_handler) ]
12581250 #[ expr( $; self ) ]
12591251 fn with_distributed_route_tasks_handler<H : RouteTasksHandler >( mut self , h: H ) -> Self ;
1252+
1253+ fn set_distributed_event_handler<E : Event , H : Handler <E >>( & mut self , h: H ) ;
1254+ #[ call( set_distributed_event_handler) ]
1255+ #[ expr( $; self ) ]
1256+ fn with_distributed_event_handler<E : Event , H : Handler <E >>( mut self , h: H ) -> Self ;
12601257 }
12611258 }
12621259}
@@ -1381,11 +1378,6 @@ impl DistributedExt for SessionContext {
13811378 #[ expr( $; self ) ]
13821379 fn with_distributed_local_worker_context( self , local_worker_context: LocalWorkerContext ) -> Self ;
13831380
1384- fn set_distributed_desired_task_count_handler<H : DesiredTaskCountHandler >( & mut self , h: H ) ;
1385- #[ call( set_distributed_desired_task_count_handler) ]
1386- #[ expr( $; self ) ]
1387- fn with_distributed_desired_task_count_handler<H : DesiredTaskCountHandler >( self , h: H ) -> Self ;
1388-
13891381 fn set_distributed_scale_up_leaf_node_handler<H : ScaleUpLeafNodeHandler >( & mut self , h: H ) ;
13901382 #[ call( set_distributed_scale_up_leaf_node_handler) ]
13911383 #[ expr( $; self ) ]
@@ -1395,6 +1387,11 @@ impl DistributedExt for SessionContext {
13951387 #[ call( set_distributed_route_tasks_handler) ]
13961388 #[ expr( $; self ) ]
13971389 fn with_distributed_route_tasks_handler<H : RouteTasksHandler >( self , h: H ) -> Self ;
1390+
1391+ fn set_distributed_event_handler<E : Event , H : Handler <E >>( & mut self , h: H ) ;
1392+ #[ call( set_distributed_event_handler) ]
1393+ #[ expr( $; self ) ]
1394+ fn with_distributed_event_handler<E : Event , H : Handler <E >>( self , h: H ) -> Self ;
13981395 }
13991396 }
14001397}
0 commit comments