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

taosdata / TDengine / #5002

24 Mar 2026 01:11AM UTC coverage: 72.671% (+0.4%) from 72.254%
#5002

push

travis-ci

web-flow
fix: possible memory leak in tdb; (#34872)

1 of 20 new or added lines in 2 files covered. (5.0%)

539 existing lines in 124 files now uncovered.

227507 of 313065 relevant lines covered (72.67%)

147556935.28 hits per line

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

79.15
/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,
90,505,343✔
77
                                    SOperatorInfo** pOptrInfo) {
78
  QRY_PARAM_CHECK(pOptrInfo);
90,505,343✔
79

80
  int32_t    lino = 0;
90,520,367✔
81
  int32_t    code = 0;
90,520,367✔
82
  int32_t    num = 0;
90,520,367✔
83
  SExprInfo* pExprInfo = NULL;
90,524,352✔
84
  int32_t    numOfScalarExpr = 0;
90,509,044✔
85
  SExprInfo* pScalarExprInfo = NULL;
90,499,419✔
86

87
  SAggOperatorInfo* pInfo = taosMemoryCalloc(1, sizeof(SAggOperatorInfo));
90,496,523✔
88
  SOperatorInfo*    pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo));
90,428,850✔
89
  if (pInfo == NULL || pOperator == NULL) {
90,441,572✔
UNCOV
90
    code = terrno;
×
91
    goto _error;
×
92
  }
93
  initOperatorCostInfo(pOperator);
90,453,985✔
94

95
  pOperator->exprSupp.hasWindowOrGroup = false;
90,531,654✔
96

97
  SSDataBlock* pResBlock = createDataBlockFromDescNode(pAggNode->node.pOutputDataBlockDesc);
90,527,133✔
98
  QUERY_CHECK_NULL(pResBlock, code, lino, _error, terrno);
90,544,963✔
99
  initBasicInfo(&pInfo->binfo, pResBlock);
90,544,963✔
100

101
  size_t keyBufSize = sizeof(int64_t) + sizeof(int64_t) + POINTER_BYTES;
90,505,896✔
102
  initResultSizeInfo(&pOperator->resultInfo, 4096);
90,505,896✔
103

104

105
  code = createExprInfo(pAggNode->pAggFuncs, pAggNode->pGroupKeys, &pExprInfo, &num);
90,522,086✔
106
  TSDB_CHECK_CODE(code, lino, _error);
90,499,762✔
107

108
  code = initAggSup(&pOperator->exprSupp, &pInfo->aggSup, pExprInfo, num, keyBufSize, pTaskInfo->id.str,
90,499,762✔
109
                               NULL, &pTaskInfo->storageAPI.functionStore);
110
  TSDB_CHECK_CODE(code, lino, _error);
90,475,704✔
111

112
  if (pAggNode->pExprs != NULL) {
90,475,704✔
113
    code = createExprInfo(pAggNode->pExprs, NULL, &pScalarExprInfo, &numOfScalarExpr);
17,419,775✔
114
    TSDB_CHECK_CODE(code, lino, _error);
17,417,215✔
115
  }
116

117
  code = initExprSupp(&pInfo->scalarExprSup, pScalarExprInfo, numOfScalarExpr, &pTaskInfo->storageAPI.functionStore);
90,467,794✔
118
  TSDB_CHECK_CODE(code, lino, _error);
90,440,057✔
119

120
  code = filterInitFromNode((SNode*)pAggNode->node.pConditions, &pOperator->exprSupp.pFilterInfo, 0,
90,448,007✔
121
                            GET_STM_RTINFO(pTaskInfo));
90,440,057✔
122
  TSDB_CHECK_CODE(code, lino, _error);
90,443,365✔
123

124
  pInfo->binfo.mergeResultBlock = pAggNode->mergeDataBlock;
90,443,365✔
125
  pInfo->groupKeyOptimized = pAggNode->groupKeyOptimized;
90,445,174✔
126
  pInfo->groupId = UINT64_MAX;
90,495,123✔
127
  pInfo->binfo.inputTsOrder = pAggNode->node.inputTsOrder;
90,425,578✔
128
  pInfo->binfo.outputTsOrder = pAggNode->node.outputTsOrder;
90,497,313✔
129
  pInfo->hasCountFunc = pAggNode->hasCountLikeFunc;
90,426,865✔
130
  pInfo->pOperator = pOperator;
90,502,806✔
131
  pInfo->cleanGroupResInfo = false;
90,453,069✔
132

133
  setOperatorInfo(pOperator, "TableAggregate", QUERY_NODE_PHYSICAL_PLAN_HASH_AGG,
90,419,740✔
134
                  !pAggNode->node.forceCreateNonBlockingOptr, OP_NOT_OPENED, pInfo, pTaskInfo);
90,420,849✔
135
  pOperator->fpSet = createOperatorFpSet(optrDummyOpenFn, getAggregateResultNext, NULL, destroyAggOperatorInfo,
90,485,544✔
136
                                         optrDefaultBufFn, NULL, optrDefaultGetNextExtFn, NULL);
137
  setOperatorResetStateFn(pOperator, resetAggregateOperatorState);
90,434,267✔
138

139
  pOperator->pPhyNode = pAggNode;
90,437,439✔
140

141
  if (downstream->operatorType == QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN) {
90,438,131✔
142
    STableScanInfo* pTableScanInfo = downstream->info;
51,630,372✔
143
    pTableScanInfo->base.pdInfo.pExprSup = &pOperator->exprSupp;
51,656,577✔
144
    pTableScanInfo->base.pdInfo.pAggSup = &pInfo->aggSup;
51,607,630✔
145
  }
146

147
  code = appendDownstream(pOperator, &downstream, 1);
90,453,926✔
148
  if (code != TSDB_CODE_SUCCESS) {
90,409,502✔
149
    goto _error;
×
150
  }
151

152
  *pOptrInfo = pOperator;
90,409,502✔
153
  return TSDB_CODE_SUCCESS;
90,410,467✔
154

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

165
void destroyAggOperatorInfo(void* param) {
90,536,597✔
166
  if (param == NULL) {
90,536,597✔
167
    return;
×
168
  }
169
  SAggOperatorInfo* pInfo = (SAggOperatorInfo*)param;
90,536,597✔
170
  cleanupBasicInfo(&pInfo->binfo);
90,536,597✔
171

172
  if (pInfo->pOperator) {
90,537,169✔
173
    cleanupResultInfo(pInfo->pOperator->pTaskInfo, &pInfo->pOperator->exprSupp, &pInfo->groupResInfo, &pInfo->aggSup,
90,520,154✔
174
                      pInfo->cleanGroupResInfo);
90,524,604✔
175
    pInfo->pOperator = NULL;
90,490,026✔
176
  }
177
  cleanupAggSup(&pInfo->aggSup);
90,504,319✔
178
  cleanupExprSuppWithoutFilter(&pInfo->scalarExprSup);
90,531,877✔
179
  cleanupGroupResInfo(&pInfo->groupResInfo);
90,514,527✔
180
  taosMemoryFreeClear(param);
90,515,443✔
181
}
182

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

196
  if(!pAggInfo) {
107,811,497✔
197
    qError("function:%s, pAggInfo is NULL", __func__);
×
198
    return false;
×
199
  }
200
  if (pOperator->blocking && pAggInfo->hasValidBlock) {
107,811,497✔
201
    return false;
10,157,315✔
202
  }
203

204
  SExprSupp*   pSup = &pOperator->exprSupp;
97,652,955✔
205
  int32_t      order = pAggInfo->binfo.inputTsOrder;
97,643,428✔
206
  SSDataBlock* pBlock = pAggInfo->pNewGroupBlock;
97,637,749✔
207

208
  pAggInfo->cleanGroupResInfo = false;
97,659,321✔
209
  if (pBlock) {
97,642,111✔
210
    pAggInfo->pNewGroupBlock = NULL;
714,012✔
211
    tSimpleHashClear(pAggInfo->aggSup.pResultRowHashTable);
714,012✔
212
    code = setExecutionContext(pOperator, pOperator->exprSupp.numOfExprs, pBlock->info.id.groupId);
714,012✔
213
    QUERY_CHECK_CODE(code, lino, _end);
714,012✔
214
    code = setInputDataBlock(pSup, pBlock, order, pBlock->info.scanFlag, true);
714,012✔
215
    QUERY_CHECK_CODE(code, lino, _end);
714,012✔
216

217
    code = doAggregateImpl(pOperator, pSup->pCtx);
714,012✔
218
    QUERY_CHECK_CODE(code, lino, _end);
726,407✔
219
  }
