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

taosdata / TDengine / #4881

14 Dec 2025 03:48AM UTC coverage: 60.617% (+0.5%) from 60.092%
#4881

push

travis-ci

web-flow
test: update coverage workflow time (#33918)

156854 of 258761 relevant lines covered (60.62%)

75258957.81 hits per line

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

85.87
/source/libs/executor/src/eventwindowoperator.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 "executorInt.h"
17
#include "filter.h"
18
#include "function.h"
19
#include "functionMgt.h"
20
#include "operator.h"
21
#include "querytask.h"
22
#include "tcommon.h"
23
#include "tcompare.h"
24
#include "tdatablock.h"
25
#include "ttime.h"
26

27
static int32_t eventWindowAggregateNext(SOperatorInfo* pOperator, SSDataBlock** pRes);
28
static void    destroyEWindowOperatorInfo(void* param);
29
static int32_t eventWindowAggImpl(SOperatorInfo* pOperator, SEventWindowOperatorInfo* pInfo, SSDataBlock* pBlock);
30
void cleanupResultInfoInEventWindow(SOperatorInfo* pOperator, SEventWindowOperatorInfo* pInfo);
31

32
static int32_t resetEventWindowOperState(SOperatorInfo* pOper) {
×
33
  SEventWindowOperatorInfo* pEvent = pOper->info;
×
34
  SExecTaskInfo*           pTaskInfo = pOper->pTaskInfo;
×
35
  SEventWinodwPhysiNode* pPhynode = (SEventWinodwPhysiNode*)pOper->pPhyNode;
×
36
  pOper->status = OP_NOT_OPENED;
×
37

38
  resetBasicOperatorState(&pEvent->binfo);
×
39
  taosMemoryFreeClear(pEvent->pRow);
×
40

41
  pEvent->groupId = 0;
×
42
  pEvent->pPreDataBlock = NULL;
×
43
  pEvent->inWindow = false;
×
44
  pEvent->winSup.lastTs = INT64_MIN;
×
45

46
  colDataDestroy(&pEvent->twAggSup.timeWindowData);
×
47
  int32_t code = initExecTimeWindowInfo(&pEvent->twAggSup.timeWindowData, &pTaskInfo->window);
×
48
  cleanupResultInfoInEventWindow(pOper, pEvent);
×
49

50
  if (code == 0) {
×
51
    code = resetAggSup(&pOper->exprSupp, &pEvent->aggSup, pTaskInfo, pPhynode->window.pFuncs, NULL,
×
52
                       sizeof(int64_t) * 2 + POINTER_BYTES, pTaskInfo->id.str, pTaskInfo->streamInfo.pState,
×
53
                       &pTaskInfo->storageAPI.functionStore);
54
  }
55
  if (code == 0) {
×
56
    code = resetExprSupp(&pEvent->scalarSup, pTaskInfo, pPhynode->window.pExprs, NULL,
×
57
                         &pTaskInfo->storageAPI.functionStore);
58
  }
59
  return code;
×
60
}
61

62
int32_t createEventwindowOperatorInfo(SOperatorInfo* downstream, SPhysiNode* physiNode,
63,297✔
63
                                             SExecTaskInfo* pTaskInfo, SOperatorInfo** pOptrInfo) {
64
  QRY_PARAM_CHECK(pOptrInfo);
63,297✔
65

66
  int32_t                   code = TSDB_CODE_SUCCESS;
63,297✔
67
  int32_t                   lino = 0;
63,297✔
68
  SEventWindowOperatorInfo* pInfo = taosMemoryCalloc(1, sizeof(SEventWindowOperatorInfo));
63,297✔
69
  SOperatorInfo*            pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo));
63,297✔
70
  if (pInfo == NULL || pOperator == NULL) {
63,297✔
71
    code = terrno;
×
72
    goto _error;
×
73
  }
74

75
  pOperator->pPhyNode = physiNode;
63,297✔
76
  pOperator->exprSupp.hasWindowOrGroup = true;
63,297✔
77
  pOperator->exprSupp.hasWindow = true;
63,297✔
78

79
  SEventWinodwPhysiNode* pEventWindowNode = (SEventWinodwPhysiNode*)physiNode;
63,297✔
80

81
  int32_t tsSlotId = ((SColumnNode*)pEventWindowNode->window.pTspk)->slotId;
63,297✔
82
  code = filterInitFromNode((SNode*)pEventWindowNode->pStartCond, &pInfo->pStartCondInfo, 0,
63,297✔
83
                            pTaskInfo->pStreamRuntimeInfo);
63,297✔
84
  QUERY_CHECK_CODE(code, lino, _error);
63,297✔
85

86
  code = filterInitFromNode((SNode*)pEventWindowNode->pEndCond, &pInfo->pEndCondInfo, 0,
63,297✔
87
                            pTaskInfo->pStreamRuntimeInfo);
63,297✔
88
  QUERY_CHECK_CODE(code, lino, _error);
63,297✔
89

90
  if (pEventWindowNode->window.pExprs != NULL) {
63,297✔
91
    int32_t    numOfScalarExpr = 0;
306✔
92
    SExprInfo* pScalarExprInfo = NULL;
306✔
93

94
    code = createExprInfo(pEventWindowNode->window.pExprs, NULL, &pScalarExprInfo, &numOfScalarExpr);
306✔
95
    QUERY_CHECK_CODE(code, lino, _error);
306✔
96
    code = initExprSupp(&pInfo->scalarSup, pScalarExprInfo, numOfScalarExpr, &pTaskInfo->storageAPI.functionStore);
306✔
97
    QUERY_CHECK_CODE(code, lino, _error);
306✔
98
  }
99

100
  code = filterInitFromNode((SNode*)pEventWindowNode->window.node.pConditions, &pOperator->exprSupp.pFilterInfo, 0,
63,297✔
101
                            pTaskInfo->pStreamRuntimeInfo);
63,297✔
102
  QUERY_CHECK_CODE(code, lino, _error);
63,297✔
103

104
  size_t keyBufSize = sizeof(int64_t) + sizeof(int64_t) + POINTER_BYTES;
63,297✔
105

106
  int32_t    num = 0;
63,297✔
107
  SExprInfo* pExprInfo = NULL;
63,297✔
108
  code = createExprInfo(pEventWindowNode->window.pFuncs, NULL, &pExprInfo, &num);
63,297✔
109
  QUERY_CHECK_CODE(code, lino, _error);
63,297✔
110

111
  initResultSizeInfo(&pOperator->resultInfo, 4096);
63,297✔
112

113
  code = initAggSup(&pOperator->exprSupp, &pInfo->aggSup, pExprInfo, num, keyBufSize, pTaskInfo->id.str,
126,594✔
114
                    pTaskInfo->streamInfo.pState, &pTaskInfo->storageAPI.functionStore);
63,297✔
115
  QUERY_CHECK_CODE(code, lino, _error);
63,297✔
116

117
  SSDataBlock* pResBlock = createDataBlockFromDescNode(pEventWindowNode->window.node.pOutputDataBlockDesc);
63,297✔
118
  QUERY_CHECK_NULL(pResBlock, code, lino, _error, terrno);
63,297✔
119
  initBasicInfo(&pInfo->binfo, pResBlock);
63,297✔
120

121
  code = blockDataEnsureCapacity(pResBlock, pOperator->resultInfo.capacity);
63,297✔
122
  QUERY_CHECK_CODE(code, lino, _error);
63,297✔
123

124
  initResultRowInfo(&pInfo->binfo.resultRowInfo);
63,297✔
125
  pInfo->binfo.inputTsOrder = physiNode->inputTsOrder;
63,297✔
126
  pInfo->binfo.outputTsOrder = physiNode->outputTsOrder;
63,297✔
127
  pInfo->winSup.lastTs = INT64_MIN;
63,297✔
128

129
  code = initExecTimeWindowInfo(&pInfo->twAggSup.timeWindowData, &pTaskInfo->window);
63,297✔
130
  QUERY_CHECK_CODE(code, lino, _error);
63,297✔
131

132
  pInfo->tsSlotId = tsSlotId;
63,297✔
133
  pInfo->pPreDataBlock = NULL;
63,297✔
134
  pInfo->pOperator = pOperator;
63,297✔
135
  pInfo->trueForLimit = pEventWindowNode->trueForLimit;
63,297✔
136

137
  setOperatorInfo(pOperator, "EventWindowOperator", QUERY_NODE_PHYSICAL_PLAN_MERGE_EVENT, true, OP_NOT_OPENED, pInfo,
63,297✔
138
                  pTaskInfo);
139
  pOperator->fpSet = createOperatorFpSet(optrDummyOpenFn, eventWindowAggregateNext, NULL, destroyEWindowOperatorInfo,
63,297✔
140
                                         optrDefaultBufFn, NULL, optrDefaultGetNextExtFn, NULL);
141

