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

taosdata / TDengine / #4981

11 Mar 2026 06:29AM UTC coverage: 68.488% (-0.004%) from 68.492%
#4981

push

travis-ci

web-flow
enh: [6548485194] Support push down ts condition in vtable query. (#34718)

62 of 76 new or added lines in 2 files covered. (81.58%)

859 existing lines in 123 files now uncovered.

211924 of 309434 relevant lines covered (68.49%)

135102255.25 hits per line

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

79.48
/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,
91,660,198✔
77
                                    SOperatorInfo** pOptrInfo) {
78
  QRY_PARAM_CHECK(pOptrInfo);
91,660,198✔
79

80
  int32_t    lino = 0;
91,673,683✔
81
  int32_t    code = 0;
91,673,683✔
82
  int32_t    num = 0;
91,673,683✔
83
  SExprInfo* pExprInfo = NULL;
91,672,186✔
84
  int32_t    numOfScalarExpr = 0;
91,662,996✔
85
  SExprInfo* pScalarExprInfo = NULL;
91,648,766✔
86

87
  SAggOperatorInfo* pInfo = taosMemoryCalloc(1, sizeof(SAggOperatorInfo));
91,636,992✔
88
  SOperatorInfo*    pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo));
91,580,252✔
89
  if (pInfo == NULL || pOperator == NULL) {
91,577,783✔
UNCOV
90
    code = terrno;
×
91
    goto _error;
×
92
  }
93

94
  pOperator->exprSupp.hasWindowOrGroup = false;
91,578,619✔
95

96
  SSDataBlock* pResBlock = createDataBlockFromDescNode(pAggNode->node.pOutputDataBlockDesc);
91,580,513✔
97
  QUERY_CHECK_NULL(pResBlock, code, lino, _error, terrno);
91,679,645✔
98
  initBasicInfo(&pInfo->binfo, pResBlock);
91,679,645✔
99

100
  size_t keyBufSize = sizeof(int64_t) + sizeof(int64_t) + POINTER_BYTES;
91,661,246✔
101
  initResultSizeInfo(&pOperator->resultInfo, 4096);
91,661,246✔
102

103

104
  code = createExprInfo(pAggNode->pAggFuncs, pAggNode->pGroupKeys, &pExprInfo, &num);
91,674,349✔
105
  TSDB_CHECK_CODE(code, lino, _error);
91,661,748✔
106

107
  code = initAggSup(&pOperator->exprSupp, &pInfo->aggSup, pExprInfo, num, keyBufSize, pTaskInfo->id.str,
183,309,037✔
108
                               pTaskInfo->streamInfo.pState, &pTaskInfo->storageAPI.functionStore);
91,677,800✔
109
  TSDB_CHECK_CODE(code, lino, _error);
91,631,788✔
110

111
  if (pAggNode->pExprs != NULL) {
91,631,788✔
112
    code = createExprInfo(pAggNode->pExprs, NULL, &pScalarExprInfo, &numOfScalarExpr);
19,222,480✔
113
    TSDB_CHECK_CODE(code, lino, _error);
19,217,514✔
114
  }
115

116
  code = initExprSupp(&pInfo->scalarExprSup, pScalarExprInfo, numOfScalarExpr, &pTaskInfo->storageAPI.functionStore);
91,610,146✔
117
  TSDB_CHECK_CODE(code, lino, _error);
91,597,391✔
118

119
  code = filterInitFromNode((SNode*)pAggNode->node.pConditions, &pOperator->exprSupp.pFilterInfo, 0,
91,572,167✔
120
                            GET_STM_RTINFO(pTaskInfo));
91,597,391✔
121
  TSDB_CHECK_CODE(code, lino, _error);
91,612,997✔
122

123
  pInfo->binfo.mergeResultBlock = pAggNode->mergeDataBlock;
91,612,997✔
124
  pInfo->groupKeyOptimized = pAggNode->groupKeyOptimized;
91,638,781✔
125
  pInfo->groupId = UINT64_MAX;
91,622,237✔
126
  pInfo->binfo.inputTsOrder = pAggNode->node.inputTsOrder;
91,581,750✔
127
  pInfo->binfo.outputTsOrder = pAggNode->node.outputTsOrder;
91,634,797✔
128
  pInfo->hasCountFunc = pAggNode->hasCountLikeFunc;
91,582,004✔
129
  pInfo->pOperator = pOperator;
