• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

taosdata / TDengine / #4979

09 Mar 2026 09:42AM UTC coverage: 68.512% (+0.07%) from 68.439%
#4979

push

travis-ci

web-flow
doc: update user manual. (#34693)

211961 of 309380 relevant lines covered (68.51%)

134839524.93 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

79.88
/source/libs/executor/src/aggregateoperator.c
1
/*
2
 * Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
3
 *
4
 * This program is free software: you can use, redistribute, and/or modify
5
 * it under the terms of the GNU Affero General Public License, version 3
6
 * or later ("AGPL"), as published by the Free Software Foundation.
7
 *
8
 * This program is distributed in the hope that it will be useful, but WITHOUT
9
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10
 * FITNESS FOR A PARTICULAR PURPOSE.
11
 *
12
 * You should have received a copy of the GNU Affero General Public License
13
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
14
 */
15

16
#include "filter.h"
17
#include "function.h"
18
#include "nodes.h"
19
#include "os.h"
20
#include "querynodes.h"
21
#include "tfill.h"
22
#include "tname.h"
23

24
#include "executorInt.h"
25
#include "index.h"
26
#include "operator.h"
27
#include "query.h"
28
#include "querytask.h"
29
#include "tcompare.h"
30
#include "tdatablock.h"
31
#include "tglobal.h"
32
#include "thash.h"
33
#include "ttypes.h"
34

35
typedef struct {
36
  bool    hasAgg;
37
  int32_t numOfRows;
38
  int32_t startOffset;
39
} SFunctionCtxStatus;
40

41
typedef struct SAggOperatorInfo {
42
  SOptrBasicInfo   binfo;
43
  SAggSupporter    aggSup;
44
  STableQueryInfo* current;
45
  uint64_t         groupId;
46
  SGroupResInfo    groupResInfo;
47
  SExprSupp        scalarExprSup;
48
  bool             groupKeyOptimized;
49
  bool             hasValidBlock;
50
  SSDataBlock*     pNewGroupBlock;
51
  bool             hasCountFunc;
52
  SOperatorInfo*   pOperator;
53
  bool             cleanGroupResInfo;
54
} SAggOperatorInfo;
55

56
static void destroyAggOperatorInfo(void* param);
57
static int32_t setExecutionContext(SOperatorInfo* pOperator, int32_t numOfOutput, uint64_t groupId);
58

59
static int32_t createDataBlockForEmptyInput(SOperatorInfo* pOperator, SSDataBlock** ppBlock);
60
static void    destroyDataBlockForEmptyInput(bool blockAllocated, SSDataBlock** ppBlock);
61

62
static int32_t doAggregateImpl(SOperatorInfo* pOperator, SqlFunctionCtx* pCtx);
63
static int32_t getAggregateResultNext(SOperatorInfo* pOperator, SSDataBlock** ppRes);
64
static int32_t doInitAggInfoSup(SAggSupporter* pAggSup, SqlFunctionCtx* pCtx, int32_t numOfOutput, size_t keyBufSize,
65
                                const char* pKey);
66

67
// static int32_t addNewResultRowBuf(SResultRow* pWindowRes, SDiskbasedBuf* pResultBuf, uint32_t size);
68

69
static int32_t doSetTableGroupOutputBuf(SOperatorInfo* pOperator, int32_t numOfOutput, uint64_t groupId);
70

71
static void functionCtxSave(SqlFunctionCtx* pCtx, SFunctionCtxStatus* pStatus);
72
static void functionCtxRestore(SqlFunctionCtx* pCtx, SFunctionCtxStatus* pStatus);
73

74
static int32_t resetAggregateOperatorState(SOperatorInfo* pOper);
75

76
int32_t createAggregateOperatorInfo(SOperatorInfo* downstream, SAggPhysiNode* pAggNode, SExecTaskInfo* pTaskInfo,
91,538,488✔
77
                                    SOperatorInfo** pOptrInfo) {
78
  QRY_PARAM_CHECK(pOptrInfo);
91,538,488✔
79

80
  int32_t    lino = 0;
91,553,881✔
81
  int32_t    code = 0;
91,553,881✔
82
  int32_t    num = 0;
91,553,881✔
83
  SExprInfo* pExprInfo = NULL;
91,552,568✔
84
  int32_t    numOfScalarExpr = 0;
91,547,166✔
85
  SExprInfo* pScalarExprInfo = NULL;
91,531,494✔
86

87
  SAggOperatorInfo* pInfo = taosMemoryCalloc(1, sizeof(SAggOperatorInfo));
91,527,530✔
88
  SOperatorInfo*    pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo));
91,451,044✔
89
  if (pInfo == NULL || pOperator == NULL) {
91,431,297✔
90
    code = terrno;
×
91
    goto _error;
×
92
  }
93

94
  pOperator->exprSupp.hasWindowOrGroup = false;
91,433,437✔
95

96
  SSDataBlock* pResBlock = createDataBlockFromDescNode(pAggNode->node.pOutputDataBlockDesc);
91,435,054✔
97
  QUERY_CHECK_NULL(pResBlock, code, lino, _error, terrno);
91,561,258✔
98
  initBasicInfo(&pInfo->binfo, pResBlock);
91,561,258✔
99

100
  size_t keyBufSize = sizeof(int64_t) + sizeof(int64_t) + POINTER_BYTES;
91,547,168✔
101
  initResultSizeInfo(&pOperator->resultInfo, 4096);
91,547,168✔
102

103

104
  code = createExprInfo(pAggNode->pAggFuncs, pAggNode->pGroupKeys, &pExprInfo, &num);
91,563,606✔
105
  TSDB_CHECK_CODE(code, lino, _error);
91,541,082✔
106

107
  code = initAggSup(&pOperator->exprSupp, &pInfo->aggSup, pExprInfo, num, keyBufSize, pTaskInfo->id.str,
183,090,045✔
108
                               pTaskInfo->streamInfo.pState, &pTaskInfo->storageAPI.functionStore);
91,546,786✔
109
  TSDB_CHECK_CODE(code, lino, _error);
91,510,772✔
110

111
  if (pAggNode->pExprs != NULL) {
91,510,772✔
112
    code = createExprInfo(pAggNode->pExprs, NULL, &pScalarExprInfo, &numOfScalarExpr);
18,894,742✔
113
    TSDB_CHECK_CODE(code, lino, _error);
18,889,773✔
114
  }
115

116
  code = initExprSupp(&pInfo->scalarExprSup, pScalarExprInfo, numOfScalarExpr, &pTaskInfo->storageAPI.functionStore);
91,496,492✔
117
  TSDB_CHECK_CODE(code, lino, _error);
91,473,683✔
118

119
  code = filterInitFromNode((SNode*)pAggNode->node.pConditions, &pOperator->exprSupp.pFilterInfo, 0,
91,420,394✔
120
                            GET_STM_RTINFO(pTaskInfo));
91,473,683✔
121
  TSDB_CHECK_CODE(code, lino, _error);
91,479,823✔
122

123
  pInfo->binfo.mergeResultBlock = pAggNode->mergeDataBlock;
91,479,823✔
124
  pInfo->groupKeyOptimized = pAggNode->groupKeyOptimized;
91,436,944✔
125
  pInfo->groupId = UINT64_MAX;
91,451,229✔
126
  pInfo->binfo.inputTsOrder = pAggNode->node.inputTsOrder;
91,460,140✔
127
  pInfo->binfo.outputTsOrder = pAggNode->node.outputTsOrder;
91,482,839✔
128
  pInfo->hasCountFunc = pAggNode->hasCountLikeFunc;
91,453,741✔
129
  pInfo->pOperator = pOperator;
91,453,607✔
130
  pInfo->cleanGroupResInfo = false;
91,459,362✔
131

132
  setOperatorInfo(pOperator, "TableAggregate", QUERY_NODE_PHYSICAL_PLAN_HASH_AGG,
91,484,494✔
133
                  !pAggNode->node.forceCreateNonBlockingOptr, OP_NOT_OPENED, pInfo, pTaskInfo);
91,457,043✔
134
  pOperator->fpSet = createOperatorFpSet(optrDummyOpenFn, getAggregateResultNext, NULL, destroyAggOperatorInfo,
91,478,201✔
135
                                         optrDefaultBufFn, NULL, optrDefaultGetNextExtFn, NULL);
136
  setOperatorResetStateFn(pOperator, resetAggregateOperatorState);
91,483,617✔
137

138
  pOperator->pPhyNode = pAggNode;
91,470,228✔
139

140
  if (downstream->operatorType == QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN) {
91,454,407✔
141
    STableScanInfo* pTableScanInfo = downstream->info;
54,577,133✔
142
    pTableScanInfo->base.pdInfo.pExprSup = &pOperator->exprSupp;
54,584,494✔
143
    pTableScanInfo->base.pdInfo.pAggSup = &pInfo->aggSup;
54,565,826✔
144
  }
145

146
  code = appendDownstream(pOperator, &downstream, 1);
91,460,460✔
147
  if (code != TSDB_CODE_SUCCESS) {
91,453,766✔
148
    goto _error;
×
149
  }
150

151
  *pOptrInfo = pOperator;
91,453,766✔
152
  return TSDB_CODE_SUCCESS;
91,451,620✔
153

154
_error:
18,190✔
155
  qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
18,190✔
156
  if (pInfo != NULL) {
18,190✔
157
    destroyAggOperatorInfo(pInfo);
18,190✔
158
  }
159
  destroyOperatorAndDownstreams(pOperator, &downstream, 1);
18,190✔
160
  pTaskInfo->code = code;
18,190✔
161
  return code;
18,190✔
162
}
163

164
void destroyAggOperatorInfo(void* param) {
91,564,874✔
165
  if (param == NULL) {
91,564,874✔
166
    return;
×
167
  }
168
  SAggOperatorInfo* pInfo = (SAggOperatorInfo*)param;
91,564,874✔
169
  cleanupBasicInfo(&pInfo->binfo);
91,564,874✔
170

171
  if (pInfo->pOperator) {
91,570,553✔
172
    cleanupResultInfo(pInfo->pOperator->pTaskInfo, &pInfo->pOperator->exprSupp, &pInfo->groupResInfo, &pInfo->aggSup,
91,543,908✔
173
                      pInfo->cleanGroupResInfo);
91,555,860✔
174
    pInfo->pOperator = NULL;
91,530,664✔
175
  }
176
  cleanupAggSup(&pInfo->aggSup);
91,549,252✔
177
  cleanupExprSuppWithoutFilter(&pInfo->scalarExprSup);
91,556,001✔
178
  cleanupGroupResInfo(&pInfo->groupResInfo);
91,533,891✔
179
  taosMemoryFreeClear(param);
91,556,785✔
180
}
181

182
/**
183
 * @brief get blocks from downstream and fill results into groupedRes after aggragation
184
 * @retval false if no more groups
185
 * @retval true if there could have new groups coming
186
 * @note if pOperator.blocking is true, scan all blocks from downstream, all groups are handled
187
 *       if false, fill results of ONE GROUP
188
 * */
