diff --git a/datafusion/core/src/execution/context/mod.rs b/datafusion/core/src/execution/context/mod.rs index b5ad6174821b9..4d3a7358ae425 100644 --- a/datafusion/core/src/execution/context/mod.rs +++ b/datafusion/core/src/execution/context/mod.rs @@ -49,9 +49,9 @@ use datafusion_expr::{ pub use datafusion_physical_expr::execution_props::ExecutionProps; use datafusion_physical_expr::var_provider::is_system_variables; use parking_lot::RwLock; -use std::collections::hash_map::Entry; use std::string::String; use std::sync::Arc; +use std::{any::Any, collections::hash_map::Entry}; use std::{ collections::{HashMap, HashSet}, fmt::Debug, @@ -1270,6 +1270,8 @@ pub struct SessionState { table_factories: HashMap>, /// Runtime environment runtime_env: Arc, + /// User provide context that can be anything. + extension_context: Option>, } impl Debug for SessionState { @@ -1356,6 +1358,7 @@ impl SessionState { execution_props: ExecutionProps::new(), runtime_env: runtime, table_factories, + extension_context: None, } } /// Returns new [`SessionState`] using the provided @@ -1869,6 +1872,18 @@ impl SessionState { pub fn version(&self) -> &str { env!("CARGO_PKG_VERSION") } + + /// Return extension context. + pub fn with_extension_context(&self) -> Option> { + self.extension_context.clone() + } + + /// Return extension context mut. + pub fn with_extension_context_mut( + &mut self, + ) -> &mut Option> { + &mut self.extension_context + } } struct SessionContextProvider<'a> {