From 71d71a74666c1f37cba879c9ef76b59392ebc2c5 Mon Sep 17 00:00:00 2001 From: yuyang Date: Tue, 30 Jan 2024 09:43:35 +0800 Subject: [PATCH 1/3] add extension context --- datafusion/core/src/execution/context/mod.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/datafusion/core/src/execution/context/mod.rs b/datafusion/core/src/execution/context/mod.rs index b5ad6174821b9..a5e5c678ccc1a 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,16 @@ impl SessionState { pub fn version(&self) -> &str { env!("CARGO_PKG_VERSION") } + /// Return extension context. + pub fn with_extension_context(&self) -> &Option> { + &self.extension_context + } + /// Return extension context mut. + pub fn with_extension_context_mut( + &mut self, + ) -> &mut Option> { + &mut self.extension_context + } } struct SessionContextProvider<'a> { From 0d61b744732deac11b6cc4e892522adc24eb6a11 Mon Sep 17 00:00:00 2001 From: yuyang Date: Tue, 30 Jan 2024 10:13:28 +0800 Subject: [PATCH 2/3] fix a api --- datafusion/core/src/execution/context/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/datafusion/core/src/execution/context/mod.rs b/datafusion/core/src/execution/context/mod.rs index a5e5c678ccc1a..7e6ff6d5ab7c7 100644 --- a/datafusion/core/src/execution/context/mod.rs +++ b/datafusion/core/src/execution/context/mod.rs @@ -1873,8 +1873,8 @@ impl SessionState { env!("CARGO_PKG_VERSION") } /// Return extension context. - pub fn with_extension_context(&self) -> &Option> { - &self.extension_context + pub fn with_extension_context(&self) -> Option> { + self.extension_context.clone() } /// Return extension context mut. pub fn with_extension_context_mut( From c6a36799a813dd9d30f3ccb431897d556f89801d Mon Sep 17 00:00:00 2001 From: yuyang Date: Tue, 30 Jan 2024 10:46:47 +0800 Subject: [PATCH 3/3] add extra space --- datafusion/core/src/execution/context/mod.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/datafusion/core/src/execution/context/mod.rs b/datafusion/core/src/execution/context/mod.rs index 7e6ff6d5ab7c7..4d3a7358ae425 100644 --- a/datafusion/core/src/execution/context/mod.rs +++ b/datafusion/core/src/execution/context/mod.rs @@ -1872,10 +1872,12 @@ 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,