LucaCappelletti94 commented on code in PR #2522:
URL:
https://github.com/apache/datafusion-sqlparser-rs/pull/2522#discussion_r4098297338
##########
src/parser/mod.rs:
##########
@@ -4457,8 +4457,14 @@ impl<'a> Parser<'a> {
Ok(in_op)
}
- /// Parses `BETWEEN <low> AND <high>`, assuming the `BETWEEN` keyword was
already consumed.
+ /// Parses `[ASYMMETRIC | SYMMETRIC] <low> AND <high>`, assuming the
`BETWEEN` keyword was already consumed.
pub fn parse_between(&mut self, expr: Expr, negated: bool) -> Result<Expr,
ParserError> {
+ let symmetric = if self.parse_keyword(Keyword::SYMMETRIC) {
+ true
+ } else {
+ let _ = self.parse_keyword(Keyword::ASYMMETRIC);
+ false
+ };
Review Comment:
You should gate the modifier behind a dialect method. Consumed
unconditionally, it breaks `a BETWEEN symmetric AND 5` in every dialect where
`symmetric` is an ordinary identifier.
```suggestion
let symmetric = self.dialect.supports_between_symmetric()
&& self.parse_one_of_keywords(&[Keyword::SYMMETRIC,
Keyword::ASYMMETRIC])
== Some(Keyword::SYMMETRIC);
```
##########
tests/sqlparser_common.rs:
##########
@@ -20067,6 +20071,26 @@ fn parse_insert_by_name() {
}
}
+#[test]
+fn parse_between_symmetric() {
+ // See https://www.postgresql.org/docs/current/functions-comparison.html
+ match verified_expr("1 BETWEEN SYMMETRIC 2 AND 3") {
+ Expr::Between {
+ symmetric, negated, ..
+ } => {
+ assert!(symmetric);
+ assert!(!negated);
+ }
+ _ => unreachable!(),
+ }
+
+ // ASYMMETRIC is the default behavior and is not preserved as SQL text.
+ one_statement_parses_to(
+ "SELECT * FROM t WHERE 1 NOT BETWEEN ASYMMETRIC 2 AND 3",
+ "SELECT * FROM t WHERE 1 NOT BETWEEN 2 AND 3",
+ );
Review Comment:
Some additional red tests.
```suggestion
// See https://www.postgresql.org/docs/current/functions-comparison.html
let supported = all_dialects_where(|d| d.supports_between_symmetric());
match supported.verified_expr("1 BETWEEN SYMMETRIC 2 AND 3") {
Expr::Between {
symmetric, negated, ..
} => {
assert!(symmetric);
assert!(!negated);
}
_ => unreachable!(),
}
// ASYMMETRIC is the default behavior and is not preserved as SQL text.
supported.one_statement_parses_to(
"SELECT * FROM t WHERE 1 NOT BETWEEN ASYMMETRIC 2 AND 3",
"SELECT * FROM t WHERE 1 NOT BETWEEN 2 AND 3",
);
let unsupported = all_dialects_where(|d|
!d.supports_between_symmetric());
unsupported.verified_expr("a BETWEEN symmetric AND 5");
unsupported.verified_expr("a BETWEEN asymmetric AND 5");
```
--
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]