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

taosdata / TDengine / #4980

10 Mar 2026 08:57AM UTC coverage: 68.492% (-0.02%) from 68.512%
#4980

push

travis-ci

web-flow
fix: add retry while exec ci case test_stable_keep_compact.py. (#34729)

211901 of 309380 relevant lines covered (68.49%)

135171938.8 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,
88,770,859✔
77
                                    SOperatorInfo** pOptrInfo) {
78
  QRY_PARAM_CHECK(pOptrInfo);
88,770,859✔
79

80
  int32_t    lino = 0;
88,789,584✔
81
  int32_t    code = 0;
88,789,584✔
82
  int32_t    num = 0;
88,789,584✔
83
  SExprInfo* pExprInfo = NULL;
88,790,375✔
84
  int32_t    numOfScalarExpr = 0;
88,786,301✔
85
  SExprInfo* pScalarExprInfo = NULL;
88,760,546✔
86

87
  SAggOperatorInfo* pInfo = taosMemoryCalloc(1, sizeof(SAggOperatorInfo));
88,762,844✔
88
  SOperatorInfo*    pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo));
88,698,958✔
89
  if (pInfo == NULL || pOperator == NULL) {
88,689,550✔
90
    code = terrno;
125✔
91
    goto _error;
×
92
  }
93

94
  pOperator->exprSupp.hasWindowOrGroup = false;
88,690,469✔
95

96
  SSDataBlock* pResBlock = createDataBlockFromDescNode(pAggNode->node.pOutputDataBlockDesc);
88,694,171✔
97
  QUERY_CHECK_NULL(pResBlock, code, lino, _error, terrno);
88,790,598✔
98
  initBasicInfo(&pInfo->binfo, pResBlock);
88,790,598✔
99

100
  size_t keyBufSize = sizeof(int64_t) + sizeof(int64_t) + POINTER_BYTES;
88,781,906✔
101
  initResultSizeInfo(&pOperator->resultInfo, 4096);
88,781,906✔
102

103

104
  code = createExprInfo(pAggNode->pAggFuncs, pAggNode->pGroupKeys, &pExprInfo, &num);
88,792,154✔
105
  TSDB_CHECK_CODE(code, lino, _error);
88,773,079✔
106

107
  code = initAggSup(&pOperator->exprSupp, &pInfo->aggSup, pExprInfo, num, keyBufSize, pTaskInfo->id.str,
177,555,719✔
108
                               pTaskInfo->streamInfo.pState, &pTaskInfo->storageAPI.functionStore);
88,780,279✔
109
  TSDB_CHECK_CODE(code, lino, _error);
88,750,069✔
110

111
  if (pAggNode->pExprs != NULL) {
88,750,069✔
112
    code = createExprInfo(pAggNode->pExprs, NULL, &pScalarExprInfo, &numOfScalarExpr);
14,121,324✔
113
    TSDB_CHECK_CODE(code, lino, _error);
14,108,112✔
114
  }
115

116
  code = initExprSupp(&pInfo->scalarExprSup, pScalarExprInfo, numOfScalarExpr, &pTaskInfo->storageAPI.functionStore);
88,718,564✔
117
  TSDB_CHECK_CODE(code, lino, _error);
88,712,562✔
118

119
  code = filterInitFromNode((SNode*)pAggNode->node.pConditions, &pOperator->exprSupp.pFilterInfo, 0,
88,667,536✔
120
                            GET_STM_RTINFO(pTaskInfo));
88,712,562✔
121
  TSDB_CHECK_CODE(code, lino, _error);
88,710,872✔
122

123
  pInfo->binfo.mergeResultBlock = pAggNode->mergeDataBlock;
88,710,872✔
124
  pInfo->groupKeyOptimized = pAggNode->groupKeyOptimized;
88,678,003✔
125
  pInfo->groupId = UINT64_MAX;
88,693,167✔
126
  pInfo->binfo.inputTsOrder = pAggNode->node.inputTsOrder;
88,693,603✔
127
  pInfo->binfo.outputTsOrder = pAggNode->node.outputTsOrder;
88,717,372✔
128
  pInfo->hasCountFunc = pAggNode->hasCountLikeFunc;
88,691,874✔
129
  pInfo->pOperator = pOperator;
88,701,560✔
130
  pInfo->cleanGroupResInfo = false;
88,700,924✔
131

132
  setOperatorInfo(pOperator, "TableAggregate", QUERY_NODE_PHYSICAL_PLAN_HASH_AGG,
88,710,120✔
133
                  !pAggNode->node.forceCreateNonBlockingOptr, OP_NOT_OPENED, pInfo, pTaskInfo);
88,675,721✔
134
  pOperator->fpSet = createOperatorFpSet(optrDummyOpenFn, getAggregateResultNext, NULL, destroyAggOperatorInfo,
88,718,066✔
135
                                         optrDefaultBufFn, NULL, optrDefaultGetNextExtFn, NULL);
136
  setOperatorResetStateFn(pOperator, resetAggregateOperatorState);
88,715,803✔
137

138
  pOperator->pPhyNode = pAggNode;
88,708,437✔
139

140
  if (downstream->operatorType == QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN) {
88,694,203✔
141
    STableScanInfo* pTableScanInfo = downstream->info;
51,573,220✔
142
    pTableScanInfo->base.pdInfo.pExprSup = &pOperator->exprSupp;
51,569,837✔
143
    pTableScanInfo->base.pdInfo.pAggSup = &pInfo->aggSup;
51,565,151✔
144
  }
145

146
  code = appendDownstream(pOperator, &downstream, 1);
88,687,830✔
147
  if (code != TSDB_CODE_SUCCESS) {
88,692,963✔
148
    goto _error;
×
149
  }
150

151
  *pOptrInfo = pOperator;
88,692,963✔
152
  return TSDB_CODE_SUCCESS;
88,696,719✔
153

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

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

171
  if (pInfo->pOperator) {
88,796,860✔
172
    cleanupResultInfo(pInfo->pOperator->pTaskInfo, &pInfo->pOperator->exprSupp, &pInfo->groupResInfo, &pInfo->aggSup,
88,773,782✔
173
                      pInfo->cleanGroupResInfo);
88,781,369✔
174
    pInfo->pOperator = NULL;
88,757,219✔
175
  }
176
  cleanupAggSup(&pInfo->aggSup);
88,771,978✔
177
  cleanupExprSuppWithoutFilter(&pInfo->scalarExprSup);
88,787,211✔
178
  cleanupGroupResInfo(&pInfo->groupResInfo);
88,764,194✔
179
  taosMemoryFreeClear(param);
