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

taosdata / TDengine / #4820

20 Oct 2025 09:08AM UTC coverage: 61.353% (-0.04%) from 61.392%
#4820

push

travis-ci

happyguoxy
add alarm result print

156500 of 324369 branches covered (48.25%)

Branch coverage included in aggregate %.

207878 of 269535 relevant lines covered (77.12%)

242602011.17 hits per line

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

61.86
/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,
367,820,664✔
77
                                    SOperatorInfo** pOptrInfo) {
78
  QRY_PARAM_CHECK(pOptrInfo);
367,820,664!
79

80
  int32_t    lino = 0;
367,890,521✔
81
  int32_t    code = 0;
367,890,521✔
82
  int32_t    num = 0;
367,890,521✔
83
  SExprInfo* pExprInfo = NULL;
367,907,350✔
84
  int32_t    numOfScalarExpr = 0;
367,892,180✔
85
  SExprInfo* pScalarExprInfo = NULL;
367,845,797✔
86

87
  SAggOperatorInfo* pInfo = taosMemoryCalloc(1, sizeof(SAggOperatorInfo));
367,837,148✔
88
  SOperatorInfo*    pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo));
367,495,561✔
89
  if (pInfo == NULL || pOperator == NULL) {
367,458,751✔
90
    code = terrno;
349✔
91
    goto _error;
×
92
  }
93

94
  pOperator->exprSupp.hasWindowOrGroup = false;
367,463,350✔
95

96
  SSDataBlock* pResBlock = createDataBlockFromDescNode(pAggNode->node.pOutputDataBlockDesc);
367,622,501✔
97
  QUERY_CHECK_NULL(pResBlock, code, lino, _error, terrno);
367,976,774!
98
  initBasicInfo(&pInfo->binfo, pResBlock);
367,976,774✔
99

100
  size_t keyBufSize = sizeof(int64_t) + sizeof(int64_t) + POINTER_BYTES;
367,865,167✔
101
  initResultSizeInfo(&pOperator->resultInfo, 4096);
367,865,167✔
102

103

104
  code = createExprInfo(pAggNode->pAggFuncs, pAggNode->pGroupKeys, &pExprInfo, &num);
367,899,300✔
105
  TSDB_CHECK_CODE(code, lino, _error);
367,917,983!
106

107
  code = initAggSup(&pOperator->exprSupp, &pInfo->aggSup, pExprInfo, num, keyBufSize, pTaskInfo->id.str,
735,805,129✔
108
                               pTaskInfo->streamInfo.pState, &pTaskInfo->storageAPI.functionStore);
367,922,569✔
109
  TSDB_CHECK_CODE(code, lino, _error);
367,711,795!
110

111
  if (pAggNode->pExprs != NULL) {
367,711,795✔
112
    code = createExprInfo(pAggNode->pExprs, NULL, &pScalarExprInfo, &numOfScalarExpr);
85,649,105✔
113
    TSDB_CHECK_CODE(code, lino, _error);
85,646,982!
114
  }
115

116
  code = initExprSupp(&pInfo->scalarExprSup, pScalarExprInfo, numOfScalarExpr, &pTaskInfo->storageAPI.functionStore);
367,808,505✔
117
  TSDB_CHECK_CODE(code, lino, _error);
367,707,844!
118

119
  code = filterInitFromNode((SNode*)pAggNode->node.pConditions, &pOperator->exprSupp.pFilterInfo, 0,
367,807,329✔
120
                            GET_STM_RTINFO(pTaskInfo));
367,707,844✔
121
  TSDB_CHECK_CODE(code, lino, _error);
367,678,172!
122

123
  pInfo->binfo.mergeResultBlock = pAggNode->mergeDataBlock;
367,678,172!
124
  pInfo->groupKeyOptimized = pAggNode->groupKeyOptimized;
367,822,438!
125
  pInfo->groupId = UINT64_MAX;
367,800,822✔
126
  pInfo->binfo.inputTsOrder = pAggNode->node.inputTsOrder;
367,646,950✔
127
  pInfo->binfo.outputTsOrder = pAggNode->node.outputTsOrder;
