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

taosdata / TDengine / #4759

25 Sep 2025 05:58AM UTC coverage: 58.866% (+0.03%) from 58.832%
#4759

push

travis-ci

web-flow
enh: taos command line support '-uroot' on windows (#33055)

135700 of 293169 branches covered (46.29%)

Branch coverage included in aggregate %.

204479 of 284720 relevant lines covered (71.82%)

25399510.59 hits per line

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

62.35
/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,
3,657,335✔
77
                                    SOperatorInfo** pOptrInfo) {
78
  QRY_PARAM_CHECK(pOptrInfo);
3,657,335!
79

80
  int32_t    lino = 0;
3,657,335✔
81
  int32_t    code = 0;
3,657,335✔
82
  int32_t    num = 0;
3,657,335✔
83
  SExprInfo* pExprInfo = NULL;
3,657,335✔
84
  int32_t    numOfScalarExpr = 0;
3,657,335✔
85
  SExprInfo* pScalarExprInfo = NULL;
3,657,335✔
86

87
  SAggOperatorInfo* pInfo = taosMemoryCalloc(1, sizeof(SAggOperatorInfo));
3,657,335!
88
  SOperatorInfo*    pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo));
3,658,127!
89
  if (pInfo == NULL || pOperator == NULL) {
3,658,855!
90
    code = terrno;
×
91
    goto _error;
×
92
  }
93

94
  pOperator->exprSupp.hasWindowOrGroup = false;
3,659,125✔
95

96
  SSDataBlock* pResBlock = createDataBlockFromDescNode(pAggNode->node.pOutputDataBlockDesc);
3,659,125✔
97
  QUERY_CHECK_NULL(pResBlock, code, lino, _error, terrno);
3,660,633!
98
  initBasicInfo(&pInfo->binfo, pResBlock);
3,660,633✔
99

100
  size_t keyBufSize = sizeof(int64_t) + sizeof(int64_t) + POINTER_BYTES;
3,660,844✔
101
  initResultSizeInfo(&pOperator->resultInfo, 4096);
3,660,844✔
102

103

104
  code = createExprInfo(pAggNode->pAggFuncs, pAggNode->pGroupKeys, &pExprInfo, &num);
3,661,340✔
105
  TSDB_CHECK_CODE(code, lino, _error);
3,659,370!
106

107
  code = initAggSup(&pOperator->exprSupp, &pInfo->aggSup, pExprInfo, num, keyBufSize, pTaskInfo->id.str,
3,659,370✔
108
                               pTaskInfo->streamInfo.pState, &pTaskInfo->storageAPI.functionStore);
3,659,370✔
109
  TSDB_CHECK_CODE(code, lino, _error);
3,658,789!
110

111
  if (pAggNode->pExprs != NULL) {
3,658,789✔
112
    code = createExprInfo(pAggNode->pExprs, NULL, &pScalarExprInfo, &numOfScalarExpr);
229,079✔
113
    TSDB_CHECK_CODE(code, lino, _error);
229,097!
114
  }
115

116
  code = initExprSupp(&pInfo->scalarExprSup, pScalarExprInfo, numOfScalarExpr, &pTaskInfo->storageAPI.functionStore);
3,658,807✔
117
  TSDB_CHECK_CODE(code, lino, _error);
3,658,970!
118

119
  code = filterInitFromNode((SNode*)pAggNode->node.pConditions, &pOperator->exprSupp.pFilterInfo, 0,
3,658,970✔
120
                            GET_STM_RTINFO(pTaskInfo));
3,658,970✔
121
  TSDB_CHECK_CODE(code, lino, _error);
3,657,974!
122

123
  pInfo->binfo.mergeResultBlock = pAggNode->mergeDataBlock;
3,657,974✔
124
  pInfo->groupKeyOptimized = pAggNode->groupKeyOptimized;
3,657,974✔
125
  pInfo->groupId = UINT64_MAX;
3,657,974✔
126
  pInfo->binfo.inputTsOrder = pAggNode->node.inputTsOrder;
3,657,974✔
127
  pInfo->binfo.outputTsOrder = pAggNode->node.outputTsOrder;
3,657,974✔
128
  pInfo->hasCountFunc = pAggNode->hasCountLikeFunc;
3,657,974✔
129
  pInfo->pOperator = pOperator;
3,657,974✔
130
  pInfo->cleanGroupResInfo = false;
3,657,974✔
131

132
  setOperatorInfo(pOperator, "TableAggregate", QUERY_NODE_PHYSICAL_PLAN_HASH_AGG,
3,657,974✔
133
                  !pAggNode->node.forceCreateNonBlockingOptr, OP_NOT_OPENED, pInfo, pTaskInfo);
3,657,974✔
134
  pOperator->fpSet = createOperatorFpSet(optrDummyOpenFn, getAggregateResultNext, NULL, destroyAggOperatorInfo,
3,659,350✔
135
                                         optrDefaultBufFn, NULL, optrDefaultGetNextExtFn, NULL);
136
  setOperatorResetStateFn(pOperator, resetAggregateOperatorState);
3,658,002✔
137

138
  pOperator->pPhyNode = pAggNode;
3,658,462✔
139

140
  if (downstream->operatorType == QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN) {
3,658,462✔
141
    STableScanInfo* pTableScanInfo = downstream->info;
761,957✔
142
    pTableScanInfo->base.pdInfo.pExprSup = &pOperator->exprSupp;
761,957✔
143
    pTableScanInfo->base.pdInfo.pAggSup = &pInfo->aggSup;
761,957✔
144
  }
145

146
  code = appendDownstream(pOperator, &downstream, 1);
3,658,462✔
147
  if (code != TSDB_CODE_SUCCESS) {
3,661,060!
148
    goto _error;
×
149
  }
150

151
  *pOptrInfo = pOperator;
