diff --git a/docs/zh/05-get-started/03-package.md b/docs/zh/05-get-started/03-package.md index a21066e0cd..6ac7567a05 100644 --- a/docs/zh/05-get-started/03-package.md +++ b/docs/zh/05-get-started/03-package.md @@ -1,6 +1,6 @@ --- sidebar_label: 安装包 -title: 使用安装包安装和卸载 +title: 使用安装包立即开始 --- import Tabs from "@theme/Tabs"; @@ -169,72 +169,128 @@ install.sh 安装脚本在执行过程中,会通过命令行交互界面询问 ::: -## 卸载 +## 启动 - - - -内容 TBD - - - - -卸载命令如下: - -``` -$ sudo dpkg -r tdengine -(Reading database ... 137504 files and directories currently installed.) -Removing tdengine (2.4.0.7) ... -TDengine is removed successfully! +安装后,请使用 `systemctl` 命令来启动 TDengine 的服务进程。 +```bash +systemctl start taosd ``` - +检查服务是否正常工作: - - -卸载命令如下: - -``` -$ sudo rpm -e tdengine -TDengine is removed successfully! +```bash +systemctl status taosd ``` - - - - -卸载命令如下: +如果服务进程处于活动状态,则 status 指令会显示如下的相关信息: ``` -$ rmtaos -Nginx for TDengine is running, stopping it... -TDengine is removed successfully! - -taosKeeper is removed successfully! +Active: active (running) ``` - - +如果后台服务进程处于停止状态,则 status 指令会显示如下的相关信息: + +``` +Active: inactive (dead) +``` + +如果 TDengine 服务正常工作,那么您可以通过 TDengine 的命令行程序 `taos` 来访问并体验 TDengine。 + +systemctl 命令汇总: + +- 启动服务进程:`systemctl start taosd` + +- 停止服务进程:`systemctl stop taosd` + +- 重启服务进程:`systemctl restart taosd` + +- 查看服务状态:`systemctl status taosd` :::info -- TDengine 提供了多种安装包,但最好不要在一个系统上同时使用 tar.gz 安装包和 deb 或 rpm 安装包。否则会相互影响,导致在使用时出现问题。 +- systemctl 命令需要 _root_ 权限来运行,如果您非 _root_ 用户,请在命令前添加 sudo 。 +- `systemctl stop taosd` 指令在执行后并不会马上停止 TDengine 服务,而是会等待系统中必要的落盘工作正常完成。在数据量很大的情况下,这可能会消耗较长时间。 +- 如果系统中不支持 `systemd`,也可以用手动运行 `/usr/local/taos/bin/taosd` 方式启动 TDengine 服务。 -- 对于 deb 包安装后,如果安装目录被手工误删了部分,出现卸载、或重新安装不能成功。此时,需要清除 TDengine 包的安装信息,执行如下命令: +::: - ``` - $ sudo rm -f /var/lib/dpkg/info/tdengine* - ``` +## TDengine 命令行 (CLI) -然后再重新进行安装就可以了。 +为便于检查 TDengine 的状态,执行数据库 (Database) 的各种即席(Ad Hoc)查询,TDengine 提供一命令行应用程序(以下简称为 TDengine CLI) taos。要进入 TDengine 命令行,您只要在安装有 TDengine 的 Linux 终端执行 `taos` 即可。 -- 对于 rpm 包安装后,如果安装目录被手工误删了部分,出现卸载、或重新安装不能成功。此时,需要清除 TDengine 包的安装信息,执行如下命令: +```bash +taos +``` - ``` - $ sudo rpm -e --noscripts tdengine - ``` +如果连接服务成功,将会打印出欢迎消息和版本信息。如果失败,则会打印错误消息出来(请参考 [FAQ](/train-faq/faq) 来解决终端连接服务端失败的问题)。 TDengine CLI 的提示符号如下: -然后再重新进行安装就可以了。 +```cmd +taos> +``` -::: \ No newline at end of file +在 TDengine CLI 中,用户可以通过 SQL 命令来创建/删除数据库、表等,并进行数据库(database)插入查询操作。在终端中运行的 SQL 语句需要以分号结束来运行。示例: + +```sql +create database demo; +use demo; +create table t (ts timestamp, speed int); +insert into t values ('2019-07-15 00:00:00', 10); +insert into t values ('2019-07-15 01:00:00', 20); +select * from t; + ts | speed | +======================================== + 2019-07-15 00:00:00.000 | 10 | + 2019-07-15 01:00:00.000 | 20 | +Query OK, 2 row(s) in set (0.003128s) +``` + +除执行 SQL 语句外,系统管理员还可以从 TDengine CLI 进行检查系统运行状态、添加删除用户账号等操作。TDengine CLI 连同应用驱动也可以独立安装在 Linux 或 Windows 机器上运行,更多细节请参考 [这里](../reference/taos-shell/) + +## 使用 taosBenchmark 体验写入速度 + +启动 TDengine 的服务,在 Linux 终端执行 `taosBenchmark` (曾命名为 `taosdemo`): + +```bash +taosBenchmark +``` + +该命令将在数据库 test 下面自动创建一张超级表 meters,该超级表下有 1 万张表,表名为 "d0" 到 "d9999",每张表有 1 万条记录,每条记录有 (ts, current, voltage, phase) 四个字段,时间戳从 "2017-07-14 10:40:00 000" 到 "2017-07-14 10:40:09 999",每张表带有标签 location 和 groupId,groupId 被设置为 1 到 10, location 被设置为 "California.SanFrancisco" 或者 "California.LosAngeles"。 + +这条命令很快完成 1 亿条记录的插入。具体时间取决于硬件性能,即使在一台普通的 PC 服务器往往也仅需十几秒。 + +taosBenchmark 命令本身带有很多选项,配置表的数目、记录条数等等,您可以设置不同参数进行体验,请执行 `taosBenchmark --help` 详细列出。taosBenchmark 详细使用方法请参照 [如何使用 taosBenchmark 对 TDengine 进行性能测试](https://www.taosdata.com/2021/10/09/3111.html)。 + +## 使用 TDengine CLI 体验查询速度 + +使用上述 taosBenchmark 插入数据后,可以在 TDengine CLI 输入查询命令,体验查询速度。 + +查询超级表下记录总条数: + +```sql +taos> select count(*) from test.meters; +``` + +查询 1 亿条记录的平均值、最大值、最小值等: + +```sql +taos> select avg(current), max(voltage), min(phase) from test.meters; +``` + +查询 location="California.SanFrancisco" 的记录总条数: + +```sql +taos> select count(*) from test.meters where location="California.SanFrancisco"; +``` + +查询 groupId=10 的所有记录的平均值、最大值、最小值等: + +```sql +taos> select avg(current), max(voltage), min(phase) from test.meters where groupId=10; +``` + +对表 d10 按 10s 进行平均值、最大值和最小值聚合统计: + +```sql +taos> select avg(current), max(voltage), min(phase) from test.d10 interval(10s); +``` \ No newline at end of file diff --git a/docs/zh/05-get-started/06-first-use.md b/docs/zh/05-get-started/06-first-use.md deleted file mode 100644 index 927ce0a1bd..0000000000 --- a/docs/zh/05-get-started/06-first-use.md +++ /dev/null @@ -1,135 +0,0 @@ ---- -sidebar_label: 开始使用 -title: 快速体验 TDengine ---- - -import Tabs from "@theme/Tabs"; -import TabItem from "@theme/TabItem"; -import PkgInstall from "./\_pkg_install.mdx"; -import AptGetInstall from "./\_apt_get_install.mdx"; - -## 启动 - -安装后,请使用 `systemctl` 命令来启动 TDengine 的服务进程。 - -```bash -systemctl start taosd -``` - -检查服务是否正常工作: - -```bash -systemctl status taosd -``` - -如果服务进程处于活动状态,则 status 指令会显示如下的相关信息: - -``` -Active: active (running) -``` - -如果后台服务进程处于停止状态,则 status 指令会显示如下的相关信息: - -``` -Active: inactive (dead) -``` - -如果 TDengine 服务正常工作,那么您可以通过 TDengine 的命令行程序 `taos` 来访问并体验 TDengine。 - -systemctl 命令汇总: - -- 启动服务进程:`systemctl start taosd` - -- 停止服务进程:`systemctl stop taosd` - -- 重启服务进程:`systemctl restart taosd` - -- 查看服务状态:`systemctl status taosd` - -:::info - -- systemctl 命令需要 _root_ 权限来运行,如果您非 _root_ 用户,请在命令前添加 sudo 。 -- `systemctl stop taosd` 指令在执行后并不会马上停止 TDengine 服务,而是会等待系统中必要的落盘工作正常完成。在数据量很大的情况下,这可能会消耗较长时间。 -- 如果系统中不支持 `systemd`,也可以用手动运行 `/usr/local/taos/bin/taosd` 方式启动 TDengine 服务。 - -::: - -## TDengine 命令行 (CLI) - -为便于检查 TDengine 的状态,执行数据库 (Database) 的各种即席(Ad Hoc)查询,TDengine 提供一命令行应用程序(以下简称为 TDengine CLI) taos。要进入 TDengine 命令行,您只要在安装有 TDengine 的 Linux 终端执行 `taos` 即可。 - -```bash -taos -``` - -如果连接服务成功,将会打印出欢迎消息和版本信息。如果失败,则会打印错误消息出来(请参考 [FAQ](/train-faq/faq) 来解决终端连接服务端失败的问题)。 TDengine CLI 的提示符号如下: - -```cmd -taos> -``` - -在 TDengine CLI 中,用户可以通过 SQL 命令来创建/删除数据库、表等,并进行数据库(database)插入查询操作。在终端中运行的 SQL 语句需要以分号结束来运行。示例: - -```sql -create database demo; -use demo; -create table t (ts timestamp, speed int); -insert into t values ('2019-07-15 00:00:00', 10); -insert into t values ('2019-07-15 01:00:00', 20); -select * from t; - ts | speed | -======================================== - 2019-07-15 00:00:00.000 | 10 | - 2019-07-15 01:00:00.000 | 20 | -Query OK, 2 row(s) in set (0.003128s) -``` - -除执行 SQL 语句外,系统管理员还可以从 TDengine CLI 进行检查系统运行状态、添加删除用户账号等操作。TDengine CLI 连同应用驱动也可以独立安装在 Linux 或 Windows 机器上运行,更多细节请参考 [这里](../reference/taos-shell/) - -## 使用 taosBenchmark 体验写入速度 - -启动 TDengine 的服务,在 Linux 终端执行 `taosBenchmark` (曾命名为 `taosdemo`): - -```bash -taosBenchmark -``` - -该命令将在数据库 test 下面自动创建一张超级表 meters,该超级表下有 1 万张表,表名为 "d0" 到 "d9999",每张表有 1 万条记录,每条记录有 (ts, current, voltage, phase) 四个字段,时间戳从 "2017-07-14 10:40:00 000" 到 "2017-07-14 10:40:09 999",每张表带有标签 location 和 groupId,groupId 被设置为 1 到 10, location 被设置为 "California.SanFrancisco" 或者 "California.LosAngeles"。 - -这条命令很快完成 1 亿条记录的插入。具体时间取决于硬件性能,即使在一台普通的 PC 服务器往往也仅需十几秒。 - -taosBenchmark 命令本身带有很多选项,配置表的数目、记录条数等等,您可以设置不同参数进行体验,请执行 `taosBenchmark --help` 详细列出。taosBenchmark 详细使用方法请参照 [如何使用 taosBenchmark 对 TDengine 进行性能测试](https://www.taosdata.com/2021/10/09/3111.html)。 - -## 使用 TDengine CLI 体验查询速度 - -使用上述 taosBenchmark 插入数据后,可以在 TDengine CLI 输入查询命令,体验查询速度。 - -查询超级表下记录总条数: - -```sql -taos> select count(*) from test.meters; -``` - -查询 1 亿条记录的平均值、最大值、最小值等: - -```sql -taos> select avg(current), max(voltage), min(phase) from test.meters; -``` - -查询 location="California.SanFrancisco" 的记录总条数: - -```sql -taos> select count(*) from test.meters where location="California.SanFrancisco"; -``` - -查询 groupId=10 的所有记录的平均值、最大值、最小值等: - -```sql -taos> select avg(current), max(voltage), min(phase) from test.meters where groupId=10; -``` - -对表 d10 按 10s 进行平均值、最大值和最小值聚合统计: - -```sql -taos> select avg(current), max(voltage), min(phase) from test.d10 interval(10s); -``` diff --git a/docs/zh/13-operation/01-pkg-install.md b/docs/zh/13-operation/01-pkg-install.md index 41daffc1b7..f814ee70b7 100644 --- a/docs/zh/13-operation/01-pkg-install.md +++ b/docs/zh/13-operation/01-pkg-install.md @@ -8,9 +8,11 @@ import TabItem from "@theme/TabItem"; 本节将介绍一些关于安装和卸载更深层次的内容,以及升级的注意事项。 -## 安装和卸载 +## 安装 + +关于安装,请参考 [使用安装包立即开始](../get-started/package) + -关于安装和卸载,请参考 [安装和卸载](../get-started/package) ## 安装目录说明 @@ -40,6 +42,76 @@ lrwxrwxrwx 1 root root 13 Feb 22 09:34 log -> /var/log/taos/ - /usr/local/taos/driver 目录下的动态库文件,会软链接到 /usr/lib 目录下; - /usr/local/taos/include 目录下的头文件,会软链接到到 /usr/include 目录下; +## 卸载 + + + + +内容 TBD + + + + +卸载命令如下: + +``` +$ sudo dpkg -r tdengine +(Reading database ... 137504 files and directories currently installed.) +Removing tdengine (2.4.0.7) ... +TDengine is removed successfully! + +``` + + + + + +卸载命令如下: + +``` +$ sudo rpm -e tdengine +TDengine is removed successfully! +``` + + + + + +卸载命令如下: + +``` +$ rmtaos +Nginx for TDengine is running, stopping it... +TDengine is removed successfully! + +taosKeeper is removed successfully! +``` + + + + +:::info + +- TDengine 提供了多种安装包,但最好不要在一个系统上同时使用 tar.gz 安装包和 deb 或 rpm 安装包。否则会相互影响,导致在使用时出现问题。 + +- 对于 deb 包安装后,如果安装目录被手工误删了部分,出现卸载、或重新安装不能成功。此时,需要清除 TDengine 包的安装信息,执行如下命令: + + ``` + $ sudo rm -f /var/lib/dpkg/info/tdengine* + ``` + +然后再重新进行安装就可以了。 + +- 对于 rpm 包安装后,如果安装目录被手工误删了部分,出现卸载、或重新安装不能成功。此时,需要清除 TDengine 包的安装信息,执行如下命令: + + ``` + $ sudo rpm -e --noscripts tdengine + ``` + +然后再重新进行安装就可以了。 + +::: + ## 卸载和更新文件说明 卸载安装包的时候,将保留配置文件、数据库文件和日志文件,即 /etc/taos/taos.cfg 、 /var/lib/taos 、 /var/log/taos 。如果用户确认后不需保留,可以手工删除,但一定要慎重,因为删除后,数据将永久丢失,不可以恢复! @@ -64,4 +136,4 @@ lrwxrwxrwx 1 root root 13 Feb 22 09:34 log -> /var/log/taos/ :::warning TDengine 不保证低版本能够兼容高版本的数据,所以任何时候都不推荐降级 -::: \ No newline at end of file +::: diff --git a/include/common/tmsg.h b/include/common/tmsg.h index 8a3b28a125..77b6ca1833 100644 --- a/include/common/tmsg.h +++ b/include/common/tmsg.h @@ -438,7 +438,7 @@ static FORCE_INLINE int32_t tDecodeSSchemaWrapperEx(SDecoder* pDecoder, SSchemaW return 0; } -STSchema* tdGetSTSChemaFromSSChema(SSchema** pSchema, int32_t nCols); +STSchema* tdGetSTSChemaFromSSChema(SSchema* pSchema, int32_t nCols, int32_t sver); typedef struct { char name[TSDB_TABLE_FNAME_LEN]; diff --git a/source/common/src/tmsg.c b/source/common/src/tmsg.c index 8611278550..3e733d291b 100644 --- a/source/common/src/tmsg.c +++ b/source/common/src/tmsg.c @@ -4941,14 +4941,14 @@ int tDecodeSVCreateStbReq(SDecoder *pCoder, SVCreateStbReq *pReq) { return 0; } -STSchema *tdGetSTSChemaFromSSChema(SSchema **pSchema, int32_t nCols) { +STSchema *tdGetSTSChemaFromSSChema(SSchema *pSchema, int32_t nCols, int32_t sver) { STSchemaBuilder schemaBuilder = {0}; - if (tdInitTSchemaBuilder(&schemaBuilder, 1) < 0) { + if (tdInitTSchemaBuilder(&schemaBuilder, sver) < 0) { return NULL; } for (int i = 0; i < nCols; i++) { - SSchema *schema = *pSchema + i; + SSchema *schema = pSchema + i; if (tdAddColToSchema(&schemaBuilder, schema->type, schema->flags, schema->colId, schema->bytes) < 0) { tdDestroyTSchemaBuilder(&schemaBuilder); return NULL; diff --git a/source/common/src/trow.c b/source/common/src/trow.c index df5bf64acf..754e142437 100644 --- a/source/common/src/trow.c +++ b/source/common/src/trow.c @@ -568,6 +568,7 @@ int32_t tdSTSRowNew(SArray *pArray, STSchema *pTSchema, STSRow **ppRow) { int32_t maxVarDataLen = 0; int32_t iColVal = 0; void *varBuf = NULL; + bool isAlloc = false; ASSERT(nColVal > 1); @@ -610,8 +611,11 @@ int32_t tdSTSRowNew(SArray *pArray, STSchema *pTSchema, STSRow **ppRow) { ++iColVal; } - *ppRow = (STSRow *)taosMemoryCalloc( - 1, sizeof(STSRow) + pTSchema->flen + varDataLen + TD_BITMAP_BYTES(pTSchema->numOfCols - 1)); + if (!(*ppRow)) { + *ppRow = (STSRow *)taosMemoryCalloc( + 1, sizeof(STSRow) + pTSchema->flen + varDataLen + TD_BITMAP_BYTES(pTSchema->numOfCols - 1)); + isAlloc = true; + } if (!(*ppRow)) { terrno = TSDB_CODE_OUT_OF_MEMORY; @@ -621,7 +625,9 @@ int32_t tdSTSRowNew(SArray *pArray, STSchema *pTSchema, STSRow **ppRow) { if (maxVarDataLen > 0) { varBuf = taosMemoryMalloc(maxVarDataLen); if (!varBuf) { - taosMemoryFreeClear(*ppRow); + if(isAlloc) { + taosMemoryFreeClear(*ppRow); + } terrno = TSDB_CODE_OUT_OF_MEMORY; return -1; } @@ -1323,12 +1329,11 @@ void tTSRowGetVal(STSRow *pRow, STSchema *pTSchema, int16_t iCol, SColVal *pColV SCellVal cv; SValue value; - ASSERT(iCol > 0); + ASSERT((pTColumn->colId == PRIMARYKEY_TIMESTAMP_COL_ID) || (iCol > 0)); if (TD_IS_TP_ROW(pRow)) { tdSTpRowGetVal(pRow, pTColumn->colId, pTColumn->type, pTSchema->flen, pTColumn->offset, iCol - 1, &cv); } else if (TD_IS_KV_ROW(pRow)) { - ASSERT(iCol > 0); tdSKvRowGetVal(pRow, pTColumn->colId, iCol - 1, &cv); } else { ASSERT(0); diff --git a/source/common/test/dataformatTest.cpp b/source/common/test/dataformatTest.cpp index d16e35ff07..65f21bee40 100644 --- a/source/common/test/dataformatTest.cpp +++ b/source/common/test/dataformatTest.cpp @@ -116,7 +116,7 @@ STSchema *genSTSchema(int16_t nCols) { } STSchema *pResult = NULL; - pResult = tdGetSTSChemaFromSSChema(&pSchema, nCols); + pResult = tdGetSTSChemaFromSSChema(pSchema, nCols, 1); taosMemoryFree(pSchema); return pResult; diff --git a/source/dnode/vnode/src/tq/tq.c b/source/dnode/vnode/src/tq/tq.c index b2679ee245..5469960ce6 100644 --- a/source/dnode/vnode/src/tq/tq.c +++ b/source/dnode/vnode/src/tq/tq.c @@ -634,7 +634,7 @@ int32_t tqProcessTaskDeployReq(STQ* pTq, char* msg, int32_t msgLen) { ASSERT(pTask->tbSink.pSchemaWrapper->pSchema); pTask->tbSink.pTSchema = - tdGetSTSChemaFromSSChema(&pTask->tbSink.pSchemaWrapper->pSchema, pTask->tbSink.pSchemaWrapper->nCols); + tdGetSTSChemaFromSSChema(pTask->tbSink.pSchemaWrapper->pSchema, pTask->tbSink.pSchemaWrapper->nCols, 1); ASSERT(pTask->tbSink.pTSchema); } diff --git a/source/libs/parser/src/parInsert.c b/source/libs/parser/src/parInsert.c index 05e8c1094d..76e57a9a07 100644 --- a/source/libs/parser/src/parInsert.c +++ b/source/libs/parser/src/parInsert.c @@ -1200,7 +1200,7 @@ static int parseOneRow(SInsertParseContext* pCxt, STableDataBlocks* pDataBlocks, *gotRow = true; #ifdef TD_DEBUG_PRINT_ROW - STSchema* pSTSchema = tdGetSTSChemaFromSSChema(&schema, spd->numOfCols); + STSchema* pSTSchema = tdGetSTSChemaFromSSChema(schema, spd->numOfCols, 1); tdSRowPrint(row, pSTSchema, __func__); taosMemoryFree(pSTSchema); #endif @@ -1972,7 +1972,7 @@ int32_t qBindStmtColsValue(void* pBlock, TAOS_MULTI_BIND* bind, char* msgBuf, in } } #ifdef TD_DEBUG_PRINT_ROW - STSchema* pSTSchema = tdGetSTSChemaFromSSChema(&pSchema, spd->numOfCols); + STSchema* pSTSchema = tdGetSTSChemaFromSSChema(pSchema, spd->numOfCols, 1); tdSRowPrint(row, pSTSchema, __func__); taosMemoryFree(pSTSchema); #endif @@ -2057,7 +2057,7 @@ int32_t qBindStmtSingleColValue(void* pBlock, TAOS_MULTI_BIND* bind, char* msgBu #ifdef TD_DEBUG_PRINT_ROW if (rowEnd) { - STSchema* pSTSchema = tdGetSTSChemaFromSSChema(&pSchema, spd->numOfCols); + STSchema* pSTSchema = tdGetSTSChemaFromSSChema(pSchema, spd->numOfCols, 1); tdSRowPrint(row, pSTSchema, __func__); taosMemoryFree(pSTSchema); } diff --git a/source/libs/parser/src/parInsertData.c b/source/libs/parser/src/parInsertData.c index 9e1d8dba8b..ae123a3563 100644 --- a/source/libs/parser/src/parInsertData.c +++ b/source/libs/parser/src/parInsertData.c @@ -19,6 +19,7 @@ #include "parInt.h" #include "parUtil.h" #include "querynodes.h" +#include "tRealloc.h" #define IS_RAW_PAYLOAD(t) \ (((int)(t)) == PAYLOAD_TYPE_RAW) // 0: K-V payload for non-prepare insert, 1: rawPayload for prepare insert @@ -34,6 +35,32 @@ typedef struct SBlockKeyInfo { SBlockKeyTuple* pKeyTuple; } SBlockKeyInfo; +typedef struct { + int32_t index; + SArray* rowArray; // array of merged rows(mem allocated by tRealloc/free by tFree) + STSchema* pSchema; + int64_t tbUid; // suid for child table, uid for normal table +} SBlockRowMerger; + +static FORCE_INLINE void tdResetSBlockRowMerger(SBlockRowMerger* pMerger) { + if (pMerger) { + pMerger->index = -1; + } +} + +static void tdFreeSBlockRowMerger(SBlockRowMerger* pMerger) { + if (pMerger) { + int32_t size = taosArrayGetSize(pMerger->rowArray); + for (int32_t i = 0; i < size; ++i) { + tFree(*(void**)taosArrayGet(pMerger->rowArray, i)); + } + taosArrayDestroy(pMerger->rowArray); + + taosMemoryFreeClear(pMerger->pSchema); + taosMemoryFree(pMerger); + } +} + static int32_t rowDataCompar(const void* lhs, const void* rhs) { TSKEY left = *(TSKEY*)lhs; TSKEY right = *(TSKEY*)rhs; @@ -328,7 +355,7 @@ void sortRemoveDataBlockDupRowsRaw(STableDataBlocks* dataBuf) { } // data block is disordered, sort it in ascending order -int sortRemoveDataBlockDupRows(STableDataBlocks* dataBuf, SBlockKeyInfo* pBlkKeyInfo) { +static int sortRemoveDataBlockDupRows(STableDataBlocks* dataBuf, SBlockKeyInfo* pBlkKeyInfo) { SSubmitBlk* pBlocks = (SSubmitBlk*)dataBuf->pData; int16_t nRows = pBlocks->numOfRows; @@ -396,6 +423,201 @@ int sortRemoveDataBlockDupRows(STableDataBlocks* dataBuf, SBlockKeyInfo* pBlkKey return 0; } +static void* tdGetCurRowFromBlockMerger(SBlockRowMerger* pBlkRowMerger) { + if (pBlkRowMerger && (pBlkRowMerger->index >= 0)) { + ASSERT(pBlkRowMerger->index < taosArrayGetSize(pBlkRowMerger->rowArray)); + return *(void**)taosArrayGet(pBlkRowMerger->rowArray, pBlkRowMerger->index); + } + return NULL; +} + +static int32_t tdBlockRowMerge(STableMeta* pTableMeta, SBlockKeyTuple* pEndKeyTp, int32_t nDupRows, + SBlockRowMerger** pBlkRowMerger, int32_t rowSize) { + ASSERT(nDupRows > 1); + SBlockKeyTuple* pStartKeyTp = pEndKeyTp - (nDupRows - 1); + ASSERT(pStartKeyTp->skey == pEndKeyTp->skey); + + // TODO: optimization if end row is all normal +#if 0 + STSRow* pEndRow = (STSRow*)pEndKeyTp->payloadAddr; + if(isNormal(pEndRow)) { // set the end row if it is normal and return directly + pStartKeyTp->payloadAddr = pEndKeyTp->payloadAddr; + return TSDB_CODE_SUCCESS; + } +#endif + + if (!(*pBlkRowMerger)) { + (*pBlkRowMerger) = taosMemoryCalloc(1, sizeof(**pBlkRowMerger)); + if (!(*pBlkRowMerger)) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + return TSDB_CODE_FAILED; + } + (*pBlkRowMerger)->index = -1; + if (!(*pBlkRowMerger)->rowArray) { + (*pBlkRowMerger)->rowArray = taosArrayInit(1, sizeof(void*)); + if (!(*pBlkRowMerger)->rowArray) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + return TSDB_CODE_FAILED; + } + } + } + + if ((*pBlkRowMerger)->pSchema) { + if ((*pBlkRowMerger)->pSchema->version != pTableMeta->sversion) { + taosMemoryFreeClear((*pBlkRowMerger)->pSchema); + } else { + if ((*pBlkRowMerger)->tbUid != (pTableMeta->suid > 0 ? pTableMeta->suid : pTableMeta->uid)) { + taosMemoryFreeClear((*pBlkRowMerger)->pSchema); + } + } + } + + if (!(*pBlkRowMerger)->pSchema) { + (*pBlkRowMerger)->pSchema = + tdGetSTSChemaFromSSChema(pTableMeta->schema, pTableMeta->tableInfo.numOfColumns, pTableMeta->sversion); + + if (!(*pBlkRowMerger)->pSchema) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + return TSDB_CODE_FAILED; + } + (*pBlkRowMerger)->tbUid = pTableMeta->suid > 0 ? pTableMeta->suid : pTableMeta->uid; + } + + void* pDestRow = NULL; + ++((*pBlkRowMerger)->index); + if ((*pBlkRowMerger)->index < taosArrayGetSize((*pBlkRowMerger)->rowArray)) { + void* pAlloc = *(void**)taosArrayGet((*pBlkRowMerger)->rowArray, (*pBlkRowMerger)->index); + if (tRealloc((uint8_t**)&pAlloc, rowSize) != 0) { + return TSDB_CODE_FAILED; + } + pDestRow = pAlloc; + } else { + if (tRealloc((uint8_t**)&pDestRow, rowSize) != 0) { + return TSDB_CODE_FAILED; + } + taosArrayPush((*pBlkRowMerger)->rowArray, &pDestRow); + } + + // merge rows to pDestRow + STSchema* pSchema = (*pBlkRowMerger)->pSchema; + SArray* pArray = taosArrayInit(pSchema->numOfCols, sizeof(SColVal)); + for (int32_t i = 0; i < pSchema->numOfCols; ++i) { + SColVal colVal = {0}; + for (int32_t j = 0; j < nDupRows; ++j) { + tTSRowGetVal((pEndKeyTp - j)->payloadAddr, pSchema, i, &colVal); + if (!colVal.isNone) { + break; + } + } + taosArrayPush(pArray, &colVal); + } + if (tdSTSRowNew(pArray, pSchema, (STSRow**)&pDestRow) < 0) { + taosArrayDestroy(pArray); + return TSDB_CODE_FAILED; + } + + taosArrayDestroy(pArray); + return TSDB_CODE_SUCCESS; +} + +// data block is disordered, sort it in ascending order, and merge dup rows if exists +static int sortMergeDataBlockDupRows(STableDataBlocks* dataBuf, SBlockKeyInfo* pBlkKeyInfo, + SBlockRowMerger** ppBlkRowMerger) { + SSubmitBlk* pBlocks = (SSubmitBlk*)dataBuf->pData; + STableMeta* pTableMeta = dataBuf->pTableMeta; + int16_t nRows = pBlocks->numOfRows; + + // size is less than the total size, since duplicated rows may be removed. + + // allocate memory + size_t nAlloc = nRows * sizeof(SBlockKeyTuple); + if (pBlkKeyInfo->pKeyTuple == NULL || pBlkKeyInfo->maxBytesAlloc < nAlloc) { + char* tmp = taosMemoryRealloc(pBlkKeyInfo->pKeyTuple, nAlloc); + if (tmp == NULL) { + return TSDB_CODE_TSC_OUT_OF_MEMORY; + } + pBlkKeyInfo->pKeyTuple = (SBlockKeyTuple*)tmp; + pBlkKeyInfo->maxBytesAlloc = (int32_t)nAlloc; + } + memset(pBlkKeyInfo->pKeyTuple, 0, nAlloc); + + tdResetSBlockRowMerger(*ppBlkRowMerger); + + int32_t extendedRowSize = getExtendedRowSize(dataBuf); + SBlockKeyTuple* pBlkKeyTuple = pBlkKeyInfo->pKeyTuple; + char* pBlockData = pBlocks->data + pBlocks->schemaLen; + int n = 0; + while (n < nRows) { + pBlkKeyTuple->skey = TD_ROW_KEY((STSRow*)pBlockData); + pBlkKeyTuple->payloadAddr = pBlockData; + pBlkKeyTuple->index = n; + + // next loop + pBlockData += extendedRowSize; + ++pBlkKeyTuple; + ++n; + } + + if (!dataBuf->ordered) { + pBlkKeyTuple = pBlkKeyInfo->pKeyTuple; + + taosSort(pBlkKeyTuple, nRows, sizeof(SBlockKeyTuple), rowDataComparStable); + + pBlkKeyTuple = pBlkKeyInfo->pKeyTuple; + bool hasDup = false; + int32_t nextPos = 0; + int32_t i = 0; + int32_t j = 1; + + while (j < nRows) { + TSKEY ti = (pBlkKeyTuple + i)->skey; + TSKEY tj = (pBlkKeyTuple + j)->skey; + + if (ti == tj) { + ++j; + continue; + } + + if ((j - i) > 1) { + if (tdBlockRowMerge(pTableMeta, (pBlkKeyTuple + j - 1), j - i, ppBlkRowMerger, extendedRowSize) < 0) { + return TSDB_CODE_FAILED; + } + (pBlkKeyTuple + nextPos)->payloadAddr = tdGetCurRowFromBlockMerger(*ppBlkRowMerger); + if (!hasDup) { + hasDup = true; + } + i = j; + } else { + if (hasDup) { + memmove(pBlkKeyTuple + nextPos, pBlkKeyTuple + i, sizeof(SBlockKeyTuple)); + } + ++i; + } + + ++nextPos; + ++j; + } + + if ((j - i) > 1) { + ASSERT((pBlkKeyTuple + i)->skey == (pBlkKeyTuple + j - 1)->skey); + if (tdBlockRowMerge(pTableMeta, (pBlkKeyTuple + j - 1), j - i, ppBlkRowMerger, extendedRowSize) < 0) { + return TSDB_CODE_FAILED; + } + (pBlkKeyTuple + nextPos)->payloadAddr = tdGetCurRowFromBlockMerger(*ppBlkRowMerger); + } else if (hasDup) { + memmove(pBlkKeyTuple + nextPos, pBlkKeyTuple + i, sizeof(SBlockKeyTuple)); + } + + dataBuf->ordered = true; + pBlocks->numOfRows = nextPos + 1; + } + + dataBuf->size = sizeof(SSubmitBlk) + pBlocks->numOfRows * extendedRowSize; + dataBuf->prevTS = INT64_MIN; + + return TSDB_CODE_SUCCESS; +} + // Erase the empty space reserved for binary data static int trimDataBlock(void* pDataBlock, STableDataBlocks* pTableDataBlock, SBlockKeyTuple* blkKeyTuple, bool isRawPayload) { @@ -464,6 +686,8 @@ int32_t mergeTableDataBlocks(SHashObj* pHashObj, uint8_t payloadType, SArray** p STableDataBlocks** p = taosHashIterate(pHashObj, NULL); STableDataBlocks* pOneTableBlock = *p; SBlockKeyInfo blkKeyInfo = {0}; // share by pOneTableBlock + SBlockRowMerger *pBlkRowMerger = NULL; + while (pOneTableBlock) { SSubmitBlk* pBlocks = (SSubmitBlk*)pOneTableBlock->pData; if (pBlocks->numOfRows > 0) { @@ -473,6 +697,7 @@ int32_t mergeTableDataBlocks(SHashObj* pHashObj, uint8_t payloadType, SArray** p getDataBlockFromList(pVnodeDataBlockHashList, &pOneTableBlock->vgId, sizeof(pOneTableBlock->vgId), TSDB_PAYLOAD_SIZE, INSERT_HEAD_SIZE, 0, pOneTableBlock->pTableMeta, &dataBuf, pVnodeDataBlockList, NULL); if (ret != TSDB_CODE_SUCCESS) { + tdFreeSBlockRowMerger(pBlkRowMerger); taosHashCleanup(pVnodeDataBlockHashList); destroyBlockArrayList(pVnodeDataBlockList); taosMemoryFreeClear(blkKeyInfo.pKeyTuple); @@ -490,6 +715,7 @@ int32_t mergeTableDataBlocks(SHashObj* pHashObj, uint8_t payloadType, SArray** p if (tmp != NULL) { dataBuf->pData = tmp; } else { // failed to allocate memory, free already allocated memory and return error code + tdFreeSBlockRowMerger(pBlkRowMerger); taosHashCleanup(pVnodeDataBlockHashList); destroyBlockArrayList(pVnodeDataBlockList); taosMemoryFreeClear(dataBuf->pData); @@ -501,7 +727,8 @@ int32_t mergeTableDataBlocks(SHashObj* pHashObj, uint8_t payloadType, SArray** p if (isRawPayload) { sortRemoveDataBlockDupRowsRaw(pOneTableBlock); } else { - if ((code = sortRemoveDataBlockDupRows(pOneTableBlock, &blkKeyInfo)) != 0) { + if ((code = sortMergeDataBlockDupRows(pOneTableBlock, &blkKeyInfo, &pBlkRowMerger)) != 0) { + tdFreeSBlockRowMerger(pBlkRowMerger); taosHashCleanup(pVnodeDataBlockHashList); destroyBlockArrayList(pVnodeDataBlockList); taosMemoryFreeClear(dataBuf->pData); @@ -529,6 +756,7 @@ int32_t mergeTableDataBlocks(SHashObj* pHashObj, uint8_t payloadType, SArray** p } // free the table data blocks; + tdFreeSBlockRowMerger(pBlkRowMerger); taosHashCleanup(pVnodeDataBlockHashList); taosMemoryFreeClear(blkKeyInfo.pKeyTuple); *pVgDataBlocks = pVnodeDataBlockList; diff --git a/source/libs/sync/src/syncMain.c b/source/libs/sync/src/syncMain.c index e0133641b3..a453b2572c 100644 --- a/source/libs/sync/src/syncMain.c +++ b/source/libs/sync/src/syncMain.c @@ -1550,12 +1550,12 @@ void syncNodeEventLog(const SSyncNode* pSyncNode, char* str) { char logBuf[256 + 256]; if (pSyncNode != NULL && pSyncNode->pRaftCfg != NULL && pSyncNode->pRaftStore != NULL) { snprintf(logBuf, sizeof(logBuf), - "vgId:%d, sync %s %s, term:%" PRIu64 ", commit:%" PRId64 ", first:%" PRId64 ", last:%" PRId64 - ", snapshot:%" PRId64 ", snapshot-term:%" PRIu64 - ", standby:%d, " - "strategy:%d, batch:%d, " - "replica-num:%d, " - "lconfig:%" PRId64 ", changing:%d, restore:%d, %s", + "vgId:%d, sync %s %s, tm:%" PRIu64 ", cmt:%" PRId64 ", fst:%" PRId64 ", lst:%" PRId64 ", snap:%" PRId64 + ", snap-tm:%" PRIu64 + ", sby:%d, " + "stgy:%d, bch:%d, " + "r-num:%d, " + "lcfg:%" PRId64 ", chging:%d, rsto:%d, %s", pSyncNode->vgId, syncUtilState2String(pSyncNode->state), str, pSyncNode->pRaftStore->currentTerm, pSyncNode->commitIndex, logBeginIndex, logLastIndex, snapshot.lastApplyIndex, snapshot.lastApplyTerm, pSyncNode->pRaftCfg->isStandBy, pSyncNode->pRaftCfg->snapshotStrategy, pSyncNode->pRaftCfg->batchSize, @@ -1573,12 +1573,12 @@ void syncNodeEventLog(const SSyncNode* pSyncNode, char* str) { char* s = (char*)taosMemoryMalloc(len); if (pSyncNode != NULL && pSyncNode->pRaftCfg != NULL && pSyncNode->pRaftStore != NULL) { snprintf(s, len, - "vgId:%d, sync %s %s, term:%" PRIu64 ", commit:%" PRId64 ", first:%" PRId64 ", last:%" PRId64 - ", snapshot:%" PRId64 ", snapshot-term:%" PRIu64 - ", standby:%d, " - "strategy:%d, batch:%d, " - "replica-num:%d, " - "lconfig:%" PRId64 ", changing:%d, restore:%d, %s", + "vgId:%d, sync %s %s, tm:%" PRIu64 ", cmt:%" PRId64 ", fst:%" PRId64 ", lst:%" PRId64 ", snap:%" PRId64 + ", snap-tm:%" PRIu64 + ", sby:%d, " + "stgy:%d, bch:%d, " + "r-num:%d, " + "lcfg:%" PRId64 ", chging:%d, rsto:%d, %s", pSyncNode->vgId, syncUtilState2String(pSyncNode->state), str, pSyncNode->pRaftStore->currentTerm, pSyncNode->commitIndex, logBeginIndex, logLastIndex, snapshot.lastApplyIndex, snapshot.lastApplyTerm, pSyncNode->pRaftCfg->isStandBy, pSyncNode->pRaftCfg->snapshotStrategy, pSyncNode->pRaftCfg->batchSize, @@ -1621,12 +1621,12 @@ void syncNodeErrorLog(const SSyncNode* pSyncNode, char* str) { char logBuf[256 + 256]; if (pSyncNode != NULL && pSyncNode->pRaftCfg != NULL && pSyncNode->pRaftStore != NULL) { snprintf(logBuf, sizeof(logBuf), - "vgId:%d, sync %s %s, term:%" PRIu64 ", commit:%" PRId64 ", first:%" PRId64 ", last:%" PRId64 - ", snapshot:%" PRId64 ", snapshot-term:%" PRIu64 - ", standby:%d, " - "strategy:%d, batch:%d, " - "replica-num:%d, " - "lconfig:%" PRId64 ", changing:%d, restore:%d, %s", + "vgId:%d, sync %s %s, tm:%" PRIu64 ", cmt:%" PRId64 ", fst:%" PRId64 ", lst:%" PRId64 ", snap:%" PRId64 + ", snap-tm:%" PRIu64 + ", sby:%d, " + "stgy:%d, bch:%d, " + "r-num:%d, " + "lcfg:%" PRId64 ", chging:%d, rsto:%d, %s", pSyncNode->vgId, syncUtilState2String(pSyncNode->state), str, pSyncNode->pRaftStore->currentTerm, pSyncNode->commitIndex, logBeginIndex, logLastIndex, snapshot.lastApplyIndex, snapshot.lastApplyTerm, pSyncNode->pRaftCfg->isStandBy, pSyncNode->pRaftCfg->snapshotStrategy, pSyncNode->pRaftCfg->batchSize, @@ -1642,12 +1642,12 @@ void syncNodeErrorLog(const SSyncNode* pSyncNode, char* str) { char* s = (char*)taosMemoryMalloc(len); if (pSyncNode != NULL && pSyncNode->pRaftCfg != NULL && pSyncNode->pRaftStore != NULL) { snprintf(s, len, - "vgId:%d, sync %s %s, term:%" PRIu64 ", commit:%" PRId64 ", first:%" PRId64 ", last:%" PRId64 - ", snapshot:%" PRId64 ", snapshot-term:%" PRIu64 - ", standby:%d, " - "strategy:%d, batch:%d, " - "replica-num:%d, " - "lconfig:%" PRId64 ", changing:%d, restore:%d, %s", + "vgId:%d, sync %s %s, tm:%" PRIu64 ", cmt:%" PRId64 ", fst:%" PRId64 ", lst:%" PRId64 ", snap:%" PRId64 + ", snap-tm:%" PRIu64 + ", sby:%d, " + "stgy:%d, bch:%d, " + "r-num:%d, " + "lcfg:%" PRId64 ", chging:%d, rsto:%d, %s", pSyncNode->vgId, syncUtilState2String(pSyncNode->state), str, pSyncNode->pRaftStore->currentTerm, pSyncNode->commitIndex, logBeginIndex, logLastIndex, snapshot.lastApplyIndex, snapshot.lastApplyTerm, pSyncNode->pRaftCfg->isStandBy, pSyncNode->pRaftCfg->snapshotStrategy, pSyncNode->pRaftCfg->batchSize, @@ -1675,11 +1675,10 @@ char* syncNode2SimpleStr(const SSyncNode* pSyncNode) { SyncIndex logBeginIndex = pSyncNode->pLogStore->syncLogBeginIndex(pSyncNode->pLogStore); snprintf(s, len, - "vgId:%d, sync %s, term:%" PRIu64 ", commit:%" PRId64 ", first:%" PRId64 ", last:%" PRId64 - ", snapshot:%" PRId64 - ", standby:%d, " - "replica-num:%d, " - "lconfig:%" PRId64 ", changing:%d, restore:%d", + "vgId:%d, sync %s, tm:%" PRIu64 ", cmt:%" PRId64 ", fst:%" PRId64 ", lst:%" PRId64 ", snap:%" PRId64 + ", sby:%d, " + "r-num:%d, " + "lcfg:%" PRId64 ", chging:%d, rsto:%d", pSyncNode->vgId, syncUtilState2String(pSyncNode->state), pSyncNode->pRaftStore->currentTerm, pSyncNode->commitIndex, logBeginIndex, logLastIndex, snapshot.lastApplyIndex, pSyncNode->pRaftCfg->isStandBy, pSyncNode->replicaNum, pSyncNode->pRaftCfg->lastConfigIndex, pSyncNode->changing, pSyncNode->restoreFinish); @@ -2977,7 +2976,7 @@ void syncLogSendAppendEntries(SSyncNode* pSyncNode, const SyncAppendEntries* pMs char logBuf[256]; snprintf(logBuf, sizeof(logBuf), "send sync-append-entries to %s:%d, {term:%" PRIu64 ", pre-index:%" PRId64 ", pre-term:%" PRIu64 - ", pterm:%" PRIu64 ", commit:%" PRId64 + ", pterm:%" PRIu64 ", cmt:%" PRId64 ", " "datalen:%d}, %s", host, port, pMsg->term, pMsg->prevLogIndex, pMsg->prevLogTerm, pMsg->privateTerm, pMsg->commitIndex, @@ -2992,7 +2991,7 @@ void syncLogRecvAppendEntries(SSyncNode* pSyncNode, const SyncAppendEntries* pMs char logBuf[256]; snprintf(logBuf, sizeof(logBuf), "recv sync-append-entries from %s:%d {term:%" PRIu64 ", pre-index:%" PRIu64 ", pre-term:%" PRIu64 - ", commit:%" PRIu64 ", pterm:%" PRIu64 + ", cmt:%" PRIu64 ", pterm:%" PRIu64 ", " "datalen:%d}, %s", host, port, pMsg->term, pMsg->prevLogIndex, pMsg->prevLogTerm, pMsg->commitIndex, pMsg->privateTerm, @@ -3007,7 +3006,7 @@ void syncLogSendAppendEntriesBatch(SSyncNode* pSyncNode, const SyncAppendEntries char logBuf[256]; snprintf(logBuf, sizeof(logBuf), "send sync-append-entries-batch to %s:%d, {term:%" PRIu64 ", pre-index:%" PRId64 ", pre-term:%" PRIu64 - ", pterm:%" PRIu64 ", commit:%" PRId64 ", datalen:%d, count:%d}, %s", + ", pterm:%" PRIu64 ", cmt:%" PRId64 ", datalen:%d, count:%d}, %s", host, port, pMsg->term, pMsg->prevLogIndex, pMsg->prevLogTerm, pMsg->privateTerm, pMsg->commitIndex, pMsg->dataLen, pMsg->dataCount, s); syncNodeEventLog(pSyncNode, logBuf); @@ -3020,7 +3019,7 @@ void syncLogRecvAppendEntriesBatch(SSyncNode* pSyncNode, const SyncAppendEntries char logBuf[256]; snprintf(logBuf, sizeof(logBuf), "recv sync-append-entries-batch from %s:%d, {term:%" PRIu64 ", pre-index:%" PRId64 ", pre-term:%" PRIu64 - ", pterm:%" PRIu64 ", commit:%" PRId64 ", datalen:%d, count:%d}, %s", + ", pterm:%" PRIu64 ", cmt:%" PRId64 ", datalen:%d, count:%d}, %s", host, port, pMsg->term, pMsg->prevLogIndex, pMsg->prevLogTerm, pMsg->privateTerm, pMsg->commitIndex, pMsg->dataLen, pMsg->dataCount, s); syncNodeEventLog(pSyncNode, logBuf); diff --git a/source/libs/sync/src/syncRaftCfg.c b/source/libs/sync/src/syncRaftCfg.c index 0bbeaaf5b0..c634a1bf49 100644 --- a/source/libs/sync/src/syncRaftCfg.c +++ b/source/libs/sync/src/syncRaftCfg.c @@ -101,7 +101,7 @@ cJSON *syncCfg2Json(SSyncCfg *pSyncCfg) { char *syncCfg2Str(SSyncCfg *pSyncCfg) { cJSON *pJson = syncCfg2Json(pSyncCfg); - char * serialized = cJSON_Print(pJson); + char *serialized = cJSON_Print(pJson); cJSON_Delete(pJson); return serialized; } @@ -109,10 +109,10 @@ char *syncCfg2Str(SSyncCfg *pSyncCfg) { char *syncCfg2SimpleStr(SSyncCfg *pSyncCfg) { if (pSyncCfg != NULL) { int32_t len = 512; - char * s = taosMemoryMalloc(len); + char *s = taosMemoryMalloc(len); memset(s, 0, len); - snprintf(s, len, "{replica-num:%d, my-index:%d, ", pSyncCfg->replicaNum, pSyncCfg->myIndex); + snprintf(s, len, "{r-num:%d, my:%d, ", pSyncCfg->replicaNum, pSyncCfg->myIndex); char *p = s + strlen(s); for (int i = 0; i < pSyncCfg->replicaNum; ++i) { /* @@ -206,7 +206,7 @@ cJSON *raftCfg2Json(SRaftCfg *pRaftCfg) { char *raftCfg2Str(SRaftCfg *pRaftCfg) { cJSON *pJson = raftCfg2Json(pRaftCfg); - char * serialized = cJSON_Print(pJson); + char *serialized = cJSON_Print(pJson); cJSON_Delete(pJson); return serialized; } @@ -285,7 +285,7 @@ int32_t raftCfgFromJson(const cJSON *pRoot, SRaftCfg *pRaftCfg) { (pRaftCfg->configIndexArr)[i] = atoll(pIndex->valuestring); } - cJSON * pJsonSyncCfg = cJSON_GetObjectItem(pJson, "SSyncCfg"); + cJSON *pJsonSyncCfg = cJSON_GetObjectItem(pJson, "SSyncCfg"); int32_t code = syncCfgFromJson(pJsonSyncCfg, &(pRaftCfg->cfg)); ASSERT(code == 0); diff --git a/tests/script/jenkins/basic.txt b/tests/script/jenkins/basic.txt index f319de4c2f..1ef6d55b27 100644 --- a/tests/script/jenkins/basic.txt +++ b/tests/script/jenkins/basic.txt @@ -110,9 +110,9 @@ ./test.sh -f tsim/parser/fourArithmetic-basic.sim # jira ./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_child.sim -## ./test.sh -f tsim/parser/having.sim +# jira ./test.sh -f tsim/parser/groupby.sim +# jira ./test.sh -f tsim/parser/having_child.sim +# jira ./test.sh -f tsim/parser/having.sim ./test.sh -f tsim/parser/import_commit1.sim ./test.sh -f tsim/parser/import_commit2.sim ./test.sh -f tsim/parser/import_commit3.sim @@ -137,37 +137,36 @@ ## ./test.sh -f tsim/parser/limit_stb.sim ## ./test.sh -f tsim/parser/limit_tb.sim ## ./test.sh -f tsim/parser/line_insert.sim -# ./test.sh -f tsim/parser/mixed_blocks.sim -# ./test.sh -f tsim/parser/nchar.sim +./test.sh -f tsim/parser/mixed_blocks.sim +./test.sh -f tsim/parser/nchar.sim # ./test.sh -f tsim/parser/nestquery.sim -# ./test.sh -f tsim/parser/null_char.sim -## ./test.sh -f tsim/parser/precision_ns.sim -# ./test.sh -f tsim/parser/projection_limit_offset.sim -## ./test.sh -f tsim/parser/regex.sim -# ./test.sh -f tsim/parser/repeatAlter.sim -# ./test.sh -f tsim/parser/selectResNum.sim -# ./test.sh -f tsim/parser/select_across_vnodes.sim -# ./test.sh -f tsim/parser/select_distinct_tag.sim -# ./test.sh -f tsim/parser/select_from_cache_disk.sim -# ./test.sh -f tsim/parser/select_with_tags.sim -# ./test.sh -f tsim/parser/set_tag_vals.sim -# ./test.sh -f tsim/parser/single_row_in_tb.sim -# ./test.sh -f tsim/parser/sliding.sim -# ./test.sh -f tsim/parser/slimit_alter_tags.sim -# ./test.sh -f tsim/parser/slimit.sim -# ./test.sh -f tsim/parser/slimit1.sim +# jira ./test.sh -f tsim/parser/null_char.sim +./test.sh -f tsim/parser/precision_ns.sim +./test.sh -f tsim/parser/projection_limit_offset.sim +./test.sh -f tsim/parser/regex.sim +./test.sh -f tsim/parser/select_across_vnodes.sim +./test.sh -f tsim/parser/select_distinct_tag.sim +./test.sh -f tsim/parser/select_from_cache_disk.sim +# jira ./test.sh -f tsim/parser/select_with_tags.sim +./test.sh -f tsim/parser/selectResNum.sim +# jira ./test.sh -f tsim/parser/set_tag_vals.sim +./test.sh -f tsim/parser/single_row_in_tb.sim +# jira ./test.sh -f tsim/parser/sliding.sim +# jira ./test.sh -f tsim/parser/slimit_alter_tags.sim +# jira ./test.sh -f tsim/parser/slimit.sim +# jira ./test.sh -f tsim/parser/slimit1.sim ./test.sh -f tsim/parser/stableOp.sim -# ./test.sh -f tsim/parser/tags_dynamically_specifiy.sim -# ./test.sh -f tsim/parser/tags_filter.sim +# jira ./test.sh -f tsim/parser/tags_dynamically_specifiy.sim +# jira ./test.sh -f tsim/parser/tags_filter.sim ./test.sh -f tsim/parser/tbnameIn.sim ./test.sh -f tsim/parser/timestamp.sim ./test.sh -f tsim/parser/top_groupby.sim ./test.sh -f tsim/parser/topbot.sim -# ./test.sh -f tsim/parser/udf_dll_stable.sim -# ./test.sh -f tsim/parser/udf_dll.sim -# ./test.sh -f tsim/parser/udf.sim +# jira ./test.sh -f tsim/parser/udf_dll_stable.sim +# jira ./test.sh -f tsim/parser/udf_dll.sim +# jira ./test.sh -f tsim/parser/udf.sim # ./test.sh -f tsim/parser/union.sim -# ./test.sh -f tsim/parser/where.sim +# jira ./test.sh -f tsim/parser/where.sim # ---- query ./test.sh -f tsim/query/interval.sim @@ -426,18 +425,18 @@ ./test.sh -f tsim/tag/bool_binary.sim ./test.sh -f tsim/tag/bool_int.sim ./test.sh -f tsim/tag/bool.sim -# ./test.sh -f tsim/tag/change.sim -# ./test.sh -f tsim/tag/column.sim -# ./test.sh -f tsim/tag/commit.sim -# ./test.sh -f tsim/tag/create.sim -# ./test.sh -f tsim/tag/delete.sim +# jira ./test.sh -f tsim/tag/change.sim +# jira ./test.sh -f tsim/tag/column.sim +# jira ./test.sh -f tsim/tag/commit.sim +# jira ./test.sh -f tsim/tag/create.sim +# jira /test.sh -f tsim/tag/delete.sim # jira ./test.sh -f tsim/tag/double.sim -# ./test.sh -f tsim/tag/filter.sim +# jira ./test.sh -f tsim/tag/filter.sim # jira ./test.sh -f tsim/tag/float.sim ./test.sh -f tsim/tag/int_binary.sim ./test.sh -f tsim/tag/int_float.sim ./test.sh -f tsim/tag/int.sim -# ./test.sh -f tsim/tag/set.sim +# jira ./test.sh -f tsim/tag/set.sim ./test.sh -f tsim/tag/smallint.sim ./test.sh -f tsim/tag/tinyint.sim diff --git a/tests/script/tsim/insert/update0.sim b/tests/script/tsim/insert/update0.sim index 09b8de08e6..c6843acb9d 100644 --- a/tests/script/tsim/insert/update0.sim +++ b/tests/script/tsim/insert/update0.sim @@ -79,8 +79,8 @@ if $rows != 3 then return -1 endi -if $data01 != 103 then - print data01 $data01 != 103 +if $data01 != 303 then + print data01 $data01 != 303 return -1 endi @@ -89,8 +89,8 @@ if $data11 != 80 then return -1 endi -if $data21 != 40 then - print data21 $data21 != 40 +if $data21 != 60 then + print data21 $data21 != 60 return -1 endi @@ -138,8 +138,8 @@ if $rows != 3 then return -1 endi -if $data01 != 103 then - print data01 $data01 != 103 +if $data01 != 303 then + print data01 $data01 != 303 return -1 endi @@ -148,8 +148,8 @@ if $data11 != 80 then return -1 endi -if $data21 != 40 then - print data21 $data21 != 40 +if $data21 != 60 then + print data21 $data21 != 60 return -1 endi @@ -208,8 +208,8 @@ if $data01 != 10 then return -1 endi -if $data11 != 103 then - print data11 $data11 != 103 +if $data11 != 303 then + print data11 $data11 != 303 return -1 endi @@ -218,8 +218,8 @@ if $data21 != NULL then return -1 endi -if $data31 != 40 then - print data31 $data31 != 40 +if $data31 != 60 then + print data31 $data31 != 60 return -1 endi diff --git a/tests/script/tsim/insert/update1_sort_merge.sim b/tests/script/tsim/insert/update1_sort_merge.sim new file mode 100644 index 0000000000..c4f7877220 --- /dev/null +++ b/tests/script/tsim/insert/update1_sort_merge.sim @@ -0,0 +1,818 @@ +system sh/stop_dnodes.sh +system sh/deploy.sh -n dnode1 -i 1 +system sh/exec.sh -n dnode1 -s start +sql connect + +print =============== create database +sql drop database if exists d0 +sql create database d0 keep 365000d,365000d,365000d +sql use d0 + +print =============== create super table +sql create table if not exists stb (ts timestamp, c1 int unsigned, c2 double, c3 binary(10), c4 nchar(10), c5 double) tags (city binary(20),district binary(20)); + +sql show stables +if $rows != 1 then + return -1 +endi + +print =============== create child table +sql create table ct1 using stb tags("BeiJing", "ChaoYang") +sql create table ct2 using stb tags("BeiJing", "HaiDian") +sql create table ct3 using stb tags("BeiJing", "PingGu") +sql create table ct4 using stb tags("BeiJing", "YanQing") + +sql show tables +if $rows != 4 then + print rows $rows != 4 + return -1 +endi + +print =============== step 1 insert records into ct1 - taosd merge +sql insert into ct1(ts,c1,c2) values('2022-05-03 16:59:00.010', 10, 20); +sql insert into ct1(ts,c1,c2,c3,c4) values('2022-05-03 16:59:00.011', 11, NULL, 'binary', 'nchar'); +sql insert into ct1 values('2022-05-03 16:59:00.016', 16, NULL, NULL, 'nchar', NULL); +sql insert into ct1 values('2022-05-03 16:59:00.016', 17, NULL, NULL, 'nchar', 170); +sql insert into ct1 values('2022-05-03 16:59:00.020', 20, NULL, NULL, 'nchar', 200); +sql insert into ct1 values('2022-05-03 16:59:00.016', 18, NULL, NULL, 'nchar', 180); +sql insert into ct1 values('2022-05-03 16:59:00.021', 21, NULL, NULL, 'nchar', 210); +sql insert into ct1 values('2022-05-03 16:59:00.022', 22, NULL, NULL, 'nchar', 220); + +print =============== step 2 insert records into ct1/ct2 - taosc merge for 2022-05-03 16:59:00.010 +sql insert into ct1(ts,c1,c2) values('2022-05-03 16:59:00.010', 10,10), ('2022-05-03 16:59:00.010',20,10.0), ('2022-05-03 16:59:00.010',30,NULL) ct2(ts,c1) values('2022-05-03 16:59:00.010',10), ('2022-05-03 16:59:00.010',20) ct1(ts,c2) values('2022-05-03 16:59:00.010',10), ('2022-05-03 16:59:00.010',100) ct1(ts,c3) values('2022-05-03 16:59:00.010','bin1'), ('2022-05-03 16:59:00.010','bin2') ct1(ts,c4,c5) values('2022-05-03 16:59:00.010',NULL,NULL), ('2022-05-03 16:59:00.010','nchar4',1000.01) ct2(ts,c2,c3,c4,c5) values('2022-05-03 16:59:00.010',20,'xkl','zxc',10); + +print =============== step 3 insert records into ct3 +sql insert into ct3(ts,c1,c5) values('2022-05-03 16:59:00.020', 10,10); +sql insert into ct3(ts,c1,c5) values('2022-05-03 16:59:00.021', 10,10), ('2022-05-03 16:59:00.021',20,20.0); +sql insert into ct3(ts,c1,c5) values('2022-05-03 16:59:00.022', 30,30), ('2022-05-03 16:59:00.022',40,40.0),('2022-05-03 16:59:00.022',50,50.0); +sql insert into ct3(ts,c1,c5) values('2022-05-03 16:59:00.023', 60,60), ('2022-05-03 16:59:00.023',70,70.0),('2022-05-03 16:59:00.023',80,80.0), ('2022-05-03 16:59:00.023',90,90.0); +sql insert into ct3(ts,c1,c5) values('2022-05-03 16:59:00.024', 100,100), ('2022-05-03 16:59:00.025',110,110.0),('2022-05-03 16:59:00.025',120,120.0), ('2022-05-03 16:59:00.025',130,130.0); +sql insert into ct3(ts,c1,c5) values('2022-05-03 16:59:00.030', 140,140), ('2022-05-03 16:59:00.030',150,150.0),('2022-05-03 16:59:00.031',160,160.0), ('2022-05-03 16:59:00.030',170,170.0), ('2022-05-03 16:59:00.031',180,180.0); +sql insert into ct3(ts,c1,c5) values('2022-05-03 16:59:00.042', 190,190), ('2022-05-03 16:59:00.041',200,200.0),('2022-05-03 16:59:00.040',210,210.0); +sql insert into ct3(ts,c1,c5) values('2022-05-03 16:59:00.050', 220,220), ('2022-05-03 16:59:00.051',230,230.0),('2022-05-03 16:59:00.052',240,240.0); + +print =============== step 4 insert records into ct4 +sql insert into ct4(ts,c1,c3,c4) values('2022-05-03 16:59:00.020', 10,'b0','n0'); +sql insert into ct4(ts,c1,c3,c4) values('2022-05-03 16:59:00.021', 20,'b1','n1'), ('2022-05-03 16:59:00.021',30,'b2','n2'); +sql insert into ct4(ts,c1,c3,c4) values('2022-05-03 16:59:00.022', 40,'b3','n3'), ('2022-05-03 16:59:00.022',40,'b4','n4'),('2022-05-03 16:59:00.022',50,'b5','n5'); +sql insert into ct4(ts,c1,c3,c4) values('2022-05-03 16:59:00.023', 60,'b6','n6'), ('2022-05-03 16:59:00.024',70,'b7','n7'),('2022-05-03 16:59:00.024',80,'b8','n8'), ('2022-05-03 16:59:00.023',90,'b9','n9'); + + + +print =============== step 5 query records of ct1 from memory(taosc and taosd merge) +sql select * from ct1; +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 +print $data40 $data41 $data42 $data43 $data44 $data45 +print $data50 $data51 $data52 $data53 $data54 $data55 + +if $rows != 6 then + print rows $rows != 6 + return -1 +endi + +if $data01 != 30 then + print data01 $data01 != 30 + return -1 +endi + +if $data02 != 100.000000000 then + print data02 $data02 != 100.000000000 + return -1 +endi + +if $data03 != bin2 then + print data03 $data03 != bin2 + return -1 +endi + +if $data04 != nchar4 then + print data04 $data04 != nchar4 + return -1 +endi + +if $data05 != 1000.010000000 then + print data05 $data05 != 1000.010000000 + return -1 +endi + +if $data11 != 11 then + print data11 $data11 != 11 + return -1 +endi + +if $data12 != NULL then + print data12 $data12 != NULL + return -1 +endi + +if $data13 != binary then + print data13 $data13 != binary + return -1 +endi + +if $data14 != nchar then + print data14 $data14 != nchar + return -1 +endi + +if $data15 != NULL then + print data15 $data15 != NULL + return -1 +endi + +if $data51 != 22 then + print data51 $data51 != 22 + return -1 +endi + +if $data52 != NULL then + print data52 $data52 != NULL + return -1 +endi + +if $data53 != NULL then + print data53 $data53 != NULL + return -1 +endi + +if $data54 != nchar then + print data54 $data54 != nchar + return -1 +endi + +if $data55 != 220.000000000 then + print data55 $data55 != 220.000000000 + return -1 +endi + + +print =============== step 6 query records of ct2 from memory(taosc and taosd merge) +sql select * from ct2; +print $data00 $data01 $data02 $data03 $data04 $data05 + +if $rows != 1 then + print rows $rows != 1 + return -1 +endi + +if $data01 != 20 then + print data01 $data01 != 20 + return -1 +endi + +if $data02 != 20.000000000 then + print data02 $data02 != 20.000000000 + return -1 +endi + +if $data03 != xkl then + print data03 $data03 != xkl + return -1 +endi + +if $data04 != zxc then + print data04 $data04 != zxc + return -1 +endi + +if $data05 != 10.000000000 then + print data05 $data05 != 10.000000000 + return -1 +endi + +print =============== step 7 query records of ct3 from memory +sql select * from ct3; +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 +print $data40 $data41 $data42 $data43 $data44 $data45 +print $data50 $data51 $data52 $data53 $data54 $data55 +print $data60 $data61 $data62 $data63 $data64 $data65 +print $data70 $data71 $data72 $data73 $data74 $data75 +print $data80 $data81 $data82 $data83 $data84 $data85 +print $data90 $data91 $data92 $data93 $data94 $data95 +print $data[10][0] $data[10][1] $data[10][2] $data[10][3] $data[10][4] $data[10][5] +print $data[11][0] $data[11][1] $data[11][2] $data[11][3] $data[11][4] $data[11][5] +print $data[12][0] $data[12][1] $data[12][2] $data[12][3] $data[12][4] $data[12][5] +print $data[13][0] $data[13][1] $data[13][2] $data[13][3] $data[13][4] $data[13][5] + +if $rows != 14 then + print rows $rows != 14 + return -1 +endi + +if $data01 != 10 then + print data01 $data01 != 10 + return -1 +endi + +if $data11 != 20 then + print data11 $data1 != 20 + return -1 +endi + +if $data21 != 50 then + print data21 $data21 != 50 + return -1 +endi + +if $data31 != 90 then + print data31 $data31 != 90 + return -1 +endi + +if $data41 != 100 then + print data41 $data41 != 100 + return -1 +endi + +if $data51 != 130 then + print data51 $data51 != 130 + return -1 +endi + +if $data61 != 170 then + print data61 $data61 != 170 + return -1 +endi + +if $data71 != 180 then + print data71 $data71 != 180 + return -1 +endi + +if $data81 != 210 then + print data81 $data81 != 210 + return -1 +endi + +if $data91 != 200 then + print data91 $data91 != 200 + return -1 +endi + +if $data[10][1] != 190 then + print data[10][1] $data[10][1] != 190 + return -1 +endi + +if $data[11][1] != 220 then + print data[11][1] $data[11][1] != 220 + return -1 +endi + +if $data[12][1] != 230 then + print data[12][1] $data[12][1] != 230 + return -1 +endi + +if $data[13][1] != 240 then + print data[13][1] $data[13][1] != 240 + return -1 +endi + +if $data05 != 10.000000000 then + print data05 $data05 != 10.000000000 + return -1 +endi + +if $data15 != 20.000000000 then + print data15 $data5 != 20.000000000 + return -1 +endi + +if $data25 != 50.000000000 then + print data25 $data25 != 50.000000000 + return -1 +endi + +if $data35 != 90.000000000 then + print data35 $data35 != 90.000000000 + return -1 +endi + +if $data45 != 100.000000000 then + print data45 $data45 != 100.000000000 + return -1 +endi + +if $data55 != 130.000000000 then + print data55 $data55 != 130.000000000 + return -1 +endi + +if $data65 != 170.000000000 then + print data65 $data65 != 170.000000000 + return -1 +endi + +if $data75 != 180.000000000 then + print data75 $data75 != 180.000000000 + return -1 +endi + +if $data85 != 210.000000000 then + print data85 $data85 != 210.000000000 + return -1 +endi + +if $data95 != 200.000000000 then + print data95 $data95 != 200.000000000 + return -1 +endi + +if $data[10][5] != 190.000000000 then + print data[10][5] $data[10][5] != 190.000000000 + return -1 +endi + +if $data[11][5] != 220.000000000 then + print data[11][5] $data[11][5] != 220.000000000 + return -1 +endi + +if $data[12][5] != 230.000000000 then + print data[12][5] $data[12][5] != 230.000000000 + return -1 +endi + +if $data[13][5] != 240.000000000 then + print data[13][5] $data[13][5] != 240.000000000 + return -1 +endi + + +print =============== step 8 query records of ct4 from memory +sql select * from ct4; +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 +print $data40 $data41 $data42 $data43 $data44 $data45 + + +if $rows != 5 then + print rows $rows != 5 + return -1 +endi + +if $data01 != 10 then + print data01 $data01 != 10 + return -1 +endi + +if $data11 != 30 then + print data11 $data11 != 30 + return -1 +endi + +if $data21 != 50 then + print data21 $data21 != 50 + return -1 +endi + +if $data31 != 90 then + print data31 $data31 != 90 + return -1 +endi + +if $data41 != 80 then + print data41 $data41 != 80 + return -1 +endi + +if $data03 != b0 then + print data03 $data03 != b0 + return -1 +endi + +if $data13 != b2 then + print data13 $data13 != b2 + return -1 +endi + +if $data23 != b5 then + print data23 $data23 != b5 + return -1 +endi + +if $data33 != b9 then + print data33 $data33 != b9 + return -1 +endi + +if $data43 != b8 then + print data43 $data43 != b8 + return -1 +endi + +if $data04 != n0 then + print data04 $data04 != n0 + return -1 +endi + +if $data14 != n2 then + print data14 $data14 != n2 + return -1 +endi + +if $data24 != n5 then + print data24 $data24 != n5 + return -1 +endi + +if $data34 != n9 then + print data34 $data34 != n9 + return -1 +endi + +if $data44 != n8 then + print data44 $data44 != n8 + return -1 +endi + +#==================== reboot to trigger commit data to file +system sh/exec.sh -n dnode1 -s stop -x SIGINT +system sh/exec.sh -n dnode1 -s start + + + +print =============== step 9 query records of ct1 from file +sql select * from ct1; +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 +print $data40 $data41 $data42 $data43 $data44 $data45 +print $data50 $data51 $data52 $data53 $data54 $data55 + +if $rows != 6 then + print rows $rows != 6 + return -1 +endi + +if $data01 != 30 then + print data01 $data01 != 30 + return -1 +endi + +if $data02 != 100.000000000 then + print data02 $data02 != 100.000000000 + return -1 +endi + +if $data03 != bin2 then + print data03 $data03 != bin2 + return -1 +endi + +if $data04 != nchar4 then + print data04 $data04 != nchar4 + return -1 +endi + +if $data05 != 1000.010000000 then + print data05 $data05 != 1000.010000000 + return -1 +endi + +if $data11 != 11 then + print data11 $data11 != 11 + return -1 +endi + +if $data12 != NULL then + print data12 $data12 != NULL + return -1 +endi + +if $data13 != binary then + print data13 $data13 != binary + return -1 +endi + +if $data14 != nchar then + print data14 $data14 != nchar + return -1 +endi + +if $data15 != NULL then + print data15 $data15 != NULL + return -1 +endi + +if $data51 != 22 then + print data51 $data51 != 22 + return -1 +endi + +if $data52 != NULL then + print data52 $data52 != NULL + return -1 +endi + +if $data53 != NULL then + print data53 $data53 != NULL + return -1 +endi + +if $data54 != nchar then + print data54 $data54 != nchar + return -1 +endi + +if $data55 != 220.000000000 then + print data55 $data55 != 220.000000000 + return -1 +endi + + +print =============== step 10 query records of ct2 from file +sql select * from ct2; +print $data00 $data01 $data02 $data03 $data04 $data05 + +if $rows != 1 then + print rows $rows != 1 + return -1 +endi + +if $data01 != 20 then + print data01 $data01 != 20 + return -1 +endi + +if $data02 != 20.000000000 then + print data02 $data02 != 20.000000000 + return -1 +endi + +if $data03 != xkl then + print data03 $data03 != xkl + return -1 +endi + +if $data04 != zxc then + print data04 $data04 != zxc + return -1 +endi + +if $data05 != 10.000000000 then + print data05 $data05 != 10.000000000 + return -1 +endi + +print =============== step 11 query records of ct3 from file +sql select * from ct3; +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 +print $data40 $data41 $data42 $data43 $data44 $data45 +print $data50 $data51 $data52 $data53 $data54 $data55 +print $data60 $data61 $data62 $data63 $data64 $data65 +print $data70 $data71 $data72 $data73 $data74 $data75 +print $data80 $data81 $data82 $data83 $data84 $data85 +print $data90 $data91 $data92 $data93 $data94 $data95 +print $data[10][0] $data[10][1] $data[10][2] $data[10][3] $data[10][4] $data[10][5] +print $data[11][0] $data[11][1] $data[11][2] $data[11][3] $data[11][4] $data[11][5] +print $data[12][0] $data[12][1] $data[12][2] $data[12][3] $data[12][4] $data[12][5] +print $data[13][0] $data[13][1] $data[13][2] $data[13][3] $data[13][4] $data[13][5] + +if $rows != 14 then + print rows $rows != 14 + return -1 +endi + +if $data01 != 10 then + print data01 $data01 != 10 + return -1 +endi + +if $data11 != 20 then + print data11 $data1 != 20 + return -1 +endi + +if $data21 != 50 then + print data21 $data21 != 50 + return -1 +endi + +if $data31 != 90 then + print data31 $data31 != 90 + return -1 +endi + +if $data41 != 100 then + print data41 $data41 != 100 + return -1 +endi + +if $data51 != 130 then + print data51 $data51 != 130 + return -1 +endi + +if $data61 != 170 then + print data61 $data61 != 170 + return -1 +endi + +if $data71 != 180 then + print data71 $data71 != 180 + return -1 +endi + +if $data81 != 210 then + print data81 $data81 != 210 + return -1 +endi + +if $data91 != 200 then + print data91 $data91 != 200 + return -1 +endi + +if $data[10][1] != 190 then + print data[10][1] $data[10][1] != 190 + return -1 +endi + +if $data[11][1] != 220 then + print data[11][1] $data[11][1] != 220 + return -1 +endi + +if $data[12][1] != 230 then + print data[12][1] $data[12][1] != 230 + return -1 +endi + +if $data[13][1] != 240 then + print data[13][1] $data[13][1] != 240 + return -1 +endi + +if $data05 != 10.000000000 then + print data05 $data05 != 10.000000000 + return -1 +endi + +if $data15 != 20.000000000 then + print data15 $data5 != 20.000000000 + return -1 +endi + +if $data25 != 50.000000000 then + print data25 $data25 != 50.000000000 + return -1 +endi + +if $data35 != 90.000000000 then + print data35 $data35 != 90.000000000 + return -1 +endi + +if $data45 != 100.000000000 then + print data45 $data45 != 100.000000000 + return -1 +endi + +if $data55 != 130.000000000 then + print data55 $data55 != 130.000000000 + return -1 +endi + +if $data65 != 170.000000000 then + print data65 $data65 != 170.000000000 + return -1 +endi + +if $data75 != 180.000000000 then + print data75 $data75 != 180.000000000 + return -1 +endi + +if $data85 != 210.000000000 then + print data85 $data85 != 210.000000000 + return -1 +endi + +if $data95 != 200.000000000 then + print data95 $data95 != 200.000000000 + return -1 +endi + +if $data[10][5] != 190.000000000 then + print data[10][5] $data[10][5] != 190.000000000 + return -1 +endi + +if $data[11][5] != 220.000000000 then + print data[11][5] $data[11][5] != 220.000000000 + return -1 +endi + +if $data[12][5] != 230.000000000 then + print data[12][5] $data[12][5] != 230.000000000 + return -1 +endi + +if $data[13][5] != 240.000000000 then + print data[13][5] $data[13][5] != 240.000000000 + return -1 +endi + + +print =============== step 12 query records of ct4 from file +sql select * from ct4; +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 +print $data40 $data41 $data42 $data43 $data44 $data45 + + +if $rows != 5 then + print rows $rows != 5 + return -1 +endi + +if $data01 != 10 then + print data01 $data01 != 10 + return -1 +endi + +if $data11 != 30 then + print data11 $data11 != 30 + return -1 +endi + +if $data21 != 50 then + print data21 $data21 != 50 + return -1 +endi + +if $data31 != 90 then + print data31 $data31 != 90 + return -1 +endi + +if $data41 != 80 then + print data41 $data41 != 80 + return -1 +endi + +if $data03 != b0 then + print data03 $data03 != b0 + return -1 +endi + +if $data13 != b2 then + print data13 $data13 != b2 + return -1 +endi + +if $data23 != b5 then + print data23 $data23 != b5 + return -1 +endi + +if $data33 != b9 then + print data33 $data33 != b9 + return -1 +endi + +if $data43 != b8 then + print data43 $data43 != b8 + return -1 +endi + +if $data04 != n0 then + print data04 $data04 != n0 + return -1 +endi + +if $data14 != n2 then + print data14 $data14 != n2 + return -1 +endi + +if $data24 != n5 then + print data24 $data24 != n5 + return -1 +endi + +if $data34 != n9 then + print data34 $data34 != n9 + return -1 +endi + +if $data44 != n8 then + print data44 $data44 != n8 + return -1 +endi \ No newline at end of file diff --git a/tests/script/tsim/parser/mixed_blocks.sim b/tests/script/tsim/parser/mixed_blocks.sim index 50229ab35a..76ac7c1c54 100644 --- a/tests/script/tsim/parser/mixed_blocks.sim +++ b/tests/script/tsim/parser/mixed_blocks.sim @@ -54,7 +54,6 @@ sql show databases 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 @@ -76,7 +75,7 @@ while $x < $rowNum endw #### query a STable and using where clause to filter out all the data from tb2 and make the query only return first/last of tb1 -sql select first(ts,c1), last(ts,c1), spread(c1) from $stb where c1 > 0 group by t1 +sql select first(ts,c1), last(ts,c1), spread(c1), t1 from $stb where c1 > 0 group by t1 if $rows != 1 then return -1 endi @@ -99,7 +98,7 @@ if $data05 != 1 then return -1 endi -sql select max(c1), min(c1), sum(c1), avg(c1), count(c1) from $stb where c1 > 0 group by t1 +sql select max(c1), min(c1), sum(c1), avg(c1), count(c1), t1 from $stb where c1 > 0 group by t1 if $rows != 1 then return -1 endi @@ -149,7 +148,6 @@ sql insert into t2 values('2020-1-1 1:5:1', 99); 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 select ts from m1 where ts='2020-1-1 1:5:1' diff --git a/tests/script/tsim/parser/nchar.sim b/tests/script/tsim/parser/nchar.sim index 52fc8b6864..ca94d964bb 100644 --- a/tests/script/tsim/parser/nchar.sim +++ b/tests/script/tsim/parser/nchar.sim @@ -228,7 +228,8 @@ sql_error select avg(tbcol) from $mt where tbcol1 = 1 group by tgcol sql_error select sum(tbcol) from $mt where tbcol1 = 1 group by tgcol sql_error select min(tbcol) from $mt where tbcol1 = 1 group by tgcol sql_error select max(tbcol) from $mt where tbcol1 = 1 group by tgcol -sql select first(tbcol) from $mt where tbcol1 = 1 group by tgcol + +sql select first(tbcol), tgcol from $mt where tbcol1 = 1 group by tgcol order by tgcol if $rows != 2 then return -1 endi @@ -244,7 +245,8 @@ endi if $data11 != 1 then return -1 endi -sql select last(tbcol) from $mt where tbcol1 = 1 group by tgcol + +sql select last(tbcol), tgcol from $mt where tbcol1 = 1 group by tgcol order by tgcol if $rows != 2 then return -1 endi @@ -265,6 +267,7 @@ sql create table stbb (ts timestamp, c1 nchar(5)) tags (t1 int) sql create table tbb1 using stbb tags(1) sql insert into tbb1 values ('2018-09-17 09:00:00', '涛思') sql insert into tbb1 values ('2018-09-17 09:00:01', 'insrt') + sql select * from tbb1 order by ts asc if $rows != 2 then return -1 diff --git a/tests/script/tsim/parser/null_char.sim b/tests/script/tsim/parser/null_char.sim index 2bdb960968..fca4da78a0 100644 --- a/tests/script/tsim/parser/null_char.sim +++ b/tests/script/tsim/parser/null_char.sim @@ -78,6 +78,8 @@ endi #### case 1: tag NULL, or 'NULL' sql create table mt2 (ts timestamp, col1 int, col3 float, col5 binary(8), col6 bool, col9 nchar(8)) tags (tag1 binary(8), tag2 nchar(8), tag3 int, tag5 bool) sql create table st2 using mt2 tags (NULL, 'NULL', 102, 'true') +sql insert into st2 (ts, col1) values(now, 1) + sql select tag1, tag2, tag3, tag5 from st2 if $rows != 1 then return -1 @@ -115,6 +117,7 @@ if $rows != 0 then endi sql create table st3 using mt2 tags (NULL, 'ABC', 103, 'FALSE') +sql insert into st3 (ts, col1) values(now, 1) sql select tag1, tag2, tag3, tag5 from st3 if $rows != 1 then return -1 @@ -134,9 +137,10 @@ if $data03 != 0 then endi ### bool: -sql_error create table stx using mt2 tags ('NULL', '123aBc', 104, '123') -sql_error create table sty using mt2 tags ('NULL', '123aBc', 104, 'xtz') +sql create table stx using mt2 tags ('NULL', '123aBc', 104, '123') +sql create table sty using mt2 tags ('NULL', '123aBc', 104, 'xtz') sql create table st4 using mt2 tags ('NULL', '123aBc', 104, 'NULL') +sql insert into st4 (ts, col1) values(now, 1) sql select tag1,tag2,tag3,tag5 from st4 if $rows != 1 then return -1 @@ -150,12 +154,13 @@ endi if $data02 != 104 then return -1 endi -if $data03 != NULL then +if $data03 != 0 then print ==6== expect: NULL, actually: $data03 return -1 endi sql create table st5 using mt2 tags ('NULL', '123aBc', 105, NULL) +sql insert into st5 (ts, col1) values(now, 1) sql select tag1,tag2,tag3,tag5 from st5 if $rows != 1 then return -1 @@ -173,8 +178,6 @@ if $data03 != NULL then return -1 endi - - #### case 2: dynamic create table using super table when insert into sql create table mt3 (ts timestamp, col1 int, col3 float, col5 binary(8), col6 bool, col9 nchar(8)) tags (tag1 binary(8), tag2 nchar(8), tag3 int, tag5 bool) sql_error insert into st31 using mt3 tags (NULL, 'NULL', 102, 'true') values (now+1s, 31, 31, 'bin_31', '123', 'nchar_31') @@ -182,10 +185,10 @@ sql_error insert into st32 using mt3 tags (NULL, 'ABC', 103, 'FALSE') values sql_error insert into st33 using mt3 tags ('NULL', '123aBc', 104, 'NULL') values (now+3s, 33, 33, 'bin_33', 'false123', 'nchar_33') sql_error insert into st34 using mt3 tags ('NULL', '123aBc', 105, NULL) values (now+4s, 34, 34.12345, 'bin_34', 'true123', 'nchar_34') - #### case 3: set tag value sql create table mt4 (ts timestamp, c1 int) tags (tag_binary binary(16), tag_nchar nchar(16), tag_int int, tag_bool bool, tag_float float, tag_double double) sql create table st41 using mt4 tags ("beijing", 'nchar_tag', 100, false, 9.12345, 7.123456789) +sql insert into st41 (ts, c1) values(now, 1) sql select tag_binary, tag_nchar, tag_int, tag_bool, tag_float, tag_double from st41 if $rows != 1 then return -1 @@ -245,7 +248,7 @@ endi ################### nchar sql alter table st41 set tag tag_nchar = "��˼����" sql select tag_binary, tag_nchar, tag_int, tag_bool, tag_float, tag_double from st41 -#sleep 100 + #if $data01 != ��˼���� then # print ==== expect ��˼����, actually $data01 # return -1 diff --git a/tests/script/tsim/parser/precision_ns.sim b/tests/script/tsim/parser/precision_ns.sim index bb822cd2b1..45b140f382 100644 --- a/tests/script/tsim/parser/precision_ns.sim +++ b/tests/script/tsim/parser/precision_ns.sim @@ -48,8 +48,6 @@ while $x < $rowNum $x = $x + 1 endw -sleep 100 - print =============== step2: select count(*) from tables $i = 0 $tb = $tbPrefix . $i @@ -103,7 +101,7 @@ sql select count(*) from $mt interval(100000000b) sliding(100000000b) print =============== clear sql drop database $db sql show databases -if $rows != 0 then +if $rows != 2 then return -1 endi diff --git a/tests/script/tsim/parser/projection_limit_offset.sim b/tests/script/tsim/parser/projection_limit_offset.sim index 37f2e79995..5a96af2b3e 100644 --- a/tests/script/tsim/parser/projection_limit_offset.sim +++ b/tests/script/tsim/parser/projection_limit_offset.sim @@ -271,14 +271,14 @@ endi #[tbase-695] sql select ts,tbname from group_mt0 where ts>='1970-01-01 8:1:40' and ts<'1970-1-1 8:1:45' and c1<99999999 limit 100000 offset 5000 +print ===> $data00 $data01 $data02 $data03 $data04 $data05 $data06 $data07 $data08 $data09 +print ===> $data10 $data11 $data12 $data13 $data14 $data15 $data16 $data17 $data18 $data19 +print ===> $data20 $data21 $data22 $data23 $data24 $data25 $data26 $data27 $data28 $data29 +print ===> $data30 $data31 $data32 $data33 $data34 $data35 $data36 $data37 $data38 $data39 if $row != 35000 then return -1 endi -if $data00 != @70-01-01 08:01:40.000@ then - return -1 -endi - #=================================parse error sql========================================== sql_error select ts,tbname from group_mt0 order by ts desc limit 100 offset -1; sql_error select ts,tbname from group_mt0 order by c1 asc limit 100 offset -1; @@ -287,13 +287,13 @@ sql_error select ts,tbname from group_mt0 order by ts desc slimit -1, 100; sql_error select ts,tbname from group_mt0 order by ts desc slimit 1 soffset 1; #================================functions applys to sql=================================== -sql_error select first(t1) from group_mt0; -sql_error select last(t1) from group_mt0; -sql_error select min(t1) from group_mt0; -sql_error select max(t1) from group_mt0; -sql_error select top(t1, 20) from group_mt0; -sql_error select bottom(t1, 20) from group_mt0; -sql_error select avg(t1) from group_mt0; +sql select first(t1) from group_mt0; +sql select last(t1) from group_mt0; +sql select min(t1) from group_mt0; +sql select max(t1) from group_mt0; +sql select top(t1, 20) from group_mt0; +sql select bottom(t1, 20) from group_mt0; +sql select avg(t1) from group_mt0; sql_error select percentile(t1, 50) from group_mt0; sql_error select percentile(t1, 50) from group_mt0; sql_error select percentile(t1, 50) from group_mt0; @@ -309,7 +309,7 @@ endi #====================================tbase-716============================================== print tbase-716 -sql_error select count(*) from group_tb0 where ts in ('2016-1-1 12:12:12'); +sql select count(*) from group_tb0 where ts in ('2016-1-1 12:12:12'); sql_error select count(*) from group_tb0 where ts < '12:12:12'; #===============================sql for twa========================================== @@ -345,7 +345,7 @@ if $rows != 0 then return -1 endi -sql select count(*),first(k),last(k) from m1 where tbname in ('tm0') interval(1s) order by ts desc; +sql select _wstart, count(*),first(k),last(k) from m1 where tbname in ('tm0') interval(1s) order by _wstart desc; if $row != 5 then return -1 endi @@ -374,6 +374,7 @@ if $data13 != NULL then return -1 endi + print =============tbase-1324 sql select a, k-k from m1 if $row != 8 then @@ -384,8 +385,7 @@ sql select diff(k) from tm0 if $row != 3 then return -1 endi - -if $data21 != -1 then +if $data20 != -1 then return -1 endi @@ -395,20 +395,19 @@ sql_error select * from 1; sql_error select k+k; sql_error select k+1; sql_error select abc(); -sql_error select 1 where 1=2; -sql_error select 1 limit 1; -sql_error select 1 slimit 1; -sql_error select 1 interval(1h); +sql select 1 where 1=2; +sql select 1 limit 1; +sql select 1 slimit 1; +sql select 1 interval(1h); sql_error select count(*); sql_error select sum(k); -sql_error select 'abc'; +sql select 'abc'; sql_error select k+1,sum(k) from tm0; sql_error select k, sum(k) from tm0; sql_error select k, sum(k)+1 from tm0; 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 diff --git a/tests/script/tsim/parser/regex.sim b/tests/script/tsim/parser/regex.sim index 41f52575d6..e5fb9f5f4e 100644 --- a/tests/script/tsim/parser/regex.sim +++ b/tests/script/tsim/parser/regex.sim @@ -18,12 +18,15 @@ sql create table $ct1_name using $st_name tags('taosdata1') sql create table $ct2_name using $st_name tags('taosdata2') sql create table not_match using $st_name tags('NOTMATCH') +sql insert into $ct1_name values(now, 'this is engine') +sql insert into $ct2_name values(now, 'this is app egnine') +sql insert into not_match values (now + 1s, '1234') + sql select tbname from $st_name where tbname match '.*' if $rows != 3 then return -1 endi - sql select tbname from $st_name where tbname match '^ct[[:digit:]]' if $rows != 2 then return -1 @@ -54,9 +57,6 @@ if $rows != 1 then return -1 endi -sql insert into $ct1_name values(now, 'this is engine') -sql insert into $ct2_name values(now, 'this is app egnine') - sql select c1b from $st_name where c1b match 'engine' if $data00 != @this is engine@ then return -1 @@ -66,12 +66,11 @@ if $rows != 1 then return -1 endi -sql select c1b from $st_name where c1b nmatch 'engine' +sql select c1b from $st_name where c1b nmatch 'engine' order by ts if $data00 != @this is app egnine@ then return -1 endi - -if $rows != 1 then +if $rows != 2 then return -1 endi @@ -96,8 +95,8 @@ sql_error select * from wrong_type where c5 match '.*' sql_error select * from wrong_type where c5 nmatch '.*' sql_error select * from wrong_type where c6 match '.*' sql_error select * from wrong_type where c6 nmatch '.*' -sql_error select * from wrong_type where c7 match '.*' -sql_error select * from wrong_type where c7 nmatch '.*' +sql select * from wrong_type where c7 match '.*' +sql select * from wrong_type where c7 nmatch '.*' sql_error select * from wrong_type where t1 match '.*' sql_error select * from wrong_type where t1 nmatch '.*' sql_error select * from wrong_type where t2 match '.*' @@ -110,9 +109,7 @@ sql_error select * from wrong_type where t5 match '.*' sql_error select * from wrong_type where t5 nmatch '.*' sql_error select * from wrong_type where t6 match '.*' sql_error select * from wrong_type where t6 nmatch '.*' -sql_error select * from wrong_type where t7 match '.*' -sql_error select * from wrong_type where t7 nmatch '.*' +sql select * from wrong_type where t7 match '.*' +sql select * from wrong_type where t7 nmatch '.*' system sh/exec.sh -n dnode1 -s stop -x SIGINT - - diff --git a/tests/script/tsim/parser/selectResNum.sim b/tests/script/tsim/parser/selectResNum.sim index ac5ccd6e07..69ea2dccd5 100644 --- a/tests/script/tsim/parser/selectResNum.sim +++ b/tests/script/tsim/parser/selectResNum.sim @@ -20,7 +20,7 @@ $stb = $stbPrefix . $i sql drop database $db -x step1 step1: -sql create database $db cache 16 +sql create database $db print ====== create tables 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) @@ -114,12 +114,8 @@ endw 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 -sleep 100 -sql connect -sleep 100 sql use $db ##### repeat test after server restart diff --git a/tests/script/tsim/parser/select_across_vnodes.sim b/tests/script/tsim/parser/select_across_vnodes.sim index 0ee011cf8a..c9696e563d 100644 --- a/tests/script/tsim/parser/select_across_vnodes.sim +++ b/tests/script/tsim/parser/select_across_vnodes.sim @@ -17,7 +17,7 @@ $db = $dbPrefix $stb = $stbPrefix sql drop database if exists $db -sql create database $db +sql create database $db vgroups 10 sql use $db print ====== create tables 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) @@ -72,7 +72,7 @@ endi sql drop database $db sql show databases -if $rows != 0 then +if $rows != 2 then return -1 endi diff --git a/tests/script/tsim/parser/select_distinct_tag.sim b/tests/script/tsim/parser/select_distinct_tag.sim index 92303ce64e..ec33ff8ac6 100644 --- a/tests/script/tsim/parser/select_distinct_tag.sim +++ b/tests/script/tsim/parser/select_distinct_tag.sim @@ -27,6 +27,7 @@ $ts = $ts0 while $i < $tbNum $tb = $tbPrefix . $i sql create table $tb using $stb tags( $i , 0 ) + sql insert into $tb (ts, c1) values (now, 1); $i = $i + 1 endw @@ -50,7 +51,7 @@ sql_error select distinct t1, t2 from &stb sql drop database $db sql show databases -if $rows != 0 then +if $rows != 2 then return -1 endi diff --git a/tests/script/tsim/parser/select_from_cache_disk.sim b/tests/script/tsim/parser/select_from_cache_disk.sim index 2c9f359afe..0983e36a3a 100644 --- a/tests/script/tsim/parser/select_from_cache_disk.sim +++ b/tests/script/tsim/parser/select_from_cache_disk.sim @@ -31,17 +31,13 @@ sql insert into $tb values ('2018-09-17 09:00:00.030', 3) 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 -sql use $db # generate some data in cache sql insert into $tb values ('2018-09-17 09:00:04.000', 4) sql insert into $tb values ('2018-09-17 09:00:04.010', 5) -sql select count(*) from $stb interval(1s) group by t1 +sql select _wstart, count(*), t1 from $stb partition by t1 interval(1s) order by _wstart if $rows != 2 then return -1 endi diff --git a/tests/script/tsim/parser/select_with_tags.sim b/tests/script/tsim/parser/select_with_tags.sim index b840a666f4..5130b39f48 100644 --- a/tests/script/tsim/parser/select_with_tags.sim +++ b/tests/script/tsim/parser/select_with_tags.sim @@ -62,9 +62,6 @@ while $i < $tbNum endw -sleep 100 - - #======================= only check first table tag, TD-4827 sql select count(*) from $mt where t1 in (0) if $rows != 1 then @@ -178,15 +175,15 @@ if $data03 != @abc15@ then endi sql select top(c6, 3) from select_tags_mt0 interval(10a) -sql select top(c3,10) from select_tags_mt0 interval(10a) group by tbname,t1,t2 -sql select top(c6, 3) from select_tags_mt0 interval(10a) group by tbname; +sql select top(c3,10) from select_tags_mt0 partition by tbname,t1,t2 interval(10a) +sql select top(c6, 3) from select_tags_mt0 partition by tbname interval(10a) sql select top(c6, 10) from select_tags_mt0 interval(10a); if $rows != 12800 then return -1 endi -sql select top(c1, 80), tbname, t1, t2 from select_tags_mt0; +sql select _rowts, top(c1, 80), tbname, t1, t2 from select_tags_mt0; if $rows != 80 then return -1 endi diff --git a/tests/script/tsim/parser/set_tag_vals.sim b/tests/script/tsim/parser/set_tag_vals.sim index 07b424ec6a..4bad716705 100644 --- a/tests/script/tsim/parser/set_tag_vals.sim +++ b/tests/script/tsim/parser/set_tag_vals.sim @@ -55,10 +55,8 @@ while $i < $tbNum $i = $i + 1 endw + print ====== tables created - -sleep 500 - sql show tables if $rows != $tbNum then return -1 @@ -74,12 +72,16 @@ while $i < $tbNum sql insert into $tb (ts, c1) values (now-100a, $i ) sql alter table $tb set tag t3 = $i sql insert into $tb (ts, c1) values (now, $i ) - sql alter table $tb set tag t4 = $i + + $name = ' . $i + $name = $name . ' + sql alter table $tb set tag t4 = $name $i = $i + 1 endw print ================== all tags have been changed! -sql_error select tbname from $stb where t3 = 'NULL' +sql reset query cache +sql select tbname from $stb where t3 = 'NULL' print ================== set tag to NULL sql create table stb1_tg (ts timestamp, c1 int) tags(t1 int,t2 bigint,t3 double,t4 float,t5 smallint,t6 tinyint) @@ -142,7 +144,9 @@ sql alter table tb1_tg2 set tag t1 = false sql alter table tb1_tg2 set tag t2 = 'binary2' sql alter table tb1_tg2 set tag t3 = '涛思' sql reset query cache + sql select * from stb1_tg +print ===> $data00 $data01 $data02 $data03 $data04 $data05 $data06 $data07 $data08 $data09 if $rows != 1 then return -1 endi @@ -164,7 +168,9 @@ endi if $data07 != -6 then return -1 endi + sql select * from stb2_tg +print ===> $data00 $data01 $data02 $data03 $data04 $data05 $data06 $data07 $data08 $data09 if $data02 != 0 then return -1 endi @@ -185,7 +191,9 @@ sql alter table tb1_tg2 set tag t1 = NULL sql alter table tb1_tg2 set tag t2 = NULL sql alter table tb1_tg2 set tag t3 = NULL sql reset query cache + sql select * from stb1_tg +print ===> $data00 $data01 $data02 $data03 $data04 $data05 $data06 $data07 $data08 $data09 if $rows != 1 then return -1 endi @@ -207,12 +215,12 @@ endi if $data07 != NULL then return -1 endi + sql select * from stb2_tg +print ===> $data00 $data01 $data02 $data03 $data04 $data05 $data06 $data07 $data08 $data09 if $data02 != NULL then return -1 endi - -print $data03 if $data03 != NULL then return -1 endi diff --git a/tests/script/tsim/parser/single_row_in_tb_query.sim b/tests/script/tsim/parser/single_row_in_tb_query.sim index acf85ea692..422756b798 100644 --- a/tests/script/tsim/parser/single_row_in_tb_query.sim +++ b/tests/script/tsim/parser/single_row_in_tb_query.sim @@ -1,4 +1,3 @@ -sleep 100 sql connect $dbPrefix = sr_db @@ -113,7 +112,7 @@ if $data02 != 2 then endi #### query a STable and using where clause -sql select first(ts,c1), last(ts,c1), spread(c1) from $stb where ts >= $ts0 and ts < '2018-09-20 00:00:00.000' group by t1 +sql select first(ts,c1), last(ts,c1), spread(c1), t1 from $stb where ts >= $ts0 and ts < '2018-09-20 00:00:00.000' group by t1 if $rows != 1 then return -1 endi @@ -137,7 +136,7 @@ if $data05 != 1 then return -1 endi -sql select first(c1), last(c1) from $stb where ts >= $ts0 and ts < '2018-09-20 00:00:00.000' interval(1d) group by t1 +sql select _wstart, first(c1), last(c1) from sr_stb where ts >= 1537146000000 and ts < '2018-09-20 00:00:00.000' partition by t1 interval(1d) if $rows != 1 then return -1 endi @@ -151,7 +150,7 @@ if $data02 != 1 then return -1 endi -sql select max(c1), min(c1), sum(c1), avg(c1), count(c1) from $stb where c1 > 0 group by t1 +sql select max(c1), min(c1), sum(c1), avg(c1), count(c1), t1 from $stb where c1 > 0 group by t1 if $rows != 1 then return -1 endi @@ -174,7 +173,7 @@ if $data05 != 1 then return -1 endi -sql select first(ts,c1), last(ts,c1) from $tb1 where ts >= $ts0 and ts < '2018-09-20 00:00:00.000' interval(1d) +sql select _wstart, first(ts,c1), last(ts,c1) from $tb1 where ts >= $ts0 and ts < '2018-09-20 00:00:00.000' interval(1d) if $rows != 1 then return -1 endi diff --git a/tests/script/tsim/parser/sliding.sim b/tests/script/tsim/parser/sliding.sim index 18d7bda8a1..b9353e2c61 100644 --- a/tests/script/tsim/parser/sliding.sim +++ b/tests/script/tsim/parser/sliding.sim @@ -58,8 +58,6 @@ while $i < $tbNum $tstart = 946656000000 endw -sleep 100 - $i1 = 1 $i2 = 0 @@ -76,425 +74,355 @@ $ts1 = $tb1 . .ts $ts2 = $tb2 . .ts print ===============================interval_sliding query -sql select count(*) from sliding_tb0 interval(30s) sliding(30s); +sql select _wstart, count(*) from sliding_tb0 interval(30s) sliding(30s); if $row != 10 then return -1 endi - if $data00 != @00-01-01 00:00:00.000@ then return -1 endi - if $data01 != 1000 then return -1 endi - if $data10 != @00-01-01 00:00:30.000@ then return -1 endi - if $data11 != 1000 then return -1 endi -sql select stddev(c1) from sliding_tb0 interval(10a) sliding(10a) +sql select _wstart, stddev(c1) from sliding_tb0 interval(10a) sliding(10a); if $row != 10000 then return -1 endi - if $data00 != @00-01-01 00:00:00.000@ then return -1 endi - if $data01 != 0.000000000 then return -1 endi - if $data90 != @00-01-01 00:00:00.270@ then return -1 endi - if $data91 != 0.000000000 then return -1 endi -sql select stddev(c1),count(c2),first(c3),last(c4) from sliding_tb0 interval(10a) sliding(10a) order by ts desc; +sql select _wstart, stddev(c1),count(c2),first(c3),last(c4) from sliding_tb0 interval(10a) sliding(10a) order by _wstart desc; if $row != 10000 then return -1 endi - if $data00 != @00-01-01 00:04:59.970@ then return -1 endi - if $data01 != 0.000000000 then return -1 endi - if $data02 != 1 then return -1 endi - if $data03 != 99 then return -1 endi - if $data04 != 99 then return -1 endi - if $data90 != @00-01-01 00:04:59.700@ then return -1 endi - if $data91 != 0.000000000 then return -1 endi - if $data92 != 1 then return -1 endi - if $data93 != 90 then return -1 endi - if $data94 != 90 then return -1 endi -sql select count(c2),last(c4) from sliding_tb0 interval(30s) sliding(10s) order by ts asc; +sql select _wstart, count(c2),last(c4) from sliding_tb0 interval(30s) sliding(10s) order by _wstart asc; if $row != 32 then return -1 endi - if $data00 != @99-12-31 23:59:40.000@ then print expect 12-31 23:59:40.000, actual: $data00 return -1 endi - if $data01 != 334 then return -1 endi - if $data02 != 33 then return -1 endi -sql select count(c2),stddev(c3),first(c4),last(c4) from sliding_tb0 where ts>'2000-01-01 0:0:0' and ts<'2000-1-1 0:0:31' interval(30s) sliding(30s) order by ts asc; +sql select _wstart, count(c2),stddev(c3),first(c4),last(c4) from sliding_tb0 where ts>'2000-01-01 0:0:0' and ts<'2000-1-1 0:0:31' interval(30s) sliding(30s) order by _wstart asc; if $row != 2 then return -1 endi - if $data04 != 99 then return -1 endi - if $data01 != 999 then return -1 endi - if $data02 != 28.837977152 then return -1 endi #interval offset + limit -sql select count(c2), first(c3),stddev(c4) from sliding_tb0 interval(10a) sliding(10a) order by ts desc limit 10 offset 990; +sql select _wstart, count(c2), first(c3),stddev(c4) from sliding_tb0 interval(10a) sliding(10a) order by _wstart desc limit 10 offset 990; if $row != 10 then return -1 endi - if $data00 != @00-01-01 00:04:30.270@ then return -1 endi - if $data01 != 1 then return -1 endi - if $data02 != 9 then return -1 endi - if $data03 != 0.000000000 then return -1 endi - if $data90 != @00-01-01 00:04:30.000@ then return -1 endi - if $data91 != 1 then return -1 endi - if $data92 != 0 then return -1 endi - if $data93 != 0.000000000 then return -1 endi #interval offset test -sql select count(c2),last(c4),stddev(c3) from sliding_tb0 interval(30s) sliding(30s) order by ts asc limit 1000 offset 1; +sql select _wstart, count(c2),last(c4),stddev(c3) from sliding_tb0 interval(30s) sliding(30s) order by _wstart asc limit 1000 offset 1; if $row != 9 then return -1 endi - if $data00 != @00-01-01 00:00:30.000@ then return -1 endi - if $data01 != 1000 then return -1 endi - if $data02 != 99 then return -1 endi - if $data80 != @00-01-01 00:04:30.000@ then return -1 endi - if $data81 != 1000 then return -1 endi -sql select count(c2),last(c4),stddev(c3) from sliding_tb0 where ts>'2000-1-1 0:0:0' and ts<'2000-1-1 0:0:31' interval(30s) sliding(30s) order by ts asc limit 1000 offset 0; +sql select _wstart, count(c2),last(c4),stddev(c3) from sliding_tb0 where ts>'2000-1-1 0:0:0' and ts<'2000-1-1 0:0:31' interval(30s) sliding(30s) order by _wstart asc limit 1000 offset 0; if $row != 2 then return -1 endi - if $data00 != @00-01-01 00:00:00.000@ then return -1 endi - if $data01 != 999 then return -1 endi - if $data02 != 99 then return -1 endi - if $data03 != 28.837977152 then return -1 endi - if $data10 != @00-01-01 00:00:30.000@ then return -1 endi - if $data11 != 34 then return -1 endi - if $data12 != 33 then return -1 endi - if $data13 != 9.810708435 then return -1 endi -sql select count(c2),last(c4),stddev(c3) from sliding_tb0 interval(30s) sliding(20s) order by ts asc limit 100 offset 1; +sql select _wstart, count(c2),last(c4),stddev(c3) from sliding_tb0 interval(30s) sliding(20s) order by _wstart asc limit 100 offset 1; if $row != 15 then return -1 endi - if $data00 != @00-01-01 00:00:00.000@ then return -1 endi - if $data01 != 1000 then return -1 endi - if $data02 != 99 then return -1 endi - if $data03 != 28.866070048 then return -1 endi - if $data90 != @00-01-01 00:03:00.000@ then return -1 endi - if $data91 != 1000 then return -1 endi - if $data92 != 99 then return -1 endi -sql select count(c2),last(c4),stddev(c3) from sliding_tb0 interval(30s) sliding(20s) order by ts asc limit 100 offset 5; +sql select count(c2),last(c4),stddev(c3) from sliding_tb0 interval(30s) sliding(20s) order by _wstart asc limit 100 offset 5; if $row != 11 then return -1 endi -sql select count(c2),last(c4),stddev(c3) from sliding_tb0 interval(30s) sliding(20s) order by ts asc limit 100 offset 6; +sql select count(c2),last(c4),stddev(c3) from sliding_tb0 interval(30s) sliding(20s) order by _wstart asc limit 100 offset 6; if $row != 10 then return -1 endi -sql select count(c2),last(c4),stddev(c3) from sliding_tb0 interval(30s) sliding(20s) order by ts asc limit 100 offset 7; +sql select count(c2),last(c4),stddev(c3) from sliding_tb0 interval(30s) sliding(20s) order by _wstart asc limit 100 offset 7; if $row != 9 then return -1 endi -sql select count(c2),last(c4),stddev(c3) from sliding_tb0 interval(30s) sliding(20s) order by ts asc limit 100 offset 8; +sql select count(c2),last(c4),stddev(c3) from sliding_tb0 interval(30s) sliding(20s) order by _wstart asc limit 100 offset 8; if $row != 8 then return -1 endi -sql select count(c2),last(c4),stddev(c3) from sliding_tb0 interval(30s) sliding(20s) order by ts asc limit 100 offset 9; +sql select count(c2),last(c4),stddev(c3) from sliding_tb0 interval(30s) sliding(20s) order by _wstart asc limit 100 offset 9; if $row != 7 then return -1 endi -sql select count(c2),last(c4),stddev(c3) from sliding_tb0 interval(30s) sliding(20s) order by ts asc limit 100 offset 10; +sql select count(c2),last(c4),stddev(c3) from sliding_tb0 interval(30s) sliding(20s) order by _wstart asc limit 100 offset 10; if $row != 6 then return -1 endi -sql select count(c2),last(c4),stddev(c3) from sliding_tb0 interval(30s) sliding(20s) order by ts asc limit 100 offset 11; +sql select count(c2),last(c4),stddev(c3) from sliding_tb0 interval(30s) sliding(20s) order by _wstart asc limit 100 offset 11; if $row != 5 then return -1 endi -sql select count(c2),last(c4),stddev(c3) from sliding_tb0 interval(30s) sliding(20s) order by ts asc limit 100 offset 12; +sql select count(c2),last(c4),stddev(c3) from sliding_tb0 interval(30s) sliding(20s) order by _wstart asc limit 100 offset 12; if $row != 4 then return -1 endi -sql select count(c2),last(c4),stddev(c3) from sliding_tb0 interval(30s) sliding(20s) order by ts asc limit 100 offset 13; +sql select count(c2),last(c4),stddev(c3) from sliding_tb0 interval(30s) sliding(20s) order by _wstart asc limit 100 offset 13; if $row != 3 then return -1 endi -sql select count(c2),last(c4),stddev(c3) from sliding_tb0 interval(30s) sliding(20s) order by ts asc limit 100 offset 14; +sql select count(c2),last(c4),stddev(c3) from sliding_tb0 interval(30s) sliding(20s) order by _wstart asc limit 100 offset 14; if $row != 2 then return -1 endi -sql select count(c2),last(c4),stddev(c3) from sliding_tb0 interval(30s) sliding(20s) order by ts asc limit 100 offset 15; +sql select count(c2),last(c4),stddev(c3) from sliding_tb0 interval(30s) sliding(20s) order by _wstart asc limit 100 offset 15; if $row != 1 then return -1 endi -sql select count(c2),last(c4),stddev(c3) from sliding_tb0 interval(30s) sliding(20s) order by ts asc limit 100 offset 16; +sql select count(c2),last(c4),stddev(c3) from sliding_tb0 interval(30s) sliding(20s) order by _wstart asc limit 100 offset 16; if $row != 0 then return -1 endi -sql select count(c2),last(c4),stddev(c3),spread(c3) from sliding_tb0 where c2 = 0 interval(30s) order by ts desc; +sql select _wstart, count(c2),last(c4),stddev(c3),spread(c3) from sliding_tb0 where c2 = 0 interval(30s) order by _wstart desc; if $row != 10 then return -1 endi - #00-01-01 00:04:30.000| 10| 0| 0.000000000| 0.000000000| if $data00 != @00-01-01 00:04:30.000@ then return -1 endi - if $data01 != 10 then return -1 endi - if $data02 != 0 then return -1 endi - if $data03 != 0.000000000 then return -1 endi -sql select count(c2),last(c4),stddev(c3),spread(c3) from sliding_tb0 where c2 = 0 interval(30s) sliding(20s) order by ts desc limit 1 offset 15; +sql select count(c2),last(c4),stddev(c3),spread(c3) from sliding_tb0 where c2 = 0 interval(30s) sliding(20s) order by _wstart desc limit 1 offset 15; if $row != 1 then return -1 endi -sql select count(c2),last(c4),stddev(c3),spread(c3) from sliding_tb0 where c2 = 0 interval(30s) sliding(20s) order by ts desc limit 1 offset 16; +sql select count(c2),last(c4),stddev(c3),spread(c3) from sliding_tb0 where c2 = 0 interval(30s) sliding(20s) order by _wstart desc limit 1 offset 16; if $row != 0 then return -1 endi -sql select count(c2), first(c3),stddev(c4) from sliding_tb0 interval(10a) order by ts desc limit 10 offset 2; +sql select _wstart, count(c2), first(c3),stddev(c4) from sliding_tb0 interval(10a) order by _wstart desc limit 10 offset 2; if $data00 != @00-01-01 00:04:59.910@ then return -1 endi -sql select count(*),stddev(c1),count(c1),first(c2),last(c3) from sliding_tb0 where ts>'2000-1-1 00:00:00' and ts<'2000-1-1 00:00:01.002' and c2 >= 0 interval(30s) sliding(10s) order by ts asc limit 1000; +sql select _wstart, count(*),stddev(c1),count(c1),first(c2),last(c3) from sliding_tb0 where ts>'2000-1-1 00:00:00' and ts<'2000-1-1 00:00:01.002' and c2 >= 0 interval(30s) sliding(10s) order by _wstart asc limit 1000; if $row != 3 then return -1 endi - if $data00 != @99-12-31 23:59:40.000@ then return -1 endi - if $data02 != 9.521904571 then return -1 endi - if $data05 != 33 then return -1 endi - if $data10 != @99-12-31 23:59:50.000@ then return -1 endi - if $data12 != 9.521904571 then return -1 endi - if $data15 != 33 then return -1 endi - if $data25 != 33 then return -1 endi -sql select count(*),stddev(c1),count(c1),first(c2),last(c3) from sliding_tb0 where ts>'2000-1-1 00:00:00' and ts<'2000-1-1 00:00:01.002' and c2 >= 0 interval(30s) sliding(10s) order by ts desc limit 1000; +sql select _wstart, count(*),stddev(c1),count(c1),first(c2),last(c3) from sliding_tb0 where ts>'2000-1-1 00:00:00' and ts<'2000-1-1 00:00:01.002' and c2 >= 0 interval(30s) sliding(10s) order by _wstart desc limit 1000; if $row != 3 then return -1 endi - if $data00 != @00-01-01 00:00:00.000@ then print expect 00-01-01 00:00:00.000, actual: $data00 return -1 endi - if $data01 != 33 then return -1 endi - if $data02 != 9.521904571 then return -1 endi - if $data03 != 33 then return -1 endi - if $data10 != @99-12-31 23:59:50.000@ then return -1 endi - if $data11 != 33 then return -1 endi if $data12 != 9.521904571 then return -1 endi - if $data20 != @99-12-31 23:59:40.000@ then return -1 endi diff --git a/tests/script/tsim/stream/basic1.sim b/tests/script/tsim/stream/basic1.sim index a6ee5951a0..d4e575801c 100644 --- a/tests/script/tsim/stream/basic1.sim +++ b/tests/script/tsim/stream/basic1.sim @@ -391,13 +391,13 @@ if $data02 != 4 then return -1 endi -if $data03 != 14 then - print ======$data03 +if $data03 != 50 then + print ======$data03 != 50 return -1 endi -if $data04 != 4 then - print ======$data04 +if $data04 != 20 then + print ======$data04 != 20 return -1 endi @@ -421,13 +421,13 @@ if $data12 != 4 then return -1 endi -if $data13 != 10 then - print ======$data13 +if $data13 != 46 then + print ======$data13 != 46 return -1 endi -if $data14 != 3 then - print ======$data14 +if $data14 != 20 then + print ======$data14 != 20 return -1 endi