Merge pull request #29934 from taosdata/enh/TS-5650/showLike

enh: show variables like
This commit is contained in:
Simon Guan 2025-03-07 16:37:19 +08:00 committed by GitHub
commit 8fa8fc2a0c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
18 changed files with 234 additions and 52 deletions

View File

@ -127,10 +127,11 @@ Displays created indexes.
## SHOW LOCAL VARIABLES ## SHOW LOCAL VARIABLES
```sql ```sql
SHOW LOCAL VARIABLES; SHOW LOCAL VARIABLES [like pattern];
``` ```
Displays the runtime values of configuration parameters for the current client. Displays the runtime values of configuration parameters for the current client.
You can use the like pattern to filter by name.
## SHOW MNODES ## SHOW MNODES
@ -320,11 +321,11 @@ Displays information about all users in the current system, including user-defin
## SHOW CLUSTER VARIABLES (before version 3.0.1.6 it was SHOW VARIABLES) ## SHOW CLUSTER VARIABLES (before version 3.0.1.6 it was SHOW VARIABLES)
```sql ```sql
SHOW CLUSTER VARIABLES; SHOW CLUSTER VARIABLES [like pattern];
SHOW DNODE dnode_id VARIABLES; SHOW DNODE dnode_id VARIABLES [like pattern];
``` ```
Displays the runtime values of configuration parameters that need to be the same across nodes in the current system, or you can specify a DNODE to view its configuration parameters. Displays the runtime values of configuration parameters that need to be the same across nodes in the current system, or you can specify a DNODE to view its configuration parameters. And you can use the like pattern to filter by name.
## SHOW VGROUPS ## SHOW VGROUPS

View File

@ -134,10 +134,10 @@ SHOW INDEXES FROM [db_name.]tbl_name;
## SHOW LOCAL VARIABLES ## SHOW LOCAL VARIABLES
```sql ```sql
SHOW LOCAL VARIABLES; SHOW LOCAL VARIABLES [like pattern];
``` ```
显示当前客户端配置参数的运行值。 显示当前客户端配置参数的运行值,可使用 like pattern 根据 name 进行过滤
## SHOW MNODES ## SHOW MNODES
@ -329,11 +329,12 @@ SHOW USERS;
## SHOW CLUSTER VARIABLES(3.0.1.6 之前为 SHOW VARIABLES) ## SHOW CLUSTER VARIABLES(3.0.1.6 之前为 SHOW VARIABLES)
```sql ```sql
SHOW CLUSTER VARIABLES; SHOW CLUSTER VARIABLES [like pattern];;
SHOW DNODE dnode_id VARIABLES; SHOW DNODE dnode_id VARIABLES [like pattern];;
``` ```
显示当前系统中各节点需要相同的配置参数的运行值,也可以指定 DNODE 来查看其的配置参数。 显示当前系统中各节点需要相同的配置参数的运行值,也可以指定 DNODE 来查看其的配置参数。
可使用 like pattern 根据 name 进行过滤。
## SHOW VGROUPS ## SHOW VGROUPS

View File

