Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

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

Open
#2,974 1 comment 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
sql
Domain
databases

Research direction

Start by tracing Apache Drill's existing LEAD and LAG window-function implementation and how it parses their arguments. Compare the current behavior with the documented lag(expr, offset, default) syntax and the computed-column examples in the issue. Done means parameterized offsets work for LEAD and LAG, including lagging computed expressions without producing unexpected nulls.

Written by the indexing model from the issue text.

Description

verified

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

Dominant language
Java
Stars
2k
Forks
989
Avg merge
3d 14h
Merged PRs (30d)
7

Getting set up

  • Ships a Dockerfile or Docker Compose file
  • Has a pull request template
  • No contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from apache/drill

All issues in apache/drill

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.