189
static bool nextGroupedResult(SOperatorInfo* pOperator) {
110,520,949✔
190
  int32_t           code = TSDB_CODE_SUCCESS;
110,520,949✔
191
  int32_t           lino = 0;
110,520,949✔
192
  SExecTaskInfo*    pTaskInfo = pOperator->pTaskInfo;
110,520,949✔
193
  SAggOperatorInfo* pAggInfo = pOperator->info;
110,520,346✔
194

195
  if(!pAggInfo) {
110,489,075✔
196
    qError("function:%s, pAggInfo is NULL", __func__);
×
197
    return false;
×
198
  }
199
  if (pOperator->blocking && pAggInfo->hasValidBlock) {
110,489,075✔
200
    return false;
9,627,479✔
201
  }
202

203
  SExprSupp*   pSup = &pOperator->exprSupp;
100,862,196✔
204
  int64_t      st = taosGetTimestampUs();
100,881,220✔
205
  int32_t      order = pAggInfo->binfo.inputTsOrder;
100,881,220✔
206
  SSDataBlock* pBlock = pAggInfo->pNewGroupBlock;
100,883,983✔
207

208
  pAggInfo->cleanGroupResInfo = false;
100,876,485✔
209
  if (pBlock) {
100,876,614✔
210
    pAggInfo->pNewGroupBlock = NULL;
679,881✔
211
    tSimpleHashClear(pAggInfo->aggSup.pResultRowHashTable);
679,881✔
212
    code = setExecutionContext(pOperator, pOperator->exprSupp.numOfExprs, pBlock->info.id.groupId);
679,881✔
213
    QUERY_CHECK_CODE(code, lino, _end);
679,881✔
214
    code = setInputDataBlock(pSup, pBlock, order, pBlock->info.scanFlag, true);
679,881✔
215
    QUERY_CHECK_CODE(code, lino, _end);
679,881✔
216

217
    code = doAggregateImpl(pOperator, pSup->pCtx);
679,881✔
218
    QUERY_CHECK_CODE(code, lino, _end);
691,828✔
219
  }
220
  while (1) {
597,750,391✔
221
    bool blockAllocated = false;
698,638,868✔
222
    pBlock = getNextBlockFromDownstreamRemainDetach(pOperator, 0);
698,638,868✔
223
    if (pBlock == NULL) {
697,062,076✔
224
      if (!pAggInfo->hasValidBlock) {
101,775,606✔
225
        code = createDataBlockForEmptyInput(pOperator, &pBlock);
24,471,637✔
226
        QUERY_CHECK_CODE(code, lino, _end);
24,462,729✔
227

228
        if (pBlock == NULL) {
24,462,729✔
229
          break;
21,240,105✔
230
        }
231
        blockAllocated = true;
3,222,624✔
232
      } else {
233
        break;
77,305,408✔
234
      }
235
    }
236
    pAggInfo->hasValidBlock = true;
598,509,094✔
237
    pAggInfo->binfo.pRes->info.scanFlag = pBlock->info.scanFlag;
598,546,216✔
238

239
    printDataBlock(pBlock, __func__, pTaskInfo->id.str, pTaskInfo->id.queryId);
598,585,792✔
240

241
    // there is an scalar expression that needs to be calculated before apply the group aggregation.
242
    if (pAggInfo->scalarExprSup.pExprInfo != NULL && !blockAllocated) {
598,536,024✔
243
      SExprSupp* pSup1 = &pAggInfo->scalarExprSup;
76,898,056✔
244
      code = projectApplyFunctions(pSup1->pExprInfo, pBlock, pBlock, pSup1->pCtx, pSup1->numOfExprs, NULL, GET_STM_RTINFO(pOperator->pTaskInfo));
76,897,042✔
245
      if (code != TSDB_CODE_SUCCESS) {
76,851,285✔
246
        destroyDataBlockForEmptyInput(blockAllocated, &pBlock);
33,170✔
247
        T_LONG_JMP(pTaskInfo->env, code);
33,170✔
248
      }
249
    }
250
    // if non-blocking mode and new group arrived, save the block and break
251
    if (!pOperator->blocking && pAggInfo->groupId != UINT64_MAX && pBlock->info.id.groupId != pAggInfo->groupId) {
598,464,437✔
252
      pAggInfo->pNewGroupBlock = pBlock;
692,514✔
253
      break;
692,514✔
254
    }
255
    // the pDataBlock are always the same one, no need to call this again
256
    code = setExecutionContext(pOperator, pOperator->exprSupp.numOfExprs, pBlock->info.id.groupId);
597,754,110✔
257
    if (code != TSDB_CODE_SUCCESS) {
597,796,593✔
258
      destroyDataBlockForEmptyInput(blockAllocated, &pBlock);
×
259
      T_LONG_JMP(pTaskInfo->env, code);
×
260
    }
261
    code = setInputDataBlock(pSup, pBlock, order, pBlock->info.scanFlag, true);
597,796,593✔
262
    if (code != TSDB_CODE_SUCCESS) {
597,822,790✔
263
      destroyDataBlockForEmptyInput(blockAllocated, &pBlock);
×
264
      T_LONG_JMP(pTaskInfo->env, code);
×
265
    }
266

267
    code = doAggregateImpl(pOperator, pSup->pCtx);
597,822,790✔
268
    if (code != TSDB_CODE_SUCCESS) {
597,770,400✔
269
      destroyDataBlockForEmptyInput(blockAllocated, &pBlock);
2,936✔
270
      T_LONG_JMP(pTaskInfo->env, code);
2,936✔
271
    }
272

273
    destroyDataBlockForEmptyInput(blockAllocated, &pBlock);
597,767,464✔
274
  }
275

276
  // the downstream operator may return with error code, so let's check the code before generating results.
277
  if (pTaskInfo->code != TSDB_CODE_SUCCESS) {
99,238,027✔
278
    T_LONG_JMP(pTaskInfo->env, pTaskInfo->code);
×
279
  }
280

281
  code = initGroupedResultInfo(&pAggInfo->groupResInfo, pAggInfo->aggSup.pResultRowHashTable, 0);
99,235,342✔
282
  QUERY_CHECK_CODE(code, lino, _end);
99,240,324✔
283
  pAggInfo->cleanGroupResInfo = true;
99,240,324✔
284

285
_end:
99,236,819✔
286
  if (code != TSDB_CODE_SUCCESS) {
99,241,924✔
287
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
1,106✔
288
    pTaskInfo->code = code;
1,106✔
289
    T_LONG_JMP(pTaskInfo->env, code);
×
290
  }
291
  return pBlock != NULL;
99,241,362✔
292
}
293

