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

taosdata / TDengine / #4976

06 Mar 2026 09:48AM UTC coverage: 68.446% (+0.08%) from 68.37%
#4976

push

travis-ci

web-flow
feat(TDgpt): support multiple input data columns for anomaly detection. (#34606)

0 of 93 new or added lines in 9 files covered. (0.0%)

5718 existing lines in 144 files now uncovered.

211146 of 308486 relevant lines covered (68.45%)

136170362.0 hits per line

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

79.76
/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,293,277✔
77
                                    SOperatorInfo** pOptrInfo) {
78
  QRY_PARAM_CHECK(pOptrInfo);
91,293,277✔
79

80
  int32_t    lino = 0;
91,314,264✔
81
  int32_t    code = 0;
91,314,264✔
82
  int32_t    num = 0;
91,314,264✔
83
  SExprInfo* pExprInfo = NULL;
91,315,545✔
84
  int32_t    numOfScalarExpr = 0;
91,300,012✔
85
  SExprInfo* pScalarExprInfo = NULL;
91,291,245✔
86

87
  SAggOperatorInfo* pInfo = taosMemoryCalloc(1, sizeof(SAggOperatorInfo));
91,287,546✔
88
  SOperatorInfo*    pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo));
91,207,537✔
89
  if (pInfo == NULL || pOperator == NULL) {
91,188,954✔
90
    code = terrno;
277✔
91
    goto _error;
×
92
  }
93

94
  pOperator->exprSupp.hasWindowOrGroup = false;
91,188,793✔
95

96
  SSDataBlock* pResBlock = createDataBlockFromDescNode(pAggNode->node.pOutputDataBlockDesc);
91,191,887✔
97
  QUERY_CHECK_NULL(pResBlock, code, lino, _error, terrno);
91,336,337✔
98
  initBasicInfo(&pInfo->binfo, pResBlock);
91,336,337✔
99

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

103

104
  code = createExprInfo(pAggNode->pAggFuncs, pAggNode->pGroupKeys, &pExprInfo, &num);
91,315,258✔
105
  TSDB_CHECK_CODE(code, lino, _error);
91,300,872✔
106

107
  code = initAggSup(&pOperator->exprSupp, &pInfo->aggSup, pExprInfo, num, keyBufSize, pTaskInfo->id.str,
182,609,604✔
108
                               pTaskInfo->streamInfo.pState, &pTaskInfo->storageAPI.functionStore);
91,317,387✔
109
  TSDB_CHECK_CODE(code, lino, _error);
91,274,103✔
110

111
  if (pAggNode->pExprs != NULL) {
91,274,103✔
112
    code = createExprInfo(pAggNode->pExprs, NULL, &pScalarExprInfo, &numOfScalarExpr);
16,654,166✔
113
    TSDB_CHECK_CODE(code, lino, _error);
16,653,177✔
114
  }
115

116
  code = initExprSupp(&pInfo->scalarExprSup, pScalarExprInfo, numOfScalarExpr, &pTaskInfo->storageAPI.functionStore);
91,267,517✔
117
  TSDB_CHECK_CODE(code, lino, _error);
91,234,352✔
118

119
  code = filterInitFromNode((SNode*)pAggNode->node.pConditions, &pOperator->exprSupp.pFilterInfo, 0,
91,253,798✔
120
                            GET_STM_RTINFO(pTaskInfo));
91,234,352✔
121
  TSDB_CHECK_CODE(code, lino, _error);
91,235,527✔
122

123
  pInfo->binfo.mergeResultBlock = pAggNode->mergeDataBlock;
91,235,527✔
124
  pInfo->groupKeyOptimized = pAggNode->groupKeyOptimized;
91,260,105✔
125
  pInfo->groupId = UINT64_MAX;
91,233,016✔
126
  pInfo->binfo.inputTsOrder = pAggNode->node.inputTsOrder;
91,228,206✔
127
  pInfo->binfo.outputTsOrder = pAggNode->node.outputTsOrder;
91,283,167✔
128
  pInfo->hasCountFunc = pAggNode->hasCountLikeFunc;
