-
Notifications
You must be signed in to change notification settings - Fork 5k
fix(stream/fetch): fix stream data fetching from runner #34170
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+160
−2
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
a79e439
fix(stream/fetch): fix stream data fetching from runner
stephenkgu 5a3069f
fix(udf): no decoding with error rsp
stephenkgu 39b5309
Merge branch 'fix/not-decodong-w-error-rsp' into fix/stream-fetch-fro…
stephenkgu 8398d17
not malloc udf handle in case errors
stephenkgu 049513a
Merge branch 'fix/not-decodong-w-error-rsp' into fix/stream-fetch-fro…
stephenkgu 40c9d65
free udf in error cases
stephenkgu 7e1b5d6
Merge branch 'fix/not-decodong-w-error-rsp' into fix/stream-fetch-fro…
stephenkgu 306d5c4
fix multithread issues
stephenkgu e1c0b67
fix multithread issues
stephenkgu 9a64d49
dec udf refcount in error cases
stephenkgu ab7383f
Merge branch 'fix/not-decodong-w-error-rsp' into fix/stream-fetch-fro…
stephenkgu 0ab100f
Merge branch 'main' into fix/stream-fetch-from-runner
stephenkgu f5a223d
test case for stream interval result
stephenkgu 5f0b5bb
test case for count window stream
stephenkgu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
156 changes: 156 additions & 0 deletions
156
test/cases/18-StreamProcessing/02-Stream/stream_fetch.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,156 @@ | ||
| import time | ||
| import math | ||
| import random | ||
| from new_test_framework.utils import tdLog, tdSql, tdStream, streamUtil,StreamTableType, StreamTable, cluster | ||
| from random import randint | ||
| import os | ||
| import subprocess | ||
|
|
||
| class TestStreamFetch: | ||
| def setup_class(cls): | ||
| tdLog.debug(f"start to execute {__file__}") | ||
|
|
||
| def test_stream_fetch(self): | ||
| """Stream fetch data from runner | ||
|
|
||
| 1. Check stream interval result | ||
|
|
||
|
|
||
| Since: v3.3.8.11 | ||
|
|
||
| Labels: common,ci | ||
|
|
||
| Jira: None | ||
|
|
||
| History: | ||
| - 2026-01-06 Stephen Jin Created | ||
|
|
||
| """ | ||
|
|
||
|
|
||
| self.prepareData() | ||
| # create the interval stream | ||
| self.createIntervalStream() | ||
| # check the interval stream result | ||
| self.checkIntervalResult() | ||
| self.prepareCountData() | ||
| self.createCountStream() | ||
| self.checkCountResult() | ||
|
|
||
| def prepareData(self): | ||
| tdLog.info(f"prepare data") | ||
|
|
||
| sqls = [ | ||
| "alter dnode 1 'debugflag 135';", | ||
| "create snode on dnode 1;", | ||
| "create database db vgroups 4;", | ||
| "create table db.meters (ts timestamp, current int) tags(`groupid` int);" | ||
| ] | ||
|
|
||
| ts = 1767196800000 # int(time.time())*1000 | ||
| for t in range(0, 4): | ||
| sqls.append(f"create table db.d{t} using db.meters tags({t})") | ||
| for i in range(0, 12000000, 1000): | ||
| sqls.append(f"insert into db.d{t} values({ts+i},{i})") | ||
|
|
||
| tdSql.executes(sqls) | ||
| tdLog.info(f"create successfully.") | ||
|
|
||
| def createIntervalStream(self): | ||
| tdLog.info(f"create stream:") | ||
| sql = ( | ||
| f"create stream db.meters_stream_interval_3 interval(3s) sliding(3s) from db.meters partition by tbname ,groupid stream_options (fill_history ('2026-01-01 00:00:00') |event_type (window_close) |force_output |pre_filter (tbname in ('d0','d1','d2'))) into db.stream_meters_interval output_subtable (concat('run_s_3#', tbname)) tags (point_name varchar(128) as '全椒2#窑运行状态', point_id varchar(128) as 'run_state_2#') as select _twend as ts, last(case when tbname = 'd0' then current end) as kilnrun, last(case when tbname = 'd1' then current end) as flowfeedback, last(case when tbname = 'd2' then current end) as fanrun, cast(case when last(case when tbname = 'd0' then current end) = 1.0 and last(case when tbname = 'd1' then current end) > 120.0 and last(case when tbname = 'd2' then current end) = 1.0 then 1 else 0 end as int) as run_state from db.meters where tbname in ('d0','d1','d2') and ts >= _twstart and ts < _twend;" | ||
| ) | ||
|
|
||
| tdLog.info(f"create stream:{sql}") | ||
|
|
||
| try: | ||
| tdSql.execute(sql) | ||
| except Exception as e: | ||
| if "No stream available snode now" not in str(e): | ||
| raise Exception(f" user cant create stream no snode ,but create success") | ||
|
|
||
| while True: | ||
| tdSql.query(f"select status from information_schema.ins_streams") | ||
| if tdSql.getData(0,0) == "Running": | ||
| tdLog.info("Stream is running!") | ||
| break | ||
|
|
||
| tdLog.debug(f"current stream status: {tdSql.getData(0,0)}") | ||
| time.sleep(1) | ||
|
|
||
| def checkIntervalResult(self): | ||
| tdLog.info(f"checkIntervalResult start") | ||
|
|
||
| while True: | ||
| tdSql.query(f"select count(*) from db.`run_s_3#d0`") | ||
| if tdSql.getData(0,0) == 4000: | ||
| tdLog.info(f"get {tdSql.getData(0,0)} rows") | ||
| break | ||
|
|
||
| tdLog.debug(f"current row count: {tdSql.getData(0,0)}") | ||
| time.sleep(1) | ||
|
|
||
| tdSql.query(f"select * from db.`run_s_3#d0` order by ts limit 3065,10") | ||
| tdSql.checkData(7, 1, 9218000) | ||
|
|
||
| tdLog.info(f"check stream result successfully.") | ||
|
|
||
| def prepareCountData(self): | ||
| tdLog.info(f"prepare count data") | ||
|
|
||
| sqls = [ | ||
| "alter dnode 1 'debugflag 135';", | ||
| "drop database db", | ||
| "create database db vgroups 4;", | ||
| "create table db.meters (ts timestamp, current int) tags(`groupid` int);" | ||
| ] | ||
|
|
||
| ts = 1767196800000 # int(time.time())*1000 | ||
| for t in range(0, 4): | ||
| sqls.append(f"create table db.d{t} using db.meters tags({t})") | ||
| for i in range(0, 4000000, 1000): | ||
| sqls.append(f"insert into db.d{t} values({ts+i},{i})") | ||
|
|
||
| tdSql.executes(sqls) | ||
| tdLog.info(f"create successfully.") | ||
|
|
||
| def createCountStream(self): | ||
| tdLog.info(f"create stream:") | ||
| sql = ( | ||
| f"create stream db.meters_stream_count count_window(2,1) from db.meters partition by tbname ,groupid stream_options (fill_history ('2026-01-01 00:00:00') |low_latency_calc|watermark(10s)) into db.stream_meters_count output_subtable (concat('run_c_3#', tbname)) tags (groupid int as groupid) as select _twstart as ts, last(current) as now_batch, first(current) as previous_batch, _twstart as starttime, _twend as endtime from %%tbname where ts >= _twstart and ts<=_twend " | ||
| ) | ||
|
|
||
| tdLog.info(f"create stream:{sql}") | ||
|
|
||
| try: | ||
| tdSql.execute(sql) | ||
| except Exception as e: | ||
| if "No stream available snode now" not in str(e): | ||
| raise Exception(f" user cant create stream no snode ,but create success") | ||
|
|
||
| while True: | ||
| tdSql.query(f"select status from information_schema.ins_streams") | ||
| if tdSql.getData(0,0) == "Running": | ||
| tdLog.info("Stream is running!") | ||
| break | ||
|
|
||
| tdLog.debug(f"current stream status: {tdSql.getData(0,0)}") | ||
| time.sleep(1) | ||
|
|
||
| def checkCountResult(self): | ||
| tdLog.info(f"checkIntervalResult start") | ||
|
|
||
| while True: | ||
| tdSql.query(f"select count(*) from db.`run_c_3#d0`") | ||
| if tdSql.getData(0,0) == 3999: | ||
| tdLog.info(f"get {tdSql.getData(0,0)} rows") | ||
| break | ||
|
|
||
| tdLog.debug(f"current row count: {tdSql.getData(0,0)}") | ||
| time.sleep(1) | ||
|
|
||
| tdSql.query(f"select * from db.`run_c_3#d0` order by ts limit 3065,10") | ||
| tdSql.checkData(7, 1, 3073000) | ||
|
|
||
| tdLog.info(f"check stream result successfully.") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.