91,658,437✔
130
  pInfo->cleanGroupResInfo = false;
91,623,043✔
131

132
  setOperatorInfo(pOperator, "TableAggregate", QUERY_NODE_PHYSICAL_PLAN_HASH_AGG,
91,577,584✔
133
                  !pAggNode->node.forceCreateNonBlockingOptr, OP_NOT_OPENED, pInfo, pTaskInfo);
91,589,319✔
134
  pOperator->fpSet = createOperatorFpSet(optrDummyOpenFn, getAggregateResultNext, NULL, destroyAggOperatorInfo,
91,644,255✔
135
                                         optrDefaultBufFn, NULL, optrDefaultGetNextExtFn, NULL);
136
  setOperatorResetStateFn(pOperator, resetAggregateOperatorState);
91,607,934✔
137

138
  pOperator->pPhyNode = pAggNode;
91,619,540✔
139

140
  if (downstream->operatorType == QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN) {
91,606,007✔
141
    STableScanInfo* pTableScanInfo = downstream->info;
53,959,890✔
142
    pTableScanInfo->base.pdInfo.pExprSup = &pOperator->exprSupp;
53,956,029✔
143
    pTableScanInfo->base.pdInfo.pAggSup = &pInfo->aggSup;
53,902,930✔
144
  }
145

146
  code = appendDownstream(pOperator, &downstream, 1);
91,615,868✔
147
  if (code != TSDB_CODE_SUCCESS) {
91,598,699✔
148
    goto _error;
×
149
  }
150

151
  *pOptrInfo = pOperator;
91,598,699✔
152
  return TSDB_CODE_SUCCESS;
91,601,322✔
153

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

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

171
  if (pInfo->pOperator) {
91,679,405✔
172
    cleanupResultInfo(pInfo->pOperator->pTaskInfo, &pInfo->pOperator->exprSupp, &pInfo->groupResInfo, &pInfo->aggSup,
91,659,803✔
173
                      pInfo->cleanGroupResInfo);
91,661,042✔
174
    pInfo->pOperator = NULL;
91,642,539✔
175
  }
176
  cleanupAggSup(&pInfo->aggSup);
91,664,621✔
177
  cleanupExprSuppWithoutFilter(&pInfo->scalarExprSup);
91,671,783✔
178
  cleanupGroupResInfo(&pInfo->groupResInfo);
91,652,342✔
179
  taosMemoryFreeClear(param);