91,217,035✔
129
  pInfo->pOperator = pOperator;
91,288,306✔
130
  pInfo->cleanGroupResInfo = false;
91,267,530✔
131

132
  setOperatorInfo(pOperator, "TableAggregate", QUERY_NODE_PHYSICAL_PLAN_HASH_AGG,
91,203,532✔
133
                  !pAggNode->node.forceCreateNonBlockingOptr, OP_NOT_OPENED, pInfo, pTaskInfo);
91,235,512✔
134
  pOperator->fpSet = createOperatorFpSet(optrDummyOpenFn, getAggregateResultNext, NULL, destroyAggOperatorInfo,
91,267,055✔
135
                                         optrDefaultBufFn, NULL, optrDefaultGetNextExtFn, NULL);
136
  setOperatorResetStateFn(pOperator, resetAggregateOperatorState);
91,237,204✔
137

138
  pOperator->pPhyNode = pAggNode;
91,248,088✔
139

140
  if (downstream->operatorType == QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN) {
91,233,845✔
141
    STableScanInfo* pTableScanInfo = downstream->info;
53,946,036✔
142
    pTableScanInfo->base.pdInfo.pExprSup = &pOperator->exprSupp;
53,940,778✔
143
    pTableScanInfo->base.pdInfo.pAggSup = &pInfo->aggSup;
53,873,205✔
144
  }
145

146
  code = appendDownstream(pOperator, &downstream, 1);
91,233,132✔
147
  if (code != TSDB_CODE_SUCCESS) {
91,222,236✔
148
    goto _error;
×
149
  }
150

151
  *pOptrInfo = pOperator;
91,222,236✔
152
  return TSDB_CODE_SUCCESS;
91,229,271✔
153

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

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

171
  if (pInfo->pOperator) {
91,325,553✔
172
    cleanupResultInfo(pInfo->pOperator->pTaskInfo, &pInfo->pOperator->exprSupp, &pInfo->groupResInfo, &pInfo->aggSup,
91,310,721✔
173
                      pInfo->cleanGroupResInfo);
91,313,488✔
174
    pInfo->pOperator = NULL;
91,287,353✔
175
  }
176
  cleanupAggSup(&pInfo->aggSup);
91,306,368✔
177
  cleanupExprSuppWithoutFilter(&pInfo->scalarExprSup);
91,303,266✔
178
  cleanupGroupResInfo(&pInfo->groupResInfo);
91,332,037✔
179
  taosMemoryFreeClear(param);
91,299,528✔
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,528,474✔
190
  int32_t           code = TSDB_CODE_SUCCESS;
110,528,474✔
191
  int32_t           lino = 0;
110,528,474✔
192
  SExecTaskInfo*    pTaskInfo = pOperator->pTaskInfo;
110,528,474✔
193
  SAggOperatorInfo* pAggInfo = pOperator->info;
110,526,712✔
194

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

203
  SExprSupp*   pSup = &pOperator->exprSupp;
100,736,373✔
204
  int64_t      st = taosGetTimestampUs();
100,739,914✔
205
  int32_t      order = pAggInfo->binfo.inputTsOrder;
100,739,914✔
206
  SSDataBlock* pBlock = pAggInfo->pNewGroupBlock;
100,743,335✔
207

208
  pAggInfo->cleanGroupResInfo = false;
100,738,042✔
209
  if (pBlock) {
100,720,318✔
210
    pAggInfo->pNewGroupBlock = NULL;
684,373✔
211
    tSimpleHashClear(pAggInfo->aggSup.pResultRowHashTable);
684,373✔
212
    code = setExecutionContext(pOperator, pOperator->exprSupp.numOfExprs, pBlock->info.id.groupId);
684,373✔
213
    QUERY_CHECK_CODE(code, lino, _end);
684,373✔
214
    code = setInputDataBlock(pSup, pBlock, order, pBlock->info.scanFlag, true);
684,373✔
215
    QUERY_CHECK_CODE(code, lino, _end);
684,373✔
216

217
    code = doAggregateImpl(pOperator, pSup->pCtx);
684,373✔
218
    QUERY_CHECK_CODE(code, lino, _end);
705,828✔
219
  }
