提交 57ed3359 编写于 作者: S shenglian zhou

Merge branch 'szhou/feature/npr-math-dev' into szhou/feature/support-math-functions

......@@ -66,7 +66,7 @@ int32_t exprTreeValidateFunctionNode(tExprNode *pExpr) {
int16_t prevResultType = TSDB_DATA_TYPE_NULL;
int16_t resultType = TSDB_DATA_TYPE_NULL;
bool resultTypeAlreadySet = false;
bool resultTypeDeduced = false;
for (int32_t i = 0; i < pExpr->_func.numChildren; ++i) {
tExprNode *child = pExpr->_func.pChildren[i];
if (child->nodeType != TSQL_NODE_VALUE) {
......@@ -74,32 +74,48 @@ int32_t exprTreeValidateFunctionNode(tExprNode *pExpr) {
if (!IS_VAR_DATA_TYPE(resultType)) {
return TSDB_CODE_TSC_INVALID_OPERATION;
}
if (!resultTypeAlreadySet) {
resultTypeAlreadySet = true;
if (!resultTypeDeduced) {
resultTypeDeduced = true;
} else {
if (resultType != prevResultType) {
return TSDB_CODE_TSC_INVALID_OPERATION;
}
}
prevResultType = child->resultType;
} else {
if (!IS_VAR_DATA_TYPE(child->resultType)) {
return TSDB_CODE_TSC_INVALID_OPERATION;
}
}
}
if (resultTypeAlreadySet) {
if (resultTypeDeduced) {
for (int32_t i = 0; i < pExpr->_func.numChildren; ++i) {
tExprNode *child = pExpr->_func.pChildren[i];
if (child->nodeType == TSQL_NODE_VALUE) {
if (!IS_VAR_DATA_TYPE(child->pVal->nType)) {
return TSDB_CODE_TSC_INVALID_OPERATION;
}
tVariantTypeSetType(child->pVal, (char)resultType);
char* payload = malloc(child->pVal->nLen * TSDB_NCHAR_SIZE + VARSTR_HEADER_SIZE);
tVariantDump(child->pVal, payload, resultType, true);
int16_t resultBytes = varDataTLen(payload);
free(payload);
child->resultType = resultType;
child->resultBytes = (int16_t)(child->pVal->nLen + VARSTR_HEADER_SIZE);
child->resultBytes = (int16_t)(resultBytes);
}
}
} else {
for (int32_t i = 0; i < pExpr->_func.numChildren; ++i) {
tExprNode *child = pExpr->_func.pChildren[i];
assert(child->nodeType == TSQL_NODE_VALUE) ;
resultType = child->resultType;
for (int j = i+1; j < pExpr->_func.numChildren; ++j) {
if (pExpr->_func.pChildren[j]->resultType != resultType) {
return TSDB_CODE_TSC_INVALID_OPERATION;
}
}
}
}
pExpr->resultType = resultType;
int16_t resultBytes = 0;
......@@ -142,7 +158,6 @@ int32_t exprTreeValidateFunctionNode(tExprNode *pExpr) {
}
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) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册