fmguerreiro commented on code in PR #2307:
URL:
https://github.com/apache/datafusion-sqlparser-rs/pull/2307#discussion_r3411810246
##########
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:
yeah, you're right, it doesn't change correctness. tested removing it:
`EXCLUDE (c WITH)` still errors because the trailing `expect RParen` catches
it, just with a worse message (`Expected: ',' or ')' ... found: EOF` instead of
`Expected: exclusion operator, found: )`). no valid operator is one of those
delimiter tokens, so the guard never rejects anything real. kept it just for
the error message and reworded the comment to say that. happy to drop it if
you'd rather.
--
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]