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

taosdata / TDengine / #4021

29 Apr 2025 09:40AM UTC coverage: 62.432% (+0.1%) from 62.312%
#4021

push

travis-ci

web-flow
Merge pull request #30938 from taosdata/fix/taosdCmdArgs

fix: taosd cmd args

155376 of 317399 branches covered (48.95%)

Branch coverage included in aggregate %.

1 of 4 new or added lines in 1 file covered. (25.0%)

410 existing lines in 104 files now uncovered.

240384 of 316504 relevant lines covered (75.95%)

6469011.24 hits per line

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

63.17
/source/libs/executor/src/executorInt.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 "functionMgt.h"
19
#include "os.h"
20
#include "querynodes.h"
21
#include "tfill.h"
22
#include "tname.h"
23

24
#include "tdatablock.h"
25
#include "tmsg.h"
26
#include "ttime.h"
27

28
#include "executorInt.h"
29
#include "index.h"
30
#include "operator.h"
31
#include "query.h"
32
#include "querytask.h"
33
#include "storageapi.h"
34
#include "tcompare.h"
35
#include "thash.h"
36
#include "ttypes.h"
37

38
#define SET_REVERSE_SCAN_FLAG(runtime)    ((runtime)->scanFlag = REVERSE_SCAN)
39
#define GET_FORWARD_DIRECTION_FACTOR(ord) (((ord) == TSDB_ORDER_ASC) ? QUERY_ASC_FORWARD_STEP : QUERY_DESC_FORWARD_STEP)
40

41
#if 0
42
static UNUSED_FUNC void *u_malloc (size_t __size) {
43
  uint32_t v = taosRand();
44

45
  if (v % 1000 <= 0) {
46
    return NULL;
47
  } else {
48
    return taosMemoryMalloc(__size);
49
  }
50
}
51

52
static UNUSED_FUNC void* u_calloc(size_t num, size_t __size) {
53
  uint32_t v = taosRand();
54
  if (v % 1000 <= 0) {
55
    return NULL;
56
  } else {
57
    return taosMemoryCalloc(num, __size);
58
  }
59
}
60

61
static UNUSED_FUNC void* u_realloc(void* p, size_t __size) {
62
  uint32_t v = taosRand();
63
  if (v % 5 <= 1) {
64
    return NULL;
65
  } else {
66
    return taosMemoryRealloc(p, __size);
67
  }
68
}
69

70
#define calloc  u_calloc
71
#define malloc  u_malloc
72
#define realloc u_realloc
73
#endif
74

75
static int32_t setBlockSMAInfo(SqlFunctionCtx* pCtx, SExprInfo* pExpr, SSDataBlock* pBlock);
76

77
static int32_t initCtxOutputBuffer(SqlFunctionCtx* pCtx, int32_t size);
78
static void    doApplyScalarCalculation(SOperatorInfo* pOperator, SSDataBlock* pBlock, int32_t order, int32_t scanFlag);
79

80
static int32_t doSetInputDataBlock(SExprSupp* pExprSup, SSDataBlock* pBlock, int32_t order, int32_t scanFlag,
81
                                   bool createDummyCol);
82
static void    doCopyToSDataBlock(SExecTaskInfo* pTaskInfo, SSDataBlock* pBlock, SExprSupp* pSup, SDiskbasedBuf* pBuf,
83
                                  SGroupResInfo* pGroupResInfo, int32_t threshold, bool ignoreGroup,
84
                                  int64_t minWindowSize);
85

86
SResultRow* getNewResultRow(SDiskbasedBuf* pResultBuf, int32_t* currentPageId, int32_t interBufSize) {
82,527,729✔
87
  SFilePage* pData = NULL;
82,527,729✔
88

89
  // in the first scan, new space needed for results
90
  int32_t pageId = -1;
82,527,729✔
91
  if (*currentPageId == -1) {
82,527,729✔
92
    pData = getNewBufPage(pResultBuf, &pageId);
1,308,277✔
93
    if (pData == NULL) {
1,308,822✔
94
      qError("failed to get buffer, code:%s", tstrerror(terrno));
145!
95
      return NULL;
×
96
    }
97
    pData->num = sizeof(SFilePage);
1,308,677✔
98
  } else {
99
    pData = getBufPage(pResultBuf, *currentPageId);
81,219,452✔
100
    if (pData == NULL) {
81,437,316!
101
      qError("failed to get buffer, code:%s", tstrerror(terrno));
×
102
      return NULL;
×
103
    }
104

105
    pageId = *currentPageId;
81,437,316✔
106

107
    if (pData->num + interBufSize > getBufPageSize(pResultBuf)) {
81,437,316✔
108
      // release current page first, and prepare the next one
109
      releaseBufPage(pResultBuf, pData);
5,888,237✔
110

111
      pData = getNewBufPage(pResultBuf, &pageId);
6,048,966✔
112
      if (pData == NULL) {
6,059,805!
113
        qError("failed to get buffer, code:%s", tstrerror(terrno));
×
114
        return NULL;
×
115
      }
116
      pData->num = sizeof(SFilePage);
6,059,805✔
117
    }
118
  }
119

120
  if (pData == NULL) {
82,780,589!
121
    return NULL;
×
122
  }
123

124
  setBufPageDirty(pData, true);
82,780,589✔
125

126
  // set the number of rows in current disk page
127
  SResultRow* pResultRow = (SResultRow*)((char*)pData + pData->num);
82,562,930✔
128

129
  memset((char*)pResultRow, 0, interBufSize);
82,562,930✔
130
  pResultRow->pageId = pageId;
82,562,930✔
131
  pResultRow->offset = (int32_t)pData->num;
82,562,930✔
132

133
  *currentPageId = pageId;
82,562,930✔
134
  pData->num += interBufSize;
82,562,930✔
135
  return pResultRow;
82,562,930✔
136
}
137

138
/**
139
 * the struct of key in hash table
140
 * +----------+---------------+
141
 * | group id |   key data    |
142
 * | 8 bytes  | actual length |
143
 * +----------+---------------+
144
 */
145
SResultRow* doSetResultOutBufByKey(SDiskbasedBuf* pResultBuf, SResultRowInfo* pResultRowInfo, char* pData,
118,638,746✔
146
                                   int32_t bytes, bool masterscan, uint64_t groupId, SExecTaskInfo* pTaskInfo,
147
                                   bool isIntervalQuery, SAggSupporter* pSup, bool keepGroup) {
148
  SET_RES_WINDOW_KEY(pSup->keyBuf, pData, bytes, groupId);
118,638,746✔
149
  if (!keepGroup) {
118,638,746✔
150
    *(uint64_t*)pSup->keyBuf = calcGroupId(pSup->keyBuf, GET_RES_WINDOW_KEY_LEN(bytes));
12,732,716✔
151
  }
152

153
  SResultRowPosition* p1 =
154
      (SResultRowPosition*)tSimpleHashGet(pSup->pResultRowHashTable, pSup->keyBuf, GET_RES_WINDOW_KEY_LEN(bytes));
118,894,199✔
155

156
  SResultRow* pResult = NULL;
120,181,304✔
157

158
  // in case of repeat scan/reverse scan, no new time window added.
159
  if (isIntervalQuery) {
120,181,304✔
160
    if (p1 != NULL) {  // the *p1 may be NULL in case of sliding+offset exists.
105,439,381✔
161
      pResult = getResultRowByPos(pResultBuf, p1, true);
28,649,765✔
162
      if (pResult == NULL) {
28,649,765!
163
        pTaskInfo->code = terrno;
×
164
        return NULL;
×
165
      }
166

167
      if (pResult->pageId != p1->pageId || pResult->offset != p1->offset) {
28,649,765!
168
        terrno = TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR;
11,952✔
169
        pTaskInfo->code = terrno;
×
170
        return NULL;
×
171
      }
172
    }
173
  } else {
174
    // In case of group by column query, the required SResultRow object must be existInCurrentResusltRowInfo in the
175
    // pResultRowInfo object.
176
    if (p1 != NULL) {
14,741,923✔
177
      // todo
178
      pResult = getResultRowByPos(pResultBuf, p1, true);
6,350,519✔
179
      if (NULL == pResult) {
6,350,519!
180
        pTaskInfo->code = terrno;
×
181
        return NULL;
×
182
      }
183

184
      if (pResult->pageId != p1->pageId || pResult->offset != p1->offset) {
6,350,519!
185
        terrno = TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR;
×
186
        pTaskInfo->code = terrno;
×
187
        return NULL;
24,508✔
188
      }
189
    }
190
  }
191

192
  // 1. close current opened time window
193
  if (pResultRowInfo->cur.pageId != -1 && ((pResult == NULL) || (pResult->pageId != pResultRowInfo->cur.pageId))) {
119,671,085✔
194
    SResultRowPosition pos = pResultRowInfo->cur;
85,600,764✔
195
    SFilePage*         pPage = getBufPage(pResultBuf, pos.pageId);
85,600,764✔
196
    if (pPage == NULL) {
84,050,814!
197
      qError("failed to get buffer, code:%s, %s", tstrerror(terrno), GET_TASKID(pTaskInfo));
×
198
      pTaskInfo->code = terrno;
×
199
      return NULL;
×
200
    }
201
    releaseBufPage(pResultBuf, pPage);
84,050,814✔
202
  }
203

204
  // allocate a new buffer page
205
  if (pResult == NULL) {
117,427,946✔
206
    pResult = getNewResultRow(pResultBuf, &pSup->currentPageId, pSup->resultRowSize);
82,546,740✔
207
    if (pResult == NULL) {
82,868,150!
208
      pTaskInfo->code = terrno;
×
209
      return NULL;
×
210
    }
211

212
    // add a new result set for a new group
213
    SResultRowPosition pos = {.pageId = pResult->pageId, .offset = pResult->offset};
82,868,150✔
214
    int32_t code = tSimpleHashPut(pSup->pResultRowHashTable, pSup->keyBuf, GET_RES_WINDOW_KEY_LEN(bytes), &pos,
82,868,150✔
215
                                  sizeof(SResultRowPosition));
216
    if (code != TSDB_CODE_SUCCESS) {
84,621,399!
217
      qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(code));
×
218
      pTaskInfo->code = code;
×
219
      return NULL;
×
220
    }
221
  }
