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

taosdata / TDengine / #3843

08 Apr 2025 10:23AM UTC coverage: 63.077% (+0.4%) from 62.696%
#3843

push

travis-ci

web-flow
fix: clear cache when meta abort (#30674)

155571 of 315083 branches covered (49.37%)

Branch coverage included in aggregate %.

241876 of 315013 relevant lines covered (76.78%)

19243431.01 hits per line

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

65.87
/source/libs/executor/src/executorInt.c
1
/*
2
 * Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
3
 *
4
 * This program is free software: you can use, redistribute, and/or modify
5
 * it under the terms of the GNU Affero General Public License, version 3
6
 * or later ("AGPL"), as published by the Free Software Foundation.
7
 *
8
 * This program is distributed in the hope that it will be useful, but WITHOUT
9
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10
 * FITNESS FOR A PARTICULAR PURPOSE.
11
 *
12
 * You should have received a copy of the GNU Affero General Public License
13
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
14
 */
15

16
#include "filter.h"
17
#include "function.h"
18
#include "functionMgt.h"
19
#include "os.h"
20
#include "querynodes.h"
21
#include "tfill.h"
22
#include "tname.h"
23

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

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

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

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

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

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

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

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

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

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

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

86
SResultRow* getNewResultRow(SDiskbasedBuf* pResultBuf, int32_t* currentPageId, int32_t interBufSize) {
223,494,609✔
87
  SFilePage* pData = NULL;
223,494,609✔
88

89
  // in the first scan, new space needed for results
90
  int32_t pageId = -1;
223,494,609✔
91
  if (*currentPageId == -1) {
223,494,609✔
92
    pData = getNewBufPage(pResultBuf, &pageId);
5,406,585✔
93
    if (pData == NULL) {
5,406,753✔
94
      qError("failed to get buffer, code:%s", tstrerror(terrno));
190!
95
      return NULL;
×
96
    }
97
    pData->num = sizeof(SFilePage);
5,406,563✔
98
  } else {
99
    pData = getBufPage(pResultBuf, *currentPageId);
218,088,024✔
100
    if (pData == NULL) {
217,987,519!
101
      qError("failed to get buffer, code:%s", tstrerror(terrno));
×
102
      return NULL;
×
103
    }
104

105
    pageId = *currentPageId;
217,987,519✔
106

107
    if (pData->num + interBufSize > getBufPageSize(pResultBuf)) {
217,987,519✔
108
      // release current page first, and prepare the next one
109
      releaseBufPage(pResultBuf, pData);
15,767,689✔
110

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

120
  if (pData == NULL) {
223,672,420!
121
    return NULL;
×
122
  }
123

124
  setBufPageDirty(pData, true);
223,672,420✔
125

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

129
  memset((char*)pResultRow, 0, interBufSize);
223,491,713✔
130
  pResultRow->pageId = pageId;
223,491,713✔
131
  pResultRow->offset = (int32_t)pData->num;
223,491,713✔
132

133
  *currentPageId = pageId;
223,491,713✔
134
  pData->num += interBufSize;
223,491,713✔
135
  return pResultRow;
223,491,713✔
136
}
137

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

153
  SResultRowPosition* p1 =
154
      (SResultRowPosition*)tSimpleHashGet(pSup->pResultRowHashTable, pSup->keyBuf, GET_RES_WINDOW_KEY_LEN(bytes));
273,999,987✔
155

156
  SResultRow* pResult = NULL;
273,722,018✔
157

158
  // in case of repeat scan/reverse scan, no new time window added.
159
  if (isIntervalQuery) {
273,722,018✔
160
    if (p1 != NULL) {  // the *p1 may be NULL in case of sliding+offset exists.
245,532,780✔
161
      pResult = getResultRowByPos(pResultBuf, p1, true);
42,116,507✔
162
      if (pResult == NULL) {
42,116,507!
163
        pTaskInfo->code = terrno;
×
164
        return NULL;
×
165
      }
166

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

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

192
  // 1. close current opened time window
193
  if (pResultRowInfo->cur.pageId != -1 && ((pResult == NULL) || (pResult->pageId != pResultRowInfo->cur.pageId))) {
273,364,839✔
194
    SResultRowPosition pos = pResultRowInfo->cur;
223,687,162✔
195
    SFilePage*         pPage = getBufPage(pResultBuf, pos.pageId);
223,687,162✔
196
    if (pPage == NULL) {
222,648,583!
197
      qError("failed to get buffer, code:%s, %s", tstrerror(terrno), GET_TASKID(pTaskInfo));
×
198
      pTaskInfo->code = terrno;
×
199
      return NULL;
×
200
    }
201
    releaseBufPage(pResultBuf, pPage);
222,648,583✔
202
  }
203

204
  // allocate a new buffer page
205
  if (pResult == NULL) {
271,790,508✔
206
    pResult = getNewResultRow(pResultBuf, &pSup->currentPageId, pSup->resultRowSize);
223,060,833✔
207
    if (pResult == NULL) {
223,914,472!
208
      pTaskInfo->code = terrno;
×
209
      return NULL;
×
210
    }
211

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

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

226
  // too many time window in query
227
  if (pTaskInfo->execModel == OPTR_EXEC_MODEL_BATCH &&
548,498,399!
228
      tSimpleHashGetSize(pSup->pResultRowHashTable) > MAX_INTERVAL_TIME_WINDOW) {
274,542,609✔
229
    pTaskInfo->code = TSDB_CODE_QRY_TOO_MANY_TIMEWINDOW;
×
230
    return NULL;
×
231
  }
232

233
  return pResult;
273,955,790✔
234
}
235

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

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

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

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

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

275
int32_t setInputDataBlock(SExprSupp* pExprSup, SSDataBlock* pBlock, int32_t order, int32_t scanFlag,
32,469,931✔
276
                          bool createDummyCol) {
277
  if (pBlock->pBlockAgg != NULL) {
32,469,931✔
278
    return doSetInputDataBlockInfo(pExprSup, pBlock, order, scanFlag);
2,656,117✔
279
  } else {
280
    return doSetInputDataBlock(pExprSup, pBlock, order, scanFlag, createDummyCol);
29,813,814✔
281
  }
282
}
283

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

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

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

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

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

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

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

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

341
  for (int32_t i = 0; i < pExprSup->numOfExprs; ++i) {
100,086,607✔
342
    pCtx[i].order = order;
70,277,496✔
343
    pCtx[i].input.numOfRows = pBlock->info.rows;
70,277,496✔
344

345
    pCtx[i].pSrcBlock = pBlock;
70,277,496✔
346
    pCtx[i].scanFlag = scanFlag;
70,277,496✔
347

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

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

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

359
    for (int32_t j = 0; j < pOneExpr->base.numOfParams; ++j) {
147,494,246✔
360
      SFunctParam* pFuncParam = &pOneExpr->base.pParam[j];
77,221,283✔
361
      if (pFuncParam->type == FUNC_PARAM_TYPE_COLUMN) {
77,221,283✔
362
        int32_t slotId = pFuncParam->pCol->slotId;
67,064,456✔
363
        pInput->pData[j] = taosArrayGet(pBlock->pDataBlock, slotId);
67,064,456✔
364
        pInput->totalRows = pBlock->info.rows;
67,060,136✔
365
        pInput->numOfRows = pBlock->info.rows;
67,060,136✔
366
        pInput->startRowIndex = 0;
67,060,136✔
367
        pInput->blankFill = pBlock->info.blankFill;
67,060,136✔
368

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

372
        if (fmIsImplicitTsFunc(pCtx[i].functionId) && (j == tsParamIdx)) {
67,060,136✔
373
          pInput->pPTS = pInput->pData[j];  // in case of merge function, this is not always the ts column data.
10,651,140✔
374
        }
375
        if (hasPk && (j == pkParamIdx)) {
67,059,923✔
376
          pInput->pPrimaryKey = pInput->pData[j];
30,343✔
377
        }
378
        QUERY_CHECK_CONDITION((pInput->pData[j] != NULL), code, lino, _end, TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR);
67,059,923!
379
      } else if (pFuncParam->type == FUNC_PARAM_TYPE_VALUE) {
10,156,827✔
380
        // todo avoid case: top(k, 12), 12 is the value parameter.
381
        // sum(11), 11 is also the value parameter.
382
        if (createDummyCol && pOneExpr->base.numOfParams == 1) {
8,940,570!
383
          pInput->totalRows = pBlock->info.rows;
×
384
          pInput->numOfRows = pBlock->info.rows;
×
385
          pInput->startRowIndex = 0;
×
386
          pInput->blankFill = pBlock->info.blankFill;
×
387

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

395
_end:
29,809,111✔
396
  if (code != TSDB_CODE_SUCCESS) {
29,809,111!
397
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
×
398
  }
399
  return code;
29,815,272✔
400
}
401

402
bool functionNeedToExecute(SqlFunctionCtx* pCtx) {
895,771,538✔
403
  struct SResultRowEntryInfo* pResInfo = GET_RES_INFO(pCtx);
895,771,538✔
404

405
  // in case of timestamp column, always generated results.
406
  int32_t functionId = pCtx->functionId;
895,771,538✔
407
  if (functionId == -1) {
895,771,538✔
408
    return false;
41,508,682✔
409
  }
410

411
  if (pCtx->scanFlag == PRE_SCAN) {
854,262,856✔
412
    return fmIsRepeatScanFunc(pCtx->functionId);
1,695,599✔
413
  }
414

415
  if (isRowEntryCompleted(pResInfo)) {
852,567,257✔
416
    return false;
76✔
417
  }
418

419
  return true;
852,567,181✔
420
}
421

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

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

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

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

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

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

469
  return TSDB_CODE_SUCCESS;
2,160,756✔
470
}
471

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

477
  SInputColumnInfoData* pInput = &pCtx->input;
2,656,121✔
478
  pInput->numOfRows = numOfRows;
2,656,121✔
479
  pInput->totalRows = numOfRows;
2,656,121✔
480

481
  if (pBlock->pBlockAgg != NULL) {
2,656,121✔
482
    pInput->colDataSMAIsSet = true;
2,656,120✔
483

484
    for (int32_t j = 0; j < pExprInfo->base.numOfParams; ++j) {
7,472,996✔
485
      SFunctParam* pFuncParam = &pExprInfo->base.pParam[j];
4,816,876✔
486

487
      if (pFuncParam->type == FUNC_PARAM_TYPE_COLUMN) {
4,816,876✔
488
        int32_t slotId = pFuncParam->pCol->slotId;
2,656,120✔
489
        pInput->pColumnDataAgg[j] = &pBlock->pBlockAgg[slotId];
2,656,120✔
490
        if (pInput->pColumnDataAgg[j]->colId == -1) {
2,656,120✔
491
          pInput->colDataSMAIsSet = false;
3,902✔
492
        }
493

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

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

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

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

527
  return win;
33,208,139✔
528
}
529

530
int32_t setResultRowInitCtx(SResultRow* pResult, SqlFunctionCtx* pCtx, int32_t numOfOutput,
418,362,304✔
531
                            int32_t* rowEntryInfoOffset) {
532
  bool init = false;
418,362,304✔
533
  for (int32_t i = 0; i < numOfOutput; ++i) {
1,584,395,505✔
534
    pCtx[i].resultInfo = getResultEntryInfo(pResult, i, rowEntryInfoOffset);
1,167,296,077✔
535
    if (init) {
1,167,584,575✔
536
      continue;
112,459,296✔
537
    }
538

539
    struct SResultRowEntryInfo* pResInfo = pCtx[i].resultInfo;
1,055,125,279✔
540
    if (isRowEntryCompleted(pResInfo) && isRowEntryInitialized(pResInfo)) {
1,055,125,279!
541
      continue;
×
542
    }
543

544
    if (pCtx[i].isPseudoFunc) {
1,055,125,279✔
545
      continue;
273,604,554✔
546
    }
547

548
    if (!pResInfo->initialized) {
781,520,725✔
549
      if (pCtx[i].functionId != -1) {
739,055,983✔
550
        int32_t code = pCtx[i].fpSet.init(&pCtx[i], pResInfo);
709,666,814✔
551
        if (code != TSDB_CODE_SUCCESS && fmIsUserDefinedFunc(pCtx[i].functionId)) {
709,918,728!
552
          pResInfo->initialized = false;
1,803,288✔
553
          qError("failed to initialize udf, funcId:%d error:%s", pCtx[i].functionId, tstrerror(code));
1,803,288!
554
          return TSDB_CODE_UDF_FUNC_EXEC_FAILURE;
×
555
        } else if (code != TSDB_CODE_SUCCESS) {
708,115,440!
556
          qError("failed to initialize function context, funcId:%d error:%s", pCtx[i].functionId, tstrerror(code));
×
557
          return code;
×
558
        }
559
      } else {
560
        pResInfo->initialized = true;
29,389,169✔
561
      }
562
    } else {
563
      init = true;
42,464,742✔
564
    }
565
  }
566
  return TSDB_CODE_SUCCESS;
417,099,428✔
567
}
568

569
void clearResultRowInitFlag(SqlFunctionCtx* pCtx, int32_t numOfOutput) {
69,530,021✔
570
  for (int32_t i = 0; i < numOfOutput; ++i) {
170,983,015✔
571
    SResultRowEntryInfo* pResInfo = pCtx[i].resultInfo;
101,452,994✔
572
    if (pResInfo == NULL) {
101,452,994!
573
      continue;
×
574
    }
575

576
    pResInfo->initialized = false;
101,452,994✔
577
    pResInfo->numOfRes = 0;
101,452,994✔
578
    pResInfo->isNullRes = 0;
101,452,994✔
579
    pResInfo->complete = false;
101,452,994✔
580
  }
581
}
69,530,021✔
582

583
int32_t doFilter(SSDataBlock* pBlock, SFilterInfo* pFilterInfo, SColMatchInfo* pColMatchInfo) {
43,413,031✔
584
  int32_t code = TSDB_CODE_SUCCESS;
43,413,031✔
585
  int32_t lino = 0;
43,413,031✔
586
  if (pFilterInfo == NULL || pBlock->info.rows == 0) {
43,413,031✔
587
    return TSDB_CODE_SUCCESS;
38,068,084✔
588
  }
589

590
  SFilterColumnParam param1 = {.numOfCols = taosArrayGetSize(pBlock->pDataBlock), .pDataBlock = pBlock->pDataBlock};
5,344,947✔
591
  SColumnInfoData*   p = NULL;
5,344,892✔
592

593
  code = filterSetDataFromSlotId(pFilterInfo, &param1);
5,344,892✔
594
  QUERY_CHECK_CODE(code, lino, _err);
5,344,804!
595

596
  int32_t status = 0;
5,344,804✔
597
  code = filterExecute(pFilterInfo, pBlock, &p, NULL, param1.numOfCols, &status);
5,344,804✔
598
  QUERY_CHECK_CODE(code, lino, _err);
5,344,822✔
599

600
  code = extractQualifiedTupleByFilterResult(pBlock, p, status);
5,344,821✔
601
  QUERY_CHECK_CODE(code, lino, _err);
5,344,837!
602

603
  if (pColMatchInfo != NULL) {
5,344,837✔
604
    size_t size = taosArrayGetSize(pColMatchInfo->pList);
4,059,615✔
605
    for (int32_t i = 0; i < size; ++i) {
4,063,764✔
606
      SColMatchItem* pInfo = taosArrayGet(pColMatchInfo->pList, i);
4,062,395✔
607
      QUERY_CHECK_NULL(pInfo, code, lino, _err, terrno);
4,062,343!
608
      if (pInfo->colId == PRIMARYKEY_TIMESTAMP_COL_ID) {
4,062,343✔
609
        SColumnInfoData* pColData = taosArrayGet(pBlock->pDataBlock, pInfo->dstSlotId);
4,058,200✔
610
        QUERY_CHECK_NULL(pColData, code, lino, _err, terrno);
4,058,125!
611
        if (pColData->info.type == TSDB_DATA_TYPE_TIMESTAMP) {
4,058,159✔
612
          code = blockDataUpdateTsWindow(pBlock, pInfo->dstSlotId);
4,058,136✔
613
          QUERY_CHECK_CODE(code, lino, _err);
4,058,152!
614
          break;
4,058,152✔
615
        }
616
      }
617
    }
618
  }
619
  code = blockDataCheck(pBlock);
5,344,743✔
620
  QUERY_CHECK_CODE(code, lino, _err);
5,344,645!
621
_err:
5,344,645✔
622
  if (code != TSDB_CODE_SUCCESS) {
5,344,646✔
623
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
1!
624
  }
625
  colDataDestroy(p);
5,344,646✔
626
  taosMemoryFree(p);
5,345,098!
627
  return code;
5,345,089✔
628
}
629

630
int32_t extractQualifiedTupleByFilterResult(SSDataBlock* pBlock, const SColumnInfoData* p, int32_t status) {
5,344,881✔
631
  int32_t code = TSDB_CODE_SUCCESS;
5,344,881✔
632
  int8_t* pIndicator = (int8_t*)p->pData;
5,344,881✔
633
  if (status == FILTER_RESULT_ALL_QUALIFIED) {
5,344,881✔
634
    // here nothing needs to be done
635
  } else if (status == FILTER_RESULT_NONE_QUALIFIED) {
1,444,914✔
636
    code = trimDataBlock(pBlock, pBlock->info.rows, NULL);
755,272✔
637
    pBlock->info.rows = 0;
755,231✔
638
  } else if (status == FILTER_RESULT_PARTIAL_QUALIFIED) {
689,642!
639
    code = trimDataBlock(pBlock, pBlock->info.rows, (bool*)pIndicator);
689,662✔
640
  } else {
641
    qError("unknown filter result type: %d", status);
×
642
  }
643
  return code;
5,345,037✔
644
}
645

646
void doUpdateNumOfRows(SqlFunctionCtx* pCtx, SResultRow* pRow, int32_t numOfExprs, const int32_t* rowEntryOffset) {
371,685,668✔
647
  bool returnNotNull = false;
371,685,668✔
648
  for (int32_t j = 0; j < numOfExprs; ++j) {
1,336,870,500✔
649
    SResultRowEntryInfo* pResInfo = getResultEntryInfo(pRow, j, rowEntryOffset);
964,886,381✔
650
    if (!isRowEntryInitialized(pResInfo)) {
965,184,832✔
651
      continue;
223,351,502✔
652
    } else {
653
    }
654

655
    if (pRow->numOfRows < pResInfo->numOfRes) {
741,833,330✔
656
      pRow->numOfRows = pResInfo->numOfRes;
364,687,559✔
657
    }
658

659
    if (pCtx[j].isNotNullFunc) {
741,833,330✔
660
      returnNotNull = true;
222,765,237✔
661
    }
662
  }
663
  // if all expr skips all blocks, e.g. all null inputs for max function, output one row in final result.
664
  //  except for first/last, which require not null output, output no rows
665
  if (pRow->numOfRows == 0 && !returnNotNull) {
371,984,119✔
666
    pRow->numOfRows = 1;
30,318✔
667
  }
668
}
371,984,119✔
669

670
int32_t copyResultrowToDataBlock(SExprInfo* pExprInfo, int32_t numOfExprs, SResultRow* pRow, SqlFunctionCtx* pCtx,
357,342,105✔
671
                                 SSDataBlock* pBlock, const int32_t* rowEntryOffset, SExecTaskInfo* pTaskInfo) {
672
  int32_t code = TSDB_CODE_SUCCESS;
357,342,105✔
673
  int32_t lino = 0;
357,342,105✔
674
  for (int32_t j = 0; j < numOfExprs; ++j) {
1,251,005,836✔
675
    int32_t slotId = pExprInfo[j].base.resSchema.slotId;
893,849,342✔
676

677
    pCtx[j].resultInfo = getResultEntryInfo(pRow, j, rowEntryOffset);
893,849,342✔
678
    if (pCtx[j].fpSet.finalize) {
893,885,114✔
679
      if (strcmp(pCtx[j].pExpr->pExpr->_function.functionName, "_group_key") == 0 ||
550,550,195✔
680
          strcmp(pCtx[j].pExpr->pExpr->_function.functionName, "_group_const_value") == 0) {
457,648,336✔
681
        // for groupkey along with functions that output multiple lines(e.g. Histogram)
682
        // need to match groupkey result for each output row of that function.
683
        if (pCtx[j].resultInfo->numOfRes != 0) {
92,902,880!
684
          pCtx[j].resultInfo->numOfRes = pRow->numOfRows;
94,248,532✔
685
        }
686
      }
687

688
      code = blockDataEnsureCapacity(pBlock, pBlock->info.rows + pCtx[j].resultInfo->numOfRes);
550,550,195✔
689
      QUERY_CHECK_CODE(code, lino, _end);
550,834,829!
690

691
      code = pCtx[j].fpSet.finalize(&pCtx[j], pBlock);
550,834,829✔
692
      if (TSDB_CODE_SUCCESS != code) {
552,661,094!
693
        qError("%s build result data block error, code %s", GET_TASKID(pTaskInfo), tstrerror(code));
×
694
        QUERY_CHECK_CODE(code, lino, _end);
×
695
      }
696
    } else if (strcmp(pCtx[j].pExpr->pExpr->_function.functionName, "_select_value") == 0) {
343,334,919✔
697
      // do nothing
698
    } else {
699
      // expand the result into multiple rows. E.g., _wstart, top(k, 20)
700
      // the _wstart needs to copy to 20 following rows, since the results of top-k expands to 20 different rows.
701
      SColumnInfoData* pColInfoData = taosArrayGet(pBlock->pDataBlock, slotId);
232,513,634✔
702
      QUERY_CHECK_NULL(pColInfoData, code, lino, _end, terrno);
231,077,595✔
703
      char*            in = GET_ROWCELL_INTERBUF(pCtx[j].resultInfo);
231,026,593✔
704
      for (int32_t k = 0; k < pRow->numOfRows; ++k) {
469,050,483✔
705
        code = colDataSetValOrCover(pColInfoData, pBlock->info.rows + k, in, pCtx[j].resultInfo->isNullRes);
237,285,260✔
706
        QUERY_CHECK_CODE(code, lino, _end);
238,023,890!
707
      }
708
    }
709
  }
710

711
_end:
357,156,494✔
712
  if (code != TSDB_CODE_SUCCESS) {
357,156,494!
713
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
×
714
  }
715
  return code;
358,630,714✔
716
}
717

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

727
  SResultRow* pRow = (SResultRow*)((char*)page + resultRowPosition->offset);
67,365,023✔
728

729
  SqlFunctionCtx* pCtx = pSup->pCtx;
67,365,023✔
730
  SExprInfo*      pExprInfo = pSup->pExprInfo;
67,365,023✔
731
  const int32_t*  rowEntryOffset = pSup->rowEntryInfoOffset;
67,365,023✔
732

733
  doUpdateNumOfRows(pCtx, pRow, pSup->numOfExprs, rowEntryOffset);
67,365,023✔
734
  if (pRow->numOfRows == 0) {
67,349,747!
735
    releaseBufPage(pBuf, page);
×
736
    return;
×
737
  }
738

739
  int32_t size = pBlock->info.capacity;
67,350,352✔
740
  while (pBlock->info.rows + pRow->numOfRows > size) {
67,438,200✔
741
    size = size * 1.25;
87,848✔
742
  }
743

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

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

758
  releaseBufPage(pBuf, page);
67,322,158✔
759
  pBlock->info.rows += pRow->numOfRows;
67,329,658✔
760
}
761

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

771
  size_t  keyLen = 0;
5,650,291✔
772
  int32_t numOfRows = tSimpleHashGetSize(pHashmap);
5,650,291✔
773

774
  // begin from last iter
775
  void*   pData = pGroupResInfo->dataPos;
5,643,116✔
776
  int32_t iter = pGroupResInfo->iter;
5,643,116✔
777
  while ((pData = tSimpleHashIterate(pHashmap, pData, &iter)) != NULL) {
22,379,914✔
778
    void*               key = tSimpleHashGetKey(pData, &keyLen);
22,048,538✔
779
    SResultRowPosition* pos = pData;
22,048,538✔
780
    uint64_t            groupId = *(uint64_t*)key;
22,048,538✔
781

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

788
    SResultRow* pRow = (SResultRow*)((char*)page + pos->offset);
22,040,241✔
789

790
    doUpdateNumOfRows(pCtx, pRow, numOfExprs, rowEntryOffset);
22,040,241✔
791

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

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

802
    if (!ignoreGroup) {
21,982,629✔
803
      if (pBlock->info.id.groupId == 0) {
10,605,105✔
804
        pBlock->info.id.groupId = groupId;
5,342,024✔
805
      } else {
806
        // current value belongs to different group, it can't be packed into one datablock
807
        if (pBlock->info.id.groupId != groupId) {
5,263,081!
808
          releaseBufPage(pBuf, page);
5,285,862✔
809
          break;
5,286,965✔
810
        }
811
      }
812
    }
813

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

823
    pGroupResInfo->index += 1;
16,696,767✔
824
    pGroupResInfo->iter = iter;
16,696,767✔
825
    pGroupResInfo->dataPos = pData;
16,696,767✔
826

827
    code = copyResultrowToDataBlock(pExprInfo, numOfExprs, pRow, pCtx, pBlock, rowEntryOffset, pTaskInfo);
16,696,767✔
828
    releaseBufPage(pBuf, page);
16,740,698✔
829
    QUERY_CHECK_CODE(code, lino, _end);
16,736,918!
830
    pBlock->info.rows += pRow->numOfRows;
16,736,918✔
831
    if (pBlock->info.rows >= threshold) {
16,736,918✔
832
      break;
120✔
833
    }
834
  }
835

836
  qDebug("%s result generated, rows:%" PRId64 ", groupId:%" PRIu64, GET_TASKID(pTaskInfo), pBlock->info.rows,
5,607,873✔
837
         pBlock->info.id.groupId);
838
  pBlock->info.dataLoad = 1;
5,607,875✔
839
  code = blockDataUpdateTsWindow(pBlock, 0);
5,607,875✔
840
  QUERY_CHECK_CODE(code, lino, _end);
5,608,195!
841

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

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

858
  int32_t numOfRows = getNumOfTotalRes(pGroupResInfo);
3,400,713✔
859

860
  for (int32_t i = pGroupResInfo->index; i < numOfRows; i += 1) {
208,003,351✔
861
    SResKeyPos* pPos = taosArrayGetP(pGroupResInfo->pRows, i);
205,184,355✔
862
    SFilePage*  page = getBufPage(pBuf, pPos->pos.pageId);
204,587,307✔
863
    if (page == NULL) {
204,483,464!
864
      qError("failed to get buffer, code:%s, %s", tstrerror(terrno), GET_TASKID(pTaskInfo));
×
865
      T_LONG_JMP(pTaskInfo->env, terrno);
×
866
    }
867

868
    SResultRow* pRow = (SResultRow*)((char*)page + pPos->pos.offset);
204,483,464✔
869

870
    doUpdateNumOfRows(pCtx, pRow, numOfExprs, rowEntryOffset);
204,483,464✔
871

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

887
    if (!ignoreGroup) {
203,245,209✔
888
      if (pBlock->info.id.groupId == 0) {
131,636,067✔
889
        pBlock->info.id.groupId = pPos->groupId;
115,850,605✔
890
      } else {
891
        // current value belongs to different group, it can't be packed into one datablock
892
        if (pBlock->info.id.groupId != pPos->groupId) {
15,785,462✔
893
          releaseBufPage(pBuf, page);
133,925✔
894
          break;
133,925✔
895
        }
896
      }
897
    }
898

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

908
    pGroupResInfo->index += 1;
203,111,284✔
909
    code = copyResultrowToDataBlock(pExprInfo, numOfExprs, pRow, pCtx, pBlock, rowEntryOffset, pTaskInfo);
203,111,284✔
910
    releaseBufPage(pBuf, page);
205,720,188✔
911
    QUERY_CHECK_CODE(code, lino, _end);
205,028,428!
912

913
    pBlock->info.rows += pRow->numOfRows;
205,028,428✔
914
    if (pBlock->info.rows >= threshold) {
205,028,428✔
915
      break;
427,090✔
916
    }
917
  }
918

919
  qDebug("%s result generated, rows:%" PRId64 ", groupId:%" PRIu64, GET_TASKID(pTaskInfo), pBlock->info.rows,
3,380,011✔
920
         pBlock->info.id.groupId);
921
  pBlock->info.dataLoad = 1;
3,380,016✔
922
  code = blockDataUpdateTsWindow(pBlock, 0);
3,380,016✔
923
  QUERY_CHECK_CODE(code, lino, _end);
3,400,605!
924

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

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

937
  // set output datablock version
938
  pBlock->info.version = pTaskInfo->version;
4,362,908✔
939

940
  blockDataCleanup(pBlock);
4,362,908✔
941
  if (!hasRemainResults(pGroupResInfo)) {
4,363,819✔
942
    return;
961,579✔
943
  }
944

945
  // clear the existed group id
946
  pBlock->info.id.groupId = 0;
3,401,785✔
947
  if (!pbInfo->mergeResultBlock) {
3,401,785✔
948
    doCopyToSDataBlock(pTaskInfo, pBlock, &pOperator->exprSupp, pBuf, pGroupResInfo, pOperator->resultInfo.threshold,
2,104,778✔
949
                       false, getMinWindowSize(pOperator));
950
  } else {
951
    while (hasRemainResults(pGroupResInfo)) {
2,373,172✔
952
      doCopyToSDataBlock(pTaskInfo, pBlock, &pOperator->exprSupp, pBuf, pGroupResInfo, pOperator->resultInfo.threshold,
1,296,783✔
953
                         true, getMinWindowSize(pOperator));
954
      if (pBlock->info.rows >= pOperator->resultInfo.threshold) {
1,296,777✔
955
        break;
220,612✔
956
      }
957

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

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

967
void destroyExprInfo(SExprInfo* pExpr, int32_t numOfExprs) {
10,370,625✔
968
  for (int32_t i = 0; i < numOfExprs; ++i) {
40,241,059✔
969
    SExprInfo* pExprInfo = &pExpr[i];
29,868,923✔
970
    for (int32_t j = 0; j < pExprInfo->base.numOfParams; ++j) {
61,286,766✔
971
      if (pExprInfo->base.pParam[j].type == FUNC_PARAM_TYPE_COLUMN) {
31,416,961✔
972
        taosMemoryFreeClear(pExprInfo->base.pParam[j].pCol);
28,510,041!
973
      } else if (pExprInfo->base.pParam[j].type == FUNC_PARAM_TYPE_VALUE) {
2,906,920✔
974
        taosVariantDestroy(&pExprInfo->base.pParam[j].param);
2,250,532✔
975
      }
976
    }
977

978
    taosMemoryFree(pExprInfo->base.pParam);
29,869,805!
979
    taosMemoryFree(pExprInfo->pExpr);
29,870,099!
980
  }
981
}
10,372,136✔
982

983
int32_t getBufferPgSize(int32_t rowSize, uint32_t* defaultPgsz, int64_t* defaultBufsz) {
6,927,964✔
984
  *defaultPgsz = 4096;
6,927,964✔
985
  uint32_t last = *defaultPgsz;
6,927,964✔
986
  while (*defaultPgsz < rowSize * 4) {
8,303,712✔
987
    *defaultPgsz <<= 1u;
1,375,748✔
988
    if (*defaultPgsz < last) {
1,375,748!
989
      return TSDB_CODE_INVALID_PARA;
×
990
    }
991
    last = *defaultPgsz;
1,375,748✔
992
  }
993

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

1005
  return 0;
6,927,964✔
1006
}
1007

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

1013
  pResultInfo->capacity = numOfRows;
15,973,059✔
1014
  pResultInfo->threshold = numOfRows * 0.75;
15,973,059✔
1015

1016
  if (pResultInfo->threshold == 0) {
15,973,059✔
1017
    pResultInfo->threshold = numOfRows;
5,419✔
1018
  }
1019
}
15,973,059✔
1020

1021
void initBasicInfo(SOptrBasicInfo* pInfo, SSDataBlock* pBlock) {
6,905,648✔
1022
  pInfo->pRes = pBlock;
6,905,648✔
1023
  initResultRowInfo(&pInfo->resultRowInfo);
6,905,648✔
1024
}
6,905,404✔
1025

1026
static void destroySqlFunctionCtx(SqlFunctionCtx* pCtx, SExprInfo* pExpr, int32_t numOfOutput) {
30,967,949✔
1027
  if (pCtx == NULL) {
30,967,949✔
1028
    return;
19,742,785✔
1029
  }
1030

1031
  for (int32_t i = 0; i < numOfOutput; ++i) {
40,804,981✔
1032
    if (pExpr != NULL) {
29,576,179!
1033
      SExprInfo* pExprInfo = &pExpr[i];
29,577,727✔
1034
      for (int32_t j = 0; j < pExprInfo->base.numOfParams; ++j) {
60,701,855✔
1035
        if (pExprInfo->base.pParam[j].type == FUNC_PARAM_TYPE_VALUE) {
31,124,528✔
1036
          taosMemoryFree(pCtx[i].input.pData[j]);
2,246,490!
1037
          taosMemoryFree(pCtx[i].input.pColumnDataAgg[j]);
2,246,500✔
1038
        }
1039
      }
1040
    }
1041
    for (int32_t j = 0; j < pCtx[i].numOfParams; ++j) {
60,699,369✔
1042
      taosVariantDestroy(&pCtx[i].param[j].param);
31,124,117✔
1043
    }
1044

1045
    taosMemoryFreeClear(pCtx[i].subsidiaries.pCtx);
29,575,252!
1046
    taosMemoryFreeClear(pCtx[i].subsidiaries.buf);
29,575,301!
1047
    taosMemoryFree(pCtx[i].input.pData);
29,575,301!
1048
    taosMemoryFree(pCtx[i].input.pColumnDataAgg);
29,579,564!
1049

1050
    if (pCtx[i].udfName != NULL) {
29,580,226✔
1051
      taosMemoryFree(pCtx[i].udfName);
8!
1052
    }
1053
  }
1054

1055
  taosMemoryFreeClear(pCtx);
11,228,802!
1056
  return;
11,228,990✔
1057
}
1058

1059
int32_t initExprSupp(SExprSupp* pSup, SExprInfo* pExprInfo, int32_t numOfExpr, SFunctionStateStore* pStore) {
11,003,021✔
1060
  pSup->pExprInfo = pExprInfo;
11,003,021✔
1061
  pSup->numOfExprs = numOfExpr;
11,003,021✔
1062
  if (pSup->pExprInfo != NULL) {
11,003,021✔
1063
    pSup->pCtx = createSqlFunctionCtx(pExprInfo, numOfExpr, &pSup->rowEntryInfoOffset, pStore);
8,466,280✔
1064
    if (pSup->pCtx == NULL) {
8,460,812!
1065
      return terrno;
×
1066
    }
1067
  }
1068

1069
  return TSDB_CODE_SUCCESS;
11,000,603✔
1070
}
1071

1072
void cleanupExprSupp(SExprSupp* pSupp) {
30,968,270✔
1073
  destroySqlFunctionCtx(pSupp->pCtx, pSupp->pExprInfo, pSupp->numOfExprs);
30,968,270✔
1074
  if (pSupp->pExprInfo != NULL) {
30,967,832✔
1075
    destroyExprInfo(pSupp->pExprInfo, pSupp->numOfExprs);
10,366,055✔
1076
    taosMemoryFreeClear(pSupp->pExprInfo);
10,365,931!
1077
  }
1078

1079
  if (pSupp->pFilterInfo != NULL) {
30,967,923✔
1080
    filterFreeInfo(pSupp->pFilterInfo);
2,892,340✔
1081
    pSupp->pFilterInfo = NULL;
2,892,391✔
1082
  }
1083

1084
  taosMemoryFree(pSupp->rowEntryInfoOffset);
30,967,974!
1085
}
30,966,354✔
1086

1087
void cleanupBasicInfo(SOptrBasicInfo* pInfo) {
6,937,899✔
1088
  blockDataDestroy(pInfo->pRes);
6,937,899✔
1089
  pInfo->pRes = NULL;
6,938,920✔
1090
}
6,938,920✔
1091

1092
bool groupbyTbname(SNodeList* pGroupList) {
4,691,090✔
1093
  bool bytbname = false;
4,691,090✔
1094
  SNode*pNode = NULL;
4,691,090✔
1095
  FOREACH(pNode, pGroupList) {
4,768,274✔
1096
    if (pNode->type == QUERY_NODE_FUNCTION) {
351,673✔
1097
      bytbname = (strcmp(((struct SFunctionNode*)pNode)->functionName, "tbname") == 0);
274,489✔
1098
      break;
274,489✔
1099
    }
1100
  }
1101
  return bytbname;
4,691,090✔
1102
}
1103

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

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

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

1129
      STableListInfo* pTableListInfo = taosArrayGetP(pInfoList, 0);
112,275✔
1130
      taosArrayDestroy(pInfoList);
112,273✔
1131

1132
      pDeleterParam->suid = tableListGetSuid(pTableListInfo);
112,276✔
1133

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

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

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

1164
      *pParam = pDeleterParam;
112,277✔
1165
      break;
112,277✔
1166
    }
1167
    default:
8,250,976✔
1168
      break;
8,250,976✔
1169
  }
1170

1171
  return TSDB_CODE_SUCCESS;
8,363,646✔
1172
}
1173

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

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

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

1195
  taosArrayDestroy(pParam->pChildren);
66,322✔
1196
  pParam->pChildren = NULL;
66,322✔
1197

1198
  taosMemoryFreeClear(pParam->value);
66,322!
1199

1200
  taosMemoryFree(pParam);
66,322!
1201
}
66,322✔
1202

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

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

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

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

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

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

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

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

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

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

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

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

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

1260
void freeOperatorParam(SOperatorParam* pParam, SOperatorParamType type) {
14,077,451✔
1261
  if (NULL == pParam || pParam->reUse) {
14,077,451!
1262
    return;
14,011,129✔
1263
  }
1264

1265
  switch (pParam->opType) {
66,322!
1266
    case QUERY_NODE_PHYSICAL_PLAN_EXCHANGE:
639✔
1267
      type == OP_GET_PARAM ? freeExchangeGetOperatorParam(pParam) : freeExchangeNotifyOperatorParam(pParam);
639!
1268
      break;
639✔
1269
    case QUERY_NODE_PHYSICAL_PLAN_GROUP_CACHE:
42,368✔
1270
      type == OP_GET_PARAM ? freeGroupCacheGetOperatorParam(pParam) : freeGroupCacheNotifyOperatorParam(pParam);
42,368!
1271
      break;
42,368✔
1272
    case QUERY_NODE_PHYSICAL_PLAN_MERGE_JOIN:
21,184✔
1273
      type == OP_GET_PARAM ? freeMergeJoinGetOperatorParam(pParam) : freeMergeJoinNotifyOperatorParam(pParam);
21,184!
1274
      break;
21,184✔
1275
    case QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN:
2,130✔
1276
      type == OP_GET_PARAM ? freeTableScanGetOperatorParam(pParam) : freeTableScanNotifyOperatorParam(pParam);
2,130!
1277
      break;
2,131✔
1278
    case QUERY_NODE_PHYSICAL_PLAN_VIRTUAL_TABLE_SCAN:
×
1279
      type == OP_GET_PARAM ? freeVirtualTableScanGetOperatorParam(pParam) : freeVTableScanNotifyOperatorParam(pParam);
×
1280
      break;
×
1281
    default:
1✔
1282
      qError("unsupported op %d param, type %d", pParam->opType, type);
1!
1283
      break;
×
1284
  }
1285
}
1286

1287
void freeResetOperatorParams(struct SOperatorInfo* pOperator, SOperatorParamType type, bool allFree) {
39,651,261✔
1288
  SOperatorParam**  ppParam = NULL;
39,651,261✔
1289
  SOperatorParam*** pppDownstramParam = NULL;
39,651,261✔
1290
  switch (type) {
39,651,261!
1291
    case OP_GET_PARAM:
19,838,486✔
1292
      ppParam = &pOperator->pOperatorGetParam;
19,838,486✔
1293
      pppDownstramParam = &pOperator->pDownstreamGetParams;
19,838,486✔
1294
      break;
19,838,486✔
1295
    case OP_NOTIFY_PARAM:
19,816,110✔
1296
      ppParam = &pOperator->pOperatorNotifyParam;
19,816,110✔
1297
      pppDownstramParam = &pOperator->pDownstreamNotifyParams;
19,816,110✔
1298
      break;
19,816,110✔
1299
    default:
×
1300
      return;
×
1301
  }
1302

1303
  if (*ppParam) {
39,654,596✔
1304
    freeOperatorParam(*ppParam, type);
21,184✔
1305
    *ppParam = NULL;
21,184✔
1306
  }
1307

1308
  if (*pppDownstramParam) {
39,654,596✔
1309
    for (int32_t i = 0; i < pOperator->numOfDownstream; ++i) {
65,276✔
1310
      if ((*pppDownstramParam)[i]) {
42,368!
1311
        freeOperatorParam((*pppDownstramParam)[i], type);
×
1312
        (*pppDownstramParam)[i] = NULL;
×
1313
      }
1314
    }
1315
    if (allFree) {
22,908✔
1316
      taosMemoryFreeClear(*pppDownstramParam);
2,008!
1317
    }
1318
  }
1319
}
1320

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

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

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

1341
  code = pOperator->pDownstream[idx]->fpSet.getNextFn(pOperator->pDownstream[idx], pResBlock);
39,893,147✔
1342
  if (code) {
39,898,768!
1343
    qError("failed to get next data block from upstream at %s, %d code:%s", __func__, __LINE__, tstrerror(code));
×
1344
  }
1345
  return code;
39,899,078✔
1346
}
1347

1348
bool compareVal(const char* v, const SStateKeys* pKey) {
19,029,697✔
1349
  if (IS_VAR_DATA_TYPE(pKey->type)) {
19,029,697!
1350
    if (varDataLen(v) != varDataLen(pKey->pData)) {
3,121!
1351
      return false;
×
1352
    } else {
1353
      return memcmp(varDataVal(v), varDataVal(pKey->pData), varDataLen(v)) == 0;
3,121✔
1354
    }
1355
  } else {
1356
    return memcmp(pKey->pData, v, pKey->bytes) == 0;
19,026,576✔
1357
  }
1358
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc