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

taosdata / TDengine / #5053

13 May 2026 12:00PM UTC coverage: 73.397% (+0.06%) from 73.338%
#5053

push

travis-ci

web-flow
feat: taosdump support stream backup/restore (#35326)

139 of 170 new or added lines in 3 files covered. (81.76%)

627 existing lines in 131 files now uncovered.

281694 of 383795 relevant lines covered (73.4%)

132505311.38 hits per line

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

76.9
/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 "../../function/inc/functionResInfoInt.h"
20
#include "os.h"
21
#include "querynodes.h"
22
#include "tfill.h"
23
#include "tname.h"
24

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

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

39
#define SET_REVERSE_SCAN_FLAG(runtime)    ((runtime)->scanFlag = REVERSE_SCAN)
40
#define GET_FORWARD_DIRECTION_FACTOR(ord) (((ord) != TSDB_ORDER_DESC) ? QUERY_ASC_FORWARD_STEP : QUERY_DESC_FORWARD_STEP)
41

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

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

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

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

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

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

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

81
static int32_t doSetInputDataBlock(SExprSupp* pExprSup, SSDataBlock* pBlock, int32_t order, int32_t scanFlag,
82
                                   bool createDummyCol);
83

84
SResultRow* getNewResultRow(SDiskbasedBuf* pResultBuf, int32_t* currentPageId, int32_t interBufSize) {
2,147,483,647✔
85
  SFilePage* pData = NULL;
2,147,483,647✔
86

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

103
    pageId = *currentPageId;
2,147,483,647✔
104

105
    if (pData->num + interBufSize > getBufPageSize(pResultBuf)) {
2,147,483,647✔
106
      // release current page first, and prepare the next one
107
      releaseBufPage(pResultBuf, pData);
1,015,786,557✔
108

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

118
  setBufPageDirty(pData, true);
2,147,483,647✔
119

120
  // set the number of rows in current disk page
121
  SResultRow* pResultRow = (SResultRow*)((char*)pData + pData->num);
2,147,483,647✔
122

123
  memset((char*)pResultRow, 0, interBufSize);
2,147,483,647✔
124
  pResultRow->pageId = pageId;
2,147,483,647✔
125
  pResultRow->offset = (int32_t)pData->num;
2,147,483,647✔
126

127
  *currentPageId = pageId;
2,147,483,647✔
128
  pData->num += interBufSize;
2,147,483,647✔
129
  return pResultRow;
2,147,483,647✔
130
}
131

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

147
  SResultRowPosition* p1 =
148
      (SResultRowPosition*)tSimpleHashGet(pSup->pResultRowHashTable, pSup->keyBuf, GET_RES_WINDOW_KEY_LEN(bytes));
2,147,483,647✔
149

150
  SResultRow* pResult = NULL;
2,147,483,647✔
151

152
  // in case of repeat scan/reverse scan, no new time window added.
153
  if (isIntervalQuery) {
2,147,483,647✔
154
    if (p1 != NULL) {  // the *p1 may be NULL in case of sliding+offset exists.
2,147,483,647✔
155
      pResult = getResultRowByPos(pResultBuf, p1, true);
1,896,465,555✔
156
      if (pResult == NULL) {
1,896,465,555✔
157
        pTaskInfo->code = terrno;
×
158
        return NULL;
×
159
      }
160

161
      if (pResult->pageId != p1->pageId || pResult->offset != p1->offset) {
1,896,465,555✔
162
        terrno = TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR;
103✔
163
        pTaskInfo->code = terrno;
×
164
        return NULL;
×
165
      }
166
    }
167
  } else {
168
    // In case of group by column query, the required SResultRow object must be existInCurrentResusltRowInfo in the
169
    // pResultRowInfo object.
170
    if (p1 != NULL) {
2,147,483,647✔
171
      // todo
172
      pResult = getResultRowByPos(pResultBuf, p1, true);
2,147,483,647✔
173
      if (NULL == pResult) {
2,147,483,647✔
174
        pTaskInfo->code = terrno;
×
175
        return NULL;
×
176
      }
177

178
      if (pResult->pageId != p1->pageId || pResult->offset != p1->offset) {
2,147,483,647✔
179
        terrno = TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR;
×
180
        pTaskInfo->code = terrno;
×
181
        return NULL;
×
182
      }
183
    }
184
  }
185

186
  // 1. close current opened time window
187
  if (pResultRowInfo->cur.pageId != -1 && ((pResult == NULL) || (pResult->pageId != pResultRowInfo->cur.pageId))) {
2,147,483,647✔
188
    SResultRowPosition pos = pResultRowInfo->cur;
2,147,483,647✔
189
    SFilePage*         pPage = getBufPage(pResultBuf, pos.pageId);
2,147,483,647✔
190
    if (pPage == NULL) {
2,147,483,647✔
191
      qError("failed to get buffer, code:%s, %s", tstrerror(terrno), GET_TASKID(pTaskInfo));
×
192
      pTaskInfo->code = terrno;
×
193
      return NULL;
×
194
    }
195
    releaseBufPage(pResultBuf, pPage);
2,147,483,647✔
196
  }
197

198
  // allocate a new buffer page
199
  if (pResult == NULL) {
2,147,483,647✔
200
    pResult = getNewResultRow(pResultBuf, &pSup->currentPageId, pSup->resultRowSize);
2,147,483,647✔
201
    if (pResult == NULL) {
2,147,483,647✔
202
      pTaskInfo->code = terrno;
×
203
      return NULL;
×
204
    }
205

206
    // add a new result set for a new group
207
    SResultRowPosition pos = {.pageId = pResult->pageId, .offset = pResult->offset};
2,147,483,647✔
208
     int32_t code = tSimpleHashPut(pSup->pResultRowHashTable, pSup->keyBuf, GET_RES_WINDOW_KEY_LEN(bytes), &pos,
2,147,483,647✔
209
                                  sizeof(SResultRowPosition));
210
    if (code != TSDB_CODE_SUCCESS) {
2,147,483,647✔
211
      qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(code));
×
212
      pTaskInfo->code = code;
×
213
      return NULL;
×
214
    }
215
  }
216

217
  // 2. set the new time window to be the new active time window
218
  pResultRowInfo->cur = (SResultRowPosition){.pageId = pResult->pageId, .offset = pResult->offset};
2,147,483,647✔
219

220
  // too many time window in query
221
  if (pTaskInfo->execModel == OPTR_EXEC_MODEL_BATCH &&
2,147,483,647✔
222
      tSimpleHashGetSize(pSup->pResultRowHashTable) > MAX_INTERVAL_TIME_WINDOW) {
2,147,483,647✔
223
    pTaskInfo->code = TSDB_CODE_QRY_TOO_MANY_TIMEWINDOW;
×
224
    return NULL;
×
225
  }
226

227
  return pResult;
2,147,483,647✔
228
}
229

230
//  query_range_start, query_range_end, window_duration, window_start, window_end
231
int32_t initExecTimeWindowInfo(SColumnInfoData* pColData, STimeWindow* pQueryWindow) {
11,366,249✔
232
  pColData->info.type = TSDB_DATA_TYPE_TIMESTAMP;
11,366,249✔
233
  pColData->info.bytes = sizeof(int64_t);
11,368,889✔
234

235
  int32_t code = colInfoDataEnsureCapacity(pColData, 6, false);
11,366,759✔
236
  if (code != TSDB_CODE_SUCCESS) {
11,372,068✔
237
    return code;
×
238
  }
239
  colDataSetInt64(pColData, 0, &pQueryWindow->skey);
11,372,068✔
240
  colDataSetInt64(pColData, 1, &pQueryWindow->ekey);
11,361,802✔
241

242
  int64_t interval = 0;
11,364,905✔
243
  colDataSetInt64(pColData, 2, &interval);  // this value may be variable in case of 'n' and 'y'.
244
  colDataSetInt64(pColData, 3, &pQueryWindow->skey);
11,356,613✔
245
  colDataSetInt64(pColData, 4, &pQueryWindow->ekey);
11,357,058✔
246

247
  interval = -1;
11,351,407✔
248
  colDataSetInt64(pColData, 5,  &interval);
249
  return TSDB_CODE_SUCCESS;
11,361,074✔
250
}
251

252
static int32_t doSetInputDataBlockInfo(SExprSupp* pExprSup, SSDataBlock* pBlock, int32_t order, int32_t scanFlag) {
26,253,075✔
253
  int32_t         code = TSDB_CODE_SUCCESS;
26,253,075✔
254
  int32_t         lino = 0;
26,253,075✔
255
  SqlFunctionCtx* pCtx = pExprSup->pCtx;
26,253,075✔
256
  for (int32_t i = 0; i < pExprSup->numOfExprs; ++i) {
141,903,549✔
257
    pCtx[i].order = order;
115,592,188✔
258
    pCtx[i].input.numOfRows = pBlock->info.rows;
115,603,916✔
259
    code = setBlockSMAInfo(&pCtx[i], &pExprSup->pExprInfo[i], pBlock);
115,623,783✔
260
    QUERY_CHECK_CODE(code, lino, _end);
115,621,122✔
261
    pCtx[i].pSrcBlock = pBlock;
115,621,122✔
262
    pCtx[i].scanFlag = scanFlag;
115,621,524✔
263
  }
264

265
_end:
26,295,719✔
266
  if (code != TSDB_CODE_SUCCESS) {
26,295,719✔
267
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
×
268
  }
269
  return code;
26,291,025✔
270
}
271

272
int32_t setInputDataBlock(SExprSupp* pExprSup, SSDataBlock* pBlock, int32_t order, int32_t scanFlag,
2,147,483,647✔
273
                          bool createDummyCol) {
274
  if (pBlock->pBlockAgg != NULL) {
2,147,483,647✔
275
    return doSetInputDataBlockInfo(pExprSup, pBlock, order, scanFlag);
26,285,969✔
276
  } else {
277
    return doSetInputDataBlock(pExprSup, pBlock, order, scanFlag, createDummyCol);
2,147,483,647✔
278
  }
279
}
280

281
static int32_t doCreateConstantValColumnInfo(SInputColumnInfoData* pInput, SFunctParam* pFuncParam, int32_t paramIndex,
347,117,895✔
282
                                             int32_t numOfRows) {
283
  int32_t          code = TSDB_CODE_SUCCESS;
347,117,895✔
284
  int32_t          lino = 0;
347,117,895✔
285
  SColumnInfoData* pColInfo = NULL;
347,117,895✔
286
  if (pInput->pData[paramIndex] == NULL) {
347,117,895✔
287
    pColInfo = taosMemoryCalloc(1, sizeof(SColumnInfoData));
795,839✔
288
    QUERY_CHECK_NULL(pColInfo, code, lino, _end, terrno);
795,839✔
289

290
    // Set the correct column info (data type and bytes)
291
    pColInfo->info.type = pFuncParam->param.nType;
795,839✔
292
    pColInfo->info.bytes = pFuncParam->param.nLen;
795,839✔
293

294
    pInput->pData[paramIndex] = pColInfo;
795,839✔
295
  } else {
296
    pColInfo = pInput->pData[paramIndex];
346,329,025✔
297
  }
298

299
  code = colInfoDataEnsureCapacity(pColInfo, numOfRows, false);
347,137,737✔
300
  QUERY_CHECK_CODE(code, lino, _end);
347,111,171✔
301

302
  int8_t type = pFuncParam->param.nType;
347,111,171✔
303
  if (type == TSDB_DATA_TYPE_BIGINT || type == TSDB_DATA_TYPE_UBIGINT) {
347,114,127✔
304
    int64_t v = pFuncParam->param.i;
546,084✔
305
    for (int32_t i = 0; i < numOfRows; ++i) {
1,192,202,307✔
306
      colDataSetInt64(pColInfo, i, &v);
1,191,653,267✔
307
    }
308
  } else if (type == TSDB_DATA_TYPE_DOUBLE) {
346,568,043✔
309
    double v = pFuncParam->param.d;
×
310
    for (int32_t i = 0; i < numOfRows; ++i) {
×
311
      colDataSetDouble(pColInfo, i, &v);
×
312
    }
313
  } else if (type == TSDB_DATA_TYPE_VARCHAR || type == TSDB_DATA_TYPE_GEOMETRY) {
346,568,043✔
314
    char* tmp = taosMemoryMalloc(pFuncParam->param.nLen + VARSTR_HEADER_SIZE);
2,166✔
315
    QUERY_CHECK_NULL(tmp, code, lino, _end, terrno);
×
316

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

325
_end:
346,565,877✔
326
  if (code != TSDB_CODE_SUCCESS) {
347,114,917✔
327
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
×
328
  }
329
  return code;
347,093,658✔
330
}
331

332
static int32_t doSetInputDataBlock(SExprSupp* pExprSup, SSDataBlock* pBlock, int32_t order, int32_t scanFlag,
2,147,483,647✔
333
                                   bool createDummyCol) {
334
  int32_t         code = TSDB_CODE_SUCCESS;
2,147,483,647✔
335
  int32_t         lino = 0;
2,147,483,647✔
336
  SqlFunctionCtx* pCtx = pExprSup->pCtx;
2,147,483,647✔
337

338
  for (int32_t i = 0; i < pExprSup->numOfExprs; ++i) {
2,147,483,647✔
339
    pCtx[i].order = order;
2,147,483,647✔
340
    pCtx[i].input.numOfRows = pBlock->info.rows;
2,147,483,647✔
341

342
    pCtx[i].pSrcBlock = pBlock;
2,147,483,647✔
343
    pCtx[i].scanFlag = scanFlag;
2,147,483,647✔
344

345
    SInputColumnInfoData* pInput = &pCtx[i].input;
2,147,483,647✔
346
    pInput->uid = pBlock->info.id.uid;
2,147,483,647✔
347
    pInput->colDataSMAIsSet = false;
2,147,483,647✔
348

349
    SExprInfo* pOneExpr = &pExprSup->pExprInfo[i];
2,147,483,647✔
350
    bool       hasPk = pOneExpr->pExpr->nodeType == QUERY_NODE_FUNCTION && pOneExpr->pExpr->_function.pFunctNode->hasPk;
2,147,483,647✔
351
    pCtx[i].hasPrimaryKey = hasPk;
2,147,483,647✔
352

353
    int16_t tsParamIdx = (!hasPk) ? pOneExpr->base.numOfParams - 1 : pOneExpr->base.numOfParams - 2;
2,147,483,647✔
354
    int16_t pkParamIdx = pOneExpr->base.numOfParams - 1;
2,147,483,647✔
355

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

366
        // NOTE: the last parameter is the primary timestamp column
367
        // todo: refactor this
368

369
        if (fmIsImplicitTsFunc(pCtx[i].functionId) && (j == tsParamIdx)) {
2,147,483,647✔
370
          pInput->pPTS = pInput->pData[j];  // in case of merge function, this is not always the ts column data.
2,147,483,647✔
371
        }
372
        if (hasPk && (j == pkParamIdx)) {
2,147,483,647✔
373
          pInput->pPrimaryKey = pInput->pData[j];
157,498,685✔
374
        }
375
        QUERY_CHECK_CONDITION((pInput->pData[j] != NULL), code, lino, _end, TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR);
2,147,483,647✔
376
      } else if (pFuncParam->type == FUNC_PARAM_TYPE_VALUE) {
730,339,059✔
377
        // todo avoid case: top(k, 12), 12 is the value parameter.
378
        // sum(11), 11 is also the value parameter.
379
        bool needDummyCol = (createDummyCol && pOneExpr->base.numOfParams == 1);
523,777,220✔
380
        // For indefinite-rows functions (e.g. mavg, csum, diff), the first parameter
381
        // is the data-input column.  When that argument is a constant we must expand
382
        // it into a per-row column so the function implementation can iterate over it.
383
        if (!needDummyCol && j == 0 &&
523,770,724✔
384
            pOneExpr->pExpr->nodeType == QUERY_NODE_FUNCTION &&
50,620,513✔
385
            fmIsIndefiniteRowsFunc(pOneExpr->pExpr->_function.functionId)) {
15,565,715✔
386
          needDummyCol = true;
×
387
        }
388
        if (needDummyCol) {
523,764,998✔
389
          pInput->totalRows = pBlock->info.rows;
347,098,217✔
390
          pInput->numOfRows = pBlock->info.rows;
347,119,755✔
391
          pInput->startRowIndex = 0;
347,124,337✔
392
          pInput->blankFill = pBlock->info.blankFill;
347,128,203✔
393

394
          code = doCreateConstantValColumnInfo(pInput, pFuncParam, j, pBlock->info.rows);
347,120,879✔
395
          QUERY_CHECK_CODE(code, lino, _end);
345,984,299✔
396
        }
397
      }
398
    }
399
  }
400

401
_end:
2,147,483,647✔
402
  if (code != TSDB_CODE_SUCCESS) {
2,147,483,647✔
403
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
×
404
  }
405
  return code;
2,147,483,647✔
406
}
407

408
bool functionNeedToExecute(SqlFunctionCtx* pCtx) {
2,147,483,647✔
409
  struct SResultRowEntryInfo* pResInfo = GET_RES_INFO(pCtx);
2,147,483,647✔
410

411
  // in case of timestamp column, always generated results.
412
  int32_t functionId = pCtx->functionId;
2,147,483,647✔
413
  if (functionId == -1) {
2,147,483,647✔
414
    return false;
×
415
  }
416

417
  if (pCtx->scanFlag == PRE_SCAN) {
2,147,483,647✔
418
    return fmIsRepeatScanFunc(pCtx->functionId);
3,886,833✔
419
  }
420

421
  if (isRowEntryCompleted(pResInfo)) {
2,147,483,647✔
422
    return false;
×
423
  }
424

425
  return true;
2,147,483,647✔
426
}
427

428
static int32_t doCreateConstantValColumnSMAInfo(SInputColumnInfoData* pInput, SFunctParam* pFuncParam, int32_t type,
×
429
                                                int32_t paramIndex, int32_t numOfRows) {
430
  if (pInput->pData[paramIndex] == NULL) {
×
431
    pInput->pData[paramIndex] = taosMemoryCalloc(1, sizeof(SColumnInfoData));
×
432
    if (pInput->pData[paramIndex] == NULL) {
×
433
      return terrno;
×
434
    }
435

436
    // Set the correct column info (data type and bytes)
437
    pInput->pData[paramIndex]->info.type = type;
×
438
    pInput->pData[paramIndex]->info.bytes = tDataTypes[type].bytes;
×
439
  }
440

441
  SColumnDataAgg* da = NULL;
×
442
  if (pInput->pColumnDataAgg[paramIndex] == NULL) {
×
443
    da = taosMemoryCalloc(1, sizeof(SColumnDataAgg));
×
444
    if (!da) {
×
445
      return terrno;
×
446
    }
447
    pInput->pColumnDataAgg[paramIndex] = da;
×
448
  } else {
449
    da = pInput->pColumnDataAgg[paramIndex];
×
450
  }
451

452
  if (type == TSDB_DATA_TYPE_BIGINT) {
×
453
    int64_t v = pFuncParam->param.i;
×
454
    *da = (SColumnDataAgg){.numOfNull = 0, .min = v, .max = v, .sum = v * numOfRows};
×
455
  } else if (type == TSDB_DATA_TYPE_DOUBLE) {
×
456
    double v = pFuncParam->param.d;
×
457
    *da = (SColumnDataAgg){.numOfNull = 0};
×
458

459
    *(double*)&da->min = v;
×
460
    *(double*)&da->max = v;
×
461
    *(double*)&da->sum = v * numOfRows;
×
462
  } else if (type == TSDB_DATA_TYPE_BOOL) {  // todo validate this data type
×
463
    bool v = pFuncParam->param.i;
×
464

465
    *da = (SColumnDataAgg){.numOfNull = 0};
×
466
    *(bool*)&da->min = 0;
×
467
    *(bool*)&da->max = v;
×
468
    *(bool*)&da->sum = v * numOfRows;
×
469
  } else if (type == TSDB_DATA_TYPE_TIMESTAMP) {
×
470
    // do nothing
471
  } else {
472
    qError("invalid constant type for sma info");
×
473
  }
474

475
  return TSDB_CODE_SUCCESS;
×
476
}
477

478
int32_t setBlockSMAInfo(SqlFunctionCtx* pCtx, SExprInfo* pExprInfo, SSDataBlock* pBlock) {
115,590,002✔
479
  int32_t code = TSDB_CODE_SUCCESS;
115,590,002✔
480
  int32_t lino = 0;
115,590,002✔
481
  int32_t numOfRows = pBlock->info.rows;
115,590,002✔
482

483
  SInputColumnInfoData* pInput = &pCtx->input;
115,623,080✔
484
  pInput->numOfRows = numOfRows;
115,627,667✔
485
  pInput->totalRows = numOfRows;
115,648,793✔
486

487
  if (pBlock->pBlockAgg != NULL) {
115,655,231✔
488
    pInput->colDataSMAIsSet = true;
115,670,089✔
489

490
    for (int32_t j = 0; j < pExprInfo->base.numOfParams; ++j) {
231,271,589✔
491
      SFunctParam* pFuncParam = &pExprInfo->base.pParam[j];
115,648,518✔
492

493
      if (pFuncParam->type == FUNC_PARAM_TYPE_COLUMN) {
115,657,310✔
494
        int32_t slotId = pFuncParam->pCol->slotId;
115,652,238✔
495
        pInput->pColumnDataAgg[j] = &pBlock->pBlockAgg[slotId];
115,657,615✔
496
        if (pInput->pColumnDataAgg[j]->colId == -1) {
115,658,094✔
497
          pInput->colDataSMAIsSet = false;
21,738✔
498
        }
499

500
        // Here we set the column info data since the data type for each column data is required, but
501
        // the data in the corresponding SColumnInfoData will not be used.
502
        pInput->pData[j] = taosArrayGet(pBlock->pDataBlock, slotId);
115,652,436✔
503
      } else if (pFuncParam->type == FUNC_PARAM_TYPE_VALUE) {
×
504
        code = doCreateConstantValColumnSMAInfo(pInput, pFuncParam, pFuncParam->param.nType, j, pBlock->info.rows);
×
505
        QUERY_CHECK_CODE(code, lino, _end);
611,091✔
506
      }
507
    }
508
  } else {
509
    pInput->colDataSMAIsSet = false;
×
510
  }
511

512
_end:
115,506,555✔
513
  if (code != TSDB_CODE_SUCCESS) {
115,506,555✔
514
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
×
515
  }
516
  return code;
115,607,382✔
517
}
518

519
/////////////////////////////////////////////////////////////////////////////////////////////
520
STimeWindow getAlignQueryTimeWindow(const SInterval* pInterval, int64_t key) {
2,147,483,647✔
521
  STimeWindow win = {0};
2,147,483,647✔
522
  win.skey = taosTimeTruncate(key, pInterval);
2,147,483,647✔
523

524
  /*
525
   * if the realSkey > INT64_MAX - pInterval->interval, the query duration between
526
   * realSkey and realEkey must be less than one interval.Therefore, no need to adjust the query ranges.
527
   */
528
  win.ekey = taosTimeGetIntervalEnd(win.skey, pInterval);
2,147,483,647✔
529
  if (win.ekey < win.skey) {
2,147,483,647✔
530
    win.ekey = INT64_MAX;
×
531
  }
532

533
  return win;
2,147,483,647✔
534
}
535

536
int32_t setResultRowInitCtx(SResultRow* pResult, SqlFunctionCtx* pCtx, int32_t numOfOutput,
2,147,483,647✔
537
                            int32_t* rowEntryInfoOffset) {
538
  bool init = false;
2,147,483,647✔
539
  for (int32_t i = 0; i < numOfOutput; ++i) {
2,147,483,647✔
540
    pCtx[i].resultInfo = getResultEntryInfo(pResult, i, rowEntryInfoOffset);
2,147,483,647✔
541
    if (init) {
2,147,483,647✔
542
      continue;
2,147,483,647✔
543
    }
544

545
    struct SResultRowEntryInfo* pResInfo = pCtx[i].resultInfo;
2,147,483,647✔
546
    
547
    if (isRowEntryCompleted(pResInfo) && isRowEntryInitialized(pResInfo)) {
2,147,483,647✔
548
      continue;
×
549
    }
550

551
    if (pCtx[i].isPseudoFunc) {
2,147,483,647✔
552
      continue;
2,147,483,647✔
553
    }
554

555
    if (!pResInfo->initialized) {
2,147,483,647✔
556
      if (pCtx[i].functionId != -1) {
2,147,483,647✔
557
        int32_t code = pCtx[i].fpSet.init(&pCtx[i], pResInfo);
2,147,483,647✔
558
        if (code != TSDB_CODE_SUCCESS && fmIsUserDefinedFunc(pCtx[i].functionId)) {
2,147,483,647✔
559
          pResInfo->initialized = false;
×
560
          qError("failed to initialize udf, funcId:%d error:%s", pCtx[i].functionId, tstrerror(code));
×
561
          return TSDB_CODE_UDF_FUNC_EXEC_FAILURE;
×
562
        } else if (code != TSDB_CODE_SUCCESS) {
2,147,483,647✔
563
          qError("failed to initialize function context, funcId:%d error:%s", pCtx[i].functionId, tstrerror(code));
×
564
          return code;
×
565
        }
566
      } else {
567
        pResInfo->initialized = true;
2,147,483,647✔
568
      }
569
    } else {
570
      init = true;
2,147,483,647✔
571
    }
572
  }
573
  return TSDB_CODE_SUCCESS;
2,147,483,647✔
574
}
575

576
void clearResultRowInitFlag(SqlFunctionCtx* pCtx, int32_t numOfOutput) {
695,917,215✔
577
  for (int32_t i = 0; i < numOfOutput; ++i) {
2,147,483,647✔
578
    SResultRowEntryInfo* pResInfo = pCtx[i].resultInfo;
2,147,483,647✔
579
    if (pResInfo == NULL) {
2,147,483,647✔
580
      continue;
×
581
    }
582

583
    pResInfo->initialized = false;
2,147,483,647✔
584
    pResInfo->numOfRes = 0;
2,147,483,647✔
585
    pResInfo->isNullRes = 0;
2,147,483,647✔
586
    pResInfo->complete = false;
2,147,483,647✔
587
  }
588
}
695,915,823✔
589

590
int32_t doFilter(SSDataBlock* pBlock, SFilterInfo* pFilterInfo, SColMatchInfo* pColMatchInfo, SColumnInfoData** pRet) {
2,147,483,647✔
591
  int32_t code = TSDB_CODE_SUCCESS;
2,147,483,647✔
592
  int32_t lino = 0;
2,147,483,647✔
593
  if (pFilterInfo == NULL || pBlock->info.rows == 0) {
2,147,483,647✔
594
    return TSDB_CODE_SUCCESS;
2,147,483,647✔
595
  }
596

597
  SFilterColumnParam param1 = {.numOfCols = taosArrayGetSize(pBlock->pDataBlock), .pDataBlock = pBlock->pDataBlock};
205,520,796✔
598
  SColumnInfoData*   p = NULL;
205,510,994✔
599

600
  code = filterSetDataFromSlotId(pFilterInfo, &param1);
205,498,970✔
601
  QUERY_CHECK_CODE(code, lino, _err);
205,517,010✔
602

603
  int32_t status = 0;
205,517,010✔
604
  code =
605
      filterExecute(pFilterInfo, pBlock, pRet != NULL ? pRet : &p, NULL, param1.numOfCols, &status);
205,520,414✔
606
  QUERY_CHECK_CODE(code, lino, _err);
205,502,285✔
607

608
  code = extractQualifiedTupleByFilterResult(pBlock, pRet != NULL ? *pRet : p, status);
204,384,837✔
609
  QUERY_CHECK_CODE(code, lino, _err);
204,388,061✔
610

611
  if (pColMatchInfo != NULL) {
204,388,061✔
612
    size_t size = taosArrayGetSize(pColMatchInfo->pList);
151,173,648✔
613
    for (int32_t i = 0; i < size; ++i) {
151,341,218✔
614
      SColMatchItem* pInfo = taosArrayGet(pColMatchInfo->pList, i);
151,171,895✔
615
      QUERY_CHECK_NULL(pInfo, code, lino, _err, terrno);
151,164,279✔
616
      if (pInfo->colId == PRIMARYKEY_TIMESTAMP_COL_ID) {
151,164,279✔
617
        SColumnInfoData* pColData = taosArrayGet(pBlock->pDataBlock, pInfo->dstSlotId);
151,004,450✔
618
        QUERY_CHECK_NULL(pColData, code, lino, _err, terrno);
151,004,604✔
619
        if (pColData->info.type == TSDB_DATA_TYPE_TIMESTAMP) {
151,004,576✔
620
          code = blockDataUpdateTsWindow(pBlock, pInfo->dstSlotId);
150,999,993✔
621
          QUERY_CHECK_CODE(code, lino, _err);
151,003,064✔
622
          break;
151,003,064✔
623
        }
624
      }
625
    }
626
  }
627
  code = blockDataCheck(pBlock);
204,386,800✔
628
  QUERY_CHECK_CODE(code, lino, _err);
204,401,606✔
629
_err:
205,519,054✔
630
  if (code != TSDB_CODE_SUCCESS) {
205,507,277✔
631
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
1,117,448✔
632
  }
633
  colDataDestroy(p);
205,507,277✔
634
  taosMemoryFree(p);
205,505,854✔
635
  return code;
205,506,936✔
636
}
637

638
int32_t extractQualifiedTupleByFilterResult(SSDataBlock* pBlock, const SColumnInfoData* p, int32_t status) {
204,598,022✔
639
  int32_t code = TSDB_CODE_SUCCESS;
204,598,022✔
640
  int8_t* pIndicator = (int8_t*)p->pData;
204,598,022✔
641
  if (status == FILTER_RESULT_ALL_QUALIFIED) {
204,613,631✔
642
    // here nothing needs to be done
643
  } else if (status == FILTER_RESULT_NONE_QUALIFIED) {
128,056,814✔
644
    code = trimDataBlock(pBlock, pBlock->info.rows, NULL);
52,933,726✔
645
    pBlock->info.rows = 0;
52,933,132✔
646
  } else if (status == FILTER_RESULT_PARTIAL_QUALIFIED) {
75,123,088✔
647
    code = trimDataBlock(pBlock, pBlock->info.rows, (bool*)pIndicator);
75,126,146✔
648
  } else {
UNCOV
649
    qError("unknown filter result type: %d", status);
×
650
  }
651
  return code;
204,603,833✔
652
}
653

654
void doUpdateNumOfRows(SqlFunctionCtx* pCtx, SResultRow* pRow, int32_t numOfExprs, const int32_t* rowEntryOffset) {
2,147,483,647✔
655
  bool returnNotNull = false;
2,147,483,647✔
656
  for (int32_t j = 0; j < numOfExprs; ++j) {
2,147,483,647✔
657
    SResultRowEntryInfo* pResInfo = getResultEntryInfo(pRow, j, rowEntryOffset);
2,147,483,647✔
658
    if (!isRowEntryInitialized(pResInfo)) {
2,147,483,647✔
659
      continue;
2,147,483,647✔
660
    } else {
661
    }
662

663
    if (pRow->numOfRows < pResInfo->numOfRes) {
2,147,483,647✔
664
      pRow->numOfRows = pResInfo->numOfRes;
2,147,483,647✔
665
    }
666

667
    if (pCtx[j].isNotNullFunc) {
2,147,483,647✔
668
      returnNotNull = true;
2,147,483,647✔
669
    }
670
  }
671
  // if all expr skips all blocks, e.g. all null inputs for max function, output one row in final result.
672
  //  except for first/last, which require not null output, output no rows
673
  if (pRow->numOfRows == 0 && !returnNotNull) {
2,147,483,647✔
674
    pRow->numOfRows = 1;
2,147,483,647✔
675
  }
676
}
2,147,483,647✔
677

678
int32_t copyResultrowToDataBlock(SExprInfo* pExprInfo, int32_t numOfExprs, SResultRow* pRow, SqlFunctionCtx* pCtx,
2,147,483,647✔
679
                                 SSDataBlock* pBlock, const int32_t* rowEntryOffset, SExecTaskInfo* pTaskInfo) {
680
  int32_t code = TSDB_CODE_SUCCESS;
2,147,483,647✔
681
  int32_t lino = 0;
2,147,483,647✔
682
  int32_t groupKeyIdx = 0;
2,147,483,647✔
683
  for (int32_t j = 0; j < numOfExprs; ++j) {
2,147,483,647✔
684
    int32_t slotId = pExprInfo[j].base.resSchema.slotId;
2,147,483,647✔
685

686
    pCtx[j].resultInfo = getResultEntryInfo(pRow, j, rowEntryOffset);
2,147,483,647✔
687
    if (pCtx[j].fpSet.finalize) {
2,147,483,647✔
688
      if (strcmp(pCtx[j].pExpr->pExpr->_function.functionName, "_group_key") == 0 ||
2,147,483,647✔
689
          strcmp(pCtx[j].pExpr->pExpr->_function.functionName, "_group_const_value") == 0) {
2,147,483,647✔
690
        // for groupkey along with functions that output multiple lines(e.g. Histogram)
691
        if (strcmp(pCtx[j].pExpr->pExpr->_function.functionName, "_group_key") == 0 &&
2,147,483,647✔
692
            pCtx[j].resultInfo->numOfRes == 0 && pTaskInfo->pStreamRuntimeInfo != NULL) {
2,147,483,647✔
693
          SArray* pVals = pTaskInfo->pStreamRuntimeInfo->funcInfo.pStreamPartColVals;
×
694
          if (pVals != NULL && groupKeyIdx < taosArrayGetSize(pVals)) {
×
695
            SStreamGroupValue* pValue = taosArrayGet(pVals, groupKeyIdx);
×
696
            if (pValue != NULL) {
×
697
              SGroupKeyInfo* pInfo = GET_ROWCELL_INTERBUF(pCtx[j].resultInfo);
×
698
              pInfo->hasResult = true;
×
699
              pInfo->isNull = pValue->isNull;
×
700
              if (!pValue->isNull) {
×
701
                if (IS_VAR_DATA_TYPE(pValue->data.type) || pValue->data.type == TSDB_DATA_TYPE_DECIMAL) {
×
702
                  if (pValue->data.pData != NULL && pValue->data.nData > 0) {
×
703
                    memcpy(pInfo->data, pValue->data.pData, pValue->data.nData);
×
704
                  }
705
                } else {
706
                  memcpy(pInfo->data, &pValue->data.val, pExprInfo[j].base.resSchema.bytes);
×
707
                }
708
              }
709
              pCtx[j].resultInfo->numOfRes = 1;
×
710
            }
711
          }
712
        }
713

714
        if (strcmp(pCtx[j].pExpr->pExpr->_function.functionName, "_group_key") == 0) {
2,147,483,647✔
715
          ++groupKeyIdx;
2,147,483,647✔
716
        }
717

718
        // need to match groupkey result for each output row of that function.
719
        if (pCtx[j].resultInfo->numOfRes != 0) {
2,147,483,647✔
720
          pCtx[j].resultInfo->numOfRes = pRow->numOfRows;
2,147,483,647✔
721
        }
722
      }
723

724
      code = pCtx[j].fpSet.finalize(&pCtx[j], pBlock);
2,147,483,647✔
725
      if (TSDB_CODE_SUCCESS != code) {
2,147,483,647✔
726
        qError("%s build result data block error, code %s", GET_TASKID(pTaskInfo), tstrerror(code));
×
727
        QUERY_CHECK_CODE(code, lino, _end);
1,507,939✔
728
      }
729
    } else if (strcmp(pCtx[j].pExpr->pExpr->_function.functionName, "_select_value") == 0) {
2,147,483,647✔
730
      // do nothing
731
    } else {
732
      // expand the result into multiple rows. E.g., _wstart, top(k, 20)
733
      // the _wstart needs to copy to 20 following rows, since the results of top-k expands to 20 different rows.
734
      SColumnInfoData* pColInfoData = taosArrayGet(pBlock->pDataBlock, slotId);
2,147,483,647✔
735
      QUERY_CHECK_NULL(pColInfoData, code, lino, _end, terrno);
2,147,483,647✔
736
      char*            in = GET_ROWCELL_INTERBUF(pCtx[j].resultInfo);
2,147,483,647✔
737
      for (int32_t k = 0; k < pRow->numOfRows; ++k) {        
2,147,483,647✔
738
        code = colDataSetValOrCover(pColInfoData, pBlock->info.rows + k, in, pCtx[j].resultInfo->isNullRes);
2,147,483,647✔
739
        QUERY_CHECK_CODE(code, lino, _end);
2,147,483,647✔
740
      }
741
    }
742
  }
743

744
_end:
2,147,483,647✔
745
  if (code != TSDB_CODE_SUCCESS) {
2,147,483,647✔
746
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
×
747
  }
748
  return code;
2,147,483,647✔
749
}
750

751
bool resultRowGetGroupKeyResult(const SResultRow* pRow, int32_t index, const int32_t* rowEntryOffset,
23,409✔
752
                                const void** ppData, bool* pIsNull) {
753
  if (pRow == NULL) {
23,409✔
754
    return false;
×
755
  }
756

757
  SResultRowEntryInfo* pEntryInfo = getResultEntryInfo(pRow, index, rowEntryOffset);
23,409✔
758
  SGroupKeyInfo*       pGroupKey = GET_ROWCELL_INTERBUF(pEntryInfo);
23,409✔
759

760
  if (ppData != NULL) {
23,409✔
761
    *ppData = pGroupKey->data;
23,409✔
762
  }
763
  if (pIsNull != NULL) {
23,409✔
764
    *pIsNull = pGroupKey->isNull;
23,409✔
765
  }
766

767
  return pGroupKey->hasResult;
23,409✔
768
}
769

770
bool resultRowCopyGroupKeyResult(SResultRow* pDstRow, int32_t dstIndex, const SResultRow* pSrcRow, int32_t srcIndex,
×
771
                                 const int32_t* rowEntryOffset, int32_t interBufSize) {
772
  if (pDstRow == NULL || pSrcRow == NULL) {
×
773
    return false;
×
774
  }
775

776
  SResultRowEntryInfo* pSrcEntry = getResultEntryInfo(pSrcRow, srcIndex, rowEntryOffset);
×
777
  SGroupKeyInfo*       pSrcGroupKey = GET_ROWCELL_INTERBUF(pSrcEntry);
×
778
  if (!pSrcGroupKey->hasResult) {
×
779
    return false;
×
780
  }
781

782
  SResultRowEntryInfo* pDstEntry = getResultEntryInfo(pDstRow, dstIndex, rowEntryOffset);
×
783
  memcpy(GET_ROWCELL_INTERBUF(pDstEntry), pSrcGroupKey, interBufSize);
×
784
  pDstEntry->numOfRes = 1;
×
785
  pDstEntry->isNullRes = pSrcGroupKey->isNull ? 1 : 0;
×
786

787
  return true;
×
788
}
789

790
// todo refactor. SResultRow has direct pointer in miainfo
791
void finalizeResultRows(SDiskbasedBuf* pBuf, SResultRowPosition* resultRowPosition, SExprSupp* pSup,
1,077,651,736✔
792
                        SSDataBlock* pBlock, SExecTaskInfo* pTaskInfo) {
793
  SFilePage* page = getBufPage(pBuf, resultRowPosition->pageId);
1,077,651,736✔
794
  if (page == NULL) {
1,077,651,921✔
795
    qError("failed to get buffer, code:%s, %s", tstrerror(terrno), GET_TASKID(pTaskInfo));
×
796
    T_LONG_JMP(pTaskInfo->env, terrno);
×
797
  }
798

799
  SResultRow* pRow = (SResultRow*)((char*)page + resultRowPosition->offset);
1,077,651,921✔
800

801
  SqlFunctionCtx* pCtx = pSup->pCtx;
1,077,663,177✔
802
  SExprInfo*      pExprInfo = pSup->pExprInfo;
1,077,680,061✔
803
  const int32_t*  rowEntryOffset = pSup->rowEntryInfoOffset;
1,077,679,123✔
804

805
  doUpdateNumOfRows(pCtx, pRow, pSup->numOfExprs, rowEntryOffset);
1,077,684,665✔
806
  if (pRow->numOfRows == 0) {
1,077,688,120✔
807
    releaseBufPage(pBuf, page);
×
808
    return;
×
809
  }
810

811
  int32_t size = pBlock->info.capacity;
1,077,689,811✔
812
  while (pBlock->info.rows + pRow->numOfRows > size) {
1,077,947,268✔
813
    size = size * 1.25;
258,679✔
814
  }
815

816
  int32_t code = blockDataEnsureCapacity(pBlock, size);
1,077,688,873✔
817
  if (TAOS_FAILED(code)) {
1,077,686,997✔
818
    releaseBufPage(pBuf, page);
×
819
    qError("%s ensure result data capacity failed, code %s", GET_TASKID(pTaskInfo), tstrerror(code));
×
820
    T_LONG_JMP(pTaskInfo->env, code);
×
821
  }
822

823
  code = copyResultrowToDataBlock(pExprInfo, pSup->numOfExprs, pRow, pCtx, pBlock, rowEntryOffset, pTaskInfo);
1,077,686,997✔
824
  if (TAOS_FAILED(code)) {
1,077,673,482✔
825
    releaseBufPage(pBuf, page);
×
826
    qError("%s copy result row to datablock failed, code %s", GET_TASKID(pTaskInfo), tstrerror(code));
×
827
    T_LONG_JMP(pTaskInfo->env, code);
×
828
  }
829

830
  releaseBufPage(pBuf, page);
1,077,673,482✔
831
  pBlock->info.rows += pRow->numOfRows;
1,077,663,818✔
832
}
833