294
int32_t getAggregateResultNext(SOperatorInfo* pOperator, SSDataBlock** ppRes) {
183,698,836✔
295
  int32_t           code = TSDB_CODE_SUCCESS;
183,698,836✔
296
  int32_t           lino = 0;
183,698,836✔
297
  SAggOperatorInfo* pAggInfo = pOperator->info;
183,698,836✔
298
  SOptrBasicInfo*   pInfo = &pAggInfo->binfo;
183,712,017✔
299

300
  if (pOperator->status == OP_EXEC_DONE && !pOperator->pOperatorGetParam) {
183,706,595✔
301
    (*ppRes) = NULL;
73,193,580✔
302
    return code;
73,190,795✔
303
  }
304

305
  if (pOperator->pOperatorGetParam) {
110,511,067✔
306
    if (pOperator->status == OP_EXEC_DONE) {
8,275,720✔
307
      pOperator->status = OP_OPENED;
5,250,929✔
308
      tSimpleHashClear(pAggInfo->aggSup.pResultRowHashTable);
5,252,471✔
309
      pAggInfo->groupId = UINT64_MAX;
5,254,645✔
310
      pAggInfo->hasValidBlock = false;
5,254,645✔
311
    }
312
    freeOperatorParam(pOperator->pOperatorGetParam, OP_GET_PARAM);
8,277,430✔
313
    pOperator->pOperatorGetParam = NULL;
8,275,795✔
314

315
  }
316

317
  SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
110,503,121✔
318
  bool           hasNewGroups = false;
110,501,777✔
319
  do {
320
    hasNewGroups = nextGroupedResult(pOperator);
110,512,838✔
321
    code = blockDataEnsureCapacity(pInfo->pRes, pOperator->resultInfo.capacity);
108,870,099✔
322
    QUERY_CHECK_CODE(code, lino, _end);
108,877,472✔
323

324
    while (1) {
325
      doBuildResultDatablock(pOperator, pInfo, &pAggInfo->groupResInfo, pAggInfo->aggSup.pResultBuf);
108,877,472✔
326
      code = doFilter(pInfo->pRes, pOperator->exprSupp.pFilterInfo, NULL, NULL);
108,872,403✔
327
      QUERY_CHECK_CODE(code, lino, _end);
108,874,311✔
328

329
      if (!hasRemainResults(&pAggInfo->groupResInfo)) {
108,874,311✔
330
        if (!hasNewGroups) setOperatorCompleted(pOperator);
99,243,094✔
331
        break;
99,243,037✔
332
      }
333

334
      if (pInfo->pRes->info.rows > 0) {
9,634,432✔
335
        break;
9,634,432✔
336
      }
337
    }
338
  } while (pInfo->pRes->info.rows == 0 && hasNewGroups);
108,877,469✔
339

340
  size_t rows = blockDataGetNumOfRows(pInfo->pRes);
108,865,115✔
341
  pOperator->resultInfo.totalRows += rows;
108,863,586✔
342

343
_end:
108,853,796✔
344
  if (code != TSDB_CODE_SUCCESS) {
108,853,796✔
345
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
×
346
    pTaskInfo->code = code;
×
347
    T_LONG_JMP(pTaskInfo->env, code);
×
348
  }
349

350
  printDataBlock(pInfo->pRes, __func__, pTaskInfo->id.str, pTaskInfo->id.queryId);
108,853,796✔
351

352
  (*ppRes) = (rows == 0) ? NULL : pInfo->pRes;
108,854,401✔
353
  return code;
108,856,705✔
354
}
355

356
int32_t doAggregateImpl(SOperatorInfo* pOperator, SqlFunctionCtx* pCtx) {
598,497,069✔
357
  int32_t code = TSDB_CODE_SUCCESS;
598,497,069✔
358
  if (!pOperator || (pOperator->exprSupp.numOfExprs > 0 && pCtx == NULL)) {
598,497,069✔
359
    qError("%s failed at line %d since pCtx is NULL.", __func__, __LINE__);
16,633✔
360
    return TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR;
×
361
  }
362
  for (int32_t k = 0; k < pOperator->exprSupp.numOfExprs; ++k) {
2,147,483,647✔
363
    if (functionNeedToExecute(&pCtx[k])) {
2,147,483,647✔
364
      // todo add a dummy function to avoid process check
365
      if (pCtx[k].fpSet.process == NULL) {
2,147,483,647✔
366
        continue;
9,399,667✔
367
      }
368

369
      if ((&pCtx[k])->input.pData[0] == NULL) {
2,147,483,647✔
370
        code = TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR;
×
371
        qError("%s aggregate function error happens, input data is NULL.", GET_TASKID(pOperator->pTaskInfo));
×
372
      } else {
373
        code = pCtx[k].fpSet.process(&pCtx[k]);
2,147,483,647✔
374
      }
375

376
      if (code != TSDB_CODE_SUCCESS) {
2,147,483,647✔
377
        if (pCtx[k].fpSet.cleanup != NULL) {
2,936✔
378
          pCtx[k].fpSet.cleanup(&pCtx[k]);
×
379
        }
380
        qError("%s aggregate function error happens, code:%s", GET_TASKID(pOperator->pTaskInfo), tstrerror(code));
2,936✔
381
        return code;
2,936✔
382
      }
383
    }
384
  }
385

386
  return TSDB_CODE_SUCCESS;
598,475,304✔
387
}
388

389
static int32_t createDataBlockForEmptyInput(SOperatorInfo* pOperator, SSDataBlock** ppBlock) {
24,469,585✔
390
  int32_t code = TSDB_CODE_SUCCESS;
24,469,585✔
391
  int32_t lino = 0;
24,469,585✔
392
  SSDataBlock* pBlock = NULL;
24,469,585✔
393
  if (!tsCountAlwaysReturnValue) {
24,468,971✔
394
    return TSDB_CODE_SUCCESS;
6,190,084✔
395
  }
396

397
  SAggOperatorInfo* pAggInfo = pOperator->info;
18,278,887✔
398
  if (pAggInfo->groupKeyOptimized) {
18,278,741✔
399
    return TSDB_CODE_SUCCESS;
5,974,616✔
400
  }
401

402
  SOperatorInfo* downstream = pOperator->pDownstream[0];
12,301,385✔
403
  if (downstream->operatorType == QUERY_NODE_PHYSICAL_PLAN_PARTITION ||
12,302,838✔
404
      downstream->operatorType == QUERY_NODE_PHYSICAL_PLAN_SORT ||
12,267,741✔
405
      (downstream->operatorType == QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN &&
12,256,522✔
406
       ((STableScanInfo*)downstream->info)->hasGroupByTag == true)) {
4,121,205✔
407
    return TSDB_CODE_SUCCESS;
49,125✔
408
  }
409

410
  SqlFunctionCtx* pCtx = pOperator->exprSupp.pCtx;
12,251,361✔
411

412
  if (!pAggInfo->hasCountFunc) {
12,254,501✔
413
    return TSDB_CODE_SUCCESS;
9,028,381✔
414
  }
415

416
  code = createDataBlock(&pBlock);
3,222,227✔
417
  if (code) {
3,224,053✔
418
    return code;
×
419
  }
420

421
  pBlock->info.rows = 1;
3,224,053✔
422
  pBlock->info.capacity = 0;
3,224,053✔
423

424
  for (int32_t i = 0; i < pOperator->exprSupp.numOfExprs; ++i) {
8,937,998✔
425
    SColumnInfoData colInfo = {0};
5,714,501✔
426
    colInfo.hasNull = true;
5,713,945✔
427
    colInfo.info.type = TSDB_DATA_TYPE_NULL;
5,713,945✔
428
    colInfo.info.bytes = 1;
5,713,945✔
429

430
    SExprInfo* pOneExpr = &pOperator->exprSupp.pExprInfo[i];
5,713,945✔
431
    for (int32_t j = 0; j < pOneExpr->base.numOfParams; ++j) {
11,643,812✔
432
      SFunctParam* pFuncParam = &pOneExpr->base.pParam[j];
5,931,693✔
433
      if (pFuncParam->type == FUNC_PARAM_TYPE_COLUMN) {
5,930,502✔
434
        int32_t slotId = pFuncParam->pCol->slotId;
5,928,200✔
435
        int32_t numOfCols = taosArrayGetSize(pBlock->pDataBlock);
5,927,565✔
436
        if (slotId >= numOfCols) {
5,927,009✔
437
          code = taosArrayEnsureCap(pBlock->pDataBlock, slotId + 1);
3,563,195✔
438
          QUERY_CHECK_CODE(code, lino, _end);
3,563,195✔
439

440
          for (int32_t k = numOfCols; k < slotId + 1; ++k) {
9,710,239✔
441
            void* tmp = taosArrayPush(pBlock->pDataBlock, &colInfo);
6,147,044✔
442
            QUERY_CHECK_NULL(tmp, code, lino, _end, terrno);
6,147,044✔
443
          }
444
        }
445
      } else if (pFuncParam->type == FUNC_PARAM_TYPE_VALUE) {
3,493✔
446
        // do nothing
447
      }
448
    }
449
  }
450

451
  code = blockDataEnsureCapacity(pBlock, pBlock->info.rows);
3,223,418✔
452
  QUERY_CHECK_CODE(code, lino, _end);
3,223,418✔
453

454
  for (int32_t i = 0; i < blockDataGetNumOfCols(pBlock); ++i) {
9,371,018✔
455
    SColumnInfoData* pColInfoData = taosArrayGet(pBlock->pDataBlock, i);
6,148,235✔
456
    QUERY_CHECK_NULL(pColInfoData, code, lino, _end, terrno);
6,148,235✔
457
    colDataSetNULL(pColInfoData, 0);
458
  }
459
  *ppBlock = pBlock;
3,223,418✔
460

461
_end:
3,223,418✔
462
  if (code != TSDB_CODE_SUCCESS) {
3,223,418✔
463
    blockDataDestroy(pBlock);
×
464
    qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(code));
×
465
  }
