Skip to content
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

support undrop statement #328

Merged
merged 1 commit into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/cst.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ pub enum NodeType {
TypeDeclaration, // x INT64
UnaryOperator, // - | + | TIMESTAMP | ...
Unknown,
UndropStatement,
UnpivotOperator,
UnpivotConfig, // ((c1, c2) FOR v IN ((v1, v2) 1, (v3, v4) 3))
UpdateStatement,
Expand Down
17 changes: 17 additions & 0 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1011,6 +1011,7 @@ impl Parser {
self.parse_drop_statement_general(semicolon)?
}
}
"UNDROP" => self.parse_undrop_statement(semicolon)?,
// DCL
"GRANT" => self.parse_grant_statement(semicolon)?,
"REVOKE" => self.parse_revoke_statement(semicolon)?,
Expand Down Expand Up @@ -2984,6 +2985,22 @@ impl Parser {
}
Ok(drop)
}
fn parse_undrop_statement(&mut self, semicolon: bool) -> BQ2CSTResult<Node> {
let mut undrop = self.construct_node(NodeType::UndropStatement)?;
self.next_token()?; // -> SCHEMA
undrop.push_node("what", self.construct_node(NodeType::Keyword)?);
if self.get_token(1)?.is("IF") {
self.next_token()?; // -> IF
undrop.push_node_vec("if_not_exists", self.parse_n_keywords(3)?);
}
self.next_token()?; // -> ident
undrop.push_node("ident", self.parse_identifier()?);
if self.get_token(1)?.is(";") && semicolon {
self.next_token()?; // -> ;
undrop.push_node("semicolon", self.construct_node(NodeType::Symbol)?);
}
Ok(undrop)
}
// ----- DCL -----
fn parse_grant_statement(&mut self, semicolon: bool) -> BQ2CSTResult<Node> {
let mut grant = self.construct_node(NodeType::GrantStatement)?;
Expand Down
37 changes: 37 additions & 0 deletions src/parser/tests/tests_ddl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3196,6 +3196,43 @@ if_exists:
- self: EXISTS (Keyword)
what:
self: ASSIGNMENT (Keyword)
",
0,
)),
// ----- UNDROP statement -----
Box::new(SuccessTestCase::new(
"\
UNDROP SCHEMA datasetname;
",
"\
self: UNDROP (UndropStatement)
ident:
self: datasetname (Identifier)
semicolon:
self: ; (Symbol)
what:
self: SCHEMA (Keyword)
",
0,
)),
Box::new(SuccessTestCase::new(
"\
UNDROP SCHEMA IF NOT EXISTS projectname.datasetname
",
"\
self: UNDROP (UndropStatement)
ident:
self: . (DotOperator)
left:
self: projectname (Identifier)
right:
self: datasetname (Identifier)
if_not_exists:
- self: IF (Keyword)
- self: NOT (Keyword)
- self: EXISTS (Keyword)
what:
self: SCHEMA (Keyword)
",
0,
)),
Expand Down
10 changes: 10 additions & 0 deletions src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ export type UnknownNode =
| Type
| TypeDeclaration
| UnaryOperator
| UndropStatement
| UnpivotConfig
| UnpivotOperator
| UpdateStatement
Expand Down Expand Up @@ -1350,6 +1351,15 @@ export type UnaryOperator = Expr & {
};
};

export type UndropStatement = XXXStatement & {
node_type: "UndropStatement";
children: {
what: NodeChild;
if_not_exists?: NodeVecChild;
ident: NodeChild;
};
};

export type UnpivotConfig = BaseNode & {
token: Token;
node_type: "UnpivotConfig";
Expand Down