91,659,750✔
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) {
110,846,651✔
190
  int32_t           code = TSDB_CODE_SUCCESS;
110,846,651✔
191
  int32_t           lino = 0;
110,846,651✔
192
  SExecTaskInfo*    pTaskInfo = pOperator->pTaskInfo;
110,846,651✔
193
  SAggOperatorInfo* pAggInfo = pOperator->info;
110,843,667✔
194

195
  if(!pAggInfo) {
110,824,114✔
196
    qError("function:%s, pAggInfo is NULL", __func__);
×
197
    return false;
×
198
  }
199
  if (pOperator->blocking && pAggInfo->hasValidBlock) {
110,824,114✔
200
    return false;
9,833,849✔
201
  }
202

203
  SExprSupp*   pSup = &pOperator->exprSupp;
100,999,316✔
204
  int64_t      st = taosGetTimestampUs();
101,012,602✔
205
  int32_t      order = pAggInfo->binfo.inputTsOrder;
101,012,602✔
206
  SSDataBlock* pBlock = pAggInfo->pNewGroupBlock;
101,007,245✔
207

208
  pAggInfo->cleanGroupResInfo = false;
101,011,150✔
209
  if (pBlock) {
101,008,136✔
210
    pAggInfo->pNewGroupBlock = NULL;
693,079✔
211
    tSimpleHashClear(pAggInfo->aggSup.pResultRowHashTable);
693,079✔
212
    code = setExecutionContext(pOperator, pOperator->exprSupp.numOfExprs, pBlock->info.id.groupId);
693,079✔
213
    QUERY_CHECK_CODE(code, lino, _end);
693,079✔
214
    code = setInputDataBlock(pSup, pBlock, order, pBlock->info.scanFlag, true);
693,079✔
215
    QUERY_CHECK_CODE(code, lino, _end);
693,079✔
216

217
    code = doAggregateImpl(pOperator, pSup->pCtx);
693,079✔
218
    QUERY_CHECK_CODE(code, lino, _end);
695,018✔
219
  }
220
  while (1) {
497,658,603✔
221
    bool blockAllocated = false;
598,668,678✔
222
    pBlock = getNextBlockFromDownstreamRemainDetach(pOperator, 0);
598,668,678✔
223
    if (pBlock == NULL) {
596,499,046✔
224
      if (!pAggInfo->hasValidBlock) {
101,476,269✔
225
        code = createDataBlockForEmptyInput(pOperator, &pBlock);
24,435,944✔
226
        QUERY_CHECK_CODE(code, lino, _end);
24,434,121✔
227

228
        if (pBlock == NULL) {
24,434,121✔
229
          break;
21,053,684✔
230
        }
231
        blockAllocated = true;
3,380,437✔
232
      } else {
233
        break;
77,041,518✔
234
      }
235
    }
236
    pAggInfo->hasValidBlock = true;
498,403,214✔
237
    pAggInfo->binfo.pRes->info.scanFlag = pBlock->info.scanFlag;
498,432,333✔
238

239
    printDataBlock(pBlock, __func__, pTaskInfo->id.str, pTaskInfo->id.queryId);
498,430,241✔
240

241
    // there is an scalar expression that needs to be calculated before apply the group aggregation.
242
    if (pAggInfo->scalarExprSup.pExprInfo != NULL && !blockAllocated) {
498,414,336✔
243
      SExprSupp* pSup1 = &pAggInfo->scalarExprSup;
78,498,027✔
244
      code = projectApplyFunctions(pSup1->pExprInfo, pBlock, pBlock, pSup1->pCtx, pSup1->numOfExprs, NULL, GET_STM_RTINFO(pOperator->pTaskInfo));
78,496,301✔
245
      if (code != TSDB_CODE_SUCCESS) {
78,460,526✔
246
        destroyDataBlockForEmptyInput(blockAllocated, &pBlock);
32,040✔
247
        T_LONG_JMP(pTaskInfo->env, code);
32,040✔
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) {
498,346,004✔
252
      pAggInfo->pNewGroupBlock = pBlock;
705,850✔
253
      break;
705,850✔
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);
497,652,591✔
257
    if (code != TSDB_CODE_SUCCESS) {
497,661,529✔
258
      destroyDataBlockForEmptyInput(blockAllocated, &pBlock);
×
259
      T_LONG_JMP(pTaskInfo->env, code);
×
260
    }
261
    code = setInputDataBlock(pSup, pBlock, order, pBlock->info.scanFlag, true);
497,661,529✔
262
    if (code != TSDB_CODE_SUCCESS) {
497,680,681✔
263
      destroyDataBlockForEmptyInput(blockAllocated, &pBlock);
×
264
      T_LONG_JMP(pTaskInfo->env, code);
×
265
    }
266

267
    code = doAggregateImpl(pOperator, pSup->pCtx);
497,680,681✔
268
    if (code != TSDB_CODE_SUCCESS) {
497,649,668✔
269
      destroyDataBlockForEmptyInput(blockAllocated, &pBlock);
2,940✔
270
      T_LONG_JMP(pTaskInfo->env, code);
2,940✔
271
    }
272

273
    destroyDataBlockForEmptyInput(blockAllocated, &pBlock);
497,646,728✔
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) {
98,801,052✔
278
    T_LONG_JMP(pTaskInfo->env, pTaskInfo->code);
×
279
  }
280

281
  code = initGroupedResultInfo(&pAggInfo->groupResInfo, pAggInfo->aggSup.pResultRowHashTable, 0);
98,795,013✔
282
  QUERY_CHECK_CODE(code, lino, _end);
98,793,453✔
283
  pAggInfo->cleanGroupResInfo = true;
98,793,453✔
284

285
_end:
98,789,903✔
286
  if (code != TSDB_CODE_SUCCESS) {
98,791,651✔
UNCOV
287
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
×
UNCOV
288
    pTaskInfo->code = code;
×
289
    T_LONG_JMP(pTaskInfo->env, code);
×
290
  }
291
  return pBlock != NULL;
98,793,183✔
292
}
293

294
int32_t getAggregateResultNext(SOperatorInfo* pOperator, SSDataBlock** ppRes) {
184,014,731✔
295
  int32_t           code = TSDB_CODE_SUCCESS;
184,014,731✔
296
  int32_t           lino = 0;
184,014,731✔
297
  SAggOperatorInfo* pAggInfo = pOperator->info;
184,014,731✔
298
  SOptrBasicInfo*   pInfo = &pAggInfo->binfo;
184,023,353✔
299

300
  if (pOperator->status == OP_EXEC_DONE && !pOperator->pOperatorGetParam) {
184,018,491✔
301
    (*ppRes) = NULL;
73,184,326✔
302
    return code;
73,183,390✔
303
  }
304

305
  if (pOperator->pOperatorGetParam) {
110,835,104✔
306
    if (pOperator->status == OP_EXEC_DONE) {
5,615,247✔
307
      pOperator->status = OP_OPENED;
3,750,322✔
308
      tSimpleHashClear(pAggInfo->aggSup.pResultRowHashTable);
3,753,157✔
309
      pAggInfo->groupId = UINT64_MAX;
3,753,157✔
310
      pAggInfo->hasValidBlock = false;
3,753,680✔
311
    }
312
    freeOperatorParam(pOperator->pOperatorGetParam, OP_GET_PARAM);
5,615,397✔
313
    pOperator->pOperatorGetParam = NULL;
5,615,177✔
314

315
  }
316

317
  SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
110,832,291✔
318
  bool           hasNewGroups = false;
110,836,334✔
319
  do {
320
    hasNewGroups = nextGroupedResult(pOperator);
110,847,548✔
321
    code = blockDataEnsureCapacity(pInfo->pRes, pOperator->resultInfo.capacity);
108,630,074✔
322
    QUERY_CHECK_CODE(code, lino, _end);
108,634,752✔
323

324
    while (1) {
325
      doBuildResultDatablock(pOperator, pInfo, &pAggInfo->groupResInfo, pAggInfo->aggSup.pResultBuf);
108,634,752✔
326
      code = doFilter(pInfo->pRes, pOperator->exprSupp.pFilterInfo, NULL, NULL);
108,633,195✔
327
      QUERY_CHECK_CODE(code, lino, _end);
108,630,407✔
328

329
      if (!hasRemainResults(&pAggInfo->groupResInfo)) {
108,630,407✔
330
        if (!hasNewGroups) setOperatorCompleted(pOperator);
98,792,824✔
331
        break;
98,791,781✔
332
      }
333

334
      if (pInfo->pRes->info.rows > 0) {
9,840,377✔
335
        break;
9,840,377✔
336
      }
337
    }
338
  } while (pInfo->pRes->info.rows == 0 && hasNewGroups);
108,632,158✔
339

340
  size_t rows = blockDataGetNumOfRows(pInfo->pRes);
108,623,144✔
341
  pOperator->resultInfo.totalRows += rows;
108,623,297✔
342

343
_end:
108,621,769✔
344
  if (code != TSDB_CODE_SUCCESS) {
108,621,769✔
345
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
×
346
    pTaskInfo->code = code;
×
347
    T_LONG_JMP(pTaskInfo->env, code);
×
348
  }
349

350
  printDataBlock(pInfo->pRes, __func__, pTaskInfo->id.str, pTaskInfo->id.queryId);
108,621,769✔
351

352
  (*ppRes) = (rows == 0) ? NULL : pInfo->pRes;
108,622,785✔
353
  return code;
108,621,604✔
354
}
355

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

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

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

386
  return TSDB_CODE_SUCCESS;
498,358,432✔
387
}
388

