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

taosdata / TDengine / #4971

28 Feb 2026 08:05AM UTC coverage: 67.671% (-0.04%) from 67.707%
#4971

push

travis-ci

web-flow
fix(planner): disable project block merge in non-top-level subplans (#34617)

208281 of 307783 relevant lines covered (67.67%)

130135765.28 hits per line

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

80.16
/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,
69,035,337✔
77
                                    SOperatorInfo** pOptrInfo) {
78
  QRY_PARAM_CHECK(pOptrInfo);
69,035,337✔
79

80
  int32_t    lino = 0;
69,051,096✔
81
  int32_t    code = 0;
69,051,096✔
82
  int32_t    num = 0;
69,051,096✔
83
  SExprInfo* pExprInfo = NULL;
69,043,219✔
84
  int32_t    numOfScalarExpr = 0;
69,046,513✔
85
  SExprInfo* pScalarExprInfo = NULL;
69,024,003✔
86

87
  SAggOperatorInfo* pInfo = taosMemoryCalloc(1, sizeof(SAggOperatorInfo));
69,035,413✔
88
  SOperatorInfo*    pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo));
68,960,495✔
89
  if (pInfo == NULL || pOperator == NULL) {
68,934,546✔
90
    code = terrno;
115✔
91
    goto _error;
×
92
  }
93

94
  pOperator->exprSupp.hasWindowOrGroup = false;
68,935,110✔
95

96
  SSDataBlock* pResBlock = createDataBlockFromDescNode(pAggNode->node.pOutputDataBlockDesc);
68,957,499✔
97
  QUERY_CHECK_NULL(pResBlock, code, lino, _error, terrno);
69,084,397✔
98
  initBasicInfo(&pInfo->binfo, pResBlock);
69,084,397✔
99

100
  size_t keyBufSize = sizeof(int64_t) + sizeof(int64_t) + POINTER_BYTES;
69,061,986✔
101
  initResultSizeInfo(&pOperator->resultInfo, 4096);
69,061,986✔
102

103

104
  code = createExprInfo(pAggNode->pAggFuncs, pAggNode->pGroupKeys, &pExprInfo, &num);
69,074,585✔
105
  TSDB_CHECK_CODE(code, lino, _error);
69,036,459✔
106

107
  code = initAggSup(&pOperator->exprSupp, &pInfo->aggSup, pExprInfo, num, keyBufSize, pTaskInfo->id.str,
138,067,039✔
108
                               pTaskInfo->streamInfo.pState, &pTaskInfo->storageAPI.functionStore);
69,039,491✔
109
  TSDB_CHECK_CODE(code, lino, _error);
69,010,163✔
110

111
  if (pAggNode->pExprs != NULL) {
69,010,163✔
112
    code = createExprInfo(pAggNode->pExprs, NULL, &pScalarExprInfo, &numOfScalarExpr);
16,800,270✔
113
    TSDB_CHECK_CODE(code, lino, _error);
16,787,981✔
114
  }
115

116
  code = initExprSupp(&pInfo->scalarExprSup, pScalarExprInfo, numOfScalarExpr, &pTaskInfo->storageAPI.functionStore);
68,987,877✔
117
  TSDB_CHECK_CODE(code, lino, _error);
68,975,438✔
118

119
  code = filterInitFromNode((SNode*)pAggNode->node.pConditions, &pOperator->exprSupp.pFilterInfo, 0,
68,935,732✔
120
                            GET_STM_RTINFO(pTaskInfo));
68,975,438✔
121
  TSDB_CHECK_CODE(code, lino, _error);
68,992,795✔
122

123
  pInfo->binfo.mergeResultBlock = pAggNode->mergeDataBlock;
68,992,795✔
124
  pInfo->groupKeyOptimized = pAggNode->groupKeyOptimized;
68,970,872✔
125
  pInfo->groupId = UINT64_MAX;
68,942,524✔
126
  pInfo->binfo.inputTsOrder = pAggNode->node.inputTsOrder;
68,975,556✔
127
  pInfo->binfo.outputTsOrder = pAggNode->node.outputTsOrder;
68,954,376✔
128
  pInfo->hasCountFunc = pAggNode->hasCountLikeFunc;
68,968,591✔
129
  pInfo->pOperator = pOperator;
68,930,862✔
130
  pInfo->cleanGroupResInfo = false;
68,918,819✔
131

132
  setOperatorInfo(pOperator, "TableAggregate", QUERY_NODE_PHYSICAL_PLAN_HASH_AGG,
68,918,677✔
133
                  !pAggNode->node.forceCreateNonBlockingOptr, OP_NOT_OPENED, pInfo, pTaskInfo);
68,934,676✔
134
  pOperator->fpSet = createOperatorFpSet(optrDummyOpenFn, getAggregateResultNext, NULL, destroyAggOperatorInfo,
68,994,004✔
135
                                         optrDefaultBufFn, NULL, optrDefaultGetNextExtFn, NULL);
136
  setOperatorResetStateFn(pOperator, resetAggregateOperatorState);
69,002,269✔
137

138
  pOperator->pPhyNode = pAggNode;
69,006,915✔
139

140
  if (downstream->operatorType == QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN) {
68,985,756✔
141
    STableScanInfo* pTableScanInfo = downstream->info;
51,860,093✔
142
    pTableScanInfo->base.pdInfo.pExprSup = &pOperator->exprSupp;
51,866,984✔
143
    pTableScanInfo->base.pdInfo.pAggSup = &pInfo->aggSup;
51,863,680✔
144
  }
145

146
  code = appendDownstream(pOperator, &downstream, 1);
68,989,199✔
147
  if (code != TSDB_CODE_SUCCESS) {
68,949,594✔
148
    goto _error;
×
149
  }
150

151
  *pOptrInfo = pOperator;
68,949,594✔
152
  return TSDB_CODE_SUCCESS;
68,965,008✔
153

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

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

171
  if (pInfo->pOperator) {
69,081,822✔
172
    cleanupResultInfo(pInfo->pOperator->pTaskInfo, &pInfo->pOperator->exprSupp, &pInfo->groupResInfo, &pInfo->aggSup,
69,049,767✔
173
                      pInfo->cleanGroupResInfo);
69,064,906✔
174
    pInfo->pOperator = NULL;
69,034,953✔
175
  }
176
  cleanupAggSup(&pInfo->aggSup);
69,053,082✔
177
  cleanupExprSuppWithoutFilter(&pInfo->scalarExprSup);
69,064,741✔
178
  cleanupGroupResInfo(&pInfo->groupResInfo);
69,042,974✔
179
  taosMemoryFreeClear(param);
69,047,341✔
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) {
87,320,812✔
190
  int32_t           code = TSDB_CODE_SUCCESS;
87,320,812✔
191
  int32_t           lino = 0;
87,320,812✔
192
  SExecTaskInfo*    pTaskInfo = pOperator->pTaskInfo;
87,320,812✔
193
  SAggOperatorInfo* pAggInfo = pOperator->info;
87,316,420✔
194

195
  if(!pAggInfo) {
87,290,768✔
196
    qError("function:%s, pAggInfo is NULL", __func__);
×
197
    return false;
×
198
  }
199
  if (pOperator->blocking && pAggInfo->hasValidBlock) {
87,290,768✔
200
    return false;
9,505,565✔
201
  }
202

203
  SExprSupp*   pSup = &pOperator->exprSupp;
77,785,485✔
204
  int64_t      st = taosGetTimestampUs();
77,802,682✔
205
  int32_t      order = pAggInfo->binfo.inputTsOrder;
77,802,682✔
206
  SSDataBlock* pBlock = pAggInfo->pNewGroupBlock;
77,797,631✔
207

208
  pAggInfo->cleanGroupResInfo = false;
77,792,370✔
209
  if (pBlock) {
77,794,401✔
210
    pAggInfo->pNewGroupBlock = NULL;
679,637✔
211
    tSimpleHashClear(pAggInfo->aggSup.pResultRowHashTable);
679,637✔
212
    code = setExecutionContext(pOperator, pOperator->exprSupp.numOfExprs, pBlock->info.id.groupId);
679,637✔
213
    QUERY_CHECK_CODE(code, lino, _end);
679,637✔
214
    code = setInputDataBlock(pSup, pBlock, order, pBlock->info.scanFlag, true);
679,637✔
215
    QUERY_CHECK_CODE(code, lino, _end);
679,637✔
216

217
    code = doAggregateImpl(pOperator, pSup->pCtx);
679,637✔
218
    QUERY_CHECK_CODE(code, lino, _end);
667,261✔
219
  }
220
  while (1) {
512,457,881✔
221
    bool blockAllocated = false;
590,239,906✔
222
    pBlock = getNextBlockFromDownstreamRemain(pOperator, 0);
590,239,906✔
223
    if (pOperator->pDownstreamGetParams) {
588,068,620✔
224
      pOperator->pDownstreamGetParams[0] = NULL;
17,932,476✔
225
    }
226
    if (pBlock == NULL) {
588,081,937✔
227
      if (!pAggInfo->hasValidBlock) {
78,108,097✔
228
        code = createDataBlockForEmptyInput(pOperator, &pBlock);
18,155,279✔
229
        QUERY_CHECK_CODE(code, lino, _end);
18,154,318✔
230

231
        if (pBlock == NULL) {
18,154,318✔
232
          break;
14,883,604✔
233
        }
234
        blockAllocated = true;
3,270,714✔
235
      } else {
236
        break;
59,952,344✔
237
      }
238
    }
239
    pAggInfo->hasValidBlock = true;
513,244,554✔
240
    pAggInfo->binfo.pRes->info.scanFlag = pBlock->info.scanFlag;
513,249,792✔
241

242
    printDataBlock(pBlock, __func__, pTaskInfo->id.str, pTaskInfo->id.queryId);
513,249,563✔
243

244
    // there is an scalar expression that needs to be calculated before apply the group aggregation.
245
    if (pAggInfo->scalarExprSup.pExprInfo != NULL && !blockAllocated) {
513,213,355✔
246
      SExprSupp* pSup1 = &pAggInfo->scalarExprSup;
75,998,802✔
247
      code = projectApplyFunctions(pSup1->pExprInfo, pBlock, pBlock, pSup1->pCtx, pSup1->numOfExprs, NULL, GET_STM_RTINFO(pOperator->pTaskInfo));
75,995,072✔
248
      if (code != TSDB_CODE_SUCCESS) {
75,986,292✔
249
        destroyDataBlockForEmptyInput(blockAllocated, &pBlock);
32,736✔
250
        T_LONG_JMP(pTaskInfo->env, code);
32,736✔
251
      }
252
    }
253
    // if non-blocking mode and new group arrived, save the block and break
254
    if (!pOperator->blocking && pAggInfo->groupId != UINT64_MAX && pBlock->info.id.groupId != pAggInfo->groupId) {
513,166,958✔
255
      pAggInfo->pNewGroupBlock = pBlock;
692,151✔
256
      break;
692,151✔
257
    }
258
    // the pDataBlock are always the same one, no need to call this again
259
    code = setExecutionContext(pOperator, pOperator->exprSupp.numOfExprs, pBlock->info.id.groupId);
512,480,722✔
260
    if (code != TSDB_CODE_SUCCESS) {
512,475,954✔
261
      destroyDataBlockForEmptyInput(blockAllocated, &pBlock);
×
262
      T_LONG_JMP(pTaskInfo->env, code);
×
263
    }
264
    code = setInputDataBlock(pSup, pBlock, order, pBlock->info.scanFlag, true);
512,475,954✔
265
    if (code != TSDB_CODE_SUCCESS) {
512,483,976✔
266
      destroyDataBlockForEmptyInput(blockAllocated, &pBlock);
×
267
      T_LONG_JMP(pTaskInfo->env, code);
×
268
    }
269

270
    code = doAggregateImpl(pOperator, pSup->pCtx);
512,483,976✔
271
    if (code != TSDB_CODE_SUCCESS) {
512,448,899✔
272
      destroyDataBlockForEmptyInput(blockAllocated, &pBlock);
2,844✔
273
      T_LONG_JMP(pTaskInfo->env, code);
2,844✔
274
    }
275

276
    destroyDataBlockForEmptyInput(blockAllocated, &pBlock);
512,446,055✔
277
  }
278

279
  // the downstream operator may return with error code, so let's check the code before generating results.
280
  if (pTaskInfo->code != TSDB_CODE_SUCCESS) {
75,528,099✔
281
    T_LONG_JMP(pTaskInfo->env, pTaskInfo->code);
×
282
  }
283

284
  code = initGroupedResultInfo(&pAggInfo->groupResInfo, pAggInfo->aggSup.pResultRowHashTable, 0);
75,526,617✔
285
  QUERY_CHECK_CODE(code, lino, _end);
75,529,607✔
286
  pAggInfo->cleanGroupResInfo = true;
75,529,607✔
287

288
_end:
75,531,513✔
289
  if (code != TSDB_CODE_SUCCESS) {
75,529,646✔
290
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
91✔
291
    pTaskInfo->code = code;
91✔
292
    T_LONG_JMP(pTaskInfo->env, code);
×
293
  }
294
  return pBlock != NULL;
75,530,527✔
295
}
296