367,757,587✔
128
  pInfo->hasCountFunc = pAggNode->hasCountLikeFunc;
367,924,140!
129
  pInfo->pOperator = pOperator;
367,692,840✔
130
  pInfo->cleanGroupResInfo = false;
367,817,691✔
131

132
  setOperatorInfo(pOperator, "TableAggregate", QUERY_NODE_PHYSICAL_PLAN_HASH_AGG,
367,719,223✔
133
                  !pAggNode->node.forceCreateNonBlockingOptr, OP_NOT_OPENED, pInfo, pTaskInfo);
367,893,314!
134
  pOperator->fpSet = createOperatorFpSet(optrDummyOpenFn, getAggregateResultNext, NULL, destroyAggOperatorInfo,
367,685,484✔
135
                                         optrDefaultBufFn, NULL, optrDefaultGetNextExtFn, NULL);
136
  setOperatorResetStateFn(pOperator, resetAggregateOperatorState);
367,824,178✔
137

138
  pOperator->pPhyNode = pAggNode;
367,625,755✔
139

140
  if (downstream->operatorType == QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN) {
367,657,705✔
141
    STableScanInfo* pTableScanInfo = downstream->info;
237,476,954✔
142
    pTableScanInfo->base.pdInfo.pExprSup = &pOperator->exprSupp;
237,435,551✔
143
    pTableScanInfo->base.pdInfo.pAggSup = &pInfo->aggSup;
237,493,339✔
144
  }
145

146
  code = appendDownstream(pOperator, &downstream, 1);
367,564,305✔
147
  if (code != TSDB_CODE_SUCCESS) {
367,825,853!
148
    goto _error;
×
149
  }
150

151
  *pOptrInfo = pOperator;
367,825,853✔
152
  return TSDB_CODE_SUCCESS;
