Struct datafusion::execution::session_state::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
impl SessionState
sourcepub fn new_with_config_rt(
config: SessionConfig,
runtime: Arc<RuntimeEnv>,
) -> Self
pub fn new_with_config_rt( config: SessionConfig, runtime: Arc<RuntimeEnv>, ) -> Self
Returns new SessionState
using the provided
SessionConfig
and RuntimeEnv
.
sourcepub fn with_config_rt(config: SessionConfig, runtime: Arc<RuntimeEnv>) -> Self
👎Deprecated since 32.0.0: Use SessionState::new_with_config_rt
pub fn with_config_rt(config: SessionConfig, runtime: Arc<RuntimeEnv>) -> Self
Returns new SessionState
using the provided
SessionConfig
and RuntimeEnv
.
sourcepub fn new_with_config_rt_and_catalog_list(
config: SessionConfig,
runtime: Arc<RuntimeEnv>,
catalog_list: Arc<dyn CatalogProviderList>,
) -> Self
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
sourcepub 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
pub fn with_config_rt_and_catalog_list( config: SessionConfig, runtime: Arc<RuntimeEnv>, catalog_list: Arc<dyn CatalogProviderList>, ) -> Self
Returns new SessionState
using the provided
SessionConfig
and RuntimeEnv
.
sourcepub fn with_session_id(self, session_id: String) -> Self
pub fn with_session_id(self, session_id: String) -> Self
Replace the random session id.
sourcepub fn with_query_planner(
self,
query_planner: Arc<dyn QueryPlanner + Send + Sync>,
) -> Self
pub fn with_query_planner( self, query_planner: Arc<dyn QueryPlanner + Send + Sync>, ) -> Self
override default query planner with query_planner
sourcepub fn with_analyzer_rules(
self,
rules: Vec<Arc<dyn AnalyzerRule + Send + Sync>>,
) -> Self
pub fn with_analyzer_rules( self, rules: Vec<Arc<dyn AnalyzerRule + Send + Sync>>, ) -> Self
Override the AnalyzerRule
s optimizer plan rules.
sourcepub fn with_optimizer_rules(
self,
rules: Vec<Arc<dyn OptimizerRule + Send + Sync>>,
) -> Self
pub fn with_optimizer_rules( self, rules: Vec<Arc<dyn OptimizerRule + Send + Sync>>, ) -> Self
Replace the entire list of OptimizerRule
s used to optimize plans
sourcepub fn with_physical_optimizer_rules(
self,
physical_optimizers: Vec<Arc<dyn PhysicalOptimizerRule + Send + Sync>>,
) -> Self
pub fn with_physical_optimizer_rules( self, physical_optimizers: Vec<Arc<dyn PhysicalOptimizerRule + Send + Sync>>, ) -> Self
Replace the entire list of PhysicalOptimizerRule
s used to optimize plans
sourcepub fn add_analyzer_rule(
&mut self,
analyzer_rule: Arc<dyn AnalyzerRule + Send + Sync>,
) -> &Self
pub fn add_analyzer_rule( &mut self, analyzer_rule: Arc<dyn AnalyzerRule + Send + Sync>, ) -> &Self
Add analyzer_rule
to the end of the list of
AnalyzerRule
s used to rewrite queries.
sourcepub fn add_optimizer_rule(
self,
optimizer_rule: Arc<dyn OptimizerRule + Send + Sync>,
) -> Self
pub fn add_optimizer_rule( self, optimizer_rule: Arc<dyn OptimizerRule + Send + Sync>, ) -> Self
Add optimizer_rule
to the end of the list of
OptimizerRule
s used to rewrite queries.
sourcepub fn add_physical_optimizer_rule(
self,
physical_optimizer_rule: Arc<dyn PhysicalOptimizerRule + Send + Sync>,
) -> Self
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
PhysicalOptimizerRule
s used to rewrite queries.
sourcepub fn add_table_options_extension<T: ConfigExtension>(
self,
extension: T,
) -> Self
pub fn add_table_options_extension<T: ConfigExtension>( self, extension: T, ) -> Self
Adds a new ConfigExtension
to TableOptions
sourcepub fn with_function_factory(
self,
function_factory: Arc<dyn FunctionFactory>,
) -> Self
pub fn with_function_factory( self, function_factory: Arc<dyn FunctionFactory>, ) -> Self
Registers a FunctionFactory
to handle CREATE FUNCTION
statements
sourcepub fn set_function_factory(
&mut self,
function_factory: Arc<dyn FunctionFactory>,
)
pub fn set_function_factory( &mut self, function_factory: Arc<dyn FunctionFactory>, )
Registers a FunctionFactory
to handle CREATE FUNCTION
statements
sourcepub fn with_serializer_registry(
self,
registry: Arc<dyn SerializerRegistry>,
) -> Self
pub fn with_serializer_registry( self, registry: Arc<dyn SerializerRegistry>, ) -> Self
Replace the extension SerializerRegistry
sourcepub fn function_factory(&self) -> Option<&Arc<dyn FunctionFactory>>
pub fn function_factory(&self) -> Option<&Arc<dyn FunctionFactory>>
Get the function factory
sourcepub fn table_factories(&self) -> &HashMap<String, Arc<dyn TableProviderFactory>>
pub fn table_factories(&self) -> &HashMap<String, Arc<dyn TableProviderFactory>>
Get the table factories
sourcepub fn table_factories_mut(
&mut self,
) -> &mut HashMap<String, Arc<dyn TableProviderFactory>>
pub fn table_factories_mut( &mut self, ) -> &mut HashMap<String, Arc<dyn TableProviderFactory>>
Get the table factories
sourcepub fn sql_to_statement(&self, sql: &str, dialect: &str) -> Result<Statement>
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.
sourcepub fn sql_to_expr(&self, sql: &str, dialect: &str) -> Result<SQLExpr>
pub fn sql_to_expr(&self, sql: &str, dialect: &str) -> Result<SQLExpr>
parse a sql string into a sqlparser-rs AST SQLExpr
.
See Self::create_logical_expr
for parsing sql to Expr
.
sourcepub fn resolve_table_references(
&self,
statement: &Statement,
) -> Result<Vec<TableReference>>
pub fn resolve_table_references( &self, statement: &Statement, ) -> Result<Vec<TableReference>>
Resolve all table references in the SQL statement. Does not include CTE references.
See catalog::resolve_table_references
for more information.
sourcepub async fn statement_to_plan(
&self,
statement: Statement,
) -> Result<LogicalPlan>
pub async fn statement_to_plan( &self, statement: Statement, ) -> Result<LogicalPlan>
Convert an AST Statement into a LogicalPlan
sourcepub async fn create_logical_plan(&self, sql: &str) -> Result<LogicalPlan>
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.
sourcepub fn create_logical_expr(
&self,
sql: &str,
df_schema: &DFSchema,
) -> Result<Expr>
pub fn create_logical_expr( &self, sql: &str, df_schema: &DFSchema, ) -> Result<Expr>
Creates a datafusion style AST Expr
from a SQL string.
See example on SessionContext::parse_sql_expr
sourcepub fn optimize(&self, plan: &LogicalPlan) -> Result<LogicalPlan>
pub fn optimize(&self, plan: &LogicalPlan) -> Result<LogicalPlan>
Optimizes the logical plan by applying optimizer rules.
sourcepub async fn create_physical_plan(
&self,
logical_plan: &LogicalPlan,
) -> Result<Arc<dyn ExecutionPlan>>
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 LogicalPlan
s such as catalog DDL like
CREATE TABLE
, which do not have corresponding physical plans and must
be handled by another layer, typically SessionContext
.
sourcepub fn create_physical_expr(
&self,
expr: Expr,
df_schema: &DFSchema,
) -> Result<Arc<dyn PhysicalExpr>>
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
- 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.
§See Also:
SessionContext::create_physical_expr
for a higher-level APIcreate_physical_expr
for a lower-level API
sourcepub fn session_id(&self) -> &str
pub fn session_id(&self) -> &str
Return the session ID
sourcepub fn runtime_env(&self) -> &Arc<RuntimeEnv>
pub fn runtime_env(&self) -> &Arc<RuntimeEnv>
Return the runtime env
sourcepub fn execution_props(&self) -> &ExecutionProps
pub fn execution_props(&self) -> &ExecutionProps
Return the execution properties
sourcepub fn execution_props_mut(&mut self) -> &mut ExecutionProps
pub fn execution_props_mut(&mut self) -> &mut ExecutionProps
Return mutable execution properties
sourcepub fn config(&self) -> &SessionConfig
pub fn config(&self) -> &SessionConfig
Return the SessionConfig
sourcepub fn config_mut(&mut self) -> &mut SessionConfig
pub fn config_mut(&mut self) -> &mut SessionConfig
Return the mutable SessionConfig
.
sourcepub fn physical_optimizers(
&self,
) -> &[Arc<dyn PhysicalOptimizerRule + Send + Sync>]
pub fn physical_optimizers( &self, ) -> &[Arc<dyn PhysicalOptimizerRule + Send + Sync>]
Return the physical optimizers
sourcepub fn config_options(&self) -> &ConfigOptions
pub fn config_options(&self) -> &ConfigOptions
return the configuration options
sourcepub fn default_table_options(&self) -> TableOptions
pub fn default_table_options(&self) -> TableOptions
return the TableOptions options with its extensions
sourcepub fn table_options(&self) -> &TableOptions
pub fn table_options(&self) -> &TableOptions
Return the table options
sourcepub fn table_options_mut(&mut self) -> &mut TableOptions
pub fn table_options_mut(&mut self) -> &mut TableOptions
Return mutable table opptions
sourcepub fn register_table_options_extension<T: ConfigExtension>(
&mut self,
extension: T,
)
pub fn register_table_options_extension<T: ConfigExtension>( &mut self, extension: T, )
Registers a ConfigExtension
as a table option extention that can be
referenced from SQL statements executed against this context.
sourcepub fn register_file_format(
&mut self,
file_format: Arc<dyn FileFormatFactory>,
overwrite: bool,
) -> Result<(), DataFusionError>
pub fn register_file_format( &mut self, file_format: Arc<dyn FileFormatFactory>, overwrite: bool, ) -> Result<(), DataFusionError>
Adds or updates a FileFormatFactory which can be used with COPY TO or CREATE EXTERNAL TABLE statements for reading and writing files of custom formats.
sourcepub fn get_file_format_factory(
&self,
ext: &str,
) -> Option<Arc<dyn FileFormatFactory>>
pub fn get_file_format_factory( &self, ext: &str, ) -> Option<Arc<dyn FileFormatFactory>>
Retrieves a FileFormatFactory based on file extension which has been registered via SessionContext::register_file_format. Extensions are not case sensitive.
sourcepub fn task_ctx(&self) -> Arc<TaskContext>
pub fn task_ctx(&self) -> Arc<TaskContext>
Get a new TaskContext to run in this session
sourcepub fn catalog_list(&self) -> &Arc<dyn CatalogProviderList>
pub fn catalog_list(&self) -> &Arc<dyn CatalogProviderList>
Return catalog list
sourcepub fn scalar_functions(&self) -> &HashMap<String, Arc<ScalarUDF>>
pub fn scalar_functions(&self) -> &HashMap<String, Arc<ScalarUDF>>
Return reference to scalar_functions
sourcepub fn aggregate_functions(&self) -> &HashMap<String, Arc<AggregateUDF>>
pub fn aggregate_functions(&self) -> &HashMap<String, Arc<AggregateUDF>>
Return reference to aggregate_functions
sourcepub fn window_functions(&self) -> &HashMap<String, Arc<WindowUDF>>
pub fn window_functions(&self) -> &HashMap<String, Arc<WindowUDF>>
Return reference to window functions
sourcepub fn table_functions(&self) -> &HashMap<String, Arc<TableFunction>>
pub fn table_functions(&self) -> &HashMap<String, Arc<TableFunction>>
Return reference to table_functions
sourcepub fn serializer_registry(&self) -> &Arc<dyn SerializerRegistry>
pub fn serializer_registry(&self) -> &Arc<dyn SerializerRegistry>
Return SerializerRegistry for extensions
sourcepub fn register_udtf(&mut self, name: &str, fun: Arc<dyn TableFunctionImpl>)
pub fn register_udtf(&mut self, name: &str, fun: Arc<dyn TableFunctionImpl>)
Register a user defined table function
sourcepub fn deregister_udtf(
&mut self,
name: &str,
) -> Result<Option<Arc<dyn TableFunctionImpl>>>
pub fn deregister_udtf( &mut self, name: &str, ) -> Result<Option<Arc<dyn TableFunctionImpl>>>
Deregsiter a user defined table function
Trait Implementations§
source§impl Clone for SessionState
impl Clone for SessionState
source§fn clone(&self) -> SessionState
fn clone(&self) -> SessionState
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for SessionState
impl Debug for SessionState
source§impl From<&SessionState> for TaskContext
impl From<&SessionState> for TaskContext
Create a new task context instance from SessionState
source§fn from(state: &SessionState) -> Self
fn from(state: &SessionState) -> Self
source§impl FunctionRegistry for SessionState
impl FunctionRegistry for SessionState
source§fn udf(&self, name: &str) -> Result<Arc<ScalarUDF>>
fn udf(&self, name: &str) -> Result<Arc<ScalarUDF>>
name
.source§fn udaf(&self, name: &str) -> Result<Arc<AggregateUDF>>
fn udaf(&self, name: &str) -> Result<Arc<AggregateUDF>>
name
.source§fn udwf(&self, name: &str) -> Result<Arc<WindowUDF>>
fn udwf(&self, name: &str) -> Result<Arc<WindowUDF>>
name
.source§fn register_udaf(
&mut self,
udaf: Arc<AggregateUDF>,
) -> Result<Option<Arc<AggregateUDF>>>
fn register_udaf( &mut self, udaf: Arc<AggregateUDF>, ) -> Result<Option<Arc<AggregateUDF>>>
AggregateUDF
, returning any previously registered
implementation. Read moresource§fn deregister_udaf(&mut self, name: &str) -> Result<Option<Arc<AggregateUDF>>>
fn deregister_udaf(&mut self, name: &str) -> Result<Option<Arc<AggregateUDF>>>
AggregateUDF
, returning the implementation that was
deregistered. Read moresource§fn register_function_rewrite(
&mut self,
rewrite: Arc<dyn FunctionRewrite + Send + Sync>,
) -> Result<()>
fn register_function_rewrite( &mut self, rewrite: Arc<dyn FunctionRewrite + Send + Sync>, ) -> Result<()>
FunctionRewrite
with the registry. Read moresource§fn expr_planners(&self) -> Vec<Arc<dyn ExprPlanner>>
fn expr_planners(&self) -> Vec<Arc<dyn ExprPlanner>>
ExprPlanner
ssource§fn register_expr_planner(
&mut self,
expr_planner: Arc<dyn ExprPlanner>,
) -> Result<()>
fn register_expr_planner( &mut self, expr_planner: Arc<dyn ExprPlanner>, ) -> Result<()>
ExprPlanner
with the registry.source§impl OptimizerConfig for SessionState
impl OptimizerConfig for SessionState
source§fn query_execution_start_time(&self) -> DateTime<Utc>
fn query_execution_start_time(&self) -> DateTime<Utc>
source§fn alias_generator(&self) -> Arc<AliasGenerator>
fn alias_generator(&self) -> Arc<AliasGenerator>
fn options(&self) -> &ConfigOptions
fn function_registry(&self) -> Option<&dyn FunctionRegistry>
Auto Trait Implementations§
impl Freeze for SessionState
impl !RefUnwindSafe for SessionState
impl Send for SessionState
impl Sync for SessionState
impl Unpin for SessionState
impl !UnwindSafe for SessionState
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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