220
  while (1) {
366,782,012✔
221
    bool blockAllocated = false;
464,436,518✔
222
    pBlock = getNextBlockFromDownstreamRemainDetach(pOperator, 0);
464,436,518✔
223
    if (pBlock == NULL) {
462,574,520✔
224
      if (!pAggInfo->hasValidBlock) {
98,235,793✔
225
        code = createDataBlockForEmptyInput(pOperator, &pBlock);
22,590,011✔
226
        QUERY_CHECK_CODE(code, lino, _end);
22,588,194✔
227

228
        if (pBlock == NULL) {
22,588,194✔
229
          break;
19,328,763✔
230
        }
231
        blockAllocated = true;
3,259,431✔
232
      } else {
233
        break;
75,645,908✔
234
      }
235
    }
236
    pAggInfo->hasValidBlock = true;
367,598,158✔
237
    pAggInfo->binfo.pRes->info.scanFlag = pBlock->info.scanFlag;
367,624,019✔
238

239
    printDataBlock(pBlock, __func__, pTaskInfo->id.str, pTaskInfo->id.queryId);
367,631,949✔
240

241
    // there is an scalar expression that needs to be calculated before apply the group aggregation.
242
    if (pAggInfo->scalarExprSup.pExprInfo != NULL && !blockAllocated) {
367,584,772✔
243
      SExprSupp* pSup1 = &pAggInfo->scalarExprSup;
82,066,904✔
244
      code = projectApplyFunctions(pSup1->pExprInfo, pBlock, pBlock, pSup1->pCtx, pSup1->numOfExprs, NULL, GET_STM_RTINFO(pOperator->pTaskInfo));
82,073,967✔
245
      if (code != TSDB_CODE_SUCCESS) {
82,011,692✔
246
        destroyDataBlockForEmptyInput(blockAllocated, &pBlock);
34,410✔
247
        T_LONG_JMP(pTaskInfo->env, code);
34,410✔
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) {
367,500,591✔
252
      pAggInfo->pNewGroupBlock = pBlock;
727,223✔
253
      break;
726,656✔
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);
366,782,087✔
257
    if (code != TSDB_CODE_SUCCESS) {
366,778,801✔
258
      destroyDataBlockForEmptyInput(blockAllocated, &pBlock);
×
259
      T_LONG_JMP(pTaskInfo->env, code);
×
260
    }
261
    code = setInputDataBlock(pSup, pBlock, order, pBlock->info.scanFlag, true);
366,778,801✔
262
    if (code != TSDB_CODE_SUCCESS) {
366,845,203✔
263
      destroyDataBlockForEmptyInput(blockAllocated, &pBlock);
×
264
      T_LONG_JMP(pTaskInfo->env, code);
×
265
    }
266

267
    code = doAggregateImpl(pOperator, pSup->pCtx);
366,845,203✔
268
    if (code != TSDB_CODE_SUCCESS) {
366,767,676✔
269
      destroyDataBlockForEmptyInput(blockAllocated, &pBlock);
3,700✔
270
      T_LONG_JMP(pTaskInfo->env, code);
3,700✔
271
    }
272

273
    destroyDataBlockForEmptyInput(blockAllocated, &pBlock);
366,763,976✔
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) {
95,701,327✔
278
    T_LONG_JMP(pTaskInfo->env, pTaskInfo->code);
×
279
  }
280

281
  code = initGroupedResultInfo(&pAggInfo->groupResInfo, pAggInfo->aggSup.pResultRowHashTable, 0);
95,684,624✔
282
  QUERY_CHECK_CODE(code, lino, _end);
95,697,979✔
283
  pAggInfo->cleanGroupResInfo = true;
95,697,979✔
284

285
_end:
95,698,835✔
286
  if (code != TSDB_CODE_SUCCESS) {
95,698,858✔
287
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
388✔
288
    pTaskInfo->code = code;
388✔
289
    T_LONG_JMP(pTaskInfo->env, code);
×
290
  }
291
  return pBlock != NULL;
95,698,989✔
292
}
293

