@@ -105,12 +105,14 @@ use ballista_core::serde::protobuf::execute_query_params::OptionalSessionId;
105
105
use ballista_core:: serde:: protobuf:: executor_grpc_client:: ExecutorGrpcClient ;
106
106
use ballista_core:: serde:: scheduler:: to_proto:: hash_partitioning_to_proto;
107
107
use ballista_core:: serde:: { AsExecutionPlan , AsLogicalPlan , BallistaCodec } ;
108
+ use datafusion:: execution:: context:: { default_session_builder, SessionState } ;
108
109
use datafusion:: prelude:: { SessionConfig , SessionContext } ;
109
110
use std:: time:: { Duration , Instant , SystemTime , UNIX_EPOCH } ;
110
111
use tokio:: sync:: { mpsc, RwLock } ;
111
112
use tonic:: transport:: Channel ;
112
113
113
114
type ExecutorsClient = Arc < RwLock < HashMap < String , ExecutorGrpcClient < Channel > > > > ;
115
+ type SessionBuilder = fn ( SessionConfig ) -> SessionState ;
114
116
115
117
#[ derive( Clone ) ]
116
118
pub struct SchedulerServer < T : ' static + AsLogicalPlan , U : ' static + AsExecutionPlan > {
@@ -120,6 +122,8 @@ pub struct SchedulerServer<T: 'static + AsLogicalPlan, U: 'static + AsExecutionP
120
122
scheduler_loop : Option < SchedulerLoop > ,
121
123
executors_client : Option < ExecutorsClient > ,
122
124
codec : BallistaCodec < T , U > ,
125
+ /// SessionState Builder
126
+ session_builder : SessionBuilder ,
123
127
/// DataFusion session contexts that are registered within the SchedulerServer
124
128
session_context_registry : Arc < SessionContextRegistry > ,
125
129
}
@@ -134,13 +138,28 @@ impl<T: 'static + AsLogicalPlan, U: 'static + AsExecutionPlan> SchedulerServer<T
134
138
config : Arc < dyn ConfigBackendClient > ,
135
139
namespace : String ,
136
140
codec : BallistaCodec < T , U > ,
141
+ ) -> Self {
142
+ SchedulerServer :: new_with_builder (
143
+ config,
144
+ namespace,
145
+ codec,
146
+ default_session_builder,
147
+ )
148
+ }
149
+
150
+ pub fn new_with_builder (
151
+ config : Arc < dyn ConfigBackendClient > ,
152
+ namespace : String ,
153
+ codec : BallistaCodec < T , U > ,
154
+ session_builder : SessionBuilder ,
137
155
) -> Self {
138
156
SchedulerServer :: new_with_policy (
139
157
config,
140
158
namespace,
141
159
TaskSchedulingPolicy :: PullStaged ,
142
160
None ,
143
161
codec,
162
+ session_builder,
144
163
)
145
164
}
146
165
@@ -150,6 +169,7 @@ impl<T: 'static + AsLogicalPlan, U: 'static + AsExecutionPlan> SchedulerServer<T
150
169
policy : TaskSchedulingPolicy ,
151
170
scheduler_loop : Option < SchedulerLoop > ,
152
171
codec : BallistaCodec < T , U > ,
172
+ session_builder : SessionBuilder ,
153
173
) -> Self {
154
174
let state = Arc :: new ( SchedulerState :: new ( config, namespace, codec. clone ( ) ) ) ;
155
175
@@ -168,6 +188,7 @@ impl<T: 'static + AsLogicalPlan, U: 'static + AsExecutionPlan> SchedulerServer<T
168
188
scheduler_loop,
169
189
executors_client,
170
190
codec,
191
+ session_builder,
171
192
session_context_registry : Arc :: new ( SessionContextRegistry :: default ( ) ) ,
172
193
}
173
194
}
@@ -771,7 +792,8 @@ impl<T: 'static + AsLogicalPlan, U: 'static + AsExecutionPlan> SchedulerGrpc
771
792
update_datafusion_session_context ( session_ctx, & config)
772
793
}
773
794
_ => {
774
- let df_session = create_datafusion_session_context ( & config) ;
795
+ let df_session =
796
+ create_datafusion_session_context ( & config, self . session_builder ) ;
775
797
let session_id = df_session. session_id . clone ( ) ;
776
798
self . session_context_registry
777
799
. register_session ( session_id, df_session. clone ( ) )
@@ -972,7 +994,8 @@ impl<T: 'static + AsLogicalPlan, U: 'static + AsExecutionPlan> SchedulerGrpc
972
994
error ! ( "{}" , msg) ;
973
995
tonic:: Status :: internal ( msg)
974
996
} ) ?;
975
- let df_session = create_datafusion_session_context ( & config) ;
997
+ let df_session =
998
+ create_datafusion_session_context ( & config, self . session_builder ) ;
976
999
let session_id = df_session. session_id . clone ( ) ;
977
1000
self . session_context_registry
978
1001
. register_session ( session_id. clone ( ) , df_session. clone ( ) )
@@ -1000,15 +1023,19 @@ impl<T: 'static + AsLogicalPlan, U: 'static + AsExecutionPlan> SchedulerGrpc
1000
1023
}
1001
1024
1002
1025
/// Create a new DataFusion session context from Ballista Configuration
1003
- pub fn create_datafusion_session_context ( config : & BallistaConfig ) -> Arc < SessionContext > {
1026
+ pub fn create_datafusion_session_context (
1027
+ config : & BallistaConfig ,
1028
+ session_builder : SessionBuilder ,
1029
+ ) -> Arc < SessionContext > {
1004
1030
let config = SessionConfig :: new ( )
1005
1031
. with_target_partitions ( config. default_shuffle_partitions ( ) )
1006
1032
. with_batch_size ( config. default_batch_size ( ) )
1007
1033
. with_repartition_joins ( config. repartition_joins ( ) )
1008
1034
. with_repartition_aggregations ( config. repartition_aggregations ( ) )
1009
1035
. with_repartition_windows ( config. repartition_windows ( ) )
1010
1036
. with_parquet_pruning ( config. parquet_pruning ( ) ) ;
1011
- Arc :: new ( SessionContext :: with_config ( config) )
1037
+ let session_state = session_builder ( config) ;
1038
+ Arc :: new ( SessionContext :: with_state ( session_state) )
1012
1039
}
1013
1040
1014
1041
/// Update the existing DataFusion session context with Ballista Configuration
0 commit comments