367,874,149✔
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) {
367,981,206✔
165
  if (param == NULL) {
367,981,206!
166
    return;
×
167
  }
168
  SAggOperatorInfo* pInfo = (SAggOperatorInfo*)param;
367,981,206✔
169
  cleanupBasicInfo(&pInfo->binfo);
367,981,206✔
170

171
  if (pInfo->pOperator) {
367,983,045!
172
    cleanupResultInfo(pInfo->pOperator->pTaskInfo, &pInfo->pOperator->exprSupp, &pInfo->groupResInfo, &pInfo->aggSup,
367,977,796✔
173
                      pInfo->cleanGroupResInfo);
367,993,923!
174
    pInfo->pOperator = NULL;
367,979,197✔
175
  }
176
  cleanupAggSup(&pInfo->aggSup);
367,981,947✔
177
  cleanupExprSuppWithoutFilter(&pInfo->scalarExprSup);
367,982,932✔
178
  cleanupGroupResInfo(&pInfo->groupResInfo);
367,986,372✔
179
  taosMemoryFreeClear(param);
367,956,700!
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) {
510,007,239✔
190
  int32_t           code = TSDB_CODE_SUCCESS;
510,007,239✔
191
  int32_t           lino = 0;
510,007,239✔
192
  SExecTaskInfo*    pTaskInfo = pOperator->pTaskInfo;
510,007,239✔
193
  SAggOperatorInfo* pAggInfo = pOperator->info;
510,020,117✔
194

195
  if(!pAggInfo) {
510,003,998!
196
    qError("function:%s, pAggInfo is NULL", __func__);
×
197
    return false;
×
198
  }
199
  if (pOperator->blocking && pAggInfo->hasValidBlock) {
510,003,998!
200
    return false;
63,825,034✔
201
  }
202

203
  SExprSupp*   pSup = &pOperator->exprSupp;
446,169,879✔
204
  int64_t      st = taosGetTimestampUs();
446,175,258✔
205
  int32_t      order = pAggInfo->binfo.inputTsOrder;
446,175,258✔
206
  SSDataBlock* pBlock = pAggInfo->pNewGroupBlock;
446,182,421✔
207

208
  pAggInfo->cleanGroupResInfo = false;
446,152,929✔
209
  if (pBlock) {
446,140,936✔
210
    pAggInfo->pNewGroupBlock = NULL;
52,224,355✔
211
    tSimpleHashClear(pAggInfo->aggSup.pResultRowHashTable);
52,224,355✔
212
    code = setExecutionContext(pOperator, pOperator->exprSupp.numOfExprs, pBlock->info.id.groupId);
52,224,355✔
213
    QUERY_CHECK_CODE(code, lino, _end);
52,224,355!
214
    code = setInputDataBlock(pSup, pBlock, order, pBlock->info.scanFlag, true);
52,224,355✔
215
    QUERY_CHECK_CODE(code, lino, _end);
52,224,355!
216

217
    code = doAggregateImpl(pOperator, pSup->pCtx);
52,224,355✔
218
    QUERY_CHECK_CODE(code, lino, _end);
52,266,551!
219
  }
220
  while (1) {
1,305,178,068✔
221
    bool blockAllocated = false;
1,751,361,200✔
222
    pBlock = getNextBlockFromDownstream(pOperator, 0);
1,751,361,200✔
223
    if (pBlock == NULL) {
1,733,815,307✔
224
      if (!pAggInfo->hasValidBlock) {
389,912,190!
225
        code = createDataBlockForEmptyInput(pOperator, &pBlock);
87,829,190✔
226
        QUERY_CHECK_CODE(code, lino, _end);
87,825,462!
227

228
        if (pBlock == NULL) {
87,825,462✔
229
          break;
74,270,542✔
230
        }
231
        blockAllocated = true;
13,554,920✔
232
      } else {
233
        break;
302,080,718✔
234
      }
235
    }
236
    pAggInfo->hasValidBlock = true;
1,357,458,037✔
237
    pAggInfo->binfo.pRes->info.scanFlag = pBlock->info.scanFlag;
1,357,572,059✔
238

239
    printDataBlock(pBlock, __func__, pTaskInfo->id.str, pTaskInfo->id.queryId);
1,357,585,365✔
240

241
    // there is an scalar expression that needs to be calculated before apply the group aggregation.
242
    if (pAggInfo->scalarExprSup.pExprInfo != NULL && !blockAllocated) {
1,357,480,395✔
243
      SExprSupp* pSup1 = &pAggInfo->scalarExprSup;
282,003,253✔
244
      code = projectApplyFunctions(pSup1->pExprInfo, pBlock, pBlock, pSup1->pCtx, pSup1->numOfExprs, NULL, GET_STM_RTINFO(pOperator->pTaskInfo));
282,002,446✔
245
      if (code != TSDB_CODE_SUCCESS) {
281,952,210!
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) {
1,357,533,709!
252
      pAggInfo->pNewGroupBlock = pBlock;
52,289,346✔
253
      break;
52,289,346✔
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);
1,305,078,432✔
257
    if (code != TSDB_CODE_SUCCESS) {
1,305,009,492!
258
      destroyDataBlockForEmptyInput(blockAllocated, &pBlock);
×
259
      T_LONG_JMP(pTaskInfo->env, code);
×
260
    }
261
    code = setInputDataBlock(pSup, pBlock, order, pBlock->info.scanFlag, true);
1,305,009,492✔
262
    if (code != TSDB_CODE_SUCCESS) {
1,305,220,876!
263
      destroyDataBlockForEmptyInput(blockAllocated, &pBlock);
×
264
      T_LONG_JMP(pTaskInfo->env, code);
×
265
    }
266

267
    code = doAggregateImpl(pOperator, pSup->pCtx);
1,305,220,876✔
268
    if (code != TSDB_CODE_SUCCESS) {
1,305,153,486✔
269
      destroyDataBlockForEmptyInput(blockAllocated, &pBlock);
4,076✔
270
      T_LONG_JMP(pTaskInfo->env, code);
4,076!
271
    }
272

273
    destroyDataBlockForEmptyInput(blockAllocated, &pBlock);
1,305,149,410✔
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) {
428,640,606!
278
    T_LONG_JMP(pTaskInfo->env, pTaskInfo->code);
×
279
  }
280

281
  code = initGroupedResultInfo(&pAggInfo->groupResInfo, pAggInfo->aggSup.pResultRowHashTable, 0);
428,603,805✔
282
  QUERY_CHECK_CODE(code, lino, _end);
428,617,348!
283
  pAggInfo->cleanGroupResInfo = true;
428,617,348✔
284

285
_end:
428,622,624✔
286
  if (code != TSDB_CODE_SUCCESS) {
428,612,227✔
287
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
113!
288
    pTaskInfo->code = code;
113✔
289
    T_LONG_JMP(pTaskInfo->env, code);
×
290
  }
291
  return pBlock != NULL;
428,620,638✔
292
}
293

294
int32_t getAggregateResultNext(SOperatorInfo* pOperator, SSDataBlock** ppRes) {
792,355,765✔
295
  int32_t           code = TSDB_CODE_SUCCESS;
792,355,765✔
296
  int32_t           lino = 0;
792,355,765✔
297
  SAggOperatorInfo* pAggInfo = pOperator->info;
792,355,765✔
298
  SOptrBasicInfo*   pInfo = &pAggInfo->binfo;
792,373,948✔
299

300
  if (pOperator->status == OP_EXEC_DONE) {
792,342,788✔
301
    (*ppRes) = NULL;
282,396,386✔
302
    return code;
282,394,474✔
303
  }
304

305
  SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
509,922,907✔
306
  bool           hasNewGroups = false;
509,976,840✔
307
  do {
308
    hasNewGroups = nextGroupedResult(pOperator);
510,017,010✔
309
    code = blockDataEnsureCapacity(pInfo->pRes, pOperator->resultInfo.capacity);
492,442,534✔
310
    QUERY_CHECK_CODE(code, lino, _end);
492,475,806!
311

312
    while (1) {
313
      doBuildResultDatablock(pOperator, pInfo, &pAggInfo->groupResInfo, pAggInfo->aggSup.pResultBuf);
492,475,806✔
314
      code = doFilter(pInfo->pRes, pOperator->exprSupp.pFilterInfo, NULL, NULL);
492,473,071✔
315
      QUERY_CHECK_CODE(code, lino, _end);
492,473,995!
316

317
      if (!hasRemainResults(&pAggInfo->groupResInfo)) {
492,473,995✔
318
        if (!hasNewGroups) setOperatorCompleted(pOperator);
428,647,579✔
319
        break;
428,656,375✔
320
      }
321

322
      if (pInfo->pRes->info.rows > 0) {
63,828,687!
323
        break;
63,828,687✔
324
      }
325
    }
326
  } while (pInfo->pRes->info.rows == 0 && hasNewGroups);
492,485,062✔
327

328
  size_t rows = blockDataGetNumOfRows(pInfo->pRes);
492,444,304✔
329
  pOperator->resultInfo.totalRows += rows;
492,437,442✔
330

331
_end:
492,415,034✔
332
  if (code != TSDB_CODE_SUCCESS) {
492,415,034!
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);
492,415,034✔
339

340
  (*ppRes) = (rows == 0) ? NULL : pInfo->pRes;
492,433,182✔
341
  return code;
492,424,764✔
342
}
343

344
int32_t doAggregateImpl(SOperatorInfo* pOperator, SqlFunctionCtx* pCtx) {
1,357,423,340✔
345
  int32_t code = TSDB_CODE_SUCCESS;
1,357,423,340✔
346
  if (!pOperator || (pOperator->exprSupp.numOfExprs > 0 && pCtx == NULL)) {
1,357,423,340!
347
    qError("%s failed at line %d since pCtx is NULL.", __func__, __LINE__);
55,369!
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;
36,375,138✔
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) {
4,076!
366
          pCtx[k].fpSet.cleanup(&pCtx[k]);
×
367
        }
368
        qError("%s aggregate function error happens, code:%s", GET_TASKID(pOperator->pTaskInfo), tstrerror(code));
4,076!
369
        return code;
4,076✔
370
      }
371
    }
