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

taosdata / TDengine / #3546

03 Dec 2024 10:02AM UTC coverage: 60.691% (-0.1%) from 60.839%
#3546

push

travis-ci

web-flow
Merge pull request #29015 from taosdata/fix/TS-5668

[TS-5668] fix(keeper): fix endpoint value too long for column/tag and eliminate warnings

120577 of 253823 branches covered (47.5%)

Branch coverage included in aggregate %.

201666 of 277134 relevant lines covered (72.77%)

18719900.08 hits per line

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

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

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

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

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

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

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

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

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

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

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

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

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

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

85
SResultRow* getNewResultRow(SDiskbasedBuf* pResultBuf, int32_t* currentPageId, int32_t interBufSize) {
239,816,004✔
86
  SFilePage* pData = NULL;
239,816,004✔
87

88
  // in the first scan, new space needed for results
89
  int32_t pageId = -1;
239,816,004✔
90
  if (*currentPageId == -1) {
239,816,004✔
91
    pData = getNewBufPage(pResultBuf, &pageId);
5,335,699✔
92
    if (pData == NULL) {
5,336,235✔
93
      qError("failed to get buffer, code:%s", tstrerror(terrno));
341!
94
      return NULL;
×
95
    }
96
    pData->num = sizeof(SFilePage);
5,335,894✔
97
  } else {
98
    pData = getBufPage(pResultBuf, *currentPageId);
234,480,305✔
99
    if (pData == NULL) {
234,829,385!
100
      qError("failed to get buffer, code:%s", tstrerror(terrno));
×
101
      return NULL;
×
102
    }
103

104
    pageId = *currentPageId;
234,829,385✔
105

106
    if (pData->num + interBufSize > getBufPageSize(pResultBuf)) {
234,829,385✔
107
      // release current page first, and prepare the next one
108
      releaseBufPage(pResultBuf, pData);
17,651,906✔
109

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

119
  if (pData == NULL) {
240,445,354!
120
    return NULL;
×
121
  }
122

123
  setBufPageDirty(pData, true);
240,445,354✔
124

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

128
  memset((char*)pResultRow, 0, interBufSize);
239,948,213✔
129
  pResultRow->pageId = pageId;
239,948,213✔
130
  pResultRow->offset = (int32_t)pData->num;
239,948,213✔
131

132
  *currentPageId = pageId;
239,948,213✔
133
  pData->num += interBufSize;
239,948,213✔
134
  return pResultRow;
239,948,213✔
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,
293,622,447✔
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);
293,622,447✔
148
  if (!keepGroup) {
293,622,447✔
149
    *(uint64_t*)pSup->keyBuf = calcGroupId(pSup->keyBuf, GET_RES_WINDOW_KEY_LEN(bytes));
24,520,646✔
150
  }
151

152
  SResultRowPosition* p1 =
153
      (SResultRowPosition*)tSimpleHashGet(pSup->pResultRowHashTable, pSup->keyBuf, GET_RES_WINDOW_KEY_LEN(bytes));
293,927,290✔
154

155
  SResultRow* pResult = NULL;
293,017,890✔
156

157
  // in case of repeat scan/reverse scan, no new time window added.
158
  if (isIntervalQuery) {
293,017,890✔
159
    if (p1 != NULL) {  // the *p1 may be NULL in case of sliding+offset exists.
263,666,410✔
160
      pResult = getResultRowByPos(pResultBuf, p1, true);
45,798,033✔
161
      if (pResult == NULL) {
45,798,033!
162
        pTaskInfo->code = terrno;
×
163
        return NULL;
×
164
      }
165

166
      if (pResult->pageId != p1->pageId || pResult->offset != p1->offset) {
45,798,033!
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,351,480✔
176
      // todo
177
      pResult = getResultRowByPos(pResultBuf, p1, true);
6,393,773✔
178
      if (NULL == pResult) {
6,393,773!
179
        pTaskInfo->code = terrno;
×
180
        return NULL;
×
181
      }
182

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

191
  // 1. close current opened time window
192
  if (pResultRowInfo->cur.pageId != -1 && ((pResult == NULL) || (pResult->pageId != pResultRowInfo->cur.pageId))) {
292,792,994✔
193
    SResultRowPosition pos = pResultRowInfo->cur;
239,473,674✔
194
    SFilePage*         pPage = getBufPage(pResultBuf, pos.pageId);
239,473,674✔
195
    if (pPage == NULL) {
239,020,126!
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);
239,020,126✔
201
  }
202

203
  // allocate a new buffer page
204
  if (pResult == NULL) {
291,167,170✔
205
    pResult = getNewResultRow(pResultBuf, &pSup->currentPageId, pSup->resultRowSize);
239,353,356✔
206
    if (pResult == NULL) {
239,910,064!
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};
239,910,064✔
213
    int32_t code = tSimpleHashPut(pSup->pResultRowHashTable, pSup->keyBuf, GET_RES_WINDOW_KEY_LEN(bytes), &pos,
239,910,064✔
214
                                  sizeof(SResultRowPosition));
215
    if (code != TSDB_CODE_SUCCESS) {
242,866,509✔
216
      qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(code));
10,180!
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};
294,670,143✔
224

225
  // too many time window in query
226
  if (pTaskInfo->execModel == OPTR_EXEC_MODEL_BATCH &&
588,513,427!
227
      tSimpleHashGetSize(pSup->pResultRowHashTable) > MAX_INTERVAL_TIME_WINDOW) {
294,609,813✔
228
    pTaskInfo->code = TSDB_CODE_QRY_TOO_MANY_TIMEWINDOW;
×
229
    return NULL;
×
230
  }
231

232
  return pResult;
293,903,614✔
233
}
234

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

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

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

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

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

274
int32_t setInputDataBlock(SExprSupp* pExprSup, SSDataBlock* pBlock, int32_t order, int32_t scanFlag,
29,498,647✔
275
                          bool createDummyCol) {
276
  if (pBlock->pBlockAgg != NULL) {
29,498,647✔
277
    return doSetInputDataBlockInfo(pExprSup, pBlock, order, scanFlag);
1,850,237✔
278
  } else {
279
    return doSetInputDataBlock(pExprSup, pBlock, order, scanFlag, createDummyCol);
27,648,410✔
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,
27,648,666✔
335
                                   bool createDummyCol) {
336
  int32_t         code = TSDB_CODE_SUCCESS;
27,648,666✔
337
  int32_t         lino = 0;
27,648,666✔
338
  SqlFunctionCtx* pCtx = pExprSup->pCtx;
27,648,666✔
339

340
  for (int32_t i = 0; i < pExprSup->numOfExprs; ++i) {
102,973,764✔
341
    pCtx[i].order = order;
75,322,592✔
342
    pCtx[i].input.numOfRows = pBlock->info.rows;
75,322,592✔
343

344
    pCtx[i].pSrcBlock = pBlock;
75,322,592✔
345
    pCtx[i].scanFlag = scanFlag;
75,322,592✔
346

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

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

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

358
    for (int32_t j = 0; j < pOneExpr->base.numOfParams; ++j) {
158,314,417✔
359
      SFunctParam* pFuncParam = &pOneExpr->base.pParam[j];
82,989,319✔
360
      if (pFuncParam->type == FUNC_PARAM_TYPE_COLUMN) {
82,989,319✔
361
        int32_t slotId = pFuncParam->pCol->slotId;
73,934,868✔
362
        pInput->pData[j] = taosArrayGet(pBlock->pDataBlock, slotId);
73,934,868✔
363
        pInput->totalRows = pBlock->info.rows;
73,925,254✔
364
        pInput->numOfRows = pBlock->info.rows;
73,925,254✔
365
        pInput->startRowIndex = 0;
73,925,254✔
366
        pInput->blankFill = pBlock->info.blankFill;
73,925,254✔
367

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

371
        if (fmIsImplicitTsFunc(pCtx[i].functionId) && (j == tsParamIdx)) {
73,925,254✔
372
          pInput->pPTS = pInput->pData[j];  // in case of merge function, this is not always the ts column data.
11,008,656✔
373
        }
374
        if (hasPk && (j == pkParamIdx)) {
73,937,374✔
375
          pInput->pPrimaryKey = pInput->pData[j];
605,766✔
376
        }
377
        QUERY_CHECK_CONDITION((pInput->pData[j] != NULL), code, lino, _end, TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR);
73,937,374!
378
      } else if (pFuncParam->type == FUNC_PARAM_TYPE_VALUE) {
9,054,451✔
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,430,200!
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:
27,651,172✔
395
  if (code != TSDB_CODE_SUCCESS) {
27,651,172!
396
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
×
397
  }
398
  return code;
27,645,057✔
399
}
400

401
bool functionNeedToExecute(SqlFunctionCtx* pCtx) {
983,864,654✔
402
  struct SResultRowEntryInfo* pResInfo = GET_RES_INFO(pCtx);
983,864,654✔
403

404
  // in case of timestamp column, always generated results.
405
  int32_t functionId = pCtx->functionId;
983,864,654✔
406
  if (functionId == -1) {
983,864,654✔
407
    return false;
57,089,845✔
408
  }
409

410
  if (pCtx->scanFlag == PRE_SCAN) {
926,774,809✔
411
    return fmIsRepeatScanFunc(pCtx->functionId);
1,192,092✔
412
  }
413

414
  if (isRowEntryCompleted(pResInfo)) {
925,582,717✔
415
    return false;
4,160✔
416
  }
417

418
  return true;
925,578,557✔
419
}
420

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

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

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

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

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

486
    for (int32_t j = 0; j < pExprInfo->base.numOfParams; ++j) {
5,205,632✔
487
      SFunctParam* pFuncParam = &pExprInfo->base.pParam[j];
3,355,387✔
488

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

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

515
/////////////////////////////////////////////////////////////////////////////////////////////
516
STimeWindow getAlignQueryTimeWindow(const SInterval* pInterval, int64_t key) {
9,720,873✔
517
  STimeWindow win = {0};
9,720,873✔
518
  win.skey = taosTimeTruncate(key, pInterval);
9,720,873✔
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,720,499✔
525
  if (win.ekey < win.skey) {
9,719,703✔
526
    win.ekey = INT64_MAX;
2,150✔
527
  }
528

529
  return win;
9,719,703✔
530
}
531

532
int32_t setResultRowInitCtx(SResultRow* pResult, SqlFunctionCtx* pCtx, int32_t numOfOutput,
454,289,923✔
533
                            int32_t* rowEntryInfoOffset) {
534
  bool init = false;
454,289,923✔
535
  for (int32_t i = 0; i < numOfOutput; ++i) {
1,707,574,596✔
536
    pCtx[i].resultInfo = getResultEntryInfo(pResult, i, rowEntryInfoOffset);
1,254,760,334✔
537
    if (init) {
1,254,850,856✔
538
      continue;
116,449,474✔
539
    }
540

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

546
    if (pCtx[i].isPseudoFunc) {
1,138,401,382✔
547
      continue;
274,184,669✔
548
    }
549

550
    if (!pResInfo->initialized) {
864,216,713✔
551
      if (pCtx[i].functionId != -1) {
819,940,461✔
552
        int32_t code = pCtx[i].fpSet.init(&pCtx[i], pResInfo);
774,466,026✔
553
        if (code != TSDB_CODE_SUCCESS && fmIsUserDefinedFunc(pCtx[i].functionId)) {
774,720,799!
554
          pResInfo->initialized = false;
1,820,956✔
555
          qError("failed to initialize udf, funcId:%d error:%s", pCtx[i].functionId, tstrerror(code));
1,820,956!
556
          return TSDB_CODE_UDF_FUNC_EXEC_FAILURE;
44✔
557
        } else if (code != TSDB_CODE_SUCCESS) {
772,899,843!
558
          qError("failed to initialize function context, funcId:%d error:%s", pCtx[i].functionId, tstrerror(code));
×
559
          return code;
×
560
        }
561
      } else {
562
        pResInfo->initialized = true;
45,474,435✔
563
      }
564
    } else {
565
      init = true;
44,276,252✔
566
    }
567
  }
568
  return TSDB_CODE_SUCCESS;
452,814,262✔
569
}
570

571
void clearResultRowInitFlag(SqlFunctionCtx* pCtx, int32_t numOfOutput) {
87,218,285✔
572
  for (int32_t i = 0; i < numOfOutput; ++i) {
223,679,923✔
573
    SResultRowEntryInfo* pResInfo = pCtx[i].resultInfo;
136,461,638✔
574
    if (pResInfo == NULL) {
136,461,638!
575
      continue;
×
576
    }
577

578
    pResInfo->initialized = false;
136,461,638✔
579
    pResInfo->numOfRes = 0;
136,461,638✔
580
    pResInfo->isNullRes = 0;
136,461,638✔
581
    pResInfo->complete = false;
136,461,638✔
582
  }
583
}
87,218,285✔
584

585
int32_t doFilter(SSDataBlock* pBlock, SFilterInfo* pFilterInfo, SColMatchInfo* pColMatchInfo) {
41,946,844✔
586
  int32_t code = TSDB_CODE_SUCCESS;
41,946,844✔
587
  int32_t lino = 0;
41,946,844✔
588
  if (pFilterInfo == NULL || pBlock->info.rows == 0) {
41,946,844✔
589
    return TSDB_CODE_SUCCESS;
37,064,877✔
590
  }
591

592
  SFilterColumnParam param1 = {.numOfCols = taosArrayGetSize(pBlock->pDataBlock), .pDataBlock = pBlock->pDataBlock};
4,881,967✔
593
  SColumnInfoData*   p = NULL;
4,881,923✔
594

595
  code = filterSetDataFromSlotId(pFilterInfo, &param1);
4,881,923✔
596
  QUERY_CHECK_CODE(code, lino, _err);
4,881,733!
597

598
  int32_t status = 0;
4,881,733✔
599
  code = filterExecute(pFilterInfo, pBlock, &p, NULL, param1.numOfCols, &status);
4,881,733✔
600
  QUERY_CHECK_CODE(code, lino, _err);
4,881,878✔
601

602
  code = extractQualifiedTupleByFilterResult(pBlock, p, status);
4,881,877✔
603
  QUERY_CHECK_CODE(code, lino, _err);
4,881,786!
604

605
  if (pColMatchInfo != NULL) {
4,881,786✔
606
    size_t size = taosArrayGetSize(pColMatchInfo->pList);
4,024,749✔
607
    for (int32_t i = 0; i < size; ++i) {
4,029,948✔
608
      SColMatchItem* pInfo = taosArrayGet(pColMatchInfo->pList, i);
4,027,524✔
609
      QUERY_CHECK_NULL(pInfo, code, lino, _err, terrno);
4,027,473!
610
      if (pInfo->colId == PRIMARYKEY_TIMESTAMP_COL_ID) {
4,027,473✔
611
        SColumnInfoData* pColData = taosArrayGet(pBlock->pDataBlock, pInfo->dstSlotId);
4,022,289✔
612
        QUERY_CHECK_NULL(pColData, code, lino, _err, terrno);
4,022,211!
613
        if (pColData->info.type == TSDB_DATA_TYPE_TIMESTAMP) {
4,022,233!
614
          code = blockDataUpdateTsWindow(pBlock, pInfo->dstSlotId);
4,022,245✔
615
          QUERY_CHECK_CODE(code, lino, _err);
4,022,242!
616
          break;
4,022,242✔
617
        }
618
      }
619
    }
620
  }
621
  code = blockDataCheck(pBlock);
4,881,703✔
622
  QUERY_CHECK_CODE(code, lino, _err);
4,881,562!
623
_err:
4,881,562✔
624
  if (code != TSDB_CODE_SUCCESS) {
4,881,563✔
625
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
1!
626
  }
627
  colDataDestroy(p);
4,881,563✔
628
  taosMemoryFree(p);
4,882,221✔
629
  return code;
4,882,351✔
630
}
631

632
int32_t extractQualifiedTupleByFilterResult(SSDataBlock* pBlock, const SColumnInfoData* p, int32_t status) {
4,881,901✔
633
  int32_t code = TSDB_CODE_SUCCESS;
4,881,901✔
634
  int8_t* pIndicator = (int8_t*)p->pData;
4,881,901✔
635
  if (status == FILTER_RESULT_ALL_QUALIFIED) {
4,881,901✔
636
    // here nothing needs to be done
637
  } else if (status == FILTER_RESULT_NONE_QUALIFIED) {
1,051,823✔
638
    code = trimDataBlock(pBlock, pBlock->info.rows, NULL);
578,160✔
639
    pBlock->info.rows = 0;
578,074✔
640
  } else if (status == FILTER_RESULT_PARTIAL_QUALIFIED) {
473,663!
641
    code = trimDataBlock(pBlock, pBlock->info.rows, (bool*)pIndicator);
473,712✔
642
  } else {
643
    qError("unknown filter result type: %d", status);
×
644
  }
645
  return code;
4,881,996✔
646
}
647

648
void doUpdateNumOfRows(SqlFunctionCtx* pCtx, SResultRow* pRow, int32_t numOfExprs, const int32_t* rowEntryOffset) {
405,220,218✔
649
  bool returnNotNull = false;
405,220,218✔
650
  for (int32_t j = 0; j < numOfExprs; ++j) {
1,461,274,770✔
651
    SResultRowEntryInfo* pResInfo = getResultEntryInfo(pRow, j, rowEntryOffset);
1,056,195,276✔
652
    if (!isRowEntryInitialized(pResInfo)) {
1,056,054,552✔
653
      continue;
224,326,093✔
654
    } else {
655
    }
656

657
    if (pRow->numOfRows < pResInfo->numOfRes) {
831,728,459✔
658
      pRow->numOfRows = pResInfo->numOfRes;
396,996,221✔
659
    }
660

661
    if (pCtx[j].isNotNullFunc) {
831,728,459✔
662
      returnNotNull = true;
237,945,440✔
663
    }
664
  }
665
  // if all expr skips all blocks, e.g. all null inputs for max function, output one row in final result.
666
  //  except for first/last, which require not null output, output no rows
667
  if (pRow->numOfRows == 0 && !returnNotNull) {
405,079,494✔
668
    pRow->numOfRows = 1;
26,991✔
669
  }
670
}
405,079,494✔
671

672
int32_t copyResultrowToDataBlock(SExprInfo* pExprInfo, int32_t numOfExprs, SResultRow* pRow, SqlFunctionCtx* pCtx,
389,692,548✔
673
                                 SSDataBlock* pBlock, const int32_t* rowEntryOffset, SExecTaskInfo* pTaskInfo) {
674
  int32_t code = TSDB_CODE_SUCCESS;
389,692,548✔
675
  int32_t lino = 0;
389,692,548✔
676
  for (int32_t j = 0; j < numOfExprs; ++j) {
1,367,501,808✔
677
    int32_t slotId = pExprInfo[j].base.resSchema.slotId;
978,374,409✔
678

679
    pCtx[j].resultInfo = getResultEntryInfo(pRow, j, rowEntryOffset);
978,374,409✔
680
    if (pCtx[j].fpSet.finalize) {
978,782,398✔
681
      if (strcmp(pCtx[j].pExpr->pExpr->_function.functionName, "_group_key") == 0 ||
583,351,527✔
682
          strcmp(pCtx[j].pExpr->pExpr->_function.functionName, "_group_const_value") == 0) {
488,369,562✔
683
        // for groupkey along with functions that output multiple lines(e.g. Histogram)
684
        // need to match groupkey result for each output row of that function.
685
        if (pCtx[j].resultInfo->numOfRes != 0) {
95,232,474!
686
          pCtx[j].resultInfo->numOfRes = pRow->numOfRows;
96,761,053✔
687
        }
688
      }
689

690
      code = blockDataEnsureCapacity(pBlock, pBlock->info.rows + pCtx[j].resultInfo->numOfRes);
583,351,527✔
691
      QUERY_CHECK_CODE(code, lino, _end);
583,825,403!
692

693
      code = pCtx[j].fpSet.finalize(&pCtx[j], pBlock);
583,825,403✔
694
      if (TSDB_CODE_SUCCESS != code) {
585,585,635!
695
        qError("%s build result data block error, code %s", GET_TASKID(pTaskInfo), tstrerror(code));
×
696
        QUERY_CHECK_CODE(code, lino, _end);
×
697
      }
698
    } else if (strcmp(pCtx[j].pExpr->pExpr->_function.functionName, "_select_value") == 0) {
395,430,871✔
699
      // do nothing
700
    } else {
701
      // expand the result into multiple rows. E.g., _wstart, top(k, 20)
702
      // the _wstart needs to copy to 20 following rows, since the results of top-k expands to 20 different rows.
703
      SColumnInfoData* pColInfoData = taosArrayGet(pBlock->pDataBlock, slotId);
250,245,449✔
704
      QUERY_CHECK_NULL(pColInfoData, code, lino, _end, terrno);
249,374,713✔
705
      char*            in = GET_ROWCELL_INTERBUF(pCtx[j].resultInfo);
249,205,723✔
706
      for (int32_t k = 0; k < pRow->numOfRows; ++k) {
503,824,598✔
707
        code = colDataSetValOrCover(pColInfoData, pBlock->info.rows + k, in, pCtx[j].resultInfo->isNullRes);
254,444,879✔
708
        QUERY_CHECK_CODE(code, lino, _end);
254,618,875!
709
      }
710
    }
711
  }
712

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

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

729
  SResultRow* pRow = (SResultRow*)((char*)page + resultRowPosition->offset);
66,466,987✔
730

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

735
  doUpdateNumOfRows(pCtx, pRow, pSup->numOfExprs, rowEntryOffset);
66,466,987✔
736
  if (pRow->numOfRows == 0) {
66,444,450✔
737
    releaseBufPage(pBuf, page);
4,573✔
738
    return;
×
739
  }
740

741
  int32_t size = pBlock->info.capacity;
66,439,877✔
742
  while (pBlock->info.rows + pRow->numOfRows > size) {
66,520,814✔
743
    size = size * 1.25;
80,937✔
744
  }
745

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

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

760
  releaseBufPage(pBuf, page);
66,432,388✔
761
  pBlock->info.rows += pRow->numOfRows;
66,415,557✔
762
}
763

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

773
  size_t  keyLen = 0;
6,176,992✔
774
  int32_t numOfRows = tSimpleHashGetSize(pHashmap);
6,176,992✔
775

776
  // begin from last iter
777
  void*   pData = pGroupResInfo->dataPos;
6,172,197✔
778
  int32_t iter = pGroupResInfo->iter;
6,172,197✔
779
  while ((pData = tSimpleHashIterate(pHashmap, pData, &iter)) != NULL) {
24,549,298✔
780
    void*               key = tSimpleHashGetKey(pData, &keyLen);
24,192,118✔
781
    SResultRowPosition* pos = pData;
24,192,118✔
782
    uint64_t            groupId = *(uint64_t*)key;
24,192,118✔
783

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

790
    SResultRow* pRow = (SResultRow*)((char*)page + pos->offset);
24,187,643✔
791

792
    doUpdateNumOfRows(pCtx, pRow, numOfExprs, rowEntryOffset);
24,187,643✔
793

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

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

804
    if (!ignoreGroup) {
24,133,892✔
805
      if (pBlock->info.id.groupId == 0) {
11,634,369✔
806
        pBlock->info.id.groupId = groupId;
5,866,828✔
807
      } else {
808
        // current value belongs to different group, it can't be packed into one datablock
809
        if (pBlock->info.id.groupId != groupId) {
5,767,541!
810
          releaseBufPage(pBuf, page);
5,794,611✔
811
          break;
5,795,534✔
812
        }
813
      }
814
    }
815

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

825
    pGroupResInfo->index += 1;
18,339,281✔
826
    pGroupResInfo->iter = iter;
18,339,281✔
827
    pGroupResInfo->dataPos = pData;
18,339,281✔
828

829
    code = copyResultrowToDataBlock(pExprInfo, numOfExprs, pRow, pCtx, pBlock, rowEntryOffset, pTaskInfo);
18,339,281✔
830
    releaseBufPage(pBuf, page);
18,380,346✔
831
    QUERY_CHECK_CODE(code, lino, _end);
18,377,141!
832
    pBlock->info.rows += pRow->numOfRows;
18,377,141✔
833
    if (pBlock->info.rows >= threshold) {
18,377,141✔
834
      break;
40✔
835
    }
836
  }
837

838
  qDebug("%s result generated, rows:%" PRId64 ", groupId:%" PRIu64, GET_TASKID(pTaskInfo), pBlock->info.rows,
6,143,452✔
839
         pBlock->info.id.groupId);
840
  pBlock->info.dataLoad = 1;
6,143,453✔
841
  code = blockDataUpdateTsWindow(pBlock, 0);
6,143,453✔
842
  QUERY_CHECK_CODE(code, lino, _end);
6,145,214!
843

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

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

860
  int32_t numOfRows = getNumOfTotalRes(pGroupResInfo);
3,307,047✔
861

862
  for (int32_t i = pGroupResInfo->index; i < numOfRows; i += 1) {
222,498,321✔
863
    SResKeyPos* pPos = taosArrayGetP(pGroupResInfo->pRows, i);
219,776,085✔
864
    SFilePage*  page = getBufPage(pBuf, pPos->pos.pageId);
219,718,825✔
865
    if (page == NULL) {
219,914,528!
866
      qError("failed to get buffer, code:%s, %s", tstrerror(terrno), GET_TASKID(pTaskInfo));
×
867
      T_LONG_JMP(pTaskInfo->env, terrno);
×
868
    }
869

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

872
    doUpdateNumOfRows(pCtx, pRow, numOfExprs, rowEntryOffset);
219,914,528✔
873

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

881
    if (!ignoreGroup) {
217,590,363✔
882
      if (pBlock->info.id.groupId == 0) {
144,975,634✔
883
        pBlock->info.id.groupId = pPos->groupId;
128,459,257✔
884
      } else {
885
        // current value belongs to different group, it can't be packed into one datablock
886
        if (pBlock->info.id.groupId != pPos->groupId) {
16,516,377✔
887
          releaseBufPage(pBuf, page);
133,341✔
888
          break;
133,339✔
889
        }
890
      }
891
    }
892

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

902
    pGroupResInfo->index += 1;
217,457,022✔
903
    code = copyResultrowToDataBlock(pExprInfo, numOfExprs, pRow, pCtx, pBlock, rowEntryOffset, pTaskInfo);
217,457,022✔
904
    releaseBufPage(pBuf, page);
220,433,537✔
905
    QUERY_CHECK_CODE(code, lino, _end);
219,626,179!
906

907
    pBlock->info.rows += pRow->numOfRows;
219,626,179✔
908
    if (pBlock->info.rows >= threshold) {
219,626,179✔
909
      break;
435,878✔
910
    }
911
  }
912

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

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

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

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

934
  blockDataCleanup(pBlock);
4,222,232✔
935
  if (!hasRemainResults(pGroupResInfo)) {
4,223,010✔
936
    return;
915,186✔
937
  }
938

939
  // clear the existed group id
940
  pBlock->info.id.groupId = 0;
3,307,629✔
941
  if (!pbInfo->mergeResultBlock) {
3,307,629✔
942
    doCopyToSDataBlock(pTaskInfo, pBlock, &pOperator->exprSupp, pBuf, pGroupResInfo, pOperator->resultInfo.threshold,
2,144,583✔
943
                       false);
944
  } else {
945
    while (hasRemainResults(pGroupResInfo)) {
2,118,388✔
946
      doCopyToSDataBlock(pTaskInfo, pBlock, &pOperator->exprSupp, pBuf, pGroupResInfo, pOperator->resultInfo.threshold,
1,162,701✔
947
                         true);
948
      if (pBlock->info.rows >= pOperator->resultInfo.threshold) {
1,162,787✔
949
        break;
207,445✔
950
      }
951

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

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

961
void destroyExprInfo(SExprInfo* pExpr, int32_t numOfExprs) {
10,358,642✔
962
  for (int32_t i = 0; i < numOfExprs; ++i) {
41,581,863✔
963
    SExprInfo* pExprInfo = &pExpr[i];
31,222,313✔
964
    for (int32_t j = 0; j < pExprInfo->base.numOfParams; ++j) {
64,432,244✔
965
      if (pExprInfo->base.pParam[j].type == FUNC_PARAM_TYPE_COLUMN) {
33,224,017✔
966
        taosMemoryFreeClear(pExprInfo->base.pParam[j].pCol);
29,862,321✔
967
      } else if (pExprInfo->base.pParam[j].type == FUNC_PARAM_TYPE_VALUE) {
3,361,696✔
968
        taosVariantDestroy(&pExprInfo->base.pParam[j].param);
2,549,531✔
969
      }
970
    }
971

972
    taosMemoryFree(pExprInfo->base.pParam);
31,208,227✔
973
    taosMemoryFree(pExprInfo->pExpr);
31,201,785✔
974
  }
975
}
10,359,550✔
976

977
int32_t getBufferPgSize(int32_t rowSize, uint32_t* defaultPgsz, uint32_t* defaultBufsz) {
6,795,767✔
978
  *defaultPgsz = 4096;
6,795,767✔
979
  uint32_t last = *defaultPgsz;
6,795,767✔
980
  while (*defaultPgsz < rowSize * 4) {
8,144,724✔
981
    *defaultPgsz <<= 1u;
1,348,957✔
982
    if (*defaultPgsz < last) {
1,348,957!
983
      return TSDB_CODE_INVALID_PARA;
×
984
    }
985
    last = *defaultPgsz;
1,348,957✔
986
  }
987

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

999
  return 0;
6,795,767✔
1000
}
1001

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

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

1010
  if (pResultInfo->threshold == 0) {
15,687,956✔
1011
    pResultInfo->threshold = numOfRows;
12,102✔
1012
  }
1013
}
15,687,956✔
1014

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

1020
static void destroySqlFunctionCtx(SqlFunctionCtx* pCtx, SExprInfo* pExpr, int32_t numOfOutput) {
30,442,371✔
1021
  if (pCtx == NULL) {
30,442,371✔
1022
    return;
19,217,614✔
1023
  }
1024

1025
  for (int32_t i = 0; i < numOfOutput; ++i) {
42,159,254✔
1026
    if (pExpr != NULL) {
30,935,021✔
1027
      SExprInfo* pExprInfo = &pExpr[i];
30,933,659✔
1028
      for (int32_t j = 0; j < pExprInfo->base.numOfParams; ++j) {
63,869,928✔
1029
        if (pExprInfo->base.pParam[j].type == FUNC_PARAM_TYPE_VALUE) {
32,935,107✔
1030
          taosMemoryFree(pCtx[i].input.pData[j]);
2,545,433✔
1031
          taosMemoryFree(pCtx[i].input.pColumnDataAgg[j]);
2,545,370✔
1032
        }
1033
      }
1034
    }
1035
    for (int32_t j = 0; j < pCtx[i].numOfParams; ++j) {
63,855,355✔
1036
      taosVariantDestroy(&pCtx[i].param[j].param);
32,921,803✔
1037
    }
1038

1039
    taosMemoryFreeClear(pCtx[i].subsidiaries.pCtx);
30,933,552✔
1040
    taosMemoryFreeClear(pCtx[i].subsidiaries.buf);
30,933,643✔
1041
    taosMemoryFree(pCtx[i].input.pData);
30,933,638✔
1042
    taosMemoryFree(pCtx[i].input.pColumnDataAgg);
30,941,795✔
1043

1044
    if (pCtx[i].udfName != NULL) {
30,935,240✔
1045
      taosMemoryFree(pCtx[i].udfName);
599✔
1046
    }
1047
  }
1048

1049
  taosMemoryFreeClear(pCtx);
11,224,233!
1050
  return;
11,224,721✔
1051
}
1052

1053
int32_t initExprSupp(SExprSupp* pSup, SExprInfo* pExprInfo, int32_t numOfExpr, SFunctionStateStore* pStore) {
10,740,454✔
1054
  pSup->pExprInfo = pExprInfo;
10,740,454✔
1055
  pSup->numOfExprs = numOfExpr;
10,740,454✔
1056
  if (pSup->pExprInfo != NULL) {
10,740,454✔
1057
    pSup->pCtx = createSqlFunctionCtx(pExprInfo, numOfExpr, &pSup->rowEntryInfoOffset, pStore);
8,389,999✔
1058
    if (pSup->pCtx == NULL) {
8,387,860!
1059
      return TSDB_CODE_OUT_OF_MEMORY;
×
1060
    }
1061
  }
1062

1063
  return TSDB_CODE_SUCCESS;
10,738,315✔
1064
}
1065

1066
void cleanupExprSupp(SExprSupp* pSupp) {
30,443,593✔
1067
  destroySqlFunctionCtx(pSupp->pCtx, pSupp->pExprInfo, pSupp->numOfExprs);
30,443,593✔
1068
  if (pSupp->pExprInfo != NULL) {
30,441,776✔
1069
    destroyExprInfo(pSupp->pExprInfo, pSupp->numOfExprs);
10,353,538✔
1070
    taosMemoryFreeClear(pSupp->pExprInfo);
10,353,664!
1071
  }
1072

1073
  if (pSupp->pFilterInfo != NULL) {
30,442,188✔
1074
    filterFreeInfo(pSupp->pFilterInfo);
2,885,420✔
1075
    pSupp->pFilterInfo = NULL;
2,885,468✔
1076
  }
1077

1078
  taosMemoryFree(pSupp->rowEntryInfoOffset);
30,442,236✔
1079
}
30,420,047✔
1080

1081
void cleanupBasicInfo(SOptrBasicInfo* pInfo) {
6,805,914✔
1082
  blockDataDestroy(pInfo->pRes);
6,805,914✔
1083
  pInfo->pRes = NULL;
6,806,606✔
1084
}
6,806,606✔
1085

1086
bool groupbyTbname(SNodeList* pGroupList) {
4,658,049✔
1087
  bool bytbname = false;
4,658,049✔
1088
  SNode*pNode = NULL;
4,658,049✔
1089
  FOREACH(pNode, pGroupList) {
4,756,496✔
1090
    if (pNode->type == QUERY_NODE_FUNCTION) {
414,736✔
1091
      bytbname = (strcmp(((struct SFunctionNode*)pNode)->functionName, "tbname") == 0);
316,289✔
1092
      break;
316,289✔
1093
    }
1094
  }
1095
  return bytbname;
4,658,049✔
1096
}
1097

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

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

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

1123
      STableListInfo* pTableListInfo = taosArrayGetP(pInfoList, 0);
59,979✔
1124
      taosArrayDestroy(pInfoList);
59,981✔
1125

1126
      pDeleterParam->suid = tableListGetSuid(pTableListInfo);
59,986✔
1127

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

1137
      pDeleterParam->pUidList = taosArrayInit(numOfTables, sizeof(uint64_t));
59,976✔
1138
      if (NULL == pDeleterParam->pUidList) {
59,987✔
1139
        taosMemoryFree(pDeleterParam);
4✔
1140
        return terrno;
×
1141
      }
1142

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

1158
      *pParam = pDeleterParam;
59,986✔
1159
      break;
59,986✔
1160
    }
1161
    default:
8,162,492✔
1162
      break;
8,162,492✔
1163
  }
1164

1165
  return TSDB_CODE_SUCCESS;
8,222,914✔
1166
}
1167

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

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

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

1189
  taosArrayDestroy(pParam->pChildren);
106,186✔
1190

1191
  taosMemoryFree(pParam->value);
106,186✔
1192

1193
  taosMemoryFree(pParam);
106,186✔
1194
}
106,186✔
1195

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

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

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

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

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

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

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

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

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

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

1231
void freeOperatorParam(SOperatorParam* pParam, SOperatorParamType type) {
5,583,849✔
1232
  if (NULL == pParam) {
5,583,849✔
1233
    return;
5,477,765✔
1234
  }
1235

1236
  switch (pParam->opType) {
106,084!
1237
    case QUERY_NODE_PHYSICAL_PLAN_EXCHANGE:
632✔
1238
      type == OP_GET_PARAM ? freeExchangeGetOperatorParam(pParam) : freeExchangeNotifyOperatorParam(pParam);
632!
1239
      break;
632✔
1240
    case QUERY_NODE_PHYSICAL_PLAN_GROUP_CACHE:
68,992✔
1241
      type == OP_GET_PARAM ? freeGroupCacheGetOperatorParam(pParam) : freeGroupCacheNotifyOperatorParam(pParam);
68,992!
1242
      break;
68,992✔
1243
    case QUERY_NODE_PHYSICAL_PLAN_MERGE_JOIN:
34,496✔
1244
      type == OP_GET_PARAM ? freeMergeJoinGetOperatorParam(pParam) : freeMergeJoinNotifyOperatorParam(pParam);
34,496!
1245
      break;
34,496✔
1246
    case QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN:
2,065✔
1247
      type == OP_GET_PARAM ? freeTableScanGetOperatorParam(pParam) : freeTableScanNotifyOperatorParam(pParam);
2,065!
1248
      break;
2,066✔
1249
    default:
×
1250
      qError("unsupported op %d param, type %d", pParam->opType, type);
×
1251
      break;
×
1252
  }
1253
}
1254

1255
void freeResetOperatorParams(struct SOperatorInfo* pOperator, SOperatorParamType type, bool allFree) {
38,977,093✔
1256
  SOperatorParam**  ppParam = NULL;
38,977,093✔
1257
  SOperatorParam*** pppDownstramParam = NULL;
38,977,093✔
1258
  switch (type) {
38,977,093!
1259
    case OP_GET_PARAM:
19,518,729✔
1260
      ppParam = &pOperator->pOperatorGetParam;
19,518,729✔
1261
      pppDownstramParam = &pOperator->pDownstreamGetParams;
19,518,729✔
1262
      break;
19,518,729✔
1263
    case OP_NOTIFY_PARAM:
19,484,680✔
1264
      ppParam = &pOperator->pOperatorNotifyParam;
19,484,680✔
1265
      pppDownstramParam = &pOperator->pDownstreamNotifyParams;
19,484,680✔
1266
      break;
19,484,680✔
1267
    default:
×
1268
      return;
×
1269
  }
1270

1271
  if (*ppParam) {
39,003,409✔
1272
    freeOperatorParam(*ppParam, type);
34,496✔
1273
    *ppParam = NULL;
34,496✔
1274
  }
1275

1276
  if (*pppDownstramParam) {
39,003,409✔
1277
    for (int32_t i = 0; i < pOperator->numOfDownstream; ++i) {
105,154✔
1278
      if ((*pppDownstramParam)[i]) {
68,992!
1279
        freeOperatorParam((*pppDownstramParam)[i], type);
×
1280
        (*pppDownstramParam)[i] = NULL;
×
1281
      }
1282
    }
1283
    if (allFree) {
36,162✔
1284
      taosMemoryFreeClear(*pppDownstramParam);
1,923!
1285
    }
1286
  }
1287
}
1288

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

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

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

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

1316
bool compareVal(const char* v, const SStateKeys* pKey) {
20,257,205✔
1317
  if (IS_VAR_DATA_TYPE(pKey->type)) {
20,257,205!
1318
    if (varDataLen(v) != varDataLen(pKey->pData)) {
1,954!
1319
      return false;
×
1320
    } else {
1321
      return memcmp(varDataVal(v), varDataVal(pKey->pData), varDataLen(v)) == 0;
1,954✔
1322
    }
1323
  } else {
1324
    return memcmp(pKey->pData, v, pKey->bytes) == 0;
20,255,251✔
1325
  }
1326
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc