(&mut self)
| 4243 | } |
| 4244 | |
| 4245 | fn parse_create_index(&mut self) -> Result<Statement<Raw>, ParserError> { |
| 4246 | let default_index = self.parse_keyword(DEFAULT); |
| 4247 | self.expect_keyword(INDEX)?; |
| 4248 | |
| 4249 | let if_not_exists = self.parse_if_not_exists()?; |
| 4250 | let name = if self.peek_keyword(IN) || self.peek_keyword(ON) { |
| 4251 | if if_not_exists && !default_index { |
| 4252 | return self.expected(self.peek_pos(), "index name", self.peek_token()); |
| 4253 | } |
| 4254 | None |
| 4255 | } else { |
| 4256 | Some(self.parse_identifier()?) |
| 4257 | }; |
| 4258 | let in_cluster = self.parse_optional_in_cluster()?; |
| 4259 | self.expect_keyword(ON)?; |
| 4260 | let on_name = self.parse_raw_name()?; |
| 4261 | |
| 4262 | // Arrangements are the only index type we support, so we can just ignore this |
| 4263 | if self.parse_keyword(USING) { |
| 4264 | self.expect_keyword(ARRANGEMENT)?; |
| 4265 | } |
| 4266 | |
| 4267 | let key_parts = if default_index { |
| 4268 | None |
| 4269 | } else { |
| 4270 | self.expect_token(&Token::LParen)?; |
| 4271 | if self.consume_token(&Token::RParen) { |
| 4272 | Some(vec![]) |
| 4273 | } else { |
| 4274 | let key_parts = self |
| 4275 | .parse_comma_separated(Parser::parse_order_by_expr)? |
| 4276 | .into_iter() |
| 4277 | .map(|x| x.expr) |
| 4278 | .collect::<Vec<_>>(); |
| 4279 | self.expect_token(&Token::RParen)?; |
| 4280 | Some(key_parts) |
| 4281 | } |
| 4282 | }; |
| 4283 | |
| 4284 | let with_options = if self.parse_keyword(WITH) { |
| 4285 | self.expect_token(&Token::LParen)?; |
| 4286 | let o = if matches!(self.peek_token(), Some(Token::RParen)) { |
| 4287 | vec![] |
| 4288 | } else { |
| 4289 | self.parse_comma_separated(Parser::parse_index_option)? |
| 4290 | }; |
| 4291 | self.expect_token(&Token::RParen)?; |
| 4292 | o |
| 4293 | } else { |
| 4294 | vec![] |
| 4295 | }; |
| 4296 | |
| 4297 | Ok(Statement::CreateIndex(CreateIndexStatement { |
| 4298 | name, |
| 4299 | in_cluster, |
| 4300 | on_name, |
| 4301 | key_parts, |
| 4302 | with_options, |
no test coverage detected