389
static int32_t createDataBlockForEmptyInput(SOperatorInfo* pOperator, SSDataBlock** ppBlock) {
24,436,756✔
390
  int32_t code = TSDB_CODE_SUCCESS;
24,436,756✔
391
  int32_t lino = 0;
24,436,756✔
392
  SSDataBlock* pBlock = NULL;
24,436,756✔
393
  if (!tsCountAlwaysReturnValue) {
24,437,238✔
394
    return TSDB_CODE_SUCCESS;
6,250,844✔
395
  }
396

397
  SAggOperatorInfo* pAggInfo = pOperator->info;
18,186,394✔
398
  if (pAggInfo->groupKeyOptimized) {
18,184,747✔
399
    return TSDB_CODE_SUCCESS;
5,489,056✔
400
  }
401

402
  SOperatorInfo* downstream = pOperator->pDownstream[0];
12,692,525✔
403
  if (downstream->operatorType == QUERY_NODE_PHYSICAL_PLAN_PARTITION ||
12,693,987✔
404
      downstream->operatorType == QUERY_NODE_PHYSICAL_PLAN_SORT ||
12,660,292✔
405
      (downstream->operatorType == QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN &&
12,635,098✔
406
       ((STableScanInfo*)downstream->info)->hasGroupByTag == true)) {
4,071,454✔
407
    return TSDB_CODE_SUCCESS;
60,535✔
408
  }
409

410
  SqlFunctionCtx* pCtx = pOperator->exprSupp.pCtx;
12,630,527✔
411

412
  if (!pAggInfo->hasCountFunc) {
12,635,098✔
413
    return TSDB_CODE_SUCCESS;
9,249,404✔
414
  }
415

416
  code = createDataBlock(&pBlock);
3,379,762✔
417
  if (code) {
3,380,955✔
418
    return code;
×
419
  }
420

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

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

430
    SExprInfo* pOneExpr = &pOperator->exprSupp.pExprInfo[i];
5,987,631✔
431
    for (int32_t j = 0; j < pOneExpr->base.numOfParams; ++j) {
12,193,840✔
432
      SFunctParam* pFuncParam = &pOneExpr->base.pParam[j];
6,205,663✔
433
      if (pFuncParam->type == FUNC_PARAM_TYPE_COLUMN) {
6,205,663✔
434
        int32_t slotId = pFuncParam->pCol->slotId;
6,203,349✔
435
        int32_t numOfCols = taosArrayGetSize(pBlock->pDataBlock);
6,203,349✔
436
        if (slotId >= numOfCols) {
6,201,594✔
437
          code = taosArrayEnsureCap(pBlock->pDataBlock, slotId + 1);
3,810,615✔
438
          QUERY_CHECK_CODE(code, lino, _end);
3,810,623✔
439

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

451
  code = blockDataEnsureCapacity(pBlock, pBlock->info.rows);
3,382,156✔
452
  QUERY_CHECK_CODE(code, lino, _end);
3,381,509✔
453

454
  for (int32_t i = 0; i < blockDataGetNumOfCols(pBlock); ++i) {
9,822,513✔
455
    SColumnInfoData* pColInfoData = taosArrayGet(pBlock->pDataBlock, i);
6,442,205✔
456
    QUERY_CHECK_NULL(pColInfoData, code, lino, _end, terrno);
6,442,205✔
457
    colDataSetNULL(pColInfoData, 0);
458
  }
459
  *ppBlock = pBlock;
3,379,014✔
460

461
_end:
3,378,367✔
462
  if (code != TSDB_CODE_SUCCESS) {
3,379,014✔
463
    blockDataDestroy(pBlock);
×
464
    qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(code));
×
465
  }
466
  return code;
3,381,610✔
467
}
468

469
void destroyDataBlockForEmptyInput(bool blockAllocated, SSDataBlock** ppBlock) {
497,678,754✔
470
  if (!blockAllocated) {
497,678,754✔
471
    return;
494,329,940✔
472
  }
473

474
  blockDataDestroy(*ppBlock);
3,348,814✔
475
  *ppBlock = NULL;
3,381,509✔
476
}
477

478
int32_t setExecutionContext(SOperatorInfo* pOperator, int32_t numOfOutput, uint64_t groupId) {
498,345,177✔
479
  int32_t           code = TSDB_CODE_SUCCESS;
498,345,177✔
480
  SAggOperatorInfo* pAggInfo = pOperator->info;
498,345,177✔
481
  if (pAggInfo->groupId != UINT64_MAX && pAggInfo->groupId == groupId) {
498,395,060✔
482
    return code;
323,062,451✔
483
  }
484

485
  code = doSetTableGroupOutputBuf(pOperator, numOfOutput, groupId);
175,340,648✔
486

487
  // record the current active group id
488
  pAggInfo->groupId = groupId;
175,309,786✔
489
  return code;
175,323,804✔
490
}
491

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

499
  SResultRowInfo* pResultRowInfo = &pAggInfo->binfo.resultRowInfo;
175,328,588✔
500
  SqlFunctionCtx* pCtx = pOperator->exprSupp.pCtx;
175,337,438✔
501
  int32_t*        rowEntryInfoOffset = pOperator->exprSupp.rowEntryInfoOffset;
175,323,487✔
502

503
  SResultRow* pResultRow =
504
      doSetResultOutBufByKey(pAggInfo->aggSup.pResultBuf, pResultRowInfo, (char*)&groupId, sizeof(groupId), true,
175,318,834✔
505
                             groupId, pTaskInfo, false, &pAggInfo->aggSup, true);
506
  if (pResultRow == NULL || pTaskInfo->code != 0) {
175,318,304✔
507
    code = pTaskInfo->code;
4,383✔
508
    lino = __LINE__;
×
509
    goto _end;
×
510
  }
511
  /*
512
   * not assign result buffer yet, add new result buffer
513
   * all group belong to one result set, and each group result has different group id so set the id to be one
514
   */
515
  if (pResultRow->pageId == -1) {
175,319,419✔
516
    code = addNewResultRowBuf(pResultRow, pAggInfo->aggSup.pResultBuf, pAggInfo->binfo.pRes->info.rowSize);
×
517
    QUERY_CHECK_CODE(code, lino, _end);
×
518
  }
519

520
  code = setResultRowInitCtx(pResultRow, pCtx, numOfOutput, rowEntryInfoOffset);
175,332,952✔
521
  QUERY_CHECK_CODE(code, lino, _end);
175,324,336✔
522

523
_end:
175,324,336✔
524
  if (code != TSDB_CODE_SUCCESS) {
175,324,336✔
525
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
×
526
  }
527
  return code;
175,323,112✔
528
}
529

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

536
  SFilePage* pData = NULL;
×
537

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

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

557
    pageId = getPageId(pi);
×
558

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

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

572
  if (pData == NULL) {
×
573
    return -1;
×
574
  }
575

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

581
    pData->num += size;
×
582
  }
