This is an automated email from the ASF dual-hosted git repository.

xuanwo pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/iceberg-rust.git


The following commit(s) were added to refs/heads/main by this push:
     new e5fffe4c fix(catalog): fix sql catalog drop table (#853)
e5fffe4c is described below

commit e5fffe4cd113844423c0060c9d59a7deda9eb3f7
Author: Li0k <[email protected]>
AuthorDate: Fri Dec 27 19:13:56 2024 +0800

    fix(catalog): fix sql catalog drop table (#853)
---
 crates/catalog/sql/src/catalog.rs | 58 ++++++++++++++++++++++++++++++++++++++-
 1 file changed, 57 insertions(+), 1 deletion(-)

diff --git a/crates/catalog/sql/src/catalog.rs 
b/crates/catalog/sql/src/catalog.rs
index 51e2904f..b6bff789 100644
--- a/crates/catalog/sql/src/catalog.rs
+++ b/crates/catalog/sql/src/catalog.rs
@@ -588,8 +588,8 @@ impl Catalog for SqlCatalog {
             &format!(
                 "DELETE FROM {CATALOG_TABLE_NAME}
                  WHERE {CATALOG_FIELD_CATALOG_NAME} = ?
-                  AND {CATALOG_FIELD_TABLE_NAMESPACE} = ?
                   AND {CATALOG_FIELD_TABLE_NAME} = ?
+                  AND {CATALOG_FIELD_TABLE_NAMESPACE} = ?
                   AND (
                     {CATALOG_FIELD_RECORD_TYPE} = 
'{CATALOG_FIELD_TABLE_RECORD_TYPE}' 
                     OR {CATALOG_FIELD_RECORD_TYPE} IS NULL
@@ -1714,4 +1714,60 @@ mod tests {
             format!("Unexpected => Table {:?} already exists.", 
&dst_table_ident),
         );
     }
+
+    #[tokio::test]
+    async fn test_drop_table_throws_error_if_table_not_exist() {
+        let warehouse_loc = temp_path();
+        let catalog = new_sql_catalog(warehouse_loc.clone()).await;
+        let namespace_ident = NamespaceIdent::new("a".into());
+        let table_name = "tbl1";
+        let table_ident = TableIdent::new(namespace_ident.clone(), 
table_name.into());
+        create_namespace(&catalog, &namespace_ident).await;
+
+        let err = catalog
+            .drop_table(&table_ident)
+            .await
+            .unwrap_err()
+            .to_string();
+        assert_eq!(
+            err,
+            "Unexpected => No such table: TableIdent { namespace: 
NamespaceIdent([\"a\"]), name: \"tbl1\" }"
+        );
+    }
+
+    #[tokio::test]
+    async fn test_drop_table() {
+        let warehouse_loc = temp_path();
+        let catalog = new_sql_catalog(warehouse_loc.clone()).await;
+        let namespace_ident = NamespaceIdent::new("a".into());
+        let table_name = "tbl1";
+        let table_ident = TableIdent::new(namespace_ident.clone(), 
table_name.into());
+        create_namespace(&catalog, &namespace_ident).await;
+
+        let location = warehouse_loc.clone();
+        let table_creation = TableCreation::builder()
+            .name(table_name.into())
+            .location(location.clone())
+            .schema(simple_table_schema())
+            .build();
+
+        catalog
+            .create_table(&namespace_ident, table_creation)
+            .await
+            .unwrap();
+
+        let table = catalog.load_table(&table_ident).await.unwrap();
+        assert_table_eq(&table, &table_ident, &simple_table_schema());
+
+        catalog.drop_table(&table_ident).await.unwrap();
+        let err = catalog
+            .load_table(&table_ident)
+            .await
+            .unwrap_err()
+            .to_string();
+        assert_eq!(
+            err,
+            "Unexpected => No such table: TableIdent { namespace: 
NamespaceIdent([\"a\"]), name: \"tbl1\" }"
+        );
+    }
 }

Reply via email to