@@ -41,13 +41,32 @@ use url::Url;
41
41
/// Execution runtime environment that manages system resources such
42
42
/// as memory, disk, cache and storage.
43
43
///
44
- /// A [`RuntimeEnv`] is created from a [`RuntimeEnvBuilder`] and has the
44
+ /// A [`RuntimeEnv`] can be created using [`RuntimeEnvBuilder`] and has the
45
45
/// following resource management functionality:
46
46
///
47
47
/// * [`MemoryPool`]: Manage memory
48
48
/// * [`DiskManager`]: Manage temporary files on local disk
49
49
/// * [`CacheManager`]: Manage temporary cache data during the session lifetime
50
50
/// * [`ObjectStoreRegistry`]: Manage mapping URLs to object store instances
51
+ ///
52
+ /// # Example: Create default `RuntimeEnv`
53
+ /// ```
54
+ /// # use datafusion_execution::runtime_env::RuntimeEnv;
55
+ /// let runtime_env = RuntimeEnv::default();
56
+ /// ```
57
+ ///
58
+ /// # Example: Create a `RuntimeEnv` from [`RuntimeEnvBuilder`] with a new memory pool
59
+ /// ```
60
+ /// # use std::sync::Arc;
61
+ /// # use datafusion_execution::memory_pool::GreedyMemoryPool;
62
+ /// # use datafusion_execution::runtime_env::{RuntimeEnv, RuntimeEnvBuilder};
63
+ /// // restrict to using at most 100MB of memory
64
+ /// let pool_size = 100 * 1024 * 1024;
65
+ /// let runtime_env = RuntimeEnvBuilder::new()
66
+ /// .with_memory_pool(Arc::new(GreedyMemoryPool::new(pool_size)))
67
+ /// .build()
68
+ /// .unwrap();
69
+ /// ```
51
70
pub struct RuntimeEnv {
52
71
/// Runtime memory management
53
72
pub memory_pool : Arc < dyn MemoryPool > ,
@@ -66,28 +85,16 @@ impl Debug for RuntimeEnv {
66
85
}
67
86
68
87
impl RuntimeEnv {
69
- #[ deprecated( since = "43.0.0" , note = "please use `try_new` instead" ) ]
88
+ #[ deprecated( since = "43.0.0" , note = "please use `RuntimeEnvBuilder` instead" ) ]
89
+ #[ allow( deprecated) ]
70
90
pub fn new ( config : RuntimeConfig ) -> Result < Self > {
71
91
Self :: try_new ( config)
72
92
}
73
93
/// Create env based on configuration
94
+ #[ deprecated( since = "44.0.0" , note = "please use `RuntimeEnvBuilder` instead" ) ]
95
+ #[ allow( deprecated) ]
74
96
pub fn try_new ( config : RuntimeConfig ) -> Result < Self > {
75
- let RuntimeConfig {
76
- memory_pool,
77
- disk_manager,
78
- cache_manager,
79
- object_store_registry,
80
- } = config;
81
-
82
- let memory_pool =
83
- memory_pool. unwrap_or_else ( || Arc :: new ( UnboundedMemoryPool :: default ( ) ) ) ;
84
-
85
- Ok ( Self {
86
- memory_pool,
87
- disk_manager : DiskManager :: try_new ( disk_manager) ?,
88
- cache_manager : CacheManager :: try_new ( & cache_manager) ?,
89
- object_store_registry,
90
- } )
97
+ config. build ( )
91
98
}
92
99
93
100
/// Registers a custom `ObjectStore` to be used with a specific url.
@@ -104,7 +111,7 @@ impl RuntimeEnv {
104
111
/// # use std::sync::Arc;
105
112
/// # use url::Url;
106
113
/// # use datafusion_execution::runtime_env::RuntimeEnv;
107
- /// # let runtime_env = RuntimeEnv::try_new(Default:: default()).unwrap ();
114
+ /// # let runtime_env = RuntimeEnv::default();
108
115
/// let url = Url::try_from("file://").unwrap();
109
116
/// let object_store = object_store::local::LocalFileSystem::new();
110
117
/// // register the object store with the runtime environment
@@ -119,11 +126,12 @@ impl RuntimeEnv {
119
126
/// # use std::sync::Arc;
120
127
/// # use url::Url;
121
128
/// # use datafusion_execution::runtime_env::RuntimeEnv;
122
- /// # let runtime_env = RuntimeEnv::try_new(Default:: default()).unwrap ();
129
+ /// # let runtime_env = RuntimeEnv::default();
123
130
/// # // use local store for example as http feature is not enabled
124
131
/// # let http_store = object_store::local::LocalFileSystem::new();
125
132
/// // create a new object store via object_store::http::HttpBuilder;
126
133
/// let base_url = Url::parse("https://github.com").unwrap();
134
+ /// // (note this example can't depend on the http feature)
127
135
/// // let http_store = HttpBuilder::new()
128
136
/// // .with_url(base_url.clone())
129
137
/// // .build()
@@ -155,12 +163,15 @@ impl Default for RuntimeEnv {
155
163
}
156
164
}
157
165
158
- /// Please see: <https://github.com/apache/datafusion/issues/12156 >
166
+ /// Please see: <https://github.com/apache/datafusion/issues/12156a >
159
167
/// This a type alias for backwards compatibility.
168
+ #[ deprecated( since = "43.0.0" , note = "please use `RuntimeEnvBuilder` instead" ) ]
160
169
pub type RuntimeConfig = RuntimeEnvBuilder ;
161
170
162
171
#[ derive( Clone ) ]
163
- /// Execution runtime configuration
172
+ /// Execution runtime configuration builder.
173
+ ///
174
+ /// See example on [`RuntimeEnv`]
164
175
pub struct RuntimeEnvBuilder {
165
176
/// DiskManager to manage temporary disk file usage
166
177
pub disk_manager : DiskManagerConfig ,
@@ -239,15 +250,20 @@ impl RuntimeEnvBuilder {
239
250
240
251
/// Build a RuntimeEnv
241
252
pub fn build ( self ) -> Result < RuntimeEnv > {
242
- let memory_pool = self
243
- . memory_pool
244
- . unwrap_or_else ( || Arc :: new ( UnboundedMemoryPool :: default ( ) ) ) ;
253
+ let Self {
254
+ disk_manager,
255
+ memory_pool,
256
+ cache_manager,
257
+ object_store_registry,
258
+ } = self ;
259
+ let memory_pool =
260
+ memory_pool. unwrap_or_else ( || Arc :: new ( UnboundedMemoryPool :: default ( ) ) ) ;
245
261
246
262
Ok ( RuntimeEnv {
247
263
memory_pool,
248
- disk_manager : DiskManager :: try_new ( self . disk_manager ) ?,
249
- cache_manager : CacheManager :: try_new ( & self . cache_manager ) ?,
250
- object_store_registry : self . object_store_registry ,
264
+ disk_manager : DiskManager :: try_new ( disk_manager) ?,
265
+ cache_manager : CacheManager :: try_new ( & cache_manager) ?,
266
+ object_store_registry,
251
267
} )
252
268
}
253
269
0 commit comments