提交 4d7b7127 编写于 作者: D dapan1121

Merge branch 'szhou/feature/support-math-functions' into feature/TD-6140

...@@ -4373,12 +4373,10 @@ static int32_t validateSQLExprItemSQLFunc(SSqlCmd* pCmd, tSqlExpr* pExpr, ...@@ -4373,12 +4373,10 @@ static int32_t validateSQLExprItemSQLFunc(SSqlCmd* pCmd, tSqlExpr* pExpr,
} }
{ {
if (TSDB_FUNC_IS_SCALAR(functionId)) { if (TSDB_FUNC_IS_SCALAR(functionId)) {
bool allChildValue = true;
bool anyChildScalar = false; bool anyChildScalar = false;
bool anyChildAgg = false; bool anyChildAgg = false;
for (int i = 0; i < numChildren; ++i) { for (int i = 0; i < numChildren; ++i) {
assert (childrenTypes[i] != SQLEXPR_TYPE_UNASSIGNED); assert (childrenTypes[i] != SQLEXPR_TYPE_UNASSIGNED);
allChildValue = allChildValue && (childrenTypes[i] == SQLEXPR_TYPE_VALUE);
anyChildScalar = anyChildScalar || (childrenTypes[i] == SQLEXPR_TYPE_SCALAR); anyChildScalar = anyChildScalar || (childrenTypes[i] == SQLEXPR_TYPE_SCALAR);
anyChildAgg = anyChildAgg || (childrenTypes[i] == SQLEXPR_TYPE_AGG); anyChildAgg = anyChildAgg || (childrenTypes[i] == SQLEXPR_TYPE_AGG);
} }
...@@ -4387,8 +4385,6 @@ static int32_t validateSQLExprItemSQLFunc(SSqlCmd* pCmd, tSqlExpr* pExpr, ...@@ -4387,8 +4385,6 @@ static int32_t validateSQLExprItemSQLFunc(SSqlCmd* pCmd, tSqlExpr* pExpr,
} }
if (anyChildAgg) { if (anyChildAgg) {
*type = SQLEXPR_TYPE_AGG; *type = SQLEXPR_TYPE_AGG;
} else if (allChildValue) {
*type = SQLEXPR_TYPE_VALUE;
} else { } else {
*type = SQLEXPR_TYPE_SCALAR; *type = SQLEXPR_TYPE_SCALAR;
} }
...@@ -7386,7 +7382,8 @@ static bool onlyTagPrjFunction(SQueryInfo* pQueryInfo) { ...@@ -7386,7 +7382,8 @@ static bool onlyTagPrjFunction(SQueryInfo* pQueryInfo) {
size_t size = taosArrayGetSize(pQueryInfo->exprList); size_t size = taosArrayGetSize(pQueryInfo->exprList);
for (int32_t i = 0; i < size; ++i) { for (int32_t i = 0; i < size; ++i) {
SExprInfo* pExpr = tscExprGet(pQueryInfo, i); SExprInfo* pExpr = tscExprGet(pQueryInfo, i);
if (pExpr->base.functionId == TSDB_FUNC_PRJ) { if (pExpr->base.functionId == TSDB_FUNC_PRJ ||
(pExpr->base.functionId == TSDB_FUNC_SCALAR_EXPR && ((pQueryInfo->type & TSDB_QUERY_TYPE_PROJECTION_QUERY) != 0))) {
hasColumnPrj = true; hasColumnPrj = true;
} else if (pExpr->base.functionId == TSDB_FUNC_TAGPRJ) { } else if (pExpr->base.functionId == TSDB_FUNC_TAGPRJ) {
hasTagPrj = true; hasTagPrj = true;
...@@ -7478,8 +7475,6 @@ static int32_t checkUpdateTagPrjFunctions(SQueryInfo* pQueryInfo, char* msg) { ...@@ -7478,8 +7475,6 @@ static int32_t checkUpdateTagPrjFunctions(SQueryInfo* pQueryInfo, char* msg) {
if ((aAggs[functionId].status & TSDB_FUNCSTATE_SELECTIVITY) != 0) { if ((aAggs[functionId].status & TSDB_FUNCSTATE_SELECTIVITY) != 0) {
numOfSelectivity++; numOfSelectivity++;
} else if ((aAggs[functionId].status & TSDB_FUNCSTATE_SCALAR) != 0) {
numOfScalar++;
} else { } else {
numOfAggregation++; numOfAggregation++;
} }
...@@ -7721,7 +7716,8 @@ int32_t doFunctionsCompatibleCheck(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, char* ...@@ -7721,7 +7716,8 @@ int32_t doFunctionsCompatibleCheck(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, char*
continue; continue;
} }
if (TSDB_FUNC_IS_SCALAR(f)) { if (f == TSDB_FUNC_SCALAR_EXPR &&
(pQueryInfo->type & TSDB_QUERY_TYPE_PROJECTION_QUERY) != 0) {
return invalidOperationMsg(msg, msg1); return invalidOperationMsg(msg, msg1);
} }
...@@ -7745,9 +7741,6 @@ int32_t doFunctionsCompatibleCheck(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, char* ...@@ -7745,9 +7741,6 @@ int32_t doFunctionsCompatibleCheck(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, char*
return invalidOperationMsg(msg, msg1); return invalidOperationMsg(msg, msg1);
} }
if (IS_SCALAR_FUNCTION(aAggs[f].status)) {
return invalidOperationMsg(msg, msg1);
}
if (f == TSDB_FUNC_COUNT && pExpr->base.colInfo.colIndex == TSDB_TBNAME_COLUMN_INDEX) { if (f == TSDB_FUNC_COUNT && pExpr->base.colInfo.colIndex == TSDB_TBNAME_COLUMN_INDEX) {
return invalidOperationMsg(msg, msg1); return invalidOperationMsg(msg, msg1);
...@@ -9826,7 +9819,7 @@ int32_t exprTreeFromSqlExpr(SSqlCmd* pCmd, tExprNode **pExpr, const tSqlExpr* pS ...@@ -9826,7 +9819,7 @@ int32_t exprTreeFromSqlExpr(SSqlCmd* pCmd, tExprNode **pExpr, const tSqlExpr* pS
SArray* paramList = pSqlExpr->Expr.paramList; SArray* paramList = pSqlExpr->Expr.paramList;
size_t paramSize = paramList ? taosArrayGetSize(paramList) : 0; size_t paramSize = paramList ? taosArrayGetSize(paramList) : 0;
if (paramSize > 0) { if (paramSize > 0) {
(*pExpr)->_func.numChildren = (uint8_t)paramSize; (*pExpr)->_func.numChildren = (int32_t)paramSize;
(*pExpr)->_func.pChildren = (tExprNode**)calloc(paramSize, sizeof(tExprNode*)); (*pExpr)->_func.pChildren = (tExprNode**)calloc(paramSize, sizeof(tExprNode*));
} }
for (int32_t i = 0; i < paramSize; ++i) { for (int32_t i = 0; i < paramSize; ++i) {
......
...@@ -62,8 +62,10 @@ struct SSchema; ...@@ -62,8 +62,10 @@ struct SSchema;
#define TSDB_FUNC_SCALAR_ROUND (TSDB_FUNC_FLAG_SCALAR | 0x000C) #define TSDB_FUNC_SCALAR_ROUND (TSDB_FUNC_FLAG_SCALAR | 0x000C)
#define TSDB_FUNC_SCALAR_CONCAT (TSDB_FUNC_FLAG_SCALAR | 0x000D) #define TSDB_FUNC_SCALAR_CONCAT (TSDB_FUNC_FLAG_SCALAR | 0x000D)
#define TSDB_FUNC_SCALAR_LENGTH (TSDB_FUNC_FLAG_SCALAR | 0x000E) #define TSDB_FUNC_SCALAR_LENGTH (TSDB_FUNC_FLAG_SCALAR | 0x000E)
#define TSDB_FUNC_SCALAR_CAST (TSDB_FUNC_FLAG_SCALAR | 0x000F) #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 | 0x0010)
#define TSDB_FUNC_SCALAR_CAST (TSDB_FUNC_FLAG_SCALAR | 0x0011)
#define TSDB_FUNC_SCALAR_MAX_NUM 18
#define TSDB_FUNC_SCALAR_NAME_MAX_LEN 16 #define TSDB_FUNC_SCALAR_NAME_MAX_LEN 16
...@@ -74,7 +76,7 @@ typedef struct { ...@@ -74,7 +76,7 @@ typedef struct {
char* data; char* data;
} tExprOperandInfo; } tExprOperandInfo;
typedef void (*_expr_scalar_function_t)(int16_t functionId, tExprOperandInfo* pInputs, uint8_t numInputs, tExprOperandInfo* pOutput, int32_t order); typedef void (*_expr_scalar_function_t)(int16_t functionId, tExprOperandInfo* pInputs, int32_t numInputs, tExprOperandInfo* pOutput, int32_t order);
_expr_scalar_function_t getExprScalarFunction(uint16_t scalar); _expr_scalar_function_t getExprScalarFunction(uint16_t scalar);
...@@ -128,7 +130,7 @@ typedef struct tExprNode { ...@@ -128,7 +130,7 @@ typedef struct tExprNode {
struct { struct {
int16_t functionId; int16_t functionId;
uint8_t numChildren; int32_t numChildren;
struct tExprNode **pChildren; struct tExprNode **pChildren;
} _func; } _func;
......
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
static int32_t exprValidateMathNode(tExprNode *pExpr); static int32_t exprValidateMathNode(tExprNode *pExpr);
static int32_t exprValidateStringConcatNode(tExprNode *pExpr); static int32_t exprValidateStringConcatNode(tExprNode *pExpr);
static int32_t exprValidateStringConcatWsNode(tExprNode *pExpr);
static int32_t exprValidateStringLengthNode(tExprNode *pExpr); static int32_t exprValidateStringLengthNode(tExprNode *pExpr);
static int32_t exprValidateCastNode(char* msgbuf, tExprNode *pExpr); static int32_t exprValidateCastNode(char* msgbuf, tExprNode *pExpr);
...@@ -65,12 +66,17 @@ int32_t exprTreeValidateFunctionNode(char* msgbuf, tExprNode *pExpr) { ...@@ -65,12 +66,17 @@ int32_t exprTreeValidateFunctionNode(char* msgbuf, tExprNode *pExpr) {
case TSDB_FUNC_SCALAR_CONCAT: { case TSDB_FUNC_SCALAR_CONCAT: {
return exprValidateStringConcatNode(pExpr); return exprValidateStringConcatNode(pExpr);
} }
case TSDB_FUNC_SCALAR_LENGTH: { case TSDB_FUNC_SCALAR_LENGTH:
case TSDB_FUNC_SCALAR_CHAR_LENGTH: {
return exprValidateStringLengthNode(pExpr); return exprValidateStringLengthNode(pExpr);
} }
case TSDB_FUNC_SCALAR_CAST: { case TSDB_FUNC_SCALAR_CAST: {
return exprValidateCastNode(msgbuf, pExpr); return exprValidateCastNode(msgbuf, pExpr);
} }
case TSDB_FUNC_SCALAR_CONCAT_WS: {
return exprValidateStringConcatWsNode(pExpr);
}
default: default:
break; break;
} }
...@@ -348,7 +354,7 @@ void exprTreeInternalNodeTraverse(tExprNode *pExpr, int32_t numOfRows, tExprOper ...@@ -348,7 +354,7 @@ void exprTreeInternalNodeTraverse(tExprNode *pExpr, int32_t numOfRows, tExprOper
void exprTreeFunctionNodeTraverse(tExprNode *pExpr, int32_t numOfRows, tExprOperandInfo *output, void *param, int32_t order, void exprTreeFunctionNodeTraverse(tExprNode *pExpr, int32_t numOfRows, tExprOperandInfo *output, void *param, int32_t order,
char *(*getSourceDataBlock)(void *, const char*, int32_t)) { char *(*getSourceDataBlock)(void *, const char*, int32_t)) {
uint8_t numChildren = pExpr->_func.numChildren; int32_t numChildren = pExpr->_func.numChildren;
if (numChildren == 0) { if (numChildren == 0) {
_expr_scalar_function_t scalarFn = getExprScalarFunction(pExpr->_func.functionId); _expr_scalar_function_t scalarFn = getExprScalarFunction(pExpr->_func.functionId);
output->type = pExpr->resultType; output->type = pExpr->resultType;
...@@ -517,7 +523,7 @@ static void exprTreeToBinaryImpl(SBufferWriter* bw, tExprNode* expr) { ...@@ -517,7 +523,7 @@ static void exprTreeToBinaryImpl(SBufferWriter* bw, tExprNode* expr) {
exprTreeToBinaryImpl(bw, expr->_node.pRight); exprTreeToBinaryImpl(bw, expr->_node.pRight);
} else if (expr->nodeType == TSQL_NODE_FUNC) { } else if (expr->nodeType == TSQL_NODE_FUNC) {
tbufWriteInt16(bw, expr->_func.functionId); tbufWriteInt16(bw, expr->_func.functionId);
tbufWriteUint8(bw, expr->_func.numChildren); tbufWriteInt32(bw, expr->_func.numChildren);
for (int i = 0; i < expr->_func.numChildren; ++i) { for (int i = 0; i < expr->_func.numChildren; ++i) {
exprTreeToBinaryImpl(bw, expr->_func.pChildren[i]); exprTreeToBinaryImpl(bw, expr->_func.pChildren[i]);
} }
...@@ -590,7 +596,7 @@ static tExprNode* exprTreeFromBinaryImpl(SBufferReader* br) { ...@@ -590,7 +596,7 @@ static tExprNode* exprTreeFromBinaryImpl(SBufferReader* br) {
assert(pExpr->_node.pLeft != NULL && pExpr->_node.pRight != NULL); assert(pExpr->_node.pLeft != NULL && pExpr->_node.pRight != NULL);
} else if (pExpr->nodeType == TSQL_NODE_FUNC) { } else if (pExpr->nodeType == TSQL_NODE_FUNC) {
pExpr->_func.functionId = tbufReadInt16(br); pExpr->_func.functionId = tbufReadInt16(br);
pExpr->_func.numChildren = tbufReadUint8(br); pExpr->_func.numChildren = tbufReadInt32(br);
pExpr->_func.pChildren = (tExprNode**)calloc(pExpr->_func.numChildren, sizeof(tExprNode*)); pExpr->_func.pChildren = (tExprNode**)calloc(pExpr->_func.numChildren, sizeof(tExprNode*));
for (int i = 0; i < pExpr->_func.numChildren; ++i) { for (int i = 0; i < pExpr->_func.numChildren; ++i) {
pExpr->_func.pChildren[i] = exprTreeFromBinaryImpl(br); pExpr->_func.pChildren[i] = exprTreeFromBinaryImpl(br);
...@@ -865,7 +871,7 @@ tExprNode* exprdup(tExprNode* pNode) { ...@@ -865,7 +871,7 @@ tExprNode* exprdup(tExprNode* pNode) {
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// scalar functions // scalar functions
int32_t exprValidateStringConcatNode(tExprNode *pExpr) { 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; return TSDB_CODE_TSC_INVALID_OPERATION;
} }
...@@ -936,6 +942,82 @@ int32_t exprValidateStringConcatNode(tExprNode *pExpr) { ...@@ -936,6 +942,82 @@ int32_t exprValidateStringConcatNode(tExprNode *pExpr) {
return TSDB_CODE_SUCCESS; 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) { int32_t exprValidateStringLengthNode(tExprNode *pExpr) {
if (pExpr->_func.numChildren != 1) { if (pExpr->_func.numChildren != 1) {
return TSDB_CODE_TSC_INVALID_OPERATION; return TSDB_CODE_TSC_INVALID_OPERATION;
...@@ -1073,7 +1155,7 @@ int32_t exprValidateMathNode(tExprNode *pExpr) { ...@@ -1073,7 +1155,7 @@ int32_t exprValidateMathNode(tExprNode *pExpr) {
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
void vectorConcat(int16_t functionId, tExprOperandInfo* pInputs, uint8_t numInputs, tExprOperandInfo* pOutput, int32_t order) { void vectorConcat(int16_t functionId, tExprOperandInfo* pInputs, int32_t numInputs, tExprOperandInfo* pOutput, int32_t order) {
assert(functionId == TSDB_FUNC_SCALAR_CONCAT && numInputs >=2 && order == TSDB_ORDER_ASC); assert(functionId == TSDB_FUNC_SCALAR_CONCAT && numInputs >=2 && order == TSDB_ORDER_ASC);
for (int i = 0; i < numInputs; ++i) { for (int i = 0; i < numInputs; ++i) {
assert(pInputs[i].numOfRows == 1 || pInputs[i].numOfRows == pOutput->numOfRows); assert(pInputs[i].numOfRows == 1 || pInputs[i].numOfRows == pOutput->numOfRows);
...@@ -1113,8 +1195,52 @@ void vectorConcat(int16_t functionId, tExprOperandInfo* pInputs, uint8_t numInpu ...@@ -1113,8 +1195,52 @@ void vectorConcat(int16_t functionId, tExprOperandInfo* pInputs, uint8_t numInpu
free(inputData); free(inputData);
} }
void vectorLength(int16_t functionId, tExprOperandInfo *pInputs, uint8_t numInputs, tExprOperandInfo* pOutput, int32_t order) { 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;
if (isNull(inputData[0], pInputs[0].type)) {
setNull(outputData, pOutput->type, pOutput->bytes);
continue;
}
int16_t dataLen = 0;
for (int j = 1; j < numInputs; ++j) {
if (isNull(inputData[j], pInputs[j].type)) {
continue;
}
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); assert(functionId == TSDB_FUNC_SCALAR_LENGTH && numInputs == 1 && order == TSDB_ORDER_ASC);
assert(IS_VAR_DATA_TYPE(pInputs[0].type));
char* data0 = NULL; char* data0 = NULL;
char* outputData = NULL; char* outputData = NULL;
...@@ -1232,8 +1358,34 @@ void castConvert(int16_t inputType, int16_t inputBytes, char *input, int16_t Out ...@@ -1232,8 +1358,34 @@ void castConvert(int16_t inputType, int16_t inputBytes, char *input, int16_t Out
} }
} }
void vectorMathFunc(int16_t functionId, tExprOperandInfo *pInputs, uint8_t numInputs, tExprOperandInfo* pOutput, int32_t order) { 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) { for (int i = 0; i < numInputs; ++i) {
assert(pInputs[i].numOfRows == 1 || pInputs[i].numOfRows == pOutput->numOfRows); assert(pInputs[i].numOfRows == 1 || pInputs[i].numOfRows == pOutput->numOfRows);
} }
...@@ -1538,4 +1690,14 @@ tScalarFunctionInfo aScalarFunctions[] = { ...@@ -1538,4 +1690,14 @@ tScalarFunctionInfo aScalarFunctions[] = {
"cast", "cast",
vectorMathFunc vectorMathFunc
}, },
{
TSDB_FUNC_SCALAR_CONCAT_WS,
"concat_ws",
vectorConcatWs
},
{
TSDB_FUNC_SCALAR_CHAR_LENGTH,
"char_length",
vectorCharLength
}
}; };
...@@ -220,6 +220,8 @@ ...@@ -220,6 +220,8 @@
#define TK_SPACE 300 #define TK_SPACE 300
#define TK_COMMENT 301 #define TK_COMMENT 301
#define TK_ILLEGAL 302 #define TK_ILLEGAL 302
......
...@@ -90,7 +90,6 @@ extern "C" { ...@@ -90,7 +90,6 @@ extern "C" {
#define TSDB_FUNCSTATE_OF 0x10u // outer forward #define TSDB_FUNCSTATE_OF 0x10u // outer forward
#define TSDB_FUNCSTATE_NEED_TS 0x20u // timestamp is required during query processing #define TSDB_FUNCSTATE_NEED_TS 0x20u // timestamp is required during query processing
#define TSDB_FUNCSTATE_SELECTIVITY 0x40u // selectivity functions, can exists along with tag columns #define TSDB_FUNCSTATE_SELECTIVITY 0x40u // selectivity functions, can exists along with tag columns
#define TSDB_FUNCSTATE_SCALAR 0x80u
#define TSDB_BASE_FUNC_SO TSDB_FUNCSTATE_SO | TSDB_FUNCSTATE_STREAM | TSDB_FUNCSTATE_STABLE | TSDB_FUNCSTATE_OF #define TSDB_BASE_FUNC_SO TSDB_FUNCSTATE_SO | TSDB_FUNCSTATE_STREAM | TSDB_FUNCSTATE_STABLE | TSDB_FUNCSTATE_OF
#define TSDB_BASE_FUNC_MO TSDB_FUNCSTATE_MO | TSDB_FUNCSTATE_STREAM | TSDB_FUNCSTATE_STABLE | TSDB_FUNCSTATE_OF #define TSDB_BASE_FUNC_MO TSDB_FUNCSTATE_MO | TSDB_FUNCSTATE_STREAM | TSDB_FUNCSTATE_STABLE | TSDB_FUNCSTATE_OF
...@@ -231,7 +230,6 @@ int32_t isValidFunction(const char* name, int32_t len); ...@@ -231,7 +230,6 @@ int32_t isValidFunction(const char* name, int32_t len);
#define IS_MULTIOUTPUT(x) (((x)&TSDB_FUNCSTATE_MO) != 0) #define IS_MULTIOUTPUT(x) (((x)&TSDB_FUNCSTATE_MO) != 0)
#define IS_SINGLEOUTPUT(x) (((x)&TSDB_FUNCSTATE_SO) != 0) #define IS_SINGLEOUTPUT(x) (((x)&TSDB_FUNCSTATE_SO) != 0)
#define IS_OUTER_FORWARD(x) (((x)&TSDB_FUNCSTATE_OF) != 0) #define IS_OUTER_FORWARD(x) (((x)&TSDB_FUNCSTATE_OF) != 0)
#define IS_SCALAR_FUNCTION(x) (((x)&TSDB_FUNCSTATE_SCALAR) != 0)
// determine the real data need to calculated the result // determine the real data need to calculated the result
enum { enum {
......
...@@ -435,10 +435,6 @@ static bool isScalarWithTagsQuery(SQLFunctionCtx *pCtx, int32_t numOfOutput) { ...@@ -435,10 +435,6 @@ static bool isScalarWithTagsQuery(SQLFunctionCtx *pCtx, int32_t numOfOutput) {
hasTags = true; hasTags = true;
continue; continue;
} }
if ((aAggs[functId].status & TSDB_FUNCSTATE_SCALAR) != 0) {
numOfScalar++;
}
} }
return (numOfScalar > 0 && hasTags); return (numOfScalar > 0 && hasTags);
...@@ -1866,7 +1862,7 @@ static int32_t setCtxTagColumnInfo(SQLFunctionCtx *pCtx, int32_t numOfOutput) { ...@@ -1866,7 +1862,7 @@ static int32_t setCtxTagColumnInfo(SQLFunctionCtx *pCtx, int32_t numOfOutput) {
if (functionId == TSDB_FUNC_TAG_DUMMY || functionId == TSDB_FUNC_TS_DUMMY) { if (functionId == TSDB_FUNC_TAG_DUMMY || functionId == TSDB_FUNC_TS_DUMMY) {
tagLen += pCtx[i].outputBytes; tagLen += pCtx[i].outputBytes;
pTagCtx[num++] = &pCtx[i]; pTagCtx[num++] = &pCtx[i];
} else if ((aAggs[functionId].status & TSDB_FUNCSTATE_SELECTIVITY) != 0 || (aAggs[functionId].status & TSDB_FUNCSTATE_SCALAR) != 0) { } else if ((aAggs[functionId].status & TSDB_FUNCSTATE_SELECTIVITY) != 0) {
p = &pCtx[i]; p = &pCtx[i];
} else if (functionId == TSDB_FUNC_TS || functionId == TSDB_FUNC_TAG) { } else if (functionId == TSDB_FUNC_TS || functionId == TSDB_FUNC_TAG) {
// tag function may be the group by tag column // tag function may be the group by tag column
......
...@@ -146,7 +146,7 @@ int32_t tBucketIntHash(tMemBucket *pBucket, const void *value) { ...@@ -146,7 +146,7 @@ int32_t tBucketIntHash(tMemBucket *pBucket, const void *value) {
} }
int32_t tBucketUintHash(tMemBucket *pBucket, const void *value) { int32_t tBucketUintHash(tMemBucket *pBucket, const void *value) {
int64_t v = 0; uint64_t v = 0;
GET_TYPED_DATA(v, uint64_t, pBucket->type, value); GET_TYPED_DATA(v, uint64_t, pBucket->type, value);
int32_t index = -1; int32_t index = -1;
...@@ -162,8 +162,8 @@ int32_t tBucketUintHash(tMemBucket *pBucket, const void *value) { ...@@ -162,8 +162,8 @@ int32_t tBucketUintHash(tMemBucket *pBucket, const void *value) {
index = (int32_t) (delta % pBucket->numOfSlots); index = (int32_t) (delta % pBucket->numOfSlots);
} else { } else {
double slotSpan = (double)span / pBucket->numOfSlots; double slotSpan = (double)span / pBucket->numOfSlots;
index = (int32_t)((v - pBucket->range.u64MinVal) / slotSpan); index = (int32_t)(((double)v - pBucket->range.u64MinVal) / slotSpan);
if (v == pBucket->range.u64MaxVal) { if (index == pBucket->numOfSlots) {
index -= 1; index -= 1;
} }
} }
...@@ -194,7 +194,7 @@ int32_t tBucketDoubleHash(tMemBucket *pBucket, const void *value) { ...@@ -194,7 +194,7 @@ int32_t tBucketDoubleHash(tMemBucket *pBucket, const void *value) {
} else { } else {
double slotSpan = span / pBucket->numOfSlots; double slotSpan = span / pBucket->numOfSlots;
index = (int32_t)((v - pBucket->range.dMinVal) / slotSpan); index = (int32_t)((v - pBucket->range.dMinVal) / slotSpan);
if (v == pBucket->range.dMaxVal) { if (index == pBucket->numOfSlots) {
index -= 1; index -= 1;
} }
} }
......
...@@ -39,6 +39,8 @@ run general/compute/sum.sim ...@@ -39,6 +39,8 @@ run general/compute/sum.sim
run general/compute/top.sim run general/compute/top.sim
run general/compute/block_dist.sim run general/compute/block_dist.sim
run general/compute/scalar_pow.sim run general/compute/scalar_pow.sim
run general/compute/scalar_triangle.sim
run general/compute/scalar_str_concat_len.sim
run general/compute/table_group.sim run general/compute/table_group.sim
run general/db/alter_option.sim run general/db/alter_option.sim
run general/db/alter_tables_d2.sim run general/db/alter_tables_d2.sim
...@@ -141,6 +143,7 @@ run general/parser/groupby.sim ...@@ -141,6 +143,7 @@ run general/parser/groupby.sim
run general/parser/top_groupby.sim run general/parser/top_groupby.sim
run general/parser/tags_dynamically_specifiy.sim run general/parser/tags_dynamically_specifiy.sim
run general/parser/set_tag_vals.sim run general/parser/set_tag_vals.sim
run general/parser/scalar_expression.sim
#unsupport run general/parser/repeatAlter.sim #unsupport run general/parser/repeatAlter.sim
#unsupport run general/parser/slimit_alter_tags.sim #unsupport run general/parser/slimit_alter_tags.sim
run general/parser/precision_ns.sim run general/parser/precision_ns.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 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
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
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
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
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 =============== trival test
print execute sql select concat(c2,c3),concat(c2,c3,c4),concat(c2,c3,c4,c5) from ct1
sql select concat(c2,c3),concat(c2,c3,c4),concat(c2,c3,c4,c5) from ct1
if $rows != 50 then
return -1
endi
if $data00 != @0203@ then
return -1
endi
if $data01 != @020304@ then
return -1
endi
if $data02 != @02030405@ then
return -1
endi
if $data10 != @1213@ then
return -1
endi
if $data11 != @121314@ then
return -1
endi
if $data12 != @12131415@ then
return -1
endi
print execute sql select concat('taos',c2,c3),concat('taos',c2,c4),concat('taos',c2,c5),concat('taos',c3,c4),concat('taos',c3,c5) from ct1
sql select concat('taos',c2,c3),concat('taos',c2,c4),concat('taos',c2,c5),concat('taos',c3,c4),concat('taos',c3,c5) from ct1
if $rows != 50 then
return -1
endi
if $data00 != @taos0203@ then
return -1
endi
if $data01 != @taos0204@ then
return -1
endi
if $data02 != @taos0205@ then
return -1
endi
if $data03 != @taos0304@ then
return -1
endi
if $data04 != @taos0305@ then
return -1
endi
if $data10 != @taos1213@ then
return -1
endi
if $data11 != @taos1214@ then
return -1
endi
if $data12 != @taos1215@ then
return -1
endi
if $data13 != @taos1314@ then
return -1
endi
if $data14 != @taos1315@ then
return -1
endi
print execute sql select concat(c6,c7,'taos'),concat(c6,c8,'taos'),concat(c6,c9,'taos'),concat(c7,c8,'taos'),concat(c7,c9,'taos') from ct1
sql select concat(c6,c7,'taos'),concat(c6,c8,'taos'),concat(c6,c9,'taos'),concat(c7,c8,'taos'),concat(c7,c9,'taos') from ct1
if $rows != 50 then
return -1
endi
if $data00 != @0607taos@ then
return -1
endi
if $data01 != @0608taos@ then
return -1
endi
if $data02 != @0609taos@ then
return -1
endi
if $data03 != @0708taos@ then
return -1
endi
if $data04 != @0709taos@ then
return -1
endi
if $data10 != @1617taos@ then
return -1
endi
if $data11 != @1618taos@ then
return -1
endi
if $data12 != @1619taos@ then
return -1
endi
if $data13 != @1718taos@ then
return -1
endi
if $data14 != @1719taos@ then
return -1
endi
print execute sql select concat('data',c7,'taos'),concat('data',c8,'taos'),concat('data',c9,'taos'),concat(c7,c8,'taos'),concat(c7,c9,'taos') from ct1
sql select concat('data',c7,'taos'),concat('data',c8,'taos'),concat('data',c9,'taos'),concat(c7,c8,'taos'),concat(c7,c9,'taos') from ct1
if $rows != 50 then
return -1
endi
if $data00 != @data07taos@ then
return -1
endi
if $data01 != @data08taos@ then
return -1
endi
if $data02 != @data09taos@ then
return -1
endi
if $data03 != @0708taos@ then
return -1
endi
if $data04 != @0709taos@ then
return -1
endi
if $data10 != @data17taos@ then
return -1
endi
if $data11 != @data18taos@ then
return -1
endi
if $data12 != @data19taos@ then
return -1
endi
if $data13 != @1718taos@ then
return -1
endi
if $data14 != @1719taos@ then
return -1
endi
print execute sql select concat_ws('jeff',c2,c3),concat_ws('jeff',c2,c3,c4),concat_ws('jeff',c2,c3,c4,c5) from ct1
sql select concat_ws('jeff',c2,c3),concat_ws('jeff',c2,c3,c4),concat_ws('jeff',c2,c3,c4,c5) from ct1
if $rows != 50 then
return -1
endi
if $data00 != @02jeff03@ then
return -1
endi
if $data01 != @02jeff03jeff04@ then
return -1
endi
if $data02 != @02jeff03jeff04jeff05@ then
return -1
endi
if $data10 != @12jeff13@ then
return -1
endi
if $data11 != @12jeff13jeff14@ then
return -1
endi
if $data12 != @12jeff13jeff14jeff15@ then
return -1
endi
print execute sql select concat_ws('jeff','taos',c2,c3),concat_ws('jeff','taos',c2,c4),concat_ws('jeff','taos',c2,c5),concat_ws('jeff','taos',c3,c4),concat_ws('jeff','taos',c3,c5) from ct1
sql select concat_ws('jeff','taos',c2,c3),concat_ws('jeff','taos',c2,c4),concat_ws('jeff','taos',c2,c5),concat_ws('jeff','taos',c3,c4),concat_ws('jeff','taos',c3,c5) from ct1
if $rows != 50 then
return -1
endi
if $data00 != @taosjeff02jeff03@ then
return -1
endi
if $data01 != @taosjeff02jeff04@ then
return -1
endi
if $data02 != @taosjeff02jeff05@ then
return -1
endi
if $data03 != @taosjeff03jeff04@ then
return -1
endi
if $data04 != @taosjeff03jeff05@ then
return -1
endi
if $data10 != @taosjeff12jeff13@ then
return -1
endi
if $data11 != @taosjeff12jeff14@ then
return -1
endi
if $data12 != @taosjeff12jeff15@ then
return -1
endi
if $data13 != @taosjeff13jeff14@ then
return -1
endi
if $data14 != @taosjeff13jeff15@ then
return -1
endi
print execute sql select concat_ws('jeff','data',c3),concat_ws('jeff','data',c3,c4),concat_ws('jeff','data',c3,c4,c5) from ct1
sql select concat_ws('jeff','data',c3),concat_ws('jeff','data',c3,c4),concat_ws('jeff','data',c3,c4,c5) from ct1
if $rows != 50 then
return -1
endi
if $data00 != @datajeff03@ then
return -1
endi
if $data01 != @datajeff03jeff04@ then
return -1
endi
if $data02 != @datajeff03jeff04jeff05@ then
return -1
endi
if $data10 != @datajeff13@ then
return -1
endi
if $data11 != @datajeff13jeff14@ then
return -1
endi
if $data12 != @datajeff13jeff14jeff15@ then
return -1
endi
print execute sql select concat_ws('jeff','data',c7,'taos'),concat_ws('jeff','data',c8,'taos'),concat_ws('jeff','data',c9,'taos'),concat_ws('jeff',c7,c8,'taos'),concat_ws('jeff',c7,c9,'taos') from ct1
sql select concat_ws('jeff','data',c7,'taos'),concat_ws('jeff','data',c8,'taos'),concat_ws('jeff','data',c9,'taos'),concat_ws('jeff',c7,c8,'taos'),concat_ws('jeff',c7,c9,'taos') from ct1
if $rows != 50 then
return -1
endi
if $data00 != @datajeff07jefftaos@ then
return -1
endi
if $data01 != @datajeff08jefftaos@ then
return -1
endi
if $data02 != @datajeff09jefftaos@ then
return -1
endi
if $data03 != @07jeff08jefftaos@ then
return -1
endi
if $data04 != @07jeff09jefftaos@ then
return -1
endi
if $data10 != @datajeff17jefftaos@ then
return -1
endi
if $data11 != @datajeff18jefftaos@ then
return -1
endi
if $data12 != @datajeff19jefftaos@ then
return -1
endi
if $data13 != @17jeff18jefftaos@ then
return -1
endi
if $data14 != @17jeff19jefftaos@ then
return -1
endi
print execute sql select length(concat(c2,c3)),length(concat(c2,c3,c4)),length(concat(c2,c3,c4,c5)) from ct1
sql select length(concat(c2,c3)),length(concat(c2,c3,c4)),length(concat(c2,c3,c4,c5)) from ct1
if $rows != 50 then
return -1
endi
if $data00 != @4@ then
return -1
endi
if $data01 != @6@ then
return -1
endi
if $data02 != @8@ then
return -1
endi
if $data10 != @4@ then
return -1
endi
if $data11 != @6@ then
return -1
endi
if $data12 != @8@ then
return -1
endi
print execute sql select length(concat(c6,c7,'taos')),length(concat(c6,c8,'taos')),length(concat(c6,c9,'taos')),length(concat(c7,c8,'taos')),length(concat(c7,c9,'taos')) from ct1
sql select length(concat(c6,c7,'taos')),length(concat(c6,c8,'taos')),length(concat(c6,c9,'taos')),length(concat(c7,c8,'taos')),length(concat(c7,c9,'taos')) from ct1
if $rows != 50 then
return -1
endi
if $data00 != @32@ then
return -1
endi
if $data01 != @32@ then
return -1
endi
if $data02 != @32@ then
return -1
endi
if $data03 != @32@ then
return -1
endi
if $data04 != @32@ then
return -1
endi
if $data10 != @32@ then
return -1
endi
if $data11 != @32@ then
return -1
endi
if $data12 != @32@ then
return -1
endi
if $data13 != @32@ then
return -1
endi
if $data14 != @32@ then
return -1
endi
print execute sql select length(concat_ws('jeff','taos',c2,c3)),length(concat_ws('jeff','taos',c2,c4)),length(concat_ws('jeff','taos',c2,c5)),length(concat_ws('jeff','taos',c3,c4)),length(concat_ws('jeff','taos',c3,c5)) from ct1
sql select length(concat_ws('jeff','taos',c2,c3)),length(concat_ws('jeff','taos',c2,c4)),length(concat_ws('jeff','taos',c2,c5)),length(concat_ws('jeff','taos',c3,c4)),length(concat_ws('jeff','taos',c3,c5)) from ct1
if $rows != 50 then
return -1
endi
if $data00 != @16@ then
return -1
endi
if $data01 != @16@ then
return -1
endi
if $data02 != @16@ then
return -1
endi
if $data03 != @16@ then
return -1
endi
if $data04 != @16@ then
return -1
endi
if $data10 != @16@ then
return -1
endi
if $data11 != @16@ then
return -1
endi
if $data12 != @16@ then
return -1
endi
if $data13 != @16@ then
return -1
endi
if $data14 != @16@ then
return -1
endi
print execute sql select length(concat_ws('jeff',c6,c7,'taos')),length(concat_ws('jeff',c6,c8,'taos')),length(concat_ws('jeff',c6,c9,'taos')),length(concat_ws('jeff',c7,c8,'taos')),length(concat_ws('jeff',c7,c9,'taos')) from ct1
sql select length(concat_ws('jeff',c6,c7,'taos')),length(concat_ws('jeff',c6,c8,'taos')),length(concat_ws('jeff',c6,c9,'taos')),length(concat_ws('jeff',c7,c8,'taos')),length(concat_ws('jeff',c7,c9,'taos')) from ct1
if $rows != 50 then
return -1
endi
if $data00 != @64@ then
return -1
endi
if $data01 != @64@ then
return -1
endi
if $data02 != @64@ then
return -1
endi
if $data03 != @64@ then
return -1
endi
if $data04 != @64@ then
return -1
endi
if $data10 != @64@ then
return -1
endi
if $data11 != @64@ then
return -1
endi
if $data12 != @64@ then
return -1
endi
if $data13 != @64@ then
return -1
endi
if $data14 != @64@ then
return -1
endi
print execute sql select char_length(concat(c2,'taos',c3)),char_length(concat(c2,'taos',c4)),char_length(concat(c2,'taos',c5)),char_length(concat(c3,'taos',c4)),char_length(concat(c3,'taos',c5)) from ct1
sql select char_length(concat(c2,'taos',c3)),char_length(concat(c2,'taos',c4)),char_length(concat(c2,'taos',c5)),char_length(concat(c3,'taos',c4)),char_length(concat(c3,'taos',c5)) from ct1
if $rows != 50 then
return -1
endi
if $data00 != @8@ then
return -1
endi
if $data01 != @8@ then
return -1
endi
if $data02 != @8@ then
return -1
endi
if $data03 != @8@ then
return -1
endi
if $data04 != @8@ then
return -1
endi
if $data10 != @8@ then
return -1
endi
if $data11 != @8@ then
return -1
endi
if $data12 != @8@ then
return -1
endi
if $data13 != @8@ then
return -1
endi
if $data14 != @8@ then
return -1
endi
print execute sql select char_length(concat(c6,'taos')),char_length(concat(c7,'taos')),char_length(concat(c8,'taos')),char_length(concat(c9,'taos')) from ct1
sql select char_length(concat(c6,'taos')),char_length(concat(c7,'taos')),char_length(concat(c8,'taos')),char_length(concat(c9,'taos')) from ct1
if $rows != 50 then
return -1
endi
if $data00 != @6@ then
return -1
endi
if $data01 != @6@ then
return -1
endi
if $data02 != @6@ then
return -1
endi
if $data03 != @6@ then
return -1
endi
if $data10 != @6@ then
return -1
endi
if $data11 != @6@ then
return -1
endi
if $data12 != @6@ then
return -1
endi
if $data13 != @6@ then
return -1
endi
print execute sql select char_length(concat_ws('jeff',c2,'taos',c3)),char_length(concat_ws('jeff',c2,'taos',c4)),char_length(concat_ws('jeff',c2,'taos',c5)),char_length(concat_ws('jeff',c3,'taos',c4)),char_length(concat_ws('jeff',c3,'taos',c5)) from ct1
sql select char_length(concat_ws('jeff',c2,'taos',c3)),char_length(concat_ws('jeff',c2,'taos',c4)),char_length(concat_ws('jeff',c2,'taos',c5)),char_length(concat_ws('jeff',c3,'taos',c4)),char_length(concat_ws('jeff',c3,'taos',c5)) from ct1
if $rows != 50 then
return -1
endi
if $data00 != @16@ then
return -1
endi
if $data01 != @16@ then
return -1
endi
if $data02 != @16@ then
return -1
endi
if $data03 != @16@ then
return -1
endi
if $data04 != @16@ then
return -1
endi
if $data10 != @16@ then
return -1
endi
if $data11 != @16@ then
return -1
endi
if $data12 != @16@ then
return -1
endi
if $data13 != @16@ then
return -1
endi
if $data14 != @16@ then
return -1
endi
print execute sql select char_length(concat_ws('jeff',c6,'taos')),char_length(concat_ws('jeff',c7,'taos')),char_length(concat_ws('jeff',c8,'taos')),char_length(concat_ws('jeff',c9,'taos')) from ct1
sql select char_length(concat_ws('jeff',c6,'taos')),char_length(concat_ws('jeff',c7,'taos')),char_length(concat_ws('jeff',c8,'taos')),char_length(concat_ws('jeff',c9,'taos')) from ct1
if $rows != 50 then
return -1
endi
if $data00 != @10@ then
return -1
endi
if $data01 != @10@ then
return -1
endi
if $data02 != @10@ then
return -1
endi
if $data03 != @10@ then
return -1
endi
if $data10 != @10@ then
return -1
endi
if $data11 != @10@ then
return -1
endi
if $data12 != @10@ then
return -1
endi
if $data13 != @10@ then
return -1
endi
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
此差异已折叠。
...@@ -21,4 +21,6 @@ run general/compute/sum.sim ...@@ -21,4 +21,6 @@ run general/compute/sum.sim
run general/compute/top.sim run general/compute/top.sim
run general/compute/block_dist.sim run general/compute/block_dist.sim
run general/compute/scalar_pow.sim run general/compute/scalar_pow.sim
run general/compute/scalar_triangle.sim
run general/compute/scalar_str_concat_len.sim
run general/compute/table_group.sim run general/compute/table_group.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
$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 float, c3 bigint, c4 smallint, c5 tinyint, c6 double, c7 bool, c8 nchar(5), c9 binary(10)) TAGS (tgcol int)
$i = 0
while $i < $tbNum
$tb = $tbPrefix . $i
sql create table $tb using $mt tags( $i )
$x = 0
$y = 0.25
while $x < $rowNum
$cc = $x * 60000
$ms = 1601481600000 + $cc
sql insert into $tb values ($ms , $x , $y , $x , $x , $x , $y , $x , $x , $x )
$x = $x + 1
$y = $y + 1
endw
$i = $i + 1
endw
print ================= step2
$stb = $mtPrefix . 0
$tb = $tbPrefix . 0
print execute sql select floor(3.0)+ceil(4.0) from $tb
sql select floor(3.0)+ceil(4.0) from $tb
if $rows != 50 then
return -1
endi
if $data00 != 7.000000000 then
return -1
endi
if $data10 != 7.000000000 then
return -1
endi
if $data20 != 7.000000000 then
return -1
endi
if $data30 != 7.000000000 then
return -1
endi
if $data40 != 7.000000000 then
return -1
endi
if $data50 != 7.000000000 then
return -1
endi
if $data60 != 7.000000000 then
return -1
endi
if $data70 != 7.000000000 then
return -1
endi
if $data80 != 7.000000000 then
return -1
endi
if $data90 != 7.000000000 then
return -1
endi
print execute sql select sum(c1)+3.0+4.0 from $stb
sql select sum(c1)+3.0+4.0 from $stb
if $rows != 1 then
return -1
endi
if $data00 != 2457.000000000 then
return -1
endi
print execute sql select sin(log(avg(c1),sum(c2))+3)%4 from $stb
sql select sin(log(avg(c1),sum(c2))+3)%4 from $stb
if $rows != 1 then
return -1
endi
if $data00 != -0.265074286 then
return -1
endi
print execute sql select select log(pow(length(concat('3','4')),2),c2) from $stb
sql select log(pow(length(concat('3','4')),2),c2) from $stb
print [ $data00 , $data10 , $data20 , $data30 , $data40 , $data50 , $data60 , $data70 , $data80 , $data90 ]
if $data00 != -1.000000000 then
return -1
endi
if $data10 != @inf@ then
return -1
endi
if $data20 != 2.000000000 then
return -1
endi
if $data30 != 1.261859507 then
return -1
endi
if $data40 != 1.000000000 then
return -1
endi
if $data50 != 0.861353116 then
return -1
endi
if $data60 != 0.773705614 then
return -1
endi
if $data70 != 0.712414374 then
return -1
endi
if $data80 != 0.666666667 then
return -1
endi
if $data90 != 0.630929754 then
return -1
endi
print execute sql select round(log(pow(length(concat('3','4')),2),c2)+floor(c3))+2 from $stb
sql select round(log(pow(length(concat('3','4')),2),c2)+floor(c3))+2 from $stb
print [ $data00 , $data10 , $data20 , $data30 , $data40 , $data50 , $data60 , $data70 , $data80 , $data90 ]
if $data00 != 1.000000000 then
return -1
endi
if $data10 != @inf@ then
return -1
endi
if $data20 != 4.000000000 then
return -1
endi
if $data30 != 3.000000000 then
return -1
endi
if $data40 != 3.000000000 then
return -1
endi
if $data50 != 3.000000000 then
return -1
endi
if $data60 != 3.000000000 then
return -1
endi
if $data70 != 3.000000000 then
return -1
endi
if $data80 != 3.000000000 then
return -1
endi
if $data90 != 3.000000000 then
return -1
endi
$tb0 = $tbPrefix . 0
$tb1 = $tbPrefix . 1
print execute sql select sin(pow(c1,log(c2,2))+pow(c2,2)) as val from $tb0 union all select pow(c4,2)+tan(sin(c5)/cos(c6)) as val from $tb1
sql select sin(pow(c1,log(c2,2))+pow(c2,2)) as val from $tb0 union all select pow(c4,2)+tan(sin(c5)/cos(c6)) as val from $tb1
print [ $data00 , $data10 , $data20 , $data30 , $data40 , $data50 , $data60 , $data70 , $data80 , $data90 ]
if $data00 != @-nan@ then
return -1
endi
if $data10 != 0.909297427 then
return -1
endi
if $data20 != -0.279415498 then
return -1
endi
if $data30 != 0.843325058 then
return -1
endi
if $data40 != 0.551426681 then
return -1
endi
if $data50 != -0.840606612 then
return -1
endi
if $data60 != 0.436161076 then
return -1
endi
if $data70 != 0.897498185 then
return -1
endi
if $data80 != -0.885952778 then
return -1
endi
if $data90 != 0.429470715 then
return -1
endi
print execute sql select asin(c1) from $stb limit 1
sql select asin(c1) from $stb limit 1
if $data00 != 0.000000000 then
return -1
endi
print execute sql select pow(c1,2) from $stb limit 1 offset 2;
sql select pow(c1,2) from $stb limit 1 offset 2;
if $data00 != 4.000000000 then
return -1
endi
print exeucte sql select cos(c1) from db0.ct0, db0.ct1 where ct0.ts==ct1.ts;
sql select cos(c1) from db0.ct0, db0.ct1 where ct0.ts==ct1.ts
if $rows != 50 then
return -1
endi
if $data10 != 0.540302306 then
return -1
endi
print ============== invalid expressions
sql_error select agg(c1)+c2 from $stb
sql_error select agg(c1+2) from $stb
sql_error select agg(ceil(c1))+c2 from $stb
sql_error select agg(ceil(c1)) from $stb
sql_error select asin(c1) from $stb group by tbname
sql_error select asin(c2) from $stb group by tgcol
sql_error select asin(c1) from $stb session_window(ts, 1s)
sql_error select cos(c1) from $stb state_window(f1)
sql_error select pow(c2,2) from $stb interval(1s) sliding(500a)
sql_error select pow(c2,2) from $stb state_window(f1)
sql_error select tan(f1) from $stb from d.st slimit 1
sql_error select f1+2, tbname from $stb group by tbname
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
...@@ -39,6 +39,8 @@ run general/compute/sum.sim ...@@ -39,6 +39,8 @@ run general/compute/sum.sim
run general/compute/top.sim run general/compute/top.sim
run general/compute/block_dist.sim run general/compute/block_dist.sim
run general/compute/scalar_pow.sim run general/compute/scalar_pow.sim
run general/compute/scalar_triangle.sim
run general/compute/scalar_str_concat_len.sim
run general/compute/table_group.sim run general/compute/table_group.sim
run general/db/alter_option.sim run general/db/alter_option.sim
run general/db/alter_tables_d2.sim run general/db/alter_tables_d2.sim
...@@ -142,6 +144,7 @@ run general/parser/tags_dynamically_specifiy.sim ...@@ -142,6 +144,7 @@ run general/parser/tags_dynamically_specifiy.sim
run general/parser/set_tag_vals.sim run general/parser/set_tag_vals.sim
run general/parser/repeatAlter.sim run general/parser/repeatAlter.sim
run general/parser/precision_ns.sim run general/parser/precision_ns.sim
run general/parser/scalar_expression.sim
##unsupport run general/parser/slimit_alter_tags.sim ##unsupport run general/parser/slimit_alter_tags.sim
run general/stable/disk.sim run general/stable/disk.sim
run general/stable/dnode3.sim run general/stable/dnode3.sim
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册