220
  while (1) {
627,448,693✔
221
    bool blockAllocated = false;
728,190,466✔
222
    pBlock = getNextBlockFromDownstreamRemain(pOperator, 0);
728,190,466✔
223
    if (pOperator->pDownstreamGetParams) {
726,726,483✔
224
      pOperator->pDownstreamGetParams[0] = NULL;
85,123,329✔
225
    }
226
    if (pBlock == NULL) {
726,803,438✔
227
      if (!pAggInfo->hasValidBlock) {
101,983,209✔
228
        code = createDataBlockForEmptyInput(pOperator, &pBlock);
24,099,402✔
229
        QUERY_CHECK_CODE(code, lino, _end);
24,095,368✔
230

231
        if (pBlock == NULL) {
24,095,368✔
232
          break;
20,645,275✔
233
        }
234
        blockAllocated = true;
3,450,093✔
235
      } else {
236
        break;
77,884,765✔
237
      }
238
    }
239
    pAggInfo->hasValidBlock = true;
628,270,322✔
240
    pAggInfo->binfo.pRes->info.scanFlag = pBlock->info.scanFlag;
628,271,069✔
241

242
    printDataBlock(pBlock, __func__, pTaskInfo->id.str, pTaskInfo->id.queryId);
628,274,645✔
243

244
    // there is an scalar expression that needs to be calculated before apply the group aggregation.
245
    if (pAggInfo->scalarExprSup.pExprInfo != NULL && !blockAllocated) {
628,213,965✔
246
      SExprSupp* pSup1 = &pAggInfo->scalarExprSup;
78,106,623✔
247
      code = projectApplyFunctions(pSup1->pExprInfo, pBlock, pBlock, pSup1->pCtx, pSup1->numOfExprs, NULL, GET_STM_RTINFO(pOperator->pTaskInfo));
78,108,774✔
248
      if (code != TSDB_CODE_SUCCESS) {
78,064,836✔
249
        destroyDataBlockForEmptyInput(blockAllocated, &pBlock);
32,513✔
250
        T_LONG_JMP(pTaskInfo->env, code);
32,513✔
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) {
628,136,087✔
255
      pAggInfo->pNewGroupBlock = pBlock;
697,170✔
256
      break;
697,170✔
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);
627,430,615✔
260
    if (code != TSDB_CODE_SUCCESS) {
627,441,077✔
261
      destroyDataBlockForEmptyInput(blockAllocated, &pBlock);
×
262
      T_LONG_JMP(pTaskInfo->env, code);
×
263
    }
264
    code = setInputDataBlock(pSup, pBlock, order, pBlock->info.scanFlag, true);
627,441,077✔
265
    if (code != TSDB_CODE_SUCCESS) {
627,501,892✔
266
      destroyDataBlockForEmptyInput(blockAllocated, &pBlock);
×
267
      T_LONG_JMP(pTaskInfo->env, code);
×
268
    }
269

270
    code = doAggregateImpl(pOperator, pSup->pCtx);
627,501,892✔
271
    if (code != TSDB_CODE_SUCCESS) {
627,434,390✔
272
      destroyDataBlockForEmptyInput(blockAllocated, &pBlock);
2,864✔
273
      T_LONG_JMP(pTaskInfo->env, code);
2,864✔
274
    }
275

276
    destroyDataBlockForEmptyInput(blockAllocated, &pBlock);
627,431,526✔
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) {
99,227,210✔
281
    T_LONG_JMP(pTaskInfo->env, pTaskInfo->code);
×
282
  }
283

284
  code = initGroupedResultInfo(&pAggInfo->groupResInfo, pAggInfo->aggSup.pResultRowHashTable, 0);
99,216,801✔
285
  QUERY_CHECK_CODE(code, lino, _end);
99,223,705✔
286
  pAggInfo->cleanGroupResInfo = true;
99,223,705✔
287

288
_end:
99,224,558✔
289
  if (code != TSDB_CODE_SUCCESS) {
99,224,637✔
290
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
67✔
291
    pTaskInfo->code = code;
67✔
292
    T_LONG_JMP(pTaskInfo->env, code);
×
293
  }
294
  return pBlock != NULL;
99,225,180✔
295
}
296