834
void doCopyToSDataBlockByHash(SExecTaskInfo* pTaskInfo, SSDataBlock* pBlock, SExprSupp* pSup, SDiskbasedBuf* pBuf,
2,147,483,647✔
835
                              SGroupResInfo* pGroupResInfo, SSHashObj* pHashmap, int32_t threshold, bool ignoreGroup) {
836
  int32_t         code = TSDB_CODE_SUCCESS;
2,147,483,647✔
837
  int32_t         lino = 0;
2,147,483,647✔
838
  SExprInfo*      pExprInfo = pSup->pExprInfo;
2,147,483,647✔
839
  int32_t         numOfExprs = pSup->numOfExprs;
2,147,483,647✔
840
  int32_t*        rowEntryOffset = pSup->rowEntryInfoOffset;
2,147,483,647✔
841
  SqlFunctionCtx* pCtx = pSup->pCtx;
2,147,483,647✔
842

843
  size_t  keyLen = 0;
2,147,483,647✔
844
  int32_t numOfRows = tSimpleHashGetSize(pHashmap);
2,147,483,647✔
845

846
  // begin from last iter
847
  void*   pData = pGroupResInfo->dataPos;
2,147,483,647✔
848
  int32_t iter = pGroupResInfo->iter;
2,147,483,647✔
849
  while ((pData = tSimpleHashIterate(pHashmap, pData, &iter)) != NULL) {
2,147,483,647✔
850
    void*               key = tSimpleHashGetKey(pData, &keyLen);
2,147,483,647✔
851
    SResultRowPosition* pos = pData;
2,147,483,647✔
852
    uint64_t            groupId = calcGroupId((char*)key + sizeof(uint64_t), keyLen - sizeof(uint64_t));
2,147,483,647✔
853

854
    SFilePage* page = getBufPage(pBuf, pos->pageId);
2,147,483,647✔
855
    if (page == NULL) {
2,147,483,647✔
856
      qError("failed to get buffer, code:%s, %s", tstrerror(terrno), GET_TASKID(pTaskInfo));
×
857
      T_LONG_JMP(pTaskInfo->env, terrno);
×
858
    }
859

860
    SResultRow* pRow = (SResultRow*)((char*)page + pos->offset);
2,147,483,647✔
861

862
    doUpdateNumOfRows(pCtx, pRow, numOfExprs, rowEntryOffset);
2,147,483,647✔
863

864
    // no results, continue to check the next one
865
    if (pRow->numOfRows == 0) {
2,147,483,647✔
866
      pGroupResInfo->index += 1;
×
867
      pGroupResInfo->iter = iter;
×
868
      pGroupResInfo->dataPos = pData;
×
869

870
      releaseBufPage(pBuf, page);
×
871
      continue;
×
872
    }
873

874
    if (!ignoreGroup) {
2,147,483,647✔
875
      if (pBlock->info.id.groupId == 0) {
2,147,483,647✔
876
        pBlock->info.id.groupId = groupId;
2,147,483,647✔
877
      } else {
878
        // current value belongs to different group, it can't be packed into one datablock
879
        if (pBlock->info.id.groupId != groupId) {
2,147,483,647✔
880
          releaseBufPage(pBuf, page);
2,147,483,647✔
881
          break;
2,147,483,647✔
882
        }
883
      }
884
    }
885

886
    if (pBlock->info.rows + pRow->numOfRows > pBlock->info.capacity) {
2,147,483,647✔
887
      uint32_t newSize = pBlock->info.rows + pRow->numOfRows + ((numOfRows - iter) > 1 ? 1 : 0);
×
888
      code = blockDataEnsureCapacity(pBlock, newSize);
×
889
      QUERY_CHECK_CODE(code, lino, _end);
×
890
      qDebug("datablock capacity not sufficient, expand to required:%d, current capacity:%d, %s", newSize,
×
891
             pBlock->info.capacity, GET_TASKID(pTaskInfo));
892
      // todo set the pOperator->resultInfo size
893
    }
894

895
    pGroupResInfo->index += 1;
2,147,483,647✔
896
    pGroupResInfo->iter = iter;
2,147,483,647✔
897
    pGroupResInfo->dataPos = pData;
2,147,483,647✔
898

899
    code = copyResultrowToDataBlock(pExprInfo, numOfExprs, pRow, pCtx, pBlock, rowEntryOffset, pTaskInfo);
2,147,483,647✔
900
    releaseBufPage(pBuf, page);
2,147,483,647✔
901
    QUERY_CHECK_CODE(code, lino, _end);
2,147,483,647✔
902
    pBlock->info.rows += pRow->numOfRows;
2,147,483,647✔
903
    if (pBlock->info.rows >= threshold) {
2,147,483,647✔
904
      break;
18,072✔
905
    }
906
  }
907

908
  qDebug("%s result generated, rows:%" PRId64 ", groupId:%" PRIu64, GET_TASKID(pTaskInfo), pBlock->info.rows,
2,147,483,647✔
909
         pBlock->info.id.groupId);
910
  pBlock->info.dataLoad = 1;
2,147,483,647✔
911
  code = blockDataUpdateTsWindow(pBlock, 0);
2,147,483,647✔
912
  QUERY_CHECK_CODE(code, lino, _end);
2,147,483,647✔
913

914
_end:
2,147,483,647✔
915
  if (code != TSDB_CODE_SUCCESS) {
2,147,483,647✔
916
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
×
917
    T_LONG_JMP(pTaskInfo->env, code);
×
918
  }
919
}
2,147,483,647✔
920

921
void doCopyToSDataBlock(SExecTaskInfo* pTaskInfo, SSDataBlock* pBlock, SExprSupp* pSup, SDiskbasedBuf* pBuf,
131,523,017✔
922
                        SGroupResInfo* pGroupResInfo, int32_t threshold, bool ignoreGroup, STrueForInfo *pTrueForInfo) {
923
  int32_t         code = TSDB_CODE_SUCCESS;
131,523,017✔
924
  int32_t         lino = 0;
131,523,017✔
925
  SExprInfo*      pExprInfo = pSup->pExprInfo;
131,523,017✔
926
  int32_t         numOfExprs = pSup->numOfExprs;
131,524,765✔
927
  int32_t*        rowEntryOffset = pSup->rowEntryInfoOffset;
131,522,450✔
928
  SqlFunctionCtx* pCtx = pSup->pCtx;
131,523,211✔
929

930
  int32_t numOfRows = getNumOfTotalRes(pGroupResInfo);
131,518,589✔
931

932
  for (int32_t i = pGroupResInfo->index; i < numOfRows; i += 1) {
2,147,483,647✔
933
    SResKeyPos* pPos = taosArrayGetP(pGroupResInfo->pRows, i);
2,147,483,647✔
934
    SFilePage*  page = getBufPage(pBuf, pPos->pos.pageId);
2,147,483,647✔
935
    if (page == NULL) {
2,147,483,647✔
936
      qError("failed to get buffer, code:%s, %s", tstrerror(terrno), GET_TASKID(pTaskInfo));
×
937
      T_LONG_JMP(pTaskInfo->env, terrno);
×
938
    }
939

940
    SResultRow* pRow = (SResultRow*)((char*)page + pPos->pos.offset);
2,147,483,647✔
941

942
    doUpdateNumOfRows(pCtx, pRow, numOfExprs, rowEntryOffset);
2,147,483,647✔
943

944
    // no results, continue to check the next one
945
    if (pRow->numOfRows == 0) {
2,147,483,647✔
946
      pGroupResInfo->index += 1;
141,834✔
947
      releaseBufPage(pBuf, page);
141,834✔
948
      continue;
141,834✔
949
    }
950
    // skip the window which is less than the windowMinSize
951
    if (!isTrueForSatisfied(pTrueForInfo, pRow->win.skey, pRow->win.ekey, pRow->nOrigRows)) {
2,147,483,647✔
952
      qDebug("skip small window, groupId: %" PRId64 ", skey: %" PRId64 ", ekey: %" PRId64 ", nrows: %u", pPos->groupId,
53,144✔
953
             pRow->win.skey, pRow->win.ekey, pRow->nOrigRows);
954
      pGroupResInfo->index += 1;
53,144✔
955
      releaseBufPage(pBuf, page);
53,144✔
956
      continue;
53,144✔
957
    }
958

959
    if (!ignoreGroup) {
2,147,483,647✔
960
      if (pBlock->info.id.groupId == 0) {
2,147,483,647✔
961
        pBlock->info.id.groupId = pPos->groupId;
2,147,483,647✔
962
      } else {
963
        // current value belongs to different group, it can't be packed into one datablock
964
        if (pBlock->info.id.groupId != pPos->groupId) {
2,147,483,647✔
965
          releaseBufPage(pBuf, page);
21,697,263✔
966
          break;
21,697,263✔
967
        }
968
      }
969
    }
970

971
    if (pBlock->info.rows + pRow->numOfRows > pBlock->info.capacity) {
2,147,483,647✔
972
      uint32_t newSize = pBlock->info.rows + pRow->numOfRows + ((numOfRows - i) > 1 ? 1 : 0);
×
973
      code = blockDataEnsureCapacity(pBlock, newSize);
×
974
      QUERY_CHECK_CODE(code, lino, _end);
×
975
      qDebug("datablock capacity not sufficient, expand to required:%d, current capacity:%d, %s", newSize,
×
976
             pBlock->info.capacity, GET_TASKID(pTaskInfo));
977
      // todo set the pOperator->resultInfo size
978
    }
979

980
    pGroupResInfo->index += 1;
2,147,483,647✔
981
    code = copyResultrowToDataBlock(pExprInfo, numOfExprs, pRow, pCtx, pBlock, rowEntryOffset, pTaskInfo);
2,147,483,647✔
982
    releaseBufPage(pBuf, page);
2,147,483,647✔
983
    QUERY_CHECK_CODE(code, lino, _end);
2,147,483,647✔
984

985
    pBlock->info.rows += pRow->numOfRows;
2,147,483,647✔
986
    if (pBlock->info.rows >= threshold) {
2,147,483,647✔
987
      break;
19,209,614✔
988
    }
989
  }
990

991
  qDebug("%s result generated, rows:%" PRId64 ", groupId:%" PRIu64, GET_TASKID(pTaskInfo), pBlock->info.rows,
131,511,048✔
992
         pBlock->info.id.groupId);
993
  pBlock->info.dataLoad = 1;
131,517,162✔
994
  code = blockDataUpdateTsWindow(pBlock, 0);
131,527,054✔
995
  QUERY_CHECK_CODE(code, lino, _end);
131,524,056✔
996

997
_end:
131,524,056✔
998
  if (code != TSDB_CODE_SUCCESS) {
131,524,056✔
999
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
×
1000
    T_LONG_JMP(pTaskInfo->env, code);
×
1001
  }
1002
}
131,524,056✔
1003

1004
void doBuildResultDatablock(SOperatorInfo* pOperator, SOptrBasicInfo* pbInfo, SGroupResInfo* pGroupResInfo,
154,720,852✔
1005
                            SDiskbasedBuf* pBuf) {
1006
  SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
154,720,852✔
1007
  SSDataBlock*   pBlock = pbInfo->pRes;
154,728,218✔
1008

1009
  // set output datablock version
1010
  pBlock->info.version = pTaskInfo->version;
154,724,455✔
1011

1012
  blockDataCleanup(pBlock);
154,726,861✔
1013
  if (!hasRemainResults(pGroupResInfo)) {
154,729,729✔
1014
    return;
23,675,880✔
1015
  }
1016

1017
  // clear the existed group id
1018
  pBlock->info.id.groupId = 0;
131,050,251✔
1019
  if (!pbInfo->mergeResultBlock) {
131,050,592✔
1020
    doCopyToSDataBlock(pTaskInfo, pBlock, &pOperator->exprSupp, pBuf, pGroupResInfo, pOperator->resultInfo.threshold,
50,610,007✔
1021
                       false, getTrueForInfo(pOperator));
1022
  } else {
1023
    while (hasRemainResults(pGroupResInfo)) {
149,640,146✔
1024
      doCopyToSDataBlock(pTaskInfo, pBlock, &pOperator->exprSupp, pBuf, pGroupResInfo, pOperator->resultInfo.threshold,
80,440,095✔
1025
                         true, getTrueForInfo(pOperator));
1026
      if (pBlock->info.rows >= pOperator->resultInfo.threshold) {
80,441,139✔
1027
        break;
11,241,027✔
1028
      }
1029

1030
      // clearing group id to continue to merge data that belong to different groups
1031
      pBlock->info.id.groupId = 0;
69,199,739✔
1032
    }
1033

1034
    // clear the group id info in SSDataBlock, since the client does not need it
1035
    pBlock->info.id.groupId = 0;
80,440,850✔
1036
  }
1037
}
1038

1039
void destroyExprInfo(SExprInfo* pExpr, int32_t numOfExprs) {
462,707,557✔
1040
  for (int32_t i = 0; i < numOfExprs; ++i) {
1,819,101,683✔
1041
    SExprInfo* pExprInfo = &pExpr[i];
1,356,381,248✔
1042
    for (int32_t j = 0; j < pExprInfo->base.numOfParams; ++j) {
2,147,483,647✔
1043
      if (pExprInfo->base.pParam[j].type == FUNC_PARAM_TYPE_COLUMN) {
1,544,980,926✔
1044
        taosMemoryFreeClear(pExprInfo->base.pParam[j].pCol);
1,275,689,751✔
1045
      } else if (pExprInfo->base.pParam[j].type == FUNC_PARAM_TYPE_VALUE) {
269,314,423✔
1046
        taosVariantDestroy(&pExprInfo->base.pParam[j].param);
156,976,158✔
1047
      }
1048
    }
1049

1050
    taosMemoryFree(pExprInfo->base.pParam);
1,356,457,110✔
1051
    taosMemoryFree(pExprInfo->pExpr);
1,356,415,746✔
1052
  }
1053
}
462,720,435✔
1054

1055
int32_t getBufferPgSize(int32_t rowSize, uint32_t* defaultPgsz, int64_t* defaultBufsz) {
331,551,841✔
1056
  *defaultPgsz = 4096;
331,551,841✔
1057
  uint32_t last = *defaultPgsz;
331,577,248✔
1058
  while (*defaultPgsz < rowSize * 4) {
400,727,264✔
1059
    *defaultPgsz <<= 1u;
69,239,282✔
1060
    if (*defaultPgsz < last) {
69,221,705✔
1061
      return TSDB_CODE_INVALID_PARA;
×
1062
    }
1063
    last = *defaultPgsz;
69,212,614✔
1064
  }
1065

1066
  // The default buffer for each operator in query is 10MB.
1067
  // at least four pages need to be in buffer
1068
  // TODO: make this variable to be configurable.
1069
  *defaultBufsz = 4096 * 2560;
331,482,426✔
1070
  if ((*defaultBufsz) <= (*defaultPgsz)) {
331,522,944✔
1071
    (*defaultBufsz) = (*defaultPgsz) * 4;
×
1072
    if (*defaultBufsz < ((int64_t)(*defaultPgsz)) * 4) {
×
1073
      return TSDB_CODE_INVALID_PARA;
×
1074
    }
1075
  }
1076

1077
  return 0;
331,468,753✔
1078
}
1079

1080
void initResultSizeInfo(SResultInfo* pResultInfo, int32_t numOfRows) {
705,286,359✔
1081
  if (numOfRows == 0) {
705,286,359✔
1082
    numOfRows = 4096;
×
1083
  }
1084

1085
  pResultInfo->capacity = numOfRows;
705,286,359✔
1086
  pResultInfo->threshold = numOfRows * 0.75;
705,431,173✔
1087

1088
  if (pResultInfo->threshold == 0) {
705,055,696✔
1089
    pResultInfo->threshold = numOfRows;
1,934,662✔
1090
  }
1091
  pResultInfo->totalRows = 0;
705,142,139✔
1092
}
705,142,015✔
1093

1094
void initBasicInfo(SOptrBasicInfo* pInfo, SSDataBlock* pBlock) {
311,063,117✔
1095
  pInfo->pRes = pBlock;
311,063,117✔
1096
  initResultRowInfo(&pInfo->resultRowInfo);
311,093,851✔
1097
}
311,076,205✔
1098

