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

taosdata / TDengine / #4869

26 Nov 2025 05:46AM UTC coverage: 64.539% (-0.09%) from 64.629%
#4869

push

travis-ci

guanshengliang
Merge branch '3.0' into cover/3.0

771 of 945 new or added lines in 33 files covered. (81.59%)

3214 existing lines in 124 files now uncovered.

158203 of 245129 relevant lines covered (64.54%)

113224023.06 hits per line

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

76.95
/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,
34,158,383✔
77
                                    SOperatorInfo** pOptrInfo) {
78
  QRY_PARAM_CHECK(pOptrInfo);
34,158,383✔
79

80
  int32_t    lino = 0;
34,166,302✔
81
  int32_t    code = 0;
34,166,302✔
82
  int32_t    num = 0;
34,166,302✔
83
  SExprInfo* pExprInfo = NULL;
34,168,164✔
84
  int32_t    numOfScalarExpr = 0;
34,162,407✔
85
  SExprInfo* pScalarExprInfo = NULL;
34,166,252✔
86

87
  SAggOperatorInfo* pInfo = taosMemoryCalloc(1, sizeof(SAggOperatorInfo));
34,162,937✔
88
  SOperatorInfo*    pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo));
34,122,593✔
89
  if (pInfo == NULL || pOperator == NULL) {
34,124,206✔
90
    code = terrno;
1,287✔
91
    goto _error;
×
92
  }
93

94
  pOperator->exprSupp.hasWindowOrGroup = false;
34,122,919✔
95

96
  SSDataBlock* pResBlock = createDataBlockFromDescNode(pAggNode->node.pOutputDataBlockDesc);
34,129,560✔
97
  QUERY_CHECK_NULL(pResBlock, code, lino, _error, terrno);
34,174,912✔
98
  initBasicInfo(&pInfo->binfo, pResBlock);
34,174,912✔
99

100
  size_t keyBufSize = sizeof(int64_t) + sizeof(int64_t) + POINTER_BYTES;
34,157,896✔
101
  initResultSizeInfo(&pOperator->resultInfo, 4096);
34,157,896✔
102

103

104
  code = createExprInfo(pAggNode->pAggFuncs, pAggNode->pGroupKeys, &pExprInfo, &num);
34,164,236✔
105
  TSDB_CHECK_CODE(code, lino, _error);
34,171,683✔
106

107
  code = initAggSup(&pOperator->exprSupp, &pInfo->aggSup, pExprInfo, num, keyBufSize, pTaskInfo->id.str,
68,298,034✔
108
                               pTaskInfo->streamInfo.pState, &pTaskInfo->storageAPI.functionStore);
34,172,691✔
109
  TSDB_CHECK_CODE(code, lino, _error);
34,145,797✔
110

111
  if (pAggNode->pExprs != NULL) {
34,145,797✔
112
    code = createExprInfo(pAggNode->pExprs, NULL, &pScalarExprInfo, &numOfScalarExpr);
4,422,173✔
113
    TSDB_CHECK_CODE(code, lino, _error);
4,421,845✔
114
  }
115

116
  code = initExprSupp(&pInfo->scalarExprSup, pScalarExprInfo, numOfScalarExpr, &pTaskInfo->storageAPI.functionStore);
34,149,289✔
117
  TSDB_CHECK_CODE(code, lino, _error);
34,137,278✔
118

119
  code = filterInitFromNode((SNode*)pAggNode->node.pConditions, &pOperator->exprSupp.pFilterInfo, 0,
34,155,198✔
120
                            GET_STM_RTINFO(pTaskInfo));
34,137,278✔
121
  TSDB_CHECK_CODE(code, lino, _error);
34,137,854✔
122

123
  pInfo->binfo.mergeResultBlock = pAggNode->mergeDataBlock;
34,137,854✔
124
  pInfo->groupKeyOptimized = pAggNode->groupKeyOptimized;
