@@ -80,7 +80,6 @@ use crate::config::{
8080 ConfigOptions , OPT_BATCH_SIZE , OPT_COALESCE_BATCHES , OPT_COALESCE_TARGET_BATCH_SIZE ,
8181 OPT_FILTER_NULL_JOIN_KEYS , OPT_OPTIMIZER_SKIP_FAILED_RULES ,
8282} ;
83- use crate :: datasource:: datasource:: TableProviderFactory ;
8483use crate :: datasource:: file_format:: file_type:: { FileCompressionType , FileType } ;
8584use crate :: execution:: { runtime_env:: RuntimeEnv , FunctionRegistry } ;
8685use crate :: physical_plan:: file_format:: { plan_to_csv, plan_to_json, plan_to_parquet} ;
@@ -159,8 +158,6 @@ pub struct SessionContext {
159158 pub session_start_time : DateTime < Utc > ,
160159 /// Shared session state for the session
161160 pub state : Arc < RwLock < SessionState > > ,
162- /// Dynamic table providers
163- pub table_factories : HashMap < String , Arc < dyn TableProviderFactory > > ,
164161}
165162
166163impl Default for SessionContext {
@@ -188,7 +185,6 @@ impl SessionContext {
188185 session_id : state. session_id . clone ( ) ,
189186 session_start_time : chrono:: Utc :: now ( ) ,
190187 state : Arc :: new ( RwLock :: new ( state) ) ,
191- table_factories : HashMap :: default ( ) ,
192188 }
193189 }
194190
@@ -198,19 +194,9 @@ impl SessionContext {
198194 session_id : state. session_id . clone ( ) ,
199195 session_start_time : chrono:: Utc :: now ( ) ,
200196 state : Arc :: new ( RwLock :: new ( state) ) ,
201- table_factories : HashMap :: default ( ) ,
202197 }
203198 }
204199
205- /// Register a `TableProviderFactory` for a given `file_type` identifier
206- pub fn register_table_factory (
207- & mut self ,
208- file_type : & str ,
209- factory : Arc < dyn TableProviderFactory > ,
210- ) {
211- self . table_factories . insert ( file_type. to_string ( ) , factory) ;
212- }
213-
214200 /// Registers the [`RecordBatch`] as the specified table name
215201 pub fn register_batch (
216202 & self ,
@@ -431,13 +417,20 @@ impl SessionContext {
431417 & self ,
432418 cmd : & CreateExternalTable ,
433419 ) -> Result < Arc < DataFrame > > {
434- let factory = & self . table_factories . get ( & cmd. file_type ) . ok_or_else ( || {
435- DataFusionError :: Execution ( format ! (
436- "Unable to find factory for {}" ,
437- cmd. file_type
438- ) )
439- } ) ?;
440- let table = ( * factory) . create ( cmd. name . as_str ( ) , cmd. location . as_str ( ) ) ;
420+ let state = self . state . read ( ) . clone ( ) ;
421+ let factory = & state
422+ . runtime_env
423+ . table_factories
424+ . get ( & cmd. file_type )
425+ . ok_or_else ( || {
426+ DataFusionError :: Execution ( format ! (
427+ "Unable to find factory for {}" ,
428+ cmd. file_type
429+ ) )
430+ } ) ?;
431+ let table = ( * factory)
432+ . create ( cmd. name . as_str ( ) , cmd. location . as_str ( ) )
433+ . await ?;
441434 self . register_table ( cmd. name . as_str ( ) , table) ?;
442435 let plan = LogicalPlanBuilder :: empty ( false ) . build ( ) ?;
443436 Ok ( Arc :: new ( DataFrame :: new ( self . state . clone ( ) , & plan) ) )
0 commit comments