@@ -28,13 +28,42 @@ use std::any::Any;
28
28
use std:: collections:: HashMap ;
29
29
use std:: sync:: Arc ;
30
30
31
- /// Execution context which access to the session state kept by DataFusion .
31
+ /// Interface for accessing [`SessionState`] from the catalog .
32
32
///
33
- /// Note that this trait is implemented by the DataFusion core, and you typically
34
- /// do not need to implement it. When this trait is backed by the core's
35
- /// `SessionState` you can unwrap it using a `downcast_ref`
36
- /// (`.as_any().downcast_ref::<SessionState>().unwrap()`). This functionality
37
- /// is provided to facilitate transition period, avoid depending on it.
33
+ /// This trait provides access to the information needed to plan and execute
34
+ /// queries, such as configuration, functions, and runtime environment. See the
35
+ /// documentation on [`SessionState`] for more information.
36
+ ///
37
+ /// Historically, the `SessionState` struct was passed directly to catalog
38
+ /// traits such as [`TableProvider`], which required a direct dependency on the
39
+ /// DataFusion core. The interface required is now defined by this trait. See
40
+ /// [#10782] for more details.
41
+ ///
42
+ /// [#10782]: https://github.com/apache/datafusion/issues/10782
43
+ ///
44
+ /// # Migration from `SessionState`
45
+ ///
46
+ /// Using trait methods is preferred, as the implementation may change in future
47
+ /// versions. However, you can downcast a `Session` to a `SessionState` as shown
48
+ /// in the example below. If you find yourself needing to do this, please open
49
+ /// an issue on the DataFusion repository so we can extend the trait to provide
50
+ /// the required information.
51
+ ///
52
+ /// ```
53
+ /// # use datafusion_catalog::Session;
54
+ /// # use datafusion_common::{Result, exec_datafusion_err};
55
+ /// struct SessionState {}
56
+ /// // Given a `Session` reference, get the concrete `SessionState` reference
57
+ /// // Note: this may stop working in future versions,
58
+ /// fn session_state_from_session(session: &dyn Session) -> Result<&SessionState> {
59
+ /// session.as_any()
60
+ /// .downcast_ref::<SessionState>()
61
+ /// .ok_or_else(|| exec_datafusion_err!("Failed to downcast Session to SessionState"))
62
+ /// }
63
+ /// ```
64
+ ///
65
+ /// [`SessionState`]: https://docs.rs/datafusion/latest/datafusion/execution/session_state/struct.SessionState.html
66
+ /// [TableProvider]: crate::TableProvider
38
67
#[ async_trait]
39
68
pub trait Session : Send + Sync {
40
69
/// Return the session ID
@@ -43,7 +72,7 @@ pub trait Session: Send + Sync {
43
72
/// Return the [`SessionConfig`]
44
73
fn config ( & self ) -> & SessionConfig ;
45
74
46
- /// return the configuration options
75
+ /// return the [`ConfigOptions`]
47
76
fn config_options ( & self ) -> & ConfigOptions {
48
77
self . config ( ) . options ( )
49
78
}
0 commit comments