466
  return code;
3,222,783✔
467
}
468

469
void destroyDataBlockForEmptyInput(bool blockAllocated, SSDataBlock** ppBlock) {
597,769,601✔
470
  if (!blockAllocated) {
597,769,601✔
471
    return;
594,574,604✔
472
  }
473

474
  blockDataDestroy(*ppBlock);
3,194,997✔
475
  *ppBlock = NULL;
3,223,418✔
476
}
477

478
int32_t setExecutionContext(SOperatorInfo* pOperator, int32_t numOfOutput, uint64_t groupId) {
598,450,891✔
479
  int32_t           code = TSDB_CODE_SUCCESS;
598,450,891✔
480
  SAggOperatorInfo* pAggInfo = pOperator->info;
598,450,891✔
481
  if (pAggInfo->groupId != UINT64_MAX && pAggInfo->groupId == groupId) {
598,534,833✔
482
    return code;
424,680,938✔
483
  }
484

485
  code = doSetTableGroupOutputBuf(pOperator, numOfOutput, groupId);
173,849,549✔
486

487
  // record the current active group id
488
  pAggInfo->groupId = groupId;
173,834,027✔
489
  return code;
173,850,808✔
490
}
491

492
int32_t doSetTableGroupOutputBuf(SOperatorInfo* pOperator, int32_t numOfOutput, uint64_t groupId) {
173,847,605✔
493
  // for simple group by query without interval, all the tables belong to one group result.
494
  int32_t           code = TSDB_CODE_SUCCESS;
173,847,605✔
495
  int32_t           lino = 0;
173,847,605✔
496
  SExecTaskInfo*    pTaskInfo = pOperator->pTaskInfo;
173,847,605✔
497
  SAggOperatorInfo* pAggInfo = pOperator->info;
173,854,966✔
498

499
  SResultRowInfo* pResultRowInfo = &pAggInfo->binfo.resultRowInfo;
173,852,294✔
500
  SqlFunctionCtx* pCtx = pOperator->exprSupp.pCtx;
173,833,437✔
501
  int32_t*        rowEntryInfoOffset = pOperator->exprSupp.rowEntryInfoOffset;
173,844,356✔
502

503
  SResultRow* pResultRow =
504
      doSetResultOutBufByKey(pAggInfo->aggSup.pResultBuf, pResultRowInfo, (char*)&groupId, sizeof(groupId), true,
173,835,634✔
505
                             groupId, pTaskInfo, false, &pAggInfo->aggSup, true);
506
  if (pResultRow == NULL || pTaskInfo->code != 0) {
173,849,531✔
507
    code = pTaskInfo->code;
8,668✔
508
    lino = __LINE__;
×
509
    goto _end;
×
510
  }
511
  /*
512
   * not assign result buffer yet, add new result buffer
513
   * all group belong to one result set, and each group result has different group id so set the id to be one
514
   */
515
  if (pResultRow->pageId == -1) {
173,843,676✔
516
    code = addNewResultRowBuf(pResultRow, pAggInfo->aggSup.pResultBuf, pAggInfo->binfo.pRes->info.rowSize);
×
517
    QUERY_CHECK_CODE(code, lino, _end);
×
518
  }
519

520
  code = setResultRowInitCtx(pResultRow, pCtx, numOfOutput, rowEntryInfoOffset);
173,839,372✔
521
  QUERY_CHECK_CODE(code, lino, _end);
173,847,952✔
522

523
_end:
173,847,952✔
524
  if (code != TSDB_CODE_SUCCESS) {
173,847,952✔
525
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
×
526
  }
527
  return code;
173,836,554✔
528
}
529

