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

taosdata / TDengine / #4788

14 Oct 2025 11:21AM UTC coverage: 60.992% (-2.3%) from 63.264%
#4788

push

travis-ci

web-flow
Merge 7ca9b50f9 into 19574fe21

154868 of 324306 branches covered (47.75%)

Branch coverage included in aggregate %.

207304 of 269498 relevant lines covered (76.92%)

125773493.22 hits per line

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

60.25
/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,
46,346,517✔
77
                                    SOperatorInfo** pOptrInfo) {
78
  QRY_PARAM_CHECK(pOptrInfo);
46,346,517!
79

80
  int32_t    lino = 0;
46,356,020✔
81
  int32_t    code = 0;
46,356,020✔
82
  int32_t    num = 0;
46,356,020✔
83
  SExprInfo* pExprInfo = NULL;
46,351,619✔
84
  int32_t    numOfScalarExpr = 0;
46,350,564✔
85
  SExprInfo* pScalarExprInfo = NULL;
46,351,197✔
86

87
  SAggOperatorInfo* pInfo = taosMemoryCalloc(1, sizeof(SAggOperatorInfo));
46,352,513✔
88
  SOperatorInfo*    pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo));
46,309,322✔
89
  if (pInfo == NULL || pOperator == NULL) {
46,302,597!
90
    code = terrno;
569✔
91
    goto _error;
×
92
  }
93

94
  pOperator->exprSupp.hasWindowOrGroup = false;
46,302,028✔
95

96
  SSDataBlock* pResBlock = createDataBlockFromDescNode(pAggNode->node.pOutputDataBlockDesc);
46,316,052✔
97
  QUERY_CHECK_NULL(pResBlock, code, lino, _error, terrno);
46,365,959!
98
  initBasicInfo(&pInfo->binfo, pResBlock);
46,365,959✔
99

100
  size_t keyBufSize = sizeof(int64_t) + sizeof(int64_t) + POINTER_BYTES;
46,351,556✔
101
  initResultSizeInfo(&pOperator->resultInfo, 4096);
46,351,556✔
102

103

104
  code = createExprInfo(pAggNode->pAggFuncs, pAggNode->pGroupKeys, &pExprInfo, &num);
46,354,900✔
105
  TSDB_CHECK_CODE(code, lino, _error);
46,358,239!
106

107
  code = initAggSup(&pOperator->exprSupp, &pInfo->aggSup, pExprInfo, num, keyBufSize, pTaskInfo->id.str,
92,715,196✔
108
                               pTaskInfo->streamInfo.pState, &pTaskInfo->storageAPI.functionStore);
46,361,017✔
109
  TSDB_CHECK_CODE(code, lino, _error);
46,334,201!
110

111
  if (pAggNode->pExprs != NULL) {
46,334,201✔
112
    code = createExprInfo(pAggNode->pExprs, NULL, &pScalarExprInfo, &numOfScalarExpr);
6,511,456✔
113
    TSDB_CHECK_CODE(code, lino, _error);
6,509,460!
114
  }
115

116
  code = initExprSupp(&pInfo->scalarExprSup, pScalarExprInfo, numOfScalarExpr, &pTaskInfo->storageAPI.functionStore);
46,340,591✔
117
  TSDB_CHECK_CODE(code, lino, _error);
46,322,992!
118

119
  code = filterInitFromNode((SNode*)pAggNode->node.pConditions, &pOperator->exprSupp.pFilterInfo, 0,
46,342,013✔
120
                            GET_STM_RTINFO(pTaskInfo));
46,322,992✔
121
  TSDB_CHECK_CODE(code, lino, _error);
46,330,788!
122

123
  pInfo->binfo.mergeResultBlock = pAggNode->mergeDataBlock;
46,330,788!
124
  pInfo->groupKeyOptimized = pAggNode->groupKeyOptimized;
46,342,854!
125
  pInfo->groupId = UINT64_MAX;
46,341,224✔
126
  pInfo->binfo.inputTsOrder = pAggNode->node.inputTsOrder;
46,323,133✔
127
  pInfo->binfo.outputTsOrder = pAggNode->node.outputTsOrder;
46,320,671✔
128
  pInfo->hasCountFunc = pAggNode->hasCountLikeFunc;
46,349,355!
129
  pInfo->pOperator = pOperator;
46,308,194✔
130
  pInfo->cleanGroupResInfo = false;
46,342,071✔
131

132
  setOperatorInfo(pOperator, "TableAggregate", QUERY_NODE_PHYSICAL_PLAN_HASH_AGG,
46,321,169✔
133
                  !pAggNode->node.forceCreateNonBlockingOptr, OP_NOT_OPENED, pInfo, pTaskInfo);
46,341,648!
134
  pOperator->fpSet = createOperatorFpSet(optrDummyOpenFn, getAggregateResultNext, NULL, destroyAggOperatorInfo,
46,325,077✔
135
                                         optrDefaultBufFn, NULL, optrDefaultGetNextExtFn, NULL);
136
  setOperatorResetStateFn(pOperator, resetAggregateOperatorState);
46,344,388✔
137

138
  pOperator->pPhyNode = pAggNode;
46,325,703✔
139

