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

taosdata / TDengine / #4983

13 Mar 2026 03:38AM UTC coverage: 68.653% (+0.07%) from 68.587%
#4983

push

travis-ci

web-flow
feat/6641435300-save-audit-in-self (#34738)

434 of 584 new or added lines in 10 files covered. (74.32%)

434 existing lines in 121 files now uncovered.

212745 of 309883 relevant lines covered (68.65%)

134272959.11 hits per line

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

79.64
/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,
92,735,374✔
77
                                    SOperatorInfo** pOptrInfo) {
78
  QRY_PARAM_CHECK(pOptrInfo);
92,735,374✔
79

80
  int32_t    lino = 0;
92,752,366✔
81
  int32_t    code = 0;
92,752,366✔
82
  int32_t    num = 0;
92,752,366✔
83
  SExprInfo* pExprInfo = NULL;
92,761,268✔
84
  int32_t    numOfScalarExpr = 0;
92,749,123✔
85
  SExprInfo* pScalarExprInfo = NULL;
92,756,345✔
86

87
  SAggOperatorInfo* pInfo = taosMemoryCalloc(1, sizeof(SAggOperatorInfo));
92,749,884✔
88
  SOperatorInfo*    pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo));
92,648,311✔
89
  if (pInfo == NULL || pOperator == NULL) {
92,647,800✔
90
    code = terrno;
1,028✔
91
    goto _error;
×
92
  }
93

94
  pOperator->exprSupp.hasWindowOrGroup = false;
92,646,772✔
95

96
  SSDataBlock* pResBlock = createDataBlockFromDescNode(pAggNode->node.pOutputDataBlockDesc);
92,669,416✔
97
  QUERY_CHECK_NULL(pResBlock, code, lino, _error, terrno);
92,780,339✔
98
  initBasicInfo(&pInfo->binfo, pResBlock);
92,780,339✔
99

100
  size_t keyBufSize = sizeof(int64_t) + sizeof(int64_t) + POINTER_BYTES;
92,745,771✔
101
  initResultSizeInfo(&pOperator->resultInfo, 4096);
92,745,771✔
102

103

104
  code = createExprInfo(pAggNode->pAggFuncs, pAggNode->pGroupKeys, &pExprInfo, &num);
92,766,183✔
105
  TSDB_CHECK_CODE(code, lino, _error);
92,739,431✔
106

107
  code = initAggSup(&pOperator->exprSupp, &pInfo->aggSup, pExprInfo, num, keyBufSize, pTaskInfo->id.str,
92,739,431✔
108
                               NULL, &pTaskInfo->storageAPI.functionStore);
109
  TSDB_CHECK_CODE(code, lino, _error);
92,709,158✔
110

111
  if (pAggNode->pExprs != NULL) {
92,709,158✔
112
    code = createExprInfo(pAggNode->pExprs, NULL, &pScalarExprInfo, &numOfScalarExpr);
19,433,522✔
113
    TSDB_CHECK_CODE(code, lino, _error);
19,433,284✔
114
  }
115

116
  code = initExprSupp(&pInfo->scalarExprSup, pScalarExprInfo, numOfScalarExpr, &pTaskInfo->storageAPI.functionStore);
92,696,304✔
117
  TSDB_CHECK_CODE(code, lino, _error);
92,704,596✔
118

119
  code = filterInitFromNode((SNode*)pAggNode->node.pConditions, &pOperator->exprSupp.pFilterInfo, 0,
92,715,397✔
120
                            GET_STM_RTINFO(pTaskInfo));
92,704,596✔
121
  TSDB_CHECK_CODE(code, lino, _error);
92,674,553✔
122

123
  pInfo->binfo.mergeResultBlock = pAggNode->mergeDataBlock;
92,674,553✔
124
  pInfo->groupKeyOptimized = pAggNode->groupKeyOptimized;
92,742,232✔
125
  pInfo->groupId = UINT64_MAX;