222

223
  // 2. set the new time window to be the new active time window
224
  pResultRowInfo->cur = (SResultRowPosition){.pageId = pResult->pageId, .offset = pResult->offset};
119,605,354✔
225

226
  // too many time window in query
227
  if (pTaskInfo->execModel == OPTR_EXEC_MODEL_BATCH &&
238,493,892!
228
      tSimpleHashGetSize(pSup->pResultRowHashTable) > MAX_INTERVAL_TIME_WINDOW) {
119,536,476✔
229
    pTaskInfo->code = TSDB_CODE_QRY_TOO_MANY_TIMEWINDOW;
×
230
    return NULL;
×
231
  }
232

233
  return pResult;
118,957,416✔
234
}
235

236
//  query_range_start, query_range_end, window_duration, window_start, window_end
237
int32_t initExecTimeWindowInfo(SColumnInfoData* pColData, STimeWindow* pQueryWindow) {
95,658✔
238
  pColData->info.type = TSDB_DATA_TYPE_TIMESTAMP;
95,658✔
239
  pColData->info.bytes = sizeof(int64_t);
95,658✔
240

241
  int32_t code = colInfoDataEnsureCapacity(pColData, 5, false);
95,658✔
242
  if (code != TSDB_CODE_SUCCESS) {
95,749!
243
    return code;
×
244
  }
245
  colDataSetInt64(pColData, 0, &pQueryWindow->skey);
95,749✔
246
  colDataSetInt64(pColData, 1, &pQueryWindow->ekey);
95,749✔
247

248
  int64_t interval = 0;
95,749✔
249
  colDataSetInt64(pColData, 2, &interval);  // this value may be variable in case of 'n' and 'y'.
250
  colDataSetInt64(pColData, 3, &pQueryWindow->skey);
95,749✔
251
  colDataSetInt64(pColData, 4, &pQueryWindow->ekey);
95,749✔
252
  return TSDB_CODE_SUCCESS;
95,749✔
253
}
254

255
static int32_t doSetInputDataBlockInfo(SExprSupp* pExprSup, SSDataBlock* pBlock, int32_t order, int32_t scanFlag) {
16,262✔
256
  int32_t         code = TSDB_CODE_SUCCESS;
16,262✔
257
  int32_t         lino = 0;
16,262✔
258
  SqlFunctionCtx* pCtx = pExprSup->pCtx;
16,262✔
259
  for (int32_t i = 0; i < pExprSup->numOfExprs; ++i) {
32,538✔
260
    pCtx[i].order = order;
16,270✔
261
    pCtx[i].input.numOfRows = pBlock->info.rows;
16,270✔
262
    code = setBlockSMAInfo(&pCtx[i], &pExprSup->pExprInfo[i], pBlock);
16,270✔
263
    QUERY_CHECK_CODE(code, lino, _end);
16,276!
264
    pCtx[i].pSrcBlock = pBlock;
16,276✔
265
    pCtx[i].scanFlag = scanFlag;
16,276✔
266
  }
267

268
_end:
16,268✔
269
  if (code != TSDB_CODE_SUCCESS) {
16,268!
270
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
×
271
  }
272
  return code;
16,267✔
273
}
274

275
int32_t setInputDataBlock(SExprSupp* pExprSup, SSDataBlock* pBlock, int32_t order, int32_t scanFlag,
8,315,774✔
276
                          bool createDummyCol) {
277
  if (pBlock->pBlockAgg != NULL) {
8,315,774✔
278
    return doSetInputDataBlockInfo(pExprSup, pBlock, order, scanFlag);
16,261✔
279
  } else {
280
    return doSetInputDataBlock(pExprSup, pBlock, order, scanFlag, createDummyCol);
8,299,513✔
281
  }
282
}
283

284
static int32_t doCreateConstantValColumnInfo(SInputColumnInfoData* pInput, SFunctParam* pFuncParam, int32_t paramIndex,
×
285
                                             int32_t numOfRows) {
286
  int32_t          code = TSDB_CODE_SUCCESS;
×
287
  int32_t          lino = 0;
×
288
  SColumnInfoData* pColInfo = NULL;
×
289
  if (pInput->pData[paramIndex] == NULL) {
×
290
    pColInfo = taosMemoryCalloc(1, sizeof(SColumnInfoData));
×
291
    QUERY_CHECK_NULL(pColInfo, code, lino, _end, terrno);
×
292

293
    // Set the correct column info (data type and bytes)
294
    pColInfo->info.type = pFuncParam->param.nType;
×
295
    pColInfo->info.bytes = pFuncParam->param.nLen;
×
296

297
    pInput->pData[paramIndex] = pColInfo;
×
298
  } else {
299
    pColInfo = pInput->pData[paramIndex];
×
300
  }
301

302
  code = colInfoDataEnsureCapacity(pColInfo, numOfRows, false);
×
303
  QUERY_CHECK_CODE(code, lino, _end);
×
304

305
  int8_t type = pFuncParam->param.nType;
×
306
  if (type == TSDB_DATA_TYPE_BIGINT || type == TSDB_DATA_TYPE_UBIGINT) {
×
307
    int64_t v = pFuncParam->param.i;
×
308
    for (int32_t i = 0; i < numOfRows; ++i) {
×
309
      colDataSetInt64(pColInfo, i, &v);
×
310
    }
311
  } else if (type == TSDB_DATA_TYPE_DOUBLE) {
×
312
    double v = pFuncParam->param.d;
×
313
    for (int32_t i = 0; i < numOfRows; ++i) {
×
314
      colDataSetDouble(pColInfo, i, &v);
×
315
    }
316
  } else if (type == TSDB_DATA_TYPE_VARCHAR || type == TSDB_DATA_TYPE_GEOMETRY) {
×
317
    char* tmp = taosMemoryMalloc(pFuncParam->param.nLen + VARSTR_HEADER_SIZE);
×
318
    QUERY_CHECK_NULL(tmp, code, lino, _end, terrno);
×
319

320
    STR_WITH_SIZE_TO_VARSTR(tmp, pFuncParam->param.pz, pFuncParam->param.nLen);
×
321
    for (int32_t i = 0; i < numOfRows; ++i) {
×
322
      code = colDataSetVal(pColInfo, i, tmp, false);
×
323
      QUERY_CHECK_CODE(code, lino, _end);
×
324
    }
325
    taosMemoryFree(tmp);
×
326
  }
327

328
_end:
×
329
  if (code != TSDB_CODE_SUCCESS) {
×
330
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
×
331
  }
332
  return code;
×
333
}
334

335
static int32_t doSetInputDataBlock(SExprSupp* pExprSup, SSDataBlock* pBlock, int32_t order, int32_t scanFlag,
8,299,058✔
336
                                   bool createDummyCol) {
337
  int32_t         code = TSDB_CODE_SUCCESS;
8,299,058✔
338
  int32_t         lino = 0;
8,299,058✔
339
  SqlFunctionCtx* pCtx = pExprSup->pCtx;
8,299,058✔
340

341
  for (int32_t i = 0; i < pExprSup->numOfExprs; ++i) {
47,850,727✔
342
    pCtx[i].order = order;
39,550,177✔
343
    pCtx[i].input.numOfRows = pBlock->info.rows;
39,550,177✔
344

345
    pCtx[i].pSrcBlock = pBlock;
39,550,177✔
346
    pCtx[i].scanFlag = scanFlag;
39,550,177✔
347

348
    SInputColumnInfoData* pInput = &pCtx[i].input;
39,550,177✔
349
    pInput->uid = pBlock->info.id.uid;
39,550,177✔
350
    pInput->colDataSMAIsSet = false;
39,550,177✔
351

352
    SExprInfo* pOneExpr = &pExprSup->pExprInfo[i];
39,550,177✔
353
    bool       hasPk = pOneExpr->pExpr->nodeType == QUERY_NODE_FUNCTION && pOneExpr->pExpr->_function.pFunctNode->hasPk;
39,550,177✔
354
    pCtx[i].hasPrimaryKey = hasPk;
39,550,177✔
355

356
    int16_t tsParamIdx = (!hasPk) ? pOneExpr->base.numOfParams - 1 : pOneExpr->base.numOfParams - 2;
39,550,177✔
357
    int16_t pkParamIdx = pOneExpr->base.numOfParams - 1;
39,550,177✔
358

359
    for (int32_t j = 0; j < pOneExpr->base.numOfParams; ++j) {
81,994,820✔
360
      SFunctParam* pFuncParam = &pOneExpr->base.pParam[j];
42,443,151✔
361
      if (pFuncParam->type == FUNC_PARAM_TYPE_COLUMN) {
42,443,151✔
362
        int32_t slotId = pFuncParam->pCol->slotId;
39,403,567✔
363
        pInput->pData[j] = taosArrayGet(pBlock->pDataBlock, slotId);
39,403,567✔
364
        pInput->totalRows = pBlock->info.rows;
39,401,273✔
365
        pInput->numOfRows = pBlock->info.rows;
39,401,273✔
366
        pInput->startRowIndex = 0;
39,401,273✔
367
        pInput->blankFill = pBlock->info.blankFill;
39,401,273✔
368

369
        // NOTE: the last parameter is the primary timestamp column
370
        // todo: refactor this
371

372
        if (fmIsImplicitTsFunc(pCtx[i].functionId) && (j == tsParamIdx)) {
39,401,273✔
373
          pInput->pPTS = pInput->pData[j];  // in case of merge function, this is not always the ts column data.
3,117,967✔
374
        }
375
        if (hasPk && (j == pkParamIdx)) {
39,405,059✔
376
          pInput->pPrimaryKey = pInput->pData[j];
763,482✔
377
        }
378
        QUERY_CHECK_CONDITION((pInput->pData[j] != NULL), code, lino, _end, TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR);
39,405,059!
379
      } else if (pFuncParam->type == FUNC_PARAM_TYPE_VALUE) {
3,039,584✔
380
        // todo avoid case: top(k, 12), 12 is the value parameter.
381
        // sum(11), 11 is also the value parameter.
382
        if (createDummyCol && pOneExpr->base.numOfParams == 1) {
1,446,829!
383
          pInput->totalRows = pBlock->info.rows;
×
384
          pInput->numOfRows = pBlock->info.rows;
×
385
          pInput->startRowIndex = 0;
×
386
          pInput->blankFill = pBlock->info.blankFill;
×
387

388
          code = doCreateConstantValColumnInfo(pInput, pFuncParam, j, pBlock->info.rows);
×
389
          QUERY_CHECK_CODE(code, lino, _end);
×
390
        }
391
      }
392
    }
393
  }
394

395
_end:
8,300,550✔
396
  if (code != TSDB_CODE_SUCCESS) {
8,300,550!
397
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
×
398
  }
399
  return code;
8,302,314✔
400
}
401