140
  if (downstream->operatorType == QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN) {
46,330,130✔
141
    STableScanInfo* pTableScanInfo = downstream->info;
34,283,358✔
142
    pTableScanInfo->base.pdInfo.pExprSup = &pOperator->exprSupp;
34,274,935✔
143
    pTableScanInfo->base.pdInfo.pAggSup = &pInfo->aggSup;
34,283,276✔
144
  }
145

146
  code = appendDownstream(pOperator, &downstream, 1);
46,313,737✔
147
  if (code != TSDB_CODE_SUCCESS) {
46,349,703!
148
    goto _error;
×
149
  }
150

151
  *pOptrInfo = pOperator;
46,349,703✔
152
  return TSDB_CODE_SUCCESS;
46,357,358✔
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) {
46,367,607✔
165
  if (param == NULL) {
46,367,607!
166
    return;
×
167
  }
168
  SAggOperatorInfo* pInfo = (SAggOperatorInfo*)param;
46,367,607✔
169
  cleanupBasicInfo(&pInfo->binfo);
46,367,607✔
170

171
  if (pInfo->pOperator) {
46,367,697✔
172
    cleanupResultInfo(pInfo->pOperator->pTaskInfo, &pInfo->pOperator->exprSupp, &pInfo->groupResInfo, &pInfo->aggSup,
46,367,853✔
173
                      pInfo->cleanGroupResInfo);
46,368,576!
174
    pInfo->pOperator = NULL;
46,367,717✔
175
  }
176
  cleanupAggSup(&pInfo->aggSup);
46,368,008✔
177
  cleanupExprSuppWithoutFilter(&pInfo->scalarExprSup);
46,367,370✔
178
  cleanupGroupResInfo(&pInfo->groupResInfo);
46,366,934✔
179
  taosMemoryFreeClear(param);
46,367,340!
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) {
65,806,246✔
190
  int32_t           code = TSDB_CODE_SUCCESS;
65,806,246✔
191
  int32_t           lino = 0;
65,806,246✔
192
  SExecTaskInfo*    pTaskInfo = pOperator->pTaskInfo;
65,806,246✔
193
  SAggOperatorInfo* pAggInfo = pOperator->info;
65,805,901✔
194

195
  if(!pAggInfo) {
65,803,682!
196
    qError("function:%s, pAggInfo is NULL", __func__);
×
197
    return false;
×
198
  }
199
  if (pOperator->blocking && pAggInfo->hasValidBlock) {
65,803,682!
200
    return false;
4,768,262✔
201
  }
202

203
  SExprSupp*   pSup = &pOperator->exprSupp;
61,038,383✔
204
  int64_t      st = taosGetTimestampUs();
61,036,092✔
205
  int32_t      order = pAggInfo->binfo.inputTsOrder;
61,036,092✔
206
  SSDataBlock* pBlock = pAggInfo->pNewGroupBlock;
61,037,838✔
207

208
  pAggInfo->cleanGroupResInfo = false;
61,037,251✔
209
  if (pBlock) {
61,032,115✔
210
    pAggInfo->pNewGroupBlock = NULL;
4,494,279✔
211
    tSimpleHashClear(pAggInfo->aggSup.pResultRowHashTable);
4,494,279✔
212
    code = setExecutionContext(pOperator, pOperator->exprSupp.numOfExprs, pBlock->info.id.groupId);
4,494,279✔
213
    QUERY_CHECK_CODE(code, lino, _end);
4,494,279!
214
    code = setInputDataBlock(pSup, pBlock, order, pBlock->info.scanFlag, true);
4,494,279✔
215
    QUERY_CHECK_CODE(code, lino, _end);
4,494,279!
216

217
    code = doAggregateImpl(pOperator, pSup->pCtx);
4,494,279✔
218
    QUERY_CHECK_CODE(code, lino, _end);
4,498,812!
219
  }
220
  while (1) {
173,492,103✔
221
    bool blockAllocated = false;
234,528,751✔
222
    pBlock = getNextBlockFromDownstream(pOperator, 0);
234,528,751✔
223
    if (pBlock == NULL) {
228,974,143✔
224
      if (!pAggInfo->hasValidBlock) {
53,480,775!
225
        code = createDataBlockForEmptyInput(pOperator, &pBlock);
12,275,274✔
226
        QUERY_CHECK_CODE(code, lino, _end);
12,274,898!
227

228
        if (pBlock == NULL) {
12,274,898✔
229
          break;
9,762,332✔
230
        }
231
        blockAllocated = true;
2,512,566✔
232
      } else {
233
        break;
41,205,938✔
234
      }
235
    }
236
    pAggInfo->hasValidBlock = true;
178,005,934✔
237
    pAggInfo->binfo.pRes->info.scanFlag = pBlock->info.scanFlag;
178,019,408✔
238

239
    printDataBlock(pBlock, __func__, pTaskInfo->id.str, pTaskInfo->id.queryId);
178,018,109✔
240

241
    // there is an scalar expression that needs to be calculated before apply the group aggregation.
242
    if (pAggInfo->scalarExprSup.pExprInfo != NULL && !blockAllocated) {
177,989,698✔
243
      SExprSupp* pSup1 = &pAggInfo->scalarExprSup;
17,890,648✔
244
      code = projectApplyFunctions(pSup1->pExprInfo, pBlock, pBlock, pSup1->pCtx, pSup1->numOfExprs, NULL, GET_STM_RTINFO(pOperator->pTaskInfo));
17,889,756✔
245
      if (code != TSDB_CODE_SUCCESS) {
17,885,879!
246
        destroyDataBlockForEmptyInput(blockAllocated, &pBlock);
×
247
        T_LONG_JMP(pTaskInfo->env, code);
×
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) {
178,002,298!
252
      pAggInfo->pNewGroupBlock = pBlock;
4,512,639✔
253
      break;
4,513,356✔
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);
173,478,743✔
257
    if (code != TSDB_CODE_SUCCESS) {
173,464,978!
258
      destroyDataBlockForEmptyInput(blockAllocated, &pBlock);
×
259
      T_LONG_JMP(pTaskInfo->env, code);
×
260
    }
261
    code = setInputDataBlock(pSup, pBlock, order, pBlock->info.scanFlag, true);
173,464,978✔
262
    if (code != TSDB_CODE_SUCCESS) {
173,497,126!
263
      destroyDataBlockForEmptyInput(blockAllocated, &pBlock);
×
264
      T_LONG_JMP(pTaskInfo->env, code);
×
265
    }
266

267
    code = doAggregateImpl(pOperator, pSup->pCtx);
173,497,126✔
268
    if (code != TSDB_CODE_SUCCESS) {
173,496,038!
269
      destroyDataBlockForEmptyInput(blockAllocated, &pBlock);
×
270
      T_LONG_JMP(pTaskInfo->env, code);
×
271
    }
272

273
    destroyDataBlockForEmptyInput(blockAllocated, &pBlock);
173,496,038✔
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) {
55,481,626!
278
    T_LONG_JMP(pTaskInfo->env, pTaskInfo->code);
×
279
  }
280

281
  code = initGroupedResultInfo(&pAggInfo->groupResInfo, pAggInfo->aggSup.pResultRowHashTable, 0);
55,473,187✔
282
  QUERY_CHECK_CODE(code, lino, _end);
55,479,412!
283
  pAggInfo->cleanGroupResInfo = true;
55,479,412✔
284

285
_end:
55,478,420✔
286
  if (code != TSDB_CODE_SUCCESS) {
55,475,466!
287
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
×
288
    pTaskInfo->code = code;
×
289
    T_LONG_JMP(pTaskInfo->env, code);
×
290
  }
291
  return pBlock != NULL;
55,477,565✔
292
}
293

294
int32_t getAggregateResultNext(SOperatorInfo* pOperator, SSDataBlock** ppRes) {
105,509,149✔
295
  int32_t           code = TSDB_CODE_SUCCESS;
105,509,149✔
296
  int32_t           lino = 0;
105,509,149✔
297
  SAggOperatorInfo* pAggInfo = pOperator->info;
105,509,149✔
298
  SOptrBasicInfo*   pInfo = &pAggInfo->binfo;
105,510,700✔
299

300
  if (pOperator->status == OP_EXEC_DONE) {
105,508,799✔
301
    (*ppRes) = NULL;
39,721,870✔
302
    return code;
39,721,330✔
303
  }
304

305
  SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
65,783,876✔
306
  bool           hasNewGroups = false;
65,791,158✔
307
  do {
308
    hasNewGroups = nextGroupedResult(pOperator);
65,808,233✔
309
    code = blockDataEnsureCapacity(pInfo->pRes, pOperator->resultInfo.capacity);
60,246,606✔
310
    QUERY_CHECK_CODE(code, lino, _end);
60,253,438!
311

312
    while (1) {
313
      doBuildResultDatablock(pOperator, pInfo, &pAggInfo->groupResInfo, pAggInfo->aggSup.pResultBuf);
60,253,438✔
314
      code = doFilter(pInfo->pRes, pOperator->exprSupp.pFilterInfo, NULL, NULL);
60,251,315✔
315
      QUERY_CHECK_CODE(code, lino, _end);
60,253,102!
316

317
      if (!hasRemainResults(&pAggInfo->groupResInfo)) {
60,253,102✔
318
        if (!hasNewGroups) setOperatorCompleted(pOperator);
55,484,175✔
319
        break;
55,483,521✔
320
      }
321

322
      if (pInfo->pRes->info.rows > 0) {
4,769,694!
323
        break;
4,769,694✔
324
      }
325
    }
326
  } while (pInfo->pRes->info.rows == 0 && hasNewGroups);
60,253,215✔
327

328
  size_t rows = blockDataGetNumOfRows(pInfo->pRes);
60,237,561✔
329
  pOperator->resultInfo.totalRows += rows;
60,235,647✔
330

331
_end:
60,231,705✔
332
  if (code != TSDB_CODE_SUCCESS) {
60,231,705!
333
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
×
334
    pTaskInfo->code = code;
×
335
    T_LONG_JMP(pTaskInfo->env, code);
×
336
  }
337

338
  printDataBlock(pInfo->pRes, __func__, pTaskInfo->id.str, pTaskInfo->id.queryId);
60,231,705✔
339

340
  (*ppRes) = (rows == 0) ? NULL : pInfo->pRes;
60,235,758✔
341
  return code;
60,236,023✔
342
}
343

344
int32_t doAggregateImpl(SOperatorInfo* pOperator, SqlFunctionCtx* pCtx) {
177,986,857✔
345
  int32_t code = TSDB_CODE_SUCCESS;
177,986,857✔
346
  if (!pOperator || (pOperator->exprSupp.numOfExprs > 0 && pCtx == NULL)) {
177,986,857!
347
    qError("%s failed at line %d since pCtx is NULL.", __func__, __LINE__);
18,491!
348
    return TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR;
×
349
  }
350
  for (int32_t k = 0; k < pOperator->exprSupp.numOfExprs; ++k) {
2,147,483,647✔
351
    if (functionNeedToExecute(&pCtx[k])) {
2,147,483,647✔
352
      // todo add a dummy function to avoid process check
353
      if (pCtx[k].fpSet.process == NULL) {
2,147,483,647✔
354
        continue;
8,640,705✔
355
      }
356

357
      if ((&pCtx[k])->input.pData[0] == NULL) {
2,147,483,647!
358
        code = TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR;
×
359
        qError("%s aggregate function error happens, input data is NULL.", GET_TASKID(pOperator->pTaskInfo));
×
360
      } else {
361
        code = pCtx[k].fpSet.process(&pCtx[k]);
2,147,483,647✔
362
      }
363

364
      if (code != TSDB_CODE_SUCCESS) {
2,147,483,647!
365
        if (pCtx[k].fpSet.cleanup != NULL) {
×
366
          pCtx[k].fpSet.cleanup(&pCtx[k]);
×
367
        }
368
        qError("%s aggregate function error happens, code:%s", GET_TASKID(pOperator->pTaskInfo), tstrerror(code));
×
369
        return code;
×
370
      }
371
    }
372
  }
373

374
  return TSDB_CODE_SUCCESS;
177,990,573✔
375
}
376

377
static int32_t createDataBlockForEmptyInput(SOperatorInfo* pOperator, SSDataBlock** ppBlock) {
12,275,274✔
378
  int32_t code = TSDB_CODE_SUCCESS;
12,275,274✔
379
  int32_t lino = 0;
12,275,274✔
380
  SSDataBlock* pBlock = NULL;
12,275,274✔
381
  if (!tsCountAlwaysReturnValue) {
12,274,507✔
382
    return TSDB_CODE_SUCCESS;
2,796,379✔
383
  }
384

385
  SAggOperatorInfo* pAggInfo = pOperator->info;
9,478,128✔
386
  if (pAggInfo->groupKeyOptimized) {
9,477,500!
387
    return TSDB_CODE_SUCCESS;
1,939,323✔
388
  }
389

390
  SOperatorInfo* downstream = pOperator->pDownstream[0];
7,536,818✔
391
  if (downstream->operatorType == QUERY_NODE_PHYSICAL_PLAN_PARTITION ||
7,535,120✔
392
      downstream->operatorType == QUERY_NODE_PHYSICAL_PLAN_SORT ||
7,518,132✔
393
      (downstream->operatorType == QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN &&
7,510,243✔
394
       ((STableScanInfo*)downstream->info)->hasGroupByTag == true)) {
3,636,686!
395
    return TSDB_CODE_SUCCESS;
27,970✔
396
  }
397

398
  SqlFunctionCtx* pCtx = pOperator->exprSupp.pCtx;
7,507,551✔
399

400
  if (!pAggInfo->hasCountFunc) {
7,509,852!
401
    return TSDB_CODE_SUCCESS;
4,993,981✔
402
  }
403

404
  code = createDataBlock(&pBlock);
2,512,942✔
405
  if (code) {
2,513,333!
406
    return code;
×
407
  }
408

409
  pBlock->info.rows = 1;
2,513,333✔
410
  pBlock->info.capacity = 0;
2,513,333✔
411

412
  for (int32_t i = 0; i < pOperator->exprSupp.numOfExprs; ++i) {
7,594,758✔
413
    SColumnInfoData colInfo = {0};
5,081,425✔
414
    colInfo.hasNull = true;
5,081,034✔
415
    colInfo.info.type = TSDB_DATA_TYPE_NULL;
5,081,034✔
416
    colInfo.info.bytes = 1;
5,081,034✔
417

418
    SExprInfo* pOneExpr = &pOperator->exprSupp.pExprInfo[i];
5,081,034✔
419
    for (int32_t j = 0; j < pOneExpr->base.numOfParams; ++j) {
10,325,575✔
420
      SFunctParam* pFuncParam = &pOneExpr->base.pParam[j];
5,243,759✔
421
      if (pFuncParam->type == FUNC_PARAM_TYPE_COLUMN) {
5,242,977✔
422
        int32_t slotId = pFuncParam->pCol->slotId;
5,241,223✔
423
        int32_t numOfCols = taosArrayGetSize(pBlock->pDataBlock);
5,241,223✔
424
        if (slotId >= numOfCols) {
5,241,223✔
425
          code = taosArrayEnsureCap(pBlock->pDataBlock, slotId + 1);
2,806,173✔
426
          QUERY_CHECK_CODE(code, lino, _end);
2,805,782!
427

428
          for (int32_t k = numOfCols; k < slotId + 1; ++k) {
7,466,260✔
429
            void* tmp = taosArrayPush(pBlock->pDataBlock, &colInfo);
4,660,087✔
430
            QUERY_CHECK_NULL(tmp, code, lino, _end, terrno);
4,660,478!
431
          }
432
        }
433
      } else if (pFuncParam->type == FUNC_PARAM_TYPE_VALUE) {
2,536✔
434
        // do nothing
435
      }
436
    }
437
  }
438

439
  code = blockDataEnsureCapacity(pBlock, pBlock->info.rows);
2,513,333✔
440
  QUERY_CHECK_CODE(code, lino, _end);
2,513,333!
441

442
  for (int32_t i = 0; i < blockDataGetNumOfCols(pBlock); ++i) {
7,173,811✔
443
    SColumnInfoData* pColInfoData = taosArrayGet(pBlock->pDataBlock, i);
4,660,478✔
444
    QUERY_CHECK_NULL(pColInfoData, code, lino, _end, terrno);
4,660,478!
445
    colDataSetNULL(pColInfoData, 0);
446
  }
447
  *ppBlock = pBlock;
2,513,333✔
448

449
_end:
2,513,724✔
450
  if (code != TSDB_CODE_SUCCESS) {
2,513,333!
451
    blockDataDestroy(pBlock);
×
452
    qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(code));
×
453
  }
454
  return code;
2,513,333✔
455
}
456

