From 55de8a4a94a6429450b3942dc24ad7a7397220da Mon Sep 17 00:00:00 2001 From: Ilya Biryukov Date: Fri, 8 Oct 2021 13:58:02 +0300 Subject: [PATCH] Syntax for PARTITIONED INDEX (CubeStore extension) --- src/ast/mod.rs | 19 +++++++++++++++++++ src/parser.rs | 15 +++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/src/ast/mod.rs b/src/ast/mod.rs index 78f6a353c..e9f346feb 100644 --- a/src/ast/mod.rs +++ b/src/ast/mod.rs @@ -651,6 +651,12 @@ pub enum Statement { unique: bool, if_not_exists: bool, }, + // CubeStore extension. + CreatePartitionedIndex { + name: ObjectName, + columns: Vec, + if_not_exists: bool, + }, /// ALTER TABLE AlterTable { /// Table name @@ -1276,6 +1282,19 @@ impl fmt::Display for Statement { } write!(f, "AS {}", statement) } + Statement::CreatePartitionedIndex { + name, + columns, + if_not_exists, + } => { + write!( + f, + "CREATE PARTITIONED INDEX{} {}({})", + if *if_not_exists { " IF NOT EXISTS" } else { "" }, + name, + display_comma_separated(&columns) + ) + } } } } diff --git a/src/parser.rs b/src/parser.rs index 96c2f9286..7aa0476f2 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -1267,6 +1267,8 @@ impl<'a> Parser<'a> { self.parse_create_virtual_table() } else if self.parse_keyword(Keyword::SCHEMA) { self.parse_create_schema() + } else if self.parse_keywords(&[Keyword::PARTITIONED, Keyword::INDEX]) { + self.parse_create_partitioned_index() } else { self.expected("an object type after CREATE", self.peek_token()) } @@ -1433,6 +1435,19 @@ impl<'a> Parser<'a> { }) } + pub fn parse_create_partitioned_index(&mut self) -> Result { + let if_not_exists = self.parse_keywords(&[Keyword::IF, Keyword::NOT, Keyword::EXISTS]); + let name = self.parse_object_name()?; + self.expect_token(&Token::LParen)?; + let columns = self.parse_comma_separated(Parser::parse_column_def)?; + self.expect_token(&Token::RParen)?; + Ok(Statement::CreatePartitionedIndex { + name, + columns, + if_not_exists, + }) + } + pub fn parse_create_index(&mut self, unique: bool) -> Result { let if_not_exists = self.parse_keywords(&[Keyword::IF, Keyword::NOT, Keyword::EXISTS]); let index_name = self.parse_object_name()?;