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

taosdata / TDengine / #4693

29 Aug 2025 06:36AM UTC coverage: 58.007% (-1.1%) from 59.151%
#4693

push

travis-ci

web-flow
fix(gpt): fix race-condition in preparing tmp files (#32800)

132676 of 291873 branches covered (45.46%)

Branch coverage included in aggregate %.

5 of 34 new or added lines in 6 files covered. (14.71%)

4288 existing lines in 199 files now uncovered.

201114 of 283561 relevant lines covered (70.92%)

5433357.08 hits per line

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

66.77
/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) {
52,108,830✔
87
  SFilePage* pData = NULL;
52,108,830✔
88

89
  // in the first scan, new space needed for results
90
  int32_t pageId = -1;
52,108,830✔
91
  if (*currentPageId == -1) {
52,108,830✔
92
    pData = getNewBufPage(pResultBuf, &pageId);
1,094,789✔
93
    if (pData == NULL) {
1,094,892✔
94
      qError("failed to get buffer, code:%s", tstrerror(terrno));
26!
95
      return NULL;
×
96
    }
97
    pData->num = sizeof(SFilePage);
1,094,866✔
98
  } else {
99
    pData = getBufPage(pResultBuf, *currentPageId);
51,014,041✔
100
    if (pData == NULL) {
51,028,369!
101
      qError("failed to get buffer, code:%s", tstrerror(terrno));
×
102
      return NULL;
×
103
    }
104

105
    pageId = *currentPageId;
51,028,369✔
106

107
    if (pData->num + interBufSize > getBufPageSize(pResultBuf)) {
51,028,369✔
108
      // release current page first, and prepare the next one
109
      releaseBufPage(pResultBuf, pData);
4,244,950✔
110

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

120
  setBufPageDirty(pData, true);
52,094,978✔
121

122
  // set the number of rows in current disk page
123
  SResultRow* pResultRow = (SResultRow*)((char*)pData + pData->num);
52,055,987✔
124

125
  memset((char*)pResultRow, 0, interBufSize);
52,055,987✔
126
  pResultRow->pageId = pageId;
52,055,987✔
127
  pResultRow->offset = (int32_t)pData->num;
52,055,987✔
128

129
  *currentPageId = pageId;
52,055,987✔
130
  pData->num += interBufSize;
52,055,987✔
131
  return pResultRow;
52,055,987✔
132
}
133

134
/**
135
 * the struct of key in hash table
136
 * +----------+---------------+
137
 * | group id |   key data    |
138
 * | 8 bytes  | actual length |
139
 * +----------+---------------+
140
 */
141
SResultRow* doSetResultOutBufByKey(SDiskbasedBuf* pResultBuf, SResultRowInfo* pResultRowInfo, char* pData,
60,786,317✔
142
                                   int32_t bytes, bool masterscan, uint64_t groupId, SExecTaskInfo* pTaskInfo,
143
                                   bool isIntervalQuery, SAggSupporter* pSup, bool keepGroup) {
144
  SET_RES_WINDOW_KEY(pSup->keyBuf, pData, bytes, groupId);
60,786,317✔
145
  if (!keepGroup) {
60,786,317✔
146
    *(uint64_t*)pSup->keyBuf = calcGroupId(pSup->keyBuf, GET_RES_WINDOW_KEY_LEN(bytes));
12,090,594✔
147
  }
148

149
  SResultRowPosition* p1 =
150
      (SResultRowPosition*)tSimpleHashGet(pSup->pResultRowHashTable, pSup->keyBuf, GET_RES_WINDOW_KEY_LEN(bytes));
60,960,072✔
151

152
  SResultRow* pResult = NULL;
61,360,277✔
153

154
  // in case of repeat scan/reverse scan, no new time window added.
155
  if (isIntervalQuery) {
61,360,277✔
156
    if (p1 != NULL) {  // the *p1 may be NULL in case of sliding+offset exists.
47,621,711✔
157
      pResult = getResultRowByPos(pResultBuf, p1, true);
3,334,240✔
158
      if (pResult == NULL) {
3,334,240!
159
        pTaskInfo->code = terrno;
×
160
        return NULL;
×
161
      }
162

163
      if (pResult->pageId != p1->pageId || pResult->offset != p1->offset) {
3,334,240!
164
        terrno = TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR;
×
165
        pTaskInfo->code = terrno;
×
166
        return NULL;
×
167
      }
168
    }
169
  } else {
170
    // In case of group by column query, the required SResultRow object must be existInCurrentResusltRowInfo in the
171
    // pResultRowInfo object.
172
    if (p1 != NULL) {
13,738,566✔
173
      // todo
174
      pResult = getResultRowByPos(pResultBuf, p1, true);
5,313,023✔
175
      if (NULL == pResult) {
5,313,023!
176
        pTaskInfo->code = terrno;
×
177
        return NULL;
×
178
      }
179

180
      if (pResult->pageId != p1->pageId || pResult->offset != p1->offset) {
5,313,023!
181
        terrno = TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR;
×
182
        pTaskInfo->code = terrno;
×
183
        return NULL;
2,233✔
184
      }
185
    }
186
  }
187

188
  // 1. close current opened time window
189
  if (pResultRowInfo->cur.pageId != -1 && ((pResult == NULL) || (pResult->pageId != pResultRowInfo->cur.pageId))) {
61,284,091✔
190
    SResultRowPosition pos = pResultRowInfo->cur;
53,290,622✔
191
    SFilePage*         pPage = getBufPage(pResultBuf, pos.pageId);
53,290,622✔
192
    if (pPage == NULL) {
52,914,600!
193
      qError("failed to get buffer, code:%s, %s", tstrerror(terrno), GET_TASKID(pTaskInfo));
×
194
      pTaskInfo->code = terrno;
×
195
      return NULL;
×
196
    }
197
    releaseBufPage(pResultBuf, pPage);
52,914,600✔
198
  }
199

200
  // allocate a new buffer page
201
  if (pResult == NULL) {
60,724,827✔
202
    pResult = getNewResultRow(pResultBuf, &pSup->currentPageId, pSup->resultRowSize);
52,104,929✔
203
    if (pResult == NULL) {
52,184,765!
204
      pTaskInfo->code = terrno;
×
205
      return NULL;
×
206
    }
207

208
    // add a new result set for a new group
209
    SResultRowPosition pos = {.pageId = pResult->pageId, .offset = pResult->offset};
52,184,765✔
210
    int32_t code = tSimpleHashPut(pSup->pResultRowHashTable, pSup->keyBuf, GET_RES_WINDOW_KEY_LEN(bytes), &pos,
52,184,765✔
211
                                  sizeof(SResultRowPosition));
212
    if (code != TSDB_CODE_SUCCESS) {
52,736,947✔
213
      qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(code));
9,176!
214
      pTaskInfo->code = code;
×
215
      return NULL;
×
216
    }
217
  }
218

219
  // 2. set the new time window to be the new active time window
220
  pResultRowInfo->cur = (SResultRowPosition){.pageId = pResult->pageId, .offset = pResult->offset};
61,347,669✔
221

222
  // too many time window in query
223
  if (pTaskInfo->execModel == OPTR_EXEC_MODEL_BATCH &&
122,522,011!
224
      tSimpleHashGetSize(pSup->pResultRowHashTable) > MAX_INTERVAL_TIME_WINDOW) {
61,317,200✔
225
    pTaskInfo->code = TSDB_CODE_QRY_TOO_MANY_TIMEWINDOW;
×
226
    return NULL;
×
227
  }
228

229
  return pResult;
61,204,811✔
230
}
231

232
//  query_range_start, query_range_end, window_duration, window_start, window_end
233
int32_t initExecTimeWindowInfo(SColumnInfoData* pColData, STimeWindow* pQueryWindow) {
23,628✔
234
  pColData->info.type = TSDB_DATA_TYPE_TIMESTAMP;
23,628✔
235
  pColData->info.bytes = sizeof(int64_t);
23,628✔
236

237
  int32_t code = colInfoDataEnsureCapacity(pColData, 5, false);
23,628✔
238
  if (code != TSDB_CODE_SUCCESS) {
23,646!
239
    return code;
×
240
  }
241
  colDataSetInt64(pColData, 0, &pQueryWindow->skey);
23,646✔
242
  colDataSetInt64(pColData, 1, &pQueryWindow->ekey);
23,646✔
243

244
  int64_t interval = 0;
23,646✔
245
  colDataSetInt64(pColData, 2, &interval);  // this value may be variable in case of 'n' and 'y'.
246
  colDataSetInt64(pColData, 3, &pQueryWindow->skey);
23,646✔
247
  colDataSetInt64(pColData, 4, &pQueryWindow->ekey);
23,646✔
248
  return TSDB_CODE_SUCCESS;
23,646✔
249
}
250

251
static int32_t doSetInputDataBlockInfo(SExprSupp* pExprSup, SSDataBlock* pBlock, int32_t order, int32_t scanFlag) {
21,945✔
252
  int32_t         code = TSDB_CODE_SUCCESS;
21,945✔
253
  int32_t         lino = 0;
21,945✔
254
  SqlFunctionCtx* pCtx = pExprSup->pCtx;
21,945✔
255
  for (int32_t i = 0; i < pExprSup->numOfExprs; ++i) {
43,932✔
256
    pCtx[i].order = order;
21,987✔
257
    pCtx[i].input.numOfRows = pBlock->info.rows;
21,987✔
258
    code = setBlockSMAInfo(&pCtx[i], &pExprSup->pExprInfo[i], pBlock);
21,987✔
259
    QUERY_CHECK_CODE(code, lino, _end);
21,987!
260
    pCtx[i].pSrcBlock = pBlock;
21,987✔
261
    pCtx[i].scanFlag = scanFlag;
21,987✔
262
  }
263

264
_end:
21,945✔
265
  if (code != TSDB_CODE_SUCCESS) {
21,945!
266
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
×
267
  }
268
  return code;
21,945✔
269
}
270

271
int32_t setInputDataBlock(SExprSupp* pExprSup, SSDataBlock* pBlock, int32_t order, int32_t scanFlag,
5,547,062✔
272
                          bool createDummyCol) {
273
  if (pBlock->pBlockAgg != NULL) {
5,547,062✔
274
    return doSetInputDataBlockInfo(pExprSup, pBlock, order, scanFlag);
21,945✔
275
  } else {
276
    return doSetInputDataBlock(pExprSup, pBlock, order, scanFlag, createDummyCol);
5,525,117✔
277
  }
278
}
279

280
static int32_t doCreateConstantValColumnInfo(SInputColumnInfoData* pInput, SFunctParam* pFuncParam, int32_t paramIndex,
545✔
281
                                             int32_t numOfRows) {
282
  int32_t          code = TSDB_CODE_SUCCESS;
545✔
283
  int32_t          lino = 0;
545✔
284
  SColumnInfoData* pColInfo = NULL;
545✔
285
  if (pInput->pData[paramIndex] == NULL) {
545✔
286
    pColInfo = taosMemoryCalloc(1, sizeof(SColumnInfoData));
114!
287
    QUERY_CHECK_NULL(pColInfo, code, lino, _end, terrno);
114!
288

289
    // Set the correct column info (data type and bytes)
290
    pColInfo->info.type = pFuncParam->param.nType;
114✔
291
    pColInfo->info.bytes = pFuncParam->param.nLen;
114✔
292

293
    pInput->pData[paramIndex] = pColInfo;
114✔
294
  } else {
295
    pColInfo = pInput->pData[paramIndex];
431✔
296
  }
297

298
  code = colInfoDataEnsureCapacity(pColInfo, numOfRows, false);
545✔
299
  QUERY_CHECK_CODE(code, lino, _end);
545!
300

301
  int8_t type = pFuncParam->param.nType;
545✔
302
  if (type == TSDB_DATA_TYPE_BIGINT || type == TSDB_DATA_TYPE_UBIGINT) {
592!
303
    int64_t v = pFuncParam->param.i;
47✔
304
    for (int32_t i = 0; i < numOfRows; ++i) {
254✔
305
      colDataSetInt64(pColInfo, i, &v);
207✔
306
    }
307
  } else if (type == TSDB_DATA_TYPE_DOUBLE) {
498!
308
    double v = pFuncParam->param.d;
×
309
    for (int32_t i = 0; i < numOfRows; ++i) {
×
310
      colDataSetDouble(pColInfo, i, &v);
×
311
    }
312
  } else if (type == TSDB_DATA_TYPE_VARCHAR || type == TSDB_DATA_TYPE_GEOMETRY) {
498!
313
    char* tmp = taosMemoryMalloc(pFuncParam->param.nLen + VARSTR_HEADER_SIZE);
×
314
    QUERY_CHECK_NULL(tmp, code, lino, _end, terrno);
×
315

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

324
_end:
498✔
325
  if (code != TSDB_CODE_SUCCESS) {
545!
326
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
×
327
  }
328
  return code;
545✔
329
}
330

331
static int32_t doSetInputDataBlock(SExprSupp* pExprSup, SSDataBlock* pBlock, int32_t order, int32_t scanFlag,
5,524,917✔
332
                                   bool createDummyCol) {
333
  int32_t         code = TSDB_CODE_SUCCESS;
5,524,917✔
334
  int32_t         lino = 0;
5,524,917✔
335
  SqlFunctionCtx* pCtx = pExprSup->pCtx;
5,524,917✔
336

337
  for (int32_t i = 0; i < pExprSup->numOfExprs; ++i) {
24,856,746✔
338
    pCtx[i].order = order;
19,332,530✔
339
    pCtx[i].input.numOfRows = pBlock->info.rows;
19,332,530✔
340

341
    pCtx[i].pSrcBlock = pBlock;
19,332,530✔
342
    pCtx[i].scanFlag = scanFlag;
19,332,530✔
343

344
    SInputColumnInfoData* pInput = &pCtx[i].input;
19,332,530✔
345
    pInput->uid = pBlock->info.id.uid;
19,332,530✔
346
    pInput->colDataSMAIsSet = false;
19,332,530✔
347

348
    SExprInfo* pOneExpr = &pExprSup->pExprInfo[i];
19,332,530✔
349
    bool       hasPk = pOneExpr->pExpr->nodeType == QUERY_NODE_FUNCTION && pOneExpr->pExpr->_function.pFunctNode->hasPk;
19,332,530✔
350
    pCtx[i].hasPrimaryKey = hasPk;
19,332,530✔
351

352
    int16_t tsParamIdx = (!hasPk) ? pOneExpr->base.numOfParams - 1 : pOneExpr->base.numOfParams - 2;
19,332,530✔
353
    int16_t pkParamIdx = pOneExpr->base.numOfParams - 1;
19,332,530✔
354

355
    for (int32_t j = 0; j < pOneExpr->base.numOfParams; ++j) {
40,549,278✔
356
      SFunctParam* pFuncParam = &pOneExpr->base.pParam[j];
21,217,449✔
357
      if (pFuncParam->type == FUNC_PARAM_TYPE_COLUMN) {
21,217,449✔
358
        int32_t slotId = pFuncParam->pCol->slotId;
18,462,909✔
359
        pInput->pData[j] = taosArrayGet(pBlock->pDataBlock, slotId);
18,462,909✔
360
        pInput->totalRows = pBlock->info.rows;
18,461,830✔
361
        pInput->numOfRows = pBlock->info.rows;
18,461,830✔
362
        pInput->startRowIndex = 0;
18,461,830✔
363
        pInput->blankFill = pBlock->info.blankFill;
18,461,830✔
364

365
        // NOTE: the last parameter is the primary timestamp column
366
        // todo: refactor this
367

368
        if (fmIsImplicitTsFunc(pCtx[i].functionId) && (j == tsParamIdx)) {
18,461,830✔
369
          pInput->pPTS = pInput->pData[j];  // in case of merge function, this is not always the ts column data.
785,724✔
370
        }
371
        if (hasPk && (j == pkParamIdx)) {
18,462,208✔
372
          pInput->pPrimaryKey = pInput->pData[j];
237,302✔
373
        }
374
        QUERY_CHECK_CONDITION((pInput->pData[j] != NULL), code, lino, _end, TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR);
18,462,208!
375
      } else if (pFuncParam->type == FUNC_PARAM_TYPE_VALUE) {
2,754,540✔
376
        // todo avoid case: top(k, 12), 12 is the value parameter.
377
        // sum(11), 11 is also the value parameter.
378
        if (createDummyCol && pOneExpr->base.numOfParams == 1) {
1,247,836✔
379
          pInput->totalRows = pBlock->info.rows;
545✔
380
          pInput->numOfRows = pBlock->info.rows;
545✔
381
          pInput->startRowIndex = 0;
545✔
382
          pInput->blankFill = pBlock->info.blankFill;
545✔
383

384
          code = doCreateConstantValColumnInfo(pInput, pFuncParam, j, pBlock->info.rows);
545✔
385
          QUERY_CHECK_CODE(code, lino, _end);
545!
386
        }
387
      }
388
    }
389
  }
390

391
_end:
5,524,216✔
392
  if (code != TSDB_CODE_SUCCESS) {
5,524,216!
393
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
×
394
  }
395
  return code;
5,526,033✔
396
}
397

398
bool functionNeedToExecute(SqlFunctionCtx* pCtx) {
222,824,180✔
399
  struct SResultRowEntryInfo* pResInfo = GET_RES_INFO(pCtx);
222,824,180✔
400

401
  // in case of timestamp column, always generated results.
402
  int32_t functionId = pCtx->functionId;
222,824,180✔
403
  if (functionId == -1) {
222,824,180✔
404
    return false;
29,220,930✔
405
  }
406

407
  if (pCtx->scanFlag == PRE_SCAN) {
193,603,250✔
408
    return fmIsRepeatScanFunc(pCtx->functionId);
13,392✔
409
  }
410

411
  if (isRowEntryCompleted(pResInfo)) {
193,589,858✔
412
    return false;
34✔
413
  }
414

415
  return true;
193,589,824✔
416
}
417

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

426
    // Set the correct column info (data type and bytes)
UNCOV
427
    pInput->pData[paramIndex]->info.type = type;
×
UNCOV
428
    pInput->pData[paramIndex]->info.bytes = tDataTypes[type].bytes;
×
429
  }
430

UNCOV
431
  SColumnDataAgg* da = NULL;
×
UNCOV
432
  if (pInput->pColumnDataAgg[paramIndex] == NULL) {
×
UNCOV
433
    da = taosMemoryCalloc(1, sizeof(SColumnDataAgg));
×
UNCOV
434
    if (!da) {
×
435
      return terrno;
×
436
    }
UNCOV
437
    pInput->pColumnDataAgg[paramIndex] = da;
×
438
  } else {
UNCOV
439
    da = pInput->pColumnDataAgg[paramIndex];
×
440
  }
441

UNCOV
442
  if (type == TSDB_DATA_TYPE_BIGINT) {
×
UNCOV
443
    int64_t v = pFuncParam->param.i;
×
UNCOV
444
    *da = (SColumnDataAgg){.numOfNull = 0, .min = v, .max = v, .sum = v * numOfRows};
×
445
  } else if (type == TSDB_DATA_TYPE_DOUBLE) {
×
446
    double v = pFuncParam->param.d;
×
447
    *da = (SColumnDataAgg){.numOfNull = 0};
×
448

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

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

UNCOV
465
  return TSDB_CODE_SUCCESS;
×
466
}
467

468
int32_t setBlockSMAInfo(SqlFunctionCtx* pCtx, SExprInfo* pExprInfo, SSDataBlock* pBlock) {
21,986✔
469
  int32_t code = TSDB_CODE_SUCCESS;
21,986✔
470
  int32_t lino = 0;
21,986✔
471
  int32_t numOfRows = pBlock->info.rows;
21,986✔
472

473
  SInputColumnInfoData* pInput = &pCtx->input;
21,986✔
474
  pInput->numOfRows = numOfRows;
21,986✔
475
  pInput->totalRows = numOfRows;
21,986✔
476

477
  if (pBlock->pBlockAgg != NULL) {
21,986!
478
    pInput->colDataSMAIsSet = true;
21,987✔
479

480
    for (int32_t j = 0; j < pExprInfo->base.numOfParams; ++j) {
43,974✔
481
      SFunctParam* pFuncParam = &pExprInfo->base.pParam[j];
21,987✔
482

483
      if (pFuncParam->type == FUNC_PARAM_TYPE_COLUMN) {
21,987!
484
        int32_t slotId = pFuncParam->pCol->slotId;
21,987✔
485
        pInput->pColumnDataAgg[j] = &pBlock->pBlockAgg[slotId];
21,987✔
486
        if (pInput->pColumnDataAgg[j]->colId == -1) {
21,987✔
487
          pInput->colDataSMAIsSet = false;
3,745✔
488
        }
489

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

502
_end:
21,986✔
503
  if (code != TSDB_CODE_SUCCESS) {
21,986!
504
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
×
505
  }
506
  return code;
21,987✔
507
}
508

509
/////////////////////////////////////////////////////////////////////////////////////////////
510
STimeWindow getAlignQueryTimeWindow(const SInterval* pInterval, int64_t key) {
322,521✔
511
  STimeWindow win = {0};
322,521✔
512
  win.skey = taosTimeTruncate(key, pInterval);
322,521✔
513

514
  /*
515
   * if the realSkey > INT64_MAX - pInterval->interval, the query duration between
516
   * realSkey and realEkey must be less than one interval.Therefore, no need to adjust the query ranges.
517
   */
518
  win.ekey = taosTimeGetIntervalEnd(win.skey, pInterval);
322,447✔
519
  if (win.ekey < win.skey) {
322,574!
520
    win.ekey = INT64_MAX;
×
521
  }
522

523
  return win;
322,574✔
524
}
525

526
int32_t setResultRowInitCtx(SResultRow* pResult, SqlFunctionCtx* pCtx, int32_t numOfOutput,
64,455,772✔
527
                            int32_t* rowEntryInfoOffset) {
528
  bool init = false;
64,455,772✔
529
  for (int32_t i = 0; i < numOfOutput; ++i) {
337,281,767✔
530
    pCtx[i].resultInfo = getResultEntryInfo(pResult, i, rowEntryInfoOffset);
273,330,251✔
531
    if (init) {
273,262,941✔
532
      continue;
20,680,269✔
533
    }
534

535
    struct SResultRowEntryInfo* pResInfo = pCtx[i].resultInfo;
252,582,672✔
536
    
537
    if (isRowEntryCompleted(pResInfo) && isRowEntryInitialized(pResInfo)) {
252,582,672!
538
      continue;
×
539
    }
540

541
    if (pCtx[i].isPseudoFunc) {
252,582,672✔
542
      continue;
52,478,594✔
543
    }
544

545
    if (!pResInfo->initialized) {
200,104,078✔
546
      if (pCtx[i].functionId != -1) {
193,149,308✔
547
        int32_t code = pCtx[i].fpSet.init(&pCtx[i], pResInfo);
170,455,991✔
548
        if (code != TSDB_CODE_SUCCESS && fmIsUserDefinedFunc(pCtx[i].functionId)) {
170,344,295!
549
          pResInfo->initialized = false;
325,250✔
550
          qError("failed to initialize udf, funcId:%d error:%s", pCtx[i].functionId, tstrerror(code));
325,250!
551
          return TSDB_CODE_UDF_FUNC_EXEC_FAILURE;
×
552
        } else if (code != TSDB_CODE_SUCCESS) {
170,019,045!
553
          qError("failed to initialize function context, funcId:%d error:%s", pCtx[i].functionId, tstrerror(code));
×
554
          return code;
×
555
        }
556
      } else {
557
        pResInfo->initialized = true;
22,693,317✔
558
      }
559
    } else {
560
      init = true;
6,954,770✔
561
    }
562
  }
563
  return TSDB_CODE_SUCCESS;
63,951,516✔
564
}
565

566
void clearResultRowInitFlag(SqlFunctionCtx* pCtx, int32_t numOfOutput) {
702✔
567
  for (int32_t i = 0; i < numOfOutput; ++i) {
2,942✔
568
    SResultRowEntryInfo* pResInfo = pCtx[i].resultInfo;
2,240✔
569
    if (pResInfo == NULL) {
2,240!
570
      continue;
×
571
    }
572

573
    pResInfo->initialized = false;
2,240✔
574
    pResInfo->numOfRes = 0;
2,240✔
575
    pResInfo->isNullRes = 0;
2,240✔
576
    pResInfo->complete = false;
2,240✔
577
  }
578
}
702✔
579

580
int32_t doFilter(SSDataBlock* pBlock, SFilterInfo* pFilterInfo, SColMatchInfo* pColMatchInfo) {
9,082,014✔
581
  int32_t code = TSDB_CODE_SUCCESS;
9,082,014✔
582
  int32_t lino = 0;
9,082,014✔
583
  if (pFilterInfo == NULL || pBlock->info.rows == 0) {
9,082,014✔
584
    return TSDB_CODE_SUCCESS;
8,171,142✔
585
  }
586

587
  SFilterColumnParam param1 = {.numOfCols = taosArrayGetSize(pBlock->pDataBlock), .pDataBlock = pBlock->pDataBlock};
910,872✔
588
  SColumnInfoData*   p = NULL;
910,834✔
589

590
  code = filterSetDataFromSlotId(pFilterInfo, &param1);
910,834✔
591
  QUERY_CHECK_CODE(code, lino, _err);
910,761!
592

593
  int32_t status = 0;
910,761✔
594
  code =
595
      filterExecute(pFilterInfo, pBlock, &p, NULL, param1.numOfCols, &status);
910,761✔
596
  QUERY_CHECK_CODE(code, lino, _err);
910,711✔
597

598
  code = extractQualifiedTupleByFilterResult(pBlock, p, status);
910,710✔
599
  QUERY_CHECK_CODE(code, lino, _err);
910,737!
600

601
  if (pColMatchInfo != NULL) {
910,737✔
602
    size_t size = taosArrayGetSize(pColMatchInfo->pList);
643,215✔
603
    for (int32_t i = 0; i < size; ++i) {
644,026✔
604
      SColMatchItem* pInfo = taosArrayGet(pColMatchInfo->pList, i);
643,223✔
605
      QUERY_CHECK_NULL(pInfo, code, lino, _err, terrno);
643,245!
606
      if (pInfo->colId == PRIMARYKEY_TIMESTAMP_COL_ID) {
643,245✔
607
        SColumnInfoData* pColData = taosArrayGet(pBlock->pDataBlock, pInfo->dstSlotId);
642,459✔
608
        QUERY_CHECK_NULL(pColData, code, lino, _err, terrno);
642,450!
609
        if (pColData->info.type == TSDB_DATA_TYPE_TIMESTAMP) {
642,475✔
610
          code = blockDataUpdateTsWindow(pBlock, pInfo->dstSlotId);
642,459✔
611
          QUERY_CHECK_CODE(code, lino, _err);
642,447!
612
          break;
642,447✔
613
        }
614
      }
615
    }
616
  }
617
  code = blockDataCheck(pBlock);
910,772✔
618
  QUERY_CHECK_CODE(code, lino, _err);
910,737!
619
_err:
910,737✔
620
  if (code != TSDB_CODE_SUCCESS) {
910,738✔
621
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
1!
622
  }
623
  colDataDestroy(p);
910,738✔
624
  taosMemoryFree(p);
910,903!
625
  return code;
910,906✔
626
}
627

628
int32_t extractQualifiedTupleByFilterResult(SSDataBlock* pBlock, const SColumnInfoData* p, int32_t status) {
911,187✔
629
  int32_t code = TSDB_CODE_SUCCESS;
911,187✔
630
  int8_t* pIndicator = (int8_t*)p->pData;
911,187✔
631
  if (status == FILTER_RESULT_ALL_QUALIFIED) {
911,187✔
632
    // here nothing needs to be done
633
  } else if (status == FILTER_RESULT_NONE_QUALIFIED) {
442,473✔
634
    code = trimDataBlock(pBlock, pBlock->info.rows, NULL);
142,252✔
635
    pBlock->info.rows = 0;
142,227✔
636
  } else if (status == FILTER_RESULT_PARTIAL_QUALIFIED) {
300,221!
637
    code = trimDataBlock(pBlock, pBlock->info.rows, (bool*)pIndicator);
300,259✔
638
  } else {
639
    qError("unknown filter result type: %d", status);
×
640
  }
641
  return code;
911,351✔
642
}
643

644
void doUpdateNumOfRows(SqlFunctionCtx* pCtx, SResultRow* pRow, int32_t numOfExprs, const int32_t* rowEntryOffset) {
59,194,836✔
645
  bool returnNotNull = false;
59,194,836✔
646
  for (int32_t j = 0; j < numOfExprs; ++j) {
306,418,492✔
647
    SResultRowEntryInfo* pResInfo = getResultEntryInfo(pRow, j, rowEntryOffset);
247,276,959✔
648
    if (!isRowEntryInitialized(pResInfo)) {
247,223,656✔
649
      continue;
48,457,646✔
650
    } else {
651
    }
652

653
    if (pRow->numOfRows < pResInfo->numOfRes) {
198,766,010✔
654
      pRow->numOfRows = pResInfo->numOfRes;
54,442,228✔
655
    }
656

657
    if (pCtx[j].isNotNullFunc) {
198,766,010✔
658
      returnNotNull = true;
43,351,229✔
659
    }
660
  }
661
  // if all expr skips all blocks, e.g. all null inputs for max function, output one row in final result.
662
  //  except for first/last, which require not null output, output no rows
663
  if (pRow->numOfRows == 0 && !returnNotNull) {
59,141,533✔
664
    pRow->numOfRows = 1;
36,692✔
665
  }
666
}
59,141,533✔
667

668
int32_t copyResultrowToDataBlock(SExprInfo* pExprInfo, int32_t numOfExprs, SResultRow* pRow, SqlFunctionCtx* pCtx,
54,289,482✔
669
                                 SSDataBlock* pBlock, const int32_t* rowEntryOffset, SExecTaskInfo* pTaskInfo) {
670
  int32_t code = TSDB_CODE_SUCCESS;
54,289,482✔
671
  int32_t lino = 0;
54,289,482✔
672
  for (int32_t j = 0; j < numOfExprs; ++j) {
293,087,955✔
673
    int32_t slotId = pExprInfo[j].base.resSchema.slotId;
237,871,388✔
674

675
    pCtx[j].resultInfo = getResultEntryInfo(pRow, j, rowEntryOffset);
237,871,388✔
676
    if (pCtx[j].fpSet.finalize) {
237,993,214✔
677
      if (strcmp(pCtx[j].pExpr->pExpr->_function.functionName, "_group_key") == 0 ||
169,226,651✔
678
          strcmp(pCtx[j].pExpr->pExpr->_function.functionName, "_group_const_value") == 0) {
84,152,797✔
679
        // for groupkey along with functions that output multiple lines(e.g. Histogram)
680
        // need to match groupkey result for each output row of that function.
681
        if (pCtx[j].resultInfo->numOfRes != 0) {
85,127,761!
682
          pCtx[j].resultInfo->numOfRes = pRow->numOfRows;
86,211,775✔
683
        }
684
      }
685

686
      code = pCtx[j].fpSet.finalize(&pCtx[j], pBlock);
169,226,651✔
687
      if (TSDB_CODE_SUCCESS != code) {
170,563,280!
688
        qError("%s build result data block error, code %s", GET_TASKID(pTaskInfo), tstrerror(code));
×
689
        QUERY_CHECK_CODE(code, lino, _end);
×
690
      }
691
    } else if (strcmp(pCtx[j].pExpr->pExpr->_function.functionName, "_select_value") == 0) {
68,766,563!
692
      // do nothing
693
    } else {
694
      // expand the result into multiple rows. E.g., _wstart, top(k, 20)
695
      // the _wstart needs to copy to 20 following rows, since the results of top-k expands to 20 different rows.
696
      SColumnInfoData* pColInfoData = taosArrayGet(pBlock->pDataBlock, slotId);
70,096,560✔
697
      QUERY_CHECK_NULL(pColInfoData, code, lino, _end, terrno);
69,860,248!
698
      char*            in = GET_ROWCELL_INTERBUF(pCtx[j].resultInfo);
69,875,610✔
699
      for (int32_t k = 0; k < pRow->numOfRows; ++k) {        
139,876,472✔
700
        code = colDataSetValOrCover(pColInfoData, pBlock->info.rows + k, in, pCtx[j].resultInfo->isNullRes);
69,834,276✔
701
        QUERY_CHECK_CODE(code, lino, _end);
70,000,862!
702
      }
703
    }
704
  }
705

706
_end:
55,216,567✔
707
  if (code != TSDB_CODE_SUCCESS) {
55,216,567!
708
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
×
709
  }
710
  return code;
55,501,330✔
711
}
712

713
// todo refactor. SResultRow has direct pointer in miainfo
714
void finalizeResultRows(SDiskbasedBuf* pBuf, SResultRowPosition* resultRowPosition, SExprSupp* pSup,
3,859,530✔
715
                        SSDataBlock* pBlock, SExecTaskInfo* pTaskInfo) {
716
  SFilePage* page = getBufPage(pBuf, resultRowPosition->pageId);
3,859,530✔
717
  if (page == NULL) {
3,858,058!
718
    qError("failed to get buffer, code:%s, %s", tstrerror(terrno), GET_TASKID(pTaskInfo));
×
719
    T_LONG_JMP(pTaskInfo->env, terrno);
×
720
  }
721

722
  SResultRow* pRow = (SResultRow*)((char*)page + resultRowPosition->offset);
3,858,058✔
723

724
  SqlFunctionCtx* pCtx = pSup->pCtx;
3,858,058✔
725
  SExprInfo*      pExprInfo = pSup->pExprInfo;
3,858,058✔
726
  const int32_t*  rowEntryOffset = pSup->rowEntryInfoOffset;
3,858,058✔
727

728
  doUpdateNumOfRows(pCtx, pRow, pSup->numOfExprs, rowEntryOffset);
3,858,058✔
729
  if (pRow->numOfRows == 0) {
3,851,562!
730
    releaseBufPage(pBuf, page);
×
731
    return;
×
732
  }
733

734
  int32_t size = pBlock->info.capacity;
3,851,646✔
735
  while (pBlock->info.rows + pRow->numOfRows > size) {
3,852,172✔
736
    size = size * 1.25;
526✔
737
  }
738

739
  int32_t code = blockDataEnsureCapacity(pBlock, size);
3,851,646✔
740
  if (TAOS_FAILED(code)) {
3,852,480!
741
    releaseBufPage(pBuf, page);
×
742
    qError("%s ensure result data capacity failed, code %s", GET_TASKID(pTaskInfo), tstrerror(code));
×
743
    T_LONG_JMP(pTaskInfo->env, code);
×
744
  }
745

746
  code = copyResultrowToDataBlock(pExprInfo, pSup->numOfExprs, pRow, pCtx, pBlock, rowEntryOffset, pTaskInfo);
3,852,480✔
747
  if (TAOS_FAILED(code)) {
3,853,776!
748
    releaseBufPage(pBuf, page);
×
749
    qError("%s copy result row to datablock failed, code %s", GET_TASKID(pTaskInfo), tstrerror(code));
×
750
    T_LONG_JMP(pTaskInfo->env, code);
×
751
  }
752

753
  releaseBufPage(pBuf, page);
3,853,776✔
754
  pBlock->info.rows += pRow->numOfRows;
3,852,380✔
755
}
756

757
void doCopyToSDataBlockByHash(SExecTaskInfo* pTaskInfo, SSDataBlock* pBlock, SExprSupp* pSup, SDiskbasedBuf* pBuf,
4,064,472✔
758
                              SGroupResInfo* pGroupResInfo, SSHashObj* pHashmap, int32_t threshold, bool ignoreGroup) {
759
  int32_t         code = TSDB_CODE_SUCCESS;
4,064,472✔
760
  int32_t         lino = 0;
4,064,472✔
761
  SExprInfo*      pExprInfo = pSup->pExprInfo;
4,064,472✔
762
  int32_t         numOfExprs = pSup->numOfExprs;
4,064,472✔
763
  int32_t*        rowEntryOffset = pSup->rowEntryInfoOffset;
4,064,472✔
764
  SqlFunctionCtx* pCtx = pSup->pCtx;
4,064,472✔
765

766
  size_t  keyLen = 0;
4,064,472✔
767
  int32_t numOfRows = tSimpleHashGetSize(pHashmap);
4,064,472✔
768

769
  // begin from last iter
770
  void*   pData = pGroupResInfo->dataPos;
4,064,101✔
771
  int32_t iter = pGroupResInfo->iter;
4,064,101✔
772
  while ((pData = tSimpleHashIterate(pHashmap, pData, &iter)) != NULL) {
10,987,731✔
773
    void*               key = tSimpleHashGetKey(pData, &keyLen);
10,803,097✔
774
    SResultRowPosition* pos = pData;
10,803,097✔
775
    uint64_t            groupId = *(uint64_t*)key;
10,803,097✔
776

777
    SFilePage* page = getBufPage(pBuf, pos->pageId);
10,803,097✔
778
    if (page == NULL) {
10,803,062!
779
      qError("failed to get buffer, code:%s, %s", tstrerror(terrno), GET_TASKID(pTaskInfo));
×
780
      T_LONG_JMP(pTaskInfo->env, terrno);
×
781
    }
782

783
    SResultRow* pRow = (SResultRow*)((char*)page + pos->offset);
10,803,062✔
784

785
    doUpdateNumOfRows(pCtx, pRow, numOfExprs, rowEntryOffset);
10,803,062✔
786

787
    // no results, continue to check the next one
788
    if (pRow->numOfRows == 0) {
10,801,919!
789
      pGroupResInfo->index += 1;
×
790
      pGroupResInfo->iter = iter;
×
791
      pGroupResInfo->dataPos = pData;
×
792

793
      releaseBufPage(pBuf, page);
×
794
      continue;
×
795
    }
796

797
    if (!ignoreGroup) {
10,801,919✔
798
      if (pBlock->info.id.groupId == 0) {
7,805,035✔
799
        pBlock->info.id.groupId = groupId;
3,926,700✔
800
      } else {
801
        // current value belongs to different group, it can't be packed into one datablock
802
        if (pBlock->info.id.groupId != groupId) {
3,878,335!
803
          releaseBufPage(pBuf, page);
3,879,937✔
804
          break;
3,879,923✔
805
        }
806
      }
807
    }
808

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

818
    pGroupResInfo->index += 1;
6,921,982✔
819
    pGroupResInfo->iter = iter;
6,921,982✔
820
    pGroupResInfo->dataPos = pData;
6,921,982✔
821

822
    code = copyResultrowToDataBlock(pExprInfo, numOfExprs, pRow, pCtx, pBlock, rowEntryOffset, pTaskInfo);
6,921,982✔
823
    releaseBufPage(pBuf, page);
6,923,742✔
824
    QUERY_CHECK_CODE(code, lino, _end);
6,923,630!
825
    pBlock->info.rows += pRow->numOfRows;
6,923,630✔
826
    if (pBlock->info.rows >= threshold) {
6,923,630!
827
      break;
×
828
    }
829
  }
830

831
  qDebug("%s result generated, rows:%" PRId64 ", groupId:%" PRIu64, GET_TASKID(pTaskInfo), pBlock->info.rows,
4,063,990✔
832
         pBlock->info.id.groupId);
833
  pBlock->info.dataLoad = 1;
4,064,707✔
834
  code = blockDataUpdateTsWindow(pBlock, 0);
4,064,707✔
835
  QUERY_CHECK_CODE(code, lino, _end);
4,064,450!
836

837
_end:
4,064,450✔
838
  if (code != TSDB_CODE_SUCCESS) {
4,064,450!
839
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
×
840
    T_LONG_JMP(pTaskInfo->env, code);
×
841
  }
842
}
4,064,450✔
843

844
void doCopyToSDataBlock(SExecTaskInfo* pTaskInfo, SSDataBlock* pBlock, SExprSupp* pSup, SDiskbasedBuf* pBuf,
580,253✔
845
                        SGroupResInfo* pGroupResInfo, int32_t threshold, bool ignoreGroup, int64_t minWindowSize) {
846
  int32_t         code = TSDB_CODE_SUCCESS;
580,253✔
847
  int32_t         lino = 0;
580,253✔
848
  SExprInfo*      pExprInfo = pSup->pExprInfo;
580,253✔
849
  int32_t         numOfExprs = pSup->numOfExprs;
580,253✔
850
  int32_t*        rowEntryOffset = pSup->rowEntryInfoOffset;
580,253✔
851
  SqlFunctionCtx* pCtx = pSup->pCtx;
580,253✔
852

853
  int32_t numOfRows = getNumOfTotalRes(pGroupResInfo);
580,253✔
854

855
  for (int32_t i = pGroupResInfo->index; i < numOfRows; i += 1) {
45,115,700✔
856
    SResKeyPos* pPos = taosArrayGetP(pGroupResInfo->pRows, i);
44,742,266✔
857
    SFilePage*  page = getBufPage(pBuf, pPos->pos.pageId);
44,690,497✔
858
    if (page == NULL) {
44,665,655!
859
      qError("failed to get buffer, code:%s, %s", tstrerror(terrno), GET_TASKID(pTaskInfo));
×
860
      T_LONG_JMP(pTaskInfo->env, terrno);
×
861
    }
862

863
    SResultRow* pRow = (SResultRow*)((char*)page + pPos->pos.offset);
44,665,655✔
864

865
    doUpdateNumOfRows(pCtx, pRow, numOfExprs, rowEntryOffset);
44,665,655✔
866

867
    // no results, continue to check the next one
868
    if (pRow->numOfRows == 0) {
43,653,172!
869
      pGroupResInfo->index += 1;
×
870
      releaseBufPage(pBuf, page);
×
871
      continue;
593✔
872
    }
873
    // skip the window which is less than the windowMinSize
874
    if (pRow->win.ekey - pRow->win.skey < minWindowSize) {
43,663,519✔
875
      qDebug("skip small window, groupId: %" PRId64 ", windowSize: %" PRId64 ", minWindowSize: %" PRId64, pPos->groupId,
12!
876
             pRow->win.ekey - pRow->win.skey, minWindowSize);
877
      pGroupResInfo->index += 1;
12✔
878
      releaseBufPage(pBuf, page);
12✔
879
      continue;
12✔
880
    }
881

882
    if (!ignoreGroup) {
43,663,507✔
883
      if (pBlock->info.id.groupId == 0) {
8,927,698✔
884
        pBlock->info.id.groupId = pPos->groupId;
1,624,137✔
885
      } else {
886
        // current value belongs to different group, it can't be packed into one datablock
887
        if (pBlock->info.id.groupId != pPos->groupId) {
7,303,561✔
888
          releaseBufPage(pBuf, page);
97,895✔
889
          break;
97,895✔
890
        }
891
      }
892
    }
893

894
    if (pBlock->info.rows + pRow->numOfRows > pBlock->info.capacity) {
43,565,612!
895
      uint32_t newSize = pBlock->info.rows + pRow->numOfRows + ((numOfRows - i) > 1 ? 1 : 0);
×
896
      code = blockDataEnsureCapacity(pBlock, newSize);
×
897
      QUERY_CHECK_CODE(code, lino, _end);
×
898
      qDebug("datablock capacity not sufficient, expand to required:%d, current capacity:%d, %s", newSize,
×
899
             pBlock->info.capacity, GET_TASKID(pTaskInfo));
900
      // todo set the pOperator->resultInfo size
901
    }
902

903
    pGroupResInfo->index += 1;
43,565,612✔
904
    code = copyResultrowToDataBlock(pExprInfo, numOfExprs, pRow, pCtx, pBlock, rowEntryOffset, pTaskInfo);
43,565,612✔
905
    releaseBufPage(pBuf, page);
44,854,946✔
906
    QUERY_CHECK_CODE(code, lino, _end);
44,643,298!
907

908
    pBlock->info.rows += pRow->numOfRows;
44,643,298✔
909
    if (pBlock->info.rows >= threshold) {
44,643,298✔
910
      break;
108,461✔
911
    }
912
  }
913

914
  qDebug("%s result generated, rows:%" PRId64 ", groupId:%" PRIu64, GET_TASKID(pTaskInfo), pBlock->info.rows,
579,790✔
915
         pBlock->info.id.groupId);
916
  pBlock->info.dataLoad = 1;
579,871✔
917
  code = blockDataUpdateTsWindow(pBlock, 0);
579,871✔
918
  QUERY_CHECK_CODE(code, lino, _end);
580,290!
919

920
_end:
580,290✔
921
  if (code != TSDB_CODE_SUCCESS) {
580,290!
922
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
×
923
    T_LONG_JMP(pTaskInfo->env, code);
×
924
  }
925
}
580,290✔
926

927
void doBuildResultDatablock(SOperatorInfo* pOperator, SOptrBasicInfo* pbInfo, SGroupResInfo* pGroupResInfo,
666,762✔
928
                            SDiskbasedBuf* pBuf) {
929
  SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
666,762✔
930
  SSDataBlock*   pBlock = pbInfo->pRes;
666,762✔
931

932
  // set output datablock version
933
  pBlock->info.version = pTaskInfo->version;
666,762✔
934

935
  blockDataCleanup(pBlock);
666,762✔
936
  if (!hasRemainResults(pGroupResInfo)) {
666,796✔
937
    return;
86,521✔
938
  }
939

940
  // clear the existed group id
941
  pBlock->info.id.groupId = 0;
580,273✔
942
  if (!pbInfo->mergeResultBlock) {
580,273✔
943
    doCopyToSDataBlock(pTaskInfo, pBlock, &pOperator->exprSupp, pBuf, pGroupResInfo, pOperator->resultInfo.threshold,
216,819✔
944
                       false, getMinWindowSize(pOperator));
945
  } else {
946
    while (hasRemainResults(pGroupResInfo)) {
636,479✔
947
      doCopyToSDataBlock(pTaskInfo, pBlock, &pOperator->exprSupp, pBuf, pGroupResInfo, pOperator->resultInfo.threshold,
363,429✔
948
                         true, getMinWindowSize(pOperator));
949
      if (pBlock->info.rows >= pOperator->resultInfo.threshold) {
363,459✔
950
        break;
90,434✔
951
      }
952

953
      // clearing group id to continue to merge data that belong to different groups
954
      pBlock->info.id.groupId = 0;
273,025✔
955
    }
956

957
    // clear the group id info in SSDataBlock, since the client does not need it
958
    pBlock->info.id.groupId = 0;
363,458✔
959
  }
960
}
961

962
void destroyExprInfo(SExprInfo* pExpr, int32_t numOfExprs) {
1,915,213✔
963
  for (int32_t i = 0; i < numOfExprs; ++i) {
7,082,941✔
964
    SExprInfo* pExprInfo = &pExpr[i];
5,167,561✔
965
    for (int32_t j = 0; j < pExprInfo->base.numOfParams; ++j) {
11,319,057✔
966
      if (pExprInfo->base.pParam[j].type == FUNC_PARAM_TYPE_COLUMN) {
6,151,714✔
967
        taosMemoryFreeClear(pExprInfo->base.pParam[j].pCol);
4,647,112!
968
      } else if (pExprInfo->base.pParam[j].type == FUNC_PARAM_TYPE_VALUE) {
1,504,602✔
969
        taosVariantDestroy(&pExprInfo->base.pParam[j].param);
814,365✔
970
      }
971
    }
972

973
    taosMemoryFree(pExprInfo->base.pParam);
5,167,343!
974
    taosMemoryFree(pExprInfo->pExpr);
5,167,482!
975
  }
976
}
1,915,380✔
977

978
int32_t getBufferPgSize(int32_t rowSize, uint32_t* defaultPgsz, int64_t* defaultBufsz) {
1,241,773✔
979
  *defaultPgsz = 4096;
1,241,773✔
980
  uint32_t last = *defaultPgsz;
1,241,773✔
981
  while (*defaultPgsz < rowSize * 4) {
1,625,675✔
982
    *defaultPgsz <<= 1u;
383,902✔
983
    if (*defaultPgsz < last) {
383,902!
984
      return TSDB_CODE_INVALID_PARA;
×
985
    }
986
    last = *defaultPgsz;
383,902✔
987
  }
988

989
  // The default buffer for each operator in query is 10MB.
990
  // at least four pages need to be in buffer
991
  // TODO: make this variable to be configurable.
992
  *defaultBufsz = 4096 * 2560;
1,241,773✔
993
  if ((*defaultBufsz) <= (*defaultPgsz)) {
1,241,773!
994
    (*defaultBufsz) = (*defaultPgsz) * 4;
×
995
    if (*defaultBufsz < ((int64_t)(*defaultPgsz)) * 4) {
×
996
      return TSDB_CODE_INVALID_PARA;
×
997
    }
998
  }
999

1000
  return 0;
1,241,773✔
1001
}
1002

1003
void initResultSizeInfo(SResultInfo* pResultInfo, int32_t numOfRows) {
2,641,597✔
1004
  if (numOfRows == 0) {
2,641,597!
1005
    numOfRows = 4096;
×
1006
  }
1007

1008
  pResultInfo->capacity = numOfRows;
2,641,597✔
1009
  pResultInfo->threshold = numOfRows * 0.75;
2,641,597✔
1010

1011
  if (pResultInfo->threshold == 0) {
2,641,597✔
1012
    pResultInfo->threshold = numOfRows;
5,124✔
1013
  }
1014
  pResultInfo->totalRows = 0;
2,641,597✔
1015
}
2,641,597✔
1016

1017
void initBasicInfo(SOptrBasicInfo* pInfo, SSDataBlock* pBlock) {
1,204,047✔
1018
  pInfo->pRes = pBlock;
1,204,047✔
1019
  initResultRowInfo(&pInfo->resultRowInfo);
1,204,047✔
1020
}
1,204,019✔
1021

1022
void destroySqlFunctionCtx(SqlFunctionCtx* pCtx, SExprInfo* pExpr, int32_t numOfOutput) {
5,265,068✔
1023
  if (pCtx == NULL) {
5,265,068✔
1024
    return;
3,215,546✔
1025
  }
1026

1027
  for (int32_t i = 0; i < numOfOutput; ++i) {
7,180,455✔
1028
    if (pExpr != NULL) {
5,130,794✔
1029
      SExprInfo* pExprInfo = &pExpr[i];
5,130,716✔
1030
      for (int32_t j = 0; j < pExprInfo->base.numOfParams; ++j) {
11,243,702✔
1031
        if (pExprInfo->base.pParam[j].type == FUNC_PARAM_TYPE_VALUE) {
6,113,174✔
1032
          colDataDestroy(pCtx[i].input.pData[j]);
811,561✔
1033
          taosMemoryFree(pCtx[i].input.pData[j]);
811,542!
1034
          taosMemoryFree(pCtx[i].input.pColumnDataAgg[j]);
811,545!
1035
        }
1036
      }
1037
    }
1038
    for (int32_t j = 0; j < pCtx[i].numOfParams; ++j) {
11,243,625✔
1039
      taosVariantDestroy(&pCtx[i].param[j].param);
6,113,004✔
1040
    }
1041

1042
    taosMemoryFreeClear(pCtx[i].subsidiaries.pCtx);
5,130,621!
1043
    taosMemoryFreeClear(pCtx[i].subsidiaries.buf);
5,130,622!
1044
    taosMemoryFree(pCtx[i].input.pData);
5,130,622✔
1045
    taosMemoryFree(pCtx[i].input.pColumnDataAgg);
5,131,085!
1046

1047
    if (pCtx[i].udfName != NULL) {
5,130,952✔
1048
      taosMemoryFree(pCtx[i].udfName);
85!
1049
    }
1050
  }
1051

1052
  taosMemoryFreeClear(pCtx);
2,049,661!
1053
  return;
2,049,640✔
1054
}
1055

1056
int32_t initExprSupp(SExprSupp* pSup, SExprInfo* pExprInfo, int32_t numOfExpr, SFunctionStateStore* pStore) {
1,963,440✔
1057
  pSup->pExprInfo = pExprInfo;
1,963,440✔
1058
  pSup->numOfExprs = numOfExpr;
1,963,440✔
1059
  if (pSup->pExprInfo != NULL) {
1,963,440✔
1060
    pSup->pCtx = createSqlFunctionCtx(pExprInfo, numOfExpr, &pSup->rowEntryInfoOffset, pStore);
1,534,369✔
1061
    if (pSup->pCtx == NULL) {
1,534,185!
1062
      return terrno;
×
1063
    }
1064
  }
1065

1066
  return TSDB_CODE_SUCCESS;
1,963,293✔
1067
}
1068

1069
void cleanupExprSupp(SExprSupp* pSupp) {
4,797,964✔
1070
  destroySqlFunctionCtx(pSupp->pCtx, pSupp->pExprInfo, pSupp->numOfExprs);
4,797,964✔
1071
  if (pSupp->pExprInfo != NULL) {
4,797,996✔
1072
    destroyExprInfo(pSupp->pExprInfo, pSupp->numOfExprs);
1,780,668✔
1073
    taosMemoryFreeClear(pSupp->pExprInfo);
1,780,686!
1074
  }
1075

1076
  if (pSupp->pFilterInfo != NULL) {
4,798,046✔
1077
    filterFreeInfo(pSupp->pFilterInfo);
391,702✔
1078
    pSupp->pFilterInfo = NULL;
391,704✔
1079
  }
1080

1081
  taosMemoryFree(pSupp->rowEntryInfoOffset);
4,798,048✔
1082
  memset(pSupp, 0, sizeof(SExprSupp));
4,797,977✔
1083
}
4,797,977✔
1084

1085
void cleanupExprSuppWithoutFilter(SExprSupp* pSupp) {
467,170✔
1086
  destroySqlFunctionCtx(pSupp->pCtx, pSupp->pExprInfo, pSupp->numOfExprs);
467,170✔
1087
  if (pSupp->pExprInfo != NULL) {
467,173✔
1088
    destroyExprInfo(pSupp->pExprInfo, pSupp->numOfExprs);
132,375✔
1089
    taosMemoryFreeClear(pSupp->pExprInfo);
132,375!
1090
  }
1091

1092
  taosMemoryFreeClear(pSupp->rowEntryInfoOffset);
467,183!
1093
  pSupp->numOfExprs = 0;
467,187✔
1094
  pSupp->hasWindowOrGroup = false;
467,187✔
1095
  pSupp->pCtx = NULL;
467,187✔
1096
}
467,187✔
1097

1098
void cleanupBasicInfo(SOptrBasicInfo* pInfo) {
1,213,850✔
1099
  blockDataDestroy(pInfo->pRes);
1,213,850✔
1100
  pInfo->pRes = NULL;
1,213,961✔
1101
}
1,213,961✔
1102

1103
bool groupbyTbname(SNodeList* pGroupList) {
1,092,008✔
1104
  bool   bytbname = false;
1,092,008✔
1105
  SNode* pNode = NULL;
1,092,008✔
1106
  FOREACH(pNode, pGroupList) {
1,136,066✔
1107
    if (pNode->type == QUERY_NODE_FUNCTION) {
256,998✔
1108
      bytbname = (strcmp(((struct SFunctionNode*)pNode)->functionName, "tbname") == 0);
212,940✔
1109
      break;
212,940✔
1110
    }
1111
  }
1112
  return bytbname;
1,092,008✔
1113
}
1114

1115
int32_t createDataSinkParam(SDataSinkNode* pNode, void** pParam, SExecTaskInfo* pTask, SReadHandle* readHandle) {
1,598,358✔
1116
  switch (pNode->type) {
1,598,358✔
1117
    case QUERY_NODE_PHYSICAL_PLAN_QUERY_INSERT: {
180✔
1118
      SInserterParam* pInserterParam = taosMemoryCalloc(1, sizeof(SInserterParam));
180!
1119
      if (NULL == pInserterParam) {
180!
1120
        return terrno;
×
1121
      }
1122
      pInserterParam->readHandle = readHandle;
180✔
1123

1124
      *pParam = pInserterParam;
180✔
1125
      break;
180✔
1126
    }
1127
    case QUERY_NODE_PHYSICAL_PLAN_DELETE: {
7,004✔
1128
      SDeleterParam* pDeleterParam = taosMemoryCalloc(1, sizeof(SDeleterParam));
7,004!
1129
      if (NULL == pDeleterParam) {
7,004!
1130
        return terrno;
×
1131
      }
1132

1133
      SArray* pInfoList = NULL;
7,004✔
1134
      int32_t code = getTableListInfo(pTask, &pInfoList);
7,004✔
1135
      if (code != TSDB_CODE_SUCCESS || pInfoList == NULL) {
7,004!
UNCOV
1136
        taosMemoryFree(pDeleterParam);
×
1137
        return code;
×
1138
      }
1139

1140
      STableListInfo* pTableListInfo = taosArrayGetP(pInfoList, 0);
7,004✔
1141
      taosArrayDestroy(pInfoList);
7,004✔
1142

1143
      pDeleterParam->suid = tableListGetSuid(pTableListInfo);
7,004✔
1144

1145
      // TODO extract uid list
1146
      int32_t numOfTables = 0;
7,005✔
1147
      code = tableListGetSize(pTableListInfo, &numOfTables);
7,005✔
1148
      if (code != TSDB_CODE_SUCCESS) {
7,005!
1149
        qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(code));
×
1150
        taosMemoryFree(pDeleterParam);
×
1151
        return code;
×
1152
      }
1153

1154
      pDeleterParam->pUidList = taosArrayInit(numOfTables, sizeof(uint64_t));
7,005✔
1155
      if (NULL == pDeleterParam->pUidList) {
7,004!
UNCOV
1156
        taosMemoryFree(pDeleterParam);
×
1157
        return terrno;
×
1158
      }
1159

1160
      for (int32_t i = 0; i < numOfTables; ++i) {
14,470✔
1161
        STableKeyInfo* pTable = tableListGetInfo(pTableListInfo, i);
7,465✔
1162
        if (!pTable) {
7,465!
1163
          taosArrayDestroy(pDeleterParam->pUidList);
×
1164
          taosMemoryFree(pDeleterParam);
×
1165
          return TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR;
×
1166
        }
1167
        void* tmp = taosArrayPush(pDeleterParam->pUidList, &pTable->uid);
7,465✔
1168
        if (!tmp) {
7,465!
1169
          taosArrayDestroy(pDeleterParam->pUidList);
×
1170
          taosMemoryFree(pDeleterParam);
×
1171
          return terrno;
×
1172
        }
1173
      }
1174

1175
      *pParam = pDeleterParam;
7,005✔
1176
      break;
7,005✔
1177
    }
1178
    default:
1,591,174✔
1179
      break;
1,591,174✔
1180
  }
1181

1182
  return TSDB_CODE_SUCCESS;
1,598,359✔
1183
}
1184

1185
void streamOpReleaseState(SOperatorInfo* pOperator) {
×
1186
  SOperatorInfo* downstream = pOperator->pDownstream[0];
×
1187
  if (downstream->fpSet.releaseStreamStateFn) {
×
1188
    downstream->fpSet.releaseStreamStateFn(downstream);
×
1189
  }
1190
}
×
1191

1192
void streamOpReloadState(SOperatorInfo* pOperator) {
×
1193
  SOperatorInfo* downstream = pOperator->pDownstream[0];
×
1194
  if (downstream->fpSet.reloadStreamStateFn) {
×
1195
    downstream->fpSet.reloadStreamStateFn(downstream);
×
1196
  }
1197
}
×
1198

1199
void freeOperatorParamImpl(SOperatorParam* pParam, SOperatorParamType type) {
86,801✔
1200
  int32_t childrenNum = taosArrayGetSize(pParam->pChildren);
86,801✔
1201
  for (int32_t i = 0; i < childrenNum; ++i) {
86,801!
1202
    SOperatorParam* pChild = taosArrayGetP(pParam->pChildren, i);
×
1203
    freeOperatorParam(pChild, type);
×
1204
  }
1205

1206
  taosArrayDestroy(pParam->pChildren);
86,801✔
1207
  pParam->pChildren = NULL;
86,801✔
1208

1209
  taosMemoryFreeClear(pParam->value);
86,801!
1210

1211
  taosMemoryFree(pParam);
86,801!
1212
}
86,801✔
1213

1214
void freeExchangeGetBasicOperatorParam(void* pParam) {
1,023✔
1215
  SExchangeOperatorBasicParam* pBasic = (SExchangeOperatorBasicParam*)pParam;
1,023✔
1216
  taosArrayDestroy(pBasic->uidList);
1,023✔
1217
  if (pBasic->colMap) {
1,023✔
1218
    taosArrayDestroy(pBasic->colMap->colMap);
57✔
1219
    taosMemoryFreeClear(pBasic->colMap);
57!
1220
  }
1221
}
1,023✔
1222

1223
void freeExchangeGetOperatorParam(SOperatorParam* pParam) {
660✔
1224
  SExchangeOperatorParam* pExcParam = (SExchangeOperatorParam*)pParam->value;
660✔
1225
  if (pExcParam->multiParams) {
660✔
1226
    SExchangeOperatorBatchParam* pExcBatch = (SExchangeOperatorBatchParam*)pParam->value;
543✔
1227
    tSimpleHashCleanup(pExcBatch->pBatchs);
543✔
1228
  } else {
1229
    freeExchangeGetBasicOperatorParam(&pExcParam->basic);
117✔
1230
  }
1231

1232
  freeOperatorParamImpl(pParam, OP_GET_PARAM);
660✔
1233
}
660✔
1234

1235
void freeExchangeNotifyOperatorParam(SOperatorParam* pParam) { freeOperatorParamImpl(pParam, OP_NOTIFY_PARAM); }
×
1236

1237
void freeGroupCacheGetOperatorParam(SOperatorParam* pParam) { freeOperatorParamImpl(pParam, OP_GET_PARAM); }
55,700✔
1238

1239
void freeGroupCacheNotifyOperatorParam(SOperatorParam* pParam) { freeOperatorParamImpl(pParam, OP_NOTIFY_PARAM); }
×
1240

1241
void freeMergeJoinGetOperatorParam(SOperatorParam* pParam) { freeOperatorParamImpl(pParam, OP_GET_PARAM); }
27,850✔
1242

1243
void freeMergeJoinNotifyOperatorParam(SOperatorParam* pParam) { freeOperatorParamImpl(pParam, OP_NOTIFY_PARAM); }
×
1244

1245
void freeTagScanGetOperatorParam(SOperatorParam* pParam) { freeOperatorParamImpl(pParam, OP_GET_PARAM); }
48✔
1246

1247
void freeTableScanGetOperatorParam(SOperatorParam* pParam) {
2,519✔
1248
  STableScanOperatorParam* pTableScanParam = (STableScanOperatorParam*)pParam->value;
2,519✔
1249
  taosArrayDestroy(pTableScanParam->pUidList);
2,519✔
1250
  if (pTableScanParam->pOrgTbInfo) {
2,519✔
1251
    taosArrayDestroy(pTableScanParam->pOrgTbInfo->colMap);
456✔
1252
    taosMemoryFreeClear(pTableScanParam->pOrgTbInfo);
456!
1253
  }
1254
  freeOperatorParamImpl(pParam, OP_GET_PARAM);
2,519✔
1255
}
2,519✔
1256

1257
void freeTableScanNotifyOperatorParam(SOperatorParam* pParam) { freeOperatorParamImpl(pParam, OP_NOTIFY_PARAM); }
×
1258

1259
void freeTagScanNotifyOperatorParam(SOperatorParam* pParam) { freeOperatorParamImpl(pParam, OP_NOTIFY_PARAM); }
×
1260

1261
void freeOpParamItem(void* pItem) {
81✔
1262
  SOperatorParam* pParam = *(SOperatorParam**)pItem;
81✔
1263
  pParam->reUse = false;
81✔
1264
  freeOperatorParam(pParam, OP_GET_PARAM);
81✔
1265
}
81✔
1266

1267
void freeVirtualTableScanGetOperatorParam(SOperatorParam* pParam) {
24✔
1268
  SVTableScanOperatorParam* pVTableScanParam = (SVTableScanOperatorParam*)pParam->value;
24✔
1269
  taosArrayDestroyEx(pVTableScanParam->pOpParamArray, freeOpParamItem);
24✔
1270
  freeOpParamItem(&pVTableScanParam->pTagScanOp);
24✔
1271
  freeOperatorParamImpl(pParam, OP_GET_PARAM);
24✔
1272
}
24✔
1273

1274
void freeVTableScanNotifyOperatorParam(SOperatorParam* pParam) { freeOperatorParamImpl(pParam, OP_NOTIFY_PARAM); }
×
1275

1276
void freeOperatorParam(SOperatorParam* pParam, SOperatorParamType type) {
2,597,093✔
1277
  if (NULL == pParam || pParam->reUse) {
2,597,093✔
1278
    return;
2,510,292✔
1279
  }
1280

1281
  switch (pParam->opType) {
86,801!
1282
    case QUERY_NODE_PHYSICAL_PLAN_EXCHANGE:
660✔
1283
      type == OP_GET_PARAM ? freeExchangeGetOperatorParam(pParam) : freeExchangeNotifyOperatorParam(pParam);
660!
1284
      break;
660✔
1285
    case QUERY_NODE_PHYSICAL_PLAN_GROUP_CACHE:
55,700✔
1286
      type == OP_GET_PARAM ? freeGroupCacheGetOperatorParam(pParam) : freeGroupCacheNotifyOperatorParam(pParam);
55,700!
1287
      break;
55,700✔
1288
    case QUERY_NODE_PHYSICAL_PLAN_MERGE_JOIN:
27,850✔
1289
      type == OP_GET_PARAM ? freeMergeJoinGetOperatorParam(pParam) : freeMergeJoinNotifyOperatorParam(pParam);
27,850!
1290
      break;
27,850✔
1291
    case QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN:
2,519✔
1292
      type == OP_GET_PARAM ? freeTableScanGetOperatorParam(pParam) : freeTableScanNotifyOperatorParam(pParam);
2,519!
1293
      break;
2,519✔
1294
    case QUERY_NODE_PHYSICAL_PLAN_VIRTUAL_TABLE_SCAN:
24✔
1295
      type == OP_GET_PARAM ? freeVirtualTableScanGetOperatorParam(pParam) : freeVTableScanNotifyOperatorParam(pParam);
24!
1296
      break;
24✔
1297
    case QUERY_NODE_PHYSICAL_PLAN_TAG_SCAN:
48✔
1298
      type == OP_GET_PARAM ? freeTagScanGetOperatorParam(pParam) : freeTagScanNotifyOperatorParam(pParam);
48!
1299
      break;
48✔
1300
    default:
×
1301
      qError("unsupported op %d param, type %d", pParam->opType, type);
×
1302
      break;
×
1303
  }
1304
}
1305

1306
void freeResetOperatorParams(struct SOperatorInfo* pOperator, SOperatorParamType type, bool allFree) {
6,805,333✔
1307
  SOperatorParam**  ppParam = NULL;
6,805,333✔
1308
  SOperatorParam*** pppDownstramParam = NULL;
6,805,333✔
1309
  switch (type) {
6,805,333!
1310
    case OP_GET_PARAM:
3,417,734✔
1311
      ppParam = &pOperator->pOperatorGetParam;
3,417,734✔
1312
      pppDownstramParam = &pOperator->pDownstreamGetParams;
3,417,734✔
1313
      break;
3,417,734✔
1314
    case OP_NOTIFY_PARAM:
3,387,653✔
1315
      ppParam = &pOperator->pOperatorNotifyParam;
3,387,653✔
1316
      pppDownstramParam = &pOperator->pDownstreamNotifyParams;
3,387,653✔
1317
      break;
3,387,653✔
1318
    default:
×
1319
      return;
×
1320
  }
1321

1322
  if (*ppParam) {
6,805,387✔
1323
    freeOperatorParam(*ppParam, type);
27,874✔
1324
    *ppParam = NULL;
27,874✔
1325
  }
1326

1327
  if (*pppDownstramParam) {
6,805,387✔
1328
    for (int32_t i = 0; i < pOperator->numOfDownstream; ++i) {
85,826✔
1329
      if ((*pppDownstramParam)[i]) {
55,748!
1330
        freeOperatorParam((*pppDownstramParam)[i], type);
×
1331
        (*pppDownstramParam)[i] = NULL;
×
1332
      }
1333
    }
1334
    if (allFree) {
30,078✔
1335
      taosMemoryFreeClear(*pppDownstramParam);
2,008!
1336
    }
1337
  }
1338
}
1339

1340
FORCE_INLINE int32_t getNextBlockFromDownstreamImpl(struct SOperatorInfo* pOperator, int32_t idx, bool clearParam,
7,563,779✔
1341
                                                    SSDataBlock** pResBlock) {
1342
  QRY_PARAM_CHECK(pResBlock);
7,563,779!
1343

1344
  int32_t code = 0;
7,563,779✔
1345
  if (pOperator->pDownstreamGetParams && pOperator->pDownstreamGetParams[idx]) {
7,563,779!
1346
    qDebug("DynOp: op %s start to get block from downstream %s", pOperator->name, pOperator->pDownstream[idx]->name);
83,913!
1347
    code = pOperator->pDownstream[idx]->fpSet.getNextExtFn(pOperator->pDownstream[idx],
83,913✔
1348
                                                           pOperator->pDownstreamGetParams[idx], pResBlock);
83,913✔
1349
    if (clearParam && (code == 0)) {
83,913!
1350
      freeOperatorParam(pOperator->pDownstreamGetParams[idx], OP_GET_PARAM);
×
1351
      pOperator->pDownstreamGetParams[idx] = NULL;
×
1352
    }
1353

1354
    if (code) {
83,913!
1355
      qError("failed to get next data block from upstream at %s, line:%d code:%s", __func__, __LINE__, tstrerror(code));
×
1356
    }
1357
    return code;
83,913✔
1358
  }
1359

1360
  code = pOperator->pDownstream[idx]->fpSet.getNextFn(pOperator->pDownstream[idx], pResBlock);
7,479,866✔
1361
  if (code) {
7,480,711!
1362
    qError("failed to get next data block from upstream at %s, %d code:%s", __func__, __LINE__, tstrerror(code));
×
1363
  }
1364
  return code;
7,480,669✔
1365
}
1366

1367
bool compareVal(const char* v, const SStateKeys* pKey) {
83,472✔
1368
  if (IS_VAR_DATA_TYPE(pKey->type)) {
83,472!
1369
    if (IS_STR_DATA_BLOB(pKey->type)) {
1,231!
1370
      if (blobDataLen(v) != blobDataLen(pKey->pData)) {
×
1371
        return false;
×
1372
      } else {
1373
        return memcmp(blobDataVal(v), blobDataVal(pKey->pData), blobDataLen(v)) == 0;
×
1374
      }
1375
    } else {
1376
      if (varDataLen(v) != varDataLen(pKey->pData)) {
1,233!
1377
        return false;
×
1378
      } else {
1379
        return memcmp(varDataVal(v), varDataVal(pKey->pData), varDataLen(v)) == 0;
1,233✔
1380
      }
1381
    }
1382
  } else {
1383
    return memcmp(pKey->pData, v, pKey->bytes) == 0;
82,241✔
1384
  }
1385
}
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