From 6202e1f501b444e7626115e7c86623e435737b28 Mon Sep 17 00:00:00 2001 From: slzhou Date: Fri, 29 Mar 2024 10:26:09 +0800 Subject: [PATCH] feat: drop pk column and update pk column is not supported for stable --- include/util/taoserror.h | 1 + source/libs/parser/src/parTranslater.c | 10 ++++++++-- source/libs/parser/src/parUtil.c | 4 +++- source/util/src/terror.c | 1 + 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/include/util/taoserror.h b/include/util/taoserror.h index ba66cfb06a..affa1f0345 100644 --- a/include/util/taoserror.h +++ b/include/util/taoserror.h @@ -765,6 +765,7 @@ int32_t* taosGetErrno(); #define TSDB_CODE_PAR_TAG_IS_PRIMARY_KEY TAOS_DEF_ERROR_CODE(0, 0x2671) #define TSDB_CODE_PAR_SECOND_COL_PK TAOS_DEF_ERROR_CODE(0, 0x2672) #define TSDB_CODE_PAR_COL_PK_TYPE TAOS_DEF_ERROR_CODE(0, 0x2673) +#define TSDB_CODE_PAR_INVALID_PK_OP TAOS_DEF_ERROR_CODE(0, 0x2674) #define TSDB_CODE_PAR_INTERNAL_ERROR TAOS_DEF_ERROR_CODE(0, 0x26FF) //planner diff --git a/source/libs/parser/src/parTranslater.c b/source/libs/parser/src/parTranslater.c index 3d59146d13..9fc9f28a6a 100644 --- a/source/libs/parser/src/parTranslater.c +++ b/source/libs/parser/src/parTranslater.c @@ -927,7 +927,7 @@ static bool isPrimaryKey(STempTableNode* pTable, SNode* pExpr) { return isPrimaryKeyImpl(pExpr); } -static bool hasPkInTable(STableMeta* pTableMeta) { +static bool hasPkInTable(const STableMeta* pTableMeta) { return pTableMeta->tableInfo.numOfColumns>=2 && pTableMeta->schema[1].flags & COL_IS_KEY; } @@ -6752,7 +6752,13 @@ static int32_t checkAlterSuperTableBySchema(STranslateContext* pCxt, SAlterTable : TSDB_CODE_PAR_INVALID_TAG_NAME, pStmt->colName); } - + if (hasPkInTable(pTableMeta) && (pSchema->flags & COL_IS_KEY)) { + if (TSDB_ALTER_TABLE_DROP_COLUMN == pStmt->alterType || + TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES == pStmt->alterType || + TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME == pStmt->alterType) { + return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_PK_OP, pStmt->colName); + } + } if ((TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES == pStmt->alterType || TSDB_ALTER_TABLE_UPDATE_TAG_BYTES == pStmt->alterType) && (!IS_VAR_DATA_TYPE(pSchema->type) || pSchema->type != pStmt->dataType.type || diff --git a/source/libs/parser/src/parUtil.c b/source/libs/parser/src/parUtil.c index 39f50da9fd..7c82555e63 100644 --- a/source/libs/parser/src/parUtil.c +++ b/source/libs/parser/src/parUtil.c @@ -199,7 +199,9 @@ static char* getSyntaxErrFormat(int32_t errCode) { case TSDB_CODE_PAR_SECOND_COL_PK: return "primary key column must be second column"; case TSDB_CODE_PAR_COL_PK_TYPE: - return "primary key column must be of type int, uint, bigint, ubigint, and varchar"; + return "primary key column must be of type int, uint, bigint, ubigint, and varchar"; + case TSDB_CODE_PAR_INVALID_PK_OP: + return "primary key column can not be added, modified, and dropped"; default: return "Unknown error"; } diff --git a/source/util/src/terror.c b/source/util/src/terror.c index 6df9bf0e16..a64c8642db 100644 --- a/source/util/src/terror.c +++ b/source/util/src/terror.c @@ -627,6 +627,7 @@ TAOS_DEFINE_ERROR(TSDB_CODE_PAR_NOT_SUPPORT_MULTI_RESULT, "Operator not suppor TAOS_DEFINE_ERROR(TSDB_CODE_PAR_TAG_IS_PRIMARY_KEY, "tag can not be primary key") TAOS_DEFINE_ERROR(TSDB_CODE_PAR_SECOND_COL_PK, "primary key must be second column") TAOS_DEFINE_ERROR(TSDB_CODE_PAR_COL_PK_TYPE, "primary key column must be of type int, uint, bigint, ubigint, and varchar") +TAOS_DEFINE_ERROR(TSDB_CODE_PAR_INVALID_PK_OP, "primary key column can not be added, modified, and dropped") TAOS_DEFINE_ERROR(TSDB_CODE_PAR_INTERNAL_ERROR, "Parser internal error") //planner