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

taosdata / TDengine / #3543

29 Nov 2024 02:58AM UTC coverage: 60.842% (+0.02%) from 60.819%
#3543

push

travis-ci

web-flow
Merge pull request #28973 from taosdata/merge/mainto3.0

merge: from main to 3.0

120460 of 253224 branches covered (47.57%)

Branch coverage included in aggregate %.

706 of 908 new or added lines in 18 files covered. (77.75%)

2401 existing lines in 137 files now uncovered.

201633 of 276172 relevant lines covered (73.01%)

19045673.23 hits per line

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

68.73
/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) {
241,257,295✔
86
  SFilePage* pData = NULL;
241,257,295✔
87

88
  // in the first scan, new space needed for results
89
  int32_t pageId = -1;
241,257,295✔
90
  if (*currentPageId == -1) {
241,257,295✔
91
    pData = getNewBufPage(pResultBuf, &pageId);
5,104,843✔
92
    if (pData == NULL) {
5,104,637✔
93
      qError("failed to get buffer, code:%s", tstrerror(terrno));
231!
94
      return NULL;
×
95
    }
96
    pData->num = sizeof(SFilePage);
5,104,406✔
97
  } else {
98
    pData = getBufPage(pResultBuf, *currentPageId);
236,152,452✔
99
    if (pData == NULL) {
236,468,818!
100
      qError("failed to get buffer, code:%s", tstrerror(terrno));
×
101
      return NULL;
×
102
    }
103

104
    pageId = *currentPageId;
236,468,818✔
105

106
    if (pData->num + interBufSize > getBufPageSize(pResultBuf)) {
236,468,818✔
107
      // release current page first, and prepare the next one
108
      releaseBufPage(pResultBuf, pData);
16,801,066✔
109

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

119
  if (pData == NULL) {
241,715,191!
120
    return NULL;
×
121
  }
122

123
  setBufPageDirty(pData, true);
241,715,191✔
124

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

128
  memset((char*)pResultRow, 0, interBufSize);
241,224,532✔
129
  pResultRow->pageId = pageId;
241,224,532✔
130
  pResultRow->offset = (int32_t)pData->num;
241,224,532✔
131

132
  *currentPageId = pageId;
241,224,532✔
133
  pData->num += interBufSize;
241,224,532✔
134
  return pResultRow;
241,224,532✔
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,
299,749,217✔
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);
299,749,217✔
148
  if (!keepGroup) {
299,749,217✔
149
    *(uint64_t*)pSup->keyBuf = calcGroupId(pSup->keyBuf, GET_RES_WINDOW_KEY_LEN(bytes));
27,003,755✔
150
  }
151

152
  SResultRowPosition* p1 =
153
      (SResultRowPosition*)tSimpleHashGet(pSup->pResultRowHashTable, pSup->keyBuf, GET_RES_WINDOW_KEY_LEN(bytes));
300,030,241✔
154

155
  SResultRow* pResult = NULL;
298,946,721✔
156

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

166
      if (pResult->pageId != p1->pageId || pResult->offset != p1->offset) {
48,946,987!
167
        terrno = TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR;
5,711✔
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,587,267✔
176
      // todo
177
      pResult = getResultRowByPos(pResultBuf, p1, true);
8,654,474✔
178
      if (NULL == pResult) {
8,654,474!
179
        pTaskInfo->code = terrno;
×
180
        return NULL;
×
181
      }
182

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

191
  // 1. close current opened time window
192
  if (pResultRowInfo->cur.pageId != -1 && ((pResult == NULL) || (pResult->pageId != pResultRowInfo->cur.pageId))) {
298,765,881✔
193
    SResultRowPosition pos = pResultRowInfo->cur;
240,459,355✔
194
    SFilePage*         pPage = getBufPage(pResultBuf, pos.pageId);
240,459,355✔
195
    if (pPage == NULL) {
240,662,544!
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);
240,662,544✔
201
  }
202

203
  // allocate a new buffer page
204
  if (pResult == NULL) {
298,181,414✔
205
    pResult = getNewResultRow(pResultBuf, &pSup->currentPageId, pSup->resultRowSize);
240,911,677✔
206
    if (pResult == NULL) {
241,545,105!
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};
241,545,105✔
213
    int32_t code = tSimpleHashPut(pSup->pResultRowHashTable, pSup->keyBuf, GET_RES_WINDOW_KEY_LEN(bytes), &pos,
241,545,105✔
214
                                  sizeof(SResultRowPosition));
215
    if (code != TSDB_CODE_SUCCESS) {
243,650,899!
UNCOV
216
      qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(code));
×
217
      pTaskInfo->code = code;
×
218
      return NULL;
×
219
    }
220
  }
221

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

225
  // too many time window in query
226
  if (pTaskInfo->execModel == OPTR_EXEC_MODEL_BATCH &&
601,315,022!
227
      tSimpleHashGetSize(pSup->pResultRowHashTable) > MAX_INTERVAL_TIME_WINDOW) {
300,985,533✔
228
    pTaskInfo->code = TSDB_CODE_QRY_TOO_MANY_TIMEWINDOW;
×
229
    return NULL;
×
230
  }
231

232
  return pResult;
300,329,489✔
233
}
234

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

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

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

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

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

274
int32_t setInputDataBlock(SExprSupp* pExprSup, SSDataBlock* pBlock, int32_t order, int32_t scanFlag,
31,271,864✔
275
                          bool createDummyCol) {
276
  if (pBlock->pBlockAgg != NULL) {
31,271,864✔
277
    return doSetInputDataBlockInfo(pExprSup, pBlock, order, scanFlag);
2,280,521✔
278
  } else {
279
    return doSetInputDataBlock(pExprSup, pBlock, order, scanFlag, createDummyCol);
28,991,343✔
280
  }
281
}
282

283
static int32_t doCreateConstantValColumnInfo(SInputColumnInfoData* pInput, SFunctParam* pFuncParam, int32_t paramIndex,
×
284
                                             int32_t numOfRows) {
285
  int32_t          code = TSDB_CODE_SUCCESS;
×
286
  int32_t          lino = 0;
×
287
  SColumnInfoData* pColInfo = NULL;
×
288
  if (pInput->pData[paramIndex] == NULL) {
×
289
    pColInfo = taosMemoryCalloc(1, sizeof(SColumnInfoData));
×
290
    QUERY_CHECK_NULL(pColInfo, code, lino, _end, terrno);
×
291

292
    // Set the correct column info (data type and bytes)
293
    pColInfo->info.type = pFuncParam->param.nType;
×
294
    pColInfo->info.bytes = pFuncParam->param.nLen;
×
295

296
    pInput->pData[paramIndex] = pColInfo;
×
297
  } else {
298
    pColInfo = pInput->pData[paramIndex];
×
299
  }
300

301
  code = colInfoDataEnsureCapacity(pColInfo, numOfRows, false);
×
302
  QUERY_CHECK_CODE(code, lino, _end);
×
303

304
  int8_t type = pFuncParam->param.nType;
×
305
  if (type == TSDB_DATA_TYPE_BIGINT || type == TSDB_DATA_TYPE_UBIGINT) {
×
306
    int64_t v = pFuncParam->param.i;
×
307
    for (int32_t i = 0; i < numOfRows; ++i) {
×
308
      colDataSetInt64(pColInfo, i, &v);
×
309
    }
310
  } else if (type == TSDB_DATA_TYPE_DOUBLE) {
×
311
    double v = pFuncParam->param.d;
×
312
    for (int32_t i = 0; i < numOfRows; ++i) {
×
313
      colDataSetDouble(pColInfo, i, &v);
×
314
    }
315
  } else if (type == TSDB_DATA_TYPE_VARCHAR || type == TSDB_DATA_TYPE_GEOMETRY) {
×
316
    char* tmp = taosMemoryMalloc(pFuncParam->param.nLen + VARSTR_HEADER_SIZE);
×
317
    QUERY_CHECK_NULL(tmp, code, lino, _end, terrno);
×
318

319
    STR_WITH_SIZE_TO_VARSTR(tmp, pFuncParam->param.pz, pFuncParam->param.nLen);
×
320
    for (int32_t i = 0; i < numOfRows; ++i) {
×
321
      code = colDataSetVal(pColInfo, i, tmp, false);
×
322
      QUERY_CHECK_CODE(code, lino, _end);
×
323
    }
324
    taosMemoryFree(tmp);
×
325
  }
326

327
_end:
×
328
  if (code != TSDB_CODE_SUCCESS) {
×
329
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
×
330
  }
331
  return code;
×
332
}
333

334
static int32_t doSetInputDataBlock(SExprSupp* pExprSup, SSDataBlock* pBlock, int32_t order, int32_t scanFlag,
28,991,439✔
335
                                   bool createDummyCol) {
336
  int32_t         code = TSDB_CODE_SUCCESS;
28,991,439✔
337
  int32_t         lino = 0;
28,991,439✔
338
  SqlFunctionCtx* pCtx = pExprSup->pCtx;
28,991,439✔
339

340
  for (int32_t i = 0; i < pExprSup->numOfExprs; ++i) {
101,869,940✔
341
    pCtx[i].order = order;
72,881,301✔
342
    pCtx[i].input.numOfRows = pBlock->info.rows;
72,881,301✔
343

344
    pCtx[i].pSrcBlock = pBlock;
72,881,301✔
345
    pCtx[i].scanFlag = scanFlag;
72,881,301✔
346

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

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

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

358
    for (int32_t j = 0; j < pOneExpr->base.numOfParams; ++j) {
153,372,139✔
359
      SFunctParam* pFuncParam = &pOneExpr->base.pParam[j];
80,493,638✔
360
      if (pFuncParam->type == FUNC_PARAM_TYPE_COLUMN) {
80,493,638✔
361
        int32_t slotId = pFuncParam->pCol->slotId;
70,798,641✔
362
        pInput->pData[j] = taosArrayGet(pBlock->pDataBlock, slotId);
70,798,641✔
363
        pInput->totalRows = pBlock->info.rows;
70,791,703✔
364
        pInput->numOfRows = pBlock->info.rows;
70,791,703✔
365
        pInput->startRowIndex = 0;
70,791,703✔
366
        pInput->blankFill = pBlock->info.blankFill;
70,791,703✔
367

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

371
        if (fmIsImplicitTsFunc(pCtx[i].functionId) && (j == tsParamIdx)) {
70,791,703✔
372
          pInput->pPTS = pInput->pData[j];  // in case of merge function, this is not always the ts column data.
9,162,787✔
373
        }
374
        if (hasPk && (j == pkParamIdx)) {
70,795,841✔
375
          pInput->pPrimaryKey = pInput->pData[j];
792,031✔
376
        }
377
        QUERY_CHECK_CONDITION((pInput->pData[j] != NULL), code, lino, _end, TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR);
70,795,841!
378
      } else if (pFuncParam->type == FUNC_PARAM_TYPE_VALUE) {
9,694,997✔
379
        // todo avoid case: top(k, 12), 12 is the value parameter.
380
        // sum(11), 11 is also the value parameter.
381
        if (createDummyCol && pOneExpr->base.numOfParams == 1) {
8,090,292!
382
          pInput->totalRows = pBlock->info.rows;
×
383
          pInput->numOfRows = pBlock->info.rows;
×
384
          pInput->startRowIndex = 0;
×
385
          pInput->blankFill = pBlock->info.blankFill;
×
386

387
          code = doCreateConstantValColumnInfo(pInput, pFuncParam, j, pBlock->info.rows);
×
388
          QUERY_CHECK_CODE(code, lino, _end);
×
389
        }
390
      }
391
    }
392
  }
393

394
_end:
28,988,639✔
395
  if (code != TSDB_CODE_SUCCESS) {
28,988,639!
396
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
×
397
  }
398
  return code;
28,994,195✔
399
}
400

401
bool functionNeedToExecute(SqlFunctionCtx* pCtx) {
1,006,702,765✔
402
  struct SResultRowEntryInfo* pResInfo = GET_RES_INFO(pCtx);
1,006,702,765✔
403

404
  // in case of timestamp column, always generated results.
405
  int32_t functionId = pCtx->functionId;
1,006,702,765✔
406
  if (functionId == -1) {
1,006,702,765✔
407
    return false;
61,526,806✔
408
  }
409

410
  if (pCtx->scanFlag == PRE_SCAN) {
945,175,959✔
411
    return fmIsRepeatScanFunc(pCtx->functionId);
1,463,524✔
412
  }
413

414
  if (isRowEntryCompleted(pResInfo)) {
943,712,435✔
415
    return false;
5,547✔
416
  }
417

418
  return true;
943,706,888✔
419
}
420

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

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

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

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

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

486
    for (int32_t j = 0; j < pExprInfo->base.numOfParams; ++j) {
6,417,092✔
487
      SFunctParam* pFuncParam = &pExprInfo->base.pParam[j];
4,136,563✔
488

489
      if (pFuncParam->type == FUNC_PARAM_TYPE_COLUMN) {
4,136,563✔
490
        int32_t slotId = pFuncParam->pCol->slotId;
2,280,529✔
491
        pInput->pColumnDataAgg[j] = &pBlock->pBlockAgg[slotId];
2,280,529✔
492
        if (pInput->pColumnDataAgg[j]->colId == -1) {
2,280,529✔
493
          pInput->colDataSMAIsSet = false;
2,105✔
494
        }
495

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

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

515
/////////////////////////////////////////////////////////////////////////////////////////////
516
STimeWindow getAlignQueryTimeWindow(const SInterval* pInterval, int64_t key) {
22,024,961✔
517
  STimeWindow win = {0};
22,024,961✔
518
  win.skey = taosTimeTruncate(key, pInterval);
22,024,961✔
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);
22,024,880✔
525
  if (win.ekey < win.skey) {
22,024,857✔
526
    win.ekey = INT64_MAX;
2,082✔
527
  }
528

529
  return win;
22,024,857✔
530
}
531

532
int32_t setResultRowInitCtx(SResultRow* pResult, SqlFunctionCtx* pCtx, int32_t numOfOutput,
469,191,771✔
533
                            int32_t* rowEntryInfoOffset) {
534
  bool init = false;
469,191,771✔
535
  for (int32_t i = 0; i < numOfOutput; ++i) {
1,756,260,377✔
536
    pCtx[i].resultInfo = getResultEntryInfo(pResult, i, rowEntryInfoOffset);
1,288,692,023✔
537
    if (init) {
1,288,642,532✔
538
      continue;
123,834,776✔
539
    }
540

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

546
    if (pCtx[i].isPseudoFunc) {
1,164,807,756✔
547
      continue;
281,254,254✔
548
    }
549

550
    if (!pResInfo->initialized) {
883,553,502✔
551
      if (pCtx[i].functionId != -1) {
833,400,992✔
552
        int32_t code = pCtx[i].fpSet.init(&pCtx[i], pResInfo);
785,601,977✔
553
        if (code != TSDB_CODE_SUCCESS && fmIsUserDefinedFunc(pCtx[i].functionId)) {
785,874,151!
554
          pResInfo->initialized = false;
1,846,100✔
555
          qError("failed to initialize udf, funcId:%d error:%s", pCtx[i].functionId, tstrerror(code));
1,846,100!
556
          return TSDB_CODE_UDF_FUNC_EXEC_FAILURE;
44✔
557
        } else if (code != TSDB_CODE_SUCCESS) {
784,028,051!
UNCOV
558
          qError("failed to initialize function context, funcId:%d error:%s", pCtx[i].functionId, tstrerror(code));
×
UNCOV
559
          return code;
×
560
        }
561
      } else {
562
        pResInfo->initialized = true;
47,799,015✔
563
      }
564
    } else {
565
      init = true;
50,152,510✔
566
    }
567
  }
568
  return TSDB_CODE_SUCCESS;
467,568,354✔
569
}
570

571
void clearResultRowInitFlag(SqlFunctionCtx* pCtx, int32_t numOfOutput) {
87,604,426✔
572
  for (int32_t i = 0; i < numOfOutput; ++i) {
219,771,948✔
573
    SResultRowEntryInfo* pResInfo = pCtx[i].resultInfo;
132,167,522✔
574
    if (pResInfo == NULL) {
132,167,522!
UNCOV
575
      continue;
×
576
    }
577

578
    pResInfo->initialized = false;
132,167,522✔
579
    pResInfo->numOfRes = 0;
132,167,522✔
580
    pResInfo->isNullRes = 0;
132,167,522✔
581
    pResInfo->complete = false;
132,167,522✔
582
  }
583
}
87,604,426✔
584

585
int32_t doFilter(SSDataBlock* pBlock, SFilterInfo* pFilterInfo, SColMatchInfo* pColMatchInfo) {
43,426,612✔
586
  int32_t code = TSDB_CODE_SUCCESS;
43,426,612✔
587
  int32_t lino = 0;
43,426,612✔
588
  if (pFilterInfo == NULL || pBlock->info.rows == 0) {
43,426,612✔
589
    return TSDB_CODE_SUCCESS;
37,875,319✔
590
  }
591

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

595
  code = filterSetDataFromSlotId(pFilterInfo, &param1);
5,551,178✔
596
  QUERY_CHECK_CODE(code, lino, _err);
5,550,912!
597

598
  int32_t status = 0;
5,550,912✔
599
  code = filterExecute(pFilterInfo, pBlock, &p, NULL, param1.numOfCols, &status);
5,550,912✔
600
  QUERY_CHECK_CODE(code, lino, _err);
5,551,242✔
601

602
  code = extractQualifiedTupleByFilterResult(pBlock, p, status);
5,551,241✔
603
  QUERY_CHECK_CODE(code, lino, _err);
5,551,228!
604

605
  if (pColMatchInfo != NULL) {
5,551,228✔
606
    size_t size = taosArrayGetSize(pColMatchInfo->pList);
4,495,005✔
607
    for (int32_t i = 0; i < size; ++i) {
4,500,141✔
608
      SColMatchItem* pInfo = taosArrayGet(pColMatchInfo->pList, i);
4,497,712✔
609
      QUERY_CHECK_NULL(pInfo, code, lino, _err, terrno);
4,497,591!
610
      if (pInfo->colId == PRIMARYKEY_TIMESTAMP_COL_ID) {
4,497,591✔
611
        SColumnInfoData* pColData = taosArrayGet(pBlock->pDataBlock, pInfo->dstSlotId);
4,492,443✔
612
        QUERY_CHECK_NULL(pColData, code, lino, _err, terrno);
4,492,244!
613
        if (pColData->info.type == TSDB_DATA_TYPE_TIMESTAMP) {
4,492,310✔
614
          code = blockDataUpdateTsWindow(pBlock, pInfo->dstSlotId);
4,492,253✔
615
          QUERY_CHECK_CODE(code, lino, _err);
4,492,362!
616
          break;
4,492,362✔
617
        }
618
      }
619
    }
620
  }
621
  code = blockDataCheck(pBlock);
5,551,014✔
622
  QUERY_CHECK_CODE(code, lino, _err);
5,550,798!
623
_err:
5,550,798✔
624
  if (code != TSDB_CODE_SUCCESS) {
5,550,799✔
625
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
1!
626
  }
627
  colDataDestroy(p);
5,550,799✔
628
  taosMemoryFree(p);
5,551,468✔
629
  return code;
5,551,831✔
630
}
631

632
int32_t extractQualifiedTupleByFilterResult(SSDataBlock* pBlock, const SColumnInfoData* p, int32_t status) {
5,551,298✔
633
  int32_t code = TSDB_CODE_SUCCESS;
5,551,298✔
634
  int8_t* pIndicator = (int8_t*)p->pData;
5,551,298✔
635
  if (status == FILTER_RESULT_ALL_QUALIFIED) {
5,551,298✔
636
    // here nothing needs to be done
637
  } else if (status == FILTER_RESULT_NONE_QUALIFIED) {
1,456,389✔
638
    code = trimDataBlock(pBlock, pBlock->info.rows, NULL);
657,516✔
639
    pBlock->info.rows = 0;
657,471✔
640
  } else if (status == FILTER_RESULT_PARTIAL_QUALIFIED) {
798,873!
641
    code = trimDataBlock(pBlock, pBlock->info.rows, (bool*)pIndicator);
798,946✔
642
  } else {
UNCOV
643
    qError("unknown filter result type: %d", status);
×
644
  }
645
  return code;
5,551,442✔
646
}
647

648
void doUpdateNumOfRows(SqlFunctionCtx* pCtx, SResultRow* pRow, int32_t numOfExprs, const int32_t* rowEntryOffset) {
414,548,208✔
649
  bool returnNotNull = false;
414,548,208✔
650
  for (int32_t j = 0; j < numOfExprs; ++j) {
1,497,440,532✔
651
    SResultRowEntryInfo* pResInfo = getResultEntryInfo(pRow, j, rowEntryOffset);
1,082,641,889✔
652
    if (!isRowEntryInitialized(pResInfo)) {
1,082,892,324✔
653
      continue;
232,938,648✔
654
    } else {
655
    }
656

657
    if (pRow->numOfRows < pResInfo->numOfRes) {
849,953,676✔
658
      pRow->numOfRows = pResInfo->numOfRes;
407,065,679✔
659
    }
660

661
    if (pCtx[j].isNotNullFunc) {
849,953,676✔
662
      returnNotNull = true;
245,963,219✔
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) {
414,798,643✔
668
    pRow->numOfRows = 1;
27,545✔
669
  }
670
}
414,798,643✔
671

672
int32_t copyResultrowToDataBlock(SExprInfo* pExprInfo, int32_t numOfExprs, SResultRow* pRow, SqlFunctionCtx* pCtx,
394,205,550✔
673
                                 SSDataBlock* pBlock, const int32_t* rowEntryOffset, SExecTaskInfo* pTaskInfo) {
674
  int32_t code = TSDB_CODE_SUCCESS;
394,205,550✔
675
  int32_t lino = 0;
394,205,550✔
676
  for (int32_t j = 0; j < numOfExprs; ++j) {
1,376,304,676✔
677
    int32_t slotId = pExprInfo[j].base.resSchema.slotId;
984,129,503✔
678

679
    pCtx[j].resultInfo = getResultEntryInfo(pRow, j, rowEntryOffset);
984,129,503✔
680
    if (pCtx[j].fpSet.finalize) {
984,360,975✔
681
      if (strcmp(pCtx[j].pExpr->pExpr->_function.functionName, "_group_key") == 0 ||
587,726,176✔
682
          strcmp(pCtx[j].pExpr->pExpr->_function.functionName, "_group_const_value") == 0) {
494,823,949✔
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) {
93,152,928!
686
          pCtx[j].resultInfo->numOfRes = pRow->numOfRows;
94,393,856✔
687
        }
688
      }
689

690
      code = blockDataEnsureCapacity(pBlock, pBlock->info.rows + pCtx[j].resultInfo->numOfRes);
587,726,176✔
691
      QUERY_CHECK_CODE(code, lino, _end);
587,573,892!
692

693
      code = pCtx[j].fpSet.finalize(&pCtx[j], pBlock);
587,573,892✔
694
      if (TSDB_CODE_SUCCESS != code) {
589,932,606!
UNCOV
695
        qError("%s build result data block error, code %s", GET_TASKID(pTaskInfo), tstrerror(code));
×
UNCOV
696
        QUERY_CHECK_CODE(code, lino, _end);
×
697
      }
698
    } else if (strcmp(pCtx[j].pExpr->pExpr->_function.functionName, "_select_value") == 0) {
396,634,799✔
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);
254,851,430✔
704
      QUERY_CHECK_NULL(pColInfoData, code, lino, _end, terrno);
253,631,574!
705
      char*            in = GET_ROWCELL_INTERBUF(pCtx[j].resultInfo);
253,685,892✔
706
      for (int32_t k = 0; k < pRow->numOfRows; ++k) {
518,134,746✔
707
        code = colDataSetValOrCover(pColInfoData, pBlock->info.rows + k, in, pCtx[j].resultInfo->isNullRes);
264,246,986✔
708
        QUERY_CHECK_CODE(code, lino, _end);
264,448,854!
709
      }
710
    }
711
  }
712

713
_end:
392,175,173✔
714
  if (code != TSDB_CODE_SUCCESS) {
392,175,173!
UNCOV
715
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
×
716
  }
717
  return code;
394,510,998✔
718
}
719

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

729
  SResultRow* pRow = (SResultRow*)((char*)page + resultRowPosition->offset);
68,157,324✔
730

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

735
  doUpdateNumOfRows(pCtx, pRow, pSup->numOfExprs, rowEntryOffset);
68,157,324✔
736
  if (pRow->numOfRows == 0) {
68,152,494✔
737
    releaseBufPage(pBuf, page);
3,092✔
UNCOV
738
    return;
×
739
  }
740

741
  int32_t size = pBlock->info.capacity;
68,149,402✔
742
  while (pBlock->info.rows + pRow->numOfRows > size) {
68,214,529✔
743
    size = size * 1.25;
65,127✔
744
  }
745

746
  int32_t code = blockDataEnsureCapacity(pBlock, size);
68,149,402✔
747
  if (TAOS_FAILED(code)) {
68,150,117!
748
    releaseBufPage(pBuf, page);
×
UNCOV
749
    qError("%s ensure result data capacity failed, code %s", GET_TASKID(pTaskInfo), tstrerror(code));
×
UNCOV
750
    T_LONG_JMP(pTaskInfo->env, code);
×
751
  }
752

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

760
  releaseBufPage(pBuf, page);
68,105,729✔
761
  pBlock->info.rows += pRow->numOfRows;
68,099,267✔
762
}
763

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

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

776
  // begin from last iter
777
  void*   pData = pGroupResInfo->dataPos;
6,265,552✔
778
  int32_t iter = pGroupResInfo->iter;
6,265,552✔
779
  while ((pData = tSimpleHashIterate(pHashmap, pData, &iter)) != NULL) {
24,945,813✔
780
    void*               key = tSimpleHashGetKey(pData, &keyLen);
24,597,126✔
781
    SResultRowPosition* pos = pData;
24,597,126✔
782
    uint64_t            groupId = *(uint64_t*)key;
24,597,126✔
783

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

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

792
    doUpdateNumOfRows(pCtx, pRow, numOfExprs, rowEntryOffset);
24,593,592✔
793

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

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

804
    if (!ignoreGroup) {
24,558,700✔
805
      if (pBlock->info.id.groupId == 0) {
11,849,141✔
806
        pBlock->info.id.groupId = groupId;
5,970,016✔
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,879,125!
810
          releaseBufPage(pBuf, page);
5,901,141✔
811
          break;
5,900,728✔
812
        }
813
      }
814
    }
815

816
    if (pBlock->info.rows + pRow->numOfRows > pBlock->info.capacity) {
18,657,559!
817
      uint32_t newSize = pBlock->info.rows + pRow->numOfRows + ((numOfRows - iter) > 1 ? 1 : 0);
×
818
      code = blockDataEnsureCapacity(pBlock, newSize);
×
UNCOV
819
      QUERY_CHECK_CODE(code, lino, _end);
×
UNCOV
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,657,559✔
826
    pGroupResInfo->iter = iter;
18,657,559✔
827
    pGroupResInfo->dataPos = pData;
18,657,559✔
828

829
    code = copyResultrowToDataBlock(pExprInfo, numOfExprs, pRow, pCtx, pBlock, rowEntryOffset, pTaskInfo);
18,657,559✔
830
    releaseBufPage(pBuf, page);
18,681,326✔
831
    QUERY_CHECK_CODE(code, lino, _end);
18,680,301!
832
    pBlock->info.rows += pRow->numOfRows;
18,680,301✔
833
    if (pBlock->info.rows >= threshold) {
18,680,301✔
834
      break;
40✔
835
    }
836
  }
