From ece59a7cf0ba00d2978e7b2790969a61d67d3945 Mon Sep 17 00:00:00 2001 From: 54liuyao <54liuyao> Date: Sun, 7 Apr 2024 10:18:36 +0800 Subject: [PATCH] create pk stable --- source/libs/parser/src/parTranslater.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/source/libs/parser/src/parTranslater.c b/source/libs/parser/src/parTranslater.c index 8edb7a19aa..59ce465c08 100644 --- a/source/libs/parser/src/parTranslater.c +++ b/source/libs/parser/src/parTranslater.c @@ -8534,7 +8534,7 @@ static int32_t createLastTsSelectStmt(char* pDb, char* pTable, STableMeta* pMeta return nodesListAppend((*pSelect1)->pGroupByList, (SNode*)pNode2); } -static int32_t checkStreamDestTableSchema(STranslateContext* pCxt, SCreateStreamStmt* pStmt) { +static int32_t checkAndAdjStreamDestTableSchema(STranslateContext* pCxt, SCreateStreamStmt* pStmt, SCMCreateStreamReq* pReq) { SSelectStmt* pSelect = (SSelectStmt*)pStmt->pQuery; SNode* pNode = nodesListGetNode(pStmt->pCols, 0); SColumnDefNode* pCol = (SColumnDefNode*)pNode; @@ -8560,6 +8560,9 @@ static int32_t checkStreamDestTableSchema(STranslateContext* pCxt, SCreateStream pNode = nodesListGetNode(pStmt->pCols, 1); pCol = (SColumnDefNode*)pNode; + if (STREAM_CREATE_STABLE_TRUE == pReq->createStb) { + pCol->is_pk = true; + } if (!pCol->is_pk) { return generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_STREAM_QUERY, "Source table has primary key, dest table must has primary key"); } @@ -8593,7 +8596,7 @@ static int32_t buildCreateStreamQuery(STranslateContext* pCxt, SCreateStreamStmt code = adjustTags(pCxt, pStmt, pMeta, pReq); } if (TSDB_CODE_SUCCESS == code) { - code = checkStreamDestTableSchema(pCxt, pStmt); + code = checkAndAdjStreamDestTableSchema(pCxt, pStmt, pReq); } if (TSDB_CODE_SUCCESS == code) { getSourceDatabase(pStmt->pQuery, pCxt->pParseCxt->acctId, pReq->sourceDB);