Skip to content

Commit

Permalink
Fix PR review
Browse files Browse the repository at this point in the history
  • Loading branch information
kyotoYaho committed Jul 18, 2022
1 parent 7dda307 commit 2b0c6ad
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions datafusion/core/src/datasource/object_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,15 @@ impl std::fmt::Display for ObjectStoreUrl {
pub trait ObjectStoreProvider: Send + Sync + 'static {
/// Detector a suitable object store based on its url if possible
/// Return the key and object store
fn get_by_url(&self, url: &Url) -> Option<(String, Arc<dyn ObjectStore>)>;
fn get_by_url(&self, url: &Url) -> Option<Arc<dyn ObjectStore>>;
}

/// Object store registry
#[derive(Clone)]
pub struct ObjectStoreRegistry {
/// A map from scheme to object store that serve list / read operations for the store
object_stores: Arc<RwLock<HashMap<String, Arc<dyn ObjectStore>>>>,
self_detector: Option<Arc<dyn ObjectStoreProvider>>,
provider: Option<Arc<dyn ObjectStoreProvider>>,
}

impl std::fmt::Debug for ObjectStoreRegistry {
Expand All @@ -116,19 +116,17 @@ impl Default for ObjectStoreRegistry {
impl ObjectStoreRegistry {
/// By default the self detector is None
pub fn new() -> Self {
ObjectStoreRegistry::new_with_detector(None)
ObjectStoreRegistry::new_with_provider(None)
}

/// Create the registry that object stores can registered into.
/// ['LocalFileSystem'] store is registered in by default to support read local files natively.
pub fn new_with_detector(
self_detector: Option<Arc<dyn ObjectStoreProvider>>,
) -> Self {
pub fn new_with_provider(provider: Option<Arc<dyn ObjectStoreProvider>>) -> Self {
let mut map: HashMap<String, Arc<dyn ObjectStore>> = HashMap::new();
map.insert("file://".to_string(), Arc::new(LocalFileSystem::new()));
Self {
object_stores: Arc::new(RwLock::new(map)),
self_detector,
provider,
}
}

Expand Down Expand Up @@ -163,11 +161,13 @@ impl ObjectStoreRegistry {
// If not, then try to detector based on its url.
let store = store
.or_else(|| {
if let Some(self_detector) = &self.self_detector {
if let Some(provider) = &self.provider {
// If detected, register it
if let Some((key, store)) = self_detector.get_by_url(url) {
if let Some(store) = provider.get_by_url(url) {
let mut stores = self.object_stores.write();
stores.insert(key, store.clone());
let key =
&url[url::Position::BeforeScheme..url::Position::BeforePath];
stores.insert(key.to_owned(), store.clone());
Some(store)
} else {
None
Expand Down

0 comments on commit 2b0c6ad

Please sign in to comment.