402
bool functionNeedToExecute(SqlFunctionCtx* pCtx) {
493,067,096✔
403
  struct SResultRowEntryInfo* pResInfo = GET_RES_INFO(pCtx);
493,067,096✔
404

405
  // in case of timestamp column, always generated results.
406
  int32_t functionId = pCtx->functionId;
493,067,096✔
407
  if (functionId == -1) {
493,067,096✔
408
    return false;
42,176,497✔
409
  }
410

411
  if (pCtx->scanFlag == PRE_SCAN) {
450,890,599✔
412
    return fmIsRepeatScanFunc(pCtx->functionId);
19,291✔
413
  }
414

415
  if (isRowEntryCompleted(pResInfo)) {
450,871,308!
UNCOV
416
    return false;
×
417
  }
418

419
  return true;
450,871,308✔
420
}
421

422
static int32_t doCreateConstantValColumnSMAInfo(SInputColumnInfoData* pInput, SFunctParam* pFuncParam, int32_t type,
×
423
                                                int32_t paramIndex, int32_t numOfRows) {
424
  if (pInput->pData[paramIndex] == NULL) {
×
425
    pInput->pData[paramIndex] = taosMemoryCalloc(1, sizeof(SColumnInfoData));
×
426
    if (pInput->pData[paramIndex] == NULL) {
×
427
      return terrno;
×
428
    }
429

430
    // Set the correct column info (data type and bytes)
431
    pInput->pData[paramIndex]->info.type = type;
×
432
    pInput->pData[paramIndex]->info.bytes = tDataTypes[type].bytes;
×
433
  }
434

435
  SColumnDataAgg* da = NULL;
×
436
  if (pInput->pColumnDataAgg[paramIndex] == NULL) {
×
437
    da = taosMemoryCalloc(1, sizeof(SColumnDataAgg));
×
438
    if (!da) {
×
439
      return terrno;
×
440
    }
441
    pInput->pColumnDataAgg[paramIndex] = da;
×
442
  } else {
443
    da = pInput->pColumnDataAgg[paramIndex];
×
444
  }
445

446
  if (type == TSDB_DATA_TYPE_BIGINT) {
×
447
    int64_t v = pFuncParam->param.i;
×
448
    *da = (SColumnDataAgg){.numOfNull = 0, .min = v, .max = v, .sum = v * numOfRows};
×
449
  } else if (type == TSDB_DATA_TYPE_DOUBLE) {
×
450
    double v = pFuncParam->param.d;
×
451
    *da = (SColumnDataAgg){.numOfNull = 0};
×
452

453
    *(double*)&da->min = v;
×
454
    *(double*)&da->max = v;
×
455
    *(double*)&da->sum = v * numOfRows;
×
456
  } else if (type == TSDB_DATA_TYPE_BOOL) {  // todo validate this data type
×
457
    bool v = pFuncParam->param.i;
×
458

459
    *da = (SColumnDataAgg){.numOfNull = 0};
×
460
    *(bool*)&da->min = 0;
×
461
    *(bool*)&da->max = v;
×
462
    *(bool*)&da->sum = v * numOfRows;
×
463
  } else if (type == TSDB_DATA_TYPE_TIMESTAMP) {
×
464
    // do nothing
465
  } else {
466
    qError("invalid constant type for sma info");
×
467
  }
468

469
  return TSDB_CODE_SUCCESS;
×
470
}
471

472
int32_t setBlockSMAInfo(SqlFunctionCtx* pCtx, SExprInfo* pExprInfo, SSDataBlock* pBlock) {
16,273✔
473
  int32_t code = TSDB_CODE_SUCCESS;
16,273✔
474
  int32_t lino = 0;
16,273✔
475
  int32_t numOfRows = pBlock->info.rows;
16,273✔
476

477
  SInputColumnInfoData* pInput = &pCtx->input;
16,273✔
478
  pInput->numOfRows = numOfRows;
16,273✔
479
  pInput->totalRows = numOfRows;
16,273✔
480

481
  if (pBlock->pBlockAgg != NULL) {
16,273!
482
    pInput->colDataSMAIsSet = true;
16,274✔
483

484
    for (int32_t j = 0; j < pExprInfo->base.numOfParams; ++j) {
32,553✔
485
      SFunctParam* pFuncParam = &pExprInfo->base.pParam[j];
16,274✔
486

487
      if (pFuncParam->type == FUNC_PARAM_TYPE_COLUMN) {
16,274!
488
        int32_t slotId = pFuncParam->pCol->slotId;
16,274✔
489
        pInput->pColumnDataAgg[j] = &pBlock->pBlockAgg[slotId];
16,274✔
490
        if (pInput->pColumnDataAgg[j]->colId == -1) {
16,274✔
491
          pInput->colDataSMAIsSet = false;
3,105✔
492
        }
493

494
        // Here we set the column info data since the data type for each column data is required, but
495
        // the data in the corresponding SColumnInfoData will not be used.
496
        pInput->pData[j] = taosArrayGet(pBlock->pDataBlock, slotId);
16,274✔
497
      } else if (pFuncParam->type == FUNC_PARAM_TYPE_VALUE) {
×
498
        code = doCreateConstantValColumnSMAInfo(pInput, pFuncParam, pFuncParam->param.nType, j, pBlock->info.rows);
×
499
        QUERY_CHECK_CODE(code, lino, _end);
×
500
      }
501
    }
502
  } else {
503
    pInput->colDataSMAIsSet = false;
×
504
  }
505

506
_end:
16,278✔
507
  if (code != TSDB_CODE_SUCCESS) {
16,278!
508
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
×
509
  }
510
  return code;
16,278✔
511
}
512

513
/////////////////////////////////////////////////////////////////////////////////////////////
514
STimeWindow getAlignQueryTimeWindow(const SInterval* pInterval, int64_t key) {
989,772✔
515
  STimeWindow win = {0};
989,772✔
516
  win.skey = taosTimeTruncate(key, pInterval);
989,772✔
517

518
  /*
519
   * if the realSkey > INT64_MAX - pInterval->interval, the query duration between
520
   * realSkey and realEkey must be less than one interval.Therefore, no need to adjust the query ranges.
521
   */
522
  win.ekey = taosTimeGetIntervalEnd(win.skey, pInterval);
989,778✔
523
  if (win.ekey < win.skey) {
989,931✔
524
    win.ekey = INT64_MAX;
1,267✔
525
  }
526

527
  return win;
989,931✔
528
}
529

530
int32_t setResultRowInitCtx(SResultRow* pResult, SqlFunctionCtx* pCtx, int32_t numOfOutput,
137,742,343✔
531
                            int32_t* rowEntryInfoOffset) {
532
  bool init = false;
137,742,343✔
533
  for (int32_t i = 0; i < numOfOutput; ++i) {
815,852,395✔
534
    pCtx[i].resultInfo = getResultEntryInfo(pResult, i, rowEntryInfoOffset);
679,647,296✔
535
    if (init) {
679,538,165✔
536
      continue;
99,164,945✔
537
    }
538

539
    struct SResultRowEntryInfo* pResInfo = pCtx[i].resultInfo;
580,373,220✔
540
    if (isRowEntryCompleted(pResInfo) && isRowEntryInitialized(pResInfo)) {
580,373,220!
UNCOV
541
      continue;
×
542
    }
543

544
    if (pCtx[i].isPseudoFunc) {
580,373,220✔
545
      continue;
190,093,030✔
546
    }
547

548
    if (!pResInfo->initialized) {
390,280,190✔
549
      if (pCtx[i].functionId != -1) {
362,085,864✔
550
        int32_t code = pCtx[i].fpSet.init(&pCtx[i], pResInfo);
330,126,809✔
551
        if (code != TSDB_CODE_SUCCESS && fmIsUserDefinedFunc(pCtx[i].functionId)) {
330,363,629!
552
          pResInfo->initialized = false;
1,664,933✔
553
          qError("failed to initialize udf, funcId:%d error:%s", pCtx[i].functionId, tstrerror(code));
1,664,933!
554
          return TSDB_CODE_UDF_FUNC_EXEC_FAILURE;
×
555
        } else if (code != TSDB_CODE_SUCCESS) {
328,698,696!
556
          qError("failed to initialize function context, funcId:%d error:%s", pCtx[i].functionId, tstrerror(code));
×
557
          return code;
×
558
        }
559
      } else {
560
        pResInfo->initialized = true;
31,959,055✔
561
      }
562
    } else {
563
      init = true;
28,194,326✔
564
    }
565
  }
566
  return TSDB_CODE_SUCCESS;
136,205,099✔
567
}
568