457
void destroyDataBlockForEmptyInput(bool blockAllocated, SSDataBlock** ppBlock) {
173,491,927✔
458
  if (!blockAllocated) {
173,491,927✔
459
    return;
170,984,621✔
460
  }
461

462
  blockDataDestroy(*ppBlock);
2,507,306✔
463
  *ppBlock = NULL;
2,513,333✔
464
}
465

466
int32_t setExecutionContext(SOperatorInfo* pOperator, int32_t numOfOutput, uint64_t groupId) {
177,968,377✔
467
  int32_t           code = TSDB_CODE_SUCCESS;
177,968,377✔
468
  SAggOperatorInfo* pAggInfo = pOperator->info;
177,968,377✔
469
  if (pAggInfo->groupId != UINT64_MAX && pAggInfo->groupId == groupId) {
177,998,208✔
470
    return code;
93,660,510✔
471
  }
472

473
  code = doSetTableGroupOutputBuf(pOperator, numOfOutput, groupId);
84,338,251✔
474

475
  // record the current active group id
476
  pAggInfo->groupId = groupId;
84,313,561✔
477
  return code;
84,323,536✔
478
}
479

480
int32_t doSetTableGroupOutputBuf(SOperatorInfo* pOperator, int32_t numOfOutput, uint64_t groupId) {
84,320,891✔
481
  // for simple group by query without interval, all the tables belong to one group result.
482
  int32_t           code = TSDB_CODE_SUCCESS;
84,320,891✔
483
  int32_t           lino = 0;
84,320,891✔
484
  SExecTaskInfo*    pTaskInfo = pOperator->pTaskInfo;
84,320,891✔
485
  SAggOperatorInfo* pAggInfo = pOperator->info;
84,322,661✔
486

487
  SResultRowInfo* pResultRowInfo = &pAggInfo->binfo.resultRowInfo;
84,325,175✔
488
  SqlFunctionCtx* pCtx = pOperator->exprSupp.pCtx;
84,327,860✔
489
  int32_t*        rowEntryInfoOffset = pOperator->exprSupp.rowEntryInfoOffset;
84,320,921✔
490

491
  SResultRow* pResultRow =
492
      doSetResultOutBufByKey(pAggInfo->aggSup.pResultBuf, pResultRowInfo, (char*)&groupId, sizeof(groupId), true,
84,323,140✔
493
                             groupId, pTaskInfo, false, &pAggInfo->aggSup, true);
494
  if (pResultRow == NULL || pTaskInfo->code != 0) {
84,314,179✔
495
    code = pTaskInfo->code;
743✔
496
    lino = __LINE__;
×
497
    goto _end;
×
498
  }
499
  /*
500
   * not assign result buffer yet, add new result buffer
501
   * all group belong to one result set, and each group result has different group id so set the id to be one
502
   */
503
  if (pResultRow->pageId == -1) {
84,313,268!
504
    code = addNewResultRowBuf(pResultRow, pAggInfo->aggSup.pResultBuf, pAggInfo->binfo.pRes->info.rowSize);
×
505
    QUERY_CHECK_CODE(code, lino, _end);
×
506
  }
507

508
  code = setResultRowInitCtx(pResultRow, pCtx, numOfOutput, rowEntryInfoOffset);
84,328,423✔
509
  QUERY_CHECK_CODE(code, lino, _end);
84,319,032!
510

511
_end:
84,319,032✔
512
  if (code != TSDB_CODE_SUCCESS) {
84,319,032!
513
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
×
514
  }
515
  return code;
84,316,014✔
516
}
517

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

