1+ use crate :: channel_manager_ext:: set_channel_resolver;
12use crate :: config_extension_ext:: {
23 set_distributed_option_extension, set_distributed_option_extension_from_headers,
34} ;
45use crate :: user_codec_ext:: set_user_codec;
6+ use crate :: ChannelResolver ;
57use datafusion:: common:: DataFusionError ;
68use datafusion:: config:: ConfigExtension ;
79use datafusion:: execution:: { SessionState , SessionStateBuilder } ;
@@ -122,17 +124,19 @@ pub trait DistributedExt: Sized {
122124 headers : & HeaderMap ,
123125 ) -> Result < ( ) , DataFusionError > ;
124126
125- /// Injects a user-defined codec that is capable of encoding/decoding custom execution nodes.
127+ /// Injects a user-defined [PhysicalExtensionCodec] that is capable of encoding/decoding
128+ /// custom execution nodes.
126129 ///
127130 /// Example:
128131 ///
129132 /// ```
130133 /// # use std::sync::Arc;
134+ /// # use datafusion::common::DataFusionError;
131135 /// # use datafusion::execution::{SessionState, FunctionRegistry, SessionStateBuilder};
132136 /// # use datafusion::physical_plan::ExecutionPlan;
133137 /// # use datafusion::prelude::SessionConfig;
134138 /// # use datafusion_proto::physical_plan::PhysicalExtensionCodec;
135- /// # use datafusion_distributed::DistributedExt;
139+ /// # use datafusion_distributed::{ DistributedExt, DistributedSessionBuilderContext} ;
136140 ///
137141 /// #[derive(Debug)]
138142 /// struct CustomExecCodec;
@@ -148,11 +152,61 @@ pub trait DistributedExt: Sized {
148152 /// }
149153 ///
150154 /// let config = SessionConfig::new().with_user_codec(CustomExecCodec);
155+ ///
156+ /// async fn build_state(ctx: DistributedSessionBuilderContext) -> Result<SessionState, DataFusionError> {
157+ /// // while providing this MyCustomSessionBuilder to an Arrow Flight endpoint, it will
158+ /// // know how to deserialize the CustomExtension from the gRPC metadata.
159+ /// Ok(SessionStateBuilder::new()
160+ /// .with_user_codec(CustomExecCodec)
161+ /// .build())
162+ /// }
151163 /// ```
152164 fn with_user_codec < T : PhysicalExtensionCodec + ' static > ( self , codec : T ) -> Self ;
153165
154166 /// Same as [DistributedExt::with_user_codec] but with an in-place mutation
155167 fn set_user_codec < T : PhysicalExtensionCodec + ' static > ( & mut self , codec : T ) ;
168+
169+ /// Injects a [ChannelResolver] implementation for Distributed DataFusion to resolve worker
170+ /// nodes. When running in distributed mode, setting a [ChannelResolver] is required.
171+ ///
172+ /// Example:
173+ ///
174+ /// ```
175+ /// # use async_trait::async_trait;
176+ /// # use datafusion::common::DataFusionError;
177+ /// # use datafusion::execution::{SessionState, SessionStateBuilder};
178+ /// # use datafusion::prelude::SessionConfig;
179+ /// # use url::Url;
180+ /// # use datafusion_distributed::{BoxCloneSyncChannel, ChannelResolver, DistributedExt, DistributedSessionBuilderContext};
181+ ///
182+ /// struct CustomChannelResolver;
183+ ///
184+ /// #[async_trait]
185+ /// impl ChannelResolver for CustomChannelResolver {
186+ /// fn get_urls(&self) -> Result<Vec<Url>, DataFusionError> {
187+ /// todo!()
188+ /// }
189+ ///
190+ /// async fn get_channel_for_url(&self, url: &Url) -> Result<BoxCloneSyncChannel, DataFusionError> {
191+ /// todo!()
192+ /// }
193+ /// }
194+ ///
195+ /// let config = SessionConfig::new().with_channel_resolver(CustomChannelResolver);
196+ ///
197+ /// async fn build_state(ctx: DistributedSessionBuilderContext) -> Result<SessionState, DataFusionError> {
198+ /// // while providing this MyCustomSessionBuilder to an Arrow Flight endpoint, it will
199+ /// // know how to deserialize the CustomExtension from the gRPC metadata.
200+ /// Ok(SessionStateBuilder::new()
201+ /// .with_channel_resolver(CustomChannelResolver)
202+ /// .build())
203+ /// }
204+ /// ```
205+ fn with_channel_resolver < T : ChannelResolver + Send + Sync + ' static > ( self , resolver : T )
206+ -> Self ;
207+
208+ /// Same as [DistributedExt::with_channel_resolver] but with an in-place mutation.
209+ fn set_channel_resolver < T : ChannelResolver + Send + Sync + ' static > ( & mut self , resolver : T ) ;
156210}
157211
158212impl DistributedExt for SessionConfig {
@@ -174,17 +228,27 @@ impl DistributedExt for SessionConfig {
174228 set_user_codec ( self , codec)
175229 }
176230
231+ fn set_channel_resolver < T : ChannelResolver + Send + Sync + ' static > ( & mut self , resolver : T ) {
232+ set_channel_resolver ( self , resolver)
233+ }
234+
177235 delegate ! {
178236 to self {
179237 #[ call( set_distributed_option_extension) ]
180238 #[ expr( $?; Ok ( self ) ) ]
181239 fn with_distributed_option_extension<T : ConfigExtension + Default >( mut self , t: T ) -> Result <Self , DataFusionError >;
240+
182241 #[ call( set_distributed_option_extension_from_headers) ]
183242 #[ expr( $?; Ok ( self ) ) ]
184243 fn with_distributed_option_extension_from_headers<T : ConfigExtension + Default >( mut self , headers: & HeaderMap ) -> Result <Self , DataFusionError >;
244+
185245 #[ call( set_user_codec) ]
186246 #[ expr( $; self ) ]
187247 fn with_user_codec<T : PhysicalExtensionCodec + ' static >( mut self , codec: T ) -> Self ;
248+
249+ #[ call( set_channel_resolver) ]
250+ #[ expr( $; self ) ]
251+ fn with_channel_resolver<T : ChannelResolver + Send + Sync + ' static >( mut self , resolver: T ) -> Self ;
188252 }
189253 }
190254}
@@ -196,14 +260,21 @@ impl DistributedExt for SessionStateBuilder {
196260 #[ call( set_distributed_option_extension) ]
197261 #[ expr( $?; Ok ( self ) ) ]
198262 fn with_distributed_option_extension<T : ConfigExtension + Default >( mut self , t: T ) -> Result <Self , DataFusionError >;
263+
199264 fn set_distributed_option_extension_from_headers<T : ConfigExtension + Default >( & mut self , h: & HeaderMap ) -> Result <( ) , DataFusionError >;
200265 #[ call( set_distributed_option_extension_from_headers) ]
201266 #[ expr( $?; Ok ( self ) ) ]
202267 fn with_distributed_option_extension_from_headers<T : ConfigExtension + Default >( mut self , headers: & HeaderMap ) -> Result <Self , DataFusionError >;
268+
203269 fn set_user_codec<T : PhysicalExtensionCodec + ' static >( & mut self , codec: T ) ;
204270 #[ call( set_user_codec) ]
205271 #[ expr( $; self ) ]
206272 fn with_user_codec<T : PhysicalExtensionCodec + ' static >( mut self , codec: T ) -> Self ;
273+
274+ fn set_channel_resolver<T : ChannelResolver + Send + Sync + ' static >( & mut self , resolver: T ) ;
275+ #[ call( set_channel_resolver) ]
276+ #[ expr( $; self ) ]
277+ fn with_channel_resolver<T : ChannelResolver + Send + Sync + ' static >( mut self , resolver: T ) -> Self ;
207278 }
208279 }
209280}
@@ -215,14 +286,21 @@ impl DistributedExt for SessionState {
215286 #[ call( set_distributed_option_extension) ]
216287 #[ expr( $?; Ok ( self ) ) ]
217288 fn with_distributed_option_extension<T : ConfigExtension + Default >( mut self , t: T ) -> Result <Self , DataFusionError >;
289+
218290 fn set_distributed_option_extension_from_headers<T : ConfigExtension + Default >( & mut self , h: & HeaderMap ) -> Result <( ) , DataFusionError >;
219291 #[ call( set_distributed_option_extension_from_headers) ]
220292 #[ expr( $?; Ok ( self ) ) ]
221293 fn with_distributed_option_extension_from_headers<T : ConfigExtension + Default >( mut self , headers: & HeaderMap ) -> Result <Self , DataFusionError >;
294+
222295 fn set_user_codec<T : PhysicalExtensionCodec + ' static >( & mut self , codec: T ) ;
223296 #[ call( set_user_codec) ]
224297 #[ expr( $; self ) ]
225298 fn with_user_codec<T : PhysicalExtensionCodec + ' static >( mut self , codec: T ) -> Self ;
299+
300+ fn set_channel_resolver<T : ChannelResolver + Send + Sync + ' static >( & mut self , resolver: T ) ;
301+ #[ call( set_channel_resolver) ]
302+ #[ expr( $; self ) ]
303+ fn with_channel_resolver<T : ChannelResolver + Send + Sync + ' static >( mut self , resolver: T ) -> Self ;
226304 }
227305 }
228306}
@@ -234,14 +312,21 @@ impl DistributedExt for SessionContext {
234312 #[ call( set_distributed_option_extension) ]
235313 #[ expr( $?; Ok ( self ) ) ]
236314 fn with_distributed_option_extension<T : ConfigExtension + Default >( self , t: T ) -> Result <Self , DataFusionError >;
315+
237316 fn set_distributed_option_extension_from_headers<T : ConfigExtension + Default >( & mut self , h: & HeaderMap ) -> Result <( ) , DataFusionError >;
238317 #[ call( set_distributed_option_extension_from_headers) ]
239318 #[ expr( $?; Ok ( self ) ) ]
240319 fn with_distributed_option_extension_from_headers<T : ConfigExtension + Default >( self , headers: & HeaderMap ) -> Result <Self , DataFusionError >;
320+
241321 fn set_user_codec<T : PhysicalExtensionCodec + ' static >( & mut self , codec: T ) ;
242322 #[ call( set_user_codec) ]
243323 #[ expr( $; self ) ]
244324 fn with_user_codec<T : PhysicalExtensionCodec + ' static >( self , codec: T ) -> Self ;
325+
326+ fn set_channel_resolver<T : ChannelResolver + Send + Sync + ' static >( & mut self , resolver: T ) ;
327+ #[ call( set_channel_resolver) ]
328+ #[ expr( $; self ) ]
329+ fn with_channel_resolver<T : ChannelResolver + Send + Sync + ' static >( self , resolver: T ) -> Self ;
245330 }
246331 }
247332}
0 commit comments