From d6dc966ed12ff5cc697d0b46c2d2fe77f6a7a4ed Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Wed, 22 Jan 2025 15:12:43 +0800 Subject: [PATCH] fix(analysis): fix compiler error on windows. --- cmake/cmake.options | 11 +-- source/common/CMakeLists.txt | 8 +- source/common/src/tanalytics.c | 78 ++++++++++--------- source/dnode/mnode/impl/CMakeLists.txt | 6 +- source/dnode/mnode/impl/src/mndAnode.c | 26 ++++++- .../libs/executor/src/anomalywindowoperator.c | 12 +++ source/libs/executor/src/forecastoperator.c | 74 ++++++++++-------- 7 files changed, 128 insertions(+), 87 deletions(-) diff --git a/cmake/cmake.options b/cmake/cmake.options index 4c69544466..3e655b1796 100644 --- a/cmake/cmake.options +++ b/cmake/cmake.options @@ -166,7 +166,9 @@ IF(${BUILD_WITH_ANALYSIS}) set(BUILD_WITH_S3 ON) ENDIF() -set(BUILD_WITH_ANALYSIS ON) +IF(${TD_LINUX}) + set(BUILD_WITH_ANALYSIS ON) +ENDIF() IF(${BUILD_S3}) @@ -207,13 +209,6 @@ option( off ) - -option( - BUILD_WITH_NURAFT - "If build with NuRaft" - OFF -) - option( BUILD_WITH_UV "If build with libuv" diff --git a/source/common/CMakeLists.txt b/source/common/CMakeLists.txt index 047e8be193..33a6099daf 100644 --- a/source/common/CMakeLists.txt +++ b/source/common/CMakeLists.txt @@ -49,11 +49,11 @@ if(${TD_WINDOWS}) ) target_link_libraries( - common + common - PUBLIC os - PUBLIC util - INTERFACE api + PUBLIC os + PUBLIC util + INTERFACE api ) else() diff --git a/source/common/src/tanalytics.c b/source/common/src/tanalytics.c index aa9dd842ac..c78e979b99 100644 --- a/source/common/src/tanalytics.c +++ b/source/common/src/tanalytics.c @@ -16,8 +16,8 @@ #define _DEFAULT_SOURCE #include "tanalytics.h" #include "ttypes.h" -#include "tutil.h" +#ifdef USE_ANALYTICS #include #define ANALYTICS_ALOG_SPLIT_CHAR "," @@ -215,20 +215,20 @@ static size_t taosCurlWriteData(char *pCont, size_t contLen, size_t nmemb, void return 0; } - int64_t newDataSize = (int64_t) contLen * nmemb; + int64_t newDataSize = (int64_t)contLen * nmemb; int64_t size = pRsp->dataLen + newDataSize; if (pRsp->data == NULL) { pRsp->data = taosMemoryMalloc(size + 1); if (pRsp->data == NULL) { - uError("failed to prepare recv buffer for post rsp, len:%d, code:%s", (int32_t) size + 1, tstrerror(terrno)); - return 0; // return the recv length, if failed, return 0 + uError("failed to prepare recv buffer for post rsp, len:%d, code:%s", (int32_t)size + 1, tstrerror(terrno)); + return 0; // return the recv length, if failed, return 0 } } else { - char* p = taosMemoryRealloc(pRsp->data, size + 1); + char *p = taosMemoryRealloc(pRsp->data, size + 1); if (p == NULL) { - uError("failed to prepare recv buffer for post rsp, len:%d, code:%s", (int32_t) size + 1, tstrerror(terrno)); - return 0; // return the recv length, if failed, return 0 + uError("failed to prepare recv buffer for post rsp, len:%d, code:%s", (int32_t)size + 1, tstrerror(terrno)); + return 0; // return the recv length, if failed, return 0 } pRsp->data = p; @@ -472,7 +472,7 @@ static int32_t taosAnalJsonBufWriteColMeta(SAnalyticBuf *pBuf, int32_t colIndex, } int32_t bufLen = tsnprintf(buf, sizeof(buf), " [\"%s\", \"%s\", %d]%s\n", colName, tDataTypes[colType].name, - tDataTypes[colType].bytes, last ? "" : ","); + tDataTypes[colType].bytes, last ? "" : ","); if (taosWriteFile(pBuf->filePtr, buf, bufLen) != bufLen) { return terrno; } @@ -762,33 +762,35 @@ static int32_t taosAnalBufGetCont(SAnalyticBuf *pBuf, char **ppCont, int64_t *pC } } -//#else -// -//int32_t taosAnalyticsInit() { return 0; } -//void taosAnalyticsCleanup() {} -//SJson *taosAnalSendReqRetJson(const char *url, EAnalHttpType type, SAnalyticBuf *pBuf) { return NULL; } -// -//int32_t taosAnalGetAlgoUrl(const char *algoName, EAnalAlgoType type, char *url, int32_t urlLen) { return 0; } -//bool taosAnalGetOptStr(const char *option, const char *optName, char *optValue, int32_t optMaxLen) { return true; } -//bool taosAnalGetOptInt(const char *option, const char *optName, int64_t *optValue) { return true; } -//int64_t taosAnalGetVersion() { return 0; } -//void taosAnalUpdate(int64_t newVer, SHashObj *pHash) {} -// -//int32_t tsosAnalBufOpen(SAnalyticBuf *pBuf, int32_t numOfCols) { return 0; } -//int32_t taosAnalBufWriteOptStr(SAnalyticBuf *pBuf, const char *optName, const char *optVal) { return 0; } -//int32_t taosAnalBufWriteOptInt(SAnalyticBuf *pBuf, const char *optName, int64_t optVal) { return 0; } -//int32_t taosAnalBufWriteOptFloat(SAnalyticBuf *pBuf, const char *optName, float optVal) { return 0; } -//int32_t taosAnalBufWriteColMeta(SAnalyticBuf *pBuf, int32_t colIndex, int32_t colType, const char *colName) { return 0; } -//int32_t taosAnalBufWriteDataBegin(SAnalyticBuf *pBuf) { return 0; } -//int32_t taosAnalBufWriteColBegin(SAnalyticBuf *pBuf, int32_t colIndex) { return 0; } -//int32_t taosAnalBufWriteColData(SAnalyticBuf *pBuf, int32_t colIndex, int32_t colType, void *colValue) { return 0; } -//int32_t taosAnalBufWriteColEnd(SAnalyticBuf *pBuf, int32_t colIndex) { return 0; } -//int32_t taosAnalBufWriteDataEnd(SAnalyticBuf *pBuf) { return 0; } -//int32_t taosAnalBufClose(SAnalyticBuf *pBuf) { return 0; } -//void taosAnalBufDestroy(SAnalyticBuf *pBuf) {} -// -//const char *taosAnalAlgoStr(EAnalAlgoType algoType) { return 0; } -//EAnalAlgoType taosAnalAlgoInt(const char *algoName) { return 0; } -//const char *taosAnalAlgoUrlStr(EAnalAlgoType algoType) { return 0; } -// -//#endif \ No newline at end of file +#else + +int32_t taosAnalyticsInit() { return 0; } +void taosAnalyticsCleanup() {} +SJson *taosAnalSendReqRetJson(const char *url, EAnalHttpType type, SAnalyticBuf *pBuf) { return NULL; } + +int32_t taosAnalGetAlgoUrl(const char *algoName, EAnalAlgoType type, char *url, int32_t urlLen) { return 0; } +bool taosAnalGetOptStr(const char *option, const char *optName, char *optValue, int32_t optMaxLen) { return true; } +bool taosAnalGetOptInt(const char *option, const char *optName, int64_t *optValue) { return true; } +int64_t taosAnalGetVersion() { return 0; } +void taosAnalUpdate(int64_t newVer, SHashObj *pHash) {} + +int32_t tsosAnalBufOpen(SAnalyticBuf *pBuf, int32_t numOfCols) { return 0; } +int32_t taosAnalBufWriteOptStr(SAnalyticBuf *pBuf, const char *optName, const char *optVal) { return 0; } +int32_t taosAnalBufWriteOptInt(SAnalyticBuf *pBuf, const char *optName, int64_t optVal) { return 0; } +int32_t taosAnalBufWriteOptFloat(SAnalyticBuf *pBuf, const char *optName, float optVal) { return 0; } +int32_t taosAnalBufWriteColMeta(SAnalyticBuf *pBuf, int32_t colIndex, int32_t colType, const char *colName) { + return 0; +} +int32_t taosAnalBufWriteDataBegin(SAnalyticBuf *pBuf) { return 0; } +int32_t taosAnalBufWriteColBegin(SAnalyticBuf *pBuf, int32_t colIndex) { return 0; } +int32_t taosAnalBufWriteColData(SAnalyticBuf *pBuf, int32_t colIndex, int32_t colType, void *colValue) { return 0; } +int32_t taosAnalBufWriteColEnd(SAnalyticBuf *pBuf, int32_t colIndex) { return 0; } +int32_t taosAnalBufWriteDataEnd(SAnalyticBuf *pBuf) { return 0; } +int32_t taosAnalBufClose(SAnalyticBuf *pBuf) { return 0; } +void taosAnalBufDestroy(SAnalyticBuf *pBuf) {} + +const char *taosAnalAlgoStr(EAnalAlgoType algoType) { return 0; } +EAnalAlgoType taosAnalAlgoInt(const char *algoName) { return 0; } +const char *taosAnalAlgoUrlStr(EAnalAlgoType algoType) { return 0; } + +#endif \ No newline at end of file diff --git a/source/dnode/mnode/impl/CMakeLists.txt b/source/dnode/mnode/impl/CMakeLists.txt index ad36d8c8ae..e4e184eee0 100644 --- a/source/dnode/mnode/impl/CMakeLists.txt +++ b/source/dnode/mnode/impl/CMakeLists.txt @@ -16,10 +16,10 @@ if(TD_ENTERPRISE) ELSEIF(${BUILD_WITH_COS}) add_definitions(-DUSE_COS) endif() +endif() - if(${BUILD_WITH_ANALYSIS}) - add_definitions(-DUSE_ANALYTICS) - endif() +if(${BUILD_WITH_ANALYSIS}) + add_definitions(-DUSE_ANALYTICS) endif() add_library(mnode STATIC ${MNODE_SRC}) diff --git a/source/dnode/mnode/impl/src/mndAnode.c b/source/dnode/mnode/impl/src/mndAnode.c index de3f7a607c..c64208600a 100644 --- a/source/dnode/mnode/impl/src/mndAnode.c +++ b/source/dnode/mnode/impl/src/mndAnode.c @@ -24,6 +24,8 @@ #include "tanalytics.h" #include "tjson.h" +#ifdef USE_ANALYTICS + #define TSDB_ANODE_VER_NUMBER 1 #define TSDB_ANODE_RESERVE_SIZE 64 @@ -877,4 +879,26 @@ static int32_t mndProcessAnalAlgoReq(SRpcMsg *pReq) { _OVER: tFreeRetrieveAnalAlgoRsp(&rsp); TAOS_RETURN(code); -} \ No newline at end of file +} + +#else + +static int32_t mndProcessUnsupportReq(SRpcMsg *pReq) { return TSDB_CODE_OPS_NOT_SUPPORT; } +static int32_t mndRetrieveUnsupport(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows) { + return TSDB_CODE_OPS_NOT_SUPPORT; +} + +int32_t mndInitAnode(SMnode *pMnode) { + mndSetMsgHandle(pMnode, TDMT_MND_CREATE_ANODE, mndProcessUnsupportReq); + mndSetMsgHandle(pMnode, TDMT_MND_UPDATE_ANODE, mndProcessUnsupportReq); + mndSetMsgHandle(pMnode, TDMT_MND_DROP_ANODE, mndProcessUnsupportReq); + mndSetMsgHandle(pMnode, TDMT_MND_RETRIEVE_ANAL_ALGO, mndProcessUnsupportReq); + + mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_ANODE, mndRetrieveUnsupport); + mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_ANODE_FULL, mndRetrieveUnsupport); + return 0; +} + +void mndCleanupAnode(SMnode *pMnode) {} + +#endif \ No newline at end of file diff --git a/source/libs/executor/src/anomalywindowoperator.c b/source/libs/executor/src/anomalywindowoperator.c index 8e539d52d9..3124fa0b57 100644 --- a/source/libs/executor/src/anomalywindowoperator.c +++ b/source/libs/executor/src/anomalywindowoperator.c @@ -26,6 +26,8 @@ #include "tjson.h" #include "ttime.h" +#ifdef USE_ANALYTICS + typedef struct { SArray* blocks; // SSDataBlock* SArray* windows; // STimeWindow @@ -657,3 +659,13 @@ _OVER: return code; } + +#else + +int32_t createAnomalywindowOperatorInfo(SOperatorInfo* downstream, SPhysiNode* physiNode, SExecTaskInfo* pTaskInfo, + SOperatorInfo** pOptrInfo) { + return TSDB_CODE_OPS_NOT_SUPPORT; +} +void destroyForecastInfo(void* param) {} + +#endif \ No newline at end of file diff --git a/source/libs/executor/src/forecastoperator.c b/source/libs/executor/src/forecastoperator.c index 9eecad8644..02b122830c 100644 --- a/source/libs/executor/src/forecastoperator.c +++ b/source/libs/executor/src/forecastoperator.c @@ -12,13 +12,12 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ + #include "executorInt.h" #include "filter.h" -#include "function.h" #include "functionMgt.h" #include "operator.h" #include "querytask.h" -#include "storageapi.h" #include "tanalytics.h" #include "tcommon.h" #include "tcompare.h" @@ -26,25 +25,27 @@ #include "tfill.h" #include "ttime.h" +#ifdef USE_ANALYTICS + typedef struct { - char algoName[TSDB_ANALYTIC_ALGO_NAME_LEN]; - char algoUrl[TSDB_ANALYTIC_ALGO_URL_LEN]; - char algoOpt[TSDB_ANALYTIC_ALGO_OPTION_LEN]; - int64_t maxTs; - int64_t minTs; - int64_t numOfRows; - uint64_t groupId; - int64_t optRows; - int64_t cachedRows; - int32_t numOfBlocks; - int16_t resTsSlot; - int16_t resValSlot; - int16_t resLowSlot; - int16_t resHighSlot; - int16_t inputTsSlot; - int16_t inputValSlot; - int8_t inputValType; - int8_t inputPrecision; + char algoName[TSDB_ANALYTIC_ALGO_NAME_LEN]; + char algoUrl[TSDB_ANALYTIC_ALGO_URL_LEN]; + char algoOpt[TSDB_ANALYTIC_ALGO_OPTION_LEN]; + int64_t maxTs; + int64_t minTs; + int64_t numOfRows; + uint64_t groupId; + int64_t optRows; + int64_t cachedRows; + int32_t numOfBlocks; + int16_t resTsSlot; + int16_t resValSlot; + int16_t resLowSlot; + int16_t resHighSlot; + int16_t inputTsSlot; + int16_t inputValSlot; + int8_t inputValType; + int8_t inputPrecision; SAnalyticBuf analBuf; } SForecastSupp; @@ -116,7 +117,7 @@ static int32_t forecastCacheBlock(SForecastSupp* pSupp, SSDataBlock* pBlock, con static int32_t forecastCloseBuf(SForecastSupp* pSupp) { SAnalyticBuf* pBuf = &pSupp->analBuf; - int32_t code = 0; + int32_t code = 0; for (int32_t i = 0; i < 2; ++i) { code = taosAnalBufWriteColEnd(pBuf, i); @@ -176,7 +177,6 @@ static int32_t forecastCloseBuf(SForecastSupp* pSupp) { code = taosAnalBufWriteOptInt(pBuf, "start", start); if (code != 0) return code; - bool hasEvery = taosAnalGetOptInt(pSupp->algoOpt, "every", &every); if (!hasEvery) { qDebug("forecast every not found from %s, use %" PRId64, pSupp->algoOpt, every); @@ -190,14 +190,14 @@ static int32_t forecastCloseBuf(SForecastSupp* pSupp) { static int32_t forecastAnalysis(SForecastSupp* pSupp, SSDataBlock* pBlock, const char* pId) { SAnalyticBuf* pBuf = &pSupp->analBuf; - int32_t resCurRow = pBlock->info.rows; - int8_t tmpI8; - int16_t tmpI16; - int32_t tmpI32; - int64_t tmpI64; - float tmpFloat; - double tmpDouble; - int32_t code = 0; + int32_t resCurRow = pBlock->info.rows; + int8_t tmpI8; + int16_t tmpI16; + int32_t tmpI32; + int64_t tmpI64; + float tmpFloat; + double tmpDouble; + int32_t code = 0; SColumnInfoData* pResValCol = taosArrayGet(pBlock->pDataBlock, pSupp->resValSlot); if (NULL == pResValCol) { @@ -354,8 +354,8 @@ _OVER: } static int32_t forecastAggregateBlocks(SForecastSupp* pSupp, SSDataBlock* pResBlock, const char* pId) { - int32_t code = TSDB_CODE_SUCCESS; - int32_t lino = 0; + int32_t code = TSDB_CODE_SUCCESS; + int32_t lino = 0; SAnalyticBuf* pBuf = &pSupp->analBuf; code = forecastCloseBuf(pSupp); @@ -540,7 +540,7 @@ static int32_t forecastParseAlgo(SForecastSupp* pSupp) { static int32_t forecastCreateBuf(SForecastSupp* pSupp) { SAnalyticBuf* pBuf = &pSupp->analBuf; - int64_t ts = 0; // taosGetTimestampMs(); + int64_t ts = 0; // taosGetTimestampMs(); pBuf->bufType = ANALYTICS_BUF_TYPE_JSON_COL; snprintf(pBuf->fileName, sizeof(pBuf->fileName), "%s/tdengine-forecast-%" PRId64, tsTempDir, ts); @@ -660,3 +660,11 @@ static void destroyForecastInfo(void* param) { taosMemoryFreeClear(param); } +#else + +int32_t createForecastOperatorInfo(SOperatorInfo* downstream, SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo, + SOperatorInfo** pOptrInfo) { + return TSDB_CODE_OPS_NOT_SUPPORT; +} + +#endif