From 6ffa3945eacce3764a275fce3b9eb272295507fa Mon Sep 17 00:00:00 2001 From: dapan1121 Date: Mon, 29 Apr 2024 09:18:26 +0800 Subject: [PATCH 1/3] fix: create stream udf issue --- source/libs/parser/src/parAstParser.c | 7 +++++++ source/libs/parser/src/parTranslater.c | 5 +---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/source/libs/parser/src/parAstParser.c b/source/libs/parser/src/parAstParser.c index a1f09088da..3da6ac668c 100644 --- a/source/libs/parser/src/parAstParser.c +++ b/source/libs/parser/src/parAstParser.c @@ -405,6 +405,13 @@ static int32_t collectMetaKeyFromDescribe(SCollectMetaKeyCxt* pCxt, SDescribeStm static int32_t collectMetaKeyFromCreateStream(SCollectMetaKeyCxt* pCxt, SCreateStreamStmt* pStmt) { int32_t code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, pStmt->targetDbName, pStmt->targetTabName, pCxt->pMetaCache); + if (TSDB_CODE_SUCCESS == code && NULL != pStmt->pSubtable && NULL != pStmt->pQuery) { + SSelectStmt* pSelect = (SSelectStmt*)pStmt->pQuery; + pSelect->pSubtable = nodesCloneNode(pStmt->pSubtable); + if (NULL == pSelect->pSubtable) { + return TSDB_CODE_OUT_OF_MEMORY; + } + } if (TSDB_CODE_SUCCESS == code) { code = collectMetaKeyFromQuery(pCxt, pStmt->pQuery); } diff --git a/source/libs/parser/src/parTranslater.c b/source/libs/parser/src/parTranslater.c index 8f77f0dedf..8740f7c883 100644 --- a/source/libs/parser/src/parTranslater.c +++ b/source/libs/parser/src/parTranslater.c @@ -9327,10 +9327,7 @@ static int32_t addSubtableNameToCreateStreamQuery(STranslateContext* pCxt, SCrea if (NULL == pStmt->pSubtable) { return TSDB_CODE_SUCCESS; } - pSelect->pSubtable = nodesCloneNode(pStmt->pSubtable); - if (NULL == pSelect->pSubtable) { - return TSDB_CODE_OUT_OF_MEMORY; - } + SRewriteSubtableCxt cxt = {.pCxt = pCxt, .pPartitionList = pSelect->pPartitionByList}; nodesRewriteExpr(&pSelect->pSubtable, rewriteSubtable, &cxt); return pCxt->errCode; From 0ef476a09efa7cac4d9ccb31c80d0b62829fabaa Mon Sep 17 00:00:00 2001 From: dapan1121 Date: Tue, 30 Apr 2024 09:42:53 +0800 Subject: [PATCH 2/3] fix: ut issue --- source/libs/parser/src/parTranslater.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/source/libs/parser/src/parTranslater.c b/source/libs/parser/src/parTranslater.c index 8740f7c883..06bf0081c3 100644 --- a/source/libs/parser/src/parTranslater.c +++ b/source/libs/parser/src/parTranslater.c @@ -1054,9 +1054,9 @@ static bool isPrimaryKey(STempTableNode* pTable, SNode* pExpr) { static bool hasPkInTable(const STableMeta* pTableMeta) { bool hasPK = pTableMeta->tableInfo.numOfColumns >= 2 && pTableMeta->schema[1].flags & COL_IS_KEY; if (hasPK) { - uInfo("has primary key, %s", pTableMeta->schema[1].name); + uDebug("has primary key, %s", pTableMeta->schema[1].name); } else { - uInfo("no primary key, %s", pTableMeta->schema[1].name); + uDebug("no primary key, %s", pTableMeta->schema[1].name); } return hasPK; } @@ -9327,6 +9327,10 @@ static int32_t addSubtableNameToCreateStreamQuery(STranslateContext* pCxt, SCrea if (NULL == pStmt->pSubtable) { return TSDB_CODE_SUCCESS; } + pSelect->pSubtable = nodesCloneNode(pStmt->pSubtable); + if (NULL == pSelect->pSubtable) { + return TSDB_CODE_OUT_OF_MEMORY; + } SRewriteSubtableCxt cxt = {.pCxt = pCxt, .pPartitionList = pSelect->pPartitionByList}; nodesRewriteExpr(&pSelect->pSubtable, rewriteSubtable, &cxt); From 2bd83169bbda3d5a6fa85e32fe5cdb37d322d130 Mon Sep 17 00:00:00 2001 From: dapan1121 Date: Tue, 30 Apr 2024 13:22:10 +0800 Subject: [PATCH 3/3] fix: memory leak issue --- source/libs/parser/src/parTranslater.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/source/libs/parser/src/parTranslater.c b/source/libs/parser/src/parTranslater.c index 06bf0081c3..124bfbc9d8 100644 --- a/source/libs/parser/src/parTranslater.c +++ b/source/libs/parser/src/parTranslater.c @@ -9327,9 +9327,11 @@ static int32_t addSubtableNameToCreateStreamQuery(STranslateContext* pCxt, SCrea if (NULL == pStmt->pSubtable) { return TSDB_CODE_SUCCESS; } - pSelect->pSubtable = nodesCloneNode(pStmt->pSubtable); if (NULL == pSelect->pSubtable) { - return TSDB_CODE_OUT_OF_MEMORY; + pSelect->pSubtable = nodesCloneNode(pStmt->pSubtable); + if (NULL == pSelect->pSubtable) { + return TSDB_CODE_OUT_OF_MEMORY; + } } SRewriteSubtableCxt cxt = {.pCxt = pCxt, .pPartitionList = pSelect->pPartitionByList};