pub trait Session: Send + Sync {
// Required methods
fn session_id(&self) -> &str;
fn config(&self) -> &SessionConfig;
fn create_physical_plan<'life0, 'life1, 'async_trait>(
&'life0 self,
logical_plan: &'life1 LogicalPlan,
) -> Pin<Box<dyn Future<Output = Result<Arc<dyn ExecutionPlan>>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn create_physical_expr(
&self,
expr: Expr,
df_schema: &DFSchema,
) -> Result<Arc<dyn PhysicalExpr>>;
fn scalar_functions(&self) -> &HashMap<String, Arc<ScalarUDF>>;
fn aggregate_functions(&self) -> &HashMap<String, Arc<AggregateUDF>>;
fn window_functions(&self) -> &HashMap<String, Arc<WindowUDF>>;
fn runtime_env(&self) -> &Arc<RuntimeEnv>;
fn execution_props(&self) -> &ExecutionProps;
fn as_any(&self) -> &dyn Any;
// Provided method
fn config_options(&self) -> &ConfigOptions { ... }
}
Expand description
Interface for accessing SessionState
from the catalog.
This trait provides access to the information needed to plan and execute
queries, such as configuration, functions, and runtime environment. See the
documentation on SessionState
for more information.
Historically, the SessionState
struct was passed directly to catalog
traits such as TableProvider
, which required a direct dependency on the
DataFusion core. The interface required is now defined by this trait. See
#10782 for more details.
§Migration from SessionState
Using trait methods is preferred, as the implementation may change in future
versions. However, you can downcast a Session
to a SessionState
as shown
in the example below. If you find yourself needing to do this, please open
an issue on the DataFusion repository so we can extend the trait to provide
the required information.
// Given a `Session` reference, get the concrete `SessionState` reference
// Note: this may stop working in future versions,
fn session_state_from_session(session: &dyn Session) -> Result<&SessionState> {
session.as_any()
.downcast_ref::<SessionState>()
.ok_or_else(|| exec_datafusion_err!("Failed to downcast Session to SessionState"))
}
Required Methods§
Sourcefn session_id(&self) -> &str
fn session_id(&self) -> &str
Return the session ID
Sourcefn config(&self) -> &SessionConfig
fn config(&self) -> &SessionConfig
Return the SessionConfig
Sourcefn create_physical_plan<'life0, 'life1, 'async_trait>(
&'life0 self,
logical_plan: &'life1 LogicalPlan,
) -> Pin<Box<dyn Future<Output = Result<Arc<dyn ExecutionPlan>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn create_physical_plan<'life0, 'life1, 'async_trait>(
&'life0 self,
logical_plan: &'life1 LogicalPlan,
) -> Pin<Box<dyn Future<Output = Result<Arc<dyn ExecutionPlan>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Creates a physical ExecutionPlan
plan from a LogicalPlan
.
Note: this will optimize the provided plan first.
This function will error for LogicalPlan
s such as catalog DDL like
CREATE TABLE
, which do not have corresponding physical plans and must
be handled by another layer, typically the SessionContext
.
Sourcefn create_physical_expr(
&self,
expr: Expr,
df_schema: &DFSchema,
) -> Result<Arc<dyn PhysicalExpr>>
fn create_physical_expr( &self, expr: Expr, df_schema: &DFSchema, ) -> Result<Arc<dyn PhysicalExpr>>
Create a PhysicalExpr
from an Expr
after applying type
coercion, and function rewrites.
Note: The expression is not simplified or otherwise optimized: `a = 1
- 2
will not be simplified to
a = 3` as this is a more involved process. See the expr_api example for how to simplify expressions.
Sourcefn scalar_functions(&self) -> &HashMap<String, Arc<ScalarUDF>>
fn scalar_functions(&self) -> &HashMap<String, Arc<ScalarUDF>>
Return reference to scalar_functions
Sourcefn aggregate_functions(&self) -> &HashMap<String, Arc<AggregateUDF>>
fn aggregate_functions(&self) -> &HashMap<String, Arc<AggregateUDF>>
Return reference to aggregate_functions
Sourcefn window_functions(&self) -> &HashMap<String, Arc<WindowUDF>>
fn window_functions(&self) -> &HashMap<String, Arc<WindowUDF>>
Return reference to window functions
Sourcefn runtime_env(&self) -> &Arc<RuntimeEnv>
fn runtime_env(&self) -> &Arc<RuntimeEnv>
Return the runtime env
Sourcefn execution_props(&self) -> &ExecutionProps
fn execution_props(&self) -> &ExecutionProps
Return the execution properties
fn as_any(&self) -> &dyn Any
Provided Methods§
Sourcefn config_options(&self) -> &ConfigOptions
fn config_options(&self) -> &ConfigOptions
return the ConfigOptions