1099
void destroySqlFunctionCtx(SqlFunctionCtx* pCtx, SExprInfo* pExpr, int32_t numOfOutput) {
1,338,743,177✔
1100
  if (pCtx == NULL) {
1,338,743,177✔
1101
    return;
846,299,768✔
1102
  }
1103

1104
  for (int32_t i = 0; i < numOfOutput; ++i) {
1,835,062,264✔
1105
    if (pExpr != NULL) {
1,342,645,332✔
1106
      SExprInfo* pExprInfo = &pExpr[i];
1,342,619,769✔
1107
      for (int32_t j = 0; j < pExprInfo->base.numOfParams; ++j) {
2,147,483,647✔
1108
        if (pExprInfo->base.pParam[j].type == FUNC_PARAM_TYPE_VALUE) {
1,530,368,799✔
1109
          colDataDestroy(pCtx[i].input.pData[j]);
154,542,544✔
1110
          taosMemoryFree(pCtx[i].input.pData[j]);
154,543,858✔
1111
          taosMemoryFree(pCtx[i].input.pColumnDataAgg[j]);
154,542,912✔
1112
        }
1113
      }
1114
    }
1115
    for (int32_t j = 0; j < pCtx[i].numOfParams; ++j) {
2,147,483,647✔
1116
      taosVariantDestroy(&pCtx[i].param[j].param);
1,530,406,569✔
1117
    }
1118

1119
    if(pCtx[i].fpSet.cleanup) {
1,342,671,836✔
1120
      pCtx[i].fpSet.cleanup(&pCtx[i]);
1,001,157✔
1121
    }
1122

1123
    taosMemoryFreeClear(pCtx[i].subsidiaries.pCtx);
1,342,704,133✔
1124
    taosMemoryFreeClear(pCtx[i].subsidiaries.buf);
1,342,722,309✔
1125
    taosMemoryFree(pCtx[i].input.pData);
1,342,719,510✔
1126
    taosMemoryFree(pCtx[i].input.pColumnDataAgg);
1,342,666,377✔
1127

1128
    if (pCtx[i].udfName != NULL) {
1,342,664,586✔
1129
      taosMemoryFree(pCtx[i].udfName);
54,097✔
1130
    }
1131
  }
1132

1133
  taosMemoryFreeClear(pCtx);
492,416,932✔
1134
  return;
492,403,523✔
1135
}
1136

1137
int32_t initExprSupp(SExprSupp* pSup, SExprInfo* pExprInfo, int32_t numOfExpr, SFunctionStateStore* pStore) {
487,798,936✔
1138
  pSup->pExprInfo = pExprInfo;
487,798,936✔
1139
  pSup->numOfExprs = numOfExpr;
487,839,466✔
1140
  if (pSup->pExprInfo != NULL) {
487,809,615✔
1141
    pSup->pCtx = createSqlFunctionCtx(pExprInfo, numOfExpr, &pSup->rowEntryInfoOffset, pStore);
380,507,945✔
1142
    if (pSup->pCtx == NULL) {
380,533,909✔
1143
      return terrno;
×
1144
    }
1145
  }
1146

1147
  return TSDB_CODE_SUCCESS;
487,798,761✔
1148
}
1149

1150
void checkIndefRowsFuncs(SExprSupp* pSup) {
9,804✔
1151
  for (int32_t i = 0; i < pSup->numOfExprs; ++i) {
28,344✔
1152
    if (fmIsIndefiniteRowsFunc(pSup->pCtx[i].functionId)) {
18,540✔
1153
      pSup->hasIndefRowsFunc = true;
×
1154
      break;
×
1155
    }
1156
  }
1157
}
9,804✔
1158

1159
static void cleanupIndefRowsResultRow(SOperatorInfo* pOperator, SResultRow* pRow) {
11,204,521✔
1160
  if (NULL == pOperator || NULL == pRow) {
11,204,521✔
1161
    return;
×
1162
  }
1163

1164
  SExprSupp* pSup = &pOperator->exprSupp;
11,204,521✔
1165
  for (int32_t i = 0; i < pSup->numOfExprs; ++i) {
25,047,551✔
1166
    pSup->pCtx[i].resultInfo = getResultEntryInfo(pRow, i, pSup->rowEntryInfoOffset);
13,843,030✔
1167
    if (pSup->pCtx[i].fpSet.cleanup != NULL) {
13,843,030✔
1168
      pSup->pCtx[i].fpSet.cleanup(&pSup->pCtx[i]);
14,838✔
1169
    }
1170
    pSup->pCtx[i].resultInfo = NULL;
13,843,030✔
1171
  }
1172
}
1173

1174
static void destroyIndefRowsWindowState(SOperatorInfo* pOperator, SIndefRowsWindowState* pState) {
3,395✔
1175
  if (NULL == pState) {
3,395✔
1176
    return;
×
1177
  }
1178

1179
  cleanupIndefRowsResultRow(pOperator, pState->pRow);
3,395✔
1180
  taosMemoryFreeClear(pState->pRow);
3,395✔
1181

1182
  if (pState->pSealedBlocks != NULL) {
3,395✔
1183
    SListNode* pNode = NULL;
3,395✔
1184
    while ((pNode = tdListPopHead(pState->pSealedBlocks)) != NULL) {
3,395✔
1185
      SSDataBlock* pBlock = *(SSDataBlock**)pNode->data;
×
1186
      blockDataDestroy(pBlock);
×
1187
      taosMemoryFree(pNode);
×
1188
    }
1189
    pState->pSealedBlocks = tdListFree(pState->pSealedBlocks);
3,395✔
1190
  }
1191

1192
  blockDataDestroy(pState->pCurBlock);
3,395✔
1193
  taosMemoryFreeClear(pState);
3,395✔
1194
}
1195

1196
static void removeIndefRowsOpenState(SSHashObj* pOpenStatesMap, SIndefRowsWindowState* pState) {
11,201,126✔
1197
  if (NULL == pOpenStatesMap || NULL == pState) {
11,201,126✔
1198
    return;
×
1199
  }
1200

1201
  SIndefRowsStateKey key = {.groupId = pState->groupId, .skey = pState->win.skey};
11,201,126✔
1202
  int32_t  code = tSimpleHashRemove(pOpenStatesMap, &key, sizeof(key));
11,201,126✔
1203
  if (code != TSDB_CODE_SUCCESS) {
11,201,126✔
1204
    qError("failed to remove open state for groupId:%" PRIu64 ", skey:%" PRId64 ", code:%s", pState->groupId, pState->win.skey,
×
1205
           tstrerror(code));
1206
  }
1207
}
1208

1209
static int32_t createIndefRowsWindowState(SIndefRowsRuntime* pRuntime, SSDataBlock* pResultTemplate, uint64_t groupId,
11,204,521✔
1210
                                          const STimeWindow* pWin, int32_t resultRowSize,
1211
                                          SIndefRowsWindowState** ppState) {
1212
  int32_t code = TSDB_CODE_SUCCESS;
11,204,521✔
1213
  int32_t lino = 0;
11,204,521✔
1214

1215
  SIndefRowsWindowState* pState = taosMemoryCalloc(1, sizeof(SIndefRowsWindowState));
11,204,521✔
1216
  TSDB_CHECK_NULL(pState, code, lino, _return, terrno);
11,204,521✔
1217

1218
  pState->pRow = taosMemoryCalloc(1, resultRowSize);
11,204,521✔
1219
  QUERY_CHECK_NULL(pState->pRow, code, lino, _return, terrno);
11,204,521✔
1220

1221
  pState->pSealedBlocks = tdListNew(POINTER_BYTES);
11,204,521✔
1222
  QUERY_CHECK_NULL(pState->pSealedBlocks, code, lino, _return, terrno);
11,204,521✔
1223

1224
  code = createOneDataBlock(pResultTemplate, false, &pState->pCurBlock);
11,204,521✔
1225
  QUERY_CHECK_CODE(code, lino, _return);
11,204,521✔
1226

1227
  pState->groupId = groupId;
11,204,521✔
1228
  pState->win = *pWin;
11,204,521✔
1229
  TAOS_SET_POBJ_ALIGNED(&pState->pRow->win, pWin);
11,204,521✔
1230

1231
  SIndefRowsStateKey key = {.groupId = groupId, .skey = pWin->skey};
11,204,521✔
1232
  code = tSimpleHashPut(pRuntime->pOpenStatesMap, &key, sizeof(key), &pState, POINTER_BYTES);
11,204,521✔
1233
  QUERY_CHECK_CODE(code, lino, _return);
11,204,521✔
1234

1235
  *ppState = pState;
11,204,521✔
1236
  return code;
11,204,521✔
1237

1238
_return:
×
1239
  if (NULL != pState) {
×
1240
    taosMemoryFree(pState->pRow);
×
1241
    pState->pSealedBlocks = tdListFree(pState->pSealedBlocks);
×
1242
    blockDataDestroy(pState->pCurBlock);
×
1243
    taosMemoryFree(pState);
×
1244
  }
1245

1246
  if (code != TSDB_CODE_SUCCESS) {
×
1247
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
×
1248
  }
1249

1250
  return code;
×
1251
}
1252

1253
static int32_t fillIndefRowsWindowPseudoCols(SOperatorInfo* pOperator, SSDataBlock* pBlock, const STimeWindow* pWin,
1,318,211✔
1254
                                             int32_t startOffset, int32_t rows) {
1255
  int32_t code = TSDB_CODE_SUCCESS;
1,318,211✔
1256
  int32_t lino = 0;
1,318,211✔
1257

1258
  if (rows <= 0) {
1,318,211✔
1259
    return code;
×
1260
  }
1261

1262
  for (int32_t i = 0; i < pOperator->exprSupp.numOfExprs; ++i) {
5,372,385✔
1263
    SqlFunctionCtx* pCtx = &pOperator->exprSupp.pCtx[i];
4,054,174✔
1264
    if (!fmIsPseudoColumnFunc(pCtx->functionId)) {
4,054,174✔
1265
      continue;
2,052,815✔
1266
    }
1267

1268
    const char* pFuncName = pCtx->pExpr->pExpr->_function.functionName;
2,001,359✔
1269
    int64_t     val = 0;
2,001,359✔
1270
    if (strcmp(pFuncName, "_wstart") == 0) {
2,001,359✔
1271
      val = pWin->skey;
823,231✔
1272
    } else if (strcmp(pFuncName, "_wend") == 0) {
1,178,128✔
1273
      val = pWin->ekey;
589,064✔
1274
    } else if (strcmp(pFuncName, "_wduration") == 0) {
589,064✔
1275
      val = pWin->ekey - pWin->skey;
589,064✔
1276
    } else {
1277
      continue;
×
1278
    }
1279

1280
    int32_t slotId = pOperator->exprSupp.pExprInfo[i].base.resSchema.slotId;
2,001,359✔
1281
    SColumnInfoData* pCol = taosArrayGet(pBlock->pDataBlock, slotId);
2,001,359✔
1282
    QUERY_CHECK_NULL(pCol, code, lino, _return, terrno);
2,001,359✔
1283

1284
    for (int32_t row = 0; row < rows; ++row) {
784,380,849✔
1285
      code = colDataSetVal(pCol, startOffset + row, (const char*)&val, false);
782,378,522✔
1286
      QUERY_CHECK_CODE(code, lino, _return);
782,379,490✔
1287
    }
1288
  }
1289

1290
  return code;
1,318,211✔
1291

1292
_return:
×
1293
  qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
×
1294
  return code;
×
1295
}
1296

1297
int32_t initIndefRowsRuntime(SIndefRowsRuntime* pRuntime, SqlFunctionCtx* pCtx, int32_t numOfExprs, int32_t blockCapacity) {
127,756✔
1298
  int32_t code = TSDB_CODE_SUCCESS;
127,756✔
1299
  int32_t lino = 0;
127,756✔
1300

1301
  if (NULL == pRuntime) {
127,756✔
1302
    return TSDB_CODE_INVALID_PARA;
×
1303
  }
1304

1305
  pRuntime->blockCapacity = blockCapacity > 0 ? blockCapacity : 4096;
127,756✔
1306

1307
  pRuntime->pOpenStatesMap = tSimpleHashInit(16, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY));
127,756✔
1308
  QUERY_CHECK_NULL(pRuntime->pOpenStatesMap, code, lino, _return, terrno);
127,756✔
1309

1310
  pRuntime->pReadyBlocks = tdListNew(POINTER_BYTES);
127,756✔
1311
  QUERY_CHECK_NULL(pRuntime->pReadyBlocks, code, lino, _return, terrno);
127,756✔
1312

1313
  code = setRowTsColumnOutputInfo(pCtx, numOfExprs, &pRuntime->pPseudoColInfo);
127,756✔
1314
  QUERY_CHECK_CODE(code, lino, _return);
127,756✔
1315

1316
  return code;
127,756✔
1317

1318
_return:
×
1319
  qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
×
1320
  pRuntime->pReadyBlocks = tdListFree(pRuntime->pReadyBlocks);
×
1321
  tSimpleHashCleanup(pRuntime->pOpenStatesMap);
×
1322
  pRuntime->pOpenStatesMap = NULL;
×
1323
  return code;
×
1324
}
1325

1326
void resetIndefRowsRuntime(SIndefRowsRuntime* pRuntime, SOperatorInfo* pOperator) {
9,016,766✔
1327
  if (NULL == pRuntime) {
9,016,766✔
1328
    return;
×
1329
  }
1330

1331
  if (pRuntime->pReturnedBlock != NULL) {
9,016,766✔
1332
    blockDataDestroy(pRuntime->pReturnedBlock);
×
1333
    pRuntime->pReturnedBlock = NULL;
×
1334
  }
1335

1336
  if (pRuntime->pReadyBlocks != NULL) {
9,018,582✔
1337
    SListNode* pNode = NULL;
127,756✔
1338
    while ((pNode = tdListPopHead(pRuntime->pReadyBlocks)) != NULL) {
127,756✔
1339
      SSDataBlock* pBlock = *(SSDataBlock**)pNode->data;
×
1340
      blockDataDestroy(pBlock);
×
1341
      taosMemoryFree(pNode);
×
1342
    }
1343
  }
1344

1345
  if (pRuntime->pOpenStatesMap != NULL) {
9,017,239✔
1346
    int32_t iter = 0;
127,756✔
1347
    void*   pData = NULL;
127,756✔
1348
    while ((pData = tSimpleHashIterate(pRuntime->pOpenStatesMap, pData, &iter)) != NULL) {
131,151✔
1349
      SIndefRowsWindowState* pState = *(SIndefRowsWindowState**)pData;
3,395✔
1350
      destroyIndefRowsWindowState(pOperator, pState);
3,395✔
1351
    }
1352
    tSimpleHashClear(pRuntime->pOpenStatesMap);
127,756✔
1353
  }
1354

1355
  if (pRuntime->pTmpBlock != NULL) {
9,016,766✔
1356
    blockDataCleanup(pRuntime->pTmpBlock);
114,038✔
1357
  }
1358
}
1359

1360
void cleanupIndefRowsRuntime(SIndefRowsRuntime* pRuntime, SOperatorInfo* pOperator) {
8,901,991✔
1361
  if (NULL == pRuntime) {
8,901,991✔
1362
    return;
×
1363
  }
1364

1365
  resetIndefRowsRuntime(pRuntime, pOperator);
8,901,991✔
1366
  tSimpleHashCleanup(pRuntime->pOpenStatesMap);
8,899,185✔
1367
  pRuntime->pOpenStatesMap = NULL;
8,901,090✔
1368
  pRuntime->pReadyBlocks = tdListFree(pRuntime->pReadyBlocks);
8,901,063✔
1369
  taosArrayDestroy(pRuntime->pPseudoColInfo);
8,897,916✔
1370
  pRuntime->pPseudoColInfo = NULL;
8,901,537✔
1371
  blockDataDestroy(pRuntime->pTmpBlock);
8,902,742✔
1372
  pRuntime->pTmpBlock = NULL;
8,901,013✔
1373
}
1374

