From 7a7d935d184a02b4632dd74f9b150798d0448707 Mon Sep 17 00:00:00 2001 From: Dan Hansen Date: Sun, 28 Jan 2024 16:03:43 -0800 Subject: [PATCH] [Windowing] Handle null values in partitions --- internal/function_window_option.go | 9 ++++++++- query_test.go | 4 +++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/internal/function_window_option.go b/internal/function_window_option.go index 19da038..b3a7ce8 100644 --- a/internal/function_window_option.go +++ b/internal/function_window_option.go @@ -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 { @@ -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: diff --git a/query_test.go b/query_test.go index 31d13f3..45f6a69 100644 --- a/query_test.go +++ b/query_test.go @@ -1592,7 +1592,8 @@ 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, @@ -1600,6 +1601,7 @@ SELECT name, 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"},