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

snowflake.snowpark.functions.lead¶

snowflake.snowpark.functions.lead(e: ColumnOrName, offset: int = 1, default_value: Column | LiteralType | None = 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