11use datafusion:: execution:: SessionStateBuilder ;
2- use datafusion_proto:: physical_plan:: PhysicalExtensionCodec ;
3- use std:: sync:: Arc ;
42
53/// Trait called by the Arrow Flight endpoint that handles distributed parts of a DataFusion
64/// plan for building a DataFusion's [datafusion::prelude::SessionContext].
75pub trait SessionBuilder {
86 /// Takes a [SessionStateBuilder] and adds whatever is necessary for it to work, like
9- /// custom physical optimization rules, UDFs, UDAFs, config extensions, etc...
7+ /// custom extension codecs, custom physical optimization rules, UDFs, UDAFs, config
8+ /// extensions, etc...
109 ///
11- /// Example:
10+ /// Example: adding some custom extension plan codecs
1211 ///
1312 /// ```rust
14- /// # use datafusion::execution::{FunctionRegistry, SessionStateBuilder};
15- /// # use datafusion_distributed::{SessionBuilder};
16- ///
17- /// #[derive(Clone)]
18- /// struct CustomSessionBuilder;
19- /// impl SessionBuilder for CustomSessionBuilder {
20- /// fn on_new_session(&self, mut builder: SessionStateBuilder) -> SessionStateBuilder {
21- /// // add your own UDFs, optimization rules, etc...
22- /// builder
23- /// }
24- /// }
25- /// ```
26- fn on_new_session ( & self , builder : SessionStateBuilder ) -> SessionStateBuilder {
27- builder
28- }
29-
30- /// Allows users to provide their own codecs.
3113 ///
32- /// ```rust
3314 /// # use std::sync::Arc;
3415 /// # use datafusion::execution::runtime_env::RuntimeEnv;
3516 /// # use datafusion::execution::{FunctionRegistry, SessionStateBuilder};
3617 /// # use datafusion::physical_plan::ExecutionPlan;
3718 /// # use datafusion_proto::physical_plan::PhysicalExtensionCodec;
38- /// # use datafusion_distributed::{SessionBuilder};
19+ /// # use datafusion_distributed::{with_user_codec, SessionBuilder};
3920 ///
4021 /// #[derive(Debug)]
4122 /// struct CustomExecCodec;
@@ -53,14 +34,13 @@ pub trait SessionBuilder {
5334 /// #[derive(Clone)]
5435 /// struct CustomSessionBuilder;
5536 /// impl SessionBuilder for CustomSessionBuilder {
56- /// fn codec(&self) -> Option<Arc<dyn PhysicalExtensionCodec + 'static>> {
57- /// Some(Arc::new(CustomExecCodec))
37+ /// fn on_new_session(&self, mut builder: SessionStateBuilder) -> SessionStateBuilder {
38+ /// // Add your UDFs, optimization rules, etc...
39+ /// with_user_codec(builder, CustomExecCodec)
5840 /// }
5941 /// }
6042 /// ```
61- fn codec ( & self ) -> Option < Arc < dyn PhysicalExtensionCodec + ' static > > {
62- None
63- }
43+ fn on_new_session ( & self , builder : SessionStateBuilder ) -> SessionStateBuilder ;
6444}
6545
6646/// Noop implementation of the [SessionBuilder]. Used by default if no [SessionBuilder] is provided
0 commit comments