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

[Windowing] Handle null values in partitions #9

Merged
merged 1 commit into from
Jan 29, 2024
Merged
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
9 changes: 8 additions & 1 deletion internal/function_window_option.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,9 @@ type WindowFuncStatus struct {
OrderBy []*WindowOrderBy
}

// windowNilPartitionValue Placeholder value for nil
const windowNilPartitionValue = StringValue("^^^ZETASQLITE_NIL^^^")

func (s *WindowFuncStatus) Partition() (string, error) {
partitions := make([]string, 0, len(s.Partitions))
for _, p := range s.Partitions {
Expand Down Expand Up @@ -314,7 +317,11 @@ func parseWindowOptions(args ...Value) ([]Value, *WindowFuncStatus, error) {
case WindowFuncOptionEnd:
opt.End = v.Value.(*WindowBoundary)
case WindowFuncOptionPartition:
opt.Partitions = append(opt.Partitions, v.Value.(Value))
if v.Value != nil {
opt.Partitions = append(opt.Partitions, v.Value.(Value))
} else {
opt.Partitions = append(opt.Partitions, windowNilPartitionValue)
}
case WindowFuncOptionRowID:
opt.RowID = v.Value.(int64)
case WindowFuncOptionOrderBy:
Expand Down
4 changes: 3 additions & 1 deletion query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1592,14 +1592,16 @@ WITH finishers AS
UNION ALL SELECT 'Jen Edwards', TIMESTAMP '2016-10-18 3:06:36+00', 'F30-34'
UNION ALL SELECT 'Meghan Lederer', TIMESTAMP '2016-10-18 3:07:41+00', 'F30-34'
UNION ALL SELECT 'Carly Forte', TIMESTAMP '2016-10-18 3:08:58+00', 'F25-29'
UNION ALL SELECT 'Lauren Reasoner', TIMESTAMP '2016-10-18 3:10:14+00', 'F30-34')
UNION ALL SELECT 'Lauren Reasoner', TIMESTAMP '2016-10-18 3:10:14+00', 'F30-34'
UNION ALL SELECT 'Nilly Nada', TIMESTAMP '2016-10-18 3:10:14+00', null)
SELECT name,
FORMAT_TIMESTAMP('%X', finish_time) AS finish_time,
division,
LEAD(name, 2, 'Nobody')
OVER (PARTITION BY division ORDER BY finish_time ASC) AS two_runners_back
FROM finishers`,
expectedRows: [][]interface{}{
{"Nilly Nada", "03:10:14", nil, "Nobody"},
{"Carly Forte", "03:08:58", "F25-29", "Nobody"},
{"Sophia Liu", "02:51:45", "F30-34", "Jen Edwards"},
{"Nikki Leith", "02:59:01", "F30-34", "Meghan Lederer"},
Expand Down
Loading