1375
SIndefRowsWindowState* findIndefRowsWindowState(const SIndefRowsRuntime* pRuntime, uint64_t groupId, TSKEY winSKey) {
11,543,388✔
1376
  if (NULL == pRuntime || NULL == pRuntime->pOpenStatesMap) {
11,543,388✔
1377
    return NULL;
×
1378
  }
1379

1380
  SIndefRowsStateKey key = {.groupId = groupId, .skey = winSKey};
11,543,388✔
1381
  SIndefRowsWindowState** ppState = tSimpleHashGet(pRuntime->pOpenStatesMap, &key, sizeof(key));
11,543,388✔
1382
  return ppState ? *ppState : NULL;
11,543,388✔
1383
}
1384

1385
int32_t applyIndefRowsFuncOnWindowState(SOperatorInfo* pOperator, SIndefRowsRuntime* pRuntime,
11,453,530✔
1386
                                        SIndefRowsWindowState** ppState, SSDataBlock* pResultTemplate,
1387
                                        uint64_t groupId, const STimeWindow* pWin, SSDataBlock* pInputBlock,
1388
                                        int32_t startRow, int32_t numRows, int32_t inputTsOrder,
1389
                                        int32_t resultRowSize) {
1390
  int32_t                code = TSDB_CODE_SUCCESS;
11,453,530✔
1391
  int32_t                lino = 0;
11,453,530✔
1392
  SIndefRowsWindowState* pState = NULL;
11,453,530✔
1393

1394
  QRY_PARAM_CHECK(ppState);
11,453,530✔
1395
  if (numRows <= 0) {
11,453,530✔
1396
    return code;
×
1397
  }
1398

1399
  if (NULL == pRuntime || NULL == pRuntime->pPseudoColInfo) {
11,453,530✔
1400
    qError("%s invalid parameter, pRuntime:%p, pPseudoColInfo:%p", __func__, pRuntime, pRuntime ? pRuntime->pPseudoColInfo : NULL);
×
1401
    return TSDB_CODE_INVALID_PARA;
×
1402
  }
1403

1404
  pState = findIndefRowsWindowState(pRuntime, groupId, pWin->skey);
11,453,530✔
1405
  if (NULL == pState) {
11,453,530✔
1406
    code = createIndefRowsWindowState(pRuntime, pResultTemplate, groupId, pWin, resultRowSize, &pState);
11,204,521✔
1407
    QUERY_CHECK_CODE(code, lino, _return);
11,204,521✔
1408
    for (int32_t i = 0; i < pOperator->exprSupp.numOfExprs; ++i) {
25,055,793✔
1409
      pOperator->exprSupp.pCtx[i].pOutput = NULL;
13,851,272✔
1410
    }
1411
  } else {
1412
    // Only update ekey — groupId and skey already matched by find
1413
    pState->win.ekey = pWin->ekey;
249,009✔
1414
    pState->pRow->win.ekey = pWin->ekey;
249,009✔
1415
  }
1416

1417
  code = setResultRowInitCtx(pState->pRow, pOperator->exprSupp.pCtx, pOperator->exprSupp.numOfExprs,
11,453,530✔
1418
                             pOperator->exprSupp.rowEntryInfoOffset);
1419
  QUERY_CHECK_CODE(code, lino, _return);
11,453,530✔
1420

1421
  if (NULL == pRuntime->pTmpBlock) {
11,453,530✔
1422
    code = createOneDataBlock(pInputBlock, false, &pRuntime->pTmpBlock);
113,554✔
1423
    QUERY_CHECK_CODE(code, lino, _return);
114,038✔
1424
  } else {
1425
    blockDataCleanup(pRuntime->pTmpBlock);
11,339,492✔
1426
  }
1427

1428
  SSDataBlock* pWindowBlock = pRuntime->pTmpBlock;
11,453,530✔
1429
  code = blockDataEnsureCapacity(pWindowBlock, TMAX(1, numRows));
11,453,046✔
1430
  QUERY_CHECK_CODE(code, lino, _return);
11,453,530✔
1431
  code = blockDataMergeNRows(pWindowBlock, pInputBlock, startRow, numRows);
11,453,530✔
1432
  QUERY_CHECK_CODE(code, lino, _return);
11,453,530✔
1433

1434
  pWindowBlock->info.id = pInputBlock->info.id;
11,453,530✔
1435
  pWindowBlock->info.window = *pWin;
11,453,530✔
1436
  pWindowBlock->info.scanFlag = pInputBlock->info.scanFlag;
11,453,530✔
1437
  pWindowBlock->info.dataLoad = pInputBlock->info.dataLoad;
11,453,530✔
1438

1439
  code = setInputDataBlock(&pOperator->exprSupp, pWindowBlock, inputTsOrder, pWindowBlock->info.scanFlag, false);
11,453,530✔
1440
  QUERY_CHECK_CODE(code, lino, _return);
11,453,530✔
1441

1442
  pState->pCurBlock->info.id = pInputBlock->info.id;
11,453,530✔
1443
  pState->pCurBlock->info.window = *pWin;
11,453,530✔
1444
  pState->pCurBlock->info.scanFlag = pInputBlock->info.scanFlag;
11,453,530✔
1445
  pState->pCurBlock->info.dataLoad = 1;
11,453,530✔
1446
  code = blockDataEnsureCapacity(pState->pCurBlock, pState->pCurBlock->info.rows + pWindowBlock->info.rows);
11,453,530✔
1447
  QUERY_CHECK_CODE(code, lino, _return);
11,453,530✔
1448

1449
  code = projectApplyFunctions(pOperator->exprSupp.pExprInfo, pState->pCurBlock, pWindowBlock,
22,907,060✔
1450
                               pOperator->exprSupp.pCtx, pOperator->exprSupp.numOfExprs,
1451
                               pRuntime->pPseudoColInfo,
1452
                               GET_STM_RTINFO(pOperator->pTaskInfo), pOperator->pTaskInfo);
11,453,530✔
1453
  QUERY_CHECK_CODE(code, lino, _return);
11,453,530✔
1454

1455
  pState->pRow->nOrigRows += numRows;
11,450,135✔
1456

1457
  // Seal current block if it reached capacity
1458
  if (pState->pCurBlock->info.rows >= pRuntime->blockCapacity) {
11,450,135✔
1459
    code = tdListAppend(pState->pSealedBlocks, &pState->pCurBlock);
335,668✔
1460
    QUERY_CHECK_CODE(code, lino, _return);
335,668✔
1461
    pState->pCurBlock = NULL;
335,668✔
1462
    code = createOneDataBlock(pResultTemplate, false, &pState->pCurBlock);
335,668✔
1463
    QUERY_CHECK_CODE(code, lino, _return);
335,668✔
1464
  }
1465

1466
  *ppState = pState;
11,450,135✔
1467

1468
_return:
11,453,530✔
1469
  if (code != TSDB_CODE_SUCCESS) {
11,453,530✔
1470
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
3,395✔
1471
  }
1472

1473
  return code;
11,453,530✔
1474
}
1475

1476
int32_t closeIndefRowsWindowState(SOperatorInfo* pOperator, SIndefRowsRuntime* pRuntime, SIndefRowsWindowState* pState) {
11,201,126✔
1477
  int32_t code = TSDB_CODE_SUCCESS;
11,201,126✔
1478
  int32_t lino = 0;
11,201,126✔
1479

1480
  if (NULL == pRuntime || NULL == pState) {
11,201,126✔
1481
    return code;
×
1482
  }
1483

1484
  // Phase 1: Seal current block into sealed list (so all blocks are in one place)
1485
  if (pState->pCurBlock != NULL && pState->pCurBlock->info.rows > 0) {
11,201,126✔
1486
    code = tdListAppend(pState->pSealedBlocks, &pState->pCurBlock);
982,543✔
1487
    QUERY_CHECK_CODE(code, lino, _error);
982,543✔
1488
    pState->pCurBlock = NULL;
982,543✔
1489
  } else {
1490
    blockDataDestroy(pState->pCurBlock);
10,218,583✔
1491
    pState->pCurBlock = NULL;
10,218,583✔
1492
  }
1493

1494
  // Phase 2: Process each block — fill pseudo cols, filter, push to readyBlocks
1495
  SListNode* pNode = NULL;
11,201,126✔
1496
  while ((pNode = tdListPopHead(pState->pSealedBlocks)) != NULL) {
12,519,337✔
1497
    SSDataBlock* pBlock = *(SSDataBlock**)pNode->data;
1,318,211✔
1498
    taosMemoryFree(pNode);
1,318,211✔
1499

1500
    code = fillIndefRowsWindowPseudoCols(pOperator, pBlock, &pState->win, 0, pBlock->info.rows);
1,318,211✔
1501
    if (code != TSDB_CODE_SUCCESS) {
1,318,211✔
1502
      blockDataDestroy(pBlock);
×
1503
      qError("%s fillPseudoCols failed since %s", __func__, tstrerror(code));
×
1504
      goto _cleanup;
×
1505
    }
1506

1507
    if (pOperator->exprSupp.pFilterInfo != NULL) {
1,318,211✔
1508
      code = doFilter(pBlock, pOperator->exprSupp.pFilterInfo, NULL, NULL);
×
1509
      if (code != TSDB_CODE_SUCCESS) {
×
1510
        blockDataDestroy(pBlock);
×
1511
        qError("%s doFilter failed since %s", __func__, tstrerror(code));
×
1512
        goto _cleanup;
×
1513
      }
1514
    }
1515

1516
    if (pBlock->info.rows > 0) {
1,318,211✔
1517
      code = tdListAppend(pRuntime->pReadyBlocks, &pBlock);
1,318,211✔
1518
      if (code != TSDB_CODE_SUCCESS) {
1,318,211✔
1519
        blockDataDestroy(pBlock);
×
1520
        qError("%s append readyBlocks failed since %s", __func__, tstrerror(code));
×
1521
        goto _cleanup;
×
1522
      }
1523
    } else {
1524
      blockDataDestroy(pBlock);
×
1525
    }
1526
  }
1527

1528
  // Phase 3: All succeeded — remove from open states and destroy the state shell
1529
  removeIndefRowsOpenState(pRuntime->pOpenStatesMap, pState);
11,201,126✔
1530
  cleanupIndefRowsResultRow(pOperator, pState->pRow);
11,201,126✔
1531
  taosMemoryFreeClear(pState->pRow);
11,201,126✔
1532
  pState->pSealedBlocks = tdListFree(pState->pSealedBlocks);
11,201,126✔
1533
  taosMemoryFreeClear(pState);
11,201,126✔
1534

1535
  return TSDB_CODE_SUCCESS;
11,201,126✔
1536

1537
_error:
×
1538
  // Seal failed — state still intact in openStates, let dropAll clean up
1539
  qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
×
1540
  return code;
×
1541

1542
_cleanup:
×
1543
  // Some blocks already pushed to readyBlocks (they'll be consumed normally).
1544
  // Remaining blocks still in pSealedBlocks — destroy them along with state.
1545
  removeIndefRowsOpenState(pRuntime->pOpenStatesMap, pState);
×
1546
  destroyIndefRowsWindowState(pOperator, pState);
×
1547
  return code;
×
1548
}
1549

1550
int32_t closeAllIndefRowsWindowStates(SOperatorInfo* pOperator, SIndefRowsRuntime* pRuntime) {
119,101✔
1551
  int32_t code = TSDB_CODE_SUCCESS;
119,101✔
1552
  int32_t lino = 0;
119,101✔
1553

1554
  if (NULL == pRuntime || NULL == pRuntime->pOpenStatesMap) {
119,101✔
1555
    return code;
×
1556
  }
1557

1558
  // Collect all states first since closeIndefRowsWindowState removes from the map
1559
  int32_t numOpen = tSimpleHashGetSize(pRuntime->pOpenStatesMap);
119,101✔
1560
  if (numOpen == 0) {
119,101✔
1561
    return code;
15,699✔
1562
  }
1563

1564
  SArray* pStates = taosArrayInit(numOpen, POINTER_BYTES);
103,402✔
1565
  QUERY_CHECK_NULL(pStates, code, lino, _return, terrno);
103,402✔
1566

1567
  int32_t iter = 0;
103,402✔
1568
  void*   pData = NULL;
103,402✔
1569
  while ((pData = tSimpleHashIterate(pRuntime->pOpenStatesMap, pData, &iter)) != NULL) {
650,622✔
1570
    SIndefRowsWindowState* pState = *(SIndefRowsWindowState**)pData;
547,220✔
1571
    QUERY_CHECK_NULL(taosArrayPush(pStates, &pState), code, lino, _return, terrno);
547,220✔
1572
  }
1573

1574
  for (int32_t i = 0; i < taosArrayGetSize(pStates); ++i) {
650,622✔
1575
    SIndefRowsWindowState* pState = taosArrayGetP(pStates, i);
547,220✔
1576
    code = closeIndefRowsWindowState(pOperator, pRuntime, pState);
547,220✔
1577
    QUERY_CHECK_CODE(code, lino, _return);
547,220✔
1578
  }
1579

1580
_return:
103,402✔
1581
  taosArrayDestroy(pStates);
103,402✔
1582
  if (code != TSDB_CODE_SUCCESS) {
103,402✔
1583
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
×
1584
  }
1585
  return code;
103,402✔
1586
}
1587

1588
void dropIndefRowsWindowState(SOperatorInfo* pOperator, SIndefRowsRuntime* pRuntime, SIndefRowsWindowState* pState) {
×
1589
  if (NULL == pRuntime || NULL == pState) {
×
1590
    return;
×
1591
  }
1592

1593
  removeIndefRowsOpenState(pRuntime->pOpenStatesMap, pState);
×
1594
  destroyIndefRowsWindowState(pOperator, pState);
×
1595
}
1596

1597
void dropAllIndefRowsWindowStates(SOperatorInfo* pOperator, SIndefRowsRuntime* pRuntime) {
22,832✔
1598
  if (NULL == pRuntime || NULL == pRuntime->pOpenStatesMap) {
22,832✔
1599
    return;
×
1600
  }
1601

1602
  int32_t openCount = tSimpleHashGetSize(pRuntime->pOpenStatesMap);
22,832✔
1603
  if (openCount > 0) {
22,832✔
1604
    qDebug("%s dropping %d unclosed indefRows window state(s)", GET_TASKID(pOperator->pTaskInfo), openCount);
×
1605
  }
1606

1607
  int32_t iter = 0;
22,832✔
1608
  void*   pData = NULL;
22,832✔
1609
  while ((pData = tSimpleHashIterate(pRuntime->pOpenStatesMap, pData, &iter)) != NULL) {
22,832✔
1610
    SIndefRowsWindowState* pState = *(SIndefRowsWindowState**)pData;
×
1611
    destroyIndefRowsWindowState(pOperator, pState);
×
1612
  }
1613
  tSimpleHashClear(pRuntime->pOpenStatesMap);
22,832✔
1614
}
1615

