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

taosdata / TDengine / #3542

27 Nov 2024 02:52AM UTC coverage: 60.819% (+0.04%) from 60.776%
#3542

push

travis-ci

web-flow
Merge pull request #28931 from taosdata/enh/jdbc-demo-3.0

update jdbc demo, and version history

120305 of 252779 branches covered (47.59%)

Branch coverage included in aggregate %.

201010 of 275538 relevant lines covered (72.95%)

19989893.51 hits per line

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

69.59
/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) {
226,723,332✔
86
  SFilePage* pData = NULL;
226,723,332✔
87

88
  // in the first scan, new space needed for results
89
  int32_t pageId = -1;
226,723,332✔
90
  if (*currentPageId == -1) {
226,723,332✔
91
    pData = getNewBufPage(pResultBuf, &pageId);
5,045,926✔
92
    if (pData == NULL) {
5,046,333✔
93
      qError("failed to get buffer, code:%s", tstrerror(terrno));
97!
94
      return NULL;
×
95
    }
96
    pData->num = sizeof(SFilePage);
5,046,236✔
97
  } else {
98
    pData = getBufPage(pResultBuf, *currentPageId);
221,677,406✔
99
    if (pData == NULL) {
222,041,139!
100
      qError("failed to get buffer, code:%s", tstrerror(terrno));
×
101
      return NULL;
×
102
    }
103

104
    pageId = *currentPageId;
222,041,139✔
105

106
    if (pData->num + interBufSize > getBufPageSize(pResultBuf)) {
222,041,139✔
107
      // release current page first, and prepare the next one
108
      releaseBufPage(pResultBuf, pData);
17,170,358✔
109

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

119
  if (pData == NULL) {
227,236,803!
120
    return NULL;
×
121
  }
122

123
  setBufPageDirty(pData, true);
227,236,803✔
124

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

128
  memset((char*)pResultRow, 0, interBufSize);
226,818,661✔
129
  pResultRow->pageId = pageId;
226,818,661✔
130
  pResultRow->offset = (int32_t)pData->num;
226,818,661✔
131

132
  *currentPageId = pageId;
226,818,661✔
133
  pData->num += interBufSize;
226,818,661✔
134
  return pResultRow;
226,818,661✔
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,
285,854,112✔
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);
285,854,112✔
148
  if (!keepGroup) {
285,854,112✔
149
    *(uint64_t*)pSup->keyBuf = calcGroupId(pSup->keyBuf, GET_RES_WINDOW_KEY_LEN(bytes));
15,805,996✔
150
  }
151

152
  SResultRowPosition* p1 =
153
      (SResultRowPosition*)tSimpleHashGet(pSup->pResultRowHashTable, pSup->keyBuf, GET_RES_WINDOW_KEY_LEN(bytes));
286,121,321✔
154

155
  SResultRow* pResult = NULL;
285,578,387✔
156

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

166
      if (pResult->pageId != p1->pageId || pResult->offset != p1->offset) {
48,982,747!
167
        terrno = TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR;
×
168
        pTaskInfo->code = terrno;
×
169
        return NULL;
×
170
      }
171
    }
172
  } else {
173
    // In case of group by column query, the required SResultRow object must be existInCurrentResusltRowInfo in the
174
    // pResultRowInfo object.
175
    if (p1 != NULL) {
20,471,724✔
176
      // todo
177
      pResult = getResultRowByPos(pResultBuf, p1, true);
8,683,806✔
178
      if (NULL == pResult) {
8,683,806!
179
        pTaskInfo->code = terrno;
×
180
        return NULL;
×
181
      }
182

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

191
  // 1. close current opened time window
192
  if (pResultRowInfo->cur.pageId != -1 && ((pResult == NULL) || (pResult->pageId != pResultRowInfo->cur.pageId))) {
285,345,279✔
193
    SResultRowPosition pos = pResultRowInfo->cur;
227,276,788✔
194
    SFilePage*         pPage = getBufPage(pResultBuf, pos.pageId);
227,276,788✔
195
    if (pPage == NULL) {
226,807,350!
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);
226,807,350✔
201
  }
202

203
  // allocate a new buffer page
204
  if (pResult == NULL) {
283,968,306✔
205
    pResult = getNewResultRow(pResultBuf, &pSup->currentPageId, pSup->resultRowSize);
226,430,231✔
206
    if (pResult == NULL) {
226,746,506!
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};
226,746,506✔
213
    int32_t code = tSimpleHashPut(pSup->pResultRowHashTable, pSup->keyBuf, GET_RES_WINDOW_KEY_LEN(bytes), &pos,
226,746,506✔
214
                                  sizeof(SResultRowPosition));
215
    if (code != TSDB_CODE_SUCCESS) {
229,507,675✔
216
      qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(code));
64,706!
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};
286,981,044✔
224

225
  // too many time window in query
226
  if (pTaskInfo->execModel == OPTR_EXEC_MODEL_BATCH &&
573,418,538!
227
      tSimpleHashGetSize(pSup->pResultRowHashTable) > MAX_INTERVAL_TIME_WINDOW) {
286,912,861✔
228
    pTaskInfo->code = TSDB_CODE_QRY_TOO_MANY_TIMEWINDOW;
×
229
    return NULL;
×
230
  }
231

232
  return pResult;
286,505,677✔
233
}
234

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

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

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

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

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

274
int32_t setInputDataBlock(SExprSupp* pExprSup, SSDataBlock* pBlock, int32_t order, int32_t scanFlag,
28,337,538✔
275
                          bool createDummyCol) {
276
  if (pBlock->pBlockAgg != NULL) {
28,337,538✔
277
    return doSetInputDataBlockInfo(pExprSup, pBlock, order, scanFlag);
2,576,129✔
278
  } else {
279
    return doSetInputDataBlock(pExprSup, pBlock, order, scanFlag, createDummyCol);
25,761,409✔
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,
25,761,140✔
335
                                   bool createDummyCol) {
336
  int32_t         code = TSDB_CODE_SUCCESS;
25,761,140✔
337
  int32_t         lino = 0;
25,761,140✔
338
  SqlFunctionCtx* pCtx = pExprSup->pCtx;
25,761,140✔
339

340
  for (int32_t i = 0; i < pExprSup->numOfExprs; ++i) {
92,457,081✔
341
    pCtx[i].order = order;
66,700,403✔
342
    pCtx[i].input.numOfRows = pBlock->info.rows;
66,700,403✔
343

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

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

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

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

358
    for (int32_t j = 0; j < pOneExpr->base.numOfParams; ++j) {
142,897,045✔
359
      SFunctParam* pFuncParam = &pOneExpr->base.pParam[j];
76,201,104✔
360
      if (pFuncParam->type == FUNC_PARAM_TYPE_COLUMN) {
76,201,104✔
361
        int32_t slotId = pFuncParam->pCol->slotId;
65,467,227✔
362
        pInput->pData[j] = taosArrayGet(pBlock->pDataBlock, slotId);
65,467,227✔
363
        pInput->totalRows = pBlock->info.rows;
65,464,852✔
364
        pInput->numOfRows = pBlock->info.rows;
65,464,852✔
365
        pInput->startRowIndex = 0;
65,464,852✔
366
        pInput->blankFill = pBlock->info.blankFill;
65,464,852✔
367

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

371
        if (fmIsImplicitTsFunc(pCtx[i].functionId) && (j == tsParamIdx)) {
65,464,852✔
372
          pInput->pPTS = pInput->pData[j];  // in case of merge function, this is not always the ts column data.
5,982,789✔
373
        }
374
        if (hasPk && (j == pkParamIdx)) {
65,462,765✔
375
          pInput->pPrimaryKey = pInput->pData[j];
981,799✔
376
        }
377
        QUERY_CHECK_CONDITION((pInput->pData[j] != NULL), code, lino, _end, TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR);
65,462,765!
378
      } else if (pFuncParam->type == FUNC_PARAM_TYPE_VALUE) {
10,733,877✔
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) {
9,106,173!
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:
25,756,678✔
395
  if (code != TSDB_CODE_SUCCESS) {
25,756,678!
396
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
×
397
  }
398
  return code;
25,762,934✔
399
}
400

401
bool functionNeedToExecute(SqlFunctionCtx* pCtx) {
966,148,178✔
402
  struct SResultRowEntryInfo* pResInfo = GET_RES_INFO(pCtx);
966,148,178✔
403

404
  // in case of timestamp column, always generated results.
405
  int32_t functionId = pCtx->functionId;
966,148,178✔
406
  if (functionId == -1) {
966,148,178✔
407
    return false;
50,072,114✔
408
  }
409

410
  if (pCtx->scanFlag == PRE_SCAN) {
916,076,064✔
411
    return fmIsRepeatScanFunc(pCtx->functionId);
1,654,152✔
412
  }
413

414
  if (isRowEntryCompleted(pResInfo)) {
914,421,912✔
415
    return false;
7,034✔
416
  }
417

418
  return true;
914,414,878✔
419
}
420

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

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

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

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

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

486
    for (int32_t j = 0; j < pExprInfo->base.numOfParams; ++j) {
7,248,392✔
487
      SFunctParam* pFuncParam = &pExprInfo->base.pParam[j];
4,672,255✔
488

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

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

515
/////////////////////////////////////////////////////////////////////////////////////////////
516
STimeWindow getAlignQueryTimeWindow(const SInterval* pInterval, int64_t key) {
2,560,069✔
517
  STimeWindow win = {0};
2,560,069✔
518
  win.skey = taosTimeTruncate(key, pInterval);
2,560,069✔
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);
2,560,106✔
525
  if (win.ekey < win.skey) {
2,560,093✔
526
    win.ekey = INT64_MAX;
2,116✔
527
  }
528

529
  return win;
2,560,093✔
530
}
531

532
int32_t setResultRowInitCtx(SResultRow* pResult, SqlFunctionCtx* pCtx, int32_t numOfOutput,
447,720,367✔
533
                            int32_t* rowEntryInfoOffset) {
534
  bool init = false;
447,720,367✔
535
  for (int32_t i = 0; i < numOfOutput; ++i) {
1,687,124,835✔
536
    pCtx[i].resultInfo = getResultEntryInfo(pResult, i, rowEntryInfoOffset);
1,240,940,520✔
537
    if (init) {
1,241,178,588✔
538
      continue;
126,897,186✔
539
    }
540

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

546
    if (pCtx[i].isPseudoFunc) {
1,114,281,402✔
547
      continue;
272,720,256✔
548
    }
549

550
    if (!pResInfo->initialized) {
841,561,146✔
551
      if (pCtx[i].functionId != -1) {
789,767,676✔
552
        int32_t code = pCtx[i].fpSet.init(&pCtx[i], pResInfo);
753,387,390✔
553
        if (code != TSDB_CODE_SUCCESS && fmIsUserDefinedFunc(pCtx[i].functionId)) {
753,726,575!
554
          pResInfo->initialized = false;
44✔
555
          return TSDB_CODE_UDF_FUNC_EXEC_FAILURE;
44✔
556
        } else if (code != TSDB_CODE_SUCCESS) {
751,613,270!
557
          return code;
×
558
        }
559
      } else {
560
        pResInfo->initialized = true;
36,380,286✔
561
      }
562
    } else {
563
      init = true;
51,793,470✔
564
    }
565
  }
566
  return TSDB_CODE_SUCCESS;
446,184,315✔
567
}
568

569
void clearResultRowInitFlag(SqlFunctionCtx* pCtx, int32_t numOfOutput) {
86,472,932✔
570
  for (int32_t i = 0; i < numOfOutput; ++i) {
219,483,084✔
571
    SResultRowEntryInfo* pResInfo = pCtx[i].resultInfo;
133,010,152✔
572
    if (pResInfo == NULL) {
133,010,152!
573
      continue;
×
574
    }
575

576
    pResInfo->initialized = false;
133,010,152✔
577
    pResInfo->numOfRes = 0;
133,010,152✔
578
    pResInfo->isNullRes = 0;
133,010,152✔
579
    pResInfo->complete = false;
133,010,152✔
580
  }
581
}
86,472,932✔
582

583
int32_t doFilter(SSDataBlock* pBlock, SFilterInfo* pFilterInfo, SColMatchInfo* pColMatchInfo) {
35,922,016✔
584
  int32_t code = TSDB_CODE_SUCCESS;
35,922,016✔
585
  int32_t lino = 0;
35,922,016✔
586
  if (pFilterInfo == NULL || pBlock->info.rows == 0) {
35,922,016✔
587
    return TSDB_CODE_SUCCESS;
30,415,108✔
588
  }
589

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

593
  code = filterSetDataFromSlotId(pFilterInfo, &param1);
5,506,792✔
594
  QUERY_CHECK_CODE(code, lino, _err);
5,506,596!
595

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

600
  code = extractQualifiedTupleByFilterResult(pBlock, p, status);
5,506,888✔
601
  QUERY_CHECK_CODE(code, lino, _err);
5,506,660!
602

603
  if (pColMatchInfo != NULL) {
5,506,660✔
604
    size_t size = taosArrayGetSize(pColMatchInfo->pList);
4,542,516✔
605
    for (int32_t i = 0; i < size; ++i) {
4,547,823✔
606
      SColMatchItem* pInfo = taosArrayGet(pColMatchInfo->pList, i);
4,545,431✔
607
      QUERY_CHECK_NULL(pInfo, code, lino, _err, terrno);
4,545,397!
608
      if (pInfo->colId == PRIMARYKEY_TIMESTAMP_COL_ID) {
4,545,397✔
609
        SColumnInfoData* pColData = taosArrayGet(pBlock->pDataBlock, pInfo->dstSlotId);
4,540,132✔
610
        QUERY_CHECK_NULL(pColData, code, lino, _err, terrno);
4,540,083!
611
        if (pColData->info.type == TSDB_DATA_TYPE_TIMESTAMP) {
4,540,114✔
612
          code = blockDataUpdateTsWindow(pBlock, pInfo->dstSlotId);
4,540,098✔
613
          QUERY_CHECK_CODE(code, lino, _err);
4,540,120!
614
          break;
4,540,120✔
615
        }
616
      }
617
    }
618
  }
619
  code = blockDataCheck(pBlock);
5,506,656✔
620
  QUERY_CHECK_CODE(code, lino, _err);
5,506,663!
621
_err:
5,506,663✔
622
  if (code != TSDB_CODE_SUCCESS) {
5,506,664✔
623
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
1!
624
  }
625
  colDataDestroy(p);
5,506,664✔
626
  taosMemoryFree(p);
5,507,097✔
627
  return code;
5,507,030✔
628
}
629

630
int32_t extractQualifiedTupleByFilterResult(SSDataBlock* pBlock, const SColumnInfoData* p, int32_t status) {
5,506,934✔
631
  int32_t code = TSDB_CODE_SUCCESS;
5,506,934✔
632
  int8_t* pIndicator = (int8_t*)p->pData;
5,506,934✔
633
  if (status == FILTER_RESULT_ALL_QUALIFIED) {
5,506,934✔
634
    // here nothing needs to be done
635
  } else if (status == FILTER_RESULT_NONE_QUALIFIED) {
1,129,222✔
636
    code = trimDataBlock(pBlock, pBlock->info.rows, NULL);
752,903✔
637
    pBlock->info.rows = 0;
752,817✔
638
  } else if (status == FILTER_RESULT_PARTIAL_QUALIFIED) {
376,319!
639
    code = trimDataBlock(pBlock, pBlock->info.rows, (bool*)pIndicator);
376,338✔
640
  } else {
641
    qError("unknown filter result type: %d", status);
×
642
  }
643
  return code;
5,506,926✔
644
}
645

646
void doUpdateNumOfRows(SqlFunctionCtx* pCtx, SResultRow* pRow, int32_t numOfExprs, const int32_t* rowEntryOffset) {
390,295,672✔
647
  bool returnNotNull = false;
390,295,672✔
648
  for (int32_t j = 0; j < numOfExprs; ++j) {
1,417,844,900✔
649
    SResultRowEntryInfo* pResInfo = getResultEntryInfo(pRow, j, rowEntryOffset);
1,027,413,044✔
650
    if (!isRowEntryInitialized(pResInfo)) {
1,027,549,228✔
651
      continue;
224,734,540✔
652
    } else {
653
    }
654

655
    if (pRow->numOfRows < pResInfo->numOfRes) {
802,814,688✔
656
      pRow->numOfRows = pResInfo->numOfRes;
386,871,643✔
657
    }
658

659
    if (pCtx[j].isNotNullFunc) {
802,814,688✔
660
      returnNotNull = true;
228,482,880✔
661
    }
662
  }
663
  // if all expr skips all blocks, e.g. all null inputs for max function, output one row in final result.
664
  //  except for first/last, which require not null output, output no rows
665
  if (pRow->numOfRows == 0 && !returnNotNull) {
390,431,856✔
666
    pRow->numOfRows = 1;
26,165✔
667
  }
668
}
390,431,856✔
669

670
int32_t copyResultrowToDataBlock(SExprInfo* pExprInfo, int32_t numOfExprs, SResultRow* pRow, SqlFunctionCtx* pCtx,
380,448,998✔
671
                                 SSDataBlock* pBlock, const int32_t* rowEntryOffset, SExecTaskInfo* pTaskInfo) {
672
  int32_t code = TSDB_CODE_SUCCESS;
380,448,998✔
673
  int32_t lino = 0;
380,448,998✔
674
  for (int32_t j = 0; j < numOfExprs; ++j) {
1,340,186,840✔
675
    int32_t slotId = pExprInfo[j].base.resSchema.slotId;
959,134,096✔
676

677
    pCtx[j].resultInfo = getResultEntryInfo(pRow, j, rowEntryOffset);
959,134,096✔
678
    if (pCtx[j].fpSet.finalize) {
959,266,855✔
679
      if (strcmp(pCtx[j].pExpr->pExpr->_function.functionName, "_group_key") == 0 ||
582,730,528✔
680
          strcmp(pCtx[j].pExpr->pExpr->_function.functionName, "_group_const_value") == 0) {
486,982,852✔
681
        // for groupkey along with functions that output multiple lines(e.g. Histogram)
682
        // need to match groupkey result for each output row of that function.
683
        if (pCtx[j].resultInfo->numOfRes != 0) {
95,998,429!
684
          pCtx[j].resultInfo->numOfRes = pRow->numOfRows;
97,434,204✔
685
        }
686
      }
687

688
      code = blockDataEnsureCapacity(pBlock, pBlock->info.rows + pCtx[j].resultInfo->numOfRes);
582,730,528✔
689
      QUERY_CHECK_CODE(code, lino, _end);
583,013,093!
690

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

711
_end:
381,052,744✔
712
  if (code != TSDB_CODE_SUCCESS) {
381,052,744!
713
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
×
714
  }
715
  return code;
382,080,330✔
716
}
717

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

727
  SResultRow* pRow = (SResultRow*)((char*)page + resultRowPosition->offset);
69,837,030✔
728

729
  SqlFunctionCtx* pCtx = pSup->pCtx;
69,837,030✔
730
  SExprInfo*      pExprInfo = pSup->pExprInfo;
69,837,030✔
731
  const int32_t*  rowEntryOffset = pSup->rowEntryInfoOffset;
69,837,030✔
732

733
  doUpdateNumOfRows(pCtx, pRow, pSup->numOfExprs, rowEntryOffset);
69,837,030✔
734
  if (pRow->numOfRows == 0) {
69,817,606!
735
    releaseBufPage(pBuf, page);
×
736
    return;
×
737
  }
738

739
  int32_t size = pBlock->info.capacity;
69,820,007✔
740
  while (pBlock->info.rows + pRow->numOfRows > size) {
69,918,518✔
741
    size = size * 1.25;
98,511✔
742
  }
743

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

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

758
  releaseBufPage(pBuf, page);
69,814,861✔
759
  pBlock->info.rows += pRow->numOfRows;
69,800,438✔
760
}
761

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

771
  size_t  keyLen = 0;
2,072,833✔
772
  int32_t numOfRows = tSimpleHashGetSize(pHashmap);
2,072,833✔
773

774
  // begin from last iter
775
  void*   pData = pGroupResInfo->dataPos;
2,067,246✔
776
  int32_t iter = pGroupResInfo->iter;
2,067,246✔
777
  while ((pData = tSimpleHashIterate(pHashmap, pData, &iter)) != NULL) {
9,517,331✔
778
    void*               key = tSimpleHashGetKey(pData, &keyLen);
9,176,997✔
779
    SResultRowPosition* pos = pData;
9,176,997✔
780
    uint64_t            groupId = *(uint64_t*)key;
9,176,997✔
781

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

788
    SResultRow* pRow = (SResultRow*)((char*)page + pos->offset);
9,172,747✔
789

790
    doUpdateNumOfRows(pCtx, pRow, numOfExprs, rowEntryOffset);
9,172,747✔
791

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

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

802
    if (!ignoreGroup) {
9,123,674✔
803
      if (pBlock->info.id.groupId == 0) {
3,452,283✔
804
        pBlock->info.id.groupId = groupId;
1,768,014✔
805
      } else {
806
        // current value belongs to different group, it can't be packed into one datablock
807
        if (pBlock->info.id.groupId != groupId) {
1,684,269!
808
          releaseBufPage(pBuf, page);
1,706,975✔
809
          break;
1,708,003✔
810
        }
811
      }
812
    }
813

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

823
    pGroupResInfo->index += 1;
7,416,699✔
824
    pGroupResInfo->iter = iter;
7,416,699✔
825
    pGroupResInfo->dataPos = pData;
7,416,699✔
826

827
    code = copyResultrowToDataBlock(pExprInfo, numOfExprs, pRow, pCtx, pBlock, rowEntryOffset, pTaskInfo);
7,416,699✔
828
    releaseBufPage(pBuf, page);
7,453,048✔
829
    QUERY_CHECK_CODE(code, lino, _end);
7,450,125!
830
    pBlock->info.rows += pRow->numOfRows;
7,450,125✔
831
    if (pBlock->info.rows >= threshold) {
7,450,125✔
832
      break;
40✔
833
    }
834
  }
835

836
  qDebug("%s result generated, rows:%" PRId64 ", groupId:%" PRIu64, GET_TASKID(pTaskInfo), pBlock->info.rows,
2,037,824✔
837
         pBlock->info.id.groupId);
838
  pBlock->info.dataLoad = 1;
2,037,825✔
839
  code = blockDataUpdateTsWindow(pBlock, 0);
2,037,825✔
840
  QUERY_CHECK_CODE(code, lino, _end);
2,038,152!
841

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

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

858
  int32_t numOfRows = getNumOfTotalRes(pGroupResInfo);
3,046,462✔
859

860
  for (int32_t i = pGroupResInfo->index; i < numOfRows; i += 1) {
220,474,181✔
861
    SResKeyPos* pPos = taosArrayGetP(pGroupResInfo->pRows, i);
218,042,576✔
862
    SFilePage*  page = getBufPage(pBuf, pPos->pos.pageId);
218,121,106✔
863
    if (page == NULL) {
218,041,479!
864
      qError("failed to get buffer, code:%s, %s", tstrerror(terrno), GET_TASKID(pTaskInfo));
×
865
      T_LONG_JMP(pTaskInfo->env, terrno);
×
866
    }
867

868
    SResultRow* pRow = (SResultRow*)((char*)page + pPos->pos.offset);
218,041,479✔
869

870
    doUpdateNumOfRows(pCtx, pRow, numOfExprs, rowEntryOffset);
218,041,479✔
871

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

879
    if (!ignoreGroup) {
216,436,613✔
880
      if (pBlock->info.id.groupId == 0) {
144,816,644✔
881
        pBlock->info.id.groupId = pPos->groupId;
126,933,183✔
882
      } else {
883
        // current value belongs to different group, it can't be packed into one datablock
884
        if (pBlock->info.id.groupId != pPos->groupId) {
17,883,461✔
885
          releaseBufPage(pBuf, page);
134,748✔
886
          break;
134,746✔
887
        }
888
      }
889
    }
890

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

900
    pGroupResInfo->index += 1;
216,301,865✔
901
    code = copyResultrowToDataBlock(pExprInfo, numOfExprs, pRow, pCtx, pBlock, rowEntryOffset, pTaskInfo);
216,301,865✔
902
    releaseBufPage(pBuf, page);
218,724,966✔
903
    QUERY_CHECK_CODE(code, lino, _end);
217,898,245!
904

905
    pBlock->info.rows += pRow->numOfRows;
217,898,245✔
906
    if (pBlock->info.rows >= threshold) {
217,898,245✔
907
      break;
471,508✔
908
    }
909
  }
910

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

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

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

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

932
  blockDataCleanup(pBlock);
4,006,149✔
933
  if (!hasRemainResults(pGroupResInfo)) {
4,006,681✔
934
    return;
959,648✔
935
  }
936

937
  // clear the existed group id
938
  pBlock->info.id.groupId = 0;
3,046,877✔
939
  if (!pbInfo->mergeResultBlock) {
3,046,877✔
940
    doCopyToSDataBlock(pTaskInfo, pBlock, &pOperator->exprSupp, pBuf, pGroupResInfo, pOperator->resultInfo.threshold,
1,869,204✔
941
                       false);
942
  } else {
943
    while (hasRemainResults(pGroupResInfo)) {
2,132,991✔
944
      doCopyToSDataBlock(pTaskInfo, pBlock, &pOperator->exprSupp, pBuf, pGroupResInfo, pOperator->resultInfo.threshold,
1,177,376✔
945
                         true);
946
      if (pBlock->info.rows >= pOperator->resultInfo.threshold) {
1,177,440✔
947
        break;
222,122✔
948
      }
949

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

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

959
void destroyExprInfo(SExprInfo* pExpr, int32_t numOfExprs) {
10,201,318✔
960
  for (int32_t i = 0; i < numOfExprs; ++i) {
41,004,183✔
961
    SExprInfo* pExprInfo = &pExpr[i];
30,802,509✔
962
    for (int32_t j = 0; j < pExprInfo->base.numOfParams; ++j) {
63,475,043✔
963
      if (pExprInfo->base.pParam[j].type == FUNC_PARAM_TYPE_COLUMN) {
32,681,554✔
964
        taosMemoryFreeClear(pExprInfo->base.pParam[j].pCol);
29,351,575✔
965
      } else if (pExprInfo->base.pParam[j].type == FUNC_PARAM_TYPE_VALUE) {
3,329,979✔
966
        taosVariantDestroy(&pExprInfo->base.pParam[j].param);
2,521,241✔
967
      }
968
    }
969

970
    taosMemoryFree(pExprInfo->base.pParam);
30,793,489✔
971
    taosMemoryFree(pExprInfo->pExpr);
30,790,408✔
972
  }
973
}
10,201,674✔
974

975
int32_t getBufferPgSize(int32_t rowSize, uint32_t* defaultPgsz, uint32_t* defaultBufsz) {
6,572,382✔
976
  *defaultPgsz = 4096;
6,572,382✔
977
  uint32_t last = *defaultPgsz;
6,572,382✔
978
  while (*defaultPgsz < rowSize * 4) {
7,997,219✔
979
    *defaultPgsz <<= 1u;
1,424,837✔
980
    if (*defaultPgsz < last) {
1,424,837!
981
      return TSDB_CODE_INVALID_PARA;
×
982
    }
983
    last = *defaultPgsz;
1,424,837✔
984
  }
985

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

997
  return 0;
6,572,382✔
998
}
999

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

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

1008
  if (pResultInfo->threshold == 0) {
15,603,647✔
1009
    pResultInfo->threshold = numOfRows;
301,995✔
1010
  }
1011
}
15,603,647✔
1012

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

1018
static void destroySqlFunctionCtx(SqlFunctionCtx* pCtx, SExprInfo* pExpr, int32_t numOfOutput) {
30,326,822✔
1019
  if (pCtx == NULL) {
30,326,822✔
1020
    return;
19,253,884✔
1021
  }
1022

1023
  for (int32_t i = 0; i < numOfOutput; ++i) {
41,593,128✔
1024
    if (pExpr != NULL) {
30,521,176✔
1025
      SExprInfo* pExprInfo = &pExpr[i];
30,520,333✔
1026
      for (int32_t j = 0; j < pExprInfo->base.numOfParams; ++j) {
62,919,769✔
1027
        if (pExprInfo->base.pParam[j].type == FUNC_PARAM_TYPE_VALUE) {
32,397,529✔
1028
          taosMemoryFree(pCtx[i].input.pData[j]);
2,517,227✔
1029
          taosMemoryFree(pCtx[i].input.pColumnDataAgg[j]);
2,517,160✔
1030
        }
1031
      }
1032
    }
1033
    for (int32_t j = 0; j < pCtx[i].numOfParams; ++j) {
62,909,626✔
1034
      taosVariantDestroy(&pCtx[i].param[j].param);
32,390,325✔
1035
    }
1036

1037
    taosMemoryFreeClear(pCtx[i].subsidiaries.pCtx);
30,519,301✔
1038
    taosMemoryFreeClear(pCtx[i].subsidiaries.buf);
30,519,364✔
1039
    taosMemoryFree(pCtx[i].input.pData);
30,519,364✔
1040
    taosMemoryFree(pCtx[i].input.pColumnDataAgg);
30,529,140✔
1041

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

1047
  taosMemoryFreeClear(pCtx);
11,071,952!
1048
  return;
11,072,258✔
1049
}
1050

1051
int32_t initExprSupp(SExprSupp* pSup, SExprInfo* pExprInfo, int32_t numOfExpr, SFunctionStateStore* pStore) {
10,241,917✔
1052
  pSup->pExprInfo = pExprInfo;
10,241,917✔
1053
  pSup->numOfExprs = numOfExpr;
10,241,917✔
1054
  if (pSup->pExprInfo != NULL) {
10,241,917✔
1055
    pSup->pCtx = createSqlFunctionCtx(pExprInfo, numOfExpr, &pSup->rowEntryInfoOffset, pStore);
8,173,882✔
1056
    if (pSup->pCtx == NULL) {
8,173,117!
1057
      return TSDB_CODE_OUT_OF_MEMORY;
×
1058
    }
1059
  }
1060

1061
  return TSDB_CODE_SUCCESS;
10,241,152✔
1062
}
1063

1064
void cleanupExprSupp(SExprSupp* pSupp) {
30,326,992✔
1065
  destroySqlFunctionCtx(pSupp->pCtx, pSupp->pExprInfo, pSupp->numOfExprs);
30,326,992✔
1066
  if (pSupp->pExprInfo != NULL) {
30,326,096✔
1067
    destroyExprInfo(pSupp->pExprInfo, pSupp->numOfExprs);
10,196,051✔
1068
    taosMemoryFreeClear(pSupp->pExprInfo);
10,196,017!
1069
  }
1070

1071
  if (pSupp->pFilterInfo != NULL) {
30,326,217✔
1072
    filterFreeInfo(pSupp->pFilterInfo);
2,989,713✔
1073
    pSupp->pFilterInfo = NULL;
2,989,706✔
1074
  }
1075

1076
  taosMemoryFree(pSupp->rowEntryInfoOffset);
30,326,210✔
1077
}
30,322,771✔
1078

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

1084
bool groupbyTbname(SNodeList* pGroupList) {
4,757,453✔
1085
  bool bytbname = false;
4,757,453✔
1086
  SNode*pNode = NULL;
4,757,453✔
1087
  FOREACH(pNode, pGroupList) {
4,851,182✔
1088
    if (pNode->type == QUERY_NODE_FUNCTION) {
403,158✔
1089
      bytbname = (strcmp(((struct SFunctionNode*)pNode)->functionName, "tbname") == 0);
309,429✔
1090
      break;
309,429✔
1091
    }
1092
  }
1093
  return bytbname;
4,757,453✔
1094
}
1095

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

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

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

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

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

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

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

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

1156
      *pParam = pDeleterParam;
60,157✔
1157
      break;
60,157✔
1158
    }
1159
    default:
8,293,568✔
1160
      break;
8,293,568✔
1161
  }
1162

1163
  return TSDB_CODE_SUCCESS;
8,353,894✔
1164
}
1165

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

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

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

1187
  taosArrayDestroy(pParam->pChildren);
106,114✔
1188

1189
  taosMemoryFree(pParam->value);
106,114✔
1190

1191
  taosMemoryFree(pParam);
106,114✔
1192
}
106,114✔
1193

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

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

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

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

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

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

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

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

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

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

1229
void freeOperatorParam(SOperatorParam* pParam, SOperatorParamType type) {
5,772,113✔
1230
  if (NULL == pParam) {
5,772,113✔
1231
    return;
5,666,085✔
1232
  }
1233

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

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

1269
  if (*ppParam) {
39,059,978✔
1270
    freeOperatorParam(*ppParam, type);
34,488✔
1271
    *ppParam = NULL;
34,488✔
1272
  }
1273

1274
  if (*pppDownstramParam) {
39,059,978✔
1275
    for (int32_t i = 0; i < pOperator->numOfDownstream; ++i) {
105,098✔
1276
      if ((*pppDownstramParam)[i]) {
68,976!
1277
        freeOperatorParam((*pppDownstramParam)[i], type);
×
1278
        (*pppDownstramParam)[i] = NULL;
×
1279
      }
1280
    }
1281
    if (allFree) {
36,122✔
1282
      taosMemoryFreeClear(*pppDownstramParam);
1,883!
1283
    }
1284
  }
1285
}
1286

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

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

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

1307
  code = pOperator->pDownstream[idx]->fpSet.getNextFn(pOperator->pDownstream[idx], pResBlock);
36,303,028✔
1308
  if (code) {
36,311,293✔
1309
    qError("failed to get next data block from upstream at %s, %d code:%s", __func__, __LINE__, tstrerror(code));
1!
1310
  }
1311
  return code;
36,311,568✔
1312
}
1313

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

© 2025 Coveralls, Inc