alamb commented on code in PR #2906:
URL: https://github.com/apache/arrow-datafusion/pull/2906#discussion_r922075140


##########
datafusion/core/src/datasource/listing/helpers.rs:
##########
@@ -162,7 +162,7 @@ pub fn split_files(
 pub async fn pruned_partition_list<'a>(
     store: &'a dyn ObjectStore,
     table_path: &'a ListingTableUrl,
-    filters: &[Expr],
+    filters: &'a [Expr],

Review Comment:
   I also see this error occasionally (but not always) locally



##########
datafusion/core/src/datasource/object_store.rs:
##########
@@ -81,10 +81,19 @@ impl std::fmt::Display for ObjectStoreUrl {
     }
 }
 
+/// Object store self detector can detector an object store based on the url
+pub trait ObjectStoreSelfDetector: Send + Sync + 'static {

Review Comment:
   I think @tustvold 's suggestion is to use a slightly different name that 
perhaps is more conventional (I think often the term "Provider" is used to 
describe factory-like things in object oriented programming that instantiate 
instances of interfaces -- aka what this is doing)



##########
datafusion/core/src/datasource/object_store.rs:
##########
@@ -132,19 +149,51 @@ impl ObjectStoreRegistry {
     ///
     /// - URL with scheme `file:///` or no schema will return the default 
LocalFS store
     /// - URL with scheme `s3://bucket/` will return the S3 store if it's 
registered
+    /// - URL with scheme `hdfs://hostname:port` will return the hdfs store if 
it's registered
     ///
     pub fn get_by_url(&self, url: impl AsRef<Url>) -> Result<Arc<dyn 
ObjectStore>> {
         let url = url.as_ref();
-        let s = &url[url::Position::BeforeScheme..url::Position::AfterHost];
-        let stores = self.object_stores.read();
-        let store = stores.get(s).ok_or_else(|| {
-            DataFusionError::Internal(format!(
-                "No suitable object store found for {}",
-                url
-            ))
-        })?;
-
-        Ok(store.clone())
+        // First check whether can get object store from registry
+        let store = {
+            let stores = self.object_stores.read();
+            let s = 
&url[url::Position::BeforeScheme..url::Position::BeforeHost];

Review Comment:
   What if we called the detector *first* and if that does not return an 
instance, we can fall back to the `self.object_stores`? This would preserve the 
existing behavior and would likely have a simpler implementation
   
   Something like (untested): 
   
   ```rust
   let store = self_detector
     // try to get url from detector first
     .map(|detector| detector.get_by_url(url))
     // fallback to looking up by registered scheme
     .or_else(|| self.oject_stores.read().get(s))
     .ok_or_else(|| {
                   DataFusionError::Internal(format!(
                       "No suitable object store found for {}",
                       url
                   ))
               })?;
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to