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

taosdata / TDengine / #3621

22 Feb 2025 11:44AM UTC coverage: 2.037% (-61.5%) from 63.573%
#3621

push

travis-ci

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

merge: from main to 3.0 branch

4357 of 287032 branches covered (1.52%)

Branch coverage included in aggregate %.

0 of 174 new or added lines in 18 files covered. (0.0%)

213359 existing lines in 469 files now uncovered.

7260 of 283369 relevant lines covered (2.56%)

23737.72 hits per line

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

0.0
/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

UNCOV
85
SResultRow* getNewResultRow(SDiskbasedBuf* pResultBuf, int32_t* currentPageId, int32_t interBufSize) {
×
UNCOV
86
  SFilePage* pData = NULL;
×
87

88
  // in the first scan, new space needed for results
UNCOV
89
  int32_t pageId = -1;
×
UNCOV
90
  if (*currentPageId == -1) {
×
UNCOV
91
    pData = getNewBufPage(pResultBuf, &pageId);
×
UNCOV
92
    if (pData == NULL) {
×
UNCOV
93
      qError("failed to get buffer, code:%s", tstrerror(terrno));
×
94
      return NULL;
×
95
    }
UNCOV
96
    pData->num = sizeof(SFilePage);
×
97
  } else {
UNCOV
98
    pData = getBufPage(pResultBuf, *currentPageId);
×
UNCOV
99
    if (pData == NULL) {
×
100
      qError("failed to get buffer, code:%s", tstrerror(terrno));
×
101
      return NULL;
×
102
    }
103

UNCOV
104
    pageId = *currentPageId;
×
105

UNCOV
106
    if (pData->num + interBufSize > getBufPageSize(pResultBuf)) {
×
107
      // release current page first, and prepare the next one
UNCOV
108
      releaseBufPage(pResultBuf, pData);
×
109

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

UNCOV
119
  if (pData == NULL) {
×
120
    return NULL;
×
121
  }
122

UNCOV
123
  setBufPageDirty(pData, true);
×
124

125
  // set the number of rows in current disk page
UNCOV
126
  SResultRow* pResultRow = (SResultRow*)((char*)pData + pData->num);
×
127

UNCOV
128
  memset((char*)pResultRow, 0, interBufSize);
×
UNCOV
129
  pResultRow->pageId = pageId;
×
UNCOV
130
  pResultRow->offset = (int32_t)pData->num;
×
131

UNCOV
132
  *currentPageId = pageId;
×
UNCOV
133
  pData->num += interBufSize;
×
UNCOV
134
  return pResultRow;
×
135
}
136

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

152
  SResultRowPosition* p1 =
UNCOV
153
      (SResultRowPosition*)tSimpleHashGet(pSup->pResultRowHashTable, pSup->keyBuf, GET_RES_WINDOW_KEY_LEN(bytes));
×
154

UNCOV
155
  SResultRow* pResult = NULL;
×
156

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

UNCOV
166
      if (pResult->pageId != p1->pageId || pResult->offset != p1->offset) {
×
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.
UNCOV
175
    if (p1 != NULL) {
×
176
      // todo
UNCOV
177
      pResult = getResultRowByPos(pResultBuf, p1, true);
×
UNCOV
178
      if (NULL == pResult) {
×
179
        pTaskInfo->code = terrno;
×
180
        return NULL;
×
181
      }
182

UNCOV
183
      if (pResult->pageId != p1->pageId || pResult->offset != p1->offset) {
×
184
        terrno = TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR;
×
185
        pTaskInfo->code = terrno;
×
UNCOV
186
        return NULL;
×
187
      }
188
    }
189
  }
190

191
  // 1. close current opened time window
UNCOV
192
  if (pResultRowInfo->cur.pageId != -1 && ((pResult == NULL) || (pResult->pageId != pResultRowInfo->cur.pageId))) {
×
UNCOV
193
    SResultRowPosition pos = pResultRowInfo->cur;
×
UNCOV
194
    SFilePage*         pPage = getBufPage(pResultBuf, pos.pageId);
×
UNCOV
195
    if (pPage == NULL) {
×
196
      qError("failed to get buffer, code:%s, %s", tstrerror(terrno), GET_TASKID(pTaskInfo));
×
197
      pTaskInfo->code = terrno;
×
198
      return NULL;
×
199
    }
UNCOV
200
    releaseBufPage(pResultBuf, pPage);
×
201
  }
202

203
  // allocate a new buffer page
UNCOV
204
  if (pResult == NULL) {
×
UNCOV
205
    pResult = getNewResultRow(pResultBuf, &pSup->currentPageId, pSup->resultRowSize);
×
UNCOV
206
    if (pResult == NULL) {
×
207
      pTaskInfo->code = terrno;
×
208
      return NULL;
×
209
    }
210

211
    // add a new result set for a new group
UNCOV
212
    SResultRowPosition pos = {.pageId = pResult->pageId, .offset = pResult->offset};
×
UNCOV
213
    int32_t code = tSimpleHashPut(pSup->pResultRowHashTable, pSup->keyBuf, GET_RES_WINDOW_KEY_LEN(bytes), &pos,
×
214
                                  sizeof(SResultRowPosition));
UNCOV
215
    if (code != TSDB_CODE_SUCCESS) {
×
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
UNCOV
223
  pResultRowInfo->cur = (SResultRowPosition){.pageId = pResult->pageId, .offset = pResult->offset};
×
224

225
  // too many time window in query
UNCOV
226
  if (pTaskInfo->execModel == OPTR_EXEC_MODEL_BATCH &&
×
UNCOV
227
      tSimpleHashGetSize(pSup->pResultRowHashTable) > MAX_INTERVAL_TIME_WINDOW) {
×
228
    pTaskInfo->code = TSDB_CODE_QRY_TOO_MANY_TIMEWINDOW;
×
229
    return NULL;
×
230
  }
231

UNCOV
232
  return pResult;
×
233
}
234

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

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

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

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

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

UNCOV
274
int32_t setInputDataBlock(SExprSupp* pExprSup, SSDataBlock* pBlock, int32_t order, int32_t scanFlag,
×
275
                          bool createDummyCol) {
UNCOV
276
  if (pBlock->pBlockAgg != NULL) {
×
UNCOV
277
    return doSetInputDataBlockInfo(pExprSup, pBlock, order, scanFlag);
×
278
  } else {
UNCOV
279
    return doSetInputDataBlock(pExprSup, pBlock, order, scanFlag, createDummyCol);
×
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

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

UNCOV
340
  for (int32_t i = 0; i < pExprSup->numOfExprs; ++i) {
×
UNCOV
341
    pCtx[i].order = order;
×
UNCOV
342
    pCtx[i].input.numOfRows = pBlock->info.rows;
×
343

UNCOV
344
    pCtx[i].pSrcBlock = pBlock;
×
UNCOV
345
    pCtx[i].scanFlag = scanFlag;
×
346

UNCOV
347
    SInputColumnInfoData* pInput = &pCtx[i].input;
×
UNCOV
348
    pInput->uid = pBlock->info.id.uid;
×
UNCOV
349
    pInput->colDataSMAIsSet = false;
×
350

UNCOV
351
    SExprInfo* pOneExpr = &pExprSup->pExprInfo[i];
×
UNCOV
352
    bool       hasPk = pOneExpr->pExpr->nodeType == QUERY_NODE_FUNCTION && pOneExpr->pExpr->_function.pFunctNode->hasPk;
×
UNCOV
353
    pCtx[i].hasPrimaryKey = hasPk;
×
354

UNCOV
355
    int16_t tsParamIdx = (!hasPk) ? pOneExpr->base.numOfParams - 1 : pOneExpr->base.numOfParams - 2;
×
UNCOV
356
    int16_t pkParamIdx = pOneExpr->base.numOfParams - 1;
×
357

UNCOV
358
    for (int32_t j = 0; j < pOneExpr->base.numOfParams; ++j) {
×
UNCOV
359
      SFunctParam* pFuncParam = &pOneExpr->base.pParam[j];
×
UNCOV
360
      if (pFuncParam->type == FUNC_PARAM_TYPE_COLUMN) {
×
UNCOV
361
        int32_t slotId = pFuncParam->pCol->slotId;
×
UNCOV
362
        pInput->pData[j] = taosArrayGet(pBlock->pDataBlock, slotId);
×
UNCOV
363
        pInput->totalRows = pBlock->info.rows;
×
UNCOV
364
        pInput->numOfRows = pBlock->info.rows;
×
UNCOV
365
        pInput->startRowIndex = 0;
×
UNCOV
366
        pInput->blankFill = pBlock->info.blankFill;
×
367

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

UNCOV
371
        if (fmIsImplicitTsFunc(pCtx[i].functionId) && (j == tsParamIdx)) {
×
UNCOV
372
          pInput->pPTS = pInput->pData[j];  // in case of merge function, this is not always the ts column data.
×
373
        }
UNCOV
374
        if (hasPk && (j == pkParamIdx)) {
×
UNCOV
375
          pInput->pPrimaryKey = pInput->pData[j];
×
376
        }
UNCOV
377
        QUERY_CHECK_CONDITION((pInput->pData[j] != NULL), code, lino, _end, TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR);
×
UNCOV
378
      } else if (pFuncParam->type == FUNC_PARAM_TYPE_VALUE) {
×
379
        // todo avoid case: top(k, 12), 12 is the value parameter.
380
        // sum(11), 11 is also the value parameter.
UNCOV
381
        if (createDummyCol && pOneExpr->base.numOfParams == 1) {
×
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

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

UNCOV
401
bool functionNeedToExecute(SqlFunctionCtx* pCtx) {
×
UNCOV
402
  struct SResultRowEntryInfo* pResInfo = GET_RES_INFO(pCtx);
×
403

404
  // in case of timestamp column, always generated results.
UNCOV
405
  int32_t functionId = pCtx->functionId;
×
UNCOV
406
  if (functionId == -1) {
×
UNCOV
407
    return false;
×
408
  }
409

UNCOV
410
  if (pCtx->scanFlag == PRE_SCAN) {
×
UNCOV
411
    return fmIsRepeatScanFunc(pCtx->functionId);
×
412
  }
413

UNCOV
414
  if (isRowEntryCompleted(pResInfo)) {
×
415
    return false;
×
416
  }
417

UNCOV
418
  return true;
×
419
}
420

UNCOV
421
static int32_t doCreateConstantValColumnSMAInfo(SInputColumnInfoData* pInput, SFunctParam* pFuncParam, int32_t type,
×
422
                                                int32_t paramIndex, int32_t numOfRows) {
UNCOV
423
  if (pInput->pData[paramIndex] == NULL) {
×
UNCOV
424
    pInput->pData[paramIndex] = taosMemoryCalloc(1, sizeof(SColumnInfoData));
×
UNCOV
425
    if (pInput->pData[paramIndex] == NULL) {
×
426
      return terrno;
×
427
    }
428

429
    // Set the correct column info (data type and bytes)
UNCOV
430
    pInput->pData[paramIndex]->info.type = type;
×
UNCOV
431
    pInput->pData[paramIndex]->info.bytes = tDataTypes[type].bytes;
×
432
  }
433

UNCOV
434
  SColumnDataAgg* da = NULL;
×
UNCOV
435
  if (pInput->pColumnDataAgg[paramIndex] == NULL) {
×
UNCOV
436
    da = taosMemoryCalloc(1, sizeof(SColumnDataAgg));
×
UNCOV
437
    if (!da) {
×
438
      return terrno;
×
439
    }
UNCOV
440
    pInput->pColumnDataAgg[paramIndex] = da;
×
441
  } else {
UNCOV
442
    da = pInput->pColumnDataAgg[paramIndex];
×
443
  }
444

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

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

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

UNCOV
468
  return TSDB_CODE_SUCCESS;
×
469
}
470

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

UNCOV
476
  SInputColumnInfoData* pInput = &pCtx->input;
×
UNCOV
477
  pInput->numOfRows = numOfRows;
×
UNCOV
478
  pInput->totalRows = numOfRows;
×
479

UNCOV
480
  if (pBlock->pBlockAgg != NULL) {
×
UNCOV
481
    pInput->colDataSMAIsSet = true;
×
482

UNCOV
483
    for (int32_t j = 0; j < pExprInfo->base.numOfParams; ++j) {
×
UNCOV
484
      SFunctParam* pFuncParam = &pExprInfo->base.pParam[j];
×
485

UNCOV
486
      if (pFuncParam->type == FUNC_PARAM_TYPE_COLUMN) {
×
UNCOV
487
        int32_t slotId = pFuncParam->pCol->slotId;
×
UNCOV
488
        pInput->pColumnDataAgg[j] = &pBlock->pBlockAgg[slotId];
×
UNCOV
489
        if (pInput->pColumnDataAgg[j]->colId == -1) {
×
UNCOV
490
          pInput->colDataSMAIsSet = false;
×
491
        }
492

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

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

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

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

UNCOV
526
  return win;
×
527
}
528

UNCOV
529
int32_t setResultRowInitCtx(SResultRow* pResult, SqlFunctionCtx* pCtx, int32_t numOfOutput,
×
530
                            int32_t* rowEntryInfoOffset) {
UNCOV
531
  bool init = false;
×
UNCOV
532
  for (int32_t i = 0; i < numOfOutput; ++i) {
×
UNCOV
533
    pCtx[i].resultInfo = getResultEntryInfo(pResult, i, rowEntryInfoOffset);
×
UNCOV
534
    if (init) {
×
UNCOV
535
      continue;
×
536
    }
537

UNCOV
538
    struct SResultRowEntryInfo* pResInfo = pCtx[i].resultInfo;
×
UNCOV
539
    if (isRowEntryCompleted(pResInfo) && isRowEntryInitialized(pResInfo)) {
×
540
      continue;
×
541
    }
542

UNCOV
543
    if (pCtx[i].isPseudoFunc) {
×
UNCOV
544
      continue;
×
545
    }
546

UNCOV
547
    if (!pResInfo->initialized) {
×
UNCOV
548
      if (pCtx[i].functionId != -1) {
×
UNCOV
549
        int32_t code = pCtx[i].fpSet.init(&pCtx[i], pResInfo);
×
UNCOV
550
        if (code != TSDB_CODE_SUCCESS && fmIsUserDefinedFunc(pCtx[i].functionId)) {
×
UNCOV
551
          pResInfo->initialized = false;
×
UNCOV
552
          qError("failed to initialize udf, funcId:%d error:%s", pCtx[i].functionId, tstrerror(code));
×
553
          return TSDB_CODE_UDF_FUNC_EXEC_FAILURE;
×
UNCOV
554
        } else if (code != TSDB_CODE_SUCCESS) {
×
555
          qError("failed to initialize function context, funcId:%d error:%s", pCtx[i].functionId, tstrerror(code));
×
556
          return code;
×
557
        }
558
      } else {
UNCOV
559
        pResInfo->initialized = true;
×
560
      }
561
    } else {
UNCOV
562
      init = true;
×
563
    }
564
  }
UNCOV
565
  return TSDB_CODE_SUCCESS;
×
566
}
567

UNCOV
568
void clearResultRowInitFlag(SqlFunctionCtx* pCtx, int32_t numOfOutput) {
×
UNCOV
569
  for (int32_t i = 0; i < numOfOutput; ++i) {
×
UNCOV
570
    SResultRowEntryInfo* pResInfo = pCtx[i].resultInfo;
×
UNCOV
571
    if (pResInfo == NULL) {
×
572
      continue;
×
573
    }
574

UNCOV
575
    pResInfo->initialized = false;
×
UNCOV
576
    pResInfo->numOfRes = 0;
×
UNCOV
577
    pResInfo->isNullRes = 0;
×
UNCOV
578
    pResInfo->complete = false;
×
579
  }
UNCOV
580
}
×
581

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

UNCOV
589
  SFilterColumnParam param1 = {.numOfCols = taosArrayGetSize(pBlock->pDataBlock), .pDataBlock = pBlock->pDataBlock};
×
UNCOV
590
  SColumnInfoData*   p = NULL;
×
591

UNCOV
592
  code = filterSetDataFromSlotId(pFilterInfo, &param1);
×
UNCOV
593
  QUERY_CHECK_CODE(code, lino, _err);
×
594

UNCOV
595
  int32_t status = 0;
×
UNCOV
596
  code = filterExecute(pFilterInfo, pBlock, &p, NULL, param1.numOfCols, &status);
×
UNCOV
597
  QUERY_CHECK_CODE(code, lino, _err);
×
598

UNCOV
599
  code = extractQualifiedTupleByFilterResult(pBlock, p, status);
×
UNCOV
600
  QUERY_CHECK_CODE(code, lino, _err);
×
601

UNCOV
602
  if (pColMatchInfo != NULL) {
×
UNCOV
603
    size_t size = taosArrayGetSize(pColMatchInfo->pList);
×
UNCOV
604
    for (int32_t i = 0; i < size; ++i) {
×
UNCOV
605
      SColMatchItem* pInfo = taosArrayGet(pColMatchInfo->pList, i);
×
UNCOV
606
      QUERY_CHECK_NULL(pInfo, code, lino, _err, terrno);
×
UNCOV
607
      if (pInfo->colId == PRIMARYKEY_TIMESTAMP_COL_ID) {
×
UNCOV
608
        SColumnInfoData* pColData = taosArrayGet(pBlock->pDataBlock, pInfo->dstSlotId);
×
UNCOV
609
        QUERY_CHECK_NULL(pColData, code, lino, _err, terrno);
×
UNCOV
610
        if (pColData->info.type == TSDB_DATA_TYPE_TIMESTAMP) {
×
UNCOV
611
          code = blockDataUpdateTsWindow(pBlock, pInfo->dstSlotId);
×
UNCOV
612
          QUERY_CHECK_CODE(code, lino, _err);
×
UNCOV
613
          break;
×
614
        }
615
      }
616
    }
617
  }
UNCOV
618
  code = blockDataCheck(pBlock);
×
UNCOV
619
  QUERY_CHECK_CODE(code, lino, _err);
×
UNCOV
620
_err:
×
UNCOV
621
  if (code != TSDB_CODE_SUCCESS) {
×
UNCOV
622
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
×
623
  }
UNCOV
624
  colDataDestroy(p);
×
UNCOV
625
  taosMemoryFree(p);
×
UNCOV
626
  return code;
×
627
}
628

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

UNCOV
645
void doUpdateNumOfRows(SqlFunctionCtx* pCtx, SResultRow* pRow, int32_t numOfExprs, const int32_t* rowEntryOffset) {
×
UNCOV
646
  bool returnNotNull = false;
×
UNCOV
647
  for (int32_t j = 0; j < numOfExprs; ++j) {
×
UNCOV
648
    SResultRowEntryInfo* pResInfo = getResultEntryInfo(pRow, j, rowEntryOffset);
×
UNCOV
649
    if (!isRowEntryInitialized(pResInfo)) {
×
UNCOV
650
      continue;
×
651
    } else {
652
    }
653

UNCOV
654
    if (pRow->numOfRows < pResInfo->numOfRes) {
×
UNCOV
655
      pRow->numOfRows = pResInfo->numOfRes;
×
656
    }
657

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

UNCOV
669
int32_t copyResultrowToDataBlock(SExprInfo* pExprInfo, int32_t numOfExprs, SResultRow* pRow, SqlFunctionCtx* pCtx,
×
670
                                 SSDataBlock* pBlock, const int32_t* rowEntryOffset, SExecTaskInfo* pTaskInfo) {
UNCOV
671
  int32_t code = TSDB_CODE_SUCCESS;
×
UNCOV
672
  int32_t lino = 0;
×
UNCOV
673
  for (int32_t j = 0; j < numOfExprs; ++j) {
×
UNCOV
674
    int32_t slotId = pExprInfo[j].base.resSchema.slotId;
×
675

UNCOV
676
    pCtx[j].resultInfo = getResultEntryInfo(pRow, j, rowEntryOffset);
×
UNCOV
677
    if (pCtx[j].fpSet.finalize) {
×
UNCOV
678
      if (strcmp(pCtx[j].pExpr->pExpr->_function.functionName, "_group_key") == 0 ||
×
UNCOV
679
          strcmp(pCtx[j].pExpr->pExpr->_function.functionName, "_group_const_value") == 0) {
×
680
        // for groupkey along with functions that output multiple lines(e.g. Histogram)
681
        // need to match groupkey result for each output row of that function.
UNCOV
682
        if (pCtx[j].resultInfo->numOfRes != 0) {
×
UNCOV
683
          pCtx[j].resultInfo->numOfRes = pRow->numOfRows;
×
684
        }
685
      }
686

UNCOV
687
      code = blockDataEnsureCapacity(pBlock, pBlock->info.rows + pCtx[j].resultInfo->numOfRes);
×
UNCOV
688
      QUERY_CHECK_CODE(code, lino, _end);
×
689

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

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

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

UNCOV
726
  SResultRow* pRow = (SResultRow*)((char*)page + resultRowPosition->offset);
×
727

UNCOV
728
  SqlFunctionCtx* pCtx = pSup->pCtx;
×
UNCOV
729
  SExprInfo*      pExprInfo = pSup->pExprInfo;
×
UNCOV
730
  const int32_t*  rowEntryOffset = pSup->rowEntryInfoOffset;
×
731

UNCOV
732
  doUpdateNumOfRows(pCtx, pRow, pSup->numOfExprs, rowEntryOffset);
×
UNCOV
733
  if (pRow->numOfRows == 0) {
×
UNCOV
734
    releaseBufPage(pBuf, page);
×
735
    return;
×
736
  }
737

UNCOV
738
  int32_t size = pBlock->info.capacity;
×
UNCOV
739
  while (pBlock->info.rows + pRow->numOfRows > size) {
×
UNCOV
740
    size = size * 1.25;
×
741
  }
742

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

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

UNCOV
757
  releaseBufPage(pBuf, page);
×
UNCOV
758
  pBlock->info.rows += pRow->numOfRows;
×
759
}
760

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

UNCOV
770
  size_t  keyLen = 0;
×
UNCOV
771
  int32_t numOfRows = tSimpleHashGetSize(pHashmap);
×
772

773
  // begin from last iter
UNCOV
774
  void*   pData = pGroupResInfo->dataPos;
×
UNCOV
775
  int32_t iter = pGroupResInfo->iter;
×
UNCOV
776
  while ((pData = tSimpleHashIterate(pHashmap, pData, &iter)) != NULL) {
×
UNCOV
777
    void*               key = tSimpleHashGetKey(pData, &keyLen);
×
UNCOV
778
    SResultRowPosition* pos = pData;
×
UNCOV
779
    uint64_t            groupId = *(uint64_t*)key;
×
780

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

UNCOV
787
    SResultRow* pRow = (SResultRow*)((char*)page + pos->offset);
×
788

UNCOV
789
    doUpdateNumOfRows(pCtx, pRow, numOfExprs, rowEntryOffset);
×
790

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

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

UNCOV
801
    if (!ignoreGroup) {
×
UNCOV
802
      if (pBlock->info.id.groupId == 0) {
×
UNCOV
803
        pBlock->info.id.groupId = groupId;
×
804
      } else {
805
        // current value belongs to different group, it can't be packed into one datablock
UNCOV
806
        if (pBlock->info.id.groupId != groupId) {
×
UNCOV
807
          releaseBufPage(pBuf, page);
×
UNCOV
808
          break;
×
809
        }
810
      }
811
    }
812

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

UNCOV
822
    pGroupResInfo->index += 1;
×
UNCOV
823
    pGroupResInfo->iter = iter;
×
UNCOV
824
    pGroupResInfo->dataPos = pData;
×
825

UNCOV
826
    code = copyResultrowToDataBlock(pExprInfo, numOfExprs, pRow, pCtx, pBlock, rowEntryOffset, pTaskInfo);
×
UNCOV
827
    releaseBufPage(pBuf, page);
×
UNCOV
828
    QUERY_CHECK_CODE(code, lino, _end);
×
UNCOV
829
    pBlock->info.rows += pRow->numOfRows;
×
UNCOV
830
    if (pBlock->info.rows >= threshold) {
×
UNCOV
831
      break;
×
832
    }
833
  }
834

UNCOV
835
  qDebug("%s result generated, rows:%" PRId64 ", groupId:%" PRIu64, GET_TASKID(pTaskInfo), pBlock->info.rows,
×
836
         pBlock->info.id.groupId);
UNCOV
837
  pBlock->info.dataLoad = 1;
×
UNCOV
838
  code = blockDataUpdateTsWindow(pBlock, 0);
×
UNCOV
839
  QUERY_CHECK_CODE(code, lino, _end);
×
840

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

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

UNCOV
857
  int32_t numOfRows = getNumOfTotalRes(pGroupResInfo);
×
858

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

UNCOV
867
    SResultRow* pRow = (SResultRow*)((char*)page + pPos->pos.offset);
×
868

UNCOV
869
    doUpdateNumOfRows(pCtx, pRow, numOfExprs, rowEntryOffset);
×
870

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

UNCOV
878
    if (!ignoreGroup) {
×
UNCOV
879
      if (pBlock->info.id.groupId == 0) {
×
UNCOV
880
        pBlock->info.id.groupId = pPos->groupId;
×
881
      } else {
882
        // current value belongs to different group, it can't be packed into one datablock
UNCOV
883
        if (pBlock->info.id.groupId != pPos->groupId) {
×
UNCOV
884
          releaseBufPage(pBuf, page);
×
UNCOV
885
          break;
×
886
        }
887
      }
888
    }
889

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

UNCOV
899
    pGroupResInfo->index += 1;
×
UNCOV
900
    code = copyResultrowToDataBlock(pExprInfo, numOfExprs, pRow, pCtx, pBlock, rowEntryOffset, pTaskInfo);
×
UNCOV
901
    releaseBufPage(pBuf, page);
×
UNCOV
902
    QUERY_CHECK_CODE(code, lino, _end);
×
903

UNCOV
904
    pBlock->info.rows += pRow->numOfRows;
×
UNCOV
905
    if (pBlock->info.rows >= threshold) {
×
UNCOV
906
      break;
×
907
    }
908
  }
909

UNCOV
910
  qDebug("%s result generated, rows:%" PRId64 ", groupId:%" PRIu64, GET_TASKID(pTaskInfo), pBlock->info.rows,
×
911
         pBlock->info.id.groupId);
UNCOV
912
  pBlock->info.dataLoad = 1;
×
UNCOV
913
  code = blockDataUpdateTsWindow(pBlock, 0);
×
UNCOV
914
  QUERY_CHECK_CODE(code, lino, _end);
×
915

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

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

928
  // set output datablock version
UNCOV
929
  pBlock->info.version = pTaskInfo->version;
×
930

UNCOV
931
  blockDataCleanup(pBlock);
×
UNCOV
932
  if (!hasRemainResults(pGroupResInfo)) {
×
UNCOV
933
    return;
×
934
  }
935

936
  // clear the existed group id
UNCOV
937
  pBlock->info.id.groupId = 0;
×
UNCOV
938
  if (!pbInfo->mergeResultBlock) {
×
UNCOV
939
    doCopyToSDataBlock(pTaskInfo, pBlock, &pOperator->exprSupp, pBuf, pGroupResInfo, pOperator->resultInfo.threshold,
×
940
                       false);
941
  } else {
UNCOV
942
    while (hasRemainResults(pGroupResInfo)) {
×
UNCOV
943
      doCopyToSDataBlock(pTaskInfo, pBlock, &pOperator->exprSupp, pBuf, pGroupResInfo, pOperator->resultInfo.threshold,
×
944
                         true);
UNCOV
945
      if (pBlock->info.rows >= pOperator->resultInfo.threshold) {
×
UNCOV
946
        break;
×
947
      }
948

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

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

UNCOV
958
void destroyExprInfo(SExprInfo* pExpr, int32_t numOfExprs) {
×
UNCOV
959
  for (int32_t i = 0; i < numOfExprs; ++i) {
×
UNCOV
960
    SExprInfo* pExprInfo = &pExpr[i];
×
UNCOV
961
    for (int32_t j = 0; j < pExprInfo->base.numOfParams; ++j) {
×
UNCOV
962
      if (pExprInfo->base.pParam[j].type == FUNC_PARAM_TYPE_COLUMN) {
×
UNCOV
963
        taosMemoryFreeClear(pExprInfo->base.pParam[j].pCol);
×
UNCOV
964
      } else if (pExprInfo->base.pParam[j].type == FUNC_PARAM_TYPE_VALUE) {
×
UNCOV
965
        taosVariantDestroy(&pExprInfo->base.pParam[j].param);
×
966
      }
967
    }
968

UNCOV
969
    taosMemoryFree(pExprInfo->base.pParam);
×
UNCOV
970
    taosMemoryFree(pExprInfo->pExpr);
×
971
  }
UNCOV
972
}
×
973

UNCOV
974
int32_t getBufferPgSize(int32_t rowSize, uint32_t* defaultPgsz, int64_t* defaultBufsz) {
×
UNCOV
975
  *defaultPgsz = 4096;
×
UNCOV
976
  uint32_t last = *defaultPgsz;
×
UNCOV
977
  while (*defaultPgsz < rowSize * 4) {
×
UNCOV
978
    *defaultPgsz <<= 1u;
×
UNCOV
979
    if (*defaultPgsz < last) {
×
980
      return TSDB_CODE_INVALID_PARA;
×
981
    }
UNCOV
982
    last = *defaultPgsz;
×
983
  }
984

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

UNCOV
996
  return 0;
×
997
}
998

UNCOV
999
void initResultSizeInfo(SResultInfo* pResultInfo, int32_t numOfRows) {
×
UNCOV
1000
  if (numOfRows == 0) {
×
1001
    numOfRows = 4096;
×
1002
  }
1003

UNCOV
1004
  pResultInfo->capacity = numOfRows;
×
UNCOV
1005
  pResultInfo->threshold = numOfRows * 0.75;
×
1006

UNCOV
1007
  if (pResultInfo->threshold == 0) {
×
UNCOV
1008
    pResultInfo->threshold = numOfRows;
×
1009
  }
UNCOV
1010
}
×
1011

UNCOV
1012
void initBasicInfo(SOptrBasicInfo* pInfo, SSDataBlock* pBlock) {
×
UNCOV
1013
  pInfo->pRes = pBlock;
×
UNCOV
1014
  initResultRowInfo(&pInfo->resultRowInfo);
×
UNCOV
1015
}
×
1016

UNCOV
1017
static void destroySqlFunctionCtx(SqlFunctionCtx* pCtx, SExprInfo* pExpr, int32_t numOfOutput) {
×
UNCOV
1018
  if (pCtx == NULL) {
×
UNCOV
1019
    return;
×
1020
  }
1021

UNCOV
1022
  for (int32_t i = 0; i < numOfOutput; ++i) {
×
UNCOV
1023
    if (pExpr != NULL) {
×
UNCOV
1024
      SExprInfo* pExprInfo = &pExpr[i];
×
UNCOV
1025
      for (int32_t j = 0; j < pExprInfo->base.numOfParams; ++j) {
×
UNCOV
1026
        if (pExprInfo->base.pParam[j].type == FUNC_PARAM_TYPE_VALUE) {
×
UNCOV
1027
          taosMemoryFree(pCtx[i].input.pData[j]);
×
UNCOV
1028
          taosMemoryFree(pCtx[i].input.pColumnDataAgg[j]);
×
1029
        }
1030
      }
1031
    }
UNCOV
1032
    for (int32_t j = 0; j < pCtx[i].numOfParams; ++j) {
×
UNCOV
1033
      taosVariantDestroy(&pCtx[i].param[j].param);
×
1034
    }
1035

UNCOV
1036
    taosMemoryFreeClear(pCtx[i].subsidiaries.pCtx);
×
UNCOV
1037
    taosMemoryFreeClear(pCtx[i].subsidiaries.buf);
×
UNCOV
1038
    taosMemoryFree(pCtx[i].input.pData);
×
UNCOV
1039
    taosMemoryFree(pCtx[i].input.pColumnDataAgg);
×
1040

UNCOV
1041
    if (pCtx[i].udfName != NULL) {
×
UNCOV
1042
      taosMemoryFree(pCtx[i].udfName);
×
1043
    }
1044
  }
1045

UNCOV
1046
  taosMemoryFreeClear(pCtx);
×
UNCOV
1047
  return;
×
1048
}
1049

UNCOV
1050
int32_t initExprSupp(SExprSupp* pSup, SExprInfo* pExprInfo, int32_t numOfExpr, SFunctionStateStore* pStore) {
×
UNCOV
1051
  pSup->pExprInfo = pExprInfo;
×
UNCOV
1052
  pSup->numOfExprs = numOfExpr;
×
UNCOV
1053
  if (pSup->pExprInfo != NULL) {
×
UNCOV
1054
    pSup->pCtx = createSqlFunctionCtx(pExprInfo, numOfExpr, &pSup->rowEntryInfoOffset, pStore);
×
UNCOV
1055
    if (pSup->pCtx == NULL) {
×
1056
      return terrno;
×
1057
    }
1058
  }
1059

UNCOV
1060
  return TSDB_CODE_SUCCESS;
×
1061
}
1062

UNCOV
1063
void cleanupExprSupp(SExprSupp* pSupp) {
×
UNCOV
1064
  destroySqlFunctionCtx(pSupp->pCtx, pSupp->pExprInfo, pSupp->numOfExprs);
×
UNCOV
1065
  if (pSupp->pExprInfo != NULL) {
×
UNCOV
1066
    destroyExprInfo(pSupp->pExprInfo, pSupp->numOfExprs);
×
UNCOV
1067
    taosMemoryFreeClear(pSupp->pExprInfo);
×
1068
  }
1069

UNCOV
1070
  if (pSupp->pFilterInfo != NULL) {
×
UNCOV
1071
    filterFreeInfo(pSupp->pFilterInfo);
×
UNCOV
1072
    pSupp->pFilterInfo = NULL;
×
1073
  }
1074

UNCOV
1075
  taosMemoryFree(pSupp->rowEntryInfoOffset);
×
UNCOV
1076
}
×
1077

UNCOV
1078
void cleanupBasicInfo(SOptrBasicInfo* pInfo) {
×
UNCOV
1079
  blockDataDestroy(pInfo->pRes);
×
UNCOV
1080
  pInfo->pRes = NULL;
×
UNCOV
1081
}
×
1082

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

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

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

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

UNCOV
1120
      STableListInfo* pTableListInfo = taosArrayGetP(pInfoList, 0);
×
UNCOV
1121
      taosArrayDestroy(pInfoList);
×
1122

UNCOV
1123
      pDeleterParam->suid = tableListGetSuid(pTableListInfo);
×
1124

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

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

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

UNCOV
1155
      *pParam = pDeleterParam;
×
UNCOV
1156
      break;
×
1157
    }
UNCOV
1158
    default:
×
UNCOV
1159
      break;
×
1160
  }
1161

UNCOV
1162
  return TSDB_CODE_SUCCESS;
×
1163
}
1164

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

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

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

UNCOV
1186
  taosArrayDestroy(pParam->pChildren);
×
1187

UNCOV
1188
  taosMemoryFree(pParam->value);
×
1189

UNCOV
1190
  taosMemoryFree(pParam);
×
UNCOV
1191
}
×
1192

UNCOV
1193
void freeExchangeGetBasicOperatorParam(void* pParam) {
×
UNCOV
1194
  SExchangeOperatorBasicParam* pBasic = (SExchangeOperatorBasicParam*)pParam;
×
UNCOV
1195
  taosArrayDestroy(pBasic->uidList);
×
UNCOV
1196
}
×
1197

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

UNCOV
1207
  freeOperatorParamImpl(pParam, OP_GET_PARAM);
×
UNCOV
1208
}
×
1209

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

UNCOV
1212
void freeGroupCacheGetOperatorParam(SOperatorParam* pParam) { freeOperatorParamImpl(pParam, OP_GET_PARAM); }
×
1213

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

UNCOV
1216
void freeMergeJoinGetOperatorParam(SOperatorParam* pParam) { freeOperatorParamImpl(pParam, OP_GET_PARAM); }
×
1217

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

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

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

UNCOV
1228
void freeOperatorParam(SOperatorParam* pParam, SOperatorParamType type) {
×
UNCOV
1229
  if (NULL == pParam) {
×
UNCOV
1230
    return;
×
1231
  }
1232

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

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

UNCOV
1268
  if (*ppParam) {
×
UNCOV
1269
    freeOperatorParam(*ppParam, type);
×
UNCOV
1270
    *ppParam = NULL;
×
1271
  }
1272

UNCOV
1273
  if (*pppDownstramParam) {
×
UNCOV
1274
    for (int32_t i = 0; i < pOperator->numOfDownstream; ++i) {
×
UNCOV
1275
      if ((*pppDownstramParam)[i]) {
×
1276
        freeOperatorParam((*pppDownstramParam)[i], type);
×
1277
        (*pppDownstramParam)[i] = NULL;
×
1278
      }
1279
    }
UNCOV
1280
    if (allFree) {
×
UNCOV
1281
      taosMemoryFreeClear(*pppDownstramParam);
×
1282
    }
1283
  }
1284
}
1285

UNCOV
1286
FORCE_INLINE int32_t getNextBlockFromDownstreamImpl(struct SOperatorInfo* pOperator, int32_t idx, bool clearParam,
×
1287
                                                    SSDataBlock** pResBlock) {
UNCOV
1288
  QRY_PARAM_CHECK(pResBlock);
×
1289

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

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

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

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

© 2026 Coveralls, Inc