Bitwise `&` and `->` group differently in the PostgreSQL and MySQL/Generic dialects
Maintainer thường phản hồi trong vòng 2 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 78/100
Hướng nghiên cứu
Bắt đầu trong src/dialect/mod.rs với bảng độ ưu tiên mặc định, sau đó so sánh nó với PostgreSqlDialect::prec_value trong src/dialect/postgresql.rs:176-184 và quy tắc PostgreSQL trong gram.y được trích dẫn trong issue. Thêm một bài kiểm thử hồi quy ở cấp cây cho a -> b & c, vì các bài kiểm thử round-trip SQL không thể phát hiện việc nhóm, rồi chạy toàn bộ bộ kiểm thử để xác minh thay đổi.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
& and -> have the same precedence in PostgreSQL but not in the default precedence table, so the
same expression produces two different trees depending on dialect:
| SQL | PostgreSqlDialect |
MySqlDialect / GenericDialect |
|---|---|---|
a -> b & c |
((a -> b) & c) |
(a -> (b & c)) |
a -> b | c |
((a -> b) | c) |
((a -> b) | c) |
a -> b ^ c |
(a -> (b ^ c)) |
(a -> (b ^ c)) |
a -> b + c |
(a -> (b + c)) |
(a -> (b + c)) |
& is the only row that disagrees.
Cause
The default table in src/dialect/mod.rs has:
Precedence::Ampersand => 23,
Precedence::Caret => 22,
Precedence::Pipe => 21,
Precedence::Colon => 21,
Precedence::PgOther => 21,
PostgreSqlDialect::prec_value instead maps Ampersand, Pipe, Colon and PgOther all to
PG_OTHER_PREC (src/dialect/postgresql.rs:176-184), which matches gram.y, where & is just a
generic Op and shares one left-associative level with ->:
%left Op OPERATOR RIGHT_ARROW '|'
So Pipe already agrees with PgOther in the default table (both 21), and Caret is legitimately
above it, but Ampersand at 23 is left as the sole outlier.
Candidate fix
- Precedence::Ampersand => 23,
+ Precedence::Ampersand => 21,
The full suite passes unchanged with that applied, so no existing test pins the current grouping —
which is also why this went unnoticed. Display for Expr::BinaryOp emits no parentheses, so a
mis-grouped tree round-trips to the original SQL and verified_expr / verified_stmt cannot catch
it; a test would have to assert on the tree.
Open question, possibly a separate issue
For MySQL the fix above is necessary but not sufficient. MySQL's -> / ->> take a quoted JSON path
on the right-hand side, so there is nothing for MySQL to resolve — col->'$.a' + 1 can only mean
(col->'$.a') + 1. sqlparser parses that right operand as a full expression at PgOther, giving
col -> ('$.a' + 1), so -> under-binds in MySQL against +, *, ^ and friends, not just &.
Making that correct probably means a MySQL-specific precedence for the arrow operators rather than
another adjustment to the shared row, so I've kept it out of scope here — happy to split it out if
a maintainer would prefer it tracked separately.
Surfaced while working on #2436. Related: #2460.
- Ngôn ngữ chính
- Rust
- Star
- 3.5k
- Fork
- 780
- Merge trung bình
- 4 ngày 6 giờ
- Pull request đã merge (30 ngày)
- 56
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Không có hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của apache/datafusion-sqlparser-rs
-
ClickHouse
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
apache/datafusion-sqlparser-rs#2599 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
ClickHouse: Support `GLOBAL IN` / `GLOBAL NOT IN`Có thể đã có người làm @s5dsn-eqee đã nhận 6 ngày trước. Đang mởClickHouse
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
apache/datafusion-sqlparser-rs#2597 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
HIVE: Round trip fails for field access on a numeric-prefix identifierCó thể đã có người làm @efegokdemir đã nhận 9 ngày trước. Đang mởHive
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
apache/datafusion-sqlparser-rs#2589 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
PostgreSQL 18 generated virtual columns require STOREDCó thể đã có người làm @ting-hong-shieh đã nhận 50 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 73/100
apache/datafusion-sqlparser-rs#2407 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
Add SQL/PGQ keywordsCó thể đã có người làm @zhjwpku đã nhận 96 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
apache/datafusion-sqlparser-rs#2393 ·
Maintainer thường phản hồi trong vòng 2 ngày
Tất cả issue của apache/datafusion-sqlparser-rs
Issue tương tự
-
enhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
zcashlabs/thus-spoke-zakura#153 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
claude_code: step fails on session-scoped (`@inline`) plugins with `Invalid scope "session"`Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 79/100
topgrade-rs/topgrade#2395 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
app bug windows-os
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 67/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Improve sublime text syntaxĐang mởeditor good first issue
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
funnyboy-roks/inq#54 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
pnpm/pnpm#16635 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày