From 4abe06627cb2476244cca3c9c9b4d8c1e2ab4e18 Mon Sep 17 00:00:00 2001 From: kailixu Date: Tue, 14 May 2024 12:25:25 +0800 Subject: [PATCH 1/2] fix: error msg of show table tags from view --- source/libs/parser/src/parTranslater.c | 2 +- tests/system-test/0-others/show_tag_index.py | 22 ++++++++++++++------ 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/source/libs/parser/src/parTranslater.c b/source/libs/parser/src/parTranslater.c index 68e207e64e..b92674fc26 100644 --- a/source/libs/parser/src/parTranslater.c +++ b/source/libs/parser/src/parTranslater.c @@ -4338,7 +4338,7 @@ int32_t translateTable(STranslateContext* pCxt, SNode** pTable, SNode* pJoinPare return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_GET_META_ERROR, tstrerror(code)); } #ifdef TD_ENTERPRISE - if (TSDB_VIEW_TABLE == pRealTable->pMeta->tableType) { + if (TSDB_VIEW_TABLE == pRealTable->pMeta->tableType && !pCurrSmt->tagScan) { return translateView(pCxt, pTable, &name); } translateAudit(pCxt, pRealTable, &name); diff --git a/tests/system-test/0-others/show_tag_index.py b/tests/system-test/0-others/show_tag_index.py index 3f1b598589..1a7e6dca2c 100644 --- a/tests/system-test/0-others/show_tag_index.py +++ b/tests/system-test/0-others/show_tag_index.py @@ -78,6 +78,11 @@ class TDTestCase: tdSql.execute(f'create table stb (ts timestamp, c0 int) tags (t0 int, t1 int)') tdSql.execute(f'create table ctb1 using stb tags (1, 1)') tdSql.execute(f'create table ctb2 using stb tags (2, 2)') + tdSql.execute(f'create table ntb (ts timestamp, c0 int)') + tdSql.execute(f'create view vtb as select * from stb') + tdSql.execute(f'create view vtb1 as select * from ctb1') + tdSql.execute(f'create view vtb2 as select * from ctb2') + tdSql.execute(f'create view vtbn as select * from ntb') tdSql.execute(f'insert into ctb1 values (now, 1)') tdSql.execute(f'insert into ctb2 values (now, 2)') @@ -113,9 +118,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') + tdSql.error(f'show tags from tb_undef from db', expectErrInfo='Fail to get table info, error: Table does not exist') + tdSql.error(f'show tags from db.tb_undef', expectErrInfo='Fail to get table info, error: Table does not exist') + tdSql.error(f'show tags from tb_undef', expectErrInfo='Fail to get table info, error: Table does not exist') # show table tags tdSql.query(f'show table tags from stb') @@ -148,9 +153,14 @@ 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') + tdSql.error(f'show table tags from tb_undef from db', expectErrInfo='Fail to get table info, error: Table does not exist') + tdSql.error(f'show table tags from db.tb_undef', expectErrInfo='Fail to get table info, error: Table does not exist') + tdSql.error(f'show table tags from tb_undef', expectErrInfo='Fail to get table info, error: Table does not exist') + tdSql.error(f'show table tags from ntb', expectErrInfo='Tags can only applied to super table and child table') + tdSql.error(f'show table tags from vtb', expectErrInfo='Tags can only applied to super table and child table') + tdSql.error(f'show table tags from vtb1', expectErrInfo='Tags can only applied to super table and child table') + tdSql.error(f'show table tags from vtb2', expectErrInfo='Tags can only applied to super table and child table') + tdSql.error(f'show table tags from vtbn', expectErrInfo='Tags can only applied to super table and child table') # show indexes tdSql.execute(f'create index idx1 on stb (t1)') From ba8d44e49c41d83caae1e8769b2809647c56d591 Mon Sep 17 00:00:00 2001 From: kailixu Date: Tue, 14 May 2024 12:49:09 +0800 Subject: [PATCH 2/2] fix: error msg of show tags from ntb/view --- source/libs/parser/src/parTranslater.c | 11 +++++++++-- tests/system-test/0-others/show_tag_index.py | 5 +++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/source/libs/parser/src/parTranslater.c b/source/libs/parser/src/parTranslater.c index b92674fc26..2745f7c15b 100644 --- a/source/libs/parser/src/parTranslater.c +++ b/source/libs/parser/src/parTranslater.c @@ -11875,11 +11875,18 @@ static int32_t checkShowTags(STranslateContext* pCxt, const SShowStmt* pShow) { 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)); + code = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_GET_META_ERROR, tstrerror(code)); + goto _exit; + } + if (TSDB_SUPER_TABLE != pTableMeta->tableType && TSDB_CHILD_TABLE != pTableMeta->tableType) { + code = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_TAGS_PC, + "The _TAGS pseudo column can only be used for child table and super table queries"); + goto _exit; } +_exit: + taosMemoryFreeClear(pTableMeta); return code; } diff --git a/tests/system-test/0-others/show_tag_index.py b/tests/system-test/0-others/show_tag_index.py index 1a7e6dca2c..d84d4193c4 100644 --- a/tests/system-test/0-others/show_tag_index.py +++ b/tests/system-test/0-others/show_tag_index.py @@ -121,6 +121,11 @@ class TDTestCase: tdSql.error(f'show tags from tb_undef from db', expectErrInfo='Fail to get table info, error: Table does not exist') tdSql.error(f'show tags from db.tb_undef', expectErrInfo='Fail to get table info, error: Table does not exist') tdSql.error(f'show tags from tb_undef', expectErrInfo='Fail to get table info, error: Table does not exist') + tdSql.error(f'show tags from ntb', expectErrInfo='Tags can only applied to super table and child table') + tdSql.error(f'show tags from vtb', expectErrInfo='Tags can only applied to super table and child table') + tdSql.error(f'show tags from vtb1', expectErrInfo='Tags can only applied to super table and child table') + tdSql.error(f'show tags from vtb2', expectErrInfo='Tags can only applied to super table and child table') + tdSql.error(f'show tags from vtbn', expectErrInfo='Tags can only applied to super table and child table') # show table tags tdSql.query(f'show table tags from stb')