@@ -68,13 +68,15 @@ use datafusion_sql::parser::{DFParser, Statement};
68
68
use datafusion_sql:: planner:: { ContextProvider , ParserOptions , PlannerContext , SqlToRel } ;
69
69
use itertools:: Itertools ;
70
70
use log:: { debug, info} ;
71
+ use object_store:: ObjectStore ;
71
72
use sqlparser:: ast:: Expr as SQLExpr ;
72
73
use sqlparser:: dialect:: dialect_from_str;
73
74
use std:: any:: Any ;
74
75
use std:: collections:: hash_map:: Entry ;
75
76
use std:: collections:: { HashMap , HashSet } ;
76
77
use std:: fmt:: Debug ;
77
78
use std:: sync:: Arc ;
79
+ use url:: Url ;
78
80
use uuid:: Uuid ;
79
81
80
82
/// `SessionState` contains all the necessary state to plan and execute queries,
@@ -1229,6 +1231,41 @@ impl SessionStateBuilder {
1229
1231
self
1230
1232
}
1231
1233
1234
+ /// Register an `ObjectStore` to the [`RuntimeEnv`]. See [`RuntimeEnv::register_object_store`]
1235
+ /// for more details.
1236
+ ///
1237
+ /// Note that this creates a default [`RuntimeEnv`] if there isn't one passed in already.
1238
+ ///
1239
+ /// ```
1240
+ /// # use datafusion::prelude::*;
1241
+ /// # use datafusion::execution::session_state::SessionStateBuilder;
1242
+ /// # use datafusion_execution::runtime_env::RuntimeEnv;
1243
+ /// # use url::Url;
1244
+ /// # use std::sync::Arc;
1245
+ /// # let http_store = object_store::local::LocalFileSystem::new();
1246
+ /// let url = Url::try_from("file://").unwrap();
1247
+ /// let object_store = object_store::local::LocalFileSystem::new();
1248
+ /// let state = SessionStateBuilder::new()
1249
+ /// .with_config(SessionConfig::new())
1250
+ /// .with_object_store(&url, Arc::new(object_store))
1251
+ /// .with_default_features()
1252
+ /// .build();
1253
+ /// ```
1254
+ pub fn with_object_store (
1255
+ mut self ,
1256
+ url : & Url ,
1257
+ object_store : Arc < dyn ObjectStore > ,
1258
+ ) -> Self {
1259
+ if self . runtime_env . is_none ( ) {
1260
+ self . runtime_env = Some ( Arc :: new ( RuntimeEnv :: default ( ) ) ) ;
1261
+ }
1262
+ self . runtime_env
1263
+ . as_ref ( )
1264
+ . unwrap ( )
1265
+ . register_object_store ( url, object_store) ;
1266
+ self
1267
+ }
1268
+
1232
1269
/// Builds a [`SessionState`] with the current configuration.
1233
1270
///
1234
1271
/// Note that there is an explicit option for enabling catalog and schema defaults
0 commit comments