3,661,060✔
152
  return TSDB_CODE_SUCCESS;
3,661,060✔
153

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

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

171
  if (pInfo->pOperator) {
3,663,072!
172
    cleanupResultInfo(pInfo->pOperator->pTaskInfo, &pInfo->pOperator->exprSupp, &pInfo->groupResInfo, &pInfo->aggSup,
3,663,084✔
173
                      pInfo->cleanGroupResInfo);
3,663,084✔
174
    pInfo->pOperator = NULL;
3,661,810✔
175
  }
176
  cleanupAggSup(&pInfo->aggSup);
3,661,798✔
177
  cleanupExprSuppWithoutFilter(&pInfo->scalarExprSup);
3,663,069✔
178
  cleanupGroupResInfo(&pInfo->groupResInfo);
3,662,107✔
179
  taosMemoryFreeClear(param);
3,662,966!
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) {
3,736,035✔
190
  int32_t           code = TSDB_CODE_SUCCESS;
3,736,035✔
191
  int32_t           lino = 0;
3,736,035✔
192
  SExecTaskInfo*    pTaskInfo = pOperator->pTaskInfo;
3,736,035✔
193
  SAggOperatorInfo* pAggInfo = pOperator->info;
3,736,035✔
194

195
  if(!pAggInfo) {
3,736,035!
196
    qError("function:%s, pAggInfo is NULL", __func__);
×
197
    return false;
×
198
  }
199
  if (pOperator->blocking && pAggInfo->hasValidBlock) {
3,736,035!
200
    return false;
74,250✔
201
  }
202

203
  SExprSupp*   pSup = &pOperator->exprSupp;
3,661,785✔
204
  int64_t      st = taosGetTimestampUs();
3,668,958✔
205
  int32_t      order = pAggInfo->binfo.inputTsOrder;
3,668,958✔
206
  SSDataBlock* pBlock = pAggInfo->pNewGroupBlock;
3,668,958✔
207

208
  pAggInfo->cleanGroupResInfo = false;
3,668,958✔
209
  if (pBlock) {
3,668,958✔
210
    pAggInfo->pNewGroupBlock = NULL;
1,619✔
211
    tSimpleHashClear(pAggInfo->aggSup.pResultRowHashTable);
1,619✔
212
    code = setExecutionContext(pOperator, pOperator->exprSupp.numOfExprs, pBlock->info.id.groupId);
1,619✔
213
    QUERY_CHECK_CODE(code, lino, _end);
1,619!
214
    code = setInputDataBlock(pSup, pBlock, order, pBlock->info.scanFlag, true);
1,619✔
215
    QUERY_CHECK_CODE(code, lino, _end);
1,619!
216

217
    code = doAggregateImpl(pOperator, pSup->pCtx);
1,619✔
218
    QUERY_CHECK_CODE(code, lino, _end);
1,619!
219
  }
220
  while (1) {
21,404,641✔
221
    bool blockAllocated = false;
25,073,599✔
222
    pBlock = getNextBlockFromDownstream(pOperator, 0);
25,073,599✔
223
    if (pBlock == NULL) {
25,062,967✔
224
      if (!pAggInfo->hasValidBlock) {
4,047,743✔
225
        code = createDataBlockForEmptyInput(pOperator, &pBlock);
524,552✔
226
        QUERY_CHECK_CODE(code, lino, _end);
524,307!
227

228
        if (pBlock == NULL) {
524,307✔
229
          break;
140,590✔
230
        }
231
        blockAllocated = true;
383,717✔
232
      } else {
233
        break;
3,523,191✔
234
      }
235
    }
236
    pAggInfo->hasValidBlock = true;
21,398,941✔
237
    pAggInfo->binfo.pRes->info.scanFlag = pBlock->info.scanFlag;
21,398,941✔
238

239
    // there is an scalar expression that needs to be calculated before apply the group aggregation.
240
    if (pAggInfo->scalarExprSup.pExprInfo != NULL && !blockAllocated) {
21,398,941✔
241
      SExprSupp* pSup1 = &pAggInfo->scalarExprSup;
2,647,961✔
242
      code = projectApplyFunctions(pSup1->pExprInfo, pBlock, pBlock, pSup1->pCtx, pSup1->numOfExprs, NULL, GET_STM_RTINFO(pOperator->pTaskInfo));
2,647,961✔
243
      if (code != TSDB_CODE_SUCCESS) {
2,647,891!
244
        destroyDataBlockForEmptyInput(blockAllocated, &pBlock);
×
245
        T_LONG_JMP(pTaskInfo->env, code);
×
246
      }
247
    }
248
    // if non-blocking mode and new group arrived, save the block and break
249
    if (!pOperator->blocking && pAggInfo->groupId != UINT64_MAX && pBlock->info.id.groupId != pAggInfo->groupId) {
21,398,871✔
250
      pAggInfo->pNewGroupBlock = pBlock;
1,643✔
251
      break;
1,643✔
252
    }
253
    // the pDataBlock are always the same one, no need to call this again
254
    code = setExecutionContext(pOperator, pOperator->exprSupp.numOfExprs, pBlock->info.id.groupId);
21,397,228✔
255
    if (code != TSDB_CODE_SUCCESS) {
21,402,578✔
256
      destroyDataBlockForEmptyInput(blockAllocated, &pBlock);
8✔
257
      T_LONG_JMP(pTaskInfo->env, code);
8!
258
    }
259
    code = setInputDataBlock(pSup, pBlock, order, pBlock->info.scanFlag, true);
21,402,570✔
260
    if (code != TSDB_CODE_SUCCESS) {
21,401,443!
261
      destroyDataBlockForEmptyInput(blockAllocated, &pBlock);
×
262
      T_LONG_JMP(pTaskInfo->env, code);
×
263
    }
264

265
    code = doAggregateImpl(pOperator, pSup->pCtx);
21,401,443✔
266
    if (code != TSDB_CODE_SUCCESS) {
21,404,532!
267
      destroyDataBlockForEmptyInput(blockAllocated, &pBlock);
×
268
      T_LONG_JMP(pTaskInfo->env, code);
×
269
    }
270

271
    destroyDataBlockForEmptyInput(blockAllocated, &pBlock);
21,404,532✔
272
  }
273

274
  // the downstream operator may return with error code, so let's check the code before generating results.
275
  if (pTaskInfo->code != TSDB_CODE_SUCCESS) {
3,665,424!
276
    T_LONG_JMP(pTaskInfo->env, pTaskInfo->code);
×
277
  }
278

279
  code = initGroupedResultInfo(&pAggInfo->groupResInfo, pAggInfo->aggSup.pResultRowHashTable, 0);
3,665,424✔
280
  QUERY_CHECK_CODE(code, lino, _end);
3,664,912!
281
  pAggInfo->cleanGroupResInfo = true;
3,664,912✔
282

283
_end:
3,664,912✔
284
  if (code != TSDB_CODE_SUCCESS) {
3,664,912!
285
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
×
286
    pTaskInfo->code = code;
×
287
    T_LONG_JMP(pTaskInfo->env, code);
×
288
  }
289
  return pBlock != NULL;
3,664,912✔
290
}
291

292
int32_t getAggregateResultNext(SOperatorInfo* pOperator, SSDataBlock** ppRes) {
7,236,703✔
293
  int32_t           code = TSDB_CODE_SUCCESS;
7,236,703✔
294
  int32_t           lino = 0;
7,236,703✔
295
  SAggOperatorInfo* pAggInfo = pOperator->info;
7,236,703✔
296
  SOptrBasicInfo*   pInfo = &pAggInfo->binfo;
7,236,703✔
297

298
  if (pOperator->status == OP_EXEC_DONE) {
7,236,703✔
299
    (*ppRes) = NULL;
3,501,094✔
300
    return code;
3,501,094✔
301
  }
302

303
  SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
3,735,609✔
304
  bool           hasNewGroups = false;
3,735,609✔
305
  do {
306
    hasNewGroups = nextGroupedResult(pOperator);
3,735,638✔
307
    code = blockDataEnsureCapacity(pInfo->pRes, pOperator->resultInfo.capacity);
3,739,000✔
308
    QUERY_CHECK_CODE(code, lino, _end);
3,739,386!
309

310
    while (1) {
311
      doBuildResultDatablock(pOperator, pInfo, &pAggInfo->groupResInfo, pAggInfo->aggSup.pResultBuf);
3,739,386✔
312
      code = doFilter(pInfo->pRes, pOperator->exprSupp.pFilterInfo, NULL);
3,735,294✔
313
      QUERY_CHECK_CODE(code, lino, _end);
3,735,617!
314

315
      if (!hasRemainResults(&pAggInfo->groupResInfo)) {
3,735,617✔
316
        if (!hasNewGroups) setOperatorCompleted(pOperator);
3,663,177✔
317
        break;
3,664,443✔
318
      }
319

320
      if (pInfo->pRes->info.rows > 0) {
74,256!
321
        break;
74,256✔
322
      }
323
    }
324
  } while (pInfo->pRes->info.rows == 0 && hasNewGroups);
3,738,699✔
325

326
  size_t rows = blockDataGetNumOfRows(pInfo->pRes);
3,738,670✔
327
  pOperator->resultInfo.totalRows += rows;
3,737,247✔
328

329
_end:
3,737,247✔
330
  if (code != TSDB_CODE_SUCCESS) {
3,737,247!
331
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
×
332
    pTaskInfo->code = code;
×
333
    T_LONG_JMP(pTaskInfo->env, code);
×
334
  }
335

336
  (*ppRes) = (rows == 0) ? NULL : pInfo->pRes;
3,737,247✔
337
  return code;
3,737,247✔
338
}
339

340
int32_t doAggregateImpl(SOperatorInfo* pOperator, SqlFunctionCtx* pCtx) {
21,402,473✔
341
  int32_t code = TSDB_CODE_SUCCESS;
21,402,473✔
342
  if (!pOperator || (pOperator->exprSupp.numOfExprs > 0 && pCtx == NULL)) {
21,402,473!
343
    qError("%s failed at line %d since pCtx is NULL.", __func__, __LINE__);
×
344
    return TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR;
×
345
  }
346
  for (int32_t k = 0; k < pOperator->exprSupp.numOfExprs; ++k) {
44,980,295✔
347
    if (functionNeedToExecute(&pCtx[k])) {
23,572,986✔
348
      // todo add a dummy function to avoid process check
349
      if (pCtx[k].fpSet.process == NULL) {
23,572,984✔
350
        continue;
422,437✔
351
      }
352

353
      if ((&pCtx[k])->input.pData[0] == NULL) {
23,150,547!
354
        code = TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR;
×
355
        qError("%s aggregate function error happens, input data is NULL.", GET_TASKID(pOperator->pTaskInfo));
×
356
      } else {
357
        code = pCtx[k].fpSet.process(&pCtx[k]);
23,150,547✔
358
      }
359

360
      if (code != TSDB_CODE_SUCCESS) {
23,153,972!
361
        if (pCtx[k].fpSet.cleanup != NULL) {
×
362
          pCtx[k].fpSet.cleanup(&pCtx[k]);
×
363
        }
364
        qError("%s aggregate function error happens, code:%s", GET_TASKID(pOperator->pTaskInfo), tstrerror(code));
×
365
        return code;
×
366
      }
367
    }
368
  }
369

370
  return TSDB_CODE_SUCCESS;
21,407,309✔
371
}
372

373
static int32_t createDataBlockForEmptyInput(SOperatorInfo* pOperator, SSDataBlock** ppBlock) {
524,403✔
374
  int32_t code = TSDB_CODE_SUCCESS;
524,403✔
375
  int32_t lino = 0;
524,403✔
376
  SSDataBlock* pBlock = NULL;
524,403✔
377
  if (!tsCountAlwaysReturnValue) {
524,403✔
378
    return TSDB_CODE_SUCCESS;
47,957✔
379
  }
380

381
  SAggOperatorInfo* pAggInfo = pOperator->info;
476,446✔
382
  if (pAggInfo->groupKeyOptimized) {
476,446✔
383
    return TSDB_CODE_SUCCESS;
48,064✔
384
  }
385

386
  SOperatorInfo* downstream = pOperator->pDownstream[0];
428,382✔
387
  if (downstream->operatorType == QUERY_NODE_PHYSICAL_PLAN_PARTITION ||
428,382✔
388
      downstream->operatorType == QUERY_NODE_PHYSICAL_PLAN_SORT ||
428,319✔
389
      (downstream->operatorType == QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN &&
428,226✔
390
       ((STableScanInfo*)downstream->info)->hasGroupByTag == true)) {
46,087✔
391
    return TSDB_CODE_SUCCESS;
306✔
392
  }
393

394
  SqlFunctionCtx* pCtx = pOperator->exprSupp.pCtx;
428,076✔
395

396
  if (!pAggInfo->hasCountFunc) {
428,076✔
397
    return TSDB_CODE_SUCCESS;
44,260✔
398
  }
399

400
  code = createDataBlock(&pBlock);
383,816✔
401
  if (code) {
383,928!
402
    return code;
×
403
  }
404

405
  pBlock->info.rows = 1;
383,928✔
406
  pBlock->info.capacity = 0;
383,928✔
407

408
  for (int32_t i = 0; i < pOperator->exprSupp.numOfExprs; ++i) {
782,771✔
409
    SColumnInfoData colInfo = {0};
399,053✔
410
    colInfo.hasNull = true;
399,053✔
411
    colInfo.info.type = TSDB_DATA_TYPE_NULL;
399,053✔
412
    colInfo.info.bytes = 1;
399,053✔
413

414
    SExprInfo* pOneExpr = &pOperator->exprSupp.pExprInfo[i];
399,053✔
415
    for (int32_t j = 0; j < pOneExpr->base.numOfParams; ++j) {
798,469✔
416
      SFunctParam* pFuncParam = &pOneExpr->base.pParam[j];
399,626✔
417
      if (pFuncParam->type == FUNC_PARAM_TYPE_COLUMN) {
399,626✔
418
        int32_t slotId = pFuncParam->pCol->slotId;
399,598✔
419
        int32_t numOfCols = taosArrayGetSize(pBlock->pDataBlock);
399,598✔
420
        if (slotId >= numOfCols) {
399,473✔
421
          code = taosArrayEnsureCap(pBlock->pDataBlock, slotId + 1);
384,695✔
422
          QUERY_CHECK_CODE(code, lino, _end);
384,603!
423

424
          for (int32_t k = numOfCols; k < slotId + 1; ++k) {
778,917✔
425
            void* tmp = taosArrayPush(pBlock->pDataBlock, &colInfo);
394,307✔
426
            QUERY_CHECK_NULL(tmp, code, lino, _end, terrno);
394,314!
427
          }
428
        }
429
      } else if (pFuncParam->type == FUNC_PARAM_TYPE_VALUE) {
28✔
430
        // do nothing
431
      }
432
    }
433
  }
434

435
  code = blockDataEnsureCapacity(pBlock, pBlock->info.rows);
383,718✔
436
  QUERY_CHECK_CODE(code, lino, _end);
383,949!
437

438
  for (int32_t i = 0; i < blockDataGetNumOfCols(pBlock); ++i) {
777,826✔
439
    SColumnInfoData* pColInfoData = taosArrayGet(pBlock->pDataBlock, i);
394,030✔
440
    QUERY_CHECK_NULL(pColInfoData, code, lino, _end, terrno);
393,864!
441
    colDataSetNULL(pColInfoData, 0);
442
  }
443
  *ppBlock = pBlock;
383,739✔
444

445
_end:
383,739✔
446
  if (code != TSDB_CODE_SUCCESS) {
383,739!
447
    blockDataDestroy(pBlock);
×
448
    qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(code));
×
449
  }
450
  return code;
383,680✔
451
}
452

453
void destroyDataBlockForEmptyInput(bool blockAllocated, SSDataBlock** ppBlock) {
21,404,614✔
454
  if (!blockAllocated) {
21,404,614✔
455
    return;
21,021,256✔
456
  }
457

458
  blockDataDestroy(*ppBlock);
383,358✔
459
  *ppBlock = NULL;
383,954✔
460
}
461

462
int32_t setExecutionContext(SOperatorInfo* pOperator, int32_t numOfOutput, uint64_t groupId) {
21,404,039✔
463
  int32_t           code = TSDB_CODE_SUCCESS;
21,404,039✔
464
  SAggOperatorInfo* pAggInfo = pOperator->info;
21,404,039✔
465
  if (pAggInfo->groupId != UINT64_MAX && pAggInfo->groupId == groupId) {
21,404,039✔
466
    return code;
17,187,871✔
467
  }
468

469
  code = doSetTableGroupOutputBuf(pOperator, numOfOutput, groupId);
4,216,168✔
470

471
  // record the current active group id
472
  pAggInfo->groupId = groupId;
4,216,463✔
473
  return code;
4,216,463✔
474
}
475

476
int32_t doSetTableGroupOutputBuf(SOperatorInfo* pOperator, int32_t numOfOutput, uint64_t groupId) {
4,216,655✔
477
  // for simple group by query without interval, all the tables belong to one group result.
478
  int32_t           code = TSDB_CODE_SUCCESS;
4,216,655✔
479
  int32_t           lino = 0;
4,216,655✔
480
  SExecTaskInfo*    pTaskInfo = pOperator->pTaskInfo;
4,216,655✔
481
  SAggOperatorInfo* pAggInfo = pOperator->info;
4,216,655✔
482

483
  SResultRowInfo* pResultRowInfo = &pAggInfo->binfo.resultRowInfo;
4,216,655✔
484
  SqlFunctionCtx* pCtx = pOperator->exprSupp.pCtx;
4,216,655✔
485
  int32_t*        rowEntryInfoOffset = pOperator->exprSupp.rowEntryInfoOffset;
4,216,655✔
486

487
  SResultRow* pResultRow =
488
      doSetResultOutBufByKey(pAggInfo->aggSup.pResultBuf, pResultRowInfo, (char*)&groupId, sizeof(groupId), true,
4,216,655✔
489
                             groupId, pTaskInfo, false, &pAggInfo->aggSup, true);
490
  if (pResultRow == NULL || pTaskInfo->code != 0) {
4,217,439!
491
    code = pTaskInfo->code;
×
492
    lino = __LINE__;
×
493
    goto _end;
×
494
  }
495
  /*
496
   * not assign result buffer yet, add new result buffer
497
   * all group belong to one result set, and each group result has different group id so set the id to be one
498
   */
499
  if (pResultRow->pageId == -1) {
4,217,442!
500
    code = addNewResultRowBuf(pResultRow, pAggInfo->aggSup.pResultBuf, pAggInfo->binfo.pRes->info.rowSize);
×
501
    QUERY_CHECK_CODE(code, lino, _end);
×
502
  }
503

504
  code = setResultRowInitCtx(pResultRow, pCtx, numOfOutput, rowEntryInfoOffset);
4,217,442✔
505
  QUERY_CHECK_CODE(code, lino, _end);
4,216,889!
506

507
_end:
4,216,889✔
508
  if (code != TSDB_CODE_SUCCESS) {
4,216,886✔
509
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
8!
510
  }
511
  return code;
4,216,443✔
512
}
513

514
// a new buffer page for each table. Needs to opt this design
515
int32_t addNewResultRowBuf(SResultRow* pWindowRes, SDiskbasedBuf* pResultBuf, uint32_t size) {
×
516
  if (pWindowRes->pageId != -1) {
×
517
    return 0;
×
518
  }
519

520
  SFilePage* pData = NULL;
×
521

522
  // in the first scan, new space needed for results
523
  int32_t pageId = -1;
×
524
  SArray* list = getDataBufPagesIdList(pResultBuf);
×
525

526
  if (taosArrayGetSize(list) == 0) {
×
527
    pData = getNewBufPage(pResultBuf, &pageId);
×
528
    if (pData == NULL) {
×
529
      qError("failed to get buffer, code:%s", tstrerror(terrno));
×
530
      return terrno;
×
531
    }
532
    pData->num = sizeof(SFilePage);
×
533
  } else {
534
    SPageInfo* pi = getLastPageInfo(list);
×
535
    pData = getBufPage(pResultBuf, getPageId(pi));
×
536
    if (pData == NULL) {
×
537
      qError("failed to get buffer, code:%s", tstrerror(terrno));
×
538
      return terrno;
×
539
    }
540

541
    pageId = getPageId(pi);
×
542

543
    if (pData->num + size > getBufPageSize(pResultBuf)) {
×
544
      // release current page first, and prepare the next one
545
      releaseBufPageInfo(pResultBuf, pi);
×
546

547
      pData = getNewBufPage(pResultBuf, &pageId);
×
548
      if (pData == NULL) {
×
549
        qError("failed to get buffer, code:%s", tstrerror(terrno));
×
550
        return terrno;
×
551
      }
552
      pData->num = sizeof(SFilePage);
×
553
    }
554
  }
555

556
  if (pData == NULL) {
×
557
    return -1;
×
558
  }
559

560
  // set the number of rows in current disk page
561
  if (pWindowRes->pageId == -1) {  // not allocated yet, allocate new buffer
×
562
    pWindowRes->pageId = pageId;
×
563
    pWindowRes->offset = (int32_t)pData->num;
×
564

565
    pData->num += size;
×
566
  }
567

568
  return 0;
×
569
}
570

571
int32_t doInitAggInfoSup(SAggSupporter* pAggSup, SqlFunctionCtx* pCtx, int32_t numOfOutput, size_t keyBufSize,
11,571,496✔
572
                         const char* pKey) {
573
  int32_t code = 0;
11,571,496✔
574
  //  _hash_fn_t hashFn = taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY);
575

576
  pAggSup->currentPageId = -1;
11,571,496✔
577
  pAggSup->resultRowSize = getResultRowSize(pCtx, numOfOutput);
11,571,496✔
578
  pAggSup->keyBuf = taosMemoryCalloc(1, keyBufSize + POINTER_BYTES + sizeof(int64_t));
11,580,815!
579
  pAggSup->pResultRowHashTable = tSimpleHashInit(100, taosFastHash);
11,582,586✔
580

581
  if (pAggSup->keyBuf == NULL || pAggSup->pResultRowHashTable == NULL) {
11,574,115!
582
    return terrno;
×
583
  }
584

585
  uint32_t defaultPgsz = 0;
11,575,716✔
586
  int64_t defaultBufsz = 0;
11,575,716✔
587
  code = getBufferPgSize(pAggSup->resultRowSize, &defaultPgsz, &defaultBufsz);
11,575,716✔
588
  if (code) {
11,582,007!
589
    qError("failed to get buff page size, rowSize:%d", pAggSup->resultRowSize);
×
590
    return code;
×
591
  }
592

593
  if (!osTempSpaceAvailable()) {
11,582,007!
594
    code = TSDB_CODE_NO_DISKSPACE;
×
595
    qError("Init stream agg supporter failed since %s, key:%s, tempDir:%s", tstrerror(code), pKey, tsTempDir);
×
596
    return code;
×
597
  }
598

599
  code = createDiskbasedBuf(&pAggSup->pResultBuf, defaultPgsz, defaultBufsz, pKey, tsTempDir);
11,579,698✔
600
  if (code != TSDB_CODE_SUCCESS) {
11,583,616!
601
    qError("Create agg result buf failed since %s, %s", tstrerror(code), pKey);
×
602
    return code;
×
603
  }
604

605
  return code;
11,584,645✔
606
}
607

