Fix window frame clause BETWEEN ... AND ... syntax - #8
Open
SanjanaBoggaramJ wants to merge 1 commit into
Open
Conversation
window_frame_extent previously couldn't parse the BETWEEN form at all: it never consumed a numeric/expr offset before PRECEDING/FOLLOWING, and had no AND <second bound> clause. Splits BETWEEN into window_frame_start/window_frame_end per the N1QL window docs, since the two bounds are asymmetric (start excludes UNBOUNDED FOLLOWING, end excludes UNBOUNDED PRECEDING).
There was a problem hiding this comment.
Pull request overview
This PR updates the SQL++ grammar to correctly parse window frame clauses using ROWS|RANGE|GROUPS BETWEEN ... AND ... (including consuming the numeric offset before PRECEDING/FOLLOWING) and adds parser tests to cover common window frame bound/exclusion combinations.
Changes:
- Fixes
window_frame_extentparsing by adding an explicitBETWEEN <start> AND <end>form and consumingexproffsets beforePRECEDING/FOLLOWING. - Splits bounds into
window_frame_startandwindow_frame_endto reflect asymmetric bound rules. - Adds
test_window_frame_clausewith several window frame examples across frame units and exclusion variants.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| tests/test_parser.py | Adds parsing tests for window frame clauses and exclusions. |
| src/lark_sqlpp/sqlpp.lark | Adjusts window frame grammar to support BETWEEN ... AND ... and numeric offsets with PRECEDING/FOLLOWING. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
425
to
+428
| window_frame_extent: ( "UNBOUNDED"i "PRECEDING"i ) | ||
| | ( expr "PRECEDING"i ) | ||
| | ( "CURRENT"i "ROW"i ) | ||
| | ( "BETWEEN"i ( ( "UNBOUNDED"i "PRECEDING"i ) | ||
| | ( "CURRENT"i "ROW"i ) | ||
| | ( "PRECEDING"i | "FOLLOWING"i ) \ | ||
| ) ) | ||
| | ( "BETWEEN"i window_frame_start "AND"i window_frame_end ) |
Comment on lines
+120
to
+126
| tree = parse_sqlpp("SELECT SUM(x) OVER (ORDER BY y ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING EXCLUDE NO OTHERS) FROM foo;") | ||
| assert modifies_data(tree) == False | ||
| assert modifies_structure(tree) == False | ||
|
|
||
| tree = parse_sqlpp("SELECT SUM(x) OVER (ORDER BY y ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING EXCLUDE TIES) FROM foo;") | ||
| assert modifies_data(tree) == False | ||
| assert modifies_structure(tree) == False |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Solves the WINDOW issue mentioned in Few Queries not handled in the parser #6
For more details, here is the Couchbase docs link: https://docs.couchbase.com/server/current/n1ql/n1ql-language-reference/window.html
Test plan