zvonimir-dd commented on code in PR #2436:
URL:
https://github.com/apache/datafusion-sqlparser-rs/pull/2436#discussion_r3865922235
##########
tests/sqlparser_mysql.rs:
##########
@@ -4946,3 +4946,48 @@ fn parse_adjacent_string_literal_concatenation() {
fn parse_group_by_with_rollup() {
mysql().verified_stmt("SELECT * FROM tbl GROUP BY col1, col2 WITH ROLLUP");
}
+
+#[test]
+fn parse_is_distinct_from_json_arrow_precedence() {
+ // MySQL's `->` binds tighter than `IS [NOT] DISTINCT FROM`, so the JSON
+ // extraction must stay inside the right operand.
+ assert_eq!(
+ Expr::IsDistinctFrom(
+ Box::new(Expr::Identifier(Ident::new("a"))),
+ Box::new(Expr::BinaryOp {
+ left: Box::new(Expr::Identifier(Ident::new("b"))),
+ op: BinaryOperator::Arrow,
+ right: Box::new(Expr::Value(
+ Value::SingleQuotedString("k".into()).with_empty_span()
+ )),
+ }),
+ ),
+ mysql().verified_expr("a IS DISTINCT FROM b -> 'k'")
+ );
+}
+
+#[test]
+fn parse_json_arrow_comparison_precedence() {
+ // The same "any other operator" class also binds tighter than the
+ // comparison operators and `LIKE`, so the JSON extraction is the left
+ // operand rather than swallowing the right-hand side.
+ assert_eq!(
+ Expr::BinaryOp {
+ left: Box::new(Expr::BinaryOp {
+ left: Box::new(Expr::Identifier(Ident::new("a"))),
+ op: BinaryOperator::Arrow,
+ right: Box::new(Expr::Value(
+ Value::SingleQuotedString("k".into()).with_empty_span()
+ )),
+ }),
+ op: BinaryOperator::Eq,
+ right: Box::new(Expr::value(number("1"))),
+ },
+ mysql().verified_expr("a -> 'k' = 1")
+ );
+
+ assert_matches!(
+ mysql().verified_expr("a -> 'k' LIKE 'x'"),
+ Expr::Like { .. }
+ );
+}
Review Comment:
Done. `parse_json_arrow_comparison_precedence` is gone;
`parse_pg_other_operator_precedence` in `sqlparser_common.rs` replaces it. `t.a
-> 'k' = b` passes on all 15 dialects — a compound left operand is never read
as a lambda — so only the bare `a -> 'k' = b` form needs
`all_dialects_where(|d| !d.supports_lambda_functions())`. No dialect had to be
excluded.
One deviation: I kept a `LIKE` case rather than dropping it. `Like` is 19
and `Eq` is 20, so the `=` assertion alone leaves the 19/21 boundary untested —
a future change landing `PgOther` anywhere in 17..=19 would still pass `=` and
silently break `LIKE`. Let me know if you'd prefer it gone.
--
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]