569
void clearResultRowInitFlag(SqlFunctionCtx* pCtx, int32_t numOfOutput) {
645✔
570
  for (int32_t i = 0; i < numOfOutput; ++i) {
2,527✔
571
    SResultRowEntryInfo* pResInfo = pCtx[i].resultInfo;
1,882✔
572
    if (pResInfo == NULL) {
1,882!
573
      continue;
×
574
    }
575

576
    pResInfo->initialized = false;
1,882✔
577
    pResInfo->numOfRes = 0;
1,882✔
578
    pResInfo->isNullRes = 0;
1,882✔
579
    pResInfo->complete = false;
1,882✔
580
  }
581
}
645✔
582

583
int32_t doFilter(SSDataBlock* pBlock, SFilterInfo* pFilterInfo, SColMatchInfo* pColMatchInfo) {
10,334,485✔
584
  int32_t code = TSDB_CODE_SUCCESS;
10,334,485✔
585
  int32_t lino = 0;
10,334,485✔
586
  if (pFilterInfo == NULL || pBlock->info.rows == 0) {
10,334,485✔
587
    return TSDB_CODE_SUCCESS;
9,363,026✔
588
  }
589

590
  SFilterColumnParam param1 = {.numOfCols = taosArrayGetSize(pBlock->pDataBlock), .pDataBlock = pBlock->pDataBlock};
971,459✔
591
  SColumnInfoData*   p = NULL;
971,429✔
592

593
  code = filterSetDataFromSlotId(pFilterInfo, &param1);
971,429✔
594
  QUERY_CHECK_CODE(code, lino, _err);
971,314!
595

596
  int32_t status = 0;
971,314✔
597
  code = filterExecute(pFilterInfo, pBlock, &p, NULL, param1.numOfCols, &status);
971,314✔
598
  QUERY_CHECK_CODE(code, lino, _err);
971,260✔
599

600
  code = extractQualifiedTupleByFilterResult(pBlock, p, status);
971,259✔
601
  QUERY_CHECK_CODE(code, lino, _err);
971,190!
602

603
  if (pColMatchInfo != NULL) {
971,190✔
604
    size_t size = taosArrayGetSize(pColMatchInfo->pList);
670,584✔
605
    for (int32_t i = 0; i < size; ++i) {
674,865✔
606
      SColMatchItem* pInfo = taosArrayGet(pColMatchInfo->pList, i);
673,436✔
607
      QUERY_CHECK_NULL(pInfo, code, lino, _err, terrno);
673,447!
608
      if (pInfo->colId == PRIMARYKEY_TIMESTAMP_COL_ID) {
673,447✔
609
        SColumnInfoData* pColData = taosArrayGet(pBlock->pDataBlock, pInfo->dstSlotId);
669,286✔
610
        QUERY_CHECK_NULL(pColData, code, lino, _err, terrno);
669,221!
611
        if (pColData->info.type == TSDB_DATA_TYPE_TIMESTAMP) {
669,309✔
612
          code = blockDataUpdateTsWindow(pBlock, pInfo->dstSlotId);
669,249✔
613
          QUERY_CHECK_CODE(code, lino, _err);
669,251!
614
          break;
669,251✔
615
        }
616
      }
617
    }
618
  }
619
  code = blockDataCheck(pBlock);
971,286✔
620
  QUERY_CHECK_CODE(code, lino, _err);
971,278!
621
_err:
971,278✔
622
  if (code != TSDB_CODE_SUCCESS) {
971,279✔
623
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
1!
624
  }
625
  colDataDestroy(p);
971,279✔
626
  taosMemoryFree(p);
971,590!
627
  return code;
971,689✔
628
}
629

630
int32_t extractQualifiedTupleByFilterResult(SSDataBlock* pBlock, const SColumnInfoData* p, int32_t status) {
971,217✔
631
  int32_t code = TSDB_CODE_SUCCESS;
971,217✔
632
  int8_t* pIndicator = (int8_t*)p->pData;
971,217✔
633
  if (status == FILTER_RESULT_ALL_QUALIFIED) {
971,217✔
634
    // here nothing needs to be done
635
  } else if (status == FILTER_RESULT_NONE_QUALIFIED) {
455,540✔
636
    code = trimDataBlock(pBlock, pBlock->info.rows, NULL);
140,735✔
637
    pBlock->info.rows = 0;
140,706✔
638
  } else if (status == FILTER_RESULT_PARTIAL_QUALIFIED) {
314,805!
639
    code = trimDataBlock(pBlock, pBlock->info.rows, (bool*)pIndicator);
314,885✔
640
  } else {
641
    qError("unknown filter result type: %d", status);
×
642
  }
643
  return code;
971,389✔
644
}
645

646
void doUpdateNumOfRows(SqlFunctionCtx* pCtx, SResultRow* pRow, int32_t numOfExprs, const int32_t* rowEntryOffset) {
103,326,301✔
647
  bool returnNotNull = false;
103,326,301✔
648
  for (int32_t j = 0; j < numOfExprs; ++j) {
616,185,902✔
649
    SResultRowEntryInfo* pResInfo = getResultEntryInfo(pRow, j, rowEntryOffset);
512,613,342✔
650
    if (!isRowEntryInitialized(pResInfo)) {
512,859,601✔
651
      continue;
143,423,461✔
652
    } else {
653
    }
654

655
    if (pRow->numOfRows < pResInfo->numOfRes) {
369,436,140✔
656
      pRow->numOfRows = pResInfo->numOfRes;
100,515,907✔
657
    }
658

659
    if (pCtx[j].isNotNullFunc) {
369,436,140✔
660
      returnNotNull = true;
109,437,472✔
661
    }
662
  }
663
  // if all expr skips all blocks, e.g. all null inputs for max function, output one row in final result.
664
  //  except for first/last, which require not null output, output no rows
665
  if (pRow->numOfRows == 0 && !returnNotNull) {
103,572,560✔
666
    pRow->numOfRows = 1;
48,163✔
667
  }
668
}
103,572,560✔
669

670
int32_t copyResultrowToDataBlock(SExprInfo* pExprInfo, int32_t numOfExprs, SResultRow* pRow, SqlFunctionCtx* pCtx,
94,961,282✔
671
                                 SSDataBlock* pBlock, const int32_t* rowEntryOffset, SExecTaskInfo* pTaskInfo) {
672
  int32_t code = TSDB_CODE_SUCCESS;
94,961,282✔
673
  int32_t lino = 0;
94,961,282✔
674
  for (int32_t j = 0; j < numOfExprs; ++j) {
541,007,123✔
675
    int32_t slotId = pExprInfo[j].base.resSchema.slotId;
445,121,391✔
676

677
    pCtx[j].resultInfo = getResultEntryInfo(pRow, j, rowEntryOffset);
445,121,391✔
678
    if (pCtx[j].fpSet.finalize) {
445,740,248✔
679
      if (strcmp(pCtx[j].pExpr->pExpr->_function.functionName, "_group_key") == 0 ||
294,719,020✔
680
          strcmp(pCtx[j].pExpr->pExpr->_function.functionName, "_group_const_value") == 0) {
200,304,383✔
681
        // for groupkey along with functions that output multiple lines(e.g. Histogram)
682
        // need to match groupkey result for each output row of that function.
683
        if (pCtx[j].resultInfo->numOfRes != 0) {
94,666,007!
684
          pCtx[j].resultInfo->numOfRes = pRow->numOfRows;
95,621,212✔
685
        }
686
      }
687

688
      code = blockDataEnsureCapacity(pBlock, pBlock->info.rows + pCtx[j].resultInfo->numOfRes);
294,719,020✔
689
      QUERY_CHECK_CODE(code, lino, _end);
294,577,832!
690

691
      code = pCtx[j].fpSet.finalize(&pCtx[j], pBlock);
294,577,832✔
692
      if (TSDB_CODE_SUCCESS != code) {
297,153,325!
693
        qError("%s build result data block error, code %s", GET_TASKID(pTaskInfo), tstrerror(code));
×
694
        QUERY_CHECK_CODE(code, lino, _end);
×
695
      }
696
    } else if (strcmp(pCtx[j].pExpr->pExpr->_function.functionName, "_select_value") == 0) {
151,021,228!
697
      // do nothing
698
    } else {
699
      // expand the result into multiple rows. E.g., _wstart, top(k, 20)
700
      // the _wstart needs to copy to 20 following rows, since the results of top-k expands to 20 different rows.
701
      SColumnInfoData* pColInfoData = taosArrayGet(pBlock->pDataBlock, slotId);
156,379,356✔
702
      QUERY_CHECK_NULL(pColInfoData, code, lino, _end, terrno);
153,530,551!
703
      char*            in = GET_ROWCELL_INTERBUF(pCtx[j].resultInfo);
153,648,246✔
704
      for (int32_t k = 0; k < pRow->numOfRows; ++k) {
309,432,924✔
705
        code = colDataSetValOrCover(pColInfoData, pBlock->info.rows + k, in, pCtx[j].resultInfo->isNullRes);
153,322,160✔
706
        QUERY_CHECK_CODE(code, lino, _end);
155,784,678!
707
      }
708
    }
709
  }
710

711
_end:
95,885,732✔
712
  if (code != TSDB_CODE_SUCCESS) {
95,885,732!
713
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
×
714
  }
715
  return code;
96,373,793✔
716
}
717

