Skip to content

Commit bc36c09

Browse files
committed
distinguish between nil bc buffer is empty and nil bc the value is supposed to be nil
1 parent fb801ef commit bc36c09

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

enginetest/queries/order_by_group_by_queries.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,4 +320,18 @@ var OrderByGroupByScriptTests = []ScriptTest{
320320
},
321321
},
322322
},
323+
{
324+
Name: "Group by null = 1",
325+
// https://github.com/dolthub/dolt/issues/9035
326+
SetUpScript: []string{
327+
"create table t0(c0 int, c1 int)",
328+
"insert into t0(c0, c1) values(NULL,1),(1,NULL)",
329+
},
330+
Assertions: []ScriptTestAssertion{
331+
{
332+
Query: "select t0.c0 = t0.c1 as ref0, sum(1) as ref1 from t0 group by ref0",
333+
Expected: []sql.Row{{nil, float64(2)}},
334+
},
335+
},
336+
},
323337
}

sql/expression/function/aggregation/unary_agg_buffers.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -500,17 +500,19 @@ func (c *countBuffer) Dispose() {
500500
}
501501

502502
type firstBuffer struct {
503-
val interface{}
504-
expr sql.Expression
503+
val interface{}
504+
// writtenNil means that val is supposed to be nil and should not be overwritten
505+
writtenNil bool
506+
expr sql.Expression
505507
}
506508

507509
func NewFirstBuffer(child sql.Expression) *firstBuffer {
508-
return &firstBuffer{nil, child}
510+
return &firstBuffer{nil, false, child}
509511
}
510512

511513
// Update implements the AggregationBuffer interface.
512514
func (f *firstBuffer) Update(ctx *sql.Context, row sql.Row) error {
513-
if f.val != nil {
515+
if f.val != nil || f.writtenNil {
514516
return nil
515517
}
516518

@@ -520,6 +522,7 @@ func (f *firstBuffer) Update(ctx *sql.Context, row sql.Row) error {
520522
}
521523

522524
if v == nil {
525+
f.writtenNil = true
523526
return nil
524527
}
525528

0 commit comments

Comments
 (0)