You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2022/11/15 20:29:35 UTC

[GitHub] [arrow-datafusion] timvw opened a new pull request, #4227: refactor how we create listing tables

timvw opened a new pull request, #4227:
URL: https://github.com/apache/arrow-datafusion/pull/4227

   # Which issue does this PR close?
   
   <!--
   We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes #123` indicates that this PR will close issue #123.
   -->
   
   Closes #.
   
   # Rationale for this change
   
   <!--
    Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed.
    Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes.  
   -->
   
   # What changes are included in this PR?
   
   <!--
   There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR.
   -->
   
   # Are these changes tested?
   
   <!--
   We typically require tests for all PRs in order to:
   1. Prevent the code from being accidentally broken by subsequent changes
   2. Serve as another way to document the expected behavior of the code
   
   If tests are not included in your PR, please explain why (for example, are they covered by existing tests)?
   -->
   
   # Are there any user-facing changes?
   
   <!--
   If there are user-facing changes then we may require documentation to be updated before approving the PR.
   -->
   
   <!--
   If there are any breaking changes to public APIs, please add the `api change` label.
   -->


-- 
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-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-datafusion] avantgardnerio commented on pull request #4227: refactor how we create listing tables

Posted by GitBox <gi...@apache.org>.
avantgardnerio commented on PR #4227:
URL: https://github.com/apache/arrow-datafusion/pull/4227#issuecomment-1315902831

   Just because it's not obvious, I'd like to leave a note here to say that the real functionality of the Factories is to allow other repos to register TableProviders we don't even know about at compile time: https://github.com/delta-io/delta-rs/pull/892


-- 
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-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-datafusion] ursabot commented on pull request #4227: refactor how we create listing tables