294
int32_t getAggregateResultNext(SOperatorInfo* pOperator, SSDataBlock** ppRes) {
179,991,567✔
295
  int32_t           code = TSDB_CODE_SUCCESS;
179,991,567✔
296
  int32_t           lino = 0;
179,991,567✔
297
  SAggOperatorInfo* pAggInfo = pOperator->info;
179,991,567✔
298
  SOptrBasicInfo*   pInfo = &pAggInfo->binfo;
180,004,854✔
299

300
  if (pOperator->status == OP_EXEC_DONE && !pOperator->pOperatorGetParam) {
180,000,669✔
301
    (*ppRes) = NULL;
72,194,170✔
302
    return code;
72,193,060✔
303
  }
304

305
  if (pOperator->pOperatorGetParam) {
107,800,112✔
306
    if (pOperator->status == OP_EXEC_DONE) {
2,468,064✔
307
      pOperator->status = OP_OPENED;
1,611,144✔
308
      tSimpleHashClear(pAggInfo->aggSup.pResultRowHashTable);
1,611,144✔
309
      pAggInfo->groupId = UINT64_MAX;
1,611,138✔
310
      pAggInfo->hasValidBlock = false;
1,611,138✔
311
    }
312
    freeOperatorParam(pOperator->pOperatorGetParam, OP_GET_PARAM);
2,466,216✔
313
    pOperator->pOperatorGetParam = NULL;
2,468,064✔
314

315
  }
316

317
  SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
107,801,206✔
318
  bool           hasNewGroups = false;
107,810,003✔
319
  do {
320
    hasNewGroups = nextGroupedResult(pOperator);
107,820,440✔
321
    code = blockDataEnsureCapacity(pInfo->pRes, pOperator->resultInfo.capacity);
105,852,147✔
322
    QUERY_CHECK_CODE(code, lino, _end);
105,862,775✔
323

324
    while (1) {
325
      doBuildResultDatablock(pOperator, pInfo, &pAggInfo->groupResInfo, pAggInfo->aggSup.pResultBuf);
105,862,775✔
326
      code = doFilter(pInfo->pRes, pOperator->exprSupp.pFilterInfo, NULL, NULL);
105,862,331✔
327
      QUERY_CHECK_CODE(code, lino, _end);
105,862,179✔
328

329
      if (!hasRemainResults(&pAggInfo->groupResInfo)) {
105,862,179✔
330
        if (!hasNewGroups) setOperatorCompleted(pOperator);
95,700,814✔
331
        break;
95,701,232✔
332
      }
333

334
      if (pInfo->pRes->info.rows > 0) {
10,164,035✔
335
        break;
10,164,035✔
336
      }
337
    }
338
  } while (pInfo->pRes->info.rows == 0 && hasNewGroups);
105,865,267✔
339

340
_end:
105,849,011✔
341
  if (code != TSDB_CODE_SUCCESS) {
105,849,011✔
342
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
×
343
    pTaskInfo->code = code;
×
344
    T_LONG_JMP(pTaskInfo->env, code);
×
345
  }
346

347
  printDataBlock(pInfo->pRes, __func__, pTaskInfo->id.str, pTaskInfo->id.queryId);
105,849,011✔
348

349
  (*ppRes) = (pInfo->pRes->info.rows == 0) ? NULL : pInfo->pRes;
105,844,801✔
350
  return code;
105,850,036✔
351
}
352

353
int32_t doAggregateImpl(SOperatorInfo* pOperator, SqlFunctionCtx* pCtx) {
367,536,038✔
354
  int32_t code = TSDB_CODE_SUCCESS;
367,536,038✔
355
  if (!pOperator || (pOperator->exprSupp.numOfExprs > 0 && pCtx == NULL)) {
367,536,038✔
356
    qError("%s failed at line %d since pCtx is NULL.", __func__, __LINE__);
5,421✔
357
    return TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR;
×
358
  }
359
  for (int32_t k = 0; k < pOperator->exprSupp.numOfExprs; ++k) {
2,147,483,647✔
360
    if (functionNeedToExecute(&pCtx[k])) {
2,147,483,647✔
361
      // todo add a dummy function to avoid process check
362
      if (pCtx[k].fpSet.process == NULL) {
2,147,483,647✔
363
        continue;
12,484,689✔
364
      }
365

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

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

383
  return TSDB_CODE_SUCCESS;
367,549,961✔
384
}
385

386
static int32_t createDataBlockForEmptyInput(SOperatorInfo* pOperator, SSDataBlock** ppBlock) {
22,592,538✔
387
  int32_t code = TSDB_CODE_SUCCESS;
22,592,538✔
388
  int32_t lino = 0;
22,592,538✔
389
  SSDataBlock* pBlock = NULL;
22,592,538✔
390
  if (!tsCountAlwaysReturnValue) {
22,590,876✔
391
    return TSDB_CODE_SUCCESS;
6,491,600✔
392
  }
393

394
  SAggOperatorInfo* pAggInfo = pOperator->info;
16,099,276✔
395
  if (pAggInfo->groupKeyOptimized) {
16,093,014✔
396
    return TSDB_CODE_SUCCESS;
3,452,963✔
397
  }
398

399
  SOperatorInfo* downstream = pOperator->pDownstream[0];
12,642,315✔
400
  if (downstream->operatorType == QUERY_NODE_PHYSICAL_PLAN_PARTITION ||
12,642,973✔
401
      downstream->operatorType == QUERY_NODE_PHYSICAL_PLAN_SORT ||
12,608,552✔
402
      (downstream->operatorType == QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN &&
12,579,803✔
403
       ((STableScanInfo*)downstream->info)->hasGroupByTag == true)) {
3,887,722✔
404
    return TSDB_CODE_SUCCESS;
62,730✔
405
  }
406

407
  SqlFunctionCtx* pCtx = pOperator->exprSupp.pCtx;
12,576,447✔
408

409
  if (!pAggInfo->hasCountFunc) {
12,576,527✔
410
    return TSDB_CODE_SUCCESS;
9,317,718✔
411
  }
412

413
  code = createDataBlock(&pBlock);
3,261,957✔
414
  if (code) {
3,262,615✔
415
    return code;
×
416
  }
417

418
  pBlock->info.rows = 1;
3,262,615✔
419
  pBlock->info.capacity = 0;
3,262,615✔
420

421
  for (int32_t i = 0; i < pOperator->exprSupp.numOfExprs; ++i) {
9,228,664✔
422
    SColumnInfoData colInfo = {0};
5,966,572✔
423
    colInfo.hasNull = true;
5,965,391✔
424
    colInfo.info.type = TSDB_DATA_TYPE_NULL;
5,965,391✔
425
    colInfo.info.bytes = 1;
5,965,391✔
426

427
    SExprInfo* pOneExpr = &pOperator->exprSupp.pExprInfo[i];
5,965,391✔
428
    for (int32_t j = 0; j < pOneExpr->base.numOfParams; ++j) {
12,159,013✔
429
      SFunctParam* pFuncParam = &pOneExpr->base.pParam[j];
6,192,680✔
430
      if (pFuncParam->type == FUNC_PARAM_TYPE_COLUMN) {
6,192,292✔
431
        int32_t slotId = pFuncParam->pCol->slotId;
6,188,671✔
432
        int32_t numOfCols = taosArrayGetSize(pBlock->pDataBlock);
6,189,194✔
433
        if (slotId >= numOfCols) {
6,189,194✔
434
          code = taosArrayEnsureCap(pBlock->pDataBlock, slotId + 1);
3,715,946✔
435
          QUERY_CHECK_CODE(code, lino, _end);
3,714,391✔
436

437
          for (int32_t k = numOfCols; k < slotId + 1; ++k) {
10,062,642✔
438
            void* tmp = taosArrayPush(pBlock->pDataBlock, &colInfo);
6,347,593✔
439
            QUERY_CHECK_NULL(tmp, code, lino, _end, terrno);
6,348,251✔
440
          }
441
        }
442
      } else if (pFuncParam->type == FUNC_PARAM_TYPE_VALUE) {
4,144✔
443
        // do nothing
444
      }
445
    }
446
  }
447

448
  code = blockDataEnsureCapacity(pBlock, pBlock->info.rows);
3,262,615✔
449
  QUERY_CHECK_CODE(code, lino, _end);
3,261,583✔
450

451
  for (int32_t i = 0; i < blockDataGetNumOfCols(pBlock); ++i) {
9,607,995✔
452
    SColumnInfoData* pColInfoData = taosArrayGet(pBlock->pDataBlock, i);
6,349,148✔
453
    QUERY_CHECK_NULL(pColInfoData, code, lino, _end, terrno);
6,348,490✔
454
    colDataSetNULL(pColInfoData, 0);
455
  }
456
  *ppBlock = pBlock;
3,259,879✔
457

458
_end:
3,259,879✔
459
  if (code != TSDB_CODE_SUCCESS) {
3,259,879✔
460
    blockDataDestroy(pBlock);
×
461
    qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(code));
×
462
  }
463
  return code;
3,262,092✔
464
}
465

466
void destroyDataBlockForEmptyInput(bool blockAllocated, SSDataBlock** ppBlock) {
366,794,214✔
467
  if (!blockAllocated) {
366,794,214✔
468
    return;
363,579,814✔
469
  }
470

471
  blockDataDestroy(*ppBlock);
3,214,400✔
472
  *ppBlock = NULL;
3,261,718✔
473
}
474

475
int32_t setExecutionContext(SOperatorInfo* pOperator, int32_t numOfOutput, uint64_t groupId) {
367,509,713✔
476
  int32_t           code = TSDB_CODE_SUCCESS;
367,509,713✔
477
  SAggOperatorInfo* pAggInfo = pOperator->info;
367,509,713✔
478
  if (pAggInfo->groupId != UINT64_MAX && pAggInfo->groupId == groupId) {
367,578,180✔
479
    return code;
170,794,967✔
480
  }
481

482
  code = doSetTableGroupOutputBuf(pOperator, numOfOutput, groupId);
196,757,485✔
483

484
  // record the current active group id
485
  pAggInfo->groupId = groupId;
196,742,371✔
486
  return code;
196,762,138✔
487
}
488

489
int32_t doSetTableGroupOutputBuf(SOperatorInfo* pOperator, int32_t numOfOutput, uint64_t groupId) {
196,784,588✔
490
  // for simple group by query without interval, all the tables belong to one group result.
491
  int32_t           code = TSDB_CODE_SUCCESS;
196,784,588✔
492
  int32_t           lino = 0;
196,784,588✔
493
  SExecTaskInfo*    pTaskInfo = pOperator->pTaskInfo;
196,784,588✔
494
  SAggOperatorInfo* pAggInfo = pOperator->info;
196,797,332✔
495

496
  SResultRowInfo* pResultRowInfo = &pAggInfo->binfo.resultRowInfo;
196,792,185✔
497
  SqlFunctionCtx* pCtx = pOperator->exprSupp.pCtx;
196,758,741✔
498
  int32_t*        rowEntryInfoOffset = pOperator->exprSupp.rowEntryInfoOffset;
196,772,774✔
499

500
  SResultRow* pResultRow =
501
      doSetResultOutBufByKey(pAggInfo->aggSup.pResultBuf, pResultRowInfo, (char*)&groupId, sizeof(groupId), true,
196,794,571✔
502
                             groupId, pTaskInfo, false, &pAggInfo->aggSup, true);
503
  if (pResultRow == NULL || pTaskInfo->code != 0) {
196,769,070✔
504
    code = pTaskInfo->code;
14,216✔
505
    lino = __LINE__;
×
506
    goto _end;
×
507
  }
508
  /*
509
   * not assign result buffer yet, add new result buffer
510
   * all group belong to one result set, and each group result has different group id so set the id to be one
511
   */
512
  if (pResultRow->pageId == -1) {
196,762,572✔
513
    code = addNewResultRowBuf(pResultRow, pAggInfo->aggSup.pResultBuf, pAggInfo->binfo.pRes->info.rowSize);
×
514
    QUERY_CHECK_CODE(code, lino, _end);
×
515
  }
516

517
  code = setResultRowInitCtx(pResultRow, pCtx, numOfOutput, rowEntryInfoOffset);
196,768,084✔
518
  QUERY_CHECK_CODE(code, lino, _end);
196,766,371✔
519

520
_end:
196,766,371✔
521
  if (code != TSDB_CODE_SUCCESS) {
196,766,371✔
522
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
×
523
  }
524
  return code;
196,746,875✔
525
}
526

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

533
  SFilePage* pData = NULL;
×
534

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

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

554
    pageId = getPageId(pi);
×
555

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

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

569
  if (pData == NULL) {
×
570
    return -1;
×
571
  }
572

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

578
    pData->num += size;
×
579
  }
580

581
  return 0;
×
582
}
583

584
int32_t doInitAggInfoSup(SAggSupporter* pAggSup, SqlFunctionCtx* pCtx, int32_t numOfOutput, size_t keyBufSize,
290,916,184✔
585
                         const char* pKey) {
586
  int32_t code = 0;
290,916,184✔
587
  //  _hash_fn_t hashFn = taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY);
588

589
  pAggSup->currentPageId = -1;
290,916,184✔
590
  pAggSup->resultRowSize = getResultRowSize(pCtx, numOfOutput);
290,943,846✔
591
  pAggSup->keyBuf = taosMemoryCalloc(1, keyBufSize + POINTER_BYTES + sizeof(int64_t));
290,882,838✔
592
  pAggSup->pResultRowHashTable = tSimpleHashInit(100, taosFastHash);
290,837,333✔
593

594
  if (pAggSup->keyBuf == NULL || pAggSup->pResultRowHashTable == NULL) {
290,807,534✔
595
    return terrno;
14,911✔
596
  }
597

598
  uint32_t defaultPgsz = 0;
290,795,314✔
599
  int64_t defaultBufsz = 0;
290,871,134✔
600
  code = getBufferPgSize(pAggSup->resultRowSize, &defaultPgsz, &defaultBufsz);
290,890,753✔
601
  if (code) {
290,780,560✔
602
    qError("failed to get buff page size, rowSize:%d", pAggSup->resultRowSize);
×
603
    return code;
×
604
  }
605

606
  if (!osTempSpaceAvailable()) {
290,780,560✔
607
    code = TSDB_CODE_NO_DISKSPACE;
×
608
    qError("Init stream agg supporter failed since %s, key:%s, tempDir:%s", tstrerror(code), pKey, tsTempDir);
×
609
    return code;
×
610
  }
611

612
  code = createDiskbasedBuf(&pAggSup->pResultBuf, defaultPgsz, defaultBufsz, pKey, tsTempDir);
290,905,691✔
613
  if (code != TSDB_CODE_SUCCESS) {
290,925,418✔
614
    qError("Create agg result buf failed since %s, %s", tstrerror(code), pKey);
×
615
    return code;
×
616
  }
617

618
  return code;
290,925,418✔
619
}
620

