提交 78445fdf 编写于 作者: S shenglian zhou

(query):function lower upper ltrim rtrim substr

上级 03cd2695
......@@ -65,7 +65,12 @@ struct SSchema;
#define TSDB_FUNC_SCALAR_CONCAT_WS (TSDB_FUNC_FLAG_SCALAR | 0x000F)
#define TSDB_FUNC_SCALAR_CHAR_LENGTH (TSDB_FUNC_FLAG_SCALAR | 0x0010)
#define TSDB_FUNC_SCALAR_CAST (TSDB_FUNC_FLAG_SCALAR | 0x0011)
#define TSDB_FUNC_SCALAR_MAX_NUM 18
#define TSDB_FUNC_SCALAR_LOWER (TSDB_FUNC_FLAG_SCALAR | 0x0012)
#define TSDB_FUNC_SCALAR_UPPER (TSDB_FUNC_FLAG_SCALAR | 0x0013)
#define TSDB_FUNC_SCALAR_LTRIM (TSDB_FUNC_FLAG_SCALAR | 0x0014)
#define TSDB_FUNC_SCALAR_RTRIM (TSDB_FUNC_FLAG_SCALAR | 0x0015)
#define TSDB_FUNC_SCALAR_SUBSTR (TSDB_FUNC_FLAG_SCALAR | 0x0016)
#define TSDB_FUNC_SCALAR_MAX_NUM 23
#define TSDB_FUNC_SCALAR_NAME_MAX_LEN 16
......
......@@ -33,6 +33,8 @@ static int32_t exprValidateMathNode(tExprNode *pExpr);
static int32_t exprValidateStringConcatNode(tExprNode *pExpr);
static int32_t exprValidateStringConcatWsNode(tExprNode *pExpr);
static int32_t exprValidateStringLengthNode(tExprNode *pExpr);
static int32_t exprValidateStringLowerUpperTrimNode(char* msgBuf, tExprNode *pExpr);
static int32_t exprValidateStringSubstrNode(char* msgBuf, tExprNode *pExpr);
static int32_t exprValidateCastNode(char* msgbuf, tExprNode *pExpr);
static int32_t exprInvalidOperationMsg(char *msgbuf, const char *msg) {
......@@ -77,6 +79,15 @@ int32_t exprTreeValidateFunctionNode(char* msgbuf, tExprNode *pExpr) {
case TSDB_FUNC_SCALAR_CONCAT_WS: {
return exprValidateStringConcatWsNode(pExpr);
}
case TSDB_FUNC_SCALAR_LOWER:
case TSDB_FUNC_SCALAR_UPPER:
case TSDB_FUNC_SCALAR_LTRIM:
case TSDB_FUNC_SCALAR_RTRIM: {
return exprValidateStringLowerUpperTrimNode(msgbuf, pExpr);
}
case TSDB_FUNC_SCALAR_SUBSTR: {
return exprValidateStringSubstrNode(msgbuf, pExpr);
}
default:
break;
......@@ -1042,6 +1053,58 @@ int32_t exprValidateStringLengthNode(tExprNode *pExpr) {
return TSDB_CODE_SUCCESS;
}
int32_t exprValidateStringLowerUpperTrimNode(char* msgBuf, tExprNode *pExpr) {
if (pExpr->_func.numChildren != 1) {
return TSDB_CODE_TSC_INVALID_OPERATION;
}
tExprNode* child1 = pExpr->_func.pChildren[0];
if (child1->nodeType == TSQL_NODE_VALUE) {
child1->resultType = (int16_t)child1->pVal->nType;
child1->resultBytes = (int16_t)(child1->pVal->nLen + VARSTR_HEADER_SIZE);
}
if (!IS_VAR_DATA_TYPE(child1->resultType)) {
return TSDB_CODE_TSC_INVALID_OPERATION;
}
pExpr->resultType = child1->resultType;
pExpr->resultBytes = child1->resultBytes;
return TSDB_CODE_SUCCESS;
}
int32_t exprValidateStringSubstrNode(char* msgBuf, tExprNode *pExpr) {
if (pExpr->_func.numChildren != 2 || pExpr->_func.numChildren != 3) {
return TSDB_CODE_TSC_INVALID_OPERATION;
}
tExprNode* child1 = pExpr->_func.pChildren[0];
if (child1->nodeType == TSQL_NODE_VALUE) {
child1->resultType = (int16_t)child1->pVal->nType;
child1->resultBytes = (int16_t)(child1->pVal->nLen + VARSTR_HEADER_SIZE);
}
if (!IS_VAR_DATA_TYPE(child1->resultType)) {
return TSDB_CODE_TSC_INVALID_OPERATION;
}
tExprNode* pos = pExpr->_func.pChildren[1];
tExprNode* length = (pExpr->_func.numChildren == 3) ? pExpr->_func.pChildren[2] : NULL;
if (!IS_NUMERIC_TYPE(pos->resultType) ||
(length != NULL && !IS_NUMERIC_TYPE(length->resultType))) {
return TSDB_CODE_TSC_INVALID_OPERATION;
}
pExpr->resultType = child1->resultType;
pExpr->resultBytes = child1->resultBytes;
return TSDB_CODE_SUCCESS;
}
int32_t exprValidateCastNode(char* msgbuf, tExprNode *pExpr) {
const char* msg1 = "invalid param num for cast function";
const char* msg2 = "the second param should be a valid type name for cast function";
......@@ -1409,6 +1472,16 @@ void vectorCharLength(int16_t functionId, tExprOperandInfo *pInputs, int32_t num
}
}
void vectorLowerUpperTrimFunc(int16_t functionId, tExprOperandInfo *pInputs, int32_t numInputs, tExprOperandInfo* pOutput, int32_t order) {
assert(numInputs == 1);
assert(pInputs[0].numOfRows == 1 || pInputs[0].numOfRows == pOutput->numOfRows);
}
void vectorSubstrFunc(int16_t functionId, tExprOperandInfo *pInputs, int32_t numInputs, tExprOperandInfo* pOutput, int32_t order) {
}
void vectorMathFunc(int16_t functionId, tExprOperandInfo *pInputs, int32_t numInputs, tExprOperandInfo* pOutput, int32_t order) {
for (int i = 0; i < numInputs; ++i) {
assert(pInputs[i].numOfRows == 1 || pInputs[i].numOfRows == pOutput->numOfRows);
......@@ -1724,4 +1797,30 @@ tScalarFunctionInfo aScalarFunctions[] = {
"cast",
vectorMathFunc
},
{
TSDB_FUNC_SCALAR_LOWER,
"lower",
vectorLowerUpperTrimFunc
},
{
TSDB_FUNC_SCALAR_UPPER,
"upper",
vectorLowerUpperTrimFunc
},
{
TSDB_FUNC_SCALAR_LTRIM,
"ltrim",
vectorLowerUpperTrimFunc
},
{
TSDB_FUNC_SCALAR_RTRIM,
"rtrim",
vectorLowerUpperTrimFunc
},
{
TSDB_FUNC_SCALAR_SUBSTR,
"substr",
vectorSubstrFunc
},
};
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册