From 68b83d1026902ffeb37da00b728e43a3aac115f7 Mon Sep 17 00:00:00 2001 From: dr666m1 Date: Wed, 3 May 2023 09:26:25 +0900 Subject: [PATCH 1/5] add todo comment --- src/parser.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/parser.rs b/src/parser.rs index ece5736..fcc2bf2 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -2117,6 +2117,7 @@ impl Parser { self.next_token()?; // -> ( create.push_node("column_name_list", self.parse_grouped_exprs(false)?); } + // TODO view column name list if self.get_token(1)?.is("PARTITION") && materialized { self.next_token()?; // -> PARTITION create.push_node("partitionby", self.parse_xxxby_exprs()?); @@ -2611,6 +2612,7 @@ impl Parser { } self.next_token()?; // -> ident alter.push_node("ident", self.parse_identifier()?); + // TODO alter column self.next_token()?; // -> SET alter.push_node("set", self.construct_node(NodeType::Keyword)?); self.next_token()?; // -> OPTIONS From 9e16195db619fe24c5392c858a246d18870d2c34 Mon Sep 17 00:00:00 2001 From: dr666m1 Date: Wed, 3 May 2023 10:41:41 +0900 Subject: [PATCH 2/5] create view column description --- src/cst.rs | 2 ++ src/parser.rs | 24 ++++++++++++++++-- src/parser/tests/tests_ddl.rs | 48 ++++++++++++++++++++++++++++++++--- src/types.rs | 21 +++++++++++++++ 4 files changed, 89 insertions(+), 6 deletions(-) diff --git a/src/cst.rs b/src/cst.rs index 2dbbcb3..510fb79 100644 --- a/src/cst.rs +++ b/src/cst.rs @@ -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) @@ -80,6 +81,7 @@ pub enum NodeType { KeywordWithStatement, // THEN INSERT ROW KeywordWithStatements, // THEN SELECT 1; Identifier, + IdentWithOptions, IfStatement, InsertStatement, IntervalLiteral, diff --git a/src/parser.rs b/src/parser.rs index fcc2bf2..e57918d 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -2115,9 +2115,29 @@ 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) } - // TODO view column name list if self.get_token(1)?.is("PARTITION") && materialized { self.next_token()?; // -> PARTITION create.push_node("partitionby", self.parse_xxxby_exprs()?); diff --git a/src/parser/tests/tests_ddl.rs b/src/parser/tests/tests_ddl.rs index 5143ec6..641e0ef 100644 --- a/src/parser/tests/tests_ddl.rs +++ b/src/parser/tests/tests_ddl.rs @@ -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: @@ -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, )), diff --git a/src/types.rs b/src/types.rs index 010397b..5ccd861 100644 --- a/src/types.rs +++ b/src/types.rs @@ -60,11 +60,13 @@ export type UnknownNode = | GrantStatement | GroupedExpr | GroupedExprs + | GroupedIdentWithOptions | GroupedStatement | GroupedTypeDeclarationOrConstraints | GroupedType | Identifier | IfStatement + | IdentWithOptions | InOperator | InsertStatement | IntervalLiteral @@ -189,6 +191,16 @@ export type IdentifierGeneral = FromItemExpr & { }; }; +export type IdentWithOptions = Expr & { + children: { + as: undefined; + alias: undefined; + order: undefined; + null_order: undefined; + options?: NodeChild; + }; +}; + export type XXXStatement = BaseNode & { token: Token; children: { @@ -803,6 +815,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"; From 99e2cf83e674e7c407486aa65819936ce1023afa Mon Sep 17 00:00:00 2001 From: dr666m1 Date: Wed, 3 May 2023 11:00:23 +0900 Subject: [PATCH 3/5] alter column within alter view --- src/parser.rs | 15 ++++++++++----- src/parser/tests/tests_ddl.rs | 35 +++++++++++++++++++++++++++++++++++ src/types.rs | 7 +++++-- 3 files changed, 50 insertions(+), 7 deletions(-) diff --git a/src/parser.rs b/src/parser.rs index e57918d..9b2d067 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -2632,11 +2632,16 @@ impl Parser { } self.next_token()?; // -> ident alter.push_node("ident", self.parse_identifier()?); - // TODO alter column - 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)?); diff --git a/src/parser/tests/tests_ddl.rs b/src/parser/tests/tests_ddl.rs index 641e0ef..fba3fec 100644 --- a/src/parser/tests/tests_ddl.rs +++ b/src/parser/tests/tests_ddl.rs @@ -2689,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, )), diff --git a/src/types.rs b/src/types.rs index 5ccd861..665b082 100644 --- a/src/types.rs +++ b/src/types.rs @@ -340,8 +340,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; }; }; From 6fc7add5868ad8089c7988788b763ffea5bf27c6 Mon Sep 17 00:00:00 2001 From: dr666m1 Date: Wed, 3 May 2023 15:57:00 +0900 Subject: [PATCH 4/5] fix type --- src/types.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/types.rs b/src/types.rs index 665b082..1f8efc4 100644 --- a/src/types.rs +++ b/src/types.rs @@ -192,6 +192,7 @@ export type IdentifierGeneral = FromItemExpr & { }; export type IdentWithOptions = Expr & { + node_type: "IdentWithOptions"; children: { as: undefined; alias: undefined; From 4e4bd77bd098c3f6fa8477f1e7bc906e3a96a3b7 Mon Sep 17 00:00:00 2001 From: dr666m1 Date: Wed, 3 May 2023 16:24:07 +0900 Subject: [PATCH 5/5] 0.4.23 --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 8fc5936..03c9a3b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "bq2cst" -version = "0.4.22" +version = "0.4.23" authors = ["dr666m1 "] edition = "2018" license = "MIT"