92,689,187✔
126
  pInfo->binfo.inputTsOrder = pAggNode->node.inputTsOrder;
92,710,214✔
127
  pInfo->binfo.outputTsOrder = pAggNode->node.outputTsOrder;
92,685,104✔
128
  pInfo->hasCountFunc = pAggNode->hasCountLikeFunc;
92,713,774✔
129
  pInfo->pOperator = pOperator;
92,684,074✔
130
  pInfo->cleanGroupResInfo = false;
92,651,120✔
131

132
  setOperatorInfo(pOperator, "TableAggregate", QUERY_NODE_PHYSICAL_PLAN_HASH_AGG,
92,730,016✔
133
                  !pAggNode->node.forceCreateNonBlockingOptr, OP_NOT_OPENED, pInfo, pTaskInfo);
92,715,983✔
134
  pOperator->fpSet = createOperatorFpSet(optrDummyOpenFn, getAggregateResultNext, NULL, destroyAggOperatorInfo,
92,697,503✔
135
                                         optrDefaultBufFn, NULL, optrDefaultGetNextExtFn, NULL);
136
  setOperatorResetStateFn(pOperator, resetAggregateOperatorState);
92,686,754✔
137

138
  pOperator->pPhyNode = pAggNode;
92,703,533✔
139

140
  if (downstream->operatorType == QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN) {
92,727,412✔
141
    STableScanInfo* pTableScanInfo = downstream->info;
54,246,378✔
142
    pTableScanInfo->base.pdInfo.pExprSup = &pOperator->exprSupp;
54,263,115✔
143
    pTableScanInfo->base.pdInfo.pAggSup = &pInfo->aggSup;
54,263,418✔
144
  }
145

146
  code = appendDownstream(pOperator, &downstream, 1);
92,670,434✔
147
  if (code != TSDB_CODE_SUCCESS) {
92,669,017✔
148
    goto _error;
×
149
  }
150

151
  *pOptrInfo = pOperator;
92,669,017✔
152
  return TSDB_CODE_SUCCESS;
92,695,542✔
153

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

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

171
  if (pInfo->pOperator) {
92,780,108✔
172
    cleanupResultInfo(pInfo->pOperator->pTaskInfo, &pInfo->pOperator->exprSupp, &pInfo->groupResInfo, &pInfo->aggSup,
92,763,629✔
173
                      pInfo->cleanGroupResInfo);
92,763,337✔
174
    pInfo->pOperator = NULL;
92,737,790✔
175
  }
176
  cleanupAggSup(&pInfo->aggSup);
92,763,304✔
177
  cleanupExprSuppWithoutFilter(&pInfo->scalarExprSup);
92,769,500✔
178
  cleanupGroupResInfo(&pInfo->groupResInfo);
92,749,677✔
179
  taosMemoryFreeClear(param);