1616
SSDataBlock* getNextIndefRowsResultBlock(SIndefRowsRuntime* pRuntime, SOperatorInfo* pOperator) {
1,538,256✔
1617
  if (NULL == pRuntime) {
1,538,256✔
1618
    return NULL;
×
1619
  }
1620

1621
  if (pRuntime->pReturnedBlock != NULL) {
1,538,256✔
1622
    blockDataDestroy(pRuntime->pReturnedBlock);
1,318,211✔
1623
    pRuntime->pReturnedBlock = NULL;
1,318,211✔
1624
  }
1625

1626
  if (NULL == pRuntime->pReadyBlocks) {
1,538,256✔
1627
    return NULL;
×
1628
  }
1629

1630
  while (listNEles(pRuntime->pReadyBlocks) > 0) {
1,538,256✔
1631
    SListNode* pNode = tdListPopHead(pRuntime->pReadyBlocks);
1,318,211✔
1632
    if (NULL == pNode) {
1,318,211✔
1633
      return NULL;
×
1634
    }
1635

1636
    SSDataBlock* pBlock = *(SSDataBlock**)pNode->data;
1,318,211✔
1637
    taosMemoryFree(pNode);
1,318,211✔
1638
    if (NULL == pBlock) {
1,318,211✔
1639
      continue;
×
1640
    }
1641

1642
    if (pBlock->info.rows > 0) {
1,318,211✔
1643
      pBlock->info.version = pOperator->pTaskInfo->version;
1,318,211✔
1644
      pBlock->info.dataLoad = 1;
1,318,211✔
1645
      pRuntime->pReturnedBlock = pBlock;
1,318,211✔
1646
      return pBlock;
1,318,211✔
1647
    }
1648

1649
    blockDataDestroy(pBlock);
×
1650
  }
1651

1652
  return NULL;
220,045✔
1653
}
1654

1655
void cleanupExprSupp(SExprSupp* pSupp) {
1,212,802,447✔
1656
  destroySqlFunctionCtx(pSupp->pCtx, pSupp->pExprInfo, pSupp->numOfExprs);
1,212,802,447✔
1657
  if (pSupp->pExprInfo != NULL) {
1,212,740,563✔
1658
    destroyExprInfo(pSupp->pExprInfo, pSupp->numOfExprs);
422,596,769✔
1659
    taosMemoryFreeClear(pSupp->pExprInfo);
422,595,472✔
1660
  }
1661

1662
  if (pSupp->pFilterInfo != NULL) {
1,212,710,419✔
1663
    filterFreeInfo(pSupp->pFilterInfo);
111,201,679✔
1664
    pSupp->pFilterInfo = NULL;
111,193,855✔
1665
  }
1666

1667
  taosMemoryFree(pSupp->rowEntryInfoOffset);
1,212,783,032✔
1668
  memset(pSupp, 0, sizeof(SExprSupp));
1,212,790,991✔
1669
}
1,212,790,991✔
1670

1671
void cleanupExprSuppWithoutFilter(SExprSupp* pSupp) {
125,614,042✔
1672
  destroySqlFunctionCtx(pSupp->pCtx, pSupp->pExprInfo, pSupp->numOfExprs);
125,614,042✔
1673
  if (pSupp->pExprInfo != NULL) {
125,610,617✔
1674
    destroyExprInfo(pSupp->pExprInfo, pSupp->numOfExprs);
37,438,596✔
1675
    taosMemoryFreeClear(pSupp->pExprInfo);
37,439,244✔
1676
  }
1677

1678
  taosMemoryFreeClear(pSupp->rowEntryInfoOffset);
125,607,596✔
1679
  pSupp->numOfExprs = 0;
125,614,913✔
1680
  pSupp->hasWindowOrGroup = false;
125,625,568✔
1681
  pSupp->pCtx = NULL;
125,615,469✔
1682
}
125,617,637✔
1683

1684
void cleanupBasicInfo(SOptrBasicInfo* pInfo) {
314,812,920✔
1685
  blockDataDestroy(pInfo->pRes);
314,812,920✔
1686
  pInfo->pRes = NULL;
314,824,561✔
1687
}
314,825,113✔
1688

1689
bool groupbyTbname(SNodeList* pGroupList) {
276,649,337✔
1690
  bool   bytbname = false;
276,649,337✔
1691
  SNode* pNode = NULL;
276,649,337✔
1692
  FOREACH(pNode, pGroupList) {
285,054,367✔
1693
    if (pNode->type == QUERY_NODE_FUNCTION) {
42,658,531✔
1694
      bytbname = (strcmp(((struct SFunctionNode*)pNode)->functionName, "tbname") == 0);
34,250,438✔
1695
      break;
34,252,634✔
1696
    }
1697
  }
1698
  return bytbname;
276,643,794✔
1699
}
1700

1701
int32_t createDataSinkParam(SDataSinkNode* pNode, void** pParam, SExecTaskInfo* pTask, SReadHandle* readHandle) {
399,951,367✔
1702
  switch (pNode->type) {
399,951,367✔
1703
    case QUERY_NODE_PHYSICAL_PLAN_QUERY_INSERT: {
534,985✔
1704
      SInserterParam* pInserterParam = taosMemoryCalloc(1, sizeof(SInserterParam));
534,985✔
1705
      if (NULL == pInserterParam) {
534,985✔
1706
        return terrno;
×
1707
      }
1708
      pInserterParam->readHandle = readHandle;
534,985✔
1709

1710
      *pParam = pInserterParam;
534,985✔
1711
      break;
534,985✔
1712
    }
1713
    case QUERY_NODE_PHYSICAL_PLAN_DELETE: {
2,091,717✔
1714
      SDeleterParam* pDeleterParam = taosMemoryCalloc(1, sizeof(SDeleterParam));
2,091,717✔
1715
      if (NULL == pDeleterParam) {
2,021,509✔
1716
        return terrno;
×
1717
      }
1718

1719
      SArray* pInfoList = NULL;
2,021,509✔
1720
      int32_t code = getTableListInfo(pTask, &pInfoList);
2,023,474✔
1721
      if (code != TSDB_CODE_SUCCESS || pInfoList == NULL) {
2,022,172✔
UNCOV
1722
        taosMemoryFree(pDeleterParam);
×
1723
        return code;
×
1724
      }
1725

1726
      STableListInfo* pTableListInfo = taosArrayGetP(pInfoList, 0);
2,022,823✔
1727
      taosArrayDestroy(pInfoList);
2,023,474✔
1728

1729
      pDeleterParam->suid = tableListGetSuid(pTableListInfo);
2,022,811✔
1730

1731
      // TODO extract uid list
1732
      int32_t numOfTables = 0;
2,022,811✔
1733
      code = tableListGetSize(pTableListInfo, &numOfTables);
2,022,811✔
1734
      if (code != TSDB_CODE_SUCCESS) {
2,023,474✔
1735
        qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(code));
×
1736
        taosMemoryFree(pDeleterParam);
×
1737
        return code;
×
1738
      }
1739

1740
      pDeleterParam->pUidList = taosArrayInit(numOfTables, sizeof(uint64_t));
2,023,474✔
1741
      if (NULL == pDeleterParam->pUidList) {
2,022,811✔
1742
        taosMemoryFree(pDeleterParam);
×
1743
        return terrno;
×
1744
      }
1745

1746
      for (int32_t i = 0; i < numOfTables; ++i) {
4,318,845✔
1747
        STableKeyInfo* pTable = tableListGetInfo(pTableListInfo, i);
2,295,371✔
1748
        if (!pTable) {
2,295,371✔
1749
          taosArrayDestroy(pDeleterParam->pUidList);
×
1750
          taosMemoryFree(pDeleterParam);
×
1751
          return TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR;
×
1752
        }
1753
        void* tmp = taosArrayPush(pDeleterParam->pUidList, &pTable->uid);
2,295,371✔
1754
        if (!tmp) {
2,295,371✔
1755
          taosArrayDestroy(pDeleterParam->pUidList);
×
1756
          taosMemoryFree(pDeleterParam);
×
1757
          return terrno;
×
1758
        }
1759
      }
1760

1761
      *pParam = pDeleterParam;
2,023,474✔
1762
      break;
2,024,113✔
1763
    }
1764
    default:
397,379,309✔
1765
      break;
397,379,309✔
1766
  }
1767

1768
  return TSDB_CODE_SUCCESS;
399,997,957✔
1769
}
1770

1771
void streamOpReleaseState(SOperatorInfo* pOperator) {
×
1772
  SOperatorInfo* downstream = pOperator->pDownstream[0];
×
1773
  if (downstream->fpSet.releaseStreamStateFn) {
×
1774
    downstream->fpSet.releaseStreamStateFn(downstream);
×
1775
  }
1776
}
×
1777

1778
void streamOpReloadState(SOperatorInfo* pOperator) {
×
1779
  SOperatorInfo* downstream = pOperator->pDownstream[0];
×
1780
  if (downstream->fpSet.reloadStreamStateFn) {
×
1781
    downstream->fpSet.reloadStreamStateFn(downstream);
×
1782
  }
1783
}
×
1784

1785
void freeOperatorParamImpl(SOperatorParam* pParam, SOperatorParamType type) {
151,534,721✔
1786
  int32_t childrenNum = taosArrayGetSize(pParam->pChildren);
151,534,721✔
1787
  for (int32_t i = 0; i < childrenNum; ++i) {
153,451,476✔
1788
    SOperatorParam* pChild = taosArrayGetP(pParam->pChildren, i);
1,915,465✔
1789
    freeOperatorParam(pChild, type);
1,915,465✔
1790
  }
1791

1792
  taosArrayDestroy(pParam->pChildren);
151,536,011✔
1793
  pParam->pChildren = NULL;
151,546,702✔
1794

1795
  taosMemoryFreeClear(pParam->value);
151,545,369✔
1796

1797
  taosMemoryFree(pParam);
151,540,637✔
1798
}
151,540,570✔
1799

1800
void freeExchangeGetBasicOperatorParam(void* pParam) {
27,088,499✔
1801
  SExchangeOperatorBasicParam* pBasic = (SExchangeOperatorBasicParam*)pParam;
27,088,499✔
1802
  if (pBasic->uidList) {
27,088,499✔
1803
    taosArrayDestroy(pBasic->uidList);
22,231,751✔
1804
    pBasic->uidList = NULL;
22,231,751✔
1805
  }
1806
  if (pBasic->orgTbInfo) {
27,088,499✔
1807
    taosArrayDestroy(pBasic->orgTbInfo->colMap);
12,205,316✔
1808
    taosMemoryFreeClear(pBasic->orgTbInfo);
12,205,316✔
1809
  }
1810
  if (pBasic->batchOrgTbInfo) {
27,088,499✔
1811
    taosArrayDestroyEx(pBasic->batchOrgTbInfo, destroySOrgTbInfo);
3,555,825✔
1812
    pBasic->batchOrgTbInfo = NULL;
3,555,825✔
1813
  }
1814
  if (pBasic->tagList) {
27,088,499✔
1815
    taosArrayDestroyEx(pBasic->tagList, destroyTagVal);
923,318✔
1816
    pBasic->tagList = NULL;
923,318✔
1817
  }
1818
}
27,088,499✔
1819

1820
void freeExchangeGetOperatorParam(SOperatorParam* pParam) {
25,742,421✔
1821
  SExchangeOperatorParam* pExcParam = (SExchangeOperatorParam*)pParam->value;
25,742,421✔
1822
  if (pExcParam->multiParams) {
25,742,421✔
1823
    SExchangeOperatorBatchParam* pExcBatch = (SExchangeOperatorBatchParam*)pParam->value;
2,491,125✔
1824
    tSimpleHashSetFreeFp(pExcBatch->pBatchs, freeExchangeGetBasicOperatorParam);
2,491,125✔
1825
    tSimpleHashCleanup(pExcBatch->pBatchs);
2,491,125✔
1826
  } else {
1827
    freeExchangeGetBasicOperatorParam(&pExcParam->basic);
23,251,296✔
1828
  }
1829

1830
  freeOperatorParamImpl(pParam, OP_GET_PARAM);
25,742,421✔
1831
}
25,742,421✔
1832

1833
void freeExchangeNotifyOperatorParam(SOperatorParam* pParam) { freeOperatorParamImpl(pParam, OP_NOTIFY_PARAM); }
×
1834

1835
void freeGroupCacheGetOperatorParam(SOperatorParam* pParam) { freeOperatorParamImpl(pParam, OP_GET_PARAM); }
8,584,384✔
1836

1837
void freeGroupCacheNotifyOperatorParam(SOperatorParam* pParam) { freeOperatorParamImpl(pParam, OP_NOTIFY_PARAM); }
×
1838

1839
void freeMergeJoinGetOperatorParam(SOperatorParam* pParam) { freeOperatorParamImpl(pParam, OP_GET_PARAM); }
4,292,192✔
1840

1841
void freeMergeJoinNotifyOperatorParam(SOperatorParam* pParam) { freeOperatorParamImpl(pParam, OP_NOTIFY_PARAM); }
×
1842

1843
void freeTagScanGetOperatorParam(SOperatorParam* pParam) { freeOperatorParamImpl(pParam, OP_GET_PARAM); }
6,760,442✔
1844

1845
void freeMergeGetOperatorParam(SOperatorParam* pParam) { freeOperatorParamImpl(pParam, OP_GET_PARAM); }
5,285,556✔
1846

1847
void freeDynQueryCtrlGetOperatorParam(SOperatorParam* pParam) { freeOperatorParamImpl(pParam, OP_GET_PARAM); }
×
1848

1849
void freeDynQueryCtrlNotifyOperatorParam(SOperatorParam* pParam) { freeOperatorParamImpl(pParam, OP_NOTIFY_PARAM); }
×
1850

1851
void freeInterpFuncGetOperatorParam(SOperatorParam* pParam) {
×
1852
  freeOperatorParamImpl(pParam, OP_GET_PARAM);
×
1853
}
×
1854

1855
void freeInterpFuncNotifyOperatorParam(SOperatorParam* pParam) {
×
1856
  freeOperatorParamImpl(pParam, OP_NOTIFY_PARAM);
×
1857
}
×
1858

