[WIP] Implement LEAD, LAG, FIRST_VALUE, and LAST_VALUE functions #2412
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.
Thanks for assigning this issue to me. I'm starting to work on it and will keep this PR's description up to date as I form a plan and make progress.
Original prompt
This section details on the original issue you should resolve
<issue_title>Window Offset Functions (LEAD/LAG/FIRST_VALUE/LAST_VALUE) Not Implemented</issue_title>
<issue_description>## Summary
Window offset functions
LEAD(),LAG(),FIRST_VALUE(), andLAST_VALUE()are not implemented in AlaSQL. These are essential SQL:2003 standard window functions that allow accessing rows relative to the current row within a partition.Current Behavior
The same error occurs for
LAG(),FIRST_VALUE(), andLAST_VALUE().Expected Behavior
LEAD() - Access Next Row Value
LAG() - Access Previous Row Value
FIRST_VALUE() - Access First Row in Window
LAST_VALUE() - Access Last Row in Window
Use Cases
1. Calculate Period-over-Period Change
2. Find Next Event Time
3. Compare with Baseline
Function Signatures
LEAD(expression [, offset [, default]]) OVER (...)
expression: Column or expression to retrieve from the lead rowoffset: Number of rows forward (default: 1)default: Value to return when lead row doesn't exist (default: NULL)LAG(expression [, offset [, default]]) OVER (...)
expression: Column or expression to retrieve from the lag rowoffset: Number of rows backward (default: 1)default: Value to return when lag row doesn't exist (default: NULL)FIRST_VALUE(expression) OVER (...)
expression: Column or expression to retrieve from first row in window frameLAST_VALUE(expression) OVER (...)
expression: Column or expression to retrieve from last row in window frameImplementation Requirements
1. Parser Updates
Add function tokens to
src/alasqlparser.jison:2. Function R...
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.