92,774,815✔
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) {
112,464,578✔
190
  int32_t           code = TSDB_CODE_SUCCESS;
112,464,578✔
191
  int32_t           lino = 0;
112,464,578✔
192
  SExecTaskInfo*    pTaskInfo = pOperator->pTaskInfo;
112,464,578✔
193
  SAggOperatorInfo* pAggInfo = pOperator->info;
112,466,503✔
194

195
  if(!pAggInfo) {
112,463,580✔
196
    qError("function:%s, pAggInfo is NULL", __func__);
×
197
    return false;
×
198
  }
199
  if (pOperator->blocking && pAggInfo->hasValidBlock) {
112,463,580✔
200
    return false;
9,851,206✔
201
  }
202

203
  SExprSupp*   pSup = &pOperator->exprSupp;
102,616,078✔
204
  int64_t      st = taosGetTimestampUs();
102,609,500✔
205
  int32_t      order = pAggInfo->binfo.inputTsOrder;
102,609,500✔
206
  SSDataBlock* pBlock = pAggInfo->pNewGroupBlock;
102,602,325✔
207

208
  pAggInfo->cleanGroupResInfo = false;
102,599,119✔
209
  if (pBlock) {
102,597,620✔
210
    pAggInfo->pNewGroupBlock = NULL;
706,201✔
211
    tSimpleHashClear(pAggInfo->aggSup.pResultRowHashTable);
706,201✔
212
    code = setExecutionContext(pOperator, pOperator->exprSupp.numOfExprs, pBlock->info.id.groupId);
706,201✔
213
    QUERY_CHECK_CODE(code, lino, _end);
706,201✔
214
    code = setInputDataBlock(pSup, pBlock, order, pBlock->info.scanFlag, true);
706,201✔
215
    QUERY_CHECK_CODE(code, lino, _end);
706,201✔
216

217
    code = doAggregateImpl(pOperator, pSup->pCtx);
706,201✔
218
    QUERY_CHECK_CODE(code, lino, _end);
720,840✔
219
  }
220
  while (1) {
579,441,681✔
221
    bool blockAllocated = false;
682,053,940✔
222
    pBlock = getNextBlockFromDownstreamRemainDetach(pOperator, 0);
682,053,940✔
223
    if (pBlock == NULL) {
680,363,906✔
224
      if (!pAggInfo->hasValidBlock) {
103,300,994✔
225
        code = createDataBlockForEmptyInput(pOperator, &pBlock);
24,855,022✔
226
        QUERY_CHECK_CODE(code, lino, _end);
24,851,999✔
227

228
        if (pBlock == NULL) {
24,851,999✔
229
          break;
21,732,148✔
230
        }
231
        blockAllocated = true;
3,119,851✔
232
      } else {
233
        break;
78,445,509✔
234
      }
235
    }
236
    pAggInfo->hasValidBlock = true;
580,182,763✔
237
    pAggInfo->binfo.pRes->info.scanFlag = pBlock->info.scanFlag;
580,218,895✔
238

239
    printDataBlock(pBlock, __func__, pTaskInfo->id.str, pTaskInfo->id.queryId);
580,235,595✔
240

241
    // there is an scalar expression that needs to be calculated before apply the group aggregation.
242
    if (pAggInfo->scalarExprSup.pExprInfo != NULL && !blockAllocated) {
580,196,801✔
243
      SExprSupp* pSup1 = &pAggInfo->scalarExprSup;
42,313,019✔
244
      code = projectApplyFunctions(pSup1->pExprInfo, pBlock, pBlock, pSup1->pCtx, pSup1->numOfExprs, NULL, GET_STM_RTINFO(pOperator->pTaskInfo));
42,315,843✔
245
      if (code != TSDB_CODE_SUCCESS) {
42,305,794✔
246
        destroyDataBlockForEmptyInput(blockAllocated, &pBlock);
33,428✔
247
        T_LONG_JMP(pTaskInfo->env, code);
33,428✔
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) {
580,190,066✔
252
      pAggInfo->pNewGroupBlock = pBlock;
719,139✔
253
      break;
719,139✔
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);
579,442,551✔
257
    if (code != TSDB_CODE_SUCCESS) {
579,425,756✔
258
      destroyDataBlockForEmptyInput(blockAllocated, &pBlock);
×
259
      T_LONG_JMP(pTaskInfo->env, code);
×
260
    }
261
    code = setInputDataBlock(pSup, pBlock, order, pBlock->info.scanFlag, true);
579,425,756✔
262
    if (code != TSDB_CODE_SUCCESS) {
579,457,719✔
263
      destroyDataBlockForEmptyInput(blockAllocated, &pBlock);
×
264
      T_LONG_JMP(pTaskInfo->env, code);
×
265
    }
266

267
    code = doAggregateImpl(pOperator, pSup->pCtx);
579,457,719✔
268
    if (code != TSDB_CODE_SUCCESS) {
579,433,029✔
269
      destroyDataBlockForEmptyInput(blockAllocated, &pBlock);
2,948✔
270
      T_LONG_JMP(pTaskInfo->env, code);
2,948✔
271
    }
272

273
    destroyDataBlockForEmptyInput(blockAllocated, &pBlock);
579,430,081✔
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) {
100,896,796✔
278
    T_LONG_JMP(pTaskInfo->env, pTaskInfo->code);
×
279
  }
280

281
  code = initGroupedResultInfo(&pAggInfo->groupResInfo, pAggInfo->aggSup.pResultRowHashTable, 0);
100,892,520✔
282
  QUERY_CHECK_CODE(code, lino, _end);
100,898,942✔
283
  pAggInfo->cleanGroupResInfo = true;
100,898,942✔
284

285
_end:
100,899,202✔
286
  if (code != TSDB_CODE_SUCCESS) {
100,899,105✔
287
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
1,773✔
288
    pTaskInfo->code = code;
1,773✔
289
    T_LONG_JMP(pTaskInfo->env, code);
×
290
  }
291
  return pBlock != NULL;
100,897,332✔
292
}
293

294
int32_t getAggregateResultNext(SOperatorInfo* pOperator, SSDataBlock** ppRes) {
186,659,602✔
295
  int32_t           code = TSDB_CODE_SUCCESS;
186,659,602✔
296
  int32_t           lino = 0;
186,659,602✔
297
  SAggOperatorInfo* pAggInfo = pOperator->info;
186,659,602✔
298
  SOptrBasicInfo*   pInfo = &pAggInfo->binfo;
186,673,303✔
299

300
  if (pOperator->status == OP_EXEC_DONE && !pOperator->pOperatorGetParam) {
186,670,117✔
301
    (*ppRes) = NULL;
74,209,828✔
302
    return code;
74,208,089✔
303
  }
304

305
  if (pOperator->pOperatorGetParam) {
112,455,958✔
306
    if (pOperator->status == OP_EXEC_DONE) {
8,576,568✔
307
      pOperator->status = OP_OPENED;
5,434,544✔
308
      tSimpleHashClear(pAggInfo->aggSup.pResultRowHashTable);
5,432,255✔
309
      pAggInfo->groupId = UINT64_MAX;
5,434,544✔
310
      pAggInfo->hasValidBlock = false;
5,434,904✔
311
    }
312
    freeOperatorParam(pOperator->pOperatorGetParam, OP_GET_PARAM);
8,573,396✔
313
    pOperator->pOperatorGetParam = NULL;
8,575,238✔
314

315
  }
316

317
  SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
112,450,942✔
318
  bool           hasNewGroups = false;
112,462,442✔
319
  do {
320
    hasNewGroups = nextGroupedResult(pOperator);
112,473,941✔
321
    code = blockDataEnsureCapacity(pInfo->pRes, pOperator->resultInfo.capacity);
110,746,551✔
322
    QUERY_CHECK_CODE(code, lino, _end);
110,755,424✔
323

324
    while (1) {
325
      doBuildResultDatablock(pOperator, pInfo, &pAggInfo->groupResInfo, pAggInfo->aggSup.pResultBuf);
110,755,424✔
326
      code = doFilter(pInfo->pRes, pOperator->exprSupp.pFilterInfo, NULL, NULL);
110,754,170✔
327
      QUERY_CHECK_CODE(code, lino, _end);
110,755,070✔
328

329
      if (!hasRemainResults(&pAggInfo->groupResInfo)) {
110,755,070✔
330
        if (!hasNewGroups) setOperatorCompleted(pOperator);
100,896,668✔
331
        break;
100,899,508✔
332
      }
333

334
      if (pInfo->pRes->info.rows > 0) {
9,858,516✔
335
        break;
9,858,516✔
336
      }
337
    }
338
  } while (pInfo->pRes->info.rows == 0 && hasNewGroups);
110,758,024✔
339

340
  size_t rows = blockDataGetNumOfRows(pInfo->pRes);
110,745,756✔
341
  pOperator->resultInfo.totalRows += rows;
110,744,212✔
342

343
_end:
110,740,291✔
344
  if (code != TSDB_CODE_SUCCESS) {
110,740,291✔
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);
110,740,291✔
351

352
  (*ppRes) = (rows == 0) ? NULL : pInfo->pRes;
110,737,249✔
353
  return code;
110,738,009✔
354
}
355

356
int32_t doAggregateImpl(SOperatorInfo* pOperator, SqlFunctionCtx* pCtx) {
580,156,060✔
357
  int32_t code = TSDB_CODE_SUCCESS;
580,156,060✔
358
  if (!pOperator || (pOperator->exprSupp.numOfExprs > 0 && pCtx == NULL)) {
580,156,060✔
359
    qError("%s failed at line %d since pCtx is NULL.", __func__, __LINE__);
3,757✔
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,029,405✔
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,948✔
378
          pCtx[k].fpSet.cleanup(&pCtx[k]);
×
379
        }
380
        qError("%s aggregate function error happens, code:%s", GET_TASKID(pOperator->pTaskInfo), tstrerror(code));
2,948✔
381
        return code;
2,948✔
382
      }
383
    }
