zommiommy commented on PR #3043:
URL:
https://github.com/apache/datafusion-sqlparser-rs/pull/3043#issuecomment-7237899559
there's a precedence issue:
```sql
SELECT 'a' NOT GLOB 'a' = 1
-- this PR: 'a' NOT GLOB ('a' = 1)
-- SQLite: ('a' NOT GLOB 'a') = 1 -- sqlite3 3.53.3 returns 0; the
right-grouped form returns 1
```
in SQLite's docs
(https://www.sqlite.org/lang_expr.html#operators_and_parse_affecting_attributes),
=, ==, <>, !=, IS [NOT] [DISTINCT FROM], BETWEEN, IN, MATCH, LIKE, REGEXP and
GLOB share one cell, so they have the same precedence and are
left-associative.
note 5 says NOT keeps the bare operator's precedence.
SQLiteDialect maps Precedence::Like to 19 and Eq/Between to 20, so they are
not on the same level.
```rust
#[test]
fn parse_negated_glob_and_match_binds_like_comparison() {
for (operator, expected) in [
("NOT GLOB", BinaryOperator::NotGlob),
("NOT MATCH", BinaryOperator::NotMatch),
] {
assert_eq!(
sqlite().verified_expr(&format!("a {operator} 'p' = 1")),
Expr::BinaryOp {
left: Box::new(Expr::BinaryOp {
left: Box::new(Expr::Identifier(Ident::new("a"))),
op: expected,
right: Box::new(Expr::Value(
(Value::SingleQuotedString("p".to_string())).with_empty_span()
)),
}),
op: BinaryOperator::Eq,
right: Box::new(Expr::value(number("1"))),
}
);
}
}
```
GLOB / MATCH already have this problem on main
a nit: NotGlob/NotMatch should be inserted at the end; otherwise, it will
BinaryOperator's serialized versions. serde formats like bincode use the enum
variant position as discriminant, so changing the order of variants breaks file
compatibility. idk if this is important for this crate tho.
--
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]