You are viewing documentation about an older version (1.13.0). View latest version

snowflake.snowpark.functions.lead¶

snowflake.snowpark.functions.lead(e: Union[Column, str], offset: int = 1, default_value: Union[Column, None, bool, int, float, str, bytearray, Decimal, date, datetime, time, bytes, list, tuple, dict] = None, ignore_nulls: bool = False) → Column[source]¶

Accesses data in a subsequent row in the same result set without having to join the table to itself.

Example:

>>> from snowflake.snowpark.window import Window
>>> df = session.create_dataframe(
...     [
...         [1, 2, 1],
...         [1, 2, 3],
...         [2, 1, 10],
...         [2, 2, 1],
...         [2, 2, 3],
...     ],
...     schema=["x", "y", "z"]
... )
>>> df.select(lead("Z").over(Window.partition_by(col("X")).order_by(col("Y"))).alias("result")).collect()
[Row(RESULT=1), Row(RESULT=3), Row(RESULT=None), Row(RESULT=3), Row(RESULT=None)]
Copy