583

584
  return 0;
×
585
}
586

587
int32_t doInitAggInfoSup(SAggSupporter* pAggSup, SqlFunctionCtx* pCtx, int32_t numOfOutput, size_t keyBufSize,
287,608,040✔
588
                         const char* pKey) {
589
  int32_t code = 0;
287,608,040✔
590
  //  _hash_fn_t hashFn = taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY);
591

592
  pAggSup->currentPageId = -1;
287,608,040✔
593
  pAggSup->resultRowSize = getResultRowSize(pCtx, numOfOutput);
287,623,447✔
594
  pAggSup->keyBuf = taosMemoryCalloc(1, keyBufSize + POINTER_BYTES + sizeof(int64_t));
287,535,615✔
595
  pAggSup->pResultRowHashTable = tSimpleHashInit(100, taosFastHash);
287,558,325✔
596

597
  if (pAggSup->keyBuf == NULL || pAggSup->pResultRowHashTable == NULL) {
287,538,389✔
598
    return terrno;
74,079✔
599
  }
600

601
  uint32_t defaultPgsz = 0;
287,481,390✔
602
  int64_t defaultBufsz = 0;
287,522,886✔
603
  code = getBufferPgSize(pAggSup->resultRowSize, &defaultPgsz, &defaultBufsz);
287,531,093✔
604
  if (code) {
287,474,336✔
605
    qError("failed to get buff page size, rowSize:%d", pAggSup->resultRowSize);
×
606
    return code;
×
607
  }
608

609
  if (!osTempSpaceAvailable()) {
287,474,336✔
610
    code = TSDB_CODE_NO_DISKSPACE;
×
611
    qError("Init stream agg supporter failed since %s, key:%s, tempDir:%s", tstrerror(code), pKey, tsTempDir);
×
612
    return code;
×
613
  }
614

615
  code = createDiskbasedBuf(&pAggSup->pResultBuf, defaultPgsz, defaultBufsz, pKey, tsTempDir);
287,604,603✔
616
  if (code != TSDB_CODE_SUCCESS) {
287,615,645✔
617
    qError("Create agg result buf failed since %s, %s", tstrerror(code), pKey);
×
618
    return code;
×
619
  }
620

621
  return code;
287,615,645✔
622
}
623