530
// a new buffer page for each table. Needs to opt this design
531
int32_t addNewResultRowBuf(SResultRow* pWindowRes, SDiskbasedBuf* pResultBuf, uint32_t size) {
×
532
  if (pWindowRes->pageId != -1) {
×
533
    return 0;
×
534
  }
535

536
  SFilePage* pData = NULL;
×
537

538
  // in the first scan, new space needed for results
539
  int32_t pageId = -1;
×
540
  SArray* list = getDataBufPagesIdList(pResultBuf);
×
541

542
  if (taosArrayGetSize(list) == 0) {
×
543
    pData = getNewBufPage(pResultBuf, &pageId);
×
544
    if (pData == NULL) {
×
545
      qError("failed to get buffer, code:%s", tstrerror(terrno));
×
546
      return terrno;
×
547
    }
548
    pData->num = sizeof(SFilePage);
×
549
  } else {
550
    SPageInfo* pi = getLastPageInfo(list);
×
551
    pData = getBufPage(pResultBuf, getPageId(pi));
×
552
    if (pData == NULL) {
×
553
      qError("failed to get buffer, code:%s", tstrerror(terrno));
×
554
      return terrno;
×
555
    }
556

557
    pageId = getPageId(pi);
×
558

559
    if (pData->num + size > getBufPageSize(pResultBuf)) {
×
560
      // release current page first, and prepare the next one
561
      releaseBufPageInfo(pResultBuf, pi);
×
562

563
      pData = getNewBufPage(pResultBuf, &pageId);
×
564
      if (pData == NULL) {
×
565
        qError("failed to get buffer, code:%s", tstrerror(terrno));
×
566
        return terrno;
×
567
      }
568
      pData->num = sizeof(SFilePage);
×
569
    }
570
  }
571

572
  if (pData == NULL) {
×
573
    return -1;
×
574
  }
575

576
  // set the number of rows in current disk page
577
  if (pWindowRes->pageId == -1) {  // not allocated yet, allocate new buffer
×
578
    pWindowRes->pageId = pageId;
×
579
    pWindowRes->offset = (int32_t)pData->num;
×
580

581
    pData->num += size;
×
582
  }
583

584
  return 0;
×
585
}
586

587
int32_t doInitAggInfoSup(SAggSupporter* pAggSup, SqlFunctionCtx* pCtx, int32_t numOfOutput, size_t keyBufSize,
281,511,794✔
588
                         const char* pKey) {
589
  int32_t code = 0;
281,511,794✔
590
  //  _hash_fn_t hashFn = taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY);
591

592
  pAggSup->currentPageId = -1;
281,511,794✔
593
  pAggSup->resultRowSize = getResultRowSize(pCtx, numOfOutput);
281,562,145✔
594
  pAggSup->keyBuf = taosMemoryCalloc(1, keyBufSize + POINTER_BYTES + sizeof(int64_t));
281,403,744✔
595
  pAggSup->pResultRowHashTable = tSimpleHashInit(100, taosFastHash);
281,493,709✔
596

597
  if (pAggSup->keyBuf == NULL || pAggSup->pResultRowHashTable == NULL) {
281,433,645✔
598
    return terrno;
30✔
599
  }
600

601
  uint32_t defaultPgsz = 0;
281,462,285✔
602
  int64_t defaultBufsz = 0;
281,449,082✔
603
  code = getBufferPgSize(pAggSup->resultRowSize, &defaultPgsz, &defaultBufsz);
281,436,086✔
604
  if (code) {
281,360,726✔
605
    qError("failed to get buff page size, rowSize:%d", pAggSup->resultRowSize);
×
606
    return code;
×
607
  }
608

609
  if (!osTempSpaceAvailable()) {
281,360,726✔
610
    code = TSDB_CODE_NO_DISKSPACE;
×
611
    qError("Init stream agg supporter failed since %s, key:%s, tempDir:%s", tstrerror(code), pKey, tsTempDir);
×
612
    return code;
×
613
  }
614

615
  code = createDiskbasedBuf(&pAggSup->pResultBuf, defaultPgsz, defaultBufsz, pKey, tsTempDir);
281,514,000✔
616
  if (code != TSDB_CODE_SUCCESS) {
281,519,557✔
617
    qError("Create agg result buf failed since %s, %s", tstrerror(code), pKey);
×
618
    return code;
×
619
  }
620

621
  return code;
281,519,557✔
622
}
623

624
void cleanupResultInfoInGroupResInfo(SExecTaskInfo* pTaskInfo, SExprSupp* pSup, SDiskbasedBuf* pBuf,
99,069,147✔
625
                                  SGroupResInfo* pGroupResInfo) {
626
  int32_t         numOfExprs = pSup->numOfExprs;
99,069,147✔
627
  int32_t*        rowEntryOffset = pSup->rowEntryInfoOffset;
99,082,049✔
628
  SqlFunctionCtx* pCtx = pSup->pCtx;
99,073,380✔
629
  int32_t         numOfRows = getNumOfTotalRes(pGroupResInfo);
99,074,089✔
630
  bool            needCleanup = false;
99,059,886✔
631

632
  for (int32_t j = 0; j < numOfExprs; ++j) {
106,794,576✔
633
    needCleanup |= pCtx[j].needCleanup;
7,735,123✔
634
  }
635
  if (!needCleanup) {
99,059,453✔
636
    return;
99,053,950✔
637
  }
638

639
  for (int32_t i = pGroupResInfo->index; i < numOfRows; i += 1) {
5,503✔
640
    SResultRow*        pRow = NULL;
×
641
    SResKeyPos*        pPos = taosArrayGetP(pGroupResInfo->pRows, i);
×
642
    SFilePage*         page = getBufPage(pBuf, pPos->pos.pageId);
×
643
    if (page == NULL) {
×
644
      qError("failed to get buffer, code:%s, %s", tstrerror(terrno), GET_TASKID(pTaskInfo));
×
645
      continue;
×
646
    }
647
    pRow = (SResultRow*)((char*)page + pPos->pos.offset);
×
648

649

650
    for (int32_t j = 0; j < numOfExprs; ++j) {
×
651
      pCtx[j].resultInfo = getResultEntryInfo(pRow, j, rowEntryOffset);
×
652
      if (pCtx[j].fpSet.cleanup) {
×
653
        pCtx[j].fpSet.cleanup(&pCtx[j]);
×
654
      }
655
    }
656
    releaseBufPage(pBuf, page);
×
657
  }
658
}
659