718
// todo refactor. SResultRow has direct pointer in miainfo
719
void finalizeResultRows(SDiskbasedBuf* pBuf, SResultRowPosition* resultRowPosition, SExprSupp* pSup,
13,248,746✔
720
                        SSDataBlock* pBlock, SExecTaskInfo* pTaskInfo) {
721
  SFilePage* page = getBufPage(pBuf, resultRowPosition->pageId);
13,248,746✔
722
  if (page == NULL) {
13,250,738!
723
    qError("failed to get buffer, code:%s, %s", tstrerror(terrno), GET_TASKID(pTaskInfo));
×
724
    T_LONG_JMP(pTaskInfo->env, terrno);
×
725
  }
726

727
  SResultRow* pRow = (SResultRow*)((char*)page + resultRowPosition->offset);
13,250,738✔
728

729
  SqlFunctionCtx* pCtx = pSup->pCtx;
13,250,738✔
730
  SExprInfo*      pExprInfo = pSup->pExprInfo;
13,250,738✔
731
  const int32_t*  rowEntryOffset = pSup->rowEntryInfoOffset;
13,250,738✔
732

733
  doUpdateNumOfRows(pCtx, pRow, pSup->numOfExprs, rowEntryOffset);
13,250,738✔
734
  if (pRow->numOfRows == 0) {
13,234,447✔
735
    releaseBufPage(pBuf, page);
1,467✔
736
    return;
×
737
  }
738

739
  int32_t size = pBlock->info.capacity;
13,232,980✔
740
  while (pBlock->info.rows + pRow->numOfRows > size) {
13,237,390✔
741
    size = size * 1.25;
4,410✔
742
  }
743

744
  int32_t code = blockDataEnsureCapacity(pBlock, size);
13,232,980✔
745
  if (TAOS_FAILED(code)) {
13,234,262!
746
    releaseBufPage(pBuf, page);
×
747
    qError("%s ensure result data capacity failed, code %s", GET_TASKID(pTaskInfo), tstrerror(code));
×
748
    T_LONG_JMP(pTaskInfo->env, code);
×
749
  }
750

751
  code = copyResultrowToDataBlock(pExprInfo, pSup->numOfExprs, pRow, pCtx, pBlock, rowEntryOffset, pTaskInfo);
13,234,262✔
752
  if (TAOS_FAILED(code)) {
13,221,251!
753
    releaseBufPage(pBuf, page);
×
754
    qError("%s copy result row to datablock failed, code %s", GET_TASKID(pTaskInfo), tstrerror(code));
×
755
    T_LONG_JMP(pTaskInfo->env, code);
×
756
  }
757

758
  releaseBufPage(pBuf, page);
13,221,251✔
759
  pBlock->info.rows += pRow->numOfRows;
13,216,812✔
760
}
761

762
void doCopyToSDataBlockByHash(SExecTaskInfo* pTaskInfo, SSDataBlock* pBlock, SExprSupp* pSup, SDiskbasedBuf* pBuf,
1,958,841✔
763
                              SGroupResInfo* pGroupResInfo, SSHashObj* pHashmap, int32_t threshold, bool ignoreGroup) {
764
  int32_t         code = TSDB_CODE_SUCCESS;
1,958,841✔
765
  int32_t         lino = 0;
1,958,841✔
766
  SExprInfo*      pExprInfo = pSup->pExprInfo;
1,958,841✔
767
  int32_t         numOfExprs = pSup->numOfExprs;
1,958,841✔
768
  int32_t*        rowEntryOffset = pSup->rowEntryInfoOffset;
1,958,841✔
769
  SqlFunctionCtx* pCtx = pSup->pCtx;
1,958,841✔
770

771
  size_t  keyLen = 0;
1,958,841✔
772
  int32_t numOfRows = tSimpleHashGetSize(pHashmap);
1,958,841✔
773

774
  // begin from last iter
775
  void*   pData = pGroupResInfo->dataPos;
1,954,349✔
776
  int32_t iter = pGroupResInfo->iter;
1,954,349✔
777
  while ((pData = tSimpleHashIterate(pHashmap, pData, &iter)) != NULL) {
8,596,856✔
778
    void*               key = tSimpleHashGetKey(pData, &keyLen);
8,393,915✔
779
    SResultRowPosition* pos = pData;
8,393,915✔
780
    uint64_t            groupId = *(uint64_t*)key;
8,393,915✔
781

782
    SFilePage* page = getBufPage(pBuf, pos->pageId);
8,393,915✔
783
    if (page == NULL) {
8,390,864!
784
      qError("failed to get buffer, code:%s, %s", tstrerror(terrno), GET_TASKID(pTaskInfo));
×
785
      T_LONG_JMP(pTaskInfo->env, terrno);
×
786
    }
787

788
    SResultRow* pRow = (SResultRow*)((char*)page + pos->offset);
8,390,864✔
789

790
    doUpdateNumOfRows(pCtx, pRow, numOfExprs, rowEntryOffset);
8,390,864✔
791

792
    // no results, continue to check the next one
793
    if (pRow->numOfRows == 0) {
8,362,347!
794
      pGroupResInfo->index += 1;
×
795
      pGroupResInfo->iter = iter;
×
796
      pGroupResInfo->dataPos = pData;
×
797

798
      releaseBufPage(pBuf, page);
×
799
      continue;
×
800
    }
801

802
    if (!ignoreGroup) {
8,362,347✔
803
      if (pBlock->info.id.groupId == 0) {
3,515,830✔
804
        pBlock->info.id.groupId = groupId;
1,792,871✔
805
      } else {
806
        // current value belongs to different group, it can't be packed into one datablock
807
        if (pBlock->info.id.groupId != groupId) {
1,722,959!
808
          releaseBufPage(pBuf, page);
1,741,384✔
809
          break;
1,741,024✔
810
        }
811
      }
812
    }
813

814
    if (pBlock->info.rows + pRow->numOfRows > pBlock->info.capacity) {
6,620,963!
815
      uint32_t newSize = pBlock->info.rows + pRow->numOfRows + ((numOfRows - iter) > 1 ? 1 : 0);
×
816
      code = blockDataEnsureCapacity(pBlock, newSize);
×
817
      QUERY_CHECK_CODE(code, lino, _end);
×
818
      qDebug("datablock capacity not sufficient, expand to required:%d, current capacity:%d, %s", newSize,
×
819
             pBlock->info.capacity, GET_TASKID(pTaskInfo));
820
      // todo set the pOperator->resultInfo size
821
    }
822

823
    pGroupResInfo->index += 1;
6,620,963✔
824
    pGroupResInfo->iter = iter;
6,620,963✔
825
    pGroupResInfo->dataPos = pData;
6,620,963✔
826

827
    code = copyResultrowToDataBlock(pExprInfo, numOfExprs, pRow, pCtx, pBlock, rowEntryOffset, pTaskInfo);
6,620,963✔
828
    releaseBufPage(pBuf, page);
6,646,368✔
829
    QUERY_CHECK_CODE(code, lino, _end);
6,642,627!
830
    pBlock->info.rows += pRow->numOfRows;
6,642,627✔
831
    if (pBlock->info.rows >= threshold) {
6,642,627✔
832
      break;
120✔
833
    }
834
  }
835

836
  qDebug("%s result generated, rows:%" PRId64 ", groupId:%" PRIu64, GET_TASKID(pTaskInfo), pBlock->info.rows,
1,942,460✔
837
         pBlock->info.id.groupId);
838
  pBlock->info.dataLoad = 1;
1,942,462✔
839
  code = blockDataUpdateTsWindow(pBlock, 0);
1,942,462✔
840
  QUERY_CHECK_CODE(code, lino, _end);
1,944,080!
841

842
_end:
1,944,080✔
843
  if (code != TSDB_CODE_SUCCESS) {
1,944,080!
844
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
×
845
    T_LONG_JMP(pTaskInfo->env, code);
×
846
  }
847
}
1,944,080✔
848