372
  }
373

374
  return TSDB_CODE_SUCCESS;
1,357,433,395✔
375
}
376

377
static int32_t createDataBlockForEmptyInput(SOperatorInfo* pOperator, SSDataBlock** ppBlock) {
87,825,188✔
378
  int32_t code = TSDB_CODE_SUCCESS;
87,825,188✔
379
  int32_t lino = 0;
87,825,188✔
380
  SSDataBlock* pBlock = NULL;
87,825,188✔
381
  if (!tsCountAlwaysReturnValue) {
87,828,843✔
382
    return TSDB_CODE_SUCCESS;
43,050,274✔
383
  }
384

385
  SAggOperatorInfo* pAggInfo = pOperator->info;
44,778,569✔
386
  if (pAggInfo->groupKeyOptimized) {
44,774,284!
387
    return TSDB_CODE_SUCCESS;
14,354,645✔
388
  }
389

390
  SOperatorInfo* downstream = pOperator->pDownstream[0];
30,418,113✔
391
  if (downstream->operatorType == QUERY_NODE_PHYSICAL_PLAN_PARTITION ||
30,421,042✔
392
      downstream->operatorType == QUERY_NODE_PHYSICAL_PLAN_SORT ||
30,217,248✔
393
      (downstream->operatorType == QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN &&
30,098,088✔
394
       ((STableScanInfo*)downstream->info)->hasGroupByTag == true)) {
11,813,867!
395
    return TSDB_CODE_SUCCESS;
327,634✔
396
  }
397

398
  SqlFunctionCtx* pCtx = pOperator->exprSupp.pCtx;
30,079,228✔
399

400
  if (!pAggInfo->hasCountFunc) {
30,098,494!
401
    return TSDB_CODE_SUCCESS;
16,539,381✔
402
  }
403

404
  code = createDataBlock(&pBlock);
13,550,383✔
405
  if (code) {
13,553,657!
406
    return code;
×
407
  }
408

409
  pBlock->info.rows = 1;
13,553,657✔
410
  pBlock->info.capacity = 0;
13,553,323✔
411

412
  for (int32_t i = 0; i < pOperator->exprSupp.numOfExprs; ++i) {
33,277,891✔
413
    SColumnInfoData colInfo = {0};
19,719,685✔
414
    colInfo.hasNull = true;
19,720,019✔
415
    colInfo.info.type = TSDB_DATA_TYPE_NULL;
19,720,019✔
416
    colInfo.info.bytes = 1;
19,720,019✔
417

418
    SExprInfo* pOneExpr = &pOperator->exprSupp.pExprInfo[i];
19,720,019✔
419
    for (int32_t j = 0; j < pOneExpr->base.numOfParams; ++j) {
39,961,644✔
420
      SFunctParam* pFuncParam = &pOneExpr->base.pParam[j];
20,243,115✔
421
      if (pFuncParam->type == FUNC_PARAM_TYPE_COLUMN) {
20,239,411✔
422
        int32_t slotId = pFuncParam->pCol->slotId;
20,219,108✔
423
        int32_t numOfCols = taosArrayGetSize(pBlock->pDataBlock);
20,222,087✔
424
        if (slotId >= numOfCols) {
20,223,896✔
425
          code = taosArrayEnsureCap(pBlock->pDataBlock, slotId + 1);
14,239,523✔
426
          QUERY_CHECK_CODE(code, lino, _end);
14,239,558!
427

428
          for (int32_t k = numOfCols; k < slotId + 1; ++k) {
36,402,640✔
429
            void* tmp = taosArrayPush(pBlock->pDataBlock, &colInfo);
22,161,294✔
430
            QUERY_CHECK_NULL(tmp, code, lino, _end, terrno);
22,163,082!
431
          }
432
        }
433
      } else if (pFuncParam->type == FUNC_PARAM_TYPE_VALUE) {
17,765✔
434
        // do nothing
435
      }
436
    }
437
  }
438

439
  code = blockDataEnsureCapacity(pBlock, pBlock->info.rows);
13,556,480✔
440
  QUERY_CHECK_CODE(code, lino, _end);
13,555,933!
441

442
  for (int32_t i = 0; i < blockDataGetNumOfCols(pBlock); ++i) {
35,715,555✔
443
    SColumnInfoData* pColInfoData = taosArrayGet(pBlock->pDataBlock, i);
22,157,084✔
444
    QUERY_CHECK_NULL(pColInfoData, code, lino, _end, terrno);
22,159,025!
445
    colDataSetNULL(pColInfoData, 0);
446
  }
447
  *ppBlock = pBlock;
13,559,600✔
448

449
_end:
13,555,933✔
450
  if (code != TSDB_CODE_SUCCESS) {
13,555,968!
451
    blockDataDestroy(pBlock);
×
452
    qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(code));
×
453
  }
