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

taosdata / TDengine / #3534

21 Nov 2024 07:36AM UTC coverage: 60.825% (+2.0%) from 58.848%
#3534

push

travis-ci

web-flow
Merge pull request #28810 from taosdata/ehn/add-sync-heartbeat-sent-time-to-log

ehn:add-sync-heartbeat-sent-time-to-log

120023 of 252376 branches covered (47.56%)

Branch coverage included in aggregate %.

43 of 47 new or added lines in 3 files covered. (91.49%)

2254 existing lines in 162 files now uncovered.

200876 of 275203 relevant lines covered (72.99%)

16110754.39 hits per line

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

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

85
SResultRow* getNewResultRow(SDiskbasedBuf* pResultBuf, int32_t* currentPageId, int32_t interBufSize) {
246,585,628✔
86
  SFilePage* pData = NULL;
246,585,628✔
87

88
  // in the first scan, new space needed for results
89
  int32_t pageId = -1;
246,585,628✔
90
  if (*currentPageId == -1) {
246,585,628✔
91
    pData = getNewBufPage(pResultBuf, &pageId);
3,950,443✔
92
    if (pData == NULL) {
3,950,452✔
93
      qError("failed to get buffer, code:%s", tstrerror(terrno));
80!
UNCOV
94
      return NULL;
×
95
    }
96
    pData->num = sizeof(SFilePage);
3,950,372✔
97
  } else {
98
    pData = getBufPage(pResultBuf, *currentPageId);
242,635,185✔
99
    if (pData == NULL) {
242,700,979!
100
      qError("failed to get buffer, code:%s", tstrerror(terrno));
×
101
      return NULL;
×
102
    }
103

104
    pageId = *currentPageId;
242,700,979✔
105

106
    if (pData->num + interBufSize > getBufPageSize(pResultBuf)) {
242,700,979✔
107
      // release current page first, and prepare the next one
108
      releaseBufPage(pResultBuf, pData);
17,808,118✔
109

110
      pData = getNewBufPage(pResultBuf, &pageId);
18,172,386✔
111
      if (pData == NULL) {
18,189,493!
UNCOV
112
        qError("failed to get buffer, code:%s", tstrerror(terrno));
×
UNCOV
113
        return NULL;
×
114
      }
115
      pData->num = sizeof(SFilePage);
18,189,493✔
116
    }
117
  }
118

119
  if (pData == NULL) {
246,900,380!
120
    return NULL;
×
121
  }
122

123
  setBufPageDirty(pData, true);
246,900,380✔
124

125
  // set the number of rows in current disk page
126
  SResultRow* pResultRow = (SResultRow*)((char*)pData + pData->num);
246,621,219✔
127

128
  memset((char*)pResultRow, 0, interBufSize);
246,621,219✔
129
  pResultRow->pageId = pageId;
246,621,219✔
130
  pResultRow->offset = (int32_t)pData->num;
246,621,219✔
131

132
  *currentPageId = pageId;
246,621,219✔
133
  pData->num += interBufSize;
246,621,219✔
134
  return pResultRow;
246,621,219✔
135
}
136

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

152
  SResultRowPosition* p1 =
153
      (SResultRowPosition*)tSimpleHashGet(pSup->pResultRowHashTable, pSup->keyBuf, GET_RES_WINDOW_KEY_LEN(bytes));
304,467,774✔
154

155
  SResultRow* pResult = NULL;
306,112,174✔
156

157
  // in case of repeat scan/reverse scan, no new time window added.
158
  if (isIntervalQuery) {
306,112,174✔
159
    if (p1 != NULL) {  // the *p1 may be NULL in case of sliding+offset exists.
286,394,683✔
160
      pResult = getResultRowByPos(pResultBuf, p1, true);
49,609,090✔
161
      if (pResult == NULL) {
49,609,090!
162
        pTaskInfo->code = terrno;
×
163
        return NULL;
×
164
      }
165

166
      if (pResult->pageId != p1->pageId || pResult->offset != p1->offset) {
49,609,090!
167
        terrno = TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR;
×
168
        pTaskInfo->code = terrno;
×
169
        return NULL;
×
170
      }
171
    }
172
  } else {
173
    // In case of group by column query, the required SResultRow object must be existInCurrentResusltRowInfo in the
174
    // pResultRowInfo object.
175
    if (p1 != NULL) {
19,717,491✔
176
      // todo
177
      pResult = getResultRowByPos(pResultBuf, p1, true);
6,969,019✔
178
      if (NULL == pResult) {
6,969,019!
179
        pTaskInfo->code = terrno;
×
180
        return NULL;
×
181
      }
182

183
      if (pResult->pageId != p1->pageId || pResult->offset != p1->offset) {
6,969,019!
184
        terrno = TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR;
×
185
        pTaskInfo->code = terrno;
×
186
        return NULL;
26,549✔
187
      }
188
    }
189
  }
190

191
  // 1. close current opened time window
192
  if (pResultRowInfo->cur.pageId != -1 && ((pResult == NULL) || (pResult->pageId != pResultRowInfo->cur.pageId))) {
305,527,825✔
193
    SResultRowPosition pos = pResultRowInfo->cur;
250,457,553✔
194
    SFilePage*         pPage = getBufPage(pResultBuf, pos.pageId);
250,457,553✔
195
    if (pPage == NULL) {
248,274,189!
196
      qError("failed to get buffer, code:%s, %s", tstrerror(terrno), GET_TASKID(pTaskInfo));
×
197
      pTaskInfo->code = terrno;
×
198
      return NULL;
×
199
    }
200
    releaseBufPage(pResultBuf, pPage);
248,274,189✔
201
  }
202

203
  // allocate a new buffer page
204
  if (pResult == NULL) {
302,448,242✔
205
    pResult = getNewResultRow(pResultBuf, &pSup->currentPageId, pSup->resultRowSize);
246,089,606✔
206
    if (pResult == NULL) {
246,887,524!
UNCOV
207
      pTaskInfo->code = terrno;
×
UNCOV
208
      return NULL;
×
209
    }
210

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

222
  // 2. set the new time window to be the new active time window
223
  pResultRowInfo->cur = (SResultRowPosition){.pageId = pResult->pageId, .offset = pResult->offset};
305,923,158✔
224

225
  // too many time window in query
226
  if (pTaskInfo->execModel == OPTR_EXEC_MODEL_BATCH &&
611,035,940!
227
      tSimpleHashGetSize(pSup->pResultRowHashTable) > MAX_INTERVAL_TIME_WINDOW) {
305,847,152✔
228
    pTaskInfo->code = TSDB_CODE_QRY_TOO_MANY_TIMEWINDOW;
×
229
    return NULL;
×
230
  }
231

232
  return pResult;
305,188,788✔
233
}
234

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

240
  int32_t code = colInfoDataEnsureCapacity(pColData, 5, false);
