未验证 提交 4351c4c8 编写于 作者: S shenglian-zhou 提交者: GitHub

Merge pull request #9813 from taosdata/fix/TD-12945

[TD-12945]<fix>(query): taos shell crash when constant comparison cause crash
......@@ -2431,7 +2431,7 @@ int32_t addProjectionExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, t
if (pTableMeta->tableType != TSDB_TEMP_TABLE) {
tscInsertPrimaryTsSourceColumn(pQueryInfo, pTableMeta->id.uid);
}
} else if (tokenId == TK_STRING || tokenId == TK_INTEGER || tokenId == TK_FLOAT) { // simple column projection query
} else if (tokenId == TK_STRING || tokenId == TK_INTEGER || tokenId == TK_FLOAT || tokenId == TK_BOOL) { // simple column projection query
SColumnIndex index = COLUMN_INDEX_INITIALIZER;
// user-specified constant value as a new result column
......@@ -4659,6 +4659,7 @@ static int32_t validateSQLExprItemArithmeticExpr(SSqlCmd* pCmd, tSqlExpr* pExpr,
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";
const char* msg3 = "comparison/logical expression involving string operands is not supported";
int32_t leftHeight = 0;
int32_t ret = validateSQLExprItem(pCmd, pExpr->pLeft, pQueryInfo, pList, &leftType, &uidLeft, &leftHeight);
if (ret != TSDB_CODE_SUCCESS) {
......@@ -4691,6 +4692,17 @@ static int32_t validateSQLExprItemArithmeticExpr(SSqlCmd* pCmd, tSqlExpr* pExpr,
} else if (leftType == SQLEXPR_TYPE_SCALAR || rightType == SQLEXPR_TYPE_SCALAR){
*type = SQLEXPR_TYPE_SCALAR;
}
// comparison/logical operations
if (pExpr->tokenId == TK_EQ || pExpr->tokenId == TK_NE ||
pExpr->tokenId == TK_GT || pExpr->tokenId == TK_GE ||
pExpr->tokenId == TK_LT || pExpr->tokenId == TK_LE ||
pExpr->tokenId == TK_AND || pExpr->tokenId == TK_OR) {
if ((leftType == SQLEXPR_TYPE_VALUE && pExpr->pLeft->tokenId == TK_STRING) ||
(rightType == SQLEXPR_TYPE_VALUE && pExpr->pRight->tokenId == TK_STRING)) {
return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg3);
}
}
}
return TSDB_CODE_SUCCESS;
}
......
......@@ -217,6 +217,7 @@ void vectorAdd(void *left, int32_t len1, int32_t _left_type, void *right, int32_
}
}
}
void vectorSub(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;
......@@ -252,6 +253,7 @@ void vectorSub(void *left, int32_t len1, int32_t _left_type, void *right, int32_
}
}
}
void vectorMultiply(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;
......@@ -287,6 +289,7 @@ void vectorMultiply(void *left, int32_t len1, int32_t _left_type, void *right, i
}
}
}
void vectorDivide(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;
......@@ -340,6 +343,7 @@ void vectorDivide(void *left, int32_t len1, int32_t _left_type, void *right, int
}
}
}
void vectorRemainder(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;
......
......@@ -18,6 +18,7 @@
#include "taosdef.h"
#include "taosmsg.h"
#include "tcmdtype.h"
#include "tcompare.h"
#include "tstrbuild.h"
#include "ttoken.h"
#include "ttokendef.h"
......@@ -318,12 +319,17 @@ tSqlExpr *tSqlExprCreate(tSqlExpr *pLeft, tSqlExpr *pRight, int32_t optrType) {
}
if ((pLeft != NULL && pRight != NULL) &&
(optrType == TK_PLUS || optrType == TK_MINUS || optrType == TK_STAR || optrType == TK_DIVIDE || optrType == TK_REM)) {
(optrType == TK_PLUS || optrType == TK_MINUS || optrType == TK_STAR || optrType == TK_DIVIDE || optrType == TK_REM ||
optrType == TK_EQ || optrType == TK_NE || optrType == TK_LT || optrType == TK_GT || optrType == TK_LE || optrType == TK_GE ||
optrType == TK_AND || optrType == TK_OR)) {
/*
* if a exprToken is noted as the TK_TIMESTAMP, the time precision is microsecond
* Otherwise, the time precision is adaptive, determined by the time precision from databases.
*/
if ((pLeft->tokenId == TK_INTEGER && pRight->tokenId == TK_INTEGER) ||
(pLeft->tokenId == TK_BOOL && pRight->tokenId == TK_BOOL) ||
(pLeft->tokenId == TK_INTEGER && pRight->tokenId == TK_BOOL) ||
(pLeft->tokenId == TK_BOOL && pRight->tokenId == TK_INTEGER) ||
(pLeft->tokenId == TK_TIMESTAMP && pRight->tokenId == TK_TIMESTAMP)) {
pExpr->value.nType = TSDB_DATA_TYPE_BIGINT;
pExpr->tokenId = pLeft->tokenId;
......@@ -360,12 +366,46 @@ tSqlExpr *tSqlExprCreate(tSqlExpr *pLeft, tSqlExpr *pRight, int32_t optrType) {
pExpr->value.i64 = pLeft->value.i64 % pRight->value.i64;
break;
}
case TK_EQ: {
pExpr->value.i64 = (pLeft->value.i64 == pRight->value.i64) ? 1 : 0;
break;
}
case TK_NE: {
pExpr->value.i64 = (pLeft->value.i64 != pRight->value.i64) ? 1 : 0;
break;
}
case TK_LT: {
pExpr->value.i64 = (pLeft->value.i64 < pRight->value.i64) ? 1 : 0;
break;
}
case TK_GT: {
pExpr->value.i64 = (pLeft->value.i64 > pRight->value.i64) ? 1 : 0;
break;
}
case TK_LE: {
pExpr->value.i64 = (pLeft->value.i64 <= pRight->value.i64) ? 1 : 0;
break;
}
case TK_GE: {
pExpr->value.i64 = (pLeft->value.i64 >= pRight->value.i64) ? 1 : 0;
break;
}
case TK_AND: {
pExpr->value.i64 = (pLeft->value.i64 && pRight->value.i64) ? 1 : 0;
break;
}
case TK_OR: {
pExpr->value.i64 = (pLeft->value.i64 || pRight->value.i64) ? 1 : 0;
break;
}
}
tSqlExprDestroy(pLeft);
tSqlExprDestroy(pRight);
} else if ((pLeft->tokenId == TK_FLOAT && pRight->tokenId == TK_INTEGER) ||
(pLeft->tokenId == TK_INTEGER && pRight->tokenId == TK_FLOAT) ||
(pLeft->tokenId == TK_BOOL && pRight->tokenId == TK_FLOAT) ||
(pLeft->tokenId == TK_FLOAT && pRight->tokenId == TK_BOOL) ||
(pLeft->tokenId == TK_FLOAT && pRight->tokenId == TK_FLOAT)) {
pExpr->value.nType = TSDB_DATA_TYPE_DOUBLE;
pExpr->tokenId = TK_FLOAT;
......@@ -395,6 +435,80 @@ tSqlExpr *tSqlExprCreate(tSqlExpr *pLeft, tSqlExpr *pRight, int32_t optrType) {
pExpr->value.dKey = left - ((int64_t)(left / right)) * right;
break;
}
case TK_EQ: {
pExpr->tokenId = TK_INTEGER;
pExpr->value.nType = TSDB_DATA_TYPE_BIGINT;
if (compareDoubleVal(&left, &right) == 0) {
pExpr->value.i64 = 1;
} else {
pExpr->value.i64 = 0;
}
break;
}
case TK_NE: {
pExpr->tokenId = TK_INTEGER;
pExpr->value.nType = TSDB_DATA_TYPE_BIGINT;
if (compareDoubleVal(&left, &right) != 0) {
pExpr->value.i64 = 1;
} else {
pExpr->value.i64 = 0;
}
break;
}
case TK_LT: {
pExpr->tokenId = TK_INTEGER;
pExpr->value.nType = TSDB_DATA_TYPE_BIGINT;
if (compareDoubleVal(&left, &right) == -1) {
pExpr->value.i64 = 1;
} else {
pExpr->value.i64 = 0;
}
break;
}
case TK_GT: {
pExpr->tokenId = TK_INTEGER;
pExpr->value.nType = TSDB_DATA_TYPE_BIGINT;
if (compareDoubleVal(&left, &right) == 1) {
pExpr->value.i64 = 1;
} else {
pExpr->value.i64 = 0;
}
break;
}
case TK_LE: {
int32_t res = compareDoubleVal(&left, &right);
pExpr->tokenId = TK_INTEGER;
pExpr->value.nType = TSDB_DATA_TYPE_BIGINT;
if (res == 0 || res == -1) {
pExpr->value.i64 = 1;
} else {
pExpr->value.i64 = 0;
}
break;
}
case TK_GE: {
int32_t res = compareDoubleVal(&left, &right);
pExpr->tokenId = TK_INTEGER;
pExpr->value.nType = TSDB_DATA_TYPE_BIGINT;
if (res == 0 || res == 1) {
pExpr->value.i64 = 1;
} else {
pExpr->value.i64 = 0;
}
break;
}
case TK_AND: {
pExpr->tokenId = TK_INTEGER;
pExpr->value.nType = TSDB_DATA_TYPE_BIGINT;
pExpr->value.i64 = (left && right) ? 1 : 0;
break;
}
case TK_OR: {
pExpr->tokenId = TK_INTEGER;
pExpr->value.nType = TSDB_DATA_TYPE_BIGINT;
pExpr->value.i64 = (left || right) ? 1 : 0;
break;
}
}
tSqlExprDestroy(pLeft);
......
此差异已折叠。
......@@ -2,6 +2,7 @@ python3 ./test.py -f 2-query/ts_hidden_column.py
python3 ./test.py -f 2-query/union-order.py
python3 ./test.py -f 2-query/session_two_stage.py
python3 ./test.py -f 2-query/timeline_agg_func_groupby.py
python3 ./test.py -f 2-query/constant_compare.py
python3 ./test.py -f 2-query/ts_2016.py
python3 ./test.py -f 2-query/function_mavg.py
python3 ./test.py -f 2-query/escape.py
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册