34,153,391✔
125
  pInfo->groupId = UINT64_MAX;
34,149,184✔
126
  pInfo->binfo.inputTsOrder = pAggNode->node.inputTsOrder;
34,130,851✔
127
  pInfo->binfo.outputTsOrder = pAggNode->node.outputTsOrder;
34,135,084✔
128
  pInfo->hasCountFunc = pAggNode->hasCountLikeFunc;
34,151,388✔
129
  pInfo->pOperator = pOperator;
34,124,043✔
130
  pInfo->cleanGroupResInfo = false;
34,151,574✔
131

132
  setOperatorInfo(pOperator, "TableAggregate", QUERY_NODE_PHYSICAL_PLAN_HASH_AGG,
34,150,414✔
133
                  !pAggNode->node.forceCreateNonBlockingOptr, OP_NOT_OPENED, pInfo, pTaskInfo);
34,143,252✔
134
  pOperator->fpSet = createOperatorFpSet(optrDummyOpenFn, getAggregateResultNext, NULL, destroyAggOperatorInfo,
34,143,412✔
135
                                         optrDefaultBufFn, NULL, optrDefaultGetNextExtFn, NULL);
136
  setOperatorResetStateFn(pOperator, resetAggregateOperatorState);
34,154,672✔
137

138
  pOperator->pPhyNode = pAggNode;
34,150,698✔
139

140
  if (downstream->operatorType == QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN) {
34,156,817✔
141
    STableScanInfo* pTableScanInfo = downstream->info;
25,040,744✔
142
    pTableScanInfo->base.pdInfo.pExprSup = &pOperator->exprSupp;
25,036,519✔
143
    pTableScanInfo->base.pdInfo.pAggSup = &pInfo->aggSup;
25,045,636✔
144
  }
145

146
  code = appendDownstream(pOperator, &downstream, 1);
34,126,812✔
147
  if (code != TSDB_CODE_SUCCESS) {
34,148,377✔
148
    goto _error;
×
149
  }
150

151
  *pOptrInfo = pOperator;
34,148,377✔
152
  return TSDB_CODE_SUCCESS;
34,157,307✔
153

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

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

171
  if (pInfo->pOperator) {
34,175,251✔
172
    cleanupResultInfo(pInfo->pOperator->pTaskInfo, &pInfo->pOperator->exprSupp, &pInfo->groupResInfo, &pInfo->aggSup,
34,174,292✔
173
                      pInfo->cleanGroupResInfo);
34,176,262✔
174
    pInfo->pOperator = NULL;
34,174,955✔
175
  }
176
  cleanupAggSup(&pInfo->aggSup);
34,173,518✔
177
  cleanupExprSuppWithoutFilter(&pInfo->scalarExprSup);
34,173,938✔
178
  cleanupGroupResInfo(&pInfo->groupResInfo);
34,172,955✔
179
  taosMemoryFreeClear(param);
34,173,487✔
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) {
46,388,990✔
190
  int32_t           code = TSDB_CODE_SUCCESS;
46,388,990✔
191
  int32_t           lino = 0;
46,388,990✔
192
  SExecTaskInfo*    pTaskInfo = pOperator->pTaskInfo;
46,388,990✔
193
  SAggOperatorInfo* pAggInfo = pOperator->info;
46,389,336✔
194

195
  if(!pAggInfo) {
46,384,360✔
196
    qError("function:%s, pAggInfo is NULL", __func__);
×
197
    return false;
×
198
  }
199
  if (pOperator->blocking && pAggInfo->hasValidBlock) {
46,384,360✔
200
    return false;
2,864,193✔
201
  }
202

203
  SExprSupp*   pSup = &pOperator->exprSupp;
43,522,550✔
204
  int64_t      st = taosGetTimestampUs();
43,524,120✔
205
  int32_t      order = pAggInfo->binfo.inputTsOrder;
43,524,120✔
206
  SSDataBlock* pBlock = pAggInfo->pNewGroupBlock;
43,525,274✔
207

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

217
    code = doAggregateImpl(pOperator, pSup->pCtx);
3,229,571✔
218
    QUERY_CHECK_CODE(code, lino, _end);
3,232,809✔
219
  }
220
  while (1) {
122,871,220✔
221
    bool blockAllocated = false;
166,395,657✔
222
    pBlock = getNextBlockFromDownstream(pOperator, 0);
166,395,657✔
223
    if (pBlock == NULL) {
164,055,041✔
224
      if (!pAggInfo->hasValidBlock) {
40,455,081✔
225
        code = createDataBlockForEmptyInput(pOperator, &pBlock);
9,513,652✔
226
        QUERY_CHECK_CODE(code, lino, _end);
9,507,321✔
227

228
        if (pBlock == NULL) {
9,507,321✔
229
          break;
6,996,665✔
230
        }
231
        blockAllocated = true;
2,510,656✔
232
      } else {
233
        break;
30,938,089✔
234
      }
235
    }
236
    pAggInfo->hasValidBlock = true;
126,110,616✔
237
    pAggInfo->binfo.pRes->info.scanFlag = pBlock->info.scanFlag;
126,120,036✔
238

239
    printDataBlock(pBlock, __func__, pTaskInfo->id.str, pTaskInfo->id.queryId);
126,115,987✔
240

241
    // there is an scalar expression that needs to be calculated before apply the group aggregation.
242
    if (pAggInfo->scalarExprSup.pExprInfo != NULL && !blockAllocated) {
126,130,556✔
243
      SExprSupp* pSup1 = &pAggInfo->scalarExprSup;
10,335,746✔
244
      code = projectApplyFunctions(pSup1->pExprInfo, pBlock, pBlock, pSup1->pCtx, pSup1->numOfExprs, NULL, GET_STM_RTINFO(pOperator->pTaskInfo));
10,335,746✔
245
      if (code != TSDB_CODE_SUCCESS) {
10,334,262✔
246
        destroyDataBlockForEmptyInput(blockAllocated, &pBlock);
×
247
        T_LONG_JMP(pTaskInfo->env, code);
×
248
      }
249
    }
250
    // if non-blocking mode and new group arrived, save the block and break
251
    if (!pOperator->blocking && pAggInfo->groupId != UINT64_MAX && pBlock->info.id.groupId != pAggInfo->groupId) {
126,129,072✔
252
      pAggInfo->pNewGroupBlock = pBlock;
3,245,126✔
253
      break;
3,245,126✔
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);
122,882,408✔
257
    if (code != TSDB_CODE_SUCCESS) {
122,880,915✔
258
      destroyDataBlockForEmptyInput(blockAllocated, &pBlock);
314✔
259
      T_LONG_JMP(pTaskInfo->env, code);
314✔
260
    }
261
    code = setInputDataBlock(pSup, pBlock, order, pBlock->info.scanFlag, true);
122,880,601✔
262
    if (code != TSDB_CODE_SUCCESS) {
122,878,124✔
263
      destroyDataBlockForEmptyInput(blockAllocated, &pBlock);
×
264
      T_LONG_JMP(pTaskInfo->env, code);
×
265
    }
266

267
    code = doAggregateImpl(pOperator, pSup->pCtx);
122,878,124✔
268
    if (code != TSDB_CODE_SUCCESS) {
122,872,759✔
269
      destroyDataBlockForEmptyInput(blockAllocated, &pBlock);
5,378✔
270
      T_LONG_JMP(pTaskInfo->env, code);
5,378✔
271
    }
272

273
    destroyDataBlockForEmptyInput(blockAllocated, &pBlock);
122,867,381✔
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) {
41,179,880✔
278
    T_LONG_JMP(pTaskInfo->env, pTaskInfo->code);
×
279
  }
280

