From 518a2ae8184b2fbafda33364c8a78edd56a82189 Mon Sep 17 00:00:00 2001 From: wpan Date: Tue, 22 Jun 2021 10:01:24 +0800 Subject: [PATCH] support unsigned --- src/common/src/texpr.c | 18 +++-- src/util/src/thashutil.c | 4 + tests/script/general/parser/condition.sim | 95 ++++++++++++++++++++--- 3 files changed, 102 insertions(+), 15 deletions(-) diff --git a/src/common/src/texpr.c b/src/common/src/texpr.c index ede60b5001..32689e9abb 100644 --- a/src/common/src/texpr.c +++ b/src/common/src/texpr.c @@ -526,26 +526,30 @@ void convertFilterSetFromBinary(void **q, const char *buf, int32_t len, uint32_t for (int32_t i = 0; i < sz; i++) { switch (sType) { case TSDB_DATA_TYPE_BOOL: + case TSDB_DATA_TYPE_UTINYINT: case TSDB_DATA_TYPE_TINYINT: { - int8_t val = tbufReadInt64(&br); + uint8_t val = (uint8_t)tbufReadInt64(&br); t = sizeof(val); pvar = &val; break; } + case TSDB_DATA_TYPE_USMALLINT: case TSDB_DATA_TYPE_SMALLINT: { - int16_t val = tbufReadInt64(&br); + uint16_t val = (uint16_t)tbufReadInt64(&br); t = sizeof(val); pvar = &val; break; } + case TSDB_DATA_TYPE_UINT: case TSDB_DATA_TYPE_INT: { - int32_t val = tbufReadInt64(&br); + uint32_t val = (uint32_t)tbufReadInt64(&br); t = sizeof(val); pvar = &val; break; } + case TSDB_DATA_TYPE_UBIGINT: case TSDB_DATA_TYPE_BIGINT: { - int64_t val = tbufReadInt64(&br); + uint64_t val = (uint64_t)tbufReadInt64(&br); t = sizeof(val); pvar = &val; break; @@ -557,7 +561,7 @@ void convertFilterSetFromBinary(void **q, const char *buf, int32_t len, uint32_t break; } case TSDB_DATA_TYPE_FLOAT: { - float val = tbufReadDouble(&br); + float val = (float)tbufReadDouble(&br); t = sizeof(val); pvar = &val; break; @@ -587,6 +591,7 @@ void convertFilterSetFromBinary(void **q, const char *buf, int32_t len, uint32_t switch (tType) { case TSDB_DATA_TYPE_BOOL: + case TSDB_DATA_TYPE_UTINYINT: case TSDB_DATA_TYPE_TINYINT: { int8_t val = 0; if (tVariantDump(&tmpVar, (char *)&val, tType, false)) { @@ -596,6 +601,7 @@ void convertFilterSetFromBinary(void **q, const char *buf, int32_t len, uint32_t t = sizeof(val); break; } + case TSDB_DATA_TYPE_USMALLINT: case TSDB_DATA_TYPE_SMALLINT: { int16_t val = 0; if (tVariantDump(&tmpVar, (char *)&val, tType, false)) { @@ -605,6 +611,7 @@ void convertFilterSetFromBinary(void **q, const char *buf, int32_t len, uint32_t t = sizeof(val); break; } + case TSDB_DATA_TYPE_UINT: case TSDB_DATA_TYPE_INT: { int32_t val = 0; if (tVariantDump(&tmpVar, (char *)&val, tType, false)) { @@ -614,6 +621,7 @@ void convertFilterSetFromBinary(void **q, const char *buf, int32_t len, uint32_t t = sizeof(val); break; } + case TSDB_DATA_TYPE_UBIGINT: case TSDB_DATA_TYPE_BIGINT: { int64_t val = 0; if (tVariantDump(&tmpVar, (char *)&val, tType, false)) { diff --git a/src/util/src/thashutil.c b/src/util/src/thashutil.c index fa2c95aaad..13df8e4ee6 100644 --- a/src/util/src/thashutil.c +++ b/src/util/src/thashutil.c @@ -126,12 +126,16 @@ _hash_fn_t taosGetDefaultHashFunction(int32_t type) { _hash_fn_t fn = NULL; switch(type) { case TSDB_DATA_TYPE_TIMESTAMP: + case TSDB_DATA_TYPE_UBIGINT: case TSDB_DATA_TYPE_BIGINT: fn = taosIntHash_64;break; case TSDB_DATA_TYPE_BINARY: fn = MurmurHash3_32;break; case TSDB_DATA_TYPE_NCHAR: fn = MurmurHash3_32;break; + case TSDB_DATA_TYPE_UINT: case TSDB_DATA_TYPE_INT: fn = taosIntHash_32; break; + case TSDB_DATA_TYPE_USMALLINT: case TSDB_DATA_TYPE_SMALLINT: fn = taosIntHash_16; break; case TSDB_DATA_TYPE_BOOL: fn = taosIntHash_8; break; + case TSDB_DATA_TYPE_UTINYINT: case TSDB_DATA_TYPE_TINYINT: fn = taosIntHash_8; break; case TSDB_DATA_TYPE_FLOAT: fn = taosFloatHash; break; case TSDB_DATA_TYPE_DOUBLE: fn = taosDoubleHash; break; diff --git a/tests/script/general/parser/condition.sim b/tests/script/general/parser/condition.sim index 7a132d039a..228bc90fd1 100644 --- a/tests/script/general/parser/condition.sim +++ b/tests/script/general/parser/condition.sim @@ -49,6 +49,29 @@ sql insert into tb6 values ('2021-05-05 18:19:25',62,62.0,62,62,62,62.0,true ,'6 sql insert into tb6 values ('2021-05-05 18:19:26',63,63.0,63,63,63,63.0,false,'63','63') sql insert into tb6 values ('2021-05-05 18:19:27',64,64.0,64,64,64,64.0,false,'64','64') sql insert into tb6 values ('2021-05-05 18:19:28',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL) + +sql create table stb2 (ts timestamp, u1 int unsigned, u2 bigint unsigned, u3 smallint unsigned, u4 tinyint unsigned, ts2 timestamp) TAGS(t1 int unsigned, t2 bigint unsigned, t3 timestamp) + +sql create table tb2_1 using stb2 tags(1,1,'2021-05-05 18:38:38') +sql create table tb2_2 using stb2 tags(2,2,'2021-05-05 18:58:58') + +sql insert into tb2_1 values ('2021-05-05 18:19:00',1,2,3,4,'2021-05-05 18:28:01') +sql insert into tb2_1 values ('2021-05-05 18:19:01',5,6,7,8,'2021-05-05 18:28:02') +sql insert into tb2_1 values ('2021-05-05 18:19:02',2,2,3,4,'2021-05-05 18:28:03') +sql insert into tb2_1 values ('2021-05-05 18:19:03',5,6,7,8,'2021-05-05 18:28:04') +sql insert into tb2_1 values ('2021-05-05 18:19:04',3,2,3,4,'2021-05-05 18:28:05') +sql insert into tb2_1 values ('2021-05-05 18:19:05',5,6,7,8,'2021-05-05 18:28:06') +sql insert into tb2_1 values ('2021-05-05 18:19:06',4,2,3,4,'2021-05-05 18:28:07') +sql insert into tb2_1 values ('2021-05-05 18:19:07',5,6,7,8,'2021-05-05 18:28:08') +sql insert into tb2_1 values ('2021-05-05 18:19:08',5,2,3,4,'2021-05-05 18:28:09') +sql insert into tb2_1 values ('2021-05-05 18:19:09',5,6,7,8,'2021-05-05 18:28:10') +sql insert into tb2_1 values ('2021-05-05 18:19:10',6,2,3,4,'2021-05-05 18:28:11') +sql insert into tb2_2 values ('2021-05-05 18:19:11',5,6,7,8,'2021-05-05 18:28:12') +sql insert into tb2_2 values ('2021-05-05 18:19:12',7,2,3,4,'2021-05-05 18:28:13') +sql insert into tb2_2 values ('2021-05-05 18:19:13',5,6,7,8,'2021-05-05 18:28:14') +sql insert into tb2_2 values ('2021-05-05 18:19:14',8,2,3,4,'2021-05-05 18:28:15') +sql insert into tb2_2 values ('2021-05-05 18:19:15',5,6,7,8,'2021-05-05 18:28:16') + sleep 100 print "column test" @@ -68,6 +91,7 @@ sql_error select * from stb1 where c7 in (0,2,3,1); sql_error select * from stb1 where c8 in (true); sql_error select * from stb1 where c8 in (1,2); sql_error select * from stb1 where t3 in (3); +sql_error select * from stb1 where t2 in (3.0); sql_error select ts,c1,c7 from stb1 where c7 > false 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:20.000'; @@ -1281,22 +1305,73 @@ if $data10 != @21-05-05 18:19:14.000@ then return -1 endi -#sql select * from stb1 where c5 in (3,33) and c8 in ('22','55'); -#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:14.000@ then -# return -1 -#endi +sql select * from stb1 where c5 in (3,33) and c8 in ('22','55'); +if $rows != 0 then + return -1 +endi + +sql select * from stb1 where c5 in (3,33) and c8 in ('33','54'); +if $rows != 1 then + return -1 +endi +if $data00 != @21-05-05 18:19:14.000@ then + return -1 +endi + +sql select * from stb1 where c5 in (3,33) or c8 in ('22','54'); +if $rows != 4 then + return -1 +endi +if $data00 != @21-05-05 18:19:02.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:09.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:14.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:23.000@ then + return -1 +endi + +sql select * from stb1 where (c9 in ('3','1','2','4','5') or c9 in ('33','11','22','44','55')) and c9 in ('1','3','11','13'); +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:02.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:04.000@ then + return -1 +endi + +#sql select * from stb2 where (u1 in (1,2,3,4) or u2 in (5,6)) and (u3 in (3,6) or u4 in (7,8)) print "ts test" print "tbname test" print "tag test" +sql select * from stb1 where t1 in (1,2) and t1 in (2,3); +if $rows != 4 then + return -1 +endi +if $data00 != @21-05-05 18:19:08.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:09.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:10.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:11.000@ then + return -1 +endi print "join test" -- GitLab