fix(namespace): map rename_table errors to typed errors (#5254)

`LanceNamespaceDatabase::rename_table` wrapped every namespace error in
a generic `Error::Runtime`, so renaming a missing table did not return
`TableNotFound`, unlike `drop_table`.

- Map errors through `map_namespace_lance_error`, so a missing source
table returns `Error::TableNotFound`.
- When the destination name is taken, report `TableAlreadyExists` with
the destination name, not the source name.
- Other errors no longer carry the "Failed to rename table:" prefix.

Tests: `test_namespace_rename_missing_table_returns_not_found` fails on
main with `Runtime { "Failed to rename table: Namespace error: Table not
found ..." }` and passes with this change.
`test_namespace_rename_to_existing_table_returns_already_exists` covers
the destination-name case.
This commit is contained in:
Olexandr88
2026-11-30 20:12:00 +08:00
committed by GitHub
parent 8c101f49b9
commit 3b8584cd7d
+79 -2
View File
@@ -577,8 +577,12 @@ impl Database for LanceNamespaceDatabase {
self.namespace
.rename_table(rename_request)
.await
.map_err(|e| Error::Runtime {
message: format!("Failed to rename table: {}", e),
.map_err(|e| match map_namespace_lance_error(e, cur_name) {
// A conflict here means the destination name is taken.
Error::TableAlreadyExists { .. } => Error::TableAlreadyExists {
name: new_name.to_string(),
},
other => other,
})?;
Ok(())
@@ -1693,6 +1697,79 @@ mod tests {
assert!(open_result.is_err());
}
#[tokio::test]
async fn test_namespace_rename_missing_table_returns_not_found() {
let tmp_dir = tempdir().unwrap();
let mut properties = HashMap::new();
properties.insert(
"root".to_string(),
tmp_dir.path().to_str().unwrap().to_string(),
);
let conn = connect_namespace("dir", properties)
.execute()
.await
.expect("Failed to connect to namespace");
conn.create_namespace(CreateNamespaceRequest {
id: Some(vec!["test_ns".into()]),
..Default::default()
})
.await
.expect("Failed to create namespace");
let error = conn
.rename_table(
"missing",
"renamed",
&["test_ns".into()],
&["test_ns".into()],
)
.await
.expect_err("renaming a missing table should fail");
assert!(
matches!(error, Error::TableNotFound { ref name, .. } if name == "missing"),
"expected TableNotFound, got: {error:?}"
);
}
#[tokio::test]
async fn test_namespace_rename_to_existing_table_returns_already_exists() {
let tmp_dir = tempdir().unwrap();
let mut properties = HashMap::new();
properties.insert(
"root".to_string(),
tmp_dir.path().to_str().unwrap().to_string(),
);
let conn = connect_namespace("dir", properties)
.execute()
.await
.expect("Failed to connect to namespace");
conn.create_namespace(CreateNamespaceRequest {
id: Some(vec!["test_ns".into()]),
..Default::default()
})
.await
.expect("Failed to create namespace");
for name in ["source", "taken"] {
conn.create_table(name, create_test_data())
.namespace(vec!["test_ns".into()])
.execute()
.await
.expect("Failed to create table");
}
let error = conn
.rename_table("source", "taken", &["test_ns".into()], &["test_ns".into()])
.await
.expect_err("renaming onto an existing table should fail");
assert!(
matches!(error, Error::TableAlreadyExists { ref name } if name == "taken"),
"expected TableAlreadyExists for the destination, got: {error:?}"
);
}
#[tokio::test]
async fn test_table_names_at_root() {
// Test that table_names at root (empty namespace) works correctly