Skip to content

Commit 5ce853d

Browse files
Merge branch '3.0' into merge/mainto3.0
2 parents 9a98596 + b0a879b commit 5ce853d

9 files changed

Lines changed: 132 additions & 30 deletions

File tree

docs/en/14-reference/03-taos-sql/52-show.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,10 +177,10 @@ Displays information about all supertables in the current database. You can use
177177
## SHOW STREAMS
178178

179179
```sql
180-
SHOW [db_name.]STREAMS;
180+
SHOW [db_name.]STREAMS [LIKE 'pattern'];
181181
```
182182

183-
Displays information about all stream computations in the current database.
183+
Displays information about stream computations. If db_name is not specified, it displays streams from all databases. You can use LIKE for fuzzy matching of stream names.
184184

185185
## SHOW SUBSCRIPTIONS
186186

docs/zh/14-reference/03-taos-sql/52-show.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,10 +189,10 @@ SHOW [db_name.]STABLES [LIKE 'pattern'];
189189
## SHOW STREAMS
190190

191191
```sql
192-
SHOW [db_name.]STREAMS;
192+
SHOW [db_name.]STREAMS [LIKE 'pattern'];
193193
```
194194

195-
显示当前数据库下的所有流计算的信息
195+
显示流计算的信息。如果不指定数据库,则显示所有数据库下的流计算。可以使用 LIKE 对流名进行模糊匹配
196196

197197
## SHOW SUBSCRIPTIONS
198198

source/libs/parser/inc/parAst.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@ SNode* createShowTSMASStmt(SAstCreateContext* pCxt, SNode* dbName);
546546
SNode* createShowDiskUsageStmt(SAstCreateContext* pCxt, SNode* dbName, ENodeType type);
547547
SNodeList* createColsFuncParamNodeList(SAstCreateContext* pCxt, SNode* pFuncNode, SNodeList* pNodeList, SToken* pAlias);
548548

549-
SNode* createShowStreamsStmt(SAstCreateContext* pCxt, SNode* dbName, ENodeType type);
549+
SNode* createShowStreamsStmt(SAstCreateContext* pCxt, SNode* pDbName, SNode* pLike, ENodeType type);
550550
SNode* createScanStmt(SAstCreateContext* pCxt, SToken* pDbName, SNode* pStart, SNode* pEnd);
551551
SNode* createScanVgroupsStmt(SAstCreateContext* pCxt, SNode* pDbName, SNodeList* vgidList, SNode* pStart, SNode* pEnd);
552552
SNode* createShowScansStmt(SAstCreateContext* pCxt, ENodeType type);

source/libs/parser/inc/sql.y

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1322,7 +1322,7 @@ cmd ::= SHOW ARBGROUPS.
13221322
cmd ::= SHOW FUNCTIONS. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_FUNCTIONS_STMT); }
13231323
cmd ::= SHOW INDEXES FROM table_name_cond(A) from_db_opt(B). { pCxt->pRootNode = createShowStmtWithCond(pCxt, QUERY_NODE_SHOW_INDEXES_STMT, B, A, OP_TYPE_EQUAL); }
13241324
cmd ::= SHOW INDEXES FROM db_name(B) NK_DOT table_name(A). { pCxt->pRootNode = createShowStmtWithCond(pCxt, QUERY_NODE_SHOW_INDEXES_STMT, createIdentifierValueNode(pCxt, &B), createIdentifierValueNode(pCxt, &A), OP_TYPE_EQUAL); }
1325-
cmd ::= SHOW db_name_cond_opt(A) STREAMS. { pCxt->pRootNode = createShowStreamsStmt(pCxt, A, QUERY_NODE_SHOW_STREAMS_STMT); }
1325+
cmd ::= SHOW db_name_cond_opt(A) STREAMS like_pattern_opt(B). { pCxt->pRootNode = createShowStreamsStmt(pCxt, A, B, QUERY_NODE_SHOW_STREAMS_STMT); }
13261326
cmd ::= SHOW ACCOUNTS. { pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_EXPRIE_STATEMENT); }
13271327
cmd ::= SHOW APPS. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_APPS_STMT); }
13281328
cmd ::= SHOW CONNECTIONS. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_CONNECTIONS_STMT); }

source/libs/parser/src/parAstCreater.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8216,25 +8216,22 @@ SNode* createShowDiskUsageStmt(SAstCreateContext* pCxt, SNode* dbName, ENodeType
82168216
return NULL;
82178217
}
82188218

8219-
SNode* createShowStreamsStmt(SAstCreateContext* pCxt, SNode* pDbName, ENodeType type) {
8219+
SNode* createShowStreamsStmt(SAstCreateContext* pCxt, SNode* pDbName, SNode* pLike, ENodeType type) {
82208220
CHECK_PARSER_STATUS(pCxt);
82218221

8222-
if (needDbShowStmt(type) && NULL == pDbName) {
8223-
snprintf(pCxt->pQueryCxt->pMsg, pCxt->pQueryCxt->msgLen, "database not specified");
8224-
pCxt->errCode = TSDB_CODE_PAR_SYNTAX_ERROR;
8225-
CHECK_PARSER_STATUS(pCxt);
8226-
}
8227-
82288222
SShowStmt* pStmt = NULL;
82298223
pCxt->errCode = nodesMakeNode(type, (SNode**)&pStmt);
82308224
CHECK_MAKE_NODE(pStmt);
82318225
pStmt->withFull = false;
82328226
pStmt->pDbName = pDbName;
8227+
pStmt->pTbName = pLike;
8228+
pStmt->tableCondType = OP_TYPE_LIKE;
82338229

82348230
return (SNode*)pStmt;
82358231

82368232
_err:
82378233
nodesDestroyNode(pDbName);
8234+
nodesDestroyNode(pLike);
82388235
return NULL;
82398236
}
82408237

source/libs/parser/src/parAstParser.c

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1112,16 +1112,18 @@ static int32_t collectMetaKeyFromShowStables(SCollectMetaKeyCxt* pCxt, SShowStmt
11121112
static int32_t collectMetaKeyFromShowStreams(SCollectMetaKeyCxt* pCxt, SShowStmt* pStmt) {
11131113
int32_t code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_STREAMS,
11141114
pCxt->pMetaCache);
1115-
if (TSDB_CODE_SUCCESS == code) {
1116-
code = reserveDbVgInfoInCache(pCxt->pParseCxt->acctId, ((SValueNode*)pStmt->pDbName)->literal, pCxt->pMetaCache);
1117-
}
1118-
if (TSDB_CODE_SUCCESS == code) {
1119-
code = reserveDbCfgInCache(pCxt->pParseCxt->acctId, ((SValueNode*)pStmt->pDbName)->literal, pCxt->pMetaCache);
1120-
}
1121-
if (TSDB_CODE_SUCCESS == code) {
1122-
code =
1123-
reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, ((SValueNode*)pStmt->pDbName)->literal,
1124-
NULL, PRIV_DB_USE, PRIV_OBJ_DB, pCxt->pMetaCache);
1115+
if (TSDB_CODE_SUCCESS == code && pStmt->pDbName != NULL) {
1116+
if (TSDB_CODE_SUCCESS == code) {
1117+
code = reserveDbVgInfoInCache(pCxt->pParseCxt->acctId, ((SValueNode*)pStmt->pDbName)->literal, pCxt->pMetaCache);
1118+
}
1119+
if (TSDB_CODE_SUCCESS == code) {
1120+
code = reserveDbCfgInCache(pCxt->pParseCxt->acctId, ((SValueNode*)pStmt->pDbName)->literal, pCxt->pMetaCache);
1121+
}
1122+
if (TSDB_CODE_SUCCESS == code) {
1123+
code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser,
1124+
((SValueNode*)pStmt->pDbName)->literal, NULL, PRIV_DB_USE, PRIV_OBJ_DB,
1125+
pCxt->pMetaCache);
1126+
}
11251127
}
11261128
return code;
11271129
}

source/libs/parser/src/parTranslater.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ typedef struct SSysTableShowAdapter {
8282
const char* pDbName;
8383
const char* pTableName;
8484
int32_t numOfShowCols;
85-
const char* pShowCols[3];
85+
const char* pShowCols[4];
8686
} SSysTableShowAdapter;
8787

8888
typedef struct SCollectJoinCondsContext {
@@ -193,8 +193,8 @@ static const SSysTableShowAdapter sysTableShowAdapter[] = {
193193
.showType = QUERY_NODE_SHOW_STREAMS_STMT,
194194
.pDbName = TSDB_INFORMATION_SCHEMA_DB,
195195
.pTableName = TSDB_INS_TABLE_STREAMS,
196-
.numOfShowCols = 3,
197-
.pShowCols = {"stream_name","status","message"}
196+
.numOfShowCols = 4,
197+
.pShowCols = {"stream_name","status","message","db_name"}
198198
},
199199
{
200200
.showType = QUERY_NODE_SHOW_TABLES_STMT,
@@ -22419,6 +22419,9 @@ static const char* getTbNameColName(ENodeType type) {
2241922419
case QUERY_NODE_SHOW_STABLES_STMT:
2242022420
colName = "stable_name";
2242122421
break;
22422+
case QUERY_NODE_SHOW_STREAMS_STMT:
22423+
colName = "stream_name";
22424+
break;
2242222425
case QUERY_NODE_SHOW_INSTANCES_STMT:
2242322426
colName = "id";
2242422427
break;
@@ -22760,7 +22763,7 @@ static int32_t rewriteShow(STranslateContext* pCxt, SQuery* pQuery) {
2276022763

2276122764
static int32_t rewriteShowStreams(STranslateContext* pCxt, SQuery* pQuery) {
2276222765
SNode* pDbNode = ((SShowStmt*)pQuery->pRoot)->pDbName;
22763-
if (nodeType(pDbNode) == QUERY_NODE_VALUE) {
22766+
if (pDbNode != NULL && nodeType(pDbNode) == QUERY_NODE_VALUE) {
2276422767
SArray* pVgs = NULL;
2276522768
int32_t code = getDBVgInfo(pCxt, ((SValueNode*)pDbNode)->literal, &pVgs);
2276622769
taosArrayDestroy(pVgs);

test/cases/18-StreamProcessing/07-SubQuery/test_subquery_basic.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ def test_stream_subquery_basic(self):
2424
2525
"""
2626

27-
tdSql.error("show streams")
27+
# already supported in v3.4.2.0
28+
# tdSql.error("show streams")
2829
tdSql.error("show xx.streams")
2930
tdStream.dropAllStreamsAndDbs()
3031

test/cases/23-ShowCommands/test_show_basic.py

Lines changed: 101 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
import re
66
import os
77
import 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

1113
class 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

Comments
 (0)