837

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

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

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

860
  int32_t numOfRows = getNumOfTotalRes(pGroupResInfo);
3,045,454✔
861

862
  for (int32_t i = pGroupResInfo->index; i < numOfRows; i += 1) {
223,114,183✔
863
    SResKeyPos* pPos = taosArrayGetP(pGroupResInfo->pRows, i);
220,676,372✔
864
    SFilePage*  page = getBufPage(pBuf, pPos->pos.pageId);
220,362,455✔
865
    if (page == NULL) {
220,830,365!
UNCOV
866
      qError("failed to get buffer, code:%s, %s", tstrerror(terrno), GET_TASKID(pTaskInfo));
×
UNCOV
867
      T_LONG_JMP(pTaskInfo->env, terrno);
×
868
    }
869

870
    SResultRow* pRow = (SResultRow*)((char*)page + pPos->pos.offset);
220,830,365✔
871

872
    doUpdateNumOfRows(pCtx, pRow, numOfExprs, rowEntryOffset);
220,830,365✔
873

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

881
    if (!ignoreGroup) {
219,373,250✔
882
      if (pBlock->info.id.groupId == 0) {
147,149,433✔
883
        pBlock->info.id.groupId = pPos->groupId;
129,912,451✔
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,236,982✔
887
          releaseBufPage(pBuf, page);
135,407✔
888
          break;
135,390✔
889
        }
890
      }
891
    }
