class QAggregate extends QOperator {

    QAggregate(Select select) {
        super(select);
        select.currentGroup = new HashMap<>();
    }

    @Override
    public void run() {<FILL_FUNCTION_BODY>}
}

        while (next()) {
            boolean yield = yieldIfNeeded(++loopCount);
            if (conditionEvaluator.getBooleanValue()) {
                if (select.isForUpdate && !tryLockRow()) {
                    return; // 锁记录失败
                }
                rowCount++;
                select.currentGroupRowId++;
                for (int i = 0; i < columnCount; i++) {
                    Expression expr = select.expressions.get(i);
                    expr.updateAggregate(session);
                }
                if (sampleSize > 0 && rowCount >= sampleSize) {
                    break;
                }
            }
            if (yield)
                return;
        }
        // 最后把聚合后的结果增加到结果集中
        Value[] row = createRow();
        row = QGroup.toResultRow(row, columnCount, select.resultColumnCount);
        result.addRow(row);
        loopEnd = true;
    
<methods>public void <init>(com.lealone.sql.query.Select) ,public boolean canBreakLoop() ,public void copyStatusTo(com.lealone.sql.query.QOperator) ,public com.lealone.sql.expression.evaluator.ExpressionEvaluator createConditionEvaluator(com.lealone.sql.expression.Expression) ,public com.lealone.db.value.Value[] createRow() ,public com.lealone.db.result.LocalResult getLocalResult() ,public boolean isStopped() ,public void onLockedException() ,public void run() ,public void start() ,public void stop() ,public boolean yieldIfNeeded(int) <variables>protected int columnCount,protected final non-sealed com.lealone.sql.expression.evaluator.ExpressionEvaluator conditionEvaluator,protected long limitRows,protected com.lealone.db.result.LocalResult localResult,protected int loopCount,protected boolean loopEnd,protected int maxRows,protected com.lealone.db.result.ResultTarget result,protected int rowCount,protected int sampleSize,protected final non-sealed com.lealone.sql.query.Select select,protected final non-sealed com.lealone.db.session.ServerSession session,protected final non-sealed com.lealone.sql.optimizer.TableIterator tableIterator,protected com.lealone.db.result.ResultTarget target,protected com.lealone.sql.query.YieldableSelect yieldableSelect