avantgardnerio commented on code in PR #4095:
URL: https://github.com/apache/arrow-datafusion/pull/4095#discussion_r1013312827


##########
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:
   That is the big open question with this PR :smile: . Presently, in 
`flight_sql.rs` in Ballista, when FlightSql clients enumerate the 
catalogs/schemas/tables, I am doing a checked `downcast_ref` to see if it is a 
`ListingSchemaProvider` and if so calling this method. Ultimately, I think we 
should probably extend the `SchemaProvider` API? The downcast trick certainly 
doesn't seem elegant.
   
   Unfortunately this is a state synchronization problem, and I'm not sure that 
the `ObjectStore` has APIs for file system listeners, so we will need to figure 
out the best times to try to synchronize the state. Every time we run a query 
perhaps? My worry is that this could get expensive, I can imagine (or have 
heard about) each delta table containing 1000 parquet files, and there could 
probably be 100s of tables, which means a lot of files to scan.
   
   Also unfortunately, it looks like the `ObjectStore` doesn't let us list only 
children of a folder - it lists all the files in the entire bucket, thus the 
weird recursive `.parent()` stuff.
   
   I thought I would file this PR to get the discussion going.



-- 
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