281
  code = initGroupedResultInfo(&pAggInfo->groupResInfo, pAggInfo->aggSup.pResultRowHashTable, 0);
41,172,586✔
282
  QUERY_CHECK_CODE(code, lino, _end);
41,182,512✔
283
  pAggInfo->cleanGroupResInfo = true;
41,182,512✔
284

285
_end:
41,185,126✔
286
  if (code != TSDB_CODE_SUCCESS) {
41,184,814✔
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;
41,186,375✔
292
}
293

294
int32_t getAggregateResultNext(SOperatorInfo* pOperator, SSDataBlock** ppRes) {
76,392,691✔
295
  int32_t           code = TSDB_CODE_SUCCESS;
76,392,691✔
296
  int32_t           lino = 0;
76,392,691✔
297
  SAggOperatorInfo* pAggInfo = pOperator->info;
76,392,691✔
298
  SOptrBasicInfo*   pInfo = &pAggInfo->binfo;
76,393,348✔
299

300
  if (pOperator->status == OP_EXEC_DONE) {
76,392,650✔
301
    (*ppRes) = NULL;
30,017,376✔
302
    return code;
30,018,204✔
303
  }
304

305
  SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
46,370,566✔
306
  bool           hasNewGroups = false;
46,376,224✔
307
  do {
308
    hasNewGroups = nextGroupedResult(pOperator);
46,389,453✔
309
    code = blockDataEnsureCapacity(pInfo->pRes, pOperator->resultInfo.capacity);
44,048,676✔
310
    QUERY_CHECK_CODE(code, lino, _end);
44,052,037✔
311

312
    while (1) {
313
      doBuildResultDatablock(pOperator, pInfo, &pAggInfo->groupResInfo, pAggInfo->aggSup.pResultBuf);
44,052,037✔
314
      code = doFilter(pInfo->pRes, pOperator->exprSupp.pFilterInfo, NULL, NULL);
44,048,983✔
315
      QUERY_CHECK_CODE(code, lino, _end);
44,053,681✔
316

317
      if (!hasRemainResults(&pAggInfo->groupResInfo)) {
44,053,681✔
318
        if (!hasNewGroups) setOperatorCompleted(pOperator);
41,188,429✔
319
        break;
41,189,226✔
320
      }
321

322
      if (pInfo->pRes->info.rows > 0) {
2,865,389✔
323
        break;
2,865,389✔
324
      }
325
    }
326
  } while (pInfo->pRes->info.rows == 0 && hasNewGroups);
44,054,615✔
327

328
  size_t rows = blockDataGetNumOfRows(pInfo->pRes);
44,040,062✔
329
  pOperator->resultInfo.totalRows += rows;
44,039,241✔
330

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

338
  printDataBlock(pInfo->pRes, __func__, pTaskInfo->id.str, pTaskInfo->id.queryId);
44,035,726✔
339

340
  (*ppRes) = (rows == 0) ? NULL : pInfo->pRes;
44,042,446✔
341
  return code;
44,042,446✔
342
}
343

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

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

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

374
  return TSDB_CODE_SUCCESS;
126,100,236✔
375
}
376

