apache / apache/datafusion-sqlparser-rs
support scientific notation when parsing numbers
- 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ả
`select 1e3` currently identifies 1 as a number and e3 as alias. Instead, it should return 1e3 as part of the string Number.
```sql
select 1e3; -- returns now e3 as identifier and 1 as number, but should return 1e3 as number
select 1e3a; -- should return 1e3 as number, and a as identifier
select 1e; -- should return 1e as the number (currently returns 1 as number, e as identifier)
select 1e.5; -- correctly returns syntax error
select .5e2; -- should return .5e2 as number, but currently returns .5 as number, e2 as identifier
```
Since the user of the library will get back a string representing the number anyway and must parse it, we could recognize the e notation and leave it as part of the string in Number.
For example, Rust can parse scientific notation to f64:
```rust
let v = ["1", "1e3", "1e", ".5e2", "1e-1"];
for s in v {
let _ = s
.parse::()
.map(|i| println!("parsed {} as i64: {}", s, i))
.or_else(|_| {
s.parse::()
.map(|f| println!("parsed {} as f64: {}", s, f))
})
.map_err(|_| println!("couldn't parse {}", s));
}
```
```
parsed 1 as i64: 1
parsed 1e3 as f64: 1000
couldn't parse 1e
parsed .5e2 as f64: 50
parsed 1e-1 as f64: 0.1
```
Only problem is that `1e` parses to `1` in Postgres, but it wouldn't in this case without special handling by the parsers. In any case, this is an argument in favor of returning scientific notation as part of the existing Number enum value.
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
Issue không nêu tệp hoặc bài kiểm thử nào. Hãy bắt đầu bằng cách xác định điểm vào của SQL lexer hoặc phần phân tích cú pháp token số, sau đó tái hiện các đầu vào được liệt kê và bổ sung coverage cho ký hiệu khoa học, bao gồm các identifier ở phía sau và dấu của số mũ. Hoàn thành khi mỗi ví dụ tạo ra các token Number hoặc identifier được yêu cầu mà không thay đổi lỗi cú pháp hiện có đối với `1e.5`.
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, sql
- Lĩnh vực
- compilers, databases
- 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
- Đặc tả rõ ràng
- Mức phù hợp với người mới
- 35/100