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

taosdata / TDengine / #3588

24 Jan 2025 08:57AM UTC coverage: 63.555% (+0.006%) from 63.549%
#3588

push

travis-ci

web-flow
Merge pull request #29638 from taosdata/docs/TS-5846-3.0

enh: TDengine modify taosBenchmark new query rule cases and add doc

141359 of 285622 branches covered (49.49%)

Branch coverage included in aggregate %.

219930 of 282844 relevant lines covered (77.76%)

19382902.66 hits per line

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

67.53
/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) {
246,694,718✔
86
  SFilePage* pData = NULL;
246,694,718✔
87

88
  // in the first scan, new space needed for results
89
  int32_t pageId = -1;
246,694,718✔
90
  if (*currentPageId == -1) {
246,694,718✔
91
    pData = getNewBufPage(pResultBuf, &pageId);
5,352,572✔
92
    if (pData == NULL) {
5,352,909✔
93
      qError("failed to get buffer, code:%s", tstrerror(terrno));
625!
94
      return NULL;
×
95
    }
96
    pData->num = sizeof(SFilePage);
5,352,284✔
97
  } else {
98
    pData = getBufPage(pResultBuf, *currentPageId);
241,342,146✔
99
    if (pData == NULL) {
241,218,767!
100
      qError("failed to get buffer, code:%s", tstrerror(terrno));
×
101
      return NULL;
×
102
    }
103

104
    pageId = *currentPageId;
241,218,767✔
105

106
    if (pData->num + interBufSize > getBufPageSize(pResultBuf)) {
241,218,767✔
107
      // release current page first, and prepare the next one
108
      releaseBufPage(pResultBuf, pData);
17,833,439✔
109

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

119
  if (pData == NULL) {
246,688,813!
120
    return NULL;
×
121
  }
122

123
  setBufPageDirty(pData, true);
246,688,813✔
124

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

128
  memset((char*)pResultRow, 0, interBufSize);
246,494,310✔
129
  pResultRow->pageId = pageId;
246,494,310✔
130
  pResultRow->offset = (int32_t)pData->num;
246,494,310✔
131

132
  *currentPageId = pageId;
246,494,310✔
133
  pData->num += interBufSize;
246,494,310✔
134
  return pResultRow;
246,494,310✔
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,
301,972,117✔
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);
301,972,117✔
148
  if (!keepGroup) {
301,972,117✔
149
    *(uint64_t*)pSup->keyBuf = calcGroupId(pSup->keyBuf, GET_RES_WINDOW_KEY_LEN(bytes));
24,446,514✔
150
  }
151

152
  SResultRowPosition* p1 =
153
      (SResultRowPosition*)tSimpleHashGet(pSup->pResultRowHashTable, pSup->keyBuf, GET_RES_WINDOW_KEY_LEN(bytes));
302,248,840✔
154

155
  SResultRow* pResult = NULL;
302,004,849✔
156

157
  // in case of repeat scan/reverse scan, no new time window added.
158
  if (isIntervalQuery) {
302,004,849✔
159
    if (p1 != NULL) {  // the *p1 may be NULL in case of sliding+offset exists.
272,802,380✔
160
      pResult = getResultRowByPos(pResultBuf, p1, true);
47,702,568✔
161
      if (pResult == NULL) {
47,702,568!
162
        pTaskInfo->code = terrno;
×
163
        return NULL;
×
164
      }
165

166
      if (pResult->pageId != p1->pageId || pResult->offset != p1->offset) {
47,702,568!
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) {
29,202,469✔
176
      // todo
177
      pResult = getResultRowByPos(pResultBuf, p1, true);
6,432,712✔
178
      if (NULL == pResult) {
6,432,712!
179
        pTaskInfo->code = terrno;
×
180
        return NULL;
×
181
      }
182

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

191
  // 1. close current opened time window
192
  if (pResultRowInfo->cur.pageId != -1 && ((pResult == NULL) || (pResult->pageId != pResultRowInfo->cur.pageId))) {
301,675,990✔
193
    SResultRowPosition pos = pResultRowInfo->cur;
246,718,465✔
194
    SFilePage*         pPage = getBufPage(pResultBuf, pos.pageId);
246,718,465✔
195
    if (pPage == NULL) {
245,839,721!
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);
245,839,721✔
201
  }
202

203
  // allocate a new buffer page
204
  if (pResult == NULL) {
300,292,611✔
205
    pResult = getNewResultRow(pResultBuf, &pSup->currentPageId, pSup->resultRowSize);
246,281,993✔
206
    if (pResult == NULL) {
246,590,379!
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};
246,590,379✔
213
    int32_t code = tSimpleHashPut(pSup->pResultRowHashTable, pSup->keyBuf, GET_RES_WINDOW_KEY_LEN(bytes), &pos,
246,590,379✔
214
                                  sizeof(SResultRowPosition));
215
    if (code != TSDB_CODE_SUCCESS) {
249,347,045!
216
      qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(code));
×
217
      pTaskInfo->code = code;
×
218
      return NULL;
×
219
    }
220
  }
221

222
  // 2. set the new time window to be the new active time window
223
  pResultRowInfo->cur = (SResultRowPosition){.pageId = pResult->pageId, .offset = pResult->offset};
303,469,782✔
224

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

232
  return pResult;
302,658,769✔
233
}
234

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

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

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

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

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

274
int32_t setInputDataBlock(SExprSupp* pExprSup, SSDataBlock* pBlock, int32_t order, int32_t scanFlag,
31,122,774✔
275
                          bool createDummyCol) {
276
  if (pBlock->pBlockAgg != NULL) {
31,122,774✔
277
    return doSetInputDataBlockInfo(pExprSup, pBlock, order, scanFlag);
2,138,971✔
278
  } else {
279
    return doSetInputDataBlock(pExprSup, pBlock, order, scanFlag, createDummyCol);
28,983,803✔
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,
28,983,939✔
335
                                   bool createDummyCol) {
336
  int32_t         code = TSDB_CODE_SUCCESS;
28,983,939✔
337
  int32_t         lino = 0;
28,983,939✔
338
  SqlFunctionCtx* pCtx = pExprSup->pCtx;
28,983,939✔
339

340
  for (int32_t i = 0; i < pExprSup->numOfExprs; ++i) {
105,245,460✔
341
    pCtx[i].order = order;
76,279,218✔
342
    pCtx[i].input.numOfRows = pBlock->info.rows;
76,279,218✔
343

344
    pCtx[i].pSrcBlock = pBlock;
76,279,218✔
345
    pCtx[i].scanFlag = scanFlag;
76,279,218✔
346

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

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

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

358
    for (int32_t j = 0; j < pOneExpr->base.numOfParams; ++j) {
159,824,800✔
359
      SFunctParam* pFuncParam = &pOneExpr->base.pParam[j];
83,563,279✔
360
      if (pFuncParam->type == FUNC_PARAM_TYPE_COLUMN) {
83,563,279✔
361
        int32_t slotId = pFuncParam->pCol->slotId;
74,476,531✔
362
        pInput->pData[j] = taosArrayGet(pBlock->pDataBlock, slotId);
74,476,531✔
363
        pInput->totalRows = pBlock->info.rows;
74,462,359✔
364
        pInput->numOfRows = pBlock->info.rows;
74,462,359✔
365
        pInput->startRowIndex = 0;
74,462,359✔
366
        pInput->blankFill = pBlock->info.blankFill;
74,462,359✔
367

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

371
        if (fmIsImplicitTsFunc(pCtx[i].functionId) && (j == tsParamIdx)) {
74,462,359✔
372
          pInput->pPTS = pInput->pData[j];  // in case of merge function, this is not always the ts column data.
11,224,516✔
373
        }
374
        if (hasPk && (j == pkParamIdx)) {
74,458,834✔
375
          pInput->pPrimaryKey = pInput->pData[j];
780,808✔
376
        }
377
        QUERY_CHECK_CONDITION((pInput->pData[j] != NULL), code, lino, _end, TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR);
74,458,834!
378
      } else if (pFuncParam->type == FUNC_PARAM_TYPE_VALUE) {
9,086,748✔
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) {
7,814,542!
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:
28,966,242✔
395
  if (code != TSDB_CODE_SUCCESS) {
28,966,242!
396
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
×
397
  }
398
  return code;
28,985,576✔
399
}
400

401
bool functionNeedToExecute(SqlFunctionCtx* pCtx) {
1,013,520,292✔
402
  struct SResultRowEntryInfo* pResInfo = GET_RES_INFO(pCtx);
1,013,520,292✔
403

404
  // in case of timestamp column, always generated results.
405
  int32_t functionId = pCtx->functionId;
1,013,520,292✔
406
  if (functionId == -1) {
1,013,520,292✔
407
    return false;
57,219,688✔
408
  }
409

410
  if (pCtx->scanFlag == PRE_SCAN) {
956,300,604✔
411
    return fmIsRepeatScanFunc(pCtx->functionId);
1,372,552✔
412
  }
413

414
  if (isRowEntryCompleted(pResInfo)) {
954,928,052!
415
    return false;
×
416
  }
417

418
  return true;
954,928,052✔
419
}
420

421
static int32_t doCreateConstantValColumnSMAInfo(SInputColumnInfoData* pInput, SFunctParam* pFuncParam, int32_t type,
1,739,601✔
422
                                                int32_t paramIndex, int32_t numOfRows) {
423
  if (pInput->pData[paramIndex] == NULL) {
1,739,601✔
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,739,601✔
435
  if (pInput->pColumnDataAgg[paramIndex] == NULL) {
1,739,601✔
436
    da = taosMemoryCalloc(1, sizeof(SColumnDataAgg));
18!
437
    if (!da) {
18!
438
      return terrno;
×
439
    }
440
    pInput->pColumnDataAgg[paramIndex] = da;
18✔
441
  } else {
442
    da = pInput->pColumnDataAgg[paramIndex];
1,739,583✔
443
  }
444

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

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

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

468
  return TSDB_CODE_SUCCESS;
1,739,601✔
469
}
470

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

476
  SInputColumnInfoData* pInput = &pCtx->input;
2,138,975✔
477
  pInput->numOfRows = numOfRows;
2,138,975✔
478
  pInput->totalRows = numOfRows;
2,138,975✔
479

480
  if (pBlock->pBlockAgg != NULL) {
2,138,975!
481
    pInput->colDataSMAIsSet = true;
2,138,975✔
482

483
    for (int32_t j = 0; j < pExprInfo->base.numOfParams; ++j) {
6,017,551✔
484
      SFunctParam* pFuncParam = &pExprInfo->base.pParam[j];
3,878,576✔
485

486
      if (pFuncParam->type == FUNC_PARAM_TYPE_COLUMN) {
3,878,576✔
487
        int32_t slotId = pFuncParam->pCol->slotId;
2,138,975✔
488
        pInput->pColumnDataAgg[j] = &pBlock->pBlockAgg[slotId];
2,138,975✔
489
        if (pInput->pColumnDataAgg[j]->colId == -1) {
2,138,975✔
490
          pInput->colDataSMAIsSet = false;
3,216✔
491
        }
492

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

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

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

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

526
  return win;
32,355,687✔
527
}
528

529
int32_t setResultRowInitCtx(SResultRow* pResult, SqlFunctionCtx* pCtx, int32_t numOfOutput,
478,659,428✔
530
                            int32_t* rowEntryInfoOffset) {
531
  bool init = false;
478,659,428✔
532
  for (int32_t i = 0; i < numOfOutput; ++i) {
1,768,869,618✔
533
    pCtx[i].resultInfo = getResultEntryInfo(pResult, i, rowEntryInfoOffset);
1,291,863,566✔
534
    if (init) {
1,291,825,769✔
535
      continue;
113,218,564✔
536
    }
537

538
    struct SResultRowEntryInfo* pResInfo = pCtx[i].resultInfo;
1,178,607,205✔
539
    if (isRowEntryCompleted(pResInfo) && isRowEntryInitialized(pResInfo)) {
1,178,607,205!
540
      continue;
×
541
    }
542

543
    if (pCtx[i].isPseudoFunc) {
1,178,607,205✔
544
      continue;
283,365,138✔
545
    }
546

547
    if (!pResInfo->initialized) {
895,242,067✔
548
      if (pCtx[i].functionId != -1) {
848,071,576✔
549
        int32_t code = pCtx[i].fpSet.init(&pCtx[i], pResInfo);
802,402,108✔
550
        if (code != TSDB_CODE_SUCCESS && fmIsUserDefinedFunc(pCtx[i].functionId)) {
802,460,699!
551
          pResInfo->initialized = false;
1,674,170✔
552
          qError("failed to initialize udf, funcId:%d error:%s", pCtx[i].functionId, tstrerror(code));
1,674,170!
553
          return TSDB_CODE_UDF_FUNC_EXEC_FAILURE;
×
554
        } else if (code != TSDB_CODE_SUCCESS) {
800,786,529!
555
          qError("failed to initialize function context, funcId:%d error:%s", pCtx[i].functionId, tstrerror(code));
×
556
          return code;
×
557
        }
558
      } else {
559
        pResInfo->initialized = true;
45,669,468✔
560
      }
561
    } else {
562
      init = true;
47,170,491✔
563
    }
564
  }
565
  return TSDB_CODE_SUCCESS;
477,006,052✔
566
}
567

568
void clearResultRowInitFlag(SqlFunctionCtx* pCtx, int32_t numOfOutput) {
98,825,230✔
569
  for (int32_t i = 0; i < numOfOutput; ++i) {
249,971,789✔
570
    SResultRowEntryInfo* pResInfo = pCtx[i].resultInfo;
151,146,559✔
571
    if (pResInfo == NULL) {
151,146,559!
572
      continue;
×
573
    }
574

575
    pResInfo->initialized = false;
151,146,559✔
576
    pResInfo->numOfRes = 0;
151,146,559✔
577
    pResInfo->isNullRes = 0;
151,146,559✔
578
    pResInfo->complete = false;
151,146,559✔
579
  }
580
}
98,825,230✔
581

582
int32_t doFilter(SSDataBlock* pBlock, SFilterInfo* pFilterInfo, SColMatchInfo* pColMatchInfo) {
43,988,849✔
583
  int32_t code = TSDB_CODE_SUCCESS;
43,988,849✔
584
  int32_t lino = 0;
43,988,849✔
585
  if (pFilterInfo == NULL || pBlock->info.rows == 0) {
43,988,849✔
586
    return TSDB_CODE_SUCCESS;
38,380,575✔
587
  }
588

589
  SFilterColumnParam param1 = {.numOfCols = taosArrayGetSize(pBlock->pDataBlock), .pDataBlock = pBlock->pDataBlock};
5,608,274✔
590
  SColumnInfoData*   p = NULL;
5,608,202✔
591

592
  code = filterSetDataFromSlotId(pFilterInfo, &param1);
5,608,202✔
593
  QUERY_CHECK_CODE(code, lino, _err);
5,608,057!
594

595
  int32_t status = 0;
5,608,057✔
596
  code = filterExecute(pFilterInfo, pBlock, &p, NULL, param1.numOfCols, &status);
5,608,057✔
597
  QUERY_CHECK_CODE(code, lino, _err);
5,608,141✔
598

599
  code = extractQualifiedTupleByFilterResult(pBlock, p, status);
5,608,140✔
600
  QUERY_CHECK_CODE(code, lino, _err);
5,608,087!
601

602
  if (pColMatchInfo != NULL) {
5,608,087✔
603
    size_t size = taosArrayGetSize(pColMatchInfo->pList);
4,467,714✔
604
    for (int32_t i = 0; i < size; ++i) {
4,473,014✔
605
      SColMatchItem* pInfo = taosArrayGet(pColMatchInfo->pList, i);
4,470,544✔
606
      QUERY_CHECK_NULL(pInfo, code, lino, _err, terrno);
4,470,442!
607
      if (pInfo->colId == PRIMARYKEY_TIMESTAMP_COL_ID) {
4,470,442✔
608
        SColumnInfoData* pColData = taosArrayGet(pBlock->pDataBlock, pInfo->dstSlotId);
4,465,251✔
609
        QUERY_CHECK_NULL(pColData, code, lino, _err, terrno);
4,465,073!
610
        if (pColData->info.type == TSDB_DATA_TYPE_TIMESTAMP) {
4,465,193✔
611
          code = blockDataUpdateTsWindow(pBlock, pInfo->dstSlotId);
4,465,102✔
612
          QUERY_CHECK_CODE(code, lino, _err);
4,465,183!
613
          break;
4,465,183✔
614
        }
615
      }
616
    }
617
  }
618
  code = blockDataCheck(pBlock);
5,608,026✔
619
  QUERY_CHECK_CODE(code, lino, _err);
5,607,935!
620
_err:
5,607,935✔
621
  if (code != TSDB_CODE_SUCCESS) {
5,607,936✔
622
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
1!
623
  }
624
  colDataDestroy(p);
5,607,936✔
625
  taosMemoryFree(p);
5,608,479!
626
  return code;
5,608,589✔
627
}
628

629
int32_t extractQualifiedTupleByFilterResult(SSDataBlock* pBlock, const SColumnInfoData* p, int32_t status) {
5,608,081✔
630
  int32_t code = TSDB_CODE_SUCCESS;
5,608,081✔
631
  int8_t* pIndicator = (int8_t*)p->pData;
5,608,081✔
632
  if (status == FILTER_RESULT_ALL_QUALIFIED) {
5,608,081✔
633
    // here nothing needs to be done
634
  } else if (status == FILTER_RESULT_NONE_QUALIFIED) {
1,404,807✔
635
    code = trimDataBlock(pBlock, pBlock->info.rows, NULL);
670,121✔
636
    pBlock->info.rows = 0;
670,085✔
637
  } else if (status == FILTER_RESULT_PARTIAL_QUALIFIED) {
734,686!
638
    code = trimDataBlock(pBlock, pBlock->info.rows, (bool*)pIndicator);
734,780✔
639
  } else {
640
    qError("unknown filter result type: %d", status);
×
641
  }
642
  return code;
5,608,250✔
643
}
644

645
void doUpdateNumOfRows(SqlFunctionCtx* pCtx, SResultRow* pRow, int32_t numOfExprs, const int32_t* rowEntryOffset) {
426,524,013✔
646
  bool returnNotNull = false;
426,524,013✔
647
  for (int32_t j = 0; j < numOfExprs; ++j) {
1,517,916,785✔
648
    SResultRowEntryInfo* pResInfo = getResultEntryInfo(pRow, j, rowEntryOffset);
1,090,641,640✔
649
    if (!isRowEntryInitialized(pResInfo)) {
1,091,392,772✔
650
      continue;
233,796,730✔
651
    } else {
652
    }
653

654
    if (pRow->numOfRows < pResInfo->numOfRes) {
857,596,042✔
655
      pRow->numOfRows = pResInfo->numOfRes;
419,574,260✔
656
    }
657

658
    if (pCtx[j].isNotNullFunc) {
857,596,042✔
659
      returnNotNull = true;
243,242,016✔
660
    }
661
  }
662
  // if all expr skips all blocks, e.g. all null inputs for max function, output one row in final result.
663
  //  except for first/last, which require not null output, output no rows
664
  if (pRow->numOfRows == 0 && !returnNotNull) {
427,275,145✔
665
    pRow->numOfRows = 1;
28,078✔
666
  }
667
}
427,275,145✔
668

669
int32_t copyResultrowToDataBlock(SExprInfo* pExprInfo, int32_t numOfExprs, SResultRow* pRow, SqlFunctionCtx* pCtx,
410,795,284✔
670
                                 SSDataBlock* pBlock, const int32_t* rowEntryOffset, SExecTaskInfo* pTaskInfo) {
671
  int32_t code = TSDB_CODE_SUCCESS;
410,795,284✔
672
  int32_t lino = 0;
410,795,284✔
673
  for (int32_t j = 0; j < numOfExprs; ++j) {
1,420,939,220✔
674
    int32_t slotId = pExprInfo[j].base.resSchema.slotId;
1,010,413,833✔
675

676
    pCtx[j].resultInfo = getResultEntryInfo(pRow, j, rowEntryOffset);
1,010,413,833✔
677
    if (pCtx[j].fpSet.finalize) {
1,010,839,141✔
678
      if (strcmp(pCtx[j].pExpr->pExpr->_function.functionName, "_group_key") == 0 ||
603,351,640✔
679
          strcmp(pCtx[j].pExpr->pExpr->_function.functionName, "_group_const_value") == 0) {
509,740,312✔
680
        // for groupkey along with functions that output multiple lines(e.g. Histogram)
681
        // need to match groupkey result for each output row of that function.
682
        if (pCtx[j].resultInfo->numOfRes != 0) {
93,858,655!
683
          pCtx[j].resultInfo->numOfRes = pRow->numOfRows;
94,887,440✔
684
        }
685
      }
686

687
      code = blockDataEnsureCapacity(pBlock, pBlock->info.rows + pCtx[j].resultInfo->numOfRes);
603,351,640✔
688
      QUERY_CHECK_CODE(code, lino, _end);
603,180,112!
689

690
      code = pCtx[j].fpSet.finalize(&pCtx[j], pBlock);
603,180,112✔
691
      if (TSDB_CODE_SUCCESS != code) {
606,171,583!
692
        qError("%s build result data block error, code %s", GET_TASKID(pTaskInfo), tstrerror(code));
×
693
        QUERY_CHECK_CODE(code, lino, _end);
×
694
      }
695
    } else if (strcmp(pCtx[j].pExpr->pExpr->_function.functionName, "_select_value") == 0) {
407,487,501✔
696
      // do nothing
697
    } else {
698
      // expand the result into multiple rows. E.g., _wstart, top(k, 20)
699
      // the _wstart needs to copy to 20 following rows, since the results of top-k expands to 20 different rows.
700
      SColumnInfoData* pColInfoData = taosArrayGet(pBlock->pDataBlock, slotId);
258,272,278✔
701
      QUERY_CHECK_NULL(pColInfoData, code, lino, _end, terrno);
257,383,030!
702
      char*            in = GET_ROWCELL_INTERBUF(pCtx[j].resultInfo);
257,443,340✔
703
      for (int32_t k = 0; k < pRow->numOfRows; ++k) {
529,002,323✔
704
        code = colDataSetValOrCover(pColInfoData, pBlock->info.rows + k, in, pCtx[j].resultInfo->isNullRes);
271,415,968✔
705
        QUERY_CHECK_CODE(code, lino, _end);
271,558,983!
706
      }
707
    }
708
  }
709

710
_end:
410,525,387✔
711
  if (code != TSDB_CODE_SUCCESS) {
410,525,387!
712
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
×
713
  }
714
  return code;
411,877,978✔
715
}
716

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

726
  SResultRow* pRow = (SResultRow*)((char*)page + resultRowPosition->offset);
68,294,836✔
727

728
  SqlFunctionCtx* pCtx = pSup->pCtx;
68,294,836✔
729
  SExprInfo*      pExprInfo = pSup->pExprInfo;
68,294,836✔
730
  const int32_t*  rowEntryOffset = pSup->rowEntryInfoOffset;
68,294,836✔
731

732
  doUpdateNumOfRows(pCtx, pRow, pSup->numOfExprs, rowEntryOffset);
68,294,836✔
733
  if (pRow->numOfRows == 0) {
68,284,394✔
734
    releaseBufPage(pBuf, page);
1,515✔
735
    return;
×
736
  }
737

738
  int32_t size = pBlock->info.capacity;
68,282,879✔
739
  while (pBlock->info.rows + pRow->numOfRows > size) {
68,374,151✔
740
    size = size * 1.25;
91,272✔
741
  }
742

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

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

757
  releaseBufPage(pBuf, page);
68,259,064✔
758
  pBlock->info.rows += pRow->numOfRows;
68,253,545✔
759
}
760

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

770
  size_t  keyLen = 0;
6,116,936✔
771
  int32_t numOfRows = tSimpleHashGetSize(pHashmap);
6,116,936✔
772

773
  // begin from last iter
774
  void*   pData = pGroupResInfo->dataPos;
6,108,605✔
775
  int32_t iter = pGroupResInfo->iter;
6,108,605✔
776
  while ((pData = tSimpleHashIterate(pHashmap, pData, &iter)) != NULL) {
24,373,656✔
777
    void*               key = tSimpleHashGetKey(pData, &keyLen);
24,032,044✔
778
    SResultRowPosition* pos = pData;
24,032,044✔
779
    uint64_t            groupId = *(uint64_t*)key;
24,032,044✔
780

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

787
    SResultRow* pRow = (SResultRow*)((char*)page + pos->offset);
24,028,473✔
788

789
    doUpdateNumOfRows(pCtx, pRow, numOfExprs, rowEntryOffset);
24,028,473✔
790

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

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

801
    if (!ignoreGroup) {
23,976,846✔
802
      if (pBlock->info.id.groupId == 0) {
11,527,797✔
803
        pBlock->info.id.groupId = groupId;
5,809,547✔
804
      } else {
805
        // current value belongs to different group, it can't be packed into one datablock
806
        if (pBlock->info.id.groupId != groupId) {
5,718,250!
807
          releaseBufPage(pBuf, page);
5,747,353✔
808
          break;
5,747,829✔
809
        }
810
      }
811
    }
812

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

822
    pGroupResInfo->index += 1;
18,229,493✔
823
    pGroupResInfo->iter = iter;
18,229,493✔
824
    pGroupResInfo->dataPos = pData;
18,229,493✔
825

826
    code = copyResultrowToDataBlock(pExprInfo, numOfExprs, pRow, pCtx, pBlock, rowEntryOffset, pTaskInfo);
18,229,493✔
827
    releaseBufPage(pBuf, page);
18,267,156✔
828
    QUERY_CHECK_CODE(code, lino, _end);
18,265,091!
829
    pBlock->info.rows += pRow->numOfRows;
18,265,091✔
830
    if (pBlock->info.rows >= threshold) {
18,265,091✔
831
      break;
40✔
832
    }
833
  }
834

835
  qDebug("%s result generated, rows:%" PRId64 ", groupId:%" PRIu64, GET_TASKID(pTaskInfo), pBlock->info.rows,
6,083,016✔
836
         pBlock->info.id.groupId);
837
  pBlock->info.dataLoad = 1;
6,083,023✔
838
  code = blockDataUpdateTsWindow(pBlock, 0);
6,083,023✔
839
  QUERY_CHECK_CODE(code, lino, _end);
6,078,898!
840

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

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

857
  int32_t numOfRows = getNumOfTotalRes(pGroupResInfo);
3,400,623✔
858

859
  for (int32_t i = pGroupResInfo->index; i < numOfRows; i += 1) {
229,637,298✔
860
    SResKeyPos* pPos = taosArrayGetP(pGroupResInfo->pRows, i);
226,890,292✔
861
    SFilePage*  page = getBufPage(pBuf, pPos->pos.pageId);
226,172,282✔
862
    if (page == NULL) {
226,078,561!
863
      qError("failed to get buffer, code:%s, %s", tstrerror(terrno), GET_TASKID(pTaskInfo));
×
864
      T_LONG_JMP(pTaskInfo->env, terrno);
×
865
    }
866

867
    SResultRow* pRow = (SResultRow*)((char*)page + pPos->pos.offset);
226,078,561✔
868

869
    doUpdateNumOfRows(pCtx, pRow, numOfExprs, rowEntryOffset);
226,078,561✔
870

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

878
    if (!ignoreGroup) {
224,851,870✔
879
      if (pBlock->info.id.groupId == 0) {
154,405,390✔
880
        pBlock->info.id.groupId = pPos->groupId;
136,998,859✔
881
      } else {
882
        // current value belongs to different group, it can't be packed into one datablock
883
        if (pBlock->info.id.groupId != pPos->groupId) {
17,406,531✔
884
          releaseBufPage(pBuf, page);
125,628✔
885
          break;
125,620✔
886
        }
887
      }
888
    }
889

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

899
    pGroupResInfo->index += 1;
224,726,242✔
900
    code = copyResultrowToDataBlock(pExprInfo, numOfExprs, pRow, pCtx, pBlock, rowEntryOffset, pTaskInfo);
224,726,242✔
901
    releaseBufPage(pBuf, page);
227,418,097✔
902
    QUERY_CHECK_CODE(code, lino, _end);
226,740,318!
903

904
    pBlock->info.rows += pRow->numOfRows;
226,740,318✔
905
    if (pBlock->info.rows >= threshold) {
226,740,318✔
906
      break;
504,906✔
907
    }
908
  }
909

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

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

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

928
  // set output datablock version
929
  pBlock->info.version = pTaskInfo->version;
4,320,154✔
930

931
  blockDataCleanup(pBlock);
4,320,154✔
932
  if (!hasRemainResults(pGroupResInfo)) {
4,321,713✔
933
    return;
919,784✔
934
  }
935

936
  // clear the existed group id
937
  pBlock->info.id.groupId = 0;
3,401,260✔
938
  if (!pbInfo->mergeResultBlock) {
3,401,260✔
939
    doCopyToSDataBlock(pTaskInfo, pBlock, &pOperator->exprSupp, pBuf, pGroupResInfo, pOperator->resultInfo.threshold,
2,195,386✔
940
                       false);
941
  } else {
942
    while (hasRemainResults(pGroupResInfo)) {
2,164,346✔
943
      doCopyToSDataBlock(pTaskInfo, pBlock, &pOperator->exprSupp, pBuf, pGroupResInfo, pOperator->resultInfo.threshold,
1,205,650✔
944
                         true);
945
      if (pBlock->info.rows >= pOperator->resultInfo.threshold) {
1,205,764✔
946
        break;
247,292✔
947
      }
948

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

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

958
void destroyExprInfo(SExprInfo* pExpr, int32_t numOfExprs) {
10,464,391✔
959
  for (int32_t i = 0; i < numOfExprs; ++i) {
39,366,560✔
960
    SExprInfo* pExprInfo = &pExpr[i];
28,900,306✔
961
    for (int32_t j = 0; j < pExprInfo->base.numOfParams; ++j) {
59,708,070✔
962
      if (pExprInfo->base.pParam[j].type == FUNC_PARAM_TYPE_COLUMN) {
30,807,482✔
963
        taosMemoryFreeClear(pExprInfo->base.pParam[j].pCol);
27,568,729!
964
      } else if (pExprInfo->base.pParam[j].type == FUNC_PARAM_TYPE_VALUE) {
3,238,753✔
965
        taosVariantDestroy(&pExprInfo->base.pParam[j].param);
2,572,105✔
966
      }
967
    }
968

969
    taosMemoryFree(pExprInfo->base.pParam);
28,900,588!
970
    taosMemoryFree(pExprInfo->pExpr);
28,901,853!
971
  }
972
}
10,466,254✔
973

974
int32_t getBufferPgSize(int32_t rowSize, uint32_t* defaultPgsz, int64_t* defaultBufsz) {
6,831,620✔
975
  *defaultPgsz = 4096;
6,831,620✔
976
  uint32_t last = *defaultPgsz;
6,831,620✔
977
  while (*defaultPgsz < rowSize * 4) {
8,188,946✔
978
    *defaultPgsz <<= 1u;
1,357,326✔
979
    if (*defaultPgsz < last) {
1,357,326!
980
      return TSDB_CODE_INVALID_PARA;
×
981
    }
982
    last = *defaultPgsz;
1,357,326✔
983
  }
984

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

996
  return 0;
6,831,620✔
997
}
998

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

1004
  pResultInfo->capacity = numOfRows;
15,820,418✔
1005
  pResultInfo->threshold = numOfRows * 0.75;
15,820,418✔
1006

1007
  if (pResultInfo->threshold == 0) {
15,820,418✔
1008
    pResultInfo->threshold = numOfRows;
12,661✔
1009
  }
1010
}
15,820,418✔
1011

1012
void initBasicInfo(SOptrBasicInfo* pInfo, SSDataBlock* pBlock) {
6,818,074✔
1013
  pInfo->pRes = pBlock;
6,818,074✔
1014
  initResultRowInfo(&pInfo->resultRowInfo);
6,818,074✔
1015
}
6,817,733✔
1016

1017
static void destroySqlFunctionCtx(SqlFunctionCtx* pCtx, SExprInfo* pExpr, int32_t numOfOutput) {
30,824,555✔
1018
  if (pCtx == NULL) {
30,824,555✔
1019
    return;
19,484,337✔
1020
  }
1021

1022
  for (int32_t i = 0; i < numOfOutput; ++i) {
40,068,218✔
1023
    if (pExpr != NULL) {
28,723,851!
1024
      SExprInfo* pExprInfo = &pExpr[i];
28,725,658✔
1025
      for (int32_t j = 0; j < pExprInfo->base.numOfParams; ++j) {
59,355,515✔
1026
        if (pExprInfo->base.pParam[j].type == FUNC_PARAM_TYPE_VALUE) {
30,630,889✔
1027
          taosMemoryFree(pCtx[i].input.pData[j]);
2,568,661!
1028
          taosMemoryFree(pCtx[i].input.pColumnDataAgg[j]);
2,568,649!
1029
        }
1030
      }
1031
    }
1032
    for (int32_t j = 0; j < pCtx[i].numOfParams; ++j) {
59,352,548✔
1033
      taosVariantDestroy(&pCtx[i].param[j].param);
30,629,683✔
1034
    }
1035

1036
    taosMemoryFreeClear(pCtx[i].subsidiaries.pCtx);
28,722,865!
1037
    taosMemoryFreeClear(pCtx[i].subsidiaries.buf);
28,722,954!
1038
    taosMemoryFree(pCtx[i].input.pData);
28,722,953✔
1039
    taosMemoryFree(pCtx[i].input.pColumnDataAgg);
28,727,533!
1040

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

1046
  taosMemoryFreeClear(pCtx);
11,344,367!
1047
  return;
11,344,500✔
1048
}
1049

1050
int32_t initExprSupp(SExprSupp* pSup, SExprInfo* pExprInfo, int32_t numOfExpr, SFunctionStateStore* pStore) {
10,795,945✔
1051
  pSup->pExprInfo = pExprInfo;
10,795,945✔
1052
  pSup->numOfExprs = numOfExpr;
10,795,945✔
1053
  if (pSup->pExprInfo != NULL) {
10,795,945✔
1054
    pSup->pCtx = createSqlFunctionCtx(pExprInfo, numOfExpr, &pSup->rowEntryInfoOffset, pStore);
8,446,230✔
1055
    if (pSup->pCtx == NULL) {
8,442,631✔
1056
      return terrno;
484✔
1057
    }
1058
  }
1059

1060
  return TSDB_CODE_SUCCESS;
10,791,862✔
1061
}
1062

1063
void cleanupExprSupp(SExprSupp* pSupp) {
30,825,014✔
1064
  destroySqlFunctionCtx(pSupp->pCtx, pSupp->pExprInfo, pSupp->numOfExprs);
30,825,014✔
1065
  if (pSupp->pExprInfo != NULL) {
30,824,659✔
1066
    destroyExprInfo(pSupp->pExprInfo, pSupp->numOfExprs);
10,461,426✔
1067
    taosMemoryFreeClear(pSupp->pExprInfo);
10,461,373!
1068
  }
1069

1070
  if (pSupp->pFilterInfo != NULL) {
30,824,928✔
1071
    filterFreeInfo(pSupp->pFilterInfo);
2,935,838✔
1072
    pSupp->pFilterInfo = NULL;
2,935,885✔
1073
  }
1074

1075
  taosMemoryFree(pSupp->rowEntryInfoOffset);
30,824,975!
1076
}
30,823,885✔
1077

1078
void cleanupBasicInfo(SOptrBasicInfo* pInfo) {
6,842,565✔
1079
  blockDataDestroy(pInfo->pRes);
6,842,565✔
1080
  pInfo->pRes = NULL;
6,843,878✔
1081
}
6,843,878✔
1082

1083
bool groupbyTbname(SNodeList* pGroupList) {
4,736,695✔
1084
  bool bytbname = false;
4,736,695✔
1085
  SNode*pNode = NULL;
4,736,695✔
1086
  FOREACH(pNode, pGroupList) {
4,832,849✔
1087
    if (pNode->type == QUERY_NODE_FUNCTION) {
407,407✔
1088
      bytbname = (strcmp(((struct SFunctionNode*)pNode)->functionName, "tbname") == 0);
311,253✔
1089
      break;
311,253✔
1090
    }
1091
  }
1092
  return bytbname;
4,736,695✔
1093
}
1094

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

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

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

1120
      STableListInfo* pTableListInfo = taosArrayGetP(pInfoList, 0);
58,746✔
1121
      taosArrayDestroy(pInfoList);
58,747✔
1122

1123
      pDeleterParam->suid = tableListGetSuid(pTableListInfo);
58,752✔
1124

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

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

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

1155
      *pParam = pDeleterParam;
58,747✔
1156
      break;
58,747✔
1157
    }
1158
    default:
8,237,560✔
1159
      break;
8,237,560✔
1160
  }
1161

1162
  return TSDB_CODE_SUCCESS;
8,296,560✔
1163
}
1164

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

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

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

1186
  taosArrayDestroy(pParam->pChildren);
106,651✔
1187

1188
  taosMemoryFree(pParam->value);
106,651!
1189

1190
  taosMemoryFree(pParam);
106,651!
1191
}
106,651✔
1192

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

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

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

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

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

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

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

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

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

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

1228
void freeOperatorParam(SOperatorParam* pParam, SOperatorParamType type) {
5,716,352✔
1229
  if (NULL == pParam) {
5,716,352✔
1230
    return;
5,609,789✔
1231
  }
1232

1233
  switch (pParam->opType) {
106,563!
1234
    case QUERY_NODE_PHYSICAL_PLAN_EXCHANGE:
659✔
1235
      type == OP_GET_PARAM ? freeExchangeGetOperatorParam(pParam) : freeExchangeNotifyOperatorParam(pParam);
659!
1236
      break;
659✔
1237
    case QUERY_NODE_PHYSICAL_PLAN_GROUP_CACHE:
69,198✔
1238
      type == OP_GET_PARAM ? freeGroupCacheGetOperatorParam(pParam) : freeGroupCacheNotifyOperatorParam(pParam);
69,198!
1239
      break;
69,198✔
1240
    case QUERY_NODE_PHYSICAL_PLAN_MERGE_JOIN:
34,599✔
1241
      type == OP_GET_PARAM ? freeMergeJoinGetOperatorParam(pParam) : freeMergeJoinNotifyOperatorParam(pParam);
34,599!
1242
      break;
34,599✔
1243
    case QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN:
2,194✔
1244
      type == OP_GET_PARAM ? freeTableScanGetOperatorParam(pParam) : freeTableScanNotifyOperatorParam(pParam);
2,194!
1245
      break;
2,195✔
1246
    default:
×
1247
      qError("unsupported op %d param, type %d", pParam->opType, type);
×
1248
      break;
×
1249
  }
1250
}
1251

1252
void freeResetOperatorParams(struct SOperatorInfo* pOperator, SOperatorParamType type, bool allFree) {
39,531,730✔
1253
  SOperatorParam**  ppParam = NULL;
39,531,730✔
1254
  SOperatorParam*** pppDownstramParam = NULL;
39,531,730✔
1255
  switch (type) {
39,531,730!
1256
    case OP_GET_PARAM:
19,785,502✔
1257
      ppParam = &pOperator->pOperatorGetParam;
19,785,502✔
1258
      pppDownstramParam = &pOperator->pDownstreamGetParams;
19,785,502✔
1259
      break;
19,785,502✔
1260
    case OP_NOTIFY_PARAM:
19,750,233✔
1261
      ppParam = &pOperator->pOperatorNotifyParam;
19,750,233✔
1262
      pppDownstramParam = &pOperator->pDownstreamNotifyParams;
19,750,233✔
1263
      break;
19,750,233✔
1264
    default:
×
1265
      return;
×
1266
  }
1267

1268
  if (*ppParam) {
39,535,735✔
1269
    freeOperatorParam(*ppParam, type);
34,599✔
1270
    *ppParam = NULL;
34,599✔
1271
  }
1272

1273
  if (*pppDownstramParam) {
39,535,735✔
1274
    for (int32_t i = 0; i < pOperator->numOfDownstream; ++i) {
105,587✔
1275
      if ((*pppDownstramParam)[i]) {
69,198!
1276
        freeOperatorParam((*pppDownstramParam)[i], type);
×
1277
        (*pppDownstramParam)[i] = NULL;
×
1278
      }
1279
    }
1280
    if (allFree) {
36,389✔
1281
      taosMemoryFreeClear(*pppDownstramParam);
2,093!
1282
    }
1283
  }
1284
}
1285

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

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

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

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

1313
bool compareVal(const char* v, const SStateKeys* pKey) {
21,773,771✔
1314
  if (IS_VAR_DATA_TYPE(pKey->type)) {
21,773,771!
1315
    if (varDataLen(v) != varDataLen(pKey->pData)) {
2,854!
1316
      return false;
×
1317
    } else {
1318
      return memcmp(varDataVal(v), varDataVal(pKey->pData), varDataLen(v)) == 0;
2,854✔
1319
    }
1320
  } else {
1321
    return memcmp(pKey->pData, v, pKey->bytes) == 0;
21,770,917✔
1322
  }
1323
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc