Skip to content

feat(stream): support the change of vtable in stream#34715

Open
wangmm0220 wants to merge 22 commits into3.0from
feat/TD-37208-3.0
Open

feat(stream): support the change of vtable in stream#34715
wangmm0220 wants to merge 22 commits into3.0from
feat/TD-37208-3.0

Conversation

@wangmm0220
Copy link
Contributor

Description

Issue(s)

  • Close/close/Fix/fix/Resolve/resolve: Issue Link

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 March 9, 2026 02:37
@wangmm0220 wangmm0220 requested a review from a team as a code owner March 9, 2026 02:37
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the stream processing capabilities by introducing support for dynamic modifications to virtual tables (vtables). The changes are validated through an updated test case that demonstrates the system's ability to correctly handle ALTER VTABLE operations, specifically when altering a vtable column's source or setting it to null, ensuring robust and adaptable stream processing.

Highlights

  • Debug Flags: Updated debug flags for stream processing nodes in the test setup.
  • Stream Creation Refactoring: Refactored stream creation test cases, introducing new stream definitions (s1, s2, s3).
  • ALTER VTABLE Support: Expanded test coverage for ALTER VTABLE statements, including changing a vtable column's source and setting it to null.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • test/cases/18-StreamProcessing/04-Options/test_meta_change_vtable.py
    • Updated debugflag and stdebugflag values in the test setup.
    • Refactored stream creation within the create method, removing commented-out code and adding three new stream definitions (s1, s2, s3).
    • Modified the insert3 method to include new CREATE VTABLE statements and ALTER VTABLE operations, specifically demonstrating changing a vtable column's source and setting it to null.
Activity
  • No human activity has been recorded on this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
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 updates stream processing tests to support the "alter vtable" operations in streams, specifically testing scenarios where virtual table (vtable) column source references are changed or nulled. The key changes are in the Basic37208 test class within test_meta_change_vtable.py.

Changes:

  • Replaced the old placeholder debug flags (debugflag 131 / stdebugflag 131) with more specific flags (qdebugflag 143 / stdebugflag 135) that produce more detailed vtable query and stream debug logs.
  • Rewrote Basic37208.create() to define three focused streams (s1, s2, s3) targeting vtable operations instead of the previous commented-out approach.
  • Expanded insert3 to exercise vtable tag changes and the new ALTER VTABLE ... ALTER COLUMN ... SET and SET NULL operations; added vct3, vct4, vct5 setup for wider coverage.

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

You can also share your feedback on Copilot code review. Take the survey.

Comment on lines 155 to 186

def insert3(self):
tdSql.execute(f"create vtable {self.db}.vct3 (cint from {self.db}.ct3.cint) using {self.db}.{self.vstbName} tags(10,10)")
tdSql.execute(f"create vtable {self.db}.vct4 (cint from {self.db}.ct3.cint) using {self.db}.{self.vstbName} tags(20,20)")
tdSql.execute(f"create vtable {self.db}.vct4 (cint from {self.db}.ct4.cint) using {self.db}.{self.vstbName} tags(-20,-20)")
tdSql.execute(f"create vtable {self.db}.vct5 (cint from {self.db}.ct2.cint) using {self.db}.{self.vstbName} tags(20,20)")
time.sleep(5)
tdSql.execute(f"insert into ct4 values ('2025-01-01 00:01:00', 1);")
tdSql.execute(f"insert into ct3 values ('2025-01-01 00:01:00', 1);")
tdSql.execute(f"alter table {self.db}.ct1 set tag tbigint = 30")
tdSql.execute(f"insert into ct2 values ('2025-01-05 10:01:00', 1);")

tdSql.execute(f"alter table {self.db}.vct1 set tag tbigint = 30")
time.sleep(5)
tdSql.execute(f"insert into {self.db}.ct1 values ('2025-01-03 00:00:00', 1);")
tdSql.execute(f"alter table {self.db}.ct3 set tag tbigint = 3")
tdSql.execute(f"alter table {self.db}.ct4 set tag tbigint = 30")

tdSql.execute(f"alter table {self.db}.vct3 set tag tbigint = -3")
tdSql.execute(f"alter table {self.db}.vct4 set tag tbigint = -30")
tdSql.execute(f"alter table {self.db}.vct5 set tag tbigint = 60")
time.sleep(5)
tdSql.execute(f"insert into ct4 values ('2025-01-02 00:01:00', 1);")
tdSql.execute(f"insert into ct3 values ('2025-01-02 00:01:00', 1);")

tdSql.execute(f"alter vtable {self.db}.vct4 alter column cint set {self.db}.ct2.cint")
time.sleep(5)
tdSql.execute(f"insert into ct2 values ('2025-01-05 10:01:10', 1);")

tdSql.execute(f"alter vtable {self.db}.vct4 alter column cint set null")
time.sleep(5)
tdSql.execute(f"insert into ct2 values ('2025-01-05 10:01:11', 1);")

