From c5d972fa3361be8f1aab318c71ce86310dbba242 Mon Sep 17 00:00:00 2001 From: shenglian zhou Date: Tue, 2 Nov 2021 16:42:15 +0800 Subject: [PATCH] begin to add more math functions --- src/common/inc/texpr.h | 7 ++++--- src/common/src/texpr.c | 27 ++++++++++++--------------- 2 files changed, 16 insertions(+), 18 deletions(-) diff --git a/src/common/inc/texpr.h b/src/common/inc/texpr.h index 8628cbf777..58dcbf1404 100644 --- a/src/common/inc/texpr.h +++ b/src/common/inc/texpr.h @@ -57,19 +57,20 @@ typedef struct { char* data; } tExprOperandInfo; - -typedef void (*_expr_scalar_function_t)(tExprOperandInfo* pInputs, uint8_t numInputs, tExprOperandInfo* pOutput, int32_t order); +typedef void (*_expr_scalar_function_t)(int16_t functionId, tExprOperandInfo* pInputs, uint8_t numInputs, tExprOperandInfo* pOutput, int32_t order); _expr_scalar_function_t getExprScalarFunction(uint16_t scalar); typedef struct tScalarFunctionInfo{ int16_t functionId; // scalar function id & ~TSDB_FUNC_FLAG_SCALAR == index char name[TSDB_FUNC_SCALAR_NAME_MAX_LEN]; - + _expr_scalar_function_t scalarFunc; } tScalarFunctionInfo; /* global scalar sql functions array */ extern struct tScalarFunctionInfo aScalarFunctions[TSDB_FUNC_SCALAR_MAX_NUM]; + + typedef bool (*__result_filter_fn_t)(const void *, void *); typedef void (*__do_filter_suppl_fn_t)(void *, void *); diff --git a/src/common/src/texpr.c b/src/common/src/texpr.c index 0c477761e0..80b032f3e1 100644 --- a/src/common/src/texpr.c +++ b/src/common/src/texpr.c @@ -265,7 +265,7 @@ void exprTreeFunctionNodeTraverse(tExprNode *pExpr, int32_t numOfRows, char *pOu output.type = TSDB_DATA_TYPE_DOUBLE; output.bytes = tDataTypes[TSDB_DATA_TYPE_DOUBLE].bytes; - scalarFn(pInputs, numChildren, &output, order); + scalarFn(pExpr->_func.functionId, pInputs, numChildren, &output, order); for (int i = 0; i < numChildren; ++i) { tfree(pChildrenOutput[i]); @@ -744,7 +744,7 @@ tExprNode* exprdup(tExprNode* pNode) { } -void vectorPow(tExprOperandInfo* pInputs, uint8_t numInputs, tExprOperandInfo* pOutput, int32_t order) { +void vectorPow(int16_t functionId, tExprOperandInfo* pInputs, uint8_t numInputs, tExprOperandInfo* pOutput, int32_t order) { assert(numInputs == 2); assert(pInputs[1].numOfRows == 1 && pInputs[0].numOfRows >= 1); int numOfRows = pInputs[0].numOfRows; @@ -766,7 +766,7 @@ void vectorPow(tExprOperandInfo* pInputs, uint8_t numInputs, tExprOperandInfo* p } } -void vectorLog(tExprOperandInfo* pInputs, uint8_t numInputs, tExprOperandInfo* pOutput, int32_t order) { +void vectorLog(int16_t functionId, tExprOperandInfo* pInputs, uint8_t numInputs, tExprOperandInfo* pOutput, int32_t order) { assert(numInputs == 2); assert(pInputs[1].numOfRows == 1 && pInputs[0].numOfRows >= 1); int numOfRows = pInputs[0].numOfRows; @@ -789,25 +789,22 @@ void vectorLog(tExprOperandInfo* pInputs, uint8_t numInputs, tExprOperandInfo* p } -_expr_scalar_function_t getExprScalarFunction(uint16_t scalarFunc) { - switch (scalarFunc) { - case TSDB_FUNC_SCALAR_POW: - return vectorPow; - case TSDB_FUNC_SCALAR_LOG: - return vectorLog; - default: - assert(0); - return NULL; - } +_expr_scalar_function_t getExprScalarFunction(uint16_t funcId) { + assert(TSDB_FUNC_IS_SCALAR(funcId)); + int16_t scalaIdx = TSDB_FUNC_SCALAR_INDEX(funcId); + assert(scalaIdx>=0 && scalaIdx <= TSDB_FUNC_SCALAR_MAX_NUM); + return aScalarFunctions[scalaIdx].scalarFunc; } tScalarFunctionInfo aScalarFunctions[] = { { TSDB_FUNC_SCALAR_POW, - "pow" + "pow", + vectorPow }, { TSDB_FUNC_SCALAR_LOG, - "log" + "log", + vectorLog }, }; \ No newline at end of file -- GitLab