297
int32_t getAggregateResultNext(SOperatorInfo* pOperator, SSDataBlock** ppRes) {
143,504,833✔
298
  int32_t           code = TSDB_CODE_SUCCESS;
143,504,833✔
299
  int32_t           lino = 0;
143,504,833✔
300
  SAggOperatorInfo* pAggInfo = pOperator->info;
143,504,833✔
301
  SOptrBasicInfo*   pInfo = &pAggInfo->binfo;
143,502,295✔
302

303
  if (pOperator->status == OP_EXEC_DONE && !pOperator->pOperatorGetParam) {
143,504,569✔
304
    (*ppRes) = NULL;
56,200,333✔
305
    return code;
56,198,499✔
306
  }
307

308
  if (pOperator->pOperatorGetParam) {
87,305,526✔
309
    if (pOperator->status == OP_EXEC_DONE) {
5,943,251✔
310
      pOperator->status = OP_OPENED;
3,710,019✔
311
      tSimpleHashClear(pAggInfo->aggSup.pResultRowHashTable);
3,713,060✔
312
      pAggInfo->groupId = UINT64_MAX;
3,716,289✔
313
      pAggInfo->hasValidBlock = false;
3,716,289✔
314
    }
315
    freeOperatorParam(pOperator->pOperatorGetParam, OP_GET_PARAM);
5,944,608✔
316
    pOperator->pOperatorGetParam = NULL;
5,944,044✔
317

318
  }
319

320
  SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
87,302,979✔
321
  bool           hasNewGroups = false;
87,310,149✔
322
  do {
323
    hasNewGroups = nextGroupedResult(pOperator);
87,321,166✔
324
    code = blockDataEnsureCapacity(pInfo->pRes, pOperator->resultInfo.capacity);
85,034,170✔
325
    QUERY_CHECK_CODE(code, lino, _end);
85,038,765✔
326

327
    while (1) {
328
      doBuildResultDatablock(pOperator, pInfo, &pAggInfo->groupResInfo, pAggInfo->aggSup.pResultBuf);
85,038,765✔
329
      code = doFilter(pInfo->pRes, pOperator->exprSupp.pFilterInfo, NULL, NULL);
85,038,033✔
330
      QUERY_CHECK_CODE(code, lino, _end);
85,037,859✔
331

332
      if (!hasRemainResults(&pAggInfo->groupResInfo)) {
85,037,859✔
333
        if (!hasNewGroups) setOperatorCompleted(pOperator);
75,526,013✔
334
        break;
75,527,453✔
335
      }
336

337
      if (pInfo->pRes->info.rows > 0) {
9,511,937✔
338
        break;
9,511,937✔
339
      }
340
    }
341
  } while (pInfo->pRes->info.rows == 0 && hasNewGroups);
85,039,390✔
342

343
  size_t rows = blockDataGetNumOfRows(pInfo->pRes);
85,026,948✔
344
  pOperator->resultInfo.totalRows += rows;
85,027,962✔
345

346
_end:
85,025,418✔
347
  if (code != TSDB_CODE_SUCCESS) {
85,025,418✔
348
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
×
349
    pTaskInfo->code = code;
×
350
    T_LONG_JMP(pTaskInfo->env, code);
×
351
  }
352

353
  printDataBlock(pInfo->pRes, __func__, pTaskInfo->id.str, pTaskInfo->id.queryId);
85,025,418✔
354

355
  (*ppRes) = (rows == 0) ? NULL : pInfo->pRes;
85,023,494✔
356
  return code;
85,024,211✔
357
}
358

359
int32_t doAggregateImpl(SOperatorInfo* pOperator, SqlFunctionCtx* pCtx) {
513,168,981✔
360
  int32_t code = TSDB_CODE_SUCCESS;
513,168,981✔
361
  if (!pOperator || (pOperator->exprSupp.numOfExprs > 0 && pCtx == NULL)) {
513,168,981✔
362
    qError("%s failed at line %d since pCtx is NULL.", __func__, __LINE__);
34,703✔
363
    return TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR;
×
364
  }
365
  for (int32_t k = 0; k < pOperator->exprSupp.numOfExprs; ++k) {
2,147,483,647✔
366
    if (functionNeedToExecute(&pCtx[k])) {
2,147,483,647✔
367
      // todo add a dummy function to avoid process check
368
      if (pCtx[k].fpSet.process == NULL) {
2,147,483,647✔
369
        continue;
9,247,157✔
370
      }
371

372
      if ((&pCtx[k])->input.pData[0] == NULL) {
2,147,483,647✔
373
        code = TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR;
×
374
        qError("%s aggregate function error happens, input data is NULL.", GET_TASKID(pOperator->pTaskInfo));
×
375
      } else {
376
        code = pCtx[k].fpSet.process(&pCtx[k]);
2,147,483,647✔
377
      }
378

379
      if (code != TSDB_CODE_SUCCESS) {
2,147,483,647✔
380
        if (pCtx[k].fpSet.cleanup != NULL) {
2,844✔
381
          pCtx[k].fpSet.cleanup(&pCtx[k]);
×
382
        }
383
        qError("%s aggregate function error happens, code:%s", GET_TASKID(pOperator->pTaskInfo), tstrerror(code));
2,844✔
384
        return code;
2,844✔
385
      }
386
    }
387
  }
388

389
  return TSDB_CODE_SUCCESS;
513,150,837✔
390
}
391

392
static int32_t createDataBlockForEmptyInput(SOperatorInfo* pOperator, SSDataBlock** ppBlock) {
18,155,241✔
393
  int32_t code = TSDB_CODE_SUCCESS;
18,155,241✔
394
  int32_t lino = 0;
18,155,241✔
395
  SSDataBlock* pBlock = NULL;
18,155,241✔
396
  if (!tsCountAlwaysReturnValue) {
18,155,173✔
397
    return TSDB_CODE_SUCCESS;
6,094,598✔
398
  }
399

400
  SAggOperatorInfo* pAggInfo = pOperator->info;
12,060,575✔
401
  if (pAggInfo->groupKeyOptimized) {
12,057,222✔
402
    return TSDB_CODE_SUCCESS;
4,785,911✔
403
  }
404

405
  SOperatorInfo* downstream = pOperator->pDownstream[0];
7,271,726✔
406
  if (downstream->operatorType == QUERY_NODE_PHYSICAL_PLAN_PARTITION ||
7,269,597✔
407
      downstream->operatorType == QUERY_NODE_PHYSICAL_PLAN_SORT ||
7,236,424✔
408
      (downstream->operatorType == QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN &&
7,237,213✔
409
       ((STableScanInfo*)downstream->info)->hasGroupByTag == true)) {
4,346,086✔
410
    return TSDB_CODE_SUCCESS;
34,572✔
411
  }
412

413
  SqlFunctionCtx* pCtx = pOperator->exprSupp.pCtx;
7,237,447✔
414

415
  if (!pAggInfo->hasCountFunc) {
7,236,577✔
416
    return TSDB_CODE_SUCCESS;
3,965,227✔
417
  }
418

419
  code = createDataBlock(&pBlock);
3,269,472✔
420
  if (code) {
3,271,339✔
421
    return code;
×
422
  }
423

424
  pBlock->info.rows = 1;
3,271,339✔
425
  pBlock->info.capacity = 0;
3,270,714✔
426

427
  for (int32_t i = 0; i < pOperator->exprSupp.numOfExprs; ++i) {
9,073,269✔
428
    SColumnInfoData colInfo = {0};
5,800,688✔
429
    colInfo.hasNull = true;
5,800,688✔
430
    colInfo.info.type = TSDB_DATA_TYPE_NULL;
5,800,688✔
431
    colInfo.info.bytes = 1;
5,800,688✔
432

433
    SExprInfo* pOneExpr = &pOperator->exprSupp.pExprInfo[i];
5,800,688✔
434
    for (int32_t j = 0; j < pOneExpr->base.numOfParams; ++j) {
11,814,453✔
435
      SFunctParam* pFuncParam = &pOneExpr->base.pParam[j];
6,015,007✔
436
      if (pFuncParam->type == FUNC_PARAM_TYPE_COLUMN) {
6,014,382✔
437
        int32_t slotId = pFuncParam->pCol->slotId;
6,013,533✔
438
        int32_t numOfCols = taosArrayGetSize(pBlock->pDataBlock);
6,012,908✔
439
        if (slotId >= numOfCols) {
6,012,908✔
440
          code = taosArrayEnsureCap(pBlock->pDataBlock, slotId + 1);
3,675,971✔
441
          QUERY_CHECK_CODE(code, lino, _end);
3,674,729✔
442

443
          for (int32_t k = numOfCols; k < slotId + 1; ++k) {
10,062,928✔
444
            void* tmp = taosArrayPush(pBlock->pDataBlock, &colInfo);
6,386,957✔
445
            QUERY_CHECK_NULL(tmp, code, lino, _end, terrno);
6,388,199✔
446
          }
447
        }
448
      } else if (pFuncParam->type == FUNC_PARAM_TYPE_VALUE) {
1,474✔
449
        // do nothing
450
      }
451
    }
452
  }
453

454
  code = blockDataEnsureCapacity(pBlock, pBlock->info.rows);
3,271,331✔
455
  QUERY_CHECK_CODE(code, lino, _end);
3,271,331✔
456

457
  for (int32_t i = 0; i < blockDataGetNumOfCols(pBlock); ++i) {
9,660,147✔
458
    SColumnInfoData* pColInfoData = taosArrayGet(pBlock->pDataBlock, i);
6,388,191✔
459
    QUERY_CHECK_NULL(pColInfoData, code, lino, _end, terrno);
6,386,957✔
460
    colDataSetNULL(pColInfoData, 0);
461
  }
462
  *ppBlock = pBlock;
3,272,581✔
463

464
_end:
3,271,956✔
465
  if (code != TSDB_CODE_SUCCESS) {
3,271,956✔
466
    blockDataDestroy(pBlock);
×
467
    qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(code));
×
468
  }
469
  return code;
3,269,480✔
470
}
471

472
void destroyDataBlockForEmptyInput(bool blockAllocated, SSDataBlock** ppBlock) {
512,478,776✔
473
  if (!blockAllocated) {
512,478,776✔
474
    return;
509,231,014✔
475
  }
476

477
  blockDataDestroy(*ppBlock);
3,247,762✔
478
  *ppBlock = NULL;
3,267,503✔
479
}
480

481
int32_t setExecutionContext(SOperatorInfo* pOperator, int32_t numOfOutput, uint64_t groupId) {
513,167,708✔
482
  int32_t           code = TSDB_CODE_SUCCESS;
513,167,708✔
483
  SAggOperatorInfo* pAggInfo = pOperator->info;
513,167,708✔
484
  if (pAggInfo->groupId != UINT64_MAX && pAggInfo->groupId == groupId) {
513,205,297✔
485
    return code;
354,342,651✔
486
  }
487

488
  code = doSetTableGroupOutputBuf(pOperator, numOfOutput, groupId);
158,861,184✔
489

490
  // record the current active group id
491
  pAggInfo->groupId = groupId;
158,821,707✔
492
  return code;
158,846,449✔
493
}
494

495
int32_t doSetTableGroupOutputBuf(SOperatorInfo* pOperator, int32_t numOfOutput, uint64_t groupId) {
158,842,743✔
496
  // for simple group by query without interval, all the tables belong to one group result.
497
  int32_t           code = TSDB_CODE_SUCCESS;
158,842,743✔
498
  int32_t           lino = 0;
158,842,743✔
499
  SExecTaskInfo*    pTaskInfo = pOperator->pTaskInfo;
158,842,743✔
500
  SAggOperatorInfo* pAggInfo = pOperator->info;
158,850,456✔
501

502
  SResultRowInfo* pResultRowInfo = &pAggInfo->binfo.resultRowInfo;
158,853,746✔
503
  SqlFunctionCtx* pCtx = pOperator->exprSupp.pCtx;
158,840,141✔
504
  int32_t*        rowEntryInfoOffset = pOperator->exprSupp.rowEntryInfoOffset;
158,850,851✔
505

506
  SResultRow* pResultRow =
507
      doSetResultOutBufByKey(pAggInfo->aggSup.pResultBuf, pResultRowInfo, (char*)&groupId, sizeof(groupId), true,
158,836,362✔
508
                             groupId, pTaskInfo, false, &pAggInfo->aggSup, true);
509
  if (pResultRow == NULL || pTaskInfo->code != 0) {
158,850,560✔
510
    code = pTaskInfo->code;
8,775✔
511
    lino = __LINE__;
×
512
    goto _end;
×
513
  }
514
  /*
515
   * not assign result buffer yet, add new result buffer
516
   * all group belong to one result set, and each group result has different group id so set the id to be one
517
   */
518
  if (pResultRow->pageId == -1) {
158,831,595✔
519
    code = addNewResultRowBuf(pResultRow, pAggInfo->aggSup.pResultBuf, pAggInfo->binfo.pRes->info.rowSize);
×
520
    QUERY_CHECK_CODE(code, lino, _end);
×
521
  }
522

523
  code = setResultRowInitCtx(pResultRow, pCtx, numOfOutput, rowEntryInfoOffset);
158,830,926✔
524
  QUERY_CHECK_CODE(code, lino, _end);
158,839,893✔
525

526
_end:
158,839,893✔
527
  if (code != TSDB_CODE_SUCCESS) {
158,839,893✔
528
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
×
529
  }
530
  return code;
158,827,792✔
531
}
532

533
// a new buffer page for each table. Needs to opt this design
534
int32_t addNewResultRowBuf(SResultRow* pWindowRes, SDiskbasedBuf* pResultBuf, uint32_t size) {
×
535
  if (pWindowRes->pageId != -1) {
×
536
    return 0;
×
537
  }
538

539
  SFilePage* pData = NULL;
×
540

541
  // in the first scan, new space needed for results
542
  int32_t pageId = -1;
×
543
  SArray* list = getDataBufPagesIdList(pResultBuf);
×
544

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

560
    pageId = getPageId(pi);
×
561

562
    if (pData->num + size > getBufPageSize(pResultBuf)) {
×
563
      // release current page first, and prepare the next one
564
      releaseBufPageInfo(pResultBuf, pi);
×
565

566
      pData = getNewBufPage(pResultBuf, &pageId);
×
567
      if (pData == NULL) {
×
568
        qError("failed to get buffer, code:%s", tstrerror(terrno));
×
569
        return terrno;
×
570
      }
571
      pData->num = sizeof(SFilePage);
×
572
    }
573
  }
574

575
  if (pData == NULL) {
×
576
    return -1;
×
577
  }
578

579
  // set the number of rows in current disk page
580
  if (pWindowRes->pageId == -1) {  // not allocated yet, allocate new buffer
×
581
    pWindowRes->pageId = pageId;
×
582
    pWindowRes->offset = (int32_t)pData->num;
×
583

584
    pData->num += size;
×
585
  }
586

587
  return 0;
×
588
}
589

590
int32_t doInitAggInfoSup(SAggSupporter* pAggSup, SqlFunctionCtx* pCtx, int32_t numOfOutput, size_t keyBufSize,
203,159,526✔
591
                         const char* pKey) {
592
  int32_t code = 0;
203,159,526✔
593
  //  _hash_fn_t hashFn = taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY);
594

595
  pAggSup->currentPageId = -1;
203,159,526✔
596
  pAggSup->resultRowSize = getResultRowSize(pCtx, numOfOutput);
203,178,201✔
597
  pAggSup->keyBuf = taosMemoryCalloc(1, keyBufSize + POINTER_BYTES + sizeof(int64_t));
202,946,834✔
598
  pAggSup->pResultRowHashTable = tSimpleHashInit(100, taosFastHash);
203,131,139✔
599

600
  if (pAggSup->keyBuf == NULL || pAggSup->pResultRowHashTable == NULL) {
203,160,983✔
601
    return terrno;
7,427✔
602
  }
603

604
  uint32_t defaultPgsz = 0;
203,099,415✔
605
  int64_t defaultBufsz = 0;
203,013,802✔
606
  code = getBufferPgSize(pAggSup->resultRowSize, &defaultPgsz, &defaultBufsz);
203,101,372✔
607
  if (code) {
202,940,502✔
608
    qError("failed to get buff page size, rowSize:%d", pAggSup->resultRowSize);
×
609
    return code;
×
610
  }
611

612
  if (!osTempSpaceAvailable()) {
202,940,502✔
613
    code = TSDB_CODE_NO_DISKSPACE;
×
614
    qError("Init stream agg supporter failed since %s, key:%s, tempDir:%s", tstrerror(code), pKey, tsTempDir);
×
615
    return code;
×
616
  }
617

618
  code = createDiskbasedBuf(&pAggSup->pResultBuf, defaultPgsz, defaultBufsz, pKey, tsTempDir);
203,172,119✔
619
  if (code != TSDB_CODE_SUCCESS) {
203,173,389✔
620
    qError("Create agg result buf failed since %s, %s", tstrerror(code), pKey);
×
621
    return code;
×
622
  }
623

624
  return code;
203,173,389✔
625
}
626

627
void cleanupResultInfoInGroupResInfo(SExecTaskInfo* pTaskInfo, SExprSupp* pSup, SDiskbasedBuf* pBuf,
76,549,514✔
628
                                  SGroupResInfo* pGroupResInfo) {
629
  int32_t         numOfExprs = pSup->numOfExprs;
76,549,514✔
630
  int32_t*        rowEntryOffset = pSup->rowEntryInfoOffset;
76,555,750✔
631
  SqlFunctionCtx* pCtx = pSup->pCtx;
76,542,289✔
632
  int32_t         numOfRows = getNumOfTotalRes(pGroupResInfo);
76,544,528✔
633
  bool            needCleanup = false;
76,529,381✔
634

635
  for (int32_t j = 0; j < numOfExprs; ++j) {
84,475,282✔
636
    needCleanup |= pCtx[j].needCleanup;
7,945,901✔
637
  }
638
  if (!needCleanup) {
76,529,381✔
639
    return;
76,525,987✔
640
  }
641

642
  for (int32_t i = pGroupResInfo->index; i < numOfRows; i += 1) {
3,394✔
643
    SResultRow*        pRow = NULL;
×
644
    SResKeyPos*        pPos = taosArrayGetP(pGroupResInfo->pRows, i);
×
645
    SFilePage*         page = getBufPage(pBuf, pPos->pos.pageId);
×
646
    if (page == NULL) {
×
647
      qError("failed to get buffer, code:%s, %s", tstrerror(terrno), GET_TASKID(pTaskInfo));
×
648
      continue;
×
649
    }
650
    pRow = (SResultRow*)((char*)page + pPos->pos.offset);
×
651

652

653
    for (int32_t j = 0; j < numOfExprs; ++j) {
×
654
      pCtx[j].resultInfo = getResultEntryInfo(pRow, j, rowEntryOffset);
×
655
      if (pCtx[j].fpSet.cleanup) {
×
656
        pCtx[j].fpSet.cleanup(&pCtx[j]);
×
657
      }
658
    }
659
    releaseBufPage(pBuf, page);
×
660
  }
661
}
662

663
void cleanupResultInfoInHashMap(SExecTaskInfo* pTaskInfo, SExprSupp* pSup, SDiskbasedBuf* pBuf,
33,346,776✔
664
                       SGroupResInfo* pGroupResInfo, SSHashObj* pHashmap) {
665
  int32_t         numOfExprs = pSup->numOfExprs;
33,346,776✔
666
  int32_t*        rowEntryOffset = pSup->rowEntryInfoOffset;
33,346,412✔
667
  SqlFunctionCtx* pCtx = pSup->pCtx;
33,349,062✔
668
  bool            needCleanup = false;
33,345,030✔
669
  for (int32_t j = 0; j < numOfExprs; ++j) {
43,699,021✔
670
    needCleanup |= pCtx[j].needCleanup;
10,351,423✔
671
  }
672
  if (!needCleanup) {
33,347,598✔
673
    return;
33,348,823✔
674
  }
675

676
  // begin from last iter
677
  void*   pData = pGroupResInfo->dataPos;
×
678
  int32_t iter = pGroupResInfo->iter;
×
679
  while ((pData = tSimpleHashIterate(pHashmap, pData, &iter)) != NULL) {
×
680
    SResultRowPosition* pos = pData;
×
681

682
    SFilePage* page = getBufPage(pBuf, pos->pageId);
×
683
    if (page == NULL) {
×
684
      qError("failed to get buffer, code:%s, %s", tstrerror(terrno), GET_TASKID(pTaskInfo));
×
685
      continue;
×
686
    }
687

688
    SResultRow* pRow = (SResultRow*)((char*)page + pos->offset);
×
689

690
    for (int32_t j = 0; j < numOfExprs; ++j) {
×
691
      pCtx[j].resultInfo = getResultEntryInfo(pRow, j, rowEntryOffset);
×
692
      if (pCtx[j].fpSet.cleanup) {
×
693
        pCtx[j].fpSet.cleanup(&pCtx[j]);
×
694
      }
695
    }
696

697
    releaseBufPage(pBuf, page);
×
698
  }
699
}
700

701
void cleanupResultInfo(SExecTaskInfo* pTaskInfo, SExprSupp* pSup, SGroupResInfo* pGroupResInfo,
109,902,325✔
702
                       SAggSupporter *pAggSup, bool cleanGroupResInfo) {
703
  if (cleanGroupResInfo) {
109,902,325✔
704
    cleanupResultInfoInGroupResInfo(pTaskInfo, pSup, pAggSup->pResultBuf, pGroupResInfo);
76,554,642✔
705
  } else {
706
    cleanupResultInfoInHashMap(pTaskInfo, pSup, pAggSup->pResultBuf, pGroupResInfo, pAggSup->pResultRowHashTable);
33,347,683✔
707
  }
708
}
109,867,149✔
709
void cleanupAggSup(SAggSupporter* pAggSup) {
203,598,554✔
710
  taosMemoryFreeClear(pAggSup->keyBuf);
203,598,554✔
711
  tSimpleHashCleanup(pAggSup->pResultRowHashTable);
203,573,403✔
712
  destroyDiskbasedBuf(pAggSup->pResultBuf);
203,593,271✔
713
  memset(pAggSup, 0, sizeof(SAggSupporter));
203,594,618✔
714
}
203,594,618✔
715

716
int32_t initAggSup(SExprSupp* pSup, SAggSupporter* pAggSup, SExprInfo* pExprInfo, int32_t numOfCols, size_t keyBufSize,
203,177,593✔
717
                   const char* pkey, void* pState, SFunctionStateStore* pStore) {
718
  int32_t code = initExprSupp(pSup, pExprInfo, numOfCols, pStore);
203,177,593✔
719
  if (code != TSDB_CODE_SUCCESS) {
202,987,557✔
720
    return code;
×
721
  }
722

723
  code = doInitAggInfoSup(pAggSup, pSup->pCtx, numOfCols, keyBufSize, pkey);
202,987,557✔
724
  if (code != TSDB_CODE_SUCCESS) {
203,119,078✔
725
    return code;
×
726
  }
727

728
  for (int32_t i = 0; i < numOfCols; ++i) {
1,013,267,716✔
729
    pSup->pCtx[i].hasWindowOrGroup = pSup->hasWindowOrGroup;
810,286,508✔
730
    pSup->pCtx[i].hasWindow= pSup->hasWindow;
810,243,697✔
731
    if (pState) {
810,031,326✔
732
      pSup->pCtx[i].saveHandle.pBuf = NULL;
×
733
      pSup->pCtx[i].saveHandle.pState = pState;
×
734
      pSup->pCtx[i].exprIdx = i;
×
735
    } else {
736
      pSup->pCtx[i].saveHandle.pBuf = pAggSup->pResultBuf;
810,031,326✔
737
    }
738
  }
739

740
  return TSDB_CODE_SUCCESS;
202,981,208✔
741
}
742

