2022-01-20 02:51:23 +00:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
|
|
|
|
*
|
|
|
|
|
* This program is free software: you can use, redistribute, and/or modify
|
|
|
|
|
* it under the terms of the GNU Affero General Public License, version 3
|
|
|
|
|
* or later ("AGPL"), as published by the Free Software Foundation.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "functionMgt.h"
|
|
|
|
|
|
2022-04-26 10:15:06 +00:00
|
|
|
#include "builtins.h"
|
2022-10-18 03:38:59 +00:00
|
|
|
#include "builtinsimpl.h"
|
2022-01-20 02:51:23 +00:00
|
|
|
#include "functionMgtInt.h"
|
2026-01-22 06:32:36 +00:00
|
|
|
#include "nodes.h"
|
|
|
|
|
#include "querynodes.h"
|
2022-01-20 02:51:23 +00:00
|
|
|
#include "taos.h"
|
|
|
|
|
#include "taoserror.h"
|
|
|
|
|
#include "thash.h"
|
2022-04-25 07:44:40 +00:00
|
|
|
#include "tudf.h"
|
2022-01-20 02:51:23 +00:00
|
|
|
|
|
|
|
|
typedef struct SFuncMgtService {
|
|
|
|
|
SHashObj* pFuncNameHashTable;
|
|
|
|
|
} SFuncMgtService;
|
|
|
|
|
|
|
|
|
|
static SFuncMgtService gFunMgtService;
|
2022-04-26 10:15:06 +00:00
|
|
|
static TdThreadOnce functionHashTableInit = PTHREAD_ONCE_INIT;
|
|
|
|
|
static int32_t initFunctionCode = 0;
|
2022-01-20 02:51:23 +00:00
|
|
|
|
2022-04-20 09:43:02 +00:00
|
|
|
static void doInitFunctionTable() {
|
2022-04-26 10:15:06 +00:00
|
|
|
gFunMgtService.pFuncNameHashTable =
|
|
|
|
|
taosHashInit(funcMgtBuiltinsNum, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK);
|
2022-01-20 02:51:23 +00:00
|
|
|
if (NULL == gFunMgtService.pFuncNameHashTable) {
|
2024-07-23 07:37:08 +00:00
|
|
|
initFunctionCode = terrno;
|
2022-03-09 02:22:53 +00:00
|
|
|
return;
|
2022-01-20 02:51:23 +00:00
|
|
|
}
|
2022-03-09 02:22:53 +00:00
|
|
|
|
2022-02-09 01:03:32 +00:00
|
|
|
for (int32_t i = 0; i < funcMgtBuiltinsNum; ++i) {
|
2022-04-26 10:15:06 +00:00
|
|
|
if (TSDB_CODE_SUCCESS != taosHashPut(gFunMgtService.pFuncNameHashTable, funcMgtBuiltins[i].name,
|
|
|
|
|
strlen(funcMgtBuiltins[i].name), &i, sizeof(int32_t))) {
|
2024-07-23 07:37:08 +00:00
|
|
|
initFunctionCode = terrno;
|
2022-03-09 02:22:53 +00:00
|
|
|
return;
|
2022-02-09 01:03:32 +00:00
|
|
|
}
|
2022-01-20 02:51:23 +00:00
|
|
|
}
|
2022-04-21 05:37:18 +00:00
|
|
|
}
|
|
|
|
|
|
2022-03-28 11:26:06 +00:00
|
|
|
static bool isSpecificClassifyFunc(int32_t funcId, uint64_t classification) {
|
2022-04-21 05:37:18 +00:00
|
|
|
if (fmIsUserDefinedFunc(funcId)) {
|
2022-04-26 10:15:06 +00:00
|
|
|
return FUNC_MGT_AGG_FUNC == classification
|
|
|
|
|
? FUNC_AGGREGATE_UDF_ID == funcId
|
|
|
|
|
: (FUNC_MGT_SCALAR_FUNC == classification ? FUNC_SCALAR_UDF_ID == funcId : false);
|
2022-04-21 05:37:18 +00:00
|
|
|
}
|
2022-03-28 11:26:06 +00:00
|
|
|
if (funcId < 0 || funcId >= funcMgtBuiltinsNum) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return FUNC_MGT_TEST_MASK(funcMgtBuiltins[funcId].classification, classification);
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-09 02:22:53 +00:00
|
|
|
int32_t fmFuncMgtInit() {
|
2024-07-20 09:34:29 +00:00
|
|
|
(void)taosThreadOnce(&functionHashTableInit, doInitFunctionTable);
|
2022-03-09 02:22:53 +00:00
|
|
|
return initFunctionCode;
|
2022-01-20 02:51:23 +00:00
|
|
|
}
|
|
|
|
|
|
2022-05-28 11:56:06 +00:00
|
|
|
int32_t fmGetFuncInfo(SFunctionNode* pFunc, char* pMsg, int32_t msgLen) {
|
2022-06-18 11:42:03 +00:00
|
|
|
if (NULL != gFunMgtService.pFuncNameHashTable) {
|
|
|
|
|
void* pVal = taosHashGet(gFunMgtService.pFuncNameHashTable, pFunc->functionName, strlen(pFunc->functionName));
|
|
|
|
|
if (NULL != pVal) {
|
|
|
|
|
pFunc->funcId = *(int32_t*)pVal;
|
|
|
|
|
pFunc->funcType = funcMgtBuiltins[pFunc->funcId].type;
|
|
|
|
|
return funcMgtBuiltins[pFunc->funcId].translateFunc(pFunc, pMsg, msgLen);
|
|
|
|
|
}
|
|
|
|
|
return TSDB_CODE_FUNC_NOT_BUILTIN_FUNTION;
|
|
|
|
|
}
|
|
|
|
|
for (int32_t i = 0; i < funcMgtBuiltinsNum; ++i) {
|
|
|
|
|
if (0 == strcmp(funcMgtBuiltins[i].name, pFunc->functionName)) {
|
|
|
|
|
pFunc->funcId = i;
|
|
|
|
|
pFunc->funcType = funcMgtBuiltins[pFunc->funcId].type;
|
|
|
|
|
return funcMgtBuiltins[pFunc->funcId].translateFunc(pFunc, pMsg, msgLen);
|
|
|
|
|
}
|
2022-02-09 01:03:32 +00:00
|
|
|
}
|
2022-05-28 11:56:06 +00:00
|
|
|
return TSDB_CODE_FUNC_NOT_BUILTIN_FUNTION;
|
2022-02-08 10:01:30 +00:00
|
|
|
}
|
|
|
|
|
|
2022-07-29 10:00:48 +00:00
|
|
|
EFuncReturnRows fmGetFuncReturnRows(SFunctionNode* pFunc) {
|
|
|
|
|
if (NULL != funcMgtBuiltins[pFunc->funcId].estimateReturnRowsFunc) {
|
|
|
|
|
return funcMgtBuiltins[pFunc->funcId].estimateReturnRowsFunc(pFunc);
|
|
|
|
|
}
|
|
|
|
|
return (fmIsIndefiniteRowsFunc(pFunc->funcId) || fmIsMultiRowsFunc(pFunc->funcId)) ? FUNC_RETURN_ROWS_INDEFINITE
|
|
|
|
|
: FUNC_RETURN_ROWS_NORMAL;
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-19 06:26:10 +00:00
|
|
|
bool fmIsBuiltinFunc(const char* pFunc) {
|
|
|
|
|
return NULL != taosHashGet(gFunMgtService.pFuncNameHashTable, pFunc, strlen(pFunc));
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-31 03:36:59 +00:00
|
|
|
EFunctionType fmGetFuncType(const char* pFunc) {
|
|
|
|
|
void* pVal = taosHashGet(gFunMgtService.pFuncNameHashTable, pFunc, strlen(pFunc));
|
|
|
|
|
if (NULL != pVal) {
|
|
|
|
|
return funcMgtBuiltins[*(int32_t*)pVal].type;
|
|
|
|
|
}
|
|
|
|
|
return FUNCTION_TYPE_UDF;
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-25 07:48:14 +00:00
|
|
|
EFunctionType fmGetFuncTypeFromId(int32_t funcId) {
|
|
|
|
|
if (funcId < funcMgtBuiltinsNum) {
|
|
|
|
|
return funcMgtBuiltins[funcId].type;
|
|
|
|
|
}
|
|
|
|
|
return FUNCTION_TYPE_UDF;
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-12 05:10:47 +00:00
|
|
|
EFuncDataRequired fmFuncDataRequired(SFunctionNode* pFunc, STimeWindow* pTimeWindow) {
|
2022-04-20 09:43:02 +00:00
|
|
|
if (fmIsUserDefinedFunc(pFunc->funcId) || pFunc->funcId < 0 || pFunc->funcId >= funcMgtBuiltinsNum) {
|
2022-04-15 10:06:49 +00:00
|
|
|
return FUNC_DATA_REQUIRED_DATA_LOAD;
|
2022-04-12 05:10:47 +00:00
|
|
|
}
|
|
|
|
|
if (NULL == funcMgtBuiltins[pFunc->funcId].dataRequiredFunc) {
|
2022-04-15 10:06:49 +00:00
|
|
|
return FUNC_DATA_REQUIRED_DATA_LOAD;
|
2022-04-12 05:10:47 +00:00
|
|
|
}
|
|
|
|
|
return funcMgtBuiltins[pFunc->funcId].dataRequiredFunc(pFunc, pTimeWindow);
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-27 09:07:13 +00:00
|
|
|
EFuncDataRequired fmFuncDynDataRequired(int32_t funcId, void* pRes, SDataBlockInfo* pBlockInfo) {
|
2022-07-27 10:28:54 +00:00
|
|
|
if (fmIsUserDefinedFunc(funcId) || funcId < 0 || funcId >= funcMgtBuiltinsNum) {
|
2024-08-27 09:07:13 +00:00
|
|
|
return FUNC_DATA_REQUIRED_DATA_LOAD;
|
2022-07-27 10:28:54 +00:00
|
|
|
}
|
2022-07-29 01:56:03 +00:00
|
|
|
|
2022-08-02 06:34:50 +00:00
|
|
|
const char* name = funcMgtBuiltins[funcId].name;
|
|
|
|
|
if ((strcmp(name, "_group_key") == 0) || (strcmp(name, "_select_value") == 0)) {
|
2024-11-12 13:10:17 +00:00
|
|
|
return FUNC_DATA_REQUIRED_NOT_LOAD;
|
|
|
|
|
;
|
2022-08-02 06:34:50 +00:00
|
|
|
}
|
|
|
|
|
|
2022-07-29 01:56:03 +00:00
|
|
|
if (funcMgtBuiltins[funcId].dynDataRequiredFunc == NULL) {
|
2024-08-27 09:07:13 +00:00
|
|
|
return FUNC_DATA_REQUIRED_DATA_LOAD;
|
2022-07-29 01:56:03 +00:00
|
|
|
} else {
|
2024-08-27 09:07:13 +00:00
|
|
|
return funcMgtBuiltins[funcId].dynDataRequiredFunc(pRes, pBlockInfo);
|
2022-07-29 01:56:03 +00:00
|
|
|
}
|
2022-07-27 10:28:54 +00:00
|
|
|
}
|
|
|
|
|
|
2022-02-11 14:19:31 +00:00
|
|
|
int32_t fmGetFuncExecFuncs(int32_t funcId, SFuncExecFuncs* pFpSet) {
|
2022-04-20 09:43:02 +00:00
|
|
|
if (fmIsUserDefinedFunc(funcId) || funcId < 0 || funcId >= funcMgtBuiltinsNum) {
|
2022-02-11 14:19:31 +00:00
|
|
|
return TSDB_CODE_FAILED;
|
|
|
|
|
}
|
|
|
|
|
pFpSet->getEnv = funcMgtBuiltins[funcId].getEnvFunc;
|
|
|
|
|
pFpSet->init = funcMgtBuiltins[funcId].initFunc;
|
|
|
|
|
pFpSet->process = funcMgtBuiltins[funcId].processFunc;
|
|
|
|
|
pFpSet->finalize = funcMgtBuiltins[funcId].finalizeFunc;
|
2022-05-20 11:34:39 +00:00
|
|
|
pFpSet->combine = funcMgtBuiltins[funcId].combineFunc;
|
2024-07-04 03:04:59 +00:00
|
|
|
pFpSet->processFuncByRow = funcMgtBuiltins[funcId].processFuncByRow;
|
2024-09-03 09:34:23 +00:00
|
|
|
pFpSet->cleanup = funcMgtBuiltins[funcId].cleanupFunc;
|
2022-02-11 14:19:31 +00:00
|
|
|
return TSDB_CODE_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-28 06:43:54 +00:00
|
|
|
int32_t fmGetUdafExecFuncs(int32_t funcId, SFuncExecFuncs* pFpSet) {
|
2025-03-14 05:32:13 +00:00
|
|
|
#ifdef USE_UDF
|
2022-04-28 06:43:54 +00:00
|
|
|
if (!fmIsUserDefinedFunc(funcId)) {
|
|
|
|
|
return TSDB_CODE_FAILED;
|
|
|
|
|
}
|
2022-04-25 07:44:40 +00:00
|
|
|
pFpSet->getEnv = udfAggGetEnv;
|
|
|
|
|
pFpSet->init = udfAggInit;
|
|
|
|
|
pFpSet->process = udfAggProcess;
|
|
|
|
|
pFpSet->finalize = udfAggFinalize;
|
|
|
|
|
return TSDB_CODE_SUCCESS;
|
2025-03-14 05:32:13 +00:00
|
|
|
#else
|
|
|
|
|
TAOS_RETURN(TSDB_CODE_OPS_NOT_SUPPORT);
|
|
|
|
|
#endif
|
2022-04-25 07:44:40 +00:00
|
|
|
}
|
|
|
|
|
|
2022-02-21 11:31:14 +00:00
|
|
|
int32_t fmGetScalarFuncExecFuncs(int32_t funcId, SScalarFuncExecFuncs* pFpSet) {
|
2022-04-20 09:43:02 +00:00
|
|
|
if (fmIsUserDefinedFunc(funcId) || funcId < 0 || funcId >= funcMgtBuiltinsNum) {
|
2022-02-21 11:31:14 +00:00
|
|
|
return TSDB_CODE_FAILED;
|
|
|
|
|
}
|
|
|
|
|
pFpSet->process = funcMgtBuiltins[funcId].sprocessFunc;
|
2022-04-26 10:15:06 +00:00
|
|
|
pFpSet->getEnv = funcMgtBuiltins[funcId].getEnvFunc;
|
2022-02-21 11:31:14 +00:00
|
|
|
return TSDB_CODE_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-26 10:15:06 +00:00
|
|
|
bool fmIsAggFunc(int32_t funcId) { return isSpecificClassifyFunc(funcId, FUNC_MGT_AGG_FUNC); }
|
2022-03-28 11:26:06 +00:00
|
|
|
|
2022-04-26 10:15:06 +00:00
|
|
|
bool fmIsScalarFunc(int32_t funcId) { return isSpecificClassifyFunc(funcId, FUNC_MGT_SCALAR_FUNC); }
|
2022-03-28 11:26:06 +00:00
|
|
|
|
2022-07-11 02:07:11 +00:00
|
|
|
bool fmIsVectorFunc(int32_t funcId) { return !fmIsScalarFunc(funcId) && !fmIsPseudoColumnFunc(funcId); }
|
2022-05-23 11:50:08 +00:00
|
|
|
|
2024-12-09 08:21:14 +00:00
|
|
|
bool fmIsSelectColsFunc(int32_t funcId) { return isSpecificClassifyFunc(funcId, FUNC_MGT_SELECT_COLS_FUNC); }
|
|
|
|
|
|
2022-05-01 00:38:17 +00:00
|
|
|
bool fmIsSelectFunc(int32_t funcId) { return isSpecificClassifyFunc(funcId, FUNC_MGT_SELECT_FUNC); }
|
|
|
|
|
|
2022-04-29 12:06:26 +00:00
|
|
|
bool fmIsTimelineFunc(int32_t funcId) { return isSpecificClassifyFunc(funcId, FUNC_MGT_TIMELINE_FUNC); }
|
|
|
|
|
|
2023-04-13 03:22:15 +00:00
|
|
|
bool fmIsDateTimeFunc(int32_t funcId) { return isSpecificClassifyFunc(funcId, FUNC_MGT_DATETIME_FUNC); }
|
|
|
|
|
|
2022-04-26 10:15:06 +00:00
|
|
|
bool fmIsPseudoColumnFunc(int32_t funcId) { return isSpecificClassifyFunc(funcId, FUNC_MGT_PSEUDO_COLUMN_FUNC); }
|
2022-04-02 12:20:26 +00:00
|
|
|
|
2022-04-26 10:15:06 +00:00
|
|
|
bool fmIsScanPseudoColumnFunc(int32_t funcId) { return isSpecificClassifyFunc(funcId, FUNC_MGT_SCAN_PC_FUNC); }
|
2022-03-28 11:26:06 +00:00
|
|
|
|
2022-04-26 10:15:06 +00:00
|
|
|
bool fmIsWindowPseudoColumnFunc(int32_t funcId) { return isSpecificClassifyFunc(funcId, FUNC_MGT_WINDOW_PC_FUNC); }
|
2022-03-10 11:32:39 +00:00
|
|
|
|
2022-04-26 10:15:06 +00:00
|
|
|
bool fmIsWindowClauseFunc(int32_t funcId) { return fmIsAggFunc(funcId) || fmIsWindowPseudoColumnFunc(funcId); }
|
|
|
|
|
|
2025-07-16 06:42:16 +00:00
|
|
|
bool fmIsStreamWindowClauseFunc(int32_t funcId) { return fmIsWindowClauseFunc(funcId) || fmIsPlaceHolderFunc(funcId); }
|
|
|
|
|
|
2025-07-23 09:11:16 +00:00
|
|
|
bool fmIsStreamVectorFunc(int32_t funcId) { return fmIsVectorFunc(funcId) || fmIsPlaceHolderFunc(funcId); }
|
|
|
|
|
|
2022-05-23 11:50:08 +00:00
|
|
|
bool fmIsIndefiniteRowsFunc(int32_t funcId) { return isSpecificClassifyFunc(funcId, FUNC_MGT_INDEFINITE_ROWS_FUNC); }
|
2022-04-04 06:54:39 +00:00
|
|
|
|
2022-04-12 05:10:47 +00:00
|
|
|
bool fmIsSpecialDataRequiredFunc(int32_t funcId) {
|
|
|
|
|
return isSpecificClassifyFunc(funcId, FUNC_MGT_SPECIAL_DATA_REQUIRED);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool fmIsDynamicScanOptimizedFunc(int32_t funcId) {
|
|
|
|
|
return isSpecificClassifyFunc(funcId, FUNC_MGT_DYNAMIC_SCAN_OPTIMIZED);
|
|
|
|
|
}
|
2022-04-04 06:54:39 +00:00
|
|
|
|
2022-04-26 10:15:06 +00:00
|
|
|
bool fmIsMultiResFunc(int32_t funcId) { return isSpecificClassifyFunc(funcId, FUNC_MGT_MULTI_RES_FUNC); }
|
2022-04-15 10:30:01 +00:00
|
|
|
|
2022-05-09 12:20:05 +00:00
|
|
|
bool fmIsRepeatScanFunc(int32_t funcId) { return isSpecificClassifyFunc(funcId, FUNC_MGT_REPEAT_SCAN_FUNC); }
|
|
|
|
|
|
2022-04-26 10:15:06 +00:00
|
|
|
bool fmIsUserDefinedFunc(int32_t funcId) { return funcId > FUNC_UDF_ID_START; }
|
2022-04-20 09:43:02 +00:00
|
|
|
|
2022-06-11 07:44:49 +00:00
|
|
|
bool fmIsForbidFillFunc(int32_t funcId) { return isSpecificClassifyFunc(funcId, FUNC_MGT_FORBID_FILL_FUNC); }
|
|
|
|
|
|
2022-06-14 03:54:13 +00:00
|
|
|
bool fmIsIntervalInterpoFunc(int32_t funcId) { return isSpecificClassifyFunc(funcId, FUNC_MGT_INTERVAL_INTERPO_FUNC); }
|
|
|
|
|
|
2022-06-29 03:41:32 +00:00
|
|
|
bool fmIsSystemInfoFunc(int32_t funcId) { return isSpecificClassifyFunc(funcId, FUNC_MGT_SYSTEM_INFO_FUNC); }
|
|
|
|
|
|
2022-07-01 05:31:22 +00:00
|
|
|
bool fmIsImplicitTsFunc(int32_t funcId) { return isSpecificClassifyFunc(funcId, FUNC_MGT_IMPLICIT_TS_FUNC); }
|
|
|
|
|
|
2022-07-13 10:12:02 +00:00
|
|
|
bool fmIsClientPseudoColumnFunc(int32_t funcId) { return isSpecificClassifyFunc(funcId, FUNC_MGT_CLIENT_PC_FUNC); }
|
|
|
|
|
|
2022-07-15 08:17:00 +00:00
|
|
|
bool fmIsMultiRowsFunc(int32_t funcId) { return isSpecificClassifyFunc(funcId, FUNC_MGT_MULTI_ROWS_FUNC); }
|
|
|
|
|
|
2026-01-22 06:32:36 +00:00
|
|
|
static bool fmIsKeepOrderFuncId(int32_t funcId) { return isSpecificClassifyFunc(funcId, FUNC_MGT_KEEP_ORDER_FUNC); }
|
|
|
|
|
|
|
|
|
|
bool fmIsKeepOrderFunc(SFunctionNode* pFunc) {
|
|
|
|
|
if (pFunc->funcType == FUNCTION_TYPE_TOP || pFunc->funcType == FUNCTION_TYPE_BOTTOM ||
|
|
|
|
|
pFunc->funcType == FUNCTION_TYPE_SAMPLE) {
|
|
|
|
|
if (pFunc->pParameterList != NULL && pFunc->pParameterList->length >= 2) {
|
|
|
|
|
SNode* pParam = nodesListGetNode(pFunc->pParameterList, 1);
|
|
|
|
|
if (pParam != NULL && nodeType(pParam) == QUERY_NODE_VALUE) {
|
|
|
|
|
SValueNode* pConst = (SValueNode*)pParam;
|
|
|
|
|
if (pConst->datum.i == 1) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return fmIsKeepOrderFuncId(pFunc->funcId);
|
|
|
|
|
}
|
2022-07-22 03:41:18 +00:00
|
|
|
|
2022-07-29 10:00:48 +00:00
|
|
|
bool fmIsCumulativeFunc(int32_t funcId) { return isSpecificClassifyFunc(funcId, FUNC_MGT_CUMULATIVE_FUNC); }
|
|
|
|
|
|
2023-06-26 10:43:00 +00:00
|
|
|
bool fmIsForbidSysTableFunc(int32_t funcId) { return isSpecificClassifyFunc(funcId, FUNC_MGT_FORBID_SYSTABLE_FUNC); }
|
|
|
|
|
|
2022-06-19 11:39:12 +00:00
|
|
|
bool fmIsInterpFunc(int32_t funcId) {
|
|
|
|
|
if (funcId < 0 || funcId >= funcMgtBuiltinsNum) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return FUNCTION_TYPE_INTERP == funcMgtBuiltins[funcId].type;
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-27 07:23:24 +00:00
|
|
|
bool fmIsInterpPseudoColumnFunc(int32_t funcId) { return isSpecificClassifyFunc(funcId, FUNC_MGT_INTERP_PC_FUNC); }
|
|
|
|
|
|
2024-10-15 02:00:38 +00:00
|
|
|
bool fmIsForecastFunc(int32_t funcId) {
|
|
|
|
|
if (funcId < 0 || funcId >= funcMgtBuiltinsNum) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return FUNCTION_TYPE_FORECAST == funcMgtBuiltins[funcId].type;
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-28 01:47:01 +00:00
|
|
|
bool fmIsAnalysisPseudoColumnFunc(int32_t funcId) { return isSpecificClassifyFunc(funcId, FUNC_MGT_ANALYTICS_PC_FUNC); }
|
2024-10-15 02:00:38 +00:00
|
|
|
|
2025-10-31 03:26:35 +00:00
|
|
|
bool fmIsImputationCorrelationFunc(int32_t funcId) {
|
2025-09-09 00:31:20 +00:00
|
|
|
if (funcId < 0 || funcId >= funcMgtBuiltinsNum) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-31 03:26:35 +00:00
|
|
|
int32_t type = funcMgtBuiltins[funcId].type;
|
|
|
|
|
return FUNCTION_TYPE_IMPUTATION == type || FUNCTION_TYPE_DTW == type || FUNCTION_TYPE_DTW_PATH == type ||
|
|
|
|
|
FUNCTION_TYPE_TLCC == type;
|
2025-09-09 00:31:20 +00:00
|
|
|
}
|
|
|
|
|
|
2022-06-21 11:52:26 +00:00
|
|
|
bool fmIsLastRowFunc(int32_t funcId) {
|
|
|
|
|
if (funcId < 0 || funcId >= funcMgtBuiltinsNum) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return FUNCTION_TYPE_LAST_ROW == funcMgtBuiltins[funcId].type;
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-15 06:10:46 +00:00
|
|
|
bool fmIsLastFunc(int32_t funcId) {
|
|
|
|
|
if (funcId < 0 || funcId >= funcMgtBuiltinsNum) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return FUNCTION_TYPE_LAST == funcMgtBuiltins[funcId].type;
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-06 22:39:26 +00:00
|
|
|
bool fmIsNotNullOutputFunc(int32_t funcId) {
|
2022-08-06 13:39:53 +00:00
|
|
|
if (funcId < 0 || funcId >= funcMgtBuiltinsNum) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return FUNCTION_TYPE_LAST == funcMgtBuiltins[funcId].type ||
|
2025-09-12 01:25:43 +00:00
|
|
|
FUNCTION_TYPE_CACHE_LAST == funcMgtBuiltins[funcId].type ||
|
2022-08-06 13:39:53 +00:00
|
|
|
FUNCTION_TYPE_LAST_PARTIAL == funcMgtBuiltins[funcId].type ||
|
|
|
|
|
FUNCTION_TYPE_LAST_MERGE == funcMgtBuiltins[funcId].type ||
|
|
|
|
|
FUNCTION_TYPE_FIRST == funcMgtBuiltins[funcId].type ||
|
|
|
|
|
FUNCTION_TYPE_FIRST_PARTIAL == funcMgtBuiltins[funcId].type ||
|
2022-11-03 02:39:53 +00:00
|
|
|
FUNCTION_TYPE_FIRST_MERGE == funcMgtBuiltins[funcId].type ||
|
|
|
|
|
FUNCTION_TYPE_COUNT == funcMgtBuiltins[funcId].type ||
|
|
|
|
|
FUNCTION_TYPE_HYPERLOGLOG == funcMgtBuiltins[funcId].type ||
|
|
|
|
|
FUNCTION_TYPE_HYPERLOGLOG_PARTIAL == funcMgtBuiltins[funcId].type ||
|
|
|
|
|
FUNCTION_TYPE_HYPERLOGLOG_MERGE == funcMgtBuiltins[funcId].type;
|
2022-08-06 13:39:53 +00:00
|
|
|
}
|
|
|
|
|
|
2022-08-01 06:15:16 +00:00
|
|
|
bool fmIsSelectValueFunc(int32_t funcId) {
|
|
|
|
|
if (funcId < 0 || funcId >= funcMgtBuiltinsNum) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return FUNCTION_TYPE_SELECT_VALUE == funcMgtBuiltins[funcId].type;
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-01 05:34:10 +00:00
|
|
|
bool fmIsGroupKeyFunc(int32_t funcId) {
|
|
|
|
|
if (funcId < 0 || funcId >= funcMgtBuiltinsNum) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return FUNCTION_TYPE_GROUP_KEY == funcMgtBuiltins[funcId].type;
|
2024-07-21 16:06:47 +00:00
|
|
|
}
|
|
|
|
|
|
2026-03-06 06:45:30 +00:00
|
|
|
bool fmIsHasNullFunc(int32_t funcId) {
|
|
|
|
|
if (funcId < 0 || funcId >= funcMgtBuiltinsNum) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return FUNCTION_TYPE_HAS_NULL == funcMgtBuiltins[funcId].type;
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-22 03:19:11 +00:00
|
|
|
bool fmisSelectGroupConstValueFunc(int32_t funcId) {
|
2024-07-21 16:06:47 +00:00
|
|
|
if (funcId < 0 || funcId >= funcMgtBuiltinsNum) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2024-07-22 03:19:11 +00:00
|
|
|
return FUNCTION_TYPE_GROUP_CONST_VALUE == funcMgtBuiltins[funcId].type;
|
2022-11-01 05:34:10 +00:00
|
|
|
}
|
|
|
|
|
|
2024-09-12 07:34:57 +00:00
|
|
|
bool fmIsElapsedFunc(int32_t funcId) {
|
|
|
|
|
if (funcId < 0 || funcId >= funcMgtBuiltinsNum) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return FUNCTION_TYPE_ELAPSED == funcMgtBuiltins[funcId].type;
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-02 03:57:22 +00:00
|
|
|
bool fmIsBlockDistFunc(int32_t funcId) {
|
|
|
|
|
if (funcId < 0 || funcId >= funcMgtBuiltinsNum) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return FUNCTION_TYPE_BLOCK_DIST == funcMgtBuiltins[funcId].type;
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-12 13:10:17 +00:00
|
|
|
bool fmIsDBUsageFunc(int32_t funcId) {
|
|
|
|
|
if (funcId < 0 || funcId >= funcMgtBuiltinsNum) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return FUNCTION_TYPE_DB_USAGE == funcMgtBuiltins[funcId].type;
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-04 03:04:59 +00:00
|
|
|
bool fmIsProcessByRowFunc(int32_t funcId) { return isSpecificClassifyFunc(funcId, FUNC_MGT_PROCESS_BY_ROW); }
|
|
|
|
|
|
2024-04-09 01:48:38 +00:00
|
|
|
bool fmIsIgnoreNullFunc(int32_t funcId) { return isSpecificClassifyFunc(funcId, FUNC_MGT_IGNORE_NULL_FUNC); }
|
|
|
|
|
|
2022-03-10 11:32:39 +00:00
|
|
|
void fmFuncMgtDestroy() {
|
|
|
|
|
void* m = gFunMgtService.pFuncNameHashTable;
|
2022-03-21 16:54:21 +00:00
|
|
|
if (m != NULL && atomic_val_compare_exchange_ptr((void**)&gFunMgtService.pFuncNameHashTable, m, 0) == m) {
|
2022-03-10 11:32:39 +00:00
|
|
|
taosHashCleanup(m);
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-05-05 11:50:11 +00:00
|
|
|
|
2024-01-12 05:49:32 +00:00
|
|
|
#ifdef BUILD_NO_CALL
|
2022-05-05 11:50:11 +00:00
|
|
|
int32_t fmSetNormalFunc(int32_t funcId, SFuncExecFuncs* pFpSet) {
|
|
|
|
|
if (fmIsUserDefinedFunc(funcId) || funcId < 0 || funcId >= funcMgtBuiltinsNum) {
|
|
|
|
|
return TSDB_CODE_FAILED;
|
|
|
|
|
}
|
|
|
|
|
pFpSet->process = funcMgtBuiltins[funcId].processFunc;
|
|
|
|
|
return TSDB_CODE_SUCCESS;
|
|
|
|
|
}
|
2024-01-12 05:49:32 +00:00
|
|
|
#endif
|
2022-06-02 02:45:27 +00:00
|
|
|
|
2022-06-16 08:58:55 +00:00
|
|
|
// function has same input/output type
|
2022-06-10 13:10:55 +00:00
|
|
|
bool fmIsSameInOutType(int32_t funcId) {
|
|
|
|
|
bool res = false;
|
|
|
|
|
switch (funcMgtBuiltins[funcId].type) {
|
|
|
|
|
case FUNCTION_TYPE_MAX:
|
|
|
|
|
case FUNCTION_TYPE_MIN:
|
|
|
|
|
case FUNCTION_TYPE_TOP:
|
|
|
|
|
case FUNCTION_TYPE_BOTTOM:
|
|
|
|
|
case FUNCTION_TYPE_FIRST:
|
|
|
|
|
case FUNCTION_TYPE_LAST:
|
|
|
|
|
case FUNCTION_TYPE_SAMPLE:
|
|
|
|
|
case FUNCTION_TYPE_TAIL:
|
|
|
|
|
case FUNCTION_TYPE_UNIQUE:
|
|
|
|
|
res = true;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-30 08:51:44 +00:00
|
|
|
bool fmIsConstantResFunc(SFunctionNode* pFunc) {
|
|
|
|
|
SNode* pNode;
|
|
|
|
|
FOREACH(pNode, pFunc->pParameterList) {
|
|
|
|
|
if (nodeType(pNode) != QUERY_NODE_VALUE) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-12 13:10:17 +00:00
|
|
|
bool fmIsSkipScanCheckFunc(int32_t funcId) { return isSpecificClassifyFunc(funcId, FUNC_MGT_SKIP_SCAN_CHECK_FUNC); }
|
2023-09-19 06:56:02 +00:00
|
|
|
|
2024-11-12 13:10:17 +00:00
|
|
|
bool fmIsPrimaryKeyFunc(int32_t funcId) { return isSpecificClassifyFunc(funcId, FUNC_MGT_PRIMARY_KEY_FUNC); }
|
2025-07-16 06:42:16 +00:00
|
|
|
|
|
|
|
|
bool fmIsPlaceHolderFunc(int32_t funcId) {return isSpecificClassifyFunc(funcId, FUNC_MGT_PLACE_HOLDER_FUNC); }
|
|
|
|
|
|
2024-03-15 10:34:41 +00:00
|
|
|
void getLastCacheDataType(SDataType* pType, int32_t pkBytes) {
|
2024-11-12 13:10:17 +00:00
|
|
|
// TODO: do it later.
|
2024-03-15 10:34:41 +00:00
|
|
|
pType->bytes = getFirstLastInfoSize(pType->bytes, pkBytes) + VARSTR_HEADER_SIZE;
|
2022-10-18 03:38:59 +00:00
|
|
|
pType->type = TSDB_DATA_TYPE_BINARY;
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-10 06:28:58 +00:00
|
|
|
static int32_t getFuncInfo(SFunctionNode* pFunc) {
|
2022-07-04 06:46:58 +00:00
|
|
|
char msg[128] = {0};
|
2022-06-18 11:42:03 +00:00
|
|
|
return fmGetFuncInfo(pFunc, msg, sizeof(msg));
|
2022-06-10 06:28:58 +00:00
|
|
|
}
|
|
|
|
|
|
2024-07-21 10:20:30 +00:00
|
|
|
int32_t createFunction(const char* pName, SNodeList* pParameterList, SFunctionNode** ppFunc) {
|
|
|
|
|
int32_t code = nodesMakeNode(QUERY_NODE_FUNCTION, (SNode**)ppFunc);
|
|
|
|
|
if (NULL == *ppFunc) {
|
|
|
|
|
return code;
|
|
|
|
|
}
|
|
|
|
|
(void)snprintf((*ppFunc)->functionName, sizeof((*ppFunc)->functionName), "%s", pName);
|
|
|
|
|
(*ppFunc)->pParameterList = pParameterList;
|
|
|
|
|
code = getFuncInfo((*ppFunc));
|
2024-07-20 09:34:29 +00:00
|
|
|
if (TSDB_CODE_SUCCESS != code) {
|
2024-07-21 10:20:30 +00:00
|
|
|
(*ppFunc)->pParameterList = NULL;
|
|
|
|
|
nodesDestroyNode((SNode*)*ppFunc);
|
|
|
|
|
*ppFunc = NULL;
|
2024-07-20 09:34:29 +00:00
|
|
|
return code;
|
2022-06-02 02:45:27 +00:00
|
|
|
}
|
2024-07-20 09:34:29 +00:00
|
|
|
return code;
|
2022-06-02 02:45:27 +00:00
|
|
|
}
|
|
|
|
|
|
2024-11-25 05:56:14 +00:00
|
|
|
static void resetOutputChangedFunc(SFunctionNode *pFunc, const SFunctionNode* pSrcFunc) {
|
|
|
|
|
if (funcMgtBuiltins[pFunc->funcId].type == FUNCTION_TYPE_LAST_MERGE) {
|
|
|
|
|
pFunc->node.resType = pSrcFunc->node.resType;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-27 14:41:34 +00:00
|
|
|
int32_t createFunctionWithSrcFunc(const char* pName, const SFunctionNode* pSrcFunc, SNodeList* pParameterList, SFunctionNode** ppFunc) {
|
|
|
|
|
int32_t code = nodesMakeNode(QUERY_NODE_FUNCTION, (SNode**)ppFunc);
|
|
|
|
|
if (NULL == *ppFunc) {
|
|
|
|
|
return code;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
(*ppFunc)->hasPk = pSrcFunc->hasPk;
|
|
|
|
|
(*ppFunc)->pkBytes = pSrcFunc->pkBytes;
|
2025-03-14 10:08:07 +00:00
|
|
|
(*ppFunc)->pSrcFuncRef = pSrcFunc;
|
2024-10-27 14:41:34 +00:00
|
|
|
|
|
|
|
|
(void)snprintf((*ppFunc)->functionName, sizeof((*ppFunc)->functionName), "%s", pName);
|
|
|
|
|
(*ppFunc)->pParameterList = pParameterList;
|
|
|
|
|
code = getFuncInfo((*ppFunc));
|
|
|
|
|
if (TSDB_CODE_SUCCESS != code) {
|
|
|
|
|
(*ppFunc)->pParameterList = NULL;
|
|
|
|
|
nodesDestroyNode((SNode*)*ppFunc);
|
|
|
|
|
*ppFunc = NULL;
|
|
|
|
|
return code;
|
|
|
|
|
}
|
2024-11-25 05:56:14 +00:00
|
|
|
resetOutputChangedFunc(*ppFunc, pSrcFunc);
|
2025-02-15 17:15:12 +00:00
|
|
|
(*ppFunc)->node.relatedTo = pSrcFunc->node.relatedTo;
|
|
|
|
|
(*ppFunc)->node.bindExprID = pSrcFunc->node.bindExprID;
|
2024-10-27 14:41:34 +00:00
|
|
|
return code;
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-21 10:20:30 +00:00
|
|
|
static int32_t createColumnByFunc(const SFunctionNode* pFunc, SColumnNode** ppCol) {
|
2024-07-23 11:04:01 +00:00
|
|
|
int32_t code = nodesMakeNode(QUERY_NODE_COLUMN, (SNode**)ppCol);
|
2024-07-21 10:20:30 +00:00
|
|
|
if (NULL == *ppCol) {
|
|
|
|
|
return code;
|
2022-06-02 02:45:27 +00:00
|
|
|
}
|
2024-09-30 06:39:44 +00:00
|
|
|
tstrncpy((*ppCol)->colName, pFunc->node.aliasName, TSDB_COL_NAME_LEN);
|
2024-07-21 10:20:30 +00:00
|
|
|
(*ppCol)->node.resType = pFunc->node.resType;
|
2024-07-20 09:34:29 +00:00
|
|
|
return TSDB_CODE_SUCCESS;
|
2022-06-02 02:45:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool fmIsDistExecFunc(int32_t funcId) {
|
2022-06-04 01:33:13 +00:00
|
|
|
if (fmIsUserDefinedFunc(funcId)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2022-06-02 02:45:27 +00:00
|
|
|
if (!fmIsVectorFunc(funcId)) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return (NULL != funcMgtBuiltins[funcId].pPartialFunc && NULL != funcMgtBuiltins[funcId].pMergeFunc);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int32_t createPartialFunction(const SFunctionNode* pSrcFunc, SFunctionNode** pPartialFunc) {
|
2024-07-21 10:20:30 +00:00
|
|
|
SNodeList* pParameterList = NULL;
|
2024-11-12 13:10:17 +00:00
|
|
|
int32_t code = nodesCloneList(pSrcFunc->pParameterList, &pParameterList);
|
2022-06-02 02:45:27 +00:00
|
|
|
if (NULL == pParameterList) {
|
2024-07-21 10:20:30 +00:00
|
|
|
return code;
|
2022-06-02 02:45:27 +00:00
|
|
|
}
|
2024-10-27 14:41:34 +00:00
|
|
|
code =
|
|
|
|
|
createFunctionWithSrcFunc(funcMgtBuiltins[pSrcFunc->funcId].pPartialFunc, pSrcFunc, pParameterList, pPartialFunc);
|
2024-07-20 09:34:29 +00:00
|
|
|
if (TSDB_CODE_SUCCESS != code) {
|
2022-06-02 02:45:27 +00:00
|
|
|
nodesDestroyList(pParameterList);
|
2024-07-20 09:34:29 +00:00
|
|
|
return code;
|
2022-06-02 02:45:27 +00:00
|
|
|
}
|
2024-03-11 11:29:08 +00:00
|
|
|
(*pPartialFunc)->hasOriginalFunc = true;
|
|
|
|
|
(*pPartialFunc)->originalFuncId = pSrcFunc->hasOriginalFunc ? pSrcFunc->originalFuncId : pSrcFunc->funcId;
|
2023-08-30 02:25:16 +00:00
|
|
|
char name[TSDB_FUNC_NAME_LEN + TSDB_NAME_DELIMITER_LEN + TSDB_POINTER_PRINT_BYTES + 1] = {0};
|
2024-11-12 13:10:17 +00:00
|
|
|
|
2024-10-10 02:37:31 +00:00
|
|
|
int32_t len = tsnprintf(name, sizeof(name), "%s.%p", (*pPartialFunc)->functionName, pSrcFunc);
|
2024-09-05 01:57:45 +00:00
|
|
|
if (taosHashBinary(name, len) < 0) {
|
|
|
|
|
return TSDB_CODE_FAILED;
|
|
|
|
|
}
|
2024-09-30 06:39:44 +00:00
|
|
|
tstrncpy((*pPartialFunc)->node.aliasName, name, TSDB_COL_NAME_LEN);
|
2022-06-02 02:45:27 +00:00
|
|
|
return TSDB_CODE_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-18 12:52:42 +00:00
|
|
|
static int32_t createMergeFuncPara(const SFunctionNode* pSrcFunc, const SFunctionNode* pPartialFunc,
|
|
|
|
|
SNodeList** pParameterList) {
|
2024-11-12 13:10:17 +00:00
|
|
|
SNode* pRes = NULL;
|
2024-07-20 09:34:29 +00:00
|
|
|
int32_t code = createColumnByFunc(pPartialFunc, (SColumnNode**)&pRes);
|
|
|
|
|
if (TSDB_CODE_SUCCESS != code) {
|
|
|
|
|
return code;
|
|
|
|
|
}
|
2022-06-18 12:52:42 +00:00
|
|
|
if (NULL != funcMgtBuiltins[pSrcFunc->funcId].createMergeParaFuc) {
|
|
|
|
|
return funcMgtBuiltins[pSrcFunc->funcId].createMergeParaFuc(pSrcFunc->pParameterList, pRes, pParameterList);
|
|
|
|
|
} else {
|
|
|
|
|
return nodesListMakeStrictAppend(pParameterList, pRes);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-22 10:30:22 +00:00
|
|
|
static int32_t createMidFunction(const SFunctionNode* pSrcFunc, const SFunctionNode* pPartialFunc,
|
2024-11-12 13:10:17 +00:00
|
|
|
SFunctionNode** pMidFunc) {
|
2023-12-22 10:30:22 +00:00
|
|
|
SNodeList* pParameterList = NULL;
|
|
|
|
|
SFunctionNode* pFunc = NULL;
|
|
|
|
|
|
|
|
|
|
int32_t code = createMergeFuncPara(pSrcFunc, pPartialFunc, &pParameterList);
|
|
|
|
|
if (TSDB_CODE_SUCCESS == code) {
|
|
|
|
|
if(funcMgtBuiltins[pSrcFunc->funcId].pMiddleFunc != NULL){
|
2024-10-27 14:41:34 +00:00
|
|
|
code = createFunctionWithSrcFunc(funcMgtBuiltins[pSrcFunc->funcId].pMiddleFunc, pSrcFunc, pParameterList, &pFunc);
|
2023-12-22 10:30:22 +00:00
|
|
|
}else{
|
2024-10-27 14:41:34 +00:00
|
|
|
code = createFunctionWithSrcFunc(funcMgtBuiltins[pSrcFunc->funcId].pMergeFunc, pSrcFunc, pParameterList, &pFunc);
|
2023-12-22 10:30:22 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (TSDB_CODE_SUCCESS == code) {
|
2024-09-30 06:39:44 +00:00
|
|
|
tstrncpy(pFunc->node.aliasName, pPartialFunc->node.aliasName, TSDB_COL_NAME_LEN);
|
2023-12-22 10:30:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (TSDB_CODE_SUCCESS == code) {
|
|
|
|
|
*pMidFunc = pFunc;
|
|
|
|
|
} else {
|
|
|
|
|
nodesDestroyList(pParameterList);
|
|
|
|
|
}
|
|
|
|
|
return code;
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-02 02:45:27 +00:00
|
|
|
static int32_t createMergeFunction(const SFunctionNode* pSrcFunc, const SFunctionNode* pPartialFunc,
|
|
|
|
|
SFunctionNode** pMergeFunc) {
|
2022-06-18 12:52:42 +00:00
|
|
|
SNodeList* pParameterList = NULL;
|
|
|
|
|
SFunctionNode* pFunc = NULL;
|
|
|
|
|
|
|
|
|
|
int32_t code = createMergeFuncPara(pSrcFunc, pPartialFunc, &pParameterList);
|
|
|
|
|
if (TSDB_CODE_SUCCESS == code) {
|
2024-10-27 14:41:34 +00:00
|
|
|
code = createFunctionWithSrcFunc(funcMgtBuiltins[pSrcFunc->funcId].pMergeFunc, pSrcFunc, pParameterList, &pFunc);
|
2022-06-02 02:45:27 +00:00
|
|
|
}
|
2022-06-18 12:52:42 +00:00
|
|
|
if (TSDB_CODE_SUCCESS == code) {
|
2024-03-11 11:29:08 +00:00
|
|
|
pFunc->hasOriginalFunc = true;
|
|
|
|
|
pFunc->originalFuncId = pSrcFunc->hasOriginalFunc ? pSrcFunc->originalFuncId : pSrcFunc->funcId;
|
2022-06-18 12:52:42 +00:00
|
|
|
// overwrite function restype set by translate function
|
|
|
|
|
if (fmIsSameInOutType(pSrcFunc->funcId)) {
|
2022-06-19 02:06:46 +00:00
|
|
|
pFunc->node.resType = pSrcFunc->node.resType;
|
2022-06-18 12:52:42 +00:00
|
|
|
}
|
2024-09-30 06:39:44 +00:00
|
|
|
tstrncpy(pFunc->node.aliasName, pSrcFunc->node.aliasName, TSDB_COL_NAME_LEN);
|
2022-06-02 02:45:27 +00:00
|
|
|
}
|
2022-06-18 12:52:42 +00:00
|
|
|
|
|
|
|
|
if (TSDB_CODE_SUCCESS == code) {
|
|
|
|
|
*pMergeFunc = pFunc;
|
|
|
|
|
} else {
|
|
|
|
|
nodesDestroyList(pParameterList);
|
2022-06-10 13:10:55 +00:00
|
|
|
}
|
2022-06-18 12:52:42 +00:00
|
|
|
return code;
|
2022-06-02 02:45:27 +00:00
|
|
|
}
|
|
|
|
|
|
2024-11-12 13:10:17 +00:00
|
|
|
int32_t fmGetDistMethod(const SFunctionNode* pFunc, SFunctionNode** pPartialFunc, SFunctionNode** pMidFunc,
|
|
|
|
|
SFunctionNode** pMergeFunc) {
|
2022-06-02 02:45:27 +00:00
|
|
|
if (!fmIsDistExecFunc(pFunc->funcId)) {
|
|
|
|
|
return TSDB_CODE_FAILED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int32_t code = createPartialFunction(pFunc, pPartialFunc);
|
2024-02-04 01:27:46 +00:00
|
|
|
if (TSDB_CODE_SUCCESS == code && pMidFunc) {
|
2023-12-22 10:30:22 +00:00
|
|
|
code = createMidFunction(pFunc, *pPartialFunc, pMidFunc);
|
|
|
|
|
}
|
2022-06-02 02:45:27 +00:00
|
|
|
if (TSDB_CODE_SUCCESS == code) {
|
|
|
|
|
code = createMergeFunction(pFunc, *pPartialFunc, pMergeFunc);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (TSDB_CODE_SUCCESS != code) {
|
2022-06-13 06:54:38 +00:00
|
|
|
nodesDestroyNode((SNode*)*pPartialFunc);
|
2024-02-04 01:27:46 +00:00
|
|
|
if (pMidFunc) nodesDestroyNode((SNode*)*pMidFunc);
|
2022-06-13 06:54:38 +00:00
|
|
|
nodesDestroyNode((SNode*)*pMergeFunc);
|
2022-06-02 02:45:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return code;
|
|
|
|
|
}
|
2023-03-23 03:18:14 +00:00
|
|
|
|
2025-09-26 09:32:32 +00:00
|
|
|
const char* fmGetFuncName(int32_t funcId) {
|
2023-03-23 03:18:14 +00:00
|
|
|
if (fmIsUserDefinedFunc(funcId) || funcId < 0 || funcId >= funcMgtBuiltinsNum) {
|
2025-09-26 09:32:32 +00:00
|
|
|
return "invalid function";
|
2023-03-23 03:18:14 +00:00
|
|
|
}
|
2025-09-26 09:32:32 +00:00
|
|
|
return funcMgtBuiltins[funcId].name;
|
2023-03-23 03:18:14 +00:00
|
|
|
}
|
2023-11-29 11:07:23 +00:00
|
|
|
|
|
|
|
|
/// @param [out] pStateFunc, not changed if error occured or no need to create state func
|
|
|
|
|
/// @retval 0 for succ, otherwise err occured
|
|
|
|
|
static int32_t fmCreateStateFunc(const SFunctionNode* pFunc, SFunctionNode** pStateFunc) {
|
|
|
|
|
if (funcMgtBuiltins[pFunc->funcId].pStateFunc) {
|
2024-07-21 10:20:30 +00:00
|
|
|
SNodeList* pParams = NULL;
|
2024-11-12 13:10:17 +00:00
|
|
|
int32_t code = nodesCloneList(pFunc->pParameterList, &pParams);
|
2024-07-21 10:20:30 +00:00
|
|
|
if (!pParams) return code;
|
|
|
|
|
code = createFunction(funcMgtBuiltins[pFunc->funcId].pStateFunc, pParams, pStateFunc);
|
2024-07-20 09:34:29 +00:00
|
|
|
if (TSDB_CODE_SUCCESS != code) {
|
2023-11-29 11:07:23 +00:00
|
|
|
nodesDestroyList(pParams);
|
2024-07-25 06:49:47 +00:00
|
|
|
return code;
|
2023-11-29 11:07:23 +00:00
|
|
|
}
|
2024-09-30 06:39:44 +00:00
|
|
|
tstrncpy((*pStateFunc)->node.aliasName, pFunc->node.aliasName, TSDB_COL_NAME_LEN);
|
|
|
|
|
tstrncpy((*pStateFunc)->node.userAlias, pFunc->node.userAlias, TSDB_COL_NAME_LEN);
|
2023-11-29 11:07:23 +00:00
|
|
|
}
|
|
|
|
|
return TSDB_CODE_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-26 09:32:32 +00:00
|
|
|
bool fmIsTSMASupportedFunc(func_id_t funcId) { return isSpecificClassifyFunc(funcId, FUNC_MGT_TSMA_FUNC); }
|
|
|
|
|
|
|
|
|
|
bool fmIsRsmaSupportedFunc(func_id_t funcId) { return isSpecificClassifyFunc(funcId, FUNC_MGT_RSMA_FUNC); }
|
2023-11-29 11:07:23 +00:00
|
|
|
|
2023-12-22 06:05:31 +00:00
|
|
|
int32_t fmCreateStateFuncs(SNodeList* pFuncs) {
|
2023-11-29 11:07:23 +00:00
|
|
|
int32_t code;
|
|
|
|
|
SNode* pNode;
|
|
|
|
|
char buf[128] = {0};
|
|
|
|
|
FOREACH(pNode, pFuncs) {
|
|
|
|
|
SFunctionNode* pFunc = (SFunctionNode*)pNode;
|
|
|
|
|
code = fmGetFuncInfo(pFunc, buf, 128);
|
|
|
|
|
if (code) break;
|
|
|
|
|
if (fmIsTSMASupportedFunc(pFunc->funcId)) {
|
|
|
|
|
SFunctionNode* pNewFunc = NULL;
|
|
|
|
|
code = fmCreateStateFunc(pFunc, &pNewFunc);
|
|
|
|
|
if (code) {
|
|
|
|
|
// error
|
|
|
|
|
break;
|
|
|
|
|
} else if (!pNewFunc) {
|
|
|
|
|
// no need state func
|
|
|
|
|
continue;
|
|
|
|
|
} else {
|
|
|
|
|
REPLACE_NODE(pNewFunc);
|
|
|
|
|
nodesDestroyNode(pNode);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return code;
|
|
|
|
|
}
|
2023-12-15 10:11:22 +00:00
|
|
|
|
2023-12-27 06:38:02 +00:00
|
|
|
static int32_t fmCreateStateMergeFunc(SFunctionNode* pFunc, SFunctionNode** pStateMergeFunc) {
|
|
|
|
|
if (funcMgtBuiltins[pFunc->funcId].pMergeFunc) {
|
2024-07-21 10:20:30 +00:00
|
|
|
SNodeList* pParams = NULL;
|
2024-11-12 13:10:17 +00:00
|
|
|
int32_t code = nodesCloneList(pFunc->pParameterList, &pParams);
|
2024-07-21 10:20:30 +00:00
|
|
|
if (!pParams) return code;
|
2025-03-14 10:08:07 +00:00
|
|
|
code = createFunctionWithSrcFunc(funcMgtBuiltins[pFunc->funcId].pMergeFunc, pFunc, pParams, pStateMergeFunc);
|
2024-07-20 09:34:29 +00:00
|
|
|
if (TSDB_CODE_SUCCESS != code) {
|
2023-12-27 06:38:02 +00:00
|
|
|
nodesDestroyList(pParams);
|
2024-07-20 09:34:29 +00:00
|
|
|
return code;
|
2023-12-27 06:38:02 +00:00
|
|
|
}
|
2024-09-30 06:39:44 +00:00
|
|
|
tstrncpy((*pStateMergeFunc)->node.aliasName, pFunc->node.aliasName, TSDB_COL_NAME_LEN);
|
|
|
|
|
tstrncpy((*pStateMergeFunc)->node.userAlias, pFunc->node.userAlias, TSDB_COL_NAME_LEN);
|
2023-12-27 06:38:02 +00:00
|
|
|
}
|
|
|
|
|
return TSDB_CODE_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int32_t fmCreateStateMergeFuncs(SNodeList* pFuncs) {
|
|
|
|
|
int32_t code;
|
|
|
|
|
SNode* pNode;
|
|
|
|
|
char buf[128] = {0};
|
|
|
|
|
FOREACH(pNode, pFuncs) {
|
|
|
|
|
SFunctionNode* pFunc = (SFunctionNode*)pNode;
|
|
|
|
|
if (fmIsTSMASupportedFunc(pFunc->funcId)) {
|
|
|
|
|
SFunctionNode* pNewFunc = NULL;
|
|
|
|
|
code = fmCreateStateMergeFunc(pFunc, &pNewFunc);
|
|
|
|
|
if (code) {
|
|
|
|
|
// error
|
|
|
|
|
break;
|
|
|
|
|
} else if (!pNewFunc) {
|
|
|
|
|
// no state merge func
|
|
|
|
|
continue;
|
|
|
|
|
} else {
|
|
|
|
|
REPLACE_NODE(pNewFunc);
|
|
|
|
|
nodesDestroyNode(pNode);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return code;
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-22 06:05:31 +00:00
|
|
|
int32_t fmGetFuncId(const char* name) {
|
2023-12-15 10:11:22 +00:00
|
|
|
if (NULL != gFunMgtService.pFuncNameHashTable) {
|
|
|
|
|
void* pVal = taosHashGet(gFunMgtService.pFuncNameHashTable, name, strlen(name));
|
|
|
|
|
if (NULL != pVal) {
|
|
|
|
|
return *(int32_t*)pVal;
|
|
|
|
|
}
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
for (int32_t i = 0; i < funcMgtBuiltinsNum; ++i) {
|
|
|
|
|
if (0 == strcmp(funcMgtBuiltins[i].name, name)) {
|
|
|
|
|
return i;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
2023-12-22 06:05:31 +00:00
|
|
|
|
|
|
|
|
bool fmIsMyStateFunc(int32_t funcId, int32_t stateFuncId) {
|
|
|
|
|
const SBuiltinFuncDefinition* pFunc = &funcMgtBuiltins[funcId];
|
|
|
|
|
const SBuiltinFuncDefinition* pStateFunc = &funcMgtBuiltins[stateFuncId];
|
|
|
|
|
if (!pFunc->pStateFunc) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2024-02-19 08:04:55 +00:00
|
|
|
if (strcmp(pFunc->pStateFunc, pStateFunc->name) == 0) return true;
|
|
|
|
|
int32_t stateMergeFuncId = fmGetFuncId(pFunc->pStateFunc);
|
2024-07-20 09:34:29 +00:00
|
|
|
if (stateMergeFuncId == -1) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2024-02-19 08:04:55 +00:00
|
|
|
const SBuiltinFuncDefinition* pStateMergeFunc = &funcMgtBuiltins[stateMergeFuncId];
|
|
|
|
|
return strcmp(pStateFunc->name, pStateMergeFunc->pMergeFunc) == 0;
|
2023-12-22 06:05:31 +00:00
|
|
|
}
|
2024-03-11 11:29:08 +00:00
|
|
|
|
|
|
|
|
bool fmIsCountLikeFunc(int32_t funcId) {
|
|
|
|
|
return isSpecificClassifyFunc(funcId, FUNC_MGT_COUNT_LIKE_FUNC);
|
|
|
|
|
}
|
2024-11-28 10:29:20 +00:00
|
|
|
|
|
|
|
|
bool fmIsRowTsOriginFunc(int32_t funcId) {
|
|
|
|
|
if (funcId < 0 || funcId >= funcMgtBuiltinsNum) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return FUNCTION_TYPE_IROWTS_ORIGIN == funcMgtBuiltins[funcId].type;
|
|
|
|
|
}
|
2025-03-14 12:14:01 +00:00
|
|
|
|
|
|
|
|
bool fmIsGroupIdFunc(int32_t funcId) {
|
|
|
|
|
if (funcId < 0 || funcId >= funcMgtBuiltinsNum) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return FUNCTION_TYPE_GROUP_ID == funcMgtBuiltins[funcId].type;
|
|
|
|
|
}
|
2025-07-16 06:42:16 +00:00
|
|
|
|
|
|
|
|
const void* fmGetStreamPesudoFuncVal(int32_t funcId, const SStreamRuntimeFuncInfo* pStreamRuntimeFuncInfo) {
|
|
|
|
|
SSTriggerCalcParam *pParams = taosArrayGet(pStreamRuntimeFuncInfo->pStreamPesudoFuncVals, pStreamRuntimeFuncInfo->curIdx);
|
|
|
|
|
switch (funcMgtBuiltins[funcId].type) {
|
|
|
|
|
case FUNCTION_TYPE_TPREV_TS:
|
|
|
|
|
return &pParams->prevTs;
|
|
|
|
|
case FUNCTION_TYPE_TCURRENT_TS:
|
|
|
|
|
return &pParams->currentTs;
|
|
|
|
|
case FUNCTION_TYPE_TNEXT_TS:
|
|
|
|
|
return &pParams->nextTs;
|
|
|
|
|
case FUNCTION_TYPE_TWSTART:
|
|
|
|
|
return &pParams->wstart;
|
|
|
|
|
case FUNCTION_TYPE_TWEND:
|
|
|
|
|
return &pParams->wend;
|
|
|
|
|
case FUNCTION_TYPE_TWDURATION:
|
|
|
|
|
return &pParams->wduration;
|
|
|
|
|
case FUNCTION_TYPE_TWROWNUM:
|
|
|
|
|
return &pParams->wrownum;
|
|
|
|
|
case FUNCTION_TYPE_TPREV_LOCALTIME:
|
|
|
|
|
return &pParams->prevLocalTime;
|
|
|
|
|
case FUNCTION_TYPE_TLOCALTIME:
|
|
|
|
|
return &pParams->triggerTime;
|
|
|
|
|
case FUNCTION_TYPE_TNEXT_LOCALTIME:
|
|
|
|
|
return &pParams->nextLocalTime;
|
|
|
|
|
case FUNCTION_TYPE_TGRPID:
|
|
|
|
|
return &pStreamRuntimeFuncInfo->groupId;
|
|
|
|
|
case FUNCTION_TYPE_PLACEHOLDER_COLUMN:
|
|
|
|
|
return pStreamRuntimeFuncInfo->pStreamPartColVals;
|
|
|
|
|
case FUNCTION_TYPE_PLACEHOLDER_TBNAME:
|
|
|
|
|
return pStreamRuntimeFuncInfo->pStreamPartColVals;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-30 01:59:15 +00:00
|
|
|
bool fmIsStreamPesudoColVal(int32_t funcId) {
|
|
|
|
|
return funcMgtBuiltins[funcId].type == FUNCTION_TYPE_PLACEHOLDER_COLUMN
|
|
|
|
|
|| funcMgtBuiltins[funcId].type == FUNCTION_TYPE_PLACEHOLDER_TBNAME;
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-16 06:42:16 +00:00
|
|
|
int32_t fmGetStreamPesudoFuncEnv(int32_t funcId, SNodeList* pParamNodes, SFuncExecEnv *pEnv) {
|
|
|
|
|
if (NULL == pParamNodes || pParamNodes->length < 1) {
|
|
|
|
|
uError("invalid stream pesudo func param list %p", pParamNodes);
|
|
|
|
|
return TSDB_CODE_INTERNAL_ERROR;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int32_t firstParamType = nodeType(nodesListGetNode(pParamNodes, 0));
|
|
|
|
|
if (QUERY_NODE_VALUE != firstParamType) {
|
|
|
|
|
uError("invalid stream pesudo func first param type %d", firstParamType);
|
|
|
|
|
return TSDB_CODE_INTERNAL_ERROR;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SValueNode* pResDesc = (SValueNode*)nodesListGetNode(pParamNodes, 0);
|
|
|
|
|
pEnv->calcMemSize = pResDesc->node.resType.bytes;
|
|
|
|
|
|
|
|
|
|
return TSDB_CODE_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-25 07:48:14 +00:00
|
|
|
|
2025-07-16 06:42:16 +00:00
|
|
|
int32_t fmSetStreamPseudoFuncParamVal(int32_t funcId, SNodeList* pParamNodes, const SStreamRuntimeFuncInfo* pStreamRuntimeInfo) {
|
|
|
|
|
if (!pStreamRuntimeInfo) {
|
|
|
|
|
uError("internal error, should have pVals for stream pseudo funcs");
|
|
|
|
|
return TSDB_CODE_INTERNAL_ERROR;
|
|
|
|
|
}
|
|
|
|
|
int32_t code = 0;
|
2025-09-25 07:48:14 +00:00
|
|
|
SArray *pVals1 = NULL;
|
2025-07-16 06:42:16 +00:00
|
|
|
SNode* pFirstParam = nodesListGetNode(pParamNodes, 0);
|
|
|
|
|
if (nodeType(pFirstParam) != QUERY_NODE_VALUE) {
|
|
|
|
|
uError("invalid param node type: %d for func: %d", nodeType(pFirstParam), funcId);
|
|
|
|
|
return TSDB_CODE_INTERNAL_ERROR;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int32_t t = funcMgtBuiltins[funcId].type;
|
2025-07-23 09:11:16 +00:00
|
|
|
uDebug("set stream pseudo func param val, functype: %d, pStreamRuntimeInfo: %p", t, pStreamRuntimeInfo);
|
2025-07-16 06:42:16 +00:00
|
|
|
if (FUNCTION_TYPE_TGRPID == t) {
|
|
|
|
|
SValue v = {0};
|
|
|
|
|
v.type = TSDB_DATA_TYPE_BIGINT;
|
|
|
|
|
v.val = *(int64_t*)fmGetStreamPesudoFuncVal(funcId, pStreamRuntimeInfo);
|
|
|
|
|
|
|
|
|
|
code = nodesSetValueNodeValue((SValueNode*)pFirstParam, VALUE_GET_DATUM(&v, pFirstParam->type));
|
|
|
|
|
if (code != 0) {
|
|
|
|
|
uError("failed to set value node value: %s", tstrerror(code));
|
|
|
|
|
return code;
|
|
|
|
|
}
|
|
|
|
|
} else if (FUNCTION_TYPE_PLACEHOLDER_COLUMN == t) {
|
|
|
|
|
SNode* pSecondParam = nodesListGetNode(pParamNodes, 1);
|
|
|
|
|
if (nodeType(pSecondParam) != QUERY_NODE_VALUE) {
|
|
|
|
|
uError("invalid param node type: %d for func: %d", nodeType(pSecondParam), funcId);
|
|
|
|
|
return TSDB_CODE_INTERNAL_ERROR;
|
|
|
|
|
}
|
|
|
|
|
SArray* pVal = (SArray*)fmGetStreamPesudoFuncVal(funcId, pStreamRuntimeInfo);
|
|
|
|
|
int32_t idx = ((SValueNode*)pSecondParam)->datum.i;
|
|
|
|
|
if (idx - 1 < 0 || idx - 1 >= taosArrayGetSize(pVal)) {
|
|
|
|
|
uError("invalid idx: %d for func: %d, should be in [1, %d]", idx, funcId, (int32_t)taosArrayGetSize(pVal));
|
|
|
|
|
return TSDB_CODE_INTERNAL_ERROR;
|
|
|
|
|
}
|
|
|
|
|
SStreamGroupValue* pValue = taosArrayGet(pVal, idx - 1);
|
|
|
|
|
if (pValue == NULL) {
|
|
|
|
|
uError("invalid idx: %d for func: %d, should be in [1, %d]", idx, funcId, (int32_t)taosArrayGetSize(pVal));
|
|
|
|
|
return TSDB_CODE_INTERNAL_ERROR;
|
|
|
|
|
}
|
|
|
|
|
if (!pValue->isNull){
|
|
|
|
|
if (pValue->data.type != ((SValueNode*)pFirstParam)->node.resType.type){
|
|
|
|
|
uError("invalid value type: %d for func: %d, should be: %d", pValue->data.type, funcId, ((SValueNode*)pFirstParam)->node.resType.type);
|
|
|
|
|
return TSDB_CODE_INTERNAL_ERROR;
|
|
|
|
|
}
|
|
|
|
|
if (IS_VAR_DATA_TYPE(((SValueNode*)pFirstParam)->node.resType.type)) {
|
2025-10-30 01:59:15 +00:00
|
|
|
char* tmp = taosMemoryCalloc(1, pValue->data.nData + VARSTR_HEADER_SIZE);
|
|
|
|
|
if (tmp == NULL) {
|
|
|
|
|
return TSDB_CODE_OUT_OF_MEMORY;
|
|
|
|
|
}
|
2025-07-16 06:42:16 +00:00
|
|
|
taosMemoryFree(((SValueNode*)pFirstParam)->datum.p);
|
2025-10-30 01:59:15 +00:00
|
|
|
((SValueNode*)pFirstParam)->datum.p = tmp;
|
2025-07-16 06:42:16 +00:00
|
|
|
memcpy(varDataVal(((SValueNode*)pFirstParam)->datum.p), pValue->data.pData, pValue->data.nData);
|
|
|
|
|
varDataLen(((SValueNode*)pFirstParam)->datum.p) = pValue->data.nData;
|
|
|
|
|
} else {
|
|
|
|
|
code = nodesSetValueNodeValue((SValueNode*)pFirstParam, VALUE_GET_DATUM(&pValue->data, pValue->data.type));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
((SValueNode*)pFirstParam)->isNull = pValue->isNull;
|
|
|
|
|
} else if (FUNCTION_TYPE_PLACEHOLDER_TBNAME == t) {
|
|
|
|
|
SArray* pVal = (SArray*)fmGetStreamPesudoFuncVal(funcId, pStreamRuntimeInfo);
|
|
|
|
|
for (int32_t i = 0; i < taosArrayGetSize(pVal); ++i) {
|
|
|
|
|
SStreamGroupValue* pValue = taosArrayGet(pVal, i);
|
|
|
|
|
if (pValue != NULL && pValue->isTbname) {
|
|
|
|
|
taosMemoryFreeClear(((SValueNode*)pFirstParam)->datum.p);
|
|
|
|
|
((SValueNode*)pFirstParam)->datum.p = taosMemoryCalloc(pValue->data.nData + VARSTR_HEADER_SIZE, 1);
|
|
|
|
|
if (NULL == ((SValueNode*)pFirstParam)->datum.p ) {
|
|
|
|
|
return terrno;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
(void)memcpy(varDataVal(((SValueNode*)pFirstParam)->datum.p), pValue->data.pData, pValue->data.nData);
|
|
|
|
|
varDataLen(((SValueNode*)pFirstParam)->datum.p) = pValue->data.nData;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else if (LIST_LENGTH(pParamNodes) == 1) {
|
|
|
|
|
// twstart, twend
|
|
|
|
|
const void* pVal = fmGetStreamPesudoFuncVal(funcId, pStreamRuntimeInfo);
|
|
|
|
|
if (!pVal) {
|
|
|
|
|
uError("failed to set stream pseudo func param val, NULL val for funcId: %d", funcId);
|
|
|
|
|
return TSDB_CODE_INTERNAL_ERROR;
|
|
|
|
|
}
|
|
|
|
|
code = nodesSetValueNodeValue((SValueNode*)pFirstParam, (void*)pVal);
|
|
|
|
|
if (code != 0) {
|
|
|
|
|
uError("failed to set value node value: %s", tstrerror(code));
|
|
|
|
|
return code;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2025-09-25 07:48:14 +00:00
|
|
|
uError("invalid placeholder function type: %d", t);
|
|
|
|
|
return TSDB_CODE_INTERNAL_ERROR;
|
2025-07-16 06:42:16 +00:00
|
|
|
}
|
2025-09-25 07:48:14 +00:00
|
|
|
|
2025-07-16 06:42:16 +00:00
|
|
|
return code;
|
|
|
|
|
}
|
2025-09-25 07:48:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|