Skip to content

DuckDB: support QUALIFY after WINDOW, OVER (w ...) and FILTER without WHERE - #2803

Merged
manticore-projects merged 2 commits into
JSQLParser:masterfrom
guizmaii:duckdb-window-grouping
Oct 13, 2026
Merged

manticore-projects merged 2 commits into
JSQLParser:masterfrom
guizmaii:duckdb-window-grouping

Conversation

@guizmaii

Copy link
Copy Markdown
Contributor

For DuckDB's window and aggregate syntax (window functions, QUALIFY, FILTER).

Input Before After
... WINDOW w AS (ORDER BY a) QUALIFY row_number() OVER w = 1 error QUALIFY printed after WINDOW (isQualifyAfterWindow())
sum(a) OVER (w ROWS 2 PRECEDING), WINDOW w2 AS (w ORDER BY b) error WindowDefinition.getBaseWindowName() = w
sum(a) FILTER (b > 1) error AnalyticExpression.isFilterWhereKeyword() = false
  • DuckDB requires WINDOW before QUALIFY and BigQuery the reverse, so PlainSelect records the order it was written in.
  • The base window name is recognised when the first token of the specification is not PARTITION, ORDER, ROWS, RANGE or GROUPS, so frames such as OVER (rows BETWEEN ...) are unchanged.
  • FILTER without WHERE is rejected under Dialect.POSTGRESQL, which requires it (OrderedSetFilterTest unchanged).
  • All new inputs were errors in every dialect; on ~9,760 statements extracted from this repository's tests, results are identical to master.
  • Not included: DuckDB's GROUP BY a, GROUPING SETS (...) mixes, which GroupByElement's separate lists cannot represent in order.
  • checkGrammarAmbiguity: no conflicts. ./gradlew check: 10,118 tests, 0 failures.
  • DuckDB's own test suite (test/sql, 70,729 statements): 26 more parse, none less.

@guizmaii
guizmaii marked this pull request as ready for review October 13, 2026 09:59
Copilot AI balanced review requested due to automatic review settings October 13, 2026 09:59

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@manticore-projects

Copy link
Copy Markdown
Contributor

please resolve conflict.

@guizmaii
guizmaii force-pushed the duckdb-window-grouping branch 2 times, most recently from e1d2f66 to 2f3123b Compare October 13, 2026 12:49
@hayssams

Copy link
Copy Markdown
Contributor

Nice

@guizmaii
guizmaii force-pushed the duckdb-window-grouping branch 2 times, most recently from 91825c0 to cd8889c Compare October 13, 2026 22:02
@manticore-projects

Copy link
Copy Markdown
Contributor

please resolve conflict.

@guizmaii
guizmaii force-pushed the duckdb-window-grouping branch from cd8889c to 6a340be Compare October 13, 2026 22:27
@guizmaii

Copy link
Copy Markdown
Contributor Author

Rebased on master, conflicts resolved.

… WHERE

- QUALIFY may follow the WINDOW clause and prints back there
  (`PlainSelect.isQualifyAfterWindow()`).
- A window specification may start with the name of the window it
  extends, `OVER (w ORDER BY b)`, also in WINDOW definitions
  (`WindowDefinition.getBaseWindowName()`).
- `FILTER (b > 1)` without WHERE is accepted except under the
  PostgreSQL dialect (`AnalyticExpression.isFilterWhereKeyword()`).
- The base window name is a choice rather than an optional, so that
  lookahead scans through a window specification keep its check:
  `JSON_VALUE(... DEFAULT sum(a) OVER (PARTITION BY b) ON EMPTY)` parses
  again.
- Only an OVER window may extend a named window, not WITHIN GROUP.
- QUALIFY after WINDOW requires a WINDOW clause.
@manticore-projects

Copy link
Copy Markdown
Contributor

Please resolve conflicts.

@guizmaii
guizmaii force-pushed the duckdb-window-grouping branch from 6a340be to 70e67f4 Compare October 13, 2026 22:31
@guizmaii

Copy link
Copy Markdown
Contributor Author

Rebased on master again (after #2801), conflicts resolved.

@manticore-projects
manticore-projects merged commit 7dcdeec into JSQLParser:master Oct 13, 2026
9 checks passed
@manticore-projects

Copy link
Copy Markdown
Contributor

Thank you very much!

@guizmaii

Copy link
Copy Markdown
Contributor Author

@manticore-projects Thanks for reviewing and merging my PRs!

Do you mind releasing a new version, please?

@manticore-projects

Copy link
Copy Markdown
Contributor

@manticore-projects Thanks for reviewing and merging my PRs!

Do you mind releasing a new version, please?

Certainly: pkg:maven/com.manticore-projects.jsqlformatter/jsqlparser@5.4.162

And thank you for all your work and contributions! I do appreciate you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants