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/08 21:47:26 UTC

[GitHub] [arrow-datafusion] alamb commented on a diff in pull request #4143: add schema parameter to table provider factory create method

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


##########
datafusion/core/tests/sql/create_drop.rs:
##########
@@ -387,6 +387,36 @@ async fn create_custom_table() -> Result<()> {
     Ok(())
 }
 
+#[tokio::test]
+async fn create_external_table_with_ddl() -> Result<()> {
+    let mut table_factories: HashMap<String, Arc<dyn TableProviderFactory>> =
+        HashMap::new();
+    table_factories.insert("mocktable".to_string(), Arc::new(TestTableFactory {}));
+    let cfg = RuntimeConfig::new().with_table_factories(table_factories);
+    let env = RuntimeEnv::new(cfg).unwrap();
+    let ses = SessionConfig::new();
+    let ctx = SessionContext::with_config_rt(ses, Arc::new(env));
+
+    let sql = "CREATE EXTERNAL TABLE dt (a_id integer, a_str string, a_bool boolean) STORED AS MOCKTABLE LOCATION 'mockprotocol://path/to/table';";
+    ctx.sql(sql).await.unwrap();
+
+    let cat = ctx.catalog("datafusion").unwrap();
+    let schema = cat.schema("public").unwrap();
+
+    let exists = schema.table_exist("dt");
+    assert!(exists, "Table should have been created!");
+
+    let table_schema = schema.table("dt").unwrap().schema();
+
+    assert_eq!(3, table_schema.fields().len());
+
+    assert_eq!(&DataType::Int32, table_schema.field(0).data_type());

Review Comment:
   👍 



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