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

taosdata / TDengine / #4945

30 Jan 2026 06:19AM UTC coverage: 66.87% (+0.02%) from 66.849%
#4945

push

travis-ci

web-flow
merge: from main to 3.0 #34453

1126 of 2018 new or added lines in 72 files covered. (55.8%)

13708 existing lines in 159 files now uncovered.

205277 of 306978 relevant lines covered (66.87%)

126353544.65 hits per line

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

93.8
/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) {
1,476✔
33
  SEventWindowOperatorInfo* pEvent = pOper->info;
1,476✔
34
  SExecTaskInfo*           pTaskInfo = pOper->pTaskInfo;
1,476✔
35
  SEventWinodwPhysiNode* pPhynode = (SEventWinodwPhysiNode*)pOper->pPhyNode;
1,476✔
36
  pOper->status = OP_NOT_OPENED;
1,476✔
37

38
  resetBasicOperatorState(&pEvent->binfo);
1,476✔
39
  taosMemoryFreeClear(pEvent->pRow);
1,476✔
40

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

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

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

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

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

75
  pOperator->pPhyNode = physiNode;
195,992✔
76
  pOperator->exprSupp.hasWindowOrGroup = true;
195,992✔
77
  pOperator->exprSupp.hasWindow = true;
195,555✔
78

79
  SEventWinodwPhysiNode* pEventWindowNode = (SEventWinodwPhysiNode*)physiNode;
195,555✔
80

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

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

90
  if (pEventWindowNode->window.pExprs != NULL) {
195,992✔
91
    int32_t    numOfScalarExpr = 0;
33,283✔
92
    SExprInfo* pScalarExprInfo = NULL;
33,283✔
93

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

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

104
  size_t keyBufSize = sizeof(int64_t) + sizeof(int64_t) + POINTER_BYTES;
195,992✔
105

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

111
  initResultSizeInfo(&pOperator->resultInfo, 4096);
195,992✔
112

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

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

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

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

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

132
  pInfo->tsSlotId = tsSlotId;
195,992✔
133
  pInfo->pPreDataBlock = NULL;
195,992✔
134
  pInfo->pOperator = pOperator;
195,992✔
135
  pInfo->trueForInfo.trueForType = pEventWindowNode->trueForType;
195,992✔
136
  pInfo->trueForInfo.count = pEventWindowNode->trueForCount;
195,992✔
137
  pInfo->trueForInfo.duration = pEventWindowNode->trueForDuration;
195,992✔
138

139
  setOperatorInfo(pOperator, "EventWindowOperator", QUERY_NODE_PHYSICAL_PLAN_MERGE_EVENT, true, OP_NOT_OPENED, pInfo,
195,992✔
140
                  pTaskInfo);
141
  pOperator->fpSet = createOperatorFpSet(optrDummyOpenFn, eventWindowAggregateNext, NULL, destroyEWindowOperatorInfo,
195,992✔
142
                                         optrDefaultBufFn, NULL, optrDefaultGetNextExtFn, NULL);
143

144
  setOperatorResetStateFn(pOperator, resetEventWindowOperState);
195,992✔
145
  code = appendDownstream(pOperator, &downstream, 1);
195,992✔
146
  if (code != TSDB_CODE_SUCCESS) {
195,992✔
UNCOV
147
    goto _error;
×
148
  }
149

150
  *pOptrInfo = pOperator;
195,992✔
151
  return TSDB_CODE_SUCCESS;
195,992✔
152

UNCOV
153
_error:
×
UNCOV
154
  if (pInfo != NULL) {
×
155
    destroyEWindowOperatorInfo(pInfo);
×
156
  }
157

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

163
void cleanupResultInfoInEventWindow(SOperatorInfo* pOperator, SEventWindowOperatorInfo* pInfo) {
197,468✔
164
  if (pInfo == NULL || pInfo->pRow == NULL || pOperator == NULL) {
197,468✔
165
    return;
55,499✔
166
  }
167
  SExprSupp*       pSup = &pOperator->exprSupp;
141,969✔
168
  for (int32_t j = 0; j < pSup->numOfExprs; ++j) {
141,969✔
UNCOV
169
    pSup->pCtx[j].resultInfo = getResultEntryInfo(pInfo->pRow, j, pSup->rowEntryInfoOffset);
×
UNCOV
170
    if (pSup->pCtx[j].fpSet.cleanup) {
×
171
      pSup->pCtx[j].fpSet.cleanup(&pSup->pCtx[j]);
×
172
    }
173
  }
174
}
175

176
void destroyEWindowOperatorInfo(void* param) {
195,992✔
177
  SEventWindowOperatorInfo* pInfo = (SEventWindowOperatorInfo*)param;
195,992✔
178
  if (pInfo == NULL) {
195,992✔
UNCOV
179
    return;
×
180
  }
181

182
  // First cleanup function contexts that may reference result buffers/state.
183
  // This must happen before freeing any buffers that those cleanups might touch.
184
  cleanupResultInfoInEventWindow(pInfo->pOperator, pInfo);
195,992✔
185

186
  if (pInfo->pRow != NULL) {
195,992✔
187
    taosMemoryFree(pInfo->pRow);
141,969✔
188
    pInfo->pRow = NULL;
141,969✔
189
  }
190

191
  if (pInfo->pStartCondInfo != NULL) {
195,992✔
192
    filterFreeInfo(pInfo->pStartCondInfo);
195,992✔
193
    pInfo->pStartCondInfo = NULL;
195,992✔
194
  }
195

196
  if (pInfo->pEndCondInfo != NULL) {
195,992✔
197
    filterFreeInfo(pInfo->pEndCondInfo);
195,992✔
198
    pInfo->pEndCondInfo = NULL;
195,992✔
199
  }
200

201
  cleanupBasicInfo(&pInfo->binfo);
195,992✔
202
  colDataDestroy(&pInfo->twAggSup.timeWindowData);
195,992✔
203
  pInfo->pOperator = NULL;
195,992✔
204
  cleanupAggSup(&pInfo->aggSup);
195,992✔
205
  cleanupExprSupp(&pInfo->scalarSup);
195,992✔
206
  taosMemoryFreeClear(param);
195,992✔
207
}
208

209
static int32_t eventWindowAggregateNext(SOperatorInfo* pOperator, SSDataBlock** ppRes) {
466,384✔
210
  int32_t                   code = TSDB_CODE_SUCCESS;
466,384✔
211
  int32_t                   lino = 0;
466,384✔
212
  SEventWindowOperatorInfo* pInfo = pOperator->info;
466,384✔
213
  SExecTaskInfo*            pTaskInfo = pOperator->pTaskInfo;
466,384✔
214

215
  SExprSupp* pSup = &pOperator->exprSupp;
466,384✔
216
  int32_t    order = pInfo->binfo.inputTsOrder;
466,384✔
217

218
  SSDataBlock* pRes = pInfo->binfo.pRes;
466,384✔
219

220
  blockDataCleanup(pRes);
466,384✔
221

222
  SOperatorInfo* downstream = pOperator->pDownstream[0];
466,384✔
223
  while (1) {
1,186,690✔
224
    SSDataBlock* pBlock = NULL;
1,653,074✔
225
    if (pInfo->pPreDataBlock == NULL) {
1,653,074✔
226
      pBlock = getNextBlockFromDownstream(pOperator, 0);
1,386,971✔
227
    } else {
228
      pBlock = pInfo->pPreDataBlock;
266,103✔
229
      pInfo->pPreDataBlock = NULL;
266,103✔
230
    }
231

232
    if (pBlock == NULL) {
1,653,074✔
233
      break;
182,815✔
234
    }
235

236
    pRes->info.scanFlag = pBlock->info.scanFlag;
1,470,259✔
237
    code = setInputDataBlock(pSup, pBlock, order, pBlock->info.scanFlag, true);
1,470,259✔
238
    QUERY_CHECK_CODE(code, lino, _end);
1,470,259✔
239

240
    code = blockDataUpdateTsWindow(pBlock, pInfo->tsSlotId);
1,470,259✔
241
    QUERY_CHECK_CODE(code, lino, _end);
1,470,259✔
242

243
    // there is an scalar expression that needs to be calculated right before apply the group aggregation.
244
    if (pInfo->scalarSup.pExprInfo != NULL) {
1,470,259✔
245
      code = projectApplyFunctions(pInfo->scalarSup.pExprInfo, pBlock, pBlock, pInfo->scalarSup.pCtx,
29,749✔
246
                                   pInfo->scalarSup.numOfExprs, NULL, GET_STM_RTINFO(pOperator->pTaskInfo));
29,749✔
247
      QUERY_CHECK_CODE(code, lino, _end);
29,749✔
248
    }
249

250
    code = eventWindowAggImpl(pOperator, pInfo, pBlock);
1,460,593✔
251
    QUERY_CHECK_CODE(code, lino, _end);
1,460,593✔
252

253
    code = doFilter(pRes, pSup->pFilterInfo, NULL, NULL);
1,450,982✔
254
    QUERY_CHECK_CODE(code, lino, _end);
1,450,982✔
255

256
    if (pRes->info.rows >= pOperator->resultInfo.threshold ||
1,450,982✔
257
        (pRes->info.id.groupId != pInfo->groupId && pRes->info.rows > 0)) {
1,426,940✔
258
      (*ppRes) = pRes;
264,292✔
259
      return code;
264,292✔
260
    }
261
  }
262

263
_end:
202,092✔
264
  if (code != TSDB_CODE_SUCCESS) {
202,092✔
265
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
19,277✔
266
    pTaskInfo->code = code;
19,277✔
267
    T_LONG_JMP(pTaskInfo->env, code);
19,277✔
268
  }
269
  (*ppRes) =  pRes->info.rows == 0 ? NULL : pRes;
182,815✔
270
  return code;
182,815✔
271
}
272

273
static int32_t setSingleOutputTupleBufv1(SResultRowInfo* pResultRowInfo, STimeWindow* win, SResultRow** pResult,
159,242,836✔
274
                                         SExprSupp* pExprSup, SAggSupporter* pAggSup) {
275
  if (*pResult == NULL) {
159,242,836✔
276
    SResultRow* p = taosMemoryCalloc(1, pAggSup->resultRowSize);
143,445✔
277
    if (!p) {
143,445✔
UNCOV
278
      return terrno;
×
279
    }
280
    pResultRowInfo->cur = (SResultRowPosition){.pageId = p->pageId, .offset = p->offset};
143,445✔
281
    *pResult = p;
143,008✔
282
  }
283

284
  (*pResult)->win = *win;
159,242,836✔
285

286
  return setResultRowInitCtx(*pResult, pExprSup->pCtx, pExprSup->numOfExprs, pExprSup->rowEntryInfoOffset);
159,242,836✔
287
}
288

289
static int32_t doEventWindowAggImpl(SEventWindowOperatorInfo* pInfo, SExprSupp* pSup, int32_t startIndex,
159,242,455✔
290
                                    int32_t endIndex, const SSDataBlock* pBlock, int64_t* tsList,
291
                                    SExecTaskInfo* pTaskInfo) {
292
  int32_t code = TSDB_CODE_SUCCESS;
159,242,455✔
293
  SWindowRowsSup* pRowSup = &pInfo->winSup;
159,242,455✔
294

295
  int32_t numOfOutput = pSup->numOfExprs;
159,242,455✔
296
  int32_t numOfRows = endIndex - startIndex + 1;
159,242,455✔
297

298
  doKeepTuple(pRowSup, tsList[endIndex], endIndex, pBlock->info.id.groupId);
159,242,455✔
299

300
  code = setSingleOutputTupleBufv1(&pInfo->binfo.resultRowInfo, &pRowSup->win, &pInfo->pRow, pSup, &pInfo->aggSup);
159,242,836✔
301
  if (code != TSDB_CODE_SUCCESS) {  // null data, too many state code
159,242,836✔
UNCOV
302
    qError("failed to set single output tuple buffer, code:%d", code);
×
UNCOV
303
    return code;
×
304
  }
305

306
  updateTimeWindowInfo(&pInfo->twAggSup.timeWindowData, &pRowSup->win, 0);
159,242,836✔
307
  pInfo->pRow->nOrigRows += numOfRows;
159,242,399✔
308
  code = applyAggFunctionOnPartialTuples(pTaskInfo, pSup->pCtx, &pInfo->twAggSup.timeWindowData, startIndex, numOfRows,
159,242,836✔
309
                                         pBlock->info.rows, numOfOutput);
159,242,399✔
310
  return code;
159,242,836✔
311
}
312

313
int32_t eventWindowAggImpl(SOperatorInfo* pOperator, SEventWindowOperatorInfo* pInfo, SSDataBlock* pBlock) {
1,460,593✔
314
  int32_t          code = TSDB_CODE_SUCCESS;
1,460,593✔
315
  int32_t          lino = 0;
1,460,593✔
316
  SExecTaskInfo*   pTaskInfo = pOperator->pTaskInfo;
1,460,593✔
317
  SExprSupp*       pSup = &pOperator->exprSupp;
1,460,593✔
318
  SSDataBlock*     pRes = pInfo->binfo.pRes;
1,460,593✔
319
  int64_t          gid = pBlock->info.id.groupId;
1,460,593✔
320
  SColumnInfoData *ps = NULL, *pe = NULL;
1,460,593✔
321
  SColumnInfoData* pColInfoData = taosArrayGet(pBlock->pDataBlock, pInfo->tsSlotId);
1,460,593✔
322
  QUERY_CHECK_NULL(pColInfoData, code, lino, _return, terrno);
1,460,593✔
323
  TSKEY*           tsList = (TSKEY*)pColInfoData->pData;
1,460,593✔
324
  SWindowRowsSup*  pRowSup = &pInfo->winSup;
1,460,593✔
325
  int32_t          rowIndex = 0;
1,460,593✔
326
  STrueForInfo*    pTrueForInfo = getTrueForInfo(pOperator);
1,460,593✔
327

328
  pRowSup->numOfRows = 0;
1,460,593✔
329
  if (pInfo->groupId == 0) {
1,460,593✔
330
    pInfo->groupId = gid;
900,205✔
331
  } else if (pInfo->groupId != gid) {
560,388✔
332
    // this is a new group, reset the info
333
    pInfo->inWindow = false;
285,177✔
334
    pInfo->groupId = gid;
285,177✔
335
    pInfo->winSup.lastTs = INT64_MIN;
285,177✔
336
    pInfo->pPreDataBlock = pBlock;
285,177✔
337
    goto _return;
285,177✔
338
  }
339
  pRes->info.id.groupId = pInfo->groupId;
1,175,416✔
340

341
  SFilterColumnParam param1 = {.numOfCols = taosArrayGetSize(pBlock->pDataBlock), .pDataBlock = pBlock->pDataBlock};
1,175,416✔
342

343
  code = filterSetDataFromSlotId(pInfo->pStartCondInfo, &param1);
1,175,416✔
344
  QUERY_CHECK_CODE(code, lino, _return);
1,174,979✔
345

346
  int32_t status1 = 0;
1,174,979✔
347
  code = filterExecute(pInfo->pStartCondInfo, pBlock, &ps, NULL, param1.numOfCols, &status1);
1,174,979✔
348
  QUERY_CHECK_CODE(code, lino, _return);
1,175,416✔
349

350
  SFilterColumnParam param2 = {.numOfCols = taosArrayGetSize(pBlock->pDataBlock), .pDataBlock = pBlock->pDataBlock};
1,175,416✔
351
  code = filterSetDataFromSlotId(pInfo->pEndCondInfo, &param2);
1,175,416✔
352
  QUERY_CHECK_CODE(code, lino, _return);
1,175,416✔
353

354
  int32_t status2 = 0;
1,175,416✔
355
  code = filterExecute(pInfo->pEndCondInfo, pBlock, &pe, NULL, param2.numOfCols, &status2);
1,175,416✔
356
  QUERY_CHECK_CODE(code, lino, _return);
1,175,416✔
357

358
  for (int32_t i = 0; i < pBlock->info.rows; ++i) {
1,241,475,766✔
359
    if (pBlock->info.scanFlag != PRE_SCAN) {
1,240,309,961✔
360
      if (pInfo->winSup.lastTs == INT64_MIN) {
1,240,309,524✔
361
        pInfo->winSup.lastTs = tsList[i];
423,097✔
362
      } else {
363
        if (tsList[i] == pInfo->winSup.lastTs) {
1,239,887,301✔
364
          qError("duplicate timestamp found in event window operator, groupId: %" PRId64 ", timestamp: %" PRId64,
9,611✔
365
                 gid, tsList[i]);
366
          code = TSDB_CODE_QRY_WINDOW_DUP_TIMESTAMP;
8,737✔
367
          QUERY_CHECK_CODE(code, lino, _return);
8,737✔
368
        } else {
369
          pInfo->winSup.lastTs = tsList[i];
1,239,876,816✔
370
        }
371
      }
372
    }
373
  }
374
  int32_t startIndex = pInfo->inWindow ? 0 : -1;
1,165,805✔
375
  while (rowIndex < pBlock->info.rows) {
319,169,844✔
376
    if (pInfo->inWindow) {  // let's find the first end value
318,329,965✔
377
      for (rowIndex = startIndex; rowIndex < pBlock->info.rows; ++rowIndex) {
904,287,738✔
378
        if (((bool*)pe->pData)[rowIndex]) {
903,596,175✔
379
          break;
158,550,455✔
380
        }
381
      }
382

383
      if (rowIndex < pBlock->info.rows) {
159,242,018✔
384
        code = doEventWindowAggImpl(pInfo, pSup, startIndex, rowIndex, pBlock, tsList, pTaskInfo);
158,550,455✔
385
        QUERY_CHECK_CODE(code, lino, _return);
158,550,836✔
386
        doUpdateNumOfRows(pSup->pCtx, pInfo->pRow, pSup->numOfExprs, pSup->rowEntryInfoOffset);
158,550,836✔
387

388
        if (!isTrueForSatisfied(pTrueForInfo, pRowSup->win.skey, pRowSup->win.ekey, pInfo->pRow->nOrigRows)) {
158,550,836✔
NEW
389
          qDebug("skip small window, groupId: %" PRId64 ", skey: %" PRId64 ", ekey: %" PRId64 ", nrows: %u",
×
390
                 pInfo->groupId, pRowSup->win.skey, pRowSup->win.ekey, pInfo->pRow->nOrigRows);
391
        } else {
392
          // check buffer size
393
          if (pRes->info.rows + pInfo->pRow->numOfRows >= pRes->info.capacity) {
158,550,455✔
394
            int32_t newSize = pRes->info.rows + pInfo->pRow->numOfRows;
659,232✔
395
            code = blockDataEnsureCapacity(pRes, newSize);
659,232✔
396
            QUERY_CHECK_CODE(code, lino, _return);
659,232✔
397
          }
398

399
          code = copyResultrowToDataBlock(pSup->pExprInfo, pSup->numOfExprs, pInfo->pRow, pSup->pCtx, pRes,
158,550,836✔
400
                                          pSup->rowEntryInfoOffset, pTaskInfo);
158,550,836✔
401
          QUERY_CHECK_CODE(code, lino, _return);
158,550,836✔
402

403
          pRes->info.rows += pInfo->pRow->numOfRows;
158,550,836✔
404
        }
405
        pInfo->pRow->numOfRows = 0;
158,550,836✔
406
        pInfo->pRow->nOrigRows = 0;
158,550,836✔
407

408
        pInfo->inWindow = false;
158,550,455✔
409
        rowIndex += 1;
158,550,455✔
410
      } else {
411
        code = doEventWindowAggImpl(pInfo, pSup, startIndex, pBlock->info.rows - 1, pBlock, tsList, pTaskInfo);
691,563✔
412
        QUERY_CHECK_CODE(code, lino, _return);
692,000✔
413
      }
414
    } else {  // find the first start value that is fulfill for the start condition
415
      for (; rowIndex < pBlock->info.rows; ++rowIndex) {
495,780,875✔
416
        if (((bool*)ps->pData)[rowIndex]) {
495,454,949✔
417
          doKeepNewWindowStartInfo(pRowSup, tsList, rowIndex, gid);
158,761,965✔
418
          pInfo->inWindow = true;
158,761,528✔
419
          startIndex = rowIndex;
158,761,528✔
420
          if (pInfo->pRow != NULL) {
158,761,528✔
421
            clearResultRowInitFlag(pSup->pCtx, pSup->numOfExprs);
158,618,520✔
422
          }
423
          break;
158,761,147✔
424
        }
425
      }
426

427
      if (pInfo->inWindow) {
159,087,510✔
428
        continue;  // try to find the end position
158,761,584✔
429
      } else {
430
        break;  // no valid start position, quit
325,926✔
431
      }
432
    }
433
  }
434

435
_return:
1,460,593✔
436

437
  if (code != TSDB_CODE_SUCCESS) {
1,460,593✔
438
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
9,611✔
439
  }
440
  colDataDestroy(ps);
1,460,593✔
441
  taosMemoryFree(ps);
1,460,593✔
442
  colDataDestroy(pe);
1,460,593✔
443
  taosMemoryFree(pe);
1,460,593✔
444

445
  return code;
1,460,593✔
446
}
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