apache / apache/datafusion-sqlparser-rs

Inconsistent spans for function calls

Đang mở
#2,050 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ả

When using functions spans, it appears that sometimes the closing parenthesis is included, sometimes not.

Consider the following test:

```rust
#[test]
fn test_function_span() {
let sql = "SELECT database(), left(user(),instr(concat(user(),'@'),'@')-1);";
let r = Parser::parse_sql(&crate::dialect::MySqlDialect {}, sql).unwrap();

let query = match &r[0] {
crate::ast::Statement::Query(q) => q,
_ => panic!("Expected query"),
};

let select = match query.body.as_ref() {
crate::ast::SetExpr::Select(s) => s,
_ => panic!("Expected select"),
};

let database_func = match &select.projection[0] {
crate::ast::SelectItem::UnnamedExpr(crate::ast::Expr::Function(func)) => func,
_ => panic!("Expected function expression"),
};
let span = database_func.span();
assert_eq!(span.start, (1, 8).into());
assert_eq!(span.end, (1, 17).into()); // fails here

let left_func = match &select.projection[1] {
crate::ast::SelectItem::UnnamedExpr(crate::ast::Expr::Function(func)) => func,
_ => panic!("Expected function expression"),
};
let span = left_func.span();
assert_eq!(span.start, (1, 20).into());
assert_eq!(span.end, (1, 63).into());
}
```

In both cases, we're testing if the closing parenthesis is included in the span. The first span test for `database_func` fails:

```diff
Diff < left / right > :
-Location(1,16)
+Location(1,17)
```

If I comment that part, the second pair of span assertions passes correctly.

In other words, it seems that we only include closing parentheses for function calls with arguments, but not if there's no argument.

Related: #1548 #1563 #1676

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

Bắt đầu với trường hợp test_function_span được cung cấp bằng cách sử dụng Parser::parse_sql và MySqlDialect, sau đó theo dõi cách các span của hàm được tạo ra cho database() và left(...). So sánh ranh giới span đối với các lời gọi có và không có đối số. Hoàn thành khi cả hai assertion đều nhất quán bao gồm dấu ngoặc đơn đóng và test chạy thành công.

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
compilers
Loại issue
Lỗi
Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
45/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.