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

taosdata / TDengine / #3544

30 Nov 2024 03:06AM UTC coverage: 60.88% (+0.04%) from 60.842%
#3544

push

travis-ci

web-flow
Merge pull request #28988 from taosdata/main

merge: from main to 3.0 branch

120724 of 253479 branches covered (47.63%)

Branch coverage included in aggregate %.

407 of 489 new or added lines in 21 files covered. (83.23%)

1148 existing lines in 113 files now uncovered.

201919 of 276488 relevant lines covered (73.03%)

18898587.44 hits per line

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

68.66
/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) {
242,684,681✔
86
  SFilePage* pData = NULL;
242,684,681✔
87

88
  // in the first scan, new space needed for results
89
  int32_t pageId = -1;
242,684,681✔
90
  if (*currentPageId == -1) {
242,684,681✔
91
    pData = getNewBufPage(pResultBuf, &pageId);
5,058,166✔
92
    if (pData == NULL) {
5,058,297✔
93
      qError("failed to get buffer, code:%s", tstrerror(terrno));
86!
94
      return NULL;
×
95
    }
96
    pData->num = sizeof(SFilePage);
5,058,211✔
97
  } else {
98
    pData = getBufPage(pResultBuf, *currentPageId);
237,626,515✔
99
    if (pData == NULL) {
237,928,172!
100
      qError("failed to get buffer, code:%s", tstrerror(terrno));
×
101
      return NULL;
×
102
    }
103

104
    pageId = *currentPageId;
237,928,172✔
105

106
    if (pData->num + interBufSize > getBufPageSize(pResultBuf)) {
237,928,172✔
107
      // release current page first, and prepare the next one
108
      releaseBufPage(pResultBuf, pData);
16,882,511✔
109

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

119
  if (pData == NULL) {
243,161,211!
120
    return NULL;
×
121
  }
122

123
  setBufPageDirty(pData, true);
243,161,211✔
124

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

128
  memset((char*)pResultRow, 0, interBufSize);
242,699,461✔
129
  pResultRow->pageId = pageId;
242,699,461✔
130
  pResultRow->offset = (int32_t)pData->num;
242,699,461✔
131

132
  *currentPageId = pageId;
242,699,461✔
133
  pData->num += interBufSize;
242,699,461✔
134
  return pResultRow;
242,699,461✔
135
}
136

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

152
  SResultRowPosition* p1 =
153
      (SResultRowPosition*)tSimpleHashGet(pSup->pResultRowHashTable, pSup->keyBuf, GET_RES_WINDOW_KEY_LEN(bytes));
301,364,730✔
154

155
  SResultRow* pResult = NULL;
300,676,987✔
156

157
  // in case of repeat scan/reverse scan, no new time window added.
158
  if (isIntervalQuery) {
300,676,987✔
159
    if (p1 != NULL) {  // the *p1 may be NULL in case of sliding+offset exists.
269,114,560✔
160
      pResult = getResultRowByPos(pResultBuf, p1, true);
48,047,686✔
161
      if (pResult == NULL) {
48,047,686!
162
        pTaskInfo->code = terrno;
×
163
        return NULL;
×
164
      }
165

166
      if (pResult->pageId != p1->pageId || pResult->offset != p1->offset) {
48,047,686!
UNCOV
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) {
31,562,427✔
176
      // todo
177
      pResult = getResultRowByPos(pResultBuf, p1, true);
8,711,747✔
178
      if (NULL == pResult) {
8,711,747!
179
        pTaskInfo->code = terrno;
×
180
        return NULL;
×
181
      }
182

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

191
  // 1. close current opened time window
192
  if (pResultRowInfo->cur.pageId != -1 && ((pResult == NULL) || (pResult->pageId != pResultRowInfo->cur.pageId))) {
300,360,760✔
193
    SResultRowPosition pos = pResultRowInfo->cur;
243,194,324✔
194
    SFilePage*         pPage = getBufPage(pResultBuf, pos.pageId);
243,194,324✔
195
    if (pPage == NULL) {
242,452,196!
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);
242,452,196✔
201
  }
202

203
  // allocate a new buffer page
204
  if (pResult == NULL) {
298,578,400✔
205
    pResult = getNewResultRow(pResultBuf, &pSup->currentPageId, pSup->resultRowSize);
242,199,569✔
206
    if (pResult == NULL) {
242,723,338!
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};
242,723,338✔
213
    int32_t code = tSimpleHashPut(pSup->pResultRowHashTable, pSup->keyBuf, GET_RES_WINDOW_KEY_LEN(bytes), &pos,
242,723,338✔
214
                                  sizeof(SResultRowPosition));
215
    if (code != TSDB_CODE_SUCCESS) {
246,081,380!
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};
302,529,063✔
224

225
  // too many time window in query
226
  if (pTaskInfo->execModel == OPTR_EXEC_MODEL_BATCH &&
604,445,717!
227
      tSimpleHashGetSize(pSup->pResultRowHashTable) > MAX_INTERVAL_TIME_WINDOW) {
302,467,723✔
228
    pTaskInfo->code = TSDB_CODE_QRY_TOO_MANY_TIMEWINDOW;
×
229
    return NULL;
×
230
  }
231

232
  return pResult;
301,977,994✔
233
}
234

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

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

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

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

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

274
int32_t setInputDataBlock(SExprSupp* pExprSup, SSDataBlock* pBlock, int32_t order, int32_t scanFlag,
29,675,966✔
275
                          bool createDummyCol) {
276
  if (pBlock->pBlockAgg != NULL) {
29,675,966✔
277
    return doSetInputDataBlockInfo(pExprSup, pBlock, order, scanFlag);
1,681,714✔
278
  } else {
279
    return doSetInputDataBlock(pExprSup, pBlock, order, scanFlag, createDummyCol);
27,994,252✔
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,994,318✔
335
                                   bool createDummyCol) {
336
  int32_t         code = TSDB_CODE_SUCCESS;
27,994,318✔
337
  int32_t         lino = 0;
27,994,318✔
338
  SqlFunctionCtx* pCtx = pExprSup->pCtx;
27,994,318✔
339

340
  for (int32_t i = 0; i < pExprSup->numOfExprs; ++i) {
108,817,247✔
341
    pCtx[i].order = order;
80,842,589✔
342
    pCtx[i].input.numOfRows = pBlock->info.rows;
80,842,589✔
343

344
    pCtx[i].pSrcBlock = pBlock;
80,842,589✔
345
    pCtx[i].scanFlag = scanFlag;
80,842,589✔
346

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

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

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

358
    for (int32_t j = 0; j < pOneExpr->base.numOfParams; ++j) {
169,698,257✔
359
      SFunctParam* pFuncParam = &pOneExpr->base.pParam[j];
88,875,328✔
360
      if (pFuncParam->type == FUNC_PARAM_TYPE_COLUMN) {
88,875,328✔
361
        int32_t slotId = pFuncParam->pCol->slotId;
80,028,277✔
362
        pInput->pData[j] = taosArrayGet(pBlock->pDataBlock, slotId);
80,028,277✔
363
        pInput->totalRows = pBlock->info.rows;
80,017,118✔
364
        pInput->numOfRows = pBlock->info.rows;
80,017,118✔
365
        pInput->startRowIndex = 0;
80,017,118✔
366
        pInput->blankFill = pBlock->info.blankFill;
80,017,118✔
367

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

371
        if (fmIsImplicitTsFunc(pCtx[i].functionId) && (j == tsParamIdx)) {
80,017,118✔
372
          pInput->pPTS = pInput->pData[j];  // in case of merge function, this is not always the ts column data.
11,353,617✔
373
        }
374
        if (hasPk && (j == pkParamIdx)) {
80,008,617✔
375
          pInput->pPrimaryKey = pInput->pData[j];
983,274✔
376
        }
377
        QUERY_CHECK_CONDITION((pInput->pData[j] != NULL), code, lino, _end, TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR);
80,008,617!
378
      } else if (pFuncParam->type == FUNC_PARAM_TYPE_VALUE) {
8,847,051✔
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,220,179!
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,974,658✔
395
  if (code != TSDB_CODE_SUCCESS) {
27,974,658!
396
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
×
397
  }
398
  return code;
27,995,021✔
399
}
400

401
bool functionNeedToExecute(SqlFunctionCtx* pCtx) {
1,011,840,761✔
402
  struct SResultRowEntryInfo* pResInfo = GET_RES_INFO(pCtx);
1,011,840,761✔
403

404
  // in case of timestamp column, always generated results.
405
  int32_t functionId = pCtx->functionId;
1,011,840,761✔
406
  if (functionId == -1) {
1,011,840,761✔
407
    return false;
60,984,902✔
408
  }
409

410
  if (pCtx->scanFlag == PRE_SCAN) {
950,855,859✔
411
    return fmIsRepeatScanFunc(pCtx->functionId);
1,080,077✔
412
  }
413

414
  if (isRowEntryCompleted(pResInfo)) {
949,775,782✔
415
    return false;
7,072✔
416
  }
417

418
  return true;
949,768,710✔
419
}
420

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

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

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

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

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

486
    for (int32_t j = 0; j < pExprInfo->base.numOfParams; ++j) {
4,725,216✔
487
      SFunctParam* pFuncParam = &pExprInfo->base.pParam[j];
3,043,494✔
488

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

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

515
/////////////////////////////////////////////////////////////////////////////////////////////
516
STimeWindow getAlignQueryTimeWindow(const SInterval* pInterval, int64_t key) {
29,966,752✔
517
  STimeWindow win = {0};
29,966,752✔
518
  win.skey = taosTimeTruncate(key, pInterval);
29,966,752✔
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);
29,965,238✔
525
  if (win.ekey < win.skey) {
29,963,949✔
526
    win.ekey = INT64_MAX;
2,143✔
527
  }
528

529
  return win;
29,963,949✔
530
}
531

532
int32_t setResultRowInitCtx(SResultRow* pResult, SqlFunctionCtx* pCtx, int32_t numOfOutput,
477,185,874✔
533
                            int32_t* rowEntryInfoOffset) {
534
  bool init = false;
477,185,874✔
535
  for (int32_t i = 0; i < numOfOutput; ++i) {
1,772,501,747✔
536
    pCtx[i].resultInfo = getResultEntryInfo(pResult, i, rowEntryInfoOffset);
1,297,128,358✔
537
    if (init) {
1,297,100,926✔
538
      continue;
120,749,370✔
539
    }
540

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

546
    if (pCtx[i].isPseudoFunc) {
1,176,351,556✔
547
      continue;
285,235,817✔
548
    }
549

550
    if (!pResInfo->initialized) {
891,115,739✔
551
      if (pCtx[i].functionId != -1) {
841,530,918✔
552
        int32_t code = pCtx[i].fpSet.init(&pCtx[i], pResInfo);
794,250,670✔
553
        if (code != TSDB_CODE_SUCCESS && fmIsUserDefinedFunc(pCtx[i].functionId)) {
794,432,438!
554
          pResInfo->initialized = false;
1,966,821✔
555
          qError("failed to initialize udf, funcId:%d error:%s", pCtx[i].functionId, tstrerror(code));
1,966,821!
556
          return TSDB_CODE_UDF_FUNC_EXEC_FAILURE;
44✔
557
        } else if (code != TSDB_CODE_SUCCESS) {
792,465,617!
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;
47,280,248✔
563
      }
564
    } else {
565
      init = true;
49,584,821✔
566
    }
567
  }
568
  return TSDB_CODE_SUCCESS;
475,373,389✔
569
}
570

571
void clearResultRowInitFlag(SqlFunctionCtx* pCtx, int32_t numOfOutput) {
91,813,319✔
572
  for (int32_t i = 0; i < numOfOutput; ++i) {
229,517,537✔
573
    SResultRowEntryInfo* pResInfo = pCtx[i].resultInfo;
137,704,218✔
574
    if (pResInfo == NULL) {
137,704,218!
575
      continue;
×
576
    }
577

578
    pResInfo->initialized = false;
137,704,218✔
579
    pResInfo->numOfRes = 0;
137,704,218✔
580
    pResInfo->isNullRes = 0;
137,704,218✔
581
    pResInfo->complete = false;
137,704,218✔
582
  }
583
}
91,813,319✔
584

585
int32_t doFilter(SSDataBlock* pBlock, SFilterInfo* pFilterInfo, SColMatchInfo* pColMatchInfo) {
42,334,569✔
586
  int32_t code = TSDB_CODE_SUCCESS;
42,334,569✔
587
  int32_t lino = 0;
42,334,569✔
588
  if (pFilterInfo == NULL || pBlock->info.rows == 0) {
42,334,569✔
589
    return TSDB_CODE_SUCCESS;
36,436,895✔
590
  }
591

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

595
  code = filterSetDataFromSlotId(pFilterInfo, &param1);
5,897,574✔
596
  QUERY_CHECK_CODE(code, lino, _err);
5,897,390!
597

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

602
  code = extractQualifiedTupleByFilterResult(pBlock, p, status);
5,897,552✔
603
  QUERY_CHECK_CODE(code, lino, _err);
5,897,421!
604

605
  if (pColMatchInfo != NULL) {
5,897,421✔
606
    size_t size = taosArrayGetSize(pColMatchInfo->pList);
4,885,329✔
607
    for (int32_t i = 0; i < size; ++i) {
4,890,683✔
608
      SColMatchItem* pInfo = taosArrayGet(pColMatchInfo->pList, i);
4,888,149✔
609
      QUERY_CHECK_NULL(pInfo, code, lino, _err, terrno);
4,888,137!
610
      if (pInfo->colId == PRIMARYKEY_TIMESTAMP_COL_ID) {
4,888,137✔
611
        SColumnInfoData* pColData = taosArrayGet(pBlock->pDataBlock, pInfo->dstSlotId);
4,882,983✔
612
        QUERY_CHECK_NULL(pColData, code, lino, _err, terrno);
4,882,885!
613
        if (pColData->info.type == TSDB_DATA_TYPE_TIMESTAMP) {
4,882,981✔
614
          code = blockDataUpdateTsWindow(pBlock, pInfo->dstSlotId);
4,882,908✔
615
          QUERY_CHECK_CODE(code, lino, _err);
4,882,935!
616
          break;
4,882,935✔
617
        }
618
      }
619
    }
620
  }
621
  code = blockDataCheck(pBlock);
5,897,561✔
622
  QUERY_CHECK_CODE(code, lino, _err);
5,897,269!
623
_err:
5,897,269✔
624
  if (code != TSDB_CODE_SUCCESS) {
5,897,270✔
625
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
1!
626
  }
627
  colDataDestroy(p);
5,897,270✔
628
  taosMemoryFree(p);
5,897,840✔
629
  return code;
5,898,130✔
630
}
631

632
int32_t extractQualifiedTupleByFilterResult(SSDataBlock* pBlock, const SColumnInfoData* p, int32_t status) {
5,897,545✔
633
  int32_t code = TSDB_CODE_SUCCESS;
5,897,545✔
634
  int8_t* pIndicator = (int8_t*)p->pData;
5,897,545✔
635
  if (status == FILTER_RESULT_ALL_QUALIFIED) {
5,897,545✔
636
    // here nothing needs to be done
637
  } else if (status == FILTER_RESULT_NONE_QUALIFIED) {
1,353,320✔
638
    code = trimDataBlock(pBlock, pBlock->info.rows, NULL);
540,160✔
639
    pBlock->info.rows = 0;
540,104✔
640
  } else if (status == FILTER_RESULT_PARTIAL_QUALIFIED) {
813,160!
641
    code = trimDataBlock(pBlock, pBlock->info.rows, (bool*)pIndicator);
813,243✔
642
  } else {
643
    qError("unknown filter result type: %d", status);
×
644
  }
645
  return code;
5,897,667✔
646
}
647

648
void doUpdateNumOfRows(SqlFunctionCtx* pCtx, SResultRow* pRow, int32_t numOfExprs, const int32_t* rowEntryOffset) {
422,208,028✔
649
  bool returnNotNull = false;
422,208,028✔
650
  for (int32_t j = 0; j < numOfExprs; ++j) {
1,510,849,635✔
651
    SResultRowEntryInfo* pResInfo = getResultEntryInfo(pRow, j, rowEntryOffset);
1,088,173,584✔
652
    if (!isRowEntryInitialized(pResInfo)) {
1,088,641,607✔
653
      continue;
234,192,140✔
654
    } else {
655
    }
656

657
    if (pRow->numOfRows < pResInfo->numOfRes) {
854,449,467✔
658
      pRow->numOfRows = pResInfo->numOfRes;
414,918,396✔
659
    }
660

661
    if (pCtx[j].isNotNullFunc) {
854,449,467✔
662
      returnNotNull = true;
235,854,383✔
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) {
422,676,051✔
668
    pRow->numOfRows = 1;
29,664✔
669
  }
670
}
422,676,051✔
671

672
int32_t copyResultrowToDataBlock(SExprInfo* pExprInfo, int32_t numOfExprs, SResultRow* pRow, SqlFunctionCtx* pCtx,
403,794,008✔
673
                                 SSDataBlock* pBlock, const int32_t* rowEntryOffset, SExecTaskInfo* pTaskInfo) {
674
  int32_t code = TSDB_CODE_SUCCESS;
403,794,008✔
675
  int32_t lino = 0;
403,794,008✔
676
  for (int32_t j = 0; j < numOfExprs; ++j) {
1,396,276,507✔
677
    int32_t slotId = pExprInfo[j].base.resSchema.slotId;
994,030,977✔
678

679
    pCtx[j].resultInfo = getResultEntryInfo(pRow, j, rowEntryOffset);
994,030,977✔
680
    if (pCtx[j].fpSet.finalize) {
994,323,076✔
681
      if (strcmp(pCtx[j].pExpr->pExpr->_function.functionName, "_group_key") == 0 ||
598,062,904✔
682
          strcmp(pCtx[j].pExpr->pExpr->_function.functionName, "_group_const_value") == 0) {
506,187,459✔
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) {
92,126,124!
686
          pCtx[j].resultInfo->numOfRes = pRow->numOfRows;
93,510,360✔
687
        }
688
      }
689

690
      code = blockDataEnsureCapacity(pBlock, pBlock->info.rows + pCtx[j].resultInfo->numOfRes);
598,062,904✔
691
      QUERY_CHECK_CODE(code, lino, _end);
598,044,329!
692

693
      code = pCtx[j].fpSet.finalize(&pCtx[j], pBlock);
598,044,329✔
694
      if (TSDB_CODE_SUCCESS != code) {
599,778,699!
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) {
396,260,172✔
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);
257,293,719✔
704
      QUERY_CHECK_NULL(pColInfoData, code, lino, _end, terrno);
256,546,820!
705
      char*            in = GET_ROWCELL_INTERBUF(pCtx[j].resultInfo);
256,622,831✔
706
      for (int32_t k = 0; k < pRow->numOfRows; ++k) {
530,631,828✔
707
        code = colDataSetValOrCover(pColInfoData, pBlock->info.rows + k, in, pCtx[j].resultInfo->isNullRes);
273,882,237✔
708
        QUERY_CHECK_CODE(code, lino, _end);
274,008,997!
709
      }
710
    }
711
  }
712

713
_end:
402,245,530✔
714
  if (code != TSDB_CODE_SUCCESS) {
402,245,530!
715
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
×
716
  }
717
  return code;
404,227,469✔
718
}
719

720
// todo refactor. SResultRow has direct pointer in miainfo
721
void finalizeResultRows(SDiskbasedBuf* pBuf, SResultRowPosition* resultRowPosition, SExprSupp* pSup,
71,361,121✔
722
                        SSDataBlock* pBlock, SExecTaskInfo* pTaskInfo) {
723
  SFilePage* page = getBufPage(pBuf, resultRowPosition->pageId);
71,361,121✔
724
  if (page == NULL) {
71,350,519!
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);
71,350,519✔
730

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

735
  doUpdateNumOfRows(pCtx, pRow, pSup->numOfExprs, rowEntryOffset);
71,350,519✔
736
  if (pRow->numOfRows == 0) {
71,338,614✔
737
    releaseBufPage(pBuf, page);
2,032✔
738
    return;
×
739
  }
740

741
  int32_t size = pBlock->info.capacity;
71,336,582✔
742
  while (pBlock->info.rows + pRow->numOfRows > size) {
71,434,713✔
743
    size = size * 1.25;
98,131✔
744
  }
745

746
  int32_t code = blockDataEnsureCapacity(pBlock, size);
71,336,582✔
747
  if (TAOS_FAILED(code)) {
71,340,826!
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);
71,340,826✔
754
  if (TAOS_FAILED(code)) {
71,313,633!
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);
71,313,633✔
761
  pBlock->info.rows += pRow->numOfRows;
71,290,569✔
762
}
763

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

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

776
  // begin from last iter
777
  void*   pData = pGroupResInfo->dataPos;
6,275,267✔
778
  int32_t iter = pGroupResInfo->iter;
6,275,267✔
779
  while ((pData = tSimpleHashIterate(pHashmap, pData, &iter)) != NULL) {
24,856,822✔
780
    void*               key = tSimpleHashGetKey(pData, &keyLen);
24,499,613✔
781
    SResultRowPosition* pos = pData;
24,499,613✔
782
    uint64_t            groupId = *(uint64_t*)key;
24,499,613✔
783

784
    SFilePage* page = getBufPage(pBuf, pos->pageId);
24,499,613✔
785
    if (page == NULL) {
24,496,361!
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,496,361✔
791

792
    doUpdateNumOfRows(pCtx, pRow, numOfExprs, rowEntryOffset);
24,496,361✔
793

794
    // no results, continue to check the next one
795
    if (pRow->numOfRows == 0) {
24,462,716!
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,462,716✔
805
      if (pBlock->info.id.groupId == 0) {
11,860,049✔
806
        pBlock->info.id.groupId = groupId;
5,977,112✔
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,882,937!
810
          releaseBufPage(pBuf, page);
5,907,498✔
811
          break;
5,906,296✔
812
        }
813
      }
814
    }
815

816
    if (pBlock->info.rows + pRow->numOfRows > pBlock->info.capacity) {
18,555,218!
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,555,218✔
826
    pGroupResInfo->iter = iter;
18,555,218✔
827
    pGroupResInfo->dataPos = pData;
18,555,218✔
828

829
    code = copyResultrowToDataBlock(pExprInfo, numOfExprs, pRow, pCtx, pBlock, rowEntryOffset, pTaskInfo);
18,555,218✔
830
    releaseBufPage(pBuf, page);
18,584,827✔
831
    QUERY_CHECK_CODE(code, lino, _end);
18,581,595!
832
    pBlock->info.rows += pRow->numOfRows;
18,581,595✔
833
    if (pBlock->info.rows >= threshold) {
18,581,595✔
834
      break;
40✔
835
    }
836
  }
837

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

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

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

860
  int32_t numOfRows = getNumOfTotalRes(pGroupResInfo);
3,040,366✔
861

862
  for (int32_t i = pGroupResInfo->index; i < numOfRows; i += 1) {
225,067,990✔
863
    SResKeyPos* pPos = taosArrayGetP(pGroupResInfo->pRows, i);
222,684,921✔
864
    SFilePage*  page = getBufPage(pBuf, pPos->pos.pageId);
222,712,136✔
865
    if (page == NULL) {
222,802,859!
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);
222,802,859✔
871

872
    doUpdateNumOfRows(pCtx, pRow, numOfExprs, rowEntryOffset);
222,802,859✔
873

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

881
    if (!ignoreGroup) {
221,699,725✔
882
      if (pBlock->info.id.groupId == 0) {
149,513,788✔
883
        pBlock->info.id.groupId = pPos->groupId;
132,061,528✔
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) {
17,452,260✔
887
          releaseBufPage(pBuf, page);
133,737✔
888
          break;
133,738✔
889
        }
890
      }
891
    }
892

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

902
    pGroupResInfo->index += 1;
221,565,988✔
903
    code = copyResultrowToDataBlock(pExprInfo, numOfExprs, pRow, pCtx, pBlock, rowEntryOffset, pTaskInfo);
221,565,988✔
904
    releaseBufPage(pBuf, page);
223,409,583✔
905
    QUERY_CHECK_CODE(code, lino, _end);
222,526,417!
906

907
    pBlock->info.rows += pRow->numOfRows;
222,526,417✔
908
    if (pBlock->info.rows >= threshold) {
222,526,417✔
909
      break;
499,871✔
910
    }
911
  }
912

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

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

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

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

934
  blockDataCleanup(pBlock);
4,049,635✔
935
  if (!hasRemainResults(pGroupResInfo)) {
4,050,315✔
936
    return;
1,009,149✔
937
  }
938

939
  // clear the existed group id
940
  pBlock->info.id.groupId = 0;
3,040,637✔
941
  if (!pbInfo->mergeResultBlock) {
3,040,637✔
942
    doCopyToSDataBlock(pTaskInfo, pBlock, &pOperator->exprSupp, pBuf, pGroupResInfo, pOperator->resultInfo.threshold,
1,846,476✔
943
                       false);
944
  } else {
945
    while (hasRemainResults(pGroupResInfo)) {
2,154,583✔
946
      doCopyToSDataBlock(pTaskInfo, pBlock, &pOperator->exprSupp, pBuf, pGroupResInfo, pOperator->resultInfo.threshold,
1,193,824✔
947
                         true);
948
      if (pBlock->info.rows >= pOperator->resultInfo.threshold) {
1,193,967✔
949
        break;
233,545✔
950
      }
951

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

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

961
void destroyExprInfo(SExprInfo* pExpr, int32_t numOfExprs) {
10,297,812✔
962
  for (int32_t i = 0; i < numOfExprs; ++i) {
40,967,040✔
963
    SExprInfo* pExprInfo = &pExpr[i];
30,668,485✔
964
    for (int32_t j = 0; j < pExprInfo->base.numOfParams; ++j) {
63,393,503✔
965
      if (pExprInfo->base.pParam[j].type == FUNC_PARAM_TYPE_COLUMN) {
32,748,587✔
966
        taosMemoryFreeClear(pExprInfo->base.pParam[j].pCol);
29,294,617!
967
      } else if (pExprInfo->base.pParam[j].type == FUNC_PARAM_TYPE_VALUE) {
3,453,970✔
968
        taosVariantDestroy(&pExprInfo->base.pParam[j].param);
2,644,549✔
969
      }
970
    }
971

972
    taosMemoryFree(pExprInfo->base.pParam);
30,644,916✔
973
    taosMemoryFree(pExprInfo->pExpr);
30,675,286✔
974
  }
975
}
10,298,555✔
976

977
int32_t getBufferPgSize(int32_t rowSize, uint32_t* defaultPgsz, uint32_t* defaultBufsz) {
6,625,108✔
978
  *defaultPgsz = 4096;
6,625,108✔
979
  uint32_t last = *defaultPgsz;
6,625,108✔
980
  while (*defaultPgsz < rowSize * 4) {
8,122,171✔
981
    *defaultPgsz <<= 1u;
1,497,063✔
982
    if (*defaultPgsz < last) {
1,497,063!
983
      return TSDB_CODE_INVALID_PARA;
×
984
    }
985
    last = *defaultPgsz;
1,497,063✔
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,625,108✔
992
  if ((*defaultBufsz) <= (*defaultPgsz)) {
6,625,108!
993
    (*defaultBufsz) = (*defaultPgsz) * 4;
×
994
    if (*defaultBufsz < ((int64_t)(*defaultPgsz)) * 4) {
×
995
      return TSDB_CODE_INVALID_PARA;
×
996
    }
997
  }
998

999
  return 0;
6,625,108✔
1000
}
1001

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

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

1010
  if (pResultInfo->threshold == 0) {
15,708,956✔
1011
    pResultInfo->threshold = numOfRows;
305,498✔
1012
  }
1013
}
15,708,956✔
1014

1015
void initBasicInfo(SOptrBasicInfo* pInfo, SSDataBlock* pBlock) {
6,608,070✔
1016
  pInfo->pRes = pBlock;
6,608,070✔
1017
  initResultRowInfo(&pInfo->resultRowInfo);
6,608,070✔
1018
}
6,607,734✔
1019

1020
static void destroySqlFunctionCtx(SqlFunctionCtx* pCtx, SExprInfo* pExpr, int32_t numOfOutput) {
30,513,089✔
1021
  if (pCtx == NULL) {
30,513,089✔
1022
    return;
19,337,624✔
1023
  }
1024

1025
  for (int32_t i = 0; i < numOfOutput; ++i) {
41,578,228✔
1026
    if (pExpr != NULL) {
30,395,938!
1027
      SExprInfo* pExprInfo = &pExpr[i];
30,398,830✔
1028
      for (int32_t j = 0; j < pExprInfo->base.numOfParams; ++j) {
62,870,912✔
1029
        if (pExprInfo->base.pParam[j].type == FUNC_PARAM_TYPE_VALUE) {
32,474,545✔
1030
          taosMemoryFree(pCtx[i].input.pData[j]);
2,640,393✔
1031
          taosMemoryFree(pCtx[i].input.pColumnDataAgg[j]);
2,640,336✔
1032
        }
1033
      }
1034
    }
1035
    for (int32_t j = 0; j < pCtx[i].numOfParams; ++j) {
62,859,179✔
1036
      taosVariantDestroy(&pCtx[i].param[j].param);
32,470,386✔
1037
    }
1038

1039
    taosMemoryFreeClear(pCtx[i].subsidiaries.pCtx);
30,388,793✔
1040
    taosMemoryFreeClear(pCtx[i].subsidiaries.buf);
30,388,909✔
1041
    taosMemoryFree(pCtx[i].input.pData);
30,388,917✔
1042
    taosMemoryFree(pCtx[i].input.pColumnDataAgg);
30,410,162✔
1043

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

1049
  taosMemoryFreeClear(pCtx);
11,182,290!
1050
  return;
11,182,189✔
1051
}
1052

1053
int32_t initExprSupp(SExprSupp* pSup, SExprInfo* pExprInfo, int32_t numOfExpr, SFunctionStateStore* pStore) {
10,319,609✔
1054
  pSup->pExprInfo = pExprInfo;
10,319,609✔
1055
  pSup->numOfExprs = numOfExpr;
10,319,609✔
1056
  if (pSup->pExprInfo != NULL) {
10,319,609✔
1057
    pSup->pCtx = createSqlFunctionCtx(pExprInfo, numOfExpr, &pSup->rowEntryInfoOffset, pStore);
8,233,684✔
1058
    if (pSup->pCtx == NULL) {
8,233,439!
1059
      return TSDB_CODE_OUT_OF_MEMORY;
×
1060
    }
1061
  }
1062

1063
  return TSDB_CODE_SUCCESS;
10,319,364✔
1064
}
1065

1066
void cleanupExprSupp(SExprSupp* pSupp) {
30,514,882✔
1067
  destroySqlFunctionCtx(pSupp->pCtx, pSupp->pExprInfo, pSupp->numOfExprs);
30,514,882✔
1068
  if (pSupp->pExprInfo != NULL) {
30,512,856✔
1069
    destroyExprInfo(pSupp->pExprInfo, pSupp->numOfExprs);
10,292,667✔
1070
    taosMemoryFreeClear(pSupp->pExprInfo);
10,292,567✔
1071
  }
1072

1073
  if (pSupp->pFilterInfo != NULL) {
30,513,220✔
1074
    filterFreeInfo(pSupp->pFilterInfo);
2,907,404✔
1075
    pSupp->pFilterInfo = NULL;
2,907,450✔
1076
  }
1077

1078
  taosMemoryFree(pSupp->rowEntryInfoOffset);
30,513,266✔
1079
}
30,496,607✔
1080

1081
void cleanupBasicInfo(SOptrBasicInfo* pInfo) {
6,635,590✔
1082
  blockDataDestroy(pInfo->pRes);
6,635,590✔
1083
  pInfo->pRes = NULL;
6,636,082✔
1084
}
6,636,082✔
1085

1086
bool groupbyTbname(SNodeList* pGroupList) {
4,821,228✔
1087
  bool bytbname = false;
4,821,228✔
1088
  SNode*pNode = NULL;
4,821,228✔
1089
  FOREACH(pNode, pGroupList) {
4,919,645✔
1090
    if (pNode->type == QUERY_NODE_FUNCTION) {
419,062✔
1091
      bytbname = (strcmp(((struct SFunctionNode*)pNode)->functionName, "tbname") == 0);
320,645✔
1092
      break;
320,645✔
1093
    }
1094
  }
1095
  return bytbname;
4,821,228✔
1096
}
1097

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

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

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

1123
      STableListInfo* pTableListInfo = taosArrayGetP(pInfoList, 0);
60,032✔
1124
      taosArrayDestroy(pInfoList);
60,025✔
1125

1126
      pDeleterParam->suid = tableListGetSuid(pTableListInfo);
60,032✔
1127

1128
      // TODO extract uid list
1129
      int32_t numOfTables = 0;
60,024✔
1130
      code = tableListGetSize(pTableListInfo, &numOfTables);
60,024✔
1131
      if (code != TSDB_CODE_SUCCESS) {
60,026!
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));
60,026✔
1138
      if (NULL == pDeleterParam->pUidList) {
60,030!
1139
        taosMemoryFree(pDeleterParam);
×
1140
        return terrno;
×
1141
      }
1142

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

1158
      *pParam = pDeleterParam;
60,033✔
1159
      break;
60,033✔
1160
    }
1161
    default:
8,341,310✔
1162
      break;
8,341,310✔
1163
  }
1164

1165
  return TSDB_CODE_SUCCESS;
8,401,512✔
1166
}
1167

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

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

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

1189
  taosArrayDestroy(pParam->pChildren);
105,871✔
1190

1191
  taosMemoryFree(pParam->value);
105,871✔
1192

1193
  taosMemoryFree(pParam);
105,871✔
1194
}
105,871✔
1195

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

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

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

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

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

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

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

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

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

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

1231
void freeOperatorParam(SOperatorParam* pParam, SOperatorParamType type) {
5,692,443✔
1232
  if (NULL == pParam) {
5,692,443✔
1233
    return;
5,586,635✔
1234
  }
1235

1236
  switch (pParam->opType) {
105,808!
1237
    case QUERY_NODE_PHYSICAL_PLAN_EXCHANGE:
562✔
1238
      type == OP_GET_PARAM ? freeExchangeGetOperatorParam(pParam) : freeExchangeNotifyOperatorParam(pParam);
562!
1239
      break;
562✔
1240
    case QUERY_NODE_PHYSICAL_PLAN_GROUP_CACHE:
68,922✔
1241
      type == OP_GET_PARAM ? freeGroupCacheGetOperatorParam(pParam) : freeGroupCacheNotifyOperatorParam(pParam);
68,922!
1242
      break;
68,922✔
1243
    case QUERY_NODE_PHYSICAL_PLAN_MERGE_JOIN:
34,461✔
1244
      type == OP_GET_PARAM ? freeMergeJoinGetOperatorParam(pParam) : freeMergeJoinNotifyOperatorParam(pParam);
34,461!
1245
      break;
34,461✔
1246
    case QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN:
1,925✔
1247
      type == OP_GET_PARAM ? freeTableScanGetOperatorParam(pParam) : freeTableScanNotifyOperatorParam(pParam);
1,925!
1248
      break;
1,926✔
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) {
39,245,815✔
1256
  SOperatorParam**  ppParam = NULL;
39,245,815✔
1257
  SOperatorParam*** pppDownstramParam = NULL;
39,245,815✔
1258
  switch (type) {
39,245,815!
1259
    case OP_GET_PARAM:
19,654,136✔
1260
      ppParam = &pOperator->pOperatorGetParam;
19,654,136✔
1261
      pppDownstramParam = &pOperator->pDownstreamGetParams;
19,654,136✔
1262
      break;
19,654,136✔
1263
    case OP_NOTIFY_PARAM:
19,615,919✔
1264
      ppParam = &pOperator->pOperatorNotifyParam;
19,615,919✔
1265
      pppDownstramParam = &pOperator->pDownstreamNotifyParams;
19,615,919✔
1266
      break;
19,615,919✔
1267
    default:
×
1268
      return;
×
1269
  }
1270

1271
  if (*ppParam) {
39,270,055✔
1272
    freeOperatorParam(*ppParam, type);
34,461✔
1273
    *ppParam = NULL;
34,461✔
1274
  }
1275

1276
  if (*pppDownstramParam) {
39,270,055✔
1277
    for (int32_t i = 0; i < pOperator->numOfDownstream; ++i) {
104,909✔
1278
      if ((*pppDownstramParam)[i]) {
68,922!
1279
        freeOperatorParam((*pppDownstramParam)[i], type);
×
1280
        (*pppDownstramParam)[i] = NULL;
×
1281
      }
1282
    }
1283
    if (allFree) {
35,987✔
1284
      taosMemoryFreeClear(*pppDownstramParam);
1,748!
1285
    }
1286
  }
1287
}
1288

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

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

1303
    if (code) {
103,582!
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,582✔
1307
  }
1308

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

1316
bool compareVal(const char* v, const SStateKeys* pKey) {
21,967,322✔
1317
  if (IS_VAR_DATA_TYPE(pKey->type)) {
21,967,322!
1318
    if (varDataLen(v) != varDataLen(pKey->pData)) {
3,677!
1319
      return false;
×
1320
    } else {
1321
      return memcmp(varDataVal(v), varDataVal(pKey->pData), varDataLen(v)) == 0;
3,677✔
1322
    }
1323
  } else {
1324
    return memcmp(pKey->pData, v, pKey->bytes) == 0;
21,963,645✔
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