88,776,422✔
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) {
107,442,422✔
190
  int32_t           code = TSDB_CODE_SUCCESS;
107,442,422✔
191
  int32_t           lino = 0;
107,442,422✔
192
  SExecTaskInfo*    pTaskInfo = pOperator->pTaskInfo;
107,442,422✔
193
  SAggOperatorInfo* pAggInfo = pOperator->info;
107,440,372✔
194

195
  if(!pAggInfo) {
107,412,863✔
196
    qError("function:%s, pAggInfo is NULL", __func__);
×
197
    return false;
×
198
  }
199
  if (pOperator->blocking && pAggInfo->hasValidBlock) {
107,412,863✔
200
    return false;
9,656,964✔
201
  }
202

203
  SExprSupp*   pSup = &pOperator->exprSupp;
97,760,671✔
204
  int64_t      st = taosGetTimestampUs();
97,775,548✔
205
  int32_t      order = pAggInfo->binfo.inputTsOrder;
97,775,548✔
206
  SSDataBlock* pBlock = pAggInfo->pNewGroupBlock;
97,775,345✔
207

208
  pAggInfo->cleanGroupResInfo = false;
97,770,636✔
209
  if (pBlock) {
97,768,841✔
210
    pAggInfo->pNewGroupBlock = NULL;
677,311✔
211
    tSimpleHashClear(pAggInfo->aggSup.pResultRowHashTable);
677,311✔
212
    code = setExecutionContext(pOperator, pOperator->exprSupp.numOfExprs, pBlock->info.id.groupId);
677,311✔
213
    QUERY_CHECK_CODE(code, lino, _end);
677,311✔
214
    code = setInputDataBlock(pSup, pBlock, order, pBlock->info.scanFlag, true);
677,311✔
215
    QUERY_CHECK_CODE(code, lino, _end);
677,311✔
216

217
    code = doAggregateImpl(pOperator, pSup->pCtx);
677,311✔
218
    QUERY_CHECK_CODE(code, lino, _end);
689,133✔
219
  }
220
  while (1) {
624,246,169✔
221
    bool blockAllocated = false;
722,026,717✔
222
    pBlock = getNextBlockFromDownstreamRemainDetach(pOperator, 0);
722,026,717✔
223
    if (pBlock == NULL) {
720,778,237✔
224
      if (!pAggInfo->hasValidBlock) {
99,338,984✔
225
        code = createDataBlockForEmptyInput(pOperator, &pBlock);
23,962,061✔
226
        QUERY_CHECK_CODE(code, lino, _end);
23,951,475✔
227

228
        if (pBlock == NULL) {
23,951,475✔
229
          break;
20,483,727✔
230
        }
231
        blockAllocated = true;
3,467,748✔
232
      } else {
233
        break;
75,377,386✔
234
      }
235
    }
236
    pAggInfo->hasValidBlock = true;
624,907,001✔
237
    pAggInfo->binfo.pRes->info.scanFlag = pBlock->info.scanFlag;
624,944,405✔
238

239
    printDataBlock(pBlock, __func__, pTaskInfo->id.str, pTaskInfo->id.queryId);
624,996,359✔
240

241
    // there is an scalar expression that needs to be calculated before apply the group aggregation.
242
    if (pAggInfo->scalarExprSup.pExprInfo != NULL && !blockAllocated) {
624,947,593✔
243
      SExprSupp* pSup1 = &pAggInfo->scalarExprSup;
79,658,405✔
244
      code = projectApplyFunctions(pSup1->pExprInfo, pBlock, pBlock, pSup1->pCtx, pSup1->numOfExprs, NULL, GET_STM_RTINFO(pOperator->pTaskInfo));
79,658,916✔
245
      if (code != TSDB_CODE_SUCCESS) {
79,656,361✔
246
        destroyDataBlockForEmptyInput(blockAllocated, &pBlock);
33,294✔
247
        T_LONG_JMP(pTaskInfo->env, code);
33,294✔
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) {
624,911,952✔
252
      pAggInfo->pNewGroupBlock = pBlock;
689,998✔
253
      break;
689,998✔
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);
624,174,533✔
257
    if (code != TSDB_CODE_SUCCESS) {
624,170,806✔
258
      destroyDataBlockForEmptyInput(blockAllocated, &pBlock);
×
259
      T_LONG_JMP(pTaskInfo->env, code);
×
260
    }
261
    code = setInputDataBlock(pSup, pBlock, order, pBlock->info.scanFlag, true);
624,170,806✔
262
    if (code != TSDB_CODE_SUCCESS) {
624,235,344✔
263
      destroyDataBlockForEmptyInput(blockAllocated, &pBlock);
×
264
      T_LONG_JMP(pTaskInfo->env, code);
×
265
    }
266

267
    code = doAggregateImpl(pOperator, pSup->pCtx);
624,235,344✔
268
    if (code != TSDB_CODE_SUCCESS) {
624,238,811✔
269
      destroyDataBlockForEmptyInput(blockAllocated, &pBlock);
2,904✔
270
      T_LONG_JMP(pTaskInfo->env, code);
2,904✔
271
    }
272

273
    destroyDataBlockForEmptyInput(blockAllocated, &pBlock);
624,235,907✔
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) {
96,551,111✔
278
    T_LONG_JMP(pTaskInfo->env, pTaskInfo->code);
×
279
  }
280

281
  code = initGroupedResultInfo(&pAggInfo->groupResInfo, pAggInfo->aggSup.pResultRowHashTable, 0);
96,548,208✔
282
  QUERY_CHECK_CODE(code, lino, _end);
96,554,022✔
283
  pAggInfo->cleanGroupResInfo = true;
96,554,022✔
284

285
_end:
96,546,683✔
286
  if (code != TSDB_CODE_SUCCESS) {
96,548,954✔
287
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
36✔
288
    pTaskInfo->code = code;
36✔
289
    T_LONG_JMP(pTaskInfo->env, code);
×
290
  }
291
  return pBlock != NULL;
96,552,676✔
292
}
293

294
int32_t getAggregateResultNext(SOperatorInfo* pOperator, SSDataBlock** ppRes) {
178,644,331✔
295
  int32_t           code = TSDB_CODE_SUCCESS;
178,644,331✔
296
  int32_t           lino = 0;
178,644,331✔
297
  SAggOperatorInfo* pAggInfo = pOperator->info;
178,644,331✔
298
  SOptrBasicInfo*   pInfo = &pAggInfo->binfo;
178,655,083✔
299

300
  if (pOperator->status == OP_EXEC_DONE && !pOperator->pOperatorGetParam) {
178,649,588✔
301
    (*ppRes) = NULL;
71,218,236✔
302
    return code;
71,216,735✔
303
  }
304

305
  if (pOperator->pOperatorGetParam) {
107,424,358✔
306
    if (pOperator->status == OP_EXEC_DONE) {
8,309,511✔
307
      pOperator->status = OP_OPENED;
5,273,432✔
308
      tSimpleHashClear(pAggInfo->aggSup.pResultRowHashTable);
5,274,468✔
309
      pAggInfo->groupId = UINT64_MAX;
5,277,180✔
310
      pAggInfo->hasValidBlock = false;
5,277,180✔
311
    }
312
    freeOperatorParam(pOperator->pOperatorGetParam, OP_GET_PARAM);
8,309,862✔
313
    pOperator->pOperatorGetParam = NULL;
8,307,761✔
314

315
  }
316

317
  SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
107,426,051✔
318
  bool           hasNewGroups = false;
107,425,459✔
319
  do {
320
    hasNewGroups = nextGroupedResult(pOperator);
107,436,521✔
321
    code = blockDataEnsureCapacity(pInfo->pRes, pOperator->resultInfo.capacity);
106,211,686✔
322
    QUERY_CHECK_CODE(code, lino, _end);
106,214,861✔
323

324
    while (1) {
325
      doBuildResultDatablock(pOperator, pInfo, &pAggInfo->groupResInfo, pAggInfo->aggSup.pResultBuf);
106,214,861✔
326
      code = doFilter(pInfo->pRes, pOperator->exprSupp.pFilterInfo, NULL, NULL);
106,215,518✔
327
      QUERY_CHECK_CODE(code, lino, _end);
106,213,646✔
328

329
      if (!hasRemainResults(&pAggInfo->groupResInfo)) {
106,213,646✔
330
        if (!hasNewGroups) setOperatorCompleted(pOperator);
96,553,552✔
331
        break;
96,553,066✔
332
      }
333

334
      if (pInfo->pRes->info.rows > 0) {
9,663,432✔
335
        break;
9,663,432✔
336
      }
337
    }
338
  } while (pInfo->pRes->info.rows == 0 && hasNewGroups);
106,216,498✔
339

340
  size_t rows = blockDataGetNumOfRows(pInfo->pRes);
106,203,389✔
341
  pOperator->resultInfo.totalRows += rows;
106,205,558✔
342

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

352
  (*ppRes) = (rows == 0) ? NULL : pInfo->pRes;
106,199,059✔
353
  return code;
106,200,055✔
354
}
355

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

386
  return TSDB_CODE_SUCCESS;
624,919,856✔
387
}
388

