Struct datafusion::execution::context::SessionState

source ·
pub struct SessionState { /* private fields */ }
Expand description

Execution context for registering data sources and executing queries. See SessionContext for a higher level API.

Note that there is no Default or new() for SessionState, to avoid accidentally running queries or other operations without passing through the SessionConfig or RuntimeEnv. See SessionContext.

Implementations§

source§

impl SessionState

source

pub fn new_with_config_rt( config: SessionConfig, runtime: Arc<RuntimeEnv> ) -> Self

Returns new SessionState using the provided SessionConfig and RuntimeEnv.

source

pub fn with_config_rt(config: SessionConfig, runtime: Arc<RuntimeEnv>) -> Self

👎Deprecated since 32.0.0: Use SessionState::new_with_config_rt

Returns new SessionState using the provided SessionConfig and RuntimeEnv.

source

pub fn new_with_config_rt_and_catalog_list( config: SessionConfig, runtime: Arc<RuntimeEnv>, catalog_list: Arc<dyn CatalogProviderList> ) -> Self

Returns new SessionState using the provided SessionConfig, RuntimeEnv, and CatalogProviderList

source

pub fn with_config_rt_and_catalog_list( config: SessionConfig, runtime: Arc<RuntimeEnv>, catalog_list: Arc<dyn CatalogProviderList> ) -> Self

👎Deprecated since 32.0.0: Use SessionState::new_with_config_rt_and_catalog_list

Returns new SessionState using the provided SessionConfig and RuntimeEnv.

source

pub fn with_session_id(self, session_id: String) -> Self

Replace the random session id.

source

pub fn with_query_planner( self, query_planner: Arc<dyn QueryPlanner + Send + Sync> ) -> Self

override default query planner with query_planner

source

pub fn with_analyzer_rules( self, rules: Vec<Arc<dyn AnalyzerRule + Send + Sync>> ) -> Self

Override the AnalyzerRules optimizer plan rules.

source

pub fn with_optimizer_rules( self, rules: Vec<Arc<dyn OptimizerRule + Send + Sync>> ) -> Self

Replace the entire list of OptimizerRules used to optimize plans

source

pub fn with_physical_optimizer_rules( self, physical_optimizers: Vec<Arc<dyn PhysicalOptimizerRule + Send + Sync>> ) -> Self

Replace the entire list of PhysicalOptimizerRules used to optimize plans

source

pub fn add_analyzer_rule( self, analyzer_rule: Arc<dyn AnalyzerRule + Send + Sync> ) -> Self

Add analyzer_rule to the end of the list of AnalyzerRules used to rewrite queries.

source

pub fn add_optimizer_rule( self, optimizer_rule: Arc<dyn OptimizerRule + Send + Sync> ) -> Self

Add optimizer_rule to the end of the list of OptimizerRules used to rewrite queries.

source

pub fn add_physical_optimizer_rule( self, physical_optimizer_rule: Arc<dyn PhysicalOptimizerRule + Send + Sync> ) -> Self

Add physical_optimizer_rule to the end of the list of PhysicalOptimizerRules used to rewrite queries.

source

pub fn add_table_options_extension<T: ConfigExtension>( self, extension: T ) -> Self

Adds a new ConfigExtension to TableOptions

source

pub fn with_function_factory( self, function_factory: Arc<dyn FunctionFactory> ) -> Self

Registers a FunctionFactory to handle CREATE FUNCTION statements

source

pub fn set_function_factory( &mut self, function_factory: Arc<dyn FunctionFactory> )

Registers a FunctionFactory to handle CREATE FUNCTION statements

source

pub fn with_serializer_registry( self, registry: Arc<dyn SerializerRegistry> ) -> Self

Replace the extension SerializerRegistry

source

pub fn table_factories(&self) -> &HashMap<String, Arc<dyn TableProviderFactory>>

Get the table factories

source

pub fn table_factories_mut( &mut self ) -> &mut HashMap<String, Arc<dyn TableProviderFactory>>

Get the table factories

source

pub fn sql_to_statement(&self, sql: &str, dialect: &str) -> Result<Statement>

Parse an SQL string into an DataFusion specific AST Statement. See SessionContext::sql for running queries.

source

pub fn resolve_table_references( &self, statement: &Statement ) -> Result<Vec<TableReference>>

Resolve all table references in the SQL statement.

source

pub async fn statement_to_plan( &self, statement: Statement ) -> Result<LogicalPlan>

Convert an AST Statement into a LogicalPlan

source

