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: support new aggregate framework for HashAggExec #7268

Merged
merged 8 commits into from
Aug 21, 2018
19 changes: 8 additions & 11 deletions executor/aggfuncs/func_group_concat.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,29 +82,28 @@ 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 := "", false
v, isNull, preLen := "", false, 0
for _, row := range rowsInGroup {
if p.buffer != nil {
if p.buffer != nil && p.buffer.Len() != 0 {
preLen = p.buffer.Len()
p.buffer.WriteString(e.sep)
}
isAllNull := true
for _, arg := range e.args {
v, isNull, err = arg.EvalString(sctx, row)
if err != nil {
return errors.Trace(err)
}
if isNull {
continue
break
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why change here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}
isAllNull = false
if p.buffer == nil {
p.buffer = &bytes.Buffer{}
}
p.buffer.WriteString(v)
}
if isAllNull {
if isNull {
if p.buffer != nil {
p.buffer.Truncate(p.buffer.Len() - len(e.sep))
p.buffer.Truncate(preLen)
}
continue
}
Expand Down Expand Up @@ -156,20 +155,18 @@ 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)
if err != nil {
return errors.Trace(err)
}
if isNull {
continue
break
}
allIsNull = false
p.valsBuf.WriteString(v)
}
if allIsNull {
if isNull {
continue
}
joinedVals := p.valsBuf.String()
Expand Down
Loading