@ -414,7 +414,7 @@ typedef struct STUidTagInfo {
#define NOTIFY_EVENT_STR_COLUMN_INDEX 0 #define NOTIFY_EVENT_STR_COLUMN_INDEX 0
int32_t taosGenCrashJsonMsg(int signum, char** pMsg, int64_t clusterId, int64_t startTime); int32_t taosGenCrashJsonMsg(int signum, char** pMsg, int64_t clusterId, int64_t startTime);
int32_t dumpConfToDataBlock(SSDataBlock* pBlock, int32_t startCol); int32_t dumpConfToDataBlock(SSDataBlock* pBlock, int32_t startCol, char* likePattern);
#define TSMA_RES_STB_POSTFIX "_tsma_res_stb_" #define TSMA_RES_STB_POSTFIX "_tsma_res_stb_"
#define MD5_OUTPUT_LEN 32 #define MD5_OUTPUT_LEN 32

View File

@ -2255,11 +2255,14 @@ typedef struct {
} STagData; } STagData;
typedef struct { typedef struct {
int32_t useless; // useless int32_t opType;
uint32_t valLen;
char* val;
} SShowVariablesReq; } SShowVariablesReq;
int32_t tSerializeSShowVariablesReq(void* buf, int32_t bufLen, SShowVariablesReq* pReq); int32_t tSerializeSShowVariablesReq(void* buf, int32_t bufLen, SShowVariablesReq* pReq);
// int32_t tDeserializeSShowVariablesReq(void* buf, int32_t bufLen, SShowVariablesReq* pReq); int32_t tDeserializeSShowVariablesReq(void* buf, int32_t bufLen, SShowVariablesReq* pReq);
void tFreeSShowVariablesReq(SShowVariablesReq* pReq);
typedef struct { typedef struct {
char name[TSDB_CONFIG_OPTION_LEN + 1]; char name[TSDB_CONFIG_OPTION_LEN + 1];

View File

@ -47,6 +47,7 @@ typedef struct SPatternCompareInfo {
int32_t InitRegexCache(); int32_t InitRegexCache();
void DestroyRegexCache(); void DestroyRegexCache();
int32_t rawStrPatternMatch(const char *pattern, const char *str);
int32_t patternMatch(const char *pattern, size_t psize, const char *str, size_t ssize, const SPatternCompareInfo *pInfo); int32_t patternMatch(const char *pattern, size_t psize, const char *str, size_t ssize, const SPatternCompareInfo *pInfo);
int32_t checkRegexPattern(const char *pPattern); int32_t checkRegexPattern(const char *pPattern);
void DestoryThreadLocalRegComp(); void DestoryThreadLocalRegComp();

View File

@ -630,26 +630,30 @@ static int32_t buildShowVariablesRsp(SArray* pVars, SRetrieveTableRsp** pRsp) {
(*pRsp)->numOfRows = htobe64((int64_t)pBlock->info.rows); (*pRsp)->numOfRows = htobe64((int64_t)pBlock->info.rows);
(*pRsp)->numOfCols = htonl(SHOW_VARIABLES_RESULT_COLS); (*pRsp)->numOfCols = htonl(SHOW_VARIABLES_RESULT_COLS);
int32_t len = blockEncode(pBlock, (*pRsp)->data + PAYLOAD_PREFIX_LEN, dataEncodeBufSize, SHOW_VARIABLES_RESULT_COLS); int32_t len = 0;
if (len < 0) { if ((*pRsp)->numOfRows > 0) {
uError("buildShowVariablesRsp error, len:%d", len); len = blockEncode(pBlock, (*pRsp)->data + PAYLOAD_PREFIX_LEN, dataEncodeBufSize, SHOW_VARIABLES_RESULT_COLS);
code = terrno; if (len < 0) {
goto _exit; uError("buildShowVariablesRsp error, len:%d", len);
code = terrno;
goto _exit;
}
SET_PAYLOAD_LEN((*pRsp)->data, len, len);
int32_t payloadLen = len + PAYLOAD_PREFIX_LEN;
(*pRsp)->payloadLen = htonl(payloadLen);
(*pRsp)->compLen = htonl(payloadLen);
if (payloadLen != rspSize - sizeof(SRetrieveTableRsp)) {
uError("buildShowVariablesRsp error, len:%d != rspSize - sizeof(SRetrieveTableRsp):%" PRIu64, len,
(uint64_t)(rspSize - sizeof(SRetrieveTableRsp)));
code = TSDB_CODE_TSC_INVALID_INPUT;
goto _exit;
}
} }
blockDataDestroy(pBlock); blockDataDestroy(pBlock);
pBlock = NULL;
SET_PAYLOAD_LEN((*pRsp)->data, len, len);
int32_t payloadLen = len + PAYLOAD_PREFIX_LEN;
(*pRsp)->payloadLen = htonl(payloadLen);
(*pRsp)->compLen = htonl(payloadLen);
if (payloadLen != rspSize - sizeof(SRetrieveTableRsp)) {
uError("buildShowVariablesRsp error, len:%d != rspSize - sizeof(SRetrieveTableRsp):%" PRIu64, len,
(uint64_t)(rspSize - sizeof(SRetrieveTableRsp)));
code = TSDB_CODE_TSC_INVALID_INPUT;
goto _exit;
}
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
_exit: _exit:

View File

@ -5837,7 +5837,11 @@ int32_t tSerializeSShowVariablesReq(void *buf, int32_t bufLen, SShowVariablesReq
tEncoderInit(&encoder, buf, bufLen); tEncoderInit(&encoder, buf, bufLen);
TAOS_CHECK_EXIT(tStartEncode(&encoder)); TAOS_CHECK_EXIT(tStartEncode(&encoder));
TAOS_CHECK_EXIT(tEncodeI32(&encoder, pReq->useless)); TAOS_CHECK_EXIT(tEncodeI32(&encoder, pReq->opType));
TAOS_CHECK_EXIT(tEncodeI32(&encoder, pReq->valLen));
if (pReq->valLen > 0) {
TAOS_CHECK_EXIT(tEncodeBinary(&encoder, (const uint8_t *)pReq->val, pReq->valLen));
}
tEndEncode(&encoder); tEndEncode(&encoder);
_exit: _exit:
@ -5850,6 +5854,37 @@ _exit:
return tlen; return tlen;
} }
int32_t tDeserializeSShowVariablesReq(void *buf, int32_t bufLen, SShowVariablesReq *pReq) {
SDecoder decoder = {0};
int32_t code = 0;
int32_t lino;
tDecoderInit(&decoder, buf, bufLen);
TAOS_CHECK_EXIT(tStartDecode(&decoder));
TAOS_CHECK_EXIT(tDecodeI32(&decoder, &pReq->opType));
TAOS_CHECK_EXIT(tDecodeU32(&decoder, &pReq->valLen));
if (pReq->valLen > 0) {
pReq->val = taosMemoryCalloc(1, pReq->valLen + 1);
if (pReq->val == NULL) {
TAOS_CHECK_EXIT(terrno);
}
TAOS_CHECK_EXIT(tDecodeCStrTo(&decoder, pReq->val));
}
tEndDecode(&decoder);
_exit:
tDecoderClear(&decoder);
return code;
}
void tFreeSShowVariablesReq(SShowVariablesReq *pReq) {
if (NULL != pReq && NULL != pReq->val) {
taosMemoryFree(pReq->val);
pReq->val = NULL;
}
}
int32_t tEncodeSVariablesInfo(SEncoder *pEncoder, SVariablesInfo *pInfo) { int32_t tEncodeSVariablesInfo(SEncoder *pEncoder, SVariablesInfo *pInfo) {
TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pInfo->name)); TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pInfo->name));
TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pInfo->value)); TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pInfo->value));

View File

@ -18,6 +18,7 @@
#include "tglobal.h" #include "tglobal.h"
#include "tjson.h" #include "tjson.h"
#include "tmisce.h" #include "tmisce.h"
#include "tcompare.h"
int32_t taosGetFqdnPortFromEp(const char* ep, SEp* pEp) { int32_t taosGetFqdnPortFromEp(const char* ep, SEp* pEp) {
pEp->port = 0; pEp->port = 0;
@ -257,7 +258,7 @@ _exit:
TAOS_RETURN(code); TAOS_RETURN(code);
} }
int32_t dumpConfToDataBlock(SSDataBlock* pBlock, int32_t startCol) { int32_t dumpConfToDataBlock(SSDataBlock* pBlock, int32_t startCol, char* likePattern) {
int32_t code = 0; int32_t code = 0;
SConfig* pConf = taosGetCfg(); SConfig* pConf = taosGetCfg();
if (pConf == NULL) { if (pConf == NULL) {
@ -291,6 +292,9 @@ int32_t dumpConfToDataBlock(SSDataBlock* pBlock, int32_t startCol) {
// GRANT_CFG_SKIP; // GRANT_CFG_SKIP;
char name[TSDB_CONFIG_OPTION_LEN + VARSTR_HEADER_SIZE] = {0}; char name[TSDB_CONFIG_OPTION_LEN + VARSTR_HEADER_SIZE] = {0};
if (likePattern && rawStrPatternMatch(pItem->name, likePattern) != TSDB_PATTERN_MATCH) {
continue;
}
STR_WITH_MAXSIZE_TO_VARSTR(name, pItem->name, TSDB_CONFIG_OPTION_LEN + VARSTR_HEADER_SIZE); STR_WITH_MAXSIZE_TO_VARSTR(name, pItem->name, TSDB_CONFIG_OPTION_LEN + VARSTR_HEADER_SIZE);
SColumnInfoData* pColInfo = taosArrayGet(pBlock->pDataBlock, col++); SColumnInfoData* pColInfo = taosArrayGet(pBlock->pDataBlock, col++);

View File

@ -690,7 +690,7 @@ _exit:
} }
int32_t dmAppendVariablesToBlock(SSDataBlock *pBlock, int32_t dnodeId) { int32_t dmAppendVariablesToBlock(SSDataBlock *pBlock, int32_t dnodeId) {
int32_t code = dumpConfToDataBlock(pBlock, 1); int32_t code = dumpConfToDataBlock(pBlock, 1, NULL);
if (code != 0) { if (code != 0) {
return code; return code;
} }

View File

@ -23,6 +23,7 @@
#include "mndTrans.h" #include "mndTrans.h"
#include "mndUser.h" #include "mndUser.h"
#include "tutil.h" #include "tutil.h"
#include "tcompare.h"
#define CFG_VER_NUMBER 1 #define CFG_VER_NUMBER 1
#define CFG_RESERVE_SIZE 63 #define CFG_RESERVE_SIZE 63
@ -809,7 +810,7 @@ static void cfgObjArrayCleanUp(SArray *array) {
taosArrayDestroy(array); taosArrayDestroy(array);
} }
SArray *initVariablesFromItems(SArray *pItems) { static SArray *initVariablesFromItems(SArray *pItems, const char* likePattern) {
if (pItems == NULL) { if (pItems == NULL) {
return NULL; return NULL;
} }
@ -825,6 +826,9 @@ SArray *initVariablesFromItems(SArray *pItems) {
SConfigItem *pItem = taosArrayGet(pItems, i); SConfigItem *pItem = taosArrayGet(pItems, i);
SVariablesInfo info = {0}; SVariablesInfo info = {0};
tstrncpy(info.name, pItem->name, sizeof(info.name)); tstrncpy(info.name, pItem->name, sizeof(info.name));
if (likePattern != NULL && rawStrPatternMatch(pItem->name, likePattern) != TSDB_PATTERN_MATCH) {
continue;
}
// init info value // init info value
switch (pItem->dtype) { switch (pItem->dtype) {
@ -891,15 +895,23 @@ SArray *initVariablesFromItems(SArray *pItems) {
static int32_t mndProcessShowVariablesReq(SRpcMsg *pReq) { static int32_t mndProcessShowVariablesReq(SRpcMsg *pReq) {
SShowVariablesRsp rsp = {0}; SShowVariablesRsp rsp = {0};
int32_t code = -1; int32_t code = TSDB_CODE_SUCCESS;
SShowVariablesReq req = {0};
SArray *array = NULL;
code = tDeserializeSShowVariablesReq(pReq->pCont, pReq->contLen, &req);
if (code != 0) {
mError("failed to deserialize config req, since %s", terrstr());
goto _OVER;
}
if ((code = mndCheckOperPrivilege(pReq->info.node, pReq->info.conn.user, MND_OPER_SHOW_VARIABLES)) != 0) { if ((code = mndCheckOperPrivilege(pReq->info.node, pReq->info.conn.user, MND_OPER_SHOW_VARIABLES)) != 0) {
goto _OVER; goto _OVER;
} }
SVariablesInfo info = {0}; SVariablesInfo info = {0};
char *likePattern = req.opType == OP_TYPE_LIKE ? req.val : NULL;
rsp.variables = initVariablesFromItems(taosGetGlobalCfg(tsCfg)); rsp.variables = initVariablesFromItems(taosGetGlobalCfg(tsCfg), likePattern);
if (rsp.variables == NULL) { if (rsp.variables == NULL) {
code = terrno; code = terrno;
goto _OVER; goto _OVER;
@ -926,7 +938,7 @@ _OVER:
if (code != 0) { if (code != 0) {
mError("failed to get show variables info since %s", tstrerror(code)); mError("failed to get show variables info since %s", tstrerror(code));
} }
tFreeSShowVariablesReq(&req);
tFreeSShowVariablesRsp(&rsp); tFreeSShowVariablesRsp(&rsp);
TAOS_RETURN(code); TAOS_RETURN(code);
} }

View File

@ -20,6 +20,7 @@
#include "systable.h" #include "systable.h"
#include "taosdef.h" #include "taosdef.h"
#include "tdatablock.h" #include "tdatablock.h"
#include "tdataformat.h"
#include "tglobal.h" #include "tglobal.h"
#include "tgrant.h" #include "tgrant.h"
@ -53,13 +54,16 @@ static int32_t buildRetrieveTableRsp(SSDataBlock* pBlock, int32_t numOfCols, SRe
(*pRsp)->numOfRows = htobe64((int64_t)pBlock->info.rows); (*pRsp)->numOfRows = htobe64((int64_t)pBlock->info.rows);
(*pRsp)->numOfCols = htonl(numOfCols); (*pRsp)->numOfCols = htonl(numOfCols);
int32_t len = blockEncode(pBlock, (*pRsp)->data + PAYLOAD_PREFIX_LEN, dataEncodeBufSize, numOfCols); int32_t len = 0;
if (len < 0) { if (pBlock->info.rows > 0) {
taosMemoryFree(*pRsp); len = blockEncode(pBlock, (*pRsp)->data + PAYLOAD_PREFIX_LEN, dataEncodeBufSize, numOfCols);
*pRsp = NULL; if (len < 0) {
return terrno; taosMemoryFree(*pRsp);
*pRsp = NULL;
return terrno;
}
SET_PAYLOAD_LEN((*pRsp)->data, len, len);
} }
SET_PAYLOAD_LEN((*pRsp)->data, len, len);
int32_t payloadLen = len + PAYLOAD_PREFIX_LEN; int32_t payloadLen = len + PAYLOAD_PREFIX_LEN;
(*pRsp)->payloadLen = htonl(payloadLen); (*pRsp)->payloadLen = htonl(payloadLen);
@ -985,11 +989,17 @@ _exit:
return terrno; return terrno;
} }
static int32_t execShowLocalVariables(SRetrieveTableRsp** pRsp) { static int32_t execShowLocalVariables(SShowStmt* pStmt, SRetrieveTableRsp** pRsp) {
SSDataBlock* pBlock = NULL; SSDataBlock* pBlock = NULL;
char* likePattern = NULL;
int32_t code = buildLocalVariablesResultDataBlock(&pBlock); int32_t code = buildLocalVariablesResultDataBlock(&pBlock);
if (TSDB_CODE_SUCCESS == code) { if (TSDB_CODE_SUCCESS == code) {
code = dumpConfToDataBlock(pBlock, 0); if (pStmt->tableCondType == OP_TYPE_LIKE) {
likePattern = ((SValueNode*)pStmt->pTbName)->literal;
}
}
if (TSDB_CODE_SUCCESS == code) {
code = dumpConfToDataBlock(pBlock, 0, likePattern);
} }
if (TSDB_CODE_SUCCESS == code) { if (TSDB_CODE_SUCCESS == code) {
code = buildRetrieveTableRsp(pBlock, SHOW_LOCAL_VARIABLES_RESULT_COLS, pRsp); code = buildRetrieveTableRsp(pBlock, SHOW_LOCAL_VARIABLES_RESULT_COLS, pRsp);
@ -1091,7 +1101,7 @@ int32_t qExecCommand(int64_t* pConnId, bool sysInfoUser, SNode* pStmt, SRetrieve
case QUERY_NODE_ALTER_LOCAL_STMT: case QUERY_NODE_ALTER_LOCAL_STMT:
return execAlterLocal((SAlterLocalStmt*)pStmt); return execAlterLocal((SAlterLocalStmt*)pStmt);
case QUERY_NODE_SHOW_LOCAL_VARIABLES_STMT: case QUERY_NODE_SHOW_LOCAL_VARIABLES_STMT:
return execShowLocalVariables(pRsp); return execShowLocalVariables((SShowStmt*)pStmt, pRsp);
case QUERY_NODE_SELECT_STMT: case QUERY_NODE_SELECT_STMT:
return execSelectWithoutFrom((SSelectStmt*)pStmt, pRsp); return execSelectWithoutFrom((SSelectStmt*)pStmt, pRsp);
default: default:

View File

@ -241,6 +241,7 @@ SNode* createUseDatabaseStmt(SAstCreateContext* pCxt, SToken* pDbName);
SNode* setShowKind(SAstCreateContext* pCxt, SNode* pStmt, EShowKind showKind); SNode* setShowKind(SAstCreateContext* pCxt, SNode* pStmt, EShowKind showKind);
SNode* createShowStmt(SAstCreateContext* pCxt, ENodeType type); SNode* createShowStmt(SAstCreateContext* pCxt, ENodeType type);
SNode* createShowStmtWithFull(SAstCreateContext* pCxt, ENodeType type); SNode* createShowStmtWithFull(SAstCreateContext* pCxt, ENodeType type);
SNode* createShowStmtWithLike(SAstCreateContext* pCxt, ENodeType type, SNode* pLikePattern);
SNode* createShowStmtWithCond(SAstCreateContext* pCxt, ENodeType type, SNode* pDbName, SNode* pTbName, SNode* createShowStmtWithCond(SAstCreateContext* pCxt, ENodeType type, SNode* pDbName, SNode* pTbName,
EOperatorType tableCondType); EOperatorType tableCondType);
SNode* createShowTablesStmt(SAstCreateContext* pCxt, SShowTablesOption option, SNode* pTbName, SNode* createShowTablesStmt(SAstCreateContext* pCxt, SShowTablesOption option, SNode* pTbName,

View File

@ -602,9 +602,9 @@ cmd ::= SHOW ENCRYPTIONS.
cmd ::= SHOW QUERIES. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_QUERIES_STMT); } cmd ::= SHOW QUERIES. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_QUERIES_STMT); }
cmd ::= SHOW SCORES. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_SCORES_STMT); } cmd ::= SHOW SCORES. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_SCORES_STMT); }
cmd ::= SHOW TOPICS. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_TOPICS_STMT); } cmd ::= SHOW TOPICS. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_TOPICS_STMT); }
cmd ::= SHOW VARIABLES. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_VARIABLES_STMT); } cmd ::= SHOW VARIABLES like_pattern_opt(B). { pCxt->pRootNode = createShowStmtWithLike(pCxt, QUERY_NODE_SHOW_VARIABLES_STMT, B); }
cmd ::= SHOW CLUSTER VARIABLES. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_VARIABLES_STMT); } cmd ::= SHOW CLUSTER VARIABLES like_pattern_opt(B). { pCxt->pRootNode = createShowStmtWithLike(pCxt, QUERY_NODE_SHOW_VARIABLES_STMT, B); }
cmd ::= SHOW LOCAL VARIABLES. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_LOCAL_VARIABLES_STMT); } cmd ::= SHOW LOCAL VARIABLES like_pattern_opt(B). { pCxt->pRootNode = createShowStmtWithLike(pCxt, QUERY_NODE_SHOW_LOCAL_VARIABLES_STMT, B); }
cmd ::= SHOW DNODE NK_INTEGER(A) VARIABLES like_pattern_opt(B). { pCxt->pRootNode = createShowDnodeVariablesStmt(pCxt, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &A), B); } cmd ::= SHOW DNODE NK_INTEGER(A) VARIABLES like_pattern_opt(B). { pCxt->pRootNode = createShowDnodeVariablesStmt(pCxt, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &A), B); }
cmd ::= SHOW BNODES. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_BNODES_STMT); } cmd ::= SHOW BNODES. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_BNODES_STMT); }
cmd ::= SHOW SNODES. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_SNODES_STMT); } cmd ::= SHOW SNODES. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_SNODES_STMT); }

View File

@ -2804,6 +2804,22 @@ static bool needDbShowStmt(ENodeType type) {
QUERY_NODE_SHOW_VIEWS_STMT == type || QUERY_NODE_SHOW_TSMAS_STMT == type || QUERY_NODE_SHOW_USAGE_STMT == type; QUERY_NODE_SHOW_VIEWS_STMT == type || QUERY_NODE_SHOW_TSMAS_STMT == type || QUERY_NODE_SHOW_USAGE_STMT == type;
} }
SNode* createShowStmtWithLike(SAstCreateContext* pCxt, ENodeType type, SNode* pLikePattern) {
CHECK_PARSER_STATUS(pCxt);
SShowStmt* pStmt = NULL;
pCxt->errCode = nodesMakeNode(type, (SNode**)&pStmt);
CHECK_MAKE_NODE(pStmt);
pStmt->withFull = false;
pStmt->pTbName = pLikePattern;
if (pLikePattern) {
pStmt->tableCondType = OP_TYPE_LIKE;
}
return (SNode*)pStmt;
_err:
nodesDestroyNode(pLikePattern);
return NULL;
}
SNode* createShowStmt(SAstCreateContext* pCxt, ENodeType type) { SNode* createShowStmt(SAstCreateContext* pCxt, ENodeType type) {
CHECK_PARSER_STATUS(pCxt); CHECK_PARSER_STATUS(pCxt);
SShowStmt* pStmt = NULL; SShowStmt* pStmt = NULL;

View File

@ -13325,7 +13325,16 @@ static int32_t translateSplitVgroup(STranslateContext* pCxt, SSplitVgroupStmt* p
static int32_t translateShowVariables(STranslateContext* pCxt, SShowStmt* pStmt) { static int32_t translateShowVariables(STranslateContext* pCxt, SShowStmt* pStmt) {
SShowVariablesReq req = {0}; SShowVariablesReq req = {0};
return buildCmdMsg(pCxt, TDMT_MND_SHOW_VARIABLES, (FSerializeFunc)tSerializeSShowVariablesReq, &req); req.opType = pStmt->tableCondType;
if (req.opType == OP_TYPE_LIKE && pStmt->pTbName) {
req.valLen = strlen(((SValueNode*)pStmt->pTbName)->literal);
if (req.valLen > 0) {
req.val = taosStrdupi(((SValueNode*)pStmt->pTbName)->literal);
}
}
int32_t code = buildCmdMsg(pCxt, TDMT_MND_SHOW_VARIABLES, (FSerializeFunc)tSerializeSShowVariablesReq, &req);
tFreeSShowVariablesReq(&req);
return code;
} }
static int32_t translateShowCreateDatabase(STranslateContext* pCxt, SShowCreateDatabaseStmt* pStmt) { static int32_t translateShowCreateDatabase(STranslateContext* pCxt, SShowCreateDatabaseStmt* pStmt) {

View File

@ -1123,6 +1123,19 @@ int32_t patternMatch(const char *pattern, size_t psize, const char *str, size_t
return (j >= ssize || str[j] == 0) ? TSDB_PATTERN_MATCH : TSDB_PATTERN_NOMATCH; return (j >= ssize || str[j] == 0) ? TSDB_PATTERN_MATCH : TSDB_PATTERN_NOMATCH;
} }
int32_t rawStrPatternMatch(const char *str, const char *pattern) {
SPatternCompareInfo pInfo = PATTERN_COMPARE_INFO_INITIALIZER;
size_t pLen = strlen(pattern);
size_t sz = strlen(str);
if (pLen > TSDB_MAX_FIELD_LEN) {
return 1;
}
int32_t ret = patternMatch(pattern, pLen, str, sz, &pInfo);
return (ret == TSDB_PATTERN_MATCH) ? 0 : 1;
}
int32_t wcsPatternMatch(const TdUcs4 *pattern, size_t psize, const TdUcs4 *str, size_t ssize, int32_t wcsPatternMatch(const TdUcs4 *pattern, size_t psize, const TdUcs4 *str, size_t ssize,
const SPatternCompareInfo *pInfo) { const SPatternCompareInfo *pInfo) {
TdUcs4 c, c1; TdUcs4 c, c1;

View File

@ -704,6 +704,17 @@ class TDSql:
tdLog.info("sql:%s, elm:%s == expect_elm:%s" % (self.sql, elm, expect_elm)) tdLog.info("sql:%s, elm:%s == expect_elm:%s" % (self.sql, elm, expect_elm))
return True return True
self.print_error_frame_info(elm, expect_elm) self.print_error_frame_info(elm, expect_elm)
def checkGreater(self, elm, expect_elm):
if elm > expect_elm:
tdLog.info("sql:%s, elm:%s > expect_elm:%s" % (self.sql, elm, expect_elm))
return True
else:
caller = inspect.getframeinfo(inspect.stack()[1][0])
args = (caller.filename, caller.lineno, self.sql, elm, expect_elm)
tdLog.info("%s(%d) failed: sql:%s, elm:%s <= expect_elm:%s" % args)
self.print_error_frame_info(elm, expect_elm)
return False
def checkNotEqual(self, elm, expect_elm): def checkNotEqual(self, elm, expect_elm):
if elm != expect_elm: if elm != expect_elm:

View File

@ -46,8 +46,9 @@ class TDTestCase:
tdSql.checkRows(2) tdSql.checkRows(2)
def case2(self): def case2(self):
tdSql.query("show variables")
tdSql.checkRows(88) tdSql.query("show variables")
tdSql.checkGreater(tdSql.getRows(), 80)
for i in range(self.replicaVar): for i in range(self.replicaVar):
tdSql.query("show dnode %d variables like 'debugFlag'" % (i + 1)) tdSql.query("show dnode %d variables like 'debugFlag'" % (i + 1))
@ -85,7 +86,59 @@ class TDTestCase:
tdSql.checkData(0, 0, 1) tdSql.checkData(0, 0, 1)
tdSql.checkData(0, 1, 's3UploadDelaySec') tdSql.checkData(0, 1, 's3UploadDelaySec')
tdSql.checkData(0, 2, 60) tdSql.checkData(0, 2, 60)
def show_local_variables_like(self):
tdSql.query("show local variables")
tdSql.checkGreater(tdSql.getRows(), 80)
tdSql.query("show local variables like 'debugFlag'")
tdSql.checkRows(1)
tdSql.checkData(0, 0, 'debugFlag')
tdSql.checkData(0, 1, 0)
tdSql.query("show local variables like '%debugFlag'")
tdSql.checkRows(9)
tdSql.query("show local variables like '____debugFlag'")
tdSql.checkRows(0)
tdSql.query("show local variables like 's3MigrateEnab%'")
tdSql.checkRows(0)
tdSql.query("show local variables like 'mini%'")
tdSql.checkRows(3)
tdSql.checkData(0, 0, 'minimalTmpDirGB')
tdSql.query("show local variables like '%info'")
tdSql.checkRows(2)
def show_cluster_variables_like(self):
zones = ["", "cluster"]
for zone in zones:
tdLog.info(f"show {zone} variables")
tdSql.query(f"show {zone} variables")
tdSql.checkGreater(tdSql.getRows(), 80)
tdLog.info(f"show {zone} variables like 'debugFlag'")
#tdSql.query(f"show {zone} variables like 'debugFlag'")
#tdSql.checkRows(0)
tdSql.query(f"show {zone} variables like 's3%'")
tdSql.checkRows(6)
tdSql.query(f"show {zone} variables like 'Max%'")
tdSql.checkRows(3)
tdSql.query(f"show {zone} variables like 'ttl%'")
tdSql.checkRows(5)
tdSql.query(f"show {zone} variables like 'ttl34343434%'")
tdSql.checkRows(0)
tdSql.query(f"show {zone} variables like 'jdlkfdjdfkdfnldlfdnfkdkfdmfdlfmnnnnnjkjk'")
tdSql.checkRows(0)
def threadTest(self, threadID): def threadTest(self, threadID):
print(f"Thread {threadID} starting...") print(f"Thread {threadID} starting...")
tdsqln = tdCom.newTdSql() tdsqln = tdCom.newTdSql()
@ -127,6 +180,14 @@ class TDTestCase:
tdLog.printNoPrefix("==========start case3 run ...............") tdLog.printNoPrefix("==========start case3 run ...............")
self.case3() self.case3()
tdLog.printNoPrefix("==========end case3 run ...............") tdLog.printNoPrefix("==========end case3 run ...............")
tdLog.printNoPrefix("==========start show_local_variables_like run ...............")
self.show_local_variables_like()
tdLog.printNoPrefix("==========end show_local_variables_like run ...............")
tdLog.printNoPrefix("==========start show_cluster_variables_like run ...............")
self.show_cluster_variables_like()
tdLog.printNoPrefix("==========end show_cluster_variables_like run ...............")
def stop(self): def stop(self):
tdSql.close() tdSql.close()