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

taosdata / TDengine / #5081

17 May 2026 01:15AM UTC coverage: 73.368% (-0.04%) from 73.403%
#5081

push

travis-ci

web-flow
feat (TDgpt): Dynamic Model Synchronization Enhancements (#35344)

* refactor: do some internal refactor.

* fix: fix multiprocess sync issue.

* feat: add dynamic anomaly detection and forecasting services

* fix: log error message for undeploying model in exception handling

* Potential fix for pull request finding

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

* Potential fix for pull request finding

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

* Potential fix for pull request finding

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

* Potential fix for pull request finding

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

* fix: handle undeploy when model exists only on disk

Agent-Logs-Url: https://github.com/taosdata/TDengine/sessions/286aafa0-c3ce-4c27-b803-2707571e9dc1

Co-authored-by: hjxilinx <8252296+hjxilinx@users.noreply.github.com>

* fix: guard dynamic registry concurrent access

Agent-Logs-Url: https://github.com/taosdata/TDengine/sessions/5e4db858-6458-40f4-ac28-d1b1b7f97c18

Co-authored-by: hjxilinx <8252296+hjxilinx@users.noreply.github.com>

* fix: tighten service list locking scope

Agent-Logs-Url: https://github.com/taosdata/TDengine/sessions/5e4db858-6458-40f4-ac28-d1b1b7f97c18

Co-authored-by: hjxilinx <8252296+hjxilinx@users.noreply.github.com>

* fix: restore prophet support and update tests per review feedback

Agent-Logs-Url: https://github.com/taosdata/TDengine/sessions/92298ae1-7da6-4d07-b20e-101c7cd0b26b

Co-authored-by: hjxilinx <8252296+hjxilinx@users.noreply.github.com>

* fix: improve test name and move copy inside lock scope

Agent-Logs-Url: https://github.com/taosdata/TDengine/sessions/92298ae1-7da6-4d07-b20e-101c7cd0b26b

Co-authored-by: hjxilinx <8252296+hjxilinx@users.noreply.github.com>

* Potential fix for pull request finding

Co-au... (continued)

281582 of 383795 relevant lines covered (73.37%)

137177705.18 hits per line

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

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

38
  resetBasicOperatorState(&pEvent->binfo);
1,902✔
39
  cleanupResultInfoInEventWindow(pOper, pEvent);
1,902✔
40
  taosMemoryFreeClear(pEvent->pRow);
1,902✔
41

42
  pEvent->groupId = 0;
1,902✔
43
  pEvent->pPreDataBlock = NULL;
1,902✔
44
  pEvent->inWindow = false;
1,902✔
45
  pEvent->winSup.lastTs = INT64_MIN;
1,902✔
46
  resetIndefRowsRuntime(&pEvent->indefRows, pOper);
1,902✔
47

48
  colDataDestroy(&pEvent->twAggSup.timeWindowData);
1,902✔
49
  int32_t code = initExecTimeWindowInfo(&pEvent->twAggSup.timeWindowData, &pTaskInfo->window);
1,902✔
50

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

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

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

77
  pOperator->pPhyNode = physiNode;
357,531✔
78
  pOperator->exprSupp.hasWindowOrGroup = true;
357,531✔
79
  pOperator->exprSupp.hasWindow = true;
357,531✔
80

81
  SEventWinodwPhysiNode* pEventWindowNode = (SEventWinodwPhysiNode*)physiNode;
357,531✔
82

83
  int32_t tsSlotId = ((SColumnNode*)pEventWindowNode->window.pTspk)->slotId;
357,531✔
84
  code = filterInitFromNode((SNode*)pEventWindowNode->pStartCond, &pInfo->pStartCondInfo, 0,
357,531✔
85
                            pTaskInfo->pStreamRuntimeInfo);
357,531✔
86
  QUERY_CHECK_CODE(code, lino, _error);
357,531✔
87
  filterSetExecContext(pInfo->pStartCondInfo, pTaskInfo, isTaskKilled);
357,531✔
88

89
  code = filterInitFromNode((SNode*)pEventWindowNode->pEndCond, &pInfo->pEndCondInfo, 0,
357,531✔
90
                            pTaskInfo->pStreamRuntimeInfo);
357,531✔
91
  QUERY_CHECK_CODE(code, lino, _error);
357,531✔
92
  filterSetExecContext(pInfo->pEndCondInfo, pTaskInfo, isTaskKilled);
357,531✔
93

94
  if (pEventWindowNode->window.pExprs != NULL) {
357,531✔
95
    int32_t    numOfScalarExpr = 0;
72,881✔
96
    SExprInfo* pScalarExprInfo = NULL;
72,881✔
97

98
    code = createExprInfo(pEventWindowNode->window.pExprs, NULL, &pScalarExprInfo, &numOfScalarExpr);
72,881✔
99
    QUERY_CHECK_CODE(code, lino, _error);
72,881✔
100
    code = initExprSupp(&pInfo->scalarSup, pScalarExprInfo, numOfScalarExpr, &pTaskInfo->storageAPI.functionStore);
72,881✔
101
    QUERY_CHECK_CODE(code, lino, _error);
72,881✔
102
  }
103

104
  code = filterInitFromNode((SNode*)pEventWindowNode->window.node.pConditions, &pOperator->exprSupp.pFilterInfo, 0,
357,531✔
105
                            pTaskInfo->pStreamRuntimeInfo);
357,531✔
106
  QUERY_CHECK_CODE(code, lino, _error);
357,531✔
107
  filterSetExecContext(pOperator->exprSupp.pFilterInfo, pTaskInfo, isTaskKilled);
357,531✔
108

109
  size_t keyBufSize = sizeof(int64_t) + sizeof(int64_t) + POINTER_BYTES;
357,531✔
110

111
  int32_t    num = 0;
357,531✔
112
  SExprInfo* pExprInfo = NULL;
357,531✔
113
  code = createExprInfo(pEventWindowNode->window.pFuncs, NULL, &pExprInfo, &num);
357,531✔
114
  QUERY_CHECK_CODE(code, lino, _error);
357,531✔
115

116
  initResultSizeInfo(&pOperator->resultInfo, 4096);
357,531✔
117

118
  code = initAggSup(&pOperator->exprSupp, &pInfo->aggSup, pExprInfo, num, keyBufSize, pTaskInfo->id.str,
357,531✔
119
                    NULL, &pTaskInfo->storageAPI.functionStore);
120
  QUERY_CHECK_CODE(code, lino, _error);
357,531✔
121

122
  pInfo->indefRowsMode = pEventWindowNode->window.indefRowsFunc;
357,531✔
123
  if (pInfo->indefRowsMode) {
357,531✔
124
    code = initIndefRowsRuntime(&pInfo->indefRows, pOperator->exprSupp.pCtx, num, pOperator->resultInfo.capacity);
11,055✔
125
    QUERY_CHECK_CODE(code, lino, _error);
11,055✔
126
  }
127

128
  SSDataBlock* pResBlock = createDataBlockFromDescNode(pEventWindowNode->window.node.pOutputDataBlockDesc);
357,531✔
129
  QUERY_CHECK_NULL(pResBlock, code, lino, _error, terrno);
357,531✔
130
  initBasicInfo(&pInfo->binfo, pResBlock);
357,531✔
131

132
  code = blockDataEnsureCapacity(pResBlock, pOperator->resultInfo.capacity);
357,531✔
133
  QUERY_CHECK_CODE(code, lino, _error);
357,531✔
134

135
  initResultRowInfo(&pInfo->binfo.resultRowInfo);
357,531✔
136
  pInfo->binfo.inputTsOrder = physiNode->inputTsOrder;
357,531✔
137
  pInfo->binfo.outputTsOrder = physiNode->outputTsOrder;
357,531✔
138
  pInfo->winSup.lastTs = INT64_MIN;
357,531✔
139

140
  code = initExecTimeWindowInfo(&pInfo->twAggSup.timeWindowData, &pTaskInfo->window);
357,531✔
141
  QUERY_CHECK_CODE(code, lino, _error);
357,531✔
142

143
  pInfo->tsSlotId = tsSlotId;
357,531✔
144
  pInfo->pPreDataBlock = NULL;
357,531✔
145
  pInfo->pOperator = pOperator;
357,531✔
146
  pInfo->trueForInfo.trueForType = pEventWindowNode->trueForType;
357,531✔
147
  pInfo->trueForInfo.count = pEventWindowNode->trueForCount;
357,531✔
148
  pInfo->trueForInfo.duration = pEventWindowNode->trueForDuration;
357,531✔
149

150
  setOperatorInfo(pOperator, "EventWindowOperator", QUERY_NODE_PHYSICAL_PLAN_MERGE_EVENT, true, OP_NOT_OPENED, pInfo,
357,531✔
151
                  pTaskInfo);
152
  pOperator->fpSet = createOperatorFpSet(optrDummyOpenFn, eventWindowAggregateNext, NULL, destroyEWindowOperatorInfo,
357,531✔
153
                                         optrDefaultBufFn, NULL, optrDefaultGetNextExtFn, NULL);
154

155
  setOperatorResetStateFn(pOperator, resetEventWindowOperState);
357,531✔
156
  code = appendDownstream(pOperator, &downstream, 1);
357,531✔
157
  if (code != TSDB_CODE_SUCCESS) {
357,531✔
158
    goto _error;
×
159
  }
160

161
  *pOptrInfo = pOperator;
357,531✔
162
  return TSDB_CODE_SUCCESS;
357,531✔
163

164
_error:
×
165
  if (pInfo != NULL) {
×
166
    destroyEWindowOperatorInfo(pInfo);
×
167
  }
168

169
  destroyOperatorAndDownstreams(pOperator, &downstream, 1);
×
170
  pTaskInfo->code = code;
×
171
  return code;
×
172
}
173