2,521,189✔
241
  if (code != TSDB_CODE_SUCCESS) {
2,525,750!
242
    return code;
×
243
  }
244
  colDataSetInt64(pColData, 0, &pQueryWindow->skey);
2,525,750✔
245
  colDataSetInt64(pColData, 1, &pQueryWindow->ekey);
2,525,750✔
246

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

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

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

274
int32_t setInputDataBlock(SExprSupp* pExprSup, SSDataBlock* pBlock, int32_t order, int32_t scanFlag,
14,553,606✔
275
                          bool createDummyCol) {
276
  if (pBlock->pBlockAgg != NULL) {
14,553,606✔
277
    return doSetInputDataBlockInfo(pExprSup, pBlock, order, scanFlag);
9,420✔
278
  } else {
279
    return doSetInputDataBlock(pExprSup, pBlock, order, scanFlag, createDummyCol);
14,544,186✔
280
  }
281
}
282

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

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

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

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

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

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

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

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

340
  for (int32_t i = 0; i < pExprSup->numOfExprs; ++i) {
71,045,687✔
341
    pCtx[i].order = order;
56,501,009✔
342
    pCtx[i].input.numOfRows = pBlock->info.rows;
56,501,009✔
343

344
    pCtx[i].pSrcBlock = pBlock;
56,501,009✔
345
    pCtx[i].scanFlag = scanFlag;
56,501,009✔
346

347
    SInputColumnInfoData* pInput = &pCtx[i].input;
56,501,009✔
348
    pInput->uid = pBlock->info.id.uid;
56,501,009✔
349
    pInput->colDataSMAIsSet = false;
56,501,009✔
350

351
    SExprInfo* pOneExpr = &pExprSup->pExprInfo[i];
56,501,009✔
352
    bool       hasPk = pOneExpr->pExpr->nodeType == QUERY_NODE_FUNCTION && pOneExpr->pExpr->_function.pFunctNode->hasPk;
56,501,009✔
353
    pCtx[i].hasPrimaryKey = hasPk;
56,501,009✔
354

355
    int16_t tsParamIdx = (!hasPk) ? pOneExpr->base.numOfParams - 1 : pOneExpr->base.numOfParams - 2;
56,501,009✔
356
    int16_t pkParamIdx = pOneExpr->base.numOfParams - 1;
56,501,009✔
357

358
    for (int32_t j = 0; j < pOneExpr->base.numOfParams; ++j) {
117,564,975✔
359
      SFunctParam* pFuncParam = &pOneExpr->base.pParam[j];
61,063,292✔
360
      if (pFuncParam->type == FUNC_PARAM_TYPE_COLUMN) {
61,063,292✔
361
        int32_t slotId = pFuncParam->pCol->slotId;
56,189,598✔
362
        pInput->pData[j] = taosArrayGet(pBlock->pDataBlock, slotId);
56,189,598✔
363
        pInput->totalRows = pBlock->info.rows;
56,185,043✔
364
        pInput->numOfRows = pBlock->info.rows;
56,185,043✔
365
        pInput->startRowIndex = 0;
56,185,043✔
366
        pInput->blankFill = pBlock->info.blankFill;
56,185,043✔
367

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

371
        if (fmIsImplicitTsFunc(pCtx[i].functionId) && (j == tsParamIdx)) {
56,185,043✔
372
          pInput->pPTS = pInput->pData[j];  // in case of merge function, this is not always the ts column data.
4,995,489✔
373
        }
374
        if (hasPk && (j == pkParamIdx)) {
56,190,272✔
375
          pInput->pPrimaryKey = pInput->pData[j];
795,350✔
376
        }
377
        QUERY_CHECK_CONDITION((pInput->pData[j] != NULL), code, lino, _end, TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR);
56,190,272!
378
      } else if (pFuncParam->type == FUNC_PARAM_TYPE_VALUE) {
4,873,694✔
379
        // todo avoid case: top(k, 12), 12 is the value parameter.
380
        // sum(11), 11 is also the value parameter.
381
        if (createDummyCol && pOneExpr->base.numOfParams == 1) {
3,225,813!
382
          pInput->totalRows = pBlock->info.rows;
×
383
          pInput->numOfRows = pBlock->info.rows;
×
384
          pInput->startRowIndex = 0;
×
385
          pInput->blankFill = pBlock->info.blankFill;
×
386

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

394
_end:
14,544,678✔
395
  if (code != TSDB_CODE_SUCCESS) {
14,544,678!
396
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
×
397
  }
398
  return code;
14,545,370✔
399
}
400

401
bool functionNeedToExecute(SqlFunctionCtx* pCtx) {
1,018,481,765✔
402
  struct SResultRowEntryInfo* pResInfo = GET_RES_INFO(pCtx);
1,018,481,765✔
403

404
  // in case of timestamp column, always generated results.
405
  int32_t functionId = pCtx->functionId;
1,018,481,765✔
406
  if (functionId == -1) {
1,018,481,765✔
407
    return false;
48,875,115✔
408
  }
409

410
  if (pCtx->scanFlag == PRE_SCAN) {
969,606,650✔
411
    return fmIsRepeatScanFunc(pCtx->functionId);
20,484✔
412
  }
413

414
  if (isRowEntryCompleted(pResInfo)) {
969,586,166✔
415
    return false;
5,637✔
416
  }
417

418
  return true;
969,580,529✔
419
}
420

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

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

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

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

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

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

471
  return TSDB_CODE_SUCCESS;
×
472
}
473

474
int32_t setBlockSMAInfo(SqlFunctionCtx* pCtx, SExprInfo* pExprInfo, SSDataBlock* pBlock) {
9,451✔
475
  int32_t code = TSDB_CODE_SUCCESS;
9,451✔
476
  int32_t lino = 0;
9,451✔
477
  int32_t numOfRows = pBlock->info.rows;
9,451✔
478

479
  SInputColumnInfoData* pInput = &pCtx->input;
9,451✔
480
  pInput->numOfRows = numOfRows;
9,451✔
481
  pInput->totalRows = numOfRows;
9,451✔
482

483
  if (pBlock->pBlockAgg != NULL) {
9,451!
484
    pInput->colDataSMAIsSet = true;
9,456✔
485

486
    for (int32_t j = 0; j < pExprInfo->base.numOfParams; ++j) {
18,969✔
487
      SFunctParam* pFuncParam = &pExprInfo->base.pParam[j];
9,462✔
488

489
      if (pFuncParam->type == FUNC_PARAM_TYPE_COLUMN) {
9,462!
490
        int32_t slotId = pFuncParam->pCol->slotId;
9,462✔
491
        pInput->pColumnDataAgg[j] = &pBlock->pBlockAgg[slotId];
9,462✔
492
        if (pInput->pColumnDataAgg[j]->colId == -1) {
9,462✔
493
          pInput->colDataSMAIsSet = false;
1,380✔
494
        }
495

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

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

515
/////////////////////////////////////////////////////////////////////////////////////////////
516
STimeWindow getAlignQueryTimeWindow(const SInterval* pInterval, int64_t key) {
28,603,134✔
517
  STimeWindow win = {0};
28,603,134✔
518
  win.skey = taosTimeTruncate(key, pInterval);
28,603,134✔
519

520
  /*
521
   * if the realSkey > INT64_MAX - pInterval->interval, the query duration between
522
   * realSkey and realEkey must be less than one interval.Therefore, no need to adjust the query ranges.
523
   */
524
  win.ekey = taosTimeGetIntervalEnd(win.skey, pInterval);
28,603,057✔
525
  if (win.ekey < win.skey) {
28,602,979✔
526
    win.ekey = INT64_MAX;
2,114✔
527
  }
528

529
  return win;
28,602,979✔
530
}
531

532
int32_t setResultRowInitCtx(SResultRow* pResult, SqlFunctionCtx* pCtx, int32_t numOfOutput,
492,788,035✔
533
                            int32_t* rowEntryInfoOffset) {
534
  bool init = false;
492,788,035✔
535
  for (int32_t i = 0; i < numOfOutput; ++i) {
1,814,299,613✔
536
    pCtx[i].resultInfo = getResultEntryInfo(pResult, i, rowEntryInfoOffset);
1,322,453,927✔
537
    if (init) {
1,322,649,294✔
538
      continue;
116,781,602✔
539
    }
540

541
    struct SResultRowEntryInfo* pResInfo = pCtx[i].resultInfo;
1,205,867,692✔
542
    if (isRowEntryCompleted(pResInfo) && isRowEntryInitialized(pResInfo)) {
1,205,867,692!
543
      continue;
58✔
544
    }
545

546
    if (pCtx[i].isPseudoFunc) {
1,205,867,634✔
547
      continue;
299,756,881✔
548
    }
549

550
    if (!pResInfo->initialized) {
906,110,753✔
551
      if (pCtx[i].functionId != -1) {
856,924,025✔
552
        int32_t code = pCtx[i].fpSet.init(&pCtx[i], pResInfo);
820,198,785✔
553
        if (code != TSDB_CODE_SUCCESS && fmIsUserDefinedFunc(pCtx[i].functionId)) {
820,118,318!
554
          pResInfo->initialized = false;
44✔
555
          return TSDB_CODE_UDF_FUNC_EXEC_FAILURE;
44✔
556
        } else if (code != TSDB_CODE_SUCCESS) {
819,061,069!
557
          return code;
×
558
        }
559
      } else {
560
        pResInfo->initialized = true;
36,725,240✔
561
      }
562
    } else {
563
      init = true;
49,186,728✔
564
    }
565
  }
566
  return TSDB_CODE_SUCCESS;
491,845,686✔
567
}
568

569
void clearResultRowInitFlag(SqlFunctionCtx* pCtx, int32_t numOfOutput) {
99,977,548✔
570
  for (int32_t i = 0; i < numOfOutput; ++i) {
250,412,882✔
571
    SResultRowEntryInfo* pResInfo = pCtx[i].resultInfo;
150,435,334✔
572
    if (pResInfo == NULL) {
150,435,334!
573
      continue;
×
574
    }
575

576
    pResInfo->initialized = false;
150,435,334✔
577
    pResInfo->numOfRes = 0;
150,435,334✔
578
    pResInfo->isNullRes = 0;
150,435,334✔
579
    pResInfo->complete = false;
150,435,334✔
580
  }
581
}
99,977,548✔
582

583
int32_t doFilter(SSDataBlock* pBlock, SFilterInfo* pFilterInfo, SColMatchInfo* pColMatchInfo) {
27,018,687✔
584
  int32_t code = TSDB_CODE_SUCCESS;
27,018,687✔
585
  int32_t lino = 0;
27,018,687✔
586
  if (pFilterInfo == NULL || pBlock->info.rows == 0) {
27,018,687✔
587
    return TSDB_CODE_SUCCESS;
21,815,558✔
588
  }
589

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

593
  code = filterSetDataFromSlotId(pFilterInfo, &param1);
5,203,078✔
594
  QUERY_CHECK_CODE(code, lino, _err);
5,202,858!
595

596
  int32_t status = 0;
5,202,858✔
597
  code = filterExecute(pFilterInfo, pBlock, &p, NULL, param1.numOfCols, &status);
5,202,858✔
598
  QUERY_CHECK_CODE(code, lino, _err);
5,203,042✔
599

600
  code = extractQualifiedTupleByFilterResult(pBlock, p, status);
5,203,041✔
601
  QUERY_CHECK_CODE(code, lino, _err);
5,202,993!
602

603
  if (pColMatchInfo != NULL) {
5,202,993✔
604
    size_t size = taosArrayGetSize(pColMatchInfo->pList);
4,596,588✔
605
    for (int32_t i = 0; i < size; ++i) {
4,601,904✔
606
      SColMatchItem* pInfo = taosArrayGet(pColMatchInfo->pList, i);
4,599,444✔
607
      QUERY_CHECK_NULL(pInfo, code, lino, _err, terrno);
4,599,351!
608
      if (pInfo->colId == PRIMARYKEY_TIMESTAMP_COL_ID) {
4,599,351✔
609
        SColumnInfoData* pColData = taosArrayGet(pBlock->pDataBlock, pInfo->dstSlotId);
4,594,160✔
610
        QUERY_CHECK_NULL(pColData, code, lino, _err, terrno);
4,594,060!
611
        if (pColData->info.type == TSDB_DATA_TYPE_TIMESTAMP) {
4,594,101✔
612
          code = blockDataUpdateTsWindow(pBlock, pInfo->dstSlotId);
4,594,054✔
613
          QUERY_CHECK_CODE(code, lino, _err);
4,594,125!
614
          break;
4,594,125✔
615
        }
616
      }
617
    }
618
  }
619
  code = blockDataCheck(pBlock);
5,202,990✔
620
  QUERY_CHECK_CODE(code, lino, _err);
5,202,807!
621
_err:
5,202,807✔
622
  if (code != TSDB_CODE_SUCCESS) {
5,202,808✔
623
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
1!
624
  }
625
  colDataDestroy(p);
5,202,808✔
626
  taosMemoryFree(p);
5,203,225✔
627
  return code;
5,203,306✔
628
}
629

630
int32_t extractQualifiedTupleByFilterResult(SSDataBlock* pBlock, const SColumnInfoData* p, int32_t status) {
5,203,096✔
631
  int32_t code = TSDB_CODE_SUCCESS;
5,203,096✔
632
  int8_t* pIndicator = (int8_t*)p->pData;
5,203,096✔
633
  if (status == FILTER_RESULT_ALL_QUALIFIED) {
5,203,096✔
634
    // here nothing needs to be done
635
  } else if (status == FILTER_RESULT_NONE_QUALIFIED) {
1,015,914✔
636
    code = trimDataBlock(pBlock, pBlock->info.rows, NULL);
130,981✔
637
    pBlock->info.rows = 0;
130,963✔
638
  } else if (status == FILTER_RESULT_PARTIAL_QUALIFIED) {
884,933!
639
    code = trimDataBlock(pBlock, pBlock->info.rows, (bool*)pIndicator);
884,991✔
640
  } else {
641
    qError("unknown filter result type: %d", status);
×
642
  }
643
  return code;
5,203,200✔
644
}
645

646
void doUpdateNumOfRows(SqlFunctionCtx* pCtx, SResultRow* pRow, int32_t numOfExprs, const int32_t* rowEntryOffset) {
435,576,840✔
647
  bool returnNotNull = false;
435,576,840✔
648
  for (int32_t j = 0; j < numOfExprs; ++j) {
1,551,955,684✔
649
    SResultRowEntryInfo* pResInfo = getResultEntryInfo(pRow, j, rowEntryOffset);
1,115,875,469✔
650
    if (!isRowEntryInitialized(pResInfo)) {
1,116,378,844✔
651
      continue;
250,008,758✔
652
    } else {
653
    }
654

655
    if (pRow->numOfRows < pResInfo->numOfRes) {
866,370,086✔
656
      pRow->numOfRows = pResInfo->numOfRes;
431,781,791✔
657
    }
658

659
    if (pCtx[j].isNotNullFunc) {
866,370,086✔
660
      returnNotNull = true;
237,127,083✔
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) {
436,080,215✔
666
    pRow->numOfRows = 1;
36,414✔
667
  }
668
}
436,080,215✔
669

670
int32_t copyResultrowToDataBlock(SExprInfo* pExprInfo, int32_t numOfExprs, SResultRow* pRow, SqlFunctionCtx* pCtx,
418,189,941✔
671
                                 SSDataBlock* pBlock, const int32_t* rowEntryOffset, SExecTaskInfo* pTaskInfo) {
672
  int32_t code = TSDB_CODE_SUCCESS;
418,189,941✔
673
  int32_t lino = 0;
418,189,941✔
674
  for (int32_t j = 0; j < numOfExprs; ++j) {
1,439,073,298✔
675
    int32_t slotId = pExprInfo[j].base.resSchema.slotId;
1,022,193,915✔
676

677
    pCtx[j].resultInfo = getResultEntryInfo(pRow, j, rowEntryOffset);
1,022,193,915✔
678
    if (pCtx[j].fpSet.finalize) {
1,022,441,729✔
679
      if (strcmp(pCtx[j].pExpr->pExpr->_function.functionName, "_group_key") == 0 ||
615,843,647✔
680
          strcmp(pCtx[j].pExpr->pExpr->_function.functionName, "_group_const_value") == 0) {
521,774,351✔
681
        // for groupkey along with functions that output multiple lines(e.g. Histogram)
682
        // need to match groupkey result for each output row of that function.
683
        if (pCtx[j].resultInfo->numOfRes != 0) {
94,319,818!
684
          pCtx[j].resultInfo->numOfRes = pRow->numOfRows;
95,716,824✔
685
        }
686
      }
687

688
      code = blockDataEnsureCapacity(pBlock, pBlock->info.rows + pCtx[j].resultInfo->numOfRes);
615,843,647✔
689
      QUERY_CHECK_CODE(code, lino, _end);
615,902,377!
690

691
      code = pCtx[j].fpSet.finalize(&pCtx[j], pBlock);
615,902,377✔
692
      if (TSDB_CODE_SUCCESS != code) {
618,331,861!
UNCOV
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) {
406,598,082✔
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);
259,945,003✔
702
      QUERY_CHECK_NULL(pColInfoData, code, lino, _end, terrno);
259,008,667!
703
      char*            in = GET_ROWCELL_INTERBUF(pCtx[j].resultInfo);
259,073,685✔
704
      for (int32_t k = 0; k < pRow->numOfRows; ++k) {
527,719,429✔
705
        code = colDataSetValOrCover(pColInfoData, pBlock->info.rows + k, in, pCtx[j].resultInfo->isNullRes);
268,756,867✔
706
        QUERY_CHECK_CODE(code, lino, _end);
268,645,744!
707
      }
708
    }
709
  }
710

711
_end:
416,879,383✔
712
  if (code != TSDB_CODE_SUCCESS) {
416,879,383!
UNCOV
713
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
×
714
  }
715
  return code;
418,693,496✔
716
}
717

718
// todo refactor. SResultRow has direct pointer in miainfo
719
void finalizeResultRows(SDiskbasedBuf* pBuf, SResultRowPosition* resultRowPosition, SExprSupp* pSup,
73,790,234✔
720
                        SSDataBlock* pBlock, SExecTaskInfo* pTaskInfo) {
721
  SFilePage* page = getBufPage(pBuf, resultRowPosition->pageId);
73,790,234✔
722
  if (page == NULL) {
73,787,347!
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);
73,787,347✔
728

729
  SqlFunctionCtx* pCtx = pSup->pCtx;
73,787,347✔
730
  SExprInfo*      pExprInfo = pSup->pExprInfo;
73,787,347✔
731
  const int32_t*  rowEntryOffset = pSup->rowEntryInfoOffset;
73,787,347✔
732

733
  doUpdateNumOfRows(pCtx, pRow, pSup->numOfExprs, rowEntryOffset);
73,787,347✔
734
  if (pRow->numOfRows == 0) {
73,767,643✔
735
    releaseBufPage(pBuf, page);
1,761✔
736
    return;
×
737
  }
738

739
  int32_t size = pBlock->info.capacity;
73,765,882✔
740
  while (pBlock->info.rows + pRow->numOfRows > size) {
73,857,304✔
741
    size = size * 1.25;
91,422✔
742
  }
743

744
  int32_t code = blockDataEnsureCapacity(pBlock, size);
73,765,882✔
745
  if (TAOS_FAILED(code)) {
73,768,022!
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);
73,768,022✔
752
  if (TAOS_FAILED(code)) {
73,731,928!
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);
73,731,928✔
759
  pBlock->info.rows += pRow->numOfRows;
73,715,578✔
760
}
761

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

771
  size_t  keyLen = 0;
2,809,574✔
772
  int32_t numOfRows = tSimpleHashGetSize(pHashmap);
2,809,574✔
773

774
  // begin from last iter
775
  void*   pData = pGroupResInfo->dataPos;
2,804,878✔
776
  int32_t iter = pGroupResInfo->iter;
2,804,878✔
777
  while ((pData = tSimpleHashIterate(pHashmap, pData, &iter)) != NULL) {
12,329,016✔
778
    void*               key = tSimpleHashGetKey(pData, &keyLen);
12,109,295✔
779
    SResultRowPosition* pos = pData;
12,109,295✔
780
    uint64_t            groupId = *(uint64_t*)key;
12,109,295✔
781

782
    SFilePage* page = getBufPage(pBuf, pos->pageId);
12,109,295✔
783
    if (page == NULL) {
12,104,897!
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);
12,104,897✔
789

790
    doUpdateNumOfRows(pCtx, pRow, numOfExprs, rowEntryOffset);
12,104,897✔
791

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

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

802
    if (!ignoreGroup) {
12,074,087✔
803
      if (pBlock->info.id.groupId == 0) {
5,182,705✔
804
        pBlock->info.id.groupId = groupId;
2,629,720✔
805
      } else {
806
        // current value belongs to different group, it can't be packed into one datablock
807
        if (pBlock->info.id.groupId != groupId) {
2,552,985!
808
          releaseBufPage(pBuf, page);
2,573,251✔
809
          break;
2,572,629✔
810
        }
811
      }
812
    }
813

814
    if (pBlock->info.rows + pRow->numOfRows > pBlock->info.capacity) {
9,500,836!
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;
9,500,836✔
824
    pGroupResInfo->iter = iter;
9,500,836✔
825
    pGroupResInfo->dataPos = pData;
9,500,836✔
826

827
    code = copyResultrowToDataBlock(pExprInfo, numOfExprs, pRow, pCtx, pBlock, rowEntryOffset, pTaskInfo);
9,500,836✔
828
    releaseBufPage(pBuf, page);
9,525,730✔
829
    QUERY_CHECK_CODE(code, lino, _end);
9,524,178!
830
    pBlock->info.rows += pRow->numOfRows;
9,524,178✔
831
    if (pBlock->info.rows >= threshold) {
9,524,178✔
832
      break;
40✔
833
    }
834
  }
835

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

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

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

858
  int32_t numOfRows = getNumOfTotalRes(pGroupResInfo);
2,227,368✔
859

860
  for (int32_t i = pGroupResInfo->index; i < numOfRows; i += 1) {
237,338,066✔
861
    SResKeyPos* pPos = taosArrayGetP(pGroupResInfo->pRows, i);
235,751,872✔
862
    SFilePage*  page = getBufPage(pBuf, pPos->pos.pageId);
235,228,249✔
863
    if (page == NULL) {
235,370,540!
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);
235,370,540✔
869

870
    doUpdateNumOfRows(pCtx, pRow, numOfExprs, rowEntryOffset);
235,370,540✔
871

872
    // no results, continue to check the next one
873
    if (pRow->numOfRows == 0) {
234,516,863✔
874
      pGroupResInfo->index += 1;
884✔
875
      releaseBufPage(pBuf, page);
884✔
876
      continue;
884✔
877
    }
878

879
    if (!ignoreGroup) {
234,515,979✔
880
      if (pBlock->info.id.groupId == 0) {
160,099,040✔
881
        pBlock->info.id.groupId = pPos->groupId;
143,102,714✔
882
      } else {
883
        // current value belongs to different group, it can't be packed into one datablock
884
        if (pBlock->info.id.groupId != pPos->groupId) {
16,996,326✔
885
          releaseBufPage(pBuf, page);
133,431✔
886
          break;
133,426✔
887
        }
888
      }
889
    }
890

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

900
    pGroupResInfo->index += 1;
234,382,548✔
901
    code = copyResultrowToDataBlock(pExprInfo, numOfExprs, pRow, pCtx, pBlock, rowEntryOffset, pTaskInfo);
234,382,548✔
902
    releaseBufPage(pBuf, page);
236,431,776✔
903
    QUERY_CHECK_CODE(code, lino, _end);
235,593,129!
904

905
    pBlock->info.rows += pRow->numOfRows;
235,593,129✔
906
    if (pBlock->info.rows >= threshold) {
235,593,129✔
907
      break;
483,330✔
908
    }
909
  }
910

911
  qDebug("%s result generated, rows:%" PRId64 ", groupId:%" PRIu64, GET_TASKID(pTaskInfo), pBlock->info.rows,
2,202,950✔
912
         pBlock->info.id.groupId);
913
  pBlock->info.dataLoad = 1;
2,202,954✔
914
  code = blockDataUpdateTsWindow(pBlock, 0);
2,202,954✔
915
  QUERY_CHECK_CODE(code, lino, _end);
2,227,263!
916

917
_end:
2,227,263✔
918
  if (code != TSDB_CODE_SUCCESS) {
2,227,263!
UNCOV
919
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
×
UNCOV
920
    T_LONG_JMP(pTaskInfo->env, code);
×
921
  }
922
}
2,227,263✔
923

924
void doBuildResultDatablock(SOperatorInfo* pOperator, SOptrBasicInfo* pbInfo, SGroupResInfo* pGroupResInfo,
3,165,135✔
925
                            SDiskbasedBuf* pBuf) {
926
  SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
3,165,135✔
927
  SSDataBlock*   pBlock = pbInfo->pRes;
3,165,135✔
928

929
  // set output datablock version
930
  pBlock->info.version = pTaskInfo->version;
3,165,135✔
931

932
  blockDataCleanup(pBlock);
3,165,135✔
933
  if (!hasRemainResults(pGroupResInfo)) {
3,165,735✔
934
    return;
938,196✔
935
  }
936

937
  // clear the existed group id
938
  pBlock->info.id.groupId = 0;
2,227,414✔
939
  if (!pbInfo->mergeResultBlock) {
2,227,414✔
940
    doCopyToSDataBlock(pTaskInfo, pBlock, &pOperator->exprSupp, pBuf, pGroupResInfo, pOperator->resultInfo.threshold,
1,306,040✔
941
                       false);
942
  } else {
943
    while (hasRemainResults(pGroupResInfo)) {
1,613,598✔
944
      doCopyToSDataBlock(pTaskInfo, pBlock, &pOperator->exprSupp, pBuf, pGroupResInfo, pOperator->resultInfo.threshold,
921,333✔
945
                         true);
946
      if (pBlock->info.rows >= pOperator->resultInfo.threshold) {
921,365✔
947
        break;
229,141✔
948
      }
949

950
      // clearing group id to continue to merge data that belong to different groups
951
      pBlock->info.id.groupId = 0;
692,224✔
952
    }
953

954
    // clear the group id info in SSDataBlock, since the client does not need it
955
    pBlock->info.id.groupId = 0;
921,371✔
956
  }
957
}
958

959
void destroyExprInfo(SExprInfo* pExpr, int32_t numOfExprs) {
9,047,299✔
960
  for (int32_t i = 0; i < numOfExprs; ++i) {
38,869,157✔
961
    SExprInfo* pExprInfo = &pExpr[i];
29,821,544✔
962
    for (int32_t j = 0; j < pExprInfo->base.numOfParams; ++j) {
61,701,805✔
963
      if (pExprInfo->base.pParam[j].type == FUNC_PARAM_TYPE_COLUMN) {
31,898,257✔
964
        taosMemoryFreeClear(pExprInfo->base.pParam[j].pCol);
28,545,774!
965
      } else if (pExprInfo->base.pParam[j].type == FUNC_PARAM_TYPE_VALUE) {
3,352,483✔
966
        taosVariantDestroy(&pExprInfo->base.pParam[j].param);
2,612,945✔
967
      }
968
    }
969

970
    taosMemoryFree(pExprInfo->base.pParam);
29,803,548✔
971
    taosMemoryFree(pExprInfo->pExpr);
29,828,122✔
972
  }
973
}
9,047,613✔
974

975
int32_t getBufferPgSize(int32_t rowSize, uint32_t* defaultPgsz, uint32_t* defaultBufsz) {
5,457,128✔
976
  *defaultPgsz = 4096;
5,457,128✔
977
  uint32_t last = *defaultPgsz;
5,457,128✔
978
  while (*defaultPgsz < rowSize * 4) {
6,871,867✔
979
    *defaultPgsz <<= 1u;
1,414,739✔
980
    if (*defaultPgsz < last) {
1,414,739!
981
      return TSDB_CODE_INVALID_PARA;
×
982
    }
983
    last = *defaultPgsz;
1,414,739✔
984
  }
985

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

997
  return 0;
5,457,128✔
998
}
999

1000
void initResultSizeInfo(SResultInfo* pResultInfo, int32_t numOfRows) {
13,478,099✔
1001
  if (numOfRows == 0) {
13,478,099!
1002
    numOfRows = 4096;
×
1003
  }
1004

1005
  pResultInfo->capacity = numOfRows;
13,478,099✔
1006
  pResultInfo->threshold = numOfRows * 0.75;
13,478,099✔
1007

1008
  if (pResultInfo->threshold == 0) {
13,478,099✔
1009
    pResultInfo->threshold = numOfRows;
13,937✔
1010
  }
1011
}
13,478,099✔
1012

1013
void initBasicInfo(SOptrBasicInfo* pInfo, SSDataBlock* pBlock) {
5,436,582✔
1014
  pInfo->pRes = pBlock;
5,436,582✔
1015
  initResultRowInfo(&pInfo->resultRowInfo);
5,436,582✔
1016
}
5,436,462✔
1017

1018
static void destroySqlFunctionCtx(SqlFunctionCtx* pCtx, SExprInfo* pExpr, int32_t numOfOutput) {
27,239,300✔
1019
  if (pCtx == NULL) {
27,239,300✔
1020
    return;
17,305,705✔
1021
  }
1022

1023
  for (int32_t i = 0; i < numOfOutput; ++i) {
39,488,094✔
1024
    if (pExpr != NULL) {
29,548,471!
1025
      SExprInfo* pExprInfo = &pExpr[i];
29,550,920✔
1026
      for (int32_t j = 0; j < pExprInfo->base.numOfParams; ++j) {
61,172,578✔
1027
        if (pExprInfo->base.pParam[j].type == FUNC_PARAM_TYPE_VALUE) {
31,623,935✔
1028
          taosMemoryFree(pCtx[i].input.pData[j]);
2,608,710✔
1029
          taosMemoryFree(pCtx[i].input.pColumnDataAgg[j]);
2,608,648✔
1030
        }
1031
      }
1032
    }
1033
    for (int32_t j = 0; j < pCtx[i].numOfParams; ++j) {
61,161,775✔
1034
      taosVariantDestroy(&pCtx[i].param[j].param);
31,620,256✔
1035
    }
1036

1037
    taosMemoryFreeClear(pCtx[i].subsidiaries.pCtx);
29,541,519✔
1038
    taosMemoryFreeClear(pCtx[i].subsidiaries.buf);
29,541,637✔
1039
    taosMemoryFree(pCtx[i].input.pData);
29,541,642✔
1040
    taosMemoryFree(pCtx[i].input.pColumnDataAgg);
29,559,800✔
1041

1042
    if (pCtx[i].udfName != NULL) {
29,553,334✔
1043
      taosMemoryFree(pCtx[i].udfName);
599✔
1044
    }
1045
  }
1046

1047
  taosMemoryFreeClear(pCtx);
9,939,623✔
1048
  return;
9,939,559✔
1049
}
1050

1051
int32_t initExprSupp(SExprSupp* pSup, SExprInfo* pExprInfo, int32_t numOfExpr, SFunctionStateStore* pStore) {
8,135,367✔
1052
  pSup->pExprInfo = pExprInfo;
8,135,367✔
1053
  pSup->numOfExprs = numOfExpr;
8,135,367✔
1054
  if (pSup->pExprInfo != NULL) {
8,135,367✔
1055
    pSup->pCtx = createSqlFunctionCtx(pExprInfo, numOfExpr, &pSup->rowEntryInfoOffset, pStore);
6,985,627✔
1056
    if (pSup->pCtx == NULL) {
6,984,819!
UNCOV
1057
      return TSDB_CODE_OUT_OF_MEMORY;
×
1058
    }
1059
  }
1060

1061
  return TSDB_CODE_SUCCESS;
8,134,559✔
1062
}
1063

1064
void cleanupExprSupp(SExprSupp* pSupp) {
27,239,537✔
1065
  destroySqlFunctionCtx(pSupp->pCtx, pSupp->pExprInfo, pSupp->numOfExprs);
27,239,537✔
1066
  if (pSupp->pExprInfo != NULL) {
27,238,823✔
1067
    destroyExprInfo(pSupp->pExprInfo, pSupp->numOfExprs);
9,041,771✔
1068
    taosMemoryFreeClear(pSupp->pExprInfo);
9,041,864!
1069
  }
1070

1071
  if (pSupp->pFilterInfo != NULL) {
27,239,033✔
1072
    filterFreeInfo(pSupp->pFilterInfo);
2,988,907✔
1073
    pSupp->pFilterInfo = NULL;
2,988,936✔
1074
  }
1075

1076
  taosMemoryFree(pSupp->rowEntryInfoOffset);
27,239,062✔
1077
}
27,237,231✔
1078

1079
void cleanupBasicInfo(SOptrBasicInfo* pInfo) {
5,465,128✔
1080
  blockDataDestroy(pInfo->pRes);
5,465,128✔
1081
  pInfo->pRes = NULL;
5,465,257✔
1082
}
5,465,257✔
1083

1084
bool groupbyTbname(SNodeList* pGroupList) {
4,755,013✔
1085
  bool bytbname = false;
4,755,013✔
1086
  SNode*pNode = NULL;
4,755,013✔
1087
  FOREACH(pNode, pGroupList) {
4,855,235✔
1088
    if (pNode->type == QUERY_NODE_FUNCTION) {
416,295✔
1089
      bytbname = (strcmp(((struct SFunctionNode*)pNode)->functionName, "tbname") == 0);
316,073✔
1090
      break;
316,073✔
1091
    }
1092
  }
1093
  return bytbname;
4,755,013✔
1094
}
1095

1096
int32_t createDataSinkParam(SDataSinkNode* pNode, void** pParam, SExecTaskInfo* pTask, SReadHandle* readHandle) {
7,239,481✔
1097
  switch (pNode->type) {
7,239,481✔
1098
    case QUERY_NODE_PHYSICAL_PLAN_QUERY_INSERT: {
422✔
1099
      SInserterParam* pInserterParam = taosMemoryCalloc(1, sizeof(SInserterParam));
422✔
1100
      if (NULL == pInserterParam) {
422!
1101
        return terrno;
×
1102
      }
1103
      pInserterParam->readHandle = readHandle;
422✔
1104

1105
      *pParam = pInserterParam;
422✔
1106
      break;
422✔
1107
    }
1108
    case QUERY_NODE_PHYSICAL_PLAN_DELETE: {
60,217✔
1109
      SDeleterParam* pDeleterParam = taosMemoryCalloc(1, sizeof(SDeleterParam));
60,217✔
1110
      if (NULL == pDeleterParam) {
60,217!
1111
        return terrno;
×
1112
      }
1113

1114
      SArray* pInfoList = NULL;
60,217✔
1115
      int32_t code = getTableListInfo(pTask, &pInfoList);
60,217✔
1116
      if (code != TSDB_CODE_SUCCESS || pInfoList == NULL) {
60,213!
1117
        taosMemoryFree(pDeleterParam);
×
1118
        return code;
×
1119
      }
1120

1121
      STableListInfo* pTableListInfo = taosArrayGetP(pInfoList, 0);
60,213✔
1122
      taosArrayDestroy(pInfoList);
60,206✔
1123

1124
      pDeleterParam->suid = tableListGetSuid(pTableListInfo);
60,216✔
1125

1126
      // TODO extract uid list
1127
      int32_t numOfTables = 0;
60,213✔
1128
      code = tableListGetSize(pTableListInfo, &numOfTables);
60,213✔
1129
      if (code != TSDB_CODE_SUCCESS) {
60,214!
1130
        qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(code));
×
1131
        taosMemoryFree(pDeleterParam);
×
1132
        return code;
×
1133
      }
1134

1135
      pDeleterParam->pUidList = taosArrayInit(numOfTables, sizeof(uint64_t));
60,214✔
1136
      if (NULL == pDeleterParam->pUidList) {
60,216!
1137
        taosMemoryFree(pDeleterParam);
×
1138
        return terrno;
×
1139
      }
1140

1141
      for (int32_t i = 0; i < numOfTables; ++i) {
135,103✔
1142
        STableKeyInfo* pTable = tableListGetInfo(pTableListInfo, i);
74,889✔
1143
        if (!pTable) {
74,886!
1144
          taosArrayDestroy(pDeleterParam->pUidList);
×
1145
          taosMemoryFree(pDeleterParam);
×
1146
          return TSDB_CODE_OUT_OF_MEMORY;
×
1147
        }
1148
        void*          tmp = taosArrayPush(pDeleterParam->pUidList, &pTable->uid);
74,886✔
1149
        if (!tmp) {
74,887!
1150
          taosArrayDestroy(pDeleterParam->pUidList);
×
1151
          taosMemoryFree(pDeleterParam);
×
1152
          return terrno;
×
1153
        }
1154
      }
1155

1156
      *pParam = pDeleterParam;
60,214✔
1157
      break;
60,214✔
1158
    }
1159
    default:
7,178,842✔
1160
      break;
7,178,842✔
1161
  }
1162

1163
  return TSDB_CODE_SUCCESS;
7,239,478✔
1164
}
1165

1166
void streamOpReleaseState(SOperatorInfo* pOperator) {
392✔
1167
  SOperatorInfo* downstream = pOperator->pDownstream[0];
392✔
1168
  if (downstream->fpSet.releaseStreamStateFn) {
392!
1169
    downstream->fpSet.releaseStreamStateFn(downstream);
392✔
1170
  }
1171
}
392✔
1172

1173
void streamOpReloadState(SOperatorInfo* pOperator) {
392✔
1174
  SOperatorInfo* downstream = pOperator->pDownstream[0];
392✔
1175
  if (downstream->fpSet.reloadStreamStateFn) {
392!
1176
    downstream->fpSet.reloadStreamStateFn(downstream);
392✔
1177
  }
1178
}
392✔
1179

1180
void freeOperatorParamImpl(SOperatorParam* pParam, SOperatorParamType type) {
106,248✔
1181
  int32_t childrenNum = taosArrayGetSize(pParam->pChildren);
106,248✔
1182
  for (int32_t i = 0; i < childrenNum; ++i) {
106,248!
UNCOV
1183
    SOperatorParam* pChild = taosArrayGetP(pParam->pChildren, i);
×
UNCOV
1184
    freeOperatorParam(pChild, type);
×
1185
  }
1186

1187
  taosArrayDestroy(pParam->pChildren);
106,248✔
1188

1189
  taosMemoryFree(pParam->value);
106,249✔
1190

1191
  taosMemoryFree(pParam);
106,248✔
1192
}
106,249✔
1193

1194
void freeExchangeGetBasicOperatorParam(void* pParam) {
1,046✔
1195
  SExchangeOperatorBasicParam* pBasic = (SExchangeOperatorBasicParam*)pParam;
1,046✔
1196
  taosArrayDestroy(pBasic->uidList);
1,046✔
1197
}
1,046✔
1198

1199
void freeExchangeGetOperatorParam(SOperatorParam* pParam) {
646✔
1200
  SExchangeOperatorParam* pExcParam = (SExchangeOperatorParam*)pParam->value;
646✔
1201
  if (pExcParam->multiParams) {
646✔
1202
    SExchangeOperatorBatchParam* pExcBatch = (SExchangeOperatorBatchParam*)pParam->value;
598✔
1203
    tSimpleHashCleanup(pExcBatch->pBatchs);
598✔
1204
  } else {
1205
    freeExchangeGetBasicOperatorParam(&pExcParam->basic);
48✔
1206
  }
1207

1208
  freeOperatorParamImpl(pParam, OP_GET_PARAM);
646✔
1209
}
646✔
1210

1211
void freeExchangeNotifyOperatorParam(SOperatorParam* pParam) { freeOperatorParamImpl(pParam, OP_NOTIFY_PARAM); }
×
1212

1213
void freeGroupCacheGetOperatorParam(SOperatorParam* pParam) { freeOperatorParamImpl(pParam, OP_GET_PARAM); }
69,006✔
1214

1215
void freeGroupCacheNotifyOperatorParam(SOperatorParam* pParam) { freeOperatorParamImpl(pParam, OP_NOTIFY_PARAM); }
×
1216

1217
void freeMergeJoinGetOperatorParam(SOperatorParam* pParam) { freeOperatorParamImpl(pParam, OP_GET_PARAM); }
34,503✔
1218

1219
void freeMergeJoinNotifyOperatorParam(SOperatorParam* pParam) { freeOperatorParamImpl(pParam, OP_NOTIFY_PARAM); }
×
1220

1221
void freeTableScanGetOperatorParam(SOperatorParam* pParam) {
2,093✔
1222
  STableScanOperatorParam* pTableScanParam = (STableScanOperatorParam*)pParam->value;
2,093✔
1223
  taosArrayDestroy(pTableScanParam->pUidList);
2,093✔
1224
  freeOperatorParamImpl(pParam, OP_GET_PARAM);
2,093✔
1225
}
2,094✔
1226

1227
void freeTableScanNotifyOperatorParam(SOperatorParam* pParam) { freeOperatorParamImpl(pParam, OP_NOTIFY_PARAM); }
×
1228

1229
void freeOperatorParam(SOperatorParam* pParam, SOperatorParamType type) {
4,430,696✔
1230
  if (NULL == pParam) {
4,430,696✔
1231
    return;
4,324,475✔
1232
  }
1233

1234
  switch (pParam->opType) {
106,221!
1235
    case QUERY_NODE_PHYSICAL_PLAN_EXCHANGE:
646✔
1236
      type == OP_GET_PARAM ? freeExchangeGetOperatorParam(pParam) : freeExchangeNotifyOperatorParam(pParam);
646!
1237
      break;
646✔
1238
    case QUERY_NODE_PHYSICAL_PLAN_GROUP_CACHE:
69,006✔
1239
      type == OP_GET_PARAM ? freeGroupCacheGetOperatorParam(pParam) : freeGroupCacheNotifyOperatorParam(pParam);
69,006!
1240
      break;
69,006✔
1241
    case QUERY_NODE_PHYSICAL_PLAN_MERGE_JOIN:
34,503✔
1242
      type == OP_GET_PARAM ? freeMergeJoinGetOperatorParam(pParam) : freeMergeJoinNotifyOperatorParam(pParam);
34,503!
1243
      break;
34,503✔
1244
    case QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN:
2,094✔
1245
      type == OP_GET_PARAM ? freeTableScanGetOperatorParam(pParam) : freeTableScanNotifyOperatorParam(pParam);
2,094✔
1246
      break;
2,094✔
UNCOV
1247
    default:
×
UNCOV
1248
      qError("unsupported op %d param, type %d", pParam->opType, type);
×
UNCOV
1249
      break;
×
1250
  }
1251
}
1252

1253
void freeResetOperatorParams(struct SOperatorInfo* pOperator, SOperatorParamType type, bool allFree) {
34,668,035✔
1254
  SOperatorParam**  ppParam = NULL;
34,668,035✔
1255
  SOperatorParam*** pppDownstramParam = NULL;
34,668,035✔
1256
  switch (type) {
34,668,035!
1257
    case OP_GET_PARAM:
17,358,738✔
1258
      ppParam = &pOperator->pOperatorGetParam;
17,358,738✔
1259
      pppDownstramParam = &pOperator->pDownstreamGetParams;
17,358,738✔
1260
      break;
17,358,738✔
1261
    case OP_NOTIFY_PARAM:
17,320,288✔
1262
      ppParam = &pOperator->pOperatorNotifyParam;
17,320,288✔
1263
      pppDownstramParam = &pOperator->pDownstreamNotifyParams;
17,320,288✔
1264
      break;
17,320,288✔
1265
    default:
×
1266
      return;
×
1267
  }
1268

1269
  if (*ppParam) {
34,679,026✔
1270
    freeOperatorParam(*ppParam, type);
34,503✔
1271
    *ppParam = NULL;
34,503✔
1272
  }
1273

1274
  if (*pppDownstramParam) {
34,679,026✔
1275
    for (int32_t i = 0; i < pOperator->numOfDownstream; ++i) {
105,203✔
1276
      if ((*pppDownstramParam)[i]) {
69,006!
UNCOV
1277
        freeOperatorParam((*pppDownstramParam)[i], type);
×
UNCOV
1278
        (*pppDownstramParam)[i] = NULL;
×
1279
      }
1280
    }
1281
    if (allFree) {
36,197✔
1282
      taosMemoryFreeClear(*pppDownstramParam);
1,958!
1283
    }
1284
  }
1285
}
1286

1287
FORCE_INLINE int32_t getNextBlockFromDownstreamImpl(struct SOperatorInfo* pOperator, int32_t idx, bool clearParam,
20,997,984✔
1288
                                                    SSDataBlock** pResBlock) {
1289
  QRY_PARAM_CHECK(pResBlock);
20,997,984!
1290

1291
  int32_t code = 0;
20,997,984✔
1292
  if (pOperator->pDownstreamGetParams && pOperator->pDownstreamGetParams[idx]) {
20,997,984!
1293
    qDebug("DynOp: op %s start to get block from downstream %s", pOperator->name, pOperator->pDownstream[idx]->name);
103,666✔
1294
    code = pOperator->pDownstream[idx]->fpSet.getNextExtFn(pOperator->pDownstream[idx],
103,666✔
1295
                                                           pOperator->pDownstreamGetParams[idx], pResBlock);
103,666✔
1296
    if (clearParam && (code == 0)) {
103,666!
1297
      freeOperatorParam(pOperator->pDownstreamGetParams[idx], OP_GET_PARAM);
×
1298
      pOperator->pDownstreamGetParams[idx] = NULL;
×
1299
    }
1300

1301
    if (code) {
103,666!
1302
      qError("failed to get next data block from upstream at %s, line:%d code:%s", __func__, __LINE__, tstrerror(code));
×
1303
    }
1304
    return code;
103,666✔
1305
  }
1306

1307
  code = pOperator->pDownstream[idx]->fpSet.getNextFn(pOperator->pDownstream[idx], pResBlock);
20,894,318✔
1308
  if (code) {
20,904,875!
1309
    qError("failed to get next data block from upstream at %s, %d code:%s", __func__, __LINE__, tstrerror(code));
×
1310
  }
1311
  return code;
20,904,961✔
1312
}
1313

1314
bool compareVal(const char* v, const SStateKeys* pKey) {
24,361,529✔
1315
  if (IS_VAR_DATA_TYPE(pKey->type)) {
24,361,529!
1316
    if (varDataLen(v) != varDataLen(pKey->pData)) {
2,373!
1317
      return false;
×
1318
    } else {
1319
      return memcmp(varDataVal(v), varDataVal(pKey->pData), varDataLen(v)) == 0;
2,373✔
1320
    }
1321
  } else {
1322
    return memcmp(pKey->pData, v, pKey->bytes) == 0;
24,359,156✔
1323
  }
1324
}
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