389
static int32_t createDataBlockForEmptyInput(SOperatorInfo* pOperator, SSDataBlock** ppBlock) {
23,958,669✔
390
  int32_t code = TSDB_CODE_SUCCESS;
23,958,669✔
391
  int32_t lino = 0;
23,958,669✔
392
  SSDataBlock* pBlock = NULL;
23,958,669✔
393
  if (!tsCountAlwaysReturnValue) {
23,959,646✔
394
    return TSDB_CODE_SUCCESS;
6,203,140✔
395
  }
396

397
  SAggOperatorInfo* pAggInfo = pOperator->info;
17,756,506✔
398
  if (pAggInfo->groupKeyOptimized) {
17,755,478✔
399
    return TSDB_CODE_SUCCESS;
4,836,370✔
400
  }
401

402
  SOperatorInfo* downstream = pOperator->pDownstream[0];
12,919,872✔
403
  if (downstream->operatorType == QUERY_NODE_PHYSICAL_PLAN_PARTITION ||
12,917,562✔
404
      downstream->operatorType == QUERY_NODE_PHYSICAL_PLAN_SORT ||
12,884,496✔
405
      (downstream->operatorType == QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN &&
12,871,039✔
406
       ((STableScanInfo*)downstream->info)->hasGroupByTag == true)) {
4,796,247✔
407
    return TSDB_CODE_SUCCESS;
49,170✔
408
  }
409

410
  SqlFunctionCtx* pCtx = pOperator->exprSupp.pCtx;
12,865,343✔
411

412
  if (!pAggInfo->hasCountFunc) {
12,868,625✔
413
    return TSDB_CODE_SUCCESS;
9,394,965✔
414
  }
415

416
  code = createDataBlock(&pBlock);
3,470,039✔
417
  if (code) {
3,470,039✔
418
    return code;
×
419
  }
420

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

424
  for (int32_t i = 0; i < pOperator->exprSupp.numOfExprs; ++i) {
9,415,109✔
425
    SColumnInfoData colInfo = {0};
5,945,070✔
426
    colInfo.hasNull = true;
5,945,070✔
427
    colInfo.info.type = TSDB_DATA_TYPE_NULL;
5,945,070✔
428
    colInfo.info.bytes = 1;
5,945,070✔
429

430
    SExprInfo* pOneExpr = &pOperator->exprSupp.pExprInfo[i];
5,945,070✔
431
    for (int32_t j = 0; j < pOneExpr->base.numOfParams; ++j) {
12,108,706✔
432
      SFunctParam* pFuncParam = &pOneExpr->base.pParam[j];
6,163,636✔
433
      if (pFuncParam->type == FUNC_PARAM_TYPE_COLUMN) {
6,163,636✔
434
        int32_t slotId = pFuncParam->pCol->slotId;
6,158,656✔
435
        int32_t numOfCols = taosArrayGetSize(pBlock->pDataBlock);
6,158,656✔
436
        if (slotId >= numOfCols) {
6,158,656✔
437
          code = taosArrayEnsureCap(pBlock->pDataBlock, slotId + 1);
3,790,347✔
438
          QUERY_CHECK_CODE(code, lino, _end);
3,790,347✔
439

440
          for (int32_t k = numOfCols; k < slotId + 1; ++k) {
10,420,073✔
441
            void* tmp = taosArrayPush(pBlock->pDataBlock, &colInfo);
6,629,726✔
442
            QUERY_CHECK_NULL(tmp, code, lino, _end, terrno);
6,629,726✔
443
          }
444
        }
445
      } else if (pFuncParam->type == FUNC_PARAM_TYPE_VALUE) {
4,980✔
446
        // do nothing
447
      }
448
    }
449
  }
450

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

454
  for (int32_t i = 0; i < blockDataGetNumOfCols(pBlock); ++i) {
10,099,125✔
455
    SColumnInfoData* pColInfoData = taosArrayGet(pBlock->pDataBlock, i);
6,627,578✔
456
    QUERY_CHECK_NULL(pColInfoData, code, lino, _end, terrno);
6,629,726✔
457
    colDataSetNULL(pColInfoData, 0);
458
  }
459
  *ppBlock = pBlock;
3,471,547✔
460

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

469
void destroyDataBlockForEmptyInput(bool blockAllocated, SSDataBlock** ppBlock) {
624,249,283✔
470
  if (!blockAllocated) {
624,249,283✔
471
    return;
620,810,827✔
472
  }
473

474
  blockDataDestroy(*ppBlock);
3,438,456✔
475
  *ppBlock = NULL;
3,470,039✔
476
}
477

478
int32_t setExecutionContext(SOperatorInfo* pOperator, int32_t numOfOutput, uint64_t groupId) {
624,851,852✔
479
  int32_t           code = TSDB_CODE_SUCCESS;
624,851,852✔
480
  SAggOperatorInfo* pAggInfo = pOperator->info;
624,851,852✔
481
  if (pAggInfo->groupId != UINT64_MAX && pAggInfo->groupId == groupId) {
624,956,284✔
482
    return code;
432,179,363✔
483
  }
484

485
  code = doSetTableGroupOutputBuf(pOperator, numOfOutput, groupId);
192,768,628✔
486

487
  // record the current active group id
488
  pAggInfo->groupId = groupId;
192,758,423✔
489
  return code;
192,775,819✔
490
}
491

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

499
  SResultRowInfo* pResultRowInfo = &pAggInfo->binfo.resultRowInfo;
192,785,424✔
500
  SqlFunctionCtx* pCtx = pOperator->exprSupp.pCtx;
192,766,569✔
501
  int32_t*        rowEntryInfoOffset = pOperator->exprSupp.rowEntryInfoOffset;
192,776,104✔
502

503
  SResultRow* pResultRow =
504
      doSetResultOutBufByKey(pAggInfo->aggSup.pResultBuf, pResultRowInfo, (char*)&groupId, sizeof(groupId), true,
192,765,158✔
505
                             groupId, pTaskInfo, false, &pAggInfo->aggSup, true);
506
  if (pResultRow == NULL || pTaskInfo->code != 0) {
192,778,868✔
507
    code = pTaskInfo->code;
7,480✔
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) {
192,772,333✔
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);
192,772,598✔
521
  QUERY_CHECK_CODE(code, lino, _end);
192,777,344✔
522

523
_end:
192,777,344✔
524
  if (code != TSDB_CODE_SUCCESS) {
192,777,344✔
525
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
×
526
  }
527
  return code;
192,774,247✔
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,
279,172,503✔
588
                         const char* pKey) {
589
  int32_t code = 0;
279,172,503✔
590
  //  _hash_fn_t hashFn = taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY);
591

592
  pAggSup->currentPageId = -1;
279,172,503✔
593
  pAggSup->resultRowSize = getResultRowSize(pCtx, numOfOutput);
279,189,799✔
594
  pAggSup->keyBuf = taosMemoryCalloc(1, keyBufSize + POINTER_BYTES + sizeof(int64_t));
279,064,971✔
595
  pAggSup->pResultRowHashTable = tSimpleHashInit(100, taosFastHash);
279,153,123✔
596

597
  if (pAggSup->keyBuf == NULL || pAggSup->pResultRowHashTable == NULL) {
279,089,767✔
598
    return terrno;
×
599
  }
600

601
  uint32_t defaultPgsz = 0;
279,114,822✔
602
  int64_t defaultBufsz = 0;
279,097,377✔
603
  code = getBufferPgSize(pAggSup->resultRowSize, &defaultPgsz, &defaultBufsz);
279,100,423✔
604
  if (code) {
279,020,119✔
605
    qError("failed to get buff page size, rowSize:%d", pAggSup->resultRowSize);
×
606
    return code;
×
607
  }
608

609
  if (!osTempSpaceAvailable()) {
279,020,119✔
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);
279,175,087✔
616
  if (code != TSDB_CODE_SUCCESS) {
279,178,379✔
617
    qError("Create agg result buf failed since %s, %s", tstrerror(code), pKey);
×
618
    return code;
×
619
  }
620

621
  return code;
279,178,379✔
622
}
623