297
int32_t getAggregateResultNext(SOperatorInfo* pOperator, SSDataBlock** ppRes) {
184,225,192✔
298
  int32_t           code = TSDB_CODE_SUCCESS;
184,225,192✔
299
  int32_t           lino = 0;
184,225,192✔
300
  SAggOperatorInfo* pAggInfo = pOperator->info;
184,225,192✔
301
  SOptrBasicInfo*   pInfo = &pAggInfo->binfo;
184,237,972✔
302

303
  if (pOperator->status == OP_EXEC_DONE && !pOperator->pOperatorGetParam) {
184,228,608✔
304
    (*ppRes) = NULL;
73,707,655✔
305
    return code;
73,707,676✔
306
  }
307

308
  if (pOperator->pOperatorGetParam) {
110,526,025✔
309
    if (pOperator->status == OP_EXEC_DONE) {
8,415,304✔
310
      pOperator->status = OP_OPENED;
5,326,046✔
311
      tSimpleHashClear(pAggInfo->aggSup.pResultRowHashTable);
5,326,220✔
312
      pAggInfo->groupId = UINT64_MAX;
5,327,325✔
313
      pAggInfo->hasValidBlock = false;
5,327,843✔
314
    }
315
    freeOperatorParam(pOperator->pOperatorGetParam, OP_GET_PARAM);
8,415,199✔
316
    pOperator->pOperatorGetParam = NULL;
8,410,907✔
317

318
  }
319

320
  SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
110,510,772✔
321
  bool           hasNewGroups = false;
110,524,811✔
322
  do {
323
    hasNewGroups = nextGroupedResult(pOperator);
110,535,955✔
324
    code = blockDataEnsureCapacity(pInfo->pRes, pOperator->resultInfo.capacity);
109,012,984✔
325
    QUERY_CHECK_CODE(code, lino, _end);
109,022,471✔
326

327
    while (1) {
328
      doBuildResultDatablock(pOperator, pInfo, &pAggInfo->groupResInfo, pAggInfo->aggSup.pResultBuf);
109,022,471✔
329
      code = doFilter(pInfo->pRes, pOperator->exprSupp.pFilterInfo, NULL, NULL);
109,022,786✔
330
      QUERY_CHECK_CODE(code, lino, _end);
109,021,603✔
331

332
      if (!hasRemainResults(&pAggInfo->groupResInfo)) {
109,021,603✔
333
        if (!hasNewGroups) setOperatorCompleted(pOperator);
99,225,350✔
334
        break;
99,226,862✔
335
      }
336

337
      if (pInfo->pRes->info.rows > 0) {
9,797,142✔
338
        break;
9,797,142✔
339
      }
340
    }
341
  } while (pInfo->pRes->info.rows == 0 && hasNewGroups);
109,024,004✔
342

343
  size_t rows = blockDataGetNumOfRows(pInfo->pRes);
109,011,732✔
344
  pOperator->resultInfo.totalRows += rows;
109,011,026✔
345

346
_end:
109,006,186✔
347
  if (code != TSDB_CODE_SUCCESS) {
109,006,186✔
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);
109,006,186✔
354

355
  (*ppRes) = (rows == 0) ? NULL : pInfo->pRes;
109,003,706✔
356
  return code;
109,007,965✔
357
}
358

359
int32_t doAggregateImpl(SOperatorInfo* pOperator, SqlFunctionCtx* pCtx) {
628,150,941✔
360
  int32_t code = TSDB_CODE_SUCCESS;
628,150,941✔
361
  if (!pOperator || (pOperator->exprSupp.numOfExprs > 0 && pCtx == NULL)) {
628,150,941✔
362
    qError("%s failed at line %d since pCtx is NULL.", __func__, __LINE__);
532✔
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;
12,571,487✔
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,864✔
381
          pCtx[k].fpSet.cleanup(&pCtx[k]);
×
382
        }
383
        qError("%s aggregate function error happens, code:%s", GET_TASKID(pOperator->pTaskInfo), tstrerror(code));
2,864✔
384
        return code;
2,864✔
385
      }
