提交 e5e8f6d7 编写于 作者: D dapan1121

[TD-6140]

上级 838e5667
......@@ -499,6 +499,8 @@ bool tscHasReachLimitation(SQueryInfo *pQueryInfo, SSqlRes *pRes);
void tscSetBoundColumnInfo(SParsedDataColInfo *pColInfo, SSchema *pSchema, int32_t numOfCols);
char *tscGetErrorMsgPayload(SSqlCmd *pCmd);
int32_t tscGetErrorMsgLength(SSqlCmd* pCmd);
int32_t tscErrorMsgWithCode(int32_t code, char* dstBuffer, const char* errMsg, const char* sql);
int32_t tscInvalidOperationMsg(char *msg, const char *additionalInfo, const char *sql);
......
......@@ -1766,6 +1766,10 @@ static int32_t handleScalarTypeExpr(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32
if (ret != TSDB_CODE_SUCCESS) {
taosArrayDestroy(colList);
tExprTreeDestroy(pNode, NULL);
if (tscGetErrorMsgLength(pCmd) > 0) {
return ret;
}
return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg2);
}
......@@ -1776,7 +1780,7 @@ static int32_t handleScalarTypeExpr(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32
if (TSDB_COL_IS_TAG(pIndex->flag)) {
tExprTreeDestroy(pNode, NULL);
taosArrayDestroy(colList);
return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg3);
}
}
......@@ -1785,6 +1789,10 @@ static int32_t handleScalarTypeExpr(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32
if (ret != TSDB_CODE_SUCCESS) {
taosArrayDestroy(colList);
tExprTreeDestroy(pNode, NULL);
if (tscGetErrorMsgLength(pCmd) > 0) {
return ret;
}
return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg2);
}
......@@ -1892,17 +1900,16 @@ static int32_t handleAggTypeExpr(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t
}
static int32_t handleSQLExprItem(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t exprIndex, tSqlExprItem* pItem) {
const char* msg1 = "invalid column name, illegal column type, or columns in arithmetic expression from two tables";
SColumnList columnList = {0};
int32_t sqlExprType = SQLEXPR_TYPE_UNASSIGNED;
uint64_t uid;
if (validateSQLExprItem(pCmd, pItem->pNode, pQueryInfo, &columnList, &sqlExprType, &uid) != TSDB_CODE_SUCCESS) {
return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg1);
int32_t code = validateSQLExprItem(pCmd, pItem->pNode, pQueryInfo, &columnList, &sqlExprType, &uid);
if (code != TSDB_CODE_SUCCESS) {
return code;
}
int32_t code = TSDB_CODE_SUCCESS;
if (sqlExprType == SQLEXPR_TYPE_SCALAR) {
code = handleScalarTypeExpr(pCmd, pQueryInfo, exprIndex, pItem, &columnList, true);
} else {
......@@ -4279,6 +4286,9 @@ static int32_t getJoinCondInfo(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSqlExpr*
static int32_t validateSQLExprItemSQLFunc(SSqlCmd* pCmd, tSqlExpr* pExpr,
SQueryInfo* pQueryInfo, SColumnList* pList, int32_t* type, uint64_t *uid) {
int32_t code = TSDB_CODE_SUCCESS;
const char* msg1 = "invalid function parameters";
const char* msg2 = "not supported functions in arithmetic expression";
int32_t functionId = isValidFunction(pExpr->Expr.operand.z, pExpr->Expr.operand.n);
pExpr->functionId = functionId;
......@@ -4297,7 +4307,7 @@ static int32_t validateSQLExprItemSQLFunc(SSqlCmd* pCmd, tSqlExpr* pExpr,
if (!TSDB_FUNC_IS_SCALAR(functionId) &&
(pParamElem->pNode->type == SQL_NODE_EXPR || pParamElem->pNode->type == SQL_NODE_SQLFUNCTION)) {
return TSDB_CODE_TSC_INVALID_OPERATION;
return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg1);
}
}
......@@ -4313,7 +4323,7 @@ static int32_t validateSQLExprItemSQLFunc(SSqlCmd* pCmd, tSqlExpr* pExpr,
anyChildAgg = anyChildAgg || (childrenTypes[i] == SQLEXPR_TYPE_AGG);
}
if (anyChildAgg && anyChildScalar) {
return TSDB_CODE_TSC_INVALID_OPERATION;
return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg1);
}
if (anyChildAgg) {
*type = SQLEXPR_TYPE_AGG;
......@@ -4359,7 +4369,7 @@ static int32_t validateSQLExprItemSQLFunc(SSqlCmd* pCmd, tSqlExpr* pExpr,
// It is invalid in case of more than one sqlExpr, such as first(ts, k) - last(ts, k)
int32_t inc = (int32_t)tscNumOfExprs(pQueryInfo) - outputIndex;
if (inc > 1) {
return TSDB_CODE_TSC_INVALID_OPERATION;
return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg2);
}
// Not supported data type in arithmetic expression
......@@ -4394,6 +4404,9 @@ static int32_t validateSQLExprItemArithmeticExpr(SSqlCmd* pCmd, tSqlExpr* pExpr,
uint64_t uidRight = 0;
int32_t leftType = SQLEXPR_TYPE_UNASSIGNED;
int32_t rightType = SQLEXPR_TYPE_UNASSIGNED;
const char* msg1 = "arithmetic expression composed with columns from different tables";
const char* msg2 = "arithmetic expression composed with functions/columns of different types";
int32_t ret = validateSQLExprItem(pCmd, pExpr->pLeft, pQueryInfo, pList, &leftType, &uidLeft);
if (ret != TSDB_CODE_SUCCESS) {
return ret;
......@@ -4404,7 +4417,7 @@ static int32_t validateSQLExprItemArithmeticExpr(SSqlCmd* pCmd, tSqlExpr* pExpr,
}
if (uidLeft != uidRight && uidLeft != 0 && uidRight != 0) {
return TSDB_CODE_TSC_INVALID_OPERATION;
return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg1);
}
*uid = uidLeft;
......@@ -4412,11 +4425,8 @@ static int32_t validateSQLExprItemArithmeticExpr(SSqlCmd* pCmd, tSqlExpr* pExpr,
assert(leftType != SQLEXPR_TYPE_UNASSIGNED && rightType != SQLEXPR_TYPE_UNASSIGNED);
// return invalid operation when one child aggregate and the other child scalar or column
if (leftType == SQLEXPR_TYPE_AGG && rightType == SQLEXPR_TYPE_SCALAR) {
return TSDB_CODE_TSC_INVALID_OPERATION;
}
if (rightType == SQLEXPR_TYPE_AGG && leftType == SQLEXPR_TYPE_SCALAR) {
return TSDB_CODE_TSC_INVALID_OPERATION;
if ((leftType == SQLEXPR_TYPE_AGG && rightType == SQLEXPR_TYPE_SCALAR) || (rightType == SQLEXPR_TYPE_AGG && leftType == SQLEXPR_TYPE_SCALAR)) {
return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg2);
}
if (leftType == SQLEXPR_TYPE_AGG || rightType == SQLEXPR_TYPE_AGG) {
......@@ -4432,6 +4442,10 @@ static int32_t validateSQLExprItemArithmeticExpr(SSqlCmd* pCmd, tSqlExpr* pExpr,
static int32_t validateSQLExprItem(SSqlCmd* pCmd, tSqlExpr* pExpr,
SQueryInfo* pQueryInfo, SColumnList* pList, int32_t* type, uint64_t* uid) {
const char* msg1 = "invalid column name in select clause";
const char* msg2 = "invalid data type in select clause";
const char* msg3 = "invalid select clause";
if (pExpr == NULL) {
return TSDB_CODE_SUCCESS;
}
......@@ -4450,21 +4464,26 @@ static int32_t validateSQLExprItem(SSqlCmd* pCmd, tSqlExpr* pExpr,
SColumnIndex index = COLUMN_INDEX_INITIALIZER;
if (getColumnIndexByName(&pExpr->columnName, pQueryInfo, &index, tscGetErrorMsgPayload(pCmd)) !=
TSDB_CODE_SUCCESS) {
return TSDB_CODE_TSC_INVALID_OPERATION;
return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg1);
}
pList->ids[pList->num++] = index;
*type = SQLEXPR_TYPE_SCALAR;
} else if (pExpr->type == SQL_NODE_DATA_TYPE) {
if (pExpr->dataType.type < 0 || pExpr->dataType.bytes <= 0) {
return TSDB_CODE_TSC_INVALID_OPERATION;
return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg2);
}
*type = SQLEXPR_TYPE_SCALAR;
} else {
if ((pExpr->tokenId == TK_FLOAT && (isnan(pExpr->value.dKey) || isinf(pExpr->value.dKey))) ||
pExpr->tokenId == TK_NULL) {
return TSDB_CODE_TSC_INVALID_OPERATION;
return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg3);
}
if (pExpr->value.nType == (uint32_t)-1) {
return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg3);
}
if (pExpr->type == SQL_NODE_VALUE) {
*type = SQLEXPR_TYPE_VALUE;
}
......
......@@ -4370,6 +4370,8 @@ bool tscHasReachLimitation(SQueryInfo* pQueryInfo, SSqlRes* pRes) {
char* tscGetErrorMsgPayload(SSqlCmd* pCmd) { return pCmd->payload; }
int32_t tscGetErrorMsgLength(SSqlCmd* pCmd) { return strlen(pCmd->payload); }
/**
* If current vnode query does not return results anymore (pRes->numOfRows == 0), try the next vnode if exists,
* while multi-vnode super table projection query and the result does not reach the limitation.
......
......@@ -158,7 +158,7 @@ static uint8_t UNUSED_FUNC isQueryOnPrimaryKey(const char *primaryColumnName, co
}
}
static void reverseCopy(char* dest, const char* src, int16_t type, int32_t numOfRows) {
static void reverseCopy(char* dest, const char* src, int16_t type, int32_t numOfRows, int16_t colSize) {
switch(type) {
case TSDB_DATA_TYPE_TINYINT:
case TSDB_DATA_TYPE_UTINYINT:{
......@@ -219,6 +219,13 @@ static void reverseCopy(char* dest, const char* src, int16_t type, int32_t numOf
}
return;
}
case TSDB_DATA_TYPE_BINARY:
case TSDB_DATA_TYPE_NCHAR:{
for(int32_t i = 0; i < numOfRows; ++i) {
memcpy(dest + i * colSize, src + (numOfRows - i - 1) * colSize, colSize);
}
return;
}
default: assert(0);
}
}
......@@ -318,7 +325,7 @@ void exprTreeNodeTraverse(tExprNode *pExpr, int32_t numOfRows, tExprOperandInfo
} else if (pExpr->nodeType == TSQL_NODE_COL) {
char *pInputData = getSourceDataBlock(param, pExpr->pSchema->name, pExpr->pSchema->colId);
if (order == TSDB_ORDER_DESC) {
reverseCopy(pOutput, pInputData, pExpr->pSchema->type, numOfRows);
reverseCopy(pOutput, pInputData, pExpr->pSchema->type, numOfRows, pExpr->pSchema->bytes);
} else {
memcpy(pOutput, pInputData, pExpr->pSchema->bytes*numOfRows);
}
......@@ -364,7 +371,7 @@ void exprTreeFunctionNodeTraverse(tExprNode *pExpr, int32_t numOfRows, tExprOper
for (int i = 0; i < numChildren; ++i) {
tExprNode *pChild = pExpr->_func.pChildren[i];
if (pChild->nodeType == TSQL_NODE_EXPR || pChild->nodeType == TSQL_NODE_FUNC) {
pChildrenOutput[i] = malloc((pChild->resultBytes + 1) * numOfRows);
pChildrenOutput[i] = malloc(pChild->resultBytes * numOfRows);
pChildrenResults[i].data = pChildrenOutput[i];
exprTreeInternalNodeTraverse(pChild, numOfRows, pChildrenResults+i, param, order, getSourceDataBlock);
pInputs[i].data = pChildrenOutput[i];
......@@ -373,15 +380,15 @@ void exprTreeFunctionNodeTraverse(tExprNode *pExpr, int32_t numOfRows, tExprOper
assert(pChild->resultType == pChild->pSchema->type && pChild->resultBytes == pChild->pSchema->bytes);
char *pInputData = getSourceDataBlock(param, pChild->pSchema->name, pChild->pSchema->colId);
if (order == TSDB_ORDER_DESC) {
pChildrenOutput[i] = malloc((pChild->pSchema->bytes + 1) * numOfRows);
reverseCopy(pChildrenOutput[i], pInputData, pChild->pSchema->type, numOfRows);
pChildrenOutput[i] = malloc(pChild->pSchema->bytes * numOfRows);
reverseCopy(pChildrenOutput[i], pInputData, pChild->pSchema->type, numOfRows, pChild->pSchema->bytes);
pInputs[i].data = pChildrenOutput[i];
} else {
pInputs[i].data = pInputData;
}
pInputs[i].numOfRows = (int16_t)numOfRows;
} else if (pChild->nodeType == TSQL_NODE_VALUE) {
pChildrenOutput[i] = malloc(pChild->resultBytes + 1);
pChildrenOutput[i] = malloc(pChild->resultBytes);
tVariantDump(pChild->pVal, pChildrenOutput[i], pChild->resultType, true);
pInputs[i].data = pChildrenOutput[i];
pInputs[i].numOfRows = 1;
......@@ -407,115 +414,79 @@ void exprTreeExprNodeTraverse(tExprNode *pExpr, int32_t numOfRows, tExprOperandI
tExprNode *pLeft = pExpr->_node.pLeft;
tExprNode *pRight = pExpr->_node.pRight;
/* the left output has result from the left child syntax tree */
char *pLeftOutput = (char*)malloc(sizeof(int64_t) * numOfRows);
tExprOperandInfo left;
left.type = TSDB_DATA_TYPE_DOUBLE;
left.bytes = tDataTypes[TSDB_DATA_TYPE_DOUBLE].bytes;
left.data = pLeftOutput;
char *ltmp = NULL, *rtmp = NULL;
char *leftIn = NULL, *rightIn = NULL;
int32_t leftNum = 0, rightNum = 0;
int32_t leftType = 0, rightType = 0;
int32_t fnOrder = TSDB_ORDER_ASC;
if (pLeft->nodeType == TSQL_NODE_EXPR || pLeft->nodeType == TSQL_NODE_FUNC) {
ltmp = (char*)malloc(sizeof(int64_t) * numOfRows);
tExprOperandInfo left;
left.data = ltmp;
exprTreeInternalNodeTraverse(pLeft, numOfRows, &left, param, order, getSourceDataBlock);
}
/* the right output has result from the right child syntax tree */
char *pRightOutput = malloc(sizeof(int64_t) * numOfRows);
tExprOperandInfo right;
right.type = TSDB_DATA_TYPE_DOUBLE;
right.bytes = tDataTypes[TSDB_DATA_TYPE_DOUBLE].bytes;
right.data = pRightOutput;
leftIn = ltmp;
leftType = left.type;
leftNum = left.numOfRows;
} else if (pLeft->nodeType == TSQL_NODE_COL) {
char *pInputData = getSourceDataBlock(param, pLeft->pSchema->name, pLeft->pSchema->colId);
if (order == TSDB_ORDER_DESC && (pRight->nodeType != TSQL_NODE_COL)) {
ltmp = malloc(sizeof(int64_t) * numOfRows);
reverseCopy(ltmp, pInputData, pLeft->pSchema->type, numOfRows, pLeft->pSchema->bytes);
leftIn = ltmp;
} else {
leftIn = pInputData;
fnOrder = order;
}
char *pData = malloc(sizeof(int64_t) * numOfRows);
leftType = pLeft->pSchema->type;
leftNum = numOfRows;
} else {
assert(pLeft->nodeType == TSQL_NODE_VALUE);
leftIn = (char *)&pLeft->pVal->i64;
leftType = pLeft->pVal->nType;
leftNum = 1;
}
if (pRight->nodeType == TSQL_NODE_EXPR || pRight->nodeType == TSQL_NODE_FUNC) {
rtmp = (char*)malloc(sizeof(int64_t) * numOfRows);
tExprOperandInfo right;
right.data = rtmp;
exprTreeInternalNodeTraverse(pRight, numOfRows, &right, param, order, getSourceDataBlock);
}
if (pLeft->nodeType == TSQL_NODE_EXPR || pLeft->nodeType == TSQL_NODE_FUNC) {
if (pRight->nodeType == TSQL_NODE_EXPR || pRight->nodeType == TSQL_NODE_FUNC) {
/*
* exprLeft + exprRight
* the type of returned value of one expression is always double float precious
*/
_arithmetic_operator_fn_t OperatorFn = getArithmeticOperatorFn(pExpr->_node.optr);
OperatorFn(pLeftOutput, numOfRows, TSDB_DATA_TYPE_DOUBLE, pRightOutput, numOfRows, TSDB_DATA_TYPE_DOUBLE, output->data, TSDB_ORDER_ASC);
output->numOfRows = MAX(left.numOfRows, right.numOfRows);
} else if (pRight->nodeType == TSQL_NODE_COL) { // exprLeft + columnRight
_arithmetic_operator_fn_t OperatorFn = getArithmeticOperatorFn(pExpr->_node.optr);
// set input buffer
char *pInputData = getSourceDataBlock(param, pRight->pSchema->name, pRight->pSchema->colId);
if (order == TSDB_ORDER_DESC) {
reverseCopy(pData, pInputData, pRight->pSchema->type, numOfRows);
OperatorFn(pLeftOutput, numOfRows, TSDB_DATA_TYPE_DOUBLE, pData, numOfRows, pRight->pSchema->type, output->data, TSDB_ORDER_ASC);
} else {
OperatorFn(pLeftOutput, numOfRows, TSDB_DATA_TYPE_DOUBLE, pInputData, numOfRows, pRight->pSchema->type, output->data, TSDB_ORDER_ASC);
}
output->numOfRows = numOfRows;
} else if (pRight->nodeType == TSQL_NODE_VALUE) { // exprLeft + 12
_arithmetic_operator_fn_t OperatorFn = getArithmeticOperatorFn(pExpr->_node.optr);
OperatorFn(pLeftOutput, numOfRows, TSDB_DATA_TYPE_DOUBLE, &pRight->pVal->i64, 1, pRight->pVal->nType, output->data, TSDB_ORDER_ASC);
output->numOfRows = numOfRows;
rightIn = rtmp;
rightType = right.type;
rightNum = right.numOfRows;
} else if (pRight->nodeType == TSQL_NODE_COL) {
char *pInputData = getSourceDataBlock(param, pRight->pSchema->name, pRight->pSchema->colId);
if (order == TSDB_ORDER_DESC && (pLeft->nodeType != TSQL_NODE_COL)) {
rtmp = malloc(sizeof(int64_t) * numOfRows);
reverseCopy(rtmp, pInputData, pRight->pSchema->type, numOfRows, pRight->pSchema->bytes);
rightIn = rtmp;
} else {
rightIn = pInputData;
fnOrder = order;
}
} else if (pLeft->nodeType == TSQL_NODE_COL) {
// column data specified on left-hand-side
char *pLeftInputData = getSourceDataBlock(param, pLeft->pSchema->name, pLeft->pSchema->colId);
if (pRight->nodeType == TSQL_NODE_EXPR || pRight->nodeType == TSQL_NODE_FUNC) { // columnLeft + expr2
_arithmetic_operator_fn_t OperatorFn = getArithmeticOperatorFn(pExpr->_node.optr);
if (order == TSDB_ORDER_DESC) {
reverseCopy(pData, pLeftInputData, pLeft->pSchema->type, numOfRows);
OperatorFn(pData, numOfRows, pLeft->pSchema->type, pRightOutput, numOfRows, TSDB_DATA_TYPE_DOUBLE, output->data, TSDB_ORDER_ASC);
} else {
OperatorFn(pLeftInputData, numOfRows, pLeft->pSchema->type, pRightOutput, numOfRows, TSDB_DATA_TYPE_DOUBLE, output->data, TSDB_ORDER_ASC);
}
} else if (pRight->nodeType == TSQL_NODE_COL) { // columnLeft + columnRight
// column data specified on right-hand-side
char *pRightInputData = getSourceDataBlock(param, pRight->pSchema->name, pRight->pSchema->colId);
_arithmetic_operator_fn_t OperatorFn = getArithmeticOperatorFn(pExpr->_node.optr);
// both columns are descending order, do not reverse the source data
OperatorFn(pLeftInputData, numOfRows, pLeft->pSchema->type, pRightInputData, numOfRows, pRight->pSchema->type, output->data, order);
} else if (pRight->nodeType == TSQL_NODE_VALUE) { // columnLeft + 12
_arithmetic_operator_fn_t OperatorFn = getArithmeticOperatorFn(pExpr->_node.optr);
if (order == TSDB_ORDER_DESC) {
reverseCopy(pData, pLeftInputData, pLeft->pSchema->type, numOfRows);
OperatorFn(pData, numOfRows, pLeft->pSchema->type, &pRight->pVal->i64, 1, pRight->pVal->nType, output->data, TSDB_ORDER_ASC);
} else {
OperatorFn(pLeftInputData, numOfRows, pLeft->pSchema->type, &pRight->pVal->i64, 1, pRight->pVal->nType, output->data, TSDB_ORDER_ASC);
}
}
output->numOfRows = numOfRows;
rightType = pRight->pSchema->type;
rightNum = numOfRows;
} else {
// column data specified on left-hand-side
if (pRight->nodeType == TSQL_NODE_EXPR || pRight->nodeType == TSQL_NODE_FUNC) { // 12 + expr2
_arithmetic_operator_fn_t OperatorFn = getArithmeticOperatorFn(pExpr->_node.optr);
OperatorFn(&pLeft->pVal->i64, 1, pLeft->pVal->nType, pRightOutput, numOfRows, TSDB_DATA_TYPE_DOUBLE, output->data, TSDB_ORDER_ASC);
output->numOfRows = right.numOfRows;
} else if (pRight->nodeType == TSQL_NODE_COL) { // 12 + columnRight
// column data specified on right-hand-side
char *pRightInputData = getSourceDataBlock(param, pRight->pSchema->name, pRight->pSchema->colId);
_arithmetic_operator_fn_t OperatorFn = getArithmeticOperatorFn(pExpr->_node.optr);
if (order == TSDB_ORDER_DESC) {
reverseCopy(pData, pRightInputData, pRight->pSchema->type, numOfRows);
OperatorFn(&pLeft->pVal->i64, 1, pLeft->pVal->nType, pData, numOfRows, pRight->pSchema->type, output->data, TSDB_ORDER_ASC);
} else {
OperatorFn(&pLeft->pVal->i64, 1, pLeft->pVal->nType, pRightInputData, numOfRows, pRight->pSchema->type, output->data, TSDB_ORDER_ASC);
}
output->numOfRows = numOfRows;
} else if (pRight->nodeType == TSQL_NODE_VALUE) { // 12 + 12
_arithmetic_operator_fn_t OperatorFn = getArithmeticOperatorFn(pExpr->_node.optr);
OperatorFn(&pLeft->pVal->i64, 1, pLeft->pVal->nType, &pRight->pVal->i64, 1, pRight->pVal->nType, output->data, TSDB_ORDER_ASC);
output->numOfRows = 1;
}
assert(pRight->nodeType == TSQL_NODE_VALUE);
rightIn = (char *)&pRight->pVal->i64;
rightType = pRight->pVal->nType;
rightNum = 1;
}
tfree(pData);
tfree(pLeftOutput);
tfree(pRightOutput);
_arithmetic_operator_fn_t OperatorFn = getArithmeticOperatorFn(pExpr->_node.optr);
OperatorFn(leftIn, leftNum, leftType, rightIn, rightNum, rightType, output->data, fnOrder);
output->numOfRows = MAX(leftNum, rightNum);
output->type = TSDB_DATA_TYPE_DOUBLE;
output->bytes = tDataTypes[output->type].bytes;
tfree(ltmp);
tfree(rtmp);
}
static void exprTreeToBinaryImpl(SBufferWriter* bw, tExprNode* expr) {
......@@ -1168,8 +1139,11 @@ void castConvert(int16_t inputType, int16_t inputBytes, char *input, int16_t Out
switch (OutputType) {
case TSDB_DATA_TYPE_BIGINT:
if (inputType == TSDB_DATA_TYPE_BINARY) {
input[inputBytes] = 0;
*(int64_t *)output = strtoll(varDataVal(input), NULL, 10);
char *tmp = malloc(varDataLen(input) + 1);
memcpy(tmp, varDataVal(input), varDataLen(input));
tmp[varDataLen(input)] = 0;
*(int64_t *)output = strtoll(tmp, NULL, 10);
free(tmp);
} else if (inputType == TSDB_DATA_TYPE_NCHAR) {
char *newColData = calloc(1, outputBytes * TSDB_NCHAR_SIZE + 1);
int len = taosUcs4ToMbs(varDataVal(input), varDataLen(input), newColData);
......@@ -1182,8 +1156,11 @@ void castConvert(int16_t inputType, int16_t inputBytes, char *input, int16_t Out
break;
case TSDB_DATA_TYPE_UBIGINT:
if (inputType == TSDB_DATA_TYPE_BINARY) {
input[inputBytes] = 0;
*(uint64_t *)output = strtoull(varDataVal(input), NULL, 10);
char *tmp = malloc(varDataLen(input) + 1);
memcpy(tmp, varDataVal(input), varDataLen(input));
tmp[varDataLen(input)] = 0;
*(uint64_t *)output = strtoull(tmp, NULL, 10);
free(tmp);
} else if (inputType == TSDB_DATA_TYPE_NCHAR) {
char *newColData = calloc(1, outputBytes * TSDB_NCHAR_SIZE + 1);
int len = taosUcs4ToMbs(varDataVal(input), varDataLen(input), newColData);
......@@ -1206,12 +1183,16 @@ void castConvert(int16_t inputType, int16_t inputBytes, char *input, int16_t Out
int32_t len = sprintf(varDataVal(output), "%.*s", (int32_t)(outputBytes - VARSTR_HEADER_SIZE), *(int8_t*)input ? "true" : "false");
varDataSetLen(output, len);
} else if (inputType == TSDB_DATA_TYPE_BINARY) {
int32_t len = sprintf(varDataVal(output), "%.*s", (int32_t)(outputBytes - VARSTR_HEADER_SIZE), input);
char *tmp = malloc(varDataLen(input) + 1);
memcpy(tmp, varDataVal(input), varDataLen(input));
tmp[varDataLen(input)] = 0;
int32_t len = sprintf(varDataVal(output), "%.*s", (int32_t)(outputBytes - VARSTR_HEADER_SIZE), tmp);
varDataSetLen(output, len);
free(tmp);
} else if (inputType == TSDB_DATA_TYPE_TIMESTAMP || inputType == TSDB_DATA_TYPE_NCHAR) {
assert(0);
} else {
char tmp[64] = {0};
char tmp[400] = {0};
NUM_TO_STRING(inputType, input, sizeof(tmp), tmp);
int32_t len = strlen(tmp);
len = (outputBytes - VARSTR_HEADER_SIZE) > len ? len : (outputBytes - VARSTR_HEADER_SIZE);
......@@ -1237,7 +1218,7 @@ void castConvert(int16_t inputType, int16_t inputBytes, char *input, int16_t Out
memcpy(output, input, len);
varDataSetLen(output, len - VARSTR_HEADER_SIZE);
} else {
char tmp[64] = {0};
char tmp[400] = {0};
NUM_TO_STRING(inputType, input, sizeof(tmp), tmp);
int32_t len = ncharSize > strlen(tmp) ? strlen(tmp) : ncharSize;
taosMbsToUcs4(tmp, len, varDataVal(output), outputBytes - VARSTR_HEADER_SIZE, &len);
......
......@@ -147,10 +147,10 @@ typedef struct {
snprintf(_output, (int32_t)(_outputBytes), "%" PRIu64, *(uint64_t *)(_input)); \
break; \
case TSDB_DATA_TYPE_FLOAT: \
snprintf(_output, (int32_t)(_outputBytes), "%e", *(float *)(_input)); \
snprintf(_output, (int32_t)(_outputBytes), "%f", *(float *)(_input)); \
break; \
case TSDB_DATA_TYPE_DOUBLE: \
snprintf(_output, (int32_t)(_outputBytes), "%e", *(double *)(_input)); \
snprintf(_output, (int32_t)(_outputBytes), "%f", *(double *)(_input)); \
break; \
case TSDB_DATA_TYPE_UINT: \
snprintf(_output, (int32_t)(_outputBytes), "%u", *(uint32_t *)(_input)); \
......
......@@ -637,7 +637,7 @@ static void shellPrintNChar(const char *str, int length, int width) {
static void printField(const char* val, TAOS_FIELD* field, int width, int32_t length, int precision) {
if (val == NULL) {
int w = width;
if (field->type < TSDB_DATA_TYPE_TINYINT || field->type > TSDB_DATA_TYPE_DOUBLE) {
if (field->type == TSDB_DATA_TYPE_BINARY || field->type == TSDB_DATA_TYPE_NCHAR || field->type == TSDB_DATA_TYPE_TIMESTAMP) {
w = 0;
}
w = printf("%*s", w, TSDB_DATA_NULL_STR);
......
......@@ -769,6 +769,10 @@ void tSetColumnType(TAOS_FIELD *pField, SStrToken *type) {
pField->bytes = (int16_t)bytes;
}
} else {
if (type->type > 0) {
pField->type = -1;
}
}
}
......
......@@ -13,467 +13,93 @@ sql connect
sql drop database if exists db
sql create database if not exists db
sql use db
sql create table stb1 (ts timestamp, c1 bool, c2 tinyint, c3 smallint, c4 int, c5 bigint, c6 float, c7 double, c8 binary(10), c9 nchar(10), c10 tinyint unsigned, c11 smallint unsigned, c12 int unsigned, c13 bigint unsigned) TAGS(t1 int, t2 binary(10), t3 double)
sql create table stb1 (ts timestamp, c1 bool, c2 tinyint, c3 smallint, c4 int, c5 bigint, c6 float, c7 double, c8 binary(10), c9 nchar(10), c10 tinyint unsigned, c11 smallint unsigned, c12 int unsigned, c13 bigint unsigned) TAGS(t1 int, t2 binary(10), t3 double);
sql create table tb1 using stb1 tags(1,'1',1.0)
sql create table tb2 using stb1 tags(2,'2',2.0)
sql create table tb1 using stb1 tags(1,'1',1.0);
sql create table tb2 using stb1 tags(2,'2',2.0);
sql create table tb3 using stb1 tags(3,'3',3.0);
sql insert into tb1 values ('2021-11-11 09:00:00',true,1,1,1,1,1,1,"1","1",1,1,1,1);
sql insert into tb1 values ('2021-11-11 09:00:00',true,1,1,1,1,1,1,"123","1234",1,1,1,1);
sql insert into tb1 values ('2021-11-11 09:00:01',true,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL);
sql insert into tb1 values ('2021-11-11 09:00:02',true,2,NULL,2,NULL,2,NULL,"2",NULL,2,NULL,2,NULL);
sql insert into tb1 values ('2021-11-11 09:00:03',false,NULL,3,NULL,3,NULL,3,NULL,"3",NULL,3,NULL,3);
sql insert into tb1 values ('2021-11-11 09:00:04',true,4,4,4,4,4,4,"4","4",4,4,4,4);
sql insert into tb1 values ('2021-11-11 09:00:05',true,127,32767,2147483647,9223372036854775807,3.402823466e+38,1.79769e+308,"5","5",254,65534,4294967294,9223372036854775807);
sql insert into tb1 values ('2021-11-11 09:00:06',true,-127,-32767,-2147483647,-9223372036854775807,-3.402823466e+38,-1.79769e+308,"6","6",0,0,0,0);
sql_error select cast(* as tinyint) from tb1;
sql_error select cast(* as smallint) from tb1;
sql_error select cast(* as int) from tb1;
sql_error select cast(* as bool) from tb1;
sql_error select cast(* as bigint) as a from tb1;
sql_error select cast(* as bigint) + 1 as a from tb1;
sql_error select cast(tb1.* as bigint) + 1 as a from tb1;
sql_error select cast(* as bigint) from tb1;
sql_error select cast(c1 + c2 as bigint) from tb1;
sql_error select cast(c1 as binary(0)) from tb1;
sql_error select cast(c1 as binary(-1)) from tb1;
sql_error select cast(c1 as nchar(0)) from tb1;
sql_error select cast(c1 as nchar(-1)) from tb1;
sql_error select cast(c1 as tinyint) from tb1;
sql_error select cast(c1 as bool) from tb1;
sql_error select cast(c1 as smallint) from tb1;
sql_error select cast(c1 as int) from tb1;
sql_error select cast(c1 as float) from tb1;
sql_error select cast(c1 as double) from tb1;
sql_error select cast(c1 as tinyint unsigned) from tb1;
sql_error select cast(c1 as smallint unsigned) from tb1;
sql_error select cast(c1 as int unsigned) from tb1;
sql_error select cast(c2 as binary(0)) from tb1;
sql_error select cast(c2 as binary(-1)) from tb1;
sql_error select cast(c2 as nchar(0)) from tb1;
sql_error select cast(c2 as nchar(-1)) from tb1;
sql_error select cast(c2 as tinyint) from tb1;
sql_error select cast(c2 as bool) from tb1;
sql_error select cast(c2 as smallint) from tb1;
sql_error select cast(c2 as int) from tb1;
sql_error select cast(c2 as float) from tb1;
sql_error select cast(c2 as double) from tb1;
sql_error select cast(c2 as tinyint unsigned) from tb1;
sql_error select cast(c2 as smallint unsigned) from tb1;
sql_error select cast(c2 as int unsigned) from tb1;
sql select cast(c1 as bigint) from tb1;
if $rows != 7 then
return -1
endi
if $data00 != 1 then
return -1
endi
if $data10 != 1 then
return -1
endi
if $data20 != 1 then
return -1
endi
if $data30 != 0 then
return -1
endi
if $data40 != 1 then
return -1
endi
if $data50 != 1 then
return -1
endi
if $data60 != 1 then
return -1
endi
sql select cast(c1 as binary(10)) from tb1;
if $rows != 7 then
return -1
endi
if $data00 != true then
return -1
endi
if $data10 != true then
return -1
endi
if $data20 != true then
return -1
endi
if $data30 != false then
return -1
endi
if $data40 != true then
return -1
endi
if $data50 != true then
return -1
endi
if $data60 != true then
return -1
endi
sql select cast(c1 as binary(1)) from tb1;
if $rows != 7 then
return -1
endi
if $data00 != t then
return -1
endi
if $data10 != t then
return -1
endi
if $data20 != t then
return -1
endi
if $data30 != f then
return -1
endi
if $data40 != t then
return -1
endi
if $data50 != t then
return -1
endi
if $data60 != t then
return -1
endi
sql select cast(c1 as timestamp) from tb1;
if $rows != 7 then
return -1
endi
if $data00 != @70-01-01 08:00:00.001@ then
return -1
endi
if $data10 != @70-01-01 08:00:00.001@ then
return -1
endi
if $data20 != @70-01-01 08:00:00.001@ then
return -1
endi
if $data30 != @70-01-01 08:00:00.000@ then
return -1
endi
if $data40 != @70-01-01 08:00:00.001@ then
return -1
endi
if $data50 != @70-01-01 08:00:00.001@ then
return -1
endi
if $data60 != @70-01-01 08:00:00.001@ then
return -1
endi
sql select cast(c1 as nchar(10)) from tb1;
if $rows != 7 then
return -1
endi
if $data00 != true then
return -1
endi
if $data10 != true then
return -1
endi
if $data20 != true then
return -1
endi
if $data30 != false then
return -1
endi
if $data40 != true then
return -1
endi
if $data50 != true then
return -1
endi
if $data60 != true then
return -1
endi
sql select cast(c1 as nchar(1)) from tb1;
if $rows != 7 then
return -1
endi
if $data00 != t then
return -1
endi
if $data10 != t then
return -1
endi
if $data20 != t then
return -1
endi
if $data30 != f then
return -1
endi
if $data40 != t then
return -1
endi
if $data50 != t then
return -1
endi
if $data60 != t then
return -1
endi
sql select cast(c1 as bigint unsigned) from tb1;
if $rows != 7 then
return -1
endi
if $data00 != 1 then
return -1
endi
if $data10 != 1 then
return -1
endi
if $data20 != 1 then
return -1
endi
if $data30 != 0 then
return -1
endi
if $data40 != 1 then
return -1
endi
if $data50 != 1 then
return -1
endi
if $data60 != 1 then
return -1
endi
sql select cast(c2 as bigint) from tb1;
if $rows != 7 then
return -1
endi
if $data00 != 1 then
return -1
endi
if $data10 != NULL then
return -1
endi
if $data20 != 2 then
return -1
endi
if $data30 != NULL then
return -1
endi
if $data40 != 4 then
return -1
endi
if $data50 != 127 then
return -1
endi
if $data60 != -127 then
return -1
endi
sql select cast(c2 as binary(10)) from tb1;
if $rows != 7 then
return -1
endi
if $data00 != 1 then
return -1
endi
if $data10 != NULL then
return -1
endi
if $data20 != 2 then
return -1
endi
if $data30 != NULL then
return -1
endi
if $data40 != 4 then
return -1
endi
if $data50 != 127 then
return -1
endi
if $data60 != -127 then
return -1
endi
sql select cast(c2 as binary(1)) from tb1;
if $rows != 7 then
return -1
endi
if $data00 != 1 then
return -1
endi
if $data10 != NULL then
return -1
endi
if $data20 != 2 then
return -1
endi
if $data30 != NULL then
return -1
endi
if $data40 != 4 then
return -1
endi
if $data50 != 1 then
return -1
endi
if $data60 != - then
return -1
endi
sql select cast(c2 as timestamp) from tb1;
if $rows != 7 then
return -1
endi
if $data00 != @70-01-01 08:00:00.001@ then
return -1
endi
if $data10 != NULL then
return -1
endi
if $data20 != @70-01-01 08:00:00.002@ then
return -1
endi
if $data30 != NULL then
return -1
endi
if $data40 != @70-01-01 08:00:00.004@ then
return -1
endi
if $data50 != @70-01-01 08:00:00.127@ then
return -1
endi
if $data60 != @70-01-01 08:00:00.-127@ then
print $data60
return -1
endi
sql select cast(c2 as nchar(10)) from tb1;
if $rows != 7 then
return -1
endi
if $data00 != 1 then
return -1
endi
if $data10 != NULL then
return -1
endi
if $data20 != 2 then
return -1
endi
if $data30 != NULL then
return -1
endi
if $data40 != 4 then
return -1
endi
if $data50 != 127 then
return -1
endi
if $data60 != -127 then
return -1
endi
sql select cast(c2 as nchar(1)) from tb1;
if $rows != 7 then
return -1
endi
if $data00 != 1 then
return -1
endi
if $data10 != NULL then
return -1
endi
if $data20 != 2 then
return -1
endi
if $data30 != NULL then
return -1
endi
if $data40 != 4 then
return -1
endi
if $data50 != 1 then
return -1
endi
if $data60 != - then
return -1
endi
sql select cast(c2 as bigint unsigned) from tb1;
if $rows != 7 then
return -1
endi
if $data00 != 1 then
return -1
endi
if $data10 != 1 then
return -1
endi
if $data20 != 1 then
return -1
endi
if $data30 != 0 then
return -1
endi
if $data40 != 1 then
return -1
endi
if $data50 != 1 then
return -1
endi
if $data60 != 1 then
return -1
endi
sql select cast(c2 + c3 as bigint) from tb1;
if $rows != 7 then
return -1
endi
if $data00 != 2 then
return -1
endi
if $data10 != NULL then
return -1
endi
if $data20 != NULL then
return -1
endi
if $data30 != NULL then
return -1
endi
if $data40 != 8 then
return -1
endi
if $data50 != 32894 then
return -1
endi
if $data60 != -32894 then
return -1
endi
sql select cast((c2 + c3) as bigint) from tb1;
if $rows != 7 then
return -1
endi
if $data00 != 2 then
return -1
endi
if $data10 != NULL then
return -1
endi
if $data20 != NULL then
return -1
endi
if $data30 != NULL then
return -1
endi
if $data40 != 8 then
return -1
endi
if $data50 != 32894 then
return -1
endi
if $data60 != -32894 then
return -1
endi
sql select cast(c1 as bigint)+c2 from tb1;
sql insert into tb1 values ('2021-11-11 09:00:02',true,2,NULL,2,NULL,2,NULL,"234",NULL,2,NULL,2,NULL);
sql insert into tb1 values ('2021-11-11 09:00:03',false,NULL,3,NULL,3,NULL,3,NULL,"3456",NULL,3,NULL,3);
sql insert into tb1 values ('2021-11-11 09:00:04',true,4,4,4,4,4,4,"456","4567",4,4,4,4);
sql insert into tb1 values ('2021-11-11 09:00:05',true,127,32767,2147483647,9223372036854775807,3.402823466e+38,1.79769e+308,"567","5678",254,65534,4294967294,9223372036854775807);
sql insert into tb1 values ('2021-11-11 09:00:06',true,-127,-32767,-2147483647,-9223372036854775807,-3.402823466e+38,-1.79769e+308,"678","6789",0,0,0,0);
sql insert into tb2 values ('2021-11-11 09:00:00',true,1,1,1,1,1,1,"111","1111",1,1,1,1);
sql insert into tb2 values ('2021-11-11 09:00:01',true,2,2,2,2,2,2,"222","2222",2,2,2,2);
sql insert into tb2 values ('2021-11-11 09:00:02',true,3,3,2,3,3,3,"333","3333",3,3,3,3);
sql insert into tb2 values ('2021-11-11 09:00:03',false,4,4,4,4,4,4,"444","4444",4,4,4,4);
sql insert into tb2 values ('2021-11-11 09:00:04',true,5,5,5,5,5,5,"555","5555",5,5,5,5);
sql insert into tb2 values ('2021-11-11 09:00:05',true,6,6,6,6,6,6,"666","6666",6,6,6,6);
sql insert into tb2 values ('2021-11-11 09:00:06',true,7,7,7,7,7,7,"777","7777",7,7,7,7);
sql create table tbn (ts timestamp, c1 bool, c2 tinyint, c3 smallint, c4 int, c5 bigint, c6 float, c7 double, c8 binary(10), c9 nchar(10), c10 tinyint unsigned, c11 smallint unsigned, c12 int unsigned, c13 bigint unsigned);
sql insert into tbn values ('2021-11-11 09:00:00',true,1,1,1,1,1,1,"111","1111",1,1,1,1);
sql insert into tbn values ('2021-11-11 09:00:01',true,2,2,2,2,2,2,"222","2222",2,2,2,2);
sql insert into tbn values ('2021-11-11 09:00:02',true,3,3,2,3,3,3,"333","3333",3,3,3,3);
sql insert into tbn values ('2021-11-11 09:00:03',false,4,4,4,4,4,4,"444","4444",4,4,4,4);
sql insert into tbn values ('2021-11-11 09:00:04',true,5,5,5,5,5,5,"555","5555",5,5,5,5);
sql insert into tbn values ('2021-11-11 09:00:05',true,6,6,6,6,6,6,"666","6666",6,6,6,6);
sql insert into tbn values ('2021-11-11 09:00:06',true,7,7,7,7,7,7,"777","7777",7,7,7,7);
run general/compute/cast_query1.sim
run general/compute/cast_query2.sim
sql create table stba (ts timestamp, c1 bool, c2 tinyint, c3 smallint, c4 int, c5 bigint, c6 float, c7 double, c8 binary(10), c9 nchar(10), c10 tinyint unsigned, c11 smallint unsigned, c12 int unsigned, c13 bigint unsigned) TAGS(t1 int, t2 binary(10), t3 double);
sql create table tba1 using stba tags(1,'1',1.0);
sql insert into tba1 values ('2021-11-11 09:00:00',true, 1,1,1,1,1,1,"111","1111",1,1,1,1);
sql insert into tba1 values ('2021-11-11 09:00:01',true, 2,2,2,2,2,2,"222","2222",2,2,2,2);
sql insert into tba1 values ('2021-11-11 09:00:02',true, 3,3,2,3,3,3,"333","3333",3,3,3,3);
sql insert into tba1 values ('2021-11-11 09:00:03',false,4,4,4,4,4,4,"444","4444",4,4,4,4);
sql insert into tba1 values ('2021-11-11 09:00:04',true, 5,5,5,5,5,5,"555","5555",5,5,5,5);
sql insert into tba1 values ('2021-11-11 09:00:05',true, 6,6,6,6,6,6,"666","6666",6,6,6,6);
sql insert into tba1 values ('2021-11-11 09:00:06',true, 7,7,7,7,7,7,"777","7777",7,7,7,7);
sql insert into tba1 values ('2021-11-11 09:00:07',true, 8,8,8,8,8,8,"888","8888",8,8,8,8);
sql insert into tba1 values ('2021-11-11 09:00:08',true, 9,9,9,9,9,9,"999","9999",9,9,9,9);
sql insert into tba1 values ('2021-11-11 09:00:09',true, 0,0,0,0,0,0,"000","0000",0,0,0,0);
print ================== restart server to commit data into disk
system sh/exec.sh -n dnode1 -s stop -x SIGINT
sleep 500
system sh/exec.sh -n dnode1 -s start
print ================== server restart completed
sql insert into tba1 values ('2021-11-11 09:00:10',true, 1,1,1,1,1,1,"111","1111",1,1,1,1);
sql insert into tba1 values ('2021-11-11 09:00:11',true, 2,2,2,2,2,2,"222","2222",2,2,2,2);
sql insert into tba1 values ('2021-11-11 09:00:12',true, 3,3,2,3,3,3,"333","3333",3,3,3,3);
sql insert into tba1 values ('2021-11-11 09:00:13',false,4,4,4,4,4,4,"444","4444",4,4,4,4);
sql insert into tba1 values ('2021-11-11 09:00:14',true, 5,5,5,5,5,5,"555","5555",5,5,5,5);
sql insert into tba1 values ('2021-11-11 09:00:15',true, 6,6,6,6,6,6,"666","6666",6,6,6,6);
sql insert into tba1 values ('2021-11-11 09:00:16',true, 7,7,7,7,7,7,"777","7777",7,7,7,7);
sql insert into tba1 values ('2021-11-11 09:00:17',true, 8,8,8,8,8,8,"888","8888",8,8,8,8);
sql insert into tba1 values ('2021-11-11 09:00:18',true, 9,9,9,9,9,9,"999","9999",9,9,9,9);
sql insert into tba1 values ('2021-11-11 09:00:19',true, 0,0,0,0,0,0,"000","0000",0,0,0,0);
print ================== restart server to commit data into disk
system sh/exec.sh -n dnode1 -s stop -x SIGINT
sleep 500
system sh/exec.sh -n dnode1 -s start
print ================== server restart completed
sql insert into tba1 values ('2021-11-11 09:00:20',true, 1,1,1,1,1,1,"111","1111",1,1,1,1);
sql insert into tba1 values ('2021-11-11 09:00:21',true, 2,2,2,2,2,2,"222","2222",2,2,2,2);
sql insert into tba1 values ('2021-11-11 09:00:22',true, 3,3,2,3,3,3,"333","3333",3,3,3,3);
sql insert into tba1 values ('2021-11-11 09:00:23',false,4,4,4,4,4,4,"444","4444",4,4,4,4);
sql insert into tba1 values ('2021-11-11 09:00:24',true, 5,5,5,5,5,5,"555","5555",5,5,5,5);
sql insert into tba1 values ('2021-11-11 09:00:25',true, 6,6,6,6,6,6,"666","6666",6,6,6,6);
sql insert into tba1 values ('2021-11-11 09:00:26',true, 7,7,7,7,7,7,"777","7777",7,7,7,7);
sql insert into tba1 values ('2021-11-11 09:00:27',true, 8,8,8,8,8,8,"888","8888",8,8,8,8);
sql insert into tba1 values ('2021-11-11 09:00:28',true, 9,9,9,9,9,9,"999","9999",9,9,9,9);
sql insert into tba1 values ('2021-11-11 09:00:29',true, 0,0,0,0,0,0,"000","0000",0,0,0,0);
run general/compute/cast_query1.sim
run general/compute/cast_query2.sim
#system sh/exec.sh -n dnode1 -s stop -x SIGINT
此差异已折叠。
sleep 100
sql connect
sql use db;
print "test arithmetic"
sql select cast(c2 + c3 as bigint) from tb1;
if $rows != 7 then
return -1
endi
if $data00 != 2 then
return -1
endi
if $data10 != NULL then
return -1
endi
if $data20 != NULL then
return -1
endi
if $data30 != NULL then
return -1
endi
if $data40 != 8 then
return -1
endi
if $data50 != 32894 then
return -1
endi
if $data60 != -32894 then
return -1
endi
sql select cast((c2 + c3) as bigint) from tb1;
if $rows != 7 then
return -1
endi
if $data00 != 2 then
return -1
endi
if $data10 != NULL then
return -1
endi
if $data20 != NULL then
return -1
endi
if $data30 != NULL then
return -1
endi
if $data40 != 8 then
return -1
endi
if $data50 != 32894 then
return -1
endi
if $data60 != -32894 then
return -1
endi
sql select cast((c2 * c3)+c4-6 as bigint) from tb1;
if $rows != 7 then
return -1
endi
if $data00 != -4 then
return -1
endi
if $data10 != NULL then
return -1
endi
if $data20 != NULL then
return -1
endi
if $data30 != NULL then
return -1
endi
if $data40 != 14 then
return -1
endi
if $data50 != 2151645050 then
return -1
endi
if $data60 != -2143322244 then
return -1
endi
sql select cast(11 as bigint)+c2 from tb1;
if $rows != 7 then
return -1
endi
if $data00 != 12.000000000 then
return -1
endi
if $data10 != NULL then
return -1
endi
if $data20 != 13.000000000 then
return -1
endi
if $data30 != NULL then
return -1
endi
if $data40 != 15.000000000 then
return -1
endi
if $data50 != 138.000000000 then
return -1
endi
if $data60 != -116.000000000 then
return -1
endi
sql select cast(c1 as bigint)+c2 from tb1;
if $rows != 7 then
return -1
endi
if $data00 != 2.000000000 then
return -1
endi
if $data10 != NULL then
return -1
endi
if $data20 != 3.000000000 then
return -1
endi
if $data30 != NULL then
return -1
endi
if $data40 != 5.000000000 then
return -1
endi
if $data50 != 128.000000000 then
return -1
endi
if $data60 != -126.000000000 then
return -1
endi
sql select cast(c2 as bigint)+11 from tb1;
if $rows != 7 then
return -1
endi
if $data00 != 12.000000000 then
return -1
endi
if $data10 != NULL then
return -1
endi
if $data20 != 13.000000000 then
return -1
endi
if $data30 != NULL then
return -1
endi
if $data40 != 15.000000000 then
return -1
endi
if $data50 != 138.000000000 then
return -1
endi
if $data60 != -116.000000000 then
return -1
endi
sql select cast(c2 as bigint)+11+floor(c2) from tb1;
if $rows != 7 then
return -1
endi
if $data00 != 13.000000000 then
return -1
endi
if $data10 != NULL then
return -1
endi
if $data20 != 15.000000000 then
return -1
endi
if $data30 != NULL then
return -1
endi
if $data40 != 19.000000000 then
return -1
endi
if $data50 != 265.000000000 then
return -1
endi
if $data60 != -243.000000000 then
return -1
endi
print "test function,column/tag/tbname/ts/_C0/_c0/scalar/agg/selectivity/self"
sql select cast(c1 as bigint),c1,c2 from tb1;
if $rows != 7 then
return -1
endi
if $data00 != 1 then
return -1
endi
if $data01 != 1 then
return -1
endi
if $data02 != 1 then
return -1
endi
if $data10 != 1 then
return -1
endi
if $data11 != 1 then
return -1
endi
if $data12 != NULL then
return -1
endi
if $data20 != 1 then
return -1
endi
if $data21 != 1 then
return -1
endi
if $data22 != 2 then
return -1
endi
if $data30 != 0 then
return -1
endi
if $data31 != 0 then
return -1
endi
if $data32 != NULL then
return -1
endi
if $data40 != 1 then
return -1
endi
if $data41 != 1 then
return -1
endi
if $data42 != 4 then
return -1
endi
if $data50 != 1 then
return -1
endi
if $data51 != 1 then
return -1
endi
if $data52 != 127 then
return -1
endi
if $data60 != 1 then
return -1
endi
if $data61 != 1 then
return -1
endi
if $data62 != -127 then
return -1
endi
sql select cast(c1 as bigint),t1,ts,tbname,_C0,_c0 from tb1;
if $rows != 7 then
return -1
endi
if $data00 != 1 then
return -1
endi
if $data01 != 1 then
return -1
endi
if $data02 != @21-11-11 09:00:00.000@ then
return -1
endi
if $data03 != tb1 then
return -1
endi
if $data04 != @21-11-11 09:00:00.000@ then
return -1
endi
if $data10 != 1 then
return -1
endi
if $data11 != 1 then
return -1
endi
if $data12 != @21-11-11 09:00:01.000@ then
return -1
endi
if $data13 != tb1 then
return -1
endi
if $data14 != @21-11-11 09:00:01.000@ then
return -1
endi
if $data20 != 1 then
return -1
endi
if $data21 != 1 then
return -1
endi
if $data22 != @21-11-11 09:00:02.000@ then
return -1
endi
if $data23 != tb1 then
return -1
endi
if $data24 != @21-11-11 09:00:02.000@ then
return -1
endi
if $data30 != 0 then
return -1
endi
if $data31 != 1 then
return -1
endi
if $data32 != @21-11-11 09:00:03.000@ then
return -1
endi
if $data33 != tb1 then
return -1
endi
if $data34 != @21-11-11 09:00:03.000@ then
return -1
endi
if $data40 != 1 then
return -1
endi
if $data41 != 1 then
return -1
endi
if $data42 != @21-11-11 09:00:04.000@ then
return -1
endi
if $data43 != tb1 then
return -1
endi
if $data44 != @21-11-11 09:00:04.000@ then
return -1
endi
if $data50 != 1 then
return -1
endi
if $data51 != 1 then
return -1
endi
if $data52 != @21-11-11 09:00:05.000@ then
return -1
endi
if $data53 != tb1 then
return -1
endi
if $data54 != @21-11-11 09:00:05.000@ then
return -1
endi
if $data60 != 1 then
return -1
endi
if $data61 != 1 then
return -1
endi
if $data62 != @21-11-11 09:00:06.000@ then
return -1
endi
if $data63 != tb1 then
return -1
endi
if $data64 != @21-11-11 09:00:06.000@ then
return -1
endi
sql select cast(c1 as bigint),floor(c3) from tb1;
if $rows != 7 then
return -1
endi
if $data00 != 1 then
return -1
endi
if $data01 != 1 then
return -1
endi
if $data10 != 1 then
return -1
endi
if $data11 != NULL then
return -1
endi
if $data20 != 1 then
return -1
endi
if $data21 != NULL then
return -1
endi
if $data30 != 0 then
return -1
endi
if $data31 != 3 then
return -1
endi
if $data40 != 1 then
return -1
endi
if $data41 != 4 then
return -1
endi
if $data50 != 1 then
return -1
endi
if $data51 != 32767 then
return -1
endi
if $data60 != 1 then
return -1
endi
if $data61 != -32767 then
return -1
endi
sql select cast(c1 as bigint),cast(c2+c3 as binary(6)) from tb1;
if $rows != 7 then
return -1
endi
if $data00 != 1 then
return -1
endi
if $data01 != 2.0000 then
return -1
endi
if $data10 != 1 then
return -1
endi
if $data11 != NULL then
return -1
endi
if $data20 != 1 then
return -1
endi
if $data21 != NULL then
return -1
endi
if $data30 != 0 then
return -1
endi
if $data31 != NULL then
return -1
endi
if $data40 != 1 then
return -1
endi
if $data41 != 8.0000 then
return -1
endi
if $data50 != 1 then
return -1
endi
if $data51 != 32894. then
return -1
endi
if $data60 != 1 then
return -1
endi
if $data61 != -32894 then
return -1
endi
sql select cast(c2+c3 as binary(6)) from tb1 where c2 is not null and c3 is not null;
if $rows != 4 then
return -1
endi
if $data00 != 2.0000 then
return -1
endi
if $data10 != 8.0000 then
return -1
endi
if $data20 != 32894. then
return -1
endi
if $data30 != -32894 then
return -1
endi
sql select cast(c2 as binary(6)) from tb1 order by ts desc;
if $rows != 7 then
return -1
endi
if $data00 != -127 then
return -1
endi
if $data10 != 127 then
return -1
endi
if $data20 != 4 then
return -1
endi
if $data30 != NULL then
return -1
endi
if $data40 != 2 then
return -1
endi
if $data50 != NULL then
return -1
endi
if $data60 != 1 then
return -1
endi
sql select cast(c2+c3 as binary(6)) from tb1 order by ts desc;
if $rows != 7 then
return -1
endi
if $data00 != -32894 then
return -1
endi
if $data10 != 32894. then
return -1
endi
if $data20 != 8.0000 then
return -1
endi
if $data30 != NULL then
return -1
endi
if $data40 != NULL then
return -1
endi
if $data50 != NULL then
return -1
endi
if $data60 != 2.0000 then
return -1
endi
sql select cast(c2+c3 as binary(6)) from tb1 order by ts desc limit 3 offset 2;
if $rows != 3 then
return -1
endi
if $data00 != 8.0000 then
return -1
endi
if $data10 != NULL then
return -1
endi
if $data20 != NULL then
return -1
endi
sql select cast(c2 as binary(2)) from stb1;
if $rows != 14 then
return -1
endi
if $data00 != 1 then
return -1
endi
if $data10 != NULL then
return -1
endi
if $data20 != 2 then
return -1
endi
if $data30 != NULL then
return -1
endi
if $data40 != 4 then
return -1
endi
if $data50 != 12 then
return -1
endi
if $data60 != -1 then
return -1
endi
if $data70 != 1 then
return -1
endi
if $data80 != 2 then
return -1
endi
if $data90 != 3 then
return -1
endi
sql select cast(c2 as binary(2)) from stb1 order by ts desc;
if $rows != 14 then
return -1
endi
if $data00 != -1 then
if $data00 != 7 then
return -1
endi
endi
if $data10 != 7 then
if $data10 != -1 then
return -1
endi
endi
if $data20 != 6 then
if $data20 != 12 then
return -1
endi
endi
if $data30 != 12 then
if $data30 != 6 then
return -1
endi
endi
if $data40 != 4 then
if $data40 != 5 then
return -1
endi
endi
if $data50 != 5 then
if $data50 != 4 then
return -1
endi
endi
if $data60 != 4 then
if $data60 != NULL then
return -1
endi
endi
if $data70 != NULL then
if $data70 != 4 then
return -1
endi
endi
if $data80 != 2 then
if $data80 != 3 then
return -1
endi
endi
if $data90 != 3 then
if $data90 != 2 then
return -1
endi
endi
sql select cast(c4 as bigint),t1 from stb1 order by ts desc;
if $rows != 14 then
return -1
endi
if $data00 != -2147483647 then
if $data00 != 7 then
return -1
endi
endi
if $data01 != 1 then
if $data01 != 2 then
return -1
endi
endi
if $data10 != 7 then
if $data10 != -2147483647 then
return -1
endi
endi
if $data11 != 1 then
if $data11 != 2 then
return -1
endi
endi
if $data20 != 6 then
if $data20 != 2147483647 then
return -1
endi
endi
if $data21 != 2 then
if $data21 != 1 then
return -1
endi
endi
if $data30 != 2147483647 then
if $data30 != 6 then
return -1
endi
endi
if $data31 != 1 then
if $data31 != 2 then
return -1
endi
endi
if $data40 != 4 then
if $data40 != 5 then
return -1
endi
endi
if $data41 != 1 then
if $data41 != 2 then
return -1
endi
endi
if $data50 != 5 then
if $data50 != 4 then
return -1
endi
endi
if $data51 != 1 then
if $data51 != 2 then
return -1
endi
endi
if $data60 != 4 then
if $data60 != NULL then
return -1
endi
endi
if $data61 != 2 then
if $data61 != 1 then
return -1
endi
endi
if $data70 != NULL then
if $data70 != 4 then
return -1
endi
endi
if $data71 != 1 then
if $data71 != 2 then
return -1
endi
endi
if $data80 != 2 then
if $data80 != 2 then
return -1
endi
endi
if $data81 != 1 then
if $data81 != 2 then
return -1
endi
endi
if $data90 != 2 then
return -1
endi
if $data91 != 2 then
if $data91 != 1 then
return -1
endi
endi
sql select cast(c3 as bigint),tbname from stb1;
if $rows != 14 then
return -1
endi
if $data00 != 1 then
return -1
endi
if $data01 != tb1 then
return -1
endi
if $data10 != NULL then
return -1
endi
if $data11 != tb1 then
return -1
endi
if $data20 != NULL then
return -1
endi
if $data21 != tb1 then
return -1
endi
if $data30 != 3 then
return -1
endi
if $data31 != tb1 then
return -1
endi
if $data40 != 4 then
return -1
endi
if $data41 != tb1 then
return -1
endi
if $data50 != 32767 then
return -1
endi
if $data51 != tb1 then
return -1
endi
if $data60 != -32767 then
return -1
endi
if $data61 != tb1 then
return -1
endi
if $data70 != 1 then
return -1
endi
if $data71 != tb2 then
return -1
endi
if $data80 != 2 then
return -1
endi
if $data81 != tb2 then
return -1
endi
if $data90 != 3 then
return -1
endi
if $data91 != tb2 then
return -1
endi
sql select cast(c3 as bigint),tbname from stb1 where t1 > 1;
if $rows != 7 then
return -1
endi
sql select cast(c8 as bigint),cast(c9 as bigint) from tbn;
if $rows != 7 then
return -1
endi
if $data00 != 111 then
return -1
endi
if $data01 != 1111 then
return -1
endi
if $data10 != 222 then
return -1
endi
if $data11 != 2222 then
return -1
endi
if $data20 != 333 then
return -1
endi
if $data21 != 3333 then
return -1
endi
if $data30 != 444 then
return -1
endi
if $data31 != 4444 then
return -1
endi
if $data40 != 555 then
return -1
endi
if $data41 != 5555 then
return -1
endi
if $data50 != 666 then
return -1
endi
if $data51 != 6666 then
return -1
endi
if $data60 != 777 then
return -1
endi
if $data61 != 7777 then
return -1
endi
sql select cast(c8 as bigint),cast(c9 as bigint) from tbn order by ts desc;
if $rows != 7 then
return -1
endi
if $data00 != 777 then
return -1
endi
if $data01 != 7777 then
return -1
endi
if $data10 != 666 then
return -1
endi
if $data11 != 6666 then
return -1
endi
if $data20 != 555 then
return -1
endi
if $data21 != 5555 then
return -1
endi
if $data30 != 444 then
return -1
endi
if $data31 != 4444 then
return -1
endi
if $data40 != 333 then
return -1
endi
if $data41 != 3333 then
return -1
endi
if $data50 != 222 then
return -1
endi
if $data51 != 2222 then
return -1
endi
if $data60 != 111 then
return -1
endi
if $data61 != 1111 then
return -1
endi
sql select cast(cast(c8 as binary(2)) as bigint) from tbn;
if $rows != 7 then
return -1
endi
if $data00 != 11 then
return -1
endi
if $data10 != 22 then
return -1
endi
if $data20 != 33 then
return -1
endi
if $data30 != 44 then
return -1
endi
if $data40 != 55 then
return -1
endi
if $data50 != 66 then
return -1
endi
if $data60 != 77 then
return -1
endi
sql select cast(cast(cast(cast(ts as bigint) as binary(5)) as bigint)+cast(cast(cast(ts as bigint) as binary(2)) as bigint) as bigint) from tbn;
if $rows != 7 then
return -1
endi
if $data00 != 16381 then
return -1
endi
if $data10 != 16381 then
return -1
endi
if $data20 != 16381 then
return -1
endi
if $data30 != 16381 then
return -1
endi
if $data40 != 16381 then
return -1
endi
if $data50 != 16381 then
return -1
endi
if $data60 != 16381 then
return -1
endi
sql select cast(cast(cast(cast(ts as bigint) as binary(5)) as bigint)+cast(cast(cast(ts as bigint) as binary(2)) as bigint) as bigint) from tb3;
if $rows != 0 then
return -1
endi
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册