apache / apache/datafusion-sqlparser-rs

A bracket-quoted identifier containing `]]` round-trips to SQL that fails to reparse

Đang mở
#2,409 1 bình luận 0 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
Rust
Star
3.5k
Fork
772
Merge trung bình
4 ngày 9 giờ
Pull request đã merge (30 ngày)
17

Mô tả

```rust
use sqlparser::dialect::MsSqlDialect;
use sqlparser::parser::Parser;

fn main() {
let sql = "SELECT [a]]b]";
let ast = Parser::parse_sql(&MsSqlDialect {}, sql).unwrap();
let printed = ast[0].to_string();
println!("input: {}", sql);
println!("printed: {}", printed);
let reparsed = Parser::parse_sql(&MsSqlDialect {}, &printed);
println!("reparsed: {:?}", reparsed);
}
```

```
input: SELECT [a]]b]
printed: SELECT [a]b]
reparsed: Err(ParserError("Expected: end of statement, found: ] at Line: 1, Column: 12"))
```

`[a]]b]` is a bracket-quoted identifier whose value is `a]b` (the tokenizer folds the doubled `]]` into a literal `]`). Displaying the parsed AST back to SQL writes `[a]b]` instead, and that string does not parse as the same identifier: it parses as `a` followed by leftover tokens `]b]`.

Tested on sqlparser 0.62.0.

BTW, this bug was found using [hegel](https://crates.io/crates/hegeltest). Happy to contribute the tests if you're interested.

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Hướng nghiên cứu

Tái hiện sự cố bằng ví dụ Rust sử dụng MsSqlDialect, Parser::parse_sql và AST to_string. Kiểm tra cách tokenizer xử lý các dấu ngoặc vuông kép và cách định danh đã được phân tích cú pháp được hiển thị, sau đó thêm một bài kiểm thử hồi quy round-trip cho thấy [a]]b] được phân tích cú pháp lại thành định danh a]b và chạy bộ kiểm thử liên quan.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
rust
Lĩnh vực
databases
Loại issue
Lỗi
Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức độ hoạt động
Ít trao đổi
Độ rõ ràng
Đặc tả rõ ràng
Mức phù hợp với người mới
68/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.