377
static int32_t createDataBlockForEmptyInput(SOperatorInfo* pOperator, SSDataBlock** ppBlock) {
9,514,312✔
378
  int32_t code = TSDB_CODE_SUCCESS;
9,514,312✔
379
  int32_t lino = 0;
9,514,312✔
380
  SSDataBlock* pBlock = NULL;
9,514,312✔
381
  if (!tsCountAlwaysReturnValue) {
9,514,449✔
382
    return TSDB_CODE_SUCCESS;
1,662,697✔
383
  }
384

385
  SAggOperatorInfo* pAggInfo = pOperator->info;
7,851,752✔
386
  if (pAggInfo->groupKeyOptimized) {
7,851,092✔
387
    return TSDB_CODE_SUCCESS;
1,394,338✔
388
  }
389

390
  SOperatorInfo* downstream = pOperator->pDownstream[0];
6,448,834✔
391
  if (downstream->operatorType == QUERY_NODE_PHYSICAL_PLAN_PARTITION ||
6,450,154✔
392
      downstream->operatorType == QUERY_NODE_PHYSICAL_PLAN_SORT ||
6,439,664✔
393
      (downstream->operatorType == QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN &&
6,434,624✔
394
       ((STableScanInfo*)downstream->info)->hasGroupByTag == true)) {
3,435,998✔
395
    return TSDB_CODE_SUCCESS;
18,830✔
396
  }
397

398
  SqlFunctionCtx* pCtx = pOperator->exprSupp.pCtx;
6,433,304✔
399

400
  if (!pAggInfo->hasCountFunc) {
6,431,984✔
401
    return TSDB_CODE_SUCCESS;
3,914,524✔
402
  }
403

404
  code = createDataBlock(&pBlock);
2,513,956✔
405
  if (code) {
2,515,210✔
406
    return code;
×
407
  }
408

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

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

418
    SExprInfo* pOneExpr = &pOperator->exprSupp.pExprInfo[i];
5,298,745✔
419
    for (int32_t j = 0; j < pOneExpr->base.numOfParams; ++j) {
10,843,640✔
420
      SFunctParam* pFuncParam = &pOneExpr->base.pParam[j];
5,545,555✔
421
      if (pFuncParam->type == FUNC_PARAM_TYPE_COLUMN) {
5,543,641✔
422
        int32_t slotId = pFuncParam->pCol->slotId;
5,543,977✔
423
        int32_t numOfCols = taosArrayGetSize(pBlock->pDataBlock);
5,542,723✔
424
        if (slotId >= numOfCols) {
5,543,251✔
425
          code = taosArrayEnsureCap(pBlock->pDataBlock, slotId + 1);
2,928,773✔
426
          QUERY_CHECK_CODE(code, lino, _end);
2,928,839✔
427

428
          for (int32_t k = numOfCols; k < slotId + 1; ++k) {
8,456,935✔
429
            void* tmp = taosArrayPush(pBlock->pDataBlock, &colInfo);
5,528,096✔
430
            QUERY_CHECK_NULL(tmp, code, lino, _end, terrno);
5,528,096✔
431
          }
432
        }
433
      } else if (pFuncParam->type == FUNC_PARAM_TYPE_VALUE) {
1,578✔
434
        // do nothing
435
      }
436
    }
437
  }
438

439
  code = blockDataEnsureCapacity(pBlock, pBlock->info.rows);
2,514,550✔
440
  QUERY_CHECK_CODE(code, lino, _end);
2,515,210✔
441

442
  for (int32_t i = 0; i < blockDataGetNumOfCols(pBlock); ++i) {
8,043,900✔
443
    SColumnInfoData* pColInfoData = taosArrayGet(pBlock->pDataBlock, i);
5,529,350✔
444
    QUERY_CHECK_NULL(pColInfoData, code, lino, _end, terrno);
5,528,096✔
445
    colDataSetNULL(pColInfoData, 0);
446
  }
447
  *ppBlock = pBlock;
2,515,210✔
448

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

457
void destroyDataBlockForEmptyInput(bool blockAllocated, SSDataBlock** ppBlock) {
122,877,686✔
458
  if (!blockAllocated) {
122,877,686✔
459
    return;
120,363,535✔
460
  }
461

462
  blockDataDestroy(*ppBlock);
2,514,151✔
463
  *ppBlock = NULL;
2,515,870✔
464
}
465

466
int32_t setExecutionContext(SOperatorInfo* pOperator, int32_t numOfOutput, uint64_t groupId) {
126,111,120✔
467
  int32_t           code = TSDB_CODE_SUCCESS;
126,111,120✔
468
  SAggOperatorInfo* pAggInfo = pOperator->info;
126,111,120✔
469
  if (pAggInfo->groupId != UINT64_MAX && pAggInfo->groupId == groupId) {
126,113,854✔
470
    return code;
69,667,245✔
471
  }
472

473
  code = doSetTableGroupOutputBuf(pOperator, numOfOutput, groupId);
56,445,711✔
474

475
  // record the current active group id
476
  pAggInfo->groupId = groupId;
56,442,171✔
477
  return code;
56,444,421✔
478
}
479

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

487
  SResultRowInfo* pResultRowInfo = &pAggInfo->binfo.resultRowInfo;
56,446,075✔
488
  SqlFunctionCtx* pCtx = pOperator->exprSupp.pCtx;
56,446,954✔
489
  int32_t*        rowEntryInfoOffset = pOperator->exprSupp.rowEntryInfoOffset;
56,446,466✔
490

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

508
  code = setResultRowInitCtx(pResultRow, pCtx, numOfOutput, rowEntryInfoOffset);
56,445,051✔
509
  QUERY_CHECK_CODE(code, lino, _end);
56,442,484✔
510

511
_end:
56,442,484✔
512
  if (code != TSDB_CODE_SUCCESS) {
56,442,798✔
513
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
314✔
514
  }
515
  return code;
56,443,303✔
516
}
517

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

524
  SFilePage* pData = NULL;
×
525

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

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

545
    pageId = getPageId(pi);
×
546

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

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

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

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

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

572
  return 0;
×
573
}
574

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

580
  pAggSup->currentPageId = -1;
135,095,130✔
581
  pAggSup->resultRowSize = getResultRowSize(pCtx, numOfOutput);
135,078,480✔
582
  pAggSup->keyBuf = taosMemoryCalloc(1, keyBufSize + POINTER_BYTES + sizeof(int64_t));
135,074,220✔
583
  pAggSup->pResultRowHashTable = tSimpleHashInit(100, taosFastHash);
135,097,415✔
584

585
  if (pAggSup->keyBuf == NULL || pAggSup->pResultRowHashTable == NULL) {
135,073,173✔
586
    return terrno;
13,053✔
587
  }
588

589
  uint32_t defaultPgsz = 0;
135,062,180✔
590
  int64_t defaultBufsz = 0;
135,063,940✔
591
  code = getBufferPgSize(pAggSup->resultRowSize, &defaultPgsz, &defaultBufsz);
135,074,162✔
592
  if (code) {
135,036,908✔
593
    qError("failed to get buff page size, rowSize:%d", pAggSup->resultRowSize);
×
594
    return code;
×
595
  }
596

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

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

609
  return code;
135,092,750✔
610
}
611

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

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

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

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