pub async fn create_logical_plan(&self, sql: &str) -> Result<LogicalPlan>

Creates a LogicalPlan from the provided SQL string. This interface will plan any SQL DataFusion supports, including DML like CREATE TABLE, and COPY (which can write to local files.

See SessionContext::sql and SessionContext::sql_with_options for a higher-level interface that handles DDL and verification of allowed statements.

source

pub fn optimize(&self, plan: &LogicalPlan) -> Result<LogicalPlan>

Optimizes the logical plan by applying optimizer rules.

source

pub async fn create_physical_plan( &self, logical_plan: &LogicalPlan ) -> Result<Arc<dyn ExecutionPlan>>

Creates a physical ExecutionPlan plan from a LogicalPlan.

Note: this first calls Self::optimize on the provided plan.

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

source

pub 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

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

pub fn session_id(&self) -> &str

Return the session ID

source

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

Return the runtime env

source

pub fn execution_props(&self) -> &ExecutionProps

Return the execution properties

source

pub fn config(&self) -> &SessionConfig

Return the SessionConfig

source

pub fn config_mut(&mut self) -> &mut SessionConfig

Return the mutable SessionConfig.

source

pub fn physical_optimizers( &self ) -> &[Arc<dyn PhysicalOptimizerRule + Send + Sync>]

Return the physical optimizers

source

pub fn config_options(&self) -> &ConfigOptions

return the configuration options

source

pub fn default_table_options(&self) -> TableOptions

return the TableOptions options with its extensions

source

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

Get a new TaskContext to run in this session

source

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

Return catalog list

source

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

Return reference to scalar_functions

source

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

Return reference to aggregate_functions

source

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

Return reference to window functions

source

pub fn serializer_registry(&self) -> Arc<dyn SerializerRegistry>

Return SerializerRegistry for extensions

source

pub fn version(&self) -> &str

Return version of the cargo package that produced this query

Trait Implementations§

source§

impl Clone for SessionState

source§

fn clone(&self) -> SessionState

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for SessionState

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl From<&SessionState> for TaskContext

Create a new task context instance from SessionState

source§

fn from(state: &SessionState) -> Self

Converts to this type from the input type.
source§

impl FunctionRegistry for SessionState

source§

fn udfs(&self) -> HashSet<String>

Set of all available udfs.
source§

fn udf(&self, name: &str) -> Result<Arc<ScalarUDF>>

Returns a reference to the user defined scalar function (udf) named name.
source§

fn udaf(&self, name: &str) -> Result<Arc<AggregateUDF>>

Returns a reference to the user defined aggregate function (udaf) named name.
source§

fn udwf(&self, name: &str) -> Result<Arc<WindowUDF>>

Returns a reference to the user defined window function (udwf) named name.
source§

fn register_udf( &mut self, udf: Arc<ScalarUDF> ) -> Result<Option<Arc<ScalarUDF>>>

Registers a new ScalarUDF, returning any previously registered implementation. Read more
source§

fn register_udaf( &mut self, udaf: Arc<AggregateUDF> ) -> Result<Option<Arc<AggregateUDF>>>

Registers a new AggregateUDF, returning any previously registered implementation. Read more
source§

fn register_udwf( &mut self, udwf: Arc<WindowUDF> ) -> Result<Option<Arc<WindowUDF>>>

Registers a new WindowUDF, returning any previously registered implementation. Read more
source§

fn deregister_udf(&mut self, name: &str) -> Result<Option<Arc<ScalarUDF>>>

Deregisters a ScalarUDF, returning the implementation that was deregistered. Read more
source§

fn deregister_udaf(&mut self, name: &str) -> Result<Option<Arc<AggregateUDF>>>

Deregisters a AggregateUDF, returning the implementation that was deregistered. Read more
source§

fn deregister_udwf(&mut self, name: &str) -> Result<Option<Arc<WindowUDF>>>

Deregisters a WindowUDF, returning the implementation that was deregistered. Read more
source§

fn register_function_rewrite( &mut self, rewrite: Arc<dyn FunctionRewrite + Send + Sync> ) -> Result<()>

Registers a new FunctionRewrite with the registry. Read more
source§

impl OptimizerConfig for SessionState

source§

fn query_execution_start_time(&self) -> DateTime<Utc>

Return the time at which the query execution started. This time is used as the value for now()
source§

fn alias_generator(&self) -> Arc<AliasGenerator>

Return alias generator used to generate unique aliases for subqueries
source§

fn options(&self) -> &ConfigOptions

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V