def check3(self):
tdSql.checkResultsByFunc(
sql=f'select * from information_schema.ins_tables where db_name="{self.db}" and table_name like "res_stb_%"',
Copy link

Copilot AI Mar 9, 2026

Choose a reason for hiding this comment

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

The check3 method references output table names res_stb_t2_vct1, res_stb_t2_vct3, and res_stb_f_vct4 (lines 191, 201, 211), but none of the three streams defined in create() generate tables with those prefixes. Stream s1 uses prefix res_stb_, stream s2 uses res_stb_1_, and stream s3 uses res_stb_2_. These check queries appear to be stale references from the old commented-out stream definitions (s37208_g_t2res_stb_t2_ and s37208_g_fres_stb_f_). If Basic37208 is re-enabled, these checks will always fail because the expected result tables don't exist under those names.

Copilot uses AI. Check for mistakes.
Copy link
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 enhances stream processing capabilities by adding support for metadata changes in virtual tables. The changes are demonstrated through updates to a Python test file, which now includes scenarios for altering virtual table tags and columns. My review focuses on improving code consistency and test reliability. Specifically, I've pointed out an inconsistent SQL keyword casing and suggested refactoring repeated time.sleep calls to make the tests more robust and maintainable. Overall, the changes are a good addition and the tests seem to cover the new functionality well.

Comment on lines +84 to +86
tdSql.execute(
f"create stream {self.db}.s3 count_window(1) from {self.vstbName} partition by tbname, tint stream_options(PRE_FILTER(tbigint <= 2)) into {self.db}.res_stb_2 OUTPUT_SUBTABLE(CONCAT('res_stb_2_', tbname)) (firstts, lastts, cnt_v, sum_v, avg_v) as select first(_c0), last_row(_c0), count(cint), sum(cint), avg(cint) from {self.vstbName};"
)
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

For consistency with other stream definitions in this file, it's better to use lowercase for SQL keywords like pre_filter. Also, the trailing semicolon in the f-string is unnecessary and can be removed.

Suggested change
tdSql.execute(
f"create stream {self.db}.s3 count_window(1) from {self.vstbName} partition by tbname, tint stream_options(PRE_FILTER(tbigint <= 2)) into {self.db}.res_stb_2 OUTPUT_SUBTABLE(CONCAT('res_stb_2_', tbname)) (firstts, lastts, cnt_v, sum_v, avg_v) as select first(_c0), last_row(_c0), count(cint), sum(cint), avg(cint) from {self.vstbName};"
)
tdSql.execute(
f"create stream {self.db}.s3 count_window(1) from {self.vstbName} partition by tbname, tint stream_options(pre_filter(tbigint <= 2)) into {self.db}.res_stb_2 OUTPUT_SUBTABLE(CONCAT('res_stb_2_', tbname)) (firstts, lastts, cnt_v, sum_v, avg_v) as select first(_c0), last_row(_c0), count(cint), sum(cint), avg(cint) from {self.vstbName}"
)

Comment on lines 160 to +182
time.sleep(5)
tdSql.execute(f"insert into ct4 values ('2025-01-01 00:01:00', 1);")
tdSql.execute(f"insert into ct3 values ('2025-01-01 00:01:00', 1);")
tdSql.execute(f"alter table {self.db}.ct1 set tag tbigint = 30")
tdSql.execute(f"insert into ct2 values ('2025-01-05 10:01:00', 1);")

tdSql.execute(f"alter table {self.db}.vct1 set tag tbigint = 30")
time.sleep(5)
tdSql.execute(f"insert into {self.db}.ct1 values ('2025-01-03 00:00:00', 1);")
tdSql.execute(f"alter table {self.db}.ct3 set tag tbigint = 3")
tdSql.execute(f"alter table {self.db}.ct4 set tag tbigint = 30")

tdSql.execute(f"alter table {self.db}.vct3 set tag tbigint = -3")
tdSql.execute(f"alter table {self.db}.vct4 set tag tbigint = -30")
tdSql.execute(f"alter table {self.db}.vct5 set tag tbigint = 60")
time.sleep(5)
tdSql.execute(f"insert into ct4 values ('2025-01-02 00:01:00', 1);")
tdSql.execute(f"insert into ct3 values ('2025-01-02 00:01:00', 1);")

tdSql.execute(f"alter vtable {self.db}.vct4 alter column cint set {self.db}.ct2.cint")
time.sleep(5)
tdSql.execute(f"insert into ct2 values ('2025-01-05 10:01:10', 1);")

tdSql.execute(f"alter vtable {self.db}.vct4 alter column cint set null")
time.sleep(5)
tdSql.execute(f"insert into ct2 values ('2025-01-05 10:01:11', 1);")
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The insert3 method contains multiple time.sleep(5) calls. These hardcoded sleeps can make tests slower and potentially flaky. Consider refactoring these waits into a helper method, for example _wait_for_stream_processing(seconds=5). This would improve readability by making the purpose of the wait explicit and centralize the wait duration, making it easier to adjust if needed. A more robust solution would be to use a polling mechanism to check for the expected state instead of a fixed sleep time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants