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

taosdata / TDengine / #4822

27 Oct 2025 05:42AM UTC coverage: 59.732% (+1.0%) from 58.728%
#4822

push

travis-ci

web-flow
Merge pull request #33377 from taosdata/fix/main/rename-udf-path

fix: update UDF example links to correct file paths

121214 of 258518 branches covered (46.89%)

Branch coverage included in aggregate %.

193636 of 268583 relevant lines covered (72.1%)

4002399.5 hits per line

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

66.52
/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

83
SResultRow* getNewResultRow(SDiskbasedBuf* pResultBuf, int32_t* currentPageId, int32_t interBufSize) {
16,165,678✔
84
  SFilePage* pData = NULL;
16,165,678✔
85

86
  // in the first scan, new space needed for results
87
  int32_t pageId = -1;
16,165,678✔
88
  if (*currentPageId == -1) {
16,165,678✔
89
    pData = getNewBufPage(pResultBuf, &pageId);
368,516✔
90
    if (pData == NULL) {
368,555✔
91
      qError("failed to get buffer, code:%s", tstrerror(terrno));
31!
92
      return NULL;
×
93
    }
94
    pData->num = sizeof(SFilePage);
368,524✔
95
  } else {
96
    pData = getBufPage(pResultBuf, *currentPageId);
15,797,162✔
97
    if (pData == NULL) {
15,803,790!
98
      qError("failed to get buffer, code:%s", tstrerror(terrno));
×
99
      return NULL;
×
100
    }
101

102
    pageId = *currentPageId;
15,803,790✔
103

104
    if (pData->num + interBufSize > getBufPageSize(pResultBuf)) {
15,803,790✔
105
      // release current page first, and prepare the next one
106
      releaseBufPage(pResultBuf, pData);
1,111,761✔
107

108
      pData = getNewBufPage(pResultBuf, &pageId);
1,111,496✔
109
      if (pData == NULL) {
1,112,435!
110
        qError("failed to get buffer, code:%s", tstrerror(terrno));
×
111
        return NULL;
×
112
      }
113
      pData->num = sizeof(SFilePage);
1,112,435✔
114
    }
115
  }
116

117
  setBufPageDirty(pData, true);
16,168,663✔
118

119
  // set the number of rows in current disk page
120
  SResultRow* pResultRow = (SResultRow*)((char*)pData + pData->num);
16,154,664✔
121

122
  memset((char*)pResultRow, 0, interBufSize);
16,154,664✔
123
  pResultRow->pageId = pageId;
16,154,664✔
124
  pResultRow->offset = (int32_t)pData->num;
16,154,664✔
125

126
  *currentPageId = pageId;
16,154,664✔
127
  pData->num += interBufSize;
16,154,664✔
128
  return pResultRow;
16,154,664✔
129
}
130

131
/**
132
 * the struct of key in hash table
133
 * +----------+---------------+
134
 * | group id |   key data    |
135
 * | 8 bytes  | actual length |
136
 * +----------+---------------+
137
 */
138
SResultRow* doSetResultOutBufByKey(SDiskbasedBuf* pResultBuf, SResultRowInfo* pResultRowInfo, char* pData,
29,359,263✔
139
                                   int32_t bytes, bool masterscan, uint64_t groupId, SExecTaskInfo* pTaskInfo,
140
                                   bool isIntervalQuery, SAggSupporter* pSup, bool keepGroup) {
141
  SET_RES_WINDOW_KEY(pSup->keyBuf, pData, bytes, groupId);
29,359,263✔
142
  if (!keepGroup) {
29,359,263✔
143
    *(uint64_t*)pSup->keyBuf = calcGroupId(pSup->keyBuf, GET_RES_WINDOW_KEY_LEN(bytes));
16,618,937✔
144
  }
145

146
  SResultRowPosition* p1 =
147
      (SResultRowPosition*)tSimpleHashGet(pSup->pResultRowHashTable, pSup->keyBuf, GET_RES_WINDOW_KEY_LEN(bytes));
29,417,999✔
148

149
  SResultRow* pResult = NULL;
29,393,336✔
150

151
  // in case of repeat scan/reverse scan, no new time window added.
152
  if (isIntervalQuery) {
29,393,336✔
153
    if (p1 != NULL) {  // the *p1 may be NULL in case of sliding+offset exists.
12,269,987✔
154
      pResult = getResultRowByPos(pResultBuf, p1, true);
1,228,856✔
155
      if (pResult == NULL) {
1,228,856!
156
        pTaskInfo->code = terrno;
×
157
        return NULL;
×
158
      }
159

160
      if (pResult->pageId != p1->pageId || pResult->offset != p1->offset) {
1,228,856!
161
        terrno = TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR;
×
162
        pTaskInfo->code = terrno;
×
163
        return NULL;
×
164
      }
165
    }
166
  } else {
167
    // In case of group by column query, the required SResultRow object must be existInCurrentResusltRowInfo in the
168
    // pResultRowInfo object.
169
    if (p1 != NULL) {
17,123,349✔
170
      // todo
171
      pResult = getResultRowByPos(pResultBuf, p1, true);
11,920,489✔
172
      if (NULL == pResult) {
11,920,489!
173
        pTaskInfo->code = terrno;
×
174
        return NULL;
×
175
      }
176

177
      if (pResult->pageId != p1->pageId || pResult->offset != p1->offset) {
11,920,489!
178
        terrno = TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR;
×
179
        pTaskInfo->code = terrno;
×
180
        return NULL;
525✔
181
      }
182
    }
183
  }
184

185
  // 1. close current opened time window
186
  if (pResultRowInfo->cur.pageId != -1 && ((pResult == NULL) || (pResult->pageId != pResultRowInfo->cur.pageId))) {
29,368,459✔
187
    SResultRowPosition pos = pResultRowInfo->cur;
25,387,959✔
188
    SFilePage*         pPage = getBufPage(pResultBuf, pos.pageId);
25,387,959✔
189
    if (pPage == NULL) {
25,371,128!
190
      qError("failed to get buffer, code:%s, %s", tstrerror(terrno), GET_TASKID(pTaskInfo));
×
191
      pTaskInfo->code = terrno;
×
192
      return NULL;
×
193
    }
194
    releaseBufPage(pResultBuf, pPage);
25,371,128✔
195
  }
196

197
  // allocate a new buffer page
198
  if (pResult == NULL) {
29,304,828✔
199
    pResult = getNewResultRow(pResultBuf, &pSup->currentPageId, pSup->resultRowSize);
16,162,385✔
200
    if (pResult == NULL) {
16,192,043!
201
      pTaskInfo->code = terrno;
×
202
      return NULL;
×
203
    }
204

205
    // add a new result set for a new group
206
    SResultRowPosition pos = {.pageId = pResult->pageId, .offset = pResult->offset};
16,192,043✔
207
    int32_t code = tSimpleHashPut(pSup->pResultRowHashTable, pSup->keyBuf, GET_RES_WINDOW_KEY_LEN(bytes), &pos,
16,192,043✔
208
                                  sizeof(SResultRowPosition));
209
    if (code != TSDB_CODE_SUCCESS) {
16,297,416✔
210
      qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(code));
2,002!
211
      pTaskInfo->code = code;
×
212
      return NULL;
×
213
    }
214
  }
