From 69e402d547998953aef833f7d86d14b01f83719e Mon Sep 17 00:00:00 2001 From: Yihao Deng Date: Fri, 31 May 2024 10:36:30 +0000 Subject: [PATCH] add error --- source/libs/parser/src/parAstCreater.c | 18 ++++++++++++++---- source/libs/parser/src/parTranslater.c | 6 ++++-- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/source/libs/parser/src/parAstCreater.c b/source/libs/parser/src/parAstCreater.c index 13c74ca881..00ce03cf6a 100644 --- a/source/libs/parser/src/parAstCreater.c +++ b/source/libs/parser/src/parAstCreater.c @@ -1901,20 +1901,30 @@ SNode* createAlterTableAddModifyColOptions2(SAstCreateContext* pCxt, SNode* pRea if (!checkColumnName(pCxt, pColName)) { return NULL; } + SAlterTableStmt* pStmt = (SAlterTableStmt*)nodesMakeNode(QUERY_NODE_ALTER_TABLE_STMT); CHECK_OUT_OF_MEM(pStmt); pStmt->alterType = alterType; COPY_STRING_FORM_ID_TOKEN(pStmt->colName, pColName); pStmt->dataType = dataType; + pStmt->pColOptions = (SColumnOptions*)pOptions; - // if pOptions is NULL, it means that the column has no options if (pOptions != NULL) { SColumnOptions* pOption = (SColumnOptions*)pOptions; - if (strlen(pOption->compress) != 0 || strlen(pOption->compressLevel) || strlen(pOption->encode) != 0) { - pStmt->alterType = TSDB_ALTER_TABLE_ADD_COLUMN_WITH_COMPRESS_OPTION; + if (pOption->bPrimaryKey == false || pOption->commentNull == true) { + if (strlen(pOption->compress) != 0 || strlen(pOption->compressLevel) || strlen(pOption->encode) != 0) { + pStmt->alterType = TSDB_ALTER_TABLE_ADD_COLUMN_WITH_COMPRESS_OPTION; + } else { + pCxt->errCode = generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_SYNTAX_ERROR, + "not support alter column with option except compress"); + return NULL; + } + } else { + pCxt->errCode = generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_SYNTAX_ERROR, + "not support alter column with option except compress"); + return NULL; } } - pStmt->pColOptions = (SColumnOptions*)pOptions; return createAlterTableStmtFinalize(pRealTable, pStmt); } diff --git a/source/libs/parser/src/parTranslater.c b/source/libs/parser/src/parTranslater.c index 1c38e1bc31..b6673d6219 100644 --- a/source/libs/parser/src/parTranslater.c +++ b/source/libs/parser/src/parTranslater.c @@ -12899,8 +12899,10 @@ static int32_t buildAddColReq(STranslateContext* pCxt, SAlterTableStmt* pStmt, S pReq->bytes = calcTypeBytes(pStmt->dataType); if (pStmt->pColOptions != NULL) { if (!checkColumnEncodeOrSetDefault(pReq->type, pStmt->pColOptions->encode)) return TSDB_CODE_TSC_ENCODE_PARAM_ERROR; - if (!checkColumnCompressOrSetDefault(pReq->type, pStmt->pColOptions->compress)) return TSDB_CODE_TSC_COMPRESS_PARAM_ERROR; - if (!checkColumnLevelOrSetDefault(pReq->type, pStmt->pColOptions->compressLevel)) return TSDB_CODE_TSC_COMPRESS_LEVEL_ERROR; + if (!checkColumnCompressOrSetDefault(pReq->type, pStmt->pColOptions->compress)) + return TSDB_CODE_TSC_COMPRESS_PARAM_ERROR; + if (!checkColumnLevelOrSetDefault(pReq->type, pStmt->pColOptions->compressLevel)) + return TSDB_CODE_TSC_COMPRESS_LEVEL_ERROR; int8_t code = setColCompressByOption(pReq->type, columnEncodeVal(pStmt->pColOptions->encode), columnCompressVal(pStmt->pColOptions->compress), columnLevelVal(pStmt->pColOptions->compressLevel), true, &pReq->compress);