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

char_length function implementation

上级 6d0c9211
......@@ -63,7 +63,8 @@ struct SSchema;
#define TSDB_FUNC_SCALAR_CONCAT (TSDB_FUNC_FLAG_SCALAR | 0x000D)
#define TSDB_FUNC_SCALAR_LENGTH (TSDB_FUNC_FLAG_SCALAR | 0x000E)
#define TSDB_FUNC_SCALAR_CONCAT_WS (TSDB_FUNC_FLAG_SCALAR | 0x000F)
#define TSDB_FUNC_SCALAR_MAX_NUM 16
#define TSDB_FUNC_SCALAR_CHAR_LENGTH (TSDB_FUNC_FLAG_SCALAR | 0x0011)
#define TSDB_FUNC_SCALAR_MAX_NUM 17
#define TSDB_FUNC_SCALAR_NAME_MAX_LEN 16
......
......@@ -55,7 +55,8 @@ int32_t exprTreeValidateFunctionNode(tExprNode *pExpr) {
case TSDB_FUNC_SCALAR_CONCAT: {
return exprValidateStringConcatNode(pExpr);
}
case TSDB_FUNC_SCALAR_LENGTH: {
case TSDB_FUNC_SCALAR_LENGTH:
case TSDB_FUNC_SCALAR_CHAR_LENGTH: {
return exprValidateStringLengthNode(pExpr);
}
case TSDB_FUNC_SCALAR_CONCAT_WS: {
......@@ -1206,6 +1207,7 @@ void vectorConcatWs(int16_t functionId, tExprOperandInfo* pInputs, int32_t numIn
void vectorLength(int16_t functionId, tExprOperandInfo *pInputs, int32_t numInputs, tExprOperandInfo* pOutput, int32_t order) {
assert(functionId == TSDB_FUNC_SCALAR_LENGTH && numInputs == 1 && order == TSDB_ORDER_ASC);
assert(IS_VAR_DATA_TYPE(pInputs[0].type));
char* data0 = NULL;
char* outputData = NULL;
......@@ -1226,6 +1228,33 @@ void vectorLength(int16_t functionId, tExprOperandInfo *pInputs, int32_t numInpu
}
}
void vectorCharLength(int16_t functionId, tExprOperandInfo *pInputs, int32_t numInputs, tExprOperandInfo* pOutput, int32_t order) {
assert(functionId == TSDB_FUNC_SCALAR_CHAR_LENGTH && numInputs == 1 && order == TSDB_ORDER_ASC);
assert(IS_VAR_DATA_TYPE(pInputs[0].type));
char* data0 = NULL;
char* outputData = NULL;
for (int32_t i = 0; i < pOutput->numOfRows; ++i) {
if (pInputs[0].numOfRows == 1) {
data0 = pInputs[0].data;
} else {
data0 = pInputs[0].data + i * pInputs[0].bytes;
}
outputData = pOutput->data + i * pOutput->bytes;
if (isNull(data0, pInputs[0].type)) {
setNull(outputData, pOutput->type, pOutput->bytes);
} else {
int16_t result = varDataLen(data0);
if (pInputs[0].type == TSDB_DATA_TYPE_BINARY) {
SET_TYPED_DATA(outputData, pOutput->type, result);
} else if (pInputs[0].type == TSDB_DATA_TYPE_NCHAR) {
SET_TYPED_DATA(outputData, pOutput->type, result/TSDB_NCHAR_SIZE);
}
}
}
}
void vectorMathFunc(int16_t functionId, tExprOperandInfo *pInputs, int32_t numInputs, tExprOperandInfo* pOutput, int32_t order) {
for (int i = 0; i < numInputs; ++i) {
......@@ -1527,5 +1556,10 @@ tScalarFunctionInfo aScalarFunctions[] = {
TSDB_FUNC_SCALAR_CONCAT_WS,
"concat_ws",
vectorConcatWs
},
{
TSDB_FUNC_SCALAR_CHAR_LENGTH,
"char_length",
vectorCharLength
}
};
......@@ -145,6 +145,13 @@ if $data00 != 8 then
return -1
endi
print sql select char_length(concat(c2, c3, c4, c5)) from $tb
sql select char_length(concat(c2, c3, c4, c5)) from $tb
print $data00
if $data00 != 8 then
return -1
endi
print sql select length(concat_ws('data',c2,c3,c4,c5)) from $tb
sql select length(concat_ws('data',c2,c3,c4,c5)) from $tb
print $data00
......@@ -152,6 +159,15 @@ print $data00
if $data00 != 20 then
return -1
endi
print sql select char_length(concat_ws('data',c2,c3,c4,c5)) from $tb
sql select char_length(concat_ws('data',c2,c3,c4,c5)) from $tb
print $data00
if $data00 != 20 then
return -1
endi
print sql select length(concat(c6, c7, c8, c9)) from $tb
sql select length(concat(c6, c7, c8, c9)) from $tb
print $data00
......@@ -159,6 +175,13 @@ if $data00 != 32 then
return -1
endi
print sql select char_length(concat(c6, c7, c8, c9)) from $tb
sql select char_length(concat(c6, c7, c8, c9)) from $tb
print $data00
if $data00 != 8 then
return -1
endi
print sql select length(concat_ws('data' ,c6,c7,c8,c9)) from $tb
sql select length(concat_ws('data' ,c6,c7,c8,c9)) from $tb
print $data00
......@@ -167,6 +190,13 @@ if $data00 != 80 then
return -1
endi
print sql select char_length(concat_ws('data', c6,c7,c8,c9)) from $tb
sql select char_length(concat_ws('data', c6, c7, c8, c9)) from $tb
print $data00
if $data00 != 20 then
return -1
endi
print sql_error select concat(c1, c2, c3, c4, c5) from $tb
sql_error select concat(c1, c2, c3, c4, c5) from $tb
print sql_error select concat_ws('data',c1,c2,c3,c4,c5) from $tb
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册