提交 c5d972fa 编写于 作者: S shenglian zhou

begin to add more math functions

上级 27c94691
...@@ -57,19 +57,20 @@ typedef struct { ...@@ -57,19 +57,20 @@ typedef struct {
char* data; char* data;
} tExprOperandInfo; } tExprOperandInfo;
typedef void (*_expr_scalar_function_t)(int16_t functionId, tExprOperandInfo* pInputs, uint8_t numInputs, tExprOperandInfo* pOutput, int32_t order);
typedef void (*_expr_scalar_function_t)(tExprOperandInfo* pInputs, uint8_t numInputs, tExprOperandInfo* pOutput, int32_t order);
_expr_scalar_function_t getExprScalarFunction(uint16_t scalar); _expr_scalar_function_t getExprScalarFunction(uint16_t scalar);
typedef struct tScalarFunctionInfo{ typedef struct tScalarFunctionInfo{
int16_t functionId; // scalar function id & ~TSDB_FUNC_FLAG_SCALAR == index int16_t functionId; // scalar function id & ~TSDB_FUNC_FLAG_SCALAR == index
char name[TSDB_FUNC_SCALAR_NAME_MAX_LEN]; char name[TSDB_FUNC_SCALAR_NAME_MAX_LEN];
_expr_scalar_function_t scalarFunc;
} tScalarFunctionInfo; } tScalarFunctionInfo;
/* global scalar sql functions array */ /* global scalar sql functions array */
extern struct tScalarFunctionInfo aScalarFunctions[TSDB_FUNC_SCALAR_MAX_NUM]; extern struct tScalarFunctionInfo aScalarFunctions[TSDB_FUNC_SCALAR_MAX_NUM];
typedef bool (*__result_filter_fn_t)(const void *, void *); typedef bool (*__result_filter_fn_t)(const void *, void *);
typedef void (*__do_filter_suppl_fn_t)(void *, void *); typedef void (*__do_filter_suppl_fn_t)(void *, void *);
......
...@@ -265,7 +265,7 @@ void exprTreeFunctionNodeTraverse(tExprNode *pExpr, int32_t numOfRows, char *pOu ...@@ -265,7 +265,7 @@ void exprTreeFunctionNodeTraverse(tExprNode *pExpr, int32_t numOfRows, char *pOu
output.type = TSDB_DATA_TYPE_DOUBLE; output.type = TSDB_DATA_TYPE_DOUBLE;
output.bytes = tDataTypes[TSDB_DATA_TYPE_DOUBLE].bytes; 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) { for (int i = 0; i < numChildren; ++i) {
tfree(pChildrenOutput[i]); tfree(pChildrenOutput[i]);
...@@ -744,7 +744,7 @@ tExprNode* exprdup(tExprNode* pNode) { ...@@ -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(numInputs == 2);
assert(pInputs[1].numOfRows == 1 && pInputs[0].numOfRows >= 1); assert(pInputs[1].numOfRows == 1 && pInputs[0].numOfRows >= 1);
int numOfRows = pInputs[0].numOfRows; int numOfRows = pInputs[0].numOfRows;
...@@ -766,7 +766,7 @@ void vectorPow(tExprOperandInfo* pInputs, uint8_t numInputs, tExprOperandInfo* p ...@@ -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(numInputs == 2);
assert(pInputs[1].numOfRows == 1 && pInputs[0].numOfRows >= 1); assert(pInputs[1].numOfRows == 1 && pInputs[0].numOfRows >= 1);
int numOfRows = pInputs[0].numOfRows; int numOfRows = pInputs[0].numOfRows;
...@@ -789,25 +789,22 @@ void vectorLog(tExprOperandInfo* pInputs, uint8_t numInputs, tExprOperandInfo* p ...@@ -789,25 +789,22 @@ void vectorLog(tExprOperandInfo* pInputs, uint8_t numInputs, tExprOperandInfo* p
} }
_expr_scalar_function_t getExprScalarFunction(uint16_t scalarFunc) { _expr_scalar_function_t getExprScalarFunction(uint16_t funcId) {
switch (scalarFunc) { assert(TSDB_FUNC_IS_SCALAR(funcId));
case TSDB_FUNC_SCALAR_POW: int16_t scalaIdx = TSDB_FUNC_SCALAR_INDEX(funcId);
return vectorPow; assert(scalaIdx>=0 && scalaIdx <= TSDB_FUNC_SCALAR_MAX_NUM);
case TSDB_FUNC_SCALAR_LOG: return aScalarFunctions[scalaIdx].scalarFunc;
return vectorLog;
default:
assert(0);
return NULL;
}
} }
tScalarFunctionInfo aScalarFunctions[] = { tScalarFunctionInfo aScalarFunctions[] = {
{ {
TSDB_FUNC_SCALAR_POW, TSDB_FUNC_SCALAR_POW,
"pow" "pow",
vectorPow
}, },
{ {
TSDB_FUNC_SCALAR_LOG, TSDB_FUNC_SCALAR_LOG,
"log" "log",
vectorLog
}, },
}; };
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册