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

Feature/fix195 #196

Merged
merged 5 commits into from
May 3, 2023
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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bq2cst"
version = "0.4.22"
version = "0.4.23"
authors = ["dr666m1 <skndr666m1@gmail.com>"]
edition = "2018"
license = "MIT"
Expand Down
2 changes: 2 additions & 0 deletions src/cst.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ pub enum NodeType {
ForSystemTimeAsOfClause, // FOR SYSTEM_TIME AS OF ts
ForStatement,
GrantStatement,
GroupedIdentWithOptions, // (col OPTIONS())
GroupedExpr, // (1)
GroupedExprs, // (1, 2, 3)
GroupedStatement, // (SELECT 1)
Expand All @@ -80,6 +81,7 @@ pub enum NodeType {
KeywordWithStatement, // THEN INSERT ROW
KeywordWithStatements, // THEN SELECT 1;
Identifier,
IdentWithOptions,
IfStatement,
InsertStatement,
IntervalLiteral,
Expand Down
37 changes: 32 additions & 5 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2115,7 +2115,28 @@ impl Parser {
create.push_node("ident", self.parse_identifier()?);
if self.get_token(1)?.is("(") && !materialized {
self.next_token()?; // -> (
create.push_node("column_name_list", self.parse_grouped_exprs(false)?);
let mut column_name_list = self.construct_node(NodeType::GroupedIdentWithOptions)?;
let mut idents = vec![];
loop {
self.next_token()?; // -> ident
if self.get_token(0)?.is(")") {
column_name_list.push_node("rparen", self.construct_node(NodeType::Symbol)?);
break;
}
let mut ident = self.parse_identifier()?;
ident.node_type = NodeType::IdentWithOptions;
if self.get_token(1)?.is("OPTIONS") {
self.next_token()?; // -> OPTIONS
ident.push_node("OPTIONS", self.parse_keyword_with_grouped_exprs(false)?);
}
if self.get_token(1)?.is(",") {
self.next_token()?; // -> ,
ident.push_node("comma", self.construct_node(NodeType::Symbol)?);
}
idents.push(ident);
}
column_name_list.push_node_vec("idents", idents);
create.push_node("column_name_list", column_name_list)
}
if self.get_token(1)?.is("PARTITION") && materialized {
self.next_token()?; // -> PARTITION
Expand Down Expand Up @@ -2611,10 +2632,16 @@ impl Parser {
}
self.next_token()?; // -> ident
alter.push_node("ident", self.parse_identifier()?);
self.next_token()?; // -> SET
alter.push_node("set", self.construct_node(NodeType::Keyword)?);
self.next_token()?; // -> OPTIONS
alter.push_node("options", self.parse_keyword_with_grouped_exprs(false)?);
if self.get_token(1)?.is("ALTER") {
self.next_token()?;
let alter_column = self.parse_alter_column_statement(false)?;
alter.push_node("alter_column_stmt", alter_column);
} else {
self.next_token()?; // -> SET
alter.push_node("set", self.construct_node(NodeType::Keyword)?);
self.next_token()?; // -> OPTIONS
alter.push_node("options", self.parse_keyword_with_grouped_exprs(false)?);
}
if self.get_token(1)?.is(";") && semicolon {
self.next_token()?; // -> ;
alter.push_node("semicolon", self.construct_node(NodeType::Symbol)?);
Expand Down
83 changes: 79 additions & 4 deletions src/parser/tests/tests_ddl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1097,12 +1097,12 @@ as:
alias:
self: TWO (Identifier)
column_name_list:
self: ( (GroupedExprs)
exprs:
- self: uno (Identifier)
self: ( (GroupedIdentWithOptions)
idents:
- self: uno (IdentWithOptions)
comma:
self: , (Symbol)
- self: dos (Identifier)
- self: dos (IdentWithOptions)
rparen:
self: ) (Symbol)
ident:
Expand All @@ -1113,6 +1113,46 @@ ident:
self: view_name (Identifier)
what:
self: VIEW (Keyword)
",
0,
)),
Box::new(SuccessTestCase::new(
"\
CREATE VIEW viewname (uno OPTIONS(description='single'))
AS SELECT 1 ONE
",
"\
self: CREATE (CreateViewStatement)
as:
self: AS (KeywordWithStatement)
stmt:
self: SELECT (SelectStatement)
exprs:
- self: 1 (NumericLiteral)
alias:
self: ONE (Identifier)
column_name_list:
self: ( (GroupedIdentWithOptions)
idents:
- self: uno (IdentWithOptions)
OPTIONS:
self: OPTIONS (KeywordWithGroupedXXX)
group:
self: ( (GroupedExprs)
exprs:
- self: = (BinaryOperator)
left:
self: description (Identifier)
right:
self: 'single' (StringLiteral)
rparen:
self: ) (Symbol)
rparen:
self: ) (Symbol)
ident:
self: viewname (Identifier)
what:
self: VIEW (Keyword)
",
0,
)),
Expand Down Expand Up @@ -2649,6 +2689,41 @@ set:
self: SET (Keyword)
what:
self: VIEW (Keyword)
",
0,
)),
Box::new(SuccessTestCase::new(
"\
ALTER VIEW viewname
alter column colname set options(dummy='dummy');",
"\
self: ALTER (AlterViewStatement)
alter_column_stmt:
self: alter (AlterColumnStatement)
ident:
self: colname (Identifier)
options:
self: options (KeywordWithGroupedXXX)
group:
self: ( (GroupedExprs)
exprs:
- self: = (BinaryOperator)
left:
self: dummy (Identifier)
right:
self: 'dummy' (StringLiteral)
rparen:
self: ) (Symbol)
set:
self: set (Keyword)
what:
self: column (Keyword)
ident:
self: viewname (Identifier)
semicolon:
self: ; (Symbol)
what:
self: VIEW (Keyword)
",
0,
)),
Expand Down
29 changes: 27 additions & 2 deletions src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,13 @@ export type UnknownNode =
| GrantStatement
| GroupedExpr
| GroupedExprs
| GroupedIdentWithOptions
| GroupedStatement
| GroupedTypeDeclarationOrConstraints
| GroupedType
| Identifier
| IfStatement
| IdentWithOptions
| InOperator
| InsertStatement
| IntervalLiteral
Expand Down Expand Up @@ -189,6 +191,17 @@ export type IdentifierGeneral = FromItemExpr & {
};
};

export type IdentWithOptions = Expr & {
node_type: "IdentWithOptions";
children: {
as: undefined;
alias: undefined;
order: undefined;
null_order: undefined;
options?: NodeChild;
};
};

export type XXXStatement = BaseNode & {
token: Token;
children: {
Expand Down Expand Up @@ -328,8 +341,11 @@ export type AlterViewStatement = XXXStatement & {
what: NodeChild;
if_exists?: NodeVecChild;
ident: NodeChild;
set: NodeChild;
options: NodeChild;
// SET
set?: NodeChild;
options?: NodeChild;
// ALTER COLUMN statement
alter_column_stmt?: NodeChild;
};
};

Expand Down Expand Up @@ -803,6 +819,15 @@ export type GroupedExprs = BaseNode & {
};
};

export type GroupedIdentWithOptions = BaseNode & {
token: Token;
node_type: "GroupedIdentWithOptions";
children: {
idents: NodeVecChild;
rparen: NodeChild;
};
};

export type GroupedStatement = FromItemExpr &
XXXStatement & {
node_type: "GroupedStatement";
Expand Down