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


##########
datafusion/core/src/datasource/listing_table_factory.rs:
##########
@@ -0,0 +1,79 @@
+// 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.
+
+//! Factory for creating ListingTables with default options
+
+use crate::datasource::datasource::TableProviderFactory;
+use crate::datasource::file_format::avro::AvroFormat;
+use crate::datasource::file_format::csv::CsvFormat;
+use crate::datasource::file_format::file_type::{FileType, GetExt};
+use crate::datasource::file_format::json::JsonFormat;
+use crate::datasource::file_format::parquet::ParquetFormat;
+use crate::datasource::file_format::FileFormat;
+use crate::datasource::listing::{
+    ListingOptions, ListingTable, ListingTableConfig, ListingTableUrl,
+};
+use crate::datasource::TableProvider;
+use crate::execution::context::SessionState;
+use async_trait::async_trait;
+use std::sync::Arc;
+
+/// A `TableProviderFactory` capable of creating new `ListingTable`s
+pub struct ListingTableFactory {
+    file_type: FileType,
+}
+
+impl ListingTableFactory {
+    /// Creates a new `ListingTableFactory`
+    pub fn new(file_type: FileType) -> Self {
+        Self { file_type }
+    }
+}
+
+#[async_trait]
+impl TableProviderFactory for ListingTableFactory {
+    async fn create(
+        &self,
+        state: &SessionState,
+        url: &str,
+    ) -> datafusion_common::Result<Arc<dyn TableProvider>> {
+        let file_extension = self.file_type.get_ext();
+
+        let file_format: Arc<dyn FileFormat> = match self.file_type {

Review Comment:
   🤔  it would be really neat to somehow combine the logic in ListingTable and 
ListingTableFactory (or maybe datafusion-cli could just use the factory -- not 
sure)



##########
datafusion/core/src/catalog/listing_schema.rs:
##########
@@ -100,13 +102,20 @@ impl ListingSchemaProvider {
                 .ok_or_else(|| {
                     DataFusionError::Internal("Cannot parse file 
name!".to_string())
                 })?;
-            let table_name = table.to_str().ok_or_else(|| {
+            let table_name = file_name.split('.').collect_vec()[0];

Review Comment:
   Which method? Maybe we can contribute something back upstream to 
object_store 🤔 



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

Reply via email to