Skip to content

feat(stream): support nested event window sub-events#35149

Closed
JinqingKuang wants to merge 2 commits intomainfrom
feat/event-window-multilevel-sub-events
Closed

feat(stream): support nested event window sub-events#35149
JinqingKuang wants to merge 2 commits intomainfrom
feat/event-window-multilevel-sub-events

Conversation

@JinqingKuang
Copy link
Copy Markdown
Contributor

@JinqingKuang JinqingKuang commented Apr 15, 2026

Description

  • Extend EVENT_WINDOW START WITH to accept nested condition trees.
  • Keep the outer true_for syntax backward compatible for existing stream definitions.
  • Allow leaf conditions to override true_for, while parent groups still inherit the outer setting.
  • Add _event_condition_path support through parser, node serialization, planning, and runtime.
  • Fix nested start-condition match reads in history and realtime execution so leaf true_for checks use the correct value width.
  • Refresh parser tests, stream system tests, and SQL documentation for nested starts, condition-path placeholders, and leaf-specific true_for behavior.

Issue(s)

Checklist

Please check the items in the checklist if applicable.

  • Is the user manual updated?
  • Are the test cases passed and automated?
  • Is there no significant decrease in test coverage?

Copilot AI review requested due to automatic review settings April 15, 2026 09:38
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request implements multi-level nested sub-event support for EVENT_WINDOW in stream processing. It introduces the _event_condition_path placeholder to identify matched nodes within a hierarchical start-condition tree and updates the notification payload to include conditionPath. The implementation includes changes to the parser, stream trigger task logic, and documentation. Feedback was provided regarding safer path length calculations and ensuring null-safety when evaluating event conditions.

Comment thread source/libs/new-stream/src/streamTriggerTask.c Outdated
Comment thread source/libs/new-stream/src/streamTriggerTask.c
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR extends TDengine stream EVENT_WINDOW support to allow recursively nested START WITH groups, propagates a stable runtime “conditionPath” for matched nodes, and exposes that path via the new _event_condition_path placeholder and updated notification payload fields.

Changes:

  • Parser: add recursive START WITH grammar (start_event_item) and validation for _event_condition_path usage.
  • Runtime: build/start-condition metadata (node ids + stable paths), evaluate nested start trees, and propagate conditionPath through trigger calc params and notifications.
  • Function/Scalar plumbing: register _event_condition_path as a pseudo/placeholder function and populate its value at execution time; add tests and docs.

Reviewed changes

Copilot reviewed 19 out of 19 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
test/cases/18-StreamProcessing/03-TriggerMode/test_event_new.py Adds a system test verifying nested start groups produce expected _event_condition_path values.
source/libs/scalar/src/scalar.c Populates _event_condition_path placeholder results via new varstring setters.
source/libs/parser/test/parStreamTest.cpp Adds parser tests for nested start condition AST shape and placeholder legality.
source/libs/parser/src/parTranslater.c Tracks placeholder bitmap and enforces _event_condition_path validity for event windows with sub-events.
source/libs/parser/src/parTokenizer.c Adds keyword mapping for _EVENT_CONDITION_PATH.
source/libs/parser/inc/sql.y Introduces recursive start_event_item grammar and _event_condition_path pseudo column.
source/libs/new-stream/src/streamUtil.c Updates event notification payload to include conditionPath + conditionIndex and removes windowIndex.
source/libs/new-stream/src/streamTriggerTask.c Implements nested start-condition evaluation, path switching, and conditionPath propagation into calc params/notifications.
source/libs/new-stream/inc/streamTriggerTask.h Extends window structs with eventNodeId and adds start-condition meta structures.
source/libs/new-stream/inc/streamInt.h Updates streamBuildEventNotifyContent signature to accept conditionPath.
source/libs/function/src/functionMgt.c Exposes conditionPath as a stream pseudo value and wires placeholder parameter updates.
source/libs/function/src/builtins.c Registers _event_condition_path builtin and its return type handling.
source/common/src/msg/streamMsg.c Serializes/deserializes conditionPath in SSTriggerCalcParam and frees it in destructor.
include/libs/function/functionMgt.h Adds FUNCTION_TYPE_EVENT_CONDITION_PATH.
include/common/streamMsg.h Adds placeholder bit + conditionPath field to trigger calc param struct.
docs/zh/06-advanced/03-stream.md Documents nested start_event_item and _event_condition_path (ZH advanced).
docs/zh/14-reference/03-taos-sql/41-stream.md Updates syntax/semantics and notification JSON fields (ZH reference).
docs/en/06-advanced/03-stream.md Documents nested start_event_item and _event_condition_path (EN advanced).
docs/en/14-reference/03-taos-sql/41-stream.md Updates syntax/semantics and notification JSON fields (EN reference).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread source/libs/new-stream/src/streamTriggerTask.c
@JinqingKuang JinqingKuang force-pushed the feat/event-window-multilevel-sub-events branch 2 times, most recently from cde25f3 to 4554448 Compare April 17, 2026 08:21
Copilot AI review requested due to automatic review settings April 17, 2026 08:21
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 21 out of 21 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread conan/fast-lzma2/conanfile.py
Comment thread cmake/in/lzma2.Makefile
Comment thread source/libs/new-stream/inc/streamTriggerTask.h
@JinqingKuang JinqingKuang force-pushed the feat/event-window-multilevel-sub-events branch 2 times, most recently from 3ad9570 to 569b488 Compare April 21, 2026 08:08
Copilot AI review requested due to automatic review settings April 22, 2026 06:23
@JinqingKuang JinqingKuang force-pushed the feat/event-window-multilevel-sub-events branch from 569b488 to ef3d5b5 Compare April 22, 2026 06:23
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 27 out of 27 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread source/libs/scalar/src/scalar.c Outdated
Comment on lines +886 to +916
size_t len = strlen(pVal);
char* buf = taosMemoryCalloc(len + VARSTR_HEADER_SIZE, 1);
if (buf == NULL) {
return terrno;
}
*(VarDataLenT*)buf = (VarDataLenT)len;
if (len > 0) {
(void)memcpy(varDataVal(buf), pVal, len);
}
int32_t code = colDataSetVal(pResColData, rowIndex, buf, false);
taosMemoryFreeClear(buf);
return code;
}

static int32_t sclSetVarDataCStringN(SColumnInfoData* pResColData, uint32_t currentRow, uint32_t numOfRows,
const char* pVal) {
if (pVal == NULL) {
colDataSetNItemsNull(pResColData, currentRow, numOfRows);
return TSDB_CODE_SUCCESS;
}

size_t len = strlen(pVal);
char* buf = taosMemoryCalloc(len + VARSTR_HEADER_SIZE, 1);
if (buf == NULL) {
return terrno;
}
*(VarDataLenT*)buf = (VarDataLenT)len;
if (len > 0) {
(void)memcpy(varDataVal(buf), pVal, len);
}
int32_t code = colDataSetNItems(pResColData, currentRow, buf, numOfRows, 1, false);
Copy link

Copilot AI Apr 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sclSetVarDataCString/sclSetVarDataCStringN cast strlen(pVal) to VarDataLenT (uint16). If conditionPath (or any future caller) exceeds 65535 bytes, the length header will truncate and produce a malformed VARSTR. Add an explicit len <= UINT16_MAX check (and return an error or clamp consistently with other VARSTR builders) before writing the header.

Copilot uses AI. Check for mistakes.
Comment thread source/libs/function/src/functionMgt.c Outdated
Comment on lines +995 to +1002
size_t len = strlen(pVal);
((SValueNode*)pFirstParam)->datum.p = taosMemoryCalloc(len + VARSTR_HEADER_SIZE, 1);
if (NULL == ((SValueNode*)pFirstParam)->datum.p) {
return terrno;
}
(void)memcpy(varDataVal(((SValueNode*)pFirstParam)->datum.p), pVal, len);
varDataLen(((SValueNode*)pFirstParam)->datum.p) = len;
((SValueNode*)pFirstParam)->isNull = false;
Copy link

Copilot AI Apr 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When populating the VARSTR for _event_condition_path, len is assigned from strlen(pVal) and then written into varDataLen(...) (VarDataLenT/uint16). If the path string is ever longer than 65535 bytes, this will overflow/truncate the VARSTR length header. Please validate the length (and fail or clamp) before allocating/writing the header.

Copilot uses AI. Check for mistakes.
Jinqing Kuang and others added 2 commits April 23, 2026 15:15
- Extend EVENT_WINDOW START WITH to accept nested condition trees.
- Keep the outer true_for syntax backward compatible for existing
  stream definitions.
- Allow leaf conditions to override true_for, while parent groups still
  inherit the outer setting.
- Add _event_condition_path support through parser, node serialization,
  planning, and runtime.
- Fix nested start-condition match reads in history and realtime
  execution so leaf true_for checks use the correct value width.
- Refresh parser tests, stream system tests, and SQL documentation for
  nested starts, condition-path placeholders, and leaf-specific
  true_for behavior.

Co-authored-by: OpenAI Codex GPT-5 <noreply@openai.com>
@JinqingKuang JinqingKuang force-pushed the feat/event-window-multilevel-sub-events branch from ef3d5b5 to be5e94d Compare April 26, 2026 04:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants