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/02/18 04:24:22 UTC

[GitHub] [arrow-datafusion] matthewmturner opened a new pull request #1863: Enhance MemorySchemaProvider to support `read_listing_table`

matthewmturner opened a new pull request #1863:
URL: https://github.com/apache/arrow-datafusion/pull/1863


   # 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 #1836 
   
    # 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 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] alamb commented on pull request #1863: Enhance MemorySchemaProvider to support `register_listing_table`

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


   Sorry for the late review. Looking now


-- 
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] matthewmturner commented on pull request #1863: Enhance MemorySchemaProvider to support `register_listing_table`

Posted by GitBox <gi...@apache.org>.
matthewmturner commented on pull request #1863:
URL: https://github.com/apache/arrow-datafusion/pull/1863#issuecomment-1049999806


   @houqp do you have any thoughts 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-unsubscribe@arrow.apache.org

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



[GitHub] [arrow-datafusion] yjshen commented on a change in pull request #1863: Enhance MemorySchemaProvider to support `register_listing_table`

Posted by GitBox <gi...@apache.org>.
yjshen commented on a change in pull request #1863:
URL: https://github.com/apache/arrow-datafusion/pull/1863#discussion_r819211360



##########
File path: datafusion/src/catalog/schema.rs
##########
@@ -154,4 +208,100 @@ mod tests {
             provider.register_table(table_name.to_string(), Arc::new(other_table));
         assert!(result.is_err());
     }
