apache / apache/datafusion-sqlparser-rs

Cannot parse named windows with modifiers

Open
#999 1 comment 1 reaction 0 assignees View on GitHub
Dominant language
Rust
Stars
3.5k
Forks
772
Avg merge
4d 9h
Merged PRs (30d)
17

Description

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

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by examining how sqlparser-rs parses the named-window expression in the OVER clause, then review issue #867 and pull request #881 for the prior design. Add parsing coverage for the MySQL and BigQuery examples, and verify that named windows with modifiers are accepted without regressing plain named windows.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust, sql
Domain
compilers, databases
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
40/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.