iffyio commented on code in PR #2307:
URL:
https://github.com/apache/datafusion-sqlparser-rs/pull/2307#discussion_r3411737295
##########
src/parser/mod.rs:
##########
@@ -10020,6 +10029,107 @@ impl<'a> Parser<'a> {
}
}
+ // The leading `EXCLUDE` keyword is already consumed by the caller.
+ fn parse_exclude_constraint(
+ &mut self,
+ name: Option<Ident>,
+ ) -> Result<ExcludeConstraint, ParserError> {
+ let index_method = if self.parse_keyword(Keyword::USING) {
+ Some(self.parse_identifier()?)
+ } else {
+ None
+ };
+
+ self.expect_token(&Token::LParen)?;
+ let elements = self.parse_comma_separated(|p|
p.parse_exclude_constraint_element())?;
+ self.expect_token(&Token::RParen)?;
+
+ let include = if self.parse_keyword(Keyword::INCLUDE) {
+ self.expect_token(&Token::LParen)?;
+ let cols = self.parse_comma_separated(|p| p.parse_identifier())?;
+ self.expect_token(&Token::RParen)?;
+ cols
+ } else {
+ vec![]
+ };
+
+ let where_clause = if self.parse_keyword(Keyword::WHERE) {
+ self.expect_token(&Token::LParen)?;
+ let predicate = self.parse_expr()?;
+ self.expect_token(&Token::RParen)?;
+ Some(Box::new(predicate))
+ } else {
+ None
+ };
+
+ let characteristics = self.parse_constraint_characteristics()?;
+
+ Ok(ExcludeConstraint {
+ name,
+ index_method,
+ elements,
+ include,
+ where_clause,
+ characteristics,
+ })
+ }
+
+ fn parse_exclude_constraint_element(
+ &mut self,
+ ) -> Result<ExcludeConstraintElement, ParserError> {
+ let column = self.parse_create_index_expr()?;
+ self.expect_keyword_is(Keyword::WITH)?;
+ let operator = self.parse_exclude_constraint_operator()?;
+ Ok(ExcludeConstraintElement { column, operator })
+ }
+
+ /// Parse the operator that follows `WITH` in an `EXCLUDE` element.
+ fn parse_exclude_constraint_operator(
+ &mut self,
+ ) -> Result<ExcludeConstraintOperator, ParserError> {
+ if self.parse_keyword(Keyword::OPERATOR) {
+ return Ok(ExcludeConstraintOperator::PGOperator(
+ self.parse_pg_operator_ident_parts()?,
+ ));
+ }
+
+ // Without this guard a bare `WITH` at the end of an element would
Review Comment:
is this check necessary (if the parser already consumed a valid operator it
should be able to return OK and leave the rest of the stream as is)? the
comment seems to suggest otherwise but I'm not sure I see how it affects this
function's behavior
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]