+
+    #[tokio::test]
+    async fn test_schema_register_listing_table() {
+        let testdata = crate::test_util::parquet_test_data();
+        let filename = format!("{}/{}", testdata, "alltypes_plain.parquet");
+
+        let schema = MemorySchemaProvider::new();
+        let _store = schema.register_object_store("test", Arc::new(LocalFileSystem {}));
+
+        schema
+            .register_listing_table("alltypes_plain", &filename, None)
+            .await
+            .unwrap();
+
+        let catalog = MemoryCatalogProvider::new();
+        catalog.register_schema("active", Arc::new(schema));
+
+        let mut ctx = ExecutionContext::new();
+
+        ctx.register_catalog("cat", Arc::new(catalog));
+
+        let df = ctx
+            .sql("SELECT id, bool_col FROM cat.active.alltypes_plain")
+            .await
+            .unwrap();
+
+        let actual = df.collect().await.unwrap();
+
+        let expected = vec![
+            "+----+----------+",
+            "| id | bool_col |",
+            "+----+----------+",
+            "| 4  | true     |",
+            "| 5  | false    |",
+            "| 6  | true     |",
+            "| 7  | false    |",
+            "| 2  | true     |",
+            "| 3  | false    |",
+            "| 0  | true     |",
+            "| 1  | false    |",
+            "+----+----------+",
+        ];
+        assert_batches_eq!(expected, &actual);
+    }
+
+    #[tokio::test]
+    async fn test_schema_register_listing_tables() {
+        let testdata = crate::test_util::parquet_test_data();
+
+        let schema = MemorySchemaProvider::new();
+        let store = schema
+            .register_object_store("file", Arc::new(LocalFileSystem {}))
+            .unwrap();
+
+        let mut files = store.list_file(&testdata).await.unwrap();
+        while let Some(file) = files.next().await {
+            let sized_file = file.unwrap().sized_file;
+            let file = sized_file.path.split('/').last().unwrap();
+            if file == "alltypes_dictionary.parquet" || file == "alltypes_plain.parquet" {
+                let (name, _) = file.split_once(".").unwrap();

Review comment:
       ```suggestion
               let path = Path::new(&sized_file.path);
               let file = path.file_name().unwrap();
               if file == OsStr::new("alltypes_dictionary.parquet")
                   || file == OsStr::new("alltypes_plain.parquet")
               {
                   let name = path.file_stem().unwrap().to_str().unwrap();
   ```




-- 
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 #1863: Enhance MemorySchemaProvider to support `register_listing_table`

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


   > I don't understand why there should be various interfaces. If you want to achieve abstraction over tables, the best is to enable a single data abstraction/discovery interface that points to tables no matter where they are ?
   
   
   I think it comes down to if the InMemoryCatalog implementation would be used for interfaces on top of files -- aka do we want all InMemoryCatalog's to know about ObjectStores? 
   
   I can go either way -- if people prefer this way I am fine with that -- let's get the PR polished up and we can merge it in


-- 
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] matthewmturner edited a comment on pull request #1863: Enhance MemorySchemaProvider to support `register_listing_table`

Posted by GitBox <gi...@apache.org>.
matthewmturner edited a comment on pull request #1863:
URL: https://github.com/apache/arrow-datafusion/pull/1863#issuecomment-1058678976


   I agree with @Igosuki that it would be nice to have a single abstraction but im not sure this is the PR for that.  I've seen talks of other table providers, for example on slack a BigTable table provider was mentioned / potentially in the works - so its not clear to me where we would want to draw the line yet.
   
   My proposal would be to get this merged with the clear separation of functionalities (i.e. i migrate to `ObjectStoreSchemaProvider` and I can also make a separate issue to discuss having a single interface.


-- 
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] matthewmturner commented on pull request #1863: Enhance MemorySchemaProvider to support `register_listing_table`

Posted by GitBox <gi...@apache.org>.
matthewmturner commented on pull request #1863:
URL: https://github.com/apache/arrow-datafusion/pull/1863#issuecomment-1058678976


   I agree with @Igosuki that it would be nice to have a single abstraction but im not sure this is the PR for that.  I've seen talks of other table providers, for example on slack a BigTable table provider was mentioned / potentially in the works - so its not clear to me where we would want to draw the line yet.
   
   My proposal would be to get this merged with the clear separation of functionalities (i.e. i migrate to `ObjectStoreSchemaProvider` and I can also make a separate issue to discuss having a single interface - for example maybe a `TableRegistry`.


-- 
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] matthewmturner commented on a change in pull request #1863: Enhance MemorySchemaProvider to support `register_listing_table`

Posted by GitBox <gi...@apache.org>.
matthewmturner commented on a change in pull request #1863:
URL: https://github.com/apache/arrow-datafusion/pull/1863#discussion_r819290028



##########
File path: datafusion/src/catalog/schema.rs
##########
@@ -154,4 +208,100 @@ mod tests {
             provider.register_table(table_name.to_string(), Arc::new(other_table));
         assert!(result.is_err());
     }
+
+    #[tokio::test]
+    async fn test_schema_register_listing_table() {
+        let testdata = crate::test_util::parquet_test_data();
+        let filename = format!("{}/{}", testdata, "alltypes_plain.parquet");
+
+        let schema = MemorySchemaProvider::new();
+        let _store = schema.register_object_store("test", Arc::new(LocalFileSystem {}));
+
+        schema
+            .register_listing_table("alltypes_plain", &filename, None)
+            .await
+            .unwrap();
+
+        let catalog = MemoryCatalogProvider::new();
+        catalog.register_schema("active", Arc::new(schema));
+
+        let mut ctx = ExecutionContext::new();
+
+        ctx.register_catalog("cat", Arc::new(catalog));
+
+        let df = ctx
+            .sql("SELECT id, bool_col FROM cat.active.alltypes_plain")
+            .await
+            .unwrap();
+
+        let actual = df.collect().await.unwrap();
+
+        let expected = vec![
+            "+----+----------+",
+            "| id | bool_col |",
+            "+----+----------+",
+            "| 4  | true     |",
+            "| 5  | false    |",
+            "| 6  | true     |",
+            "| 7  | false    |",
+            "| 2  | true     |",
+            "| 3  | false    |",
+            "| 0  | true     |",
+            "| 1  | false    |",
+            "+----+----------+",
+        ];
+        assert_batches_eq!(expected, &actual);
+    }
+
+    #[tokio::test]
+    async fn test_schema_register_listing_tables() {
+        let testdata = crate::test_util::parquet_test_data();
+
+        let schema = MemorySchemaProvider::new();
+        let store = schema
+            .register_object_store("file", Arc::new(LocalFileSystem {}))
+            .unwrap();
+
+        let mut files = store.list_file(&testdata).await.unwrap();
+        while let Some(file) = files.next().await {
+            let sized_file = file.unwrap().sized_file;
+            let file = sized_file.path.split('/').last().unwrap();
+            if file == "alltypes_dictionary.parquet" || file == "alltypes_plain.parquet" {
+                let (name, _) = file.split_once(".").unwrap();

Review comment:
       @yjshen thx much




-- 
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] matthewmturner commented on pull request #1863: Enhance MemorySchemaProvider to support `register_listing_table`

Posted by GitBox <gi...@apache.org>.
matthewmturner commented on pull request #1863:
URL: https://github.com/apache/arrow-datafusion/pull/1863#issuecomment-1045541566


   @alamb @seddonm1 @Igosuki @returnString i've extended the `MemorySchemaProvider` to support creating `ListingTable` from an `ObjectStore`.  This can further be used with `object_store.list_file(...)` to create many tables in a directory at once.
   
   I havent yet tested with partitioned data, but I think this is a good start.
   
   I'm interested in your views.
   
   


-- 
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] matthewmturner commented on pull request #1863: Enhance MemorySchemaProvider to support `register_listing_table`

Posted by GitBox <gi...@apache.org>.
matthewmturner commented on pull request #1863:
URL: https://github.com/apache/arrow-datafusion/pull/1863#issuecomment-1058885322


   @alamb hopefully this is good now.


-- 
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] matthewmturner commented on pull request #1863: Enhance MemorySchemaProvider to support `register_listing_table`

Posted by GitBox <gi...@apache.org>.
matthewmturner commented on pull request #1863:
URL: https://github.com/apache/arrow-datafusion/pull/1863#issuecomment-1057673985


   @alamb do you think `ObjectStoreSchemaProvider` is the way to go here? Doing that makes sense to me to keep a cleaner separation of functionality without the bloat of `ObjectStore` when it isn't 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] Igosuki commented on pull request #1863: Enhance MemorySchemaProvider to support `register_listing_table`

Posted by GitBox <gi...@apache.org>.
Igosuki commented on pull request #1863:
URL: https://github.com/apache/arrow-datafusion/pull/1863#issuecomment-1058097772


   I don't understand why there should be various interfaces. If you want to achieve abstraction over tables, the best is to enable a single data abstraction/discovery interface that points to tables no matter where they are ?


-- 
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] matthewmturner commented on pull request #1863: Enhance MemorySchemaProvider to support `register_listing_table`

Posted by GitBox <gi...@apache.org>.
matthewmturner commented on pull request #1863:
URL: https://github.com/apache/arrow-datafusion/pull/1863#issuecomment-1051338450


   Its also quite interesting how this only fails CI tests on windows.
   
   Has anyone seen that issue with the object store abstraction before?


-- 
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 merged pull request #1863: Enhance MemorySchemaProvider to support `register_listing_table`

Posted by GitBox <gi...@apache.org>.
alamb merged pull request #1863:
URL: https://github.com/apache/arrow-datafusion/pull/1863


   


-- 
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] matthewmturner commented on pull request #1863: Enhance MemorySchemaProvider to support `read_listing_table`

Posted by GitBox <gi...@apache.org>.
matthewmturner commented on pull request #1863:
URL: https://github.com/apache/arrow-datafusion/pull/1863#issuecomment-1043871957


   Im looking into whether I should just have `register_object_store` do the same thing as the same named method on `ExecutionContext`


-- 
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 #1863: Enhance MemorySchemaProvider to support `register_listing_table`

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


   > My proposal would be to get this merged with the clear separation of functionalities (i.e. i migrate to ObjectStoreSchemaProvider and I can also make a separate issue to discuss having a single interface.
   
   
   Sounds good to me -- it seems to me like the only blocker is whatever is causing the test failure on Windows


-- 
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 #1863: Enhance MemorySchemaProvider to support `register_listing_table`

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


   > @alamb do you think ObjectStoreSchemaProvider is the way to go here? Doing that makes sense to me to keep a cleaner separation of functionality without the bloat of ObjectStore when it isn't needed.
   
   Yes, I do think that would be a cleaner separation of functionality. Does anyone else have opinions (@rdettai  or @yjshen  for example?)


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