Merge pull request #25764 from taosdata/fix/TD-30030-3.0

fix: error msg of show tags from ntb/view
This commit is contained in:
Hongze Cheng 2024-05-14 18:10:54 +08:00 committed by GitHub
commit c57dd5f607
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 31 additions and 9 deletions

View File

@ -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);
@ -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;
}

View File

@ -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,14 @@ 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')
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')
@ -148,9 +158,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)')