386
    }
387
  }
388

389
  return TSDB_CODE_SUCCESS;
628,183,249✔
390
}
391

392
static int32_t createDataBlockForEmptyInput(SOperatorInfo* pOperator, SSDataBlock** ppBlock) {
24,100,020✔
393
  int32_t code = TSDB_CODE_SUCCESS;
24,100,020✔
394
  int32_t lino = 0;
24,100,020✔
395
  SSDataBlock* pBlock = NULL;
24,100,020✔
396
  if (!tsCountAlwaysReturnValue) {
24,095,416✔
397
    return TSDB_CODE_SUCCESS;
6,251,498✔
398
  }
399

400
  SAggOperatorInfo* pAggInfo = pOperator->info;
17,843,918✔
401
  if (pAggInfo->groupKeyOptimized) {
17,843,268✔
402
    return TSDB_CODE_SUCCESS;
5,021,513✔
403
  }
404

405
  SOperatorInfo* downstream = pOperator->pDownstream[0];
12,822,646✔
406
  if (downstream->operatorType == QUERY_NODE_PHYSICAL_PLAN_PARTITION ||
12,819,502✔
407
      downstream->operatorType == QUERY_NODE_PHYSICAL_PLAN_SORT ||
12,786,539✔
408
      (downstream->operatorType == QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN &&
12,772,753✔
409
       ((STableScanInfo*)downstream->info)->hasGroupByTag == true)) {
4,536,159✔
410
    return TSDB_CODE_SUCCESS;
49,285✔
411
  }
412

413
  SqlFunctionCtx* pCtx = pOperator->exprSupp.pCtx;
12,765,575✔
414

415
  if (!pAggInfo->hasCountFunc) {
12,767,583✔
416
    return TSDB_CODE_SUCCESS;
9,323,519✔
417
  }
418

419
  code = createDataBlock(&pBlock);
3,451,804✔
420
  if (code) {
3,450,006✔
421
    return code;
×
422
  }
423

424
  pBlock->info.rows = 1;
3,450,006✔
425
  pBlock->info.capacity = 0;
3,450,006✔
426

427
  for (int32_t i = 0; i < pOperator->exprSupp.numOfExprs; ++i) {
9,470,164✔
428
    SColumnInfoData colInfo = {0};
6,020,238✔
429
    colInfo.hasNull = true;
6,019,600✔
430
    colInfo.info.type = TSDB_DATA_TYPE_NULL;
6,019,600✔
431
    colInfo.info.bytes = 1;
6,019,600✔
432

433
    SExprInfo* pOneExpr = &pOperator->exprSupp.pExprInfo[i];
6,019,600✔
434
    for (int32_t j = 0; j < pOneExpr->base.numOfParams; ++j) {
12,254,434✔
435
      SFunctParam* pFuncParam = &pOneExpr->base.pParam[j];
6,236,668✔
436
      if (pFuncParam->type == FUNC_PARAM_TYPE_COLUMN) {
6,236,665✔
437
        int32_t slotId = pFuncParam->pCol->slotId;
6,234,181✔
438
        int32_t numOfCols = taosArrayGetSize(pBlock->pDataBlock);
6,233,496✔
439
        if (slotId >= numOfCols) {
6,232,430✔
440
          code = taosArrayEnsureCap(pBlock->pDataBlock, slotId + 1);
3,854,403✔
441
          QUERY_CHECK_CODE(code, lino, _end);
3,852,486✔
442

443
          for (int32_t k = numOfCols; k < slotId + 1; ++k) {
10,461,320✔
444
            void* tmp = taosArrayPush(pBlock->pDataBlock, &colInfo);
6,607,602✔
445
            QUERY_CHECK_NULL(tmp, code, lino, _end, terrno);
6,608,834✔
446
          }
447
        }
448
      } else if (pFuncParam->type == FUNC_PARAM_TYPE_VALUE) {
2,487✔
449
        // do nothing
450
      }
451
    }
452
  }
453

454
  code = blockDataEnsureCapacity(pBlock, pBlock->info.rows);
3,451,166✔
455
  QUERY_CHECK_CODE(code, lino, _end);
3,449,973✔
456

457
  for (int32_t i = 0; i < blockDataGetNumOfCols(pBlock); ++i) {
10,059,406✔
458
    SColumnInfoData* pColInfoData = taosArrayGet(pBlock->pDataBlock, i);
6,610,709✔
459
    QUERY_CHECK_NULL(pColInfoData, code, lino, _end, terrno);
6,608,276✔
460
    colDataSetNULL(pColInfoData, 0);
461
  }
462
  *ppBlock = pBlock;
3,450,528✔
463

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

472
void destroyDataBlockForEmptyInput(bool blockAllocated, SSDataBlock** ppBlock) {
627,458,576✔
473
  if (!blockAllocated) {
627,458,576✔
474
    return;
624,056,404✔
475
  }
476

477
  blockDataDestroy(*ppBlock);
3,402,172✔
478
  *ppBlock = NULL;
3,451,166✔
479
}
480

481
int32_t setExecutionContext(SOperatorInfo* pOperator, int32_t numOfOutput, uint64_t groupId) {
628,119,097✔
482
  int32_t           code = TSDB_CODE_SUCCESS;
628,119,097✔
483
  SAggOperatorInfo* pAggInfo = pOperator->info;
628,119,097✔
484
  if (pAggInfo->groupId != UINT64_MAX && pAggInfo->groupId == groupId) {
628,220,700✔
485
    return code;
437,181,150✔
486
  }
487

488
  code = doSetTableGroupOutputBuf(pOperator, numOfOutput, groupId);
191,005,563✔
489

490
  // record the current active group id
491
  pAggInfo->groupId = groupId;
190,979,334✔
492
  return code;
191,014,368✔
493
}
494

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

502
  SResultRowInfo* pResultRowInfo = &pAggInfo->binfo.resultRowInfo;
191,026,476✔
503
  SqlFunctionCtx* pCtx = pOperator->exprSupp.pCtx;
191,045,509✔
504
  int32_t*        rowEntryInfoOffset = pOperator->exprSupp.rowEntryInfoOffset;
191,031,046✔
505

506
  SResultRow* pResultRow =
507
      doSetResultOutBufByKey(pAggInfo->aggSup.pResultBuf, pResultRowInfo, (char*)&groupId, sizeof(groupId), true,
191,042,081✔
508
                             groupId, pTaskInfo, false, &pAggInfo->aggSup, true);
509
  if (pResultRow == NULL || pTaskInfo->code != 0) {
191,024,723✔
510
    code = pTaskInfo->code;
16,279✔
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) {
191,020,987✔
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);
191,025,263✔
524
  QUERY_CHECK_CODE(code, lino, _end);
190,996,926✔
525

526
_end:
190,996,926✔
527
  if (code != TSDB_CODE_SUCCESS) {
190,996,926✔
528
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
×
529
  }
530
  return code;
190,990,424✔
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,
286,100,199✔
591
                         const char* pKey) {
592
  int32_t code = 0;
286,100,199✔
593
  //  _hash_fn_t hashFn = taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY);
594

595
  pAggSup->currentPageId = -1;
286,100,199✔
596
  pAggSup->resultRowSize = getResultRowSize(pCtx, numOfOutput);
286,124,620✔
597
  pAggSup->keyBuf = taosMemoryCalloc(1, keyBufSize + POINTER_BYTES + sizeof(int64_t));
286,092,049✔
598
  pAggSup->pResultRowHashTable = tSimpleHashInit(100, taosFastHash);
286,042,169✔
599

600
  if (pAggSup->keyBuf == NULL || pAggSup->pResultRowHashTable == NULL) {
286,025,623✔
601
    return terrno;
88,179✔
602
  }
603

604
  uint32_t defaultPgsz = 0;
286,018,561✔
605
  int64_t defaultBufsz = 0;
286,069,605✔
606
  code = getBufferPgSize(pAggSup->resultRowSize, &defaultPgsz, &defaultBufsz);
286,103,736✔
607
  if (code) {
285,963,572✔
608
    qError("failed to get buff page size, rowSize:%d", pAggSup->resultRowSize);
×
609
    return code;
×
610
  }
611

612
  if (!osTempSpaceAvailable()) {
285,963,572✔
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);
286,107,312✔
619
  if (code != TSDB_CODE_SUCCESS) {
286,097,444✔
620
    qError("Create agg result buf failed since %s, %s", tstrerror(code), pKey);
×
621
    return code;
×
622
  }
623

624
  return code;
286,097,444✔
625
}
626