Posted by GitBox <gi...@apache.org>.
ursabot commented on PR #4227:
URL: https://github.com/apache/arrow-datafusion/pull/4227#issuecomment-1318794613

   Benchmark runs are scheduled for baseline = a0581dc61beef8400157177134956e0875934a14 and contender = e18f7bac209987dcc95c1bfa01de9c13ef75efe4. e18f7bac209987dcc95c1bfa01de9c13ef75efe4 is a master commit associated with this PR. Results will be available as each benchmark for each run completes.
   Conbench compare runs links:
   [Skipped :warning: Benchmarking of arrow-datafusion-commits is not supported on ec2-t3-xlarge-us-east-2] [ec2-t3-xlarge-us-east-2](https://conbench.ursa.dev/compare/runs/59e61ffd76c24bc0bc5cf7d3cb6d38e8...e97c339fa42a4574927cf7f12cfe4a96/)
   [Skipped :warning: Benchmarking of arrow-datafusion-commits is not supported on test-mac-arm] [test-mac-arm](https://conbench.ursa.dev/compare/runs/fa809f26270745808c3d75ade8c969f8...0de3ce9e835e447b9dfca7d37362b022/)
   [Skipped :warning: Benchmarking of arrow-datafusion-commits is not supported on ursa-i9-9960x] [ursa-i9-9960x](https://conbench.ursa.dev/compare/runs/44c64be0a9dd4bf0972635c0e56f309d...bc8b0799c80d482eb011e724e245f48d/)
   [Skipped :warning: Benchmarking of arrow-datafusion-commits is not supported on ursa-thinkcentre-m75q] [ursa-thinkcentre-m75q](https://conbench.ursa.dev/compare/runs/69c0e524d4cc41309af6f3357700b9fe...6fbda19f36ca437e828a7cbaccbe367e/)
   Buildkite builds:
   Supported benchmarks:
   ec2-t3-xlarge-us-east-2: Supported benchmark langs: Python, R. Runs only benchmarks with cloud = True
   test-mac-arm: Supported benchmark langs: C++, Python, R
   ursa-i9-9960x: Supported benchmark langs: Python, R, JavaScript
   ursa-thinkcentre-m75q: Supported benchmark langs: C++, Java
   


-- 
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-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-datafusion] avantgardnerio commented on pull request #4227: refactor how we create listing tables

Posted by GitBox <gi...@apache.org>.
avantgardnerio commented on PR #4227:
URL: https://github.com/apache/arrow-datafusion/pull/4227#issuecomment-1315899483

   > Is it possible that "with_listing_schema_provider" implementation/test is missing something?
   
   Definitely possible... what makes you ask?


-- 
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-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-datafusion] timvw commented on a diff in pull request #4227: refactor how we create listing tables

Posted by GitBox <gi...@apache.org>.
timvw commented on code in PR #4227:
URL: https://github.com/apache/arrow-datafusion/pull/4227#discussion_r1023566499


##########
datafusion/core/src/execution/runtime_env.rs:
##########
@@ -152,7 +153,16 @@ pub struct RuntimeConfig {
 impl RuntimeConfig {
     /// New with default values
     pub fn new() -> Self {
-        Default::default()
+        let mut table_factories: HashMap<String, Arc<dyn TableProviderFactory>> =
+            HashMap::new();
+        table_factories.insert("PARQUET".into(), Arc::new(ListingTableFactory::new()));
+        table_factories.insert("CSV".into(), Arc::new(ListingTableFactory::new()));
+        table_factories.insert("JSON".into(), Arc::new(ListingTableFactory::new()));

Review Comment:
   > do we need to add an entry for "NDJSON" as well? See #4198
   
   This would be possible but I would do that in a separate PR (Not clear how/when the tableprovider for ndjson from https://github.com/apache/arrow-datafusion/pull/404/files got lost).



-- 
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-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-datafusion] timvw commented on pull request #4227: refactor how we create listing tables

Posted by GitBox <gi...@apache.org>.
timvw commented on PR #4227:
URL: https://github.com/apache/arrow-datafusion/pull/4227#issuecomment-1316461984

   It is still possible to register other/unknown tableproviderfactories. This happens in eg: test sql::create_drop::create_external_table_with_ddl.
   
   There is a slight change in how ListingSchemaProvider (this is very new functionality anyway) behaves (as it now requires a fileformat and (optional) has_header values).
   
   (In a next step i'd like to move the has_header, delimiter etc values into options of CreateExternalTable command)


-- 
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-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-datafusion] alamb commented on pull request #4227: refactor how we create listing tables

Posted by GitBox <gi...@apache.org>.
alamb commented on PR #4227:
URL: https://github.com/apache/arrow-datafusion/pull/4227#issuecomment-1318794878

   🚀 


-- 
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-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-datafusion] andygrove merged pull request #4227: refactor how we create listing tables

Posted by GitBox <gi...@apache.org>.
andygrove merged PR #4227:
URL: https://github.com/apache/arrow-datafusion/pull/4227


-- 
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-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-datafusion] alamb commented on a diff in pull request #4227: refactor how we create listing tables

Posted by GitBox <gi...@apache.org>.
alamb commented on code in PR #4227:
URL: https://github.com/apache/arrow-datafusion/pull/4227#discussion_r1025261843


##########
datafusion-cli/src/main.rs:
##########
@@ -147,31 +143,11 @@ pub async fn main() -> Result<()> {
 }
 
 fn create_runtime_env() -> Result<RuntimeEnv> {
-    let mut table_factories: HashMap<String, Arc<dyn TableProviderFactory>> =
-        HashMap::new();
-    table_factories.insert(
-        "csv".to_string(),
-        Arc::new(ListingTableFactory::new(FileType::CSV)),
-    );
-    table_factories.insert(
-        "parquet".to_string(),
-        Arc::new(ListingTableFactory::new(FileType::PARQUET)),
-    );
-    table_factories.insert(
-        "avro".to_string(),
-        Arc::new(ListingTableFactory::new(FileType::AVRO)),
-    );
-    table_factories.insert(
-        "json".to_string(),
-        Arc::new(ListingTableFactory::new(FileType::JSON)),
-    );
-
     let object_store_provider = DatafusionCliObjectStoreProvider {};
     let object_store_registry =
         ObjectStoreRegistry::new_with_provider(Some(Arc::new(object_store_provider)));
     let rn_config = RuntimeConfig::new()
-        .with_object_store_registry(Arc::new(object_store_registry))
-        .with_table_factories(table_factories);
+        .with_object_store_registry(Arc::new(object_store_registry));

Review Comment:
   ❤️ 



##########
datafusion/core/src/catalog/listing_schema.rs:
##########
@@ -59,18 +61,24 @@ impl ListingSchemaProvider {
     /// `path`: The root path that contains subfolders which represent tables
     /// `factory`: The `TableProviderFactory` to use to instantiate tables for each subfolder
     /// `store`: The `ObjectStore` containing the table data
+    /// `format`: The `FileFormat` of the tables

Review Comment:
   I am not sure it matters, but this says `FileFormat` but the actual argument is a String



-- 
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-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-datafusion] andygrove commented on a diff in pull request #4227: refactor how we create listing tables

Posted by GitBox <gi...@apache.org>.
andygrove commented on code in PR #4227:
URL: https://github.com/apache/arrow-datafusion/pull/4227#discussion_r1024278856


##########
datafusion/core/src/datasource/listing_table_factory.rs:
##########
@@ -52,27 +58,61 @@ impl TableProviderFactory for ListingTableFactory {
         state: &SessionState,
         cmd: &CreateExternalTable,
     ) -> datafusion_common::Result<Arc<dyn TableProvider>> {
-        let file_extension = self.file_type.get_ext();
+        let file_compression_type =
+            match FileCompressionType::from_str(cmd.file_compression_type.as_str()) {
+                Ok(t) => t,
+                Err(_) => Err(DataFusionError::Execution(
+                    "Only known FileCompressionTypes can be ListingTables!".to_string(),
+                ))?,
+            };
+
+        let file_type = match FileType::from_str(cmd.file_type.as_str()) {
+            Ok(t) => t,
+            Err(_) => Err(DataFusionError::Execution(
+                "Only known FileTypes can be ListingTables!".to_string(),
+            ))?,
+        };

Review Comment:
   Let's include some context in the error message so the user knows what they used that isn't supported. Also changes to use `map_err` to remove the need to match here.
   
   ```suggestion
           let file_compression_type = FileCompressionType::from_str(
               cmd.file_compression_type.as_str(),
           )
           .map_err(|_| {
               DataFusionError::Execution(format!(
                   "Unknown FileCompressionType {}",
                   cmd.file_compression_type.as_str()
               ))
           })?;
           let file_type = FileType::from_str(cmd.file_type.as_str()).map_err(|_| {
               DataFusionError::Execution(format!("Unknown FileType {}", cmd.file_type))
           })?;
   ```



-- 
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-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-datafusion] timvw commented on a diff in pull request #4227: refactor how we create listing tables

Posted by GitBox <gi...@apache.org>.
timvw commented on code in PR #4227:
URL: https://github.com/apache/arrow-datafusion/pull/4227#discussion_r1023245036


##########
datafusion/core/src/execution/context.rs:
##########
@@ -2296,8 +2235,8 @@ mod tests {
         let url = format!("file://{}", path.display());
 
         let mut table_factories: HashMap<String, Arc<dyn TableProviderFactory>> =
-            HashMap::new();
-        let factory = Arc::new(ListingTableFactory::new(FileType::CSV));
+            RuntimeConfig::default().table_factories;
+        let factory = Arc::new(ListingTableFactory::new());
         table_factories.insert("test".to_string(), factory);
         let rt_cfg = RuntimeConfig::new().with_table_factories(table_factories);

Review Comment:
   Probably want an easier way to add/register additional factories (instead of re-providing the entire collection), similar to object_store_registry



-- 
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-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-datafusion] avantgardnerio commented on pull request #4227: refactor how we create listing tables

Posted by GitBox <gi...@apache.org>.
avantgardnerio commented on PR #4227:
URL: https://github.com/apache/arrow-datafusion/pull/4227#issuecomment-1315900483

   > Ideally we extend the catalog.XXX options such that this can be provided as parameter as well?
   
   That's what I was thinking...


-- 
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-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-datafusion] timvw commented on pull request #4227: refactor how we create listing tables

Posted by GitBox <gi...@apache.org>.
timvw commented on PR #4227:
URL: https://github.com/apache/arrow-datafusion/pull/4227#issuecomment-1315842450

   @avantgardnerio Is it possible that "with_listing_schema_provider" implementation/test is missing something?


-- 
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-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-datafusion] timvw commented on a diff in pull request #4227: refactor how we create listing tables

Posted by GitBox <gi...@apache.org>.
timvw commented on code in PR #4227:
URL: https://github.com/apache/arrow-datafusion/pull/4227#discussion_r1023570338


##########
datafusion/core/src/execution/runtime_env.rs:
##########
@@ -152,7 +153,16 @@ pub struct RuntimeConfig {
 impl RuntimeConfig {
     /// New with default values
     pub fn new() -> Self {
-        Default::default()
+        let mut table_factories: HashMap<String, Arc<dyn TableProviderFactory>> =
+            HashMap::new();
+        table_factories.insert("PARQUET".into(), Arc::new(ListingTableFactory::new()));
+        table_factories.insert("CSV".into(), Arc::new(ListingTableFactory::new()));
+        table_factories.insert("JSON".into(), Arc::new(ListingTableFactory::new()));

Review Comment:
   This, NDJSON missing, and compression only being supported in some code paths is the reason I believe this refactoring is much needed...



-- 
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-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-datafusion] timvw commented on pull request #4227: refactor how we create listing tables

Posted by GitBox <gi...@apache.org>.
timvw commented on PR #4227:
URL: https://github.com/apache/arrow-datafusion/pull/4227#issuecomment-1315888283

   I have updated the semantics of catalog.type such that it indicates the fileformat.. 
   
   Only difference is now that by default we assume CSV does not have a header line. 
   The with_listing_schema_provider test uses tests/tpch-csv data which does have a header column... 
   Ideally we extend the catalog.XXX options such that this can be provided as parameter as well? 


-- 
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-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-datafusion] timvw commented on a diff in pull request #4227: refactor how we create listing tables

Posted by GitBox <gi...@apache.org>.
timvw commented on code in PR #4227:
URL: https://github.com/apache/arrow-datafusion/pull/4227#discussion_r1023566499


##########
datafusion/core/src/execution/runtime_env.rs:
##########
@@ -152,7 +153,16 @@ pub struct RuntimeConfig {
 impl RuntimeConfig {
     /// New with default values
     pub fn new() -> Self {
-        Default::default()
+        let mut table_factories: HashMap<String, Arc<dyn TableProviderFactory>> =
+            HashMap::new();
+        table_factories.insert("PARQUET".into(), Arc::new(ListingTableFactory::new()));
+        table_factories.insert("CSV".into(), Arc::new(ListingTableFactory::new()));
+        table_factories.insert("JSON".into(), Arc::new(ListingTableFactory::new()));

Review Comment:
   > do we need to add an entry for "NDJSON" as well? See #4198
   
   This would be possible, but currently (logical/datasource) FileType::from_str only knows about avro,parquet,json and csv and will err.. So more changes will be needed to enable NDJSON again..



-- 
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-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-datafusion] andygrove commented on a diff in pull request #4227: refactor how we create listing tables

Posted by GitBox <gi...@apache.org>.
andygrove commented on code in PR #4227:
URL: https://github.com/apache/arrow-datafusion/pull/4227#discussion_r1023280477


##########
datafusion/core/src/execution/runtime_env.rs:
##########
@@ -152,7 +153,16 @@ pub struct RuntimeConfig {
 impl RuntimeConfig {
     /// New with default values
     pub fn new() -> Self {
-        Default::default()
+        let mut table_factories: HashMap<String, Arc<dyn TableProviderFactory>> =
+            HashMap::new();
+        table_factories.insert("PARQUET".into(), Arc::new(ListingTableFactory::new()));
+        table_factories.insert("CSV".into(), Arc::new(ListingTableFactory::new()));
+        table_factories.insert("JSON".into(), Arc::new(ListingTableFactory::new()));

Review Comment:
   do we need to add an entry for "NDJSON" as well? See https://github.com/apache/arrow-datafusion/issues/4198



-- 
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-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-datafusion] avantgardnerio commented on pull request #4227: refactor how we create listing tables

Posted by GitBox <gi...@apache.org>.
avantgardnerio commented on PR #4227:
URL: https://github.com/apache/arrow-datafusion/pull/4227#issuecomment-1315898990

   Nice work, ty @timvw !


-- 
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-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-datafusion] alamb commented on pull request #4227: refactor how we create listing tables

Posted by GitBox <gi...@apache.org>.
alamb commented on PR #4227:
URL: https://github.com/apache/arrow-datafusion/pull/4227#issuecomment-1317946838

   I am looking forward to reviewing this tomorrow -- thank you @timvw 


-- 
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-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org