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

taosdata / TDengine / #3558

17 Dec 2024 06:05AM UTC coverage: 59.778% (+1.6%) from 58.204%
#3558

push

travis-ci

web-flow
Merge pull request #29179 from taosdata/merge/mainto3.0

merge: form main to 3.0 branch

132787 of 287595 branches covered (46.17%)

Branch coverage included in aggregate %.

104 of 191 new or added lines in 5 files covered. (54.45%)

6085 existing lines in 168 files now uncovered.

209348 of 284746 relevant lines covered (73.52%)

8164844.48 hits per line

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

64.34
/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) {
65,325,565✔
86
  SFilePage* pData = NULL;
65,325,565✔
87

88
  // in the first scan, new space needed for results
89
  int32_t pageId = -1;
65,325,565✔
90
  if (*currentPageId == -1) {
65,325,565✔
91
    pData = getNewBufPage(pResultBuf, &pageId);
1,900,339✔
92
    if (pData == NULL) {
1,900,437✔
93
      qError("failed to get buffer, code:%s", tstrerror(terrno));
612!
94
      return NULL;
×
95
    }
96
    pData->num = sizeof(SFilePage);
1,899,825✔
97
  } else {
98
    pData = getBufPage(pResultBuf, *currentPageId);
63,425,226✔
99
    if (pData == NULL) {
63,440,042!
100
      qError("failed to get buffer, code:%s", tstrerror(terrno));
×
101
      return NULL;
×
102
    }
103

104
    pageId = *currentPageId;
63,440,042✔
105

106
    if (pData->num + interBufSize > getBufPageSize(pResultBuf)) {
63,440,042✔
107
      // release current page first, and prepare the next one
108
      releaseBufPage(pResultBuf, pData);
4,239,733✔
109

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

119
  if (pData == NULL) {
65,392,433!
120
    return NULL;
×
121
  }
122

123
  setBufPageDirty(pData, true);
65,392,433✔
124

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

128
  memset((char*)pResultRow, 0, interBufSize);
65,139,491✔
129
  pResultRow->pageId = pageId;
65,139,491✔
130
  pResultRow->offset = (int32_t)pData->num;
65,139,491✔
131

132
  *currentPageId = pageId;
65,139,491✔
133
  pData->num += interBufSize;
65,139,491✔
134
  return pResultRow;
65,139,491✔
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,
98,859,501✔
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);
98,859,501✔
148
  if (!keepGroup) {
98,859,501✔
149
    *(uint64_t*)pSup->keyBuf = calcGroupId(pSup->keyBuf, GET_RES_WINDOW_KEY_LEN(bytes));
10,472,422✔
150
  }
151

152
  SResultRowPosition* p1 =
153
      (SResultRowPosition*)tSimpleHashGet(pSup->pResultRowHashTable, pSup->keyBuf, GET_RES_WINDOW_KEY_LEN(bytes));
99,140,539✔
154

155
  SResultRow* pResult = NULL;
100,423,626✔
156

157
  // in case of repeat scan/reverse scan, no new time window added.
158
  if (isIntervalQuery) {
100,423,626✔
159
    if (p1 != NULL) {  // the *p1 may be NULL in case of sliding+offset exists.
87,567,137✔
160
      pResult = getResultRowByPos(pResultBuf, p1, true);
27,049,139✔
161
      if (pResult == NULL) {
27,049,139!
162
        pTaskInfo->code = terrno;
×
163
        return NULL;
×
164
      }
165

166
      if (pResult->pageId != p1->pageId || pResult->offset != p1->offset) {
27,049,139!
167
        terrno = TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR;
957✔
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) {
12,856,489✔
176
      // todo
177
      pResult = getResultRowByPos(pResultBuf, p1, true);
5,697,792✔
178
      if (NULL == pResult) {
5,697,792!
179
        pTaskInfo->code = terrno;
×
180
        return NULL;
×
181
      }
182

183
      if (pResult->pageId != p1->pageId || pResult->offset != p1->offset) {
5,697,792!
184
        terrno = TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR;
×
185
        pTaskInfo->code = terrno;
×
186
        return NULL;
16,010✔
187
      }
188
    }
189
  }
190

191
  // 1. close current opened time window
192
  if (pResultRowInfo->cur.pageId != -1 && ((pResult == NULL) || (pResult->pageId != pResultRowInfo->cur.pageId))) {
99,916,811✔
193
    SResultRowPosition pos = pResultRowInfo->cur;
67,269,102✔
194
    SFilePage*         pPage = getBufPage(pResultBuf, pos.pageId);
67,269,102✔
195
    if (pPage == NULL) {
65,829,238!
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);
65,829,238✔
201
  }
202

203
  // allocate a new buffer page
204
  if (pResult == NULL) {
97,907,952✔
205
    pResult = getNewResultRow(pResultBuf, &pSup->currentPageId, pSup->resultRowSize);
65,322,717✔
206
    if (pResult == NULL) {
65,368,971!
207
      pTaskInfo->code = terrno;
×
208
      return NULL;
×
209
    }
210

211
    // add a new result set for a new group
212
    SResultRowPosition pos = {.pageId = pResult->pageId, .offset = pResult->offset};
65,368,971✔
213
    int32_t code = tSimpleHashPut(pSup->pResultRowHashTable, pSup->keyBuf, GET_RES_WINDOW_KEY_LEN(bytes), &pos,
65,368,971✔
214
                                  sizeof(SResultRowPosition));
215
    if (code != TSDB_CODE_SUCCESS) {
66,952,268!
UNCOV
216
      qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(code));
×
217
      pTaskInfo->code = code;
×
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};
99,619,645✔
224

225
  // too many time window in query
226
  if (pTaskInfo->execModel == OPTR_EXEC_MODEL_BATCH &&
198,619,029!
227
      tSimpleHashGetSize(pSup->pResultRowHashTable) > MAX_INTERVAL_TIME_WINDOW) {
99,564,754✔
228
    pTaskInfo->code = TSDB_CODE_QRY_TOO_MANY_TIMEWINDOW;
×
229
    return NULL;
×
230
  }
231

232
  return pResult;
99,054,275✔
233
}
234

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

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

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

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

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

274
int32_t setInputDataBlock(SExprSupp* pExprSup, SSDataBlock* pBlock, int32_t order, int32_t scanFlag,
7,989,970✔
275
                          bool createDummyCol) {
276
  if (pBlock->pBlockAgg != NULL) {
7,989,970✔
277
    return doSetInputDataBlockInfo(pExprSup, pBlock, order, scanFlag);
8,174✔
278
  } else {
279
    return doSetInputDataBlock(pExprSup, pBlock, order, scanFlag, createDummyCol);
7,981,796✔
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,
7,981,887✔
335
                                   bool createDummyCol) {
336
  int32_t         code = TSDB_CODE_SUCCESS;
7,981,887✔
337
  int32_t         lino = 0;
7,981,887✔
338
  SqlFunctionCtx* pCtx = pExprSup->pCtx;
7,981,887✔
339

340
  for (int32_t i = 0; i < pExprSup->numOfExprs; ++i) {
39,601,853✔
341
    pCtx[i].order = order;
31,625,983✔
342
    pCtx[i].input.numOfRows = pBlock->info.rows;
31,625,983✔
343

344
    pCtx[i].pSrcBlock = pBlock;
31,625,983✔
345
    pCtx[i].scanFlag = scanFlag;
31,625,983✔
346

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

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

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

358
    for (int32_t j = 0; j < pOneExpr->base.numOfParams; ++j) {
64,064,880✔
359
      SFunctParam* pFuncParam = &pOneExpr->base.pParam[j];
32,444,914✔
360
      if (pFuncParam->type == FUNC_PARAM_TYPE_COLUMN) {
32,444,914✔
361
        int32_t slotId = pFuncParam->pCol->slotId;
30,072,171✔
362
        pInput->pData[j] = taosArrayGet(pBlock->pDataBlock, slotId);
30,072,171✔
363
        pInput->totalRows = pBlock->info.rows;
30,063,639✔
364
        pInput->numOfRows = pBlock->info.rows;
30,063,639✔
365
        pInput->startRowIndex = 0;
30,063,639✔
366
        pInput->blankFill = pBlock->info.blankFill;
30,063,639✔
367

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

371
        if (fmIsImplicitTsFunc(pCtx[i].functionId) && (j == tsParamIdx)) {
30,063,639✔
372
          pInput->pPTS = pInput->pData[j];  // in case of merge function, this is not always the ts column data.
3,151,359✔
373
        }
374
        if (hasPk && (j == pkParamIdx)) {
30,066,154✔
375
          pInput->pPrimaryKey = pInput->pData[j];
30,335✔
376
        }
377
        QUERY_CHECK_CONDITION((pInput->pData[j] != NULL), code, lino, _end, TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR);
30,066,154!
378
      } else if (pFuncParam->type == FUNC_PARAM_TYPE_VALUE) {
2,372,743✔
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) {
1,321,131!
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:
7,975,870✔
395
  if (code != TSDB_CODE_SUCCESS) {
7,975,870!
396
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
×
397
  }
398
  return code;
7,984,038✔
399
}
400

401
bool functionNeedToExecute(SqlFunctionCtx* pCtx) {
412,936,792✔
402
  struct SResultRowEntryInfo* pResInfo = GET_RES_INFO(pCtx);
412,936,792✔
403

404
  // in case of timestamp column, always generated results.
405
  int32_t functionId = pCtx->functionId;
412,936,792✔
406
  if (functionId == -1) {
412,936,792✔
407
    return false;
23,021,845✔
408
  }
409

410
  if (pCtx->scanFlag == PRE_SCAN) {
389,914,947✔
411
    return fmIsRepeatScanFunc(pCtx->functionId);
18,198✔
412
  }
413

414
  if (isRowEntryCompleted(pResInfo)) {
389,896,749✔
415
    return false;
58✔
416
  }
417

418
  return true;
389,896,691✔
419
}
420

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

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

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

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

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

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

UNCOV
468
  return TSDB_CODE_SUCCESS;
×
469
}
470

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

476
  SInputColumnInfoData* pInput = &pCtx->input;
8,177✔
477
  pInput->numOfRows = numOfRows;
8,177✔
478
  pInput->totalRows = numOfRows;
8,177✔
479

480
  if (pBlock->pBlockAgg != NULL) {
8,177!
481
    pInput->colDataSMAIsSet = true;
8,178✔
482

483
    for (int32_t j = 0; j < pExprInfo->base.numOfParams; ++j) {
16,356✔
484
      SFunctParam* pFuncParam = &pExprInfo->base.pParam[j];
8,178✔
485

486
      if (pFuncParam->type == FUNC_PARAM_TYPE_COLUMN) {
8,178!
487
        int32_t slotId = pFuncParam->pCol->slotId;
8,178✔
488
        pInput->pColumnDataAgg[j] = &pBlock->pBlockAgg[slotId];
8,178✔
489
        if (pInput->pColumnDataAgg[j]->colId == -1) {
8,178✔
490
          pInput->colDataSMAIsSet = false;
2,834✔
491
        }
492

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

505
_end:
8,177✔
506
  if (code != TSDB_CODE_SUCCESS) {
8,177!
507
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
×
508
  }
509
  return code;
8,178✔
510
}
511

512
/////////////////////////////////////////////////////////////////////////////////////////////
513
STimeWindow getAlignQueryTimeWindow(const SInterval* pInterval, int64_t key) {
26,449,625✔
514
  STimeWindow win = {0};
26,449,625✔
515
  win.skey = taosTimeTruncate(key, pInterval);
26,449,625✔
516

517
  /*
518
   * if the realSkey > INT64_MAX - pInterval->interval, the query duration between
519
   * realSkey and realEkey must be less than one interval.Therefore, no need to adjust the query ranges.
520
   */
521
  win.ekey = taosTimeGetIntervalEnd(win.skey, pInterval);
26,448,719✔
522
  if (win.ekey < win.skey) {
26,448,143✔
523
    win.ekey = INT64_MAX;
1,827✔
524
  }
525

526
  return win;
26,448,143✔
527
}
528

529
int32_t setResultRowInitCtx(SResultRow* pResult, SqlFunctionCtx* pCtx, int32_t numOfOutput,
121,275,677✔
530
                            int32_t* rowEntryInfoOffset) {
531
  bool init = false;
121,275,677✔
532
  for (int32_t i = 0; i < numOfOutput; ++i) {
688,318,374✔
533
    pCtx[i].resultInfo = getResultEntryInfo(pResult, i, rowEntryInfoOffset);
567,316,270✔
534
    if (init) {
567,243,253✔
535
      continue;
96,179,498✔
536
    }
537

538
    struct SResultRowEntryInfo* pResInfo = pCtx[i].resultInfo;
471,063,755✔
539
    if (isRowEntryCompleted(pResInfo) && isRowEntryInitialized(pResInfo)) {
471,063,755!
UNCOV
540
      continue;
×
541
    }
542

543
    if (pCtx[i].isPseudoFunc) {
471,063,755✔
544
      continue;
156,391,136✔
545
    }
546

547
    if (!pResInfo->initialized) {
314,672,619✔
548
      if (pCtx[i].functionId != -1) {
288,418,133✔
549
        int32_t code = pCtx[i].fpSet.init(&pCtx[i], pResInfo);
275,224,137✔
550
        if (code != TSDB_CODE_SUCCESS && fmIsUserDefinedFunc(pCtx[i].functionId)) {
275,243,783!
551
          pResInfo->initialized = false;
220,202✔
552
          qError("failed to initialize udf, funcId:%d error:%s", pCtx[i].functionId, tstrerror(code));
220,202!
553
          return TSDB_CODE_UDF_FUNC_EXEC_FAILURE;
×
554
        } else if (code != TSDB_CODE_SUCCESS) {
275,023,581!
555
          qError("failed to initialize function context, funcId:%d error:%s", pCtx[i].functionId, tstrerror(code));
×
556
          return code;
×
557
        }
558
      } else {
559
        pResInfo->initialized = true;
13,193,996✔
560
      }
561
    } else {
562
      init = true;
26,254,486✔
563
    }
564
  }
565
  return TSDB_CODE_SUCCESS;
121,002,104✔
566
}
567

568
void clearResultRowInitFlag(SqlFunctionCtx* pCtx, int32_t numOfOutput) {
66,182✔
569
  for (int32_t i = 0; i < numOfOutput; ++i) {
1,178,274✔
570
    SResultRowEntryInfo* pResInfo = pCtx[i].resultInfo;
1,112,092✔
571
    if (pResInfo == NULL) {
1,112,092!
572
      continue;
×
573
    }
574

575
    pResInfo->initialized = false;
1,112,092✔
576
    pResInfo->numOfRes = 0;
1,112,092✔
577
    pResInfo->isNullRes = 0;
1,112,092✔
578
    pResInfo->complete = false;
1,112,092✔
579
  }
580
}
66,182✔
581

582
int32_t doFilter(SSDataBlock* pBlock, SFilterInfo* pFilterInfo, SColMatchInfo* pColMatchInfo) {
10,247,628✔
583
  int32_t code = TSDB_CODE_SUCCESS;
10,247,628✔
584
  int32_t lino = 0;
10,247,628✔
585
  if (pFilterInfo == NULL || pBlock->info.rows == 0) {
10,247,628✔
586
    return TSDB_CODE_SUCCESS;
9,083,283✔
587
  }
588

589
  SFilterColumnParam param1 = {.numOfCols = taosArrayGetSize(pBlock->pDataBlock), .pDataBlock = pBlock->pDataBlock};
1,164,345✔
590
  SColumnInfoData*   p = NULL;
1,164,310✔
591

592
  code = filterSetDataFromSlotId(pFilterInfo, &param1);
1,164,310✔
593
  QUERY_CHECK_CODE(code, lino, _err);
1,164,241!
594

595
  int32_t status = 0;
1,164,241✔
596
  code = filterExecute(pFilterInfo, pBlock, &p, NULL, param1.numOfCols, &status);
1,164,241✔
597
  QUERY_CHECK_CODE(code, lino, _err);
1,164,243!
598

599
  code = extractQualifiedTupleByFilterResult(pBlock, p, status);
1,164,243✔
600
  QUERY_CHECK_CODE(code, lino, _err);
1,164,258!
601

602
  if (pColMatchInfo != NULL) {
1,164,258✔
603
    size_t size = taosArrayGetSize(pColMatchInfo->pList);
625,012✔
604
    for (int32_t i = 0; i < size; ++i) {
629,347✔
605
      SColMatchItem* pInfo = taosArrayGet(pColMatchInfo->pList, i);
627,752✔
606
      QUERY_CHECK_NULL(pInfo, code, lino, _err, terrno);
627,764!
607
      if (pInfo->colId == PRIMARYKEY_TIMESTAMP_COL_ID) {
627,764✔
608
        SColumnInfoData* pColData = taosArrayGet(pBlock->pDataBlock, pInfo->dstSlotId);
623,482✔
609
        QUERY_CHECK_NULL(pColData, code, lino, _err, terrno);
623,465!
610
        if (pColData->info.type == TSDB_DATA_TYPE_TIMESTAMP) {
623,490✔
611
          code = blockDataUpdateTsWindow(pBlock, pInfo->dstSlotId);
623,469✔
612
          QUERY_CHECK_CODE(code, lino, _err);
623,456!
613
          break;
623,456✔
614
        }
615
      }
616
    }
617
  }
618
  code = blockDataCheck(pBlock);
1,164,297✔
619
  QUERY_CHECK_CODE(code, lino, _err);
1,164,218!
620
_err:
1,164,218✔
621
  if (code != TSDB_CODE_SUCCESS) {
1,164,218!
622
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
×
623
  }
624
  colDataDestroy(p);
1,164,218✔
625
  taosMemoryFree(p);
1,164,420!
626
  return code;
1,164,494✔
627
}
628

629
int32_t extractQualifiedTupleByFilterResult(SSDataBlock* pBlock, const SColumnInfoData* p, int32_t status) {
1,164,325✔
630
  int32_t code = TSDB_CODE_SUCCESS;
1,164,325✔
631
  int8_t* pIndicator = (int8_t*)p->pData;
1,164,325✔
632
  if (status == FILTER_RESULT_ALL_QUALIFIED) {
1,164,325✔
633
    // here nothing needs to be done
634
  } else if (status == FILTER_RESULT_NONE_QUALIFIED) {
755,378✔
635
    code = trimDataBlock(pBlock, pBlock->info.rows, NULL);
88,592✔
636
    pBlock->info.rows = 0;
88,563✔
637
  } else if (status == FILTER_RESULT_PARTIAL_QUALIFIED) {
666,786!
638
    code = trimDataBlock(pBlock, pBlock->info.rows, (bool*)pIndicator);
666,844✔
639
  } else {
640
    qError("unknown filter result type: %d", status);
×
641
  }
642
  return code;
1,164,446✔
643
}
644

645
void doUpdateNumOfRows(SqlFunctionCtx* pCtx, SResultRow* pRow, int32_t numOfExprs, const int32_t* rowEntryOffset) {
87,846,023✔
646
  bool returnNotNull = false;
87,846,023✔
647
  for (int32_t j = 0; j < numOfExprs; ++j) {
489,503,085✔
648
    SResultRowEntryInfo* pResInfo = getResultEntryInfo(pRow, j, rowEntryOffset);
401,468,809✔
649
    if (!isRowEntryInitialized(pResInfo)) {
401,657,062✔
650
      continue;
112,958,321✔
651
    } else {
652
    }
653

654
    if (pRow->numOfRows < pResInfo->numOfRes) {
288,698,741✔
655
      pRow->numOfRows = pResInfo->numOfRes;
85,571,282✔
656
    }
657

658
    if (pCtx[j].isNotNullFunc) {
288,698,741✔
659
      returnNotNull = true;
96,515,275✔
660
    }
661
  }
662
  // if all expr skips all blocks, e.g. all null inputs for max function, output one row in final result.
663
  //  except for first/last, which require not null output, output no rows
664
  if (pRow->numOfRows == 0 && !returnNotNull) {
88,034,276✔
665
    pRow->numOfRows = 1;
29,733✔
666
  }
667
}
88,034,276✔
668

669
int32_t copyResultrowToDataBlock(SExprInfo* pExprInfo, int32_t numOfExprs, SResultRow* pRow, SqlFunctionCtx* pCtx,
76,088,556✔
670
                                 SSDataBlock* pBlock, const int32_t* rowEntryOffset, SExecTaskInfo* pTaskInfo) {
671
  int32_t code = TSDB_CODE_SUCCESS;
76,088,556✔
672
  int32_t lino = 0;
76,088,556✔
673
  for (int32_t j = 0; j < numOfExprs; ++j) {
416,483,454✔
674
    int32_t slotId = pExprInfo[j].base.resSchema.slotId;
339,221,137✔
675

676
    pCtx[j].resultInfo = getResultEntryInfo(pRow, j, rowEntryOffset);
339,221,137✔
677
    if (pCtx[j].fpSet.finalize) {
339,496,465✔
678
      if (strcmp(pCtx[j].pExpr->pExpr->_function.functionName, "_group_key") == 0 ||
236,886,554✔
679
          strcmp(pCtx[j].pExpr->pExpr->_function.functionName, "_group_const_value") == 0) {
167,828,084✔
680
        // for groupkey along with functions that output multiple lines(e.g. Histogram)
681
        // need to match groupkey result for each output row of that function.
682
        if (pCtx[j].resultInfo->numOfRes != 0) {
69,058,677!
683
          pCtx[j].resultInfo->numOfRes = pRow->numOfRows;
69,914,056✔
684
        }
685
      }
686

687
      code = blockDataEnsureCapacity(pBlock, pBlock->info.rows + pCtx[j].resultInfo->numOfRes);
236,886,554✔
688
      QUERY_CHECK_CODE(code, lino, _end);
236,690,452!
689

690
      code = pCtx[j].fpSet.finalize(&pCtx[j], pBlock);
236,690,452✔
691
      if (TSDB_CODE_SUCCESS != code) {
239,097,929!
692
        qError("%s build result data block error, code %s", GET_TASKID(pTaskInfo), tstrerror(code));
×
693
        QUERY_CHECK_CODE(code, lino, _end);
×
694
      }
695
    } else if (strcmp(pCtx[j].pExpr->pExpr->_function.functionName, "_select_value") == 0) {
102,609,911!
696
      // do nothing
697
    } else {
698
      // expand the result into multiple rows. E.g., _wstart, top(k, 20)
699
      // the _wstart needs to copy to 20 following rows, since the results of top-k expands to 20 different rows.
700
      SColumnInfoData* pColInfoData = taosArrayGet(pBlock->pDataBlock, slotId);
106,571,263✔
701
      QUERY_CHECK_NULL(pColInfoData, code, lino, _end, terrno);
106,289,735!
702
      char*            in = GET_ROWCELL_INTERBUF(pCtx[j].resultInfo);
106,326,448✔
703
      for (int32_t k = 0; k < pRow->numOfRows; ++k) {
212,755,404✔
704
        code = colDataSetValOrCover(pColInfoData, pBlock->info.rows + k, in, pCtx[j].resultInfo->isNullRes);
106,184,821✔
705
        QUERY_CHECK_CODE(code, lino, _end);
106,428,956!
706
      }
707
    }
708
  }
709

710
_end:
77,262,317✔
711
  if (code != TSDB_CODE_SUCCESS) {
77,262,317!
712
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
×
713
  }
714
  return code;
77,462,375✔
715
}
716

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

726
  SResultRow* pRow = (SResultRow*)((char*)page + resultRowPosition->offset);
11,296,481✔
727

728
  SqlFunctionCtx* pCtx = pSup->pCtx;
11,296,481✔
729
  SExprInfo*      pExprInfo = pSup->pExprInfo;
11,296,481✔
730
  const int32_t*  rowEntryOffset = pSup->rowEntryInfoOffset;
11,296,481✔
731

732
  doUpdateNumOfRows(pCtx, pRow, pSup->numOfExprs, rowEntryOffset);
11,296,481✔
733
  if (pRow->numOfRows == 0) {
11,289,136✔
734
    releaseBufPage(pBuf, page);
516✔
735
    return;
×
736
  }
737

738
  int32_t size = pBlock->info.capacity;
11,288,620✔
739
  while (pBlock->info.rows + pRow->numOfRows > size) {
11,292,273✔
740
    size = size * 1.25;
3,653✔
741
  }
742

743
  int32_t code = blockDataEnsureCapacity(pBlock, size);
11,288,620✔
744
  if (TAOS_FAILED(code)) {
11,289,487!
745
    releaseBufPage(pBuf, page);
×
746
    qError("%s ensure result data capacity failed, code %s", GET_TASKID(pTaskInfo), tstrerror(code));
×
747
    T_LONG_JMP(pTaskInfo->env, code);
×
748
  }
749

750
  code = copyResultrowToDataBlock(pExprInfo, pSup->numOfExprs, pRow, pCtx, pBlock, rowEntryOffset, pTaskInfo);
11,289,487✔
751
  if (TAOS_FAILED(code)) {
11,287,649!
752
    releaseBufPage(pBuf, page);
×
753
    qError("%s copy result row to datablock failed, code %s", GET_TASKID(pTaskInfo), tstrerror(code));
×
754
    T_LONG_JMP(pTaskInfo->env, code);
×
755
  }
756

757
  releaseBufPage(pBuf, page);
11,287,649✔
758
  pBlock->info.rows += pRow->numOfRows;
11,279,220✔
759
}
760

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

770
  size_t  keyLen = 0;
1,344,709✔
771
  int32_t numOfRows = tSimpleHashGetSize(pHashmap);
1,344,709✔
772

773
  // begin from last iter
774
  void*   pData = pGroupResInfo->dataPos;
1,340,626✔
775
  int32_t iter = pGroupResInfo->iter;
1,340,626✔
776
  while ((pData = tSimpleHashIterate(pHashmap, pData, &iter)) != NULL) {
6,216,424✔
777
    void*               key = tSimpleHashGetKey(pData, &keyLen);
5,967,230✔
778
    SResultRowPosition* pos = pData;
5,967,230✔
779
    uint64_t            groupId = *(uint64_t*)key;
5,967,230✔
780

781
    SFilePage* page = getBufPage(pBuf, pos->pageId);
5,967,230✔
782
    if (page == NULL) {
5,958,872!
783
      qError("failed to get buffer, code:%s, %s", tstrerror(terrno), GET_TASKID(pTaskInfo));
×
784
      T_LONG_JMP(pTaskInfo->env, terrno);
×
785
    }
786

787
    SResultRow* pRow = (SResultRow*)((char*)page + pos->offset);
5,958,872✔
788

789
    doUpdateNumOfRows(pCtx, pRow, numOfExprs, rowEntryOffset);
5,958,872✔
790

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

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

801
    if (!ignoreGroup) {
5,924,987✔
802
      if (pBlock->info.id.groupId == 0) {
2,164,871✔
803
        pBlock->info.id.groupId = groupId;
1,112,159✔
804
      } else {
805
        // current value belongs to different group, it can't be packed into one datablock
806
        if (pBlock->info.id.groupId != groupId) {
1,052,712!
807
          releaseBufPage(pBuf, page);
1,072,764✔
808
          break;
1,072,219✔
809
        }
810
      }
811
    }
812

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

822
    pGroupResInfo->index += 1;
4,852,223✔
823
    pGroupResInfo->iter = iter;
4,852,223✔
824
    pGroupResInfo->dataPos = pData;
4,852,223✔
825

826
    code = copyResultrowToDataBlock(pExprInfo, numOfExprs, pRow, pCtx, pBlock, rowEntryOffset, pTaskInfo);
4,852,223✔
827
    releaseBufPage(pBuf, page);
4,878,627✔
828
    QUERY_CHECK_CODE(code, lino, _end);
4,875,838!
829
    pBlock->info.rows += pRow->numOfRows;
4,875,838✔
830
    if (pBlock->info.rows >= threshold) {
4,875,838✔
831
      break;
40✔
832
    }
833
  }
834

835
  qDebug("%s result generated, rows:%" PRId64 ", groupId:%" PRIu64, GET_TASKID(pTaskInfo), pBlock->info.rows,
1,322,571✔
836
         pBlock->info.id.groupId);
837
  pBlock->info.dataLoad = 1;
1,322,573✔
838
  code = blockDataUpdateTsWindow(pBlock, 0);
1,322,573✔
839
  QUERY_CHECK_CODE(code, lino, _end);
1,321,098!
840

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

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

857
  int32_t numOfRows = getNumOfTotalRes(pGroupResInfo);
1,229,576✔
858

859
  for (int32_t i = pGroupResInfo->index; i < numOfRows; i += 1) {
61,869,429✔
860
    SResKeyPos* pPos = taosArrayGetP(pGroupResInfo->pRows, i);
60,921,123✔
861
    SFilePage*  page = getBufPage(pBuf, pPos->pos.pageId);
60,681,525✔
862
    if (page == NULL) {
60,626,967!
863
      qError("failed to get buffer, code:%s, %s", tstrerror(terrno), GET_TASKID(pTaskInfo));
×
864
      T_LONG_JMP(pTaskInfo->env, terrno);
×
865
    }
866

867
    SResultRow* pRow = (SResultRow*)((char*)page + pPos->pos.offset);
60,626,967✔
868

869
    doUpdateNumOfRows(pCtx, pRow, numOfExprs, rowEntryOffset);
60,626,967✔
870

871
    // no results, continue to check the next one
872
    if (pRow->numOfRows == 0) {
59,605,818✔
873
      pGroupResInfo->index += 1;
686✔
874
      releaseBufPage(pBuf, page);
686✔
875
      continue;
686✔
876
    }
877

878
    if (!ignoreGroup) {
59,605,132✔
879
      if (pBlock->info.id.groupId == 0) {
32,654,347✔
880
        pBlock->info.id.groupId = pPos->groupId;
18,110,229✔
881
      } else {
882
        // current value belongs to different group, it can't be packed into one datablock
883
        if (pBlock->info.id.groupId != pPos->groupId) {
14,544,118✔
884
          releaseBufPage(pBuf, page);
120,910✔
885
          break;
120,901✔
886
        }
887
      }
888
    }
889

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

899
    pGroupResInfo->index += 1;
59,484,222✔
900
    code = copyResultrowToDataBlock(pExprInfo, numOfExprs, pRow, pCtx, pBlock, rowEntryOffset, pTaskInfo);
59,484,222✔
901
    releaseBufPage(pBuf, page);
61,385,376✔
902
    QUERY_CHECK_CODE(code, lino, _end);
60,785,317!
903

904
    pBlock->info.rows += pRow->numOfRows;
60,785,317✔
905
    if (pBlock->info.rows >= threshold) {
60,785,317✔
906
      break;
146,336✔
907
    }
908
  }
909

910
  qDebug("%s result generated, rows:%" PRId64 ", groupId:%" PRIu64, GET_TASKID(pTaskInfo), pBlock->info.rows,
1,215,543✔
911
         pBlock->info.id.groupId);
912
  pBlock->info.dataLoad = 1;
1,215,543✔
913
  code = blockDataUpdateTsWindow(pBlock, 0);
1,215,543✔
914
  QUERY_CHECK_CODE(code, lino, _end);
1,229,694!
915

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

923
void doBuildResultDatablock(SOperatorInfo* pOperator, SOptrBasicInfo* pbInfo, SGroupResInfo* pGroupResInfo,
1,342,941✔
924
                            SDiskbasedBuf* pBuf) {
925
  SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
1,342,941✔
926
  SSDataBlock*   pBlock = pbInfo->pRes;
1,342,941✔
927

928
  // set output datablock version
929
  pBlock->info.version = pTaskInfo->version;
1,342,941✔
930

931
  blockDataCleanup(pBlock);
1,342,941✔
932
  if (!hasRemainResults(pGroupResInfo)) {
1,343,755✔
933
    return;
113,480✔
934
  }
935

936
  // clear the existed group id
937
  pBlock->info.id.groupId = 0;
1,229,566✔
938
  if (!pbInfo->mergeResultBlock) {
1,229,566✔
939
    doCopyToSDataBlock(pTaskInfo, pBlock, &pOperator->exprSupp, pBuf, pGroupResInfo, pOperator->resultInfo.threshold,
542,454✔
940
                       false);
941
  } else {
942
    while (hasRemainResults(pGroupResInfo)) {
1,305,465✔
943
      doCopyToSDataBlock(pTaskInfo, pBlock, &pOperator->exprSupp, pBuf, pGroupResInfo, pOperator->resultInfo.threshold,
687,293✔
944
                         true);
945
      if (pBlock->info.rows >= pOperator->resultInfo.threshold) {
687,733✔
946
        break;
69,380✔
947
      }
948

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

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

958
void destroyExprInfo(SExprInfo* pExpr, int32_t numOfExprs) {
2,859,054✔
959
  for (int32_t i = 0; i < numOfExprs; ++i) {
9,459,623✔
960
    SExprInfo* pExprInfo = &pExpr[i];
6,599,610✔
961
    for (int32_t j = 0; j < pExprInfo->base.numOfParams; ++j) {
13,851,466✔
962
      if (pExprInfo->base.pParam[j].type == FUNC_PARAM_TYPE_COLUMN) {
7,251,852✔
963
        taosMemoryFreeClear(pExprInfo->base.pParam[j].pCol);
5,802,808!
964
      } else if (pExprInfo->base.pParam[j].type == FUNC_PARAM_TYPE_VALUE) {
1,449,044✔
965
        taosVariantDestroy(&pExprInfo->base.pParam[j].param);
868,398✔
966
      }
967
    }
968

969
    taosMemoryFree(pExprInfo->base.pParam);
6,599,614!
970
    taosMemoryFree(pExprInfo->pExpr);
6,600,178!
971
  }
972
}
2,860,013✔
973

974
int32_t getBufferPgSize(int32_t rowSize, uint32_t* defaultPgsz, int64_t* defaultBufsz) {
2,084,828✔
975
  *defaultPgsz = 4096;
2,084,828✔
976
  uint32_t last = *defaultPgsz;
2,084,828✔
977
  while (*defaultPgsz < rowSize * 4) {
2,544,751✔
978
    *defaultPgsz <<= 1u;
459,923✔
979
    if (*defaultPgsz < last) {
459,923!
980
      return TSDB_CODE_INVALID_PARA;
×
981
    }
982
    last = *defaultPgsz;
459,923✔
983
  }
984

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

996
  return 0;
2,084,828✔
997
}
998

999
void initResultSizeInfo(SResultInfo* pResultInfo, int32_t numOfRows) {
3,970,905✔
1000
  if (numOfRows == 0) {
3,970,905!
1001
    numOfRows = 4096;
×
1002
  }
1003

1004
  pResultInfo->capacity = numOfRows;
3,970,905✔
1005
  pResultInfo->threshold = numOfRows * 0.75;
3,970,905✔
1006

1007
  if (pResultInfo->threshold == 0) {
3,970,905✔
1008
    pResultInfo->threshold = numOfRows;
2,492✔
1009
  }
1010
}
3,970,905✔
1011

1012
void initBasicInfo(SOptrBasicInfo* pInfo, SSDataBlock* pBlock) {
2,066,716✔
1013
  pInfo->pRes = pBlock;
2,066,716✔
1014
  initResultRowInfo(&pInfo->resultRowInfo);
2,066,716✔
1015
}
2,066,588✔
1016

1017
static void destroySqlFunctionCtx(SqlFunctionCtx* pCtx, SExprInfo* pExpr, int32_t numOfOutput) {
7,531,192✔
1018
  if (pCtx == NULL) {
7,531,192✔
1019
    return;
4,503,070✔
1020
  }
1021

1022
  for (int32_t i = 0; i < numOfOutput; ++i) {
9,398,212✔
1023
    if (pExpr != NULL) {
6,368,435!
1024
      SExprInfo* pExprInfo = &pExpr[i];
6,369,222✔
1025
      for (int32_t j = 0; j < pExprInfo->base.numOfParams; ++j) {
13,389,496✔
1026
        if (pExprInfo->base.pParam[j].type == FUNC_PARAM_TYPE_VALUE) {
7,020,464✔
1027
          taosMemoryFree(pCtx[i].input.pData[j]);
864,419!
1028
          taosMemoryFree(pCtx[i].input.pColumnDataAgg[j]);
864,420!
1029
        }
1030
      }
1031
    }
1032
    for (int32_t j = 0; j < pCtx[i].numOfParams; ++j) {
13,388,954✔
1033
      taosVariantDestroy(&pCtx[i].param[j].param);
7,020,472✔
1034
    }
1035

1036
    taosMemoryFreeClear(pCtx[i].subsidiaries.pCtx);
6,368,482✔
1037
    taosMemoryFreeClear(pCtx[i].subsidiaries.buf);
6,368,480!
1038
    taosMemoryFree(pCtx[i].input.pData);
6,368,480✔
1039
    taosMemoryFree(pCtx[i].input.pColumnDataAgg);
6,369,482!
1040

1041
    if (pCtx[i].udfName != NULL) {
6,370,174✔
1042
      taosMemoryFree(pCtx[i].udfName);
32!
1043
    }
1044
  }
1045

1046
  taosMemoryFreeClear(pCtx);
3,029,777!
1047
  return;
3,029,803✔
1048
}
1049

1050
int32_t initExprSupp(SExprSupp* pSup, SExprInfo* pExprInfo, int32_t numOfExpr, SFunctionStateStore* pStore) {
3,405,399✔
1051
  pSup->pExprInfo = pExprInfo;
3,405,399✔
1052
  pSup->numOfExprs = numOfExpr;
3,405,399✔
1053
  if (pSup->pExprInfo != NULL) {
3,405,399✔
1054
    pSup->pCtx = createSqlFunctionCtx(pExprInfo, numOfExpr, &pSup->rowEntryInfoOffset, pStore);
2,406,884✔
1055
    if (pSup->pCtx == NULL) {
2,405,786!
1056
      return terrno;
×
1057
    }
1058
  }
1059

1060
  return TSDB_CODE_SUCCESS;
3,405,825✔
1061
}
1062

1063
void cleanupExprSupp(SExprSupp* pSupp) {
7,531,378✔
1064
  destroySqlFunctionCtx(pSupp->pCtx, pSupp->pExprInfo, pSupp->numOfExprs);
7,531,378✔
1065
  if (pSupp->pExprInfo != NULL) {
7,531,075✔
1066
    destroyExprInfo(pSupp->pExprInfo, pSupp->numOfExprs);
2,854,649✔
1067
    taosMemoryFreeClear(pSupp->pExprInfo);
2,854,586!
1068
  }
1069

1070
  if (pSupp->pFilterInfo != NULL) {
7,531,171✔
1071
    filterFreeInfo(pSupp->pFilterInfo);
369,202✔
1072
    pSupp->pFilterInfo = NULL;
369,219✔
1073
  }
1074

1075
  taosMemoryFree(pSupp->rowEntryInfoOffset);
7,531,188!
1076
}
7,527,661✔
1077

1078
void cleanupBasicInfo(SOptrBasicInfo* pInfo) {
2,091,618✔
1079
  blockDataDestroy(pInfo->pRes);
2,091,618✔
1080
  pInfo->pRes = NULL;
2,093,579✔
1081
}
2,093,579✔
1082

1083
bool groupbyTbname(SNodeList* pGroupList) {
1,045,934✔
1084
  bool bytbname = false;
1,045,934✔
1085
  SNode*pNode = NULL;
1,045,934✔
1086
  FOREACH(pNode, pGroupList) {
1,095,589✔
1087
    if (pNode->type == QUERY_NODE_FUNCTION) {
257,865✔
1088
      bytbname = (strcmp(((struct SFunctionNode*)pNode)->functionName, "tbname") == 0);
208,210✔
1089
      break;
208,210✔
1090
    }
1091
  }
1092
  return bytbname;
1,045,934✔
1093
}
1094

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

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

1113
      SArray* pInfoList = NULL;
34,981✔
1114
      int32_t code = getTableListInfo(pTask, &pInfoList);
34,981✔
1115
      if (code != TSDB_CODE_SUCCESS || pInfoList == NULL) {
34,981!
1116
        taosMemoryFree(pDeleterParam);
1!
1117
        return code;
×
1118
      }
1119

1120
      STableListInfo* pTableListInfo = taosArrayGetP(pInfoList, 0);
34,980✔
1121
      taosArrayDestroy(pInfoList);
34,980✔
1122

1123
      pDeleterParam->suid = tableListGetSuid(pTableListInfo);
34,981✔
1124

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

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

1140
      for (int32_t i = 0; i < numOfTables; ++i) {
82,917✔
1141
        STableKeyInfo* pTable = tableListGetInfo(pTableListInfo, i);
47,936✔
1142
        if (!pTable) {
47,937!
1143
          taosArrayDestroy(pDeleterParam->pUidList);
×
1144
          taosMemoryFree(pDeleterParam);
×
1145
          return TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR;
×
1146
        }
1147
        void*          tmp = taosArrayPush(pDeleterParam->pUidList, &pTable->uid);
47,937✔
1148
        if (!tmp) {
47,937!
1149
          taosArrayDestroy(pDeleterParam->pUidList);
×
1150
          taosMemoryFree(pDeleterParam);
×
1151
          return terrno;
×
1152
        }
1153
      }
1154

1155
      *pParam = pDeleterParam;
34,981✔
1156
      break;
34,981✔
1157
    }
1158
    default:
2,137,246✔
1159
      break;
2,137,246✔
1160
  }
1161

1162
  return TSDB_CODE_SUCCESS;
2,172,326✔
1163
}
1164

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

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

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

1186
  taosArrayDestroy(pParam->pChildren);
65,125✔
1187

1188
  taosMemoryFree(pParam->value);
65,125!
1189

1190
  taosMemoryFree(pParam);
65,125!
1191
}
65,125✔
1192

1193
void freeExchangeGetBasicOperatorParam(void* pParam) {
902✔
1194
  SExchangeOperatorBasicParam* pBasic = (SExchangeOperatorBasicParam*)pParam;
902✔
1195
  taosArrayDestroy(pBasic->uidList);
902✔
1196
}
902✔
1197

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

1207
  freeOperatorParamImpl(pParam, OP_GET_PARAM);
538✔
1208
}
538✔
1209

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

1212
void freeGroupCacheGetOperatorParam(SOperatorParam* pParam) { freeOperatorParamImpl(pParam, OP_GET_PARAM); }
41,854✔
1213

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

1216
void freeMergeJoinGetOperatorParam(SOperatorParam* pParam) { freeOperatorParamImpl(pParam, OP_GET_PARAM); }
20,927✔
1217

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

1220
void freeTableScanGetOperatorParam(SOperatorParam* pParam) {
1,806✔
1221
  STableScanOperatorParam* pTableScanParam = (STableScanOperatorParam*)pParam->value;
1,806✔
1222
  taosArrayDestroy(pTableScanParam->pUidList);
1,806✔
1223
  freeOperatorParamImpl(pParam, OP_GET_PARAM);
1,806✔
1224
}
1,806✔
1225

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

1228
void freeOperatorParam(SOperatorParam* pParam, SOperatorParamType type) {
1,463,534✔
1229
  if (NULL == pParam) {
1,463,534✔
1230
    return;
1,398,485✔
1231
  }
1232

1233
  switch (pParam->opType) {
65,049!
1234
    case QUERY_NODE_PHYSICAL_PLAN_EXCHANGE:
538✔
1235
      type == OP_GET_PARAM ? freeExchangeGetOperatorParam(pParam) : freeExchangeNotifyOperatorParam(pParam);
538!
1236
      break;
538✔
1237
    case QUERY_NODE_PHYSICAL_PLAN_GROUP_CACHE:
41,854✔
1238
      type == OP_GET_PARAM ? freeGroupCacheGetOperatorParam(pParam) : freeGroupCacheNotifyOperatorParam(pParam);
41,854!
1239
      break;
41,854✔
1240
    case QUERY_NODE_PHYSICAL_PLAN_MERGE_JOIN:
20,927✔
1241
      type == OP_GET_PARAM ? freeMergeJoinGetOperatorParam(pParam) : freeMergeJoinNotifyOperatorParam(pParam);
20,927!
1242
      break;
20,927✔
1243
    case QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN:
1,806✔
1244
      type == OP_GET_PARAM ? freeTableScanGetOperatorParam(pParam) : freeTableScanNotifyOperatorParam(pParam);
1,806!
1245
      break;
1,806✔
1246
    default:
×
1247
      qError("unsupported op %d param, type %d", pParam->opType, type);
×
1248
      break;
×
1249
  }
1250
}
1251

1252
void freeResetOperatorParams(struct SOperatorInfo* pOperator, SOperatorParamType type, bool allFree) {
9,935,799✔
1253
  SOperatorParam**  ppParam = NULL;
9,935,799✔
1254
  SOperatorParam*** pppDownstramParam = NULL;
9,935,799✔
1255
  switch (type) {
9,935,799!
1256
    case OP_GET_PARAM:
4,979,583✔
1257
      ppParam = &pOperator->pOperatorGetParam;
4,979,583✔
1258
      pppDownstramParam = &pOperator->pDownstreamGetParams;
4,979,583✔
1259
      break;
4,979,583✔
1260
    case OP_NOTIFY_PARAM:
4,958,541✔
1261
      ppParam = &pOperator->pOperatorNotifyParam;
4,958,541✔
1262
      pppDownstramParam = &pOperator->pDownstreamNotifyParams;
4,958,541✔
1263
      break;
4,958,541✔
1264
    default:
×
1265
      return;
×
1266
  }
1267

1268
  if (*ppParam) {
9,938,124✔
1269
    freeOperatorParam(*ppParam, type);
20,927✔
1270
    *ppParam = NULL;
20,927✔
1271
  }
1272

1273
  if (*pppDownstramParam) {
9,938,124✔
1274
    for (int32_t i = 0; i < pOperator->numOfDownstream; ++i) {
64,223✔
1275
      if ((*pppDownstramParam)[i]) {
41,854!
1276
        freeOperatorParam((*pppDownstramParam)[i], type);
×
1277
        (*pppDownstramParam)[i] = NULL;
×
1278
      }
1279
    }
1280
    if (allFree) {
22,369✔
1281
      taosMemoryFreeClear(*pppDownstramParam);
1,652!
1282
    }
1283
  }
1284
}
1285

1286
FORCE_INLINE int32_t getNextBlockFromDownstreamImpl(struct SOperatorInfo* pOperator, int32_t idx, bool clearParam,
9,565,648✔
1287
                                                    SSDataBlock** pResBlock) {
1288
  QRY_PARAM_CHECK(pResBlock);
9,565,648!
1289

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

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

1306
  code = pOperator->pDownstream[idx]->fpSet.getNextFn(pOperator->pDownstream[idx], pResBlock);
9,502,544✔
1307
  if (code) {
9,509,370!
1308
    qError("failed to get next data block from upstream at %s, %d code:%s", __func__, __LINE__, tstrerror(code));
×
1309
  }
1310
  return code;
9,509,599✔
1311
}
1312

1313
bool compareVal(const char* v, const SStateKeys* pKey) {
125,787✔
1314
  if (IS_VAR_DATA_TYPE(pKey->type)) {
125,787!
1315
    if (varDataLen(v) != varDataLen(pKey->pData)) {
978!
1316
      return false;
×
1317
    } else {
1318
      return memcmp(varDataVal(v), varDataVal(pKey->pData), varDataLen(v)) == 0;
978✔
1319
    }
1320
  } else {
1321
    return memcmp(pKey->pData, v, pKey->bytes) == 0;
124,809✔
1322
  }
1323
}
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