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

taosdata / TDengine / #3535

23 Nov 2024 02:07AM UTC coverage: 60.85% (+0.03%) from 60.825%
#3535

push

travis-ci

web-flow
Merge pull request #28893 from taosdata/doc/internal

refact: rename taos lib name

120252 of 252737 branches covered (47.58%)

Branch coverage included in aggregate %.

201187 of 275508 relevant lines covered (73.02%)

15886166.19 hits per line

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

67.05
/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) {
223,414,188✔
86
  SFilePage* pData = NULL;
223,414,188✔
87

88
  // in the first scan, new space needed for results
89
  int32_t pageId = -1;
223,414,188✔
90
  if (*currentPageId == -1) {
223,414,188✔
91
    pData = getNewBufPage(pResultBuf, &pageId);
3,899,496✔
92
    if (pData == NULL) {
3,900,062✔
93
      qError("failed to get buffer, code:%s", tstrerror(terrno));
220!
94
      return NULL;
×
95
    }
96
    pData->num = sizeof(SFilePage);
3,899,842✔
97
  } else {
98
    pData = getBufPage(pResultBuf, *currentPageId);
219,514,692✔
99
    if (pData == NULL) {
219,706,685!
100
      qError("failed to get buffer, code:%s", tstrerror(terrno));
×
101
      return NULL;
×
102
    }
103

104
    pageId = *currentPageId;
219,706,685✔
105

106
    if (pData->num + interBufSize > getBufPageSize(pResultBuf)) {
219,706,685✔
107
      // release current page first, and prepare the next one
108
      releaseBufPage(pResultBuf, pData);
15,534,272✔
109

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

119
  if (pData == NULL) {
223,797,356!
120
    return NULL;
×
121
  }
122

123
  setBufPageDirty(pData, true);
223,797,356✔
124

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

128
  memset((char*)pResultRow, 0, interBufSize);
223,346,117✔
129
  pResultRow->pageId = pageId;
223,346,117✔
130
  pResultRow->offset = (int32_t)pData->num;
223,346,117✔
131

132
  *currentPageId = pageId;
223,346,117✔
133
  pData->num += interBufSize;
223,346,117✔
134
  return pResultRow;
223,346,117✔
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,
281,032,880✔
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);
281,032,880✔
148
  if (!keepGroup) {
281,032,880✔
149
    *(uint64_t*)pSup->keyBuf = calcGroupId(pSup->keyBuf, GET_RES_WINDOW_KEY_LEN(bytes));
16,748,256✔
150
  }
151

152
  SResultRowPosition* p1 =
153
      (SResultRowPosition*)tSimpleHashGet(pSup->pResultRowHashTable, pSup->keyBuf, GET_RES_WINDOW_KEY_LEN(bytes));
281,352,813✔
154

155
  SResultRow* pResult = NULL;
280,938,626✔
156

157
  // in case of repeat scan/reverse scan, no new time window added.
158
  if (isIntervalQuery) {
280,938,626✔
159
    if (p1 != NULL) {  // the *p1 may be NULL in case of sliding+offset exists.
260,482,620✔
160
      pResult = getResultRowByPos(pResultBuf, p1, true);
49,737,351✔
161
      if (pResult == NULL) {
49,737,351!
162
        pTaskInfo->code = terrno;
×
163
        return NULL;
×
164
      }
165

166
      if (pResult->pageId != p1->pageId || pResult->offset != p1->offset) {
49,737,351!
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,456,006✔
176
      // todo
177
      pResult = getResultRowByPos(pResultBuf, p1, true);
6,469,361✔
178
      if (NULL == pResult) {
6,469,361!
179
        pTaskInfo->code = terrno;
×
180
        return NULL;
×
181
      }
182

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

191
  // 1. close current opened time window
192
  if (pResultRowInfo->cur.pageId != -1 && ((pResult == NULL) || (pResult->pageId != pResultRowInfo->cur.pageId))) {
280,630,354✔
193
    SResultRowPosition pos = pResultRowInfo->cur;
225,936,352✔
194
    SFilePage*         pPage = getBufPage(pResultBuf, pos.pageId);
225,936,352✔
195
    if (pPage == NULL) {
225,207,075!
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);
225,207,075✔
201
  }
202

203
  // allocate a new buffer page
204
  if (pResult == NULL) {
278,899,193✔
205
    pResult = getNewResultRow(pResultBuf, &pSup->currentPageId, pSup->resultRowSize);
222,957,092✔
206
    if (pResult == NULL) {
223,325,637!
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};
223,325,637✔
213
    int32_t code = tSimpleHashPut(pSup->pResultRowHashTable, pSup->keyBuf, GET_RES_WINDOW_KEY_LEN(bytes), &pos,
223,325,637✔
214
                                  sizeof(SResultRowPosition));
215
    if (code != TSDB_CODE_SUCCESS) {
226,746,413✔
216
      qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(code));
108,109!
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};
282,580,405✔
224

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

232
  return pResult;
281,977,388✔
233
}
234

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

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

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

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

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

274
int32_t setInputDataBlock(SExprSupp* pExprSup, SSDataBlock* pBlock, int32_t order, int32_t scanFlag,
15,258,318✔
275
                          bool createDummyCol) {
276
  if (pBlock->pBlockAgg != NULL) {
15,258,318✔
277
    return doSetInputDataBlockInfo(pExprSup, pBlock, order, scanFlag);
13,157✔
278
  } else {
279
    return doSetInputDataBlock(pExprSup, pBlock, order, scanFlag, createDummyCol);
15,245,161✔
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,244,920✔
335
                                   bool createDummyCol) {
336
  int32_t         code = TSDB_CODE_SUCCESS;
15,244,920✔
337
  int32_t         lino = 0;
15,244,920✔
338
  SqlFunctionCtx* pCtx = pExprSup->pCtx;
15,244,920✔
339

340
  for (int32_t i = 0; i < pExprSup->numOfExprs; ++i) {
74,985,544✔
341
    pCtx[i].order = order;
59,741,579✔
342
    pCtx[i].input.numOfRows = pBlock->info.rows;
59,741,579✔
343

344
    pCtx[i].pSrcBlock = pBlock;
59,741,579✔
345
    pCtx[i].scanFlag = scanFlag;
59,741,579✔
346

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

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

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

358
    for (int32_t j = 0; j < pOneExpr->base.numOfParams; ++j) {
125,394,798✔
359
      SFunctParam* pFuncParam = &pOneExpr->base.pParam[j];
65,654,174✔
360
      if (pFuncParam->type == FUNC_PARAM_TYPE_COLUMN) {
65,654,174✔
361
        int32_t slotId = pFuncParam->pCol->slotId;
60,267,072✔
362
        pInput->pData[j] = taosArrayGet(pBlock->pDataBlock, slotId);
60,267,072✔
363
        pInput->totalRows = pBlock->info.rows;
60,262,496✔
364
        pInput->numOfRows = pBlock->info.rows;
60,262,496✔
365
        pInput->startRowIndex = 0;
60,262,496✔
366
        pInput->blankFill = pBlock->info.blankFill;
60,262,496✔
367

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

371
        if (fmIsImplicitTsFunc(pCtx[i].functionId) && (j == tsParamIdx)) {
60,262,496✔
372
          pInput->pPTS = pInput->pData[j];  // in case of merge function, this is not always the ts column data.
5,458,836✔
373
        }
374
        if (hasPk && (j == pkParamIdx)) {
60,266,117✔
375
          pInput->pPrimaryKey = pInput->pData[j];
969,234✔
376
        }
377
        QUERY_CHECK_CONDITION((pInput->pData[j] != NULL), code, lino, _end, TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR);
60,266,117!
378
      } else if (pFuncParam->type == FUNC_PARAM_TYPE_VALUE) {
5,387,102✔
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,745,948!
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,243,965✔
395
  if (code != TSDB_CODE_SUCCESS) {
15,243,965!
396
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
×
397
  }
398
  return code;
15,247,574✔
399
}
400

401
bool functionNeedToExecute(SqlFunctionCtx* pCtx) {
934,959,482✔
402
  struct SResultRowEntryInfo* pResInfo = GET_RES_INFO(pCtx);
934,959,482✔
403

404
  // in case of timestamp column, always generated results.
405
  int32_t functionId = pCtx->functionId;
934,959,482✔
406
  if (functionId == -1) {
934,959,482✔
407
    return false;
51,071,983✔
408
  }
409

410
  if (pCtx->scanFlag == PRE_SCAN) {
883,887,499✔
411
    return fmIsRepeatScanFunc(pCtx->functionId);
16,914✔
412
  }
413

414
  if (isRowEntryCompleted(pResInfo)) {
883,870,585✔
415
    return false;
7,006✔
416
  }
417

418
  return true;
883,863,579✔
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) {
13,165✔
475
  int32_t code = TSDB_CODE_SUCCESS;
13,165✔
476
  int32_t lino = 0;
13,165✔
477
  int32_t numOfRows = pBlock->info.rows;
13,165✔
478

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

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

486
    for (int32_t j = 0; j < pExprInfo->base.numOfParams; ++j) {
26,330✔
487
      SFunctParam* pFuncParam = &pExprInfo->base.pParam[j];
13,165✔
488

489
      if (pFuncParam->type == FUNC_PARAM_TYPE_COLUMN) {
13,165!
490
        int32_t slotId = pFuncParam->pCol->slotId;
13,165✔
491
        pInput->pColumnDataAgg[j] = &pBlock->pBlockAgg[slotId];
13,165✔
492
        if (pInput->pColumnDataAgg[j]->colId == -1) {
13,165✔
493
          pInput->colDataSMAIsSet = false;
2,320✔
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);
13,165✔
499
      } else if (pFuncParam->type == FUNC_PARAM_TYPE_VALUE) {
×
500
        code = doCreateConstantValColumnSMAInfo(pInput, pFuncParam, pFuncParam->param.nType, j, pBlock->info.rows);
×
501
        QUERY_CHECK_CODE(code, lino, _end);
×
502
      }
503
    }
504
  } else {
505
    pInput->colDataSMAIsSet = false;
×
506
  }
507

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

515
/////////////////////////////////////////////////////////////////////////////////////////////
516
STimeWindow getAlignQueryTimeWindow(const SInterval* pInterval, int64_t key) {
22,107,216✔
517
  STimeWindow win = {0};
22,107,216✔
518
  win.skey = taosTimeTruncate(key, pInterval);
22,107,216✔
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);
22,107,125✔
525
  if (win.ekey < win.skey) {
22,107,099✔
526
    win.ekey = INT64_MAX;
2,125✔
527
  }
528

529
  return win;
22,107,099✔
530
}
531

532
int32_t setResultRowInitCtx(SResultRow* pResult, SqlFunctionCtx* pCtx, int32_t numOfOutput,
449,930,073✔
533
                            int32_t* rowEntryInfoOffset) {
534
  bool init = false;
449,930,073✔
535
  for (int32_t i = 0; i < numOfOutput; ++i) {
1,661,342,684✔
536
    pCtx[i].resultInfo = getResultEntryInfo(pResult, i, rowEntryInfoOffset);
1,213,324,741✔
537
    if (init) {
1,213,179,714✔
538
      continue;
116,902,138✔
539
    }
540

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

546
    if (pCtx[i].isPseudoFunc) {
1,096,277,576✔
547
      continue;
270,991,710✔
548
    }
549

550
    if (!pResInfo->initialized) {
825,285,866✔
551
      if (pCtx[i].functionId != -1) {
775,765,212✔
552
        int32_t code = pCtx[i].fpSet.init(&pCtx[i], pResInfo);
736,211,014✔
553
        if (code != TSDB_CODE_SUCCESS && fmIsUserDefinedFunc(pCtx[i].functionId)) {
736,161,194!
554
          pResInfo->initialized = false;
44✔
555
          return TSDB_CODE_UDF_FUNC_EXEC_FAILURE;
44✔
556
        } else if (code != TSDB_CODE_SUCCESS) {
734,443,911!
557
          return code;
×
558
        }
559
      } else {
560
        pResInfo->initialized = true;
39,554,198✔
561
      }
562
    } else {
563
      init = true;
49,520,654✔
564
    }
565
  }
566
  return TSDB_CODE_SUCCESS;
448,017,943✔
567
}
568

569
void clearResultRowInitFlag(SqlFunctionCtx* pCtx, int32_t numOfOutput) {
87,954,104✔
570
  for (int32_t i = 0; i < numOfOutput; ++i) {
212,880,761✔
571
    SResultRowEntryInfo* pResInfo = pCtx[i].resultInfo;
124,926,657✔
572
    if (pResInfo == NULL) {
124,926,657!
573
      continue;
×
574
    }
575

576
    pResInfo->initialized = false;
124,926,657✔
577
    pResInfo->numOfRes = 0;
124,926,657✔
578
    pResInfo->isNullRes = 0;
124,926,657✔
579
    pResInfo->complete = false;
124,926,657✔
580
  }
581
}
87,954,104✔
582

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

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

593
  code = filterSetDataFromSlotId(pFilterInfo, &param1);
5,367,760✔
594
  QUERY_CHECK_CODE(code, lino, _err);
5,367,554!
595

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

600
  code = extractQualifiedTupleByFilterResult(pBlock, p, status);
5,367,783✔
601
  QUERY_CHECK_CODE(code, lino, _err);
5,367,689!
602

603
  if (pColMatchInfo != NULL) {
5,367,689✔
604
    size_t size = taosArrayGetSize(pColMatchInfo->pList);
4,819,742✔
605
    for (int32_t i = 0; i < size; ++i) {
4,825,027✔
606
      SColMatchItem* pInfo = taosArrayGet(pColMatchInfo->pList, i);
4,822,608✔
607
      QUERY_CHECK_NULL(pInfo, code, lino, _err, terrno);
4,822,584!
608
      if (pInfo->colId == PRIMARYKEY_TIMESTAMP_COL_ID) {
4,822,584✔
609
        SColumnInfoData* pColData = taosArrayGet(pBlock->pDataBlock, pInfo->dstSlotId);
4,817,288✔
610
        QUERY_CHECK_NULL(pColData, code, lino, _err, terrno);
4,817,216!
611
        if (pColData->info.type == TSDB_DATA_TYPE_TIMESTAMP) {
4,817,232!
612
          code = blockDataUpdateTsWindow(pBlock, pInfo->dstSlotId);
4,817,235✔
613
          QUERY_CHECK_CODE(code, lino, _err);
4,817,218!
614
          break;
4,817,218✔
615
        }
616
      }
617
    }
618
  }
619
  code = blockDataCheck(pBlock);
5,367,584✔
620
  QUERY_CHECK_CODE(code, lino, _err);
5,367,405!
621
_err:
5,367,405✔
622
  if (code != TSDB_CODE_SUCCESS) {
5,367,406✔
623
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
1!
624
  }
625
  colDataDestroy(p);
5,367,406✔
626
  taosMemoryFree(p);
5,368,034✔
627
  return code;
5,367,743✔
628
}
629

630
int32_t extractQualifiedTupleByFilterResult(SSDataBlock* pBlock, const SColumnInfoData* p, int32_t status) {
5,367,750✔
631
  int32_t code = TSDB_CODE_SUCCESS;
5,367,750✔
632
  int8_t* pIndicator = (int8_t*)p->pData;
5,367,750✔
633
  if (status == FILTER_RESULT_ALL_QUALIFIED) {
5,367,750✔
634
    // here nothing needs to be done
635
  } else if (status == FILTER_RESULT_NONE_QUALIFIED) {
892,502✔
636
    code = trimDataBlock(pBlock, pBlock->info.rows, NULL);
132,672✔
637
    pBlock->info.rows = 0;
132,612✔
638
  } else if (status == FILTER_RESULT_PARTIAL_QUALIFIED) {
759,830!
639
    code = trimDataBlock(pBlock, pBlock->info.rows, (bool*)pIndicator);
759,856✔
640
  } else {
641
    qError("unknown filter result type: %d", status);
×
642
  }
643
  return code;
5,367,891✔
644
}
645

646
void doUpdateNumOfRows(SqlFunctionCtx* pCtx, SResultRow* pRow, int32_t numOfExprs, const int32_t* rowEntryOffset) {
393,055,404✔
647
  bool returnNotNull = false;
393,055,404✔
648
  for (int32_t j = 0; j < numOfExprs; ++j) {
1,402,483,483✔
649
    SResultRowEntryInfo* pResInfo = getResultEntryInfo(pRow, j, rowEntryOffset);
1,009,605,014✔
650
    if (!isRowEntryInitialized(pResInfo)) {
1,009,428,079✔
651
      continue;
224,403,613✔
652
    } else {
653
    }
654

655
    if (pRow->numOfRows < pResInfo->numOfRes) {
785,024,466✔
656
      pRow->numOfRows = pResInfo->numOfRes;
387,543,050✔
657
    }
658

659
    if (pCtx[j].isNotNullFunc) {
785,024,466✔
660
      returnNotNull = true;
214,442,400✔
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) {
392,878,469✔
666
    pRow->numOfRows = 1;
31,741✔
667
  }
668
}
392,878,469✔
669

670
int32_t copyResultrowToDataBlock(SExprInfo* pExprInfo, int32_t numOfExprs, SResultRow* pRow, SqlFunctionCtx* pCtx,
375,733,378✔
671
                                 SSDataBlock* pBlock, const int32_t* rowEntryOffset, SExecTaskInfo* pTaskInfo) {
672
  int32_t code = TSDB_CODE_SUCCESS;
375,733,378✔
673
  int32_t lino = 0;
375,733,378✔
674
  for (int32_t j = 0; j < numOfExprs; ++j) {
1,298,708,305✔
675
    int32_t slotId = pExprInfo[j].base.resSchema.slotId;
921,839,666✔
676

677
    pCtx[j].resultInfo = getResultEntryInfo(pRow, j, rowEntryOffset);
921,839,666✔
678
    if (pCtx[j].fpSet.finalize) {
922,293,223✔
679
      if (strcmp(pCtx[j].pExpr->pExpr->_function.functionName, "_group_key") == 0 ||
569,916,807✔
680
          strcmp(pCtx[j].pExpr->pExpr->_function.functionName, "_group_const_value") == 0) {
478,559,808✔
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) {
91,607,625!
684
          pCtx[j].resultInfo->numOfRes = pRow->numOfRows;
93,028,508✔
685
        }
686
      }
687

688
      code = blockDataEnsureCapacity(pBlock, pBlock->info.rows + pCtx[j].resultInfo->numOfRes);
569,916,807✔
689
      QUERY_CHECK_CODE(code, lino, _end);
570,142,221!
690

691
      code = pCtx[j].fpSet.finalize(&pCtx[j], pBlock);
570,142,221✔
692
      if (TSDB_CODE_SUCCESS != code) {
572,667,155!
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) {
352,376,416✔
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);
239,286,192✔
702
      QUERY_CHECK_NULL(pColInfoData, code, lino, _end, terrno);
238,483,620✔
703
      char*            in = GET_ROWCELL_INTERBUF(pCtx[j].resultInfo);
238,313,865✔
704
      for (int32_t k = 0; k < pRow->numOfRows; ++k) {
486,784,437✔
705
        code = colDataSetValOrCover(pColInfoData, pBlock->info.rows + k, in, pCtx[j].resultInfo->isNullRes);
248,155,382✔
706
        QUERY_CHECK_CODE(code, lino, _end);
248,470,572!
707
      }
708
    }
709
  }
710

711
_end:
376,868,639✔
712
  if (code != TSDB_CODE_SUCCESS) {
376,868,639!
713
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
×
714
  }
715
  return code;
378,187,415✔
716
}
717

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

729
  SqlFunctionCtx* pCtx = pSup->pCtx;
68,501,447✔
730
  SExprInfo*      pExprInfo = pSup->pExprInfo;
68,501,447✔
731
  const int32_t*  rowEntryOffset = pSup->rowEntryInfoOffset;
68,501,447✔
732

733
  doUpdateNumOfRows(pCtx, pRow, pSup->numOfExprs, rowEntryOffset);
68,501,447✔
734
  if (pRow->numOfRows == 0) {
68,469,687!
735
    releaseBufPage(pBuf, page);
×
736
    return;
×
737
  }
738

739
  int32_t size = pBlock->info.capacity;
68,470,176✔
740
  while (pBlock->info.rows + pRow->numOfRows > size) {
68,558,298✔
741
    size = size * 1.25;
88,122✔
742
  }
743

744
  int32_t code = blockDataEnsureCapacity(pBlock, size);
68,470,176✔
745
  if (TAOS_FAILED(code)) {
68,481,780!
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);
68,481,780✔
752
  if (TAOS_FAILED(code)) {
68,477,269!
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);
68,477,269✔
759
  pBlock->info.rows += pRow->numOfRows;
68,450,314✔
760
}
761

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

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

774
  // begin from last iter
775
  void*   pData = pGroupResInfo->dataPos;
3,198,785✔
776
  int32_t iter = pGroupResInfo->iter;
3,198,785✔
777
  while ((pData = tSimpleHashIterate(pHashmap, pData, &iter)) != NULL) {
13,813,407✔
778
    void*               key = tSimpleHashGetKey(pData, &keyLen);
13,571,683✔
779
    SResultRowPosition* pos = pData;
13,571,683✔
780
    uint64_t            groupId = *(uint64_t*)key;
13,571,683✔
781

782
    SFilePage* page = getBufPage(pBuf, pos->pageId);
13,571,683✔
783
    if (page == NULL) {
13,566,529!
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,566,529✔
789

790
    doUpdateNumOfRows(pCtx, pRow, numOfExprs, rowEntryOffset);
13,566,529✔
791

792
    // no results, continue to check the next one
793
    if (pRow->numOfRows == 0) {
13,517,063!
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,517,063✔
803
      if (pBlock->info.id.groupId == 0) {
5,915,869✔
804
        pBlock->info.id.groupId = groupId;
3,003,319✔
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,912,550!
808
          releaseBufPage(pBuf, page);
2,936,145✔
809
          break;
2,937,463✔
810
        }
811
      }
812
    }
813

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

827
    code = copyResultrowToDataBlock(pExprInfo, numOfExprs, pRow, pCtx, pBlock, rowEntryOffset, pTaskInfo);
10,580,918✔
828
    releaseBufPage(pBuf, page);
10,616,227✔
829
    QUERY_CHECK_CODE(code, lino, _end);
10,614,662!
830
    pBlock->info.rows += pRow->numOfRows;
10,614,662✔
831
    if (pBlock->info.rows >= threshold) {
10,614,662✔
832
      break;
40✔
833
    }
834
  }
835

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

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

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

858
  int32_t numOfRows = getNumOfTotalRes(pGroupResInfo);
2,134,768✔
859

860
  for (int32_t i = pGroupResInfo->index; i < numOfRows; i += 1) {
212,458,979✔
861
    SResKeyPos* pPos = taosArrayGetP(pGroupResInfo->pRows, i);
210,923,464✔
862
    SFilePage*  page = getBufPage(pBuf, pPos->pos.pageId);
210,906,495✔
863
    if (page == NULL) {
211,095,279!
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);
211,095,279✔
869

870
    doUpdateNumOfRows(pCtx, pRow, numOfExprs, rowEntryOffset);
211,095,279✔
871

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

879
    if (!ignoreGroup) {
208,638,491✔
880
      if (pBlock->info.id.groupId == 0) {
139,855,848✔
881
        pBlock->info.id.groupId = pPos->groupId;
123,041,976✔
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,813,872✔
885
          releaseBufPage(pBuf, page);
133,003✔
886
          break;
132,993✔
887
        }
888
      }
889
    }
890

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

900
    pGroupResInfo->index += 1;
208,505,488✔
901
    code = copyResultrowToDataBlock(pExprInfo, numOfExprs, pRow, pCtx, pBlock, rowEntryOffset, pTaskInfo);
208,505,488✔
902
    releaseBufPage(pBuf, page);
211,729,230✔
903
    QUERY_CHECK_CODE(code, lino, _end);
210,779,881!
904

905
    pBlock->info.rows += pRow->numOfRows;
210,779,881✔
906
    if (pBlock->info.rows >= threshold) {
210,779,881✔
907
      break;
456,501✔
908
    }
909
  }
910

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

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

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

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

932
  blockDataCleanup(pBlock);
3,134,981✔
933
  if (!hasRemainResults(pGroupResInfo)) {
3,135,483✔
934
    return;
1,000,576✔
935
  }
936

937
  // clear the existed group id
938
  pBlock->info.id.groupId = 0;
2,134,917✔
939
  if (!pbInfo->mergeResultBlock) {
2,134,917✔
940
    doCopyToSDataBlock(pTaskInfo, pBlock, &pOperator->exprSupp, pBuf, pGroupResInfo, pOperator->resultInfo.threshold,
1,219,361✔
941
                       false);
942
  } else {
943
    while (hasRemainResults(pGroupResInfo)) {
1,602,403✔
944
      doCopyToSDataBlock(pTaskInfo, pBlock, &pOperator->exprSupp, pBuf, pGroupResInfo, pOperator->resultInfo.threshold,
915,488✔
945
                         true);
946
      if (pBlock->info.rows >= pOperator->resultInfo.threshold) {
915,516✔
947
        break;
228,669✔
948
      }
949

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

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

959
void destroyExprInfo(SExprInfo* pExpr, int32_t numOfExprs) {
9,063,109✔
960
  for (int32_t i = 0; i < numOfExprs; ++i) {
39,184,654✔
961
    SExprInfo* pExprInfo = &pExpr[i];
30,121,284✔
962
    for (int32_t j = 0; j < pExprInfo->base.numOfParams; ++j) {
62,281,087✔
963
      if (pExprInfo->base.pParam[j].type == FUNC_PARAM_TYPE_COLUMN) {
32,177,560✔
964
        taosMemoryFreeClear(pExprInfo->base.pParam[j].pCol);
28,856,892✔
965
      } else if (pExprInfo->base.pParam[j].type == FUNC_PARAM_TYPE_VALUE) {
3,320,668✔
966
        taosVariantDestroy(&pExprInfo->base.pParam[j].param);
2,571,078✔
967
      }
968
    }
969

970
    taosMemoryFree(pExprInfo->base.pParam);
30,103,527✔
971
    taosMemoryFree(pExprInfo->pExpr);
30,089,506✔
972
  }
973
}
9,063,370✔
974

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

997
  return 0;
5,466,875✔
998
}
999

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

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

1008
  if (pResultInfo->threshold == 0) {
13,472,286✔
1009
    pResultInfo->threshold = numOfRows;
11,774✔
1010
  }
1011
}
13,472,286✔
1012

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

1018
static void destroySqlFunctionCtx(SqlFunctionCtx* pCtx, SExprInfo* pExpr, int32_t numOfOutput) {
27,234,572✔
1019
  if (pCtx == NULL) {
27,234,572✔
1020
    return;
17,294,030✔
1021
  }
1022

1023
  for (int32_t i = 0; i < numOfOutput; ++i) {
39,767,364✔
1024
    if (pExpr != NULL) {
29,827,003✔
1025
      SExprInfo* pExprInfo = &pExpr[i];
29,826,742✔
1026
      for (int32_t j = 0; j < pExprInfo->base.numOfParams; ++j) {
61,711,283✔
1027
        if (pExprInfo->base.pParam[j].type == FUNC_PARAM_TYPE_VALUE) {
31,882,086✔
1028
          taosMemoryFree(pCtx[i].input.pData[j]);
2,566,946✔
1029
          taosMemoryFree(pCtx[i].input.pColumnDataAgg[j]);
2,566,899✔
1030
        }
1031
      }
1032
    }
1033
    for (int32_t j = 0; j < pCtx[i].numOfParams; ++j) {
61,695,902✔
1034
      taosVariantDestroy(&pCtx[i].param[j].param);
31,869,943✔
1035
    }
1036

1037
    taosMemoryFreeClear(pCtx[i].subsidiaries.pCtx);
29,825,959✔
1038
    taosMemoryFreeClear(pCtx[i].subsidiaries.buf);
29,826,120✔
1039
    taosMemoryFree(pCtx[i].input.pData);
29,826,113✔
1040
    taosMemoryFree(pCtx[i].input.pColumnDataAgg);
29,836,750✔
1041

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

1047
  taosMemoryFreeClear(pCtx);
9,940,361!
1048
  return;
9,940,473✔
1049
}
1050

1051
int32_t initExprSupp(SExprSupp* pSup, SExprInfo* pExprInfo, int32_t numOfExpr, SFunctionStateStore* pStore) {
8,171,468✔
1052
  pSup->pExprInfo = pExprInfo;
8,171,468✔
1053
  pSup->numOfExprs = numOfExpr;
8,171,468✔
1054
  if (pSup->pExprInfo != NULL) {
8,171,468✔
1055
    pSup->pCtx = createSqlFunctionCtx(pExprInfo, numOfExpr, &pSup->rowEntryInfoOffset, pStore);
7,011,672✔
1056
    if (pSup->pCtx == NULL) {
7,010,111!
1057
      return TSDB_CODE_OUT_OF_MEMORY;
×
1058
    }
1059
  }
1060

1061
  return TSDB_CODE_SUCCESS;
8,169,907✔
1062
}
1063

1064
void cleanupExprSupp(SExprSupp* pSupp) {
27,234,871✔
1065
  destroySqlFunctionCtx(pSupp->pCtx, pSupp->pExprInfo, pSupp->numOfExprs);
27,234,871✔
1066
  if (pSupp->pExprInfo != NULL) {
27,233,745✔
1067
    destroyExprInfo(pSupp->pExprInfo, pSupp->numOfExprs);
9,057,511✔
1068
    taosMemoryFreeClear(pSupp->pExprInfo);
9,057,602!
1069
  }
1070

1071
  if (pSupp->pFilterInfo != NULL) {
27,233,903✔
1072
    filterFreeInfo(pSupp->pFilterInfo);
3,011,287✔
1073
    pSupp->pFilterInfo = NULL;
3,011,328✔
1074
  }
1075

1076
  taosMemoryFree(pSupp->rowEntryInfoOffset);
27,233,944✔
1077
}
27,232,760✔
1078

1079
void cleanupBasicInfo(SOptrBasicInfo* pInfo) {
5,473,836✔
1080
  blockDataDestroy(pInfo->pRes);
5,473,836✔
1081
  pInfo->pRes = NULL;
5,474,044✔
1082
}
5,474,044✔
1083

1084
bool groupbyTbname(SNodeList* pGroupList) {
4,735,093✔
1085
  bool bytbname = false;
4,735,093✔
1086
  SNode*pNode = NULL;
4,735,093✔
1087
  FOREACH(pNode, pGroupList) {
4,833,369✔
1088
    if (pNode->type == QUERY_NODE_FUNCTION) {
413,134✔
1089
      bytbname = (strcmp(((struct SFunctionNode*)pNode)->functionName, "tbname") == 0);
314,858✔
1090
      break;
314,858✔
1091
    }
1092
  }
1093
  return bytbname;
4,735,093✔
1094
}
1095

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

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

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

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

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

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

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

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

1156
      *pParam = pDeleterParam;
60,094✔
1157
      break;
60,094✔
1158
    }
1159
    default:
7,168,252✔
1160
      break;
7,168,252✔
1161
  }
1162

1163
  return TSDB_CODE_SUCCESS;
7,228,652✔
1164
}
1165

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

1229
void freeOperatorParam(SOperatorParam* pParam, SOperatorParamType type) {
4,422,380✔
1230
  if (NULL == pParam) {
4,422,380✔
1231
    return;
4,316,188✔
1232
  }
1233

1234
  switch (pParam->opType) {
106,192!
1235
    case QUERY_NODE_PHYSICAL_PLAN_EXCHANGE:
646✔
1236
      type == OP_GET_PARAM ? freeExchangeGetOperatorParam(pParam) : freeExchangeNotifyOperatorParam(pParam);
646!
1237
      break;
646✔
1238
    case QUERY_NODE_PHYSICAL_PLAN_GROUP_CACHE:
69,006✔
1239
      type == OP_GET_PARAM ? freeGroupCacheGetOperatorParam(pParam) : freeGroupCacheNotifyOperatorParam(pParam);
69,006!
1240
      break;
69,006✔
1241
    case QUERY_NODE_PHYSICAL_PLAN_MERGE_JOIN:
34,503✔
1242
      type == OP_GET_PARAM ? freeMergeJoinGetOperatorParam(pParam) : freeMergeJoinNotifyOperatorParam(pParam);
34,503!
1243
      break;
34,503✔
1244
    case QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN:
2,093✔
1245
      type == OP_GET_PARAM ? freeTableScanGetOperatorParam(pParam) : freeTableScanNotifyOperatorParam(pParam);
2,093!
1246
      break;
2,094✔
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,635,980✔
1254
  SOperatorParam**  ppParam = NULL;
34,635,980✔
1255
  SOperatorParam*** pppDownstramParam = NULL;
34,635,980✔
1256
  switch (type) {
34,635,980!
1257
    case OP_GET_PARAM:
17,341,955✔
1258
      ppParam = &pOperator->pOperatorGetParam;
17,341,955✔
1259
      pppDownstramParam = &pOperator->pDownstreamGetParams;
17,341,955✔
1260
      break;
17,341,955✔
1261
    case OP_NOTIFY_PARAM:
17,305,810✔
1262
      ppParam = &pOperator->pOperatorNotifyParam;
17,305,810✔
1263
      pppDownstramParam = &pOperator->pDownstreamNotifyParams;
17,305,810✔
1264
      break;
17,305,810✔
1265
    default:
×
1266
      return;
×
1267
  }
1268

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

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

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

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

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

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

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

© 2025 Coveralls, Inc