608
void cleanupResultInfoInStream(SExecTaskInfo* pTaskInfo, void* pState, SExprSupp* pSup, SGroupResInfo* pGroupResInfo) {
×
609
  int32_t         code = TSDB_CODE_SUCCESS;
×
610
  SStorageAPI*    pAPI = &pTaskInfo->storageAPI;
×
611
  int32_t         numOfExprs = pSup->numOfExprs;
×
612
  int32_t*        rowEntryOffset = pSup->rowEntryInfoOffset;
×
613
  SqlFunctionCtx* pCtx = pSup->pCtx;
×
614
  int32_t         numOfRows = getNumOfTotalRes(pGroupResInfo);
×
615
  bool            needCleanup = false;
×
616

617
  for (int32_t j = 0; j < numOfExprs; ++j) {
×
618
    needCleanup |= pCtx[j].needCleanup;
×
619
  }
620
  if (!needCleanup) {
×
621
    return;
×
622
  }
623
  
624
  for (int32_t i = pGroupResInfo->index; i < numOfRows; i += 1) {
×
625
    SResultWindowInfo* pWinInfo = taosArrayGet(pGroupResInfo->pRows, i);
×
626
    SRowBuffPos*       pPos = pWinInfo->pStatePos;
×
627
    SResultRow*        pRow = NULL;
×
628

629
    code = pAPI->stateStore.streamStateGetByPos(pState, pPos, (void**)&pRow);
×
630
    if (TSDB_CODE_SUCCESS != code) {
×
631
      qError("failed to get state by pos, code:%s, %s", tstrerror(code), GET_TASKID(pTaskInfo));
×
632
      continue;
×
633
    }
634

635
    for (int32_t j = 0; j < numOfExprs; ++j) {
×
636
      pCtx[j].resultInfo = getResultEntryInfo(pRow, j, rowEntryOffset);
×
637
      if (pCtx[j].fpSet.cleanup) {
×
638
        pCtx[j].fpSet.cleanup(&pCtx[j]);
×
639
      }
640
    }
641
  }
642
}
643

644
void cleanupResultInfoInGroupResInfo(SExecTaskInfo* pTaskInfo, SExprSupp* pSup, SDiskbasedBuf* pBuf,
6,510,302✔
645
                                  SGroupResInfo* pGroupResInfo) {
646
  int32_t         numOfExprs = pSup->numOfExprs;
6,510,302✔
647
  int32_t*        rowEntryOffset = pSup->rowEntryInfoOffset;
6,510,302✔
648
  SqlFunctionCtx* pCtx = pSup->pCtx;
6,510,302✔
649
  int32_t         numOfRows = getNumOfTotalRes(pGroupResInfo);
6,510,302✔
650
  bool            needCleanup = false;
6,510,088✔
651

652
  for (int32_t j = 0; j < numOfExprs; ++j) {
17,467,536✔
653
    needCleanup |= pCtx[j].needCleanup;
10,957,448✔
654
  }
655
  if (!needCleanup) {
6,510,088✔
656
    return;
6,477,061✔
657
  }
658

659
  for (int32_t i = pGroupResInfo->index; i < numOfRows; i += 1) {
33,027!
660
    SResultRow*        pRow = NULL;
×
661
    SResKeyPos*        pPos = taosArrayGetP(pGroupResInfo->pRows, i);
×
662
    SFilePage*         page = getBufPage(pBuf, pPos->pos.pageId);
×
663
    if (page == NULL) {
×
664
      qError("failed to get buffer, code:%s, %s", tstrerror(terrno), GET_TASKID(pTaskInfo));
×
665
      continue;
×
666
    }
667
    pRow = (SResultRow*)((char*)page + pPos->pos.offset);
×
668

669

670
    for (int32_t j = 0; j < numOfExprs; ++j) {
×
671
      pCtx[j].resultInfo = getResultEntryInfo(pRow, j, rowEntryOffset);
×
672
      if (pCtx[j].fpSet.cleanup) {
×
673
        pCtx[j].fpSet.cleanup(&pCtx[j]);
×
674
      }
675
    }
676
    releaseBufPage(pBuf, page);
×
677
  }
678
}
679

680
void cleanupResultInfoInHashMap(SExecTaskInfo* pTaskInfo, SExprSupp* pSup, SDiskbasedBuf* pBuf,
1,520,735✔
681
                       SGroupResInfo* pGroupResInfo, SSHashObj* pHashmap) {
682
  int32_t         numOfExprs = pSup->numOfExprs;
1,520,735✔
683
  int32_t*        rowEntryOffset = pSup->rowEntryInfoOffset;
1,520,735✔
684
  SqlFunctionCtx* pCtx = pSup->pCtx;
1,520,735✔
685
  bool            needCleanup = false;
1,520,735✔
686
  for (int32_t j = 0; j < numOfExprs; ++j) {
4,464,376✔
687
    needCleanup |= pCtx[j].needCleanup;
2,943,641✔
688
  }
689
  if (!needCleanup) {
1,520,735✔
690
    return;
1,517,960✔
691
  }
692

693
  // begin from last iter
694
  void*   pData = pGroupResInfo->dataPos;
2,775✔
695
  int32_t iter = pGroupResInfo->iter;
2,775✔
696
  while ((pData = tSimpleHashIterate(pHashmap, pData, &iter)) != NULL) {
2,777✔
697
    SResultRowPosition* pos = pData;
2✔
698

699
    SFilePage* page = getBufPage(pBuf, pos->pageId);
2✔
700
    if (page == NULL) {
2!
701
      qError("failed to get buffer, code:%s, %s", tstrerror(terrno), GET_TASKID(pTaskInfo));
×
702
      continue;
×
703
    }
704

705
    SResultRow* pRow = (SResultRow*)((char*)page + pos->offset);
2✔
706

707
    for (int32_t j = 0; j < numOfExprs; ++j) {
42✔
708
      pCtx[j].resultInfo = getResultEntryInfo(pRow, j, rowEntryOffset);
40✔
709
      if (pCtx[j].fpSet.cleanup) {
40✔
710
        pCtx[j].fpSet.cleanup(&pCtx[j]);
4✔
711
      }
712
    }
713

714
    releaseBufPage(pBuf, page);
2✔
715
  }
716
}
717