660
void cleanupResultInfoInHashMap(SExecTaskInfo* pTaskInfo, SExprSupp* pSup, SDiskbasedBuf* pBuf,
34,676,667✔
661
                       SGroupResInfo* pGroupResInfo, SSHashObj* pHashmap) {
662
  int32_t         numOfExprs = pSup->numOfExprs;
34,676,667✔
663
  int32_t*        rowEntryOffset = pSup->rowEntryInfoOffset;
34,673,930✔
664
  SqlFunctionCtx* pCtx = pSup->pCtx;
34,676,607✔
665
  bool            needCleanup = false;
34,671,796✔
666
  for (int32_t j = 0; j < numOfExprs; ++j) {
42,363,013✔
667
    needCleanup |= pCtx[j].needCleanup;
7,690,790✔
668
  }
669
  if (!needCleanup) {
34,672,223✔
670
    return;
34,672,694✔
671
  }
672

673
  // begin from last iter
674
  void*   pData = pGroupResInfo->dataPos;
×
675
  int32_t iter = pGroupResInfo->iter;
×
676
  while ((pData = tSimpleHashIterate(pHashmap, pData, &iter)) != NULL) {
×
677
    SResultRowPosition* pos = pData;
×
678

679
    SFilePage* page = getBufPage(pBuf, pos->pageId);
×
680
    if (page == NULL) {
×
681
      qError("failed to get buffer, code:%s, %s", tstrerror(terrno), GET_TASKID(pTaskInfo));
×
682
      continue;
×
683
    }
684

685
    SResultRow* pRow = (SResultRow*)((char*)page + pos->offset);
×
686

687
    for (int32_t j = 0; j < numOfExprs; ++j) {
×
688
      pCtx[j].resultInfo = getResultEntryInfo(pRow, j, rowEntryOffset);
×
689
      if (pCtx[j].fpSet.cleanup) {
×
690
        pCtx[j].fpSet.cleanup(&pCtx[j]);
×
691
      }
692
    }
693

694
    releaseBufPage(pBuf, page);
×
695
  }
696
}
697

698
void cleanupResultInfo(SExecTaskInfo* pTaskInfo, SExprSupp* pSup, SGroupResInfo* pGroupResInfo,
133,740,312✔
699
                       SAggSupporter *pAggSup, bool cleanGroupResInfo) {
700
  if (cleanGroupResInfo) {
133,740,312✔
701
    cleanupResultInfoInGroupResInfo(pTaskInfo, pSup, pAggSup->pResultBuf, pGroupResInfo);
99,070,437✔
702
  } else {
703
    cleanupResultInfoInHashMap(pTaskInfo, pSup, pAggSup->pResultBuf, pGroupResInfo, pAggSup->pResultRowHashTable);
34,669,875✔
704
  }
705
}
133,729,424✔
706
void cleanupAggSup(SAggSupporter* pAggSup) {
281,941,346✔
707
  taosMemoryFreeClear(pAggSup->keyBuf);
281,941,346✔
708
  tSimpleHashCleanup(pAggSup->pResultRowHashTable);
281,939,067✔
709
  destroyDiskbasedBuf(pAggSup->pResultBuf);
281,945,194✔
710
  memset(pAggSup, 0, sizeof(SAggSupporter));
281,923,981✔
711
}
281,923,981✔
712

713
int32_t initAggSup(SExprSupp* pSup, SAggSupporter* pAggSup, SExprInfo* pExprInfo, int32_t numOfCols, size_t keyBufSize,
281,534,132✔
714
                   const char* pkey, void* pState, SFunctionStateStore* pStore) {
715
  int32_t code = initExprSupp(pSup, pExprInfo, numOfCols, pStore);
281,534,132✔
716
  if (code != TSDB_CODE_SUCCESS) {
281,413,086✔
717
    return code;
×
718
  }
719

720
  code = doInitAggInfoSup(pAggSup, pSup->pCtx, numOfCols, keyBufSize, pkey);
281,413,086✔
721
  if (code != TSDB_CODE_SUCCESS) {
281,481,881✔
722
    return code;
×
723
  }
724

725
  for (int32_t i = 0; i < numOfCols; ++i) {
1,232,347,923✔
726
    pSup->pCtx[i].hasWindowOrGroup = pSup->hasWindowOrGroup;
950,938,836✔
727
    pSup->pCtx[i].hasWindow= pSup->hasWindow;
950,932,611✔
728
    if (pState) {
950,810,012✔
729
      pSup->pCtx[i].saveHandle.pBuf = NULL;
×
730
      pSup->pCtx[i].saveHandle.pState = pState;
×
731
      pSup->pCtx[i].exprIdx = i;
×
732
    } else {
733
      pSup->pCtx[i].saveHandle.pBuf = pAggSup->pResultBuf;
950,810,012✔
734
    }
735
  }
736

737
  return TSDB_CODE_SUCCESS;
281,409,087✔
738
}
739