892

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

902
    pGroupResInfo->index += 1;
219,237,843✔
903
    code = copyResultrowToDataBlock(pExprInfo, numOfExprs, pRow, pCtx, pBlock, rowEntryOffset, pTaskInfo);
219,237,843✔
904
    releaseBufPage(pBuf, page);
221,167,255✔
905
    QUERY_CHECK_CODE(code, lino, _end);
220,515,826!
906

907
    pBlock->info.rows += pRow->numOfRows;
220,515,826✔
908
    if (pBlock->info.rows >= threshold) {
220,515,826✔
909
      break;
448,055✔
910
    }
911
  }
912

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

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

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

931
  // set output datablock version
932
  pBlock->info.version = pTaskInfo->version;
3,969,159✔
933

934
  blockDataCleanup(pBlock);
3,969,159✔
935
  if (!hasRemainResults(pGroupResInfo)) {
3,969,653✔
936
    return;
923,363✔
937
  }
938

939
  // clear the existed group id
940
  pBlock->info.id.groupId = 0;
3,045,594✔
941
  if (!pbInfo->mergeResultBlock) {
3,045,594✔
942
    doCopyToSDataBlock(pTaskInfo, pBlock, &pOperator->exprSupp, pBuf, pGroupResInfo, pOperator->resultInfo.threshold,
1,884,035✔
943
                       false);
944
  } else {
945
    while (hasRemainResults(pGroupResInfo)) {
2,123,780✔
946
      doCopyToSDataBlock(pTaskInfo, pBlock, &pOperator->exprSupp, pBuf, pGroupResInfo, pOperator->resultInfo.threshold,
1,161,171✔
947
                         true);
948
      if (pBlock->info.rows >= pOperator->resultInfo.threshold) {
1,161,351✔
949
        break;
199,130✔
950
      }
951

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

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

961
void destroyExprInfo(SExprInfo* pExpr, int32_t numOfExprs) {
10,240,215✔
962
  for (int32_t i = 0; i < numOfExprs; ++i) {
41,264,867✔
963
    SExprInfo* pExprInfo = &pExpr[i];
31,023,909✔
964
    for (int32_t j = 0; j < pExprInfo->base.numOfParams; ++j) {
63,966,892✔
965
      if (pExprInfo->base.pParam[j].type == FUNC_PARAM_TYPE_COLUMN) {
32,971,259✔
966
        taosMemoryFreeClear(pExprInfo->base.pParam[j].pCol);
29,654,379!
967
      } else if (pExprInfo->base.pParam[j].type == FUNC_PARAM_TYPE_VALUE) {
3,316,880✔
968
        taosVariantDestroy(&pExprInfo->base.pParam[j].param);
2,503,612✔
969
      }
970
    }
971

972
    taosMemoryFree(pExprInfo->base.pParam);
30,995,633✔
973
    taosMemoryFree(pExprInfo->pExpr);
31,032,216✔
974
  }
975
}
10,240,958✔
976

977
int32_t getBufferPgSize(int32_t rowSize, uint32_t* defaultPgsz, uint32_t* defaultBufsz) {
6,593,136✔
978
  *defaultPgsz = 4096;
6,593,136✔
979
  uint32_t last = *defaultPgsz;
6,593,136✔
980
  while (*defaultPgsz < rowSize * 4) {
7,737,748✔
981
    *defaultPgsz <<= 1u;
1,144,612✔
982
    if (*defaultPgsz < last) {
1,144,612!
UNCOV
983
      return TSDB_CODE_INVALID_PARA;
×
984
    }
985
    last = *defaultPgsz;
1,144,612✔
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,593,136✔
992
  if ((*defaultBufsz) <= (*defaultPgsz)) {
6,593,136!
993
    (*defaultBufsz) = (*defaultPgsz) * 4;
×
UNCOV
994
    if (*defaultBufsz < ((int64_t)(*defaultPgsz)) * 4) {
×
UNCOV
995
      return TSDB_CODE_INVALID_PARA;
×
996
    }
997
  }
998

999
  return 0;
6,593,136✔
1000
}
1001

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

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

1010
  if (pResultInfo->threshold == 0) {
15,627,172✔
1011
    pResultInfo->threshold = numOfRows;
307,525✔
1012
  }
1013
}
15,627,172✔
1014

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

1020
static void destroySqlFunctionCtx(SqlFunctionCtx* pCtx, SExprInfo* pExpr, int32_t numOfOutput) {
30,329,727✔
1021
  if (pCtx == NULL) {
30,329,727✔
1022
    return;
19,210,980✔
1023
  }
1024

1025
  for (int32_t i = 0; i < numOfOutput; ++i) {
41,878,730✔
1026
    if (pExpr != NULL) {
30,754,298!
1027
      SExprInfo* pExprInfo = &pExpr[i];
30,756,497✔
1028
      for (int32_t j = 0; j < pExprInfo->base.numOfParams; ++j) {
63,454,329✔
1029
        if (pExprInfo->base.pParam[j].type == FUNC_PARAM_TYPE_VALUE) {
32,700,607✔
1030
          taosMemoryFree(pCtx[i].input.pData[j]);
2,499,366✔
1031
          taosMemoryFree(pCtx[i].input.pColumnDataAgg[j]);
2,499,302✔
1032
        }
1033
      }
1034
    }
1035
    for (int32_t j = 0; j < pCtx[i].numOfParams; ++j) {
63,444,135✔
1036
      taosVariantDestroy(&pCtx[i].param[j].param);
32,696,459✔
1037
    }
1038

1039
    taosMemoryFreeClear(pCtx[i].subsidiaries.pCtx);
30,747,676✔
1040
    taosMemoryFreeClear(pCtx[i].subsidiaries.buf);
30,747,797✔
1041
    taosMemoryFree(pCtx[i].input.pData);
30,747,801✔
1042
    taosMemoryFree(pCtx[i].input.pColumnDataAgg);
30,769,153✔
1043

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

1049
  taosMemoryFreeClear(pCtx);
11,124,432!
1050
  return;
11,124,315✔
1051
}
1052

1053
int32_t initExprSupp(SExprSupp* pSup, SExprInfo* pExprInfo, int32_t numOfExpr, SFunctionStateStore* pStore) {
10,293,261✔
1054
  pSup->pExprInfo = pExprInfo;
10,293,261✔
1055
  pSup->numOfExprs = numOfExpr;
10,293,261✔
1056
  if (pSup->pExprInfo != NULL) {
10,293,261✔
1057
    pSup->pCtx = createSqlFunctionCtx(pExprInfo, numOfExpr, &pSup->rowEntryInfoOffset, pStore);
8,209,037✔
1058
    if (pSup->pCtx == NULL) {
8,208,786!
UNCOV
1059
      return TSDB_CODE_OUT_OF_MEMORY;
×
1060
    }
1061
  }
1062

1063
  return TSDB_CODE_SUCCESS;
10,293,010✔
1064
}
1065

1066
void cleanupExprSupp(SExprSupp* pSupp) {
30,330,708✔
1067
  destroySqlFunctionCtx(pSupp->pCtx, pSupp->pExprInfo, pSupp->numOfExprs);
30,330,708✔
1068
  if (pSupp->pExprInfo != NULL) {
30,328,965✔
1069
    destroyExprInfo(pSupp->pExprInfo, pSupp->numOfExprs);
10,234,880✔
1070
    taosMemoryFreeClear(pSupp->pExprInfo);
10,234,850!
1071
  }
1072

1073
  if (pSupp->pFilterInfo != NULL) {
30,329,217✔
1074
    filterFreeInfo(pSupp->pFilterInfo);
2,920,537✔
1075
    pSupp->pFilterInfo = NULL;
2,920,604✔
1076
  }
1077

1078
  taosMemoryFree(pSupp->rowEntryInfoOffset);
30,329,284✔
1079
}
30,314,126✔
1080

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

1086
bool groupbyTbname(SNodeList* pGroupList) {
4,724,393✔
1087
  bool bytbname = false;
4,724,393✔
1088
  SNode*pNode = NULL;
4,724,393✔
1089
  FOREACH(pNode, pGroupList) {
4,828,632✔
1090
    if (pNode->type == QUERY_NODE_FUNCTION) {
427,074✔
1091
      bytbname = (strcmp(((struct SFunctionNode*)pNode)->functionName, "tbname") == 0);
322,835✔
1092
      break;
322,835✔
1093
    }
1094
  }
1095
  return bytbname;
4,724,393✔
1096
}
1097

1098
int32_t createDataSinkParam(SDataSinkNode* pNode, void** pParam, SExecTaskInfo* pTask, SReadHandle* readHandle) {
8,353,827✔
1099
  switch (pNode->type) {
8,353,827✔
1100
    case QUERY_NODE_PHYSICAL_PLAN_QUERY_INSERT: {
169✔
1101
      SInserterParam* pInserterParam = taosMemoryCalloc(1, sizeof(SInserterParam));
169✔
1102
      if (NULL == pInserterParam) {
169!
UNCOV
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,130✔
1111
      SDeleterParam* pDeleterParam = taosMemoryCalloc(1, sizeof(SDeleterParam));
60,130✔
1112
      if (NULL == pDeleterParam) {
60,128!
UNCOV
1113
        return terrno;
×
1114
      }
1115

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

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

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

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

1137
      pDeleterParam->pUidList = taosArrayInit(numOfTables, sizeof(uint64_t));
60,125✔
1138
      if (NULL == pDeleterParam->pUidList) {
60,128!
UNCOV
1139
        taosMemoryFree(pDeleterParam);
×
UNCOV
1140
        return terrno;
×
1141
      }
1142

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

1158
      *pParam = pDeleterParam;
60,130✔
1159
      break;
60,130✔
1160
    }
1161
    default:
8,293,528✔
1162
      break;
8,293,528✔
1163
  }
1164

1165
  return TSDB_CODE_SUCCESS;
8,353,827✔
1166
}
1167

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

1231
void freeOperatorParam(SOperatorParam* pParam, SOperatorParamType type) {
5,730,016✔
1232
  if (NULL == pParam) {
5,730,016✔
1233
    return;
5,623,941✔
1234
  }
1235

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

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

1271
  if (*ppParam) {
39,027,186✔
1272
    freeOperatorParam(*ppParam, type);
34,494✔
1273
    *ppParam = NULL;
34,494✔
1274
  }
1275

1276
  if (*pppDownstramParam) {
39,027,186✔
1277
    for (int32_t i = 0; i < pOperator->numOfDownstream; ++i) {
105,140✔
1278
      if ((*pppDownstramParam)[i]) {
68,988!
UNCOV
1279
        freeOperatorParam((*pppDownstramParam)[i], type);
×
UNCOV
1280
        (*pppDownstramParam)[i] = NULL;
×
1281
      }
1282
    }
1283
    if (allFree) {
36,152✔
1284
      taosMemoryFreeClear(*pppDownstramParam);
1,913!
1285
    }
1286
  }
1287
}
1288

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

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

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

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

1316
bool compareVal(const char* v, const SStateKeys* pKey) {
18,847,594✔
1317
  if (IS_VAR_DATA_TYPE(pKey->type)) {
18,847,594!
1318
    if (varDataLen(v) != varDataLen(pKey->pData)) {
2,055!
UNCOV
1319
      return false;
×
1320
    } else {
1321
      return memcmp(varDataVal(v), varDataVal(pKey->pData), varDataLen(v)) == 0;
2,055✔
1322
    }
1323
  } else {
1324
    return memcmp(pKey->pData, v, pKey->bytes) == 0;
18,845,539✔
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