From 39521a1b747de20df4dc628ce0e08871f196dfac Mon Sep 17 00:00:00 2001 From: wpan Date: Thu, 24 Jun 2021 18:20:11 +0800 Subject: [PATCH] fix test case and bugs --- src/client/src/tscSQLParser.c | 33 +++- src/inc/taosdef.h | 1 + tests/script/general/parser/condition.sim | 204 ++++++++++++++++++++++ tests/script/general/parser/where.sim | 38 ++-- 4 files changed, 243 insertions(+), 33 deletions(-) diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index ab6bfa6c23..1721c9bcd5 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -4071,7 +4071,7 @@ static int32_t setNormalExprToCond(tSqlExpr** parent, tSqlExpr* pExpr, int32_t p } -static int32_t validateNullExpr(tSqlExpr* pExpr, char* msgBuf) { +static int32_t validateNullExpr(tSqlExpr* pExpr, STableMeta* pTableMeta, int32_t index, char* msgBuf) { const char* msg = "only support is [not] null"; tSqlExpr* pRight = pExpr->pRight; @@ -4079,6 +4079,27 @@ static int32_t validateNullExpr(tSqlExpr* pExpr, char* msgBuf) { return invalidOperationMsg(msgBuf, msg); } + if (pRight->tokenId == TK_STRING) { + SSchema* pSchema = tscGetTableSchema(pTableMeta); + if (IS_VAR_DATA_TYPE(pSchema[index].type)) { + return TSDB_CODE_SUCCESS; + } + + char *v = strndup(pRight->token.z, pRight->token.n); + int32_t len = strRmquote(v, pRight->token.n); + if (len > 0) { + uint32_t type = 0; + tGetToken(v, &type); + + if (type == TK_NULL) { + free(v); + return invalidOperationMsg(msgBuf, msg); + } + } + + free(v); + } + return TSDB_CODE_SUCCESS; } @@ -4129,7 +4150,7 @@ static int32_t handleExprInQueryCond(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSql STableMeta* pTableMeta = pTableMetaInfo->pTableMeta; // validate the null expression - int32_t code = validateNullExpr(*pExpr, tscGetErrorMsgPayload(pCmd)); + int32_t code = validateNullExpr(*pExpr, pTableMeta, index.columnIndex, tscGetErrorMsgPayload(pCmd)); if (code != TSDB_CODE_SUCCESS) { return code; } @@ -8086,12 +8107,8 @@ int32_t validateSqlNode(SSqlObj* pSql, SSqlNode* pSqlNode, SQueryInfo* pQueryInf SExprInfo* pExpr1 = tscExprGet(pQueryInfo, 0); if (pExpr1->base.functionId != TSDB_FUNC_TID_TAG) { - int32_t numOfCols = (int32_t)taosArrayGetSize(pQueryInfo->colList); - for (int32_t i = 0; i < numOfCols; ++i) { - SColumn* pCols = taosArrayGetP(pQueryInfo->colList, i); - if (pCols->info.flist.numOfFilters > 0) { - return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg5); - } + if ((pQueryInfo->colCond && taosArrayGetSize(pQueryInfo->colCond) > 0) || IS_TSWINDOW_SPECIFIED(pQueryInfo->window)) { + return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg5); } } } diff --git a/src/inc/taosdef.h b/src/inc/taosdef.h index dac2dc84b6..ac0cb02a3a 100644 --- a/src/inc/taosdef.h +++ b/src/inc/taosdef.h @@ -34,6 +34,7 @@ extern "C" { #define TSWINDOW_INITIALIZER ((STimeWindow) {INT64_MIN, INT64_MAX}) #define TSWINDOW_DESC_INITIALIZER ((STimeWindow) {INT64_MAX, INT64_MIN}) +#define IS_TSWINDOW_SPECIFIED(win) (((win).skey != INT64_MIN) || ((win).ekey != INT64_MAX)) #define TSKEY_INITIAL_VAL INT64_MIN diff --git a/tests/script/general/parser/condition.sim b/tests/script/general/parser/condition.sim index 6b10101eaa..ddba3040c2 100644 --- a/tests/script/general/parser/condition.sim +++ b/tests/script/general/parser/condition.sim @@ -96,6 +96,15 @@ sql_error select ts,c1,c7 from stb1 where c7 > false sql_error select * from stb1 where c1 > NULL; sql_error select * from stb1 where c1 = NULL; sql_error select * from stb1 where c1 LIKE '%1'; +sql_error select * from stb1 where c1 = 'NULL'; +sql_error select * from stb1 where c2 > 'NULL'; +sql_error select * from stb1 where c3 <> 'NULL'; +sql_error select * from stb1 where c4 != 'null'; +sql_error select * from stb1 where c5 >= 'null'; +sql_error select * from stb1 where c6 <= 'null'; +sql_error select * from stb1 where c7 < 'nuLl'; +sql_error select * from stb1 where c8 < 'nuLl'; +sql_error select * from stb1 where c9 > 'nuLl'; sql select * from stb1 where c2 > 3.0 or c2 < 60; if $rows != 28 then @@ -1365,10 +1374,205 @@ if $data00 != @21-05-05 18:19:08.000@ then return -1 endi +sql select avg(c1) from tb1 where (c1 > 12 or c2 > 10) and (c3 < 12 or c3 > 13); +if $rows != 1 then + return -1 +endi +if $data00 != 12.500000000 then + return -1 +endi + +sql select count(c1),sum(c3) from tb1 where ((c7 = true and c6 > 2) or (c1 > 10 or c3 < 3)) and ((c8 like '1%') or (c9 like '%2' or c9 like '%3')) interval(5s); +if $rows != 2 then + return -1 +endi +if $data00 != @21-05-05 18:19:00.000@ then + return -1 +endi +if $data01 != 3 then + return -1 +endi +if $data02 != 14 then + return -1 +endi +if $data10 != @21-05-05 18:19:05.000@ then + return -1 +endi +if $data11 != 3 then + return -1 +endi +if $data12 != 39 then + return -1 +endi + +sql select * from stb1 where c8 = 'null'; +if $rows != 0 then + return -1 +endi + +sql select * from stb1 where c8 = 'NULL'; +if $rows != 0 then + return -1 +endi + +sql select * from stb1 where c9 = 'null'; +if $rows != 0 then + return -1 +endi + +sql select * from stb1 where c9 = 'NULL'; +if $rows != 0 then + return -1 +endi + +#sql select * from (select * from stb1 where (c1 > 60 or c1 < 10) and (c7 = true or c5 > 2 and c5 < 63)) where (c3 > 61 or c3 < 3); + + print "ts test" sql_error select ts,c1,c7 from stb1 where ts != '2021-05-05 18:19:27' sql_error select ts,c1,c7 from stb1 where ts > '2021-05-05 18:19:03.000' or ts < '2021-05-05 18:19:02.000'; sql_error select ts,c1,c7 from stb1 where ts > '2021-05-05 18:19:03.000' and ts > '2021-05-05 18:19:20.000' and ts != '2021-05-05 18:19:22.000'; +sql_error select * from stb1 where ts2 like '2021-05-05%'; + +sql select * from stb1 where ts > '2021-05-05 18:19:03.000' and ts < '2021-05-05 18:19:02'; +if $rows != 0 then + return -1 +endi + +sql select * from stb1 where ts > '2021-05-05 18:19:03.000' and ts > '2021-05-05 18:19:25'; +if $rows != 3 then + return -1 +endi +if $data00 != @21-05-05 18:19:26.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:27.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:28.000@ then + return -1 +endi + +sql select * from stb1 where ts < '2021-05-05 18:19:03.000' and ts < '2021-05-05 18:19:25'; +if $rows != 3 then + return -1 +endi +if $data00 != @21-05-05 18:19:00.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:01.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:02.000@ then + return -1 +endi + +sql select * from stb1 where ts > '2021-05-05 18:19:23.000' and ts < '2021-05-05 18:19:25'; +if $rows != 1 then + return -1 +endi +if $data00 != @21-05-05 18:19:24.000@ then + return -1 +endi + +sql select * from stb1 where ts > '2021-05-05 18:19:03.000' or ts > '2021-05-05 18:19:25'; +if $rows != 25 then + return -1 +endi +if $data00 != @21-05-05 18:19:04.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:05.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:06.000@ then + return -1 +endi + +sql select * from stb1 where ts < '2021-05-05 18:19:03.000' or ts < '2021-05-05 18:19:25'; +if $rows != 25 then + return -1 +endi +if $data00 != @21-05-05 18:19:00.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:01.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:02.000@ then + return -1 +endi + +sql select * from stb1 where ts > '2021-05-05 18:19:23.000' or ts < '2021-05-05 18:19:25'; +if $rows != 29 then + return -1 +endi +if $data00 != @21-05-05 18:19:00.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:01.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:02.000@ then + return -1 +endi + +sql select * from stb1 where (ts > '2021-05-05 18:19:23.000' or ts < '2021-05-05 18:19:25') and (ts > '2021-05-05 18:19:23.000' and ts < '2021-05-05 18:19:26'); +if $rows != 2 then + return -1 +endi +if $data00 != @21-05-05 18:19:24.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:25.000@ then + return -1 +endi + +sql select * from stb1 where (ts > '2021-05-05 18:19:23.000' or ts < '2021-05-05 18:19:25') and (ts > '2021-05-05 18:19:23.000' or ts > '2021-05-05 18:19:26'); +if $rows != 5 then + return -1 +endi +if $data00 != @21-05-05 18:19:24.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:25.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:26.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:27.000@ then + return -1 +endi +if $data40 != @21-05-05 18:19:28.000@ then + return -1 +endi + + +sql select * from stb2 where ts2 in ('2021-05-05 18:28:03','2021-05-05 18:28:05','2021-05-05 18:28:08'); +if $rows != 3 then + return -1 +endi +if $data00 != @21-05-05 18:19:02.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:04.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:07.000@ then + return -1 +endi + +sql select * from stb2 where t3 in ('2021-05-05 18:38:38','2021-05-05 18:38:28','2021-05-05 18:38:08') and ts2 in ('2021-05-05 18:28:04','2021-05-05 18:28:04','2021-05-05 18:28:03'); +if $rows != 2 then + return -1 +endi +if $data00 != @21-05-05 18:19:02.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:03.000@ then + return -1 +endi print "tbname test" diff --git a/tests/script/general/parser/where.sim b/tests/script/general/parser/where.sim index 00a22eede6..682c5c688c 100644 --- a/tests/script/general/parser/where.sim +++ b/tests/script/general/parser/where.sim @@ -65,7 +65,14 @@ $tb = $tbPrefix . $i sql_error select * from $tb where c7 # TBASE-654 : invalid filter expression cause server crashed -sql_error select count(*) from $tb where c1<10 and c1<>2 +sql select count(*) from $tb where c1<10 and c1<>2 +if $rows != 1 then + return -1 +endi +if $data00 != 900 then + return -1 +endi + sql select * from $tb where c7 = false $val = $rowNum / 100 @@ -253,30 +260,11 @@ sql insert into tb_where_NULL values ('2019-01-01 09:00:02.000', 2, 'val2') sql_error select * from tb_where_NULL where c1 = NULL sql_error select * from tb_where_NULL where c1 <> NULL sql_error select * from tb_where_NULL where c1 < NULL -sql select * from tb_where_NULL where c1 = "NULL" -if $rows != 0 then - return -1 -endi - -sql select * from tb_where_NULL where c1 <> "NULL" -if $rows != 2 then - return -1 -endi -sql select * from tb_where_NULL where c1 <> "nulL" -if $rows != 2 then - return -1 -endi - -sql select * from tb_where_NULL where c1 > "NULL" -if $rows != 0 then - return -1 -endi - -sql select * from tb_where_NULL where c1 >= "NULL" -if $rows != 0 then - return -1 -endi - +sql_error select * from tb_where_NULL where c1 = "NULL" +sql_error select * from tb_where_NULL where c1 <> "NULL" +sql_error select * from tb_where_NULL where c1 <> "nulL" +sql_error select * from tb_where_NULL where c1 > "NULL" +sql_error select * from tb_where_NULL where c1 >= "NULL" sql select * from tb_where_NULL where c2 = "NULL" if $rows != 0 then return -1