Skip to content

Commit 861103b

Browse files
lwhilengaut
authored andcommitted
executor: remove Next function for HashAggExec (#5987)
1 parent 5445e17 commit 861103b

File tree

1 file changed

+0
-63
lines changed

1 file changed

+0
-63
lines changed

executor/aggregate.go

Lines changed: 0 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -141,41 +141,6 @@ func (e *HashAggExec) execute(ctx context.Context) (err error) {
141141
}
142142
}
143143

144-
// Next implements the Executor Next interface.
145-
func (e *HashAggExec) Next(ctx context.Context) (Row, error) {
146-
// In this stage we consider all data from src as a single group.
147-
if !e.executed {
148-
for {
149-
hasMore, err := e.innerNext(ctx)
150-
if err != nil {
151-
return nil, errors.Trace(err)
152-
}
153-
if !hasMore {
154-
break
155-
}
156-
}
157-
if (e.groupMap.Len() == 0) && len(e.GroupByItems) == 0 {
158-
// If no groupby and no data, we should add an empty group.
159-
// For example:
160-
// "select count(c) from t;" should return one row [0]
161-
// "select count(c) from t group by c1;" should return empty result set.
162-
e.groupMap.Put([]byte{}, []byte{})
163-
}
164-
e.executed = true
165-
}
166-
167-
groupKey, _ := e.groupIterator.Next()
168-
if groupKey == nil {
169-
return nil, nil
170-
}
171-
retRow := make([]types.Datum, 0, len(e.AggFuncs))
172-
aggCtxs := e.getContexts(groupKey)
173-
for i, af := range e.AggFuncs {
174-
retRow = append(retRow, af.GetResult(aggCtxs[i]))
175-
}
176-
return retRow, nil
177-
}
178-
179144
func (e *HashAggExec) getGroupKey(row types.Row) ([]byte, error) {
180145
vals := make([]types.Datum, 0, len(e.GroupByItems))
181146
for _, item := range e.GroupByItems {
@@ -196,34 +161,6 @@ func (e *HashAggExec) getGroupKey(row types.Row) ([]byte, error) {
196161
return e.groupKey, nil
197162
}
198163

199-
// innerNext fetches a single row from src and update each aggregate function.
200-
// If the first return value is false, it means there is no more data from src.
201-
func (e *HashAggExec) innerNext(ctx context.Context) (ret bool, err error) {
202-
srcRow, err := e.children[0].Next(ctx)
203-
if err != nil {
204-
return false, errors.Trace(err)
205-
}
206-
if srcRow == nil {
207-
return false, nil
208-
}
209-
e.executed = true
210-
groupKey, err := e.getGroupKey(srcRow)
211-
if err != nil {
212-
return false, errors.Trace(err)
213-
}
214-
if len(e.groupMap.Get(groupKey, e.groupVals[:0])) == 0 {
215-
e.groupMap.Put(groupKey, []byte{})
216-
}
217-
aggCtxs := e.getContexts(groupKey)
218-
for i, af := range e.AggFuncs {
219-
err = af.Update(aggCtxs[i], e.sc, srcRow)
220-
if err != nil {
221-
return false, errors.Trace(err)
222-
}
223-
}
224-
return true, nil
225-
}
226-
227164
func (e *HashAggExec) getContexts(groupKey []byte) []*aggregation.AggEvaluateContext {
228165
groupKeyString := string(groupKey)
229166
aggCtxs, ok := e.aggCtxsMap[groupKeyString]

0 commit comments

Comments
 (0)