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

taosdata / TDengine / #3548

04 Dec 2024 01:03PM UTC coverage: 59.846% (-0.8%) from 60.691%
#3548

push

travis-ci

web-flow
Merge pull request #29033 from taosdata/fix/calculate-vnode-memory-used

fix/calculate-vnode-memory-used

118484 of 254183 branches covered (46.61%)

Branch coverage included in aggregate %.

199691 of 277471 relevant lines covered (71.97%)

18794141.86 hits per line

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

68.58
/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) {
231,770,492✔
86
  SFilePage* pData = NULL;
231,770,492✔
87

88
  // in the first scan, new space needed for results
89
  int32_t pageId = -1;
231,770,492✔
90
  if (*currentPageId == -1) {
231,770,492✔
91
    pData = getNewBufPage(pResultBuf, &pageId);
5,096,299✔
92
    if (pData == NULL) {
5,096,519✔
93
      qError("failed to get buffer, code:%s", tstrerror(terrno));
133!
94
      return NULL;
×
95
    }
96
    pData->num = sizeof(SFilePage);
5,096,386✔
97
  } else {
98
    pData = getBufPage(pResultBuf, *currentPageId);
226,674,193✔
99
    if (pData == NULL) {
226,632,929!
100
      qError("failed to get buffer, code:%s", tstrerror(terrno));
×
101
      return NULL;
×
102
    }
103

104
    pageId = *currentPageId;
226,632,929✔
105

106
    if (pData->num + interBufSize > getBufPageSize(pResultBuf)) {
226,632,929✔
107
      // release current page first, and prepare the next one
108
      releaseBufPage(pResultBuf, pData);
15,170,582✔
109

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

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

123
  setBufPageDirty(pData, true);
231,900,386✔
124

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

128
  memset((char*)pResultRow, 0, interBufSize);
231,583,001✔
129
  pResultRow->pageId = pageId;
231,583,001✔
130
  pResultRow->offset = (int32_t)pData->num;
231,583,001✔
131

132
  *currentPageId = pageId;
231,583,001✔
133
  pData->num += interBufSize;
231,583,001✔
134
  return pResultRow;
231,583,001✔
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,
294,031,829✔
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);
294,031,829✔
148
  if (!keepGroup) {
294,031,829✔
149
    *(uint64_t*)pSup->keyBuf = calcGroupId(pSup->keyBuf, GET_RES_WINDOW_KEY_LEN(bytes));
17,934,877✔
150
  }
151

152
  SResultRowPosition* p1 =
153
      (SResultRowPosition*)tSimpleHashGet(pSup->pResultRowHashTable, pSup->keyBuf, GET_RES_WINDOW_KEY_LEN(bytes));
294,315,440✔
154

155
  SResultRow* pResult = NULL;
293,852,517✔
156

157
  // in case of repeat scan/reverse scan, no new time window added.
158
  if (isIntervalQuery) {
293,852,517✔
159
    if (p1 != NULL) {  // the *p1 may be NULL in case of sliding+offset exists.
271,391,749✔
160
      pResult = getResultRowByPos(pResultBuf, p1, true);
53,102,223✔
161
      if (pResult == NULL) {
53,102,223!
162
        pTaskInfo->code = terrno;
×
163
        return NULL;
×
164
      }
165

166
      if (pResult->pageId != p1->pageId || pResult->offset != p1->offset) {
53,102,223!
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) {
22,460,768✔
176
      // todo
177
      pResult = getResultRowByPos(pResultBuf, p1, true);
8,218,328✔
178
      if (NULL == pResult) {
8,218,328!
179
        pTaskInfo->code = terrno;
×
180
        return NULL;
×
181
      }
182

183
      if (pResult->pageId != p1->pageId || pResult->offset != p1->offset) {
8,218,328!
184
        terrno = TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR;
×
185
        pTaskInfo->code = terrno;
×
186
        return NULL;
8,830✔
187
      }
188
    }
189
  }
190

191
  // 1. close current opened time window
192
  if (pResultRowInfo->cur.pageId != -1 && ((pResult == NULL) || (pResult->pageId != pResultRowInfo->cur.pageId))) {
293,629,666✔
193
    SResultRowPosition pos = pResultRowInfo->cur;
232,521,602✔
194
    SFilePage*         pPage = getBufPage(pResultBuf, pos.pageId);
232,521,602✔
195
    if (pPage == NULL) {
232,037,462!
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);
232,037,462✔
201
  }
202

203
  // allocate a new buffer page
204
  if (pResult == NULL) {
292,475,481✔
205
    pResult = getNewResultRow(pResultBuf, &pSup->currentPageId, pSup->resultRowSize);
231,346,786✔
206
    if (pResult == NULL) {
231,789,942!
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};
231,789,942✔
213
    int32_t code = tSimpleHashPut(pSup->pResultRowHashTable, pSup->keyBuf, GET_RES_WINDOW_KEY_LEN(bytes), &pos,
231,789,942✔
214
                                  sizeof(SResultRowPosition));
215
    if (code != TSDB_CODE_SUCCESS) {
234,266,633✔
216
      qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(code));
53,713!
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};
295,341,615✔
224

225
  // too many time window in query
226
  if (pTaskInfo->execModel == OPTR_EXEC_MODEL_BATCH &&
590,056,118!
227
      tSimpleHashGetSize(pSup->pResultRowHashTable) > MAX_INTERVAL_TIME_WINDOW) {
295,304,286✔
228
    pTaskInfo->code = TSDB_CODE_QRY_TOO_MANY_TIMEWINDOW;
×
229
    return NULL;
×
230
  }
231

232
  return pResult;
294,751,832✔
233
}
234

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

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

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

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

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

274
int32_t setInputDataBlock(SExprSupp* pExprSup, SSDataBlock* pBlock, int32_t order, int32_t scanFlag,
28,722,253✔
275
                          bool createDummyCol) {
276
  if (pBlock->pBlockAgg != NULL) {
28,722,253✔
277
    return doSetInputDataBlockInfo(pExprSup, pBlock, order, scanFlag);
2,357,701✔
278
  } else {
279
    return doSetInputDataBlock(pExprSup, pBlock, order, scanFlag, createDummyCol);
26,364,552✔
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,
26,364,589✔
335
                                   bool createDummyCol) {
336
  int32_t         code = TSDB_CODE_SUCCESS;
26,364,589✔
337
  int32_t         lino = 0;
26,364,589✔
338
  SqlFunctionCtx* pCtx = pExprSup->pCtx;
26,364,589✔
339

340
  for (int32_t i = 0; i < pExprSup->numOfExprs; ++i) {
91,086,501✔
341
    pCtx[i].order = order;
64,725,970✔
342
    pCtx[i].input.numOfRows = pBlock->info.rows;
64,725,970✔
343

344
    pCtx[i].pSrcBlock = pBlock;
64,725,970✔
345
    pCtx[i].scanFlag = scanFlag;
64,725,970✔
346

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

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

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

358
    for (int32_t j = 0; j < pOneExpr->base.numOfParams; ++j) {
135,893,991✔
359
      SFunctParam* pFuncParam = &pOneExpr->base.pParam[j];
71,172,079✔
360
      if (pFuncParam->type == FUNC_PARAM_TYPE_COLUMN) {
71,172,079✔
361
        int32_t slotId = pFuncParam->pCol->slotId;
61,678,722✔
362
        pInput->pData[j] = taosArrayGet(pBlock->pDataBlock, slotId);
61,678,722✔
363
        pInput->totalRows = pBlock->info.rows;
61,669,504✔
364
        pInput->numOfRows = pBlock->info.rows;
61,669,504✔
365
        pInput->startRowIndex = 0;
61,669,504✔
366
        pInput->blankFill = pBlock->info.blankFill;
61,669,504✔
367

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

371
        if (fmIsImplicitTsFunc(pCtx[i].functionId) && (j == tsParamIdx)) {
61,669,504✔
372
          pInput->pPTS = pInput->pData[j];  // in case of merge function, this is not always the ts column data.
8,400,083✔
373
        }
374
        if (hasPk && (j == pkParamIdx)) {
61,674,664✔
375
          pInput->pPrimaryKey = pInput->pData[j];
30,336✔
376
        }
377
        QUERY_CHECK_CONDITION((pInput->pData[j] != NULL), code, lino, _end, TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR);
61,674,664!
378
      } else if (pFuncParam->type == FUNC_PARAM_TYPE_VALUE) {
9,493,357✔
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) {
8,299,213!
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:
26,360,531✔
395
  if (code != TSDB_CODE_SUCCESS) {
26,360,531!
396
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
×
397
  }
398
  return code;
26,358,170✔
399
}
400

401
bool functionNeedToExecute(SqlFunctionCtx* pCtx) {
994,005,158✔
402
  struct SResultRowEntryInfo* pResInfo = GET_RES_INFO(pCtx);
994,005,158✔
403

404
  // in case of timestamp column, always generated results.
405
  int32_t functionId = pCtx->functionId;
994,005,158✔
406
  if (functionId == -1) {
994,005,158✔
407
    return false;
36,149,651✔
408
  }
409

410
  if (pCtx->scanFlag == PRE_SCAN) {
957,855,507✔
411
    return fmIsRepeatScanFunc(pCtx->functionId);
1,519,012✔
412
  }
413

414
  if (isRowEntryCompleted(pResInfo)) {
956,336,495!
415
    return false;
×
416
  }
417

418
  return true;
956,336,495✔
419
}
420

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

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

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

448
  if (type == TSDB_DATA_TYPE_BIGINT) {
1,920,672!
449
    int64_t v = pFuncParam->param.i;
1,920,672✔
450
    *da = (SColumnDataAgg){.numOfNull = 0, .min = v, .max = v, .sum = v * numOfRows};
1,920,672✔
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;
1,920,672✔
472
}
473

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

479
  SInputColumnInfoData* pInput = &pCtx->input;
2,357,705✔
480
  pInput->numOfRows = numOfRows;
2,357,705✔
481
  pInput->totalRows = numOfRows;
2,357,705✔
482

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

486
    for (int32_t j = 0; j < pExprInfo->base.numOfParams; ++j) {
6,636,083✔
487
      SFunctParam* pFuncParam = &pExprInfo->base.pParam[j];
4,278,378✔
488

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

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

515
/////////////////////////////////////////////////////////////////////////////////////////////
516
STimeWindow getAlignQueryTimeWindow(const SInterval* pInterval, int64_t key) {
25,147,932✔
517
  STimeWindow win = {0};
25,147,932✔
518
  win.skey = taosTimeTruncate(key, pInterval);
25,147,932✔
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);
25,147,387✔
525
  if (win.ekey < win.skey) {
25,146,638✔
526
    win.ekey = INT64_MAX;
2,129✔
527
  }
528

529
  return win;
25,146,638✔
530
}
531

532
int32_t setResultRowInitCtx(SResultRow* pResult, SqlFunctionCtx* pCtx, int32_t numOfOutput,
470,687,143✔
533
                            int32_t* rowEntryInfoOffset) {
534
  bool init = false;
470,687,143✔
535
  for (int32_t i = 0; i < numOfOutput; ++i) {
1,750,209,092✔
536
    pCtx[i].resultInfo = getResultEntryInfo(pResult, i, rowEntryInfoOffset);
1,281,183,878✔
537
    if (init) {
1,281,091,942✔
538
      continue;
125,119,604✔
539
    }
540

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

546
    if (pCtx[i].isPseudoFunc) {
1,155,972,338✔
547
      continue;
285,079,212✔
548
    }
549

550
    if (!pResInfo->initialized) {
870,893,126✔
551
      if (pCtx[i].functionId != -1) {
815,980,028✔
552
        int32_t code = pCtx[i].fpSet.init(&pCtx[i], pResInfo);
793,420,627✔
553
        if (code != TSDB_CODE_SUCCESS && fmIsUserDefinedFunc(pCtx[i].functionId)) {
793,480,756!
554
          pResInfo->initialized = false;
1,630,122✔
555
          qError("failed to initialize udf, funcId:%d error:%s", pCtx[i].functionId, tstrerror(code));
1,630,122!
556
          return TSDB_CODE_UDF_FUNC_EXEC_FAILURE;
×
557
        } else if (code != TSDB_CODE_SUCCESS) {
791,850,634!
558
          qError("failed to initialize function context, funcId:%d error:%s", pCtx[i].functionId, tstrerror(code));
×
559
          return code;
×
560
        }
561
      } else {
562
        pResInfo->initialized = true;
22,559,401✔
563
      }
564
    } else {
565
      init = true;
54,913,098✔
566
    }
567
  }
568
  return TSDB_CODE_SUCCESS;
469,025,214✔
569
}
570

571
void clearResultRowInitFlag(SqlFunctionCtx* pCtx, int32_t numOfOutput) {
94,827,905✔
572
  for (int32_t i = 0; i < numOfOutput; ++i) {
242,826,636✔
573
    SResultRowEntryInfo* pResInfo = pCtx[i].resultInfo;
147,998,731✔
574
    if (pResInfo == NULL) {
147,998,731!
575
      continue;
×
576
    }
577

578
    pResInfo->initialized = false;
147,998,731✔
579
    pResInfo->numOfRes = 0;
147,998,731✔
580
    pResInfo->isNullRes = 0;
147,998,731✔
581
    pResInfo->complete = false;
147,998,731✔
582
  }
583
}
94,827,905✔
584

585
int32_t doFilter(SSDataBlock* pBlock, SFilterInfo* pFilterInfo, SColMatchInfo* pColMatchInfo) {
37,343,783✔
586
  int32_t code = TSDB_CODE_SUCCESS;
37,343,783✔
587
  int32_t lino = 0;
37,343,783✔
588
  if (pFilterInfo == NULL || pBlock->info.rows == 0) {
37,343,783✔
589
    return TSDB_CODE_SUCCESS;
31,416,830✔
590
  }
591

592
  SFilterColumnParam param1 = {.numOfCols = taosArrayGetSize(pBlock->pDataBlock), .pDataBlock = pBlock->pDataBlock};
5,926,953✔
593
  SColumnInfoData*   p = NULL;
5,926,892✔
594

595
  code = filterSetDataFromSlotId(pFilterInfo, &param1);
5,926,892✔
596
  QUERY_CHECK_CODE(code, lino, _err);
5,926,765!
597

598
  int32_t status = 0;
5,926,765✔
599
  code = filterExecute(pFilterInfo, pBlock, &p, NULL, param1.numOfCols, &status);
5,926,765✔
600
  QUERY_CHECK_CODE(code, lino, _err);
5,926,888✔
601

602
  code = extractQualifiedTupleByFilterResult(pBlock, p, status);
5,926,887✔
603
  QUERY_CHECK_CODE(code, lino, _err);
5,926,876!
604

605
  if (pColMatchInfo != NULL) {
5,926,876✔
606
    size_t size = taosArrayGetSize(pColMatchInfo->pList);
4,798,867✔
607
    for (int32_t i = 0; i < size; ++i) {
4,804,156✔
608
      SColMatchItem* pInfo = taosArrayGet(pColMatchInfo->pList, i);
4,801,736✔
609
      QUERY_CHECK_NULL(pInfo, code, lino, _err, terrno);
4,801,661!
610
      if (pInfo->colId == PRIMARYKEY_TIMESTAMP_COL_ID) {
4,801,661✔
611
        SColumnInfoData* pColData = taosArrayGet(pBlock->pDataBlock, pInfo->dstSlotId);
4,796,393✔
612
        QUERY_CHECK_NULL(pColData, code, lino, _err, terrno);
4,796,303!
613
        if (pColData->info.type == TSDB_DATA_TYPE_TIMESTAMP) {
4,796,336✔
614
          code = blockDataUpdateTsWindow(pBlock, pInfo->dstSlotId);
4,796,322✔
615
          QUERY_CHECK_CODE(code, lino, _err);
4,796,332!
616
          break;
4,796,332✔
617
        }
618
      }
619
    }
620
  }
621
  code = blockDataCheck(pBlock);
5,926,761✔
622
  QUERY_CHECK_CODE(code, lino, _err);
5,926,635!
623
_err:
5,926,635✔
624
  if (code != TSDB_CODE_SUCCESS) {
5,926,636✔
625
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
1!
626
  }
627
  colDataDestroy(p);
5,926,636✔
628
  taosMemoryFree(p);
5,927,135✔
629
  return code;
5,927,350✔
630
}
631

632
int32_t extractQualifiedTupleByFilterResult(SSDataBlock* pBlock, const SColumnInfoData* p, int32_t status) {
5,926,969✔
633
  int32_t code = TSDB_CODE_SUCCESS;
5,926,969✔
634
  int8_t* pIndicator = (int8_t*)p->pData;
5,926,969✔
635
  if (status == FILTER_RESULT_ALL_QUALIFIED) {
5,926,969✔
636
    // here nothing needs to be done
637
  } else if (status == FILTER_RESULT_NONE_QUALIFIED) {
1,462,979✔
638
    code = trimDataBlock(pBlock, pBlock->info.rows, NULL);
674,074✔
639
    pBlock->info.rows = 0;
674,052✔
640
  } else if (status == FILTER_RESULT_PARTIAL_QUALIFIED) {
788,905!
641
    code = trimDataBlock(pBlock, pBlock->info.rows, (bool*)pIndicator);
788,927✔
642
  } else {
643
    qError("unknown filter result type: %d", status);
×
644
  }
645
  return code;
5,927,088✔
646
}
647

648
void doUpdateNumOfRows(SqlFunctionCtx* pCtx, SResultRow* pRow, int32_t numOfExprs, const int32_t* rowEntryOffset) {
407,328,811✔
649
  bool returnNotNull = false;
407,328,811✔
650
  for (int32_t j = 0; j < numOfExprs; ++j) {
1,450,814,564✔
651
    SResultRowEntryInfo* pResInfo = getResultEntryInfo(pRow, j, rowEntryOffset);
1,043,697,809✔
652
    if (!isRowEntryInitialized(pResInfo)) {
1,043,485,753✔
653
      continue;
232,045,552✔
654
    } else {
655
    }
656

657
    if (pRow->numOfRows < pResInfo->numOfRes) {
811,440,201✔
658
      pRow->numOfRows = pResInfo->numOfRes;
402,386,947✔
659
    }
660

661
    if (pCtx[j].isNotNullFunc) {
811,440,201✔
662
      returnNotNull = true;
231,020,160✔
663
    }
664
  }
665
  // if all expr skips all blocks, e.g. all null inputs for max function, output one row in final result.
666
  //  except for first/last, which require not null output, output no rows
667
  if (pRow->numOfRows == 0 && !returnNotNull) {
407,116,755✔
668
    pRow->numOfRows = 1;
25,642✔
669
  }
670
}
407,116,755✔
671

672
int32_t copyResultrowToDataBlock(SExprInfo* pExprInfo, int32_t numOfExprs, SResultRow* pRow, SqlFunctionCtx* pCtx,
389,744,561✔
673
                                 SSDataBlock* pBlock, const int32_t* rowEntryOffset, SExecTaskInfo* pTaskInfo) {
674
  int32_t code = TSDB_CODE_SUCCESS;
389,744,561✔
675
  int32_t lino = 0;
389,744,561✔
676
  for (int32_t j = 0; j < numOfExprs; ++j) {
1,352,290,345✔
677
    int32_t slotId = pExprInfo[j].base.resSchema.slotId;
963,184,178✔
678

679
    pCtx[j].resultInfo = getResultEntryInfo(pRow, j, rowEntryOffset);
963,184,178✔
680
    if (pCtx[j].fpSet.finalize) {
963,481,693✔
681
      if (strcmp(pCtx[j].pExpr->pExpr->_function.functionName, "_group_key") == 0 ||
581,766,319✔
682
          strcmp(pCtx[j].pExpr->pExpr->_function.functionName, "_group_const_value") == 0) {
490,295,208✔
683
        // for groupkey along with functions that output multiple lines(e.g. Histogram)
684
        // need to match groupkey result for each output row of that function.
685
        if (pCtx[j].resultInfo->numOfRes != 0) {
91,471,330!
686
          pCtx[j].resultInfo->numOfRes = pRow->numOfRows;
92,796,373✔
687
        }
688
      }
689

690
      code = blockDataEnsureCapacity(pBlock, pBlock->info.rows + pCtx[j].resultInfo->numOfRes);
581,766,319✔
691
      QUERY_CHECK_CODE(code, lino, _end);
582,146,830!
692

693
      code = pCtx[j].fpSet.finalize(&pCtx[j], pBlock);
582,146,830✔
694
      if (TSDB_CODE_SUCCESS != code) {
584,009,163!
695
        qError("%s build result data block error, code %s", GET_TASKID(pTaskInfo), tstrerror(code));
×
696
        QUERY_CHECK_CODE(code, lino, _end);
×
697
      }
698
    } else if (strcmp(pCtx[j].pExpr->pExpr->_function.functionName, "_select_value") == 0) {
381,715,374✔
699
      // do nothing
700
    } else {
701
      // expand the result into multiple rows. E.g., _wstart, top(k, 20)
702
      // the _wstart needs to copy to 20 following rows, since the results of top-k expands to 20 different rows.
703
      SColumnInfoData* pColInfoData = taosArrayGet(pBlock->pDataBlock, slotId);
229,772,938✔
704
      QUERY_CHECK_NULL(pColInfoData, code, lino, _end, terrno);
229,185,609✔
705
      char*            in = GET_ROWCELL_INTERBUF(pCtx[j].resultInfo);
229,047,817✔
706
      for (int32_t k = 0; k < pRow->numOfRows; ++k) {
466,304,123✔
707
        code = colDataSetValOrCover(pColInfoData, pBlock->info.rows + k, in, pCtx[j].resultInfo->isNullRes);
237,185,905✔
708
        QUERY_CHECK_CODE(code, lino, _end);
237,256,306!
709
      }
710
    }
711
  }
712

713
_end:
389,106,167✔
714
  if (code != TSDB_CODE_SUCCESS) {
389,106,167!
715
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
×
716
  }
717
  return code;
391,545,774✔
718
}
719

720
// todo refactor. SResultRow has direct pointer in miainfo
721
void finalizeResultRows(SDiskbasedBuf* pBuf, SResultRowPosition* resultRowPosition, SExprSupp* pSup,
67,531,742✔
722
                        SSDataBlock* pBlock, SExecTaskInfo* pTaskInfo) {
723
  SFilePage* page = getBufPage(pBuf, resultRowPosition->pageId);
67,531,742✔
724
  if (page == NULL) {
67,524,733!
725
    qError("failed to get buffer, code:%s, %s", tstrerror(terrno), GET_TASKID(pTaskInfo));
×
726
    T_LONG_JMP(pTaskInfo->env, terrno);
×
727
  }
728

729
  SResultRow* pRow = (SResultRow*)((char*)page + resultRowPosition->offset);
67,524,733✔
730

731
  SqlFunctionCtx* pCtx = pSup->pCtx;
67,524,733✔
732
  SExprInfo*      pExprInfo = pSup->pExprInfo;
67,524,733✔
733
  const int32_t*  rowEntryOffset = pSup->rowEntryInfoOffset;
67,524,733✔
734

735
  doUpdateNumOfRows(pCtx, pRow, pSup->numOfExprs, rowEntryOffset);
67,524,733✔
736
  if (pRow->numOfRows == 0) {
67,508,143!
737
    releaseBufPage(pBuf, page);
×
738
    return;
×
739
  }
740

741
  int32_t size = pBlock->info.capacity;
67,508,709✔
742
  while (pBlock->info.rows + pRow->numOfRows > size) {
67,598,868✔
743
    size = size * 1.25;
90,159✔
744
  }
745

746
  int32_t code = blockDataEnsureCapacity(pBlock, size);
67,508,709✔
747
  if (TAOS_FAILED(code)) {
67,513,528!
748
    releaseBufPage(pBuf, page);
×
749
    qError("%s ensure result data capacity failed, code %s", GET_TASKID(pTaskInfo), tstrerror(code));
×
750
    T_LONG_JMP(pTaskInfo->env, code);
×
751
  }
752

753
  code = copyResultrowToDataBlock(pExprInfo, pSup->numOfExprs, pRow, pCtx, pBlock, rowEntryOffset, pTaskInfo);
67,513,528✔
754
  if (TAOS_FAILED(code)) {
67,487,027!
755
    releaseBufPage(pBuf, page);
×
756
    qError("%s copy result row to datablock failed, code %s", GET_TASKID(pTaskInfo), tstrerror(code));
×
757
    T_LONG_JMP(pTaskInfo->env, code);
×
758
  }
759

760
  releaseBufPage(pBuf, page);
67,487,027✔
761
  pBlock->info.rows += pRow->numOfRows;
67,486,826✔
762
}
763

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

773
  size_t  keyLen = 0;
2,990,654✔
774
  int32_t numOfRows = tSimpleHashGetSize(pHashmap);
2,990,654✔
775

776
  // begin from last iter
777
  void*   pData = pGroupResInfo->dataPos;
2,984,883✔
778
  int32_t iter = pGroupResInfo->iter;
2,984,883✔
779
  while ((pData = tSimpleHashIterate(pHashmap, pData, &iter)) != NULL) {
12,898,178✔
780
    void*               key = tSimpleHashGetKey(pData, &keyLen);
12,597,889✔
781
    SResultRowPosition* pos = pData;
12,597,889✔
782
    uint64_t            groupId = *(uint64_t*)key;
12,597,889✔
783

784
    SFilePage* page = getBufPage(pBuf, pos->pageId);
12,597,889✔
785
    if (page == NULL) {
12,591,814!
786
      qError("failed to get buffer, code:%s, %s", tstrerror(terrno), GET_TASKID(pTaskInfo));
×
787
      T_LONG_JMP(pTaskInfo->env, terrno);
×
788
    }
789

790
    SResultRow* pRow = (SResultRow*)((char*)page + pos->offset);
12,591,814✔
791

792
    doUpdateNumOfRows(pCtx, pRow, numOfExprs, rowEntryOffset);
12,591,814✔
793

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

800
      releaseBufPage(pBuf, page);
×
801
      continue;
×
802
    }
803

804
    if (!ignoreGroup) {
12,536,248✔
805
      if (pBlock->info.id.groupId == 0) {
5,345,497✔
806
        pBlock->info.id.groupId = groupId;
2,709,975✔
807
      } else {
808
        // current value belongs to different group, it can't be packed into one datablock
809
        if (pBlock->info.id.groupId != groupId) {
2,635,522!
810
          releaseBufPage(pBuf, page);
2,659,163✔
811
          break;
2,660,322✔
812
        }
813
      }
814
    }
815

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

825
    pGroupResInfo->index += 1;
9,877,085✔
826
    pGroupResInfo->iter = iter;
9,877,085✔
827
    pGroupResInfo->dataPos = pData;
9,877,085✔
828

829
    code = copyResultrowToDataBlock(pExprInfo, numOfExprs, pRow, pCtx, pBlock, rowEntryOffset, pTaskInfo);
9,877,085✔
830
    releaseBufPage(pBuf, page);
9,916,759✔
831
    QUERY_CHECK_CODE(code, lino, _end);
9,913,335!
832
    pBlock->info.rows += pRow->numOfRows;
9,913,335✔
833
    if (pBlock->info.rows >= threshold) {
9,913,335✔
834
      break;
40✔
835
    }
836
  }
837

838
  qDebug("%s result generated, rows:%" PRId64 ", groupId:%" PRIu64, GET_TASKID(pTaskInfo), pBlock->info.rows,
2,958,186✔
839
         pBlock->info.id.groupId);
840
  pBlock->info.dataLoad = 1;
2,958,189✔
841
  code = blockDataUpdateTsWindow(pBlock, 0);
2,958,189✔
842
  QUERY_CHECK_CODE(code, lino, _end);
2,960,008!
843

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

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

860
  int32_t numOfRows = getNumOfTotalRes(pGroupResInfo);
3,246,050✔
861

862
  for (int32_t i = pGroupResInfo->index; i < numOfRows; i += 1) {
222,494,805✔
863
    SResKeyPos* pPos = taosArrayGetP(pGroupResInfo->pRows, i);
219,876,729✔
864
    SFilePage*  page = getBufPage(pBuf, pPos->pos.pageId);
219,427,161✔
865
    if (page == NULL) {
219,439,134!
866
      qError("failed to get buffer, code:%s, %s", tstrerror(terrno), GET_TASKID(pTaskInfo));
×
867
      T_LONG_JMP(pTaskInfo->env, terrno);
×
868
    }
869

870
    SResultRow* pRow = (SResultRow*)((char*)page + pPos->pos.offset);
219,439,134✔
871

872
    doUpdateNumOfRows(pCtx, pRow, numOfExprs, rowEntryOffset);
219,439,134✔
873

874
    // no results, continue to check the next one
875
    if (pRow->numOfRows == 0) {
217,495,855✔
876
      pGroupResInfo->index += 1;
817✔
877
      releaseBufPage(pBuf, page);
817✔
878
      continue;
817✔
879
    }
880

881
    if (!ignoreGroup) {
217,495,038✔
882
      if (pBlock->info.id.groupId == 0) {
147,773,545✔
883
        pBlock->info.id.groupId = pPos->groupId;
132,597,040✔
884
      } else {
885
        // current value belongs to different group, it can't be packed into one datablock
886
        if (pBlock->info.id.groupId != pPos->groupId) {
15,176,505✔
887
          releaseBufPage(pBuf, page);
125,660✔
888
          break;
125,653✔
889
        }
890
      }
891
    }
892

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

902
    pGroupResInfo->index += 1;
217,369,378✔
903
    code = copyResultrowToDataBlock(pExprInfo, numOfExprs, pRow, pCtx, pBlock, rowEntryOffset, pTaskInfo);
217,369,378✔
904
    releaseBufPage(pBuf, page);
220,297,515✔
905
    QUERY_CHECK_CODE(code, lino, _end);
219,721,931!
906

907
    pBlock->info.rows += pRow->numOfRows;
219,721,931✔
908
    if (pBlock->info.rows >= threshold) {
219,721,931✔
909
      break;
474,051✔
910
    }
911
  }
912

913
  qDebug("%s result generated, rows:%" PRId64 ", groupId:%" PRIu64, GET_TASKID(pTaskInfo), pBlock->info.rows,
3,217,780✔
914
         pBlock->info.id.groupId);
915
  pBlock->info.dataLoad = 1;
3,217,783✔
916
  code = blockDataUpdateTsWindow(pBlock, 0);
3,217,783✔
917
  QUERY_CHECK_CODE(code, lino, _end);
3,245,412!
918

919
_end:
3,245,412✔
920
  if (code != TSDB_CODE_SUCCESS) {
3,245,412!
921
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
×
922
    T_LONG_JMP(pTaskInfo->env, code);
×
923
  }
924
}
3,245,412✔
925

926
void doBuildResultDatablock(SOperatorInfo* pOperator, SOptrBasicInfo* pbInfo, SGroupResInfo* pGroupResInfo,
4,097,563✔
927
                            SDiskbasedBuf* pBuf) {
928
  SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
4,097,563✔
929
  SSDataBlock*   pBlock = pbInfo->pRes;
4,097,563✔
930

931
  // set output datablock version
932
  pBlock->info.version = pTaskInfo->version;
4,097,563✔
933

934
  blockDataCleanup(pBlock);
4,097,563✔
935
  if (!hasRemainResults(pGroupResInfo)) {
4,098,577✔
936
    return;
851,466✔
937
  }
938

939
  // clear the existed group id
940
  pBlock->info.id.groupId = 0;
3,246,616✔
941
  if (!pbInfo->mergeResultBlock) {
3,246,616✔
942
    doCopyToSDataBlock(pTaskInfo, pBlock, &pOperator->exprSupp, pBuf, pGroupResInfo, pOperator->resultInfo.threshold,
2,115,832✔
943
                       false);
944
  } else {
945
    while (hasRemainResults(pGroupResInfo)) {
2,022,479✔
946
      doCopyToSDataBlock(pTaskInfo, pBlock, &pOperator->exprSupp, pBuf, pGroupResInfo, pOperator->resultInfo.threshold,
1,130,351✔
947
                         true);
948
      if (pBlock->info.rows >= pOperator->resultInfo.threshold) {
1,130,590✔
949
        break;
238,895✔
950
      }
951

952
      // clearing group id to continue to merge data that belong to different groups
953
      pBlock->info.id.groupId = 0;
891,695✔
954
    }
955

956
    // clear the group id info in SSDataBlock, since the client does not need it
957
    pBlock->info.id.groupId = 0;
1,130,600✔
958
  }
959
}
960

961
void destroyExprInfo(SExprInfo* pExpr, int32_t numOfExprs) {
9,834,908✔
962
  for (int32_t i = 0; i < numOfExprs; ++i) {
37,689,036✔
963
    SExprInfo* pExprInfo = &pExpr[i];
27,853,267✔
964
    for (int32_t j = 0; j < pExprInfo->base.numOfParams; ++j) {
57,082,839✔
965
      if (pExprInfo->base.pParam[j].type == FUNC_PARAM_TYPE_COLUMN) {
29,233,992✔
966
        taosMemoryFreeClear(pExprInfo->base.pParam[j].pCol);
26,369,104✔
967
      } else if (pExprInfo->base.pParam[j].type == FUNC_PARAM_TYPE_VALUE) {
2,864,888✔
968
        taosVariantDestroy(&pExprInfo->base.pParam[j].param);
2,224,474✔
969
      }
970
    }
971

972
    taosMemoryFree(pExprInfo->base.pParam);
27,848,847✔
973
    taosMemoryFree(pExprInfo->pExpr);
27,848,527✔
974
  }
975
}
9,835,769✔
976

977
int32_t getBufferPgSize(int32_t rowSize, uint32_t* defaultPgsz, uint32_t* defaultBufsz) {
6,488,074✔
978
  *defaultPgsz = 4096;
6,488,074✔
979
  uint32_t last = *defaultPgsz;
6,488,074✔
980
  while (*defaultPgsz < rowSize * 4) {
7,842,838✔
981
    *defaultPgsz <<= 1u;
1,354,764✔
982
    if (*defaultPgsz < last) {
1,354,764!
983
      return TSDB_CODE_INVALID_PARA;
×
984
    }
985
    last = *defaultPgsz;
1,354,764✔
986
  }
987

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

999
  return 0;
6,488,074✔
1000
}
1001

1002
void initResultSizeInfo(SResultInfo* pResultInfo, int32_t numOfRows) {
15,029,390✔
1003
  if (numOfRows == 0) {
15,029,390!
1004
    numOfRows = 4096;
×
1005
  }
1006

1007
  pResultInfo->capacity = numOfRows;
15,029,390✔
1008
  pResultInfo->threshold = numOfRows * 0.75;
15,029,390✔
1009

1010
  if (pResultInfo->threshold == 0) {
15,029,390✔
1011
    pResultInfo->threshold = numOfRows;
3,840✔
1012
  }
1013
}
15,029,390✔
1014

1015
void initBasicInfo(SOptrBasicInfo* pInfo, SSDataBlock* pBlock) {
6,470,163✔
1016
  pInfo->pRes = pBlock;
6,470,163✔
1017
  initResultRowInfo(&pInfo->resultRowInfo);
6,470,163✔
1018
}
6,470,022✔
1019

1020
static void destroySqlFunctionCtx(SqlFunctionCtx* pCtx, SExprInfo* pExpr, int32_t numOfOutput) {
29,143,343✔
1021
  if (pCtx == NULL) {
29,143,343✔
1022
    return;
18,462,736✔
1023
  }
1024

1025
  for (int32_t i = 0; i < numOfOutput; ++i) {
38,265,490✔
1026
    if (pExpr != NULL) {
27,584,942✔
1027
      SExprInfo* pExprInfo = &pExpr[i];
27,584,597✔
1028
      for (int32_t j = 0; j < pExprInfo->base.numOfParams; ++j) {
56,550,439✔
1029
        if (pExprInfo->base.pParam[j].type == FUNC_PARAM_TYPE_VALUE) {
28,965,002✔
1030
          taosMemoryFree(pCtx[i].input.pData[j]);
2,220,529✔
1031
          taosMemoryFree(pCtx[i].input.pColumnDataAgg[j]);
2,220,501✔
1032
        }
1033
      }
1034
    }
1035
    for (int32_t j = 0; j < pCtx[i].numOfParams; ++j) {
56,542,735✔
1036
      taosVariantDestroy(&pCtx[i].param[j].param);
28,959,540✔
1037
    }
1038

1039
    taosMemoryFreeClear(pCtx[i].subsidiaries.pCtx);
27,583,195✔
1040
    taosMemoryFreeClear(pCtx[i].subsidiaries.buf);
27,583,346✔
1041
    taosMemoryFree(pCtx[i].input.pData);
27,583,342✔
1042
    taosMemoryFree(pCtx[i].input.pColumnDataAgg);
27,587,764✔
1043

1044
    if (pCtx[i].udfName != NULL) {
27,585,848✔
1045
      taosMemoryFree(pCtx[i].udfName);
32✔
1046
    }
1047
  }
1048

1049
  taosMemoryFreeClear(pCtx);
10,680,548!
1050
  return;
10,681,144✔
1051
}
1052

1053
int32_t initExprSupp(SExprSupp* pSup, SExprInfo* pExprInfo, int32_t numOfExpr, SFunctionStateStore* pStore) {
10,249,366✔
1054
  pSup->pExprInfo = pExprInfo;
10,249,366✔
1055
  pSup->numOfExprs = numOfExpr;
10,249,366✔
1056
  if (pSup->pExprInfo != NULL) {
10,249,366✔
1057
    pSup->pCtx = createSqlFunctionCtx(pExprInfo, numOfExpr, &pSup->rowEntryInfoOffset, pStore);
7,980,126✔
1058
    if (pSup->pCtx == NULL) {
7,978,168!
1059
      return TSDB_CODE_OUT_OF_MEMORY;
×
1060
    }
1061
  }
1062

1063
  return TSDB_CODE_SUCCESS;
10,247,408✔
1064
}
1065

1066
void cleanupExprSupp(SExprSupp* pSupp) {
29,144,711✔
1067
  destroySqlFunctionCtx(pSupp->pCtx, pSupp->pExprInfo, pSupp->numOfExprs);
29,144,711✔
1068
  if (pSupp->pExprInfo != NULL) {
29,142,651✔
1069
    destroyExprInfo(pSupp->pExprInfo, pSupp->numOfExprs);
9,829,897✔
1070
    taosMemoryFreeClear(pSupp->pExprInfo);
9,829,913!
1071
  }
1072

1073
  if (pSupp->pFilterInfo != NULL) {
29,143,062✔
1074
    filterFreeInfo(pSupp->pFilterInfo);
2,818,337✔
1075
    pSupp->pFilterInfo = NULL;
2,818,385✔
1076
  }
1077

1078
  taosMemoryFree(pSupp->rowEntryInfoOffset);
29,143,110✔
1079
}
29,122,223✔
1080

1081
void cleanupBasicInfo(SOptrBasicInfo* pInfo) {
6,498,073✔
1082
  blockDataDestroy(pInfo->pRes);
6,498,073✔
1083
  pInfo->pRes = NULL;
6,498,749✔
1084
}
6,498,749✔
1085

1086
bool groupbyTbname(SNodeList* pGroupList) {
4,425,225✔
1087
  bool bytbname = false;
4,425,225✔
1088
  SNode*pNode = NULL;
4,425,225✔
1089
  FOREACH(pNode, pGroupList) {
4,497,280✔
1090
    if (pNode->type == QUERY_NODE_FUNCTION) {
341,220✔
1091
      bytbname = (strcmp(((struct SFunctionNode*)pNode)->functionName, "tbname") == 0);
269,165✔
1092
      break;
269,165✔
1093
    }
1094
  }
1095
  return bytbname;
4,425,225✔
1096
}
1097

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

1107
      *pParam = pInserterParam;
364✔
1108
      break;
364✔
1109
    }
1110
    case QUERY_NODE_PHYSICAL_PLAN_DELETE: {
58,896✔
1111
      SDeleterParam* pDeleterParam = taosMemoryCalloc(1, sizeof(SDeleterParam));
58,896✔
1112
      if (NULL == pDeleterParam) {
58,895!
1113
        return terrno;
×
1114
      }
1115

1116
      SArray* pInfoList = NULL;
58,895✔
1117
      int32_t code = getTableListInfo(pTask, &pInfoList);
58,895✔
1118
      if (code != TSDB_CODE_SUCCESS || pInfoList == NULL) {
58,895!
1119
        taosMemoryFree(pDeleterParam);
×
1120
        return code;
×
1121
      }
1122

1123
      STableListInfo* pTableListInfo = taosArrayGetP(pInfoList, 0);
58,896✔
1124
      taosArrayDestroy(pInfoList);
58,889✔
1125

1126
      pDeleterParam->suid = tableListGetSuid(pTableListInfo);
58,898✔
1127

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

1137
      pDeleterParam->pUidList = taosArrayInit(numOfTables, sizeof(uint64_t));
58,889✔
1138
      if (NULL == pDeleterParam->pUidList) {
58,897✔
1139
        taosMemoryFree(pDeleterParam);
5✔
1140
        return terrno;
×
1141
      }
1142

1143
      for (int32_t i = 0; i < numOfTables; ++i) {
132,357✔
1144
        STableKeyInfo* pTable = tableListGetInfo(pTableListInfo, i);
73,464✔
1145
        if (!pTable) {
73,463!
1146
          taosArrayDestroy(pDeleterParam->pUidList);
×
1147
          taosMemoryFree(pDeleterParam);
×
1148
          return TSDB_CODE_OUT_OF_MEMORY;
×
1149
        }
1150
        void*          tmp = taosArrayPush(pDeleterParam->pUidList, &pTable->uid);
73,463✔
1151
        if (!tmp) {
73,465!
1152
          taosArrayDestroy(pDeleterParam->pUidList);
×
1153
          taosMemoryFree(pDeleterParam);
×
1154
          return terrno;
×
1155
        }
1156
      }
1157

1158
      *pParam = pDeleterParam;
58,893✔
1159
      break;
58,893✔
1160
    }
1161
    default:
7,804,014✔
1162
      break;
7,804,014✔
1163
  }
1164

1165
  return TSDB_CODE_SUCCESS;
7,863,271✔
1166
}
1167

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

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

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

1189
  taosArrayDestroy(pParam->pChildren);
65,604✔
1190

1191
  taosMemoryFree(pParam->value);
65,604✔
1192

1193
  taosMemoryFree(pParam);
65,604✔
1194
}
65,604✔
1195