621
void cleanupResultInfoInGroupResInfo(SExecTaskInfo* pTaskInfo, SExprSupp* pSup, SDiskbasedBuf* pBuf,
99,311,282✔
622
                                  SGroupResInfo* pGroupResInfo) {
623
  int32_t         numOfExprs = pSup->numOfExprs;
99,311,282✔
624
  int32_t*        rowEntryOffset = pSup->rowEntryInfoOffset;
99,321,483✔
625
  SqlFunctionCtx* pCtx = pSup->pCtx;
99,309,910✔
626
  int32_t         numOfRows = getNumOfTotalRes(pGroupResInfo);
99,312,766✔
627
  bool            needCleanup = false;
99,309,783✔
628

629
  for (int32_t j = 0; j < numOfExprs; ++j) {
108,208,794✔
630
    needCleanup |= pCtx[j].needCleanup;
8,898,247✔
631
  }
632
  if (!needCleanup) {
99,310,547✔
633
    return;
99,314,988✔
634
  }
635

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

646

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

657
void cleanupResultInfoInHashMap(SExecTaskInfo* pTaskInfo, SExprSupp* pSup, SDiskbasedBuf* pBuf,
34,916,282✔
658
                       SGroupResInfo* pGroupResInfo, SSHashObj* pHashmap) {
659
  int32_t         numOfExprs = pSup->numOfExprs;
34,916,282✔
660
  int32_t*        rowEntryOffset = pSup->rowEntryInfoOffset;
34,918,412✔
661
  SqlFunctionCtx* pCtx = pSup->pCtx;
34,917,919✔
662
  bool            needCleanup = false;
34,916,050✔
663
  for (int32_t j = 0; j < numOfExprs; ++j) {
44,124,082✔
664
    needCleanup |= pCtx[j].needCleanup;
9,206,401✔
665
  }
666
  if (!needCleanup) {
34,917,681✔
667
    return;
34,918,037✔
668
  }
669

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

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

682
    SResultRow* pRow = (SResultRow*)((char*)page + pos->offset);
×
683

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

691
    releaseBufPage(pBuf, page);
×
692
  }
693
}
694

695
void cleanupResultInfo(SExecTaskInfo* pTaskInfo, SExprSupp* pSup, SGroupResInfo* pGroupResInfo,
134,228,710✔
696
                       SAggSupporter *pAggSup, bool cleanGroupResInfo) {
697
  if (cleanGroupResInfo) {
134,228,710✔
698
    cleanupResultInfoInGroupResInfo(pTaskInfo, pSup, pAggSup->pResultBuf, pGroupResInfo);
99,320,761✔
699
  } else {
700
    cleanupResultInfoInHashMap(pTaskInfo, pSup, pAggSup->pResultBuf, pGroupResInfo, pAggSup->pResultRowHashTable);
34,907,949✔
701
  }
702
}
134,215,389✔
703
void cleanupAggSup(SAggSupporter* pAggSup) {
291,361,447✔
704
  taosMemoryFreeClear(pAggSup->keyBuf);
291,361,447✔
705
  tSimpleHashCleanup(pAggSup->pResultRowHashTable);
291,382,108✔
706
  destroyDiskbasedBuf(pAggSup->pResultBuf);
291,363,550✔
707
  memset(pAggSup, 0, sizeof(SAggSupporter));
291,352,507✔
708
}
291,352,507✔
709

710
int32_t initAggSup(SExprSupp* pSup, SAggSupporter* pAggSup, SExprInfo* pExprInfo, int32_t numOfCols, size_t keyBufSize,
290,939,773✔
711
                   const char* pkey, void* pState, SFunctionStateStore* pStore) {
712
  int32_t code = initExprSupp(pSup, pExprInfo, numOfCols, pStore);
290,939,773✔
713
  if (code != TSDB_CODE_SUCCESS) {
290,856,647✔
714
    return code;
×
715
  }
716

717
  code = doInitAggInfoSup(pAggSup, pSup->pCtx, numOfCols, keyBufSize, pkey);
290,856,647✔
718
  if (code != TSDB_CODE_SUCCESS) {
290,913,039✔
719
    return code;
×
720
  }
721

722
  for (int32_t i = 0; i < numOfCols; ++i) {
1,217,166,509✔
723
    pSup->pCtx[i].hasWindowOrGroup = pSup->hasWindowOrGroup;
926,349,654✔
724
    pSup->pCtx[i].hasWindow= pSup->hasWindow;
926,248,127✔
725
    if (pState) {
926,148,775✔
726
      pSup->pCtx[i].saveHandle.pBuf = NULL;
×
727
      pSup->pCtx[i].saveHandle.pState = pState;
×
728
      pSup->pCtx[i].exprIdx = i;
×
729
    } else {
730
      pSup->pCtx[i].saveHandle.pBuf = pAggSup->pResultBuf;
926,148,775✔
731
    }
732
  }
733

734
  return TSDB_CODE_SUCCESS;
290,816,855✔
735
}
736

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

745
    pCtx[k].input.startRowIndex = offset;
2,147,483,647✔
746
    pCtx[k].input.numOfRows = forwardStep;
2,147,483,647✔
747

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

