55import re
66import os
77import taos
8- from new_test_framework .utils import tdLog , tdSql , cluster , sc , clusterComCheck , etool , tdCom , AutoGen , TDSetSql
8+ import taosrest
9+ from new_test_framework .utils import tdLog , tdSql , cluster , sc , clusterComCheck , etool , tdCom , AutoGen , TDSetSql , tdStream
10+ from new_test_framework .utils .server .dnodes import tdDnodes
911
1012
1113class TestShowBasic :
@@ -817,6 +819,100 @@ def do_show_tag_index(self):
817819
818820 print ("do show tag index ..................... [passed]" )
819821
822+ def _assert_show_streams_name_db_rows (self , expected_pairs , require_nonzero = False ):
823+ """Last query must be SHOW STREAMS (or equivalent); compare (stream_name, db_name) on cols 0 and 3, order-independent."""
824+ if require_nonzero :
825+ tdSql .checkAssert (tdSql .getRows () > 0 )
826+ got = [(tdSql .getData (i , 0 ), tdSql .getData (i , 3 )) for i in range (tdSql .getRows ())]
827+ tdSql .checkEqual (sorted (got ), sorted (expected_pairs ))
828+
829+ #
830+ # ------------------- show streams without database ----------------
831+ #
832+ def do_show_streams_no_db (self ):
833+ """Test SHOW STREAMS works without a selected database and shows db_name column."""
834+ tdLog .info ("do_show_streams_no_db ..................... [start]" )
835+
836+ # New taos client session (same deploy as conftest get_taos_conn) so current DB is not inherited
837+ # from prior steps (e.g. use db). Restore cls.conn cursor in finally for teardown.
838+ _saved_conn = self .conn
839+ try :
840+ tdSql .close ()
841+ except Exception :
842+ pass
843+ if getattr (self , "restful" , False ):
844+ _conn = taosrest .connect (url = f"http://{ self .host } :6041" , timezone = "utc" )
845+ else :
846+ _conn = taos .connect (host = self .host , config = tdDnodes .sim .cfgPath )
847+ tdSql .init (_conn .cursor (), False )
848+ try :
849+ tdSql .execute ("drop database if exists ss_db1" )
850+ tdSql .execute ("drop database if exists ss_db2" )
851+ tdSql .execute ("create database ss_db1" )
852+ tdSql .execute ("create database ss_db2" )
853+
854+ # Create source tables in each db
855+ tdSql .execute ("create table ss_db1.src1 (ts timestamp, v int)" )
856+ tdSql .execute ("create table ss_db2.src2 (ts timestamp, v int)" )
857+
858+ # Ensure an snode exists (required for stream creation)
859+ tdStream .createSnode (1 )
860+ # Create a stream in each database
861+ tdSql .execute (
862+ "create stream ss_db1.ss1 INTERVAL(1s) SLIDING(1s) from ss_db1.src1 into ss_db1.dst1 as select _tlocaltime as ts, count(v) as cnt from ss_db1.src1"
863+ )
864+ tdSql .execute (
865+ "create stream ss_db2.ss2 INTERVAL(1s) SLIDING(1s) from ss_db2.src2 into ss_db2.dst2 as select _tlocaltime as ts, count(v) as cnt from ss_db2.src2"
866+ )
867+ tdSql .execute (
868+ "create stream ss_db1.stm3 count_window(1) from ss_db1.src1 into ss_db1.dst1 as select _tlocaltime as ts, count(v) as cnt from ss_db1.src1"
869+ )
870+ tdSql .execute (
871+ "create stream ss_db2.stm4 count_window(1) from ss_db2.src2 into ss_db2.dst2 as select _tlocaltime as ts, count(v) as cnt from ss_db2.src2"
872+ )
873+ tdStream .checkStreamStatus ()
874+
875+ # (stream_name, db_name); order-independent — same idea as tdSql.checkEqual(sorted(...), sorted(...)) in e.g. test_write_sml_opentsdb_json.py
876+ tdLog .info ("check show streams" )
877+ tdSql .query ("show streams" )
878+ exp_all = [
879+ ("stm4" , "ss_db2" ),
880+ ("stm3" , "ss_db1" ),
881+ ("ss2" , "ss_db2" ),
882+ ("ss1" , "ss_db1" ),
883+ ]
884+ self ._assert_show_streams_name_db_rows (exp_all , require_nonzero = True )
885+
886+ tdLog .info ("check show streams like 'ss%'" )
887+ tdSql .query ("show streams like 'ss%'" )
888+ exp_ss = [("ss2" , "ss_db2" ), ("ss1" , "ss_db1" )]
889+ self ._assert_show_streams_name_db_rows (exp_ss )
890+
891+ tdLog .info ("check show streams like 'stm%'" )
892+ tdSql .query ("show streams like 'stm%'" )
893+ exp_stm = [("stm4" , "ss_db2" ), ("stm3" , "ss_db1" )]
894+ self ._assert_show_streams_name_db_rows (exp_stm )
895+
896+ tdLog .info ("check show streams db.streams" )
897+ tdSql .query ("show ss_db1.streams" )
898+ exp_db1 = [("stm3" , "ss_db1" ), ("ss1" , "ss_db1" )]
899+ self ._assert_show_streams_name_db_rows (exp_db1 )
900+
901+ tdSql .query ("show ss_db2.streams" )
902+ exp_db2 = [("stm4" , "ss_db2" ), ("ss2" , "ss_db2" )]
903+ self ._assert_show_streams_name_db_rows (exp_db2 )
904+ tdLog .info ("do_show_streams_no_db ..................... [passed]" )
905+ finally :
906+ try :
907+ tdSql .close ()
908+ except Exception :
909+ pass
910+ try :
911+ _conn .close ()
912+ except Exception :
913+ pass
914+ tdSql .init (_saved_conn .cursor (), False )
915+
820916 #
821917 # ------------------- main ----------------
822918 #
@@ -839,6 +935,7 @@ def test_show_basic(self):
839935 show tags from super table/child table
840936 show table tags from super table/child table
841937 show indexes from super table/child table
938+ 9. Verify SHOW STREAMS works without a selected database and shows db_name column
842939
843940
844941 Since: v3.0.0.0
@@ -852,9 +949,11 @@ def test_show_basic(self):
852949 - 2025-10-17 Alex Duan Migrated from uncatalog/system-test/0-others/test_show.py
853950 - 2025-4-28 Simon Guan Migrated from tsim/show/basic.sim
854951 - 2025-11-03 Alex Duan Migrated from uncatalog/system-test/0-others/test_show_tag_index.py
952+ - 2026-04-03 Mario Peng Add test_show_streams_no_db
855953
856954 """
857955 self .do_system_test_show ()
858956 self .do_army_show ()
859957 self .do_sim ()
860- self .do_show_tag_index ()
958+ self .do_show_tag_index ()
959+ self .do_show_streams_no_db ()
0 commit comments