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

executor: fix group_concat for cases like group_concat(123,null) (#9921) #9930

Merged
merged 2 commits into from
Mar 28, 2019
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
31 changes: 15 additions & 16 deletions executor/aggfuncs/func_group_concat.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ func (e *baseGroupConcat4String) truncatePartialResultIfNeed(sctx sessionctx.Con
}

type basePartialResult4GroupConcat struct {
buffer *bytes.Buffer
valsBuf *bytes.Buffer
buffer *bytes.Buffer
}

type partialResult4GroupConcat struct {
Expand All @@ -76,7 +77,9 @@ type groupConcat struct {
}

func (e *groupConcat) AllocPartialResult() PartialResult {
return PartialResult(new(partialResult4GroupConcat))
p := new(partialResult4GroupConcat)
p.valsBuf = &bytes.Buffer{}
return PartialResult(p)
}

func (e *groupConcat) ResetPartialResult(pr PartialResult) {
Expand All @@ -86,12 +89,9 @@ func (e *groupConcat) ResetPartialResult(pr PartialResult) {

func (e *groupConcat) UpdatePartialResult(sctx sessionctx.Context, rowsInGroup []chunk.Row, pr PartialResult) (err error) {
p := (*partialResult4GroupConcat)(pr)
v, isNull, preLen := "", false, 0
v, isNull := "", false
for _, row := range rowsInGroup {
if p.buffer != nil && p.buffer.Len() != 0 {
preLen = p.buffer.Len()
p.buffer.WriteString(e.sep)
}
p.valsBuf.Reset()
for _, arg := range e.args {
v, isNull, err = arg.EvalString(sctx, row)
if err != nil {
Expand All @@ -100,17 +100,17 @@ func (e *groupConcat) UpdatePartialResult(sctx sessionctx.Context, rowsInGroup [
if isNull {
break
}
if p.buffer == nil {
p.buffer = &bytes.Buffer{}
}
p.buffer.WriteString(v)
p.valsBuf.WriteString(v)
}
if isNull {
if p.buffer != nil {
p.buffer.Truncate(preLen)
}
continue
}
if p.buffer == nil {
p.buffer = &bytes.Buffer{}
} else {
p.buffer.WriteString(e.sep)
}
p.buffer.WriteString(p.valsBuf.String())
}
if p.buffer != nil {
return e.truncatePartialResultIfNeed(sctx, p.buffer)
Expand Down Expand Up @@ -144,8 +144,7 @@ func (e *groupConcat) GetTruncated() *int32 {

type partialResult4GroupConcatDistinct struct {
basePartialResult4GroupConcat
valsBuf *bytes.Buffer
valSet set.StringSet
valSet set.StringSet
}

type groupConcatDistinct struct {
Expand Down
3 changes: 3 additions & 0 deletions executor/aggregate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,9 @@ func (s *testSuite) TestGroupConcatAggr(c *C) {

result = tk.MustQuery("select id, group_concat(name SEPARATOR '123') from test group by id order by id")
result.Check(testkit.Rows("1 101232012330", "2 20", "3 200123500"))

// issue #9920
tk.MustQuery("select group_concat(123, null)").Check(testkit.Rows("<nil>"))
}

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