454
  return code;
13,553,983✔
455
}
456

457
void destroyDataBlockForEmptyInput(bool blockAllocated, SSDataBlock** ppBlock) {
1,305,153,046✔
458
  if (!blockAllocated) {
1,305,153,046✔
459
    return;
1,291,674,214✔
460
  }
461

462
  blockDataDestroy(*ppBlock);
13,478,832✔
463
  *ppBlock = NULL;
13,554,966✔
464
}
465

466
int32_t setExecutionContext(SOperatorInfo* pOperator, int32_t numOfOutput, uint64_t groupId) {
1,357,250,717✔
467
  int32_t           code = TSDB_CODE_SUCCESS;
1,357,250,717✔
468
  SAggOperatorInfo* pAggInfo = pOperator->info;
1,357,250,717✔
469
  if (pAggInfo->groupId != UINT64_MAX && pAggInfo->groupId == groupId) {
1,357,501,870✔
470
    return code;
500,489,276✔
471
  }
472

473
  code = doSetTableGroupOutputBuf(pOperator, numOfOutput, groupId);
857,019,349✔
474

475
  // record the current active group id
476
  pAggInfo->groupId = groupId;
856,811,792✔
477
  return code;
856,888,810✔
478
}
479

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

487
  SResultRowInfo* pResultRowInfo = &pAggInfo->binfo.resultRowInfo;
856,879,154✔
488
  SqlFunctionCtx* pCtx = pOperator->exprSupp.pCtx;
856,917,738✔
489
  int32_t*        rowEntryInfoOffset = pOperator->exprSupp.rowEntryInfoOffset;
856,895,613✔
490

491
  SResultRow* pResultRow =
492
      doSetResultOutBufByKey(pAggInfo->aggSup.pResultBuf, pResultRowInfo, (char*)&groupId, sizeof(groupId), true,
856,861,203✔
493
                             groupId, pTaskInfo, false, &pAggInfo->aggSup, true);
494
  if (pResultRow == NULL || pTaskInfo->code != 0) {
856,879,490!
495
    code = pTaskInfo->code;
36,745✔
496
    lino = __LINE__;
×
497
    goto _end;
×
498
  }
499
  /*
500
   * not assign result buffer yet, add new result buffer
501
   * all group belong to one result set, and each group result has different group id so set the id to be one
502
   */
503
  if (pResultRow->pageId == -1) {
856,848,160!
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);
856,909,252✔
509
  QUERY_CHECK_CODE(code, lino, _end);
856,841,458!
510

511
_end:
856,841,458✔
512
  if (code != TSDB_CODE_SUCCESS) {
856,841,458!
513
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
×
514
  }
515
  return code;
856,825,839✔
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,
1,014,142,972✔
576
                         const char* pKey) {
577
  int32_t code = 0;
1,014,142,972✔
578
  //  _hash_fn_t hashFn = taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY);
579

580
  pAggSup->currentPageId = -1;
1,014,142,972✔
581
  pAggSup->resultRowSize = getResultRowSize(pCtx, numOfOutput);
1,014,361,511✔
582
  pAggSup->keyBuf = taosMemoryCalloc(1, keyBufSize + POINTER_BYTES + sizeof(int64_t));
1,013,939,359✔
583
  pAggSup->pResultRowHashTable = tSimpleHashInit(100, taosFastHash);
1,014,203,663✔
584

585
  if (pAggSup->keyBuf == NULL || pAggSup->pResultRowHashTable == NULL) {
1,013,982,934✔
586
    return terrno;
4,411✔
587
  }
588

589
  uint32_t defaultPgsz = 0;
1,014,033,542✔
590
  int64_t defaultBufsz = 0;
1,014,043,842✔
591
  code = getBufferPgSize(pAggSup->resultRowSize, &defaultPgsz, &defaultBufsz);
1,014,027,521✔
592
  if (code) {
1,013,791,322!
593
    qError("failed to get buff page size, rowSize:%d", pAggSup->resultRowSize);
×
594
    return code;
×
595
  }
596

597
  if (!osTempSpaceAvailable()) {
1,013,791,322!
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);
1,014,167,440✔
604
  if (code != TSDB_CODE_SUCCESS) {
1,014,230,710!
605
    qError("Create agg result buf failed since %s, %s", tstrerror(code), pKey);
×
606
    return code;
×
607
  }
608

609
  return code;
1,014,230,710✔
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,
400,646,844✔
649
                                  SGroupResInfo* pGroupResInfo) {
650
  int32_t         numOfExprs = pSup->numOfExprs;
400,646,844✔
651
  int32_t*        rowEntryOffset = pSup->rowEntryInfoOffset;
400,671,717✔
652
  SqlFunctionCtx* pCtx = pSup->pCtx;
400,669,281✔
653
  int32_t         numOfRows = getNumOfTotalRes(pGroupResInfo);
400,662,470✔
654
  bool            needCleanup = false;
400,664,189✔
655

656
  for (int32_t j = 0; j < numOfExprs; ++j) {
1,350,788,018✔
657
    needCleanup |= pCtx[j].needCleanup;
950,118,193!
658
  }
659
  if (!needCleanup) {
400,669,825✔
660
    return;
396,768,200✔
661
  }
662

663
  for (int32_t i = pGroupResInfo->index; i < numOfRows; i += 1) {
3,901,625!
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,
165,118,500✔
685
                       SGroupResInfo* pGroupResInfo, SSHashObj* pHashmap) {
686
  int32_t         numOfExprs = pSup->numOfExprs;
165,118,500✔
687
  int32_t*        rowEntryOffset = pSup->rowEntryInfoOffset;
165,123,860✔
688
  SqlFunctionCtx* pCtx = pSup->pCtx;
165,122,978✔
689
  bool            needCleanup = false;
165,127,366✔
690
  for (int32_t j = 0; j < numOfExprs; ++j) {
568,260,328✔
691
    needCleanup |= pCtx[j].needCleanup;
403,135,344!
692
  }
693
  if (!needCleanup) {
165,124,984✔
694
    return;
165,101,998✔
695
  }
696

697
  // begin from last iter
698
  void*   pData = pGroupResInfo->dataPos;
22,986✔
699
  int32_t iter = pGroupResInfo->iter;
23,533✔
700
  while ((pData = tSimpleHashIterate(pHashmap, pData, &iter)) != NULL) {
26,230✔
701
    SResultRowPosition* pos = pData;
2,697✔
702

703
    SFilePage* page = getBufPage(pBuf, pos->pageId);
2,697✔
704
    if (page == NULL) {
2,697!
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);
2,697✔
710

711
    for (int32_t j = 0; j < numOfExprs; ++j) {
56,637✔
712
      pCtx[j].resultInfo = getResultEntryInfo(pRow, j, rowEntryOffset);
53,940✔
713
      if (pCtx[j].fpSet.cleanup) {
53,940✔
714
        pCtx[j].fpSet.cleanup(&pCtx[j]);
5,394✔
715
      }
716
    }
717

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

722
void cleanupResultInfo(SExecTaskInfo* pTaskInfo, SExprSupp* pSup, SGroupResInfo* pGroupResInfo,
565,765,838✔
723
                       SAggSupporter *pAggSup, bool cleanGroupResInfo) {
724
  if (cleanGroupResInfo) {
565,765,838✔
725
    cleanupResultInfoInGroupResInfo(pTaskInfo, pSup, pAggSup->pResultBuf, pGroupResInfo);
400,661,582✔
726
  } else {
727
    cleanupResultInfoInHashMap(pTaskInfo, pSup, pAggSup->pResultBuf, pGroupResInfo, pAggSup->pResultRowHashTable);
165,104,256✔
728
  }
729
}
565,773,838✔
730
void cleanupAggSup(SAggSupporter* pAggSup) {
1,014,568,272✔
731
  taosMemoryFreeClear(pAggSup->keyBuf);
1,014,568,272✔
732
  tSimpleHashCleanup(pAggSup->pResultRowHashTable);
1,014,590,056✔
733
  destroyDiskbasedBuf(pAggSup->pResultBuf);
1,014,580,517✔
734
  memset(pAggSup, 0, sizeof(SAggSupporter));
1,014,540,112!
735
}
1,014,540,112✔
736

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

744
  code = doInitAggInfoSup(pAggSup, pSup->pCtx, numOfCols, keyBufSize, pkey);
1,014,091,394✔
745
  if (code != TSDB_CODE_SUCCESS) {
1,014,231,805!
746
    return code;
×
747
  }
748

749
  for (int32_t i = 0; i < numOfCols; ++i) {
2,147,483,647✔
750
    pSup->pCtx[i].hasWindowOrGroup = pSup->hasWindowOrGroup;
2,147,483,647!
751
    if (pState) {
2,147,483,647!
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;
2,147,483,647✔
757
    }
758
  }
759

760
  return TSDB_CODE_SUCCESS;
1,013,889,206✔
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]);
41,040,339✔
782
      char* p = GET_ROWCELL_INTERBUF(pEntryInfo);
41,040,339✔
783

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

786
      SValueNode *valueNode = (SValueNode *)nodesListGetNode(pCtx[k].pExpr->base.pParamList, 0);
41,045,697✔
787
      pEntryInfo->isNullRes = 0;
41,047,031✔
788
      if (TSDB_DATA_TYPE_NULL == valueNode->node.resType.type || valueNode->isNull) {
41,047,031!
789
        pEntryInfo->isNullRes = 1;
×
790
      } else if (IS_VAR_DATA_TYPE(pCtx[k].pExpr->base.resSchema.type)){
41,045,693!
791
        void* v = nodesGetValueFromNode(valueNode);
5,348✔
792
        memcpy(p, v, varDataTLen(v));
×
793
      } else {
794
        memcpy(p, nodesGetValueFromNode(valueNode), pCtx[k].pExpr->base.resSchema.bytes);
41,039,007!
795
      }
796
      
797
      pEntryInfo->numOfRes = 1;
41,045,693✔
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) {
2,697!
824
            pCtx[k].fpSet.cleanup(&pCtx[k]);
2,697✔
825
          }
