Skip to content
Snippets Groups Projects
Commit b444975a authored by Arseniy Volynets's avatar Arseniy Volynets
Browse files

feat: support rename procedure frontend

parent 528448ad
No related branches found
No related tags found
2 merge requests!396Draft: String storage,!386Rename procedure with sql API
Pipeline #35150 passed
......@@ -189,6 +189,44 @@ fn parse_call_proc<M: Metadata>(
Ok(call_proc)
}
fn parse_rename_proc(ast: &AbstractSyntaxTree, node: &ParseNode) -> Result<Ddl, SbroadError> {
if node.rule != Rule::RenameProc {
return Err(SbroadError::Invalid(
Entity::Type,
Some("rename procedure".into()),
));
}
let mut old_name: String = String::new();
let mut new_name: String = String::new();
let mut params: Option<Vec<ParamDef>> = None;
let mut timeout = get_default_timeout();
for child_id in &node.children {
let child_node = ast.nodes.get_node(*child_id)?;
match child_node.rule {
Rule::NewProc => {
new_name = normalize_name_for_space_api(parse_string_value_node(ast, *child_id)?);
}
Rule::OldProc => {
old_name = normalize_name_for_space_api(parse_string_value_node(ast, *child_id)?);
}
Rule::ProcParams => {
params = Some(parse_proc_params(ast, child_node)?);
}
Rule::Timeout => {
timeout = get_timeout(ast, *child_id)?;
}
_ => panic!("Unexpected node: {child_node:?}"),
}
}
Ok(Ddl::RenameRoutine {
old_name,
new_name,
params,
timeout,
})
}
fn parse_create_proc(ast: &AbstractSyntaxTree, node: &ParseNode) -> Result<Ddl, SbroadError> {
let proc_name_id = node.children.first().expect("Expected to get Proc name");
let proc_name = parse_identifier(ast, *proc_name_id)?;
......@@ -2455,6 +2493,11 @@ impl AbstractSyntaxTree {
let plan_id = plan.nodes.push(Node::Ddl(drop_proc));
map.add(id, plan_id);
}
Rule::RenameProc => {
let rename_proc = parse_rename_proc(self, node)?;
let plan_id = plan.nodes.push(Node::Ddl(rename_proc));
map.add(id, plan_id);
}
Rule::AlterUser => {
let user_name_node_id = node
.children
......
......@@ -50,7 +50,7 @@ ACL = _{ DropRole | DropUser | CreateRole | CreateUser | AlterUser | GrantPrivil
PrivilegeUsage = { ^"usage" }
PrivilegeWrite = { ^"write" }
DDL = _{ CreateTable | DropTable | CreateProc | DropProc }
DDL = _{ CreateTable | DropTable | CreateProc | DropProc | RenameProc }
CreateTable = {
^"create" ~ ^"table" ~ NewTable ~
"(" ~ Columns ~ "," ~ PrimaryKey ~ ")" ~
......@@ -86,6 +86,10 @@ DDL = _{ CreateTable | DropTable | CreateProc | DropProc }
DropProc = { ^"drop" ~ ^"procedure" ~ ProcWithOptionalParams ~ TimeoutOption? }
ProcWithOptionalParams = { Identifier ~ ProcParams? }
RenameProc = { ^"alter" ~ ^"procedure" ~ OldProc ~ ProcParams? ~ ^"rename" ~ ^"to" ~ NewProc ~ TimeoutOption? }
OldProc = @{ Identifier }
NewProc = @{ Identifier }
Block = { CallProc ~ DqlOption? }
CallProc = { ^"call" ~ Identifier ~ "(" ~ ProcValues ~ ")" }
ProcValues = { ProcValue? ~ ("," ~ ProcValue)* }
......
......@@ -62,6 +62,12 @@ pub enum Ddl {
params: Vec<ParamDef>,
timeout: Decimal,
},
RenameRoutine {
old_name: String,
new_name: String,
params: Option<Vec<ParamDef>>,
timeout: Decimal,
},
}
impl Ddl {
......@@ -74,7 +80,8 @@ impl Ddl {
Ddl::CreateTable { ref timeout, .. }
| Ddl::DropTable { ref timeout, .. }
| Ddl::CreateProc { ref timeout, .. }
| Ddl::DropProc { ref timeout, .. } => timeout,
| Ddl::DropProc { ref timeout, .. }
| Ddl::RenameRoutine { ref timeout, .. } => timeout,
}
.to_string()
.parse()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment