提交 6e0a6b85 编写于 作者: S shenglian zhou

add concat_ws and concat/length test case

上级 96d12323
......@@ -62,7 +62,8 @@ struct SSchema;
#define TSDB_FUNC_SCALAR_ROUND (TSDB_FUNC_FLAG_SCALAR | 0x000C)
#define TSDB_FUNC_SCALAR_CONCAT (TSDB_FUNC_FLAG_SCALAR | 0x000D)
#define TSDB_FUNC_SCALAR_LENGTH (TSDB_FUNC_FLAG_SCALAR | 0x000E)
#define TSDB_FUNC_SCALAR_MAX_NUM 15
#define TSDB_FUNC_SCALAR_CONCAT_WS (TSDB_FUNC_FLAG_SCALAR | 0x000F)
#define TSDB_FUNC_SCALAR_MAX_NUM 16
#define TSDB_FUNC_SCALAR_NAME_MAX_LEN 16
......
......@@ -30,6 +30,7 @@
static int32_t exprValidateMathNode(tExprNode *pExpr);
static int32_t exprValidateStringConcatNode(tExprNode *pExpr);
static int32_t exprValidateStringConcatWsNode(tExprNode *pExpr);
static int32_t exprValidateStringLengthNode(tExprNode *pExpr);
int32_t exprTreeValidateFunctionNode(tExprNode *pExpr) {
......@@ -57,6 +58,9 @@ int32_t exprTreeValidateFunctionNode(tExprNode *pExpr) {
case TSDB_FUNC_SCALAR_LENGTH: {
return exprValidateStringLengthNode(pExpr);
}
case TSDB_FUNC_SCALAR_CONCAT_WS: {
return exprValidateStringConcatWsNode(pExpr);
}
default:
break;
......@@ -871,7 +875,7 @@ tExprNode* exprdup(tExprNode* pNode) {
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// scalar functions
int32_t exprValidateStringConcatNode(tExprNode *pExpr) {
if (pExpr->_func.numChildren < 2) {
if (pExpr->_func.numChildren < 2 || pExpr->_func.numChildren > 8) {
return TSDB_CODE_TSC_INVALID_OPERATION;
}
......@@ -942,6 +946,82 @@ int32_t exprValidateStringConcatNode(tExprNode *pExpr) {
return TSDB_CODE_SUCCESS;
}
int32_t exprValidateStringConcatWsNode(tExprNode *pExpr) {
if (pExpr->_func.numChildren < 3 || pExpr->_func.numChildren > 9) {
return TSDB_CODE_TSC_INVALID_OPERATION;
}
int16_t prevResultType = TSDB_DATA_TYPE_NULL;
int16_t resultType = TSDB_DATA_TYPE_NULL;
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) {
resultType = child->resultType;
if (!IS_VAR_DATA_TYPE(resultType)) {
return TSDB_CODE_TSC_INVALID_OPERATION;
}
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 (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;
}
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)(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;
for (int32_t i = 1; i < pExpr->_func.numChildren; ++i) {
tExprNode *child = pExpr->_func.pChildren[i];
if (resultBytes <= resultBytes + child->resultBytes - VARSTR_HEADER_SIZE) {
resultBytes += child->resultBytes - VARSTR_HEADER_SIZE;
} else {
return TSDB_CODE_TSC_INVALID_OPERATION;
}
}
tExprNode* wsNode = pExpr->_func.pChildren[0];
int16_t wsResultBytes = wsNode->resultBytes - VARSTR_HEADER_SIZE;
resultBytes += wsResultBytes * (pExpr->_func.numChildren - 2);
pExpr->resultBytes = resultBytes + VARSTR_HEADER_SIZE;
return TSDB_CODE_SUCCESS;
}
int32_t exprValidateStringLengthNode(tExprNode *pExpr) {
if (pExpr->_func.numChildren != 1) {
return TSDB_CODE_TSC_INVALID_OPERATION;
......@@ -1080,6 +1160,50 @@ void vectorConcat(int16_t functionId, tExprOperandInfo* pInputs, int32_t numInpu
free(inputData);
}
void vectorConcatWs(int16_t functionId, tExprOperandInfo* pInputs, int32_t numInputs, tExprOperandInfo* pOutput, int32_t order) {
assert(functionId == TSDB_FUNC_SCALAR_CONCAT_WS && numInputs >=3 && order == TSDB_ORDER_ASC);
for (int i = 0; i < numInputs; ++i) {
assert(pInputs[i].numOfRows == 1 || pInputs[i].numOfRows == pOutput->numOfRows);
}
char* outputData = NULL;
char** inputData = calloc(numInputs, sizeof(char*));
for (int i = 0; i < pOutput->numOfRows; ++i) {
for (int j = 0; j < numInputs; ++j) {
if (pInputs[j].numOfRows == 1) {
inputData[j] = pInputs[j].data;
} else {
inputData[j] = pInputs[j].data + i * pInputs[j].bytes;
}
}
outputData = pOutput->data + i * pOutput->bytes;
bool hasNullInputs = false;
for (int j = 0; j < numInputs; ++j) {
if (isNull(inputData[j], pInputs[j].type)) {
hasNullInputs = true;
setNull(outputData, pOutput->type, pOutput->bytes);
}
}
if (!hasNullInputs) {
int16_t dataLen = 0;
for (int j = 1; j < numInputs; ++j) {
memcpy(((char*)varDataVal(outputData))+dataLen, varDataVal(inputData[j]), varDataLen(inputData[j]));
dataLen += varDataLen(inputData[j]);
if (j < numInputs - 1) {
memcpy(((char*)varDataVal(outputData))+dataLen, varDataVal(inputData[0]), varDataLen(inputData[0]));
dataLen += varDataLen(inputData[0]);
}
}
varDataSetLen(outputData, dataLen);
}
}
free(inputData);
}
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);
......@@ -1398,5 +1522,10 @@ tScalarFunctionInfo aScalarFunctions[] = {
TSDB_FUNC_SCALAR_LENGTH,
"length",
vectorLength
},
{
TSDB_FUNC_SCALAR_CONCAT_WS,
"concat_ws",
vectorConcatWs
}
};
......@@ -40,6 +40,7 @@ run general/compute/top.sim
run general/compute/block_dist.sim
run general/compute/scalar_pow.sim
run general/compute/scalar_triangle.sim
run general/compute/scalar_str_concat_len.sim
run general/db/alter_option.sim
run general/db/alter_tables_d2.sim
run general/db/alter_tables_v1.sim
......
system sh/stop_dnodes.sh
system sh/deploy.sh -n dnode1 -i 1
system sh/cfg.sh -n dnode1 -c walLevel -v 1
system sh/exec.sh -n dnode1 -s start
sleep 500
sql connect
$dbPrefix = db
$tbPrefix = ct
$mtPrefix = st
$quote = '
$tbNum = 2
$rowNum = 50
print =============== step1 create stable/table
$i = 0
$db = $dbPrefix . $i
$mt = $mtPrefix . $i
sql drop database $db -x step1
step1:
sql create database $db
sql use $db
sql create table $mt (ts timestamp, c1 int, c2 binary(10), c3 binary(30), c4 binary(40), c5 binary(50), c6 nchar(10), c7 nchar(20), c8 nchar(30), c9 nchar(40)) TAGS (tgcol int)
$i = 0
while $i < $tbNum
$tb = $tbPrefix . $i
sql create table $tb using $mt tags( $i )
$x = 0
$z2 = $x . 2
$y2 = $quote . $z2
$y2 = $y2 . $quote
$z3 = $x . 3
$y3 = $quote . $z3
$y3 = $y3 . $quote
$z4 = $x . 4
$y4 = $quote . $z4
$y4 = $y4 . $quote
$z5 = $x . 5
$y5 = $quote . $z5
$y5 = $y5 . $quote
$z6 = $x . 6
$y6 = $quote . $z6
$y6 = $y6 . $quote
$z7 = $x . 7
$y7 = $quote . $z7
$y7 = $y7 . $quote
$z8 = $x . 8
$y8 = $quote . $z8
$y8 = $y8 . $quote
$z9 = $x . 9
$y9 = $quote . $z9
$y9 = $y9 . $quote
while $x < $rowNum
$cc = $x * 60000
$ms = 1601481600000 + $cc
sql insert into $tb values ($ms , $x , $y2 , $y3 , $y4 , $y5 , $y6 , $y7 , $y8 , $y9 )
$x = $x + 1
$z2 = $x . 2
$y2 = $quote . $z2
$y2 = $y2 . $quote
$z3 = $x . 3
$y3 = $quote . $z3
$y3 = $y3 . $quote
$z4 = $x . 4
$y4 = $quote . $z4
$y4 = $y4 . $quote
$z5 = $x . 5
$y5 = $quote . $z5
$y5 = $y5 . $quote
$z6 = $x . 6
$y6 = $quote . $z6
$y6 = $y6 . $quote
$z7 = $x . 7
$y7 = $quote . $z7
$y7 = $y7 . $quote
$z8 = $x . 8
$y8 = $quote . $z8
$y8 = $y8 . $quote
$z9 = $x . 9
$y9 = $quote . $z9
$y9 = $y9 . $quote
endw
$i = $i + 1
endw
print ================= step2
$i = 1
$tb = $tbPrefix . $i
$stb = $mtPrefix . 0
print sql select concat(c2, c3, c4, c5) from $tb
sql select concat(c2, c3, c4, c5) from $tb
print $data00
if $data00 != 02030405 then
return -1
endi
print sql select concat_ws('data',c2,c3,c4,c5) from $tb
sql select concat_ws('data',c2,c3,c4,c5) from $tb
print $data00
if $data00 != 02data03data04data05 then
return -1
endi
print sql select concat(c6, c7, c8, c9) from $tb
sql select concat(c6, c7, c8, c9) from $tb
print $data00
if $data00 != 06070809 then
return -1
endi
print sql select concat_ws('data' ,c6,c7,c8,c9) from $tb
sql select concat_ws('data' ,c6,c7,c8,c9) from $tb
print $data00
if $data00 != 06data07data08data09 then
return -1
endi
print sql select length(concat(c2, c3, c4, c5)) from $tb
sql select 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
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
if $data00 != 32 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
if $data00 != 80 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
sql_error select concat_ws('data',c1,c2,c3,c4,c5) from $tb
print ===============> step 3 sql_error stable, group by, window
sql_error select concat(c2) from $stb group by tbname;
sql_error select concat(c2) from $stb group by tgcol;
sql_error select concat(c2) from $stb group by c3;
sql_error select concat(c2) from $stb interval(1m);
sql_error select concat(c2) from $stb state_window(c7);
sql_error select concat(c2) from $tb state_window(c7);
sql_error select concat(c2) from $stb session(ts, 30s);
sql_error select concat(c2) from $tb session(ts, 30s);
sql_error select concat(c2) from $stb slimit 2;
sql_error select concat(c2) from $stb interval(1m) slimit 2;
sql_error select length(c2) from $stb group by tbname;
sql_error select length(c2) from $stb group by tgcol;
sql_error select length(c2) from $stb group by c3;
sql_error select length(c2) from $stb interval(1m);
sql_error select length(c2) from $stb state_window(c7);
sql_error select length(c2) from $tb state_window(c7);
sql_error select length(c2) from $stb session(ts, 30s);
sql_error select length(c2) from $tb session(ts, 30s);
sql_error select length(c2) from $stb slimit 2;
sql_error select length(c2) from $stb interval(1m) slimit 2;
sql_error select concat_ws(c2) from $stb group by tbname;
sql_error select concat_ws(c2) from $stb group by tgcol;
sql_error select concat_ws(c2) from $stb group by c3;
sql_error select concat_ws(c2) from $stb interval(1m);
sql_error select concat_ws(c2) from $stb state_window(c7);
sql_error select concat_ws(c2) from $tb state_window(c7);
sql_error select concat_ws(c2) from $stb session(ts, 30s);
sql_error select concat_ws(c2) from $tb session(ts, 30s);
sql_error select concat_ws(c2) from $stb slimit 2;
sql_error select concat_ws(c2) from $stb interval(1m) slimit 2;
print =============== clear
#sql drop database $db
#sql show databases
#if $rows != 0 then
# return -1
#endi
#system sh/exec.sh -n dnode1 -s stop -x SIGINT
......@@ -22,3 +22,4 @@ run general/compute/top.sim
run general/compute/block_dist.sim
run general/compute/scalar_pow.sim
run general/compute/scalar_triangle.sim
run general/compute/scalar_str_concat_len.sim
......@@ -40,6 +40,7 @@ run general/compute/top.sim
run general/compute/block_dist.sim
run general/compute/scalar_pow.sim
run general/compute/scalar_triangle.sim
run general/compute/scalar_str_concat_len.sim
run general/db/alter_option.sim
run general/db/alter_tables_d2.sim
run general/db/alter_tables_v1.sim
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册