未验证 提交 9ff4b302 编写于 作者: M Minglei Jin 提交者: GitHub

Merge pull request #11110 from taosdata/fix/TS-1210-2.4

[TS-1210]<feature>: added Bitwise AND feature
...@@ -282,6 +282,8 @@ static uint8_t convertRelationalOperator(SStrToken *pToken) { ...@@ -282,6 +282,8 @@ static uint8_t convertRelationalOperator(SStrToken *pToken) {
return TSDB_BINARY_OP_DIVIDE; return TSDB_BINARY_OP_DIVIDE;
case TK_REM: case TK_REM:
return TSDB_BINARY_OP_REMAINDER; return TSDB_BINARY_OP_REMAINDER;
case TK_BITAND:
return TSDB_BINARY_OP_BITAND;
case TK_LIKE: case TK_LIKE:
return TSDB_RELATION_LIKE; return TSDB_RELATION_LIKE;
case TK_MATCH: case TK_MATCH:
...@@ -10251,6 +10253,23 @@ int32_t exprTreeFromSqlExpr(SSqlCmd* pCmd, tExprNode **pExpr, const tSqlExpr* pS ...@@ -10251,6 +10253,23 @@ int32_t exprTreeFromSqlExpr(SSqlCmd* pCmd, tExprNode **pExpr, const tSqlExpr* pS
} }
} }
if (pSqlExpr->tokenId == TK_BITAND && pSqlExpr->pLeft != NULL && pSqlExpr->pRight != NULL) {
// for example: col type is "bool" but expr "col & 1" received
uint8_t colType = pLeft->pSchema->type;
SStrToken *exprToken = &pSqlExpr->pRight->exprToken;
if (pSqlExpr->pLeft->type == SQL_NODE_TABLE_COLUMN && pSqlExpr->pRight->type == SQL_NODE_VALUE) {
if (colType == TSDB_DATA_TYPE_BOOL) {
if ((exprToken->n != 4 || strncasecmp(exprToken->z, "true", 4)) && (exprToken->n != 5 || strncasecmp(exprToken->z, "false", 5))) {
return TSDB_CODE_TSC_INVALID_OPERATION;
}
} else if (IS_SIGNED_NUMERIC_TYPE(colType) || IS_UNSIGNED_NUMERIC_TYPE(colType)) {
if ((exprToken->n == 4 && strncasecmp(exprToken->z, "true", 4) == 0) || (exprToken->n == 5 || strncasecmp(exprToken->z, "false", 5) == 0)) {
return TSDB_CODE_TSC_INVALID_OPERATION;
}
}
}
}
if (pSqlExpr->pRight != NULL) { if (pSqlExpr->pRight != NULL) {
int32_t ret = exprTreeFromSqlExpr(pCmd, &pRight, pSqlExpr->pRight, pQueryInfo, pCols, uid); int32_t ret = exprTreeFromSqlExpr(pCmd, &pRight, pSqlExpr->pRight, pQueryInfo, pCols, uid);
if (ret != TSDB_CODE_SUCCESS) { if (ret != TSDB_CODE_SUCCESS) {
...@@ -10288,12 +10307,14 @@ int32_t exprTreeFromSqlExpr(SSqlCmd* pCmd, tExprNode **pExpr, const tSqlExpr* pS ...@@ -10288,12 +10307,14 @@ int32_t exprTreeFromSqlExpr(SSqlCmd* pCmd, tExprNode **pExpr, const tSqlExpr* pS
if (pLeft->_node.optr == TSDB_RELATION_ARROW){ if (pLeft->_node.optr == TSDB_RELATION_ARROW){
pLeft = pLeft->_node.pLeft; pLeft = pLeft->_node.pLeft;
} }
if (pRight->pVal->nType == TSDB_DATA_TYPE_BOOL && pLeft->nodeType == TSQL_NODE_COL && if (pRight->pVal->nType == TSDB_DATA_TYPE_BOOL && pLeft->nodeType == TSQL_NODE_COL) {
(pLeft->pSchema->type == TSDB_DATA_TYPE_BOOL || pLeft->pSchema->type == TSDB_DATA_TYPE_JSON)) { if (((*pExpr)->_node.optr != TSDB_BINARY_OP_BITAND && pLeft->pSchema->type == TSDB_DATA_TYPE_BOOL) ||
pLeft->pSchema->type == TSDB_DATA_TYPE_JSON) {
return TSDB_CODE_TSC_INVALID_OPERATION; return TSDB_CODE_TSC_INVALID_OPERATION;
} }
} }
} }
}
} else if (pSqlExpr->type == SQL_NODE_SQLFUNCTION) { } else if (pSqlExpr->type == SQL_NODE_SQLFUNCTION) {
if (TSDB_FUNC_IS_SCALAR(pSqlExpr->functionId)) { if (TSDB_FUNC_IS_SCALAR(pSqlExpr->functionId)) {
......
...@@ -123,6 +123,9 @@ _arithmetic_getVectorDoubleValue_fn_t getVectorDoubleValueFn(int32_t srcType) { ...@@ -123,6 +123,9 @@ _arithmetic_getVectorDoubleValue_fn_t getVectorDoubleValueFn(int32_t srcType) {
typedef void* (*_arithmetic_getVectorValueAddr_fn_t)(void *src, int32_t index); typedef void* (*_arithmetic_getVectorValueAddr_fn_t)(void *src, int32_t index);
void* getVectorValueAddr_BOOL(void *src, int32_t index) {
return (void*)((bool *)src + index);
}
void* getVectorValueAddr_TINYINT(void *src, int32_t index) { void* getVectorValueAddr_TINYINT(void *src, int32_t index) {
return (void*)((int8_t *)src + index); return (void*)((int8_t *)src + index);
} }
...@@ -156,7 +159,9 @@ void* getVectorValueAddr_DOUBLE(void *src, int32_t index) { ...@@ -156,7 +159,9 @@ void* getVectorValueAddr_DOUBLE(void *src, int32_t index) {
_arithmetic_getVectorValueAddr_fn_t getVectorValueAddrFn(int32_t srcType) { _arithmetic_getVectorValueAddr_fn_t getVectorValueAddrFn(int32_t srcType) {
_arithmetic_getVectorValueAddr_fn_t p = NULL; _arithmetic_getVectorValueAddr_fn_t p = NULL;
if(srcType==TSDB_DATA_TYPE_TINYINT) { if (srcType == TSDB_DATA_TYPE_BOOL) {
p = getVectorValueAddr_BOOL;
}else if(srcType==TSDB_DATA_TYPE_TINYINT) {
p = getVectorValueAddr_TINYINT; p = getVectorValueAddr_TINYINT;
}else if(srcType==TSDB_DATA_TYPE_UTINYINT) { }else if(srcType==TSDB_DATA_TYPE_UTINYINT) {
p = getVectorValueAddr_UTINYINT; p = getVectorValueAddr_UTINYINT;
...@@ -398,6 +403,271 @@ void vectorRemainder(void *left, int32_t len1, int32_t _left_type, void *right, ...@@ -398,6 +403,271 @@ void vectorRemainder(void *left, int32_t len1, int32_t _left_type, void *right,
} }
} }
void vectorBitand(void *left, int32_t len1, int32_t _left_type, void *right, int32_t len2, int32_t _right_type, void *out, int32_t _ord) {
int32_t i = (_ord == TSDB_ORDER_ASC) ? 0 : MAX(len1, len2) - 1;
int32_t step = (_ord == TSDB_ORDER_ASC) ? 1 : -1;
char *output = out;
_arithmetic_getVectorValueAddr_fn_t getVectorValueAddrFnLeft = getVectorValueAddrFn(_left_type);
_arithmetic_getVectorValueAddr_fn_t getVectorValueAddrFnRight = getVectorValueAddrFn(_right_type);
if (len1 == (len2)) {
for (; i >= 0 && i < (len2); i += step) {
if (isNull(getVectorValueAddrFnLeft(left, i), _left_type) || isNull(getVectorValueAddrFnRight(right, i), _right_type)) {
switch (_left_type) {
case TSDB_DATA_TYPE_BOOL:
*(bool *) output = TSDB_DATA_BOOL_NULL;
output += sizeof(bool);
break;
case TSDB_DATA_TYPE_TINYINT:
*(int8_t *) output = TSDB_DATA_TINYINT_NULL;
output += sizeof(int8_t);
break;
case TSDB_DATA_TYPE_SMALLINT:
*(int16_t *) output = TSDB_DATA_SMALLINT_NULL;
output += sizeof(int16_t);
break;
case TSDB_DATA_TYPE_INT:
*(int32_t *) output = TSDB_DATA_INT_NULL;
output += sizeof(int32_t);
break;
case TSDB_DATA_TYPE_BIGINT:
*(int64_t *) output = TSDB_DATA_BIGINT_NULL;
output += sizeof(int64_t);
break;
case TSDB_DATA_TYPE_UTINYINT:
*(uint8_t *) output = TSDB_DATA_UTINYINT_NULL;
output += sizeof(int8_t);
break;
case TSDB_DATA_TYPE_USMALLINT:
*(uint16_t *) output = TSDB_DATA_USMALLINT_NULL;
output += sizeof(int16_t);
break;
case TSDB_DATA_TYPE_UINT:
*(uint32_t *) output = TSDB_DATA_UINT_NULL;
output += sizeof(int32_t);
break;
case TSDB_DATA_TYPE_UBIGINT:
*(uint64_t *) output = TSDB_DATA_UBIGINT_NULL;
output += sizeof(int64_t);
break;
}
continue;
}
switch (_left_type) {
case TSDB_DATA_TYPE_BOOL:
*(bool *) output = (*((bool *) left + i)) & (*((bool *) right + i));
output += sizeof(bool);
break;
case TSDB_DATA_TYPE_TINYINT:
*(int8_t *) output = (*((int8_t *) left + i)) & (*((int8_t *) right + i));
output += sizeof(int8_t);
break;
case TSDB_DATA_TYPE_SMALLINT:
*(int16_t *) output = (*((int16_t *) left + i)) & (*((int16_t *) right + i));
output += sizeof(int16_t);
break;
case TSDB_DATA_TYPE_INT:
*(int32_t *) output = (*((int32_t *) left + i)) & (*((int32_t *) right + i));
output += sizeof(int32_t);
break;
case TSDB_DATA_TYPE_BIGINT:
*(int64_t *) output = (*((int64_t *) left + i)) & (*((int64_t *) right + i));
output += sizeof(int64_t);
break;
case TSDB_DATA_TYPE_UTINYINT:
*(uint8_t *) output = (*((uint8_t *) left + i)) & (*((uint8_t *) right + i));
output += sizeof(int8_t);
break;
case TSDB_DATA_TYPE_USMALLINT:
*(uint16_t *) output = (*((uint16_t *) left + i)) & (*((uint16_t *) right + i));
output += sizeof(int16_t);
break;
case TSDB_DATA_TYPE_UINT:
*(uint32_t *) output = (*((uint32_t *) left + i)) & (*((uint32_t *) right + i));
output += sizeof(int32_t);
break;
case TSDB_DATA_TYPE_UBIGINT:
*(uint64_t *) output = (*((uint64_t *) left + i)) & (*((uint64_t *) right + i));
output += sizeof(int64_t);
break;
}
}
} else if (len1 == 1) {
for (; i >= 0 && i < (len2); i += step) {
if (isNull(getVectorValueAddrFnLeft(left, 0), _left_type) || isNull(getVectorValueAddrFnRight(right, i), _right_type)) {
switch (_left_type) {
case TSDB_DATA_TYPE_BOOL:
*(bool *) output = TSDB_DATA_BOOL_NULL;
output += sizeof(bool);
break;
case TSDB_DATA_TYPE_TINYINT:
*(int8_t *) output = TSDB_DATA_TINYINT_NULL;
output += sizeof(int8_t);
break;
case TSDB_DATA_TYPE_SMALLINT:
*(int16_t *) output = TSDB_DATA_SMALLINT_NULL;
output += sizeof(int16_t);
break;
case TSDB_DATA_TYPE_INT:
*(int32_t *) output = TSDB_DATA_INT_NULL;
output += sizeof(int32_t);
break;
case TSDB_DATA_TYPE_BIGINT:
*(int64_t *) output = TSDB_DATA_BIGINT_NULL;
output += sizeof(int64_t);
break;
case TSDB_DATA_TYPE_UTINYINT:
*(uint8_t *) output = TSDB_DATA_UTINYINT_NULL;
output += sizeof(int8_t);
break;
case TSDB_DATA_TYPE_USMALLINT:
*(uint16_t *) output = TSDB_DATA_USMALLINT_NULL;
output += sizeof(int16_t);
break;
case TSDB_DATA_TYPE_UINT:
*(uint32_t *) output = TSDB_DATA_UINT_NULL;
output += sizeof(int32_t);
break;
case TSDB_DATA_TYPE_UBIGINT:
*(uint64_t *) output = TSDB_DATA_UBIGINT_NULL;
output += sizeof(int64_t);
break;
}
continue;
}
switch (_left_type) {
case TSDB_DATA_TYPE_BOOL:
*(bool *) output = (*(bool *) left) & (*((bool *) right + i));
output += sizeof(bool);
break;
case TSDB_DATA_TYPE_TINYINT:
*(int8_t *) output = (*(int8_t *) left) & (*((int8_t *) right + i));
output += sizeof(int8_t);
break;
case TSDB_DATA_TYPE_SMALLINT:
*(int16_t *) output = (*(int16_t *) left) & (*((int16_t *) right + i));
output += sizeof(int16_t);
break;
case TSDB_DATA_TYPE_INT:
*(int32_t *) output = (*(int32_t *) left) & (*((int32_t *) right + i));
output += sizeof(int32_t);
break;
case TSDB_DATA_TYPE_BIGINT:
*(int64_t *) output = (*(int64_t *) left) & (*((int64_t *) right + i));
output += sizeof(int64_t);
break;
case TSDB_DATA_TYPE_UTINYINT:
*(uint8_t *) output = (*(uint8_t *) left) & (*((uint8_t *) right + i));
output += sizeof(int8_t);
break;
case TSDB_DATA_TYPE_USMALLINT:
*(uint16_t *) output = (*(uint16_t *) left) & (*((uint16_t *) right + i));
output += sizeof(int16_t);
break;
case TSDB_DATA_TYPE_UINT:
*(uint32_t *) output = (*(uint32_t *) left) & (*((uint32_t *) right + i));
output += sizeof(int32_t);
break;
case TSDB_DATA_TYPE_UBIGINT:
*(uint64_t *) output = (*(uint64_t *) left) & (*((uint64_t *) right + i));
output += sizeof(int64_t);
break;
}
}
} else if ((len2) == 1) {
for (; i >= 0 && i < len1; i += step) {
if (isNull(getVectorValueAddrFnLeft(left, i), _left_type) || isNull(getVectorValueAddrFnRight(right, 0), _right_type)) {
switch (_left_type) {
case TSDB_DATA_TYPE_BOOL:
*(bool *) output = TSDB_DATA_BOOL_NULL;
output += sizeof(bool);
break;
case TSDB_DATA_TYPE_TINYINT:
*(int8_t *) output = TSDB_DATA_TINYINT_NULL;
output += sizeof(int8_t);
break;
case TSDB_DATA_TYPE_SMALLINT:
*(int16_t *) output = TSDB_DATA_SMALLINT_NULL;
output += sizeof(int16_t);
break;
case TSDB_DATA_TYPE_INT:
*(int32_t *) output = TSDB_DATA_INT_NULL;
output += sizeof(int32_t);
break;
case TSDB_DATA_TYPE_BIGINT:
*(int64_t *) output = TSDB_DATA_BIGINT_NULL;
output += sizeof(int64_t);
break;
case TSDB_DATA_TYPE_UTINYINT:
*(uint8_t *) output = TSDB_DATA_UTINYINT_NULL;
output += sizeof(int8_t);
break;
case TSDB_DATA_TYPE_USMALLINT:
*(uint16_t *) output = TSDB_DATA_USMALLINT_NULL;
output += sizeof(int16_t);
break;
case TSDB_DATA_TYPE_UINT:
*(uint32_t *) output = TSDB_DATA_UINT_NULL;
output += sizeof(int32_t);
break;
case TSDB_DATA_TYPE_UBIGINT:
*(uint64_t *) output = TSDB_DATA_UBIGINT_NULL;
output += sizeof(int64_t);
break;
}
continue;
}
switch (_left_type) {
case TSDB_DATA_TYPE_BOOL:
*(bool *) output = (*((bool *) left + i)) & (*(bool *) right);
output += sizeof(bool);
break;
case TSDB_DATA_TYPE_TINYINT:
*(int8_t *) output = (*((int8_t *) left + i)) & (*(int8_t *) right);
output += sizeof(int8_t);
break;
case TSDB_DATA_TYPE_SMALLINT:
*(int16_t *) output = (*((int16_t *) left + i)) & (*(int16_t *) right);
output += sizeof(int16_t);
break;
case TSDB_DATA_TYPE_INT:
*(int32_t *) output = (*((int32_t *) left + i)) & (*(int32_t *) right);
output += sizeof(int32_t);
break;
case TSDB_DATA_TYPE_BIGINT:
*(int64_t *) output = (*((int64_t *) left + i)) & (*(int64_t *) right);
output += sizeof(int64_t);
break;
case TSDB_DATA_TYPE_UTINYINT:
*(uint8_t *) output = (*((uint8_t *) left + i)) & (*(uint8_t *) right);
output += sizeof(int8_t);
break;
case TSDB_DATA_TYPE_USMALLINT:
*(uint16_t *) output = (*((uint16_t *) left + i)) & (*(uint16_t *) right);
output += sizeof(int16_t);
break;
case TSDB_DATA_TYPE_UINT:
*(uint32_t *) output = (*((uint32_t *) left + i)) & (*(uint32_t *) right);
output += sizeof(int32_t);
break;
case TSDB_DATA_TYPE_UBIGINT:
*(uint64_t *) output = (*((uint64_t *) left + i)) & (*(uint64_t *) right);
output += sizeof(int64_t);
break;
}
}
}
}
_arithmetic_operator_fn_t getArithmeticOperatorFn(int32_t arithmeticOptr) { _arithmetic_operator_fn_t getArithmeticOperatorFn(int32_t arithmeticOptr) {
switch (arithmeticOptr) { switch (arithmeticOptr) {
case TSDB_BINARY_OP_ADD: case TSDB_BINARY_OP_ADD:
...@@ -410,6 +680,8 @@ _arithmetic_operator_fn_t getArithmeticOperatorFn(int32_t arithmeticOptr) { ...@@ -410,6 +680,8 @@ _arithmetic_operator_fn_t getArithmeticOperatorFn(int32_t arithmeticOptr) {
return vectorDivide; return vectorDivide;
case TSDB_BINARY_OP_REMAINDER: case TSDB_BINARY_OP_REMAINDER:
return vectorRemainder; return vectorRemainder;
case TSDB_BINARY_OP_BITAND:
return vectorBitand;
default: default:
assert(0); assert(0);
return NULL; return NULL;
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#include "tarray.h" #include "tarray.h"
#include "tbuffer.h" #include "tbuffer.h"
#include "tcompare.h" #include "tcompare.h"
#include "tglobal.h"
#include "tsdb.h" #include "tsdb.h"
#include "tskiplist.h" #include "tskiplist.h"
#include "texpr.h" #include "texpr.h"
...@@ -47,7 +48,7 @@ static int32_t exprInvalidOperationMsg(char *msgbuf, const char *msg) { ...@@ -47,7 +48,7 @@ static int32_t exprInvalidOperationMsg(char *msgbuf, const char *msg) {
int32_t exprTreeValidateFunctionNode(char* msgbuf, tExprNode *pExpr) { int32_t exprTreeValidateFunctionNode(char* msgbuf, tExprNode *pExpr) {
int32_t code = TSDB_CODE_SUCCESS; int32_t code = TSDB_CODE_SUCCESS;
//TODO: check childs for every function //TODO: check children for every function
switch (pExpr->_func.functionId) { switch (pExpr->_func.functionId) {
case TSDB_FUNC_SCALAR_POW: case TSDB_FUNC_SCALAR_POW:
case TSDB_FUNC_SCALAR_LOG: case TSDB_FUNC_SCALAR_LOG:
...@@ -85,17 +86,184 @@ int32_t exprTreeValidateFunctionNode(char* msgbuf, tExprNode *pExpr) { ...@@ -85,17 +86,184 @@ int32_t exprTreeValidateFunctionNode(char* msgbuf, tExprNode *pExpr) {
} }
int32_t exprTreeValidateExprNode(tExprNode *pExpr) { int32_t exprTreeValidateExprNode(tExprNode *pExpr) {
int16_t leftType = pExpr->_node.pLeft->resultType;
int16_t rightType = pExpr->_node.pRight->resultType;
int16_t resultType = leftType;
if (pExpr->_node.optr == TSDB_BINARY_OP_ADD || pExpr->_node.optr == TSDB_BINARY_OP_SUBTRACT || if (pExpr->_node.optr == TSDB_BINARY_OP_ADD || pExpr->_node.optr == TSDB_BINARY_OP_SUBTRACT ||
pExpr->_node.optr == TSDB_BINARY_OP_MULTIPLY || pExpr->_node.optr == TSDB_BINARY_OP_DIVIDE || pExpr->_node.optr == TSDB_BINARY_OP_MULTIPLY || pExpr->_node.optr == TSDB_BINARY_OP_DIVIDE ||
pExpr->_node.optr == TSDB_BINARY_OP_REMAINDER) { pExpr->_node.optr == TSDB_BINARY_OP_REMAINDER) {
int16_t leftType = pExpr->_node.pLeft->resultType;
int16_t rightType = pExpr->_node.pRight->resultType;
if (!IS_NUMERIC_TYPE(leftType) || !IS_NUMERIC_TYPE(rightType)) { if (!IS_NUMERIC_TYPE(leftType) || !IS_NUMERIC_TYPE(rightType)) {
return TSDB_CODE_TSC_INVALID_OPERATION; return TSDB_CODE_TSC_INVALID_OPERATION;
} }
pExpr->resultType = TSDB_DATA_TYPE_DOUBLE; pExpr->resultType = TSDB_DATA_TYPE_DOUBLE;
pExpr->resultBytes = tDataTypes[TSDB_DATA_TYPE_DOUBLE].bytes; pExpr->resultBytes = tDataTypes[TSDB_DATA_TYPE_DOUBLE].bytes;
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} else if (pExpr->_node.optr == TSDB_BINARY_OP_BITAND) {
if ((leftType != TSDB_DATA_TYPE_BOOL && !IS_SIGNED_NUMERIC_TYPE(leftType) && !IS_UNSIGNED_NUMERIC_TYPE(leftType)) ||
(rightType != TSDB_DATA_TYPE_BOOL && !IS_SIGNED_NUMERIC_TYPE(rightType) && !IS_UNSIGNED_NUMERIC_TYPE(rightType)))
{
return TSDB_CODE_TSC_INVALID_OPERATION;
}
uint8_t schemaType;
// now leftType and rightType are both numeric
if (pExpr->_node.pLeft->nodeType == TSQL_NODE_COL && pExpr->_node.pRight->nodeType == TSQL_NODE_COL) {
if (leftType != rightType) {
return TSDB_CODE_TSC_INVALID_OPERATION;
}
} else if (pExpr->_node.pLeft->nodeType == TSQL_NODE_COL) {
if (pExpr->_node.pRight->nodeType != TSQL_NODE_VALUE) {
return TSDB_CODE_TSC_INVALID_OPERATION;
} else {
schemaType = pExpr->_node.pLeft->pSchema->type;
int64_t sVal = pExpr->_node.pRight->pVal->i64;
uint64_t uVal = pExpr->_node.pRight->pVal->u64;
switch (schemaType) {
case TSDB_DATA_TYPE_BOOL:
if ((pExpr->_node.pRight->pVal->nType != TSDB_DATA_TYPE_BOOL) ||
(pExpr->_node.pRight->pVal->i64 != 0 &&
pExpr->_node.pRight->pVal->i64 != 1 &&
pExpr->_node.pRight->pVal->i64 != TSDB_DATA_BOOL_NULL))
{
return TSDB_CODE_TSC_INVALID_OPERATION;
}
break;
case TSDB_DATA_TYPE_TINYINT:
if (sVal < -128 || sVal > 127) {
return TSDB_CODE_TSC_INVALID_OPERATION;
}
break;
case TSDB_DATA_TYPE_SMALLINT:
if (sVal < -32768 || sVal > 32767) {
return TSDB_CODE_TSC_INVALID_OPERATION;
}
break;
case TSDB_DATA_TYPE_INT:
if (sVal < INT32_MIN || sVal > INT32_MAX) {
return TSDB_CODE_TSC_INVALID_OPERATION;
}
break;
case TSDB_DATA_TYPE_BIGINT:
if (sVal < INT64_MIN || sVal > INT64_MAX) {
return TSDB_CODE_TSC_INVALID_OPERATION;
}
break;
case TSDB_DATA_TYPE_UTINYINT:
if (uVal > 255) {
return TSDB_CODE_TSC_INVALID_OPERATION;
}
break;
case TSDB_DATA_TYPE_USMALLINT:
if (uVal > 65535) {
return TSDB_CODE_TSC_INVALID_OPERATION;
}
break;
case TSDB_DATA_TYPE_UINT:
if (uVal > UINT32_MAX) {
return TSDB_CODE_TSC_INVALID_OPERATION;
}
break;
case TSDB_DATA_TYPE_UBIGINT:
if (uVal > UINT64_MAX) {
return TSDB_CODE_TSC_INVALID_OPERATION;
}
break;
}
pExpr->_node.pRight->pSchema->type = schemaType;
pExpr->_node.pRight->pVal->nType = schemaType;
pExpr->_node.pRight->resultType = schemaType;
pExpr->_node.pRight->resultBytes = tDataTypes[schemaType].bytes;
}
} else {
if (pExpr->_node.pLeft->nodeType != TSQL_NODE_VALUE) {
return TSDB_CODE_TSC_INVALID_OPERATION;
} else {
schemaType = pExpr->_node.pRight->pSchema->type;
int64_t sVal = pExpr->_node.pLeft->pVal->i64;
uint64_t uVal = pExpr->_node.pLeft->pVal->u64;
switch (schemaType) {
case TSDB_DATA_TYPE_BOOL:
if ((pExpr->_node.pLeft->pVal->nType != TSDB_DATA_TYPE_BOOL) ||
(pExpr->_node.pLeft->pVal->i64 != 0 &&
pExpr->_node.pLeft->pVal->i64 != 1 &&
pExpr->_node.pLeft->pVal->i64 != TSDB_DATA_BOOL_NULL))
{
return TSDB_CODE_TSC_INVALID_OPERATION;
}
pExpr->_node.pLeft->pVal->nLen = 1;
break;
case TSDB_DATA_TYPE_TINYINT:
if (sVal < -128 || sVal > 127) {
return TSDB_CODE_TSC_INVALID_OPERATION;
}
pExpr->_node.pLeft->pVal->nLen = 1;
break;
case TSDB_DATA_TYPE_SMALLINT:
if (sVal < -32768 || sVal > 32767) {
return TSDB_CODE_TSC_INVALID_OPERATION;
}
pExpr->_node.pLeft->pVal->nLen = 2;
break;
case TSDB_DATA_TYPE_INT:
if (sVal < INT32_MIN || sVal > INT32_MAX) {
return TSDB_CODE_TSC_INVALID_OPERATION;
}
pExpr->_node.pLeft->pVal->nLen = 4;
break;
case TSDB_DATA_TYPE_BIGINT:
if (sVal < INT64_MIN || sVal > INT64_MAX) {
return TSDB_CODE_TSC_INVALID_OPERATION;
}
pExpr->_node.pLeft->pVal->nLen = 8;
break;
case TSDB_DATA_TYPE_UTINYINT:
if (uVal > 255) {
return TSDB_CODE_TSC_INVALID_OPERATION;
}
pExpr->_node.pLeft->pVal->nLen = 1;
break;
case TSDB_DATA_TYPE_USMALLINT:
if (uVal > 65535) {
return TSDB_CODE_TSC_INVALID_OPERATION;
}
pExpr->_node.pLeft->pVal->nLen = 2;
break;
case TSDB_DATA_TYPE_UINT:
if (uVal > UINT32_MAX) {
return TSDB_CODE_TSC_INVALID_OPERATION;
}
pExpr->_node.pLeft->pVal->nLen = 4;
break;
case TSDB_DATA_TYPE_UBIGINT:
if (uVal > UINT64_MAX) {
return TSDB_CODE_TSC_INVALID_OPERATION;
}
pExpr->_node.pLeft->pVal->nLen = 8;
break;
}
pExpr->_node.pLeft->pSchema->type = schemaType;
pExpr->_node.pLeft->pVal->nType = schemaType;
pExpr->_node.pLeft->resultType = schemaType;
pExpr->_node.pLeft->resultBytes = tDataTypes[schemaType].bytes;
}
resultType = schemaType;
}
if (resultType == TSDB_DATA_TYPE_BOOL) {
pExpr->resultType = TSDB_DATA_TYPE_BOOL;
pExpr->resultBytes = tDataTypes[TSDB_DATA_TYPE_BOOL].bytes;
} else {
pExpr->resultType = resultType;
pExpr->resultBytes = tDataTypes[resultType].bytes;
}
return TSDB_CODE_SUCCESS;
} else { } else {
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
...@@ -490,7 +658,15 @@ void exprTreeExprNodeTraverse(tExprNode *pExpr, int32_t numOfRows, tExprOperandI ...@@ -490,7 +658,15 @@ void exprTreeExprNodeTraverse(tExprNode *pExpr, int32_t numOfRows, tExprOperandI
OperatorFn(leftIn, leftNum, leftType, rightIn, rightNum, rightType, output->data, fnOrder); OperatorFn(leftIn, leftNum, leftType, rightIn, rightNum, rightType, output->data, fnOrder);
output->numOfRows = MAX(leftNum, rightNum); output->numOfRows = MAX(leftNum, rightNum);
if(leftType == TSDB_DATA_TYPE_TIMESTAMP || rightType == TSDB_DATA_TYPE_TIMESTAMP) {
output->type = TSDB_DATA_TYPE_BIGINT;
} else {
if (pExpr->_node.optr == TSDB_BINARY_OP_BITAND) {
output->type = leftType; // rightType must be the same as leftType
} else {
output->type = TSDB_DATA_TYPE_DOUBLE; output->type = TSDB_DATA_TYPE_DOUBLE;
}
}
output->bytes = tDataTypes[output->type].bytes; output->bytes = tDataTypes[output->type].bytes;
tfree(ltmp); tfree(ltmp);
...@@ -1724,4 +1900,5 @@ tScalarFunctionInfo aScalarFunctions[] = { ...@@ -1724,4 +1900,5 @@ tScalarFunctionInfo aScalarFunctions[] = {
"cast", "cast",
vectorMathFunc vectorMathFunc
}, },
}; };
...@@ -176,10 +176,11 @@ do { \ ...@@ -176,10 +176,11 @@ do { \
#define TSDB_BINARY_OP_MULTIPLY 32 #define TSDB_BINARY_OP_MULTIPLY 32
#define TSDB_BINARY_OP_DIVIDE 33 #define TSDB_BINARY_OP_DIVIDE 33
#define TSDB_BINARY_OP_REMAINDER 34 #define TSDB_BINARY_OP_REMAINDER 34
#define TSDB_BINARY_OP_BITAND 35
#define IS_RELATION_OPTR(op) (((op) >= TSDB_RELATION_LESS) && ((op) < TSDB_RELATION_IN)) #define IS_RELATION_OPTR(op) (((op) >= TSDB_RELATION_LESS) && ((op) < TSDB_RELATION_IN))
#define IS_ARITHMETIC_OPTR(op) (((op) >= TSDB_BINARY_OP_ADD) && ((op) <= TSDB_BINARY_OP_REMAINDER)) #define IS_ARITHMETIC_OPTR(op) (((op) >= TSDB_BINARY_OP_ADD) && ((op) <= TSDB_BINARY_OP_BITAND))
#define TS_PATH_DELIMITER_LEN 1 #define TS_PATH_DELIMITER_LEN 1
......
...@@ -786,6 +786,7 @@ expr(A) ::= expr(X) MINUS expr(Y). {A = tSqlExprCreate(X, Y, TK_MINUS); } ...@@ -786,6 +786,7 @@ expr(A) ::= expr(X) MINUS expr(Y). {A = tSqlExprCreate(X, Y, TK_MINUS); }
expr(A) ::= expr(X) STAR expr(Y). {A = tSqlExprCreate(X, Y, TK_STAR); } expr(A) ::= expr(X) STAR expr(Y). {A = tSqlExprCreate(X, Y, TK_STAR); }
expr(A) ::= expr(X) SLASH expr(Y). {A = tSqlExprCreate(X, Y, TK_DIVIDE);} expr(A) ::= expr(X) SLASH expr(Y). {A = tSqlExprCreate(X, Y, TK_DIVIDE);}
expr(A) ::= expr(X) REM expr(Y). {A = tSqlExprCreate(X, Y, TK_REM); } expr(A) ::= expr(X) REM expr(Y). {A = tSqlExprCreate(X, Y, TK_REM); }
expr(A) ::= expr(X) BITAND expr(Y). {A = tSqlExprCreate(X, Y, TK_BITAND);}
// like expression // like expression
expr(A) ::= expr(X) LIKE expr(Y). {A = tSqlExprCreate(X, Y, TK_LIKE); } expr(A) ::= expr(X) LIKE expr(Y). {A = tSqlExprCreate(X, Y, TK_LIKE); }
......
因为 它太大了无法显示 source diff 。你可以改为 查看blob
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册