1196
void freeExchangeGetBasicOperatorParam(void* pParam) {
940✔
1197
  SExchangeOperatorBasicParam* pBasic = (SExchangeOperatorBasicParam*)pParam;
940✔
1198
  taosArrayDestroy(pBasic->uidList);
940✔
1199
}
940✔
1200

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

1210
  freeOperatorParamImpl(pParam, OP_GET_PARAM);
548✔
1211
}
548✔
1212

1213
void freeExchangeNotifyOperatorParam(SOperatorParam* pParam) { freeOperatorParamImpl(pParam, OP_NOTIFY_PARAM); }
×
1214

1215
void freeGroupCacheGetOperatorParam(SOperatorParam* pParam) { freeOperatorParamImpl(pParam, OP_GET_PARAM); }
42,116✔
1216

1217
void freeGroupCacheNotifyOperatorParam(SOperatorParam* pParam) { freeOperatorParamImpl(pParam, OP_NOTIFY_PARAM); }
×
1218

1219
void freeMergeJoinGetOperatorParam(SOperatorParam* pParam) { freeOperatorParamImpl(pParam, OP_GET_PARAM); }
21,058✔
1220

1221
void freeMergeJoinNotifyOperatorParam(SOperatorParam* pParam) { freeOperatorParamImpl(pParam, OP_NOTIFY_PARAM); }
×
1222

1223
void freeTableScanGetOperatorParam(SOperatorParam* pParam) {
1,882✔
1224
  STableScanOperatorParam* pTableScanParam = (STableScanOperatorParam*)pParam->value;
1,882✔
1225
  taosArrayDestroy(pTableScanParam->pUidList);
1,882✔
1226
  freeOperatorParamImpl(pParam, OP_GET_PARAM);
1,882✔
1227
}
1,882✔
1228

1229
void freeTableScanNotifyOperatorParam(SOperatorParam* pParam) { freeOperatorParamImpl(pParam, OP_NOTIFY_PARAM); }
×
1230

1231
void freeOperatorParam(SOperatorParam* pParam, SOperatorParamType type) {
5,411,036✔
1232
  if (NULL == pParam) {
5,411,036✔
1233
    return;
5,345,516✔
1234
  }
1235

1236
  switch (pParam->opType) {
65,520!
1237
    case QUERY_NODE_PHYSICAL_PLAN_EXCHANGE:
548✔
1238
      type == OP_GET_PARAM ? freeExchangeGetOperatorParam(pParam) : freeExchangeNotifyOperatorParam(pParam);
548!
1239
      break;
548✔
1240
    case QUERY_NODE_PHYSICAL_PLAN_GROUP_CACHE:
42,116✔
1241
      type == OP_GET_PARAM ? freeGroupCacheGetOperatorParam(pParam) : freeGroupCacheNotifyOperatorParam(pParam);
42,116!
1242
      break;
42,116✔
1243
    case QUERY_NODE_PHYSICAL_PLAN_MERGE_JOIN:
21,058✔
1244
      type == OP_GET_PARAM ? freeMergeJoinGetOperatorParam(pParam) : freeMergeJoinNotifyOperatorParam(pParam);
21,058!
1245
      break;
21,058✔
1246
    case QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN:
1,882✔
1247
      type == OP_GET_PARAM ? freeTableScanGetOperatorParam(pParam) : freeTableScanNotifyOperatorParam(pParam);
1,882!
1248
      break;
1,882✔
1249
    default:
×
1250
      qError("unsupported op %d param, type %d", pParam->opType, type);
×
1251
      break;
×
1252
  }
1253
}
1254