142
  setOperatorResetStateFn(pOperator, resetEventWindowOperState);
63,297✔
143
  code = appendDownstream(pOperator, &downstream, 1);
63,297✔
144
  if (code != TSDB_CODE_SUCCESS) {
63,297✔
145
    goto _error;
×
146
  }
147

148
  *pOptrInfo = pOperator;
63,297✔
149
  return TSDB_CODE_SUCCESS;
63,297✔
150

151
_error:
×
152
  if (pInfo != NULL) {
×
153
    destroyEWindowOperatorInfo(pInfo);
×
154
  }
155

156
  destroyOperatorAndDownstreams(pOperator, &downstream, 1);
×
157
  pTaskInfo->code = code;
×
158
  return code;
×
159
}
160

161
void cleanupResultInfoInEventWindow(SOperatorInfo* pOperator, SEventWindowOperatorInfo* pInfo) {
63,297✔
162
  if (pInfo == NULL || pInfo->pRow == NULL || pOperator == NULL) {
63,297✔
163
    return;
22,057✔
164
  }
165
  SExprSupp*       pSup = &pOperator->exprSupp;
41,240✔
166
  for (int32_t j = 0; j < pSup->numOfExprs; ++j) {
478,885✔
167
    pSup->pCtx[j].resultInfo = getResultEntryInfo(pInfo->pRow, j, pSup->rowEntryInfoOffset);
437,645✔
168
    if (pSup->pCtx[j].fpSet.cleanup) {
437,645✔
169
      pSup->pCtx[j].fpSet.cleanup(&pSup->pCtx[j]);
×
170
    }
171
  }
172
}
173

174
void destroyEWindowOperatorInfo(void* param) {
63,297✔
175
  SEventWindowOperatorInfo* pInfo = (SEventWindowOperatorInfo*)param;
63,297✔
176
  if (pInfo == NULL) {
63,297✔
177
    return;
×
178
  }
179

180
  if (pInfo->pRow != NULL) {
63,297✔
181
    taosMemoryFree(pInfo->pRow);
41,240✔
182
  }
183

184
  if (pInfo->pStartCondInfo != NULL) {
63,297✔
185
    filterFreeInfo(pInfo->pStartCondInfo);
63,297✔
186
    pInfo->pStartCondInfo = NULL;
63,297✔
187
  }
188

189
  if (pInfo->pEndCondInfo != NULL) {
63,297✔
190
    filterFreeInfo(pInfo->pEndCondInfo);
63,297✔
191
    pInfo->pEndCondInfo = NULL;
63,297✔
192
  }
193

194
  cleanupBasicInfo(&pInfo->binfo);
63,297✔
195
  colDataDestroy(&pInfo->twAggSup.timeWindowData);
63,297✔
196

197
  cleanupResultInfoInEventWindow(pInfo->pOperator, pInfo);
63,297✔
198
  pInfo->pOperator = NULL;
63,297✔
199
  cleanupAggSup(&pInfo->aggSup);
63,297✔
200
  cleanupExprSupp(&pInfo->scalarSup);
63,043✔
201
  taosMemoryFreeClear(param);
63,297✔
202
}
203

