Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add more window functions #534

Merged
merged 15 commits into from
Sep 8, 2023
Merged
Changes from 5 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
128 changes: 128 additions & 0 deletions extensions/functions_arithmetic.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1614,3 +1614,131 @@ window_functions:
decomposable: NONE
return: i64?
window_type: PARTITION
- name: "first_value"
description: >
The `expression` is evaluated against the first row. The `expression` can be a
column, expression or subquery that evaluates to a single value.
EpsilonPrime marked this conversation as resolved.
Show resolved Hide resolved
impls:
- args:
- value: any1
name: expression
nullability: DECLARED_OUTPUT
decomposable: NONE
return: any1?
richtia marked this conversation as resolved.
Show resolved Hide resolved
window_type: PARTITION
- name: "last_value"
description: >
The `expression` is evaluated against the last row. The `expression` can be a
column, expression, or subquery that evaluates to a single value.
impls:
- args:
- value: any1
name: expression
nullability: DECLARED_OUTPUT
decomposable: NONE
return: any1?
richtia marked this conversation as resolved.
Show resolved Hide resolved
window_type: PARTITION
- name: "nth_value"
description: >
The `expression` is evaluated against a row that comes after the current row based
EpsilonPrime marked this conversation as resolved.
Show resolved Hide resolved
on the `offset`. `offset` should be a positive integer. The `expression` can be a
column, expression or subquery that evaluates to a single value.
EpsilonPrime marked this conversation as resolved.
Show resolved Hide resolved
impls:
- args:
- value: any1
name: expression
- value: i32
name: offset
nullability: DECLARED_OUTPUT
decomposable: NONE
return: any1?
window_type: PARTITION
- args:
- value: any1
name: expression
- value: i64
name: offset
nullability: DECLARED_OUTPUT
decomposable: NONE
return: any1?
window_type: PARTITION
- name: "lead"
description: >
Return a value from a following row based on a specified physical offset.
This allows you to compare a value in the current row against a following row.

The `expression` is evaluated against a row that comes after the current row based
on the `offset`. The `expression` can be a column, expression or subquery that
evaluates to a single value. The `offset` should be a positive integer and is set to
1 if not specified explicitly. The function returns the `default` input value if
EpsilonPrime marked this conversation as resolved.
Show resolved Hide resolved
`offset` goes beyond the scope of the partition. If a `default` value is not
specified, it is set to `null`

Example comparing the sales of the current year to the following year.
| year | sales | next_year_sales |
| 2019 | 20.50 | 30.00 |
| 2020 | 30.00 | 45.99 |
| 2021 | 45.99 | null |
impls:
- args:
- value: any1
name: expression
- value: i32
name: offset
- value: any1
name: default
nullability: DECLARED_OUTPUT
decomposable: NONE
return: any1?
window_type: PARTITION
- args:
- value: any1
name: expression
- value: i64
name: offset
- value: any1
name: default
EpsilonPrime marked this conversation as resolved.
Show resolved Hide resolved
nullability: DECLARED_OUTPUT
decomposable: NONE
return: any1?
window_type: PARTITION
- name: "lag"
description: >
Return a column value from a previous row based on a specified physical offset.
This allows you to compare a value in the current row against a previous row.

The `expression` is evaluated against a row that comes before the current row based
on the `offset`. The `expression` can be a column, expression or subquery that
evaluates to a single value. The `offset` should be a positive integer and is set to
1 if not specified explicitly. The function returns the `default` input value if
`offset` goes beyond the scope of the partition. If a `default` value is not
specified, it is set to `null`

Example comparing the sales of the current year to the previous year.
| year | sales | previous_year_sales |
| 2019 | 20.50 | null |
| 2020 | 30.00 | 20.50 |
| 2021 | 45.99 | 30.00 |
impls:
- args:
- value: any1
name: expression
- value: i32
name: offset
- value: any1
name: default
nullability: DECLARED_OUTPUT
decomposable: NONE
return: any1?
window_type: PARTITION
- args:
- value: any1
name: expression
- value: i64
name: offset
- value: any1
name: default
nullability: DECLARED_OUTPUT
decomposable: NONE
return: any1?
window_type: PARTITION