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/03/04 02:09:09 UTC

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

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