754
    if (fmIsPlaceHolderFunc(pCtx[k].functionId)) {
2,147,483,647✔
755
      SResultRowEntryInfo* pEntryInfo = GET_RES_INFO(&pCtx[k]);
197,960,813✔
756
      char* p = GET_ROWCELL_INTERBUF(pEntryInfo);
197,969,839✔
757

758
      TAOS_CHECK_EXIT(fmSetStreamPseudoFuncParamVal(pCtx[k].functionId, pCtx[k].pExpr->base.pParamList, &taskInfo->pStreamRuntimeInfo->funcInfo));
197,974,347✔
759

760
      SValueNode *valueNode = (SValueNode *)nodesListGetNode(pCtx[k].pExpr->base.pParamList, 0);
197,994,892✔
761
      pEntryInfo->isNullRes = 0;
197,996,743✔
762
      if (TSDB_DATA_TYPE_NULL == valueNode->node.resType.type || valueNode->isNull) {
197,980,250✔
763
        pEntryInfo->isNullRes = 1;
×
764
      } else if (IS_VAR_DATA_TYPE(pCtx[k].pExpr->base.resSchema.type)){
198,001,075✔
UNCOV
765
        void* v = nodesGetValueFromNode(valueNode);
×
766
        memcpy(p, v, varDataTLen(v));
10,780✔
767
      } else {
768
        memcpy(p, nodesGetValueFromNode(valueNode), pCtx[k].pExpr->base.resSchema.bytes);
197,915,600✔
769
      }
770
      
771
      pEntryInfo->numOfRes = 1;
197,923,558✔
772
    } else if (pCtx[k].isPseudoFunc) {
2,147,483,647✔
773
      SResultRowEntryInfo* pEntryInfo = GET_RES_INFO(&pCtx[k]);
2,147,483,647✔
774

775
      char* p = GET_ROWCELL_INTERBUF(pEntryInfo);
2,147,483,647✔
776

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

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

796
        if (code != TSDB_CODE_SUCCESS) {
2,147,483,647✔
797
          if (pCtx[k].fpSet.cleanup != NULL) {
464✔
798
            pCtx[k].fpSet.cleanup(&pCtx[k]);
464✔
799
          }
800
          TAOS_CHECK_EXIT(code);
464✔
801
        }
802
      }
803

804
      // restore it
805
      functionCtxRestore(&pCtx[k], &status);
2,147,483,647✔
806
    }
807
  }
808

809
_exit:
2,147,483,647✔
810

811
  if (code) {
2,147,483,647✔
812
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
464✔
813
    taskInfo->code = code;
464✔
814
  }
815

816
  return code;
2,147,483,647✔
817
}
818

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

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

831
static int32_t resetAggregateOperatorState(SOperatorInfo* pOper) {
5,645,084✔
832
  SAggOperatorInfo* pAgg = pOper->info;
5,645,084✔
833
  SAggPhysiNode*   pAggNode = (SAggPhysiNode*)pOper->pPhyNode;
5,646,940✔
834
  
835
  pOper->status = OP_NOT_OPENED;
5,646,476✔
836
  size_t keyBufSize = sizeof(int64_t) + sizeof(int64_t) + POINTER_BYTES;
5,646,708✔
837
  SExecTaskInfo*  pTaskInfo = pOper->pTaskInfo;
5,646,708✔
838
  cleanupResultInfo(pTaskInfo, &pOper->exprSupp, &pAgg->groupResInfo, &pAgg->aggSup,
5,647,172✔
839
                      pAgg->cleanGroupResInfo);
5,646,012✔
840
  cleanupGroupResInfo(&pAgg->groupResInfo);
5,646,472✔
841
  resetBasicOperatorState(&pAgg->binfo);
5,645,077✔
842
  
843
  pAgg->pNewGroupBlock = NULL;
5,647,172✔
844

845
  int32_t code = resetAggSup(&pOper->exprSupp, &pAgg->aggSup, pTaskInfo, pAggNode->pAggFuncs, pAggNode->pGroupKeys,
11,293,482✔
846
    keyBufSize, pTaskInfo->id.str, NULL, &pTaskInfo->storageAPI.functionStore);
5,647,172✔
847

848
  if (code == 0) {
5,646,012✔
849
    code = resetExprSupp(&pAgg->scalarExprSup, pTaskInfo, pAggNode->pExprs, NULL,
5,646,244✔
850
                          &pTaskInfo->storageAPI.functionStore);
851
  }
852

853
  pAgg->groupId = UINT64_MAX;
5,646,476✔
854
  pAgg->cleanGroupResInfo = false;
5,646,708✔
855
  pAgg->hasValidBlock = false;
5,646,708✔
856
  return 0;
5,645,773✔
857
}
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