624
void cleanupResultInfoInGroupResInfo(SExecTaskInfo* pTaskInfo, SExprSupp* pSup, SDiskbasedBuf* pBuf,
100,149,920✔
625
                                  SGroupResInfo* pGroupResInfo) {
626
  int32_t         numOfExprs = pSup->numOfExprs;
100,149,920✔
627
  int32_t*        rowEntryOffset = pSup->rowEntryInfoOffset;
100,158,419✔
628
  SqlFunctionCtx* pCtx = pSup->pCtx;
100,150,949✔
629
  int32_t         numOfRows = getNumOfTotalRes(pGroupResInfo);
100,161,006✔
630
  bool            needCleanup = false;
100,137,330✔
631

632
  for (int32_t j = 0; j < numOfExprs; ++j) {
109,048,603✔
633
    needCleanup |= pCtx[j].needCleanup;
8,911,273✔
634
  }
635
  if (!needCleanup) {
100,137,330✔
636
    return;
100,145,223✔
637
  }
638

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

649

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

660
void cleanupResultInfoInHashMap(SExecTaskInfo* pTaskInfo, SExprSupp* pSup, SDiskbasedBuf* pBuf,
35,348,139✔
661
                       SGroupResInfo* pGroupResInfo, SSHashObj* pHashmap) {
662
  int32_t         numOfExprs = pSup->numOfExprs;
35,348,139✔
663
  int32_t*        rowEntryOffset = pSup->rowEntryInfoOffset;
35,349,215✔
664
  SqlFunctionCtx* pCtx = pSup->pCtx;
35,347,631✔
665
  bool            needCleanup = false;
35,345,727✔
666
  for (int32_t j = 0; j < numOfExprs; ++j) {
45,522,522✔
667
    needCleanup |= pCtx[j].needCleanup;
10,176,802✔
668
  }
669
  if (!needCleanup) {
35,345,720✔
670
    return;
35,344,747✔
671
  }
672

673
  // begin from last iter
674
  void*   pData = pGroupResInfo->dataPos;
973✔
675
  int32_t iter = pGroupResInfo->iter;
×
676
  while ((pData = tSimpleHashIterate(pHashmap, pData, &iter)) != NULL) {
×
677
    SResultRowPosition* pos = pData;
×
678

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

685
    SResultRow* pRow = (SResultRow*)((char*)page + pos->offset);
×
686

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

694
    releaseBufPage(pBuf, page);
×
695
  }
696
}
697

698
void cleanupResultInfo(SExecTaskInfo* pTaskInfo, SExprSupp* pSup, SGroupResInfo* pGroupResInfo,
135,496,337✔
699
                       SAggSupporter *pAggSup, bool cleanGroupResInfo) {
700
  if (cleanGroupResInfo) {
135,496,337✔
701
    cleanupResultInfoInGroupResInfo(pTaskInfo, pSup, pAggSup->pResultBuf, pGroupResInfo);
100,156,944✔
702
  } else {
703
    cleanupResultInfoInHashMap(pTaskInfo, pSup, pAggSup->pResultBuf, pGroupResInfo, pAggSup->pResultRowHashTable);
35,339,393✔
704
  }
705
}
135,498,203✔
706
void cleanupAggSup(SAggSupporter* pAggSup) {
288,006,065✔
707
  taosMemoryFreeClear(pAggSup->keyBuf);
288,006,065✔
708
  tSimpleHashCleanup(pAggSup->pResultRowHashTable);
287,989,928✔
709
  destroyDiskbasedBuf(pAggSup->pResultBuf);
287,995,714✔
710
  memset(pAggSup, 0, sizeof(SAggSupporter));
287,980,753✔
711
}
287,980,753✔
712

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

720
  code = doInitAggInfoSup(pAggSup, pSup->pCtx, numOfCols, keyBufSize, pkey);
287,552,113✔
721
  if (code != TSDB_CODE_SUCCESS) {
287,577,241✔
722
    return code;
×
723
  }
724

725
  for (int32_t i = 0; i < numOfCols; ++i) {
1,247,710,574✔
726
    pSup->pCtx[i].hasWindowOrGroup = pSup->hasWindowOrGroup;
960,196,014✔
727
    pSup->pCtx[i].hasWindow= pSup->hasWindow;
960,223,119✔
728
    if (pState) {
960,223,572✔
729
      pSup->pCtx[i].saveHandle.pBuf = NULL;
×
730
      pSup->pCtx[i].saveHandle.pState = pState;
×
731
      pSup->pCtx[i].exprIdx = i;
×
732
    } else {
733
      pSup->pCtx[i].saveHandle.pBuf = pAggSup->pResultBuf;
960,223,572✔
734
    }
735
  }
736

737
  return TSDB_CODE_SUCCESS;
287,514,560✔
738
}
739

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

748
    pCtx[k].input.startRowIndex = offset;
2,147,483,647✔
749
    pCtx[k].input.numOfRows = forwardStep;
2,147,483,647✔
750

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

757
    if (fmIsPlaceHolderFunc(pCtx[k].functionId)) {
2,147,483,647✔
758
      SResultRowEntryInfo* pEntryInfo = GET_RES_INFO(&pCtx[k]);
36,624,502✔
759
      char* p = GET_ROWCELL_INTERBUF(pEntryInfo);
36,624,502✔
760

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

763
      SValueNode *valueNode = (SValueNode *)nodesListGetNode(pCtx[k].pExpr->base.pParamList, 0);
36,623,608✔
764
      pEntryInfo->isNullRes = 0;
36,632,943✔
765
      if (TSDB_DATA_TYPE_NULL == valueNode->node.resType.type || valueNode->isNull) {
36,635,842✔
766
        pEntryInfo->isNullRes = 1;
2,459✔
767
      } else if (IS_VAR_DATA_TYPE(pCtx[k].pExpr->base.resSchema.type)){
36,634,723✔
768
        void* v = nodesGetValueFromNode(valueNode);
12,314✔
769
        memcpy(p, v, varDataTLen(v));
9,988✔
770
      } else {
771
        memcpy(p, nodesGetValueFromNode(valueNode), pCtx[k].pExpr->base.resSchema.bytes);
36,627,418✔
772
      }
773
      
774
      pEntryInfo->numOfRes = 1;
36,636,068✔
775
    } else if (pCtx[k].isPseudoFunc) {
2,147,483,647✔
776
      SResultRowEntryInfo* pEntryInfo = GET_RES_INFO(&pCtx[k]);
2,147,483,647✔
777

778
      char* p = GET_ROWCELL_INTERBUF(pEntryInfo);
2,147,483,647✔
779

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

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

799
        if (code != TSDB_CODE_SUCCESS) {
2,147,483,647✔
800
          if (pCtx[k].fpSet.cleanup != NULL) {
439✔
801
            pCtx[k].fpSet.cleanup(&pCtx[k]);
439✔
802
          }
803
          TAOS_CHECK_EXIT(code);
439✔
804
        }
805
      }