624
void cleanupResultInfoInGroupResInfo(SExecTaskInfo* pTaskInfo, SExprSupp* pSup, SDiskbasedBuf* pBuf,
96,386,979✔
625
                                  SGroupResInfo* pGroupResInfo) {
626
  int32_t         numOfExprs = pSup->numOfExprs;
96,386,979✔
627
  int32_t*        rowEntryOffset = pSup->rowEntryInfoOffset;
96,399,434✔
628
  SqlFunctionCtx* pCtx = pSup->pCtx;
96,383,878✔
629
  int32_t         numOfRows = getNumOfTotalRes(pGroupResInfo);
96,385,009✔
630
  bool            needCleanup = false;
96,369,446✔
631

632
  for (int32_t j = 0; j < numOfExprs; ++j) {
104,406,288✔
633
    needCleanup |= pCtx[j].needCleanup;
8,037,772✔
634
  }
635
  if (!needCleanup) {
96,368,516✔
636
    return;
96,369,587✔
637
  }
638

639
  for (int32_t i = pGroupResInfo->index; i < numOfRows; i += 1) {
26✔
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,
33,333,331✔
661
                       SGroupResInfo* pGroupResInfo, SSHashObj* pHashmap) {
662
  int32_t         numOfExprs = pSup->numOfExprs;
33,333,331✔
663
  int32_t*        rowEntryOffset = pSup->rowEntryInfoOffset;
33,333,491✔
664
  SqlFunctionCtx* pCtx = pSup->pCtx;
33,333,810✔
665
  bool            needCleanup = false;
33,330,104✔
666
  for (int32_t j = 0; j < numOfExprs; ++j) {
39,386,741✔
667
    needCleanup |= pCtx[j].needCleanup;
6,056,212✔
668
  }
669
  if (!needCleanup) {
33,330,529✔
670
    return;
33,332,572✔
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,
129,721,477✔
699
                       SAggSupporter *pAggSup, bool cleanGroupResInfo) {
700
  if (cleanGroupResInfo) {
129,721,477✔
701
    cleanupResultInfoInGroupResInfo(pTaskInfo, pSup, pAggSup->pResultBuf, pGroupResInfo);
96,389,494✔
702
  } else {
703
    cleanupResultInfoInHashMap(pTaskInfo, pSup, pAggSup->pResultBuf, pGroupResInfo, pAggSup->pResultRowHashTable);
33,331,983✔
704
  }
705
}
129,701,270✔
706
void cleanupAggSup(SAggSupporter* pAggSup) {
279,594,200✔
707
  taosMemoryFreeClear(pAggSup->keyBuf);
279,594,200✔
708
  tSimpleHashCleanup(pAggSup->pResultRowHashTable);
279,589,026✔
709
  destroyDiskbasedBuf(pAggSup->pResultBuf);
279,596,205✔
710
  memset(pAggSup, 0, sizeof(SAggSupporter));
279,575,526✔
711
}
279,575,526✔
712

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

720
  code = doInitAggInfoSup(pAggSup, pSup->pCtx, numOfCols, keyBufSize, pkey);
279,055,403✔
721
  if (code != TSDB_CODE_SUCCESS) {
279,162,627✔
722
    return code;
×
723
  }
724

725
  for (int32_t i = 0; i < numOfCols; ++i) {
1,142,941,280✔
726
    pSup->pCtx[i].hasWindowOrGroup = pSup->hasWindowOrGroup;
863,875,587✔
727
    pSup->pCtx[i].hasWindow= pSup->hasWindow;
863,860,758✔
728
    if (pState) {
863,734,866✔
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;
863,734,866✔
734
    }
735
  }
736

737
  return TSDB_CODE_SUCCESS;
279,065,693✔
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,276,031✔
759
      char* p = GET_ROWCELL_INTERBUF(pEntryInfo);
35,277,663✔
760

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

763
      SValueNode *valueNode = (SValueNode *)nodesListGetNode(pCtx[k].pExpr->base.pParamList, 0);
35,292,332✔
764
      pEntryInfo->isNullRes = 0;
35,290,743✔
765
      if (TSDB_DATA_TYPE_NULL == valueNode->node.resType.type || valueNode->isNull) {
35,290,302✔
766
        pEntryInfo->isNullRes = 1;
524✔
767
      } else if (IS_VAR_DATA_TYPE(pCtx[k].pExpr->base.resSchema.type)){
35,289,709✔
768
        void* v = nodesGetValueFromNode(valueNode);
11,592✔
769
        memcpy(p, v, varDataTLen(v));
9,944✔
770
      } else {
771
        memcpy(p, nodesGetValueFromNode(valueNode), pCtx[k].pExpr->base.resSchema.bytes);
35,286,621✔
772
      }
773
      
774
      pEntryInfo->numOfRes = 1;
35,292,096✔
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,385,292✔
835
  SAggOperatorInfo* pAgg = pOper->info;
4,385,292✔
836
  SAggPhysiNode*   pAggNode = (SAggPhysiNode*)pOper->pPhyNode;
4,385,292✔
837
  
838
  pOper->status = OP_NOT_OPENED;
4,385,717✔
839
  size_t keyBufSize = sizeof(int64_t) + sizeof(int64_t) + POINTER_BYTES;
4,385,940✔
840
  SExecTaskInfo*  pTaskInfo = pOper->pTaskInfo;
4,385,940✔
841
  cleanupResultInfo(pTaskInfo, &pOper->exprSupp, &pAgg->groupResInfo, &pAgg->aggSup,
4,385,909✔
842
                      pAgg->cleanGroupResInfo);
4,385,714✔
843
  cleanupGroupResInfo(&pAgg->groupResInfo);
4,384,241✔
844
  resetBasicOperatorState(&pAgg->binfo);
4,383,782✔
845
  
846
  pAgg->pNewGroupBlock = NULL;
4,385,724✔
847

848
  int32_t code = resetAggSup(&pOper->exprSupp, &pAgg->aggSup, pTaskInfo, pAggNode->pAggFuncs, pAggNode->pGroupKeys,
8,771,460✔
849
    keyBufSize, pTaskInfo->id.str, pTaskInfo->streamInfo.pState, &pTaskInfo->storageAPI.functionStore);
4,385,724✔
850

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

856
  pAgg->groupId = UINT64_MAX;
4,384,530✔
857
  pAgg->cleanGroupResInfo = false;
4,384,962✔
858
  pAgg->hasValidBlock = false;
4,384,746✔
859
  return 0;
4,385,470✔
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