@@ -83,9 +83,8 @@ impl std::fmt::Display for ObjectStoreUrl {
83
83
84
84
/// Object store provider can detector an object store based on the url
85
85
pub trait ObjectStoreProvider : Send + Sync + ' static {
86
- /// Detector a suitable object store based on its url if possible
87
- /// Return the key and object store
88
- fn get_by_url ( & self , url : & Url ) -> Option < Arc < dyn ObjectStore > > ;
86
+ /// Return an ObjectStore for the provided url based on its scheme and authority
87
+ fn get_by_url ( & self , url : & Url ) -> Result < Arc < dyn ObjectStore > > ;
89
88
}
90
89
91
90
/// Object store registry
@@ -157,32 +156,23 @@ impl ObjectStoreRegistry {
157
156
stores. get ( s) . cloned ( )
158
157
} ;
159
158
160
- // If not, then try to detector based on its url.
161
- let store = store
162
- . or_else ( || {
163
- if let Some ( provider) = & self . provider {
164
- // If detected, register it
165
- if let Some ( store) = provider. get_by_url ( url) {
166
- let mut stores = self . object_stores . write ( ) ;
167
- let key =
168
- & url[ url:: Position :: BeforeScheme ..url:: Position :: BeforePath ] ;
169
- stores. insert ( key. to_owned ( ) , store. clone ( ) ) ;
170
- Some ( store)
171
- } else {
172
- None
173
- }
174
- } else {
175
- None
159
+ match store {
160
+ Some ( store) => Ok ( store) ,
161
+ None => match & self . provider {
162
+ Some ( provider) => {
163
+ let store = provider. get_by_url ( url) ?;
164
+ let mut stores = self . object_stores . write ( ) ;
165
+ let key =
166
+ & url[ url:: Position :: BeforeScheme ..url:: Position :: BeforePath ] ;
167
+ stores. insert ( key. to_owned ( ) , store. clone ( ) ) ;
168
+ Ok ( store)
176
169
}
177
- } )
178
- . ok_or_else ( || {
179
- DataFusionError :: Internal ( format ! (
170
+ None => Err ( DataFusionError :: Internal ( format ! (
180
171
"No suitable object store found for {}" ,
181
172
url
182
- ) )
183
- } ) ?;
184
-
185
- Ok ( store)
173
+ ) ) ) ,
174
+ } ,
175
+ }
186
176
}
187
177
}
188
178
0 commit comments