Skip to content

Commit

Permalink
executor: fix group_concat(a) when a is null (#7287)
Browse files Browse the repository at this point in the history
  • Loading branch information
XuHuaiyu authored and zhexuany committed Aug 8, 2018
1 parent b39b5f5 commit af7fed9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
17 changes: 14 additions & 3 deletions executor/aggfuncs/func_group_concat.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,11 @@ func (e *groupConcat) UpdatePartialResult(sctx sessionctx.Context, rowsInGroup [
p.buffer.WriteString(e.sep)
}
}
p.buffer.Truncate(p.buffer.Len() - len(e.sep))
return e.truncatePartialResultIfNeed(sctx, p.buffer)
if p.buffer != nil {
p.buffer.Truncate(p.buffer.Len() - len(e.sep))
return e.truncatePartialResultIfNeed(sctx, p.buffer)
}
return nil
}

type partialResult4GroupConcatDistinct struct {
Expand Down Expand Up @@ -133,6 +136,7 @@ func (e *groupConcatDistinct) UpdatePartialResult(sctx sessionctx.Context, rowsI
p := (*partialResult4GroupConcatDistinct)(pr)
v, isNull := "", false
for _, row := range rowsInGroup {
allIsNull := true
p.valsBuf.Reset()
for _, arg := range e.args {
v, isNull, err = arg.EvalString(sctx, row)
Expand All @@ -142,8 +146,12 @@ func (e *groupConcatDistinct) UpdatePartialResult(sctx sessionctx.Context, rowsI
if isNull {
continue
}
allIsNull = false
p.valsBuf.WriteString(v)
}
if allIsNull {
continue
}
joinedVals := p.valsBuf.String()
if p.valSet.exist(joinedVals) {
continue
Expand All @@ -158,5 +166,8 @@ func (e *groupConcatDistinct) UpdatePartialResult(sctx sessionctx.Context, rowsI
// write values
p.buffer.WriteString(joinedVals)
}
return e.truncatePartialResultIfNeed(sctx, p.buffer)
if p.buffer != nil {
return e.truncatePartialResultIfNeed(sctx, p.buffer)
}
return nil
}
5 changes: 5 additions & 0 deletions executor/aggregate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,11 @@ func (s *testSuite) TestAggregation(c *C) {
result.Check(testkit.Rows(string([]byte{0x0}), string([]byte{0x1})))
result = tk.MustQuery("select cast(a as signed) as idx, cast(max(a) as signed), cast(min(a) as signed) from t group by 1 order by idx")
result.Check(testkit.Rows("0 0 0", "1 1 1"))

tk.MustExec("drop table t")
tk.MustExec("create table t(a int)")
tk.MustExec("insert into t value(null)")
tk.MustQuery("select group_concat(a), group_concat(distinct a) from t").Check(testkit.Rows("<nil> <nil>"))
}

func (s *testSuite) TestStreamAggPushDown(c *C) {
Expand Down

0 comments on commit af7fed9

Please sign in to comment.