Skip to content

Commit

Permalink
*: Address comment
Browse files Browse the repository at this point in the history
  • Loading branch information
shenli committed Jan 23, 2016
1 parent aa431ee commit 6ed674f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
10 changes: 4 additions & 6 deletions ast/functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -557,17 +557,14 @@ func (n *AggregateFuncExpr) updateGroupConcat() error {
return nil
}
}
var buf bytes.Buffer
if ctx.Value != nil {
if ctx.Buffer.Len() > 0 {
// now use comma separator
buf.WriteString(ctx.Value.(string))
buf.WriteString(",")
ctx.Buffer.WriteString(",")
}
for _, val := range vals {
buf.WriteString(fmt.Sprintf("%v", val))
ctx.Buffer.WriteString(fmt.Sprintf("%v", val))
}
// TODO: if total length is greater than global var group_concat_max_len, truncate it.
ctx.Value = buf.String()
return nil
}

Expand Down Expand Up @@ -624,5 +621,6 @@ type AggEvaluateContext struct {
distinctChecker *distinct.Checker
Count int64
Value interface{}
Buffer bytes.Buffer // Buffer is used for group_concat.
evaluated bool
}
13 changes: 12 additions & 1 deletion optimizer/evaluator/evaluator.go
Original file line number Diff line number Diff line change
Expand Up @@ -960,8 +960,10 @@ func (e *Evaluator) aggregateFunc(v *ast.AggregateFuncExpr) bool {
e.evalAggAvg(v)
case ast.AggFuncCount:
e.evalAggCount(v)
case ast.AggFuncFirstRow, ast.AggFuncMax, ast.AggFuncMin, ast.AggFuncSum, ast.AggFuncGroupConcat:
case ast.AggFuncFirstRow, ast.AggFuncMax, ast.AggFuncMin, ast.AggFuncSum:
e.evalAggSetValue(v)
case ast.AggFuncGroupConcat:
e.evalAggGroupConcat(v)
}
return e.err == nil
}
Expand All @@ -986,3 +988,12 @@ func (e *Evaluator) evalAggAvg(v *ast.AggregateFuncExpr) {
}
v.SetValue(ctx.Value)
}

func (e *Evaluator) evalAggGroupConcat(v *ast.AggregateFuncExpr) {
ctx := v.GetContext()
if ctx.Buffer.Len() > 0 {
v.SetValue(ctx.Buffer.String())
} else {
v.SetValue(nil)
}
}

0 comments on commit 6ed674f

Please sign in to comment.