Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions dialects/tests/expressions_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,5 @@ supported_expressions:
- CURRENT_DATE
- CURRENT_TIMESTAMP
- CURRENT_TIMEZONE
- expression: WINDOW_FUNCTION
supports_offset_expr: false
26 changes: 20 additions & 6 deletions proto/substrait/algebra.proto
Original file line number Diff line number Diff line change
Expand Up @@ -1402,17 +1402,31 @@ message Expression {
// Defines that the bound extends this far back from the current record.
message Preceding {
// A strictly positive integer specifying the number of records that
// the window extends back from the current record. Required. Use
// CurrentRow for offset zero and Following for negative offsets.
int64 offset = 1;
// the window extends back from the current record. Required.
// Use CurrentRow for offset zero and Following for negative offsets.
// Deprecated: use `offset_expr` instead.
int64 offset = 1 [deprecated = true];

// Expression evaluated into a strictly positive integer specifying
// the offset from the current record. Evaluating to null, zero, or
// a negative integer should result in an error.
// Recommended type for offset is int64.
Expression offset_expr = 2;
}

// Defines that the bound extends this far ahead of the current record.
message Following {
// A strictly positive integer specifying the number of records that
// the window extends ahead of the current record. Required. Use
// CurrentRow for offset zero and Preceding for negative offsets.
int64 offset = 1;
// the window extends ahead of the current record. Required.
// Use CurrentRow for offset zero and Preceding for negative offsets.
// Deprecated: use `offset_expr` instead.
int64 offset = 1 [deprecated = true];

// Expression evaluated into a strictly positive integer specifying
// the offset from the current record. Evaluating to null, zero, or
// a negative integer should result in an error.
// Recommended type for offset is int64.
Expression offset_expr = 2;
}

// Defines that the bound extends to or from the current record.
Expand Down
6 changes: 4 additions & 2 deletions site/docs/expressions/window_functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ When binding a window function, the binding must include the following additiona
| Property | Description | Required |
| ----------- | ------------------------------------------------------------ | ------------------------------------------------------------ |
| Partition | A list of partitioning expressions. | False, defaults to a single partition for the entire dataset |
| Lower Bound | Bound Following(int64), Bound Trailing(int64) or CurrentRow. | False, defaults to start of partition |
| Upper Bound | Bound Following(int64), Bound Trailing(int64) or CurrentRow. | False, defaults to end of partition |
| Lower Bound | Preceding, Following, CurrentRow, or Unbounded. | False, defaults to start of partition |
| Upper Bound | Preceding, Following, CurrentRow, or Unbounded. | False, defaults to end of partition |

`Preceding` and `Following` define offsets relative to the current record. `offset_expr` is the recommended way to specify the offset; it should evaluate to a strictly positive integer and should use type `int64`. A literal integer `offset` is still accepted for compatibility but is deprecated. Evaluating `offset_expr` to null, zero, or a negative integer should result in an error. Use `CurrentRow` for offset zero, and use the opposite bound direction for negative offsets.

## Aggregate Functions as Window Functions

Expand Down
7 changes: 7 additions & 0 deletions text/dialect_schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1100,6 +1100,13 @@ definitions:
metadata:
type: object
description: Arbitrary data created by the dialect author.
supports_offset_expr:
type: boolean
default: false
description: >
Whether this dialect supports expression-based offsets for window
function bounds. If false, only literal offsets are supported for
Preceding and Following bounds. Defaults to false.
required: [expression]
if_then_expression:
type: object
Expand Down