174
void cleanupResultInfoInEventWindow(SOperatorInfo* pOperator, SEventWindowOperatorInfo* pInfo) {
359,433✔
175
  if (pInfo == NULL || pInfo->pRow == NULL || pOperator == NULL) {
359,433✔
176
    return;
109,573✔
177
  }
178
  SExprSupp*       pSup = &pOperator->exprSupp;
249,860✔
179
  for (int32_t j = 0; j < pSup->numOfExprs; ++j) {
249,860✔
180
    pSup->pCtx[j].resultInfo = getResultEntryInfo(pInfo->pRow, j, pSup->rowEntryInfoOffset);
×
181
    if (pSup->pCtx[j].fpSet.cleanup) {
×
182
      pSup->pCtx[j].fpSet.cleanup(&pSup->pCtx[j]);
×
183
    }
184
  }
185
}
186

187
void destroyEWindowOperatorInfo(void* param) {
357,531✔
188
  SEventWindowOperatorInfo* pInfo = (SEventWindowOperatorInfo*)param;
357,531✔
189
  if (pInfo == NULL) {
357,531✔
190
    return;
×
191
  }
192

193
  // First cleanup function contexts that may reference result buffers/state.
194
  // This must happen before freeing any buffers that those cleanups might touch.
195
  cleanupResultInfoInEventWindow(pInfo->pOperator, pInfo);
357,531✔
196
  cleanupIndefRowsRuntime(&pInfo->indefRows, pInfo->pOperator);
357,531✔
197

198
  if (pInfo->pRow != NULL) {
357,531✔
199
    taosMemoryFree(pInfo->pRow);
247,958✔
200
    pInfo->pRow = NULL;
247,958✔
201
  }
202

203
  if (pInfo->pStartCondInfo != NULL) {
357,531✔
204
    filterFreeInfo(pInfo->pStartCondInfo);
357,531✔
205
    pInfo->pStartCondInfo = NULL;
357,531✔
206
  }
207

208
  if (pInfo->pEndCondInfo != NULL) {
357,531✔
209
    filterFreeInfo(pInfo->pEndCondInfo);
357,531✔
210
    pInfo->pEndCondInfo = NULL;
357,531✔
211
  }
212

213
  cleanupBasicInfo(&pInfo->binfo);
357,531✔
214
  colDataDestroy(&pInfo->twAggSup.timeWindowData);
357,531✔
215
  pInfo->pOperator = NULL;
357,531✔
216
  cleanupAggSup(&pInfo->aggSup);
357,531✔
217
  cleanupExprSupp(&pInfo->scalarSup);
357,531✔
218
  taosMemoryFreeClear(param);
357,531✔
219
}
220

221
static int32_t eventWindowAggregateNext(SOperatorInfo* pOperator, SSDataBlock** ppRes) {
800,056✔
222
  int32_t                   code = TSDB_CODE_SUCCESS;
800,056✔
223
  int32_t                   lino = 0;
800,056✔
224
  SEventWindowOperatorInfo* pInfo = pOperator->info;
800,056✔
225
  SExecTaskInfo*            pTaskInfo = pOperator->pTaskInfo;
800,056✔
226

227
  if (pOperator->status == OP_EXEC_DONE) {
800,056✔
228
    *ppRes = NULL;
×
229
    return code;
×
230
  }
231

232
  SExprSupp* pSup = &pOperator->exprSupp;
800,056✔
233
  int32_t    order = pInfo->binfo.inputTsOrder;
800,056✔
234

235
  SSDataBlock* pRes = pInfo->binfo.pRes;
800,056✔
236

237
  if (pInfo->indefRowsMode) {
800,056✔
238
    (*ppRes) = getNextIndefRowsResultBlock(&pInfo->indefRows, pOperator);
39,354✔
239
    if ((*ppRes) != NULL) {
39,354✔
240
      return code;
6,762✔
241
    }
242
  }
243

244
  blockDataCleanup(pRes);
793,294✔
245

246
  SOperatorInfo* downstream = pOperator->pDownstream[0];
793,294✔
247
  while (1) {
3,425,382✔
248
    SSDataBlock* pBlock = NULL;
4,218,676✔
249
    if (pInfo->pPreDataBlock == NULL) {
4,218,676✔
250
      pBlock = getNextBlockFromDownstream(pOperator, 0);
3,892,980✔
251
    } else {
252
      pBlock = pInfo->pPreDataBlock;
325,696✔
253
      pInfo->pPreDataBlock = NULL;
325,696✔
254
    }
255

256
    if (pBlock == NULL) {
4,218,003✔
257
      break;
375,549✔
258
    }
259

260
    pRes->info.scanFlag = pBlock->info.scanFlag;
3,842,454✔
261
    pRes->info.dataLoad = 1;
3,842,454✔
262
    code = setInputDataBlock(pSup, pBlock, order, pBlock->info.scanFlag, true);
3,842,454✔
263
    QUERY_CHECK_CODE(code, lino, _end);
3,842,454✔
264

265
    code = blockDataUpdateTsWindow(pBlock, pInfo->tsSlotId);
3,842,454✔
266
    QUERY_CHECK_CODE(code, lino, _end);
3,842,454✔
267

268
    // there is an scalar expression that needs to be calculated right before apply the group aggregation.
269
    if (pInfo->scalarSup.pExprInfo != NULL) {
3,842,454✔
270
      code = projectApplyFunctions(pInfo->scalarSup.pExprInfo, pBlock, pBlock, pInfo->scalarSup.pCtx,
127,016✔
271
                                   pInfo->scalarSup.numOfExprs, NULL, GET_STM_RTINFO(pOperator->pTaskInfo), pOperator->pTaskInfo);
63,508✔
272
      QUERY_CHECK_CODE(code, lino, _end);
63,508✔
273
    }
274

275
    code = eventWindowAggImpl(pOperator, pInfo, pBlock);
3,826,065✔
276
    QUERY_CHECK_CODE(code, lino, _end);
3,826,065✔
277

278
    if (pInfo->indefRowsMode) {
3,807,888✔
279
      (*ppRes) = getNextIndefRowsResultBlock(&pInfo->indefRows, pOperator);
33,468✔
280
      if ((*ppRes) != NULL) {
33,468✔
281
        return code;
21,537✔
282
      }
283
      continue;
11,931✔
284
    }
285

286
    code = doFilter(pRes, pSup->pFilterInfo, NULL, NULL);
3,774,420✔
287
    QUERY_CHECK_CODE(code, lino, _end);
3,774,420✔
288

289
    if (pRes->info.rows >= pOperator->resultInfo.threshold ||
3,774,420✔
290
        (pRes->info.id.groupId != pInfo->groupId && pRes->info.rows > 0)) {
3,696,018✔
291
      (*ppRes) = pRes;
360,969✔
292
      return code;
360,969✔
293
    }
294
  }
295

296
  if (pInfo->indefRowsMode) {
375,549✔
297
    dropAllIndefRowsWindowStates(pOperator, &pInfo->indefRows);
11,055✔
298
    pInfo->inWindow = false;
11,055✔
299
    (*ppRes) = getNextIndefRowsResultBlock(&pInfo->indefRows, pOperator);
11,055✔
300
    if ((*ppRes) == NULL) {
11,055✔
301
      setOperatorCompleted(pOperator);
11,055✔
302
    }
303
    return code;
11,055✔
304
  }
305

306
_end:
364,494✔
307
  if (code != TSDB_CODE_SUCCESS) {
399,060✔
308
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
34,566✔
309
    pTaskInfo->code = code;
34,566✔
310
    T_LONG_JMP(pTaskInfo->env, code);
34,566✔
311
  }
312
  (*ppRes) =  pRes->info.rows == 0 ? NULL : pRes;
364,494✔
313
  return code;
364,494✔
314
}
315

316
static int32_t setSingleOutputTupleBufv1(SResultRowInfo* pResultRowInfo, STimeWindow* win, SResultRow** pResult,
558,308,296✔
317
                                         SExprSupp* pExprSup, SAggSupporter* pAggSup) {
318
  if (*pResult == NULL) {
558,308,296✔
319
    SResultRow* p = taosMemoryCalloc(1, pAggSup->resultRowSize);
249,860✔
320
    if (!p) {
249,329✔
321
      return terrno;
×
322
    }
323
    pResultRowInfo->cur = (SResultRowPosition){.pageId = p->pageId, .offset = p->offset};
249,329✔
324
    *pResult = p;
249,329✔
325
  }
326

327
  (*pResult)->win = *win;
558,308,296✔
328

329
  return setResultRowInitCtx(*pResult, pExprSup->pCtx, pExprSup->numOfExprs, pExprSup->rowEntryInfoOffset);
558,308,296✔
330
}
331

332
static int32_t doEventWindowAggImpl(SEventWindowOperatorInfo* pInfo, SExprSupp* pSup, int32_t startIndex,
558,336,595✔
333
                                    int32_t endIndex, const SSDataBlock* pBlock, int64_t* tsList,
334
                                    SExecTaskInfo* pTaskInfo) {
335
  int32_t code = TSDB_CODE_SUCCESS;
558,336,595✔
336
  SWindowRowsSup* pRowSup = &pInfo->winSup;
558,336,595✔
337

338
  int32_t numOfOutput = pSup->numOfExprs;
558,337,126✔
339
  int32_t numOfRows = endIndex - startIndex + 1;
558,337,126✔
340

341
  doKeepTuple(pRowSup, tsList[endIndex], endIndex, pBlock->info.id.groupId);
558,337,126✔
342

343
  if (pInfo->indefRowsMode) {
558,336,595✔
344
    SIndefRowsWindowState* pState = NULL;
28,299✔
345
    return applyIndefRowsFuncOnWindowState(pInfo->pOperator, &pInfo->indefRows, &pState, pInfo->binfo.pRes,
56,598✔
346
                                           pBlock->info.id.groupId, &pRowSup->win, (SSDataBlock*)pBlock, startIndex,
28,299✔
347
                                           numOfRows, pInfo->binfo.inputTsOrder, pInfo->aggSup.resultRowSize);
348
  }
349

350
  code = setSingleOutputTupleBufv1(&pInfo->binfo.resultRowInfo, &pRowSup->win, &pInfo->pRow, pSup, &pInfo->aggSup);
558,308,296✔
351
  if (code != TSDB_CODE_SUCCESS) {  // null data, too many state code
558,308,296✔
352
    qError("failed to set single output tuple buffer, code:%d", code);
×
353
    return code;
×
354
  }
355

356
  updateTimeWindowInfo(&pInfo->twAggSup.timeWindowData, &pRowSup->win, 0);
558,308,296✔
357
  pInfo->pRow->nOrigRows += numOfRows;
558,308,296✔
358
  code = applyAggFunctionOnPartialTuples(pTaskInfo, pSup->pCtx, &pInfo->twAggSup.timeWindowData, startIndex, numOfRows,
558,308,296✔
359
                                         pBlock->info.rows, numOfOutput);
558,308,296✔
360
  return code;
558,308,296✔
361
}
362

363
int32_t eventWindowAggImpl(SOperatorInfo* pOperator, SEventWindowOperatorInfo* pInfo, SSDataBlock* pBlock) {
3,826,065✔
364
  int32_t          code = TSDB_CODE_SUCCESS;
3,826,065✔
365
  int32_t          lino = 0;
3,826,065✔
366
  SExecTaskInfo*   pTaskInfo = pOperator->pTaskInfo;
3,826,065✔
367
  SExprSupp*       pSup = &pOperator->exprSupp;
3,826,065✔
368
  SSDataBlock*     pRes = pInfo->binfo.pRes;
3,826,065✔
369
  int64_t          gid = pBlock->info.id.groupId;
3,826,065✔
370
  SColumnInfoData *ps = NULL, *pe = NULL;
3,826,065✔
371
  SColumnInfoData* pColInfoData = taosArrayGet(pBlock->pDataBlock, pInfo->tsSlotId);
3,826,065✔
372
  QUERY_CHECK_NULL(pColInfoData, code, lino, _return, terrno);
3,826,065✔
373
  TSKEY*           tsList = (TSKEY*)pColInfoData->pData;
3,826,065✔
374
  SWindowRowsSup*  pRowSup = &pInfo->winSup;
3,826,065✔
375
  int32_t          rowIndex = 0;
3,826,065✔
376
  STrueForInfo*    pTrueForInfo = getTrueForInfo(pOperator);
3,826,065✔
377

378
  pRowSup->numOfRows = 0;
3,826,065✔
379
  if (pInfo->groupId == 0) {
3,826,065✔
380
    pInfo->groupId = gid;
3,142,353✔
381
  } else if (pInfo->groupId != gid) {
683,712✔
382
    // this is a new group, reset the info
383
    if (pInfo->indefRowsMode) {
347,288✔
384
      dropAllIndefRowsWindowStates(pOperator, &pInfo->indefRows);
11,448✔
385
    }
386
    pInfo->inWindow = false;
347,288✔
387
    pInfo->groupId = gid;
347,288✔
388
    pInfo->winSup.lastTs = INT64_MIN;
347,288✔
389
    pInfo->pPreDataBlock = pBlock;
347,288✔
390
    goto _return;
347,288✔
391
  }
392
  pRes->info.id.groupId = pInfo->groupId;
3,478,777✔
393

394
  SFilterColumnParam param1 = {.numOfCols = taosArrayGetSize(pBlock->pDataBlock), .pDataBlock = pBlock->pDataBlock};
3,478,777✔
395

396
  code = filterSetDataFromSlotId(pInfo->pStartCondInfo, &param1);
3,478,777✔
397
  QUERY_CHECK_CODE(code, lino, _return);
3,478,777✔
398

399
  int32_t status1 = 0;
3,478,777✔
400
  code = filterExecute(pInfo->pStartCondInfo, pBlock, &ps, NULL, param1.numOfCols, &status1);
3,478,777✔
401
  QUERY_CHECK_CODE(code, lino, _return);
3,478,246✔
402

403
  SFilterColumnParam param2 = {.numOfCols = taosArrayGetSize(pBlock->pDataBlock), .pDataBlock = pBlock->pDataBlock};
3,478,246✔
404
  code = filterSetDataFromSlotId(pInfo->pEndCondInfo, &param2);
3,478,777✔
405
  QUERY_CHECK_CODE(code, lino, _return);
3,478,777✔
406

407
  int32_t status2 = 0;
3,478,777✔
408
  code = filterExecute(pInfo->pEndCondInfo, pBlock, &pe, NULL, param2.numOfCols, &status2);
3,478,777✔
409
  QUERY_CHECK_CODE(code, lino, _return);
3,478,246✔
410

411
  for (int32_t i = 0; i < pBlock->info.rows; ++i) {
2,147,483,647✔
412
    if (pBlock->info.scanFlag != PRE_SCAN) {
2,147,483,647✔
413
      if (pInfo->winSup.lastTs == INT64_MIN) {
2,147,483,647✔
414
        pInfo->winSup.lastTs = tsList[i];
624,992✔
415
      } else {
416
        if (tsList[i] == pInfo->winSup.lastTs) {
2,147,483,647✔
417
          qError("duplicate timestamp found in event window operator, groupId: %" PRId64 ", timestamp: %" PRId64,
18,177✔
418
                 gid, tsList[i]);
419
          code = TSDB_CODE_QRY_WINDOW_DUP_TIMESTAMP;
18,708✔
420
          QUERY_CHECK_CODE(code, lino, _return);
18,708✔
421
        } else {
422
          pInfo->winSup.lastTs = tsList[i];
2,147,483,647✔
423
        }
424
      }
425
    }
426
  }
427
  int32_t startIndex = pInfo->inWindow ? 0 : -1;
3,460,600✔
428
  while (rowIndex < pBlock->info.rows) {
1,118,127,818✔
429
    if (pInfo->inWindow) {  // let's find the first end value
1,115,364,192✔
430
      for (rowIndex = startIndex; rowIndex < pBlock->info.rows; ++rowIndex) {
2,147,483,647✔
431
        if (((bool*)pe->pData)[rowIndex]) {
2,147,483,647✔
432
          break;
556,062,940✔
433
        }
434
      }
435

436
      if (rowIndex < pBlock->info.rows) {
558,337,126✔
437
        code = doEventWindowAggImpl(pInfo, pSup, startIndex, rowIndex, pBlock, tsList, pTaskInfo);
556,062,940✔
438
        QUERY_CHECK_CODE(code, lino, _return);
556,062,940✔
439
        if (pInfo->indefRowsMode) {
556,062,940✔
440
          SIndefRowsWindowState* pState = findIndefRowsWindowState(&pInfo->indefRows, pInfo->groupId, pRowSup->win.skey);
27,816✔
441
          if (pState == NULL) {
27,816✔
442
            code = TSDB_CODE_QRY_WINDOW_STATE_NOT_EXIST;
×
443
            QUERY_CHECK_CODE(code, lino, _return);
×
444
          }
445

446
          if (!isTrueForSatisfied(pTrueForInfo, pState->win.skey, pState->win.ekey, pState->pRow->nOrigRows)) {
27,816✔
447
            qDebug("skip small window, groupId: %" PRId64 ", skey: %" PRId64 ", ekey: %" PRId64 ", nrows: %u",
×
448
                   pInfo->groupId, pState->win.skey, pState->win.ekey, pState->pRow->nOrigRows);
449
            dropIndefRowsWindowState(pOperator, &pInfo->indefRows, pState);
×
450
          } else {
451
            code = closeIndefRowsWindowState(pOperator, &pInfo->indefRows, pState);
27,816✔
452
            QUERY_CHECK_CODE(code, lino, _return);
27,816✔
453
          }
454
        } else {
455
          doUpdateNumOfRows(pSup->pCtx, pInfo->pRow, pSup->numOfExprs, pSup->rowEntryInfoOffset);
556,035,124✔
456

457
          if (!isTrueForSatisfied(pTrueForInfo, pRowSup->win.skey, pRowSup->win.ekey, pInfo->pRow->nOrigRows)) {
556,035,124✔
458
            qDebug("skip small window, groupId: %" PRId64 ", skey: %" PRId64 ", ekey: %" PRId64 ", nrows: %u",
152,346,460✔
459
                   pInfo->groupId, pRowSup->win.skey, pRowSup->win.ekey, pInfo->pRow->nOrigRows);
460
          } else {
461
            // check buffer size
462
            if (pRes->info.rows + pInfo->pRow->numOfRows >= pRes->info.capacity) {
403,688,664✔
463
              int32_t newSize = pRes->info.rows + pInfo->pRow->numOfRows;
777,312✔
464
              code = blockDataEnsureCapacity(pRes, newSize);
777,312✔
465
              QUERY_CHECK_CODE(code, lino, _return);
777,312✔
466
            }
467

468
            code = copyResultrowToDataBlock(pSup->pExprInfo, pSup->numOfExprs, pInfo->pRow, pSup->pCtx, pRes,
403,688,664✔
469
                                            pSup->rowEntryInfoOffset, pTaskInfo);
403,688,664✔
470
            QUERY_CHECK_CODE(code, lino, _return);
403,688,664✔
471

472
            pRes->info.rows += pInfo->pRow->numOfRows;
403,688,664✔
473
          }
474
          pInfo->pRow->numOfRows = 0;
556,035,124✔
475
          pInfo->pRow->nOrigRows = 0;
556,035,124✔
476
        }
477

478
        pInfo->inWindow = false;
556,062,940✔
479
        rowIndex += 1;
556,062,940✔
480
      } else {
481
        code = doEventWindowAggImpl(pInfo, pSup, startIndex, pBlock->info.rows - 1, pBlock, tsList, pTaskInfo);
2,274,186✔
482
        QUERY_CHECK_CODE(code, lino, _return);
2,274,186✔
483
      }
484
    } else {  // find the first start value that is fulfill for the start condition
485
      for (; rowIndex < pBlock->info.rows; ++rowIndex) {
1,510,926,828✔
486
        if (((bool*)ps->pData)[rowIndex]) {
1,510,229,854✔
487
          doKeepNewWindowStartInfo(pRowSup, tsList, rowIndex, gid);
556,330,092✔
488
          pInfo->inWindow = true;
556,330,092✔
489
          startIndex = rowIndex;
556,330,092✔
490
          if (!pInfo->indefRowsMode && pInfo->pRow != NULL) {
556,330,092✔
491
            clearResultRowInitFlag(pSup->pCtx, pSup->numOfExprs);
556,052,947✔
492
          }
493
          break;
556,330,092✔
494
        }
495
      }
496

497
      if (pInfo->inWindow) {
557,027,066✔
498
        continue;  // try to find the end position
556,330,092✔
499
      } else {
500
        break;  // no valid start position, quit
696,974✔
501
      }
502
    }
503
  }
504

505
_return:
3,826,065✔
506

507
  if (code != TSDB_CODE_SUCCESS) {
3,826,065✔
508
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
18,177✔
509
  }
510
  colDataDestroy(ps);
3,826,065✔
511
  taosMemoryFree(ps);
3,826,065✔
512
  colDataDestroy(pe);
3,826,065✔
513
  taosMemoryFree(pe);
3,826,065✔
514

515
  return code;
3,826,065✔
516
}
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