627
void cleanupResultInfoInGroupResInfo(SExecTaskInfo* pTaskInfo, SExprSupp* pSup, SDiskbasedBuf* pBuf,
99,283,223✔
628
                                  SGroupResInfo* pGroupResInfo) {
629
  int32_t         numOfExprs = pSup->numOfExprs;
99,283,223✔
630
  int32_t*        rowEntryOffset = pSup->rowEntryInfoOffset;
99,295,370✔
631
  SqlFunctionCtx* pCtx = pSup->pCtx;
99,285,563✔
632
  int32_t         numOfRows = getNumOfTotalRes(pGroupResInfo);
99,285,592✔
633
  bool            needCleanup = false;
99,281,706✔
634

635
  for (int32_t j = 0; j < numOfExprs; ++j) {
107,614,531✔
636
    needCleanup |= pCtx[j].needCleanup;
8,332,154✔
637
  }
638
  if (!needCleanup) {
99,282,377✔
639
    return;
99,290,182✔
640
  }
641

642
  for (int32_t i = pGroupResInfo->index; i < numOfRows; i += 1) {
×
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,
34,519,212✔
664
                       SGroupResInfo* pGroupResInfo, SSHashObj* pHashmap) {
665
  int32_t         numOfExprs = pSup->numOfExprs;
34,519,212✔
666
  int32_t*        rowEntryOffset = pSup->rowEntryInfoOffset;
34,519,746✔
667
  SqlFunctionCtx* pCtx = pSup->pCtx;
34,519,525✔
668
  bool            needCleanup = false;
34,517,616✔
669
  for (int32_t j = 0; j < numOfExprs; ++j) {
41,829,427✔
670
    needCleanup |= pCtx[j].needCleanup;
7,310,714✔
671
  }
672
  if (!needCleanup) {
34,518,713✔
673
    return;
34,519,246✔
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,
133,802,287✔
702
                       SAggSupporter *pAggSup, bool cleanGroupResInfo) {
703
  if (cleanGroupResInfo) {
133,802,287✔
704
    cleanupResultInfoInGroupResInfo(pTaskInfo, pSup, pAggSup->pResultBuf, pGroupResInfo);
99,283,031✔
705
  } else {
706
    cleanupResultInfoInHashMap(pTaskInfo, pSup, pAggSup->pResultBuf, pGroupResInfo, pAggSup->pResultRowHashTable);
34,519,256✔
707
  }
708
}
133,785,793✔
709
void cleanupAggSup(SAggSupporter* pAggSup) {
286,523,856✔
710
  taosMemoryFreeClear(pAggSup->keyBuf);
286,523,856✔
711
  tSimpleHashCleanup(pAggSup->pResultRowHashTable);
286,549,569✔
712
  destroyDiskbasedBuf(pAggSup->pResultBuf);
286,524,781✔
713
  memset(pAggSup, 0, sizeof(SAggSupporter));
286,480,888✔
714
}
286,480,888✔
715

716
int32_t initAggSup(SExprSupp* pSup, SAggSupporter* pAggSup, SExprInfo* pExprInfo, int32_t numOfCols, size_t keyBufSize,
286,117,337✔
717
                   const char* pkey, void* pState, SFunctionStateStore* pStore) {
718
  int32_t code = initExprSupp(pSup, pExprInfo, numOfCols, pStore);
286,117,337✔
719
  if (code != TSDB_CODE_SUCCESS) {
286,090,371✔
720
    return code;
×
721
  }
722

723
  code = doInitAggInfoSup(pAggSup, pSup->pCtx, numOfCols, keyBufSize, pkey);
286,090,371✔
724
  if (code != TSDB_CODE_SUCCESS) {
286,085,075✔
725
    return code;
×
726
  }
727

728
  for (int32_t i = 0; i < numOfCols; ++i) {
1,222,218,115✔
729
    pSup->pCtx[i].hasWindowOrGroup = pSup->hasWindowOrGroup;
936,237,237✔
730
    pSup->pCtx[i].hasWindow= pSup->hasWindow;
936,167,723✔
731
    if (pState) {
936,039,907✔
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;
936,039,907✔
737
    }
738
  }
739

740
  return TSDB_CODE_SUCCESS;
285,980,878✔
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,523,603✔
762
      char* p = GET_ROWCELL_INTERBUF(pEntryInfo);
35,524,040✔
763

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

766
      SValueNode *valueNode = (SValueNode *)nodesListGetNode(pCtx[k].pExpr->base.pParamList, 0);
35,540,400✔
767
      pEntryInfo->isNullRes = 0;
35,540,717✔
768
      if (TSDB_DATA_TYPE_NULL == valueNode->node.resType.type || valueNode->isNull) {
35,540,717✔
UNCOV
769
        pEntryInfo->isNullRes = 1;
×
770
      } else if (IS_VAR_DATA_TYPE(pCtx[k].pExpr->base.resSchema.type)){
35,540,717✔
771
        void* v = nodesGetValueFromNode(valueNode);
11,482✔
772
        memcpy(p, v, varDataTLen(v));
10,076✔
773
      } else {
774
        memcpy(p, nodesGetValueFromNode(valueNode), pCtx[k].pExpr->base.resSchema.bytes);
35,529,550✔
775
      }
776
      
777
      pEntryInfo->numOfRes = 1;
35,539,845✔
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) {
442✔
804
            pCtx[k].fpSet.cleanup(&pCtx[k]);
442✔
805
          }
806
          TAOS_CHECK_EXIT(code);
442✔
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));
442✔
819
    taskInfo->code = code;
442✔
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) {
4,810,708✔
838
  SAggOperatorInfo* pAgg = pOper->info;
4,810,708✔
839
  SAggPhysiNode*   pAggNode = (SAggPhysiNode*)pOper->pPhyNode;
4,810,708✔
840
  
841
  pOper->status = OP_NOT_OPENED;
4,810,488✔
842
  size_t keyBufSize = sizeof(int64_t) + sizeof(int64_t) + POINTER_BYTES;
4,809,752✔
843
  SExecTaskInfo*  pTaskInfo = pOper->pTaskInfo;
4,809,752✔
844
  cleanupResultInfo(pTaskInfo, &pOper->exprSupp, &pAgg->groupResInfo, &pAgg->aggSup,
4,809,749✔
845
                      pAgg->cleanGroupResInfo);
4,809,752✔
846
  cleanupGroupResInfo(&pAgg->groupResInfo);
4,810,265✔
847
  resetBasicOperatorState(&pAgg->binfo);
4,810,268✔
848
  
849
  pAgg->pNewGroupBlock = NULL;
4,811,444✔
850

851
  int32_t code = resetAggSup(&pOper->exprSupp, &pAgg->aggSup, pTaskInfo, pAggNode->pAggFuncs, pAggNode->pGroupKeys,
9,621,996✔
852
    keyBufSize, pTaskInfo->id.str, pTaskInfo->streamInfo.pState, &pTaskInfo->storageAPI.functionStore);
4,811,444✔
853

854
  if (code == 0) {
4,811,004✔
855
    code = resetExprSupp(&pAgg->scalarExprSup, pTaskInfo, pAggNode->pExprs, NULL,
4,810,583✔
856
                          &pTaskInfo->storageAPI.functionStore);
857
  }
858

859
  pAgg->groupId = UINT64_MAX;
4,811,224✔
860
  pAgg->cleanGroupResInfo = false;
4,810,803✔
861
  pAgg->hasValidBlock = false;
4,811,026✔
862
  return 0;
4,810,806✔
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