SparkEx.WindowSpec (SparkEx v0.1.0)

Copy Markdown View Source

Represents a window specification for window functions.

A WindowSpec defines partitioning, ordering, and frame boundaries for window functions used with SparkEx.Column.over/2.

Examples

import SparkEx.Functions, only: [col: 1]

spec =
  SparkEx.Window.partition_by(["dept"])
  |> SparkEx.WindowSpec.order_by(["salary"])
  |> SparkEx.WindowSpec.rows_between(-1, 1)

col("salary") |> SparkEx.Functions.row_number() |> SparkEx.Column.over(spec)

Summary

Functions

Adds order-by columns to the window specification.

Adds partition-by columns to the window specification.

Defines a range-based window frame between start and end_ boundaries.

Defines a row-based window frame between start and end_ boundaries.

Types

boundary()

@type boundary() :: :unbounded | :current_row | integer()

frame_spec()

@type frame_spec() ::
  nil | {:rows, boundary(), boundary()} | {:range, boundary(), boundary()}

t()

@type t() :: %SparkEx.WindowSpec{
  frame_spec: frame_spec(),
  order_spec: [SparkEx.Column.expr()],
  partition_spec: [SparkEx.Column.expr()]
}

Functions

order_by(spec, cols)

@spec order_by(t(), [SparkEx.Column.t() | String.t() | atom()]) :: t()

Adds order-by columns to the window specification.

partition_by(spec, cols)

@spec partition_by(t(), [SparkEx.Column.t() | String.t() | atom()]) :: t()

Adds partition-by columns to the window specification.

range_between(spec, start, end_)

@spec range_between(t(), boundary(), boundary()) :: t()

Defines a range-based window frame between start and end_ boundaries.

Boundary values:

  • :unbounded — unbounded preceding/following
  • :current_row — current row
  • negative integer — N preceding
  • positive integer — N following
  • 0 — current row

rows_between(spec, start, end_)

@spec rows_between(t(), boundary(), boundary()) :: t()

Defines a row-based window frame between start and end_ boundaries.

Boundary values:

  • :unbounded — unbounded preceding/following
  • :current_row — current row
  • negative integer — N rows preceding
  • positive integer — N rows following
  • 0 — current row