WindowSpec — Window Specification
WindowSpec
is a window specification that defines which rows are included in a window (frame), i.e. the set of rows that are associated with the current row by some relation.
WindowSpec
takes the following when created:
-
Partition specification (
Seq[Expression]
) which defines which records are in the same partition. With no partition defined, all records belong to a single partition -
Ordering Specification (
Seq[SortOrder]
) which defines how records in a partition are ordered that in turn defines the position of a record in a partition. The ordering could be ascending (ASC
in SQL orasc
in Scala) or descending (DESC
ordesc
). -
Frame Specification (
WindowFrame
) which defines the rows to be included in the frame for the current row, based on their relative position to the current row. For example, “the three rows preceding the current row to the current row” describes a frame including the current input row and three rows appearing before the current row.
You use Window object to create a WindowSpec
.
1 2 3 4 5 6 7 |
import org.apache.spark.sql.expressions.Window scala> val byHTokens = Window.partitionBy('token startsWith "h") byHTokens: org.apache.spark.sql.expressions.WindowSpec = org.apache.spark.sql.expressions.WindowSpec@574985d8 |
Once the initial version of a WindowSpec
is created, you use the methods to further configure the window specification.
Method | Description | ||
---|---|---|---|
|
|
||
|
|
||
|
|
||
|
|
With a window specification fully defined, you use Column.over operator that associates the WindowSpec
with an aggregate or window function.
1 2 3 4 5 6 7 8 9 |
scala> :type windowSpec org.apache.spark.sql.expressions.WindowSpec import org.apache.spark.sql.functions.rank val c = rank over windowSpec |
withAggregate
Internal Method
1 2 3 4 5 |
withAggregate(aggregate: Column): Column |
withAggregate
…FIXME
Note
|
withAggregate is used exclusively when Column.over operator is used.
|