daft.functions.lead#
lead #
lead(expr: Expression, offset: int = 1, default: Expression | None = None) -> Expression
Get the value from a future row within a window partition.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
expr | Expression | The expression to get the lead value of. | required |
offset | int | The number of rows to shift forward. Must be >= 0. | 1 |
default | Expression | None | Value to use when no future row exists. Can be a column reference. | None |
Returns:
| Name | Type | Description |
|---|---|---|
Expression | Expression | Value from the row |
Examples:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | |
╭──────────┬───────┬─────────────┬───────┬───────────────────╮
│ category ┆ value ┆ default_val ┆ lead ┆ lead_with_default │
│ --- ┆ --- ┆ --- ┆ --- ┆ --- │
│ String ┆ Int64 ┆ Int64 ┆ Int64 ┆ Int64 │
╞══════════╪═══════╪═════════════╪═══════╪═══════════════════╡
│ A ┆ 1 ┆ 10 ┆ 2 ┆ 2 │
├╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
│ A ┆ 2 ┆ 20 ┆ 3 ┆ 3 │
├╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
│ A ┆ 3 ┆ 30 ┆ None ┆ 30 │
├╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
│ B ┆ 4 ┆ 40 ┆ 5 ┆ 5 │
├╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
│ B ┆ 5 ┆ 50 ┆ 6 ┆ 6 │
├╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
│ B ┆ 6 ┆ 60 ┆ None ┆ 60 │
╰──────────┴───────┴─────────────┴───────┴───────────────────╯
(Showing first 6 of 6 rows) Source code in daft/functions/window.py
255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 | |