384
  }
385

386
  return TSDB_CODE_SUCCESS;
580,168,049✔
387
}
388

389
static int32_t createDataBlockForEmptyInput(SOperatorInfo* pOperator, SSDataBlock** ppBlock) {
24,853,233✔
390
  int32_t code = TSDB_CODE_SUCCESS;
24,853,233✔
391
  int32_t lino = 0;
24,853,233✔
392
  SSDataBlock* pBlock = NULL;
24,853,233✔
393
  if (!tsCountAlwaysReturnValue) {
24,855,545✔
394
    return TSDB_CODE_SUCCESS;
6,312,443✔
395
  }
396

397
  SAggOperatorInfo* pAggInfo = pOperator->info;
18,543,102✔
398
  if (pAggInfo->groupKeyOptimized) {
18,536,214✔
399
    return TSDB_CODE_SUCCESS;
5,985,013✔
400
  }
401

402
  SOperatorInfo* downstream = pOperator->pDownstream[0];
12,552,188✔
403
  if (downstream->operatorType == QUERY_NODE_PHYSICAL_PLAN_PARTITION ||
12,555,414✔
404
      downstream->operatorType == QUERY_NODE_PHYSICAL_PLAN_SORT ||
12,517,180✔
405
      (downstream->operatorType == QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN &&
12,487,591✔
406
       ((STableScanInfo*)downstream->info)->hasGroupByTag == true)) {
3,921,125✔
407
    return TSDB_CODE_SUCCESS;
65,510✔
408
  }
409

410
  SqlFunctionCtx* pCtx = pOperator->exprSupp.pCtx;
12,490,839✔
411

412
  if (!pAggInfo->hasCountFunc) {
12,483,498✔
413
    return TSDB_CODE_SUCCESS;
9,366,899✔
414
  }
415

416
  code = createDataBlock(&pBlock);
3,120,865✔
417
  if (code) {
3,119,563✔
418
    return code;
×
419
  }
420

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

424
  for (int32_t i = 0; i < pOperator->exprSupp.numOfExprs; ++i) {
8,864,675✔
425
    SColumnInfoData colInfo = {0};
5,744,965✔
426
    colInfo.hasNull = true;
5,745,616✔
427
    colInfo.info.type = TSDB_DATA_TYPE_NULL;
5,745,616✔
428
    colInfo.info.bytes = 1;
5,745,616✔
429

430
    SExprInfo* pOneExpr = &pOperator->exprSupp.pExprInfo[i];
5,745,616✔
431
    for (int32_t j = 0; j < pOneExpr->base.numOfParams; ++j) {
11,712,846✔
432
      SFunctParam* pFuncParam = &pOneExpr->base.pParam[j];
5,969,036✔
433
      if (pFuncParam->type == FUNC_PARAM_TYPE_COLUMN) {
5,968,385✔
434
        int32_t slotId = pFuncParam->pCol->slotId;
5,965,992✔
435
        int32_t numOfCols = taosArrayGetSize(pBlock->pDataBlock);
5,965,992✔
436
        if (slotId >= numOfCols) {
5,966,643✔
437
          code = taosArrayEnsureCap(pBlock->pDataBlock, slotId + 1);
3,552,384✔
438
          QUERY_CHECK_CODE(code, lino, _end);
3,551,229✔
439

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

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

454
  for (int32_t i = 0; i < blockDataGetNumOfCols(pBlock); ++i) {
9,189,906✔
455
    SColumnInfoData* pColInfoData = taosArrayGet(pBlock->pDataBlock, i);
6,069,545✔
456
    QUERY_CHECK_NULL(pColInfoData, code, lino, _end, terrno);
6,069,041✔
457
    colDataSetNULL(pColInfoData, 0);
458
  }
459
  *ppBlock = pBlock;
3,120,361✔
460

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

469
void destroyDataBlockForEmptyInput(bool blockAllocated, SSDataBlock** ppBlock) {
579,464,240✔
470
  if (!blockAllocated) {
579,464,240✔
471
    return;
576,363,600✔
472
  }
473

474
  blockDataDestroy(*ppBlock);
3,100,640✔
475
  *ppBlock = NULL;
3,119,059✔
476
}
477

478
int32_t setExecutionContext(SOperatorInfo* pOperator, int32_t numOfOutput, uint64_t groupId) {
580,144,558✔
479
  int32_t           code = TSDB_CODE_SUCCESS;
580,144,558✔
480
  SAggOperatorInfo* pAggInfo = pOperator->info;
580,144,558✔
481
  if (pAggInfo->groupId != UINT64_MAX && pAggInfo->groupId == groupId) {
580,197,395✔
482
    return code;
427,182,258✔
483
  }
484

485
  code = doSetTableGroupOutputBuf(pOperator, numOfOutput, groupId);
152,992,927✔
486

487
  // record the current active group id
488
  pAggInfo->groupId = groupId;
152,994,054✔
489
  return code;
153,001,368✔
490
}
491

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

499
  SResultRowInfo* pResultRowInfo = &pAggInfo->binfo.resultRowInfo;
153,013,433✔
500
  SqlFunctionCtx* pCtx = pOperator->exprSupp.pCtx;
152,990,706✔
501
  int32_t*        rowEntryInfoOffset = pOperator->exprSupp.rowEntryInfoOffset;
152,994,500✔
502

503
  SResultRow* pResultRow =
504
      doSetResultOutBufByKey(pAggInfo->aggSup.pResultBuf, pResultRowInfo, (char*)&groupId, sizeof(groupId), true,
153,017,367✔
505
                             groupId, pTaskInfo, false, &pAggInfo->aggSup, true);
506
  if (pResultRow == NULL || pTaskInfo->code != 0) {
152,993,461✔
507
    code = pTaskInfo->code;
28,489✔
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) {
152,978,097✔
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);
153,003,194✔
521
  QUERY_CHECK_CODE(code, lino, _end);
153,002,826✔
522

523
_end:
153,002,826✔
524
  if (code != TSDB_CODE_SUCCESS) {
153,002,826✔
525
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
×
526
  }
527
  return code;
152,996,202✔
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,
288,331,372✔
588
                         const char* pKey) {
589
  int32_t code = 0;
288,331,372✔
590
  //  _hash_fn_t hashFn = taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY);
591

592
  pAggSup->currentPageId = -1;
288,331,372✔
593
  pAggSup->resultRowSize = getResultRowSize(pCtx, numOfOutput);
288,327,338✔
594
  pAggSup->keyBuf = taosMemoryCalloc(1, keyBufSize + POINTER_BYTES + sizeof(int64_t));
288,338,110✔
595
  pAggSup->pResultRowHashTable = tSimpleHashInit(100, taosFastHash);
288,263,454✔
596

597
  if (pAggSup->keyBuf == NULL || pAggSup->pResultRowHashTable == NULL) {
288,251,244✔
598
    return terrno;
44,249✔
599
  }
600

601
  uint32_t defaultPgsz = 0;
288,217,941✔
602
  int64_t defaultBufsz = 0;
288,285,564✔
603
  code = getBufferPgSize(pAggSup->resultRowSize, &defaultPgsz, &defaultBufsz);
288,330,503✔
604
  if (code) {
288,197,929✔
605
    qError("failed to get buff page size, rowSize:%d", pAggSup->resultRowSize);
×
606
    return code;
×
607
  }
608

609
  if (!osTempSpaceAvailable()) {
288,197,929✔
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);
288,317,709✔
616
  if (code != TSDB_CODE_SUCCESS) {
288,343,139✔
UNCOV
617
    qError("Create agg result buf failed since %s, %s", tstrerror(code), pKey);
×
618
    return code;
×
619
  }
620

621
  return code;
288,343,139✔
622
}
623

624
void cleanupResultInfoInGroupResInfo(SExecTaskInfo* pTaskInfo, SExprSupp* pSup, SDiskbasedBuf* pBuf,
100,539,954✔
625
                                  SGroupResInfo* pGroupResInfo) {
626
  int32_t         numOfExprs = pSup->numOfExprs;
100,539,954✔
627
  int32_t*        rowEntryOffset = pSup->rowEntryInfoOffset;
100,544,670✔
628
  SqlFunctionCtx* pCtx = pSup->pCtx;
100,535,434✔
629
  int32_t         numOfRows = getNumOfTotalRes(pGroupResInfo);
100,517,495✔
630
  bool            needCleanup = false;
100,538,157✔
631

632
  for (int32_t j = 0; j < numOfExprs; ++j) {
109,106,807✔
633
    needCleanup |= pCtx[j].needCleanup;
8,569,216✔
634
  }
635
  if (!needCleanup) {
100,537,591✔
636
    return;
100,538,773✔
637
  }
638

UNCOV
639
  for (int32_t i = pGroupResInfo->index; i < numOfRows; i += 1) {
×
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,
35,718,654✔
661
                       SGroupResInfo* pGroupResInfo, SSHashObj* pHashmap) {
662
  int32_t         numOfExprs = pSup->numOfExprs;
35,718,654✔
663
  int32_t*        rowEntryOffset = pSup->rowEntryInfoOffset;
35,718,968✔
664
  SqlFunctionCtx* pCtx = pSup->pCtx;
35,716,808✔
665
  bool            needCleanup = false;
35,717,587✔
666
  for (int32_t j = 0; j < numOfExprs; ++j) {
43,950,383✔
667
    needCleanup |= pCtx[j].needCleanup;
8,231,434✔
668
  }
669
  if (!needCleanup) {
35,718,949✔
670
    return;
35,720,009✔
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,
136,259,556✔
699
                       SAggSupporter *pAggSup, bool cleanGroupResInfo) {
700
  if (cleanGroupResInfo) {
136,259,556✔
701
    cleanupResultInfoInGroupResInfo(pTaskInfo, pSup, pAggSup->pResultBuf, pGroupResInfo);
100,544,970✔
702
  } else {
703
    cleanupResultInfoInHashMap(pTaskInfo, pSup, pAggSup->pResultBuf, pGroupResInfo, pAggSup->pResultRowHashTable);
35,714,586✔
704
  }
705
}
136,234,960✔
706
void cleanupAggSup(SAggSupporter* pAggSup) {
288,778,262✔
707
  taosMemoryFreeClear(pAggSup->keyBuf);
288,778,262✔
708
  tSimpleHashCleanup(pAggSup->pResultRowHashTable);
288,781,382✔
709
  destroyDiskbasedBuf(pAggSup->pResultBuf);
288,776,434✔
710
  memset(pAggSup, 0, sizeof(SAggSupporter));
288,751,397✔
711
}
288,751,397✔
712

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

720
  code = doInitAggInfoSup(pAggSup, pSup->pCtx, numOfCols, keyBufSize, pkey);
288,247,054✔
721
  if (code != TSDB_CODE_SUCCESS) {
288,307,091✔
722
    return code;
×
723
  }
724

725
  for (int32_t i = 0; i < numOfCols; ++i) {
1,265,069,527✔
726
    pSup->pCtx[i].hasWindowOrGroup = pSup->hasWindowOrGroup;
976,921,980✔
727
    pSup->pCtx[i].hasWindow= pSup->hasWindow;
976,824,901✔
728
    if (pState) {
976,733,496✔
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;
976,733,496✔
734
    }
735
  }
736

737
  return TSDB_CODE_SUCCESS;
288,147,547✔
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]);
36,482,695✔
759
      char* p = GET_ROWCELL_INTERBUF(pEntryInfo);
36,483,367✔
760

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

763
      SValueNode *valueNode = (SValueNode *)nodesListGetNode(pCtx[k].pExpr->base.pParamList, 0);
36,491,987✔
764
      pEntryInfo->isNullRes = 0;
36,493,211✔
765
      if (TSDB_DATA_TYPE_NULL == valueNode->node.resType.type || valueNode->isNull) {
36,493,211✔
UNCOV
766
        pEntryInfo->isNullRes = 1;
×
767
      } else if (IS_VAR_DATA_TYPE(pCtx[k].pExpr->base.resSchema.type)){
36,492,987✔
768
        void* v = nodesGetValueFromNode(valueNode);
20,841✔
769
        memcpy(p, v, varDataTLen(v));
10,560✔
770
      } else {
771
        memcpy(p, nodesGetValueFromNode(valueNode), pCtx[k].pExpr->base.resSchema.bytes);
36,473,085✔
772
      }
773
      
774
      pEntryInfo->numOfRes = 1;
36,491,431✔
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) {
454✔
801
            pCtx[k].fpSet.cleanup(&pCtx[k]);
454✔
802
          }
803
          TAOS_CHECK_EXIT(code);
454✔
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));
454✔
816
    taskInfo->code = code;
454✔
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) {
5,172,565✔
835
  SAggOperatorInfo* pAgg = pOper->info;
5,172,565✔
836
  SAggPhysiNode*   pAggNode = (SAggPhysiNode*)pOper->pPhyNode;
5,173,930✔
837
  
838
  pOper->status = OP_NOT_OPENED;
5,172,940✔
839
  size_t keyBufSize = sizeof(int64_t) + sizeof(int64_t) + POINTER_BYTES;
5,172,716✔
840
  SExecTaskInfo*  pTaskInfo = pOper->pTaskInfo;
5,172,716✔
841
  cleanupResultInfo(pTaskInfo, &pOper->exprSupp, &pAgg->groupResInfo, &pAgg->aggSup,
5,173,591✔
842
                      pAgg->cleanGroupResInfo);
5,173,022✔
843
  cleanupGroupResInfo(&pAgg->groupResInfo);
5,173,170✔
844
  resetBasicOperatorState(&pAgg->binfo);
5,172,792✔
845
  
846
  pAgg->pNewGroupBlock = NULL;
5,174,351✔
847

848
  int32_t code = resetAggSup(&pOper->exprSupp, &pAgg->aggSup, pTaskInfo, pAggNode->pAggFuncs, pAggNode->pGroupKeys,
10,348,033✔
849
    keyBufSize, pTaskInfo->id.str, NULL, &pTaskInfo->storageAPI.functionStore);
5,173,249✔
850

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

856
  pAgg->groupId = UINT64_MAX;
5,173,926✔
857
  pAgg->cleanGroupResInfo = false;
5,173,926✔
858
  pAgg->hasValidBlock = false;
5,174,157✔
859
  return 0;
5,174,611✔
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