Skip to content

Fix window frame clause BETWEEN ... AND ... syntax - #8

Open
SanjanaBoggaramJ wants to merge 1 commit into
masterfrom
feature/window-frame-clause
Open

Fix window frame clause BETWEEN ... AND ... syntax#8
SanjanaBoggaramJ wants to merge 1 commit into
masterfrom
feature/window-frame-clause

Conversation

@SanjanaBoggaramJ

Copy link
Copy Markdown
Collaborator

Summary

Test plan

  • Added test_window_frame_clause covering the docs' own example, all bound combinations, all frame units, and all EXCLUDE variants.
  • Full existing test suite passes with no regressions.

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).

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.

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_extent parsing by adding an explicit BETWEEN <start> AND <end> form and consuming expr offsets before PRECEDING/FOLLOWING.
  • Splits bounds into window_frame_start and window_frame_end to reflect asymmetric bound rules.
  • Adds test_window_frame_clause with 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 thread src/lark_sqlpp/sqlpp.lark
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 thread tests/test_parser.py
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
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.

2 participants