524
  SFilePage* pData = NULL;
×
525

526
  // in the first scan, new space needed for results
527
  int32_t pageId = -1;
×
528
  SArray* list = getDataBufPagesIdList(pResultBuf);
×
529

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

545
    pageId = getPageId(pi);
×
546

547
    if (pData->num + size > getBufPageSize(pResultBuf)) {
×
548
      // release current page first, and prepare the next one
549
      releaseBufPageInfo(pResultBuf, pi);
×
550

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

560
  if (pData == NULL) {
×
561
    return -1;
×
562
  }
563

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

569
    pData->num += size;
×
570
  }
571

572
  return 0;
×
573
}
574

575
int32_t doInitAggInfoSup(SAggSupporter* pAggSup, SqlFunctionCtx* pCtx, int32_t numOfOutput, size_t keyBufSize,
177,653,701✔
576
                         const char* pKey) {
577
  int32_t code = 0;
177,653,701✔
578
  //  _hash_fn_t hashFn = taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY);
579

580
  pAggSup->currentPageId = -1;
177,653,701✔
581
  pAggSup->resultRowSize = getResultRowSize(pCtx, numOfOutput);
177,663,822✔
582
  pAggSup->keyBuf = taosMemoryCalloc(1, keyBufSize + POINTER_BYTES + sizeof(int64_t));
177,621,055✔
583
  pAggSup->pResultRowHashTable = tSimpleHashInit(100, taosFastHash);
177,663,893✔
584

585
  if (pAggSup->keyBuf == NULL || pAggSup->pResultRowHashTable == NULL) {
177,626,768!
586
    return terrno;
8,327✔
587
  }
588

589
  uint32_t defaultPgsz = 0;
177,614,452✔
590
  int64_t defaultBufsz = 0;
177,626,317✔
591
  code = getBufferPgSize(pAggSup->resultRowSize, &defaultPgsz, &defaultBufsz);
177,636,460✔
592
  if (code) {
177,590,536!
593
    qError("failed to get buff page size, rowSize:%d", pAggSup->resultRowSize);
×
594
    return code;
×
595
  }
596

597
  if (!osTempSpaceAvailable()) {
177,590,536!
598
    code = TSDB_CODE_NO_DISKSPACE;
×
599
    qError("Init stream agg supporter failed since %s, key:%s, tempDir:%s", tstrerror(code), pKey, tsTempDir);
×
600
    return code;
×
601
  }
602

603
  code = createDiskbasedBuf(&pAggSup->pResultBuf, defaultPgsz, defaultBufsz, pKey, tsTempDir);
177,660,128✔
604
  if (code != TSDB_CODE_SUCCESS) {
177,648,696!
605
    qError("Create agg result buf failed since %s, %s", tstrerror(code), pKey);
×
606
    return code;
×
607
  }
608

609
  return code;
177,648,696✔
610
}
611

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

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

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

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

648
void cleanupResultInfoInGroupResInfo(SExecTaskInfo* pTaskInfo, SExprSupp* pSup, SDiskbasedBuf* pBuf,
54,975,325✔
649
                                  SGroupResInfo* pGroupResInfo) {
650
  int32_t         numOfExprs = pSup->numOfExprs;
54,975,325✔
651
  int32_t*        rowEntryOffset = pSup->rowEntryInfoOffset;
54,977,426✔
652
  SqlFunctionCtx* pCtx = pSup->pCtx;
54,976,703✔
653
  int32_t         numOfRows = getNumOfTotalRes(pGroupResInfo);
54,976,500✔
654
  bool            needCleanup = false;
54,974,963✔
655

656
  for (int32_t j = 0; j < numOfExprs; ++j) {
194,836,439✔
657
    needCleanup |= pCtx[j].needCleanup;
139,860,927!
658
  }
659
  if (!needCleanup) {
54,975,512✔
660
    return;
54,477,066✔
661
  }
662

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

673

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

684
void cleanupResultInfoInHashMap(SExecTaskInfo* pTaskInfo, SExprSupp* pSup, SDiskbasedBuf* pBuf,
29,555,830✔
685
                       SGroupResInfo* pGroupResInfo, SSHashObj* pHashmap) {
686
  int32_t         numOfExprs = pSup->numOfExprs;
29,555,830✔
687
  int32_t*        rowEntryOffset = pSup->rowEntryInfoOffset;
29,557,543✔
688
  SqlFunctionCtx* pCtx = pSup->pCtx;
29,557,806✔
689
  bool            needCleanup = false;
29,556,918✔
690
  for (int32_t j = 0; j < numOfExprs; ++j) {
98,606,757✔
691
    needCleanup |= pCtx[j].needCleanup;
69,049,448!
692
  }
693
  if (!needCleanup) {
29,557,309✔
694
    return;
29,553,886✔
695
  }
696

697
  // begin from last iter
698
  void*   pData = pGroupResInfo->dataPos;
3,423✔
699
  int32_t iter = pGroupResInfo->iter;
3,423✔
700
  while ((pData = tSimpleHashIterate(pHashmap, pData, &iter)) != NULL) {
4,528✔
701
    SResultRowPosition* pos = pData;
1,105✔
702

703
    SFilePage* page = getBufPage(pBuf, pos->pageId);
1,105✔
704
    if (page == NULL) {
1,105!
705
      qError("failed to get buffer, code:%s, %s", tstrerror(terrno), GET_TASKID(pTaskInfo));
×
706
      continue;
×
707
    }
708

709
    SResultRow* pRow = (SResultRow*)((char*)page + pos->offset);
1,105✔
710

711
    for (int32_t j = 0; j < numOfExprs; ++j) {
23,205✔
712
      pCtx[j].resultInfo = getResultEntryInfo(pRow, j, rowEntryOffset);
22,100✔
713
      if (pCtx[j].fpSet.cleanup) {
22,100✔
714
        pCtx[j].fpSet.cleanup(&pCtx[j]);
2,210✔
715
      }
716
    }
717

718
    releaseBufPage(pBuf, page);
1,105✔
719
  }
720
}
721

722
void cleanupResultInfo(SExecTaskInfo* pTaskInfo, SExprSupp* pSup, SGroupResInfo* pGroupResInfo,
84,531,301✔
723
                       SAggSupporter *pAggSup, bool cleanGroupResInfo) {
724
  if (cleanGroupResInfo) {
84,531,301✔
725
    cleanupResultInfoInGroupResInfo(pTaskInfo, pSup, pAggSup->pResultBuf, pGroupResInfo);
54,975,917✔
726
  } else {
727
    cleanupResultInfoInHashMap(pTaskInfo, pSup, pAggSup->pResultBuf, pGroupResInfo, pAggSup->pResultRowHashTable);
29,555,384✔
728
  }
729
}
84,530,906✔
730
void cleanupAggSup(SAggSupporter* pAggSup) {
177,700,954✔
731
  taosMemoryFreeClear(pAggSup->keyBuf);
177,700,954✔
732
  tSimpleHashCleanup(pAggSup->pResultRowHashTable);
177,707,973✔
733
  destroyDiskbasedBuf(pAggSup->pResultBuf);
177,705,235✔
734
  memset(pAggSup, 0, sizeof(SAggSupporter));
177,700,110!
735
}
177,700,110✔
736

737
int32_t initAggSup(SExprSupp* pSup, SAggSupporter* pAggSup, SExprInfo* pExprInfo, int32_t numOfCols, size_t keyBufSize,
177,661,822✔
738
                   const char* pkey, void* pState, SFunctionStateStore* pStore) {
739
  int32_t code = initExprSupp(pSup, pExprInfo, numOfCols, pStore);
177,661,822✔
740
  if (code != TSDB_CODE_SUCCESS) {
177,644,835!
741
    return code;
×
742
  }
743

744
  code = doInitAggInfoSup(pAggSup, pSup->pCtx, numOfCols, keyBufSize, pkey);
177,644,835✔
745
  if (code != TSDB_CODE_SUCCESS) {
177,637,859!
746
    return code;
×
747
  }
748

749
  for (int32_t i = 0; i < numOfCols; ++i) {
889,392,733✔
750
    pSup->pCtx[i].hasWindowOrGroup = pSup->hasWindowOrGroup;
711,831,628!
751
    if (pState) {
711,744,687!
752
      pSup->pCtx[i].saveHandle.pBuf = NULL;
×
753
      pSup->pCtx[i].saveHandle.pState = pState;
×
754
      pSup->pCtx[i].exprIdx = i;
×
755
    } else {
756
      pSup->pCtx[i].saveHandle.pBuf = pAggSup->pResultBuf;
711,744,687✔
757
    }
758
  }
759

760
  return TSDB_CODE_SUCCESS;
177,561,105✔
761
}
762

763
int32_t applyAggFunctionOnPartialTuples(SExecTaskInfo* taskInfo, SqlFunctionCtx* pCtx, SColumnInfoData* pTimeWindowData,
2,147,483,647✔
764
                                        int32_t offset, int32_t forwardStep, int32_t numOfTotal, int32_t numOfOutput) {
765
  int32_t code = TSDB_CODE_SUCCESS, lino = 0;
2,147,483,647✔
766
  for (int32_t k = 0; k < numOfOutput; ++k) {
2,147,483,647✔
767
    // keep it temporarily
768
    SFunctionCtxStatus status = {0};
2,147,483,647✔
769
    functionCtxSave(&pCtx[k], &status);
2,147,483,647✔
770

771
    pCtx[k].input.startRowIndex = offset;
2,147,483,647✔
772
    pCtx[k].input.numOfRows = forwardStep;
2,147,483,647✔
773

774
    // not a whole block involved in query processing, statistics data can not be used
775
    // NOTE: the original value of isSet have been changed here
776
    if (pCtx[k].input.colDataSMAIsSet && forwardStep < numOfTotal) {
2,147,483,647!
777
      pCtx[k].input.colDataSMAIsSet = false;
×
778
    }
779

780
    if (fmIsPlaceHolderFunc(pCtx[k].functionId)) {
2,147,483,647✔
781
      SResultRowEntryInfo* pEntryInfo = GET_RES_INFO(&pCtx[k]);
16,963,659✔
782
      char* p = GET_ROWCELL_INTERBUF(pEntryInfo);
16,964,747✔
783

784
      TAOS_CHECK_EXIT(fmSetStreamPseudoFuncParamVal(pCtx[k].functionId, pCtx[k].pExpr->base.pParamList, &taskInfo->pStreamRuntimeInfo->funcInfo));
16,965,291!
785

786
      SValueNode *valueNode = (SValueNode *)nodesListGetNode(pCtx[k].pExpr->base.pParamList, 0);
16,964,203✔
787
      pEntryInfo->isNullRes = 0;
16,965,291✔
788
      if (TSDB_DATA_TYPE_NULL == valueNode->node.resType.type || valueNode->isNull) {
16,965,291!
789
        pEntryInfo->isNullRes = 1;
×
790
      } else if (IS_VAR_DATA_TYPE(pCtx[k].pExpr->base.resSchema.type)){
16,964,747!
791
        void* v = nodesGetValueFromNode(valueNode);
544✔
792
        memcpy(p, v, varDataTLen(v));
×
793
      } else {
794
        memcpy(p, nodesGetValueFromNode(valueNode), pCtx[k].pExpr->base.resSchema.bytes);
16,959,307!
795
      }
796
      
797
      pEntryInfo->numOfRes = 1;
16,964,203✔
798
    } else if (pCtx[k].isPseudoFunc) {
2,147,483,647✔
799
      SResultRowEntryInfo* pEntryInfo = GET_RES_INFO(&pCtx[k]);
2,147,483,647✔
800

801
      char* p = GET_ROWCELL_INTERBUF(pEntryInfo);
2,147,483,647✔
802

803
      SColumnInfoData idata = {0};
2,147,483,647✔
804
      idata.info.type = TSDB_DATA_TYPE_BIGINT;
2,147,483,647✔
805
      idata.info.bytes = tDataTypes[TSDB_DATA_TYPE_BIGINT].bytes;
2,147,483,647✔
806
      idata.pData = p;
2,147,483,647✔
807

808
      SScalarParam out = {.columnData = &idata};
2,147,483,647✔
809
      SScalarParam tw = {.numOfRows = 5, .columnData = pTimeWindowData};
2,147,483,647✔
810
      TAOS_CHECK_EXIT(pCtx[k].sfp.process(&tw, 1, &out));
2,147,483,647!
811
      pEntryInfo->isNullRes = colDataIsNull_s(&idata, 0);
2,147,483,647✔
812
      pEntryInfo->numOfRes = 1;
2,147,483,647✔
813
    } else {
814
      if (functionNeedToExecute(&pCtx[k]) && pCtx[k].fpSet.process != NULL) {
2,147,483,647✔
815
        if ((&pCtx[k])->input.pData[0] == NULL) {
2,147,483,647!
816
          code = TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR;
×
817
          qError("%s apply functions error, input data is NULL.", GET_TASKID(taskInfo));
×
818
        } else {
819
          code = pCtx[k].fpSet.process(&pCtx[k]);
2,147,483,647✔
820
        }
821

822
        if (code != TSDB_CODE_SUCCESS) {
2,147,483,647✔
823
          if (pCtx[k].fpSet.cleanup != NULL) {
1,105!
824
            pCtx[k].fpSet.cleanup(&pCtx[k]);
1,105✔
825
          }
826
          TAOS_CHECK_EXIT(code);
1,105!
827
        }
828
      }
829

830
      // restore it
831
      functionCtxRestore(&pCtx[k], &status);
2,147,483,647✔
832
    }
833
  }
834

835
_exit:
2,147,483,647✔
836

837
  if (code) {
2,147,483,647✔
838
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
1,105!
839
    taskInfo->code = code;
1,105✔
840
  }
841

842
  return code;
2,147,483,647✔
843
}
844

845
void functionCtxSave(SqlFunctionCtx* pCtx, SFunctionCtxStatus* pStatus) {
2,147,483,647✔
846
  pStatus->hasAgg = pCtx->input.colDataSMAIsSet;
2,147,483,647!
847
  pStatus->numOfRows = pCtx->input.numOfRows;
2,147,483,647✔
848
  pStatus->startOffset = pCtx->input.startRowIndex;
2,147,483,647✔
849
}
2,147,483,647✔
850

851
void functionCtxRestore(SqlFunctionCtx* pCtx, SFunctionCtxStatus* pStatus) {
2,147,483,647✔
852
  pCtx->input.colDataSMAIsSet = pStatus->hasAgg;
2,147,483,647!
853
  pCtx->input.numOfRows = pStatus->numOfRows;
2,147,483,647✔
854
  pCtx->input.startRowIndex = pStatus->startOffset;
2,147,483,647✔
855
}
2,147,483,647✔
856

857
static int32_t resetAggregateOperatorState(SOperatorInfo* pOper) {
10,799,910✔
858
  SAggOperatorInfo* pAgg = pOper->info;
10,799,910✔
859
  SAggPhysiNode*   pAggNode = (SAggPhysiNode*)pOper->pPhyNode;
10,800,994✔
860
  
861
  pOper->status = OP_NOT_OPENED;
10,800,998✔
862
  size_t keyBufSize = sizeof(int64_t) + sizeof(int64_t) + POINTER_BYTES;
10,800,998✔
863
  SExecTaskInfo*  pTaskInfo = pOper->pTaskInfo;
10,800,998✔
864
  cleanupResultInfo(pTaskInfo, &pOper->exprSupp, &pAgg->groupResInfo, &pAgg->aggSup,
10,800,998✔
865
                      pAgg->cleanGroupResInfo);
10,799,902!
866
  cleanupGroupResInfo(&pAgg->groupResInfo);
10,800,439✔
867
  resetBasicOperatorState(&pAgg->binfo);
10,798,803✔
868
  
869
  pAgg->pNewGroupBlock = NULL;
10,800,994✔
870

871
  int32_t code = resetAggSup(&pOper->exprSupp, &pAgg->aggSup, pTaskInfo, pAggNode->pAggFuncs, pAggNode->pGroupKeys,
21,600,178✔
872
    keyBufSize, pTaskInfo->id.str, pTaskInfo->streamInfo.pState, &pTaskInfo->storageAPI.functionStore);
10,800,994✔
873

874
  if (code == 0) {
10,800,450!
875
    code = resetExprSupp(&pAgg->scalarExprSup, pTaskInfo, pAggNode->pExprs, NULL,
10,800,450✔
876
                          &pTaskInfo->storageAPI.functionStore);
877
  }
878

879
  pAgg->groupId = UINT64_MAX;
10,799,910✔
880
  pAgg->cleanGroupResInfo = false;
10,799,910✔
881
  pAgg->hasValidBlock = false;
10,800,450✔
882
  return 0;
10,799,910✔
883
}
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