718
void cleanupResultInfo(SExecTaskInfo* pTaskInfo, SExprSupp* pSup, SGroupResInfo* pGroupResInfo,
8,031,075✔
719
                       SAggSupporter *pAggSup, bool cleanGroupResInfo) {
720
  if (cleanGroupResInfo) {
8,031,075✔
721
    cleanupResultInfoInGroupResInfo(pTaskInfo, pSup, pAggSup->pResultBuf, pGroupResInfo);
6,511,063✔
722
  } else {
723
    cleanupResultInfoInHashMap(pTaskInfo, pSup, pAggSup->pResultBuf, pGroupResInfo, pAggSup->pResultRowHashTable);
1,520,012✔
724
  }
725
}
8,031,482✔
726
void cleanupAggSup(SAggSupporter* pAggSup) {
11,588,601✔
727
  taosMemoryFreeClear(pAggSup->keyBuf);
11,588,601!
728
  tSimpleHashCleanup(pAggSup->pResultRowHashTable);
11,590,008✔
729
  destroyDiskbasedBuf(pAggSup->pResultBuf);
11,591,309✔
730
  memset(pAggSup, 0, sizeof(SAggSupporter));
11,591,707✔
731
}
11,591,707✔
732

733
int32_t initAggSup(SExprSupp* pSup, SAggSupporter* pAggSup, SExprInfo* pExprInfo, int32_t numOfCols, size_t keyBufSize,
11,579,535✔
734
                   const char* pkey, void* pState, SFunctionStateStore* pStore) {
735
  int32_t code = initExprSupp(pSup, pExprInfo, numOfCols, pStore);
11,579,535✔
736
  if (code != TSDB_CODE_SUCCESS) {
11,576,375!
737
    return code;
×
738
  }
739

740
  code = doInitAggInfoSup(pAggSup, pSup->pCtx, numOfCols, keyBufSize, pkey);
11,576,375✔
741
  if (code != TSDB_CODE_SUCCESS) {
11,585,042!
742
    return code;
×
743
  }
744

745
  for (int32_t i = 0; i < numOfCols; ++i) {
45,073,846✔
746
    pSup->pCtx[i].hasWindowOrGroup = pSup->hasWindowOrGroup;
33,488,804✔
747
    if (pState) {
33,488,804!
748
      pSup->pCtx[i].saveHandle.pBuf = NULL;
×
749
      pSup->pCtx[i].saveHandle.pState = pState;
×
750
      pSup->pCtx[i].exprIdx = i;
×
751
    } else {
752
      pSup->pCtx[i].saveHandle.pBuf = pAggSup->pResultBuf;
33,488,804✔
753
    }
754
  }
755

756
  return TSDB_CODE_SUCCESS;
11,585,042✔
757
}
758

