@@ -30,10 +30,12 @@ use datafusion_proto::logical_plan::LogicalExtensionCodec;
3030use datafusion_proto:: physical_plan:: PhysicalExtensionCodec ;
3131use datafusion_proto:: protobuf:: LogicalPlanNode ;
3232use std:: collections:: HashMap ;
33+ use std:: error:: Error ;
3334use std:: sync:: Arc ;
3435use tonic:: codegen:: http:: HeaderName ;
3536use tonic:: metadata:: MetadataMap ;
3637use tonic:: service:: Interceptor ;
38+ use tonic:: transport:: Endpoint ;
3739use tonic:: { Request , Status } ;
3840
3941/// Provides methods which adapt [SessionState]
@@ -146,7 +148,24 @@ pub trait SessionConfigExt {
146148 prefer_flight : bool ,
147149 ) -> Self ;
148150
151+ /// Set user defined metadata keys in Ballista gRPC requests
149152 fn with_ballista_grpc_metadata ( self , metadata : HashMap < String , String > ) -> Self ;
153+
154+ /// Get a `tonic` interceptor configured to decorate the provided metadata keys
155+ fn ballista_grpc_interceptor ( & self ) -> Arc < BallistaGrpcMetadataInterceptor > ;
156+
157+ fn with_ballista_override_create_grpc_client_endpoint (
158+ self ,
159+ override_f : Arc <
160+ dyn Fn ( Endpoint ) -> Result < Endpoint , Box < dyn Error + Send + Sync > >
161+ + Send
162+ + Sync ,
163+ > ,
164+ ) -> Self ;
165+
166+ fn ballista_override_create_grpc_client_endpoint (
167+ & self ,
168+ ) -> Option < Arc < BallistaConfigGrpcEndpoint > > ;
150169}
151170
152171/// [SessionConfigHelperExt] is set of [SessionConfig] extension methods
@@ -398,6 +417,29 @@ impl SessionConfigExt for SessionConfig {
398417 let extension = BallistaGrpcMetadataInterceptor :: new ( metadata) ;
399418 self . with_extension ( Arc :: new ( extension) )
400419 }
420+
421+ fn ballista_grpc_interceptor ( & self ) -> Arc < BallistaGrpcMetadataInterceptor > {
422+ self . get_extension :: < BallistaGrpcMetadataInterceptor > ( )
423+ . unwrap_or_default ( )
424+ }
425+
426+ fn with_ballista_override_create_grpc_client_endpoint (
427+ self ,
428+ override_f : Arc <
429+ dyn Fn ( Endpoint ) -> Result < Endpoint , Box < dyn Error + Send + Sync > >
430+ + Send
431+ + Sync ,
432+ > ,
433+ ) -> Self {
434+ let extension = BallistaConfigGrpcEndpoint :: new ( override_f) ;
435+ self . with_extension ( Arc :: new ( extension) )
436+ }
437+
438+ fn ballista_override_create_grpc_client_endpoint (
439+ & self ,
440+ ) -> Option < Arc < BallistaConfigGrpcEndpoint > > {
441+ self . get_extension :: < BallistaConfigGrpcEndpoint > ( )
442+ }
401443}
402444
403445impl SessionConfigHelperExt for SessionConfig {
@@ -570,6 +612,32 @@ impl Interceptor for BallistaGrpcMetadataInterceptor {
570612 }
571613}
572614
615+ #[ derive( Clone ) ]
616+ pub struct BallistaConfigGrpcEndpoint {
617+ override_f : Arc <
618+ dyn Fn ( Endpoint ) -> Result < Endpoint , Box < dyn Error + Send + Sync > > + Send + Sync ,
619+ > ,
620+ }
621+
622+ impl BallistaConfigGrpcEndpoint {
623+ pub fn new (
624+ override_f : Arc <
625+ dyn Fn ( Endpoint ) -> Result < Endpoint , Box < dyn Error + Send + Sync > >
626+ + Send
627+ + Sync ,
628+ > ,
629+ ) -> Self {
630+ Self { override_f }
631+ }
632+
633+ pub fn configure_endpoint (
634+ & self ,
635+ endpoint : Endpoint ,
636+ ) -> Result < Endpoint , Box < dyn Error + Send + Sync > > {
637+ ( self . override_f ) ( endpoint)
638+ }
639+ }
640+
573641#[ cfg( test) ]
574642mod test {
575643 use datafusion:: {
0 commit comments