Skip to content

Commit

Permalink
executor: remove Next function for HashAggExec (#5987)
Browse files Browse the repository at this point in the history
  • Loading branch information
lwhile authored and ngaut committed Mar 22, 2018
1 parent 5445e17 commit 861103b
Showing 1 changed file with 0 additions and 63 deletions.
63 changes: 0 additions & 63 deletions executor/aggregate.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,41 +141,6 @@ func (e *HashAggExec) execute(ctx context.Context) (err error) {
}
}

// Next implements the Executor Next interface.
func (e *HashAggExec) Next(ctx context.Context) (Row, error) {
// In this stage we consider all data from src as a single group.
if !e.executed {
for {
hasMore, err := e.innerNext(ctx)
if err != nil {
return nil, errors.Trace(err)
}
if !hasMore {
break
}
}
if (e.groupMap.Len() == 0) && len(e.GroupByItems) == 0 {
// If no groupby and no data, we should add an empty group.
// For example:
// "select count(c) from t;" should return one row [0]
// "select count(c) from t group by c1;" should return empty result set.
e.groupMap.Put([]byte{}, []byte{})
}
e.executed = true
}

groupKey, _ := e.groupIterator.Next()
if groupKey == nil {
return nil, nil
}
retRow := make([]types.Datum, 0, len(e.AggFuncs))
aggCtxs := e.getContexts(groupKey)
for i, af := range e.AggFuncs {
retRow = append(retRow, af.GetResult(aggCtxs[i]))
}
return retRow, nil
}

func (e *HashAggExec) getGroupKey(row types.Row) ([]byte, error) {
vals := make([]types.Datum, 0, len(e.GroupByItems))
for _, item := range e.GroupByItems {
Expand All @@ -196,34 +161,6 @@ func (e *HashAggExec) getGroupKey(row types.Row) ([]byte, error) {
return e.groupKey, nil
}

// innerNext fetches a single row from src and update each aggregate function.
// If the first return value is false, it means there is no more data from src.
func (e *HashAggExec) innerNext(ctx context.Context) (ret bool, err error) {
srcRow, err := e.children[0].Next(ctx)
if err != nil {
return false, errors.Trace(err)
}
if srcRow == nil {
return false, nil
}
e.executed = true
groupKey, err := e.getGroupKey(srcRow)
if err != nil {
return false, errors.Trace(err)
}
if len(e.groupMap.Get(groupKey, e.groupVals[:0])) == 0 {
e.groupMap.Put(groupKey, []byte{})
}
aggCtxs := e.getContexts(groupKey)
for i, af := range e.AggFuncs {
err = af.Update(aggCtxs[i], e.sc, srcRow)
if err != nil {
return false, errors.Trace(err)
}
}
return true, nil
}

func (e *HashAggExec) getContexts(groupKey []byte) []*aggregation.AggEvaluateContext {
groupKeyString := string(groupKey)
aggCtxs, ok := e.aggCtxsMap[groupKeyString]
Expand Down

0 comments on commit 861103b

Please sign in to comment.