@@ -5,6 +5,36 @@ use std::sync::Arc;
55
66pub struct UserProvidedCodec ( Arc < dyn PhysicalExtensionCodec > ) ;
77
8+ /// Injects a user-defined codec that is capable of encoding/decoding custom execution nodes.
9+ /// It will inject the codec as a config extension in the provided [SessionConfig], [SessionContext]
10+ /// or [SessionStateBuilder].
11+ ///
12+ /// Example:
13+ ///
14+ /// ```
15+ /// # use std::sync::Arc;
16+ /// # use datafusion::execution::{SessionState, FunctionRegistry, SessionStateBuilder};
17+ /// # use datafusion::physical_plan::ExecutionPlan;
18+ /// # use datafusion_proto::physical_plan::PhysicalExtensionCodec;
19+ /// # use datafusion_distributed::{add_user_codec};
20+ ///
21+ /// #[derive(Debug)]
22+ /// struct CustomExecCodec;
23+ ///
24+ /// impl PhysicalExtensionCodec for CustomExecCodec {
25+ /// fn try_decode(&self, buf: &[u8], inputs: &[Arc<dyn ExecutionPlan>], registry: &dyn FunctionRegistry) -> datafusion::common::Result<Arc<dyn ExecutionPlan>> {
26+ /// todo!()
27+ /// }
28+ ///
29+ /// fn try_encode(&self, node: Arc<dyn ExecutionPlan>, buf: &mut Vec<u8>) -> datafusion::common::Result<()> {
30+ /// todo!()
31+ /// }
32+ /// }
33+ ///
34+ /// let builder = SessionStateBuilder::new();
35+ /// let mut state = builder.build();
36+ /// add_user_codec(state.config_mut(), CustomExecCodec);
37+ /// ```
838#[ allow( private_bounds) ]
939pub fn add_user_codec (
1040 transport : & mut impl UserCodecTransport ,
@@ -13,6 +43,36 @@ pub fn add_user_codec(
1343 transport. set ( codec) ;
1444}
1545
46+ /// Adds a user-defined codec that is capable of encoding/decoding custom execution nodes.
47+ /// It returns the [SessionContext], [SessionConfig] or [SessionStateBuilder] passed on the first
48+ /// argument with the user-defined codec already placed into the config extensions.
49+ ///
50+ /// Example:
51+ ///
52+ /// ```
53+ /// # use std::sync::Arc;
54+ /// # use datafusion::execution::{SessionState, FunctionRegistry, SessionStateBuilder};
55+ /// # use datafusion::physical_plan::ExecutionPlan;
56+ /// # use datafusion_proto::physical_plan::PhysicalExtensionCodec;
57+ /// # use datafusion_distributed::with_user_codec;
58+ ///
59+ /// #[derive(Debug)]
60+ /// struct CustomExecCodec;
61+ ///
62+ /// impl PhysicalExtensionCodec for CustomExecCodec {
63+ /// fn try_decode(&self, buf: &[u8], inputs: &[Arc<dyn ExecutionPlan>], registry: &dyn FunctionRegistry) -> datafusion::common::Result<Arc<dyn ExecutionPlan>> {
64+ /// todo!()
65+ /// }
66+ ///
67+ /// fn try_encode(&self, node: Arc<dyn ExecutionPlan>, buf: &mut Vec<u8>) -> datafusion::common::Result<()> {
68+ /// todo!()
69+ /// }
70+ /// }
71+ ///
72+ /// let builder = SessionStateBuilder::new();
73+ /// let builder = with_user_codec(builder, CustomExecCodec);
74+ /// let state = builder.build();
75+ /// ```
1676#[ allow( private_bounds) ]
1777pub fn with_user_codec < T : UserCodecTransport > (
1878 mut transport : T ,
@@ -23,7 +83,7 @@ pub fn with_user_codec<T: UserCodecTransport>(
2383}
2484
2585#[ allow( private_bounds) ]
26- pub fn get_user_codec (
86+ pub ( crate ) fn get_user_codec (
2787 transport : & impl UserCodecTransport ,
2888) -> Option < Arc < dyn PhysicalExtensionCodec > > {
2989 transport. get ( )
0 commit comments