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

taosdata / TDengine / #4799

13 Oct 2025 06:50AM UTC coverage: 58.524% (+0.09%) from 58.433%
#4799

push

travis-ci

web-flow
Merge pull request #33213 from taosdata/fix/huoh/timemoe_model_directory

fix: fix tdgpt timemoe model directory

139292 of 303332 branches covered (45.92%)

Branch coverage included in aggregate %.

210815 of 294900 relevant lines covered (71.49%)

23992095.37 hits per line

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

69.62
/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) {
342,403,797✔
84
  SFilePage* pData = NULL;
342,403,797✔
85

86
  // in the first scan, new space needed for results
87
  int32_t pageId = -1;
342,403,797✔
88
  if (*currentPageId == -1) {
342,403,797✔
89
    pData = getNewBufPage(pResultBuf, &pageId);
8,733,948✔
90
    if (pData == NULL) {
8,733,376✔
91
      qError("failed to get buffer, code:%s", tstrerror(terrno));
322!
92
      return NULL;
×
93
    }
94
    pData->num = sizeof(SFilePage);
8,733,054✔
95
  } else {
96
    pData = getBufPage(pResultBuf, *currentPageId);
333,669,849✔
97
    if (pData == NULL) {
333,712,156!
98
      qError("failed to get buffer, code:%s", tstrerror(terrno));
×
99
      return NULL;
×
100
    }
101

102
    pageId = *currentPageId;
333,712,156✔
103

104
    if (pData->num + interBufSize > getBufPageSize(pResultBuf)) {
333,712,156✔
105
      // release current page first, and prepare the next one
106
      releaseBufPage(pResultBuf, pData);
24,823,263✔
107

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

117
  setBufPageDirty(pData, true);
342,371,792✔
118

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

122
  memset((char*)pResultRow, 0, interBufSize);
342,328,310✔
123
  pResultRow->pageId = pageId;
342,328,310✔
124
  pResultRow->offset = (int32_t)pData->num;
342,328,310✔
125

126
  *currentPageId = pageId;
342,328,310✔
127
  pData->num += interBufSize;
342,328,310✔
128
  return pResultRow;
342,328,310✔
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,
403,107,105✔
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);
403,107,105✔
142
  if (!keepGroup) {
403,107,105✔
143
    *(uint64_t*)pSup->keyBuf = calcGroupId(pSup->keyBuf, GET_RES_WINDOW_KEY_LEN(bytes));
37,581,526✔
144
  }
145

146
  SResultRowPosition* p1 =
147
      (SResultRowPosition*)tSimpleHashGet(pSup->pResultRowHashTable, pSup->keyBuf, GET_RES_WINDOW_KEY_LEN(bytes));
403,139,248✔
148

149
  SResultRow* pResult = NULL;
403,371,320✔
150

151
  // in case of repeat scan/reverse scan, no new time window added.
152
  if (isIntervalQuery) {
403,371,320✔
153
    if (p1 != NULL) {  // the *p1 may be NULL in case of sliding+offset exists.
359,464,122✔
154
      pResult = getResultRowByPos(pResultBuf, p1, true);
42,802,215✔
155
      if (pResult == NULL) {
42,802,215!
156
        pTaskInfo->code = terrno;
×
157
        return NULL;
×
158
      }
159

160
      if (pResult->pageId != p1->pageId || pResult->offset != p1->offset) {
42,802,215!
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) {
43,907,198✔
170
      // todo
171
      pResult = getResultRowByPos(pResultBuf, p1, true);
17,917,984✔
172
      if (NULL == pResult) {
17,917,984!
173
        pTaskInfo->code = terrno;
×
174
        return NULL;
×
175
      }
176

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

185
  // 1. close current opened time window
186
  if (pResultRowInfo->cur.pageId != -1 && ((pResult == NULL) || (pResult->pageId != pResultRowInfo->cur.pageId))) {
403,346,347✔
187
    SResultRowPosition pos = pResultRowInfo->cur;
352,815,880✔
188
    SFilePage*         pPage = getBufPage(pResultBuf, pos.pageId);
352,815,880✔
189
    if (pPage == NULL) {
352,186,419!
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);
352,186,419✔
195
  }
196

197
  // allocate a new buffer page
198
  if (pResult == NULL) {
402,420,128✔
199
    pResult = getNewResultRow(pResultBuf, &pSup->currentPageId, pSup->resultRowSize);
341,706,802✔
200
    if (pResult == NULL) {
342,015,571!
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};
342,015,571✔
207
    int32_t code = tSimpleHashPut(pSup->pResultRowHashTable, pSup->keyBuf, GET_RES_WINDOW_KEY_LEN(bytes), &pos,
342,015,571✔
208
                                  sizeof(SResultRowPosition));
209
    if (code != TSDB_CODE_SUCCESS) {
342,474,444✔
210
      qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(code));
14,345!
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};
403,173,425✔
218

219
  // too many time window in query
220
  if (pTaskInfo->execModel == OPTR_EXEC_MODEL_BATCH &&
806,055,209!
221
      tSimpleHashGetSize(pSup->pResultRowHashTable) > MAX_INTERVAL_TIME_WINDOW) {
403,130,399✔
222
    pTaskInfo->code = TSDB_CODE_QRY_TOO_MANY_TIMEWINDOW;
×
223
    return NULL;
×
224
  }
225

226
  return pResult;
402,924,810✔
227
}
228

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

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

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

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

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

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

271
int32_t setInputDataBlock(SExprSupp* pExprSup, SSDataBlock* pBlock, int32_t order, int32_t scanFlag,
43,403,007✔
272
                          bool createDummyCol) {
273
  if (pBlock->pBlockAgg != NULL) {
43,403,007✔
274
    return doSetInputDataBlockInfo(pExprSup, pBlock, order, scanFlag);
4,279,421✔
275
  } else {
276
    return doSetInputDataBlock(pExprSup, pBlock, order, scanFlag, createDummyCol);
39,123,586✔
277
  }
278
}
279

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

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

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

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

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

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

337
  for (int32_t i = 0; i < pExprSup->numOfExprs; ++i) {
109,471,985✔
338
    pCtx[i].order = order;
70,371,190✔
339
    pCtx[i].input.numOfRows = pBlock->info.rows;
70,371,190✔
340

341
    pCtx[i].pSrcBlock = pBlock;
70,371,190✔
342
    pCtx[i].scanFlag = scanFlag;
70,371,190✔
343

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

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

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

355
    for (int32_t j = 0; j < pOneExpr->base.numOfParams; ++j) {
150,854,579✔
356
      SFunctParam* pFuncParam = &pOneExpr->base.pParam[j];
80,506,442✔
357
      if (pFuncParam->type == FUNC_PARAM_TYPE_COLUMN) {
80,506,442✔
358
        int32_t slotId = pFuncParam->pCol->slotId;
66,800,655✔
359
        pInput->pData[j] = taosArrayGet(pBlock->pDataBlock, slotId);
66,800,655✔
360
        pInput->totalRows = pBlock->info.rows;
66,769,954✔
361
        pInput->numOfRows = pBlock->info.rows;
66,769,954✔
362
        pInput->startRowIndex = 0;
66,769,954✔
363
        pInput->blankFill = pBlock->info.blankFill;
66,769,954✔
364

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

368
        if (fmIsImplicitTsFunc(pCtx[i].functionId) && (j == tsParamIdx)) {
66,769,954✔
369
          pInput->pPTS = pInput->pData[j];  // in case of merge function, this is not always the ts column data.
11,742,553✔
370
        }
371
        if (hasPk && (j == pkParamIdx)) {
66,777,602✔
372
          pInput->pPrimaryKey = pInput->pData[j];
7,837✔
373
        }
374
        QUERY_CHECK_CONDITION((pInput->pData[j] != NULL), code, lino, _end, TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR);
66,777,602!
375
      } else if (pFuncParam->type == FUNC_PARAM_TYPE_VALUE) {
13,705,787✔
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) {
13,269,648✔
379
          pInput->totalRows = pBlock->info.rows;
30,829✔
380
          pInput->numOfRows = pBlock->info.rows;
30,829✔
381
          pInput->startRowIndex = 0;
30,829✔
382
          pInput->blankFill = pBlock->info.blankFill;
30,829✔
383

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

391
_end:
39,100,795✔
392
  if (code != TSDB_CODE_SUCCESS) {
39,100,795!
393
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
×
394
  }
395
  return code;
39,118,517✔
396
}
397

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

401
  // in case of timestamp column, always generated results.
402
  int32_t functionId = pCtx->functionId;
1,123,875,166✔
403
  if (functionId == -1) {
1,123,875,166✔
404
    return false;
53,757,459✔
405
  }
406

407
  if (pCtx->scanFlag == PRE_SCAN) {
1,070,117,707✔
408
    return fmIsRepeatScanFunc(pCtx->functionId);
2,729,438✔
409
  }
410

411
  if (isRowEntryCompleted(pResInfo)) {
1,067,388,269!
412
    return false;
×
413
  }
414

415
  return true;
1,067,388,269✔
416
}
417

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

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

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

442
  if (type == TSDB_DATA_TYPE_BIGINT) {
3,493,827!
443
    int64_t v = pFuncParam->param.i;
3,493,827✔
444
    *da = (SColumnDataAgg){.numOfNull = 0, .min = v, .max = v, .sum = v * numOfRows};
3,493,827✔
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;
3,493,827✔
466
}
467

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

473
  SInputColumnInfoData* pInput = &pCtx->input;
4,279,442✔
474
  pInput->numOfRows = numOfRows;
4,279,442✔
475
  pInput->totalRows = numOfRows;
4,279,442✔
476

477
  if (pBlock->pBlockAgg != NULL) {
4,279,442!
478
    pInput->colDataSMAIsSet = true;
4,279,458✔
479

480
    for (int32_t j = 0; j < pExprInfo->base.numOfParams; ++j) {
12,052,752✔
481
      SFunctParam* pFuncParam = &pExprInfo->base.pParam[j];
7,773,289✔
482

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

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

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

523
  return win;
2,165,185✔
524
}
525

526
int32_t setResultRowInitCtx(SResultRow* pResult, SqlFunctionCtx* pCtx, int32_t numOfOutput,
694,064,323✔
527
                            int32_t* rowEntryInfoOffset) {
528
  bool init = false;
694,064,323✔
529
  for (int32_t i = 0; i < numOfOutput; ++i) {
2,045,847,648✔
530
    pCtx[i].resultInfo = getResultEntryInfo(pResult, i, rowEntryInfoOffset);
1,352,303,468✔
531
    if (init) {
1,351,783,302✔
532
      continue;
103,672,927✔
533
    }
534

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

541
    if (pCtx[i].isPseudoFunc) {
1,248,110,375✔
542
      continue;
227,279,465✔
543
    }
544

545
    if (!pResInfo->initialized) {
1,020,830,910✔
546
      if (pCtx[i].functionId != -1) {
962,389,152✔
547
        int32_t code = pCtx[i].fpSet.init(&pCtx[i], pResInfo);
931,164,269✔
548
        if (code != TSDB_CODE_SUCCESS && fmIsUserDefinedFunc(pCtx[i].functionId)) {
931,633,800!
549
          pResInfo->initialized = false;
469,508✔
550
          qError("failed to initialize udf, funcId:%d error:%s", pCtx[i].functionId, tstrerror(code));
469,508!
551
          return TSDB_CODE_UDF_FUNC_EXEC_FAILURE;
×
552
        } else if (code != TSDB_CODE_SUCCESS) {
931,164,292!
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;
31,224,883✔
558
      }
559
    } else {
560
      init = true;
58,441,758✔
561
    }
562
  }
563
  return TSDB_CODE_SUCCESS;
693,544,180✔
564
}
565

566
void clearResultRowInitFlag(SqlFunctionCtx* pCtx, int32_t numOfOutput) {
171,857,696✔
567
  for (int32_t i = 0; i < numOfOutput; ++i) {
424,184,375✔
568
    SResultRowEntryInfo* pResInfo = pCtx[i].resultInfo;
252,326,679✔
569
    if (pResInfo == NULL) {
252,326,679!
570
      continue;
×
571
    }
572

573
    pResInfo->initialized = false;
252,326,679✔
574
    pResInfo->numOfRes = 0;
252,326,679✔
575
    pResInfo->isNullRes = 0;
252,326,679✔
576
    pResInfo->complete = false;
252,326,679✔
577
  }
578
}
171,857,696✔
579

580
int32_t doFilter(SSDataBlock* pBlock, SFilterInfo* pFilterInfo, SColMatchInfo* pColMatchInfo, SColumnInfoData** pRet) {
64,012,581✔
581
  int32_t code = TSDB_CODE_SUCCESS;
64,012,581✔
582
  int32_t lino = 0;
64,012,581✔
583
  if (pFilterInfo == NULL || pBlock->info.rows == 0) {
64,012,581✔
584
    return TSDB_CODE_SUCCESS;
55,888,117✔
585
  }
586

587
  SFilterColumnParam param1 = {.numOfCols = taosArrayGetSize(pBlock->pDataBlock), .pDataBlock = pBlock->pDataBlock};
8,124,464✔
588
  SColumnInfoData*   p = NULL;
8,124,315✔
589

590
  code = filterSetDataFromSlotId(pFilterInfo, &param1);
8,124,315✔
591
  QUERY_CHECK_CODE(code, lino, _err);
8,124,215!
592

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

598
  code = extractQualifiedTupleByFilterResult(pBlock, pRet != NULL ? *pRet : p, status);
8,124,433✔
599
  QUERY_CHECK_CODE(code, lino, _err);
8,124,395!
600

601
  if (pColMatchInfo != NULL) {
8,124,395✔
602
    size_t size = taosArrayGetSize(pColMatchInfo->pList);
6,985,997✔
603
    for (int32_t i = 0; i < size; ++i) {
6,986,156✔
604
      SColMatchItem* pInfo = taosArrayGet(pColMatchInfo->pList, i);
6,985,949✔
605
      QUERY_CHECK_NULL(pInfo, code, lino, _err, terrno);
6,984,982!
606
      if (pInfo->colId == PRIMARYKEY_TIMESTAMP_COL_ID) {
6,984,982✔
607
        SColumnInfoData* pColData = taosArrayGet(pBlock->pDataBlock, pInfo->dstSlotId);
6,984,798✔
608
        QUERY_CHECK_NULL(pColData, code, lino, _err, terrno);
6,984,585!
609
        if (pColData->info.type == TSDB_DATA_TYPE_TIMESTAMP) {
6,984,604✔
610
          code = blockDataUpdateTsWindow(pBlock, pInfo->dstSlotId);
6,984,586✔
611
          QUERY_CHECK_CODE(code, lino, _err);
6,985,181!
612
          break;
6,985,181✔
613
        }
614
      }
615
    }
616
  }
617
  code = blockDataCheck(pBlock);
8,123,786✔
618
  QUERY_CHECK_CODE(code, lino, _err);
8,123,583!
619
_err:
8,123,583✔
620
  if (code != TSDB_CODE_SUCCESS) {
8,123,584✔
621
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
1!
622
  }
623
  colDataDestroy(p);
8,123,584✔
624
  taosMemoryFree(p);
8,124,604!
625
  return code;
8,124,619✔
626
}
627

628
int32_t extractQualifiedTupleByFilterResult(SSDataBlock* pBlock, const SColumnInfoData* p, int32_t status) {
8,124,938✔
629
  int32_t code = TSDB_CODE_SUCCESS;
8,124,938✔
630
  int8_t* pIndicator = (int8_t*)p->pData;
8,124,938✔
631
  if (status == FILTER_RESULT_ALL_QUALIFIED) {
8,124,938✔
632
    // here nothing needs to be done
633
  } else if (status == FILTER_RESULT_NONE_QUALIFIED) {
1,212,794✔
634
    code = trimDataBlock(pBlock, pBlock->info.rows, NULL);
1,027,980✔
635
    pBlock->info.rows = 0;
1,027,967✔
636
  } else if (status == FILTER_RESULT_PARTIAL_QUALIFIED) {
184,814!
637
    code = trimDataBlock(pBlock, pBlock->info.rows, (bool*)pIndicator);
184,862✔
638
  } else {
639
    qError("unknown filter result type: %d", status);
×
640
  }
641
  return code;
8,125,029✔
642
}
643

644
void doUpdateNumOfRows(SqlFunctionCtx* pCtx, SResultRow* pRow, int32_t numOfExprs, const int32_t* rowEntryOffset) {
638,439,428✔
645
  bool returnNotNull = false;
638,439,428✔
646
  for (int32_t j = 0; j < numOfExprs; ++j) {
1,817,175,945✔
647
    SResultRowEntryInfo* pResInfo = getResultEntryInfo(pRow, j, rowEntryOffset);
1,178,558,515✔
648
    if (!isRowEntryInitialized(pResInfo)) {
1,178,736,517✔
649
      continue;
212,594,048✔
650
    } else {
651
    }
652

653
    if (pRow->numOfRows < pResInfo->numOfRes) {
966,142,469✔
654
      pRow->numOfRows = pResInfo->numOfRes;
629,542,303✔
655
    }
656

657
    if (pCtx[j].isNotNullFunc) {
966,142,469✔
658
      returnNotNull = true;
273,022,924✔
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) {
638,617,430✔
664
    pRow->numOfRows = 1;
7,904✔
665
  }
666
}
638,617,430✔
667

668
int32_t copyResultrowToDataBlock(SExprInfo* pExprInfo, int32_t numOfExprs, SResultRow* pRow, SqlFunctionCtx* pCtx,
630,489,873✔
669
                                 SSDataBlock* pBlock, const int32_t* rowEntryOffset, SExecTaskInfo* pTaskInfo) {
670
  int32_t code = TSDB_CODE_SUCCESS;
630,489,873✔
671
  int32_t lino = 0;
630,489,873✔
672
  for (int32_t j = 0; j < numOfExprs; ++j) {
1,766,365,419✔
673
    int32_t slotId = pExprInfo[j].base.resSchema.slotId;
1,159,836,696✔
674

675
    pCtx[j].resultInfo = getResultEntryInfo(pRow, j, rowEntryOffset);
1,159,836,696✔
676
    if (pCtx[j].fpSet.finalize) {
1,159,939,356✔
677
      if (strcmp(pCtx[j].pExpr->pExpr->_function.functionName, "_group_key") == 0 ||
659,794,965✔
678
          strcmp(pCtx[j].pExpr->pExpr->_function.functionName, "_group_const_value") == 0) {
640,367,802✔
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,428,786!
682
          pCtx[j].resultInfo->numOfRes = pRow->numOfRows;
20,131,177✔
683
        }
684
      }
685

686
      code = pCtx[j].fpSet.finalize(&pCtx[j], pBlock);
659,794,965✔
687
      if (TSDB_CODE_SUCCESS != code) {
650,948,125!
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) {
500,144,391✔
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);
243,315,488✔
697
      QUERY_CHECK_NULL(pColInfoData, code, lino, _end, terrno);
242,082,713!
698
      char*            in = GET_ROWCELL_INTERBUF(pCtx[j].resultInfo);
242,112,550✔
699
      for (int32_t k = 0; k < pRow->numOfRows; ++k) {        
500,767,283✔
700
        code = colDataSetValOrCover(pColInfoData, pBlock->info.rows + k, in, pCtx[j].resultInfo->isNullRes);
259,314,506✔
701
        QUERY_CHECK_CODE(code, lino, _end);
258,654,733!
702
      }
703
    }
704
  }
705

706
_end:
606,528,723✔
707
  if (code != TSDB_CODE_SUCCESS) {
606,528,723!
708
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
×
709
  }
710
  return code;
617,891,082✔
711
}
712

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

724
  SqlFunctionCtx* pCtx = pSup->pCtx;
122,280,687✔
725
  SExprInfo*      pExprInfo = pSup->pExprInfo;
122,280,687✔
726
  const int32_t*  rowEntryOffset = pSup->rowEntryInfoOffset;
122,280,687✔
727

728
  doUpdateNumOfRows(pCtx, pRow, pSup->numOfExprs, rowEntryOffset);
122,280,687✔
729
  if (pRow->numOfRows == 0) {
122,272,612✔
730
    releaseBufPage(pBuf, page);
522✔
731
    return;
×
732
  }
733

734
  int32_t size = pBlock->info.capacity;
122,272,090✔
735
  while (pBlock->info.rows + pRow->numOfRows > size) {
122,451,225✔
736
    size = size * 1.25;
179,135✔
737
  }
738

739
  int32_t code = blockDataEnsureCapacity(pBlock, size);
122,272,090✔
740
  if (TAOS_FAILED(code)) {
122,271,877!
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);
122,271,877✔
747
  if (TAOS_FAILED(code)) {
121,913,667!
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);
121,913,667✔
754
  pBlock->info.rows += pRow->numOfRows;
122,040,123✔
755
}
756

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

766
  size_t  keyLen = 0;
8,806,683✔
767
  int32_t numOfRows = tSimpleHashGetSize(pHashmap);
8,806,683✔
768

769
  // begin from last iter
770
  void*   pData = pGroupResInfo->dataPos;
8,806,438✔
771
  int32_t iter = pGroupResInfo->iter;
8,806,438✔
772
  while ((pData = tSimpleHashIterate(pHashmap, pData, &iter)) != NULL) {
28,269,076✔
773
    void*               key = tSimpleHashGetKey(pData, &keyLen);
27,926,156✔
774
    SResultRowPosition* pos = pData;
27,926,156✔
775
    uint64_t            groupId = *(uint64_t*)key;
27,926,156✔
776

777
    SFilePage* page = getBufPage(pBuf, pos->pageId);
27,926,156✔
778
    if (page == NULL) {
27,923,883!
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);
27,923,883✔
784

785
    doUpdateNumOfRows(pCtx, pRow, numOfExprs, rowEntryOffset);
27,923,883✔
786

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

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

797
    if (!ignoreGroup) {
27,921,904✔
798
      if (pBlock->info.id.groupId == 0) {
16,936,250✔
799
        pBlock->info.id.groupId = groupId;
8,485,397✔
800
      } else {
801
        // current value belongs to different group, it can't be packed into one datablock
802
        if (pBlock->info.id.groupId != groupId) {
8,450,853!
803
          releaseBufPage(pBuf, page);
8,456,284✔
804
          break;
8,455,987✔
805
        }
806
      }
807
    }
808

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

822
    code = copyResultrowToDataBlock(pExprInfo, numOfExprs, pRow, pCtx, pBlock, rowEntryOffset, pTaskInfo);
19,465,620✔
823
    releaseBufPage(pBuf, page);
19,457,595✔
824
    QUERY_CHECK_CODE(code, lino, _end);
19,462,638!
825
    pBlock->info.rows += pRow->numOfRows;
19,462,638✔
826
    if (pBlock->info.rows >= threshold) {
19,462,638!
827
      break;
×
828
    }
829
  }
830

831
  qDebug("%s result generated, rows:%" PRId64 ", groupId:%" PRIu64, GET_TASKID(pTaskInfo), pBlock->info.rows,
8,803,141✔
832
         pBlock->info.id.groupId);
833
  pBlock->info.dataLoad = 1;
8,803,191✔
834
  code = blockDataUpdateTsWindow(pBlock, 0);
8,803,191✔
835
  QUERY_CHECK_CODE(code, lino, _end);
8,797,498!
836

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

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

853
  int32_t numOfRows = getNumOfTotalRes(pGroupResInfo);
5,443,696✔
854

855
  for (int32_t i = pGroupResInfo->index; i < numOfRows; i += 1) {
320,616,903✔
856
    SResKeyPos* pPos = taosArrayGetP(pGroupResInfo->pRows, i);
315,847,802✔
857
    SFilePage*  page = getBufPage(pBuf, pPos->pos.pageId);
314,170,795✔
858
    if (page == NULL) {
317,025,801!
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);
317,025,801✔
864

865
    doUpdateNumOfRows(pCtx, pRow, numOfExprs, rowEntryOffset);
317,025,801✔
866

867
    // no results, continue to check the next one
868
    if (pRow->numOfRows == 0) {
316,868,103!
869
      pGroupResInfo->index += 1;
×
870
      releaseBufPage(pBuf, page);
×
871
      continue;
152✔
872
    }
873
    // skip the window which is less than the windowMinSize
874
    if (llabs(pRow->win.ekey - pRow->win.skey) < minWindowSize) {
316,910,615!
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) {
316,910,615✔
883
      if (pBlock->info.id.groupId == 0) {
230,632,745✔
884
        pBlock->info.id.groupId = pPos->groupId;
228,717,435✔
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) {
1,915,310✔
888
          releaseBufPage(pBuf, page);
35,866✔
889
          break;
35,866✔
890
        }
891
      }
892
    }
893

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

903
    pGroupResInfo->index += 1;
316,874,749✔
904
    code = copyResultrowToDataBlock(pExprInfo, numOfExprs, pRow, pCtx, pBlock, rowEntryOffset, pTaskInfo);
316,874,749✔
905
    releaseBufPage(pBuf, page);
314,402,990✔
906
    QUERY_CHECK_CODE(code, lino, _end);
315,778,429!
907

908
    pBlock->info.rows += pRow->numOfRows;
315,778,429✔
909
    if (pBlock->info.rows >= threshold) {
315,778,429✔
910
      break;
605,827✔
911
    }
912
  }
913

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

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

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

932
  // set output datablock version
933
  pBlock->info.version = pTaskInfo->version;
7,152,481✔
934

935
  blockDataCleanup(pBlock);
7,152,481✔
936
  if (!hasRemainResults(pGroupResInfo)) {
7,153,087✔
937
    return;
1,707,652✔
938
  }
939

940
  // clear the existed group id
941
  pBlock->info.id.groupId = 0;
5,444,151✔
942
  if (!pbInfo->mergeResultBlock) {
5,444,151✔
943
    doCopyToSDataBlock(pTaskInfo, pBlock, &pOperator->exprSupp, pBuf, pGroupResInfo, pOperator->resultInfo.threshold,
3,726,638✔
944
                       false, getMinWindowSize(pOperator));
945
  } else {
946
    while (hasRemainResults(pGroupResInfo)) {
3,138,094✔
947
      doCopyToSDataBlock(pTaskInfo, pBlock, &pOperator->exprSupp, pBuf, pGroupResInfo, pOperator->resultInfo.threshold,
1,716,757✔
948
                         true, getMinWindowSize(pOperator));
949
      if (pBlock->info.rows >= pOperator->resultInfo.threshold) {
1,716,915✔
950
        break;
296,334✔
951
      }
952

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

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

962
void destroyExprInfo(SExprInfo* pExpr, int32_t numOfExprs) {
17,116,339✔
963
  for (int32_t i = 0; i < numOfExprs; ++i) {
64,631,534✔
964
    SExprInfo* pExprInfo = &pExpr[i];
47,511,944✔
965
    for (int32_t j = 0; j < pExprInfo->base.numOfParams; ++j) {
96,591,583✔
966
      if (pExprInfo->base.pParam[j].type == FUNC_PARAM_TYPE_COLUMN) {
49,075,528✔
967
        taosMemoryFreeClear(pExprInfo->base.pParam[j].pCol);
45,922,099!
968
      } else if (pExprInfo->base.pParam[j].type == FUNC_PARAM_TYPE_VALUE) {
3,153,429✔
969
        taosVariantDestroy(&pExprInfo->base.pParam[j].param);
2,841,016✔
970
      }
971
    }
972

973
    taosMemoryFree(pExprInfo->base.pParam);
47,516,055!
974
    taosMemoryFree(pExprInfo->pExpr);
47,515,282!
975
  }
976
}
17,119,590✔
977

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

1000
  return 0;
11,428,157✔
1001
}
1002

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

1008
  pResultInfo->capacity = numOfRows;
26,745,239✔
1009
  pResultInfo->threshold = numOfRows * 0.75;
26,745,239✔
1010

1011
  if (pResultInfo->threshold == 0) {
26,745,239✔
1012
    pResultInfo->threshold = numOfRows;
4,710✔
1013
  }
1014
  pResultInfo->totalRows = 0;
26,745,239✔
1015
}
26,745,239✔
1016

1017
void initBasicInfo(SOptrBasicInfo* pInfo, SSDataBlock* pBlock) {
11,370,748✔
1018
  pInfo->pRes = pBlock;
11,370,748✔
1019
  initResultRowInfo(&pInfo->resultRowInfo);
11,370,748✔
1020
}
11,373,607✔
1021

1022
void destroySqlFunctionCtx(SqlFunctionCtx* pCtx, SExprInfo* pExpr, int32_t numOfOutput) {
51,525,802✔
1023
  if (pCtx == NULL) {
51,525,802✔
1024
    return;
32,988,182✔
1025
  }
1026

1027
  for (int32_t i = 0; i < numOfOutput; ++i) {
65,924,771✔
1028
    if (pExpr != NULL) {
47,381,525!
1029
      SExprInfo* pExprInfo = &pExpr[i];
47,383,067✔
1030
      for (int32_t j = 0; j < pExprInfo->base.numOfParams; ++j) {
96,326,851✔
1031
        if (pExprInfo->base.pParam[j].type == FUNC_PARAM_TYPE_VALUE) {
48,941,937✔
1032
          colDataDestroy(pCtx[i].input.pData[j]);
2,837,427✔
1033
          taosMemoryFree(pCtx[i].input.pData[j]);
2,837,437✔
1034
          taosMemoryFree(pCtx[i].input.pColumnDataAgg[j]);
2,837,404✔
1035
        }
1036
      }
1037
    }
1038
    for (int32_t j = 0; j < pCtx[i].numOfParams; ++j) {
96,324,231✔
1039
      taosVariantDestroy(&pCtx[i].param[j].param);
48,942,183✔
1040
    }
1041

1042
    taosMemoryFreeClear(pCtx[i].subsidiaries.pCtx);
47,382,048✔
1043
    taosMemoryFreeClear(pCtx[i].subsidiaries.buf);
47,382,184!
1044
    taosMemoryFree(pCtx[i].input.pData);
47,382,191✔
1045
    taosMemoryFree(pCtx[i].input.pColumnDataAgg);
47,386,853!
1046

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

1052
  taosMemoryFreeClear(pCtx);
18,543,246!
1053
  return;
18,544,856✔
1054
}
1055

1056
int32_t initExprSupp(SExprSupp* pSup, SExprInfo* pExprInfo, int32_t numOfExpr, SFunctionStateStore* pStore) {
18,152,919✔
1057
  pSup->pExprInfo = pExprInfo;
18,152,919✔
1058
  pSup->numOfExprs = numOfExpr;
18,152,919✔
1059
  if (pSup->pExprInfo != NULL) {
18,152,919✔
1060
    pSup->pCtx = createSqlFunctionCtx(pExprInfo, numOfExpr, &pSup->rowEntryInfoOffset, pStore);
14,032,095✔
1061
    if (pSup->pCtx == NULL) {
14,020,483!
1062
      return terrno;
×
1063
    }
1064
  }
1065

1066
  return TSDB_CODE_SUCCESS;
18,148,375✔
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) {
48,133,336✔
1079
  destroySqlFunctionCtx(pSupp->pCtx, pSupp->pExprInfo, pSupp->numOfExprs);
48,133,336✔
1080
  if (pSupp->pExprInfo != NULL) {
48,132,894✔
1081
    destroyExprInfo(pSupp->pExprInfo, pSupp->numOfExprs);
16,902,157✔
1082
    taosMemoryFreeClear(pSupp->pExprInfo);
16,902,407!
1083
  }
1084

1085
  if (pSupp->pFilterInfo != NULL) {
48,133,393✔
1086
    filterFreeInfo(pSupp->pFilterInfo);
5,264,963✔
1087
    pSupp->pFilterInfo = NULL;
5,265,058✔
1088
  }
1089

1090
  taosMemoryFree(pSupp->rowEntryInfoOffset);
48,133,488!
1091
  memset(pSupp, 0, sizeof(SExprSupp));
48,129,732✔
1092
}
48,129,732✔
1093

1094
void cleanupExprSuppWithoutFilter(SExprSupp* pSupp) {
3,397,175✔
1095
  destroySqlFunctionCtx(pSupp->pCtx, pSupp->pExprInfo, pSupp->numOfExprs);
3,397,175✔
1096
  if (pSupp->pExprInfo != NULL) {
3,397,126✔
1097
    destroyExprInfo(pSupp->pExprInfo, pSupp->numOfExprs);
212,888✔
1098
    taosMemoryFreeClear(pSupp->pExprInfo);
212,889!
1099
  }
1100

1101
  taosMemoryFreeClear(pSupp->rowEntryInfoOffset);
3,397,129!
1102
  pSupp->numOfExprs = 0;
3,397,126✔
1103
  pSupp->hasWindowOrGroup = false;
3,397,126✔
1104
  pSupp->pCtx = NULL;
3,397,126✔
1105
}
3,397,126✔
1106

1107
void cleanupBasicInfo(SOptrBasicInfo* pInfo) {
11,387,983✔
1108
  blockDataDestroy(pInfo->pRes);
11,387,983✔
1109
  pInfo->pRes = NULL;
11,390,599✔
1110
}
11,390,599✔
1111

1112
bool groupbyTbname(SNodeList* pGroupList) {
7,410,432✔
1113
  bool   bytbname = false;
7,410,432✔
1114
  SNode* pNode = NULL;
7,410,432✔
1115
  FOREACH(pNode, pGroupList) {
7,466,296✔
1116
    if (pNode->type == QUERY_NODE_FUNCTION) {
210,583✔
1117
      bytbname = (strcmp(((struct SFunctionNode*)pNode)->functionName, "tbname") == 0);
154,719✔
1118
      break;
154,719✔
1119
    }
1120
  }
1121
  return bytbname;
7,410,432✔
1122
}
1123

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

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

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

1149
      STableListInfo* pTableListInfo = taosArrayGetP(pInfoList, 0);
119,019✔
1150
      taosArrayDestroy(pInfoList);
119,002✔
1151

1152
      pDeleterParam->suid = tableListGetSuid(pTableListInfo);
119,026✔
1153

1154
      // TODO extract uid list
1155
      int32_t numOfTables = 0;
119,017✔
1156
      code = tableListGetSize(pTableListInfo, &numOfTables);
119,017✔
1157
      if (code != TSDB_CODE_SUCCESS) {
119,016!
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));
119,016✔
1164
      if (NULL == pDeleterParam->pUidList) {
119,021✔
1165
        taosMemoryFree(pDeleterParam);
3!
1166
        return terrno;
×
1167
      }
1168

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

1184
      *pParam = pDeleterParam;
119,019✔
1185
      break;
119,019✔
1186
    }
1187
    default:
13,461,318✔
1188
      break;
13,461,318✔
1189
  }
1190

1191
  return TSDB_CODE_SUCCESS;
13,580,471✔
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) {
141,924✔
1209
  int32_t childrenNum = taosArrayGetSize(pParam->pChildren);
141,924✔
1210
  for (int32_t i = 0; i < childrenNum; ++i) {
141,924!
1211
    SOperatorParam* pChild = taosArrayGetP(pParam->pChildren, i);
×
1212
    freeOperatorParam(pChild, type);
×
1213
  }
1214

1215
  taosArrayDestroy(pParam->pChildren);
141,924✔
1216
  pParam->pChildren = NULL;
141,924✔
1217

1218
  taosMemoryFreeClear(pParam->value);
141,924!
1219

1220
  taosMemoryFree(pParam);
141,924!
1221
}
141,924✔
1222

1223
void freeExchangeGetBasicOperatorParam(void* pParam) {
16,571✔
1224
  SExchangeOperatorBasicParam* pBasic = (SExchangeOperatorBasicParam*)pParam;
16,571✔
1225
  taosArrayDestroy(pBasic->uidList);
16,571✔
1226
  if (pBasic->colMap) {
16,571✔
1227
    taosArrayDestroy(pBasic->colMap->colMap);
11,435✔
1228
    taosMemoryFreeClear(pBasic->colMap);
11,435!
1229
  }
1230
}
16,571✔
1231

1232
void freeExchangeGetOperatorParam(SOperatorParam* pParam) {
16,306✔
1233
  SExchangeOperatorParam* pExcParam = (SExchangeOperatorParam*)pParam->value;
16,306✔
1234
  if (pExcParam->multiParams) {
16,306✔
1235
    SExchangeOperatorBatchParam* pExcBatch = (SExchangeOperatorBatchParam*)pParam->value;
359✔
1236
    tSimpleHashCleanup(pExcBatch->pBatchs);
359✔
1237
  } else {
1238
    freeExchangeGetBasicOperatorParam(&pExcParam->basic);
15,947✔
1239
  }
1240

1241
  freeOperatorParamImpl(pParam, OP_GET_PARAM);
16,306✔
1242
}
16,306✔
1243

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

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

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

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

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

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

1256
void freeTableScanGetOperatorParam(SOperatorParam* pParam) {
92,043✔
1257
  STableScanOperatorParam* pTableScanParam = (STableScanOperatorParam*)pParam->value;
92,043✔
1258
  taosArrayDestroy(pTableScanParam->pUidList);
92,043✔
1259
  if (pTableScanParam->pOrgTbInfo) {
92,043✔
1260
    taosArrayDestroy(pTableScanParam->pOrgTbInfo->colMap);
90,740✔
1261
    taosMemoryFreeClear(pTableScanParam->pOrgTbInfo);
90,740!
1262
  }
1263
  freeOperatorParamImpl(pParam, OP_GET_PARAM);
92,043✔
1264
}
92,043✔
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) {
15,935✔
1271
  SOperatorParam* pParam = *(SOperatorParam**)pItem;
15,935✔
1272
  pParam->reUse = false;
15,935✔
1273
  freeOperatorParam(pParam, OP_GET_PARAM);
15,935✔
1274
}
15,935✔
1275

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

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

1285
void freeOperatorParam(SOperatorParam* pParam, SOperatorParamType type) {
23,105,789✔
1286
  if (NULL == pParam || pParam->reUse) {
23,105,789✔
1287
    return;
22,963,865✔
1288
  }
1289

1290
  switch (pParam->opType) {
141,924!
1291
    case QUERY_NODE_PHYSICAL_PLAN_EXCHANGE:
16,306✔
1292
      type == OP_GET_PARAM ? freeExchangeGetOperatorParam(pParam) : freeExchangeNotifyOperatorParam(pParam);
16,306!
1293
      break;
16,306✔
1294
    case QUERY_NODE_PHYSICAL_PLAN_GROUP_CACHE:
14,718✔
1295
      type == OP_GET_PARAM ? freeGroupCacheGetOperatorParam(pParam) : freeGroupCacheNotifyOperatorParam(pParam);
14,718!
1296
      break;
14,718✔
1297
    case QUERY_NODE_PHYSICAL_PLAN_MERGE_JOIN:
7,359✔
1298
      type == OP_GET_PARAM ? freeMergeJoinGetOperatorParam(pParam) : freeMergeJoinNotifyOperatorParam(pParam);
7,359!
1299
      break;
7,359✔
1300
    case QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN:
92,043✔
1301
      type == OP_GET_PARAM ? freeTableScanGetOperatorParam(pParam) : freeTableScanNotifyOperatorParam(pParam);
92,043!
1302
      break;
92,043✔
1303
    case QUERY_NODE_PHYSICAL_PLAN_VIRTUAL_TABLE_SCAN:
4,500✔
1304
      type == OP_GET_PARAM ? freeVirtualTableScanGetOperatorParam(pParam) : freeVTableScanNotifyOperatorParam(pParam);
4,500!
1305
      break;
4,500✔
1306
    case QUERY_NODE_PHYSICAL_PLAN_TAG_SCAN:
6,998✔
1307
      type == OP_GET_PARAM ? freeTagScanGetOperatorParam(pParam) : freeTagScanNotifyOperatorParam(pParam);
6,998!
1308
      break;
6,998✔
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) {
66,094,769✔
1316
  SOperatorParam**  ppParam = NULL;
66,094,769✔
1317
  SOperatorParam*** pppDownstramParam = NULL;
66,094,769✔
1318
  switch (type) {
66,094,769!
1319
    case OP_GET_PARAM:
33,106,228✔
1320
      ppParam = &pOperator->pOperatorGetParam;
33,106,228✔
1321
      pppDownstramParam = &pOperator->pDownstreamGetParams;
33,106,228✔
1322
      break;
33,106,228✔
1323
    case OP_NOTIFY_PARAM:
32,995,434✔
1324
      ppParam = &pOperator->pOperatorNotifyParam;
32,995,434✔
1325
      pppDownstramParam = &pOperator->pDownstreamNotifyParams;
32,995,434✔
1326
      break;
32,995,434✔
1327
    default:
×
1328
      return;
×
1329
  }
1330

1331
  if (*ppParam) {
66,101,662✔
1332
    freeOperatorParam(*ppParam, type);
11,859✔
1333
    *ppParam = NULL;
11,859✔
1334
  }
1335

1336
  if (*pppDownstramParam) {
66,101,662✔
1337
    for (int32_t i = 0; i < pOperator->numOfDownstream; ++i) {
133,352✔
1338
      if ((*pppDownstramParam)[i]) {
22,717!
1339
        freeOperatorParam((*pppDownstramParam)[i], type);
×
1340
        (*pppDownstramParam)[i] = NULL;
×
1341
      }
1342
    }
1343
    if (allFree) {
110,635✔
1344
      taosMemoryFreeClear(*pppDownstramParam);
10,136!
1345
    }
1346
  }
1347
}
1348

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

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

1363
    if (code) {
22,465!
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,465✔
1367
  }
1368

1369
  code = pOperator->pDownstream[idx]->fpSet.getNextFn(pOperator->pDownstream[idx], pResBlock);
56,579,062✔
1370
  if (code) {
56,568,642!
1371
    qError("failed to get next data block from upstream at %s, %d code:%s", __func__, __LINE__, tstrerror(code));
×
1372
  }
1373
  return code;
56,569,782✔
1374
}
1375

1376
bool compareVal(const char* v, const SStateKeys* pKey) {
44,968,723✔
1377
  if (IS_VAR_DATA_TYPE(pKey->type)) {
44,968,723!
1378
    if (IS_STR_DATA_BLOB(pKey->type)) {
×
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)) {
452!
1386
        return false;
×
1387
      } else {
1388
        return memcmp(varDataVal(v), varDataVal(pKey->pData), varDataLen(v)) == 0;
452✔
1389
      }
1390
    }
1391
  } else {
1392
    return memcmp(pKey->pData, v, pKey->bytes) == 0;
44,968,741✔
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