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

snowflake.snowpark.Window

class snowflake.snowpark.Window[source]

Bases: object

Contains functions to form WindowSpec. See Snowflake Window functions for reference.

Examples:

>>> from snowflake.snowpark.functions import col, avg
>>> window1 = Window.partition_by("value").order_by("key").rows_between(Window.CURRENT_ROW, 2)
>>> window2 = Window.order_by(col("key").desc()).range_between(Window.UNBOUNDED_PRECEDING, Window.UNBOUNDED_FOLLOWING)
>>> df = session.create_dataframe([(1, "1"), (2, "2"), (1, "3"), (2, "4")], schema=["key", "value"])
>>> df.select(avg("value").over(window1).as_("window1"), avg("value").over(window2).as_("window2")).sort("window1").collect()
[Row(WINDOW1=1.0, WINDOW2=2.5), Row(WINDOW1=2.0, WINDOW2=2.5), Row(WINDOW1=3.0, WINDOW2=2.5), Row(WINDOW1=4.0, WINDOW2=2.5)]
Copy

Methods

orderBy(*cols)

Returns a WindowSpec object with order by clause.

order_by(*cols)

Returns a WindowSpec object with order by clause.

partitionBy(*cols)

Returns a WindowSpec object with partition by clause.

partition_by(*cols)

Returns a WindowSpec object with partition by clause.

rangeBetween(start, end)

Returns a WindowSpec object with the range frame clause.

range_between(start, end)

Returns a WindowSpec object with the range frame clause.

rowsBetween(start, end)

Returns a WindowSpec object with the row frame clause.

rows_between(start, end)

Returns a WindowSpec object with the row frame clause.

Attributes

CURRENT_ROW

Returns a value representing current row.

UNBOUNDED_FOLLOWING

Returns a value representing unbounded following.

UNBOUNDED_PRECEDING

Returns a value representing unbounded preceding.

currentRow

unboundedFollowing

unboundedPreceding