1255
void freeResetOperatorParams(struct SOperatorInfo* pOperator, SOperatorParamType type, bool allFree) {
37,417,744✔
1256
  SOperatorParam**  ppParam = NULL;
37,417,744✔
1257
  SOperatorParam*** pppDownstramParam = NULL;
37,417,744✔
1258
  switch (type) {
37,417,744!
1259
    case OP_GET_PARAM:
18,732,668✔
1260
      ppParam = &pOperator->pOperatorGetParam;
18,732,668✔
1261
      pppDownstramParam = &pOperator->pDownstreamGetParams;
18,732,668✔
1262
      break;
18,732,668✔
1263
    case OP_NOTIFY_PARAM:
18,710,309✔
1264
      ppParam = &pOperator->pOperatorNotifyParam;
18,710,309✔
1265
      pppDownstramParam = &pOperator->pDownstreamNotifyParams;
18,710,309✔
1266
      break;
18,710,309✔
1267
    default:
×
1268
      return;
×
1269
  }
1270

1271
  if (*ppParam) {
37,442,977✔
1272
    freeOperatorParam(*ppParam, type);
21,058✔
1273
    *ppParam = NULL;
21,058✔
1274
  }
1275

1276
  if (*pppDownstramParam) {
37,442,977✔
1277
    for (int32_t i = 0; i < pOperator->numOfDownstream; ++i) {
64,664✔
1278
      if ((*pppDownstramParam)[i]) {
42,116!
1279
        freeOperatorParam((*pppDownstramParam)[i], type);
×
1280
        (*pppDownstramParam)[i] = NULL;
×
1281
      }
1282
    }
1283
    if (allFree) {
22,548✔
1284
      taosMemoryFreeClear(*pppDownstramParam);
1,705!
1285
    }
1286
  }
1287
}
1288

