From ccebd62e07d712a8a9ca4ebd48128eca173acd37 Mon Sep 17 00:00:00 2001 From: jiacy-jcy Date: Tue, 19 Jul 2022 16:04:05 +0800 Subject: [PATCH 01/45] update --- tests/system-test/1-insert/delete_data.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/system-test/1-insert/delete_data.py b/tests/system-test/1-insert/delete_data.py index a7eba2d97d..3308c2e542 100644 --- a/tests/system-test/1-insert/delete_data.py +++ b/tests/system-test/1-insert/delete_data.py @@ -157,7 +157,7 @@ class TDTestCase: elif 'nchar' in column_type.lower(): tdSql.error(f'''delete from {tbname} where {error_list} {column_name} ="{base_data['nchar']}"''') else: - tdSql.error('delete from {tbname} where {error_list} {column_name} = {base_data[column_type]}') + tdSql.error(f'delete from {tbname} where {error_list} {column_name} = {base_data[column_type]}') def delete_data_ntb(self): tdSql.execute(f'create database if not exists {self.dbname}') From 29b8eb76ca95a8da941e156d91f5bdc874eddcb4 Mon Sep 17 00:00:00 2001 From: jiacy-jcy Date: Tue, 19 Jul 2022 19:48:33 +0800 Subject: [PATCH 02/45] update --- tests/system-test/1-insert/delete_data.py | 59 +++++++++++++++++------ 1 file changed, 45 insertions(+), 14 deletions(-) diff --git a/tests/system-test/1-insert/delete_data.py b/tests/system-test/1-insert/delete_data.py index 3308c2e542..836c32d757 100644 --- a/tests/system-test/1-insert/delete_data.py +++ b/tests/system-test/1-insert/delete_data.py @@ -28,6 +28,7 @@ class TDTestCase: tdSql.init(conn.cursor(),logSql) self.dbname = 'db_test' self.setsql = TDSetSql() + self.stbname = 'stb' self.ntbname = 'ntb' self.rowNum = 10 self.tbnum = 20 @@ -51,6 +52,7 @@ class TDTestCase: 'col13': f'nchar({self.str_length})', } + self.tinyint_val = random.randint(constant.TINYINT_MIN,constant.TINYINT_MAX) self.smallint_val = random.randint(constant.SMALLINT_MIN,constant.SMALLINT_MAX) self.int_val = random.randint(constant.INT_MIN,constant.INT_MAX) @@ -146,10 +148,36 @@ class TDTestCase: else: tdSql.checkEqual(tdSql.queryResult[0][0],base_data[column_type]) - def delete_rows(self): + def delete_rows(self,dbname,tbname,col_name,col_type,base_data,rowNum): + for i in range(rowNum): + tdSql.execute(f'delete from {tbname} where ts>{self.ts+i}') + tdSql.execute(f'flush database {dbname}') + tdSql.execute('reset query cache') + tdSql.query(f'select {col_name} from {tbname}') + tdSql.checkRows(i+1) + self.insert_base_data(col_type,tbname,rowNum,base_data) + for i in range(rowNum): + tdSql.execute(f'delete from {tbname} where ts>={self.ts+i}') + tdSql.execute(f'flush database {dbname}') + tdSql.execute('reset query cache') + tdSql.query(f'select {col_name} from {tbname}') + tdSql.checkRows(i) + self.insert_base_data(col_type,tbname,rowNum,base_data) + for i in range(rowNum): + tdSql.execute(f'delete from {tbname} where ts<={self.ts+i}') + tdSql.execute(f'flush database {dbname}') + tdSql.execute('reset query cache') + tdSql.query(f'select {col_name} from {tbname}') + tdSql.checkRows(rowNum-i-1) + self.insert_base_data(col_type,tbname,rowNum,base_data) + for i in range(rowNum): + tdSql.execute(f'delete from {tbname} where ts<{self.ts+i}') + tdSql.execute(f'flush database {dbname}') + tdSql.execute('reset query cache') + tdSql.query(f'select {col_name} from {tbname}') + tdSql.checkRows(rowNum-i) + self.insert_base_data(col_type,tbname,rowNum,base_data) - - pass def delete_error(self,tbname,column_name,column_type,base_data): for error_list in ['',f'ts = {self.ts} and',f'ts = {self.ts} or']: if 'binary' in column_type.lower(): @@ -168,19 +196,22 @@ class TDTestCase: self.delete_one_row(self.ntbname,col_type,col_name,self.base_data,self.dbname) self.delete_all_data(self.ntbname,col_type,self.rowNum,self.base_data,self.dbname) self.delete_error(self.ntbname,col_name,col_type,self.base_data) - for i in range(self.rowNum): - tdSql.execute(f'delete from {self.ntbname} where ts>{self.ts+i}') - tdSql.execute(f'flush database {self.dbname}') - tdSql.execute('reset query cache') - tdSql.query(f'select {col_name} from {self.ntbname}') - tdSql.checkRows(i+1) - self.insert_base_data(col_type,self.ntbname,self.rowNum,self.base_data) - + self.delete_rows(self.dbname,self.ntbname,col_name,col_type,self.base_data,self.rowNum) tdSql.execute(f'drop table {self.ntbname}') - + tdSql.execute(f'drop database {self.dbname}') + def delete_data_ctb(self): + tdSql.execute(f'create database if not exists {self.dbname}') + tdSql.execute(f'use {self.dbname}') + for col_name,col_type in self.column_dict.items(): + tdSql.execute(f'create table {self.stbname} (ts timestamp,{col_name} {col_type}) tags(t1 int)') + for i in range(self.tbnum): + tdSql.execute(f'create table {self.stbname}_{i} using {self.stbname} tags(1)') + self.insert_base_data(col_type,f'{self.stbname}_{i}',self.rowNum,self.base_data) + self.delete_one_row(f'{self.stbname}_{i}',col_type,col_name,self.base_data,self.dbname) + def run(self): - self.delete_data_ntb() - + # self.delete_data_ntb() + self.delete_data_ctb() def stop(self): tdSql.close() From 578a23d225af1ef60e4214cf605566a18e611b74 Mon Sep 17 00:00:00 2001 From: jiacy-jcy Date: Wed, 20 Jul 2022 09:32:47 +0800 Subject: [PATCH 03/45] update --- tests/system-test/1-insert/delete_data.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/tests/system-test/1-insert/delete_data.py b/tests/system-test/1-insert/delete_data.py index 836c32d757..27153185b9 100644 --- a/tests/system-test/1-insert/delete_data.py +++ b/tests/system-test/1-insert/delete_data.py @@ -25,7 +25,7 @@ from util.sqlset import TDSetSql class TDTestCase: def init(self, conn, logSql): tdLog.debug("start to execute %s" % __file__) - tdSql.init(conn.cursor(),logSql) + tdSql.init(conn.cursor()) self.dbname = 'db_test' self.setsql = TDSetSql() self.stbname = 'stb' @@ -208,10 +208,14 @@ class TDTestCase: tdSql.execute(f'create table {self.stbname}_{i} using {self.stbname} tags(1)') self.insert_base_data(col_type,f'{self.stbname}_{i}',self.rowNum,self.base_data) self.delete_one_row(f'{self.stbname}_{i}',col_type,col_name,self.base_data,self.dbname) + self.delete_all_data(f'{self.stbname}_{i}',col_type,self.rowNum,self.base_data,self.dbname) + self.delete_error(f'{self.stbname}_{i}',col_name,col_type,self.base_data) + self.delete_rows(self.dbname,f'{self.stbname}_{i}',col_name,col_type,self.base_data,self.rowNum) + tdSql.execute(f'drop table {self.stbname}') def run(self): - # self.delete_data_ntb() - self.delete_data_ctb() + self.delete_data_ntb() + # self.delete_data_ctb() def stop(self): tdSql.close() From bc0e8e306176fc09f9e32175cabb919f2faa5089 Mon Sep 17 00:00:00 2001 From: wangmm0220 Date: Wed, 20 Jul 2022 09:48:57 +0800 Subject: [PATCH 04/45] fix:invalidate in telnet schemaless --- source/client/src/clientSml.c | 2 +- source/dnode/vnode/src/tsdb/tsdbRead.c | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/source/client/src/clientSml.c b/source/client/src/clientSml.c index 078ecbb4db..ca45202547 100644 --- a/source/client/src/clientSml.c +++ b/source/client/src/clientSml.c @@ -2210,7 +2210,7 @@ static int32_t smlParseTelnetLine(SSmlHandle *info, void *data) { (SSmlSTableMeta **)taosHashGet(info->superTables, (*oneTable)->sTableName, (*oneTable)->sTableNameLen); if (tableMeta) { // update meta ret = smlUpdateMeta((*tableMeta)->colHash, (*tableMeta)->cols, cols, &info->msgBuf); - if (!hasTable && ret) { + if (!hasTable && ret == TSDB_CODE_SUCCESS) { ret = smlUpdateMeta((*tableMeta)->tagHash, (*tableMeta)->tags, (*oneTable)->tags, &info->msgBuf); } if (ret != TSDB_CODE_SUCCESS) { diff --git a/source/dnode/vnode/src/tsdb/tsdbRead.c b/source/dnode/vnode/src/tsdb/tsdbRead.c index ad12ee60f1..2cfe3548c9 100644 --- a/source/dnode/vnode/src/tsdb/tsdbRead.c +++ b/source/dnode/vnode/src/tsdb/tsdbRead.c @@ -2806,7 +2806,6 @@ int32_t tsdbReaderOpen(SVnode* pVnode, SQueryTableDataCond* pCond, SArray* pTabl if (pCond->suid != 0) { (*ppReader)->pSchema = metaGetTbTSchema((*ppReader)->pTsdb->pVnode->pMeta, (*ppReader)->suid, -1); - ASSERT((*ppReader)->pSchema); } else if (taosArrayGetSize(pTableList) > 0) { STableKeyInfo* pKey = taosArrayGet(pTableList, 0); (*ppReader)->pSchema = metaGetTbTSchema((*ppReader)->pTsdb->pVnode->pMeta, pKey->uid, -1); From 2a68aaf1ad4194f345fe9a56b724db54bbe6bc30 Mon Sep 17 00:00:00 2001 From: jiacy-jcy Date: Wed, 20 Jul 2022 09:59:44 +0800 Subject: [PATCH 05/45] update --- tests/system-test/1-insert/alter_table.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/system-test/1-insert/alter_table.py b/tests/system-test/1-insert/alter_table.py index 4a9cfd30c7..0007210ccd 100644 --- a/tests/system-test/1-insert/alter_table.py +++ b/tests/system-test/1-insert/alter_table.py @@ -211,10 +211,10 @@ class TDTestCase: for error in [constant.INT_UN_MIN-1,constant.INT_UN_MAX+1]: tdSql.error(f'alter table {self.stbname}_{i} set tag {k} = {error}') #! bug TD-17106 - # elif v.lower() == 'bigint unsigned': - # self.tag_check(i,k,tag_unbigint) - # for error in [constant.BIGINT_UN_MIN-1,constant.BIGINT_UN_MAX+1]: - # tdSql.error(f'alter table {self.stbname}_{i} set tag {k} = {error}') + elif v.lower() == 'bigint unsigned': + self.tag_check(i,k,tag_unbigint) + for error in [constant.BIGINT_UN_MIN-1,constant.BIGINT_UN_MAX+1]: + tdSql.error(f'alter table {self.stbname}_{i} set tag {k} = {error}') elif v.lower() == 'bool': self.tag_check(i,k,tag_bool) elif v.lower() == 'float': @@ -225,8 +225,8 @@ class TDTestCase: else: tdLog.exit(f'select {k} from {self.stbname}_{i},data check failure') #! bug TD-17106 - # for error in [constant.FLOAT_MIN*1.1,constant.FLOAT_MAX*1.1]: - # tdSql.error(f'alter table {self.stbname}_{i} set tag {k} = {error}') + for error in [constant.FLOAT_MIN*1.1,constant.FLOAT_MAX*1.1]: + tdSql.error(f'alter table {self.stbname}_{i} set tag {k} = {error}') elif v.lower() == 'double': tdSql.execute(f'alter table {self.stbname}_{i} set tag {k} = {tag_double}') tdSql.query(f'select {k} from {self.stbname}_{i}') From ebd02be60d827883cb59ca1dbac10c8814266148 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Wed, 20 Jul 2022 10:50:26 +0800 Subject: [PATCH 06/45] fix: definite lost while get sma meta --- include/common/tmsg.h | 1 + source/common/src/tmsg.c | 7 +++++++ source/dnode/mnode/impl/src/mndSma.c | 1 + tests/script/tsim/valgrind/checkError6.sim | 2 +- 4 files changed, 10 insertions(+), 1 deletion(-) diff --git a/include/common/tmsg.h b/include/common/tmsg.h index 2f4c80f025..3e27bd9268 100644 --- a/include/common/tmsg.h +++ b/include/common/tmsg.h @@ -2803,6 +2803,7 @@ typedef struct { int32_t tSerializeSTableIndexRsp(void* buf, int32_t bufLen, const STableIndexRsp* pRsp); int32_t tDeserializeSTableIndexRsp(void* buf, int32_t bufLen, STableIndexRsp* pRsp); +void tFreeSerializeSTableIndexRsp(STableIndexRsp* pRsp); void tFreeSTableIndexInfo(void* pInfo); diff --git a/source/common/src/tmsg.c b/source/common/src/tmsg.c index b79c412914..43003e7fab 100644 --- a/source/common/src/tmsg.c +++ b/source/common/src/tmsg.c @@ -2933,6 +2933,13 @@ int32_t tSerializeSTableIndexRsp(void *buf, int32_t bufLen, const STableIndexRsp return tlen; } +void tFreeSerializeSTableIndexRsp(STableIndexRsp *pRsp) { + if (pRsp->pIndex != NULL) { + taosArrayDestroy(pRsp->pIndex); + pRsp->pIndex = NULL; + } +} + int32_t tDeserializeSTableIndexInfo(SDecoder *pDecoder, STableIndexInfo *pInfo) { if (tDecodeI8(pDecoder, &pInfo->intervalUnit) < 0) return -1; if (tDecodeI8(pDecoder, &pInfo->slidingUnit) < 0) return -1; diff --git a/source/dnode/mnode/impl/src/mndSma.c b/source/dnode/mnode/impl/src/mndSma.c index bff3f19e99..e82e5e0870 100644 --- a/source/dnode/mnode/impl/src/mndSma.c +++ b/source/dnode/mnode/impl/src/mndSma.c @@ -1153,6 +1153,7 @@ _OVER: mError("failed to get table index %s since %s", indexReq.tbFName, terrstr()); } + tFreeSerializeSTableIndexRsp(&rsp); return code; } diff --git a/tests/script/tsim/valgrind/checkError6.sim b/tests/script/tsim/valgrind/checkError6.sim index 2783e94771..a9f66647f9 100644 --- a/tests/script/tsim/valgrind/checkError6.sim +++ b/tests/script/tsim/valgrind/checkError6.sim @@ -68,7 +68,7 @@ $null= system_content sh/checkValgrind.sh -n dnode1 print cmd return result ----> [ $system_content ] -if $system_content > 3 then +if $system_content > 0 then return -1 endi From 3a65f10f86b503b53d05e756405308ac75b23850 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Wed, 20 Jul 2022 11:01:06 +0800 Subject: [PATCH 07/45] fix: avoid rpc mem leak --- source/libs/transport/inc/transComm.h | 2 +- source/libs/transport/src/.transComm.c.swo | Bin 0 -> 28672 bytes source/libs/transport/src/transCli.c | 7 ++++--- source/libs/transport/src/transComm.c | 7 ++++++- 4 files changed, 11 insertions(+), 5 deletions(-) create mode 100644 source/libs/transport/src/.transComm.c.swo diff --git a/source/libs/transport/inc/transComm.h b/source/libs/transport/inc/transComm.h index 2972f512f1..37ee1f4b0c 100644 --- a/source/libs/transport/inc/transComm.h +++ b/source/libs/transport/inc/transComm.h @@ -392,7 +392,7 @@ typedef struct SDelayQueue { } SDelayQueue; int transDQCreate(uv_loop_t* loop, SDelayQueue** queue); -void transDQDestroy(SDelayQueue* queue); +void transDQDestroy(SDelayQueue* queue, void (*freeFunc)(void* arg)); int transDQSched(SDelayQueue* queue, void (*func)(void* arg), void* arg, uint64_t timeoutMs); bool transEpSetIsEqual(SEpSet* a, SEpSet* b); diff --git a/source/libs/transport/src/.transComm.c.swo b/source/libs/transport/src/.transComm.c.swo new file mode 100644 index 0000000000000000000000000000000000000000..72ffc92ce91fc2c808e34fe9b349cc0bff6709f0 GIT binary patch literal 28672 zcmeI53virQb;p+^glC#SC=Bl#1v@KQvMeV~9NSTlSF$avm!(x4ClfTQ-EXCh_vLTD zwWZh&lk#e(3@HP&kU*JI2pw7;<=`gFw-`elHuXE2i_uPBVJ*zBkyJ39N?A$t(;^&f7>NT~mFNU}Fq%J&_N`(=OU zpv!?S2f7^Sa-hqBE(f|C=yIUTf!`PoMD@p~UdC+Bb2B>bem}0`_XY0x4)^;+NBQI3 z^K0Gj2Rq6ybkDcD->-55_;Jp6@AtXi7dV1^xqIFH)#X5!16>YuInd=mmjhi6bUD!F zK$inu4sH+Wua1d+; zmxHfgluF$Rejl6$r$7J-U<>F2mx70%no2zc-V5FgUJiZ-l)(^q9QfQ*QmOZW_kuiF z1X(Z(4uK27PoJDh{RDgiybaXARp9yHdEkL3rBdGm_k%wHuLFx<61)hcz>lApO8p4@ z5WEB239bYE;JM&g;F;hnPe`Rsg5%&~@W%u)-UKS(I`ATJKKK>^kZ*#!!R?>|7QrEK zJ=hIi1b!P_3jTqB%6;Gi;1%HI;AU_T>;~6@o#5Hv0`MRKl3##(!No*k?dLv|x1ak>^Y{Wy z7ot8sQP^uvrcTpI7(~smYPRj>Gvx!rQ7y`q&2?sANM2QfN+XEUl=Pcz{iad6EvOaK zeLVN}?rsgADF?ZbUZJdgc&WI~NJ?|Ek75 zxv;Od(pWMBp3b?f-s!4H@ZN*%<5ok9EB3}-wFiu%1f~g%3!es{Lo#UIOhs>Tjy+RJ-x4r5!bt$Al zy8XROONMdMiiaH>G^I+tY|3azm|CpW%9ilaAWuJG(2&Vn&ItMa2D+}?z7QEmjUW0< zk;e`(HJbUnjM%|tD<{uJsRXexIV=I`idXzAtxuZ(2EjDLkEeypMsMbn86n{8(EW~(iGglzQH ztBMGLA^QgPUz1%9OtBO;B2y$;%q*@(LBo_9h9zmDnk>kO8V!V9EhMYt!oW16Qkm6? zCfCf-AgF8AT390YjP=d1OVP3zl?qCdTMF!e%zRZVdal!6bXNu~Q<1V8b@!#X=z{=9=Y5 z)WPWhEKsd6E$y(XlQa>kv{oTIRGT@Bg<&mB_Y`xbvgLD5tgsks%qDgTk%V4tF~oL3 z!VmP%YFj)VOFkNcb|y`cF>2LBY0JaBGV)_*YEND3$Vn>NlO7TZs!>Vo4AMC#K{cWr9mI!$Qne9HE+Mdv_hC@f*ZzIB zkX;T@j_GPXu*6K(3e9pLnue5SvIl0zMn)H=r!r#;<5S~VG~n`5HD7KP0@GuUe3I0> z+#~OcSY$IlH?}Z;LrOQiK9eigs!QfXiH#{*X3waHwWTmu*=oj%rdpHr8U$v~aun5f z4Gx|-aboLIwYjwxE|Ei>52}rzF*v-HzRZzY(=?WA&2qsk=Z*)kHXoE^>&~I~^;OyR zWZ&FBHE%}b$XYY|gK7}6EzUF->B~&m{^(1(+c%z_!ZMnD)3av8%#6%t$20R2BeP~^ zes*ShZcN7%o-Abp& zKs*PbPKGmArE%6=#AXCxLyiGgt~bA;4BK$S?lP;$F3%Z*>GUJG*6bm=S{P(5m0F=x zTy=BHAWzOT%MpjGUbB7M(6uHzGCgNTakl!+cs0M(?74NBjq}B_d5QzIm5q2f#UVue z|DWL3s$Y!%zt1^`U&P;k3%Cm$1%u%E;Mw5E`24Q`b#N;vg2P}QWWhDyzw!6K2JQjx z0IvYc;2;Yea@M&;2cr&Ph!{8v;4+g*%AUwJpbbq=W z=yIUTfi4HS9O!c3H=hHS2UQMR>PfeP4;pSI4pb-y>enV?3lb_3pU)O2Lm928>L|W9 z(UGy01KNl4U|fd;z@$GH36Mc&1A@zqU^XbGtwSQ`!s2*A$0ooK+H#3_1VplJKPmhr z4Ros8;kt-N^o71Zp0B=&sHp9?BgSj#>lIQ)^2eH`aAQ((w!DKB>m^&~%~m)!LM$^X z#0qCO;>G#|_~|-cNDpUEL5DO(3Wen8buWbtM^?t#$rlP64(lQbJ_s#S&6I0a>XjuM z9YWT5c_(5@#4UV1T-CInsWe%uNz?V9D#T03q2Cmn)qG5Sp`h*+vC^72w>F;cdsFIN zV>gP%!E7|dr2Dihrzd_~Z6vB5)>g-=$J2f&f|Iy6LG^gs6nNLHr!|VwHtPN$8n@oL z6f$$Yt?>>!VZF}U%uh&6REAr;*-hPe9k<;0^k${A<;N4el{*u0>7m*aT@nw!on{R$ zDZ!#4+NfO;8dJ~?))ZQjD02aacH7_?<^;&aRjsi=$eZ!gJ@Yp#WHU1hbK_I{C&m^= zGMTZNEYbg-p&lK|afWDwsE`-<4kG159hJUuJaMgRiIAEy;e>d1Y~#oAp~F_KN3vs; z6<%_+xO)zHVM|<@h`B^dsuCm14GahM#?7T$wib^Sh!Zb%JZoTa-=Wbd4Jw+; zh>@97r%bDve1}|Kw;IYD5tGqqw5$+Q(vTXz_DIWWvoc*At2cI=(v~f@rX|@aTTH4D znyBxF@y#6_rRqE@)KZ|IrN>qzcdR~#MmNTeH3_WF=@W6Ee&atbN_ADJY?#Xj>7Gpu zi9gb(jg{-|OP7ag3LSyO{QNt>Nw5!$fnM+o@K5;np9Aj$Zvl6MJAlLiwu6hokMQg72Y(CR3~mBP zz}4Ux;1X~FI1hXipZ+gE04Bk+fcW@d0G|P;z)`RS4ug4c0XQFg5kFpX0Dcb?!6Fz3 z2f!Y%3tS6+3;Yz{{j=b&!H2FhAl)yAN2)2Mr!PCI~XtTOn{dF$p?5M_!aVf5d0^&7rY1D2^PUi z!7bo=um$u2(T6KQ{3Gg^k5&eTbKz2hr6c#mqI6D}I{sxFi=uD}KEu+Q*F1En+*C6h^U;joK?XVS~(1VvA`t zXrm+9k%jD$8DhcXQ(3~3az)&44vfqlSeTk#n3&ESR2Fam(2dCMC(%lB2aQ&Aw6(;k zHF2hltt8i2t>)QHs)e+E)Q+vF=$_5CSWEYCi+5DQjl?|lW4_jito;%D*&A4ih&>F- zX4vfDqCyNTWqR7-rQLs+bhg9=Ym}?h=Ns%0WF`=1x2j_|;Yk9!EAu)`dNUHQ3=CJ` zs#H2OKQ=$MFf%`Qz?U53cBtPR(^6q-qKgSg_SJj`o*wRx*QZCdVQxfNf?`%wiz?Jr z&I}AoxKs#<*+%k+7Ext$y3U0kYeE{cV-;3zNwCtEm53OxP}gQez^%mVEn8rmeXc42 zmW9ZmS~Jyv(^y3~W0r$Z?xyLVj^y7>ZLNenrs>KP{U?%1wEH=cxSi?@gmW9ozwojd zG=n}^>bD)Znn)^K8U znaCDqsXne@mM-kp+Gv}fT_bYYuq_m4v$-c%h;Rsq4?m? zs_ia@6HFCrlrGn5b-7Vt9dN_E=*B*qHS-u5596#rbS&A4&Oml+{9Z1Vl7dtMlP~C~ zahtHlzHD2yoh#KNd%@18tjI|F~H}*$!W8t=q)ix=tTC>P)?`=!@ipAB>Ezst78^* zJBbN$wqozb*>!Q%`D#6vKPtDvb|2)EO}$`E$OowRF61_K2;-JBXKaTf!pi0PHOx1; zlXH(bZlXJTl$Gr^+t_cgtKGfz*tk@Dp(C$YVTh{Bta z&YCV=K}4V$qM;y|Fd+k}nUgoYHq~nx&TO@XDzrFt%%v1=mI|6YVyQ(^v2~Cln^@@c z!5q)oxN-&6&*Vhoi3|+2O;8vx+>u=4IwBP!=|IiWt)#=0@rT<}EgcV}x_RowF!GEF&KNKvhB$S(V?6KT&GDB$IKeiYd$$@Y`$bF32|@^04^67 z18t>oT}LNw;5adnXOResZgXN=_Q&mRp1@d*rJhw|H#KFZX5gHJk!=~p!eysxN~w$C z@QQP$7!=<-_1dzpxX9QI<%?S zVx%;2TFc#AX`}u>E`2I5z8?PnYn{XQcf5Q*cq6ETNpKC=0`yT{f1#bX{K?V$hXMhXA1>oEG|B?gnZcqo3 z1279VgA2ib5CixY_-F8S@Cop7@Jg@*roj|=F&GBV0S^-g_%`?gkeI;<@KSISxDgx% zPX^y27Vs|cPEZFofH5!v40w`8n_Qg4B-tR0!2^& zqC*l-==@1+hxI5F#h0}>LJrXCEGeR#QPcq$7(PZEKuwVv2I zdgTbsuB$7jx7XJY&1q54TD|H>6OVJdvTK#h0anTqfi!)N7q1)D57RcfxYuf0RJkl; zgvW_+NEq12m1S&ufeiz=!=L5KY;dfP1M4y7YrT946Q;@Hj*ERL%!kTm$0nz57)vj^ zZj=RmW;yQQ0NJT&OM{E1UgqKla|>gWGua~)3e$C-YRaHNSzvuO*I^tia@Lby)(dQ( z?g>BN4mQa9#B^y5fih1#9xbx*9CLm0$%RRFx!^Mbwv@XmZ?>Jv+&ZlWU5Y-eVR}s7 zx+Mt$MW3Z|azkj%!N0XDCfDF(6=`)xG5Z5;EnTtT`i!wXw#{2kaemhN+0RxZE+<05 zIT9*RQhYQ=by#M{kL9E_Ire><4BdunOGI1S4WZ+cWvd2V*^?7|mHwUFke84zY)vvk zD#*KarrA<~weck!r7B4dsGc+?;LtJCGqi10md5MMS&R%_TYHoUb2_z`u$f&Cc#IOv zQs%0fud@i$E+p4Lav$-FpbtknyGnjCPJ-N-EQYnCL6s{C@vx;pH8kDVQAjki8emY` zn{fAm4Cq=}(`IdTJbZhUv!juA)vlJ7GaKkfCR!P7R_c3|&~mAI6k^>DLy=x`=($C< zSN#&8%wmo5Xe^3p(HJMq%|;*EC$W~4j$J;vWlC@DGqJh_U6eqYmaBo6TNOEXC^OJ* zu1(uEhs{Ujiz&|X^Vw=!8%x_pZryjae=*XB@+{LBeu>` zy-iEVmDTOfyi#?XN4Y4AtF~Q~`3`5AQM%BGY-jy4B>&)qGgC;5=i4VwcE+CD#%Mdg zm!%8TXkE5h#gcc{uK7jn880PhxFbI^N}|HPTs}*YEcTeq$#o%QyC7_|G8u$RgvQjY>H?;TKQ!nw zbcs~u{{K=OHofb`|M!2N?;r8+KL*|n?g6L3ZD1N~1wY5X|2%jPco+Cn@M`c%a3dH7 z2D|_~AAAEJ|Lx#bFaoXwY49BIOdvS{mx2fI^*;&j0`j*34ucsWx&P;Z`|#=C3Yy?X zum?!K|MS4l@Z-M^z6-trJ_=5O6>uC#KENaR^4|rL^Z!>s@&Hyq5s1J4V$cVA!E?dI z;3Du;@L7ENcLMo)0k?x0Ah`iofXjgR`wxMSf{%c^z{@}p1mGap54M1(gG+$?O@a60 z`G18k|1kJ6xEGuRli++HKK_4!2f^K-0d|01a0S>5evQ8_`2b%6p8}r% z_ka+{-wAjDcptvH{9S+{Aou>F13jSQ#~KT(|MuU)sl6)Q)csH56~>fOSaZ>cobc zuqD_3J@6)ocAc~-T@ss=FTmcsV`%#=n1qwtP77<+S|uNH7K>!G3zrkdH0%u4w;3~% zGo&=f8A-OfSc&8rM@^*M2yv$$E)e(RsH^88Lc#LN=ZqbaOMkxp#k2h|$!=`DV{QfN zB=pH4*|n56Yy(lQagcN7YjHnC9f_dSjNV`Qm`Xgzu1!5=W_G-J z^;Pa-yG56$!|q7!8XdQXxs_5itCR#QK|V_>v*$W)H0R#in^)@iR~ zlgH*dj5pL#xr39zI8@nD86ST(%JF|k2^aV?6TF^+AsFwtZa>307P;Z1hVAnJoRlZ+ zPd?C}aCfp)O)}fE!1CJ@MNOIHmX^R|O12KW55@f3dL{Xuypvz@vPB-JBau<^+G6d2 zKc0*`@gq@98!<+Su#GuV2>Ug4WRld8#0}->p*e1M$Y#)v4!H~l8(-6%uq`1~9rHv~ zfxiUe2aE+DD|*Y<*vCz!<(lfF@X;qNBotT6tTuHt6+T!_ukkNorM4p@(Wg4`ii`Rj zU-lewMRQp?7zvliI8pw`vT#SLb$EW(x`W7!YDRku)~-aSbdC&f_3<6}GbwF)ZZ)iR zI+jk)UIlR-?Fmjs)lglMt^N`?wT5}FmWWQW##$$z(L-K7XVMGD@Lrd6FQSNrZ|7(a zf_*v;ii}4K5jeg&qIc@$wZ4^mduquq_eSf<3J?n2JDDS|` z+X>rc&xvi|fZ=vOCw##(A^m>0Zk-RajDlrY)r9bRgrE$h!NJQ4A z2}vs<%tNk22_+g9d%eB&!pg~#YNaIQ5ZWfC#SQlOj&?(x?Id$N-cIAQfxD50xAsb; zWf)vYq$N~3fDl6Htyir?BQZ;Q|K=^LGrl%trolxuOo`|)D&8{5TIkzahg4s6n1gtj zL_gdJ>T0pV@ax!(A8(uX+c%=dGAL;ribKNVZAtMbOatQh*4%g8;ET o8cslWI;L&svhk#y8f`qXtVUf6ZTk2aFImPa^=Q?_0ypCont); userdata->pCont = NULL; } -static void destroyCmsg(SCliMsg* pMsg) { +static void destroyCmsg(void* arg) { + SCliMsg* pMsg = arg; if (pMsg == NULL) { return; } @@ -1001,7 +1002,7 @@ static void destroyThrdObj(SCliThrd* pThrd) { TRANS_DESTROY_ASYNC_POOL_MSG(pThrd->asyncPool, SCliMsg, destroyCmsg); transDestroyAsyncPool(pThrd->asyncPool); - transDQDestroy(pThrd->delayQueue); + transDQDestroy(pThrd->delayQueue, destroyCmsg); taosMemoryFree(pThrd->loop); taosMemoryFree(pThrd); } diff --git a/source/libs/transport/src/transComm.c b/source/libs/transport/src/transComm.c index 84af8da513..0a2d3a13ff 100644 --- a/source/libs/transport/src/transComm.c +++ b/source/libs/transport/src/transComm.c @@ -456,7 +456,7 @@ int transDQCreate(uv_loop_t* loop, SDelayQueue** queue) { return 0; } -void transDQDestroy(SDelayQueue* queue) { +void transDQDestroy(SDelayQueue* queue, void (*freeFunc)(void* arg)) { taosMemoryFree(queue->timer); while (heapSize(queue->heap) > 0) { @@ -467,6 +467,11 @@ void transDQDestroy(SDelayQueue* queue) { heapRemove(queue->heap, minNode); SDelayTask* task = container_of(minNode, SDelayTask, node); + + STaskArg* arg = task->arg; + freeFunc(arg->param1); + taosMemoryFree(arg); + taosMemoryFree(task); } heapDestroy(queue->heap); From 43711652356f62467ed689afecd7281d1a8992eb Mon Sep 17 00:00:00 2001 From: 54liuyao <54liuyao@163.com> Date: Wed, 20 Jul 2022 10:03:50 +0800 Subject: [PATCH 08/45] feat(stream): add result group id --- source/libs/executor/src/timewindowoperator.c | 109 ++++++++++++++++-- tests/script/tsim/stream/basic1.sim | 107 +++++++++++++++++ tests/script/tsim/stream/sliding.sim | 20 +++- 3 files changed, 220 insertions(+), 16 deletions(-) diff --git a/source/libs/executor/src/timewindowoperator.c b/source/libs/executor/src/timewindowoperator.c index b0a74c3002..42dfdc603a 100644 --- a/source/libs/executor/src/timewindowoperator.c +++ b/source/libs/executor/src/timewindowoperator.c @@ -660,6 +660,62 @@ void printDataBlock(SSDataBlock* pBlock, const char* flag) { taosMemoryFree(pBuf); } +typedef int32_t (*__compare_fn_t)(void* pKey, void* data, int32_t index); + +int32_t binarySearchCom(void* keyList, int num, void* pKey, int order, __compare_fn_t comparefn) { + int firstPos = 0, lastPos = num - 1, midPos = -1; + int numOfRows = 0; + + if (num <= 0) return -1; + if (order == TSDB_ORDER_DESC) { + // find the first position which is smaller or equal than the key + while (1) { + if (comparefn(pKey, keyList, lastPos) >= 0) return lastPos; + if (comparefn(pKey, keyList, firstPos) == 0) return firstPos; + if (comparefn(pKey, keyList, firstPos) < 0) return firstPos - 1; + + numOfRows = lastPos - firstPos + 1; + midPos = (numOfRows >> 1) + firstPos; + + if (comparefn(pKey, keyList, midPos) < 0) { + lastPos = midPos - 1; + } else if (comparefn(pKey, keyList, midPos) > 0) { + firstPos = midPos + 1; + } else { + break; + } + } + + } else { + // find the first position which is bigger or equal than the key + while (1) { + if (comparefn(pKey, keyList, firstPos) <= 0) return firstPos; + if (comparefn(pKey, keyList, lastPos) == 0) return lastPos; + + if (comparefn(pKey, keyList, lastPos) > 0) { + lastPos = lastPos + 1; + if (lastPos >= num) + return -1; + else + return lastPos; + } + + numOfRows = lastPos - firstPos + 1; + midPos = (numOfRows >> 1) + firstPos; + + if (comparefn(pKey, keyList, midPos) < 0) { + lastPos = midPos - 1; + } else if (comparefn(pKey, keyList, midPos) > 0) { + firstPos = midPos + 1; + } else { + break; + } + } + } + + return midPos; +} + typedef int64_t (*__get_value_fn_t)(void* data, int32_t index); int32_t binarySearch(void* keyList, int num, TSKEY key, int order, __get_value_fn_t getValuefn) { @@ -722,14 +778,31 @@ int64_t getReskey(void* data, int32_t index) { return *(int64_t*)pos->key; } +int32_t compareResKey(void* pKey, void* data, int32_t index) { + SArray* res = (SArray*)data; + SResKeyPos* pos = taosArrayGetP(res, index); + SWinRes* pData = (SWinRes*) pKey; + if (pData->ts == *(int64_t*)pos->key) { + if (pData->groupId > pos->groupId) { + return 1; + } else if (pData->groupId < pos->groupId) { + return -1; + } + return 0; + } else if (pData->ts > *(int64_t*)pos->key) { + return 1; + } + return -1; +} + static int32_t saveResult(int64_t ts, int32_t pageId, int32_t offset, uint64_t groupId, SArray* pUpdated) { int32_t size = taosArrayGetSize(pUpdated); - int32_t index = binarySearch(pUpdated, size, ts, TSDB_ORDER_DESC, getReskey); + SWinRes data = {.ts = ts, .groupId = groupId}; + int32_t index = binarySearchCom(pUpdated, size, &data, TSDB_ORDER_DESC, compareResKey); if (index == -1) { index = 0; } else { - TSKEY resTs = getReskey(pUpdated, index); - if (resTs < ts) { + if (compareResKey(&data, pUpdated, index) > 0) { index++; } else { return TSDB_CODE_SUCCESS; @@ -753,10 +826,10 @@ static int32_t saveResultRow(SResultRow* result, uint64_t groupId, SArray* pUpda return saveResult(result->win.skey, result->pageId, result->offset, groupId, pUpdated); } -static void removeResult(SArray* pUpdated, TSKEY key) { +static void removeResult(SArray* pUpdated, SWinRes* pKey) { int32_t size = taosArrayGetSize(pUpdated); - int32_t index = binarySearch(pUpdated, size, key, TSDB_ORDER_DESC, getReskey); - if (index >= 0 && key == getReskey(pUpdated, index)) { + int32_t index = binarySearchCom(pUpdated, size, pKey, TSDB_ORDER_DESC, compareResKey); + if (index >= 0 && 0 == compareResKey(pKey, pUpdated, index)) { taosArrayRemove(pUpdated, index); } } @@ -765,7 +838,7 @@ static void removeResults(SArray* pWins, SArray* pUpdated) { int32_t size = taosArrayGetSize(pWins); for (int32_t i = 0; i < size; i++) { SWinRes* pW = taosArrayGet(pWins, i); - removeResult(pUpdated, pW->ts); + removeResult(pUpdated, pW); } } @@ -775,14 +848,30 @@ int64_t getWinReskey(void* data, int32_t index) { return pos->ts; } +int32_t compareWinRes(void* pKey, void* data, int32_t index) { + SArray* res = (SArray*)data; + SWinRes* pos = taosArrayGetP(res, index); + SResKeyPos* pData = (SResKeyPos*) pKey; + if (*(int64_t*)pData->key == pos->ts) { + if (pData->groupId > pos->groupId) { + return 1; + } else if (pData->groupId < pos->groupId) { + return -1; + } + return 0; + } else if (*(int64_t*)pData->key > pos->ts) { + return 1; + } + return -1; +} + static void removeDeleteResults(SArray* pUpdated, SArray* pDelWins) { int32_t upSize = taosArrayGetSize(pUpdated); int32_t delSize = taosArrayGetSize(pDelWins); for (int32_t i = 0; i < upSize; i++) { SResKeyPos* pResKey = taosArrayGetP(pUpdated, i); - int64_t key = *(int64_t*)pResKey->key; - int32_t index = binarySearch(pDelWins, delSize, key, TSDB_ORDER_DESC, getWinReskey); - if (index >= 0 && key == getWinReskey(pDelWins, index)) { + int32_t index = binarySearchCom(pDelWins, delSize, pResKey, TSDB_ORDER_DESC, compareWinRes); + if (index >= 0 && 0 == compareWinRes(pResKey, pDelWins, index)) { taosArrayRemove(pDelWins, index); } } diff --git a/tests/script/tsim/stream/basic1.sim b/tests/script/tsim/stream/basic1.sim index 2a6d64bcaf..a6f9860831 100644 --- a/tests/script/tsim/stream/basic1.sim +++ b/tests/script/tsim/stream/basic1.sim @@ -462,6 +462,113 @@ if $data25 != 3 then return -1 endi +sql create database test2 vgroups 1 +sql show databases +sql use test2 +sql create stable st(ts timestamp, a int, b int, c int, d double) tags(ta int,tb int,tc int); +sql create table t1 using st tags(1,1,1); +sql create table t2 using st tags(2,2,2); +sql create table t3 using st tags(2,2,2); +sql create table t4 using st tags(2,2,2); +sql create table t5 using st tags(2,2,2); +sql create stream streams2 trigger at_once into streamt as select _wstart, count(*) c1, sum(a) c3,max(b) c4 from st partition by tbname interval(10s) + +sql insert into t1 values(1648791213000,1,1,1,1.0) t2 values(1648791213000,2,2,2,2.0) t3 values(1648791213000,3,3,3,3.0) t4 values(1648791213000,4,4,4,4.0); + +$loop_count = 0 + +loop0: +sleep 300 + +$loop_count = $loop_count + 1 +if $loop_count == 10 then + return -1 +endi + +sql select * from streamt; + +if $rows != 4 then + print =====rows=$rows + goto loop0 +endi + +sql insert into t1 values(1648791213000,5,5,5,5.0) t2 values(1648791213000,6,6,6,6.0) t5 values(1648791213000,7,7,7,7.0); + + +$loop_count = 0 + +loop1: +sleep 300 + +$loop_count = $loop_count + 1 +if $loop_count == 10 then + return -1 +endi + +sql select * from streamt order by c4 desc; + +if $rows != 5 then + print =====rows=$rows + goto loop1 +endi + +# row 0 +if $data01 != 1 then + print =====data01=$data01 + goto loop1 +endi + +if $data02 != 7 then + print =====data02=$data02 + goto loop1 +endi + +# row 1 +if $data11 != 1 then + print =====data11=$data11 + goto loop1 +endi + +if $data12 != 6 then + print =====data12=$data12 + goto loop1 +endi + +# row 2 +if $data21 != 1 then + print =====data21=$data21 + goto loop1 +endi + +if $data22 != 5 then + print =====data22=$data22 + goto loop1 +endi + +sql insert into t1 values(1648791213000,8,8,8,8.0); + +$loop_count = 0 + +loop2: +sleep 300 + +$loop_count = $loop_count + 1 +if $loop_count == 10 then + return -1 +endi + +sql select * from streamt order by c4 desc; + +# row 0 +if $data01 != 1 then + print =====data01=$data01 + goto loop2 +endi + +if $data02 != 8 then + print =====data02=$data02 + goto loop2 +endi system sh/exec.sh -n dnode1 -s stop -x SIGINT diff --git a/tests/script/tsim/stream/sliding.sim b/tests/script/tsim/stream/sliding.sim index f34a50de9d..4364b56d44 100644 --- a/tests/script/tsim/stream/sliding.sim +++ b/tests/script/tsim/stream/sliding.sim @@ -366,18 +366,21 @@ if $data32 != 8 then goto loop1 endi +#$loop_all = 0 +#looptest: + sql drop database IF EXISTS test2; sql drop stream IF EXISTS streams21; sql drop stream IF EXISTS streams22; -sql create database test2 vgroups 2; +sql create database test2 vgroups 6; sql use test2; sql create stable st(ts timestamp, a int, b int, c int, d double) tags(ta int,tb int,tc int); sql create table t1 using st tags(1,1,1); sql create table t2 using st tags(2,2,2); -sql create stream streams21 trigger at_once into streamt as select _wstart, count(*) c1, sum(a) c3 , max(b) c4, min(c) c5 from t1 interval(10s); -sql create stream streams22 trigger at_once into streamt2 as select _wstart, count(*) c1, sum(a) c3 , max(b) c4, min(c) c5 from st interval(10s); +sql create stream streams21 trigger at_once into streamt as select _wstart, count(*) c1, sum(a) c3 , max(b) c4, min(c) c5 from t1 interval(10s, 5s); +sql create stream streams22 trigger at_once into streamt2 as select _wstart, count(*) c1, sum(a) c3 , max(b) c4, min(c) c5 from st interval(10s, 5s); sql insert into t1 values(1648791213000,1,1,1,1.0); sql insert into t1 values(1648791223001,2,2,2,1.1); @@ -394,7 +397,7 @@ sql insert into t2 values(1648791213004,4,10,10,4.1); $loop_count = 0 loop2: -sleep 300 +sleep 100 $loop_count = $loop_count + 1 if $loop_count == 10 then @@ -452,7 +455,7 @@ print step 6 $loop_count = 0 loop3: -sleep 300 +# sleep 300 $loop_count = $loop_count + 1 if $loop_count == 10 then @@ -464,7 +467,7 @@ sql select * from streamt2; # row 0 if $data01 != 4 then print =====data01=$data01 - # goto loop3 + goto loop3 endi if $data02 != 10 then @@ -505,4 +508,9 @@ if $data32 != 8 then goto loop3 endi +$loop_all = $loop_all + 1 +print ============loop_all=$loop_all + +#goto looptest + system sh/stop_dnodes.sh \ No newline at end of file From 2b4e861f8da7a6cc0bcb0b8076c4288f80b63c23 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Wed, 20 Jul 2022 11:03:58 +0800 Subject: [PATCH 09/45] fix(query): update the column data info. --- source/libs/executor/src/timewindowoperator.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/source/libs/executor/src/timewindowoperator.c b/source/libs/executor/src/timewindowoperator.c index b0a74c3002..3933ded7a9 100644 --- a/source/libs/executor/src/timewindowoperator.c +++ b/source/libs/executor/src/timewindowoperator.c @@ -924,11 +924,17 @@ SResultRowPosition addToOpenWindowList(SResultRowInfo* pResultRowInfo, const SRe int64_t* extractTsCol(SSDataBlock* pBlock, const SIntervalAggOperatorInfo* pInfo) { TSKEY* tsCols = NULL; + if (pBlock->pDataBlock != NULL) { SColumnInfoData* pColDataInfo = taosArrayGet(pBlock->pDataBlock, pInfo->primaryTsIndex); tsCols = (int64_t*)pColDataInfo->pData; - if (tsCols != NULL) { + // no data in primary ts + if (tsCols[0] == 0 && tsCols[pBlock->info.rows - 1] == 0) { + return NULL; + } + + if (tsCols[0] != 0 && (pBlock->info.window.skey == 0 && pBlock->info.window.ekey == 0)) { blockDataUpdateTsWindow(pBlock, pInfo->primaryTsIndex); } } From 242ad4a1ff37ff96960a3c456ba5517055ebbbf3 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Wed, 20 Jul 2022 11:23:19 +0800 Subject: [PATCH 10/45] test: valgrind case --- tests/script/tsim/valgrind/basic2.sim | 133 +++++++++++++++----------- tests/script/tsim/valgrind/basic3.sim | 68 ++++++------- 2 files changed, 112 insertions(+), 89 deletions(-) diff --git a/tests/script/tsim/valgrind/basic2.sim b/tests/script/tsim/valgrind/basic2.sim index d3c72d1e5c..45ac78daf0 100644 --- a/tests/script/tsim/valgrind/basic2.sim +++ b/tests/script/tsim/valgrind/basic2.sim @@ -1,6 +1,5 @@ system sh/stop_dnodes.sh system sh/deploy.sh -n dnode1 -i 1 -system sh/cfg.sh -n dnode1 -c debugflag -v 131 system sh/exec.sh -n dnode1 -s start -v sql connect @@ -23,65 +22,87 @@ if $data(1)[4] != ready then endi print =============== step2: create db -sql create database d1 vgroups 2 buffer 3 -sql show databases -sql use d1 -sql show vgroups +sql create database db +sql use db +sql create table db.stb (ts timestamp, c1 int, c2 binary(4)) tags(t1 int, t2 float, t3 binary(16)) comment "abd" +sql create table db.c1 using db.stb tags(101, 102, "103") -print =============== step3: create show stable -sql create table if not exists stb (ts timestamp, c1 int, c2 float, c3 double) tags (t1 int unsigned) -sql show stables -if $rows != 1 then - return -1 -endi +print =============== step3: alter stb +sql_error alter table db.stb add column ts int +sql alter table db.stb add column c3 int +sql alter table db.stb add column c4 bigint +sql alter table db.stb add column c5 binary(12) +sql alter table db.stb drop column c1 +sql alter table db.stb drop column c4 +sql alter table db.stb MODIFY column c2 binary(32) +sql alter table db.stb add tag t4 bigint +sql alter table db.stb add tag c1 int +sql alter table db.stb add tag t5 binary(12) +sql alter table db.stb drop tag c1 +sql alter table db.stb drop tag t5 +sql alter table db.stb MODIFY tag t3 binary(32) +sql alter table db.stb rename tag t1 tx +sql alter table db.stb comment 'abcde' ; +sql drop table db.stb -print =============== step4: create show table -sql create table ct1 using stb tags(1000) -sql create table ct2 using stb tags(2000) -sql create table ct3 using stb tags(3000) -sql show tables -if $rows != 3 then - return -1 -endi +print =============== step4: alter tb +sql create table tb (ts timestamp, a int) +sql insert into tb values(now-28d, -28) +sql select count(a) from tb +sql alter table tb add column b smallint +sql insert into tb values(now-25d, -25, 0) +sql select count(b) from tb +sql alter table tb add column c tinyint +sql insert into tb values(now-22d, -22, 3, 0) +sql select count(c) from tb +sql alter table tb add column d int +sql insert into tb values(now-19d, -19, 6, 0, 0) +sql select count(d) from tb +sql alter table tb add column e bigint +sql alter table tb add column f float +sql alter table tb add column g double +sql alter table tb add column h binary(10) +sql select count(a), count(b), count(c), count(d), count(e), count(f), count(g), count(h) from tb +sql select * from tb order by ts desc -print =============== step5: insert data -sql insert into ct1 values(now+0s, 10, 2.0, 3.0) -sql insert into ct1 values(now+1s, 11, 2.1, 3.1)(now+2s, -12, -2.2, -3.2)(now+3s, -13, -2.3, -3.3) -sql insert into ct2 values(now+0s, 10, 2.0, 3.0) -sql insert into ct2 values(now+1s, 11, 2.1, 3.1)(now+2s, -12, -2.2, -3.2)(now+3s, -13, -2.3, -3.3) -sql insert into ct3 values('2021-01-01 00:00:00.000', 10, 2.0, 3.0) +print =============== step5: alter stb and insert data +sql create table stb (ts timestamp, c1 int, c2 binary(4)) tags(t1 int, t2 float, t3 binary(16)) comment "abd" +sql show db.stables +sql describe stb +sql_error alter table stb add column ts int + +sql create table db.ctb using db.stb tags(101, 102, "103") +sql insert into db.ctb values(now, 1, "2") +sql show db.tables +sql select * from db.stb +sql select * from tb + +sql alter table stb add column c3 int +sql describe stb +sql select * from db.stb +sql select * from tb +sql insert into db.ctb values(now+1s, 1, 2, 3) +sql select * from db.stb + +sql alter table db.stb add column c4 bigint +sql select * from db.stb +sql insert into db.ctb values(now+2s, 1, 2, 3, 4) + +sql alter table db.stb drop column c1 +sql reset query cache +sql select * from tb +sql insert into db.ctb values(now+3s, 2, 3, 4) +sql select * from db.stb + +sql alter table db.stb add tag t4 bigint +sql select * from db.stb +sql select * from db.stb +sql_error create table db.ctb2 using db.stb tags(101, "102") +sql create table db.ctb2 using db.stb tags(101, 102, "103", 104) +sql insert into db.ctb2 values(now, 1, 2, 3) print =============== step6: query data -sql select * from ct1 -sql select * from stb -sql select c1, c2, c3 from ct1 -sql select ts, c1, c2, c3 from stb - -print =============== step7: count -sql select count(*) from ct1; -sql select count(*) from stb; -sql select count(ts), count(c1), count(c2), count(c3) from ct1 -sql select count(ts), count(c1), count(c2), count(c3) from stb - -print =============== step8: func -sql select first(ts), first(c1), first(c2), first(c3) from ct1 -sql select min(c1), min(c2), min(c3) from ct1 -sql select max(c1), max(c2), max(c3) from ct1 -sql select sum(c1), sum(c2), sum(c3) from ct1 - -print =============== step9: insert select -sql create table ct4 using stb tags(4000); -sql insert into ct4 select * from ct1; -sql select * from ct4; -sql insert into ct4 select ts,c1,c2,c3 from stb; - -sql create table tb1 (ts timestamp, c1 int, c2 float, c3 double); -sql insert into tb1 (ts, c1, c2, c3) select * from ct1; -sql select * from tb1; - -sql create table tb2 (ts timestamp, f1 binary(10), c1 int, c2 double); -sql insert into tb2 (c2, c1, ts) select c2+1, c1, ts+3 from ct2; -sql select * from tb2; +sql select * from db.stb where tbname = 'ctb2'; _OVER: system sh/exec.sh -n dnode1 -s stop -x SIGINT @@ -90,7 +111,7 @@ $null= system_content sh/checkValgrind.sh -n dnode1 print cmd return result ----> [ $system_content ] -if $system_content > 1 then +if $system_content > 0 then return -1 endi diff --git a/tests/script/tsim/valgrind/basic3.sim b/tests/script/tsim/valgrind/basic3.sim index 6a42a8eb7f..d513eee3cf 100644 --- a/tests/script/tsim/valgrind/basic3.sim +++ b/tests/script/tsim/valgrind/basic3.sim @@ -1,6 +1,5 @@ system sh/stop_dnodes.sh system sh/deploy.sh -n dnode1 -i 1 -system sh/cfg.sh -n dnode1 -c debugflag -v 131 system sh/exec.sh -n dnode1 -s start -v sql connect @@ -22,40 +21,43 @@ if $data(1)[4] != ready then goto step1 endi -print =============== step2: create db -sql create database d1 vgroups 2 buffer 3 -sql show databases -sql use d1 -sql show vgroups +$tbPrefix = tb +$tbNum = 5 +$rowNum = 10 -print =============== step3: create show stable -sql create table if not exists stb (ts timestamp, c1 int, c2 float, c3 double) tags (t1 int unsigned) -sql show stables -if $rows != 1 then - return -1 -endi +print =============== step2: prepare data +sql create database db vgroups 2 +sql use db +sql create table if not exists stb (ts timestamp, tbcol int, tbcol2 float, tbcol3 double) tags (tgcol int unsigned) -print =============== step4: create show table -sql create table ct1 using stb tags(1000) -sql create table ct2 using stb tags(2000) -sql create table ct3 using stb tags(3000) -sql show tables -if $rows != 3 then - return -1 -endi +$i = 0 +while $i < $tbNum + $tb = $tbPrefix . $i + sql create table $tb using stb tags( $i ) + $x = 0 + while $x < $rowNum + $cc = $x * 60000 + $ms = 1601481600000 + $cc + sql insert into $tb values ($ms , $x , $x , $x ) + $x = $x + 1 + endw + $i = $i + 1 +endw -print =============== step5: insert data -sql insert into ct1 values(now+0d, 10, 2.0, 3.0) -sql insert into ct1 values(now+1d, 11, 2.1, 3.1)(now+2d, -12, -2.2, -3.2)(now+3d, -13, -2.3, -3.3) -sql insert into ct2 values(now+0d, 10, 2.0, 3.0) -sql insert into ct2 values(now+1d, 11, 2.1, 3.1)(now+2d, -12, -2.2, -3.2)(now+3d, -13, -2.3, -3.3) -sql insert into ct3 values('2022-01-01 00:00:00.000', 10, 2.0, 3.0) - -print =============== step6: query data -sql select * from ct1 where ts < now -1d and ts > now +1d -sql select * from stb where ts < now -1d and ts > now +1d -sql select * from ct1 where ts < now -1d and ts > now +1d order by ts desc -sql select * from stb where ts < now -1d and ts > now +1d order by ts desc +print =============== step3: avg +sql select avg(tbcol) from tb1 +sql select avg(tbcol) from tb1 where ts <= 1601481840000 +sql select avg(tbcol) as b from tb1 +sql select avg(tbcol) as b from tb1 interval(1d) +sql select avg(tbcol) as b from tb1 where ts <= 1601481840000s interval(1m) +sql select avg(tbcol) as c from stb +sql select avg(tbcol) as c from stb where ts <= 1601481840000 +sql select avg(tbcol) as c from stb where tgcol < 5 and ts <= 1601481840000 +sql select avg(tbcol) as c from stb interval(1m) +sql select avg(tbcol) as c from stb interval(1d) +sql select avg(tbcol) as b from stb where ts <= 1601481840000s interval(1m) +sql select avg(tbcol) as c from stb group by tgcol +sql select avg(tbcol) as b from stb where ts <= 1601481840000s partition by tgcol interval(1m) _OVER: system sh/exec.sh -n dnode1 -s stop -x SIGINT @@ -64,7 +66,7 @@ $null= system_content sh/checkValgrind.sh -n dnode1 print cmd return result ----> [ $system_content ] -if $system_content > 1 then +if $system_content > 0 then return -1 endi From c8f5ba85372188071fd8e13726e23ba3f28d98e6 Mon Sep 17 00:00:00 2001 From: jiacy-jcy Date: Wed, 20 Jul 2022 11:27:32 +0800 Subject: [PATCH 11/45] update delete.py --- tests/system-test/1-insert/delete_data.py | 136 +++++++++++++++------- 1 file changed, 95 insertions(+), 41 deletions(-) diff --git a/tests/system-test/1-insert/delete_data.py b/tests/system-test/1-insert/delete_data.py index 27153185b9..4c1426d0b1 100644 --- a/tests/system-test/1-insert/delete_data.py +++ b/tests/system-test/1-insert/delete_data.py @@ -30,8 +30,8 @@ class TDTestCase: self.setsql = TDSetSql() self.stbname = 'stb' self.ntbname = 'ntb' - self.rowNum = 10 - self.tbnum = 20 + self.rowNum = 5 + self.tbnum = 2 self.ts = 1537146000000 self.binary_str = 'taosdata' self.nchar_str = '涛思数据' @@ -109,32 +109,50 @@ class TDTestCase: tdSql.execute(f'''insert into {tbname} values({self.ts+i},"{base_data['binary']}")''') elif 'nchar' in col_type.lower(): tdSql.execute(f'''insert into {tbname} values({self.ts+i},"{base_data['nchar']}")''') - - def delete_all_data(self,tbname,col_type,row_num,base_data,dbname): + def delete_all_data(self,tbname,col_type,row_num,base_data,dbname,tb_type,tb_num=1): tdSql.execute(f'delete from {tbname}') tdSql.execute(f'flush database {dbname}') tdSql.execute('reset query cache') tdSql.query(f'select * from {tbname}') tdSql.checkRows(0) - self.insert_base_data(col_type,tbname,row_num,base_data) + if tb_type == 'ntb' or tb_type == 'ctb': + self.insert_base_data(col_type,tbname,row_num,base_data) + elif tb_type == 'stb': + for i in range(tb_num): + self.insert_base_data(col_type,f'{tbname}_{i}',row_num,base_data) tdSql.execute(f'flush database {dbname}') tdSql.execute('reset query cache') tdSql.query(f'select * from {tbname}') - tdSql.checkRows(row_num) - def delete_one_row(self,tbname,column_type,column_name,base_data,dbname): + if tb_type == 'ntb' or tb_type == 'ctb': + tdSql.checkRows(row_num) + elif tb_type =='stb': + tdSql.checkRows(row_num*tb_num) + def delete_one_row(self,tbname,column_type,column_name,base_data,row_num,dbname,tb_type,tb_num=1): tdSql.execute(f'delete from {tbname} where ts={self.ts}') tdSql.execute(f'flush database {dbname}') tdSql.execute('reset query cache') tdSql.query(f'select {column_name} from {tbname}') - tdSql.checkRows(self.rowNum-1) + if tb_type == 'ntb' or tb_type == 'ctb': + tdSql.checkRows(row_num-1) + elif tb_type == 'stb': + tdSql.checkRows((row_num-1)*tb_num) tdSql.query(f'select {column_name} from {tbname} where ts={self.ts}') tdSql.checkRows(0) - if 'binary' in column_type.lower(): - tdSql.execute(f'''insert into {tbname} values({self.ts},"{base_data['binary']}")''') - elif 'nchar' in column_type.lower(): - tdSql.execute(f'''insert into {tbname} values({self.ts},"{base_data['nchar']}")''') - else: - tdSql.execute(f'insert into {tbname} values({self.ts},{base_data[column_type]})') + if tb_type == 'ntb' or tb_type == 'ctb': + if 'binary' in column_type.lower(): + tdSql.execute(f'''insert into {tbname} values({self.ts},"{base_data['binary']}")''') + elif 'nchar' in column_type.lower(): + tdSql.execute(f'''insert into {tbname} values({self.ts},"{base_data['nchar']}")''') + else: + tdSql.execute(f'insert into {tbname} values({self.ts},{base_data[column_type]})') + elif tb_type == 'stb': + for i in range(tb_num): + if 'binary' in column_type.lower(): + tdSql.execute(f'''insert into {tbname}_{i} values({self.ts},"{base_data['binary']}")''') + elif 'nchar' in column_type.lower(): + tdSql.execute(f'''insert into {tbname}_{i} values({self.ts},"{base_data['nchar']}")''') + else: + tdSql.execute(f'insert into {tbname}_{i} values({self.ts},{base_data[column_type]})') tdSql.query(f'select {column_name} from {tbname} where ts={self.ts}') if column_type.lower() == 'float' or column_type.lower() == 'double': if abs(tdSql.queryResult[0][0] - base_data[column_type]) / base_data[column_type] <= 0.0001: @@ -146,38 +164,56 @@ class TDTestCase: elif 'nchar' in column_type.lower(): tdSql.checkEqual(tdSql.queryResult[0][0],base_data['nchar']) else: - tdSql.checkEqual(tdSql.queryResult[0][0],base_data[column_type]) - - def delete_rows(self,dbname,tbname,col_name,col_type,base_data,rowNum): - for i in range(rowNum): + tdSql.checkEqual(tdSql.queryResult[0][0],base_data[column_type]) + def delete_rows(self,dbname,tbname,col_name,col_type,base_data,row_num,tb_type,tb_num=1): + for i in range(row_num): tdSql.execute(f'delete from {tbname} where ts>{self.ts+i}') tdSql.execute(f'flush database {dbname}') tdSql.execute('reset query cache') tdSql.query(f'select {col_name} from {tbname}') - tdSql.checkRows(i+1) - self.insert_base_data(col_type,tbname,rowNum,base_data) - for i in range(rowNum): + if tb_type == 'ntb' or tb_type == 'ctb': + tdSql.checkRows(i+1) + self.insert_base_data(col_type,tbname,row_num,base_data) + elif tb_type == 'stb': + tdSql.checkRows((i+1)*tb_num) + for j in range(tb_num): + self.insert_base_data(col_type,f'{tbname}_{j}',row_num,base_data) + for i in range(row_num): tdSql.execute(f'delete from {tbname} where ts>={self.ts+i}') tdSql.execute(f'flush database {dbname}') tdSql.execute('reset query cache') tdSql.query(f'select {col_name} from {tbname}') - tdSql.checkRows(i) - self.insert_base_data(col_type,tbname,rowNum,base_data) - for i in range(rowNum): + if tb_type == 'ntb' or tb_type == 'ctb': + tdSql.checkRows(i) + self.insert_base_data(col_type,tbname,row_num,base_data) + elif tb_type == 'stb': + tdSql.checkRows(i*tb_num) + for j in range(tb_num): + self.insert_base_data(col_type,f'{tbname}_{j}',row_num,base_data) + for i in range(row_num): tdSql.execute(f'delete from {tbname} where ts<={self.ts+i}') tdSql.execute(f'flush database {dbname}') tdSql.execute('reset query cache') tdSql.query(f'select {col_name} from {tbname}') - tdSql.checkRows(rowNum-i-1) - self.insert_base_data(col_type,tbname,rowNum,base_data) - for i in range(rowNum): + if tb_type == 'ntb' or tb_type == 'ctb': + tdSql.checkRows(row_num-i-1) + self.insert_base_data(col_type,tbname,row_num,base_data) + elif tb_type == 'stb': + tdSql.checkRows((row_num-i-1)*tb_num) + for j in range(tb_num): + self.insert_base_data(col_type,f'{tbname}_{j}',row_num,base_data) + for i in range(row_num): tdSql.execute(f'delete from {tbname} where ts<{self.ts+i}') tdSql.execute(f'flush database {dbname}') tdSql.execute('reset query cache') tdSql.query(f'select {col_name} from {tbname}') - tdSql.checkRows(rowNum-i) - self.insert_base_data(col_type,tbname,rowNum,base_data) - + if tb_type == 'ntb' or tb_type == 'ctb': + tdSql.checkRows(row_num-i) + self.insert_base_data(col_type,tbname,row_num,base_data) + elif tb_type == 'stb': + tdSql.checkRows((row_num-i)*tb_num) + for j in range(tb_num): + self.insert_base_data(col_type,f'{tbname}_{j}',row_num,base_data) def delete_error(self,tbname,column_name,column_type,base_data): for error_list in ['',f'ts = {self.ts} and',f'ts = {self.ts} or']: if 'binary' in column_type.lower(): @@ -185,18 +221,19 @@ class TDTestCase: elif 'nchar' in column_type.lower(): tdSql.error(f'''delete from {tbname} where {error_list} {column_name} ="{base_data['nchar']}"''') else: - tdSql.error(f'delete from {tbname} where {error_list} {column_name} = {base_data[column_type]}') - + tdSql.error(f'delete from {tbname} where {error_list} {column_name} = {base_data[column_type]}') def delete_data_ntb(self): tdSql.execute(f'create database if not exists {self.dbname}') tdSql.execute(f'use {self.dbname}') for col_name,col_type in self.column_dict.items(): tdSql.execute(f'create table {self.ntbname} (ts timestamp,{col_name} {col_type})') self.insert_base_data(col_type,self.ntbname,self.rowNum,self.base_data) - self.delete_one_row(self.ntbname,col_type,col_name,self.base_data,self.dbname) - self.delete_all_data(self.ntbname,col_type,self.rowNum,self.base_data,self.dbname) + self.delete_one_row(self.ntbname,col_type,col_name,self.base_data,self.rowNum,self.dbname,'ntb') + self.delete_all_data(self.ntbname,col_type,self.rowNum,self.base_data,self.dbname,'ntb') self.delete_error(self.ntbname,col_name,col_type,self.base_data) - self.delete_rows(self.dbname,self.ntbname,col_name,col_type,self.base_data,self.rowNum) + self.delete_rows(self.dbname,self.ntbname,col_name,col_type,self.base_data,self.rowNum,'ntb') + for func in ['first','last']: + tdSql.query(f'select {func}(*) from {self.ntbname}') tdSql.execute(f'drop table {self.ntbname}') tdSql.execute(f'drop database {self.dbname}') def delete_data_ctb(self): @@ -207,16 +244,33 @@ class TDTestCase: for i in range(self.tbnum): tdSql.execute(f'create table {self.stbname}_{i} using {self.stbname} tags(1)') self.insert_base_data(col_type,f'{self.stbname}_{i}',self.rowNum,self.base_data) - self.delete_one_row(f'{self.stbname}_{i}',col_type,col_name,self.base_data,self.dbname) - self.delete_all_data(f'{self.stbname}_{i}',col_type,self.rowNum,self.base_data,self.dbname) + self.delete_one_row(f'{self.stbname}_{i}',col_type,col_name,self.base_data,self.rowNum,self.dbname,'ctb') + self.delete_all_data(f'{self.stbname}_{i}',col_type,self.rowNum,self.base_data,self.dbname,'ctb') self.delete_error(f'{self.stbname}_{i}',col_name,col_type,self.base_data) - self.delete_rows(self.dbname,f'{self.stbname}_{i}',col_name,col_type,self.base_data,self.rowNum) + self.delete_rows(self.dbname,f'{self.stbname}_{i}',col_name,col_type,self.base_data,self.rowNum,'ctb') + for func in ['first','last']: + tdSql.query(f'select {func}(*) from {self.stbname}_{i}') tdSql.execute(f'drop table {self.stbname}') - + def delete_data_stb(self): + tdSql.execute(f'create database if not exists {self.dbname}') + tdSql.execute(f'use {self.dbname}') + for col_name,col_type in self.column_dict.items(): + tdSql.execute(f'create table {self.stbname} (ts timestamp,{col_name} {col_type}) tags(t1 int)') + for i in range(self.tbnum): + tdSql.execute(f'create table {self.stbname}_{i} using {self.stbname} tags(1)') + self.insert_base_data(col_type,f'{self.stbname}_{i}',self.rowNum,self.base_data) + self.delete_error(self.stbname,col_name,col_type,self.base_data) + self.delete_one_row(self.stbname,col_type,col_name,self.base_data,self.rowNum,self.dbname,'stb',self.tbnum) + self.delete_all_data(self.stbname,col_type,self.rowNum,self.base_data,self.dbname,'stb',self.tbnum) + self.delete_rows(self.dbname,self.stbname,col_name,col_type,self.base_data,self.rowNum,'stb',self.tbnum) + for func in ['first','last']: + tdSql.query(f'select {func}(*) from {self.stbname}') + tdSql.execute(f'drop table {self.stbname}') + tdSql.execute(f'drop database {self.dbname}') def run(self): self.delete_data_ntb() - # self.delete_data_ctb() - + self.delete_data_ctb() + self.delete_data_stb() def stop(self): tdSql.close() tdLog.success("%s successfully executed" % __file__) From 994089b53e6aca6f8cd628ee65613d2101fe00ba Mon Sep 17 00:00:00 2001 From: jiacy-jcy Date: Wed, 20 Jul 2022 11:28:26 +0800 Subject: [PATCH 12/45] add case into ci --- tests/system-test/fulltest.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/system-test/fulltest.sh b/tests/system-test/fulltest.sh index 19658c3a0a..189c2da931 100755 --- a/tests/system-test/fulltest.sh +++ b/tests/system-test/fulltest.sh @@ -33,7 +33,7 @@ python3 ./test.py -f 1-insert/create_retentions.py python3 ./test.py -f 1-insert/table_param_ttl.py python3 ./test.py -f 1-insert/update_data.py - +python3 ./test.py -f 1-insert/delete_data.py python3 ./test.py -f 2-query/db.py python3 ./test.py -f 2-query/between.py From 503e89f00d7d79ba9ee6ef3c42dc08c6927bcdd9 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Wed, 20 Jul 2022 11:31:03 +0800 Subject: [PATCH 13/45] fix: avoid rpc mem leak --- source/libs/transport/src/transCli.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index fb0598d247..56268b03ef 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -198,6 +198,7 @@ static void cliReleaseUnfinishedMsg(SCliConn* conn) { } \ destroyCmsg(pMsg); \ cliReleaseUnfinishedMsg(conn); \ + transQueueClear(&conn->cliMsgs); \ addConnToPool(((SCliThrd*)conn->hostThrd)->pool, conn); \ return; \ } \ @@ -545,6 +546,7 @@ static void addConnToPool(void* pool, SCliConn* conn) { STrans* pTransInst = thrd->pTransInst; conn->expireTime = taosGetTimestampMs() + CONN_PERSIST_TIME(pTransInst->idleTime); + cliReleaseUnfinishedMsg(conn); transQueueClear(&conn->cliMsgs); transCtxCleanup(&conn->ctx); conn->status = ConnInPool; @@ -645,6 +647,7 @@ static void cliDestroy(uv_handle_t* handle) { conn->stream->data = NULL; taosMemoryFree(conn->stream); transCtxCleanup(&conn->ctx); + cliReleaseUnfinishedMsg(conn); transQueueDestroy(&conn->cliMsgs); tTrace("%s conn %p destroy successfully", CONN_GET_INST_LABEL(conn), conn); transReqQueueClear(&conn->wreqQueue); From b4537bc41e3f1b5fc9fe29687c5218dd454cc02c Mon Sep 17 00:00:00 2001 From: afwerar <1296468573@qq.com> Date: Wed, 20 Jul 2022 11:31:35 +0800 Subject: [PATCH 14/45] shell: change shell print text --- tools/shell/src/shellEngine.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/shell/src/shellEngine.c b/tools/shell/src/shellEngine.c index a496cc2864..a0adb7c7bc 100644 --- a/tools/shell/src/shellEngine.c +++ b/tools/shell/src/shellEngine.c @@ -197,7 +197,7 @@ void shellRunSingleCommandImp(char *command) { et = taosGetTimestampUs(); if (error_no == 0) { - printf("Query OK, %d rows affected (%.6fs)\r\n", numOfRows, (et - st) / 1E6); + printf("Query OK, %d rows in database (%.6fs)\r\n", numOfRows, (et - st) / 1E6); } else { printf("Query interrupted (%s), %d rows affected (%.6fs)\r\n", taos_errstr(pSql), numOfRows, (et - st) / 1E6); } From 3fba8182a5ab831980b4ddddb8b755ae78e63666 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Wed, 20 Jul 2022 13:02:33 +0800 Subject: [PATCH 15/45] fix(query): fix time window generating bug. --- source/common/src/ttime.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/source/common/src/ttime.c b/source/common/src/ttime.c index 944ee6a731..9b044d6e93 100644 --- a/source/common/src/ttime.c +++ b/source/common/src/ttime.c @@ -844,11 +844,14 @@ int64_t taosTimeTruncate(int64_t t, const SInterval* pInterval, int32_t precisio } else { // try to move current window to the left-hande-side, due to the offset effect. int64_t end = taosTimeAdd(start, pInterval->interval, pInterval->intervalUnit, precision) - 1; - ASSERT(end >= t); - end = taosTimeAdd(end, -pInterval->sliding, pInterval->slidingUnit, precision); - if (end >= t) { - start = taosTimeAdd(start, -pInterval->sliding, pInterval->slidingUnit, precision); + + int64_t newEnd = end; + while(newEnd >= t) { + end = newEnd; + newEnd = taosTimeAdd(newEnd, -pInterval->sliding, pInterval->slidingUnit, precision); } + + start = taosTimeAdd(end, -pInterval->interval + 1, pInterval->intervalUnit, precision); } } From b65d55daac7cb8fc4989cbdeb5a029c3c8b2ade0 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Wed, 20 Jul 2022 13:10:29 +0800 Subject: [PATCH 16/45] test: valgrind case --- tests/script/tsim/valgrind/checkError3.sim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/script/tsim/valgrind/checkError3.sim b/tests/script/tsim/valgrind/checkError3.sim index 52ef01785e..e8b25098d6 100644 --- a/tests/script/tsim/valgrind/checkError3.sim +++ b/tests/script/tsim/valgrind/checkError3.sim @@ -90,7 +90,7 @@ $null= system_content sh/checkValgrind.sh -n dnode1 print cmd return result ----> [ $system_content ] -if $system_content > 0 then +if $system_content > 2 then return -1 endi From 26c6db230ea9613bd7431dac7b74e481dc44b54d Mon Sep 17 00:00:00 2001 From: Ganlin Zhao Date: Wed, 20 Jul 2022 13:22:49 +0800 Subject: [PATCH 17/45] fix(query): twa function handling null constant or all null column TD-17562 --- source/libs/function/src/builtinsimpl.c | 67 +++++++++++++++++++------ 1 file changed, 51 insertions(+), 16 deletions(-) diff --git a/source/libs/function/src/builtinsimpl.c b/source/libs/function/src/builtinsimpl.c index 9534b2c7b3..dfc5b6a363 100644 --- a/source/libs/function/src/builtinsimpl.c +++ b/source/libs/function/src/builtinsimpl.c @@ -165,6 +165,7 @@ typedef struct SElapsedInfo { typedef struct STwaInfo { double dOutput; + bool isNull; SPoint1 p; STimeWindow win; } STwaInfo; @@ -5181,8 +5182,9 @@ bool twaFunctionSetup(SqlFunctionCtx* pCtx, SResultRowEntryInfo* pResultInfo) { } STwaInfo* pInfo = GET_ROWCELL_INTERBUF(GET_RES_INFO(pCtx)); - pInfo->p.key = INT64_MIN; - pInfo->win = TSWINDOW_INITIALIZER; + pInfo->isNull = false; + pInfo->p.key = INT64_MIN; + pInfo->win = TSWINDOW_INITIALIZER; return true; } @@ -5214,21 +5216,36 @@ int32_t twaFunction(SqlFunctionCtx* pCtx) { (pCtx->start.key > tsList[i] && pCtx->order == TSDB_ORDER_DESC)); ASSERT(last->key == INT64_MIN); - last->key = tsList[i]; + for (; i < pInput->numOfRows + pInput->startRowIndex; ++i) { + if (colDataIsNull_f(pInputCol->nullbitmap, i)) { + continue; + } - GET_TYPED_DATA(last->val, double, pInputCol->info.type, colDataGetData(pInputCol, i)); + last->key = tsList[i]; - pInfo->dOutput += twa_get_area(pCtx->start, *last); - pInfo->win.skey = pCtx->start.key; - numOfElems++; - i += 1; + GET_TYPED_DATA(last->val, double, pInputCol->info.type, colDataGetData(pInputCol, i)); + + pInfo->dOutput += twa_get_area(pCtx->start, *last); + pInfo->win.skey = pCtx->start.key; + numOfElems++; + i += 1; + break; + } } else if (pInfo->p.key == INT64_MIN) { - last->key = tsList[i]; - GET_TYPED_DATA(last->val, double, pInputCol->info.type, colDataGetData(pInputCol, i)); + for (; i < pInput->numOfRows + pInput->startRowIndex; ++i) { + if (colDataIsNull_f(pInputCol->nullbitmap, i)) { + continue; + } - pInfo->win.skey = last->key; - numOfElems++; - i += 1; + last->key = tsList[i]; + + GET_TYPED_DATA(last->val, double, pInputCol->info.type, colDataGetData(pInputCol, i)); + + pInfo->win.skey = last->key; + numOfElems++; + i += 1; + break; + } } SPoint1 st = {0}; @@ -5241,6 +5258,7 @@ int32_t twaFunction(SqlFunctionCtx* pCtx) { if (colDataIsNull_f(pInputCol->nullbitmap, i)) { continue; } + numOfElems++; INIT_INTP_POINT(st, tsList[i], val[i]); pInfo->dOutput += twa_get_area(pInfo->p, st); @@ -5255,6 +5273,7 @@ int32_t twaFunction(SqlFunctionCtx* pCtx) { if (colDataIsNull_f(pInputCol->nullbitmap, i)) { continue; } + numOfElems++; INIT_INTP_POINT(st, tsList[i], val[i]); pInfo->dOutput += twa_get_area(pInfo->p, st); @@ -5268,6 +5287,7 @@ int32_t twaFunction(SqlFunctionCtx* pCtx) { if (colDataIsNull_f(pInputCol->nullbitmap, i)) { continue; } + numOfElems++; INIT_INTP_POINT(st, tsList[i], val[i]); pInfo->dOutput += twa_get_area(pInfo->p, st); @@ -5281,6 +5301,7 @@ int32_t twaFunction(SqlFunctionCtx* pCtx) { if (colDataIsNull_f(pInputCol->nullbitmap, i)) { continue; } + numOfElems++; INIT_INTP_POINT(st, tsList[i], val[i]); pInfo->dOutput += twa_get_area(pInfo->p, st); @@ -5294,6 +5315,7 @@ int32_t twaFunction(SqlFunctionCtx* pCtx) { if (colDataIsNull_f(pInputCol->nullbitmap, i)) { continue; } + numOfElems++; INIT_INTP_POINT(st, tsList[i], val[i]); pInfo->dOutput += twa_get_area(pInfo->p, st); @@ -5307,6 +5329,7 @@ int32_t twaFunction(SqlFunctionCtx* pCtx) { if (colDataIsNull_f(pInputCol->nullbitmap, i)) { continue; } + numOfElems++; INIT_INTP_POINT(st, tsList[i], val[i]); pInfo->dOutput += twa_get_area(pInfo->p, st); @@ -5320,6 +5343,7 @@ int32_t twaFunction(SqlFunctionCtx* pCtx) { if (colDataIsNull_f(pInputCol->nullbitmap, i)) { continue; } + numOfElems++; INIT_INTP_POINT(st, tsList[i], val[i]); pInfo->dOutput += twa_get_area(pInfo->p, st); @@ -5333,6 +5357,7 @@ int32_t twaFunction(SqlFunctionCtx* pCtx) { if (colDataIsNull_f(pInputCol->nullbitmap, i)) { continue; } + numOfElems++; INIT_INTP_POINT(st, tsList[i], val[i]); pInfo->dOutput += twa_get_area(pInfo->p, st); @@ -5346,6 +5371,7 @@ int32_t twaFunction(SqlFunctionCtx* pCtx) { if (colDataIsNull_f(pInputCol->nullbitmap, i)) { continue; } + numOfElems++; INIT_INTP_POINT(st, tsList[i], val[i]); pInfo->dOutput += twa_get_area(pInfo->p, st); @@ -5359,6 +5385,7 @@ int32_t twaFunction(SqlFunctionCtx* pCtx) { if (colDataIsNull_f(pInputCol->nullbitmap, i)) { continue; } + numOfElems++; INIT_INTP_POINT(st, tsList[i], val[i]); pInfo->dOutput += twa_get_area(pInfo->p, st); @@ -5366,6 +5393,10 @@ int32_t twaFunction(SqlFunctionCtx* pCtx) { } break; } + case TSDB_DATA_TYPE_NULL: { + pInfo->isNull = true; + break; + } default: ASSERT(0); @@ -5379,7 +5410,11 @@ int32_t twaFunction(SqlFunctionCtx* pCtx) { pInfo->win.ekey = pInfo->p.key; - SET_VAL(pResInfo, numOfElems, 1); + if (numOfElems == 0) { + pInfo->isNull = true; + } + + SET_VAL(pResInfo, 1, 1); return TSDB_CODE_SUCCESS; } @@ -5400,8 +5435,8 @@ int32_t twaFinalize(struct SqlFunctionCtx* pCtx, SSDataBlock* pBlock) { SResultRowEntryInfo* pResInfo = GET_RES_INFO(pCtx); STwaInfo* pInfo = (STwaInfo*)GET_ROWCELL_INTERBUF(pResInfo); - if (pResInfo->numOfRes == 0) { - pResInfo->isNullRes = 1; + if (pInfo->isNull == true) { + pResInfo->numOfRes = 0; } else { if (pInfo->win.ekey == pInfo->win.skey) { pInfo->dOutput = pInfo->p.val; From 9fa47f7e676ed1662310949e9a437a7d0896745d Mon Sep 17 00:00:00 2001 From: Ganlin Zhao Date: Wed, 20 Jul 2022 13:22:49 +0800 Subject: [PATCH 18/45] fix(query): twa function handling null constant or all null column TD-17562 --- source/libs/function/src/builtinsimpl.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/source/libs/function/src/builtinsimpl.c b/source/libs/function/src/builtinsimpl.c index dfc5b6a363..7a76e1136e 100644 --- a/source/libs/function/src/builtinsimpl.c +++ b/source/libs/function/src/builtinsimpl.c @@ -5210,6 +5210,11 @@ int32_t twaFunction(SqlFunctionCtx* pCtx) { SPoint1* last = &pInfo->p; int32_t numOfElems = 0; + if (IS_NULL_TYPE(pInputCol->info.type)) { + pInfo->isNull = true; + goto _twa_over; + } + int32_t i = pInput->startRowIndex; if (pCtx->start.key != INT64_MIN) { ASSERT((pCtx->start.key < tsList[i] && pCtx->order == TSDB_ORDER_ASC) || @@ -5393,10 +5398,6 @@ int32_t twaFunction(SqlFunctionCtx* pCtx) { } break; } - case TSDB_DATA_TYPE_NULL: { - pInfo->isNull = true; - break; - } default: ASSERT(0); @@ -5410,6 +5411,7 @@ int32_t twaFunction(SqlFunctionCtx* pCtx) { pInfo->win.ekey = pInfo->p.key; +_twa_over: if (numOfElems == 0) { pInfo->isNull = true; } From be56f8b1216fa1f86cde17e196ed9cf846587173 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Wed, 20 Jul 2022 13:36:49 +0800 Subject: [PATCH 19/45] test: restore 2.0 case --- tests/script/jenkins/basic.txt | 6 +- tests/script/tsim/db/commit.sim | 50 ++++++----- tests/script/tsim/db/keep.sim | 141 ++++++++------------------------ 3 files changed, 63 insertions(+), 134 deletions(-) diff --git a/tests/script/jenkins/basic.txt b/tests/script/jenkins/basic.txt index 90353ef114..98c5251ac5 100644 --- a/tests/script/jenkins/basic.txt +++ b/tests/script/jenkins/basic.txt @@ -17,7 +17,7 @@ ./test.sh -f tsim/db/basic4.sim ./test.sh -f tsim/db/basic5.sim ./test.sh -f tsim/db/basic6.sim -# nojira ./test.sh -f tsim/db/commit.sim +./test.sh -f tsim/db/commit.sim ./test.sh -f tsim/db/create_all_options.sim ./test.sh -f tsim/db/delete_reuse1.sim ./test.sh -f tsim/db/delete_reuse2.sim @@ -27,7 +27,7 @@ ./test.sh -f tsim/db/delete_writing2.sim # unsupport ./test.sh -f tsim/db/dropdnodes.sim ./test.sh -f tsim/db/error1.sim -# nojira ./test.sh -f tsim/db/keep.sim +# jira ./test.sh -f tsim/db/keep.sim ./test.sh -f tsim/db/len.sim ./test.sh -f tsim/db/repeat.sim ./test.sh -f tsim/db/show_create_db.sim @@ -88,7 +88,7 @@ ./test.sh -f tsim/parser/alter__for_community_version.sim ./test.sh -f tsim/parser/alter_column.sim ./test.sh -f tsim/parser/alter_stable.sim -# nojira ./test.sh -f tsim/parser/auto_create_tb.sim +# jira ./test.sh -f tsim/parser/auto_create_tb.sim ./test.sh -f tsim/parser/auto_create_tb_drop_tb.sim ./test.sh -f tsim/parser/between_and.sim ./test.sh -f tsim/parser/binary_escapeCharacter.sim diff --git a/tests/script/tsim/db/commit.sim b/tests/script/tsim/db/commit.sim index 74c1366afb..191f618adb 100644 --- a/tests/script/tsim/db/commit.sim +++ b/tests/script/tsim/db/commit.sim @@ -1,27 +1,35 @@ system sh/stop_dnodes.sh system sh/deploy.sh -n dnode1 -i 1 system sh/deploy.sh -n dnode2 -i 2 -system sh/deploy.sh -n dnode3 -i 3 - -system sh/cfg.sh -n dnode1 -c walLevel -v 2 -system sh/cfg.sh -n dnode2 -c walLevel -v 2 -system sh/cfg.sh -n dnode3 -c walLevel -v 2 -system sh/cfg.sh -n dnode1 -c numOfMnodes -v 1 -system sh/cfg.sh -n dnode2 -c numOfMnodes -v 1 -system sh/cfg.sh -n dnode3 -c numOfMnodes -v 1 -system sh/cfg.sh -n dnode1 -c mnodeEqualVnodeNum -v 4 -system sh/cfg.sh -n dnode2 -c mnodeEqualVnodeNum -v 4 -system sh/cfg.sh -n dnode3 -c mnodeEqualVnodeNum -v 4 print ========= start dnode1 as master system sh/exec.sh -n dnode1 -s start +system sh/exec.sh -n dnode2 -s start sql connect -sleep 2000 print ========= start other dnodes -sql create dnode $hostname2 -system sh/exec.sh -n dnode2 -s start -sleep 2000 +sql create dnode $hostname port 7200 + +$x = 0 +step1: + $ = $x + 1 + sleep 1000 + if $x == 10 then + print ====> dnode not ready! + return -1 + endi +sql show dnodes +print ===> $data00 $data01 $data02 $data03 $data04 $data05 +print ===> $data10 $data11 $data12 $data13 $data14 $data15 +if $rows != 2 then + return -1 +endi +if $data(1)[4] != ready then + goto step1 +endi +if $data(2)[4] != ready then + goto step1 +endi print ======== step1 create db sql create database commitdb replica 1 duration 7 keep 30 @@ -68,9 +76,7 @@ $num = $rows + 2 print ======== step3 import old data sql import into tb values (now - 10d , -10 ) - sql import into tb values (now - 11d , -11 ) - sql select * from tb order by ts desc print ===> rows $rows expect $num print ===> last $data01 expect $data01 @@ -99,9 +105,7 @@ endi print ======== step5 stop dnode system sh/exec.sh -n dnode2 -s stop -x SIGINT -sleep 3000 system sh/exec.sh -n dnode2 -s start -sleep 3000 sql select * from tb print ===> rows $rows @@ -116,10 +120,4 @@ if $data01 != 40 then endi system sh/exec.sh -n dnode1 -s stop -x SIGINT -system sh/exec.sh -n dnode2 -s stop -x SIGINT -system sh/exec.sh -n dnode3 -s stop -x SIGINT -system sh/exec.sh -n dnode4 -s stop -x SIGINT -system sh/exec.sh -n dnode5 -s stop -x SIGINT -system sh/exec.sh -n dnode6 -s stop -x SIGINT -system sh/exec.sh -n dnode7 -s stop -x SIGINT -system sh/exec.sh -n dnode8 -s stop -x SIGINT \ No newline at end of file +system sh/exec.sh -n dnode2 -s stop -x SIGINT \ No newline at end of file diff --git a/tests/script/tsim/db/keep.sim b/tests/script/tsim/db/keep.sim index 027530026c..d8939eafbc 100644 --- a/tests/script/tsim/db/keep.sim +++ b/tests/script/tsim/db/keep.sim @@ -1,57 +1,23 @@ system sh/stop_dnodes.sh system sh/deploy.sh -n dnode1 -i 1 -system sh/deploy.sh -n dnode2 -i 2 -system sh/deploy.sh -n dnode3 -i 3 -system sh/deploy.sh -n dnode4 -i 4 -system sh/cfg.sh -n dnode1 -c transPullupInterval -v 1 -system sh/cfg.sh -n dnode2 -c transPullupInterval -v 1 -system sh/cfg.sh -n dnode3 -c transPullupInterval -v 1 -system sh/cfg.sh -n dnode4 -c transPullupInterval -v 1 system sh/exec.sh -n dnode1 -s start -system sh/exec.sh -n dnode2 -s start sql connect -print =============== step1 create dnode2 -sql create dnode $hostname port 7200 - -$x = 0 -step1: - $x = $x + 1 - sleep 1000 - if $x == 10 then - print ====> dnode not ready! - return -1 - endi -sql show dnodes -print ===> $data00 $data01 $data02 $data03 $data04 $data05 -print ===> $data10 $data11 $data12 $data13 $data14 $data15 -if $rows != 2 then - return -1 -endi -if $data(1)[4] != ready then - goto step1 -endi -if $data(2)[4] != ready then - goto step1 -endi - print ======== step1 create db -sql create database keepdb replica 1 keep 30 duration 7 +sql create database keepdb replica 1 keep 30 duration 7 vgroups 2 sql use keepdb sql create table tb (ts timestamp, i int) $x = 1 while $x < 41 $time = $x . d - sql insert into tb values (now + $time , $x ) -x step2 + sql insert into tb values (now - $time , $x ) -x step2 step2: $x = $x + 1 endw sql select * from tb -print ===> rows $rows -print ===> last $data01 - +print ===> rows $rows last $data01 if $rows >= 40 then return -1 endi @@ -61,9 +27,7 @@ system sh/exec.sh -n dnode2 -s stop -x SIGINT system sh/exec.sh -n dnode2 -s start sql select * from tb -print ===> rows $rows -print ===> last $data01 - +print ===> rows $rows last $data01 if $rows >= 40 then return -1 endi @@ -75,23 +39,13 @@ $num1 = $rows + 40 print ======== step3 alter db sql alter database keepdb keep 60 -flush database keepdb - +sql flush database keepdb sql show databases print $data00 $data01 $data02 $data03 $data04 $data05 $data06 $data07 -if $data02 != 1 then +if $data22 != 2 then return -1 endi -if $data03 != 1 then - return -1 -endi -if $data04 != 1 then - return -1 -endi -if $data05 != 7 then - return -1 -endi -if $data06 != 60 then +if $data27 != 86400m,86400m,86400m then return -1 endi @@ -99,98 +53,73 @@ print ======== step4 insert data $x = 41 while $x < 81 $time = $x . d - sql insert into tb values (now + $time , $x ) + sql insert into tb values (now - $time , $x ) -x step4 + step4: $x = $x + 1 endw sql select * from tb -print ===> rows $rows -print ===> last $data01 - -if $rows != $num1 then - return -1 -endi -if $data01 != 80 then - return -1 -endi - -print ======== step5 stop dnode -system sh/exec.sh -n dnode2 -s stop -x SIGINT -system sh/exec.sh -n dnode2 -s start - -sql select * from tb -print ===> rows $rows -print ===> last $data01 - -if $rows >= $num1 then +print ===> rows $rows last $data01 +if $rows >= 80 then return -1 endi if $rows <= 50 then return -1 endi -if $data01 != 80 then + +return + +print ======== step5 stop dnode +system sh/exec.sh -n dnode2 -s stop -x SIGKILL +system sh/exec.sh -n dnode2 -s start + +sql select * from tb +print ===> rows $rows last $data01 +if $rows >= 80 then + return -1 +endi +if $rows <= 50 then return -1 endi print ======== step6 alter db sql alter database keepdb keep 30 -sleep 1000 sql show databases -print $data00 $data01 $data02 $data03 $data04 $data05 $data06 $data07 -if $data02 != 1 then +if $data22 != 2 then return -1 endi -if $data03 != 1 then - return -1 -endi -if $data04 != 1 then - return -1 -endi -if $data05 != 7 then - return -1 -endi -if $data06 != 30 then +if $data27 != 43200m,43200m,43200m then return -1 endi print ======== step7 stop dnode -system sh/exec.sh -n dnode2 -s stop -x SIGINT -sleep 2000 +system sh/exec.sh -n dnode2 -s stop -x SIGKILL system sh/exec.sh -n dnode2 -s start -sleep 2000 sql select * from tb -print ===> rows $rows -print ===> last $data01 - +print ===> rows $rows last $data01 if $rows >= 40 then return -1 endi if $rows <= 20 then return -1 endi -if $data01 != 80 then - return -1 -endi - -$num3 = $rows + 40 print ======== step8 insert data $x = 81 while $x < 121 $time = $x . d - sql insert into tb values (now + $time , $x ) + sql insert into tb values (now - $time , $x ) -x step4 + step4: $x = $x + 1 endw sql select * from tb -print ===> rows $rows -print ===> last $data01 - -if $rows != $num3 then +print ===> rows $rows last $data01 +if $rows >= 40 then return -1 endi -if $data01 != 120 then +if $rows <= 20 then return -1 endi @@ -208,4 +137,6 @@ sql alter database keepdb duration 1 -x error3 error3: print ======= test success - \ No newline at end of file + +system sh/exec.sh -n dnode1 -s stop -x SIGINT +system sh/exec.sh -n dnode2 -s stop -x SIGINT \ No newline at end of file From bb021697ee3e2db8bb9c20956f6ef13643b76043 Mon Sep 17 00:00:00 2001 From: Ganlin Zhao Date: Wed, 20 Jul 2022 14:04:07 +0800 Subject: [PATCH 20/45] fix max_partion.py test case --- tests/system-test/2-query/max_partition.py | 54 +++++++++++----------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/tests/system-test/2-query/max_partition.py b/tests/system-test/2-query/max_partition.py index 0a7214ec75..a352865c45 100644 --- a/tests/system-test/2-query/max_partition.py +++ b/tests/system-test/2-query/max_partition.py @@ -11,13 +11,13 @@ class TDTestCase: self.row_nums = 10 self.tb_nums = 10 self.ts = 1537146000000 - + def prepare_datas(self, stb_name , tb_nums , row_nums ): tdSql.execute(" use db ") tdSql.execute(f" create stable {stb_name} (ts timestamp , c1 int , c2 bigint , c3 float , c4 double , c5 smallint , c6 tinyint , c7 bool , c8 binary(36) , c9 nchar(36) , uc1 int unsigned,\ uc2 bigint unsigned ,uc3 smallint unsigned , uc4 tinyint unsigned ) tags(t1 timestamp , t2 int , t3 bigint , t4 float , t5 double , t6 smallint , t7 tinyint , t8 bool , t9 binary(36)\ , t10 nchar(36) , t11 int unsigned , t12 bigint unsigned ,t13 smallint unsigned , t14 tinyint unsigned ) ") - + for i in range(tb_nums): tbname = f"sub_{stb_name}_{i}" ts = self.ts + i*10000 @@ -30,7 +30,7 @@ class TDTestCase: for null in range(5): ts = self.ts + row_nums*1000 + null*1000 tdSql.execute(f"insert into {tbname} values({ts} , NULL , NULL , NULL , NULL , NULL , NULL , NULL , NULL , NULL , NULL , NULL , NULL , NULL )") - + def basic_query(self): tdSql.query("select count(*) from stb") tdSql.checkData(0,0,(self.row_nums + 5 )*self.tb_nums) @@ -44,7 +44,7 @@ class TDTestCase: tdSql.query(" select max(t2) from stb group by c1 order by t1 ") tdSql.query(" select max(c1) from stb group by tbname order by tbname ") tdSql.checkRows(self.tb_nums) - # bug need fix + # bug need fix tdSql.query(" select max(t2) from stb group by t2 order by t2 ") tdSql.checkRows(self.tb_nums) tdSql.query(" select max(c1) from stb group by c1 order by c1 ") @@ -62,8 +62,8 @@ class TDTestCase: # bug need fix # tdSql.query(" select tbname , max(c1) from sub_stb_1 where c1 is null group by c1 order by c1 desc ") - # tdSql.checkRows(1) - # tdSql.checkData(0,0,"sub_stb_1") + # tdSql.checkRows(1) + # tdSql.checkData(0,0,"sub_stb_1") tdSql.query("select max(c1) ,c2 ,t2,tbname from stb group by abs(c1) order by abs(c1)") tdSql.checkRows(self.row_nums+1) @@ -80,7 +80,7 @@ class TDTestCase: tdSql.checkRows(2) tdSql.query(" select max(c1) from stb where abs(c1+t2)=1 partition by tbname ") tdSql.checkRows(2) - + tdSql.query(" select tbname , max(c1) from stb partition by tbname order by tbname ") tdSql.checkRows(self.tb_nums) tdSql.checkData(0,1,self.row_nums-1) @@ -89,7 +89,7 @@ class TDTestCase: tdSql.query("select tbname , max(t2) from stb partition by t1 order by t1") tdSql.query("select tbname , max(t2) from stb partition by t2 order by t2") - # # bug need fix + # # bug need fix tdSql.query("select t2 , max(t2) from stb partition by t2 order by t2") tdSql.checkRows(self.tb_nums) @@ -97,7 +97,7 @@ class TDTestCase: tdSql.checkRows(self.tb_nums) tdSql.checkData(0,1,self.row_nums-1) - + tdSql.query("select tbname , max(c1) from stb partition by t2 order by t2") tdSql.query("select c2, max(c1) from stb partition by c2 order by c2 desc") @@ -125,10 +125,10 @@ class TDTestCase: tdSql.checkRows(self.tb_nums) tdSql.checkData(0,0,self.row_nums) - # bug need fix + # bug need fix tdSql.query("select count(c1) , max(t2) ,abs(c1) from stb partition by abs(c1) order by abs(c1)") tdSql.checkRows(self.row_nums+1) - + tdSql.query("select max(ceil(c2)) , max(floor(t2)) ,max(floor(c2)) from stb partition by abs(c2) order by abs(c2)") tdSql.checkRows(self.row_nums+1) @@ -148,15 +148,15 @@ class TDTestCase: tdSql.query(" select c1 , sample(c1,2) from stb partition by tbname order by tbname ") tdSql.checkRows(self.tb_nums*2) - - # interval + + # interval tdSql.query("select max(c1) from stb interval(2s) sliding(1s)") # bug need fix tdSql.query('select max(c1) from stb where ts>="2022-07-06 16:00:00.000 " and ts < "2022-07-06 17:00:00.000 " interval(50s) sliding(30s) fill(NULL)') - + tdSql.query(" select tbname , count(c1) from stb partition by tbname interval(10s) slimit 5 soffset 1 ") tdSql.query("select tbname , max(c1) from stb partition by tbname interval(10s)") @@ -179,12 +179,12 @@ class TDTestCase: tdSql.query("select c1 , sample(c1,2) from stb partition by c1 order by c1") tdSql.checkRows(21) - # bug need fix + # bug need fix # tdSql.checkData(0,1,None) tdSql.query("select c1 , twa(c1) from stb partition by c1 order by c1") tdSql.checkRows(11) - tdSql.checkData(0,1,0.000000000) + tdSql.checkData(0,1,None) tdSql.query("select c1 , irate(c1) from stb partition by c1 order by c1") tdSql.checkRows(11) @@ -192,7 +192,7 @@ class TDTestCase: tdSql.query("select c1 , DERIVATIVE(c1,2,1) from stb partition by c1 order by c1") tdSql.checkRows(72) - # bug need fix + # bug need fix # tdSql.checkData(0,1,None) @@ -201,15 +201,15 @@ class TDTestCase: - # bug need fix - # tdSql.query(" select tbname , max(c1) from stb partition by tbname order by tbname slimit 5 soffset 0 ") + # bug need fix + # tdSql.query(" select tbname , max(c1) from stb partition by tbname order by tbname slimit 5 soffset 0 ") # tdSql.checkRows(5) - + # tdSql.query(" select tbname , max(c1) from stb partition by tbname order by tbname slimit 5 soffset 1 ") - # tdSql.checkRows(5) - - tdSql.query(" select tbname , max(c1) from sub_stb_1 partition by tbname interval(10s) sliding(5s) ") - + # tdSql.checkRows(5) + + tdSql.query(" select tbname , max(c1) from sub_stb_1 partition by tbname interval(10s) sliding(5s) ") + tdSql.query(f'select max(c1) from stb where ts>={self.ts} and ts < {self.ts}+1000 interval(50s) sliding(30s)') tdSql.query(f'select tbname , max(c1) from stb where ts>={self.ts} and ts < {self.ts}+1000 interval(50s) sliding(30s)') @@ -219,18 +219,18 @@ class TDTestCase: self.prepare_datas("stb",self.tb_nums,self.row_nums) self.basic_query() - # # coverage case for taosd crash about bug fix + # # coverage case for taosd crash about bug fix tdSql.query(" select sum(c1) from stb where t2+10 >1 ") tdSql.query(" select count(c1),count(t1) from stb where -t2<1 ") tdSql.query(" select tbname ,max(ceil(c1)) from stb group by tbname ") tdSql.query(" select avg(abs(c1)) , tbname from stb group by tbname ") tdSql.query(" select t1,c1 from stb where abs(t2+c1)=1 ") - + def stop(self): tdSql.close() tdLog.success("%s successfully executed" % __file__) tdCases.addWindows(__file__, TDTestCase()) -tdCases.addLinux(__file__, TDTestCase()) \ No newline at end of file +tdCases.addLinux(__file__, TDTestCase()) From facf3c86489667465391bbc9d9ef68bf682fa45e Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Wed, 20 Jul 2022 14:07:48 +0800 Subject: [PATCH 21/45] fix(query): add limit/offset for order by operator. --- source/libs/executor/inc/executorimpl.h | 6 +- source/libs/executor/src/cachescanoperator.c | 2 +- source/libs/executor/src/executorimpl.c | 18 +++--- source/libs/executor/src/groupoperator.c | 2 +- source/libs/executor/src/joinoperator.c | 2 +- source/libs/executor/src/scanoperator.c | 6 +- source/libs/executor/src/sortoperator.c | 58 +++++++++++++------ source/libs/executor/src/timewindowoperator.c | 20 +++---- 8 files changed, 67 insertions(+), 47 deletions(-) diff --git a/source/libs/executor/inc/executorimpl.h b/source/libs/executor/inc/executorimpl.h index d7c283c70d..9142af4a6d 100644 --- a/source/libs/executor/inc/executorimpl.h +++ b/source/libs/executor/inc/executorimpl.h @@ -744,8 +744,8 @@ typedef struct SSortOperatorInfo { int64_t startTs; // sort start time uint64_t sortElapsed; // sort elapsed time, time to flush to disk not included. - - SNode* pCondition; + SLimitInfo limitInfo; + SNode* pCondition; } SSortOperatorInfo; typedef struct STagFilterOperatorInfo { @@ -785,7 +785,7 @@ int32_t initExprSupp(SExprSupp* pSup, SExprInfo* pExprInfo, int32_t numOfExpr); void cleanupExprSupp(SExprSupp* pSup); int32_t initAggInfo(SExprSupp *pSup, SAggSupporter* pAggSup, SExprInfo* pExprInfo, int32_t numOfCols, size_t keyBufSize, const char* pkey); -void initResultSizeInfo(SOperatorInfo* pOperator, int32_t numOfRows); +void initResultSizeInfo(SResultInfo * pResultInfo, int32_t numOfRows); void doBuildResultDatablock(SOperatorInfo* pOperator, SOptrBasicInfo* pbInfo, SGroupResInfo* pGroupResInfo, SDiskbasedBuf* pBuf); int32_t handleLimitOffset(SOperatorInfo *pOperator, SLimitInfo* pLimitInfo, SSDataBlock* pBlock, bool holdDataInBuf); bool hasLimitOffsetInfo(SLimitInfo* pLimitInfo); diff --git a/source/libs/executor/src/cachescanoperator.c b/source/libs/executor/src/cachescanoperator.c index c46485a332..56a5e253d8 100644 --- a/source/libs/executor/src/cachescanoperator.c +++ b/source/libs/executor/src/cachescanoperator.c @@ -50,7 +50,7 @@ SOperatorInfo* createLastrowScanOperator(SLastRowScanPhysiNode* pScanNode, SRead STableListInfo* pTableList = &pTaskInfo->tableqinfoList; - initResultSizeInfo(pOperator, 1024); + initResultSizeInfo(&pOperator->resultInfo, 1024); blockDataEnsureCapacity(pInfo->pRes, pOperator->resultInfo.capacity); pInfo->pUidList = taosArrayInit(4, sizeof(int64_t)); diff --git a/source/libs/executor/src/executorimpl.c b/source/libs/executor/src/executorimpl.c index 0036a3f080..df039bc0e2 100644 --- a/source/libs/executor/src/executorimpl.c +++ b/source/libs/executor/src/executorimpl.c @@ -3601,13 +3601,13 @@ int32_t initAggInfo(SExprSupp* pSup, SAggSupporter* pAggSup, SExprInfo* pExprInf return TSDB_CODE_SUCCESS; } -void initResultSizeInfo(SOperatorInfo* pOperator, int32_t numOfRows) { +void initResultSizeInfo(SResultInfo * pResultInfo, int32_t numOfRows) { ASSERT(numOfRows != 0); - pOperator->resultInfo.capacity = numOfRows; - pOperator->resultInfo.threshold = numOfRows * 0.75; + pResultInfo->capacity = numOfRows; + pResultInfo->threshold = numOfRows * 0.75; - if (pOperator->resultInfo.threshold == 0) { - pOperator->resultInfo.threshold = numOfRows; + if (pResultInfo->threshold == 0) { + pResultInfo->threshold = numOfRows; } } @@ -3670,7 +3670,7 @@ SOperatorInfo* createAggregateOperatorInfo(SOperatorInfo* downstream, SExprInfo* int32_t numOfRows = 1024; size_t keyBufSize = sizeof(int64_t) + sizeof(int64_t) + POINTER_BYTES; - initResultSizeInfo(pOperator, numOfRows); + initResultSizeInfo(&pOperator->resultInfo, numOfRows); int32_t code = initAggInfo(&pOperator->exprSupp, &pInfo->aggSup, pExprInfo, numOfCols, keyBufSize, pTaskInfo->id.str); if (code != TSDB_CODE_SUCCESS) { goto _error; @@ -3825,7 +3825,7 @@ SOperatorInfo* createProjectOperatorInfo(SOperatorInfo* downstream, SProjectPhys if (numOfRows * pResBlock->info.rowSize > TWOMB) { numOfRows = TWOMB / pResBlock->info.rowSize; } - initResultSizeInfo(pOperator, numOfRows); + initResultSizeInfo(&pOperator->resultInfo, numOfRows); initAggInfo(&pOperator->exprSupp, &pInfo->aggSup, pExprInfo, numOfCols, keyBufSize, pTaskInfo->id.str); initBasicInfo(&pInfo->binfo, pResBlock); @@ -4003,7 +4003,7 @@ SOperatorInfo* createIndefinitOutputOperatorInfo(SOperatorInfo* downstream, SPhy numOfRows = TWOMB / pResBlock->info.rowSize; } - initResultSizeInfo(pOperator, numOfRows); + initResultSizeInfo(&pOperator->resultInfo, numOfRows); initAggInfo(pSup, &pInfo->aggSup, pExprInfo, numOfExpr, keyBufSize, pTaskInfo->id.str); initBasicInfo(&pInfo->binfo, pResBlock); @@ -4080,7 +4080,7 @@ SOperatorInfo* createFillOperatorInfo(SOperatorInfo* downstream, SFillPhysiNode* int32_t type = convertFillType(pPhyFillNode->mode); SResultInfo* pResultInfo = &pOperator->resultInfo; - initResultSizeInfo(pOperator, 4096); + initResultSizeInfo(&pOperator->resultInfo, 4096); pInfo->primaryTsCol = ((SColumnNode*)pPhyFillNode->pWStartTs)->slotId; int32_t numOfOutputCols = 0; diff --git a/source/libs/executor/src/groupoperator.c b/source/libs/executor/src/groupoperator.c index 2964948e70..20630fd6ff 100644 --- a/source/libs/executor/src/groupoperator.c +++ b/source/libs/executor/src/groupoperator.c @@ -406,7 +406,7 @@ SOperatorInfo* createGroupOperatorInfo(SOperatorInfo* downstream, SExprInfo* pEx goto _error; } - initResultSizeInfo(pOperator, 4096); + initResultSizeInfo(&pOperator->resultInfo, 4096); initAggInfo(&pOperator->exprSupp, &pInfo->aggSup, pExprInfo, numOfCols, pInfo->groupKeyLen, pTaskInfo->id.str); initBasicInfo(&pInfo->binfo, pResultBlock); initResultRowInfo(&pInfo->binfo.resultRowInfo); diff --git a/source/libs/executor/src/joinoperator.c b/source/libs/executor/src/joinoperator.c index b864fae47f..497de8347c 100644 --- a/source/libs/executor/src/joinoperator.c +++ b/source/libs/executor/src/joinoperator.c @@ -41,7 +41,7 @@ SOperatorInfo* createMergeJoinOperatorInfo(SOperatorInfo** pDownstream, int32_t int32_t numOfCols = 0; SExprInfo* pExprInfo = createExprInfo(pJoinNode->pTargets, NULL, &numOfCols); - initResultSizeInfo(pOperator, 4096); + initResultSizeInfo(&pOperator->resultInfo, 4096); pInfo->pRes = pResBlock; pOperator->name = "MergeJoinOperator"; diff --git a/source/libs/executor/src/scanoperator.c b/source/libs/executor/src/scanoperator.c index dc44de9cf3..1f77dfb093 100644 --- a/source/libs/executor/src/scanoperator.c +++ b/source/libs/executor/src/scanoperator.c @@ -2299,7 +2299,7 @@ SOperatorInfo* createSysTableScanOperatorInfo(void* readHandle, SSystemTableScan pInfo->pCondition = pScanNode->node.pConditions; pInfo->scanCols = colList; - initResultSizeInfo(pOperator, 4096); + initResultSizeInfo(&pOperator->resultInfo, 4096); tNameAssign(&pInfo->name, &pScanNode->tableName); const char* name = tNameGetTableName(&pInfo->name); @@ -2529,7 +2529,7 @@ SOperatorInfo* createTagScanOperatorInfo(SReadHandle* pReadHandle, STagScanPhysi pOperator->info = pInfo; pOperator->pTaskInfo = pTaskInfo; - initResultSizeInfo(pOperator, 4096); + initResultSizeInfo(&pOperator->resultInfo, 4096); blockDataEnsureCapacity(pInfo->pRes, pOperator->resultInfo.capacity); pOperator->fpSet = @@ -3073,7 +3073,7 @@ SOperatorInfo* createTableMergeScanOperatorInfo(STableScanPhysiNode* pTableScanN pOperator->info = pInfo; pOperator->exprSupp.numOfExprs = numOfCols; pOperator->pTaskInfo = pTaskInfo; - initResultSizeInfo(pOperator, 1024); + initResultSizeInfo(&pOperator->resultInfo, 1024); pOperator->fpSet = createOperatorFpSet(operatorDummyOpenFn, doTableMergeScan, NULL, NULL, destroyTableMergeScanOperatorInfo, NULL, diff --git a/source/libs/executor/src/sortoperator.c b/source/libs/executor/src/sortoperator.c index a3b79d9597..f019ee94b8 100644 --- a/source/libs/executor/src/sortoperator.c +++ b/source/libs/executor/src/sortoperator.c @@ -26,7 +26,7 @@ static void destroyOrderOperatorInfo(void* param, int32_t numOfOutput); SOperatorInfo* createSortOperatorInfo(SOperatorInfo* downstream, SSortPhysiNode* pSortNode, SExecTaskInfo* pTaskInfo) { SSortOperatorInfo* pInfo = taosMemoryCalloc(1, sizeof(SSortOperatorInfo)); SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo)); - if (pInfo == NULL || pOperator == NULL /* || rowSize > 100 * 1024 * 1024*/) { + if (pInfo == NULL || pOperator == NULL) { goto _error; } @@ -41,13 +41,15 @@ SOperatorInfo* createSortOperatorInfo(SOperatorInfo* downstream, SSortPhysiNode* extractColMatchInfo(pSortNode->pTargets, pDescNode, &numOfOutputCols, COL_MATCH_FROM_SLOT_ID); pOperator->exprSupp.pCtx = createSqlFunctionCtx(pExprInfo, numOfCols, &pOperator->exprSupp.rowEntryInfoOffset); + + initResultSizeInfo(&pOperator->resultInfo, 1024); + pInfo->binfo.pRes = pResBlock; - - initResultSizeInfo(pOperator, 1024); - - pInfo->pSortInfo = createSortInfo(pSortNode->pSortKeys); + pInfo->pSortInfo = createSortInfo(pSortNode->pSortKeys); pInfo->pCondition = pSortNode->node.pConditions; pInfo->pColMatchInfo = pColMatchColInfo; + initLimitInfo(pSortNode->node.pLimit, pSortNode->node.pSlimit, &pInfo->limitInfo); + pOperator->name = "SortOperator"; pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_SORT; pOperator->blocking = true; @@ -208,26 +210,44 @@ SSDataBlock* doSort(SOperatorInfo* pOperator) { SSDataBlock* pBlock = NULL; while (1) { pBlock = getSortedBlockData(pInfo->pSortHandle, pInfo->binfo.pRes, pOperator->resultInfo.capacity, - pInfo->pColMatchInfo, pInfo); - if (pBlock != NULL) { - doFilter(pInfo->pCondition, pBlock); - } - + pInfo->pColMatchInfo, pInfo); if (pBlock == NULL) { doSetOperatorCompleted(pOperator); - break; + return NULL; } - if (blockDataGetNumOfRows(pBlock) > 0) { + doFilter(pInfo->pCondition, pBlock); + if (blockDataGetNumOfRows(pBlock) == 0) { + continue; + } + + // todo add the limit/offset info + if (pInfo->limitInfo.remainOffset > 0) { + if (pInfo->limitInfo.remainOffset >= blockDataGetNumOfRows(pBlock)) { + pInfo->limitInfo.remainOffset -= pBlock->info.rows; + continue; + } + + blockDataTrimFirstNRows(pBlock, pInfo->limitInfo.remainOffset); + pInfo->limitInfo.remainOffset = 0; + } + + if (pInfo->limitInfo.limit.limit > 0 && + pInfo->limitInfo.limit.limit <= pInfo->limitInfo.numOfOutputRows + blockDataGetNumOfRows(pBlock)) { + int32_t remain = pInfo->limitInfo.limit.limit - pInfo->limitInfo.numOfOutputRows; + blockDataKeepFirstNRows(pBlock, remain); + } + + size_t numOfRows = blockDataGetNumOfRows(pBlock); + pInfo->limitInfo.numOfOutputRows += numOfRows; + pOperator->resultInfo.totalRows += numOfRows; + + if (numOfRows > 0) { break; } } - if (pBlock != NULL) { - pOperator->resultInfo.totalRows += pBlock->info.rows; - } - - return pBlock; + return blockDataGetNumOfRows(pBlock) > 0? pBlock:NULL; } void destroyOrderOperatorInfo(void* param, int32_t numOfOutput) { @@ -479,7 +499,7 @@ SOperatorInfo* createGroupSortOperatorInfo(SOperatorInfo* downstream, SGroupSort pOperator->exprSupp.pCtx = createSqlFunctionCtx(pExprInfo, numOfCols, &pOperator->exprSupp.rowEntryInfoOffset); pInfo->binfo.pRes = pResBlock; - initResultSizeInfo(pOperator, 1024); + initResultSizeInfo(&pOperator->resultInfo, 1024); pInfo->pSortInfo = createSortInfo(pSortPhyNode->pSortKeys); ; @@ -711,7 +731,7 @@ SOperatorInfo* createMultiwayMergeOperatorInfo(SOperatorInfo** downStreams, size extractColMatchInfo(pMergePhyNode->pTargets, pDescNode, &numOfOutputCols, COL_MATCH_FROM_SLOT_ID); SPhysiNode* pChildNode = (SPhysiNode*)nodesListGetNode(pPhyNode->pChildren, 0); SSDataBlock* pInputBlock = createResDataBlock(pChildNode->pOutputDataBlockDesc); - initResultSizeInfo(pOperator, 1024); + initResultSizeInfo(&pOperator->resultInfo, 1024); pInfo->groupSort = pMergePhyNode->groupSort; pInfo->binfo.pRes = pResBlock; diff --git a/source/libs/executor/src/timewindowoperator.c b/source/libs/executor/src/timewindowoperator.c index 3933ded7a9..042f807271 100644 --- a/source/libs/executor/src/timewindowoperator.c +++ b/source/libs/executor/src/timewindowoperator.c @@ -1683,7 +1683,7 @@ SOperatorInfo* createIntervalOperatorInfo(SOperatorInfo* downstream, SExprInfo* SExprSupp* pSup = &pOperator->exprSupp; size_t keyBufSize = sizeof(int64_t) + sizeof(int64_t) + POINTER_BYTES; - initResultSizeInfo(pOperator, 4096); + initResultSizeInfo(&pOperator->resultInfo, 4096); int32_t code = initAggInfo(pSup, &pInfo->aggSup, pExprInfo, numOfCols, keyBufSize, pTaskInfo->id.str); initBasicInfo(&pInfo->binfo, pResBlock); @@ -1764,7 +1764,7 @@ SOperatorInfo* createStreamIntervalOperatorInfo(SOperatorInfo* downstream, SExpr int32_t numOfRows = 4096; size_t keyBufSize = sizeof(int64_t) + sizeof(int64_t) + POINTER_BYTES; - initResultSizeInfo(pOperator, numOfRows); + initResultSizeInfo(&pOperator->resultInfo, numOfRows); int32_t code = initAggInfo(&pOperator->exprSupp, &pInfo->aggSup, pExprInfo, numOfCols, keyBufSize, pTaskInfo->id.str); initBasicInfo(&pInfo->binfo, pResBlock); initExecTimeWindowInfo(&pInfo->twAggSup.timeWindowData, &pInfo->win); @@ -2224,7 +2224,7 @@ SOperatorInfo* createTimeSliceOperatorInfo(SOperatorInfo* downstream, SPhysiNode pInfo->tsCol = extractColumnFromColumnNode((SColumnNode*)pInterpPhyNode->pTimeSeries); pInfo->fillType = convertFillType(pInterpPhyNode->fillMode); - initResultSizeInfo(pOperator, 4096); + initResultSizeInfo(&pOperator->resultInfo, 4096); pInfo->pFillColInfo = createFillColInfo(pExprInfo, numOfExprs, (SNodeListNode*)pInterpPhyNode->pFillValues); pInfo->pRes = createResDataBlock(pPhyNode->pOutputDataBlockDesc); @@ -2272,7 +2272,7 @@ SOperatorInfo* createStatewindowOperatorInfo(SOperatorInfo* downstream, SExprInf size_t keyBufSize = sizeof(int64_t) + sizeof(int64_t) + POINTER_BYTES; - initResultSizeInfo(pOperator, 4096); + initResultSizeInfo(&pOperator->resultInfo, 4096); initAggInfo(&pOperator->exprSupp, &pInfo->aggSup, pExpr, numOfCols, keyBufSize, pTaskInfo->id.str); initBasicInfo(&pInfo->binfo, pResBlock); @@ -2320,7 +2320,7 @@ SOperatorInfo* createSessionAggOperatorInfo(SOperatorInfo* downstream, SExprInfo } size_t keyBufSize = sizeof(int64_t) + sizeof(int64_t) + POINTER_BYTES; - initResultSizeInfo(pOperator, 4096); + initResultSizeInfo(&pOperator->resultInfo, 4096); int32_t code = initAggInfo(&pOperator->exprSupp, &pInfo->aggSup, pExprInfo, numOfCols, keyBufSize, pTaskInfo->id.str); if (code != TSDB_CODE_SUCCESS) { @@ -2896,7 +2896,7 @@ SOperatorInfo* createStreamFinalIntervalOperatorInfo(SOperatorInfo* downstream, ASSERT(pInfo->twAggSup.calTrigger != STREAM_TRIGGER_MAX_DELAY); pInfo->primaryTsIndex = ((SColumnNode*)pIntervalPhyNode->window.pTspk)->slotId; size_t keyBufSize = sizeof(int64_t) + sizeof(int64_t) + POINTER_BYTES; - initResultSizeInfo(pOperator, 4096); + initResultSizeInfo(&pOperator->resultInfo, 4096); if (pIntervalPhyNode->window.pExprs != NULL) { int32_t numOfScalar = 0; SExprInfo* pScalarExprInfo = createExprInfo(pIntervalPhyNode->window.pExprs, NULL, &numOfScalar); @@ -3072,7 +3072,7 @@ SOperatorInfo* createStreamSessionAggOperatorInfo(SOperatorInfo* downstream, SPh goto _error; } - initResultSizeInfo(pOperator, 4096); + initResultSizeInfo(&pOperator->resultInfo, 4096); if (pSessionNode->window.pExprs != NULL) { int32_t numOfScalar = 0; SExprInfo* pScalarExprInfo = createExprInfo(pSessionNode->window.pExprs, NULL, &numOfScalar); @@ -4336,7 +4336,7 @@ SOperatorInfo* createStreamStateAggOperatorInfo(SOperatorInfo* downstream, SPhys SExprInfo* pExprInfo = createExprInfo(pStateNode->window.pFuncs, NULL, &numOfCols); pInfo->stateCol = extractColumnFromColumnNode(pColNode); - initResultSizeInfo(pOperator, 4096); + initResultSizeInfo(&pOperator->resultInfo, 4096); if (pStateNode->window.pExprs != NULL) { int32_t numOfScalar = 0; SExprInfo* pScalarExprInfo = createExprInfo(pStateNode->window.pExprs, NULL, &numOfScalar); @@ -4586,7 +4586,7 @@ SOperatorInfo* createMergeAlignedIntervalOperatorInfo(SOperatorInfo* downstream, iaInfo->primaryTsIndex = primaryTsSlotId; size_t keyBufSize = sizeof(int64_t) + sizeof(int64_t) + POINTER_BYTES; - initResultSizeInfo(pOperator, 4096); + initResultSizeInfo(&pOperator->resultInfo, 4096); int32_t code = initAggInfo(&pOperator->exprSupp, &iaInfo->aggSup, pExprInfo, numOfCols, keyBufSize, pTaskInfo->id.str); @@ -4892,7 +4892,7 @@ SOperatorInfo* createMergeIntervalOperatorInfo(SOperatorInfo* downstream, SExprI SExprSupp* pExprSupp = &pOperator->exprSupp; size_t keyBufSize = sizeof(int64_t) + sizeof(int64_t) + POINTER_BYTES; - initResultSizeInfo(pOperator, 4096); + initResultSizeInfo(&pOperator->resultInfo, 4096); int32_t code = initAggInfo(pExprSupp, &iaInfo->aggSup, pExprInfo, numOfCols, keyBufSize, pTaskInfo->id.str); initBasicInfo(&iaInfo->binfo, pResBlock); From 01385a4beb2b6aca4b990a5cd2ac5b1fced5181b Mon Sep 17 00:00:00 2001 From: Ganlin Zhao Date: Wed, 20 Jul 2022 14:07:52 +0800 Subject: [PATCH 22/45] fix twa.py --- tests/system-test/2-query/twa.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/tests/system-test/2-query/twa.py b/tests/system-test/2-query/twa.py index dde903af00..108f955977 100644 --- a/tests/system-test/2-query/twa.py +++ b/tests/system-test/2-query/twa.py @@ -7,7 +7,7 @@ import platform import math class TDTestCase: - updatecfgDict = {'debugFlag': 143 ,"cDebugFlag":143,"uDebugFlag":143 ,"rpcDebugFlag":143 , "tmrDebugFlag":143 , + updatecfgDict = {'debugFlag': 143 ,"cDebugFlag":143,"uDebugFlag":143 ,"rpcDebugFlag":143 , "tmrDebugFlag":143 , "jniDebugFlag":143 ,"simDebugFlag":143,"dDebugFlag":143, "dDebugFlag":143,"vDebugFlag":143,"mDebugFlag":143,"qDebugFlag":143, "wDebugFlag":143,"sDebugFlag":143,"tsdbDebugFlag":143,"tqDebugFlag":143 ,"fsDebugFlag":143 ,"udfDebugFlag":143, "maxTablesPerVnode":2 ,"minTablesPerVnode":2,"tableIncStepPerVnode":2 } @@ -22,7 +22,7 @@ class TDTestCase: self.time_step = 1000 def prepare_datas_of_distribute(self): - + # prepate datas for 20 tables distributed at different vgroups tdSql.execute("create database if not exists testdb keep 3650 duration 1000 vgroups 5") tdSql.execute(" use testdb ") @@ -32,16 +32,16 @@ class TDTestCase: tags (t0 timestamp, t1 int, t2 bigint, t3 smallint, t4 tinyint, t5 float, t6 double, t7 bool, t8 binary(16),t9 nchar(32)) ''' ) - + for i in range(self.tb_nums): tdSql.execute(f'create table ct{i+1} using stb1 tags ( now(), {1*i}, {11111*i}, {111*i}, {1*i}, {1.11*i}, {11.11*i}, {i%2}, "binary{i}", "nchar{i}" )') ts = self.ts for j in range(self.row_nums): - ts+=j*self.time_step + ts+=j*self.time_step tdSql.execute( f"insert into ct{i+1} values({ts}, 1, 11111, 111, 1, 1.11, 11.11, 2, 'binary{j}', 'nchar{j}', now()+{1*j}a )" ) - + tdSql.execute("insert into ct1 values (now()-810d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") tdSql.execute("insert into ct1 values (now()-400d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") tdSql.execute("insert into ct1 values (now()+90d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") @@ -64,7 +64,7 @@ class TDTestCase: vgroups = tdSql.queryResult vnode_tables={} - + for vgroup_id in vgroups: vnode_tables[vgroup_id[0]]=[] @@ -73,7 +73,7 @@ class TDTestCase: table_names = tdSql.queryResult tablenames = [] for table_name in table_names: - vnode_tables[table_name[6]].append(table_name[0]) + vnode_tables[table_name[6]].append(table_name[0]) self.vnode_disbutes = vnode_tables count = 0 @@ -103,12 +103,12 @@ class TDTestCase: tdSql.checkRows(self.tb_nums) tdSql.checkData(0,0,1.000000000) - # union all + # union all tdSql.query(" select twa(c1) from stb1 partition by tbname union all select twa(c1) from stb1 partition by tbname ") tdSql.checkRows(40) tdSql.checkData(0,0,1.000000000) - # join + # join tdSql.execute(" create database if not exists db ") tdSql.execute(" use db ") @@ -116,7 +116,7 @@ class TDTestCase: tdSql.execute(" create table tb1 using st tags(1) ") tdSql.execute(" create table tb2 using st tags(2) ") - + for i in range(10): ts = i*10 + self.ts tdSql.execute(f" insert into tb1 values({ts},{i},{i}.0)") @@ -127,7 +127,7 @@ class TDTestCase: tdSql.checkData(0,0,4.500000000) tdSql.checkData(0,1,4.500000000) - # group by + # group by tdSql.execute(" use testdb ") # mixup with other functions @@ -141,7 +141,7 @@ class TDTestCase: self.check_distribute_datas() self.twa_support_types() self.distribute_twa_query() - + def stop(self): tdSql.close() tdLog.success("%s successfully executed" % __file__) From eefad2bd9d2b566346e933fb7e0f6f541ceeba37 Mon Sep 17 00:00:00 2001 From: Minglei Jin Date: Wed, 20 Jul 2022 14:28:13 +0800 Subject: [PATCH 23/45] fix: use Ex version of metaGetTbTSchema to retrieve schema --- source/dnode/vnode/src/tsdb/tsdbRead.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/source/dnode/vnode/src/tsdb/tsdbRead.c b/source/dnode/vnode/src/tsdb/tsdbRead.c index c1778ed5ca..cac51faeee 100644 --- a/source/dnode/vnode/src/tsdb/tsdbRead.c +++ b/source/dnode/vnode/src/tsdb/tsdbRead.c @@ -2576,10 +2576,12 @@ void updateSchema(TSDBROW* pRow, uint64_t uid, STsdbReader* pReader) { int32_t sversion = TSDBROW_SVERSION(pRow); if (pReader->pSchema == NULL) { - pReader->pSchema = metaGetTbTSchema(pReader->pTsdb->pVnode->pMeta, uid, sversion); + // pReader->pSchema = metaGetTbTSchema(pReader->pTsdb->pVnode->pMeta, uid, sversion); + metaGetTbTSchemaEx(pReader->pTsdb->pVnode->pMeta, 0, uid, sversion, &pReader->pSchema); } else if (pReader->pSchema->version != sversion) { taosMemoryFreeClear(pReader->pSchema); - pReader->pSchema = metaGetTbTSchema(pReader->pTsdb->pVnode->pMeta, uid, sversion); + // pReader->pSchema = metaGetTbTSchema(pReader->pTsdb->pVnode->pMeta, uid, sversion); + metaGetTbTSchemaEx(pReader->pTsdb->pVnode->pMeta, 0, uid, sversion, &pReader->pSchema); } } From a2dd6f0ce504c387a28df248b3699d72b4d856e9 Mon Sep 17 00:00:00 2001 From: Ganlin Zhao Date: Wed, 20 Jul 2022 14:42:03 +0800 Subject: [PATCH 24/45] fix(query): fix memory leak in histogram param validation TD-17598 --- source/libs/function/src/builtins.c | 1 + 1 file changed, 1 insertion(+) diff --git a/source/libs/function/src/builtins.c b/source/libs/function/src/builtins.c index 9c004bf1c4..ec8e6b038e 100644 --- a/source/libs/function/src/builtins.c +++ b/source/libs/function/src/builtins.c @@ -958,6 +958,7 @@ static bool validateHistogramBinDesc(char* binDescStr, int8_t binType, char* err return false; } + cJSON_Delete(binDesc); taosMemoryFree(intervals); return true; } From 83d772130856089353e975eaa49d811e50a5ec51 Mon Sep 17 00:00:00 2001 From: plum-lihui Date: Wed, 20 Jul 2022 14:43:52 +0800 Subject: [PATCH 25/45] test: add test case for tmq --- tests/system-test/7-tmq/tmqAutoCreateTbl.py | 38 ++++--- tests/system-test/7-tmq/tmqDnodeRestart.py | 112 ++++++++++---------- tests/system-test/fulltest.sh | 2 +- 3 files changed, 84 insertions(+), 68 deletions(-) diff --git a/tests/system-test/7-tmq/tmqAutoCreateTbl.py b/tests/system-test/7-tmq/tmqAutoCreateTbl.py index 8fcb57aea6..ba2066e742 100644 --- a/tests/system-test/7-tmq/tmqAutoCreateTbl.py +++ b/tests/system-test/7-tmq/tmqAutoCreateTbl.py @@ -16,6 +16,7 @@ from tmqCommon import * class TDTestCase: def __init__(self): + self.snapshot = 0 self.vgroups = 4 self.ctbNum = 1000 self.rowsPerTbl = 1000 @@ -44,7 +45,7 @@ class TDTestCase: 'pollDelay': 3, 'showMsg': 1, 'showRow': 1, - 'snapshot': 1} + 'snapshot': 0} paraDict['vgroups'] = self.vgroups paraDict['ctbNum'] = self.ctbNum @@ -84,13 +85,14 @@ class TDTestCase: 'ctbStartIdx': 0, 'ctbNum': 1000, 'rowsPerTbl': 1000, - 'batchNum': 400, + 'batchNum': 1000, 'startTs': 1640966400000, # 2022-01-01 00:00:00.000 'pollDelay': 5, 'showMsg': 1, 'showRow': 1, - 'snapshot': 1} + 'snapshot': 0} + paraDict['snapshot'] = self.snapshot paraDict['vgroups'] = self.vgroups paraDict['ctbNum'] = self.ctbNum paraDict['rowsPerTbl'] = self.rowsPerTbl @@ -131,10 +133,10 @@ class TDTestCase: totalConsumeRows += resultList[i] tdSql.query(queryString) - totalRowsInserted = tdSql.getRows() + totalRowsFromQuery = tdSql.getRows() - if totalConsumeRows != totalRowsInserted: - tdLog.info("act consume rows: %d, expect consume rows: %d"%(totalConsumeRows, totalRowsInserted)) + tdLog.info("act consume rows: %d, expect consume rows: %d"%(totalConsumeRows, totalRowsFromQuery)) + if totalConsumeRows != totalRowsFromQuery: tdLog.exit("tmq consume rows error!") tdSql.query("drop topic %s"%topicFromStb1) @@ -163,6 +165,7 @@ class TDTestCase: 'showRow': 1, 'snapshot': 0} + paraDict['snapshot'] = self.snapshot paraDict['vgroups'] = self.vgroups paraDict['ctbNum'] = self.ctbNum paraDict['rowsPerTbl'] = self.rowsPerTbl @@ -180,12 +183,13 @@ class TDTestCase: # startTs=paraDict["startTs"],ctbStartIdx=paraDict['ctbStartIdx']) tdLog.info("create topics from stb1") topicFromStb1 = 'topic_stb1' - queryString = "select ts, c1, c2 from %s.%s"%(paraDict['dbName'], paraDict['stbName']) + # queryString = "select ts, c1, c2 from %s.%s "%(paraDict['dbName'], paraDict['stbName']) + queryString = "select ts, c1, c2 from %s.%s where t4 == 'shanghai' or t4 == 'changsha'"%(paraDict['dbName'], paraDict['stbName']) sqlString = "create topic %s as %s" %(topicFromStb1, queryString) tdLog.info("create topic sql: %s"%sqlString) tdSql.execute(sqlString) - consumerId = 0 + consumerId = 1 expectrowcnt = paraDict["rowsPerTbl"] * paraDict["ctbNum"] * 2 topicList = topicFromStb1 ifcheckdata = 0 @@ -210,10 +214,10 @@ class TDTestCase: totalConsumeRows += resultList[i] tdSql.query(queryString) - totalRowsInserted = tdSql.getRows() + totalRowsFromQuery = tdSql.getRows() - if totalConsumeRows != totalRowsInserted: - tdLog.info("act consume rows: %d, expect consume rows: %d"%(totalConsumeRows, totalRowsInserted)) + tdLog.info("act consume rows: %d, expect consume rows: %d"%(totalConsumeRows, totalRowsFromQuery)) + if totalConsumeRows != totalRowsFromQuery: tdLog.exit("tmq consume rows error!") tdSql.query("drop topic %s"%topicFromStb1) @@ -222,10 +226,18 @@ class TDTestCase: def run(self): - tdSql.prepare() self.prepareTestEnv() + tdLog.printNoPrefix("=============================================") + tdLog.printNoPrefix("======== snapshot is 0: only consume from wal") self.tmqCase1() - # self.tmqCase2() # TD-17267 + self.tmqCase2() + + self.prepareTestEnv() + tdLog.printNoPrefix("====================================================================") + tdLog.printNoPrefix("======== snapshot is 1: firstly consume from tsbs, and then from wal") + self.snapshot = 1 + self.tmqCase1() + self.tmqCase2() def stop(self): diff --git a/tests/system-test/7-tmq/tmqDnodeRestart.py b/tests/system-test/7-tmq/tmqDnodeRestart.py index 8354991578..9699c4b32c 100644 --- a/tests/system-test/7-tmq/tmqDnodeRestart.py +++ b/tests/system-test/7-tmq/tmqDnodeRestart.py @@ -16,6 +16,7 @@ from tmqCommon import * class TDTestCase: def __init__(self): + self.snapshot = 0 self.vgroups = 2 self.ctbNum = 100 self.rowsPerTbl = 10000 @@ -37,15 +38,16 @@ class TDTestCase: 'tagSchema': [{'type': 'INT', 'count':1},{'type': 'BIGINT', 'count':1},{'type': 'DOUBLE', 'count':1},{'type': 'BINARY', 'len':32, 'count':1},{'type': 'NCHAR', 'len':32, 'count':1}], 'ctbPrefix': 'ctb', 'ctbStartIdx': 0, - 'ctbNum': 500, - 'rowsPerTbl': 1000, - 'batchNum': 500, + 'ctbNum': 100, + 'rowsPerTbl': 10000, + 'batchNum': 100, 'startTs': 1640966400000, # 2022-01-01 00:00:00.000 'pollDelay': 3, 'showMsg': 1, 'showRow': 1, 'snapshot': 0} + paraDict['snapshot'] = self.snapshot paraDict['vgroups'] = self.vgroups paraDict['ctbNum'] = self.ctbNum paraDict['rowsPerTbl'] = self.rowsPerTbl @@ -81,30 +83,31 @@ class TDTestCase: 'tagSchema': [{'type': 'INT', 'count':1},{'type': 'BIGINT', 'count':1},{'type': 'DOUBLE', 'count':1},{'type': 'BINARY', 'len':32, 'count':1},{'type': 'NCHAR', 'len':32, 'count':1}], 'ctbPrefix': 'ctb', 'ctbStartIdx': 0, - 'ctbNum': 1000, - 'rowsPerTbl': 1000, - 'batchNum': 400, + 'ctbNum': 100, + 'rowsPerTbl': 10000, + 'batchNum': 100, 'startTs': 1640966400000, # 2022-01-01 00:00:00.000 'pollDelay': 5, 'showMsg': 1, 'showRow': 1, - 'snapshot': 1} + 'snapshot': 0} - # paraDict['vgroups'] = self.vgroups - # paraDict['ctbNum'] = self.ctbNum - # paraDict['rowsPerTbl'] = self.rowsPerTbl + paraDict['snapshot'] = self.snapshot + paraDict['vgroups'] = self.vgroups + paraDict['ctbNum'] = self.ctbNum + paraDict['rowsPerTbl'] = self.rowsPerTbl - tmqCom.initConsumerTable() - tdCom.create_database(tdSql, paraDict["dbName"],paraDict["dropFlag"], vgroups=paraDict["vgroups"],replica=1) - tdLog.info("create stb") - tmqCom.create_stable(tdSql, dbName=paraDict["dbName"],stbName=paraDict["stbName"]) - tdLog.info("create ctb") - tmqCom.create_ctable(tdSql, dbName=paraDict["dbName"],stbName=paraDict["stbName"],ctbPrefix=paraDict['ctbPrefix'], - ctbNum=paraDict["ctbNum"],ctbStartIdx=paraDict['ctbStartIdx']) - tdLog.info("insert data") - tmqCom.insert_data_interlaceByMultiTbl(tsql=tdSql,dbName=paraDict["dbName"],ctbPrefix=paraDict["ctbPrefix"], - ctbNum=paraDict["ctbNum"],rowsPerTbl=paraDict["rowsPerTbl"],batchNum=paraDict["batchNum"], - startTs=paraDict["startTs"],ctbStartIdx=paraDict['ctbStartIdx']) + # tmqCom.initConsumerTable() + # tdCom.create_database(tdSql, paraDict["dbName"],paraDict["dropFlag"], vgroups=paraDict["vgroups"],replica=1) + # tdLog.info("create stb") + # tmqCom.create_stable(tdSql, dbName=paraDict["dbName"],stbName=paraDict["stbName"]) + # tdLog.info("create ctb") + # tmqCom.create_ctable(tdSql, dbName=paraDict["dbName"],stbName=paraDict["stbName"],ctbPrefix=paraDict['ctbPrefix'], + # ctbNum=paraDict["ctbNum"],ctbStartIdx=paraDict['ctbStartIdx']) + # tdLog.info("insert data") + # tmqCom.insert_data_interlaceByMultiTbl(tsql=tdSql,dbName=paraDict["dbName"],ctbPrefix=paraDict["ctbPrefix"], + # ctbNum=paraDict["ctbNum"],rowsPerTbl=paraDict["rowsPerTbl"],batchNum=paraDict["batchNum"], + # startTs=paraDict["startTs"],ctbStartIdx=paraDict['ctbStartIdx']) tdLog.info("create topics from stb1") topicFromStb1 = 'topic_stb1' @@ -132,7 +135,7 @@ class TDTestCase: tdLog.info("================= restart dnode ===========================") tdDnodes.stop(1) tdDnodes.start(1) - time.sleep(5) + time.sleep(3) tdLog.info("insert process end, and start to check consume result") expectRows = 1 @@ -142,10 +145,10 @@ class TDTestCase: totalConsumeRows += resultList[i] tdSql.query(queryString) - totalRowsInserted = tdSql.getRows() + totalRowsFromQury = tdSql.getRows() - if totalConsumeRows != totalRowsInserted: - tdLog.info("act consume rows: %d, expect consume rows: %d"%(totalConsumeRows, totalRowsInserted)) + tdLog.info("act consume rows: %d, expect consume rows: %d"%(totalConsumeRows, totalRowsFromQury)) + if totalConsumeRows != totalRowsFromQury: tdLog.exit("tmq consume rows error!") tdSql.query("drop topic %s"%topicFromStb1) @@ -165,30 +168,31 @@ class TDTestCase: 'tagSchema': [{'type': 'INT', 'count':1},{'type': 'BIGINT', 'count':1},{'type': 'DOUBLE', 'count':1},{'type': 'BINARY', 'len':32, 'count':1},{'type': 'NCHAR', 'len':32, 'count':1}], 'ctbPrefix': 'ctb', 'ctbStartIdx': 0, - 'ctbNum': 1000, - 'rowsPerTbl': 1000, - 'batchNum': 1000, + 'ctbNum': 100, + 'rowsPerTbl': 10000, + 'batchNum': 3000, 'startTs': 1640966400000, # 2022-01-01 00:00:00.000 'pollDelay': 5, 'showMsg': 1, 'showRow': 1, - 'snapshot': 1} + 'snapshot': 0} - # paraDict['vgroups'] = self.vgroups - # paraDict['ctbNum'] = self.ctbNum - # paraDict['rowsPerTbl'] = self.rowsPerTbl + paraDict['snapshot'] = self.snapshot + paraDict['vgroups'] = self.vgroups + paraDict['ctbNum'] = self.ctbNum + paraDict['rowsPerTbl'] = self.rowsPerTbl tmqCom.initConsumerTable() - tdCom.create_database(tdSql, paraDict["dbName"],paraDict["dropFlag"], vgroups=paraDict["vgroups"],replica=1) - tdLog.info("create stb") - tmqCom.create_stable(tdSql, dbName=paraDict["dbName"],stbName=paraDict["stbName"]) - tdLog.info("create ctb") - tmqCom.create_ctable(tdSql, dbName=paraDict["dbName"],stbName=paraDict["stbName"],ctbPrefix=paraDict['ctbPrefix'], - ctbNum=paraDict["ctbNum"],ctbStartIdx=paraDict['ctbStartIdx']) - tdLog.info("insert data") - tmqCom.insert_data_interlaceByMultiTbl(tsql=tdSql,dbName=paraDict["dbName"],ctbPrefix=paraDict["ctbPrefix"], - ctbNum=paraDict["ctbNum"],rowsPerTbl=paraDict["rowsPerTbl"],batchNum=paraDict["batchNum"], - startTs=paraDict["startTs"],ctbStartIdx=paraDict['ctbStartIdx']) + # tdCom.create_database(tdSql, paraDict["dbName"],paraDict["dropFlag"], vgroups=paraDict["vgroups"],replica=1) + # tdLog.info("create stb") + # tmqCom.create_stable(tdSql, dbName=paraDict["dbName"],stbName=paraDict["stbName"]) + # tdLog.info("create ctb") + # tmqCom.create_ctable(tdSql, dbName=paraDict["dbName"],stbName=paraDict["stbName"],ctbPrefix=paraDict['ctbPrefix'], + # ctbNum=paraDict["ctbNum"],ctbStartIdx=paraDict['ctbStartIdx']) + # tdLog.info("insert data") + # tmqCom.insert_data_interlaceByMultiTbl(tsql=tdSql,dbName=paraDict["dbName"],ctbPrefix=paraDict["ctbPrefix"], + # ctbNum=paraDict["ctbNum"],rowsPerTbl=paraDict["rowsPerTbl"],batchNum=paraDict["batchNum"], + # startTs=paraDict["startTs"],ctbStartIdx=paraDict['ctbStartIdx']) tdLog.info("create topics from stb1") topicFromStb1 = 'topic_stb1' queryString = "select ts, c1, c2 from %s.%s"%(paraDict['dbName'], paraDict['stbName']) @@ -196,29 +200,29 @@ class TDTestCase: tdLog.info("create topic sql: %s"%sqlString) tdSql.execute(sqlString) - consumerId = 0 - expectrowcnt = paraDict["rowsPerTbl"] * paraDict["ctbNum"] * 2 + consumerId = 1 + expectrowcnt = paraDict["rowsPerTbl"] * paraDict["ctbNum"] * 2 + 100000 topicList = topicFromStb1 ifcheckdata = 0 ifManualCommit = 0 keyList = 'group.id:cgrp1,\ enable.auto.commit:true,\ - auto.commit.interval.ms:1000,\ + auto.commit.interval.ms:3000,\ auto.offset.reset:earliest' tmqCom.insertConsumerInfo(consumerId, expectrowcnt,topicList,keyList,ifcheckdata,ifManualCommit) tdLog.info("start consume processor") tmqCom.startTmqSimProcess(pollDelay=paraDict['pollDelay'],dbName=paraDict["dbName"],showMsg=paraDict['showMsg'], showRow=paraDict['showRow'],snapshot=paraDict['snapshot']) - tdLog.info("create some new child table and insert data ") - tmqCom.insert_data_with_autoCreateTbl(tdSql,paraDict["dbName"],paraDict["stbName"],"ctb",paraDict["ctbNum"],paraDict["rowsPerTbl"],paraDict["batchNum"]) - tmqCom.getStartCommitNotifyFromTmqsim() tdLog.info("================= restart dnode ===========================") tdDnodes.stop(1) tdDnodes.start(1) - time.sleep(5) + time.sleep(3) + tdLog.info("create some new child table and insert data ") + tmqCom.insert_data_with_autoCreateTbl(tdSql,paraDict["dbName"],paraDict["stbName"],"ctb",paraDict["ctbNum"],paraDict["rowsPerTbl"],paraDict["batchNum"]) + tdLog.info("insert process end, and start to check consume result") expectRows = 1 resultList = tmqCom.selectConsumeResult(expectRows) @@ -227,10 +231,10 @@ class TDTestCase: totalConsumeRows += resultList[i] tdSql.query(queryString) - totalRowsInserted = tdSql.getRows() + totalRowsFromQuery = tdSql.getRows() - if totalConsumeRows != totalRowsInserted: - tdLog.info("act consume rows: %d, expect consume rows: %d"%(totalConsumeRows, totalRowsInserted)) + tdLog.info("act consume rows: %d, expect consume rows: %d"%(totalConsumeRows, totalRowsFromQuery)) + if totalConsumeRows != totalRowsFromQuery: tdLog.exit("tmq consume rows error!") tdSql.query("drop topic %s"%topicFromStb1) @@ -239,8 +243,8 @@ class TDTestCase: def run(self): tdSql.prepare() - - self.tmqCase1() + self.prepareTestEnv() + # self.tmqCase1() self.tmqCase2() def stop(self): diff --git a/tests/system-test/fulltest.sh b/tests/system-test/fulltest.sh index 6639376485..441427847a 100755 --- a/tests/system-test/fulltest.sh +++ b/tests/system-test/fulltest.sh @@ -184,7 +184,7 @@ python3 ./test.py -f 7-tmq/tmqConsFromTsdb-mutilVg-mutilCtb.py python3 ./test.py -f 7-tmq/tmqConsFromTsdb1-1ctb-funcNFilter.py python3 ./test.py -f 7-tmq/tmqConsFromTsdb1-mutilVg-mutilCtb-funcNFilter.py python3 ./test.py -f 7-tmq/tmqConsFromTsdb1-mutilVg-mutilCtb.py -python3 ./test.py -f 7-tmq/tmqAutoCreateTbl.py +#python3 ./test.py -f 7-tmq/tmqAutoCreateTbl.py #python3 ./test.py -f 7-tmq/tmqDnodeRestart.py python3 ./test.py -f 7-tmq/tmqUpdate-1ctb.py python3 ./test.py -f 7-tmq/tmqUpdate-multiCtb-snapshot0.py From 4dbb2debc05565f06eb4ca91c913fd9a5d762be7 Mon Sep 17 00:00:00 2001 From: Ganlin Zhao Date: Wed, 20 Jul 2022 14:42:03 +0800 Subject: [PATCH 26/45] fix(query): fix memory leak in histogram param validation TD-17598 --- source/libs/scalar/src/sclfunc.c | 1 + 1 file changed, 1 insertion(+) diff --git a/source/libs/scalar/src/sclfunc.c b/source/libs/scalar/src/sclfunc.c index b754c52bbd..050f77bb21 100644 --- a/source/libs/scalar/src/sclfunc.c +++ b/source/libs/scalar/src/sclfunc.c @@ -2750,6 +2750,7 @@ static bool getHistogramBinDesc(SHistoFuncBin** bins, int32_t* binNum, char* bin (*bins)[i].count = 0; } + cJSON_Delete(binDesc); taosMemoryFree(intervals); return true; } From 527aa3584dfbaa76630a8542ccc220584c7c6c2a Mon Sep 17 00:00:00 2001 From: Minglei Jin Date: Wed, 20 Jul 2022 15:26:47 +0800 Subject: [PATCH 27/45] fix: get suid from uid to be used to retrieve schema --- source/dnode/vnode/src/tsdb/tsdbRead.c | 29 ++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/source/dnode/vnode/src/tsdb/tsdbRead.c b/source/dnode/vnode/src/tsdb/tsdbRead.c index cac51faeee..7048dc7b2b 100644 --- a/source/dnode/vnode/src/tsdb/tsdbRead.c +++ b/source/dnode/vnode/src/tsdb/tsdbRead.c @@ -2572,16 +2572,41 @@ int32_t doMergeRowsInFileBlocks(SBlockData* pBlockData, STableBlockScanInfo* pSc return TSDB_CODE_SUCCESS; } +static tb_uid_t getTableSuidByUid(tb_uid_t uid, STsdb* pTsdb) { + tb_uid_t suid = 0; + + SMetaReader mr = {0}; + metaReaderInit(&mr, pTsdb->pVnode->pMeta, 0); + if (metaGetTableEntryByUid(&mr, uid) < 0) { + metaReaderClear(&mr); // table not esist + return 0; + } + + if (mr.me.type == TSDB_CHILD_TABLE) { + suid = mr.me.ctbEntry.suid; + } else if (mr.me.type == TSDB_NORMAL_TABLE) { + suid = 0; + } else { + suid = 0; + } + + metaReaderClear(&mr); + + return suid; +} + void updateSchema(TSDBROW* pRow, uint64_t uid, STsdbReader* pReader) { int32_t sversion = TSDBROW_SVERSION(pRow); + tb_uid_t suid = getTableSuidByUid(uid, pReader->pTsdb); + if (pReader->pSchema == NULL) { // pReader->pSchema = metaGetTbTSchema(pReader->pTsdb->pVnode->pMeta, uid, sversion); - metaGetTbTSchemaEx(pReader->pTsdb->pVnode->pMeta, 0, uid, sversion, &pReader->pSchema); + metaGetTbTSchemaEx(pReader->pTsdb->pVnode->pMeta, suid, uid, sversion, &pReader->pSchema); } else if (pReader->pSchema->version != sversion) { taosMemoryFreeClear(pReader->pSchema); // pReader->pSchema = metaGetTbTSchema(pReader->pTsdb->pVnode->pMeta, uid, sversion); - metaGetTbTSchemaEx(pReader->pTsdb->pVnode->pMeta, 0, uid, sversion, &pReader->pSchema); + metaGetTbTSchemaEx(pReader->pTsdb->pVnode->pMeta, suid, uid, sversion, &pReader->pSchema); } } From df58a9bb30341843081ad3cc3a4072423665eaee Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Wed, 20 Jul 2022 15:30:52 +0800 Subject: [PATCH 28/45] fix(query): handle fraction of ts in add ts offset. --- source/common/src/ttime.c | 6 ++++-- source/libs/executor/inc/executorimpl.h | 2 +- source/libs/executor/src/executil.c | 4 ++-- source/libs/executor/src/executorimpl.c | 17 +++++++++-------- source/libs/executor/src/scanoperator.c | 4 ++-- tests/script/tsim/query/interval-offset.sim | 1 + 6 files changed, 19 insertions(+), 15 deletions(-) diff --git a/source/common/src/ttime.c b/source/common/src/ttime.c index 9b044d6e93..8f150441f9 100644 --- a/source/common/src/ttime.c +++ b/source/common/src/ttime.c @@ -700,6 +700,8 @@ int64_t taosTimeAdd(int64_t t, int64_t duration, char unit, int32_t precision) { numOfMonth *= 12; } + int64_t fraction = t % TSDB_TICK_PER_SECOND(precision); + struct tm tm; time_t tt = (time_t)(t / TSDB_TICK_PER_SECOND(precision)); taosLocalTime(&tt, &tm); @@ -707,7 +709,7 @@ int64_t taosTimeAdd(int64_t t, int64_t duration, char unit, int32_t precision) { tm.tm_year = mon / 12; tm.tm_mon = mon % 12; - return (int64_t)(taosMktime(&tm) * TSDB_TICK_PER_SECOND(precision)); + return (int64_t)(taosMktime(&tm) * TSDB_TICK_PER_SECOND(precision) + fraction); } int64_t taosTimeSub(int64_t t, int64_t duration, char unit, int32_t precision) { @@ -851,7 +853,7 @@ int64_t taosTimeTruncate(int64_t t, const SInterval* pInterval, int32_t precisio newEnd = taosTimeAdd(newEnd, -pInterval->sliding, pInterval->slidingUnit, precision); } - start = taosTimeAdd(end, -pInterval->interval + 1, pInterval->intervalUnit, precision); + start = taosTimeAdd(end, -pInterval->interval, pInterval->intervalUnit, precision) + 1; } } diff --git a/source/libs/executor/inc/executorimpl.h b/source/libs/executor/inc/executorimpl.h index 9142af4a6d..2cc4058b3b 100644 --- a/source/libs/executor/inc/executorimpl.h +++ b/source/libs/executor/inc/executorimpl.h @@ -797,7 +797,7 @@ void doApplyFunctions(SExecTaskInfo* taskInfo, SqlFunctionCtx* pCtx, STimeWin int32_t extractDataBlockFromFetchRsp(SSDataBlock* pRes, SLoadRemoteDataInfo* pLoadInfo, int32_t numOfRows, char* pData, int32_t compLen, int32_t numOfOutput, int64_t startTs, uint64_t* total, SArray* pColList); -void getAlignQueryTimeWindow(SInterval* pInterval, int32_t precision, int64_t key, STimeWindow* win); +STimeWindow getAlignQueryTimeWindow(SInterval* pInterval, int32_t precision, int64_t key); STimeWindow getFirstQualifiedTimeWindow(int64_t ts, STimeWindow* pWindow, SInterval* pInterval, int32_t order); int32_t getTableScanInfo(SOperatorInfo* pOperator, int32_t *order, int32_t* scanFlag); diff --git a/source/libs/executor/src/executil.c b/source/libs/executor/src/executil.c index 978bef1607..60799e0528 100644 --- a/source/libs/executor/src/executil.c +++ b/source/libs/executor/src/executil.c @@ -824,10 +824,10 @@ int32_t convertFillType(int32_t mode) { static void getInitialStartTimeWindow(SInterval* pInterval, TSKEY ts, STimeWindow* w, bool ascQuery) { if (ascQuery) { - getAlignQueryTimeWindow(pInterval, pInterval->precision, ts, w); + *w = getAlignQueryTimeWindow(pInterval, pInterval->precision, ts); } else { // the start position of the first time window in the endpoint that spreads beyond the queried last timestamp - getAlignQueryTimeWindow(pInterval, pInterval->precision, ts, w); + *w = getAlignQueryTimeWindow(pInterval, pInterval->precision, ts); int64_t key = w->skey; while (key < ts) { // moving towards end diff --git a/source/libs/executor/src/executorimpl.c b/source/libs/executor/src/executorimpl.c index df039bc0e2..44d1cc0965 100644 --- a/source/libs/executor/src/executorimpl.c +++ b/source/libs/executor/src/executorimpl.c @@ -834,18 +834,20 @@ bool isTaskKilled(SExecTaskInfo* pTaskInfo) { void setTaskKilled(SExecTaskInfo* pTaskInfo) { pTaskInfo->code = TSDB_CODE_TSC_QUERY_CANCELLED; } ///////////////////////////////////////////////////////////////////////////////////////////// -// todo refactor : return window -void getAlignQueryTimeWindow(SInterval* pInterval, int32_t precision, int64_t key, STimeWindow* win) { - win->skey = taosTimeTruncate(key, pInterval, precision); +STimeWindow getAlignQueryTimeWindow(SInterval* pInterval, int32_t precision, int64_t key) { + STimeWindow win = {0}; + win.skey = taosTimeTruncate(key, pInterval, precision); /* * if the realSkey > INT64_MAX - pInterval->interval, the query duration between * realSkey and realEkey must be less than one interval.Therefore, no need to adjust the query ranges. */ - win->ekey = taosTimeAdd(win->skey, pInterval->interval, pInterval->intervalUnit, precision) - 1; - if (win->ekey < win->skey) { - win->ekey = INT64_MAX; + win.ekey = taosTimeAdd(win.skey, pInterval->interval, pInterval->intervalUnit, precision) - 1; + if (win.ekey < win.skey) { + win.ekey = INT64_MAX; } + + return win; } #if 0 @@ -4042,8 +4044,7 @@ static int32_t initFillInfo(SFillOperatorInfo* pInfo, SExprInfo* pExpr, int32_t STimeWindow win, int32_t capacity, const char* id, SInterval* pInterval, int32_t fillType) { SFillColInfo* pColInfo = createFillColInfo(pExpr, numOfCols, pValNode); - STimeWindow w = TSWINDOW_INITIALIZER; - getAlignQueryTimeWindow(pInterval, pInterval->precision, win.skey, &w); + STimeWindow w = getAlignQueryTimeWindow(pInterval, pInterval->precision, win.skey); w = getFirstQualifiedTimeWindow(win.skey, &w, pInterval, TSDB_ORDER_ASC); int32_t order = TSDB_ORDER_ASC; diff --git a/source/libs/executor/src/scanoperator.c b/source/libs/executor/src/scanoperator.c index 1f77dfb093..ae5996c2fa 100644 --- a/source/libs/executor/src/scanoperator.c +++ b/source/libs/executor/src/scanoperator.c @@ -125,7 +125,7 @@ static bool overlapWithTimeWindow(SInterval* pInterval, SDataBlockInfo* pBlockIn } if (order == TSDB_ORDER_ASC) { - getAlignQueryTimeWindow(pInterval, pInterval->precision, pBlockInfo->window.skey, &w); + w = getAlignQueryTimeWindow(pInterval, pInterval->precision, pBlockInfo->window.skey); assert(w.ekey >= pBlockInfo->window.skey); if (w.ekey < pBlockInfo->window.ekey) { @@ -144,7 +144,7 @@ static bool overlapWithTimeWindow(SInterval* pInterval, SDataBlockInfo* pBlockIn } } } else { - getAlignQueryTimeWindow(pInterval, pInterval->precision, pBlockInfo->window.ekey, &w); + w = getAlignQueryTimeWindow(pInterval, pInterval->precision, pBlockInfo->window.ekey); assert(w.skey <= pBlockInfo->window.ekey); if (w.skey > pBlockInfo->window.skey) { diff --git a/tests/script/tsim/query/interval-offset.sim b/tests/script/tsim/query/interval-offset.sim index b6dffb5fe3..1399be7b53 100644 --- a/tests/script/tsim/query/interval-offset.sim +++ b/tests/script/tsim/query/interval-offset.sim @@ -185,6 +185,7 @@ print ===> rows1: $data10 $data11 $data12 $data13 $data14 print ===> rows2: $data20 $data21 $data22 $data23 $data24 print ===> rows3: $data30 $data31 $data32 $data33 $data34 if $rows != 4 then + print expect 4, actual: $rows return -1 endi if $data00 != @21-12-08 00:00:00.000@ then From 736960e1d2d521682f5e6e981aebd8af10bca214 Mon Sep 17 00:00:00 2001 From: 54liuyao <54liuyao@163.com> Date: Wed, 20 Jul 2022 15:15:37 +0800 Subject: [PATCH 29/45] feat(stream): add log --- source/libs/executor/src/timewindowoperator.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/source/libs/executor/src/timewindowoperator.c b/source/libs/executor/src/timewindowoperator.c index d206f56ec3..39c05e81bf 100644 --- a/source/libs/executor/src/timewindowoperator.c +++ b/source/libs/executor/src/timewindowoperator.c @@ -652,7 +652,7 @@ static void doInterpUnclosedTimeWindow(SOperatorInfo* pOperatorInfo, int32_t num void printDataBlock(SSDataBlock* pBlock, const char* flag) { if (!pBlock || pBlock->info.rows == 0) { - qDebug("======printDataBlock: Block is Null or Empty"); + qDebug("===stream===printDataBlock: Block is Null or Empty"); return; } char* pBuf = NULL; @@ -772,12 +772,6 @@ int32_t binarySearch(void* keyList, int num, TSKEY key, int order, __get_value_f return midPos; } -int64_t getReskey(void* data, int32_t index) { - SArray* res = (SArray*)data; - SResKeyPos* pos = taosArrayGetP(res, index); - return *(int64_t*)pos->key; -} - int32_t compareResKey(void* pKey, void* data, int32_t index) { SArray* res = (SArray*)data; SResKeyPos* pos = taosArrayGetP(res, index); @@ -1537,8 +1531,10 @@ static SSDataBlock* doStreamIntervalAgg(SOperatorInfo* pOperator) { doBuildResultDatablock(pOperator, &pInfo->binfo, &pInfo->groupResInfo, pInfo->aggSup.pResultBuf); if (pInfo->binfo.pRes->info.rows == 0 || !hasDataInGroupInfo(&pInfo->groupResInfo)) { pOperator->status = OP_EXEC_DONE; + qDebug("===stream===single interval is done"); freeAllPages(pInfo->pRecycledPages, pInfo->aggSup.pResultBuf); } + printDataBlock(pInfo->binfo.pRes, "single interval"); return pInfo->binfo.pRes->info.rows == 0 ? NULL : pInfo->binfo.pRes; } From aa02a56a98935e746e0b8edd2cb19d9b0dbb0160 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Wed, 20 Jul 2022 16:14:55 +0800 Subject: [PATCH 30/45] test: restore 2.0 case --- tests/script/jenkins/basic.txt | 14 +- tests/script/tsim/parser/fill.sim | 126 ++++++++---------- tests/script/tsim/parser/fill_stb.sim | 3 +- tests/script/tsim/parser/fill_us.sim | 63 ++++----- tests/script/tsim/parser/first_last.sim | 6 +- tests/script/tsim/parser/first_last_query.sim | 22 ++- 6 files changed, 105 insertions(+), 129 deletions(-) diff --git a/tests/script/jenkins/basic.txt b/tests/script/jenkins/basic.txt index 98c5251ac5..655462d1cf 100644 --- a/tests/script/jenkins/basic.txt +++ b/tests/script/jenkins/basic.txt @@ -83,13 +83,13 @@ ./test.sh -f tsim/insert/update0.sim # ---- parser -./test.sh -f tsim/parser/alter.sim -# nojira ./test.sh -f tsim/parser/alter1.sim ./test.sh -f tsim/parser/alter__for_community_version.sim ./test.sh -f tsim/parser/alter_column.sim ./test.sh -f tsim/parser/alter_stable.sim -# jira ./test.sh -f tsim/parser/auto_create_tb.sim +./test.sh -f tsim/parser/alter.sim +# nojira ./test.sh -f tsim/parser/alter1.sim ./test.sh -f tsim/parser/auto_create_tb_drop_tb.sim +# jira ./test.sh -f tsim/parser/auto_create_tb.sim ./test.sh -f tsim/parser/between_and.sim ./test.sh -f tsim/parser/binary_escapeCharacter.sim # nojira ./test.sh -f tsim/parser/col_arithmetic_operation.sim @@ -104,10 +104,10 @@ ## ./test.sh -f tsim/parser/create_tb_with_tag_name.sim # ./test.sh -f tsim/parser/dbtbnameValidate.sim ##./test.sh -f tsim/parser/distinct.sim -# ./test.sh -f tsim/parser/fill.sim -# ./test.sh -f tsim/parser/fill_stb.sim -## ./test.sh -f tsim/parser/fill_us.sim -# ./test.sh -f tsim/parser/first_last.sim +./test.sh -f tsim/parser/fill_stb.sim +./test.sh -f tsim/parser/fill_us.sim +./test.sh -f tsim/parser/fill.sim +./test.sh -f tsim/parser/first_last.sim ./test.sh -f tsim/parser/fourArithmetic-basic.sim ## ./test.sh -f tsim/parser/function.sim ./test.sh -f tsim/parser/groupby-basic.sim diff --git a/tests/script/tsim/parser/fill.sim b/tests/script/tsim/parser/fill.sim index 642c7bd8d4..698314fa36 100644 --- a/tests/script/tsim/parser/fill.sim +++ b/tests/script/tsim/parser/fill.sim @@ -47,7 +47,7 @@ $tsu = $tsu + $ts0 ## fill syntax test # number of fill values exceeds number of selected columns -sql select max(c1), max(c2), max(c3), max(c4), max(c5) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, 6, 6, 6, 6, 6, 6, 6, 6) +sql select _wstart, max(c1), max(c2), max(c3), max(c4), max(c5) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, 6, 6, 6, 6, 6, 6, 6, 6) if $data11 != 6 then return -1 endi @@ -62,7 +62,7 @@ if $data14 != 6.000000000 then endi # number of fill values is smaller than number of selected columns -sql select max(c1), max(c2), max(c3) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, 6, 6) +sql select _wstart, max(c1), max(c2), max(c3) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, 6, 6) if $data11 != 6 then return -1 endi @@ -74,7 +74,7 @@ if $data13 != 6.00000 then endi # unspecified filling method -sql_error select max(c1), max(c2), max(c3), max(c4), max(c5) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill (6, 6, 6, 6, 6) +sql_error select _wstart, max(c1), max(c2), max(c3), max(c4), max(c5) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill (6, 6, 6, 6, 6) ## constant fill test # count_with_fill @@ -114,7 +114,7 @@ endi # avg_with_fill print avg_with_constant_fill -sql select avg(c1), avg(c2), avg(c3), avg(c4), avg(c5) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, 6, 6, 6, 6, 6) +sql select _wstart, avg(c1), avg(c2), avg(c3), avg(c4), avg(c5) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, 6, 6, 6, 6, 6) if $rows != 9 then return -1 endi @@ -148,7 +148,7 @@ endi # max_with_fill print max_with_fill -sql select max(c1), max(c2), max(c3), max(c4), max(c5) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, 6, 6, 6, 6, 6) +sql select _wstart, max(c1), max(c2), max(c3), max(c4), max(c5) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, 6, 6, 6, 6, 6) if $rows != 9 then return -1 endi @@ -182,7 +182,7 @@ endi # min_with_fill print min_with_fill -sql select min(c1), min(c2), min(c3), min(c4), min(c5) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, 6, 6, 6, 6, 6, 6, 6, 6) +sql select _wstart, min(c1), min(c2), min(c3), min(c4), min(c5) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, 6, 6, 6, 6, 6, 6, 6, 6) if $rows != 9 then return -1 endi @@ -216,7 +216,7 @@ endi # first_with_fill print first_with_fill -sql select first(c1), first(c2), first(c3), first(c4), first(c5), first(c6), first(c7), first(c8) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, 6, 6, 6, 6, 6, 6, 6, 6) +sql select _wstart, first(c1), first(c2), first(c3), first(c4), first(c5), first(c6), first(c7), first(c8) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, 6, 6, 6, 6, 6, 6, 6, 6) if $rows != 9 then return -1 endi @@ -305,7 +305,7 @@ endi # last_with_fill print last_with_fill -sql select last(c1), last(c2), last(c3), last(c4), last(c5), last(c6), last(c7), last(c8) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, 6, 6, 6, 6, 6, 6, 6, 6) +sql select _wstart, last(c1), last(c2), last(c3), last(c4), last(c5), last(c6), last(c7), last(c8) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, 6, 6, 6, 6, 6, 6, 6, 6) if $rows != 9 then return -1 endi @@ -339,7 +339,7 @@ if $data81 != 4 then endi # fill_negative_values -sql select sum(c1), avg(c2), max(c3), min(c4), count(c5), count(c6), count(c7), count(c8) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, -1, -1, -1, -1, -1, -1, -1, -1) +sql select _wstart, sum(c1), avg(c2), max(c3), min(c4), count(c5), count(c6), count(c7), count(c8) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, -1, -1, -1, -1, -1, -1, -1, -1) if $rows != 9 then return -1 endi @@ -351,11 +351,11 @@ if $data11 != -1 then endi # fill_char_values_to_arithmetic_fields -sql_error select sum(c1), avg(c2), max(c3), min(c4), avg(c4), count(c6), last(c7), last(c8) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c') +sql select sum(c1), avg(c2), max(c3), min(c4), avg(c4), count(c6), last(c7), last(c8) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c') # fill_multiple_columns sql_error select sum(c1), avg(c2), min(c3), max(c4), count(c6), first(c7), last(c8) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, 99, 99, 99, 99, 99, abc, abc) -sql select sum(c1), avg(c2), min(c3), max(c4) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, 99, 99, 99, 99) +sql select _wstart, sum(c1), avg(c2), min(c3), max(c4) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, 99, 99, 99, 99) if $rows != 9 then return -1 endi @@ -375,9 +375,12 @@ if $data08 != NCHAR then endi # fill_into_nonarithmetic_fieds -sql select first(c6), first(c7), first(c8) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, 20000000, 20000000, 20000000) -#if $data11 != 20000000 then -if $data11 != 1 then +print select _wstart, first(c6), first(c7), first(c8) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, 20000000, 20000000, 20000000) +sql select _wstart, first(c6), first(c7), first(c8) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, 20000000, 20000000, 20000000) +if $data01 != 1 then + return -1 +endi +if $data11 != NULL then return -1 endi @@ -387,48 +390,39 @@ sql select first(c6), first(c7), first(c8) from $tb where ts >= $ts0 and ts <= $ sql select first(c7), first(c8) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, '1e', '1e1') # fill quoted values into bool column will throw error unless the value is 'true' or 'false' Note:2018-10-24 # fill values into binary or nchar columns will be set to NULL automatically Note:2018-10-24 -sql_error select first(c6), first(c7), first(c8) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, '1e', '1e1','1e1') +sql select first(c6), first(c7), first(c8) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, '1e', '1e1','1e1') sql select first(c6), first(c7), first(c8) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, true, true, true) sql select first(c6), first(c7), first(c8) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, 'true', 'true','true') # fill nonarithmetic values into arithmetic fields sql_error select count(*) where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, abc); -sql_error select count(*) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, 'true'); +sql select count(*) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, 'true'); -sql select count(*) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, '1e1'); +print select _wstart, count(*) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, '1e1'); +sql select _wstart, count(*) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, '1e1'); if $rows != 9 then return -1 endi if $data01 != 1 then return -1 endi -if $data11 != 10 then - return -1 -endi -sql select count(*) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, 1e1); +sql select _wstart, count(*) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, 1e1); if $rows != 9 then return -1 endi if $data01 != 1 then return -1 endi -if $data11 != 10 then - return -1 -endi -sql select count(*) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, '10'); +sql select _wstart, count(*) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, '10'); if $rows != 9 then return -1 endi if $data01 != 1 then return -1 endi -if $data11 != 10 then - return -1 -endi - ## linear fill # feature currently switched off 2018/09/29 @@ -436,7 +430,7 @@ endi ## previous fill print fill(prev) -sql select count(c1), count(c2), count(c3), count(c4), count(c5), count(c6), count(c7), count(c8) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(prev) +sql select _wstart, count(c1), count(c2), count(c3), count(c4), count(c5), count(c6), count(c7), count(c8) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(prev) if $rows != 9 then return -1 endi @@ -469,7 +463,7 @@ if $data81 != 1 then endi # avg_with_fill -sql select avg(c1), avg(c2), avg(c3), avg(c4), avg(c5) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(prev) +sql select _wstart, avg(c1), avg(c2), avg(c3), avg(c4), avg(c5) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(prev) if $rows != 9 then return -1 endi @@ -502,7 +496,7 @@ if $data81 != 4.000000000 then endi # max_with_fill -sql select max(c1), max(c2), max(c3), max(c4), max(c5) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(prev) +sql select _wstart, max(c1), max(c2), max(c3), max(c4), max(c5) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(prev) if $rows != 9 then return -1 endi @@ -535,7 +529,7 @@ if $data81 != 4 then endi # min_with_fill -sql select min(c1), min(c2), min(c3), min(c4), min(c5) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(prev) +sql select _wstart, min(c1), min(c2), min(c3), min(c4), min(c5) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(prev) if $rows != 9 then return -1 endi @@ -568,7 +562,7 @@ if $data81 != 4 then endi # first_with_fill -sql select first(c1), first(c2), first(c3), first(c4), first(c5), first(c6), first(c7), first(c8) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(prev) +sql select _wstart, first(c1), first(c2), first(c3), first(c4), first(c5), first(c6), first(c7), first(c8) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(prev) if $rows != 9 then return -1 endi @@ -601,7 +595,7 @@ if $data81 != 4 then endi # last_with_fill -sql select last(c1), last(c2), last(c3), last(c4), last(c5), last(c6), last(c7), last(c8) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(prev) +sql select _wstart, last(c1), last(c2), last(c3), last(c4), last(c5), last(c6), last(c7), last(c8) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(prev) if $rows != 9 then return -1 endi @@ -636,9 +630,9 @@ endi ## NULL fill print fill(value, NULL) # count_with_fill -sql select count(c1), count(c2), count(c3), count(c4), count(c5), count(c6), count(c7), count(c8) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill( NULL) -print select count(c1), count(c2), count(c3), count(c4), count(c5), count(c6), count(c7), count(c8) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill( NULL) -sql select count(c1), count(c2), count(c3), count(c4), count(c5), count(c6), count(c7), count(c8) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, NULL) +sql select _wstart, count(c1), count(c2), count(c3), count(c4), count(c5), count(c6), count(c7), count(c8) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill( NULL) +print select _wstart, count(c1), count(c2), count(c3), count(c4), count(c5), count(c6), count(c7), count(c8) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill( NULL) +sql select _wstart, count(c1), count(c2), count(c3), count(c4), count(c5), count(c6), count(c7), count(c8) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(NULL) if $rows != 9 then return -1 endi @@ -669,13 +663,13 @@ endi if $data81 != 1 then return -1 endi -sql select count(c1), count(c2), count(c3), count(c4), count(c5), count(c6), count(c7), count(c8) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(none) +sql select _wstart, count(c1), count(c2), count(c3), count(c4), count(c5), count(c6), count(c7), count(c8) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(none) if $rows != 5 then return -1 endi # avg_with_fill -sql select avg(c1), avg(c2), avg(c3), avg(c4), avg(c5) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, NULL) +sql select _wstart, avg(c1), avg(c2), avg(c3), avg(c4), avg(c5) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill( NULL) if $rows != 9 then return -1 endi @@ -708,7 +702,7 @@ if $data81 != 4.000000000 then endi # max_with_fill -sql select max(c1), max(c2), max(c3), max(c4), max(c5) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, NULL) +sql select _wstart, max(c1), max(c2), max(c3), max(c4), max(c5) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(NULL) if $rows != 9 then return -1 endi @@ -741,7 +735,7 @@ if $data81 != 4 then endi # min_with_fill -sql select min(c1), min(c2), min(c3), min(c4), min(c5) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, NULL) +sql select _wstart, min(c1), min(c2), min(c3), min(c4), min(c5) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill( NULL) if $rows != 9 then return -1 endi @@ -774,7 +768,7 @@ if $data81 != 4 then endi # first_with_fill -sql select first(c1), first(c2), first(c3), first(c4), first(c5), first(c6), first(c7), first(c8) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, NULL) +sql select _wstart, first(c1), first(c2), first(c3), first(c4), first(c5), first(c6), first(c7), first(c8) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill( NULL) if $rows != 9 then return -1 endi @@ -807,7 +801,7 @@ if $data81 != 4 then endi # last_with_fill -sql select last(c1), last(c2), last(c3), last(c4), last(c5), last(c6), last(c7), last(c8) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, NULL) +sql select _wstart, last(c1), last(c2), last(c3), last(c4), last(c5), last(c6), last(c7), last(c8) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill( NULL) if $rows != 9 then return -1 endi @@ -841,7 +835,7 @@ endi # desc fill query print desc fill query -sql select count(*) from m_fl_tb0 where ts>='2018-9-17 9:0:0' and ts<='2018-9-17 9:11:00' interval(1m) fill(value,10) order by ts desc; +sql select count(*) from m_fl_tb0 where ts>='2018-9-17 9:0:0' and ts<='2018-9-17 9:11:00' interval(1m) fill(value,10); if $rows != 12 then return -1 endi @@ -865,7 +859,8 @@ sql insert into tm0 values('2020-1-1 1:3:8', 8); sql insert into tm0 values('2020-1-1 1:3:9', 9); sql insert into tm0 values('2020-1-1 1:4:10', 10); -sql select max(k)-min(k),last(k)-first(k),0-spread(k) from tm0 where ts>='2020-1-1 1:1:1' and ts<='2020-1-1 1:2:15' interval(10s) fill(value, 99,91,90,89,88,87,86,85); +print select _wstart, max(k)-min(k),last(k)-first(k),0-spread(k) from tm0 where ts>='2020-1-1 1:1:1' and ts<='2020-1-1 1:2:15' interval(10s) fill(value, 99,91,90,89,88,87,86,85); +sql select _wstart, max(k)-min(k),last(k)-first(k),0-spread(k) from tm0 where ts>='2020-1-1 1:1:1' and ts<='2020-1-1 1:2:15' interval(10s) fill(value, 99,91,90,89,88,87,86,85); if $rows != 8 then return -1 endi @@ -890,15 +885,15 @@ if $data10 != @20-01-01 01:01:10.000@ then return -1 endi -if $data11 != 99.000000000 then +if $data11 != 1.000000000 then return -1 endi -if $data12 != 91.000000000 then +if $data12 != 1.000000000 then return -1 endi -if $data13 != 90.000000000 then +if $data13 != -87.000000000 then return -1 endi @@ -922,19 +917,19 @@ if $data70 != @20-01-01 01:02:10.000@ then return -1 endi -if $data71 != 99.000000000 then +if $data71 != 1.000000000 then return -1 endi -if $data72 != 91.000000000 then +if $data72 != 1.000000000 then return -1 endi -if $data73 != 90.000000000 then +if $data73 != -87.000000000 then return -1 endi -sql select first(k)-avg(k),0-spread(k) from tm0 where ts>='2020-1-1 1:1:1' and ts<='2020-1-1 1:2:15' interval(10s) fill(NULL); +sql select _wstart, first(k)-avg(k),0-spread(k) from tm0 where ts>='2020-1-1 1:1:1' and ts<='2020-1-1 1:2:15' interval(10s) fill(NULL); if $rows != 8 then return -1 endi @@ -963,12 +958,13 @@ if $data12 != NULL then return -1 endi -sql select max(k)-min(k),last(k)-first(k),0-spread(k) from tm0 where ts>='2020-1-1 1:1:1' and ts<='2020-1-1 4:2:15' interval(500a) fill(value, 99,91,90,89,88,87,86,85) order by ts asc; +sql select _wstart, max(k)-min(k),last(k)-first(k),0-spread(k) from tm0 where ts>='2020-1-1 1:1:1' and ts<='2020-1-1 4:2:15' interval(500a) fill(value, 99,91,90,89,88,87,86,85) ; if $rows != 21749 then return -1 endi -sql select max(k)-min(k),last(k)-first(k),0-spread(k),count(1) from m1 where ts>='2020-1-1 1:1:1' and ts<='2020-1-1 1:2:15' interval(10s) fill(value, 99,91,90,89,88,87,86,85) order by ts asc; +print select _wstart, max(k)-min(k),last(k)-first(k),0-spread(k),count(1) from m1 where ts>='2020-1-1 1:1:1' and ts<='2020-1-1 1:2:15' interval(10s) fill(value, 99,91,90,89,88,87,86,85) ; +sql select _wstart, max(k)-min(k),last(k)-first(k),0-spread(k),count(1) from m1 where ts>='2020-1-1 1:1:1' and ts<='2020-1-1 1:2:15' interval(10s) fill(value, 99,91,90,89,88,87,86,85) ; if $rows != 8 then return -1 endi @@ -997,19 +993,19 @@ if $data10 != @20-01-01 01:01:10.000@ then return -1 endi -if $data11 != 99.000000000 then +if $data11 != 1.000000000 then return -1 endi -if $data12 != 91.000000000 then +if $data12 != 1.000000000 then return -1 endi -if $data13 != 90.000000000 then +if $data13 != -87.000000000 then return -1 endi -if $data14 != 89 then +if $data14 != 86 then return -1 endi @@ -1026,18 +1022,15 @@ endi if $data01 != -4.000000000 then return -1 endi - -if $data02 != 0 then +if $data10 != 5 then return -1 endi - -if $data12 != 1 then +if $data11 != -4.000000000 then return -1 endi print =====================>td-1442, td-2190 , no time range for fill option sql_error select count(*) from m_fl_tb0 interval(1s) fill(prev); - sql_error select min(c3) from m_fl_mt0 interval(10a) fill(value, 20) sql_error select min(c3) from m_fl_mt0 interval(10s) fill(value, 20) sql_error select min(c3) from m_fl_mt0 interval(10m) fill(value, 20) @@ -1051,7 +1044,7 @@ sql create table nexttb1 (ts timestamp, f1 int); sql insert into nexttb1 values ('2021-08-08 1:1:1', NULL); sql insert into nexttb1 values ('2021-08-08 1:1:5', 3); -sql select last(*) from nexttb1 where ts >= '2021-08-08 1:1:1' and ts < '2021-08-08 1:1:10' interval(1s) fill(next); +sql select _wstart, last(*) from nexttb1 where ts >= '2021-08-08 1:1:1' and ts < '2021-08-08 1:1:10' interval(1s) fill(next); if $rows != 9 then return -1 endi @@ -1065,9 +1058,6 @@ if $data02 != 3 then return -1 endi - - - print =============== clear #sql drop database $db #sql show databases diff --git a/tests/script/tsim/parser/fill_stb.sim b/tests/script/tsim/parser/fill_stb.sim index 0aadcc5a9f..5493843993 100644 --- a/tests/script/tsim/parser/fill_stb.sim +++ b/tests/script/tsim/parser/fill_stb.sim @@ -97,7 +97,8 @@ $tsu = $tsu + $ts0 #endi # number of fill values exceeds number of selected columns -sql select max(c1), max(c2), max(c3), max(c4), max(c5) from $stb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, -1, -2, -3, -4, -5, -6, -7, -8) +print select count(ts), max(c1), max(c2), max(c3), max(c4), max(c5) from $stb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, -1, -2, -3, -4, -5, -6, -7, -8) +sql select count(ts), max(c1), max(c2), max(c3), max(c4), max(c5) from $stb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, -1, -2, -3, -4, -5, -6, -7, -8) $val = $rowNum * 2 $val = $val - 1 if $rows != $val then diff --git a/tests/script/tsim/parser/fill_us.sim b/tests/script/tsim/parser/fill_us.sim index 98c37c435d..82d282642e 100644 --- a/tests/script/tsim/parser/fill_us.sim +++ b/tests/script/tsim/parser/fill_us.sim @@ -47,8 +47,8 @@ $tsu = $tsu + $ts0 ## fill syntax test # number of fill values exceeds number of selected columns -print select max(c1), max(c2), max(c3), max(c4), max(c5) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, 6, 6, 6, 6, 6, 6, 6, 6) -sql select max(c1), max(c2), max(c3), max(c4), max(c5) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, 6, 6, 6, 6, 6, 6, 6, 6) +print select _wstart, max(c1), max(c2), max(c3), max(c4), max(c5) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, 6, 6, 6, 6, 6, 6, 6, 6) +sql select _wstart, max(c1), max(c2), max(c3), max(c4), max(c5) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, 6, 6, 6, 6, 6, 6, 6, 6) if $data11 != 6 then return -1 endi @@ -63,8 +63,8 @@ if $data14 != 6.000000000 then endi # number of fill values is smaller than number of selected columns -print sql select max(c1), max(c2), max(c3) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, 6, 6) -sql select max(c1), max(c2), max(c3) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, 6, 6) +print sql select _wstart, max(c1), max(c2), max(c3) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, 6, 6) +sql select _wstart, max(c1), max(c2), max(c3) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, 6, 6) if $data11 != 6 then return -1 endi @@ -219,7 +219,7 @@ endi # first_with_fill print first_with_fill -sql select first(c1), first(c2), first(c3), first(c4), first(c5), first(c6), first(c7), first(c8) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, 6, 6, 6, 6, 6, 6, 6, 6) +sql select _wstart, first(c1), first(c2), first(c3), first(c4), first(c5), first(c6), first(c7), first(c8) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, 6, 6, 6, 6, 6, 6, 6, 6) if $rows != 9 then return -1 endi @@ -341,7 +341,7 @@ if $data81 != 4 then endi # fill_negative_values -sql select sum(c1), avg(c2), max(c3), min(c4), count(c5), count(c6), count(c7), count(c8) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, -1, -1, -1, -1, -1, -1, -1, -1) +sql select _wstart, sum(c1), avg(c2), max(c3), min(c4), count(c5), count(c6), count(c7), count(c8) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, -1, -1, -1, -1, -1, -1, -1, -1) if $rows != 9 then return -1 endi @@ -353,11 +353,11 @@ if $data11 != -1 then endi # fill_char_values_to_arithmetic_fields -sql_error select sum(c1), avg(c2), max(c3), min(c4), avg(c4), count(c6), last(c7), last(c8) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c') +sql select sum(c1), avg(c2), max(c3), min(c4), avg(c4), count(c6), last(c7), last(c8) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c') # fill_multiple_columns -sql_error select sum(c1), avg(c2), min(c3), max(c4), count(c6), first(c7), last(c8) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, 99, 99, 99, 99, 99, abc, abc) -sql select sum(c1), avg(c2), min(c3), max(c4) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, 99, 99, 99, 99) +sql_error select _wstart, sum(c1), avg(c2), min(c3), max(c4), count(c6), first(c7), last(c8) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, 99, 99, 99, 99, 99, abc, abc) +sql select _wstart, sum(c1), avg(c2), min(c3), max(c4) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, 99, 99, 99, 99) if $rows != 9 then return -1 endi @@ -379,9 +379,9 @@ endi # fill_into_nonarithmetic_fieds -sql select first(c6), first(c7), first(c8) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, 20000000, 20000000, 20000000) +sql select _wstart, first(c6), first(c7), first(c8) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, 20000000, 20000000, 20000000) #if $data11 != 20000000 then -if $data11 != 1 then +if $data11 != NULL then return -1 endi @@ -391,47 +391,38 @@ sql select first(c6), first(c7), first(c8) from $tb where ts >= $ts0 and ts <= $ sql select first(c7), first(c8) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, '1e', '1e1') # fill quoted values into bool column will throw error unless the value is 'true' or 'false' Note:2018-10-24 # fill values into binary or nchar columns will be set to null automatically Note:2018-10-24 -sql_error select first(c6), first(c7), first(c8) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, '1e', '1e1','1e1') +sql select first(c6), first(c7), first(c8) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, '1e', '1e1','1e1') sql select first(c6), first(c7), first(c8) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, true, true, true) sql select first(c6), first(c7), first(c8) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, 'true', 'true','true') # fill nonarithmetic values into arithmetic fields sql_error select count(*) where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, abc); -sql_error select count(*) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, 'true'); +sql select count(*) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, 'true'); -sql select count(*) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, '1e1'); +sql select _wstart, count(*) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, '1e1'); if $rows != 9 then return -1 endi if $data01 != 1 then return -1 endi -if $data11 != 10 then - return -1 -endi -sql select count(*) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, 1e1); +sql select _wstart, count(*) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, 1e1); if $rows != 9 then return -1 endi if $data01 != 1 then return -1 endi -if $data11 != 10 then - return -1 -endi -sql select count(*) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, '10'); +sql select _wstart, count(*) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, '10'); if $rows != 9 then return -1 endi if $data01 != 1 then return -1 endi -if $data11 != 10 then - return -1 -endi ## linear fill @@ -440,7 +431,7 @@ endi ## previous fill print fill(prev) -sql select count(c1), count(c2), count(c3), count(c4), count(c5), count(c6), count(c7), count(c8) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(prev) +sql select _wstart, count(c1), count(c2), count(c3), count(c4), count(c5), count(c6), count(c7), count(c8) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(prev) if $rows != 9 then return -1 endi @@ -473,7 +464,7 @@ if $data81 != 1 then endi # avg_with_fill -sql select avg(c1), avg(c2), avg(c3), avg(c4), avg(c5) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(prev) +sql select _wstart, avg(c1), avg(c2), avg(c3), avg(c4), avg(c5) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(prev) if $rows != 9 then return -1 endi @@ -641,8 +632,8 @@ endi print fill(value, NULL) # count_with_fill sql select count(c1), count(c2), count(c3), count(c4), count(c5), count(c6), count(c7), count(c8) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill( NULL) -print select count(c1), count(c2), count(c3), count(c4), count(c5), count(c6), count(c7), count(c8) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill( NULL) -sql select count(c1), count(c2), count(c3), count(c4), count(c5), count(c6), count(c7), count(c8) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, NULL) +print select _wstart, count(c1), count(c2), count(c3), count(c4), count(c5), count(c6), count(c7), count(c8) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill( NULL) +sql select _wstart, count(c1), count(c2), count(c3), count(c4), count(c5), count(c6), count(c7), count(c8) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(NULL) if $rows != 9 then return -1 endi @@ -679,7 +670,7 @@ if $rows != 5 then endi # avg_with_fill -sql select avg(c1), avg(c2), avg(c3), avg(c4), avg(c5) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, NULL) +sql select _wstart, avg(c1), avg(c2), avg(c3), avg(c4), avg(c5) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill( NULL) if $rows != 9 then return -1 endi @@ -712,7 +703,7 @@ if $data81 != 4.000000000 then endi # max_with_fill -sql select max(c1), max(c2), max(c3), max(c4), max(c5) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, NULL) +sql select _wstart, max(c1), max(c2), max(c3), max(c4), max(c5) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill( NULL) if $rows != 9 then return -1 endi @@ -745,7 +736,7 @@ if $data81 != 4 then endi # min_with_fill -sql select min(c1), min(c2), min(c3), min(c4), min(c5) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, NULL) +sql select _wstart, min(c1), min(c2), min(c3), min(c4), min(c5) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(NULL) if $rows != 9 then return -1 endi @@ -778,7 +769,7 @@ if $data81 != 4 then endi # first_with_fill -sql select first(c1), first(c2), first(c3), first(c4), first(c5), first(c6), first(c7), first(c8) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, NULL) +sql select _wstart, first(c1), first(c2), first(c3), first(c4), first(c5), first(c6), first(c7), first(c8) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill( NULL) if $rows != 9 then return -1 endi @@ -811,7 +802,7 @@ if $data81 != 4 then endi # last_with_fill -sql select last(c1), last(c2), last(c3), last(c4), last(c5), last(c6), last(c7), last(c8) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, NULL) +sql select _wstart, last(c1), last(c2), last(c3), last(c4), last(c5), last(c6), last(c7), last(c8) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(NULL) if $rows != 9 then return -1 endi @@ -845,7 +836,7 @@ endi # desc fill query print desc fill query -sql select count(*) from m_fl_tb0 where ts>='2018-9-17 9:0:0' and ts<='2018-9-17 9:11:00' interval(1m) fill(value,10) order by ts desc; +sql select count(*) from m_fl_tb0 where ts>='2018-9-17 9:0:0' and ts<='2018-9-17 9:11:00' interval(1m) fill(value,10); if $rows != 12 then return -1 endi @@ -1002,7 +993,7 @@ if $data71 != 21.000000000 then return -1 endi -sql select avg(c1), avg(c2) from us_t1 where ts >= '2018-09-17 09:00:00.000002' and ts <= '2018-09-17 09:00:00.000021' interval(3u) fill(linear) +sql select _wstart, avg(c1), avg(c2) from us_t1 where ts >= '2018-09-17 09:00:00.000002' and ts <= '2018-09-17 09:00:00.000021' interval(3u) fill(linear) if $rows != 8 then return -1 endi diff --git a/tests/script/tsim/parser/first_last.sim b/tests/script/tsim/parser/first_last.sim index 27bf42ead3..4f1dcb12fe 100644 --- a/tests/script/tsim/parser/first_last.sim +++ b/tests/script/tsim/parser/first_last.sim @@ -19,7 +19,7 @@ $stb = $stbPrefix . $i sql drop database $db -x step1 step1: -sql create database $db maxrows 400 cache 1 +sql create database $db maxrows 400 sql use $db sql create table $stb (ts timestamp, c1 int, c2 bigint, c3 float, c4 double, c5 smallint, c6 tinyint, c7 bool, c8 binary(10), c9 nchar(10)) tags(t1 int) @@ -73,11 +73,9 @@ run tsim/parser/first_last_query.sim 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 connect -sleep 100 run tsim/parser/first_last_query.sim @@ -102,11 +100,9 @@ while $x < 5000 endw system sh/exec.sh -n dnode1 -s stop -x SIGINT -sleep 1000 system sh/exec.sh -n dnode1 -s start print ================== server restart completed sql connect -sleep 100 sql use test sql select count(*), last(ts) from tm0 interval(1s) diff --git a/tests/script/tsim/parser/first_last_query.sim b/tests/script/tsim/parser/first_last_query.sim index 2dff1dd51b..c52a5b45d6 100644 --- a/tests/script/tsim/parser/first_last_query.sim +++ b/tests/script/tsim/parser/first_last_query.sim @@ -109,7 +109,7 @@ endi ### test if first works for committed data. An 'order by ts desc' clause should be present, and queried data should come from at least 2 file blocks $tb = $tbPrefix . 9 -sql select first(ts), first(c1) from $tb where ts < '2018-10-17 10:00:00.000' order by ts asc +sql select first(ts), first(c1) from $tb where ts < '2018-10-17 10:00:00.000' if $rows != 1 then return -1 endi @@ -121,7 +121,7 @@ if $data01 != 0 then endi $tb = $tbPrefix . 9 -sql select first(ts), first(c1) from $tb where ts < '2018-10-17 10:00:00.000' order by ts desc +sql select first(ts), first(c1) from $tb where ts < '2018-10-17 10:00:00.000' if $rows != 1 then return -1 endi @@ -154,7 +154,7 @@ sql insert into test11 using stest tags('test11','bbb') values ('2020-09-04 16:5 sql insert into test12 using stest tags('test11','bbb') values ('2020-09-04 16:53:58.003',210,3); sql insert into test21 using stest tags('test21','ccc') values ('2020-09-04 16:53:59.003',210,3); sql insert into test22 using stest tags('test21','ccc') values ('2020-09-04 16:54:54.003',210,3); -sql select sum(size) from stest group by appname; +sql select sum(size), appname from stest group by appname order by appname;; if $rows != 3 then return -1 endi @@ -170,16 +170,16 @@ if $data20 != 420 then endi if $data01 != @test1@ then -return -1 + return -1 endi if $data11 != @test11@ then -return -1 + return -1 endi if $data21 != @test21@ then -return -1 + return -1 endi -sql select sum(size) from stest interval(1d) group by appname; +sql select _wstart, sum(size), appname from stest partition by appname interval(1d) order by appname; if $rows != 3 then return -1 endi @@ -223,7 +223,7 @@ return -1 endi print ===================>td-1477, one table has only one block occurs this bug. -sql select first(size),count(*),LAST(SIZE) from stest where tbname in ('test1', 'test2') interval(1d) group by tbname; +sql select _wstart, first(size), count(*), LAST(SIZE), tbname from stest where tbname in ('test1', 'test2') partition by tbname interval(1d) ; if $rows != 2 then return -1 endi @@ -278,15 +278,13 @@ sql create table tm1 using m1 tags(2); sql insert into tm0 values('2020-3-1 1:1:1', 112); sql insert into tm1 values('2020-1-1 1:1:1', 1)('2020-3-1 0:1:1', 421); system sh/exec.sh -n dnode1 -s stop -x SIGINT -sleep 1000 - system sh/exec.sh -n dnode1 -s start + print ================== server restart completed -sleep 1000 sql connect sql use first_db0; -sql select last(*) from m1 group by tbname; +sql select last(*), tbname from m1 group by tbname; if $rows != 2 then return -1 endi From e9c408df6ba13419c3ee0fd62da8c3a35e4a4073 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Wed, 20 Jul 2022 16:15:14 +0800 Subject: [PATCH 31/45] fix: return error on child script failed --- tests/tsim/src/simSystem.c | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/tsim/src/simSystem.c b/tests/tsim/src/simSystem.c index 1c751f290a..f2fefb903d 100644 --- a/tests/tsim/src/simSystem.c +++ b/tests/tsim/src/simSystem.c @@ -99,6 +99,7 @@ SScript *simProcessCallOver(SScript *script) { } if (simScriptPos == -1) return NULL; + if (!simExecSuccess) return NULL; return simScriptList[simScriptPos]; } else { From bf37f3fa68790431e1c58cf1d1649b3d8ab0cb86 Mon Sep 17 00:00:00 2001 From: Liu Jicong Date: Wed, 20 Jul 2022 16:15:53 +0800 Subject: [PATCH 32/45] feat(wal): remove wal log size limitation --- include/libs/wal/wal.h | 20 +++++----- include/util/tdef.h | 2 +- include/util/tutil.h | 1 - source/common/src/tglobal.c | 24 +++++------ source/common/src/tmsg.c | 2 + source/dnode/mnode/sdb/src/sdbFile.c | 9 +++-- source/libs/wal/src/walMeta.c | 60 +++++++++++++++++++--------- source/libs/wal/src/walWrite.c | 9 ----- source/util/src/tutil.c | 14 ------- 9 files changed, 72 insertions(+), 69 deletions(-) diff --git a/include/libs/wal/wal.h b/include/libs/wal/wal.h index 00a36391fa..ad89e51a24 100644 --- a/include/libs/wal/wal.h +++ b/include/libs/wal/wal.h @@ -33,16 +33,16 @@ extern "C" { #define wTrace(...) { if (wDebugFlag & DEBUG_TRACE) { taosPrintLog("WAL ", DEBUG_TRACE, wDebugFlag, __VA_ARGS__); }} // clang-format on -#define WAL_PROTO_VER 0 -#define WAL_NOSUFFIX_LEN 20 -#define WAL_SUFFIX_AT (WAL_NOSUFFIX_LEN + 1) -#define WAL_LOG_SUFFIX "log" -#define WAL_INDEX_SUFFIX "idx" -#define WAL_REFRESH_MS 1000 -#define WAL_MAX_SIZE (TSDB_MAX_WAL_SIZE + sizeof(SWalCkHead)) -#define WAL_PATH_LEN (TSDB_FILENAME_LEN + 12) -#define WAL_FILE_LEN (WAL_PATH_LEN + 32) -#define WAL_MAGIC 0xFAFBFCFDULL +#define WAL_PROTO_VER 0 +#define WAL_NOSUFFIX_LEN 20 +#define WAL_SUFFIX_AT (WAL_NOSUFFIX_LEN + 1) +#define WAL_LOG_SUFFIX "log" +#define WAL_INDEX_SUFFIX "idx" +#define WAL_REFRESH_MS 1000 +#define WAL_PATH_LEN (TSDB_FILENAME_LEN + 12) +#define WAL_FILE_LEN (WAL_PATH_LEN + 32) +#define WAL_MAGIC 0xFAFBFCFDULL +#define WAL_SCAN_BUF_SIZE (1024 * 1024 * 3) typedef enum { TAOS_WAL_WRITE = 1, diff --git a/include/util/tdef.h b/include/util/tdef.h index 3b31398063..688fe5fe85 100644 --- a/include/util/tdef.h +++ b/include/util/tdef.h @@ -421,7 +421,7 @@ typedef enum ELogicConditionType { #define TSDB_DEFAULT_STABLES_HASH_SIZE 100 #define TSDB_DEFAULT_CTABLES_HASH_SIZE 20000 -#define TSDB_MAX_WAL_SIZE (1024 * 1024 * 3) +#define TSDB_MAX_MSG_SIZE (1024 * 1024 * 10) #define TSDB_ARB_DUMMY_TIME 4765104000000 // 2121-01-01 00:00:00.000, :P diff --git a/include/util/tutil.h b/include/util/tutil.h index 2e96c5b88e..6a1a40f14c 100644 --- a/include/util/tutil.h +++ b/include/util/tutil.h @@ -45,7 +45,6 @@ void taosIp2String(uint32_t ip, char *str); void taosIpPort2String(uint32_t ip, uint16_t port, char *str); void *tmemmem(const char *haystack, int hlen, const char *needle, int nlen); -char *strDupUnquo(const char *src); static FORCE_INLINE void taosEncryptPass(uint8_t *inBuf, size_t inLen, char *target) { T_MD5_CTX context; diff --git a/source/common/src/tglobal.c b/source/common/src/tglobal.c index fcc27e440c..db8afba409 100644 --- a/source/common/src/tglobal.c +++ b/source/common/src/tglobal.c @@ -40,11 +40,11 @@ bool tsPrintAuth = false; // multi process int32_t tsMultiProcess = 0; -int32_t tsMnodeShmSize = TSDB_MAX_WAL_SIZE * 2 + 1024; -int32_t tsVnodeShmSize = TSDB_MAX_WAL_SIZE * 10 + 1024; -int32_t tsQnodeShmSize = TSDB_MAX_WAL_SIZE * 4 + 1024; -int32_t tsSnodeShmSize = TSDB_MAX_WAL_SIZE * 4 + 1024; -int32_t tsBnodeShmSize = TSDB_MAX_WAL_SIZE * 4 + 1024; +int32_t tsMnodeShmSize = TSDB_MAX_MSG_SIZE * 2 + 1024; +int32_t tsVnodeShmSize = TSDB_MAX_MSG_SIZE * 10 + 1024; +int32_t tsQnodeShmSize = TSDB_MAX_MSG_SIZE * 4 + 1024; +int32_t tsSnodeShmSize = TSDB_MAX_MSG_SIZE * 4 + 1024; +int32_t tsBnodeShmSize = TSDB_MAX_MSG_SIZE * 4 + 1024; int32_t tsNumOfShmThreads = 1; // queue & threads @@ -387,11 +387,11 @@ static int32_t taosAddServerCfg(SConfig *pCfg) { if (cfgAddBool(pCfg, "deadLockKillQuery", tsDeadLockKillQuery, 0) != 0) return -1; if (cfgAddInt32(pCfg, "multiProcess", tsMultiProcess, 0, 2, 0) != 0) return -1; - if (cfgAddInt32(pCfg, "mnodeShmSize", tsMnodeShmSize, TSDB_MAX_WAL_SIZE * 2 + 1024, INT32_MAX, 0) != 0) return -1; - if (cfgAddInt32(pCfg, "vnodeShmSize", tsVnodeShmSize, TSDB_MAX_WAL_SIZE * 2 + 1024, INT32_MAX, 0) != 0) return -1; - if (cfgAddInt32(pCfg, "qnodeShmSize", tsQnodeShmSize, TSDB_MAX_WAL_SIZE * 2 + 1024, INT32_MAX, 0) != 0) return -1; - if (cfgAddInt32(pCfg, "snodeShmSize", tsSnodeShmSize, TSDB_MAX_WAL_SIZE * 2 + 1024, INT32_MAX, 0) != 0) return -1; - if (cfgAddInt32(pCfg, "bnodeShmSize", tsBnodeShmSize, TSDB_MAX_WAL_SIZE * 2 + 1024, INT32_MAX, 0) != 0) return -1; + if (cfgAddInt32(pCfg, "mnodeShmSize", tsMnodeShmSize, TSDB_MAX_MSG_SIZE * 2 + 1024, INT32_MAX, 0) != 0) return -1; + if (cfgAddInt32(pCfg, "vnodeShmSize", tsVnodeShmSize, TSDB_MAX_MSG_SIZE * 2 + 1024, INT32_MAX, 0) != 0) return -1; + if (cfgAddInt32(pCfg, "qnodeShmSize", tsQnodeShmSize, TSDB_MAX_MSG_SIZE * 2 + 1024, INT32_MAX, 0) != 0) return -1; + if (cfgAddInt32(pCfg, "snodeShmSize", tsSnodeShmSize, TSDB_MAX_MSG_SIZE * 2 + 1024, INT32_MAX, 0) != 0) return -1; + if (cfgAddInt32(pCfg, "bnodeShmSize", tsBnodeShmSize, TSDB_MAX_MSG_SIZE * 2 + 1024, INT32_MAX, 0) != 0) return -1; if (cfgAddInt32(pCfg, "mumOfShmThreads", tsNumOfShmThreads, 1, 1024, 0) != 0) return -1; tsNumOfRpcThreads = tsNumOfCores / 2; @@ -447,8 +447,8 @@ static int32_t taosAddServerCfg(SConfig *pCfg) { if (cfgAddInt32(pCfg, "numOfSnodeUniqueThreads", tsNumOfSnodeUniqueThreads, 1, 1024, 0) != 0) return -1; tsRpcQueueMemoryAllowed = tsTotalMemoryKB * 1024 * 0.1; - tsRpcQueueMemoryAllowed = TRANGE(tsRpcQueueMemoryAllowed, TSDB_MAX_WAL_SIZE * 10L, TSDB_MAX_WAL_SIZE * 10000L); - if (cfgAddInt64(pCfg, "rpcQueueMemoryAllowed", tsRpcQueueMemoryAllowed, TSDB_MAX_WAL_SIZE * 10L, INT64_MAX, 0) != 0) + tsRpcQueueMemoryAllowed = TRANGE(tsRpcQueueMemoryAllowed, TSDB_MAX_MSG_SIZE * 10L, TSDB_MAX_MSG_SIZE * 10000L); + if (cfgAddInt64(pCfg, "rpcQueueMemoryAllowed", tsRpcQueueMemoryAllowed, TSDB_MAX_MSG_SIZE * 10L, INT64_MAX, 0) != 0) return -1; if (cfgAddBool(pCfg, "monitor", tsEnableMonitor, 0) != 0) return -1; diff --git a/source/common/src/tmsg.c b/source/common/src/tmsg.c index b79c412914..2a4ad04c63 100644 --- a/source/common/src/tmsg.c +++ b/source/common/src/tmsg.c @@ -5342,6 +5342,7 @@ int32_t tEncodeSVAlterTbReq(SEncoder *pEncoder, const SVAlterTbReq *pReq) { if (tEncodeCStr(pEncoder, pReq->tbName) < 0) return -1; if (tEncodeI8(pEncoder, pReq->action) < 0) return -1; + if (tEncodeI32(pEncoder, pReq->colId) < 0) return -1; switch (pReq->action) { case TSDB_ALTER_TABLE_ADD_COLUMN: if (tEncodeCStr(pEncoder, pReq->colName) < 0) return -1; @@ -5392,6 +5393,7 @@ int32_t tDecodeSVAlterTbReq(SDecoder *pDecoder, SVAlterTbReq *pReq) { if (tDecodeCStr(pDecoder, &pReq->tbName) < 0) return -1; if (tDecodeI8(pDecoder, &pReq->action) < 0) return -1; + if (tDecodeI32(pDecoder, &pReq->colId) < 0) return -1; switch (pReq->action) { case TSDB_ALTER_TABLE_ADD_COLUMN: if (tDecodeCStr(pDecoder, &pReq->colName) < 0) return -1; diff --git a/source/dnode/mnode/sdb/src/sdbFile.c b/source/dnode/mnode/sdb/src/sdbFile.c index 302f0c5fbb..00659939e9 100644 --- a/source/dnode/mnode/sdb/src/sdbFile.c +++ b/source/dnode/mnode/sdb/src/sdbFile.c @@ -231,7 +231,7 @@ static int32_t sdbReadFileImp(SSdb *pSdb) { snprintf(file, sizeof(file), "%s%ssdb.data", pSdb->currDir, TD_DIRSEP); mDebug("start to read sdb file:%s", file); - SSdbRaw *pRaw = taosMemoryMalloc(WAL_MAX_SIZE + 100); + SSdbRaw *pRaw = taosMemoryMalloc(TSDB_MAX_MSG_SIZE + 100); if (pRaw == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; mError("failed read sdb file since %s", terrstr()); @@ -556,8 +556,9 @@ int32_t sdbStartRead(SSdb *pSdb, SSdbIter **ppIter, int64_t *index, int64_t *ter if (term != NULL) *term = commitTerm; if (config != NULL) *config = commitConfig; - mDebug("sdbiter:%p, is created to read snapshot, commit index:%" PRId64 " term:%" PRId64 " config:%" PRId64 " file:%s", - pIter, commitIndex, commitTerm, commitConfig, pIter->name); + mDebug("sdbiter:%p, is created to read snapshot, commit index:%" PRId64 " term:%" PRId64 " config:%" PRId64 + " file:%s", + pIter, commitIndex, commitTerm, commitConfig, pIter->name); return 0; } @@ -669,4 +670,4 @@ int32_t sdbDoWrite(SSdb *pSdb, SSdbIter *pIter, void *pBuf, int32_t len) { pIter->total += writelen; mDebug("sdbiter:%p, write:%d bytes to snapshot, total:%" PRId64, pIter, writelen, pIter->total); return 0; -} \ No newline at end of file +} diff --git a/source/libs/wal/src/walMeta.c b/source/libs/wal/src/walMeta.c index edc811fe82..84e5a58c1a 100644 --- a/source/libs/wal/src/walMeta.c +++ b/source/libs/wal/src/walMeta.c @@ -40,7 +40,6 @@ static FORCE_INLINE int walBuildMetaName(SWal* pWal, int metaVer, char* buf) { } static FORCE_INLINE int64_t walScanLogGetLastVer(SWal* pWal) { - ASSERT(pWal->fileInfoSet != NULL); int32_t sz = taosArrayGetSize(pWal->fileInfoSet); ASSERT(sz > 0); #if 0 @@ -55,7 +54,7 @@ static FORCE_INLINE int64_t walScanLogGetLastVer(SWal* pWal) { int64_t fileSize = 0; taosStatFile(fnameStr, &fileSize, NULL); - int readSize = TMIN(WAL_MAX_SIZE + 2, fileSize); + int32_t readSize = TMIN(WAL_SCAN_BUF_SIZE, fileSize); pLastFileInfo->fileSize = fileSize; TdFilePtr pFile = taosOpenFile(fnameStr, TD_FILE_READ); @@ -73,7 +72,8 @@ static FORCE_INLINE int64_t walScanLogGetLastVer(SWal* pWal) { return -1; } - taosLSeekFile(pFile, -readSize, SEEK_END); + int64_t offset; + offset = taosLSeekFile(pFile, -readSize, SEEK_END); if (readSize != taosReadFile(pFile, buf, readSize)) { taosMemoryFree(buf); taosCloseFile(&pFile); @@ -81,29 +81,53 @@ static FORCE_INLINE int64_t walScanLogGetLastVer(SWal* pWal) { return -1; } - char* haystack = buf; char* found = NULL; - char* candidate; - while ((candidate = tmemmem(haystack, readSize - (haystack - buf), (char*)&magic, sizeof(uint64_t))) != NULL) { - // read and validate - SWalCkHead* logContent = (SWalCkHead*)candidate; - if (walValidHeadCksum(logContent) == 0 && walValidBodyCksum(logContent) == 0) { - found = candidate; + while (1) { + char* haystack = buf; + char* candidate; + while ((candidate = tmemmem(haystack, readSize - (haystack - buf), (char*)&magic, sizeof(uint64_t))) != NULL) { + // read and validate + SWalCkHead* logContent = (SWalCkHead*)candidate; + if (walValidHeadCksum(logContent) == 0 && walValidBodyCksum(logContent) == 0) { + found = candidate; + } + haystack = candidate + 1; } - haystack = candidate + 1; - } - if (found == buf) { - SWalCkHead* logContent = (SWalCkHead*)found; - if (walValidHeadCksum(logContent) != 0 || walValidBodyCksum(logContent) != 0) { - // file has to be deleted + if (found || offset == 0) break; + offset = TMIN(0, offset - readSize + 8); + int64_t offset2 = taosLSeekFile(pFile, offset, SEEK_SET); + ASSERT(offset == offset2); + if (readSize != taosReadFile(pFile, buf, readSize)) { taosMemoryFree(buf); taosCloseFile(&pFile); - terrno = TSDB_CODE_WAL_FILE_CORRUPTED; + terrno = TAOS_SYSTEM_ERROR(errno); return -1; } +#if 0 + if (found == buf) { + SWalCkHead* logContent = (SWalCkHead*)found; + if (walValidHeadCksum(logContent) != 0 || walValidBodyCksum(logContent) != 0) { + // file has to be deleted + taosMemoryFree(buf); + taosCloseFile(&pFile); + terrno = TSDB_CODE_WAL_FILE_CORRUPTED; + return -1; + } + } +#endif + } + // TODO truncate file + + if (found == NULL) { + // file corrupted, no complete log + // TODO delete and search in previous files + ASSERT(0); + terrno = TSDB_CODE_WAL_FILE_CORRUPTED; + return -1; } - taosCloseFile(&pFile); SWalCkHead* lastEntry = (SWalCkHead*)found; + taosCloseFile(&pFile); + taosMemoryFree(buf); return lastEntry->head.version; } diff --git a/source/libs/wal/src/walWrite.c b/source/libs/wal/src/walWrite.c index 4fc135a1cf..d6348cc5dd 100644 --- a/source/libs/wal/src/walWrite.c +++ b/source/libs/wal/src/walWrite.c @@ -436,11 +436,6 @@ END: } int64_t walAppendLog(SWal *pWal, tmsg_t msgType, SWalSyncInfo syncMeta, const void *body, int32_t bodyLen) { - if (bodyLen > TSDB_MAX_WAL_SIZE) { - terrno = TSDB_CODE_WAL_SIZE_LIMIT; - return -1; - } - taosThreadMutexLock(&pWal->mutex); int64_t index = pWal->vers.lastVer + 1; @@ -472,10 +467,6 @@ int32_t walWriteWithSyncInfo(SWal *pWal, int64_t index, tmsg_t msgType, SWalSync int32_t bodyLen) { int32_t code = 0; - if (bodyLen > TSDB_MAX_WAL_SIZE) { - terrno = TSDB_CODE_WAL_SIZE_LIMIT; - return -1; - } taosThreadMutexLock(&pWal->mutex); // concurrency control: diff --git a/source/util/src/tutil.c b/source/util/src/tutil.c index 7f3728e2ad..addb9f55ba 100644 --- a/source/util/src/tutil.c +++ b/source/util/src/tutil.c @@ -64,20 +64,6 @@ int32_t strdequote(char *z) { return j + 1; // only one quote, do nothing } -char *strDupUnquo(const char *src) { - if (src == NULL) return NULL; - if (src[0] != '`') return strdup(src); - int32_t len = (int32_t)strlen(src); - if (src[len - 1] != '`') return NULL; - char *ret = taosMemoryMalloc(len); - if (ret == NULL) return NULL; - for (int32_t i = 0; i < len - 1; i++) { - ret[i] = src[i + 1]; - } - ret[len - 1] = 0; - return ret; -} - size_t strtrim(char *z) { int32_t i = 0; int32_t j = 0; From 9bff316f1257c48982e33c6154b4f2ad394a371d Mon Sep 17 00:00:00 2001 From: afwerar <1296468573@qq.com> Date: Wed, 20 Jul 2022 16:19:25 +0800 Subject: [PATCH 33/45] os: fix win timestamp convert error --- source/os/src/osTime.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/os/src/osTime.c b/source/os/src/osTime.c index 0cb4228e42..3c81ba3d9f 100644 --- a/source/os/src/osTime.c +++ b/source/os/src/osTime.c @@ -371,7 +371,7 @@ time_t taosMktime(struct tm *timep) { localtime_s(&tm1, &tt); ss.wYear = tm1.tm_year + 1900; ss.wMonth = tm1.tm_mon + 1; - ss.wDay = tm1.tm_wday; + ss.wDay = tm1.tm_mday; ss.wHour = tm1.tm_hour; ss.wMinute = tm1.tm_min; ss.wSecond = tm1.tm_sec; @@ -383,7 +383,7 @@ time_t taosMktime(struct tm *timep) { s.wYear = timep->tm_year + 1900; s.wMonth = timep->tm_mon + 1; - s.wDay = timep->tm_wday; + s.wDay = timep->tm_mday; s.wHour = timep->tm_hour; s.wMinute = timep->tm_min; s.wSecond = timep->tm_sec; From b74560537cef613e234ccace9883e4e2e46a2bfc Mon Sep 17 00:00:00 2001 From: Liu Jicong Date: Wed, 20 Jul 2022 16:25:20 +0800 Subject: [PATCH 34/45] fix(stream): check task exist --- source/dnode/vnode/src/tq/tq.c | 60 ++++++++++++++++++---------------- source/libs/wal/src/walMeta.c | 2 +- 2 files changed, 32 insertions(+), 30 deletions(-) diff --git a/source/dnode/vnode/src/tq/tq.c b/source/dnode/vnode/src/tq/tq.c index f6862621f9..208b5d3fa0 100644 --- a/source/dnode/vnode/src/tq/tq.c +++ b/source/dnode/vnode/src/tq/tq.c @@ -506,7 +506,8 @@ int32_t tqProcessVgChangeReq(STQ* pTq, char* msg, int32_t msgLen) { .initTqReader = true, .version = ver, }; - pHandle->execHandle.execCol.task[i] = qCreateQueueExecTaskInfo(pHandle->execHandle.execCol.qmsg, &handle, &pHandle->execHandle.numOfCols); + pHandle->execHandle.execCol.task[i] = + qCreateQueueExecTaskInfo(pHandle->execHandle.execCol.qmsg, &handle, &pHandle->execHandle.numOfCols); ASSERT(pHandle->execHandle.execCol.task[i]); void* scanner = NULL; qExtractStreamScanner(pHandle->execHandle.execCol.task[i], &scanner); @@ -679,9 +680,9 @@ int32_t tqProcessTaskRunReq(STQ* pTq, SRpcMsg* pMsg) { // SStreamTaskRunReq* pReq = pMsg->pCont; int32_t taskId = pReq->taskId; - SStreamTask* pTask = *(SStreamTask**)taosHashGet(pTq->pStreamTasks, &taskId, sizeof(int32_t)); - if (pTask) { - streamProcessRunReq(pTask); + SStreamTask** ppTask = (SStreamTask**)taosHashGet(pTq->pStreamTasks, &taskId, sizeof(int32_t)); + if (ppTask) { + streamProcessRunReq(*ppTask); return 0; } else { return -1; @@ -696,14 +697,14 @@ int32_t tqProcessTaskDispatchReq(STQ* pTq, SRpcMsg* pMsg) { SDecoder decoder; tDecoderInit(&decoder, msgBody, msgLen); tDecodeStreamDispatchReq(&decoder, &req); - int32_t taskId = req.taskId; - SStreamTask* pTask = *(SStreamTask**)taosHashGet(pTq->pStreamTasks, &taskId, sizeof(int32_t)); - if (pTask) { + int32_t taskId = req.taskId; + SStreamTask** ppTask = (SStreamTask**)taosHashGet(pTq->pStreamTasks, &taskId, sizeof(int32_t)); + if (ppTask) { SRpcMsg rsp = { .info = pMsg->info, .code = 0, }; - streamProcessDispatchReq(pTask, &req, &rsp); + streamProcessDispatchReq(*ppTask, &req, &rsp); return 0; } else { return -1; @@ -713,9 +714,9 @@ int32_t tqProcessTaskDispatchReq(STQ* pTq, SRpcMsg* pMsg) { int32_t tqProcessTaskRecoverReq(STQ* pTq, SRpcMsg* pMsg) { SStreamTaskRecoverReq* pReq = pMsg->pCont; int32_t taskId = pReq->taskId; - SStreamTask* pTask = *(SStreamTask**)taosHashGet(pTq->pStreamTasks, &taskId, sizeof(int32_t)); - if (pTask) { - streamProcessRecoverReq(pTask, pReq, pMsg); + SStreamTask** ppTask = (SStreamTask**)taosHashGet(pTq->pStreamTasks, &taskId, sizeof(int32_t)); + if (ppTask) { + streamProcessRecoverReq(*ppTask, pReq, pMsg); return 0; } else { return -1; @@ -725,9 +726,9 @@ int32_t tqProcessTaskRecoverReq(STQ* pTq, SRpcMsg* pMsg) { int32_t tqProcessTaskDispatchRsp(STQ* pTq, SRpcMsg* pMsg) { SStreamDispatchRsp* pRsp = POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead)); int32_t taskId = pRsp->taskId; - SStreamTask* pTask = *(SStreamTask**)taosHashGet(pTq->pStreamTasks, &taskId, sizeof(int32_t)); - if (pTask) { - streamProcessDispatchRsp(pTask, pRsp); + SStreamTask** ppTask = (SStreamTask**)taosHashGet(pTq->pStreamTasks, &taskId, sizeof(int32_t)); + if (ppTask) { + streamProcessDispatchRsp(*ppTask, pRsp); return 0; } else { return -1; @@ -737,9 +738,9 @@ int32_t tqProcessTaskDispatchRsp(STQ* pTq, SRpcMsg* pMsg) { int32_t tqProcessTaskRecoverRsp(STQ* pTq, SRpcMsg* pMsg) { SStreamTaskRecoverRsp* pRsp = pMsg->pCont; int32_t taskId = pRsp->taskId; - SStreamTask* pTask = *(SStreamTask**)taosHashGet(pTq->pStreamTasks, &taskId, sizeof(int32_t)); - if (pTask) { - streamProcessRecoverRsp(pTask, pRsp); + SStreamTask** ppTask = (SStreamTask**)taosHashGet(pTq->pStreamTasks, &taskId, sizeof(int32_t)); + if (ppTask) { + streamProcessRecoverRsp(*ppTask, pRsp); return 0; } else { return -1; @@ -749,10 +750,10 @@ int32_t tqProcessTaskRecoverRsp(STQ* pTq, SRpcMsg* pMsg) { int32_t tqProcessTaskDropReq(STQ* pTq, char* msg, int32_t msgLen) { SVDropStreamTaskReq* pReq = (SVDropStreamTaskReq*)msg; - SStreamTask* pTask = *(SStreamTask**)taosHashGet(pTq->pStreamTasks, &pReq->taskId, sizeof(int32_t)); - if (pTask) { + SStreamTask** ppTask = (SStreamTask**)taosHashGet(pTq->pStreamTasks, &pReq->taskId, sizeof(int32_t)); + if (ppTask) { taosHashRemove(pTq->pStreamTasks, &pReq->taskId, sizeof(int32_t)); - atomic_store_8(&pTask->taskStatus, TASK_STATUS__DROPPING); + atomic_store_8(&(*ppTask)->taskStatus, TASK_STATUS__DROPPING); } // todo // clear queue @@ -780,16 +781,17 @@ int32_t tqProcessTaskRetrieveReq(STQ* pTq, SRpcMsg* pMsg) { SDecoder decoder; tDecoderInit(&decoder, msgBody, msgLen); tDecodeStreamRetrieveReq(&decoder, &req); - int32_t taskId = req.dstTaskId; - SStreamTask* pTask = *(SStreamTask**)taosHashGet(pTq->pStreamTasks, &taskId, sizeof(int32_t)); - if (atomic_load_8(&pTask->taskStatus) != TASK_STATUS__NORMAL) { - return 0; + int32_t taskId = req.dstTaskId; + SStreamTask** ppTask = (SStreamTask**)taosHashGet(pTq->pStreamTasks, &taskId, sizeof(int32_t)); + if (ppTask) { + SRpcMsg rsp = { + .info = pMsg->info, + .code = 0, + }; + streamProcessRetrieveReq(*ppTask, &req, &rsp); + } else { + return -1; } - SRpcMsg rsp = { - .info = pMsg->info, - .code = 0, - }; - streamProcessRetrieveReq(pTask, &req, &rsp); return 0; } diff --git a/source/libs/wal/src/walMeta.c b/source/libs/wal/src/walMeta.c index 84e5a58c1a..4bb6f07a47 100644 --- a/source/libs/wal/src/walMeta.c +++ b/source/libs/wal/src/walMeta.c @@ -94,7 +94,7 @@ static FORCE_INLINE int64_t walScanLogGetLastVer(SWal* pWal) { haystack = candidate + 1; } if (found || offset == 0) break; - offset = TMIN(0, offset - readSize + 8); + offset = TMIN(0, offset - readSize + sizeof(uint64_t)); int64_t offset2 = taosLSeekFile(pFile, offset, SEEK_SET); ASSERT(offset == offset2); if (readSize != taosReadFile(pFile, buf, readSize)) { From e781407eb3c93c752cc19e9cba0f06f4129a445e Mon Sep 17 00:00:00 2001 From: tomchon Date: Wed, 20 Jul 2022 16:36:17 +0800 Subject: [PATCH 35/45] test:add test case of tsbs query --- tests/system-test/2-query/tsbsQuery.py | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/tests/system-test/2-query/tsbsQuery.py b/tests/system-test/2-query/tsbsQuery.py index 1863f67c8e..a82c7bfe1a 100644 --- a/tests/system-test/2-query/tsbsQuery.py +++ b/tests/system-test/2-query/tsbsQuery.py @@ -14,6 +14,7 @@ class TDTestCase: clientCfgDict["debugFlag"] = 131 updatecfgDict = {'clientCfg': {}} updatecfgDict = {'debugFlag': 131} + updatecfgDict = {'keepColumnName': 1} updatecfgDict["clientCfg"] = clientCfgDict def init(self, conn, logSql): @@ -42,7 +43,7 @@ class TDTestCase: tdSql.execute(f"create table dct{i} using diagnostics (name,fleet,driver,model,device_version) tags ('truck_{i}','South{i}','Trish{i}',NULL ,'v2.3')") else: tdSql.execute(f"create table dct{i} using diagnostics (name,fleet,driver,model,device_version) tags ('truck_{i}','South{i}','Trish{i}','H-{i}','v2.3')") - for j in range(10): + for j in range(10): for i in range(100): tdSql.execute( f"insert into rct{j} values ( {ts+i*60000}, {80+i}, {90+i}, {85+i}, {30+i*10}, {1.2*i}, {221+i*2}, {20+i*0.2}, {1500+i*20}, {150+i*2},{5+i} )" @@ -92,23 +93,23 @@ class TDTestCase: # test partition interval limit (PRcore-TD-17410) - # tdSql.query("select name,driver from (SELECT name,driver,fleet ,avg(velocity) as mean_velocity FROM readings partition BY name,driver,fleet interval (10m) limit 1);") - # tdSql.checkRows(10) + tdSql.query("select name,driver from (SELECT name,driver,fleet ,avg(velocity) as mean_velocity FROM readings partition BY name,driver,fleet interval (10m) limit 1);") + tdSql.checkRows(10) # test partition interval Pseudo time-column tdSql.query("SELECT count(ms1)/144 FROM (SELECT _wstart as ts1,model, fleet,avg(status) AS ms1 FROM diagnostics WHERE ts >= '2016-01-01T00:00:00Z' AND ts < '2016-01-05T00:00:01Z' partition by model, fleet interval(10m)) WHERE ts1 >= '2016-01-01T00:00:00Z' AND ts1 < '2016-01-05T00:00:01Z' AND ms1<1;") # 1 high-load: - # tdSql.query("SELECT ts,name,driver,current_load,load_capacity FROM (SELECT last(ts) as ts,name,driver, current_load,load_capacity FROM diagnostics WHERE fleet = 'South' partition by name,driver) WHERE current_load>= (0.9 * load_capacity) partition by name ORDER BY name desc, ts DESC;") + tdSql.query("SELECT ts,name,driver,current_load,load_capacity FROM (SELECT last(ts) as ts,name,driver, current_load,load_capacity FROM diagnostics WHERE fleet = 'South' partition by name,driver) WHERE current_load>= (0.9 * load_capacity) partition by name ORDER BY name desc, ts DESC;") - # tdSql.query("SELECT ts,name,driver,current_load,load_capacity FROM (SELECT last(ts) as ts,name,driver, current_load,load_capacity FROM diagnostics WHERE fleet = 'South' partition by name,driver) WHERE current_load>= (0.9 * load_capacity) partition by name ORDER BY name ;") + tdSql.query("SELECT ts,name,driver,current_load,load_capacity FROM (SELECT last(ts) as ts,name,driver, current_load,load_capacity FROM diagnostics WHERE fleet = 'South' partition by name,driver) WHERE current_load>= (0.9 * load_capacity) partition by name ORDER BY name ;") # 2 stationary-trucks tdSql.query("select name,driver from (SELECT name,driver,fleet ,avg(velocity) as mean_velocity FROM readings WHERE ts > '2016-01-01T15:07:21Z' AND ts <= '2016-01-01T16:17:21Z' partition BY name,driver,fleet interval(10m) LIMIT 1)") tdSql.query("select name,driver from (SELECT name,driver,fleet ,avg(velocity) as mean_velocity FROM readings WHERE ts > '2016-01-01T15:07:21Z' AND ts <= '2016-01-01T16:17:21Z' partition BY name,driver,fleet interval(10m) LIMIT 1) WHERE fleet = 'West' AND mean_velocity < 1000 partition BY name") # 3 long-driving-sessions - # tdSql.query("SELECT name,driver FROM(SELECT name,driver,count(*) AS ten_min FROM(SELECT _wstart as ts,name,driver,avg(velocity) as mean_velocity FROM readings where ts > '2016-01-01T00:00:34Z' AND ts <= '2016-01-01T04:00:34Z' partition BY name,driver interval(10m)) WHERE mean_velocity > 1 GROUP BY name,driver) WHERE ten_min > 22 ;") + tdSql.query("SELECT name,driver FROM(SELECT name,driver,count(*) AS ten_min FROM(SELECT _wstart as ts,name,driver,avg(velocity) as mean_velocity FROM readings where ts > '2016-01-01T00:00:34Z' AND ts <= '2016-01-01T04:00:34Z' partition BY name,driver interval(10m)) WHERE mean_velocity > 1 GROUP BY name,driver) WHERE ten_min > 22 ;") #4 long-daily-sessions @@ -130,15 +131,18 @@ class TDTestCase: # 8. daily-activity tdSql.query(" SELECT model,ms1 FROM (SELECT _wstart as ts1,model, fleet,avg(status) AS ms1 FROM diagnostics WHERE ts >= '2016-01-01T00:00:00Z' AND ts < '2016-01-05T00:00:01Z' partition by model, fleet interval(10m) fill(value,0)) WHERE ts1 >= '2016-01-01T00:00:00Z' AND ts1 < '2016-01-05T00:00:01Z' AND ms1<1;") + + tdSql.query(" SELECT model,ms1 FROM (SELECT _wstart as ts1,model, fleet,avg(status) AS ms1 FROM diagnostics WHERE ts >= '2016-01-01T00:00:00Z' AND ts < '2016-01-05T00:00:01Z' partition by model, fleet interval(10m) ) WHERE ts1 >= '2016-01-01T00:00:00Z' AND ts1 < '2016-01-05T00:00:01Z' AND ms1<1;") + tdSql.query("SELECT _wstart,model,fleet,count(ms1)/144 FROM (SELECT _wstart as ts1,model, fleet,avg(status) AS ms1 FROM diagnostics WHERE ts >= '2016-01-01T00:00:00Z' AND ts < '2016-01-05T00:00:01Z' partition by model, fleet interval(10m) fill(value,0)) WHERE ts1 >= '2016-01-01T00:00:00Z' AND ts1 < '2016-01-05T00:00:01Z' AND ms1<1 partition by model, fleet interval(1d) ;") # 9. breakdown-frequency # NULL ---count(NULL)=0 expect count(NULL)= 100 - tdSql.query("select tbname,count(model),model from readings partition by tbname,model;") - # model=NULL count(other) is 0 - tdSql.query("select tbname,count(name),model from readings where model=NULL partition by tbname,model;") + tdSql.query("SELECT model,state_changed,count(state_changed) FROM (SELECT model,diff(broken_down) AS state_changed FROM (SELECT _wstart,model,cast(cast(floor(2*(sum(nzs)/count(nzs))) as bool) as int) AS broken_down FROM (SELECT ts,model, cast(cast(status as bool) as int) AS nzs FROM diagnostics WHERE ts >= '2016-01-01T00:00:00Z' AND ts < '2016-01-05T00:00:01Z' ) WHERE ts >= '2016-01-01T00:00:00Z' AND ts < '2016-01-05T00:00:01Z' partition BY model interval(10m)) partition BY model) where model is null partition BY model,state_changed ") + tdSql.query(" SELECT model,state_changed,count(state_changed) FROM (SELECT model,diff(broken_down) AS state_changed FROM (SELECT _wstart,model,cast(cast(floor(2*(sum(nzs)/count(nzs))) as bool) as int) AS broken_down FROM (SELECT ts,model, cast(cast(status as bool) as int) AS nzs FROM diagnostics WHERE ts >= '2016-01-01T00:00:00Z' AND ts < '2016-01-05T00:00:01Z' ) WHERE ts >= '2016-01-01T00:00:00Z' AND ts < '2016-01-05T00:00:01Z' partition BY model interval(10m)) partition BY model) where state_changed =1 partition BY model,state_changed ;") + #it's already supported: # last-loc tdSql.query("SELECT last_row(ts),latitude,longitude,name,driver FROM readings WHERE fleet='South' and name IS NOT NULL partition BY name,driver order by name ;") From 5d20804e7670e5e55fce774ced1018665dc7969a Mon Sep 17 00:00:00 2001 From: Liu Jicong Date: Wed, 20 Jul 2022 17:10:41 +0800 Subject: [PATCH 36/45] fix(wal): use after free --- source/libs/wal/src/walMeta.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/source/libs/wal/src/walMeta.c b/source/libs/wal/src/walMeta.c index 4bb6f07a47..a5fd3fca35 100644 --- a/source/libs/wal/src/walMeta.c +++ b/source/libs/wal/src/walMeta.c @@ -126,10 +126,11 @@ static FORCE_INLINE int64_t walScanLogGetLastVer(SWal* pWal) { return -1; } SWalCkHead* lastEntry = (SWalCkHead*)found; + int64_t retVer = lastEntry->head.version; taosCloseFile(&pFile); taosMemoryFree(buf); - return lastEntry->head.version; + return retVer; } int walCheckAndRepairMeta(SWal* pWal) { From ebcf2a1a9966b2b69048417d61ac7f4c54995c52 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Wed, 20 Jul 2022 17:20:49 +0800 Subject: [PATCH 37/45] test: restore 2.0 case --- tests/script/jenkins/basic.txt | 4 +- tests/script/tsim/parser/fill_stb.sim | 5 +- tests/script/tsim/parser/groupby.sim | 116 +++++++-------------- tests/script/tsim/parser/having_child.sim | 118 +++++++++++----------- 4 files changed, 99 insertions(+), 144 deletions(-) diff --git a/tests/script/jenkins/basic.txt b/tests/script/jenkins/basic.txt index 655462d1cf..e17dddc6c4 100644 --- a/tests/script/jenkins/basic.txt +++ b/tests/script/jenkins/basic.txt @@ -104,7 +104,7 @@ ## ./test.sh -f tsim/parser/create_tb_with_tag_name.sim # ./test.sh -f tsim/parser/dbtbnameValidate.sim ##./test.sh -f tsim/parser/distinct.sim -./test.sh -f tsim/parser/fill_stb.sim +#./test.sh -f tsim/parser/fill_stb.sim ./test.sh -f tsim/parser/fill_us.sim ./test.sh -f tsim/parser/fill.sim ./test.sh -f tsim/parser/first_last.sim @@ -112,8 +112,8 @@ ## ./test.sh -f tsim/parser/function.sim ./test.sh -f tsim/parser/groupby-basic.sim # ./test.sh -f tsim/parser/groupby.sim -## ./test.sh -f tsim/parser/having.sim # ./test.sh -f tsim/parser/having_child.sim +## ./test.sh -f tsim/parser/having.sim ## ./test.sh -f tsim/parser/import.sim # ./test.sh -f tsim/parser/import_commit1.sim # ./test.sh -f tsim/parser/import_commit2.sim diff --git a/tests/script/tsim/parser/fill_stb.sim b/tests/script/tsim/parser/fill_stb.sim index 5493843993..107bac7089 100644 --- a/tests/script/tsim/parser/fill_stb.sim +++ b/tests/script/tsim/parser/fill_stb.sim @@ -97,10 +97,11 @@ $tsu = $tsu + $ts0 #endi # number of fill values exceeds number of selected columns -print select count(ts), max(c1), max(c2), max(c3), max(c4), max(c5) from $stb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, -1, -2, -3, -4, -5, -6, -7, -8) -sql select count(ts), max(c1), max(c2), max(c3), max(c4), max(c5) from $stb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, -1, -2, -3, -4, -5, -6, -7, -8) +print select _wstart, count(ts), max(c1), max(c2), max(c3), max(c4), max(c5) from $stb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, -1, -2, -3, -4, -5, -6, -7, -8) +sql select _wstart, count(ts), max(c1), max(c2), max(c3), max(c4), max(c5) from $stb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, -1, -2, -3, -4, -5, -6, -7, -8) $val = $rowNum * 2 $val = $val - 1 +print $rows $val if $rows != $val then return -1 endi diff --git a/tests/script/tsim/parser/groupby.sim b/tests/script/tsim/parser/groupby.sim index 8d7fad8cbc..7970bb4414 100644 --- a/tests/script/tsim/parser/groupby.sim +++ b/tests/script/tsim/parser/groupby.sim @@ -67,8 +67,6 @@ while $i < $half $tstart = 100000 endw -sleep 100 - $i1 = 1 $i2 = 0 @@ -85,7 +83,7 @@ $ts1 = $tb1 . .ts $ts2 = $tb2 . .ts print ===============================groupby_operation -sql select count(*),c1 from group_tb0 where c1 < 20 group by c1; +sql select count(*),c1 from group_tb0 where c1 < 20 group by c1 order by c1; if $row != 20 then return -1 endi @@ -106,7 +104,7 @@ if $data11 != 1 then return -1 endi -sql select first(ts),c1 from group_tb0 where c1<20 group by c1; +sql select first(ts),c1 from group_tb0 where c1 < 20 group by c1 order by c1; if $row != 20 then return -1 endi @@ -127,7 +125,7 @@ if $data91 != 9 then return -1 endi -sql select first(ts), ts, c1 from group_tb0 where c1 < 20 group by c1; +sql select first(ts), ts, c1 from group_tb0 where c1 < 20 group by c1 order by c1; print $row if $row != 20 then return -1 @@ -161,7 +159,7 @@ if $data92 != 9 then return -1 endi -sql select sum(c1), c1, avg(c1), min(c1), max(c2) from group_tb0 where c1 < 20 group by c1; +sql select sum(c1), c1, avg(c1), min(c1), max(c2) from group_tb0 where c1 < 20 group by c1 order by c1; if $row != 20 then return -1 endi @@ -211,20 +209,20 @@ if $data14 != 1.00000 then endi sql_error select sum(c1), ts, c1 from group_tb0 where c1<20 group by c1; -sql_error select first(ts), ts, c2 from group_tb0 where c1 < 20 group by c1; +sql select first(ts), ts, c2 from group_tb0 where c1 < 20 group by c1; sql_error select sum(c3), ts, c2 from group_tb0 where c1 < 20 group by c1; sql_error select sum(c3), first(ts), c2 from group_tb0 where c1 < 20 group by c1; -sql_error select first(c3), ts, c1, c2 from group_tb0 where c1 < 20 group by c1; +sql select first(c3), ts, c1, c2 from group_tb0 where c1 < 20 group by c1; sql_error select first(c3), last(c3), ts, c1 from group_tb0 where c1 < 20 group by c1; sql_error select ts from group_tb0 group by c1; #===========================interval=====not support====================== sql_error select count(*), c1 from group_tb0 where c1<20 interval(1y) group by c1; #=====tbname must be the first in the group by clause===================== -sql_error select count(*) from group_tb0 where c1 < 20 group by c1, tbname; +sql select count(*) from group_tb0 where c1 < 20 group by c1, tbname; #super table group by normal columns -sql select count(*), c1 from group_mt0 where c1< 20 group by c1; +sql select count(*), c1 from group_mt0 where c1< 20 group by c1 order by c1; if $row != 20 then return -1 endi @@ -253,7 +251,7 @@ if $data91 != 9 then return -1 endi -sql select first(c1), c1, ts from group_mt0 where c1<20 group by c1; +sql select first(c1), c1, ts from group_mt0 where c1<20 group by c1 order by c1; if $row != 20 then return -1 endi @@ -290,7 +288,7 @@ if $data92 != @70-01-01 08:01:40.009@ then return -1 endi -sql select first(c1), last(ts), first(ts), last(c1),c1,sum(c1),avg(c1),count(*) from group_mt0 where c1<20 group by c1; +sql select first(c1), last(ts), first(ts), last(c1),c1,sum(c1),avg(c1),count(*) from group_mt0 where c1<20 group by c1 order by c1; if $row != 20 then return -1 endi @@ -351,7 +349,7 @@ if $data94 != 9 then return -1 endi -sql select c1,sum(c1),avg(c1),count(*) from group_mt0 where c1<5 group by c1; +sql select c1,sum(c1),avg(c1),count(*) from group_mt0 where c1<5 group by c1 order by c1; if $row != 5 then return -1 endi @@ -364,7 +362,7 @@ if $data11 != 800 then return -1 endi -sql select first(c1), last(ts), first(ts), last(c1),sum(c1),avg(c1),count(*) from group_mt0 where c1<20 group by tbname,c1; +sql select first(c1), last(ts), first(ts), last(c1),sum(c1),avg(c1),count(*),tbname from group_mt0 where c1<20 group by tbname, c1 order by c1; if $row != 160 then return -1 endi @@ -395,39 +393,8 @@ if $data06 != 100 then return -1 endi -if $data07 != @group_tb0@ then - return -1 -endi -if $data90 != 9 then - return -1 -endi - -if $data91 != @70-01-01 08:01:49.909@ then - return -1 -endi - -if $data92 != @70-01-01 08:01:40.009@ then - return -1 -endi - -if $data93 != 9 then - return -1 -endi - -if $data94 != 900 then - return -1 -endi - -if $data96 != 100 then - return -1 -endi - -if $data97 != @group_tb0@ then - return -1 -endi - -sql select count(*),first(ts),last(ts),min(c3) from group_tb1 group by c4; +sql select count(*),first(ts),last(ts),min(c3) from group_tb1 group by c4 order by c4; if $rows != 10000 then return -1 endi @@ -469,7 +436,7 @@ if $rows != 100 then return -1 endi -sql select count(*),sum(c4), count(c4), sum(c4)/count(c4) from group_tb1 group by c8 +sql select count(*),sum(c4), count(c4), sum(c4)/count(c4) from group_tb1 group by c8 order by c8; if $rows != 100 then return -1 endi @@ -504,12 +471,12 @@ if $data13 != 4951.000000000 then endi print ====================> group by normal column + slimit + soffset -sql select count(*), c8 from group_mt0 group by c8 limit 1 offset 0; +sql select count(*), c8 from group_mt0 group by c8 limit 100 offset 0; if $rows != 100 then return -1 endi -sql select sum(c2),c8,avg(c2), sum(c2)/count(*) from group_mt0 group by c8 slimit 2 soffset 99 +sql select sum(c2),c8,avg(c2), sum(c2)/count(*) from group_mt0 partition by c8 order by c8 slimit 2 soffset 99 if $rows != 1 then return -1 endi @@ -531,7 +498,7 @@ if $data03 != 99.000000000 then endi print ============>td-1765 -sql select percentile(c4, 49),min(c4),max(c4),avg(c4),stddev(c4) from group_tb0 group by c8; +sql select percentile(c4, 49),min(c4),max(c4),avg(c4),stddev(c4) from group_tb0 group by c8 order by c8; if $rows != 100 then return -1 endi @@ -577,7 +544,7 @@ if $data14 != 2886.607004772 then endi print ================>td-2090 -sql select leastsquares(c2, 1, 1) from group_tb1 group by c8; +sql select leastsquares(c2, 1, 1) from group_tb1 group by c8 order by c8;; if $rows != 100 then return -1 endi @@ -607,13 +574,13 @@ print =================>TD-2665 sql_error create table txx as select avg(c) as t from st; sql_error create table txx1 as select avg(c) as t from t1; -sql select stddev(c),stddev(c) from st group by c; +sql select stddev(c),stddev(c) from st group by c order by c; if $rows != 4 then return -1 endi print =================>TD-2236 -sql select first(ts),last(ts) from t1 group by c; +sql select first(ts),last(ts) from t1 group by c order by c; if $rows != 4 then return -1 endi @@ -651,7 +618,7 @@ if $data31 != @20-03-27 05:10:19.000@ then endi print ===============> -sql select stddev(c),c from st where t2=1 or t2=2 group by c; +sql select stddev(c),c from st where t2=1 or t2=2 group by c order by c; if $rows != 4 then return -1 endi @@ -689,14 +656,11 @@ if $data31 != 4 then endi sql_error select irate(c) from st where t1="1" and ts >= '2020-03-27 04:11:17.732' and ts < '2020-03-27 05:11:17.732' interval(1m) sliding(15s) group by tbname,c; -sql select irate(c) from st where t1="1" and ts >= '2020-03-27 04:11:17.732' and ts < '2020-03-27 05:11:17.732' interval(1m) sliding(15s) group by tbname,t1,t2; +sql select _wstart, irate(c), tbname, t1, t2 from st where t1=1 and ts >= '2020-03-27 04:11:17.732' and ts < '2020-03-27 05:11:17.732' partition by tbname,t1,t2 interval(1m) sliding(15s) order by tbname; if $rows != 40 then return -1 endi -if $data01 != 1.000000000 then - return -1 -endi if $data02 != t1 then return -1 endi @@ -707,9 +671,6 @@ if $data04 != 1 then return -1 endi -if $data11 != 1.000000000 then - return -1 -endi if $data12 != t1 then return -1 endi @@ -720,21 +681,21 @@ if $data14 != 1 then return -1 endi -sql select irate(c) from st where t1="1" and ts >= '2020-03-27 04:11:17.732' and ts < '2020-03-27 05:11:17.732' interval(1m) sliding(15s) group by tbname,t1,t2 limit 1; -if $rows != 2 then +sql select _wstart, irate(c), tbname, t1, t2 from st where t1=1 and ts >= '2020-03-27 04:11:17.732' and ts < '2020-03-27 05:11:17.732' partition by tbname, t1, t2 interval(1m) sliding(15s) order by tbname desc limit 1; +if $rows != 1 then return -1 endi -if $data11 != 1.000000000 then +if $data01 != 1.000000000 then return -1 endi -if $data12 != t2 then +if $data02 != t2 then return -1 endi -if $data13 != 1 then +if $data03 != 1 then return -1 endi -if $data14 != 2 then +if $data04 != 2 then return -1 endi @@ -748,16 +709,12 @@ sql insert into tm1 values('2020-2-1 1:1:1', 2, 10); sql insert into tm1 values('2020-2-1 1:1:2', 2, 20); system sh/exec.sh -n dnode1 -s stop -x SIGINT -sleep 100 system sh/exec.sh -n dnode1 -s start -sleep 100 - sql connect -sleep 100 sql use group_db0; print =========================>TD-4894 -sql select count(*),k from m1 group by k; +sql select count(*),k from m1 group by k order by k; if $rows != 2 then return -1 endi @@ -778,14 +735,13 @@ if $data11 != 2 then return -1 endi -sql_error select count(*) from m1 group by tbname,k,f1; -sql_error select count(*) from m1 group by tbname,k,a; -sql_error select count(*) from m1 group by k, tbname; -sql_error select count(*) from m1 group by k,f1; -sql_error select count(*) from tm0 group by tbname; -sql_error select count(*) from tm0 group by a; -sql_error select count(*) from tm0 group by k,f1; - +sql select count(*) from m1 group by tbname,k,f1; +sql select count(*) from m1 group by tbname,k,a; +sql select count(*) from m1 group by k, tbname; +sql select count(*) from m1 group by k,f1; +sql select count(*) from tm0 group by tbname; +sql select count(*) from tm0 group by a; +sql select count(*) from tm0 group by k,f1; sql_error select count(*),f1 from m1 group by tbname,k; system sh/exec.sh -n dnode1 -s stop -x SIGINT diff --git a/tests/script/tsim/parser/having_child.sim b/tests/script/tsim/parser/having_child.sim index 1ee1481943..596c8d715a 100644 --- a/tests/script/tsim/parser/having_child.sim +++ b/tests/script/tsim/parser/having_child.sim @@ -27,7 +27,7 @@ sql insert into tb1 values (now+100s,4,4.0,4.0,4,4,4,true ,"4","4") sql insert into tb1 values (now+150s,4,4.0,4.0,4,4,4,false,"4","4") -sql select count(*),f1 from tb1 group by f1 having count(f1) > 0; +sql select count(*),f1 from tb1 group by f1 having count(f1) > 0 order by f1; if $rows != 4 then return -1 endi @@ -57,7 +57,7 @@ if $data31 != 4 then endi -sql select count(*),f1 from tb1 group by f1 having count(*) > 0; +sql select count(*),f1 from tb1 group by f1 having count(*) > 0 order by f1; if $rows != 4 then return -1 endi @@ -86,8 +86,7 @@ if $data31 != 4 then return -1 endi - -sql select count(*),f1 from tb1 group by f1 having count(f2) > 0; +sql select count(*),f1 from tb1 group by f1 having count(f2) > 0 order by f1; if $rows != 4 then return -1 endi @@ -118,7 +117,7 @@ endi sql_error select top(f1,2) from tb1 group by f1 having count(f2) > 0; -sql select last(f1) from tb1 group by f1 having count(f2) > 0; +sql select last(f1) from tb1 group by f1 having count(f2) > 0 order by f1;; if $rows != 4 then return -1 endi @@ -141,7 +140,7 @@ sql_error select top(f1,2) from tb1 group by f1 having count(f2) > 0; sql_error select top(f1,2) from tb1 group by f1 having avg(f1) > 0; -sql select avg(f1),count(f1) from tb1 group by f1 having avg(f1) > 2; +sql select avg(f1),count(f1) from tb1 group by f1 having avg(f1) > 2 order by f1; if $rows != 2 then return -1 endi @@ -158,8 +157,7 @@ if $data11 != 2 then return -1 endi - -sql select avg(f1),count(f1) from tb1 group by f1 having avg(f1) > 2 and sum(f1) > 0; +sql select avg(f1),count(f1) from tb1 group by f1 having avg(f1) > 2 and sum(f1) > 0 order by f1; if $rows != 2 then return -1 endi @@ -176,7 +174,7 @@ if $data11 != 2 then return -1 endi -sql select avg(f1),count(f1),sum(f1) from tb1 group by f1 having avg(f1) > 2 and sum(f1) > 0; +sql select avg(f1),count(f1),sum(f1) from tb1 group by f1 having avg(f1) > 2 and sum(f1) > 0 order by f1; if $rows != 2 then return -1 endi @@ -199,7 +197,7 @@ if $data12 != 8 then return -1 endi -sql select avg(f1),count(f1),sum(f1) from tb1 group by f1 having avg(f1) > 2; +sql select avg(f1),count(f1),sum(f1) from tb1 group by f1 having avg(f1) > 2 order by f1; if $rows != 2 then return -1 endi @@ -222,7 +220,7 @@ if $data12 != 8 then return -1 endi -sql select avg(f1),count(f1),sum(f1) from tb1 group by f1 having sum(f1) > 0; +sql select avg(f1),count(f1),sum(f1) from tb1 group by f1 having sum(f1) > 0 order by f1; if $rows != 4 then return -1 endi @@ -263,7 +261,7 @@ if $data32 != 8 then return -1 endi -sql select avg(f1),count(f1),sum(f1) from tb1 group by f1 having sum(f1) > 2 and sum(f1) < 6; +sql select avg(f1),count(f1),sum(f1) from tb1 group by f1 having sum(f1) > 2 and sum(f1) < 6 order by f1; if $rows != 1 then return -1 endi @@ -278,7 +276,7 @@ if $data02 != 4 then endi -sql select avg(f1),count(f1),sum(f1) from tb1 group by f1 having 1 <= sum(f1) and 5 >= sum(f1); +sql select avg(f1),count(f1),sum(f1) from tb1 group by f1 having 1 <= sum(f1) and 5 >= sum(f1) order by f1; if $rows != 2 then return -1 endi @@ -309,7 +307,7 @@ sql_error select avg(f1),count(f1),sum(f1),twa(f1) from tb1 group by tbname havi sql_error select avg(f1),count(f1),sum(f1),twa(f1) from tb1 group by f1 having sum(f1) = 4; -sql select avg(f1),count(f1),sum(f1) from tb1 group by f1 having sum(f1) > 0; +sql select avg(f1),count(f1),sum(f1) from tb1 group by f1 having sum(f1) > 0 order by f1; if $rows != 4 then return -1 endi @@ -350,7 +348,7 @@ if $data32 != 8 then return -1 endi -sql select avg(f1),count(f1),sum(f1) from tb1 group by f1 having sum(f1) > 3; +sql select avg(f1),count(f1),sum(f1) from tb1 group by f1 having sum(f1) > 3 order by f1; if $rows != 3 then return -1 endi @@ -383,7 +381,7 @@ if $data22 != 8 then endi ###########and issue -sql select avg(f1),count(f1),sum(f1) from tb1 group by f1 having sum(f1) > 3 and sum(f1) > 1; +sql select avg(f1),count(f1),sum(f1) from tb1 group by f1 having sum(f1) > 3 and sum(f1) > 1 order by f1; if $rows != 4 then return -1 endi @@ -425,7 +423,7 @@ if $data32 != 8 then endi -sql select avg(f1),count(f1),sum(f1) from tb1 group by f1 having sum(f1) > 3 or sum(f1) > 1; +sql select avg(f1),count(f1),sum(f1) from tb1 group by f1 having sum(f1) > 3 or sum(f1) > 1 order by f1; if $rows != 4 then return -1 endi @@ -466,7 +464,7 @@ if $data32 != 8 then return -1 endi -sql select avg(f1),count(f1),sum(f1) from tb1 group by f1 having sum(f1) > 3 or sum(f1) > 4; +sql select avg(f1),count(f1),sum(f1) from tb1 group by f1 having sum(f1) > 3 or sum(f1) > 4 order by f1; if $rows != 3 then return -1 endi @@ -499,12 +497,12 @@ if $data22 != 8 then endi ############or issue -sql select avg(f1),count(f1),sum(f1) from tb1 group by f1 having sum(f1) > 3 or avg(f1) > 4; +sql select avg(f1),count(f1),sum(f1) from tb1 group by f1 having sum(f1) > 3 or avg(f1) > 4 order by f1; if $rows != 0 then return -1 endi -sql select avg(f1),count(f1),sum(f1) from tb1 group by f1 having (sum(f1) > 3); +sql select avg(f1),count(f1),sum(f1) from tb1 group by f1 having (sum(f1) > 3) order by f1; if $rows != 3 then return -1 endi @@ -538,7 +536,7 @@ endi sql_error select avg(f1),count(f1),sum(f1) from tb1 group by f1 having (sum(*) > 3); -sql select avg(f1),count(f1),sum(f1) from tb1 group by f1 having (sum(tb1.f1) > 3); +sql select avg(f1),count(f1),sum(f1) from tb1 group by f1 having (sum(tb1.f1) > 3) order by f1; if $rows != 3 then return -1 endi @@ -570,7 +568,7 @@ if $data22 != 8 then return -1 endi -sql select avg(f1),count(tb1.*),sum(f1) from tb1 group by f1 having (sum(tb1.f1) > 3); +sql select avg(f1),count(tb1.*),sum(f1) from tb1 group by f1 having (sum(tb1.f1) > 3) order by f1; if $rows != 3 then return -1 endi @@ -602,7 +600,7 @@ if $data22 != 8 then return -1 endi -sql select avg(f1),count(tb1.*),sum(f1),stddev(f1),stddev(f1) from tb1 group by f1; +sql select avg(f1),count(tb1.*),sum(f1),stddev(f1),stddev(f1) from tb1 group by f1 order by f1; if $rows != 4 then return -1 endi @@ -667,12 +665,12 @@ if $data34 != 0.000000000 then return -1 endi -sql select avg(f1),count(tb1.*),sum(f1),stddev(f1) from tb1 group by f1 having (stddev(tb1.f1) > 3); +sql select avg(f1),count(tb1.*),sum(f1),stddev(f1) from tb1 group by f1 having (stddev(tb1.f1) > 3) order by f1; if $rows != 0 then return -1 endi -sql select avg(f1),count(tb1.*),sum(f1),stddev(f1) from tb1 group by f1 having (stddev(tb1.f1) < 1); +sql select avg(f1),count(tb1.*),sum(f1),stddev(f1) from tb1 group by f1 having (stddev(tb1.f1) < 1) order by f1; if $rows != 4 then return -1 endi @@ -736,7 +734,7 @@ sql_error select avg(f1),count(tb1.*),sum(f1),stddev(f1) from tb1 group by f1 ha sql_error select avg(f1),count(tb1.*),sum(f1),stddev(f1),LEASTSQUARES(f1,1,1) from tb1 group by f1 having LEASTSQUARES(f1,1,1) > 2; -sql select avg(f1),count(tb1.*),sum(f1),stddev(f1),LEASTSQUARES(f1,1,1) from tb1 group by f1 having sum(f1) > 2; +sql select avg(f1),count(tb1.*),sum(f1),stddev(f1),LEASTSQUARES(f1,1,1) from tb1 group by f1 having sum(f1) > 2 order by f1; if $rows != 3 then return -1 endi @@ -777,7 +775,7 @@ if $data23 != 0.000000000 then return -1 endi -sql select avg(f1),count(tb1.*),sum(f1),stddev(f1) from tb1 group by f1 having min(f1) > 2; +sql select avg(f1),count(tb1.*),sum(f1),stddev(f1) from tb1 group by f1 having min(f1) > 2 order by f1; if $rows != 2 then return -1 endi @@ -806,7 +804,7 @@ if $data13 != 0.000000000 then return -1 endi -sql select avg(f1),count(tb1.*),sum(f1),stddev(f1),min(f1) from tb1 group by f1 having min(f1) > 2; +sql select avg(f1),count(tb1.*),sum(f1),stddev(f1),min(f1) from tb1 group by f1 having min(f1) > 2 order by f1; if $rows != 2 then return -1 endi @@ -841,7 +839,7 @@ if $data14 != 4 then return -1 endi -sql select avg(f1),count(tb1.*),sum(f1),stddev(f1),min(f1) from tb1 group by f1 having max(f1) > 2; +sql select avg(f1),count(tb1.*),sum(f1),stddev(f1),min(f1) from tb1 group by f1 having max(f1) > 2 order by f1; if $rows != 2 then return -1 endi @@ -876,7 +874,7 @@ if $data14 != 4 then return -1 endi -sql select avg(f1),count(tb1.*),sum(f1),stddev(f1),min(f1),max(f1) from tb1 group by f1 having max(f1) != 2; +sql select avg(f1),count(tb1.*),sum(f1),stddev(f1),min(f1),max(f1) from tb1 group by f1 having max(f1) != 2 order by f1; if $rows != 3 then return -1 endi @@ -935,7 +933,7 @@ if $data25 != 4 then return -1 endi -sql select avg(f1),count(tb1.*),sum(f1),stddev(f1),min(f1),max(f1) from tb1 group by f1 having first(f1) != 2; +sql select avg(f1),count(tb1.*),sum(f1),stddev(f1),min(f1),max(f1) from tb1 group by f1 having first(f1) != 2 order by f1; if $rows != 3 then return -1 endi @@ -996,7 +994,7 @@ endi -sql select avg(f1),count(tb1.*),sum(f1),stddev(f1),min(f1),max(f1),first(f1) from tb1 group by f1 having first(f1) != 2; +sql select avg(f1),count(tb1.*),sum(f1),stddev(f1),min(f1),max(f1),first(f1) from tb1 group by f1 having first(f1) != 2 order by f1; if $rows != 3 then return -1 endi @@ -1078,7 +1076,7 @@ sql_error select avg(f1),count(tb1.*),sum(f1),stddev(f1),min(f1),max(f1),first(f sql_error select PERCENTILE(f1) from tb1 group by f1 having sum(f1) > 1; -sql select PERCENTILE(f1,20) from tb1 group by f1 having sum(f1) = 4; +sql select PERCENTILE(f1,20) from tb1 group by f1 having sum(f1) = 4 order by f1; if $rows != 1 then return -1 endi @@ -1086,7 +1084,7 @@ if $data00 != 2.000000000 then return -1 endi -sql select aPERCENTILE(f1,20) from tb1 group by f1 having sum(f1) > 1; +sql select aPERCENTILE(f1,20) from tb1 group by f1 having sum(f1) > 1 order by f1; if $rows != 4 then return -1 endi @@ -1103,7 +1101,7 @@ if $data30 != 4.000000000 then return -1 endi -sql select aPERCENTILE(f1,20) from tb1 group by f1 having apercentile(f1,1) > 1; +sql select aPERCENTILE(f1,20) from tb1 group by f1 having apercentile(f1,1) > 1 order by f1; if $rows != 3 then return -1 endi @@ -1117,7 +1115,7 @@ if $data20 != 4.000000000 then return -1 endi -sql select aPERCENTILE(f1,20) from tb1 group by f1 having apercentile(f1,1) > 1 and apercentile(f1,1) < 50; +sql select aPERCENTILE(f1,20) from tb1 group by f1 having apercentile(f1,1) > 1 and apercentile(f1,1) < 50 order by f1; if $rows != 3 then return -1 endi @@ -1131,7 +1129,7 @@ if $data20 != 4.000000000 then return -1 endi -sql select aPERCENTILE(f1,20) from tb1 group by f1 having apercentile(f1,1) > 1 and apercentile(f1,1) < 3; +sql select aPERCENTILE(f1,20) from tb1 group by f1 having apercentile(f1,1) > 1 and apercentile(f1,1) < 3 order by f1; if $rows != 1 then return -1 endi @@ -1139,7 +1137,7 @@ if $data00 != 2.000000000 then return -1 endi -sql select aPERCENTILE(f1,20) from tb1 group by f1 having apercentile(f1,1) > 1 and apercentile(f1,3) < 3; +sql select aPERCENTILE(f1,20) from tb1 group by f1 having apercentile(f1,1) > 1 and apercentile(f1,3) < 3 order by f1; if $rows != 1 then return -1 endi @@ -1161,12 +1159,12 @@ sql_error select avg(f1),diff(f1) from tb1 group by f1 having avg(f1) > 0; sql_error select avg(f1),diff(f1) from tb1 group by f1 having spread(f2) > 0; -sql select avg(f1) from tb1 group by f1 having spread(f2) > 0; +sql select avg(f1) from tb1 group by f1 having spread(f2) > 0 order by f1; if $rows != 0 then return -1 endi -sql select avg(f1) from tb1 group by f1 having spread(f2) = 0; +sql select avg(f1) from tb1 group by f1 having spread(f2) = 0 order by f1; if $rows != 4 then return -1 endi @@ -1183,7 +1181,7 @@ if $data30 != 4.000000000 then return -1 endi -sql select avg(f1),spread(f2) from tb1 group by f1; +sql select avg(f1),spread(f2) from tb1 group by f1 order by f1; if $rows != 4 then return -1 endi @@ -1212,7 +1210,7 @@ if $data31 != 0.000000000 then return -1 endi -sql select avg(f1),spread(f1,f2,tb1.f1) from tb1 group by f1 having spread(f1) = 0; +sql select avg(f1),spread(f1,f2,tb1.f1) from tb1 group by f1 having spread(f1) = 0 order by f1; if $rows != 4 then return -1 endi @@ -1265,7 +1263,7 @@ if $data33 != 0.000000000 then return -1 endi -sql select avg(f1),spread(f1,f2,tb1.f1) from tb1 group by f1 having spread(f1) != 0; +sql select avg(f1),spread(f1,f2,tb1.f1) from tb1 group by f1 having spread(f1) != 0 order by f1; if $rows != 0 then return -1 endi @@ -1301,12 +1299,12 @@ sql_error select avg(f1),spread(f1,f2,tb1.f1) from tb1 group by f1 having spread sql_error select avg(f1),spread(f1,f2,tb1.f1) from tb1 group by f1 having spread(f1) > id1 and sum(f1) > 1; -sql select avg(f1),spread(f1,f2,tb1.f1) from tb1 group by f1 having spread(f1) > 2 and sum(f1) > 1; +sql select avg(f1),spread(f1,f2,tb1.f1) from tb1 group by f1 having spread(f1) > 2 and sum(f1) > 1 order by f1; if $rows != 0 then return -1 endi -sql select avg(f1),spread(f1,f2,tb1.f1) from tb1 group by f1 having spread(f1) = 0 and sum(f1) > 1; +sql select avg(f1),spread(f1,f2,tb1.f1) from tb1 group by f1 having spread(f1) = 0 and sum(f1) > 1 order by f1; if $rows != 4 then return -1 endi @@ -1359,7 +1357,7 @@ if $data33 != 0.000000000 then return -1 endi -sql select avg(f1),spread(f1,f2,tb1.f1) from tb1 group by f1 having spread(f1) = 0 and avg(f1) > 1; +sql select avg(f1),spread(f1,f2,tb1.f1) from tb1 group by f1 having spread(f1) = 0 and avg(f1) > 1 order by f1; if $rows != 3 then return -1 endi @@ -1410,7 +1408,7 @@ sql_error select avg(f1),spread(f1,f2,tb1.f1),avg(id1) from tb1 group by id1 hav sql_error select avg(f1),spread(f1,f2,tb1.f1) from tb1 group by id1 having avg(f1) > 0; -sql select avg(f1),spread(f1,f2,tb1.f1) from tb1 group by f1 having avg(f1) > 0 and avg(f1) = 3; +sql select avg(f1),spread(f1,f2,tb1.f1) from tb1 group by f1 having avg(f1) > 0 and avg(f1) = 3 order by f1; if $rows != 1 then return -1 endi @@ -1430,7 +1428,7 @@ endi #sql_error select avg(f1),spread(f1,f2,tb1.f1) from tb1 group by f1 having avg(f1) < 0 and avg(f1) = 3; sql_error select avg(f1),spread(f1,f2,tb1.f1) from tb1 group by id1 having avg(f1) < 2; -sql select avg(f1),spread(f1,f2,tb1.f1) from tb1 where f1 > 0 group by f1 having avg(f1) > 0; +sql select avg(f1),spread(f1,f2,tb1.f1) from tb1 where f1 > 0 group by f1 having avg(f1) > 0 order by f1; if $rows != 4 then return -1 endi @@ -1483,7 +1481,7 @@ if $data33 != 0.000000000 then return -1 endi -sql select avg(f1),spread(f1,f2,tb1.f1) from tb1 where f1 > 2 group by f1 having avg(f1) > 0; +sql select avg(f1),spread(f1,f2,tb1.f1) from tb1 where f1 > 2 group by f1 having avg(f1) > 0 order by f1; if $rows != 2 then return -1 endi @@ -1512,7 +1510,7 @@ if $data13 != 0.000000000 then return -1 endi -sql select avg(f1),spread(f1,f2,tb1.f1) from tb1 where f2 > 2 group by f1 having avg(f1) > 0; +sql select avg(f1),spread(f1,f2,tb1.f1) from tb1 where f2 > 2 group by f1 having avg(f1) > 0 order by f1; if $rows != 2 then return -1 endi @@ -1541,7 +1539,7 @@ if $data13 != 0.000000000 then return -1 endi -sql select avg(f1),spread(f1,f2,tb1.f1) from tb1 where f3 > 2 group by f1 having avg(f1) > 0; +sql select avg(f1),spread(f1,f2,tb1.f1) from tb1 where f3 > 2 group by f1 having avg(f1) > 0 order by f1; if $rows != 2 then return -1 endi @@ -1570,7 +1568,7 @@ if $data13 != 0.000000000 then return -1 endi -sql select avg(f1),spread(f1,f2,tb1.f1) from tb1 where f2 > 3 group by f1 having avg(f1) > 0; +sql select avg(f1),spread(f1,f2,tb1.f1) from tb1 where f2 > 3 group by f1 having avg(f1) > 0 order by f1; if $rows != 1 then return -1 endi @@ -1595,7 +1593,7 @@ sql_error select avg(f1),spread(f1,f2,tb1.f1) from tb1 where f2 > 3 group by f1 sql_error select avg(f1),spread(f1,f2,tb1.f1) from tb1 where f2 > 3 group by f1 having avg(f9) > 0; -sql select avg(f1),spread(f1,f2,tb1.f1) from tb1 where f2 > 3 group by f1 having count(f9) > 0; +sql select avg(f1),spread(f1,f2,tb1.f1) from tb1 where f2 > 3 group by f1 having count(f9) > 0 order by f1; if $rows != 1 then return -1 endi @@ -1614,7 +1612,7 @@ endi sql_error select avg(f1),spread(f1,f2,tb1.f1) from tb1 where f2 > 3 group by f1 having last(f9) > 0; -sql select avg(f1),spread(f1,f2,tb1.f1) from tb1 where f2 > 3 group by f1 having last(f2) > 0; +sql select avg(f1),spread(f1,f2,tb1.f1) from tb1 where f2 > 3 group by f1 having last(f2) > 0 order by f1; if $rows != 1 then return -1 endi @@ -1631,7 +1629,7 @@ if $data03 != 0.000000000 then return -1 endi -sql select avg(f1),spread(f1,f2,tb1.f1) from tb1 where f2 > 3 group by f1 having last(f3) > 0; +sql select avg(f1),spread(f1,f2,tb1.f1) from tb1 where f2 > 3 group by f1 having last(f3) > 0 order by f1; if $rows != 1 then return -1 endi @@ -1648,7 +1646,7 @@ if $data03 != 0.000000000 then return -1 endi -sql select avg(f1),spread(f1,f2,tb1.f1) from tb1 where f2 > 1 group by f1 having last(f3) > 0; +sql select avg(f1),spread(f1,f2,tb1.f1) from tb1 where f2 > 1 group by f1 having last(f3) > 0 order by f1; if $rows != 3 then return -1 endi @@ -1689,7 +1687,7 @@ if $data23 != 0.000000000 then return -1 endi -sql select avg(f1),spread(f1,f2,tb1.f1) from tb1 where f2 > 1 group by f1 having last(f4) > 0; +sql select avg(f1),spread(f1,f2,tb1.f1) from tb1 where f2 > 1 group by f1 having last(f4) > 0 order by f1; if $rows != 3 then return -1 endi @@ -1730,7 +1728,7 @@ if $data23 != 0.000000000 then return -1 endi -sql select avg(f1),spread(f1,f2,tb1.f1) from tb1 where f2 > 1 group by f1 having last(f5) > 0; +sql select avg(f1),spread(f1,f2,tb1.f1) from tb1 where f2 > 1 group by f1 having last(f5) > 0 order by f1; if $rows != 3 then return -1 endi @@ -1771,7 +1769,7 @@ if $data23 != 0.000000000 then return -1 endi -sql select avg(f1),spread(f1,f2,tb1.f1) from tb1 where f2 > 1 group by f1 having last(f6) > 0; +sql select avg(f1),spread(f1,f2,tb1.f1) from tb1 where f2 > 1 group by f1 having last(f6) > 0 order by f1; if $rows != 3 then return -1 endi @@ -1823,7 +1821,7 @@ sql_error select avg(f1),spread(f1,f2,tb1.f1),f1,f6 from tb1 where f2 > 1 group sql_error select avg(f1),spread(f1,f2,tb1.f1),f1,f6 from tb1 where f2 > 1 group by id1 having last(f6) > 0; -sql select avg(f1),spread(f1,f2,tb1.f1) from tb1 where f2 > 1 and f2 < 4 group by f1 having last(f6) > 0; +sql select avg(f1),spread(f1,f2,tb1.f1) from tb1 where f2 > 1 and f2 < 4 group by f1 having last(f6) > 0 order by f1; if $rows != 2 then return -1 endi From fc7887e6b7b957648275f93fdaef3f57c867e6d2 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Wed, 20 Jul 2022 17:24:49 +0800 Subject: [PATCH 38/45] fix(query): update the sim. --- include/common/ttime.h | 1 - source/common/src/ttime.c | 26 -------------------------- source/libs/scalar/src/sclvector.c | 2 +- tests/script/tsim/scalar/scalar.sim | 9 ++++++--- 4 files changed, 7 insertions(+), 31 deletions(-) diff --git a/include/common/ttime.h b/include/common/ttime.h index 2f4129f979..8f4f4f15d8 100644 --- a/include/common/ttime.h +++ b/include/common/ttime.h @@ -73,7 +73,6 @@ static FORCE_INLINE int64_t taosGetTimestampToday(int32_t precision) { } int64_t taosTimeAdd(int64_t t, int64_t duration, char unit, int32_t precision); -int64_t taosTimeSub(int64_t t, int64_t duration, char unit, int32_t precision); int64_t taosTimeTruncate(int64_t t, const SInterval* pInterval, int32_t precision); int32_t taosTimeCountInterval(int64_t skey, int64_t ekey, int64_t interval, char unit, int32_t precision); diff --git a/source/common/src/ttime.c b/source/common/src/ttime.c index 8f150441f9..b1e4321053 100644 --- a/source/common/src/ttime.c +++ b/source/common/src/ttime.c @@ -712,32 +712,6 @@ int64_t taosTimeAdd(int64_t t, int64_t duration, char unit, int32_t precision) { return (int64_t)(taosMktime(&tm) * TSDB_TICK_PER_SECOND(precision) + fraction); } -int64_t taosTimeSub(int64_t t, int64_t duration, char unit, int32_t precision) { - if (duration == 0) { - return t; - } - - if (unit != 'n' && unit != 'y') { - return t - duration; - } - - // The following code handles the y/n time duration - int64_t numOfMonth = duration; - if (unit == 'y') { - numOfMonth *= 12; - } - - struct tm tm; - time_t tt = (time_t)(t / TSDB_TICK_PER_SECOND(precision)); - taosLocalTime(&tt, &tm); - int32_t mon = tm.tm_year * 12 + tm.tm_mon - (int32_t)numOfMonth; - tm.tm_year = mon / 12; - tm.tm_mon = mon % 12; - - return (int64_t)(taosMktime(&tm) * TSDB_TICK_PER_SECOND(precision)); -} - - int32_t taosTimeCountInterval(int64_t skey, int64_t ekey, int64_t interval, char unit, int32_t precision) { if (ekey < skey) { int64_t tmp = ekey; diff --git a/source/libs/scalar/src/sclvector.c b/source/libs/scalar/src/sclvector.c index 76de4da4fd..254c99f05d 100644 --- a/source/libs/scalar/src/sclvector.c +++ b/source/libs/scalar/src/sclvector.c @@ -1195,7 +1195,7 @@ static void vectorMathTsSubHelper(SColumnInfoData* pLeftCol, SColumnInfoData* pR colDataAppendNULL(pOutputCol, i); continue; // TODO set null or ignore } - *output = taosTimeSub(getVectorBigintValueFnLeft(pLeftCol->pData, i), getVectorBigintValueFnRight(pRightCol->pData, 0), + *output = taosTimeAdd(getVectorBigintValueFnLeft(pLeftCol->pData, i), -getVectorBigintValueFnRight(pRightCol->pData, 0), pRightCol->info.scale, pRightCol->info.precision); } diff --git a/tests/script/tsim/scalar/scalar.sim b/tests/script/tsim/scalar/scalar.sim index 32224e33ba..29cc67ec24 100644 --- a/tests/script/tsim/scalar/scalar.sim +++ b/tests/script/tsim/scalar/scalar.sim @@ -43,7 +43,8 @@ sql select cast(1 as timestamp)+1n; if $rows != 1 then return -1 endi -if $data00 != @70-02-01 08:00:00.000@ then +if $data00 != @70-02-01 08:00:00.001@ then + print expect 70-02-01 08:00:00.001, actual: $data00 return -1 endi @@ -52,11 +53,13 @@ if $rows != 1 then return -1 endi -sql select cast(1 as timestamp)-1y; +# there is an *bug* in print timestamp that smaller than 0, so let's try value that is greater than 0. +sql select cast(1 as timestamp)+1y; if $rows != 1 then return -1 endi -if $data00 != @69-01-01 08:00:00.000@ then +if $data00 != @71-01-01 08:00:00.001@ then + print expect 71-01-01 08:00:00.001 , actual: $data00 return -1 endi From b4e8fc39368f3d662e86a0157ee9fc1b3dde8a32 Mon Sep 17 00:00:00 2001 From: Shuduo Sang Date: Wed, 20 Jul 2022 17:32:47 +0800 Subject: [PATCH 39/45] feat: update taostools for3.0 (#15189) * feat: update taos-tools for 3.0 [TD-14141] * feat: update taos-tools for 3.0 * feat: update taos-tools for 3.0 * feat: update taos-tools for 3.0 * feat: update taos-tools for 3.0 * feat: update taos-tools for 3.0 * feat: update taos-tools for 3.0 * feat: update taos-tools for 3.0 --- tools/taos-tools | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/taos-tools b/tools/taos-tools index 2b75339b8b..f84cb6e515 160000 --- a/tools/taos-tools +++ b/tools/taos-tools @@ -1 +1 @@ -Subproject commit 2b75339b8b5c239619d1f09970d03075c58140dd +Subproject commit f84cb6e51556d8030585128c2b252aa2a6453328 From 90b73eb399406d6850ccfba5f1ce4a19a6a04edc Mon Sep 17 00:00:00 2001 From: afwerar <1296468573@qq.com> Date: Wed, 20 Jul 2022 17:36:23 +0800 Subject: [PATCH 40/45] test: no valgrind on win --- tests/script/test-all.bat | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/script/test-all.bat b/tests/script/test-all.bat index 056d989e6b..229302fd1e 100644 --- a/tests/script/test-all.bat +++ b/tests/script/test-all.bat @@ -63,4 +63,5 @@ goto :eof :CheckSkipCase set skipCase=false @REM if "%*" == "./test.sh -f tsim/query/scalarFunction.sim" ( set skipCase=true ) +echo %* | grep valgrind && set skipCase=true :goto eof \ No newline at end of file From 9ef4f7f429e2d4252c8da394f092a5061340cbb4 Mon Sep 17 00:00:00 2001 From: afwerar <1296468573@qq.com> Date: Wed, 20 Jul 2022 18:05:56 +0800 Subject: [PATCH 41/45] test: close tmqUdf case --- .../script/tsim/query/charScalarFunction.sim | 683 ------------------ 1 file changed, 683 deletions(-) diff --git a/tests/script/tsim/query/charScalarFunction.sim b/tests/script/tsim/query/charScalarFunction.sim index f1575d7293..ce140a116c 100644 --- a/tests/script/tsim/query/charScalarFunction.sim +++ b/tests/script/tsim/query/charScalarFunction.sim @@ -35,695 +35,12 @@ print $data10 $data11 $data12 $data13 $data14 $data15 $data16 $data17 $data18 $d sql use $dbNamme -print =============== create super table -sql create table stb (ts timestamp, c1 binary(128), c2 nchar(128)) tags (t1 binary(128), t2 nchar(128)) - -print =============== create child table and normal table, insert data -sql create table ctb0 using stb tags("tag-binary-0" , "tag-nchar-0" ) -sql create table ntb0 (ts timestamp, c1 binary(128), c2 nchar(128)) -sql insert into ctb0 values ("2022-01-01 00:00:00.000" , "lenByte0=11" , "lenByte0=44" ) -sql insert into ntb0 values ("2022-01-01 00:00:00.000" , "lenByte0=11" , "lenByte0=44" ) -sql insert into ctb0 values ("2022-01-01 00:00:00.001" , "lenByte01=12" , "lenByte01=48" ) -sql insert into ntb0 values ("2022-01-01 00:00:00.001" , "lenByte01=12" , "lenByte01=48" ) -sql insert into ctb0 values ("2022-01-01 00:00:00.002" , "lenChar01=12" , "lenChar01=48" ) -sql insert into ntb0 values ("2022-01-01 00:00:00.002" , "lenChar01=12" , "lenChar01=48" ) -sql insert into ctb0 values ("2022-01-01 00:00:00.003" , "lenChar0001=14" , "lenChar0001=56" ) -sql insert into ntb0 values ("2022-01-01 00:00:00.003" , "lenChar0001=14" , "lenChar0001=56" ) - -sql create table ctb1 using stb tags("tag-binary-1" , "tag-nchar-1" ) -sql create table ntb1 (ts timestamp, c1 binary(128), c2 nchar(128)) -sql insert into ctb1 values ("2022-01-01 00:00:00.000" , "ABCD1234" , "ABCD1234" ) -sql insert into ntb1 values ("2022-01-01 00:00:00.000" , "ABCD1234" , "ABCD1234" ) -sql insert into ctb1 values ("2022-01-01 00:00:00.001" , "AaBbCcDd1234" , "AaBbCcDd1234" ) -sql insert into ntb1 values ("2022-01-01 00:00:00.001" , "AaBbCcDd1234" , "AaBbCcDd1234" ) - -sql create table ctb2 using stb tags("tag-binary-2" , "tag-nchar-2" ) -sql create table ntb2 (ts timestamp, c1 binary(128), c2 nchar(128)) -sql insert into ctb2 values ("2022-01-01 00:00:00.000" , "abcd1234" , "abcd1234" ) -sql insert into ntb2 values ("2022-01-01 00:00:00.000" , "abcd1234" , "abcd1234" ) -sql insert into ctb2 values ("2022-01-01 00:00:00.001" , "AaBbCcDd1234" , "AaBbCcDd1234" ) -sql insert into ntb2 values ("2022-01-01 00:00:00.001" , "AaBbCcDd1234" , "AaBbCcDd1234" ) - -sql create table ctb3 using stb tags("tag-binary-3" , "tag-nchar-3" ) -sql create table ntb3 (ts timestamp, c1 binary(128), c2 nchar(128)) -sql insert into ctb3 values ("2022-01-01 00:00:00.000" , " abcd 1234 " , " abcd 1234 " ) -sql insert into ntb3 values ("2022-01-01 00:00:00.000" , " abcd 1234 " , " abcd 1234 " ) - -sql create table stb2 (ts timestamp, c1 binary(128), c2 nchar(128), c3 binary(128), c4 nchar(128)) tags (t1 binary(128), t2 nchar(128), t3 binary(128), t4 nchar(128)) -sql create table ctb4 using stb2 tags("tag-binary-4" , "tag-nchar-4", "tag-binary-4" , "tag-nchar-4") -sql create table ntb4 (ts timestamp, c1 binary(128), c2 nchar(128), c3 binary(128), c4 nchar(128)) -sql insert into ctb4 values ("2022-01-01 00:00:00.000" , " ab 12 " , " ab 12 " , " cd 34 " , " cd 34 " ) -sql insert into ntb4 values ("2022-01-01 00:00:00.000" , " ab 12 " , " ab 12 " , " cd 34 " , " cd 34 " ) - -sql create table ctb5 using stb tags("tag-binary-5" , "tag-nchar-5") -sql create table ntb5 (ts timestamp, c1 binary(128), c2 nchar(128)) -sql insert into ctb5 values ("2022-01-01 00:00:00.000" , "0123456789" , "0123456789" ) -sql insert into ntb5 values ("2022-01-01 00:00:00.000" , "0123456789" , "0123456789" ) -sql insert into ctb5 values ("2022-01-01 00:00:00.001" , NULL , NULL ) -sql insert into ntb5 values ("2022-01-01 00:00:00.001" , NULL , NULL ) - sql create table stb3 (ts timestamp, c1 binary(64), c2 nchar(64), c3 nchar(64) ) tags (t1 nchar(64)) sql create table ctb6 using stb3 tags("tag-nchar-6") -sql create table ntb6 (ts timestamp, c1 binary(64), c2 nchar(64), c3 nchar(64) ) sql insert into ctb6 values ("2022-01-01 00:00:00.000" , "0123456789" , "中文测试1" , "中文测试2" ) -sql insert into ntb6 values ("2022-01-01 00:00:00.000" , "0123456789" , "中文测试01", "中文测试01" ) sql insert into ctb6 values ("2022-01-01 00:00:00.001" , NULL , NULL, NULL ) -sql insert into ntb6 values ("2022-01-01 00:00:00.001" , NULL , NULL, NULL ) -$loop_test = 0 -loop_test_pos: - -print ====> length -print ====> select c1, length(c1), c2, length(c2) from ctb0 -sql select c1, length(c1), c2, length(c2) from ctb0 -print ====> rows: $rows -print ====> $data00 $data01 $data02 $data03 $data04 $data05 -print ====> $data10 $data11 $data12 $data13 $data14 $data15 -print ====> $data20 $data21 $data22 $data23 $data24 $data25 -print ====> $data30 $data31 $data32 $data33 $data34 $data35 -if $rows != 4 then - return -1 -endi -if $data01 != 11 then - return -1 -endi -if $data03 != 44 then - return -1 -endi -if $data11 != 12 then - return -1 -endi -if $data13 != 48 then - return -1 -endi - -print ====> select c1, length(c1), c2, length(c2) from ntb0 -sql select c1, length(c1), c2, length(c2) from ntb0 -print ====> rows: $rows -print ====> $data00 $data01 $data02 $data03 $data04 $data05 -print ====> $data10 $data11 $data12 $data13 $data14 $data15 -print ====> $data20 $data21 $data22 $data23 $data24 $data25 -print ====> $data30 $data31 $data32 $data33 $data34 $data35 -if $rows != 4 then - return -1 -endi -if $data01 != 11 then - return -1 -endi -if $data03 != 44 then - return -1 -endi -if $data11 != 12 then - return -1 -endi -if $data13 != 48 then - return -1 -endi - -print ====> select length("abcd1234"), char_length("abcd1234=-+*") from ntb0 -sql select length("abcd1234"), char_length("abcd1234=-+*") from ntb0 -print ====> rows: $rows -print ====> $data00 $data01 $data02 $data03 $data04 $data05 -print ====> $data10 $data11 $data12 $data13 $data14 $data15 -print ====> $data20 $data21 $data22 $data23 $data24 $data25 -print ====> $data30 $data31 $data32 $data33 $data34 $data35 -if $rows != 4 then - return -1 -endi -if $data00 != 8 then - return -1 -endi -if $data01 != 12 then - return -1 -endi print ====> select c2 ,length(c2), char_length(c2) from ctb6 sql select c2 ,length(c2), char_length(c2) from ctb6 -print ====> rows: $rows -print ====> $data00 $data01 $data02 -print ====> $data10 $data11 $data12 -if $rows != 2 then - return -1 -endi -if $data01 != 20 then - return -1 -endi -if $data02 != 5 then - return -1 -endi -if $data11 != NULL then - return -1 -endi -print ====> select c2 ,length(c2),char_length(c2) from ntb6 -sql select c2 ,length(c2),char_length(c2) from ntb6 -print ====> rows: $rows -print ====> $data00 $data01 $data02 -print ====> $data10 $data11 $data12 -if $rows != 2 then - return -1 -endi -if $data01 != 24 then - return -1 -endi -if $data02 != 6 then - return -1 -endi -if $data11 != NULL then - return -1 -endi - -print ====> select c2 ,lower(c2), upper(c2) from ctb6 -sql select c2 ,lower(c2), upper(c2) from ctb6 -print ====> rows: $rows -print ====> $data00 $data01 $data02 -print ====> $data10 $data11 $data12 -if $rows != 2 then - return -1 -endi -if $data01 != 中文测试1 then - return -1 -endi -if $data02 != 中文测试1 then - return -1 -endi -if $data11 != NULL then - return -1 -endi - -print ====> select c2 ,lower(c2), upper(c2) from ntb6 -sql select c2 ,lower(c2), upper(c2) from ntb6 -print ====> rows: $rows -print ====> $data00 $data01 $data02 -print ====> $data10 $data11 $data12 -if $rows != 2 then - return -1 -endi -if $data01 != 中文测试01 then - return -1 -endi -if $data02 != 中文测试01 then - return -1 -endi -if $data11 != NULL then - return -1 -endi - -print ====> select c2, ltrim(c2), ltrim(c2) from ctb6 -sql select c2, ltrim(c2), ltrim(c2) from ctb6 -print ====> rows: $rows -print ====> $data00 $data01 $data02 -print ====> $data10 $data11 $data12 -if $rows != 2 then - return -1 -endi -if $data01 != 中文测试1 then - return -1 -endi -if $data02 != 中文测试1 then - return -1 -endi -if $data11 != NULL then - return -1 -endi - -print ====> select c2, ltrim(c2), ltrim(c2) from ntb6 -sql select c2, ltrim(c2), ltrim(c2) from ntb6 -print ====> rows: $rows -print ====> $data00 $data01 $data02 -print ====> $data10 $data11 $data12 -if $rows != 2 then - return -1 -endi -if $data01 != 中文测试01 then - return -1 -endi -if $data02 != 中文测试01 then - return -1 -endi -if $data11 != NULL then - return -1 -endi - -print ====> select c2, c3 , concat(c2,c3) from ctb6 -sql select c2, c3 , concat(c2,c3) from ctb6 -print ====> rows: $rows -print ====> $data00 $data01 $data02 -print ====> $data10 $data11 $data12 -if $rows != 2 then - return -1 -endi -if $data02 != 中文测试1中文测试2 then - return -1 -endi -if $data12 != NULL then - return -1 -endi - -print ====> select c2, c3 , concat(c2,c3) from ntb6 -sql select c2, c3 , concat(c2,c3) from ntb6 -print ====> rows: $rows -print ====> $data00 $data01 $data02 -print ====> $data10 $data11 $data12 -if $rows != 2 then - return -1 -endi -if $data02 != 中文测试01中文测试01 then - return -1 -endi -if $data12 != NULL then - return -1 -endi - -print ====> select c2, c3 , concat_ws('_', c2, c3) from ctb6 -sql select c2, c3 , concat_ws('_', c2, c3) from ctb6 -print ====> rows: $rows -print ====> $data00 $data01 $data02 -print ====> $data10 $data11 $data12 -if $rows != 2 then - return -1 -endi -if $data02 != 中文测试1_中文测试2 then - return -1 -endi -# if $data12 != NULL then -# return -1 -# endi - -print ====> select c2, c3 , concat_ws('_', c2, c3) from ntb6 -sql select c2, c3 , concat_ws('_', c2, c3) from ntb6 -print ====> rows: $rows -print ====> $data00 $data01 $data02 -print ====> $data10 $data11 $data12 -if $rows != 2 then - return -1 -endi -if $data02 != 中文测试01_中文测试01 then - return -1 -endi -# if $data12 != NULL then -# return -1 -# endi - -print ====> select c2, substr(c2,1, 4) from ctb6 -sql select c2, substr(c2,1, 4) from ctb6 -print ====> rows: $rows -print ====> $data00 $data01 -print ====> $data10 $data11 -if $rows != 2 then - return -1 -endi -if $data00 != 中文测试1 then - return -1 -endi -if $data01 != 中文测试 then - return -1 -endi -# if $data11 != NULL then -# return -1 -# endi - -print ====> select c2, substr(c2,1, 4) from ntb6 -sql select c2, substr(c2,1, 4) from ntb6 -print ====> rows: $rows -print ====> $data00 $data01 -print ====> $data10 $data11 -if $rows != 2 then - return -1 -endi -if $data00 != 中文测试01 then - return -1 -endi -if $data01 != 中文测试 then - return -1 -endi -if $data11 != NULL then - return -1 -endi - -#sql_error select c1, length(t1), c2, length(t2) from ctb0 - -print ====> char_length -print ====> select c1, char_length(c1), c2, char_length(c2) from ctb0 -sql select c1, char_length(c1), c2, char_length(c2) from ctb0 -print ====> rows: $rows -print ====> $data00 $data01 $data02 $data03 $data04 $data05 -print ====> $data10 $data11 $data12 $data13 $data14 $data15 -print ====> $data20 $data21 $data22 $data23 $data24 $data25 -print ====> $data30 $data31 $data32 $data33 $data34 $data35 -if $rows != 4 then - return -1 -endi -if $data21 != 12 then - return -1 -endi -if $data23 != 12 then - return -1 -endi -if $data31 != 14 then - return -1 -endi -if $data33 != 14 then - return -1 -endi - -print ====> select c1, char_length(c1), c2, char_length(c2) from ntb0 -sql select c1, char_length(c1), c2, char_length(c2) from ntb0 -print ====> rows: $rows -print ====> $data00 $data01 $data02 $data03 $data04 $data05 -print ====> $data10 $data11 $data12 $data13 $data14 $data15 -print ====> $data20 $data21 $data22 $data23 $data24 $data25 -print ====> $data30 $data31 $data32 $data33 $data34 $data35 -if $rows != 4 then - return -1 -endi -if $data21 != 12 then - return -1 -endi -if $data23 != 12 then - return -1 -endi -if $data31 != 14 then - return -1 -endi -if $data33 != 14 then - return -1 -endi - -#sql_error select c1, char_length(t1), c2, char_length(t2) from ctb0 - -print ====> lower -sql select c1, lower(c1), c2, lower(c2), lower("abcdEFGH=-*&%") from ntb1 -print ====> select c1, lower(c1), c2, lower(c2), lower("abcdEFGH=-*&%") from ctb1 -sql select c1, lower(c1), c2, lower(c2), lower("abcdEFGH=-*&%") from ctb1 -print ====> rows: $rows -print ====> $data00 $data01 $data02 $data03 $data04 $data05 -print ====> $data10 $data11 $data12 $data13 $data14 $data15 -if $rows != 2 then - return -1 -endi -if $data01 != abcd1234 then - return -1 -endi -if $data03 != abcd1234 then - return -1 -endi -if $data04 != abcdefgh=-*&% then - return -1 -endi -if $data11 != aabbccdd1234 then - return -1 -endi -if $data13 != aabbccdd1234 then - return -1 -endi -if $data14 != abcdefgh=-*&% then - return -1 -endi - -#sql_error select c1, lower(t1), c2, lower(t2) from ctb1 - -print ====> upper -sql select c1, upper(c1), c2, upper(c2), upper("abcdEFGH=-*&%") from ntb2 -print ====> select c1, upper(c1), c2, upper(c2), upper("abcdEFGH=-*&%") from ctb2 -sql select c1, upper(c1), c2, upper(c2), upper("abcdEFGH=-*&%") from ctb2 -print ====> rows: $rows -print ====> $data00 $data01 $data02 $data03 $data04 $data05 -print ====> $data10 $data11 $data12 $data13 $data14 $data15 -if $rows != 2 then - return -1 -endi -if $data01 != ABCD1234 then - return -1 -endi -if $data03 != ABCD1234 then - return -1 -endi -if $data04 != ABCDEFGH=-*&% then - return -1 -endi -if $data11 != AABBCCDD1234 then - return -1 -endi -if $data13 != AABBCCDD1234 then - return -1 -endi -if $data14 != ABCDEFGH=-*&% then - return -1 -endi - -#sql_error select c1, upper(t1), c2, upper(t2) from ctb2 - -print ====> ltrim -sql select c1, ltrim(c1), c2, ltrim(c2), ltrim(" abcdEFGH =-*&% ") from ntb3 -print ====> select c1, ltrim(c1), c2, ltrim(c2), ltrim(" abcdEFGH =-*&% ") from ctb3 -sql select c1, ltrim(c1), c2, ltrim(c2), ltrim(" abcdEFGH =-*&% ") from ctb3 -print ====> rows: $rows -print ====> $data00 $data01 $data02 $data03 $data04 $data05 -print ====> $data10 $data11 $data12 $data13 $data14 $data15 -if $rows != 1 then - return -1 -endi -if $data01 != @abcd 1234 @ then - return -1 -endi -if $data03 != @abcd 1234 @ then - return -1 -endi -if $data04 != @abcdEFGH =-*&% @ then - return -1 -endi - -#sql_error select c1, ltrim(t1), c2, ltrim(t2) from ctb3 - - -print ====> rtrim -sql select c1, rtrim(c1), c2, rtrim(c2), rtrim(" abcdEFGH =-*&% ") from ntb3 -print ====> select c1, rtrim(c1), c2, rtrim(c2), rtrim(" abcdEFGH =-*&% ") from ctb3 -sql select c1, rtrim(c1), c2, rtrim(c2), rtrim(" abcdEFGH =-*&% ") from ctb3 -print ====> rows: $rows -print ====> [ $data00 ] [ $data01 ] [ $data02 ] [ $data03 ] [ $data04 ] [ $data05 ] [ $data06 ] -print ====> $data10 $data11 $data12 $data13 $data14 $data15 -if $rows != 1 then - return -1 -endi -if $data01 != @ abcd 1234@ then - return -1 -endi -if $data03 != @ abcd 1234@ then - return -1 -endi -if $data04 != @ abcdEFGH =-*&%@ then - return -1 -endi - -#sql_error select c1, rtrim(t1), c2, rtrim(t2) from ctb3 - -print ====> concat -sql select c1, c3, concat(c1, c3), c2, c4, concat(c2, c4), concat("binary+", c1, c3), concat("nchar+", c2, c4) from ntb4 -print ====> select c1, c3, concat(c1, c3), c2, c4, concat(c2, c4), concat("binary+", c1, c3), concat("nchar+", c2, c4) from ctb4 -sql select c1, c3, concat(c1, c3), c2, c4, concat(c2, c4), concat("binary+", c1, c3), concat("nchar+", c2, c4) from ctb4 -print ====> rows: $rows -print ====> $data00 $data01 $data02 $data03 $data04 $data05 $data06 -print ====> $data10 $data11 $data12 $data13 $data14 $data15 $data16 -if $rows != 1 then - return -1 -endi -if $data02 != @ ab 12 cd 34 @ then - return -1 -endi -if $data05 != @ ab 12 cd 34 @ then - return -1 -endi -if $data06 != @binary+ ab 12 cd 34 @ then - return -1 -endi -if $data07 != @nchar+ ab 12 cd 34 @ then - return -1 -endi - -sql select c1, c3, concat("bin-", c1, "-a1-", "a2-", c3, "-a3-", "a4-", "END"), c2, c4, concat("nchar-", c2, "-a1-", "-a2-", c4, "-a3-", "a4-", "END") from ntb4 -print ====> select c1, c3, concat("bin-", c1, "-a1-", "a2-", c3, "-a3-", "a4-", "END"), c2, c4, concat("nchar-", c2, "-a1-", "a2-", c4, "-a3-", "a4-", "END") from ctb4 -sql select c1, c3, concat("bin-", c1, "-a1-", "a2-", c3, "-a3-", "a4-", "END"), c2, c4, concat("nchar-", c2, "-a1-", "a2-", c4, "-a3-", "a4-", "END") from ctb4 -print ====> rows: $rows -print ====> [ $data00 ] [ $data01 ] [ $data02 ] [ $data03 ] [ $data04 ] [ $data05 ] [ $data06 ] -print ====> $data10 $data11 $data12 $data13 $data14 $data15 $data16 -if $rows != 1 then - return -1 -endi -if $data02 != @bin- ab 12 -a1-a2- cd 34 -a3-a4-END@ then - return -1 -endi -if $data05 != @nchar- ab 12 -a1-a2- cd 34 -a3-a4-END@ then - return -1 -endi - -#sql_error select c1, c2, concat(c1, c2), c3, c4, concat(c3, c4) from ctb4 -#sql_error select t1, t2, concat(t1, t2), t3, t4, concat(t3, t4) from ctb4 -#sql_error select t1, t3, concat(t1, t3), t2, t4, concat(t2, t4) from ctb4 - -print ====> concat_ws -sql select c1, c3, concat_ws("*", c1, c3), c2, c4, concat_ws("*", c2, c4), concat_ws("*", "binary+", c1, c3), concat_ws("*", "nchar+", c2, c4) from ntb4 -print ====> select c1, c3, concat_ws("*", c1, c3), c2, c4, concat_ws("*", c2, c4), concat_ws("*", "binary+", c1, c3), concat_ws("*", "nchar+", c2, c4) from ctb4 -sql select c1, c3, concat_ws("*", c1, c3), c2, c4, concat_ws("*", c2, c4), concat_ws("*", "binary+", c1, c3), concat_ws("*", "nchar+", c2, c4) from ctb4 -print ====> rows: $rows -print ====> $data00 $data01 $data02 $data03 $data04 $data05 $data06 -print ====> $data10 $data11 $data12 $data13 $data14 $data15 $data16 -if $rows != 1 then - return -1 -endi -if $data02 != @ ab 12 * cd 34 @ then - return -1 -endi -if $data05 != @ ab 12 * cd 34 @ then - return -1 -endi -if $data06 != @binary+* ab 12 * cd 34 @ then - return -1 -endi -if $data07 != @nchar+* ab 12 * cd 34 @ then - return -1 -endi - -print ====> select c1, c3, concat_ws("*", "b0", c1, "b1", c3, "b2", "E0", "E1", "E2"), c2, c4, concat_ws("*", "n0", c2, c4, "n1", c2, c4, "n2", "END") from ctb4 -sql select c1, c3, concat_ws("*", "b0", c1, "b1", c3, "b2", "E0", "E1", "E2"), c2, c4, concat_ws("*", "n0", c2, c4, "n1", c2, c4, "n2", "END") from ctb4 -print ====> rows: $rows -print ====> [ $data00 ] [ $data01 ] [ $data02 ] [ $data03 ] [ $data04 ] [ $data05 ] [ $data06 ] -print ====> $data10 $data11 $data12 $data13 $data14 $data15 $data16 -if $rows != 1 then - return -1 -endi -if $data02 != @b0* ab 12 *b1* cd 34 *b2*E0*E1*E2@ then - return -1 -endi -if $data05 != @n0* ab 12 * cd 34 *n1* ab 12 * cd 34 *n2*END@ then - return -1 -endi - -#sql_error select c1, c2, concat_ws("*", c1, c2), c3, c4, concat_ws("*", c3, c4) from ctb4 -#sql_error select t1, t2, concat_ws("*", t1, t2), t3, t4, concat_ws("*", t3, t4) from ctb4 -#sql_error select t1, t3, concat_ws("*", t1, t3), t2, t4, concat_ws("*", t2, t4) from ctb4 - - -print ====> substr -#sql select c1, substr(c1, 3, 3), substr(c1, -5, 3), c2, substr(c2, 3, 3), substr(c2, -5, 3), substr("abcdefg", 3, 3), substr("abcdefg", -3, 3) from ntb5 -#print ====> select c1, substr(c1, 3, 3), substr(c1, -5, 3), c2, substr(c2, 3, 3), substr(c2, -5, 3), substr("abcdefg", 3, 3), substr("abcdefg", -3, 3) from ctb5 -#sql select c1, substr(c1, 3, 3), substr(c1, -5, 3), c2, substr(c2, 3, 3), substr(c2, -5, 3), substr("abcdefg", 3, 3), substr("abcdefg", -3, 3) from ctb5 -#print ====> rows: $rows -#print ====> $data00 $data01 $data02 $data03 $data04 $data05 $data06 -#print ====> $data10 $data11 $data12 $data13 $data14 $data15 $data16 -#if $rows != 1 then -# return -1 -#endi -#if $data01 != 345 then -# return -1 -#endi -#if $data02 != 456 then -# return -1 -#endi -#if $data04 != 345 then -# return -1 -#endi -#if $data05 != 456 then -# return -1 -#endi -#if $data06 != def then -# return -1 -#endi -#if $data07 != efg then -# return -1 -#endi -#if $data11 != NULL then -# return -1 -#endi -#if $data12 != NULL then -# return -1 -#endi -#if $data14 != NULL then -# return -1 -#endi -#if $data15 != NULL then -# return -1 -#endi -#if $data16 != def then -# return -1 -#endi -#if $data17 != efg then -# return -1 -#endi -# -#sql select c1, substr(c1, 3), substr(c1, -5), c2, substr(c2, 3), substr(c2, -5), substr("abcdefg", 3), substr("abcdefg", -3) from ntb5 -#print ====> select c1, substr(c1, 3), substr(c1, -5), c2, substr(c2, 3), substr(c2, -5), substr("abcdefg", 3), substr("abcdefg", -3) from ctb5 -#sql select c1, substr(c1, 3), substr(c1, -5), c2, substr(c2, 3), substr(c2, -5), substr("abcdefg", 3), substr("abcdefg", -3) from ctb5 -#print ====> rows: $rows -#print ====> $data00 $data01 $data02 $data03 $data04 $data05 $data06 -#print ====> $data10 $data11 $data12 $data13 $data14 $data15 $data16 -#if $rows != 1 then -# return -1 -#endi -#if $data01 != 3456789 then -# return -1 -#endi -#if $data02 != 456789 then -# return -1 -#endi -#if $data04 != 3456789 then -# return -1 -#endi -#if $data05 != 456789 then -# return -1 -#endi -#if $data06 != defg then -# return -1 -#endi -#if $data07 != efg then -# return -1 -#endi -#if $data11 != NULL then -# return -1 -#endi -#if $data12 != NULL then -# return -1 -#endi -#if $data14 != NULL then -# return -1 -#endi -#if $data15 != NULL then -# return -1 -#endi -#if $data16 != defg then -# return -1 -#endi -#if $data17 != efg then -# return -1 -#endi - -#sql_error select t1, substr(t1, 3, 2), substr(t1, -3, 2), t2, substr(t2, 3, 2), substr(t2, -3, 2) from ctb5 - -if $loop_test == 0 then - print =============== stop and restart taosd - system sh/exec.sh -n dnode1 -s stop -x SIGINT - system sh/exec.sh -n dnode1 -s start - - $loop_cnt = 0 - check_dnode_ready_0: - $loop_cnt = $loop_cnt + 1 - sleep 200 - if $loop_cnt == 10 then - print ====> dnode not ready! - return -1 - endi - sql show dnodes - print ===> $rows $data00 $data01 $data02 $data03 $data04 $data05 - if $data00 != 1 then - return -1 - endi - if $data04 != ready then - goto check_dnode_ready_0 - endi - - $loop_test = 1 - goto loop_test_pos -endi - -system sh/exec.sh -n dnode1 -s stop -x SIGINT From 5cc829e45f06d722d07c98fc82ab8a9fc8f257d0 Mon Sep 17 00:00:00 2001 From: Minglei Jin Date: Wed, 20 Jul 2022 18:47:46 +0800 Subject: [PATCH 42/45] fix: use suid from pReader --- source/dnode/vnode/src/tsdb/tsdbRead.c | 31 ++------------------------ 1 file changed, 2 insertions(+), 29 deletions(-) diff --git a/source/dnode/vnode/src/tsdb/tsdbRead.c b/source/dnode/vnode/src/tsdb/tsdbRead.c index 7048dc7b2b..d4055f9482 100644 --- a/source/dnode/vnode/src/tsdb/tsdbRead.c +++ b/source/dnode/vnode/src/tsdb/tsdbRead.c @@ -2572,41 +2572,14 @@ int32_t doMergeRowsInFileBlocks(SBlockData* pBlockData, STableBlockScanInfo* pSc return TSDB_CODE_SUCCESS; } -static tb_uid_t getTableSuidByUid(tb_uid_t uid, STsdb* pTsdb) { - tb_uid_t suid = 0; - - SMetaReader mr = {0}; - metaReaderInit(&mr, pTsdb->pVnode->pMeta, 0); - if (metaGetTableEntryByUid(&mr, uid) < 0) { - metaReaderClear(&mr); // table not esist - return 0; - } - - if (mr.me.type == TSDB_CHILD_TABLE) { - suid = mr.me.ctbEntry.suid; - } else if (mr.me.type == TSDB_NORMAL_TABLE) { - suid = 0; - } else { - suid = 0; - } - - metaReaderClear(&mr); - - return suid; -} - void updateSchema(TSDBROW* pRow, uint64_t uid, STsdbReader* pReader) { int32_t sversion = TSDBROW_SVERSION(pRow); - tb_uid_t suid = getTableSuidByUid(uid, pReader->pTsdb); - if (pReader->pSchema == NULL) { - // pReader->pSchema = metaGetTbTSchema(pReader->pTsdb->pVnode->pMeta, uid, sversion); - metaGetTbTSchemaEx(pReader->pTsdb->pVnode->pMeta, suid, uid, sversion, &pReader->pSchema); + metaGetTbTSchemaEx(pReader->pTsdb->pVnode->pMeta, pReader->suid, uid, sversion, &pReader->pSchema); } else if (pReader->pSchema->version != sversion) { taosMemoryFreeClear(pReader->pSchema); - // pReader->pSchema = metaGetTbTSchema(pReader->pTsdb->pVnode->pMeta, uid, sversion); - metaGetTbTSchemaEx(pReader->pTsdb->pVnode->pMeta, suid, uid, sversion, &pReader->pSchema); + metaGetTbTSchemaEx(pReader->pTsdb->pVnode->pMeta, pReader->suid, uid, sversion, &pReader->pSchema); } } From ecaa0c64bbdeca42715c268fd53e22abfb215dff Mon Sep 17 00:00:00 2001 From: afwerar <1296468573@qq.com> Date: Wed, 20 Jul 2022 18:52:27 +0800 Subject: [PATCH 43/45] test: no valgrind on win --- tests/script/tsim/query/charScalarFunction.sim | 1 - tests/system-test/fulltest.sh | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/script/tsim/query/charScalarFunction.sim b/tests/script/tsim/query/charScalarFunction.sim index ce140a116c..7a9b5a2b97 100644 --- a/tests/script/tsim/query/charScalarFunction.sim +++ b/tests/script/tsim/query/charScalarFunction.sim @@ -43,4 +43,3 @@ sql insert into ctb6 values ("2022-01-01 00:00:00.001" , NULL , NULL, NULL ) print ====> select c2 ,length(c2), char_length(c2) from ctb6 sql select c2 ,length(c2), char_length(c2) from ctb6 - diff --git a/tests/system-test/fulltest.sh b/tests/system-test/fulltest.sh index 10bf3d39e3..dd5f3809e8 100755 --- a/tests/system-test/fulltest.sh +++ b/tests/system-test/fulltest.sh @@ -191,8 +191,8 @@ python3 ./test.py -f 7-tmq/tmqUpdate-multiCtb-snapshot0.py python3 ./test.py -f 7-tmq/tmqUpdate-multiCtb-snapshot1.py #python3 ./test.py -f 7-tmq/tmqDelete-1ctb.py python3 ./test.py -f 7-tmq/tmqUdf.py -python3 ./test.py -f 7-tmq/tmqUdf-multCtb-snapshot0.py -python3 ./test.py -f 7-tmq/tmqUdf-multCtb-snapshot1.py +# python3 ./test.py -f 7-tmq/tmqUdf-multCtb-snapshot0.py +# python3 ./test.py -f 7-tmq/tmqUdf-multCtb-snapshot1.py python3 ./test.py -f 7-tmq/stbTagFilter-1ctb.py python3 ./test.py -f 7-tmq/stbTagFilter-multiCtb.py From 946aef2181595d017b790a834288d54b7e508509 Mon Sep 17 00:00:00 2001 From: afwerar <1296468573@qq.com> Date: Wed, 20 Jul 2022 18:54:01 +0800 Subject: [PATCH 44/45] test: no valgrind on win --- .../script/tsim/query/charScalarFunction.sim | 684 ++++++++++++++++++ 1 file changed, 684 insertions(+) diff --git a/tests/script/tsim/query/charScalarFunction.sim b/tests/script/tsim/query/charScalarFunction.sim index 7a9b5a2b97..f1575d7293 100644 --- a/tests/script/tsim/query/charScalarFunction.sim +++ b/tests/script/tsim/query/charScalarFunction.sim @@ -35,11 +35,695 @@ print $data10 $data11 $data12 $data13 $data14 $data15 $data16 $data17 $data18 $d sql use $dbNamme +print =============== create super table +sql create table stb (ts timestamp, c1 binary(128), c2 nchar(128)) tags (t1 binary(128), t2 nchar(128)) + +print =============== create child table and normal table, insert data +sql create table ctb0 using stb tags("tag-binary-0" , "tag-nchar-0" ) +sql create table ntb0 (ts timestamp, c1 binary(128), c2 nchar(128)) +sql insert into ctb0 values ("2022-01-01 00:00:00.000" , "lenByte0=11" , "lenByte0=44" ) +sql insert into ntb0 values ("2022-01-01 00:00:00.000" , "lenByte0=11" , "lenByte0=44" ) +sql insert into ctb0 values ("2022-01-01 00:00:00.001" , "lenByte01=12" , "lenByte01=48" ) +sql insert into ntb0 values ("2022-01-01 00:00:00.001" , "lenByte01=12" , "lenByte01=48" ) +sql insert into ctb0 values ("2022-01-01 00:00:00.002" , "lenChar01=12" , "lenChar01=48" ) +sql insert into ntb0 values ("2022-01-01 00:00:00.002" , "lenChar01=12" , "lenChar01=48" ) +sql insert into ctb0 values ("2022-01-01 00:00:00.003" , "lenChar0001=14" , "lenChar0001=56" ) +sql insert into ntb0 values ("2022-01-01 00:00:00.003" , "lenChar0001=14" , "lenChar0001=56" ) + +sql create table ctb1 using stb tags("tag-binary-1" , "tag-nchar-1" ) +sql create table ntb1 (ts timestamp, c1 binary(128), c2 nchar(128)) +sql insert into ctb1 values ("2022-01-01 00:00:00.000" , "ABCD1234" , "ABCD1234" ) +sql insert into ntb1 values ("2022-01-01 00:00:00.000" , "ABCD1234" , "ABCD1234" ) +sql insert into ctb1 values ("2022-01-01 00:00:00.001" , "AaBbCcDd1234" , "AaBbCcDd1234" ) +sql insert into ntb1 values ("2022-01-01 00:00:00.001" , "AaBbCcDd1234" , "AaBbCcDd1234" ) + +sql create table ctb2 using stb tags("tag-binary-2" , "tag-nchar-2" ) +sql create table ntb2 (ts timestamp, c1 binary(128), c2 nchar(128)) +sql insert into ctb2 values ("2022-01-01 00:00:00.000" , "abcd1234" , "abcd1234" ) +sql insert into ntb2 values ("2022-01-01 00:00:00.000" , "abcd1234" , "abcd1234" ) +sql insert into ctb2 values ("2022-01-01 00:00:00.001" , "AaBbCcDd1234" , "AaBbCcDd1234" ) +sql insert into ntb2 values ("2022-01-01 00:00:00.001" , "AaBbCcDd1234" , "AaBbCcDd1234" ) + +sql create table ctb3 using stb tags("tag-binary-3" , "tag-nchar-3" ) +sql create table ntb3 (ts timestamp, c1 binary(128), c2 nchar(128)) +sql insert into ctb3 values ("2022-01-01 00:00:00.000" , " abcd 1234 " , " abcd 1234 " ) +sql insert into ntb3 values ("2022-01-01 00:00:00.000" , " abcd 1234 " , " abcd 1234 " ) + +sql create table stb2 (ts timestamp, c1 binary(128), c2 nchar(128), c3 binary(128), c4 nchar(128)) tags (t1 binary(128), t2 nchar(128), t3 binary(128), t4 nchar(128)) +sql create table ctb4 using stb2 tags("tag-binary-4" , "tag-nchar-4", "tag-binary-4" , "tag-nchar-4") +sql create table ntb4 (ts timestamp, c1 binary(128), c2 nchar(128), c3 binary(128), c4 nchar(128)) +sql insert into ctb4 values ("2022-01-01 00:00:00.000" , " ab 12 " , " ab 12 " , " cd 34 " , " cd 34 " ) +sql insert into ntb4 values ("2022-01-01 00:00:00.000" , " ab 12 " , " ab 12 " , " cd 34 " , " cd 34 " ) + +sql create table ctb5 using stb tags("tag-binary-5" , "tag-nchar-5") +sql create table ntb5 (ts timestamp, c1 binary(128), c2 nchar(128)) +sql insert into ctb5 values ("2022-01-01 00:00:00.000" , "0123456789" , "0123456789" ) +sql insert into ntb5 values ("2022-01-01 00:00:00.000" , "0123456789" , "0123456789" ) +sql insert into ctb5 values ("2022-01-01 00:00:00.001" , NULL , NULL ) +sql insert into ntb5 values ("2022-01-01 00:00:00.001" , NULL , NULL ) + sql create table stb3 (ts timestamp, c1 binary(64), c2 nchar(64), c3 nchar(64) ) tags (t1 nchar(64)) sql create table ctb6 using stb3 tags("tag-nchar-6") +sql create table ntb6 (ts timestamp, c1 binary(64), c2 nchar(64), c3 nchar(64) ) sql insert into ctb6 values ("2022-01-01 00:00:00.000" , "0123456789" , "中文测试1" , "中文测试2" ) +sql insert into ntb6 values ("2022-01-01 00:00:00.000" , "0123456789" , "中文测试01", "中文测试01" ) sql insert into ctb6 values ("2022-01-01 00:00:00.001" , NULL , NULL, NULL ) +sql insert into ntb6 values ("2022-01-01 00:00:00.001" , NULL , NULL, NULL ) +$loop_test = 0 +loop_test_pos: + +print ====> length +print ====> select c1, length(c1), c2, length(c2) from ctb0 +sql select c1, length(c1), c2, length(c2) from ctb0 +print ====> rows: $rows +print ====> $data00 $data01 $data02 $data03 $data04 $data05 +print ====> $data10 $data11 $data12 $data13 $data14 $data15 +print ====> $data20 $data21 $data22 $data23 $data24 $data25 +print ====> $data30 $data31 $data32 $data33 $data34 $data35 +if $rows != 4 then + return -1 +endi +if $data01 != 11 then + return -1 +endi +if $data03 != 44 then + return -1 +endi +if $data11 != 12 then + return -1 +endi +if $data13 != 48 then + return -1 +endi + +print ====> select c1, length(c1), c2, length(c2) from ntb0 +sql select c1, length(c1), c2, length(c2) from ntb0 +print ====> rows: $rows +print ====> $data00 $data01 $data02 $data03 $data04 $data05 +print ====> $data10 $data11 $data12 $data13 $data14 $data15 +print ====> $data20 $data21 $data22 $data23 $data24 $data25 +print ====> $data30 $data31 $data32 $data33 $data34 $data35 +if $rows != 4 then + return -1 +endi +if $data01 != 11 then + return -1 +endi +if $data03 != 44 then + return -1 +endi +if $data11 != 12 then + return -1 +endi +if $data13 != 48 then + return -1 +endi + +print ====> select length("abcd1234"), char_length("abcd1234=-+*") from ntb0 +sql select length("abcd1234"), char_length("abcd1234=-+*") from ntb0 +print ====> rows: $rows +print ====> $data00 $data01 $data02 $data03 $data04 $data05 +print ====> $data10 $data11 $data12 $data13 $data14 $data15 +print ====> $data20 $data21 $data22 $data23 $data24 $data25 +print ====> $data30 $data31 $data32 $data33 $data34 $data35 +if $rows != 4 then + return -1 +endi +if $data00 != 8 then + return -1 +endi +if $data01 != 12 then + return -1 +endi print ====> select c2 ,length(c2), char_length(c2) from ctb6 sql select c2 ,length(c2), char_length(c2) from ctb6 +print ====> rows: $rows +print ====> $data00 $data01 $data02 +print ====> $data10 $data11 $data12 +if $rows != 2 then + return -1 +endi +if $data01 != 20 then + return -1 +endi +if $data02 != 5 then + return -1 +endi +if $data11 != NULL then + return -1 +endi + +print ====> select c2 ,length(c2),char_length(c2) from ntb6 +sql select c2 ,length(c2),char_length(c2) from ntb6 +print ====> rows: $rows +print ====> $data00 $data01 $data02 +print ====> $data10 $data11 $data12 +if $rows != 2 then + return -1 +endi +if $data01 != 24 then + return -1 +endi +if $data02 != 6 then + return -1 +endi +if $data11 != NULL then + return -1 +endi + +print ====> select c2 ,lower(c2), upper(c2) from ctb6 +sql select c2 ,lower(c2), upper(c2) from ctb6 +print ====> rows: $rows +print ====> $data00 $data01 $data02 +print ====> $data10 $data11 $data12 +if $rows != 2 then + return -1 +endi +if $data01 != 中文测试1 then + return -1 +endi +if $data02 != 中文测试1 then + return -1 +endi +if $data11 != NULL then + return -1 +endi + +print ====> select c2 ,lower(c2), upper(c2) from ntb6 +sql select c2 ,lower(c2), upper(c2) from ntb6 +print ====> rows: $rows +print ====> $data00 $data01 $data02 +print ====> $data10 $data11 $data12 +if $rows != 2 then + return -1 +endi +if $data01 != 中文测试01 then + return -1 +endi +if $data02 != 中文测试01 then + return -1 +endi +if $data11 != NULL then + return -1 +endi + +print ====> select c2, ltrim(c2), ltrim(c2) from ctb6 +sql select c2, ltrim(c2), ltrim(c2) from ctb6 +print ====> rows: $rows +print ====> $data00 $data01 $data02 +print ====> $data10 $data11 $data12 +if $rows != 2 then + return -1 +endi +if $data01 != 中文测试1 then + return -1 +endi +if $data02 != 中文测试1 then + return -1 +endi +if $data11 != NULL then + return -1 +endi + +print ====> select c2, ltrim(c2), ltrim(c2) from ntb6 +sql select c2, ltrim(c2), ltrim(c2) from ntb6 +print ====> rows: $rows +print ====> $data00 $data01 $data02 +print ====> $data10 $data11 $data12 +if $rows != 2 then + return -1 +endi +if $data01 != 中文测试01 then + return -1 +endi +if $data02 != 中文测试01 then + return -1 +endi +if $data11 != NULL then + return -1 +endi + +print ====> select c2, c3 , concat(c2,c3) from ctb6 +sql select c2, c3 , concat(c2,c3) from ctb6 +print ====> rows: $rows +print ====> $data00 $data01 $data02 +print ====> $data10 $data11 $data12 +if $rows != 2 then + return -1 +endi +if $data02 != 中文测试1中文测试2 then + return -1 +endi +if $data12 != NULL then + return -1 +endi + +print ====> select c2, c3 , concat(c2,c3) from ntb6 +sql select c2, c3 , concat(c2,c3) from ntb6 +print ====> rows: $rows +print ====> $data00 $data01 $data02 +print ====> $data10 $data11 $data12 +if $rows != 2 then + return -1 +endi +if $data02 != 中文测试01中文测试01 then + return -1 +endi +if $data12 != NULL then + return -1 +endi + +print ====> select c2, c3 , concat_ws('_', c2, c3) from ctb6 +sql select c2, c3 , concat_ws('_', c2, c3) from ctb6 +print ====> rows: $rows +print ====> $data00 $data01 $data02 +print ====> $data10 $data11 $data12 +if $rows != 2 then + return -1 +endi +if $data02 != 中文测试1_中文测试2 then + return -1 +endi +# if $data12 != NULL then +# return -1 +# endi + +print ====> select c2, c3 , concat_ws('_', c2, c3) from ntb6 +sql select c2, c3 , concat_ws('_', c2, c3) from ntb6 +print ====> rows: $rows +print ====> $data00 $data01 $data02 +print ====> $data10 $data11 $data12 +if $rows != 2 then + return -1 +endi +if $data02 != 中文测试01_中文测试01 then + return -1 +endi +# if $data12 != NULL then +# return -1 +# endi + +print ====> select c2, substr(c2,1, 4) from ctb6 +sql select c2, substr(c2,1, 4) from ctb6 +print ====> rows: $rows +print ====> $data00 $data01 +print ====> $data10 $data11 +if $rows != 2 then + return -1 +endi +if $data00 != 中文测试1 then + return -1 +endi +if $data01 != 中文测试 then + return -1 +endi +# if $data11 != NULL then +# return -1 +# endi + +print ====> select c2, substr(c2,1, 4) from ntb6 +sql select c2, substr(c2,1, 4) from ntb6 +print ====> rows: $rows +print ====> $data00 $data01 +print ====> $data10 $data11 +if $rows != 2 then + return -1 +endi +if $data00 != 中文测试01 then + return -1 +endi +if $data01 != 中文测试 then + return -1 +endi +if $data11 != NULL then + return -1 +endi + +#sql_error select c1, length(t1), c2, length(t2) from ctb0 + +print ====> char_length +print ====> select c1, char_length(c1), c2, char_length(c2) from ctb0 +sql select c1, char_length(c1), c2, char_length(c2) from ctb0 +print ====> rows: $rows +print ====> $data00 $data01 $data02 $data03 $data04 $data05 +print ====> $data10 $data11 $data12 $data13 $data14 $data15 +print ====> $data20 $data21 $data22 $data23 $data24 $data25 +print ====> $data30 $data31 $data32 $data33 $data34 $data35 +if $rows != 4 then + return -1 +endi +if $data21 != 12 then + return -1 +endi +if $data23 != 12 then + return -1 +endi +if $data31 != 14 then + return -1 +endi +if $data33 != 14 then + return -1 +endi + +print ====> select c1, char_length(c1), c2, char_length(c2) from ntb0 +sql select c1, char_length(c1), c2, char_length(c2) from ntb0 +print ====> rows: $rows +print ====> $data00 $data01 $data02 $data03 $data04 $data05 +print ====> $data10 $data11 $data12 $data13 $data14 $data15 +print ====> $data20 $data21 $data22 $data23 $data24 $data25 +print ====> $data30 $data31 $data32 $data33 $data34 $data35 +if $rows != 4 then + return -1 +endi +if $data21 != 12 then + return -1 +endi +if $data23 != 12 then + return -1 +endi +if $data31 != 14 then + return -1 +endi +if $data33 != 14 then + return -1 +endi + +#sql_error select c1, char_length(t1), c2, char_length(t2) from ctb0 + +print ====> lower +sql select c1, lower(c1), c2, lower(c2), lower("abcdEFGH=-*&%") from ntb1 +print ====> select c1, lower(c1), c2, lower(c2), lower("abcdEFGH=-*&%") from ctb1 +sql select c1, lower(c1), c2, lower(c2), lower("abcdEFGH=-*&%") from ctb1 +print ====> rows: $rows +print ====> $data00 $data01 $data02 $data03 $data04 $data05 +print ====> $data10 $data11 $data12 $data13 $data14 $data15 +if $rows != 2 then + return -1 +endi +if $data01 != abcd1234 then + return -1 +endi +if $data03 != abcd1234 then + return -1 +endi +if $data04 != abcdefgh=-*&% then + return -1 +endi +if $data11 != aabbccdd1234 then + return -1 +endi +if $data13 != aabbccdd1234 then + return -1 +endi +if $data14 != abcdefgh=-*&% then + return -1 +endi + +#sql_error select c1, lower(t1), c2, lower(t2) from ctb1 + +print ====> upper +sql select c1, upper(c1), c2, upper(c2), upper("abcdEFGH=-*&%") from ntb2 +print ====> select c1, upper(c1), c2, upper(c2), upper("abcdEFGH=-*&%") from ctb2 +sql select c1, upper(c1), c2, upper(c2), upper("abcdEFGH=-*&%") from ctb2 +print ====> rows: $rows +print ====> $data00 $data01 $data02 $data03 $data04 $data05 +print ====> $data10 $data11 $data12 $data13 $data14 $data15 +if $rows != 2 then + return -1 +endi +if $data01 != ABCD1234 then + return -1 +endi +if $data03 != ABCD1234 then + return -1 +endi +if $data04 != ABCDEFGH=-*&% then + return -1 +endi +if $data11 != AABBCCDD1234 then + return -1 +endi +if $data13 != AABBCCDD1234 then + return -1 +endi +if $data14 != ABCDEFGH=-*&% then + return -1 +endi + +#sql_error select c1, upper(t1), c2, upper(t2) from ctb2 + +print ====> ltrim +sql select c1, ltrim(c1), c2, ltrim(c2), ltrim(" abcdEFGH =-*&% ") from ntb3 +print ====> select c1, ltrim(c1), c2, ltrim(c2), ltrim(" abcdEFGH =-*&% ") from ctb3 +sql select c1, ltrim(c1), c2, ltrim(c2), ltrim(" abcdEFGH =-*&% ") from ctb3 +print ====> rows: $rows +print ====> $data00 $data01 $data02 $data03 $data04 $data05 +print ====> $data10 $data11 $data12 $data13 $data14 $data15 +if $rows != 1 then + return -1 +endi +if $data01 != @abcd 1234 @ then + return -1 +endi +if $data03 != @abcd 1234 @ then + return -1 +endi +if $data04 != @abcdEFGH =-*&% @ then + return -1 +endi + +#sql_error select c1, ltrim(t1), c2, ltrim(t2) from ctb3 + + +print ====> rtrim +sql select c1, rtrim(c1), c2, rtrim(c2), rtrim(" abcdEFGH =-*&% ") from ntb3 +print ====> select c1, rtrim(c1), c2, rtrim(c2), rtrim(" abcdEFGH =-*&% ") from ctb3 +sql select c1, rtrim(c1), c2, rtrim(c2), rtrim(" abcdEFGH =-*&% ") from ctb3 +print ====> rows: $rows +print ====> [ $data00 ] [ $data01 ] [ $data02 ] [ $data03 ] [ $data04 ] [ $data05 ] [ $data06 ] +print ====> $data10 $data11 $data12 $data13 $data14 $data15 +if $rows != 1 then + return -1 +endi +if $data01 != @ abcd 1234@ then + return -1 +endi +if $data03 != @ abcd 1234@ then + return -1 +endi +if $data04 != @ abcdEFGH =-*&%@ then + return -1 +endi + +#sql_error select c1, rtrim(t1), c2, rtrim(t2) from ctb3 + +print ====> concat +sql select c1, c3, concat(c1, c3), c2, c4, concat(c2, c4), concat("binary+", c1, c3), concat("nchar+", c2, c4) from ntb4 +print ====> select c1, c3, concat(c1, c3), c2, c4, concat(c2, c4), concat("binary+", c1, c3), concat("nchar+", c2, c4) from ctb4 +sql select c1, c3, concat(c1, c3), c2, c4, concat(c2, c4), concat("binary+", c1, c3), concat("nchar+", c2, c4) from ctb4 +print ====> rows: $rows +print ====> $data00 $data01 $data02 $data03 $data04 $data05 $data06 +print ====> $data10 $data11 $data12 $data13 $data14 $data15 $data16 +if $rows != 1 then + return -1 +endi +if $data02 != @ ab 12 cd 34 @ then + return -1 +endi +if $data05 != @ ab 12 cd 34 @ then + return -1 +endi +if $data06 != @binary+ ab 12 cd 34 @ then + return -1 +endi +if $data07 != @nchar+ ab 12 cd 34 @ then + return -1 +endi + +sql select c1, c3, concat("bin-", c1, "-a1-", "a2-", c3, "-a3-", "a4-", "END"), c2, c4, concat("nchar-", c2, "-a1-", "-a2-", c4, "-a3-", "a4-", "END") from ntb4 +print ====> select c1, c3, concat("bin-", c1, "-a1-", "a2-", c3, "-a3-", "a4-", "END"), c2, c4, concat("nchar-", c2, "-a1-", "a2-", c4, "-a3-", "a4-", "END") from ctb4 +sql select c1, c3, concat("bin-", c1, "-a1-", "a2-", c3, "-a3-", "a4-", "END"), c2, c4, concat("nchar-", c2, "-a1-", "a2-", c4, "-a3-", "a4-", "END") from ctb4 +print ====> rows: $rows +print ====> [ $data00 ] [ $data01 ] [ $data02 ] [ $data03 ] [ $data04 ] [ $data05 ] [ $data06 ] +print ====> $data10 $data11 $data12 $data13 $data14 $data15 $data16 +if $rows != 1 then + return -1 +endi +if $data02 != @bin- ab 12 -a1-a2- cd 34 -a3-a4-END@ then + return -1 +endi +if $data05 != @nchar- ab 12 -a1-a2- cd 34 -a3-a4-END@ then + return -1 +endi + +#sql_error select c1, c2, concat(c1, c2), c3, c4, concat(c3, c4) from ctb4 +#sql_error select t1, t2, concat(t1, t2), t3, t4, concat(t3, t4) from ctb4 +#sql_error select t1, t3, concat(t1, t3), t2, t4, concat(t2, t4) from ctb4 + +print ====> concat_ws +sql select c1, c3, concat_ws("*", c1, c3), c2, c4, concat_ws("*", c2, c4), concat_ws("*", "binary+", c1, c3), concat_ws("*", "nchar+", c2, c4) from ntb4 +print ====> select c1, c3, concat_ws("*", c1, c3), c2, c4, concat_ws("*", c2, c4), concat_ws("*", "binary+", c1, c3), concat_ws("*", "nchar+", c2, c4) from ctb4 +sql select c1, c3, concat_ws("*", c1, c3), c2, c4, concat_ws("*", c2, c4), concat_ws("*", "binary+", c1, c3), concat_ws("*", "nchar+", c2, c4) from ctb4 +print ====> rows: $rows +print ====> $data00 $data01 $data02 $data03 $data04 $data05 $data06 +print ====> $data10 $data11 $data12 $data13 $data14 $data15 $data16 +if $rows != 1 then + return -1 +endi +if $data02 != @ ab 12 * cd 34 @ then + return -1 +endi +if $data05 != @ ab 12 * cd 34 @ then + return -1 +endi +if $data06 != @binary+* ab 12 * cd 34 @ then + return -1 +endi +if $data07 != @nchar+* ab 12 * cd 34 @ then + return -1 +endi + +print ====> select c1, c3, concat_ws("*", "b0", c1, "b1", c3, "b2", "E0", "E1", "E2"), c2, c4, concat_ws("*", "n0", c2, c4, "n1", c2, c4, "n2", "END") from ctb4 +sql select c1, c3, concat_ws("*", "b0", c1, "b1", c3, "b2", "E0", "E1", "E2"), c2, c4, concat_ws("*", "n0", c2, c4, "n1", c2, c4, "n2", "END") from ctb4 +print ====> rows: $rows +print ====> [ $data00 ] [ $data01 ] [ $data02 ] [ $data03 ] [ $data04 ] [ $data05 ] [ $data06 ] +print ====> $data10 $data11 $data12 $data13 $data14 $data15 $data16 +if $rows != 1 then + return -1 +endi +if $data02 != @b0* ab 12 *b1* cd 34 *b2*E0*E1*E2@ then + return -1 +endi +if $data05 != @n0* ab 12 * cd 34 *n1* ab 12 * cd 34 *n2*END@ then + return -1 +endi + +#sql_error select c1, c2, concat_ws("*", c1, c2), c3, c4, concat_ws("*", c3, c4) from ctb4 +#sql_error select t1, t2, concat_ws("*", t1, t2), t3, t4, concat_ws("*", t3, t4) from ctb4 +#sql_error select t1, t3, concat_ws("*", t1, t3), t2, t4, concat_ws("*", t2, t4) from ctb4 + + +print ====> substr +#sql select c1, substr(c1, 3, 3), substr(c1, -5, 3), c2, substr(c2, 3, 3), substr(c2, -5, 3), substr("abcdefg", 3, 3), substr("abcdefg", -3, 3) from ntb5 +#print ====> select c1, substr(c1, 3, 3), substr(c1, -5, 3), c2, substr(c2, 3, 3), substr(c2, -5, 3), substr("abcdefg", 3, 3), substr("abcdefg", -3, 3) from ctb5 +#sql select c1, substr(c1, 3, 3), substr(c1, -5, 3), c2, substr(c2, 3, 3), substr(c2, -5, 3), substr("abcdefg", 3, 3), substr("abcdefg", -3, 3) from ctb5 +#print ====> rows: $rows +#print ====> $data00 $data01 $data02 $data03 $data04 $data05 $data06 +#print ====> $data10 $data11 $data12 $data13 $data14 $data15 $data16 +#if $rows != 1 then +# return -1 +#endi +#if $data01 != 345 then +# return -1 +#endi +#if $data02 != 456 then +# return -1 +#endi +#if $data04 != 345 then +# return -1 +#endi +#if $data05 != 456 then +# return -1 +#endi +#if $data06 != def then +# return -1 +#endi +#if $data07 != efg then +# return -1 +#endi +#if $data11 != NULL then +# return -1 +#endi +#if $data12 != NULL then +# return -1 +#endi +#if $data14 != NULL then +# return -1 +#endi +#if $data15 != NULL then +# return -1 +#endi +#if $data16 != def then +# return -1 +#endi +#if $data17 != efg then +# return -1 +#endi +# +#sql select c1, substr(c1, 3), substr(c1, -5), c2, substr(c2, 3), substr(c2, -5), substr("abcdefg", 3), substr("abcdefg", -3) from ntb5 +#print ====> select c1, substr(c1, 3), substr(c1, -5), c2, substr(c2, 3), substr(c2, -5), substr("abcdefg", 3), substr("abcdefg", -3) from ctb5 +#sql select c1, substr(c1, 3), substr(c1, -5), c2, substr(c2, 3), substr(c2, -5), substr("abcdefg", 3), substr("abcdefg", -3) from ctb5 +#print ====> rows: $rows +#print ====> $data00 $data01 $data02 $data03 $data04 $data05 $data06 +#print ====> $data10 $data11 $data12 $data13 $data14 $data15 $data16 +#if $rows != 1 then +# return -1 +#endi +#if $data01 != 3456789 then +# return -1 +#endi +#if $data02 != 456789 then +# return -1 +#endi +#if $data04 != 3456789 then +# return -1 +#endi +#if $data05 != 456789 then +# return -1 +#endi +#if $data06 != defg then +# return -1 +#endi +#if $data07 != efg then +# return -1 +#endi +#if $data11 != NULL then +# return -1 +#endi +#if $data12 != NULL then +# return -1 +#endi +#if $data14 != NULL then +# return -1 +#endi +#if $data15 != NULL then +# return -1 +#endi +#if $data16 != defg then +# return -1 +#endi +#if $data17 != efg then +# return -1 +#endi + +#sql_error select t1, substr(t1, 3, 2), substr(t1, -3, 2), t2, substr(t2, 3, 2), substr(t2, -3, 2) from ctb5 + +if $loop_test == 0 then + print =============== stop and restart taosd + system sh/exec.sh -n dnode1 -s stop -x SIGINT + system sh/exec.sh -n dnode1 -s start + + $loop_cnt = 0 + check_dnode_ready_0: + $loop_cnt = $loop_cnt + 1 + sleep 200 + if $loop_cnt == 10 then + print ====> dnode not ready! + return -1 + endi + sql show dnodes + print ===> $rows $data00 $data01 $data02 $data03 $data04 $data05 + if $data00 != 1 then + return -1 + endi + if $data04 != ready then + goto check_dnode_ready_0 + endi + + $loop_test = 1 + goto loop_test_pos +endi + +system sh/exec.sh -n dnode1 -s stop -x SIGINT From 6275ac14c7adbaae5d4ea351f80cfb3e0fb6d9f0 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Wed, 20 Jul 2022 19:24:41 +0800 Subject: [PATCH 45/45] test: adjust case --- tests/script/tsim/parser/first_last_query.sim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/script/tsim/parser/first_last_query.sim b/tests/script/tsim/parser/first_last_query.sim index c52a5b45d6..a001b929c3 100644 --- a/tests/script/tsim/parser/first_last_query.sim +++ b/tests/script/tsim/parser/first_last_query.sim @@ -223,7 +223,7 @@ return -1 endi print ===================>td-1477, one table has only one block occurs this bug. -sql select _wstart, first(size), count(*), LAST(SIZE), tbname from stest where tbname in ('test1', 'test2') partition by tbname interval(1d) ; +sql select _wstart, first(size), count(*), LAST(SIZE), tbname from stest where tbname in ('test1', 'test2') partition by tbname interval(1d) order by tbname asc; if $rows != 2 then return -1 endi