1859
void freeTableScanGetOperatorParam(SOperatorParam* pParam) {
94,401,907✔
1860
  STableScanOperatorParam* pTableScanParam =
94,401,907✔
1861
    (STableScanOperatorParam*)pParam->value;
1862
  taosArrayDestroy(pTableScanParam->pUidList);
94,408,719✔
1863
  if (pTableScanParam->pOrgTbInfo) {
94,412,379✔
1864
    taosArrayDestroy(pTableScanParam->pOrgTbInfo->colMap);
82,272,904✔
1865
    taosMemoryFreeClear(pTableScanParam->pOrgTbInfo);
82,272,904✔
1866
  }
1867
  if (pTableScanParam->pBatchTbInfo) {
94,415,728✔
1868
    for (int32_t i = 0;
2,935,483✔
1869
      i < taosArrayGetSize(pTableScanParam->pBatchTbInfo); ++i) {
8,538,121✔
1870
      SOrgTbInfo* pOrgTbInfo =
1871
        (SOrgTbInfo*)taosArrayGet(pTableScanParam->pBatchTbInfo, i);
5,602,638✔
1872
      taosArrayDestroy(pOrgTbInfo->colMap);
5,602,638✔
1873
    }
1874
    taosArrayDestroy(pTableScanParam->pBatchTbInfo);
2,935,483✔
1875
    pTableScanParam->pBatchTbInfo = NULL;
2,935,483✔
1876
  }
1877
  if (pTableScanParam->pTagList) {
94,423,341✔
1878
    for (int32_t i = 0;
923,318✔
1879
      i < taosArrayGetSize(pTableScanParam->pTagList); ++i) {
5,719,704✔
1880
      STagVal* pTagVal =
1881
        (STagVal*)taosArrayGet(pTableScanParam->pTagList, i);
4,796,386✔
1882
      if (IS_VAR_DATA_TYPE(pTagVal->type)) {
4,796,386✔
1883
        taosMemoryFreeClear(pTagVal->pData);
2,082,210✔
1884
      }
1885
    }
1886
    taosArrayDestroy(pTableScanParam->pTagList);
923,318✔
1887
    pTableScanParam->pTagList = NULL;
923,318✔
1888
  }
1889
  freeOperatorParamImpl(pParam, OP_GET_PARAM);
94,425,885✔
1890
}
94,412,008✔
1891

1892
void freeTableScanNotifyOperatorParam(SOperatorParam* pParam) { freeOperatorParamImpl(pParam, OP_NOTIFY_PARAM); }
×
1893

1894
void freeTagScanNotifyOperatorParam(SOperatorParam* pParam) { freeOperatorParamImpl(pParam, OP_NOTIFY_PARAM); }
×
1895

1896
void freeMergeNotifyOperatorParam(SOperatorParam* pParam) { freeOperatorParamImpl(pParam, OP_NOTIFY_PARAM); }
×
1897

1898
void freeOpParamItem(void* pItem) {
17,445,396✔
1899
  SOperatorParam* pParam = *(SOperatorParam**)pItem;
17,445,396✔
1900
  pParam->reUse = false;
17,445,396✔
1901
  freeOperatorParam(pParam, OP_GET_PARAM);
17,445,396✔
1902
}
17,445,396✔
1903

1904
static void destroyRefColIdGroupParam(void* info) {
9,129✔
1905
  SRefColIdGroup* pGroup = (SRefColIdGroup*)info;
9,129✔
1906
  if (pGroup && pGroup->pSlotIdList) {
9,129✔
1907
    taosArrayDestroy(pGroup->pSlotIdList);
9,129✔
1908
    pGroup->pSlotIdList = NULL;
9,129✔
1909
  }
1910
}
9,129✔
1911

1912
void freeExternalWindowGetOperatorParam(SOperatorParam* pParam) {
1,223,560✔
1913
  SExternalWindowOperatorParam *pExtParam = (SExternalWindowOperatorParam*)pParam->value;
1,223,560✔
1914
  taosArrayDestroy(pExtParam->ExtWins);
1,223,560✔
1915
  for (int32_t i = 0; i < taosArrayGetSize(pParam->pChildren); i++) {
1,223,560✔
1916
    SOperatorParam* pChild = *(SOperatorParam**)taosArrayGet(pParam->pChildren, i);
×
1917
    pChild->reUse = false;
×
1918
  }
1919
  freeOperatorParamImpl(pParam, OP_GET_PARAM);
1,223,560✔
1920
}
1,223,560✔
1921

1922
void freeVirtualTableScanGetOperatorParam(SOperatorParam* pParam) {
5,240,080✔
1923
  SVTableScanOperatorParam* pVTableScanParam = (SVTableScanOperatorParam*)pParam->value;
5,240,080✔
1924
  taosArrayDestroyEx(pVTableScanParam->pOpParamArray, freeOpParamItem);
5,240,080✔
1925
  if (pVTableScanParam->pRefColGroups) {
5,240,080✔
1926
    taosArrayDestroyEx(pVTableScanParam->pRefColGroups, destroyRefColIdGroupParam);
5,624✔
1927
    pVTableScanParam->pRefColGroups = NULL;
5,624✔
1928
  }
1929
  freeOpParamItem(&pVTableScanParam->pTagScanOp);
5,240,080✔
1930
  freeOperatorParamImpl(pParam, OP_GET_PARAM);
5,240,080✔
1931
}
5,240,080✔
1932

1933
void freeVTableScanNotifyOperatorParam(SOperatorParam* pParam) { freeOperatorParamImpl(pParam, OP_NOTIFY_PARAM); }
×
1934

1935
void freeExternalWindowNotifyOperatorParam(SOperatorParam* pParam) { freeOperatorParamImpl(pParam, OP_NOTIFY_PARAM); }
×
1936

1937
void freeOperatorParam(SOperatorParam* pParam, SOperatorParamType type) {
879,805,180✔
1938
  if (NULL == pParam || pParam->reUse) {
879,805,180✔
1939
    return;
728,253,231✔
1940
  }
1941

1942
  switch (pParam->opType) {
151,553,962✔
1943
    case QUERY_NODE_PHYSICAL_PLAN_EXCHANGE:
25,742,421✔
1944
      type == OP_GET_PARAM ? freeExchangeGetOperatorParam(pParam) : freeExchangeNotifyOperatorParam(pParam);
25,742,421✔
1945
      break;
25,742,421✔
1946
    case QUERY_NODE_PHYSICAL_PLAN_GROUP_CACHE:
8,584,384✔
1947
      type == OP_GET_PARAM ? freeGroupCacheGetOperatorParam(pParam) : freeGroupCacheNotifyOperatorParam(pParam);
8,584,384✔
1948
      break;
8,584,384✔
1949
    case QUERY_NODE_PHYSICAL_PLAN_MERGE_JOIN:
4,292,192✔
1950
      type == OP_GET_PARAM ? freeMergeJoinGetOperatorParam(pParam) : freeMergeJoinNotifyOperatorParam(pParam);
4,292,192✔
1951
      break;
4,292,192✔
1952
    case QUERY_NODE_PHYSICAL_PLAN_TABLE_MERGE_SCAN:
94,418,283✔
1953
    case QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN:
1954
      type == OP_GET_PARAM ? freeTableScanGetOperatorParam(pParam) : freeTableScanNotifyOperatorParam(pParam);
94,418,283✔
1955
      break;
94,413,255✔
1956
    case QUERY_NODE_PHYSICAL_PLAN_VIRTUAL_TABLE_SCAN:
5,240,080✔
1957
      type == OP_GET_PARAM ? freeVirtualTableScanGetOperatorParam(pParam) : freeVTableScanNotifyOperatorParam(pParam);
5,240,080✔
1958
      break;
5,240,080✔
1959
    case QUERY_NODE_PHYSICAL_PLAN_TAG_SCAN:
6,760,442✔
1960
      type == OP_GET_PARAM ? freeTagScanGetOperatorParam(pParam) : freeTagScanNotifyOperatorParam(pParam);
6,760,442✔
1961
      break;
6,760,442✔
1962
    case QUERY_NODE_PHYSICAL_PLAN_HASH_AGG:
5,285,556✔
1963
    case QUERY_NODE_PHYSICAL_PLAN_HASH_INTERVAL:
1964
    case QUERY_NODE_PHYSICAL_PLAN_MERGE:
1965
    case QUERY_NODE_PHYSICAL_PLAN_MERGE_INTERVAL:
1966
    case QUERY_NODE_PHYSICAL_PLAN_MERGE_ALIGNED_INTERVAL:
1967
      type == OP_GET_PARAM ? freeMergeGetOperatorParam(pParam) : freeMergeNotifyOperatorParam(pParam);
5,285,556✔
1968
      break;
5,284,884✔
1969
    case QUERY_NODE_PHYSICAL_PLAN_EXTERNAL_WINDOW:
1,223,560✔
1970
      type == OP_GET_PARAM ? freeExternalWindowGetOperatorParam(pParam) : freeExternalWindowNotifyOperatorParam(pParam);
1,223,560✔
1971
      break;
1,223,560✔
1972
    case QUERY_NODE_PHYSICAL_PLAN_DYN_QUERY_CTRL:
×
1973
      type == OP_GET_PARAM ? freeDynQueryCtrlGetOperatorParam(pParam) : freeDynQueryCtrlNotifyOperatorParam(pParam);
×
1974
      break;
×
1975
    case QUERY_NODE_PHYSICAL_PLAN_INTERP_FUNC:
×
1976
      type == OP_GET_PARAM ? freeInterpFuncGetOperatorParam(pParam) : freeInterpFuncNotifyOperatorParam(pParam);
×
1977
      break;
×
1978
    default:
7,474✔
1979
      qError("%s unsupported op %d param, param type %d, param:%p value:%p children:%p reuse:%d",
7,474✔
1980
             __func__, pParam->opType, type, pParam, pParam->value, pParam->pChildren, pParam->reUse);
1981
      break;
×
1982
  }
1983
}
1984

1985
void freeResetOperatorParams(struct SOperatorInfo* pOperator, SOperatorParamType type, bool allFree) {
1,890,252,715✔
1986
  SOperatorParam**  ppParam = NULL;
1,890,252,715✔
1987
  SOperatorParam*** pppDownstramParam = NULL;
1,890,252,715✔
1988
  switch (type) {
1,890,252,715✔
1989
    case OP_GET_PARAM:
1,004,598,198✔
1990
      ppParam = &pOperator->pOperatorGetParam;
1,004,598,198✔
1991
      pppDownstramParam = &pOperator->pDownstreamGetParams;
1,004,610,701✔
1992
      break;
1,004,590,213✔
1993
    case OP_NOTIFY_PARAM:
885,711,108✔
1994
      ppParam = &pOperator->pOperatorNotifyParam;
885,711,108✔
1995
      pppDownstramParam = &pOperator->pDownstreamNotifyParams;
885,707,213✔
1996
      break;
885,707,011✔
1997
    default:
×
1998
      return;
×
1999
  }
2000

2001
  if (*ppParam) {
1,890,297,224✔
2002
    qDebug("%s free self param, operator:%s type:%d paramType:%d param:%p", __func__, pOperator->name,
9,625,312✔
2003
           pOperator->operatorType, type, *ppParam);
2004
    freeOperatorParam(*ppParam, type);
9,625,312✔
2005
    *ppParam = NULL;
9,625,312✔
2006
  }
2007

2008
  if (*pppDownstramParam) {
1,890,256,251✔
2009
    for (int32_t i = 0; i < pOperator->numOfDownstream; ++i) {
148,376,736✔
2010
      if ((*pppDownstramParam)[i]) {
26,085,286✔
2011
        qDebug("%s free downstream param, operator:%s type:%d idx:%d downstream:%s paramType:%d param:%p", __func__,
×
2012
               pOperator->name, pOperator->operatorType, i, pOperator->pDownstream[i]->name, type,
2013
               (*pppDownstramParam)[i]);
2014
        freeOperatorParam((*pppDownstramParam)[i], type);
×
2015
        (*pppDownstramParam)[i] = NULL;
×
2016
      }
2017
    }
2018
    if (allFree) {
122,291,495✔
2019
      taosMemoryFreeClear(*pppDownstramParam);
24,218,405✔
2020
    }
2021
  }
2022
}
2023

2024
FORCE_INLINE int32_t getNextBlockFromDownstreamImpl(struct SOperatorInfo* pOperator, int32_t idx, bool clearParam,
1,213,558,353✔
2025
                                                    SSDataBlock** pResBlock) {
2026
  QRY_PARAM_CHECK(pResBlock);
1,213,558,353✔
2027

2028
  int32_t code = 0;
1,213,661,644✔
2029
  if (pOperator->pDownstreamGetParams && pOperator->pDownstreamGetParams[idx]) {
1,213,661,644✔
2030
    qDebug("DynOp: op %s start to get block from downstream %s", pOperator->name, pOperator->pDownstream[idx]->name);
21,376,267✔
2031
    code = pOperator->pDownstream[idx]->fpSet.getNextExtFn(pOperator->pDownstream[idx],
42,753,015✔
2032
                                                           pOperator->pDownstreamGetParams[idx], pResBlock);
21,376,267✔
2033
    if (clearParam && (code == 0)) {
21,376,267✔
2034
      qDebug("%s clear downstream param, operator:%s type:%d idx:%d downstream:%s param:%p", __func__,
8,321,682✔
2035
             pOperator->name, pOperator->operatorType, idx, pOperator->pDownstream[idx]->name,
2036
             pOperator->pDownstreamGetParams[idx]);
2037
      freeOperatorParam(pOperator->pDownstreamGetParams[idx], OP_GET_PARAM);
8,322,163✔
2038
      pOperator->pDownstreamGetParams[idx] = NULL;
8,321,682✔
2039
    }
2040

2041
    if (code) {
21,376,267✔
2042
      qError("failed to get next data block from upstream at %s, line:%d code:%s", __func__, __LINE__, tstrerror(code));
×
2043
    }
2044
    return code;
21,376,267✔
2045
  }
2046

2047
  code = pOperator->pDownstream[idx]->fpSet.getNextFn(pOperator->pDownstream[idx], pResBlock);
1,192,245,775✔
2048
  if (code) {
1,189,092,904✔
2049
    qError("failed to get next data block from upstream at %s, %d code:%s", __func__, __LINE__, tstrerror(code));
×
2050
  }
2051
  return code;
1,189,057,441✔
2052
}
2053

2054
bool compareVal(const char* v, const SStateKeys* pKey) {
2,147,483,647✔
2055
  if (IS_VAR_DATA_TYPE(pKey->type)) {
2,147,483,647✔
2056
    if (IS_STR_DATA_BLOB(pKey->type)) {
500,134✔
2057
      if (blobDataLen(v) != blobDataLen(pKey->pData)) {
×
2058
        return false;
×
2059
      } else {
2060
        return memcmp(blobDataVal(v), blobDataVal(pKey->pData), blobDataLen(v)) == 0;
×
2061
      }
2062
    } else {
2063
      if (varDataLen(v) != varDataLen(pKey->pData)) {
500,134✔
2064
        return false;
464✔
2065
      } else {
2066
        return memcmp(varDataVal(v), varDataVal(pKey->pData), varDataLen(v)) == 0;
499,670✔
2067
      }
2068
    }
2069
  } else {
2070
    return memcmp(pKey->pData, v, pKey->bytes) == 0;
2,147,483,647✔
2071
  }
2072
}
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