alamb commented on code in PR #4095: URL: https://github.com/apache/arrow-datafusion/pull/4095#discussion_r1014223721
########## datafusion/core/src/catalog/listing_schema.rs: ########## @@ -0,0 +1,145 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +//! listing_schema contains a SchemaProvider that scans ObjectStores for tables automatically +use crate::catalog::schema::SchemaProvider; +use crate::datasource::datasource::TableProviderFactory; +use crate::datasource::TableProvider; +use datafusion_common::DataFusionError; +use futures::TryStreamExt; +use object_store::ObjectStore; +use std::any::Any; +use std::collections::{HashMap, HashSet}; +use std::path::Path; +use std::sync::{Arc, Mutex}; + +/// A SchemaProvider that scans an ObjectStore to automatically discover tables +pub struct ListingSchemaProvider { + authority: String, + path: object_store::path::Path, + factory: Arc<dyn TableProviderFactory>, + store: Arc<dyn ObjectStore>, + tables: Arc<Mutex<HashMap<String, Arc<dyn TableProvider>>>>, +} + +impl ListingSchemaProvider { + /// Create a new ListingSchemaProvider + pub fn new( + authority: String, + path: object_store::path::Path, + factory: Arc<dyn TableProviderFactory>, + store: Arc<dyn ObjectStore>, + ) -> Self { + Self { + authority, + path, + factory, + store, + tables: Arc::new(Mutex::new(HashMap::new())), + } + } + + /// Reload table information from ObjectStore Review Comment: I agree that there is no policy that will work well for all implementations / usecases so the refresh policy will need to be decided by whatever the upstream system is (e.g. ballista or iox, or whatever) Adding a `refresh()` method to `SchemaProvider` seems fine, though to be honest I think using `downcast_ref()` also seems fine to me Would definitely be interested in hearing other opinions on this -- 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: github-unsubscr...@arrow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org