849
void doCopyToSDataBlock(SExecTaskInfo* pTaskInfo, SSDataBlock* pBlock, SExprSupp* pSup, SDiskbasedBuf* pBuf,
797,878✔
850
                        SGroupResInfo* pGroupResInfo, int32_t threshold, bool ignoreGroup, int64_t minWindowSize) {
851
  int32_t         code = TSDB_CODE_SUCCESS;
797,878✔
852
  int32_t         lino = 0;
797,878✔
853
  SExprInfo*      pExprInfo = pSup->pExprInfo;
797,878✔
854
  int32_t         numOfExprs = pSup->numOfExprs;
797,878✔
855
  int32_t*        rowEntryOffset = pSup->rowEntryInfoOffset;
797,878✔
856
  SqlFunctionCtx* pCtx = pSup->pCtx;
797,878✔
857

858
  int32_t numOfRows = getNumOfTotalRes(pGroupResInfo);
797,878✔
859

860
  for (int32_t i = pGroupResInfo->index; i < numOfRows; i += 1) {
76,679,153✔
861
    SResKeyPos* pPos = taosArrayGetP(pGroupResInfo->pRows, i);
76,198,695✔
862
    SFilePage*  page = getBufPage(pBuf, pPos->pos.pageId);
75,448,162✔
863
    if (page == NULL) {
75,765,222!
864
      qError("failed to get buffer, code:%s, %s", tstrerror(terrno), GET_TASKID(pTaskInfo));
×
865
      T_LONG_JMP(pTaskInfo->env, terrno);
×
866
    }
867

868
    SResultRow* pRow = (SResultRow*)((char*)page + pPos->pos.offset);
75,765,222✔
869

870
    doUpdateNumOfRows(pCtx, pRow, numOfExprs, rowEntryOffset);
75,765,222✔
871

872
    // no results, continue to check the next one
873
    if (pRow->numOfRows == 0) {
74,678,084!
874
      pGroupResInfo->index += 1;
×
875
      releaseBufPage(pBuf, page);
×
876
      continue;
872✔
877
    }
878
    // skip the window which is less than the windowMinSize
879
    if (pRow->win.ekey - pRow->win.skey < minWindowSize) {
74,710,596✔
880
      qDebug("skip small window, groupId: %" PRId64 ", windowSize: %" PRId64 ", minWindowSize: %" PRId64, pPos->groupId,
27✔
881
             pRow->win.ekey - pRow->win.skey, minWindowSize);
882
      pGroupResInfo->index += 1;
27✔
883
      releaseBufPage(pBuf, page);
27✔
884
      continue;
27✔
885
    }
886

887
    if (!ignoreGroup) {
74,710,569✔
888
      if (pBlock->info.id.groupId == 0) {
37,450,856✔
889
        pBlock->info.id.groupId = pPos->groupId;
19,505,910✔
890
      } else {
891
        // current value belongs to different group, it can't be packed into one datablock
892
        if (pBlock->info.id.groupId != pPos->groupId) {
17,944,946✔
893
          releaseBufPage(pBuf, page);
118,477✔
894
          break;
118,478✔
895
        }
896
      }
897
    }
898

899
    if (pBlock->info.rows + pRow->numOfRows > pBlock->info.capacity) {
74,592,092!
900
      uint32_t newSize = pBlock->info.rows + pRow->numOfRows + ((numOfRows - i) > 1 ? 1 : 0);
×
901
      code = blockDataEnsureCapacity(pBlock, newSize);
×
902
      QUERY_CHECK_CODE(code, lino, _end);
×
903
      qDebug("datablock capacity not sufficient, expand to required:%d, current capacity:%d, %s", newSize,
×
904
             pBlock->info.capacity, GET_TASKID(pTaskInfo));
905
      // todo set the pOperator->resultInfo size
906
    }
907

908
    pGroupResInfo->index += 1;
74,592,092✔
909
    code = copyResultrowToDataBlock(pExprInfo, numOfExprs, pRow, pCtx, pBlock, rowEntryOffset, pTaskInfo);
74,592,092✔
910
    releaseBufPage(pBuf, page);
76,747,791✔
911
    QUERY_CHECK_CODE(code, lino, _end);
76,063,612!
912

913
    pBlock->info.rows += pRow->numOfRows;
76,063,612✔
914
    if (pBlock->info.rows >= threshold) {
76,063,612✔
915
      break;
183,254✔
916
    }
917
  }
918

919
  qDebug("%s result generated, rows:%" PRId64 ", groupId:%" PRIu64, GET_TASKID(pTaskInfo), pBlock->info.rows,
782,190✔
920
         pBlock->info.id.groupId);
921
  pBlock->info.dataLoad = 1;
782,192✔
922
  code = blockDataUpdateTsWindow(pBlock, 0);
782,192✔
923
  QUERY_CHECK_CODE(code, lino, _end);
797,787!
924

925
_end:
797,787✔
926
  if (code != TSDB_CODE_SUCCESS) {
797,787!
927
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
×
928
    T_LONG_JMP(pTaskInfo->env, code);
×
929
  }
930
}
797,787✔
931

932
void doBuildResultDatablock(SOperatorInfo* pOperator, SOptrBasicInfo* pbInfo, SGroupResInfo* pGroupResInfo,
922,398✔
933
                            SDiskbasedBuf* pBuf) {
934
  SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
922,398✔
935
  SSDataBlock*   pBlock = pbInfo->pRes;
922,398✔
936

937
  // set output datablock version
938
  pBlock->info.version = pTaskInfo->version;
922,398✔
939

940
  blockDataCleanup(pBlock);
922,398✔
941
  if (!hasRemainResults(pGroupResInfo)) {
922,564✔
942
    return;
124,552✔
943
  }
944

945
  // clear the existed group id
946
  pBlock->info.id.groupId = 0;
797,998✔
947
  if (!pbInfo->mergeResultBlock) {
797,998✔
948
    doCopyToSDataBlock(pTaskInfo, pBlock, &pOperator->exprSupp, pBuf, pGroupResInfo, pOperator->resultInfo.threshold,
388,137✔
949
                       false, getMinWindowSize(pOperator));
950
  } else {
951
    while (hasRemainResults(pGroupResInfo)) {
722,659✔
952
      doCopyToSDataBlock(pTaskInfo, pBlock, &pOperator->exprSupp, pBuf, pGroupResInfo, pOperator->resultInfo.threshold,
409,812✔
953
                         true, getMinWindowSize(pOperator));
954
      if (pBlock->info.rows >= pOperator->resultInfo.threshold) {
409,839✔
955
        break;
97,041✔
956
      }
957

958
      // clearing group id to continue to merge data that belong to different groups
959
      pBlock->info.id.groupId = 0;
312,798✔
960
    }
961

962
    // clear the group id info in SSDataBlock, since the client does not need it
963
    pBlock->info.id.groupId = 0;
409,839✔
964
  }
965
}
966

967
void destroyExprInfo(SExprInfo* pExpr, int32_t numOfExprs) {
2,315,435✔
968
  for (int32_t i = 0; i < numOfExprs; ++i) {
9,461,983✔
969
    SExprInfo* pExprInfo = &pExpr[i];
7,146,154✔
970
    for (int32_t j = 0; j < pExprInfo->base.numOfParams; ++j) {
15,477,417✔
971
      if (pExprInfo->base.pParam[j].type == FUNC_PARAM_TYPE_COLUMN) {
8,331,291✔
972
        taosMemoryFreeClear(pExprInfo->base.pParam[j].pCol);
6,515,443!
973
      } else if (pExprInfo->base.pParam[j].type == FUNC_PARAM_TYPE_VALUE) {
1,815,848✔
974
        taosVariantDestroy(&pExprInfo->base.pParam[j].param);
1,082,782✔
975
      }
976
    }
977

978
    taosMemoryFree(pExprInfo->base.pParam);
7,146,126!
979
    taosMemoryFree(pExprInfo->pExpr);
7,146,592!
980
  }
981
}
2,315,829✔
982

983
int32_t getBufferPgSize(int32_t rowSize, uint32_t* defaultPgsz, int64_t* defaultBufsz) {
1,508,447✔
984
  *defaultPgsz = 4096;
1,508,447✔
985
  uint32_t last = *defaultPgsz;
1,508,447✔
986
  while (*defaultPgsz < rowSize * 4) {
1,972,706✔
987
    *defaultPgsz <<= 1u;
464,259✔
988
    if (*defaultPgsz < last) {
464,259!
989
      return TSDB_CODE_INVALID_PARA;
×
990
    }
991
    last = *defaultPgsz;
464,259✔
992
  }
993

994
  // The default buffer for each operator in query is 10MB.
995
  // at least four pages need to be in buffer
996
  // TODO: make this variable to be configurable.
997
  *defaultBufsz = 4096 * 2560;
1,508,447✔
998
  if ((*defaultBufsz) <= (*defaultPgsz)) {
1,508,447!
999
    (*defaultBufsz) = (*defaultPgsz) * 4;
×
1000
    if (*defaultBufsz < ((int64_t)(*defaultPgsz)) * 4) {
×
1001
      return TSDB_CODE_INVALID_PARA;
×
1002
    }
1003
  }
1004

1005
  return 0;
1,508,447✔
1006
}
1007

1008
void initResultSizeInfo(SResultInfo* pResultInfo, int32_t numOfRows) {
3,246,057✔
1009
  if (numOfRows == 0) {
3,246,057!
1010
    numOfRows = 4096;
×
1011
  }
1012

1013
  pResultInfo->capacity = numOfRows;
3,246,057✔
1014
  pResultInfo->threshold = numOfRows * 0.75;
3,246,057✔
1015

1016
  if (pResultInfo->threshold == 0) {
3,246,057✔
1017
    pResultInfo->threshold = numOfRows;
9,881✔
1018
  }
1019
}
3,246,057✔
1020

1021
void initBasicInfo(SOptrBasicInfo* pInfo, SSDataBlock* pBlock) {
1,493,952✔
1022
  pInfo->pRes = pBlock;
1,493,952✔
1023
  initResultRowInfo(&pInfo->resultRowInfo);
1,493,952✔
1024
}
1,493,853✔
1025

