Skip to content

Commit

Permalink
chore: improve the code
Browse files Browse the repository at this point in the history
  • Loading branch information
e1ijah1 committed Jan 12, 2023
1 parent 0163e93 commit b5487c9
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 17 deletions.
3 changes: 2 additions & 1 deletion src/catalog/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ pub trait CatalogManager: CatalogList {
async fn register_schema(&self, request: RegisterSchemaRequest) -> Result<bool>;

/// Rename a table to [RenameTableRequest::new_table_name], returns whether the table is renamed.
async fn rename_table(&self, request: RenameTableRequest, table_id: TableId) -> Result<bool>;
async fn rename_table(&self, request: RenameTableRequest) -> Result<bool>;

/// Register a system table, should be called before starting the manager.
async fn register_system_table(&self, request: RegisterSystemTableRequest)
Expand Down Expand Up @@ -151,6 +151,7 @@ pub struct RenameTableRequest {
pub schema: String,
pub table_name: String,
pub new_table_name: String,
pub table_id: TableId,
}

#[derive(Clone)]
Expand Down
4 changes: 2 additions & 2 deletions src/catalog/src/local/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ impl CatalogManager for LocalCatalogManager {
}
}

async fn rename_table(&self, request: RenameTableRequest, table_id: TableId) -> Result<bool> {
async fn rename_table(&self, request: RenameTableRequest) -> Result<bool> {
let started = self.init_lock.lock().await;

ensure!(
Expand Down Expand Up @@ -411,7 +411,7 @@ impl CatalogManager for LocalCatalogManager {
catalog_name.clone(),
schema_name.clone(),
request.new_table_name.clone(),
table_id,
request.table_id,
)
.await?;
Ok(schema
Expand Down
8 changes: 3 additions & 5 deletions src/catalog/src/local/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ impl CatalogManager for MemoryCatalogManager {
.map(|v| v.is_none())
}

async fn rename_table(&self, request: RenameTableRequest, _table_id: TableId) -> Result<bool> {
async fn rename_table(&self, request: RenameTableRequest) -> Result<bool> {
let catalogs = self.catalogs.write().unwrap();
let catalog = catalogs
.get(&request.catalog)
Expand Down Expand Up @@ -456,11 +456,9 @@ mod tests {
schema: DEFAULT_SCHEMA_NAME.to_string(),
table_name: table_name.to_string(),
new_table_name: new_table_name.to_string(),
table_id,
};
assert!(catalog
.rename_table(rename_table_req, table_id)
.await
.unwrap());
assert!(catalog.rename_table(rename_table_req).await.unwrap());
assert!(!schema.table_exist(table_name).unwrap());
assert!(schema.table_exist(new_table_name).unwrap());

Expand Down
2 changes: 1 addition & 1 deletion src/catalog/src/remote/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ impl CatalogManager for RemoteCatalogManager {
Ok(true)
}

async fn rename_table(&self, _request: RenameTableRequest, _table_id: TableId) -> Result<bool> {
async fn rename_table(&self, _request: RenameTableRequest) -> Result<bool> {
UnimplementedSnafu {
operation: "rename table",
}
Expand Down
3 changes: 2 additions & 1 deletion src/catalog/tests/local_catalog_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,10 @@ mod tests {
schema: DEFAULT_SCHEMA_NAME.to_string(),
table_name: table_name.to_string(),
new_table_name: new_table_name.to_string(),
table_id,
};
assert!(catalog_manager
.rename_table(rename_table_req, table_id)
.rename_table(rename_table_req)
.await
.unwrap());

Expand Down
3 changes: 2 additions & 1 deletion src/datanode/src/sql/alter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,10 @@ impl SqlHandler {
schema: table_info.schema_name.clone(),
table_name,
new_table_name: table_info.name.clone(),
table_id: table_info.ident.table_id,
};
self.catalog_manager
.rename_table(rename_table_req, table_info.ident.table_id)
.rename_table(rename_table_req)
.await
.context(error::RenameTableSnafu)?;
}
Expand Down
7 changes: 1 addition & 6 deletions src/frontend/src/catalog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ use catalog::{
use futures::StreamExt;
use meta_client::rpc::TableName;
use snafu::prelude::*;
use table::metadata::TableId;
use table::TableRef;

use crate::datanode::DatanodeClients;
Expand Down Expand Up @@ -98,11 +97,7 @@ impl CatalogManager for FrontendCatalogManager {
unimplemented!()
}

async fn rename_table(
&self,
_request: RenameTableRequest,
_table_id: TableId,
) -> catalog_err::Result<bool> {
async fn rename_table(&self, _request: RenameTableRequest) -> catalog_err::Result<bool> {
unimplemented!()
}

Expand Down

0 comments on commit b5487c9

Please sign in to comment.