From 8ab24c71d012cc5547ba1098b3a350f3d4f94b5a Mon Sep 17 00:00:00 2001 From: kailixu Date: Mon, 13 May 2024 17:14:29 +0800 Subject: [PATCH] fix: show tags from undefined table --- source/libs/parser/src/parAstParser.c | 4 +++ source/libs/parser/src/parTranslater.c | 28 +++++++++++++++++++- tests/system-test/0-others/show_tag_index.py | 6 +++++ 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/source/libs/parser/src/parAstParser.c b/source/libs/parser/src/parAstParser.c index 3da6ac668c..ef9252e337 100644 --- a/source/libs/parser/src/parAstParser.c +++ b/source/libs/parser/src/parAstParser.c @@ -534,6 +534,10 @@ static int32_t collectMetaKeyFromShowTables(SCollectMetaKeyCxt* pCxt, SShowStmt* static int32_t collectMetaKeyFromShowTags(SCollectMetaKeyCxt* pCxt, SShowStmt* pStmt) { int32_t code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_TAGS, pCxt->pMetaCache); + if (TSDB_CODE_SUCCESS == code) { + code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, ((SValueNode*)pStmt->pDbName)->literal, + ((SValueNode*)pStmt->pTbName)->literal, pCxt->pMetaCache); + } if (TSDB_CODE_SUCCESS == code) { code = reserveDbVgInfoInCache(pCxt->pParseCxt->acctId, ((SValueNode*)pStmt->pDbName)->literal, pCxt->pMetaCache); } diff --git a/source/libs/parser/src/parTranslater.c b/source/libs/parser/src/parTranslater.c index b26f837423..68e207e64e 100644 --- a/source/libs/parser/src/parTranslater.c +++ b/source/libs/parser/src/parTranslater.c @@ -11867,6 +11867,30 @@ static int32_t rewriteShowVgroups(STranslateContext* pCxt, SQuery* pQuery) { return code; } +static int32_t checkShowTags(STranslateContext* pCxt, const SShowStmt* pShow) { + int32_t code = 0; + SName name; + STableMeta* pTableMeta = NULL; + code = getTargetMeta(pCxt, + toName(pCxt->pParseCxt->acctId, ((SValueNode*)pShow->pDbName)->literal, + ((SValueNode*)pShow->pTbName)->literal, &name), + &pTableMeta, true); + taosMemoryFreeClear(pTableMeta); + if (TSDB_CODE_SUCCESS != code) { + return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_GET_META_ERROR, tstrerror(code)); + } + + return code; +} + +static int32_t rewriteShowTags(STranslateContext* pCxt, SQuery* pQuery) { + int32_t code = checkShowTags(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) { @@ -13170,7 +13194,6 @@ static int32_t rewriteQuery(STranslateContext* pCxt, SQuery* pQuery) { case QUERY_NODE_SHOW_APPS_STMT: case QUERY_NODE_SHOW_CONSUMERS_STMT: case QUERY_NODE_SHOW_SUBSCRIPTIONS_STMT: - case QUERY_NODE_SHOW_TAGS_STMT: case QUERY_NODE_SHOW_USER_PRIVILEGES_STMT: case QUERY_NODE_SHOW_VIEWS_STMT: case QUERY_NODE_SHOW_GRANTS_FULL_STMT: @@ -13181,6 +13204,9 @@ static int32_t rewriteQuery(STranslateContext* pCxt, SQuery* pQuery) { case QUERY_NODE_SHOW_TSMAS_STMT: code = rewriteShow(pCxt, pQuery); break; + case QUERY_NODE_SHOW_TAGS_STMT: + code = rewriteShowTags(pCxt, pQuery); + break; case QUERY_NODE_SHOW_VGROUPS_STMT: code = rewriteShowVgroups(pCxt, pQuery); break; diff --git a/tests/system-test/0-others/show_tag_index.py b/tests/system-test/0-others/show_tag_index.py index c79880ba35..3f1b598589 100644 --- a/tests/system-test/0-others/show_tag_index.py +++ b/tests/system-test/0-others/show_tag_index.py @@ -113,6 +113,9 @@ class TDTestCase: tdSql.error(f'show tags from `db`.`stb` from db') tdSql.error(f'show tags from db.ctb1 from db') tdSql.error(f'show tags from `db`.`ctb1` from db') + tdSql.error(f'show tags from tb_undef from db') + tdSql.error(f'show tags from db.tb_undef') + tdSql.error(f'show tags from tb_undef') # show table tags tdSql.query(f'show table tags from stb') @@ -145,6 +148,9 @@ class TDTestCase: tdSql.error(f'show table tags from `db`.`stb` from db') tdSql.error(f'show table tags from db.ctb1 from db') tdSql.error(f'show table tags from `db`.`ctb1` from db') + tdSql.error(f'show table tags from tb_undef from db') + tdSql.error(f'show table tags from db.tb_undef') + tdSql.error(f'show table tags from tb_undef') # show indexes tdSql.execute(f'create index idx1 on stb (t1)')