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

taosdata / TDengine / #3631

07 Mar 2025 03:18PM UTC coverage: 60.671% (-3.0%) from 63.629%
#3631

push

travis-ci

web-flow
Merge pull request #30074 from taosdata/ciup30

ci: update ci workflow to fix path issue

141481 of 300084 branches covered (47.15%)

Branch coverage included in aggregate %.

223132 of 300884 relevant lines covered (74.16%)

7878557.0 hits per line

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

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

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

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

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

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

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

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

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

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

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

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

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

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

86
SResultRow* getNewResultRow(SDiskbasedBuf* pResultBuf, int32_t* currentPageId, int32_t interBufSize) {
76,132,944✔
87
  SFilePage* pData = NULL;
76,132,944✔
88

89
  // in the first scan, new space needed for results
90
  int32_t pageId = -1;
76,132,944✔
91
  if (*currentPageId == -1) {
76,132,944✔
92
    pData = getNewBufPage(pResultBuf, &pageId);
1,247,702✔
93
    if (pData == NULL) {
1,247,939✔
94
      qError("failed to get buffer, code:%s", tstrerror(terrno));
77!
95
      return NULL;
×
96
    }
97
    pData->num = sizeof(SFilePage);
1,247,862✔
98
  } else {
99
    pData = getBufPage(pResultBuf, *currentPageId);
74,885,242✔
100
    if (pData == NULL) {
74,698,195!
101
      qError("failed to get buffer, code:%s", tstrerror(terrno));
×
102
      return NULL;
×
103
    }
104

105
    pageId = *currentPageId;
74,698,195✔
106

107
    if (pData->num + interBufSize > getBufPageSize(pResultBuf)) {
74,698,195✔
108
      // release current page first, and prepare the next one
109
      releaseBufPage(pResultBuf, pData);
5,330,894✔
110

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

120
  if (pData == NULL) {
76,171,871!
121
    return NULL;
×
122
  }
123

124
  setBufPageDirty(pData, true);
76,171,871✔
125

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

129
  memset((char*)pResultRow, 0, interBufSize);
76,006,408✔
130
  pResultRow->pageId = pageId;
76,006,408✔
131
  pResultRow->offset = (int32_t)pData->num;
76,006,408✔
132

133
  *currentPageId = pageId;
76,006,408✔
134
  pData->num += interBufSize;
76,006,408✔
135
  return pResultRow;
76,006,408✔
136
}
137

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

153
  SResultRowPosition* p1 =
154
      (SResultRowPosition*)tSimpleHashGet(pSup->pResultRowHashTable, pSup->keyBuf, GET_RES_WINDOW_KEY_LEN(bytes));
110,199,142✔
155

156
  SResultRow* pResult = NULL;
109,783,660✔
157

158
  // in case of repeat scan/reverse scan, no new time window added.
159
  if (isIntervalQuery) {
109,783,660✔
160
    if (p1 != NULL) {  // the *p1 may be NULL in case of sliding+offset exists.
97,760,319✔
161
      pResult = getResultRowByPos(pResultBuf, p1, true);
27,426,666✔
162
      if (pResult == NULL) {
27,426,666!
163
        pTaskInfo->code = terrno;
×
164
        return NULL;
×
165
      }
166

167
      if (pResult->pageId != p1->pageId || pResult->offset != p1->offset) {
27,426,666!
168
        terrno = TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR;
×
169
        pTaskInfo->code = terrno;
×
170
        return NULL;
×
171
      }
172
    }
173
  } else {
174
    // In case of group by column query, the required SResultRow object must be existInCurrentResusltRowInfo in the
175
    // pResultRowInfo object.
176
    if (p1 != NULL) {
12,023,341✔
177
      // todo
178
      pResult = getResultRowByPos(pResultBuf, p1, true);
5,132,163✔
179
      if (NULL == pResult) {
5,132,163!
180
        pTaskInfo->code = terrno;
×
181
        return NULL;
×
182
      }
183

184
      if (pResult->pageId != p1->pageId || pResult->offset != p1->offset) {
5,132,163!
185
        terrno = TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR;
×
186
        pTaskInfo->code = terrno;
×
187
        return NULL;
15,213✔
188
      }
189
    }
190
  }
191

192
  // 1. close current opened time window
193
  if (pResultRowInfo->cur.pageId != -1 && ((pResult == NULL) || (pResult->pageId != pResultRowInfo->cur.pageId))) {
109,490,618✔
194
    SResultRowPosition pos = pResultRowInfo->cur;
77,721,058✔
195
    SFilePage*         pPage = getBufPage(pResultBuf, pos.pageId);
77,721,058✔
196
    if (pPage == NULL) {
76,868,520!
197
      qError("failed to get buffer, code:%s, %s", tstrerror(terrno), GET_TASKID(pTaskInfo));
×
198
      pTaskInfo->code = terrno;
×
199
      return NULL;
×
200
    }
201
    releaseBufPage(pResultBuf, pPage);
76,868,520✔
202
  }
203

204
  // allocate a new buffer page
205
  if (pResult == NULL) {
108,371,692✔
206
    pResult = getNewResultRow(pResultBuf, &pSup->currentPageId, pSup->resultRowSize);
76,019,147✔
207
    if (pResult == NULL) {
76,440,903!
208
      pTaskInfo->code = terrno;
×
209
      return NULL;
×
210
    }
211

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

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

226
  // too many time window in query
227
  if (pTaskInfo->execModel == OPTR_EXEC_MODEL_BATCH &&
221,154,441!
228
      tSimpleHashGetSize(pSup->pResultRowHashTable) > MAX_INTERVAL_TIME_WINDOW) {
110,828,422✔
229
    pTaskInfo->code = TSDB_CODE_QRY_TOO_MANY_TIMEWINDOW;
×
230
    return NULL;
×
231
  }
232

233
  return pResult;
110,326,019✔
234
}
235

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

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

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

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

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

275
int32_t setInputDataBlock(SExprSupp* pExprSup, SSDataBlock* pBlock, int32_t order, int32_t scanFlag,
6,499,463✔
276
                          bool createDummyCol) {
277
  if (pBlock->pBlockAgg != NULL) {
6,499,463✔
278
    return doSetInputDataBlockInfo(pExprSup, pBlock, order, scanFlag);
9,354✔
279
  } else {
280
    return doSetInputDataBlock(pExprSup, pBlock, order, scanFlag, createDummyCol);
6,490,109✔
281
  }
282
}
283

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

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

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

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

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

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

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

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

341
  for (int32_t i = 0; i < pExprSup->numOfExprs; ++i) {
27,089,055✔
342
    pCtx[i].order = order;
20,599,733✔
343
    pCtx[i].input.numOfRows = pBlock->info.rows;
20,599,733✔
344

345
    pCtx[i].pSrcBlock = pBlock;
20,599,733✔
346
    pCtx[i].scanFlag = scanFlag;
20,599,733✔
347

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

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

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

359
    for (int32_t j = 0; j < pOneExpr->base.numOfParams; ++j) {
41,745,761✔
360
      SFunctParam* pFuncParam = &pOneExpr->base.pParam[j];
21,146,549✔
361
      if (pFuncParam->type == FUNC_PARAM_TYPE_COLUMN) {
21,146,549✔
362
        int32_t slotId = pFuncParam->pCol->slotId;
18,902,067✔
363
        pInput->pData[j] = taosArrayGet(pBlock->pDataBlock, slotId);
18,902,067✔
364
        pInput->totalRows = pBlock->info.rows;
18,901,829✔
365
        pInput->numOfRows = pBlock->info.rows;
18,901,829✔
366
        pInput->startRowIndex = 0;
18,901,829✔
367
        pInput->blankFill = pBlock->info.blankFill;
18,901,829✔
368

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

372
        if (fmIsImplicitTsFunc(pCtx[i].functionId) && (j == tsParamIdx)) {
18,901,829✔
373
          pInput->pPTS = pInput->pData[j];  // in case of merge function, this is not always the ts column data.
878,490✔
374
        }
375
        if (hasPk && (j == pkParamIdx)) {
18,901,546✔
376
          pInput->pPrimaryKey = pInput->pData[j];
30,343✔
377
        }
378
        QUERY_CHECK_CONDITION((pInput->pData[j] != NULL), code, lino, _end, TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR);
18,901,546!
379
      } else if (pFuncParam->type == FUNC_PARAM_TYPE_VALUE) {
2,244,482✔
380
        // todo avoid case: top(k, 12), 12 is the value parameter.
381
        // sum(11), 11 is also the value parameter.
382
        if (createDummyCol && pOneExpr->base.numOfParams == 1) {
1,097,099!
383
          pInput->totalRows = pBlock->info.rows;
×
384
          pInput->numOfRows = pBlock->info.rows;
×
385
          pInput->startRowIndex = 0;
×
386
          pInput->blankFill = pBlock->info.blankFill;
×
387

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

395
_end:
6,489,322✔
396
  if (code != TSDB_CODE_SUCCESS) {
6,489,322!
397
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
×
398
  }
399
  return code;
6,491,450✔
400
}
401

402
bool functionNeedToExecute(SqlFunctionCtx* pCtx) {
443,806,893✔
403
  struct SResultRowEntryInfo* pResInfo = GET_RES_INFO(pCtx);
443,806,893✔
404

405
  // in case of timestamp column, always generated results.
406
  int32_t functionId = pCtx->functionId;
443,806,893✔
407
  if (functionId == -1) {
443,806,893✔
408
    return false;
22,880,527✔
409
  }
410

411
  if (pCtx->scanFlag == PRE_SCAN) {
420,926,366✔
412
    return fmIsRepeatScanFunc(pCtx->functionId);
16,415✔
413
  }
414

415
  if (isRowEntryCompleted(pResInfo)) {
420,909,951✔
416
    return false;
38✔
417
  }
418

419
  return true;
420,909,913✔
420
}
421

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

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

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

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

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

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

469
  return TSDB_CODE_SUCCESS;
×
470
}
471

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

477
  SInputColumnInfoData* pInput = &pCtx->input;
9,359✔
478
  pInput->numOfRows = numOfRows;
9,359✔
479
  pInput->totalRows = numOfRows;
9,359✔
480

481
  if (pBlock->pBlockAgg != NULL) {
9,359!
482
    pInput->colDataSMAIsSet = true;
9,359✔
483

484
    for (int32_t j = 0; j < pExprInfo->base.numOfParams; ++j) {
18,718✔
485
      SFunctParam* pFuncParam = &pExprInfo->base.pParam[j];
9,358✔
486

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

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

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

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

518
  /*
519
   * if the realSkey > INT64_MAX - pInterval->interval, the query duration between
520
   * realSkey and realEkey must be less than one interval.Therefore, no need to adjust the query ranges.
521
   */
522
  win.ekey = taosTimeGetIntervalEnd(win.skey, pInterval);
31,481,931✔
523
  if (win.ekey < win.skey) {
31,460,137✔
524
    win.ekey = INT64_MAX;
1,666✔
525
  }
526

527
  return win;
31,460,137✔
528
}
529

530
int32_t setResultRowInitCtx(SResultRow* pResult, SqlFunctionCtx* pCtx, int32_t numOfOutput,
129,265,106✔
531
                            int32_t* rowEntryInfoOffset) {
532
  bool init = false;
129,265,106✔
533
  for (int32_t i = 0; i < numOfOutput; ++i) {
749,629,018✔
534
    pCtx[i].resultInfo = getResultEntryInfo(pResult, i, rowEntryInfoOffset);
621,420,815✔
535
    if (init) {
621,855,736✔
536
      continue;
94,348,767✔
537
    }
538

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

544
    if (pCtx[i].isPseudoFunc) {
527,506,969✔
545
      continue;
177,884,140✔
546
    }
547

548
    if (!pResInfo->initialized) {
349,622,829✔
549
      if (pCtx[i].functionId != -1) {
323,378,134✔
550
        int32_t code = pCtx[i].fpSet.init(&pCtx[i], pResInfo);
309,297,402✔
551
        if (code != TSDB_CODE_SUCCESS && fmIsUserDefinedFunc(pCtx[i].functionId)) {
309,566,029!
552
          pResInfo->initialized = false;
1,760,451✔
553
          qError("failed to initialize udf, funcId:%d error:%s", pCtx[i].functionId, tstrerror(code));
1,760,451!
554
          return TSDB_CODE_UDF_FUNC_EXEC_FAILURE;
×
555
        } else if (code != TSDB_CODE_SUCCESS) {
307,805,578!
556
          qError("failed to initialize function context, funcId:%d error:%s", pCtx[i].functionId, tstrerror(code));
×
557
          return code;
×
558
        }
559
      } else {
560
        pResInfo->initialized = true;
14,080,732✔
561
      }
562
    } else {
563
      init = true;
26,244,695✔
564
    }
565
  }
566
  return TSDB_CODE_SUCCESS;
128,208,203✔
567
}
568

569
void clearResultRowInitFlag(SqlFunctionCtx* pCtx, int32_t numOfOutput) {
445✔
570
  for (int32_t i = 0; i < numOfOutput; ++i) {
1,927✔
571
    SResultRowEntryInfo* pResInfo = pCtx[i].resultInfo;
1,482✔
572
    if (pResInfo == NULL) {
1,482!
573
      continue;
×
574
    }
575

576
    pResInfo->initialized = false;
1,482✔
577
    pResInfo->numOfRes = 0;
1,482✔
578
    pResInfo->isNullRes = 0;
1,482✔
579
    pResInfo->complete = false;
1,482✔
580
  }
581
}
445✔
582

583
int32_t doFilter(SSDataBlock* pBlock, SFilterInfo* pFilterInfo, SColMatchInfo* pColMatchInfo) {
8,502,054✔
584
  int32_t code = TSDB_CODE_SUCCESS;
8,502,054✔
585
  int32_t lino = 0;
8,502,054✔
586
  if (pFilterInfo == NULL || pBlock->info.rows == 0) {
8,502,054✔
587
    return TSDB_CODE_SUCCESS;
7,340,441✔
588
  }
589

590
  SFilterColumnParam param1 = {.numOfCols = taosArrayGetSize(pBlock->pDataBlock), .pDataBlock = pBlock->pDataBlock};
1,161,613✔
591
  SColumnInfoData*   p = NULL;
1,161,587✔
592

593
  code = filterSetDataFromSlotId(pFilterInfo, &param1);
1,161,587✔
594
  QUERY_CHECK_CODE(code, lino, _err);
1,161,528!
595

596
  int32_t status = 0;
1,161,528✔
597
  code = filterExecute(pFilterInfo, pBlock, &p, NULL, param1.numOfCols, &status);
1,161,528✔
598
  QUERY_CHECK_CODE(code, lino, _err);
1,161,449!
599

600
  code = extractQualifiedTupleByFilterResult(pBlock, p, status);
1,161,449✔
601
  QUERY_CHECK_CODE(code, lino, _err);
1,161,430!
602

603
  if (pColMatchInfo != NULL) {
1,161,430✔
604
    size_t size = taosArrayGetSize(pColMatchInfo->pList);
551,616✔
605
    for (int32_t i = 0; i < size; ++i) {
556,780✔
606
      SColMatchItem* pInfo = taosArrayGet(pColMatchInfo->pList, i);
554,375✔
607
      QUERY_CHECK_NULL(pInfo, code, lino, _err, terrno);
554,412!
608
      if (pInfo->colId == PRIMARYKEY_TIMESTAMP_COL_ID) {
554,412✔
609
        SColumnInfoData* pColData = taosArrayGet(pBlock->pDataBlock, pInfo->dstSlotId);
549,262✔
610
        QUERY_CHECK_NULL(pColData, code, lino, _err, terrno);
549,258!
611
        if (pColData->info.type == TSDB_DATA_TYPE_TIMESTAMP) {
549,263!
612
          code = blockDataUpdateTsWindow(pBlock, pInfo->dstSlotId);
549,263✔
613
          QUERY_CHECK_CODE(code, lino, _err);
549,238!
614
          break;
549,238✔
615
        }
616
      }
617
    }
618
  }
619
  code = blockDataCheck(pBlock);
1,161,457✔
620
  QUERY_CHECK_CODE(code, lino, _err);
1,161,431!
621
_err:
1,161,431✔
622
  if (code != TSDB_CODE_SUCCESS) {
1,161,431!
623
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
×
624
  }
625
  colDataDestroy(p);
1,161,431✔
626
  taosMemoryFree(p);
1,161,708!
627
  return code;
1,161,745✔
628
}
629

630
int32_t extractQualifiedTupleByFilterResult(SSDataBlock* pBlock, const SColumnInfoData* p, int32_t status) {
1,161,515✔
631
  int32_t code = TSDB_CODE_SUCCESS;
1,161,515✔
632
  int8_t* pIndicator = (int8_t*)p->pData;
1,161,515✔
633
  if (status == FILTER_RESULT_ALL_QUALIFIED) {
1,161,515✔
634
    // here nothing needs to be done
635
  } else if (status == FILTER_RESULT_NONE_QUALIFIED) {
726,160✔
636
    code = trimDataBlock(pBlock, pBlock->info.rows, NULL);
85,255✔
637
    pBlock->info.rows = 0;
85,209✔
638
  } else if (status == FILTER_RESULT_PARTIAL_QUALIFIED) {
640,905!
639
    code = trimDataBlock(pBlock, pBlock->info.rows, (bool*)pIndicator);
640,929✔
640
  } else {
641
    qError("unknown filter result type: %d", status);
×
642
  }
643
  return code;
1,161,636✔
644
}
645

646
void doUpdateNumOfRows(SqlFunctionCtx* pCtx, SResultRow* pRow, int32_t numOfExprs, const int32_t* rowEntryOffset) {
96,150,570✔
647
  bool returnNotNull = false;
96,150,570✔
648
  for (int32_t j = 0; j < numOfExprs; ++j) {
551,465,963✔
649
    SResultRowEntryInfo* pResInfo = getResultEntryInfo(pRow, j, rowEntryOffset);
455,270,257✔
650
    if (!isRowEntryInitialized(pResInfo)) {
455,315,393✔
651
      continue;
131,913,157✔
652
    } else {
653
    }
654

655
    if (pRow->numOfRows < pResInfo->numOfRes) {
323,402,236✔
656
      pRow->numOfRows = pResInfo->numOfRes;
93,463,174✔
657
    }
658

659
    if (pCtx[j].isNotNullFunc) {
323,402,236✔
660
      returnNotNull = true;
101,439,911✔
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) {
96,195,706✔
666
    pRow->numOfRows = 1;
33,169✔
667
  }
668
}
96,195,706✔
669

670
int32_t copyResultrowToDataBlock(SExprInfo* pExprInfo, int32_t numOfExprs, SResultRow* pRow, SqlFunctionCtx* pCtx,
87,066,018✔
671
                                 SSDataBlock* pBlock, const int32_t* rowEntryOffset, SExecTaskInfo* pTaskInfo) {
672
  int32_t code = TSDB_CODE_SUCCESS;
87,066,018✔
673
  int32_t lino = 0;
87,066,018✔
674
  for (int32_t j = 0; j < numOfExprs; ++j) {
492,119,592✔
675
    int32_t slotId = pExprInfo[j].base.resSchema.slotId;
403,325,378✔
676

677
    pCtx[j].resultInfo = getResultEntryInfo(pRow, j, rowEntryOffset);
403,325,378✔
678
    if (pCtx[j].fpSet.finalize) {
403,856,988✔
679
      if (strcmp(pCtx[j].pExpr->pExpr->_function.functionName, "_group_key") == 0 ||
280,023,670✔
680
          strcmp(pCtx[j].pExpr->pExpr->_function.functionName, "_group_const_value") == 0) {
187,451,276✔
681
        // for groupkey along with functions that output multiple lines(e.g. Histogram)
682
        // need to match groupkey result for each output row of that function.
683
        if (pCtx[j].resultInfo->numOfRes != 0) {
92,573,396!
684
          pCtx[j].resultInfo->numOfRes = pRow->numOfRows;
93,752,480✔
685
        }
686
      }
687

688
      code = blockDataEnsureCapacity(pBlock, pBlock->info.rows + pCtx[j].resultInfo->numOfRes);
280,023,670✔
689
      QUERY_CHECK_CODE(code, lino, _end);
280,301,455!
690

691
      code = pCtx[j].fpSet.finalize(&pCtx[j], pBlock);
280,301,455✔
692
      if (TSDB_CODE_SUCCESS != code) {
282,249,692!
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) {
123,833,318!
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);
128,964,681✔
702
      QUERY_CHECK_NULL(pColInfoData, code, lino, _end, terrno);
128,246,599✔
703
      char*            in = GET_ROWCELL_INTERBUF(pCtx[j].resultInfo);
128,068,618✔
704
      for (int32_t k = 0; k < pRow->numOfRows; ++k) {
256,797,189✔
705
        code = colDataSetValOrCover(pColInfoData, pBlock->info.rows + k, in, pCtx[j].resultInfo->isNullRes);
128,148,574✔
706
        QUERY_CHECK_CODE(code, lino, _end);
128,728,571!
707
      }
708
    }
709
  }
710

711
_end:
88,794,214✔
712
  if (code != TSDB_CODE_SUCCESS) {
88,794,214!
713
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
×
714
  }
715
  return code;
89,225,779✔
716
}
717

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

729
  SqlFunctionCtx* pCtx = pSup->pCtx;
12,323,912✔
730
  SExprInfo*      pExprInfo = pSup->pExprInfo;
12,323,912✔
731
  const int32_t*  rowEntryOffset = pSup->rowEntryInfoOffset;
12,323,912✔
732

733
  doUpdateNumOfRows(pCtx, pRow, pSup->numOfExprs, rowEntryOffset);
12,323,912✔
734
  if (pRow->numOfRows == 0) {
12,303,629!
735
    releaseBufPage(pBuf, page);
×
736
    return;
×
737
  }
738

739
  int32_t size = pBlock->info.capacity;
12,304,186✔
740
  while (pBlock->info.rows + pRow->numOfRows > size) {
12,307,927✔
741
    size = size * 1.25;
3,741✔
742
  }
743

744
  int32_t code = blockDataEnsureCapacity(pBlock, size);
12,304,186✔
745
  if (TAOS_FAILED(code)) {
12,310,402!
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);
12,310,402✔
752
  if (TAOS_FAILED(code)) {
12,301,706!
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);
12,301,706✔
759
  pBlock->info.rows += pRow->numOfRows;
12,307,186✔
760
}
761

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

771
  size_t  keyLen = 0;
1,253,634✔
772
  int32_t numOfRows = tSimpleHashGetSize(pHashmap);
1,253,634✔
773

774
  // begin from last iter
775
  void*   pData = pGroupResInfo->dataPos;
1,249,563✔
776
  int32_t iter = pGroupResInfo->iter;
1,249,563✔
777
  while ((pData = tSimpleHashIterate(pHashmap, pData, &iter)) != NULL) {
6,411,620✔
778
    void*               key = tSimpleHashGetKey(pData, &keyLen);
6,257,106✔
779
    SResultRowPosition* pos = pData;
6,257,106✔
780
    uint64_t            groupId = *(uint64_t*)key;
6,257,106✔
781

782
    SFilePage* page = getBufPage(pBuf, pos->pageId);
6,257,106✔
783
    if (page == NULL) {
6,246,873!
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);
6,246,873✔
789

790
    doUpdateNumOfRows(pCtx, pRow, numOfExprs, rowEntryOffset);
6,246,873✔
791

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

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

802
    if (!ignoreGroup) {
6,213,265✔
803
      if (pBlock->info.id.groupId == 0) {
2,179,238✔
804
        pBlock->info.id.groupId = groupId;
1,116,974✔
805
      } else {
806
        // current value belongs to different group, it can't be packed into one datablock
807
        if (pBlock->info.id.groupId != groupId) {
1,062,264!
808
          releaseBufPage(pBuf, page);
1,079,796✔
809
          break;
1,080,997✔
810
        }
811
      }
812
    }
813

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

827
    code = copyResultrowToDataBlock(pExprInfo, numOfExprs, pRow, pCtx, pBlock, rowEntryOffset, pTaskInfo);
5,133,469✔
828
    releaseBufPage(pBuf, page);
5,164,287✔
829
    QUERY_CHECK_CODE(code, lino, _end);
5,162,087!
830
    pBlock->info.rows += pRow->numOfRows;
5,162,087✔
831
    if (pBlock->info.rows >= threshold) {
5,162,087✔
832
      break;
30✔
833
    }
834
  }
835

836
  qDebug("%s result generated, rows:%" PRId64 ", groupId:%" PRIu64, GET_TASKID(pTaskInfo), pBlock->info.rows,
1,233,538✔
837
         pBlock->info.id.groupId);
838
  pBlock->info.dataLoad = 1;
1,233,541✔
839
  code = blockDataUpdateTsWindow(pBlock, 0);
1,233,541✔
840
  QUERY_CHECK_CODE(code, lino, _end);
1,235,951!
841

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

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

858
  int32_t numOfRows = getNumOfTotalRes(pGroupResInfo);
871,034✔
859

860
  for (int32_t i = pGroupResInfo->index; i < numOfRows; i += 1) {
72,305,097✔
861
    SResKeyPos* pPos = taosArrayGetP(pGroupResInfo->pRows, i);
71,730,328✔
862
    SFilePage*  page = getBufPage(pBuf, pPos->pos.pageId);
71,443,522✔
863
    if (page == NULL) {
70,917,591!
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);
70,917,591✔
869

870
    doUpdateNumOfRows(pCtx, pRow, numOfExprs, rowEntryOffset);
70,917,591✔
871

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

887
    if (!ignoreGroup) {
69,433,651✔
888
      if (pBlock->info.id.groupId == 0) {
32,668,044✔
889
        pBlock->info.id.groupId = pPos->groupId;
17,797,295✔
890
      } else {
891
        // current value belongs to different group, it can't be packed into one datablock
892
        if (pBlock->info.id.groupId != pPos->groupId) {
14,870,749✔
893
          releaseBufPage(pBuf, page);
117,801✔
894
          break;
117,790✔
895
        }
896
      }
897
    }
898

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

908
    pGroupResInfo->index += 1;
69,315,850✔
909
    code = copyResultrowToDataBlock(pExprInfo, numOfExprs, pRow, pCtx, pBlock, rowEntryOffset, pTaskInfo);
69,315,850✔
910
    releaseBufPage(pBuf, page);
71,983,527✔
911
    QUERY_CHECK_CODE(code, lino, _end);
71,608,209!
912

913
    pBlock->info.rows += pRow->numOfRows;
71,608,209✔
914
    if (pBlock->info.rows >= threshold) {
71,608,209✔
915
      break;
174,898✔
916
    }
917
  }
918

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

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

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

937
  // set output datablock version
938
  pBlock->info.version = pTaskInfo->version;
983,494✔
939

940
  blockDataCleanup(pBlock);
983,494✔
941
  if (!hasRemainResults(pGroupResInfo)) {
983,703✔
942
    return;
112,544✔
943
  }
944

945
  // clear the existed group id
946
  pBlock->info.id.groupId = 0;
871,145✔
947
  if (!pbInfo->mergeResultBlock) {
871,145✔
948
    doCopyToSDataBlock(pTaskInfo, pBlock, &pOperator->exprSupp, pBuf, pGroupResInfo, pOperator->resultInfo.threshold,
353,766✔
949
                       false, getMinWindowSize(pOperator));
950
  } else {
951
    while (hasRemainResults(pGroupResInfo)) {
938,471✔
952
      doCopyToSDataBlock(pTaskInfo, pBlock, &pOperator->exprSupp, pBuf, pGroupResInfo, pOperator->resultInfo.threshold,
517,342✔
953
                         true, getMinWindowSize(pOperator));
954
      if (pBlock->info.rows >= pOperator->resultInfo.threshold) {
517,351✔
955
        break;
96,259✔
956
      }
957

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

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

967
void destroyExprInfo(SExprInfo* pExpr, int32_t numOfExprs) {
2,104,312✔
968
  for (int32_t i = 0; i < numOfExprs; ++i) {
7,190,255✔
969
    SExprInfo* pExprInfo = &pExpr[i];
5,085,576✔
970
    for (int32_t j = 0; j < pExprInfo->base.numOfParams; ++j) {
10,778,451✔
971
      if (pExprInfo->base.pParam[j].type == FUNC_PARAM_TYPE_COLUMN) {
5,693,070✔
972
        taosMemoryFreeClear(pExprInfo->base.pParam[j].pCol);
4,340,693!
973
      } else if (pExprInfo->base.pParam[j].type == FUNC_PARAM_TYPE_VALUE) {
1,352,377✔
974
        taosVariantDestroy(&pExprInfo->base.pParam[j].param);
801,117✔
975
      }
976
    }
977

978
    taosMemoryFree(pExprInfo->base.pParam);
5,085,381!
979
    taosMemoryFree(pExprInfo->pExpr);
5,085,803!
980
  }
981
}
2,104,679✔
982

983
int32_t getBufferPgSize(int32_t rowSize, uint32_t* defaultPgsz, int64_t* defaultBufsz) {
1,435,599✔
984
  *defaultPgsz = 4096;
1,435,599✔
985
  uint32_t last = *defaultPgsz;
1,435,599✔
986
  while (*defaultPgsz < rowSize * 4) {
1,839,506✔
987
    *defaultPgsz <<= 1u;
403,907✔
988
    if (*defaultPgsz < last) {
403,907!
989
      return TSDB_CODE_INVALID_PARA;
×
990
    }
991
    last = *defaultPgsz;
403,907✔
992
  }
993

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

1005
  return 0;
1,435,599✔
1006
}
1007

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

1013
  pResultInfo->capacity = numOfRows;
3,062,756✔
1014
  pResultInfo->threshold = numOfRows * 0.75;
3,062,756✔
1015

1016
  if (pResultInfo->threshold == 0) {
3,062,756✔
1017
    pResultInfo->threshold = numOfRows;
2,621✔
1018
  }
1019
}
3,062,756✔
1020

1021
void initBasicInfo(SOptrBasicInfo* pInfo, SSDataBlock* pBlock) {
1,419,882✔
1022
  pInfo->pRes = pBlock;
1,419,882✔
1023
  initResultRowInfo(&pInfo->resultRowInfo);
1,419,882✔
1024
}
1,419,836✔
1025

1026
static void destroySqlFunctionCtx(SqlFunctionCtx* pCtx, SExprInfo* pExpr, int32_t numOfOutput) {
6,186,774✔
1027
  if (pCtx == NULL) {
6,186,774✔
1028
    return;
3,911,494✔
1029
  }
1030

1031
  for (int32_t i = 0; i < numOfOutput; ++i) {
7,239,858✔
1032
    if (pExpr != NULL) {
4,963,976!
1033
      SExprInfo* pExprInfo = &pExpr[i];
4,964,249✔
1034
      for (int32_t j = 0; j < pExprInfo->base.numOfParams; ++j) {
10,535,203✔
1035
        if (pExprInfo->base.pParam[j].type == FUNC_PARAM_TYPE_VALUE) {
5,571,513✔
1036
          taosMemoryFree(pCtx[i].input.pData[j]);
798,274!
1037
          taosMemoryFree(pCtx[i].input.pColumnDataAgg[j]);
798,273✔
1038
        }
1039
      }
1040
    }
1041
    for (int32_t j = 0; j < pCtx[i].numOfParams; ++j) {
10,534,394✔
1042
      taosVariantDestroy(&pCtx[i].param[j].param);
5,570,971✔
1043
    }
1044

1045
    taosMemoryFreeClear(pCtx[i].subsidiaries.pCtx);
4,963,423!
1046
    taosMemoryFreeClear(pCtx[i].subsidiaries.buf);
4,963,424!
1047
    taosMemoryFree(pCtx[i].input.pData);
4,963,424✔
1048
    taosMemoryFree(pCtx[i].input.pColumnDataAgg);
4,964,537!
1049

1050
    if (pCtx[i].udfName != NULL) {
4,964,612✔
1051
      taosMemoryFree(pCtx[i].udfName);
32!
1052
    }
1053
  }
1054

1055
  taosMemoryFreeClear(pCtx);
2,275,882!
1056
  return;
2,275,892✔
1057
}
1058

1059
int32_t initExprSupp(SExprSupp* pSup, SExprInfo* pExprInfo, int32_t numOfExpr, SFunctionStateStore* pStore) {
2,312,745✔
1060
  pSup->pExprInfo = pExprInfo;
2,312,745✔
1061
  pSup->numOfExprs = numOfExpr;
2,312,745✔
1062
  if (pSup->pExprInfo != NULL) {
2,312,745✔
1063
    pSup->pCtx = createSqlFunctionCtx(pExprInfo, numOfExpr, &pSup->rowEntryInfoOffset, pStore);
1,721,210✔
1064
    if (pSup->pCtx == NULL) {
1,720,910!
1065
      return terrno;
×
1066
    }
1067
  }
1068

1069
  return TSDB_CODE_SUCCESS;
2,312,860✔
1070
}
1071

1072
void cleanupExprSupp(SExprSupp* pSupp) {
6,186,805✔
1073
  destroySqlFunctionCtx(pSupp->pCtx, pSupp->pExprInfo, pSupp->numOfExprs);
6,186,805✔
1074
  if (pSupp->pExprInfo != NULL) {
6,186,816✔
1075
    destroyExprInfo(pSupp->pExprInfo, pSupp->numOfExprs);
2,100,329✔
1076
    taosMemoryFreeClear(pSupp->pExprInfo);
2,100,339!
1077
  }
1078

1079
  if (pSupp->pFilterInfo != NULL) {
6,186,912✔
1080
    filterFreeInfo(pSupp->pFilterInfo);
390,124✔
1081
    pSupp->pFilterInfo = NULL;
390,134✔
1082
  }
1083

1084
  taosMemoryFree(pSupp->rowEntryInfoOffset);
6,186,922✔
1085
}
6,186,775✔
1086

1087
void cleanupBasicInfo(SOptrBasicInfo* pInfo) {
1,438,378✔
1088
  blockDataDestroy(pInfo->pRes);
1,438,378✔
1089
  pInfo->pRes = NULL;
1,438,440✔
1090
}
1,438,440✔
1091

1092
bool groupbyTbname(SNodeList* pGroupList) {
1,170,655✔
1093
  bool bytbname = false;
1,170,655✔
1094
  SNode*pNode = NULL;
1,170,655✔
1095
  FOREACH(pNode, pGroupList) {
1,216,190✔
1096
    if (pNode->type == QUERY_NODE_FUNCTION) {
254,886✔
1097
      bytbname = (strcmp(((struct SFunctionNode*)pNode)->functionName, "tbname") == 0);
209,351✔
1098
      break;
209,351✔
1099
    }
1100
  }
1101
  return bytbname;
1,170,655✔
1102
}
1103

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

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

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

1129
      STableListInfo* pTableListInfo = taosArrayGetP(pInfoList, 0);
63,821✔
1130
      taosArrayDestroy(pInfoList);
63,818✔
1131

1132
      pDeleterParam->suid = tableListGetSuid(pTableListInfo);
63,822✔
1133

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

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

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

1164
      *pParam = pDeleterParam;
63,820✔
1165
      break;
63,820✔
1166
    }
1167
    default:
1,757,141✔
1168
      break;
1,757,141✔
1169
  }
1170

1171
  return TSDB_CODE_SUCCESS;
1,821,084✔
1172
}
1173

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

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

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

1195
  taosArrayDestroy(pParam->pChildren);
65,914✔
1196

1197
  taosMemoryFree(pParam->value);
65,914!
1198

1199
  taosMemoryFree(pParam);
65,914!
1200
}
65,914✔
1201

1202
void freeExchangeGetBasicOperatorParam(void* pParam) {
1,016✔
1203
  SExchangeOperatorBasicParam* pBasic = (SExchangeOperatorBasicParam*)pParam;
1,016✔
1204
  taosArrayDestroy(pBasic->uidList);
1,016✔
1205
}
1,016✔
1206

1207
void freeExchangeGetOperatorParam(SOperatorParam* pParam) {
647✔
1208
  SExchangeOperatorParam* pExcParam = (SExchangeOperatorParam*)pParam->value;
647✔
1209
  if (pExcParam->multiParams) {
647✔
1210
    SExchangeOperatorBatchParam* pExcBatch = (SExchangeOperatorBatchParam*)pParam->value;
599✔
1211
    tSimpleHashCleanup(pExcBatch->pBatchs);
599✔
1212
  } else {
1213
    freeExchangeGetBasicOperatorParam(&pExcParam->basic);
48✔
1214
  }
1215

1216
  freeOperatorParamImpl(pParam, OP_GET_PARAM);
647✔
1217
}
647✔
1218

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

1221
void freeGroupCacheGetOperatorParam(SOperatorParam* pParam) { freeOperatorParamImpl(pParam, OP_GET_PARAM); }
42,124✔
1222

1223
void freeGroupCacheNotifyOperatorParam(SOperatorParam* pParam) { freeOperatorParamImpl(pParam, OP_NOTIFY_PARAM); }
×
1224

1225
void freeMergeJoinGetOperatorParam(SOperatorParam* pParam) { freeOperatorParamImpl(pParam, OP_GET_PARAM); }
21,062✔
1226

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

1229
void freeTableScanGetOperatorParam(SOperatorParam* pParam) {
2,080✔
1230
  STableScanOperatorParam* pTableScanParam = (STableScanOperatorParam*)pParam->value;
2,080✔
1231
  taosArrayDestroy(pTableScanParam->pUidList);
2,080✔
1232
  freeOperatorParamImpl(pParam, OP_GET_PARAM);
2,081✔
1233
}
2,081✔
1234

1235
void freeTableScanNotifyOperatorParam(SOperatorParam* pParam) { freeOperatorParamImpl(pParam, OP_NOTIFY_PARAM); }
×
1236

1237
void freeOperatorParam(SOperatorParam* pParam, SOperatorParamType type) {
1,133,496✔
1238
  if (NULL == pParam) {
1,133,496✔
1239
    return;
1,067,610✔
1240
  }
1241

1242
  switch (pParam->opType) {
65,886!
1243
    case QUERY_NODE_PHYSICAL_PLAN_EXCHANGE:
647✔
1244
      type == OP_GET_PARAM ? freeExchangeGetOperatorParam(pParam) : freeExchangeNotifyOperatorParam(pParam);
647!
1245
      break;
647✔
1246
    case QUERY_NODE_PHYSICAL_PLAN_GROUP_CACHE:
42,124✔
1247
      type == OP_GET_PARAM ? freeGroupCacheGetOperatorParam(pParam) : freeGroupCacheNotifyOperatorParam(pParam);
42,124!
1248
      break;
42,124✔
1249
    case QUERY_NODE_PHYSICAL_PLAN_MERGE_JOIN:
21,062✔
1250
      type == OP_GET_PARAM ? freeMergeJoinGetOperatorParam(pParam) : freeMergeJoinNotifyOperatorParam(pParam);
21,062!
1251
      break;
21,062✔
1252
    case QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN:
2,080✔
1253
      type == OP_GET_PARAM ? freeTableScanGetOperatorParam(pParam) : freeTableScanNotifyOperatorParam(pParam);
2,080!
1254
      break;
2,081✔
1255
    default:
×
1256
      qError("unsupported op %d param, type %d", pParam->opType, type);
×
1257
      break;
×
1258
  }
1259
}
1260

1261
void freeResetOperatorParams(struct SOperatorInfo* pOperator, SOperatorParamType type, bool allFree) {
7,958,141✔
1262
  SOperatorParam**  ppParam = NULL;
7,958,141✔
1263
  SOperatorParam*** pppDownstramParam = NULL;
7,958,141✔
1264
  switch (type) {
7,958,141!
1265
    case OP_GET_PARAM:
3,990,632✔
1266
      ppParam = &pOperator->pOperatorGetParam;
3,990,632✔
1267
      pppDownstramParam = &pOperator->pDownstreamGetParams;
3,990,632✔
1268
      break;
3,990,632✔
1269
    case OP_NOTIFY_PARAM:
3,968,002✔
1270
      ppParam = &pOperator->pOperatorNotifyParam;
3,968,002✔
1271
      pppDownstramParam = &pOperator->pDownstreamNotifyParams;
3,968,002✔
1272
      break;
3,968,002✔
1273
    default:
×
1274
      return;
×
1275
  }
1276

1277
  if (*ppParam) {
7,958,634✔
1278
    freeOperatorParam(*ppParam, type);
21,062✔
1279
    *ppParam = NULL;
21,062✔
1280
  }
1281

1282
  if (*pppDownstramParam) {
7,958,634✔
1283
    for (int32_t i = 0; i < pOperator->numOfDownstream; ++i) {
64,898✔
1284
      if ((*pppDownstramParam)[i]) {
42,124!
1285
        freeOperatorParam((*pppDownstramParam)[i], type);
×
1286
        (*pppDownstramParam)[i] = NULL;
×
1287
      }
1288
    }
1289
    if (allFree) {
22,774✔
1290
      taosMemoryFreeClear(*pppDownstramParam);
2,000!
1291
    }
1292
  }
1293
}
1294

1295
FORCE_INLINE int32_t getNextBlockFromDownstreamImpl(struct SOperatorInfo* pOperator, int32_t idx, bool clearParam,
8,417,791✔
1296
                                                    SSDataBlock** pResBlock) {
1297
  QRY_PARAM_CHECK(pResBlock);
8,417,791!
1298

1299
  int32_t code = 0;
8,417,791✔
1300
  if (pOperator->pDownstreamGetParams && pOperator->pDownstreamGetParams[idx]) {
8,417,791!
1301
    qDebug("DynOp: op %s start to get block from downstream %s", pOperator->name, pOperator->pDownstream[idx]->name);
63,570✔
1302
    code = pOperator->pDownstream[idx]->fpSet.getNextExtFn(pOperator->pDownstream[idx],
63,570✔
1303
                                                           pOperator->pDownstreamGetParams[idx], pResBlock);
63,570✔
1304
    if (clearParam && (code == 0)) {
63,570!
1305
      freeOperatorParam(pOperator->pDownstreamGetParams[idx], OP_GET_PARAM);
×
1306
      pOperator->pDownstreamGetParams[idx] = NULL;
×
1307
    }
1308

1309
    if (code) {
63,570!
1310
      qError("failed to get next data block from upstream at %s, line:%d code:%s", __func__, __LINE__, tstrerror(code));
×
1311
    }
1312
    return code;
63,570✔
1313
  }
1314

1315
  code = pOperator->pDownstream[idx]->fpSet.getNextFn(pOperator->pDownstream[idx], pResBlock);
8,354,221✔
1316
  if (code) {
8,355,628!
1317
    qError("failed to get next data block from upstream at %s, %d code:%s", __func__, __LINE__, tstrerror(code));
×
1318
  }
1319
  return code;
8,355,741✔
1320
}
1321

1322
bool compareVal(const char* v, const SStateKeys* pKey) {
140,776✔
1323
  if (IS_VAR_DATA_TYPE(pKey->type)) {
140,776!
1324
    if (varDataLen(v) != varDataLen(pKey->pData)) {
1,787!
1325
      return false;
×
1326
    } else {
1327
      return memcmp(varDataVal(v), varDataVal(pKey->pData), varDataLen(v)) == 0;
1,787✔
1328
    }
1329
  } else {
1330
    return memcmp(pKey->pData, v, pKey->bytes) == 0;
138,989✔
1331
  }
1332
}
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