759
int32_t applyAggFunctionOnPartialTuples(SExecTaskInfo* taskInfo, SqlFunctionCtx* pCtx, SColumnInfoData* pTimeWindowData,
821,879,461✔
760
                                        int32_t offset, int32_t forwardStep, int32_t numOfTotal, int32_t numOfOutput) {
761
  int32_t code = TSDB_CODE_SUCCESS, lino = 0;
821,879,461✔
762
  for (int32_t k = 0; k < numOfOutput; ++k) {
2,147,483,647✔
763
    // keep it temporarily
764
    SFunctionCtxStatus status = {0};
1,536,211,518✔
765
    functionCtxSave(&pCtx[k], &status);
1,536,211,518✔
766

767
    pCtx[k].input.startRowIndex = offset;
1,535,630,418✔
768
    pCtx[k].input.numOfRows = forwardStep;
1,535,630,418✔
769

770
    // not a whole block involved in query processing, statistics data can not be used
771
    // NOTE: the original value of isSet have been changed here
772
    if (pCtx[k].input.colDataSMAIsSet && forwardStep < numOfTotal) {
1,535,630,418!
773
      pCtx[k].input.colDataSMAIsSet = false;
×
774
    }
775

776
    if (fmIsPlaceHolderFunc(pCtx[k].functionId)) {
1,535,630,418!
777
      SResultRowEntryInfo* pEntryInfo = GET_RES_INFO(&pCtx[k]);
×
778
      char* p = GET_ROWCELL_INTERBUF(pEntryInfo);
×
779

780
      TAOS_CHECK_EXIT(fmSetStreamPseudoFuncParamVal(pCtx[k].functionId, pCtx[k].pExpr->base.pParamList, &taskInfo->pStreamRuntimeInfo->funcInfo));
×
781

782
      SValueNode *valueNode = (SValueNode *)nodesListGetNode(pCtx[k].pExpr->base.pParamList, 0);
263,517✔
783
      pEntryInfo->isNullRes = 0;
263,517✔
784
      if (TSDB_DATA_TYPE_NULL == valueNode->node.resType.type || valueNode->isNull) {
263,517!
785
        pEntryInfo->isNullRes = 1;
×
786
      } else if (IS_VAR_DATA_TYPE(pCtx[k].pExpr->base.resSchema.type)){
263,517!
787
        void* v = nodesGetValueFromNode(valueNode);
×
788
        memcpy(p, v, varDataTLen(v));
×
789
      } else {
790
        memcpy(p, nodesGetValueFromNode(valueNode), pCtx[k].pExpr->base.resSchema.bytes);
263,517✔
791
      }
792
      
793
      pEntryInfo->numOfRes = 1;
263,517✔
794
    } else if (pCtx[k].isPseudoFunc) {
1,537,686,519✔
795
      SResultRowEntryInfo* pEntryInfo = GET_RES_INFO(&pCtx[k]);
255,129,516✔
796

797
      char* p = GET_ROWCELL_INTERBUF(pEntryInfo);
255,129,516✔
798

799
      SColumnInfoData idata = {0};
255,129,516✔
800
      idata.info.type = TSDB_DATA_TYPE_BIGINT;
255,129,516✔
801
      idata.info.bytes = tDataTypes[TSDB_DATA_TYPE_BIGINT].bytes;
255,129,516✔
802
      idata.pData = p;
255,129,516✔
803

804
      SScalarParam out = {.columnData = &idata};
255,129,516✔
805
      SScalarParam tw = {.numOfRows = 5, .columnData = pTimeWindowData};
255,129,516✔
806
      TAOS_CHECK_EXIT(pCtx[k].sfp.process(&tw, 1, &out));
255,129,516!
807
      pEntryInfo->isNullRes = colDataIsNull_s(&idata, 0);
256,902,127✔
808
      pEntryInfo->numOfRes = 1;
256,902,127✔
809
    } else {
810
      if (functionNeedToExecute(&pCtx[k]) && pCtx[k].fpSet.process != NULL) {
1,282,557,003✔
811
        if ((&pCtx[k])->input.pData[0] == NULL) {
951,822,002!
812
          code = TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR;
×
813
          qError("%s apply functions error, input data is NULL.", GET_TASKID(taskInfo));
×
814
        } else {
815
          code = pCtx[k].fpSet.process(&pCtx[k]);
951,822,002✔
816
        }
817

818
        if (code != TSDB_CODE_SUCCESS) {
952,478,154✔
819
          if (pCtx[k].fpSet.cleanup != NULL) {
2!
820
            pCtx[k].fpSet.cleanup(&pCtx[k]);
2✔
821
          }
822
          TAOS_CHECK_EXIT(code);
2!
823
        }
824
      }
825

826
      // restore it
827
      functionCtxRestore(&pCtx[k], &status);
1,282,808,051✔
828
    }
829
  }
830

831
_exit:
820,980,335✔
832

833
  if (code) {
820,980,337✔
834
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
2!
835
    taskInfo->code = code;
2✔
836
  }
837

838
  return code;
820,980,337✔
839
}
840

841
void functionCtxSave(SqlFunctionCtx* pCtx, SFunctionCtxStatus* pStatus) {
1,536,175,573✔
842
  pStatus->hasAgg = pCtx->input.colDataSMAIsSet;
1,536,175,573✔
843
  pStatus->numOfRows = pCtx->input.numOfRows;
1,536,175,573✔
844
  pStatus->startOffset = pCtx->input.startRowIndex;
1,536,175,573✔
845
}
1,536,175,573✔
846

847
void functionCtxRestore(SqlFunctionCtx* pCtx, SFunctionCtxStatus* pStatus) {
1,281,895,130✔
848
  pCtx->input.colDataSMAIsSet = pStatus->hasAgg;
1,281,895,130✔
849
  pCtx->input.numOfRows = pStatus->numOfRows;
1,281,895,130✔
850
  pCtx->input.startRowIndex = pStatus->startOffset;
1,281,895,130✔
851
}
1,281,895,130✔
852

853
static int32_t resetAggregateOperatorState(SOperatorInfo* pOper) {
6,970✔
854
  SAggOperatorInfo* pAgg = pOper->info;
6,970✔
855
  SAggPhysiNode*   pAggNode = (SAggPhysiNode*)pOper->pPhyNode;
6,970✔
856
  
857
  pOper->status = OP_NOT_OPENED;
6,970✔
858
  size_t keyBufSize = sizeof(int64_t) + sizeof(int64_t) + POINTER_BYTES;
6,970✔
859
  SExecTaskInfo*  pTaskInfo = pOper->pTaskInfo;
6,970✔
860
  cleanupResultInfo(pTaskInfo, &pOper->exprSupp, &pAgg->groupResInfo, &pAgg->aggSup,
6,970✔
861
                      pAgg->cleanGroupResInfo);
6,970✔
862
  cleanupGroupResInfo(&pAgg->groupResInfo);
6,971✔
863
  resetBasicOperatorState(&pAgg->binfo);
6,970✔
864
  
865
  int32_t code = resetAggSup(&pOper->exprSupp, &pAgg->aggSup, pTaskInfo, pAggNode->pAggFuncs, pAggNode->pGroupKeys,
6,971✔
866
    keyBufSize, pTaskInfo->id.str, pTaskInfo->streamInfo.pState, &pTaskInfo->storageAPI.functionStore);
6,971✔
867

868
  if (code == 0) {
6,970!
869
    code = resetExprSupp(&pAgg->scalarExprSup, pTaskInfo, pAggNode->pExprs, NULL,
6,971✔
870
                          &pTaskInfo->storageAPI.functionStore);
871
  }
872

873
  pAgg->groupId = UINT64_MAX;
6,970✔
874
  pAgg->cleanGroupResInfo = false;
6,970✔
875
  pAgg->hasValidBlock = false;
6,970✔
876
  return 0;
6,970✔
877
}
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