1026
static void destroySqlFunctionCtx(SqlFunctionCtx* pCtx, SExprInfo* pExpr, int32_t numOfOutput) {
6,506,548✔
1027
  if (pCtx == NULL) {
6,506,548✔
1028
    return;
4,003,150✔
1029
  }
1030

1031
  for (int32_t i = 0; i < numOfOutput; ++i) {
9,555,985✔
1032
    if (pExpr != NULL) {
7,052,318✔
1033
      SExprInfo* pExprInfo = &pExpr[i];
7,052,097✔
1034
      for (int32_t j = 0; j < pExprInfo->base.numOfParams; ++j) {
15,288,492✔
1035
        if (pExprInfo->base.pParam[j].type == FUNC_PARAM_TYPE_VALUE) {
8,237,093✔
1036
          taosMemoryFree(pCtx[i].input.pData[j]);
1,081,214!
1037
          taosMemoryFree(pCtx[i].input.pColumnDataAgg[j]);
1,081,178!
1038
        }
1039
      }
1040
    }
1041
    for (int32_t j = 0; j < pCtx[i].numOfParams; ++j) {
15,288,033✔
1042
      taosVariantDestroy(&pCtx[i].param[j].param);
8,236,345✔
1043
    }
1044

1045
    taosMemoryFreeClear(pCtx[i].subsidiaries.pCtx);
7,051,688!
1046
    taosMemoryFreeClear(pCtx[i].subsidiaries.buf);
7,051,695!
1047
    taosMemoryFree(pCtx[i].input.pData);
7,051,695✔
1048
    taosMemoryFree(pCtx[i].input.pColumnDataAgg);
7,052,597!
1049

1050
    if (pCtx[i].udfName != NULL) {
7,052,612✔
1051
      taosMemoryFree(pCtx[i].udfName);
32!
1052
    }
1053
  }
1054

1055
  taosMemoryFreeClear(pCtx);
2,503,667!
1056
  return;
2,503,681✔
1057
}
1058

1059
int32_t initExprSupp(SExprSupp* pSup, SExprInfo* pExprInfo, int32_t numOfExpr, SFunctionStateStore* pStore) {
2,363,572✔
1060
  pSup->pExprInfo = pExprInfo;
2,363,572✔
1061
  pSup->numOfExprs = numOfExpr;
2,363,572✔
1062
  if (pSup->pExprInfo != NULL) {
2,363,572✔
1063
    pSup->pCtx = createSqlFunctionCtx(pExprInfo, numOfExpr, &pSup->rowEntryInfoOffset, pStore);
1,874,108✔
1064
    if (pSup->pCtx == NULL) {
1,873,725!
1065
      return terrno;
×
1066
    }
1067
  }
1068

1069
  return TSDB_CODE_SUCCESS;
2,363,954✔
1070
}
1071

1072
void cleanupExprSupp(SExprSupp* pSupp) {
6,506,513✔
1073
  destroySqlFunctionCtx(pSupp->pCtx, pSupp->pExprInfo, pSupp->numOfExprs);
6,506,513✔
1074
  if (pSupp->pExprInfo != NULL) {
6,506,589✔
1075
    destroyExprInfo(pSupp->pExprInfo, pSupp->numOfExprs);
2,313,147✔
1076
    taosMemoryFreeClear(pSupp->pExprInfo);
2,313,148!
1077
  }
1078

1079
  if (pSupp->pFilterInfo != NULL) {
6,506,497✔
1080
    filterFreeInfo(pSupp->pFilterInfo);
431,252✔
1081
    pSupp->pFilterInfo = NULL;
431,255✔
1082
  }
1083

1084
  taosMemoryFree(pSupp->rowEntryInfoOffset);
6,506,500!
1085
}
6,506,541✔
1086

1087
void cleanupBasicInfo(SOptrBasicInfo* pInfo) {
1,510,991✔
1088
  blockDataDestroy(pInfo->pRes);
1,510,991✔
1089
  pInfo->pRes = NULL;
1,511,194✔
1090
}
1,511,194✔
1091

1092
bool groupbyTbname(SNodeList* pGroupList) {
1,238,041✔
1093
  bool bytbname = false;
1,238,041✔
1094
  SNode*pNode = NULL;
1,238,041✔
1095
  FOREACH(pNode, pGroupList) {
1,298,358✔
1096
    if (pNode->type == QUERY_NODE_FUNCTION) {
311,824✔
1097
      bytbname = (strcmp(((struct SFunctionNode*)pNode)->functionName, "tbname") == 0);
251,507✔
1098
      break;
251,507✔
1099
    }
1100
  }
1101
  return bytbname;
1,238,041✔
1102
}
1103

1104
int32_t createDataSinkParam(SDataSinkNode* pNode, void** pParam, SExecTaskInfo* pTask, SReadHandle* readHandle) {
1,954,285✔
1105
  switch (pNode->type) {
1,954,285✔
1106
    case QUERY_NODE_PHYSICAL_PLAN_QUERY_INSERT: {
129✔
1107
      SInserterParam* pInserterParam = taosMemoryCalloc(1, sizeof(SInserterParam));
129!
1108
      if (NULL == pInserterParam) {
129!
1109
        return terrno;
×
1110
      }
1111
      pInserterParam->readHandle = readHandle;
129✔
1112

1113
      *pParam = pInserterParam;
129✔
1114
      break;
129✔
1115
    }
1116
    case QUERY_NODE_PHYSICAL_PLAN_DELETE: {
7,146✔
1117
      SDeleterParam* pDeleterParam = taosMemoryCalloc(1, sizeof(SDeleterParam));
7,146!
1118
      if (NULL == pDeleterParam) {
7,146!
1119
        return terrno;
×
1120
      }
1121

1122
      SArray* pInfoList = NULL;
7,146✔
1123
      int32_t code = getTableListInfo(pTask, &pInfoList);
7,146✔
1124
      if (code != TSDB_CODE_SUCCESS || pInfoList == NULL) {
7,147!
1125
        taosMemoryFree(pDeleterParam);
1!
1126
        return code;
×
1127
      }
1128

1129
      STableListInfo* pTableListInfo = taosArrayGetP(pInfoList, 0);
7,146✔
1130
      taosArrayDestroy(pInfoList);
7,146✔
1131

1132
      pDeleterParam->suid = tableListGetSuid(pTableListInfo);
7,147✔
1133

1134
      // TODO extract uid list
1135
      int32_t numOfTables = 0;
7,147✔
1136
      code = tableListGetSize(pTableListInfo, &numOfTables);
7,147✔
1137
      if (code != TSDB_CODE_SUCCESS) {
7,146!
1138
        qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(code));
×
1139
        taosMemoryFree(pDeleterParam);
×
1140
        return code;
×
1141
      }
1142

1143
      pDeleterParam->pUidList = taosArrayInit(numOfTables, sizeof(uint64_t));
7,146✔
1144
      if (NULL == pDeleterParam->pUidList) {
7,146!
1145
        taosMemoryFree(pDeleterParam);
×
1146
        return terrno;
×
1147
      }
1148

1149
      for (int32_t i = 0; i < numOfTables; ++i) {
14,691✔
1150
        STableKeyInfo* pTable = tableListGetInfo(pTableListInfo, i);
7,545✔
1151
        if (!pTable) {
7,545!
1152
          taosArrayDestroy(pDeleterParam->pUidList);
×
1153
          taosMemoryFree(pDeleterParam);
×
1154
          return TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR;
×
1155
        }
1156
        void*          tmp = taosArrayPush(pDeleterParam->pUidList, &pTable->uid);
7,545✔
1157
        if (!tmp) {
7,545!
1158
          taosArrayDestroy(pDeleterParam->pUidList);
×
1159
          taosMemoryFree(pDeleterParam);
×
1160
          return terrno;
×
1161
        }
1162
      }
1163

1164
      *pParam = pDeleterParam;
7,146✔
1165
      break;
7,146✔
1166
    }
1167
    default:
1,947,010✔
1168
      break;
1,947,010✔
1169
  }
1170

1171
  return TSDB_CODE_SUCCESS;
1,954,285✔
1172
}
1173

1174
void streamOpReleaseState(SOperatorInfo* pOperator) {
106✔
1175
  SOperatorInfo* downstream = pOperator->pDownstream[0];
106✔
1176
  if (downstream->fpSet.releaseStreamStateFn) {
106!
1177
    downstream->fpSet.releaseStreamStateFn(downstream);
106✔
1178
  }
1179
}
106✔
1180

1181
void streamOpReloadState(SOperatorInfo* pOperator) {
106✔
1182
  SOperatorInfo* downstream = pOperator->pDownstream[0];
106✔
1183
  if (downstream->fpSet.reloadStreamStateFn) {
106!
1184
    downstream->fpSet.reloadStreamStateFn(downstream);
106✔
1185
  }
1186
}
106✔
1187

1188
void freeOperatorParamImpl(SOperatorParam* pParam, SOperatorParamType type) {
106,705✔
1189
  int32_t childrenNum = taosArrayGetSize(pParam->pChildren);
106,705✔
1190
  for (int32_t i = 0; i < childrenNum; ++i) {
106,705!
1191
    SOperatorParam* pChild = taosArrayGetP(pParam->pChildren, i);
×
1192
    freeOperatorParam(pChild, type);
×
1193
  }
1194

1195
  taosArrayDestroy(pParam->pChildren);
106,705✔
1196
  pParam->pChildren = NULL;
106,705✔
1197

1198
  taosMemoryFreeClear(pParam->value);
106,705!
1199

1200
  taosMemoryFree(pParam);
106,705!
1201
}
106,705✔
1202

1203
void freeExchangeGetBasicOperatorParam(void* pParam) {
1,076✔
1204
  SExchangeOperatorBasicParam* pBasic = (SExchangeOperatorBasicParam*)pParam;
1,076✔
1205
  taosArrayDestroy(pBasic->uidList);
1,076✔
1206
  if (pBasic->colMap) {
1,076!
1207
    taosArrayDestroy(pBasic->colMap->colMap);
×
1208
    taosMemoryFreeClear(pBasic->colMap);
×
1209
  }
1210
}
1,076✔
1211