215

216
  // 2. set the new time window to be the new active time window
217
  pResultRowInfo->cur = (SResultRowPosition){.pageId = pResult->pageId, .offset = pResult->offset};
29,437,857✔
218

219
  // too many time window in query
220
  if (pTaskInfo->execModel == OPTR_EXEC_MODEL_BATCH &&
58,804,040!
221
      tSimpleHashGetSize(pSup->pResultRowHashTable) > MAX_INTERVAL_TIME_WINDOW) {
29,396,436✔
222
    pTaskInfo->code = TSDB_CODE_QRY_TOO_MANY_TIMEWINDOW;
×
223
    return NULL;
×
224
  }
225

226
  return pResult;
29,407,604✔
227
}
228

229
//  query_range_start, query_range_end, window_duration, window_start, window_end
230
int32_t initExecTimeWindowInfo(SColumnInfoData* pColData, STimeWindow* pQueryWindow) {
9,634✔
231
  pColData->info.type = TSDB_DATA_TYPE_TIMESTAMP;
9,634✔
232
  pColData->info.bytes = sizeof(int64_t);
9,634✔
233

234
  int32_t code = colInfoDataEnsureCapacity(pColData, 6, false);
9,634✔
235
  if (code != TSDB_CODE_SUCCESS) {
9,650!
236
    return code;
×
237
  }
238
  colDataSetInt64(pColData, 0, &pQueryWindow->skey);
9,650✔
239
  colDataSetInt64(pColData, 1, &pQueryWindow->ekey);
9,650✔
240

241
  int64_t interval = 0;
9,650✔
242
  colDataSetInt64(pColData, 2, &interval);  // this value may be variable in case of 'n' and 'y'.
243
  colDataSetInt64(pColData, 3, &pQueryWindow->skey);
9,650✔
244
  colDataSetInt64(pColData, 4, &pQueryWindow->ekey);
9,650✔
245

246
  interval = -1;
9,650✔
247
  colDataSetInt64(pColData, 5,  &interval);
248
  return TSDB_CODE_SUCCESS;
9,650✔
249
}
250

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

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

271
int32_t setInputDataBlock(SExprSupp* pExprSup, SSDataBlock* pBlock, int32_t order, int32_t scanFlag,
1,997,174✔
272
                          bool createDummyCol) {
273
  if (pBlock->pBlockAgg != NULL) {
1,997,174✔
274
    return doSetInputDataBlockInfo(pExprSup, pBlock, order, scanFlag);
11,376✔
275
  } else {
276
    return doSetInputDataBlock(pExprSup, pBlock, order, scanFlag, createDummyCol);
1,985,798✔
277
  }
278
}
279

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

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

293
    pInput->pData[paramIndex] = pColInfo;
283✔
294
  } else {
295
    pColInfo = pInput->pData[paramIndex];
30,742✔
296
  }
297

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

301
  int8_t type = pFuncParam->param.nType;
31,024✔
302
  if (type == TSDB_DATA_TYPE_BIGINT || type == TSDB_DATA_TYPE_UBIGINT) {
31,191!
303
    int64_t v = pFuncParam->param.i;
167✔
304
    for (int32_t i = 0; i < numOfRows; ++i) {
1,917✔
305
      colDataSetInt64(pColInfo, i, &v);
1,750✔
306
    }
307
  } else if (type == TSDB_DATA_TYPE_DOUBLE) {
30,857!
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) {
30,857!
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:
30,857✔
325
  if (code != TSDB_CODE_SUCCESS) {
31,024!
326
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
×
327
  }
328
  return code;
31,024✔
329
}
330

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

