From db08d3ca9b27b9cdca35c3513e602ad576ffbb6e Mon Sep 17 00:00:00 2001 From: Xiaoyu Wang Date: Thu, 31 Mar 2022 22:38:48 -0400 Subject: [PATCH] TD-14392 bugfix --- include/common/ttokendef.h | 30 +++++++++++++------------- include/util/taoserror.h | 1 + source/libs/parser/src/parAstCreater.c | 6 +++--- source/libs/parser/src/parTranslater.c | 16 +++++++++++--- source/libs/parser/src/parUtil.c | 2 ++ 5 files changed, 34 insertions(+), 21 deletions(-) diff --git a/include/common/ttokendef.h b/include/common/ttokendef.h index 47a97071aa..07ca829bf0 100644 --- a/include/common/ttokendef.h +++ b/include/common/ttokendef.h @@ -82,21 +82,21 @@ #define TK_SINGLE_STABLE 64 #define TK_STREAM_MODE 65 #define TK_RETENTIONS 66 -#define TK_TABLE 67 -#define TK_NK_LP 68 -#define TK_NK_RP 69 -#define TK_STABLE 70 -#define TK_ADD 71 -#define TK_COLUMN 72 -#define TK_MODIFY 73 -#define TK_RENAME 74 -#define TK_TAG 75 -#define TK_SET 76 -#define TK_NK_EQ 77 -#define TK_USING 78 -#define TK_TAGS 79 -#define TK_NK_DOT 80 -#define TK_NK_COMMA 81 +#define TK_NK_COMMA 67 +#define TK_TABLE 68 +#define TK_NK_LP 69 +#define TK_NK_RP 70 +#define TK_STABLE 71 +#define TK_ADD 72 +#define TK_COLUMN 73 +#define TK_MODIFY 74 +#define TK_RENAME 75 +#define TK_TAG 76 +#define TK_SET 77 +#define TK_NK_EQ 78 +#define TK_USING 79 +#define TK_TAGS 80 +#define TK_NK_DOT 81 #define TK_COMMENT 82 #define TK_BOOL 83 #define TK_TINYINT 84 diff --git a/include/util/taoserror.h b/include/util/taoserror.h index 7c6ecd6d9a..4e2cb7944a 100644 --- a/include/util/taoserror.h +++ b/include/util/taoserror.h @@ -481,6 +481,7 @@ int32_t* taosGetErrno(); #define TSDB_CODE_PAR_INTERVAL_VALUE_TOO_SMALL TAOS_DEF_ERROR_CODE(0, 0x2615) #define TSDB_CODE_PAR_DB_NOT_SPECIFIED TAOS_DEF_ERROR_CODE(0, 0x2616) #define TSDB_CODE_PAR_INVALID_IDENTIFIER_NAME TAOS_DEF_ERROR_CODE(0, 0x2617) +#define TSDB_CODE_PAR_CORRESPONDING_STABLE_ERR TAOS_DEF_ERROR_CODE(0, 0x2618) #ifdef __cplusplus } diff --git a/source/libs/parser/src/parAstCreater.c b/source/libs/parser/src/parAstCreater.c index 50ab120c56..028238ab60 100644 --- a/source/libs/parser/src/parAstCreater.c +++ b/source/libs/parser/src/parAstCreater.c @@ -193,7 +193,7 @@ static SDatabaseOptions* setDbTtl(SAstCreateContext* pCxt, SDatabaseOptions* pOp static SDatabaseOptions* setDbWal(SAstCreateContext* pCxt, SDatabaseOptions* pOptions, const SToken* pVal) { int64_t val = strtol(pVal->z, NULL, 10); if (val < TSDB_MIN_WAL_LEVEL || val > TSDB_MAX_WAL_LEVEL) { - snprintf(pCxt->pQueryCxt->pMsg, pCxt->pQueryCxt->msgLen, "invalid db option walLevel: %d, only 1-2 allowed", val); + snprintf(pCxt->pQueryCxt->pMsg, pCxt->pQueryCxt->msgLen, "invalid db option walLevel: %"PRId64", only 1-2 allowed", val); pCxt->valid = false; return pOptions; } @@ -216,7 +216,7 @@ static SDatabaseOptions* setDbVgroups(SAstCreateContext* pCxt, SDatabaseOptions* static SDatabaseOptions* setDbSingleStable(SAstCreateContext* pCxt, SDatabaseOptions* pOptions, const SToken* pVal) { int64_t val = strtol(pVal->z, NULL, 10); if (val < TSDB_MIN_DB_SINGLE_STABLE_OPTION || val > TSDB_MAX_DB_SINGLE_STABLE_OPTION) { - snprintf(pCxt->pQueryCxt->pMsg, pCxt->pQueryCxt->msgLen, "invalid db option singleStable: %d, only 0-1 allowed", val); + snprintf(pCxt->pQueryCxt->pMsg, pCxt->pQueryCxt->msgLen, "invalid db option singleStable: %"PRId64", only 0-1 allowed", val); pCxt->valid = false; return pOptions; } @@ -227,7 +227,7 @@ static SDatabaseOptions* setDbSingleStable(SAstCreateContext* pCxt, SDatabaseOpt static SDatabaseOptions* setDbStreamMode(SAstCreateContext* pCxt, SDatabaseOptions* pOptions, const SToken* pVal) { int64_t val = strtol(pVal->z, NULL, 10); if (val < TSDB_MIN_DB_STREAM_MODE_OPTION || val > TSDB_MAX_DB_STREAM_MODE_OPTION) { - snprintf(pCxt->pQueryCxt->pMsg, pCxt->pQueryCxt->msgLen, "invalid db option streamMode: %d, only 0-1 allowed", val); + snprintf(pCxt->pQueryCxt->pMsg, pCxt->pQueryCxt->msgLen, "invalid db option streamMode: %"PRId64", only 0-1 allowed", val); pCxt->valid = false; return pOptions; } diff --git a/source/libs/parser/src/parTranslater.c b/source/libs/parser/src/parTranslater.c index 2a5fa5fdfe..a3ba53c496 100644 --- a/source/libs/parser/src/parTranslater.c +++ b/source/libs/parser/src/parTranslater.c @@ -1120,7 +1120,7 @@ static const SColumnDefNode* findColDef(const SNodeList* pCols, const SColumnNod return NULL; } -static int32_t checkCreateTable(STranslateContext* pCxt, SCreateTableStmt* pStmt) { +static int32_t checkCreateSuperTable(STranslateContext* pCxt, SCreateTableStmt* pStmt) { if (NULL != pStmt->pOptions->pSma) { SNode* pNode = NULL; FOREACH(pNode, pStmt->pOptions->pSma) { @@ -1149,7 +1149,7 @@ static int32_t getAggregationMethod(SNodeList* pFuncs) { } static int32_t translateCreateSuperTable(STranslateContext* pCxt, SCreateTableStmt* pStmt) { - int32_t code = checkCreateTable(pCxt, pStmt); + int32_t code = checkCreateSuperTable(pCxt, pStmt); if (TSDB_CODE_SUCCESS != code) { return code; } @@ -2448,9 +2448,19 @@ static int32_t buildKVRowForAllTags(STranslateContext* pCxt, SCreateSubTableClau return TSDB_CODE_SUCCESS; } +static int32_t checkCreateSubTable(STranslateContext* pCxt, SCreateSubTableClause* pStmt) { + if (0 != strcmp(pStmt->dbName, pStmt->useDbName)) { + return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_CORRESPONDING_STABLE_ERR);; + } + return TSDB_CODE_SUCCESS; +} static int32_t rewriteCreateSubTable(STranslateContext* pCxt, SCreateSubTableClause* pStmt, SHashObj* pVgroupHashmap) { + int32_t code = checkCreateSubTable(pCxt, pStmt); + STableMeta* pSuperTableMeta = NULL; - int32_t code = getTableMeta(pCxt, pStmt->useDbName, pStmt->useTableName, &pSuperTableMeta); + if (TSDB_CODE_SUCCESS == code) { + code = getTableMeta(pCxt, pStmt->useDbName, pStmt->useTableName, &pSuperTableMeta); + } SKVRowBuilder kvRowBuilder = {0}; if (TSDB_CODE_SUCCESS == code) { diff --git a/source/libs/parser/src/parUtil.c b/source/libs/parser/src/parUtil.c index 0b999322ce..aeed7719f3 100644 --- a/source/libs/parser/src/parUtil.c +++ b/source/libs/parser/src/parUtil.c @@ -65,6 +65,8 @@ static char* getSyntaxErrFormat(int32_t errCode) { return "db not specified"; case TSDB_CODE_PAR_INVALID_IDENTIFIER_NAME: return "Invalid identifier name : %s"; + case TSDB_CODE_PAR_CORRESPONDING_STABLE_ERR: + return "corresponding super table not in this db"; case TSDB_CODE_OUT_OF_MEMORY: return "Out of memory"; default: