fix: support PostgreSQL GROUPS window frames - #2460
Conversation
There was a problem hiding this comment.
Pull request overview
Adds PostgreSQL-compatible support for GROUPS window frames, enabling parsing/deparsing of ... OVER ( ... GROUPS ... ) frame specifications (fixes #2431).
Changes:
- Added
GROUPSas a non-reserved keyword so it can still be used as an unquoted identifier outside window-frame contexts. - Extended
WindowElement.TypewithGROUPSand updated the window-frame grammar to acceptGROUPSalongsideROWS/RANGE. - Added unit tests covering
GROUPS BETWEEN ... AND ..., single-sidedUNBOUNDED PRECEDING, and namedWINDOWdefinitions.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/test/java/net/sf/jsqlparser/statement/select/WindowFunctionTest.java | Adds regression/variant tests asserting AST typing and round-trip deparse for GROUPS frames. |
| src/main/jjtree/net/sf/jsqlparser/parser/JSqlParserCC.jjt | Adds GROUPS token to non-reserved keywords and accepts it in the WindowElement frame-mode grammar. |
| src/main/java/net/sf/jsqlparser/expression/WindowElement.java | Extends WindowElement.Type enum to include GROUPS for AST representation and deparsing. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
Thank you for working on this. PostgreSQL's (and SQL:2011's) frame clause has a third component that JSqlParser's WindowElement() doesn't model at all. It bites harder in GROUPS mode and so I do wonder if not adding full support while you are on it. With your PR this meaningful query still fails: SELECT id, ts, value,
SUM(value) OVER (ORDER BY ts
GROUPS BETWEEN 1 PRECEDING AND CURRENT ROW
EXCLUDE TIES) AS sum_excl_ties
FROM events
ORDER BY ts, id;Furthermore, promoting a word to a token breaks every production taking a raw <S_IDENTIFIER>: CREATE SCHEMA (~10496), SET PATH (~10538), Oracle KEEP (~9121), interval type (~9092), COLLATE (7912), and the nested ColDataType() lookahead (10873). We either need to declare it a reserved keyword (which was reasonable) or make at least |
|
Thanks for the detailed review. I’ve updated the PR in I also moved The tests now cover all four exclusions, the |
|
Very nice! Thank you much for your contribution! |
Fixes #2431
What
Add support for PostgreSQL
GROUPSwindow frames and all four window frame exclusions.How
WindowElement.Type.GROUPS.GROUPSas a reserved structural keyword.WindowElement.Exclusionfor:EXCLUDE CURRENT ROWEXCLUDE GROUPEXCLUDE TIESEXCLUDE NO OTHERSTIESandOTHERScontextual so they remain usable as unquoted identifiers outside the frame-exclusion grammar.WindowElement.toString().Tests
BETWEEN ... AND ..., a single-sided frame, a namedWINDOW, and all four frame exclusions.tiesandothersremain usable as identifiers../gradlew clean checkmvn clean verify