337
  for (int32_t i = 0; i < pExprSup->numOfExprs; ++i) {
8,630,643✔
338
    pCtx[i].order = order;
6,644,948✔
339
    pCtx[i].input.numOfRows = pBlock->info.rows;
6,644,948✔
340

341
    pCtx[i].pSrcBlock = pBlock;
6,644,948✔
342
    pCtx[i].scanFlag = scanFlag;
6,644,948✔
343

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

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

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

355
    for (int32_t j = 0; j < pOneExpr->base.numOfParams; ++j) {
13,624,022✔
356
      SFunctParam* pFuncParam = &pOneExpr->base.pParam[j];
6,979,108✔
357
      if (pFuncParam->type == FUNC_PARAM_TYPE_COLUMN) {
6,979,108✔
358
        int32_t slotId = pFuncParam->pCol->slotId;
6,272,410✔
359
        pInput->pData[j] = taosArrayGet(pBlock->pDataBlock, slotId);
6,272,410✔
360
        pInput->totalRows = pBlock->info.rows;
6,272,297✔
361
        pInput->numOfRows = pBlock->info.rows;
6,272,297✔
362
        pInput->startRowIndex = 0;
6,272,297✔
363
        pInput->blankFill = pBlock->info.blankFill;
6,272,297✔
364

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

368
        if (fmIsImplicitTsFunc(pCtx[i].functionId) && (j == tsParamIdx)) {
6,272,297✔
369
          pInput->pPTS = pInput->pData[j];  // in case of merge function, this is not always the ts column data.
271,672✔
370
        }
371
        if (hasPk && (j == pkParamIdx)) {
6,272,377✔
372
          pInput->pPrimaryKey = pInput->pData[j];
7,744✔
373
        }
374
        QUERY_CHECK_CONDITION((pInput->pData[j] != NULL), code, lino, _end, TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR);
6,272,377!
375
      } else if (pFuncParam->type == FUNC_PARAM_TYPE_VALUE) {
706,698✔
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) {
331,086✔
379
          pInput->totalRows = pBlock->info.rows;
31,025✔
380
          pInput->numOfRows = pBlock->info.rows;
31,025✔
381
          pInput->startRowIndex = 0;
31,025✔
382
          pInput->blankFill = pBlock->info.blankFill;
31,025✔
383

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

391
_end:
1,985,695✔
392
  if (code != TSDB_CODE_SUCCESS) {
1,985,695!
393
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
×
394
  }
395
  return code;
1,985,960✔
396
}
397

398
bool functionNeedToExecute(SqlFunctionCtx* pCtx) {
123,567,223✔
399
  struct SResultRowEntryInfo* pResInfo = GET_RES_INFO(pCtx);
123,567,223✔
400

401
  // in case of timestamp column, always generated results.
402
  int32_t functionId = pCtx->functionId;
123,567,223✔
403
  if (functionId == -1) {
123,567,223✔
404
    return false;
21,831,468✔
405
  }
406

407
  if (pCtx->scanFlag == PRE_SCAN) {
101,735,755✔
408
    return fmIsRepeatScanFunc(pCtx->functionId);
6,416✔
409
  }
410

411
  if (isRowEntryCompleted(pResInfo)) {
101,729,339!
412
    return false;
×
413
  }
414

415
  return true;
101,729,339✔
416
}
417

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

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

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

442
  if (type == TSDB_DATA_TYPE_BIGINT) {
×
443
    int64_t v = pFuncParam->param.i;
×
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

465
  return TSDB_CODE_SUCCESS;
×
466
}
467

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

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

477
  if (pBlock->pBlockAgg != NULL) {
11,403!
478
    pInput->colDataSMAIsSet = true;
11,408✔
479

480
    for (int32_t j = 0; j < pExprInfo->base.numOfParams; ++j) {
22,813✔
481
      SFunctParam* pFuncParam = &pExprInfo->base.pParam[j];
11,406✔
482

483
      if (pFuncParam->type == FUNC_PARAM_TYPE_COLUMN) {
11,406!
484
        int32_t slotId = pFuncParam->pCol->slotId;
11,406✔
485
        pInput->pColumnDataAgg[j] = &pBlock->pBlockAgg[slotId];
11,406✔
486
        if (pInput->pColumnDataAgg[j]->colId == -1) {
11,406✔
487
          pInput->colDataSMAIsSet = false;
1,027✔
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);
11,406✔
493
      } else if (pFuncParam->type == FUNC_PARAM_TYPE_VALUE) {
×
494
        code = doCreateConstantValColumnSMAInfo(pInput, pFuncParam, pFuncParam->param.nType, j, pBlock->info.rows);
×
495
        QUERY_CHECK_CODE(code, lino, _end);
×
496
      }
497
    }
498
  } else {
499
    pInput->colDataSMAIsSet = false;
×
500
  }
501

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

509
/////////////////////////////////////////////////////////////////////////////////////////////
510
STimeWindow getAlignQueryTimeWindow(const SInterval* pInterval, int64_t key) {
79,879✔
511
  STimeWindow win = {0};
79,879✔
512
  win.skey = taosTimeTruncate(key, pInterval);
79,879✔
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);
79,873✔
519
  if (win.ekey < win.skey) {
79,881!
520
    win.ekey = INT64_MAX;
×
521
  }
522

523
  return win;
79,881✔
524
}
525

526
int32_t setResultRowInitCtx(SResultRow* pResult, SqlFunctionCtx* pCtx, int32_t numOfOutput,
30,677,610✔
527
                            int32_t* rowEntryInfoOffset) {
528
  bool init = false;
30,677,610✔
529
  for (int32_t i = 0; i < numOfOutput; ++i) {
169,430,611✔
530
    pCtx[i].resultInfo = getResultEntryInfo(pResult, i, rowEntryInfoOffset);
138,831,516✔
531
    if (init) {
138,832,350✔
532
      continue;
51,710,843✔
533
    }
534

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

541
    if (pCtx[i].isPseudoFunc) {
87,121,507✔
542
      continue;
15,404,199✔
543
    }
544

545
    if (!pResInfo->initialized) {
71,717,308✔
546
      if (pCtx[i].functionId != -1) {
58,851,709✔
547
        int32_t code = pCtx[i].fpSet.init(&pCtx[i], pResInfo);
50,500,538✔
548
        if (code != TSDB_CODE_SUCCESS && fmIsUserDefinedFunc(pCtx[i].functionId)) {
50,509,456!
549
          pResInfo->initialized = false;
88,267✔
550
          qError("failed to initialize udf, funcId:%d error:%s", pCtx[i].functionId, tstrerror(code));
88,267!
551
          return TSDB_CODE_UDF_FUNC_EXEC_FAILURE;
×
552
        } else if (code != TSDB_CODE_SUCCESS) {
50,421,189!
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;
8,351,171✔
558
      }
559
    } else {
560
      init = true;
12,865,599✔
561
    }
562
  }
563
  return TSDB_CODE_SUCCESS;
30,599,095✔
564
}
565

566
void clearResultRowInitFlag(SqlFunctionCtx* pCtx, int32_t numOfOutput) {
366,860✔
567
  for (int32_t i = 0; i < numOfOutput; ++i) {
4,289,753✔
568
    SResultRowEntryInfo* pResInfo = pCtx[i].resultInfo;
3,922,893✔
569
    if (pResInfo == NULL) {
3,922,893!
570
      continue;
×
571
    }
572

573
    pResInfo->initialized = false;
3,922,893✔
574
    pResInfo->numOfRes = 0;
3,922,893✔
575
    pResInfo->isNullRes = 0;
3,922,893✔
576
    pResInfo->complete = false;
3,922,893✔
577
  }
578
}
366,860✔
579

580
int32_t doFilter(SSDataBlock* pBlock, SFilterInfo* pFilterInfo, SColMatchInfo* pColMatchInfo, SColumnInfoData** pRet) {
5,420,991✔
581
  int32_t code = TSDB_CODE_SUCCESS;
5,420,991✔
582
  int32_t lino = 0;
5,420,991✔
583
  if (pFilterInfo == NULL || pBlock->info.rows == 0) {
5,420,991✔
584
    return TSDB_CODE_SUCCESS;
5,066,346✔
585
  }
586

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

590
  code = filterSetDataFromSlotId(pFilterInfo, &param1);
354,640✔
591
  QUERY_CHECK_CODE(code, lino, _err);
354,617!
592

593
  int32_t status = 0;
354,617✔
594
  code =
595
      filterExecute(pFilterInfo, pBlock, pRet != NULL ? pRet : &p, NULL, param1.numOfCols, &status);
354,617✔
596
  QUERY_CHECK_CODE(code, lino, _err);
354,548✔
597

598
  code = extractQualifiedTupleByFilterResult(pBlock, pRet != NULL ? *pRet : p, status);
354,547✔
599
  QUERY_CHECK_CODE(code, lino, _err);
354,602!
600

601
  if (pColMatchInfo != NULL) {
354,602✔
602
    size_t size = taosArrayGetSize(pColMatchInfo->pList);
209,974✔
603
    for (int32_t i = 0; i < size; ++i) {
210,219✔
604
      SColMatchItem* pInfo = taosArrayGet(pColMatchInfo->pList, i);
210,015✔
605
      QUERY_CHECK_NULL(pInfo, code, lino, _err, terrno);
210,017!
606
      if (pInfo->colId == PRIMARYKEY_TIMESTAMP_COL_ID) {
210,017✔
607
        SColumnInfoData* pColData = taosArrayGet(pBlock->pDataBlock, pInfo->dstSlotId);
209,821✔
608
        QUERY_CHECK_NULL(pColData, code, lino, _err, terrno);
209,815!
609
        if (pColData->info.type == TSDB_DATA_TYPE_TIMESTAMP) {
209,822✔
610
          code = blockDataUpdateTsWindow(pBlock, pInfo->dstSlotId);
209,817✔
611
          QUERY_CHECK_CODE(code, lino, _err);
209,826!
612
          break;
209,826✔
613
        }
614
      }
615
    }
616
  }
617
  code = blockDataCheck(pBlock);
354,658✔
618
  QUERY_CHECK_CODE(code, lino, _err);
354,609!
619
_err:
354,609✔
620
  if (code != TSDB_CODE_SUCCESS) {
354,610✔
621
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
1!
622
  }
623
  colDataDestroy(p);
354,610✔
624
  taosMemoryFree(p);
354,610!
625
  return code;
354,662✔
626
}
627

628
int32_t extractQualifiedTupleByFilterResult(SSDataBlock* pBlock, const SColumnInfoData* p, int32_t status) {
354,895✔
629
  int32_t code = TSDB_CODE_SUCCESS;
354,895✔
630
  int8_t* pIndicator = (int8_t*)p->pData;
354,895✔
631
  if (status == FILTER_RESULT_ALL_QUALIFIED) {
354,895✔
632
    // here nothing needs to be done
633
  } else if (status == FILTER_RESULT_NONE_QUALIFIED) {
217,428✔
634
    code = trimDataBlock(pBlock, pBlock->info.rows, NULL);
49,853✔
635
    pBlock->info.rows = 0;
49,846✔
636
  } else if (status == FILTER_RESULT_PARTIAL_QUALIFIED) {
167,575!
637
    code = trimDataBlock(pBlock, pBlock->info.rows, (bool*)pIndicator);
167,617✔
638
  } else {
639
    qError("unknown filter result type: %d", status);
×
640
  }
641
  return code;
354,990✔
642
}
643

644
void doUpdateNumOfRows(SqlFunctionCtx* pCtx, SResultRow* pRow, int32_t numOfExprs, const int32_t* rowEntryOffset) {
20,282,022✔
645
  bool returnNotNull = false;
20,282,022✔
646
  for (int32_t j = 0; j < numOfExprs; ++j) {
91,496,814✔
647
    SResultRowEntryInfo* pResInfo = getResultEntryInfo(pRow, j, rowEntryOffset);
71,171,340✔
648
    if (!isRowEntryInitialized(pResInfo)) {
71,214,792✔
649
      continue;
12,974,240✔
650
    } else {
651
    }
652

653
    if (pRow->numOfRows < pResInfo->numOfRes) {
58,240,552✔
654
      pRow->numOfRows = pResInfo->numOfRes;
16,622,845✔
655
    }
656

657
    if (pCtx[j].isNotNullFunc) {
58,240,552✔
658
      returnNotNull = true;
16,917,159✔
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) {
20,325,474✔
664
    pRow->numOfRows = 1;
8,625✔
665
  }
666
}
20,325,474✔
667

668
int32_t copyResultrowToDataBlock(SExprInfo* pExprInfo, int32_t numOfExprs, SResultRow* pRow, SqlFunctionCtx* pCtx,
16,808,957✔
669
                                 SSDataBlock* pBlock, const int32_t* rowEntryOffset, SExecTaskInfo* pTaskInfo) {
670
  int32_t code = TSDB_CODE_SUCCESS;
16,808,957✔
671
  int32_t lino = 0;
16,808,957✔
672
  for (int32_t j = 0; j < numOfExprs; ++j) {
83,933,557✔
673
    int32_t slotId = pExprInfo[j].base.resSchema.slotId;
67,064,588✔
674

675
    pCtx[j].resultInfo = getResultEntryInfo(pRow, j, rowEntryOffset);
67,064,588✔
676
    if (pCtx[j].fpSet.finalize) {
67,080,357✔
677
      if (strcmp(pCtx[j].pExpr->pExpr->_function.functionName, "_group_key") == 0 ||
46,344,496✔
678
          strcmp(pCtx[j].pExpr->pExpr->_function.functionName, "_group_const_value") == 0) {
26,426,958✔
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) {
19,919,161!
682
          pCtx[j].resultInfo->numOfRes = pRow->numOfRows;
20,196,482✔
683
        }
684
      }
685

686
      code = pCtx[j].fpSet.finalize(&pCtx[j], pBlock);
46,344,496✔
687
      if (TSDB_CODE_SUCCESS != code) {
46,529,003!
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) {
20,735,861!
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);
20,942,084✔
697
      QUERY_CHECK_NULL(pColInfoData, code, lino, _end, terrno);
20,869,824!
698
      char*            in = GET_ROWCELL_INTERBUF(pCtx[j].resultInfo);
20,872,559✔
699
      for (int32_t k = 0; k < pRow->numOfRows; ++k) {        
41,791,931✔
700
        code = colDataSetValOrCover(pColInfoData, pBlock->info.rows + k, in, pCtx[j].resultInfo->isNullRes);
20,889,210✔
701
        QUERY_CHECK_CODE(code, lino, _end);
20,919,372!
702
      }
703
    }
704
  }
705

706
_end:
16,868,969✔
707
  if (code != TSDB_CODE_SUCCESS) {
16,868,969!
708
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
×
709
  }
710
  return code;
16,938,778✔
711
}
712

713
// todo refactor. SResultRow has direct pointer in miainfo
714
void finalizeResultRows(SDiskbasedBuf* pBuf, SResultRowPosition* resultRowPosition, SExprSupp* pSup,
1,092,038✔
715
                        SSDataBlock* pBlock, SExecTaskInfo* pTaskInfo) {
716
  SFilePage* page = getBufPage(pBuf, resultRowPosition->pageId);
1,092,038✔
717
  if (page == NULL) {
1,091,903!
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);
1,091,903✔
723

724
  SqlFunctionCtx* pCtx = pSup->pCtx;
1,091,903✔
725
  SExprInfo*      pExprInfo = pSup->pExprInfo;
1,091,903✔
726
  const int32_t*  rowEntryOffset = pSup->rowEntryInfoOffset;
1,091,903✔
727

728
  doUpdateNumOfRows(pCtx, pRow, pSup->numOfExprs, rowEntryOffset);
1,091,903✔
729
  if (pRow->numOfRows == 0) {
1,091,835!
730
    releaseBufPage(pBuf, page);
×
731
    return;
×
732
  }
733

734
  int32_t size = pBlock->info.capacity;
1,091,835✔
735
  while (pBlock->info.rows + pRow->numOfRows > size) {
1,091,996✔
736
    size = size * 1.25;
161✔
737
  }
738

739
  int32_t code = blockDataEnsureCapacity(pBlock, size);
1,091,835✔
740
  if (TAOS_FAILED(code)) {
1,091,879!
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);
1,091,879✔
747
  if (TAOS_FAILED(code)) {
1,091,803!
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);
1,091,803✔
754
  pBlock->info.rows += pRow->numOfRows;
1,091,662✔
755
}
756

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

766
  size_t  keyLen = 0;
3,423,496✔
767
  int32_t numOfRows = tSimpleHashGetSize(pHashmap);
3,423,496✔
768

769
  // begin from last iter
770
  void*   pData = pGroupResInfo->dataPos;
3,423,412✔
771
  int32_t iter = pGroupResInfo->iter;
3,423,412✔
772
  while ((pData = tSimpleHashIterate(pHashmap, pData, &iter)) != NULL) {
8,003,906✔
773
    void*               key = tSimpleHashGetKey(pData, &keyLen);
7,958,222✔
774
    SResultRowPosition* pos = pData;
7,958,222✔
775
    uint64_t            groupId = *(uint64_t*)key;
7,958,222✔
776

777
    SFilePage* page = getBufPage(pBuf, pos->pageId);
7,958,222✔
778
    if (page == NULL) {
7,957,992!
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);
7,957,992✔
784

785
    doUpdateNumOfRows(pCtx, pRow, numOfExprs, rowEntryOffset);
7,957,992✔
786

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

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

797
    if (!ignoreGroup) {
7,957,882✔
798
      if (pBlock->info.id.groupId == 0) {
6,765,866✔
799
        pBlock->info.id.groupId = groupId;
3,388,696✔
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,377,170!
803
          releaseBufPage(pBuf, page);
3,377,415✔
804
          break;
3,377,363✔
805
        }
806
      }
807
    }
808

809
    if (pBlock->info.rows + pRow->numOfRows > pBlock->info.capacity) {
4,580,467!
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;
4,580,467✔
819
    pGroupResInfo->iter = iter;
4,580,467✔
820
    pGroupResInfo->dataPos = pData;
4,580,467✔
821

822
    code = copyResultrowToDataBlock(pExprInfo, numOfExprs, pRow, pCtx, pBlock, rowEntryOffset, pTaskInfo);
4,580,467✔
823
    releaseBufPage(pBuf, page);
4,580,553✔
824
    QUERY_CHECK_CODE(code, lino, _end);
4,580,510!
825
    pBlock->info.rows += pRow->numOfRows;
4,580,510✔
826
    if (pBlock->info.rows >= threshold) {
4,580,510✔
827
      break;
16✔
828
    }
829
  }
830

831
  qDebug("%s result generated, rows:%" PRId64 ", groupId:%" PRIu64, GET_TASKID(pTaskInfo), pBlock->info.rows,
3,422,967✔
832
         pBlock->info.id.groupId);
833
  pBlock->info.dataLoad = 1;
3,423,105✔
834
  code = blockDataUpdateTsWindow(pBlock, 0);
3,423,105✔
835
  QUERY_CHECK_CODE(code, lino, _end);
3,422,935!
836

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

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

853
  int32_t numOfRows = getNumOfTotalRes(pGroupResInfo);
176,358✔
854

855
  for (int32_t i = pGroupResInfo->index; i < numOfRows; i += 1) {
11,039,887✔
856
    SResKeyPos* pPos = taosArrayGetP(pGroupResInfo->pRows, i);
10,922,606✔
857
    SFilePage*  page = getBufPage(pBuf, pPos->pos.pageId);
10,912,928✔
858
    if (page == NULL) {
10,900,754!
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);
10,900,754✔
864

865
    doUpdateNumOfRows(pCtx, pRow, numOfExprs, rowEntryOffset);
10,900,754✔
866

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

882
    if (!ignoreGroup) {
10,781,215✔
883
      if (pBlock->info.id.groupId == 0) {
2,806,896✔
884
        pBlock->info.id.groupId = pPos->groupId;
765,916✔
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) {
2,040,980✔
888
          releaseBufPage(pBuf, page);
33,434✔
889
          break;
33,435✔
890
        }
891
      }
892
    }
893

894
    if (pBlock->info.rows + pRow->numOfRows > pBlock->info.capacity) {
10,747,781!
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;
10,747,781✔
904
    code = copyResultrowToDataBlock(pExprInfo, numOfExprs, pRow, pCtx, pBlock, rowEntryOffset, pTaskInfo);
10,747,781✔
905
    releaseBufPage(pBuf, page);
10,936,587✔
906
    QUERY_CHECK_CODE(code, lino, _end);
10,888,962!
907

908
    pBlock->info.rows += pRow->numOfRows;
10,888,962✔
909
    if (pBlock->info.rows >= threshold) {
10,888,962✔
910
      break;
25,553✔
911
    }
912
  }
913

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

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

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

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

935
  blockDataCleanup(pBlock);
205,263✔
936
  if (!hasRemainResults(pGroupResInfo)) {
205,279✔
937
    return;
28,984✔
938
  }
939

940
  // clear the existed group id
941
  pBlock->info.id.groupId = 0;
176,293✔
942
  if (!pbInfo->mergeResultBlock) {
176,293✔
943
    doCopyToSDataBlock(pTaskInfo, pBlock, &pOperator->exprSupp, pBuf, pGroupResInfo, pOperator->resultInfo.threshold,
67,880✔
944
                       false, getMinWindowSize(pOperator));
945
  } else {
946
    while (hasRemainResults(pGroupResInfo)) {
196,295✔
947
      doCopyToSDataBlock(pTaskInfo, pBlock, &pOperator->exprSupp, pBuf, pGroupResInfo, pOperator->resultInfo.threshold,
108,408✔
948
                         true, getMinWindowSize(pOperator));
949
      if (pBlock->info.rows >= pOperator->resultInfo.threshold) {
108,413✔
950
        break;
20,531✔
951
      }
952

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

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

962
void destroyExprInfo(SExprInfo* pExpr, int32_t numOfExprs) {
635,552✔
963
  for (int32_t i = 0; i < numOfExprs; ++i) {
2,477,830✔
964
    SExprInfo* pExprInfo = &pExpr[i];
1,842,209✔
965
    for (int32_t j = 0; j < pExprInfo->base.numOfParams; ++j) {
3,938,999✔
966
      if (pExprInfo->base.pParam[j].type == FUNC_PARAM_TYPE_COLUMN) {
2,096,772✔
967
        taosMemoryFreeClear(pExprInfo->base.pParam[j].pCol);
1,698,902!
968
      } else if (pExprInfo->base.pParam[j].type == FUNC_PARAM_TYPE_VALUE) {
397,870✔
969
        taosVariantDestroy(&pExprInfo->base.pParam[j].param);
236,005✔
970
      }
971
    }
972

973
    taosMemoryFree(pExprInfo->base.pParam);
1,842,227!
974
    taosMemoryFree(pExprInfo->pExpr);
1,842,285!
975
  }
976
}
635,621✔
977

978
int32_t getBufferPgSize(int32_t rowSize, uint32_t* defaultPgsz, int64_t* defaultBufsz) {
428,233✔
979
  *defaultPgsz = 4096;
428,233✔
980
  uint32_t last = *defaultPgsz;
428,233✔
981
  while (*defaultPgsz < rowSize * 4) {
538,459✔
982
    *defaultPgsz <<= 1u;
110,226✔
983
    if (*defaultPgsz < last) {
110,226!
984
      return TSDB_CODE_INVALID_PARA;
×
985
    }
986
    last = *defaultPgsz;
110,226✔
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;
428,233✔
993
  if ((*defaultBufsz) <= (*defaultPgsz)) {
428,233!
994
    (*defaultBufsz) = (*defaultPgsz) * 4;
×
995
    if (*defaultBufsz < ((int64_t)(*defaultPgsz)) * 4) {
×
996
      return TSDB_CODE_INVALID_PARA;
×
997
    }
998
  }
999

1000
  return 0;
428,233✔
1001
}
1002

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

1008
  pResultInfo->capacity = numOfRows;
854,914✔
1009
  pResultInfo->threshold = numOfRows * 0.75;
854,914✔
1010

1011
  if (pResultInfo->threshold == 0) {
854,914✔
1012
    pResultInfo->threshold = numOfRows;
478✔
1013
  }
1014
  pResultInfo->totalRows = 0;
854,914✔
1015
}
854,914✔
1016

1017
void initBasicInfo(SOptrBasicInfo* pInfo, SSDataBlock* pBlock) {
366,026✔
1018
  pInfo->pRes = pBlock;
366,026✔
1019
  initResultRowInfo(&pInfo->resultRowInfo);
366,026✔
1020
}
366,067✔
1021

1022
void destroySqlFunctionCtx(SqlFunctionCtx* pCtx, SExprInfo* pExpr, int32_t numOfOutput) {
1,728,024✔
1023
  if (pCtx == NULL) {
1,728,024✔
1024
    return;
1,047,714✔
1025
  }
1026

1027
  for (int32_t i = 0; i < numOfOutput; ++i) {
2,499,922✔
1028
    if (pExpr != NULL) {
1,819,521✔
1029
      SExprInfo* pExprInfo = &pExpr[i];
1,819,503✔
1030
      for (int32_t j = 0; j < pExprInfo->base.numOfParams; ++j) {
3,891,027✔
1031
        if (pExprInfo->base.pParam[j].type == FUNC_PARAM_TYPE_VALUE) {
2,071,547✔
1032
          colDataDestroy(pCtx[i].input.pData[j]);
231,934✔
1033
          taosMemoryFree(pCtx[i].input.pData[j]);
231,929!
1034
          taosMemoryFree(pCtx[i].input.pColumnDataAgg[j]);
231,930✔
1035
        }
1036
      }
1037
    }
1038
    for (int32_t j = 0; j < pCtx[i].numOfParams; ++j) {
3,891,022✔
1039
      taosVariantDestroy(&pCtx[i].param[j].param);
2,071,515✔
1040
    }
1041

1042
    taosMemoryFreeClear(pCtx[i].subsidiaries.pCtx);
1,819,507!
1043
    taosMemoryFreeClear(pCtx[i].subsidiaries.buf);
1,819,507!
1044
    taosMemoryFree(pCtx[i].input.pData);
1,819,507✔
1045
    taosMemoryFree(pCtx[i].input.pColumnDataAgg);
1,819,595!
1046

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

1052
  taosMemoryFreeClear(pCtx);
680,401!
1053
  return;
680,397✔
1054
}
1055

1056
int32_t initExprSupp(SExprSupp* pSup, SExprInfo* pExprInfo, int32_t numOfExpr, SFunctionStateStore* pStore) {
653,759✔
1057
  pSup->pExprInfo = pExprInfo;
653,759✔
1058
  pSup->numOfExprs = numOfExpr;
653,759✔
1059
  if (pSup->pExprInfo != NULL) {
653,759✔
1060
    pSup->pCtx = createSqlFunctionCtx(pExprInfo, numOfExpr, &pSup->rowEntryInfoOffset, pStore);
500,886✔
1061
    if (pSup->pCtx == NULL) {
500,827!
1062
      return terrno;
×
1063
    }
1064
  }
1065

1066
  return TSDB_CODE_SUCCESS;
653,790✔
1067
}
1068

1069
void checkIndefRowsFuncs(SExprSupp* pSup) {
×
1070
  for (int32_t i = 0; i < pSup->numOfExprs; ++i) {
×
1071
    if (fmIsIndefiniteRowsFunc(pSup->pCtx[i].functionId)) {
×
1072
      pSup->hasIndefRowsFunc = true;
×
1073
      break;
×
1074
    }
1075
  }
1076
}
×
1077

1078
void cleanupExprSupp(SExprSupp* pSupp) {
1,519,525✔
1079
  destroySqlFunctionCtx(pSupp->pCtx, pSupp->pExprInfo, pSupp->numOfExprs);
1,519,525✔
1080
  if (pSupp->pExprInfo != NULL) {
1,519,563✔
1081
    destroyExprInfo(pSupp->pExprInfo, pSupp->numOfExprs);
549,830✔
1082
    taosMemoryFreeClear(pSupp->pExprInfo);
549,838!
1083
  }
1084

1085
  if (pSupp->pFilterInfo != NULL) {
1,519,589✔
1086
    filterFreeInfo(pSupp->pFilterInfo);
111,538✔
1087
    pSupp->pFilterInfo = NULL;
111,534✔
1088
  }
1089

1090
  taosMemoryFree(pSupp->rowEntryInfoOffset);
1,519,585✔
1091
  memset(pSupp, 0, sizeof(SExprSupp));
1,519,529✔
1092
}
1,519,529✔
1093

1094
void cleanupExprSuppWithoutFilter(SExprSupp* pSupp) {
208,498✔
1095
  destroySqlFunctionCtx(pSupp->pCtx, pSupp->pExprInfo, pSupp->numOfExprs);
208,498✔
1096
  if (pSupp->pExprInfo != NULL) {
208,502✔
1097
    destroyExprInfo(pSupp->pExprInfo, pSupp->numOfExprs);
82,119✔
1098
    taosMemoryFreeClear(pSupp->pExprInfo);
82,120!
1099
  }
1100

1101
  taosMemoryFreeClear(pSupp->rowEntryInfoOffset);
208,506!
1102
  pSupp->numOfExprs = 0;
208,505✔
1103
  pSupp->hasWindowOrGroup = false;
208,505✔
1104
  pSupp->pCtx = NULL;
208,505✔
1105
}
208,505✔
1106

1107
void cleanupBasicInfo(SOptrBasicInfo* pInfo) {
371,357✔
1108
  blockDataDestroy(pInfo->pRes);
371,357✔
1109
  pInfo->pRes = NULL;
371,400✔
1110
}
371,400✔
1111

1112
bool groupbyTbname(SNodeList* pGroupList) {
348,475✔
1113
  bool   bytbname = false;
348,475✔
1114
  SNode* pNode = NULL;
348,475✔
1115
  FOREACH(pNode, pGroupList) {
356,399✔
1116
    if (pNode->type == QUERY_NODE_FUNCTION) {
62,228✔
1117
      bytbname = (strcmp(((struct SFunctionNode*)pNode)->functionName, "tbname") == 0);
54,304✔
1118
      break;
54,304✔
1119
    }
1120
  }
1121
  return bytbname;
348,475✔
1122
}
1123

1124
int32_t createDataSinkParam(SDataSinkNode* pNode, void** pParam, SExecTaskInfo* pTask, SReadHandle* readHandle) {
501,968✔
1125
  switch (pNode->type) {
501,968✔
1126
    case QUERY_NODE_PHYSICAL_PLAN_QUERY_INSERT: {
117✔
1127
      SInserterParam* pInserterParam = taosMemoryCalloc(1, sizeof(SInserterParam));
117!
1128
      if (NULL == pInserterParam) {
117!
1129
        return terrno;
×
1130
      }
1131
      pInserterParam->readHandle = readHandle;
117✔
1132

1133
      *pParam = pInserterParam;
117✔
1134
      break;
117✔
1135
    }
1136
    case QUERY_NODE_PHYSICAL_PLAN_DELETE: {
5,566✔
1137
      SDeleterParam* pDeleterParam = taosMemoryCalloc(1, sizeof(SDeleterParam));
5,566!
1138
      if (NULL == pDeleterParam) {
5,566!
1139
        return terrno;
×
1140
      }
1141

1142
      SArray* pInfoList = NULL;
5,566✔
1143
      int32_t code = getTableListInfo(pTask, &pInfoList);
5,566✔
1144
      if (code != TSDB_CODE_SUCCESS || pInfoList == NULL) {
5,566!
1145
        taosMemoryFree(pDeleterParam);
×
1146
        return code;
×
1147
      }
1148

1149
      STableListInfo* pTableListInfo = taosArrayGetP(pInfoList, 0);
5,566✔
1150
      taosArrayDestroy(pInfoList);
5,566✔
1151

1152
      pDeleterParam->suid = tableListGetSuid(pTableListInfo);
5,566✔
1153

1154
      // TODO extract uid list
1155
      int32_t numOfTables = 0;
5,566✔
1156
      code = tableListGetSize(pTableListInfo, &numOfTables);
5,566✔
1157
      if (code != TSDB_CODE_SUCCESS) {
5,566!
1158
        qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(code));
×
1159
        taosMemoryFree(pDeleterParam);
×
1160
        return code;
×
1161
      }
1162

1163
      pDeleterParam->pUidList = taosArrayInit(numOfTables, sizeof(uint64_t));
5,566✔
1164
      if (NULL == pDeleterParam->pUidList) {
5,566!
1165
        taosMemoryFree(pDeleterParam);
×
1166
        return terrno;
×
1167
      }
1168

1169
      for (int32_t i = 0; i < numOfTables; ++i) {
11,562✔
1170
        STableKeyInfo* pTable = tableListGetInfo(pTableListInfo, i);
5,996✔
1171
        if (!pTable) {
5,996!
1172
          taosArrayDestroy(pDeleterParam->pUidList);
×
1173
          taosMemoryFree(pDeleterParam);
×
1174
          return TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR;
×
1175
        }
1176
        void* tmp = taosArrayPush(pDeleterParam->pUidList, &pTable->uid);
5,996✔
1177
        if (!tmp) {
5,996!
1178
          taosArrayDestroy(pDeleterParam->pUidList);
×
1179
          taosMemoryFree(pDeleterParam);
×
1180
          return terrno;
×
1181
        }
1182
      }
1183

1184
      *pParam = pDeleterParam;
5,566✔
1185
      break;
5,566✔
1186
    }
1187
    default:
496,285✔
1188
      break;
496,285✔
1189
  }
1190

1191
  return TSDB_CODE_SUCCESS;
501,968✔
1192
}
1193

1194
void streamOpReleaseState(SOperatorInfo* pOperator) {
×
1195
  SOperatorInfo* downstream = pOperator->pDownstream[0];
×
1196
  if (downstream->fpSet.releaseStreamStateFn) {
×
1197
    downstream->fpSet.releaseStreamStateFn(downstream);
×
1198
  }
1199
}
×
1200

1201
void streamOpReloadState(SOperatorInfo* pOperator) {
×
1202
  SOperatorInfo* downstream = pOperator->pDownstream[0];
×
1203
  if (downstream->fpSet.reloadStreamStateFn) {
×
1204
    downstream->fpSet.reloadStreamStateFn(downstream);
×
1205
  }
1206
}
×
1207

1208
void freeOperatorParamImpl(SOperatorParam* pParam, SOperatorParamType type) {
147,247✔
1209
  int32_t childrenNum = taosArrayGetSize(pParam->pChildren);
147,247✔
1210
  for (int32_t i = 0; i < childrenNum; ++i) {
147,247!
1211
    SOperatorParam* pChild = taosArrayGetP(pParam->pChildren, i);
×
1212
    freeOperatorParam(pChild, type);
×
1213
  }
1214

1215
  taosArrayDestroy(pParam->pChildren);
147,247✔
1216
  pParam->pChildren = NULL;
147,247✔
1217

1218
  taosMemoryFreeClear(pParam->value);
147,247!
1219

1220
  taosMemoryFree(pParam);
147,247!
1221
}
147,247✔
1222

1223
void freeExchangeGetBasicOperatorParam(void* pParam) {
19,380✔
1224
  SExchangeOperatorBasicParam* pBasic = (SExchangeOperatorBasicParam*)pParam;
19,380✔
1225
  taosArrayDestroy(pBasic->uidList);
19,380✔
1226
  if (pBasic->colMap) {
19,380✔
1227
    taosArrayDestroy(pBasic->colMap->colMap);
13,544✔
1228
    taosMemoryFreeClear(pBasic->colMap);
13,544!
1229
  }
1230
}
19,380✔
1231

1232
void freeExchangeGetOperatorParam(SOperatorParam* pParam) {
19,115✔
1233
  SExchangeOperatorParam* pExcParam = (SExchangeOperatorParam*)pParam->value;
19,115✔
1234
  if (pExcParam->multiParams) {
19,115✔
1235
    SExchangeOperatorBatchParam* pExcBatch = (SExchangeOperatorBatchParam*)pParam->value;
339✔
1236
    tSimpleHashCleanup(pExcBatch->pBatchs);
339✔
1237
  } else {
1238
    freeExchangeGetBasicOperatorParam(&pExcParam->basic);
18,776✔
1239
  }
1240

1241
  freeOperatorParamImpl(pParam, OP_GET_PARAM);
19,115✔
1242
}
19,115✔
1243

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

1246
void freeGroupCacheGetOperatorParam(SOperatorParam* pParam) { freeOperatorParamImpl(pParam, OP_GET_PARAM); }
14,698✔
1247

1248
void freeGroupCacheNotifyOperatorParam(SOperatorParam* pParam) { freeOperatorParamImpl(pParam, OP_NOTIFY_PARAM); }
×
1249

1250
void freeMergeJoinGetOperatorParam(SOperatorParam* pParam) { freeOperatorParamImpl(pParam, OP_GET_PARAM); }
7,349✔
1251

1252
void freeMergeJoinNotifyOperatorParam(SOperatorParam* pParam) { freeOperatorParamImpl(pParam, OP_NOTIFY_PARAM); }
×
1253

1254
void freeTagScanGetOperatorParam(SOperatorParam* pParam) { freeOperatorParamImpl(pParam, OP_GET_PARAM); }
7,874✔
1255

1256
void freeTableScanGetOperatorParam(SOperatorParam* pParam) {
92,991✔
1257
  STableScanOperatorParam* pTableScanParam = (STableScanOperatorParam*)pParam->value;
92,991✔
1258
  taosArrayDestroy(pTableScanParam->pUidList);
92,991✔
1259
  if (pTableScanParam->pOrgTbInfo) {
92,991✔
1260
    taosArrayDestroy(pTableScanParam->pOrgTbInfo->colMap);
91,728✔
1261
    taosMemoryFreeClear(pTableScanParam->pOrgTbInfo);
91,728!
1262
  }
1263
  freeOperatorParamImpl(pParam, OP_GET_PARAM);
92,991✔
1264
}
92,991✔
1265

1266
void freeTableScanNotifyOperatorParam(SOperatorParam* pParam) { freeOperatorParamImpl(pParam, OP_NOTIFY_PARAM); }
×
1267

1268
void freeTagScanNotifyOperatorParam(SOperatorParam* pParam) { freeOperatorParamImpl(pParam, OP_NOTIFY_PARAM); }
×
1269

1270
void freeOpParamItem(void* pItem) {
18,764✔
1271
  SOperatorParam* pParam = *(SOperatorParam**)pItem;
18,764✔
1272
  pParam->reUse = false;
18,764✔
1273
  freeOperatorParam(pParam, OP_GET_PARAM);
18,764✔
1274
}
18,764✔
1275

1276
void freeVirtualTableScanGetOperatorParam(SOperatorParam* pParam) {
5,220✔
1277
  SVTableScanOperatorParam* pVTableScanParam = (SVTableScanOperatorParam*)pParam->value;
5,220✔
1278
  taosArrayDestroyEx(pVTableScanParam->pOpParamArray, freeOpParamItem);
5,220✔
1279
  freeOpParamItem(&pVTableScanParam->pTagScanOp);
5,220✔
1280
  freeOperatorParamImpl(pParam, OP_GET_PARAM);
5,220✔
1281
}
5,220✔
1282

1283
void freeVTableScanNotifyOperatorParam(SOperatorParam* pParam) { freeOperatorParamImpl(pParam, OP_NOTIFY_PARAM); }
×
1284

1285
void freeOperatorParam(SOperatorParam* pParam, SOperatorParamType type) {
1,004,701✔
1286
  if (NULL == pParam || pParam->reUse) {
1,004,701✔
1287
    return;
857,454✔
1288
  }
1289

1290
  switch (pParam->opType) {
147,247!
1291
    case QUERY_NODE_PHYSICAL_PLAN_EXCHANGE:
19,115✔
1292
      type == OP_GET_PARAM ? freeExchangeGetOperatorParam(pParam) : freeExchangeNotifyOperatorParam(pParam);
19,115!
1293
      break;
19,115✔
1294
    case QUERY_NODE_PHYSICAL_PLAN_GROUP_CACHE:
14,698✔
1295
      type == OP_GET_PARAM ? freeGroupCacheGetOperatorParam(pParam) : freeGroupCacheNotifyOperatorParam(pParam);
14,698!
1296
      break;
14,698✔
1297
    case QUERY_NODE_PHYSICAL_PLAN_MERGE_JOIN:
7,349✔
1298
      type == OP_GET_PARAM ? freeMergeJoinGetOperatorParam(pParam) : freeMergeJoinNotifyOperatorParam(pParam);
7,349!
1299
      break;
7,349✔
1300
    case QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN:
92,991✔
1301
      type == OP_GET_PARAM ? freeTableScanGetOperatorParam(pParam) : freeTableScanNotifyOperatorParam(pParam);
92,991!
1302
      break;
92,991✔
1303
    case QUERY_NODE_PHYSICAL_PLAN_VIRTUAL_TABLE_SCAN:
5,220✔
1304
      type == OP_GET_PARAM ? freeVirtualTableScanGetOperatorParam(pParam) : freeVTableScanNotifyOperatorParam(pParam);
5,220!
1305
      break;
5,220✔
1306
    case QUERY_NODE_PHYSICAL_PLAN_TAG_SCAN:
7,874✔
1307
      type == OP_GET_PARAM ? freeTagScanGetOperatorParam(pParam) : freeTagScanNotifyOperatorParam(pParam);
7,874!
1308
      break;
7,874✔
1309
    default:
×
1310
      qError("unsupported op %d param, type %d", pParam->opType, type);
×
1311
      break;
×
1312
  }
1313
}
1314

1315
void freeResetOperatorParams(struct SOperatorInfo* pOperator, SOperatorParamType type, bool allFree) {
2,520,010✔
1316
  SOperatorParam**  ppParam = NULL;
2,520,010✔
1317
  SOperatorParam*** pppDownstramParam = NULL;
2,520,010✔
1318
  switch (type) {
2,520,010!
1319
    case OP_GET_PARAM:
1,316,607✔
1320
      ppParam = &pOperator->pOperatorGetParam;
1,316,607✔
1321
      pppDownstramParam = &pOperator->pDownstreamGetParams;
1,316,607✔
1322
      break;
1,316,607✔
1323
    case OP_NOTIFY_PARAM:
1,203,428✔
1324
      ppParam = &pOperator->pOperatorNotifyParam;
1,203,428✔
1325
      pppDownstramParam = &pOperator->pDownstreamNotifyParams;
1,203,428✔
1326
      break;
1,203,428✔
1327
    default:
×
1328
      return;
×
1329
  }
1330

1331
  if (*ppParam) {
2,520,035✔
1332
    freeOperatorParam(*ppParam, type);
12,569✔
1333
    *ppParam = NULL;
12,569✔
1334
  }
1335

1336
  if (*pppDownstramParam) {
2,520,035✔
1337
    for (int32_t i = 0; i < pOperator->numOfDownstream; ++i) {
137,024✔
1338
      if ((*pppDownstramParam)[i]) {
23,855!
1339
        freeOperatorParam((*pppDownstramParam)[i], type);
×
1340
        (*pppDownstramParam)[i] = NULL;
×
1341
      }
1342
    }
1343
    if (allFree) {
113,169✔
1344
      taosMemoryFreeClear(*pppDownstramParam);
12,293!
1345
    }
1346
  }
1347
}
1348

1349
FORCE_INLINE int32_t getNextBlockFromDownstreamImpl(struct SOperatorInfo* pOperator, int32_t idx, bool clearParam,
2,632,127✔
1350
                                                    SSDataBlock** pResBlock) {
1351
  QRY_PARAM_CHECK(pResBlock);
2,632,127!
1352

1353
  int32_t code = 0;
2,632,127✔
1354
  if (pOperator->pDownstreamGetParams && pOperator->pDownstreamGetParams[idx]) {
2,632,127!
1355
    qDebug("DynOp: op %s start to get block from downstream %s", pOperator->name, pOperator->pDownstream[idx]->name);
22,445!
1356
    code = pOperator->pDownstream[idx]->fpSet.getNextExtFn(pOperator->pDownstream[idx],
22,445✔
1357
                                                           pOperator->pDownstreamGetParams[idx], pResBlock);
22,445✔
1358
    if (clearParam && (code == 0)) {
22,445!
1359
      freeOperatorParam(pOperator->pDownstreamGetParams[idx], OP_GET_PARAM);
×
1360
      pOperator->pDownstreamGetParams[idx] = NULL;
×
1361
    }
1362

1363
    if (code) {
22,445!
1364
      qError("failed to get next data block from upstream at %s, line:%d code:%s", __func__, __LINE__, tstrerror(code));
×
1365
    }
1366
    return code;
22,445✔
1367
  }
1368

1369
  code = pOperator->pDownstream[idx]->fpSet.getNextFn(pOperator->pDownstream[idx], pResBlock);
2,609,682✔
1370
  if (code) {
2,585,380!
1371
    qError("failed to get next data block from upstream at %s, %d code:%s", __func__, __LINE__, tstrerror(code));
×
1372
  }
1373
  return code;
2,585,381✔
1374
}
1375

1376
bool compareVal(const char* v, const SStateKeys* pKey) {
622,575✔
1377
  if (IS_VAR_DATA_TYPE(pKey->type)) {
622,575!
1378
    if (IS_STR_DATA_BLOB(pKey->type)) {
614!
1379
      if (blobDataLen(v) != blobDataLen(pKey->pData)) {
×
1380
        return false;
×
1381
      } else {
1382
        return memcmp(blobDataVal(v), blobDataVal(pKey->pData), blobDataLen(v)) == 0;
×
1383
      }
1384
    } else {
1385
      if (varDataLen(v) != varDataLen(pKey->pData)) {
614!
1386
        return false;
×
1387
      } else {
1388
        return memcmp(varDataVal(v), varDataVal(pKey->pData), varDataLen(v)) == 0;
614✔
1389
      }
1390
    }
1391
  } else {
1392
    return memcmp(pKey->pData, v, pKey->bytes) == 0;
621,961✔
1393
  }
1394
}
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