1212
void freeExchangeGetOperatorParam(SOperatorParam* pParam) {
671✔
1213
  SExchangeOperatorParam* pExcParam = (SExchangeOperatorParam*)pParam->value;
671✔
1214
  if (pExcParam->multiParams) {
671✔
1215
    SExchangeOperatorBatchParam* pExcBatch = (SExchangeOperatorBatchParam*)pParam->value;
623✔
1216
    tSimpleHashCleanup(pExcBatch->pBatchs);
623✔
1217
  } else {
1218
    freeExchangeGetBasicOperatorParam(&pExcParam->basic);
48✔
1219
  }
1220

1221
  freeOperatorParamImpl(pParam, OP_GET_PARAM);
671✔
1222
}
671✔
1223

1224
void freeExchangeNotifyOperatorParam(SOperatorParam* pParam) { freeOperatorParamImpl(pParam, OP_NOTIFY_PARAM); }
×
1225

1226
void freeGroupCacheGetOperatorParam(SOperatorParam* pParam) { freeOperatorParamImpl(pParam, OP_GET_PARAM); }
69,210✔
1227

1228
void freeGroupCacheNotifyOperatorParam(SOperatorParam* pParam) { freeOperatorParamImpl(pParam, OP_NOTIFY_PARAM); }
×
1229

1230
void freeMergeJoinGetOperatorParam(SOperatorParam* pParam) { freeOperatorParamImpl(pParam, OP_GET_PARAM); }
34,605✔
1231

1232
void freeMergeJoinNotifyOperatorParam(SOperatorParam* pParam) { freeOperatorParamImpl(pParam, OP_NOTIFY_PARAM); }
×
1233

1234
void freeTableScanGetOperatorParam(SOperatorParam* pParam) {
2,219✔
1235
  STableScanOperatorParam* pTableScanParam = (STableScanOperatorParam*)pParam->value;
2,219✔
1236
  taosArrayDestroy(pTableScanParam->pUidList);
2,219✔
1237
  if (pTableScanParam->pOrgTbInfo) {
2,219!
1238
    taosArrayDestroy(pTableScanParam->pOrgTbInfo->colMap);
×
1239
    taosMemoryFreeClear(pTableScanParam->pOrgTbInfo);
×
1240
  }
1241
  freeOperatorParamImpl(pParam, OP_GET_PARAM);
2,219✔
1242
}
2,219✔
1243

1244
void freeTableScanNotifyOperatorParam(SOperatorParam* pParam) { freeOperatorParamImpl(pParam, OP_NOTIFY_PARAM); }
×
1245

1246
void freeOpParamItem(void* pItem) {
×
1247
  SOperatorParam* pParam = *(SOperatorParam**)pItem;
×
1248
  pParam->reUse = false;
×
1249
  freeOperatorParam(pParam, OP_GET_PARAM);
×
1250
}
×
1251

1252
void freeVirtualTableScanGetOperatorParam(SOperatorParam* pParam) {
×
1253
  SVTableScanOperatorParam* pVTableScanParam = (SVTableScanOperatorParam*)pParam->value;
×
1254
  taosArrayDestroyEx(pVTableScanParam->pOpParamArray, freeOpParamItem);
×
1255
  freeOperatorParamImpl(pParam, OP_GET_PARAM);
×
1256
}
×
1257

1258
void freeVTableScanNotifyOperatorParam(SOperatorParam* pParam) { freeOperatorParamImpl(pParam, OP_NOTIFY_PARAM); }
×
1259

1260
void freeOperatorParam(SOperatorParam* pParam, SOperatorParamType type) {
3,281,697✔
1261
  if (NULL == pParam || pParam->reUse) {
3,281,697!
1262
    return;
3,174,992✔
1263
  }
1264

1265
  switch (pParam->opType) {
106,705!
1266
    case QUERY_NODE_PHYSICAL_PLAN_EXCHANGE:
671✔
1267
      type == OP_GET_PARAM ? freeExchangeGetOperatorParam(pParam) : freeExchangeNotifyOperatorParam(pParam);
671!
1268
      break;
671✔
1269
    case QUERY_NODE_PHYSICAL_PLAN_GROUP_CACHE:
69,210✔
1270
      type == OP_GET_PARAM ? freeGroupCacheGetOperatorParam(pParam) : freeGroupCacheNotifyOperatorParam(pParam);
69,210!
1271
      break;
69,210✔
1272
    case QUERY_NODE_PHYSICAL_PLAN_MERGE_JOIN:
34,605✔
1273
      type == OP_GET_PARAM ? freeMergeJoinGetOperatorParam(pParam) : freeMergeJoinNotifyOperatorParam(pParam);
34,605!
1274
      break;
34,605✔
1275
    case QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN:
2,219✔
1276
      type == OP_GET_PARAM ? freeTableScanGetOperatorParam(pParam) : freeTableScanNotifyOperatorParam(pParam);
2,219!
1277
      break;
2,219✔
1278
    case QUERY_NODE_PHYSICAL_PLAN_VIRTUAL_TABLE_SCAN:
×
1279
      type == OP_GET_PARAM ? freeVirtualTableScanGetOperatorParam(pParam) : freeVTableScanNotifyOperatorParam(pParam);
×
1280
      break;
×
UNCOV
1281
    default:
×
UNCOV
1282
      qError("unsupported op %d param, type %d", pParam->opType, type);
×
1283
      break;
×
1284
  }
1285
}
1286

1287
void freeResetOperatorParams(struct SOperatorInfo* pOperator, SOperatorParamType type, bool allFree) {
8,477,278✔
1288
  SOperatorParam**  ppParam = NULL;
8,477,278✔
1289
  SOperatorParam*** pppDownstramParam = NULL;
8,477,278✔
1290
  switch (type) {
8,477,278!
1291
    case OP_GET_PARAM:
4,257,111✔
1292
      ppParam = &pOperator->pOperatorGetParam;
4,257,111✔
1293
      pppDownstramParam = &pOperator->pDownstreamGetParams;
4,257,111✔
1294
      break;
4,257,111✔
1295
    case OP_NOTIFY_PARAM:
4,220,858✔
1296
      ppParam = &pOperator->pOperatorNotifyParam;
4,220,858✔
1297
      pppDownstramParam = &pOperator->pDownstreamNotifyParams;
4,220,858✔
1298
      break;
4,220,858✔
1299
    default:
×
1300
      return;
×
1301
  }
1302

1303
  if (*ppParam) {
8,477,969✔
1304
    freeOperatorParam(*ppParam, type);
34,605✔
1305
    *ppParam = NULL;
34,605✔
1306
  }
1307

1308
  if (*pppDownstramParam) {
8,477,969✔
1309
    for (int32_t i = 0; i < pOperator->numOfDownstream; ++i) {
105,629✔
1310
      if ((*pppDownstramParam)[i]) {
69,210!
1311
        freeOperatorParam((*pppDownstramParam)[i], type);
×
1312
        (*pppDownstramParam)[i] = NULL;
×
1313
      }
1314
    }
1315
    if (allFree) {
36,419✔
1316
      taosMemoryFreeClear(*pppDownstramParam);
2,123!
1317
    }
1318
  }
1319
}
1320

1321
FORCE_INLINE int32_t getNextBlockFromDownstreamImpl(struct SOperatorInfo* pOperator, int32_t idx, bool clearParam,
10,164,012✔
1322
                                                    SSDataBlock** pResBlock) {
1323
  QRY_PARAM_CHECK(pResBlock);
10,164,012!
1324

1325
  int32_t code = 0;
10,164,012✔
1326
  if (pOperator->pDownstreamGetParams && pOperator->pDownstreamGetParams[idx]) {
10,164,012!
1327
    qDebug("DynOp: op %s start to get block from downstream %s", pOperator->name, pOperator->pDownstream[idx]->name);
104,084✔
1328
    code = pOperator->pDownstream[idx]->fpSet.getNextExtFn(pOperator->pDownstream[idx],
104,084✔
1329
                                                           pOperator->pDownstreamGetParams[idx], pResBlock);
104,084✔
1330
    if (clearParam && (code == 0)) {
104,084!
1331
      freeOperatorParam(pOperator->pDownstreamGetParams[idx], OP_GET_PARAM);
×
1332
      pOperator->pDownstreamGetParams[idx] = NULL;
×
1333
    }
1334

1335
    if (code) {
104,084!
1336
      qError("failed to get next data block from upstream at %s, line:%d code:%s", __func__, __LINE__, tstrerror(code));
×
1337
    }
1338
    return code;
104,084✔
1339
  }
1340

1341
  code = pOperator->pDownstream[idx]->fpSet.getNextFn(pOperator->pDownstream[idx], pResBlock);
10,059,928✔
1342
  if (code) {
10,061,072!
1343
    qError("failed to get next data block from upstream at %s, %d code:%s", __func__, __LINE__, tstrerror(code));
×
1344
  }
1345
  return code;
10,061,203✔
1346
}
1347

1348
bool compareVal(const char* v, const SStateKeys* pKey) {
144,850✔
1349
  if (IS_VAR_DATA_TYPE(pKey->type)) {
144,850!
1350
    if (varDataLen(v) != varDataLen(pKey->pData)) {
2,373!
1351
      return false;
×
1352
    } else {
1353
      return memcmp(varDataVal(v), varDataVal(pKey->pData), varDataLen(v)) == 0;
2,373✔
1354
    }
1355
  } else {
1356
    return memcmp(pKey->pData, v, pKey->bytes) == 0;
142,477✔
1357
  }
1358
}
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