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

taosdata / TDengine / #3541

26 Nov 2024 03:56AM UTC coverage: 60.776% (-0.07%) from 60.846%
#3541

push

travis-ci

web-flow
Merge pull request #28920 from taosdata/fix/TD-33008-3.0

fix(query)[TD-33008]. fix error handling in tsdbCacheRead

120076 of 252763 branches covered (47.51%)

Branch coverage included in aggregate %.

0 of 2 new or added lines in 1 file covered. (0.0%)

1395 existing lines in 154 files now uncovered.

200995 of 275526 relevant lines covered (72.95%)

19612328.37 hits per line

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

69.01
/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) {
258,800,746✔
86
  SFilePage* pData = NULL;
258,800,746✔
87

88
  // in the first scan, new space needed for results
89
  int32_t pageId = -1;
258,800,746✔
90
  if (*currentPageId == -1) {
258,800,746✔
91
    pData = getNewBufPage(pResultBuf, &pageId);
5,206,427✔
92
    if (pData == NULL) {
5,206,487✔
93
      qError("failed to get buffer, code:%s", tstrerror(terrno));
147!
94
      return NULL;
×
95
    }
96
    pData->num = sizeof(SFilePage);
5,206,340✔
97
  } else {
98
    pData = getBufPage(pResultBuf, *currentPageId);
253,594,319✔
99
    if (pData == NULL) {
253,801,953!
100
      qError("failed to get buffer, code:%s", tstrerror(terrno));
×
101
      return NULL;
×
102
    }
103

104
    pageId = *currentPageId;
253,801,953✔
105

106
    if (pData->num + interBufSize > getBufPageSize(pResultBuf)) {
253,801,953✔
107
      // release current page first, and prepare the next one
108
      releaseBufPage(pResultBuf, pData);
18,546,532✔
109

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

119
  if (pData == NULL) {
259,145,476!
120
    return NULL;
×
121
  }
122

123
  setBufPageDirty(pData, true);
259,145,476✔
124

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

128
  memset((char*)pResultRow, 0, interBufSize);
258,781,406✔
129
  pResultRow->pageId = pageId;
258,781,406✔
130
  pResultRow->offset = (int32_t)pData->num;
258,781,406✔
131

132
  *currentPageId = pageId;
258,781,406✔
133
  pData->num += interBufSize;
258,781,406✔
134
  return pResultRow;
258,781,406✔
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,
317,774,528✔
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);
317,774,528✔
148
  if (!keepGroup) {
317,774,528✔
149
    *(uint64_t*)pSup->keyBuf = calcGroupId(pSup->keyBuf, GET_RES_WINDOW_KEY_LEN(bytes));
17,054,838✔
150
  }
151

152
  SResultRowPosition* p1 =
153
      (SResultRowPosition*)tSimpleHashGet(pSup->pResultRowHashTable, pSup->keyBuf, GET_RES_WINDOW_KEY_LEN(bytes));
317,988,915✔
154

155
  SResultRow* pResult = NULL;
319,095,423✔
156

157
  // in case of repeat scan/reverse scan, no new time window added.
158
  if (isIntervalQuery) {
319,095,423✔
159
    if (p1 != NULL) {  // the *p1 may be NULL in case of sliding+offset exists.
297,564,158✔
160
      pResult = getResultRowByPos(pResultBuf, p1, true);
51,013,487✔
161
      if (pResult == NULL) {
51,013,487!
162
        pTaskInfo->code = terrno;
×
163
        return NULL;
×
164
      }
165

166
      if (pResult->pageId != p1->pageId || pResult->offset != p1->offset) {
51,013,487!
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) {
21,531,265✔
176
      // todo
177
      pResult = getResultRowByPos(pResultBuf, p1, true);
6,643,873✔
178
      if (NULL == pResult) {
6,643,873!
179
        pTaskInfo->code = terrno;
×
180
        return NULL;
×
181
      }
182

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

191
  // 1. close current opened time window
192
  if (pResultRowInfo->cur.pageId != -1 && ((pResult == NULL) || (pResult->pageId != pResultRowInfo->cur.pageId))) {
318,598,590✔
193
    SResultRowPosition pos = pResultRowInfo->cur;
259,802,432✔
194
    SFilePage*         pPage = getBufPage(pResultBuf, pos.pageId);
259,802,432✔
195
    if (pPage == NULL) {
258,144,733!
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);
258,144,733✔
201
  }
202

203
  // allocate a new buffer page
204
  if (pResult == NULL) {
316,019,440✔
205
    pResult = getNewResultRow(pResultBuf, &pSup->currentPageId, pSup->resultRowSize);
258,377,215✔
206
    if (pResult == NULL) {
258,918,399!
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};
258,918,399✔
213
    int32_t code = tSimpleHashPut(pSup->pResultRowHashTable, pSup->keyBuf, GET_RES_WINDOW_KEY_LEN(bytes), &pos,
258,918,399✔
214
                                  sizeof(SResultRowPosition));
215
    if (code != TSDB_CODE_SUCCESS) {
261,071,213!
UNCOV
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};
318,824,696✔
224

225
  // too many time window in query
226
  if (pTaskInfo->execModel == OPTR_EXEC_MODEL_BATCH &&
636,748,778!
227
      tSimpleHashGetSize(pSup->pResultRowHashTable) > MAX_INTERVAL_TIME_WINDOW) {
318,675,468✔
228
    pTaskInfo->code = TSDB_CODE_QRY_TOO_MANY_TIMEWINDOW;
×
229
    return NULL;
×
230
  }
231

232
  return pResult;
318,073,310✔
233
}
234

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

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

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

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

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

274
int32_t setInputDataBlock(SExprSupp* pExprSup, SSDataBlock* pBlock, int32_t order, int32_t scanFlag,
26,385,064✔
275
                          bool createDummyCol) {
276
  if (pBlock->pBlockAgg != NULL) {
26,385,064✔
277
    return doSetInputDataBlockInfo(pExprSup, pBlock, order, scanFlag);
1,874,381✔
278
  } else {
279
    return doSetInputDataBlock(pExprSup, pBlock, order, scanFlag, createDummyCol);
24,510,683✔
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,
24,510,456✔
335
                                   bool createDummyCol) {
336
  int32_t         code = TSDB_CODE_SUCCESS;
24,510,456✔
337
  int32_t         lino = 0;
24,510,456✔
338
  SqlFunctionCtx* pCtx = pExprSup->pCtx;
24,510,456✔
339

340
  for (int32_t i = 0; i < pExprSup->numOfExprs; ++i) {
91,149,091✔
341
    pCtx[i].order = order;
66,640,688✔
342
    pCtx[i].input.numOfRows = pBlock->info.rows;
66,640,688✔
343

344
    pCtx[i].pSrcBlock = pBlock;
66,640,688✔
345
    pCtx[i].scanFlag = scanFlag;
66,640,688✔
346

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

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

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

358
    for (int32_t j = 0; j < pOneExpr->base.numOfParams; ++j) {
141,226,724✔
359
      SFunctParam* pFuncParam = &pOneExpr->base.pParam[j];
74,588,089✔
360
      if (pFuncParam->type == FUNC_PARAM_TYPE_COLUMN) {
74,588,089✔
361
        int32_t slotId = pFuncParam->pCol->slotId;
65,203,488✔
362
        pInput->pData[j] = taosArrayGet(pBlock->pDataBlock, slotId);
65,203,488✔
363
        pInput->totalRows = pBlock->info.rows;
65,200,549✔
364
        pInput->numOfRows = pBlock->info.rows;
65,200,549✔
365
        pInput->startRowIndex = 0;
65,200,549✔
366
        pInput->blankFill = pBlock->info.blankFill;
65,200,549✔
367

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

371
        if (fmIsImplicitTsFunc(pCtx[i].functionId) && (j == tsParamIdx)) {
65,200,549✔
372
          pInput->pPTS = pInput->pData[j];  // in case of merge function, this is not always the ts column data.
6,648,769✔
373
        }
374
        if (hasPk && (j == pkParamIdx)) {
65,201,435✔
375
          pInput->pPrimaryKey = pInput->pData[j];
620,526✔
376
        }
377
        QUERY_CHECK_CONDITION((pInput->pData[j] != NULL), code, lino, _end, TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR);
65,201,435!
378
      } else if (pFuncParam->type == FUNC_PARAM_TYPE_VALUE) {
9,384,601✔
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,779,910!
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:
24,508,403✔
395
  if (code != TSDB_CODE_SUCCESS) {
24,508,403!
396
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
×
397
  }
398
  return code;
24,513,030✔
399
}
400

401
bool functionNeedToExecute(SqlFunctionCtx* pCtx) {
1,008,087,689✔
402
  struct SResultRowEntryInfo* pResInfo = GET_RES_INFO(pCtx);
1,008,087,689✔
403

404
  // in case of timestamp column, always generated results.
405
  int32_t functionId = pCtx->functionId;
1,008,087,689✔
406
  if (functionId == -1) {
1,008,087,689✔
407
    return false;
51,169,892✔
408
  }
409

410
  if (pCtx->scanFlag == PRE_SCAN) {
956,917,797✔
411
    return fmIsRepeatScanFunc(pCtx->functionId);
1,203,412✔
412
  }
413

414
  if (isRowEntryCompleted(pResInfo)) {
955,714,385✔
415
    return false;
4,198✔
416
  }
417

418
  return true;
955,710,187✔
419
}
420

421
static int32_t doCreateConstantValColumnSMAInfo(SInputColumnInfoData* pInput, SFunctParam* pFuncParam, int32_t type,
1,523,610✔
422
                                                int32_t paramIndex, int32_t numOfRows) {
423
  if (pInput->pData[paramIndex] == NULL) {
1,523,610✔
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,523,610✔
435
  if (pInput->pColumnDataAgg[paramIndex] == NULL) {
1,523,610✔
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,523,592✔
446
  }
447

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

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

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

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

486
    for (int32_t j = 0; j < pExprInfo->base.numOfParams; ++j) {
5,272,388✔
487
      SFunctParam* pFuncParam = &pExprInfo->base.pParam[j];
3,397,999✔
488

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

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

515
/////////////////////////////////////////////////////////////////////////////////////////////
516
STimeWindow getAlignQueryTimeWindow(const SInterval* pInterval, int64_t key) {
9,276,259✔
517
  STimeWindow win = {0};
9,276,259✔
518
  win.skey = taosTimeTruncate(key, pInterval);
9,276,259✔
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);
9,276,193✔
525
  if (win.ekey < win.skey) {
9,275,990✔
526
    win.ekey = INT64_MAX;
2,145✔
527
  }
528

529
  return win;
9,275,990✔
530
}
531

532
int32_t setResultRowInitCtx(SResultRow* pResult, SqlFunctionCtx* pCtx, int32_t numOfOutput,
497,261,056✔
533
                            int32_t* rowEntryInfoOffset) {
534
  bool init = false;
497,261,056✔
535
  for (int32_t i = 0; i < numOfOutput; ++i) {
1,792,629,221✔
536
    pCtx[i].resultInfo = getResultEntryInfo(pResult, i, rowEntryInfoOffset);
1,296,105,576✔
537
    if (init) {
1,296,225,391✔
538
      continue;
115,958,781✔
539
    }
540

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

546
    if (pCtx[i].isPseudoFunc) {
1,180,266,574✔
547
      continue;
287,398,315✔
548
    }
549

550
    if (!pResInfo->initialized) {
892,868,259✔
551
      if (pCtx[i].functionId != -1) {
843,358,232✔
552
        int32_t code = pCtx[i].fpSet.init(&pCtx[i], pResInfo);
804,028,317✔
553
        if (code != TSDB_CODE_SUCCESS && fmIsUserDefinedFunc(pCtx[i].functionId)) {
804,088,989!
554
          pResInfo->initialized = false;
44✔
555
          return TSDB_CODE_UDF_FUNC_EXEC_FAILURE;
44✔
556
        } else if (code != TSDB_CODE_SUCCESS) {
803,171,091!
557
          return code;
×
558
        }
559
      } else {
560
        pResInfo->initialized = true;
39,329,915✔
561
      }
562
    } else {
563
      init = true;
49,510,027✔
564
    }
565
  }
566
  return TSDB_CODE_SUCCESS;
496,523,645✔
567
}
568

569
void clearResultRowInitFlag(SqlFunctionCtx* pCtx, int32_t numOfOutput) {
102,735,309✔
570
  for (int32_t i = 0; i < numOfOutput; ++i) {
255,482,784✔
571
    SResultRowEntryInfo* pResInfo = pCtx[i].resultInfo;
152,747,475✔
572
    if (pResInfo == NULL) {
152,747,475!
573
      continue;
×
574
    }
575

576
    pResInfo->initialized = false;
152,747,475✔
577
    pResInfo->numOfRes = 0;
152,747,475✔
578
    pResInfo->isNullRes = 0;
152,747,475✔
579
    pResInfo->complete = false;
152,747,475✔
580
  }
581
}
102,735,309✔
582

583
int32_t doFilter(SSDataBlock* pBlock, SFilterInfo* pFilterInfo, SColMatchInfo* pColMatchInfo) {
36,750,666✔
584
  int32_t code = TSDB_CODE_SUCCESS;
36,750,666✔
585
  int32_t lino = 0;
36,750,666✔
586
  if (pFilterInfo == NULL || pBlock->info.rows == 0) {
36,750,666✔
587
    return TSDB_CODE_SUCCESS;
31,222,018✔
588
  }
589

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

593
  code = filterSetDataFromSlotId(pFilterInfo, &param1);
5,528,556✔
594
  QUERY_CHECK_CODE(code, lino, _err);
5,528,499!
595

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

600
  code = extractQualifiedTupleByFilterResult(pBlock, p, status);
5,528,592✔
601
  QUERY_CHECK_CODE(code, lino, _err);
5,528,513!
602

603
  if (pColMatchInfo != NULL) {
5,528,513✔
604
    size_t size = taosArrayGetSize(pColMatchInfo->pList);
4,666,105✔
605
    for (int32_t i = 0; i < size; ++i) {
4,671,597✔
606
      SColMatchItem* pInfo = taosArrayGet(pColMatchInfo->pList, i);
4,669,145✔
607
      QUERY_CHECK_NULL(pInfo, code, lino, _err, terrno);
4,669,106!
608
      if (pInfo->colId == PRIMARYKEY_TIMESTAMP_COL_ID) {
4,669,106✔
609
        SColumnInfoData* pColData = taosArrayGet(pBlock->pDataBlock, pInfo->dstSlotId);
4,663,774✔
610
        QUERY_CHECK_NULL(pColData, code, lino, _err, terrno);
4,663,713!
611
        if (pColData->info.type == TSDB_DATA_TYPE_TIMESTAMP) {
4,663,771✔
612
          code = blockDataUpdateTsWindow(pBlock, pInfo->dstSlotId);
4,663,722✔
613
          QUERY_CHECK_CODE(code, lino, _err);
4,663,836!
614
          break;
4,663,836✔
615
        }
616
      }
617
    }
618
  }
619
  code = blockDataCheck(pBlock);
5,528,696✔
620
  QUERY_CHECK_CODE(code, lino, _err);
5,528,477!
621
_err:
5,528,477✔
622
  if (code != TSDB_CODE_SUCCESS) {
5,528,478✔
623
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
1!
624
  }
625
  colDataDestroy(p);
5,528,478✔
626
  taosMemoryFree(p);
5,528,806✔
627
  return code;
5,528,678✔
628
}
629

630
int32_t extractQualifiedTupleByFilterResult(SSDataBlock* pBlock, const SColumnInfoData* p, int32_t status) {
5,528,599✔
631
  int32_t code = TSDB_CODE_SUCCESS;
5,528,599✔
632
  int8_t* pIndicator = (int8_t*)p->pData;
5,528,599✔
633
  if (status == FILTER_RESULT_ALL_QUALIFIED) {
5,528,599✔
634
    // here nothing needs to be done
635
  } else if (status == FILTER_RESULT_NONE_QUALIFIED) {
1,049,639✔
636
    code = trimDataBlock(pBlock, pBlock->info.rows, NULL);
582,988✔
637
    pBlock->info.rows = 0;
582,956✔
638
  } else if (status == FILTER_RESULT_PARTIAL_QUALIFIED) {
466,651!
639
    code = trimDataBlock(pBlock, pBlock->info.rows, (bool*)pIndicator);
466,697✔
640
  } else {
641
    qError("unknown filter result type: %d", status);
×
642
  }
643
  return code;
5,528,717✔
644
}
645

646
void doUpdateNumOfRows(SqlFunctionCtx* pCtx, SResultRow* pRow, int32_t numOfExprs, const int32_t* rowEntryOffset) {
440,948,234✔
647
  bool returnNotNull = false;
440,948,234✔
648
  for (int32_t j = 0; j < numOfExprs; ++j) {
1,536,348,332✔
649
    SResultRowEntryInfo* pResInfo = getResultEntryInfo(pRow, j, rowEntryOffset);
1,094,750,413✔
650
    if (!isRowEntryInitialized(pResInfo)) {
1,095,400,098✔
651
      continue;
238,147,723✔
652
    } else {
653
    }
654

655
    if (pRow->numOfRows < pResInfo->numOfRes) {
857,252,375✔
656
      pRow->numOfRows = pResInfo->numOfRes;
437,122,748✔
657
    }
658

659
    if (pCtx[j].isNotNullFunc) {
857,252,375✔
660
      returnNotNull = true;
234,430,187✔
661
    }
662
  }
663
  // if all expr skips all blocks, e.g. all null inputs for max function, output one row in final result.
664
  //  except for first/last, which require not null output, output no rows
665
  if (pRow->numOfRows == 0 && !returnNotNull) {
441,597,919✔
666
    pRow->numOfRows = 1;
29,219✔
667
  }
668
}
441,597,919✔
669

670
int32_t copyResultrowToDataBlock(SExprInfo* pExprInfo, int32_t numOfExprs, SResultRow* pRow, SqlFunctionCtx* pCtx,
430,353,458✔
671
                                 SSDataBlock* pBlock, const int32_t* rowEntryOffset, SExecTaskInfo* pTaskInfo) {
672
  int32_t code = TSDB_CODE_SUCCESS;
430,353,458✔
673
  int32_t lino = 0;
430,353,458✔
674
  for (int32_t j = 0; j < numOfExprs; ++j) {
1,450,613,766✔
675
    int32_t slotId = pExprInfo[j].base.resSchema.slotId;
1,021,429,842✔
676

677
    pCtx[j].resultInfo = getResultEntryInfo(pRow, j, rowEntryOffset);
1,021,429,842✔
678
    if (pCtx[j].fpSet.finalize) {
1,021,398,750✔
679
      if (strcmp(pCtx[j].pExpr->pExpr->_function.functionName, "_group_key") == 0 ||
624,893,786✔
680
          strcmp(pCtx[j].pExpr->pExpr->_function.functionName, "_group_const_value") == 0) {
532,295,284✔
681
        // for groupkey along with functions that output multiple lines(e.g. Histogram)
682
        // need to match groupkey result for each output row of that function.
683
        if (pCtx[j].resultInfo->numOfRes != 0) {
92,849,210!
684
          pCtx[j].resultInfo->numOfRes = pRow->numOfRows;
94,209,133✔
685
        }
686
      }
687

688
      code = blockDataEnsureCapacity(pBlock, pBlock->info.rows + pCtx[j].resultInfo->numOfRes);
624,893,786✔
689
      QUERY_CHECK_CODE(code, lino, _end);
625,193,844!
690

691
      code = pCtx[j].fpSet.finalize(&pCtx[j], pBlock);
625,193,844✔
692
      if (TSDB_CODE_SUCCESS != code) {
627,084,481!
693
        qError("%s build result data block error, code %s", GET_TASKID(pTaskInfo), tstrerror(code));
×
694
        QUERY_CHECK_CODE(code, lino, _end);
×
695
      }
696
    } else if (strcmp(pCtx[j].pExpr->pExpr->_function.functionName, "_select_value") == 0) {
396,504,964✔
697
      // do nothing
698
    } else {
699
      // expand the result into multiple rows. E.g., _wstart, top(k, 20)
700
      // the _wstart needs to copy to 20 following rows, since the results of top-k expands to 20 different rows.
701
      SColumnInfoData* pColInfoData = taosArrayGet(pBlock->pDataBlock, slotId);
257,667,760✔
702
      QUERY_CHECK_NULL(pColInfoData, code, lino, _end, terrno);
256,647,580!
703
      char*            in = GET_ROWCELL_INTERBUF(pCtx[j].resultInfo);
256,770,800✔
704
      for (int32_t k = 0; k < pRow->numOfRows; ++k) {
525,019,779✔
705
        code = colDataSetValOrCover(pColInfoData, pBlock->info.rows + k, in, pCtx[j].resultInfo->isNullRes);
268,162,111✔
706
        QUERY_CHECK_CODE(code, lino, _end);
268,248,979!
707
      }
708
    }
709
  }
710

711
_end:
429,183,924✔
712
  if (code != TSDB_CODE_SUCCESS) {
429,183,924!
713
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
×
714
  }
715
  return code;
430,751,366✔
716
}
717

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

727
  SResultRow* pRow = (SResultRow*)((char*)page + resultRowPosition->offset);
70,684,859✔
728

729
  SqlFunctionCtx* pCtx = pSup->pCtx;
70,684,859✔
730
  SExprInfo*      pExprInfo = pSup->pExprInfo;
70,684,859✔
731
  const int32_t*  rowEntryOffset = pSup->rowEntryInfoOffset;
70,684,859✔
732

733
  doUpdateNumOfRows(pCtx, pRow, pSup->numOfExprs, rowEntryOffset);
70,684,859✔
734
  if (pRow->numOfRows == 0) {
70,666,403!
735
    releaseBufPage(pBuf, page);
×
736
    return;
×
737
  }
738

739
  int32_t size = pBlock->info.capacity;
70,667,063✔
740
  while (pBlock->info.rows + pRow->numOfRows > size) {
70,767,027✔
741
    size = size * 1.25;
99,964✔
742
  }
743

744
  int32_t code = blockDataEnsureCapacity(pBlock, size);
70,667,063✔
745
  if (TAOS_FAILED(code)) {
70,673,171!
746
    releaseBufPage(pBuf, page);
×
747
    qError("%s ensure result data capacity failed, code %s", GET_TASKID(pTaskInfo), tstrerror(code));
×
748
    T_LONG_JMP(pTaskInfo->env, code);
×
749
  }
750

751
  code = copyResultrowToDataBlock(pExprInfo, pSup->numOfExprs, pRow, pCtx, pBlock, rowEntryOffset, pTaskInfo);
70,673,171✔
752
  if (TAOS_FAILED(code)) {
70,649,323!
753
    releaseBufPage(pBuf, page);
×
754
    qError("%s copy result row to datablock failed, code %s", GET_TASKID(pTaskInfo), tstrerror(code));
×
755
    T_LONG_JMP(pTaskInfo->env, code);
×
756
  }
757

758
  releaseBufPage(pBuf, page);
70,649,323✔
759
  pBlock->info.rows += pRow->numOfRows;
70,630,840✔
760
}
761

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

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

774
  // begin from last iter
775
  void*   pData = pGroupResInfo->dataPos;
3,287,008✔
776
  int32_t iter = pGroupResInfo->iter;
3,287,008✔
777
  while ((pData = tSimpleHashIterate(pHashmap, pData, &iter)) != NULL) {
13,929,074✔
778
    void*               key = tSimpleHashGetKey(pData, &keyLen);
13,585,767✔
779
    SResultRowPosition* pos = pData;
13,585,767✔
780
    uint64_t            groupId = *(uint64_t*)key;
13,585,767✔
781

782
    SFilePage* page = getBufPage(pBuf, pos->pageId);
13,585,767✔
783
    if (page == NULL) {
13,581,076!
784
      qError("failed to get buffer, code:%s, %s", tstrerror(terrno), GET_TASKID(pTaskInfo));
×
785
      T_LONG_JMP(pTaskInfo->env, terrno);
×
786
    }
787

788
    SResultRow* pRow = (SResultRow*)((char*)page + pos->offset);
13,581,076✔
789

790
    doUpdateNumOfRows(pCtx, pRow, numOfExprs, rowEntryOffset);
13,581,076✔
791

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

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

802
    if (!ignoreGroup) {
13,549,367✔
803
      if (pBlock->info.id.groupId == 0) {
5,903,340✔
804
        pBlock->info.id.groupId = groupId;
2,990,523✔
805
      } else {
806
        // current value belongs to different group, it can't be packed into one datablock
807
        if (pBlock->info.id.groupId != groupId) {
2,912,817!
808
          releaseBufPage(pBuf, page);
2,931,681✔
809
          break;
2,930,846✔
810
        }
811
      }
812
    }
813

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

823
    pGroupResInfo->index += 1;
10,617,686✔
824
    pGroupResInfo->iter = iter;
10,617,686✔
825
    pGroupResInfo->dataPos = pData;
10,617,686✔
826

827
    code = copyResultrowToDataBlock(pExprInfo, numOfExprs, pRow, pCtx, pBlock, rowEntryOffset, pTaskInfo);
10,617,686✔
828
    releaseBufPage(pBuf, page);
10,644,694✔
829
    QUERY_CHECK_CODE(code, lino, _end);
10,642,106!
830
    pBlock->info.rows += pRow->numOfRows;
10,642,106✔
831
    if (pBlock->info.rows >= threshold) {
10,642,106✔
832
      break;
40✔
833
    }
834
  }
835

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

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

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

858
  int32_t numOfRows = getNumOfTotalRes(pGroupResInfo);
3,162,459✔
859

860
  for (int32_t i = pGroupResInfo->index; i < numOfRows; i += 1) {
249,191,785✔
861
    SResKeyPos* pPos = taosArrayGetP(pGroupResInfo->pRows, i);
246,693,132✔
862
    SFilePage*  page = getBufPage(pBuf, pPos->pos.pageId);
246,148,083✔
863
    if (page == NULL) {
246,373,177!
864
      qError("failed to get buffer, code:%s, %s", tstrerror(terrno), GET_TASKID(pTaskInfo));
×
865
      T_LONG_JMP(pTaskInfo->env, terrno);
×
866
    }
867

868
    SResultRow* pRow = (SResultRow*)((char*)page + pPos->pos.offset);
246,373,177✔
869

870
    doUpdateNumOfRows(pCtx, pRow, numOfExprs, rowEntryOffset);
246,373,177✔
871

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

879
    if (!ignoreGroup) {
245,722,464✔
880
      if (pBlock->info.id.groupId == 0) {
158,953,137✔
881
        pBlock->info.id.groupId = pPos->groupId;
141,351,040✔
882
      } else {
883
        // current value belongs to different group, it can't be packed into one datablock
884
        if (pBlock->info.id.groupId != pPos->groupId) {
17,602,097✔
885
          releaseBufPage(pBuf, page);
132,769✔
886
          break;
132,767✔
887
        }
888
      }
889
    }
890

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

900
    pGroupResInfo->index += 1;
245,589,695✔
901
    code = copyResultrowToDataBlock(pExprInfo, numOfExprs, pRow, pCtx, pBlock, rowEntryOffset, pTaskInfo);
245,589,695✔
902
    releaseBufPage(pBuf, page);
247,284,457✔
903
    QUERY_CHECK_CODE(code, lino, _end);
246,525,463!
904

905
    pBlock->info.rows += pRow->numOfRows;
246,525,463✔
906
    if (pBlock->info.rows >= threshold) {
246,525,463✔
907
      break;
497,059✔
908
    }
909
  }
910

911
  qDebug("%s result generated, rows:%" PRId64 ", groupId:%" PRIu64, GET_TASKID(pTaskInfo), pBlock->info.rows,
3,128,479✔
912
         pBlock->info.id.groupId);
913
  pBlock->info.dataLoad = 1;
3,128,481✔
914
  code = blockDataUpdateTsWindow(pBlock, 0);
3,128,481✔
915
  QUERY_CHECK_CODE(code, lino, _end);
3,162,142!
916

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

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

929
  // set output datablock version
930
  pBlock->info.version = pTaskInfo->version;
4,101,899✔
931

932
  blockDataCleanup(pBlock);
4,101,899✔
933
  if (!hasRemainResults(pGroupResInfo)) {
4,102,702✔
934
    return;
939,592✔
935
  }
936

937
  // clear the existed group id
938
  pBlock->info.id.groupId = 0;
3,162,703✔
939
  if (!pbInfo->mergeResultBlock) {
3,162,703✔
940
    doCopyToSDataBlock(pTaskInfo, pBlock, &pOperator->exprSupp, pBuf, pGroupResInfo, pOperator->resultInfo.threshold,
1,932,991✔
941
                       false);
942
  } else {
943
    while (hasRemainResults(pGroupResInfo)) {
2,221,487✔
944
      doCopyToSDataBlock(pTaskInfo, pBlock, &pOperator->exprSupp, pBuf, pGroupResInfo, pOperator->resultInfo.threshold,
1,229,508✔
945
                         true);
946
      if (pBlock->info.rows >= pOperator->resultInfo.threshold) {
1,229,647✔
947
        break;
237,872✔
948
      }
949

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

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

959
void destroyExprInfo(SExprInfo* pExpr, int32_t numOfExprs) {
10,505,753✔
960
  for (int32_t i = 0; i < numOfExprs; ++i) {
42,260,060✔
961
    SExprInfo* pExprInfo = &pExpr[i];
31,753,740✔
962
    for (int32_t j = 0; j < pExprInfo->base.numOfParams; ++j) {
65,673,683✔
963
      if (pExprInfo->base.pParam[j].type == FUNC_PARAM_TYPE_COLUMN) {
33,928,510✔
964
        taosMemoryFreeClear(pExprInfo->base.pParam[j].pCol);
30,405,798!
965
      } else if (pExprInfo->base.pParam[j].type == FUNC_PARAM_TYPE_VALUE) {
3,522,712✔
966
        taosVariantDestroy(&pExprInfo->base.pParam[j].param);
2,711,578✔
967
      }
968
    }
969

970
    taosMemoryFree(pExprInfo->base.pParam);
31,745,173✔
971
    taosMemoryFree(pExprInfo->pExpr);
31,758,641✔
972
  }
973
}
10,506,320✔
974

975
int32_t getBufferPgSize(int32_t rowSize, uint32_t* defaultPgsz, uint32_t* defaultBufsz) {
6,740,279✔
976
  *defaultPgsz = 4096;
6,740,279✔
977
  uint32_t last = *defaultPgsz;
6,740,279✔
978
  while (*defaultPgsz < rowSize * 4) {
8,501,645✔
979
    *defaultPgsz <<= 1u;
1,761,366✔
980
    if (*defaultPgsz < last) {
1,761,366!
981
      return TSDB_CODE_INVALID_PARA;
×
982
    }
983
    last = *defaultPgsz;
1,761,366✔
984
  }
985

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

997
  return 0;
6,740,279✔
998
}
999

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

1005
  pResultInfo->capacity = numOfRows;
15,949,704✔
1006
  pResultInfo->threshold = numOfRows * 0.75;
15,949,704✔
1007

1008
  if (pResultInfo->threshold == 0) {
15,949,704✔
1009
    pResultInfo->threshold = numOfRows;
301,713✔
1010
  }
1011
}
15,949,704✔
1012

1013
void initBasicInfo(SOptrBasicInfo* pInfo, SSDataBlock* pBlock) {
6,721,549✔
1014
  pInfo->pRes = pBlock;
6,721,549✔
1015
  initResultRowInfo(&pInfo->resultRowInfo);
6,721,549✔
1016
}
6,721,467✔
1017

1018
static void destroySqlFunctionCtx(SqlFunctionCtx* pCtx, SExprInfo* pExpr, int32_t numOfOutput) {
30,989,709✔
1019
  if (pCtx == NULL) {
30,989,709✔
1020
    return;
19,597,218✔
1021
  }
1022

1023
  for (int32_t i = 0; i < numOfOutput; ++i) {
42,884,344✔
1024
    if (pExpr != NULL) {
31,485,012!
1025
      SExprInfo* pExprInfo = &pExpr[i];
31,488,111✔
1026
      for (int32_t j = 0; j < pExprInfo->base.numOfParams; ++j) {
65,143,636✔
1027
        if (pExprInfo->base.pParam[j].type == FUNC_PARAM_TYPE_VALUE) {
33,656,600✔
1028
          taosMemoryFree(pCtx[i].input.pData[j]);
2,707,485✔
1029
          taosMemoryFree(pCtx[i].input.pColumnDataAgg[j]);
2,707,431✔
1030
        }
1031
      }
1032
    }
1033
    for (int32_t j = 0; j < pCtx[i].numOfParams; ++j) {
65,132,905✔
1034
      taosVariantDestroy(&pCtx[i].param[j].param);
33,654,938✔
1035
    }
1036

1037
    taosMemoryFreeClear(pCtx[i].subsidiaries.pCtx);
31,477,967✔
1038
    taosMemoryFreeClear(pCtx[i].subsidiaries.buf);
31,478,028✔
1039
    taosMemoryFree(pCtx[i].input.pData);
31,478,031✔
1040
    taosMemoryFree(pCtx[i].input.pColumnDataAgg);
31,488,963✔
1041

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

1047
  taosMemoryFreeClear(pCtx);
11,399,332✔
1048
  return;
11,399,287✔
1049
}
1050

1051
int32_t initExprSupp(SExprSupp* pSup, SExprInfo* pExprInfo, int32_t numOfExpr, SFunctionStateStore* pStore) {
10,431,213✔
1052
  pSup->pExprInfo = pExprInfo;
10,431,213✔
1053
  pSup->numOfExprs = numOfExpr;
10,431,213✔
1054
  if (pSup->pExprInfo != NULL) {
10,431,213✔
1055
    pSup->pCtx = createSqlFunctionCtx(pExprInfo, numOfExpr, &pSup->rowEntryInfoOffset, pStore);
8,344,535✔
1056
    if (pSup->pCtx == NULL) {
8,343,352!
1057
      return TSDB_CODE_OUT_OF_MEMORY;
×
1058
    }
1059
  }
1060

1061
  return TSDB_CODE_SUCCESS;
10,430,030✔
1062
}
1063

1064
void cleanupExprSupp(SExprSupp* pSupp) {
30,989,965✔
1065
  destroySqlFunctionCtx(pSupp->pCtx, pSupp->pExprInfo, pSupp->numOfExprs);
30,989,965✔
1066
  if (pSupp->pExprInfo != NULL) {
30,988,812✔
1067
    destroyExprInfo(pSupp->pExprInfo, pSupp->numOfExprs);
10,500,494✔
1068
    taosMemoryFreeClear(pSupp->pExprInfo);
10,500,549✔
1069
  }
1070

1071
  if (pSupp->pFilterInfo != NULL) {
30,989,133✔
1072
    filterFreeInfo(pSupp->pFilterInfo);
3,037,879✔
1073
    pSupp->pFilterInfo = NULL;
3,037,858✔
1074
  }
1075

1076
  taosMemoryFree(pSupp->rowEntryInfoOffset);
30,989,112✔
1077
}
30,983,769✔
1078

1079
void cleanupBasicInfo(SOptrBasicInfo* pInfo) {
6,749,670✔
1080
  blockDataDestroy(pInfo->pRes);
6,749,670✔
1081
  pInfo->pRes = NULL;
6,749,868✔
1082
}
6,749,868✔
1083

1084
bool groupbyTbname(SNodeList* pGroupList) {
4,893,134✔
1085
  bool bytbname = false;
4,893,134✔
1086
  SNode*pNode = NULL;
4,893,134✔
1087
  FOREACH(pNode, pGroupList) {
4,989,917✔
1088
    if (pNode->type == QUERY_NODE_FUNCTION) {
410,715✔
1089
      bytbname = (strcmp(((struct SFunctionNode*)pNode)->functionName, "tbname") == 0);
313,932✔
1090
      break;
313,932✔
1091
    }
1092
  }
1093
  return bytbname;
4,893,134✔
1094
}
1095

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

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

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

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

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

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

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

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

1156
      *pParam = pDeleterParam;
60,135✔
1157
      break;
60,135✔
1158
    }
1159
    default:
8,466,420✔
1160
      break;
8,466,420✔
1161
  }
1162

1163
  return TSDB_CODE_SUCCESS;
8,527,394✔
1164
}
1165

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

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

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

1187
  taosArrayDestroy(pParam->pChildren);
105,979✔
1188

1189
  taosMemoryFree(pParam->value);
105,979✔
1190

1191
  taosMemoryFree(pParam);
105,979✔
1192
}
105,979✔
1193

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

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

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

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

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

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

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

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

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

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

1229
void freeOperatorParam(SOperatorParam* pParam, SOperatorParamType type) {
5,762,966✔
1230
  if (NULL == pParam) {
5,762,966✔
1231
    return;
5,657,091✔
1232
  }
1233

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

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

1269
  if (*ppParam) {
39,868,402✔
1270
    freeOperatorParam(*ppParam, type);
34,473✔
1271
    *ppParam = NULL;
34,473✔
1272
  }
1273

1274
  if (*pppDownstramParam) {
39,868,402✔
1275
    for (int32_t i = 0; i < pOperator->numOfDownstream; ++i) {
104,993✔
1276
      if ((*pppDownstramParam)[i]) {
68,946!
1277
        freeOperatorParam((*pppDownstramParam)[i], type);
×
1278
        (*pppDownstramParam)[i] = NULL;
×
1279
      }
1280
    }
1281
    if (allFree) {
36,047✔
1282
      taosMemoryFreeClear(*pppDownstramParam);
1,808!
1283
    }
1284
  }
1285
}
1286

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

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

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

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

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

© 2025 Coveralls, Inc