From 2339b8c0a62144ca2fa9183b6e566d07ed11618c Mon Sep 17 00:00:00 2001 From: Xiaoyu Wang Date: Thu, 20 Oct 2022 16:53:26 +0800 Subject: [PATCH] some parser problem --- source/libs/parser/src/parAstParser.c | 9 +++++++-- source/libs/parser/src/parTranslater.c | 18 +++++++++++++++++- tools/shell/src/shellEngine.c | 16 +++++----------- 3 files changed, 29 insertions(+), 14 deletions(-) diff --git a/source/libs/parser/src/parAstParser.c b/source/libs/parser/src/parAstParser.c index 64aa017a68..95db6b93c9 100644 --- a/source/libs/parser/src/parAstParser.c +++ b/source/libs/parser/src/parAstParser.c @@ -455,8 +455,13 @@ static int32_t collectMetaKeyFromShowLicence(SCollectMetaKeyCxt* pCxt, SShowStmt } static int32_t collectMetaKeyFromShowVgroups(SCollectMetaKeyCxt* pCxt, SShowStmt* pStmt) { - return reserveTableMetaInCache(pCxt->pParseCxt->acctId, TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_VGROUPS, - pCxt->pMetaCache); + int32_t code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_VGROUPS, + pCxt->pMetaCache); + if (TSDB_CODE_SUCCESS == code) { + // just to verify whether the database exists + code = reserveDbCfgInCache(pCxt->pParseCxt->acctId, ((SValueNode*)pStmt->pDbName)->literal, pCxt->pMetaCache); + } + return code; } static int32_t collectMetaKeyFromShowTopics(SCollectMetaKeyCxt* pCxt, SShowStmt* pStmt) { diff --git a/source/libs/parser/src/parTranslater.c b/source/libs/parser/src/parTranslater.c index 5a05440c73..24f1bba5a3 100644 --- a/source/libs/parser/src/parTranslater.c +++ b/source/libs/parser/src/parTranslater.c @@ -6212,6 +6212,20 @@ static int32_t rewriteShow(STranslateContext* pCxt, SQuery* pQuery) { return code; } +static int32_t checkShowVgroups(STranslateContext* pCxt, SShowStmt* pShow) { + // just to verify whether the database exists + SDbCfgInfo dbCfg = {0}; + return getDBCfg(pCxt, ((SValueNode*)pShow->pDbName)->literal, &dbCfg); +} + +static int32_t rewriteShowVgroups(STranslateContext* pCxt, SQuery* pQuery) { + int32_t code = checkShowVgroups(pCxt, (SShowStmt*)pQuery->pRoot); + if (TSDB_CODE_SUCCESS == code) { + code = rewriteShow(pCxt, pQuery); + } + return code; +} + static SNode* createTagsFunction() { SFunctionNode* pFunc = (SFunctionNode*)nodesMakeNode(QUERY_NODE_FUNCTION); if (NULL == pFunc) { @@ -7358,7 +7372,6 @@ static int32_t rewriteQuery(STranslateContext* pCxt, SQuery* pQuery) { case QUERY_NODE_SHOW_STABLES_STMT: case QUERY_NODE_SHOW_USERS_STMT: case QUERY_NODE_SHOW_DNODES_STMT: - case QUERY_NODE_SHOW_VGROUPS_STMT: case QUERY_NODE_SHOW_MNODES_STMT: case QUERY_NODE_SHOW_MODULES_STMT: case QUERY_NODE_SHOW_QNODES_STMT: @@ -7378,6 +7391,9 @@ static int32_t rewriteQuery(STranslateContext* pCxt, SQuery* pQuery) { case QUERY_NODE_SHOW_TAGS_STMT: code = rewriteShow(pCxt, pQuery); break; + case QUERY_NODE_SHOW_VGROUPS_STMT: + code = rewriteShowVgroups(pCxt, pQuery); + break; case QUERY_NODE_SHOW_TABLE_TAGS_STMT: code = rewriteShowStableTags(pCxt, pQuery); break; diff --git a/tools/shell/src/shellEngine.c b/tools/shell/src/shellEngine.c index 37d00c0a7c..e216d597a3 100644 --- a/tools/shell/src/shellEngine.c +++ b/tools/shell/src/shellEngine.c @@ -285,6 +285,10 @@ void shellDumpFieldToFile(TdFilePtr pFile, const char *val, TAOS_FIELD *field, i return; } + char quotationStr[2]; + quotationStr[0] = '\"'; + quotationStr[1] = 0; + int n; char buf[TSDB_MAX_BYTES_PER_ROW]; switch (field->type) { @@ -330,33 +334,23 @@ void shellDumpFieldToFile(TdFilePtr pFile, const char *val, TAOS_FIELD *field, i case TSDB_DATA_TYPE_NCHAR: case TSDB_DATA_TYPE_JSON: { - char quotationStr[2]; int32_t bufIndex = 0; - quotationStr[0] = 0; - quotationStr[1] = 0; for (int32_t i = 0; i < length; i++) { buf[bufIndex] = val[i]; bufIndex++; if (val[i] == '\"') { buf[bufIndex] = val[i]; bufIndex++; - quotationStr[0] = '\"'; - } - if (val[i] == ',') { - quotationStr[0] = '\"'; } } buf[bufIndex] = 0; - if (length == 0) { - quotationStr[0] = '\"'; - } taosFprintfFile(pFile, "%s%s%s", quotationStr, buf, quotationStr); } break; case TSDB_DATA_TYPE_TIMESTAMP: shellFormatTimestamp(buf, *(int64_t *)val, precision); - taosFprintfFile(pFile, "%s", buf); + taosFprintfFile(pFile, "%s%s%s", quotationStr, buf, quotationStr); break; default: break; -- GitLab