204
static int32_t eventWindowAggregateNext(SOperatorInfo* pOperator, SSDataBlock** ppRes) {
74,915✔
205
  int32_t                   code = TSDB_CODE_SUCCESS;
74,915✔
206
  int32_t                   lino = 0;
74,915✔
207
  SEventWindowOperatorInfo* pInfo = pOperator->info;
74,915✔
208
  SExecTaskInfo*            pTaskInfo = pOperator->pTaskInfo;
74,915✔
209

210
  SExprSupp* pSup = &pOperator->exprSupp;
74,915✔
211
  int32_t    order = pInfo->binfo.inputTsOrder;
74,915✔
212

213
  SSDataBlock* pRes = pInfo->binfo.pRes;
74,915✔
214

215
  blockDataCleanup(pRes);
74,915✔
216

217
  SOperatorInfo* downstream = pOperator->pDownstream[0];
74,915✔
218
  while (1) {
498,637✔
219
    SSDataBlock* pBlock = NULL;
573,552✔
220
    if (pInfo->pPreDataBlock == NULL) {
573,552✔
221
      pBlock = getNextBlockFromDownstream(pOperator, 0);
570,170✔
222
    } else {
223
      pBlock = pInfo->pPreDataBlock;
3,636✔
224
      pInfo->pPreDataBlock = NULL;
3,636✔
225
    }
226

227
    if (pBlock == NULL) {
573,806✔
228
      break;
58,434✔
229
    }
230

231
    pRes->info.scanFlag = pBlock->info.scanFlag;
515,372✔
232
    code = setInputDataBlock(pSup, pBlock, order, pBlock->info.scanFlag, true);
515,372✔
233
    QUERY_CHECK_CODE(code, lino, _end);
515,372✔
234

235
    code = blockDataUpdateTsWindow(pBlock, pInfo->tsSlotId);
515,372✔
236
    QUERY_CHECK_CODE(code, lino, _end);
515,372✔
237

238
    // there is an scalar expression that needs to be calculated right before apply the group aggregation.
239
    if (pInfo->scalarSup.pExprInfo != NULL) {
515,372✔
240
      code = projectApplyFunctions(pInfo->scalarSup.pExprInfo, pBlock, pBlock, pInfo->scalarSup.pCtx,
814✔
241
                                   pInfo->scalarSup.numOfExprs, NULL, GET_STM_RTINFO(pOperator->pTaskInfo));
814✔
242
      QUERY_CHECK_CODE(code, lino, _end);
814✔
243
    }
244

245
    code = eventWindowAggImpl(pOperator, pInfo, pBlock);
515,372✔
246
    QUERY_CHECK_CODE(code, lino, _end);
515,118✔
247

248
    code = doFilter(pRes, pSup->pFilterInfo, NULL, NULL);
510,105✔
249
    QUERY_CHECK_CODE(code, lino, _end);
510,105✔
250

251
    if (pRes->info.rows >= pOperator->resultInfo.threshold ||
510,105✔
252
        (pRes->info.id.groupId != pInfo->groupId && pRes->info.rows > 0)) {
500,627✔
253
      (*ppRes) = pRes;
11,468✔
254
      return code;
11,468✔
255
    }
256
  }
257

258
_end:
63,447✔
259
  if (code != TSDB_CODE_SUCCESS) {
63,447✔
260
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
5,013✔
261
    pTaskInfo->code = code;
5,013✔
262
    T_LONG_JMP(pTaskInfo->env, code);
5,013✔
263
  }
264
  (*ppRes) =  pRes->info.rows == 0 ? NULL : pRes;
58,434✔
265
  return code;
58,434✔
266
}
267

268
static int32_t setSingleOutputTupleBufv1(SResultRowInfo* pResultRowInfo, STimeWindow* win, SResultRow** pResult,
62,763,471✔
269
                                         SExprSupp* pExprSup, SAggSupporter* pAggSup) {
270
  if (*pResult == NULL) {
62,763,471✔
271
    SResultRow* p = taosMemoryCalloc(1, pAggSup->resultRowSize);
41,240✔
272
    if (!p) {
41,240✔
273
      return terrno;
×
274
    }
275
    pResultRowInfo->cur = (SResultRowPosition){.pageId = p->pageId, .offset = p->offset};
41,240✔
276
    *pResult = p;
41,240✔
277
  }
278

279
  (*pResult)->win = *win;
62,763,471✔
280

281
  return setResultRowInitCtx(*pResult, pExprSup->pCtx, pExprSup->numOfExprs, pExprSup->rowEntryInfoOffset);
62,763,471✔
282
}
283

284
static int32_t doEventWindowAggImpl(SEventWindowOperatorInfo* pInfo, SExprSupp* pSup, int32_t startIndex,
62,763,471✔
285
                                    int32_t endIndex, const SSDataBlock* pBlock, int64_t* tsList,
286
                                    SExecTaskInfo* pTaskInfo) {
287
  int32_t code = TSDB_CODE_SUCCESS;
62,763,471✔
288
  SWindowRowsSup* pRowSup = &pInfo->winSup;
62,763,471✔
289

290
  int32_t numOfOutput = pSup->numOfExprs;
62,763,471✔
291
  int32_t numOfRows = endIndex - startIndex + 1;
62,763,471✔
292

293
  doKeepTuple(pRowSup, tsList[endIndex], endIndex, pBlock->info.id.groupId);
62,763,471✔
294

295
  code = setSingleOutputTupleBufv1(&pInfo->binfo.resultRowInfo, &pRowSup->win, &pInfo->pRow, pSup, &pInfo->aggSup);
62,763,471✔
296
  if (code != TSDB_CODE_SUCCESS) {  // null data, too many state code
62,763,471✔
297
    qError("failed to set single output tuple buffer, code:%d", code);
×
298
    return code;
×
299
  }
300

301
  updateTimeWindowInfo(&pInfo->twAggSup.timeWindowData, &pRowSup->win, 0);
62,763,471✔
302
  code = applyAggFunctionOnPartialTuples(pTaskInfo, pSup->pCtx, &pInfo->twAggSup.timeWindowData, startIndex, numOfRows,
62,763,471✔
303
                                         pBlock->info.rows, numOfOutput);
62,763,471✔
304
  return code;
62,763,217✔
305
}
306

307
int32_t eventWindowAggImpl(SOperatorInfo* pOperator, SEventWindowOperatorInfo* pInfo, SSDataBlock* pBlock) {
515,372✔
308
  int32_t          code = TSDB_CODE_SUCCESS;
515,372✔
309
  int32_t          lino = 0;
515,372✔
310
  SExecTaskInfo*   pTaskInfo = pOperator->pTaskInfo;
515,372✔
311
  SExprSupp*       pSup = &pOperator->exprSupp;
515,372✔
312
  SSDataBlock*     pRes = pInfo->binfo.pRes;
515,372✔
313
  int64_t          gid = pBlock->info.id.groupId;
515,372✔
314
  SColumnInfoData *ps = NULL, *pe = NULL;
515,372✔
315
  SColumnInfoData* pColInfoData = taosArrayGet(pBlock->pDataBlock, pInfo->tsSlotId);
515,372✔
316
  QUERY_CHECK_NULL(pColInfoData, code, lino, _return, terrno);
515,372✔
317
  TSKEY*           tsList = (TSKEY*)pColInfoData->pData;
515,372✔
318
  SWindowRowsSup*  pRowSup = &pInfo->winSup;
515,372✔
319
  int32_t          rowIndex = 0;
515,372✔
320
  int64_t          minWindowSize = getMinWindowSize(pOperator);
515,372✔
321

322
  pRowSup->numOfRows = 0;
515,372✔
323
  if (pInfo->groupId == 0) {
515,372✔
324
    pInfo->groupId = gid;
501,224✔
325
  } else if (pInfo->groupId != gid) {
14,148✔
326
    // this is a new group, reset the info
327
    pInfo->inWindow = false;
3,636✔
328
    pInfo->groupId = gid;
3,636✔
329
    pInfo->winSup.lastTs = INT64_MIN;
3,636✔
330
    pInfo->pPreDataBlock = pBlock;
3,636✔
331
    goto _return;
3,636✔
332
  }
333
  pRes->info.id.groupId = pInfo->groupId;
511,736✔
334

335
  SFilterColumnParam param1 = {.numOfCols = taosArrayGetSize(pBlock->pDataBlock), .pDataBlock = pBlock->pDataBlock};
511,736✔
336

337
  code = filterSetDataFromSlotId(pInfo->pStartCondInfo, &param1);
511,736✔
338
  QUERY_CHECK_CODE(code, lino, _return);
511,736✔
339

340
  int32_t status1 = 0;
511,736✔
341
  code = filterExecute(pInfo->pStartCondInfo, pBlock, &ps, NULL, param1.numOfCols, &status1);
511,736✔
342
  QUERY_CHECK_CODE(code, lino, _return);
511,736✔
343

344
  SFilterColumnParam param2 = {.numOfCols = taosArrayGetSize(pBlock->pDataBlock), .pDataBlock = pBlock->pDataBlock};
511,736✔
345
  code = filterSetDataFromSlotId(pInfo->pEndCondInfo, &param2);
511,736✔
346
  QUERY_CHECK_CODE(code, lino, _return);
511,736✔
347

348
  int32_t status2 = 0;
511,736✔
349
  code = filterExecute(pInfo->pEndCondInfo, pBlock, &pe, NULL, param2.numOfCols, &status2);
511,736✔
350
  QUERY_CHECK_CODE(code, lino, _return);
511,736✔
351

352
  for (int32_t i = 0; i < pBlock->info.rows; ++i) {
498,460,373✔
353
    if (pBlock->info.scanFlag != PRE_SCAN) {
497,953,650✔
354
      if (pInfo->winSup.lastTs == INT64_MIN) {
497,953,650✔
355
        pInfo->winSup.lastTs = tsList[i];
49,889✔
356
      } else {
357
        if (tsList[i] == pInfo->winSup.lastTs) {
497,903,761✔
358
          qError("duplicate timestamp found in event window operator, groupId: %" PRId64 ", timestamp: %" PRId64,
5,013✔
359
                 gid, tsList[i]);
360
          code = TSDB_CODE_QRY_WINDOW_DUP_TIMESTAMP;
5,013✔
361
          QUERY_CHECK_CODE(code, lino, _return);
5,013✔
362
        } else {
363
          pInfo->winSup.lastTs = tsList[i];
497,898,748✔
364
        }
365
      }
366
    }
367
  }
368
  int32_t startIndex = pInfo->inWindow ? 0 : -1;
506,723✔
369
  while (rowIndex < pBlock->info.rows) {
125,740,828✔
370
    if (pInfo->inWindow) {  // let's find the first end value
125,365,315✔
371
      for (rowIndex = startIndex; rowIndex < pBlock->info.rows; ++rowIndex) {
361,415,824✔
372
        if (((bool*)pe->pData)[rowIndex]) {
361,104,777✔
373
          break;
62,452,424✔
374
        }
375
      }
376

377
      if (rowIndex < pBlock->info.rows) {
62,763,471✔
378
        code = doEventWindowAggImpl(pInfo, pSup, startIndex, rowIndex, pBlock, tsList, pTaskInfo);
62,452,424✔
379
        QUERY_CHECK_CODE(code, lino, _return);
62,452,424✔
380
        doUpdateNumOfRows(pSup->pCtx, pInfo->pRow, pSup->numOfExprs, pSup->rowEntryInfoOffset);
62,452,424✔
381

382
        if (pRowSup->win.ekey - pRowSup->win.skey < minWindowSize) {
62,452,424✔
383
          qDebug("skip small window, groupId: %" PRId64 ", windowSize: %" PRId64 ", minWindowSize: %" PRId64,
×
384
                 pInfo->groupId, pRowSup->win.ekey - pRowSup->win.skey, minWindowSize);
385
        } else {
386
          // check buffer size
387
          if (pRes->info.rows + pInfo->pRow->numOfRows >= pRes->info.capacity) {
62,452,424✔
388
            int32_t newSize = pRes->info.rows + pInfo->pRow->numOfRows;
×
389
            code = blockDataEnsureCapacity(pRes, newSize);
×
390
            QUERY_CHECK_CODE(code, lino, _return);
×
391
          }
392

393
          code = copyResultrowToDataBlock(pSup->pExprInfo, pSup->numOfExprs, pInfo->pRow, pSup->pCtx, pRes,
62,452,424✔
394
                                          pSup->rowEntryInfoOffset, pTaskInfo);
62,452,424✔
395
          QUERY_CHECK_CODE(code, lino, _return);
62,452,424✔
396

397
          pRes->info.rows += pInfo->pRow->numOfRows;
62,452,424✔
398
        }
399
        pInfo->pRow->numOfRows = 0;
62,452,424✔
400

401
        pInfo->inWindow = false;
62,452,424✔
402
        rowIndex += 1;
62,452,424✔
403
      } else {
404
        code = doEventWindowAggImpl(pInfo, pSup, startIndex, pBlock->info.rows - 1, pBlock, tsList, pTaskInfo);
311,047✔
405
        QUERY_CHECK_CODE(code, lino, _return);
310,793✔
406
      }
407
    } else {  // find the first start value that is fulfill for the start condition
408
      for (; rowIndex < pBlock->info.rows; ++rowIndex) {
199,440,691✔
409
        if (((bool*)ps->pData)[rowIndex]) {
199,309,735✔
410
          doKeepNewWindowStartInfo(pRowSup, tsList, rowIndex, gid);
62,470,888✔
411
          pInfo->inWindow = true;
62,470,888✔
412
          startIndex = rowIndex;
62,470,888✔
413
          if (pInfo->pRow != NULL) {
62,470,888✔
414
            clearResultRowInitFlag(pSup->pCtx, pSup->numOfExprs);
62,429,648✔
415
          }
416
          break;
62,470,888✔
417
        }
418
      }
419

420
      if (pInfo->inWindow) {
62,601,844✔
421
        continue;  // try to find the end position
62,470,888✔
422
      } else {
423
        break;  // no valid start position, quit
130,956✔
424
      }
425
    }
426
  }
427

428
_return:
515,118✔
429

430
  if (code != TSDB_CODE_SUCCESS) {
515,372✔
431
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
5,013✔
432
  }
433
  colDataDestroy(ps);
515,372✔
434
  taosMemoryFree(ps);
515,118✔
435
  colDataDestroy(pe);
515,118✔
436
  taosMemoryFree(pe);
515,118✔
437

438
  return code;
515,372✔
439
}
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