826
          TAOS_CHECK_EXIT(code);
2,697!
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));
2,697!
839
    taskInfo->code = code;
2,697✔
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) {
27,135,945✔
858
  SAggOperatorInfo* pAgg = pOper->info;
27,135,945✔
859
  SAggPhysiNode*   pAggNode = (SAggPhysiNode*)pOper->pPhyNode;
27,135,945✔
860
  
861
  pOper->status = OP_NOT_OPENED;
27,142,640✔
862
  size_t keyBufSize = sizeof(int64_t) + sizeof(int64_t) + POINTER_BYTES;
27,142,640✔
863
  SExecTaskInfo*  pTaskInfo = pOper->pTaskInfo;
27,142,640✔
864
  cleanupResultInfo(pTaskInfo, &pOper->exprSupp, &pAgg->groupResInfo, &pAgg->aggSup,
27,138,617✔
865
                      pAgg->cleanGroupResInfo);
27,137,282!
866
  cleanupGroupResInfo(&pAgg->groupResInfo);
27,141,293✔
867
  resetBasicOperatorState(&pAgg->binfo);
27,141,293✔
868
  
869
  pAgg->pNewGroupBlock = NULL;
27,142,640✔
870

871
  int32_t code = resetAggSup(&pOper->exprSupp, &pAgg->aggSup, pTaskInfo, pAggNode->pAggFuncs, pAggNode->pGroupKeys,
54,277,713✔
872
    keyBufSize, pTaskInfo->id.str, pTaskInfo->streamInfo.pState, &pTaskInfo->storageAPI.functionStore);
27,142,640✔
873

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

879
  pAgg->groupId = UINT64_MAX;
27,138,617✔
880
  pAgg->cleanGroupResInfo = false;
27,141,291✔
881
  pAgg->hasValidBlock = false;
27,139,954✔
882
  return 0;
27,141,291✔
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