From e91dd72c0ee0c6320486d40d2c72c50bf7eae941 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Sat, 8 May 2021 03:33:24 +0800 Subject: [PATCH] [TD-4096] support 'show create stable xx' --- src/client/src/tscLocal.c | 6 +++++- src/client/src/tscSQLParser.c | 1 + src/client/src/tscServer.c | 1 + src/client/src/tscSql.c | 1 + src/common/inc/tcmdtype.h | 1 + src/query/inc/sql.y | 4 ++++ 6 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/client/src/tscLocal.c b/src/client/src/tscLocal.c index a7882ffa61..6b55780af9 100644 --- a/src/client/src/tscLocal.c +++ b/src/client/src/tscLocal.c @@ -326,6 +326,7 @@ TAOS_ROW tscFetchRow(void *param) { pCmd->command == TSDB_SQL_FETCH || pCmd->command == TSDB_SQL_SHOW || pCmd->command == TSDB_SQL_SHOW_CREATE_TABLE || + pCmd->command == TSDB_SQL_SHOW_CREATE_STABLE || pCmd->command == TSDB_SQL_SHOW_CREATE_DATABASE || pCmd->command == TSDB_SQL_SELECT || pCmd->command == TSDB_SQL_DESCRIBE_TABLE || @@ -679,6 +680,9 @@ static int32_t tscProcessShowCreateTable(SSqlObj *pSql) { assert(pTableMetaInfo->pTableMeta != NULL); const char* tableName = tNameGetTableName(&pTableMetaInfo->name); + if (pSql->cmd.command == TSDB_SQL_SHOW_CREATE_STABLE && !UTIL_TABLE_IS_SUPER_TABLE(pTableMetaInfo)) { + return TSDB_CODE_TSC_INVALID_VALUE; + } char *result = (char *)calloc(1, TSDB_MAX_BINARY_LEN); int32_t code = TSDB_CODE_SUCCESS; @@ -907,7 +911,7 @@ int tscProcessLocalCmd(SSqlObj *pSql) { */ pRes->qId = 0x1; pRes->numOfRows = 0; - } else if (pCmd->command == TSDB_SQL_SHOW_CREATE_TABLE) { + } else if (pCmd->command == TSDB_SQL_SHOW_CREATE_TABLE || pCmd->command == TSDB_SQL_SHOW_CREATE_STABLE) { pRes->code = tscProcessShowCreateTable(pSql); } else if (pCmd->command == TSDB_SQL_SHOW_CREATE_DATABASE) { pRes->code = tscProcessShowCreateDatabase(pSql); diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index 87b4669a04..931189e603 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -446,6 +446,7 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) { return tscGetTableMeta(pSql, pTableMetaInfo); } + case TSDB_SQL_SHOW_CREATE_STABLE: case TSDB_SQL_SHOW_CREATE_TABLE: { const char* msg1 = "invalid table name"; const char* msg2 = "table name is too long"; diff --git a/src/client/src/tscServer.c b/src/client/src/tscServer.c index 9528a553b2..d2bf458e58 100644 --- a/src/client/src/tscServer.c +++ b/src/client/src/tscServer.c @@ -2641,6 +2641,7 @@ void tscInitMsgsFp() { tscProcessMsgRsp[TSDB_SQL_ALTER_DB] = tscProcessAlterDbMsgRsp; tscProcessMsgRsp[TSDB_SQL_SHOW_CREATE_TABLE] = tscProcessShowCreateRsp; + tscProcessMsgRsp[TSDB_SQL_SHOW_CREATE_STABLE] = tscProcessShowCreateRsp; tscProcessMsgRsp[TSDB_SQL_SHOW_CREATE_DATABASE] = tscProcessShowCreateRsp; tscKeepConn[TSDB_SQL_SHOW] = 1; diff --git a/src/client/src/tscSql.c b/src/client/src/tscSql.c index 8dbb1c0a52..364af4e8b1 100644 --- a/src/client/src/tscSql.c +++ b/src/client/src/tscSql.c @@ -457,6 +457,7 @@ static bool needToFetchNewBlock(SSqlObj* pSql) { pCmd->command == TSDB_SQL_FETCH || pCmd->command == TSDB_SQL_SHOW || pCmd->command == TSDB_SQL_SHOW_CREATE_TABLE || + pCmd->command == TSDB_SQL_SHOW_CREATE_STABLE || pCmd->command == TSDB_SQL_SHOW_CREATE_DATABASE || pCmd->command == TSDB_SQL_SELECT || pCmd->command == TSDB_SQL_DESCRIBE_TABLE || diff --git a/src/common/inc/tcmdtype.h b/src/common/inc/tcmdtype.h index be16e80124..adf210cfeb 100644 --- a/src/common/inc/tcmdtype.h +++ b/src/common/inc/tcmdtype.h @@ -80,6 +80,7 @@ enum { TSDB_DEFINE_SQL_TYPE( TSDB_SQL_TABLE_JOIN_RETRIEVE, "join-retrieve" ) TSDB_DEFINE_SQL_TYPE( TSDB_SQL_SHOW_CREATE_TABLE, "show-create-table") + TSDB_DEFINE_SQL_TYPE( TSDB_SQL_SHOW_CREATE_STABLE, "show-create-stable") TSDB_DEFINE_SQL_TYPE( TSDB_SQL_SHOW_CREATE_DATABASE, "show-create-database") /* diff --git a/src/query/inc/sql.y b/src/query/inc/sql.y index fd922240c2..8ef8ef0e2b 100644 --- a/src/query/inc/sql.y +++ b/src/query/inc/sql.y @@ -94,6 +94,10 @@ cmd ::= SHOW CREATE TABLE ids(X) cpxName(Y). { X.n += Y.n; setDCLSqlElems(pInfo, TSDB_SQL_SHOW_CREATE_TABLE, 1, &X); } +cmd ::= SHOW CREATE STABLE ids(X) cpxName(Y). { + X.n += Y.n; + setDCLSqlElems(pInfo, TSDB_SQL_SHOW_CREATE_STABLE, 1, &X); +} cmd ::= SHOW CREATE DATABASE ids(X). { setDCLSqlElems(pInfo, TSDB_SQL_SHOW_CREATE_DATABASE, 1, &X); -- GitLab