743
int32_t applyAggFunctionOnPartialTuples(SExecTaskInfo* taskInfo, SqlFunctionCtx* pCtx, SColumnInfoData* pTimeWindowData,
2,147,483,647✔
744
                                        int32_t offset, int32_t forwardStep, int32_t numOfTotal, int32_t numOfOutput) {
745
  int32_t code = TSDB_CODE_SUCCESS, lino = 0;
2,147,483,647✔
746
  for (int32_t k = 0; k < numOfOutput; ++k) {
2,147,483,647✔
747
    // keep it temporarily
748
    SFunctionCtxStatus status = {0};
2,147,483,647✔
749
    functionCtxSave(&pCtx[k], &status);
2,147,483,647✔
750

751
    pCtx[k].input.startRowIndex = offset;
2,147,483,647✔
752
    pCtx[k].input.numOfRows = forwardStep;
2,147,483,647✔
753

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

760
    if (fmIsPlaceHolderFunc(pCtx[k].functionId)) {
2,147,483,647✔
761
      SResultRowEntryInfo* pEntryInfo = GET_RES_INFO(&pCtx[k]);
35,023,497✔
762
      char* p = GET_ROWCELL_INTERBUF(pEntryInfo);
35,026,095✔
763

764
      TAOS_CHECK_EXIT(fmSetStreamPseudoFuncParamVal(pCtx[k].functionId, pCtx[k].pExpr->base.pParamList, &taskInfo->pStreamRuntimeInfo->funcInfo));
35,028,039✔
765

766
      SValueNode *valueNode = (SValueNode *)nodesListGetNode(pCtx[k].pExpr->base.pParamList, 0);
35,043,297✔
767
      pEntryInfo->isNullRes = 0;
35,042,001✔
768
      if (TSDB_DATA_TYPE_NULL == valueNode->node.resType.type || valueNode->isNull) {
35,042,445✔
769
        pEntryInfo->isNullRes = 1;
216✔
770
      } else if (IS_VAR_DATA_TYPE(pCtx[k].pExpr->base.resSchema.type)){
35,042,764✔
771
        void* v = nodesGetValueFromNode(valueNode);
8,866✔
772
        memcpy(p, v, varDataTLen(v));
9,944✔
773
      } else {
774
        memcpy(p, nodesGetValueFromNode(valueNode), pCtx[k].pExpr->base.resSchema.bytes);
35,036,722✔
775
      }
776
      
777
      pEntryInfo->numOfRes = 1;
35,041,684✔
778
    } else if (pCtx[k].isPseudoFunc) {
2,147,483,647✔
779
      SResultRowEntryInfo* pEntryInfo = GET_RES_INFO(&pCtx[k]);
2,147,483,647✔
780

781
      char* p = GET_ROWCELL_INTERBUF(pEntryInfo);
2,147,483,647✔
782

783
      SColumnInfoData idata = {0};
2,147,483,647✔
784
      idata.info.type = TSDB_DATA_TYPE_BIGINT;
2,147,483,647✔
785
      idata.info.bytes = tDataTypes[TSDB_DATA_TYPE_BIGINT].bytes;
2,147,483,647✔
786
      idata.pData = p;
2,147,483,647✔
787

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

802
        if (code != TSDB_CODE_SUCCESS) {
2,147,483,647✔
803
          if (pCtx[k].fpSet.cleanup != NULL) {
433✔
804
            pCtx[k].fpSet.cleanup(&pCtx[k]);
433✔
805
          }
806
          TAOS_CHECK_EXIT(code);
433✔
807
        }
808
      }
809

810
      // restore it
811
      functionCtxRestore(&pCtx[k], &status);
2,147,483,647✔
812
    }
813
  }
814

815
_exit:
2,147,483,647✔
816

817
  if (code) {
2,147,483,647✔
818
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
433✔
819
    taskInfo->code = code;
433✔
820
  }
821

822
  return code;
2,147,483,647✔
823
}
824

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

831
void functionCtxRestore(SqlFunctionCtx* pCtx, SFunctionCtxStatus* pStatus) {
2,147,483,647✔
832
  pCtx->input.colDataSMAIsSet = pStatus->hasAgg;
2,147,483,647✔
833
  pCtx->input.numOfRows = pStatus->numOfRows;
2,147,483,647✔
834
  pCtx->input.startRowIndex = pStatus->startOffset;
2,147,483,647✔
835
}
2,147,483,647✔
836

837
static int32_t resetAggregateOperatorState(SOperatorInfo* pOper) {
5,491,870✔
838
  SAggOperatorInfo* pAgg = pOper->info;
5,491,870✔
839
  SAggPhysiNode*   pAggNode = (SAggPhysiNode*)pOper->pPhyNode;
5,493,589✔
840
  
841
  pOper->status = OP_NOT_OPENED;
5,493,290✔
842
  size_t keyBufSize = sizeof(int64_t) + sizeof(int64_t) + POINTER_BYTES;
5,493,290✔
843
  SExecTaskInfo*  pTaskInfo = pOper->pTaskInfo;
5,493,290✔
844
  cleanupResultInfo(pTaskInfo, &pOper->exprSupp, &pAgg->groupResInfo, &pAgg->aggSup,
5,494,445✔
845
                      pAgg->cleanGroupResInfo);
5,493,803✔
846
  cleanupGroupResInfo(&pAgg->groupResInfo);
5,492,777✔
847
  resetBasicOperatorState(&pAgg->binfo);
5,490,844✔
848
  
849
  pAgg->pNewGroupBlock = NULL;
5,494,231✔
850

851
  int32_t code = resetAggSup(&pOper->exprSupp, &pAgg->aggSup, pTaskInfo, pAggNode->pAggFuncs, pAggNode->pGroupKeys,
10,987,811✔
852
    keyBufSize, pTaskInfo->id.str, pTaskInfo->streamInfo.pState, &pTaskInfo->storageAPI.functionStore);
5,492,641✔
853

854
  if (code == 0) {
5,492,947✔
855
    code = resetExprSupp(&pAgg->scalarExprSup, pTaskInfo, pAggNode->pExprs, NULL,
5,492,947✔
856
                          &pTaskInfo->storageAPI.functionStore);
857
  }
858

859
  pAgg->groupId = UINT64_MAX;
5,493,154✔
860
  pAgg->cleanGroupResInfo = false;
5,493,154✔
861
  pAgg->hasValidBlock = false;
5,493,368✔
862
  return 0;
5,494,231✔
863
}
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