You can use window functions in Expression transformations to perform stateful computations on the Spark engine.
A stateful computation is a function that takes some state and returns a value along with a new state.
You can use a window function to perform stateful computations. A window function takes a small subset of a larger data set for processing and analysis.
Window functions operate on a group of rows and calculate a return value for every input row. This characteristic of window functions makes it easy to express data processing tasks that are difficult to express concisely without window functions.
Use window functions to perform the following tasks:
Retrieve data from upstream or downstream rows.
Calculate a cumulative sum based on a group of rows.
Calculate a cumulative average based on a group of rows.
Before you define a window function in an Expression transformation, you must describe the window by configuring the windowing properties. Windowing properties include a frame specification, partition keys, and order keys. The frame specification states which rows are included in the overall calculation for the current row. The partition keys determine which rows are in the same partition. The order keys determine how rows in a partition are ordered.
After you configure windowing properties, you define a window function in the Expression transformation. Spark supports the window functions LEAD and LAG. You can also use aggregate functions as window functions in an Expression transformation.