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

Support lead, lag to access the previous or next row #8962

Closed
Tracked by #8961
neverchanje opened this issue Apr 3, 2023 · 3 comments
Closed
Tracked by #8961

Support lead, lag to access the previous or next row #8962

neverchanje opened this issue Apr 3, 2023 · 3 comments
Assignees
Labels
component/func-window-agg Support a SQL window aggregate function
Milestone

Comments

@neverchanje
Copy link
Contributor

neverchanje commented Apr 3, 2023

LAG(expression [, offset [, default ]]) OVER (ORDER BY expression [ASC|DESC])
LEAD(expression [, offset [, default ]]) OVER (ORDER BY expression [ASC|DESC])

Here is a brief description of each of the parameters:

  • expression: The column or expression for which you want to access the previous or next value.
  • offset: The number of rows to move backward or forward from the current row. The default value is 1, which means the function will access the value of the previous or next row.
  • default: The default value to return if the offset goes beyond the bounds of the window frame. If this parameter is not specified, the default value is NULL.
  • ORDER BY expression [ASC|DESC]: Specifies the order in which the rows are processed. The default order is ascending. NULLs can be sorted either first or last.

Here is an example of using LAG to calculate the change in value of a column between consecutive rows:

SELECT value, LAG(value) OVER (ORDER BY timestamp) as prev_value, (value - LAG(value) OVER (ORDER BY timestamp)) as change
FROM my_table

This query calculates the change in value of the value column between consecutive rows, ordered by the timestamp column.

Similarly, you can use LEAD to access the value of a column from the next row within a specific window frame.

@github-actions github-actions bot added this to the release-0.19 milestone Apr 3, 2023
@xiangjinwu xiangjinwu added the component/func-window-agg Support a SQL window aggregate function label Apr 4, 2023
@stdrc stdrc self-assigned this Apr 18, 2023
@stdrc
Copy link
Contributor

stdrc commented May 6, 2023

Similar to #4978, the lag and lead functions are supported after #9110, #9248 and #9597, though only for EOWC mode. I'm closing this issue now cuz the implementation of general version of over window executor is basically independent from the lag and lead implementation.

@stdrc stdrc closed this as completed May 6, 2023
@neverchanje neverchanje reopened this May 22, 2023
@neverchanje
Copy link
Contributor Author

neverchanje commented May 22, 2023

Reopen as we currently only support the EOWC version of lead/lag. The batch version and the general version have not been covered yet.

@stdrc
Copy link
Contributor

stdrc commented Jul 18, 2023

I think this is done since we now have eowc streaming, general streaming and batch mode supported.

@stdrc stdrc closed this as completed Jul 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/func-window-agg Support a SQL window aggregate function
Projects
None yet
Development

No branches or pull requests

3 participants