648
void cleanupResultInfoInGroupResInfo(SExecTaskInfo* pTaskInfo, SExprSupp* pSup, SDiskbasedBuf* pBuf,
40,997,909✔
649
                                  SGroupResInfo* pGroupResInfo) {
650
  int32_t         numOfExprs = pSup->numOfExprs;
40,997,909✔
651
  int32_t*        rowEntryOffset = pSup->rowEntryInfoOffset;
40,999,096✔
652
  SqlFunctionCtx* pCtx = pSup->pCtx;
40,998,540✔
653
  int32_t         numOfRows = getNumOfTotalRes(pGroupResInfo);
40,998,693✔
654
  bool            needCleanup = false;
40,996,800✔
655

656
  for (int32_t j = 0; j < numOfExprs; ++j) {
147,786,800✔
657
    needCleanup |= pCtx[j].needCleanup;
106,788,822✔
658
  }
659
  if (!needCleanup) {
40,997,978✔
660
    return;
40,638,420✔
661
  }
662

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

673

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

684
void cleanupResultInfoInHashMap(SExecTaskInfo* pTaskInfo, SExprSupp* pSup, SDiskbasedBuf* pBuf,
22,635,167✔
685
                       SGroupResInfo* pGroupResInfo, SSHashObj* pHashmap) {
686
  int32_t         numOfExprs = pSup->numOfExprs;
22,635,167✔
687
  int32_t*        rowEntryOffset = pSup->rowEntryInfoOffset;
22,635,298✔
688
  SqlFunctionCtx* pCtx = pSup->pCtx;
22,635,698✔
689
  bool            needCleanup = false;
22,636,171✔
690
  for (int32_t j = 0; j < numOfExprs; ++j) {
67,065,119✔
691
    needCleanup |= pCtx[j].needCleanup;
44,428,417✔
692
  }
693
  if (!needCleanup) {
22,636,702✔
694
    return;
22,633,723✔
695
  }
696

697
  // begin from last iter
698
  void*   pData = pGroupResInfo->dataPos;
2,979✔
699
  int32_t iter = pGroupResInfo->iter;
2,979✔
700
  while ((pData = tSimpleHashIterate(pHashmap, pData, &iter)) != NULL) {
3,501✔
701
    SResultRowPosition* pos = pData;
522✔
702

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

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

711
    for (int32_t j = 0; j < numOfExprs; ++j) {
10,962✔
712
      pCtx[j].resultInfo = getResultEntryInfo(pRow, j, rowEntryOffset);
10,440✔
713
      if (pCtx[j].fpSet.cleanup) {
10,440✔
714
        pCtx[j].fpSet.cleanup(&pCtx[j]);
1,044✔
715
      }
716
    }
717

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

722
void cleanupResultInfo(SExecTaskInfo* pTaskInfo, SExprSupp* pSup, SGroupResInfo* pGroupResInfo,
63,633,349✔
723
                       SAggSupporter *pAggSup, bool cleanGroupResInfo) {
724
  if (cleanGroupResInfo) {
63,633,349✔
725
    cleanupResultInfoInGroupResInfo(pTaskInfo, pSup, pAggSup->pResultBuf, pGroupResInfo);
40,998,978✔
726
  } else {
727
    cleanupResultInfoInHashMap(pTaskInfo, pSup, pAggSup->pResultBuf, pGroupResInfo, pAggSup->pResultRowHashTable);
22,634,371✔
728
  }
729
}
63,634,054✔
730
void cleanupAggSup(SAggSupporter* pAggSup) {
135,140,440✔
731
  taosMemoryFreeClear(pAggSup->keyBuf);
135,140,440✔
732
  tSimpleHashCleanup(pAggSup->pResultRowHashTable);
135,137,935✔
733
  destroyDiskbasedBuf(pAggSup->pResultBuf);
135,139,547✔
734
  memset(pAggSup, 0, sizeof(SAggSupporter));
135,131,487✔
735
}
135,131,487✔
736

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

744
  code = doInitAggInfoSup(pAggSup, pSup->pCtx, numOfCols, keyBufSize, pkey);
135,091,792✔
745
  if (code != TSDB_CODE_SUCCESS) {
135,083,093✔
746
    return code;
×
747
  }
748

749
  for (int32_t i = 0; i < numOfCols; ++i) {
687,000,145✔
750
    pSup->pCtx[i].hasWindowOrGroup = pSup->hasWindowOrGroup;
551,980,293✔
751
    if (pState) {
551,883,541✔
752
      pSup->pCtx[i].saveHandle.pBuf = NULL;
×
753
      pSup->pCtx[i].saveHandle.pState = pState;
×
754
      pSup->pCtx[i].exprIdx = i;
×
755
    } else {
756
      pSup->pCtx[i].saveHandle.pBuf = pAggSup->pResultBuf;
551,883,541✔
757
    }
758
  }
759

760
  return TSDB_CODE_SUCCESS;
135,019,852✔
761
}
762

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

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

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

780
    if (fmIsPlaceHolderFunc(pCtx[k].functionId)) {
2,147,483,647✔
781
      SResultRowEntryInfo* pEntryInfo = GET_RES_INFO(&pCtx[k]);
13,223,609✔
782
      char* p = GET_ROWCELL_INTERBUF(pEntryInfo);
13,223,609✔
783

784
      TAOS_CHECK_EXIT(fmSetStreamPseudoFuncParamVal(pCtx[k].functionId, pCtx[k].pExpr->base.pParamList, &taskInfo->pStreamRuntimeInfo->funcInfo));
13,224,007✔
785

786
      SValueNode *valueNode = (SValueNode *)nodesListGetNode(pCtx[k].pExpr->base.pParamList, 0);
13,223,609✔
787
      pEntryInfo->isNullRes = 0;
13,224,007✔
788
      if (TSDB_DATA_TYPE_NULL == valueNode->node.resType.type || valueNode->isNull) {
13,224,007✔
789
        pEntryInfo->isNullRes = 1;
×
790
      } else if (IS_VAR_DATA_TYPE(pCtx[k].pExpr->base.resSchema.type)){
13,224,007✔
791
        void* v = nodesGetValueFromNode(valueNode);
20,263✔
792
        memcpy(p, v, varDataTLen(v));
18,656✔
793
      } else {
794
        memcpy(p, nodesGetValueFromNode(valueNode), pCtx[k].pExpr->base.resSchema.bytes);
13,204,158✔
795
      }
796
      
797
      pEntryInfo->numOfRes = 1;
13,223,615✔
798
    } else if (pCtx[k].isPseudoFunc) {
2,147,483,647✔
799
      SResultRowEntryInfo* pEntryInfo = GET_RES_INFO(&pCtx[k]);
2,147,483,647✔
800

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

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

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

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

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

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

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

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

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

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

857
static int32_t resetAggregateOperatorState(SOperatorInfo* pOper) {
6,806,989✔
858
  SAggOperatorInfo* pAgg = pOper->info;
6,806,989✔
859
  SAggPhysiNode*   pAggNode = (SAggPhysiNode*)pOper->pPhyNode;
6,807,789✔
860
  
861
  pOper->status = OP_NOT_OPENED;
6,807,389✔
862
  size_t keyBufSize = sizeof(int64_t) + sizeof(int64_t) + POINTER_BYTES;
6,807,789✔
863
  SExecTaskInfo*  pTaskInfo = pOper->pTaskInfo;
6,807,789✔
864
  cleanupResultInfo(pTaskInfo, &pOper->exprSupp, &pAgg->groupResInfo, &pAgg->aggSup,
6,807,789✔
865
                      pAgg->cleanGroupResInfo);
6,807,789✔
866
  cleanupGroupResInfo(&pAgg->groupResInfo);
6,806,985✔
867
  resetBasicOperatorState(&pAgg->binfo);
6,805,785✔
868
  
869
  pAgg->pNewGroupBlock = NULL;
6,807,389✔
870

871
  int32_t code = resetAggSup(&pOper->exprSupp, &pAgg->aggSup, pTaskInfo, pAggNode->pAggFuncs, pAggNode->pGroupKeys,
13,609,553✔
872
    keyBufSize, pTaskInfo->id.str, pTaskInfo->streamInfo.pState, &pTaskInfo->storageAPI.functionStore);
6,807,389✔
873

874
  if (code == 0) {
6,807,789✔
875
    code = resetExprSupp(&pAgg->scalarExprSup, pTaskInfo, pAggNode->pExprs, NULL,
6,807,389✔
876
                          &pTaskInfo->storageAPI.functionStore);
877
  }
878

879
  pAgg->groupId = UINT64_MAX;
6,807,013✔
880
  pAgg->cleanGroupResInfo = false;
6,807,413✔
881
  pAgg->hasValidBlock = false;
6,807,413✔
882
  return 0;
6,807,389✔
883
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc