提交 97f85ca1 编写于 作者: S shenglian zhou

expr tree add type, begin

上级 ccf1b20d
......@@ -1788,6 +1788,13 @@ static int32_t handleScalarExpr(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t e
}
}
// ret = exprTreeValidateTree(pNode);
// if (ret != TSDB_CODE_SUCCESS) {
// taosArrayDestroy(colList);
// tExprTreeDestroy(pNode, NULL);
// return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg2);
// }
SBufferWriter bw = tbufInitWriter(NULL, false);
TRY(0) {
......@@ -9624,12 +9631,12 @@ int32_t exprTreeFromSqlExpr(SSqlCmd* pCmd, tExprNode **pExpr, const tSqlExpr* pS
(*pExpr)->nodeType = TSQL_NODE_FUNC;
(*pExpr)->_func.functionId = pSqlExpr->functionId;
SArray* paramList = pSqlExpr->Expr.paramList;
size_t paramSize = taosArrayGetSize(paramList);
size_t paramSize = paramList ? taosArrayGetSize(paramList) : 0;
if (paramSize > 0) {
(*pExpr)->_func.numChildren = paramSize;
(*pExpr)->_func.pChildren = (tExprNode**)calloc(paramSize, sizeof(tExprNode*));
}
for (int i = 0; i < taosArrayGetSize(paramList); ++i) {
for (int32_t i = 0; i < paramSize; ++i) {
tSqlExprItem* param = taosArrayGet(paramList, i);
tSqlExpr* paramNode = param->pNode;
int32_t ret = exprTreeFromSqlExpr(pCmd, (*pExpr)->_func.pChildren+i, paramNode, pQueryInfo, pCols, uid);
......
......@@ -44,12 +44,15 @@ struct SSchema;
#define TSDB_FUNC_FLAG_SCALAR 0x4000
#define TSDB_FUNC_IS_SCALAR(id) ((((id) > 0)) && (((id) & TSDB_FUNC_FLAG_SCALAR) != 0))
#define TSDB_FUNC_SCALAR_INDEX(id) ((id) & ~TSDB_FUNC_FLAG_SCALAR)
///////////////////////////////////////////
// SCALAR FUNCTIONS
#define TSDB_FUNC_SCALAR_POW (TSDB_FUNC_FLAG_SCALAR | 0x0000)
#define TSDB_FUNC_SCALAR_LOG (TSDB_FUNC_FLAG_SCALAR | 0x0001)
#define TSDB_FUNC_SCALAR_MAX_NUM 2
#define TSDB_FUNC_SCALAR_CONCAT (TSDB_FUNC_FLAG_SCALAR | 0x0002)
#define TSDB_FUNC_SCALAR_MAX_NUM 3
#define TSDB_FUNC_SCALAR_NAME_MAX_LEN 16
typedef struct {
int16_t type;
int16_t bytes;
......@@ -126,6 +129,8 @@ typedef struct SExprTraverseSupp {
void tExprTreeDestroy(tExprNode *pNode, void (*fp)(void *));
int32_t exprTreeValidateTree(tExprNode *pExpr);
void exprTreeToBinary(SBufferWriter* bw, tExprNode* pExprTree);
tExprNode* exprTreeFromBinary(const void* data, size_t size);
tExprNode* exprdup(tExprNode* pTree);
......
......@@ -28,6 +28,96 @@
#include "texpr.h"
#include "tarithoperator.h"
int32_t exprTreeValidateFunctionNode(tExprNode *pExpr) {
int32_t code = TSDB_CODE_SUCCESS;
//TODO: check childs for every function
switch (pExpr->_func.functionId) {
case TSDB_FUNC_SCALAR_POW:
case TSDB_FUNC_SCALAR_LOG: {
if (pExpr->_func.numChildren != 2) {
return TSDB_CODE_TSC_INVALID_OPERATION;
}
tExprNode *child1 = pExpr->_func.pChildren[0];
tExprNode *child2 = pExpr->_func.pChildren[1];
if ((child2->nodeType == TSQL_NODE_VALUE && !IS_NUMERIC_TYPE(child2->pVal->nType)) ||
!IS_NUMERIC_TYPE(child2->resultType)) {
return TSDB_CODE_TSC_INVALID_OPERATION;
}
if (!IS_NUMERIC_TYPE(child1->resultType)) {
return TSDB_CODE_TSC_INVALID_OPERATION;
}
pExpr->resultType = TSDB_DATA_TYPE_DOUBLE;
pExpr->resultBytes = tDataTypes[TSDB_DATA_TYPE_DOUBLE].bytes;
break;
}
case TSDB_FUNC_SCALAR_CONCAT: {
}
default:
break;
}
return code;
}
int32_t exprTreeValidateExprNode(tExprNode *pExpr) {
//TODO: modify. keep existing behavior
if (pExpr->_node.optr == TSDB_BINARY_OP_ADD || pExpr->_node.optr == TSDB_BINARY_OP_SUBTRACT ||
pExpr->_node.optr == TSDB_BINARY_OP_MULTIPLY || pExpr->_node.optr == TSDB_BINARY_OP_DIVIDE ||
pExpr->_node.optr == TSDB_BINARY_OP_REMAINDER) {
pExpr->resultType = TSDB_DATA_TYPE_DOUBLE;
pExpr->resultBytes = tDataTypes[TSDB_DATA_TYPE_DOUBLE].bytes;
return TSDB_CODE_SUCCESS;
} else {
return TSDB_CODE_SUCCESS;
}
}
int32_t exprTreeValidateTree(tExprNode *pExpr) {
int32_t code = TSDB_CODE_SUCCESS;
if (pExpr == NULL) {
return TSDB_CODE_SUCCESS;
}
if (pExpr->nodeType == TSQL_NODE_VALUE) {
pExpr->resultType = -1;
pExpr->resultBytes = -1;
} else if (pExpr->nodeType == TSQL_NODE_COL) {
pExpr->resultType = pExpr->pSchema->type;
if (pExpr->pSchema->colId != TSDB_TBNAME_COLUMN_INDEX) {
pExpr->resultBytes = pExpr->pSchema->bytes;
} else {
pExpr->resultBytes = tGetTbnameColumnSchema()->bytes;
}
} else if (pExpr->nodeType == TSQL_NODE_EXPR) {
code = exprTreeValidateTree(pExpr->_node.pLeft);
if (code != TSDB_CODE_SUCCESS) {
return code;
}
code = exprTreeValidateTree(pExpr->_node.pRight);
if (code != TSDB_CODE_SUCCESS) {
return code;
}
code = exprTreeValidateExprNode(pExpr);
if (code != TSDB_CODE_SUCCESS) {
return code;
}
} else if (pExpr->nodeType == TSQL_NODE_FUNC) {
for (int32_t i = 0; i < pExpr->_func.numChildren; ++i) {
code = exprTreeValidateTree(pExpr->_func.pChildren[i]);
if (code != TSDB_CODE_SUCCESS) {
return code;
}
}
code = exprTreeValidateFunctionNode(pExpr);
if (code != TSDB_CODE_SUCCESS) {
return code;
}
}
return TSDB_CODE_SUCCESS;
}
static uint8_t UNUSED_FUNC isQueryOnPrimaryKey(const char *primaryColumnName, const tExprNode *pLeft, const tExprNode *pRight) {
if (pLeft->nodeType == TSQL_NODE_COL) {
// if left node is the primary column,return true
......@@ -788,6 +878,9 @@ void vectorLog(int16_t functionId, tExprOperandInfo* pInputs, uint8_t numInputs,
}
}
void vectorConcat(int16_t functionId, tExprOperandInfo* pInputs, uint8_t numInputs, tExprOperandInfo* pOutput, int32_t order) {
}
_expr_scalar_function_t getExprScalarFunction(uint16_t funcId) {
assert(TSDB_FUNC_IS_SCALAR(funcId));
......@@ -807,4 +900,9 @@ tScalarFunctionInfo aScalarFunctions[] = {
"log",
vectorLog
},
{
TSDB_FUNC_SCALAR_CONCAT,
"concat",
vectorConcat
},
};
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册