Skip to content

Commit

Permalink
refactor(ast): rename CreateOption::CreateIfNotExists(false) -> Creat…
Browse files Browse the repository at this point in the history
…eOption::None (databendlabs#14795)

* refactor(ast): rename CreateOption::CreateIfNotExists(false) -> CreateOption::None

* fix

* fix

* fix

* fix

* fix
  • Loading branch information
andylokandy authored Feb 29, 2024
1 parent a47bce9 commit b509190
Show file tree
Hide file tree
Showing 63 changed files with 2,215 additions and 2,391 deletions.
6 changes: 3 additions & 3 deletions src/binaries/metabench/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ async fn benchmark_table(client: &Arc<ClientHandle>, prefix: u64, client_num: u6

let res = client
.create_database(CreateDatabaseReq {
create_option: CreateOption::CreateIfNotExists(false),
create_option: CreateOption::None,
name_ident: DatabaseNameIdent {
tenant: tenant(),
db_name: db_name(),
Expand All @@ -206,7 +206,7 @@ async fn benchmark_table(client: &Arc<ClientHandle>, prefix: u64, client_num: u6

let res = client
.create_table(CreateTableReq {
create_option: CreateOption::CreateIfNotExists(true),
create_option: CreateOption::CreateIfNotExists,
name_ident: tb_name_ident(),
table_meta: Default::default(),
})
Expand Down Expand Up @@ -246,7 +246,7 @@ async fn benchmark_table(client: &Arc<ClientHandle>, prefix: u64, client_num: u6

let res = client
.create_table(CreateTableReq {
create_option: CreateOption::CreateIfNotExists(true),
create_option: CreateOption::CreateIfNotExists,
name_ident: tb_name_ident(),
table_meta: Default::default(),
})
Expand Down
38 changes: 19 additions & 19 deletions src/meta/api/src/data_mask_api_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,29 +79,29 @@ impl<KV: kvapi::KVApi<Error = MetaError>> DatamaskApi for KV {
let mut if_then = vec![];

if seq > 0 {
if let CreateOption::CreateIfNotExists(if_not_exists) = req.create_option {
return if if_not_exists {
Ok(CreateDatamaskReply { id })
} else {
Err(KVAppError::AppError(AppError::DatamaskAlreadyExists(
match req.create_option {
CreateOption::None => {
return Err(KVAppError::AppError(AppError::DatamaskAlreadyExists(
DatamaskAlreadyExists::new(
&name_key.name,
format!("create data mask: {}", req.name),
),
)))
};
} else {
construct_drop_mask_policy_operations(
self,
name_key,
false,
false,
func_name!(),
&mut condition,
&mut if_then,
)
.await?;
}
)));
}
CreateOption::CreateIfNotExists => return Ok(CreateDatamaskReply { id }),
CreateOption::CreateOrReplace => {
construct_drop_mask_policy_operations(
self,
name_key,
false,
false,
func_name!(),
&mut condition,
&mut if_then,
)
.await?;
}
};
};

// Create data mask by inserting these record:
Expand Down
136 changes: 70 additions & 66 deletions src/meta/api/src/schema_api_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,20 +279,19 @@ impl<KV: kvapi::KVApi<Error = MetaError> + ?Sized> SchemaApi for KV {

let spec_vec = if db_id_seq > 0 {
match req.create_option {
CreateOption::CreateIfNotExists(if_not_exists) => {
return if if_not_exists {
Ok(CreateDatabaseReply {
db_id,
spec_vec: None,
})
} else {
Err(KVAppError::AppError(AppError::DatabaseAlreadyExists(
DatabaseAlreadyExists::new(
&name_key.db_name,
format!("create db: tenant: {}", name_key.tenant),
),
)))
};
CreateOption::None => {
return Err(KVAppError::AppError(AppError::DatabaseAlreadyExists(
DatabaseAlreadyExists::new(
&name_key.db_name,
format!("create db: tenant: {}", name_key.tenant),
),
)));
}
CreateOption::CreateIfNotExists => {
return Ok(CreateDatabaseReply {
db_id,
spec_vec: None,
});
}
CreateOption::CreateOrReplace => {
drop_database_meta(
Expand Down Expand Up @@ -926,27 +925,29 @@ impl<KV: kvapi::KVApi<Error = MetaError> + ?Sized> SchemaApi for KV {
let mut if_then = vec![];

let (_, index_id_seq) = if index_id_seq > 0 {
if let CreateOption::CreateIfNotExists(if_not_exists) = req.create_option {
return if if_not_exists {
Ok(CreateIndexReply { index_id })
} else {
Err(KVAppError::AppError(AppError::IndexAlreadyExists(
match req.create_option {
CreateOption::None => {
return Err(KVAppError::AppError(AppError::IndexAlreadyExists(
IndexAlreadyExists::new(
&tenant_index.index_name,
format!("create index with tenant: {}", tenant_index.tenant),
),
)))
};
} else {
construct_drop_index_txn_operations(
self,
tenant_index,
false,
false,
&mut condition,
&mut if_then,
)
.await?
)));
}
CreateOption::CreateIfNotExists => {
return Ok(CreateIndexReply { index_id });
}
CreateOption::CreateOrReplace => {
construct_drop_index_txn_operations(
self,
tenant_index,
false,
false,
&mut condition,
&mut if_then,
)
.await?
}
}
} else {
(0, 0)
Expand Down Expand Up @@ -1262,10 +1263,8 @@ impl<KV: kvapi::KVApi<Error = MetaError> + ?Sized> SchemaApi for KV {

let mut if_then = vec![];
let seq = if old_virtual_column_opt.is_some() {
if let CreateOption::CreateIfNotExists(if_not_exists) = req.create_option {
if if_not_exists {
return Ok(CreateVirtualColumnReply {});
} else {
match req.create_option {
CreateOption::None => {
return Err(KVAppError::AppError(AppError::VirtualColumnAlreadyExists(
VirtualColumnAlreadyExists::new(
req.name_ident.table_id,
Expand All @@ -1276,16 +1275,20 @@ impl<KV: kvapi::KVApi<Error = MetaError> + ?Sized> SchemaApi for KV {
),
)));
}
} else {
construct_drop_virtual_column_txn_operations(
self,
&req.name_ident,
false,
false,
ctx,
&mut if_then,
)
.await?
CreateOption::CreateIfNotExists => {
return Ok(CreateVirtualColumnReply {});
}
CreateOption::CreateOrReplace => {
construct_drop_virtual_column_txn_operations(
self,
&req.name_ident,
false,
false,
ctx,
&mut if_then,
)
.await?
}
}
} else {
0
Expand Down Expand Up @@ -1623,32 +1626,33 @@ impl<KV: kvapi::KVApi<Error = MetaError> + ?Sized> SchemaApi for KV {

if let Some(id) = v {
// TODO: move if_not_exists to upper caller. It is not duty of SchemaApi.
if let CreateOption::CreateIfNotExists(if_not_exists) = req.create_option {
if if_not_exists {
match req.create_option {
CreateOption::None => {
let app_err = make_exists_err(&req);
return Err(KVAppError::AppError(app_err));
}
CreateOption::CreateIfNotExists => {
return Ok(CreateTableReply {
table_id: *id.data,
new_table: false,
spec_vec: None,
});
} else {
let app_err = make_exists_err(&req);
return Err(KVAppError::AppError(app_err));
};
} else {
// create or replace
construct_drop_table_txn_operations(
self,
req.name_ident.table_name.clone(),
req.name_ident.tenant.clone(),
*id.data,
db_id.data,
false,
false,
&mut tb_count,
&mut condition,
&mut if_then,
)
.await?
}
CreateOption::CreateOrReplace => {
construct_drop_table_txn_operations(
self,
req.name_ident.table_name.clone(),
req.name_ident.tenant.clone(),
*id.data,
db_id.data,
false,
false,
&mut tb_count,
&mut condition,
&mut if_then,
)
.await?
}
}
} else {
(None, 0)
Expand Down
Loading

0 comments on commit b509190

Please sign in to comment.