Skip to main content

Session

Trait Session 

Source
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§

Source

fn session_id(&self) -> &str

Return the session ID

Source

fn config(&self) -> &SessionConfig

Return the SessionConfig

Source

fn catalog_list(&self) -> Arc<dyn CatalogProviderList>

Return the catalogs registered with this session.

Source

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.

Source

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

  • 2will not be simplified toa = 3` as this is a more involved process. See the expr_api example for how to simplify expressions.
Source

fn scalar_functions(&self) -> &HashMap<String, Arc<ScalarUDF>>

Return reference to scalar_functions

Source

fn higher_order_functions(&self) -> &HashMap<String, Arc<HigherOrderUDF>>

Return reference to higher_order_functions

Source

fn aggregate_functions(&self) -> &HashMap<String, Arc<AggregateUDF>>

Return reference to aggregate_functions

Source

fn window_functions(&self) -> &HashMap<String, Arc<WindowUDF>>

Return reference to window functions

Source

fn extension_type_registry(&self) -> &Arc<dyn ExtensionTypeRegistry>

Return a reference to the extension type registry

Source

fn runtime_env(&self) -> &Arc<RuntimeEnv>

Return the runtime env

Source

fn execution_props(&self) -> &ExecutionProps

Return the execution properties

Source

fn as_any(&self) -> &(dyn Any + 'static)

Source

fn table_options(&self) -> &TableOptions

Return the table options

Source

fn table_options_mut(&mut self) -> &mut TableOptions

Returns a mutable reference to TableOptions

Source

fn task_ctx(&self) -> Arc<TaskContext>

Get a new TaskContext to run in this session

Provided Methods§

Source

fn config_options(&self) -> &ConfigOptions

return the ConfigOptions

Source

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).

Source

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).

Source

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).

Source

fn statistics_registry(&self) -> Option<&StatisticsRegistry>

Return the optional statistics registry used during physical optimization.

Source

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".

Implementors§