@@ -26,6 +26,7 @@ use datafusion::logical_expr::LogicalPlan;
2626use futures:: TryFutureExt ;
2727use log:: { debug, error, info} ;
2828
29+ use crate :: catalog:: create_app_catalog;
2930use crate :: config:: ExecutionConfig ;
3031use crate :: { ExecOptions , ExecResult } ;
3132use color_eyre:: eyre:: { self , Result } ;
@@ -41,6 +42,8 @@ use super::local_benchmarks::LocalBenchmarkStats;
4142use super :: stats:: { ExecutionDurationStats , ExecutionStats } ;
4243#[ cfg( feature = "udfs-wasm" ) ]
4344use super :: wasm:: create_wasm_udfs;
45+ #[ cfg( feature = "observability" ) ]
46+ use crate :: observability:: ObservabilityContext ;
4447
4548/// Structure for executing queries locally
4649///
@@ -64,6 +67,9 @@ pub struct ExecutionContext {
6467 ddl_path : Option < PathBuf > ,
6568 /// Dedicated executor for running CPU intensive work
6669 executor : Option < DedicatedExecutor > ,
70+ /// Observability handlers
71+ #[ cfg( feature = "observability" ) ]
72+ observability : ObservabilityContext ,
6773}
6874
6975impl std:: fmt:: Debug for ExecutionContext {
@@ -74,21 +80,35 @@ impl std::fmt::Debug for ExecutionContext {
7480
7581impl ExecutionContext {
7682 /// Construct a new `ExecutionContext` with the specified configuration
77- pub fn try_new ( config : & ExecutionConfig , session_state : SessionState ) -> Result < Self > {
83+ pub fn try_new (
84+ config : & ExecutionConfig ,
85+ session_state : SessionState ,
86+ app_name : & str ,
87+ app_version : & str ,
88+ ) -> Result < Self > {
7889 let mut executor = None ;
7990 if config. dedicated_executor_enabled {
8091 // Ideally we would only use `enable_time` but we are still doing
8192 // some network requests as part of planning / execution which require network
8293 // functionality.
83-
8494 let runtime_builder = tokio:: runtime:: Builder :: new_multi_thread ( ) ;
8595 let dedicated_executor =
8696 DedicatedExecutor :: new ( "cpu_runtime" , config. clone ( ) , runtime_builder) ;
8797 executor = Some ( dedicated_executor)
8898 }
8999
90- #[ allow( unused_mut) ]
100+ #[ cfg( any(
101+ feature = "udfs-wasm" ,
102+ feature = "observability" ,
103+ feature = "functions-json"
104+ ) ) ]
91105 let mut session_ctx = SessionContext :: new_with_state ( session_state) ;
106+ #[ cfg( all(
107+ not( feature = "udfs-wasm" ) ,
108+ not( feature = "observability" ) ,
109+ not( feature = "functions-json" )
110+ ) ) ]
111+ let session_ctx = SessionContext :: new_with_state ( session_state) ;
92112
93113 #[ cfg( feature = "functions-json" ) ]
94114 datafusion_functions_json:: register_all ( & mut session_ctx) ?;
@@ -109,12 +129,32 @@ impl ExecutionContext {
109129 Arc :: new ( datafusion_functions_parquet:: ParquetMetadataFunc { } ) ,
110130 ) ;
111131
112- Ok ( Self {
132+ let catalog = create_app_catalog ( config, app_name, app_version) ?;
133+ session_ctx. register_catalog ( & config. catalog . name , catalog) ;
134+
135+ // #[cfg(feature = "observability")]
136+ // {
137+ // let obs = ObservabilityContext::new(config.observability.clone());
138+ // }
139+
140+ #[ cfg( feature = "observability" ) ]
141+ let ctx = Self {
113142 config : config. clone ( ) ,
114143 session_ctx,
115144 ddl_path : config. ddl_path . as_ref ( ) . map ( PathBuf :: from) ,
116145 executor,
117- } )
146+ observability : ObservabilityContext :: default ( ) ,
147+ } ;
148+
149+ #[ cfg( not( feature = "observability" ) ) ]
150+ let ctx = Self {
151+ config : config. clone ( ) ,
152+ session_ctx,
153+ ddl_path : config. ddl_path . as_ref ( ) . map ( PathBuf :: from) ,
154+ executor,
155+ } ;
156+
157+ Ok ( ctx)
118158 }
119159
120160 pub fn config ( & self ) -> & ExecutionConfig {
@@ -135,6 +175,12 @@ impl ExecutionContext {
135175 & self . executor
136176 }
137177
178+ /// Return the `ObservabilityCtx`
179+ #[ cfg( feature = "observability" ) ]
180+ pub fn observability ( & self ) -> & ObservabilityContext {
181+ & self . observability
182+ }
183+
138184 /// Convert the statement to a `LogicalPlan`. Uses the [`DedicatedExecutor`] if it is available.
139185 pub async fn statement_to_logical_plan ( & self , statement : Statement ) -> Result < LogicalPlan > {
140186 let ctx = self . session_ctx . clone ( ) ;
0 commit comments