1289
FORCE_INLINE int32_t getNextBlockFromDownstreamImpl(struct SOperatorInfo* pOperator, int32_t idx, bool clearParam,
35,477,793✔
1290
                                                    SSDataBlock** pResBlock) {
1291
  QRY_PARAM_CHECK(pResBlock);
35,477,793!
1292

1293
  int32_t code = 0;
35,477,793✔
1294
  if (pOperator->pDownstreamGetParams && pOperator->pDownstreamGetParams[idx]) {
35,477,793!
1295
    qDebug("DynOp: op %s start to get block from downstream %s", pOperator->name, pOperator->pDownstream[idx]->name);
63,376✔
1296
    code = pOperator->pDownstream[idx]->fpSet.getNextExtFn(pOperator->pDownstream[idx],
63,376✔
1297
                                                           pOperator->pDownstreamGetParams[idx], pResBlock);
63,376✔
1298
    if (clearParam && (code == 0)) {
63,376!
1299
      freeOperatorParam(pOperator->pDownstreamGetParams[idx], OP_GET_PARAM);
×
1300
      pOperator->pDownstreamGetParams[idx] = NULL;
×
1301
    }
1302

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

1309
  code = pOperator->pDownstream[idx]->fpSet.getNextFn(pOperator->pDownstream[idx], pResBlock);
35,414,417✔
1310
  if (code) {
35,414,686!
1311
    qError("failed to get next data block from upstream at %s, %d code:%s", __func__, __LINE__, tstrerror(code));
×
1312
  }
1313
  return code;
35,414,699✔
1314
}
1315

1316
bool compareVal(const char* v, const SStateKeys* pKey) {
20,934,080✔
1317
  if (IS_VAR_DATA_TYPE(pKey->type)) {
20,934,080!
1318
    if (varDataLen(v) != varDataLen(pKey->pData)) {
2,402!
1319
      return false;
×
1320
    } else {
1321
      return memcmp(varDataVal(v), varDataVal(pKey->pData), varDataLen(v)) == 0;
2,402✔
1322
    }
1323
  } else {
1324
    return memcmp(pKey->pData, v, pKey->bytes) == 0;
20,931,678✔
1325
  }
1326
}
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