From 15dd6f858be0aedd302d0260107ca34add2eda24 Mon Sep 17 00:00:00 2001 From: dr666m1 <26474260+kitta65@users.noreply.github.com> Date: Sat, 2 Mar 2024 10:11:05 +0900 Subject: [PATCH] fix #315 --- src/parser.rs | 22 ++++++++++++++++++---- src/parser/tests/tests_ddl.rs | 25 +++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 4 deletions(-) diff --git a/src/parser.rs b/src/parser.rs index 84026bc..87186e3 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -2236,10 +2236,24 @@ impl Parser { } if self.get_token(1)?.is("AS") { self.next_token()?; // -> AS - let mut as_ = self.construct_node(NodeType::KeywordWithStatement)?; - self.next_token()?; // -> SELECT - as_.push_node("stmt", self.parse_select_statement(false, true)?); - create.push_node("as", as_) + if self.get_token(1)?.is("REPLICA") { + let mut as_ = self.construct_node(NodeType::KeywordSequence)?; + self.next_token()?; // -> REPLICA + let mut replica = self.construct_node(NodeType::KeywordSequence)?; + self.next_token()?; // -> OF + let mut of = self.construct_node(NodeType::KeywordWithExpr)?; + self.next_token()?; // -> ident + + of.push_node("expr", self.parse_identifier()?); + replica.push_node("next_keyword", of); + as_.push_node("next_keyword", replica); + create.push_node("as", as_) + } else { + let mut as_ = self.construct_node(NodeType::KeywordWithStatement)?; + self.next_token()?; // -> SELECT + as_.push_node("stmt", self.parse_select_statement(false, true)?); + create.push_node("as", as_) + } } if self.get_token(1)?.is(";") && semicolon { self.next_token()?; // -> ; diff --git a/src/parser/tests/tests_ddl.rs b/src/parser/tests/tests_ddl.rs index 22300b7..e941a83 100644 --- a/src/parser/tests/tests_ddl.rs +++ b/src/parser/tests/tests_ddl.rs @@ -1207,6 +1207,31 @@ ident: self: viewname (Identifier) what: self: VIEW (Keyword) +", + 0, + )), + // REPLICA + Box::new(SuccessTestCase::new( + "\ +CREATE MATERIALIZED VIEW ident1 +AS REPLICA OF ident2 +", + "\ +self: CREATE (CreateViewStatement) +as: + self: AS (KeywordSequence) + next_keyword: + self: REPLICA (KeywordSequence) + next_keyword: + self: OF (KeywordWithExpr) + expr: + self: ident2 (Identifier) +ident: + self: ident1 (Identifier) +materialized: + self: MATERIALIZED (Keyword) +what: + self: VIEW (Keyword) ", 0, )),