lead(value: storable, leadby: const int64) -> value

Return the value of one column in a following row across an ordered group. offset is the number of rows forward from the current row to obtain a value. If no ordering is specified, the default ordering is that of the invoking verb, which is generally the valid_from timestamp, ascending. In this case, lead(col, 1) returns the next value for column col.

Domain

This is a window function (calculates over a group of multiple input rows using windowing).

Categories

Examples

make_col next_value:window(lead(value, 1), group_by(key))

Obtain the next value within the group identified by key and store the results in a new column named next_value. Because we did not specify a order_by clause in the window function nor in the verb, the lead function would use the default ordering, which is time ascending.

timestampkeyvaluenext_value
100A54
150B65
180A43
300B5null
400A3null
make_col low_value:window(lead(value, 2), order_by(value, false), group_by(key))

Obtain the second lowest value above the current value within the group identified by key and store the results in a new column named low_value. We use an order_by function to order the rows by value ascending.

timestampkeyvaluelow_value
100A5null
200B6null
200A47
300B5null
400A35
400B26
500A7null
make_col next_value:window(lead(value, 1), group_by(key), frame_exact(ahead:100ns))

Obtain the next value within the group identified by key and store the results in a new column named next_value. Because a frame_exact is specified for the window function, next_value would be null if the most recent value is found outside the window frame.

timestampkeyvaluenext_value
100A54
150B6null
180A4null
300B5null
400A3null