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

taosdata / TDengine / #4943

30 Jan 2026 06:19AM UTC coverage: 66.718% (-0.07%) from 66.788%
#4943

push

travis-ci

web-flow
merge: from main to 3.0 #34453

1122 of 2018 new or added lines in 72 files covered. (55.6%)

823 existing lines in 156 files now uncovered.

204811 of 306978 relevant lines covered (66.72%)

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

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

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

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

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

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

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

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

79
  SEventWinodwPhysiNode* pEventWindowNode = (SEventWinodwPhysiNode*)physiNode;
209,557✔
80

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

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

90
  if (pEventWindowNode->window.pExprs != NULL) {
209,951✔
91
    int32_t    numOfScalarExpr = 0;
46,346✔
92
    SExprInfo* pScalarExprInfo = NULL;
46,346✔
93

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

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

104
  size_t keyBufSize = sizeof(int64_t) + sizeof(int64_t) + POINTER_BYTES;
209,951✔
105

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

111
  initResultSizeInfo(&pOperator->resultInfo, 4096);
209,951✔
112

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

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

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

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

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

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

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

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

150
  *pOptrInfo = pOperator;
209,951✔
151
  return TSDB_CODE_SUCCESS;
209,951✔
152

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

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

163
void cleanupResultInfoInEventWindow(SOperatorInfo* pOperator, SEventWindowOperatorInfo* pInfo) {
211,409✔
164
  if (pInfo == NULL || pInfo->pRow == NULL || pOperator == NULL) {
211,409✔
165
    return;
63,940✔
166
  }
167
  SExprSupp*       pSup = &pOperator->exprSupp;
147,469✔
168
  for (int32_t j = 0; j < pSup->numOfExprs; ++j) {
147,469✔
169
    pSup->pCtx[j].resultInfo = getResultEntryInfo(pInfo->pRow, j, pSup->rowEntryInfoOffset);
×
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) {
209,951✔
177
  SEventWindowOperatorInfo* pInfo = (SEventWindowOperatorInfo*)param;
209,951✔
178
  if (pInfo == NULL) {
209,951✔
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);
209,951✔
185

186
  if (pInfo->pRow != NULL) {
209,951✔
187
    taosMemoryFree(pInfo->pRow);
147,469✔
188
    pInfo->pRow = NULL;
147,469✔
189
  }
190

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

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

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

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

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

218
  SSDataBlock* pRes = pInfo->binfo.pRes;
486,214✔
219

220
  blockDataCleanup(pRes);
486,214✔
221

222
  SOperatorInfo* downstream = pOperator->pDownstream[0];
486,214✔
223
  while (1) {
1,200,471✔
224
    SSDataBlock* pBlock = NULL;
1,686,685✔
225
    if (pInfo->pPreDataBlock == NULL) {
1,686,685✔
226
      pBlock = getNextBlockFromDownstream(pOperator, 0);
1,417,814✔
227
    } else {
228
      pBlock = pInfo->pPreDataBlock;
268,871✔
229
      pInfo->pPreDataBlock = NULL;
268,871✔
230
    }
231

232
    if (pBlock == NULL) {
1,686,685✔
233
      break;
195,503✔
234
    }
235

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

240
    code = blockDataUpdateTsWindow(pBlock, pInfo->tsSlotId);
1,491,182✔
241
    QUERY_CHECK_CODE(code, lino, _end);
1,491,182✔
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,491,182✔
245
      code = projectApplyFunctions(pInfo->scalarSup.pExprInfo, pBlock, pBlock, pInfo->scalarSup.pCtx,
40,932✔
246
                                   pInfo->scalarSup.numOfExprs, NULL, GET_STM_RTINFO(pOperator->pTaskInfo));
40,932✔
247
      QUERY_CHECK_CODE(code, lino, _end);
40,932✔
248
    }
249

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

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

256
    if (pRes->info.rows >= pOperator->resultInfo.threshold ||
1,467,006✔
257
        (pRes->info.id.groupId != pInfo->groupId && pRes->info.rows > 0)) {
1,442,830✔
258
      (*ppRes) = pRes;
266,535✔
259
      return code;
266,535✔
260
    }
261
  }
262

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

273
static int32_t setSingleOutputTupleBufv1(SResultRowInfo* pResultRowInfo, STimeWindow* win, SResultRow** pResult,
160,169,980✔
274
                                         SExprSupp* pExprSup, SAggSupporter* pAggSup) {
275
  if (*pResult == NULL) {
160,169,980✔
276
    SResultRow* p = taosMemoryCalloc(1, pAggSup->resultRowSize);
148,465✔
277
    if (!p) {
148,927✔
278
      return terrno;
×
279
    }
280
    pResultRowInfo->cur = (SResultRowPosition){.pageId = p->pageId, .offset = p->offset};
148,927✔
281
    *pResult = p;
148,927✔
282
  }
283

284
  (*pResult)->win = *win;
160,169,603✔
285

286
  return setResultRowInitCtx(*pResult, pExprSup->pCtx, pExprSup->numOfExprs, pExprSup->rowEntryInfoOffset);
160,169,980✔
287
}
288

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

295
  int32_t numOfOutput = pSup->numOfExprs;
160,169,980✔
296
  int32_t numOfRows = endIndex - startIndex + 1;
160,169,603✔
297

298
  doKeepTuple(pRowSup, tsList[endIndex], endIndex, pBlock->info.id.groupId);
160,169,603✔
299

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

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

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

328
  pRowSup->numOfRows = 0;
1,477,304✔
329
  if (pInfo->groupId == 0) {
1,477,304✔
330
    pInfo->groupId = gid;
911,248✔
331
  } else if (pInfo->groupId != gid) {
566,056✔
332
    // this is a new group, reset the info
333
    pInfo->inWindow = false;
288,113✔
334
    pInfo->groupId = gid;
288,113✔
335
    pInfo->winSup.lastTs = INT64_MIN;
288,113✔
336
    pInfo->pPreDataBlock = pBlock;
288,113✔
337
    goto _return;
288,113✔
338
  }
339
  pRes->info.id.groupId = pInfo->groupId;
1,189,191✔
340

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

343
  code = filterSetDataFromSlotId(pInfo->pStartCondInfo, &param1);
1,188,814✔
344
  QUERY_CHECK_CODE(code, lino, _return);
1,188,814✔
345

346
  int32_t status1 = 0;
1,188,814✔
347
  code = filterExecute(pInfo->pStartCondInfo, pBlock, &ps, NULL, param1.numOfCols, &status1);
1,188,814✔
348
  QUERY_CHECK_CODE(code, lino, _return);
1,189,191✔
349

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

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

358
  for (int32_t i = 0; i < pBlock->info.rows; ++i) {
1,248,077,474✔
359
    if (pBlock->info.scanFlag != PRE_SCAN) {
1,246,900,996✔
360
      if (pInfo->winSup.lastTs == INT64_MIN) {
1,246,901,784✔
361
        pInfo->winSup.lastTs = tsList[i];
433,750✔
362
      } else {
363
        if (tsList[i] == pInfo->winSup.lastTs) {
1,246,470,004✔
364
          qError("duplicate timestamp found in event window operator, groupId: %" PRId64 ", timestamp: %" PRId64,
10,298✔
365
                 gid, tsList[i]);
366
          code = TSDB_CODE_QRY_WINDOW_DUP_TIMESTAMP;
8,345✔
367
          QUERY_CHECK_CODE(code, lino, _return);
8,345✔
368
        } else {
369
          pInfo->winSup.lastTs = tsList[i];
1,246,456,092✔
370
        }
371
      }
372
    }
373
  }
374
  int32_t startIndex = pInfo->inWindow ? 0 : -1;
1,178,516✔
375
  while (rowIndex < pBlock->info.rows) {
321,034,352✔
376
    if (pInfo->inWindow) {  // let's find the first end value
320,185,203✔
377
      for (rowIndex = startIndex; rowIndex < pBlock->info.rows; ++rowIndex) {
909,548,812✔
378
        if (((bool*)pe->pData)[rowIndex]) {
908,852,042✔
379
          break;
159,471,909✔
380
        }
381
      }
382

383
      if (rowIndex < pBlock->info.rows) {
160,169,226✔
384
        code = doEventWindowAggImpl(pInfo, pSup, startIndex, rowIndex, pBlock, tsList, pTaskInfo);
159,472,286✔
385
        QUERY_CHECK_CODE(code, lino, _return);
159,471,909✔
386
        doUpdateNumOfRows(pSup->pCtx, pInfo->pRow, pSup->numOfExprs, pSup->rowEntryInfoOffset);
159,471,909✔
387

388
        if (!isTrueForSatisfied(pTrueForInfo, pRowSup->win.skey, pRowSup->win.ekey, pInfo->pRow->nOrigRows)) {
159,472,286✔
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) {
159,472,286✔
394
            int32_t newSize = pRes->info.rows + pInfo->pRow->numOfRows;
665,568✔
395
            code = blockDataEnsureCapacity(pRes, newSize);
665,568✔
396
            QUERY_CHECK_CODE(code, lino, _return);
665,568✔
397
          }
398

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

403
          pRes->info.rows += pInfo->pRow->numOfRows;
159,472,286✔
404
        }
405
        pInfo->pRow->numOfRows = 0;
159,471,892✔
406
        pInfo->pRow->nOrigRows = 0;
159,472,286✔
407

408
        pInfo->inWindow = false;
159,471,892✔
409
        rowIndex += 1;
159,471,892✔
410
      } else {
411
        code = doEventWindowAggImpl(pInfo, pSup, startIndex, pBlock->info.rows - 1, pBlock, tsList, pTaskInfo);
697,694✔
412
        QUERY_CHECK_CODE(code, lino, _return);
697,694✔
413
      }
414
    } else {  // find the first start value that is fulfill for the start condition
415
      for (; rowIndex < pBlock->info.rows; ++rowIndex) {
497,896,687✔
416
        if (((bool*)ps->pData)[rowIndex]) {
497,568,125✔
417
          doKeepNewWindowStartInfo(pRowSup, tsList, rowIndex, gid);
159,687,089✔
418
          pInfo->inWindow = true;
159,687,089✔
419
          startIndex = rowIndex;
159,687,089✔
420
          if (pInfo->pRow != NULL) {
159,687,089✔
421
            clearResultRowInitFlag(pSup->pCtx, pSup->numOfExprs);
159,538,162✔
422
          }
423
          break;
159,685,873✔
424
        }
425
      }
426

427
      if (pInfo->inWindow) {
160,013,647✔
428
        continue;  // try to find the end position
159,686,250✔
429
      } else {
430
        break;  // no valid start position, quit
328,973✔
431
      }
432
    }
433
  }
434

435
_return:
1,477,304✔
436

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

445
  return code;
1,477,304✔
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