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

taosdata / TDengine / #3532

20 Nov 2024 07:11AM UTC coverage: 60.78% (+0.6%) from 60.213%
#3532

push

travis-ci

web-flow
Merge pull request #28823 from taosdata/fix/3.0/TD-32587

fix:[TD-32587]fix stmt segmentation fault

119943 of 252352 branches covered (47.53%)

Branch coverage included in aggregate %.

1 of 4 new or added lines in 1 file covered. (25.0%)

463 existing lines in 99 files now uncovered.

200682 of 275165 relevant lines covered (72.93%)

15642683.31 hits per line

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

66.98
/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) {
225,889,832✔
86
  SFilePage* pData = NULL;
225,889,832✔
87

88
  // in the first scan, new space needed for results
89
  int32_t pageId = -1;
225,889,832✔
90
  if (*currentPageId == -1) {
225,889,832✔
91
    pData = getNewBufPage(pResultBuf, &pageId);
3,897,123✔
92
    if (pData == NULL) {
3,897,416✔
93
      qError("failed to get buffer, code:%s", tstrerror(terrno));
133!
94
      return NULL;
×
95
    }
96
    pData->num = sizeof(SFilePage);
3,897,283✔
97
  } else {
98
    pData = getBufPage(pResultBuf, *currentPageId);
221,992,709✔
99
    if (pData == NULL) {
222,376,682!
100
      qError("failed to get buffer, code:%s", tstrerror(terrno));
×
101
      return NULL;
×
102
    }
103

104
    pageId = *currentPageId;
222,376,682✔
105

106
    if (pData->num + interBufSize > getBufPageSize(pResultBuf)) {
222,376,682✔
107
      // release current page first, and prepare the next one
108
      releaseBufPage(pResultBuf, pData);
17,572,383✔
109

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

119
  if (pData == NULL) {
226,339,449!
120
    return NULL;
×
121
  }
122

123
  setBufPageDirty(pData, true);
226,339,449✔
124

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

128
  memset((char*)pResultRow, 0, interBufSize);
225,955,427✔
129
  pResultRow->pageId = pageId;
225,955,427✔
130
  pResultRow->offset = (int32_t)pData->num;
225,955,427✔
131

132
  *currentPageId = pageId;
225,955,427✔
133
  pData->num += interBufSize;
225,955,427✔
134
  return pResultRow;
225,955,427✔
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,
279,042,606✔
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);
279,042,606✔
148
  if (!keepGroup) {
279,042,606✔
149
    *(uint64_t*)pSup->keyBuf = calcGroupId(pSup->keyBuf, GET_RES_WINDOW_KEY_LEN(bytes));
16,834,008✔
150
  }
151

152
  SResultRowPosition* p1 =
153
      (SResultRowPosition*)tSimpleHashGet(pSup->pResultRowHashTable, pSup->keyBuf, GET_RES_WINDOW_KEY_LEN(bytes));
279,351,024✔
154

155
  SResultRow* pResult = NULL;
278,790,271✔
156

157
  // in case of repeat scan/reverse scan, no new time window added.
158
  if (isIntervalQuery) {
278,790,271✔
159
    if (p1 != NULL) {  // the *p1 may be NULL in case of sliding+offset exists.
258,304,057✔
160
      pResult = getResultRowByPos(pResultBuf, p1, true);
45,336,519✔
161
      if (pResult == NULL) {
45,336,519!
162
        pTaskInfo->code = terrno;
×
163
        return NULL;
×
164
      }
165

166
      if (pResult->pageId != p1->pageId || pResult->offset != p1->offset) {
45,336,519!
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) {
20,486,214✔
176
      // todo
177
      pResult = getResultRowByPos(pResultBuf, p1, true);
6,410,174✔
178
      if (NULL == pResult) {
6,410,174!
179
        pTaskInfo->code = terrno;
×
180
        return NULL;
×
181
      }
182

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

191
  // 1. close current opened time window
192
  if (pResultRowInfo->cur.pageId != -1 && ((pResult == NULL) || (pResult->pageId != pResultRowInfo->cur.pageId))) {
278,528,406✔
193
    SResultRowPosition pos = pResultRowInfo->cur;
226,869,185✔
194
    SFilePage*         pPage = getBufPage(pResultBuf, pos.pageId);
226,869,185✔
195
    if (pPage == NULL) {
226,214,767!
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);
226,214,767✔
201
  }
202

203
  // allocate a new buffer page
204
  if (pResult == NULL) {
276,989,347✔
205
    pResult = getNewResultRow(pResultBuf, &pSup->currentPageId, pSup->resultRowSize);
225,521,956✔
206
    if (pResult == NULL) {
225,840,696!
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};
225,840,696✔
213
    int32_t code = tSimpleHashPut(pSup->pResultRowHashTable, pSup->keyBuf, GET_RES_WINDOW_KEY_LEN(bytes), &pos,
225,840,696✔
214
                                  sizeof(SResultRowPosition));
215
    if (code != TSDB_CODE_SUCCESS) {
228,747,710✔
216
      qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(code));
83,596!
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};
280,131,505✔
224

225
  // too many time window in query
226
  if (pTaskInfo->execModel == OPTR_EXEC_MODEL_BATCH &&
559,687,431!
227
      tSimpleHashGetSize(pSup->pResultRowHashTable) > MAX_INTERVAL_TIME_WINDOW) {
280,074,935✔
228
    pTaskInfo->code = TSDB_CODE_QRY_TOO_MANY_TIMEWINDOW;
×
229
    return NULL;
×
230
  }
231

232
  return pResult;
279,612,496✔
233
}
234

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

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

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

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

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

274
int32_t setInputDataBlock(SExprSupp* pExprSup, SSDataBlock* pBlock, int32_t order, int32_t scanFlag,
15,013,208✔
275
                          bool createDummyCol) {
276
  if (pBlock->pBlockAgg != NULL) {
15,013,208✔
277
    return doSetInputDataBlockInfo(pExprSup, pBlock, order, scanFlag);
9,381✔
278
  } else {
279
    return doSetInputDataBlock(pExprSup, pBlock, order, scanFlag, createDummyCol);
15,003,827✔
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,
15,003,745✔
335
                                   bool createDummyCol) {
336
  int32_t         code = TSDB_CODE_SUCCESS;
15,003,745✔
337
  int32_t         lino = 0;
15,003,745✔
338
  SqlFunctionCtx* pCtx = pExprSup->pCtx;
15,003,745✔
339

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

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

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

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

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

358
    for (int32_t j = 0; j < pOneExpr->base.numOfParams; ++j) {
117,240,937✔
359
      SFunctParam* pFuncParam = &pOneExpr->base.pParam[j];
61,128,143✔
360
      if (pFuncParam->type == FUNC_PARAM_TYPE_COLUMN) {
61,128,143✔
361
        int32_t slotId = pFuncParam->pCol->slotId;
55,588,420✔
362
        pInput->pData[j] = taosArrayGet(pBlock->pDataBlock, slotId);
55,588,420✔
363
        pInput->totalRows = pBlock->info.rows;
55,585,876✔
364
        pInput->numOfRows = pBlock->info.rows;
55,585,876✔
365
        pInput->startRowIndex = 0;
55,585,876✔
366
        pInput->blankFill = pBlock->info.blankFill;
55,585,876✔
367

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

371
        if (fmIsImplicitTsFunc(pCtx[i].functionId) && (j == tsParamIdx)) {
55,585,876✔
372
          pInput->pPTS = pInput->pData[j];  // in case of merge function, this is not always the ts column data.
4,907,809✔
373
        }
374
        if (hasPk && (j == pkParamIdx)) {
55,586,415✔
375
          pInput->pPrimaryKey = pInput->pData[j];
617,587✔
376
        }
377
        QUERY_CHECK_CONDITION((pInput->pData[j] != NULL), code, lino, _end, TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR);
55,586,415!
378
      } else if (pFuncParam->type == FUNC_PARAM_TYPE_VALUE) {
5,539,723✔
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,910,537!
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:
15,001,740✔
395
  if (code != TSDB_CODE_SUCCESS) {
15,001,740!
396
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
×
397
  }
398
  return code;
15,005,037✔
399
}
400

401
bool functionNeedToExecute(SqlFunctionCtx* pCtx) {
904,542,394✔
402
  struct SResultRowEntryInfo* pResInfo = GET_RES_INFO(pCtx);
904,542,394✔
403

404
  // in case of timestamp column, always generated results.
405
  int32_t functionId = pCtx->functionId;
904,542,394✔
406
  if (functionId == -1) {
904,542,394✔
407
    return false;
51,068,031✔
408
  }
409

410
  if (pCtx->scanFlag == PRE_SCAN) {
853,474,363✔
411
    return fmIsRepeatScanFunc(pCtx->functionId);
19,308✔
412
  }
413

414
  if (isRowEntryCompleted(pResInfo)) {
853,455,055✔
415
    return false;
4,128✔
416
  }
417

418
  return true;
853,450,927✔
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,389✔
475
  int32_t code = TSDB_CODE_SUCCESS;
9,389✔
476
  int32_t lino = 0;
9,389✔
477
  int32_t numOfRows = pBlock->info.rows;
9,389✔
478

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

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

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

489
      if (pFuncParam->type == FUNC_PARAM_TYPE_COLUMN) {
9,389!
490
        int32_t slotId = pFuncParam->pCol->slotId;
9,389✔
491
        pInput->pColumnDataAgg[j] = &pBlock->pBlockAgg[slotId];
9,389✔
492
        if (pInput->pColumnDataAgg[j]->colId == -1) {
9,389✔
493
          pInput->colDataSMAIsSet = false;
1,076✔
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,389✔
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 {
UNCOV
505
    pInput->colDataSMAIsSet = false;
×
506
  }
507

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

515
/////////////////////////////////////////////////////////////////////////////////////////////
516
STimeWindow getAlignQueryTimeWindow(const SInterval* pInterval, int64_t key) {
23,136,650✔
517
  STimeWindow win = {0};
23,136,650✔
518
  win.skey = taosTimeTruncate(key, pInterval);
23,136,650✔
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);
23,136,600✔
525
  if (win.ekey < win.skey) {
23,136,552✔
526
    win.ekey = INT64_MAX;
2,080✔
527
  }
528

529
  return win;
23,136,552✔
530
}
531

532
int32_t setResultRowInitCtx(SResultRow* pResult, SqlFunctionCtx* pCtx, int32_t numOfOutput,
427,975,137✔
533
                            int32_t* rowEntryInfoOffset) {
534
  bool init = false;
427,975,137✔
535
  for (int32_t i = 0; i < numOfOutput; ++i) {
1,602,040,234✔
536
    pCtx[i].resultInfo = getResultEntryInfo(pResult, i, rowEntryInfoOffset);
1,175,725,563✔
537
    if (init) {
1,175,719,892✔
538
      continue;
117,214,349✔
539
    }
540

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

546
    if (pCtx[i].isPseudoFunc) {
1,058,505,543✔
547
      continue;
262,321,697✔
548
    }
549

550
    if (!pResInfo->initialized) {
796,183,846✔
551
      if (pCtx[i].functionId != -1) {
750,240,392✔
552
        int32_t code = pCtx[i].fpSet.init(&pCtx[i], pResInfo);
710,708,808✔
553
        if (code != TSDB_CODE_SUCCESS && fmIsUserDefinedFunc(pCtx[i].functionId)) {
711,054,596!
554
          pResInfo->initialized = false;
44✔
555
          return TSDB_CODE_UDF_FUNC_EXEC_FAILURE;
44✔
556
        } else if (code != TSDB_CODE_SUCCESS) {
709,054,013!
557
          return code;
×
558
        }
559
      } else {
560
        pResInfo->initialized = true;
39,531,584✔
561
      }
562
    } else {
563
      init = true;
45,943,454✔
564
    }
565
  }
566
  return TSDB_CODE_SUCCESS;
426,314,671✔
567
}
568

569
void clearResultRowInitFlag(SqlFunctionCtx* pCtx, int32_t numOfOutput) {
71,678,858✔
570
  for (int32_t i = 0; i < numOfOutput; ++i) {
179,627,191✔
571
    SResultRowEntryInfo* pResInfo = pCtx[i].resultInfo;
107,948,333✔
572
    if (pResInfo == NULL) {
107,948,333!
573
      continue;
×
574
    }
575

576
    pResInfo->initialized = false;
107,948,333✔
577
    pResInfo->numOfRes = 0;
107,948,333✔
578
    pResInfo->isNullRes = 0;
107,948,333✔
579
    pResInfo->complete = false;
107,948,333✔
580
  }
581
}
71,678,858✔
582

583
int32_t doFilter(SSDataBlock* pBlock, SFilterInfo* pFilterInfo, SColMatchInfo* pColMatchInfo) {
27,471,506✔
584
  int32_t code = TSDB_CODE_SUCCESS;
27,471,506✔
585
  int32_t lino = 0;
27,471,506✔
586
  if (pFilterInfo == NULL || pBlock->info.rows == 0) {
27,471,506✔
587
    return TSDB_CODE_SUCCESS;
22,332,522✔
588
  }
589

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

593
  code = filterSetDataFromSlotId(pFilterInfo, &param1);
5,138,949✔
594
  QUERY_CHECK_CODE(code, lino, _err);
5,138,695!
595

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

600
  code = extractQualifiedTupleByFilterResult(pBlock, p, status);
5,138,861✔
601
  QUERY_CHECK_CODE(code, lino, _err);
5,138,719!
602

603
  if (pColMatchInfo != NULL) {
5,138,719✔
604
    size_t size = taosArrayGetSize(pColMatchInfo->pList);
4,591,190✔
605
    for (int32_t i = 0; i < size; ++i) {
4,596,474✔
606
      SColMatchItem* pInfo = taosArrayGet(pColMatchInfo->pList, i);
4,594,020✔
607
      QUERY_CHECK_NULL(pInfo, code, lino, _err, terrno);
4,594,021!
608
      if (pInfo->colId == PRIMARYKEY_TIMESTAMP_COL_ID) {
4,594,021✔
609
        SColumnInfoData* pColData = taosArrayGet(pBlock->pDataBlock, pInfo->dstSlotId);
4,588,803✔
610
        QUERY_CHECK_NULL(pColData, code, lino, _err, terrno);
4,588,724!
611
        if (pColData->info.type == TSDB_DATA_TYPE_TIMESTAMP) {
4,588,782✔
612
          code = blockDataUpdateTsWindow(pBlock, pInfo->dstSlotId);
4,588,751✔
613
          QUERY_CHECK_CODE(code, lino, _err);
4,588,782!
614
          break;
4,588,782✔
615
        }
616
      }
617
    }
618
  }
619
  code = blockDataCheck(pBlock);
5,138,765✔
620
  QUERY_CHECK_CODE(code, lino, _err);
5,138,721!
621
_err:
5,138,721✔
622
  if (code != TSDB_CODE_SUCCESS) {
5,138,722✔
623
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
1!
624
  }
625
  colDataDestroy(p);
5,138,722✔
626
  taosMemoryFree(p);
5,139,169✔
627
  return code;
5,139,047✔
628
}
629

630
int32_t extractQualifiedTupleByFilterResult(SSDataBlock* pBlock, const SColumnInfoData* p, int32_t status) {
5,138,908✔
631
  int32_t code = TSDB_CODE_SUCCESS;
5,138,908✔
632
  int8_t* pIndicator = (int8_t*)p->pData;
5,138,908✔
633
  if (status == FILTER_RESULT_ALL_QUALIFIED) {
5,138,908✔
634
    // here nothing needs to be done
635
  } else if (status == FILTER_RESULT_NONE_QUALIFIED) {
919,954✔
636
    code = trimDataBlock(pBlock, pBlock->info.rows, NULL);
132,627✔
637
    pBlock->info.rows = 0;
132,581✔
638
  } else if (status == FILTER_RESULT_PARTIAL_QUALIFIED) {
787,327!
639
    code = trimDataBlock(pBlock, pBlock->info.rows, (bool*)pIndicator);
787,355✔
640
  } else {
UNCOV
641
    qError("unknown filter result type: %d", status);
×
642
  }
643
  return code;
5,138,930✔
644
}
645

646
void doUpdateNumOfRows(SqlFunctionCtx* pCtx, SResultRow* pRow, int32_t numOfExprs, const int32_t* rowEntryOffset) {
375,881,326✔
647
  bool returnNotNull = false;
375,881,326✔
648
  for (int32_t j = 0; j < numOfExprs; ++j) {
1,351,168,409✔
649
    SResultRowEntryInfo* pResInfo = getResultEntryInfo(pRow, j, rowEntryOffset);
975,081,518✔
650
    if (!isRowEntryInitialized(pResInfo)) {
975,287,083✔
651
      continue;
213,578,323✔
652
    } else {
653
    }
654

655
    if (pRow->numOfRows < pResInfo->numOfRes) {
761,708,760✔
656
      pRow->numOfRows = pResInfo->numOfRes;
370,809,536✔
657
    }
658

659
    if (pCtx[j].isNotNullFunc) {
761,708,760✔
660
      returnNotNull = true;
201,009,776✔
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) {
376,086,891✔
666
    pRow->numOfRows = 1;
30,452✔
667
  }
668
}
376,086,891✔
669

670
int32_t copyResultrowToDataBlock(SExprInfo* pExprInfo, int32_t numOfExprs, SResultRow* pRow, SqlFunctionCtx* pCtx,
358,706,290✔
671
                                 SSDataBlock* pBlock, const int32_t* rowEntryOffset, SExecTaskInfo* pTaskInfo) {
672
  int32_t code = TSDB_CODE_SUCCESS;
358,706,290✔
673
  int32_t lino = 0;
358,706,290✔
674
  for (int32_t j = 0; j < numOfExprs; ++j) {
1,245,834,866✔
675
    int32_t slotId = pExprInfo[j].base.resSchema.slotId;
886,738,286✔
676

677
    pCtx[j].resultInfo = getResultEntryInfo(pRow, j, rowEntryOffset);
886,738,286✔
678
    if (pCtx[j].fpSet.finalize) {
886,824,941✔
679
      if (strcmp(pCtx[j].pExpr->pExpr->_function.functionName, "_group_key") == 0 ||
548,477,219✔
680
          strcmp(pCtx[j].pExpr->pExpr->_function.functionName, "_group_const_value") == 0) {
457,772,166✔
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) {
90,955,635!
684
          pCtx[j].resultInfo->numOfRes = pRow->numOfRows;
92,150,289✔
685
        }
686
      }
687

688
      code = blockDataEnsureCapacity(pBlock, pBlock->info.rows + pCtx[j].resultInfo->numOfRes);
548,477,219✔
689
      QUERY_CHECK_CODE(code, lino, _end);
548,687,735!
690

691
      code = pCtx[j].fpSet.finalize(&pCtx[j], pBlock);
548,687,735✔
692
      if (TSDB_CODE_SUCCESS != code) {
550,314,532!
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) {
338,347,722✔
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);
227,929,231✔
702
      QUERY_CHECK_NULL(pColInfoData, code, lino, _end, terrno);
227,212,442✔
703
      char*            in = GET_ROWCELL_INTERBUF(pCtx[j].resultInfo);
227,176,262✔
704
      for (int32_t k = 0; k < pRow->numOfRows; ++k) {
464,746,338✔
705
        code = colDataSetValOrCover(pColInfoData, pBlock->info.rows + k, in, pCtx[j].resultInfo->isNullRes);
237,307,417✔
706
        QUERY_CHECK_CODE(code, lino, _end);
237,570,076!
707
      }
708
    }
709
  }
710

711
_end:
359,096,580✔
712
  if (code != TSDB_CODE_SUCCESS) {
359,096,580!
713
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
×
714
  }
715
  return code;
360,409,522✔
716
}
717

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

729
  SqlFunctionCtx* pCtx = pSup->pCtx;
64,029,927✔
730
  SExprInfo*      pExprInfo = pSup->pExprInfo;
64,029,927✔
731
  const int32_t*  rowEntryOffset = pSup->rowEntryInfoOffset;
64,029,927✔
732

733
  doUpdateNumOfRows(pCtx, pRow, pSup->numOfExprs, rowEntryOffset);
64,029,927✔
734
  if (pRow->numOfRows == 0) {
64,005,871!
735
    releaseBufPage(pBuf, page);
×
736
    return;
×
737
  }
738

739
  int32_t size = pBlock->info.capacity;
64,007,245✔
740
  while (pBlock->info.rows + pRow->numOfRows > size) {
64,094,542✔
741
    size = size * 1.25;
87,297✔
742
  }
743

744
  int32_t code = blockDataEnsureCapacity(pBlock, size);
64,007,245✔
745
  if (TAOS_FAILED(code)) {
64,018,150!
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);
64,018,150✔
752
  if (TAOS_FAILED(code)) {
64,004,246!
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);
64,004,246✔
759
  pBlock->info.rows += pRow->numOfRows;
63,975,015✔
760
}
761

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

771
  size_t  keyLen = 0;
3,256,406✔
772
  int32_t numOfRows = tSimpleHashGetSize(pHashmap);
3,256,406✔
773

774
  // begin from last iter
775
  void*   pData = pGroupResInfo->dataPos;
3,251,022✔
776
  int32_t iter = pGroupResInfo->iter;
3,251,022✔
777
  while ((pData = tSimpleHashIterate(pHashmap, pData, &iter)) != NULL) {
14,012,485✔
778
    void*               key = tSimpleHashGetKey(pData, &keyLen);
13,792,826✔
779
    SResultRowPosition* pos = pData;
13,792,826✔
780
    uint64_t            groupId = *(uint64_t*)key;
13,792,826✔
781

782
    SFilePage* page = getBufPage(pBuf, pos->pageId);
13,792,826✔
783
    if (page == NULL) {
13,794,491!
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);
13,794,491✔
789

790
    doUpdateNumOfRows(pCtx, pRow, numOfExprs, rowEntryOffset);
13,794,491✔
791

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

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

802
    if (!ignoreGroup) {
13,748,980✔
803
      if (pBlock->info.id.groupId == 0) {
6,069,467✔
804
        pBlock->info.id.groupId = groupId;
3,076,153✔
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,993,314!
808
          releaseBufPage(pBuf, page);
3,013,837✔
809
          break;
3,014,562✔
810
        }
811
      }
812
    }
813

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

827
    code = copyResultrowToDataBlock(pExprInfo, numOfExprs, pRow, pCtx, pBlock, rowEntryOffset, pTaskInfo);
10,735,143✔
828
    releaseBufPage(pBuf, page);
10,765,453✔
829
    QUERY_CHECK_CODE(code, lino, _end);
10,761,503!
830
    pBlock->info.rows += pRow->numOfRows;
10,761,503✔
831
    if (pBlock->info.rows >= threshold) {
10,761,503✔
832
      break;
40✔
833
    }
834
  }
835

836
  qDebug("%s result generated, rows:%" PRId64 ", groupId:%" PRIu64, GET_TASKID(pTaskInfo), pBlock->info.rows,
3,227,189✔
837
         pBlock->info.id.groupId);
838
  pBlock->info.dataLoad = 1;
3,227,190✔
839
  code = blockDataUpdateTsWindow(pBlock, 0);
3,227,190✔
840
  QUERY_CHECK_CODE(code, lino, _end);
3,229,675!
841

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

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

858
  int32_t numOfRows = getNumOfTotalRes(pGroupResInfo);
2,111,234✔
859

860
  for (int32_t i = pGroupResInfo->index; i < numOfRows; i += 1) {
215,292,376✔
861
    SResKeyPos* pPos = taosArrayGetP(pGroupResInfo->pRows, i);
213,759,410✔
862
    SFilePage*  page = getBufPage(pBuf, pPos->pos.pageId);
213,799,407✔
863
    if (page == NULL) {
213,819,725!
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);
213,819,725✔
869

870
    doUpdateNumOfRows(pCtx, pRow, numOfExprs, rowEntryOffset);
213,819,725✔
871

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

879
    if (!ignoreGroup) {
212,037,114✔
880
      if (pBlock->info.id.groupId == 0) {
134,262,932✔
881
        pBlock->info.id.groupId = pPos->groupId;
117,707,112✔
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,555,820✔
885
          releaseBufPage(pBuf, page);
132,767✔
886
          break;
132,753✔
887
        }
888
      }
889
    }
890

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

900
    pGroupResInfo->index += 1;
211,904,347✔
901
    code = copyResultrowToDataBlock(pExprInfo, numOfExprs, pRow, pCtx, pBlock, rowEntryOffset, pTaskInfo);
211,904,347✔
902
    releaseBufPage(pBuf, page);
214,485,797✔
903
    QUERY_CHECK_CODE(code, lino, _end);
213,613,102!
904

905
    pBlock->info.rows += pRow->numOfRows;
213,613,102✔
906
    if (pBlock->info.rows >= threshold) {
213,613,102✔
907
      break;
432,822✔
908
    }
909
  }
910

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

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

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

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

932
  blockDataCleanup(pBlock);
3,151,698✔
933
  if (!hasRemainResults(pGroupResInfo)) {
3,152,125✔
934
    return;
1,040,810✔
935
  }
936

937
  // clear the existed group id
938
  pBlock->info.id.groupId = 0;
2,111,342✔
939
  if (!pbInfo->mergeResultBlock) {
2,111,342✔
940
    doCopyToSDataBlock(pTaskInfo, pBlock, &pOperator->exprSupp, pBuf, pGroupResInfo, pOperator->resultInfo.threshold,
1,194,775✔
941
                       false);
942
  } else {
943
    while (hasRemainResults(pGroupResInfo)) {
1,610,941✔
944
      doCopyToSDataBlock(pTaskInfo, pBlock, &pOperator->exprSupp, pBuf, pGroupResInfo, pOperator->resultInfo.threshold,
916,515✔
945
                         true);
946
      if (pBlock->info.rows >= pOperator->resultInfo.threshold) {
916,521✔
947
        break;
222,147✔
948
      }
949

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

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

959
void destroyExprInfo(SExprInfo* pExpr, int32_t numOfExprs) {
9,134,536✔
960
  for (int32_t i = 0; i < numOfExprs; ++i) {
39,062,631✔
961
    SExprInfo* pExprInfo = &pExpr[i];
29,927,791✔
962
    for (int32_t j = 0; j < pExprInfo->base.numOfParams; ++j) {
61,827,741✔
963
      if (pExprInfo->base.pParam[j].type == FUNC_PARAM_TYPE_COLUMN) {
31,911,374✔
964
        taosMemoryFreeClear(pExprInfo->base.pParam[j].pCol);
28,544,635✔
965
      } else if (pExprInfo->base.pParam[j].type == FUNC_PARAM_TYPE_VALUE) {
3,366,739✔
966
        taosVariantDestroy(&pExprInfo->base.pParam[j].param);
2,628,342✔
967
      }
968
    }
969

970
    taosMemoryFree(pExprInfo->base.pParam);
29,916,367✔
971
    taosMemoryFree(pExprInfo->pExpr);
29,911,918✔
972
  }
973
}
9,134,840✔
974

975
int32_t getBufferPgSize(int32_t rowSize, uint32_t* defaultPgsz, uint32_t* defaultBufsz) {
5,513,006✔
976
  *defaultPgsz = 4096;
5,513,006✔
977
  uint32_t last = *defaultPgsz;
5,513,006✔
978
  while (*defaultPgsz < rowSize * 4) {
7,117,639✔
979
    *defaultPgsz <<= 1u;
1,604,633✔
980
    if (*defaultPgsz < last) {
1,604,633!
981
      return TSDB_CODE_INVALID_PARA;
×
982
    }
983
    last = *defaultPgsz;
1,604,633✔
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,513,006✔
990
  if ((*defaultBufsz) <= (*defaultPgsz)) {
5,513,006!
991
    (*defaultBufsz) = (*defaultPgsz) * 4;
×
992
    if (*defaultBufsz < ((int64_t)(*defaultPgsz)) * 4) {
×
993
      return TSDB_CODE_INVALID_PARA;
×
994
    }
995
  }
996

997
  return 0;
5,513,006✔
998
}
999

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

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

1008
  if (pResultInfo->threshold == 0) {
13,608,274✔
1009
    pResultInfo->threshold = numOfRows;
10,649✔
1010
  }
1011
}
13,608,274✔
1012

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

1018
static void destroySqlFunctionCtx(SqlFunctionCtx* pCtx, SExprInfo* pExpr, int32_t numOfOutput) {
27,498,185✔
1019
  if (pCtx == NULL) {
27,498,185✔
1020
    return;
17,480,024✔
1021
  }
1022

1023
  for (int32_t i = 0; i < numOfOutput; ++i) {
39,668,084✔
1024
    if (pExpr != NULL) {
29,650,477✔
1025
      SExprInfo* pExprInfo = &pExpr[i];
29,649,515✔
1026
      for (int32_t j = 0; j < pExprInfo->base.numOfParams; ++j) {
61,282,028✔
1027
        if (pExprInfo->base.pParam[j].type == FUNC_PARAM_TYPE_VALUE) {
31,631,246✔
1028
          taosMemoryFree(pCtx[i].input.pData[j]);
2,624,206✔
1029
          taosMemoryFree(pCtx[i].input.pColumnDataAgg[j]);
2,624,153✔
1030
        }
1031
      }
1032
    }
1033
    for (int32_t j = 0; j < pCtx[i].numOfParams; ++j) {
61,268,965✔
1034
      taosVariantDestroy(&pCtx[i].param[j].param);
31,621,018✔
1035
    }
1036

1037
    taosMemoryFreeClear(pCtx[i].subsidiaries.pCtx);
29,647,947✔
1038
    taosMemoryFreeClear(pCtx[i].subsidiaries.buf);
29,648,114✔
1039
    taosMemoryFree(pCtx[i].input.pData);
29,648,110✔
1040
    taosMemoryFree(pCtx[i].input.pColumnDataAgg);
29,659,768✔
1041

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

1047
  taosMemoryFreeClear(pCtx);
10,017,607!
1048
  return;
10,017,800✔
1049
}
1050

1051
int32_t initExprSupp(SExprSupp* pSup, SExprInfo* pExprInfo, int32_t numOfExpr, SFunctionStateStore* pStore) {
8,188,369✔
1052
  pSup->pExprInfo = pExprInfo;
8,188,369✔
1053
  pSup->numOfExprs = numOfExpr;
8,188,369✔
1054
  if (pSup->pExprInfo != NULL) {
8,188,369✔
1055
    pSup->pCtx = createSqlFunctionCtx(pExprInfo, numOfExpr, &pSup->rowEntryInfoOffset, pStore);
7,037,421✔
1056
    if (pSup->pCtx == NULL) {
7,037,657!
1057
      return TSDB_CODE_OUT_OF_MEMORY;
×
1058
    }
1059
  }
1060

1061
  return TSDB_CODE_SUCCESS;
8,188,605✔
1062
}
1063

1064
void cleanupExprSupp(SExprSupp* pSupp) {
27,498,368✔
1065
  destroySqlFunctionCtx(pSupp->pCtx, pSupp->pExprInfo, pSupp->numOfExprs);
27,498,368✔
1066
  if (pSupp->pExprInfo != NULL) {
27,497,529✔
1067
    destroyExprInfo(pSupp->pExprInfo, pSupp->numOfExprs);
9,129,045✔
1068
    taosMemoryFreeClear(pSupp->pExprInfo);
9,129,138!
1069
  }
1070

1071
  if (pSupp->pFilterInfo != NULL) {
27,497,707✔
1072
    filterFreeInfo(pSupp->pFilterInfo);
3,021,081✔
1073
    pSupp->pFilterInfo = NULL;
3,021,120✔
1074
  }
1075

1076
  taosMemoryFree(pSupp->rowEntryInfoOffset);
27,497,746✔
1077
}
27,496,360✔
1078

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

1084
bool groupbyTbname(SNodeList* pGroupList) {
4,789,498✔
1085
  bool bytbname = false;
4,789,498✔
1086
  SNode*pNode = NULL;
4,789,498✔
1087
  FOREACH(pNode, pGroupList) {
4,883,128✔
1088
    if (pNode->type == QUERY_NODE_FUNCTION) {
397,607✔
1089
      bytbname = (strcmp(((struct SFunctionNode*)pNode)->functionName, "tbname") == 0);
303,977✔
1090
      break;
303,977✔
1091
    }
1092
  }
1093
  return bytbname;
4,789,498✔
1094
}
1095

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

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

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

1121
      STableListInfo* pTableListInfo = taosArrayGetP(pInfoList, 0);
62,677✔
1122
      taosArrayDestroy(pInfoList);
62,676✔
1123

1124
      pDeleterParam->suid = tableListGetSuid(pTableListInfo);
62,679✔
1125

1126
      // TODO extract uid list
1127
      int32_t numOfTables = 0;
62,676✔
1128
      code = tableListGetSize(pTableListInfo, &numOfTables);
62,676✔
1129
      if (code != TSDB_CODE_SUCCESS) {
62,671!
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));
62,671✔
1136
      if (NULL == pDeleterParam->pUidList) {
62,679✔
1137
        taosMemoryFree(pDeleterParam);
5✔
1138
        return terrno;
×
1139
      }
1140

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

1156
      *pParam = pDeleterParam;
62,680✔
1157
      break;
62,680✔
1158
    }
1159
    default:
7,239,112✔
1160
      break;
7,239,112✔
1161
  }
1162

1163
  return TSDB_CODE_SUCCESS;
7,302,093✔
1164
}
1165

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

1229
void freeOperatorParam(SOperatorParam* pParam, SOperatorParamType type) {
4,444,160✔
1230
  if (NULL == pParam) {
4,444,160✔
1231
    return;
4,338,091✔
1232
  }
1233

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

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

1269
  if (*ppParam) {
34,985,825✔
1270
    freeOperatorParam(*ppParam, type);
34,488✔
1271
    *ppParam = NULL;
34,488✔
1272
  }
1273

1274
  if (*pppDownstramParam) {
34,985,825✔
1275
    for (int32_t i = 0; i < pOperator->numOfDownstream; ++i) {
105,098✔
1276
      if ((*pppDownstramParam)[i]) {
68,976!
1277
        freeOperatorParam((*pppDownstramParam)[i], type);
×
1278
        (*pppDownstramParam)[i] = NULL;
×
1279
      }
1280
    }
1281
    if (allFree) {
36,122✔
1282
      taosMemoryFreeClear(*pppDownstramParam);
1,883!
1283
    }
1284
  }
1285
}
1286

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

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

1301
    if (code) {
103,645!
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,645✔
1305
  }
1306

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

1314
bool compareVal(const char* v, const SStateKeys* pKey) {
22,120,429✔
1315
  if (IS_VAR_DATA_TYPE(pKey->type)) {
22,120,429!
1316
    if (varDataLen(v) != varDataLen(pKey->pData)) {
2,729!
1317
      return false;
×
1318
    } else {
1319
      return memcmp(varDataVal(v), varDataVal(pKey->pData), varDataLen(v)) == 0;
2,729✔
1320
    }
1321
  } else {
1322
    return memcmp(pKey->pData, v, pKey->bytes) == 0;
22,117,700✔
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