-
Notifications
You must be signed in to change notification settings - Fork 753
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(query): Procedure support drop if exists and create or replace #16500
Conversation
Also need the syntax |
Yes create or replace already in plan. #16501 |
5c099b9
to
f4b3ec6
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 5 of 7 files at r1, 2 of 2 files at r2, 1 of 1 files at r3, all commit messages.
Reviewable status: all files reviewed, 3 unresolved discussions (waiting on @sundy-li and @TCeason)
src/query/management/src/procedure/procedure_mgr.rs
line 94 at r2 (raw file):
} else { Err(AppError::from(name_ident.unknown_error(func_name!())).into()) }
IMHO, CreateOrReplace
does not expect an unknown error. If there is no such record, it should just create one.
The above create_id_value()
should be already enough. I do not get why this update_id_value
is requried.
Code quote:
let res = self
.kv_api
.update_id_value(name_ident, meta.clone())
.await?;
if let Some((id, _meta)) = res {
Ok(CreateProcedureReply { procedure_id: *id })
} else {
Err(AppError::from(name_ident.unknown_error(func_name!())).into())
}
src/query/management/src/procedure/procedure_mgr.rs
line 120 at r2 (raw file):
return Err(AppError::from(name_ident.unknown_error("drop procedure")).into()); } }
The if_exists
flag only affects the response to the client; it does not influence operations on the meta-service.
This if_exists
check should be moved up the call stack to the point where an Error response is actually required, either in the immediate caller or a higher-level caller.
Adn DropProcedureReq
does not need if_exists
at all.
Code quote:
if dropped.is_none() {
if req.if_exists {
// Ok
} else {
return Err(AppError::from(name_ident.unknown_error("drop procedure")).into());
}
}
Ok, we can refactor these two function. e.g. add update_procedure API. If is replace , call update. |
19834b5
to
7a9f382
Compare
7a9f382
to
1fb3b9a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 4 of 6 files at r6, all commit messages.
Reviewable status: 10 of 12 files reviewed, 4 unresolved discussions (waiting on @sundy-li and @TCeason)
src/query/service/src/interpreters/interpreter_procedure_create.rs
line 62 at r6 (raw file):
let _ = UserApiProvider::instance() .add_procedure(&tenant, create_procedure_req, overriding) .await?;
The returned result should be consumed: with CreateOption::CreateIfNotExists
, no error should be returned.
Code quote:
let overriding = self.plan.create_option.is_overriding();
let _ = UserApiProvider::instance()
.add_procedure(&tenant, create_procedure_req, overriding)
.await?;
1fb3b9a
to
d06e9c2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The logic looks good to me. And I'd suggest avoiding using ErrorCode if possible.
Reviewed 11 of 11 files at r8, all commit messages.
Reviewable status: all files reviewed, 5 unresolved discussions (waiting on @sundy-li and @TCeason)
src/query/service/src/interpreters/interpreter_procedure_create.rs
line 71 at r8 (raw file):
return Err(e); } }
I'd suggest avoid using ErrorCode
if possible. ErrorCode
includes all kind of errors that makes it difficult to distinguish(by enumerate every of them) RPC error or logic error like PROCEDURE_ALREADY_EXISTS
.
If add_procedure()
returns KVAppError or Result<Result<..>>
, the error handling like this would be easier.
Such as with Result<Result<T, LogicError>, MetaError>
, a simple ?
will filter out meta service errors that are not interested.
Code quote:
if let Err(e) = UserApiProvider::instance()
.add_procedure(&tenant, create_procedure_req, overriding)
.await
{
if !(self.plan.create_option == CreateOption::CreateIfNotExists
&& e.code() == ErrorCode::PROCEDURE_ALREADY_EXISTS)
{
return Err(e);
}
}
Like this: 7213781? Maybe we can refactor all procedure API in next pr that support alter procedure name? |
Yes, It would be alright with another PR:) In the code snippet above, the outer |
I think we can merge this pr now. cc @BohuTANG |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 2 of 2 files at r9, all commit messages.
Reviewable status: all files reviewed, 4 unresolved discussions (waiting on @sundy-li and @TCeason)
7213781
to
392f633
Compare
I hereby agree to the terms of the CLA available at: https://docs.databend.com/dev/policies/cla/
Summary
Part of #16501
Tests
Type of change
This change is