apache / apache/datafusion-sqlparser-rs

Cannot parse named windows with modifiers

Đang mở
#999 1 bình luận 1 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ả

sqlparser-rs only supports named windows that are an identifier. This is fine for queries like:

```sql
SELECT sum(salary) OVER w, avg(salary) OVER w
FROM empsalary
WINDOW w AS (PARTITION BY depname ORDER BY salary DESC);
```

However, it is insufficient for queries in at least BigQuery and MySQL where modifiers can be added to the named window in the OVER clause.

[MySQL named window example](https://dev.mysql.com/doc/refman/8.0/en/window-functions-named-windows.html)

```sql
SELECT
DISTINCT year, country,
FIRST_VALUE(year) OVER (w ORDER BY year ASC) AS first,
FIRST_VALUE(year) OVER (w ORDER BY year DESC) AS last
FROM sales
WINDOW w AS (PARTITION BY country)
```

[BigQuery named window example](https://cloud.google.com/bigquery/docs/reference/standard-sql/window-function-calls)

```sql
SELECT item, purchases, category, LAST_VALUE(item)
OVER (
item_window
ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING
) AS most_popular
FROM Produce
WINDOW item_window AS (
PARTITION BY category
ORDER BY purchases)
```

This would build upon prior to work:
- https://github.com/sqlparser-rs/sqlparser-rs/issues/867
- https://github.com/sqlparser-rs/sqlparser-rs/pull/881

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 bằng cách kiểm tra cách sqlparser-rs phân tích biểu thức named-window trong mệnh đề OVER, sau đó xem lại issue #867 và pull request #881 để biết thiết kế trước đây. Thêm coverage cho việc phân tích các ví dụ MySQL và BigQuery, đồng thời xác minh rằng các named windows có modifier được chấp nhận mà không gây regression đối với các named windows thông thườ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, sql
Lĩnh vực
compilers, databases
Loại issue
Tính năng
Độ 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
40/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.