Skip to content

Commit c3d3a43

Browse files
alambfindepi
authored andcommitted
Proposed comment improvements
1 parent e8dae59 commit c3d3a43

File tree

1 file changed

+36
-7
lines changed

1 file changed

+36
-7
lines changed

datafusion/catalog/src/session.rs

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,42 @@ use std::any::Any;
2828
use std::collections::HashMap;
2929
use std::sync::Arc;
3030

31-
/// Execution context which access to the session state kept by DataFusion.
31+
/// Interface for accessing [`SessionState`] from the catalog.
3232
///
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
3867
#[async_trait]
3968
pub trait Session: Send + Sync {
4069
/// Return the session ID
@@ -43,7 +72,7 @@ pub trait Session: Send + Sync {
4372
/// Return the [`SessionConfig`]
4473
fn config(&self) -> &SessionConfig;
4574

46-
/// return the configuration options
75+
/// return the [`ConfigOptions`]
4776
fn config_options(&self) -> &ConfigOptions {
4877
self.config().options()
4978
}

0 commit comments

Comments
 (0)