Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow Offset parameter for LEAD and LAG window functions as input parameters #2974

Open
hermygithub opened this issue Jan 17, 2025 · 1 comment
Labels

Comments

@hermygithub
Copy link

Is your feature request related to a problem? Please describe.
For time-series analysis, I would like to be able to lag columns for more than one position offset. currently the Lag function is restricted to an offset of '1' and does not allow it to be parameterized.

using Lag() on a computed column generates nulls.

Describe the solution you'd like
Ideally aligning to the following syntax
lag(expr[, offset[, default]][ IGNORE NULLS])
Returns expr evaluated at the row that is offset rows before the current row within the window frame;
https://duckdb.org/docs/sql/functions/window_functions.html#lagexpr-offset-default-ignore-nulls

Lag() on a computed column should provide the previous value of the expression outcome
`
'tickpos (Last*)' as 'tickpos (Last*)-0t',

		LAG('tickpos (Last*)',1) OVER ( PARTITION BY tickpos_instrument_id, tickpos_granularity ORDER BY tickpos_unixtime_upper )
			as 'tickpos (Last*)-1t',

		LAG('tickpos (Last*)-1t',1) OVER ( PARTITION BY tickpos_instrument_id, tickpos_granularity ORDER BY tickpos_unixtime_upper )
			as 'tickpos (Last*)-2t',

`

Image

Describe alternatives you've considered

  • lagging a lag computed column (this provides nulls)
  • calculating the unix epoch time of lag time slices and self-joining based on that calculated timestamp
  • potentially (but not tried) taking the first() element of a time window frame, ordered by timestamp

Additional context

https://issues.apache.org/jira/browse/DRILL-3596

@cgivre
Copy link
Contributor

cgivre commented Jan 17, 2025

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants