pub trait Session: Send + Sync {
Show 22 methods
// Required methods
fn session_id(&self) -> &str;
fn config(&self) -> &SessionConfig;
fn catalog_list(&self) -> Arc<dyn CatalogProviderList> ⓘ;
fn create_physical_plan<'life0, 'life1, 'async_trait>(
&'life0 self,
logical_plan: &'life1 LogicalPlan,
) -> Pin<Box<dyn Future<Output = Result<Arc<dyn ExecutionPlan>, DataFusionError>> + Send + 'async_trait>>
where 'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait;
fn create_physical_expr(
&self,
expr: Expr,
df_schema: &DFSchema,
) -> Result<Arc<dyn PhysicalExpr>, DataFusionError>;
fn scalar_functions(&self) -> &HashMap<String, Arc<ScalarUDF>>;
fn higher_order_functions(&self) -> &HashMap<String, Arc<HigherOrderUDF>>;
fn aggregate_functions(&self) -> &HashMap<String, Arc<AggregateUDF>>;
fn window_functions(&self) -> &HashMap<String, Arc<WindowUDF>>;
fn extension_type_registry(&self) -> &Arc<dyn ExtensionTypeRegistry> ⓘ;
fn runtime_env(&self) -> &Arc<RuntimeEnv> ⓘ;
fn execution_props(&self) -> &ExecutionProps;
fn as_any(&self) -> &(dyn Any + 'static);
fn table_options(&self) -> &TableOptions;
fn table_options_mut(&mut self) -> &mut TableOptions;
fn task_ctx(&self) -> Arc<TaskContext> ⓘ;
// Provided methods
fn config_options(&self) -> &ConfigOptions { ... }
fn query_planner(&self) -> Arc<dyn QueryPlanner + Sync + Send> ⓘ { ... }
fn optimize(
&self,
plan: &LogicalPlan,
) -> Result<LogicalPlan, DataFusionError> { ... }
fn physical_optimizers(
&self,
) -> &[Arc<dyn PhysicalOptimizerRule + Sync + Send>] { ... }
fn statistics_registry(&self) -> Option<&StatisticsRegistry> { ... }
fn default_table_options(&self) -> TableOptions { ... }
}Expand description
Interface for accessing SessionState from the catalog and data source.
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 catalog_list(&self) -> Arc<dyn CatalogProviderList> ⓘ
fn catalog_list(&self) -> Arc<dyn CatalogProviderList> ⓘ
Return the catalogs registered with this session.
Sourcefn create_physical_plan<'life0, 'life1, 'async_trait>(
&'life0 self,
logical_plan: &'life1 LogicalPlan,
) -> Pin<Box<dyn Future<Output = Result<Arc<dyn ExecutionPlan>, DataFusionError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: '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>, DataFusionError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
Creates a physical ExecutionPlan plan from a LogicalPlan.
Note: this will optimize the provided plan first.
This function will error for LogicalPlans 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>, DataFusionError>
fn create_physical_expr( &self, expr: Expr, df_schema: &DFSchema, ) -> Result<Arc<dyn PhysicalExpr>, DataFusionError>
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 toa = 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 higher_order_functions(&self) -> &HashMap<String, Arc<HigherOrderUDF>>
fn higher_order_functions(&self) -> &HashMap<String, Arc<HigherOrderUDF>>
Return reference to higher_order_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 extension_type_registry(&self) -> &Arc<dyn ExtensionTypeRegistry> ⓘ
fn extension_type_registry(&self) -> &Arc<dyn ExtensionTypeRegistry> ⓘ
Return a reference to the extension type registry
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 + 'static)
Sourcefn table_options(&self) -> &TableOptions
fn table_options(&self) -> &TableOptions
Return the table options
Sourcefn table_options_mut(&mut self) -> &mut TableOptions
fn table_options_mut(&mut self) -> &mut TableOptions
Returns a mutable reference to TableOptions
Sourcefn task_ctx(&self) -> Arc<TaskContext> ⓘ
fn task_ctx(&self) -> Arc<TaskContext> ⓘ
Get a new TaskContext to run in this session
Provided Methods§
Sourcefn config_options(&self) -> &ConfigOptions
fn config_options(&self) -> &ConfigOptions
return the ConfigOptions
Sourcefn query_planner(&self) -> Arc<dyn QueryPlanner + Sync + Send> ⓘ
fn query_planner(&self) -> Arc<dyn QueryPlanner + Sync + Send> ⓘ
Return the query planner for this session.
§Warning
The default implementation returns an UnsupportedQueryPlanner, so
Session::create_physical_plan will fail. Sessions that support
physical planning should override this method (for example by returning
SessionState::query_planner).
Sourcefn optimize(&self, plan: &LogicalPlan) -> Result<LogicalPlan, DataFusionError>
fn optimize(&self, plan: &LogicalPlan) -> Result<LogicalPlan, DataFusionError>
Optimize a logical plan.
§Warning
The default implementation returns the plan unchanged, applying no
logical optimizations whatsoever. This is almost never what you want:
without optimization, queries execute in their naive, unoptimized form
and may be dramatically slower or fail to run at all. The default exists
only so this crate need not depend on the optimizer; any real session
should override this method (for example by delegating to
SessionState::optimize).
Sourcefn physical_optimizers(&self) -> &[Arc<dyn PhysicalOptimizerRule + Sync + Send>]
fn physical_optimizers(&self) -> &[Arc<dyn PhysicalOptimizerRule + Sync + Send>]
Return the physical optimizer rules for this session.
§Warning
The default implementation returns no rules. This is almost never
what you want: DataFusion relies on physical optimizer rules for
correctness-critical rewrites (such as inserting the repartitioning and
coalescing needed for parallel and multi-partition execution), so a
session with no rules will produce plans that are inefficient or that
fail to execute. The default exists only so this crate need not depend
on the optimizer; any real session should override this method (for
example by returning SessionState::physical_optimizers).
Sourcefn statistics_registry(&self) -> Option<&StatisticsRegistry>
fn statistics_registry(&self) -> Option<&StatisticsRegistry>
Return the optional statistics registry used during physical optimization.
Sourcefn default_table_options(&self) -> TableOptions
fn default_table_options(&self) -> TableOptions
return the TableOptions options with its extensions
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".