pepijnve commented on code in PR #25112:
URL: https://github.com/apache/datafusion/pull/25112#discussion_r4071590058


##########
datafusion/core/tests/sql/create_drop.rs:
##########
@@ -89,3 +113,104 @@ async fn create_drop_table() -> Result<()> {
 
     Ok(())
 }
+
+#[tokio::test]
+async fn create_external_catalog_with_factory() -> Result<()> {
+    let ctx: SessionContext = SessionStateBuilder::new()
+        .with_default_features()
+        .with_catalog_factory("TESTCATALOG", Arc::new(TestCatalogFactory {}))
+        .build()
+        .into();
+    let sql = "CREATE EXTERNAL CATALOG cat STORED AS TESTCATALOG LOCATION 
's3://bucket/warehouse' OPTIONS ('warehouse' 'cat')";
+    ctx.sql(sql).await?;
+
+    assert!(
+        ctx.catalog("cat").is_some(),
+        "Catalog should have been created!"
+    );
+
+    Ok(())
+}
+
+#[tokio::test]
+async fn create_external_catalog_unknown_factory() -> Result<()> {
+    let ctx = SessionContext::new();
+
+    let sql = "CREATE EXTERNAL CATALOG cat STORED AS TESTCATALOG LOCATION 
's3://bucket/warehouse'";
+    let err = ctx.sql(sql).await.unwrap_err();
+    assert_contains!(
+        err.to_string(),
+        "Unable to find catalog factory for TESTCATALOG"
+    );
+
+    Ok(())
+}
+
+#[tokio::test]
+async fn create_external_catalog_factory_error_not_registered() -> Result<()> {
+    let ctx: SessionContext = SessionStateBuilder::new()
+        .with_default_features()
+        .with_catalog_factory("TESTCATALOG", Arc::new(TestCatalogFactory {}))
+        .build()
+        .into();
+
+    let sql = "CREATE EXTERNAL CATALOG cat STORED AS TESTCATALOG LOCATION 
's3://x' OPTIONS ('fail' 'true')";
+    let err = ctx.sql(sql).await.unwrap_err();
+    assert_contains!(err.to_string(), "catalog factory configured to fail");
+    assert!(
+        ctx.catalog("cat").is_none(),
+        "Catalog should not have been registered when the factory errors"
+    );
+
+    Ok(())
+}
+
+#[tokio::test]
+async fn create_external_catalog_if_not_exists() -> Result<()> {
+    let ctx: SessionContext = SessionStateBuilder::new()
+        .with_default_features()
+        .with_catalog_factory("TESTCATALOG", Arc::new(TestCatalogFactory {}))
+        .build()
+        .into();
+
+    let sql = "CREATE EXTERNAL CATALOG cat STORED AS TESTCATALOG LOCATION 
's3://x'";
+    ctx.sql(sql).await?;
+
+    // creating it again without IF NOT EXISTS should fail
+    let err = ctx.sql(sql).await.unwrap_err();
+    assert_contains!(err.to_string(), "already exists");
+
+    // ... but should succeed with IF NOT EXISTS
+    let sql = "CREATE EXTERNAL CATALOG IF NOT EXISTS cat STORED AS TESTCATALOG 
LOCATION 's3://x'";
+    ctx.sql(sql).await?;
+
+    Ok(())
+}
+

Review Comment:
   Thanks for the suggestion. I've added this test case.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to