feat: support expression in window aggregate bounds#1105
Conversation
|
It looks like for |
I'm trying to separate the |
| int64 offset = 1; | ||
| // the window extends back from the current record. Required. | ||
| // Use CurrentRow for offset zero and Following for negative offsets. | ||
| oneof offset_mode { |
There was a problem hiding this comment.
@vbarua here is a requested SQL example for the scenario. adapted from SQL server documentation.
https://learn.microsoft.com/en-us/sql/t-sql/functions/lag-transact-sql?view=sql-server-ver17#a-compare-values-between-years
USE AdventureWorks2022;
GO
SELECT BusinessEntityID, YEAR(QuotaDate) AS SalesYear, SalesQuota AS CurrentQuota,
LAG(SalesQuota, LookBack,0) OVER (ORDER BY YEAR(QuotaDate)) AS PreviousQuota
FROM Sales.SalesPersonQuotaHistory
WHERE BusinessEntityID = 275 AND YEAR(QuotaDate) IN ('2005','2006');The modification I made is LookBack in the LAG(), means you differentiate the offset per business entity id (let's say per rank of business entity id, for the senior rank look into further history). You can change LookBack to arbitrary scalar expression except another analytical function.
LookBack creates a new windowing spec including expression.
Motivation
Like #748 in FetchRel,
offsetcan be expressions in window spec.Proposal
BREAKING CHANGE: the change in this PR preserves wire format and old consumers can still parse the
int64 offset = 1field produced by a new producer. Also, the offset field must be positive (i.e., the value is always present) thus makes it no difference from implicit and explicit optional.This change is