740
int32_t applyAggFunctionOnPartialTuples(SExecTaskInfo* taskInfo, SqlFunctionCtx* pCtx, SColumnInfoData* pTimeWindowData,
2,147,483,647✔
741
                                        int32_t offset, int32_t forwardStep, int32_t numOfTotal, int32_t numOfOutput) {
742
  int32_t code = TSDB_CODE_SUCCESS, lino = 0;
2,147,483,647✔
743
  for (int32_t k = 0; k < numOfOutput; ++k) {
2,147,483,647✔
744
    // keep it temporarily
745
    SFunctionCtxStatus status = {0};
2,147,483,647✔
746
    functionCtxSave(&pCtx[k], &status);
2,147,483,647✔
747

748
    pCtx[k].input.startRowIndex = offset;
2,147,483,647✔
749
    pCtx[k].input.numOfRows = forwardStep;
2,147,483,647✔
750

751
    // not a whole block involved in query processing, statistics data can not be used
752
    // NOTE: the original value of isSet have been changed here
753
    if (pCtx[k].input.colDataSMAIsSet && forwardStep < numOfTotal) {
2,147,483,647✔
754
      pCtx[k].input.colDataSMAIsSet = false;
×
755
    }
756

757
    if (fmIsPlaceHolderFunc(pCtx[k].functionId)) {
2,147,483,647✔
758
      SResultRowEntryInfo* pEntryInfo = GET_RES_INFO(&pCtx[k]);
35,187,699✔
759
      char* p = GET_ROWCELL_INTERBUF(pEntryInfo);
35,189,879✔
760

761
      TAOS_CHECK_EXIT(fmSetStreamPseudoFuncParamVal(pCtx[k].functionId, pCtx[k].pExpr->base.pParamList, &taskInfo->pStreamRuntimeInfo->funcInfo));
35,191,405✔
762

763
      SValueNode *valueNode = (SValueNode *)nodesListGetNode(pCtx[k].pExpr->base.pParamList, 0);
35,204,033✔
764
      pEntryInfo->isNullRes = 0;
35,205,345✔
765
      if (TSDB_DATA_TYPE_NULL == valueNode->node.resType.type || valueNode->isNull) {
35,204,908✔
766
        pEntryInfo->isNullRes = 1;
327✔
767
      } else if (IS_VAR_DATA_TYPE(pCtx[k].pExpr->base.resSchema.type)){
35,206,333✔
768
        void* v = nodesGetValueFromNode(valueNode);
20,677✔
769
        memcpy(p, v, varDataTLen(v));
10,032✔
770
      } else {
771
        memcpy(p, nodesGetValueFromNode(valueNode), pCtx[k].pExpr->base.resSchema.bytes);
35,199,130✔
772
      }
773
      
774
      pEntryInfo->numOfRes = 1;
35,202,954✔
775
    } else if (pCtx[k].isPseudoFunc) {
2,147,483,647✔
776
      SResultRowEntryInfo* pEntryInfo = GET_RES_INFO(&pCtx[k]);
2,147,483,647✔
777

778
      char* p = GET_ROWCELL_INTERBUF(pEntryInfo);
2,147,483,647✔
779

780
      SColumnInfoData idata = {0};
2,147,483,647✔
781
      idata.info.type = TSDB_DATA_TYPE_BIGINT;
2,147,483,647✔
782
      idata.info.bytes = tDataTypes[TSDB_DATA_TYPE_BIGINT].bytes;
2,147,483,647✔
783
      idata.pData = p;
2,147,483,647✔
784

785
      SScalarParam out = {.columnData = &idata};
2,147,483,647✔
786
      SScalarParam tw = {.numOfRows = 5, .columnData = pTimeWindowData};
2,147,483,647✔
787
      TAOS_CHECK_EXIT(pCtx[k].sfp.process(&tw, 1, &out));
2,147,483,647✔
788
      pEntryInfo->isNullRes = colDataIsNull_s(&idata, 0);
2,147,483,647✔
789
      pEntryInfo->numOfRes = 1;
2,147,483,647✔
790
    } else {
791
      if (functionNeedToExecute(&pCtx[k]) && pCtx[k].fpSet.process != NULL) {
2,147,483,647✔
792
        if ((&pCtx[k])->input.pData[0] == NULL) {
2,147,483,647✔
793
          code = TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR;
×
794
          qError("%s apply functions error, input data is NULL.", GET_TASKID(taskInfo));
×
795
        } else {
796
          code = pCtx[k].fpSet.process(&pCtx[k]);
2,147,483,647✔
797
        }
798

799
        if (code != TSDB_CODE_SUCCESS) {
2,147,483,647✔
800
          if (pCtx[k].fpSet.cleanup != NULL) {
438✔
801
            pCtx[k].fpSet.cleanup(&pCtx[k]);
438✔
802
          }
803
          TAOS_CHECK_EXIT(code);
438✔
804
        }
805
      }
806

807
      // restore it
808
      functionCtxRestore(&pCtx[k], &status);
2,147,483,647✔
809
    }
810
  }
811

812
_exit:
2,147,483,647✔
813

814
  if (code) {
2,147,483,647✔
815
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
438✔
816
    taskInfo->code = code;
438✔
817
  }
818

819
  return code;
2,147,483,647✔
820
}
821

822
void functionCtxSave(SqlFunctionCtx* pCtx, SFunctionCtxStatus* pStatus) {
2,147,483,647✔
823
  pStatus->hasAgg = pCtx->input.colDataSMAIsSet;
2,147,483,647✔
824
  pStatus->numOfRows = pCtx->input.numOfRows;
2,147,483,647✔
825
  pStatus->startOffset = pCtx->input.startRowIndex;
2,147,483,647✔
826
}
2,147,483,647✔
827

828
void functionCtxRestore(SqlFunctionCtx* pCtx, SFunctionCtxStatus* pStatus) {
2,147,483,647✔
829
  pCtx->input.colDataSMAIsSet = pStatus->hasAgg;
2,147,483,647✔
830
  pCtx->input.numOfRows = pStatus->numOfRows;
2,147,483,647✔
831
  pCtx->input.startRowIndex = pStatus->startOffset;
2,147,483,647✔
832
}
2,147,483,647✔
833

834
static int32_t resetAggregateOperatorState(SOperatorInfo* pOper) {
4,708,103✔
835
  SAggOperatorInfo* pAgg = pOper->info;
4,708,103✔
836
  SAggPhysiNode*   pAggNode = (SAggPhysiNode*)pOper->pPhyNode;
4,708,745✔
837
  
838
  pOper->status = OP_NOT_OPENED;
4,708,967✔
839
  size_t keyBufSize = sizeof(int64_t) + sizeof(int64_t) + POINTER_BYTES;
4,708,967✔
840
  SExecTaskInfo*  pTaskInfo = pOper->pTaskInfo;
4,708,967✔
841
  cleanupResultInfo(pTaskInfo, &pOper->exprSupp, &pAgg->groupResInfo, &pAgg->aggSup,
4,708,745✔
842
                      pAgg->cleanGroupResInfo);
4,708,090✔
843
  cleanupGroupResInfo(&pAgg->groupResInfo);
4,708,312✔
844
  resetBasicOperatorState(&pAgg->binfo);
4,707,655✔
845
  
846
  pAgg->pNewGroupBlock = NULL;
4,709,194✔
847

848
  int32_t code = resetAggSup(&pOper->exprSupp, &pAgg->aggSup, pTaskInfo, pAggNode->pAggFuncs, pAggNode->pGroupKeys,
9,417,196✔
849
    keyBufSize, pTaskInfo->id.str, pTaskInfo->streamInfo.pState, &pTaskInfo->storageAPI.functionStore);
4,709,400✔
850

851
  if (code == 0) {
4,708,317✔
852
    code = resetExprSupp(&pAgg->scalarExprSup, pTaskInfo, pAggNode->pExprs, NULL,
4,708,317✔
853
                          &pTaskInfo->storageAPI.functionStore);
854
  }
855

856
  pAgg->groupId = UINT64_MAX;
4,709,186✔
857
  pAgg->cleanGroupResInfo = false;
4,709,186✔
858
  pAgg->hasValidBlock = false;
4,709,186✔
859
  return 0;
4,709,622✔
860
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc