enh:[TD-32459] Abstract function properties into a struct.
This commit is contained in:
parent
fed6b4fada
commit
c26ab17f19
|
@ -917,6 +917,11 @@ int32_t taosGetErrSize();
|
||||||
#define TSDB_CODE_FUNC_INVALID_RES_LENGTH TAOS_DEF_ERROR_CODE(0, 0x280E)
|
#define TSDB_CODE_FUNC_INVALID_RES_LENGTH TAOS_DEF_ERROR_CODE(0, 0x280E)
|
||||||
#define TSDB_CODE_FUNC_HISTOGRAM_ERROR TAOS_DEF_ERROR_CODE(0, 0x280F)
|
#define TSDB_CODE_FUNC_HISTOGRAM_ERROR TAOS_DEF_ERROR_CODE(0, 0x280F)
|
||||||
#define TSDB_CODE_FUNC_PERCENTILE_ERROR TAOS_DEF_ERROR_CODE(0, 0x2810)
|
#define TSDB_CODE_FUNC_PERCENTILE_ERROR TAOS_DEF_ERROR_CODE(0, 0x2810)
|
||||||
|
#define TSDB_CODE_FUNC_FUNTION_PARA_RANGE TAOS_DEF_ERROR_CODE(0, 0x2811)
|
||||||
|
#define TSDB_CODE_FUNC_FUNTION_PARA_PRIMTS TAOS_DEF_ERROR_CODE(0, 0x2812)
|
||||||
|
#define TSDB_CODE_FUNC_FUNTION_PARA_PK TAOS_DEF_ERROR_CODE(0, 0x2813)
|
||||||
|
#define TSDB_CODE_FUNC_FUNTION_PARA_HAS_COL TAOS_DEF_ERROR_CODE(0, 0x2814)
|
||||||
|
#define TSDB_CODE_FUNC_FUNCTION_HISTO_TYPE TAOS_DEF_ERROR_CODE(0, 0x2815)
|
||||||
|
|
||||||
|
|
||||||
//udf
|
//udf
|
||||||
|
|
|
@ -22,16 +22,54 @@ extern "C" {
|
||||||
|
|
||||||
#include "functionMgtInt.h"
|
#include "functionMgtInt.h"
|
||||||
|
|
||||||
|
struct SFunctionParaInfo;
|
||||||
|
|
||||||
typedef int32_t (*FTranslateFunc)(SFunctionNode* pFunc, char* pErrBuf, int32_t len);
|
typedef int32_t (*FTranslateFunc)(SFunctionNode* pFunc, char* pErrBuf, int32_t len);
|
||||||
typedef EFuncDataRequired (*FFuncDataRequired)(SFunctionNode* pFunc, STimeWindow* pTimeWindow);
|
typedef EFuncDataRequired (*FFuncDataRequired)(SFunctionNode* pFunc, STimeWindow* pTimeWindow);
|
||||||
typedef int32_t (*FCreateMergeFuncParameters)(SNodeList* pRawParameters, SNode* pPartialRes, SNodeList** pParameters);
|
typedef int32_t (*FCreateMergeFuncParameters)(SNodeList* pRawParameters, SNode* pPartialRes, SNodeList** pParameters);
|
||||||
typedef EFuncDataRequired (*FFuncDynDataRequired)(void* pRes, SDataBlockInfo* pBlocInfo);
|
typedef EFuncDataRequired (*FFuncDynDataRequired)(void* pRes, SDataBlockInfo* pBlocInfo);
|
||||||
typedef EFuncReturnRows (*FEstimateReturnRows)(SFunctionNode* pFunc);
|
typedef EFuncReturnRows (*FEstimateReturnRows)(SFunctionNode* pFunc);
|
||||||
|
|
||||||
|
#define MAX_FUNC_PARA_NUM 16
|
||||||
|
|
||||||
|
typedef struct SParamRange {
|
||||||
|
double dMinVal;
|
||||||
|
double dMaxVal;
|
||||||
|
} SParamRange;
|
||||||
|
|
||||||
|
typedef struct SParamInfo {
|
||||||
|
bool isLastParam;
|
||||||
|
int8_t startParam;
|
||||||
|
int8_t endParam;
|
||||||
|
uint64_t validDataType;
|
||||||
|
uint64_t validNodeType;
|
||||||
|
bool hasRange;
|
||||||
|
bool isTs; // used for input parameter
|
||||||
|
bool isPK; // used for input parameter
|
||||||
|
bool isFixedValue; // used for input parameter
|
||||||
|
bool hasColumn; // used for input parameter, parameter must contain columns
|
||||||
|
bool isFirstLast; // special check for first and last
|
||||||
|
bool isTimeUnit; // used for input parameter, need check whether time unit is valid
|
||||||
|
bool isHistogramBin; // used for input parameter, need check whether histogram bin is valid
|
||||||
|
uint8_t fixedValueSize;
|
||||||
|
char fixedStrValue[MAX_FUNC_PARA_NUM][16]; // used for input parameter
|
||||||
|
int32_t fixedNumValue[MAX_FUNC_PARA_NUM]; // used for input parameter
|
||||||
|
SParamRange range;
|
||||||
|
} SParamInfo;
|
||||||
|
|
||||||
|
typedef struct SFunctionParaInfo {
|
||||||
|
int8_t minParamNum;
|
||||||
|
int8_t maxParamNum;
|
||||||
|
uint8_t paramInfoPattern;
|
||||||
|
SParamInfo inputParaInfo[MAX_FUNC_PARA_NUM][MAX_FUNC_PARA_NUM];
|
||||||
|
SParamInfo outputParaInfo;
|
||||||
|
} SFunctionParaInfo;
|
||||||
|
|
||||||
typedef struct SBuiltinFuncDefinition {
|
typedef struct SBuiltinFuncDefinition {
|
||||||
const char* name;
|
const char* name;
|
||||||
EFunctionType type;
|
EFunctionType type;
|
||||||
uint64_t classification;
|
uint64_t classification;
|
||||||
|
SFunctionParaInfo parameters;
|
||||||
FTranslateFunc translateFunc;
|
FTranslateFunc translateFunc;
|
||||||
FFuncDataRequired dataRequiredFunc;
|
FFuncDataRequired dataRequiredFunc;
|
||||||
FFuncDynDataRequired dynDataRequiredFunc;
|
FFuncDynDataRequired dynDataRequiredFunc;
|
||||||
|
|
|
@ -64,6 +64,71 @@ extern "C" {
|
||||||
|
|
||||||
#define FUNC_UDF_ID_START 5000
|
#define FUNC_UDF_ID_START 5000
|
||||||
|
|
||||||
|
#define FUNC_MGT_FUNC_PARAM_SUPPORT_TYPE(n) ((uint64_t)1 << n)
|
||||||
|
#define FUNC_PARAM_SUPPORT_ALL_TYPE FUNC_MGT_FUNC_PARAM_SUPPORT_TYPE(0)
|
||||||
|
#define FUNC_PARAM_SUPPORT_NUMERIC_TYPE FUNC_MGT_FUNC_PARAM_SUPPORT_TYPE(1)
|
||||||
|
#define FUNC_PARAM_SUPPORT_VAR_TYPE FUNC_MGT_FUNC_PARAM_SUPPORT_TYPE(2)
|
||||||
|
#define FUNC_PARAM_SUPPORT_STRING_TYPE FUNC_MGT_FUNC_PARAM_SUPPORT_TYPE(3)
|
||||||
|
#define FUNC_PARAM_SUPPORT_BOOL_TYPE FUNC_MGT_FUNC_PARAM_SUPPORT_TYPE(4)
|
||||||
|
#define FUNC_PARAM_SUPPORT_TINYINT_TYPE FUNC_MGT_FUNC_PARAM_SUPPORT_TYPE(5)
|
||||||
|
#define FUNC_PARAM_SUPPORT_SMALLINT_TYPE FUNC_MGT_FUNC_PARAM_SUPPORT_TYPE(6)
|
||||||
|
#define FUNC_PARAM_SUPPORT_INT_TYPE FUNC_MGT_FUNC_PARAM_SUPPORT_TYPE(7)
|
||||||
|
#define FUNC_PARAM_SUPPORT_BIGINT_TYPE FUNC_MGT_FUNC_PARAM_SUPPORT_TYPE(8)
|
||||||
|
#define FUNC_PARAM_SUPPORT_FLOAT_TYPE FUNC_MGT_FUNC_PARAM_SUPPORT_TYPE(9)
|
||||||
|
#define FUNC_PARAM_SUPPORT_DOUBLE_TYPE FUNC_MGT_FUNC_PARAM_SUPPORT_TYPE(10)
|
||||||
|
#define FUNC_PARAM_SUPPORT_VARCHAR_TYPE FUNC_MGT_FUNC_PARAM_SUPPORT_TYPE(11)
|
||||||
|
#define FUNC_PARAM_SUPPORT_TIMESTAMP_TYPE FUNC_MGT_FUNC_PARAM_SUPPORT_TYPE(12)
|
||||||
|
#define FUNC_PARAM_SUPPORT_NCHAR_TYPE FUNC_MGT_FUNC_PARAM_SUPPORT_TYPE(13)
|
||||||
|
#define FUNC_PARAM_SUPPORT_UTINYINT_TYPE FUNC_MGT_FUNC_PARAM_SUPPORT_TYPE(14)
|
||||||
|
#define FUNC_PARAM_SUPPORT_USMALLINT_TYPE FUNC_MGT_FUNC_PARAM_SUPPORT_TYPE(15)
|
||||||
|
#define FUNC_PARAM_SUPPORT_UINT_TYPE FUNC_MGT_FUNC_PARAM_SUPPORT_TYPE(16)
|
||||||
|
#define FUNC_PARAM_SUPPORT_UBIGINT_TYPE FUNC_MGT_FUNC_PARAM_SUPPORT_TYPE(17)
|
||||||
|
#define FUNC_PARAM_SUPPORT_JSON_TYPE FUNC_MGT_FUNC_PARAM_SUPPORT_TYPE(18)
|
||||||
|
#define FUNC_PARAM_SUPPORT_VARB_TYPE FUNC_MGT_FUNC_PARAM_SUPPORT_TYPE(19)
|
||||||
|
#define FUNC_PARAM_SUPPORT_GEOMETRY_TYPE FUNC_MGT_FUNC_PARAM_SUPPORT_TYPE(20)
|
||||||
|
#define FUNC_PARAM_SUPPORT_INTEGER_TYPE FUNC_MGT_FUNC_PARAM_SUPPORT_TYPE(21)
|
||||||
|
#define FUNC_PARAM_SUPPORT_NULL_TYPE FUNC_MGT_FUNC_PARAM_SUPPORT_TYPE(22)
|
||||||
|
#define FUNC_PARAM_SUPPORT_UNIX_TS_TYPE FUNC_MGT_FUNC_PARAM_SUPPORT_TYPE(23)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#define FUNC_MGT_FUNC_PARAM_SUPPORT_NODE(n) ((uint64_t)1 << n)
|
||||||
|
#define FUNC_PARAM_SUPPORT_EXPR_NODE FUNC_MGT_FUNC_PARAM_SUPPORT_NODE(0)
|
||||||
|
#define FUNC_PARAM_SUPPORT_VALUE_NODE FUNC_MGT_FUNC_PARAM_SUPPORT_NODE(1)
|
||||||
|
#define FUNC_PARAM_SUPPORT_OPERATOR_NODE FUNC_MGT_FUNC_PARAM_SUPPORT_NODE(2)
|
||||||
|
#define FUNC_PARAM_SUPPORT_FUNCTION_NODE FUNC_MGT_FUNC_PARAM_SUPPORT_NODE(3)
|
||||||
|
#define FUNC_PARAM_SUPPORT_LOGIC_CONDITION_NODE FUNC_MGT_FUNC_PARAM_SUPPORT_NODE(4)
|
||||||
|
#define FUNC_PARAM_SUPPORT_CASE_WHEN_NODE FUNC_MGT_FUNC_PARAM_SUPPORT_NODE(5)
|
||||||
|
#define FUNC_PARAM_SUPPORT_COLUMN_NODE FUNC_MGT_FUNC_PARAM_SUPPORT_NODE(6)
|
||||||
|
#define FUNC_PARAM_SUPPORT_NOT_VALUE_NODE FUNC_MGT_FUNC_PARAM_SUPPORT_NODE(7)
|
||||||
|
|
||||||
|
#define FUNC_PARAM_SUPPORT_NODE_MAX 7
|
||||||
|
|
||||||
|
#define FUNC_ERR_RET(c) \
|
||||||
|
do { \
|
||||||
|
int32_t _code = c; \
|
||||||
|
if (_code != TSDB_CODE_SUCCESS) { \
|
||||||
|
terrno = _code; \
|
||||||
|
return _code; \
|
||||||
|
} \
|
||||||
|
} while (0)
|
||||||
|
#define FUNC_RET(c) \
|
||||||
|
do { \
|
||||||
|
int32_t _code = c; \
|
||||||
|
if (_code != TSDB_CODE_SUCCESS) { \
|
||||||
|
terrno = _code; \
|
||||||
|
} \
|
||||||
|
return _code; \
|
||||||
|
} while (0)
|
||||||
|
#define FUNC_ERR_JRET(c) \
|
||||||
|
do { \
|
||||||
|
code = c; \
|
||||||
|
if (code != TSDB_CODE_SUCCESS) { \
|
||||||
|
terrno = code; \
|
||||||
|
goto _return; \
|
||||||
|
} \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -761,6 +761,11 @@ TAOS_DEFINE_ERROR(TSDB_CODE_FUNC_SETUP_ERROR, "Function set up fail
|
||||||
TAOS_DEFINE_ERROR(TSDB_CODE_FUNC_INVALID_RES_LENGTH, "Function result exceed max length")
|
TAOS_DEFINE_ERROR(TSDB_CODE_FUNC_INVALID_RES_LENGTH, "Function result exceed max length")
|
||||||
TAOS_DEFINE_ERROR(TSDB_CODE_FUNC_HISTOGRAM_ERROR, "Function failed to calculate histogram")
|
TAOS_DEFINE_ERROR(TSDB_CODE_FUNC_HISTOGRAM_ERROR, "Function failed to calculate histogram")
|
||||||
TAOS_DEFINE_ERROR(TSDB_CODE_FUNC_PERCENTILE_ERROR, "Function failed to calculate percentile")
|
TAOS_DEFINE_ERROR(TSDB_CODE_FUNC_PERCENTILE_ERROR, "Function failed to calculate percentile")
|
||||||
|
TAOS_DEFINE_ERROR(TSDB_CODE_FUNC_FUNTION_PARA_RANGE, "Invalid function para range")
|
||||||
|
TAOS_DEFINE_ERROR(TSDB_CODE_FUNC_FUNTION_PARA_PRIMTS, "Function parameter should be primary timestamp")
|
||||||
|
TAOS_DEFINE_ERROR(TSDB_CODE_FUNC_FUNTION_PARA_PK, "Function parameter should be primary key")
|
||||||
|
TAOS_DEFINE_ERROR(TSDB_CODE_FUNC_FUNTION_PARA_HAS_COL, "Function parameter should have column")
|
||||||
|
|
||||||
|
|
||||||
//udf
|
//udf
|
||||||
TAOS_DEFINE_ERROR(TSDB_CODE_UDF_STOPPING, "udf is stopping")
|
TAOS_DEFINE_ERROR(TSDB_CODE_UDF_STOPPING, "udf is stopping")
|
||||||
|
|
|
@ -296,7 +296,7 @@ class TDTestCase(TBase):
|
||||||
|
|
||||||
def test_error(self):
|
def test_error(self):
|
||||||
tdSql.error("select * from (select to_iso8601(ts, timezone()), timezone() from ts_4893.meters \
|
tdSql.error("select * from (select to_iso8601(ts, timezone()), timezone() from ts_4893.meters \
|
||||||
order by ts desc) limit 1000;", expectErrInfo="Not supported timzone format") # TS-5340
|
order by ts desc) limit 1000;", expectErrInfo="Invalid parameter data type : to_iso8601") # TS-5340
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
tdLog.debug(f"start to excute {__file__}")
|
tdLog.debug(f"start to excute {__file__}")
|
||||||
|
|
Loading…
Reference in New Issue