806

807
      // restore it
808
      functionCtxRestore(&pCtx[k], &status);
2,147,483,647✔
809
    }
810
  }
811

812
_exit:
2,147,483,647✔
813

814
  if (code) {
2,147,483,647✔
815
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
439✔
816
    taskInfo->code = code;
439✔
817
  }
818

819
  return code;
2,147,483,647✔
820
}
821

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

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

834
static int32_t resetAggregateOperatorState(SOperatorInfo* pOper) {
5,754,839✔
835
  SAggOperatorInfo* pAgg = pOper->info;
5,754,839✔
836
  SAggPhysiNode*   pAggNode = (SAggPhysiNode*)pOper->pPhyNode;
5,755,056✔
837
  
838
  pOper->status = OP_NOT_OPENED;
5,755,056✔
839
  size_t keyBufSize = sizeof(int64_t) + sizeof(int64_t) + POINTER_BYTES;
5,755,273✔
840
  SExecTaskInfo*  pTaskInfo = pOper->pTaskInfo;
5,755,273✔
841
  cleanupResultInfo(pTaskInfo, &pOper->exprSupp, &pAgg->groupResInfo, &pAgg->aggSup,
5,755,056✔
842
                      pAgg->cleanGroupResInfo);
5,755,056✔
843
  cleanupGroupResInfo(&pAgg->groupResInfo);
5,754,604✔
844
  resetBasicOperatorState(&pAgg->binfo);
5,754,361✔
845
  
846
  pAgg->pNewGroupBlock = NULL;
5,755,056✔
847

848
  int32_t code = resetAggSup(&pOper->exprSupp, &pAgg->aggSup, pTaskInfo, pAggNode->pAggFuncs, pAggNode->pGroupKeys,
11,509,344✔
849
    keyBufSize, pTaskInfo->id.str, pTaskInfo->streamInfo.pState, &pTaskInfo->storageAPI.functionStore);
5,755,056✔
850

851
  if (code == 0) {
5,754,622✔
852
    code = resetExprSupp(&pAgg->scalarExprSup, pTaskInfo, pAggNode->pExprs, NULL,
5,754,839✔
853
                          &pTaskInfo->storageAPI.functionStore);
854
  }
855

856
  pAgg->groupId = UINT64_MAX;
5,754,188✔
857
  pAgg->cleanGroupResInfo = false;
5,754,405✔
858
  pAgg->hasValidBlock = false;
5,755,056✔
859
  return 0;
5,755,273✔
860
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc