This is an automated email from the ASF dual-hosted git repository.
JingsongLi pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/paimon-rust.git
The following commit(s) were added to refs/heads/main by this push:
new f1f05629 [Bug] DROP TABLE deletes the wrong table when targets span
multiple catalogs (#1339)
f1f05629 is described below
commit f1f0562904900584212ce42c0178ed1f9778b719
Author: slfan1989 <[email protected]>
AuthorDate: Sun Nov 8 19:27:51 2026 +0800
[Bug] DROP TABLE deletes the wrong table when targets span multiple
catalogs (#1339)
---
crates/integrations/datafusion/src/sql_context.rs | 12 ++++----
.../datafusion/tests/sql_context_tests.rs | 35 ++++++++++++++++++++++
2 files changed, 41 insertions(+), 6 deletions(-)
diff --git a/crates/integrations/datafusion/src/sql_context.rs
b/crates/integrations/datafusion/src/sql_context.rs
index 72842818..e86e95f7 100644
--- a/crates/integrations/datafusion/src/sql_context.rs
+++ b/crates/integrations/datafusion/src/sql_context.rs
@@ -778,9 +778,7 @@ impl SQLContext {
// Only intercept DROP TABLE for Paimon catalogs; fall
through for others
let table_ref: TableReference =
names[0].to_string().as_str().into();
if self.is_paimon_catalog_ref(&table_ref) {
- let (catalog, _catalog_name, _) =
- self.resolve_catalog_and_table(&names[0])?;
- self.handle_drop_table(&catalog, names,
*if_exists).await
+ self.handle_drop_table(names, *if_exists).await
} else {
self.ctx.sql_with_options(sql, options).await
}
@@ -1354,12 +1352,14 @@ impl SQLContext {
async fn handle_drop_table(
&self,
- catalog: &Arc<dyn Catalog>,
names: &[ObjectName],
if_exists: bool,
) -> DFResult<DataFrame> {
- for name in names {
- let identifier = self.resolve_table_name(name)?;
+ let targets = names
+ .iter()
+ .map(|name| self.resolve_catalog_and_table(name))
+ .collect::<DFResult<Vec<_>>>()?;
+ for (catalog, _, identifier) in targets {
catalog
.drop_table(&identifier, if_exists)
.await
diff --git a/crates/integrations/datafusion/tests/sql_context_tests.rs
b/crates/integrations/datafusion/tests/sql_context_tests.rs
index 13e2a9d2..6a3617cb 100644
--- a/crates/integrations/datafusion/tests/sql_context_tests.rs
+++ b/crates/integrations/datafusion/tests/sql_context_tests.rs
@@ -1623,6 +1623,41 @@ async fn test_drop_table() {
);
}
+#[tokio::test]
+async fn test_drop_table_resolves_each_catalog() {
+ let (_tmp1, catalog1) = create_test_env();
+ let (_tmp2, catalog2) = create_test_env();
+ let mut ctx = SQLContext::new();
+ ctx.register_catalog("cat1", catalog1.clone())
+ .await
+ .unwrap();
+ ctx.register_catalog("cat2", catalog2.clone())
+ .await
+ .unwrap();
+
+ for sql in [
+ "CREATE TABLE cat1.default.a (id INT)",
+ "CREATE TABLE cat1.default.b (id INT)",
+ "CREATE TABLE cat2.default.b (id INT)",
+ ] {
+ ctx.sql(sql).await.unwrap();
+ }
+
+ ctx.sql("DROP TABLE cat1.default.a, cat2.default.b")
+ .await
+ .unwrap();
+ assert_eq!(catalog1.list_tables("default").await.unwrap(), vec!["b"]);
+ assert!(catalog2.list_tables("default").await.unwrap().is_empty());
+
+ assert_sql_error_contains(
+ &ctx,
+ "DROP TABLE cat1.default.b, missing.default.b",
+ "Unknown catalog 'missing'",
+ )
+ .await;
+ assert_eq!(catalog1.list_tables("default").await.unwrap(), vec!["b"]);
+}
+
// ======================= ALTER TABLE =======================
#[tokio::test]