diff --git a/README.md b/README.md index 2c33119e34305cbbfa114842e2589ddf87417100..0e1adcd97c61265ec0ad272043c9604736545b3d 100644 --- a/README.md +++ b/README.md @@ -131,10 +131,10 @@ cmake .. -DCPUTYPE=mips64 && cmake --build . ### On Windows platform If you use the Visual Studio 2013, please open a command window by executing "cmd.exe". -Please specify "x86_amd64" for 64 bits Windows or specify "x86" is for 32 bits Windows when you execute vcvarsall.bat. +Please specify "amd64" for 64 bits Windows or specify "x86" is for 32 bits Windows when you execute vcvarsall.bat. ```cmd mkdir debug && cd debug -"C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\vcvarsall.bat" < x86_amd64 | x86 > +"C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\vcvarsall.bat" < amd64 | x86 > cmake .. -G "NMake Makefiles" nmake ``` diff --git a/cmake/define.inc b/cmake/define.inc index cc8bd0fc355847354b23453d2329bda88bfaa2b7..a15e0aecbb2d30ad2ec7aa1c5761c9d2a40f3323 100755 --- a/cmake/define.inc +++ b/cmake/define.inc @@ -122,10 +122,14 @@ IF (TD_LINUX) ADD_DEFINITIONS(-D_TD_NINGSI_60) MESSAGE(STATUS "set ningsi macro to true") ENDIF () - - SET(DEBUG_FLAGS "-O0 -g3 -DDEBUG") + + IF (TD_MEMORY_SANITIZER) + SET(DEBUG_FLAGS "-fsanitize=address -fsanitize=undefined -fno-sanitize-recover=all -fsanitize=float-divide-by-zero -fsanitize=float-cast-overflow -fno-sanitize=null -fno-sanitize=alignment -static-libasan -O0 -g3 -DDEBUG") + ELSE () + SET(DEBUG_FLAGS "-O0 -g3 -DDEBUG") + ENDIF () SET(RELEASE_FLAGS "-O3 -Wno-error") - + IF (${COVER} MATCHES "true") MESSAGE(STATUS "Test coverage mode, add extra flags") SET(GCC_COVERAGE_COMPILE_FLAGS "-fprofile-arcs -ftest-coverage") @@ -144,7 +148,11 @@ IF (TD_DARWIN_64) ADD_DEFINITIONS(-DUSE_LIBICONV) MESSAGE(STATUS "darwin64 is defined") SET(COMMON_FLAGS "-std=gnu99 -Wall -Werror -Wno-missing-braces -fPIC -msse4.2 -D_FILE_OFFSET_BITS=64 -D_LARGE_FILE") - SET(DEBUG_FLAGS "-O0 -g3 -DDEBUG") + IF (TD_MEMORY_SANITIZER) + SET(DEBUG_FLAGS "-fsanitize=address -fsanitize=undefined -fno-sanitize-recover=all -fsanitize=float-divide-by-zero -fsanitize=float-cast-overflow -fno-sanitize=null -fno-sanitize=alignment -O0 -g3 -DDEBUG") + ELSE () + SET(DEBUG_FLAGS "-O0 -g3 -DDEBUG") + ENDIF () SET(RELEASE_FLAGS "-Og") INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/deps/cJson/inc) INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/deps/lz4/inc) @@ -162,7 +170,14 @@ IF (TD_WINDOWS) IF (MSVC AND (MSVC_VERSION GREATER_EQUAL 1900)) SET(COMMON_FLAGS "${COMMON_FLAGS} /Wv:18") ENDIF () - SET(DEBUG_FLAGS "/fsanitize=thread /fsanitize=leak /fsanitize=memory /fsanitize=undefined /fsanitize=hwaddress /Zi /W3 /GL") + + IF (TD_MEMORY_SANITIZER) + MESSAGE("memory sanitizer detected as true") + SET(DEBUG_FLAGS "/fsanitize=address /Zi /W3 /GL") + ELSE () + MESSAGE("memory sanitizer detected as false") + SET(DEBUG_FLAGS "/Zi /W3 /GL") + ENDIF () SET(RELEASE_FLAGS "/W0 /O3 /GL") ENDIF () @@ -171,7 +186,7 @@ IF (TD_WINDOWS) INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/deps/regex) INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/deps/wepoll/inc) INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/deps/MsvcLibX/include) -ENDIF () +ENDIF () IF (TD_WINDOWS_64) ADD_DEFINITIONS(-D_M_X64) diff --git a/cmake/input.inc b/cmake/input.inc index 9b72a35d940ba5e3d79458bbe2455b0db2b59e14..c073bbbc037d105dbacea1e14981537cd31b7202 100755 --- a/cmake/input.inc +++ b/cmake/input.inc @@ -83,3 +83,8 @@ SET(TD_BUILD_JDBC TRUE) IF (${BUILD_JDBC} MATCHES "false") SET(TD_BUILD_JDBC FALSE) ENDIF () + +SET(TD_MEMORY_SANITIZER FALSE) +IF (${MEMORY_SANITIZER} MATCHES "true") + SET(TD_MEMORY_SANITIZER TRUE) +ENDIF () diff --git a/cmake/install.inc b/cmake/install.inc index f8b3b7c3c62c16df537a941d7f14ccb74bc64217..63764348d339d992e8ff3be1036c1c9921fd7b99 100755 --- a/cmake/install.inc +++ b/cmake/install.inc @@ -32,7 +32,7 @@ ELSEIF (TD_WINDOWS) #INSTALL(TARGETS taos RUNTIME DESTINATION driver) #INSTALL(TARGETS shell RUNTIME DESTINATION .) IF (TD_MVN_INSTALLED) - INSTALL(FILES ${LIBRARY_OUTPUT_PATH}/taos-jdbcdriver-2.0.29.jar DESTINATION connector/jdbc) + INSTALL(FILES ${LIBRARY_OUTPUT_PATH}/taos-jdbcdriver-2.0.30.jar DESTINATION connector/jdbc) ENDIF () ELSEIF (TD_DARWIN) SET(TD_MAKE_INSTALL_SH "${TD_COMMUNITY_DIR}/packaging/tools/make_install.sh") diff --git a/documentation20/cn/00.index/docs.md b/documentation20/cn/00.index/docs.md index 50b31a55d392e3d21769006b62ce52681db0d60f..04de20fd6238e5a5840b4791bf8b9ac0fa1470fa 100644 --- a/documentation20/cn/00.index/docs.md +++ b/documentation20/cn/00.index/docs.md @@ -15,6 +15,7 @@ TDengine是一个高效的存储、查询、分析时序大数据的平台,专 * [命令行程序TAOS](/getting-started#console):访问TDengine的简便方式 * [极速体验](/getting-started#demo):运行示例程序,快速体验高效的数据插入、查询 * [支持平台列表](/getting-started#platforms):TDengine服务器和客户端支持的平台列表 +* [Kubenetes部署](https://taosdata.github.io/TDengine-Operator/zh/index.html):TDengine在Kubenetes环境进行部署的详细说明 ## [整体架构](/architecture) diff --git a/documentation20/cn/03.architecture/docs.md b/documentation20/cn/03.architecture/docs.md index 2668967102986952793cd0f000f32ae4cc5e1125..d22855198abc804d6cee5603b56537c9315d610e 100644 --- a/documentation20/cn/03.architecture/docs.md +++ b/documentation20/cn/03.architecture/docs.md @@ -176,7 +176,7 @@ TDengine 分布式架构的逻辑结构图如下: **通讯方式:**TDengine系统的各个数据节点之间,以及应用驱动与各数据节点之间的通讯是通过TCP/UDP进行的。因为考虑到物联网场景,数据写入的包一般不大,因此TDengine 除采用TCP做传输之外,还采用UDP方式,因为UDP 更加高效,而且不受连接数的限制。TDengine实现了自己的超时、重传、确认等机制,以确保UDP的可靠传输。对于数据量不到15K的数据包,采取UDP的方式进行传输,超过15K的,或者是查询类的操作,自动采取TCP的方式进行传输。同时,TDengine根据配置和数据包,会自动对数据进行压缩/解压缩,数字签名/认证等处理。对于数据节点之间的数据复制,只采用TCP方式进行数据传输。 -**FQDN配置**:一个数据节点有一个或多个FQDN,可以在系统配置文件taos.cfg通过参数“fqdn"进行指定,如果没有指定,系统将自动获取计算机的hostname作为其FQDN。如果节点没有配置FQDN,可以直接将该节点的配置参数fqdn设置为它的IP地址。但不建议使用IP,因为IP地址可变,一旦变化,将让集群无法正常工作。一个数据节点的EP(End Point)由FQDN + Port组成。采用FQDN,需要保证DNS服务正常工作,或者在节点以及应用所在的节点配置好hosts文件。 +**FQDN配置**:一个数据节点有一个或多个FQDN,可以在系统配置文件taos.cfg通过参数“fqdn"进行指定,如果没有指定,系统将自动获取计算机的hostname作为其FQDN。如果节点没有配置FQDN,可以直接将该节点的配置参数fqdn设置为它的IP地址。但不建议使用IP,因为IP地址可变,一旦变化,将让集群无法正常工作。一个数据节点的EP(End Point)由FQDN + Port组成。采用FQDN,需要保证DNS服务正常工作,或者在节点以及应用所在的节点配置好hosts文件。另外,这个参数值的长度需要控制在 96 个字符以内。 **端口配置:**一个数据节点对外的端口由TDengine的系统配置参数serverPort决定,对集群内部通讯的端口是serverPort+5。集群内数据节点之间的数据复制操作还占有一个TCP端口,是serverPort+10. 为支持多线程高效的处理UDP数据,每个对内和对外的UDP连接,都需要占用5个连续的端口。因此一个数据节点总的端口范围为serverPort到serverPort + 10,总共11个TCP/UDP端口。(另外还可能有 RESTful、Arbitrator 所使用的端口,那样的话就一共是 13 个。)使用时,需要确保防火墙将这些端口打开,以备使用。每个数据节点可以配置不同的serverPort。(详细的端口情况请参见 [TDengine 2.0 端口说明](https://www.taosdata.com/cn/documentation/faq#port)) diff --git a/documentation20/cn/08.connector/01.java/docs.md b/documentation20/cn/08.connector/01.java/docs.md index 4fc10b542b2e4ad4c9a82bfe0d342e56e1297ba7..e6d214c74d3367d814e0022d4c6a147c4a44b326 100644 --- a/documentation20/cn/08.connector/01.java/docs.md +++ b/documentation20/cn/08.connector/01.java/docs.md @@ -325,10 +325,12 @@ for (int i = 0; i < numOfRows; i++){ } s.setString(2, s2, 10); -// AddBatch 之后,可以再设定新的表名、TAGS、VALUES 取值,这样就能实现一次执行向多个数据表写入: +// AddBatch 之后,缓存并未清空。为避免混乱,并不推荐在 ExecuteBatch 之前再次绑定新一批的数据: s.columnDataAddBatch(); -// 执行语句: +// 执行绑定数据后的语句: s.columnDataExecuteBatch(); +// 执行语句后清空缓存。在清空之后,可以复用当前的对象,绑定新的一批数据(可以是新表名、新 TAGS 值、新 VALUES 值): +s.columnDataClearBatch(); // 执行完毕,释放资源: s.columnDataCloseBatch(); ``` @@ -361,6 +363,7 @@ public void setShort(int columnIndex, ArrayList list) throws SQLException public void setString(int columnIndex, ArrayList list, int size) throws SQLException public void setNString(int columnIndex, ArrayList list, int size) throws SQLException ``` +其中 setString 和 setNString 都要求用户在 size 参数里声明表定义中对应列的列宽。 ### 订阅 diff --git a/documentation20/cn/08.connector/docs.md b/documentation20/cn/08.connector/docs.md index 60f8df95f8c9d9a5510512c081713d32b568bfd8..8c22d50185d1c30459487682800241b48e782d95 100644 --- a/documentation20/cn/08.connector/docs.md +++ b/documentation20/cn/08.connector/docs.md @@ -301,12 +301,14 @@ TDengine的异步API均采用非阻塞调用模式。应用程序可以用多线 2. 调用 `taos_stmt_prepare` 解析 INSERT 语句; 3. 如果 INSERT 语句中预留了表名但没有预留 TAGS,那么调用 `taos_stmt_set_tbname` 来设置表名; 4. 如果 INSERT 语句中既预留了表名又预留了 TAGS(例如 INSERT 语句采取的是自动建表的方式),那么调用 `taos_stmt_set_tbname_tags` 来设置表名和 TAGS 的值; -5. 调用 `taos_stmt_bind_param_batch` 以多列的方式设置 VALUES 的值; +5. 调用 `taos_stmt_bind_param_batch` 以多列的方式设置 VALUES 的值,或者调用 `taos_stmt_bind_param` 以单行的方式设置 VALUES 的值; 6. 调用 `taos_stmt_add_batch` 把当前绑定的参数加入批处理; 7. 可以重复第 3~6 步,为批处理加入更多的数据行; 8. 调用 `taos_stmt_execute` 执行已经准备好的批处理指令; 9. 执行完毕,调用 `taos_stmt_close` 释放所有资源。 +说明:如果 `taos_stmt_execute` 执行成功,假如不需要改变 SQL 语句的话,那么是可以复用 `taos_stmt_prepare` 的解析结果,直接进行第 3~6 步绑定新数据的。但如果执行出错,那么并不建议继续在当前的环境上下文下继续工作,而是建议释放资源,然后从 `taos_stmt_init` 步骤重新开始。 + 除 C/C++ 语言外,TDengine 的 Java 语言 JNI Connector 也提供参数绑定接口支持,具体请另外参见:[参数绑定接口的 Java 用法](https://www.taosdata.com/cn/documentation/connector/java#stmt-java)。 接口相关的具体函数如下(也可以参考 [apitest.c](https://github.com/taosdata/TDengine/blob/develop/tests/examples/c/apitest.c) 文件中使用对应函数的方式): @@ -338,17 +340,17 @@ typedef struct TAOS_BIND { - `int taos_stmt_set_tbname(TAOS_STMT* stmt, const char* name)` - (2.1.1.0 版本新增) + (2.1.1.0 版本新增,仅支持用于替换 INSERT 语句中的参数值) 当 SQL 语句中的表名使用了 `?` 占位时,可以使用此函数绑定一个具体的表名。 - `int taos_stmt_set_tbname_tags(TAOS_STMT* stmt, const char* name, TAOS_BIND* tags)` - (2.1.2.0 版本新增) + (2.1.2.0 版本新增,仅支持用于替换 INSERT 语句中的参数值) 当 SQL 语句中的表名和 TAGS 都使用了 `?` 占位时,可以使用此函数绑定具体的表名和具体的 TAGS 取值。最典型的使用场景是使用了自动建表功能的 INSERT 语句(目前版本不支持指定具体的 TAGS 列)。tags 参数中的列数量需要与 SQL 语句中要求的 TAGS 数量完全一致。 - `int taos_stmt_bind_param_batch(TAOS_STMT* stmt, TAOS_MULTI_BIND* bind)` - (2.1.1.0 版本新增) + (2.1.1.0 版本新增,仅支持用于替换 INSERT 语句中的参数值) 以多列的方式传递待绑定的数据,需要保证这里传递的数据列的顺序、列的数量与 SQL 语句中的 VALUES 参数完全一致。TAOS_MULTI_BIND 的具体定义如下: ```c @@ -378,6 +380,11 @@ typedef struct TAOS_MULTI_BIND { 执行完毕,释放所有资源。 +- `char * taos_stmt_errstr(TAOS_STMT *stmt)` + + (2.1.3.0 版本新增) + 用于在其他 stmt API 返回错误(返回错误码或空指针)时获取错误信息。 + ### 连续查询接口 TDengine提供时间驱动的实时流式计算API。可以每隔一指定的时间段,对一张或多张数据库的表(数据流)进行各种实时聚合计算操作。操作简单,仅有打开、关闭流的API。具体如下: diff --git a/documentation20/cn/11.administrator/docs.md b/documentation20/cn/11.administrator/docs.md index ee2f34ff11ef5e69195c01d0b605383c3257f48c..d0e82a16c8a1faf5568b2b4dd930af5af6646bf4 100644 --- a/documentation20/cn/11.administrator/docs.md +++ b/documentation20/cn/11.administrator/docs.md @@ -99,7 +99,7 @@ taosd -C 下面仅仅列出一些重要的配置参数,更多的参数请看配置文件里的说明。各个参数的详细介绍及作用请看前述章节,而且这些参数的缺省配置都是工作的,一般无需设置。**注意:配置修改后,需要重启*taosd*服务才能生效。** - firstEp: taosd启动时,主动连接的集群中首个dnode的end point, 默认值为localhost:6030。 -- fqdn:数据节点的FQDN,缺省为操作系统配置的第一个hostname。如果习惯IP地址访问,可设置为该节点的IP地址。 +- fqdn:数据节点的FQDN,缺省为操作系统配置的第一个hostname。如果习惯IP地址访问,可设置为该节点的IP地址。这个参数值的长度需要控制在 96 个字符以内。 - serverPort:taosd启动后,对外服务的端口号,默认值为6030。(RESTful服务使用的端口号是在此基础上+11,即默认值为6041。) - dataDir: 数据文件目录,所有的数据文件都将写入该目录。默认值:/var/lib/taos。 - logDir:日志文件目录,客户端和服务器的运行日志文件将写入该目录。默认值:/var/log/taos。 diff --git a/documentation20/cn/12.taos-sql/docs.md b/documentation20/cn/12.taos-sql/docs.md index 6bd007ff215bb378767f92e7669ee595aa754342..acb0ee803c2495859a0ef35129cfd1b08522b891 100644 --- a/documentation20/cn/12.taos-sql/docs.md +++ b/documentation20/cn/12.taos-sql/docs.md @@ -1306,7 +1306,7 @@ SELECT AVG(current), MAX(current), LEASTSQUARES(current, start_val, step_val), P - 数据库名最大长度为 32 - 表名最大长度为 192,每行数据最大长度 16k 个字符(注意:数据行内每个 BINARY/NCHAR 类型的列还会额外占用 2 个字节的存储位置) - 列名最大长度为 64,最多允许 1024 列,最少需要 2 列,第一列必须是时间戳 -- 标签最多允许 128 个,可以 1 个,标签总长度不超过 16k 个字符 +- 标签名最大长度为 64,最多允许 128 个,可以 1 个,一个表中标签值的总长度不超过 16k 个字符 - SQL 语句最大长度 65480 个字符,但可通过系统配置参数 maxSQLLength 修改,最长可配置为 1M - SELECT 语句的查询结果,最多允许返回 1024 列(语句中的函数调用可能也会占用一些列空间),超限时需要显式指定较少的返回数据列,以避免语句执行报错。 - 库的数目,超级表的数目、表的数目,系统不做限制,仅受系统资源限制 diff --git a/documentation20/en/00.index/docs.md b/documentation20/en/00.index/docs.md new file mode 100644 index 0000000000000000000000000000000000000000..381f914e4a2e56e85908712a01d57ad2821de9f6 --- /dev/null +++ b/documentation20/en/00.index/docs.md @@ -0,0 +1,141 @@ +# TDengine Documentation + +TDengine is a highly efficient platform to store, query, and analyze time-series data. It is specially designed and optimized for IoT, Internet of Vehicles, Industrial IoT, IT Infrastructure and Application Monitoring, etc. It works like a relational database, such as MySQL, but you are strongly encouraged to read through the following documentation before you experience it, especially the Data Model and Data Modeling sections. In addition to this document, you should also download and read our technology white paper. For the older TDengine version 1.6 documentation, please click here. + +## [TDengine Introduction](/evaluation) + +* [TDengine Introduction and Features](/evaluation#intro) +* [TDengine Use Scenes](/evaluation#scenes) +* [TDengine Performance Metrics and Verification]((/evaluation#)) + +## [Getting Started](/getting-started) + +* [Quickly Install](/getting-started#install): install via source code/package / Docker within seconds + +- [Easy to Launch](/getting-started#start): start / stop TDengine with systemctl +- [Command-line](/getting-started#console) : an easy way to access TDengine server +- [Experience Lightning Speed](/getting-started#demo): running a demo, inserting/querying data to experience faster speed +- [List of Supported Platforms](/getting-started#platforms): a list of platforms supported by TDengine server and client + +## [Overall Architecture](/architecture) + +- [Data Model](/architecture#model): relational database model, but one table for one device with static tags +- [Cluster and Primary Logical Unit](/architecture#cluster): Take advantage of NoSQL, support scale-out and high-reliability +- [Storage Model and Data Partitioning/Sharding](/architecture#sharding): tag data will be separated from time-series data, segmented by vnode and time +- [Data Writing and Replication Process](/architecture#replication): records received are written to WAL, cached, with acknowledgement is sent back to client, while supporting multi-replicas +- [Caching and Persistence](/architecture#persistence): latest records are cached in memory, but are written in columnar format with an ultra-high compression ratio +- [Data Query](/architecture#query): support various functions, time-axis aggregation, interpolation, and multi-table aggregation + +## [Data Modeling](/model) + +- [Create a Library](/model#create-db): create a library for all data collection points with similar features +- [Create a Super Table(STable)](/model#create-stable): create a STable for all data collection points with the same type +- [Create a Table](/model#create-table): use STable as the template, to create a table for each data collecting point + +## [TAOS SQL](/taos-sql) + +- [Data Types](/taos-sql#data-type): support timestamp, int, float, nchar, bool, and other types +- [Database Management](/taos-sql#management): add, drop, check databases +- [Table Management](/taos-sql#table): add, drop, check, alter tables +- [STable Management](/taos-sql#super-table): add, drop, check, alter STables +- [Tag Management](/taos-sql#tags): add, drop, alter tags +- [Inserting Records](/taos-sql#insert): support to write single/multiple items per table, multiple items across tables, and support to write historical data +- [Data Query](/taos-sql#select): support time segment, value filtering, sorting, manual paging of query results, etc +- [SQL Function](/taos-sql#functions): support various aggregation functions, selection functions, and calculation functions, such as avg, min, diff, etc +- [Time Dimensions Aggregation](/taos-sql#aggregation): aggregate and reduce the dimension after cutting table data by time segment +- [Boundary Restrictions](/taos-sql#limitation): restrictions for the library, table, SQL, and others +- [Error Code](/taos-sql/error-code): TDengine 2.0 error codes and corresponding decimal codes + +## [Efficient Data Ingestion](/insert) + +- [SQL Ingestion](/insert#sql): write one or multiple records into one or multiple tables via SQL insert command +- [Prometheus Ingestion](/insert#prometheus): Configure Prometheus to write data directly without any code +- [Telegraf Ingestion](/insert#telegraf): Configure Telegraf to write collected data directly without any code +- [EMQ X Broker](/insert#emq): Configure EMQ X to write MQTT data directly without any code +- [HiveMQ Broker](/insert#hivemq): Configure HiveMQ to write MQTT data directly without any code + +## [Efficient Data Querying](/queries) + +- [Main Query Features](/queries#queries): support various standard functions, setting filter conditions, and querying per time segment +- [Multi-table Aggregation Query](/queries#aggregation): use STable and set tag filter conditions to perform efficient aggregation queries +- [Downsampling to Query Value](/queries#sampling): aggregate data in successive time windows, support interpolation + +## [Advanced Features](/advanced-features) + +- [Continuous Query](/advanced-features#continuous-query): Based on sliding windows, the data stream is automatically queried and calculated at regular intervals +- [Data Publisher/Subscriber](/advanced-features#subscribe): subscribe to the newly arrived data like a typical messaging system +- [Cache](/advanced-features#cache): the newly arrived data of each device/table will always be cached +- [Alarm Monitoring](/advanced-features#alert): automatically monitor out-of-threshold data, and actively push it based-on configuration rules + +## [Connector](/connector) + +- [C/C++ Connector](/connector#c-cpp): primary method to connect to TDengine server through libtaos client library +- [Java Connector(JDBC)](/connector/java): driver for connecting to the server from Java applications using the JDBC API +- [Python Connector](/connector#python): driver for connecting to TDengine server from Python applications +- [RESTful Connector](/connector#restful): a simple way to interact with TDengine via HTTP +- [Go Connector](/connector#go): driver for connecting to TDengine server from Go applications +- [Node.js Connector](/connector#nodejs): driver for connecting to TDengine server from Node.js applications +- [C# Connector](/connector#csharp): driver for connecting to TDengine server from C# applications +- [Windows Client](https://www.taosdata.com/blog/2019/07/26/514.html): compile your own Windows client, which is required by various connectors on the Windows environment + +## [Connections with Other Tools](/connections) + +- [Grafana](/connections#grafana): query the data saved in TDengine and provide visualization +- [Matlab](/connections#matlab): access data stored in TDengine server via JDBC configured within Matlab +- [R](/connections#r): access data stored in TDengine server via JDBC configured within R +- [IDEA Database](https://www.taosdata.com/blog/2020/08/27/1767.html): use TDengine visually through IDEA Database Management Tool + +## [Installation and Management of TDengine Cluster](/cluster) + +- [Preparation](/cluster#prepare): important considerations before deploying TDengine for production usage +- [Create Your First Node](/cluster#node-one): simple to follow the quick setup +- [Create Subsequent Nodes](/cluster#node-other): configure taos.cfg for new nodes to add more to the existing cluster +- [Node Management](/cluster#management): add, delete, and check nodes in the cluster +- [High-availability of Vnode](/cluster#high-availability): implement high-availability of Vnode through multi-replicas +- [Mnode Management](/cluster#mnode): automatic system creation without any manual intervention +- [Load Balancing](/cluster#load-balancing): automatically performed once the number of nodes or load changes +- [Offline Node Processing](/cluster#offline): any node that offline for more than a certain period will be removed from the cluster +- [Arbitrator](/cluster#arbitrator): used in the case of an even number of replicas to prevent split-brain + +## [TDengine Operation and Maintenance](/administrator) + +- [Capacity Planning](/administrator#planning): Estimating hardware resources based on scenarios +- [Fault Tolerance and Disaster Recovery](/administrator#tolerance): set the correct WAL and number of data replicas +- [System Configuration](/administrator#config): port, cache size, file block size, and other system configurations +- [User Management](/administrator#user): add/delete TDengine users, modify user password +- [Import Data](/administrator#import): import data into TDengine from either script or CSV file +- [Export Data](/administrator#export): export data either from TDengine shell or from the taosdump tool +- [System Monitor](/administrator#status): monitor the system connections, queries, streaming calculation, logs, and events +- [File Directory Structure](/administrator#directories): directories where TDengine data files and configuration files located +- [Parameter Restrictions and Reserved Keywords](/administrator#keywords): TDengine’s list of parameter restrictions and reserved keywords + +## TDengine Technical Design + +- [System Module](/architecture/taosd): taosd functions and modules partitioning +- [Data Replication](/architecture/replica): support real-time synchronous/asynchronous replication, to ensure high-availability of the system +- [Technical Blog](https://www.taosdata.com/cn/blog/?categories=3): More technical analysis and architecture design articles + +## Common Tools + +- [TDengine sample import tools](https://www.taosdata.com/blog/2020/01/18/1166.html) +- [TDengine performance comparison test tools](https://www.taosdata.com/blog/2020/01/18/1166.html) +- [Use TDengine visually through IDEA Database Management Tool](https://www.taosdata.com/blog/2020/08/27/1767.html) + +## [Performance: TDengine vs Others + +- [Performance: TDengine vs InfluxDB with InfluxDB’s open-source performance testing tool](https://www.taosdata.com/blog/2020/01/13/1105.html) +- [Performance: TDengine vs OpenTSDB](https://www.taosdata.com/blog/2019/08/21/621.html) +- [Performance: TDengine vs Cassandra](https://www.taosdata.com/blog/2019/08/14/573.html) +- [Performance: TDengine vs InfluxDB](https://www.taosdata.com/blog/2019/07/19/419.html) +- [Performance Test Reports of TDengine vs InfluxDB/OpenTSDB/Cassandra/MySQL/ClickHouse](https://www.taosdata.com/downloads/TDengine_Testing_Report_cn.pdf) + +## More on IoT Big Data + +- [Characteristics of IoT and Industry Internet Big Data](https://www.taosdata.com/blog/2019/07/09/characteristics-of-iot-big-data/) +- [Features and Functions of IoT Big Data platforms](https://www.taosdata.com/blog/2019/07/29/542.html) +- [Why don’t General Big Data Platforms Fit IoT Scenarios?](https://www.taosdata.com/blog/2019/07/09/why-does-the-general-big-data-platform-not-fit-iot-data-processing/) +- [Why TDengine is the best choice for IoT, Internet of Vehicles, and Industry Internet Big Data platforms?](https://www.taosdata.com/blog/2019/07/09/why-tdengine-is-the-best-choice-for-iot-big-data-processing/) + +## FAQ + +- [FAQ: Common questions and answers](/faq) \ No newline at end of file diff --git a/documentation20/en/01.evaluation/docs.md b/documentation20/en/01.evaluation/docs.md new file mode 100644 index 0000000000000000000000000000000000000000..2b9ed68015b209846a3e5ccaf5c1781c83e8540c --- /dev/null +++ b/documentation20/en/01.evaluation/docs.md @@ -0,0 +1,68 @@ +# TDengine Introduction + +## About TDengine + +TDengine is an innovative Big Data processing product launched by Taos Data in the face of the fast-growing Internet of Things (IoT) Big Data market and technical challenges. It does not rely on any third-party software, nor does it optimize or package any open-source database or stream computing product. Instead, it is a product independently developed after absorbing the advantages of many traditional relational databases, NoSQL databases, stream computing engines, message queues, and other software. TDengine has its own unique Big Data processing advantages in time-series space. + +One of the modules of TDengine is the time-series database. However, in addition to this, to reduce the complexity of research and development and the difficulty of system operation, TDengine also provides functions such as caching, message queuing, subscription, stream computing, etc. TDengine provides a full-stack technical solution for the processing of IoT and Industrial Internet BigData. It is an efficient and easy-to-use IoT Big Data platform. Compared with typical Big Data platforms such as Hadoop, TDengine has the following distinct characteristics: + +- **Performance improvement over 10 times**: An innovative data storage structure is defined, with each single core can process at least 20,000 requests per second, insert millions of data points, and read more than 10 million data points, which is more than 10 times faster than other existing general database. +- **Reduce the cost of hardware or cloud services to 1/5**: Due to its ultra-performance, TDengine’s computing resources consumption is less than 1/5 of other common Big Data solutions; through columnar storage and advanced compression algorithms, the storage consumption is less than 1/10 of other general databases. +- **Full-stack time-series data processing engine**: Integrate database, message queue, cache, stream computing, and other functions, and the applications do not need to integrate with software such as Kafka/Redis/HBase/Spark/HDFS, thus greatly reducing the complexity cost of application development and maintenance. +- **Powerful analysis functions**: Data from ten years ago or one second ago, can all be queried based on a specified time range. Data can be aggregated on a timeline or multiple devices. Ad-hoc queries can be made at any time through Shell, Python, R, and Matlab. +- **Seamless connection with third-party tools**: Integration with Telegraf, Grafana, EMQ, HiveMQ, Prometheus, Matlab, R, etc. without even one single line of code. OPC, Hadoop, Spark, etc. will be supported in the future, and more BI tools will be seamlessly connected to. +- **Zero operation cost & zero learning cost**: Installing clusters is simple and quick, with real-time backup built-in, and no need to split libraries or tables. Similar to standard SQL, TDengine can support RESTful, Python/Java/C/C + +/C#/Go/Node.js, and similar to MySQL with zero learning cost. + +With TDengine, the total cost of ownership of typical IoT, Internet of Vehicles, and Industrial Internet Big Data platforms can be greatly reduced. However, it should be pointed out that due to making full use of the characteristics of IoT time-series data, TDengine cannot be used to process general data from web crawlers, microblogs, WeChat, e-commerce, ERP, CRM, and other sources. + +![TDengine Technology Ecosystem](page://images/eco_system.png) + +
Figure 1. TDengine Technology Ecosystem
+ +## Overall Scenarios of TDengine + +As an IoT Big Data platform, the typical application scenarios of TDengine are mainly presented in the IoT category, with users having a certain amount of data. The following sections of this document are mainly aimed at IoT-relevant systems. Other systems, such as CRM, ERP, etc., are beyond the scope of this article. + +### Characteristics and Requirements of Data Sources + +From the perspective of data sources, designers can analyze the applicability of TDengine in target application systems as following. + +| **Data Source Characteristics and Requirements** | **Not Applicable** | **Might Be Applicable** | **Very Applicable** | **Description** | +| -------------------------------------------------------- | ------------------ | ----------------------- | ------------------- | :----------------------------------------------------------- | +| A huge amount of total data | | | √ | TDengine provides excellent scale-out functions in terms of capacity, and has a storage structure matching high compression ratio to achieve the best storage efficiency in the industry. | +| Data input velocity is occasionally or continuously huge | | | √ | TDengine's performance is much higher than other similar products. It can continuously process a large amount of input data in the same hardware environment, and provide a performance evaluation tool that can easily run in the user environment. | +| A huge amount of data sources | | | √ | TDengine is designed to include optimizations specifically for a huge amount of data sources, such as data writing and querying, which is especially suitable for efficiently processing massive (tens of millions or more) data sources. | + +### System Architecture Requirements + +| **System Architecture Requirements** | **Not Applicable** | **Might Be Applicable** | **Very Applicable** | **Description** | +| ------------------------------------------------- | ------------------ | ----------------------- | ------------------- | ------------------------------------------------------------ | +| Require a simple and reliable system architecture | | | √ | TDengine's system architecture is very simple and reliable, with its own message queue, cache, stream computing, monitoring and other functions, and no need to integrate any additional third-party products. | +| Require fault-tolerance and high-reliability | | | √ | TDengine has cluster functions to automatically provide high-reliability functions such as fault tolerance and disaster recovery. | +| Standardization specifications | | | √ | TDengine uses standard SQL language to provide main functions and follow standardization specifications. | + +### System Function Requirements + +| | | | | | +| ----------------------------------------------------- | ------------------ | -------------------- | ------------------- | ------------------------------------------------------------ | +| **System Function Requirements** | **Not Applicable** | **Might Applicable** | **Very Applicable** | **Description** | +| Require completed data processing algorithms built-in | | √ | | TDengine implements various general data processing algorithms, but has not properly handled all requirements of different industries, so special types of processing shall be processed at the application level. | +| Require a huge amount of crosstab queries | | √ | | This type of processing should be handled more by relational database systems, or TDengine and relational database systems should fit together to implement system functions. | + +### System Performance Requirements + +| | | | | | +| -------------------------------------------- | ------------------ | -------------------- | ------------------- | ------------------------------------------------------------ | +| **System Performance Requirements** | **Not Applicable** | **Might Applicable** | **Very Applicable** | **Description** | +| Require larger total processing capacity | | | √ | TDengine’s cluster functions can easily improve processing capacity via multi-server-cooperating. | +| Require high-speed data processing | | | √ | TDengine’s storage and data processing are designed to be optimized for IoT, can generally improve the processing speed by multiple times than other similar products. | +| Require fast processing of fine-grained data | | | √ | TDengine has achieved the same level of performance with relational and NoSQL data processing systems. | + +### System Maintenance Requirements + +| | | | | | +| -------------------------------------------- | ------------------ | -------------------- | ------------------- | ------------------------------------------------------------ | +| **System Maintenance Requirements** | **Not Applicable** | **Might Applicable** | **Very Applicable** | **Description** | +| Require system with high-reliability | | | √ | TDengine has a very robust and reliable system architecture to implement simple and convenient daily operation with streamlined experiences for operators, thus human errors and accidents are eliminated to the greatest extent. | +| Require controllable operation learning cost | | | √ | As above. | +| Require abundant talent supply | √ | | | As a new-generation product, it’s still difficult to find talents with TDengine experiences from market. However, the learning cost is low. As the vendor, we also provide extensive operation training and counselling services. | \ No newline at end of file diff --git a/documentation20/en/02.getting-started/docs.md b/documentation20/en/02.getting-started/docs.md new file mode 100644 index 0000000000000000000000000000000000000000..6d6bda114eecd303dd46ce21ca72768fe0bc5916 --- /dev/null +++ b/documentation20/en/02.getting-started/docs.md @@ -0,0 +1,277 @@ +# Quick Start + +## Quick Install + +TDegnine software consists of 3 parts: server, client, and alarm module. At the moment, TDengine server only runs on Linux (Windows, mac OS and more OS supports will come soon), but client can run on either Windows or Linux. TDengine client can be installed and run on Windows or Linux. Applications based-on any OSes can all connect to server taosd via a RESTful interface. About CPU, TDegnine supports X64/ARM64/MIPS64/Alpha64, and ARM32、RISC-V, other more CPU architectures will be supported soon. You can set up and install TDengine server either from the [source code](https://www.taosdata.com/en/getting-started/#Install-from-Source) or the [packages](https://www.taosdata.com/en/getting-started/#Install-from-Package). + +### Install from Source + +Please visit our [TDengine github page](https://github.com/taosdata/TDengine) for instructions on installation from the source code. + +### Install from Docker Container + +Please visit our [TDengine Official Docker Image: Distribution, Downloading, and Usage](https://www.taosdata.com/blog/2020/05/13/1509.html). + +### Install from Package + +It’s extremely easy to install for TDegnine, which takes only a few seconds from downloaded to successful installed. The server installation package includes clients and connectors. We provide 3 installation packages, which you can choose according to actual needs: + +Click [here](https://www.taosdata.com/cn/getting-started/#%E9%80%9A%E8%BF%87%E5%AE%89%E8%A3%85%E5%8C%85%E5%AE%89%E8%A3%85) to download the install package. + +For more about installation process, please refer [TDengine Installation Packages: Install and Uninstall](https://www.taosdata.com/blog/2019/08/09/566.html), and [Video Tutorials](https://www.taosdata.com/blog/2020/11/11/1941.html). + +## Quick Launch + +After installation, you can start the TDengine service by the `systemctl` command. + +```bash +``` + +$ systemctl start taosd + +``` +``` + +Then check if the service is working now. + +```bash +``` + +$ systemctl status taosd + +``` +``` + +If the service is running successfully, you can play around through TDengine shell `taos`. + +**Note:** + +- The `systemctl` command needs the **root** privilege. Use **sudo** if you are not the **root** user. +- To get better product feedback and improve our solution, TDegnine will collect basic usage information, but you can modify the configuration parameter **telemetryReporting** in the system configuration file taos.cfg, and set it to 0 to turn it off. +- TDegnine uses FQDN (usually hostname) as the node ID. In order to ensure normal operation, you need to set hostname for the server running taosd, and configure DNS service or hosts file for the machine running client application, to ensure the FQDN can be resolved. +- TDengine supports installation on Linux systems with[ systemd ](https://en.wikipedia.org/wiki/Systemd)as the process service management, and uses `which systemctl` command to detect whether `systemd` packages exist in the system: +- ```bash + ``` + +- $ which systemctl + +- ``` + +If `systemd` is not supported in the system, TDengine service can also be launched via `/usr/local/taos/bin/taosd` manually. + +## TDengine Shell Command Line + +To launch TDengine shell, the command line interface, in a Linux terminal, type: + +```bash +``` + +$ taos + +``` +``` + +The welcome message is printed if the shell connects to TDengine server successfully, otherwise, an error message will be printed (refer to our [FAQ](https://www.taosdata.com/en/faq) page for troubleshooting the connection error). The TDengine shell prompt is: + +```cmd +``` + +taos> + +``` +``` + +In the TDengine shell, you can create databases, create tables and insert/query data with SQL. Each query command ends with a semicolon. It works like MySQL, for example: + +```mysql +``` + +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 | + +=================================== + +19-07-15 00:00:00.000| 10| + +19-07-15 01:00:00.000| 20| + +Query OK, 2 row(s) in set (0.001700s) + +``` +``` + +Besides the SQL commands, the system administrator can check system status, add or delete accounts, and manage the servers. + +### Shell Command Line Parameters + +You can configure command parameters to change how TDengine shell executes. Some frequently used options are listed below: + +- -c, --config-dir: set the configuration directory. It is */etc/taos* by default. +- -h, --host: set the IP address of the server it will connect to. Default is localhost. +- -s, --commands: set the command to run without entering the shell. +- -u, -- user: user name to connect to server. Default is root. +- -p, --password: password. Default is 'taosdata'. +- -?, --help: get a full list of supported options. + +Examples: + +```bash +``` + +$ taos -h 192.168.0.1 -s "use db; show tables;" + +``` +``` + +### Run SQL Command Scripts + +Inside TDengine shell, you can run SQL scripts in a file with source command. + +```mysql +``` + +taos> source ; + +``` +``` + +### Shell Tips + +- Use up/down arrow key to check the command history +- To change the default password, use "alter user" command +- Use ctrl+c to interrupt any queries +- To clean the schema of local cached tables, execute command `RESET QUERY CACHE` + +## Experience TDengine’s Lightning Speed + +After starting the TDengine server, you can execute the command `taosdemo` in the Linux terminal. + +```bash +``` + +$ taosdemo + +``` +``` + +Using this command, a STable named `meters` will be created in the database `test` There are 10k tables under this stable, named from `t0` to `t9999`. In each table there are 100k rows of records, each row with columns (`f1`, `f2` and `f3`. The timestamp is from "2017-07-14 10:40:00 000" to "2017-07-14 10:41:39 999". Each table also has tags `areaid` and `loc`: `areaid` is set from 1 to 10, `loc` is set to "beijing" or "shanghai". + +It takes about 10 minutes to execute this command. Once finished, 1 billion rows of records will be inserted. + +In the TDengine client, enter sql query commands and then experience our lightning query speed. + +- query total rows of records: + +```mysql +``` + +taos> select count(*) from test.meters; + +``` +``` + +- query average, max and min of the total 1 billion records: + +```mysql +``` + +taos> select avg(f1), max(f2), min(f3) from test.meters; + +``` +``` + +- query the number of records where loc="beijing": + +```mysql +``` + +taos> select count(*) from test.meters where loc="beijing"; + +``` +``` + +- query the average, max and min of total records where areaid=10: + +```mysql +``` + +taos> select avg(f1), max(f2), min(f3) from test.meters where areaid=10; + +``` +``` + +- query the average, max, min from table t10 when aggregating over every 10s: + +```mysql +``` + +taos> select avg(f1), max(f2), min(f3) from test.t10 interval(10s); + +``` +``` + +**Note**: you can run command `taosdemo` with many options, like number of tables, rows of records and so on. To know more about these options, you can execute `taosdemo --help` and then take a try using different options. + +## Client and Alarm Module + +If your client and server running on different machines, please install the client separately. Linux and Windows packages are provided: + +- TDengine-client-2.0.10.0-Linux-x64.tar.gz(3.0M) +- TDengine-client-2.0.10.0-Windows-x64.exe(2.8M) +- TDengine-client-2.0.10.0-Windows-x86.exe(2.8M) + +Linux package of Alarm Module is as following (please refer [How to Use Alarm Module](https://github.com/taosdata/TDengine/blob/master/alert/README_cn.md)): + +- TDengine-alert-2.0.10.0-Linux-x64.tar.gz (8.1M) + +## List of Supported Platforms + +List of platforms supported by TDengine server + +| | **CentOS 6/7/8** | **Ubuntu 16/18/20** | **Other Linux** | UnionTech UOS | NeoKylin | LINX V60/V80 | +| ------------------ | ---------------- | ------------------- | --------------- | ------------- | -------- | ------------ | +| X64 | ● | ● | | ○ | ● | ● | +| Raspberry ARM32 | | ● | ● | | | | +| Loongson MIPS64 | | | ● | | | | +| Kunpeng ARM64 | | ○ | ○ | | ● | | +| SWCPU Alpha64 | | | ○ | ● | | | +| FT ARM64 | | ○Ubuntu Kylin | | | | | +| Hygon X64 | ● | ● | ● | ○ | ● | ● | +| Rockchip ARM64/32 | | | ○ | | | | +| Allwinner ARM64/32 | | | ○ | | | | +| Actions ARM64/32 | | | ○ | | | | +| TI ARM32 | | | ○ | | | | + +Note: ● has been verified by official tests; ○ has been verified by unofficial tests. + +List of platforms supported by TDengine client and connectors + +At the moment, TDengine connectors can support a wide range of platforms, including hardware platforms such as X64/X86/ARM64/ARM32/MIPS/Alpha, and development environments such as Linux/Win64/Win32. + +Comparison matrix as following: + +| **CPU** | **X64 64bit** | | | **X86 32bit** | **ARM64** | **ARM32** | **MIPS Godson** | **Alpha Shenwei** | **X64 TimecomTech** | +| ----------- | ------------- | --------- | --------- | ------------- | --------- | --------- | --------------- | ----------------- | ------------------- | +| **OS** | **Linux** | **Win64** | **Win32** | **Win32** | **Linux** | **Linux** | **Linux** | **Linux** | **Linux** | +| **C/C++** | ● | ● | ● | ○ | ● | ● | ● | ● | ● | +| **JDBC** | ● | ● | ● | ○ | ● | ● | ● | ● | ● | +| **Python** | ● | ● | ● | ○ | ● | ● | ● | -- | ● | +| **Go** | ● | ● | ● | ○ | ● | ● | ○ | -- | -- | +| **NodeJs** | ● | ● | ○ | ○ | ● | ● | ○ | -- | -- | +| **C#** | ○ | ● | ● | ○ | ○ | ○ | ○ | -- | -- | +| **RESTful** | ● | ● | ● | ● | ● | ● | ● | ● | ● | + +Note: ● has been verified by official tests; ○ has been verified by unofficial tests. + +Please visit [Connectors](https://www.taosdata.com/cn/documentation/connector) section for more detailed information. \ No newline at end of file diff --git a/documentation20/en/04.model/docs.md b/documentation20/en/04.model/docs.md new file mode 100644 index 0000000000000000000000000000000000000000..5875c66a213619bf028dd9c41894cfdeeda35c74 --- /dev/null +++ b/documentation20/en/04.model/docs.md @@ -0,0 +1,370 @@ +# Data Model and Architecture + +## ## Data Model + +### ### A Typical IoT Scenario + +In typical IoT, Internet of Vehicles and Operation Monitoring scenarios, there are often many different types of data collecting devices that collect one or more different physical metrics. However, for the collection devices of the same type, there are often many specific collection devices distributed in places. BigData processing system aims to collect all kinds of data, and then calculate and analyze them. For the same kind of devices, the data collected are very regular. Taking smart meters as an example, assuming that each smart meter collects three metrics of current, voltage and phase, the collected data are similar to the following table: + +| | | | | | | | +| ------------- | -------------- | ----------- | ----------- | --------- | ---------------- | ----------- | +| **Device ID** | **Time Stamp** | **current** | **voltage** | **phase** | **location** | **groupId** | +| d1001 | 1538548685000 | 10.3 | 219 | 0.31 | Beijing.Chaoyang | 2 | +| d1002 | 1538548684000 | 10.2 | 220 | 0.23 | Beijing.Chaoyang | 3 | +| d1003 | 1538548686500 | 11.5 | 221 | 0.35 | Beijing.Haidian | 3 | +| d1004 | 1538548685500 | 13.4 | 223 | 0.29 | Beijing.Haidian | 2 | +| d1001 | 1538548695000 | 12.6 | 218 | 0.33 | Beijing.Chaoyang | 2 | +| d1004 | 1538548696600 | 11.8 | 221 | 0.28 | Beijing.Haidian | 2 | +| d1002 | 1538548696650 | 10.3 | 218 | 0.25 | Beijing.Chaoyang | 3 | +| d1001 | 1538548696800 | 12.3 | 221 | 0.31 | Beijing.Chaoyang | 2 | + + + +| **Device ID** | **Time Stamp** | **Collected Metrics** | **Tags** | | | | +| ------------- | -------------- | --------------------- | ----------- | --------- | ---------------- | ----------- | +| **Device ID** | **Time Stamp** | **current** | **voltage** | **phase** | **location** | **groupId** | +| d1001 | 1538548685000 | 10.3 | 219 | 0.31 | Beijing.Chaoyang | 2 | +| d1002 | 1538548684000 | 10.2 | 220 | 0.23 | Beijing.Chaoyang | 3 | +| d1003 | 1538548686500 | 11.5 | 221 | 0.35 | Beijing.Haidian | 3 | +| d1004 | 1538548685500 | 13.4 | 223 | 0.29 | Beijing.Haidian | 2 | +| d1001 | 1538548695000 | 12.6 | 218 | 0.33 | Beijing.Chaoyang | 2 | +| d1004 | 1538548696600 | 11.8 | 221 | 0.28 | Beijing.Haidian | 2 | +| d1002 | 1538548696650 | 10.3 | 218 | 0.25 | Beijing.Chaoyang | 3 | +| d1001 | 1538548696800 | 12.3 | 221 | 0.31 | Beijing.Chaoyang | 2 | + +Table 1: Smart meter example data + +Each data record contains the device ID, timestamp, collected metrics (current, voltage, phase as above), and static tags (Location and groupId in Table 1) associated with the devices. Each device generates a data record in a pre-defined timer or triggered by an external event. It is a sequence of data points like a stream. + +### Data Characteristics + +As the data points are a series of data points over time, the data points generated by IoT, Internet of Vehicles, and Operation Monitoring have some strong common characteristics: + +1. Metrics are always structured data; +2. There are rarely delete/update operations on collected data; +3. No need for transactions of traditional databases +4. The ratio of reading is lower but write is higher than typical Internet applications; +5. data flow is uniform and can be predicted according to the number of devices and collection frequency; +6. the user pays attention to the trend of data, not a specific value at a specific time; +7. there is always a data retention policy; +8. the data query is always executed in a given time range and a subset of space; +9. in addition to storage and query operations, various statistical and real-time calculation operations are also required; +10. data volume is huge, a system may generate over 10 billion data points in a day. + +By utilizing the above characteristics, TDengine designs the storage and computing engine in a special and optimized way for time-series data, resulting in massive improvements in system efficiency. + +### Relational Database Model + +Since time-series data is most likely to be structured data, TDengine adopts the traditional relational database model to process them with a shallow learning curve. You need to create a database, create tables with schema definitions, then insert data points and execute queries to explore the data. Standard SQL is used, instead of NoSQL’s key-value storage. + +### One Table for One Collection Point + +To utilize this time-series and other data features, TDengine requires the user to create a table for each collection point to store collected time-series data. For example, if there are over 10 millions smart meters, means 10 millions tables shall be created. For the table above, 4 tables shall be created for devices D1001, D1002, D1003, and D1004 to store the data collected. This design has several advantages: + +1. Guarantee that all data from a collection point can be saved in a continuous memory/hard disk space block by block. If queries are applied only on one point in a time range, this design will reduce the random read latency significantly, thus increase read and query speed by orders of magnitude. +2. Since the data generation process of each collection device is completely independent, means each device has its unique data source, thus writes can be carried out in a lock-free manner to greatly improve the speed. +3. Write latency can be significantly reduced too as the data points generated by the same device will arrive in time order, the new data point will be simply appended to a block. + +If the data of multiple devices are written into a table in the traditional way, due to the uncontrollable network delay, the timing of the data from different devices arriving at the server cannot be guaranteed, the writing operation must be protected by locks, and the data of one device cannot be guaranteed to continuously stored together. **The method of one table for each data collection point can ensure the optimal performance of insertion and query of a single data collection point to the greatest extent.** + +TDengine suggests using collection point ID as the table name (like D1001 in the above table). Each point may collect one or more metrics (like the current, voltage, phase as above). Each metric has a column in the table. The data type for a column can be int, float, string and others. In addition, the first column in the table must be a timestamp. TDengine uses the time stamp as the index, and won’t build the index on any metrics stored. All data will be stored in columns. + +### STable: A Collection of Data Points in the Same Type + +The method of one table for each point will bring a greatly increasing number of tables, which is difficult to manage. Moreover, applications often need to take aggregation operations between collection points, thus aggregation operations will become complicated. To support aggregation over multiple tables efficiently, the [STable(Super Table)](https://www.taosdata.com/en/documentation/super-table) concept is introduced by TDengine. + +STable is an abstract collection for a type of data point. A STable contains a set of points (tables) that have the same schema or data structure, but with different static attributes (tags). To describe a STable (a combination of data collection points of a specific type), in addition to defining the table structure of the collected metrics, it is also necessary to define the schema of its tag. The data type of tags can be int, float, string, and there can be multiple tags, which can be added, deleted, or modified afterward. If the whole system has N different types of data collection points, N STables need to be established. + +In the design of TDengine, **a table is used to represent a specific data collection point, and STable is used to represent a set of data collection points of the same type**. When creating a table for a specific data collection point, the user uses the definition of STable as a template and specifies the tag value of the specific collection point (table). Compared with the traditional relational database, the table (a data collection point) has static tags, and these tags can be added, deleted, and modified afterward. **A STable contains multiple tables with the same time-series data schema but different tag values.** + +When aggregating multiple data collection points with the same data type, TDEngine will first find out the tables that meet the tag filters from the STables, and then scan the time-series data of these tables to perform aggregation operation, which can greatly reduce the data sets to be scanned, thus greatly improving the performance of aggregation calculation. + +## Cluster and Primary Logic Unit + +The design of TDengine is based on the assumption that one single hardware or software system is unreliable and that no single computer can provide sufficient computing and storage resources to process massive data. Therefore, TDengine has been designed according to a distributed and high-reliability architecture since Day One of R&D, which supports scale-out, so that hardware failure or software failure of any single or multiple servers will not affect the availability and reliability of the system. At the same time, through node virtualization and automatic load-balancing technology, TDengine can make the most efficient use of computing and storage resources in heterogeneous clusters to reduce hardware investment. + +### Primary Logic Unit + +Logical structure diagram of TDengine distributed architecture as following: + +Figure 1: TDengine architecture diagram + +A complete TDengine system runs on one or more physical nodes. Logically, it includes data node (dnode), TDEngine application driver (taosc) and application (app). There are one or more data nodes in the system, which form a cluster. The application interacts with the TDengine cluster through taosc's API. The following is a brief introduction to each logical unit. + +**Physical node (pnode)**: A pnode is a computer that runs independently and has its own computing, storage and network capabilities. It can be a physical machine, virtual machine or Docker container installed with OS. The physical node is identified by its configured FQDN (Fully Qualified Domain Name). TDengine relies entirely on FQDN for network communication. If you don't know about FQDN, please read the blog post "[All about FQDN of TDengine](https://www.taosdata.com/blog/2020/09/11/1824.html)". + +**Data node (dnode):** A dnode is a running instance of the TDengine server-side execution code taosd on a physical node. A working system must have at least one data node. A dnode contains zero to multiple logical virtual nodes (VNODE), zero or at most one logical management node (mnode). The unique identification of a dnode in the system is determined by the instance's End Point (EP). EP is a combination of FQDN (Fully Qualified Domain Name) of the physical node where the dnode is located and the network port number (Port) configured by the system. By configuring different ports, a physical node (a physical machine, virtual machine or container) can run multiple instances or have multiple data nodes. + +**Virtual node (vnode)**: In order to better support data sharding, load balancing and prevent data from overheating or skewing, data nodes are virtualized into multiple virtual nodes (vnode, V2, V3, V4, etc. in the figure). Each vnode is a relatively independent work unit, which is the basic unit of time-series data storage, and has independent running threads, memory space and persistent storage path. A vnode contains a certain number of tables (data collection points). When a new table is created, the system checks whether a new vnode needs to be created. The number of vnodes that can be created on a data node depends on the hardware capacities of the physical node where the data node is located. A vnode belongs to only one DB, but a DB can have multiple vnodes. In addition to the stored time-series data, a vnode also stores the schema and tag values of the included tables. A virtual node is uniquely identified in the system by the EP of the data node and the VGroup ID to which it belongs, and is created and managed by the management node. + +**Management node (mnode)**: A virtual logical unit responsible for monitoring and maintaining the running status of all data nodes and load balancing among nodes (M in figure). At the same time, the management node is also responsible for the storage and management of metadata (including users, databases, tables, static tags, etc.), so it is also called Meta Node. Multiple (up to 5) mnodes can be configured in a TDengine cluster, and they are automatically constructed into a virtual management node group (M0, M1, M2 in the figure). The master/slave mechanism is used to manage between mnodes, and the data synchronization is carried out in a strong consistent way. Any data update operation can only be done on the master. The creation of mnode cluster is completed automatically by the system without manual intervention. There is at most one mnode on each dnode, which is uniquely identified by the EP of the data node to which it belongs. Each dnode automatically obtains the EP of the dnode where all mnodes in the whole cluster are located through internal messaging interaction. + +**Virtual node group (VGroup)**: Vnodes on different data nodes can form a virtual node group to ensure the high reliability of the system. The virtual node group is managed in a master/slave structure. Write operations can only be performed on the master vnode, and the system synchronizes data to the slave vnode via replication, thus ensuring that one single replica of data is copied on multiple physical nodes. The number of virtual nodes in a vgroup equals the number of data replicas. If the number of replicas of a DB is N, the system must have at least N data nodes. The number of replicas can be specified by the parameter replica when creating DB, and the default is 1. Using the multi-replica feature of TDengine, the same high data reliability can be done without the need for expensive storage devices such as disk arrays. Virtual node group is created and managed by management node, and the management node assigns a system unique ID, aka VGroup ID. If two virtual nodes has the same vnode group ID, means that they belong to the same group and the data is backed up to each other. The number of virtual nodes in a virtual node group can be dynamically changed, allowing only one, that is, no data replication. VGroup ID is never changed. Even if a virtual node group is deleted, its ID will not be reused. + +**TAOSC**: TAOSC is the driver provided by TDengine to applications, which is responsible for dealing with the interface interaction between application and cluster, and provides the native interface of C/C + + language, which is embedded in JDBC, C #, Python, Go, Node.js language connection libraries. Applications interact with the whole cluster through taosc instead of directly connecting to data nodes in the cluster. This module is responsible for obtaining and caching metadata; forwarding requests for insertion, query, etc. to the correct data node; when returning the results to the application, taosc also need to be responsible for the final level of aggregation, sorting, filtering and other operations. For JDBC, C/C + +/C #/Python/Go/Node.js interfaces, this module runs on the physical node where the application is located. At the same time, in order to support the fully distributed RESTful interface, taosc has a running instance on each dnode of TDengine cluster. + +### Node Communication + +**Communication mode**: The communication among each data node of TDengine system, and among application driver and each data node is carried out through TCP/UDP. Considering an IoT scenario, the data writing packets are generally not large, so TDengine uses UDP in addition to TCP for transmission, because UDP is more efficient and is not limited by the number of connections. TDengine implements its own timeout, retransmission, confirmation and other mechanisms to ensure reliable transmission of UDP. For packets with a data volume of less than 15K, UDP is adopted for transmission, and TCP is automatically adopted for transmission of packets with a data volume of more than 15K or query operations. At the same time, TDengine will automatically compress/decompress the data, digital sign/authenticate the data according to the configuration and data packet. For data replication among data nodes, only TCP is used for data transmission. + +**FQDN configuration:** A data node has one or more FQDNs, which can be specified in the system configuration file taos.cfg with the parameter "fqdn". If it is not specified, the system will automatically use the hostname of the computer as its FQDN. If the node is not configured with FQDN, you can directly set the configuration parameter fqdn of the node to its IP address. However, IP is not recommended because IP address is variable, and once it changes, the cluster will not work properly. The EP (End Point) of a data node consists of FQDN + Port. With FQDN, it is necessary to ensure the normal operation of DNS service, or configure hosts files on nodes and the nodes where applications are located. + +**Port configuration**: The external port of a data node is determined by the system configuration parameter serverPort in TDengine, and the port for internal communication of cluster is serverPort+5. The data replication operation among data nodes in the cluster also occupies a TCP port, which is serverPort+10. In order to support multithreading and efficient processing of UDP data, each internal and external UDP connection needs to occupy 5 consecutive ports. Therefore, the total port range of a data node will be serverPort to serverPort + 10, for a total of 11 TCP/UDP ports. When using, make sure that the firewall keeps these ports open. Each data node can be configured with a different serverPort. + +**Cluster external connection**: TDengine cluster can accommodate one single, multiple or even thousands of data nodes. The application only needs to initiate a connection to any data node in the cluster. The network parameter required for connection is the End Point (FQDN plus configured port number) of a data node. When starting the application taos through CLI, the FQDN of the data node can be specified through the option-h, and the configured port number can be specified through -p. If the port is not configured, the system configuration parameter serverPort of TDengine will be adopted. + +**Inter-cluster communication**: Data nodes connect with each other through TCP/UDP. When a data node starts, it will obtain the EP information of the dnode where the mnode is located, and then establish a connection with the mnode in the system to exchange information. There are three steps to obtain EP information of the mnode: 1. Check whether the mnodeEpList file exists, if it does not exist or cannot be opened normally to obtain EP information of the mnode, skip to the second step; 2: Check the system configuration file taos.cfg to obtain node configuration parameters firstEp and secondEp (the node specified by these two parameters can be a normal node without mnode, in this case, the node will try to redirect to the mnode node when connected). If these two configuration parameters do not exist or do not exist in taos.cfg, or are invalid, skip to the third step; 3: Set your own EP as a mnode EP and run it independently. After obtaining the mnode EP list, the data node initiates the connection. It will successfully join the working cluster after connected. If not successful, it will try the next item in the mnode EP list. If all attempts are made, but the connection still fails, sleep for a few seconds before trying again. + +**The choice of MNODE**: TDengine logically has a management node, but there is no separated execution code. The server side only has a set of execution code taosd. So which data node will be the management node? This is determined automatically by the system without any manual intervention. The principle is as follows: when a data node starts, it will check its End Point and compare it with the obtained mnode EP List. If its EP exists in it, the data node shall start the mnode module and become a mnode. If your own EP is not in the mnode EP List, the mnode module will not start. During the system operation, due to load balancing, downtime and other reasons, mnode may migrate to the new dnode, while totally transparent without manual intervention. The modification of configuration parameters is the decision made by mnode itself according to resources usage. + +**Add new data nodes:** After the system has a data node, it has become a working system. There are two steps to add a new node into the cluster. Step1: Connect to the existing working data node using TDengine CLI, and then add the End Point of the new data node with the command "create dnode"; Step 2: In the system configuration parameter file taos.cfg of the new data node, set the firstEp and secondEp parameters to the EP of any two data nodes in the existing cluster. Please refer to the detailed user tutorial for detailed steps. In this way, the cluster will be established step by step. + +**Redirection**: No matter about dnode or taosc, the connection to the mnode shall be initiated first, but the mnode is automatically created and maintained by the system, so user does not know which dnode is running the mnode. TDengine only requires a connection to any working dnode in the system. Because any running dnode maintains the currently running mnode EP List, when receiving a connecting request from the newly started dnode or taosc, if it’s not an mnode by self, it will reply the mnode EP List back. After receiving this list, taosc or the newly started dnode will try to establish the connection again. When the mnode EP List changes, each data node quickly obtains the latest list and notifies taosc through messaging interaction among nodes. + +### A Typical Messaging Process + +To explain the relationship between vnode, mnode, taosc and application and their respective roles, the following is an analysis of a typical data writing process. + +Figure 2: A typical process of TDengine + +1. Application initiates a request to insert data through JDBC, ODBC, or other APIs. +2. Cache be checked by taosc that if meta data existing for the table. If so, go straight to Step 4. If not, taosc sends a get meta-data request to mnode. +3. Mnode returns the meta-data of the table to taosc. Meta-data contains the schema of the table, and also the vgroup information to which the table belongs (the vnode ID and the End Point of the dnode where the table belongs. If the number of replicas is N, there will be N groups of End Points). If taosc does not receive a response from the mnode for a long time, and there are multiple mnodes, taosc will send a request to the next mnode. +4. Taosc initiates an insert request to master vnode. +5. After vnode inserts the data, it gives a reply to taosc, indicating that the insertion is successful. If taosc doesn't get a response from vnode for a long time, taosc will judge the node as offline. In this case, if there are multiple replicas of the inserted database, taosc will issue an insert request to the next vnode in vgroup. +6. Taosc notifies APP that writing is successful. + +For Step 2 and 3, when taosc starts, it does not know the End Point of mnode, so it will directly initiate a request to the externally serving End Point of the configured cluster. If the dnode that received the request does not have an mnode configured, it will inform the mnode EP list in a reply message, so that taosc will re-issue a request to obtain meta-data to the EP of another new mnode. + +For Step 4 and 5, without caching, taosc can't recognize the master in the virtual node group, so assumes that the first vnodeID is the master and send a request to it. If the requested vnode is not the master, it will reply the actual master as a new target taosc makes a request to. Once the reply of successful insertion is obtained, taosc will cache the information of master node. + +The above is the process of inserting data, and the processes of querying and calculating are completely consistent. Taosc encapsulates and shields all these complicated processes, and has no perception and no special treatment for applications. + +Through taosc caching mechanism, mnode needs to be accessed only when a table is operated for the first time, so mnode will not become a system bottleneck. However, because schema and vgroup may change (such as load balancing), taosc will interact with mnode regularly to automatically update the cache. + +## Storage Model and Data Partitioning/Sharding + +### Storage Model + +The data stored by TDengine include collected time-series data, metadata related to libraries and tables, tag data, etc. These data are specifically divided into three parts: + +- Time-series data: stored in vnode and composed of data, head and last files. The amount of data is large and query amount depends on the application scenario. Out-of-order writing is allowed, but delete operation is not supported for the time being, and update operation is only allowed when update parameter is set to 1. By adopting the model with one table for each collection point, the data of a given time period is continuously stored, and the writing against one single table is a simple add operation. Multiple records can be read at one time, thus ensuring the insert and query operation of a single collection point with best performance. +- Tag data: meta files stored in vnode support four standard operations of add, delete, modify and check. The amount of data is not large. If there are N tables, there are N records, so all can be stored in memory. If there are many tag filtering operations, queries will be very frequent and TDengine supports multi-core and multi-threaded concurrent queries. As long as the computing resources are sufficient, even in face of millions of tables, the filtering results will return in milliseconds. +- Metadata: stored in mnode, including system node, user, DB, Table Schema and other information. Four standard operations of add, delete, modify and query are supported. The amount of these data are not large and can be stored in memory, moreover the query amount is not large because of the client cache. Therefore, TDengine uses centralized storage management, however, there will be no performance bottleneck. + +Compared with the typical NoSQL storage model, TDengine stores tag data and time-series data completely separately, which has two major advantages: + +- Greatly reduce the redundancy of tag data storage: general NoSQL database or time-series database adopts K-V storage, in which Key includes timestamp, device ID and various tags. Each record carries these duplicates, so wasting storage space. Moreover, if the application needs to add, modify or delete tags on historical data, it has to traverse the data and rewrite again, which is extremely expensive to operate. +- Realize extremely efficient aggregation query between multiple tables: when doing aggregation query between multiple tables, it firstly finds out the tag filtered tables, and then find out the corresponding data blocks of these tables to greatly reduce the data sets to be scanned, thus greatly improving the query efficiency. Moreover, tag data is managed and maintained in a full-memory structure, and tag data queries in tens of millions can return in milliseconds. + +### Data Sharding + +For large-scale data management, to achieve scale-out, it is generally necessary to adopt the a Partitioning strategy as Sharding. TDengine implements data sharding via vnode, and time-series data partitioning via one data file for each time range. + +VNode (Virtual Data Node) is responsible for providing writing, query and calculation functions for collected time-series data. To facilitate load balancing, data recovery and support heterogeneous environments, TDengine splits a data node into multiple vnodes according to its computing and storage resources. The management of these vnodes is done automatically by TDengine and completely transparent to the application. + +For a single data collection point, regardless of the amount of data, a vnode (or vnode group, if the number of replicas is greater than 1) has enough computing resource and storage resource to process (if a 16-byte record is generated per second, the original data generated in one year will be less than 0.5 G), so TDengine stores all the data of a table (a data collection point) in one vnode instead of distributing the data to two or more dnodes. Moreover, a vnode can store data from multiple data collection points (tables), and the upper limit of the tables’ quantity for a vnode is one million. By design, all tables in a vnode belong to the same DB. On a data node, unless specially configured, the number of vnodes owned by a DB will not exceed the number of system cores. + +When creating a DB, the system does not allocate resources immediately. However, when creating a table, the system will check if there is an allocated vnode with free tablespace. If so, the table will be created in the vacant vnode immediately. If not, the system will create a new vnode on a dnode from the cluster according to the current workload, and then a table. If there are multiple replicas of a DB, the system does not create only one vnode, but a vgroup (virtual data node group). The system has no limit on the number of vnodes, which is just limited by the computing and storage resources of physical nodes. + +The meda data of each table (including schema, tags, etc.) is also stored in vnode instead of centralized storage in mnode. In fact, this means sharding of meta data, which is convenient for efficient and parallel tag filtering operations. + +### Data Partitioning + +In addition to vnode sharding, TDengine partitions the time-series data by time range. Each data file contains only one time range of time-series data, and the length of the time range is determined by DB's configuration parameter “days”. This method of partitioning by time rang is also convenient to efficiently implement the data retention strategy. As long as the data file exceeds the specified number of days (system configuration parameter ‘keep’), it will be automatically deleted. Moreover, different time ranges can be stored in different paths and storage media, so as to facilitate the cold/hot management of big data and realize tiered-storage. + +In general, **TDengine splits big data by vnode and time as two dimensions**, which is convenient for parallel and efficient management with scale-out. + +### Load Balancing + +Each dnode regularly reports its status (including hard disk space, memory size, CPU, network, number of virtual nodes, etc.) to the mnode (virtual management node) for declaring the status of the entire cluster. Based on the overall state, when an mnode finds an overloaded dnode, it will migrate one or more vnodes to other dnodes. In the process, external services keep running and the data insertion, query and calculation operations are not affected. + +If the mnode has not received the dnode status for a period of time, the dnode will be judged as offline. When offline lasts a certain period of time (the duration is determined by the configuration parameter ‘offlineThreshold’), the dnode will be forcibly removed from the cluster by mnode. If the number of replicas of vnodes on this dnode is greater than one, the system will automatically create new replicas on other dnodes to ensure the replica number. If there are other mnodes on this dnode and the number of mnodes replicas is greater than one, the system will automatically create new mnodes on other dnodes to ensure t the replica number. + +When new data nodes are added to the cluster, with new computing and storage are added, the system will automatically start the load balancing process. + +The load balancing process does not require any manual intervention without application restarted. It will automatically connect new nodes with completely transparence. **Note: load balancing is controlled by parameter “balance”, which determines to turn on/off automatic load balancing.** + +## Data Writing and Replication Process + +If a database has N replicas, thus a virtual node group has N virtual nodes, but only one as Master and all others are slaves. When the application writes a new record to system, only the Master vnode can accept the writing request. If a slave vnode receives a writing request, the system will notifies taosc to redirect. + +### Master vnode Writing Process + +Master Vnode uses a writing process as follows: + +Figure 3: TDengine Master writing process + +1. Master vnode receives the application data insertion request, verifies, and to next step; +2. If the system configuration parameter “walLevel” is greater than 0, vnode will write the original request packet into database log file WAL. If walLevel is set to 2 and fsync is set to 0, TDengine will make WAL data written immediately to ensure that even system goes down, all data can be recovered from database log file; +3. If there are multiple replicas, vnode will forward data packet to slave vnodes in the same virtual node group, and the forwarded packet has a version number with data; +4. Write into memory and add the record to “skip list”; +5. Master vnode returns a confirmation message to the application, indicating a successful writing. +6. If any of Step 2, 3 or 4 fails, the error will directly return to the application. + +### Slave vnode Writing Process + +For a slave vnode, the write process as follows: + +Fiture 4: TDengine Slave Writing Process + +1. Slave vnode receives a data insertion request forwarded by Master vnode. +2. If the system configuration parameter “walLevel” is greater than 0, vnode will write the original request packet into database log file WAL. If walLevel is set to 2 and fsync is set to 0, TDengine will make WAL data written immediately to ensure that even system goes down, all data can be recovered from database log file; +3. Write into memory and add the record to “skip list”; + +Compared with Master vnode, slave vnode has no forwarding or reply confirmation step, means two steps less. But writing into memory is exactly the same as WAL. + +### Remote Disaster Recovery and IDC Migration + +As above Master and Slave processes discussed, TDengine adopts asynchronous replication for data synchronization. This method can greatly improve the writing performance, with not obvious impact from network delay. By configuring IDC and rack number for each physical node, it can be ensured that for a virtual node group, virtual nodes are composed of physical nodes from different IDC and different racks, thus implementing remote disaster recovery without other tools. + +On the other hand, TDengine supports dynamic modification of the replicas number. Once the number of replicas increases, the newly added virtual nodes will immediately enter the data synchronization process. After synchronization completed, added virtual nodes can provide services. In the synchronization process, master and other synchronized virtual nodes keep serving. With this feature, TDengine can realize IDC room migration without service interruption. It is only necessary to add new physical nodes to the existing IDC cluster, and then remove old physical nodes after the data synchronization is completed. + +However, this asynchronous replication method has a tiny time window of written data lost. The specific scenario is as follows: + +1. Master vnode has completed its 5-step operations, confirmed the success of writing to APP, and then went down; +2. Slave vnode receives the write request, then processing fails before writing to the log in Step 2; +3. Slave vnode will become the new master, thus losing one record + +In theory, as long as in asynchronous replication, there is no guarantee for no losing. However, this window is extremely small, only if mater and slave fail at the same time, and just confirm the successful write to the application before. + +Note: Remote disaster recovery and no-downtime IDC migration are only supported by Enterprise Edition. **Hint: This function is not available yet** + +### Master/slave Selection + +Vnode maintains a Version number. When memory data is persisted, the version number will also be persisted. For each data update operation, whether it is collecting time-series data or metadata, this version number will be increased by one. + +When a vnode starts, the roles (master, slave) are uncertain, and the data is in an unsynchronized state. It’s necessary to establish TCP connections with other nodes in the virtual node group and exchange status, including version and its own roles. Through the exchange, the system implements a master-selection process. The rules are as follows: + +1. If there’s only one replica, it’s always master +2. When all replicas are online, the one with latest version is master +3. Over half of online nodes are virtual nodes, and some virtual node is slave, it will automatically become master +4. For 2 and 3, if multiple virtual nodes meet the requirement, the first vnode in virtual node group list will be selected as master + +See [TDengine 2.0 Data Replication Module Design](https://www.taosdata.com/cn/documentation/architecture/replica/) for more information on the data replication process. + +### Synchronous Replication + +For scenarios with higher data consistency requirements, asynchronous data replication is not applicable, because there is some small probability of data loss. So, TDengine provides a synchronous replication mechanism for users. When creating a database, in addition to specifying the number of replicas, user also needs to specify a new parameter “quorum”. If quorum is greater than one, it means that every time the Master forwards a message to the replica, it needs to wait for “quorum-1” reply confirms before informing the application that data has been successfully written in slave. If “quorum-1” reply confirms are not received within a certain period of time, the master vnode will return an error to the application. + +With synchronous replication, performance of system will decrease and latency will increase. Because metadata needs strong consistent, the default for data synchronization between mnodes is synchronous replication. + +Note: synchronous replication between vnodes is only supported in Enterprise Edition + +## Caching and Persistence + +### Caching + +TDengine adopts a time-driven cache management strategy (First-In-First-Out, FIFO), also known as a Write-driven Cache Management Mechanism. This strategy is different from the read-driven data caching mode (Least-Recent-Used, LRU), which directly put the most recently written data in the system buffer. When the buffer reaches a threshold, the earliest data are written to disk in batches. Generally speaking, for the use of IoT data, users are most concerned about the newly generated data, that is, the current status. TDengine takes full advantage of this feature to put the most recently arrived (current state) data in the buffer. + +TDengine provides millisecond-level data collecting capability to users through query functions. Putting the recently arrived data directly in the buffer can respond to users' analysis query for the latest piece or batch of data more quickly, and provide faster database query response capability as a whole. In this sense, **TDengine can be used as a data buffer by setting appropriate configuration parameters without deploying Redis or other additional cache systems**, which can effectively simplify the system architecture and reduce the operation costs. It should be noted that after the TDengine is restarted, the buffer of the system will be emptied, the previously cached data will be written to disk in batches, and the previously cached data will not be reloaded into the buffer as so in a proprietary key-value cache system. + +Each vnode has its own independent memory, and it is composed of multiple memory blocks of fixed size, and different vnodes are completely isolated. When writing data, similar to the writing of logs, data is sequentially added to memory, but each vnode maintains its own skip list for quick search. When more than one third of the memory block are used, the disk writing operation will start, and the subsequent writing operation is carried out in a new memory block. By this design, one third of the memory blocks in a vnode keep the latest data, so as to achieve the purpose of caching and quick search. The number of memory blocks of a vnode is determined by the configuration parameter “blocks”, and the size of memory blocks is determined by the configuration parameter “cache”. + +### Persistent Storage + +TDengine uses a data-driven method to write the data from buffer into hard disk for persistent storage. When the cached data in vnode reaches a certain volume, TDengine will also pull up the disk-writing thread to write the cached data into persistent storage in order not to block subsequent data writing. TDengine will open a new database log file when the data is written, and delete the old database log file after written successfully to avoid unlimited log growth. + +To make full use of the characteristics of time-series data, TDengine splits the data stored in persistent storage by a vnode into multiple files, each file only saves data for a fixed number of days, which is determined by the system configuration parameter “days”. By so, for the given start and end date of a query, you can locate the data files to open immediately without any index, thus greatly speeding up reading operations. + +For collected data, there is generally a retention period, which is determined by the system configuration parameter “keep”. Data files exceeding this set number of days will be automatically deleted by the system to free up storage space. + +Given “days” and “keep” parameters, the total number of data files in a vnode is: keep/days. The total number of data files should not be too large or too small. 10 to 100 is appropriate. Based on this principle, reasonable days can be set. In the current version, parameter “keep” can be modified, but parameter “days” cannot be modified once it is set. + +In each data file, the data of a table is stored by blocks. A table can have one or more data file blocks. In a file block, data is stored in columns, occupying a continuous storage space, thus greatly improving the reading speed. The size of file block is determined by the system parameter “maxRows” (the maximum number of records per block), and the default value is 4096. This value should not be too large or too small. If it is too large, the data locating in search will cost longer; if too small, the index of data block is too large, and the compression efficiency will be low with slower reading speed. + +Each data file (with a .data postfix) has a corresponding index file (with a .head postfix). The index file has summary information of a data block for each table, recording the offset of each data block in the data file, start and end time of data and other information, so as to lead system quickly locate the data to be found. Each data file also has a corresponding last file (with a .last postfix), which is designed to prevent data block fragmentation when written in disk. If the number of written records from a table does not reach the system configuration parameter “minRows” (minimum number of records per block), it will be stored in the last file first. When write to disk next time, the newly written records will be merged with the records in last file and then written into data file. + +When data is written to disk, it is decided whether to compress the data according to system configuration parameter “comp”. TDengine provides three compression options: no compression, one-stage compression and two-stage compression, corresponding to comp values of 0, 1 and 2 respectively. One-stage compression is carried out according to the type of data. Compression algorithms include delta-delta coding, simple 8B method, zig-zag coding, LZ4 and other algorithms. Two-stage compression is based on one-stage compression and compressed by general compression algorithm, which has higher compression ratio. + +### Tiered Storage + +By default, TDengine saves all data in /var/lib/taos directory, and the data files of each vnode are saved in a different directory under this directory. In order to expand the storage space, minimize the bottleneck of file reading and improve the data throughput rate, TDengine can configure the system parameter “dataDir” to allow multiple mounted hard disks to be used by system at the same time. In addition, TDengine also provides the function of tiered data storage, i.e. storage on different storage media according to the time stamps of data files. For example, the latest data is stored on SSD, the data for more than one week is stored on local hard disk, and the data for more than four weeks is stored on network storage device, thus reducing the storage cost and ensuring efficient data access. The movement of data on different storage media is automatically done by the system and completely transparent to applications. Tiered storage of data is also configured through the system parameter “dataDir”. + + + +dataDir format is as follows: + +1. dataDir data_path [tier_level] + +Where data_path is the folder path of mount point and tier_level is the media storage-tier. The higher the media storage-tier, means the older the data file. Multiple hard disks can be mounted at the same storage-tier, and data files on the same storage-tier are distributed on all hard disks within the tier. TDengine supports up to 3 tiers of storage, so tier_level values are 0, 1, and 2. When configuring dataDir, there must be only one mount path without specifying tier_level, which is called special mount disk (path). The mount path defaults to level 0 storage media and contains special file links, which cannot be removed, otherwise it will have a devastating impact on the written data. + + + +Suppose a physical node with six mountable hard disks/mnt/disk1,/mnt/disk2, …,/mnt/disk6, where disk1 and disk2 need to be designated as level 0 storage media, disk3 and disk4 are level 1 storage media, and disk5 and disk6 are level 2 storage media. Disk1 is a special mount disk, you can configure it in/etc/taos/taos.cfg as follows: + + + +1. dataDir /mnt/disk1/taos +2. dataDir /mnt/disk2/taos 0 +3. dataDir /mnt/disk3/taos 1 +4. dataDir /mnt/disk4/taos 1 +5. dataDir /mnt/disk5/taos 2 +6. dataDir /mnt/disk6/taos 2 + + + +Mounted disks can also be a non-local network disk, as long as the system can access it. + + + +Note: Tiered Storage is only supported in Enterprise Edition + +## Data Query + +TDengine provides a variety of query processing functions for tables and STables. In addition to common aggregation queries, TDengine also provides window queries and statistical aggregation functions for time-series data. The query processing of TDengine needs the collaboration of client, vnode and mnode. + +### Single Table Query + +The parsing and verification of SQL statements are completed on the client side. SQL statements are parsed and generate an Abstract Syntax Tree (AST), which is then checksummed. Then request metadata information (table metadata) for the table specified in the query from management node (mnode). + +According to the End Point information in metadata information, the query request is serialized and sent to the data node (dnode) where the table is located. After receiving the query, the dnode identifies the virtual node (vnode) pointed to and forwards the message to the query execution queue of the vnode. The query execution thread of vnode establishes the basic query execution environment, immediately returns the query request and starts executing the query at the same time. + +When client obtains query result, the worker thread in query execution queue of dnode will wait for the execution of vnode execution thread to complete before returning the query result to the requesting client. + +### Aggregation by Time Axis, Downsampling, Interpolation + +The remarkable feature that time-series data is different from ordinary data is that each record has a timestamp, so aggregating data with timestamps on the time axis is an important and unique function from common databases. From this point of view, it is similar to the window query of stream computing engine. + +The keyword “interval” is introduced into TDengine to split fixed length time windows on time axis, and the data are aggregated according to time windows, and the data within window range are aggregated as needed. For example: + + + +1. select count(*) from d1001 interval(1h); + + + +According to the data collected by device D1001, the number of records stored per hour is returned by a 1-hour time window. + + + +In application scenarios where query results need to be obtained continuously, if there is data missing in a given time interval, the data results in this interval will also be lost. TDengine provides a strategy to interpolate the results of timeline aggregation calculation. The results of time axis aggregation can be interpolated by using keyword Fill. For example: + + + +1. select count(*) from d1001 interval(1h) fill(prev); + + + +According to the data collected by device D1001, the number of records per hour is counted. If there is no data in a certain hour, statistical data of the previous hour is returned. TDengine provides forward interpolation (prev), linear interpolation (linear), NULL value populating (NULL), and specific value populating (value). + +### Multi-table Aggregation Query + +TDengine creates a separate table for each data collection point, but in practical applications, it is often necessary to aggregate data from different collection points. In order to perform aggregation operations efficiently, TDengine introduces the concept of STable. STable is used to represent a specific type of data collection point. It is a table set containing multiple tables. The schema of each table in the set is completely consistent, but each table has its own static tag. The tags can be multiple and be added, deleted and modified at any time. Applications can aggregate or statistically operate all or a subset of tables under a STABLE by specifying tag filters, thus greatly simplifying the development of applications. The process is shown in the following figure: + + + +Figure 5: Diagram of multi-table aggregation query + +1. Application sends a query condition to system; +2. taosc sends the STable name to Meta Node(management node); +3. Management node sends the vnode list owned by the STable back to taosc; +4. taosc sends the computing request together with tag filters to multiple data nodes corresponding to these vnodes; +5. Each vnode first finds out the set of tables within its own node that meet the tag filters from memory, then scans the stored time-series data, completes corresponding aggregation calculations, and returns result to taosc; +6. taosc finally aggregates the results returned by multiple data nodes and send them back to application. + +Since TDengine stores tag data and time-series data separately in vnode, by filtering tag data in memory, the set of tables that need to participate in aggregation operation is first found, which greatly reduces the volume of data scanned and improves aggregation calculation speed. At the same time, because the data is distributed in multiple vnodes/dnodes, the aggregation calculation operation is carried out concurrently in multiple vnodes, which further improves the aggregation speed. Aggregation functions for ordinary tables and most operations are applicable to STables. The syntax is exactly the same. Please see TAOS SQL for details. + +### Precomputation + +In order to effectively improve the performance of query processing, based-on the unchangeable feature of IoT data, statistical information of data stored in data block is recorded in the head of data block, including max value, min value, and sum. We call it a precomputing unit. If the query processing involves all the data of a whole data block, the pre-calculated results are directly used, and no need to read the data block contents at all. Since the amount of pre-calculated data is much smaller than the actual size of data block stored on disk, for query processing with disk IO as bottleneck, the use of pre-calculated results can greatly reduce the pressure of reading IO and accelerate the query process. The precomputation mechanism is similar to the index BRIN (Block Range Index) of PostgreSQL. \ No newline at end of file diff --git a/documentation20/en/05.insert/docs.md b/documentation20/en/05.insert/docs.md new file mode 100644 index 0000000000000000000000000000000000000000..b8169ad4343c1179830f5323bf036254607b8490 --- /dev/null +++ b/documentation20/en/05.insert/docs.md @@ -0,0 +1,300 @@ +# Efficient Data Writing + +TDengine supports multiple interfaces to write data, including SQL, Prometheus, Telegraf, EMQ MQTT Broker, HiveMQ Broker, CSV file, etc. Kafka, OPC and other interfaces will be provided in the future. Data can be inserted in a single piece or in batches, data from one or multiple data collection points can be inserted at the same time. TDengine supports multi-thread insertion, nonsequential data insertion, and also historical data insertion. + +## SQL Writing + +Applications insert data by executing SQL insert statements through C/C + +, JDBC, GO, or Python Connector, and users can manually enter SQL insert statements to insert data through TAOS Shell. For example, the following insert writes a record to table d1001: + +```mysql +``` + +INSERT INTO d1001 VALUES (1538548685000, 10.3, 219, 0.31); + +``` +``` + +TDengine supports writing multiple records at a time. For example, the following command writes two records to table d1001: + +```mysql +``` + +INSERT INTO d1001 VALUES (1538548684000, 10.2, 220, 0.23) (1538548696650, 10.3, 218, 0.25); + +``` +``` + +TDengine also supports writing data to multiple tables at a time. For example, the following command writes two records to d1001 and one record to d1002: + +```mysql +``` + +INSERT INTO d1001 VALUES (1538548685000, 10.3, 219, 0.31) (1538548695000, 12.6, 218, 0.33) d1002 VALUES (1538548696800, 12.3, 221, 0.31); + +``` +``` + +For the SQL INSERT Grammar, please refer to [Taos SQL insert](https://www.taosdata.com/en/documentation/taos-sql#insert)。 + +**Tips:** + +- To improve writing efficiency, batch writing is required. The more records written in a batch, the higher the insertion efficiency. However, a record cannot exceed 16K, and the total length of an SQL statement cannot exceed 64K (it can be configured by parameter maxSQLLength, and the maximum can be configured to 1M). +- TDengine supports multi-thread parallel writing. To further improve writing speed, a client needs to open more than 20 threads to write parallelly. However, after the number of threads reaches a certain threshold, it cannot be increased or even become decreased, because too much frequent thread switching brings extra overhead. +- For a same table, if the timestamp of a newly inserted record already exists, (no database was created using UPDATE 1) the new record will be discarded as default, that is, the timestamp must be unique in a table. If an application automatically generates records, it is very likely that the generated timestamps will be the same, so the number of records successfully inserted will be smaller than the number of records the application try to insert. If you use UPDATE 1 option when creating a database, inserting a new record with the same timestamp will overwrite the original record. +- The timestamp of written data must be greater than the current time minus the time of configuration parameter keep. If keep is configured for 3650 days, data older than 3650 days cannot be written. The timestamp for writing data cannot be greater than the current time plus configuration parameter days. If days is configured to 2, data 2 days later than the current time cannot be written. + +## Direct Writing of Prometheus + +As a graduate project of Cloud Native Computing Foundation, [Prometheus](https://www.prometheus.io/) is widely used in the field of performance monitoring and K8S performance monitoring. TDengine provides a simple tool [Bailongma](https://github.com/taosdata/Bailongma), which only needs to be simply configured in Prometheus without any code, and can directly write the data collected by Prometheus into TDengine, then automatically create databases and related table entries in TDengine according to rules. Blog post [Use Docker Container to Quickly Build a Devops Monitoring Demo](https://www.taosdata.com/blog/2020/02/03/1189.html), which is an example of using bailongma to write Prometheus and Telegraf data into TDengine. + +### Compile blm_prometheus From Source + +Users need to download the source code of [Bailongma](https://github.com/taosdata/Bailongma) from github, then compile and generate an executable file using Golang language compiler. Before you start compiling, you need to complete following prepares: + +- A server running Linux OS +- Golang version 1.10 and higher installed +- An appropriated TDengine version. Because the client dynamic link library of TDengine is used, it is necessary to install the same version of TDengine as the server-side; for example, if the server version is TDengine 2.0. 0, ensure install the same version on the linux server where bailongma is located (can be on the same server as TDengine, or on a different server) + +Bailongma project has a folder, blm_prometheus, which holds the prometheus writing API. The compiling process is as follows: + +```bash +``` + +cd blm_prometheus + +go build + +``` +``` + +If everything goes well, an executable of blm_prometheus will be generated in the corresponding directory. + +### Install Prometheus + +Download and install as the instruction of Prometheus official website. [Download Address](https://prometheus.io/download/) + +### Configure Prometheus + +Read the Prometheus [configuration document](https://prometheus.io/docs/prometheus/latest/configuration/configuration/) and add following configurations in the section of Prometheus configuration file + +- url: The URL provided by bailongma API service, refer to the blm_prometheus startup example section below + +After Prometheus launched, you can check whether data is written successfully through query taos client. + +### Launch blm_prometheus + +blm_prometheus has following options that you can configure when you launch blm_prometheus. + +```sh +--tdengine-name + +If TDengine is installed on a server with a domain name, you can also access the TDengine by configuring the domain name of it. In K8S environment, it can be configured as the service name that TDengine runs + +--batch-size + +blm_prometheus assembles the received prometheus data into a TDengine writing request. This parameter controls the number of data pieces carried in a writing request sent to TDengine at a time. + +--dbname + +Set a name for the database created in TDengine, blm_prometheus will automatically create a database named dbname in TDengine, and the default value is prometheus. + +--dbuser + +Set the user name to access TDengine, the default value is'root ' + +--dbpassword + +Set the password to access TDengine, the default value is'taosdata ' + +--port + +The port number blm_prometheus used to serve prometheus. +``` + + + +### Example + +Launch an API service for blm_prometheus with the following command: + +```bash +./blm_prometheus -port 8088 +``` + +Assuming that the IP address of the server where blm_prometheus located is "10.1.2. 3", the URL shall be added to the configuration file of Prometheus as: + +remote_write: + +\- url: "http://10.1.2.3:8088/receive" + + + +### Query written data of prometheus + +The format of generated data by Prometheus is as follows: + +```json + + +{ + Timestamp: 1576466279341, + Value: 37.000000, + apiserver_request_latencies_bucket { + component="apiserver", + instance="192.168.99.116:8443", + job="kubernetes-apiservers", + le="125000", + resource="persistentvolumes", s + cope="cluster", + verb="LIST", + version=“v1" + } +} +``` + +Where apiserver_request_latencies_bucket is the name of the time-series data collected by prometheus, and the tag of the time-series data is in the following {}. blm_prometheus automatically creates a STable in TDengine with the name of the time series data, and converts the tag in {} into the tag value of TDengine, with Timestamp as the timestamp and value as the value of the time-series data. Therefore, in the client of TDEngine, you can check whether this data was successfully written through the following instruction. + +```mysql +use prometheus; + +select * from apiserver_request_latencies_bucket; +``` + + + +## Direct Writing of Telegraf + +[Telegraf](https://www.influxdata.com/time-series-platform/telegraf/) is a popular open source tool for IT operation data collection. TDengine provides a simple tool [Bailongma](https://github.com/taosdata/Bailongma), which only needs to be simply configured in Telegraf without any code, and can directly write the data collected by Telegraf into TDengine, then automatically create databases and related table entries in TDengine according to rules. Blog post [Use Docker Container to Quickly Build a Devops Monitoring Demo](https://www.taosdata.com/blog/2020/02/03/1189.html), which is an example of using bailongma to write Prometheus and Telegraf data into TDengine. + +### Compile blm_telegraf From Source Code + +Users need to download the source code of [Bailongma](https://github.com/taosdata/Bailongma) from github, then compile and generate an executable file using Golang language compiler. Before you start compiling, you need to complete following prepares: + +- A server running Linux OS +- Golang version 1.10 and higher installed +- An appropriated TDengine version. Because the client dynamic link library of TDengine is used, it is necessary to install the same version of TDengine as the server-side; for example, if the server version is TDengine 2.0. 0, ensure install the same version on the linux server where bailongma is located (can be on the same server as TDengine, or on a different server) + +Bailongma project has a folder, blm_telegraf, which holds the Telegraf writing API. The compiling process is as follows: + +```bash +cd blm_telegraf + +go build +``` + +If everything goes well, an executable of blm_telegraf will be generated in the corresponding directory. + +### Install Telegraf + +At the moment, TDengine supports Telegraf version 1.7. 4 and above. Users can download the installation package on Telegraf's website according to your current operating system. The download address is as follows: https://portal.influxdata.com/downloads + +### Configure Telegraf + +Modify the TDengine-related configurations in the Telegraf configuration file /etc/telegraf/telegraf.conf. + +In the output plugins section, add the [[outputs.http]] configuration: + +- url: The URL provided by bailongma API service, please refer to the example section below +- data_format: "json" +- json_timestamp_units: "1ms" + +In agent section: + +- hostname: The machine name that distinguishes different collection devices, and it is necessary to ensure its uniqueness +- metric_batch_size: 100, which is the max number of records per batch wriiten by Telegraf allowed. Increasing the number can reduce the request sending frequency of Telegraf. + +For information on how to use Telegraf to collect data and more about using Telegraf, please refer to the official [document](https://docs.influxdata.com/telegraf/v1.11/) of Telegraf. + +### Launch blm_telegraf + +blm_telegraf has following options, which can be set to tune configurations of blm_telegraf when launching. + +```sh +--host + +The ip address of TDengine server, default is null + +--batch-size + +blm_prometheus assembles the received telegraf data into a TDengine writing request. This parameter controls the number of data pieces carried in a writing request sent to TDengine at a time. + +--dbname + +Set a name for the database created in TDengine, blm_telegraf will automatically create a database named dbname in TDengine, and the default value is prometheus. + +--dbuser + +Set the user name to access TDengine, the default value is 'root ' + +--dbpassword + +Set the password to access TDengine, the default value is'taosdata ' + +--port + +The port number blm_telegraf used to serve Telegraf. +``` + + + +### Example + +Launch an API service for blm_telegraf with the following command + +```bash +./blm_telegraf -host 127.0.0.1 -port 8089 +``` + +Assuming that the IP address of the server where blm_telegraf located is "10.1.2. 3", the URL shall be added to the configuration file of telegraf as: + +```yaml +url = "http://10.1.2.3:8089/telegraf" +``` + +### Query written data of telegraf + +The format of generated data by telegraf is as follows: + +```json +{ + "fields": { + "usage_guest": 0, + "usage_guest_nice": 0, + "usage_idle": 89.7897897897898, + "usage_iowait": 0, + "usage_irq": 0, + "usage_nice": 0, + "usage_softirq": 0, + "usage_steal": 0, + "usage_system": 5.405405405405405, + "usage_user": 4.804804804804805 + }, + + "name": "cpu", + "tags": { + "cpu": "cpu2", + "host": "bogon" + }, + "timestamp": 1576464360 +} +``` + +Where the name field is the name of the time-series data collected by telegraf, and the tag field is the tag of the time-series data. blm_telegraf automatically creates a STable in TDengine with the name of the time series data, and converts the tag field into the tag value of TDengine, with Timestamp as the timestamp and fields values as the value of the time-series data. Therefore, in the client of TDEngine, you can check whether this data was successfully written through the following instruction. + +```mysql +use telegraf; + +select * from cpu; +``` + +MQTT is a popular data transmission protocol in the IoT. TDengine can easily access the data received by MQTT Broker and write it to TDengine. + +## Direct Writing of EMQ Broker + +[EMQ](https://github.com/emqx/emqx) is an open source MQTT Broker software, with no need of coding, only to use "rules" in EMQ Dashboard for simple configuration, and MQTT data can be directly written into TDengine. EMQ X supports storing data to the TDengine by sending it to a Web service, and also provides a native TDengine driver on Enterprise Edition for direct data store. Please refer to [EMQ official documents](https://docs.emqx.io/broker/latest/cn/rule/rule-example.html#%E4%BF%9D%E5%AD%98%E6%95%B0%E6%8D%AE%E5%88%B0-tdengine) for more details. + + + +## Direct Writing of HiveMQ Broker + +[HiveMQ](https://www.hivemq.com/) is an MQTT agent that provides Free Personal and Enterprise Edition versions. It is mainly used for enterprises, emerging machine-to-machine(M2M) communication and internal transmission to meet scalability, easy management and security features. HiveMQ provides an open source plug-in development kit. You can store data to TDengine via HiveMQ extension-TDengine. Refer to the [HiveMQ extension-TDengine documentation](https://github.com/huskar-t/hivemq-tdengine-extension/blob/b62a26ecc164a310104df57691691b237e091c89/README.md) for more details. \ No newline at end of file diff --git a/documentation20/en/06.queries/docs.md b/documentation20/en/06.queries/docs.md new file mode 100644 index 0000000000000000000000000000000000000000..f5d2b43e2bc4d9de829968ade95d99bfd7d4a63a --- /dev/null +++ b/documentation20/en/06.queries/docs.md @@ -0,0 +1,99 @@ +# Efficient Data Querying + +## Main Query Features + +TDengine uses SQL as the query language. Applications can send SQL statements through C/C + +, Java, Go, Python connectors, and users can manually execute SQL Ad-Hoc Query through the Command Line Interface (CLI) tool TAOS Shell provided by TDengine. TDengine supports the following query functions: + +- Single-column and multi-column data query +- Multiple filters for tags and numeric values: >, <, =, < >, like, etc +- Group by, Order by, Limit/Offset of aggregation results +- Four operations for numeric columns and aggregation results +- Time stamp aligned join query (implicit join) operations +- Multiple aggregation/calculation functions: count, max, min, avg, sum, twa, stddev, leastsquares, top, bottom, first, last, percentile, apercentile, last_row, spread, diff, etc + +For example, in TAOS shell, the records with vlotage > 215 are queried from table d1001, sorted in descending order by timestamps, and only two records are outputted. + +```mysql +taos> select * from d1001 where voltage > 215 order by ts desc limit 2; + ts | current | voltage | phase | +====================================================================================== + 2018-10-03 14:38:16.800 | 12.30000 | 221 | 0.31000 | + 2018-10-03 14:38:15.000 | 12.60000 | 218 | 0.33000 | +Query OK, 2 row(s) in set (0.001100s) +``` + +In order to meet the needs of an IoT scenario, TDengine supports several special functions, such as twa (time weighted average), spread (difference between maximum and minimum), last_row (last record), etc. More functions related to IoT scenarios will be added. TDengine also supports continuous queries. + +For specific query syntax, please see the [Data Query section of TAOS SQL](https://www.taosdata.com/cn/documentation/taos-sql#select). + +## Multi-table Aggregation Query + +In an IoT scenario, there are often multiple data collection points in a same type. TDengine uses the concept of STable to describe a certain type of data collection point, and an ordinary table to describe a specific data collection point. At the same time, TDengine uses tags to describe the statical attributes of data collection points. A given data collection point has a specific tag value. By specifying the filters of tags, TDengine provides an efficient method to aggregate and query the sub-tables of STables (data collection points of a certain type). Aggregation functions and most operations on ordinary tables are applicable to STables, and the syntax is exactly the same. + +**Example 1**: In TAOS Shell, look up the average voltages collected by all smart meters in Beijing and group them by location + +```mysql +taos> SELECT AVG(voltage) FROM meters GROUP BY location; + avg(voltage) | location | +============================================================= + 222.000000000 | Beijing.Haidian | + 219.200000000 | Beijing.Chaoyang | +Query OK, 2 row(s) in set (0.002136s) +``` + +**Example 2**: In TAOS Shell, look up the number of records with groupId 2 in the past 24 hours, check the maximum current of all smart meters + +```mysql +taos> SELECT count(*), max(current) FROM meters where groupId = 2 and ts > now - 24h; + cunt(*) | max(current) | +================================== + 5 | 13.4 | +Query OK, 1 row(s) in set (0.002136s) +``` + +TDengine only allows aggregation queries between tables belonging to a same STable, means aggregation queries between different STables are not supported. In the Data Query section of TAOS SQL, query class operations will all be indicated that whether STables are supported. + +## Down Sampling Query, Interpolation + +In a scenario of IoT, it is often necessary to aggregate the collected data by intervals through down sampling. TDengine provides a simple keyword interval, which makes query operations according to time windows extremely simple. For example, the current values collected by smart meter d1001 are summed every 10 seconds. + +```mysql +taos> SELECT sum(current) FROM d1001 INTERVAL(10s); + ts | sum(current) | +====================================================== + 2018-10-03 14:38:00.000 | 10.300000191 | + 2018-10-03 14:38:10.000 | 24.900000572 | +Query OK, 2 row(s) in set (0.000883s) +``` + +The down sampling operation is also applicable to STables, such as summing the current values collected by all smart meters in Beijing every second. + +```mysql +taos> SELECT SUM(current) FROM meters where location like "Beijing%" INTERVAL(1s); + ts | sum(current) | +====================================================== + 2018-10-03 14:38:04.000 | 10.199999809 | + 2018-10-03 14:38:05.000 | 32.900000572 | + 2018-10-03 14:38:06.000 | 11.500000000 | + 2018-10-03 14:38:15.000 | 12.600000381 | + 2018-10-03 14:38:16.000 | 36.000000000 | +Query OK, 5 row(s) in set (0.001538s) +``` + +The down sampling operation also supports time offset, such as summing the current values collected by all smart meters every second, but requires each time window to start from 500 milliseconds. + +```mysql +taos> SELECT SUM(current) FROM meters INTERVAL(1s, 500a); + ts | sum(current) | +====================================================== + 2018-10-03 14:38:04.500 | 11.189999809 | + 2018-10-03 14:38:05.500 | 31.900000572 | + 2018-10-03 14:38:06.500 | 11.600000000 | + 2018-10-03 14:38:15.500 | 12.300000381 | + 2018-10-03 14:38:16.500 | 35.000000000 | +Query OK, 5 row(s) in set (0.001521s) +``` + +In a scenario of IoT, it is difficult to synchronize the time stamp of collected data at each point, but many analysis algorithms (such as FFT) need to align the collected data strictly at equal intervals of time. In many systems, it’s required to write their own programs to process, but the down sampling operation of TDengine can be easily solved. If there is no collected data in an interval, TDengine also provides interpolation calculation function. + +For details of syntax rules, please refer to the [Time-dimension Aggregation section of TAOS SQL](https://www.taosdata.com/en/documentation/taos-sql#aggregation). \ No newline at end of file diff --git a/documentation20/en/07.advanced-features/docs.md b/documentation20/en/07.advanced-features/docs.md new file mode 100644 index 0000000000000000000000000000000000000000..cebbb4a269047b956359252bbdb71fb1a4ba8ff8 --- /dev/null +++ b/documentation20/en/07.advanced-features/docs.md @@ -0,0 +1,360 @@ +# Advanced Features + +## Continuous Query + +Continuous Query is a query executed by TDengine periodically with a sliding window, it is a simplified stream computing driven by timers. Continuous query can be applied to a table or a STable automatically and periodically, and the result set can be passed to the application directly via call back function, or written into a new table in TDengine. The query is always executed on a specified time window (window size is specified by parameter interval), and this window slides forward while time flows (the sliding period is specified by parameter sliding). + +Continuous query of TDengine adopts time-driven mode, which can be defined directly by TAOS SQL without additional operation. Using continuous query, results can be generated conveniently and quickly according to the time window, thus down sampling the original collected data. After the user defines a continuous query through TAOS SQL, TDengine automatically pulls up the query at the end of the last complete time period and pushes the calculated results to the user or writes them back to TDengine. + +The continuous query provided by TDengine differs from the time window calculation in ordinary stream computing in the following ways: + +- Unlike the real-time feedback calculated results of stream computing, continuous query only starts calculation after the time window is closed. For example, if the time period is 1 day, the results of that day will only be generated after 23:59:59. +- If a history record is written to the time interval that has been calculated, the continuous query will not recalculate and will not push the results to the user again. For the mode of writing back to TDengine, the existing calculated results will not be updated. +- Using the mode of continuous query pushing results, the server does not cache the client's calculation status, nor does it provide Exactly-Once semantic guarantee. If the user's application side crashed, the continuous query pulled up again would only recalculate the latest complete time window from the time pulled up again. If writeback mode is used, TDengine can ensure the validity and continuity of data writeback. + +### How to use continuous query + +The following is an example of the smart meter scenario to introduce the specific use of continuous query. Suppose we create a STables and sub-tables through the following SQL statement: + +```sql +create table meters (ts timestamp, current float, voltage int, phase float) tags (location binary(64), groupdId int); +create table D1001 using meters tags ("Beijing.Chaoyang", 2); +create table D1002 using meters tags ("Beijing.Haidian", 2); +... +``` + +We already know that the average voltage of these meters can be counted with one minute as the time window and 30 seconds as the forward increment through the following SQL statement. + +```sql +select avg(voltage) from meters interval(1m) sliding(30s); +``` + +Every time this statement is executed, all data will be recalculated. If you need to execute every 30 seconds to incrementally calculate the data of the latest minute, you can improve the above statement as following, using a different `startTime` each time and executing it regularly: + +```sql +select avg(voltage) from meters where ts > {startTime} interval(1m) sliding(30s); +``` + +There is no problem with this, but TDengine provides a simpler method, just add `create table {tableName} as` before the initial query statement, for example: + +```sql +create table avg_vol as select avg(voltage) from meters interval(1m) sliding(30s); +``` + +A new table named `avg_vol` will be automatically created, and then every 30 seconds, TDengine will incrementally execute the SQL statement after `as` and write the query result into this table. The user program only needs to query the data from `avg_vol`. For example: + +```mysql +taos> select * from avg_vol; + ts | avg_voltage_ | +=================================================== + 2020-07-29 13:37:30.000 | 222.0000000 | + 2020-07-29 13:38:00.000 | 221.3500000 | + 2020-07-29 13:38:30.000 | 220.1700000 | + 2020-07-29 13:39:00.000 | 223.0800000 | +``` + +It should be noted that the minimum value of the query time window is 10 milliseconds, and there is no upper limit of the time window range. + +In addition, TDengine also supports users to specify the starting and ending times of a continuous query. If the start time is not entered, the continuous query will start from the time window where the first original data is located; If no end time is entered, the continuous query will run permanently; If the user specifies an end time, the continuous query stops running after the system time reaches the specified time. For example, a continuous query created with the following SQL will run for one hour and then automatically stop. + +```mysql +create table avg_vol as select avg(voltage) from meters where ts > now and ts <= now + 1h interval(1m) sliding(30s); +``` + +It should be noted that now in the above example refers to the time when continuous queries are created, not the time when queries are executed, otherwise, queries cannot be stopped automatically. In addition, in order to avoid the problems caused by delayed writing of original data as much as possible, there is a certain delay in the calculation of continuous queries in TDengine. In other words, after a time window has passed, TDengine will not immediately calculate the data of this window, so it will take a while (usually not more than 1 minute) to find the calculation result. + +### Manage the Continuous Query + +Users can view all continuous queries running in the system through the show streams command in the console, and can kill the corresponding continuous queries through the kill stream command. Subsequent versions will provide more finer-grained and convenient continuous query management commands. + +## Publisher/Subscriber + +Based on the natural time-series characteristics of data, the data insert of TDengine is logically consistent with the data publish (pub) of messaging system, which can be regarded as a new record inserted with timestamp in the system. At the same time, TDengine stores data in strict accordance with the monotonous increment of time-series. Essentially, every table in TDengine can be regarded as a standard messaging queue. + +TDengine supports embedded lightweight message subscription and publishment services. Using the API provided by the system, users can subscribe to one or more tables in the database using common query statements. The maintenance of subscription logic and operation status is completed by the client. The client regularly polls the server for whether new records arrive, and the results will be fed back to the client when new records arrive. + +The status of the subscription and publishment services of TDengine is maintained by the client, but not by the TDengine server. Therefore, if the application restarts, it is up to the application to decide from which point of time to obtain the latest data. + +In TDengine, there are three main APIs relevant to subscription: + +```c +taos_subscribe +taos_consume +taos_unsubscribe +``` + +Please refer to the [C/C++ Connector](https://www.taosdata.com/cn/documentation/connector/) for the documentation of these APIs. The following is still a smart meter scenario as an example to introduce their specific usage (please refer to the previous section "Continuous Query" for the structure of STables and sub-tables). The complete sample code can be found [here](https://github.com/taosdata/TDengine/blob/master/tests/examples/c/subscribe.c). + +If we want to be notified and do some process when the current of a smart meter exceeds a certain limit (e.g. 10A), there are two methods: one is to query each sub-table separately, record the timestamp of the last piece of data after each query, and then only query all data after this timestamp: + +```sql +select * from D1001 where ts > {last_timestamp1} and current > 10; +select * from D1002 where ts > {last_timestamp2} and current > 10; +... +``` + +This is indeed feasible, but as the number of meters increases, the number of queries will also increase, and the performance of both the client and the server will be affected, until the system cannot afford it. + +Another method is to query the STable. In this way, no matter how many meters there are, only one query is required: + +```sql +select * from meters where ts > {last_timestamp} and current > 10; +``` + +However, how to choose `last_timestamp` has become a new problem. Because, on the one hand, the time of data generation (the data timestamp) and the time of data storage are generally not the same, and sometimes the deviation is still very large; On the other hand, the time when the data of different meters arrive at TDengine will also vary. Therefore, if we use the timestamp of the data from the slowest meter as `last_timestamp` in the query, we may repeatedly read the data of other meters; If the timestamp of the fastest meter is used, the data of other meters may be missed. + +The subscription function of TDengine provides a thorough solution to the above problem. + +First, use `taos_subscribe` to create a subscription: + +```c +TAOS_SUB* tsub = NULL; +if (async) { +  // create an asynchronized subscription, the callback function will be called every 1s +  tsub = taos_subscribe(taos, restart, topic, sql, subscribe_callback, &blockFetch, 1000); +} else { +  // create an synchronized subscription, need to call 'taos_consume' manually +  tsub = taos_subscribe(taos, restart, topic, sql, NULL, NULL, 0); +} +``` + +Subscriptions in TDengine can be either synchronous or asynchronous, and the above code will decide which method to use based on the value of parameter `async` obtained from the command line. Here, synchronous means that the user program calls `taos_consume` directly to pull data, while asynchronous means that the API calls `taos_consume` in another internal thread, and then gives the pulled data to the callback function `subscribe_callback` for processing. + +Parameter `taos` is an established database connection and has no special requirements in synchronous mode. However, in asynchronous mode, it should be noted that it will not be used by other threads, otherwise it may lead to unpredictable errors, because the callback function is called in the internal thread of the API, while some APIs of TDengine are not thread-safe. + +Parameter `sql` is a query statement in which you can specify filters using where clause. In our example, if you only want to subscribe to data when the current exceeds 10A, you can write as follows: + +```sql +select * from meters where current > 10; +``` + +Note that the starting time is not specified here, so the data of all timers will be read. If you only want to start subscribing from the data one day ago and do not need earlier historical data, you can add a time condition: + +```sql +select * from meters where ts > now - 1d and current > 10; +``` + +The `topic` of the subscription is actually its name, because the subscription function is implemented in the client API, so it is not necessary to ensure that it is globally unique, but it needs to be unique on a client machine. + +If the subscription of name `topic` does not exist, the parameter restart is meaningless; However, if the user program exits after creating this subscription, when it starts again and reuses this `topic`, `restart` will be used to decide whether to read data from scratch or from the previous location. In this example, if `restart` is **true** (non-zero value), the user program will definitely read all the data. However, if this subscription exists before, and some data has been read, and `restart` is **false** (zero), the user program will not read the previously read data. + +The last parameter of `taos_subscribe` is the polling period in milliseconds. In synchronous mode, if the interval between the two calls to `taos_consume` is less than this time, `taos_consume` will block until the interval exceeds this time. In asynchronous mode, this time is the minimum time interval between two calls to the callback function. + +The penultimate parameter of `taos_subscribe` is used by the user program to pass additional parameters to the callback function, which is passed to the callback function as it is without any processing by the subscription API. This parameter is meaningless in sync mode. + +After created, the subscription can consume data. In synchronous mode, the sample code is the following as the `else` section: + +```c +if (async) { +  getchar(); +} else while(1) { +  TAOS_RES* res = taos_consume(tsub); +  if (res == NULL) { +    printf("failed to consume data."); +    break; +  } else { +    print_result(res, blockFetch); +    getchar(); +  } +} +``` + +Here is a **while** loop. Every time the user presses the Enter key, `taos_consume` is called, and the return value of `taos_consume` is the query result set, which is exactly the same as `taos_use_result`. In the example, the code using this result set is the function `print_result`: + +```c +void print_result(TAOS_RES* res, int blockFetch) { +  TAOS_ROW row = NULL; +  int num_fields = taos_num_fields(res); +  TAOS_FIELD* fields = taos_fetch_fields(res); +  int nRows = 0; +  if (blockFetch) { +    nRows = taos_fetch_block(res, &row); +    for (int i = 0; i < nRows; i++) { +      char temp[256]; +      taos_print_row(temp, row + i, fields, num_fields); +      puts(temp); +    } +  } else { +    while ((row = taos_fetch_row(res))) { +      char temp[256]; +      taos_print_row(temp, row, fields, num_fields);puts(temp); +      nRows++; +    } +  } +  printf("%d rows consumed.\n", nRows); +} +``` + +Among them, `taos_print_row` is used to process subscription to data. In our example, it will print out all eligible records. In asynchronous mode, it is simpler to consume subscribed data: + +```c +void subscribe_callback(TAOS_SUB* tsub, TAOS_RES *res, void* param, int code) { +  print_result(res, *(int*)param); +} +``` + +To end a data subscription, you need to call `taos_unsubscribe`: + +```c +taos_unsubscribe(tsub, keep); +``` + +Its second parameter is used to decide whether to keep the progress information of subscription on the client. If this parameter is **false** (zero), the subscription can only be restarted no matter what the `restart` parameter is when `taos_subscribe` is called next time. In addition, progress information is saved in the directory {DataDir}/subscribe/. Each subscription has a file with the same name as its `topic`. Deleting a file will also lead to a new start when the corresponding subscription is created next time. + +After introducing the code, let's take a look at the actual running effect. For exmaple: + +- Sample code has been downloaded locally +- TDengine has been installed on the same machine +- All the databases, STables and sub-tables required by the example have been created + +You can compile and start the sample program by executing the following command in the directory where the sample code is located: + +```shell +$ make +$ ./subscribe -sql='select * from meters where current > 10;' +``` + +After the sample program starts, open another terminal window, and the shell that starts TDengine inserts a data with a current of 12A into **D1001**: + +```shell +$ taos +> use test; +> insert into D1001 values(now, 12, 220, 1); +``` + +At this time, because the current exceeds 10A, you should see that the sample program outputs it to the screen. You can continue to insert some data to observe the output of the sample program. + +### Use data subscription in Java + +The subscription function also provides a Java development interface, as described in [Java Connector](https://www.taosdata.com/cn/documentation/connector/). It should be noted that the Java interface does not provide asynchronous subscription mode at present, but user programs can achieve the same feature by creating TimerTask. + +The following is an example to introduce its specific use. The function it completes is basically the same as the C language example described earlier, and it is also to subscribe to all records with current exceeding 10A in the database. + +#### Prepare data + +```sql +# Create power Database +taos> create database power; +# Switch to the database +taos> use power; +# Create a STable +taos> create table meters(ts timestamp, current float, voltage int, phase int) tags(location binary(64), groupId int); +# Create tables +taos> create table d1001 using meters tags ("Beijing.Chaoyang", 2); +taos> create table d1002 using meters tags ("Beijing.Haidian", 2); +# Insert test data +taos> insert into d1001 values("2020-08-15 12:00:00.000", 12, 220, 1),("2020-08-15 12:10:00.000", 12.3, 220, 2),("2020-08-15 12:20:00.000", 12.2, 220, 1); +taos> insert into d1002 values("2020-08-15 12:00:00.000", 9.9, 220, 1),("2020-08-15 12:10:00.000", 10.3, 220, 1),("2020-08-15 12:20:00.000", 11.2, 220, 1); +# Query all records with current over 10A from STable meters +taos> select * from meters where current > 10; + ts | current | voltage | phase | location | groupid | +=========================================================================================================== + 2020-08-15 12:10:00.000 | 10.30000 | 220 | 1 | Beijing.Haidian | 2 | + 2020-08-15 12:20:00.000 | 11.20000 | 220 | 1 | Beijing.Haidian | 2 | + 2020-08-15 12:00:00.000 | 12.00000 | 220 | 1 | Beijing.Chaoyang | 2 | + 2020-08-15 12:10:00.000 | 12.30000 | 220 | 2 | Beijing.Chaoyang | 2 | + 2020-08-15 12:20:00.000 | 12.20000 | 220 | 1 | Beijing.Chaoyang | 2 | +Query OK, 5 row(s) in set (0.004896s) +``` + +#### Example + +```java +public class SubscribeDemo { + private static final String topic = "topic-meter-current-bg-10"; + private static final String sql = "select * from meters where current > 10"; + + public static void main(String[] args) { + Connection connection = null; + TSDBSubscribe subscribe = null; + + try { + Class.forName("com.taosdata.jdbc.TSDBDriver"); + Properties properties = new Properties(); + properties.setProperty(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8"); + properties.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8"); + String jdbcUrl = "jdbc:TAOS://127.0.0.1:6030/power?user=root&password=taosdata"; + connection = DriverManager.getConnection(jdbcUrl, properties); + subscribe = ((TSDBConnection) connection).subscribe(topic, sql, true); // Create a subscription + int count = 0; + while (count < 10) { + TimeUnit.SECONDS.sleep(1); / Wait 1 second to avoid calling consume too frequently and causing pressure on server + TSDBResultSet resultSet = subscribe.consume(); // 消费数据 + if (resultSet == null) { + continue; + } + ResultSetMetaData metaData = resultSet.getMetaData(); + while (resultSet.next()) { + int columnCount = metaData.getColumnCount(); + for (int i = 1; i <= columnCount; i++) { + System.out.print(metaData.getColumnLabel(i) + ": " + resultSet.getString(i) + "\t"); + } + System.out.println(); + count++; + } + } + } catch (Exception e) { + e.printStackTrace(); + } finally { + try { + if (null != subscribe) + subscribe.close(true); // Close the subscription + if (connection != null) + connection.close(); + } catch (SQLException throwables) { + throwables.printStackTrace(); + } + } + } +} +``` + +Run the sample program. First, it consumes all the historical data that meets the query conditions: + +```shell +# java -jar subscribe.jar + +ts: 1597464000000 current: 12.0 voltage: 220 phase: 1 location: Beijing.Chaoyang groupid : 2 +ts: 1597464600000 current: 12.3 voltage: 220 phase: 2 location: Beijing.Chaoyang groupid : 2 +ts: 1597465200000 current: 12.2 voltage: 220 phase: 1 location: Beijing.Chaoyang groupid : 2 +ts: 1597464600000 current: 10.3 voltage: 220 phase: 1 location: Beijing.Haidian groupid : 2 +ts: 1597465200000 current: 11.2 voltage: 220 phase: 1 location: Beijing.Haidian groupid : 2 +``` + +Then, add a piece of data to the table via taos client: + +```sql +# taos +taos> use power; +taos> insert into d1001 values("2020-08-15 12:40:00.000", 12.4, 220, 1); +``` + +Because the current of this data is greater than 10A, the sample program will consume it: + +```shell +ts: 1597466400000 current: 12.4 voltage: 220 phase: 1 location: Beijing.Chaoyang groupid: 2 +``` + +## Cache + +TDengine adopts a time-driven cache management strategy (First-In-First-Out, FIFO), also known as a write-driven cache management mechanism. This strategy is different from the read-driven data cache mode (Least-Recent-Use, LRU), which directly saves the most recently written data in the system buffer. When the buffer reaches a threshold, the oldest data is written to disk in batches. Generally speaking, for the use of IoT data, users are most concerned about the recently generated data, that is, the current status. TDengine takes full advantage of this feature by storing the most recently arrived (current status) data in the buffer. + +TDengine provides data collection in milliseconds to users through query functions. Saving the recently arrived data directly in buffer can respond to the user's query analysis for the latest piece or batch of data more quickly, and provide faster database query response as a whole. In this way, TDengine can be used as a data buffer by setting appropriate configuration parameters without deploying additional caching systems, which can effectively simplify the system architecture and reduce the operation costs. It should be noted that after the TDengine is restarted, the buffer of the system will be emptied, the previously cached data will be written to disk in batches, and the cached data will not reload the previously cached data into the buffer like some proprietary Key-value cache system. + +TDengine allocates a fixed size of memory space as a buffer, which can be configured according to application requirements and hardware resources. By properly setting the buffer space, TDengine can provide extremely high-performance write and query support. Each virtual node in TDengine is allocated a separate cache pool when it is created. Each virtual node manages its own cache pool, and different virtual nodes do not share the pool. All tables belonging to each virtual node share the cache pool owned by itself. + +TDengine manages the memory pool by blocks, and the data is stored in the form of rows within. The memory pool of a vnode is allocated by blocks when the vnode is created, and each memory block is managed according to the First-In-First-Out strategy. When creating a memory pool, the size of the blocks is determined by the system configuration parameter cache; The number of memory blocks in each vnode is determined by the configuration parameter blocks. So for a vnode, the total memory size is: cache * blocks. A cache block needs to ensure that each table can store at least dozens of records in order to be efficient. + +You can quickly obtain the last record of a table or a STable through the function last_row, which is very convenient to show the real-time status or collected values of each device on a large screen. For example: + +```mysql +select last_row(voltage) from meters where location='Beijing.Chaoyang'; +``` + +This SQL statement will obtain the last recorded voltage value of all smart meters located in Chaoyang District, Beijing. + +## Alert + +In scenarios of TDengine, alarm monitoring is a common requirement. Conceptually, it requires the program to filter out data that meet certain conditions from the data of the latest period of time, and calculate a result according to a defined formula based on these data. When the result meets certain conditions and lasts for a certain period of time, it will notify the user in some form. + +In order to meet the needs of users for alarm monitoring, TDengine provides this function in the form of an independent module. For its installation and use, please refer to the blog [How to Use TDengine for Alarm Monitoring](https://www.taosdata.com/blog/2020/04/14/1438.html). \ No newline at end of file diff --git a/documentation20/en/08.connector/docs.md b/documentation20/en/08.connector/docs.md new file mode 100644 index 0000000000000000000000000000000000000000..d7afd5cfd81e3bed283f1a081d98e615257b9a36 --- /dev/null +++ b/documentation20/en/08.connector/docs.md @@ -0,0 +1,1039 @@ +# Connectors + +TDengine provides many connectors for development, including C/C++, JAVA, Python, RESTful, Go, Node.JS, etc. + +At present, TDengine connectors support a wide range of platforms, including hardware platforms such as X64/X86/ARM64/ARM32/MIPS/Alpha, and development environments such as Linux/Win64/Win32. The comparison matrix is as follows: + +| **CPU** | **X64 64bit** | **X64 64bit** | **X64 64bit** | **X86 32bit** | **ARM64** | **ARM32** | **MIPS Godson** | **Alpha Whenwei** | **X64 TimecomTech** | +| ----------- | ------------- | ------------- | ------------- | ------------- | --------- | --------- | --------------- | ----------------- | ------------------- | +| **OS** | **Linux** | **Win64** | **Win32** | **Win32** | **Linux** | **Linux** | **Linux** | **Linux** | **Linux** | +| **C/C++** | ● | ● | ● | ○ | ● | ● | ○ | ○ | ○ | +| **JDBC** | ● | ● | ● | ○ | ● | ● | ○ | ○ | ○ | +| **Python** | ● | ● | ● | ○ | ● | ● | ○ | -- | ○ | +| **Go** | ● | ● | ● | ○ | ● | ● | ○ | -- | -- | +| **NodeJs** | ● | ● | ○ | ○ | ● | ● | ○ | -- | -- | +| **C#** | ○ | ● | ● | ○ | ○ | ○ | ○ | -- | -- | +| **RESTful** | ● | ● | ● | ● | ● | ● | ○ | ○ | ○ | + +Note: ● stands for that has been verified by official tests; ○ stands for that has been verified by unofficial tests. + +Note: + +- To access the TDengine database through connectors (except RESTful) in the system without TDengine server software, it is necessary to install the corresponding version of the client installation package to make the application driver (the file name is [libtaos.so](http://libtaos.so/) in Linux system and taos.dll in Windows system) installed in the system, otherwise, the error that the corresponding library file cannot be found will occur. +- All APIs that execute SQL statements, such as `tao_query`, `taos_query_a`, `taos_subscribe` in C/C + + Connector, and APIs corresponding to them in other languages, can only execute one SQL statement at a time. If the actual parameters contain multiple statements, their behavior is undefined. +- Users upgrading to TDengine 2.0. 8.0 must update the JDBC connection. TDengine must upgrade taos-jdbcdriver to 2.0.12 and above. +- No matter which programming language connector is selected, TDengine version 2.0 and above recommends that each thread of database application establish an independent connection or establish a connection pool based on threads to avoid mutual interference between threads of "USE statement" state variables in the connection (but query and write operations of the connection are thread-safe). + +## Steps of Connector Driver Installation + +The server should already have the TDengine server package installed. The connector driver installation steps are as follows: + +**Linux** + +**1. Download from TAOS Data website(https://www.taosdata.com/cn/all-downloads/)** + +- X64 hardware environment: TDengine-client-2.x.x.x-Linux-x64.tar.gz +- ARM64 hardware environment: TDengine-client-2.x.x.x-Linux-aarch64.tar.gz +- ARM32 hardware environment: TDengine-client-2.x.x.x-Linux-aarch32.tar.gz + +**2. Unzip the package** + +Place the package in any directory that current user can read/write, and then execute following command: + +`tar -xzvf TDengine-client-xxxxxxxxx.tar.gz` + +Where xxxxxx needs to be replaced with you actual version as a string. + +**3. Execute installation script** + +After extracting the package, you will see the following files (directories) in the extracting directory: + +*install_client. sh*: Installation script for application driver + +*taos.tar.gz*: Application driver installation package + +*driver*: TDengine application driver + +*connector*: Connectors for various programming languages (go/grafanaplugin/nodejs/python/JDBC) + +*Examples*: Sample programs for various programming languages (C/C #/go/JDBC/matlab/python/R) + +Run install_client.sh to install. + +**4. Configure taos.cfg** + +Edit the taos.cfg file (default path/etc/taos/taos.cfg) and change firstEP to End Point of the TDengine server, for example: [h1.taos.com](http://h1.taos.com/):6030. + +**Tip: If no TDengine service deployed in this machine, but only the application driver is installed, only firstEP needs to be configured in taos.cfg, and FQDN does not.** + +**Windows x64/x86** + +- **1. Download from TAOS Data website(https://www.taosdata.com/cn/all-downloads/)** + +- X64 hardware environment: TDengine-client-2.X.X.X-Windows-x64.exe +- X86 hardware environment: TDengine-client-2.X.X.X-Windows-x86.exe + +**2. Execute installation, select default vales as prompted to complete** + +**3. Installatino path** + +Default installation path is: C:\TDengine, with following files(directories): + +*taos.exe*: taos shell command line program + +*cfg*: configuration file directory + +*driver*: application driver dynamic link library + +*examples*: sample program bash/C/C #/go/JDBC/Python/Node.js + +*include*: header file + +*log*: log file + +*unins000. exe*: uninstall program + +**4. Configure taos.cfg** + +Edit the taos.cfg file (default path/etc/taos/taos.cfg) and change firstEP to End Point of the TDengine server, for example: [h1.taos.com](http://h1.taos.com/):6030. + +**Note:** + +**1. If you use FQDN to connect to the server, you must confirm that the DNS of the local network environment has been configured, or add FQDN addressing records in the hosts file. For example, edit C:\ Windows\ system32\ drivers\ etc\ hosts, and add the following record: 192.168. 1.99 [h1.taos.com](http://h1.taos.com/)** + +**2. Uninstall: Run unins000. exe to uninstall the TDengine application driver.** + +**Installation verification** + +After the above installation and configuration completed, and confirm that the TDengine service has started running normally, the taos client can be logged in at this time. + +**Linux environment:** + +If you execute taos directly under Linux shell, you should be able to connect to tdengine service normally and jump to taos shell interface. For Example: + +```mysql +$ taos +Welcome to the TDengine shell from Linux, Client Version:2.0.5.0 +Copyright (c) 2017 by TAOS Data, Inc. All rights reserved. +taos> show databases; +name | created_time | ntables | vgroups | replica | quorum | days | keep1,keep2,keep(D) | cache(MB)| blocks | minrows | maxrows | wallevel | fsync | comp | precision | status | +========================================================================================================================================================================================================================= +test | 2020-10-14 10:35:48.617 | 10 | 1 | 1 | 1 | 2 | 3650,3650,3650 | 16| 6 | 100 | 4096 | 1 | 3000 | 2 | ms | ready | +log | 2020-10-12 09:08:21.651 | 4 | 1 | 1 | 1 | 10 | 30,30,30 | 1| 3 | 100 | 4096 | 1 | 3000 | 2 | us | ready | +Query OK, 2 row(s) in set (0.001198s) +taos> +``` + +**Windows (x64/x86) environment:** + +Under cmd, enter the c:\ tdengine directory and directly execute taos.exe, and you should be able to connect to tdengine service normally and jump to taos shell interface. For example: + +```mysql + C:\TDengine>taos + Welcome to the TDengine shell from Linux, Client Version:2.0.5.0 + Copyright (c) 2017 by TAOS Data, Inc. All rights reserved. + taos> show databases; + name | created_time | ntables | vgroups | replica | quorum | days | keep1,keep2,keep(D) | cache(MB) | blocks | minrows | maxrows | wallevel | fsync | comp | precision | status | + =================================================================================================================================================================================================================================================================== + test | 2020-10-14 10:35:48.617 | 10 | 1 | 1 | 1 | 2 | 3650,3650,3650 | 16 | 6 | 100 | 4096 | 1 | 3000 | 2 | ms | ready | + log | 2020-10-12 09:08:21.651 | 4 | 1 | 1 | 1 | 10 | 30,30,30 | 1 | 3 | 100 | 4096 | 1 | 3000 | 2 | us | ready | + Query OK, 2 row(s) in set (0.045000s) + taos> +``` + +## C/C++ Connector + +**Systems supported by C/C++ connectors as follows:** + +| **CPU Type** | **x64****(****64bit****)** | | | **ARM64** | **ARM32** | +| -------------------- | ---------------------------- | ------- | ------- | --------- | ------------------ | +| **OS Type** | Linux | Win64 | Win32 | Linux | Linux | +| **Supported or Not** | Yes | **Yes** | **Yes** | **Yes** | **In development** | + +The C/C + + API is similar to MySQL's C API. When application use it, it needs to include the TDengine header file taos.h (after installed, it is located in/usr/local/taos/include): + +```C +#include +``` + +Note: + +- The TDengine dynamic library needs to be linked at compiling. The library in Linux is [libtaos.so](http://libtaos.so/), which installed at/usr/local/taos/driver. By Windows, it is taos.dll and installed at C:\ TDengine. +- Unless otherwise specified, when the return value of API is an integer, 0 represents success, others are error codes representing the cause of failure, and when the return value is a pointer, NULL represents failure. + +More sample codes for using C/C++ connectors, please visit https://github.com/taosdata/TDengine/tree/develop/tests/examples/c. + +### Basic API + +The basic API is used to create database connections and provide a runtime environment for the execution of other APIs. + +- `void taos_init()` + +Initialize the running environment. If the application does not actively call the API, the API will be automatically called when the application call taos_connect, so the application generally does not need to call the API manually. + +- `void taos_cleanup()` + +Clean up the running environment and call this API before the application exits. + +- `int taos_options(TSDB_OPTION option, const void * arg, ...)` + +Set client options, currently only time zone setting (_TSDB_OPTIONTIMEZONE) and encoding setting (_TSDB_OPTIONLOCALE) are supported. The time zone and encoding default to the current operating system settings. + +- `char *taos_get_client_info()` + +Get version information of the client. + +- `TAOS *taos_connect(const char *host, const char *user, const char *pass, const char *db, int port)` + +Create a database connection and initialize the connection context. The parameters that need to be provided by user include: + +- - host: FQDN used by TDengine to manage the master node + - user: User name + - pass: Password + - db: Database name. If user does not provide it, it can be connected normally, means user can create a new database through this connection. If user provides a database name, means the user has created the database and the database is used by default + - port: Port number + +A null return value indicates a failure. The application needs to save the returned parameters for subsequent API calls. + +- `char *taos_get_server_info(TAOS *taos)` + +Get version information of the server-side. + +- `int taos_select_db(TAOS *taos, const char *db)` + +Set the current default database to db. + +- `void taos_close(TAOS *taos)` + +Close the connection, where `taos` is the pointer returned by `taos_connect` function. + +### Synchronous query API + +Traditional database operation APIs all make synchronous operations. After the application calls an API, it remains blocked until the server returns the result. TDengine supports the following APIs: + +- `TAOS_RES* taos_query(TAOS *taos, const char *sql)` + +This API is used to execute SQL statements, which can be DQL, DML or DDL statements. Where `taos` parameter is a pointer obtained through `taos_connect`. You can't judge whether the execution result fails by whether the return value is NULL, but to use `taos_errno` function to parse the error code in the result set. + +- `int taos_result_precision(TAOS_RES *res)` + +The precision of the timestamp field in the returned result set, `0` for milliseconds, `1` for microseconds, and `2` for nanoseconds. + +- `TAOS_ROW taos_fetch_row(TAOS_RES *res)` + +Get the data in the query result set by rows. + +- `int taos_fetch_block(TAOS_RES *res, TAOS_ROW *rows)` + +The data in the query result set is obtained in batch, and the return value is the number of rows of the obtained data. + +- `int taos_num_fields(TAOS_RES *res)` 和 `int taos_field_count(TAOS_RES *res)` + +The two APIs are equivalent, and are used to get the number of columns in the query result set. + +- `int* taos_fetch_lengths(TAOS_RES *res)` + +Get the length of each field in the result set. The return value is an array whose length is the number of columns in the result set. + +- `int taos_affected_rows(TAOS_RES *res)` + +Get the number of rows affected by the executed SQL statement. + +- `TAOS_FIELD *taos_fetch_fields(TAOS_RES *res)` + +Get the attributes (data type, name, number of bytes) of each column of data in the query result set, which can be used in conjunction with `taos_num_files` to parse the data of a tuple (one row) returned by `taos_fetch_row`. The structure of `TAOS_FIELD` is as follows: + +```c +typedef struct taosField { + char name[65]; // Column name + uint8_t type; // Data type + int16_t bytes; // Number of bytes +} TAOS_FIELD; +``` + +- `void taos_stop_query(TAOS_RES *res)` + +Stop the execution of a query. + +- `void taos_free_result(TAOS_RES *res)` + +Release the query result set and related resources. After the query is completed, be sure to call the API to release resources, otherwise it may lead to application memory leakage. However, it should also be noted that after releasing resources, if you call functions such as `taos_consume` to obtain query results, it will lead the application to Crash. + +- `char *taos_errstr(TAOS_RES *res)` + +Get the reason why the last API call failed, and the return value is a string. + +- `char *taos_errno(TAOS_RES *res)` + +Get the reason why the last API call failed, and the return value is the error code. + +**Note:** TDengine 2.0 and above recommends that each thread of a database application establish an independent connection or establish a connection pool based on threads. It is not recommended to pass the connection (TAOS\*) structure to different threads for sharing in applications. Query and write operations based on TAOS structure have multithread safety, but state variables such as "USE statement" may interfere with each other among threads. In addition, C connector can dynamically establish new database-oriented connections according to requirements (this process is not visible to users), and it is recommended to call `taos_close` to close the connection only when the program finally exits. + +### Asynchronous query API + +In addition to synchronous API, TDengine also provides higher performance asynchronous call API to handle data insertion and query operations. Under the same software and hardware environment, asynchronous API processes data insertion 2 ~ 4 times faster than synchronous API. Asynchronous API adopts a non-blocking call mode and returns immediately before the system really completes a given database operation. The calling thread can handle other work, thus improving the performance of the whole application. Asynchronous API has outstanding advantages in the case of poor network delay. + +Asynchronous APIs all need applications to provide corresponding callback function. The callback function parameters are set as follows: the first two parameters are consistent, and the third parameter depends on different APIs. The first parameter param is provided to the system when the application calls the asynchronous API. When used for callback, the application can retrieve the context of the specific operation, depending on the specific implementation. The second parameter is the result set of SQL operation. If it is empty, such as insert operation, it means that there is no record returned. If it is not empty, such as select operation, it means that there is record returned. + +Asynchronous APIs have relatively high requirements for users, who can selectively use them according to specific application scenarios. Here are three important asynchronous APIs: + +- `void taos_query_a(TAOS *taos, const char *sql, void (*fp)(void *param, TAOS_RES *, int code), void *param);` + +Execute SQL statement asynchronously. + +- - taos: The database connection returned by calling `taos_connect` + - sql: The SQL statement needed to execute + - fp: User-defined callback function, whose third parameter `code` is used to indicate whether the operation is successful, `0` for success, and negative number for failure (call `taos_errstr` to get the reason for failure). When defining the callback function, it mainly handles the second parameter `TAOS_RES *`, which is the result set returned by the query + - param:the parameter for the callback + +- `void taos_fetch_rows_a(TAOS_RES *res, void (*fp)(void *param, TAOS_RES *, int numOfRows), void *param);` + +Get the result set of asynchronous queries in batch, which can only be used with `taos_query_a`. Within: + +- - res: The result set returned when backcall `taos_query_a` + - fp: Callback function. Its parameter `param` is a user-definable parameter construct passed to the callback function; `numOfRows` is the number of rows of data obtained (not a function of the entire query result set). In the callback function, applications can get each row of the batch records by calling `taos_fetch_rows` forward iteration. After reading all the records in a block, the application needs to continue calling `taos_fetch_rows_a` in the callback function to obtain the next batch of records for processing until the number of records returned (`numOfRows`) is zero (the result is returned) or the number of records is negative (the query fails). + +The asynchronous APIs of TDengine all use non-blocking calling mode. Applications can use multithreading to open multiple tables at the same time, and can query or insert to each open table at the same time. It should be pointed out that the **application client must ensure that the operation on the same table is completely serialized**, that is, when the insertion or query operation on the same table is not completed (when no result returned), the second insertion or query operation cannot be performed. + + + + + +### Parameter binding API + +In addition to calling `taos_query` directly for queries, TDengine also provides a Prepare API that supports parameter binding. Like MySQL, these APIs currently only support using question mark `?` to represent the parameters to be bound, as follows: + +- `TAOS_STMT* taos_stmt_init(TAOS *taos)` + +Create a `TAOS_STMT` object for calling later. + +- `int taos_stmt_prepare(TAOS_STMT *stmt, const char *sql, unsigned long length)` + +Parse a SQL statement and bind the parsing result and parameter information to STMT. If the parameter length is greater than 0, this parameter will be used as the length of the SQL statement. If it is equal to 0, the length of the SQL statement will be automatically judged. + +- `int taos_stmt_bind_param(TAOS_STMT *stmt, TAOS_BIND *bind)` + +For parameter binding, bind points to an array, and it is necessary to ensure that the number and order of elements in this array are exactly the same as the parameters in sql statement. TAOS_BIND is used in the same way as MYSQL_BIND in MySQL and is defined as follows: + +```c +typedef struct TAOS_BIND { + int buffer_type; + void * buffer; + unsigned long buffer_length; // Not in use + unsigned long *length; + int * is_null; + int is_unsigned; // Not in use + int * error; // Not in use +} TAOS_BIND; +``` + +Add the curren bound parameters to the batch. After calling this function, you can call `taos_stmt_bind_param` again to bind the new parameters. It should be noted that this function only supports insert/import statements, and if it is other SQL statements such as select, it will return errors. + +- `int taos_stmt_execute(TAOS_STMT *stmt)` + +Execute the prepared statement. At the moment, a statement can only be executed once. + +- `TAOS_RES* taos_stmt_use_result(TAOS_STMT *stmt)` + +Gets the result set of the statement. The result set is used in the same way as when calling nonparameterized. After using it, `taos_free_result` should be called to release resources. + +- `int taos_stmt_close(TAOS_STMT *stmt)` + +Execution completed, release all resources. + +### Continuous query interface + +TDengine provides time-driven real-time stream computing APIs. You can perform various real-time aggregation calculation operations on tables (data streams) of one or more databases at regular intervals. The operation is simple, only APIs for opening and closing streams. The details are as follows: + +- `TAOS_STREAM *taos_open_stream(TAOS *taos, const char *sql, void (*fp)(void *param, TAOS_RES *, TAOS_ROW row), int64_t stime, void *param, void (*callback)(void *))` + +This API is used to create data streams where: + +- - taos: Database connection established + - sql: SQL query statement (query statement only) + - fp: user-defined callback function pointer. After each stream computing is completed, TDengine passes the query result (TAOS_ROW), query status (TAOS_RES), and user-defined parameters (PARAM) to the callback function. In the callback function, the user can use taos_num_fields to obtain the number of columns in the result set, and taos_fetch_fields to obtain the type of data in each column of the result set. + - stime: The time when stream computing starts. If it is 0, it means starting from now. If it is not zero, it means starting from the specified time (the number of milliseconds from 1970/1/1 UTC time). + - param: It is a parameter provided by the application for callback. During callback, the parameter is provided to the application + - callback: The second callback function is called when the continuous query stop automatically. + +The return value is NULL, indicating creation failed; the return value is not NULL, indicating creation successful. + +- `void taos_close_stream (TAOS_STREAM *tstr)` + +Close the data flow, where the parameter provided is the return value of `taos_open_stream`. When the user stops stream computing, be sure to close the data flow. + +### Data subscription interface + +The subscription API currently supports subscribing to one or more tables and continuously obtaining the latest data written to the tables through regular polling. + +- `TAOS_SUB *taos_subscribe(TAOS* taos, int restart, const char* topic, const char *sql, TAOS_SUBSCRIBE_CALLBACK fp, void *param, int interval)` + +This function is for starting the subscription service, returning the subscription object in case of success, and NULL in case of failure. Its parameters are: + +- - taos: Database connection established + - Restart: If the subscription already exists, do you want to start over or continue with the previous subscription + - Topic: Subject (that is, name) of the subscription. This parameter is the unique identification of the subscription + - sql: The query statement subscribed. This statement can only be a select statement. It should only query the original data, and can only query the data in positive time sequence + - fp: The callback function when the query result is received (the function prototype will be introduced later). It is only used when calling asynchronously, and this parameter should be passed to NULL when calling synchronously + - param: The additional parameter when calling the callback function, which is passed to the callback function as it is by the system API without any processing + - interval: Polling period in milliseconds. During asynchronous call, the callback function will be called periodically according to this parameter; In order to avoid affecting system performance, it is not recommended to set this parameter too small; When calling synchronously, if the interval between two calls to taos_consume is less than this period, the API will block until the interval exceeds this period. + +- `typedef void (*TAOS_SUBSCRIBE_CALLBACK)(TAOS_SUB* tsub, TAOS_RES *res, void* param, int code)` + +In asynchronous mode, the prototype of the callback function has the following parameters: + +- - tsub: Subscription object + - res: Query the result set. Note that there may be no records in the result set + - param: Additional parameters supplied by the client when `taos_subscribe` is called + - code: Error code + +- `TAOS_RES *taos_consume(TAOS_SUB *tsub)` + +In synchronous mode, this function is used to get the results of subscription. The user application places it in a loop. If the interval between two calls to `taos_consume` is less than the polling cycle of the subscription, the API will block until the interval exceeds this cycle. If a new record arrives in the database, the API will return the latest record, otherwise it will return an empty result set with no records. If the return value is NULL, it indicates a system error. In asynchronous mode, user program should not call this API. + +- `void taos_unsubscribe(TAOS_SUB *tsub, int keepProgress)` + +Unsubscribe. If the parameter `keepProgress` is not 0, the API will keep the progress information of subscription, and the subsequent call to `taos_subscribe` can continue based on this progress; otherwise, the progress information will be deleted and the data can only be read again. + +## Python Connector + +See [video tutorials](https://www.taosdata.com/blog/2020/11/11/1963.html) for the use of Python connectors. + +### Installation preparation + +- For application driver installation, please refer to [steps of connector driver installation](https://www.taosdata.com/en/documentation/connector#driver) +- python 2.7 or >= 3.4 installed +- pip or pip3 installed + +### Python client installation + +#### Linux + +Users can find the connector package for python2 and python3 in the source code src/connector/python (or tar.gz/connector/python) folder. Users can install it through `pip` command: + +`pip install src/connector/python/linux/python2/` + +or + + `pip3 install src/connector/python/linux/python3/` + +#### Windows + +With Windows TDengine client installed, copy the file "C:\TDengine\driver\taos.dll" to the "C:\ windows\ system32" directory and enter the Windows cmd command line interface: + +```cmd +cd C:\TDengine\connector\python +python -m pip install . +``` + +- If there is no `pip` command on the machine, the user can copy the taos folder under src/connector/python to the application directory for use. For Windows client, after installing the TDengine Windows client, copy C:\ TDengine\driver\taos.dll to the C:\ windows\ system32 directory. + +### How to use + +#### Code sample + +- Import the TDengine client module + +```python +import taos +``` + +- Get the connection and cursor object + +```python +conn = taos.connect(host="127.0.0.1", user="root", password="taosdata", config="/etc/taos") +c1 = conn.cursor() +``` + +- *host* covers all IPs of TDengine server-side, and *config* is the directory where the client configuration files is located +- Write data + +```python +import datetime + +# Create a database +c1.execute('create database db') +c1.execute('use db') +# Create a table +c1.execute('create table tb (ts timestamp, temperature int, humidity float)') +# Insert data +start_time = datetime.datetime(2019, 11, 1) +affected_rows = c1.execute('insert into tb values (\'%s\', 0, 0.0)' %start_time) +# Insert data in batch +time_interval = datetime.timedelta(seconds=60) +sqlcmd = ['insert into tb values'] +for irow in range(1,11): + start_time += time_interval + sqlcmd.append('(\'%s\', %d, %f)' %(start_time, irow, irow*1.2)) +affected_rows = c1.execute(' '.join(sqlcmd)) +``` + +- Query data + +```python +c1.execute('select * from tb') +# pull query result +data = c1.fetchall() +# The result is a list, with each row as an element +numOfRows = c1.rowcount +numOfCols = len(c1.description) +for irow in range(numOfRows): + print("Row%d: ts=%s, temperature=%d, humidity=%f" %(irow, data[irow][0], data[irow][1],data[irow][2])) + +# Use cursor loop directly to pull query result +c1.execute('select * from tb') +for data in c1: + print("ts=%s, temperature=%d, humidity=%f" %(data[0], data[1],data[2])) +``` + +- Create subscription + +```python +# Create a subscription with the topic ‘test’ and a consumption cycle of 1000 milliseconds +# If the first parameter is True, it means restarting the subscription. If it is False and a subscription with the topic 'test 'has been created before, it means continuing to consume the data of this subscription instead of restarting to consume all the data +sub = conn.subscribe(True, "test", "select * from tb;", 1000) +``` + +- Consume subscription data + +```python +data = sub.consume() +for d in data: + print(d) +``` + +- Unsubscription + +```python +sub.close() +``` + +- Close connection + +```python +c1.close() +conn.close() +``` + +#### Helper + +Users can directly view the usage information of the module through Python's helper, or refer to the sample program in tests/examples/Python. The following are some common classes and methods: + +- *TDengineConnection* class + +Refer to help (taos.TDEngineConnection) in python. This class corresponds to a connection between the client and TDengine. In the scenario of client multithreading, it is recommended that each thread apply for an independent connection instance, but not recommended that multiple threads share a connection. + +- *TDegnineCursor* class + +Refer to help (taos.TDengineCursor) in python. This class corresponds to the write and query operations performed by the client. In the scenario of client multithreading, this cursor instance must be kept exclusive to threads and cannot be used by threads, otherwise errors will occur in the returned results. + +- *connect* method + +Used to generate an instance of taos.TDengineConnection. + +### Python client code sample + +In tests/examples/python, we provide a sample Python program read_example. py to guide you to design your own write and query program. After installing the corresponding client, introduce the taos class through `import taos`. The steps are as follows: + +- Get the `TDengineConnection` object through `taos.connect`, which can be applied for only one by a program and shared among multiple threads. + +- Get a new cursor object through the `.cursor ()` method of the `TDengineConnection` object, which must be guaranteed to be exclusive to each thread. + +- Execute SQL statements for writing or querying through the `execute()` method of the cursor object. + +- If a write statement is executed, `execute` returns the number of rows successfully written affected rows. + +- If the query statement is executed, the result set needs to be pulled through the fetchall method after the execution is successful. + + You can refer to the sample code for specific methods. + +## RESTful Connector + +To support the development of various types of platforms, TDengine provides an API that conforms to REST design standards, that is, RESTful API. In order to minimize the learning cost, different from other designs of database RESTful APIs, TDengine directly requests SQL statements contained in BODY through HTTP POST to operate the database, and only needs a URL. See the [video tutorial](https://www.taosdata.com/blog/2020/11/11/1965.html) for the use of RESTful connectors. + +### HTTP request format + +``` +http://:/rest/sql +``` + +Parameter description: + +- IP: Any host in the cluster +- PORT: httpPort configuration item in the configuration file, defaulting to 6041 + +For example: [http://192.168.0.1](http://192.168.0.1/): 6041/rest/sql is a URL that points to an IP address of 192.168. 0.1. + +The header of HTTP request needs to carry identity authentication information. TDengine supports Basic authentication and custom authentication. Subsequent versions will provide standard and secure digital signature mechanism for identity authentication. + +- Custom identity authentication information is as follows (We will introduce later) + +``` +Authorization: Taosd +``` + +- Basic identity authentication information is as follows + +``` +Authorization: Basic +``` + +The BODY of HTTP request is a complete SQL statement. The data table in the SQL statement should provide a database prefix, such as \.\. If the table name does not have a database prefix, the system returns an error. Because the HTTP module is just a simple forwarding, there is no current DB concept. + +Use curl to initiate an HTTP Request through custom authentication. The syntax is as follows: + +```bash +curl -H 'Authorization: Basic ' -d '' :/rest/sql +``` + +or + +```bash +curl -u username:password -d '' :/rest/sql +``` + +Where `TOKEN` is the string of `{username}:{password}` encoded by Base64, for example, `root:taosdata` will be encoded as `cm9vdDp0YW9zZGF0YQ==`. + +### HTTP return format + +The return value is in JSON format, as follows: + +```json +{ + "status": "succ", + "head": ["ts","current", …], + "column_meta": [["ts",9,8],["current",6,4], …], + "data": [ + ["2018-10-03 14:38:05.000", 10.3, …], + ["2018-10-03 14:38:15.000", 12.6, …] + ], + "rows": 2 +} +``` + +Description: + +- status: Informs whether the operation results are successful or failed. +- head: The definition of the table, with only one column "affected_rows" if no result set is returned. (Starting from version 2.0. 17, it is recommended not to rely on the head return value to judge the data column type, but to use column_meta. In future versions, head may be removed from the return value.) +- column_meta: Starting with version 2.0. 17, this item is added to the return value to indicate the data type of each column in the data. Each column will be described by three values: column name, column type and type length. For example, ["current", 6, 4] means that the column name is "current"; the column type is 6, that is, float type; the type length is 4, which corresponds to a float represented by 4 bytes. If the column type is binary or nchar, the type length indicates the maximum content length that the column can save, rather than the specific data length in this return value. When the column type is nchar, its type length indicates the number of Unicode characters that can be saved, not bytes. +- data: The specific returned data, rendered line by line, if no result set is returned, then only [[affected_rows]]. The order of the data columns for each row in data is exactly the same as the order of the data columns described in column_meta. +- rows: Indicates the total number of rows of data. + +Column types in column_meta: + +- 1:BOOL +- 2:TINYINT +- 3:SMALLINT +- 4:INT +- 5:BIGINT +- 6:FLOAT +- 7:DOUBLE +- 8:BINARY +- 9:TIMESTAMP +- 10:NCHAR + +### Custom authorization code + +The HTTP request requires the authorization code `` for identification. Authorization codes are usually provided by administrators. Authorization codes can be obtained simply by sending `HTTP GET` requests as follows: + +```bash +curl http://:6041/rest/login// +``` + +Where `ip` is the IP address of the TDengine database, `username` is the database user name, `password` is the database password, and the return value is in `JSON` format. The meanings of each field are as follows: + +- status: flag bit for request result +- code: code of return value +- desc: Authorization code + +Sample to get authorization code: + +```bash +curl http://192.168.0.1:6041/rest/login/root/taosdata +``` + +Return value: + +```json +{ + "status": "succ", + "code": 0, + "desc": "/KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04" +} +``` + +### Use case + +- Lookup all records of table d1001 in demo database: + +```bash +curl -H 'Authorization: Basic cm9vdDp0YW9zZGF0YQ==' -d 'select * from demo.d1001' 192.168.0.1:6041/rest/sql +``` + +Return value: + +```json +{ + "status": "succ", + "head": ["ts","current","voltage","phase"], + "column_meta": [["ts",9,8],["current",6,4],["voltage",4,4],["phase",6,4]], + "data": [ + ["2018-10-03 14:38:05.000",10.3,219,0.31], + ["2018-10-03 14:38:15.000",12.6,218,0.33] + ], + "rows": 2 +} +``` + +- Craete a database demo: + +```bash +curl -H 'Authorization: Basic cm9vdDp0YW9zZGF0YQ==' -d 'create database demo' 192.168.0.1:6041/rest/sql +``` + +Return value: + +```json +{ + "status": "succ", + "head": ["affected_rows"], + "column_meta": [["affected_rows",4,4]], + "data": [[1]], + "rows": 1 +} +``` + +### Other cases + +### Result set in Unix timestamp + +When the HTTP request URL is sqlt, the timestamp of the returned result set will be expressed in Unix timestamp format, for example: + +```bash +curl -H 'Authorization: Basic cm9vdDp0YW9zZGF0YQ==' -d 'select * from demo.d1001' 192.168.0.1:6041/rest/sqlt +``` + +Return value: + +```json +{ + "status": "succ", + "head": ["ts","current","voltage","phase"], + "column_meta": [["ts",9,8],["current",6,4],["voltage",4,4],["phase",6,4]], + "data": [ + [1538548685000,10.3,219,0.31], + [1538548695000,12.6,218,0.33] + ], + "rows": 2 +} +``` + +#### Result set in UTC time string + +When the HTTP request URL is `sqlutc`, the timestamp of the returned result set will be represented by a UTC time string, for example: + +```bash + curl -H 'Authorization: Basic cm9vdDp0YW9zZGF0YQ==' -d 'select * from demo.t1' 192.168.0.1:6041/rest/sqlutc +``` + +Return value: + +```json +{ + "status": "succ", + "head": ["ts","current","voltage","phase"], + "column_meta": [["ts",9,8],["current",6,4],["voltage",4,4],["phase",6,4]], + "data": [ + ["2018-10-03T14:38:05.000+0800",10.3,219,0.31], + ["2018-10-03T14:38:15.000+0800",12.6,218,0.33] + ], + "rows": 2 +} +``` + +### Important configuration options + +Only some configuration parameters related to RESTful interface are listed below. Please refer to the instructions in the configuration file for other system parameters. Note: After the configuration is modified, the taosd service needs to be restarted before it can take effect. + +- httpPort: The port number that provides RESTful services externally, which is bound to 6041 by default +- httpMaxThreads: The number of threads started, the default is 2 (starting with version 2.0. 17, the default value is changed to half of the CPU cores and rounded down) +- restfulRowLimit: The maximum number of result sets returned (in JSON format), default 10240 +- httpEnableCompress: Compression is not supported by default. Currently, TDengine only supports gzip compression format +- httpdebugflag: Logging switch, 131: error and alarm information only, 135: debugging information, 143: very detailed debugging information, default 131 + + + +## CSharp Connector + +The C # connector supports: Linux 64/Windows x64/Windows x86. + +### Installation preparation + +- For application driver installation, please refer to the[ steps of installing connector driver](https://www.taosdata.com/en/documentation/connector#driver). +- . NET interface file TDengineDrivercs.cs and reference sample TDengineTest.cs are both located in the Windows client install_directory/examples/C# directory. +- On Windows, C # applications can use the native C interface of TDengine to perform all database operations, and future versions will provide the ORM (dapper) framework driver. + +### Installation verification + +Run install_directory/examples/C#/C#Checker/C#Checker.exe + +```cmd +cd {install_directory}/examples/C#/C#Checker +csc /optimize *.cs +C#Checker.exe -h +``` + +### How to use C# connector + +On Windows system, .NET applications can use the .NET interface of TDengine to perform all database operations. The steps to use it are as follows: + +1. Add the. NET interface file TDengineDrivercs.cs to the .NET project where the application is located. +2. Users can refer to TDengineTest.cs to define database connection parameters and how to perform data insert, query and other operations; + +This. NET interface requires the taos.dll file, so before executing the application, copy the taos.dll file in the Windows client install_directory/driver directory to the folder where the. NET project finally generated the .exe executable file. After running the exe file, you can access the TDengine database and do operations such as insert and query. + +**Note:** + +1. TDengine V2.0. 3.0 supports both 32-bit and 64-bit Windows systems, so when. NET project generates a .exe file, please select the corresponding "X86" or "x64" for the "Platform" under "Solution"/"Project". +2. This. NET interface has been verified in Visual Studio 2015/2017, and other VS versions have yet to be verified. + +### Third-party Driver + +Maikebing.Data.Taos is an ADO.Net provider for TDengine that supports Linux, Windows. This development package is provided by enthusiastic contributor 麦壳饼@@maikebing. For more details: + +``` +// Download +https://github.com/maikebing/Maikebing.EntityFrameworkCore.Taos +// How to use +https://www.taosdata.com/blog/2020/11/02/1901.html +``` + +## Go Connector + +### Installation preparation + +- For application driver installation, please refer to the [steps of installing connector driver](https://www.taosdata.com/en/documentation/connector#driver). + +The TDengine provides the GO driver taosSql. taosSql implements the GO language's built-in interface database/sql/driver. Users can access TDengine in the application by simply importing the package as follows, see https://github.com/taosdata/driver-go/blob/develop/taosSql/driver_test.go for details. + +Sample code for using the Go connector can be found in https://github.com/taosdata/TDengine/tree/develop/tests/examples/go and the [video tutorial](https://www.taosdata.com/blog/2020/11/11/1951.html). + +```Go +import ( + "database/sql" + _ "github.com/taosdata/driver-go/taosSql" +) +``` + +**It is recommended to use Go version 1.13 or above and turn on module support:** + +```bash +go env -w GO111MODULE=on +go env -w GOPROXY=https://goproxy.io,direct +``` + +### Common APIs + +- `sql.Open(DRIVER_NAME string, dataSourceName string) *DB` + +This API is used to open DB and return an object of type \* DB. Generally, DRIVER_NAME is set to the string `taosSql`, and dataSourceName is set to the string `user:password@/tcp(host:port)/dbname`. If the customer wants to access TDengine with multiple goroutines concurrently, it is necessary to create a `sql.Open` object in each goroutine and use it to access TDengine. + +**Note**: When the API is successfully created, there is no permission check. Only when Query or Exec is actually executed can the connection be truly created and whether the user/password/host/port is legal can be checked at the same time. In addition, because most of the implementation of the whole driver sinks into libtaos, which taosSql depends on. Therefore, sql.Open itself is particularly lightweight. + +- `func (db *DB) Exec(query string, args ...interface{}) (Result, error)` + +`sql.Open` built-in method to execute non-query related SQL + +- `func (db *DB) Query(query string, args ...interface{}) (*Rows, error)` + +`sql.Open` built-in method used to execute query statements + +- `func (db *DB) Prepare(query string) (*Stmt, error)` + +`sql.Open` built-in method used to create a prepared statement for later queries or executions. + +- `func (s *Stmt) Exec(args ...interface{}) (Result, error)` + +`sql.Open` built-in method to execute a prepared statement with the given arguments and returns a Result summarizing the effect of the statement. + +- `func (s *Stmt) Query(args ...interface{}) (*Rows, error)` + +`sql.Open` built-in method to query executes a prepared query statement with the given arguments and returns the query results as a \*Rows. + +- `func (s *Stmt) Close() error` + +`sql.Open` built-in method to closes the statement. + +## Node.js Connector + +The Node.js connector supports the following systems: + +| **CPU Type** | **x64****(****64bit****)** | | | **aarch64** | **aarch32** | +| -------------------- | ---------------------------- | ------- | ------- | ----------- | ----------- | +| **OS Type** | Linux | Win64 | Win32 | Linux | Linux | +| **Supported or Not** | **Yes** | **Yes** | **Yes** | **Yes** | **Yes** | + +See the [video tutorial](https://www.taosdata.com/blog/2020/11/11/1957.html) for use of the Node.js connector. + +### Installation preparation + +- For application driver installation, please refer to the [steps of installing connector driver](https://www.taosdata.com/en/documentation/connector#driver). + +### Install Node.js connector + +Users can install it through [npm](https://www.npmjs.com/) or through the source code src/connector/nodejs/. The specific installation steps are as follows: + +First, install the node.js connector through [npm](https://www.npmjs.com/). + +```bash +npm install td2.0-connector +``` + +We recommend that use npm to install the node.js connector. If you do not have npm installed, you can copy src/connector/nodejs/ to your nodejs project directory. + +We use [node-gyp](https://github.com/nodejs/node-gyp) to interact with the TDengine server. Before installing the node.js connector, you also need to install the following software: + +### Linux + +- python (recommended v2.7, not currently supported in v3.x.x) +- node 2.0. 6 supports v12. x and v10. x, 2.0. 5 and earlier supports v10. x, and other versions may have package compatibility issues. +- make +- [GCC](https://gcc.gnu.org/) and other C compilers + +### Windows + +#### Solution 1 + +Use Microsoft [windows-build-tools](https://github.com/felixrieseberg/windows-build-tools) to install all necessary tools by executing npm install --global --production windows-build-tools in cmd command line interface. + +#### Solution 2 + +Mannually install the following tools: + +- Install Visual Studio related tools: [Visual Studio Build Tools](https://visualstudio.microsoft.com/thank-you-downloading-visual-studio/?sku=BuildTools) or [Visual Studio 2017 Community](https://visualstudio.microsoft.com/pl/thank-you-downloading-visual-studio/?sku=Community) +- Install [Python](https://www.python.org/downloads/) 2.7 (not supported in v3.x.x) and execute npm config set python python2.7 +- Open `cmd`, `npm config set msvs_version 2017` + +If the steps above cannot be performed successfully, you can refer to Microsoft's Node.js User Manual [Microsoft's Node.js Guidelines for Windows](https://github.com/Microsoft/nodejs-guidelines/blob/master/windows-environment.md#compiling-native-addon-modules). + +If you use ARM64 Node.js on Windows 10 ARM, you also need to add "Visual C + + compilers and libraries for ARM64" and "Visual C + + ATL for ARM64". + +#### Sample + +The sample program source code is located in install_directory/examples/nodejs, and there are: + +Node-example.js node.js sample source code Node-example-raw. js + +### Installation verification + +After installing the TDengine client, the nodejsChecker.js program can verify whether the current environment supports access to TDengine via nodejs. + +Steps: + +1. Create a new installation verification directory, for example: ~/tdengine-test, copy the nodejsChecker.js source program on github. Download address: (https://github.com/taosdata/TDengine/tree/develop/tests/examples/nodejs/nodejsChecker.js). + +2. Execute the following command: + + ```bash + npm init -y + npm install td2.0-connector + node nodejsChecker.js host=localhost + ``` + +3. After performing the above steps, the nodejs connection Tdengine instance will be outputted on the command line, and the short-answer of insertion and query will be executed. + +### How to use Node.js + +The following are some basic uses of node.js connector. Please refer to [TDengine Node.js connector](http://docs.taosdata.com/node) for details. + +### Create connection + +When using the node.js connector, you must execute require `td2.0-connector`, and then use the `taos.connect` function. The parameter that `taos.connect` function must provide is `host`, and other parameters will use the following default values if they are not provided. Finally, the `cursor` needs to be initialized to communicate with the TDengine server-side. + +```javascript +const taos = require('td2.0-connector'); +var conn = taos.connect({host:"127.0.0.1", user:"root", password:"taosdata", config:"/etc/taos",port:0}) +var cursor = conn.cursor(); // Initializing a new cursor +``` + +To close the connect: + +```javascript +conn.close(); +``` + +#### To execute SQL and insert data + +For DDL statements (such as `create database`, `create table`, `use`, and so on), you can use the `execute` method of `cursor`. The code is as follows: + +```js +cursor.execute('create database if not exists test;') +``` + +The above code creates a database named test. For DDL statements, there is generally no return value, and the execute return value of `cursor` is 0. + +For Insert statements, the code is as follows: + +```js +var affectRows = cursor.execute('insert into test.weather values(now, 22.3, 34);') +``` + +The return value of the execute method is the number of rows affected by the statement. If the sql above inserts a piece of data into the weather table of the test database, the return value affectRows is 1. + +TDengine does not currently support update and delete statements. + +#### Query + +You can query the database through `cursor.query` function. + +```javascript +var query = cursor.query('show databases;') +``` + +The results of the query can be obtained and printed through `query.execute()` function: + +```javascript +var promise = query.execute(); +promise.then(function(result) { + result.pretty(); +}); +``` + +You can also use the `bind` method of `query` to format query statements. For example: `query` automatically fills the `?` with the value provided in the query statement . + +```javascript +var query = cursor.query('select * from meterinfo.meters where ts <= ? and areaid = ?;').bind(new Date(), 5); +query.execute().then(function(result) { + result.pretty(); +}) +``` + +If you provide the second parameter in the `query` statement and set it to `true`, you can also get the query results immediately. As follows: + +```javascript +var promise = cursor.query('select * from meterinfo.meters where v1 = 30;', true) +promise.then(function(result) { + result.pretty(); +}) +``` + +#### Asynchronous function + +The operation of asynchronous query database is similar to the above, only by adding `_a` after `cursor.execute`, `TaosQuery.execute` and other functions. + +```javascript +var promise1 = cursor.query('select count(*), avg(v1), avg(v2) from meter1;').execute_a() +var promise2 = cursor.query('select count(*), avg(v1), avg(v2) from meter2;').execute_a(); +promise1.then(function(result) { + result.pretty(); +}) +promise2.then(function(result) { + result.pretty(); +}) +``` + +### Example + +[node-example.js](https://github.com/taosdata/TDengine/tree/master/tests/examples/nodejs/node-example.js) provides a code example that uses the NodeJS connector to create a table, insert weather data, and query the inserted data. + +[node-example-raw.js](https://github.com/taosdata/TDengine/tree/master/tests/examples/nodejs/node-example-raw.js) is also a code example that uses the NodeJS connector to create a table, insert weather data, and query the inserted data, but unlike the above, this example only uses cursor. \ No newline at end of file diff --git a/documentation20/en/09.connections/docs.md b/documentation20/en/09.connections/docs.md new file mode 100644 index 0000000000000000000000000000000000000000..93633ea369202200d04310fba0af7da8b67d48f5 --- /dev/null +++ b/documentation20/en/09.connections/docs.md @@ -0,0 +1,157 @@ +# Connections with Other Tools + +## Grafana + +TDengine can quickly integrate with [Grafana](https://www.grafana.com/), an open source data visualization system, to build a data monitoring and alarming system. The whole process does not require any code to write. The contents of the data table in TDengine can be visually showed on DashBoard. + +### Install Grafana + +TDengine currently supports Grafana 5.2.4 and above. You can download and install the package from Grafana website according to the current operating system. The download address is as follows: + +https://grafana.com/grafana/download. + +### Configure Grafana + +TDengine Grafana plugin is in the /usr/local/taos/connector/grafanaplugin directory. + +Taking Centos 7.2 as an example, just copy grafanaplugin directory to /var/lib/grafana/plugins directory and restart Grafana. + +```bash +sudo cp -rf /usr/local/taos/connector/grafanaplugin /var/lib/grafana/plugins/tdengine +``` + +### Use Grafana + +#### Configure data source + +You can log in the Grafana server (username/password:admin/admin) through localhost:3000, and add data sources through `Configuration -> Data Sources` on the left panel, as shown in the following figure: + +![img](page://images/connections/add_datasource1.jpg) + +Click `Add data source` to enter the Add Data Source page, and enter TDengine in the query box to select Add, as shown in the following figure: + +![img](page://images/connections/add_datasource2.jpg) + +Enter the data source configuration page and modify the corresponding configuration according to the default prompt: + +![img](page://images/connections/add_datasource3.jpg) + +- Host: IP address of any server in TDengine cluster and port number of TDengine RESTful interface (6041), default [http://localhost:6041](http://localhost:6041/) +- User: TDengine username. +- Password: TDengine user password. + +Click `Save & Test` to test. Success will be prompted as follows: + +![img](page://images/connections/add_datasource4.jpg) + +#### Create Dashboard + +Go back to the home to create Dashboard, and click `Add Query` to enter the panel query page: + +![img](page://images/connections/create_dashboard1.jpg) + +As shown in the figure above, select the TDengine data source in Query, and enter the corresponding sql in the query box below to query. Details are as follows: + +- INPUT SQL: Enter the statement to query (the result set of the SQL statement should be two columns and multiple rows), for example: `select avg(mem_system) from log.dn where ts >= $from and ts < $to interval($interval)` , where `from`, `to` and `interval` are built-in variables of the TDengine plug-in, representing the query range and time interval obtained from the Grafana plug-in panel. In addition to built-in variables, it is also supported to use custom template variables. +- ALIAS BY: You can set alias for the current queries. +- GENERATE SQL: Clicking this button will automatically replace the corresponding variable and generate the final statement to execute. + +According to the default prompt, query the average system memory usage at the specified interval of the server where the current TDengine deployed in as follows: + +![img](page://images/connections/create_dashboard2.jpg) + +> Please refer to Grafana [documents](https://grafana.com/docs/) for how to use Grafana to create the corresponding monitoring interface and for more about Grafana usage. + +#### Import Dashboard + +A `tdengine-grafana.json` importable dashboard is provided under the Grafana plug-in directory/usr/local/taos/connector/grafana/tdengine/dashboard/. + +Click the `Import` button on the left panel and upload the `tdengine-grafana.json` file: + +![img](page://images/connections/import_dashboard1.jpg) + +You can see as follows after Dashboard imported. + +![img](page://images/connections/import_dashboard2.jpg) + +## Matlab + +MatLab can access data to the local workspace by connecting directly to the TDengine via the JDBC Driver provided in the installation package. + +### JDBC Interface Adaptation of MatLab + +Several steps are required to adapt Matlab to TDengine. Taking adapting Matlab2017a on Windows10 as an example: + +- Copy the file JDBCDriver-1.0.0-dist.ja*r* in TDengine package to the directory ${matlab_root}\MATLAB\R2017a\java\jar\toolbox +- Copy the file taos.lib in TDengine package to ${matlab root dir}\MATLAB\R2017a\lib\win64 +- Add the .jar package just copied to the Matlab classpath. Append the line below as the end of the file of ${matlab root dir}\MATLAB\R2017a\toolbox\local\classpath.txt +- ``` + $matlabroot/java/jar/toolbox/JDBCDriver-1.0.0-dist.jar + ``` + +- Create a file called javalibrarypath.txt in directory ${user_home}\AppData\Roaming\MathWorks\MATLAB\R2017a_, and add the _taos.dll path in the file. For example, if the file taos.dll is in the directory of C:\Windows\System32,then add the following line in file javalibrarypath.txt: +- ``` + C:\Windows\System32 + ``` + +- ### Connect to TDengine in MatLab to get data + +After the above configured successfully, open MatLab. + +- Create a connection: + +```matlab +conn = database(‘db’, ‘root’, ‘taosdata’, ‘com.taosdata.jdbc.TSDBDriver’, ‘jdbc:TSDB://127.0.0.1:0/’) +``` + +* Make a query: + +```matlab +sql0 = [‘select * from tb’] +data = select(conn, sql0); +``` + +* Insert a record: + +```matlab +sql1 = [‘insert into tb values (now, 1)’] +exec(conn, sql1) +``` + +For more detailed examples, please refer to the examples\Matlab\TDEngineDemo.m file in the package. + +## R + +R language supports connection to the TDengine database through the JDBC interface. First, you need to install the JDBC package of R language. Launch the R language environment, and then execute the following command to install the JDBC support library for R language: + +```R +install.packages('RJDBC', repos='http://cran.us.r-project.org') +``` + +After installed, load the RJDBC package by executing `library('RJDBC')` command. + +Then load the TDengine JDBC driver: + +```R +drv<-JDBC("com.taosdata.jdbc.TSDBDriver","JDBCDriver-2.0.0-dist.jar", identifier.quote="\"") +``` + +If succeed, no error message will display. Then use the following command to try a database connection: + +```R +conn<-dbConnect(drv,"jdbc:TSDB://192.168.0.1:0/?user=root&password=taosdata","root","taosdata") +``` + +Please replace the IP address in the command above to the correct one. If no error message is shown, then the connection is established successfully, otherwise the connection command needs to be adjusted according to the error prompt. TDengine supports below functions in *RJDBC* package: + +- `dbWriteTable(conn, "test", iris, overwrite=FALSE, append=TRUE)`: Write the data in a data frame iris to the table test in the TDengine server. Parameter overwrite must be false. append must be TRUE and the schema of the data frame iris should be the same as the table test. +- `dbGetQuery(conn, "select count(*) from test")`: run a query command +- `dbSendUpdate (conn, "use db")`: Execute any non-query sql statement. For example, `dbSendUpdate (conn, "use db")`, write data `dbSendUpdate (conn, "insert into t1 values (now, 99)")`, and the like. +- `dbReadTable(conn, "test")`: read all the data in table test +- `dbDisconnect(conn)`: close a connection +- `dbRemoveTable(conn, "test")`: remove table test + +The functions below are not supported currently: + +- `dbExistsTable(conn, "test")`: if table test exists +- `dbListTables(conn)`: list all tables in the connection \ No newline at end of file diff --git a/documentation20/en/10.cluster/docs.md b/documentation20/en/10.cluster/docs.md new file mode 100644 index 0000000000000000000000000000000000000000..87c62e8e9891b06a071500009f0acf3075f6c3b4 --- /dev/null +++ b/documentation20/en/10.cluster/docs.md @@ -0,0 +1,235 @@ +# Installation and Management of TDengine Cluster + +Multiple TDengine servers, that is, multiple running instances of taosd, can form a cluster to ensure the highly reliable operation of TDengine and provide scale-out features. To understand cluster management in TDengine 2.0, it is necessary to understand the basic concepts of clustering. Please refer to the chapter "Overall Architecture of TDengine 2.0". And before installing the cluster, please follow the chapter ["Getting started"](https://www.taosdata.com/en/documentation/getting-started/) to install and experience the single node function. + +Each data node of the cluster is uniquely identified by End Point, which is composed of FQDN (Fully Qualified Domain Name) plus Port, such as [h1.taosdata.com](http://h1.taosdata.com/):6030. The general FQDN is the hostname of the server, which can be obtained through the Linux command `hostname -f` (how to configure FQDN, please refer to: [All about FQDN of TDengine](https://www.taosdata.com/blog/2020/09/11/1824.html)). Port is the external service port number of this data node. The default is 6030, but it can be modified by configuring the parameter serverPort in taos.cfg. A physical node may be configured with multiple hostnames, and TDengine will automatically get the first one, but it can also be specified through the configuration parameter fqdn in taos.cfg. If you are accustomed to direct IP address access, you can set the parameter fqdn to the IP address of this node. + +The cluster management of TDengine is extremely simple. Except for manual intervention in adding and deleting nodes, all other tasks are completed automatically, thus minimizing the workload of operation. This chapter describes the operations of cluster management in detail. + +Please refer to the [video tutorial](https://www.taosdata.com/blog/2020/11/11/1961.html) for cluster building. + +## Preparation + +**Step 0:** Plan FQDN of all physical nodes in the cluster, and add the planned FQDN to /etc/hostname of each physical node respectively; modify the /etc/hosts of each physical node, and add the corresponding IP and FQDN of all cluster physical nodes. [If DNS is deployed, contact your network administrator to configure it on DNS] + +**Step 1:** If the physical nodes have previous test data, installed with version 1. x, or installed with other versions of TDengine, please delete it first and drop all data. For specific steps, please refer to the blog "[Installation and Uninstallation of Various Packages of TDengine](https://www.taosdata.com/blog/2019/08/09/566.html)" + +**Note 1:** Because the information of FQDN will be written into a file, if FQDN has not been configured or changed before, and TDengine has been started, be sure to clean up the previous data (`rm -rf /var/lib/taos/*`)on the premise of ensuring that the data is useless or backed up; + +**Note 2:** The client also needs to be configured to ensure that it can correctly parse the FQDN configuration of each node, whether through DNS service or Host file. + +**Step 2:** It is recommended to close the firewall of all physical nodes, and at least ensure that the TCP and UDP ports of ports 6030-6042 are open. It is **strongly recommended** to close the firewall first and configure the ports after the cluster is built; + +**Step 3:** Install TDengine on all physical nodes, and the version must be consistent, **but do not start taosd**. During installation, when prompted to enter whether to join an existing TDengine cluster, press enter for the first physical node directly to create a new cluster, and enter the FQDN: port number (default 6030) of any online physical node in the cluster for the subsequent physical nodes; + +**Step 4:** Check the network settings of all data nodes and the physical nodes where the application is located: + +1. Execute command `hostname -f` on each physical node, and check and confirm that the hostnames of all nodes are different (the node where the application driver is located does not need to do this check). +2. Execute `ping host` on each physical node, wherein host is that hostname of other physical node, and see if other physical nodes can be communicated to; if not, you need to check the network settings, or the /etc/hosts file (the default path for Windows systems is C:\ Windows\ system32\ drivers\ etc\ hosts), or the configuration of DNS. If it fails to ping, then we cann't build the cluster. +3. From the physical node where the application runs, ping the data node where taosd runs. If the ping fails, the application cannot connect to taosd. Please check the DNS settings or hosts file of the physical node where the application is located; +4. The End Point of each data node is the output hostname plus the port number, for example, [h1.taosdata.com](http://h1.taosdata.com/): 6030 + +**Step 5:** Modify the TDengine configuration file (the file/etc/taos/taos.cfg for all nodes needs to be modified). Assume that the first data node End Point to be started is [h1.taosdata.com](http://h1.taosdata.com/): 6030, and its parameters related to cluster configuration are as follows: + +``` +// firstEp is the first data node connected after each data node’s first launch +firstEp h1.taosdata.com:6030 +// Must configure it as the FQDN of this data node. If this machine has only one hostname, you can comment out this configuration +fqdn h1.taosdata.com +// Configure the port number of this data node, the default is 6030 +serverPort 6030 +// For application scenarios, please refer to the section “Use of Arbitrator” +arbitrator ha.taosdata.com:6042 +``` + +The parameters that must be modified are firstEp and fqdn. At each data node, every firstEp needs to be configured to be the same, **but fqdn must be configured to the value of the data node where it is located**. Other parameters may not be modified unless you have clear reasons. + +**The data node dnode added to the cluster must be exactly the same as the 11 parameters in the following table related to the cluster, otherwise it cannot be successfully added to the cluster.** + + + +| **#** | **Configuration Parameter Name** | **Description** | +| ----- | -------------------------------- | ------------------------------------------------------------ | +| 1 | numOfMnodes | Number of management nodes in system | +| 2 | mnodeEqualVnodeNum | A mnode equals to the number of vnodes consumed | +| 3 | offlineThreshold | Offline threshold of dnode to judge if the dnode is offline | +| 4 | statusInterval | The interval for dnode to report its status to mnode | +| 5 | arbitrator | The end point of the arbitrator in system | +| 6 | timezone | Time zone | +| 7 | locale | Location information and coding format of system | +| 8 | charset | Character set encoding | +| 9 | balance | Whether to start load balancing | +| 10 | maxTablesPerVnode | The maximum number of tables that can be created in each vnode | +| 11 | maxVgroupsPerDb | The maximum number of vgroups that can be used per DB | + +## Launch the First Data Node + +Follow the instructions in "[Getting started](https://www.taosdata.com/en/documentation/getting-started/)", launch the first data node, such as [h1.taosdata.com](http://h1.taosdata.com/), then execute taos, start the taos shell, and execute command "show dnodes" from the shell; ", as follows: + +``` +Welcome to the TDengine shell from Linux, Client Version:2.0.0.0 +Copyright (c) 2017 by TAOS Data, Inc. All rights reserved. + +taos> show dnodes; + id | end_point | vnodes | cores | status | role | create_time | +===================================================================================== + 1 | h1.taos.com:6030 | 0 | 2 | ready | any | 2020-07-31 03:49:29.202 | +Query OK, 1 row(s) in set (0.006385s) + +taos> +``` + +In the above command, you can see that the End Point of the newly launched data node is: [h1.taos.com](http://h1.taos.com/): 6030, which is the firstEP of the new cluster. + +## Launch Subsequent Data Nodes + +To add subsequent data nodes to the existing cluster, there are the following steps: + +1. Start taosd at each physical node according to the chapter "[Getting started](https://www.taosdata.com/en/documentation/getting-started/)"; + +2. On the first data node, use CLI program taos to log in to TDengine system and execute the command: + + ``` + CREATE DNODE "h2.taos.com:6030"; + ``` + +Add the End Point of the new data node (learned in Step 4 of the preparation) to the cluster's EP list. **"fqdn: port" needs to be enclosed in double quotation marks**, otherwise an error will occur. Notice that the example "[h2.taos.com](http://h2.taos.com/): 6030" is replaced with the End Point for this new data node. + +3. And then execute the command + +1. ``` + SHOW DNODES; + ``` + +2. Check to see if the new node was successfully joined. If the added data node is offline, then check: + +1. - Check whether the taosd of this data node is working properly. If it is not working properly, you need to check the reason first + - Check the first few lines of the data node taosd log file taosdlog.0 (usually in the /var/log/taos directory) to see if the data node fqdn and port number output in the log are the just added End Point. If not, you need to add the correct End Point. + +According to the above steps, new data nodes can be continuously added to the cluster. + +**Tips**: + +- Any data node that has joined the cluster online can be used as the firstEP of the subsequent node to be joined. +- firstEp is only effective when the data node joins the cluster for the first time. After joining the cluster, the data node will save the latest End Point list of mnode and no longer rely on this parameter. +- The two dnode data nodes dnode that are not configured with the firstEp parameter will run independently after startup. At this time, one data node cannot be added to another data node to form a cluster. **You cannot merge two independent clusters into a new cluster**. + +## Data Node Management + +The above has already introduced how to build clusters from scratch. After the cluster is formed, new data nodes can be added at any time for expansion, or data nodes can be deleted, and the current status of the cluster can be checked. + +### Add data nodes + +Execute CLI program taos, log in to the system using root account, and execute: + +``` +CREATE DNODE "fqdn:port"; +``` + +Add the End Point for the new data node to the cluster's EP list. **"fqdn: port" needs to be enclosed in double quotation marks**, otherwise an error will occur. The fqdn and port of a data node's external service can be configured through the configuration file taos.cfg, which is automatically obtained by default. [It is strongly not recommended to configure FQDN with automatic acquisition, which may cause the End Point of the generated data node to be not expected] + +### Delete data nodes + +Execute the CLI program taos, log in to the TDengine system using the root account, and execute: + +``` +DROP DNODE "fqdn:port"; +``` + +Where fqdn is the FQDN of the deleted node, and port is the port number of its external server. + +**【Note】** + +- Once a data node is dropped, it cannot rejoin the cluster. This node needs to be redeployed (emptying the data folder). The cluster migrates the data from the dnode before it completes the drop dnode operation. +- Note that dropping a dnode and stopping the taosd process are two different concepts. Don't be confused: the data migration operation must be performed before deleting a dnode, thus the deleted dnode must remain online. The taosd process cannot be stopped until the delete operation is completed. +- After a data node is dropped, other nodes will perceive the deletion of this dnodeID, and no node in any cluster will receive the request of the dnodeID. +- dnodeID is automatically assigned by the cluster and cannot be specified manually. It is incremented at the time of generation and does not repeat. + +### View data nodes + +Execute the CLI program taos, log in to the TDengine system using the root account, and execute: + +``` +SHOW DNODES; +``` + +All dnodes, fqdn: port for each dnode, status (ready, offline, etc.), number of vnodes, number of unused vnodes in the cluster will be listed. You can use this command to view after adding or deleting a data node. + +### View virtual node group + +In order to make full use of multi-core technology and provide scalability, data needs to be processed in partitions. Therefore, TDengine will split the data of a DB into multiple parts and store them in multiple vnodes. These vnodes may be distributed in multiple data node dnodes, thus realizing scale-out. A vnode belongs to only one DB, but a DB can have multiple vnodes. vnode is allocated automatically by mnode according to the current system resources without any manual intervention. + +Execute the CLI program taos, log in to the TDengine system using the root account, and execute: + +``` +SHOW VGROUPS; +``` + +## High-availability of vnode + +TDengine provides high-availability of system through a multi-replica mechanism, including high-availability of vnode and mnode. + +The number of replicas of vnode is associated with DB. There can be multiple DBs in a cluster. Each DB can be configured with different replicas according to operational requirements. When creating a database, specify the number of replicas with parameter replica (the default is 1). If the number of replicas is 1, the reliability of the system cannot be guaranteed. As long as the node where the data is located goes down, the service cannot be provided. The number of nodes in the cluster must be greater than or equal to the number of replicas, otherwise the error "more dnodes are needed" will be returned when creating a table. For example, the following command will create a database demo with 3 replicas: + +``` +CREATE DATABASE demo replica 3; +``` + +The data in a DB will be partitioned and splitted into multiple vnode groups. The number of vnodes in a vnode group is the number of replicas of the DB, and the data of each vnode in the same vnode group is completely consistent. In order to ensure high-availability, the vnodes in a vnode group must be distributed in different dnode data nodes (in actual deployment, they need to be on different physical machines). As long as more than half of the vnodes in a vgroup are working, the vgroup can be normally serving. + +There may be data from multiple DBs of data in a data node dnode, so when a dnode is offline, it may affect multiple DBs. If half or more of the vnodes in a vnode group do not work, then the vnode group cannot serve externally and cannot insert or read data, which will affect the reading and writing operations of some tables in the DB to which it belongs. + +Because of the introduction of vnode, it is impossible to simply draw a conclusion: "If more than half of the data nodes in the cluster work in dnode, the cluster should work." But for simple cases, it is easier to judge. For example, if the number of replicas is 3 and there are only 3 dnodes, the whole cluster can still work normally if only one node does not work, but if two data nodes do not work, the whole cluster cannot work normally. + +## High-availability of mnode + +TDengine cluster is managed by mnode (a module of taosd, management node). In order to ensure the high-availability of mnode, multiple mnode replicas can be configured. The number of replicas is determined by system configuration parameter numOfMnodes, and the effective range is 1-3. In order to ensure the strong consistency of metadata, mnode replicas are duplicated synchronously. + +A cluster has multiple data node dnodes, but a dnode runs at most one mnode instance. In the case of multiple dnodes, which dnode can be used as an mnode? This is automatically specified by the system according to the resource situation on the whole. User can execute the following command in the console of TDengine through the CLI program taos: + +``` +SHOW MNODES; +``` + +To view the mnode list, which lists the End Point and roles (master, slave, unsynced, or offline) of the dnode where the mnode is located. When the first data node in the cluster starts, the data node must run an mnode instance, otherwise the dnode of the data node cannot work properly because a system must have at least one mnode. If numOfMnodes is configured to 2, when the second dnode is started, the latter will also run an mnode instance. + +To ensure the high-availability of mnode service, numOfMnodes must be set to 2 or greater. Because the metadata saved by mnode must be strongly consistent, if numOfMnodes is greater than 2, the duplication parameter quorum is automatically set to 2, that is to say, at least two replicas must be guaranteed to write the data successfully before notifying the client application of successful writing. + +**Note:** A TDengine highly-available system, whether vnode or mnode, must be configured with multiple replicas. + +## Load Balancing + +There are three situations in which load balancing will be triggered, and no manual intervention is required. + +- When a new data node is added to the cluster, the system will automatically trigger load balancing, and the data on some nodes will be automatically migrated to the new data node without any manual intervention. +- When a data node is removed from the cluster, the system will automatically migrate the data on the data node to other data nodes without any manual intervention. +- If a data node is overheated (too large amount of data), the system will automatically load balance and migrate some vnodes of the data node to other nodes. + +When the above three situations occur, the system will start a load computing of each data node to decide how to migrate. + +**[Tip] Load balancing is controlled by parameter balance, which determines whether to start automatic load balancing.** + +## Offline Processing of Data Nodes + +If a data node is offline, the TDengine cluster will automatically detect it. There are two detailed situations: + +- If the data node is offline for more than a certain period of time (configuration parameter offlineThreshold in taos.cfg controls the duration), the system will automatically delete the data node, generate system alarm information and trigger the load balancing process. If the deleted data node is online again, it will not be able to join the cluster, and the system administrator will need to add it to the cluster again. +- After offline, the system will automatically start the data recovery process if it goes online again within the duration of offlineThreshold. After the data is fully recovered, the node will start to work normally. + +**Note:** If each data node belonging to a virtual node group (including mnode group) is in offline or unsynced state, Master can only be elected after all data nodes in the virtual node group are online and can exchange status information, and the virtual node group can serve externally. For example, the whole cluster has 3 data nodes with 3 replicas. If all 3 data nodes go down and then 2 data nodes restart, it will not work. Only when all 3 data nodes restart successfully can serve externally again. + +## How to Use Arbitrator + +If the number of replicas is even, it is impossible to elect a master from a vnode group when half of the vnodes are not working. Similarly, when half of the mnodes are not working, the master of the mnode cannot be elected because of the "split brain" problem. To solve this problem, TDengine introduced the concept of Arbitrator. Arbitrator simulates a vnode or mnode working, but is simply responsible for networking, and does not handle any data insertion or access. As long as more than half of the vnodes or mnodes, including the Arbitrator, work, the vnode group or mnode group can normally provide data insertion or query services. For example, in the case of 2 replicas, if one node A is offline, but the other node B is normal on and can connect to the Arbitrator, then node B can work normally. + +In a word, under the current version, TDengine recommends configuring Arbitrator in double-replica environment to improve the availability. + +The name of the executable for Arbitrator is tarbitrator. The executable has almost no requirements for system resources, just need to ensure a network connection, with any Linux server to run it. The following briefly describes the steps to install the configuration: + + + +1. Click [Package Download](https://www.taosdata.com/cn/all-downloads/), and in the TDengine Arbitrator Linux section, select the appropriate version to download and install. +2. The command line parameter -p of this application can specify the port number of its external service, and the default is 6042. +3. Modify the configuration file of each taosd instance, and set parameter arbitrator to the End Point corresponding to the tarbitrator in taos.cfg. (If this parameter is configured, when the number of replicas is even, the system will automatically connect the configured Arbitrator. If the number of replicas is odd, even if the Arbitrator is configured, the system will not establish a connection.) +4. The Arbitrator configured in the configuration file will appear in the return result of instruction `SHOW DNODES`; the value of the corresponding role column will be "arb". + diff --git a/documentation20/en/11.administrator/docs.md b/documentation20/en/11.administrator/docs.md new file mode 100644 index 0000000000000000000000000000000000000000..dbcc2a7e1834cb4a5c435f8e782482804523e353 --- /dev/null +++ b/documentation20/en/11.administrator/docs.md @@ -0,0 +1,511 @@ +# TDengine Operation and Maintenance + +## Capacity Planing + +Using TDengine to build an IoT big data platform, computing resource and storage resource need to be planned according to business scenarios. The following is a discussion of the memory, CPU and hard disk space required for the system to run. + +### Memory requirements + +Each DB can create a fixed number of vgroups, which is the same as the CPU cores by default and can be configured by maxVgroupsPerDb; each replica in the vgroup would be a vnode; each vnode takes up a fixed amount of memory (the size is related to the database's configuration parameters blocks and cache); each table takes up memory related to the total length of the tag; in addition, the system will have some fixed memory overhead. Therefore, the system memory required for each DB can be calculated by the following formula: + +``` +Database Memory Size = maxVgroupsPerDb * (blocks * cache + 10MB) + numOfTables * (tagSizePerTable + 0.5KB) +``` + +Example: Assuming a 4-core machine, cache is the default size of 16M, blocks is the default value of 6, assuming there are 100,000 tables, and the total tag length is 256 bytes, the total memory requirement is: 4 * (16 * 6 + 10) + 100,000 * (0.25 + 0.5)/1000 = 499M. + +The actual running system often stores the data in different DBs according to different characteristics of the data. All these shall be considered when planning. + +If there is plenty of memory, the configuration of Blocks can be increased so that more data will be stored in memory and the query speed will be improved. + +### CPU requirements + +CPU requirements depend on the following two aspects: + +- **Data insertion** TDengine single core can handle at least 10,000 insertion requests per second. Each insertion request can take multiple records, and inserting one record at a time is almost the same as inserting 10 records in computing resources consuming. Therefore, the larger the number of inserts, the higher the insertion efficiency. If an insert request has more than 200 records, a single core can insert 1 million records per second. However, the faster the insertion speed, the higher the requirement for front-end data collection, because records need to be cached and then inserted in batches. +- **Query requirements** TDengine to provide efficient queries, but the queries in each scenario vary greatly and the query frequency too, making it difficult to give objective figures. Users need to write some query statements for their own scenes to determine. + +Therefore, only for data insertion, CPU can be estimated, but the computing resources consumed by query cannot be that clear. In the actual operation, it is not recommended to make CPU utilization rate over 50%. After that, new nodes need to be added to bring more computing resources. + +### Storage requirements + +Compared with general databases, TDengine has an ultra-high compression ratio. In most scenarios, the compression ratio of TDengine will not be less than 5:1, and in some scenarios, maybe over 10:1, depending on the actual data characteristics. The raw data size before compressed can be calculated as follows: + +``` +Raw DataSize = numOfTables * rowSizePerTable * rowsPerTable +``` + +Example: 10 million smart meters, each meter collects data every 15 minutes, and the data collected each time is 128 bytes, so the original data amount in one year is: 10000000 * 128 * 24 * 60/15 * 365 = 44.8512 T. The TDengine consumes approximately 44.851/5 = 8.97024 T. + +User can set the maximum retention time of data on disk through parameter `keep`. In order to further reduce the storage cost, TDengine also provides tiered storage. The coldest data can be stored on the cheapest storage media. Application access does not need to be adjusted, but lower reading speed. + +To improve speed, multiple hard disks can be configured so that data can be written or read concurrently. It should be reminded that TDengine provides high reliability of data in the form of multiple replicas, so it is no longer necessary to use expensive disk arrays. + +### Number of physical or virtual machines + +According to the above estimation of memory, CPU and storage, we can know how many cores, how much memory and storage space the whole system needs. If the number of data replicas is not 1, the total demand needs to be multiplied by the number of replicas. + +Because TDengine provides great scale-out feature, it is easy to decide how many physical or virtual machines need to be purchased according to the total amount and the resources of a single physical/ virtual machine. + +**Calculate CPU, memory and storage immediately, see:** [**Resource Estimation**](https://www.taosdata.com/config/config.html) + +### Fault Tolerance and Disaster Recovery + +### Fault tolerance + +TDengine supports WAL (Write Ahead Log) mechanism to realize fault tolerance of data and ensure high-availability of data. + +When TDengine receives the application's request packet, it first writes the requested original packet into the database log file, and then deletes the corresponding WAL after the data is successfully written. This ensures that TDengine can recover data from the database log file when the service is restarted due to power failure or other reasons, thus avoiding data loss. + +There are two system configuration parameters involved: + +- walLevel: WAL level, 0: do not write wal; 1: write wal, but do not execute fsync; 2: write wal and execute fsync. +- fsync: the cycle in which fsync is executed when walLevel is set to 2. Setting to 0 means that fsync is executed immediately whenever there is a write. + +To guarantee 100% data safe, you need to set walLevel to 2 and fsync to 0. In that way, the write speed will decrease. However, if the number of threads starting to write data on the application side reaches a certain number (more than 50), the performance of writing data will also be good, only about 30% lower than that of fsync set to 3000 milliseconds. + +### Disaster recovery + +The cluster of TDengine provides high-availability of the system and implements disaster recovery through the multipl-replica mechanism. + +TDengine cluster is managed by mnode. In order to ensure the high reliability of the mnode, multiple mnode replicas can be configured. The number of replicas is determined by system configuration parameter numOfMnodes. In order to support high reliability, it needs to be set to be greater than 1. In order to ensure the strong consistency of metadata, mnode replicas duplicate data synchronously to ensure the strong consistency of metadata. + +The number of replicas of time-series data in TDengine cluster is associated with databases. There can be multiple databases in a cluster, and each database can be configured with different replicas. When creating a database, specify the number of replicas through parameter replica. In order to support high reliability, it is necessary to set the number of replicas greater than 1. + +The number of nodes in TDengine cluster must be greater than or equal to the number of replicas, otherwise an error will be reported in table creation. + +When the nodes in TDengine cluster are deployed on different physical machines and multiple replicas are set, the high reliability of the system is implemented without using other software or tools. TDengine Enterprise Edition can also deploy replicas in different server rooms, thus realizing remote disaster recovery. + +## Server-side Configuration + +The background service of TDengine system is provided by taosd, and the configuration parameters can be modified in the configuration file taos.cfg to meet the requirements of different scenarios. The default location of the configuration file is the /etc/taos directory, which can be specified by executing the parameter -c from the taosd command line. Such as taosd-c/home/user, to specify that the configuration file is located in the /home/user directory. + +You can also use “-C” to show the current server configuration parameters: + +``` +taosd -C +``` + +Only some important configuration parameters are listed below. For more parameters, please refer to the instructions in the configuration file. Please refer to the previous chapters for detailed introduction and function of each parameter, and the default of these parameters is working and generally does not need to be set. **Note: After the configuration is modified, \*taosd service\* needs to be restarted to take effect.** + +- firstEp: end point of the first dnode in the actively connected cluster when taosd starts, the default value is localhost: 6030. +- fqdn: FQDN of the data node, which defaults to the first hostname configured by the operating system. If you are accustomed to IP address access, you can set it to the IP address of the node. +- serverPort: the port number of the external service after taosd started, the default value is 6030. +- httpPort: the port number used by the RESTful service to which all HTTP requests (TCP) require a query/write request. The default value is 6041. +- dataDir: the data file directory to which all data files will be written. [Default:/var/lib/taos](http://default/var/lib/taos). +- logDir: the log file directory to which the running log files of the client and server will be written. [Default:/var/log/taos](http://default/var/log/taos). +- arbitrator: the end point of the arbiter in the system; the default value is null. +- role: optional role for dnode. 0-any; it can be used as an mnode and to allocate vnodes; 1-mgmt; It can only be an mnode, but not to allocate vnodes; 2-dnode; caannot be an mnode, only vnode can be allocated +- debugFlage: run the log switch. 131 (output error and warning logs), 135 (output error, warning, and debug logs), 143 (output error, warning, debug, and trace logs). Default value: 131 or 135 (different modules have different default values). +- numOfLogLines: the maximum number of lines allowed for a single log file. Default: 10,000,000 lines. +- logKeepDays: the maximum retention time of the log file. When it is greater than 0, the log file will be renamed to taosdlog.xxx, where xxx is the timestamp of the last modification of the log file in seconds. Default: 0 days. +- maxSQLLength: the maximum length allowed for a single SQL statement. Default: 65380 bytes. +- telemetryReporting: whether TDengine is allowed to collect and report basic usage information. 0 means not allowed, and 1 means allowed. Default: 1. +- stream: whether continuous query (a stream computing function) is enabled, 0 means not allowed, 1 means allowed. Default: 1. +- queryBufferSize: the amount of memory reserved for all concurrent queries. The calculation rule can be multiplied by the number of the table according to the maximum possible concurrent number in practical application, and then multiplied by 170. The unit is MB (in versions before 2.0. 15, the unit of this parameter is byte). +- ratioOfQueryCores: set the maximum number of query threads. The minimum value of 0 means that there is only one query thread; the maximum value of 2 indicates that the maximum number of query threads established is 2 times the number of CPU cores. The default is 1, which indicates the maximum number of query threads equals to the number of CPU cores. This value can be a decimal, that is, 0.5 indicates that the query thread with half of the maximum CPU cores is established. + +**Note:** for ports, TDengine will use 13 continuous TCP and UDP port numbers from serverPort, so be sure to open them in the firewall. Therefore, if it is the default configuration, a total of 13 ports from 6030 to 6042 need to be opened, and the same for both TCP and UDP. + +Data in different application scenarios often have different data characteristics, such as retention days, number of replicas, collection frequency, record size, number of collection points, compression, etc. In order to obtain the best efficiency in storage, TDengine provides the following storage-related system configuration parameters: + +- days: the time span for a data file to store data, in days, the default value is 10. +- keep: the number of days to keep data in the database, in days, default value: 3650. +- minRows: the minimum number of records in a file block, in pieces, default: 100. +- maxRows: the maximum number of records in a file block, in pieces, default: 4096. +- comp: file compression flag bit, 0: off; 1: one-stage compression; 2: two-stage compression. Default: 2. +- walLevel: WAL level. 1: write wal, but do not execute fsync; 2: write wal and execute fsync. Default: 1. +- fsync: the period during which fsync is executed when wal is set to 2. Setting to 0 means that fsync is executed immediately whenever a write happens, in milliseconds, and the default value is 3000. +- cache: the size of the memory block in megabytes (MB), default: 16. +- blocks: how many cache-sized memory blocks are in each VNODE (TSDB). Therefore, the memory size used by a VNODE is roughly (cache * blocks), in blocks, and the default value is 4. +- replica: number of replicas; value range: 1-3, in items, default value: 1 +- precision: timestamp precision identification, ms for milliseconds and us for microseconds. Default: ms +- cacheLast: whether the sub-table last_row is cached in memory, 0: off; 1: on. Default: 0. (This parameter is supported as of version 2.0. 11) + +For an application scenario, there may be data with multiple characteristics coexisting. The best design is to put tables with the same data characteristics in one database. Such an application has multiple databases, and each one can be configured with different storage parameters, thus ensuring the optimal performance of the system. TDengine allows the application to specify the above storage parameter in database creation. If specified, the parameters will override the corresponding system configuration parameters. For example, there is the following SQL: + +``` + create database demo days 10 cache 32 blocks 8 replica 3 update 1; +``` + +The SQL creates a database demo, each data file stores 10 days of data, the memory block is 32 megabytes, each VNODE occupies 8 memory blocks, the number of replicas is 3, updates are allowed, and other parameters are completely consistent with the system configuration. + +When adding a new dnode to the TDengine cluster, some parameters related to the cluster must be the same as the configuration of the existing cluster, otherwise it cannot be successfully added to the cluster. The parameters that will be verified are as follows: + +- numOfMnodes: the number of management nodes in the system. Default: 3. +- balance: whether to enable load balancing. 0: No, 1: Yes. Default: 1. +- mnodeEqualVnodeNum: an mnode is equal to the number of vnodes consumed. Default: 4. +- offlineThreshold: the threshold for a dnode to be offline, exceed which the dnode will be removed from the cluster. The unit is seconds, and the default value is 86400*10 (that is, 10 days). +- statusInterval: the length of time dnode reports status to mnode. The unit is seconds, and the default value is 1. +- maxTablesPerVnode: the maximum number of tables that can be created in each vnode. Default: 1000000. +- maxVgroupsPerDb: the maximum number of vgroups that can be used in each database. +- arbitrator: the end point of the arbiter in system, which is empty by default. +- See Client Configuration for the configuration of timezone, locale and charset. + +For the convenience of debugging, the log configuration of each dnode can be temporarily adjusted through SQL statements, and all will be invalid after system restarting: + +```mysql +ALTER DNODE +``` + +- dnode_id: available from the SQL statement "SHOW DNODES" command +- config: the log parameter to be adjusted, and the value is taken in the following list + +resetlog truncates the old log file and creates a new log file debugFlag < 131 135 143 > Set debugFlag to 131, 135 or 143. + +For example: + +``` + alter dnode 1 debugFlag 135; +``` + +## Client Configuration + +The foreground interactive client application of TDengine system is taos and application driver, which shares the same configuration file taos.cfg with taosd. When running taos, use the parameter -c to specify the configuration file directory, such as taos-c/home/cfg, which means using the parameters in the taos.cfg configuration file under the /home/cfg/ directory. The default directory is /etc/taos. For more information on how to use taos, see the help information taos --help. This section mainly describes the parameters used by the taos client application in the configuration file taos.cfg. + +**Versions after 2.0. 10.0 support the following parameters on command line to display the current client configuration parameters** + +```bash +taos -C 或 taos --dump-config +``` + +Client configuration parameters: + +- firstEp: end point of the first taosd instance in the actively connected cluster when taos is started, the default value is localhost: 6030. +- secondEp: when taos starts, if not impossible to connect to firstEp, it will try to connect to secondEp. +- locale + +Default value: obtained dynamically from the system. If the automatic acquisition fails, user needs to set it in the configuration file or through API + +TDengine provides a special field type nchar for storing non-ASCII encoded wide characters such as Chinese, Japanese and Korean. The data written to the nchar field will be uniformly encoded in UCS4-LE format and sent to the server. It should be noted that the correctness of coding is guaranteed by the client. Therefore, if users want to normally use nchar fields to store non-ASCII characters such as Chinese, Japanese, Korean, etc., it’s needed to set the encoding format of the client correctly. + +The characters inputted by the client are all in the current default coding format of the operating system, mostly UTF-8 on Linux systems, and some Chinese system codes may be GB18030 or GBK, etc. The default encoding in the docker environment is POSIX. In the Chinese versions of Windows system, the code is CP936. The client needs to ensure that the character set it uses is correctly set, that is, the current encoded character set of the operating system running by the client, in order to ensure that the data in nchar is correctly converted into UCS4-LE encoding format. + +The naming rules of locale in Linux are: < language > _ < region >. < character set coding >, such as: zh_CN.UTF-8, zh stands for Chinese, CN stands for mainland region, and UTF-8 stands for character set. Character set encoding provides a description of encoding transformations for clients to correctly parse local strings. Linux system and Mac OSX system can determine the character encoding of the system by setting locale. Because the locale used by Windows is not the POSIX standard locale format, another configuration parameter charset is needed to specify the character encoding under Windows. You can also use charset to specify character encoding in Linux systems. + +- charset + +Default value: obtained dynamically from the system. If the automatic acquisition fails, user needs to set it in the configuration file or through API + +If charset is not set in the configuration file, in Linux system, when taos starts up, it automatically reads the current locale information of the system, and parses and extracts the charset encoding format from the locale information. If the automatic reading of locale information fails, an attempt is made to read the charset configuration, and if the reading of the charset configuration also fails, the startup process is interrupted. + +In Linux system, locale information contains character encoding information, so it is unnecessary to set charset separately after setting locale of Linux system correctly. For example: + + ``` + locale zh_CN.UTF-8 + ``` + +- On Windows systems, the current system encoding cannot be obtained from locale. If string encoding information cannot be read from the configuration file, taos defaults to CP936. It is equivalent to adding the following to the configuration file: + + ``` + charset CP936 + ``` + +- If you need to adjust the character encoding, check the encoding used by the current operating system and set it correctly in the configuration file. + +In Linux systems, if user sets both locale and charset encoding charset, and the locale and charset are inconsistent, the value set later will override the value set earlier. + +``` + locale zh_CN.UTF-8 + charset GBK +``` + +- The valid value for charset is GBK. + +And the valid value for charset is UTF-8. + +The configuration parameters of log are exactly the same as those of server. + +- timezone + +Default value: get the current time zone option dynamically from the system + +The time zone in which the client runs the system. In order to deal with the problem of data writing and query in multiple time zones, TDengine uses Unix Timestamp to record and store timestamps. The characteristics of UNIX timestamps determine that the generated timestamps are consistent at any time regardless of any time zone. It should be noted that UNIX timestamps are converted and recorded on the client side. In order to ensure that other forms of time on the client are converted into the correct Unix timestamp, the correct time zone needs to be set. + +In Linux system, the client will automatically read the time zone information set by the system. Users can also set time zones in profiles in a number of ways. For example: + + ``` + timezone UTC-8 + timezone GMT-8 + timezone Asia/Shanghai + ``` + +- All above are legal to set the format of the East Eight Zone. + +The setting of time zone affects the content of non-Unix timestamp (timestamp string, parsing of keyword now) in query and writing SQL statements. For example: + + ```sql + SELECT count(*) FROM table_name WHERE TS<'2019-04-11 12:01:08'; + ``` + +- In East Eight Zone, the SQL statement is equivalent to + + ```sql + SELECT count(*) FROM table_name WHERE TS<1554955268000; + ``` + +- + +In the UTC time zone, the SQL statement is equivalent to + + ```sql + SELECT count(*) FROM table_name WHERE TS<1554984068000; + ``` + +- + +In order to avoid the uncertainty caused by using string time format, Unix timestamp can also be used directly. In addition, timestamp strings with time zones can also be used in SQL statements, such as: timestamp strings in RFC3339 format, 2013-04-12T15: 52: 01.123 +08:00, or ISO-8601 format timestamp strings 2013-04-12T15: 52: 01.123 +0800. The conversion of the above two strings into Unix timestamps is not affected by the time zone in which the system is located. + +When starting taos, you can also specify an end point for an instance of taosd from the command line, otherwise read from taos.cfg. + +- maxBinaryDisplayWidth + +The upper limit of the display width of binary and nchar fields in a shell, beyond which parts will be hidden. Default: 30. You can modify this option dynamically in the shell with the command set max_binary_display_width nn. + +## User Management + +System administrators can add and delete users in CLI, and also modify passwords. The SQL syntax in the CLI is as follows: + +```sql +CREATE USER PASS <'password'>; +``` + +Create a user, and specify the user name and password. The password needs to be enclosed in single quotation marks. The single quotation marks are in English half-width. + +```sql +DROP USER ; +``` + +Delete a user, root only. + +```sql +ALTER USER PASS <'password'>; +``` + +Modify the user password. In order to avoid being converted to lowercase, the password needs to be quoted in single quotation marks. The single quotation marks are in English half-width + +```sql +ALTER USER PRIVILEGE ; +``` + +Modify the user privilege to: write or read, without adding single quotation marks. + +Note: There are three privilege levels: super/write/read in the system, but it is not allowed to give super privilege to users through alter instruction at present. + +```mysql +SHOW USERS; +``` + +Show all users + +**Note:** In SQL syntax, < > indicates the part that requires user to input, but do not enter < > itself + +## Import Data + +TDengine provides a variety of convenient data import functions, including imported by script file, by data file, and by taosdump tool. + +**Import by script file** + +TDengine shell supports source filename command, which is used to run SQL statements from a file in batch. Users can write SQL commands such as database building, table building and data writing in the same file. Each command has a separate line. By running source command in the shell, SQL statements in the file can be run in batches in sequence. SQL statements beginning with '#' are considered comments and are automatically ignored by the shell. + +**Import by data file** + +TDengine also supports data import from CSV files on existing tables in the shell. The CSV file belongs to only one table, and the data format in the CSV file should be the same as the structure of the table to be imported. When importing, its syntax is as follows: + +```mysql +insert into tb1 file 'path/data.csv'; +``` + +Note: if there is descriptive information in the first line of the CSV file, please delete it manually before importing + +For example, there is now a sub-table d1001 whose table structure is as follows: + +```mysql +taos> DESCRIBE d1001 + Field | Type | Length | Note | +================================================================================= + ts | TIMESTAMP | 8 | | + current | FLOAT | 4 | | + voltage | INT | 4 | | + phase | FLOAT | 4 | | + location | BINARY | 64 | TAG | + groupid | INT | 4 | TAG | +``` + +And the format of the data.csv to import is as follows: + +```csv +'2018-10-04 06:38:05.000',10.30000,219,0.31000 +'2018-10-05 06:38:15.000',12.60000,218,0.33000 +'2018-10-06 06:38:16.800',13.30000,221,0.32000 +'2018-10-07 06:38:05.000',13.30000,219,0.33000 +'2018-10-08 06:38:05.000',14.30000,219,0.34000 +'2018-10-09 06:38:05.000',15.30000,219,0.35000 +'2018-10-10 06:38:05.000',16.30000,219,0.31000 +'2018-10-11 06:38:05.000',17.30000,219,0.32000 +'2018-10-12 06:38:05.000',18.30000,219,0.31000 +``` + +Then we can use the following command to import: + +```mysql +taos> insert into d1001 file '~/data.csv'; +Query OK, 9 row(s) affected (0.004763s) +``` + +**Import via taosdump tool** + +TDengine provides a convenient database import and export tool, taosdump. Users can import data exported by taosdump from one system into other systems. Please refer to the blog: [User Guide of TDengine DUMP Tool](https://www.taosdata.com/blog/2020/03/09/1334.html). + +## Export Data + +To facilitate data export, TDengine provides two export methods, namely, export by table and export by taosdump. + +**Export CSV file by table** + +If user needs to export data from a table or a STable, it can run in a shell + +```mysql +select * from >> data.csv; +``` + +In this way, the data in table tb_name will be exported to the file data.csv in CSV format. + +**Export data by taosdump** + +TDengine provides a convenient database export tool, taosdump. Users can choose to export all databases, a database or a table in a database, all data or data for a time period, or even just the definition of a table as needed. Please refer to the blog: [User Guide of TDengine DUMP Tool](https://www.taosdata.com/blog/2020/03/09/1334.html) + +## System Connection and Task Query Management + +The system administrator can query the connection, ongoing query and stream computing of the system from CLI, and can close the connection and stop the ongoing query and stream computing. The SQL syntax in the CLI is as follows: + +```mysql +SHOW CONNECTIONS; +``` + +Show the connection of the database, and one column shows ip: port, which is the IP address and port number of the connection. + +```mysql +KILL CONNECTION ; +``` + +Force the database connection to close, where connection-id is the number in the first column displayed in SHOW CONNECTIONS. + +```mysql +SHOW QUERIES; +``` + +Show the data query, where the two numbers separated by colons displayed in the first column are query-id and the connection-id that initiated the query application connection and the number of queries. + +```mysql +KILL QUERY ; +``` + +Force to close the data query, where query-id is the connection-id: query-no string displayed in SHOW QUERIES, such as "105: 2", copy and paste it. + +```mysql +SHOW STREAMS; +``` + +Show the stream computing, where the first column shows the two numbers separated by colons as stream-id and the connection-id to start the stream application connection and the number of times the stream was initiated. + +```mysql +KILL STREAM ; +``` + +Force to turn off the stream computing, in which stream-id is the connection-id: stream-no string displayed in SHOW STREAMS, such as 103: 2, copy and paste it. + +## System Monitoring + +After TDengine is started, it will automatically create a monitoring database log and write the server's CPU, memory, hard disk space, bandwidth, number of requests, disk read-write speed, slow query and other information into the database regularly. TDengine also records important system operations (such as logging in, creating, deleting databases, etc.) logs and various error alarm information and stores them in the log database. The system administrator can view the database directly from CLI or view the monitoring information through GUI on WEB. + +The collection of these monitoring metrics is turned on by default, but you can modify option enableMonitor in the configuration file to turn it off or on. + +## File Directory Structure + +After installing TDengine, the following directories or files are generated in the operating system by default: + + + +| **Directory/File** | **Description** | +| ------------------------- | ------------------------------------------------------------ | +| /usr/local/taos/bin | TEngine’s executable directory. The executables are connected to the/usr/bin directory via softly links. | +| /usr/local/taos/connector | TDengine’s various connector directories. | +| /usr/local/taos/driver | TDengine’s dynamic link library directory. Connect to /usr/lib directory via soft links. | +| /usr/local/taos/examples | TDengine’s application example directory for various languages. | +| /usr/local/taos/include | TDengine’s header files of C interface for externally serving. | +| /etc/taos/taos.cfg | TDengine’s default [configuration files]. | +| /var/lib/taos | TDengine’s default data file directory, where the local can be modified via [configuration files]. | +| /var/log/taos | TDengine’s default log file directory, where the local can be modified via [configuration files]. | + +**Executables** + +All executables of TDengine are stored in the directory /usr/local/taos/bin by default. Including: + +- *taosd*: TDengine server-side executable +- *taos*: TDengine Shell executable +- *taosdump*: A data import/export tool +- remove.sh: uninstall the TDengine script, please execute carefully, and link to rmtaos command in the/usr/bin directory. The TDengine installation directory /usr/local/taos will be removed, but/etc/taos,/var/lib/taos,/var/log/taos will remain. + +You can configure different data directories and log directories by modifying system configuration file taos.cfg. + +## TDengine Parameter Limits and Reserved Keywords + +- Database name: cannot contain "." and other special characters, and cannot exceed 32 characters +- Table name: cannot contain "." and other special characters, and cannot exceed 192 characters together with the database name to which it belongs +- Table column name: cannot contain special characters, and cannot exceed 64 characters +- Database name, table name, column name cannot begin with a number +- Number of columns in table: cannot exceed 1024 columns +- Maximum length of record: including 8 bytes as timestamp, no more than 16KB (each column of BINARY/NCHAR type will occupy an additional 2 bytes of storage location) +- Default maximum string length for a single SQL statement: 65480 bytes +- Number of database replicas: no more than 3 +- User name: no more than 23 bytes +- User password: no more than 15 bytes +- Number of Tags: no more than 128 +- Total length of label: cannot exceed 16K bytes +- Number of records: limited by storage space only +- Number of tables: limited only by the number of nodes +- Number of databases: limited only by the number of nodes +- Number of virtual nodes on a single database: cannot exceed 64 + +At the moment, TDengine has nearly 200 internal reserved keywords, which cannot be used as database name, table name, STable name, data column name or tag column name regardless of case. The list of these keywords is as follows: + +| **List of Keywords** | | | | | +| -------------------- | ----------- | ------------ | ---------- | --------- | +| ABLOCKS | CONNECTIONS | GT | MNODES | SLIDING | +| ABORT | COPY | ID | MODULES | SLIMIT | +| ACCOUNT | COUNT | IF | NCHAR | SMALLINT | +| ACCOUNTS | CREATE | IGNORE | NE | SPREAD | +| ADD | CTIME | IMMEDIATE | NONE | STABLE | +| AFTER | DATABASE | IMPORT | NOT | STABLES | +| ALL | DATABASES | IN | NOTNULL | STAR | +| ALTER | DAYS | INITIALLY | NOW | STATEMENT | +| AND | DEFERRED | INSERT | OF | STDDEV | +| AS | DELIMITERS | INSTEAD | OFFSET | STREAM | +| ASC | DESC | INTEGER | OR | STREAMS | +| ATTACH | DESCRIBE | INTERVAL | ORDER | STRING | +| AVG | DETACH | INTO | PASS | SUM | +| BEFORE | DIFF | IP | PERCENTILE | TABLE | +| BEGIN | DISTINCT | IS | PLUS | TABLES | +| BETWEEN | DIVIDE | ISNULL | PRAGMA | TAG | +| BIGINT | DNODE | JOIN | PREV | TAGS | +| BINARY | DNODES | KEEP | PRIVILEGE | TBLOCKS | +| BITAND | DOT | KEY | QUERIES | TBNAME | +| BITNOT | DOUBLE | KILL | QUERY | TIMES | +| BITOR | DROP | LAST | RAISE | TIMESTAMP | +| BOOL | EACH | LE | REM | TINYINT | +| BOTTOM | END | LEASTSQUARES | REPLACE | TOP | +| BY | EQ | LIKE | REPLICA | TRIGGER | +| CACHE | EXISTS | LIMIT | RESET | UMINUS | +| CASCADE | EXPLAIN | LINEAR | RESTRICT | UPLUS | +| CHANGE | FAIL | LOCAL | ROW | USE | +| CLOG | FILL | LP | ROWS | USER | +| CLUSTER | FIRST | LSHIFT | RP | USERS | +| COLON | FLOAT | LT | RSHIFT | USING | +| COLUMN | FOR | MATCH | SCORES | VALUES | +| COMMA | FROM | MAX | SELECT | VARIABLE | +| COMP | GE | METRIC | SEMI | VGROUPS | +| CONCAT | GLOB | METRICS | SET | VIEW | +| CONFIGS | GRANTS | MIN | SHOW | WAVG | +| CONFLICT | GROUP | MINUS | SLASH | WHERE | +| CONNECTION | | | | | \ No newline at end of file diff --git a/documentation20/en/12.taos-sql/docs.md b/documentation20/en/12.taos-sql/docs.md new file mode 100644 index 0000000000000000000000000000000000000000..a457b2324526c93eacdfa3c8e9f4c87229c8feae --- /dev/null +++ b/documentation20/en/12.taos-sql/docs.md @@ -0,0 +1,1203 @@ +# TAOS SQL + +TDengine provides a SQL-style language, TAOS SQL, to insert or query data, and support other common tips. To finish this document, you should have some understanding about SQL. + +TAOS SQL is the main tool for users to write and query data to TDengine. TAOS SQL provides a style and mode similar to standard SQL to facilitate users to get started quickly. Strictly speaking, TAOS SQL is not and does not attempt to provide SQL standard syntax. In addition, since TDengine does not provide deletion function for temporal structured data, the relevant function of data deletion is non-existent in TAO SQL. + +Let’s take a look at the conventions used for syntax descriptions. + +- The content in < > is what the user needs to enter, but do not enter < > itself +- [] indicates that the content is optional, but do not enter [] itself +- "|" means you can select one of multiple choices, but you cannot enter | yourself +- "…" means repeating for as many times + +In order to better explain the rules and characteristics of SQL syntax, this document assumes that there is a data set. Take smart meters as an example, each smart meter collects three metrics: current, voltage and phase. It is modeled as follows: + +```mysql +taos> DESCRIBE meters; + Field | Type | Length | Note | +================================================================================= + ts | TIMESTAMP | 8 | | + current | FLOAT | 4 | | + voltage | INT | 4 | | + phase | FLOAT | 4 | | + location | BINARY | 64 | TAG | + groupid | INT | 4 | TAG | +``` + +The data set contains data from four smart meters, which correspond to four sub-tables according to the modeling rules of TDengine, and their names are D1001, D1002, D1003 and D1004 respectively. + +## Data Types + +With TDengine, the most important thing is timestamp. When creating and inserting records and querying history records, you need to specify a timestamp. The timestamp has the following rules: + +- Time Format: 'YYYY-MM-DD HH:mm:ss.MS', default in milliseconds. For example,'2017-08-12 18:52:58.128' +- Internal Function **now** : this is the current time of the server +- When inserting a record, if timestamp is NOW, then use the server current time. +- Epch Time: a timestamp value can also be a long integer representing milliseconds since 1970-01-01 08:00:00.000. +- Arithmetic operations can be applied to timestamp. For example: now-2h represents a timestamp which is 2 hours ago from the current server time. Units include u( microsecond), a (milliseconds), s (seconds), m (minutes), h (hours), d (days), w (weeks). In `select * from t1 where ts > now-2w and ts <= now-1w`, which queries data of the whole week before two weeks. To specify the interval of down sampling, you can also use n(calendar month) and y(calendar year) as time units. + +Default time precision of TDengine is millisecond, you can change it to microseocnd by setting parameter enableMicrosecond. + +In TDengine, the following 10 data types can be used in data model of an ordinary table. + +| | **Data Type** | **Bytes** | **Note** | +| ---- | ------------- | --------- | ------------------------------------------------------------ | +| 1 | TIMESTAMP | 8 | Time stamp. Default in milliseconds, and support microseconds. Starting from 1970-01-01 00:00:00. 000 (UTC/GMT), the timing cannot be earlier than this time. | +| 2 | INT | 4 | A nullable integer type with a range of [-2^31+1, 2^31-1 ] | +| 3 | BIGINT | 8 | A nullable integer type with a range of [-2^59, 2^59 ] | +| 4 | FLOAT | 4 | A standard nullable float type with 6 -7 significant digits and a range of [-3.4E38, 3.4E38] | +| 5 | DOUBLE | 8 | A standard nullable double float type with 15-16 significant digits and a range of [-1.7E308, 1.7E308] | +| 6 | BINARY | Custom | Used to record ASCII strings. Theoretically, the maximum length can be 16,374 bytes, but since each row of data can be up to 16K bytes, the actual limit is generally smaller than the theoretical value. Binary only supports string input, and single quotation marks are used at both ends of the string, otherwise all English will be automatically converted to lowercase. When using, the size must be specified. For example, binary (20) defines a string with a maximum length of 20 characters, and each character occupies 1 byte of storage space. In this case, if the user string exceeds 20 bytes, an error will be reported. For single quotation marks in strings, they can be represented by escape character backslash plus single quotation marks, that is\ '. | +| 7 | SMALLINT | 2 | A nullable integer type with a range of [-32767, 32767] | +| 8 | TINYINT | 1 | A nullable integer type with a range of [-127, 127] | +| 9 | BOOL | 1 | Boolean type,{true, false} | +| 10 | NCHAR | Custom | Used to record non-ASCII strings, such as Chinese characters. Each nchar character takes up 4 bytes of storage space. Single quotation marks are used at both ends of the string, and escape characters are required for single quotation marks in the string, that is \’. When nchar is used, the string size must be specified. A column of type nchar (10) indicates that the string of this column stores up to 10 nchar characters, which will take up 40 bytes of space. If the length of the user string exceeds the declared length, an error will be reported. | + + + +**Tips**: + +1. TDengine is case-insensitive to English characters in SQL statements and automatically converts them to lowercase for execution. Therefore, the user's case-sensitive strings and passwords need to be enclosed in single quotation marks. +2. Avoid using BINARY type to save non-ASCII type strings, which will easily lead to errors such as garbled data. The correct way is to use NCHAR type to save Chinese characters. + +## Database Management + +- Create a Database + + ```mysql + CREATE DATABASE [IF NOT EXISTS] db_name [KEEP keep] [DAYS days] [UPDATE 1]; + ``` + +Note: + +1. KEEP is how long the data of the database is kept, the default is 3650 days (10 years), and the database will automatically delete the data expired; +2. UPDATE marks the database support updating the same timestamp data; +3. Maximum length of the database name is 33; +4. Maximum length of a SQL statement is 65480 characters; +5. Database has more storage-related configuration parameters, see System Management. + +- Show current system parameters + +- ```mysql + SHOW VARIABLES; + ``` + +- Use a database + +Use/switch database + +- Drop a database + +Delete a database, all data tables included will be deleted. Please use with caution. + +- Modify database parameters + +- ```mysql + ALTER DATABASE db_name COMP 2; + ``` + +COMP parameter modifies the database file compression flag bit, with the default value of 2 and the value range is [0, 2]. 0 means no compression, 1 means one-stage compression, and 2 means two-stage compression. + + ```mysql + ALTER DATABASE db_name REPLICA 2; + ``` + +- REPLICA parameter refers to the number of replicas of the modified database, and the value range is [1, 3]. For use in a cluster, the number of replicas must be less than or equal to the number of DNODE. + + ```mysql + ALTER DATABASE db_name KEEP 365; + ``` + +- The KEEP parameter refers to the number of days to save a modified data file. The default value is 3650, and the value range is [days, 365000]. It must be greater than or equal to the days parameter value. + +```mysql + ALTER DATABASE db_name QUORUM 2; +``` + +- + +QUORUM parameter refers to the number of confirmations required for successful data writing, and the value range is [1, 3]. For asynchronous replication, quorum is set to 1, and the virtual node with master role can confirm it by itself. For synchronous replication, it needs to be at least 2 or greater. In principle, Quorum > = 1 and Quorum < = replica number, which is required when starting a synchronization module instance. + + ```mysql + ALTER DATABASE db_name BLOCKS 100; + ``` + +- BLOCKS parameter is the number of cache-sized memory blocks in each VNODE (TSDB), so the memory size used for a VNODE equals roughly (cache * blocks). Value range is [3,1000]. + + ```mysql + ALTER DATABASE db_name CACHELAST 0; + ``` + +- CACHELAST parameter controls whether last_row of the data subtable is cached in memory. The default value is 0, and the value range is [0, 1]. Where 0 means not enabled and 1 means enabled. (supported from version 2.0. 11) + +Tips: After all the above parameters are modified, show databases can be used to confirm whether the modification is successful. + +- Show all databases in system + + + +## Table Management + +- Create a table +Note: + +1. The first field must be a timestamp, and system will set it as the primary key; +2. The max length of table name is 192; +3. The length of each row of the table cannot exceed 16k characters; +4. Sub-table names can only consist of letters, numbers, and underscores, and cannot begin with numbers +5. ​ 10)If the data type binary or nchar is used, the maximum number of bytes should be specified, such as binary (20), which means 20 bytes; + +- Create a table via STable + +- ```mysql + CREATE TABLE [IF NOT EXISTS] tb_name USING stb_name TAGS (tag_value1, ...); + ``` + +Use a STable as template and assign tag values to create a data table. + +- **Create a data table using STable as a template and specify a specific tags column** + +- ```mysql + CREATE TABLE [IF NOT EXISTS] tb_name USING stb_name (tag_name1, ...) TAGS (tag_value1, ...); + ``` + +Using the specified STable as a template, specify the values of some tags columns to create a data table. (Unspecified tags columns are set to null values.) + +Note: This method has been supported since version 2.0. 17. In previous versions, tags columns were not allowed to be specified, but the values of all tags columns must be explicitly given. + +- Create tables in batches + +- ```mysql + CREATE TABLE [IF NOT EXISTS] tb_name1 USING stb_name TAGS (tag_value1, ...) tb_name2 USING stb_name TAGS (tag_value2, ...) ...; + ``` + +Create a large number of data tables in batches faster. (Server side 2.0. 14 and above) + +Note: + +1. The method of batch creating tables requires that the data table must use STable as a template. +2. On the premise of not exceeding the length limit of SQL statements, it is suggested that the number of tables in a single statement should be controlled between 1000 and 3000, which will obtain an ideal speed of table building. + +- Drop a table + +- Show all data table information under the current database + +Show all data table information under the current database. + +Note: Wildcard characters can be used to match names in like. The maximum length of this wildcard character string cannot exceed 24 bytes. + +Wildcard matching: 1) '%' (percent sign) matches 0 to any number of characters; 2) '_' underscore matches one character. + +- Modify display character width online + +- Get schema information of a table + +- Add a column to table + +- ```mysql + ALTER TABLE tb_name ADD COLUMN field_name data_type; + ``` + +Note: + +1. The maximum number of columns is 1024 and the minimum number is 2; +2. The maximum length of a column name is 64; + +- Drop a column in table + +- ```mysql + ALTER TABLE tb_name DROP COLUMN field_name; + ``` + +If the table is created through a STable, the operation of table schema changing can only be carried out on the STable. Moreover, the schema changes for the STable take effect for all tables created through the schema. For tables that are not created through STables, you can modify the table schema directly. + +## STable Management + +Note: In 2.0. 15.0 and later versions, STABLE reserved words are supported. That is, in the instruction description later in this section, the three instructions of CREATE, DROP and ALTER need to write TABLE instead of STABLE in the old version as the reserved word. + +- Create a STable +Similiar to a standard table creation SQL, but you need to specify name and type of TAGS field. + +Note: + +1. Data types of TAGS column cannot be timestamp; +2. No duplicated TAGS column names; +3. Reversed word cannot be used as a TAGS column name; +4. The maximum number of TAGS is 128, and at least 1 TAG allowed, with a total length of no more than 16k characters. + +- Drop a STable + +- ```mysql + DROP STABLE [IF EXISTS] stb_name; + ``` + +Drop a STable automatically deletes all sub-tables created through the STable. + +- Show all STable information under the current database + +- ```mysql + SHOW STABLES [LIKE tb_name_wildcard]; + ``` + +View all STables under the current database and relevant information, including name, creation time, column number, tag number, number of tables created through the STable, etc. + +- Obtain schema information of a STable + +- ```mysql + DESCRIBE stb_name; + ``` + +- Add column to STable + +- Drop column in STable + +- ```mysql + ALTER STABLE stb_name DROP COLUMN field_name; + ``` + +## TAG Management in STable + +- Add a tag +Add a new tag to the STable and specify a type of the new tag. The total number of tags cannot exceed 128 and the total length does not exceed 16K characters. + +- Drop a tag + +- ```mysql + ALTER STABLE stb_name DROP TAG tag_name; + ``` + +Delete a tag of STable. After deleting the tag, all sub-tables under the STable will also automatically delete the same tag. + +- Modify a tag name + +- ```mysql + ALTER STABLE stb_name CHANGE TAG old_tag_name new_tag_name; + ``` + +Modify a tag name of STable. After modifying, all sub-tables under the STable will automatically update the new tag name. + +- Modify a tag value of sub-table + +- ```mysql + ALTER TABLE tb_name SET TAG tag_name=new_tag_value; + ``` + +Note: Except that the operation of tag value updating is carried out for sub-tables, all other tag operations (adding tags, deleting tags, etc.) can only be applied to STable, and cannot be operated on a single sub-table. After adding a tag to a STable, all tables established based on that will automatically add a new tag, and the default value is NULL. + +## Data Writing + +- Insert a record + + ```mysql + INSERT INTO tb_name VALUES (field_value, ...); + ``` + +Insert a record into table tb_name + +- Insert a record with data corresponding to a given column + +Insert a record into table tb_name, and the data corresponds to a given column. For columns that do not appear in the SQL statement, database will automatically populate them with NULL. Primary key (timestamp) cannot be NULL. + +- Insert multiple records + +- ```mysql + INSERT INTO tb_name VALUES (field1_value1, ...) (field1_value2, ...) ...; + ``` + +- Insert multiple records into table tb_name + +- Insert multiple records into a given column + +- ```mysql + INSERT INTO tb_name (field1_name, ...) VALUES (field1_value1, ...) (field1_value2, ...) ...; + ``` + +Insert multiple records into a given column of table tb_name + +- Insert multiple records into multiple tables + +- ```mysql + INSERT INTO tb1_name VALUES (field1_value1, ...) (field1_value2, ...) ... + tb2_name VALUES (field1_value1, ...) (field1_value2, ...) ...; + ``` + +Insert multiple records into tables tb1_name and tb2_name at the same time + +- Insert multiple records per column into multiple tables + +- ```mysql + INSERT INTO tb1_name (tb1_field1_name, ...) VALUES (field1_value1, ...) (field1_value2, ...) ... + tb2_name (tb2_field1_name, ...) VALUES (field1_value1, ...) (field1_value2, ...) ...; + ``` + +Insert multiple records per column into tables tb1_name and tb2_name at the same time + +Note: The timestamp of the oldest record allowed to be inserted is relative to the current server time, minus the configured keep value (days of data retention), and the timestamp of the latest record allowed to be inserted is relative to the current server time, plus the configured days value (interval of data storage in the data file, in days). Both keep and days can be specified when the database is created, and the default values are 3650 days and 10 days, respectively. + +- Automatically create a table when inserting + +- ```mysql + INSERT INTO tb_name USING stb_name TAGS (tag_value1, ...) VALUES (field_value1, ...); + ``` + +If user is not sure whether a table exists when writing data, the automatic table building syntax can be used to create a non-existent table when writing. If the table already exists, no new table will be created. When automatically creating a table, it is required to use the STable as a template and specify tags value for the data table. + +- Automatically create a table when inserting, and specify a given tags column + +During automatic table creation, only the values of some tags columns can be specified, and the unspecified tags columns will be null. + +**History writing**: The IMPORT or INSERT command can be used. The syntax and function of IMPORT are exactly the same as those of INSERT. + +Note: For SQL statements in insert type, the stream parsing strategy we adopt will still execute the correct part of SQL before the following errors are found. In the following sql, insert statement is invalid, but d1001 will still be created. + +```mysql +taos> CREATE TABLE meters(ts TIMESTAMP, current FLOAT, voltage INT, phase FLOAT) TAGS(location BINARY(30), groupId INT); +Query OK, 0 row(s) affected (0.008245s) + +taos> SHOW STABLES; + name | created_time | columns | tags | tables | +============================================================================================ + meters | 2020-08-06 17:50:27.831 | 4 | 2 | 0 | +Query OK, 1 row(s) in set (0.001029s) + +taos> SHOW TABLES; +Query OK, 0 row(s) in set (0.000946s) + +taos> INSERT INTO d1001 USING meters TAGS('Beijing.Chaoyang', 2) VALUES('a'); + +DB error: invalid SQL: 'a' (invalid timestamp) (0.039494s) + +taos> SHOW TABLES; + table_name | created_time | columns | stable_name | +====================================================================================================== + d1001 | 2020-08-06 17:52:02.097 | 4 | meters | +Query OK, 1 row(s) in set (0.001091s) +``` + +## Data Query + +### Query Syntax: + +```mysql +SELECT select_expr [, select_expr ...] + FROM {tb_name_list} + [WHERE where_condition] + [INTERVAL (interval_val [, interval_offset])] + [SLIDING sliding_val] + [FILL fill_val] + [GROUP BY col_list] + [ORDER BY col_list { DESC | ASC }] + [SLIMIT limit_val [SOFFSET offset_val]] + [LIMIT limit_val [OFFSET offset_val]] + [>> export_file]; +``` + +#### SELECT Clause + +A select clause can be a subquery of UNION and another query. + +#### Wildcard character + +The wildcard \* can be used to refer to all columns. For ordinary tables, there’re only ordinary columns in results. + +```mysql +taos> SELECT * FROM d1001; + ts | current | voltage | phase | +====================================================================================== + 2018-10-03 14:38:05.000 | 10.30000 | 219 | 0.31000 | + 2018-10-03 14:38:15.000 | 12.60000 | 218 | 0.33000 | + 2018-10-03 14:38:16.800 | 12.30000 | 221 | 0.31000 | +Query OK, 3 row(s) in set (0.001165s) +``` + +For Stables, wildcards contain *tag columns*. + +```mysql +taos> SELECT * FROM meters; + ts | current | voltage | phase | location | groupid | +===================================================================================================================================== + 2018-10-03 14:38:05.500 | 11.80000 | 221 | 0.28000 | Beijing.Haidian | 2 | + 2018-10-03 14:38:16.600 | 13.40000 | 223 | 0.29000 | Beijing.Haidian | 2 | + 2018-10-03 14:38:05.000 | 10.80000 | 223 | 0.29000 | Beijing.Haidian | 3 | + 2018-10-03 14:38:06.500 | 11.50000 | 221 | 0.35000 | Beijing.Haidian | 3 | + 2018-10-03 14:38:04.000 | 10.20000 | 220 | 0.23000 | Beijing.Chaoyang | 3 | + 2018-10-03 14:38:16.650 | 10.30000 | 218 | 0.25000 | Beijing.Chaoyang | 3 | + 2018-10-03 14:38:05.000 | 10.30000 | 219 | 0.31000 | Beijing.Chaoyang | 2 | + 2018-10-03 14:38:15.000 | 12.60000 | 218 | 0.33000 | Beijing.Chaoyang | 2 | + 2018-10-03 14:38:16.800 | 12.30000 | 221 | 0.31000 | Beijing.Chaoyang | 2 | +Query OK, 9 row(s) in set (0.002022s) +​``` +``` + +Wildcards support table name prefixes, the two following SQL statements will return all columns: + +```mysql +SELECT * FROM d1001; +SELECT d1001.* FROM d1001; +``` + +In Join query, the results returned by \* with prefix and \* without prefix are different. \* returns all column data of all tables (excluding tags), while wildcards with prefix only return column data of the corresponding table. + +```mysql +taos> SELECT * FROM d1001, d1003 WHERE d1001.ts=d1003.ts; + ts | current | voltage | phase | ts | current | voltage | phase | +================================================================================================================================== + 2018-10-03 14:38:05.000 | 10.30000| 219 | 0.31000 | 2018-10-03 14:38:05.000 | 10.80000| 223 | 0.29000 | +Query OK, 1 row(s) in set (0.017385s) +``` +```mysql +taos> SELECT d1001.* FROM d1001,d1003 WHERE d1001.ts = d1003.ts; + ts | current | voltage | phase | +====================================================================================== + 2018-10-03 14:38:05.000 | 10.30000 | 219 | 0.31000 | +Query OK, 1 row(s) in set (0.020443s) +``` + +In the process of using SQL functions for query, some SQL functions support wildcard operation. The difference is that the `count(\*)` function returns only one column, but the `first`,`last`,`last_row` functions return all columns. + +```mysql +taos> SELECT COUNT(*) FROM d1001; + count(*) | +======================== + 3 | +Query OK, 1 row(s) in set (0.001035s) +``` + +```mysql +taos> SELECT FIRST(*) FROM d1001; + first(ts) | first(current) | first(voltage) | first(phase) | +========================================================================================= + 2018-10-03 14:38:05.000 | 10.30000 | 219 | 0.31000 | +Query OK, 1 row(s) in set (0.000849s) +``` + +#### Tag Column + +Since version 2.0. 14, it is supported to specify *tag column* in queries of ordinary tables, and the values of tag columns will be returned together with the data of other ordinary columns. + +```mysql +taos> SELECT location, groupid, current FROM d1001 LIMIT 2; + location | groupid | current | +====================================================================== + Beijing.Chaoyang | 2 | 10.30000 | + Beijing.Chaoyang | 2 | 12.60000 | +Query OK, 2 row(s) in set (0.003112s) +``` + +Note: The wildcard \* of ordinary tables does not contain *tag columns*. + +#### Obtain the de-duplicated value of a tag column + +Since version 2.0. 15, it is supported to specify `DISTINCT` keyword when querying tag columns in STables, which will return all non-duplicate values of given tag columns. + +```mysql +SELECT DISTINCT tag_name FROM stb_name; +``` + +Note: At present, `DISTINCT` keyword only supports deduplication of tag columns of STables, and cannot be used for ordinary columns. + +#### Column name in result set + +In `SELECT` clause, if there’s no returning of column name in result set, the result set column name defaults to the expression name in `SELECT` clause as the column name. In addition, user can use `AS` to rename the columns in the returned result set. For example: + +```mysql +taos> SELECT ts, ts AS primary_key_ts FROM d1001; + ts | primary_key_ts | +==================================================== + 2018-10-03 14:38:05.000 | 2018-10-03 14:38:05.000 | + 2018-10-03 14:38:15.000 | 2018-10-03 14:38:15.000 | + 2018-10-03 14:38:16.800 | 2018-10-03 14:38:16.800 | +Query OK, 3 row(s) in set (0.001191s) +``` + +However, renaming for one single column is not supported for `first(*)`,`last(*)`,`last_row(*)`. + +#### Implicit result column + +`Select_exprs` can be the name of a column belongs to a table, or it can be a column-based functional expression or calculation formula, with an upper limit of 256. When user uses `interval` or `group by tags` clause, the timestamp column (the first column) and the tag column in `group by` clause are forced to be returned in the final returned result. Later versions can support turning off the output of implicit columns in `group by` clause, and the column output is completely controlled by select clause. + +#### List of STable + +The `FROM` keyword can be followed by a list of several tables (STables) or result of a subquery. + +If you do not specify user's current database, you can use the database name before the table name to specify the database to which the table belongs. For example: `power.d1001` to use tables across databases. + +```mysql +SELECT * FROM power.d1001; +------------------------------ +USE power; +SELECT * FROM d1001; +``` + +#### Special Functions + +Some special query functions can be performed without using FROM clause. Obtain the current database database (): + +```mysql +taos> SELECT DATABASE(); + database() | +================================= + power | +Query OK, 1 row(s) in set (0.000079s) +``` + +If no default database is specified when logging in, and `USE` command is not used to switch data, then `NULL` is returned. + +```mysql +taos> SELECT DATABASE(); + database() | +================================= + NULL | +Query OK, 1 row(s) in set (0.000184s) +``` + +Get server and client version numbers: + +```mysql +taos> SELECT CLIENT_VERSION(); + client_version() | +=================== + 2.0.0.0 | +Query OK, 1 row(s) in set (0.000070s) + +taos> SELECT SERVER_VERSION(); + server_version() | +=================== + 2.0.0.0 | +Query OK, 1 row(s) in set (0.000077s) +``` + +A server state detection statement. If server is normal, return a number (for example, 1). If server is exceptional, return error code. The SQL syntax can be compatible with the check of TDengine status by connection pool and the check of database server status by third-party tools. And can avoid connection loss of connection pool caused by using a wrong heartbeat detection SQL statement. + +```mysql +taos> SELECT SERVER_STATUS(); + server_status() | +================== + 1 | +Query OK, 1 row(s) in set (0.000074s) + +taos> SELECT SERVER_STATUS() AS status; + status | +============== + 1 | +Query OK, 1 row(s) in set (0.000081s) +``` + +#### Special keywords in TAOS SQL + +> `TBNAME`: It can be regarded as a special tag in a STable query, representing the name of sub-table involved in the query +> +> _c0: Represents the first column of a table (STable) + +#### Tips + +Get all sub-table names and related tags information of a STable: + +```mysql +SELECT TBNAME, location FROM meters; +``` + +Statistics of sub-tables number under a STable: + +```mysql +SELECT COUNT(TBNAME) FROM meters; +``` + +The two queries above only support adding filters for TAGS in Where conditional clause. For example: + +```mysql +taos> SELECT TBNAME, location FROM meters; + tbname | location | +================================================================== + d1004 | Beijing.Haidian | + d1003 | Beijing.Haidian | + d1002 | Beijing.Chaoyang | + d1001 | Beijing.Chaoyang | +Query OK, 4 row(s) in set (0.000881s) + +taos> SELECT COUNT(tbname) FROM meters WHERE groupId > 2; + count(tbname) | +======================== + 2 | +Query OK, 1 row(s) in set (0.001091s) +``` + +- You can use \* to return all columns, or given column names. Four operations can be performed on numeric columns, and column names can be given to output columns. +- `WHERE` statement can use various logical decisions to filter numeric values, or wildcards to filter strings +- The output is sorted by default in ascending order by timestamps in the first column, but you can specify descending order (\_c0 refers to the first column timestamp). It is illegal to use ORDER BY to sort other fields. +- Parameter LIMIT controls the number of outputs, and OFFSET specifies which output starts from. LIMIT/OFFSET executes the result set after ORDER BY. +- "> >" output can be exported to a specified file + +#### Supported Filtering Operations + +| **Operation** | **Note** | **Applicable Data Types** | +| ------------- | ----------------------------- | ----------------------------------- | +| > | larger than | **timestamp** and all numeric types | +| < | smaller than | **timestamp** and all numeric types | +| >= | larger than or equal to | **timestamp** and all numeric types | +| <= | smaller than or equal to | **timestamp** and all numeric types | +| = | equal to | all types | +| <> | not equal to | all types | +| between and | within a certain range | **timestamp** and all numeric types | +| % | match with any char sequences | **binary** **nchar** | +| _ | match with a single char | **binary** **nchar** | + +1. To filter the range of multiple fields at the same time, you need to use keyword AND to connect different query conditions. The query filtering between different columns connected by OR are not supported at the moment. +2. For filtering a single field, if it is a time filtering condition, only one condition in a statement can be set; however, for other (ordinary) columns or tag columns, OR keyword can be used for query filtering of combined conditions. For example: ((value > 20 AND value < 30) OR (value < 12)). +3. Since version 2.0. 17, condition filtering supports BETWEEN AND syntax. For example, WHERE col2 BETWEEN 1.5 AND 3.25 means that the query condition is "1.5 ≤ col2 ≤ 3.25". + +### SQL Example + +- For example, table tb1 is created with the following statement +- ```mysql + CREATE TABLE tb1 (ts TIMESTAMP, col1 INT, col2 FLOAT, col3 BINARY(50)); + ``` + +- Query all records of the last hour of tb1 + +- Look up table tb1 from 2018-06-01 08:00:00. 000 to 2018-06-02 08:00:00. 000, and col3 string is a record ending in'nny ', and the result is in descending order of timestamp: + +- ```mysql + SELECT * FROM tb1 WHERE ts > '2018-06-01 08:00:00.000' AND ts <= '2018-06-02 08:00:00.000' AND col3 LIKE '%nny' ORDER BY ts DESC; + ``` + +- Query the sum of col1 and col2, and name it complex. The time is greater than 2018-06-01 08:00:00. 000, and col2 is greater than 1.2. As a result, only 10 records are outputted, starting from item 5 + +- ```mysql + SELECT (col1 + col2) AS 'complex' FROM tb1 WHERE ts > '2018-06-01 08:00:00.000' AND col2 > 1.2 LIMIT 10 OFFSET 5; + ``` + +- Query the records of past 10 minutes, the value of col2 is greater than 3.14, and output the result to the file /home/testoutpu.csv. + +- ```mysql + SELECT COUNT(*) FROM tb1 WHERE ts >= NOW - 10m AND col2 > 3.14 >> /home/testoutpu.csv; + ``` + + + +## SQL Functions + +TDengine supports aggregations over data, they are listed below: + +- **COUNT** +Function: record the number of rows or non-null values in a column of statistics/STable. + +Returned result data type: long integer INT64. + +Applicable Fields: Applied to all fields. + +Applied to: **table, STable**. + +Note: + +1. 1. You can use \* instead of specific fields, and use *() to return the total number of records. + 2. The query results for fields of the same table (excluding NULL values) are the same. + 3. If the statistic object is a specific column, return the number of records with non-NULL values in that column. + +Example: + +- ```mysql + taos> SELECT COUNT(*), COUNT(voltage) FROM meters; + count(*) | count(voltage) | + ================================================ + 9 | 9 | + Query OK, 1 row(s) in set (0.004475s) + + taos> SELECT COUNT(*), COUNT(voltage) FROM d1001; + count(*) | count(voltage) | + ================================================ + 3 | 3 | + Query OK, 1 row(s) in set (0.001075s) + ``` + +- **AVG** + +- ```mysql + SELECT AVG(field_name) FROM tb_name [WHERE clause]; + ``` + +Function: return the average value of a column in statistics/STable. + +Return Data Type: double. + +Applicable Fields: all types except timestamp, binary, nchar, bool. + +Applied to: **table,STable**. + +Example: + +- ```mysql + taos> SELECT AVG(current), AVG(voltage), AVG(phase) FROM meters; + avg(current) | avg(voltage) | avg(phase) | + ==================================================================================== + 11.466666751 | 220.444444444 | 0.293333333 | + Query OK, 1 row(s) in set (0.004135s) + + taos> SELECT AVG(current), AVG(voltage), AVG(phase) FROM d1001; + avg(current) | avg(voltage) | avg(phase) | + ==================================================================================== + 11.733333588 | 219.333333333 | 0.316666673 | + Query OK, 1 row(s) in set (0.000943s) + ``` + +- **TWA** + +- ```mysql + SELECT TWA(field_name) FROM tb_name WHERE clause; + ``` + +Function: Time weighted average function. The time-weighted average of a column in a statistical table over a period of time. + +Return Data Type: double. + +Applicable Fields: all types except timestamp, binary, nchar, bool. + +Applied to: **table**. + +- **SUM** + +- ```mysql + SELECT SUM(field_name) FROM tb_name [WHERE clause]; + ``` + +Function: return the sum of a statistics/STable. + +Return Data Type: long integer INMT64 and Double. + +Applicable Fields: All types except timestamp, binary, nchar, bool. + +Applied to: **table,STable**. + +Example: + +- ```mysql + taos> SELECT SUM(current), SUM(voltage), SUM(phase) FROM meters; + sum(current) | sum(voltage) | sum(phase) | + ================================================================================ + 103.200000763 | 1984 | 2.640000001 | + Query OK, 1 row(s) in set (0.001702s) + + taos> SELECT SUM(current), SUM(voltage), SUM(phase) FROM d1001; + sum(current) | sum(voltage) | sum(phase) | + ================================================================================ + 35.200000763 | 658 | 0.950000018 | + Query OK, 1 row(s) in set (0.000980s) + ``` + +- **STDDEV** + +- ```mysql + SELECT STDDEV(field_name) FROM tb_name [WHERE clause]; + ``` + +Function: Mean square deviation of a column in statistics table. + +Return Data Type: Double. + +Applicable Fields: All types except timestamp, binary, nchar, bool. + +Applied to: **table**. (also support **STable** since version 2.0.15.1) + +Example: + +- **LEASTSQUARES** + +Function: Value of a column in statistical table is a fitting straight equation of primary key (timestamp). Start_val is the initial value of independent variable, and step_val is the step size value of independent variable. + +Return Data Type: String expression (slope, intercept). + +Applicable Fields: All types except timestamp, binary, nchar, bool. + +Note: Independent variable is the timestamp, and dependent variable is the value of the column. + +Applied to: **table**. + +Example: + +### Selector Functions + +- **MIN** +Function: return the minimum value of a specific column in statistics/STable. + +Return Data Type: Same as applicable fields. + +Applicable Fields: All types except timestamp, binary, nchar, bool. + +Example: + + ```mysql + taos> SELECT MIN(current), MIN(voltage) FROM meters; + min(current) | min(voltage) | + ====================================== + 10.20000 | 218 | + Query OK, 1 row(s) in set (0.001765s) + + taos> SELECT MIN(current), MIN(voltage) FROM d1001; + min(current) | min(voltage) | + ====================================== + 10.30000 | 218 | + Query OK, 1 row(s) in set (0.000950s) + ``` + +- **MAX** + +- ```mysql + SELECT MAX(field_name) FROM { tb_name | stb_name } [WHERE clause]; + ``` + +Function: return the maximum value of a specific column in statistics/STable. + +Return Data Type: Same as applicable fields. + +Applicable Fields: All types except timestamp, binary, nchar, bool. + +Example: + +- ```mysql + taos> SELECT MAX(current), MAX(voltage) FROM meters; + max(current) | max(voltage) | + ====================================== + 13.40000 | 223 | + Query OK, 1 row(s) in set (0.001123s) + + taos> SELECT MAX(current), MAX(voltage) FROM d1001; + max(current) | max(voltage) | + ====================================== + 12.60000 | 221 | + Query OK, 1 row(s) in set (0.000987s) + ``` + +- **FIRST** + +- ```mysql + SELECT FIRST(field_name) FROM { tb_name | stb_name } [WHERE clause]; + ``` + +Function: The first non-NULL value written into a column in statistics/STable. + +Return Data Type: Same as applicable fields. + +Applicable Fields: All types. + +Note: + +1. 1. To return the first (minimum timestamp) non-NULL value of each column, use FIRST (\*); + 2. if all columns in the result set are NULL values, the return result of the column is also NULL; + 3. If all columns in the result set are NULL values, no result is returned. + +Example: + + ```mysql + taos> SELECT FIRST(*) FROM meters; + first(ts) | first(current) | first(voltage) | first(phase) | + ========================================================================================= + 2018-10-03 14:38:04.000 | 10.20000 | 220 | 0.23000 | + Query OK, 1 row(s) in set (0.004767s) + + taos> SELECT FIRST(current) FROM d1002; + first(current) | + ======================= + 10.20000 | + Query OK, 1 row(s) in set (0.001023s) + ``` + +- + +- **LAST** + +- ```mysql + SELECT LAST(field_name) FROM { tb_name | stb_name } [WHERE clause]; + ``` + +Function: The last non-NULL value written by the value of a column in statistics/STable. + +Return Data Type: Same as applicable fields. + +Applicable Fields: All types. + +Note: + +1. 1. To return the last (maximum timestamp) non-NULL value of each column, use LAST (\*); + 2. If a column in the result set has a NULL value, the returned result of the column is also NULL; if all columns in the result set have NULL values, no result is returned. + +Example: + + ```mysql + taos> SELECT LAST(*) FROM meters; + last(ts) | last(current) | last(voltage) | last(phase) | + ======================================================================================== + 2018-10-03 14:38:16.800 | 12.30000 | 221 | 0.31000 | + Query OK, 1 row(s) in set (0.001452s) + + taos> SELECT LAST(current) FROM d1002; + last(current) | + ======================= + 10.30000 | + Query OK, 1 row(s) in set (0.000843s) + ``` + +- + +- **TOP** + +Function: The top k non-NULL values of a column in statistics/STable. If there are more than k column values tied for the largest, the one with smaller timestamp is returned. + +Return Data Type: Same as applicable fields. + +Applicable Fields: All types except timestamp, binary, nchar, bool. + +Note: + +1. *The range of k value is* 1≤*k*≤100; +2. System also returns the timestamp column associated with the record. + +Example: + +- ```mysql + taos> SELECT TOP(current, 3) FROM meters; + ts | top(current, 3) | + ================================================= + 2018-10-03 14:38:15.000 | 12.60000 | + 2018-10-03 14:38:16.600 | 13.40000 | + 2018-10-03 14:38:16.800 | 12.30000 | + Query OK, 3 row(s) in set (0.001548s) + + taos> SELECT TOP(current, 2) FROM d1001; + ts | top(current, 2) | + ================================================= + 2018-10-03 14:38:15.000 | 12.60000 | + 2018-10-03 14:38:16.800 | 12.30000 | + Query OK, 2 row(s) in set (0.000810s) + ``` + +- **BOTTOM** + +Function: The last k non-NULL values of a column in statistics/STable. If there are more than k column values tied for the smallest, the one with smaller timestamp is returned. + +Return Data Type: Same as applicable fields. + +Applicable Fields: All types except timestamp, binary, nchar, bool. + +Note: + +1. *The range of k value is* 1≤*k*≤100; +2. System also returns the timestamp column associated with the record. + +Example: + +- ```mysql + taos> SELECT BOTTOM(voltage, 2) FROM meters; + ts | bottom(voltage, 2) | + =============================================== + 2018-10-03 14:38:15.000 | 218 | + 2018-10-03 14:38:16.650 | 218 | + Query OK, 2 row(s) in set (0.001332s) + + taos> SELECT BOTTOM(current, 2) FROM d1001; + ts | bottom(current, 2) | + ================================================= + 2018-10-03 14:38:05.000 | 10.30000 | + 2018-10-03 14:38:16.800 | 12.30000 | + Query OK, 2 row(s) in set (0.000793s) + ``` + +- **PERCENTILE** + +Function: Percentile of the value of a column in statistical table. + +Return Data Type: Double. + +Applicable Fields: All types except timestamp, binary, nchar, bool. + +Note: The range of P value is 0 ≤ P ≤ 100. P equals to MIN when, and equals MAX when it’s 100. + +Example: + + ```mysql + taos> SELECT PERCENTILE(current, 20) FROM d1001; + percentile(current, 20) | + ============================ + 11.100000191 | + Query OK, 1 row(s) in set (0.000787s) + ``` + +- + +- **APERCENTILE** + +Function: The value percentile of a column in statistical table is similar to the PERCENTILE function, but returns approximate results. + +Return Data Type: Double. + +Applicable Fields: All types except timestamp, binary, nchar, bool. + +Note: The range of P value is 0 ≤ P ≤ 100. P equals to MIN when, and equals MAX when it’s 100. APERCENTILE function is recommended, which performs far better than PERCENTILE function. + +- **LAST_ROW** + +Function: Return the last record of a table (STtable). + +Return Data Type: Double. + +Applicable Fields: All types. + +Note: Unlike last function, last_row does not support time range restriction and forces the last record to be returned. + +Example: + +- ```mysql + taos> SELECT LAST_ROW(current) FROM meters; + last_row(current) | + ======================= + 12.30000 | + Query OK, 1 row(s) in set (0.001238s) + + taos> SELECT LAST_ROW(current) FROM d1002; + last_row(current) | + ======================= + 10.30000 | + Query OK, 1 row(s) in set (0.001042s) + ``` + + + +### Computing Functions + +- **DIFF** +Function: Return the value difference between a column and the previous column. + +Return Data Type: Same as applicable fields. + +Applicable Fields: All types except timestamp, binary, nchar, bool. + +Note: The number of output result lines is the total number of lines in the range minus one, and there is no result output in the first line. + +Example: + +- ```mysql + taos> SELECT DIFF(current) FROM d1001; + ts | diff(current) | + ================================================= + 2018-10-03 14:38:15.000 | 2.30000 | + 2018-10-03 14:38:16.800 | -0.30000 | + Query OK, 2 row(s) in set (0.001162s) + ``` + +- **SPREAD** + +- ```mysql + SELECT SPREAD(field_name) FROM { tb_name | stb_name } [WHERE clause]; + ``` + +Function: Return the difference between the max value and the min value of a column in statistics /STable. + +Return Data Type: Same as applicable fields. + +Applicable Fields: All types except binary, nchar, bool. + +Note: Applicable for TIMESTAMP field, which indicates the time range of a record. + +Example: + +- ```mysql + taos> SELECT SPREAD(voltage) FROM meters; + spread(voltage) | + ============================ + 5.000000000 | + Query OK, 1 row(s) in set (0.001792s) + + taos> SELECT SPREAD(voltage) FROM d1001; + spread(voltage) | + ============================ + 3.000000000 | + Query OK, 1 row(s) in set (0.000836s) + ``` + +- Four Operations + +Function: Calculation results of addition, subtraction, multiplication, division and remainder of values in a column or among multiple columns in statistics/STable. + +Returned Data Type: Double. + +Applicable Fields: All types except timestamp, binary, nchar, bool. + +Note: + +1. Calculation between two or more columns is supported, and the calculation priorities can be controlled by parentheses(); +2. The NULL field does not participate in the calculation. If a row involved in calculation contains NULL, the calculation result of the row is NULL. + +## Time-dimension Aggregation + +TDengine supports aggregating by intervals. Data in a table can partitioned by intervals and aggregated to generate results. For example, a temperature sensor collects data once per second, but the average temperature needs to be queried every 10 minutes. This aggregation is suitable for down sample operation, and the syntax is as follows: + +```mysql +SELECT function_list FROM tb_name + [WHERE where_condition] + INTERVAL (interval [, offset]) + [SLIDING sliding] + [FILL ({NONE | VALUE | PREV | NULL | LINEAR | NEXT})] + +SELECT function_list FROM stb_name + [WHERE where_condition] + INTERVAL (interval [, offset]) + [SLIDING sliding] + [FILL ({ VALUE | PREV | NULL | LINEAR | NEXT})] + [GROUP BY tags] +``` + +- The length of aggregation interval is specified by keyword INTERVAL, the min time interval is 10 milliseconds (10a), and offset is supported (the offset must be less than interval). In aggregation queries, the aggregator and selector functions that can be executed simultaneously are limited to functions with one single output: count, avg, sum, stddev, leastsquares, percentile, min, max, first, last. Functions with multiple rows of output results (such as top, bottom, diff, and four operations) cannot be used. + +- WHERE statement specifies the start and end time of a query and other filters + +- FILL statement specifies a filling mode when data missed in a certain interval. Applicable filling modes include the following: + +- - Do not fill: NONE (default filingl mode). + - VALUE filling: Fixed value filling, where the filled value needs to be specified. For example: fill (VALUE, 1.23). + - NULL filling: Fill the data with NULL. For example: fill (NULL). + - PREV filling: Filling data with the previous non-NULL value. For example: fill (PREV). + - NEXT filling: Filling data with the next non-NULL value. For example: fill (NEXT). + +Note: + +1. When using a FILL statement, a large number of filling outputs may be generated. Be sure to specify the time interval for the query. For each query, system can return no more than 10 million results with interpolation. +2. In a time-dimension aggregation, the time-series in returned results increases strictly monotonously. +3. If the query object is a STable, the aggregator function will act on the data of all tables under the STable that meet the value filters. If group by statement is not used in the query, the returned result increases strictly monotonously according to time-series; If group by statement is used to group in the query, each group in the returned result does not increase strictly monotonously according to time-series. + +Example: The statement for building a database for smart meter is as follows: + +```mysql +CREATE TABLE meters (ts TIMESTAMP, current FLOAT, voltage INT, phase FLOAT) TAGS (location BINARY(64), groupId INT); +``` + +According to the data collected by the smart meter, the average value, maximum value, median current of current data in the past 24 hours are calculated in a phase of 10 minutes, and the current trend with time changes is fitted to a straight line. If there is no calculated value, fill it with the previous non-NULL value. The query statement used is as follows: + +```mysql +SELECT AVG(current), MAX(current), LEASTSQUARES(current, start_val, step_val), PERCENTILE(current, 50) FROM meters + WHERE ts>=NOW-1d + INTERVAL(10m) + FILL(PREV); +``` + +## TAOS SQL Boundary Restrictions + +- Max database name length is 32 +- Max length of table name is 192, and max length of each data row is 16k characters +- Max length of column name is 64, max number of columns allowed is 1024, and min number of columns allowed is 2. The first column must be a timestamp +- Max number of tags allowed is 128, down to 1, and total length of tags does not exceed 16k characters +- Max length of SQL statement is 65480 characters, but it can be modified by system configuration parameter maxSQLLength, and max length can be configured to 1M +- Number of databases, STables and tables are not limited by system, but only limited by system resources + +## Other TAOS SQL Conventions + +**Restrictions on group by** + +TAOS SQL supports group by operation on tags, tbnames and ordinary columns, required that only one column and whichhas less than 100,000 unique values. + +**Restrictions on join operation** + +TAOS SQL supports join columns of two tables by Primary Key timestamp between them, and does not support four operations after tables aggregated for the time being. + +**Availability of is no null** + +Is not null supports all types of columns. Non-null expression is < > "" and only applies to columns of non-numeric types. \ No newline at end of file diff --git a/documentation20/en/13.faq/docs.md b/documentation20/en/13.faq/docs.md new file mode 100644 index 0000000000000000000000000000000000000000..05507e26e5ab84a01e19d9ecced5e0464c1411f3 --- /dev/null +++ b/documentation20/en/13.faq/docs.md @@ -0,0 +1,161 @@ +# FAQ + +Tutorials & FAQ + +## 0.How to report an issue? + +If the contents in FAQ cannot help you and you need the technical support and assistance of TDengine team, please package the contents in the following two directories: + +1./var/log/taos (if default path has not been modified) + +2./etc/taos + +Provide the necessary description of the problem, including the version information of TDengine used, the platform environment information, the execution operation of the problem, the characterization of the problem and the approximate time, and submit the Issue on [GitHub](https://github.com/taosdata/TDengine). + +To ensure that there is enough debug information, if the problem can be repeated, please modify the/etc/taos/taos.cfg file, add a line of "debugFlag 135" at the end (without quotation marks themselves), then restart taosd, repeat the problem, and then submit. You can also temporarily set the log level of taosd through the following SQL statement. + +``` + alter dnode debugFlag 135; +``` + +However, when the system is running normally, please set debugFlag to 131, otherwise a large amount of log information will be generated and the system efficiency will be reduced. + +## 1.What should I pay attention to when upgrading TDengine from older versions to 2.0 and above? ☆☆☆ + +Version 2.0 is a complete refactoring of the previous version, and the configuration and data files are incompatible. Be sure to do the following before upgrading: + +1. Delete the configuration file, execute sudo rm `-rf /etc/taos/taos.cfg` +2. Delete the log file, execute `sudo rm -rf /var/log/taos/` +3. By ensuring that the data is no longer needed, delete the data file and execute `sudo rm -rf /var/lib/taos/` +4. Install the latest stable version of TDengine +5. If you need to migrate data or the data file is corrupted, please contact the official technical support team of TAOS Data to assist + +## 2. When encoutered with the error " Unable to establish connection " in Windows, what can I do? + +See the [technical blog](https://www.taosdata.com/blog/2019/12/03/jdbcdriver%E6%89%BE%E4%B8%8D%E5%88%B0%E5%8A%A8%E6%80%81%E9%93%BE%E6%8E%A5%E5%BA%93/) for this issue. + +## 3. Why I get “more dnodes are needed” when create a table? + +See the [technical blog](https://www.taosdata.com/blog/2019/12/03/%E5%88%9B%E5%BB%BA%E6%95%B0%E6%8D%AE%E8%A1%A8%E6%97%B6%E6%8F%90%E7%A4%BAmore-dnodes-are-needed/) for this issue. + +## 4. How do I generate a core file when TDengine crashes? + +See the [technical blog](https://www.taosdata.com/blog/2019/12/06/tdengine-crash%E6%97%B6%E7%94%9F%E6%88%90core%E6%96%87%E4%BB%B6%E7%9A%84%E6%96%B9%E6%B3%95/) for this issue. + +## 5. What should I do if I encounter an error "Unable to establish connection"? + +When the client encountered a connection failure, please follow the following steps to check: + +1. Check your network environment + +2. - Cloud server: Check whether the security group of the cloud server opens access to TCP/UDP ports 6030-6042 + - Local virtual machine: Check whether the network can be pinged, and try to avoid using localhost as hostname + - Corporate server: If you are in a NAT network environment, be sure to check whether the server can return messages to the client + +2. Make sure that the client and server version numbers are exactly the same, and the open source Community Edition and Enterprise Edition cannot be mixed. +3. On the server, execute systemctl status taosd to check the running status of *taosd*. If not running, start *taosd*. +4. Verify that the correct server FQDN (Fully Qualified Domain Name, which is available by executing the Linux command hostname-f on the server) is specified when the client connects. FQDN configuration reference: "[All about FQDN of TDengine](https://www.taosdata.com/blog/2020/09/11/1824.html)". +5. Ping the server FQDN. If there is no response, please check your network, DNS settings, or the system hosts file of the computer where the client is located. +6. Check the firewall settings (Ubuntu uses ufw status, CentOS uses firewall-cmd-list-port) to confirm that TCP/UDP ports 6030-6042 are open. +7. For JDBC (ODBC, Python, Go and other interfaces are similar) connections on Linux, make sure that libtaos.so is in the directory /usr/local/taos/driver, and /usr/local/taos/driver is in the system library function search path LD_LIBRARY_PATH. +8. For JDBC, ODBC, Python, Go, etc. connections on Windows, make sure that C:\ TDengine\ driver\ taos.dll is in your system library function search directory (it is recommended that taos.dll be placed in the directory C:\ Windows\ System32) +9. If the connection issue still exist + +1. - On Linux system, please use the command line tool nc to determine whether the TCP and UDP connections on the specified ports are unobstructed. Check whether the UDP port connection works: nc -vuz {hostIP} {port} Check whether the server-side TCP port connection works: nc -l {port}Check whether the client-side TCP port connection works: nc {hostIP} {port} + - Windows systems use the PowerShell command Net-TestConnection-ComputerName {fqdn} Port {port} to detect whether the service-segment port is accessed + +10. You can also use the built-in network connectivity detection function of taos program to verify whether the specified port connection between the server and the client is unobstructed (including TCP and UDP): [TDengine's Built-in Network Detection Tool Use Guide](https://www.taosdata.com/blog/2020/09/08/1816.html). + + + +## 6.What to do if I encounter an error "Unexpected generic error in RPC" or "TDengine error: Unable to resolve FQDN"? + +This error occurs because the client or data node cannot parse the FQDN (Fully Qualified Domain Name). For TAOS shell or client applications, check the following: + +1. Please verify whether the FQDN of the connected server is correct. FQDN configuration reference: "[All about FQDN of TDengine](https://www.taosdata.com/blog/2020/09/11/1824.html)". +2. If the network is configured with a DNS server, check that it is working properly. +3. If the network does not have a DNS server configured, check the hosts file of the machine where the client is located to see if the FQDN is configured and has the correct IP address. +4. If the network configuration is OK, from the machine where the client is located, you need to be able to ping the connected FQDN, otherwise the client cannot connect to the server + +## 7.Although the syntax is corrected, why do I still get the “Invalid SQL" error? + +If you confirm that the syntax is correct, for versions older than 2.0, please check whether the SQL statement length exceeds 64K. If it does, this error will also be returned. + +## 8. Are “validation queries” supported? + +The TDengine does not yet have a dedicated set of validation queries. However, it is recommended to use the database "log" monitored by the system. + +## 9. Can I delete or update a record? + +TDengine does not support the deletion function at present, and may support it in the future according to user requirements. + +Starting from 2.0. 8.0, TDengine supports the function of updating written data. Using the update function requires using UPDATE 1 parameter when creating the database, and then you can use INSERT INTO command to update the same timestamp data that has been written. UPDATE parameter does not support ALTER DATABASE command modification. Without a database created using UPDATE 1 parameter, writing data with the same timestamp will not modify the previous data with no error reported. + +It should also be noted that when UPDATE is set to 0, the data with the same timestamp sent later will be discarded directly, but no error will be reported, and will still be included in affected rows (so the return information of INSERT instruction cannot be used for timestamp duplicate checking). The main reason for this design is that TDengine regards the written data as a stream. Regardless of whether the timestamp conflicts or not, TDengine believes that the original device that generates the data actually generates such data. The UPDATE parameter only controls how such stream data should be processed when persistence-when UPDATE is 0, it means that the data written first overwrites the data written later; When UPDATE is 1, it means that the data written later overwrites the data written first. How to choose this coverage relationship depends on whether the data generated first or later is expected in the subsequent use and statistics compile. + +## 10. How to create a table with more than 1024 columns? + +Using version 2.0 and above, 1024 columns are supported by default; for older versions, TDengine allowed the creation of a table with a maximum of 250 columns. However, if the limit is exceeded, it is recommended to logically split this wide table into several small ones according to the data characteristics. + +## 11. What is the most effective way to write data? + +Insert in batches. Each write statement can insert multiple records into one or multiple tables at the same time. + +## 12. What is the most effective way to write data? How to solve the problem that Chinese characters in nchar inserted under Windows systems are parsed into messy code? + +If there are Chinese characters in nchar data under Windows, please first confirm that the region of the system is set to China (which can be set in the Control Panel), then the taos client in cmd should already support it normally; If you are developing Java applications in an IDE, such as Eclipse and Intellij, please confirm that the file code in the IDE is GBK (this is the default coding type of Java), and then initialize the configuration of the client when generating the Connection. The specific statement is as follows: + +```JAVA +Class.forName("com.taosdata.jdbc.TSDBDriver"); +Properties properties = new Properties(); +properties.setProperty(TSDBDriver.LOCALE_KEY, "UTF-8"); +Connection = DriverManager.getConnection(url, properties); +``` + +## 13. JDBC error: the excluded SQL is not a DML or a DDL? + +Please update to the latest JDBC driver. + +```xml + + com.taosdata.jdbc + taos-jdbcdriver + 2.0.27 + +``` + +## 14. taos connect failed, reason: invalid timestamp. + +The common reason is that the server time and client time are not calibrated, which can be calibrated by synchronizing with the time server (use ntpdate command under Linux, and select automatic synchronization in the Windows time setting). + +## 15. Incomplete display of table name + +Due to the limited display width of taos shell in the terminal, it is possible that a relatively long table name is not displayed completely. If relevant operations are carried out according to the displayed incomplete table name, a Table does not exist error will occur. The workaround can be by modifying the setting option maxBinaryDisplayWidth in the taos.cfg file, or directly entering the command `set max_binary_display_width 100`. Or, use the \\G parameter at the end of the command to adjust how the results are displayed. + +## 16. How to migrate data? + +TDengine uniquely identifies a machine according to hostname. When moving data files from machine A to machine B, pay attention to the following three points: + +- For versions 2.0. 0.0 to 2.0. 6. x, reconfigure machine B's hostname to machine A's. +- For 2.0. 7.0 and later versions, go to/var/lib/taos/dnode, repair the FQDN corresponding to dnodeId of dnodeEps.json, and restart. Make sure this file is identical for all machines. +- The storage structures of versions 1. x and 2. x are incompatible, and it is necessary to use migration tools or your own application to export and import data. + +## 17. How to temporarily adjust the log level in command line program taos? + +For the convenience of debugging, since version 2.0. 16, command line program taos gets two new instructions related to logging: + +```mysql +ALTER LOCAL flag_name flag_value; +``` + +This means that under the current command line program, modify the loglevel of a specific module (only valid for the current command line program, if taos is restarted, it needs to be reset): + +- The values of flag_name can be: debugFlag, cDebugFlag, tmrDebugFlag, uDebugFlag, rpcDebugFlag +- Flag_value values can be: 131 (output error and alarm logs), 135 (output error, alarm, and debug logs), 143 (output error, alarm, debug, and trace logs) + +```mysql +ALTER LOCAL RESETLOG; +``` + +This means wiping up all client-generated log files on the machine. + diff --git a/documentation20/en/images/architecture/dnode.png b/documentation20/en/images/architecture/dnode.png new file mode 100644 index 0000000000000000000000000000000000000000..cea87dcccba5d2761996e5dde998022d86487eb9 Binary files /dev/null and b/documentation20/en/images/architecture/dnode.png differ diff --git a/documentation20/en/images/architecture/message.png b/documentation20/en/images/architecture/message.png new file mode 100644 index 0000000000000000000000000000000000000000..715a8bd37ee9fe7e96eacce4e7ff563fedeefbee Binary files /dev/null and b/documentation20/en/images/architecture/message.png differ diff --git a/documentation20/en/images/architecture/modules.png b/documentation20/en/images/architecture/modules.png new file mode 100644 index 0000000000000000000000000000000000000000..10ae4703a6cbbf66afea325ce4c0f919f7769a07 Binary files /dev/null and b/documentation20/en/images/architecture/modules.png differ diff --git a/documentation20/en/images/architecture/multi_tables.png b/documentation20/en/images/architecture/multi_tables.png new file mode 100644 index 0000000000000000000000000000000000000000..0cefaab6a9a4cdd671c671f7c6186dea41415ff0 Binary files /dev/null and b/documentation20/en/images/architecture/multi_tables.png differ diff --git a/documentation20/en/images/architecture/replica-forward.png b/documentation20/en/images/architecture/replica-forward.png new file mode 100644 index 0000000000000000000000000000000000000000..bf616e030b130603eceb5dccfd30b4a1dfa68ea5 Binary files /dev/null and b/documentation20/en/images/architecture/replica-forward.png differ diff --git a/documentation20/en/images/architecture/replica-master.png b/documentation20/en/images/architecture/replica-master.png new file mode 100644 index 0000000000000000000000000000000000000000..cb33f1ce98661563693215d8fc73b003235c7668 Binary files /dev/null and b/documentation20/en/images/architecture/replica-master.png differ diff --git a/documentation20/en/images/architecture/replica-restore.png b/documentation20/en/images/architecture/replica-restore.png new file mode 100644 index 0000000000000000000000000000000000000000..1558e5ed0108d23efdc6b5d9ea0e44a1dff45d28 Binary files /dev/null and b/documentation20/en/images/architecture/replica-restore.png differ diff --git a/documentation20/en/images/architecture/structure.png b/documentation20/en/images/architecture/structure.png new file mode 100644 index 0000000000000000000000000000000000000000..4fc8f47ab0a30d95b85ba1d85105726ed981e56e Binary files /dev/null and b/documentation20/en/images/architecture/structure.png differ diff --git a/documentation20/en/images/architecture/vnode.png b/documentation20/en/images/architecture/vnode.png new file mode 100644 index 0000000000000000000000000000000000000000..e6148d4907cf9a18bc52251f712d5c685651b7f5 Binary files /dev/null and b/documentation20/en/images/architecture/vnode.png differ diff --git a/documentation20/en/images/architecture/write_master.png b/documentation20/en/images/architecture/write_master.png new file mode 100644 index 0000000000000000000000000000000000000000..ff2dfc20bfc2ecf956a2aab1a8965a7bbcae4387 Binary files /dev/null and b/documentation20/en/images/architecture/write_master.png differ diff --git a/documentation20/en/images/architecture/write_slave.png b/documentation20/en/images/architecture/write_slave.png new file mode 100644 index 0000000000000000000000000000000000000000..cacb2cb6bcc4f4d934e979862387e1345bbac078 Binary files /dev/null and b/documentation20/en/images/architecture/write_slave.png differ diff --git a/documentation20/en/images/connections/add_datasource1.jpg b/documentation20/en/images/connections/add_datasource1.jpg new file mode 100644 index 0000000000000000000000000000000000000000..1f0f5110f312c57f3ec1788bbc02f04fac6ac142 Binary files /dev/null and b/documentation20/en/images/connections/add_datasource1.jpg differ diff --git a/documentation20/en/images/connections/add_datasource2.jpg b/documentation20/en/images/connections/add_datasource2.jpg new file mode 100644 index 0000000000000000000000000000000000000000..fa7a83e00e96fae649910dff4edf5f5bdadd7850 Binary files /dev/null and b/documentation20/en/images/connections/add_datasource2.jpg differ diff --git a/documentation20/en/images/connections/add_datasource3.jpg b/documentation20/en/images/connections/add_datasource3.jpg new file mode 100644 index 0000000000000000000000000000000000000000..fc850ad08ff1174de972906842e0d5ee64e6e5cb Binary files /dev/null and b/documentation20/en/images/connections/add_datasource3.jpg differ diff --git a/documentation20/en/images/connections/add_datasource4.jpg b/documentation20/en/images/connections/add_datasource4.jpg new file mode 100644 index 0000000000000000000000000000000000000000..3ba73e50d455111f8621f4165746078554c2d790 Binary files /dev/null and b/documentation20/en/images/connections/add_datasource4.jpg differ diff --git a/documentation20/en/images/connections/create_dashboard1.jpg b/documentation20/en/images/connections/create_dashboard1.jpg new file mode 100644 index 0000000000000000000000000000000000000000..3b83c3a1714e9e7540e0b06239ef7c1c4f63fe2c Binary files /dev/null and b/documentation20/en/images/connections/create_dashboard1.jpg differ diff --git a/documentation20/en/images/connections/create_dashboard2.jpg b/documentation20/en/images/connections/create_dashboard2.jpg new file mode 100644 index 0000000000000000000000000000000000000000..fe5d768ac55254251e0290bf257178f5ff28f5a5 Binary files /dev/null and b/documentation20/en/images/connections/create_dashboard2.jpg differ diff --git a/documentation20/en/images/connections/import_dashboard1.jpg b/documentation20/en/images/connections/import_dashboard1.jpg new file mode 100644 index 0000000000000000000000000000000000000000..9d2ce7ed65eb0c2c729de50283b30491793493dc Binary files /dev/null and b/documentation20/en/images/connections/import_dashboard1.jpg differ diff --git a/documentation20/en/images/connections/import_dashboard2.jpg b/documentation20/en/images/connections/import_dashboard2.jpg new file mode 100644 index 0000000000000000000000000000000000000000..94b09f0ee39552bb84f7ba1f65815ce2c9548b2d Binary files /dev/null and b/documentation20/en/images/connections/import_dashboard2.jpg differ diff --git a/documentation20/en/images/connector.png b/documentation20/en/images/connector.png new file mode 100644 index 0000000000000000000000000000000000000000..6030bd73f51123615eabacfa5d734918559ce3d9 Binary files /dev/null and b/documentation20/en/images/connector.png differ diff --git a/documentation20/en/images/eco_system.png b/documentation20/en/images/eco_system.png new file mode 100644 index 0000000000000000000000000000000000000000..bf8bf8f1e0a2311fc12202d712a8a2f9b8ce419b Binary files /dev/null and b/documentation20/en/images/eco_system.png differ diff --git a/documentation20/en/images/tdengine-jdbc-connector.png b/documentation20/en/images/tdengine-jdbc-connector.png new file mode 100644 index 0000000000000000000000000000000000000000..fdf1dd3fcc5ee222c4a8753efa2c95c5257314bf Binary files /dev/null and b/documentation20/en/images/tdengine-jdbc-connector.png differ diff --git a/src/client/inc/tscUtil.h b/src/client/inc/tscUtil.h index f747184ce017e9cb780ba2a61b87360cee0379d8..2c4d711520471cb3c1cc6acc308479593a24c0f6 100644 --- a/src/client/inc/tscUtil.h +++ b/src/client/inc/tscUtil.h @@ -123,6 +123,7 @@ int32_t tscGetDataBlockFromList(SHashObj* pHashList, int64_t id, int32_t size, i */ bool tscIsPointInterpQuery(SQueryInfo* pQueryInfo); bool tscIsTWAQuery(SQueryInfo* pQueryInfo); +bool tscIsDiffQuery(SQueryInfo* pQueryInfo); bool tscIsSessionWindowQuery(SQueryInfo* pQueryInfo); bool tscIsSecondStageQuery(SQueryInfo* pQueryInfo); bool tsIsArithmeticQueryOnAggResult(SQueryInfo* pQueryInfo); @@ -132,12 +133,12 @@ bool hasTagValOutput(SQueryInfo* pQueryInfo); bool timeWindowInterpoRequired(SQueryInfo *pQueryInfo); bool isStabledev(SQueryInfo* pQueryInfo); bool isTsCompQuery(SQueryInfo* pQueryInfo); -bool isSimpleAggregate(SQueryInfo* pQueryInfo); bool isBlockDistQuery(SQueryInfo* pQueryInfo); bool isSimpleAggregateRv(SQueryInfo* pQueryInfo); bool tscNonOrderedProjectionQueryOnSTable(SQueryInfo *pQueryInfo, int32_t tableIndex); bool tscOrderedProjectionQueryOnSTable(SQueryInfo* pQueryInfo, int32_t tableIndex); +bool tscIsDiffDerivQuery(SQueryInfo* pQueryInfo); bool tscIsProjectionQueryOnSTable(SQueryInfo* pQueryInfo, int32_t tableIndex); bool tscIsProjectionQuery(SQueryInfo* pQueryInfo); @@ -214,7 +215,7 @@ void tscColumnListDestroy(SArray* pColList); void tscColumnListCopy(SArray* dst, const SArray* src, uint64_t tableUid); void tscColumnListCopyAll(SArray* dst, const SArray* src); -void convertQueryResult(SSqlRes* pRes, SQueryInfo* pQueryInfo); +void convertQueryResult(SSqlRes* pRes, SQueryInfo* pQueryInfo, uint64_t objId); void tscDequoteAndTrimToken(SStrToken* pToken); int32_t tscValidateName(SStrToken* pToken); @@ -329,9 +330,7 @@ STableMeta* tscTableMetaDup(STableMeta* pTableMeta); SVgroupsInfo* tscVgroupsInfoDup(SVgroupsInfo* pVgroupsInfo); int32_t tscCreateQueryFromQueryInfo(SQueryInfo* pQueryInfo, SQueryAttr* pQueryAttr, void* addr); - -void tsCreateSQLFunctionCtx(SQueryInfo* pQueryInfo, SQLFunctionCtx* pCtx, SSchema* pSchema); -void* createQInfoFromQueryNode(SQueryInfo* pQueryInfo, STableGroupInfo* pTableGroupInfo, SOperatorInfo* pOperator, char* sql, void* addr, int32_t stage); +void* createQInfoFromQueryNode(SQueryInfo* pQueryInfo, STableGroupInfo* pTableGroupInfo, SOperatorInfo* pOperator, char* sql, void* addr, int32_t stage, uint64_t qId); void* malloc_throw(size_t size); void* calloc_throw(size_t nmemb, size_t size); diff --git a/src/client/inc/tsclient.h b/src/client/inc/tsclient.h index c002f2cf323a03ec024f4ebc41e04ac7e6c07571..ec4bf5252783cd9df31d820bff1277fb2ba25afb 100644 --- a/src/client/inc/tsclient.h +++ b/src/client/inc/tsclient.h @@ -266,6 +266,7 @@ typedef struct SSqlObj { typedef struct SSqlStream { SSqlObj *pSql; + void * cqhandle; // stream belong to SCQContext handle const char* dstTable; uint32_t streamId; char listed; @@ -320,7 +321,7 @@ int32_t tscCreateResPointerInfo(SSqlRes *pRes, SQueryInfo *pQueryInfo); void tscSetResRawPtr(SSqlRes* pRes, SQueryInfo* pQueryInfo); void tscSetResRawPtrRv(SSqlRes* pRes, SQueryInfo* pQueryInfo, SSDataBlock* pBlock); -void handleDownstreamOperator(SSqlObj** pSqlList, int32_t numOfUpstream, SQueryInfo* px, SSqlRes* pOutput); +void handleDownstreamOperator(SSqlObj** pSqlList, int32_t numOfUpstream, SQueryInfo* px, SSqlObj* pParent); void destroyTableNameList(SInsertStatementParam* pInsertParam); void tscResetSqlCmd(SSqlCmd *pCmd, bool removeMeta); diff --git a/src/client/src/tscAsync.c b/src/client/src/tscAsync.c index 15276a38887523541cbe37ebf1add2152d2ffe80..d857d00e159d06df266187693913a6b6e404a2b3 100644 --- a/src/client/src/tscAsync.c +++ b/src/client/src/tscAsync.c @@ -144,7 +144,7 @@ static void tscAsyncFetchRowsProxy(void *param, TAOS_RES *tres, int numOfRows) { } // local merge has handle this situation during super table non-projection query. - if (pCmd->command != TSDB_SQL_RETRIEVE_LOCALMERGE) { + if (pCmd->command != TSDB_SQL_RETRIEVE_GLOBALMERGE) { pRes->numOfClauseTotal += pRes->numOfRows; } @@ -174,7 +174,7 @@ static void tscProcessAsyncRetrieveImpl(void *param, TAOS_RES *tres, int numOfRo } pSql->fp = fp; - if (pCmd->command != TSDB_SQL_RETRIEVE_LOCALMERGE && pCmd->command < TSDB_SQL_LOCAL) { + if (pCmd->command != TSDB_SQL_RETRIEVE_GLOBALMERGE && pCmd->command < TSDB_SQL_LOCAL) { pCmd->command = (pCmd->command > TSDB_SQL_MGMT) ? TSDB_SQL_RETRIEVE : TSDB_SQL_FETCH; } @@ -257,14 +257,14 @@ void taos_fetch_rows_a(TAOS_RES *tres, __async_cb_func_t fp, void *param) { } return; - } else if (pCmd->command == TSDB_SQL_RETRIEVE || pCmd->command == TSDB_SQL_RETRIEVE_LOCALMERGE) { + } else if (pCmd->command == TSDB_SQL_RETRIEVE || pCmd->command == TSDB_SQL_RETRIEVE_GLOBALMERGE) { // in case of show command, return no data (*pSql->fetchFp)(param, pSql, 0); } else { assert(0); } } else { // current query is not completed, continue retrieve from node - if (pCmd->command != TSDB_SQL_RETRIEVE_LOCALMERGE && pCmd->command < TSDB_SQL_LOCAL) { + if (pCmd->command != TSDB_SQL_RETRIEVE_GLOBALMERGE && pCmd->command < TSDB_SQL_LOCAL) { pCmd->command = (pCmd->command > TSDB_SQL_MGMT) ? TSDB_SQL_RETRIEVE : TSDB_SQL_FETCH; } diff --git a/src/client/src/tscLocal.c b/src/client/src/tscLocal.c index f97f54a6267d2754cb2edf2fd38ff6c075a2b285..2c9717306f2b26dfbbb5ec1d676b5baad3eb2d2d 100644 --- a/src/client/src/tscLocal.c +++ b/src/client/src/tscLocal.c @@ -323,7 +323,7 @@ TAOS_ROW tscFetchRow(void *param) { // current data set are exhausted, fetch more data from node if (pRes->row >= pRes->numOfRows && (pRes->completed != true || hasMoreVnodesToTry(pSql) || hasMoreClauseToTry(pSql)) && (pCmd->command == TSDB_SQL_RETRIEVE || - pCmd->command == TSDB_SQL_RETRIEVE_LOCALMERGE || + pCmd->command == TSDB_SQL_RETRIEVE_GLOBALMERGE || pCmd->command == TSDB_SQL_TABLE_JOIN_RETRIEVE || pCmd->command == TSDB_SQL_FETCH || pCmd->command == TSDB_SQL_SHOW || diff --git a/src/client/src/tscParseInsert.c b/src/client/src/tscParseInsert.c index cd9853df03bab1a953ee8fd79e66a52e84ba157c..a158162dc56af24e4a114f4926e0d339dddf553a 100644 --- a/src/client/src/tscParseInsert.c +++ b/src/client/src/tscParseInsert.c @@ -107,14 +107,10 @@ int tsParseTime(SStrToken *pToken, int64_t *time, char **next, char *error, int1 return tscInvalidOperationMsg(error, "value expected in timestamp", sToken.z); } - if (parseAbsoluteDuration(valueToken.z, valueToken.n, &interval) != TSDB_CODE_SUCCESS) { + if (parseAbsoluteDuration(valueToken.z, valueToken.n, &interval, timePrec) != TSDB_CODE_SUCCESS) { return TSDB_CODE_TSC_INVALID_OPERATION; } - if (timePrec == TSDB_TIME_PRECISION_MILLI) { - interval /= 1000; - } - if (sToken.type == TK_PLUS) { useconds += interval; } else { @@ -468,6 +464,10 @@ int tsParseOneRow(char **str, STableDataBlocks *pDataBlocks, int16_t timePrec, i int32_t cnt = 0; int32_t j = 0; + if (sToken.n >= TSDB_MAX_BYTES_PER_ROW) { + return tscSQLSyntaxErrMsg(pInsertParam->msg, "too long string", sToken.z); + } + for (uint32_t k = 1; k < sToken.n - 1; ++k) { if (sToken.z[k] == '\\' || (sToken.z[k] == delim && sToken.z[k + 1] == delim)) { tmpTokenBuf[j] = sToken.z[k + 1]; @@ -711,7 +711,7 @@ static int32_t doParseInsertStatement(SInsertStatementParam *pInsertParam, char } code = TSDB_CODE_TSC_INVALID_OPERATION; - char tmpTokenBuf[16*1024] = {0}; // used for deleting Escape character: \\, \', \" + char tmpTokenBuf[TSDB_MAX_BYTES_PER_ROW] = {0}; // used for deleting Escape character: \\, \', \" int32_t numOfRows = 0; code = tsParseValues(str, dataBuf, maxNumOfRows, pInsertParam, &numOfRows, tmpTokenBuf); diff --git a/src/client/src/tscPrepare.c b/src/client/src/tscPrepare.c index f199a5798779523e90e95bfce468a68b8afb6c6d..3f12bc811bd2508583397c37723b498c710088d1 100644 --- a/src/client/src/tscPrepare.c +++ b/src/client/src/tscPrepare.c @@ -78,6 +78,16 @@ typedef struct STscStmt { SNormalStmt normal; } STscStmt; +#define STMT_RET(c) do { \ + int32_t _code = c; \ + if (pStmt && pStmt->pSql) { pStmt->pSql->res.code = _code; } else {terrno = _code;} \ + return _code; \ +} while (0) + +static int32_t invalidOperationMsg(char* dstBuffer, const char* errMsg) { + return tscInvalidOperationMsg(dstBuffer, errMsg, NULL); +} + static int normalStmtAddPart(SNormalStmt* stmt, bool isParam, char* str, uint32_t len) { uint16_t size = stmt->numParts + 1; if (size > stmt->sizeParts) { @@ -163,8 +173,8 @@ static int normalStmtBindParam(STscStmt* stmt, TAOS_BIND* bind) { break; default: - tscDebug("0x%"PRIx64" bind column%d: type mismatch or invalid", stmt->pSql->self, i); - return TSDB_CODE_TSC_INVALID_VALUE; + tscError("0x%"PRIx64" bind column%d: type mismatch or invalid", stmt->pSql->self, i); + return invalidOperationMsg(tscGetErrorMsgPayload(&stmt->pSql->cmd), "bind type mismatch or invalid"); } } @@ -727,6 +737,7 @@ static int doBindParam(STableDataBlocks* pBlock, char* data, SParamInfo* param, #endif if (bind->buffer_type != param->type) { + tscError("column type mismatch"); return TSDB_CODE_TSC_INVALID_VALUE; } @@ -754,6 +765,7 @@ static int doBindParam(STableDataBlocks* pBlock, char* data, SParamInfo* param, case TSDB_DATA_TYPE_BINARY: if ((*bind->length) > (uintptr_t)param->bytes) { + tscError("column length is too big"); return TSDB_CODE_TSC_INVALID_VALUE; } size = (short)*bind->length; @@ -763,6 +775,7 @@ static int doBindParam(STableDataBlocks* pBlock, char* data, SParamInfo* param, case TSDB_DATA_TYPE_NCHAR: { int32_t output = 0; if (!taosMbsToUcs4(bind->buffer, *bind->length, varDataVal(data + param->offset), param->bytes - VARSTR_HEADER_SIZE, &output)) { + tscError("convert nchar failed"); return TSDB_CODE_TSC_INVALID_VALUE; } varDataSetLen(data + param->offset, output); @@ -787,6 +800,7 @@ static int doBindParam(STableDataBlocks* pBlock, char* data, SParamInfo* param, static int doBindBatchParam(STableDataBlocks* pBlock, SParamInfo* param, TAOS_MULTI_BIND* bind, int32_t rowNum) { if (bind->buffer_type != param->type || !isValidDataType(param->type)) { + tscError("column mismatch or invalid"); return TSDB_CODE_TSC_INVALID_VALUE; } @@ -892,8 +906,8 @@ static int insertStmtBindParam(STscStmt* stmt, TAOS_BIND* bind) { int code = doBindParam(pBlock, data, param, &bind[param->idx], 1); if (code != TSDB_CODE_SUCCESS) { - tscDebug("0x%"PRIx64" bind column %d: type mismatch or invalid", pStmt->pSql->self, param->idx); - return code; + tscDebug("0x%"PRIx64" bind column %d: type mismatch or invalid", pStmt->pSql->self, param->idx); + return invalidOperationMsg(tscGetErrorMsgPayload(&stmt->pSql->cmd), "bind column type mismatch or invalid"); } } @@ -957,13 +971,13 @@ static int insertStmtBindParamBatch(STscStmt* stmt, TAOS_MULTI_BIND* bind, int c SParamInfo* param = &pBlock->params[j]; if (bind[param->idx].num != rowNum) { tscError("0x%"PRIx64" param %d: num[%d:%d] not match", pStmt->pSql->self, param->idx, rowNum, bind[param->idx].num); - return TSDB_CODE_TSC_INVALID_VALUE; + return invalidOperationMsg(tscGetErrorMsgPayload(&stmt->pSql->cmd), "bind row num mismatch"); } int code = doBindBatchParam(pBlock, param, &bind[param->idx], pCmd->batchSize); if (code != TSDB_CODE_SUCCESS) { tscError("0x%"PRIx64" bind column %d: type mismatch or invalid", pStmt->pSql->self, param->idx); - return code; + return invalidOperationMsg(tscGetErrorMsgPayload(&stmt->pSql->cmd), "bind column type mismatch or invalid"); } } @@ -974,7 +988,7 @@ static int insertStmtBindParamBatch(STscStmt* stmt, TAOS_MULTI_BIND* bind, int c int code = doBindBatchParam(pBlock, param, bind, pCmd->batchSize); if (code != TSDB_CODE_SUCCESS) { tscError("0x%"PRIx64" bind column %d: type mismatch or invalid", pStmt->pSql->self, param->idx); - return code; + return invalidOperationMsg(tscGetErrorMsgPayload(&stmt->pSql->cmd), "bind column type mismatch or invalid"); } if (colIdx == (pBlock->numOfParams - 1)) { @@ -993,7 +1007,7 @@ static int insertStmtUpdateBatch(STscStmt* stmt) { if (pCmd->batchSize > INT16_MAX) { tscError("too many record:%d", pCmd->batchSize); - return TSDB_CODE_TSC_APP_ERROR; + return invalidOperationMsg(tscGetErrorMsgPayload(&stmt->pSql->cmd), "too many records"); } if (taosHashGetSize(pCmd->insertParam.pTableBlockHashList) == 0) { @@ -1057,7 +1071,8 @@ static int insertStmtReset(STscStmt* pStmt) { static int insertStmtExecute(STscStmt* stmt) { SSqlCmd* pCmd = &stmt->pSql->cmd; if (pCmd->batchSize == 0) { - return TSDB_CODE_TSC_INVALID_VALUE; + tscError("no records bind"); + return invalidOperationMsg(tscGetErrorMsgPayload(&stmt->pSql->cmd), "no records bind"); } if (taosHashGetSize(pCmd->insertParam.pTableBlockHashList) == 0) { @@ -1174,7 +1189,7 @@ static int insertBatchStmtExecute(STscStmt* pStmt) { if(pStmt->mtb.nameSet == false) { tscError("0x%"PRIx64" no table name set", pStmt->pSql->self); - return TSDB_CODE_TSC_APP_ERROR; + return invalidOperationMsg(tscGetErrorMsgPayload(&pStmt->pSql->cmd), "no table name set"); } pStmt->pSql->retry = pStmt->pSql->maxRetry + 1; //no retry @@ -1215,7 +1230,8 @@ int stmtParseInsertTbTags(SSqlObj* pSql, STscStmt* pStmt) { int32_t index = 0; SStrToken sToken = tStrGetToken(pCmd->insertParam.sql, &index, false); if (sToken.n == 0) { - return TSDB_CODE_TSC_INVALID_OPERATION; + tscError("table is is expected, sql:%s", pCmd->insertParam.sql); + return tscSQLSyntaxErrMsg(pCmd->payload, "table name is expected", pCmd->insertParam.sql); } if (sToken.n == 1 && sToken.type == TK_QUESTION) { @@ -1237,24 +1253,28 @@ int stmtParseInsertTbTags(SSqlObj* pSql, STscStmt* pStmt) { return TSDB_CODE_SUCCESS; } - if (sToken.n <= 0 || sToken.type != TK_USING) { - return tscSQLSyntaxErrMsg(pCmd->payload, "keywords USING is expected", sToken.z); + if (sToken.n <= 0 || sToken.type != TK_USING) { + tscError("keywords USING is expected, sql:%s", pCmd->insertParam.sql); + return tscSQLSyntaxErrMsg(pCmd->payload, "keywords USING is expected", sToken.z ? sToken.z : pCmd->insertParam.sql); } sToken = tStrGetToken(pCmd->insertParam.sql, &index, false); if (sToken.n <= 0 || ((sToken.type != TK_ID) && (sToken.type != TK_STRING))) { - return tscSQLSyntaxErrMsg(pCmd->payload, "invalid token", sToken.z); + tscError("invalid token, sql:%s", pCmd->insertParam.sql); + return tscSQLSyntaxErrMsg(pCmd->payload, "invalid token", sToken.z ? sToken.z : pCmd->insertParam.sql); } pStmt->mtb.stbname = sToken; sToken = tStrGetToken(pCmd->insertParam.sql, &index, false); if (sToken.n <= 0 || sToken.type != TK_TAGS) { - return tscSQLSyntaxErrMsg(pCmd->payload, "keyword TAGS expected", sToken.z); + tscError("keyword TAGS expected, sql:%s", pCmd->insertParam.sql); + return tscSQLSyntaxErrMsg(pCmd->payload, "keyword TAGS expected", sToken.z ? sToken.z : pCmd->insertParam.sql); } sToken = tStrGetToken(pCmd->insertParam.sql, &index, false); if (sToken.n <= 0 || sToken.type != TK_LP) { - return tscSQLSyntaxErrMsg(pCmd->payload, ") expected", sToken.z); + tscError("( expected, sql:%s", pCmd->insertParam.sql); + return tscSQLSyntaxErrMsg(pCmd->payload, "( expected", sToken.z ? sToken.z : pCmd->insertParam.sql); } pStmt->mtb.tags = taosArrayInit(4, sizeof(SStrToken)); @@ -1264,7 +1284,8 @@ int stmtParseInsertTbTags(SSqlObj* pSql, STscStmt* pStmt) { while (loopCont) { sToken = tStrGetToken(pCmd->insertParam.sql, &index, false); if (sToken.n <= 0) { - return TSDB_CODE_TSC_INVALID_OPERATION; + tscError("unexpected sql end, sql:%s", pCmd->insertParam.sql); + return tscSQLSyntaxErrMsg(pCmd->payload, "unexpected sql end", pCmd->insertParam.sql); } switch (sToken.type) { @@ -1272,7 +1293,8 @@ int stmtParseInsertTbTags(SSqlObj* pSql, STscStmt* pStmt) { loopCont = 0; break; case TK_VALUES: - return TSDB_CODE_TSC_INVALID_OPERATION; + tscError("unexpected token values, sql:%s", pCmd->insertParam.sql); + return tscSQLSyntaxErrMsg(pCmd->payload, "unexpected token", sToken.z); case TK_QUESTION: pStmt->mtb.tagSet = false; //continue default: @@ -1282,12 +1304,14 @@ int stmtParseInsertTbTags(SSqlObj* pSql, STscStmt* pStmt) { } if (taosArrayGetSize(pStmt->mtb.tags) <= 0) { - return TSDB_CODE_TSC_INVALID_OPERATION; + tscError("no tags, sql:%s", pCmd->insertParam.sql); + return tscSQLSyntaxErrMsg(pCmd->payload, "no tags", pCmd->insertParam.sql); } sToken = tStrGetToken(pCmd->insertParam.sql, &index, false); if (sToken.n <= 0 || (sToken.type != TK_VALUES && sToken.type != TK_LP)) { - return TSDB_CODE_TSC_INVALID_OPERATION; + tscError("sql error, sql:%s", pCmd->insertParam.sql); + return tscSQLSyntaxErrMsg(pCmd->payload, "sql error", sToken.z ? sToken.z : pCmd->insertParam.sql); } pStmt->mtb.values = sToken; @@ -1329,8 +1353,8 @@ int stmtGenInsertStatement(SSqlObj* pSql, STscStmt* pStmt, const char* name, TAO } else { if (tags[j].buffer == NULL) { free(str); - tscError("empty"); - return TSDB_CODE_TSC_APP_ERROR; + tscError("empty tag value in params"); + return invalidOperationMsg(tscGetErrorMsgPayload(&pStmt->pSql->cmd), "empty tag value in params"); } ret = converToStr(str + len, tags[j].buffer_type, tags[j].buffer, tags[j].length ? (int32_t)*tags[j].length : -1, &l); @@ -1387,13 +1411,15 @@ int stmtGenInsertStatement(SSqlObj* pSql, STscStmt* pStmt, const char* name, TAO TAOS_STMT* taos_stmt_init(TAOS* taos) { STscObj* pObj = (STscObj*)taos; + STscStmt* pStmt = NULL; + if (pObj == NULL || pObj->signature != pObj) { terrno = TSDB_CODE_TSC_DISCONNECTED; tscError("connection disconnected"); return NULL; } - STscStmt* pStmt = calloc(1, sizeof(STscStmt)); + pStmt = calloc(1, sizeof(STscStmt)); if (pStmt == NULL) { terrno = TSDB_CODE_TSC_OUT_OF_MEMORY; tscError("failed to allocate memory for statement"); @@ -1410,6 +1436,14 @@ TAOS_STMT* taos_stmt_init(TAOS* taos) { return NULL; } + if (TSDB_CODE_SUCCESS != tscAllocPayload(&pSql->cmd, TSDB_DEFAULT_PAYLOAD_SIZE)) { + free(pSql); + free(pStmt); + terrno = TSDB_CODE_TSC_OUT_OF_MEMORY; + tscError("failed to malloc payload buffer"); + return NULL; + } + tsem_init(&pSql->rspSem, 0, 0); pSql->signature = pSql; pSql->pTscObj = pObj; @@ -1425,13 +1459,12 @@ int taos_stmt_prepare(TAOS_STMT* stmt, const char* sql, unsigned long length) { STscStmt* pStmt = (STscStmt*)stmt; if (stmt == NULL || pStmt->taos == NULL || pStmt->pSql == NULL) { - terrno = TSDB_CODE_TSC_DISCONNECTED; - return TSDB_CODE_TSC_DISCONNECTED; + STMT_RET(TSDB_CODE_TSC_DISCONNECTED); } if (pStmt->last != STMT_INIT) { tscError("prepare status error, last:%d", pStmt->last); - return TSDB_CODE_TSC_APP_ERROR; + STMT_RET(invalidOperationMsg(tscGetErrorMsgPayload(&pStmt->pSql->cmd), "prepare status error")); } pStmt->last = STMT_PREPARE; @@ -1447,17 +1480,11 @@ int taos_stmt_prepare(TAOS_STMT* stmt, const char* sql, unsigned long length) { pCmd->insertParam.insertType = TSDB_QUERY_TYPE_STMT_INSERT; - if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, TSDB_DEFAULT_PAYLOAD_SIZE)) { - tscError("%p failed to malloc payload buffer", pSql); - return TSDB_CODE_TSC_OUT_OF_MEMORY; - } - pSql->sqlstr = realloc(pSql->sqlstr, sqlLen + 1); if (pSql->sqlstr == NULL) { tscError("%p failed to malloc sql string buffer", pSql); - free(pCmd->payload); - return TSDB_CODE_TSC_OUT_OF_MEMORY; + STMT_RET(TSDB_CODE_TSC_OUT_OF_MEMORY); } pRes->qId = 0; @@ -1476,11 +1503,11 @@ int taos_stmt_prepare(TAOS_STMT* stmt, const char* sql, unsigned long length) { int32_t ret = stmtParseInsertTbTags(pSql, pStmt); if (ret != TSDB_CODE_SUCCESS) { - return ret; + STMT_RET(ret); } if (pStmt->multiTbInsert) { - return TSDB_CODE_SUCCESS; + STMT_RET(TSDB_CODE_SUCCESS); } memset(&pStmt->mtb, 0, sizeof(pStmt->mtb)); @@ -1489,14 +1516,14 @@ int taos_stmt_prepare(TAOS_STMT* stmt, const char* sql, unsigned long length) { if (code == TSDB_CODE_TSC_ACTION_IN_PROGRESS) { // wait for the callback function to post the semaphore tsem_wait(&pSql->rspSem); - return pSql->res.code; + STMT_RET(pSql->res.code); } - return code; + STMT_RET(code); } pStmt->isInsert = false; - return normalStmtPrepare(pStmt); + STMT_RET(normalStmtPrepare(pStmt)); } int taos_stmt_set_tbname_tags(TAOS_STMT* stmt, const char* name, TAOS_BIND* tags) { @@ -1505,25 +1532,22 @@ int taos_stmt_set_tbname_tags(TAOS_STMT* stmt, const char* name, TAOS_BIND* tags SSqlCmd* pCmd = &pSql->cmd; if (stmt == NULL || pStmt->pSql == NULL || pStmt->taos == NULL) { - terrno = TSDB_CODE_TSC_DISCONNECTED; - return TSDB_CODE_TSC_DISCONNECTED; + STMT_RET(TSDB_CODE_TSC_DISCONNECTED); } if (name == NULL) { - terrno = TSDB_CODE_TSC_APP_ERROR; tscError("0x%"PRIx64" name is NULL", pSql->self); - return TSDB_CODE_TSC_APP_ERROR; + STMT_RET(invalidOperationMsg(tscGetErrorMsgPayload(&pStmt->pSql->cmd), "name is NULL")); } if (pStmt->multiTbInsert == false || !tscIsInsertData(pSql->sqlstr)) { - terrno = TSDB_CODE_TSC_APP_ERROR; - tscError("0x%"PRIx64" not multi table insert", pSql->self); - return TSDB_CODE_TSC_APP_ERROR; + tscError("0x%"PRIx64" not multiple table insert", pSql->self); + STMT_RET(invalidOperationMsg(tscGetErrorMsgPayload(&pStmt->pSql->cmd), "not multiple table insert")); } if (pStmt->last == STMT_INIT || pStmt->last == STMT_BIND || pStmt->last == STMT_BIND_COL) { - tscError("0x%"PRIx64" settbname status error, last:%d", pSql->self, pStmt->last); - return TSDB_CODE_TSC_APP_ERROR; + tscError("0x%"PRIx64" set_tbname_tags status error, last:%d", pSql->self, pStmt->last); + STMT_RET(invalidOperationMsg(tscGetErrorMsgPayload(&pStmt->pSql->cmd), "set_tbname_tags status error")); } pStmt->last = STMT_SETTBNAME; @@ -1535,7 +1559,7 @@ int taos_stmt_set_tbname_tags(TAOS_STMT* stmt, const char* name, TAOS_BIND* tags STableDataBlocks** t1 = (STableDataBlocks**)taosHashGet(pStmt->mtb.pTableBlockHashList, (const char*)&pStmt->mtb.currentUid, sizeof(pStmt->mtb.currentUid)); if (t1 == NULL) { tscError("0x%"PRIx64" no table data block in hash list, uid:%" PRId64 , pSql->self, pStmt->mtb.currentUid); - return TSDB_CODE_TSC_APP_ERROR; + STMT_RET(TSDB_CODE_TSC_APP_ERROR); } SSubmitBlk* pBlk = (SSubmitBlk*) (*t1)->pData; @@ -1544,7 +1568,7 @@ int taos_stmt_set_tbname_tags(TAOS_STMT* stmt, const char* name, TAOS_BIND* tags taosHashPut(pCmd->insertParam.pTableBlockHashList, (void *)&pStmt->mtb.currentUid, sizeof(pStmt->mtb.currentUid), (void*)t1, POINTER_BYTES); tscDebug("0x%"PRIx64" table:%s is already prepared, uid:%" PRIu64, pSql->self, name, pStmt->mtb.currentUid); - return TSDB_CODE_SUCCESS; + STMT_RET(TSDB_CODE_SUCCESS); } if (pStmt->mtb.tagSet) { @@ -1552,12 +1576,12 @@ int taos_stmt_set_tbname_tags(TAOS_STMT* stmt, const char* name, TAOS_BIND* tags } else { if (tags == NULL) { tscError("No tags set"); - return TSDB_CODE_TSC_APP_ERROR; + STMT_RET(invalidOperationMsg(tscGetErrorMsgPayload(&pStmt->pSql->cmd), "no tags set")); } int32_t ret = stmtGenInsertStatement(pSql, pStmt, name, tags); if (ret != TSDB_CODE_SUCCESS) { - return ret; + STMT_RET(ret); } } @@ -1591,7 +1615,7 @@ int taos_stmt_set_tbname_tags(TAOS_STMT* stmt, const char* name, TAOS_BIND* tags code = tscGetDataBlockFromList(pCmd->insertParam.pTableBlockHashList, pTableMeta->id.uid, TSDB_PAYLOAD_SIZE, sizeof(SSubmitBlk), pTableMeta->tableInfo.rowSize, &pTableMetaInfo->name, pTableMeta, &pBlock, NULL); if (code != TSDB_CODE_SUCCESS) { - return code; + STMT_RET(code); } SSubmitBlk* blk = (SSubmitBlk*)pBlock->pData; @@ -1606,7 +1630,7 @@ int taos_stmt_set_tbname_tags(TAOS_STMT* stmt, const char* name, TAOS_BIND* tags tscDebug("0x%"PRIx64" table:%s is prepared, uid:%" PRIx64, pSql->self, name, pStmt->mtb.currentUid); } - return code; + STMT_RET(code); } @@ -1639,35 +1663,34 @@ int taos_stmt_close(TAOS_STMT* stmt) { } taos_free_result(pStmt->pSql); - free(pStmt); - return TSDB_CODE_SUCCESS; + tfree(pStmt); + STMT_RET(TSDB_CODE_SUCCESS); } int taos_stmt_bind_param(TAOS_STMT* stmt, TAOS_BIND* bind) { STscStmt* pStmt = (STscStmt*)stmt; if (stmt == NULL || pStmt->pSql == NULL || pStmt->taos == NULL) { - terrno = TSDB_CODE_TSC_DISCONNECTED; - return TSDB_CODE_TSC_DISCONNECTED; + STMT_RET(TSDB_CODE_TSC_DISCONNECTED); } if (pStmt->isInsert) { if (pStmt->multiTbInsert) { if (pStmt->last != STMT_SETTBNAME && pStmt->last != STMT_ADD_BATCH) { tscError("0x%"PRIx64" bind param status error, last:%d", pStmt->pSql->self, pStmt->last); - return TSDB_CODE_TSC_APP_ERROR; + STMT_RET(invalidOperationMsg(tscGetErrorMsgPayload(&pStmt->pSql->cmd), "bind param status error")); } } else { if (pStmt->last != STMT_PREPARE && pStmt->last != STMT_ADD_BATCH && pStmt->last != STMT_EXECUTE) { tscError("0x%"PRIx64" bind param status error, last:%d", pStmt->pSql->self, pStmt->last); - return TSDB_CODE_TSC_APP_ERROR; + STMT_RET(invalidOperationMsg(tscGetErrorMsgPayload(&pStmt->pSql->cmd), "bind param status error")); } } pStmt->last = STMT_BIND; - return insertStmtBindParam(pStmt, bind); + STMT_RET(insertStmtBindParam(pStmt, bind)); } else { - return normalStmtBindParam(pStmt, bind); + STMT_RET(normalStmtBindParam(pStmt, bind)); } } @@ -1676,69 +1699,67 @@ int taos_stmt_bind_param_batch(TAOS_STMT* stmt, TAOS_MULTI_BIND* bind) { STscStmt* pStmt = (STscStmt*)stmt; if (stmt == NULL || pStmt->pSql == NULL || pStmt->taos == NULL) { - terrno = TSDB_CODE_TSC_DISCONNECTED; - return TSDB_CODE_TSC_DISCONNECTED; + STMT_RET(TSDB_CODE_TSC_DISCONNECTED); } if (bind == NULL || bind->num <= 0 || bind->num > INT16_MAX) { tscError("0x%"PRIx64" invalid parameter", pStmt->pSql->self); - return TSDB_CODE_TSC_APP_ERROR; + STMT_RET(invalidOperationMsg(tscGetErrorMsgPayload(&pStmt->pSql->cmd), "invalid bind param")); } if (!pStmt->isInsert) { tscError("0x%"PRIx64" not or invalid batch insert", pStmt->pSql->self); - return TSDB_CODE_TSC_APP_ERROR; + STMT_RET(invalidOperationMsg(tscGetErrorMsgPayload(&pStmt->pSql->cmd), "not or invalid batch insert")); } if (pStmt->multiTbInsert) { if (pStmt->last != STMT_SETTBNAME && pStmt->last != STMT_ADD_BATCH) { tscError("0x%"PRIx64" bind param status error, last:%d", pStmt->pSql->self, pStmt->last); - return TSDB_CODE_TSC_APP_ERROR; + STMT_RET(invalidOperationMsg(tscGetErrorMsgPayload(&pStmt->pSql->cmd), "bind param status error")); } } else { if (pStmt->last != STMT_PREPARE && pStmt->last != STMT_ADD_BATCH && pStmt->last != STMT_EXECUTE) { tscError("0x%"PRIx64" bind param status error, last:%d", pStmt->pSql->self, pStmt->last); - return TSDB_CODE_TSC_APP_ERROR; + STMT_RET(invalidOperationMsg(tscGetErrorMsgPayload(&pStmt->pSql->cmd), "bind param status error")); } } pStmt->last = STMT_BIND; - return insertStmtBindParamBatch(pStmt, bind, -1); + STMT_RET(insertStmtBindParamBatch(pStmt, bind, -1)); } int taos_stmt_bind_single_param_batch(TAOS_STMT* stmt, TAOS_MULTI_BIND* bind, int colIdx) { STscStmt* pStmt = (STscStmt*)stmt; if (stmt == NULL || pStmt->pSql == NULL || pStmt->taos == NULL) { - terrno = TSDB_CODE_TSC_DISCONNECTED; - return TSDB_CODE_TSC_DISCONNECTED; + STMT_RET(TSDB_CODE_TSC_DISCONNECTED); } if (bind == NULL || bind->num <= 0 || bind->num > INT16_MAX) { tscError("0x%"PRIx64" invalid parameter", pStmt->pSql->self); - return TSDB_CODE_TSC_APP_ERROR; + STMT_RET(invalidOperationMsg(tscGetErrorMsgPayload(&pStmt->pSql->cmd), "invalid bind param")); } if (!pStmt->isInsert) { tscError("0x%"PRIx64" not or invalid batch insert", pStmt->pSql->self); - return TSDB_CODE_TSC_APP_ERROR; + STMT_RET(invalidOperationMsg(tscGetErrorMsgPayload(&pStmt->pSql->cmd), "not or invalid batch insert")); } if (pStmt->multiTbInsert) { if (pStmt->last != STMT_SETTBNAME && pStmt->last != STMT_ADD_BATCH && pStmt->last != STMT_BIND_COL) { tscError("0x%"PRIx64" bind param status error, last:%d", pStmt->pSql->self, pStmt->last); - return TSDB_CODE_TSC_APP_ERROR; + STMT_RET(invalidOperationMsg(tscGetErrorMsgPayload(&pStmt->pSql->cmd), "bind param status error")); } } else { if (pStmt->last != STMT_PREPARE && pStmt->last != STMT_ADD_BATCH && pStmt->last != STMT_BIND_COL && pStmt->last != STMT_EXECUTE) { tscError("0x%"PRIx64" bind param status error, last:%d", pStmt->pSql->self, pStmt->last); - return TSDB_CODE_TSC_APP_ERROR; + STMT_RET(invalidOperationMsg(tscGetErrorMsgPayload(&pStmt->pSql->cmd), "bind param status error")); } } pStmt->last = STMT_BIND_COL; - return insertStmtBindParamBatch(pStmt, bind, colIdx); + STMT_RET(insertStmtBindParamBatch(pStmt, bind, colIdx)); } @@ -1746,44 +1767,42 @@ int taos_stmt_bind_single_param_batch(TAOS_STMT* stmt, TAOS_MULTI_BIND* bind, in int taos_stmt_add_batch(TAOS_STMT* stmt) { STscStmt* pStmt = (STscStmt*)stmt; if (stmt == NULL || pStmt->pSql == NULL || pStmt->taos == NULL) { - terrno = TSDB_CODE_TSC_DISCONNECTED; - return TSDB_CODE_TSC_DISCONNECTED; + STMT_RET(TSDB_CODE_TSC_DISCONNECTED); } if (pStmt->isInsert) { if (pStmt->last != STMT_BIND && pStmt->last != STMT_BIND_COL) { tscError("0x%"PRIx64" add batch status error, last:%d", pStmt->pSql->self, pStmt->last); - return TSDB_CODE_TSC_APP_ERROR; + STMT_RET(invalidOperationMsg(tscGetErrorMsgPayload(&pStmt->pSql->cmd), "add batch status error")); } pStmt->last = STMT_ADD_BATCH; - return insertStmtAddBatch(pStmt); + STMT_RET(insertStmtAddBatch(pStmt)); } - return TSDB_CODE_COM_OPS_NOT_SUPPORT; + STMT_RET(TSDB_CODE_COM_OPS_NOT_SUPPORT); } int taos_stmt_reset(TAOS_STMT* stmt) { STscStmt* pStmt = (STscStmt*)stmt; if (pStmt->isInsert) { - return insertStmtReset(pStmt); + STMT_RET(insertStmtReset(pStmt)); } - return TSDB_CODE_SUCCESS; + STMT_RET(TSDB_CODE_SUCCESS); } int taos_stmt_execute(TAOS_STMT* stmt) { int ret = 0; STscStmt* pStmt = (STscStmt*)stmt; if (stmt == NULL || pStmt->pSql == NULL || pStmt->taos == NULL) { - terrno = TSDB_CODE_TSC_DISCONNECTED; - return TSDB_CODE_TSC_DISCONNECTED; + STMT_RET(TSDB_CODE_TSC_DISCONNECTED); } if (pStmt->isInsert) { if (pStmt->last != STMT_ADD_BATCH) { tscError("0x%"PRIx64" exec status error, last:%d", pStmt->pSql->self, pStmt->last); - return TSDB_CODE_TSC_APP_ERROR; + STMT_RET(invalidOperationMsg(tscGetErrorMsgPayload(&pStmt->pSql->cmd), "exec status error")); } pStmt->last = STMT_EXECUTE; @@ -1809,7 +1828,7 @@ int taos_stmt_execute(TAOS_STMT* stmt) { } } - return ret; + STMT_RET(ret); } TAOS_RES *taos_stmt_use_result(TAOS_STMT* stmt) { @@ -1833,32 +1852,30 @@ int taos_stmt_is_insert(TAOS_STMT *stmt, int *insert) { STscStmt* pStmt = (STscStmt*)stmt; if (stmt == NULL || pStmt->taos == NULL || pStmt->pSql == NULL) { - terrno = TSDB_CODE_TSC_DISCONNECTED; - return TSDB_CODE_TSC_DISCONNECTED; + STMT_RET(TSDB_CODE_TSC_DISCONNECTED); } if (insert) *insert = pStmt->isInsert; - return TSDB_CODE_SUCCESS; + STMT_RET(TSDB_CODE_SUCCESS); } int taos_stmt_num_params(TAOS_STMT *stmt, int *nums) { STscStmt* pStmt = (STscStmt*)stmt; if (stmt == NULL || pStmt->taos == NULL || pStmt->pSql == NULL) { - terrno = TSDB_CODE_TSC_DISCONNECTED; - return TSDB_CODE_TSC_DISCONNECTED; + STMT_RET(TSDB_CODE_TSC_DISCONNECTED); } if (pStmt->isInsert) { SSqlObj* pSql = pStmt->pSql; SSqlCmd *pCmd = &pSql->cmd; *nums = pCmd->insertParam.numOfParams; - return TSDB_CODE_SUCCESS; + STMT_RET(TSDB_CODE_SUCCESS); } else { SNormalStmt* normal = &pStmt->normal; *nums = normal->numParams; - return TSDB_CODE_SUCCESS; + STMT_RET(TSDB_CODE_SUCCESS); } } @@ -1866,8 +1883,7 @@ int taos_stmt_get_param(TAOS_STMT *stmt, int idx, int *type, int *bytes) { STscStmt* pStmt = (STscStmt*)stmt; if (stmt == NULL || pStmt->taos == NULL || pStmt->pSql == NULL) { - terrno = TSDB_CODE_TSC_DISCONNECTED; - return TSDB_CODE_TSC_DISCONNECTED; + STMT_RET(TSDB_CODE_TSC_DISCONNECTED); } if (pStmt->isInsert) { @@ -1884,24 +1900,37 @@ int taos_stmt_get_param(TAOS_STMT *stmt, int idx, int *type, int *bytes) { tscGetDataBlockFromList(pCmd->insertParam.pTableBlockHashList, pTableMeta->id.uid, TSDB_PAYLOAD_SIZE, sizeof(SSubmitBlk), pTableMeta->tableInfo.rowSize, &pTableMetaInfo->name, pTableMeta, &pBlock, NULL); if (ret != 0) { - // todo handle error + STMT_RET(ret); } if (idx<0 || idx>=pBlock->numOfParams) { tscError("0x%"PRIx64" param %d: out of range", pStmt->pSql->self, idx); - abort(); + STMT_RET(invalidOperationMsg(tscGetErrorMsgPayload(&pStmt->pSql->cmd), "idx out of range")); } SParamInfo* param = &pBlock->params[idx]; if (type) *type = param->type; if (bytes) *bytes = param->bytes; - return TSDB_CODE_SUCCESS; + STMT_RET(TSDB_CODE_SUCCESS); } else { - return TSDB_CODE_TSC_APP_ERROR; + STMT_RET(TSDB_CODE_COM_OPS_NOT_SUPPORT); + } +} + + +char *taos_stmt_errstr(TAOS_STMT *stmt) { + STscStmt* pStmt = (STscStmt*)stmt; + + if (stmt == NULL) { + return (char*) tstrerror(terrno); } + + return taos_errstr(pStmt->pSql); } + + const char *taos_data_type(int type) { switch (type) { case TSDB_DATA_TYPE_NULL: return "TSDB_DATA_TYPE_NULL"; diff --git a/src/client/src/tscProfile.c b/src/client/src/tscProfile.c index b9ef98681001b657dafe02214853ef28e02e559c..661bd602b3532a1ddc5064ac4ae774bad568335e 100644 --- a/src/client/src/tscProfile.c +++ b/src/client/src/tscProfile.c @@ -19,6 +19,7 @@ #include "ttimer.h" #include "tutil.h" #include "taosmsg.h" +#include "tcq.h" #include "taos.h" @@ -294,24 +295,34 @@ int tscBuildQueryStreamDesc(void *pMsg, STscObj *pObj) { return msgLen; } -void tscKillConnection(STscObj *pObj) { - pthread_mutex_lock(&pObj->mutex); +// cqContext->dbconn is killed then call this callback +void cqConnKilledNotify(void* handle, void* conn) { + if (handle == NULL || conn == NULL){ + return ; + } - SSqlObj *pSql = pObj->sqlList; - while (pSql) { - pSql = pSql->next; - } - + SCqContext* pContext = (SCqContext*) handle; + if (pContext->dbConn == conn){ + atomic_store_ptr(&(pContext->dbConn), NULL); + } +} +void tscKillConnection(STscObj *pObj) { + // get stream header by locked + pthread_mutex_lock(&pObj->mutex); SSqlStream *pStream = pObj->streamList; + pthread_mutex_unlock(&pObj->mutex); + while (pStream) { SSqlStream *tmp = pStream->next; + // set associate variant to NULL + cqConnKilledNotify(pStream->cqhandle, pObj); + // taos_close_stream function call pObj->mutet lock , careful death-lock taos_close_stream(pStream); pStream = tmp; } - pthread_mutex_unlock(&pObj->mutex); - tscDebug("connection:%p is killed", pObj); taos_close(pObj); } + diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index 4a94715b6f352d2b8590a3ffbba85c14dae238bc..0427f4252fa788a4b57868592abd6dc751ff56cc 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -63,6 +63,9 @@ static SExprInfo* doAddProjectCol(SQueryInfo* pQueryInfo, int32_t colIndex, int3 static int32_t setShowInfo(SSqlObj* pSql, SSqlInfo* pInfo); static char* getAccountId(SSqlObj* pSql); +static bool serializeExprListToVariant(SArray* pList, tVariant **dest, int16_t colType); +static int32_t validateParamOfRelationIn(tVariant *pVar, int32_t colType); + static bool has(SArray* pFieldList, int32_t startIdx, const char* name); static char* cloneCurrentDBName(SSqlObj* pSql); static int32_t getDelimiterIndex(SStrToken* pTableName); @@ -120,7 +123,7 @@ static int32_t getColumnIndexByName(SSqlCmd* pCmd, const SStrToken* pToken, SQue static int32_t getTableIndexByName(SStrToken* pToken, SQueryInfo* pQueryInfo, SColumnIndex* pIndex); static int32_t getTableIndexImpl(SStrToken* pTableToken, SQueryInfo* pQueryInfo, SColumnIndex* pIndex); -static int32_t doFunctionsCompatibleCheck(SSqlCmd* pCmd, SQueryInfo* pQueryInfo); +static int32_t doFunctionsCompatibleCheck(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, char* msg); static int32_t doLocalQueryProcess(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SSqlNode* pSqlNode); static int32_t tscCheckCreateDbParams(SSqlCmd* pCmd, SCreateDbMsg* pCreate); @@ -135,14 +138,97 @@ static bool validateDebugFlag(int32_t v); static int32_t checkQueryRangeForFill(SSqlCmd* pCmd, SQueryInfo* pQueryInfo); static int32_t loadAllTableMeta(SSqlObj* pSql, struct SSqlInfo* pInfo); -static bool isTimeWindowQuery(SQueryInfo* pQueryInfo) { +static bool isTimeWindowQuery(SQueryInfo* pQueryInfo) { return pQueryInfo->interval.interval > 0 || pQueryInfo->sessionWindow.gap > 0; } + int16_t getNewResColId(SSqlCmd* pCmd) { return pCmd->resColumnId--; } +// serialize expr in exprlist to binary +// formate "type | size | value" +bool serializeExprListToVariant(SArray* pList, tVariant **dst, int16_t colType) { + bool ret = false; + if (!pList || pList->size <= 0) { + return ret; + } + if (colType == TSDB_DATA_TYPE_DOUBLE || colType == TSDB_DATA_TYPE_FLOAT) { + return ret; + } + + tSqlExprItem* item = (tSqlExprItem *)taosArrayGet(pList, 0); + int32_t firstTokenType = item->pNode->token.type; + int32_t type = firstTokenType; + + //nchar to binary and + toTSDBType(type); + if (type != colType && (type != TSDB_DATA_TYPE_BINARY || colType != TSDB_DATA_TYPE_NCHAR)) { + return false; + } + type = colType; + + SBufferWriter bw = tbufInitWriter( NULL, false ); + tbufEnsureCapacity(&bw, 512); + + int32_t size = (int32_t)(pList->size); + tbufWriteUint32(&bw, type); + tbufWriteInt32(&bw, size); + + for (int32_t i = 0; i < size; i++) { + tSqlExpr* pSub = ((tSqlExprItem*)(taosArrayGet(pList, i)))->pNode; + + // check all the token type in expr list same or not + if (firstTokenType != pSub->token.type) { + break; + } + + toTSDBType(pSub->token.type); + + tVariant var; + tVariantCreate(&var, &pSub->token); + if (type == TSDB_DATA_TYPE_BOOL || type == TSDB_DATA_TYPE_TINYINT || type == TSDB_DATA_TYPE_SMALLINT + || type == TSDB_DATA_TYPE_BIGINT || type == TSDB_DATA_TYPE_INT) { + tbufWriteInt64(&bw, var.i64); + } else if (type == TSDB_DATA_TYPE_DOUBLE || type == TSDB_DATA_TYPE_FLOAT) { + tbufWriteDouble(&bw, var.dKey); + } else if (type == TSDB_DATA_TYPE_BINARY){ + tbufWriteBinary(&bw, var.pz, var.nLen); + } else if (type == TSDB_DATA_TYPE_NCHAR) { + char *buf = (char *)calloc(1, (var.nLen + 1)*TSDB_NCHAR_SIZE); + if (tVariantDump(&var, buf, type, false) != TSDB_CODE_SUCCESS) { + free(buf); + tVariantDestroy(&var); + break; + } + tbufWriteBinary(&bw, buf, twcslen((wchar_t *)buf) * TSDB_NCHAR_SIZE); + free(buf); + } + tVariantDestroy(&var); + + if (i == size - 1) { ret = true;} + } + + if (ret == true) { + if ((*dst = calloc(1, sizeof(tVariant))) != NULL) { + tVariantCreateFromBinary(*dst, tbufGetData(&bw, false), tbufTell(&bw), TSDB_DATA_TYPE_BINARY); + } else { + ret = false; + } + } + tbufCloseWriter(&bw); + return ret; +} + +static int32_t validateParamOfRelationIn(tVariant *pVar, int32_t colType) { + if (pVar->nType != TSDB_DATA_TYPE_BINARY) { + return -1; + } + SBufferReader br = tbufInitReader(pVar->pz, pVar->nLen, false); + return colType == TSDB_DATA_TYPE_NCHAR ? 0 : (tbufReadUint32(&br) == colType ? 0: -1); +} + static uint8_t convertOptr(SStrToken *pToken) { switch (pToken->type) { case TK_LT: @@ -163,6 +249,7 @@ static uint8_t convertOptr(SStrToken *pToken) { return TSDB_RELATION_EQUAL; case TK_PLUS: return TSDB_BINARY_OP_ADD; + case TK_MINUS: return TSDB_BINARY_OP_SUBTRACT; case TK_STAR: @@ -178,6 +265,8 @@ static uint8_t convertOptr(SStrToken *pToken) { return TSDB_RELATION_ISNULL; case TK_NOTNULL: return TSDB_RELATION_NOTNULL; + case TK_IN: + return TSDB_RELATION_IN; default: { return 0; } } } @@ -350,7 +439,9 @@ int32_t tscValidateSqlInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) { } } else if (pInfo->type == TSDB_SQL_DROP_DNODE) { - pzName->n = strdequote(pzName->z); + if (pzName->type == TK_STRING) { + pzName->n = strdequote(pzName->z); + } strncpy(pCmd->payload, pzName->z, pzName->n); } else { // drop user/account if (pzName->n >= TSDB_USER_LEN) { @@ -428,7 +519,9 @@ int32_t tscValidateSqlInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) { } SStrToken* id = taosArrayGet(pInfo->pMiscInfo->a, 0); - id->n = strdequote(id->z); + if (id->type == TK_STRING) { + id->n = strdequote(id->z); + } break; } @@ -839,18 +932,15 @@ int32_t validateIntervalNode(SSqlObj* pSql, SQueryInfo* pQueryInfo, SSqlNode* pS // interval is not null SStrToken *t = &pSqlNode->interval.interval; - if (parseNatualDuration(t->z, t->n, &pQueryInfo->interval.interval, &pQueryInfo->interval.intervalUnit) != TSDB_CODE_SUCCESS) { + if (parseNatualDuration(t->z, t->n, &pQueryInfo->interval.interval, + &pQueryInfo->interval.intervalUnit, tinfo.precision) != TSDB_CODE_SUCCESS) { return TSDB_CODE_TSC_INVALID_OPERATION; } if (pQueryInfo->interval.intervalUnit != 'n' && pQueryInfo->interval.intervalUnit != 'y') { - // if the unit of time window value is millisecond, change the value from microsecond - if (tinfo.precision == TSDB_TIME_PRECISION_MILLI) { - pQueryInfo->interval.interval = pQueryInfo->interval.interval / 1000; - } // interval cannot be less than 10 milliseconds - if (pQueryInfo->interval.interval < tsMinIntervalTime) { + if (convertTimePrecision(pQueryInfo->interval.interval, tinfo.precision, TSDB_TIME_PRECISION_MILLI) < tsMinIntervalTime) { return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg2); } } @@ -926,6 +1016,8 @@ int32_t validateSessionNode(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SSqlNode * pS const char* msg3 = "invalid column name"; const char* msg4 = "invalid time window"; + STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0); + STableComInfo tinfo = tscGetTableInfo(pTableMetaInfo->pTableMeta); // no session window if (!TPARSER_HAS_TOKEN(pSqlNode->sessionVal.gap)) { return TSDB_CODE_SUCCESS; @@ -935,7 +1027,7 @@ int32_t validateSessionNode(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SSqlNode * pS SStrToken* gap = &pSqlNode->sessionVal.gap; char timeUnit = 0; - if (parseNatualDuration(gap->z, gap->n, &pQueryInfo->sessionWindow.gap, &timeUnit) != TSDB_CODE_SUCCESS) { + if (parseNatualDuration(gap->z, gap->n, &pQueryInfo->sessionWindow.gap, &timeUnit, tinfo.precision) != TSDB_CODE_SUCCESS) { return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg4); } @@ -943,13 +1035,6 @@ int32_t validateSessionNode(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SSqlNode * pS return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg1); } - // if the unit of time window value is millisecond, change the value from microsecond - STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0); - STableComInfo tinfo = tscGetTableInfo(pTableMetaInfo->pTableMeta); - if (tinfo.precision == TSDB_TIME_PRECISION_MILLI) { - pQueryInfo->sessionWindow.gap = pQueryInfo->sessionWindow.gap / 1000; - } - if (pQueryInfo->sessionWindow.gap != 0 && pQueryInfo->interval.interval != 0) { return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg2); } @@ -986,7 +1071,8 @@ int32_t parseIntervalOffset(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SStrToken* of return TSDB_CODE_SUCCESS; } - if (parseNatualDuration(t->z, t->n, &pQueryInfo->interval.offset, &pQueryInfo->interval.offsetUnit) != TSDB_CODE_SUCCESS) { + if (parseNatualDuration(t->z, t->n, &pQueryInfo->interval.offset, + &pQueryInfo->interval.offsetUnit, tinfo.precision) != TSDB_CODE_SUCCESS) { return TSDB_CODE_TSC_INVALID_OPERATION; } @@ -995,10 +1081,6 @@ int32_t parseIntervalOffset(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SStrToken* of } if (pQueryInfo->interval.offsetUnit != 'n' && pQueryInfo->interval.offsetUnit != 'y') { - // if the unit of time window value is millisecond, change the value from microsecond - if (tinfo.precision == TSDB_TIME_PRECISION_MILLI) { - pQueryInfo->interval.offset = pQueryInfo->interval.offset / 1000; - } if (pQueryInfo->interval.intervalUnit != 'n' && pQueryInfo->interval.intervalUnit != 'y') { if (pQueryInfo->interval.offset >= pQueryInfo->interval.interval) { return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg2); @@ -1043,12 +1125,10 @@ int32_t parseSlidingClause(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SStrToken* pSl return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg3); } - parseAbsoluteDuration(pSliding->z, pSliding->n, &pQueryInfo->interval.sliding); - if (tinfo.precision == TSDB_TIME_PRECISION_MILLI) { - pQueryInfo->interval.sliding /= 1000; - } + parseAbsoluteDuration(pSliding->z, pSliding->n, &pQueryInfo->interval.sliding, tinfo.precision); - if (pQueryInfo->interval.sliding < tsMinSlidingTime) { + if (pQueryInfo->interval.sliding < + convertTimePrecision(tsMinSlidingTime, TSDB_TIME_PRECISION_MILLI, tinfo.precision)) { return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg0); } @@ -2075,7 +2155,10 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col const char* msg6 = "function applied to tags not allowed"; const char* msg7 = "normal table can not apply this function"; const char* msg8 = "multi-columns selection does not support alias column name"; - const char* msg9 = "diff can no be applied to unsigned numeric type"; + const char* msg9 = "diff/derivative can no be applied to unsigned numeric type"; + const char* msg10 = "derivative duration should be greater than 1 Second"; + const char* msg11 = "third parameter in derivative should be 0 or 1"; + const char* msg12 = "parameter is out of range [1, 100]"; switch (functionId) { case TSDB_FUNC_COUNT: { @@ -2164,11 +2247,14 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col case TSDB_FUNC_MIN: case TSDB_FUNC_MAX: case TSDB_FUNC_DIFF: + case TSDB_FUNC_DERIVATIVE: case TSDB_FUNC_STDDEV: case TSDB_FUNC_LEASTSQR: { // 1. valid the number of parameters - if (pItem->pNode->pParam == NULL || (functionId != TSDB_FUNC_LEASTSQR && taosArrayGetSize(pItem->pNode->pParam) != 1) || - (functionId == TSDB_FUNC_LEASTSQR && taosArrayGetSize(pItem->pNode->pParam) != 3)) { + int32_t numOfParams = (pItem->pNode->pParam == NULL)? 0: (int32_t) taosArrayGetSize(pItem->pNode->pParam); + if (pItem->pNode->pParam == NULL || + (functionId != TSDB_FUNC_LEASTSQR && functionId != TSDB_FUNC_DERIVATIVE && numOfParams != 1) || + ((functionId == TSDB_FUNC_LEASTSQR || functionId == TSDB_FUNC_DERIVATIVE) && numOfParams != 3)) { /* no parameters or more than one parameter for function */ return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg2); } @@ -2189,11 +2275,13 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col // 2. check if sql function can be applied on this column data type pTableMetaInfo = tscGetMetaInfo(pQueryInfo, index.tableIndex); + STableComInfo info = tscGetTableInfo(pTableMetaInfo->pTableMeta); + SSchema* pSchema = tscGetTableColumnSchema(pTableMetaInfo->pTableMeta, index.columnIndex); if (!IS_NUMERIC_TYPE(pSchema->type)) { return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg1); - } else if (IS_UNSIGNED_NUMERIC_TYPE(pSchema->type) && functionId == TSDB_FUNC_DIFF) { + } else if (IS_UNSIGNED_NUMERIC_TYPE(pSchema->type) && (functionId == TSDB_FUNC_DIFF || functionId == TSDB_FUNC_DERIVATIVE)) { return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg9); } @@ -2207,11 +2295,11 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col } // set the first column ts for diff query - if (functionId == TSDB_FUNC_DIFF) { + if (functionId == TSDB_FUNC_DIFF || functionId == TSDB_FUNC_DERIVATIVE) { colIndex += 1; SColumnIndex indexTS = {.tableIndex = index.tableIndex, .columnIndex = 0}; - SExprInfo* pExpr = tscExprAppend(pQueryInfo, TSDB_FUNC_TS_DUMMY, &indexTS, TSDB_DATA_TYPE_TIMESTAMP, TSDB_KEYSIZE, - getNewResColId(pCmd), TSDB_KEYSIZE, false); + SExprInfo* pExpr = tscExprAppend(pQueryInfo, TSDB_FUNC_TS_DUMMY, &indexTS, TSDB_DATA_TYPE_TIMESTAMP, + TSDB_KEYSIZE, getNewResColId(pCmd), TSDB_KEYSIZE, false); SColumnList ids = createColumnList(1, 0, 0); insertResultField(pQueryInfo, 0, &ids, TSDB_KEYSIZE, TSDB_DATA_TYPE_TIMESTAMP, aAggs[TSDB_FUNC_TS_DUMMY].name, pExpr); @@ -2222,7 +2310,7 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg6); } - SExprInfo* pExpr = tscExprAppend(pQueryInfo, functionId, &index, resultType, resultSize, getNewResColId(pCmd), resultSize, false); + SExprInfo* pExpr = tscExprAppend(pQueryInfo, functionId, &index, resultType, resultSize, getNewResColId(pCmd), intermediateResSize, false); if (functionId == TSDB_FUNC_LEASTSQR) { // set the leastsquares parameters char val[8] = {0}; @@ -2237,12 +2325,41 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col return TSDB_CODE_TSC_INVALID_OPERATION; } - tscExprAddParams(&pExpr->base, val, TSDB_DATA_TYPE_DOUBLE, sizeof(double)); + tscExprAddParams(&pExpr->base, val, TSDB_DATA_TYPE_DOUBLE, DOUBLE_BYTES); } else if (functionId == TSDB_FUNC_IRATE) { - STableComInfo info = tscGetTableInfo(pTableMetaInfo->pTableMeta); int64_t prec = info.precision; - tscExprAddParams(&pExpr->base, (char*)&prec, TSDB_DATA_TYPE_BIGINT, LONG_BYTES); + } else if (functionId == TSDB_FUNC_DERIVATIVE) { + char val[8] = {0}; + + int64_t tickPerSec = 0; + if (tVariantDump(&pParamElem[1].pNode->value, (char*) &tickPerSec, TSDB_DATA_TYPE_BIGINT, true) < 0) { + return TSDB_CODE_TSC_INVALID_OPERATION; + } + + if (info.precision == TSDB_TIME_PRECISION_MILLI) { + tickPerSec /= 1000000; + } else if (info.precision == TSDB_TIME_PRECISION_MICRO) { + tickPerSec /= 1000; + } + + if (tickPerSec <= 0 || tickPerSec < TSDB_TICK_PER_SECOND(info.precision)) { + return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg10); + } + + tscExprAddParams(&pExpr->base, (char*) &tickPerSec, TSDB_DATA_TYPE_BIGINT, LONG_BYTES); + memset(val, 0, tListLen(val)); + + if (tVariantDump(&pParamElem[2].pNode->value, val, TSDB_DATA_TYPE_BIGINT, true) < 0) { + return TSDB_CODE_TSC_INVALID_OPERATION; + } + + int64_t v = *(int64_t*) val; + if (v != 0 && v != 1) { + return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg11); + } + + tscExprAddParams(&pExpr->base, val, TSDB_DATA_TYPE_BIGINT, LONG_BYTES); } SColumnList ids = createColumnList(1, index.tableIndex, index.columnIndex); @@ -2447,7 +2564,7 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col int64_t nTop = GET_INT32_VAL(val); if (nTop <= 0 || nTop > 100) { // todo use macro - return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg5); + return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg12); } // todo REFACTOR @@ -2947,8 +3064,8 @@ void tscRestoreFuncForSTableQuery(SQueryInfo* pQueryInfo) { } bool hasUnsupportFunctionsForSTableQuery(SSqlCmd* pCmd, SQueryInfo* pQueryInfo) { - const char* msg1 = "TWA not allowed to apply to super table directly"; - const char* msg2 = "TWA only support group by tbname for super table query"; + const char* msg1 = "TWA/Diff not allowed to apply to super table directly"; + const char* msg2 = "TWA/Diff only support group by tbname for super table query"; const char* msg3 = "function not support for super table query"; // filter sql function not supported by metric query yet. @@ -2961,7 +3078,7 @@ bool hasUnsupportFunctionsForSTableQuery(SSqlCmd* pCmd, SQueryInfo* pQueryInfo) } } - if (tscIsTWAQuery(pQueryInfo)) { + if (tscIsTWAQuery(pQueryInfo) || tscIsDiffQuery(pQueryInfo)) { if (pQueryInfo->groupbyExpr.numOfGroupCols == 0) { invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg1); return true; @@ -3201,8 +3318,9 @@ static int32_t doExtractColumnFilterInfo(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, return retVal; } } else if ((colType == TSDB_DATA_TYPE_TIMESTAMP) && (TSDB_DATA_TYPE_BIGINT == pRight->value.nType)) { - if ((timePrecision == TSDB_TIME_PRECISION_MILLI) && (pRight->flags & (1 << EXPR_FLAG_US_TIMESTAMP))) { - pRight->value.i64 /= 1000; + if (pRight->flags & (1 << EXPR_FLAG_NS_TIMESTAMP)) { + pRight->value.i64 = + convertTimePrecision(pRight->value.i64, TSDB_TIME_PRECISION_NANO, timePrecision); } } @@ -3219,6 +3337,25 @@ static int32_t doExtractColumnFilterInfo(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, retVal = tVariantDump(&pRight->value, (char*)&pColumnFilter->upperBndd, colType, false); // TK_GT,TK_GE,TK_EQ,TK_NE are based on the pColumn->lowerBndd + } else if (pExpr->tokenId == TK_IN) { + tVariant *pVal; + if (pRight->tokenId != TK_SET || !serializeExprListToVariant(pRight->pParam, &pVal, colType) || colType == TSDB_DATA_TYPE_TIMESTAMP) { + return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg); + } + if (validateParamOfRelationIn(pVal, colType) != TSDB_CODE_SUCCESS) { + tVariantDestroy(pVal); + free(pVal); + return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg); + } + pColumnFilter->pz = (int64_t)calloc(1, pVal->nLen + 1); + pColumnFilter->len = pVal->nLen; + pColumnFilter->filterstr = 1; + memcpy((char *)(pColumnFilter->pz), (char *)(pVal->pz), pVal->nLen); + //retVal = tVariantDump(pVal, (char *)(pColumnFilter->pz), TSDB_DATA_TYPE_BINARY, false); + + tVariantDestroy(pVal); + free(pVal); + } else if (colType == TSDB_DATA_TYPE_BINARY) { pColumnFilter->pz = (int64_t)calloc(1, bufLen * TSDB_NCHAR_SIZE); pColumnFilter->len = pRight->value.nLen; @@ -3267,6 +3404,9 @@ static int32_t doExtractColumnFilterInfo(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, case TK_NOTNULL: pColumnFilter->lowerRelOptr = TSDB_RELATION_NOTNULL; break; + case TK_IN: + pColumnFilter->lowerRelOptr = TSDB_RELATION_IN; + break; default: return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg); } @@ -3382,7 +3522,7 @@ static int32_t extractColumnFilterInfo(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SC && pExpr->tokenId != TK_ISNULL && pExpr->tokenId != TK_NOTNULL && pExpr->tokenId != TK_LIKE - ) { + && pExpr->tokenId != TK_IN) { return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg2); } } else { @@ -3392,7 +3532,7 @@ static int32_t extractColumnFilterInfo(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SC if (pSchema->type == TSDB_DATA_TYPE_BOOL) { int32_t t = pExpr->tokenId; - if (t != TK_EQ && t != TK_NE && t != TK_NOTNULL && t != TK_ISNULL) { + if (t != TK_EQ && t != TK_NE && t != TK_NOTNULL && t != TK_ISNULL && t != TK_IN) { return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg3); } } @@ -4434,7 +4574,11 @@ static int32_t validateTagCondExpr(SSqlCmd* pCmd, tExprNode *p) { free(tmp); } else { double tmp; - retVal = tVariantDump(vVariant, (char*)&tmp, schemaType, false); + if (p->_node.optr == TSDB_RELATION_IN) { + retVal = validateParamOfRelationIn(vVariant, schemaType); + } else { + retVal = tVariantDump(vVariant, (char*)&tmp, schemaType, false); + } } if (retVal != TSDB_CODE_SUCCESS) { @@ -4719,7 +4863,7 @@ int32_t getTimeRange(STimeWindow* win, tSqlExpr* pRight, int32_t optr, int16_t t char* seg = strnchr(pRight->value.pz, '-', pRight->value.nLen, false); if (seg != NULL) { - if (taosParseTime(pRight->value.pz, &val, pRight->value.nLen, TSDB_TIME_PRECISION_MICRO, tsDaylight) == TSDB_CODE_SUCCESS) { + if (taosParseTime(pRight->value.pz, &val, pRight->value.nLen, timePrecision, tsDaylight) == TSDB_CODE_SUCCESS) { parsed = true; } else { return TSDB_CODE_TSC_INVALID_OPERATION; @@ -4732,18 +4876,6 @@ int32_t getTimeRange(STimeWindow* win, tSqlExpr* pRight, int32_t optr, int16_t t return TSDB_CODE_TSC_INVALID_OPERATION; } } - } else if (pRight->tokenId == TK_INTEGER && timePrecision == TSDB_TIME_PRECISION_MILLI) { - /* - * if the pRight->tokenId == TK_INTEGER/TK_FLOAT, the value is adaptive, we - * need the time precision in metermeta to transfer the value in MICROSECOND - * - * Additional check to avoid data overflow - */ - if (pRight->value.i64 <= INT64_MAX / 1000) { - pRight->value.i64 *= 1000; - } - } else if (pRight->tokenId == TK_FLOAT && timePrecision == TSDB_TIME_PRECISION_MILLI) { - pRight->value.dKey *= 1000; } if (!parsed) { @@ -4751,33 +4883,19 @@ int32_t getTimeRange(STimeWindow* win, tSqlExpr* pRight, int32_t optr, int16_t t * failed to parse timestamp in regular formation, try next * it may be a epoch time in string format */ - tVariantDump(&pRight->value, (char*)&val, TSDB_DATA_TYPE_BIGINT, true); - - /* - * transfer it into MICROSECOND format if it is a string, since for - * TK_INTEGER/TK_FLOAT the value has been transferred - * - * additional check to avoid data overflow - */ - if (pRight->tokenId == TK_STRING && timePrecision == TSDB_TIME_PRECISION_MILLI) { - if (val <= INT64_MAX / 1000) { - val *= 1000; - } + if (pRight->flags & (1 << EXPR_FLAG_NS_TIMESTAMP)) { + pRight->value.i64 = convertTimePrecision(pRight->value.i64, TSDB_TIME_PRECISION_NANO, timePrecision); } - } - - int32_t delta = 1; - /* for millisecond, delta is 1ms=1000us */ - if (timePrecision == TSDB_TIME_PRECISION_MILLI) { - delta *= 1000; + + tVariantDump(&pRight->value, (char*)&val, TSDB_DATA_TYPE_BIGINT, true); } if (optr == TK_LE) { win->ekey = val; } else if (optr == TK_LT) { - win->ekey = val - delta; + win->ekey = val - 1; } else if (optr == TK_GT) { - win->skey = val + delta; + win->skey = val + 1; } else if (optr == TK_GE) { win->skey = val; } else if (optr == TK_EQ) { @@ -5500,8 +5618,10 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) { int32_t validateSqlFunctionInStreamSql(SSqlCmd* pCmd, SQueryInfo* pQueryInfo) { const char* msg0 = "sample interval can not be less than 10ms."; const char* msg1 = "functions not allowed in select clause"; - - if (pQueryInfo->interval.interval != 0 && pQueryInfo->interval.interval < 10 && + STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0); + STableComInfo tinfo = tscGetTableInfo(pTableMetaInfo->pTableMeta); + if (pQueryInfo->interval.interval != 0 && + convertTimePrecision(pQueryInfo->interval.interval, tinfo.precision, TSDB_TIME_PRECISION_MILLI)< 10 && pQueryInfo->interval.intervalUnit != 'n' && pQueryInfo->interval.intervalUnit != 'y') { return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg0); @@ -5520,7 +5640,7 @@ int32_t validateSqlFunctionInStreamSql(SSqlCmd* pCmd, SQueryInfo* pQueryInfo) { int32_t validateFunctionsInIntervalOrGroupbyQuery(SSqlCmd* pCmd, SQueryInfo* pQueryInfo) { bool isProjectionFunction = false; - const char* msg1 = "column projection is not compatible with interval"; + const char* msg1 = "functions not compatible with interval"; // multi-output set/ todo refactor size_t size = taosArrayGetSize(pQueryInfo->exprList); @@ -5544,8 +5664,8 @@ int32_t validateFunctionsInIntervalOrGroupbyQuery(SSqlCmd* pCmd, SQueryInfo* pQu } } - if ((pExpr->base.functionId == TSDB_FUNC_PRJ && pExpr->base.numOfParams == 0) || pExpr->base.functionId == TSDB_FUNC_DIFF || - pExpr->base.functionId == TSDB_FUNC_ARITHM) { + int32_t f = pExpr->base.functionId; + if ((f == TSDB_FUNC_PRJ && pExpr->base.numOfParams == 0) || f == TSDB_FUNC_DIFF || f == TSDB_FUNC_ARITHM || f == TSDB_FUNC_DERIVATIVE) { isProjectionFunction = true; } } @@ -5831,48 +5951,40 @@ int32_t validateLimitNode(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SSqlNode* pSqlN } static int32_t setKeepOption(SSqlCmd* pCmd, SCreateDbMsg* pMsg, SCreateDbInfo* pCreateDb) { - const char* msg = "invalid number of options"; + const char* msg1 = "invalid number of keep options"; + const char* msg2 = "invalid keep value"; + const char* msg3 = "invalid keep value, should be keep0 <= keep1 <= keep2"; - pMsg->daysToKeep = htonl(-1); + pMsg->daysToKeep0 = htonl(-1); pMsg->daysToKeep1 = htonl(-1); pMsg->daysToKeep2 = htonl(-1); SArray* pKeep = pCreateDb->keep; if (pKeep != NULL) { size_t s = taosArrayGetSize(pKeep); +#ifdef _STORAGE + if (s >= 4 ||s <= 0) { +#else + if (s != 1) { +#endif + return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg1); + } + tVariantListItem* p0 = taosArrayGet(pKeep, 0); - switch (s) { - case 1: { - if ((int32_t)p0->pVar.i64 <= 0) { - return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg); - } - pMsg->daysToKeep = htonl((int32_t)p0->pVar.i64); - } - break; - case 2: { - tVariantListItem* p1 = taosArrayGet(pKeep, 1); - if ((int32_t)p0->pVar.i64 <= 0 || (int32_t)p1->pVar.i64 <= 0) { - return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg); - } - pMsg->daysToKeep = htonl((int32_t)p0->pVar.i64); - pMsg->daysToKeep1 = htonl((int32_t)p1->pVar.i64); - break; - } - case 3: { - tVariantListItem* p1 = taosArrayGet(pKeep, 1); - tVariantListItem* p2 = taosArrayGet(pKeep, 2); + tVariantListItem* p1 = (s > 1) ? taosArrayGet(pKeep, 1) : p0; + tVariantListItem* p2 = (s > 2) ? taosArrayGet(pKeep, 2) : p1; + + if ((int32_t)p0->pVar.i64 <= 0 || (int32_t)p1->pVar.i64 <= 0 || (int32_t)p2->pVar.i64 <= 0) { + return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg2); + } + if (!(((int32_t)p0->pVar.i64 <= (int32_t)p1->pVar.i64) && ((int32_t)p1->pVar.i64 <= (int32_t)p2->pVar.i64))) { + return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg3); + } - if ((int32_t)p0->pVar.i64 <= 0 || (int32_t)p1->pVar.i64 <= 0 || (int32_t)p2->pVar.i64 <= 0) { - return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg); - } + pMsg->daysToKeep0 = htonl((int32_t)p0->pVar.i64); + pMsg->daysToKeep1 = htonl((int32_t)p1->pVar.i64); + pMsg->daysToKeep2 = htonl((int32_t)p2->pVar.i64); - pMsg->daysToKeep = htonl((int32_t)p0->pVar.i64); - pMsg->daysToKeep1 = htonl((int32_t)p1->pVar.i64); - pMsg->daysToKeep2 = htonl((int32_t)p2->pVar.i64); - break; - } - default: { return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg); } - } } return TSDB_CODE_SUCCESS; @@ -5894,11 +6006,15 @@ static int32_t setTimePrecision(SSqlCmd* pCmd, SCreateDbMsg* pMsg, SCreateDbInfo } else if (strncmp(pToken->z, TSDB_TIME_PRECISION_MICRO_STR, pToken->n) == 0 && strlen(TSDB_TIME_PRECISION_MICRO_STR) == pToken->n) { pMsg->precision = TSDB_TIME_PRECISION_MICRO; + } else if (strncmp(pToken->z, TSDB_TIME_PRECISION_NANO_STR, pToken->n) == 0 && + strlen(TSDB_TIME_PRECISION_NANO_STR) == pToken->n) { + pMsg->precision = TSDB_TIME_PRECISION_NANO; } else { return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg); } } + return TSDB_CODE_SUCCESS; } @@ -6141,7 +6257,7 @@ static void updateTagPrjFunction(SQueryInfo* pQueryInfo) { * 2. if selectivity function and tagprj function both exist, there should be only * one selectivity function exists. */ -static int32_t checkUpdateTagPrjFunctions(SQueryInfo* pQueryInfo, SSqlCmd* pCmd) { +static int32_t checkUpdateTagPrjFunctions(SQueryInfo* pQueryInfo, char* msg) { const char* msg1 = "only one selectivity function allowed in presence of tags function"; const char* msg3 = "aggregation function should not be mixed up with projection"; @@ -6164,10 +6280,11 @@ static int32_t checkUpdateTagPrjFunctions(SQueryInfo* pQueryInfo, SSqlCmd* pCmd) int16_t functionId = pExpr->base.functionId; if (functionId == TSDB_FUNC_TAGPRJ || functionId == TSDB_FUNC_PRJ || functionId == TSDB_FUNC_TS || - functionId == TSDB_FUNC_ARITHM) { + functionId == TSDB_FUNC_ARITHM || functionId == TSDB_FUNC_TS_DUMMY) { continue; } + if ((aAggs[functionId].status & TSDB_FUNCSTATE_SELECTIVITY) != 0) { numOfSelectivity++; } else { @@ -6179,7 +6296,7 @@ static int32_t checkUpdateTagPrjFunctions(SQueryInfo* pQueryInfo, SSqlCmd* pCmd) // When the tag projection function on tag column that is not in the group by clause, aggregation function and // selectivity function exist in select clause is not allowed. if (numOfAggregation > 0) { - return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg1); + return invalidOperationMsg(msg, msg1); } /* @@ -6208,7 +6325,7 @@ static int32_t checkUpdateTagPrjFunctions(SQueryInfo* pQueryInfo, SSqlCmd* pCmd) (functionId == TSDB_FUNC_LAST_DST && (pExpr->base.colInfo.flag & TSDB_COL_NULL) != 0)) { // do nothing } else { - return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg1); + return invalidOperationMsg(msg, msg1); } } @@ -6221,7 +6338,7 @@ static int32_t checkUpdateTagPrjFunctions(SQueryInfo* pQueryInfo, SSqlCmd* pCmd) } else { if ((pQueryInfo->type & TSDB_QUERY_TYPE_PROJECTION_QUERY) != 0) { if (numOfAggregation > 0 && pQueryInfo->groupbyExpr.numOfGroupCols == 0) { - return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg3); + return invalidOperationMsg(msg, msg3); } if (numOfAggregation > 0 || numOfSelectivity > 0) { @@ -6269,9 +6386,14 @@ static int32_t doAddGroupbyColumnsOnDemand(SSqlCmd* pCmd, SQueryInfo* pQueryInfo size_t size = tscNumOfExprs(pQueryInfo); if (TSDB_COL_IS_TAG(pColIndex->flag)) { + + int32_t f = TSDB_FUNC_TAG; + if (tscIsDiffDerivQuery(pQueryInfo)) { + f = TSDB_FUNC_TAGPRJ; + } + SColumnIndex index = {.tableIndex = pQueryInfo->groupbyExpr.tableIndex, .columnIndex = colIndex}; - SExprInfo* pExpr = tscExprAppend(pQueryInfo, TSDB_FUNC_TAG, &index, s->type, s->bytes, - getNewResColId(pCmd), s->bytes, true); + SExprInfo* pExpr = tscExprAppend(pQueryInfo, f, &index, s->type, s->bytes, getNewResColId(pCmd), s->bytes, true); memset(pExpr->base.aliasName, 0, sizeof(pExpr->base.aliasName)); tstrncpy(pExpr->base.aliasName, s->name, sizeof(pExpr->base.aliasName)); @@ -6331,7 +6453,7 @@ static int32_t doTagFunctionCheck(SQueryInfo* pQueryInfo) { return (tableCounting && tagProjection)? -1:0; } -int32_t doFunctionsCompatibleCheck(SSqlCmd* pCmd, SQueryInfo* pQueryInfo) { +int32_t doFunctionsCompatibleCheck(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, char* msg) { const char* msg1 = "functions/columns not allowed in group by query"; const char* msg2 = "projection query on columns not allowed"; const char* msg3 = "group by/session/state_window not allowed on projection query"; @@ -6341,17 +6463,17 @@ int32_t doFunctionsCompatibleCheck(SSqlCmd* pCmd, SQueryInfo* pQueryInfo) { // only retrieve tags, group by is not supportted if (tscQueryTags(pQueryInfo)) { if (doTagFunctionCheck(pQueryInfo) != TSDB_CODE_SUCCESS) { - return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg5); + return invalidOperationMsg(msg, msg5); } if (pQueryInfo->groupbyExpr.numOfGroupCols > 0 || isTimeWindowQuery(pQueryInfo)) { - return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg4); + return invalidOperationMsg(msg, msg4); } else { return TSDB_CODE_SUCCESS; } } if (tscIsProjectionQuery(pQueryInfo) && tscIsSessionWindowQuery(pQueryInfo)) { - return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg3); + return invalidOperationMsg(msg, msg3); } if (pQueryInfo->groupbyExpr.numOfGroupCols > 0) { @@ -6359,6 +6481,7 @@ int32_t doFunctionsCompatibleCheck(SSqlCmd* pCmd, SQueryInfo* pQueryInfo) { if (onlyTagPrjFunction(pQueryInfo) && allTagPrjInGroupby(pQueryInfo)) { // It is a groupby aggregate query, the tag project function is not suitable for this case. updateTagPrjFunction(pQueryInfo); + return doAddGroupbyColumnsOnDemand(pCmd, pQueryInfo); } @@ -6366,13 +6489,13 @@ int32_t doFunctionsCompatibleCheck(SSqlCmd* pCmd, SQueryInfo* pQueryInfo) { size_t size = tscNumOfExprs(pQueryInfo); for (int32_t i = 0; i < size; ++i) { SExprInfo* pExpr = tscExprGet(pQueryInfo, i); - int32_t functId = pExpr->base.functionId; + int32_t f = pExpr->base.functionId; /* * group by normal columns. * Check if the column projection is identical to the group by column or not */ - if (functId == TSDB_FUNC_PRJ && pExpr->base.colInfo.colId != PRIMARYKEY_TIMESTAMP_COL_INDEX) { + if (f == TSDB_FUNC_PRJ && pExpr->base.colInfo.colId != PRIMARYKEY_TIMESTAMP_COL_INDEX) { bool qualified = false; for (int32_t j = 0; j < pQueryInfo->groupbyExpr.numOfGroupCols; ++j) { SColIndex* pColIndex = taosArrayGet(pQueryInfo->groupbyExpr.columnInfo, j); @@ -6383,21 +6506,21 @@ int32_t doFunctionsCompatibleCheck(SSqlCmd* pCmd, SQueryInfo* pQueryInfo) { } if (!qualified) { - return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg2); + return invalidOperationMsg(msg, msg2); } } - if (IS_MULTIOUTPUT(aAggs[functId].status) && functId != TSDB_FUNC_TOP && functId != TSDB_FUNC_BOTTOM && - functId != TSDB_FUNC_TAGPRJ && functId != TSDB_FUNC_PRJ) { - return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg1); + if (IS_MULTIOUTPUT(aAggs[f].status) && f != TSDB_FUNC_TOP && f != TSDB_FUNC_BOTTOM && + f != TSDB_FUNC_DIFF && f != TSDB_FUNC_DERIVATIVE && f != TSDB_FUNC_TAGPRJ && f != TSDB_FUNC_PRJ) { + return invalidOperationMsg(msg, msg1); } - if (functId == TSDB_FUNC_COUNT && pExpr->base.colInfo.colIndex == TSDB_TBNAME_COLUMN_INDEX) { - return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg1); + if (f == TSDB_FUNC_COUNT && pExpr->base.colInfo.colIndex == TSDB_TBNAME_COLUMN_INDEX) { + return invalidOperationMsg(msg, msg1); } } - if (checkUpdateTagPrjFunctions(pQueryInfo, pCmd) != TSDB_CODE_SUCCESS) { + if (checkUpdateTagPrjFunctions(pQueryInfo, msg) != TSDB_CODE_SUCCESS) { return TSDB_CODE_TSC_INVALID_OPERATION; } @@ -6406,13 +6529,13 @@ int32_t doFunctionsCompatibleCheck(SSqlCmd* pCmd, SQueryInfo* pQueryInfo) { } // projection query on super table does not compatible with "group by" syntax - if (tscIsProjectionQuery(pQueryInfo)) { - return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg3); + if (tscIsProjectionQuery(pQueryInfo) && !(tscIsDiffDerivQuery(pQueryInfo))) { + return invalidOperationMsg(msg, msg3); } return TSDB_CODE_SUCCESS; } else { - return checkUpdateTagPrjFunctions(pQueryInfo, pCmd); + return checkUpdateTagPrjFunctions(pQueryInfo, msg); } } int32_t doLocalQueryProcess(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SSqlNode* pSqlNode) { @@ -6498,6 +6621,13 @@ int32_t tscCheckCreateDbParams(SSqlCmd* pCmd, SCreateDbMsg* pCreate) { return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg); } + int32_t blocks = ntohl(pCreate->totalBlocks); + if (blocks != -1 && (blocks < TSDB_MIN_TOTAL_BLOCKS || blocks > TSDB_MAX_TOTAL_BLOCKS)) { + snprintf(msg, tListLen(msg), "invalid db option totalBlocks: %d valid range: [%d, %d]", blocks, + TSDB_MIN_TOTAL_BLOCKS, TSDB_MAX_TOTAL_BLOCKS); + return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg); + } + if (pCreate->quorum != -1 && (pCreate->quorum < TSDB_MIN_DB_QUORUM_OPTION || pCreate->quorum > TSDB_MAX_DB_QUORUM_OPTION)) { snprintf(msg, tListLen(msg), "invalid db option quorum: %d valid range: [%d, %d]", pCreate->quorum, @@ -6526,9 +6656,10 @@ int32_t tscCheckCreateDbParams(SSqlCmd* pCmd, SCreateDbMsg* pCreate) { return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg); } - if (pCreate->precision != TSDB_TIME_PRECISION_MILLI && pCreate->precision != TSDB_TIME_PRECISION_MICRO) { - snprintf(msg, tListLen(msg), "invalid db option timePrecision: %d valid value: [%d, %d]", pCreate->precision, - TSDB_TIME_PRECISION_MILLI, TSDB_TIME_PRECISION_MICRO); + if (pCreate->precision != TSDB_TIME_PRECISION_MILLI && pCreate->precision != TSDB_TIME_PRECISION_MICRO && + pCreate->precision != TSDB_TIME_PRECISION_NANO) { + snprintf(msg, tListLen(msg), "invalid db option timePrecision: %d valid value: [%d, %d, %d]", pCreate->precision, + TSDB_TIME_PRECISION_MILLI, TSDB_TIME_PRECISION_MICRO, TSDB_TIME_PRECISION_NANO); return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg); } @@ -6870,7 +7001,7 @@ int32_t doCheckForStream(SSqlObj* pSql, SSqlInfo* pInfo) { const char* msg6 = "from missing in subclause"; const char* msg7 = "time interval is required"; const char* msg8 = "the first column should be primary timestamp column"; - + SSqlCmd* pCmd = &pSql->cmd; SQueryInfo* pQueryInfo = tscGetQueryInfo(pCmd); assert(pQueryInfo->numOfTables == 1); @@ -6927,6 +7058,7 @@ int32_t doCheckForStream(SSqlObj* pSql, SSqlInfo* pInfo) { return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg2); } + // project query primary column must be timestamp type if (tscIsProjectionQuery(pQueryInfo)) { SExprInfo* pExpr = tscExprGet(pQueryInfo, 0); if (pExpr->base.colInfo.colId != PRIMARYKEY_TIMESTAMP_COL_INDEX) { @@ -6935,7 +7067,7 @@ int32_t doCheckForStream(SSqlObj* pSql, SSqlInfo* pInfo) { } else { if (pQueryInfo->interval.interval == 0) { return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg7); - } + } } // set the created table[stream] name @@ -7606,7 +7738,8 @@ int32_t validateSqlNode(SSqlObj* pSql, SSqlNode* pSqlNode, SQueryInfo* pQueryInf const char* msg2 = "too many tables in from clause"; const char* msg3 = "start(end) time of query range required or time range too large"; const char* msg4 = "interval query not supported, since the result of sub query not include valid timestamp column"; - const char* msg9 = "only tag query not compatible with normal column filter"; + const char* msg5 = "only tag query not compatible with normal column filter"; + const char* msg6 = "not support stddev/percentile in outer query yet"; int32_t code = TSDB_CODE_SUCCESS; @@ -7647,24 +7780,27 @@ int32_t validateSqlNode(SSqlObj* pSql, SSqlNode* pSqlNode, SQueryInfo* pQueryInf return TSDB_CODE_TSC_INVALID_OPERATION; } + // todo NOT support yet + for(int32_t i = 0; i < tscNumOfExprs(pQueryInfo); ++i) { + SExprInfo* pExpr = tscExprGet(pQueryInfo, i); + int32_t f = pExpr->base.functionId; + if (f == TSDB_FUNC_STDDEV || f == TSDB_FUNC_PERCT) { + return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg6); + } + } + // validate the query filter condition info if (pSqlNode->pWhere != NULL) { if (validateWhereNode(pQueryInfo, &pSqlNode->pWhere, pSql) != TSDB_CODE_SUCCESS) { return TSDB_CODE_TSC_INVALID_OPERATION; } - - STableMeta* pTableMeta = tscGetMetaInfo(pQueryInfo, 0)->pTableMeta; - if (pTableMeta->tableInfo.precision == TSDB_TIME_PRECISION_MILLI) { - pQueryInfo->window.skey = pQueryInfo->window.skey / 1000; - pQueryInfo->window.ekey = pQueryInfo->window.ekey / 1000; - } } // validate the interval info if (validateIntervalNode(pSql, pQueryInfo, pSqlNode) != TSDB_CODE_SUCCESS) { return TSDB_CODE_TSC_INVALID_OPERATION; } else { - if (isTimeWindowQuery(pQueryInfo)) { + if (isTimeWindowQuery(pQueryInfo) || pQueryInfo->sessionWindow.gap > 0) { // check if the first column of the nest query result is timestamp column SColumn* pCol = taosArrayGetP(pQueryInfo->colList, 0); if (pCol->info.type != TSDB_DATA_TYPE_TIMESTAMP) { @@ -7679,10 +7815,13 @@ int32_t validateSqlNode(SSqlObj* pSql, SSqlNode* pSqlNode, SQueryInfo* pQueryInf // set order by info STableMeta* pTableMeta = tscGetMetaInfo(pQueryInfo, 0)->pTableMeta; - if (validateOrderbyNode(pCmd, pQueryInfo, pSqlNode, tscGetTableSchema(pTableMeta)) != - TSDB_CODE_SUCCESS) { + if (validateOrderbyNode(pCmd, pQueryInfo, pSqlNode, tscGetTableSchema(pTableMeta)) != TSDB_CODE_SUCCESS) { return TSDB_CODE_TSC_INVALID_OPERATION; } + + if ((code = doFunctionsCompatibleCheck(pCmd, pQueryInfo, tscGetErrorMsgPayload(pCmd))) != TSDB_CODE_SUCCESS) { + return code; + } } else { pQueryInfo->command = TSDB_SQL_SELECT; @@ -7708,18 +7847,12 @@ int32_t validateSqlNode(SSqlObj* pSql, SSqlNode* pSqlNode, SQueryInfo* pQueryInf } // set where info - STableComInfo tinfo = tscGetTableInfo(pTableMetaInfo->pTableMeta); - if (pSqlNode->pWhere != NULL) { if (validateWhereNode(pQueryInfo, &pSqlNode->pWhere, pSql) != TSDB_CODE_SUCCESS) { return TSDB_CODE_TSC_INVALID_OPERATION; } pSqlNode->pWhere = NULL; - if (tinfo.precision == TSDB_TIME_PRECISION_MILLI) { - pQueryInfo->window.skey = pQueryInfo->window.skey / 1000; - pQueryInfo->window.ekey = pQueryInfo->window.ekey / 1000; - } } else { if (taosArrayGetSize(pSqlNode->from->list) > 1) { // Cross join not allowed yet return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), "cross join not supported yet"); @@ -7747,11 +7880,6 @@ int32_t validateSqlNode(SSqlObj* pSql, SSqlNode* pSqlNode, SQueryInfo* pQueryInf // set interval value if (validateIntervalNode(pSql, pQueryInfo, pSqlNode) != TSDB_CODE_SUCCESS) { return TSDB_CODE_TSC_INVALID_OPERATION; - } else { - if (isTimeWindowQuery(pQueryInfo) && - (validateFunctionsInIntervalOrGroupbyQuery(pCmd, pQueryInfo) != TSDB_CODE_SUCCESS)) { - return TSDB_CODE_TSC_INVALID_OPERATION; - } } if (tscQueryTags(pQueryInfo)) { @@ -7762,7 +7890,7 @@ int32_t validateSqlNode(SSqlObj* pSql, SSqlNode* pSqlNode, SQueryInfo* pQueryInf for (int32_t i = 0; i < numOfCols; ++i) { SColumn* pCols = taosArrayGetP(pQueryInfo->colList, i); if (pCols->info.flist.numOfFilters > 0) { - return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg9); + return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg5); } } } @@ -7782,6 +7910,11 @@ int32_t validateSqlNode(SSqlObj* pSql, SSqlNode* pSqlNode, SQueryInfo* pQueryInf return TSDB_CODE_TSC_INVALID_OPERATION; } + if ((isTimeWindowQuery(pQueryInfo) || pQueryInfo->sessionWindow.gap > 0) && + (validateFunctionsInIntervalOrGroupbyQuery(pCmd, pQueryInfo) != TSDB_CODE_SUCCESS)) { + return TSDB_CODE_TSC_INVALID_OPERATION; + } + if (isSTable) { tscTansformFuncForSTableQuery(pQueryInfo); if (hasUnsupportFunctionsForSTableQuery(pCmd, pQueryInfo)) { @@ -7811,7 +7944,7 @@ int32_t validateSqlNode(SSqlObj* pSql, SSqlNode* pSqlNode, SQueryInfo* pQueryInf return code; } - if ((code = doFunctionsCompatibleCheck(pCmd, pQueryInfo)) != TSDB_CODE_SUCCESS) { + if ((code = doFunctionsCompatibleCheck(pCmd, pQueryInfo,tscGetErrorMsgPayload(pCmd))) != TSDB_CODE_SUCCESS) { return code; } @@ -7824,14 +7957,15 @@ int32_t validateSqlNode(SSqlObj* pSql, SSqlNode* pSqlNode, SQueryInfo* pQueryInf } { // set the query info - pQueryInfo->projectionQuery = tscIsProjectionQuery(pQueryInfo); - pQueryInfo->hasFilter = tscHasColumnFilter(pQueryInfo); - pQueryInfo->simpleAgg = isSimpleAggregateRv(pQueryInfo); - pQueryInfo->onlyTagQuery = onlyTagPrjFunction(pQueryInfo); - pQueryInfo->groupbyColumn = tscGroupbyColumn(pQueryInfo); + pQueryInfo->projectionQuery = tscIsProjectionQuery(pQueryInfo); + pQueryInfo->hasFilter = tscHasColumnFilter(pQueryInfo); + pQueryInfo->simpleAgg = isSimpleAggregateRv(pQueryInfo); + pQueryInfo->onlyTagQuery = onlyTagPrjFunction(pQueryInfo); + pQueryInfo->groupbyColumn = tscGroupbyColumn(pQueryInfo); - pQueryInfo->arithmeticOnAgg = tsIsArithmeticQueryOnAggResult(pQueryInfo); + pQueryInfo->arithmeticOnAgg = tsIsArithmeticQueryOnAggResult(pQueryInfo); pQueryInfo->orderProjectQuery = tscOrderedProjectionQueryOnSTable(pQueryInfo, 0); +// pQueryInfo->diffQuery = tscIsDiffQuery(pQueryInfo); SExprInfo** p = NULL; int32_t numOfExpr = 0; @@ -7942,6 +8076,24 @@ int32_t exprTreeFromSqlExpr(SSqlCmd* pCmd, tExprNode **pExpr, const tSqlExpr* pS } return TSDB_CODE_SUCCESS; + } else if (pSqlExpr->tokenId == TK_SET) { + int32_t type = -1; + STableMeta* pTableMeta = tscGetMetaInfo(pQueryInfo, 0)->pTableMeta; + if (pCols != NULL) { + SColIndex* idx = taosArrayGet(pCols, 0); + SSchema* pSchema = tscGetTableColumnSchema(pTableMeta, idx->colIndex); + if (pSchema != NULL) { + type = pSchema->type; + } + } + + tVariant *pVal; + if (serializeExprListToVariant(pSqlExpr->pParam, &pVal, type) == false) { + return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), "not support filter expression"); + } + *pExpr = calloc(1, sizeof(tExprNode)); + (*pExpr)->nodeType = TSQL_NODE_VALUE; + (*pExpr)->pVal = pVal; } else { return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), "not support filter expression"); } diff --git a/src/client/src/tscServer.c b/src/client/src/tscServer.c index 7dfd24864dfcdb12c7859440db6967fed8512f00..a3f5abdbfd3e3a2d038a49e07152f5ef3bbc9187 100644 --- a/src/client/src/tscServer.c +++ b/src/client/src/tscServer.c @@ -937,7 +937,7 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) { } SGroupbyExpr *pGroupbyExpr = query.pGroupbyExpr; - if (pGroupbyExpr->numOfGroupCols > 0) { + if (pGroupbyExpr != NULL && pGroupbyExpr->numOfGroupCols > 0) { pQueryMsg->orderByIdx = htons(pGroupbyExpr->orderIndex); pQueryMsg->orderType = htons(pGroupbyExpr->orderType); @@ -1668,7 +1668,7 @@ int tscProcessLocalRetrieveRsp(SSqlObj *pSql) { return tscLocalResultCommonBuilder(pSql, numOfRes); } -int tscProcessRetrieveLocalMergeRsp(SSqlObj *pSql) { +int tscProcessRetrieveGlobalMergeRsp(SSqlObj *pSql) { SSqlRes *pRes = &pSql->res; SSqlCmd* pCmd = &pSql->cmd; @@ -1695,12 +1695,13 @@ int tscProcessRetrieveLocalMergeRsp(SSqlObj *pSql) { taosArrayPush(group, &tableKeyInfo); taosArrayPush(tableGroupInfo.pGroupList, &group); - pQueryInfo->pQInfo = createQInfoFromQueryNode(pQueryInfo, &tableGroupInfo, NULL, NULL, pRes->pMerger, MERGE_STAGE); + tscDebug("0x%"PRIx64" create QInfo 0x%"PRIx64" to execute query processing", pSql->self, pSql->self); + pQueryInfo->pQInfo = createQInfoFromQueryNode(pQueryInfo, &tableGroupInfo, NULL, NULL, pRes->pMerger, MERGE_STAGE, pSql->self); } - uint64_t localQueryId = 0; + uint64_t localQueryId = pSql->self; qTableQuery(pQueryInfo->pQInfo, &localQueryId); - convertQueryResult(pRes, pQueryInfo); + convertQueryResult(pRes, pQueryInfo, pSql->self); code = pRes->code; if (pRes->code == TSDB_CODE_SUCCESS) { @@ -2774,7 +2775,7 @@ void tscInitMsgsFp() { tscProcessMsgRsp[TSDB_SQL_RETRIEVE_EMPTY_RESULT] = tscProcessEmptyResultRsp; - tscProcessMsgRsp[TSDB_SQL_RETRIEVE_LOCALMERGE] = tscProcessRetrieveLocalMergeRsp; + tscProcessMsgRsp[TSDB_SQL_RETRIEVE_GLOBALMERGE] = tscProcessRetrieveGlobalMergeRsp; tscProcessMsgRsp[TSDB_SQL_ALTER_TABLE] = tscProcessAlterTableMsgRsp; tscProcessMsgRsp[TSDB_SQL_ALTER_DB] = tscProcessAlterDbMsgRsp; diff --git a/src/client/src/tscSql.c b/src/client/src/tscSql.c index 554ce351eb05a3196a08a79c3b3067df6de6aab8..1e9389287674996b63ff3a7cc2d8ece81d4bc130 100644 --- a/src/client/src/tscSql.c +++ b/src/client/src/tscSql.c @@ -456,7 +456,7 @@ static bool needToFetchNewBlock(SSqlObj* pSql) { return (pRes->completed != true || hasMoreVnodesToTry(pSql) || hasMoreClauseToTry(pSql)) && (pCmd->command == TSDB_SQL_RETRIEVE || - pCmd->command == TSDB_SQL_RETRIEVE_LOCALMERGE || + pCmd->command == TSDB_SQL_RETRIEVE_GLOBALMERGE || pCmd->command == TSDB_SQL_TABLE_JOIN_RETRIEVE || pCmd->command == TSDB_SQL_FETCH || pCmd->command == TSDB_SQL_SHOW || diff --git a/src/client/src/tscStream.c b/src/client/src/tscStream.c index 9b13cd2140dea3bc416f1a418d69b2ef0e187992..da5bdf669fa41e4e44cd5551743c4feb77f447ac 100644 --- a/src/client/src/tscStream.c +++ b/src/client/src/tscStream.c @@ -53,9 +53,7 @@ static int64_t tscGetRetryDelayTime(SSqlStream* pStream, int64_t slidingTime, in if (pStream->interval.intervalUnit != 'n' && pStream->interval.intervalUnit != 'y') { // change to ms - if (prec == TSDB_TIME_PRECISION_MICRO) { - slidingTime = slidingTime / 1000; - } + slidingTime = convertTimePrecision(slidingTime, pStream->precision, TSDB_TIME_PRECISION_MILLI); if (slidingTime < retryDelta) { return slidingTime; @@ -139,8 +137,13 @@ static void tscProcessStreamTimer(void *handle, void *tmrId) { pStream->numOfRes = 0; // reset the numOfRes. SSqlObj *pSql = pStream->pSql; + + // pSql == NULL maybe killStream already called + if(pSql == NULL) { + return ; + } SQueryInfo* pQueryInfo = tscGetQueryInfo(&pSql->cmd); - tscDebug("0x%"PRIx64" timer launch query", pSql->self); + tscDebug("0x%"PRIx64" add into timer", pSql->self); if (pStream->isProject) { /* @@ -157,11 +160,7 @@ static void tscProcessStreamTimer(void *handle, void *tmrId) { pQueryInfo->window.skey = pStream->stime; int64_t etime = taosGetTimestamp(pStream->precision); // delay to wait all data in last time window - if (pStream->precision == TSDB_TIME_PRECISION_MICRO) { - etime -= tsMaxStreamComputDelay * 1000l; - } else { - etime -= tsMaxStreamComputDelay; - } + etime -= convertTimePrecision(tsMaxStreamComputDelay, TSDB_TIME_PRECISION_MILLI, pStream->precision); if (etime > pStream->etime) { etime = pStream->etime; } else if (pStream->interval.intervalUnit != 'y' && pStream->interval.intervalUnit != 'n') { @@ -178,8 +177,8 @@ static void tscProcessStreamTimer(void *handle, void *tmrId) { int64_t timer = pStream->interval.sliding; if (pStream->interval.intervalUnit == 'y' || pStream->interval.intervalUnit == 'n') { timer = 86400 * 1000l; - } else if (pStream->precision == TSDB_TIME_PRECISION_MICRO) { - timer /= 1000l; + } else { + timer = convertTimePrecision(timer, pStream->precision, TSDB_TIME_PRECISION_MILLI); } tscSetRetryTimer(pStream, pSql, timer); return; @@ -339,8 +338,12 @@ static void tscSetRetryTimer(SSqlStream *pStream, SSqlObj *pSql, int64_t timer) if (pStream->isProject) { int64_t now = taosGetTimestamp(pStream->precision); int64_t etime = now > pStream->etime ? pStream->etime : now; - - if (pStream->etime < now && now - pStream->etime > tsMaxRetentWindow) { + int64_t maxRetent = tsMaxRetentWindow * 1000; + if(pStream->precision == TSDB_TIME_PRECISION_MICRO) { + maxRetent *= 1000; + } + + if (pStream->etime < now && now - pStream->etime > maxRetent) { /* * current time window will be closed, since it too early to exceed the maxRetentWindow value */ @@ -369,9 +372,8 @@ static void tscSetRetryTimer(SSqlStream *pStream, SSqlObj *pSql, int64_t timer) } static int64_t getLaunchTimeDelay(const SSqlStream* pStream) { - int64_t maxDelay = - (pStream->precision == TSDB_TIME_PRECISION_MICRO) ? tsMaxStreamComputDelay * 1000L : tsMaxStreamComputDelay; - + int64_t maxDelay = convertTimePrecision(tsMaxStreamComputDelay, TSDB_TIME_PRECISION_MILLI, pStream->precision); + int64_t delayDelta = maxDelay; if (pStream->interval.intervalUnit != 'n' && pStream->interval.intervalUnit != 'y') { delayDelta = (int64_t)(pStream->interval.sliding * tsStreamComputDelayRatio); @@ -438,16 +440,14 @@ static void tscSetNextLaunchTimer(SSqlStream *pStream, SSqlObj *pSql) { timer += getLaunchTimeDelay(pStream); - if (pStream->precision == TSDB_TIME_PRECISION_MICRO) { - timer = timer / 1000L; - } + timer = convertTimePrecision(timer, pStream->precision, TSDB_TIME_PRECISION_MILLI); tscSetRetryTimer(pStream, pSql, timer); } static int32_t tscSetSlidingWindowInfo(SSqlObj *pSql, SSqlStream *pStream) { int64_t minIntervalTime = - (pStream->precision == TSDB_TIME_PRECISION_MICRO) ? tsMinIntervalTime * 1000L : tsMinIntervalTime; + convertTimePrecision(tsMinIntervalTime, TSDB_TIME_PRECISION_MILLI, pStream->precision); SQueryInfo* pQueryInfo = tscGetQueryInfo(&pSql->cmd); @@ -471,7 +471,7 @@ static int32_t tscSetSlidingWindowInfo(SSqlObj *pSql, SSqlStream *pStream) { } int64_t minSlidingTime = - (pStream->precision == TSDB_TIME_PRECISION_MICRO) ? tsMinSlidingTime * 1000L : tsMinSlidingTime; + convertTimePrecision(tsMinSlidingTime, TSDB_TIME_PRECISION_MILLI, pStream->precision); if (pQueryInfo->interval.intervalUnit != 'n' && pQueryInfo->interval.intervalUnit!= 'y' && pQueryInfo->interval.sliding < minSlidingTime) { tscWarn("0x%"PRIx64" stream:%p, original sliding value:%" PRId64 " too small, reset to:%" PRId64, pSql->self, pStream, @@ -539,13 +539,12 @@ static int64_t tscGetLaunchTimestamp(const SSqlStream *pStream) { timer = pStream->stime - now; } - int64_t startDelay = - (pStream->precision == TSDB_TIME_PRECISION_MICRO) ? tsStreamCompStartDelay * 1000L : tsStreamCompStartDelay; - + int64_t startDelay = convertTimePrecision(tsStreamCompStartDelay, TSDB_TIME_PRECISION_MILLI, pStream->precision); + timer += getLaunchTimeDelay(pStream); timer += startDelay; - return (pStream->precision == TSDB_TIME_PRECISION_MICRO) ? timer / 1000L : timer; + return convertTimePrecision(timer, pStream->precision, TSDB_TIME_PRECISION_MILLI); } static void tscCreateStream(void *param, TAOS_RES *res, int code) { @@ -664,7 +663,7 @@ void cbParseSql(void* param, TAOS_RES* res, int code) { } TAOS_STREAM *taos_open_stream_withname(TAOS *taos, const char* dstTable, const char *sqlstr, void (*fp)(void *param, TAOS_RES *, TAOS_ROW row), - int64_t stime, void *param, void (*callback)(void *)) { + int64_t stime, void *param, void (*callback)(void *), void* cqhandle) { STscObj *pObj = (STscObj *)taos; if (pObj == NULL || pObj->signature != pObj) return NULL; @@ -697,6 +696,7 @@ TAOS_STREAM *taos_open_stream_withname(TAOS *taos, const char* dstTable, const c pStream->callback = callback; pStream->param = param; pStream->pSql = pSql; + pStream->cqhandle = cqhandle; pSql->pStream = pStream; pSql->param = pStream; pSql->maxRetry = TSDB_MAX_REPLICA; @@ -745,7 +745,7 @@ TAOS_STREAM *taos_open_stream_withname(TAOS *taos, const char* dstTable, const c TAOS_STREAM *taos_open_stream(TAOS *taos, const char *sqlstr, void (*fp)(void *param, TAOS_RES *, TAOS_ROW row), int64_t stime, void *param, void (*callback)(void *)) { - return taos_open_stream_withname(taos, "", sqlstr, fp, stime, param, callback); + return taos_open_stream_withname(taos, "", sqlstr, fp, stime, param, callback, NULL); } void taos_close_stream(TAOS_STREAM *handle) { diff --git a/src/client/src/tscSub.c b/src/client/src/tscSub.c index 42330aa18e48eb60389ef3056c96a2aab386a6ca..7a0b3451c3b415e8e565fe091de6d1ed0e478409 100644 --- a/src/client/src/tscSub.c +++ b/src/client/src/tscSub.c @@ -265,7 +265,7 @@ static int tscUpdateSubscription(STscObj* pObj, SSub* pSub) { SSqlCmd* pCmd = &pSql->cmd; - pSub->lastSyncTime = taosGetTimestampMs(); + TSDB_QUERY_CLEAR_TYPE(tscGetQueryInfo(pCmd)->type, TSDB_QUERY_TYPE_MULTITABLE_QUERY); STableMetaInfo *pTableMetaInfo = tscGetTableMetaInfoFromCmd(pCmd, 0); if (UTIL_TABLE_IS_NORMAL_TABLE(pTableMetaInfo)) { @@ -276,6 +276,8 @@ static int tscUpdateSubscription(STscObj* pObj, SSub* pSub) { taosArrayClear(pSub->progress); taosArrayPush(pSub->progress, &target); } + + pSub->lastSyncTime = taosGetTimestampMs(); return 1; } @@ -305,7 +307,11 @@ static int tscUpdateSubscription(STscObj* pObj, SSub* pSub) { } taosArrayDestroy(tables); - TSDB_QUERY_SET_TYPE(tscGetQueryInfo(pCmd)->type, TSDB_QUERY_TYPE_MULTITABLE_QUERY); + if (pTableMetaInfo->pVgroupTables && taosArrayGetSize(pTableMetaInfo->pVgroupTables) > 0) { + TSDB_QUERY_SET_TYPE(tscGetQueryInfo(pCmd)->type, TSDB_QUERY_TYPE_MULTITABLE_QUERY); + } + + pSub->lastSyncTime = taosGetTimestampMs(); return 1; } diff --git a/src/client/src/tscSubquery.c b/src/client/src/tscSubquery.c index 2f32e775d66e3c3e1cf45b1437f3fa82278346a6..49ce73854520aa95249d9f42590acd36d83bb523 100644 --- a/src/client/src/tscSubquery.c +++ b/src/client/src/tscSubquery.c @@ -1977,9 +1977,8 @@ void tscHandleMasterJoinQuery(SSqlObj* pSql) { } memset(pSql->subState.states, 0, sizeof(*pSql->subState.states) * pSql->subState.numOfSub); - tscDebug("0x%"PRIx64" reset all sub states to 0", pSql->self); + tscDebug("0x%"PRIx64" reset all sub states to 0, start subquery, total:%d", pSql->self, pQueryInfo->numOfTables); - tscDebug("0x%"PRIx64" start subquery, total:%d", pSql->self, pQueryInfo->numOfTables); for (int32_t i = 0; i < pQueryInfo->numOfTables; ++i) { SJoinSupporter *pSupporter = tscCreateJoinSupporter(pSql, i); if (pSupporter == NULL) { // failed to create support struct, abort current query @@ -2424,7 +2423,7 @@ int32_t tscHandleMasterSTableQuery(SSqlObj *pSql) { // pRes->code check only serves in launching metric sub-queries if (pRes->code == TSDB_CODE_TSC_QUERY_CANCELLED) { - pCmd->command = TSDB_SQL_RETRIEVE_LOCALMERGE; // enable the abort of kill super table function. + pCmd->command = TSDB_SQL_RETRIEVE_GLOBALMERGE; // enable the abort of kill super table function. return pRes->code; } @@ -2780,7 +2779,7 @@ static void tscAllDataRetrievedFromDnode(SRetrieveSupport *trsupport, SSqlObj* p if (code == TSDB_CODE_SUCCESS && trsupport->pExtMemBuffer == NULL) { pParentSql->cmd.command = TSDB_SQL_RETRIEVE_EMPTY_RESULT; // no result, set the result empty } else { - pParentSql->cmd.command = TSDB_SQL_RETRIEVE_LOCALMERGE; + pParentSql->cmd.command = TSDB_SQL_RETRIEVE_GLOBALMERGE; } tscCreateResPointerInfo(&pParentSql->res, pPQueryInfo); @@ -3502,7 +3501,7 @@ static UNUSED_FUNC bool tscHasRemainDataInSubqueryResultSet(SSqlObj *pSql) { } void* createQInfoFromQueryNode(SQueryInfo* pQueryInfo, STableGroupInfo* pTableGroupInfo, SOperatorInfo* pSourceOperator, - char* sql, void* merger, int32_t stage) { + char* sql, void* merger, int32_t stage, uint64_t qId) { assert(pQueryInfo != NULL); SQInfo *pQInfo = (SQInfo *)calloc(1, sizeof(SQInfo)); if (pQInfo == NULL) { @@ -3511,7 +3510,7 @@ void* createQInfoFromQueryNode(SQueryInfo* pQueryInfo, STableGroupInfo* pTableGr // to make sure third party won't overwrite this structure pQInfo->signature = pQInfo; - + pQInfo->qId = qId; SQueryRuntimeEnv *pRuntimeEnv = &pQInfo->runtimeEnv; SQueryAttr *pQueryAttr = &pQInfo->query; diff --git a/src/client/src/tscUtil.c b/src/client/src/tscUtil.c index b5dfc956ddd31a141c009bbf8200299cd82c607f..e3dba3fcbca71f43c7be7a3c6ecbaa4a51198865 100644 --- a/src/client/src/tscUtil.c +++ b/src/client/src/tscUtil.c @@ -222,6 +222,9 @@ bool tscIsProjectionQueryOnSTable(SQueryInfo* pQueryInfo, int32_t tableIndex) { functionId != TSDB_FUNC_TS && functionId != TSDB_FUNC_ARITHM && functionId != TSDB_FUNC_TS_COMP && + functionId != TSDB_FUNC_DIFF && + functionId != TSDB_FUNC_DERIVATIVE && + functionId != TSDB_FUNC_TS_DUMMY && functionId != TSDB_FUNC_TID_TAG) { return false; } @@ -253,10 +256,14 @@ bool tscIsProjectionQuery(SQueryInfo* pQueryInfo) { size_t size = tscNumOfExprs(pQueryInfo); for (int32_t i = 0; i < size; ++i) { - int32_t functionId = tscExprGet(pQueryInfo, i)->base.functionId; + int32_t f = tscExprGet(pQueryInfo, i)->base.functionId; + if (f == TSDB_FUNC_TS_DUMMY) { + continue; + } - if (functionId != TSDB_FUNC_PRJ && functionId != TSDB_FUNC_TAGPRJ && functionId != TSDB_FUNC_TAG && - functionId != TSDB_FUNC_TS && functionId != TSDB_FUNC_ARITHM) { + if (f != TSDB_FUNC_PRJ && f != TSDB_FUNC_TAGPRJ && f != TSDB_FUNC_TAG && + f != TSDB_FUNC_TS && f != TSDB_FUNC_ARITHM && f != TSDB_FUNC_DIFF && + f != TSDB_FUNC_DERIVATIVE) { return false; } } @@ -264,6 +271,24 @@ bool tscIsProjectionQuery(SQueryInfo* pQueryInfo) { return true; } +bool tscIsDiffDerivQuery(SQueryInfo* pQueryInfo) { + size_t size = tscNumOfExprs(pQueryInfo); + + for (int32_t i = 0; i < size; ++i) { + int32_t f = tscExprGet(pQueryInfo, i)->base.functionId; + if (f == TSDB_FUNC_TS_DUMMY) { + continue; + } + + if (f == TSDB_FUNC_DIFF || f == TSDB_FUNC_DERIVATIVE) { + return true; + } + } + + return false; +} + + bool tscHasColumnFilter(SQueryInfo* pQueryInfo) { // filter on primary timestamp column if (pQueryInfo->window.skey != INT64_MIN || pQueryInfo->window.ekey != INT64_MAX) { @@ -434,6 +459,25 @@ bool tscIsTWAQuery(SQueryInfo* pQueryInfo) { return false; } + +bool tscIsDiffQuery(SQueryInfo* pQueryInfo) { + size_t num = tscNumOfExprs(pQueryInfo); + for(int32_t i = 0; i < num; ++i) { + SExprInfo* pExpr = tscExprGet(pQueryInfo, i); + + int32_t f = pExpr->base.functionId; + if (pExpr == NULL || f == TSDB_FUNC_TS_DUMMY) { + continue; + } + + if (f == TSDB_FUNC_DIFF || f == TSDB_FUNC_DERIVATIVE) { + return true; + } + } + + return false; +} + bool tscIsSessionWindowQuery(SQueryInfo* pQueryInfo) { return pQueryInfo->sessionWindow.gap > 0; } @@ -467,42 +511,12 @@ bool tscNeedReverseScan(SQueryInfo* pQueryInfo) { return false; } -bool isSimpleAggregate(SQueryInfo* pQueryInfo) { - if (pQueryInfo->interval.interval > 0) { - return false; - } - - // Note:top/bottom query is fixed output query - if (tscIsTopBotQuery(pQueryInfo) || tscGroupbyColumn(pQueryInfo) || isTsCompQuery(pQueryInfo)) { - return true; - } - - size_t numOfExprs = tscNumOfExprs(pQueryInfo); - for (int32_t i = 0; i < numOfExprs; ++i) { - SExprInfo* pExpr = tscExprGet(pQueryInfo, i); - if (pExpr == NULL) { - continue; - } - - int32_t functionId = pExpr->base.functionId; - if (functionId == TSDB_FUNC_TS || functionId == TSDB_FUNC_TS_DUMMY) { - continue; - } - - if (!IS_MULTIOUTPUT(aAggs[functionId].status)) { - return true; - } - } - - return false; -} - bool isSimpleAggregateRv(SQueryInfo* pQueryInfo) { if (pQueryInfo->interval.interval > 0 || pQueryInfo->sessionWindow.gap > 0) { return false; } - if (tscGroupbyColumn(pQueryInfo) || isTsCompQuery(pQueryInfo)) { + if (tscIsDiffQuery(pQueryInfo)) { return false; } @@ -518,13 +532,13 @@ bool isSimpleAggregateRv(SQueryInfo* pQueryInfo) { continue; } - if (!IS_MULTIOUTPUT(aAggs[functionId].status)) { + if ((!IS_MULTIOUTPUT(aAggs[functionId].status)) || + (functionId == TSDB_FUNC_TOP || functionId == TSDB_FUNC_BOTTOM || functionId == TSDB_FUNC_TS_COMP)) { return true; } } return false; - } bool isBlockDistQuery(SQueryInfo* pQueryInfo) { @@ -812,6 +826,7 @@ static void fetchNextBlockIfCompleted(SOperatorInfo* pOperator, bool* newgroup) for (int32_t i = 0; i < pOperator->numOfUpstream; ++i) { SJoinStatus* pStatus = &pJoinInfo->status[i]; if (pStatus->pBlock == NULL || pStatus->index >= pStatus->pBlock->info.rows) { + tscDebug("Retrieve nest query result, index:%d, total:%d", i, pOperator->numOfUpstream); pStatus->pBlock = pOperator->upstream[i]->exec(pOperator->upstream[i], newgroup); pStatus->index = 0; @@ -972,6 +987,9 @@ static void destroyDummyInputOperator(void* param, int32_t numOfOutput) { pInfo->block = destroyOutputBuf(pInfo->block); pInfo->pSql = NULL; + + cleanupResultRowInfo(&pInfo->pTableQueryInfo->resInfo); + tfree(pInfo->pTableQueryInfo); } // todo this operator servers as the adapter for Operator tree and SqlRes result, remove it later @@ -1056,7 +1074,7 @@ SOperatorInfo* createJoinOperatorInfo(SOperatorInfo** pUpstream, int32_t numOfUp return pOperator; } -void convertQueryResult(SSqlRes* pRes, SQueryInfo* pQueryInfo) { +void convertQueryResult(SSqlRes* pRes, SQueryInfo* pQueryInfo, uint64_t objId) { // set the correct result SSDataBlock* p = pQueryInfo->pQInfo->runtimeEnv.outputBuf; pRes->numOfRows = (p != NULL)? p->info.rows: 0; @@ -1066,6 +1084,7 @@ void convertQueryResult(SSqlRes* pRes, SQueryInfo* pQueryInfo) { tscSetResRawPtrRv(pRes, pQueryInfo, p); } + tscDebug("0x%"PRIx64" retrieve result in pRes, numOfRows:%d", objId, pRes->numOfRows); pRes->row = 0; pRes->completed = (pRes->numOfRows == 0); } @@ -1088,7 +1107,9 @@ static void createInputDataFilterInfo(SQueryInfo* px, int32_t numOfCol1, int32_t tfree(tableCols); } -void handleDownstreamOperator(SSqlObj** pSqlObjList, int32_t numOfUpstream, SQueryInfo* px, SSqlRes* pOutput) { +void handleDownstreamOperator(SSqlObj** pSqlObjList, int32_t numOfUpstream, SQueryInfo* px, SSqlObj* pSql) { + SSqlRes* pOutput = &pSql->res; + // handle the following query process if (px->pQInfo == NULL) { SColumnInfo* pColumnInfo = extractColumnInfoFromResult(px->colList); @@ -1168,7 +1189,9 @@ void handleDownstreamOperator(SSqlObj** pSqlObjList, int32_t numOfUpstream, SQue } } - px->pQInfo = createQInfoFromQueryNode(px, &tableGroupInfo, pSourceOperator, NULL, NULL, MASTER_SCAN); + tscDebug("0x%"PRIx64" create QInfo 0x%"PRIx64" to execute the main query while all nest queries are ready", pSql->self, pSql->self); + px->pQInfo = createQInfoFromQueryNode(px, &tableGroupInfo, pSourceOperator, NULL, NULL, MASTER_SCAN, pSql->self); + tfree(pColumnInfo); tfree(schema); @@ -1176,9 +1199,9 @@ void handleDownstreamOperator(SSqlObj** pSqlObjList, int32_t numOfUpstream, SQue pSourceOperator->pRuntimeEnv = &px->pQInfo->runtimeEnv; } - uint64_t qId = 0; + uint64_t qId = pSql->self; qTableQuery(px->pQInfo, &qId); - convertQueryResult(pOutput, px); + convertQueryResult(pOutput, px, pSql->self); } static void tscDestroyResPointerInfo(SSqlRes* pRes) { @@ -1374,7 +1397,7 @@ void tscFreeSqlObj(SSqlObj* pSql) { SSqlCmd* pCmd = &pSql->cmd; int32_t cmd = pCmd->command; - if (cmd < TSDB_SQL_INSERT || cmd == TSDB_SQL_RETRIEVE_LOCALMERGE || cmd == TSDB_SQL_RETRIEVE_EMPTY_RESULT || + if (cmd < TSDB_SQL_INSERT || cmd == TSDB_SQL_RETRIEVE_GLOBALMERGE || cmd == TSDB_SQL_RETRIEVE_EMPTY_RESULT || cmd == TSDB_SQL_TABLE_JOIN_RETRIEVE) { tscRemoveFromSqlList(pSql); } @@ -2177,6 +2200,7 @@ size_t tscNumOfExprs(SQueryInfo* pQueryInfo) { return taosArrayGetSize(pQueryInfo->exprList); } +// todo REFACTOR void tscExprAddParams(SSqlExpr* pExpr, char* argument, int32_t type, int32_t bytes) { assert (pExpr != NULL || argument != NULL || bytes != 0); @@ -3278,7 +3302,6 @@ SSqlObj* createSubqueryObj(SSqlObj* pSql, int16_t tableIndex, __async_cb_func_t pNewQueryInfo->numOfTables = 0; pNewQueryInfo->pTableMetaInfo = NULL; pNewQueryInfo->bufLen = pQueryInfo->bufLen; - pNewQueryInfo->buf = malloc(pQueryInfo->bufLen); if (pNewQueryInfo->buf == NULL) { terrno = TSDB_CODE_TSC_OUT_OF_MEMORY; @@ -3438,7 +3461,7 @@ void doRetrieveSubqueryData(SSchedMsg *pMsg) { } SQueryInfo *pQueryInfo = tscGetQueryInfo(&pSql->cmd); - handleDownstreamOperator(pSql->pSubs, pSql->subState.numOfSub, pQueryInfo, &pSql->res); + handleDownstreamOperator(pSql->pSubs, pSql->subState.numOfSub, pQueryInfo, pSql); pSql->res.qId = -1; if (pSql->res.code == TSDB_CODE_SUCCESS) { @@ -3468,13 +3491,12 @@ static void tscSubqueryRetrieveCallback(void* param, TAOS_RES* tres, int code) { } pParentSql->cmd.active = pParentSql->cmd.pQueryInfo; - - SSchedMsg schedMsg = {0}; - schedMsg.fp = doRetrieveSubqueryData; - schedMsg.ahandle = (void *)pParentSql; - schedMsg.thandle = (void *)1; - schedMsg.msg = 0; - taosScheduleTask(tscQhandle, &schedMsg); + pParentSql->res.qId = -1; + if (pSql->res.code == TSDB_CODE_SUCCESS) { + (*pSql->fp)(pParentSql->param, pParentSql, pParentSql->res.numOfRows); + } else { + tscAsyncResultOnError(pParentSql); + } } // todo handle the failure @@ -4238,7 +4260,8 @@ int32_t tscCreateQueryFromQueryInfo(SQueryInfo* pQueryInfo, SQueryAttr* pQueryAt pQueryAttr->hasTagResults = hasTagValOutput(pQueryInfo); pQueryAttr->stabledev = isStabledev(pQueryInfo); pQueryAttr->tsCompQuery = isTsCompQuery(pQueryInfo); - pQueryAttr->simpleAgg = isSimpleAggregate(pQueryInfo); + pQueryAttr->diffQuery = tscIsDiffQuery(pQueryInfo); + pQueryAttr->simpleAgg = isSimpleAggregateRv(pQueryInfo); pQueryAttr->needReverseScan = tscNeedReverseScan(pQueryInfo); pQueryAttr->stableQuery = QUERY_IS_STABLE_QUERY(pQueryInfo->type); pQueryAttr->groupbyColumn = (!pQueryInfo->stateWindow) && tscGroupbyColumn(pQueryInfo); @@ -4257,7 +4280,6 @@ int32_t tscCreateQueryFromQueryInfo(SQueryInfo* pQueryInfo, SQueryAttr* pQueryAt pQueryAttr->fillType = pQueryInfo->fillType; pQueryAttr->havingNum = pQueryInfo->havingFieldNum; - if (pQueryInfo->order.order == TSDB_ORDER_ASC) { // TODO refactor pQueryAttr->window = pQueryInfo->window; } else { @@ -4269,10 +4291,9 @@ int32_t tscCreateQueryFromQueryInfo(SQueryInfo* pQueryInfo, SQueryAttr* pQueryAt STableMetaInfo* pTableMetaInfo = pQueryInfo->pTableMetaInfo[0]; - pQueryAttr->pGroupbyExpr = calloc(1, sizeof(SGroupbyExpr)); - *(pQueryAttr->pGroupbyExpr) = pQueryInfo->groupbyExpr; - if (pQueryInfo->groupbyExpr.numOfGroupCols > 0) { + pQueryAttr->pGroupbyExpr = calloc(1, sizeof(SGroupbyExpr)); + *(pQueryAttr->pGroupbyExpr) = pQueryInfo->groupbyExpr; pQueryAttr->pGroupbyExpr->columnInfo = taosArrayDup(pQueryInfo->groupbyExpr.columnInfo); } else { assert(pQueryInfo->groupbyExpr.columnInfo == NULL); @@ -4351,7 +4372,7 @@ int32_t tscCreateQueryFromQueryInfo(SQueryInfo* pQueryInfo, SQueryAttr* pQueryAt return TSDB_CODE_TSC_INVALID_OPERATION; } - if (pQueryAttr->pGroupbyExpr->numOfGroupCols < 0) { + if (pQueryAttr->pGroupbyExpr != NULL && pQueryAttr->pGroupbyExpr->numOfGroupCols < 0) { tscError("%p illegal value of numOfGroupCols in query msg: %d", addr, pQueryInfo->groupbyExpr.numOfGroupCols); return TSDB_CODE_TSC_INVALID_OPERATION; } diff --git a/src/common/inc/tcmdtype.h b/src/common/inc/tcmdtype.h index 928964857b334309d4f60376d3da7a07031688fc..4331ddbf8923ee758ebaf3116740db8e24df29a9 100644 --- a/src/common/inc/tcmdtype.h +++ b/src/common/inc/tcmdtype.h @@ -78,7 +78,7 @@ enum { // SQL below for client local TSDB_DEFINE_SQL_TYPE( TSDB_SQL_LOCAL, "local" ) TSDB_DEFINE_SQL_TYPE( TSDB_SQL_DESCRIBE_TABLE, "describe-table" ) - TSDB_DEFINE_SQL_TYPE( TSDB_SQL_RETRIEVE_LOCALMERGE, "retrieve-localmerge" ) + TSDB_DEFINE_SQL_TYPE( TSDB_SQL_RETRIEVE_GLOBALMERGE, "retrieve-globalmerge" ) TSDB_DEFINE_SQL_TYPE( TSDB_SQL_TABLE_JOIN_RETRIEVE, "join-retrieve" ) TSDB_DEFINE_SQL_TYPE( TSDB_SQL_SHOW_CREATE_TABLE, "show-create-table") diff --git a/src/common/inc/texpr.h b/src/common/inc/texpr.h index 275dd12fd7ca9f9771592039d846593fa958f240..2e49a69366c2277c98ec32a1d8419c141ddecc0f 100644 --- a/src/common/inc/texpr.h +++ b/src/common/inc/texpr.h @@ -94,6 +94,8 @@ bool exprTreeApplyFilter(tExprNode *pExpr, const void *pItem, SExprTraverseSupp void arithmeticTreeTraverse(tExprNode *pExprs, int32_t numOfRows, char *pOutput, void *param, int32_t order, char *(*cb)(void *, const char*, int32_t)); +void buildFilterSetFromBinary(void **q, const char *buf, int32_t len); + #ifdef __cplusplus } #endif diff --git a/src/common/src/texpr.c b/src/common/src/texpr.c index f2dd3890a163ec1e1e25d2ac8b55f23aa9d5a79d..6fa4d68734df6fde94725026bd65b219cc6564ab 100644 --- a/src/common/src/texpr.c +++ b/src/common/src/texpr.c @@ -466,6 +466,32 @@ tExprNode* exprTreeFromTableName(const char* tbnameCond) { return expr; } +void buildFilterSetFromBinary(void **q, const char *buf, int32_t len) { + SBufferReader br = tbufInitReader(buf, len, false); + uint32_t type = tbufReadUint32(&br); + SHashObj *pObj = taosHashInit(256, taosGetDefaultHashFunction(type), true, false); + int dummy = -1; + int32_t sz = tbufReadInt32(&br); + for (int32_t i = 0; i < sz; i++) { + if (type == TSDB_DATA_TYPE_BOOL || type == TSDB_DATA_TYPE_TINYINT || type == TSDB_DATA_TYPE_SMALLINT || type == TSDB_DATA_TYPE_BIGINT || type == TSDB_DATA_TYPE_INT) { + int64_t val = tbufReadInt64(&br); + taosHashPut(pObj, (char *)&val, sizeof(val), &dummy, sizeof(dummy)); + } else if (type == TSDB_DATA_TYPE_DOUBLE || type == TSDB_DATA_TYPE_FLOAT) { + double val = tbufReadDouble(&br); + taosHashPut(pObj, (char *)&val, sizeof(val), &dummy, sizeof(dummy)); + } else if (type == TSDB_DATA_TYPE_BINARY) { + size_t t = 0; + const char *val = tbufReadBinary(&br, &t); + taosHashPut(pObj, (char *)val, t, &dummy, sizeof(dummy)); + } else if (type == TSDB_DATA_TYPE_NCHAR) { + size_t t = 0; + const char *val = tbufReadBinary(&br, &t); + taosHashPut(pObj, (char *)val, t, &dummy, sizeof(dummy)); + } + } + *q = (void *)pObj; +} + tExprNode* exprdup(tExprNode* pNode) { if (pNode == NULL) { return NULL; diff --git a/src/common/src/tglobal.c b/src/common/src/tglobal.c index eae2fab32b892bdc9ede258467217df0d82eccea..af21ef6d82f96de6c2d0349911b3176f14510ee2 100644 --- a/src/common/src/tglobal.c +++ b/src/common/src/tglobal.c @@ -831,6 +831,16 @@ static void doInitGlobalConfig(void) { cfg.unitType = TAOS_CFG_UTYPE_NONE; taosInitConfigOption(cfg); + cfg.option = "precision"; + cfg.ptr = &tsTimePrecision; + cfg.valType = TAOS_CFG_VTYPE_INT8; + cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW; + cfg.minValue = TSDB_MIN_PRECISION; + cfg.maxValue = TSDB_MAX_PRECISION; + cfg.ptrLength = 0; + cfg.unitType = TAOS_CFG_UTYPE_NONE; + taosInitConfigOption(cfg); + cfg.option = "comp"; cfg.ptr = &tsCompression; cfg.valType = TAOS_CFG_VTYPE_INT8; @@ -901,6 +911,16 @@ static void doInitGlobalConfig(void) { cfg.unitType = TAOS_CFG_UTYPE_NONE; taosInitConfigOption(cfg); + cfg.option = "cachelast"; + cfg.ptr = &tsCacheLastRow; + cfg.valType = TAOS_CFG_VTYPE_INT8; + cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW; + cfg.minValue = TSDB_MIN_DB_CACHE_LAST_ROW; + cfg.maxValue = TSDB_MAX_DB_CACHE_LAST_ROW; + cfg.ptrLength = 0; + cfg.unitType = TAOS_CFG_UTYPE_NONE; + taosInitConfigOption(cfg); + cfg.option = "mqttHostName"; cfg.ptr = tsMqttHostName; cfg.valType = TAOS_CFG_VTYPE_STRING; diff --git a/src/common/src/tvariant.c b/src/common/src/tvariant.c index 9988450c30f341d03a97c2393e1939aff96daf7d..33dab51633b244326b0490c6bf7b784bc41fe77f 100644 --- a/src/common/src/tvariant.c +++ b/src/common/src/tvariant.c @@ -74,7 +74,7 @@ void tVariantCreate(tVariant *pVar, SStrToken *token) { case TSDB_DATA_TYPE_BINARY: { pVar->pz = strndup(token->z, token->n); - pVar->nLen = strdequote(pVar->pz); + pVar->nLen = strRmquote(pVar->pz, token->n); break; } diff --git a/src/connector/jdbc/CMakeLists.txt b/src/connector/jdbc/CMakeLists.txt index 61e976cb184d3240bdc8917a5b2e5f3182d55fcc..a04902a422deadf590fa9f6172b1a58c739be19a 100644 --- a/src/connector/jdbc/CMakeLists.txt +++ b/src/connector/jdbc/CMakeLists.txt @@ -8,10 +8,9 @@ IF (TD_MVN_INSTALLED) ADD_CUSTOM_COMMAND(OUTPUT ${JDBC_CMD_NAME} POST_BUILD COMMAND mvn -Dmaven.test.skip=true install -f ${CMAKE_CURRENT_SOURCE_DIR}/pom.xml - COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/target/taos-jdbcdriver-2.0.29.jar ${LIBRARY_OUTPUT_PATH} + COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/target/taos-jdbcdriver-2.0.30.jar ${LIBRARY_OUTPUT_PATH} COMMAND mvn -Dmaven.test.skip=true clean -f ${CMAKE_CURRENT_SOURCE_DIR}/pom.xml COMMENT "build jdbc driver") ADD_CUSTOM_TARGET(${JDBC_TARGET_NAME} ALL WORKING_DIRECTORY ${EXECUTABLE_OUTPUT_PATH} DEPENDS ${JDBC_CMD_NAME}) ENDIF () - diff --git a/src/connector/jdbc/deploy-pom.xml b/src/connector/jdbc/deploy-pom.xml index 968a9bf470ddde1996467467fa24cfd2fbf355e0..657645d46c00d6b7554c931a6dacca4695e34383 100755 --- a/src/connector/jdbc/deploy-pom.xml +++ b/src/connector/jdbc/deploy-pom.xml @@ -5,7 +5,7 @@ com.taosdata.jdbc taos-jdbcdriver - 2.0.29 + 2.0.30 jar JDBCDriver diff --git a/src/connector/jdbc/pom.xml b/src/connector/jdbc/pom.xml old mode 100755 new mode 100644 index ef353d1d19d37da3c1a3e9bdc4a2a378cf4edc0c..96e17bcd9b0eedc2116c2a8358e46d7b6e696b4e --- a/src/connector/jdbc/pom.xml +++ b/src/connector/jdbc/pom.xml @@ -3,7 +3,7 @@ 4.0.0 com.taosdata.jdbc taos-jdbcdriver - 2.0.29 + 2.0.30 jar JDBCDriver https://github.com/taosdata/TDengine/tree/master/src/connector/jdbc @@ -47,7 +47,7 @@ org.apache.httpcomponents httpclient - 4.5.8 + 4.5.13 com.alibaba diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/AbstractDatabaseMetaData.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/AbstractDatabaseMetaData.java index 5dcaa77ebd4a15087785a6a9b642b85f160f5287..48811d30a6903c077a9c0fb55176b0bc2ca9ba75 100644 --- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/AbstractDatabaseMetaData.java +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/AbstractDatabaseMetaData.java @@ -12,6 +12,9 @@ public abstract class AbstractDatabaseMetaData extends WrapperImpl implements Da private final static int DRIVER_MAJAR_VERSION = 2; private final static int DRIVER_MINOR_VERSION = 0; + private String precision = "ms"; + private String database; + public boolean allProceduresAreCallable() throws SQLException { return false; } @@ -493,102 +496,105 @@ public abstract class AbstractDatabaseMetaData extends WrapperImpl implements Da public abstract ResultSet getTables(String catalog, String schemaPattern, String tableNamePattern, String[] types) throws SQLException; - protected ResultSet getTables(String catalog, String schemaPattern, String tableNamePattern, String[] types, Connection connection) throws SQLException { - try (Statement stmt = connection.createStatement()) { - if (catalog == null || catalog.isEmpty()) - return null; - - ResultSet databases = stmt.executeQuery("show databases"); - String dbname = null; - while (databases.next()) { - dbname = databases.getString("name"); - if (dbname.equalsIgnoreCase(catalog)) - break; - } - databases.close(); - if (dbname == null) - return null; + private List buildGetTablesColumnMetaDataList() { + List columnMetaDataList = new ArrayList<>(); + columnMetaDataList.add(buildTableCatalogMeta(1)); // 1. TABLE_CAT + columnMetaDataList.add(buildTableSchemaMeta(2)); // 2. TABLE_SCHEM + columnMetaDataList.add(buildTableNameMeta(3)); // 3. TABLE_NAME + columnMetaDataList.add(buildTableTypeMeta(4)); // 4. TABLE_TYPE + columnMetaDataList.add(buildRemarksMeta(5)); // 5. remarks + columnMetaDataList.add(buildTypeCatMeta(6)); // 6. TYPE_CAT + columnMetaDataList.add(buildTypeSchemaMeta(7)); // 7. TYPE_SCHEM + columnMetaDataList.add(buildTypeNameMeta(8)); // 8. TYPE_NAME + columnMetaDataList.add(buildSelfReferencingColName(9)); // 9. SELF_REFERENCING_COL_NAME + columnMetaDataList.add(buildRefGenerationMeta(10)); // 10. REF_GENERATION + return columnMetaDataList; + } + + private ColumnMetaData buildTypeCatMeta(int colIndex) { + ColumnMetaData col6 = new ColumnMetaData(); + col6.setColIndex(colIndex); + col6.setColName("TYPE_CAT"); + col6.setColType(Types.NCHAR); + return col6; + } + + private ColumnMetaData buildTypeSchemaMeta(int colIndex) { + ColumnMetaData col7 = new ColumnMetaData(); + col7.setColIndex(colIndex); + col7.setColName("TYPE_SCHEM"); + col7.setColType(Types.NCHAR); + return col7; + } + + private ColumnMetaData buildTypeNameMeta(int colIndex) { + ColumnMetaData col8 = new ColumnMetaData(); + col8.setColIndex(colIndex); + col8.setColName("TYPE_NAME"); + col8.setColType(Types.NCHAR); + return col8; + } + + private ColumnMetaData buildSelfReferencingColName(int colIndex) { + ColumnMetaData col9 = new ColumnMetaData(); + col9.setColIndex(colIndex); + col9.setColName("SELF_REFERENCING_COL_NAME"); + col9.setColType(Types.NCHAR); + return col9; + } + + private ColumnMetaData buildRefGenerationMeta(int colIndex) { + ColumnMetaData col10 = new ColumnMetaData(); + col10.setColIndex(colIndex); + col10.setColName("REF_GENERATION"); + col10.setColType(Types.NCHAR); + return col10; + } - stmt.execute("use " + dbname); - DatabaseMetaDataResultSet resultSet = new DatabaseMetaDataResultSet(); - List columnMetaDataList = new ArrayList<>(); - ColumnMetaData col1 = new ColumnMetaData(); - col1.setColIndex(1); - col1.setColName("TABLE_CAT"); - col1.setColType(TSDBConstants.TSDB_DATA_TYPE_NCHAR); - columnMetaDataList.add(col1); - ColumnMetaData col2 = new ColumnMetaData(); - col2.setColIndex(2); - col2.setColName("TABLE_SCHEM"); - col2.setColType(TSDBConstants.TSDB_DATA_TYPE_NCHAR); - columnMetaDataList.add(col2); - ColumnMetaData col3 = new ColumnMetaData(); - col3.setColIndex(3); - col3.setColName("TABLE_NAME"); - col3.setColType(TSDBConstants.TSDB_DATA_TYPE_NCHAR); - columnMetaDataList.add(col3); - ColumnMetaData col4 = new ColumnMetaData(); - col4.setColIndex(4); - col4.setColName("TABLE_TYPE"); - col4.setColType(TSDBConstants.TSDB_DATA_TYPE_NCHAR); - columnMetaDataList.add(col4); - ColumnMetaData col5 = new ColumnMetaData(); - col5.setColIndex(5); - col5.setColName("REMARKS"); - col5.setColType(TSDBConstants.TSDB_DATA_TYPE_NCHAR); - columnMetaDataList.add(col5); - ColumnMetaData col6 = new ColumnMetaData(); - col6.setColIndex(6); - col6.setColName("TYPE_CAT"); - col6.setColType(TSDBConstants.TSDB_DATA_TYPE_NCHAR); - columnMetaDataList.add(col6); - ColumnMetaData col7 = new ColumnMetaData(); - col7.setColIndex(7); - col7.setColName("TYPE_SCHEM"); - col7.setColType(TSDBConstants.TSDB_DATA_TYPE_NCHAR); - columnMetaDataList.add(col7); - ColumnMetaData col8 = new ColumnMetaData(); - col8.setColIndex(8); - col8.setColName("TYPE_NAME"); - col8.setColType(TSDBConstants.TSDB_DATA_TYPE_NCHAR); - columnMetaDataList.add(col8); - ColumnMetaData col9 = new ColumnMetaData(); - col9.setColIndex(9); - col9.setColName("SELF_REFERENCING_COL_NAME"); - col9.setColType(TSDBConstants.TSDB_DATA_TYPE_NCHAR); - columnMetaDataList.add(col9); - ColumnMetaData col10 = new ColumnMetaData(); - col10.setColIndex(10); - col10.setColName("REF_GENERATION"); - col10.setColType(TSDBConstants.TSDB_DATA_TYPE_NCHAR); - columnMetaDataList.add(col10); - resultSet.setColumnMetaDataList(columnMetaDataList); + protected ResultSet getTables(String catalog, String schemaPattern, String tableNamePattern, String[] types, Connection connection) throws SQLException { + if (catalog == null || catalog.isEmpty()) + return null; + if (!isAvailableCatalog(connection, catalog)) + return new EmptyResultSet(); - List rowDataList = new ArrayList<>(); + DatabaseMetaDataResultSet resultSet = new DatabaseMetaDataResultSet(); + // set column metadata list + resultSet.setColumnMetaDataList(buildGetTablesColumnMetaDataList()); + // set row data + List rowDataList = new ArrayList<>(); + try (Statement stmt = connection.createStatement()) { + stmt.execute("use " + catalog); ResultSet tables = stmt.executeQuery("show tables"); while (tables.next()) { TSDBResultSetRowData rowData = new TSDBResultSetRowData(10); - rowData.setString(0, dbname); //table_cat - rowData.setString(1, null); //TABLE_SCHEM - rowData.setString(2, tables.getString("table_name")); //TABLE_NAME - rowData.setString(3, "TABLE"); //TABLE_TYPE - rowData.setString(4, ""); //REMARKS + rowData.setStringValue(1, catalog); //TABLE_CAT + rowData.setStringValue(2, null); //TABLE_SCHEM + rowData.setStringValue(3, tables.getString("table_name")); //TABLE_NAME + rowData.setStringValue(4, "TABLE"); //TABLE_TYPE + rowData.setStringValue(5, ""); //REMARKS rowDataList.add(rowData); } - ResultSet stables = stmt.executeQuery("show stables"); while (stables.next()) { TSDBResultSetRowData rowData = new TSDBResultSetRowData(10); - rowData.setString(0, dbname); //TABLE_CAT - rowData.setString(1, null); //TABLE_SCHEM - rowData.setString(2, stables.getString("name")); //TABLE_NAME - rowData.setString(3, "TABLE"); //TABLE_TYPE - rowData.setString(4, "STABLE"); //REMARKS + rowData.setStringValue(1, catalog); //TABLE_CAT + rowData.setStringValue(2, null); //TABLE_SCHEM + rowData.setStringValue(3, stables.getString("name")); //TABLE_NAME + rowData.setStringValue(4, "TABLE"); //TABLE_TYPE + rowData.setStringValue(5, "STABLE"); //REMARKS rowDataList.add(rowData); } resultSet.setRowDataList(rowDataList); - return resultSet; } + return resultSet; + } + + private ColumnMetaData buildTableTypeMeta(int colIndex) { + ColumnMetaData col4 = new ColumnMetaData(); + col4.setColIndex(colIndex); + col4.setColName("TABLE_TYPE"); + col4.setColType(Types.NCHAR); + return col4; } public ResultSet getSchemas() throws SQLException { @@ -597,25 +603,24 @@ public abstract class AbstractDatabaseMetaData extends WrapperImpl implements Da public abstract ResultSet getCatalogs() throws SQLException; + private List buildTableTypesColumnMetadataList() { + List columnMetaDataList = new ArrayList<>(); + columnMetaDataList.add(buildTableTypeMeta(1)); + return columnMetaDataList; + } + public ResultSet getTableTypes() throws SQLException { DatabaseMetaDataResultSet resultSet = new DatabaseMetaDataResultSet(); // set up ColumnMetaDataList - List columnMetaDataList = new ArrayList<>(); - ColumnMetaData colMetaData = new ColumnMetaData(); - colMetaData.setColIndex(0); - colMetaData.setColName("TABLE_TYPE"); - colMetaData.setColSize(10); - colMetaData.setColType(TSDBConstants.TSDB_DATA_TYPE_NCHAR); - columnMetaDataList.add(colMetaData); - resultSet.setColumnMetaDataList(columnMetaDataList); + resultSet.setColumnMetaDataList(buildTableTypesColumnMetadataList()); // set up rowDataList List rowDataList = new ArrayList<>(); TSDBResultSetRowData rowData = new TSDBResultSetRowData(1); - rowData.setString(0, "TABLE"); + rowData.setStringValue(1, "TABLE"); rowDataList.add(rowData); rowData = new TSDBResultSetRowData(1); - rowData.setString(0, "STABLE"); + rowData.setStringValue(1, "STABLE"); rowDataList.add(rowData); resultSet.setRowDataList(rowDataList); @@ -625,278 +630,330 @@ public abstract class AbstractDatabaseMetaData extends WrapperImpl implements Da public abstract ResultSet getColumns(String catalog, String schemaPattern, String tableNamePattern, String columnNamePattern) throws SQLException; protected ResultSet getColumns(String catalog, String schemaPattern, String tableNamePattern, String columnNamePattern, Connection conn) { - try (Statement stmt = conn.createStatement()) { - if (catalog == null || catalog.isEmpty()) - return null; - - ResultSet databases = stmt.executeQuery("show databases"); - String dbname = null; - while (databases.next()) { - dbname = databases.getString("name"); - if (dbname.equalsIgnoreCase(catalog)) - break; - } - databases.close(); - if (dbname == null) - return null; + if (catalog == null || catalog.isEmpty()) + return null; + if (!isAvailableCatalog(conn, catalog)) + return new EmptyResultSet(); - stmt.execute("use " + dbname); - DatabaseMetaDataResultSet resultSet = new DatabaseMetaDataResultSet(); - // set up ColumnMetaDataList - - List columnMetaDataList = new ArrayList<>(); - // TABLE_CAT - ColumnMetaData col1 = new ColumnMetaData(); - col1.setColIndex(1); - col1.setColName("TABLE_CAT"); - col1.setColType(TSDBConstants.TSDB_DATA_TYPE_NCHAR); - columnMetaDataList.add(col1); - // TABLE_SCHEM - ColumnMetaData col2 = new ColumnMetaData(); - col2.setColIndex(2); - col2.setColName("TABLE_SCHEM"); - col2.setColType(TSDBConstants.TSDB_DATA_TYPE_NCHAR); - columnMetaDataList.add(col2); - // TABLE_NAME - ColumnMetaData col3 = new ColumnMetaData(); - col3.setColIndex(3); - col3.setColName("TABLE_NAME"); - col3.setColSize(193); - col3.setColType(TSDBConstants.TSDB_DATA_TYPE_NCHAR); - columnMetaDataList.add(col3); - // COLUMN_NAME - ColumnMetaData col4 = new ColumnMetaData(); - col4.setColIndex(4); - col4.setColName("COLUMN_NAME"); - col4.setColSize(65); - col4.setColType(TSDBConstants.TSDB_DATA_TYPE_NCHAR); - columnMetaDataList.add(col4); - // DATA_TYPE - ColumnMetaData col5 = new ColumnMetaData(); - col5.setColIndex(5); - col5.setColName("DATA_TYPE"); - col5.setColType(TSDBConstants.TSDB_DATA_TYPE_INT); - columnMetaDataList.add(col5); - // TYPE_NAME - ColumnMetaData col6 = new ColumnMetaData(); - col6.setColIndex(6); - col6.setColName("TYPE_NAME"); - col6.setColType(TSDBConstants.TSDB_DATA_TYPE_NCHAR); - columnMetaDataList.add(col6); - // COLUMN_SIZE - ColumnMetaData col7 = new ColumnMetaData(); - col7.setColIndex(7); - col7.setColName("COLUMN_SIZE"); - col7.setColType(TSDBConstants.TSDB_DATA_TYPE_INT); - columnMetaDataList.add(col7); - // BUFFER_LENGTH, not used - ColumnMetaData col8 = new ColumnMetaData(); - col8.setColIndex(8); - col8.setColName("BUFFER_LENGTH"); - columnMetaDataList.add(col8); - // DECIMAL_DIGITS - ColumnMetaData col9 = new ColumnMetaData(); - col9.setColIndex(9); - col9.setColName("DECIMAL_DIGITS"); - col9.setColType(TSDBConstants.TSDB_DATA_TYPE_INT); - columnMetaDataList.add(col9); - // add NUM_PREC_RADIX - ColumnMetaData col10 = new ColumnMetaData(); - col10.setColIndex(10); - col10.setColName("NUM_PREC_RADIX"); - col10.setColType(TSDBConstants.TSDB_DATA_TYPE_INT); - columnMetaDataList.add(col10); - // NULLABLE - ColumnMetaData col11 = new ColumnMetaData(); - col11.setColIndex(11); - col11.setColName("NULLABLE"); - col11.setColType(TSDBConstants.TSDB_DATA_TYPE_INT); - columnMetaDataList.add(col11); - // REMARKS - ColumnMetaData col12 = new ColumnMetaData(); - col12.setColIndex(12); - col12.setColName("REMARKS"); - col12.setColType(TSDBConstants.TSDB_DATA_TYPE_NCHAR); - columnMetaDataList.add(col12); - // COLUMN_DEF - ColumnMetaData col13 = new ColumnMetaData(); - col13.setColIndex(13); - col13.setColName("COLUMN_DEF"); - col13.setColType(TSDBConstants.TSDB_DATA_TYPE_NCHAR); - columnMetaDataList.add(col13); - //SQL_DATA_TYPE - ColumnMetaData col14 = new ColumnMetaData(); - col14.setColIndex(14); - col14.setColName("SQL_DATA_TYPE"); - col14.setColType(TSDBConstants.TSDB_DATA_TYPE_INT); - columnMetaDataList.add(col14); - //SQL_DATETIME_SUB - ColumnMetaData col15 = new ColumnMetaData(); - col15.setColIndex(15); - col15.setColName("SQL_DATETIME_SUB"); - col15.setColType(TSDBConstants.TSDB_DATA_TYPE_INT); - columnMetaDataList.add(col15); - //CHAR_OCTET_LENGTH - ColumnMetaData col16 = new ColumnMetaData(); - col16.setColIndex(16); - col16.setColName("CHAR_OCTET_LENGTH"); - col16.setColType(TSDBConstants.TSDB_DATA_TYPE_INT); - columnMetaDataList.add(col16); - //ORDINAL_POSITION - ColumnMetaData col17 = new ColumnMetaData(); - col17.setColIndex(17); - col17.setColName("ORDINAL_POSITION"); - col17.setColType(TSDBConstants.TSDB_DATA_TYPE_INT); - columnMetaDataList.add(col17); - // IS_NULLABLE - ColumnMetaData col18 = new ColumnMetaData(); - col18.setColIndex(18); - col18.setColName("IS_NULLABLE"); - col18.setColType(TSDBConstants.TSDB_DATA_TYPE_NCHAR); - columnMetaDataList.add(col18); - //SCOPE_CATALOG - ColumnMetaData col19 = new ColumnMetaData(); - col19.setColIndex(19); - col19.setColName("SCOPE_CATALOG"); - col19.setColType(TSDBConstants.TSDB_DATA_TYPE_NCHAR); - columnMetaDataList.add(col19); - //SCOPE_SCHEMA - ColumnMetaData col20 = new ColumnMetaData(); - col20.setColIndex(20); - col20.setColName("SCOPE_SCHEMA"); - col20.setColType(TSDBConstants.TSDB_DATA_TYPE_NCHAR); - columnMetaDataList.add(col20); - //SCOPE_TABLE - ColumnMetaData col21 = new ColumnMetaData(); - col21.setColIndex(21); - col21.setColName("SCOPE_TABLE"); - col21.setColType(TSDBConstants.TSDB_DATA_TYPE_NCHAR); - columnMetaDataList.add(col21); - //SOURCE_DATA_TYPE - ColumnMetaData col22 = new ColumnMetaData(); - col22.setColIndex(22); - col22.setColName("SOURCE_DATA_TYPE"); - col22.setColType(TSDBConstants.TSDB_DATA_TYPE_SMALLINT); - columnMetaDataList.add(col22); - //IS_AUTOINCREMENT - ColumnMetaData col23 = new ColumnMetaData(); - col23.setColIndex(23); - col23.setColName("IS_AUTOINCREMENT"); - col23.setColType(TSDBConstants.TSDB_DATA_TYPE_NCHAR); - columnMetaDataList.add(col23); - //IS_GENERATEDCOLUMN - ColumnMetaData col24 = new ColumnMetaData(); - col24.setColIndex(24); - col24.setColName("IS_GENERATEDCOLUMN"); - col24.setColType(TSDBConstants.TSDB_DATA_TYPE_NCHAR); - columnMetaDataList.add(col24); - - resultSet.setColumnMetaDataList(columnMetaDataList); - // set up rowDataList - ResultSet rs = stmt.executeQuery("describe " + dbname + "." + tableNamePattern); - List rowDataList = new ArrayList<>(); - int index = 0; + DatabaseMetaDataResultSet resultSet = new DatabaseMetaDataResultSet(); + // set up ColumnMetaDataList + resultSet.setColumnMetaDataList(buildGetColumnsColumnMetaDataList()); + // set up rowDataList + List rowDataList = new ArrayList<>(); + try (Statement stmt = conn.createStatement()) { + ResultSet rs = stmt.executeQuery("describe " + catalog + "." + tableNamePattern); + int rowIndex = 0; while (rs.next()) { TSDBResultSetRowData rowData = new TSDBResultSetRowData(24); // set TABLE_CAT - rowData.setString(0, dbname); + rowData.setStringValue(1, catalog); + // set TABLE_SCHEM + rowData.setStringValue(2, null); // set TABLE_NAME - rowData.setString(2, tableNamePattern); + rowData.setStringValue(3, tableNamePattern); // set COLUMN_NAME - rowData.setString(3, rs.getString("Field")); + rowData.setStringValue(4, rs.getString("Field")); // set DATA_TYPE String typeName = rs.getString("Type"); - rowData.setInt(4, getDataType(typeName)); + rowData.setIntValue(5, TSDBConstants.typeName2JdbcType(typeName)); // set TYPE_NAME - rowData.setString(5, typeName); + rowData.setStringValue(6, typeName); // set COLUMN_SIZE int length = rs.getInt("Length"); - rowData.setInt(6, getColumnSize(typeName, length)); + rowData.setIntValue(7, calculateColumnSize(typeName, precision, length)); + // set BUFFER LENGTH + rowData.setStringValue(8, null); // set DECIMAL_DIGITS - rowData.setInt(8, getDecimalDigits(typeName)); + Integer decimalDigits = calculateDecimalDigits(typeName); + if (decimalDigits != null) { + rowData.setIntValue(9, decimalDigits); + } else { + rowData.setStringValue(9, null); + } // set NUM_PREC_RADIX - rowData.setInt(9, 10); + rowData.setIntValue(10, 10); // set NULLABLE - rowData.setInt(10, getNullable(index, typeName)); + rowData.setIntValue(11, isNullable(rowIndex, typeName)); // set REMARKS - rowData.setString(11, rs.getString("Note")); + String note = rs.getString("Note"); + rowData.setStringValue(12, note.trim().isEmpty() ? null : note); rowDataList.add(rowData); - index++; + rowIndex++; } resultSet.setRowDataList(rowDataList); - return resultSet; - } catch (SQLException e) { e.printStackTrace(); } - return null; + return resultSet; } - protected int getNullable(int index, String typeName) { + private int isNullable(int index, String typeName) { if (index == 0 && "TIMESTAMP".equals(typeName)) return DatabaseMetaData.columnNoNulls; return DatabaseMetaData.columnNullable; } - protected int getColumnSize(String typeName, int length) { + private Integer calculateColumnSize(String typeName, String precisionType, int length) { switch (typeName) { case "TIMESTAMP": - return 23; - default: - return 0; - } - } - - protected int getDecimalDigits(String typeName) { - switch (typeName) { + return precisionType.equals("ms") ? TSDBConstants.TIMESTAMP_MS_PRECISION : TSDBConstants.TIMESTAMP_US_PRECISION; + case "BOOL": + return TSDBConstants.BOOLEAN_PRECISION; + case "TINYINT": + return TSDBConstants.TINYINT_PRECISION; + case "SMALLINT": + return TSDBConstants.SMALLINT_PRECISION; + case "INT": + return TSDBConstants.INT_PRECISION; + case "BIGINT": + return TSDBConstants.BIGINT_PRECISION; case "FLOAT": - return 5; + return TSDBConstants.FLOAT_PRECISION; case "DOUBLE": - return 9; + return TSDBConstants.DOUBLE_PRECISION; + case "NCHAR": + case "BINARY": + return length; default: - return 0; + return null; } } - protected int getDataType(String typeName) { + private Integer calculateDecimalDigits(String typeName) { switch (typeName) { - case "TIMESTAMP": - return Types.TIMESTAMP; + case "TINYINT": + case "SMALLINT": case "INT": - return Types.INTEGER; case "BIGINT": - return Types.BIGINT; - case "FLOAT": - return Types.FLOAT; - case "DOUBLE": - return Types.DOUBLE; - case "BINARY": - return Types.BINARY; - case "SMALLINT": - return Types.SMALLINT; - case "TINYINT": - return Types.TINYINT; - case "BOOL": - return Types.BOOLEAN; - case "NCHAR": - return Types.NCHAR; + return 0; default: - return Types.NULL; + return null; } } - public ResultSet getColumnPrivileges(String catalog, String schema, String table, String columnNamePattern) - throws SQLException { + private ColumnMetaData buildTableCatalogMeta(int colIndex) { + ColumnMetaData col1 = new ColumnMetaData(); + col1.setColIndex(colIndex); + col1.setColName("TABLE_CAT"); + col1.setColType(Types.NCHAR); + return col1; + } + + private ColumnMetaData buildTableSchemaMeta(int colIndex) { + ColumnMetaData col2 = new ColumnMetaData(); + col2.setColIndex(colIndex); + col2.setColName("TABLE_SCHEM"); + col2.setColType(Types.NCHAR); + return col2; + } + + private ColumnMetaData buildTableNameMeta(int colIndex) { + ColumnMetaData col3 = new ColumnMetaData(); + col3.setColIndex(colIndex); + col3.setColName("TABLE_NAME"); + col3.setColSize(193); + col3.setColType(Types.NCHAR); + return col3; + } + + private ColumnMetaData buildColumnNameMeta(int colIndex) { + ColumnMetaData col4 = new ColumnMetaData(); + col4.setColIndex(colIndex); + col4.setColName("COLUMN_NAME"); + col4.setColSize(65); + col4.setColType(Types.NCHAR); + return col4; + } + + private ColumnMetaData buildDataTypeMeta(int colIndex) { + ColumnMetaData col5 = new ColumnMetaData(); + col5.setColIndex(colIndex); + col5.setColName("DATA_TYPE"); + col5.setColType(Types.INTEGER); + return col5; + } + + private ColumnMetaData buildColumnSizeMeta() { + ColumnMetaData col7 = new ColumnMetaData(); + col7.setColIndex(7); + col7.setColName("COLUMN_SIZE"); + col7.setColType(Types.INTEGER); + return col7; + } + + private ColumnMetaData buildBufferLengthMeta() { + ColumnMetaData col8 = new ColumnMetaData(); + col8.setColIndex(8); + col8.setColName("BUFFER_LENGTH"); + return col8; + } + + private ColumnMetaData buildDecimalDigitsMeta() { + ColumnMetaData col9 = new ColumnMetaData(); + col9.setColIndex(9); + col9.setColName("DECIMAL_DIGITS"); + col9.setColType(Types.INTEGER); + return col9; + } + + private ColumnMetaData buildNumPrecRadixMeta() { + ColumnMetaData col10 = new ColumnMetaData(); + col10.setColIndex(10); + col10.setColName("NUM_PREC_RADIX"); + col10.setColType(Types.INTEGER); + return col10; + } + + private ColumnMetaData buildNullableMeta() { + ColumnMetaData col11 = new ColumnMetaData(); + col11.setColIndex(11); + col11.setColName("NULLABLE"); + col11.setColType(Types.INTEGER); + return col11; + } + + private ColumnMetaData buildRemarksMeta(int colIndex) { + ColumnMetaData col12 = new ColumnMetaData(); + col12.setColIndex(colIndex); + col12.setColName("REMARKS"); + col12.setColType(Types.NCHAR); + return col12; + } + + private ColumnMetaData buildColumnDefMeta() { + ColumnMetaData col13 = new ColumnMetaData(); + col13.setColIndex(13); + col13.setColName("COLUMN_DEF"); + col13.setColType(Types.NCHAR); + return col13; + } + + private ColumnMetaData buildSqlDataTypeMeta() { + ColumnMetaData col14 = new ColumnMetaData(); + col14.setColIndex(14); + col14.setColName("SQL_DATA_TYPE"); + col14.setColType(Types.INTEGER); + return col14; + } + + private ColumnMetaData buildSqlDatetimeSubMeta() { + ColumnMetaData col15 = new ColumnMetaData(); + col15.setColIndex(15); + col15.setColName("SQL_DATETIME_SUB"); + col15.setColType(Types.INTEGER); + return col15; + } + + private ColumnMetaData buildCharOctetLengthMeta() { + ColumnMetaData col16 = new ColumnMetaData(); + col16.setColIndex(16); + col16.setColName("CHAR_OCTET_LENGTH"); + col16.setColType(Types.INTEGER); + return col16; + } + + private ColumnMetaData buildOrdinalPositionMeta() { + ColumnMetaData col17 = new ColumnMetaData(); + col17.setColIndex(17); + col17.setColName("ORDINAL_POSITION"); + col17.setColType(Types.INTEGER); + return col17; + } + + private ColumnMetaData buildIsNullableMeta() { + ColumnMetaData col18 = new ColumnMetaData(); + col18.setColIndex(18); + col18.setColName("IS_NULLABLE"); + col18.setColType(Types.NCHAR); + return col18; + } + + private ColumnMetaData buildScopeCatalogMeta() { + ColumnMetaData col19 = new ColumnMetaData(); + col19.setColIndex(19); + col19.setColName("SCOPE_CATALOG"); + col19.setColType(Types.NCHAR); + return col19; + } + + private ColumnMetaData buildScopeSchemaMeta() { + ColumnMetaData col20 = new ColumnMetaData(); + col20.setColIndex(20); + col20.setColName("SCOPE_SCHEMA"); + col20.setColType(Types.NCHAR); + return col20; + } + + private ColumnMetaData buildScopeTableMeta() { + ColumnMetaData col21 = new ColumnMetaData(); + col21.setColIndex(21); + col21.setColName("SCOPE_TABLE"); + col21.setColType(Types.NCHAR); + return col21; + } + + private ColumnMetaData buildSourceDataTypeMeta() { + ColumnMetaData col22 = new ColumnMetaData(); + col22.setColIndex(22); + col22.setColName("SOURCE_DATA_TYPE"); + col22.setColType(TSDBConstants.TSDB_DATA_TYPE_SMALLINT); + return col22; + } + + private ColumnMetaData buildIsAutoIncrementMeta() { + ColumnMetaData col23 = new ColumnMetaData(); + col23.setColIndex(23); + col23.setColName("IS_AUTOINCREMENT"); + col23.setColType(Types.NCHAR); + return col23; + } + + private ColumnMetaData buildIsGeneratedColumnMeta() { + ColumnMetaData col24 = new ColumnMetaData(); + col24.setColIndex(24); + col24.setColName("IS_GENERATEDCOLUMN"); + col24.setColType(Types.NCHAR); + return col24; + } + + private List buildGetColumnsColumnMetaDataList() { + List columnMetaDataList = new ArrayList<>(); + columnMetaDataList.add(buildTableCatalogMeta(1)); //1. TABLE_CAT + columnMetaDataList.add(buildTableSchemaMeta(2)); //2. TABLE_SCHEMA + columnMetaDataList.add(buildTableNameMeta(3)); //3. TABLE_NAME + columnMetaDataList.add(buildColumnNameMeta(4)); //4. COLUMN_NAME + columnMetaDataList.add(buildDataTypeMeta(5)); //5. DATA_TYPE + columnMetaDataList.add(buildTypeNameMeta(6)); //6. TYPE_NAME + columnMetaDataList.add(buildColumnSizeMeta()); //7. COLUMN_SIZE + columnMetaDataList.add(buildBufferLengthMeta()); //8. BUFFER_LENGTH, not used + columnMetaDataList.add(buildDecimalDigitsMeta()); //9. DECIMAL_DIGITS + columnMetaDataList.add(buildNumPrecRadixMeta()); //10. NUM_PREC_RADIX + columnMetaDataList.add(buildNullableMeta()); //11. NULLABLE + columnMetaDataList.add(buildRemarksMeta(12)); //12. REMARKS + columnMetaDataList.add(buildColumnDefMeta()); //13. COLUMN_DEF + columnMetaDataList.add(buildSqlDataTypeMeta()); //14. SQL_DATA_TYPE + columnMetaDataList.add(buildSqlDatetimeSubMeta()); //15. SQL_DATETIME_SUB + columnMetaDataList.add(buildCharOctetLengthMeta()); //16. CHAR_OCTET_LENGTH + columnMetaDataList.add(buildOrdinalPositionMeta()); //17. ORDINAL_POSITION + columnMetaDataList.add(buildIsNullableMeta()); //18. IS_NULLABLE + columnMetaDataList.add(buildScopeCatalogMeta()); //19. SCOPE_CATALOG + columnMetaDataList.add(buildScopeSchemaMeta()); //20. SCOPE_SCHEMA + columnMetaDataList.add(buildScopeTableMeta()); //21. SCOPE_TABLE + columnMetaDataList.add(buildSourceDataTypeMeta()); //22. SOURCE_DATA_TYPE + columnMetaDataList.add(buildIsAutoIncrementMeta()); //23. IS_AUTOINCREMENT + columnMetaDataList.add(buildIsGeneratedColumnMeta()); //24. IS_GENERATEDCOLUMN + return columnMetaDataList; + } + + public ResultSet getColumnPrivileges(String catalog, String schema, String table, String columnNamePattern) throws SQLException { return getEmptyResultSet(); } - public ResultSet getTablePrivileges(String catalog, String schemaPattern, String tableNamePattern) - throws SQLException { + public ResultSet getTablePrivileges(String catalog, String schemaPattern, String tableNamePattern) throws SQLException { return getEmptyResultSet(); } - public ResultSet getBestRowIdentifier(String catalog, String schema, String table, int scope, boolean nullable) - throws SQLException { + public ResultSet getBestRowIdentifier(String catalog, String schema, String table, int scope, boolean nullable) throws SQLException { return getEmptyResultSet(); } @@ -914,8 +971,7 @@ public abstract class AbstractDatabaseMetaData extends WrapperImpl implements Da return getEmptyResultSet(); } - public ResultSet getCrossReference(String parentCatalog, String parentSchema, String parentTable, - String foreignCatalog, String foreignSchema, String foreignTable) throws SQLException { + public ResultSet getCrossReference(String parentCatalog, String parentSchema, String parentTable, String foreignCatalog, String foreignSchema, String foreignTable) throws SQLException { return getEmptyResultSet(); } @@ -923,8 +979,7 @@ public abstract class AbstractDatabaseMetaData extends WrapperImpl implements Da return getEmptyResultSet(); } - public ResultSet getIndexInfo(String catalog, String schema, String table, boolean unique, boolean approximate) - throws SQLException { + public ResultSet getIndexInfo(String catalog, String schema, String table, boolean unique, boolean approximate) throws SQLException { return getEmptyResultSet(); } @@ -976,8 +1031,7 @@ public abstract class AbstractDatabaseMetaData extends WrapperImpl implements Da return false; } - public ResultSet getUDTs(String catalog, String schemaPattern, String typeNamePattern, int[] types) - throws SQLException { + public ResultSet getUDTs(String catalog, String schemaPattern, String typeNamePattern, int[] types) throws SQLException { return getEmptyResultSet(); } @@ -1005,8 +1059,7 @@ public abstract class AbstractDatabaseMetaData extends WrapperImpl implements Da public abstract ResultSet getSuperTables(String catalog, String schemaPattern, String tableNamePattern) throws SQLException; - public ResultSet getAttributes(String catalog, String schemaPattern, String typeNamePattern, - String attributeNamePattern) throws SQLException { + public ResultSet getAttributes(String catalog, String schemaPattern, String typeNamePattern, String attributeNamePattern) throws SQLException { return getEmptyResultSet(); } @@ -1069,18 +1122,15 @@ public abstract class AbstractDatabaseMetaData extends WrapperImpl implements Da return getEmptyResultSet(); } - public ResultSet getFunctions(String catalog, String schemaPattern, String functionNamePattern) - throws SQLException { + public ResultSet getFunctions(String catalog, String schemaPattern, String functionNamePattern) throws SQLException { return getEmptyResultSet(); } - public ResultSet getFunctionColumns(String catalog, String schemaPattern, String functionNamePattern, - String columnNamePattern) throws SQLException { + public ResultSet getFunctionColumns(String catalog, String schemaPattern, String functionNamePattern, String columnNamePattern) throws SQLException { return getEmptyResultSet(); } - public ResultSet getPseudoColumns(String catalog, String schemaPattern, String tableNamePattern, - String columnNamePattern) throws SQLException { + public ResultSet getPseudoColumns(String catalog, String schemaPattern, String tableNamePattern, String columnNamePattern) throws SQLException { return getEmptyResultSet(); } @@ -1093,164 +1143,142 @@ public abstract class AbstractDatabaseMetaData extends WrapperImpl implements Da } protected ResultSet getCatalogs(Connection conn) throws SQLException { - try (Statement stmt = conn.createStatement()) { - DatabaseMetaDataResultSet resultSet = new DatabaseMetaDataResultSet(); - // set up ColumnMetaDataList - List columnMetaDataList = new ArrayList<>(); - // TABLE_CAT - ColumnMetaData col1 = new ColumnMetaData(); - col1.setColIndex(1); - col1.setColName("TABLE_CAT"); - col1.setColType(TSDBConstants.TSDB_DATA_TYPE_NCHAR); - columnMetaDataList.add(col1); - - resultSet.setColumnMetaDataList(columnMetaDataList); + DatabaseMetaDataResultSet resultSet = new DatabaseMetaDataResultSet(); + // set up ColumnMetaDataList + List columnMetaDataList = new ArrayList<>(); + columnMetaDataList.add(buildTableCatalogMeta(1)); // 1. TABLE_CAT + resultSet.setColumnMetaDataList(columnMetaDataList); + try (Statement stmt = conn.createStatement()) { List rowDataList = new ArrayList<>(); ResultSet rs = stmt.executeQuery("show databases"); while (rs.next()) { TSDBResultSetRowData rowData = new TSDBResultSetRowData(1); - rowData.setString(0, rs.getString("name")); + rowData.setStringValue(1, rs.getString("name")); rowDataList.add(rowData); } resultSet.setRowDataList(rowDataList); - return resultSet; } + return resultSet; } protected ResultSet getPrimaryKeys(String catalog, String schema, String table, Connection conn) throws SQLException { - try (Statement stmt = conn.createStatement()) { - if (catalog == null || catalog.isEmpty()) - return null; + if (catalog == null || catalog.isEmpty()) + return null; + if (!isAvailableCatalog(conn, catalog)) + return new EmptyResultSet(); - ResultSet databases = stmt.executeQuery("show databases"); - String dbname = null; - while (databases.next()) { - dbname = databases.getString("name"); - if (dbname.equalsIgnoreCase(catalog)) - break; - } - databases.close(); - if (dbname == null) - return null; - - stmt.execute("use " + dbname); - DatabaseMetaDataResultSet resultSet = new DatabaseMetaDataResultSet(); + DatabaseMetaDataResultSet resultSet = new DatabaseMetaDataResultSet(); + try (Statement stmt = conn.createStatement()) { // set up ColumnMetaDataList - List columnMetaDataList = new ArrayList<>(); - // TABLE_CAT - ColumnMetaData col1 = new ColumnMetaData(); - col1.setColIndex(0); - col1.setColName("TABLE_CAT"); - col1.setColType(TSDBConstants.TSDB_DATA_TYPE_NCHAR); - columnMetaDataList.add(col1); - // TABLE_SCHEM - ColumnMetaData col2 = new ColumnMetaData(); - col2.setColIndex(1); - col2.setColName("TABLE_SCHEM"); - col2.setColType(TSDBConstants.TSDB_DATA_TYPE_NCHAR); - columnMetaDataList.add(col2); - // TABLE_NAME - ColumnMetaData col3 = new ColumnMetaData(); - col3.setColIndex(2); - col3.setColName("TABLE_NAME"); - col3.setColType(TSDBConstants.TSDB_DATA_TYPE_NCHAR); - columnMetaDataList.add(col3); - // COLUMN_NAME - ColumnMetaData col4 = new ColumnMetaData(); - col4.setColIndex(3); - col4.setColName("COLUMN_NAME"); - col4.setColType(TSDBConstants.TSDB_DATA_TYPE_NCHAR); - columnMetaDataList.add(col4); - // KEY_SEQ - ColumnMetaData col5 = new ColumnMetaData(); - col5.setColIndex(4); - col5.setColName("KEY_SEQ"); - col5.setColType(TSDBConstants.TSDB_DATA_TYPE_INT); - columnMetaDataList.add(col5); - // PK_NAME - ColumnMetaData col6 = new ColumnMetaData(); - col6.setColIndex(5); - col6.setColName("PK_NAME"); - col6.setColType(TSDBConstants.TSDB_DATA_TYPE_NCHAR); - columnMetaDataList.add(col6); - resultSet.setColumnMetaDataList(columnMetaDataList); - + resultSet.setColumnMetaDataList(buildGetPrimaryKeysMetadataList()); // set rowData List rowDataList = new ArrayList<>(); - ResultSet rs = stmt.executeQuery("describe " + dbname + "." + table); + ResultSet rs = stmt.executeQuery("describe " + catalog + "." + table); rs.next(); TSDBResultSetRowData rowData = new TSDBResultSetRowData(6); - rowData.setString(0, null); - rowData.setString(1, null); - rowData.setString(2, table); - String pkName = rs.getString(1); - rowData.setString(3, pkName); - rowData.setInt(4, 1); - rowData.setString(5, pkName); + rowData.setStringValue(1, catalog); + rowData.setStringValue(2, null); + rowData.setStringValue(3, table); + String primaryKey = rs.getString("Field"); + rowData.setStringValue(4, primaryKey); + rowData.setShortValue(5, (short) 1); + rowData.setStringValue(6, primaryKey); rowDataList.add(rowData); resultSet.setRowDataList(rowDataList); - return resultSet; } + return resultSet; } - protected ResultSet getSuperTables(String catalog, String schemaPattern, String tableNamePattern, Connection conn) throws SQLException { - try (Statement stmt = conn.createStatement()) { - if (catalog == null || catalog.isEmpty()) - return null; + private List buildGetPrimaryKeysMetadataList() { + List columnMetaDataList = new ArrayList<>(); + columnMetaDataList.add(buildTableCatalogMeta(1)); // 1. TABLE_CAT + columnMetaDataList.add(buildTableSchemaMeta(2)); // 2. TABLE_SCHEM + columnMetaDataList.add(buildTableNameMeta(3)); // 3. TABLE_NAME + columnMetaDataList.add(buildColumnNameMeta(4)); // 4. COLUMN_NAME + columnMetaDataList.add(buildKeySeqMeta(5)); // 5. KEY_SEQ + columnMetaDataList.add(buildPrimaryKeyNameMeta(6)); // 6. PK_NAME + return columnMetaDataList; + } + + private ColumnMetaData buildKeySeqMeta(int colIndex) { + ColumnMetaData col5 = new ColumnMetaData(); + col5.setColIndex(colIndex); + col5.setColName("KEY_SEQ"); + col5.setColType(Types.SMALLINT); + return col5; + } + + private ColumnMetaData buildPrimaryKeyNameMeta(int colIndex) { + ColumnMetaData col6 = new ColumnMetaData(); + col6.setColIndex(colIndex); + col6.setColName("PK_NAME"); + col6.setColType(Types.NCHAR); + return col6; + } + private boolean isAvailableCatalog(Connection connection, String catalog) { + try (Statement stmt = connection.createStatement()) { ResultSet databases = stmt.executeQuery("show databases"); - String dbname = null; while (databases.next()) { - dbname = databases.getString("name"); + String dbname = databases.getString("name"); + this.database = dbname; + this.precision = databases.getString("precision"); if (dbname.equalsIgnoreCase(catalog)) - break; + return true; } databases.close(); - if (dbname == null) - return null; + } catch (SQLException e) { + e.printStackTrace(); + } + return false; + } - stmt.execute("use " + dbname); - DatabaseMetaDataResultSet resultSet = new DatabaseMetaDataResultSet(); - // set up ColumnMetaDataList - List columnMetaDataList = new ArrayList<>(); - // TABLE_CAT - ColumnMetaData col1 = new ColumnMetaData(); - col1.setColIndex(0); - col1.setColName("TABLE_CAT"); - col1.setColType(TSDBConstants.TSDB_DATA_TYPE_NCHAR); - columnMetaDataList.add(col1); - // TABLE_SCHEM - ColumnMetaData col2 = new ColumnMetaData(); - col2.setColIndex(1); - col2.setColName("TABLE_SCHEM"); - col2.setColType(TSDBConstants.TSDB_DATA_TYPE_NCHAR); - columnMetaDataList.add(col2); - // TABLE_NAME - ColumnMetaData col3 = new ColumnMetaData(); - col3.setColIndex(2); - col3.setColName("TABLE_NAME"); - col3.setColType(TSDBConstants.TSDB_DATA_TYPE_NCHAR); - columnMetaDataList.add(col3); - // SUPERTABLE_NAME - ColumnMetaData col4 = new ColumnMetaData(); - col4.setColIndex(3); - col4.setColName("SUPERTABLE_NAME"); - col4.setColType(TSDBConstants.TSDB_DATA_TYPE_NCHAR); - columnMetaDataList.add(col4); - resultSet.setColumnMetaDataList(columnMetaDataList); + protected ResultSet getSuperTables(String catalog, String schemaPattern, String tableNamePattern, Connection conn) throws SQLException { + if (catalog == null || catalog.isEmpty()) + return null; + + if (!isAvailableCatalog(conn, catalog)) { + return new EmptyResultSet(); + } + DatabaseMetaDataResultSet resultSet = new DatabaseMetaDataResultSet(); + try (Statement stmt = conn.createStatement()) { + // set up ColumnMetaDataList + resultSet.setColumnMetaDataList(buildGetSuperTablesColumnMetaDataList()); + // set result set row data + stmt.execute("use " + catalog); ResultSet rs = stmt.executeQuery("show tables like '" + tableNamePattern + "'"); List rowDataList = new ArrayList<>(); while (rs.next()) { TSDBResultSetRowData rowData = new TSDBResultSetRowData(4); - rowData.setString(2, rs.getString(1)); - rowData.setString(3, rs.getString(4)); + rowData.setStringValue(1, catalog); + rowData.setStringValue(2, null); + rowData.setStringValue(3, rs.getString("table_name")); + rowData.setStringValue(4, rs.getString("stable_name")); rowDataList.add(rowData); } resultSet.setRowDataList(rowDataList); - return resultSet; } + return resultSet; + } + + private List buildGetSuperTablesColumnMetaDataList() { + List columnMetaDataList = new ArrayList<>(); + columnMetaDataList.add(buildTableCatalogMeta(1)); // 1. TABLE_CAT + columnMetaDataList.add(buildTableSchemaMeta(2)); // 2. TABLE_SCHEM + columnMetaDataList.add(buildTableNameMeta(3)); // 3. TABLE_NAME + columnMetaDataList.add(buildSuperTableNameMeta(4)); // 4. SUPERTABLE_NAME + return columnMetaDataList; } + + private ColumnMetaData buildSuperTableNameMeta(int colIndex) { + ColumnMetaData col4 = new ColumnMetaData(); + col4.setColIndex(colIndex); + col4.setColName("SUPERTABLE_NAME"); + col4.setColType(Types.NCHAR); + return col4; + } + } \ No newline at end of file diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/AbstractParameterMetaData.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/AbstractParameterMetaData.java index 7df7252ae2010b5aa5e8f74de2cca55844e25b83..cb6c7d40ad1f1e12324043d78cb423fcfd46dca8 100644 --- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/AbstractParameterMetaData.java +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/AbstractParameterMetaData.java @@ -1,5 +1,7 @@ package com.taosdata.jdbc; +import com.sun.org.apache.xpath.internal.operations.Bool; + import java.sql.ParameterMetaData; import java.sql.SQLException; import java.sql.Timestamp; @@ -49,6 +51,22 @@ public abstract class AbstractParameterMetaData extends WrapperImpl implements P if (param < 1 && param >= parameters.length) throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_PARAMETER_INDEX_OUT_RANGE); + if (parameters[param - 1] instanceof Boolean) + return TSDBConstants.BOOLEAN_PRECISION; + if (parameters[param - 1] instanceof Byte) + return TSDBConstants.TINYINT_PRECISION; + if (parameters[param - 1] instanceof Short) + return TSDBConstants.SMALLINT_PRECISION; + if (parameters[param - 1] instanceof Integer) + return TSDBConstants.INT_PRECISION; + if (parameters[param - 1] instanceof Long) + return TSDBConstants.BIGINT_PRECISION; + if (parameters[param - 1] instanceof Timestamp) + return TSDBConstants.TIMESTAMP_MS_PRECISION; + if (parameters[param - 1] instanceof Float) + return TSDBConstants.FLOAT_PRECISION; + if (parameters[param - 1] instanceof Double) + return TSDBConstants.DOUBLE_PRECISION; if (parameters[param - 1] instanceof String) return ((String) parameters[param - 1]).length(); if (parameters[param - 1] instanceof byte[]) @@ -60,6 +78,11 @@ public abstract class AbstractParameterMetaData extends WrapperImpl implements P public int getScale(int param) throws SQLException { if (param < 1 && param >= parameters.length) throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_PARAMETER_INDEX_OUT_RANGE); + + if (parameters[param - 1] instanceof Float) + return TSDBConstants.FLOAT_SCALE; + if (parameters[param - 1] instanceof Double) + return TSDBConstants.DOUBLE_SCALE; return 0; } diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/AbstractResultSet.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/AbstractResultSet.java index f8ea9af4230e9584197f1141dc5a4f7c1621b3ff..e17548055c792e900a1e2fb5b510de8bf65de7a7 100644 --- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/AbstractResultSet.java +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/AbstractResultSet.java @@ -66,10 +66,16 @@ public abstract class AbstractResultSet extends WrapperImpl implements ResultSet public abstract byte[] getBytes(int columnIndex) throws SQLException; @Override - public abstract Date getDate(int columnIndex) throws SQLException; + public Date getDate(int columnIndex) throws SQLException { + Timestamp timestamp = getTimestamp(columnIndex); + return timestamp == null ? null : new Date(timestamp.getTime()); + } @Override - public abstract Time getTime(int columnIndex) throws SQLException; + public Time getTime(int columnIndex) throws SQLException { + Timestamp timestamp = getTimestamp(columnIndex); + return timestamp == null ? null : new Time(timestamp.getTime()); + } @Override public abstract Timestamp getTimestamp(int columnIndex) throws SQLException; diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/DatabaseMetaDataResultSet.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/DatabaseMetaDataResultSet.java index f6a0fcca316cb07d28c71a4e1d51d9405de083ba..cd266529f34c0693a9891af33c12705b90132800 100644 --- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/DatabaseMetaDataResultSet.java +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/DatabaseMetaDataResultSet.java @@ -14,76 +14,42 @@ *****************************************************************************/ package com.taosdata.jdbc; -import java.io.InputStream; -import java.io.Reader; import java.math.BigDecimal; -import java.net.URL; -import java.sql.Date; import java.sql.*; -import java.util.*; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.Iterator; +import java.util.List; /* - * TDengine only supports a subset of the standard SQL, thus this implemetation of the + * TDengine only supports a subset of the standard SQL, thus this implementation of the * standard JDBC API contains more or less some adjustments customized for certain * compatibility needs. */ -public class DatabaseMetaDataResultSet implements ResultSet { +public class DatabaseMetaDataResultSet extends AbstractResultSet { - private List columnMetaDataList; - private List rowDataList; + private List columnMetaDataList = new ArrayList<>(); + private List rowDataList = new ArrayList<>(); private TSDBResultSetRowData rowCursor; // position of cursor, starts from 0 as beforeFirst, increases as next() is called private int cursorRowNumber = 0; - public DatabaseMetaDataResultSet() { - rowDataList = new ArrayList(); - columnMetaDataList = new ArrayList(); - } - - public List getRowDataList() { - return rowDataList; - } - public void setRowDataList(List rowDataList) { this.rowDataList = rowDataList; } - public List getColumnMetaDataList() { - return columnMetaDataList; - } - public void setColumnMetaDataList(List columnMetaDataList) { this.columnMetaDataList = columnMetaDataList; } - public TSDBResultSetRowData getRowCursor() { - return rowCursor; - } - - public void setRowCursor(TSDBResultSetRowData rowCursor) { - this.rowCursor = rowCursor; - } - @Override public boolean next() throws SQLException { -// boolean ret = false; -// if (rowDataList.size() > 0) { -// ret = rowDataList.iterator().hasNext(); -// if (ret) { -// rowCursor = rowDataList.iterator().next(); -// cursorRowNumber++; -// } -// } -// return ret; - - /**** add by zyyang 2020-09-29 ****************/ boolean ret = false; if (!rowDataList.isEmpty() && cursorRowNumber < rowDataList.size()) { rowCursor = rowDataList.get(cursorRowNumber++); ret = true; } - return ret; } @@ -99,189 +65,72 @@ public class DatabaseMetaDataResultSet implements ResultSet { @Override public String getString(int columnIndex) throws SQLException { - columnIndex--; - int colType = columnMetaDataList.get(columnIndex).getColType(); - return rowCursor.getString(columnIndex, colType); + int colType = columnMetaDataList.get(columnIndex - 1).getColType(); + int nativeType = TSDBConstants.jdbcType2TaosType(colType); + return rowCursor.getString(columnIndex, nativeType); } @Override public boolean getBoolean(int columnIndex) throws SQLException { - columnIndex--; - return rowCursor.getBoolean(columnIndex, columnMetaDataList.get(columnIndex).getColType()); + int colType = columnMetaDataList.get(columnIndex - 1).getColType(); + int nativeType = TSDBConstants.jdbcType2TaosType(colType); + return rowCursor.getBoolean(columnIndex, nativeType); } @Override public byte getByte(int columnIndex) throws SQLException { - columnIndex--; - return (byte) rowCursor.getInt(columnIndex, columnMetaDataList.get(columnIndex).getColType()); + int colType = columnMetaDataList.get(columnIndex - 1).getColType(); + int nativeType = TSDBConstants.jdbcType2TaosType(colType); + return (byte) rowCursor.getInt(columnIndex, nativeType); } @Override public short getShort(int columnIndex) throws SQLException { - columnIndex--; - return (short) rowCursor.getInt(columnIndex, columnMetaDataList.get(columnIndex).getColType()); + int colType = columnMetaDataList.get(columnIndex - 1).getColType(); + int nativeType = TSDBConstants.jdbcType2TaosType(colType); + return (short) rowCursor.getInt(columnIndex, nativeType); } @Override public int getInt(int columnIndex) throws SQLException { - columnIndex--; - return rowCursor.getInt(columnIndex, columnMetaDataList.get(columnIndex).getColType()); + int colType = columnMetaDataList.get(columnIndex - 1).getColType(); + int nativeType = TSDBConstants.jdbcType2TaosType(colType); + return rowCursor.getInt(columnIndex, nativeType); } @Override public long getLong(int columnIndex) throws SQLException { - columnIndex--; - return rowCursor.getLong(columnIndex, columnMetaDataList.get(columnIndex).getColType()); + int colType = columnMetaDataList.get(columnIndex - 1).getColType(); + int nativeType = TSDBConstants.jdbcType2TaosType(colType); + return rowCursor.getLong(columnIndex, nativeType); } @Override public float getFloat(int columnIndex) throws SQLException { - columnIndex--; - return rowCursor.getFloat(columnIndex, columnMetaDataList.get(columnIndex).getColType()); + int colType = columnMetaDataList.get(columnIndex - 1).getColType(); + int nativeType = TSDBConstants.jdbcType2TaosType(colType); + return rowCursor.getFloat(columnIndex, nativeType); } @Override public double getDouble(int columnIndex) throws SQLException { - columnIndex--; - return rowCursor.getDouble(columnIndex, columnMetaDataList.get(columnIndex).getColType()); - } - - @Override - public BigDecimal getBigDecimal(int columnIndex, int scale) throws SQLException { - columnIndex--; - return new BigDecimal(rowCursor.getDouble(columnIndex, columnMetaDataList.get(columnIndex).getColType())); + int colType = columnMetaDataList.get(columnIndex - 1).getColType(); + int nativeType = TSDBConstants.jdbcType2TaosType(colType); + return rowCursor.getDouble(columnIndex, nativeType); } @Override public byte[] getBytes(int columnIndex) throws SQLException { - columnIndex--; - return (rowCursor.getString(columnIndex, columnMetaDataList.get(columnIndex).getColType())).getBytes(); - } - - @Override - public Date getDate(int columnIndex) throws SQLException { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD); - } - - @Override - public Time getTime(int columnIndex) throws SQLException { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD); + int colType = columnMetaDataList.get(columnIndex - 1).getColType(); + int nativeType = TSDBConstants.jdbcType2TaosType(colType); + return (rowCursor.getString(columnIndex, nativeType)).getBytes(); } @Override public Timestamp getTimestamp(int columnIndex) throws SQLException { - columnIndex--; - return rowCursor.getTimestamp(columnIndex); - } - - @Override - public InputStream getAsciiStream(int columnIndex) throws SQLException { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD); - } - - @Override - public InputStream getUnicodeStream(int columnIndex) throws SQLException { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD); - } - - @Override - public InputStream getBinaryStream(int columnIndex) throws SQLException { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD); - } - - @Override - public String getString(String columnLabel) throws SQLException { - return getString(findColumn(columnLabel)); - } - - @Override - public boolean getBoolean(String columnLabel) throws SQLException { - return getBoolean(findColumn(columnLabel)); - } - - @Override - public byte getByte(String columnLabel) throws SQLException { - return getByte(findColumn(columnLabel)); - } - - @Override - public short getShort(String columnLabel) throws SQLException { - return getShort(findColumn(columnLabel)); - } - - @Override - public int getInt(String columnLabel) throws SQLException { - return getInt(findColumn(columnLabel)); - } - - @Override - public long getLong(String columnLabel) throws SQLException { - return getLong(findColumn(columnLabel)); - } - - @Override - public float getFloat(String columnLabel) throws SQLException { - return getFloat(findColumn(columnLabel)); - } - - @Override - public double getDouble(String columnLabel) throws SQLException { - return getDouble(findColumn(columnLabel)); - } - - @Override - public BigDecimal getBigDecimal(String columnLabel, int scale) throws SQLException { - return getBigDecimal(findColumn(columnLabel)); - } - - @Override - public byte[] getBytes(String columnLabel) throws SQLException { - return getBytes(findColumn(columnLabel)); - } - - @Override - public Date getDate(String columnLabel) throws SQLException { - return getDate(findColumn(columnLabel)); - } - - @Override - public Time getTime(String columnLabel) throws SQLException { - return getTime(findColumn(columnLabel)); - } - - @Override - public Timestamp getTimestamp(String columnLabel) throws SQLException { - return getTimestamp(findColumn(columnLabel)); - } - - @Override - public InputStream getAsciiStream(String columnLabel) throws SQLException { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD); - } - - @Override - public InputStream getUnicodeStream(String columnLabel) throws SQLException { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD); - } - - @Override - public InputStream getBinaryStream(String columnLabel) throws SQLException { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD); - } - - @Override - public SQLWarning getWarnings() throws SQLException { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD); - } - - @Override - public void clearWarnings() throws SQLException { - - } - - @Override - public String getCursorName() throws SQLException { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD); + int colType = columnMetaDataList.get(columnIndex - 1).getColType(); + int nativeType = TSDBConstants.jdbcType2TaosType(colType); + return rowCursor.getTimestamp(columnIndex,nativeType); } @Override @@ -291,12 +140,7 @@ public class DatabaseMetaDataResultSet implements ResultSet { @Override public Object getObject(int columnIndex) throws SQLException { - return rowCursor.get(columnIndex); - } - - @Override - public Object getObject(String columnLabel) throws SQLException { - return rowCursor.get(findColumn(columnLabel)); + return rowCursor.getObject(columnIndex); } @Override @@ -304,31 +148,19 @@ public class DatabaseMetaDataResultSet implements ResultSet { Iterator colMetaDataIt = this.columnMetaDataList.iterator(); while (colMetaDataIt.hasNext()) { ColumnMetaData colMetaData = colMetaDataIt.next(); - if (colMetaData.getColName() != null && colMetaData.getColName().equalsIgnoreCase(columnLabel)) { - return colMetaData.getColIndex() + 1; + if (colMetaData.getColName() != null && colMetaData.getColName().equals(columnLabel)) { + return colMetaData.getColIndex(); } } throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_INVALID_VARIABLE); } - @Override - public Reader getCharacterStream(int columnIndex) throws SQLException { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD); - } - - @Override - public Reader getCharacterStream(String columnLabel) throws SQLException { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD); - } - @Override public BigDecimal getBigDecimal(int columnIndex) throws SQLException { - return new BigDecimal(rowCursor.getDouble(columnIndex, columnMetaDataList.get(columnIndex).getColType())); - } - - @Override - public BigDecimal getBigDecimal(String columnLabel) throws SQLException { - return getBigDecimal(findColumn(columnLabel)); + int colType = columnMetaDataList.get(columnIndex - 1).getColType(); + int nativeType = TSDBConstants.jdbcType2TaosType(colType); + double value = rowCursor.getDouble(columnIndex, nativeType); + return new BigDecimal(value); } @Override @@ -378,7 +210,6 @@ public class DatabaseMetaDataResultSet implements ResultSet { } else { return 0; } - } @Override @@ -397,680 +228,23 @@ public class DatabaseMetaDataResultSet implements ResultSet { } @Override - public void setFetchDirection(int direction) throws SQLException { - - } - - @Override - public int getFetchDirection() throws SQLException { - return ResultSet.FETCH_FORWARD; - } - - @Override - public void setFetchSize(int rows) throws SQLException { - - } - - @Override - public int getFetchSize() throws SQLException { - return 0; - } - - @Override - public int getType() throws SQLException { - return ResultSet.TYPE_FORWARD_ONLY; - } - - @Override - public int getConcurrency() throws SQLException { - return ResultSet.CONCUR_READ_ONLY; - } - - @Override - public boolean rowUpdated() throws SQLException { - return false; + public Statement getStatement() throws SQLException { + return null; } - @Override - public boolean rowInserted() throws SQLException { - return false; + public Timestamp getTimestamp(int columnIndex, Calendar cal) throws SQLException { + //TODO: calendar is not used + return getTimestamp(columnIndex); } @Override - public boolean rowDeleted() throws SQLException { + public boolean isClosed() throws SQLException { return false; } @Override - public void updateNull(int columnIndex) throws SQLException { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD); - } - - @Override - public void updateBoolean(int columnIndex, boolean x) throws SQLException { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD); - } - - @Override - public void updateByte(int columnIndex, byte x) throws SQLException { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD); - } - - @Override - public void updateShort(int columnIndex, short x) throws SQLException { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD); - } - - @Override - public void updateInt(int columnIndex, int x) throws SQLException { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD); - } - - @Override - public void updateLong(int columnIndex, long x) throws SQLException { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD); - } - - @Override - public void updateFloat(int columnIndex, float x) throws SQLException { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD); - } - - @Override - public void updateDouble(int columnIndex, double x) throws SQLException { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD); - } - - @Override - public void updateBigDecimal(int columnIndex, BigDecimal x) throws SQLException { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD); - } - - @Override - public void updateString(int columnIndex, String x) throws SQLException { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD); - } - - @Override - public void updateBytes(int columnIndex, byte[] x) throws SQLException { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD); - } - - @Override - public void updateDate(int columnIndex, Date x) throws SQLException { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD); - } - - @Override - public void updateTime(int columnIndex, Time x) throws SQLException { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD); - } - - @Override - public void updateTimestamp(int columnIndex, Timestamp x) throws SQLException { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD); - } - - @Override - public void updateAsciiStream(int columnIndex, InputStream x, int length) throws SQLException { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD); - } - - @Override - public void updateBinaryStream(int columnIndex, InputStream x, int length) throws SQLException { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD); - } - - @Override - public void updateCharacterStream(int columnIndex, Reader x, int length) throws SQLException { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD); - } - - @Override - public void updateObject(int columnIndex, Object x, int scaleOrLength) throws SQLException { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD); - } - - @Override - public void updateObject(int columnIndex, Object x) throws SQLException { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD); - } - - @Override - public void updateNull(String columnLabel) throws SQLException { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD); - } - - @Override - public void updateBoolean(String columnLabel, boolean x) throws SQLException { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD); - } - - @Override - public void updateByte(String columnLabel, byte x) throws SQLException { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD); - } - - @Override - public void updateShort(String columnLabel, short x) throws SQLException { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD); - } - - @Override - public void updateInt(String columnLabel, int x) throws SQLException { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD); - } - - @Override - public void updateLong(String columnLabel, long x) throws SQLException { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD); - } - - @Override - public void updateFloat(String columnLabel, float x) throws SQLException { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD); - } - - @Override - public void updateDouble(String columnLabel, double x) throws SQLException { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD); - } - - @Override - public void updateBigDecimal(String columnLabel, BigDecimal x) throws SQLException { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD); - } - - @Override - public void updateString(String columnLabel, String x) throws SQLException { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD); + public String getNString(int columnIndex) throws SQLException { + return getString(columnIndex); } - @Override - public void updateBytes(String columnLabel, byte[] x) throws SQLException { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD); - } - - @Override - public void updateDate(String columnLabel, Date x) throws SQLException { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD); - } - - @Override - public void updateTime(String columnLabel, Time x) throws SQLException { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD); - } - - @Override - public void updateTimestamp(String columnLabel, Timestamp x) throws SQLException { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD); - } - - @Override - public void updateAsciiStream(String columnLabel, InputStream x, int length) throws SQLException { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD); - } - - @Override - public void updateBinaryStream(String columnLabel, InputStream x, int length) throws SQLException { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD); - } - - @Override - public void updateCharacterStream(String columnLabel, Reader reader, int length) throws SQLException { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD); - } - - @Override - public void updateObject(String columnLabel, Object x, int scaleOrLength) throws SQLException { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD); - } - - @Override - public void updateObject(String columnLabel, Object x) throws SQLException { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD); - } - - @Override - public void insertRow() throws SQLException { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD); - } - - @Override - public void updateRow() throws SQLException { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD); - } - - @Override - public void deleteRow() throws SQLException { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD); - } - - @Override - public void refreshRow() throws SQLException { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD); - } - - @Override - public void cancelRowUpdates() throws SQLException { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD); - } - - @Override - public void moveToInsertRow() throws SQLException { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD); - } - - @Override - public void moveToCurrentRow() throws SQLException { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD); - } - - @Override - public Statement getStatement() throws SQLException { - return null; - } - - @Override - public Object getObject(int columnIndex, Map> map) throws SQLException { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD); - } - - @Override - public Ref getRef(int columnIndex) throws SQLException { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD); - } - - @Override - public Blob getBlob(int columnIndex) throws SQLException { - return null; - } - - @Override - public Clob getClob(int columnIndex) throws SQLException { - return null; - } - - @Override - public Array getArray(int columnIndex) throws SQLException { - return null; - } - - @Override - public Object getObject(String columnLabel, Map> map) throws SQLException { - return null; - } - - @Override - public Ref getRef(String columnLabel) throws SQLException { - return null; - } - - @Override - public Blob getBlob(String columnLabel) throws SQLException { - return null; - } - - @Override - public Clob getClob(String columnLabel) throws SQLException { - return null; - } - - @Override - public Array getArray(String columnLabel) throws SQLException { - return null; - } - - @Override - public Date getDate(int columnIndex, Calendar cal) throws SQLException { - return null; - } - - @Override - public Date getDate(String columnLabel, Calendar cal) throws SQLException { - return null; - } - - @Override - public Time getTime(int columnIndex, Calendar cal) throws SQLException { - return null; - } - - @Override - public Time getTime(String columnLabel, Calendar cal) throws SQLException { - return null; - } - - @Override - public Timestamp getTimestamp(int columnIndex, Calendar cal) throws SQLException { - return null; - } - - @Override - public Timestamp getTimestamp(String columnLabel, Calendar cal) throws SQLException { - return null; - } - - @Override - public URL getURL(int columnIndex) throws SQLException { - return null; - } - - @Override - public URL getURL(String columnLabel) throws SQLException { - return null; - } - - @Override - public void updateRef(int columnIndex, Ref x) throws SQLException { - - } - - @Override - public void updateRef(String columnLabel, Ref x) throws SQLException { - - } - - @Override - public void updateBlob(int columnIndex, Blob x) throws SQLException { - - } - - @Override - public void updateBlob(String columnLabel, Blob x) throws SQLException { - - } - - @Override - public void updateClob(int columnIndex, Clob x) throws SQLException { - - } - - @Override - public void updateClob(String columnLabel, Clob x) throws SQLException { - - } - - @Override - public void updateArray(int columnIndex, Array x) throws SQLException { - - } - - @Override - public void updateArray(String columnLabel, Array x) throws SQLException { - - } - - @Override - public RowId getRowId(int columnIndex) throws SQLException { - return null; - } - - @Override - public RowId getRowId(String columnLabel) throws SQLException { - return null; - } - - @Override - public void updateRowId(int columnIndex, RowId x) throws SQLException { - - } - - @Override - public void updateRowId(String columnLabel, RowId x) throws SQLException { - - } - - @Override - public int getHoldability() throws SQLException { - return 0; - } - - @Override - public boolean isClosed() throws SQLException { - return false; - } - - @Override - public void updateNString(int columnIndex, String nString) throws SQLException { - - } - - @Override - public void updateNString(String columnLabel, String nString) throws SQLException { - - } - - @Override - public void updateNClob(int columnIndex, NClob nClob) throws SQLException { - - } - - @Override - public void updateNClob(String columnLabel, NClob nClob) throws SQLException { - - } - - @Override - public NClob getNClob(int columnIndex) throws SQLException { - return null; - } - - @Override - public NClob getNClob(String columnLabel) throws SQLException { - return null; - } - - @Override - public SQLXML getSQLXML(int columnIndex) throws SQLException { - return null; - } - - @Override - public SQLXML getSQLXML(String columnLabel) throws SQLException { - return null; - } - - @Override - public void updateSQLXML(int columnIndex, SQLXML xmlObject) throws SQLException { - - } - - @Override - public void updateSQLXML(String columnLabel, SQLXML xmlObject) throws SQLException { - - } - - @Override - public String getNString(int columnIndex) throws SQLException { - return null; - } - - @Override - public String getNString(String columnLabel) throws SQLException { - return null; - } - - @Override - public Reader getNCharacterStream(int columnIndex) throws SQLException { - return null; - } - - @Override - public Reader getNCharacterStream(String columnLabel) throws SQLException { - return null; - } - - @Override - public void updateNCharacterStream(int columnIndex, Reader x, long length) throws SQLException { - - } - - @Override - public void updateNCharacterStream(String columnLabel, Reader reader, long length) throws SQLException { - - } - - @Override - public void updateAsciiStream(int columnIndex, InputStream x, long length) throws SQLException { - - } - - @Override - public void updateBinaryStream(int columnIndex, InputStream x, long length) throws SQLException { - - } - - @Override - public void updateCharacterStream(int columnIndex, Reader x, long length) throws SQLException { - - } - - @Override - public void updateAsciiStream(String columnLabel, InputStream x, long length) throws SQLException { - - } - - @Override - public void updateBinaryStream(String columnLabel, InputStream x, long length) throws SQLException { - - } - - @Override - public void updateCharacterStream(String columnLabel, Reader reader, long length) throws SQLException { - - } - - @Override - public void updateBlob(int columnIndex, InputStream inputStream, long length) throws SQLException { - - } - - @Override - public void updateBlob(String columnLabel, InputStream inputStream, long length) throws SQLException { - - } - - @Override - public void updateClob(int columnIndex, Reader reader, long length) throws SQLException { - - } - - @Override - public void updateClob(String columnLabel, Reader reader, long length) throws SQLException { - - } - - @Override - public void updateNClob(int columnIndex, Reader reader, long length) throws SQLException { - - } - - @Override - public void updateNClob(String columnLabel, Reader reader, long length) throws SQLException { - - } - - @Override - public void updateNCharacterStream(int columnIndex, Reader x) throws SQLException { - - } - - @Override - public void updateNCharacterStream(String columnLabel, Reader reader) throws SQLException { - - } - - @Override - public void updateAsciiStream(int columnIndex, InputStream x) throws SQLException { - - } - - @Override - public void updateBinaryStream(int columnIndex, InputStream x) throws SQLException { - - } - - @Override - public void updateCharacterStream(int columnIndex, Reader x) throws SQLException { - - } - - @Override - public void updateAsciiStream(String columnLabel, InputStream x) throws SQLException { - - } - - @Override - public void updateBinaryStream(String columnLabel, InputStream x) throws SQLException { - - } - - @Override - public void updateCharacterStream(String columnLabel, Reader reader) throws SQLException { - - } - - @Override - public void updateBlob(int columnIndex, InputStream inputStream) throws SQLException { - - } - - @Override - public void updateBlob(String columnLabel, InputStream inputStream) throws SQLException { - - } - - @Override - public void updateClob(int columnIndex, Reader reader) throws SQLException { - - } - - @Override - public void updateClob(String columnLabel, Reader reader) throws SQLException { - - } - - @Override - public void updateNClob(int columnIndex, Reader reader) throws SQLException { - - } - - @Override - public void updateNClob(String columnLabel, Reader reader) throws SQLException { - - } - - @Override - public T getObject(int columnIndex, Class type) throws SQLException { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD); - } - - @Override - public T getObject(String columnLabel, Class type) throws SQLException { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD); - } - - @Override - public T unwrap(Class iface) throws SQLException { - return null; - } - - @Override - public boolean isWrapperFor(Class iface) throws SQLException { - return false; - } - - private int getTrueColumnIndex(int columnIndex) throws SQLException { - if (columnIndex < 1) { - throw new SQLException("Column Index out of range, " + columnIndex + " < " + 1); - } - - int numOfCols = this.columnMetaDataList.size(); - if (columnIndex > numOfCols) { - throw new SQLException("Column Index out of range, " + columnIndex + " > " + numOfCols); - } - - return columnIndex - 1; - } } diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBConstants.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBConstants.java index f38555ce8a6c7ee946b3bdbda2204c702b49198a..e6406d2c6dc7990ec4f3149bb8c5146202f5d326 100644 --- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBConstants.java +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBConstants.java @@ -41,15 +41,15 @@ public abstract class TSDBConstants { public static final int TSDB_DATA_TYPE_BINARY = 8; public static final int TSDB_DATA_TYPE_TIMESTAMP = 9; public static final int TSDB_DATA_TYPE_NCHAR = 10; - /* - 系统增加新的无符号数据类型,分别是: - unsigned tinyint, 数值范围:0-254, NULL 为255 - unsigned smallint,数值范围: 0-65534, NULL 为65535 - unsigned int,数值范围:0-4294967294,NULL 为4294967295u - unsigned bigint,数值范围:0-18446744073709551614u,NULL 为18446744073709551615u。 - example: - create table tb(ts timestamp, a tinyint unsigned, b smallint unsigned, c int unsigned, d bigint unsigned); - */ + /** + * 系统增加新的无符号数据类型,分别是: + * unsigned tinyint, 数值范围:0-254, NULL 为255 + * unsigned smallint,数值范围: 0-65534, NULL 为65535 + * unsigned int,数值范围:0-4294967294,NULL 为4294967295u + * unsigned bigint,数值范围:0-18446744073709551614u,NULL 为18446744073709551615u。 + * example: + * create table tb(ts timestamp, a tinyint unsigned, b smallint unsigned, c int unsigned, d bigint unsigned); + */ public static final int TSDB_DATA_TYPE_UTINYINT = 11; //unsigned tinyint public static final int TSDB_DATA_TYPE_USMALLINT = 12; //unsigned smallint public static final int TSDB_DATA_TYPE_UINT = 13; //unsigned int @@ -57,6 +57,47 @@ public abstract class TSDBConstants { // nchar column max length public static final int maxFieldSize = 16 * 1024; + // precision for data types + public static final int BOOLEAN_PRECISION = 1; + public static final int TINYINT_PRECISION = 4; + public static final int SMALLINT_PRECISION = 6; + public static final int INT_PRECISION = 11; + public static final int BIGINT_PRECISION = 20; + public static final int FLOAT_PRECISION = 12; + public static final int DOUBLE_PRECISION = 22; + public static final int TIMESTAMP_MS_PRECISION = 23; + public static final int TIMESTAMP_US_PRECISION = 26; + // scale for data types + public static final int FLOAT_SCALE = 31; + public static final int DOUBLE_SCALE = 31; + + public static int typeName2JdbcType(String type) { + switch (type.toUpperCase()) { + case "TIMESTAMP": + return Types.TIMESTAMP; + case "INT": + return Types.INTEGER; + case "BIGINT": + return Types.BIGINT; + case "FLOAT": + return Types.FLOAT; + case "DOUBLE": + return Types.DOUBLE; + case "BINARY": + return Types.BINARY; + case "SMALLINT": + return Types.SMALLINT; + case "TINYINT": + return Types.TINYINT; + case "BOOL": + return Types.BOOLEAN; + case "NCHAR": + return Types.NCHAR; + default: + return Types.NULL; + } + } + public static int taosType2JdbcType(int taosType) throws SQLException { switch (taosType) { case TSDBConstants.TSDB_DATA_TYPE_BOOL: @@ -88,7 +129,7 @@ public abstract class TSDBConstants { } public static String taosType2JdbcTypeName(int taosType) throws SQLException { - switch (taosType){ + switch (taosType) { case TSDBConstants.TSDB_DATA_TYPE_BOOL: return "BOOL"; case TSDBConstants.TSDB_DATA_TYPE_UTINYINT: @@ -119,7 +160,7 @@ public abstract class TSDBConstants { } public static int jdbcType2TaosType(int jdbcType) throws SQLException { - switch (jdbcType){ + switch (jdbcType) { case Types.BOOLEAN: return TSDBConstants.TSDB_DATA_TYPE_BOOL; case Types.TINYINT: @@ -145,7 +186,7 @@ public abstract class TSDBConstants { } public static String jdbcType2TaosTypeName(int jdbcType) throws SQLException { - switch (jdbcType){ + switch (jdbcType) { case Types.BOOLEAN: return "BOOL"; case Types.TINYINT: diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBJNIConnector.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBJNIConnector.java index 256e735285bd493f37c9e369a49b369e9e6b4b38..92792d97517c98f9a5402aaae557d01e09bbca30 100755 --- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBJNIConnector.java +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBJNIConnector.java @@ -16,13 +16,13 @@ */ package com.taosdata.jdbc; +import com.taosdata.jdbc.utils.TaosInfo; + import java.nio.ByteBuffer; import java.sql.SQLException; import java.sql.SQLWarning; import java.util.List; -import com.taosdata.jdbc.utils.TaosInfo; - /** * JNI connector */ @@ -30,10 +30,10 @@ public class TSDBJNIConnector { private static volatile Boolean isInitialized = false; private TaosInfo taosInfo = TaosInfo.getInstance(); - + // Connection pointer used in C private long taos = TSDBConstants.JNI_NULL_POINTER; - + // result set status in current connection private boolean isResultsetClosed; @@ -194,7 +194,9 @@ public class TSDBJNIConnector { * Get schema metadata */ public int getSchemaMetaData(long resultSet, List columnMetaData) { - return this.getSchemaMetaDataImp(this.taos, resultSet, columnMetaData); + int ret = this.getSchemaMetaDataImp(this.taos, resultSet, columnMetaData); + columnMetaData.stream().forEach(column -> column.setColIndex(column.getColIndex() + 1)); + return ret; } private native int getSchemaMetaDataImp(long connection, long resultSet, List columnMetaData); @@ -221,7 +223,7 @@ public class TSDBJNIConnector { */ public void closeConnection() throws SQLException { int code = this.closeConnectionImp(this.taos); - + if (code < 0) { throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_JNI_CONNECTION_NULL); } else if (code == 0) { @@ -229,7 +231,7 @@ public class TSDBJNIConnector { } else { throw new SQLException("Undefined error code returned by TDengine when closing a connection"); } - + // invoke closeConnectionImpl only here taosInfo.connect_close_increment(); } @@ -274,67 +276,76 @@ public class TSDBJNIConnector { } private native int validateCreateTableSqlImp(long connection, byte[] sqlBytes); - - public long prepareStmt(String sql) throws SQLException { - Long stmt = prepareStmtImp(sql.getBytes(), this.taos); - if (stmt == TSDBConstants.JNI_TDENGINE_ERROR) { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_INVALID_SQL); - } else if (stmt == TSDBConstants.JNI_CONNECTION_NULL) { + + public long prepareStmt(String sql) throws SQLException { + Long stmt; + try { + stmt = prepareStmtImp(sql.getBytes(), this.taos); + } catch (Exception e) { + e.printStackTrace(); + throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_ENCODING); + } + + if (stmt == TSDBConstants.JNI_CONNECTION_NULL) { throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_JNI_CONNECTION_NULL); - } else if (stmt == TSDBConstants.JNI_SQL_NULL) { + } + + if (stmt == TSDBConstants.JNI_SQL_NULL) { throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_JNI_SQL_NULL); - } else if (stmt == TSDBConstants.JNI_OUT_OF_MEMORY) { + } + + if (stmt == TSDBConstants.JNI_OUT_OF_MEMORY) { throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_JNI_OUT_OF_MEMORY); } - - return stmt; + + return stmt; } - + private native long prepareStmtImp(byte[] sql, long con); - + public void setBindTableName(long stmt, String tableName) throws SQLException { - int code = setBindTableNameImp(stmt, tableName, this.taos); - if (code != TSDBConstants.JNI_SUCCESS) { + int code = setBindTableNameImp(stmt, tableName, this.taos); + if (code != TSDBConstants.JNI_SUCCESS) { throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNKNOWN, "failed to set table name"); - } - } - + } + } + private native int setBindTableNameImp(long stmt, String name, long conn); - + public void setBindTableNameAndTags(long stmt, String tableName, int numOfTags, ByteBuffer tags, ByteBuffer typeList, ByteBuffer lengthList, ByteBuffer nullList) throws SQLException { - int code = setTableNameTagsImp(stmt, tableName, numOfTags, tags.array(), typeList.array(), lengthList.array(), - nullList.array(), this.taos); - if (code != TSDBConstants.JNI_SUCCESS) { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNKNOWN, "failed to bind table name and corresponding tags"); - } + int code = setTableNameTagsImp(stmt, tableName, numOfTags, tags.array(), typeList.array(), lengthList.array(), + nullList.array(), this.taos); + if (code != TSDBConstants.JNI_SUCCESS) { + throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNKNOWN, "failed to bind table name and corresponding tags"); + } } - + private native int setTableNameTagsImp(long stmt, String name, int numOfTags, byte[] tags, byte[] typeList, byte[] lengthList, byte[] nullList, long conn); - - public void bindColumnDataArray(long stmt, ByteBuffer colDataList, ByteBuffer lengthList, ByteBuffer isNullList, int type, int bytes, int numOfRows,int columnIndex) throws SQLException { - int code = bindColDataImp(stmt, colDataList.array(), lengthList.array(), isNullList.array(), type, bytes, numOfRows, columnIndex, this.taos); - if (code != TSDBConstants.JNI_SUCCESS) { + + public void bindColumnDataArray(long stmt, ByteBuffer colDataList, ByteBuffer lengthList, ByteBuffer isNullList, int type, int bytes, int numOfRows, int columnIndex) throws SQLException { + int code = bindColDataImp(stmt, colDataList.array(), lengthList.array(), isNullList.array(), type, bytes, numOfRows, columnIndex, this.taos); + if (code != TSDBConstants.JNI_SUCCESS) { throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNKNOWN, "failed to bind column data"); - } - } - + } + } + private native int bindColDataImp(long stmt, byte[] colDataList, byte[] lengthList, byte[] isNullList, int type, int bytes, int numOfRows, int columnIndex, long conn); - + public void executeBatch(long stmt) throws SQLException { - int code = executeBatchImp(stmt, this.taos); - if (code != TSDBConstants.JNI_SUCCESS) { + int code = executeBatchImp(stmt, this.taos); + if (code != TSDBConstants.JNI_SUCCESS) { throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNKNOWN, "failed to execute batch bind"); - } + } } - + private native int executeBatchImp(long stmt, long con); - + public void closeBatch(long stmt) throws SQLException { - int code = closeStmt(stmt, this.taos); - if (code != TSDBConstants.JNI_SUCCESS) { + int code = closeStmt(stmt, this.taos); + if (code != TSDBConstants.JNI_SUCCESS) { throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNKNOWN, "failed to close batch bind"); - } + } } - + private native int closeStmt(long stmt, long con); } diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBPreparedStatement.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBPreparedStatement.java index f6810237c097a62a4c8f0f63d6e435bfb0354125..c3d5abf35c7304f86f9cc4dc4449d8c88d144e3d 100644 --- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBPreparedStatement.java +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBPreparedStatement.java @@ -39,18 +39,18 @@ public class TSDBPreparedStatement extends TSDBStatement implements PreparedStat private String rawSql; private Object[] parameters; private boolean isPrepared; - + private ArrayList colData; private ArrayList tableTags; private int tagValueLength; - + private String tableName; private long nativeStmtHandle = 0; - + private volatile TSDBParameterMetaData parameterMetaData; TSDBPreparedStatement(TSDBConnection connection, String sql) { - super(connection); + super(connection); init(sql); int parameterCnt = 0; @@ -64,11 +64,11 @@ public class TSDBPreparedStatement extends TSDBStatement implements PreparedStat this.isPrepared = true; } - if (parameterCnt > 1) { - // the table name is also a parameter, so ignore it. - this.colData = new ArrayList(); - this.tableTags = new ArrayList(); - } + if (parameterCnt > 1) { + // the table name is also a parameter, so ignore it. + this.colData = new ArrayList(); + this.tableTags = new ArrayList(); + } } private void init(String sql) { @@ -205,9 +205,7 @@ public class TSDBPreparedStatement extends TSDBStatement implements PreparedStat @Override public void setBigDecimal(int parameterIndex, BigDecimal x) throws SQLException { - if (isClosed()) - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED); - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD); + setObject(parameterIndex, x.doubleValue()); } @Override @@ -222,16 +220,12 @@ public class TSDBPreparedStatement extends TSDBStatement implements PreparedStat @Override public void setDate(int parameterIndex, Date x) throws SQLException { - if (isClosed()) - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED); - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD); + setObject(parameterIndex, new Timestamp(x.getTime())); } @Override public void setTime(int parameterIndex, Time x) throws SQLException { - if (isClosed()) - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED); - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD); + setObject(parameterIndex, new Timestamp(x.getTime())); } @Override @@ -279,11 +273,10 @@ public class TSDBPreparedStatement extends TSDBStatement implements PreparedStat if (isClosed()) { throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED); } - + if (parameterIndex < 1 && parameterIndex >= parameters.length) { throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_PARAMETER_INDEX_OUT_RANGE); } - parameters[parameterIndex - 1] = x; } @@ -323,7 +316,7 @@ public class TSDBPreparedStatement extends TSDBStatement implements PreparedStat if (isClosed()) { throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED); } - + throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD); } @@ -350,9 +343,9 @@ public class TSDBPreparedStatement extends TSDBStatement implements PreparedStat @Override public ResultSetMetaData getMetaData() throws SQLException { - if (isClosed()) - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED); - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD); + if (this.getResultSet() == null) + return null; + return getResultSet().getMetaData(); } @Override @@ -396,10 +389,7 @@ public class TSDBPreparedStatement extends TSDBStatement implements PreparedStat if (isClosed()) throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED); - if (parameterMetaData == null) { - this.parameterMetaData = new TSDBParameterMetaData(parameters); - } - return this.parameterMetaData; + return new TSDBParameterMetaData(parameters); } @Override @@ -411,9 +401,7 @@ public class TSDBPreparedStatement extends TSDBStatement implements PreparedStat @Override public void setNString(int parameterIndex, String value) throws SQLException { - if (isClosed()) - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED); - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD); + setString(parameterIndex, value); } @Override @@ -536,489 +524,495 @@ public class TSDBPreparedStatement extends TSDBStatement implements PreparedStat throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED); throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD); } - + /////////////////////////////////////////////////////////////////////// // NOTE: the following APIs are not JDBC compatible // set the bind table name private static class ColumnInfo { - @SuppressWarnings("rawtypes") - private ArrayList data; - private int type; - private int bytes; - private boolean typeIsSet; - - public ColumnInfo() { - this.typeIsSet = false; - } - - public void setType(int type) throws SQLException { - if (this.isTypeSet()) { + @SuppressWarnings("rawtypes") + private ArrayList data; + private int type; + private int bytes; + private boolean typeIsSet; + + public ColumnInfo() { + this.typeIsSet = false; + } + + public void setType(int type) throws SQLException { + if (this.isTypeSet()) { throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNKNOWN, "column data type has been set"); - } - - this.typeIsSet = true; - this.type = type; - } - - public boolean isTypeSet() { - return this.typeIsSet; - } - }; - + } + + this.typeIsSet = true; + this.type = type; + } + + public boolean isTypeSet() { + return this.typeIsSet; + } + } + + ; + private static class TableTagInfo { - private boolean isNull; - private Object value; - private int type; - public TableTagInfo(Object value, int type) { - this.value = value; - this.type = type; - } - - public static TableTagInfo createNullTag(int type) { - TableTagInfo info = new TableTagInfo(null, type); - info.isNull = true; - return info; - } - }; - + private boolean isNull; + private Object value; + private int type; + + public TableTagInfo(Object value, int type) { + this.value = value; + this.type = type; + } + + public static TableTagInfo createNullTag(int type) { + TableTagInfo info = new TableTagInfo(null, type); + info.isNull = true; + return info; + } + } + + ; + public void setTableName(String name) { - this.tableName = name; + this.tableName = name; } - + private void ensureTagCapacity(int index) { - if (this.tableTags.size() < index + 1) { - int delta = index + 1 - this.tableTags.size(); - this.tableTags.addAll(Collections.nCopies(delta, null)); - } + if (this.tableTags.size() < index + 1) { + int delta = index + 1 - this.tableTags.size(); + this.tableTags.addAll(Collections.nCopies(delta, null)); + } } - + public void setTagNull(int index, int type) { - ensureTagCapacity(index); - this.tableTags.set(index, TableTagInfo.createNullTag(type)); + ensureTagCapacity(index); + this.tableTags.set(index, TableTagInfo.createNullTag(type)); } - + public void setTagBoolean(int index, boolean value) { - ensureTagCapacity(index); - this.tableTags.set(index, new TableTagInfo(value, TSDBConstants.TSDB_DATA_TYPE_BOOL)); - this.tagValueLength += Byte.BYTES; + ensureTagCapacity(index); + this.tableTags.set(index, new TableTagInfo(value, TSDBConstants.TSDB_DATA_TYPE_BOOL)); + this.tagValueLength += Byte.BYTES; } - + public void setTagInt(int index, int value) { - ensureTagCapacity(index); - this.tableTags.set(index, new TableTagInfo(value, TSDBConstants.TSDB_DATA_TYPE_INT)); - this.tagValueLength += Integer.BYTES; + ensureTagCapacity(index); + this.tableTags.set(index, new TableTagInfo(value, TSDBConstants.TSDB_DATA_TYPE_INT)); + this.tagValueLength += Integer.BYTES; } - + public void setTagByte(int index, byte value) { - ensureTagCapacity(index); - this.tableTags.set(index, new TableTagInfo(value, TSDBConstants.TSDB_DATA_TYPE_TINYINT)); - this.tagValueLength += Byte.BYTES; + ensureTagCapacity(index); + this.tableTags.set(index, new TableTagInfo(value, TSDBConstants.TSDB_DATA_TYPE_TINYINT)); + this.tagValueLength += Byte.BYTES; } - + public void setTagShort(int index, short value) { - ensureTagCapacity(index); - this.tableTags.set(index, new TableTagInfo(value, TSDBConstants.TSDB_DATA_TYPE_SMALLINT)); - this.tagValueLength += Short.BYTES; + ensureTagCapacity(index); + this.tableTags.set(index, new TableTagInfo(value, TSDBConstants.TSDB_DATA_TYPE_SMALLINT)); + this.tagValueLength += Short.BYTES; } - + public void setTagLong(int index, long value) { - ensureTagCapacity(index); - this.tableTags.set(index, new TableTagInfo(value, TSDBConstants.TSDB_DATA_TYPE_BIGINT)); - this.tagValueLength += Long.BYTES; + ensureTagCapacity(index); + this.tableTags.set(index, new TableTagInfo(value, TSDBConstants.TSDB_DATA_TYPE_BIGINT)); + this.tagValueLength += Long.BYTES; } - + public void setTagTimestamp(int index, long value) { - ensureTagCapacity(index); - this.tableTags.set(index, new TableTagInfo(value, TSDBConstants.TSDB_DATA_TYPE_TIMESTAMP)); - this.tagValueLength += Long.BYTES; + ensureTagCapacity(index); + this.tableTags.set(index, new TableTagInfo(value, TSDBConstants.TSDB_DATA_TYPE_TIMESTAMP)); + this.tagValueLength += Long.BYTES; } - + public void setTagFloat(int index, float value) { - ensureTagCapacity(index); - this.tableTags.set(index, new TableTagInfo(value, TSDBConstants.TSDB_DATA_TYPE_FLOAT)); - this.tagValueLength += Float.BYTES; + ensureTagCapacity(index); + this.tableTags.set(index, new TableTagInfo(value, TSDBConstants.TSDB_DATA_TYPE_FLOAT)); + this.tagValueLength += Float.BYTES; } - + public void setTagDouble(int index, double value) { - ensureTagCapacity(index); - this.tableTags.set(index, new TableTagInfo(value, TSDBConstants.TSDB_DATA_TYPE_DOUBLE)); - this.tagValueLength += Double.BYTES; + ensureTagCapacity(index); + this.tableTags.set(index, new TableTagInfo(value, TSDBConstants.TSDB_DATA_TYPE_DOUBLE)); + this.tagValueLength += Double.BYTES; } - + public void setTagString(int index, String value) { - ensureTagCapacity(index); - this.tableTags.set(index, new TableTagInfo(value, TSDBConstants.TSDB_DATA_TYPE_BINARY)); - this.tagValueLength += value.getBytes().length; + ensureTagCapacity(index); + this.tableTags.set(index, new TableTagInfo(value, TSDBConstants.TSDB_DATA_TYPE_BINARY)); + this.tagValueLength += value.getBytes().length; } - + public void setTagNString(int index, String value) { - ensureTagCapacity(index); - this.tableTags.set(index, new TableTagInfo(value, TSDBConstants.TSDB_DATA_TYPE_NCHAR)); - - String charset = TaosGlobalConfig.getCharset(); - try { - this.tagValueLength += value.getBytes(charset).length; - } catch (UnsupportedEncodingException e) { - e.printStackTrace(); - } - } - + ensureTagCapacity(index); + this.tableTags.set(index, new TableTagInfo(value, TSDBConstants.TSDB_DATA_TYPE_NCHAR)); + + String charset = TaosGlobalConfig.getCharset(); + try { + this.tagValueLength += value.getBytes(charset).length; + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } + } + public void setValueImpl(int columnIndex, ArrayList list, int type, int bytes) throws SQLException { - if (this.colData.size() == 0) { - this.colData.addAll(Collections.nCopies(this.parameters.length - 1 - this.tableTags.size(), null)); - - } - ColumnInfo col = (ColumnInfo) this.colData.get(columnIndex); - if (col == null) { - ColumnInfo p = new ColumnInfo(); - p.setType(type); - p.bytes = bytes; - p.data = (ArrayList) list.clone(); - this.colData.set(columnIndex, p); - } else { - if (col.type != type) { + if (this.colData.size() == 0) { + this.colData.addAll(Collections.nCopies(this.parameters.length - 1 - this.tableTags.size(), null)); + } + + ColumnInfo col = (ColumnInfo) this.colData.get(columnIndex); + if (col == null) { + ColumnInfo p = new ColumnInfo(); + p.setType(type); + p.bytes = bytes; + p.data = (ArrayList) list.clone(); + this.colData.set(columnIndex, p); + } else { + if (col.type != type) { throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNKNOWN, "column data type mismatch"); - } - col.data.addAll(list); - } + } + col.data.addAll(list); + } } - + public void setInt(int columnIndex, ArrayList list) throws SQLException { - setValueImpl(columnIndex, list, TSDBConstants.TSDB_DATA_TYPE_INT, Integer.BYTES); + setValueImpl(columnIndex, list, TSDBConstants.TSDB_DATA_TYPE_INT, Integer.BYTES); } - + public void setFloat(int columnIndex, ArrayList list) throws SQLException { - setValueImpl(columnIndex, list, TSDBConstants.TSDB_DATA_TYPE_FLOAT, Float.BYTES); + setValueImpl(columnIndex, list, TSDBConstants.TSDB_DATA_TYPE_FLOAT, Float.BYTES); } - + public void setTimestamp(int columnIndex, ArrayList list) throws SQLException { - setValueImpl(columnIndex, list, TSDBConstants.TSDB_DATA_TYPE_TIMESTAMP, Long.BYTES); + setValueImpl(columnIndex, list, TSDBConstants.TSDB_DATA_TYPE_TIMESTAMP, Long.BYTES); } - + public void setLong(int columnIndex, ArrayList list) throws SQLException { - setValueImpl(columnIndex, list, TSDBConstants.TSDB_DATA_TYPE_BIGINT, Long.BYTES); + setValueImpl(columnIndex, list, TSDBConstants.TSDB_DATA_TYPE_BIGINT, Long.BYTES); } - + public void setDouble(int columnIndex, ArrayList list) throws SQLException { - setValueImpl(columnIndex, list, TSDBConstants.TSDB_DATA_TYPE_DOUBLE, Double.BYTES); + setValueImpl(columnIndex, list, TSDBConstants.TSDB_DATA_TYPE_DOUBLE, Double.BYTES); } - + public void setBoolean(int columnIndex, ArrayList list) throws SQLException { - setValueImpl(columnIndex, list, TSDBConstants.TSDB_DATA_TYPE_BOOL, Byte.BYTES); + setValueImpl(columnIndex, list, TSDBConstants.TSDB_DATA_TYPE_BOOL, Byte.BYTES); } - + public void setByte(int columnIndex, ArrayList list) throws SQLException { - setValueImpl(columnIndex, list, TSDBConstants.TSDB_DATA_TYPE_TINYINT, Byte.BYTES); + setValueImpl(columnIndex, list, TSDBConstants.TSDB_DATA_TYPE_TINYINT, Byte.BYTES); } - + public void setShort(int columnIndex, ArrayList list) throws SQLException { - setValueImpl(columnIndex, list, TSDBConstants.TSDB_DATA_TYPE_SMALLINT, Short.BYTES); + setValueImpl(columnIndex, list, TSDBConstants.TSDB_DATA_TYPE_SMALLINT, Short.BYTES); } - + public void setString(int columnIndex, ArrayList list, int size) throws SQLException { - setValueImpl(columnIndex, list, TSDBConstants.TSDB_DATA_TYPE_BINARY, size); + setValueImpl(columnIndex, list, TSDBConstants.TSDB_DATA_TYPE_BINARY, size); } - + // note: expand the required space for each NChar character public void setNString(int columnIndex, ArrayList list, int size) throws SQLException { - setValueImpl(columnIndex, list, TSDBConstants.TSDB_DATA_TYPE_NCHAR, size * Integer.BYTES); + setValueImpl(columnIndex, list, TSDBConstants.TSDB_DATA_TYPE_NCHAR, size * Integer.BYTES); } - + public void columnDataAddBatch() throws SQLException { - // pass the data block to native code - if (rawSql == null) { + // pass the data block to native code + if (rawSql == null) { throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNKNOWN, "sql statement not set yet"); - } - - // table name is not set yet, abort - if (this.tableName == null) { + } + + // table name is not set yet, abort + if (this.tableName == null) { throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNKNOWN, "table name not set yet"); - } - - int numOfCols = this.colData.size(); - if (numOfCols == 0) { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNKNOWN, "column data not bind"); - } - - TSDBJNIConnector connector = ((TSDBConnection) this.getConnection()).getConnector(); - this.nativeStmtHandle = connector.prepareStmt(rawSql); - - if (this.tableTags == null) { - connector.setBindTableName(this.nativeStmtHandle, this.tableName); - } else { - int num = this.tableTags.size(); - ByteBuffer tagDataList = ByteBuffer.allocate(this.tagValueLength); - tagDataList.order(ByteOrder.LITTLE_ENDIAN); - - ByteBuffer typeList = ByteBuffer.allocate(num); - typeList.order(ByteOrder.LITTLE_ENDIAN); - - ByteBuffer lengthList = ByteBuffer.allocate(num * Long.BYTES); - lengthList.order(ByteOrder.LITTLE_ENDIAN); - - ByteBuffer isNullList = ByteBuffer.allocate(num * Integer.BYTES); - isNullList.order(ByteOrder.LITTLE_ENDIAN); - - for (int i = 0; i < num; ++i) { - TableTagInfo tag = this.tableTags.get(i); - if (tag.isNull) { - typeList.put((byte) tag.type); - isNullList.putInt(1); - lengthList.putLong(0); - continue; - } - - switch (tag.type) { - case TSDBConstants.TSDB_DATA_TYPE_INT: { - Integer val = (Integer) tag.value; - tagDataList.putInt(val); - lengthList.putLong(Integer.BYTES); - break; - } - case TSDBConstants.TSDB_DATA_TYPE_TINYINT: { - Byte val = (Byte) tag.value; - tagDataList.put(val); - lengthList.putLong(Byte.BYTES); - break; - } - - case TSDBConstants.TSDB_DATA_TYPE_BOOL: { - Boolean val = (Boolean) tag.value; - tagDataList.put((byte) (val ? 1 : 0)); - lengthList.putLong(Byte.BYTES); - break; - } - - case TSDBConstants.TSDB_DATA_TYPE_SMALLINT: { - Short val = (Short) tag.value; - tagDataList.putShort(val); - lengthList.putLong(Short.BYTES); - - break; - } - - case TSDBConstants.TSDB_DATA_TYPE_TIMESTAMP: - case TSDBConstants.TSDB_DATA_TYPE_BIGINT: { - Long val = (Long) tag.value; - tagDataList.putLong(val == null ? 0 : val); - lengthList.putLong(Long.BYTES); - - break; - } - - case TSDBConstants.TSDB_DATA_TYPE_FLOAT: { - Float val = (Float) tag.value; - tagDataList.putFloat(val == null ? 0 : val); - lengthList.putLong(Float.BYTES); - - break; - } - - case TSDBConstants.TSDB_DATA_TYPE_DOUBLE: { - Double val = (Double) tag.value; - tagDataList.putDouble(val == null ? 0 : val); - lengthList.putLong(Double.BYTES); - - break; - } - - case TSDBConstants.TSDB_DATA_TYPE_NCHAR: - case TSDBConstants.TSDB_DATA_TYPE_BINARY: { - String charset = TaosGlobalConfig.getCharset(); - String val = (String) tag.value; - - byte[] b = null; - try { - if (tag.type == TSDBConstants.TSDB_DATA_TYPE_BINARY) { - b = val.getBytes(); - } else { - b = val.getBytes(charset); - } - } catch (UnsupportedEncodingException e) { - e.printStackTrace(); - } - - tagDataList.put(b); - lengthList.putLong(b.length); - break; - } - - case TSDBConstants.TSDB_DATA_TYPE_UTINYINT: - case TSDBConstants.TSDB_DATA_TYPE_USMALLINT: - case TSDBConstants.TSDB_DATA_TYPE_UINT: - case TSDBConstants.TSDB_DATA_TYPE_UBIGINT: { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNKNOWN, "not support data types"); - } - } - - typeList.put((byte) tag.type); - isNullList.putInt(tag.isNull? 1 : 0); - } - - connector.setBindTableNameAndTags(this.nativeStmtHandle, this.tableName, this.tableTags.size(), tagDataList, - typeList, lengthList, isNullList); - } - - ColumnInfo colInfo = (ColumnInfo) this.colData.get(0); - if (colInfo == null) { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNKNOWN, "column data not bind"); - } - - int rows = colInfo.data.size(); - for (int i = 0; i < numOfCols; ++i) { - ColumnInfo col1 = this.colData.get(i); - if (col1 == null || !col1.isTypeSet()) { + } + + int numOfCols = this.colData.size(); + if (numOfCols == 0) { + throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNKNOWN, "column data not bind"); + } + + TSDBJNIConnector connector = ((TSDBConnection) this.getConnection()).getConnector(); + this.nativeStmtHandle = connector.prepareStmt(rawSql); + + if (this.tableTags == null) { + connector.setBindTableName(this.nativeStmtHandle, this.tableName); + } else { + int num = this.tableTags.size(); + ByteBuffer tagDataList = ByteBuffer.allocate(this.tagValueLength); + tagDataList.order(ByteOrder.LITTLE_ENDIAN); + + ByteBuffer typeList = ByteBuffer.allocate(num); + typeList.order(ByteOrder.LITTLE_ENDIAN); + + ByteBuffer lengthList = ByteBuffer.allocate(num * Long.BYTES); + lengthList.order(ByteOrder.LITTLE_ENDIAN); + + ByteBuffer isNullList = ByteBuffer.allocate(num * Integer.BYTES); + isNullList.order(ByteOrder.LITTLE_ENDIAN); + + for (int i = 0; i < num; ++i) { + TableTagInfo tag = this.tableTags.get(i); + if (tag.isNull) { + typeList.put((byte) tag.type); + isNullList.putInt(1); + lengthList.putLong(0); + continue; + } + + switch (tag.type) { + case TSDBConstants.TSDB_DATA_TYPE_INT: { + Integer val = (Integer) tag.value; + tagDataList.putInt(val); + lengthList.putLong(Integer.BYTES); + break; + } + case TSDBConstants.TSDB_DATA_TYPE_TINYINT: { + Byte val = (Byte) tag.value; + tagDataList.put(val); + lengthList.putLong(Byte.BYTES); + break; + } + + case TSDBConstants.TSDB_DATA_TYPE_BOOL: { + Boolean val = (Boolean) tag.value; + tagDataList.put((byte) (val ? 1 : 0)); + lengthList.putLong(Byte.BYTES); + break; + } + + case TSDBConstants.TSDB_DATA_TYPE_SMALLINT: { + Short val = (Short) tag.value; + tagDataList.putShort(val); + lengthList.putLong(Short.BYTES); + + break; + } + + case TSDBConstants.TSDB_DATA_TYPE_TIMESTAMP: + case TSDBConstants.TSDB_DATA_TYPE_BIGINT: { + Long val = (Long) tag.value; + tagDataList.putLong(val == null ? 0 : val); + lengthList.putLong(Long.BYTES); + + break; + } + + case TSDBConstants.TSDB_DATA_TYPE_FLOAT: { + Float val = (Float) tag.value; + tagDataList.putFloat(val == null ? 0 : val); + lengthList.putLong(Float.BYTES); + + break; + } + + case TSDBConstants.TSDB_DATA_TYPE_DOUBLE: { + Double val = (Double) tag.value; + tagDataList.putDouble(val == null ? 0 : val); + lengthList.putLong(Double.BYTES); + + break; + } + + case TSDBConstants.TSDB_DATA_TYPE_NCHAR: + case TSDBConstants.TSDB_DATA_TYPE_BINARY: { + String charset = TaosGlobalConfig.getCharset(); + String val = (String) tag.value; + + byte[] b = null; + try { + if (tag.type == TSDBConstants.TSDB_DATA_TYPE_BINARY) { + b = val.getBytes(); + } else { + b = val.getBytes(charset); + } + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } + + tagDataList.put(b); + lengthList.putLong(b.length); + break; + } + + case TSDBConstants.TSDB_DATA_TYPE_UTINYINT: + case TSDBConstants.TSDB_DATA_TYPE_USMALLINT: + case TSDBConstants.TSDB_DATA_TYPE_UINT: + case TSDBConstants.TSDB_DATA_TYPE_UBIGINT: { + throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNKNOWN, "not support data types"); + } + } + + typeList.put((byte) tag.type); + isNullList.putInt(tag.isNull ? 1 : 0); + } + + connector.setBindTableNameAndTags(this.nativeStmtHandle, this.tableName, this.tableTags.size(), tagDataList, + typeList, lengthList, isNullList); + } + + ColumnInfo colInfo = (ColumnInfo) this.colData.get(0); + if (colInfo == null) { + throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNKNOWN, "column data not bind"); + } + + int rows = colInfo.data.size(); + for (int i = 0; i < numOfCols; ++i) { + ColumnInfo col1 = this.colData.get(i); + if (col1 == null || !col1.isTypeSet()) { throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNKNOWN, "column data not bind"); - } - - if (rows != col1.data.size()) { + } + + if (rows != col1.data.size()) { throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNKNOWN, "the rows in column data not identical"); - } - - ByteBuffer colDataList = ByteBuffer.allocate(rows * col1.bytes); - colDataList.order(ByteOrder.LITTLE_ENDIAN); - + } + + ByteBuffer colDataList = ByteBuffer.allocate(rows * col1.bytes); + colDataList.order(ByteOrder.LITTLE_ENDIAN); + ByteBuffer lengthList = ByteBuffer.allocate(rows * Integer.BYTES); lengthList.order(ByteOrder.LITTLE_ENDIAN); - + ByteBuffer isNullList = ByteBuffer.allocate(rows * Byte.BYTES); isNullList.order(ByteOrder.LITTLE_ENDIAN); - - switch (col1.type) { - case TSDBConstants.TSDB_DATA_TYPE_INT: { - for (int j = 0; j < rows; ++j) { - Integer val = (Integer) col1.data.get(j); - colDataList.putInt(val == null? Integer.MIN_VALUE:val); - isNullList.put((byte) (val == null? 1:0)); - } - break; - } - - case TSDBConstants.TSDB_DATA_TYPE_TINYINT: { - for (int j = 0; j < rows; ++j) { - Byte val = (Byte) col1.data.get(j); - colDataList.put(val == null? 0:val); - isNullList.put((byte) (val == null? 1:0)); - } - break; - } - - case TSDBConstants.TSDB_DATA_TYPE_BOOL: { - for (int j = 0; j < rows; ++j) { - Boolean val = (Boolean) col1.data.get(j); - if (val == null) { - colDataList.put((byte) 0); - } else { - colDataList.put((byte) (val? 1:0)); - } - - isNullList.put((byte) (val == null? 1:0)); - } - break; - } - - case TSDBConstants.TSDB_DATA_TYPE_SMALLINT: { - for (int j = 0; j < rows; ++j) { - Short val = (Short) col1.data.get(j); - colDataList.putShort(val == null? 0:val); - isNullList.put((byte) (val == null? 1:0)); - } - break; - } - - case TSDBConstants.TSDB_DATA_TYPE_TIMESTAMP: - case TSDBConstants.TSDB_DATA_TYPE_BIGINT: { - for (int j = 0; j < rows; ++j) { - Long val = (Long) col1.data.get(j); - colDataList.putLong(val == null? 0:val); - isNullList.put((byte) (val == null? 1:0)); - } - break; - } - - case TSDBConstants.TSDB_DATA_TYPE_FLOAT: { - for (int j = 0; j < rows; ++j) { - Float val = (Float) col1.data.get(j); - colDataList.putFloat(val == null? 0:val); - isNullList.put((byte) (val == null? 1:0)); - } - break; - } - - case TSDBConstants.TSDB_DATA_TYPE_DOUBLE: { - for (int j = 0; j < rows; ++j) { - Double val = (Double) col1.data.get(j); - colDataList.putDouble(val == null? 0:val); - isNullList.put((byte) (val == null? 1:0)); - } - break; - } - - case TSDBConstants.TSDB_DATA_TYPE_NCHAR: - case TSDBConstants.TSDB_DATA_TYPE_BINARY: { - String charset = TaosGlobalConfig.getCharset(); - for (int j = 0; j < rows; ++j) { - String val = (String) col1.data.get(j); - - colDataList.position(j * col1.bytes); // seek to the correct position - if (val != null) { - byte[] b = null; - try { - if (col1.type == TSDBConstants.TSDB_DATA_TYPE_BINARY) { - b = val.getBytes(); - } else { - b = val.getBytes(charset); - } - } catch (UnsupportedEncodingException e) { - e.printStackTrace(); - } - - if (val.length() > col1.bytes) { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNKNOWN, "string data too long"); - } - - colDataList.put(b); - lengthList.putInt(b.length); - isNullList.put((byte) 0); - } else { - lengthList.putInt(0); - isNullList.put((byte) 1); - } - } - break; - } - - case TSDBConstants.TSDB_DATA_TYPE_UTINYINT: - case TSDBConstants.TSDB_DATA_TYPE_USMALLINT: - case TSDBConstants.TSDB_DATA_TYPE_UINT: - case TSDBConstants.TSDB_DATA_TYPE_UBIGINT: { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNKNOWN, "not support data types"); - } - }; - - connector.bindColumnDataArray(this.nativeStmtHandle, colDataList, lengthList, isNullList, col1.type, col1.bytes, rows, i); - } - } - - public void columnDataExecuteBatch() throws SQLException { - TSDBJNIConnector connector = ((TSDBConnection) this.getConnection()).getConnector(); - connector.executeBatch(this.nativeStmtHandle); - this.columnDataClearBatch(); - } - + + switch (col1.type) { + case TSDBConstants.TSDB_DATA_TYPE_INT: { + for (int j = 0; j < rows; ++j) { + Integer val = (Integer) col1.data.get(j); + colDataList.putInt(val == null ? Integer.MIN_VALUE : val); + isNullList.put((byte) (val == null ? 1 : 0)); + } + break; + } + + case TSDBConstants.TSDB_DATA_TYPE_TINYINT: { + for (int j = 0; j < rows; ++j) { + Byte val = (Byte) col1.data.get(j); + colDataList.put(val == null ? 0 : val); + isNullList.put((byte) (val == null ? 1 : 0)); + } + break; + } + + case TSDBConstants.TSDB_DATA_TYPE_BOOL: { + for (int j = 0; j < rows; ++j) { + Boolean val = (Boolean) col1.data.get(j); + if (val == null) { + colDataList.put((byte) 0); + } else { + colDataList.put((byte) (val ? 1 : 0)); + } + + isNullList.put((byte) (val == null ? 1 : 0)); + } + break; + } + + case TSDBConstants.TSDB_DATA_TYPE_SMALLINT: { + for (int j = 0; j < rows; ++j) { + Short val = (Short) col1.data.get(j); + colDataList.putShort(val == null ? 0 : val); + isNullList.put((byte) (val == null ? 1 : 0)); + } + break; + } + + case TSDBConstants.TSDB_DATA_TYPE_TIMESTAMP: + case TSDBConstants.TSDB_DATA_TYPE_BIGINT: { + for (int j = 0; j < rows; ++j) { + Long val = (Long) col1.data.get(j); + colDataList.putLong(val == null ? 0 : val); + isNullList.put((byte) (val == null ? 1 : 0)); + } + break; + } + + case TSDBConstants.TSDB_DATA_TYPE_FLOAT: { + for (int j = 0; j < rows; ++j) { + Float val = (Float) col1.data.get(j); + colDataList.putFloat(val == null ? 0 : val); + isNullList.put((byte) (val == null ? 1 : 0)); + } + break; + } + + case TSDBConstants.TSDB_DATA_TYPE_DOUBLE: { + for (int j = 0; j < rows; ++j) { + Double val = (Double) col1.data.get(j); + colDataList.putDouble(val == null ? 0 : val); + isNullList.put((byte) (val == null ? 1 : 0)); + } + break; + } + + case TSDBConstants.TSDB_DATA_TYPE_NCHAR: + case TSDBConstants.TSDB_DATA_TYPE_BINARY: { + String charset = TaosGlobalConfig.getCharset(); + for (int j = 0; j < rows; ++j) { + String val = (String) col1.data.get(j); + + colDataList.position(j * col1.bytes); // seek to the correct position + if (val != null) { + byte[] b = null; + try { + if (col1.type == TSDBConstants.TSDB_DATA_TYPE_BINARY) { + b = val.getBytes(); + } else { + b = val.getBytes(charset); + } + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } + + if (val.length() > col1.bytes) { + throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNKNOWN, "string data too long"); + } + + colDataList.put(b); + lengthList.putInt(b.length); + isNullList.put((byte) 0); + } else { + lengthList.putInt(0); + isNullList.put((byte) 1); + } + } + break; + } + + case TSDBConstants.TSDB_DATA_TYPE_UTINYINT: + case TSDBConstants.TSDB_DATA_TYPE_USMALLINT: + case TSDBConstants.TSDB_DATA_TYPE_UINT: + case TSDBConstants.TSDB_DATA_TYPE_UBIGINT: { + throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNKNOWN, "not support data types"); + } + } + ; + + connector.bindColumnDataArray(this.nativeStmtHandle, colDataList, lengthList, isNullList, col1.type, col1.bytes, rows, i); + } + } + + public void columnDataExecuteBatch() throws SQLException { + TSDBJNIConnector connector = ((TSDBConnection) this.getConnection()).getConnector(); + connector.executeBatch(this.nativeStmtHandle); + this.columnDataClearBatch(); + } + public void columnDataClearBatch() { - int size = this.colData.size(); - this.colData.clear(); - + int size = this.colData.size(); + this.colData.clear(); + this.colData.addAll(Collections.nCopies(size, null)); this.tableName = null; // clear the table name } - + public void columnDataCloseBatch() throws SQLException { - TSDBJNIConnector connector = ((TSDBConnection) this.getConnection()).getConnector(); - connector.closeBatch(this.nativeStmtHandle); - - this.nativeStmtHandle = 0L; - this.tableName = null; + TSDBJNIConnector connector = ((TSDBConnection) this.getConnection()).getConnector(); + connector.closeBatch(this.nativeStmtHandle); + + this.nativeStmtHandle = 0L; + this.tableName = null; } } diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBResultSet.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBResultSet.java index aba29d602b8900d3bedee49ee94e7d226b3bd1f0..59a64ad520f01c8c7f2b85f95057365e2410ecb6 100644 --- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBResultSet.java +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBResultSet.java @@ -133,9 +133,10 @@ public class TSDBResultSet extends AbstractResultSet implements ResultSet { if (this.getBatchFetch()) return this.blockData.getString(columnIndex - 1); - this.lastWasNull = this.rowData.wasNull(columnIndex - 1); + this.lastWasNull = this.rowData.wasNull(columnIndex); if (!lastWasNull) { - res = this.rowData.getString(columnIndex - 1, this.columnMetaDataList.get(columnIndex - 1).getColType()); + int nativeType = this.columnMetaDataList.get(columnIndex - 1).getColType(); + res = this.rowData.getString(columnIndex, nativeType); } return res; } @@ -147,9 +148,10 @@ public class TSDBResultSet extends AbstractResultSet implements ResultSet { if (this.getBatchFetch()) return this.blockData.getBoolean(columnIndex - 1); - this.lastWasNull = this.rowData.wasNull(columnIndex - 1); + this.lastWasNull = this.rowData.wasNull(columnIndex); if (!lastWasNull) { - res = this.rowData.getBoolean(columnIndex - 1, this.columnMetaDataList.get(columnIndex - 1).getColType()); + int nativeType = this.columnMetaDataList.get(columnIndex - 1).getColType(); + res = this.rowData.getBoolean(columnIndex, nativeType); } return res; } @@ -161,9 +163,10 @@ public class TSDBResultSet extends AbstractResultSet implements ResultSet { if (this.getBatchFetch()) return (byte) this.blockData.getInt(columnIndex - 1); - this.lastWasNull = this.rowData.wasNull(columnIndex - 1); + this.lastWasNull = this.rowData.wasNull(columnIndex); if (!lastWasNull) { - res = (byte) this.rowData.getInt(columnIndex - 1, this.columnMetaDataList.get(columnIndex - 1).getColType()); + int nativeType = this.columnMetaDataList.get(columnIndex - 1).getColType(); + res = (byte) this.rowData.getInt(columnIndex, nativeType); } return res; } @@ -175,9 +178,10 @@ public class TSDBResultSet extends AbstractResultSet implements ResultSet { if (this.getBatchFetch()) return (short) this.blockData.getInt(columnIndex - 1); - this.lastWasNull = this.rowData.wasNull(columnIndex - 1); + this.lastWasNull = this.rowData.wasNull(columnIndex); if (!lastWasNull) { - res = (short) this.rowData.getInt(columnIndex - 1, this.columnMetaDataList.get(columnIndex - 1).getColType()); + int nativeType = this.columnMetaDataList.get(columnIndex - 1).getColType(); + res = (short) this.rowData.getInt(columnIndex, nativeType); } return res; } @@ -189,9 +193,11 @@ public class TSDBResultSet extends AbstractResultSet implements ResultSet { if (this.getBatchFetch()) return this.blockData.getInt(columnIndex - 1); - this.lastWasNull = this.rowData.wasNull(columnIndex - 1); + + this.lastWasNull = this.rowData.wasNull(columnIndex); if (!lastWasNull) { - res = this.rowData.getInt(columnIndex - 1, this.columnMetaDataList.get(columnIndex - 1).getColType()); + int nativeType = this.columnMetaDataList.get(columnIndex - 1).getColType(); + res = this.rowData.getInt(columnIndex, nativeType); } return res; } @@ -203,13 +209,15 @@ public class TSDBResultSet extends AbstractResultSet implements ResultSet { if (this.getBatchFetch()) return this.blockData.getLong(columnIndex - 1); - this.lastWasNull = this.rowData.wasNull(columnIndex - 1); + this.lastWasNull = this.rowData.wasNull(columnIndex); if (!lastWasNull) { - Object value = this.rowData.get(columnIndex - 1); - if (value instanceof Timestamp) + Object value = this.rowData.getObject(columnIndex); + if (value instanceof Timestamp) { res = ((Timestamp) value).getTime(); - else - res = this.rowData.getLong(columnIndex - 1, this.columnMetaDataList.get(columnIndex - 1).getColType()); + } else { + int nativeType = this.columnMetaDataList.get(columnIndex - 1).getColType(); + res = this.rowData.getLong(columnIndex, nativeType); + } } return res; } @@ -221,9 +229,11 @@ public class TSDBResultSet extends AbstractResultSet implements ResultSet { if (this.getBatchFetch()) return (float) this.blockData.getDouble(columnIndex - 1); - this.lastWasNull = this.rowData.wasNull(columnIndex - 1); - if (!lastWasNull) - res = this.rowData.getFloat(columnIndex - 1, this.columnMetaDataList.get(columnIndex - 1).getColType()); + this.lastWasNull = this.rowData.wasNull(columnIndex); + if (!lastWasNull) { + int nativeType = this.columnMetaDataList.get(columnIndex - 1).getColType(); + res = this.rowData.getFloat(columnIndex, nativeType); + } return res; } @@ -235,9 +245,10 @@ public class TSDBResultSet extends AbstractResultSet implements ResultSet { if (this.getBatchFetch()) return this.blockData.getDouble(columnIndex - 1); - this.lastWasNull = this.rowData.wasNull(columnIndex - 1); + this.lastWasNull = this.rowData.wasNull(columnIndex); if (!lastWasNull) { - res = this.rowData.getDouble(columnIndex - 1, this.columnMetaDataList.get(columnIndex - 1).getColType()); + int nativeType = this.columnMetaDataList.get(columnIndex - 1).getColType(); + res = this.rowData.getDouble(columnIndex, nativeType); } return res; } @@ -245,34 +256,27 @@ public class TSDBResultSet extends AbstractResultSet implements ResultSet { public byte[] getBytes(int columnIndex) throws SQLException { checkAvailability(columnIndex, this.columnMetaDataList.size()); - Object value = this.rowData.get(columnIndex - 1); + Object value = this.rowData.getObject(columnIndex); if (value == null) return null; - int colType = this.columnMetaDataList.get(columnIndex - 1).getColType(); - switch (colType) { + int nativeType = this.columnMetaDataList.get(columnIndex - 1).getColType(); + switch (nativeType) { case TSDBConstants.TSDB_DATA_TYPE_BIGINT: - return Longs.toByteArray((Long) value); + return Longs.toByteArray((long) value); case TSDBConstants.TSDB_DATA_TYPE_INT: return Ints.toByteArray((int) value); case TSDBConstants.TSDB_DATA_TYPE_SMALLINT: - return Shorts.toByteArray((Short) value); + return Shorts.toByteArray((short) value); case TSDBConstants.TSDB_DATA_TYPE_TINYINT: return new byte[]{(byte) value}; + case TSDBConstants.TSDB_DATA_TYPE_BINARY: + return (byte[]) value; + case TSDBConstants.TSDB_DATA_TYPE_BOOL: + case TSDBConstants.TSDB_DATA_TYPE_NCHAR: + default: + return value.toString().getBytes(); } - return value.toString().getBytes(); - } - - @Override - public Date getDate(int columnIndex) throws SQLException { - Timestamp timestamp = getTimestamp(columnIndex); - return timestamp == null ? null : new Date(timestamp.getTime()); - } - - @Override - public Time getTime(int columnIndex) throws SQLException { - Timestamp timestamp = getTimestamp(columnIndex); - return timestamp == null ? null : new Time(timestamp.getTime()); } public Timestamp getTimestamp(int columnIndex) throws SQLException { @@ -282,9 +286,10 @@ public class TSDBResultSet extends AbstractResultSet implements ResultSet { if (this.getBatchFetch()) return this.blockData.getTimestamp(columnIndex - 1); - this.lastWasNull = this.rowData.wasNull(columnIndex - 1); + this.lastWasNull = this.rowData.wasNull(columnIndex); if (!lastWasNull) { - res = this.rowData.getTimestamp(columnIndex - 1); + int nativeType = this.columnMetaDataList.get(columnIndex - 1).getColType(); + res = this.rowData.getTimestamp(columnIndex, nativeType); } return res; } @@ -304,13 +309,9 @@ public class TSDBResultSet extends AbstractResultSet implements ResultSet { if (this.getBatchFetch()) return this.blockData.get(columnIndex - 1); - this.lastWasNull = this.rowData.wasNull(columnIndex - 1); + this.lastWasNull = this.rowData.wasNull(columnIndex); if (!lastWasNull) { - int colType = this.columnMetaDataList.get(columnIndex - 1).getColType(); - if (colType == TSDBConstants.TSDB_DATA_TYPE_BINARY) - res = ((String) this.rowData.get(columnIndex - 1)).getBytes(); - else - res = this.rowData.get(columnIndex - 1); + res = this.rowData.getObject(columnIndex); } return res; } @@ -318,7 +319,7 @@ public class TSDBResultSet extends AbstractResultSet implements ResultSet { public int findColumn(String columnLabel) throws SQLException { for (ColumnMetaData colMetaData : this.columnMetaDataList) { if (colMetaData.getColName() != null && colMetaData.getColName().equalsIgnoreCase(columnLabel)) { - return colMetaData.getColIndex() + 1; + return colMetaData.getColIndex(); } } throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_INVALID_VARIABLE); @@ -329,25 +330,25 @@ public class TSDBResultSet extends AbstractResultSet implements ResultSet { if (this.getBatchFetch()) return new BigDecimal(this.blockData.getLong(columnIndex - 1)); - this.lastWasNull = this.rowData.wasNull(columnIndex - 1); + this.lastWasNull = this.rowData.wasNull(columnIndex); BigDecimal res = null; if (!lastWasNull) { - int colType = this.columnMetaDataList.get(columnIndex - 1).getColType(); - switch (colType) { + int nativeType = this.columnMetaDataList.get(columnIndex - 1).getColType(); + switch (nativeType) { case TSDBConstants.TSDB_DATA_TYPE_TINYINT: case TSDBConstants.TSDB_DATA_TYPE_SMALLINT: case TSDBConstants.TSDB_DATA_TYPE_INT: case TSDBConstants.TSDB_DATA_TYPE_BIGINT: - res = new BigDecimal(Long.valueOf(this.rowData.get(columnIndex - 1).toString())); + res = new BigDecimal(Long.valueOf(this.rowData.getObject(columnIndex).toString())); break; case TSDBConstants.TSDB_DATA_TYPE_FLOAT: case TSDBConstants.TSDB_DATA_TYPE_DOUBLE: - res = new BigDecimal(Double.valueOf(this.rowData.get(columnIndex - 1).toString())); + res = new BigDecimal(Double.valueOf(this.rowData.getObject(columnIndex).toString())); break; case TSDBConstants.TSDB_DATA_TYPE_TIMESTAMP: - return new BigDecimal(((Timestamp) this.rowData.get(columnIndex - 1)).getTime()); + return new BigDecimal(((Timestamp) this.rowData.getObject(columnIndex)).getTime()); default: - res = new BigDecimal(this.rowData.get(columnIndex - 1).toString()); + res = new BigDecimal(this.rowData.getObject(columnIndex).toString()); } } return res; diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBResultSetMetaData.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBResultSetMetaData.java index e4ac5303d09f132279e29039bf6b5b812b6c5404..48d42473926b638401cf5d9dd97466695ba452ab 100644 --- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBResultSetMetaData.java +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBResultSetMetaData.java @@ -113,6 +113,7 @@ public class TSDBResultSetMetaData extends WrapperImpl implements ResultSetMetaD ColumnMetaData columnMetaData = this.colMetaDataList.get(column - 1); switch (columnMetaData.getColType()) { + case TSDBConstants.TSDB_DATA_TYPE_FLOAT: return 5; case TSDBConstants.TSDB_DATA_TYPE_DOUBLE: diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBResultSetRowData.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBResultSetRowData.java index 618e896a6ddfe43d63f631b663a356f485575b06..01104440ab00c974aa021f10b4168c3f1332e91a 100644 --- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBResultSetRowData.java +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBResultSetRowData.java @@ -14,6 +14,8 @@ *****************************************************************************/ package com.taosdata.jdbc; +import com.taosdata.jdbc.utils.NullType; + import java.math.BigDecimal; import java.sql.SQLException; import java.sql.Timestamp; @@ -22,11 +24,13 @@ import java.util.ArrayList; import java.util.Collections; public class TSDBResultSetRowData { + private ArrayList data; - private int colSize = 0; + private int colSize; public TSDBResultSetRowData(int colSize) { - this.setColSize(colSize); + this.colSize = colSize; + this.clear(); } public void clear() { @@ -41,68 +45,104 @@ public class TSDBResultSetRowData { } public boolean wasNull(int col) { - return data.get(col) == null; + return data.get(col - 1) == null; + } + + /** + * $$$ this method is invoked by databaseMetaDataResultSet and so on which use a index start from 1 in JDBC api + */ + public void setBooleanValue(int col, boolean value) { + setBoolean(col - 1, value); } + /** + * !!! this method is invoked by JNI method and the index start from 0 in C implementations + */ public void setBoolean(int col, boolean value) { data.set(col, value); } - public boolean getBoolean(int col, int srcType) throws SQLException { - Object obj = data.get(col); + public boolean getBoolean(int col, int nativeType) throws SQLException { + Object obj = data.get(col - 1); - switch (srcType) { + switch (nativeType) { case TSDBConstants.TSDB_DATA_TYPE_BOOL: return (Boolean) obj; - case TSDBConstants.TSDB_DATA_TYPE_FLOAT: - return ((Float) obj) == 1.0 ? Boolean.TRUE : Boolean.FALSE; - case TSDBConstants.TSDB_DATA_TYPE_DOUBLE: - return ((Double) obj) == 1.0 ? Boolean.TRUE : Boolean.FALSE; case TSDBConstants.TSDB_DATA_TYPE_TINYINT: return ((Byte) obj) == 1 ? Boolean.TRUE : Boolean.FALSE; case TSDBConstants.TSDB_DATA_TYPE_SMALLINT: return ((Short) obj) == 1 ? Boolean.TRUE : Boolean.FALSE; case TSDBConstants.TSDB_DATA_TYPE_INT: return ((Integer) obj) == 1 ? Boolean.TRUE : Boolean.FALSE; - case TSDBConstants.TSDB_DATA_TYPE_TIMESTAMP: case TSDBConstants.TSDB_DATA_TYPE_BIGINT: return ((Long) obj) == 1L ? Boolean.TRUE : Boolean.FALSE; + case TSDBConstants.TSDB_DATA_TYPE_BINARY: + case TSDBConstants.TSDB_DATA_TYPE_NCHAR: { + return obj.toString().contains("1"); + } default: return false; } } + /** + * $$$ this method is invoked by databaseMetaDataResultSet and so on which use a index start from 1 in JDBC api + */ + public void setByteValue(int colIndex, byte value) { + setByte(colIndex - 1, value); + } + + /** + * !!! this method is invoked by JNI method and the index start from 0 in C implementations + */ public void setByte(int col, byte value) { data.set(col, value); } + /** + * $$$ this method is invoked by databaseMetaDataResultSet and so on which use a index start from 1 in JDBC api + */ + public void setShortValue(int colIndex, short value) { + setShort(colIndex - 1, value); + } + + /** + * !!! this method is invoked by JNI method and the index start from 0 in C implementations + */ public void setShort(int col, short value) { data.set(col, value); } + /** + * $$$ this method is invoked by databaseMetaDataResultSet and so on which use a index start from 1 in JDBC api + */ + public void setIntValue(int colIndex, int value) { + setInt(colIndex - 1, value); + } + + /** + * !!! this method is invoked by JNI method and the index start from 0 in C implementations + */ public void setInt(int col, int value) { data.set(col, value); } - @SuppressWarnings("deprecation") - public int getInt(int col, int srcType) throws SQLException { - Object obj = data.get(col); + public int getInt(int col, int nativeType) throws SQLException { + Object obj = data.get(col - 1); + if (obj == null) + return NullType.getIntNull(); - switch (srcType) { + switch (nativeType) { case TSDBConstants.TSDB_DATA_TYPE_BOOL: return Boolean.TRUE.equals(obj) ? 1 : 0; - case TSDBConstants.TSDB_DATA_TYPE_FLOAT: - return ((Float) obj).intValue(); - case TSDBConstants.TSDB_DATA_TYPE_DOUBLE: - return ((Double) obj).intValue(); case TSDBConstants.TSDB_DATA_TYPE_TINYINT: return (Byte) obj; case TSDBConstants.TSDB_DATA_TYPE_SMALLINT: return (Short) obj; case TSDBConstants.TSDB_DATA_TYPE_INT: return (Integer) obj; - case TSDBConstants.TSDB_DATA_TYPE_TIMESTAMP: case TSDBConstants.TSDB_DATA_TYPE_BIGINT: + case TSDBConstants.TSDB_DATA_TYPE_TIMESTAMP: return ((Long) obj).intValue(); case TSDBConstants.TSDB_DATA_TYPE_NCHAR: case TSDBConstants.TSDB_DATA_TYPE_BINARY: @@ -131,33 +171,46 @@ public class TSDBResultSetRowData { throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_NUMERIC_VALUE_OUT_OF_RANGE); return Long.valueOf(value).intValue(); } + case TSDBConstants.TSDB_DATA_TYPE_FLOAT: + return ((Float) obj).intValue(); + case TSDBConstants.TSDB_DATA_TYPE_DOUBLE: + return ((Double) obj).intValue(); + default: + return 0; } + } - return 0; + /** + * $$$ this method is invoked by databaseMetaDataResultSet and so on which use a index start from 1 in JDBC api + */ + public void setLongValue(int colIndex, long value) { + setLong(colIndex - 1, value); } + /** + * !!! this method is invoked by JNI method and the index start from 0 in C implementations + */ public void setLong(int col, long value) { data.set(col, value); } - public long getLong(int col, int srcType) throws SQLException { - Object obj = data.get(col); + public long getLong(int col, int nativeType) throws SQLException { + Object obj = data.get(col - 1); + if (obj == null) { + return NullType.getBigIntNull(); + } - switch (srcType) { + switch (nativeType) { case TSDBConstants.TSDB_DATA_TYPE_BOOL: return Boolean.TRUE.equals(obj) ? 1 : 0; - case TSDBConstants.TSDB_DATA_TYPE_FLOAT: - return ((Float) obj).longValue(); - case TSDBConstants.TSDB_DATA_TYPE_DOUBLE: - return ((Double) obj).longValue(); case TSDBConstants.TSDB_DATA_TYPE_TINYINT: return (Byte) obj; case TSDBConstants.TSDB_DATA_TYPE_SMALLINT: return (Short) obj; case TSDBConstants.TSDB_DATA_TYPE_INT: return (Integer) obj; - case TSDBConstants.TSDB_DATA_TYPE_TIMESTAMP: case TSDBConstants.TSDB_DATA_TYPE_BIGINT: + case TSDBConstants.TSDB_DATA_TYPE_TIMESTAMP: return (Long) obj; case TSDBConstants.TSDB_DATA_TYPE_NCHAR: case TSDBConstants.TSDB_DATA_TYPE_BINARY: @@ -186,19 +239,35 @@ public class TSDBResultSetRowData { throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_NUMERIC_VALUE_OUT_OF_RANGE); return value; } + case TSDBConstants.TSDB_DATA_TYPE_FLOAT: + return ((Float) obj).longValue(); + case TSDBConstants.TSDB_DATA_TYPE_DOUBLE: + return ((Double) obj).longValue(); + default: + return 0; } + } - return 0; + /** + * $$$ this method is invoked by databaseMetaDataResultSet and so on which use a index start from 1 in JDBC api + */ + public void setFloatValue(int colIndex, float value) { + setFloat(colIndex - 1, value); } + /** + * !!! this method is invoked by JNI method and the index start from 0 in C implementations + */ public void setFloat(int col, float value) { data.set(col, value); } - public float getFloat(int col, int srcType) { - Object obj = data.get(col); + public float getFloat(int col, int nativeType) { + Object obj = data.get(col - 1); + if (obj == null) + return NullType.getFloatNull(); - switch (srcType) { + switch (nativeType) { case TSDBConstants.TSDB_DATA_TYPE_BOOL: return Boolean.TRUE.equals(obj) ? 1 : 0; case TSDBConstants.TSDB_DATA_TYPE_FLOAT: @@ -214,19 +283,31 @@ public class TSDBResultSetRowData { case TSDBConstants.TSDB_DATA_TYPE_TIMESTAMP: case TSDBConstants.TSDB_DATA_TYPE_BIGINT: return (Long) obj; + default: + return NullType.getFloatNull(); } + } - return 0; + /** + * $$$ this method is invoked by databaseMetaDataResultSet and so on which use a index start from 1 in JDBC api + */ + public void setDoubleValue(int colIndex, double value) { + setDouble(colIndex - 1, value); } + /** + * !!! this method is invoked by JNI method and the index start from 0 in C implementations + */ public void setDouble(int col, double value) { data.set(col, value); } - public double getDouble(int col, int srcType) { - Object obj = data.get(col); + public double getDouble(int col, int nativeType) { + Object obj = data.get(col - 1); + if (obj == null) + return NullType.getDoubleNull(); - switch (srcType) { + switch (nativeType) { case TSDBConstants.TSDB_DATA_TYPE_BOOL: return Boolean.TRUE.equals(obj) ? 1 : 0; case TSDBConstants.TSDB_DATA_TYPE_FLOAT: @@ -242,16 +323,46 @@ public class TSDBResultSetRowData { case TSDBConstants.TSDB_DATA_TYPE_TIMESTAMP: case TSDBConstants.TSDB_DATA_TYPE_BIGINT: return (Long) obj; + default: + return NullType.getDoubleNull(); } + } - return 0; + /** + * $$$ this method is invoked by databaseMetaDataResultSet and so on which use a index start from 1 in JDBC api + */ + public void setStringValue(int colIndex, String value) { + data.set(colIndex - 1, value); } + /** + * !!! this method is invoked by JNI method and the index start from 0 in C implementations + */ public void setString(int col, String value) { - data.set(col, value); + // TODO: + // !!!NOTE!!! + // this is very confusing problem which related to JNI-method implementation, + // the JNI method return a String(encoded in UTF) for BINARY value, which means the JNI method will invoke + // this setString(int, String) to handle BINARY value, we need to build a byte[] with default charsetEncoding + data.set(col, value == null ? null : value.getBytes()); + } + + /** + * $$$ this method is invoked by databaseMetaDataResultSet and so on which use a index start from 1 in JDBC api + */ + public void setByteArrayValue(int colIndex, byte[] value) { + setByteArray(colIndex - 1, value); } + /** + * !!! this method is invoked by JNI method and the index start from 0 in C implementations + */ public void setByteArray(int col, byte[] value) { + // TODO: + // !!!NOTE!!! + // this is very confusing problem which related to JNI-method implementation, + // the JNI method return a byte[] for NCHAR value, which means the JNI method will invoke + // this setByteArr(int, byte[]) to handle NCHAR value, we need to build a String with charsetEncoding by TaosGlobalConfig try { data.set(col, new String(value, TaosGlobalConfig.getCharset())); } catch (Exception e) { @@ -259,47 +370,56 @@ public class TSDBResultSetRowData { } } - /** - * The original type may not be a string type, but will be converted to by calling this method - * - * @param col column index - * @return - */ - public String getString(int col, int srcType) { - switch (srcType) { - case TSDBConstants.TSDB_DATA_TYPE_BINARY: - case TSDBConstants.TSDB_DATA_TYPE_NCHAR: - return (String) data.get(col); + public String getString(int col, int nativeType) { + Object obj = data.get(col - 1); + if (obj == null) + return null; + + switch (nativeType) { case TSDBConstants.TSDB_DATA_TYPE_UTINYINT: { - Byte value = new Byte(String.valueOf(data.get(col))); + Byte value = new Byte(String.valueOf(obj)); if (value >= 0) return value.toString(); return Integer.toString(value & 0xff); } case TSDBConstants.TSDB_DATA_TYPE_USMALLINT: { - Short value = new Short(String.valueOf(data.get(col))); + Short value = new Short(String.valueOf(obj)); if (value >= 0) return value.toString(); return Integer.toString(value & 0xffff); } case TSDBConstants.TSDB_DATA_TYPE_UINT: { - Integer value = new Integer(String.valueOf(data.get(col))); + Integer value = new Integer(String.valueOf(obj)); if (value >= 0) return value.toString(); return Long.toString(value & 0xffffffffl); } case TSDBConstants.TSDB_DATA_TYPE_UBIGINT: { - Long value = new Long(String.valueOf(data.get(col))); + Long value = new Long(String.valueOf(obj)); if (value >= 0) return value.toString(); long lowValue = value & 0x7fffffffffffffffL; return BigDecimal.valueOf(lowValue).add(BigDecimal.valueOf(Long.MAX_VALUE)).add(BigDecimal.valueOf(1)).toString(); } + case TSDBConstants.TSDB_DATA_TYPE_BINARY: + return new String((byte[]) obj); + case TSDBConstants.TSDB_DATA_TYPE_NCHAR: + return (String) obj; default: - return String.valueOf(data.get(col)); + return String.valueOf(obj); } } + /** + * $$$ this method is invoked by databaseMetaDataResultSet and so on which use a index start from 1 in JDBC api + */ + public void setTimestampValue(int colIndex, long value) { + setTimestamp(colIndex - 1, value); + } + + /** + * !!! this method is invoked by JNI method and the index start from 0 in C implementations + */ public void setTimestamp(int col, long ts) { //TODO: this implementation contains logical error // when precision is us the (long ts) is 16 digital number @@ -316,28 +436,20 @@ public class TSDBResultSetRowData { } } - public Timestamp getTimestamp(int col) { - return (Timestamp) data.get(col); - } - - public Object get(int col) { - return data.get(col); - } - - public int getColSize() { - return colSize; - } - - private void setColSize(int colSize) { - this.colSize = colSize; - this.clear(); + public Timestamp getTimestamp(int col, int nativeType) { + Object obj = data.get(col - 1); + if (obj == null) + return null; + switch (nativeType) { + case TSDBConstants.TSDB_DATA_TYPE_BIGINT: + return new Timestamp((Long) obj); + default: + return (Timestamp) obj; + } } - public ArrayList getData() { - return data; + public Object getObject(int col) { + return data.get(col - 1); } - public void setData(ArrayList data) { - this.data = (ArrayList) data.clone(); - } } diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBStatement.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBStatement.java index d8ba67576d069a6aec0a5bb17e9549e41b8cf31e..e1ebc4ab3cf498168181dbea08a3ac28194a5c7d 100644 --- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBStatement.java +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBStatement.java @@ -32,14 +32,15 @@ public class TSDBStatement extends AbstractStatement { } public ResultSet executeQuery(String sql) throws SQLException { - // check if closed if (isClosed()) { throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED); } - - //TODO: 如果在executeQuery方法中执行insert语句,那么先执行了SQL,再通过pSql来检查是否为一个insert语句,但这个insert SQL已经执行成功了 - - // execute query + //TODO: + // this is an unreasonable implementation, if the paratemer is a insert statement, + // the JNI connector will execute the sql at first and return a pointer: pSql, + // we use this pSql and invoke the isUpdateQuery(long pSql) method to decide . + // but the insert sql is already executed in database. + //execute query long pSql = this.connection.getConnector().executeQuery(sql); // if pSql is create/insert/update/delete/alter SQL if (this.connection.getConnector().isUpdateQuery(pSql)) { diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/utils/Utils.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/utils/Utils.java index eeb936a1d0843c56e0de63a6c4b113fb644b778f..8ab610fec6541e96d8b4b997c6883dddc01f1549 100644 --- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/utils/Utils.java +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/utils/Utils.java @@ -95,16 +95,7 @@ public class Utils { public static String getNativeSql(String rawSql, Object[] parameters) { // toLowerCase String preparedSql = rawSql.trim().toLowerCase(); - - String[] clause = new String[0]; - if (SqlSyntaxValidator.isInsertSql(preparedSql)) { - // insert or import - clause = new String[]{"values\\s*\\(.*?\\)", "tags\\s*\\(.*?\\)"}; - } - if (SqlSyntaxValidator.isSelectSql(preparedSql)) { - // select - clause = new String[]{"where\\s*.*"}; - } + String[] clause = new String[]{"values\\s*\\(.*?\\)", "tags\\s*\\(.*?\\)", "where\\s*.*"}; Map placeholderPositions = new HashMap<>(); RangeSet clauseRangeSet = TreeRangeSet.create(); findPlaceholderPosition(preparedSql, placeholderPositions); diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBConnectionTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBConnectionTest.java index ca7251bb0eac306d6a21872699918e18b2447e6e..dc6d0d322af5c90dc0eb9d42328c9864714838a1 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBConnectionTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBConnectionTest.java @@ -32,20 +32,34 @@ public class TSDBConnectionTest { } @Test - public void subscribe() { + public void runSubscribe() { try { + // given TSDBConnection unwrap = conn.unwrap(TSDBConnection.class); TSDBSubscribe subscribe = unwrap.subscribe("topic1", "select * from log.log", false); + // when TSDBResultSet rs = subscribe.consume(); ResultSetMetaData metaData = rs.getMetaData(); - for (int count = 0; count < 10 && rs.next(); count++) { - for (int i = 1; i <= metaData.getColumnCount(); i++) { - String value = rs.getString(i); - System.out.print(metaData.getColumnLabel(i) + ":" + value + "\t"); - } - System.out.println(); - } + + // then Assert.assertNotNull(rs); + Assert.assertEquals(4, metaData.getColumnCount()); + Assert.assertEquals("ts", metaData.getColumnLabel(1)); + Assert.assertEquals("level", metaData.getColumnLabel(2)); + Assert.assertEquals("content", metaData.getColumnLabel(3)); + Assert.assertEquals("ipaddr", metaData.getColumnLabel(4)); + rs.next(); + // row 1 + { + Assert.assertNotNull(rs.getTimestamp(1)); + Assert.assertNotNull(rs.getTimestamp("ts")); + Assert.assertNotNull(rs.getByte(2)); + Assert.assertNotNull(rs.getByte("level")); + Assert.assertNotNull(rs.getString(3)); + Assert.assertNotNull(rs.getString("content")); + Assert.assertNotNull(rs.getString(4)); + Assert.assertNotNull(rs.getString("ipaddr")); + } subscribe.close(false); } catch (SQLException e) { e.printStackTrace(); diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBDatabaseMetaDataTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBDatabaseMetaDataTest.java index a7657fa3e581c96cf85555b16fca5f8b4c7f8ebb..cb6133015c0256de99ea4db02bedeb982ce7491d 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBDatabaseMetaDataTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBDatabaseMetaDataTest.java @@ -7,9 +7,11 @@ import java.util.Properties; public class TSDBDatabaseMetaDataTest { private static final String host = "127.0.0.1"; + private static final String url = "jdbc:TAOS://" + host + ":6030/?user=root&password=taosdata"; private static Connection connection; private static TSDBDatabaseMetaData metaData; + @Test public void unwrap() throws SQLException { TSDBDatabaseMetaData unwrap = metaData.unwrap(TSDBDatabaseMetaData.class); @@ -33,7 +35,7 @@ public class TSDBDatabaseMetaDataTest { @Test public void getURL() throws SQLException { - Assert.assertEquals("jdbc:TAOS://" + host + ":6030/?user=root&password=taosdata", metaData.getURL()); + Assert.assertEquals(url, metaData.getURL()); } @Test @@ -627,17 +629,32 @@ public class TSDBDatabaseMetaDataTest { @Test public void getTables() throws SQLException { - System.out.println("****************************************************"); - ResultSet tables = metaData.getTables("log", "", null, null); - ResultSetMetaData metaData = tables.getMetaData(); - while (tables.next()) { - System.out.print(metaData.getColumnLabel(1) + ":" + tables.getString(1) + "\t"); - System.out.print(metaData.getColumnLabel(3) + ":" + tables.getString(3) + "\t"); - System.out.print(metaData.getColumnLabel(4) + ":" + tables.getString(4) + "\t"); - System.out.print(metaData.getColumnLabel(5) + ":" + tables.getString(5) + "\n"); + ResultSet rs = metaData.getTables("log", "", null, null); + ResultSetMetaData meta = rs.getMetaData(); + Assert.assertNotNull(rs); + rs.next(); + { + // TABLE_CAT + Assert.assertEquals("TABLE_CAT", meta.getColumnLabel(1)); + Assert.assertEquals("log", rs.getString(1)); + Assert.assertEquals("log", rs.getString("TABLE_CAT")); + // TABLE_SCHEM + Assert.assertEquals("TABLE_SCHEM", meta.getColumnLabel(2)); + Assert.assertEquals(null, rs.getString(2)); + Assert.assertEquals(null, rs.getString("TABLE_SCHEM")); + // TABLE_NAME + Assert.assertEquals("TABLE_NAME", meta.getColumnLabel(3)); + Assert.assertNotNull(rs.getString(3)); + Assert.assertNotNull(rs.getString("TABLE_NAME")); + // TABLE_TYPE + Assert.assertEquals("TABLE_TYPE", meta.getColumnLabel(4)); + Assert.assertEquals("TABLE", rs.getString(4)); + Assert.assertEquals("TABLE", rs.getString("TABLE_TYPE")); + // REMARKS + Assert.assertEquals("REMARKS", meta.getColumnLabel(5)); + Assert.assertEquals("", rs.getString(5)); + Assert.assertEquals("", rs.getString("REMARKS")); } - System.out.println(); - Assert.assertNotNull(tables); } @Test @@ -647,46 +664,130 @@ public class TSDBDatabaseMetaDataTest { @Test public void getCatalogs() throws SQLException { - System.out.println("****************************************************"); - - ResultSet catalogs = metaData.getCatalogs(); - ResultSetMetaData meta = catalogs.getMetaData(); - while (catalogs.next()) { - for (int i = 1; i <= meta.getColumnCount(); i++) { - System.out.print(meta.getColumnLabel(i) + ": " + catalogs.getString(i)); - } - System.out.println(); + ResultSet rs = metaData.getCatalogs(); + ResultSetMetaData meta = rs.getMetaData(); + rs.next(); + { + // TABLE_CAT + Assert.assertEquals("TABLE_CAT", meta.getColumnLabel(1)); + Assert.assertNotNull(rs.getString(1)); + Assert.assertNotNull(rs.getString("TABLE_CAT")); } } @Test public void getTableTypes() throws SQLException { - System.out.println("****************************************************"); - ResultSet tableTypes = metaData.getTableTypes(); - while (tableTypes.next()) { - System.out.println(tableTypes.getString("TABLE_TYPE")); + tableTypes.next(); + // tableTypes: table + { + Assert.assertEquals("TABLE", tableTypes.getString(1)); + Assert.assertEquals("TABLE", tableTypes.getString("TABLE_TYPE")); + } + tableTypes.next(); + // tableTypes: stable + { + Assert.assertEquals("STABLE", tableTypes.getString(1)); + Assert.assertEquals("STABLE", tableTypes.getString("TABLE_TYPE")); } - Assert.assertNotNull(metaData.getTableTypes()); } @Test public void getColumns() throws SQLException { - System.out.println("****************************************************"); - + // when ResultSet columns = metaData.getColumns("log", "", "dn", ""); + // then ResultSetMetaData meta = columns.getMetaData(); - while (columns.next()) { - System.out.print(meta.getColumnLabel(1) + ": " + columns.getString(1) + "\t"); - System.out.print(meta.getColumnLabel(3) + ": " + columns.getString(3) + "\t"); - System.out.print(meta.getColumnLabel(4) + ": " + columns.getString(4) + "\t"); - System.out.print(meta.getColumnLabel(5) + ": " + columns.getString(5) + "\t"); - System.out.print(meta.getColumnLabel(6) + ": " + columns.getString(6) + "\t"); - System.out.print(meta.getColumnLabel(7) + ": " + columns.getString(7) + "\t"); - System.out.print(meta.getColumnLabel(9) + ": " + columns.getString(9) + "\t"); - System.out.print(meta.getColumnLabel(10) + ": " + columns.getString(10) + "\t"); - System.out.print(meta.getColumnLabel(11) + ": " + columns.getString(11) + "\n"); - System.out.print(meta.getColumnLabel(12) + ": " + columns.getString(12) + "\n"); + columns.next(); + // column: 1 + { + // TABLE_CAT + Assert.assertEquals("TABLE_CAT", meta.getColumnLabel(1)); + Assert.assertEquals("log", columns.getString(1)); + Assert.assertEquals("log", columns.getString("TABLE_CAT")); + // TABLE_NAME + Assert.assertEquals("TABLE_NAME", meta.getColumnLabel(3)); + Assert.assertEquals("dn", columns.getString(3)); + Assert.assertEquals("dn", columns.getString("TABLE_NAME")); + // COLUMN_NAME + Assert.assertEquals("COLUMN_NAME", meta.getColumnLabel(4)); + Assert.assertEquals("ts", columns.getString(4)); + Assert.assertEquals("ts", columns.getString("COLUMN_NAME")); + // DATA_TYPE + Assert.assertEquals("DATA_TYPE", meta.getColumnLabel(5)); + Assert.assertEquals(Types.TIMESTAMP, columns.getInt(5)); + Assert.assertEquals(Types.TIMESTAMP, columns.getInt("DATA_TYPE")); + // TYPE_NAME + Assert.assertEquals("TYPE_NAME", meta.getColumnLabel(6)); + Assert.assertEquals("TIMESTAMP", columns.getString(6)); + Assert.assertEquals("TIMESTAMP", columns.getString("TYPE_NAME")); + // COLUMN_SIZE + Assert.assertEquals("COLUMN_SIZE", meta.getColumnLabel(7)); + Assert.assertEquals(26, columns.getInt(7)); + Assert.assertEquals(26, columns.getInt("COLUMN_SIZE")); + // DECIMAL_DIGITS + Assert.assertEquals("DECIMAL_DIGITS", meta.getColumnLabel(9)); + Assert.assertEquals(Integer.MIN_VALUE, columns.getInt(9)); + Assert.assertEquals(Integer.MIN_VALUE, columns.getInt("DECIMAL_DIGITS")); + Assert.assertEquals(null, columns.getString(9)); + Assert.assertEquals(null, columns.getString("DECIMAL_DIGITS")); + // NUM_PREC_RADIX + Assert.assertEquals("NUM_PREC_RADIX", meta.getColumnLabel(10)); + Assert.assertEquals(10, columns.getInt(10)); + Assert.assertEquals(10, columns.getInt("NUM_PREC_RADIX")); + // NULLABLE + Assert.assertEquals("NULLABLE", meta.getColumnLabel(11)); + Assert.assertEquals(DatabaseMetaData.columnNoNulls, columns.getInt(11)); + Assert.assertEquals(DatabaseMetaData.columnNoNulls, columns.getInt("NULLABLE")); + // REMARKS + Assert.assertEquals("REMARKS", meta.getColumnLabel(12)); + Assert.assertEquals(null, columns.getString(12)); + Assert.assertEquals(null, columns.getString("REMARKS")); + } + columns.next(); + // column: 2 + { + // TABLE_CAT + Assert.assertEquals("TABLE_CAT", meta.getColumnLabel(1)); + Assert.assertEquals("log", columns.getString(1)); + Assert.assertEquals("log", columns.getString("TABLE_CAT")); + // TABLE_NAME + Assert.assertEquals("TABLE_NAME", meta.getColumnLabel(3)); + Assert.assertEquals("dn", columns.getString(3)); + Assert.assertEquals("dn", columns.getString("TABLE_NAME")); + // COLUMN_NAME + Assert.assertEquals("COLUMN_NAME", meta.getColumnLabel(4)); + Assert.assertEquals("cpu_taosd", columns.getString(4)); + Assert.assertEquals("cpu_taosd", columns.getString("COLUMN_NAME")); + // DATA_TYPE + Assert.assertEquals("DATA_TYPE", meta.getColumnLabel(5)); + Assert.assertEquals(Types.FLOAT, columns.getInt(5)); + Assert.assertEquals(Types.FLOAT, columns.getInt("DATA_TYPE")); + // TYPE_NAME + Assert.assertEquals("TYPE_NAME", meta.getColumnLabel(6)); + Assert.assertEquals("FLOAT", columns.getString(6)); + Assert.assertEquals("FLOAT", columns.getString("TYPE_NAME")); + // COLUMN_SIZE + Assert.assertEquals("COLUMN_SIZE", meta.getColumnLabel(7)); + Assert.assertEquals(12, columns.getInt(7)); + Assert.assertEquals(12, columns.getInt("COLUMN_SIZE")); + // DECIMAL_DIGITS + Assert.assertEquals("DECIMAL_DIGITS", meta.getColumnLabel(9)); + Assert.assertEquals(Integer.MIN_VALUE, columns.getInt(9)); + Assert.assertEquals(Integer.MIN_VALUE, columns.getInt("DECIMAL_DIGITS")); + Assert.assertEquals(null, columns.getString(9)); + Assert.assertEquals(null, columns.getString("DECIMAL_DIGITS")); + // NUM_PREC_RADIX + Assert.assertEquals("NUM_PREC_RADIX", meta.getColumnLabel(10)); + Assert.assertEquals(10, columns.getInt(10)); + Assert.assertEquals(10, columns.getInt("NUM_PREC_RADIX")); + // NULLABLE + Assert.assertEquals("NULLABLE", meta.getColumnLabel(11)); + Assert.assertEquals(DatabaseMetaData.columnNullable, columns.getInt(11)); + Assert.assertEquals(DatabaseMetaData.columnNullable, columns.getInt("NULLABLE")); + // REMARKS + Assert.assertEquals("REMARKS", meta.getColumnLabel(12)); + Assert.assertEquals(null, columns.getString(12)); } } @@ -712,17 +813,35 @@ public class TSDBDatabaseMetaDataTest { @Test public void getPrimaryKeys() throws SQLException { - System.out.println("****************************************************"); - ResultSet rs = metaData.getPrimaryKeys("log", "", "dn1"); - while (rs.next()) { - System.out.println("TABLE_NAME: " + rs.getString("TABLE_NAME")); - System.out.println("COLUMN_NAME: " + rs.getString("COLUMN_NAME")); - System.out.println("KEY_SEQ: " + rs.getString("KEY_SEQ")); - System.out.println("PK_NAME: " + rs.getString("PK_NAME")); + ResultSetMetaData meta = rs.getMetaData(); + rs.next(); + { + // TABLE_CAT + Assert.assertEquals("TABLE_CAT", meta.getColumnLabel(1)); + Assert.assertEquals("log", rs.getString(1)); + Assert.assertEquals("log", rs.getString("TABLE_CAT")); + // TABLE_SCHEM + Assert.assertEquals("TABLE_SCHEM", meta.getColumnLabel(2)); + Assert.assertEquals(null, rs.getString(2)); + Assert.assertEquals(null, rs.getString("TABLE_SCHEM")); + // TABLE_NAME + Assert.assertEquals("TABLE_NAME", meta.getColumnLabel(3)); + Assert.assertEquals("dn1", rs.getString(3)); + Assert.assertEquals("dn1", rs.getString("TABLE_NAME")); + // COLUMN_NAME + Assert.assertEquals("COLUMN_NAME", meta.getColumnLabel(4)); + Assert.assertEquals("ts", rs.getString(4)); + Assert.assertEquals("ts", rs.getString("COLUMN_NAME")); + // KEY_SEQ + Assert.assertEquals("KEY_SEQ", meta.getColumnLabel(5)); + Assert.assertEquals(1, rs.getShort(5)); + Assert.assertEquals(1, rs.getShort("KEY_SEQ")); + // DATA_TYPE + Assert.assertEquals("PK_NAME", meta.getColumnLabel(6)); + Assert.assertEquals("ts", rs.getString(6)); + Assert.assertEquals("ts", rs.getString("PK_NAME")); } - - Assert.assertNotNull(rs); } @Test @@ -847,14 +966,27 @@ public class TSDBDatabaseMetaDataTest { @Test public void getSuperTables() throws SQLException { - System.out.println("****************************************************"); - ResultSet rs = metaData.getSuperTables("log", "", "dn1"); - while (rs.next()) { - System.out.println("TABLE_NAME: " + rs.getString("TABLE_NAME")); - System.out.println("SUPERTABLE_NAME: " + rs.getString("SUPERTABLE_NAME")); + ResultSetMetaData meta = rs.getMetaData(); + rs.next(); + { + // TABLE_CAT + Assert.assertEquals("TABLE_CAT", meta.getColumnLabel(1)); + Assert.assertEquals("log", rs.getString(1)); + Assert.assertEquals("log", rs.getString("TABLE_CAT")); + // TABLE_CAT + Assert.assertEquals("TABLE_SCHEM", meta.getColumnLabel(2)); + Assert.assertEquals(null, rs.getString(2)); + Assert.assertEquals(null, rs.getString("TABLE_SCHEM")); + // TABLE_CAT + Assert.assertEquals("TABLE_NAME", meta.getColumnLabel(3)); + Assert.assertEquals("dn1", rs.getString(3)); + Assert.assertEquals("dn1", rs.getString("TABLE_NAME")); + // TABLE_CAT + Assert.assertEquals("SUPERTABLE_NAME", meta.getColumnLabel(4)); + Assert.assertEquals("dn", rs.getString(4)); + Assert.assertEquals("dn", rs.getString("SUPERTABLE_NAME")); } - Assert.assertNotNull(rs); } @Test @@ -951,15 +1083,12 @@ public class TSDBDatabaseMetaDataTest { @BeforeClass public static void beforeClass() { try { - Class.forName("com.taosdata.jdbc.TSDBDriver"); Properties properties = new Properties(); properties.setProperty(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8"); properties.setProperty(TSDBDriver.PROPERTY_KEY_LOCALE, "en_US.UTF-8"); properties.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8"); - connection = DriverManager.getConnection("jdbc:TAOS://" + host + ":6030/?user=root&password=taosdata", properties); + connection = DriverManager.getConnection(url, properties); metaData = connection.getMetaData().unwrap(TSDBDatabaseMetaData.class); - } catch (ClassNotFoundException e) { - e.printStackTrace(); } catch (SQLException e) { e.printStackTrace(); } diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBJNIConnectorTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBJNIConnectorTest.java index 161539962da5e26e928a669083954cc0817483a2..66078ef5036d7105ae9882508b635819bac99089 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBJNIConnectorTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBJNIConnectorTest.java @@ -45,9 +45,9 @@ public class TSDBJNIConnectorTest { rowData = new TSDBResultSetRowData(columnSize); // iterate resultSet for (int i = 0; next(connector, pSql); i++) { - System.out.println("col[" + i + "] size: " + rowData.getColSize()); - rowData.getData().stream().forEach(col -> System.out.print(col + "\t")); - System.out.println(); +// System.out.println("col[" + i + "] size: " + rowData.getColSize()); +// rowData.getData().stream().forEach(col -> System.out.print(col + "\t")); +// System.out.println(); } // close resultSet code = connector.freeResultSet(pSql); diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBParameterMetaDataTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBParameterMetaDataTest.java index 12bcc4391767e129289fae0a945d048570a18bc5..83caf1bebb72ec813683b083388e51b9dab2afc9 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBParameterMetaDataTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBParameterMetaDataTest.java @@ -54,16 +54,17 @@ public class TSDBParameterMetaDataTest { @Test public void getPrecision() throws SQLException { - Assert.assertEquals(0, parameterMetaData_insert.getPrecision(1)); - Assert.assertEquals(0, parameterMetaData_insert.getPrecision(2)); - Assert.assertEquals(0, parameterMetaData_insert.getPrecision(3)); - Assert.assertEquals(0, parameterMetaData_insert.getPrecision(4)); - Assert.assertEquals(0, parameterMetaData_insert.getPrecision(5)); - Assert.assertEquals(0, parameterMetaData_insert.getPrecision(6)); - Assert.assertEquals(0, parameterMetaData_insert.getPrecision(7)); - Assert.assertEquals(0, parameterMetaData_insert.getPrecision(8)); - Assert.assertEquals(5, parameterMetaData_insert.getPrecision(9)); - Assert.assertEquals(5, parameterMetaData_insert.getPrecision(10)); + //create table weather(ts timestamp, f1 int, f2 bigint, f3 float, f4 double, f5 smallint, f6 tinyint, f7 bool, f8 binary(64), f9 nchar(64)) + Assert.assertEquals(TSDBConstants.TIMESTAMP_MS_PRECISION, parameterMetaData_insert.getPrecision(1)); + Assert.assertEquals(TSDBConstants.INT_PRECISION, parameterMetaData_insert.getPrecision(2)); + Assert.assertEquals(TSDBConstants.BIGINT_PRECISION, parameterMetaData_insert.getPrecision(3)); + Assert.assertEquals(TSDBConstants.FLOAT_PRECISION, parameterMetaData_insert.getPrecision(4)); + Assert.assertEquals(TSDBConstants.DOUBLE_PRECISION, parameterMetaData_insert.getPrecision(5)); + Assert.assertEquals(TSDBConstants.SMALLINT_PRECISION, parameterMetaData_insert.getPrecision(6)); + Assert.assertEquals(TSDBConstants.TINYINT_PRECISION, parameterMetaData_insert.getPrecision(7)); + Assert.assertEquals(TSDBConstants.BOOLEAN_PRECISION, parameterMetaData_insert.getPrecision(8)); + Assert.assertEquals("hello".getBytes().length, parameterMetaData_insert.getPrecision(9)); + Assert.assertEquals("涛思数据".length(), parameterMetaData_insert.getPrecision(10)); } @Test @@ -71,8 +72,8 @@ public class TSDBParameterMetaDataTest { Assert.assertEquals(0, parameterMetaData_insert.getScale(1)); Assert.assertEquals(0, parameterMetaData_insert.getScale(2)); Assert.assertEquals(0, parameterMetaData_insert.getScale(3)); - Assert.assertEquals(0, parameterMetaData_insert.getScale(4)); - Assert.assertEquals(0, parameterMetaData_insert.getScale(5)); + Assert.assertEquals(31, parameterMetaData_insert.getScale(4)); + Assert.assertEquals(31, parameterMetaData_insert.getScale(5)); Assert.assertEquals(0, parameterMetaData_insert.getScale(6)); Assert.assertEquals(0, parameterMetaData_insert.getScale(7)); Assert.assertEquals(0, parameterMetaData_insert.getScale(8)); @@ -124,10 +125,16 @@ public class TSDBParameterMetaDataTest { @Test public void getParameterMode() throws SQLException { - for (int i = 1; i <= parameterMetaData_insert.getParameterCount(); i++) { - int parameterMode = parameterMetaData_insert.getParameterMode(i); - Assert.assertEquals(ParameterMetaData.parameterModeUnknown, parameterMode); - } + Assert.assertEquals(ParameterMetaData.parameterModeUnknown, parameterMetaData_insert.getParameterMode(1)); + Assert.assertEquals(ParameterMetaData.parameterModeUnknown, parameterMetaData_insert.getParameterMode(2)); + Assert.assertEquals(ParameterMetaData.parameterModeUnknown, parameterMetaData_insert.getParameterMode(3)); + Assert.assertEquals(ParameterMetaData.parameterModeUnknown, parameterMetaData_insert.getParameterMode(4)); + Assert.assertEquals(ParameterMetaData.parameterModeUnknown, parameterMetaData_insert.getParameterMode(5)); + Assert.assertEquals(ParameterMetaData.parameterModeUnknown, parameterMetaData_insert.getParameterMode(6)); + Assert.assertEquals(ParameterMetaData.parameterModeUnknown, parameterMetaData_insert.getParameterMode(7)); + Assert.assertEquals(ParameterMetaData.parameterModeUnknown, parameterMetaData_insert.getParameterMode(8)); + Assert.assertEquals(ParameterMetaData.parameterModeUnknown, parameterMetaData_insert.getParameterMode(9)); + Assert.assertEquals(ParameterMetaData.parameterModeUnknown, parameterMetaData_insert.getParameterMode(10)); } @Test @@ -144,7 +151,6 @@ public class TSDBParameterMetaDataTest { @BeforeClass public static void beforeClass() { try { - Class.forName("com.taosdata.jdbc.TSDBDriver"); conn = DriverManager.getConnection("jdbc:TAOS://" + host + ":6030/?user=root&password=taosdata"); try (Statement stmt = conn.createStatement()) { stmt.execute("drop database if exists test_pstmt"); @@ -164,7 +170,7 @@ public class TSDBParameterMetaDataTest { pstmt_insert.setObject(7, Byte.MAX_VALUE); pstmt_insert.setObject(8, true); pstmt_insert.setObject(9, "hello".getBytes()); - pstmt_insert.setObject(10, "Hello"); + pstmt_insert.setObject(10, "涛思数据"); parameterMetaData_insert = pstmt_insert.getParameterMetaData(); pstmt_select = conn.prepareStatement(sql_select); @@ -173,7 +179,7 @@ public class TSDBParameterMetaDataTest { pstmt_select.setInt(3, 0); parameterMetaData_select = pstmt_select.getParameterMetaData(); - } catch (ClassNotFoundException | SQLException e) { + } catch (SQLException e) { e.printStackTrace(); } } diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBPreparedStatementTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBPreparedStatementTest.java index 277ca447f5efcead8cf3b1d6a3d32017aac3036d..3f8bef4a7ea00915925b2924b08ad8c453420416 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBPreparedStatementTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBPreparedStatementTest.java @@ -1,102 +1,301 @@ package com.taosdata.jdbc; -import org.junit.AfterClass; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.*; import java.io.IOException; -import java.io.Serializable; +import java.math.BigDecimal; import java.sql.*; +import java.time.LocalTime; import java.util.ArrayList; import java.util.Random; public class TSDBPreparedStatementTest { + private static final String host = "127.0.0.1"; private static Connection conn; private static final String sql_insert = "insert into t1 values(?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; - private static PreparedStatement pstmt_insert; - private static final String sql_select = "select * from t1 where ts > ? and ts <= ? and f1 >= ?"; - private static PreparedStatement pstmt_select; + private static final String sql_select = "select * from t1 where ts >= ? and ts < ? and f1 >= ?"; + + private PreparedStatement pstmt_insert; + private PreparedStatement pstmt_select; + //create table weather(ts timestamp, f1 int, f2 bigint, f3 float, f4 double, f5 smallint, f6 tinyint, f7 bool, f8 binary(64), f9 nchar(64)) tags(loc nchar(64)) @Test public void executeQuery() throws SQLException { - long end = System.currentTimeMillis(); - long start = end - 1000 * 60 * 60; + // given + long ts = System.currentTimeMillis(); + pstmt_insert.setTimestamp(1, new Timestamp(ts)); + pstmt_insert.setInt(2, 2); + pstmt_insert.setLong(3, 3l); + pstmt_insert.setFloat(4, 3.14f); + pstmt_insert.setDouble(5, 3.1415); + pstmt_insert.setShort(6, (short) 6); + pstmt_insert.setByte(7, (byte) 7); + pstmt_insert.setBoolean(8, true); + pstmt_insert.setBytes(9, "abc".getBytes()); + pstmt_insert.setString(10, "涛思数据"); + pstmt_insert.executeUpdate(); + long start = ts - 1000 * 60 * 60; + long end = ts + 1000 * 60 * 60; pstmt_select.setTimestamp(1, new Timestamp(start)); pstmt_select.setTimestamp(2, new Timestamp(end)); pstmt_select.setInt(3, 0); + // when ResultSet rs = pstmt_select.executeQuery(); - Assert.assertNotNull(rs); ResultSetMetaData meta = rs.getMetaData(); - while (rs.next()) { - for (int i = 1; i <= meta.getColumnCount(); i++) { - System.out.print(meta.getColumnLabel(i) + ": " + rs.getString(i) + "\t"); - } - System.out.println(); + rs.next(); + + // then + assertMetaData(meta); + { + Assert.assertNotNull(rs); + Assert.assertEquals(ts, rs.getTimestamp(1).getTime()); + Assert.assertEquals(2, rs.getInt(2)); + Assert.assertEquals(2, rs.getInt("f1")); + Assert.assertEquals(3l, rs.getLong(3)); + Assert.assertEquals(3l, rs.getLong("f2")); + Assert.assertEquals(3.14f, rs.getFloat(4), 0.0); + Assert.assertEquals(3.14f, rs.getFloat("f3"), 0.0); + Assert.assertEquals(3.1415, rs.getDouble(5), 0.0); + Assert.assertEquals(3.1415, rs.getDouble("f4"), 0.0); + Assert.assertEquals((short) 6, rs.getShort(6)); + Assert.assertEquals((short) 6, rs.getShort("f5")); + Assert.assertEquals((byte) 7, rs.getByte(7)); + Assert.assertEquals((byte) 7, rs.getByte("f6")); + Assert.assertTrue(rs.getBoolean(8)); + Assert.assertTrue(rs.getBoolean("f7")); + Assert.assertArrayEquals("abc".getBytes(), rs.getBytes(9)); + Assert.assertArrayEquals("abc".getBytes(), rs.getBytes("f8")); + Assert.assertEquals("涛思数据", rs.getString(10)); + Assert.assertEquals("涛思数据", rs.getString("f9")); } } - @Test - public void executeUpdate() throws SQLException { - pstmt_insert.setTimestamp(1, new Timestamp(System.currentTimeMillis())); - pstmt_insert.setFloat(4, 3.14f); - int result = pstmt_insert.executeUpdate(); - Assert.assertEquals(1, result); + private void assertMetaData(ResultSetMetaData meta) throws SQLException { + Assert.assertEquals(10, meta.getColumnCount()); + Assert.assertEquals("ts", meta.getColumnLabel(1)); + Assert.assertEquals("f1", meta.getColumnLabel(2)); + Assert.assertEquals("f2", meta.getColumnLabel(3)); + Assert.assertEquals("f3", meta.getColumnLabel(4)); + Assert.assertEquals("f4", meta.getColumnLabel(5)); + Assert.assertEquals("f5", meta.getColumnLabel(6)); + Assert.assertEquals("f6", meta.getColumnLabel(7)); + Assert.assertEquals("f7", meta.getColumnLabel(8)); + Assert.assertEquals("f8", meta.getColumnLabel(9)); + Assert.assertEquals("f9", meta.getColumnLabel(10)); } @Test - public void setNull() throws SQLException { - pstmt_insert.setTimestamp(1, new Timestamp(System.currentTimeMillis())); + public void setNullForTimestamp() throws SQLException { + // given + long ts = System.currentTimeMillis(); + + // when + pstmt_insert.setTimestamp(1, new Timestamp(ts)); pstmt_insert.setNull(2, Types.INTEGER); int result = pstmt_insert.executeUpdate(); + + // then Assert.assertEquals(1, result); + try (Statement stmt = conn.createStatement()) { + ResultSet rs = stmt.executeQuery("select * from t1"); + ResultSetMetaData meta = rs.getMetaData(); + assertMetaData(meta); + rs.next(); + assertAllNullExceptTimestamp(rs, ts); + } + } - pstmt_insert.setTimestamp(1, new Timestamp(System.currentTimeMillis())); + private void assertAllNullExceptTimestamp(ResultSet rs, long ts) throws SQLException { + Assert.assertNotNull(rs); + Assert.assertEquals(ts, rs.getTimestamp(1).getTime()); + Assert.assertEquals(0, rs.getInt(2)); + Assert.assertEquals(0, rs.getInt("f1")); + Assert.assertEquals(0, rs.getLong(3)); + Assert.assertEquals(0, rs.getLong("f2")); + Assert.assertEquals(0, rs.getFloat(4), 0.0); + Assert.assertEquals(0, rs.getFloat("f3"), 0.0); + Assert.assertEquals(0, rs.getDouble(5), 0.0); + Assert.assertEquals(0, rs.getDouble("f4"), 0.0); + Assert.assertEquals(0, rs.getShort(6)); + Assert.assertEquals(0, rs.getShort("f5")); + Assert.assertEquals(0, rs.getByte(7)); + Assert.assertEquals(0, rs.getByte("f6")); + Assert.assertFalse(rs.getBoolean(8)); + Assert.assertFalse(rs.getBoolean("f7")); + Assert.assertNull(rs.getBytes(9)); + Assert.assertNull(rs.getBytes("f8")); + Assert.assertNull(rs.getString(10)); + Assert.assertNull(rs.getString("f9")); + } + + @Test + public void setNullForInteger() throws SQLException { + // given + long ts = System.currentTimeMillis(); + + // when + pstmt_insert.setTimestamp(1, new Timestamp(ts)); pstmt_insert.setNull(3, Types.BIGINT); - result = pstmt_insert.executeUpdate(); + int result = pstmt_insert.executeUpdate(); + + // then Assert.assertEquals(1, result); + try (Statement stmt = conn.createStatement()) { + ResultSet rs = stmt.executeQuery("select * from t1"); + ResultSetMetaData meta = rs.getMetaData(); + assertMetaData(meta); + rs.next(); + assertAllNullExceptTimestamp(rs, ts); + } + } - pstmt_insert.setTimestamp(1, new Timestamp(System.currentTimeMillis())); + @Test + public void setNullForFloat() throws SQLException { + // given + long ts = System.currentTimeMillis(); + + // when + pstmt_insert.setTimestamp(1, new Timestamp(ts)); pstmt_insert.setNull(4, Types.FLOAT); - result = pstmt_insert.executeUpdate(); + int result = pstmt_insert.executeUpdate(); + + // then Assert.assertEquals(1, result); + try (Statement stmt = conn.createStatement()) { + ResultSet rs = stmt.executeQuery("select * from t1"); + ResultSetMetaData meta = rs.getMetaData(); + assertMetaData(meta); + rs.next(); + assertAllNullExceptTimestamp(rs, ts); + } + } - pstmt_insert.setTimestamp(1, new Timestamp(System.currentTimeMillis())); + @Test + public void setNullForDouble() throws SQLException { + // given + long ts = System.currentTimeMillis(); + + // when + pstmt_insert.setTimestamp(1, new Timestamp(ts)); pstmt_insert.setNull(5, Types.DOUBLE); - result = pstmt_insert.executeUpdate(); + int result = pstmt_insert.executeUpdate(); + + // then Assert.assertEquals(1, result); + try (Statement stmt = conn.createStatement()) { + ResultSet rs = stmt.executeQuery("select * from t1"); + ResultSetMetaData meta = rs.getMetaData(); + assertMetaData(meta); + rs.next(); + assertAllNullExceptTimestamp(rs, ts); + } + } - pstmt_insert.setTimestamp(1, new Timestamp(System.currentTimeMillis())); + @Test + public void setNullForSmallInt() throws SQLException { + // given + long ts = System.currentTimeMillis(); + + // when + pstmt_insert.setTimestamp(1, new Timestamp(ts)); pstmt_insert.setNull(6, Types.SMALLINT); - result = pstmt_insert.executeUpdate(); + int result = pstmt_insert.executeUpdate(); + + // then Assert.assertEquals(1, result); + try (Statement stmt = conn.createStatement()) { + ResultSet rs = stmt.executeQuery("select * from t1"); + ResultSetMetaData meta = rs.getMetaData(); + assertMetaData(meta); + rs.next(); + assertAllNullExceptTimestamp(rs, ts); + } + } - pstmt_insert.setTimestamp(1, new Timestamp(System.currentTimeMillis())); + @Test + public void setNullForTinyInt() throws SQLException { + // given + long ts = System.currentTimeMillis(); + + // when + pstmt_insert.setTimestamp(1, new Timestamp(ts)); pstmt_insert.setNull(7, Types.TINYINT); - result = pstmt_insert.executeUpdate(); + int result = pstmt_insert.executeUpdate(); + + // then Assert.assertEquals(1, result); + try (Statement stmt = conn.createStatement()) { + ResultSet rs = stmt.executeQuery("select * from t1"); + ResultSetMetaData meta = rs.getMetaData(); + assertMetaData(meta); + rs.next(); + assertAllNullExceptTimestamp(rs, ts); + } + } - pstmt_insert.setTimestamp(1, new Timestamp(System.currentTimeMillis())); + @Test + public void setNullForBoolean() throws SQLException { + // given + long ts = System.currentTimeMillis(); + + // when + pstmt_insert.setTimestamp(1, new Timestamp(ts)); pstmt_insert.setNull(8, Types.BOOLEAN); - result = pstmt_insert.executeUpdate(); + int result = pstmt_insert.executeUpdate(); + + // then Assert.assertEquals(1, result); + try (Statement stmt = conn.createStatement()) { + ResultSet rs = stmt.executeQuery("select * from t1"); + ResultSetMetaData meta = rs.getMetaData(); + assertMetaData(meta); + rs.next(); + assertAllNullExceptTimestamp(rs, ts); + } + } - pstmt_insert.setTimestamp(1, new Timestamp(System.currentTimeMillis())); + @Test + public void setNullForBinary() throws SQLException { + // given + long ts = System.currentTimeMillis(); + + // when + pstmt_insert.setTimestamp(1, new Timestamp(ts)); pstmt_insert.setNull(9, Types.BINARY); - result = pstmt_insert.executeUpdate(); + int result = pstmt_insert.executeUpdate(); + + // then Assert.assertEquals(1, result); + try (Statement stmt = conn.createStatement()) { + ResultSet rs = stmt.executeQuery("select * from t1"); + ResultSetMetaData meta = rs.getMetaData(); + assertMetaData(meta); + rs.next(); + assertAllNullExceptTimestamp(rs, ts); + } + } - pstmt_insert.setTimestamp(1, new Timestamp(System.currentTimeMillis())); + @Test + public void setNullForNchar() throws SQLException { + // given + long ts = System.currentTimeMillis(); + + // when + pstmt_insert.setTimestamp(1, new Timestamp(ts)); pstmt_insert.setNull(10, Types.NCHAR); - result = pstmt_insert.executeUpdate(); - Assert.assertEquals(1, result); + int result = pstmt_insert.executeUpdate(); - pstmt_insert.setTimestamp(1, new Timestamp(System.currentTimeMillis())); - pstmt_insert.setNull(10, Types.OTHER); - result = pstmt_insert.executeUpdate(); + // then Assert.assertEquals(1, result); + try (Statement stmt = conn.createStatement()) { + ResultSet rs = stmt.executeQuery("select * from t1"); + ResultSetMetaData meta = rs.getMetaData(); + assertMetaData(meta); + rs.next(); + assertAllNullExceptTimestamp(rs, ts); + } } @Test @@ -388,136 +587,358 @@ public class TSDBPreparedStatementTest { Assert.assertEquals(numOfRows, rows); } - + + @Test + public void createTwoSameDbTest() throws SQLException { + Statement stmt = conn.createStatement(); + + stmt.execute("create database dbtest"); + Assert.assertThrows(SQLException.class, () -> stmt.execute("create database dbtest")); + } + @Test public void setBoolean() throws SQLException { - pstmt_insert.setTimestamp(1, new Timestamp(System.currentTimeMillis())); + // given + long ts = System.currentTimeMillis(); + + // when + pstmt_insert.setTimestamp(1, new Timestamp(ts)); pstmt_insert.setBoolean(8, true); - int ret = pstmt_insert.executeUpdate(); - Assert.assertEquals(1, ret); + int result = pstmt_insert.executeUpdate(); + + // then + Assert.assertEquals(1, result); + try (Statement stmt = conn.createStatement()) { + ResultSet rs = stmt.executeQuery("select * from t1"); + ResultSetMetaData meta = rs.getMetaData(); + assertMetaData(meta); + rs.next(); + { + Assert.assertNotNull(rs); + Assert.assertEquals(ts, rs.getTimestamp(1).getTime()); + Assert.assertEquals(ts, rs.getTimestamp("ts").getTime()); + Assert.assertTrue(rs.getBoolean(8)); + Assert.assertTrue(rs.getBoolean("f7")); + } + } } @Test public void setByte() throws SQLException { - pstmt_insert.setTimestamp(1, new Timestamp(System.currentTimeMillis())); + // given + long ts = System.currentTimeMillis(); + + // when + pstmt_insert.setTimestamp(1, new Timestamp(ts)); pstmt_insert.setByte(7, (byte) 0x001); - int ret = pstmt_insert.executeUpdate(); - Assert.assertEquals(1, ret); + int result = pstmt_insert.executeUpdate(); + + // then + Assert.assertEquals(1, result); + try (Statement stmt = conn.createStatement()) { + ResultSet rs = stmt.executeQuery("select * from t1"); + ResultSetMetaData meta = rs.getMetaData(); + assertMetaData(meta); + rs.next(); + { + Assert.assertNotNull(rs); + Assert.assertEquals(ts, rs.getTimestamp(1).getTime()); + Assert.assertEquals(ts, rs.getTimestamp("ts").getTime()); + Assert.assertEquals((byte) 0x001, rs.getByte(7)); + Assert.assertEquals((byte) 0x001, rs.getByte("f6")); + } + } } @Test public void setShort() throws SQLException { - pstmt_insert.setTimestamp(1, new Timestamp(System.currentTimeMillis())); + // given + long ts = System.currentTimeMillis(); + + // when + pstmt_insert.setTimestamp(1, new Timestamp(ts)); pstmt_insert.setShort(6, (short) 2); - int ret = pstmt_insert.executeUpdate(); - Assert.assertEquals(1, ret); + int result = pstmt_insert.executeUpdate(); + + // then + Assert.assertEquals(1, result); + try (Statement stmt = conn.createStatement()) { + ResultSet rs = stmt.executeQuery("select * from t1"); + ResultSetMetaData meta = rs.getMetaData(); + assertMetaData(meta); + rs.next(); + { + Assert.assertNotNull(rs); + Assert.assertEquals(ts, rs.getTimestamp(1).getTime()); + Assert.assertEquals(ts, rs.getTimestamp("ts").getTime()); + Assert.assertEquals((short) 2, rs.getByte(6)); + Assert.assertEquals((short) 2, rs.getByte("f5")); + } + } } @Test public void setInt() throws SQLException { - pstmt_insert.setTimestamp(1, new Timestamp(System.currentTimeMillis())); + // given + long ts = System.currentTimeMillis(); + + // when + pstmt_insert.setTimestamp(1, new Timestamp(ts)); pstmt_insert.setInt(2, 10086); - int ret = pstmt_insert.executeUpdate(); - Assert.assertEquals(1, ret); + int result = pstmt_insert.executeUpdate(); + + // then + Assert.assertEquals(1, result); + try (Statement stmt = conn.createStatement()) { + ResultSet rs = stmt.executeQuery("select * from t1"); + ResultSetMetaData meta = rs.getMetaData(); + assertMetaData(meta); + rs.next(); + { + Assert.assertNotNull(rs); + Assert.assertEquals(ts, rs.getTimestamp(1).getTime()); + Assert.assertEquals(ts, rs.getTimestamp("ts").getTime()); + Assert.assertEquals(10086, rs.getInt(2)); + Assert.assertEquals(10086, rs.getInt("f1")); + } + } } @Test public void setLong() throws SQLException { - pstmt_insert.setTimestamp(1, new Timestamp(System.currentTimeMillis())); + // given + long ts = System.currentTimeMillis(); + + // when + pstmt_insert.setTimestamp(1, new Timestamp(ts)); pstmt_insert.setLong(3, Long.MAX_VALUE); - int ret = pstmt_insert.executeUpdate(); - Assert.assertEquals(1, ret); + int result = pstmt_insert.executeUpdate(); + + // then + Assert.assertEquals(1, result); + try (Statement stmt = conn.createStatement()) { + ResultSet rs = stmt.executeQuery("select * from t1"); + ResultSetMetaData meta = rs.getMetaData(); + assertMetaData(meta); + rs.next(); + { + Assert.assertNotNull(rs); + Assert.assertEquals(ts, rs.getTimestamp(1).getTime()); + Assert.assertEquals(ts, rs.getTimestamp("ts").getTime()); + Assert.assertEquals(Long.MAX_VALUE, rs.getLong(3)); + Assert.assertEquals(Long.MAX_VALUE, rs.getLong("f2")); + } + } } @Test public void setFloat() throws SQLException { - pstmt_insert.setTimestamp(1, new Timestamp(System.currentTimeMillis())); + // given + long ts = System.currentTimeMillis(); + + // when + pstmt_insert.setTimestamp(1, new Timestamp(ts)); pstmt_insert.setFloat(4, 3.14f); - int ret = pstmt_insert.executeUpdate(); - Assert.assertEquals(1, ret); + int result = pstmt_insert.executeUpdate(); + + // then + Assert.assertEquals(1, result); + try (Statement stmt = conn.createStatement()) { + ResultSet rs = stmt.executeQuery("select * from t1"); + ResultSetMetaData meta = rs.getMetaData(); + assertMetaData(meta); + rs.next(); + { + Assert.assertNotNull(rs); + Assert.assertEquals(ts, rs.getTimestamp(1).getTime()); + Assert.assertEquals(ts, rs.getTimestamp("ts").getTime()); + Assert.assertEquals(3.14f, rs.getFloat(4), 0.0f); + Assert.assertEquals(3.14f, rs.getFloat("f3"), 0.0f); + } + } } @Test public void setDouble() throws SQLException { - pstmt_insert.setTimestamp(1, new Timestamp(System.currentTimeMillis())); + // given + long ts = System.currentTimeMillis(); + + // when + pstmt_insert.setTimestamp(1, new Timestamp(ts)); pstmt_insert.setDouble(5, 3.14444); - int ret = pstmt_insert.executeUpdate(); - Assert.assertEquals(1, ret); - } + int result = pstmt_insert.executeUpdate(); - @Test(expected = SQLFeatureNotSupportedException.class) - public void setBigDecimal() throws SQLException { - pstmt_insert.setBigDecimal(1, null); + // then + Assert.assertEquals(1, result); + try (Statement stmt = conn.createStatement()) { + ResultSet rs = stmt.executeQuery("select * from t1"); + ResultSetMetaData meta = rs.getMetaData(); + assertMetaData(meta); + rs.next(); + { + Assert.assertNotNull(rs); + Assert.assertEquals(ts, rs.getTimestamp(1).getTime()); + Assert.assertEquals(ts, rs.getTimestamp("ts").getTime()); + Assert.assertEquals(3.14444, rs.getDouble(5), 0.0); + Assert.assertEquals(3.14444, rs.getDouble("f4"), 0.0); + } + } } @Test - public void setString() throws SQLException { - pstmt_insert.setTimestamp(1, new Timestamp(System.currentTimeMillis())); - pstmt_insert.setString(10, "aaaa"); - boolean execute = pstmt_insert.execute(); - Assert.assertFalse(execute); + public void setBigDecimal() throws SQLException { + // given + long ts = System.currentTimeMillis(); + BigDecimal bigDecimal = new BigDecimal(3.14444); - pstmt_insert.setTimestamp(1, new Timestamp(System.currentTimeMillis())); - pstmt_insert.setString(10, new Person("john", 33, true).toString()); - Assert.assertFalse(pstmt_insert.execute()); + // when + pstmt_insert.setTimestamp(1, new Timestamp(ts)); + pstmt_insert.setBigDecimal(5, bigDecimal); + int result = pstmt_insert.executeUpdate(); - pstmt_insert.setTimestamp(1, new Timestamp(System.currentTimeMillis())); - pstmt_insert.setString(10, new Person("john", 33, true).toString().replaceAll("'", "\"")); - Assert.assertFalse(pstmt_insert.execute()); + // then + Assert.assertEquals(1, result); + try (Statement stmt = conn.createStatement()) { + ResultSet rs = stmt.executeQuery("select * from t1"); + ResultSetMetaData meta = rs.getMetaData(); + assertMetaData(meta); + rs.next(); + { + Assert.assertNotNull(rs); + Assert.assertEquals(ts, rs.getTimestamp(1).getTime()); + Assert.assertEquals(ts, rs.getTimestamp("ts").getTime()); + Assert.assertEquals(3.14444, rs.getDouble(5), 0.0); + Assert.assertEquals(3.14444, rs.getDouble("f4"), 0.0); + } + } } - class Person { - String name; - int age; - boolean sex; + @Test + public void setString() throws SQLException { + // given + long ts = System.currentTimeMillis(); + String f9 = "{\"name\": \"john\", \"age\": 10, \"address\": \"192.168.1.100\"}"; - public Person(String name, int age, boolean sex) { - this.name = name; - this.age = age; - this.sex = sex; - } + // when + pstmt_insert.setTimestamp(1, new Timestamp(ts)); + pstmt_insert.setString(10, f9); + int result = pstmt_insert.executeUpdate(); - @Override - public String toString() { - return "Person{" + - "name='" + name + '\'' + - ", age=" + age + - ", sex=" + sex + - '}'; + // then + Assert.assertEquals(1, result); + try (Statement stmt = conn.createStatement()) { + ResultSet rs = stmt.executeQuery("select * from t1"); + ResultSetMetaData meta = rs.getMetaData(); + assertMetaData(meta); + rs.next(); + { + Assert.assertNotNull(rs); + Assert.assertEquals(ts, rs.getTimestamp(1).getTime()); + Assert.assertEquals(ts, rs.getTimestamp("ts").getTime()); + Assert.assertEquals(f9, rs.getString(10)); + Assert.assertEquals(f9, rs.getString("f9")); + } } } @Test public void setBytes() throws SQLException, IOException { - pstmt_insert.setTimestamp(1, new Timestamp(System.currentTimeMillis())); + // given + long ts = System.currentTimeMillis(); + byte[] f8 = "{\"name\": \"john\", \"age\": 10, \"address\": \"192.168.1.100\"}".getBytes(); -// ByteArrayOutputStream baos = new ByteArrayOutputStream(); -// ObjectOutputStream oos = new ObjectOutputStream(baos); -// oos.writeObject(new Person("john", 33, true)); -// oos.flush(); -// byte[] bytes = baos.toByteArray(); -// pstmt_insert.setBytes(9, bytes); + // when + pstmt_insert.setTimestamp(1, new Timestamp(System.currentTimeMillis())); + pstmt_insert.setBytes(9, f8); + int result = pstmt_insert.executeUpdate(); - pstmt_insert.setBytes(9, new Person("john", 33, true).toString().getBytes()); - int ret = pstmt_insert.executeUpdate(); - Assert.assertEquals(1, ret); + // then + Assert.assertEquals(1, result); + try (Statement stmt = conn.createStatement()) { + ResultSet rs = stmt.executeQuery("select * from t1"); + ResultSetMetaData meta = rs.getMetaData(); + assertMetaData(meta); + rs.next(); + { + Assert.assertNotNull(rs); + Assert.assertEquals(ts, rs.getTimestamp(1).getTime()); + Assert.assertEquals(ts, rs.getTimestamp("ts").getTime()); + Assert.assertArrayEquals(f8, rs.getBytes(9)); + Assert.assertArrayEquals(f8, rs.getBytes("f8")); + } + } } - @Test(expected = SQLFeatureNotSupportedException.class) + @Test public void setDate() throws SQLException { - pstmt_insert.setDate(1, new Date(System.currentTimeMillis())); + // given + long ts = new java.util.Date().getTime(); + + // when + pstmt_insert.setDate(1, new Date(ts)); + int result = pstmt_insert.executeUpdate(); + + // then + Assert.assertEquals(1, result); + try (Statement stmt = conn.createStatement()) { + ResultSet rs = stmt.executeQuery("select * from t1"); + ResultSetMetaData meta = rs.getMetaData(); + assertMetaData(meta); + rs.next(); + { + Assert.assertNotNull(rs); + Assert.assertEquals(ts, rs.getTimestamp(1).getTime()); + Assert.assertEquals(ts, rs.getTimestamp("ts").getTime()); + } + } } - @Test(expected = SQLFeatureNotSupportedException.class) + @Test public void setTime() throws SQLException { - pstmt_insert.setTime(1, new Time(System.currentTimeMillis())); + // given + long ts = System.currentTimeMillis(); + + // when + pstmt_insert.setTime(1, new Time(ts)); + int result = pstmt_insert.executeUpdate(); + + // then + Assert.assertEquals(1, result); + try (Statement stmt = conn.createStatement()) { + ResultSet rs = stmt.executeQuery("select * from t1"); + ResultSetMetaData meta = rs.getMetaData(); + assertMetaData(meta); + rs.next(); + { + Assert.assertNotNull(rs); + Assert.assertEquals(ts, rs.getTimestamp(1).getTime()); + Assert.assertEquals(ts, rs.getTimestamp("ts").getTime()); + } + } } @Test public void setTimestamp() throws SQLException { - pstmt_insert.setTimestamp(1, new Timestamp(System.currentTimeMillis())); - int ret = pstmt_insert.executeUpdate(); - Assert.assertEquals(1, ret); + // given + long ts = System.currentTimeMillis(); + + // when + pstmt_insert.setTimestamp(1, new Timestamp(ts)); + int result = pstmt_insert.executeUpdate(); + + // then + Assert.assertEquals(1, result); + try (Statement stmt = conn.createStatement()) { + ResultSet rs = stmt.executeQuery("select * from t1"); + ResultSetMetaData meta = rs.getMetaData(); + assertMetaData(meta); + rs.next(); + { + Assert.assertNotNull(rs); + Assert.assertEquals(ts, rs.getTimestamp(1).getTime()); + Assert.assertEquals(ts, rs.getTimestamp("ts").getTime()); + } + } } @Test(expected = SQLFeatureNotSupportedException.class) @@ -530,72 +951,6 @@ public class TSDBPreparedStatementTest { pstmt_insert.setBinaryStream(1, null); } - @Test - public void clearParameters() throws SQLException { - pstmt_insert.clearParameters(); - } - - @Test - public void setObject() throws SQLException { - pstmt_insert.setObject(1, new Timestamp(System.currentTimeMillis())); - int ret = pstmt_insert.executeUpdate(); - Assert.assertEquals(1, ret); - - pstmt_insert.setTimestamp(1, new Timestamp(System.currentTimeMillis())); - pstmt_insert.setObject(2, 111); - ret = pstmt_insert.executeUpdate(); - Assert.assertEquals(1, ret); - - pstmt_insert.setTimestamp(1, new Timestamp(System.currentTimeMillis())); - pstmt_insert.setObject(3, Long.MAX_VALUE); - ret = pstmt_insert.executeUpdate(); - Assert.assertEquals(1, ret); - - pstmt_insert.setTimestamp(1, new Timestamp(System.currentTimeMillis())); - pstmt_insert.setObject(4, 3.14159265354f); - ret = pstmt_insert.executeUpdate(); - Assert.assertEquals(1, ret); - - pstmt_insert.setTimestamp(1, new Timestamp(System.currentTimeMillis())); - pstmt_insert.setObject(5, Double.MAX_VALUE); - ret = pstmt_insert.executeUpdate(); - Assert.assertEquals(1, ret); - - pstmt_insert.setTimestamp(1, new Timestamp(System.currentTimeMillis())); - pstmt_insert.setObject(6, Short.MAX_VALUE); - ret = pstmt_insert.executeUpdate(); - Assert.assertEquals(1, ret); - - pstmt_insert.setTimestamp(1, new Timestamp(System.currentTimeMillis())); - pstmt_insert.setObject(7, Byte.MAX_VALUE); - ret = pstmt_insert.executeUpdate(); - Assert.assertEquals(1, ret); - - pstmt_insert.setTimestamp(1, new Timestamp(System.currentTimeMillis())); - pstmt_insert.setObject(8, true); - ret = pstmt_insert.executeUpdate(); - Assert.assertEquals(1, ret); - - pstmt_insert.setTimestamp(1, new Timestamp(System.currentTimeMillis())); - pstmt_insert.setObject(9, "hello".getBytes()); - ret = pstmt_insert.executeUpdate(); - Assert.assertEquals(1, ret); - - pstmt_insert.setTimestamp(1, new Timestamp(System.currentTimeMillis())); - pstmt_insert.setObject(10, "Hello"); - ret = pstmt_insert.executeUpdate(); - Assert.assertEquals(1, ret); - } - - @Test - public void execute() throws SQLException { - pstmt_insert.setTimestamp(1, new Timestamp(System.currentTimeMillis())); - int ret = pstmt_insert.executeUpdate(); - Assert.assertEquals(1, ret); - - executeQuery(); - } - @Test(expected = SQLFeatureNotSupportedException.class) public void setCharacterStream() throws SQLException { pstmt_insert.setCharacterStream(1, null); @@ -621,9 +976,17 @@ public class TSDBPreparedStatementTest { pstmt_insert.setArray(1, null); } - @Test(expected = SQLFeatureNotSupportedException.class) + @Test public void getMetaData() throws SQLException { - pstmt_insert.getMetaData(); + // given + long ts = System.currentTimeMillis(); + + // when + pstmt_insert.setTimestamp(1, new Timestamp(ts)); + ResultSetMetaData metaData = pstmt_insert.getMetaData(); + + // then + Assert.assertNull(metaData); } @Test(expected = SQLFeatureNotSupportedException.class) @@ -633,9 +996,46 @@ public class TSDBPreparedStatementTest { @Test public void getParameterMetaData() throws SQLException { + // given + long ts = System.currentTimeMillis(); + pstmt_insert.setTimestamp(1, new Timestamp(ts)); + pstmt_insert.setInt(2, 2); + pstmt_insert.setLong(3, 3l); + pstmt_insert.setFloat(4, 3.14f); + pstmt_insert.setDouble(5, 3.1415); + pstmt_insert.setShort(6, (short) 6); + pstmt_insert.setByte(7, (byte) 7); + pstmt_insert.setBoolean(8, true); + pstmt_insert.setBytes(9, "abc".getBytes()); + pstmt_insert.setString(10, "涛思数据"); + + // when ParameterMetaData parameterMetaData = pstmt_insert.getParameterMetaData(); + + // then Assert.assertNotNull(parameterMetaData); - //TODO: modify the test case + Assert.assertEquals(10, parameterMetaData.getParameterCount()); + Assert.assertEquals(Types.TIMESTAMP, parameterMetaData.getParameterType(1)); + Assert.assertEquals(Types.INTEGER, parameterMetaData.getParameterType(2)); + Assert.assertEquals(Types.BIGINT, parameterMetaData.getParameterType(3)); + Assert.assertEquals(Types.FLOAT, parameterMetaData.getParameterType(4)); + Assert.assertEquals(Types.DOUBLE, parameterMetaData.getParameterType(5)); + Assert.assertEquals(Types.SMALLINT, parameterMetaData.getParameterType(6)); + Assert.assertEquals(Types.TINYINT, parameterMetaData.getParameterType(7)); + Assert.assertEquals(Types.BOOLEAN, parameterMetaData.getParameterType(8)); + Assert.assertEquals(Types.BINARY, parameterMetaData.getParameterType(9)); + Assert.assertEquals(Types.NCHAR, parameterMetaData.getParameterType(10)); + + Assert.assertEquals("TIMESTAMP", parameterMetaData.getParameterTypeName(1)); + Assert.assertEquals("INT", parameterMetaData.getParameterTypeName(2)); + Assert.assertEquals("BIGINT", parameterMetaData.getParameterTypeName(3)); + Assert.assertEquals("FLOAT", parameterMetaData.getParameterTypeName(4)); + Assert.assertEquals("DOUBLE", parameterMetaData.getParameterTypeName(5)); + Assert.assertEquals("SMALLINT", parameterMetaData.getParameterTypeName(6)); + Assert.assertEquals("TINYINT", parameterMetaData.getParameterTypeName(7)); + Assert.assertEquals("BOOL", parameterMetaData.getParameterTypeName(8)); + Assert.assertEquals("BINARY", parameterMetaData.getParameterTypeName(9)); + Assert.assertEquals("NCHAR", parameterMetaData.getParameterTypeName(10)); } @Test(expected = SQLFeatureNotSupportedException.class) @@ -643,9 +1043,9 @@ public class TSDBPreparedStatementTest { pstmt_insert.setRowId(1, null); } - @Test(expected = SQLFeatureNotSupportedException.class) + @Test public void setNString() throws SQLException { - pstmt_insert.setNString(1, null); + setString(); } @Test(expected = SQLFeatureNotSupportedException.class) @@ -663,22 +1063,45 @@ public class TSDBPreparedStatementTest { pstmt_insert.setSQLXML(1, null); } + @Before + public void before() { + try { + Statement stmt = conn.createStatement(); + stmt.execute("drop table if exists weather"); + stmt.execute("create table if not exists weather(ts timestamp, f1 int, f2 bigint, f3 float, f4 double, f5 smallint, f6 tinyint, f7 bool, f8 binary(64), f9 nchar(64)) tags(loc nchar(64))"); + stmt.execute("create table if not exists t1 using weather tags('beijing')"); + stmt.close(); + + pstmt_insert = conn.prepareStatement(sql_insert); + pstmt_select = conn.prepareStatement(sql_select); + } catch (SQLException e) { + e.printStackTrace(); + } + } + + @After + public void after() { + try { + if (pstmt_insert != null) + pstmt_insert.close(); + if (pstmt_select != null) + pstmt_select.close(); + } catch (SQLException e) { + e.printStackTrace(); + } + + } @BeforeClass public static void beforeClass() { try { - Class.forName("com.taosdata.jdbc.TSDBDriver"); conn = DriverManager.getConnection("jdbc:TAOS://" + host + ":6030/?user=root&password=taosdata"); try (Statement stmt = conn.createStatement()) { stmt.execute("drop database if exists test_pstmt_jni"); stmt.execute("create database if not exists test_pstmt_jni"); stmt.execute("use test_pstmt_jni"); - stmt.execute("create table weather(ts timestamp, f1 int, f2 bigint, f3 float, f4 double, f5 smallint, f6 tinyint, f7 bool, f8 binary(64), f9 nchar(64)) tags(loc nchar(64))"); - stmt.execute("create table t1 using weather tags('beijing')"); } - pstmt_insert = conn.prepareStatement(sql_insert); - pstmt_select = conn.prepareStatement(sql_select); - } catch (ClassNotFoundException | SQLException e) { + } catch (SQLException e) { e.printStackTrace(); } } @@ -686,10 +1109,6 @@ public class TSDBPreparedStatementTest { @AfterClass public static void afterClass() { try { - if (pstmt_insert != null) - pstmt_insert.close(); - if (pstmt_select != null) - pstmt_select.close(); if (conn != null) conn.close(); } catch (SQLException e) { diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBResultSetTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBResultSetTest.java index f304fd687406ccf919ea1b1e457cd218239e765f..ec54a44b7c889236676b65fea9fdf689b7207df9 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBResultSetTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBResultSetTest.java @@ -14,6 +14,7 @@ import java.math.BigDecimal; import java.sql.*; import java.text.ParseException; import java.text.SimpleDateFormat; +import java.util.Arrays; public class TSDBResultSetTest { @@ -133,7 +134,7 @@ public class TSDBResultSetTest { Assert.assertEquals(3.1415926, Double.valueOf(new String(f5)), 0.000000f); byte[] f6 = rs.getBytes("f6"); - Assert.assertEquals("abc", new String(f6)); + Assert.assertTrue(Arrays.equals("abc".getBytes(), f6)); byte[] f7 = rs.getBytes("f7"); Assert.assertEquals((short) 10, Shorts.fromByteArray(f7)); @@ -646,7 +647,6 @@ public class TSDBResultSetTest { @BeforeClass public static void beforeClass() { try { - Class.forName("com.taosdata.jdbc.TSDBDriver"); conn = DriverManager.getConnection("jdbc:TAOS://" + host + ":6030/?user=root&password=taosdata"); stmt = conn.createStatement(); stmt.execute("create database if not exists restful_test"); @@ -656,10 +656,9 @@ public class TSDBResultSetTest { stmt.execute("insert into restful_test.weather values('2021-01-01 00:00:00.000', 1, 100, 3.1415, 3.1415926, 'abc', 10, 10, true, '涛思数据')"); rs = stmt.executeQuery("select * from restful_test.weather"); rs.next(); - } catch (ClassNotFoundException | SQLException e) { + } catch (SQLException e) { e.printStackTrace(); } - } @AfterClass diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBStatementTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBStatementTest.java index 671551c42639620b09ace1ae315da6f25ea278d4..51535bc886aa0c3114a5a5bb74190300977a9ec9 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBStatementTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBStatementTest.java @@ -387,15 +387,12 @@ public class TSDBStatementTest { @BeforeClass public static void beforeClass() { try { - Class.forName("com.taosdata.jdbc.TSDBDriver"); Properties properties = new Properties(); properties.setProperty(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8"); properties.setProperty(TSDBDriver.PROPERTY_KEY_LOCALE, "en_US.UTF-8"); properties.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8"); conn = DriverManager.getConnection("jdbc:TAOS://" + host + ":6030/?user=root&password=taosdata", properties); stmt = conn.createStatement(); - } catch (ClassNotFoundException e) { - e.printStackTrace(); } catch (SQLException e) { e.printStackTrace(); } diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/RestfulDatabaseMetaDataTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/RestfulDatabaseMetaDataTest.java index a052fbbdcbc241a18cb7dd73b8b4ade053533541..85007db0e555634b25dee4f10446b1041bf19b21 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/RestfulDatabaseMetaDataTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/RestfulDatabaseMetaDataTest.java @@ -10,6 +10,7 @@ import java.sql.*; import java.util.Properties; public class RestfulDatabaseMetaDataTest { + private static final String host = "127.0.0.1"; private static final String url = "jdbc:TAOS-RS://" + host + ":6041/?user=root&password=taosdata"; private static Connection connection; @@ -632,17 +633,32 @@ public class RestfulDatabaseMetaDataTest { @Test public void getTables() throws SQLException { - System.out.println("****************************************************"); - ResultSet tables = metaData.getTables("log", "", null, null); - ResultSetMetaData metaData = tables.getMetaData(); - while (tables.next()) { - System.out.print(metaData.getColumnLabel(1) + ":" + tables.getString(1) + "\t"); - System.out.print(metaData.getColumnLabel(3) + ":" + tables.getString(3) + "\t"); - System.out.print(metaData.getColumnLabel(4) + ":" + tables.getString(4) + "\t"); - System.out.print(metaData.getColumnLabel(5) + ":" + tables.getString(5) + "\n"); + ResultSet rs = metaData.getTables("log", "", null, null); + ResultSetMetaData meta = rs.getMetaData(); + Assert.assertNotNull(rs); + rs.next(); + { + // TABLE_CAT + Assert.assertEquals("TABLE_CAT", meta.getColumnLabel(1)); + Assert.assertEquals("log", rs.getString(1)); + Assert.assertEquals("log", rs.getString("TABLE_CAT")); + // TABLE_SCHEM + Assert.assertEquals("TABLE_SCHEM", meta.getColumnLabel(2)); + Assert.assertEquals(null, rs.getString(2)); + Assert.assertEquals(null, rs.getString("TABLE_SCHEM")); + // TABLE_NAME + Assert.assertEquals("TABLE_NAME", meta.getColumnLabel(3)); + Assert.assertNotNull(rs.getString(3)); + Assert.assertNotNull(rs.getString("TABLE_NAME")); + // TABLE_TYPE + Assert.assertEquals("TABLE_TYPE", meta.getColumnLabel(4)); + Assert.assertEquals("TABLE", rs.getString(4)); + Assert.assertEquals("TABLE", rs.getString("TABLE_TYPE")); + // REMARKS + Assert.assertEquals("REMARKS", meta.getColumnLabel(5)); + Assert.assertEquals("", rs.getString(5)); + Assert.assertEquals("", rs.getString("REMARKS")); } - System.out.println(); - Assert.assertNotNull(tables); } @Test @@ -652,46 +668,130 @@ public class RestfulDatabaseMetaDataTest { @Test public void getCatalogs() throws SQLException { - System.out.println("****************************************************"); - - ResultSet catalogs = metaData.getCatalogs(); - ResultSetMetaData meta = catalogs.getMetaData(); - while (catalogs.next()) { - for (int i = 1; i <= meta.getColumnCount(); i++) { - System.out.print(meta.getColumnLabel(i) + ": " + catalogs.getString(i)); - } - System.out.println(); + ResultSet rs = metaData.getCatalogs(); + ResultSetMetaData meta = rs.getMetaData(); + rs.next(); + { + // TABLE_CAT + Assert.assertEquals("TABLE_CAT", meta.getColumnLabel(1)); + Assert.assertNotNull(rs.getString(1)); + Assert.assertNotNull(rs.getString("TABLE_CAT")); } } @Test public void getTableTypes() throws SQLException { - System.out.println("****************************************************"); - ResultSet tableTypes = metaData.getTableTypes(); - while (tableTypes.next()) { - System.out.println(tableTypes.getString("TABLE_TYPE")); + tableTypes.next(); + // tableTypes: table + { + Assert.assertEquals("TABLE", tableTypes.getString(1)); + Assert.assertEquals("TABLE", tableTypes.getString("TABLE_TYPE")); + } + tableTypes.next(); + // tableTypes: stable + { + Assert.assertEquals("STABLE", tableTypes.getString(1)); + Assert.assertEquals("STABLE", tableTypes.getString("TABLE_TYPE")); } - Assert.assertNotNull(metaData.getTableTypes()); } @Test public void getColumns() throws SQLException { - System.out.println("****************************************************"); - + // when ResultSet columns = metaData.getColumns("log", "", "dn", ""); + // then ResultSetMetaData meta = columns.getMetaData(); - while (columns.next()) { - System.out.print(meta.getColumnLabel(1) + ": " + columns.getString(1) + "\t"); - System.out.print(meta.getColumnLabel(3) + ": " + columns.getString(3) + "\t"); - System.out.print(meta.getColumnLabel(4) + ": " + columns.getString(4) + "\t"); - System.out.print(meta.getColumnLabel(5) + ": " + columns.getString(5) + "\t"); - System.out.print(meta.getColumnLabel(6) + ": " + columns.getString(6) + "\t"); - System.out.print(meta.getColumnLabel(7) + ": " + columns.getString(7) + "\t"); - System.out.print(meta.getColumnLabel(9) + ": " + columns.getString(9) + "\t"); - System.out.print(meta.getColumnLabel(10) + ": " + columns.getString(10) + "\t"); - System.out.print(meta.getColumnLabel(11) + ": " + columns.getString(11) + "\n"); - System.out.print(meta.getColumnLabel(12) + ": " + columns.getString(12) + "\n"); + columns.next(); + // column: 1 + { + // TABLE_CAT + Assert.assertEquals("TABLE_CAT", meta.getColumnLabel(1)); + Assert.assertEquals("log", columns.getString(1)); + Assert.assertEquals("log", columns.getString("TABLE_CAT")); + // TABLE_NAME + Assert.assertEquals("TABLE_NAME", meta.getColumnLabel(3)); + Assert.assertEquals("dn", columns.getString(3)); + Assert.assertEquals("dn", columns.getString("TABLE_NAME")); + // COLUMN_NAME + Assert.assertEquals("COLUMN_NAME", meta.getColumnLabel(4)); + Assert.assertEquals("ts", columns.getString(4)); + Assert.assertEquals("ts", columns.getString("COLUMN_NAME")); + // DATA_TYPE + Assert.assertEquals("DATA_TYPE", meta.getColumnLabel(5)); + Assert.assertEquals(Types.TIMESTAMP, columns.getInt(5)); + Assert.assertEquals(Types.TIMESTAMP, columns.getInt("DATA_TYPE")); + // TYPE_NAME + Assert.assertEquals("TYPE_NAME", meta.getColumnLabel(6)); + Assert.assertEquals("TIMESTAMP", columns.getString(6)); + Assert.assertEquals("TIMESTAMP", columns.getString("TYPE_NAME")); + // COLUMN_SIZE + Assert.assertEquals("COLUMN_SIZE", meta.getColumnLabel(7)); + Assert.assertEquals(26, columns.getInt(7)); + Assert.assertEquals(26, columns.getInt("COLUMN_SIZE")); + // DECIMAL_DIGITS + Assert.assertEquals("DECIMAL_DIGITS", meta.getColumnLabel(9)); + Assert.assertEquals(Integer.MIN_VALUE, columns.getInt(9)); + Assert.assertEquals(Integer.MIN_VALUE, columns.getInt("DECIMAL_DIGITS")); + Assert.assertEquals(null, columns.getString(9)); + Assert.assertEquals(null, columns.getString("DECIMAL_DIGITS")); + // NUM_PREC_RADIX + Assert.assertEquals("NUM_PREC_RADIX", meta.getColumnLabel(10)); + Assert.assertEquals(10, columns.getInt(10)); + Assert.assertEquals(10, columns.getInt("NUM_PREC_RADIX")); + // NULLABLE + Assert.assertEquals("NULLABLE", meta.getColumnLabel(11)); + Assert.assertEquals(DatabaseMetaData.columnNoNulls, columns.getInt(11)); + Assert.assertEquals(DatabaseMetaData.columnNoNulls, columns.getInt("NULLABLE")); + // REMARKS + Assert.assertEquals("REMARKS", meta.getColumnLabel(12)); + Assert.assertEquals(null, columns.getString(12)); + Assert.assertEquals(null, columns.getString("REMARKS")); + } + columns.next(); + // column: 2 + { + // TABLE_CAT + Assert.assertEquals("TABLE_CAT", meta.getColumnLabel(1)); + Assert.assertEquals("log", columns.getString(1)); + Assert.assertEquals("log", columns.getString("TABLE_CAT")); + // TABLE_NAME + Assert.assertEquals("TABLE_NAME", meta.getColumnLabel(3)); + Assert.assertEquals("dn", columns.getString(3)); + Assert.assertEquals("dn", columns.getString("TABLE_NAME")); + // COLUMN_NAME + Assert.assertEquals("COLUMN_NAME", meta.getColumnLabel(4)); + Assert.assertEquals("cpu_taosd", columns.getString(4)); + Assert.assertEquals("cpu_taosd", columns.getString("COLUMN_NAME")); + // DATA_TYPE + Assert.assertEquals("DATA_TYPE", meta.getColumnLabel(5)); + Assert.assertEquals(Types.FLOAT, columns.getInt(5)); + Assert.assertEquals(Types.FLOAT, columns.getInt("DATA_TYPE")); + // TYPE_NAME + Assert.assertEquals("TYPE_NAME", meta.getColumnLabel(6)); + Assert.assertEquals("FLOAT", columns.getString(6)); + Assert.assertEquals("FLOAT", columns.getString("TYPE_NAME")); + // COLUMN_SIZE + Assert.assertEquals("COLUMN_SIZE", meta.getColumnLabel(7)); + Assert.assertEquals(12, columns.getInt(7)); + Assert.assertEquals(12, columns.getInt("COLUMN_SIZE")); + // DECIMAL_DIGITS + Assert.assertEquals("DECIMAL_DIGITS", meta.getColumnLabel(9)); + Assert.assertEquals(Integer.MIN_VALUE, columns.getInt(9)); + Assert.assertEquals(Integer.MIN_VALUE, columns.getInt("DECIMAL_DIGITS")); + Assert.assertEquals(null, columns.getString(9)); + Assert.assertEquals(null, columns.getString("DECIMAL_DIGITS")); + // NUM_PREC_RADIX + Assert.assertEquals("NUM_PREC_RADIX", meta.getColumnLabel(10)); + Assert.assertEquals(10, columns.getInt(10)); + Assert.assertEquals(10, columns.getInt("NUM_PREC_RADIX")); + // NULLABLE + Assert.assertEquals("NULLABLE", meta.getColumnLabel(11)); + Assert.assertEquals(DatabaseMetaData.columnNullable, columns.getInt(11)); + Assert.assertEquals(DatabaseMetaData.columnNullable, columns.getInt("NULLABLE")); + // REMARKS + Assert.assertEquals("REMARKS", meta.getColumnLabel(12)); + Assert.assertEquals(null, columns.getString(12)); } } @@ -717,17 +817,35 @@ public class RestfulDatabaseMetaDataTest { @Test public void getPrimaryKeys() throws SQLException { - System.out.println("****************************************************"); - ResultSet rs = metaData.getPrimaryKeys("log", "", "dn1"); - while (rs.next()) { - System.out.println("TABLE_NAME: " + rs.getString("TABLE_NAME")); - System.out.println("COLUMN_NAME: " + rs.getString("COLUMN_NAME")); - System.out.println("KEY_SEQ: " + rs.getString("KEY_SEQ")); - System.out.println("PK_NAME: " + rs.getString("PK_NAME")); + ResultSetMetaData meta = rs.getMetaData(); + rs.next(); + { + // TABLE_CAT + Assert.assertEquals("TABLE_CAT", meta.getColumnLabel(1)); + Assert.assertEquals("log", rs.getString(1)); + Assert.assertEquals("log", rs.getString("TABLE_CAT")); + // TABLE_SCHEM + Assert.assertEquals("TABLE_SCHEM", meta.getColumnLabel(2)); + Assert.assertEquals(null, rs.getString(2)); + Assert.assertEquals(null, rs.getString("TABLE_SCHEM")); + // TABLE_NAME + Assert.assertEquals("TABLE_NAME", meta.getColumnLabel(3)); + Assert.assertEquals("dn1", rs.getString(3)); + Assert.assertEquals("dn1", rs.getString("TABLE_NAME")); + // COLUMN_NAME + Assert.assertEquals("COLUMN_NAME", meta.getColumnLabel(4)); + Assert.assertEquals("ts", rs.getString(4)); + Assert.assertEquals("ts", rs.getString("COLUMN_NAME")); + // KEY_SEQ + Assert.assertEquals("KEY_SEQ", meta.getColumnLabel(5)); + Assert.assertEquals(1, rs.getShort(5)); + Assert.assertEquals(1, rs.getShort("KEY_SEQ")); + // DATA_TYPE + Assert.assertEquals("PK_NAME", meta.getColumnLabel(6)); + Assert.assertEquals("ts", rs.getString(6)); + Assert.assertEquals("ts", rs.getString("PK_NAME")); } - - Assert.assertNotNull(rs); } @Test @@ -852,14 +970,27 @@ public class RestfulDatabaseMetaDataTest { @Test public void getSuperTables() throws SQLException { - System.out.println("****************************************************"); - ResultSet rs = metaData.getSuperTables("log", "", "dn1"); - while (rs.next()) { - System.out.println("TABLE_NAME: " + rs.getString("TABLE_NAME")); - System.out.println("SUPERTABLE_NAME: " + rs.getString("SUPERTABLE_NAME")); + ResultSetMetaData meta = rs.getMetaData(); + rs.next(); + { + // TABLE_CAT + Assert.assertEquals("TABLE_CAT", meta.getColumnLabel(1)); + Assert.assertEquals("log", rs.getString(1)); + Assert.assertEquals("log", rs.getString("TABLE_CAT")); + // TABLE_CAT + Assert.assertEquals("TABLE_SCHEM", meta.getColumnLabel(2)); + Assert.assertEquals(null, rs.getString(2)); + Assert.assertEquals(null, rs.getString("TABLE_SCHEM")); + // TABLE_CAT + Assert.assertEquals("TABLE_NAME", meta.getColumnLabel(3)); + Assert.assertEquals("dn1", rs.getString(3)); + Assert.assertEquals("dn1", rs.getString("TABLE_NAME")); + // TABLE_CAT + Assert.assertEquals("SUPERTABLE_NAME", meta.getColumnLabel(4)); + Assert.assertEquals("dn", rs.getString(4)); + Assert.assertEquals("dn", rs.getString("SUPERTABLE_NAME")); } - Assert.assertNotNull(rs); } @Test diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/RestfulParameterMetaDataTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/RestfulParameterMetaDataTest.java index 8bb2532ce82e24e4015746e04b5b2dea18f530e4..81d7f5b56c4b4e67b9573522ee031006a7e11a2b 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/RestfulParameterMetaDataTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/RestfulParameterMetaDataTest.java @@ -54,16 +54,17 @@ public class RestfulParameterMetaDataTest { @Test public void getPrecision() throws SQLException { - Assert.assertEquals(0, parameterMetaData_insert.getPrecision(1)); - Assert.assertEquals(0, parameterMetaData_insert.getPrecision(2)); - Assert.assertEquals(0, parameterMetaData_insert.getPrecision(3)); - Assert.assertEquals(0, parameterMetaData_insert.getPrecision(4)); - Assert.assertEquals(0, parameterMetaData_insert.getPrecision(5)); - Assert.assertEquals(0, parameterMetaData_insert.getPrecision(6)); - Assert.assertEquals(0, parameterMetaData_insert.getPrecision(7)); - Assert.assertEquals(0, parameterMetaData_insert.getPrecision(8)); - Assert.assertEquals(5, parameterMetaData_insert.getPrecision(9)); - Assert.assertEquals(5, parameterMetaData_insert.getPrecision(10)); + //create table weather(ts timestamp, f1 int, f2 bigint, f3 float, f4 double, f5 smallint, f6 tinyint, f7 bool, f8 binary(64), f9 nchar(64)) + Assert.assertEquals(TSDBConstants.TIMESTAMP_MS_PRECISION, parameterMetaData_insert.getPrecision(1)); + Assert.assertEquals(TSDBConstants.INT_PRECISION, parameterMetaData_insert.getPrecision(2)); + Assert.assertEquals(TSDBConstants.BIGINT_PRECISION, parameterMetaData_insert.getPrecision(3)); + Assert.assertEquals(TSDBConstants.FLOAT_PRECISION, parameterMetaData_insert.getPrecision(4)); + Assert.assertEquals(TSDBConstants.DOUBLE_PRECISION, parameterMetaData_insert.getPrecision(5)); + Assert.assertEquals(TSDBConstants.SMALLINT_PRECISION, parameterMetaData_insert.getPrecision(6)); + Assert.assertEquals(TSDBConstants.TINYINT_PRECISION, parameterMetaData_insert.getPrecision(7)); + Assert.assertEquals(TSDBConstants.BOOLEAN_PRECISION, parameterMetaData_insert.getPrecision(8)); + Assert.assertEquals("hello".getBytes().length, parameterMetaData_insert.getPrecision(9)); + Assert.assertEquals("涛思数据".length(), parameterMetaData_insert.getPrecision(10)); } @Test @@ -71,8 +72,8 @@ public class RestfulParameterMetaDataTest { Assert.assertEquals(0, parameterMetaData_insert.getScale(1)); Assert.assertEquals(0, parameterMetaData_insert.getScale(2)); Assert.assertEquals(0, parameterMetaData_insert.getScale(3)); - Assert.assertEquals(0, parameterMetaData_insert.getScale(4)); - Assert.assertEquals(0, parameterMetaData_insert.getScale(5)); + Assert.assertEquals(31, parameterMetaData_insert.getScale(4)); + Assert.assertEquals(31, parameterMetaData_insert.getScale(5)); Assert.assertEquals(0, parameterMetaData_insert.getScale(6)); Assert.assertEquals(0, parameterMetaData_insert.getScale(7)); Assert.assertEquals(0, parameterMetaData_insert.getScale(8)); @@ -164,7 +165,7 @@ public class RestfulParameterMetaDataTest { pstmt_insert.setObject(7, Byte.MAX_VALUE); pstmt_insert.setObject(8, true); pstmt_insert.setObject(9, "hello".getBytes()); - pstmt_insert.setObject(10, "Hello"); + pstmt_insert.setObject(10, "涛思数据"); parameterMetaData_insert = pstmt_insert.getParameterMetaData(); pstmt_select = conn.prepareStatement(sql_select); diff --git a/src/connector/python/taos/cinterface.py b/src/connector/python/taos/cinterface.py index b8824327b017fc0bb7f9639942e20e72891ac808..0f690aeb27ce81d867d1727c50ba948afd9493a8 100644 --- a/src/connector/python/taos/cinterface.py +++ b/src/connector/python/taos/cinterface.py @@ -242,7 +242,7 @@ def _load_taos_linux(): def _load_taos_darwin(): - return ctypes.cDLL('libtaos.dylib') + return ctypes.CDLL('libtaos.dylib') def _load_taos_windows(): diff --git a/src/cq/src/cqMain.c b/src/cq/src/cqMain.c index ee4be02b9004b56c0139b792393d00d9ea6a6f98..f539e7725315d2358767624ce74a8e9609a0b425 100644 --- a/src/cq/src/cqMain.c +++ b/src/cq/src/cqMain.c @@ -38,21 +38,6 @@ #define cDebug(...) { if (cqDebugFlag & DEBUG_DEBUG) { taosPrintLog("CQ ", cqDebugFlag, __VA_ARGS__); }} #define cTrace(...) { if (cqDebugFlag & DEBUG_TRACE) { taosPrintLog("CQ ", cqDebugFlag, __VA_ARGS__); }} -typedef struct { - int32_t vgId; - int32_t master; - int32_t num; // number of continuous streams - char user[TSDB_USER_LEN]; - char pass[TSDB_KEY_LEN]; - char db[TSDB_DB_NAME_LEN]; - FCqWrite cqWrite; - struct SCqObj *pHead; - void *dbConn; - void *tmrCtrl; - pthread_mutex_t mutex; - int32_t delete; - int32_t cqObjNum; -} SCqContext; typedef struct SCqObj { tmr_h tmrId; @@ -439,7 +424,7 @@ static void cqProcessCreateTimer(void *param, void *tmrId) { // inner implement in tscStream.c TAOS_STREAM *taos_open_stream_withname(TAOS *taos, const char* desName, const char *sqlstr, void (*fp)(void *param, TAOS_RES *, TAOS_ROW row), - int64_t stime, void *param, void (*callback)(void *)); + int64_t stime, void *param, void (*callback)(void *), void* cqhandle); static void cqCreateStream(SCqContext *pContext, SCqObj *pObj) { pObj->pContext = pContext; @@ -453,7 +438,8 @@ static void cqCreateStream(SCqContext *pContext, SCqObj *pObj) { pObj->tmrId = 0; if (pObj->pStream == NULL) { - pObj->pStream = taos_open_stream_withname(pContext->dbConn, pObj->dstTable, pObj->sqlStr, cqProcessStreamRes, INT64_MIN, (void *)pObj->rid, NULL); + pObj->pStream = taos_open_stream_withname(pContext->dbConn, pObj->dstTable, pObj->sqlStr, cqProcessStreamRes, \ + INT64_MIN, (void *)pObj->rid, NULL, pContext); // TODO the pObj->pStream may be released if error happens if (pObj->pStream) { diff --git a/src/dnode/src/dnodeVMgmt.c b/src/dnode/src/dnodeVMgmt.c index f8ba9b18b5a6c7f0ad7cc2e60c66537052e2363b..90bae8b9dd73ca80efab8090d5a189cf8c1a8966 100644 --- a/src/dnode/src/dnodeVMgmt.c +++ b/src/dnode/src/dnodeVMgmt.c @@ -156,7 +156,6 @@ static SCreateVnodeMsg* dnodeParseVnodeMsg(SRpcMsg *rpcMsg) { static int32_t dnodeProcessCreateVnodeMsg(SRpcMsg *rpcMsg) { SCreateVnodeMsg *pCreate = dnodeParseVnodeMsg(rpcMsg); - void *pVnode = vnodeAcquire(pCreate->cfg.vgId); if (pVnode != NULL) { dDebug("vgId:%d, already exist, return success", pCreate->cfg.vgId); diff --git a/src/inc/taos.h b/src/inc/taos.h index d27828fc364fd795e238b33df464fdc3548b60e2..9f72945ef03f28fb54ab05f84be810a0f9d5a66a 100644 --- a/src/inc/taos.h +++ b/src/inc/taos.h @@ -124,6 +124,7 @@ int taos_stmt_add_batch(TAOS_STMT *stmt); int taos_stmt_execute(TAOS_STMT *stmt); TAOS_RES * taos_stmt_use_result(TAOS_STMT *stmt); int taos_stmt_close(TAOS_STMT *stmt); +char * taos_stmt_errstr(TAOS_STMT *stmt); DLL_EXPORT TAOS_RES *taos_query(TAOS *taos, const char *sql); DLL_EXPORT TAOS_ROW taos_fetch_row(TAOS_RES *res); diff --git a/src/inc/taoserror.h b/src/inc/taoserror.h index ab15e851e76e1c7ad29a81a7cd1874a9e89d82ed..431c9116ccec57d90a1dbe2405845f6c26a5fef6 100644 --- a/src/inc/taoserror.h +++ b/src/inc/taoserror.h @@ -244,6 +244,7 @@ int32_t* taosGetErrno(); #define TSDB_CODE_TDB_NO_AVAIL_DISK TAOS_DEF_ERROR_CODE(0, 0x0613) //"No available disk") #define TSDB_CODE_TDB_MESSED_MSG TAOS_DEF_ERROR_CODE(0, 0x0614) //"TSDB messed message") #define TSDB_CODE_TDB_IVLD_TAG_VAL TAOS_DEF_ERROR_CODE(0, 0x0615) //"TSDB invalid tag value") +#define TSDB_CODE_TDB_NO_CACHE_LAST_ROW TAOS_DEF_ERROR_CODE(0, 0x0616) //"TSDB no cache last row data") // query #define TSDB_CODE_QRY_INVALID_QHANDLE TAOS_DEF_ERROR_CODE(0, 0x0700) //"Invalid handle") diff --git a/src/inc/taosmsg.h b/src/inc/taosmsg.h index 819d2b7a51e2aea1b011318f7dabb320a62858f4..61e1e88c13fdced4c172b4c276067ff398b5f70b 100644 --- a/src/inc/taosmsg.h +++ b/src/inc/taosmsg.h @@ -551,7 +551,7 @@ typedef struct { int32_t totalBlocks; int32_t maxTables; int32_t daysPerFile; - int32_t daysToKeep; + int32_t daysToKeep0; int32_t daysToKeep1; int32_t daysToKeep2; int32_t minRowsPerFileBlock; diff --git a/src/inc/tcq.h b/src/inc/tcq.h index 552a40665ae10c72203ac60afaec59a4381ead5f..7549c3d498a02e948212c38b071701aa55adc2fc 100644 --- a/src/inc/tcq.h +++ b/src/inc/tcq.h @@ -31,6 +31,23 @@ typedef struct { FCqWrite cqWrite; } SCqCfg; +// SCqContext +typedef struct { + int32_t vgId; + int32_t master; + int32_t num; // number of continuous streams + char user[TSDB_USER_LEN]; + char pass[TSDB_KEY_LEN]; + char db[TSDB_DB_NAME_LEN]; + FCqWrite cqWrite; + struct SCqObj *pHead; + void *dbConn; + void *tmrCtrl; + pthread_mutex_t mutex; + int32_t delete; + int32_t cqObjNum; +} SCqContext; + // the following API shall be called by vnode void *cqOpen(void *ahandle, const SCqCfg *pCfg); void cqClose(void *handle); diff --git a/src/inc/tsdb.h b/src/inc/tsdb.h index 05d29daad52c2eeeeee080b411ebedf4b7e8233f..79d9029dbc1603fe145e8b12553e2d03c028ac60 100644 --- a/src/inc/tsdb.h +++ b/src/inc/tsdb.h @@ -94,7 +94,7 @@ STsdbRepo *tsdbOpenRepo(STsdbCfg *pCfg, STsdbAppH *pAppH); int tsdbCloseRepo(STsdbRepo *repo, int toCommit); int32_t tsdbConfigRepo(STsdbRepo *repo, STsdbCfg *pCfg); int tsdbGetState(STsdbRepo *repo); - +bool tsdbInCompact(STsdbRepo *repo); // --------- TSDB TABLE DEFINITION typedef struct { uint64_t uid; // the unique table ID diff --git a/src/inc/ttokendef.h b/src/inc/ttokendef.h index 3c7cdf20757a8990e74438e86b329a42046b10c9..be13dd05f83ac5b58f02ae1c669d1ac0085a655f 100644 --- a/src/inc/ttokendef.h +++ b/src/inc/ttokendef.h @@ -106,26 +106,26 @@ #define TK_QTIME 88 #define TK_CONNS 89 #define TK_STATE 90 -#define TK_KEEP 91 -#define TK_CACHE 92 -#define TK_REPLICA 93 -#define TK_QUORUM 94 -#define TK_DAYS 95 -#define TK_MINROWS 96 -#define TK_MAXROWS 97 -#define TK_BLOCKS 98 -#define TK_CTIME 99 -#define TK_WAL 100 -#define TK_FSYNC 101 -#define TK_COMP 102 -#define TK_PRECISION 103 -#define TK_UPDATE 104 -#define TK_CACHELAST 105 -#define TK_PARTITIONS 106 -#define TK_UNSIGNED 107 -#define TK_TAGS 108 -#define TK_USING 109 -#define TK_COMMA 110 +#define TK_COMMA 91 +#define TK_KEEP 92 +#define TK_CACHE 93 +#define TK_REPLICA 94 +#define TK_QUORUM 95 +#define TK_DAYS 96 +#define TK_MINROWS 97 +#define TK_MAXROWS 98 +#define TK_BLOCKS 99 +#define TK_CTIME 100 +#define TK_WAL 101 +#define TK_FSYNC 102 +#define TK_COMP 103 +#define TK_PRECISION 104 +#define TK_UPDATE 105 +#define TK_CACHELAST 106 +#define TK_PARTITIONS 107 +#define TK_UNSIGNED 108 +#define TK_TAGS 109 +#define TK_USING 110 #define TK_AS 111 #define TK_NULL 112 #define TK_SELECT 113 @@ -207,7 +207,6 @@ #define TK_VALUES 189 - #define TK_SPACE 300 #define TK_COMMENT 301 #define TK_ILLEGAL 302 diff --git a/src/kit/shell/src/shellEngine.c b/src/kit/shell/src/shellEngine.c index d4176fca91cd412b4d2d20a9a6c72a998c443428..d5fa0a9e09f5ac10d4d6a64c48d4639697c49165 100644 --- a/src/kit/shell/src/shellEngine.c +++ b/src/kit/shell/src/shellEngine.c @@ -398,7 +398,10 @@ static char* formatTimestamp(char* buf, int64_t val, int precision) { time_t tt; int32_t ms = 0; - if (precision == TSDB_TIME_PRECISION_MICRO) { + if (precision == TSDB_TIME_PRECISION_NANO) { + tt = (time_t)(val / 1000000000); + ms = val % 1000000000; + } else if (precision == TSDB_TIME_PRECISION_MICRO) { tt = (time_t)(val / 1000000); ms = val % 1000000; } else { @@ -419,7 +422,9 @@ static char* formatTimestamp(char* buf, int64_t val, int precision) { #endif if (tt <= 0 && ms < 0) { tt--; - if (precision == TSDB_TIME_PRECISION_MICRO) { + if (precision == TSDB_TIME_PRECISION_NANO) { + ms += 1000000000; + } else if (precision == TSDB_TIME_PRECISION_MICRO) { ms += 1000000; } else { ms += 1000; @@ -427,9 +432,11 @@ static char* formatTimestamp(char* buf, int64_t val, int precision) { } struct tm* ptm = localtime(&tt); - size_t pos = strftime(buf, 32, "%Y-%m-%d %H:%M:%S", ptm); + size_t pos = strftime(buf, 35, "%Y-%m-%d %H:%M:%S", ptm); - if (precision == TSDB_TIME_PRECISION_MICRO) { + if (precision == TSDB_TIME_PRECISION_NANO) { + sprintf(buf + pos, ".%09d", ms); + } else if (precision == TSDB_TIME_PRECISION_MICRO) { sprintf(buf + pos, ".%06d", ms); } else { sprintf(buf + pos, ".%03d", ms); @@ -778,6 +785,8 @@ static int calcColWidth(TAOS_FIELD* field, int precision) { case TSDB_DATA_TYPE_TIMESTAMP: if (args.is_raw_time) { return MAX(14, width); + } if (precision == TSDB_TIME_PRECISION_NANO) { + return MAX(29, width); } else if (precision == TSDB_TIME_PRECISION_MICRO) { return MAX(26, width); // '2020-01-01 00:00:00.000000' } else { diff --git a/src/kit/taosdemo/taosdemo.c b/src/kit/taosdemo/taosdemo.c index 6f5d407a7348b2fa7768f0266c5dcd79a6b4653f..865224d2c3f513edcd8308731baf096cc697ea83 100644 --- a/src/kit/taosdemo/taosdemo.c +++ b/src/kit/taosdemo/taosdemo.c @@ -625,6 +625,10 @@ static int64_t g_totalChildTables = 0; static SQueryMetaInfo g_queryInfo; static FILE * g_fpOfInsertResult = NULL; +#if _MSC_VER <= 1900 +#define __func__ __FUNCTION__ +#endif + #define debugPrint(fmt, ...) \ do { if (g_args.debug_print || g_args.verbose_print) \ fprintf(stderr, "DEBG: "fmt, __VA_ARGS__); } while(0) @@ -1209,7 +1213,6 @@ static void fetchResult(TAOS_RES *res, threadInfo* pThreadInfo) { } int totalLen = 0; - char temp[16000]; // fetch the records row by row while((row = taos_fetch_row(res))) { @@ -1220,6 +1223,7 @@ static void fetchResult(TAOS_RES *res, threadInfo* pThreadInfo) { memset(databuf, 0, 100*1024*1024); } num_rows++; + char temp[16000] = {0}; int len = taos_print_row(temp, row, fields, num_fields); len += sprintf(temp + len, "\n"); //printf("query result:%s\n", temp); @@ -1848,7 +1852,9 @@ static void printfQueryMeta() { static char* formatTimestamp(char* buf, int64_t val, int precision) { time_t tt; - if (precision == TSDB_TIME_PRECISION_MICRO) { + if (precision == TSDB_TIME_PRECISION_NANO) { + tt = (time_t)(val / 1000000000); + } else if (precision == TSDB_TIME_PRECISION_MICRO) { tt = (time_t)(val / 1000000); } else { tt = (time_t)(val / 1000); @@ -1869,7 +1875,9 @@ static char* formatTimestamp(char* buf, int64_t val, int precision) { struct tm* ptm = localtime(&tt); size_t pos = strftime(buf, 32, "%Y-%m-%d %H:%M:%S", ptm); - if (precision == TSDB_TIME_PRECISION_MICRO) { + if (precision == TSDB_TIME_PRECISION_NANO) { + sprintf(buf + pos, ".%09d", (int)(val % 1000000000)); + } else if (precision == TSDB_TIME_PRECISION_MICRO) { sprintf(buf + pos, ".%06d", (int)(val % 1000000)); } else { sprintf(buf + pos, ".%03d", (int)(val % 1000)); @@ -6249,9 +6257,11 @@ static void startMultiThreadInsertData(int threads, char* db_name, if (0 != precision[0]) { if (0 == strncasecmp(precision, "ms", 2)) { timePrec = TSDB_TIME_PRECISION_MILLI; - } else if (0 == strncasecmp(precision, "us", 2)) { + } else if (0 == strncasecmp(precision, "us", 2)) { timePrec = TSDB_TIME_PRECISION_MICRO; - } else { + } else if (0 == strncasecmp(precision, "ns", 2)) { + timePrec = TSDB_TIME_PRECISION_NANO; + } else { errorPrint("Not support precision: %s\n", precision); exit(-1); } diff --git a/src/mnode/inc/mnodeDb.h b/src/mnode/inc/mnodeDb.h index 0fa1a15e2d7531d941f6236517385d1e97922c6e..40c5afc2c84cd497095a508df42b9e89ad638d70 100644 --- a/src/mnode/inc/mnodeDb.h +++ b/src/mnode/inc/mnodeDb.h @@ -40,6 +40,7 @@ void mnodeIncDbRef(SDbObj *pDb); void mnodeDecDbRef(SDbObj *pDb); bool mnodeCheckIsMonitorDB(char *db, char *monitordb); void mnodeDropAllDbs(SAcctObj *pAcct); +int mnodeInsertAlterDbRow(SDbObj *pDb, void *pMsg); int32_t mnodeCompactDbs(); diff --git a/src/mnode/inc/mnodeDef.h b/src/mnode/inc/mnodeDef.h index f170f58b538dbbabfad9cdfedfc469339a6e3251..5aeb37988a0ae662e4777ac8c4a53d1e844f3f0a 100644 --- a/src/mnode/inc/mnodeDef.h +++ b/src/mnode/inc/mnodeDef.h @@ -162,7 +162,7 @@ typedef struct { int32_t totalBlocks; int32_t maxTables; int32_t daysPerFile; - int32_t daysToKeep; + int32_t daysToKeep0; int32_t daysToKeep1; int32_t daysToKeep2; int32_t minRowsPerFileBlock; diff --git a/src/mnode/inc/mnodeVgroup.h b/src/mnode/inc/mnodeVgroup.h index 8ff4dbaaa57174250e8ef5150dbc7da7df11e23a..aff0411fdd777f83ccc6a882fbe91d7bc909e16b 100644 --- a/src/mnode/inc/mnodeVgroup.h +++ b/src/mnode/inc/mnodeVgroup.h @@ -49,7 +49,7 @@ int32_t mnodeAddTableIntoVgroup(SVgObj *pVgroup, SCTableObj *pTable, bool needCh void mnodeRemoveTableFromVgroup(SVgObj *pVgroup, SCTableObj *pTable); void mnodeSendDropVnodeMsg(int32_t vgId, SRpcEpSet *epSet, void *ahandle); void mnodeSendCreateVgroupMsg(SVgObj *pVgroup, void *ahandle); -void mnodeSendAlterVgroupMsg(SVgObj *pVgroup); +void mnodeSendAlterVgroupMsg(SVgObj *pVgroup,SMnodeMsg *pMsg); void mnodeSendSyncVgroupMsg(SVgObj *pVgroup); void mnodeSendCompactVgroupMsg(SVgObj *pVgroup); diff --git a/src/mnode/src/mnodeDb.c b/src/mnode/src/mnodeDb.c index 7b46f0d1083891d93fa22e3729617c8734a875c6..f4fc88476f8c2ddeb32acc4f37d27f17c76af788 100644 --- a/src/mnode/src/mnodeDb.c +++ b/src/mnode/src/mnodeDb.c @@ -24,12 +24,14 @@ #include "tdataformat.h" #include "tp.h" #include "mnode.h" +#include "dnode.h" #include "mnodeDef.h" #include "mnodeInt.h" #include "mnodeAcct.h" #include "mnodeDb.h" #include "mnodeDnode.h" #include "mnodeMnode.h" +#include "mnodePeer.h" #include "mnodeProfile.h" #include "mnodeWrite.h" #include "mnodeSdb.h" @@ -264,26 +266,27 @@ static int32_t mnodeCheckDbCfg(SDbCfg *pCfg) { return TSDB_CODE_MND_INVALID_DB_OPTION_DAYS; } - if (pCfg->daysToKeep < TSDB_MIN_KEEP || pCfg->daysToKeep > TSDB_MAX_KEEP) { - mError("invalid db option daysToKeep:%d valid range: [%d, %d]", pCfg->daysToKeep, TSDB_MIN_KEEP, TSDB_MAX_KEEP); + if (pCfg->daysToKeep0 < TSDB_MIN_KEEP || pCfg->daysToKeep0 > TSDB_MAX_KEEP) { + mError("invalid db option daysToKeep:%d valid range: [%d, %d]", pCfg->daysToKeep0, TSDB_MIN_KEEP, TSDB_MAX_KEEP); return TSDB_CODE_MND_INVALID_DB_OPTION_KEEP; } - if (pCfg->daysToKeep < pCfg->daysPerFile) { - mError("invalid db option daysToKeep:%d should larger than daysPerFile:%d", pCfg->daysToKeep, pCfg->daysPerFile); + if (pCfg->daysToKeep0 < pCfg->daysPerFile) { + mError("invalid db option daysToKeep:%d should larger than daysPerFile:%d", pCfg->daysToKeep0, pCfg->daysPerFile); return TSDB_CODE_MND_INVALID_DB_OPTION_KEEP; } - if (pCfg->daysToKeep2 < TSDB_MIN_KEEP || pCfg->daysToKeep2 > pCfg->daysToKeep) { - mError("invalid db option daysToKeep2:%d valid range: [%d, %d]", pCfg->daysToKeep2, TSDB_MIN_KEEP, pCfg->daysToKeep); + if (pCfg->daysToKeep1 < pCfg->daysToKeep0 || pCfg->daysToKeep1 > TSDB_MAX_KEEP) { + mError("invalid db option daysToKeep1:%d valid range: [%d, %d]", pCfg->daysToKeep1, pCfg->daysToKeep0, TSDB_MAX_KEEP); return TSDB_CODE_MND_INVALID_DB_OPTION_KEEP; } - if (pCfg->daysToKeep1 < TSDB_MIN_KEEP || pCfg->daysToKeep1 > pCfg->daysToKeep2) { - mError("invalid db option daysToKeep1:%d valid range: [%d, %d]", pCfg->daysToKeep1, TSDB_MIN_KEEP, pCfg->daysToKeep2); + if (pCfg->daysToKeep2 < pCfg->daysToKeep1 || pCfg->daysToKeep2 > TSDB_MAX_KEEP) { + mError("invalid db option daysToKeep2:%d valid range: [%d, %d]", pCfg->daysToKeep2, pCfg->daysToKeep1, TSDB_MAX_KEEP); return TSDB_CODE_MND_INVALID_DB_OPTION_KEEP; } + if (pCfg->maxRowsPerFileBlock < TSDB_MIN_MAX_ROW_FBLOCK || pCfg->maxRowsPerFileBlock > TSDB_MAX_MAX_ROW_FBLOCK) { mError("invalid db option maxRowsPerFileBlock:%d valid range: [%d, %d]", pCfg->maxRowsPerFileBlock, TSDB_MIN_MAX_ROW_FBLOCK, TSDB_MAX_MAX_ROW_FBLOCK); @@ -381,9 +384,9 @@ static void mnodeSetDefaultDbCfg(SDbCfg *pCfg) { if (pCfg->totalBlocks < 0) pCfg->totalBlocks = tsBlocksPerVnode; if (pCfg->maxTables < 0) pCfg->maxTables = tsMaxTablePerVnode; if (pCfg->daysPerFile < 0) pCfg->daysPerFile = tsDaysPerFile; - if (pCfg->daysToKeep < 0) pCfg->daysToKeep = tsDaysToKeep; - if (pCfg->daysToKeep1 < 0) pCfg->daysToKeep1 = pCfg->daysToKeep; - if (pCfg->daysToKeep2 < 0) pCfg->daysToKeep2 = pCfg->daysToKeep; + if (pCfg->daysToKeep2 < 0) pCfg->daysToKeep2 = tsDaysToKeep; + if (pCfg->daysToKeep1 < 0) pCfg->daysToKeep1 = pCfg->daysToKeep2; + if (pCfg->daysToKeep0 < 0) pCfg->daysToKeep0 = pCfg->daysToKeep1; if (pCfg->minRowsPerFileBlock < 0) pCfg->minRowsPerFileBlock = tsMinRowsInFileBlock; if (pCfg->maxRowsPerFileBlock < 0) pCfg->maxRowsPerFileBlock = tsMaxRowsInFileBlock; if (pCfg->fsyncPeriod <0) pCfg->fsyncPeriod = tsFsyncPeriod; @@ -438,7 +441,7 @@ static int32_t mnodeCreateDb(SAcctObj *pAcct, SCreateDbMsg *pCreate, SMnodeMsg * .totalBlocks = pCreate->totalBlocks, .maxTables = pCreate->maxTables, .daysPerFile = pCreate->daysPerFile, - .daysToKeep = pCreate->daysToKeep, + .daysToKeep0 = pCreate->daysToKeep0, .daysToKeep1 = pCreate->daysToKeep1, .daysToKeep2 = pCreate->daysToKeep2, .minRowsPerFileBlock = pCreate->minRowsPerFileBlock, @@ -614,7 +617,12 @@ static int32_t mnodeGetDbMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn pShow->bytes[cols] = 24 + VARSTR_HEADER_SIZE; pSchema[cols].type = TSDB_DATA_TYPE_BINARY; - strcpy(pSchema[cols].name, "keep0,keep1,keep(D)"); + +#ifdef _STORAGE + strcpy(pSchema[cols].name, "keep0,keep1,keep2"); +#else + strcpy(pSchema[cols].name, "keep"); +#endif pSchema[cols].bytes = htons(pShow->bytes[cols]); cols++; @@ -780,7 +788,15 @@ static int32_t mnodeRetrieveDbs(SShowObj *pShow, char *data, int32_t rows, void pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; char tmp[128] = {0}; - sprintf(tmp, "%d,%d,%d", pDb->cfg.daysToKeep1, pDb->cfg.daysToKeep2, pDb->cfg.daysToKeep); +#ifdef _STORAGE + if (pDb->cfg.daysToKeep0 > pDb->cfg.daysToKeep1 || pDb->cfg.daysToKeep0 > pDb->cfg.daysToKeep2) { + sprintf(tmp, "%d,%d,%d", pDb->cfg.daysToKeep1, pDb->cfg.daysToKeep2, pDb->cfg.daysToKeep0); + } else { + sprintf(tmp, "%d,%d,%d", pDb->cfg.daysToKeep0, pDb->cfg.daysToKeep1, pDb->cfg.daysToKeep2); + } +#else + sprintf(tmp, "%d", pDb->cfg.daysToKeep2); +#endif STR_WITH_SIZE_TO_VARSTR(pWrite, tmp, strlen(tmp)); cols++; @@ -823,8 +839,13 @@ static int32_t mnodeRetrieveDbs(SShowObj *pShow, char *data, int32_t rows, void #endif pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - char *prec = (pDb->cfg.precision == TSDB_TIME_PRECISION_MILLI) ? TSDB_TIME_PRECISION_MILLI_STR - : TSDB_TIME_PRECISION_MICRO_STR; + char *prec = NULL; + switch (pDb->cfg.precision) { + case TSDB_TIME_PRECISION_MILLI: prec = TSDB_TIME_PRECISION_MILLI_STR; break; + case TSDB_TIME_PRECISION_MICRO: prec = TSDB_TIME_PRECISION_MICRO_STR; break; + case TSDB_TIME_PRECISION_NANO: prec = TSDB_TIME_PRECISION_NANO_STR; break; + default: assert(false); break; + } STR_WITH_SIZE_TO_VARSTR(pWrite, prec, 2); cols++; @@ -893,7 +914,7 @@ static int32_t mnodeProcessCreateDbMsg(SMnodeMsg *pMsg) { pCreate->cacheBlockSize = htonl(pCreate->cacheBlockSize); pCreate->totalBlocks = htonl(pCreate->totalBlocks); pCreate->daysPerFile = htonl(pCreate->daysPerFile); - pCreate->daysToKeep = htonl(pCreate->daysToKeep); + pCreate->daysToKeep0 = htonl(pCreate->daysToKeep0); pCreate->daysToKeep1 = htonl(pCreate->daysToKeep1); pCreate->daysToKeep2 = htonl(pCreate->daysToKeep2); pCreate->commitTime = htonl(pCreate->commitTime); @@ -920,7 +941,7 @@ static SDbCfg mnodeGetAlterDbOption(SDbObj *pDb, SAlterDbMsg *pAlter) { int32_t cacheBlockSize = htonl(pAlter->cacheBlockSize); int32_t totalBlocks = htonl(pAlter->totalBlocks); int32_t daysPerFile = htonl(pAlter->daysPerFile); - int32_t daysToKeep = htonl(pAlter->daysToKeep); + int32_t daysToKeep0 = htonl(pAlter->daysToKeep0); int32_t daysToKeep1 = htonl(pAlter->daysToKeep1); int32_t daysToKeep2 = htonl(pAlter->daysToKeep2); int32_t minRows = htonl(pAlter->minRowsPerFileBlock); @@ -939,6 +960,14 @@ static SDbCfg mnodeGetAlterDbOption(SDbObj *pDb, SAlterDbMsg *pAlter) { terrno = TSDB_CODE_SUCCESS; + //UPGRATE FROM LOW VERSION, reorder it + if (pDb->cfg.daysToKeep0 > pDb->cfg.daysToKeep1 || pDb->cfg.daysToKeep0 > pDb->cfg.daysToKeep2) { + int32_t t = pDb->cfg.daysToKeep0; + newCfg.daysToKeep0 = pDb->cfg.daysToKeep1; + newCfg.daysToKeep1 = pDb->cfg.daysToKeep2; + newCfg.daysToKeep2 = t; + } + if (cacheBlockSize > 0 && cacheBlockSize != pDb->cfg.cacheBlockSize) { mError("db:%s, can't alter cache option", pDb->name); terrno = TSDB_CODE_MND_INVALID_DB_OPTION; @@ -963,17 +992,17 @@ static SDbCfg mnodeGetAlterDbOption(SDbObj *pDb, SAlterDbMsg *pAlter) { terrno = TSDB_CODE_MND_INVALID_DB_OPTION; } - if (daysToKeep > 0 && daysToKeep != pDb->cfg.daysToKeep) { - mDebug("db:%s, daysToKeep:%d change to %d", pDb->name, pDb->cfg.daysToKeep, daysToKeep); - newCfg.daysToKeep = daysToKeep; + if (daysToKeep0 > 0 && (daysToKeep0 != pDb->cfg.daysToKeep0 || newCfg.daysToKeep0 != pDb->cfg.daysToKeep0)) { + mDebug("db:%s, daysToKeep:%d change to %d", pDb->name, pDb->cfg.daysToKeep0, daysToKeep0); + newCfg.daysToKeep0 = daysToKeep0; } - if (daysToKeep1 > 0 && daysToKeep1 != pDb->cfg.daysToKeep1) { + if (daysToKeep1 > 0 && (daysToKeep1 != pDb->cfg.daysToKeep1 || newCfg.daysToKeep1 != pDb->cfg.daysToKeep1)) { mDebug("db:%s, daysToKeep1:%d change to %d", pDb->name, pDb->cfg.daysToKeep1, daysToKeep1); newCfg.daysToKeep1 = daysToKeep1; } - if (daysToKeep2 > 0 && daysToKeep2 != pDb->cfg.daysToKeep2) { + if (daysToKeep2 > 0 && (daysToKeep2 != pDb->cfg.daysToKeep2 || newCfg.daysToKeep2 != pDb->cfg.daysToKeep2)) { mDebug("db:%s, daysToKeep2:%d change to %d", pDb->name, pDb->cfg.daysToKeep2, daysToKeep2); newCfg.daysToKeep2 = daysToKeep2; } @@ -1066,24 +1095,25 @@ static SDbCfg mnodeGetAlterDbOption(SDbObj *pDb, SAlterDbMsg *pAlter) { // community version can only change daysToKeep // but enterprise version can change all daysToKeep options #ifndef _STORAGE - newCfg.daysToKeep1 = newCfg.daysToKeep; - newCfg.daysToKeep2 = newCfg.daysToKeep; + newCfg.daysToKeep1 = newCfg.daysToKeep0; + newCfg.daysToKeep2 = newCfg.daysToKeep0; #endif return newCfg; } -static int32_t mnodeAlterDbCb(SMnodeMsg *pMsg, int32_t code) { - if (code != TSDB_CODE_SUCCESS) return code; +static int32_t mnodeAlterDbFp(SMnodeMsg *pMsg) { SDbObj *pDb = pMsg->pDb; void *pIter = NULL; SVgObj *pVgroup = NULL; - while (1) { + pMsg->expected = 0; + while (1) { pIter = mnodeGetNextVgroup(pIter, &pVgroup); if (pVgroup == NULL) break; if (pVgroup->pDb == pDb) { - mnodeSendAlterVgroupMsg(pVgroup); + pMsg->expected += pVgroup->numOfVnodes; + mnodeSendAlterVgroupMsg(pVgroup,pMsg); } mnodeDecVgroupRef(pVgroup); } @@ -1091,9 +1121,32 @@ static int32_t mnodeAlterDbCb(SMnodeMsg *pMsg, int32_t code) { mDebug("db:%s, all vgroups is altered", pDb->name); mLInfo("db:%s, is alterd by %s", pDb->name, mnodeGetUserFromMsg(pMsg)); - bnNotify(); + // in case there is no vnode for this db currently(no table in db,etc.) + if (pMsg->expected == 0) { + SSdbRow row = { + .type = SDB_OPER_GLOBAL, + .pTable = tsDbSdb, + .pObj = pDb, + .pMsg = pMsg, + }; - return TSDB_CODE_SUCCESS; + return sdbUpdateRow(&row); + } + + //bnNotify(); + + return TSDB_CODE_MND_ACTION_IN_PROGRESS; +} + +int mnodeInsertAlterDbRow(SDbObj *pDb, void *pMsg) { + SSdbRow desc = { + .type = SDB_OPER_GLOBAL, + .pTable = tsDbSdb, + .pObj = pDb, + .pMsg = pMsg, + }; + + return sdbUpdateRow(&desc); } static int32_t mnodeAlterDb(SDbObj *pDb, SAlterDbMsg *pAlter, void *pMsg) { @@ -1117,14 +1170,14 @@ static int32_t mnodeAlterDb(SDbObj *pDb, SAlterDbMsg *pAlter, void *pMsg) { .pTable = tsDbSdb, .pObj = pDb, .pMsg = pMsg, - .fpRsp = mnodeAlterDbCb + .fpReq = mnodeAlterDbFp }; code = sdbUpdateRow(&row); if (code != TSDB_CODE_SUCCESS && code != TSDB_CODE_MND_ACTION_IN_PROGRESS) { mError("db:%s, failed to alter, reason:%s", pDb->name, tstrerror(code)); } - } +} return code; } diff --git a/src/mnode/src/mnodeVgroup.c b/src/mnode/src/mnodeVgroup.c index 711381374677ba101412f0149a6c45d2454c9f6a..a32da29124016424ce5fe1436f29cca91da3e546 100644 --- a/src/mnode/src/mnodeVgroup.c +++ b/src/mnode/src/mnodeVgroup.c @@ -60,7 +60,6 @@ static int32_t mnodeGetVgroupMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *p static int32_t mnodeRetrieveVgroups(SShowObj *pShow, char *data, int32_t rows, void *pConn); static void mnodeProcessCreateVnodeRsp(SRpcMsg *rpcMsg); static void mnodeProcessAlterVnodeRsp(SRpcMsg *rpcMsg); -static void mnodeProcessSyncVnodeRsp(SRpcMsg *rpcMsg); static void mnodeProcessCompactVnodeRsp(SRpcMsg *rpcMsg); static void mnodeProcessDropVnodeRsp(SRpcMsg *rpcMsg); static int32_t mnodeProcessVnodeCfgMsg(SMnodeMsg *pMsg) ; @@ -238,7 +237,6 @@ int32_t mnodeInitVgroups() { mnodeAddShowFreeIterHandle(TSDB_MGMT_TABLE_VGROUP, mnodeCancelGetNextVgroup); mnodeAddPeerRspHandle(TSDB_MSG_TYPE_MD_CREATE_VNODE_RSP, mnodeProcessCreateVnodeRsp); mnodeAddPeerRspHandle(TSDB_MSG_TYPE_MD_ALTER_VNODE_RSP, mnodeProcessAlterVnodeRsp); - mnodeAddPeerRspHandle(TSDB_MSG_TYPE_MD_ALTER_VNODE_RSP, mnodeProcessSyncVnodeRsp); mnodeAddPeerRspHandle(TSDB_MSG_TYPE_MD_COMPACT_VNODE_RSP, mnodeProcessCompactVnodeRsp); mnodeAddPeerRspHandle(TSDB_MSG_TYPE_MD_DROP_VNODE_RSP, mnodeProcessDropVnodeRsp); mnodeAddPeerMsgHandle(TSDB_MSG_TYPE_DM_CONFIG_VNODE, mnodeProcessVnodeCfgMsg); @@ -273,7 +271,7 @@ void mnodeUpdateVgroup(SVgObj *pVgroup) { if (code != TSDB_CODE_SUCCESS && code != TSDB_CODE_MND_ACTION_IN_PROGRESS) { mError("vgId:%d, failed to update vgroup", pVgroup->vgId); } - mnodeSendAlterVgroupMsg(pVgroup); + mnodeSendAlterVgroupMsg(pVgroup,NULL); } /* @@ -352,7 +350,7 @@ void mnodeUpdateVgroupStatus(SVgObj *pVgroup, SDnodeObj *pDnode, SVnodeLoad *pVl mError("dnode:%d, vgId:%d, vnode cfgVersion:%d:%d repica:%d not match with mnode cfgVersion:%d:%d replica:%d", pDnode->dnodeId, pVload->vgId, pVload->dbCfgVersion, pVload->vgCfgVersion, pVload->replica, pVgroup->pDb->dbCfgVersion, pVgroup->vgCfgVersion, pVgroup->numOfVnodes); - mnodeSendAlterVgroupMsg(pVgroup); + mnodeSendAlterVgroupMsg(pVgroup,NULL); } pVgroup->compact = pVload->compact; } @@ -908,9 +906,9 @@ static SCreateVnodeMsg *mnodeBuildVnodeMsg(SVgObj *pVgroup) { pCfg->totalBlocks = htonl(pDb->cfg.totalBlocks); pCfg->maxTables = htonl(maxTables + 1); pCfg->daysPerFile = htonl(pDb->cfg.daysPerFile); - pCfg->daysToKeep = htonl(pDb->cfg.daysToKeep); - pCfg->daysToKeep1 = htonl(pDb->cfg.daysToKeep1); - pCfg->daysToKeep2 = htonl(pDb->cfg.daysToKeep2); + pCfg->daysToKeep = htonl(pDb->cfg.daysToKeep2); //FROM DB TO VNODE MAP: + pCfg->daysToKeep1 = htonl(pDb->cfg.daysToKeep0); //keep0,keep1,keep2 in SQL is mapped to keep1,keep2,keep in vnode + pCfg->daysToKeep2 = htonl(pDb->cfg.daysToKeep1); //user,client,mnode use keep0,keep1,keep2; vnode use keep1,keep2,keep pCfg->minRowsPerFileBlock = htonl(pDb->cfg.minRowsPerFileBlock); pCfg->maxRowsPerFileBlock = htonl(pDb->cfg.maxRowsPerFileBlock); pCfg->fsyncPeriod = htonl(pDb->cfg.fsyncPeriod); @@ -960,10 +958,10 @@ SRpcEpSet mnodeGetEpSetFromIp(char *ep) { return epSet; } -static void mnodeSendAlterVnodeMsg(SVgObj *pVgroup, SRpcEpSet *epSet) { +static void mnodeSendAlterVnodeMsg(SVgObj *pVgroup, SRpcEpSet *epSet, SMnodeMsg *pMsg) { SAlterVnodeMsg *pAlter = mnodeBuildVnodeMsg(pVgroup); SRpcMsg rpcMsg = { - .ahandle = NULL, + .ahandle = pMsg, .pCont = pAlter, .contLen = pAlter ? sizeof(SAlterVnodeMsg) : 0, .code = 0, @@ -972,14 +970,18 @@ static void mnodeSendAlterVnodeMsg(SVgObj *pVgroup, SRpcEpSet *epSet) { dnodeSendMsgToDnode(epSet, &rpcMsg); } -void mnodeSendAlterVgroupMsg(SVgObj *pVgroup) { +void mnodeSendAlterVgroupMsg(SVgObj *pVgroup,SMnodeMsg *pMsg) { mDebug("vgId:%d, send alter all vnodes msg, numOfVnodes:%d db:%s", pVgroup->vgId, pVgroup->numOfVnodes, pVgroup->dbName); + if (pMsg) { + pMsg->pVgroup = pVgroup; + mnodeIncVgroupRef(pVgroup); + } for (int32_t i = 0; i < pVgroup->numOfVnodes; ++i) { SRpcEpSet epSet = mnodeGetEpSetFromIp(pVgroup->vnodeGid[i].pDnode->dnodeEp); mDebug("vgId:%d, index:%d, send alter vnode msg to dnode %s", pVgroup->vgId, i, pVgroup->vnodeGid[i].pDnode->dnodeEp); - mnodeSendAlterVnodeMsg(pVgroup, &epSet); + mnodeSendAlterVnodeMsg(pVgroup, &epSet,pMsg); } } @@ -1064,11 +1066,27 @@ void mnodeSendCreateVgroupMsg(SVgObj *pVgroup, void *ahandle) { } static void mnodeProcessAlterVnodeRsp(SRpcMsg *rpcMsg) { - mDebug("alter vnode rsp received"); -} + mDebug("alter vnode rsp is received, handle:%p", rpcMsg->ahandle); + if (rpcMsg->ahandle == NULL) return; -static void mnodeProcessSyncVnodeRsp(SRpcMsg *rpcMsg) { - mDebug("sync vnode rsp received"); + SMnodeMsg *mnodeMsg = rpcMsg->ahandle; + mnodeMsg->received++; + if (rpcMsg->code == TSDB_CODE_SUCCESS) { + mnodeMsg->code = rpcMsg->code; + mnodeMsg->successed++; + } + + SVgObj *pVgroup = mnodeMsg->pVgroup; + mDebug("vgId:%d, alter vnode rsp received, result:%s received:%d successed:%d expected:%d, thandle:%p ahandle:%p", + pVgroup->vgId, tstrerror(rpcMsg->code), mnodeMsg->received, mnodeMsg->successed, mnodeMsg->expected, + mnodeMsg->rpcMsg.handle, rpcMsg->ahandle); + + if (mnodeMsg->received != mnodeMsg->expected) return; + + int32_t code = mnodeInsertAlterDbRow(pVgroup->pDb, mnodeMsg); + if (code != TSDB_CODE_SUCCESS && code != TSDB_CODE_MND_ACTION_IN_PROGRESS) { + dnodeSendRpcMWriteRsp(mnodeMsg, code); + } } static void mnodeProcessCompactVnodeRsp(SRpcMsg *rpcMsg) { mDebug("compact vnode rsp received"); diff --git a/src/os/inc/osTime.h b/src/os/inc/osTime.h index 4743a8c160ce8228a2c564129f00ec2962038c56..f013a2f7d112c07e2b88b4329ff867e50c25ec0d 100644 --- a/src/os/inc/osTime.h +++ b/src/os/inc/osTime.h @@ -55,6 +55,13 @@ static FORCE_INLINE int64_t taosGetTimestampUs() { return (int64_t)systemTime.tv_sec * 1000000L + (int64_t)systemTime.tv_usec; } +//@return timestamp in nanosecond +static FORCE_INLINE int64_t taosGetTimestampNs() { + struct timespec systemTime = {0}; + clock_gettime(CLOCK_REALTIME, &systemTime); + return (int64_t)systemTime.tv_sec * 1000000000L + (int64_t)systemTime.tv_nsec; +} + /* * @return timestamp decided by global conf variable, tsTimePrecision * if precision == TSDB_TIME_PRECISION_MICRO, it returns timestamp in microsecond. @@ -63,7 +70,9 @@ static FORCE_INLINE int64_t taosGetTimestampUs() { static FORCE_INLINE int64_t taosGetTimestamp(int32_t precision) { if (precision == TSDB_TIME_PRECISION_MICRO) { return taosGetTimestampUs(); - } else { + } else if (precision == TSDB_TIME_PRECISION_NANO) { + return taosGetTimestampNs(); + }else { return taosGetTimestampMs(); } } @@ -88,12 +97,13 @@ int64_t taosTimeAdd(int64_t t, int64_t duration, char unit, int32_t precision); int64_t taosTimeTruncate(int64_t t, const SInterval* pInterval, int32_t precision); int32_t taosTimeCountInterval(int64_t skey, int64_t ekey, int64_t interval, char unit, int32_t precision); -int32_t parseAbsoluteDuration(char* token, int32_t tokenlen, int64_t* ts); -int32_t parseNatualDuration(const char* token, int32_t tokenLen, int64_t* duration, char* unit); +int32_t parseAbsoluteDuration(char* token, int32_t tokenlen, int64_t* ts, int32_t timePrecision); +int32_t parseNatualDuration(const char* token, int32_t tokenLen, int64_t* duration, char* unit, int32_t timePrecision); int32_t taosParseTime(char* timestr, int64_t* time, int32_t len, int32_t timePrec, int8_t dayligth); void deltaToUtcInitOnce(); +int64_t convertTimePrecision(int64_t time, int32_t fromPrecision, int32_t toPrecision); #ifdef __cplusplus } #endif diff --git a/src/os/src/detail/osString.c b/src/os/src/detail/osString.c index 2c49797d83dd4bb53b2fef69091e28be7194461e..fdc70b667e08face21554c99e2109bc49cf41cbf 100644 --- a/src/os/src/detail/osString.c +++ b/src/os/src/detail/osString.c @@ -59,6 +59,9 @@ bool taosMbsToUcs4(char *mbs, size_t mbsLength, char *ucs4, int32_t ucs4_max_len iconv_close(cd); if (len != NULL) { *len = (int32_t)(ucs4_max_len - outLeft); + if (*len < 0) { + return false; + } } return true; diff --git a/src/os/src/detail/osTime.c b/src/os/src/detail/osTime.c index 67e0c2642e42f66229c437e603f7062edf571f34..4d64e14d9415a256b9ef5032db3de35bcfeedb79 100644 --- a/src/os/src/detail/osTime.c +++ b/src/os/src/detail/osTime.c @@ -14,7 +14,13 @@ */ #define _BSD_SOURCE + +#ifdef DARWIN #define _XOPEN_SOURCE +#else +#define _XOPEN_SOURCE 500 +#endif + #define _DEFAULT_SOURCE #include "os.h" @@ -43,7 +49,7 @@ */ int64_t user_mktime64(const unsigned int year0, const unsigned int mon0, const unsigned int day, const unsigned int hour, - const unsigned int min, const unsigned int sec, int64_t timezone) + const unsigned int min, const unsigned int sec, int64_t time_zone) { unsigned int mon = mon0, year = year0; @@ -61,7 +67,7 @@ int64_t user_mktime64(const unsigned int year0, const unsigned int mon0, res = res*24; res = ((res + hour) * 60 + min) * 60 + sec; - return (res + timezone); + return (res + time_zone); } // ==== mktime() kernel code =================// @@ -119,8 +125,9 @@ int64_t parseFraction(char* str, char** end, int32_t timePrec) { const int32_t MILLI_SEC_FRACTION_LEN = 3; const int32_t MICRO_SEC_FRACTION_LEN = 6; + const int32_t NANO_SEC_FRACTION_LEN = 9; - int32_t factor[6] = {1, 10, 100, 1000, 10000, 100000}; + int32_t factor[9] = {1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000}; int32_t times = 1; while (str[i] >= '0' && str[i] <= '9') { @@ -140,12 +147,17 @@ int64_t parseFraction(char* str, char** end, int32_t timePrec) { } times = MILLI_SEC_FRACTION_LEN - i; - } else { - assert(timePrec == TSDB_TIME_PRECISION_MICRO); + } else if (timePrec == TSDB_TIME_PRECISION_MICRO) { if (i >= MICRO_SEC_FRACTION_LEN) { i = MICRO_SEC_FRACTION_LEN; } times = MICRO_SEC_FRACTION_LEN - i; + } else { + assert(timePrec == TSDB_TIME_PRECISION_NANO); + if (i >= NANO_SEC_FRACTION_LEN) { + i = NANO_SEC_FRACTION_LEN; + } + times = NANO_SEC_FRACTION_LEN - i; } fraction = strnatoi(str, i) * factor[times]; @@ -202,7 +214,9 @@ int32_t parseTimezone(char* str, int64_t* tzOffset) { * 2013-04-12T15:52:01.123+0800 */ int32_t parseTimeWithTz(char* timestr, int64_t* time, int32_t timePrec) { - int64_t factor = (timePrec == TSDB_TIME_PRECISION_MILLI) ? 1000 : 1000000; + + int64_t factor = (timePrec == TSDB_TIME_PRECISION_MILLI) ? 1000 : + (timePrec == TSDB_TIME_PRECISION_MICRO ? 1000000 : 1000000000); int64_t tzOffset = 0; struct tm tm = {0}; @@ -287,7 +301,8 @@ int32_t parseLocaltime(char* timestr, int64_t* time, int32_t timePrec) { } } - int64_t factor = (timePrec == TSDB_TIME_PRECISION_MILLI) ? 1000 : 1000000; + int64_t factor = (timePrec == TSDB_TIME_PRECISION_MILLI) ? 1000 : + (timePrec == TSDB_TIME_PRECISION_MICRO ? 1000000 : 1000000000); *time = factor * seconds + fraction; return 0; @@ -315,37 +330,50 @@ int32_t parseLocaltimeWithDst(char* timestr, int64_t* time, int32_t timePrec) { } } - int64_t factor = (timePrec == TSDB_TIME_PRECISION_MILLI) ? 1000 : 1000000; + int64_t factor = (timePrec == TSDB_TIME_PRECISION_MILLI) ? 1000 : + (timePrec == TSDB_TIME_PRECISION_MICRO ? 1000000 : 1000000000); *time = factor * seconds + fraction; return 0; } - -static int32_t getDurationInUs(int64_t val, char unit, int64_t* result) { - *result = val; - - int64_t factor = 1000L; +int64_t convertTimePrecision(int64_t time, int32_t fromPrecision, int32_t toPrecision) { + assert(fromPrecision == TSDB_TIME_PRECISION_MILLI || + fromPrecision == TSDB_TIME_PRECISION_MICRO || + fromPrecision == TSDB_TIME_PRECISION_NANO); + assert(toPrecision == TSDB_TIME_PRECISION_MILLI || + toPrecision == TSDB_TIME_PRECISION_MICRO || + toPrecision == TSDB_TIME_PRECISION_NANO); + static double factors[3][3] = { {1., 1000., 1000000.}, + {1.0 / 1000, 1., 1000.}, + {1.0 / 1000000, 1.0 / 1000, 1.} }; + return (int64_t)((double)time * factors[fromPrecision][toPrecision]); +} +static int32_t getDuration(int64_t val, char unit, int64_t* result, int32_t timePrecision) { switch (unit) { case 's': - (*result) *= MILLISECOND_PER_SECOND*factor; + (*result) = convertTimePrecision(val * MILLISECOND_PER_SECOND, TSDB_TIME_PRECISION_MILLI, timePrecision); break; case 'm': - (*result) *= MILLISECOND_PER_MINUTE*factor; + (*result) = convertTimePrecision(val * MILLISECOND_PER_MINUTE, TSDB_TIME_PRECISION_MILLI, timePrecision); break; case 'h': - (*result) *= MILLISECOND_PER_HOUR*factor; + (*result) = convertTimePrecision(val * MILLISECOND_PER_HOUR, TSDB_TIME_PRECISION_MILLI, timePrecision); break; case 'd': - (*result) *= MILLISECOND_PER_DAY*factor; + (*result) = convertTimePrecision(val * MILLISECOND_PER_DAY, TSDB_TIME_PRECISION_MILLI, timePrecision); break; case 'w': - (*result) *= MILLISECOND_PER_WEEK*factor; + (*result) = convertTimePrecision(val * MILLISECOND_PER_WEEK, TSDB_TIME_PRECISION_MILLI, timePrecision); break; case 'a': - (*result) *= factor; + (*result) = convertTimePrecision(val, TSDB_TIME_PRECISION_MILLI, timePrecision); break; case 'u': + (*result) = convertTimePrecision(val, TSDB_TIME_PRECISION_MICRO, timePrecision); + break; + case 'b': + (*result) = convertTimePrecision(val, TSDB_TIME_PRECISION_NANO, timePrecision); break; default: { return -1; @@ -357,6 +385,8 @@ static int32_t getDurationInUs(int64_t val, char unit, int64_t* result) { } /* + * b - nanoseconds; + * u - microseconds; * a - Millionseconds * s - Seconds * m - Minutes @@ -366,7 +396,7 @@ static int32_t getDurationInUs(int64_t val, char unit, int64_t* result) { * n - Months (30 days) * y - Years (365 days) */ -int32_t parseAbsoluteDuration(char* token, int32_t tokenlen, int64_t* duration) { +int32_t parseAbsoluteDuration(char* token, int32_t tokenlen, int64_t* duration, int32_t timePrecision) { errno = 0; char* endPtr = NULL; @@ -382,10 +412,10 @@ int32_t parseAbsoluteDuration(char* token, int32_t tokenlen, int64_t* duration) return -1; } - return getDurationInUs(timestamp, unit, duration); + return getDuration(timestamp, unit, duration, timePrecision); } -int32_t parseNatualDuration(const char* token, int32_t tokenLen, int64_t* duration, char* unit) { +int32_t parseNatualDuration(const char* token, int32_t tokenLen, int64_t* duration, char* unit, int32_t timePrecision) { errno = 0; /* get the basic numeric value */ @@ -399,7 +429,7 @@ int32_t parseNatualDuration(const char* token, int32_t tokenLen, int64_t* durati return 0; } - return getDurationInUs(*duration, *unit, duration); + return getDuration(*duration, *unit, duration, timePrecision); } int64_t taosTimeAdd(int64_t t, int64_t duration, char unit, int32_t precision) { diff --git a/src/plugins/http/inc/httpJson.h b/src/plugins/http/inc/httpJson.h index 4d182d0132528367a8e25b8f72329331be2cb5c5..3595ad926fa08a7ba87fc758c2b0472d34617488 100644 --- a/src/plugins/http/inc/httpJson.h +++ b/src/plugins/http/inc/httpJson.h @@ -64,8 +64,8 @@ void httpJsonOriginString(JsonBuf* buf, char* sVal, int32_t len); void httpJsonStringForTransMean(JsonBuf* buf, char* SVal, int32_t maxLen); void httpJsonInt64(JsonBuf* buf, int64_t num); void httpJsonUInt64(JsonBuf* buf, uint64_t num); -void httpJsonTimestamp(JsonBuf* buf, int64_t t, bool us); -void httpJsonUtcTimestamp(JsonBuf* buf, int64_t t, bool us); +void httpJsonTimestamp(JsonBuf* buf, int64_t t, int32_t timePrecision); +void httpJsonUtcTimestamp(JsonBuf* buf, int64_t t, int32_t timePrecision); void httpJsonInt(JsonBuf* buf, int32_t num); void httpJsonUInt(JsonBuf* buf, uint32_t num); void httpJsonFloat(JsonBuf* buf, float num); diff --git a/src/plugins/http/src/httpJson.c b/src/plugins/http/src/httpJson.c index 19166e720f0e517ccd1a793742836ae4bc245bd1..df4c4fbc63d469c22ea13273564bec49562f35a9 100644 --- a/src/plugins/http/src/httpJson.c +++ b/src/plugins/http/src/httpJson.c @@ -262,42 +262,92 @@ void httpJsonUInt64(JsonBuf* buf, uint64_t num) { buf->lst += snprintf(buf->lst, MAX_NUM_STR_SZ, "%" PRIu64, num); } -void httpJsonTimestamp(JsonBuf* buf, int64_t t, bool us) { +void httpJsonTimestamp(JsonBuf* buf, int64_t t, int32_t timePrecision) { char ts[35] = {0}; struct tm* ptm; - int32_t precision = 1000; - if (us) { - precision = 1000000; + + int32_t fractionLen; + char* format = NULL; + time_t quot = 0; + long mod = 0; + + switch (timePrecision) { + case TSDB_TIME_PRECISION_MILLI: { + quot = t / 1000; + fractionLen = 5; + format = ".%03" PRId64; + mod = t % 1000; + break; + } + + case TSDB_TIME_PRECISION_MICRO: { + quot = t / 1000000; + fractionLen = 8; + format = ".%06" PRId64; + mod = t % 1000000; + break; + } + + case TSDB_TIME_PRECISION_NANO: { + quot = t / 1000000000; + fractionLen = 11; + format = ".%09" PRId64; + mod = t % 1000000000; + break; + } + + default: + assert(false); } - time_t tt = t / precision; - ptm = localtime(&tt); + ptm = localtime("); int32_t length = (int32_t)strftime(ts, 35, "%Y-%m-%d %H:%M:%S", ptm); - if (us) { - length += snprintf(ts + length, 8, ".%06" PRId64, t % precision); - } else { - length += snprintf(ts + length, 5, ".%03" PRId64, t % precision); - } + length += snprintf(ts + length, fractionLen, format, mod); httpJsonString(buf, ts, length); } -void httpJsonUtcTimestamp(JsonBuf* buf, int64_t t, bool us) { +void httpJsonUtcTimestamp(JsonBuf* buf, int64_t t, int32_t timePrecision) { char ts[40] = {0}; struct tm* ptm; - int32_t precision = 1000; - if (us) { - precision = 1000000; + + int32_t fractionLen; + char* format = NULL; + time_t quot = 0; + long mod = 0; + + switch (timePrecision) { + case TSDB_TIME_PRECISION_MILLI: { + quot = t / 1000; + fractionLen = 5; + format = ".%03" PRId64; + mod = t % 1000; + break; + } + + case TSDB_TIME_PRECISION_MICRO: { + quot = t / 1000000; + fractionLen = 8; + format = ".%06" PRId64; + mod = t % 1000000; + break; + } + + case TSDB_TIME_PRECISION_NANO: { + quot = t / 1000000000; + fractionLen = 11; + format = ".%09" PRId64; + mod = t % 1000000000; + break; + } + + default: + assert(false); } - time_t tt = t / precision; - ptm = localtime(&tt); + ptm = localtime("); int32_t length = (int32_t)strftime(ts, 40, "%Y-%m-%dT%H:%M:%S", ptm); - if (us) { - length += snprintf(ts + length, 8, ".%06" PRId64, t % precision); - } else { - length += snprintf(ts + length, 5, ".%03" PRId64, t % precision); - } + length += snprintf(ts + length, fractionLen, format, mod); length += (int32_t)strftime(ts + length, 40 - length, "%z", ptm); httpJsonString(buf, ts, length); diff --git a/src/plugins/http/src/httpRestJson.c b/src/plugins/http/src/httpRestJson.c index 60c23e603e5107e858db2138d1aed87d5f8a5e1b..47f2d4ff5bcc513aafb8ea8f4e2a85db5a35b12a 100644 --- a/src/plugins/http/src/httpRestJson.c +++ b/src/plugins/http/src/httpRestJson.c @@ -186,13 +186,11 @@ bool restBuildSqlJson(HttpContext *pContext, HttpSqlCmd *cmd, TAOS_RES *result, break; case TSDB_DATA_TYPE_TIMESTAMP: if (timestampFormat == REST_TIMESTAMP_FMT_LOCAL_STRING) { - httpJsonTimestamp(jsonBuf, *((int64_t *)row[i]), - taos_result_precision(result) == TSDB_TIME_PRECISION_MICRO); + httpJsonTimestamp(jsonBuf, *((int64_t *)row[i]), taos_result_precision(result)); } else if (timestampFormat == REST_TIMESTAMP_FMT_TIMESTAMP) { httpJsonInt64(jsonBuf, *((int64_t *)row[i])); } else { - httpJsonUtcTimestamp(jsonBuf, *((int64_t *)row[i]), - taos_result_precision(result) == TSDB_TIME_PRECISION_MICRO); + httpJsonUtcTimestamp(jsonBuf, *((int64_t *)row[i]), taos_result_precision(result)); } break; default: diff --git a/src/plugins/monitor/src/monMain.c b/src/plugins/monitor/src/monMain.c index d9f7d81ebd3eefe77569deb30b75c227ff79e04f..2c4a0c1a4c56e560a9ffe5ec007cc51f9d7f9e24 100644 --- a/src/plugins/monitor/src/monMain.c +++ b/src/plugins/monitor/src/monMain.c @@ -184,11 +184,17 @@ static void *monThreadFunc(void *param) { static void monBuildMonitorSql(char *sql, int32_t cmd) { memset(sql, 0, SQL_LENGTH); +#ifdef _STORAGE + char *keepValue = "30,30,30"; +#else + char *keepValue = "30"; +#endif + if (cmd == MON_CMD_CREATE_DB) { snprintf(sql, SQL_LENGTH, - "create database if not exists %s replica 1 days 10 keep 30 cache %d " + "create database if not exists %s replica 1 days 10 keep %s cache %d " "blocks %d precision 'us'", - tsMonitorDbName, TSDB_MIN_CACHE_BLOCK_SIZE, TSDB_MIN_TOTAL_BLOCKS); + tsMonitorDbName, keepValue, TSDB_MIN_CACHE_BLOCK_SIZE, TSDB_MIN_TOTAL_BLOCKS); } else if (cmd == MON_CMD_CREATE_MT_DN) { snprintf(sql, SQL_LENGTH, "create table if not exists %s.dn(ts timestamp" diff --git a/src/query/inc/qAggMain.h b/src/query/inc/qAggMain.h index 47c61fc4446973b04bd558559e0a335fb944dbd2..57e7d2982f73432b9559c4ec231cf72e9680363e 100644 --- a/src/query/inc/qAggMain.h +++ b/src/query/inc/qAggMain.h @@ -66,17 +66,19 @@ extern "C" { #define TSDB_FUNC_RATE 29 #define TSDB_FUNC_IRATE 30 #define TSDB_FUNC_TID_TAG 31 -#define TSDB_FUNC_BLKINFO 32 - -#define TSDB_FUNC_HISTOGRAM 33 -#define TSDB_FUNC_HLL 34 -#define TSDB_FUNC_MODE 35 -#define TSDB_FUNC_SAMPLE 36 -#define TSDB_FUNC_CEIL 37 -#define TSDB_FUNC_FLOOR 38 -#define TSDB_FUNC_ROUND 39 -#define TSDB_FUNC_MAVG 40 -#define TSDB_FUNC_CSUM 41 +#define TSDB_FUNC_DERIVATIVE 32 +#define TSDB_FUNC_BLKINFO 33 + + +#define TSDB_FUNC_HISTOGRAM 34 +#define TSDB_FUNC_HLL 35 +#define TSDB_FUNC_MODE 36 +#define TSDB_FUNC_SAMPLE 37 +#define TSDB_FUNC_CEIL 38 +#define TSDB_FUNC_FLOOR 39 +#define TSDB_FUNC_ROUND 40 +#define TSDB_FUNC_MAVG 41 +#define TSDB_FUNC_CSUM 42 #define TSDB_FUNCSTATE_SO 0x1u // single output #define TSDB_FUNCSTATE_MO 0x2u // dynamic number of output, not multinumber of output e.g., TOP/BOTTOM diff --git a/src/query/inc/qExecutor.h b/src/query/inc/qExecutor.h index b5b4fb58548f5067c26644cf63e0a5911b69ad8b..955dd734cf58582ecfe1bbf9871525be0ebc161c 100644 --- a/src/query/inc/qExecutor.h +++ b/src/query/inc/qExecutor.h @@ -113,6 +113,7 @@ typedef struct SColumnFilterElem { int16_t bytes; // column length __filter_func_t fp; SColumnFilterInfo filterInfo; + void *q; } SColumnFilterElem; typedef struct SSingleColumnFilterInfo { @@ -185,6 +186,7 @@ typedef struct SQueryAttr { bool queryBlockDist; // if query data block distribution bool stabledev; // super table stddev query bool tsCompQuery; // is tscomp query + bool diffQuery; // is diff query bool simpleAgg; bool pointInterpQuery; // point interpolation query bool needReverseScan; // need reverse scan @@ -245,6 +247,7 @@ typedef struct SQueryRuntimeEnv { void* pQueryHandle; int32_t prevGroupId; // previous executed group id + bool enableGroupData; SDiskbasedResultBuf* pResultBuf; // query result buffer based on blocked-wised disk file SHashObj* pResultRowHashTable; // quick locate the window object for each result char* keyBuf; // window key buffer @@ -386,6 +389,7 @@ typedef struct STableScanInfo { int64_t elapsedTime; int32_t tableIndex; + int32_t prevGroupId; // previous table group id } STableScanInfo; typedef struct STagScanInfo { @@ -460,6 +464,7 @@ typedef struct SSWindowOperatorInfo { TSKEY prevTs; // previous timestamp int32_t numOfRows; // number of rows int32_t start; // start row index + bool reptScan; // next round scan } SSWindowOperatorInfo; typedef struct SStateWindowOperatorInfo { @@ -469,7 +474,7 @@ typedef struct SStateWindowOperatorInfo { int32_t colIndex; // start row index int32_t start; char* prevData; // previous data - + bool reptScan; } SStateWindowOperatorInfo ; typedef struct SDistinctOperatorInfo { diff --git a/src/query/inc/qSqlparser.h b/src/query/inc/qSqlparser.h index 5d6f25e08c740da6c5554fc5609b341a277e3f4e..c6f667475ee7b061fcbc86be7a2aa8fac7282e8e 100644 --- a/src/query/inc/qSqlparser.h +++ b/src/query/inc/qSqlparser.h @@ -46,7 +46,7 @@ enum SQL_NODE_FROM_TYPE { enum SQL_EXPR_FLAG { EXPR_FLAG_TS_ERROR = 1, - EXPR_FLAG_US_TIMESTAMP = 2, + EXPR_FLAG_NS_TIMESTAMP = 2, EXPR_FLAG_TIMESTAMP_VAR = 3, }; diff --git a/src/query/inc/qTableMeta.h b/src/query/inc/qTableMeta.h index 4fc252b644efab0c6bfdb97b19c3af3ef9c68920..ec389de9e6dde48f3c7b0b200184ad75c4e0ec0f 100644 --- a/src/query/inc/qTableMeta.h +++ b/src/query/inc/qTableMeta.h @@ -138,6 +138,7 @@ typedef struct SQueryInfo { bool hasFilter; bool onlyTagQuery; bool orderProjectQuery; +// bool diffQuery; bool stateWindow; } SQueryInfo; diff --git a/src/query/inc/sql.y b/src/query/inc/sql.y index 17ba9cb96eec9cda32f860f8e1c727cb98b11a7d..2a37b1fc2d81ca2f63cea18c521ed60a310881c9 100644 --- a/src/query/inc/sql.y +++ b/src/query/inc/sql.y @@ -242,9 +242,18 @@ acct_optr(Y) ::= pps(C) tseries(D) storage(P) streams(F) qtime(Q) dbs(E) users(K Y.stat = M; } +%type intitemlist {SArray*} +%destructor intitemlist {taosArrayDestroy($$);} + +%type intitem {tVariant} +intitemlist(A) ::= intitemlist(X) COMMA intitem(Y). { A = tVariantListAppend(X, &Y, -1); } +intitemlist(A) ::= intitem(X). { A = tVariantListAppend(NULL, &X, -1); } + +intitem(A) ::= INTEGER(X). { toTSDBType(X.type); tVariantCreate(&A, &X); } + %type keep {SArray*} %destructor keep {taosArrayDestroy($$);} -keep(Y) ::= KEEP tagitemlist(X). { Y = X; } +keep(Y) ::= KEEP intitemlist(X). { Y = X; } cache(Y) ::= CACHE INTEGER(X). { Y = X; } replica(Y) ::= REPLICA INTEGER(X). { Y = X; } @@ -563,10 +572,8 @@ session_option(X) ::= SESSION LP ids(V) cpxName(Z) COMMA tmvar(Y) RP. { X.gap = Y; } %type windowstate_option {SWindowStateVal} -windowstate_option(X) ::= . {X.col.n = 0;} -windowstate_option(X) ::= STATE_WINDOW LP ids(V) RP. { - X.col = V; -} +windowstate_option(X) ::= . { X.col.n = 0; X.col.z = NULL;} +windowstate_option(X) ::= STATE_WINDOW LP ids(V) RP. { X.col = V; } %type fill_opt {SArray*} %destructor fill_opt {taosArrayDestroy($$);} diff --git a/src/query/src/qAggMain.c b/src/query/src/qAggMain.c index ba6efcabb2f0788908485d3af246a6e0855ed2a1..5dea37ee0b36c1b7495446bb42f84ce482b14e3e 100644 --- a/src/query/src/qAggMain.c +++ b/src/query/src/qAggMain.c @@ -161,6 +161,14 @@ typedef struct SRateInfo { bool isIRate; // true for IRate functions, false for Rate functions } SRateInfo; +typedef struct SDerivInfo { + double prevValue; // previous value + TSKEY prevTs; // previous timestamp + bool ignoreNegative;// ignore the negative value + int64_t tsWindow; // time window for derivative + bool valueSet; // the value has been set already +} SDerivInfo; + int32_t getResultDataInfo(int32_t dataType, int32_t dataBytes, int32_t functionId, int32_t param, int16_t *type, int16_t *bytes, int32_t *interBytes, int16_t extLength, bool isSuperTable) { if (!isValidDataType(dataType)) { @@ -189,7 +197,9 @@ int32_t getResultDataInfo(int32_t dataType, int32_t dataBytes, int32_t functionI *bytes = (int16_t)(dataBytes + sizeof(int16_t) + sizeof(int64_t) + sizeof(int32_t) + sizeof(int32_t) + VARSTR_HEADER_SIZE); *interBytes = 0; return TSDB_CODE_SUCCESS; - } else if (functionId == TSDB_FUNC_BLKINFO) { + } + + if (functionId == TSDB_FUNC_BLKINFO) { *type = TSDB_DATA_TYPE_BINARY; *bytes = 16384; *interBytes = 0; @@ -216,7 +226,14 @@ int32_t getResultDataInfo(int32_t dataType, int32_t dataBytes, int32_t functionI *interBytes = POINTER_BYTES; return TSDB_CODE_SUCCESS; } - + + if (functionId == TSDB_FUNC_DERIVATIVE) { + *type = TSDB_DATA_TYPE_DOUBLE; + *bytes = sizeof(double); // this results is compressed ts data, only one byte + *interBytes = sizeof(SDerivInfo); + return TSDB_CODE_SUCCESS; + } + if (isSuperTable) { if (functionId == TSDB_FUNC_MIN || functionId == TSDB_FUNC_MAX) { *type = TSDB_DATA_TYPE_BINARY; @@ -3393,7 +3410,7 @@ enum { }; static bool diff_function_setup(SQLFunctionCtx *pCtx) { - if (function_setup(pCtx)) { + if (!function_setup(pCtx)) { return false; } @@ -3402,16 +3419,234 @@ static bool diff_function_setup(SQLFunctionCtx *pCtx) { return false; } +static bool deriv_function_setup(SQLFunctionCtx *pCtx) { + if (!function_setup(pCtx)) { + return false; + } + + // diff function require the value is set to -1 + SResultRowCellInfo *pResInfo = GET_RES_INFO(pCtx); + SDerivInfo* pDerivInfo = GET_ROWCELL_INTERBUF(pResInfo); + + pDerivInfo->ignoreNegative = pCtx->param[1].i64; + pDerivInfo->prevTs = -1; + pDerivInfo->tsWindow = pCtx->param[0].i64; + pDerivInfo->valueSet = false; + return false; +} + +static void deriv_function(SQLFunctionCtx *pCtx) { + SResultRowCellInfo *pResInfo = GET_RES_INFO(pCtx); + SDerivInfo* pDerivInfo = GET_ROWCELL_INTERBUF(pResInfo); + + void *data = GET_INPUT_DATA_LIST(pCtx); + + int32_t notNullElems = 0; + int32_t step = GET_FORWARD_DIRECTION_FACTOR(pCtx->order); + int32_t i = (pCtx->order == TSDB_ORDER_ASC) ? 0 : pCtx->size - 1; + + TSKEY *pTimestamp = pCtx->ptsOutputBuf; + TSKEY *tsList = GET_TS_LIST(pCtx); + + double *pOutput = (double *)pCtx->pOutput; + + switch (pCtx->inputType) { + case TSDB_DATA_TYPE_INT: { + int32_t *pData = (int32_t *)data; + for (; i < pCtx->size && i >= 0; i += step) { + if (pCtx->hasNull && isNull((const char *)&pData[i], pCtx->inputType)) { + continue; + } + + if (!pDerivInfo->valueSet) { // initial value is not set yet + pDerivInfo->valueSet = true; + } else { + *pOutput = ((pData[i] - pDerivInfo->prevValue) * pDerivInfo->tsWindow) / (tsList[i] - pDerivInfo->prevTs); + if (pDerivInfo->ignoreNegative && *pOutput < 0) { + } else { + *pTimestamp = tsList[i]; + pOutput += 1; + pTimestamp += 1; + notNullElems++; + } + } + + pDerivInfo->prevValue = pData[i]; + pDerivInfo->prevTs = tsList[i]; + } + + break; + }; + + case TSDB_DATA_TYPE_BIGINT: { + int64_t *pData = (int64_t *)data; + for (; i < pCtx->size && i >= 0; i += step) { + if (pCtx->hasNull && isNull((const char *)&pData[i], pCtx->inputType)) { + continue; + } + + if (!pDerivInfo->valueSet) { // initial value is not set yet + pDerivInfo->valueSet = true; + } else { + *pOutput = ((pData[i] - pDerivInfo->prevValue) * pDerivInfo->tsWindow) / (tsList[i] - pDerivInfo->prevTs); + if (pDerivInfo->ignoreNegative && *pOutput < 0) { + } else { + *pTimestamp = tsList[i]; + pOutput += 1; + pTimestamp += 1; + notNullElems++; + } + } + + pDerivInfo->prevValue = (double) pData[i]; + pDerivInfo->prevTs = tsList[i]; + } + break; + } + case TSDB_DATA_TYPE_DOUBLE: { + double *pData = (double *)data; + + for (; i < pCtx->size && i >= 0; i += step) { + if (pCtx->hasNull && isNull((const char *)&pData[i], pCtx->inputType)) { + continue; + } + + if (!pDerivInfo->valueSet) { // initial value is not set yet + pDerivInfo->valueSet = true; + } else { + *pOutput = ((pData[i] - pDerivInfo->prevValue) * pDerivInfo->tsWindow) / (tsList[i] - pDerivInfo->prevTs); + if (pDerivInfo->ignoreNegative && *pOutput < 0) { + } else { + *pTimestamp = tsList[i]; + pOutput += 1; + pTimestamp += 1; + notNullElems++; + } + } + + pDerivInfo->prevValue = pData[i]; + pDerivInfo->prevTs = tsList[i]; + } + break; + } + + case TSDB_DATA_TYPE_FLOAT: { + float *pData = (float *)data; + + for (; i < pCtx->size && i >= 0; i += step) { + if (pCtx->hasNull && isNull((const char *)&pData[i], pCtx->inputType)) { + continue; + } + + if (!pDerivInfo->valueSet) { // initial value is not set yet + pDerivInfo->valueSet = true; + } else { + *pOutput = ((pData[i] - pDerivInfo->prevValue) * pDerivInfo->tsWindow) / (tsList[i] - pDerivInfo->prevTs); + if (pDerivInfo->ignoreNegative && *pOutput < 0) { + } else { + *pTimestamp = tsList[i]; + pOutput += 1; + pTimestamp += 1; + notNullElems++; + } + } + + pDerivInfo->prevValue = pData[i]; + pDerivInfo->prevTs = tsList[i]; + } + break; + } + + case TSDB_DATA_TYPE_SMALLINT: { + int16_t *pData = (int16_t *)data; + for (; i < pCtx->size && i >= 0; i += step) { + if (pCtx->hasNull && isNull((const char *)&pData[i], pCtx->inputType)) { + continue; + } + + if (!pDerivInfo->valueSet) { // initial value is not set yet + pDerivInfo->valueSet = true; + } else { + *pOutput = ((pData[i] - pDerivInfo->prevValue) * pDerivInfo->tsWindow) / (tsList[i] - pDerivInfo->prevTs); + if (pDerivInfo->ignoreNegative && *pOutput < 0) { + } else { + *pTimestamp = tsList[i]; + pOutput += 1; + pTimestamp += 1; + notNullElems++; + } + } + + pDerivInfo->prevValue = pData[i]; + pDerivInfo->prevTs = tsList[i]; + } + break; + } + + case TSDB_DATA_TYPE_TINYINT: { + int8_t *pData = (int8_t *)data; + for (; i < pCtx->size && i >= 0; i += step) { + if (pCtx->hasNull && isNull((char *)&pData[i], pCtx->inputType)) { + continue; + } + + if (!pDerivInfo->valueSet) { // initial value is not set yet + pDerivInfo->valueSet = true; + } else { + *pOutput = ((pData[i] - pDerivInfo->prevValue) * pDerivInfo->tsWindow) / (tsList[i] - pDerivInfo->prevTs); + if (pDerivInfo->ignoreNegative && *pOutput < 0) { + } else { + *pTimestamp = tsList[i]; + + pOutput += 1; + pTimestamp += 1; + notNullElems++; + } + } + + pDerivInfo->prevValue = pData[i]; + pDerivInfo->prevTs = tsList[i]; + } + break; + } + default: + qError("error input type"); + } + + // initial value is not set yet, all data block are null + if (!pDerivInfo->valueSet || notNullElems <= 0) { + /* + * 1. current block and blocks before are full of null + * 2. current block may be null value + */ + assert(pCtx->hasNull); + } else { + GET_RES_INFO(pCtx)->numOfRes += notNullElems; + } +} + +#define DIFF_IMPL(ctx, d, type) \ + do { \ + if ((ctx)->param[1].nType == INITIAL_VALUE_NOT_ASSIGNED) { \ + (ctx)->param[1].nType = (ctx)->inputType; \ + *(type *)&(ctx)->param[1].i64 = *(type *)(d); \ + } else { \ + *(type *)(ctx)->pOutput = *(type *)(d) - (*(type *)(&(ctx)->param[1].i64)); \ + *(type *)(&(ctx)->param[1].i64) = *(type *)(d); \ + *(int64_t *)(ctx)->ptsOutputBuf = GET_TS_DATA(ctx, index); \ + } \ + } while (0); + // TODO difference in date column static void diff_function(SQLFunctionCtx *pCtx) { void *data = GET_INPUT_DATA_LIST(pCtx); bool isFirstBlock = (pCtx->param[1].nType == INITIAL_VALUE_NOT_ASSIGNED); - + int32_t notNullElems = 0; - + int32_t step = GET_FORWARD_DIRECTION_FACTOR(pCtx->order); int32_t i = (pCtx->order == TSDB_ORDER_ASC) ? 0 : pCtx->size - 1; - + TSKEY* pTimestamp = pCtx->ptsOutputBuf; TSKEY* tsList = GET_TS_LIST(pCtx); @@ -3419,29 +3654,19 @@ static void diff_function(SQLFunctionCtx *pCtx) { case TSDB_DATA_TYPE_INT: { int32_t *pData = (int32_t *)data; int32_t *pOutput = (int32_t *)pCtx->pOutput; - + for (; i < pCtx->size && i >= 0; i += step) { if (pCtx->hasNull && isNull((const char*) &pData[i], pCtx->inputType)) { continue; } - - if (pCtx->param[1].nType == INITIAL_VALUE_NOT_ASSIGNED) { // initial value is not set yet - pCtx->param[1].i64 = pData[i]; - pCtx->param[1].nType = pCtx->inputType; - } else if ((i == 0 && pCtx->order == TSDB_ORDER_ASC) || (i == pCtx->size - 1 && pCtx->order == TSDB_ORDER_DESC)) { - *pOutput = (int32_t)(pData[i] - pCtx->param[1].i64); - *pTimestamp = tsList[i]; - - pOutput += 1; - pTimestamp += 1; - } else { + + if (pCtx->param[1].nType != INITIAL_VALUE_NOT_ASSIGNED) { // initial value is not set yet *pOutput = (int32_t)(pData[i] - pCtx->param[1].i64); // direct previous may be null *pTimestamp = tsList[i]; - - pOutput += 1; + pOutput += 1; pTimestamp += 1; } - + pCtx->param[1].i64 = pData[i]; pCtx->param[1].nType = pCtx->inputType; notNullElems++; @@ -3451,29 +3676,19 @@ static void diff_function(SQLFunctionCtx *pCtx) { case TSDB_DATA_TYPE_BIGINT: { int64_t *pData = (int64_t *)data; int64_t *pOutput = (int64_t *)pCtx->pOutput; - + for (; i < pCtx->size && i >= 0; i += step) { if (pCtx->hasNull && isNull((const char*) &pData[i], pCtx->inputType)) { continue; } - - if (pCtx->param[1].nType == INITIAL_VALUE_NOT_ASSIGNED) { // initial value is not set yet - pCtx->param[1].i64 = pData[i]; - pCtx->param[1].nType = pCtx->inputType; - } else if ((i == 0 && pCtx->order == TSDB_ORDER_ASC) || (i == pCtx->size - 1 && pCtx->order == TSDB_ORDER_DESC)) { - *pOutput = pData[i] - pCtx->param[1].i64; - *pTimestamp = tsList[i]; - - pOutput += 1; - pTimestamp += 1; - } else { - *pOutput = pData[i] - pCtx->param[1].i64; + + if (pCtx->param[1].nType != INITIAL_VALUE_NOT_ASSIGNED) { // initial value is not set yet + *pOutput = pData[i] - pCtx->param[1].i64; // direct previous may be null *pTimestamp = tsList[i]; - - pOutput += 1; + pOutput += 1; pTimestamp += 1; } - + pCtx->param[1].i64 = pData[i]; pCtx->param[1].nType = pCtx->inputType; notNullElems++; @@ -3483,27 +3698,19 @@ static void diff_function(SQLFunctionCtx *pCtx) { case TSDB_DATA_TYPE_DOUBLE: { double *pData = (double *)data; double *pOutput = (double *)pCtx->pOutput; - + for (; i < pCtx->size && i >= 0; i += step) { if (pCtx->hasNull && isNull((const char*) &pData[i], pCtx->inputType)) { continue; } - - if (pCtx->param[1].nType == INITIAL_VALUE_NOT_ASSIGNED) { // initial value is not set yet - pCtx->param[1].dKey = pData[i]; - pCtx->param[1].nType = pCtx->inputType; - } else if ((i == 0 && pCtx->order == TSDB_ORDER_ASC) || (i == pCtx->size - 1 && pCtx->order == TSDB_ORDER_DESC)) { - *pOutput = pData[i] - pCtx->param[1].dKey; - *pTimestamp = tsList[i]; - pOutput += 1; - pTimestamp += 1; - } else { - *pOutput = pData[i] - pCtx->param[1].dKey; + + if (pCtx->param[1].nType != INITIAL_VALUE_NOT_ASSIGNED) { // initial value is not set yet + *pOutput = pData[i] - pCtx->param[1].dKey; // direct previous may be null *pTimestamp = tsList[i]; - pOutput += 1; + pOutput += 1; pTimestamp += 1; } - + pCtx->param[1].dKey = pData[i]; pCtx->param[1].nType = pCtx->inputType; notNullElems++; @@ -3513,30 +3720,19 @@ static void diff_function(SQLFunctionCtx *pCtx) { case TSDB_DATA_TYPE_FLOAT: { float *pData = (float *)data; float *pOutput = (float *)pCtx->pOutput; - + for (; i < pCtx->size && i >= 0; i += step) { if (pCtx->hasNull && isNull((const char*) &pData[i], pCtx->inputType)) { continue; } - - if (pCtx->param[1].nType == INITIAL_VALUE_NOT_ASSIGNED) { // initial value is not set yet - pCtx->param[1].dKey = pData[i]; - pCtx->param[1].nType = pCtx->inputType; - } else if ((i == 0 && pCtx->order == TSDB_ORDER_ASC) || (i == pCtx->size - 1 && pCtx->order == TSDB_ORDER_DESC)) { - *pOutput = (float)(pData[i] - pCtx->param[1].dKey); + + if (pCtx->param[1].nType != INITIAL_VALUE_NOT_ASSIGNED) { // initial value is not set yet + *pOutput = (float)(pData[i] - pCtx->param[1].dKey); // direct previous may be null *pTimestamp = tsList[i]; - - pOutput += 1; - pTimestamp += 1; - } else { - *pOutput = (float)(pData[i] - pCtx->param[1].dKey); - *pTimestamp = tsList[i]; - - pOutput += 1; + pOutput += 1; pTimestamp += 1; } - - // keep the last value, the remain may be all null + pCtx->param[1].dKey = pData[i]; pCtx->param[1].nType = pCtx->inputType; notNullElems++; @@ -3546,60 +3742,42 @@ static void diff_function(SQLFunctionCtx *pCtx) { case TSDB_DATA_TYPE_SMALLINT: { int16_t *pData = (int16_t *)data; int16_t *pOutput = (int16_t *)pCtx->pOutput; - + for (; i < pCtx->size && i >= 0; i += step) { if (pCtx->hasNull && isNull((const char*) &pData[i], pCtx->inputType)) { continue; } - - if (pCtx->param[1].nType == INITIAL_VALUE_NOT_ASSIGNED) { // initial value is not set yet - pCtx->param[1].i64 = pData[i]; - pCtx->param[1].nType = pCtx->inputType; - } else if ((i == 0 && pCtx->order == TSDB_ORDER_ASC) || (i == pCtx->size - 1 && pCtx->order == TSDB_ORDER_DESC)) { - *pOutput = (int16_t)(pData[i] - pCtx->param[1].i64); - *pTimestamp = tsList[i]; - pOutput += 1; - pTimestamp += 1; - } else { - *pOutput = (int16_t)(pData[i] - pCtx->param[1].i64); + + if (pCtx->param[1].nType != INITIAL_VALUE_NOT_ASSIGNED) { // initial value is not set yet + *pOutput = (int16_t)(pData[i] - pCtx->param[1].i64); // direct previous may be null *pTimestamp = tsList[i]; - - pOutput += 1; + pOutput += 1; pTimestamp += 1; } - + pCtx->param[1].i64 = pData[i]; pCtx->param[1].nType = pCtx->inputType; notNullElems++; } break; } + case TSDB_DATA_TYPE_TINYINT: { int8_t *pData = (int8_t *)data; int8_t *pOutput = (int8_t *)pCtx->pOutput; - + for (; i < pCtx->size && i >= 0; i += step) { if (pCtx->hasNull && isNull((char *)&pData[i], pCtx->inputType)) { continue; } - - if (pCtx->param[1].nType == INITIAL_VALUE_NOT_ASSIGNED) { // initial value is not set yet - pCtx->param[1].i64 = pData[i]; - pCtx->param[1].nType = pCtx->inputType; - } else if ((i == 0 && pCtx->order == TSDB_ORDER_ASC) || (i == pCtx->size - 1 && pCtx->order == TSDB_ORDER_DESC)) { - *pOutput = (int8_t)(pData[i] - pCtx->param[1].i64); - *pTimestamp = tsList[i]; - - pOutput += 1; - pTimestamp += 1; - } else { - *pOutput = (int8_t)(pData[i] - pCtx->param[1].i64); + + if (pCtx->param[1].nType != INITIAL_VALUE_NOT_ASSIGNED) { // initial value is not set yet + *pOutput = (int8_t)(pData[i] - pCtx->param[1].i64); // direct previous may be null *pTimestamp = tsList[i]; - - pOutput += 1; + pOutput += 1; pTimestamp += 1; } - + pCtx->param[1].i64 = pData[i]; pCtx->param[1].nType = pCtx->inputType; notNullElems++; @@ -3609,7 +3787,7 @@ static void diff_function(SQLFunctionCtx *pCtx) { default: qError("error input type"); } - + // initial value is not set yet if (pCtx->param[1].nType == INITIAL_VALUE_NOT_ASSIGNED || notNullElems <= 0) { /* @@ -3619,36 +3797,24 @@ static void diff_function(SQLFunctionCtx *pCtx) { assert(pCtx->hasNull); } else { int32_t forwardStep = (isFirstBlock) ? notNullElems - 1 : notNullElems; - + GET_RES_INFO(pCtx)->numOfRes += forwardStep; } } -#define DIFF_IMPL(ctx, d, type) \ - do { \ - if ((ctx)->param[1].nType == INITIAL_VALUE_NOT_ASSIGNED) { \ - (ctx)->param[1].nType = (ctx)->inputType; \ - *(type *)&(ctx)->param[1].i64 = *(type *)(d); \ - } else { \ - *(type *)(ctx)->pOutput = *(type *)(d) - (*(type *)(&(ctx)->param[1].i64)); \ - *(type *)(&(ctx)->param[1].i64) = *(type *)(d); \ - *(int64_t *)(ctx)->ptsOutputBuf = GET_TS_DATA(ctx, index); \ - } \ - } while (0); - static void diff_function_f(SQLFunctionCtx *pCtx, int32_t index) { char *pData = GET_INPUT_DATA(pCtx, index); if (pCtx->hasNull && isNull(pData, pCtx->inputType)) { return; } - + // the output start from the second source element if (pCtx->param[1].nType != INITIAL_VALUE_NOT_ASSIGNED) { // initial value is set GET_RES_INFO(pCtx)->numOfRes += 1; } - + int32_t step = 1/*GET_FORWARD_DIRECTION_FACTOR(pCtx->order)*/; - + switch (pCtx->inputType) { case TSDB_DATA_TYPE_INT: { if (pCtx->param[1].nType == INITIAL_VALUE_NOT_ASSIGNED) { // initial value is not set yet @@ -3684,7 +3850,7 @@ static void diff_function_f(SQLFunctionCtx *pCtx, int32_t index) { default: qError("error input type"); } - + if (GET_RES_INFO(pCtx)->numOfRes > 0) { pCtx->pOutput += pCtx->outputBytes * step; pCtx->ptsOutputBuf = (char *)pCtx->ptsOutputBuf + TSDB_KEYSIZE * step; @@ -4518,8 +4684,8 @@ static bool rate_function_setup(SQLFunctionCtx *pCtx) { pInfo->correctionValue = 0; pInfo->firstKey = INT64_MIN; pInfo->lastKey = INT64_MIN; - pInfo->firstValue = INT64_MIN; - pInfo->lastValue = INT64_MIN; + pInfo->firstValue = (double) INT64_MIN; + pInfo->lastValue = (double) INT64_MIN; pInfo->hasResult = 0; pInfo->isIRate = (pCtx->functionId == TSDB_FUNC_IRATE); @@ -4606,7 +4772,7 @@ static void rate_function_f(SQLFunctionCtx *pCtx, int32_t index) { pRateInfo->lastValue = v; pRateInfo->lastKey = primaryKey[index]; - + SET_VAL(pCtx, 1, 1); // set has result flag @@ -4630,7 +4796,7 @@ static void rate_func_copy(SQLFunctionCtx *pCtx) { static void rate_finalizer(SQLFunctionCtx *pCtx) { SResultRowCellInfo *pResInfo = GET_RES_INFO(pCtx); SRateInfo *pRateInfo = (SRateInfo *)GET_ROWCELL_INTERBUF(pResInfo); - + if (pRateInfo->hasResult != DATA_SET_FLAG) { setNull(pCtx->pOutput, TSDB_DATA_TYPE_DOUBLE, sizeof(double)); return; @@ -4834,6 +5000,19 @@ void generateBlockDistResult(STableBlockDist *pTableBlockDist, char* result) { min = totalBlocks > 0 ? pTableBlockDist->minRows : 0; max = totalBlocks > 0 ? pTableBlockDist->maxRows : 0; + double stdDev = 0; + if (totalBlocks > 0) { + double variance = 0; + for (int32_t i = 0; i < numSteps; i++) { + SFileBlockInfo *blockInfo = taosArrayGet(blockInfos, i); + int64_t blocks = blockInfo->numBlocksOfStep; + int32_t rows = (i * TSDB_BLOCK_DIST_STEP_ROWS + TSDB_BLOCK_DIST_STEP_ROWS / 2); + variance += blocks * (rows - avg) * (rows - avg); + } + variance = variance / totalBlocks; + stdDev = sqrt(variance); + } + double percents[] = {0.05, 0.10, 0.20, 0.30, 0.40, 0.50, 0.60, 0.70, 0.80, 0.90, 0.95, 0.99}; int32_t percentiles[] = {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}; assert(sizeof(percents)/sizeof(double) == sizeof(percentiles)/sizeof(int32_t)); @@ -4848,12 +5027,12 @@ void generateBlockDistResult(STableBlockDist *pTableBlockDist, char* result) { "60th=[%d], 70th=[%d], 80th=[%d], 90th=[%d], 95th=[%d], 99th=[%d]\n\t " "Min=[%"PRId64"(Rows)] Max=[%"PRId64"(Rows)] Avg=[%"PRId64"(Rows)] Stddev=[%.2f] \n\t " "Rows=[%"PRIu64"], Blocks=[%"PRId64"], Size=[%.3f(Kb)] Comp=[%.2f]\n\t " - "RowsInMem=[%d] \n\t SeekHeaderTime=[%d(us)]", + "RowsInMem=[%d] \n\t", percentiles[0], percentiles[1], percentiles[2], percentiles[3], percentiles[4], percentiles[5], percentiles[6], percentiles[7], percentiles[8], percentiles[9], percentiles[10], percentiles[11], - min, max, avg, 0.0, + min, max, avg, stdDev, totalRows, totalBlocks, totalLen/1024.0, compRatio, - pTableBlockDist->numOfRowsInMemTable, pTableBlockDist->firstSeekTimeUs); + pTableBlockDist->numOfRowsInMemTable); varDataSetLen(result, sz); UNUSED(sz); } @@ -5121,7 +5300,7 @@ SAggFunctionInfo aAggs[] = {{ }, { // 17 - "ts_dummy", + "ts", TSDB_FUNC_TS_DUMMY, TSDB_FUNC_TS_DUMMY, TSDB_BASE_FUNC_SO | TSDB_FUNCSTATE_NEED_TS, @@ -5215,7 +5394,7 @@ SAggFunctionInfo aAggs[] = {{ "diff", TSDB_FUNC_DIFF, TSDB_FUNC_INVALID_ID, - TSDB_FUNCSTATE_MO | TSDB_FUNCSTATE_NEED_TS, + TSDB_FUNCSTATE_MO | TSDB_FUNCSTATE_STABLE | TSDB_FUNCSTATE_NEED_TS | TSDB_FUNCSTATE_SELECTIVITY, diff_function_setup, diff_function, diff_function_f, @@ -5315,8 +5494,20 @@ SAggFunctionInfo aAggs[] = {{ noop1, dataBlockRequired, }, + { //32 + "derivative", // return table id and the corresponding tags for join match and subscribe + TSDB_FUNC_DERIVATIVE, + TSDB_FUNC_INVALID_ID, + TSDB_FUNCSTATE_MO | TSDB_FUNCSTATE_STABLE | TSDB_FUNCSTATE_NEED_TS | TSDB_FUNCSTATE_SELECTIVITY, + deriv_function_setup, + deriv_function, + noop2, + doFinalizer, + noop1, + dataBlockRequired, + }, { - // 32 + // 33 "_block_dist", // return table id and the corresponding tags for join match and subscribe TSDB_FUNC_BLKINFO, TSDB_FUNC_BLKINFO, diff --git a/src/query/src/qExecutor.c b/src/query/src/qExecutor.c index 5ac19bba82508361a1b46ca58291648dc531e008..77ceabbd635c56b0c95ad481982ec0a211531482 100644 --- a/src/query/src/qExecutor.c +++ b/src/query/src/qExecutor.c @@ -30,6 +30,7 @@ #define IS_MASTER_SCAN(runtime) ((runtime)->scanFlag == MASTER_SCAN) #define IS_REVERSE_SCAN(runtime) ((runtime)->scanFlag == REVERSE_SCAN) +#define IS_REPEAT_SCAN(runtime) ((runtime)->scanFlag == REPEAT_SCAN) #define SET_MASTER_SCAN_FLAG(runtime) ((runtime)->scanFlag = MASTER_SCAN) #define SET_REVERSE_SCAN_FLAG(runtime) ((runtime)->scanFlag = REVERSE_SCAN) @@ -130,10 +131,10 @@ static void getNextTimeWindow(SQueryAttr* pQueryAttr, STimeWindow* tw) { return; } - int64_t key = tw->skey / 1000, interval = pQueryAttr->interval.interval; - if (pQueryAttr->precision == TSDB_TIME_PRECISION_MICRO) { - key /= 1000; - } + int64_t key = tw->skey, interval = pQueryAttr->interval.interval; + //convert key to second + key = convertTimePrecision(key, pQueryAttr->precision, TSDB_TIME_PRECISION_MILLI) / 1000; + if (pQueryAttr->interval.intervalUnit == 'y') { interval *= 12; } @@ -145,17 +146,13 @@ static void getNextTimeWindow(SQueryAttr* pQueryAttr, STimeWindow* tw) { int mon = (int)(tm.tm_year * 12 + tm.tm_mon + interval * factor); tm.tm_year = mon / 12; tm.tm_mon = mon % 12; - tw->skey = mktime(&tm) * 1000L; + tw->skey = convertTimePrecision(mktime(&tm) * 1000L, TSDB_TIME_PRECISION_MILLI, pQueryAttr->precision); mon = (int)(mon + interval); tm.tm_year = mon / 12; tm.tm_mon = mon % 12; - tw->ekey = mktime(&tm) * 1000L; + tw->ekey = convertTimePrecision(mktime(&tm) * 1000L, TSDB_TIME_PRECISION_MILLI, pQueryAttr->precision); - if (pQueryAttr->precision == TSDB_TIME_PRECISION_MICRO) { - tw->skey *= 1000L; - tw->ekey *= 1000L; - } tw->ekey -= 1; } @@ -735,6 +732,7 @@ static void doApplyFunctions(SQueryRuntimeEnv* pRuntimeEnv, SQLFunctionCtx* pCtx if (pCtx[k].preAggVals.isSet && forwardStep < numOfTotal) { pCtx[k].preAggVals.isSet = false; } + if (functionNeedToExecute(pRuntimeEnv, &pCtx[k], functionId)) { aAggs[functionId].xFunction(&pCtx[k]); } @@ -918,7 +916,7 @@ void setInputDataBlock(SOperatorInfo* pOperator, SQLFunctionCtx* pCtx, SSDataBlo doSetInputDataBlockInfo(pOperator, pCtx, pBlock, order); } } else { - if (pCtx[0].pInput == NULL && pBlock->pDataBlock != NULL) { + if (/*pCtx[0].pInput == NULL && */pBlock->pDataBlock != NULL) { doSetInputDataBlock(pOperator, pCtx, pBlock, order); } else { doSetInputDataBlockInfo(pOperator, pCtx, pBlock, order); @@ -1169,7 +1167,7 @@ static void hashIntervalAgg(SOperatorInfo* pOperatorInfo, SResultRowInfo* pResul SQueryRuntimeEnv* pRuntimeEnv = pOperatorInfo->pRuntimeEnv; int32_t numOfOutput = pOperatorInfo->numOfOutput; - SQueryAttr* pQueryAttr = pRuntimeEnv->pQueryAttr; + SQueryAttr* pQueryAttr = pRuntimeEnv->pQueryAttr; int32_t step = GET_FORWARD_DIRECTION_FACTOR(pQueryAttr->order.order); bool ascQuery = QUERY_IS_ASC_QUERY(pQueryAttr); @@ -1336,6 +1334,10 @@ static void doSessionWindowAggImpl(SOperatorInfo* pOperator, SSWindowOperatorInf int64_t gap = pOperator->pRuntimeEnv->pQueryAttr->sw.gap; pInfo->numOfRows = 0; + if (IS_REPEAT_SCAN(pRuntimeEnv) && !pInfo->reptScan) { + pInfo->reptScan = true; + pInfo->prevTs = INT64_MIN; + } TSKEY* tsList = (TSKEY*)pColInfoData->pData; for (int32_t j = 0; j < pSDataBlock->info.rows; ++j) { @@ -1345,7 +1347,7 @@ static void doSessionWindowAggImpl(SOperatorInfo* pOperator, SSWindowOperatorInf pInfo->prevTs = tsList[j]; pInfo->numOfRows = 1; pInfo->start = j; - } else if (tsList[j] - pInfo->prevTs <= gap) { + } else if (tsList[j] - pInfo->prevTs <= gap && (tsList[j] - pInfo->prevTs) >= 0) { pInfo->curWindow.ekey = tsList[j]; pInfo->prevTs = tsList[j]; pInfo->numOfRows += 1; @@ -2652,7 +2654,7 @@ int32_t loadDataBlockOnDemand(SQueryRuntimeEnv* pRuntimeEnv, STableScanInfo* pTa pTableScanInfo->rowCellInfoOffset) != TSDB_CODE_SUCCESS) { longjmp(pRuntimeEnv->env, TSDB_CODE_QRY_OUT_OF_MEMORY); } - } else if (pQueryAttr->stableQuery && (!pQueryAttr->tsCompQuery)) { // stable aggregate, not interval aggregate or normal column aggregate + } else if (pQueryAttr->stableQuery && (!pQueryAttr->tsCompQuery) && (!pQueryAttr->diffQuery)) { // stable aggregate, not interval aggregate or normal column aggregate doSetTableGroupOutputBuf(pRuntimeEnv, pTableScanInfo->pResultRowInfo, pTableScanInfo->pCtx, pTableScanInfo->rowCellInfoOffset, pTableScanInfo->numOfOutput, pRuntimeEnv->current->groupIndex); @@ -3092,7 +3094,7 @@ int32_t initResultRow(SResultRow *pResultRow) { * +------------+-----------------result column 1-----------+-----------------result column 2-----------+ * + SResultRow | SResultRowCellInfo | intermediate buffer1 | SResultRowCellInfo | intermediate buffer 2| * +------------+-------------------------------------------+-------------------------------------------+ - * offset[0] offset[1] + * offset[0] offset[1] offset[2] */ void setDefaultOutputBuf(SQueryRuntimeEnv *pRuntimeEnv, SOptrBasicInfo *pInfo, int64_t uid, int32_t stage) { SQLFunctionCtx* pCtx = pInfo->pCtx; @@ -3119,8 +3121,8 @@ void setDefaultOutputBuf(SQueryRuntimeEnv *pRuntimeEnv, SOptrBasicInfo *pInfo, i assert(pCtx[i].pOutput != NULL); // set the timestamp output buffer for top/bottom/diff query - int32_t functionId = pCtx[i].functionId; - if (functionId == TSDB_FUNC_TOP || functionId == TSDB_FUNC_BOTTOM || functionId == TSDB_FUNC_DIFF) { + int32_t fid = pCtx[i].functionId; + if (fid == TSDB_FUNC_TOP || fid == TSDB_FUNC_BOTTOM || fid == TSDB_FUNC_DIFF || fid == TSDB_FUNC_DERIVATIVE) { pCtx[i].ptsOutputBuf = pCtx[0].pOutput; } } @@ -3155,7 +3157,7 @@ void updateOutputBuf(SOptrBasicInfo* pBInfo, int32_t *bufCapacity, int32_t numOf // re-estabilish output buffer pointer. int32_t functionId = pBInfo->pCtx[i].functionId; - if (functionId == TSDB_FUNC_TOP || functionId == TSDB_FUNC_BOTTOM || functionId == TSDB_FUNC_DIFF) { + if (functionId == TSDB_FUNC_TOP || functionId == TSDB_FUNC_BOTTOM || functionId == TSDB_FUNC_DIFF || functionId == TSDB_FUNC_DERIVATIVE) { pBInfo->pCtx[i].ptsOutputBuf = pBInfo->pCtx[0].pOutput; } } @@ -3321,7 +3323,7 @@ void setResultRowOutputBufInitCtx(SQueryRuntimeEnv *pRuntimeEnv, SResultRow *pRe offset += pCtx[i].outputBytes; int32_t functionId = pCtx[i].functionId; - if (functionId == TSDB_FUNC_TOP || functionId == TSDB_FUNC_BOTTOM || functionId == TSDB_FUNC_DIFF) { + if (functionId == TSDB_FUNC_TOP || functionId == TSDB_FUNC_BOTTOM || functionId == TSDB_FUNC_DIFF || functionId == TSDB_FUNC_DERIVATIVE) { pCtx[i].ptsOutputBuf = pCtx[0].pOutput; } @@ -3379,7 +3381,7 @@ void setResultOutputBuf(SQueryRuntimeEnv *pRuntimeEnv, SResultRow *pResult, SQLF offset += pCtx[i].outputBytes; int32_t functionId = pCtx[i].functionId; - if (functionId == TSDB_FUNC_TOP || functionId == TSDB_FUNC_BOTTOM || functionId == TSDB_FUNC_DIFF) { + if (functionId == TSDB_FUNC_TOP || functionId == TSDB_FUNC_BOTTOM || functionId == TSDB_FUNC_DIFF || functionId == TSDB_FUNC_DERIVATIVE) { pCtx[i].ptsOutputBuf = pCtx[0].pOutput; } @@ -3587,6 +3589,8 @@ static int32_t doCopyToSDataBlock(SQueryRuntimeEnv* pRuntimeEnv, SGroupResInfo* int32_t step = -1; qDebug("QInfo:0x%"PRIx64" start to copy data from windowResInfo to output buf", GET_QID(pRuntimeEnv)); + assert(orderType == TSDB_ORDER_ASC || orderType == TSDB_ORDER_DESC); + if (orderType == TSDB_ORDER_ASC) { start = pGroupResInfo->index; step = 1; @@ -4096,15 +4100,13 @@ static SFillColInfo* createFillColInfo(SExprInfo* pExpr, int32_t numOfOutput, in return pFillCol; } -int32_t doInitQInfo(SQInfo* pQInfo, STSBuf* pTsBuf, SArray* prevResult, void* tsdb, void* sourceOptr, int32_t tbScanner, +int32_t doInitQInfo(SQInfo* pQInfo, STSBuf* pTsBuf, void* tsdb, void* sourceOptr, int32_t tbScanner, SArray* pOperator, void* param) { SQueryRuntimeEnv *pRuntimeEnv = &pQInfo->runtimeEnv; SQueryAttr *pQueryAttr = pQInfo->runtimeEnv.pQueryAttr; pQueryAttr->tsdb = tsdb; - pRuntimeEnv->prevResult = prevResult; - if (tsdb != NULL) { int32_t code = setupQueryHandle(tsdb, pRuntimeEnv, pQInfo->qId, pQueryAttr->stableQuery); if (code != TSDB_CODE_SUCCESS) { @@ -4115,6 +4117,7 @@ int32_t doInitQInfo(SQInfo* pQInfo, STSBuf* pTsBuf, SArray* prevResult, void* ts pQueryAttr->interBufSize = getOutputInterResultBufSize(pQueryAttr); pRuntimeEnv->groupResInfo.totalGroup = (int32_t) (pQueryAttr->stableQuery? GET_NUM_OF_TABLEGROUP(pRuntimeEnv):0); + pRuntimeEnv->enableGroupData = false; pRuntimeEnv->pQueryAttr = pQueryAttr; pRuntimeEnv->pTsBuf = pTsBuf; @@ -4273,6 +4276,14 @@ static SSDataBlock* doTableScanImpl(void* param, bool* newgroup) { pRuntimeEnv->current = *pTableQueryInfo; doTableQueryInfoTimeWindowCheck(pQueryAttr, *pTableQueryInfo); + + if (pRuntimeEnv->enableGroupData) { + if(pTableScanInfo->prevGroupId != -1 && pTableScanInfo->prevGroupId != (*pTableQueryInfo)->groupIndex) { + *newgroup = true; + } + } + + pTableScanInfo->prevGroupId = (*pTableQueryInfo)->groupIndex; } // this function never returns error? @@ -4419,6 +4430,7 @@ SOperatorInfo* createTableScanOperator(void* pTsdbQueryHandle, SQueryRuntimeEnv* pInfo->reverseTimes = 0; pInfo->order = pRuntimeEnv->pQueryAttr->order.order; pInfo->current = 0; +// pInfo->prevGroupId = -1; SOperatorInfo* pOperator = calloc(1, sizeof(SOperatorInfo)); pOperator->name = "TableScanOperator"; @@ -4441,6 +4453,8 @@ SOperatorInfo* createTableSeqScanOperator(void* pTsdbQueryHandle, SQueryRuntimeE pInfo->reverseTimes = 0; pInfo->order = pRuntimeEnv->pQueryAttr->order.order; pInfo->current = 0; + pInfo->prevGroupId = -1; + pRuntimeEnv->enableGroupData = true; SOperatorInfo* pOperator = calloc(1, sizeof(SOperatorInfo)); pOperator->name = "TableSeqScanOperator"; @@ -4545,6 +4559,7 @@ SOperatorInfo* createDataBlocksOptScanInfo(void* pTsdbQueryHandle, SQueryRuntime pInfo->reverseTimes = reverseTime; pInfo->current = 0; pInfo->order = pRuntimeEnv->pQueryAttr->order.order; +// pInfo->prevGroupId = -1; SOperatorInfo* pOptr = calloc(1, sizeof(SOperatorInfo)); pOptr->name = "DataBlocksOptimizedScanOperator"; @@ -4558,7 +4573,7 @@ SOperatorInfo* createDataBlocksOptScanInfo(void* pTsdbQueryHandle, SQueryRuntime } SArray* getOrderCheckColumns(SQueryAttr* pQuery) { - int32_t numOfCols = pQuery->pGroupbyExpr->numOfGroupCols; + int32_t numOfCols = pQuery->pGroupbyExpr == NULL? 0: pQuery->pGroupbyExpr->numOfGroupCols; SArray* pOrderColumns = NULL; if (numOfCols > 0) { @@ -4597,7 +4612,7 @@ SArray* getOrderCheckColumns(SQueryAttr* pQuery) { } SArray* getResultGroupCheckColumns(SQueryAttr* pQuery) { - int32_t numOfCols = pQuery->pGroupbyExpr->numOfGroupCols; + int32_t numOfCols = pQuery->pGroupbyExpr == NULL? 0 : pQuery->pGroupbyExpr->numOfGroupCols; SArray* pOrderColumns = NULL; if (numOfCols > 0) { @@ -4923,10 +4938,17 @@ static SSDataBlock* doArithmeticOperation(void* param, bool* newgroup) { } // Return result of the previous group in the firstly. - if (*newgroup && pRes->info.rows > 0) { - pArithInfo->existDataBlock = pBlock; - clearNumOfRes(pInfo->pCtx, pOperator->numOfOutput); - return pInfo->pRes; + if (*newgroup) { + if (pRes->info.rows > 0) { + pArithInfo->existDataBlock = pBlock; + clearNumOfRes(pInfo->pCtx, pOperator->numOfOutput); + return pInfo->pRes; + } else { // init output buffer for a new group data + for (int32_t j = 0; j < pOperator->numOfOutput; ++j) { + aAggs[pInfo->pCtx[j].functionId].xFinalize(&pInfo->pCtx[j]); + } + initCtxOutputBuffer(pInfo->pCtx, pOperator->numOfOutput); + } } STableQueryInfo* pTableQueryInfo = pRuntimeEnv->current; @@ -5156,6 +5178,10 @@ static void doStateWindowAggImpl(SOperatorInfo* pOperator, SStateWindowOperatorI SColumnInfoData* pTsColInfoData = taosArrayGet(pSDataBlock->pDataBlock, 0); TSKEY* tsList = (TSKEY*)pTsColInfoData->pData; + if (IS_REPEAT_SCAN(pRuntimeEnv) && !pInfo->reptScan) { + pInfo->reptScan = true; + tfree(pInfo->prevData); + } pInfo->numOfRows = 0; for (int32_t j = 0; j < pSDataBlock->info.rows; ++j) { @@ -5742,6 +5768,7 @@ SOperatorInfo* createTimeIntervalOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOp SOperatorInfo* createStatewindowOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOperatorInfo* upstream, SExprInfo* pExpr, int32_t numOfOutput) { SStateWindowOperatorInfo* pInfo = calloc(1, sizeof(SStateWindowOperatorInfo)); pInfo->colIndex = -1; + pInfo->reptScan = false; pInfo->binfo.pCtx = createSQLFunctionCtx(pRuntimeEnv, pExpr, numOfOutput, &pInfo->binfo.rowCellInfoOffset); pInfo->binfo.pRes = createOutputBuf(pExpr, numOfOutput, pRuntimeEnv->resultInfo.capacity); initResultRowInfo(&pInfo->binfo.resultRowInfo, 8, TSDB_DATA_TYPE_INT); @@ -5769,7 +5796,8 @@ SOperatorInfo* createSWindowOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOperato pInfo->binfo.pRes = createOutputBuf(pExpr, numOfOutput, pRuntimeEnv->resultInfo.capacity); initResultRowInfo(&pInfo->binfo.resultRowInfo, 8, TSDB_DATA_TYPE_INT); - pInfo->prevTs = INT64_MIN; + pInfo->prevTs = INT64_MIN; + pInfo->reptScan = false; SOperatorInfo* pOperator = calloc(1, sizeof(SOperatorInfo)); pOperator->name = "SessionWindowAggOperator"; @@ -6923,6 +6951,10 @@ int32_t doCreateFilterInfo(SColumnInfo* pCols, int32_t numOfCols, int32_t numOfF } pSingleColFilter->bytes = pCols[i].bytes; + + if (lower == TSDB_RELATION_IN) { + buildFilterSetFromBinary(&pSingleColFilter->q, (char *)(pSingleColFilter->filterInfo.pz), (int32_t)(pSingleColFilter->filterInfo.len)); + } } j++; @@ -6935,6 +6967,9 @@ int32_t doCreateFilterInfo(SColumnInfo* pCols, int32_t numOfCols, int32_t numOfF void* doDestroyFilterInfo(SSingleColumnFilterInfo* pFilterInfo, int32_t numOfFilterCols) { for (int32_t i = 0; i < numOfFilterCols; ++i) { if (pFilterInfo[i].numOfFilters > 0) { + if (pFilterInfo[i].pFilters->filterInfo.lowerRelOptr == TSDB_RELATION_IN) { + taosHashCleanup((SHashObj *)(pFilterInfo[i].pFilters->q)); + } tfree(pFilterInfo[i].pFilters); } } @@ -7187,7 +7222,7 @@ SQInfo* createQInfoImpl(SQueryTableMsg* pQueryMsg, SGroupbyExpr* pGroupbyExpr, S // todo refactor pQInfo->query.queryBlockDist = (numOfOutput == 1 && pExprs[0].base.functionId == TSDB_FUNC_BLKINFO); - qDebug("qmsg:%p QInfo:0x%" PRIx64 "-%p created", pQueryMsg, pQInfo->qId, pQInfo); + qDebug("qmsg:%p vgId:%d, QInfo:0x%" PRIx64 "-%p created", pQueryMsg, pQInfo->query.vgId, pQInfo->qId, pQInfo); return pQInfo; _cleanup_qinfo: @@ -7254,7 +7289,9 @@ int32_t initQInfo(STsBufInfo* pTsBufInfo, void* tsdb, void* sourceOptr, SQInfo* SArray* prevResult = NULL; if (prevResultLen > 0) { - prevResult = interResFromBinary(param->prevResult, prevResultLen); + prevResult = interResFromBinary(param->prevResult, prevResultLen); + + pRuntimeEnv->prevResult = prevResult; } if (tsdb != NULL) { @@ -7278,7 +7315,7 @@ int32_t initQInfo(STsBufInfo* pTsBufInfo, void* tsdb, void* sourceOptr, SQInfo* } // filter the qualified - if ((code = doInitQInfo(pQInfo, pTsBuf, prevResult, tsdb, sourceOptr, param->tableScanOperator, param->pOperator, merger)) != TSDB_CODE_SUCCESS) { + if ((code = doInitQInfo(pQInfo, pTsBuf, tsdb, sourceOptr, param->tableScanOperator, param->pOperator, merger)) != TSDB_CODE_SUCCESS) { goto _error; } @@ -7442,7 +7479,6 @@ int32_t doDumpQueryResult(SQInfo *pQInfo, char *data) { doCopyQueryResultToMsg(pQInfo, (int32_t)pRuntimeEnv->outputBuf->info.rows, data); } - pRuntimeEnv->resultInfo.total += pRuntimeEnv->outputBuf->info.rows; qDebug("QInfo:0x%"PRIx64" current numOfRes rows:%d, total:%" PRId64, pQInfo->qId, pRuntimeEnv->outputBuf->info.rows, pRuntimeEnv->resultInfo.total); diff --git a/src/query/src/qFilterfunc.c b/src/query/src/qFilterfunc.c index dabce88423f762029a4b27dc3fb4731fd28e6406..663f8814a0d57eb8cecad7f2d62944425510f029 100644 --- a/src/query/src/qFilterfunc.c +++ b/src/query/src/qFilterfunc.c @@ -253,6 +253,27 @@ bool isNullOperator(SColumnFilterElem *pFilter, const char* minval, const char* bool notNullOperator(SColumnFilterElem *pFilter, const char* minval, const char* maxval, int16_t type) { return true; } +bool inOperator(SColumnFilterElem *pFilter, const char* minval, const char* maxval, int16_t type) { + if (type == TSDB_DATA_TYPE_BOOL || type == TSDB_DATA_TYPE_TINYINT || type == TSDB_DATA_TYPE_SMALLINT || type == TSDB_DATA_TYPE_BIGINT || type == TSDB_DATA_TYPE_INT) { + int64_t minv = -1, maxv = -1; + GET_TYPED_DATA(minv, int64_t, type, minval); + GET_TYPED_DATA(maxv, int64_t, type, maxval); + if (minv == maxv) { + return NULL != taosHashGet((SHashObj *)pFilter->q, (char *)&minv, sizeof(minv)); + } + return true; + } else if (type == TSDB_DATA_TYPE_DOUBLE || type == TSDB_DATA_TYPE_DOUBLE) { + double v; + GET_TYPED_DATA(v, double, type, minval); + return NULL != taosHashGet((SHashObj *)pFilter->q, (char *)&v, sizeof(v)); + } else if (type == TSDB_DATA_TYPE_BINARY) { + return NULL != taosHashGet((SHashObj *)pFilter->q, varDataVal(minval), varDataLen(minval)); + } else if (type == TSDB_DATA_TYPE_NCHAR){ + return NULL != taosHashGet((SHashObj *)pFilter->q, varDataVal(minval), varDataLen(minval)); + } + + return false; +} /////////////////////////////////////////////////////////////////////////////// bool rangeFilter_ii(SColumnFilterElem *pFilter, const char *minval, const char *maxval, int16_t type) { @@ -389,6 +410,7 @@ bool (*filterOperators[])(SColumnFilterElem *pFilter, const char* minval, const likeOperator, isNullOperator, notNullOperator, + inOperator, }; bool (*rangeFilterOperators[])(SColumnFilterElem *pFilter, const char* minval, const char* maxval, int16_t type) = { @@ -397,6 +419,7 @@ bool (*rangeFilterOperators[])(SColumnFilterElem *pFilter, const char* minval, c rangeFilter_ie, rangeFilter_ei, rangeFilter_ii, + }; __filter_func_t getFilterOperator(int32_t lowerOptr, int32_t upperOptr) { diff --git a/src/query/src/qPlan.c b/src/query/src/qPlan.c index 24531c7f4e6e9486cb2ad388ec50fa422606de52..ee587a515dca39559bc6d061501d4e3397c0781a 100644 --- a/src/query/src/qPlan.c +++ b/src/query/src/qPlan.c @@ -531,7 +531,7 @@ SArray* createTableScanPlan(SQueryAttr* pQueryAttr) { } else { if (pQueryAttr->queryBlockDist) { op = OP_TableBlockInfoScan; - } else if (pQueryAttr->tsCompQuery || pQueryAttr->pointInterpQuery) { + } else if (pQueryAttr->tsCompQuery || pQueryAttr->pointInterpQuery || pQueryAttr->diffQuery) { op = OP_TableSeqScan; } else if (pQueryAttr->needReverseScan) { op = OP_DataBlocksOptScan; @@ -605,7 +605,7 @@ SArray* createExecOperatorPlan(SQueryAttr* pQueryAttr) { taosArrayPush(plan, &op); } } else if (pQueryAttr->simpleAgg) { - if (pQueryAttr->stableQuery && !pQueryAttr->tsCompQuery) { + if (pQueryAttr->stableQuery && !pQueryAttr->tsCompQuery && !pQueryAttr->diffQuery) { op = OP_MultiTableAggregate; } else { op = OP_Aggregate; diff --git a/src/query/src/qSqlParser.c b/src/query/src/qSqlParser.c index eea57e9f9daa067060d25b984c82c89b616615c6..a2cb7aee00c8bd8173557a5bf19e8e337290c25c 100644 --- a/src/query/src/qSqlParser.c +++ b/src/query/src/qSqlParser.c @@ -139,19 +139,20 @@ tSqlExpr *tSqlExprCreateIdValue(SStrToken *pToken, int32_t optrType) { pSqlExpr->tokenId = optrType; pSqlExpr->type = SQL_NODE_VALUE; } else if (optrType == TK_NOW) { - // use microsecond by default - pSqlExpr->value.i64 = taosGetTimestamp(TSDB_TIME_PRECISION_MICRO); + // use nanosecond by default TODO set value after getting database precision + pSqlExpr->value.i64 = taosGetTimestamp(TSDB_TIME_PRECISION_NANO); pSqlExpr->value.nType = TSDB_DATA_TYPE_BIGINT; pSqlExpr->tokenId = TK_TIMESTAMP; // TK_TIMESTAMP used to denote the time value is in microsecond pSqlExpr->type = SQL_NODE_VALUE; - pSqlExpr->flags |= 1 << EXPR_FLAG_US_TIMESTAMP; + pSqlExpr->flags |= 1 << EXPR_FLAG_NS_TIMESTAMP; } else if (optrType == TK_VARIABLE) { - int32_t ret = parseAbsoluteDuration(pToken->z, pToken->n, &pSqlExpr->value.i64); + // use nanosecond by default TODO set value after getting database precision + int32_t ret = parseAbsoluteDuration(pToken->z, pToken->n, &pSqlExpr->value.i64, TSDB_TIME_PRECISION_NANO); if (ret != TSDB_CODE_SUCCESS) { terrno = TSDB_CODE_TSC_SQL_SYNTAX_ERROR; } - pSqlExpr->flags |= 1 << EXPR_FLAG_US_TIMESTAMP; + pSqlExpr->flags |= 1 << EXPR_FLAG_NS_TIMESTAMP; pSqlExpr->flags |= 1 << EXPR_FLAG_TIMESTAMP_VAR; pSqlExpr->value.nType = TSDB_DATA_TYPE_BIGINT; pSqlExpr->tokenId = TK_TIMESTAMP; diff --git a/src/query/src/queryMain.c b/src/query/src/queryMain.c index f00d5ceb41aad443911036925ef92a6fc3fd4030..38ef81e7938a3635273c0cfa2cb4e86ca2e35c1e 100644 --- a/src/query/src/queryMain.c +++ b/src/query/src/queryMain.c @@ -132,7 +132,7 @@ int32_t qCreateQueryInfo(void* tsdb, int32_t vgId, SQueryTableMsg* pQueryMsg, qi numOfGroupByCols = 0; } - qDebug("qmsg:%p query stable, uid:%"PRId64", tid:%d", pQueryMsg, id->uid, id->tid); + qDebug("qmsg:%p query stable, uid:%"PRIu64", tid:%d", pQueryMsg, id->uid, id->tid); code = tsdbQuerySTableByTagCond(tsdb, id->uid, pQueryMsg->window.skey, param.tagCond, pQueryMsg->tagCondLen, pQueryMsg->tagNameRelType, param.tbnameCond, &tableGroupInfo, param.pGroupColIndex, numOfGroupByCols); @@ -162,7 +162,7 @@ int32_t qCreateQueryInfo(void* tsdb, int32_t vgId, SQueryTableMsg* pQueryMsg, qi assert(pQueryMsg->stableQuery == isSTableQuery); (*pQInfo) = createQInfoImpl(pQueryMsg, param.pGroupbyExpr, param.pExprs, param.pSecExprs, &tableGroupInfo, - param.pTagColumnInfo, vgId, param.sql, qId); + param.pTagColumnInfo, vgId, param.sql, qId); param.sql = NULL; param.pExprs = NULL; @@ -241,15 +241,16 @@ bool qTableQuery(qinfo_t qinfo, uint64_t *qId) { bool newgroup = false; pRuntimeEnv->outputBuf = pRuntimeEnv->proot->exec(pRuntimeEnv->proot, &newgroup); + pRuntimeEnv->resultInfo.total += GET_NUM_OF_RESULTS(pRuntimeEnv); if (isQueryKilled(pQInfo)) { qDebug("QInfo:0x%"PRIx64" query is killed", pQInfo->qId); } else if (GET_NUM_OF_RESULTS(pRuntimeEnv) == 0) { - qDebug("QInfo:0x%"PRIx64" over, %u tables queried, %"PRId64" rows are returned", pQInfo->qId, pRuntimeEnv->tableqinfoGroupInfo.numOfTables, + qDebug("QInfo:0x%"PRIx64" over, %u tables queried, total %"PRId64" rows returned", pQInfo->qId, pRuntimeEnv->tableqinfoGroupInfo.numOfTables, pRuntimeEnv->resultInfo.total); } else { - qDebug("QInfo:0x%"PRIx64" query paused, %d rows returned, numOfTotal:%" PRId64 " rows", - pQInfo->qId, GET_NUM_OF_RESULTS(pRuntimeEnv), pRuntimeEnv->resultInfo.total + GET_NUM_OF_RESULTS(pRuntimeEnv)); + qDebug("QInfo:0x%"PRIx64" query paused, %d rows returned, total:%" PRId64 " rows", pQInfo->qId, + GET_NUM_OF_RESULTS(pRuntimeEnv), pRuntimeEnv->resultInfo.total); } return doBuildResCheck(pQInfo); diff --git a/src/query/src/sql.c b/src/query/src/sql.c index 815efebe7fe2ac93a0ea846df4fc4fc21fb2c122..9e95b4ce92710f043a243c2420dda6b5a37820f1 100644 --- a/src/query/src/sql.c +++ b/src/query/src/sql.c @@ -66,28 +66,28 @@ ** defined, then do no error processing. */ #define YYCODETYPE unsigned short int -#define YYNOCODE 269 +#define YYNOCODE 271 #define YYACTIONTYPE unsigned short int #define ParseTOKENTYPE SStrToken typedef union { int yyinit; ParseTOKENTYPE yy0; - SCreateDbInfo yy22; - TAOS_FIELD yy47; - SRelationInfo* yy52; - SCreateAcctInfo yy83; - SSessionWindowVal yy84; - tSqlExpr* yy162; - SWindowStateVal yy176; - int yy196; - SLimitVal yy230; - SArray* yy325; - SIntervalVal yy328; - int64_t yy373; - SCreateTableSql* yy422; - tVariant yy442; - SCreatedTableInfo yy504; - SSqlNode* yy536; + int yy112; + SCreateAcctInfo yy151; + tSqlExpr* yy166; + SCreateTableSql* yy182; + SSqlNode* yy236; + SRelationInfo* yy244; + SSessionWindowVal yy259; + SIntervalVal yy340; + TAOS_FIELD yy343; + SWindowStateVal yy348; + int64_t yy369; + SCreateDbInfo yy382; + SLimitVal yy414; + SArray* yy441; + SCreatedTableInfo yy456; + tVariant yy506; } YYMINORTYPE; #ifndef YYSTACKDEPTH #define YYSTACKDEPTH 100 @@ -96,8 +96,8 @@ typedef union { #define ParseARG_PDECL ,SSqlInfo* pInfo #define ParseARG_FETCH SSqlInfo* pInfo = yypParser->pInfo #define ParseARG_STORE yypParser->pInfo = pInfo -#define YYNSTATE 544 -#define YYNRULE 281 +#define YYNSTATE 548 +#define YYNRULE 284 #define YYFALLBACK 1 #define YY_NO_ACTION (YYNSTATE+YYNRULE+2) #define YY_ACCEPT_ACTION (YYNSTATE+YYNRULE+1) @@ -167,304 +167,306 @@ static const YYMINORTYPE yyzerominor = { 0 }; ** shifting non-terminals after a reduce. ** yy_default[] Default action for each state. */ -#define YY_ACTTAB_COUNT (845) +#define YY_ACTTAB_COUNT (852) static const YYACTIONTYPE yy_action[] = { - /* 0 */ 527, 53, 52, 544, 239, 51, 50, 49, 526, 826, - /* 10 */ 345, 236, 54, 55, 74, 58, 59, 126, 125, 238, - /* 20 */ 48, 530, 57, 299, 62, 60, 63, 61, 143, 141, - /* 30 */ 140, 6, 53, 52, 90, 252, 51, 50, 49, 54, - /* 40 */ 55, 458, 58, 59, 256, 255, 238, 48, 78, 57, - /* 50 */ 299, 62, 60, 63, 61, 440, 361, 439, 36, 53, - /* 60 */ 52, 196, 443, 51, 50, 49, 54, 55, 364, 58, - /* 70 */ 59, 422, 260, 238, 48, 9, 57, 299, 62, 60, - /* 80 */ 63, 61, 342, 341, 137, 71, 53, 52, 527, 14, - /* 90 */ 51, 50, 49, 51, 50, 49, 526, 92, 442, 529, - /* 100 */ 321, 54, 56, 456, 58, 59, 72, 446, 238, 48, - /* 110 */ 77, 57, 299, 62, 60, 63, 61, 437, 94, 436, - /* 120 */ 91, 53, 52, 461, 139, 51, 50, 49, 394, 393, - /* 130 */ 35, 387, 543, 542, 541, 540, 539, 538, 537, 536, - /* 140 */ 535, 534, 533, 532, 531, 344, 447, 55, 219, 58, - /* 150 */ 59, 319, 318, 238, 48, 138, 57, 299, 62, 60, - /* 160 */ 63, 61, 301, 152, 428, 152, 53, 52, 438, 68, - /* 170 */ 51, 50, 49, 58, 59, 25, 678, 238, 48, 145, - /* 180 */ 57, 299, 62, 60, 63, 61, 499, 497, 498, 496, - /* 190 */ 53, 52, 69, 25, 51, 50, 49, 399, 353, 411, - /* 200 */ 410, 409, 408, 407, 406, 405, 404, 403, 402, 401, - /* 210 */ 400, 398, 397, 29, 295, 338, 337, 294, 293, 292, - /* 220 */ 336, 291, 335, 334, 333, 290, 332, 331, 237, 430, - /* 230 */ 435, 281, 441, 88, 434, 373, 433, 279, 527, 24, - /* 240 */ 62, 60, 63, 61, 267, 266, 526, 527, 53, 52, - /* 250 */ 378, 377, 51, 50, 49, 526, 204, 234, 297, 445, - /* 260 */ 216, 217, 339, 205, 300, 361, 423, 391, 129, 128, - /* 270 */ 203, 518, 237, 430, 304, 83, 441, 352, 434, 484, - /* 280 */ 433, 222, 486, 485, 22, 111, 21, 483, 495, 481, - /* 290 */ 480, 482, 286, 479, 478, 25, 67, 244, 113, 20, - /* 300 */ 112, 19, 494, 241, 216, 217, 76, 64, 42, 29, - /* 310 */ 501, 338, 337, 504, 196, 503, 336, 502, 335, 334, - /* 320 */ 333, 93, 332, 331, 422, 245, 30, 114, 108, 119, - /* 330 */ 18, 259, 17, 75, 118, 124, 127, 117, 351, 429, - /* 340 */ 212, 247, 248, 121, 116, 431, 187, 185, 183, 36, - /* 350 */ 235, 64, 329, 182, 132, 131, 130, 5, 39, 169, - /* 360 */ 34, 457, 432, 36, 168, 102, 97, 101, 246, 36, - /* 370 */ 243, 390, 314, 313, 242, 284, 240, 36, 307, 306, - /* 380 */ 107, 386, 106, 429, 67, 36, 36, 369, 287, 431, - /* 390 */ 36, 317, 36, 16, 456, 15, 36, 36, 3, 180, - /* 400 */ 67, 1, 167, 81, 37, 316, 432, 196, 456, 493, - /* 410 */ 37, 315, 80, 83, 456, 370, 26, 422, 366, 311, - /* 420 */ 500, 261, 456, 95, 474, 36, 388, 310, 309, 179, - /* 430 */ 456, 456, 308, 152, 229, 456, 263, 456, 228, 220, - /* 440 */ 232, 456, 456, 419, 67, 263, 42, 147, 179, 475, - /* 450 */ 37, 152, 361, 354, 179, 230, 224, 392, 492, 218, - /* 460 */ 343, 196, 491, 490, 489, 488, 495, 487, 221, 231, - /* 470 */ 463, 421, 477, 473, 472, 471, 470, 469, 468, 467, - /* 480 */ 466, 495, 495, 37, 462, 460, 459, 109, 105, 103, - /* 490 */ 303, 8, 66, 65, 444, 427, 7, 100, 296, 417, - /* 500 */ 418, 416, 302, 89, 415, 414, 413, 412, 94, 96, - /* 510 */ 28, 27, 12, 285, 283, 13, 11, 356, 33, 32, - /* 520 */ 151, 374, 371, 275, 225, 87, 263, 368, 86, 149, - /* 530 */ 367, 148, 85, 365, 265, 31, 350, 362, 82, 258, - /* 540 */ 349, 10, 348, 254, 253, 347, 251, 346, 250, 4, - /* 550 */ 2, 525, 142, 524, 476, 136, 519, 177, 135, 517, - /* 560 */ 510, 340, 134, 133, 176, 178, 326, 328, 323, 330, - /* 570 */ 211, 327, 175, 325, 174, 324, 322, 99, 115, 173, - /* 580 */ 210, 172, 98, 464, 297, 288, 162, 233, 213, 160, - /* 590 */ 157, 155, 384, 280, 161, 47, 376, 159, 46, 277, - /* 600 */ 158, 396, 271, 156, 189, 269, 154, 827, 84, 528, - /* 610 */ 272, 827, 274, 79, 188, 276, 827, 827, 278, 320, - /* 620 */ 262, 282, 523, 372, 385, 163, 153, 264, 522, 227, - /* 630 */ 521, 520, 186, 184, 73, 70, 516, 505, 270, 223, - /* 640 */ 268, 827, 827, 827, 515, 379, 827, 827, 514, 375, - /* 650 */ 45, 827, 192, 827, 827, 827, 827, 827, 383, 827, - /* 660 */ 382, 827, 827, 827, 360, 827, 827, 827, 827, 827, - /* 670 */ 827, 827, 329, 827, 827, 827, 827, 827, 827, 827, - /* 680 */ 827, 827, 827, 827, 827, 827, 827, 827, 827, 827, - /* 690 */ 827, 827, 827, 827, 827, 827, 827, 827, 827, 827, - /* 700 */ 513, 512, 511, 181, 249, 509, 827, 508, 123, 122, - /* 710 */ 507, 120, 827, 506, 191, 44, 38, 827, 41, 465, - /* 720 */ 171, 455, 454, 110, 453, 312, 170, 451, 450, 104, - /* 730 */ 449, 827, 827, 305, 827, 827, 827, 420, 298, 40, - /* 740 */ 190, 43, 289, 395, 166, 165, 389, 164, 273, 150, - /* 750 */ 146, 363, 359, 358, 357, 355, 144, 257, 827, 827, - /* 760 */ 827, 827, 827, 827, 827, 827, 827, 827, 827, 827, - /* 770 */ 827, 827, 827, 827, 827, 827, 827, 827, 827, 827, - /* 780 */ 827, 827, 827, 827, 827, 827, 827, 827, 827, 827, - /* 790 */ 827, 827, 827, 827, 827, 226, 381, 380, 827, 827, - /* 800 */ 827, 827, 827, 827, 827, 827, 827, 452, 448, 827, - /* 810 */ 827, 827, 827, 827, 827, 827, 827, 827, 827, 827, - /* 820 */ 827, 827, 827, 827, 827, 827, 206, 209, 208, 207, - /* 830 */ 202, 201, 195, 200, 198, 197, 215, 214, 426, 425, - /* 840 */ 424, 199, 194, 193, 23, + /* 0 */ 531, 53, 52, 126, 125, 51, 50, 49, 530, 143, + /* 10 */ 141, 140, 54, 55, 14, 58, 59, 379, 378, 239, + /* 20 */ 48, 450, 57, 300, 62, 60, 63, 61, 343, 342, + /* 30 */ 137, 25, 53, 52, 833, 346, 51, 50, 49, 54, + /* 40 */ 55, 548, 58, 59, 94, 91, 239, 48, 237, 57, + /* 50 */ 300, 62, 60, 63, 61, 443, 440, 442, 439, 53, + /* 60 */ 52, 74, 253, 51, 50, 49, 54, 55, 6, 58, + /* 70 */ 59, 257, 256, 239, 48, 533, 57, 300, 62, 60, + /* 80 */ 63, 61, 68, 362, 145, 92, 53, 52, 531, 470, + /* 90 */ 51, 50, 49, 51, 50, 49, 530, 81, 80, 261, + /* 100 */ 473, 54, 56, 534, 58, 59, 240, 449, 239, 48, + /* 110 */ 77, 57, 300, 62, 60, 63, 61, 397, 396, 34, + /* 120 */ 388, 53, 52, 71, 69, 51, 50, 49, 320, 319, + /* 130 */ 264, 264, 547, 546, 545, 544, 543, 542, 541, 540, + /* 140 */ 539, 538, 537, 536, 535, 345, 35, 55, 220, 58, + /* 150 */ 59, 268, 267, 239, 48, 248, 57, 300, 62, 60, + /* 160 */ 63, 61, 302, 72, 152, 197, 53, 52, 441, 438, + /* 170 */ 51, 50, 49, 58, 59, 425, 446, 239, 48, 235, + /* 180 */ 57, 300, 62, 60, 63, 61, 22, 236, 21, 322, + /* 190 */ 53, 52, 469, 468, 51, 50, 49, 402, 414, 413, + /* 200 */ 412, 411, 410, 409, 408, 407, 406, 405, 404, 403, + /* 210 */ 401, 400, 445, 152, 41, 296, 339, 338, 295, 294, + /* 220 */ 293, 337, 292, 336, 335, 334, 291, 333, 332, 238, + /* 230 */ 433, 531, 365, 444, 282, 437, 88, 436, 197, 530, + /* 240 */ 24, 62, 60, 63, 61, 113, 197, 112, 425, 53, + /* 250 */ 52, 181, 35, 51, 50, 49, 425, 205, 9, 448, + /* 260 */ 35, 217, 218, 522, 206, 301, 20, 33, 19, 129, + /* 270 */ 128, 204, 36, 238, 433, 305, 83, 444, 247, 437, + /* 280 */ 496, 436, 498, 497, 459, 89, 458, 495, 431, 493, + /* 290 */ 492, 494, 531, 491, 490, 318, 288, 139, 25, 468, + /* 300 */ 530, 1, 167, 317, 138, 217, 218, 468, 64, 42, + /* 310 */ 41, 461, 339, 338, 464, 152, 463, 337, 462, 336, + /* 320 */ 335, 334, 242, 333, 332, 457, 474, 456, 114, 108, + /* 330 */ 119, 18, 260, 17, 75, 118, 124, 127, 117, 35, + /* 340 */ 432, 213, 244, 245, 121, 35, 434, 83, 107, 249, + /* 350 */ 106, 246, 64, 315, 314, 354, 35, 188, 186, 184, + /* 360 */ 90, 35, 35, 435, 183, 132, 131, 130, 5, 38, + /* 370 */ 169, 29, 35, 35, 78, 168, 102, 97, 101, 35, + /* 380 */ 42, 16, 316, 15, 432, 685, 468, 374, 312, 280, + /* 390 */ 434, 426, 468, 243, 95, 241, 394, 308, 307, 311, + /* 400 */ 287, 25, 391, 468, 310, 309, 65, 435, 468, 468, + /* 410 */ 93, 35, 65, 285, 387, 230, 229, 370, 371, 468, + /* 420 */ 468, 460, 221, 36, 36, 367, 468, 26, 65, 395, + /* 430 */ 262, 3, 180, 76, 353, 147, 340, 507, 486, 422, + /* 440 */ 36, 487, 116, 179, 179, 389, 179, 152, 506, 362, + /* 450 */ 330, 233, 362, 231, 197, 392, 355, 392, 475, 225, + /* 460 */ 505, 219, 344, 392, 424, 223, 352, 298, 222, 504, + /* 470 */ 503, 502, 501, 500, 499, 489, 485, 484, 483, 482, + /* 480 */ 481, 480, 479, 478, 472, 471, 304, 111, 109, 105, + /* 490 */ 232, 8, 103, 447, 430, 7, 100, 67, 66, 297, + /* 500 */ 421, 420, 419, 418, 417, 416, 96, 303, 94, 28, + /* 510 */ 415, 286, 27, 284, 13, 12, 32, 11, 31, 375, + /* 520 */ 151, 276, 357, 372, 226, 87, 149, 369, 86, 85, + /* 530 */ 368, 148, 264, 366, 30, 266, 82, 363, 10, 349, + /* 540 */ 259, 350, 255, 351, 254, 348, 252, 251, 347, 4, + /* 550 */ 2, 529, 142, 528, 509, 136, 523, 508, 135, 521, + /* 560 */ 488, 134, 178, 133, 514, 327, 331, 341, 177, 324, + /* 570 */ 176, 329, 212, 211, 328, 325, 326, 175, 174, 323, + /* 580 */ 173, 115, 172, 99, 298, 476, 289, 98, 234, 214, + /* 590 */ 160, 46, 157, 155, 70, 377, 162, 278, 271, 161, + /* 600 */ 272, 224, 159, 84, 399, 79, 156, 263, 190, 834, + /* 610 */ 532, 834, 270, 189, 273, 834, 275, 527, 526, 834, + /* 620 */ 525, 834, 834, 834, 158, 277, 373, 279, 386, 154, + /* 630 */ 283, 524, 834, 281, 153, 265, 47, 834, 385, 73, + /* 640 */ 834, 163, 269, 455, 834, 45, 361, 187, 834, 451, + /* 650 */ 834, 380, 834, 834, 185, 520, 376, 519, 834, 834, + /* 660 */ 834, 834, 834, 321, 393, 228, 834, 834, 384, 834, + /* 670 */ 834, 383, 834, 834, 834, 834, 834, 330, 834, 834, + /* 680 */ 834, 834, 834, 834, 834, 834, 834, 834, 834, 834, + /* 690 */ 834, 834, 834, 834, 834, 834, 834, 834, 834, 834, + /* 700 */ 834, 834, 834, 834, 518, 834, 517, 516, 515, 182, + /* 710 */ 250, 513, 512, 834, 123, 122, 511, 834, 120, 510, + /* 720 */ 192, 44, 37, 40, 477, 171, 467, 466, 834, 110, + /* 730 */ 465, 834, 313, 170, 834, 834, 454, 834, 453, 104, + /* 740 */ 452, 306, 423, 299, 39, 191, 834, 43, 290, 398, + /* 750 */ 166, 165, 390, 164, 274, 150, 146, 364, 360, 359, + /* 760 */ 358, 356, 144, 258, 834, 834, 834, 834, 834, 834, + /* 770 */ 834, 834, 834, 834, 834, 834, 834, 834, 834, 834, + /* 780 */ 834, 834, 834, 834, 834, 834, 834, 834, 834, 834, + /* 790 */ 834, 834, 834, 834, 834, 834, 834, 834, 834, 834, + /* 800 */ 834, 834, 227, 382, 381, 834, 834, 834, 834, 834, + /* 810 */ 834, 834, 834, 834, 834, 834, 834, 834, 834, 834, + /* 820 */ 834, 834, 834, 834, 834, 834, 834, 834, 834, 834, + /* 830 */ 834, 834, 193, 207, 210, 209, 208, 203, 202, 196, + /* 840 */ 201, 199, 198, 216, 215, 429, 428, 427, 200, 195, + /* 850 */ 194, 23, }; static const YYCODETYPE yy_lookahead[] = { - /* 0 */ 1, 33, 34, 0, 200, 37, 38, 39, 9, 191, - /* 10 */ 192, 60, 13, 14, 80, 16, 17, 76, 77, 20, - /* 20 */ 21, 59, 23, 24, 25, 26, 27, 28, 62, 63, - /* 30 */ 64, 80, 33, 34, 241, 137, 37, 38, 39, 13, - /* 40 */ 14, 107, 16, 17, 146, 147, 20, 21, 255, 23, - /* 50 */ 24, 25, 26, 27, 28, 5, 238, 7, 194, 33, - /* 60 */ 34, 257, 1, 37, 38, 39, 13, 14, 110, 16, - /* 70 */ 17, 267, 254, 20, 21, 117, 23, 24, 25, 26, - /* 80 */ 27, 28, 65, 66, 67, 110, 33, 34, 1, 80, - /* 90 */ 37, 38, 39, 37, 38, 39, 9, 201, 37, 60, - /* 100 */ 236, 13, 14, 239, 16, 17, 131, 81, 20, 21, - /* 110 */ 111, 23, 24, 25, 26, 27, 28, 5, 109, 7, - /* 120 */ 111, 33, 34, 5, 21, 37, 38, 39, 232, 233, - /* 130 */ 234, 235, 45, 46, 47, 48, 49, 50, 51, 52, - /* 140 */ 53, 54, 55, 56, 57, 58, 81, 14, 61, 16, - /* 150 */ 17, 33, 34, 20, 21, 21, 23, 24, 25, 26, - /* 160 */ 27, 28, 15, 194, 81, 194, 33, 34, 118, 110, - /* 170 */ 37, 38, 39, 16, 17, 110, 0, 20, 21, 194, - /* 180 */ 23, 24, 25, 26, 27, 28, 5, 5, 7, 7, - /* 190 */ 33, 34, 133, 110, 37, 38, 39, 213, 37, 215, - /* 200 */ 216, 217, 218, 219, 220, 221, 222, 223, 224, 225, - /* 210 */ 226, 227, 228, 91, 92, 93, 94, 95, 96, 97, - /* 220 */ 98, 99, 100, 101, 102, 103, 104, 105, 1, 2, - /* 230 */ 118, 262, 5, 264, 7, 264, 9, 266, 1, 44, - /* 240 */ 25, 26, 27, 28, 259, 260, 9, 1, 33, 34, - /* 250 */ 126, 127, 37, 38, 39, 9, 61, 200, 82, 112, - /* 260 */ 33, 34, 214, 68, 37, 238, 81, 81, 73, 74, - /* 270 */ 75, 83, 1, 2, 79, 80, 5, 116, 7, 213, - /* 280 */ 9, 254, 216, 217, 140, 142, 142, 221, 240, 223, - /* 290 */ 224, 225, 81, 227, 228, 110, 110, 68, 140, 140, - /* 300 */ 142, 142, 5, 68, 33, 34, 201, 80, 113, 91, - /* 310 */ 2, 93, 94, 5, 257, 7, 98, 9, 100, 101, - /* 320 */ 102, 110, 104, 105, 267, 194, 80, 62, 63, 64, - /* 330 */ 140, 136, 142, 138, 69, 70, 71, 72, 233, 112, - /* 340 */ 145, 33, 34, 78, 76, 118, 62, 63, 64, 194, - /* 350 */ 200, 80, 84, 69, 70, 71, 72, 62, 63, 64, - /* 360 */ 80, 230, 135, 194, 69, 70, 71, 72, 139, 194, - /* 370 */ 141, 81, 143, 144, 139, 81, 141, 194, 143, 144, - /* 380 */ 140, 81, 142, 112, 110, 194, 194, 81, 108, 118, - /* 390 */ 194, 236, 194, 140, 239, 142, 194, 194, 197, 198, - /* 400 */ 110, 202, 203, 81, 110, 236, 135, 257, 239, 5, - /* 410 */ 110, 236, 81, 80, 239, 81, 110, 267, 81, 236, - /* 420 */ 112, 81, 239, 201, 199, 194, 194, 236, 236, 204, - /* 430 */ 239, 239, 236, 194, 236, 239, 114, 239, 236, 236, - /* 440 */ 214, 239, 239, 199, 110, 114, 113, 110, 204, 199, - /* 450 */ 110, 194, 238, 194, 204, 214, 214, 235, 5, 193, - /* 460 */ 194, 257, 5, 5, 5, 5, 240, 5, 254, 237, - /* 470 */ 239, 267, 5, 5, 5, 5, 5, 5, 5, 5, - /* 480 */ 5, 240, 240, 110, 81, 5, 5, 142, 142, 142, - /* 490 */ 58, 80, 16, 16, 112, 81, 80, 76, 15, 5, - /* 500 */ 83, 5, 24, 264, 5, 5, 5, 9, 109, 76, - /* 510 */ 80, 80, 125, 108, 108, 80, 125, 258, 110, 110, - /* 520 */ 80, 264, 81, 80, 1, 80, 114, 81, 80, 110, - /* 530 */ 81, 80, 110, 81, 110, 80, 92, 81, 115, 137, - /* 540 */ 93, 80, 5, 5, 148, 5, 5, 5, 148, 197, - /* 550 */ 202, 195, 60, 195, 229, 196, 195, 208, 196, 195, - /* 560 */ 195, 82, 196, 196, 207, 205, 54, 85, 50, 106, - /* 570 */ 195, 87, 209, 88, 206, 86, 89, 201, 90, 210, - /* 580 */ 195, 211, 201, 212, 82, 195, 243, 195, 195, 245, - /* 590 */ 248, 250, 253, 128, 244, 129, 195, 246, 134, 261, - /* 600 */ 247, 229, 195, 249, 194, 119, 251, 268, 195, 194, - /* 610 */ 120, 268, 121, 195, 194, 122, 268, 268, 123, 231, - /* 620 */ 195, 124, 194, 118, 238, 242, 252, 238, 194, 231, - /* 630 */ 194, 194, 194, 194, 130, 132, 194, 240, 261, 261, - /* 640 */ 261, 268, 268, 268, 194, 265, 268, 268, 194, 265, - /* 650 */ 256, 268, 257, 268, 268, 268, 268, 268, 231, 268, - /* 660 */ 231, 268, 268, 268, 238, 268, 268, 268, 268, 268, - /* 670 */ 268, 268, 84, 268, 268, 268, 268, 268, 268, 268, - /* 680 */ 268, 268, 268, 268, 268, 268, 268, 268, 268, 268, - /* 690 */ 268, 268, 268, 268, 268, 268, 268, 268, 268, 268, - /* 700 */ 194, 194, 194, 194, 194, 194, 268, 194, 194, 194, - /* 710 */ 194, 194, 268, 194, 194, 194, 194, 268, 194, 194, - /* 720 */ 194, 194, 194, 194, 194, 194, 194, 194, 194, 194, - /* 730 */ 194, 268, 268, 194, 268, 268, 268, 194, 194, 194, - /* 740 */ 194, 194, 194, 194, 194, 194, 194, 194, 194, 194, - /* 750 */ 194, 194, 194, 194, 194, 194, 194, 194, 268, 268, - /* 760 */ 268, 268, 268, 268, 268, 268, 268, 268, 268, 268, - /* 770 */ 268, 268, 268, 268, 268, 268, 268, 268, 268, 268, - /* 780 */ 268, 268, 268, 268, 268, 268, 268, 268, 268, 268, - /* 790 */ 268, 268, 268, 268, 268, 231, 231, 231, 268, 268, - /* 800 */ 268, 268, 268, 268, 268, 268, 268, 240, 240, 268, - /* 810 */ 268, 268, 268, 268, 268, 268, 268, 268, 268, 268, - /* 820 */ 268, 268, 268, 268, 268, 268, 257, 257, 257, 257, - /* 830 */ 257, 257, 257, 257, 257, 257, 257, 257, 257, 257, - /* 840 */ 257, 257, 257, 257, 257, + /* 0 */ 1, 33, 34, 76, 77, 37, 38, 39, 9, 62, + /* 10 */ 63, 64, 13, 14, 80, 16, 17, 126, 127, 20, + /* 20 */ 21, 81, 23, 24, 25, 26, 27, 28, 65, 66, + /* 30 */ 67, 91, 33, 34, 191, 192, 37, 38, 39, 13, + /* 40 */ 14, 0, 16, 17, 110, 111, 20, 21, 60, 23, + /* 50 */ 24, 25, 26, 27, 28, 5, 5, 7, 7, 33, + /* 60 */ 34, 80, 137, 37, 38, 39, 13, 14, 80, 16, + /* 70 */ 17, 146, 147, 20, 21, 60, 23, 24, 25, 26, + /* 80 */ 27, 28, 91, 240, 194, 201, 33, 34, 1, 108, + /* 90 */ 37, 38, 39, 37, 38, 39, 9, 81, 81, 256, + /* 100 */ 5, 13, 14, 59, 16, 17, 200, 81, 20, 21, + /* 110 */ 111, 23, 24, 25, 26, 27, 28, 233, 234, 235, + /* 120 */ 236, 33, 34, 91, 133, 37, 38, 39, 33, 34, + /* 130 */ 114, 114, 45, 46, 47, 48, 49, 50, 51, 52, + /* 140 */ 53, 54, 55, 56, 57, 58, 194, 14, 61, 16, + /* 150 */ 17, 261, 262, 20, 21, 194, 23, 24, 25, 26, + /* 160 */ 27, 28, 15, 131, 194, 259, 33, 34, 118, 118, + /* 170 */ 37, 38, 39, 16, 17, 269, 1, 20, 21, 200, + /* 180 */ 23, 24, 25, 26, 27, 28, 140, 200, 142, 237, + /* 190 */ 33, 34, 231, 241, 37, 38, 39, 215, 216, 217, + /* 200 */ 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, + /* 210 */ 228, 229, 37, 194, 92, 93, 94, 95, 96, 97, + /* 220 */ 98, 99, 100, 101, 102, 103, 104, 105, 106, 1, + /* 230 */ 2, 1, 91, 5, 264, 7, 266, 9, 259, 9, + /* 240 */ 44, 25, 26, 27, 28, 140, 259, 142, 269, 33, + /* 250 */ 34, 91, 194, 37, 38, 39, 269, 61, 117, 112, + /* 260 */ 194, 33, 34, 83, 68, 37, 140, 80, 142, 73, + /* 270 */ 74, 75, 91, 1, 2, 79, 80, 5, 68, 7, + /* 280 */ 215, 9, 217, 218, 5, 266, 7, 222, 81, 224, + /* 290 */ 225, 226, 1, 228, 229, 237, 109, 21, 91, 241, + /* 300 */ 9, 202, 203, 237, 21, 33, 34, 241, 80, 113, + /* 310 */ 92, 2, 94, 95, 5, 194, 7, 99, 9, 101, + /* 320 */ 102, 103, 68, 105, 106, 5, 81, 7, 62, 63, + /* 330 */ 64, 140, 136, 142, 138, 69, 70, 71, 72, 194, + /* 340 */ 112, 145, 33, 34, 78, 194, 118, 80, 140, 139, + /* 350 */ 142, 141, 80, 143, 144, 37, 194, 62, 63, 64, + /* 360 */ 243, 194, 194, 135, 69, 70, 71, 72, 62, 63, + /* 370 */ 64, 80, 194, 194, 257, 69, 70, 71, 72, 194, + /* 380 */ 113, 140, 237, 142, 112, 0, 241, 266, 237, 268, + /* 390 */ 118, 81, 241, 139, 201, 141, 81, 143, 144, 237, + /* 400 */ 81, 91, 81, 241, 237, 237, 91, 135, 241, 241, + /* 410 */ 91, 194, 91, 81, 81, 237, 237, 81, 81, 241, + /* 420 */ 241, 112, 237, 91, 91, 81, 241, 91, 91, 236, + /* 430 */ 81, 197, 198, 201, 116, 91, 213, 214, 199, 199, + /* 440 */ 91, 199, 76, 204, 204, 194, 204, 194, 5, 240, + /* 450 */ 84, 238, 240, 238, 259, 242, 194, 242, 241, 238, + /* 460 */ 5, 193, 194, 242, 269, 256, 234, 82, 256, 5, + /* 470 */ 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + /* 480 */ 5, 5, 5, 5, 5, 5, 58, 142, 142, 142, + /* 490 */ 239, 80, 142, 112, 81, 80, 76, 16, 16, 15, + /* 500 */ 83, 5, 5, 5, 5, 5, 76, 24, 110, 80, + /* 510 */ 9, 109, 80, 109, 80, 125, 91, 125, 91, 266, + /* 520 */ 80, 80, 260, 81, 1, 80, 91, 81, 80, 91, + /* 530 */ 81, 80, 114, 81, 80, 91, 115, 81, 80, 5, + /* 540 */ 137, 94, 5, 93, 148, 5, 5, 148, 5, 197, + /* 550 */ 202, 195, 60, 195, 214, 196, 195, 5, 196, 195, + /* 560 */ 230, 196, 205, 196, 195, 54, 107, 82, 208, 50, + /* 570 */ 207, 85, 195, 195, 87, 86, 88, 209, 206, 89, + /* 580 */ 210, 90, 211, 201, 82, 212, 195, 201, 195, 195, + /* 590 */ 247, 134, 250, 252, 132, 195, 245, 263, 263, 246, + /* 600 */ 195, 263, 248, 195, 230, 195, 251, 195, 194, 270, + /* 610 */ 194, 270, 119, 194, 120, 270, 121, 194, 194, 270, + /* 620 */ 194, 270, 270, 270, 249, 122, 118, 123, 240, 253, + /* 630 */ 124, 194, 270, 128, 254, 240, 129, 270, 255, 130, + /* 640 */ 270, 244, 263, 242, 270, 258, 240, 194, 270, 242, + /* 650 */ 270, 267, 270, 270, 194, 194, 267, 194, 270, 270, + /* 660 */ 270, 270, 270, 232, 242, 232, 270, 270, 232, 270, + /* 670 */ 270, 232, 270, 270, 270, 270, 270, 84, 270, 270, + /* 680 */ 270, 270, 270, 270, 270, 270, 270, 270, 270, 270, + /* 690 */ 270, 270, 270, 270, 270, 270, 270, 270, 270, 270, + /* 700 */ 270, 270, 270, 270, 194, 270, 194, 194, 194, 194, + /* 710 */ 194, 194, 194, 270, 194, 194, 194, 270, 194, 194, + /* 720 */ 194, 194, 194, 194, 194, 194, 194, 194, 270, 194, + /* 730 */ 194, 270, 194, 194, 270, 270, 194, 270, 194, 194, + /* 740 */ 194, 194, 194, 194, 194, 194, 270, 194, 194, 194, + /* 750 */ 194, 194, 194, 194, 194, 194, 194, 194, 194, 194, + /* 760 */ 194, 194, 194, 194, 270, 270, 270, 270, 270, 270, + /* 770 */ 270, 270, 270, 270, 270, 270, 270, 270, 270, 270, + /* 780 */ 270, 270, 270, 270, 270, 270, 270, 270, 270, 270, + /* 790 */ 270, 270, 270, 270, 270, 270, 270, 270, 270, 270, + /* 800 */ 270, 270, 232, 232, 232, 270, 270, 270, 270, 270, + /* 810 */ 270, 270, 270, 270, 270, 270, 270, 270, 270, 270, + /* 820 */ 270, 270, 270, 270, 270, 270, 270, 270, 270, 270, + /* 830 */ 270, 270, 259, 259, 259, 259, 259, 259, 259, 259, + /* 840 */ 259, 259, 259, 259, 259, 259, 259, 259, 259, 259, + /* 850 */ 259, 259, }; -#define YY_SHIFT_USE_DFLT (-103) -#define YY_SHIFT_COUNT (345) -#define YY_SHIFT_MIN (-102) -#define YY_SHIFT_MAX (588) +#define YY_SHIFT_USE_DFLT (-110) +#define YY_SHIFT_COUNT (346) +#define YY_SHIFT_MIN (-109) +#define YY_SHIFT_MAX (593) static const short yy_shift_ofst[] = { - /* 0 */ 195, 122, 122, 218, 218, 502, 227, 271, 271, 246, - /* 10 */ 237, 237, 237, 237, 237, 237, 237, 237, 237, 237, - /* 20 */ 237, 237, 237, -1, 87, 271, 308, 308, 308, 308, - /* 30 */ 333, 333, 237, 237, 237, 176, 237, 237, 268, 502, - /* 40 */ 588, 588, -103, -103, -103, 271, 271, 271, 271, 271, - /* 50 */ 271, 271, 271, 271, 271, 271, 271, 271, 271, 271, - /* 60 */ 271, 271, 271, 271, 271, 308, 308, 308, 118, 118, - /* 70 */ 118, 118, 118, 118, 118, 237, 237, 237, 161, 237, - /* 80 */ 237, 237, 333, 333, 237, 237, 237, 237, 124, 124, - /* 90 */ -42, 333, 237, 237, 237, 237, 237, 237, 237, 237, - /* 100 */ 237, 237, 237, 237, 237, 237, 237, 237, 237, 237, - /* 110 */ 237, 237, 237, 237, 237, 237, 237, 237, 237, 237, - /* 120 */ 237, 237, 237, 237, 237, 237, 237, 237, 237, 237, - /* 130 */ 237, 237, 237, 237, 237, 237, 237, 237, 237, 237, - /* 140 */ 237, 237, 237, 237, 492, 492, 492, 505, 505, 505, - /* 150 */ 492, 505, 492, 504, 503, 466, 497, 465, 495, 493, - /* 160 */ 491, 490, 486, 464, 492, 492, 492, 463, 502, 502, - /* 170 */ 492, 492, 488, 487, 518, 489, 485, 512, 484, 482, - /* 180 */ 463, 492, 479, 479, 492, 479, 492, 479, 492, 492, - /* 190 */ -103, -103, 26, 53, 53, 88, 53, 133, 157, 215, - /* 200 */ 215, 215, 215, 265, 295, 284, -32, -32, -32, -32, - /* 210 */ 235, 229, -102, 9, 56, 56, 112, 50, 17, -34, - /* 220 */ 340, 331, 322, 337, 334, 306, 59, -25, 300, 294, - /* 230 */ 290, 211, 186, 280, 185, 83, 61, -49, 147, 65, - /* 240 */ 253, 240, 190, 159, 158, -66, 144, 182, 181, -59, - /* 250 */ 542, 400, 541, 540, 396, 538, 537, 447, 444, 402, - /* 260 */ 412, 406, 461, 423, 456, 455, 424, 422, 452, 451, - /* 270 */ 449, 419, 448, 446, 445, 523, 443, 441, 440, 409, - /* 280 */ 391, 408, 387, 435, 406, 431, 405, 430, 399, 433, - /* 290 */ 498, 501, 500, 499, 496, 494, 417, 483, 421, 416, - /* 300 */ 414, 382, 411, 478, 432, 477, 347, 346, 373, 373, - /* 310 */ 373, 373, 476, 345, 143, 373, 373, 373, 481, 480, - /* 320 */ 403, 373, 475, 474, 473, 472, 471, 470, 469, 468, - /* 330 */ 467, 462, 460, 459, 458, 457, 453, 404, 297, 274, - /* 340 */ 188, 134, 103, 39, -38, 3, + /* 0 */ 196, 122, 122, 218, 218, 502, 228, 272, 272, 291, + /* 10 */ 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, + /* 20 */ 230, 230, 230, -1, 87, 272, 309, 309, 309, 267, + /* 30 */ 267, 230, 230, 230, 385, 230, 230, 366, 502, 593, + /* 40 */ 593, 552, -110, -110, -110, 272, 272, 272, 272, 272, + /* 50 */ 272, 272, 272, 272, 272, 272, 272, 272, 272, 272, + /* 60 */ 272, 272, 272, 272, 272, 309, 309, 309, 95, 95, + /* 70 */ 95, 95, 95, 95, 95, 230, 230, 230, 318, 230, + /* 80 */ 230, 230, 267, 267, 230, 230, 230, 230, -109, -109, + /* 90 */ 141, 267, 230, 230, 230, 230, 230, 230, 230, 230, + /* 100 */ 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, + /* 110 */ 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, + /* 120 */ 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, + /* 130 */ 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, + /* 140 */ 230, 230, 230, 230, 492, 492, 492, 508, 508, 508, + /* 150 */ 492, 508, 492, 509, 462, 507, 506, 505, 504, 503, + /* 160 */ 495, 494, 493, 457, 492, 492, 492, 459, 502, 502, + /* 170 */ 492, 492, 491, 490, 519, 489, 488, 511, 487, 486, + /* 180 */ 459, 552, 492, 485, 485, 492, 485, 492, 485, 492, + /* 190 */ 492, -110, -110, 26, 53, 53, 88, 53, 133, 157, + /* 200 */ 216, 216, 216, 216, 266, 306, 295, -32, -32, -32, + /* 210 */ -32, 254, 210, -75, -66, 56, 56, 51, 50, -37, + /* 220 */ -53, 349, 17, 16, 344, 337, 336, -9, 32, 333, + /* 230 */ 332, 321, 319, 315, 187, 310, 207, 175, -12, 147, + /* 240 */ -60, 241, 208, 191, 320, 279, 126, 105, -19, 46, + /* 250 */ -73, 543, 399, 541, 540, 396, 537, 534, 447, 450, + /* 260 */ 403, 418, 404, 458, 421, 456, 454, 444, 438, 452, + /* 270 */ 451, 449, 435, 448, 446, 445, 523, 441, 442, 440, + /* 280 */ 427, 392, 425, 390, 434, 404, 432, 402, 429, 398, + /* 290 */ 430, 501, 500, 499, 498, 497, 496, 417, 484, 420, + /* 300 */ 415, 413, 381, 411, 483, 428, 482, 350, 347, 181, + /* 310 */ 181, 181, 181, 481, 346, 345, 181, 181, 181, 480, + /* 320 */ 479, 245, 181, 478, 477, 476, 475, 474, 473, 472, + /* 330 */ 471, 470, 469, 468, 467, 466, 465, 464, 455, 443, + /* 340 */ 160, 180, 283, 276, 15, 44, 41, }; -#define YY_REDUCE_USE_DFLT (-208) -#define YY_REDUCE_COUNT (191) -#define YY_REDUCE_MIN (-207) -#define YY_REDUCE_MAX (587) +#define YY_REDUCE_USE_DFLT (-158) +#define YY_REDUCE_COUNT (192) +#define YY_REDUCE_MIN (-157) +#define YY_REDUCE_MAX (592) static const short yy_reduce_ofst[] = { - /* 0 */ -182, -16, -16, 66, 66, -104, 150, 57, -196, -15, - /* 10 */ 203, -29, -31, 202, 198, 196, 192, 191, 183, 175, - /* 20 */ 169, 155, -136, 259, 266, 204, 242, 241, 226, 48, - /* 30 */ 214, 27, 257, 239, 232, 222, 131, 231, 250, 105, - /* 40 */ 244, 225, -207, 199, 201, 587, 586, 585, 584, 583, - /* 50 */ 582, 581, 580, 579, 578, 577, 576, 575, 574, 573, - /* 60 */ 572, 571, 570, 569, 395, 568, 567, 397, 566, 565, - /* 70 */ 564, 429, 427, 398, 388, 563, 562, 561, 394, 560, - /* 80 */ 559, 558, 426, 389, 557, 556, 555, 554, 384, 380, - /* 90 */ 383, 386, 553, 552, 551, 550, 549, 548, 547, 546, - /* 100 */ 545, 544, 543, 539, 536, 535, 534, 533, 532, 531, - /* 110 */ 530, 529, 528, 527, 526, 525, 524, 522, 521, 520, - /* 120 */ 519, 517, 516, 515, 514, 513, 511, 510, 509, 508, - /* 130 */ 507, 506, 454, 450, 442, 439, 438, 437, 436, 434, - /* 140 */ 428, 420, 415, 410, 425, 418, 413, 379, 378, 377, - /* 150 */ 407, 338, 401, 339, 374, 355, 341, 354, 342, 353, - /* 160 */ 351, 344, 350, 343, 393, 392, 390, 372, 381, 376, - /* 170 */ 385, 375, 371, 370, 369, 368, 363, 357, 349, 360, - /* 180 */ 325, 365, 367, 366, 364, 362, 361, 359, 358, 356, - /* 190 */ 348, 352, + /* 0 */ -157, -18, -18, 65, 65, -116, -13, -21, -94, -110, + /* 10 */ 185, 121, -30, 179, 178, 168, 167, 162, 151, 145, + /* 20 */ 66, 58, -48, 262, 268, 195, 221, 215, 213, 212, + /* 30 */ 209, 253, 19, 251, 193, -39, 217, 242, 232, 240, + /* 40 */ 239, 223, 117, 99, 234, 592, 591, 590, 589, 588, + /* 50 */ 587, 586, 585, 584, 583, 582, 581, 580, 579, 578, + /* 60 */ 577, 576, 575, 574, 573, 422, 407, 401, 572, 571, + /* 70 */ 570, 439, 436, 433, 431, 569, 568, 567, 387, 566, + /* 80 */ 565, 564, 406, 395, 563, 562, 561, 560, 389, 384, + /* 90 */ 397, 388, 559, 558, 557, 556, 555, 554, 553, 551, + /* 100 */ 550, 549, 548, 547, 546, 545, 544, 542, 539, 538, + /* 110 */ 536, 535, 533, 532, 531, 530, 529, 528, 527, 526, + /* 120 */ 525, 524, 522, 521, 520, 518, 517, 516, 515, 514, + /* 130 */ 513, 512, 510, 463, 461, 460, 453, 437, 426, 424, + /* 140 */ 423, 419, 416, 414, 412, 410, 408, 379, 338, 335, + /* 150 */ 405, 334, 400, 383, 380, 376, 341, 355, 342, 375, + /* 160 */ 354, 343, 353, 351, 394, 393, 391, 374, 386, 382, + /* 170 */ 378, 377, 373, 371, 370, 372, 368, 363, 360, 357, + /* 180 */ 330, 340, 369, 367, 365, 364, 362, 361, 359, 358, + /* 190 */ 356, 348, 352, }; static const YYACTIONTYPE yy_default[] = { - /* 0 */ 825, 655, 601, 667, 588, 598, 803, 803, 803, 825, - /* 10 */ 825, 825, 825, 825, 825, 825, 825, 825, 825, 825, - /* 20 */ 825, 825, 825, 714, 560, 803, 825, 825, 825, 825, - /* 30 */ 825, 825, 825, 825, 825, 598, 825, 825, 604, 598, - /* 40 */ 604, 604, 709, 639, 657, 825, 825, 825, 825, 825, - /* 50 */ 825, 825, 825, 825, 825, 825, 825, 825, 825, 825, - /* 60 */ 825, 825, 825, 825, 825, 825, 825, 825, 825, 825, - /* 70 */ 825, 825, 825, 825, 825, 825, 825, 825, 716, 722, - /* 80 */ 719, 825, 825, 825, 724, 825, 825, 825, 746, 746, - /* 90 */ 707, 825, 825, 825, 825, 825, 825, 825, 825, 825, - /* 100 */ 825, 825, 825, 825, 825, 825, 825, 825, 825, 825, - /* 110 */ 825, 825, 825, 825, 825, 825, 825, 825, 825, 825, - /* 120 */ 586, 825, 584, 825, 825, 825, 825, 825, 825, 825, - /* 130 */ 825, 825, 825, 825, 825, 825, 825, 571, 825, 825, - /* 140 */ 825, 825, 825, 825, 562, 562, 562, 825, 825, 825, - /* 150 */ 562, 825, 562, 753, 757, 751, 739, 747, 738, 734, - /* 160 */ 732, 730, 729, 761, 562, 562, 562, 602, 598, 598, - /* 170 */ 562, 562, 620, 618, 616, 608, 614, 610, 612, 606, - /* 180 */ 589, 562, 596, 596, 562, 596, 562, 596, 562, 562, - /* 190 */ 639, 657, 825, 762, 752, 825, 802, 792, 791, 798, - /* 200 */ 790, 789, 788, 825, 825, 825, 784, 787, 786, 785, - /* 210 */ 825, 825, 825, 825, 794, 793, 825, 825, 825, 825, - /* 220 */ 825, 825, 825, 825, 825, 825, 758, 754, 825, 825, - /* 230 */ 825, 825, 825, 825, 825, 825, 825, 764, 825, 825, - /* 240 */ 825, 825, 825, 825, 825, 669, 825, 825, 825, 825, - /* 250 */ 825, 825, 825, 825, 825, 825, 825, 825, 825, 825, - /* 260 */ 706, 825, 825, 825, 825, 825, 718, 717, 825, 825, - /* 270 */ 825, 825, 825, 825, 825, 825, 825, 825, 825, 748, - /* 280 */ 825, 740, 825, 825, 681, 825, 825, 825, 825, 825, - /* 290 */ 825, 825, 825, 825, 825, 825, 825, 825, 825, 825, - /* 300 */ 825, 825, 825, 825, 825, 825, 825, 825, 821, 816, - /* 310 */ 817, 814, 825, 825, 825, 813, 808, 809, 825, 825, - /* 320 */ 825, 806, 825, 825, 825, 825, 825, 825, 825, 825, - /* 330 */ 825, 825, 825, 825, 825, 825, 825, 825, 825, 623, - /* 340 */ 825, 569, 567, 825, 558, 825, 824, 823, 822, 805, - /* 350 */ 804, 677, 715, 711, 713, 712, 710, 723, 720, 721, - /* 360 */ 705, 704, 703, 725, 708, 728, 727, 731, 733, 736, - /* 370 */ 735, 737, 726, 750, 749, 742, 743, 745, 744, 741, - /* 380 */ 760, 759, 756, 755, 702, 687, 682, 679, 686, 685, - /* 390 */ 684, 683, 680, 676, 675, 603, 656, 654, 653, 652, - /* 400 */ 651, 650, 649, 648, 647, 646, 645, 644, 643, 642, - /* 410 */ 641, 640, 635, 631, 629, 628, 627, 624, 597, 600, - /* 420 */ 599, 800, 801, 799, 797, 796, 795, 781, 780, 779, - /* 430 */ 778, 775, 774, 773, 770, 776, 772, 769, 777, 771, - /* 440 */ 768, 767, 766, 765, 783, 782, 763, 592, 820, 819, - /* 450 */ 818, 815, 812, 811, 810, 807, 689, 690, 671, 674, - /* 460 */ 673, 672, 670, 688, 622, 621, 619, 617, 609, 615, - /* 470 */ 611, 613, 607, 605, 591, 590, 668, 638, 666, 665, - /* 480 */ 664, 663, 662, 661, 660, 659, 658, 637, 636, 634, - /* 490 */ 633, 632, 630, 626, 625, 692, 701, 700, 699, 698, - /* 500 */ 697, 696, 695, 694, 693, 691, 587, 585, 583, 582, - /* 510 */ 581, 580, 579, 578, 577, 576, 575, 574, 595, 573, - /* 520 */ 572, 570, 568, 566, 565, 564, 594, 593, 563, 561, - /* 530 */ 559, 557, 556, 555, 554, 553, 552, 551, 550, 549, - /* 540 */ 548, 547, 546, 545, + /* 0 */ 832, 662, 605, 674, 592, 602, 810, 810, 810, 832, + /* 10 */ 832, 832, 832, 832, 832, 832, 832, 832, 832, 832, + /* 20 */ 832, 832, 832, 721, 564, 810, 832, 832, 832, 832, + /* 30 */ 832, 832, 832, 832, 602, 832, 832, 608, 602, 608, + /* 40 */ 608, 832, 716, 646, 664, 832, 832, 832, 832, 832, + /* 50 */ 832, 832, 832, 832, 832, 832, 832, 832, 832, 832, + /* 60 */ 832, 832, 832, 832, 832, 832, 832, 832, 832, 832, + /* 70 */ 832, 832, 832, 832, 832, 832, 832, 832, 723, 729, + /* 80 */ 726, 832, 832, 832, 731, 832, 832, 832, 753, 753, + /* 90 */ 714, 832, 832, 832, 832, 832, 832, 832, 832, 832, + /* 100 */ 832, 832, 832, 832, 832, 832, 832, 832, 832, 832, + /* 110 */ 832, 832, 832, 832, 832, 832, 832, 832, 832, 832, + /* 120 */ 590, 832, 588, 832, 832, 832, 832, 832, 832, 832, + /* 130 */ 832, 832, 832, 832, 832, 832, 832, 575, 832, 832, + /* 140 */ 832, 832, 832, 832, 566, 566, 566, 832, 832, 832, + /* 150 */ 566, 832, 566, 760, 764, 758, 746, 754, 745, 741, + /* 160 */ 739, 737, 736, 768, 566, 566, 566, 606, 602, 602, + /* 170 */ 566, 566, 624, 622, 620, 612, 618, 614, 616, 610, + /* 180 */ 593, 832, 566, 600, 600, 566, 600, 566, 600, 566, + /* 190 */ 566, 646, 664, 832, 769, 759, 832, 809, 799, 798, + /* 200 */ 805, 797, 796, 795, 832, 832, 832, 791, 794, 793, + /* 210 */ 792, 832, 832, 832, 832, 801, 800, 832, 832, 832, + /* 220 */ 832, 832, 832, 832, 832, 832, 832, 765, 761, 832, + /* 230 */ 832, 832, 832, 832, 832, 832, 832, 832, 771, 832, + /* 240 */ 832, 832, 832, 832, 832, 832, 832, 832, 676, 832, + /* 250 */ 832, 832, 832, 832, 832, 832, 832, 832, 832, 832, + /* 260 */ 832, 713, 832, 832, 832, 832, 832, 725, 724, 832, + /* 270 */ 832, 832, 832, 832, 832, 832, 832, 832, 832, 832, + /* 280 */ 755, 832, 747, 832, 832, 688, 832, 832, 832, 832, + /* 290 */ 832, 832, 832, 832, 832, 832, 832, 832, 832, 832, + /* 300 */ 832, 832, 832, 832, 832, 832, 832, 832, 832, 828, + /* 310 */ 823, 824, 821, 832, 832, 832, 820, 815, 816, 832, + /* 320 */ 832, 832, 813, 832, 832, 832, 832, 832, 832, 832, + /* 330 */ 832, 832, 832, 832, 832, 832, 832, 832, 832, 832, + /* 340 */ 630, 832, 573, 571, 832, 562, 832, 831, 830, 829, + /* 350 */ 812, 811, 684, 722, 718, 720, 719, 717, 730, 727, + /* 360 */ 728, 712, 711, 710, 732, 715, 735, 734, 738, 740, + /* 370 */ 743, 742, 744, 733, 757, 756, 749, 750, 752, 751, + /* 380 */ 748, 767, 766, 763, 762, 709, 694, 689, 686, 693, + /* 390 */ 692, 691, 699, 698, 690, 687, 683, 682, 607, 663, + /* 400 */ 661, 660, 659, 658, 657, 656, 655, 654, 653, 652, + /* 410 */ 651, 650, 649, 648, 647, 642, 638, 636, 635, 634, + /* 420 */ 631, 601, 604, 603, 807, 808, 806, 804, 803, 802, + /* 430 */ 788, 787, 786, 785, 782, 781, 780, 777, 783, 779, + /* 440 */ 776, 784, 778, 775, 774, 773, 772, 790, 789, 770, + /* 450 */ 596, 827, 826, 825, 822, 819, 708, 707, 706, 705, + /* 460 */ 704, 703, 702, 701, 700, 818, 817, 814, 696, 697, + /* 470 */ 678, 681, 680, 679, 677, 695, 626, 625, 623, 621, + /* 480 */ 613, 619, 615, 617, 611, 609, 595, 594, 675, 645, + /* 490 */ 673, 672, 671, 670, 669, 668, 667, 666, 665, 644, + /* 500 */ 643, 641, 640, 639, 637, 633, 632, 628, 629, 627, + /* 510 */ 591, 589, 587, 586, 585, 584, 583, 582, 581, 580, + /* 520 */ 579, 578, 599, 577, 576, 574, 572, 570, 569, 568, + /* 530 */ 598, 597, 567, 565, 563, 561, 560, 559, 558, 557, + /* 540 */ 556, 555, 554, 553, 552, 551, 550, 549, }; /* The next table maps tokens into fallback tokens. If a construct @@ -570,6 +572,7 @@ static const YYCODETYPE yyFallback[] = { 0, /* QTIME => nothing */ 0, /* CONNS => nothing */ 0, /* STATE => nothing */ + 0, /* COMMA => nothing */ 0, /* KEEP => nothing */ 0, /* CACHE => nothing */ 0, /* REPLICA => nothing */ @@ -589,7 +592,6 @@ static const YYCODETYPE yyFallback[] = { 0, /* UNSIGNED => nothing */ 0, /* TAGS => nothing */ 0, /* USING => nothing */ - 0, /* COMMA => nothing */ 0, /* AS => nothing */ 1, /* NULL => ID */ 0, /* SELECT => nothing */ @@ -769,12 +771,12 @@ static const char *const yyTokenName[] = { "PASS", "PRIVILEGE", "LOCAL", "COMPACT", "LP", "RP", "IF", "EXISTS", "PPS", "TSERIES", "DBS", "STORAGE", - "QTIME", "CONNS", "STATE", "KEEP", - "CACHE", "REPLICA", "QUORUM", "DAYS", - "MINROWS", "MAXROWS", "BLOCKS", "CTIME", - "WAL", "FSYNC", "COMP", "PRECISION", - "UPDATE", "CACHELAST", "PARTITIONS", "UNSIGNED", - "TAGS", "USING", "COMMA", "AS", + "QTIME", "CONNS", "STATE", "COMMA", + "KEEP", "CACHE", "REPLICA", "QUORUM", + "DAYS", "MINROWS", "MAXROWS", "BLOCKS", + "CTIME", "WAL", "FSYNC", "COMP", + "PRECISION", "UPDATE", "CACHELAST", "PARTITIONS", + "UNSIGNED", "TAGS", "USING", "AS", "NULL", "SELECT", "UNION", "ALL", "DISTINCT", "FROM", "VARIABLE", "INTERVAL", "SESSION", "STATE_WINDOW", "FILL", "SLIDING", @@ -800,20 +802,21 @@ static const char *const yyTokenName[] = { "exprlist", "ifnotexists", "db_optr", "topic_optr", "pps", "tseries", "dbs", "streams", "storage", "qtime", "users", "conns", - "state", "keep", "tagitemlist", "cache", - "replica", "quorum", "days", "minrows", - "maxrows", "blocks", "ctime", "wal", - "fsync", "comp", "prec", "update", - "cachelast", "partitions", "typename", "signed", - "create_table_args", "create_stable_args", "create_table_list", "create_from_stable", - "columnlist", "tagNamelist", "select", "column", - "tagitem", "selcollist", "from", "where_opt", - "interval_opt", "session_option", "windowstate_option", "fill_opt", - "sliding_opt", "groupby_opt", "orderby_opt", "having_opt", - "slimit_opt", "limit_opt", "union", "sclp", - "distinct", "expr", "as", "tablelist", - "sub", "tmvar", "sortlist", "sortitem", - "item", "sortorder", "grouplist", "expritem", + "state", "intitemlist", "intitem", "keep", + "cache", "replica", "quorum", "days", + "minrows", "maxrows", "blocks", "ctime", + "wal", "fsync", "comp", "prec", + "update", "cachelast", "partitions", "typename", + "signed", "create_table_args", "create_stable_args", "create_table_list", + "create_from_stable", "columnlist", "tagitemlist", "tagNamelist", + "select", "column", "tagitem", "selcollist", + "from", "where_opt", "interval_opt", "session_option", + "windowstate_option", "fill_opt", "sliding_opt", "groupby_opt", + "orderby_opt", "having_opt", "slimit_opt", "limit_opt", + "union", "sclp", "distinct", "expr", + "as", "tablelist", "sub", "tmvar", + "sortlist", "sortitem", "item", "sortorder", + "grouplist", "expritem", }; #endif /* NDEBUG */ @@ -900,208 +903,211 @@ static const char *const yyRuleName[] = { /* 76 */ "state ::=", /* 77 */ "state ::= STATE ids", /* 78 */ "acct_optr ::= pps tseries storage streams qtime dbs users conns state", - /* 79 */ "keep ::= KEEP tagitemlist", - /* 80 */ "cache ::= CACHE INTEGER", - /* 81 */ "replica ::= REPLICA INTEGER", - /* 82 */ "quorum ::= QUORUM INTEGER", - /* 83 */ "days ::= DAYS INTEGER", - /* 84 */ "minrows ::= MINROWS INTEGER", - /* 85 */ "maxrows ::= MAXROWS INTEGER", - /* 86 */ "blocks ::= BLOCKS INTEGER", - /* 87 */ "ctime ::= CTIME INTEGER", - /* 88 */ "wal ::= WAL INTEGER", - /* 89 */ "fsync ::= FSYNC INTEGER", - /* 90 */ "comp ::= COMP INTEGER", - /* 91 */ "prec ::= PRECISION STRING", - /* 92 */ "update ::= UPDATE INTEGER", - /* 93 */ "cachelast ::= CACHELAST INTEGER", - /* 94 */ "partitions ::= PARTITIONS INTEGER", - /* 95 */ "db_optr ::=", - /* 96 */ "db_optr ::= db_optr cache", - /* 97 */ "db_optr ::= db_optr replica", - /* 98 */ "db_optr ::= db_optr quorum", - /* 99 */ "db_optr ::= db_optr days", - /* 100 */ "db_optr ::= db_optr minrows", - /* 101 */ "db_optr ::= db_optr maxrows", - /* 102 */ "db_optr ::= db_optr blocks", - /* 103 */ "db_optr ::= db_optr ctime", - /* 104 */ "db_optr ::= db_optr wal", - /* 105 */ "db_optr ::= db_optr fsync", - /* 106 */ "db_optr ::= db_optr comp", - /* 107 */ "db_optr ::= db_optr prec", - /* 108 */ "db_optr ::= db_optr keep", - /* 109 */ "db_optr ::= db_optr update", - /* 110 */ "db_optr ::= db_optr cachelast", - /* 111 */ "topic_optr ::= db_optr", - /* 112 */ "topic_optr ::= topic_optr partitions", - /* 113 */ "alter_db_optr ::=", - /* 114 */ "alter_db_optr ::= alter_db_optr replica", - /* 115 */ "alter_db_optr ::= alter_db_optr quorum", - /* 116 */ "alter_db_optr ::= alter_db_optr keep", - /* 117 */ "alter_db_optr ::= alter_db_optr blocks", - /* 118 */ "alter_db_optr ::= alter_db_optr comp", - /* 119 */ "alter_db_optr ::= alter_db_optr wal", - /* 120 */ "alter_db_optr ::= alter_db_optr fsync", - /* 121 */ "alter_db_optr ::= alter_db_optr update", - /* 122 */ "alter_db_optr ::= alter_db_optr cachelast", - /* 123 */ "alter_topic_optr ::= alter_db_optr", - /* 124 */ "alter_topic_optr ::= alter_topic_optr partitions", - /* 125 */ "typename ::= ids", - /* 126 */ "typename ::= ids LP signed RP", - /* 127 */ "typename ::= ids UNSIGNED", - /* 128 */ "signed ::= INTEGER", - /* 129 */ "signed ::= PLUS INTEGER", - /* 130 */ "signed ::= MINUS INTEGER", - /* 131 */ "cmd ::= CREATE TABLE create_table_args", - /* 132 */ "cmd ::= CREATE TABLE create_stable_args", - /* 133 */ "cmd ::= CREATE STABLE create_stable_args", - /* 134 */ "cmd ::= CREATE TABLE create_table_list", - /* 135 */ "create_table_list ::= create_from_stable", - /* 136 */ "create_table_list ::= create_table_list create_from_stable", - /* 137 */ "create_table_args ::= ifnotexists ids cpxName LP columnlist RP", - /* 138 */ "create_stable_args ::= ifnotexists ids cpxName LP columnlist RP TAGS LP columnlist RP", - /* 139 */ "create_from_stable ::= ifnotexists ids cpxName USING ids cpxName TAGS LP tagitemlist RP", - /* 140 */ "create_from_stable ::= ifnotexists ids cpxName USING ids cpxName LP tagNamelist RP TAGS LP tagitemlist RP", - /* 141 */ "tagNamelist ::= tagNamelist COMMA ids", - /* 142 */ "tagNamelist ::= ids", - /* 143 */ "create_table_args ::= ifnotexists ids cpxName AS select", - /* 144 */ "columnlist ::= columnlist COMMA column", - /* 145 */ "columnlist ::= column", - /* 146 */ "column ::= ids typename", - /* 147 */ "tagitemlist ::= tagitemlist COMMA tagitem", - /* 148 */ "tagitemlist ::= tagitem", - /* 149 */ "tagitem ::= INTEGER", - /* 150 */ "tagitem ::= FLOAT", - /* 151 */ "tagitem ::= STRING", - /* 152 */ "tagitem ::= BOOL", - /* 153 */ "tagitem ::= NULL", - /* 154 */ "tagitem ::= MINUS INTEGER", - /* 155 */ "tagitem ::= MINUS FLOAT", - /* 156 */ "tagitem ::= PLUS INTEGER", - /* 157 */ "tagitem ::= PLUS FLOAT", - /* 158 */ "select ::= SELECT selcollist from where_opt interval_opt session_option windowstate_option fill_opt sliding_opt groupby_opt orderby_opt having_opt slimit_opt limit_opt", - /* 159 */ "select ::= LP select RP", - /* 160 */ "union ::= select", - /* 161 */ "union ::= union UNION ALL select", - /* 162 */ "cmd ::= union", - /* 163 */ "select ::= SELECT selcollist", - /* 164 */ "sclp ::= selcollist COMMA", - /* 165 */ "sclp ::=", - /* 166 */ "selcollist ::= sclp distinct expr as", - /* 167 */ "selcollist ::= sclp STAR", - /* 168 */ "as ::= AS ids", - /* 169 */ "as ::= ids", - /* 170 */ "as ::=", - /* 171 */ "distinct ::= DISTINCT", - /* 172 */ "distinct ::=", - /* 173 */ "from ::= FROM tablelist", - /* 174 */ "from ::= FROM sub", - /* 175 */ "sub ::= LP union RP", - /* 176 */ "sub ::= LP union RP ids", - /* 177 */ "sub ::= sub COMMA LP union RP ids", - /* 178 */ "tablelist ::= ids cpxName", - /* 179 */ "tablelist ::= ids cpxName ids", - /* 180 */ "tablelist ::= tablelist COMMA ids cpxName", - /* 181 */ "tablelist ::= tablelist COMMA ids cpxName ids", - /* 182 */ "tmvar ::= VARIABLE", - /* 183 */ "interval_opt ::= INTERVAL LP tmvar RP", - /* 184 */ "interval_opt ::= INTERVAL LP tmvar COMMA tmvar RP", - /* 185 */ "interval_opt ::=", - /* 186 */ "session_option ::=", - /* 187 */ "session_option ::= SESSION LP ids cpxName COMMA tmvar RP", - /* 188 */ "windowstate_option ::=", - /* 189 */ "windowstate_option ::= STATE_WINDOW LP ids RP", - /* 190 */ "fill_opt ::=", - /* 191 */ "fill_opt ::= FILL LP ID COMMA tagitemlist RP", - /* 192 */ "fill_opt ::= FILL LP ID RP", - /* 193 */ "sliding_opt ::= SLIDING LP tmvar RP", - /* 194 */ "sliding_opt ::=", - /* 195 */ "orderby_opt ::=", - /* 196 */ "orderby_opt ::= ORDER BY sortlist", - /* 197 */ "sortlist ::= sortlist COMMA item sortorder", - /* 198 */ "sortlist ::= item sortorder", - /* 199 */ "item ::= ids cpxName", - /* 200 */ "sortorder ::= ASC", - /* 201 */ "sortorder ::= DESC", - /* 202 */ "sortorder ::=", - /* 203 */ "groupby_opt ::=", - /* 204 */ "groupby_opt ::= GROUP BY grouplist", - /* 205 */ "grouplist ::= grouplist COMMA item", - /* 206 */ "grouplist ::= item", - /* 207 */ "having_opt ::=", - /* 208 */ "having_opt ::= HAVING expr", - /* 209 */ "limit_opt ::=", - /* 210 */ "limit_opt ::= LIMIT signed", - /* 211 */ "limit_opt ::= LIMIT signed OFFSET signed", - /* 212 */ "limit_opt ::= LIMIT signed COMMA signed", - /* 213 */ "slimit_opt ::=", - /* 214 */ "slimit_opt ::= SLIMIT signed", - /* 215 */ "slimit_opt ::= SLIMIT signed SOFFSET signed", - /* 216 */ "slimit_opt ::= SLIMIT signed COMMA signed", - /* 217 */ "where_opt ::=", - /* 218 */ "where_opt ::= WHERE expr", - /* 219 */ "expr ::= LP expr RP", - /* 220 */ "expr ::= ID", - /* 221 */ "expr ::= ID DOT ID", - /* 222 */ "expr ::= ID DOT STAR", - /* 223 */ "expr ::= INTEGER", - /* 224 */ "expr ::= MINUS INTEGER", - /* 225 */ "expr ::= PLUS INTEGER", - /* 226 */ "expr ::= FLOAT", - /* 227 */ "expr ::= MINUS FLOAT", - /* 228 */ "expr ::= PLUS FLOAT", - /* 229 */ "expr ::= STRING", - /* 230 */ "expr ::= NOW", - /* 231 */ "expr ::= VARIABLE", - /* 232 */ "expr ::= PLUS VARIABLE", - /* 233 */ "expr ::= MINUS VARIABLE", - /* 234 */ "expr ::= BOOL", - /* 235 */ "expr ::= NULL", - /* 236 */ "expr ::= ID LP exprlist RP", - /* 237 */ "expr ::= ID LP STAR RP", - /* 238 */ "expr ::= expr IS NULL", - /* 239 */ "expr ::= expr IS NOT NULL", - /* 240 */ "expr ::= expr LT expr", - /* 241 */ "expr ::= expr GT expr", - /* 242 */ "expr ::= expr LE expr", - /* 243 */ "expr ::= expr GE expr", - /* 244 */ "expr ::= expr NE expr", - /* 245 */ "expr ::= expr EQ expr", - /* 246 */ "expr ::= expr BETWEEN expr AND expr", - /* 247 */ "expr ::= expr AND expr", - /* 248 */ "expr ::= expr OR expr", - /* 249 */ "expr ::= expr PLUS expr", - /* 250 */ "expr ::= expr MINUS expr", - /* 251 */ "expr ::= expr STAR expr", - /* 252 */ "expr ::= expr SLASH expr", - /* 253 */ "expr ::= expr REM expr", - /* 254 */ "expr ::= expr LIKE expr", - /* 255 */ "expr ::= expr IN LP exprlist RP", - /* 256 */ "exprlist ::= exprlist COMMA expritem", - /* 257 */ "exprlist ::= expritem", - /* 258 */ "expritem ::= expr", - /* 259 */ "expritem ::=", - /* 260 */ "cmd ::= RESET QUERY CACHE", - /* 261 */ "cmd ::= SYNCDB ids REPLICA", - /* 262 */ "cmd ::= ALTER TABLE ids cpxName ADD COLUMN columnlist", - /* 263 */ "cmd ::= ALTER TABLE ids cpxName DROP COLUMN ids", - /* 264 */ "cmd ::= ALTER TABLE ids cpxName MODIFY COLUMN columnlist", - /* 265 */ "cmd ::= ALTER TABLE ids cpxName ADD TAG columnlist", - /* 266 */ "cmd ::= ALTER TABLE ids cpxName DROP TAG ids", - /* 267 */ "cmd ::= ALTER TABLE ids cpxName CHANGE TAG ids ids", - /* 268 */ "cmd ::= ALTER TABLE ids cpxName SET TAG ids EQ tagitem", - /* 269 */ "cmd ::= ALTER TABLE ids cpxName MODIFY TAG columnlist", - /* 270 */ "cmd ::= ALTER STABLE ids cpxName ADD COLUMN columnlist", - /* 271 */ "cmd ::= ALTER STABLE ids cpxName DROP COLUMN ids", - /* 272 */ "cmd ::= ALTER STABLE ids cpxName MODIFY COLUMN columnlist", - /* 273 */ "cmd ::= ALTER STABLE ids cpxName ADD TAG columnlist", - /* 274 */ "cmd ::= ALTER STABLE ids cpxName DROP TAG ids", - /* 275 */ "cmd ::= ALTER STABLE ids cpxName CHANGE TAG ids ids", - /* 276 */ "cmd ::= ALTER STABLE ids cpxName SET TAG ids EQ tagitem", - /* 277 */ "cmd ::= ALTER STABLE ids cpxName MODIFY TAG columnlist", - /* 278 */ "cmd ::= KILL CONNECTION INTEGER", - /* 279 */ "cmd ::= KILL STREAM INTEGER COLON INTEGER", - /* 280 */ "cmd ::= KILL QUERY INTEGER COLON INTEGER", + /* 79 */ "intitemlist ::= intitemlist COMMA intitem", + /* 80 */ "intitemlist ::= intitem", + /* 81 */ "intitem ::= INTEGER", + /* 82 */ "keep ::= KEEP intitemlist", + /* 83 */ "cache ::= CACHE INTEGER", + /* 84 */ "replica ::= REPLICA INTEGER", + /* 85 */ "quorum ::= QUORUM INTEGER", + /* 86 */ "days ::= DAYS INTEGER", + /* 87 */ "minrows ::= MINROWS INTEGER", + /* 88 */ "maxrows ::= MAXROWS INTEGER", + /* 89 */ "blocks ::= BLOCKS INTEGER", + /* 90 */ "ctime ::= CTIME INTEGER", + /* 91 */ "wal ::= WAL INTEGER", + /* 92 */ "fsync ::= FSYNC INTEGER", + /* 93 */ "comp ::= COMP INTEGER", + /* 94 */ "prec ::= PRECISION STRING", + /* 95 */ "update ::= UPDATE INTEGER", + /* 96 */ "cachelast ::= CACHELAST INTEGER", + /* 97 */ "partitions ::= PARTITIONS INTEGER", + /* 98 */ "db_optr ::=", + /* 99 */ "db_optr ::= db_optr cache", + /* 100 */ "db_optr ::= db_optr replica", + /* 101 */ "db_optr ::= db_optr quorum", + /* 102 */ "db_optr ::= db_optr days", + /* 103 */ "db_optr ::= db_optr minrows", + /* 104 */ "db_optr ::= db_optr maxrows", + /* 105 */ "db_optr ::= db_optr blocks", + /* 106 */ "db_optr ::= db_optr ctime", + /* 107 */ "db_optr ::= db_optr wal", + /* 108 */ "db_optr ::= db_optr fsync", + /* 109 */ "db_optr ::= db_optr comp", + /* 110 */ "db_optr ::= db_optr prec", + /* 111 */ "db_optr ::= db_optr keep", + /* 112 */ "db_optr ::= db_optr update", + /* 113 */ "db_optr ::= db_optr cachelast", + /* 114 */ "topic_optr ::= db_optr", + /* 115 */ "topic_optr ::= topic_optr partitions", + /* 116 */ "alter_db_optr ::=", + /* 117 */ "alter_db_optr ::= alter_db_optr replica", + /* 118 */ "alter_db_optr ::= alter_db_optr quorum", + /* 119 */ "alter_db_optr ::= alter_db_optr keep", + /* 120 */ "alter_db_optr ::= alter_db_optr blocks", + /* 121 */ "alter_db_optr ::= alter_db_optr comp", + /* 122 */ "alter_db_optr ::= alter_db_optr wal", + /* 123 */ "alter_db_optr ::= alter_db_optr fsync", + /* 124 */ "alter_db_optr ::= alter_db_optr update", + /* 125 */ "alter_db_optr ::= alter_db_optr cachelast", + /* 126 */ "alter_topic_optr ::= alter_db_optr", + /* 127 */ "alter_topic_optr ::= alter_topic_optr partitions", + /* 128 */ "typename ::= ids", + /* 129 */ "typename ::= ids LP signed RP", + /* 130 */ "typename ::= ids UNSIGNED", + /* 131 */ "signed ::= INTEGER", + /* 132 */ "signed ::= PLUS INTEGER", + /* 133 */ "signed ::= MINUS INTEGER", + /* 134 */ "cmd ::= CREATE TABLE create_table_args", + /* 135 */ "cmd ::= CREATE TABLE create_stable_args", + /* 136 */ "cmd ::= CREATE STABLE create_stable_args", + /* 137 */ "cmd ::= CREATE TABLE create_table_list", + /* 138 */ "create_table_list ::= create_from_stable", + /* 139 */ "create_table_list ::= create_table_list create_from_stable", + /* 140 */ "create_table_args ::= ifnotexists ids cpxName LP columnlist RP", + /* 141 */ "create_stable_args ::= ifnotexists ids cpxName LP columnlist RP TAGS LP columnlist RP", + /* 142 */ "create_from_stable ::= ifnotexists ids cpxName USING ids cpxName TAGS LP tagitemlist RP", + /* 143 */ "create_from_stable ::= ifnotexists ids cpxName USING ids cpxName LP tagNamelist RP TAGS LP tagitemlist RP", + /* 144 */ "tagNamelist ::= tagNamelist COMMA ids", + /* 145 */ "tagNamelist ::= ids", + /* 146 */ "create_table_args ::= ifnotexists ids cpxName AS select", + /* 147 */ "columnlist ::= columnlist COMMA column", + /* 148 */ "columnlist ::= column", + /* 149 */ "column ::= ids typename", + /* 150 */ "tagitemlist ::= tagitemlist COMMA tagitem", + /* 151 */ "tagitemlist ::= tagitem", + /* 152 */ "tagitem ::= INTEGER", + /* 153 */ "tagitem ::= FLOAT", + /* 154 */ "tagitem ::= STRING", + /* 155 */ "tagitem ::= BOOL", + /* 156 */ "tagitem ::= NULL", + /* 157 */ "tagitem ::= MINUS INTEGER", + /* 158 */ "tagitem ::= MINUS FLOAT", + /* 159 */ "tagitem ::= PLUS INTEGER", + /* 160 */ "tagitem ::= PLUS FLOAT", + /* 161 */ "select ::= SELECT selcollist from where_opt interval_opt session_option windowstate_option fill_opt sliding_opt groupby_opt orderby_opt having_opt slimit_opt limit_opt", + /* 162 */ "select ::= LP select RP", + /* 163 */ "union ::= select", + /* 164 */ "union ::= union UNION ALL select", + /* 165 */ "cmd ::= union", + /* 166 */ "select ::= SELECT selcollist", + /* 167 */ "sclp ::= selcollist COMMA", + /* 168 */ "sclp ::=", + /* 169 */ "selcollist ::= sclp distinct expr as", + /* 170 */ "selcollist ::= sclp STAR", + /* 171 */ "as ::= AS ids", + /* 172 */ "as ::= ids", + /* 173 */ "as ::=", + /* 174 */ "distinct ::= DISTINCT", + /* 175 */ "distinct ::=", + /* 176 */ "from ::= FROM tablelist", + /* 177 */ "from ::= FROM sub", + /* 178 */ "sub ::= LP union RP", + /* 179 */ "sub ::= LP union RP ids", + /* 180 */ "sub ::= sub COMMA LP union RP ids", + /* 181 */ "tablelist ::= ids cpxName", + /* 182 */ "tablelist ::= ids cpxName ids", + /* 183 */ "tablelist ::= tablelist COMMA ids cpxName", + /* 184 */ "tablelist ::= tablelist COMMA ids cpxName ids", + /* 185 */ "tmvar ::= VARIABLE", + /* 186 */ "interval_opt ::= INTERVAL LP tmvar RP", + /* 187 */ "interval_opt ::= INTERVAL LP tmvar COMMA tmvar RP", + /* 188 */ "interval_opt ::=", + /* 189 */ "session_option ::=", + /* 190 */ "session_option ::= SESSION LP ids cpxName COMMA tmvar RP", + /* 191 */ "windowstate_option ::=", + /* 192 */ "windowstate_option ::= STATE_WINDOW LP ids RP", + /* 193 */ "fill_opt ::=", + /* 194 */ "fill_opt ::= FILL LP ID COMMA tagitemlist RP", + /* 195 */ "fill_opt ::= FILL LP ID RP", + /* 196 */ "sliding_opt ::= SLIDING LP tmvar RP", + /* 197 */ "sliding_opt ::=", + /* 198 */ "orderby_opt ::=", + /* 199 */ "orderby_opt ::= ORDER BY sortlist", + /* 200 */ "sortlist ::= sortlist COMMA item sortorder", + /* 201 */ "sortlist ::= item sortorder", + /* 202 */ "item ::= ids cpxName", + /* 203 */ "sortorder ::= ASC", + /* 204 */ "sortorder ::= DESC", + /* 205 */ "sortorder ::=", + /* 206 */ "groupby_opt ::=", + /* 207 */ "groupby_opt ::= GROUP BY grouplist", + /* 208 */ "grouplist ::= grouplist COMMA item", + /* 209 */ "grouplist ::= item", + /* 210 */ "having_opt ::=", + /* 211 */ "having_opt ::= HAVING expr", + /* 212 */ "limit_opt ::=", + /* 213 */ "limit_opt ::= LIMIT signed", + /* 214 */ "limit_opt ::= LIMIT signed OFFSET signed", + /* 215 */ "limit_opt ::= LIMIT signed COMMA signed", + /* 216 */ "slimit_opt ::=", + /* 217 */ "slimit_opt ::= SLIMIT signed", + /* 218 */ "slimit_opt ::= SLIMIT signed SOFFSET signed", + /* 219 */ "slimit_opt ::= SLIMIT signed COMMA signed", + /* 220 */ "where_opt ::=", + /* 221 */ "where_opt ::= WHERE expr", + /* 222 */ "expr ::= LP expr RP", + /* 223 */ "expr ::= ID", + /* 224 */ "expr ::= ID DOT ID", + /* 225 */ "expr ::= ID DOT STAR", + /* 226 */ "expr ::= INTEGER", + /* 227 */ "expr ::= MINUS INTEGER", + /* 228 */ "expr ::= PLUS INTEGER", + /* 229 */ "expr ::= FLOAT", + /* 230 */ "expr ::= MINUS FLOAT", + /* 231 */ "expr ::= PLUS FLOAT", + /* 232 */ "expr ::= STRING", + /* 233 */ "expr ::= NOW", + /* 234 */ "expr ::= VARIABLE", + /* 235 */ "expr ::= PLUS VARIABLE", + /* 236 */ "expr ::= MINUS VARIABLE", + /* 237 */ "expr ::= BOOL", + /* 238 */ "expr ::= NULL", + /* 239 */ "expr ::= ID LP exprlist RP", + /* 240 */ "expr ::= ID LP STAR RP", + /* 241 */ "expr ::= expr IS NULL", + /* 242 */ "expr ::= expr IS NOT NULL", + /* 243 */ "expr ::= expr LT expr", + /* 244 */ "expr ::= expr GT expr", + /* 245 */ "expr ::= expr LE expr", + /* 246 */ "expr ::= expr GE expr", + /* 247 */ "expr ::= expr NE expr", + /* 248 */ "expr ::= expr EQ expr", + /* 249 */ "expr ::= expr BETWEEN expr AND expr", + /* 250 */ "expr ::= expr AND expr", + /* 251 */ "expr ::= expr OR expr", + /* 252 */ "expr ::= expr PLUS expr", + /* 253 */ "expr ::= expr MINUS expr", + /* 254 */ "expr ::= expr STAR expr", + /* 255 */ "expr ::= expr SLASH expr", + /* 256 */ "expr ::= expr REM expr", + /* 257 */ "expr ::= expr LIKE expr", + /* 258 */ "expr ::= expr IN LP exprlist RP", + /* 259 */ "exprlist ::= exprlist COMMA expritem", + /* 260 */ "exprlist ::= expritem", + /* 261 */ "expritem ::= expr", + /* 262 */ "expritem ::=", + /* 263 */ "cmd ::= RESET QUERY CACHE", + /* 264 */ "cmd ::= SYNCDB ids REPLICA", + /* 265 */ "cmd ::= ALTER TABLE ids cpxName ADD COLUMN columnlist", + /* 266 */ "cmd ::= ALTER TABLE ids cpxName DROP COLUMN ids", + /* 267 */ "cmd ::= ALTER TABLE ids cpxName MODIFY COLUMN columnlist", + /* 268 */ "cmd ::= ALTER TABLE ids cpxName ADD TAG columnlist", + /* 269 */ "cmd ::= ALTER TABLE ids cpxName DROP TAG ids", + /* 270 */ "cmd ::= ALTER TABLE ids cpxName CHANGE TAG ids ids", + /* 271 */ "cmd ::= ALTER TABLE ids cpxName SET TAG ids EQ tagitem", + /* 272 */ "cmd ::= ALTER TABLE ids cpxName MODIFY TAG columnlist", + /* 273 */ "cmd ::= ALTER STABLE ids cpxName ADD COLUMN columnlist", + /* 274 */ "cmd ::= ALTER STABLE ids cpxName DROP COLUMN ids", + /* 275 */ "cmd ::= ALTER STABLE ids cpxName MODIFY COLUMN columnlist", + /* 276 */ "cmd ::= ALTER STABLE ids cpxName ADD TAG columnlist", + /* 277 */ "cmd ::= ALTER STABLE ids cpxName DROP TAG ids", + /* 278 */ "cmd ::= ALTER STABLE ids cpxName CHANGE TAG ids ids", + /* 279 */ "cmd ::= ALTER STABLE ids cpxName SET TAG ids EQ tagitem", + /* 280 */ "cmd ::= ALTER STABLE ids cpxName MODIFY TAG columnlist", + /* 281 */ "cmd ::= KILL CONNECTION INTEGER", + /* 282 */ "cmd ::= KILL STREAM INTEGER COLON INTEGER", + /* 283 */ "cmd ::= KILL QUERY INTEGER COLON INTEGER", }; #endif /* NDEBUG */ @@ -1181,58 +1187,59 @@ static void yy_destructor( ** inside the C code. */ case 200: /* exprlist */ - case 241: /* selcollist */ - case 255: /* sclp */ + case 243: /* selcollist */ + case 257: /* sclp */ { -tSqlExprListDestroy((yypminor->yy325)); +tSqlExprListDestroy((yypminor->yy441)); } break; - case 213: /* keep */ - case 214: /* tagitemlist */ - case 236: /* columnlist */ - case 237: /* tagNamelist */ - case 247: /* fill_opt */ - case 249: /* groupby_opt */ - case 250: /* orderby_opt */ - case 262: /* sortlist */ - case 266: /* grouplist */ -{ -taosArrayDestroy((yypminor->yy325)); + case 213: /* intitemlist */ + case 215: /* keep */ + case 237: /* columnlist */ + case 238: /* tagitemlist */ + case 239: /* tagNamelist */ + case 249: /* fill_opt */ + case 251: /* groupby_opt */ + case 252: /* orderby_opt */ + case 264: /* sortlist */ + case 268: /* grouplist */ +{ +taosArrayDestroy((yypminor->yy441)); } break; - case 234: /* create_table_list */ + case 235: /* create_table_list */ { -destroyCreateTableSql((yypminor->yy422)); +destroyCreateTableSql((yypminor->yy182)); } break; - case 238: /* select */ + case 240: /* select */ { -destroySqlNode((yypminor->yy536)); +destroySqlNode((yypminor->yy236)); } break; - case 242: /* from */ - case 259: /* tablelist */ - case 260: /* sub */ + case 244: /* from */ + case 261: /* tablelist */ + case 262: /* sub */ { -destroyRelationInfo((yypminor->yy52)); +destroyRelationInfo((yypminor->yy244)); } break; - case 243: /* where_opt */ - case 251: /* having_opt */ - case 257: /* expr */ - case 267: /* expritem */ + case 245: /* where_opt */ + case 253: /* having_opt */ + case 259: /* expr */ + case 269: /* expritem */ { -tSqlExprDestroy((yypminor->yy162)); +tSqlExprDestroy((yypminor->yy166)); } break; - case 254: /* union */ + case 256: /* union */ { -destroyAllSqlNode((yypminor->yy325)); +destroyAllSqlNode((yypminor->yy441)); } break; - case 263: /* sortitem */ + case 265: /* sortitem */ { -tVariantDestroy(&(yypminor->yy442)); +tVariantDestroy(&(yypminor->yy506)); } break; default: break; /* If no destructor action specified: do nothing */ @@ -1549,7 +1556,9 @@ static const struct { { 212, 0 }, { 212, 2 }, { 199, 9 }, - { 213, 2 }, + { 213, 3 }, + { 213, 1 }, + { 214, 1 }, { 215, 2 }, { 216, 2 }, { 217, 2 }, @@ -1565,6 +1574,7 @@ static const struct { { 227, 2 }, { 228, 2 }, { 229, 2 }, + { 230, 2 }, { 202, 0 }, { 202, 2 }, { 202, 2 }, @@ -1595,141 +1605,141 @@ static const struct { { 197, 2 }, { 198, 1 }, { 198, 2 }, - { 230, 1 }, - { 230, 4 }, - { 230, 2 }, { 231, 1 }, + { 231, 4 }, { 231, 2 }, - { 231, 2 }, + { 232, 1 }, + { 232, 2 }, + { 232, 2 }, { 192, 3 }, { 192, 3 }, { 192, 3 }, { 192, 3 }, - { 234, 1 }, - { 234, 2 }, - { 232, 6 }, - { 233, 10 }, - { 235, 10 }, - { 235, 13 }, + { 235, 1 }, + { 235, 2 }, + { 233, 6 }, + { 234, 10 }, + { 236, 10 }, + { 236, 13 }, + { 239, 3 }, + { 239, 1 }, + { 233, 5 }, { 237, 3 }, { 237, 1 }, - { 232, 5 }, - { 236, 3 }, - { 236, 1 }, - { 239, 2 }, - { 214, 3 }, - { 214, 1 }, - { 240, 1 }, - { 240, 1 }, - { 240, 1 }, - { 240, 1 }, - { 240, 1 }, - { 240, 2 }, - { 240, 2 }, - { 240, 2 }, - { 240, 2 }, - { 238, 14 }, + { 241, 2 }, { 238, 3 }, - { 254, 1 }, - { 254, 4 }, + { 238, 1 }, + { 242, 1 }, + { 242, 1 }, + { 242, 1 }, + { 242, 1 }, + { 242, 1 }, + { 242, 2 }, + { 242, 2 }, + { 242, 2 }, + { 242, 2 }, + { 240, 14 }, + { 240, 3 }, + { 256, 1 }, + { 256, 4 }, { 192, 1 }, - { 238, 2 }, - { 255, 2 }, - { 255, 0 }, - { 241, 4 }, - { 241, 2 }, - { 258, 2 }, + { 240, 2 }, + { 257, 2 }, + { 257, 0 }, + { 243, 4 }, + { 243, 2 }, + { 260, 2 }, + { 260, 1 }, + { 260, 0 }, { 258, 1 }, { 258, 0 }, - { 256, 1 }, - { 256, 0 }, - { 242, 2 }, - { 242, 2 }, - { 260, 3 }, - { 260, 4 }, - { 260, 6 }, - { 259, 2 }, - { 259, 3 }, - { 259, 4 }, - { 259, 5 }, - { 261, 1 }, - { 244, 4 }, - { 244, 6 }, - { 244, 0 }, - { 245, 0 }, - { 245, 7 }, - { 246, 0 }, + { 244, 2 }, + { 244, 2 }, + { 262, 3 }, + { 262, 4 }, + { 262, 6 }, + { 261, 2 }, + { 261, 3 }, + { 261, 4 }, + { 261, 5 }, + { 263, 1 }, { 246, 4 }, + { 246, 6 }, + { 246, 0 }, { 247, 0 }, - { 247, 6 }, - { 247, 4 }, - { 248, 4 }, + { 247, 7 }, { 248, 0 }, + { 248, 4 }, + { 249, 0 }, + { 249, 6 }, + { 249, 4 }, + { 250, 4 }, { 250, 0 }, - { 250, 3 }, - { 262, 4 }, - { 262, 2 }, + { 252, 0 }, + { 252, 3 }, + { 264, 4 }, { 264, 2 }, - { 265, 1 }, - { 265, 1 }, - { 265, 0 }, - { 249, 0 }, - { 249, 3 }, - { 266, 3 }, - { 266, 1 }, + { 266, 2 }, + { 267, 1 }, + { 267, 1 }, + { 267, 0 }, { 251, 0 }, - { 251, 2 }, + { 251, 3 }, + { 268, 3 }, + { 268, 1 }, { 253, 0 }, { 253, 2 }, - { 253, 4 }, - { 253, 4 }, - { 252, 0 }, - { 252, 2 }, - { 252, 4 }, - { 252, 4 }, - { 243, 0 }, - { 243, 2 }, - { 257, 3 }, - { 257, 1 }, - { 257, 3 }, - { 257, 3 }, - { 257, 1 }, - { 257, 2 }, - { 257, 2 }, - { 257, 1 }, - { 257, 2 }, - { 257, 2 }, - { 257, 1 }, - { 257, 1 }, - { 257, 1 }, - { 257, 2 }, - { 257, 2 }, - { 257, 1 }, - { 257, 1 }, - { 257, 4 }, - { 257, 4 }, - { 257, 3 }, - { 257, 4 }, - { 257, 3 }, - { 257, 3 }, - { 257, 3 }, - { 257, 3 }, - { 257, 3 }, - { 257, 3 }, - { 257, 5 }, - { 257, 3 }, - { 257, 3 }, - { 257, 3 }, - { 257, 3 }, - { 257, 3 }, - { 257, 3 }, - { 257, 3 }, - { 257, 3 }, - { 257, 5 }, + { 255, 0 }, + { 255, 2 }, + { 255, 4 }, + { 255, 4 }, + { 254, 0 }, + { 254, 2 }, + { 254, 4 }, + { 254, 4 }, + { 245, 0 }, + { 245, 2 }, + { 259, 3 }, + { 259, 1 }, + { 259, 3 }, + { 259, 3 }, + { 259, 1 }, + { 259, 2 }, + { 259, 2 }, + { 259, 1 }, + { 259, 2 }, + { 259, 2 }, + { 259, 1 }, + { 259, 1 }, + { 259, 1 }, + { 259, 2 }, + { 259, 2 }, + { 259, 1 }, + { 259, 1 }, + { 259, 4 }, + { 259, 4 }, + { 259, 3 }, + { 259, 4 }, + { 259, 3 }, + { 259, 3 }, + { 259, 3 }, + { 259, 3 }, + { 259, 3 }, + { 259, 3 }, + { 259, 5 }, + { 259, 3 }, + { 259, 3 }, + { 259, 3 }, + { 259, 3 }, + { 259, 3 }, + { 259, 3 }, + { 259, 3 }, + { 259, 3 }, + { 259, 5 }, { 200, 3 }, { 200, 1 }, - { 267, 1 }, - { 267, 0 }, + { 269, 1 }, + { 269, 0 }, { 192, 3 }, { 192, 3 }, { 192, 7 }, @@ -1974,16 +1984,16 @@ static void yy_reduce( break; case 44: /* cmd ::= ALTER DATABASE ids alter_db_optr */ case 45: /* cmd ::= ALTER TOPIC ids alter_topic_optr */ yytestcase(yyruleno==45); -{ SStrToken t = {0}; setCreateDbInfo(pInfo, TSDB_SQL_ALTER_DB, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy22, &t);} +{ SStrToken t = {0}; setCreateDbInfo(pInfo, TSDB_SQL_ALTER_DB, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy382, &t);} break; case 46: /* cmd ::= ALTER ACCOUNT ids acct_optr */ -{ setCreateAcctSql(pInfo, TSDB_SQL_ALTER_ACCT, &yymsp[-1].minor.yy0, NULL, &yymsp[0].minor.yy83);} +{ setCreateAcctSql(pInfo, TSDB_SQL_ALTER_ACCT, &yymsp[-1].minor.yy0, NULL, &yymsp[0].minor.yy151);} break; case 47: /* cmd ::= ALTER ACCOUNT ids PASS ids acct_optr */ -{ setCreateAcctSql(pInfo, TSDB_SQL_ALTER_ACCT, &yymsp[-3].minor.yy0, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy83);} +{ setCreateAcctSql(pInfo, TSDB_SQL_ALTER_ACCT, &yymsp[-3].minor.yy0, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy151);} break; case 48: /* cmd ::= COMPACT VNODES IN LP exprlist RP */ -{ setCompactVnodeSql(pInfo, TSDB_SQL_COMPACT_VNODE, yymsp[-1].minor.yy325);} +{ setCompactVnodeSql(pInfo, TSDB_SQL_COMPACT_VNODE, yymsp[-1].minor.yy441);} break; case 49: /* ids ::= ID */ case 50: /* ids ::= STRING */ yytestcase(yyruleno==50); @@ -1995,18 +2005,18 @@ static void yy_reduce( break; case 52: /* ifexists ::= */ case 54: /* ifnotexists ::= */ yytestcase(yyruleno==54); - case 172: /* distinct ::= */ yytestcase(yyruleno==172); + case 175: /* distinct ::= */ yytestcase(yyruleno==175); { yygotominor.yy0.n = 0;} break; case 55: /* cmd ::= CREATE DNODE ids */ { setDCLSqlElems(pInfo, TSDB_SQL_CREATE_DNODE, 1, &yymsp[0].minor.yy0);} break; case 56: /* cmd ::= CREATE ACCOUNT ids PASS ids acct_optr */ -{ setCreateAcctSql(pInfo, TSDB_SQL_CREATE_ACCT, &yymsp[-3].minor.yy0, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy83);} +{ setCreateAcctSql(pInfo, TSDB_SQL_CREATE_ACCT, &yymsp[-3].minor.yy0, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy151);} break; case 57: /* cmd ::= CREATE DATABASE ifnotexists ids db_optr */ case 58: /* cmd ::= CREATE TOPIC ifnotexists ids topic_optr */ yytestcase(yyruleno==58); -{ setCreateDbInfo(pInfo, TSDB_SQL_CREATE_DB, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy22, &yymsp[-2].minor.yy0);} +{ setCreateDbInfo(pInfo, TSDB_SQL_CREATE_DB, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy382, &yymsp[-2].minor.yy0);} break; case 59: /* cmd ::= CREATE USER ids PASS ids */ { setCreateUserSql(pInfo, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0);} @@ -2035,583 +2045,584 @@ static void yy_reduce( break; case 78: /* acct_optr ::= pps tseries storage streams qtime dbs users conns state */ { - yygotominor.yy83.maxUsers = (yymsp[-2].minor.yy0.n>0)?atoi(yymsp[-2].minor.yy0.z):-1; - yygotominor.yy83.maxDbs = (yymsp[-3].minor.yy0.n>0)?atoi(yymsp[-3].minor.yy0.z):-1; - yygotominor.yy83.maxTimeSeries = (yymsp[-7].minor.yy0.n>0)?atoi(yymsp[-7].minor.yy0.z):-1; - yygotominor.yy83.maxStreams = (yymsp[-5].minor.yy0.n>0)?atoi(yymsp[-5].minor.yy0.z):-1; - yygotominor.yy83.maxPointsPerSecond = (yymsp[-8].minor.yy0.n>0)?atoi(yymsp[-8].minor.yy0.z):-1; - yygotominor.yy83.maxStorage = (yymsp[-6].minor.yy0.n>0)?strtoll(yymsp[-6].minor.yy0.z, NULL, 10):-1; - yygotominor.yy83.maxQueryTime = (yymsp[-4].minor.yy0.n>0)?strtoll(yymsp[-4].minor.yy0.z, NULL, 10):-1; - yygotominor.yy83.maxConnections = (yymsp[-1].minor.yy0.n>0)?atoi(yymsp[-1].minor.yy0.z):-1; - yygotominor.yy83.stat = yymsp[0].minor.yy0; -} - break; - case 79: /* keep ::= KEEP tagitemlist */ -{ yygotominor.yy325 = yymsp[0].minor.yy325; } - break; - case 80: /* cache ::= CACHE INTEGER */ - case 81: /* replica ::= REPLICA INTEGER */ yytestcase(yyruleno==81); - case 82: /* quorum ::= QUORUM INTEGER */ yytestcase(yyruleno==82); - case 83: /* days ::= DAYS INTEGER */ yytestcase(yyruleno==83); - case 84: /* minrows ::= MINROWS INTEGER */ yytestcase(yyruleno==84); - case 85: /* maxrows ::= MAXROWS INTEGER */ yytestcase(yyruleno==85); - case 86: /* blocks ::= BLOCKS INTEGER */ yytestcase(yyruleno==86); - case 87: /* ctime ::= CTIME INTEGER */ yytestcase(yyruleno==87); - case 88: /* wal ::= WAL INTEGER */ yytestcase(yyruleno==88); - case 89: /* fsync ::= FSYNC INTEGER */ yytestcase(yyruleno==89); - case 90: /* comp ::= COMP INTEGER */ yytestcase(yyruleno==90); - case 91: /* prec ::= PRECISION STRING */ yytestcase(yyruleno==91); - case 92: /* update ::= UPDATE INTEGER */ yytestcase(yyruleno==92); - case 93: /* cachelast ::= CACHELAST INTEGER */ yytestcase(yyruleno==93); - case 94: /* partitions ::= PARTITIONS INTEGER */ yytestcase(yyruleno==94); + yygotominor.yy151.maxUsers = (yymsp[-2].minor.yy0.n>0)?atoi(yymsp[-2].minor.yy0.z):-1; + yygotominor.yy151.maxDbs = (yymsp[-3].minor.yy0.n>0)?atoi(yymsp[-3].minor.yy0.z):-1; + yygotominor.yy151.maxTimeSeries = (yymsp[-7].minor.yy0.n>0)?atoi(yymsp[-7].minor.yy0.z):-1; + yygotominor.yy151.maxStreams = (yymsp[-5].minor.yy0.n>0)?atoi(yymsp[-5].minor.yy0.z):-1; + yygotominor.yy151.maxPointsPerSecond = (yymsp[-8].minor.yy0.n>0)?atoi(yymsp[-8].minor.yy0.z):-1; + yygotominor.yy151.maxStorage = (yymsp[-6].minor.yy0.n>0)?strtoll(yymsp[-6].minor.yy0.z, NULL, 10):-1; + yygotominor.yy151.maxQueryTime = (yymsp[-4].minor.yy0.n>0)?strtoll(yymsp[-4].minor.yy0.z, NULL, 10):-1; + yygotominor.yy151.maxConnections = (yymsp[-1].minor.yy0.n>0)?atoi(yymsp[-1].minor.yy0.z):-1; + yygotominor.yy151.stat = yymsp[0].minor.yy0; +} + break; + case 79: /* intitemlist ::= intitemlist COMMA intitem */ + case 150: /* tagitemlist ::= tagitemlist COMMA tagitem */ yytestcase(yyruleno==150); +{ yygotominor.yy441 = tVariantListAppend(yymsp[-2].minor.yy441, &yymsp[0].minor.yy506, -1); } + break; + case 80: /* intitemlist ::= intitem */ + case 151: /* tagitemlist ::= tagitem */ yytestcase(yyruleno==151); +{ yygotominor.yy441 = tVariantListAppend(NULL, &yymsp[0].minor.yy506, -1); } + break; + case 81: /* intitem ::= INTEGER */ + case 152: /* tagitem ::= INTEGER */ yytestcase(yyruleno==152); + case 153: /* tagitem ::= FLOAT */ yytestcase(yyruleno==153); + case 154: /* tagitem ::= STRING */ yytestcase(yyruleno==154); + case 155: /* tagitem ::= BOOL */ yytestcase(yyruleno==155); +{ toTSDBType(yymsp[0].minor.yy0.type); tVariantCreate(&yygotominor.yy506, &yymsp[0].minor.yy0); } + break; + case 82: /* keep ::= KEEP intitemlist */ +{ yygotominor.yy441 = yymsp[0].minor.yy441; } + break; + case 83: /* cache ::= CACHE INTEGER */ + case 84: /* replica ::= REPLICA INTEGER */ yytestcase(yyruleno==84); + case 85: /* quorum ::= QUORUM INTEGER */ yytestcase(yyruleno==85); + case 86: /* days ::= DAYS INTEGER */ yytestcase(yyruleno==86); + case 87: /* minrows ::= MINROWS INTEGER */ yytestcase(yyruleno==87); + case 88: /* maxrows ::= MAXROWS INTEGER */ yytestcase(yyruleno==88); + case 89: /* blocks ::= BLOCKS INTEGER */ yytestcase(yyruleno==89); + case 90: /* ctime ::= CTIME INTEGER */ yytestcase(yyruleno==90); + case 91: /* wal ::= WAL INTEGER */ yytestcase(yyruleno==91); + case 92: /* fsync ::= FSYNC INTEGER */ yytestcase(yyruleno==92); + case 93: /* comp ::= COMP INTEGER */ yytestcase(yyruleno==93); + case 94: /* prec ::= PRECISION STRING */ yytestcase(yyruleno==94); + case 95: /* update ::= UPDATE INTEGER */ yytestcase(yyruleno==95); + case 96: /* cachelast ::= CACHELAST INTEGER */ yytestcase(yyruleno==96); + case 97: /* partitions ::= PARTITIONS INTEGER */ yytestcase(yyruleno==97); { yygotominor.yy0 = yymsp[0].minor.yy0; } break; - case 95: /* db_optr ::= */ -{setDefaultCreateDbOption(&yygotominor.yy22); yygotominor.yy22.dbType = TSDB_DB_TYPE_DEFAULT;} + case 98: /* db_optr ::= */ +{setDefaultCreateDbOption(&yygotominor.yy382); yygotominor.yy382.dbType = TSDB_DB_TYPE_DEFAULT;} break; - case 96: /* db_optr ::= db_optr cache */ -{ yygotominor.yy22 = yymsp[-1].minor.yy22; yygotominor.yy22.cacheBlockSize = strtol(yymsp[0].minor.yy0.z, NULL, 10); } + case 99: /* db_optr ::= db_optr cache */ +{ yygotominor.yy382 = yymsp[-1].minor.yy382; yygotominor.yy382.cacheBlockSize = strtol(yymsp[0].minor.yy0.z, NULL, 10); } break; - case 97: /* db_optr ::= db_optr replica */ - case 114: /* alter_db_optr ::= alter_db_optr replica */ yytestcase(yyruleno==114); -{ yygotominor.yy22 = yymsp[-1].minor.yy22; yygotominor.yy22.replica = strtol(yymsp[0].minor.yy0.z, NULL, 10); } + case 100: /* db_optr ::= db_optr replica */ + case 117: /* alter_db_optr ::= alter_db_optr replica */ yytestcase(yyruleno==117); +{ yygotominor.yy382 = yymsp[-1].minor.yy382; yygotominor.yy382.replica = strtol(yymsp[0].minor.yy0.z, NULL, 10); } break; - case 98: /* db_optr ::= db_optr quorum */ - case 115: /* alter_db_optr ::= alter_db_optr quorum */ yytestcase(yyruleno==115); -{ yygotominor.yy22 = yymsp[-1].minor.yy22; yygotominor.yy22.quorum = strtol(yymsp[0].minor.yy0.z, NULL, 10); } + case 101: /* db_optr ::= db_optr quorum */ + case 118: /* alter_db_optr ::= alter_db_optr quorum */ yytestcase(yyruleno==118); +{ yygotominor.yy382 = yymsp[-1].minor.yy382; yygotominor.yy382.quorum = strtol(yymsp[0].minor.yy0.z, NULL, 10); } break; - case 99: /* db_optr ::= db_optr days */ -{ yygotominor.yy22 = yymsp[-1].minor.yy22; yygotominor.yy22.daysPerFile = strtol(yymsp[0].minor.yy0.z, NULL, 10); } + case 102: /* db_optr ::= db_optr days */ +{ yygotominor.yy382 = yymsp[-1].minor.yy382; yygotominor.yy382.daysPerFile = strtol(yymsp[0].minor.yy0.z, NULL, 10); } break; - case 100: /* db_optr ::= db_optr minrows */ -{ yygotominor.yy22 = yymsp[-1].minor.yy22; yygotominor.yy22.minRowsPerBlock = strtod(yymsp[0].minor.yy0.z, NULL); } + case 103: /* db_optr ::= db_optr minrows */ +{ yygotominor.yy382 = yymsp[-1].minor.yy382; yygotominor.yy382.minRowsPerBlock = strtod(yymsp[0].minor.yy0.z, NULL); } break; - case 101: /* db_optr ::= db_optr maxrows */ -{ yygotominor.yy22 = yymsp[-1].minor.yy22; yygotominor.yy22.maxRowsPerBlock = strtod(yymsp[0].minor.yy0.z, NULL); } + case 104: /* db_optr ::= db_optr maxrows */ +{ yygotominor.yy382 = yymsp[-1].minor.yy382; yygotominor.yy382.maxRowsPerBlock = strtod(yymsp[0].minor.yy0.z, NULL); } break; - case 102: /* db_optr ::= db_optr blocks */ - case 117: /* alter_db_optr ::= alter_db_optr blocks */ yytestcase(yyruleno==117); -{ yygotominor.yy22 = yymsp[-1].minor.yy22; yygotominor.yy22.numOfBlocks = strtol(yymsp[0].minor.yy0.z, NULL, 10); } + case 105: /* db_optr ::= db_optr blocks */ + case 120: /* alter_db_optr ::= alter_db_optr blocks */ yytestcase(yyruleno==120); +{ yygotominor.yy382 = yymsp[-1].minor.yy382; yygotominor.yy382.numOfBlocks = strtol(yymsp[0].minor.yy0.z, NULL, 10); } break; - case 103: /* db_optr ::= db_optr ctime */ -{ yygotominor.yy22 = yymsp[-1].minor.yy22; yygotominor.yy22.commitTime = strtol(yymsp[0].minor.yy0.z, NULL, 10); } + case 106: /* db_optr ::= db_optr ctime */ +{ yygotominor.yy382 = yymsp[-1].minor.yy382; yygotominor.yy382.commitTime = strtol(yymsp[0].minor.yy0.z, NULL, 10); } break; - case 104: /* db_optr ::= db_optr wal */ - case 119: /* alter_db_optr ::= alter_db_optr wal */ yytestcase(yyruleno==119); -{ yygotominor.yy22 = yymsp[-1].minor.yy22; yygotominor.yy22.walLevel = strtol(yymsp[0].minor.yy0.z, NULL, 10); } + case 107: /* db_optr ::= db_optr wal */ + case 122: /* alter_db_optr ::= alter_db_optr wal */ yytestcase(yyruleno==122); +{ yygotominor.yy382 = yymsp[-1].minor.yy382; yygotominor.yy382.walLevel = strtol(yymsp[0].minor.yy0.z, NULL, 10); } break; - case 105: /* db_optr ::= db_optr fsync */ - case 120: /* alter_db_optr ::= alter_db_optr fsync */ yytestcase(yyruleno==120); -{ yygotominor.yy22 = yymsp[-1].minor.yy22; yygotominor.yy22.fsyncPeriod = strtol(yymsp[0].minor.yy0.z, NULL, 10); } + case 108: /* db_optr ::= db_optr fsync */ + case 123: /* alter_db_optr ::= alter_db_optr fsync */ yytestcase(yyruleno==123); +{ yygotominor.yy382 = yymsp[-1].minor.yy382; yygotominor.yy382.fsyncPeriod = strtol(yymsp[0].minor.yy0.z, NULL, 10); } break; - case 106: /* db_optr ::= db_optr comp */ - case 118: /* alter_db_optr ::= alter_db_optr comp */ yytestcase(yyruleno==118); -{ yygotominor.yy22 = yymsp[-1].minor.yy22; yygotominor.yy22.compressionLevel = strtol(yymsp[0].minor.yy0.z, NULL, 10); } + case 109: /* db_optr ::= db_optr comp */ + case 121: /* alter_db_optr ::= alter_db_optr comp */ yytestcase(yyruleno==121); +{ yygotominor.yy382 = yymsp[-1].minor.yy382; yygotominor.yy382.compressionLevel = strtol(yymsp[0].minor.yy0.z, NULL, 10); } break; - case 107: /* db_optr ::= db_optr prec */ -{ yygotominor.yy22 = yymsp[-1].minor.yy22; yygotominor.yy22.precision = yymsp[0].minor.yy0; } + case 110: /* db_optr ::= db_optr prec */ +{ yygotominor.yy382 = yymsp[-1].minor.yy382; yygotominor.yy382.precision = yymsp[0].minor.yy0; } break; - case 108: /* db_optr ::= db_optr keep */ - case 116: /* alter_db_optr ::= alter_db_optr keep */ yytestcase(yyruleno==116); -{ yygotominor.yy22 = yymsp[-1].minor.yy22; yygotominor.yy22.keep = yymsp[0].minor.yy325; } + case 111: /* db_optr ::= db_optr keep */ + case 119: /* alter_db_optr ::= alter_db_optr keep */ yytestcase(yyruleno==119); +{ yygotominor.yy382 = yymsp[-1].minor.yy382; yygotominor.yy382.keep = yymsp[0].minor.yy441; } break; - case 109: /* db_optr ::= db_optr update */ - case 121: /* alter_db_optr ::= alter_db_optr update */ yytestcase(yyruleno==121); -{ yygotominor.yy22 = yymsp[-1].minor.yy22; yygotominor.yy22.update = strtol(yymsp[0].minor.yy0.z, NULL, 10); } + case 112: /* db_optr ::= db_optr update */ + case 124: /* alter_db_optr ::= alter_db_optr update */ yytestcase(yyruleno==124); +{ yygotominor.yy382 = yymsp[-1].minor.yy382; yygotominor.yy382.update = strtol(yymsp[0].minor.yy0.z, NULL, 10); } break; - case 110: /* db_optr ::= db_optr cachelast */ - case 122: /* alter_db_optr ::= alter_db_optr cachelast */ yytestcase(yyruleno==122); -{ yygotominor.yy22 = yymsp[-1].minor.yy22; yygotominor.yy22.cachelast = strtol(yymsp[0].minor.yy0.z, NULL, 10); } + case 113: /* db_optr ::= db_optr cachelast */ + case 125: /* alter_db_optr ::= alter_db_optr cachelast */ yytestcase(yyruleno==125); +{ yygotominor.yy382 = yymsp[-1].minor.yy382; yygotominor.yy382.cachelast = strtol(yymsp[0].minor.yy0.z, NULL, 10); } break; - case 111: /* topic_optr ::= db_optr */ - case 123: /* alter_topic_optr ::= alter_db_optr */ yytestcase(yyruleno==123); -{ yygotominor.yy22 = yymsp[0].minor.yy22; yygotominor.yy22.dbType = TSDB_DB_TYPE_TOPIC; } + case 114: /* topic_optr ::= db_optr */ + case 126: /* alter_topic_optr ::= alter_db_optr */ yytestcase(yyruleno==126); +{ yygotominor.yy382 = yymsp[0].minor.yy382; yygotominor.yy382.dbType = TSDB_DB_TYPE_TOPIC; } break; - case 112: /* topic_optr ::= topic_optr partitions */ - case 124: /* alter_topic_optr ::= alter_topic_optr partitions */ yytestcase(yyruleno==124); -{ yygotominor.yy22 = yymsp[-1].minor.yy22; yygotominor.yy22.partitions = strtol(yymsp[0].minor.yy0.z, NULL, 10); } + case 115: /* topic_optr ::= topic_optr partitions */ + case 127: /* alter_topic_optr ::= alter_topic_optr partitions */ yytestcase(yyruleno==127); +{ yygotominor.yy382 = yymsp[-1].minor.yy382; yygotominor.yy382.partitions = strtol(yymsp[0].minor.yy0.z, NULL, 10); } break; - case 113: /* alter_db_optr ::= */ -{ setDefaultCreateDbOption(&yygotominor.yy22); yygotominor.yy22.dbType = TSDB_DB_TYPE_DEFAULT;} + case 116: /* alter_db_optr ::= */ +{ setDefaultCreateDbOption(&yygotominor.yy382); yygotominor.yy382.dbType = TSDB_DB_TYPE_DEFAULT;} break; - case 125: /* typename ::= ids */ + case 128: /* typename ::= ids */ { yymsp[0].minor.yy0.type = 0; - tSetColumnType (&yygotominor.yy47, &yymsp[0].minor.yy0); + tSetColumnType (&yygotominor.yy343, &yymsp[0].minor.yy0); } break; - case 126: /* typename ::= ids LP signed RP */ + case 129: /* typename ::= ids LP signed RP */ { - if (yymsp[-1].minor.yy373 <= 0) { + if (yymsp[-1].minor.yy369 <= 0) { yymsp[-3].minor.yy0.type = 0; - tSetColumnType(&yygotominor.yy47, &yymsp[-3].minor.yy0); + tSetColumnType(&yygotominor.yy343, &yymsp[-3].minor.yy0); } else { - yymsp[-3].minor.yy0.type = -yymsp[-1].minor.yy373; // negative value of name length - tSetColumnType(&yygotominor.yy47, &yymsp[-3].minor.yy0); + yymsp[-3].minor.yy0.type = -yymsp[-1].minor.yy369; // negative value of name length + tSetColumnType(&yygotominor.yy343, &yymsp[-3].minor.yy0); } } break; - case 127: /* typename ::= ids UNSIGNED */ + case 130: /* typename ::= ids UNSIGNED */ { yymsp[-1].minor.yy0.type = 0; yymsp[-1].minor.yy0.n = ((yymsp[0].minor.yy0.z + yymsp[0].minor.yy0.n) - yymsp[-1].minor.yy0.z); - tSetColumnType (&yygotominor.yy47, &yymsp[-1].minor.yy0); + tSetColumnType (&yygotominor.yy343, &yymsp[-1].minor.yy0); } break; - case 128: /* signed ::= INTEGER */ - case 129: /* signed ::= PLUS INTEGER */ yytestcase(yyruleno==129); -{ yygotominor.yy373 = strtol(yymsp[0].minor.yy0.z, NULL, 10); } + case 131: /* signed ::= INTEGER */ + case 132: /* signed ::= PLUS INTEGER */ yytestcase(yyruleno==132); +{ yygotominor.yy369 = strtol(yymsp[0].minor.yy0.z, NULL, 10); } break; - case 130: /* signed ::= MINUS INTEGER */ - case 131: /* cmd ::= CREATE TABLE create_table_args */ yytestcase(yyruleno==131); - case 132: /* cmd ::= CREATE TABLE create_stable_args */ yytestcase(yyruleno==132); - case 133: /* cmd ::= CREATE STABLE create_stable_args */ yytestcase(yyruleno==133); -{ yygotominor.yy373 = -strtol(yymsp[0].minor.yy0.z, NULL, 10);} + case 133: /* signed ::= MINUS INTEGER */ + case 134: /* cmd ::= CREATE TABLE create_table_args */ yytestcase(yyruleno==134); + case 135: /* cmd ::= CREATE TABLE create_stable_args */ yytestcase(yyruleno==135); + case 136: /* cmd ::= CREATE STABLE create_stable_args */ yytestcase(yyruleno==136); +{ yygotominor.yy369 = -strtol(yymsp[0].minor.yy0.z, NULL, 10);} break; - case 134: /* cmd ::= CREATE TABLE create_table_list */ -{ pInfo->type = TSDB_SQL_CREATE_TABLE; pInfo->pCreateTableInfo = yymsp[0].minor.yy422;} + case 137: /* cmd ::= CREATE TABLE create_table_list */ +{ pInfo->type = TSDB_SQL_CREATE_TABLE; pInfo->pCreateTableInfo = yymsp[0].minor.yy182;} break; - case 135: /* create_table_list ::= create_from_stable */ + case 138: /* create_table_list ::= create_from_stable */ { SCreateTableSql* pCreateTable = calloc(1, sizeof(SCreateTableSql)); pCreateTable->childTableInfo = taosArrayInit(4, sizeof(SCreatedTableInfo)); - taosArrayPush(pCreateTable->childTableInfo, &yymsp[0].minor.yy504); + taosArrayPush(pCreateTable->childTableInfo, &yymsp[0].minor.yy456); pCreateTable->type = TSQL_CREATE_TABLE_FROM_STABLE; - yygotominor.yy422 = pCreateTable; + yygotominor.yy182 = pCreateTable; } break; - case 136: /* create_table_list ::= create_table_list create_from_stable */ + case 139: /* create_table_list ::= create_table_list create_from_stable */ { - taosArrayPush(yymsp[-1].minor.yy422->childTableInfo, &yymsp[0].minor.yy504); - yygotominor.yy422 = yymsp[-1].minor.yy422; + taosArrayPush(yymsp[-1].minor.yy182->childTableInfo, &yymsp[0].minor.yy456); + yygotominor.yy182 = yymsp[-1].minor.yy182; } break; - case 137: /* create_table_args ::= ifnotexists ids cpxName LP columnlist RP */ + case 140: /* create_table_args ::= ifnotexists ids cpxName LP columnlist RP */ { - yygotominor.yy422 = tSetCreateTableInfo(yymsp[-1].minor.yy325, NULL, NULL, TSQL_CREATE_TABLE); - setSqlInfo(pInfo, yygotominor.yy422, NULL, TSDB_SQL_CREATE_TABLE); + yygotominor.yy182 = tSetCreateTableInfo(yymsp[-1].minor.yy441, NULL, NULL, TSQL_CREATE_TABLE); + setSqlInfo(pInfo, yygotominor.yy182, NULL, TSDB_SQL_CREATE_TABLE); yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; setCreatedTableName(pInfo, &yymsp[-4].minor.yy0, &yymsp[-5].minor.yy0); } break; - case 138: /* create_stable_args ::= ifnotexists ids cpxName LP columnlist RP TAGS LP columnlist RP */ + case 141: /* create_stable_args ::= ifnotexists ids cpxName LP columnlist RP TAGS LP columnlist RP */ { - yygotominor.yy422 = tSetCreateTableInfo(yymsp[-5].minor.yy325, yymsp[-1].minor.yy325, NULL, TSQL_CREATE_STABLE); - setSqlInfo(pInfo, yygotominor.yy422, NULL, TSDB_SQL_CREATE_TABLE); + yygotominor.yy182 = tSetCreateTableInfo(yymsp[-5].minor.yy441, yymsp[-1].minor.yy441, NULL, TSQL_CREATE_STABLE); + setSqlInfo(pInfo, yygotominor.yy182, NULL, TSDB_SQL_CREATE_TABLE); yymsp[-8].minor.yy0.n += yymsp[-7].minor.yy0.n; setCreatedTableName(pInfo, &yymsp[-8].minor.yy0, &yymsp[-9].minor.yy0); } break; - case 139: /* create_from_stable ::= ifnotexists ids cpxName USING ids cpxName TAGS LP tagitemlist RP */ + case 142: /* create_from_stable ::= ifnotexists ids cpxName USING ids cpxName TAGS LP tagitemlist RP */ { yymsp[-5].minor.yy0.n += yymsp[-4].minor.yy0.n; yymsp[-8].minor.yy0.n += yymsp[-7].minor.yy0.n; - yygotominor.yy504 = createNewChildTableInfo(&yymsp[-5].minor.yy0, NULL, yymsp[-1].minor.yy325, &yymsp[-8].minor.yy0, &yymsp[-9].minor.yy0); + yygotominor.yy456 = createNewChildTableInfo(&yymsp[-5].minor.yy0, NULL, yymsp[-1].minor.yy441, &yymsp[-8].minor.yy0, &yymsp[-9].minor.yy0); } break; - case 140: /* create_from_stable ::= ifnotexists ids cpxName USING ids cpxName LP tagNamelist RP TAGS LP tagitemlist RP */ + case 143: /* create_from_stable ::= ifnotexists ids cpxName USING ids cpxName LP tagNamelist RP TAGS LP tagitemlist RP */ { yymsp[-8].minor.yy0.n += yymsp[-7].minor.yy0.n; yymsp[-11].minor.yy0.n += yymsp[-10].minor.yy0.n; - yygotominor.yy504 = createNewChildTableInfo(&yymsp[-8].minor.yy0, yymsp[-5].minor.yy325, yymsp[-1].minor.yy325, &yymsp[-11].minor.yy0, &yymsp[-12].minor.yy0); + yygotominor.yy456 = createNewChildTableInfo(&yymsp[-8].minor.yy0, yymsp[-5].minor.yy441, yymsp[-1].minor.yy441, &yymsp[-11].minor.yy0, &yymsp[-12].minor.yy0); } break; - case 141: /* tagNamelist ::= tagNamelist COMMA ids */ -{taosArrayPush(yymsp[-2].minor.yy325, &yymsp[0].minor.yy0); yygotominor.yy325 = yymsp[-2].minor.yy325; } + case 144: /* tagNamelist ::= tagNamelist COMMA ids */ +{taosArrayPush(yymsp[-2].minor.yy441, &yymsp[0].minor.yy0); yygotominor.yy441 = yymsp[-2].minor.yy441; } break; - case 142: /* tagNamelist ::= ids */ -{yygotominor.yy325 = taosArrayInit(4, sizeof(SStrToken)); taosArrayPush(yygotominor.yy325, &yymsp[0].minor.yy0);} + case 145: /* tagNamelist ::= ids */ +{yygotominor.yy441 = taosArrayInit(4, sizeof(SStrToken)); taosArrayPush(yygotominor.yy441, &yymsp[0].minor.yy0);} break; - case 143: /* create_table_args ::= ifnotexists ids cpxName AS select */ + case 146: /* create_table_args ::= ifnotexists ids cpxName AS select */ { - yygotominor.yy422 = tSetCreateTableInfo(NULL, NULL, yymsp[0].minor.yy536, TSQL_CREATE_STREAM); - setSqlInfo(pInfo, yygotominor.yy422, NULL, TSDB_SQL_CREATE_TABLE); + yygotominor.yy182 = tSetCreateTableInfo(NULL, NULL, yymsp[0].minor.yy236, TSQL_CREATE_STREAM); + setSqlInfo(pInfo, yygotominor.yy182, NULL, TSDB_SQL_CREATE_TABLE); yymsp[-3].minor.yy0.n += yymsp[-2].minor.yy0.n; setCreatedTableName(pInfo, &yymsp[-3].minor.yy0, &yymsp[-4].minor.yy0); } break; - case 144: /* columnlist ::= columnlist COMMA column */ -{taosArrayPush(yymsp[-2].minor.yy325, &yymsp[0].minor.yy47); yygotominor.yy325 = yymsp[-2].minor.yy325; } + case 147: /* columnlist ::= columnlist COMMA column */ +{taosArrayPush(yymsp[-2].minor.yy441, &yymsp[0].minor.yy343); yygotominor.yy441 = yymsp[-2].minor.yy441; } break; - case 145: /* columnlist ::= column */ -{yygotominor.yy325 = taosArrayInit(4, sizeof(TAOS_FIELD)); taosArrayPush(yygotominor.yy325, &yymsp[0].minor.yy47);} + case 148: /* columnlist ::= column */ +{yygotominor.yy441 = taosArrayInit(4, sizeof(TAOS_FIELD)); taosArrayPush(yygotominor.yy441, &yymsp[0].minor.yy343);} break; - case 146: /* column ::= ids typename */ + case 149: /* column ::= ids typename */ { - tSetColumnInfo(&yygotominor.yy47, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy47); + tSetColumnInfo(&yygotominor.yy343, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy343); } break; - case 147: /* tagitemlist ::= tagitemlist COMMA tagitem */ -{ yygotominor.yy325 = tVariantListAppend(yymsp[-2].minor.yy325, &yymsp[0].minor.yy442, -1); } + case 156: /* tagitem ::= NULL */ +{ yymsp[0].minor.yy0.type = 0; tVariantCreate(&yygotominor.yy506, &yymsp[0].minor.yy0); } break; - case 148: /* tagitemlist ::= tagitem */ -{ yygotominor.yy325 = tVariantListAppend(NULL, &yymsp[0].minor.yy442, -1); } - break; - case 149: /* tagitem ::= INTEGER */ - case 150: /* tagitem ::= FLOAT */ yytestcase(yyruleno==150); - case 151: /* tagitem ::= STRING */ yytestcase(yyruleno==151); - case 152: /* tagitem ::= BOOL */ yytestcase(yyruleno==152); -{ toTSDBType(yymsp[0].minor.yy0.type); tVariantCreate(&yygotominor.yy442, &yymsp[0].minor.yy0); } - break; - case 153: /* tagitem ::= NULL */ -{ yymsp[0].minor.yy0.type = 0; tVariantCreate(&yygotominor.yy442, &yymsp[0].minor.yy0); } - break; - case 154: /* tagitem ::= MINUS INTEGER */ - case 155: /* tagitem ::= MINUS FLOAT */ yytestcase(yyruleno==155); - case 156: /* tagitem ::= PLUS INTEGER */ yytestcase(yyruleno==156); - case 157: /* tagitem ::= PLUS FLOAT */ yytestcase(yyruleno==157); + case 157: /* tagitem ::= MINUS INTEGER */ + case 158: /* tagitem ::= MINUS FLOAT */ yytestcase(yyruleno==158); + case 159: /* tagitem ::= PLUS INTEGER */ yytestcase(yyruleno==159); + case 160: /* tagitem ::= PLUS FLOAT */ yytestcase(yyruleno==160); { yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; yymsp[-1].minor.yy0.type = yymsp[0].minor.yy0.type; toTSDBType(yymsp[-1].minor.yy0.type); - tVariantCreate(&yygotominor.yy442, &yymsp[-1].minor.yy0); + tVariantCreate(&yygotominor.yy506, &yymsp[-1].minor.yy0); } break; - case 158: /* select ::= SELECT selcollist from where_opt interval_opt session_option windowstate_option fill_opt sliding_opt groupby_opt orderby_opt having_opt slimit_opt limit_opt */ + case 161: /* select ::= SELECT selcollist from where_opt interval_opt session_option windowstate_option fill_opt sliding_opt groupby_opt orderby_opt having_opt slimit_opt limit_opt */ { - yygotominor.yy536 = tSetQuerySqlNode(&yymsp[-13].minor.yy0, yymsp[-12].minor.yy325, yymsp[-11].minor.yy52, yymsp[-10].minor.yy162, yymsp[-4].minor.yy325, yymsp[-3].minor.yy325, &yymsp[-9].minor.yy328, &yymsp[-8].minor.yy84, &yymsp[-7].minor.yy176, &yymsp[-5].minor.yy0, yymsp[-6].minor.yy325, &yymsp[0].minor.yy230, &yymsp[-1].minor.yy230, yymsp[-2].minor.yy162); + yygotominor.yy236 = tSetQuerySqlNode(&yymsp[-13].minor.yy0, yymsp[-12].minor.yy441, yymsp[-11].minor.yy244, yymsp[-10].minor.yy166, yymsp[-4].minor.yy441, yymsp[-3].minor.yy441, &yymsp[-9].minor.yy340, &yymsp[-8].minor.yy259, &yymsp[-7].minor.yy348, &yymsp[-5].minor.yy0, yymsp[-6].minor.yy441, &yymsp[0].minor.yy414, &yymsp[-1].minor.yy414, yymsp[-2].minor.yy166); } break; - case 159: /* select ::= LP select RP */ -{yygotominor.yy536 = yymsp[-1].minor.yy536;} + case 162: /* select ::= LP select RP */ +{yygotominor.yy236 = yymsp[-1].minor.yy236;} break; - case 160: /* union ::= select */ -{ yygotominor.yy325 = setSubclause(NULL, yymsp[0].minor.yy536); } + case 163: /* union ::= select */ +{ yygotominor.yy441 = setSubclause(NULL, yymsp[0].minor.yy236); } break; - case 161: /* union ::= union UNION ALL select */ -{ yygotominor.yy325 = appendSelectClause(yymsp[-3].minor.yy325, yymsp[0].minor.yy536); } + case 164: /* union ::= union UNION ALL select */ +{ yygotominor.yy441 = appendSelectClause(yymsp[-3].minor.yy441, yymsp[0].minor.yy236); } break; - case 162: /* cmd ::= union */ -{ setSqlInfo(pInfo, yymsp[0].minor.yy325, NULL, TSDB_SQL_SELECT); } + case 165: /* cmd ::= union */ +{ setSqlInfo(pInfo, yymsp[0].minor.yy441, NULL, TSDB_SQL_SELECT); } break; - case 163: /* select ::= SELECT selcollist */ + case 166: /* select ::= SELECT selcollist */ { - yygotominor.yy536 = tSetQuerySqlNode(&yymsp[-1].minor.yy0, yymsp[0].minor.yy325, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); + yygotominor.yy236 = tSetQuerySqlNode(&yymsp[-1].minor.yy0, yymsp[0].minor.yy441, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); } break; - case 164: /* sclp ::= selcollist COMMA */ -{yygotominor.yy325 = yymsp[-1].minor.yy325;} + case 167: /* sclp ::= selcollist COMMA */ +{yygotominor.yy441 = yymsp[-1].minor.yy441;} break; - case 165: /* sclp ::= */ - case 195: /* orderby_opt ::= */ yytestcase(yyruleno==195); -{yygotominor.yy325 = 0;} + case 168: /* sclp ::= */ + case 198: /* orderby_opt ::= */ yytestcase(yyruleno==198); +{yygotominor.yy441 = 0;} break; - case 166: /* selcollist ::= sclp distinct expr as */ + case 169: /* selcollist ::= sclp distinct expr as */ { - yygotominor.yy325 = tSqlExprListAppend(yymsp[-3].minor.yy325, yymsp[-1].minor.yy162, yymsp[-2].minor.yy0.n? &yymsp[-2].minor.yy0:0, yymsp[0].minor.yy0.n?&yymsp[0].minor.yy0:0); + yygotominor.yy441 = tSqlExprListAppend(yymsp[-3].minor.yy441, yymsp[-1].minor.yy166, yymsp[-2].minor.yy0.n? &yymsp[-2].minor.yy0:0, yymsp[0].minor.yy0.n?&yymsp[0].minor.yy0:0); } break; - case 167: /* selcollist ::= sclp STAR */ + case 170: /* selcollist ::= sclp STAR */ { tSqlExpr *pNode = tSqlExprCreateIdValue(NULL, TK_ALL); - yygotominor.yy325 = tSqlExprListAppend(yymsp[-1].minor.yy325, pNode, 0, 0); + yygotominor.yy441 = tSqlExprListAppend(yymsp[-1].minor.yy441, pNode, 0, 0); } break; - case 168: /* as ::= AS ids */ - case 169: /* as ::= ids */ yytestcase(yyruleno==169); + case 171: /* as ::= AS ids */ + case 172: /* as ::= ids */ yytestcase(yyruleno==172); { yygotominor.yy0 = yymsp[0].minor.yy0; } break; - case 170: /* as ::= */ + case 173: /* as ::= */ { yygotominor.yy0.n = 0; } break; - case 171: /* distinct ::= DISTINCT */ + case 174: /* distinct ::= DISTINCT */ { yygotominor.yy0 = yymsp[0].minor.yy0; } break; - case 173: /* from ::= FROM tablelist */ - case 174: /* from ::= FROM sub */ yytestcase(yyruleno==174); -{yygotominor.yy52 = yymsp[0].minor.yy52;} + case 176: /* from ::= FROM tablelist */ + case 177: /* from ::= FROM sub */ yytestcase(yyruleno==177); +{yygotominor.yy244 = yymsp[0].minor.yy244;} break; - case 175: /* sub ::= LP union RP */ -{yygotominor.yy52 = addSubqueryElem(NULL, yymsp[-1].minor.yy325, NULL);} + case 178: /* sub ::= LP union RP */ +{yygotominor.yy244 = addSubqueryElem(NULL, yymsp[-1].minor.yy441, NULL);} break; - case 176: /* sub ::= LP union RP ids */ -{yygotominor.yy52 = addSubqueryElem(NULL, yymsp[-2].minor.yy325, &yymsp[0].minor.yy0);} + case 179: /* sub ::= LP union RP ids */ +{yygotominor.yy244 = addSubqueryElem(NULL, yymsp[-2].minor.yy441, &yymsp[0].minor.yy0);} break; - case 177: /* sub ::= sub COMMA LP union RP ids */ -{yygotominor.yy52 = addSubqueryElem(yymsp[-5].minor.yy52, yymsp[-2].minor.yy325, &yymsp[0].minor.yy0);} + case 180: /* sub ::= sub COMMA LP union RP ids */ +{yygotominor.yy244 = addSubqueryElem(yymsp[-5].minor.yy244, yymsp[-2].minor.yy441, &yymsp[0].minor.yy0);} break; - case 178: /* tablelist ::= ids cpxName */ + case 181: /* tablelist ::= ids cpxName */ { yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; - yygotominor.yy52 = setTableNameList(NULL, &yymsp[-1].minor.yy0, NULL); + yygotominor.yy244 = setTableNameList(NULL, &yymsp[-1].minor.yy0, NULL); } break; - case 179: /* tablelist ::= ids cpxName ids */ + case 182: /* tablelist ::= ids cpxName ids */ { yymsp[-2].minor.yy0.n += yymsp[-1].minor.yy0.n; - yygotominor.yy52 = setTableNameList(NULL, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0); + yygotominor.yy244 = setTableNameList(NULL, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0); } break; - case 180: /* tablelist ::= tablelist COMMA ids cpxName */ + case 183: /* tablelist ::= tablelist COMMA ids cpxName */ { yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; - yygotominor.yy52 = setTableNameList(yymsp[-3].minor.yy52, &yymsp[-1].minor.yy0, NULL); + yygotominor.yy244 = setTableNameList(yymsp[-3].minor.yy244, &yymsp[-1].minor.yy0, NULL); } break; - case 181: /* tablelist ::= tablelist COMMA ids cpxName ids */ + case 184: /* tablelist ::= tablelist COMMA ids cpxName ids */ { yymsp[-2].minor.yy0.n += yymsp[-1].minor.yy0.n; - yygotominor.yy52 = setTableNameList(yymsp[-4].minor.yy52, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0); + yygotominor.yy244 = setTableNameList(yymsp[-4].minor.yy244, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0); } break; - case 182: /* tmvar ::= VARIABLE */ + case 185: /* tmvar ::= VARIABLE */ {yygotominor.yy0 = yymsp[0].minor.yy0;} break; - case 183: /* interval_opt ::= INTERVAL LP tmvar RP */ -{yygotominor.yy328.interval = yymsp[-1].minor.yy0; yygotominor.yy328.offset.n = 0;} + case 186: /* interval_opt ::= INTERVAL LP tmvar RP */ +{yygotominor.yy340.interval = yymsp[-1].minor.yy0; yygotominor.yy340.offset.n = 0;} break; - case 184: /* interval_opt ::= INTERVAL LP tmvar COMMA tmvar RP */ -{yygotominor.yy328.interval = yymsp[-3].minor.yy0; yygotominor.yy328.offset = yymsp[-1].minor.yy0;} + case 187: /* interval_opt ::= INTERVAL LP tmvar COMMA tmvar RP */ +{yygotominor.yy340.interval = yymsp[-3].minor.yy0; yygotominor.yy340.offset = yymsp[-1].minor.yy0;} break; - case 185: /* interval_opt ::= */ -{memset(&yygotominor.yy328, 0, sizeof(yygotominor.yy328));} + case 188: /* interval_opt ::= */ +{memset(&yygotominor.yy340, 0, sizeof(yygotominor.yy340));} break; - case 186: /* session_option ::= */ -{yygotominor.yy84.col.n = 0; yygotominor.yy84.gap.n = 0;} + case 189: /* session_option ::= */ +{yygotominor.yy259.col.n = 0; yygotominor.yy259.gap.n = 0;} break; - case 187: /* session_option ::= SESSION LP ids cpxName COMMA tmvar RP */ + case 190: /* session_option ::= SESSION LP ids cpxName COMMA tmvar RP */ { yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; - yygotominor.yy84.col = yymsp[-4].minor.yy0; - yygotominor.yy84.gap = yymsp[-1].minor.yy0; + yygotominor.yy259.col = yymsp[-4].minor.yy0; + yygotominor.yy259.gap = yymsp[-1].minor.yy0; } break; - case 188: /* windowstate_option ::= */ -{yygotominor.yy176.col.n = 0;} + case 191: /* windowstate_option ::= */ +{ yygotominor.yy348.col.n = 0; yygotominor.yy348.col.z = NULL;} break; - case 189: /* windowstate_option ::= STATE_WINDOW LP ids RP */ -{ - yygotominor.yy176.col = yymsp[-1].minor.yy0; -} + case 192: /* windowstate_option ::= STATE_WINDOW LP ids RP */ +{ yygotominor.yy348.col = yymsp[-1].minor.yy0; } break; - case 190: /* fill_opt ::= */ -{ yygotominor.yy325 = 0; } + case 193: /* fill_opt ::= */ +{ yygotominor.yy441 = 0; } break; - case 191: /* fill_opt ::= FILL LP ID COMMA tagitemlist RP */ + case 194: /* fill_opt ::= FILL LP ID COMMA tagitemlist RP */ { tVariant A = {0}; toTSDBType(yymsp[-3].minor.yy0.type); tVariantCreate(&A, &yymsp[-3].minor.yy0); - tVariantListInsert(yymsp[-1].minor.yy325, &A, -1, 0); - yygotominor.yy325 = yymsp[-1].minor.yy325; + tVariantListInsert(yymsp[-1].minor.yy441, &A, -1, 0); + yygotominor.yy441 = yymsp[-1].minor.yy441; } break; - case 192: /* fill_opt ::= FILL LP ID RP */ + case 195: /* fill_opt ::= FILL LP ID RP */ { toTSDBType(yymsp[-1].minor.yy0.type); - yygotominor.yy325 = tVariantListAppendToken(NULL, &yymsp[-1].minor.yy0, -1); + yygotominor.yy441 = tVariantListAppendToken(NULL, &yymsp[-1].minor.yy0, -1); } break; - case 193: /* sliding_opt ::= SLIDING LP tmvar RP */ + case 196: /* sliding_opt ::= SLIDING LP tmvar RP */ {yygotominor.yy0 = yymsp[-1].minor.yy0; } break; - case 194: /* sliding_opt ::= */ + case 197: /* sliding_opt ::= */ {yygotominor.yy0.n = 0; yygotominor.yy0.z = NULL; yygotominor.yy0.type = 0; } break; - case 196: /* orderby_opt ::= ORDER BY sortlist */ -{yygotominor.yy325 = yymsp[0].minor.yy325;} + case 199: /* orderby_opt ::= ORDER BY sortlist */ +{yygotominor.yy441 = yymsp[0].minor.yy441;} break; - case 197: /* sortlist ::= sortlist COMMA item sortorder */ + case 200: /* sortlist ::= sortlist COMMA item sortorder */ { - yygotominor.yy325 = tVariantListAppend(yymsp[-3].minor.yy325, &yymsp[-1].minor.yy442, yymsp[0].minor.yy196); + yygotominor.yy441 = tVariantListAppend(yymsp[-3].minor.yy441, &yymsp[-1].minor.yy506, yymsp[0].minor.yy112); } break; - case 198: /* sortlist ::= item sortorder */ + case 201: /* sortlist ::= item sortorder */ { - yygotominor.yy325 = tVariantListAppend(NULL, &yymsp[-1].minor.yy442, yymsp[0].minor.yy196); + yygotominor.yy441 = tVariantListAppend(NULL, &yymsp[-1].minor.yy506, yymsp[0].minor.yy112); } break; - case 199: /* item ::= ids cpxName */ + case 202: /* item ::= ids cpxName */ { toTSDBType(yymsp[-1].minor.yy0.type); yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; - tVariantCreate(&yygotominor.yy442, &yymsp[-1].minor.yy0); + tVariantCreate(&yygotominor.yy506, &yymsp[-1].minor.yy0); } break; - case 200: /* sortorder ::= ASC */ - case 202: /* sortorder ::= */ yytestcase(yyruleno==202); -{ yygotominor.yy196 = TSDB_ORDER_ASC; } + case 203: /* sortorder ::= ASC */ + case 205: /* sortorder ::= */ yytestcase(yyruleno==205); +{ yygotominor.yy112 = TSDB_ORDER_ASC; } break; - case 201: /* sortorder ::= DESC */ -{ yygotominor.yy196 = TSDB_ORDER_DESC;} + case 204: /* sortorder ::= DESC */ +{ yygotominor.yy112 = TSDB_ORDER_DESC;} break; - case 203: /* groupby_opt ::= */ -{ yygotominor.yy325 = 0;} + case 206: /* groupby_opt ::= */ +{ yygotominor.yy441 = 0;} break; - case 204: /* groupby_opt ::= GROUP BY grouplist */ -{ yygotominor.yy325 = yymsp[0].minor.yy325;} + case 207: /* groupby_opt ::= GROUP BY grouplist */ +{ yygotominor.yy441 = yymsp[0].minor.yy441;} break; - case 205: /* grouplist ::= grouplist COMMA item */ + case 208: /* grouplist ::= grouplist COMMA item */ { - yygotominor.yy325 = tVariantListAppend(yymsp[-2].minor.yy325, &yymsp[0].minor.yy442, -1); + yygotominor.yy441 = tVariantListAppend(yymsp[-2].minor.yy441, &yymsp[0].minor.yy506, -1); } break; - case 206: /* grouplist ::= item */ + case 209: /* grouplist ::= item */ { - yygotominor.yy325 = tVariantListAppend(NULL, &yymsp[0].minor.yy442, -1); + yygotominor.yy441 = tVariantListAppend(NULL, &yymsp[0].minor.yy506, -1); } break; - case 207: /* having_opt ::= */ - case 217: /* where_opt ::= */ yytestcase(yyruleno==217); - case 259: /* expritem ::= */ yytestcase(yyruleno==259); -{yygotominor.yy162 = 0;} + case 210: /* having_opt ::= */ + case 220: /* where_opt ::= */ yytestcase(yyruleno==220); + case 262: /* expritem ::= */ yytestcase(yyruleno==262); +{yygotominor.yy166 = 0;} break; - case 208: /* having_opt ::= HAVING expr */ - case 218: /* where_opt ::= WHERE expr */ yytestcase(yyruleno==218); - case 258: /* expritem ::= expr */ yytestcase(yyruleno==258); -{yygotominor.yy162 = yymsp[0].minor.yy162;} + case 211: /* having_opt ::= HAVING expr */ + case 221: /* where_opt ::= WHERE expr */ yytestcase(yyruleno==221); + case 261: /* expritem ::= expr */ yytestcase(yyruleno==261); +{yygotominor.yy166 = yymsp[0].minor.yy166;} break; - case 209: /* limit_opt ::= */ - case 213: /* slimit_opt ::= */ yytestcase(yyruleno==213); -{yygotominor.yy230.limit = -1; yygotominor.yy230.offset = 0;} + case 212: /* limit_opt ::= */ + case 216: /* slimit_opt ::= */ yytestcase(yyruleno==216); +{yygotominor.yy414.limit = -1; yygotominor.yy414.offset = 0;} break; - case 210: /* limit_opt ::= LIMIT signed */ - case 214: /* slimit_opt ::= SLIMIT signed */ yytestcase(yyruleno==214); -{yygotominor.yy230.limit = yymsp[0].minor.yy373; yygotominor.yy230.offset = 0;} + case 213: /* limit_opt ::= LIMIT signed */ + case 217: /* slimit_opt ::= SLIMIT signed */ yytestcase(yyruleno==217); +{yygotominor.yy414.limit = yymsp[0].minor.yy369; yygotominor.yy414.offset = 0;} break; - case 211: /* limit_opt ::= LIMIT signed OFFSET signed */ -{ yygotominor.yy230.limit = yymsp[-2].minor.yy373; yygotominor.yy230.offset = yymsp[0].minor.yy373;} + case 214: /* limit_opt ::= LIMIT signed OFFSET signed */ +{ yygotominor.yy414.limit = yymsp[-2].minor.yy369; yygotominor.yy414.offset = yymsp[0].minor.yy369;} break; - case 212: /* limit_opt ::= LIMIT signed COMMA signed */ -{ yygotominor.yy230.limit = yymsp[0].minor.yy373; yygotominor.yy230.offset = yymsp[-2].minor.yy373;} + case 215: /* limit_opt ::= LIMIT signed COMMA signed */ +{ yygotominor.yy414.limit = yymsp[0].minor.yy369; yygotominor.yy414.offset = yymsp[-2].minor.yy369;} break; - case 215: /* slimit_opt ::= SLIMIT signed SOFFSET signed */ -{yygotominor.yy230.limit = yymsp[-2].minor.yy373; yygotominor.yy230.offset = yymsp[0].minor.yy373;} + case 218: /* slimit_opt ::= SLIMIT signed SOFFSET signed */ +{yygotominor.yy414.limit = yymsp[-2].minor.yy369; yygotominor.yy414.offset = yymsp[0].minor.yy369;} break; - case 216: /* slimit_opt ::= SLIMIT signed COMMA signed */ -{yygotominor.yy230.limit = yymsp[0].minor.yy373; yygotominor.yy230.offset = yymsp[-2].minor.yy373;} + case 219: /* slimit_opt ::= SLIMIT signed COMMA signed */ +{yygotominor.yy414.limit = yymsp[0].minor.yy369; yygotominor.yy414.offset = yymsp[-2].minor.yy369;} break; - case 219: /* expr ::= LP expr RP */ -{yygotominor.yy162 = yymsp[-1].minor.yy162; yygotominor.yy162->token.z = yymsp[-2].minor.yy0.z; yygotominor.yy162->token.n = (yymsp[0].minor.yy0.z - yymsp[-2].minor.yy0.z + 1);} + case 222: /* expr ::= LP expr RP */ +{yygotominor.yy166 = yymsp[-1].minor.yy166; yygotominor.yy166->token.z = yymsp[-2].minor.yy0.z; yygotominor.yy166->token.n = (yymsp[0].minor.yy0.z - yymsp[-2].minor.yy0.z + 1);} break; - case 220: /* expr ::= ID */ -{ yygotominor.yy162 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_ID);} + case 223: /* expr ::= ID */ +{ yygotominor.yy166 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_ID);} break; - case 221: /* expr ::= ID DOT ID */ -{ yymsp[-2].minor.yy0.n += (1+yymsp[0].minor.yy0.n); yygotominor.yy162 = tSqlExprCreateIdValue(&yymsp[-2].minor.yy0, TK_ID);} + case 224: /* expr ::= ID DOT ID */ +{ yymsp[-2].minor.yy0.n += (1+yymsp[0].minor.yy0.n); yygotominor.yy166 = tSqlExprCreateIdValue(&yymsp[-2].minor.yy0, TK_ID);} break; - case 222: /* expr ::= ID DOT STAR */ -{ yymsp[-2].minor.yy0.n += (1+yymsp[0].minor.yy0.n); yygotominor.yy162 = tSqlExprCreateIdValue(&yymsp[-2].minor.yy0, TK_ALL);} + case 225: /* expr ::= ID DOT STAR */ +{ yymsp[-2].minor.yy0.n += (1+yymsp[0].minor.yy0.n); yygotominor.yy166 = tSqlExprCreateIdValue(&yymsp[-2].minor.yy0, TK_ALL);} break; - case 223: /* expr ::= INTEGER */ -{ yygotominor.yy162 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_INTEGER);} + case 226: /* expr ::= INTEGER */ +{ yygotominor.yy166 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_INTEGER);} break; - case 224: /* expr ::= MINUS INTEGER */ - case 225: /* expr ::= PLUS INTEGER */ yytestcase(yyruleno==225); -{ yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; yymsp[-1].minor.yy0.type = TK_INTEGER; yygotominor.yy162 = tSqlExprCreateIdValue(&yymsp[-1].minor.yy0, TK_INTEGER);} + case 227: /* expr ::= MINUS INTEGER */ + case 228: /* expr ::= PLUS INTEGER */ yytestcase(yyruleno==228); +{ yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; yymsp[-1].minor.yy0.type = TK_INTEGER; yygotominor.yy166 = tSqlExprCreateIdValue(&yymsp[-1].minor.yy0, TK_INTEGER);} break; - case 226: /* expr ::= FLOAT */ -{ yygotominor.yy162 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_FLOAT);} + case 229: /* expr ::= FLOAT */ +{ yygotominor.yy166 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_FLOAT);} break; - case 227: /* expr ::= MINUS FLOAT */ - case 228: /* expr ::= PLUS FLOAT */ yytestcase(yyruleno==228); -{ yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; yymsp[-1].minor.yy0.type = TK_FLOAT; yygotominor.yy162 = tSqlExprCreateIdValue(&yymsp[-1].minor.yy0, TK_FLOAT);} + case 230: /* expr ::= MINUS FLOAT */ + case 231: /* expr ::= PLUS FLOAT */ yytestcase(yyruleno==231); +{ yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; yymsp[-1].minor.yy0.type = TK_FLOAT; yygotominor.yy166 = tSqlExprCreateIdValue(&yymsp[-1].minor.yy0, TK_FLOAT);} break; - case 229: /* expr ::= STRING */ -{ yygotominor.yy162 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_STRING);} + case 232: /* expr ::= STRING */ +{ yygotominor.yy166 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_STRING);} break; - case 230: /* expr ::= NOW */ -{ yygotominor.yy162 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_NOW); } + case 233: /* expr ::= NOW */ +{ yygotominor.yy166 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_NOW); } break; - case 231: /* expr ::= VARIABLE */ -{ yygotominor.yy162 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_VARIABLE);} + case 234: /* expr ::= VARIABLE */ +{ yygotominor.yy166 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_VARIABLE);} break; - case 232: /* expr ::= PLUS VARIABLE */ - case 233: /* expr ::= MINUS VARIABLE */ yytestcase(yyruleno==233); -{ yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; yymsp[-1].minor.yy0.type = TK_VARIABLE; yygotominor.yy162 = tSqlExprCreateIdValue(&yymsp[-1].minor.yy0, TK_VARIABLE);} + case 235: /* expr ::= PLUS VARIABLE */ + case 236: /* expr ::= MINUS VARIABLE */ yytestcase(yyruleno==236); +{ yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; yymsp[-1].minor.yy0.type = TK_VARIABLE; yygotominor.yy166 = tSqlExprCreateIdValue(&yymsp[-1].minor.yy0, TK_VARIABLE);} break; - case 234: /* expr ::= BOOL */ -{ yygotominor.yy162 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_BOOL);} + case 237: /* expr ::= BOOL */ +{ yygotominor.yy166 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_BOOL);} break; - case 235: /* expr ::= NULL */ -{ yygotominor.yy162 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_NULL);} + case 238: /* expr ::= NULL */ +{ yygotominor.yy166 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_NULL);} break; - case 236: /* expr ::= ID LP exprlist RP */ -{ yygotominor.yy162 = tSqlExprCreateFunction(yymsp[-1].minor.yy325, &yymsp[-3].minor.yy0, &yymsp[0].minor.yy0, yymsp[-3].minor.yy0.type); } + case 239: /* expr ::= ID LP exprlist RP */ +{ yygotominor.yy166 = tSqlExprCreateFunction(yymsp[-1].minor.yy441, &yymsp[-3].minor.yy0, &yymsp[0].minor.yy0, yymsp[-3].minor.yy0.type); } break; - case 237: /* expr ::= ID LP STAR RP */ -{ yygotominor.yy162 = tSqlExprCreateFunction(NULL, &yymsp[-3].minor.yy0, &yymsp[0].minor.yy0, yymsp[-3].minor.yy0.type); } + case 240: /* expr ::= ID LP STAR RP */ +{ yygotominor.yy166 = tSqlExprCreateFunction(NULL, &yymsp[-3].minor.yy0, &yymsp[0].minor.yy0, yymsp[-3].minor.yy0.type); } break; - case 238: /* expr ::= expr IS NULL */ -{yygotominor.yy162 = tSqlExprCreate(yymsp[-2].minor.yy162, NULL, TK_ISNULL);} + case 241: /* expr ::= expr IS NULL */ +{yygotominor.yy166 = tSqlExprCreate(yymsp[-2].minor.yy166, NULL, TK_ISNULL);} break; - case 239: /* expr ::= expr IS NOT NULL */ -{yygotominor.yy162 = tSqlExprCreate(yymsp[-3].minor.yy162, NULL, TK_NOTNULL);} + case 242: /* expr ::= expr IS NOT NULL */ +{yygotominor.yy166 = tSqlExprCreate(yymsp[-3].minor.yy166, NULL, TK_NOTNULL);} break; - case 240: /* expr ::= expr LT expr */ -{yygotominor.yy162 = tSqlExprCreate(yymsp[-2].minor.yy162, yymsp[0].minor.yy162, TK_LT);} + case 243: /* expr ::= expr LT expr */ +{yygotominor.yy166 = tSqlExprCreate(yymsp[-2].minor.yy166, yymsp[0].minor.yy166, TK_LT);} break; - case 241: /* expr ::= expr GT expr */ -{yygotominor.yy162 = tSqlExprCreate(yymsp[-2].minor.yy162, yymsp[0].minor.yy162, TK_GT);} + case 244: /* expr ::= expr GT expr */ +{yygotominor.yy166 = tSqlExprCreate(yymsp[-2].minor.yy166, yymsp[0].minor.yy166, TK_GT);} break; - case 242: /* expr ::= expr LE expr */ -{yygotominor.yy162 = tSqlExprCreate(yymsp[-2].minor.yy162, yymsp[0].minor.yy162, TK_LE);} + case 245: /* expr ::= expr LE expr */ +{yygotominor.yy166 = tSqlExprCreate(yymsp[-2].minor.yy166, yymsp[0].minor.yy166, TK_LE);} break; - case 243: /* expr ::= expr GE expr */ -{yygotominor.yy162 = tSqlExprCreate(yymsp[-2].minor.yy162, yymsp[0].minor.yy162, TK_GE);} + case 246: /* expr ::= expr GE expr */ +{yygotominor.yy166 = tSqlExprCreate(yymsp[-2].minor.yy166, yymsp[0].minor.yy166, TK_GE);} break; - case 244: /* expr ::= expr NE expr */ -{yygotominor.yy162 = tSqlExprCreate(yymsp[-2].minor.yy162, yymsp[0].minor.yy162, TK_NE);} + case 247: /* expr ::= expr NE expr */ +{yygotominor.yy166 = tSqlExprCreate(yymsp[-2].minor.yy166, yymsp[0].minor.yy166, TK_NE);} break; - case 245: /* expr ::= expr EQ expr */ -{yygotominor.yy162 = tSqlExprCreate(yymsp[-2].minor.yy162, yymsp[0].minor.yy162, TK_EQ);} + case 248: /* expr ::= expr EQ expr */ +{yygotominor.yy166 = tSqlExprCreate(yymsp[-2].minor.yy166, yymsp[0].minor.yy166, TK_EQ);} break; - case 246: /* expr ::= expr BETWEEN expr AND expr */ -{ tSqlExpr* X2 = tSqlExprClone(yymsp[-4].minor.yy162); yygotominor.yy162 = tSqlExprCreate(tSqlExprCreate(yymsp[-4].minor.yy162, yymsp[-2].minor.yy162, TK_GE), tSqlExprCreate(X2, yymsp[0].minor.yy162, TK_LE), TK_AND);} + case 249: /* expr ::= expr BETWEEN expr AND expr */ +{ tSqlExpr* X2 = tSqlExprClone(yymsp[-4].minor.yy166); yygotominor.yy166 = tSqlExprCreate(tSqlExprCreate(yymsp[-4].minor.yy166, yymsp[-2].minor.yy166, TK_GE), tSqlExprCreate(X2, yymsp[0].minor.yy166, TK_LE), TK_AND);} break; - case 247: /* expr ::= expr AND expr */ -{yygotominor.yy162 = tSqlExprCreate(yymsp[-2].minor.yy162, yymsp[0].minor.yy162, TK_AND);} + case 250: /* expr ::= expr AND expr */ +{yygotominor.yy166 = tSqlExprCreate(yymsp[-2].minor.yy166, yymsp[0].minor.yy166, TK_AND);} break; - case 248: /* expr ::= expr OR expr */ -{yygotominor.yy162 = tSqlExprCreate(yymsp[-2].minor.yy162, yymsp[0].minor.yy162, TK_OR); } + case 251: /* expr ::= expr OR expr */ +{yygotominor.yy166 = tSqlExprCreate(yymsp[-2].minor.yy166, yymsp[0].minor.yy166, TK_OR); } break; - case 249: /* expr ::= expr PLUS expr */ -{yygotominor.yy162 = tSqlExprCreate(yymsp[-2].minor.yy162, yymsp[0].minor.yy162, TK_PLUS); } + case 252: /* expr ::= expr PLUS expr */ +{yygotominor.yy166 = tSqlExprCreate(yymsp[-2].minor.yy166, yymsp[0].minor.yy166, TK_PLUS); } break; - case 250: /* expr ::= expr MINUS expr */ -{yygotominor.yy162 = tSqlExprCreate(yymsp[-2].minor.yy162, yymsp[0].minor.yy162, TK_MINUS); } + case 253: /* expr ::= expr MINUS expr */ +{yygotominor.yy166 = tSqlExprCreate(yymsp[-2].minor.yy166, yymsp[0].minor.yy166, TK_MINUS); } break; - case 251: /* expr ::= expr STAR expr */ -{yygotominor.yy162 = tSqlExprCreate(yymsp[-2].minor.yy162, yymsp[0].minor.yy162, TK_STAR); } + case 254: /* expr ::= expr STAR expr */ +{yygotominor.yy166 = tSqlExprCreate(yymsp[-2].minor.yy166, yymsp[0].minor.yy166, TK_STAR); } break; - case 252: /* expr ::= expr SLASH expr */ -{yygotominor.yy162 = tSqlExprCreate(yymsp[-2].minor.yy162, yymsp[0].minor.yy162, TK_DIVIDE);} + case 255: /* expr ::= expr SLASH expr */ +{yygotominor.yy166 = tSqlExprCreate(yymsp[-2].minor.yy166, yymsp[0].minor.yy166, TK_DIVIDE);} break; - case 253: /* expr ::= expr REM expr */ -{yygotominor.yy162 = tSqlExprCreate(yymsp[-2].minor.yy162, yymsp[0].minor.yy162, TK_REM); } + case 256: /* expr ::= expr REM expr */ +{yygotominor.yy166 = tSqlExprCreate(yymsp[-2].minor.yy166, yymsp[0].minor.yy166, TK_REM); } break; - case 254: /* expr ::= expr LIKE expr */ -{yygotominor.yy162 = tSqlExprCreate(yymsp[-2].minor.yy162, yymsp[0].minor.yy162, TK_LIKE); } + case 257: /* expr ::= expr LIKE expr */ +{yygotominor.yy166 = tSqlExprCreate(yymsp[-2].minor.yy166, yymsp[0].minor.yy166, TK_LIKE); } break; - case 255: /* expr ::= expr IN LP exprlist RP */ -{yygotominor.yy162 = tSqlExprCreate(yymsp[-4].minor.yy162, (tSqlExpr*)yymsp[-1].minor.yy325, TK_IN); } + case 258: /* expr ::= expr IN LP exprlist RP */ +{yygotominor.yy166 = tSqlExprCreate(yymsp[-4].minor.yy166, (tSqlExpr*)yymsp[-1].minor.yy441, TK_IN); } break; - case 256: /* exprlist ::= exprlist COMMA expritem */ -{yygotominor.yy325 = tSqlExprListAppend(yymsp[-2].minor.yy325,yymsp[0].minor.yy162,0, 0);} + case 259: /* exprlist ::= exprlist COMMA expritem */ +{yygotominor.yy441 = tSqlExprListAppend(yymsp[-2].minor.yy441,yymsp[0].minor.yy166,0, 0);} break; - case 257: /* exprlist ::= expritem */ -{yygotominor.yy325 = tSqlExprListAppend(0,yymsp[0].minor.yy162,0, 0);} + case 260: /* exprlist ::= expritem */ +{yygotominor.yy441 = tSqlExprListAppend(0,yymsp[0].minor.yy166,0, 0);} break; - case 260: /* cmd ::= RESET QUERY CACHE */ + case 263: /* cmd ::= RESET QUERY CACHE */ { setDCLSqlElems(pInfo, TSDB_SQL_RESET_CACHE, 0);} break; - case 261: /* cmd ::= SYNCDB ids REPLICA */ + case 264: /* cmd ::= SYNCDB ids REPLICA */ { setDCLSqlElems(pInfo, TSDB_SQL_SYNC_DB_REPLICA, 1, &yymsp[-1].minor.yy0);} break; - case 262: /* cmd ::= ALTER TABLE ids cpxName ADD COLUMN columnlist */ + case 265: /* cmd ::= ALTER TABLE ids cpxName ADD COLUMN columnlist */ { yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; - SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-4].minor.yy0, yymsp[0].minor.yy325, NULL, TSDB_ALTER_TABLE_ADD_COLUMN, -1); + SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-4].minor.yy0, yymsp[0].minor.yy441, NULL, TSDB_ALTER_TABLE_ADD_COLUMN, -1); setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 263: /* cmd ::= ALTER TABLE ids cpxName DROP COLUMN ids */ + case 266: /* cmd ::= ALTER TABLE ids cpxName DROP COLUMN ids */ { yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; @@ -2622,21 +2633,21 @@ static void yy_reduce( setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 264: /* cmd ::= ALTER TABLE ids cpxName MODIFY COLUMN columnlist */ + case 267: /* cmd ::= ALTER TABLE ids cpxName MODIFY COLUMN columnlist */ { yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; - SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-4].minor.yy0, yymsp[0].minor.yy325, NULL, TSDB_ALTER_TABLE_CHANGE_COLUMN, -1); + SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-4].minor.yy0, yymsp[0].minor.yy441, NULL, TSDB_ALTER_TABLE_CHANGE_COLUMN, -1); setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 265: /* cmd ::= ALTER TABLE ids cpxName ADD TAG columnlist */ + case 268: /* cmd ::= ALTER TABLE ids cpxName ADD TAG columnlist */ { yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; - SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-4].minor.yy0, yymsp[0].minor.yy325, NULL, TSDB_ALTER_TABLE_ADD_TAG_COLUMN, -1); + SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-4].minor.yy0, yymsp[0].minor.yy441, NULL, TSDB_ALTER_TABLE_ADD_TAG_COLUMN, -1); setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 266: /* cmd ::= ALTER TABLE ids cpxName DROP TAG ids */ + case 269: /* cmd ::= ALTER TABLE ids cpxName DROP TAG ids */ { yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; @@ -2647,7 +2658,7 @@ static void yy_reduce( setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 267: /* cmd ::= ALTER TABLE ids cpxName CHANGE TAG ids ids */ + case 270: /* cmd ::= ALTER TABLE ids cpxName CHANGE TAG ids ids */ { yymsp[-5].minor.yy0.n += yymsp[-4].minor.yy0.n; @@ -2661,33 +2672,33 @@ static void yy_reduce( setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 268: /* cmd ::= ALTER TABLE ids cpxName SET TAG ids EQ tagitem */ + case 271: /* cmd ::= ALTER TABLE ids cpxName SET TAG ids EQ tagitem */ { yymsp[-6].minor.yy0.n += yymsp[-5].minor.yy0.n; toTSDBType(yymsp[-2].minor.yy0.type); SArray* A = tVariantListAppendToken(NULL, &yymsp[-2].minor.yy0, -1); - A = tVariantListAppend(A, &yymsp[0].minor.yy442, -1); + A = tVariantListAppend(A, &yymsp[0].minor.yy506, -1); SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-6].minor.yy0, NULL, A, TSDB_ALTER_TABLE_UPDATE_TAG_VAL, -1); setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 269: /* cmd ::= ALTER TABLE ids cpxName MODIFY TAG columnlist */ + case 272: /* cmd ::= ALTER TABLE ids cpxName MODIFY TAG columnlist */ { yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; - SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-4].minor.yy0, yymsp[0].minor.yy325, NULL, TSDB_ALTER_TABLE_MODIFY_TAG_COLUMN, -1); + SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-4].minor.yy0, yymsp[0].minor.yy441, NULL, TSDB_ALTER_TABLE_MODIFY_TAG_COLUMN, -1); setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 270: /* cmd ::= ALTER STABLE ids cpxName ADD COLUMN columnlist */ + case 273: /* cmd ::= ALTER STABLE ids cpxName ADD COLUMN columnlist */ { yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; - SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-4].minor.yy0, yymsp[0].minor.yy325, NULL, TSDB_ALTER_TABLE_ADD_COLUMN, TSDB_SUPER_TABLE); + SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-4].minor.yy0, yymsp[0].minor.yy441, NULL, TSDB_ALTER_TABLE_ADD_COLUMN, TSDB_SUPER_TABLE); setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 271: /* cmd ::= ALTER STABLE ids cpxName DROP COLUMN ids */ + case 274: /* cmd ::= ALTER STABLE ids cpxName DROP COLUMN ids */ { yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; @@ -2698,21 +2709,21 @@ static void yy_reduce( setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 272: /* cmd ::= ALTER STABLE ids cpxName MODIFY COLUMN columnlist */ + case 275: /* cmd ::= ALTER STABLE ids cpxName MODIFY COLUMN columnlist */ { yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; - SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-4].minor.yy0, yymsp[0].minor.yy325, NULL, TSDB_ALTER_TABLE_CHANGE_COLUMN, TSDB_SUPER_TABLE); + SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-4].minor.yy0, yymsp[0].minor.yy441, NULL, TSDB_ALTER_TABLE_CHANGE_COLUMN, TSDB_SUPER_TABLE); setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 273: /* cmd ::= ALTER STABLE ids cpxName ADD TAG columnlist */ + case 276: /* cmd ::= ALTER STABLE ids cpxName ADD TAG columnlist */ { yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; - SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-4].minor.yy0, yymsp[0].minor.yy325, NULL, TSDB_ALTER_TABLE_ADD_TAG_COLUMN, TSDB_SUPER_TABLE); + SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-4].minor.yy0, yymsp[0].minor.yy441, NULL, TSDB_ALTER_TABLE_ADD_TAG_COLUMN, TSDB_SUPER_TABLE); setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 274: /* cmd ::= ALTER STABLE ids cpxName DROP TAG ids */ + case 277: /* cmd ::= ALTER STABLE ids cpxName DROP TAG ids */ { yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; @@ -2723,7 +2734,7 @@ static void yy_reduce( setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 275: /* cmd ::= ALTER STABLE ids cpxName CHANGE TAG ids ids */ + case 278: /* cmd ::= ALTER STABLE ids cpxName CHANGE TAG ids ids */ { yymsp[-5].minor.yy0.n += yymsp[-4].minor.yy0.n; @@ -2737,32 +2748,32 @@ static void yy_reduce( setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 276: /* cmd ::= ALTER STABLE ids cpxName SET TAG ids EQ tagitem */ + case 279: /* cmd ::= ALTER STABLE ids cpxName SET TAG ids EQ tagitem */ { yymsp[-6].minor.yy0.n += yymsp[-5].minor.yy0.n; toTSDBType(yymsp[-2].minor.yy0.type); SArray* A = tVariantListAppendToken(NULL, &yymsp[-2].minor.yy0, -1); - A = tVariantListAppend(A, &yymsp[0].minor.yy442, -1); + A = tVariantListAppend(A, &yymsp[0].minor.yy506, -1); SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-6].minor.yy0, NULL, A, TSDB_ALTER_TABLE_UPDATE_TAG_VAL, TSDB_SUPER_TABLE); setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 277: /* cmd ::= ALTER STABLE ids cpxName MODIFY TAG columnlist */ + case 280: /* cmd ::= ALTER STABLE ids cpxName MODIFY TAG columnlist */ { yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; - SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-4].minor.yy0, yymsp[0].minor.yy325, NULL, TSDB_ALTER_TABLE_MODIFY_TAG_COLUMN, TSDB_SUPER_TABLE); + SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-4].minor.yy0, yymsp[0].minor.yy441, NULL, TSDB_ALTER_TABLE_MODIFY_TAG_COLUMN, TSDB_SUPER_TABLE); setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 278: /* cmd ::= KILL CONNECTION INTEGER */ + case 281: /* cmd ::= KILL CONNECTION INTEGER */ {setKillSql(pInfo, TSDB_SQL_KILL_CONNECTION, &yymsp[0].minor.yy0);} break; - case 279: /* cmd ::= KILL STREAM INTEGER COLON INTEGER */ + case 282: /* cmd ::= KILL STREAM INTEGER COLON INTEGER */ {yymsp[-2].minor.yy0.n += (yymsp[-1].minor.yy0.n + yymsp[0].minor.yy0.n); setKillSql(pInfo, TSDB_SQL_KILL_STREAM, &yymsp[-2].minor.yy0);} break; - case 280: /* cmd ::= KILL QUERY INTEGER COLON INTEGER */ + case 283: /* cmd ::= KILL QUERY INTEGER COLON INTEGER */ {yymsp[-2].minor.yy0.n += (yymsp[-1].minor.yy0.n + yymsp[0].minor.yy0.n); setKillSql(pInfo, TSDB_SQL_KILL_QUERY, &yymsp[-2].minor.yy0);} break; default: diff --git a/src/tsdb/inc/tsdbCommitQueue.h b/src/tsdb/inc/tsdbCommitQueue.h index 6342c036b77317f6d954bf63c32674f5fbe66de9..b690e3bdc25d86acf7e5b9d580470a80f3f4316f 100644 --- a/src/tsdb/inc/tsdbCommitQueue.h +++ b/src/tsdb/inc/tsdbCommitQueue.h @@ -16,7 +16,7 @@ #ifndef _TD_TSDB_COMMIT_QUEUE_H_ #define _TD_TSDB_COMMIT_QUEUE_H_ -typedef enum { COMMIT_REQ, COMPACT_REQ } TSDB_REQ_T; +typedef enum { COMMIT_REQ, COMPACT_REQ,COMMIT_CONFIG_REQ } TSDB_REQ_T; int tsdbScheduleCommit(STsdbRepo *pRepo, TSDB_REQ_T req); diff --git a/src/tsdb/inc/tsdbMemTable.h b/src/tsdb/inc/tsdbMemTable.h index 6046274af40b855ac25dba6e220bf3bcfdc1dcca..babb7024b2500f3b8418fa5404bb593c768d8f1f 100644 --- a/src/tsdb/inc/tsdbMemTable.h +++ b/src/tsdb/inc/tsdbMemTable.h @@ -66,6 +66,7 @@ int tsdbTakeMemSnapshot(STsdbRepo* pRepo, SMemSnapshot* pSnapshot, SArray* pAT void tsdbUnTakeMemSnapShot(STsdbRepo* pRepo, SMemSnapshot* pSnapshot); void* tsdbAllocBytes(STsdbRepo* pRepo, int bytes); int tsdbAsyncCommit(STsdbRepo* pRepo); +int tsdbSyncCommitConfig(STsdbRepo* pRepo); int tsdbLoadDataFromCache(STable* pTable, SSkipListIterator* pIter, TSKEY maxKey, int maxRowsToRead, SDataCols* pCols, TKEY* filterKeys, int nFilterKeys, bool keepDup, SMergeInfo* pMergeInfo); void* tsdbCommitData(STsdbRepo* pRepo); diff --git a/src/tsdb/inc/tsdbint.h b/src/tsdb/inc/tsdbint.h index 049c1bdb6ea37121a202a931faa17a4ea36cf6dc..dd43e393102c40d4b12a948a9b4d6d72f30f6dad 100644 --- a/src/tsdb/inc/tsdbint.h +++ b/src/tsdb/inc/tsdbint.h @@ -78,7 +78,6 @@ struct STsdbRepo { bool config_changed; // config changed flag pthread_mutex_t save_mutex; // protect save config - uint8_t hasCachedLastRow; uint8_t hasCachedLastColumn; STsdbAppH appH; @@ -93,6 +92,7 @@ struct STsdbRepo { pthread_mutex_t mutex; bool repoLocked; int32_t code; // Commit code + bool inCompact; // is in compact process? }; #define REPO_ID(r) (r)->config.tsdbId diff --git a/src/tsdb/src/tsdbCommitQueue.c b/src/tsdb/src/tsdbCommitQueue.c index bb844e8e83f532e2c933ae35063460ec59129ee3..e25014bc1e8f2456eece3d517096cfee66886800 100644 --- a/src/tsdb/src/tsdbCommitQueue.c +++ b/src/tsdb/src/tsdbCommitQueue.c @@ -180,15 +180,14 @@ static void *tsdbLoopCommit(void *arg) { req = ((SReq *)pNode->data)->req; pRepo = ((SReq *)pNode->data)->pRepo; - // check if need to apply new config - if (pRepo->config_changed) { - tsdbApplyRepoConfig(pRepo); - } - if (req == COMMIT_REQ) { tsdbCommitData(pRepo); } else if (req == COMPACT_REQ) { tsdbCompactImpl(pRepo); + } else if (req == COMMIT_CONFIG_REQ) { + ASSERT(pRepo->config_changed); + tsdbApplyRepoConfig(pRepo); + tsem_post(&(pRepo->readyToCommit)); } else { ASSERT(0); } diff --git a/src/tsdb/src/tsdbCompact.c b/src/tsdb/src/tsdbCompact.c index 5e5b1d73575f260c7874f22da135eba3cd0b3ee5..210150c184e975c51d224d67f90c98df380964d9 100644 --- a/src/tsdb/src/tsdbCompact.c +++ b/src/tsdb/src/tsdbCompact.c @@ -12,11 +12,516 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -#include "tsdb.h" +#include "tsdbint.h" #ifndef _TSDB_PLUGINS -int tsdbCompact(STsdbRepo *pRepo) { return 0; } -void *tsdbCompactImpl(STsdbRepo *pRepo) { return NULL; } +typedef struct { + STable * pTable; + SBlockIdx * pBlkIdx; + SBlockIdx bindex; + SBlockInfo *pInfo; +} STableCompactH; + +typedef struct { + SRtn rtn; + SFSIter fsIter; + SArray * tbArray; // table array to cache table obj and block indexes + SReadH readh; + SDFileSet wSet; + SArray * aBlkIdx; + SArray * aSupBlk; + SDataCols *pDataCols; +} SCompactH; + +#define TSDB_COMPACT_WSET(pComph) (&((pComph)->wSet)) +#define TSDB_COMPACT_REPO(pComph) TSDB_READ_REPO(&((pComph)->readh)) +#define TSDB_COMPACT_HEAD_FILE(pComph) TSDB_DFILE_IN_SET(TSDB_COMPACT_WSET(pComph), TSDB_FILE_HEAD) +#define TSDB_COMPACT_DATA_FILE(pComph) TSDB_DFILE_IN_SET(TSDB_COMPACT_WSET(pComph), TSDB_FILE_DATA) +#define TSDB_COMPACT_LAST_FILE(pComph) TSDB_DFILE_IN_SET(TSDB_COMPACT_WSET(pComph), TSDB_FILE_LAST) +#define TSDB_COMPACT_BUF(pComph) TSDB_READ_BUF(&((pComph)->readh)) +#define TSDB_COMPACT_COMP_BUF(pComph) TSDB_READ_COMP_BUF(&((pComph)->readh)) + +static int tsdbAsyncCompact(STsdbRepo *pRepo); +static void tsdbStartCompact(STsdbRepo *pRepo); +static void tsdbEndCompact(STsdbRepo *pRepo, int eno); +static int tsdbCompactMeta(STsdbRepo *pRepo); +static int tsdbCompactTSData(STsdbRepo *pRepo); +static int tsdbCompactFSet(SCompactH *pComph, SDFileSet *pSet); +static bool tsdbShouldCompact(SCompactH *pComph); +static int tsdbInitCompactH(SCompactH *pComph, STsdbRepo *pRepo); +static void tsdbDestroyCompactH(SCompactH *pComph); +static int tsdbInitCompTbArray(SCompactH *pComph); +static void tsdbDestroyCompTbArray(SCompactH *pComph); +static int tsdbCacheFSetIndex(SCompactH *pComph); +static int tsdbCompactFSetInit(SCompactH *pComph, SDFileSet *pSet); +static void tsdbCompactFSetEnd(SCompactH *pComph); +static int tsdbCompactFSetImpl(SCompactH *pComph); +static int tsdbWriteBlockToRightFile(SCompactH *pComph, STable *pTable, SDataCols *pDataCols, void **ppBuf, + void **ppCBuf); + +int tsdbCompact(STsdbRepo *pRepo) { return tsdbAsyncCompact(pRepo); } + +void *tsdbCompactImpl(STsdbRepo *pRepo) { + // Check if there are files in TSDB FS to compact + if (REPO_FS(pRepo)->cstatus->pmf == NULL) { + tsdbInfo("vgId:%d no file to compact in FS", REPO_ID(pRepo)); + return NULL; + } + + tsdbStartCompact(pRepo); + + if (tsdbCompactMeta(pRepo) < 0) { + tsdbError("vgId:%d failed to compact META data since %s", REPO_ID(pRepo), tstrerror(terrno)); + goto _err; + } + + if (tsdbCompactTSData(pRepo) < 0) { + tsdbError("vgId:%d failed to compact TS data since %s", REPO_ID(pRepo), tstrerror(terrno)); + goto _err; + } + + tsdbEndCompact(pRepo, TSDB_CODE_SUCCESS); + return NULL; + +_err: + pRepo->code = terrno; + tsdbEndCompact(pRepo, terrno); + return NULL; +} + +static int tsdbAsyncCompact(STsdbRepo *pRepo) { + tsem_wait(&(pRepo->readyToCommit)); + return tsdbScheduleCommit(pRepo, COMPACT_REQ); +} + +static void tsdbStartCompact(STsdbRepo *pRepo) { + ASSERT(!pRepo->inCompact); + tsdbInfo("vgId:%d start to compact!", REPO_ID(pRepo)); + tsdbStartFSTxn(pRepo, 0, 0); + pRepo->code = TSDB_CODE_SUCCESS; + pRepo->inCompact = true; +} + +static void tsdbEndCompact(STsdbRepo *pRepo, int eno) { + if (eno != TSDB_CODE_SUCCESS) { + tsdbEndFSTxnWithError(REPO_FS(pRepo)); + } else { + tsdbEndFSTxn(pRepo); + } + pRepo->inCompact = false; + tsdbInfo("vgId:%d compact over, %s", REPO_ID(pRepo), (eno == TSDB_CODE_SUCCESS) ? "succeed" : "failed"); + tsem_post(&(pRepo->readyToCommit)); +} + +static int tsdbCompactMeta(STsdbRepo *pRepo) { + STsdbFS *pfs = REPO_FS(pRepo); + tsdbUpdateMFile(pfs, pfs->cstatus->pmf); + return 0; +} + +static int tsdbCompactTSData(STsdbRepo *pRepo) { + SCompactH compactH; + SDFileSet *pSet = NULL; + + tsdbDebug("vgId:%d start to compact TS data", REPO_ID(pRepo)); + + // If no file, just return 0; + if (taosArrayGetSize(REPO_FS(pRepo)->cstatus->df) <= 0) { + tsdbDebug("vgId:%d no TS data file to compact, compact over", REPO_ID(pRepo)); + return 0; + } + + if (tsdbInitCompactH(&compactH, pRepo) < 0) { + return -1; + } + + while ((pSet = tsdbFSIterNext(&(compactH.fsIter)))) { + // Remove those expired files + if (pSet->fid < compactH.rtn.minFid) { + tsdbInfo("vgId:%d FSET %d on level %d disk id %d expires, remove it", REPO_ID(pRepo), pSet->fid, + TSDB_FSET_LEVEL(pSet), TSDB_FSET_ID(pSet)); + continue; + } + + if (TSDB_FSET_LEVEL(pSet) == TFS_MAX_LEVEL) { + tsdbDebug("vgId:%d FSET %d on level %d, should not compact", REPO_ID(pRepo), pSet->fid, TFS_MAX_LEVEL); + tsdbUpdateDFileSet(REPO_FS(pRepo), pSet); + continue; + } + + if (tsdbCompactFSet(&compactH, pSet) < 0) { + tsdbDestroyCompactH(&compactH); + tsdbError("vgId:%d failed to compact FSET %d since %s", REPO_ID(pRepo), pSet->fid, tstrerror(terrno)); + return -1; + } + } + + tsdbDestroyCompactH(&compactH); + tsdbDebug("vgId:%d compact TS data over", REPO_ID(pRepo)); + return 0; +} + +static int tsdbCompactFSet(SCompactH *pComph, SDFileSet *pSet) { + STsdbRepo *pRepo = TSDB_COMPACT_REPO(pComph); + SDiskID did; + + tsdbDebug("vgId:%d start to compact FSET %d on level %d id %d", REPO_ID(pRepo), pSet->fid, TSDB_FSET_LEVEL(pSet), + TSDB_FSET_ID(pSet)); + + if (tsdbCompactFSetInit(pComph, pSet) < 0) { + return -1; + } + + if (!tsdbShouldCompact(pComph)) { + tsdbDebug("vgId:%d no need to compact FSET %d", REPO_ID(pRepo), pSet->fid); + if (tsdbApplyRtnOnFSet(TSDB_COMPACT_REPO(pComph), pSet, &(pComph->rtn)) < 0) { + tsdbCompactFSetEnd(pComph); + return -1; + } + } else { + // Create new fset as compacted fset + tfsAllocDisk(tsdbGetFidLevel(pSet->fid, &(pComph->rtn)), &(did.level), &(did.id)); + if (did.level == TFS_UNDECIDED_LEVEL) { + terrno = TSDB_CODE_TDB_NO_AVAIL_DISK; + tsdbError("vgId:%d failed to compact FSET %d since %s", REPO_ID(pRepo), pSet->fid, tstrerror(terrno)); + tsdbCompactFSetEnd(pComph); + return -1; + } + + tsdbInitDFileSet(TSDB_COMPACT_WSET(pComph), did, REPO_ID(pRepo), TSDB_FSET_FID(pSet), + FS_TXN_VERSION(REPO_FS(pRepo))); + if (tsdbCreateDFileSet(TSDB_COMPACT_WSET(pComph), true) < 0) { + tsdbError("vgId:%d failed to compact FSET %d since %s", REPO_ID(pRepo), pSet->fid, tstrerror(terrno)); + tsdbCompactFSetEnd(pComph); + return -1; + } + + if (tsdbCompactFSetImpl(pComph) < 0) { + tsdbCloseDFileSet(TSDB_COMPACT_WSET(pComph)); + tsdbRemoveDFileSet(TSDB_COMPACT_WSET(pComph)); + tsdbCompactFSetEnd(pComph); + return -1; + } + + tsdbCloseDFileSet(TSDB_COMPACT_WSET(pComph)); + tsdbUpdateDFileSet(REPO_FS(pRepo), TSDB_COMPACT_WSET(pComph)); + tsdbDebug("vgId:%d FSET %d compact over", REPO_ID(pRepo), pSet->fid); + } + + tsdbCompactFSetEnd(pComph); + return 0; +} + +static bool tsdbShouldCompact(SCompactH *pComph) { + STsdbRepo * pRepo = TSDB_COMPACT_REPO(pComph); + STsdbCfg * pCfg = REPO_CFG(pRepo); + SReadH * pReadh = &(pComph->readh); + STableCompactH *pTh; + SBlock * pBlock; + int defaultRows = TSDB_DEFAULT_BLOCK_ROWS(pCfg->maxRowsPerFileBlock); + SDFile * pDataF = TSDB_READ_DATA_FILE(pReadh); + SDFile * pLastF = TSDB_READ_LAST_FILE(pReadh); + + int tblocks = 0; // total blocks + int nSubBlocks = 0; // # of blocks with sub-blocks + int nSmallBlocks = 0; // # of blocks with rows < defaultRows + int64_t tsize = 0; + + for (size_t i = 0; i < taosArrayGetSize(pComph->tbArray); i++) { + pTh = (STableCompactH *)taosArrayGet(pComph->tbArray, i); + + if (pTh->pTable == NULL || pTh->pBlkIdx == NULL) continue; + + for (size_t bidx = 0; bidx < pTh->pBlkIdx->numOfBlocks; bidx++) { + tblocks++; + pBlock = pTh->pInfo->blocks + bidx; + + if (pBlock->numOfRows < defaultRows) { + nSmallBlocks++; + } + + if (pBlock->numOfSubBlocks > 1) { + nSubBlocks++; + for (int k = 0; k < pBlock->numOfSubBlocks; k++) { + SBlock *iBlock = ((SBlock *)POINTER_SHIFT(pTh->pInfo, pBlock->offset)) + k; + tsize = tsize + iBlock->len; + } + } else if (pBlock->numOfSubBlocks == 1) { + tsize += pBlock->len; + } else { + ASSERT(0); + } + } + } + + return (((nSubBlocks * 1.0 / tblocks) > 0.33) || ((nSmallBlocks * 1.0 / tblocks) > 0.33) || + (tsize * 1.0 / (pDataF->info.size + pLastF->info.size - 2 * TSDB_FILE_HEAD_SIZE) < 0.85)); +} + +static int tsdbInitCompactH(SCompactH *pComph, STsdbRepo *pRepo) { + STsdbCfg *pCfg = REPO_CFG(pRepo); + + memset(pComph, 0, sizeof(*pComph)); + + TSDB_FSET_SET_CLOSED(TSDB_COMPACT_WSET(pComph)); + + tsdbGetRtnSnap(pRepo, &(pComph->rtn)); + tsdbFSIterInit(&(pComph->fsIter), REPO_FS(pRepo), TSDB_FS_ITER_FORWARD); + + if (tsdbInitReadH(&(pComph->readh), pRepo) < 0) { + return -1; + } + + if (tsdbInitCompTbArray(pComph) < 0) { + tsdbDestroyCompactH(pComph); + return -1; + } + + pComph->aBlkIdx = taosArrayInit(1024, sizeof(SBlockIdx)); + if (pComph->aBlkIdx == NULL) { + terrno = TSDB_CODE_TDB_OUT_OF_MEMORY; + tsdbDestroyCompactH(pComph); + return -1; + } + + pComph->aSupBlk = taosArrayInit(1024, sizeof(SBlock)); + if (pComph->aSupBlk == NULL) { + terrno = TSDB_CODE_TDB_OUT_OF_MEMORY; + tsdbDestroyCompactH(pComph); + return -1; + } + + pComph->pDataCols = tdNewDataCols(0, 0, pCfg->maxRowsPerFileBlock); + if (pComph->pDataCols == NULL) { + terrno = TSDB_CODE_TDB_OUT_OF_MEMORY; + tsdbDestroyCompactH(pComph); + return -1; + } + + return 0; +} + +static void tsdbDestroyCompactH(SCompactH *pComph) { + pComph->pDataCols = tdFreeDataCols(pComph->pDataCols); + pComph->aSupBlk = taosArrayDestroy(pComph->aSupBlk); + pComph->aBlkIdx = taosArrayDestroy(pComph->aBlkIdx); + tsdbDestroyCompTbArray(pComph); + tsdbDestroyReadH(&(pComph->readh)); + tsdbCloseDFileSet(TSDB_COMPACT_WSET(pComph)); +} + +static int tsdbInitCompTbArray(SCompactH *pComph) { // Init pComp->tbArray + STsdbRepo *pRepo = TSDB_COMPACT_REPO(pComph); + STsdbMeta *pMeta = pRepo->tsdbMeta; + + if (tsdbRLockRepoMeta(pRepo) < 0) return -1; + + pComph->tbArray = taosArrayInit(pMeta->maxTables, sizeof(STableCompactH)); + if (pComph->tbArray == NULL) { + terrno = TSDB_CODE_TDB_OUT_OF_MEMORY; + tsdbUnlockRepoMeta(pRepo); + return -1; + } + + // Note here must start from 0 + for (int i = 0; i < pMeta->maxTables; i++) { + STableCompactH ch = {0}; + if (pMeta->tables[i] != NULL) { + tsdbRefTable(pMeta->tables[i]); + ch.pTable = pMeta->tables[i]; + } + + if (taosArrayPush(pComph->tbArray, &ch) == NULL) { + terrno = TSDB_CODE_TDB_OUT_OF_MEMORY; + tsdbUnlockRepoMeta(pRepo); + return -1; + } + } + + if (tsdbUnlockRepoMeta(pRepo) < 0) return -1; + return 0; +} + +static void tsdbDestroyCompTbArray(SCompactH *pComph) { + STableCompactH *pTh; + + if (pComph->tbArray == NULL) return; + + for (size_t i = 0; i < taosArrayGetSize(pComph->tbArray); i++) { + pTh = (STableCompactH *)taosArrayGet(pComph->tbArray, i); + if (pTh->pTable) { + tsdbUnRefTable(pTh->pTable); + } + + pTh->pInfo = taosTZfree(pTh->pInfo); + } + + pComph->tbArray = taosArrayDestroy(pComph->tbArray); +} + +static int tsdbCacheFSetIndex(SCompactH *pComph) { + SReadH *pReadH = &(pComph->readh); + + if (tsdbLoadBlockIdx(pReadH) < 0) { + return -1; + } + + for (int tid = 1; tid < taosArrayGetSize(pComph->tbArray); tid++) { + STableCompactH *pTh = (STableCompactH *)taosArrayGet(pComph->tbArray, tid); + pTh->pBlkIdx = NULL; + + if (pTh->pTable == NULL) continue; + if (tsdbSetReadTable(pReadH, pTh->pTable) < 0) { + return -1; + } + + if (pReadH->pBlkIdx == NULL) continue; + pTh->bindex = *(pReadH->pBlkIdx); + pTh->pBlkIdx = &(pTh->bindex); + + if (tsdbMakeRoom((void **)(&(pTh->pInfo)), pTh->pBlkIdx->len) < 0) { + return -1; + } + + if (tsdbLoadBlockInfo(pReadH, (void *)(pTh->pInfo)) < 0) { + return -1; + } + } + + return 0; +} + +static int tsdbCompactFSetInit(SCompactH *pComph, SDFileSet *pSet) { + taosArrayClear(pComph->aBlkIdx); + taosArrayClear(pComph->aSupBlk); + + if (tsdbSetAndOpenReadFSet(&(pComph->readh), pSet) < 0) { + return -1; + } + + if (tsdbCacheFSetIndex(pComph) < 0) { + tsdbCloseAndUnsetFSet(&(pComph->readh)); + return -1; + } + + return 0; +} + +static void tsdbCompactFSetEnd(SCompactH *pComph) { tsdbCloseAndUnsetFSet(&(pComph->readh)); } + +static int tsdbCompactFSetImpl(SCompactH *pComph) { + STsdbRepo *pRepo = TSDB_COMPACT_REPO(pComph); + STsdbCfg * pCfg = REPO_CFG(pRepo); + SReadH * pReadh = &(pComph->readh); + SBlockIdx blkIdx; + void ** ppBuf = &(TSDB_COMPACT_BUF(pComph)); + void ** ppCBuf = &(TSDB_COMPACT_COMP_BUF(pComph)); + int defaultRows = TSDB_DEFAULT_BLOCK_ROWS(pCfg->maxRowsPerFileBlock); + + taosArrayClear(pComph->aBlkIdx); + + for (int tid = 1; tid < taosArrayGetSize(pComph->tbArray); tid++) { + STableCompactH *pTh = (STableCompactH *)taosArrayGet(pComph->tbArray, tid); + STSchema * pSchema; + + if (pTh->pTable == NULL || pTh->pBlkIdx == NULL) continue; + + pSchema = tsdbGetTableSchemaImpl(pTh->pTable, true, true, -1); + taosArrayClear(pComph->aSupBlk); + if ((tdInitDataCols(pComph->pDataCols, pSchema) < 0) || (tdInitDataCols(pReadh->pDCols[0], pSchema) < 0) || + (tdInitDataCols(pReadh->pDCols[1], pSchema) < 0)) { + terrno = TSDB_CODE_TDB_OUT_OF_MEMORY; + return -1; + } + tdFreeSchema(pSchema); + + // Loop to compact each block data + for (int i = 0; i < pTh->pBlkIdx->numOfBlocks; i++) { + SBlock *pBlock = pTh->pInfo->blocks + i; + + // Load the block data + if (tsdbLoadBlockData(pReadh, pBlock, pTh->pInfo) < 0) { + return -1; + } + + // Merge pComph->pDataCols and pReadh->pDCols[0] and write data to file + if (pComph->pDataCols->numOfRows == 0 && pBlock->numOfRows >= defaultRows) { + if (tsdbWriteBlockToRightFile(pComph, pTh->pTable, pReadh->pDCols[0], ppBuf, ppCBuf) < 0) { + return -1; + } + } else { + int ridx = 0; + + while (true) { + if (pReadh->pDCols[0]->numOfRows - ridx == 0) break; + int rowsToMerge = MIN(pReadh->pDCols[0]->numOfRows - ridx, defaultRows - pComph->pDataCols->numOfRows); + + tdMergeDataCols(pComph->pDataCols, pReadh->pDCols[0], rowsToMerge, &ridx); + + if (pComph->pDataCols->numOfRows < defaultRows) { + break; + } + + if (tsdbWriteBlockToRightFile(pComph, pTh->pTable, pComph->pDataCols, ppBuf, ppCBuf) < 0) { + return -1; + } + tdResetDataCols(pComph->pDataCols); + } + } + } + + if (pComph->pDataCols->numOfRows > 0 && + tsdbWriteBlockToRightFile(pComph, pTh->pTable, pComph->pDataCols, ppBuf, ppCBuf) < 0) { + return -1; + } + + if (tsdbWriteBlockInfoImpl(TSDB_COMPACT_HEAD_FILE(pComph), pTh->pTable, pComph->aSupBlk, NULL, ppBuf, &blkIdx) < + 0) { + return -1; + } + + if ((blkIdx.numOfBlocks > 0) && (taosArrayPush(pComph->aBlkIdx, (void *)(&blkIdx)) == NULL)) { + terrno = TSDB_CODE_TDB_OUT_OF_MEMORY; + return -1; + } + } + + if (tsdbWriteBlockIdx(TSDB_COMPACT_HEAD_FILE(pComph), pComph->aBlkIdx, ppBuf) < 0) { + return -1; + } + + return 0; +} + +static int tsdbWriteBlockToRightFile(SCompactH *pComph, STable *pTable, SDataCols *pDataCols, void **ppBuf, + void **ppCBuf) { + STsdbRepo *pRepo = TSDB_COMPACT_REPO(pComph); + STsdbCfg * pCfg = REPO_CFG(pRepo); + SDFile * pDFile; + bool isLast; + SBlock block; + + ASSERT(pDataCols->numOfRows > 0); + + if (pDataCols->numOfRows < pCfg->minRowsPerFileBlock) { + pDFile = TSDB_COMPACT_LAST_FILE(pComph); + isLast = true; + } else { + pDFile = TSDB_COMPACT_DATA_FILE(pComph); + isLast = false; + } + + if (tsdbWriteBlockImpl(pRepo, pTable, pDFile, pDataCols, &block, isLast, true, ppBuf, ppCBuf) < 0) { + return -1; + } + + if (taosArrayPush(pComph->aSupBlk, (void *)(&block)) == NULL) { + terrno = TSDB_CODE_TDB_OUT_OF_MEMORY; + return -1; + } + + return 0; +} #endif diff --git a/src/tsdb/src/tsdbMain.c b/src/tsdb/src/tsdbMain.c index afbedd5b2fd231606902db104916e4ff4f10ba67..0cbabb8909814bc15e949f224cab4e21e2427660 100644 --- a/src/tsdb/src/tsdbMain.c +++ b/src/tsdb/src/tsdbMain.c @@ -195,6 +195,8 @@ STsdbRepoInfo *tsdbGetStatus(STsdbRepo *pRepo) { return NULL; } int tsdbGetState(STsdbRepo *repo) { return repo->state; } +bool tsdbInCompact(STsdbRepo *repo) { return repo->inCompact; } + void tsdbReportStat(void *repo, int64_t *totalPoints, int64_t *totalStorage, int64_t *compStorage) { ASSERT(repo != NULL); STsdbRepo *pRepo = repo; @@ -270,8 +272,8 @@ int32_t tsdbConfigRepo(STsdbRepo *repo, STsdbCfg *pCfg) { pthread_mutex_unlock(&repo->save_mutex); - // schedule a commit msg then the new config will be applied immediatly - tsdbAsyncCommit(repo); + // schedule a commit msg and wait for the new config applied + tsdbSyncCommitConfig(repo); return 0; #if 0 @@ -533,6 +535,7 @@ static STsdbRepo *tsdbNewRepo(STsdbCfg *pCfg, STsdbAppH *pAppH) { pRepo->state = TSDB_STATE_OK; pRepo->code = TSDB_CODE_SUCCESS; + pRepo->inCompact = false; pRepo->config = *pCfg; if (pAppH) { pRepo->appH = *pAppH; @@ -553,7 +556,6 @@ static STsdbRepo *tsdbNewRepo(STsdbCfg *pCfg, STsdbAppH *pAppH) { return NULL; } pRepo->config_changed = false; - atomic_store_8(&pRepo->hasCachedLastRow, 0); atomic_store_8(&pRepo->hasCachedLastColumn, 0); code = tsem_init(&(pRepo->readyToCommit), 0, 1); @@ -857,9 +859,7 @@ int tsdbRestoreInfo(STsdbRepo *pRepo) { } tsdbDestroyReadH(&readh); - if (CACHE_LAST_ROW(pCfg)) { - atomic_store_8(&pRepo->hasCachedLastRow, 1); - } + if (CACHE_LAST_NULL_COLUMN(pCfg)) { atomic_store_8(&pRepo->hasCachedLastColumn, 1); } @@ -900,20 +900,16 @@ int tsdbCacheLastData(STsdbRepo *pRepo, STsdbCfg* oldCfg) { // if close last option,need to free data if (need_free_last_row || need_free_last_col) { - if (need_free_last_row) { - atomic_store_8(&pRepo->hasCachedLastRow, 0); - } if (need_free_last_col) { atomic_store_8(&pRepo->hasCachedLastColumn, 0); } tsdbInfo("free cache last data since cacheLast option changed"); - for (int i = 1; i < maxTableIdx; i++) { + for (int i = 1; i <= maxTableIdx; i++) { STable *pTable = pMeta->tables[i]; if (pTable == NULL) continue; if (need_free_last_row) { taosTZfree(pTable->lastRow); pTable->lastRow = NULL; - pTable->lastKey = TSKEY_INITIAL_VAL; } if (need_free_last_col) { tsdbFreeLastColumns(pTable); @@ -983,9 +979,6 @@ int tsdbCacheLastData(STsdbRepo *pRepo, STsdbCfg* oldCfg) { tsdbDestroyReadH(&readh); - if (cacheLastRow) { - atomic_store_8(&pRepo->hasCachedLastRow, 1); - } if (cacheLastCol) { atomic_store_8(&pRepo->hasCachedLastColumn, 1); } diff --git a/src/tsdb/src/tsdbMemTable.c b/src/tsdb/src/tsdbMemTable.c index bee5600af730cda0d51c10dc969b070f7cd0252e..9d8b1ca7f2889f40b696f04a608dd166adf6eac6 100644 --- a/src/tsdb/src/tsdbMemTable.c +++ b/src/tsdb/src/tsdbMemTable.c @@ -271,10 +271,34 @@ void *tsdbAllocBytes(STsdbRepo *pRepo, int bytes) { return ptr; } +int tsdbSyncCommitConfig(STsdbRepo* pRepo) { + ASSERT(pRepo->config_changed == true); + tsem_wait(&(pRepo->readyToCommit)); + + if (pRepo->code != TSDB_CODE_SUCCESS) { + tsdbWarn("vgId:%d try to commit config when TSDB not in good state: %s", REPO_ID(pRepo), tstrerror(terrno)); + } + + if (tsdbLockRepo(pRepo) < 0) return -1; + tsdbScheduleCommit(pRepo, COMMIT_CONFIG_REQ); + if (tsdbUnlockRepo(pRepo) < 0) return -1; + + tsem_wait(&(pRepo->readyToCommit)); + tsem_post(&(pRepo->readyToCommit)); + + if (pRepo->code != TSDB_CODE_SUCCESS) { + terrno = pRepo->code; + return -1; + } + + terrno = TSDB_CODE_SUCCESS; + return 0; +} + int tsdbAsyncCommit(STsdbRepo *pRepo) { tsem_wait(&(pRepo->readyToCommit)); - //ASSERT(pRepo->imem == NULL); + ASSERT(pRepo->imem == NULL); if (pRepo->mem == NULL) { tsem_post(&(pRepo->readyToCommit)); return 0; @@ -1015,7 +1039,6 @@ static int tsdbUpdateTableLatestInfo(STsdbRepo *pRepo, STable *pTable, SDataRow taosTZfree(pTable->lastRow); TSDB_WLOCK_TABLE(pTable); pTable->lastRow = NULL; - pTable->lastKey = TSKEY_INITIAL_VAL; TSDB_WUNLOCK_TABLE(pTable); } diff --git a/src/tsdb/src/tsdbRead.c b/src/tsdb/src/tsdbRead.c index 1545d44395d6baca6f33c850e35796c96af8d52f..972c3c4e10c163c4c5b66d3390200b97f207e0a0 100644 --- a/src/tsdb/src/tsdbRead.c +++ b/src/tsdb/src/tsdbRead.c @@ -218,11 +218,6 @@ static void tsdbMayUnTakeMemSnapshot(STsdbQueryHandle* pQueryHandle) { int64_t tsdbGetNumOfRowsInMemTable(TsdbQueryHandleT* pHandle) { STsdbQueryHandle* pQueryHandle = (STsdbQueryHandle*) pHandle; - size_t size = taosArrayGetSize(pQueryHandle->pTableCheckInfo); - assert(pQueryHandle->activeIndex < size && pQueryHandle->activeIndex >= 0 && size >= 1); - STableCheckInfo* pCheckInfo = taosArrayGet(pQueryHandle->pTableCheckInfo, pQueryHandle->activeIndex); - - int64_t rows = 0; SMemRef* pMemRef = pQueryHandle->pMemRef; if (pMemRef == NULL) { return rows; } @@ -233,15 +228,19 @@ int64_t tsdbGetNumOfRowsInMemTable(TsdbQueryHandleT* pHandle) { SMemTable* pMemT = pMemRef->snapshot.mem; SMemTable* pIMemT = pMemRef->snapshot.imem; - if (pMemT && pCheckInfo->tableId.tid < pMemT->maxTables) { - pMem = pMemT->tData[pCheckInfo->tableId.tid]; - rows += (pMem && pMem->uid == pCheckInfo->tableId.uid) ? pMem->numOfRows: 0; - } - if (pIMemT && pCheckInfo->tableId.tid < pIMemT->maxTables) { - pIMem = pIMemT->tData[pCheckInfo->tableId.tid]; - rows += (pIMem && pIMem->uid == pCheckInfo->tableId.uid) ? pIMem->numOfRows: 0; + size_t size = taosArrayGetSize(pQueryHandle->pTableCheckInfo); + for (int32_t i = 0; i < size; ++i) { + STableCheckInfo* pCheckInfo = taosArrayGet(pQueryHandle->pTableCheckInfo, i); + + if (pMemT && pCheckInfo->tableId.tid < pMemT->maxTables) { + pMem = pMemT->tData[pCheckInfo->tableId.tid]; + rows += (pMem && pMem->uid == pCheckInfo->tableId.uid) ? pMem->numOfRows : 0; + } + if (pIMemT && pCheckInfo->tableId.tid < pIMemT->maxTables) { + pIMem = pIMemT->tData[pCheckInfo->tableId.tid]; + rows += (pIMem && pIMem->uid == pCheckInfo->tableId.uid) ? pIMem->numOfRows : 0; + } } - return rows; } @@ -1088,7 +1087,11 @@ static int32_t handleDataMergeIfNeeded(STsdbQueryHandle* pQueryHandle, SBlock* p assert(cur->pos >= 0 && cur->pos <= binfo.rows); TSKEY key = (row != NULL)? dataRowKey(row):TSKEY_INITIAL_VAL; - tsdbDebug("%p key in mem:%"PRId64", 0x%"PRIx64, pQueryHandle, key, pQueryHandle->qId); + if (key != TSKEY_INITIAL_VAL) { + tsdbDebug("%p key in mem:%"PRId64", 0x%"PRIx64, pQueryHandle, key, pQueryHandle->qId); + } else { + tsdbDebug("%p no data in mem, 0x%"PRIx64, pQueryHandle, pQueryHandle->qId); + } if ((ASCENDING_TRAVERSE(pQueryHandle->order) && (key != TSKEY_INITIAL_VAL && key <= binfo.window.ekey)) || (!ASCENDING_TRAVERSE(pQueryHandle->order) && (key != TSKEY_INITIAL_VAL && key >= binfo.window.skey))) { @@ -1152,8 +1155,14 @@ static int32_t handleDataMergeIfNeeded(STsdbQueryHandle* pQueryHandle, SBlock* p } assert(cur->blockCompleted); - tsdbDebug("create data block from remain file block, brange:%"PRId64"-%"PRId64", rows:%d, lastKey:%"PRId64", %p", - cur->win.skey, cur->win.ekey, cur->rows, cur->lastKey, pQueryHandle); + if (cur->rows == binfo.rows) { + tsdbDebug("%p whole file block qualified, brange:%"PRId64"-%"PRId64", rows:%d, lastKey:%"PRId64", %"PRIx64, + pQueryHandle, cur->win.skey, cur->win.ekey, cur->rows, cur->lastKey, pQueryHandle->qId); + } else { + tsdbDebug("%p create data block from remain file block, brange:%"PRId64"-%"PRId64", rows:%d, total:%d, lastKey:%"PRId64", %"PRIx64, + pQueryHandle, cur->win.skey, cur->win.ekey, cur->rows, binfo.rows, cur->lastKey, pQueryHandle->qId); + } + } return code; @@ -2397,6 +2406,8 @@ static void destroyHelper(void* param) { tQueryInfo* pInfo = (tQueryInfo*)param; if (pInfo->optr != TSDB_RELATION_IN) { tfree(pInfo->q); + } else { + taosHashCleanup((SHashObj *)(pInfo->q)); } free(param); @@ -2469,7 +2480,6 @@ static bool loadCachedLastRow(STsdbQueryHandle* pQueryHandle) { if (ret != TSDB_CODE_SUCCESS) { return false; } - copyOneRowFromMem(pQueryHandle, pQueryHandle->outputCapacity, 0, pRow, numOfCols, pCheckInfo->pTableObj, NULL); tfree(pRow); @@ -2860,24 +2870,29 @@ bool tsdbGetExternalRow(TsdbQueryHandleT pHandle) { } /* - * 1. no data at all (pTable->lastKey = TSKEY_INITIAL_VAL), just return TSKEY_INITIAL_VAL - * 2. has data but not loaded, just return lastKey but not set pRes - * 3. has data and loaded, return lastKey and set pRes + * if lastRow == NULL, return TSDB_CODE_TDB_NO_CACHE_LAST_ROW + * else set pRes and return TSDB_CODE_SUCCESS and save lastKey */ int32_t tsdbGetCachedLastRow(STable* pTable, SDataRow* pRes, TSKEY* lastKey) { + int32_t code = TSDB_CODE_SUCCESS; + TSDB_RLOCK_TABLE(pTable); - *lastKey = pTable->lastKey; - if ((*lastKey) != TSKEY_INITIAL_VAL && pTable->lastRow) { + if (!pTable->lastRow) { + code = TSDB_CODE_TDB_NO_CACHE_LAST_ROW; + goto out; + } + + if (pRes) { *pRes = tdDataRowDup(pTable->lastRow); if (*pRes == NULL) { - TSDB_RUNLOCK_TABLE(pTable); - return TSDB_CODE_TDB_OUT_OF_MEMORY; + code = TSDB_CODE_TDB_OUT_OF_MEMORY; } } +out: TSDB_RUNLOCK_TABLE(pTable); - return TSDB_CODE_SUCCESS; + return code; } bool isTsdbCacheLastRow(TsdbQueryHandleT* pQueryHandle) { @@ -2887,7 +2902,6 @@ bool isTsdbCacheLastRow(TsdbQueryHandleT* pQueryHandle) { int32_t checkForCachedLastRow(STsdbQueryHandle* pQueryHandle, STableGroupInfo *groupList) { assert(pQueryHandle != NULL && groupList != NULL); - SDataRow pRow = NULL; TSKEY key = TSKEY_INITIAL_VAL; SArray* group = taosArrayGetP(groupList->pGroupList, 0); @@ -2898,7 +2912,7 @@ int32_t checkForCachedLastRow(STsdbQueryHandle* pQueryHandle, STableGroupInfo *g int32_t code = 0; if (((STable*)pInfo->pTable)->lastRow) { - code = tsdbGetCachedLastRow(pInfo->pTable, &pRow, &key); + code = tsdbGetCachedLastRow(pInfo->pTable, NULL, &key); if (code != TSDB_CODE_SUCCESS) { pQueryHandle->cachelastrow = 0; } else { @@ -2913,7 +2927,6 @@ int32_t checkForCachedLastRow(STsdbQueryHandle* pQueryHandle, STableGroupInfo *g pQueryHandle->activeIndex = -1; // start from -1 } - tfree(pRow); return code; } @@ -3153,11 +3166,23 @@ void filterPrepare(void* expr, void* param) { pInfo->sch = *pSchema; pInfo->optr = pExpr->_node.optr; - pInfo->compare = getComparFunc(pSchema->type, pInfo->optr); + pInfo->compare = getComparFunc(pInfo->sch.type, pInfo->optr); pInfo->indexed = pTSSchema->columns->colId == pInfo->sch.colId; if (pInfo->optr == TSDB_RELATION_IN) { - pInfo->q = (char*) pCond->arr; + int dummy = -1; + SHashObj *pObj = NULL; + if (pInfo->sch.colId == TSDB_TBNAME_COLUMN_INDEX) { + pObj = taosHashInit(256, taosGetDefaultHashFunction(pInfo->sch.type), true, false); + SArray *arr = (SArray *)(pCond->arr); + for (size_t i = 0; i < taosArrayGetSize(arr); i++) { + char* p = taosArrayGetP(arr, i); + taosHashPut(pObj, varDataVal(p),varDataLen(p), &dummy, sizeof(dummy)); + } + } else { + buildFilterSetFromBinary((void **)&pObj, pCond->pz, pCond->nLen); + } + pInfo->q = (char *)pObj; } else if (pCond != NULL) { uint32_t size = pCond->nLen * TSDB_NCHAR_SIZE; if (size < (uint32_t)pSchema->bytes) { @@ -3328,6 +3353,20 @@ static bool tableFilterFp(const void* pNode, void* param) { } else if (pInfo->optr == TSDB_RELATION_NOTNULL) { return (val != NULL) && (!isNull(val, pInfo->sch.type)); } + } else if (pInfo->optr == TSDB_RELATION_IN) { + int type = pInfo->sch.type; + if (type == TSDB_DATA_TYPE_BOOL || type == TSDB_DATA_TYPE_TINYINT || type == TSDB_DATA_TYPE_SMALLINT || type == TSDB_DATA_TYPE_BIGINT || type == TSDB_DATA_TYPE_INT) { + int64_t v; + GET_TYPED_DATA(v, int64_t, pInfo->sch.type, val); + return NULL != taosHashGet((SHashObj *)pInfo->q, (char *)&v, sizeof(v)); + } else if (type == TSDB_DATA_TYPE_DOUBLE || type == TSDB_DATA_TYPE_DOUBLE) { + double v; + GET_TYPED_DATA(v, double, pInfo->sch.type, val); + return NULL != taosHashGet((SHashObj *)pInfo->q, (char *)&v, sizeof(v)); + } else if (type == TSDB_DATA_TYPE_BINARY || type == TSDB_DATA_TYPE_NCHAR){ + return NULL != taosHashGet((SHashObj *)pInfo->q, varDataVal(val), varDataLen(val)); + } + } int32_t ret = 0; @@ -3533,6 +3572,9 @@ int32_t tsdbGetTableGroupFromIdList(STsdbRepo* tsdb, SArray* pTableIdList, STabl if (pTable->type == TSDB_SUPER_TABLE) { tsdbError("direct query on super tale is not allowed, table uid:%"PRIu64", tid:%d", id->uid, id->tid); terrno = TSDB_CODE_QRY_INVALID_MSG; + tsdbUnlockRepoMeta(tsdb); + taosArrayDestroy(group); + return terrno; } tsdbRefTable(pTable); @@ -3670,14 +3712,18 @@ static int32_t setQueryCond(tQueryInfo *queryColInfo, SQueryCond* pCond) { if (optr == TSDB_RELATION_GREATER || optr == TSDB_RELATION_GREATER_EQUAL || optr == TSDB_RELATION_EQUAL || optr == TSDB_RELATION_NOT_EQUAL) { - pCond->start = calloc(1, sizeof(SEndPoint)); + pCond->start = calloc(1, sizeof(SEndPoint)); pCond->start->optr = queryColInfo->optr; - pCond->start->v = queryColInfo->q; + pCond->start->v = queryColInfo->q; } else if (optr == TSDB_RELATION_LESS || optr == TSDB_RELATION_LESS_EQUAL) { - pCond->end = calloc(1, sizeof(SEndPoint)); + pCond->end = calloc(1, sizeof(SEndPoint)); pCond->end->optr = queryColInfo->optr; - pCond->end->v = queryColInfo->q; - } else if (optr == TSDB_RELATION_IN || optr == TSDB_RELATION_LIKE) { + pCond->end->v = queryColInfo->q; + } else if (optr == TSDB_RELATION_IN) { + pCond->start = calloc(1, sizeof(SEndPoint)); + pCond->start->optr = queryColInfo->optr; + pCond->start->v = queryColInfo->q; + } else if (optr == TSDB_RELATION_LIKE) { assert(0); } @@ -3762,6 +3808,19 @@ static void queryIndexedColumn(SSkipList* pSkipList, tQueryInfo* pQueryInfo, SAr taosArrayPush(result, &info); } + } else if (optr == TSDB_RELATION_IN) { + while(tSkipListIterNext(iter)) { + SSkipListNode* pNode = tSkipListIterGet(iter); + + int32_t ret = pQueryInfo->compare(SL_GET_NODE_KEY(pSkipList, pNode), cond.start->v); + if (ret != 0) { + break; + } + + STableKeyInfo info = {.pTable = (void*)SL_GET_NODE_DATA(pNode), .lastKey = TSKEY_INITIAL_VAL}; + taosArrayPush(result, &info); + } + } else { assert(0); } @@ -3855,7 +3914,7 @@ void getTableListfromSkipList(tExprNode *pExpr, SSkipList *pSkipList, SArray *re param->setupInfoFn(pExpr, param->pExtInfo); tQueryInfo *pQueryInfo = pExpr->_node.info; - if (pQueryInfo->indexed && pQueryInfo->optr != TSDB_RELATION_LIKE) { + if (pQueryInfo->indexed && (pQueryInfo->optr != TSDB_RELATION_LIKE && pQueryInfo->optr != TSDB_RELATION_IN)) { queryIndexedColumn(pSkipList, pQueryInfo, result); } else { queryIndexlessColumn(pSkipList, pQueryInfo, result, param->nodeFilterFn); diff --git a/src/util/inc/tutil.h b/src/util/inc/tutil.h index fe5c038c5169d88814c7807d550ebadaba8ebacd..7c8fd2ed8353a086ec9f145aaaa30f4db57113cb 100644 --- a/src/util/inc/tutil.h +++ b/src/util/inc/tutil.h @@ -26,6 +26,7 @@ extern "C" { #include "taosdef.h" int32_t strdequote(char *src); +int32_t strRmquote(char *z, int32_t len); size_t strtrim(char *src); char * strnchr(char *haystack, char needle, int32_t len, bool skipquote); char ** strsplit(char *src, const char *delim, int32_t *num); diff --git a/src/util/src/tcompare.c b/src/util/src/tcompare.c index 09199eaee36a7233a3b31494ea3a515aa9ff78be..f91d13e6d0a4310181594b840631249bd1bcade8 100644 --- a/src/util/src/tcompare.c +++ b/src/util/src/tcompare.c @@ -17,6 +17,7 @@ #include "ttype.h" #include "tcompare.h" #include "tarray.h" +#include "hash.h" int32_t compareInt32Val(const void *pLeft, const void *pRight) { int32_t left = GET_INT32_VAL(pLeft), right = GET_INT32_VAL(pRight); @@ -291,9 +292,12 @@ int32_t taosArrayCompareString(const void* a, const void* b) { return compareLenPrefixedStr(x, y); } -static int32_t compareFindStrInArray(const void* pLeft, const void* pRight) { - const SArray* arr = (const SArray*) pRight; - return taosArraySearchString(arr, pLeft, taosArrayCompareString, TD_EQ) == NULL ? 0 : 1; +//static int32_t compareFindStrInArray(const void* pLeft, const void* pRight) { +// const SArray* arr = (const SArray*) pRight; +// return taosArraySearchString(arr, pLeft, taosArrayCompareString, TD_EQ) == NULL ? 0 : 1; +//} +static int32_t compareFindItemInSet(const void *pLeft, const void* pRight) { + return NULL != taosHashGet((SHashObj *)pRight, varDataVal(pLeft), varDataLen(pLeft)) ? 1 : 0; } static int32_t compareWStrPatternComp(const void* pLeft, const void* pRight) { @@ -325,7 +329,7 @@ __compar_fn_t getComparFunc(int32_t type, int32_t optr) { if (optr == TSDB_RELATION_LIKE) { /* wildcard query using like operator */ comparFn = compareStrPatternComp; } else if (optr == TSDB_RELATION_IN) { - comparFn = compareFindStrInArray; + comparFn = compareFindItemInSet; } else { /* normal relational comparFn */ comparFn = compareLenPrefixedStr; } diff --git a/src/util/src/terror.c b/src/util/src/terror.c index 382f872486485d93420d7f180dc11414f570132c..1d37a6e9a4b740d2cfabb18bd3d2252fa6bfd034 100644 --- a/src/util/src/terror.c +++ b/src/util/src/terror.c @@ -193,7 +193,7 @@ TAOS_DEFINE_ERROR(TSDB_CODE_MND_DB_IN_DROPPING, "Database not availabl TAOS_DEFINE_ERROR(TSDB_CODE_MND_VGROUP_NOT_READY, "Database unsynced") TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_DB_OPTION_DAYS, "Invalid database option: days out of range") -TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_DB_OPTION_KEEP, "Invalid database option: keep >= keep1 >= keep0 >= days") +TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_DB_OPTION_KEEP, "Invalid database option: keep2 >= keep1 >= keep0 >= days") TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_TOPIC, "Invalid topic name") TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_TOPIC_OPTION, "Invalid topic option") diff --git a/src/util/src/ttokenizer.c b/src/util/src/ttokenizer.c index 7f8e2896b0c40833d985cc877131e94a634b4f66..88c2a3369bb101ce6b7ae6d72fa1a7973ca732e4 100644 --- a/src/util/src/ttokenizer.c +++ b/src/util/src/ttokenizer.c @@ -266,6 +266,10 @@ static int32_t tKeywordCode(const char* z, int n) { } } + if (keywordHashTable == NULL) { + return TK_ILLEGAL; + } + SKeyword** pKey = (SKeyword**)taosHashGet(keywordHashTable, key, n); return (pKey != NULL)? (*pKey)->type:TK_ID; } @@ -495,9 +499,9 @@ uint32_t tGetToken(char* z, uint32_t* tokenId) { } /* here is the 1u/1a/2s/3m/9y */ - if ((z[i] == 'u' || z[i] == 'a' || z[i] == 's' || z[i] == 'm' || z[i] == 'h' || z[i] == 'd' || z[i] == 'n' || + if ((z[i] == 'b' || z[i] == 'u' || z[i] == 'a' || z[i] == 's' || z[i] == 'm' || z[i] == 'h' || z[i] == 'd' || z[i] == 'n' || z[i] == 'y' || z[i] == 'w' || - z[i] == 'U' || z[i] == 'A' || z[i] == 'S' || z[i] == 'M' || z[i] == 'H' || z[i] == 'D' || z[i] == 'N' || + z[i] == 'B' || z[i] == 'U' || z[i] == 'A' || z[i] == 'S' || z[i] == 'M' || z[i] == 'H' || z[i] == 'D' || z[i] == 'N' || z[i] == 'Y' || z[i] == 'W') && (isIdChar[(uint8_t)z[i + 1]] == 0)) { *tokenId = TK_VARIABLE; diff --git a/src/util/src/tutil.c b/src/util/src/tutil.c index 451976f563740b4ac933766d5c0c8f4075ad42d8..bda52936f90d07b1fde598de9ca683c8a1b8b82a 100644 --- a/src/util/src/tutil.c +++ b/src/util/src/tutil.c @@ -52,6 +52,36 @@ int32_t strdequote(char *z) { return j + 1; // only one quote, do nothing } + +int32_t strRmquote(char *z, int32_t len){ + // delete escape character: \\, \', \" + char delim = z[0]; + if (delim != '\'' && delim != '\"') { + return len; + } + + int32_t cnt = 0; + int32_t j = 0; + for (uint32_t k = 1; k < len - 1; ++k) { + if (z[k] == '\\' || (z[k] == delim && z[k + 1] == delim)) { + z[j] = z[k + 1]; + + cnt++; + j++; + k++; + continue; + } + + z[j] = z[k]; + j++; + } + + z[j] = 0; + + return len - 2 - cnt; +} + + size_t strtrim(char *z) { int32_t i = 0; int32_t j = 0; diff --git a/src/vnode/src/vnodeMgmt.c b/src/vnode/src/vnodeMgmt.c index 27d8ad86437e28a86b300094cdcf0299320d1552..5a0bafe82301d568da20cd45b0daeeb37995127d 100644 --- a/src/vnode/src/vnodeMgmt.c +++ b/src/vnode/src/vnodeMgmt.c @@ -148,7 +148,7 @@ static void vnodeBuildVloadMsg(SVnodeObj *pVnode, SStatusMsg *pStatus) { pLoad->status = pVnode->status; pLoad->role = pVnode->role; pLoad->replica = pVnode->syncCfg.replica; - pLoad->compact = 1;//pVnode->compact; + pLoad->compact = (pVnode->tsdb != NULL) && tsdbInCompact(pVnode->tsdb) ? 1 : 0; } int32_t vnodeGetVnodeList(int32_t vnodeList[], int32_t *numOfVnodes) { diff --git a/tests/comparisonTest/opentsdb/opentsdbtest/pom.xml b/tests/comparisonTest/opentsdb/opentsdbtest/pom.xml index 0af7491128cf21fc3a35d32701c0aec1aeff88cd..e0ada8b763eca8208260ebde73ce8fb192e917db 100644 --- a/tests/comparisonTest/opentsdb/opentsdbtest/pom.xml +++ b/tests/comparisonTest/opentsdb/opentsdbtest/pom.xml @@ -162,7 +162,7 @@ org.apache.httpcomponents httpclient - 4.5.4 + 4.5.13 @@ -216,13 +216,13 @@ ch.qos.logback logback-core - 1.0.13 + 1.2.0 ch.qos.logback logback-classic - 1.0.13 + 1.2.0 diff --git a/tests/examples/c/apitest.c b/tests/examples/c/apitest.c index 2961750efce3f1e746aa2e82ecb5160488065681..0f24df0f4767fe1cdace072425768473ffcaa88f 100644 --- a/tests/examples/c/apitest.c +++ b/tests/examples/c/apitest.c @@ -86,7 +86,7 @@ static int print_result(TAOS_RES* res, int blockFetch) { } } else { while ((row = taos_fetch_row(res))) { - char temp[256]; + char temp[256] = {0}; taos_print_row(temp, row, fields, num_fields); puts(temp); nRows++; @@ -342,7 +342,9 @@ void verify_prepare(TAOS* taos) { sql = "insert into m1 values(?,?,?,?,?,?,?,?,?,?)"; code = taos_stmt_prepare(stmt, sql, 0); if (code != 0){ - printf("\033[31mfailed to execute taos_stmt_prepare. code:0x%x\033[0m\n", code); + printf("\033[31mfailed to execute taos_stmt_prepare. error:%s\033[0m\n", taos_stmt_errstr(stmt)); + taos_stmt_close(stmt); + return; } v.ts = 1591060628000; for (int i = 0; i < 10; ++i) { @@ -365,8 +367,8 @@ void verify_prepare(TAOS* taos) { taos_stmt_add_batch(stmt); } if (taos_stmt_execute(stmt) != 0) { + printf("\033[31mfailed to execute insert statement.error:%s\033[0m\n", taos_stmt_errstr(stmt)); taos_stmt_close(stmt); - printf("\033[31mfailed to execute insert statement.\033[0m\n"); return; } taos_stmt_close(stmt); @@ -378,8 +380,8 @@ void verify_prepare(TAOS* taos) { v.v2 = 15; taos_stmt_bind_param(stmt, params + 2); if (taos_stmt_execute(stmt) != 0) { + printf("\033[31mfailed to execute select statement.error:%s\033[0m\n", taos_stmt_errstr(stmt)); taos_stmt_close(stmt); - printf("\033[31mfailed to execute select statement.\033[0m\n"); return; } @@ -389,10 +391,10 @@ void verify_prepare(TAOS* taos) { int rows = 0; int num_fields = taos_num_fields(result); TAOS_FIELD *fields = taos_fetch_fields(result); - char temp[256]; // fetch the records row by row while ((row = taos_fetch_row(result))) { + char temp[256] = {0}; rows++; taos_print_row(temp, row, fields, num_fields); printf("%s\n", temp); @@ -530,12 +532,16 @@ void verify_prepare2(TAOS* taos) { sql = "insert into ? (ts, b, v1, v2, v4, v8, f4, f8, bin, blob) values(?,?,?,?,?,?,?,?,?,?)"; code = taos_stmt_prepare(stmt, sql, 0); if (code != 0) { - printf("\033[31mfailed to execute taos_stmt_prepare. code:0x%x\033[0m\n", code); + printf("\033[31mfailed to execute taos_stmt_prepare. error:%s\033[0m\n", taos_stmt_errstr(stmt)); + taos_stmt_close(stmt); + return; } code = taos_stmt_set_tbname(stmt, "m1"); if (code != 0){ - printf("\033[31mfailed to execute taos_stmt_prepare. code:0x%x\033[0m\n", code); + printf("\033[31mfailed to execute taos_stmt_prepare. error:%s\033[0m\n", taos_stmt_errstr(stmt)); + taos_stmt_close(stmt); + return; } int64_t ts = 1591060628000; @@ -569,7 +575,8 @@ void verify_prepare2(TAOS* taos) { taos_stmt_add_batch(stmt); if (taos_stmt_execute(stmt) != 0) { - printf("\033[31mfailed to execute insert statement.\033[0m\n"); + printf("\033[31mfailed to execute insert statement.error:%s\033[0m\n", taos_stmt_errstr(stmt)); + taos_stmt_close(stmt); return; } @@ -596,7 +603,8 @@ void verify_prepare2(TAOS* taos) { taos_stmt_bind_param(stmt, qparams); if (taos_stmt_execute(stmt) != 0) { - printf("\033[31mfailed to execute select statement.\033[0m\n"); + printf("\033[31mfailed to execute select statement.error:%s\033[0m\n", taos_stmt_errstr(stmt)); + taos_stmt_close(stmt); return; } @@ -606,10 +614,10 @@ void verify_prepare2(TAOS* taos) { int rows = 0; int num_fields = taos_num_fields(result); TAOS_FIELD *fields = taos_fetch_fields(result); - char temp[256]; // fetch the records row by row while ((row = taos_fetch_row(result))) { + char temp[256] = {0}; rows++; taos_print_row(temp, row, fields, num_fields); printf("%s\n", temp); @@ -776,12 +784,16 @@ void verify_prepare3(TAOS* taos) { sql = "insert into ? using st1 tags(?,?) values(?,?,?,?,?,?,?,?,?,?)"; code = taos_stmt_prepare(stmt, sql, 0); if (code != 0){ - printf("\033[31mfailed to execute taos_stmt_prepare. code:0x%x\033[0m\n", code); + printf("\033[31mfailed to execute taos_stmt_prepare. error:%s\033[0m\n", taos_stmt_errstr(stmt)); + taos_stmt_close(stmt); + return; } code = taos_stmt_set_tbname_tags(stmt, "m1", tags); if (code != 0){ - printf("\033[31mfailed to execute taos_stmt_prepare. code:0x%x\033[0m\n", code); + printf("\033[31mfailed to execute taos_stmt_prepare. error:%s\033[0m\n", taos_stmt_errstr(stmt)); + taos_stmt_close(stmt); + return; } int64_t ts = 1591060628000; @@ -815,7 +827,8 @@ void verify_prepare3(TAOS* taos) { taos_stmt_add_batch(stmt); if (taos_stmt_execute(stmt) != 0) { - printf("\033[31mfailed to execute insert statement.\033[0m\n"); + printf("\033[31mfailed to execute insert statement.error:%s\033[0m\n", taos_stmt_errstr(stmt)); + taos_stmt_close(stmt); return; } taos_stmt_close(stmt); @@ -842,7 +855,8 @@ void verify_prepare3(TAOS* taos) { taos_stmt_bind_param(stmt, qparams); if (taos_stmt_execute(stmt) != 0) { - printf("\033[31mfailed to execute select statement.\033[0m\n"); + printf("\033[31mfailed to execute select statement.error:%s\033[0m\n", taos_stmt_errstr(stmt)); + taos_stmt_close(stmt); return; } @@ -852,12 +866,10 @@ void verify_prepare3(TAOS* taos) { int rows = 0; int num_fields = taos_num_fields(result); TAOS_FIELD *fields = taos_fetch_fields(result); - char temp[256] = {0}; // fetch the records row by row while ((row = taos_fetch_row(result))) { - memset(temp, 0, sizeof(temp)/sizeof(temp[0])); - + char temp[256] = {0}; rows++; taos_print_row(temp, row, fields, num_fields); printf("%s\n", temp); diff --git a/tests/examples/c/demo.c b/tests/examples/c/demo.c index 0b1cd7b5d2d304a89656c98e88b2a620e16ae5a1..f8c69d0043591afa8f5e32e80bd35e9413e60e76 100644 --- a/tests/examples/c/demo.c +++ b/tests/examples/c/demo.c @@ -116,12 +116,12 @@ void Test(TAOS *taos, char *qstr, int index) { int rows = 0; int num_fields = taos_field_count(result); TAOS_FIELD *fields = taos_fetch_fields(result); - char temp[1024]; printf("num_fields = %d\n", num_fields); printf("select * from table, result:\n"); // fetch the records row by row while ((row = taos_fetch_row(result))) { + char temp[1024] = {0}; rows++; taos_print_row(temp, row, fields, num_fields); printf("%s\n", temp); diff --git a/tests/examples/c/prepare.c b/tests/examples/c/prepare.c index 13d71beea6156aa32677c20ccc2d222d28826b24..723b340a923c0bf326599e8090f8c6142a249053 100644 --- a/tests/examples/c/prepare.c +++ b/tests/examples/c/prepare.c @@ -184,10 +184,10 @@ int main(int argc, char *argv[]) int rows = 0; int num_fields = taos_num_fields(result); TAOS_FIELD *fields = taos_fetch_fields(result); - char temp[256]; // fetch the records row by row while ((row = taos_fetch_row(result))) { + char temp[256] = {0}; rows++; taos_print_row(temp, row, fields, num_fields); printf("%s\n", temp); diff --git a/tests/examples/c/subscribe.c b/tests/examples/c/subscribe.c index 1d3533fa5ee89f7425a9b0563e738b4e0703e6c8..ad12f0e7a55b0f471f249f92f30cf659c94586a5 100644 --- a/tests/examples/c/subscribe.c +++ b/tests/examples/c/subscribe.c @@ -14,8 +14,6 @@ void print_result(TAOS_RES* res, int blockFetch) { int num_fields = taos_num_fields(res); TAOS_FIELD* fields = taos_fetch_fields(res); int nRows = 0; - char buf[4096]; - if (blockFetch) { nRows = taos_fetch_block(res, &row); @@ -25,6 +23,7 @@ void print_result(TAOS_RES* res, int blockFetch) { //} } else { while ((row = taos_fetch_row(res))) { + char buf[4096] = {0}; taos_print_row(buf, row, fields, num_fields); puts(buf); nRows++; diff --git a/tests/mas/Jenkinsfile b/tests/mas/Jenkinsfile index 0e6e94a037d3ba1a187e6bdad2070e9dc4d4a32f..ae2286298f3e7de4e831451ccdeaef28a5d71a8e 100644 --- a/tests/mas/Jenkinsfile +++ b/tests/mas/Jenkinsfile @@ -21,7 +21,7 @@ def pre_test(){ cmake .. > /dev/null make > /dev/null make install > /dev/null - pip3 install ${WKC}/src/connector/python/linux/python3/ + pip3 install ${WKC}/src/connector/python/ || echo 0 ''' return 1 } diff --git a/tests/pytest/alter/alter_keep.py b/tests/pytest/alter/alter_keep.py new file mode 100644 index 0000000000000000000000000000000000000000..f09f5ab6d13e25856fc9aca2a060aabae327fc63 --- /dev/null +++ b/tests/pytest/alter/alter_keep.py @@ -0,0 +1,195 @@ +################################################################### +# Copyright (c) 2016 by TAOS Technologies, Inc. +# All rights reserved. +# +# This file is proprietary and confidential to TAOS Technologies. +# No part of this file may be reproduced, stored, transmitted, +# disclosed or used in any form or by any means other than as +# expressly provided by the written permission from Jianhui Tao +# +################################################################### + +# -*- coding: utf-8 -*- + +import sys +from util.log import * +from util.cases import * +from util.sql import * + + +class TDTestCase: + def init(self, conn, logSql): + tdLog.debug("start to execute %s" % __file__) + tdSql.init(conn.cursor(), logSql) + + def alterKeepCommunity(self): + tdLog.notice('running Keep Test, Community Version') + #testing keep parameter during create + tdSql.query('show databases') + tdSql.checkData(0,7,'3650') + tdSql.execute('drop database db') + + tdSql.execute('create database db keep 100') + tdSql.query('show databases') + tdSql.checkData(0,7,'100') + tdSql.execute('drop database db') + + tdSql.error('create database db keep ') + tdSql.error('create database db keep 0') + tdSql.error('create database db keep 10,20') + tdSql.error('create database db keep 10,20,30') + tdSql.error('create database db keep 20,30,40,50') + + #testing keep parameter during alter + tdSql.execute('create database db') + + tdSql.execute('alter database db keep 100') + tdSql.query('show databases') + tdSql.checkData(0,7,'100') + + tdSql.error('alter database db keep ') + tdSql.error('alter database db keep 0') + tdSql.error('alter database db keep 10,20') + tdSql.error('alter database db keep 10,20,30') + tdSql.error('alter database db keep 20,30,40,50') + tdSql.query('show databases') + tdSql.checkData(0,7,'100') + + def alterKeepEnterprise(self): + tdLog.notice('running Keep Test, Enterprise Version') + #testing keep parameter during create + tdSql.query('show databases') + tdSql.checkData(0,7,'3650,3650,3650') + tdSql.execute('drop database db') + + tdSql.execute('create database db keep 100') + tdSql.query('show databases') + tdSql.checkData(0,7,'100,100,100') + tdSql.execute('drop database db') + + tdSql.execute('create database db keep 20, 30') + tdSql.query('show databases') + tdSql.checkData(0,7,'20,30,30') + tdSql.execute('drop database db') + + tdSql.execute('create database db keep 30,40,50') + tdSql.query('show databases') + tdSql.checkData(0,7,'30,40,50') + tdSql.execute('drop database db') + + tdSql.error('create database db keep ') + tdSql.error('create database db keep 20,30,40,50') + tdSql.error('create database db keep 0') + tdSql.error('create database db keep 100,50') + tdSql.error('create database db keep 100,40,50') + tdSql.error('create database db keep 20,100,50') + tdSql.error('create database db keep 50,60,20') + + #testing keep parameter during alter + tdSql.execute('create database db') + + tdSql.execute('alter database db keep 10') + tdSql.query('show databases') + tdSql.checkData(0,7,'10,10,10') + + tdSql.execute('alter database db keep 20,30') + tdSql.query('show databases') + tdSql.checkData(0,7,'20,30,30') + + tdSql.execute('alter database db keep 100,200,300') + tdSql.query('show databases') + tdSql.checkData(0,7,'100,200,300') + + tdSql.error('alter database db keep ') + tdSql.error('alter database db keep 20,30,40,50') + tdSql.error('alter database db keep 0') + tdSql.error('alter database db keep 100,50') + tdSql.error('alter database db keep 100,40,50') + tdSql.error('alter database db keep 20,100,50') + tdSql.error('alter database db keep 50,60,20') + tdSql.query('show databases') + tdSql.checkData(0,7,'100,200,300') + + + def run(self): + tdSql.prepare() + selfPath = os.path.dirname(os.path.realpath(__file__)) + + if ("community" in selfPath): + tdLog.debug('running enterprise test') + self.alterKeepEnterprise() + else: + tdLog.debug('running community test') + self.alterKeepCommunity() + + tdSql.prepare() + + ##TODO: need to wait for TD-4445 to implement the following + ## tests + + + ## preset the keep + tdSql.prepare() + tdSql.execute('create table tb (ts timestamp, speed int)') + tdSql.execute('alter database db keep 10,10,10') + tdSql.execute('insert into tb values (now, 10)') + tdSql.execute('insert into tb values (now + 10m, 10)') + tdSql.query('select * from tb') + tdSql.checkRows(2) + + + #after alter from small to large, check if the alter if functioning + #test if change through test.py is consistent with change from taos client + #test case for TD-4459 and TD-4445 + tdSql.execute('alter database db keep 40,40,40') + tdSql.query('show databases') + tdSql.checkData(0,7,'40,40,40') + tdSql.error('insert into tb values (now-60d, 10)') + tdSql.execute('insert into tb values (now-30d, 10)') + tdSql.query('select * from tb') + tdSql.checkRows(3) + + rowNum = 3 + for i in range(30): + rowNum += 1 + tdSql.execute('alter database db keep 20,20,20') + tdSql.execute('alter database db keep 40,40,40') + tdSql.query('show databases') + tdSql.checkData(0,7,'40,40,40') + tdSql.error('insert into tb values (now-60d, 10)') + tdSql.execute('insert into tb values (now-30d, 10)') + tdSql.query('select * from tb') + tdSql.checkRows(rowNum) + + tdSql.execute('alter database db keep 10,10,10') + tdSql.query('show databases') + tdSql.checkData(0,7,'10,10,10') + + # if uncomment these three lines, timestamp out of range error will appear + # tdSql.execute('alter database db keep 15,15,15') + # tdSql.query('show databases') + # tdSql.checkData(0,7,'15,15,15') + + # the following line should generate an error, but the insert was a success + # the time now-15d is out of range of now -10d + tdSql.error('insert into tb values (now-15d, 10)') + tdSql.query('select * from tb') + tdSql.checkRows(rowNum) + + # tdSql.execute('alter database db keep 20,20,20') + # tdSql.query('show databases') + # tdSql.checkData(0,7,'20,20,20') + # tdSql.error('insert into tb values (now-30d, 10)') + # tdSql.query('show databases') + # tdSql.checkData(0,7,'20,20,20') + # tdSql.query('select * from tb') + # tdSql.checkRows(rowNum) + + + def stop(self): + tdSql.close() + tdLog.success("%s successfully executed" % __file__) + + +tdCases.addWindows(__file__, TDTestCase()) +tdCases.addLinux(__file__, TDTestCase()) diff --git a/tests/pytest/client/change_time_1_1.py b/tests/pytest/client/change_time_1_1.py new file mode 100644 index 0000000000000000000000000000000000000000..24e0195a9c020c793f3e82f45029d8e24199f50b --- /dev/null +++ b/tests/pytest/client/change_time_1_1.py @@ -0,0 +1,72 @@ +################################################################### +# Copyright (c) 2016 by TAOS Technologies, Inc. +# All rights reserved. +# +# This file is proprietary and confidential to TAOS Technologies. +# No part of this file may be reproduced, stored, transmitted, +# disclosed or used in any form or by any means other than as +# expressly provided by the written permission from Jianhui Tao +# +################################################################### + +# -*- coding: utf-8 -*- + +import sys +from util.log import * +from util.cases import * +from util.sql import * +from util.pathFinding import * +from util.dnodes import tdDnodes +from datetime import datetime +import subprocess + +##TODO: this is now automatic, but not sure if this will run through jenkins +class TDTestCase: + def init(self, conn, logSql): + tdLog.debug("start to execute %s" % __file__) + tdSql.init(conn.cursor(), logSql) + tdFindPath.init(__file__) + + def run(self): + tdSql.prepare() + binPath = tdFindPath.getTaosdemoPath() + TDenginePath = tdFindPath.getTDenginePath() + + ## change system time to 2020/10/20 + os.system('sudo timedatectl set-ntp off') + os.system('sudo timedatectl set-time 2020-10-20') + + #run taosdemo to insert data. one row per second from 2020/10/11 to 2020/10/20 + #11 data files should be generated + #vnode at TDinternal/community/sim/dnode1/data/vnode + os.system(f"{binPath}taosdemo -f tools/taosdemoAllTest/manual_change_time_1_1_A.json") + commandArray = ['ls', '-l', f'{TDenginePath}/sim/dnode1/data/vnode/vnode2/tsdb/data'] + result = subprocess.run(commandArray, stdout=subprocess.PIPE).stdout.decode('utf-8') + print(result.count('data')) + if result.count('data') != 11: + tdLog.exit('wrong number of files') + else: + tdLog.debug("data file number correct") + + #move 5 days ahead to 2020/10/25. 4 oldest files should be removed during the new write + #leaving 7 data files. + os.system ('timedatectl set-time 2020-10-25') + os.system(f"{binPath}taosdemo -f tools/taosdemoAllTest/manual_change_time_1_1_B.json") + commandArray = ['ls', '-l', f'{TDenginePath}/sim/dnode1/data/vnode/vnode2/tsdb/data'] + result = subprocess.run(commandArray, stdout=subprocess.PIPE).stdout.decode('utf-8') + print(result.count('data')) + if result.count('data') != 7: + tdLog.exit('wrong number of files') + else: + tdLog.debug("data file number correct") + tdSql.query('select first(ts) from stb_0') + tdSql.checkData(0,0,datetime(2020,10,14,8,0,0,0)) #check the last data in the database + + def stop(self): + os.system('sudo timedatectl set-ntp on') + tdSql.close() + tdLog.success("alter block manual check finish") + + +tdCases.addWindows(__file__, TDTestCase()) +tdCases.addLinux(__file__, TDTestCase()) diff --git a/tests/pytest/client/change_time_1_2.py b/tests/pytest/client/change_time_1_2.py new file mode 100644 index 0000000000000000000000000000000000000000..cd1a17926da89ebb6d0f67bbe5f818f763a1ea0e --- /dev/null +++ b/tests/pytest/client/change_time_1_2.py @@ -0,0 +1,82 @@ +################################################################### +# Copyright (c) 2016 by TAOS Technologies, Inc. +# All rights reserved. +# +# This file is proprietary and confidential to TAOS Technologies. +# No part of this file may be reproduced, stored, transmitted, +# disclosed or used in any form or by any means other than as +# expressly provided by the written permission from Jianhui Tao +# +################################################################### + +# -*- coding: utf-8 -*- + +import sys +from util.log import * +from util.cases import * +from util.sql import * +from util.dnodes import tdDnodes +from util.pathFinding import * +from datetime import datetime +import subprocess + +##TODO: this is now automatic, but not sure if this will run through jenkins +class TDTestCase: + def init(self, conn, logSql): + tdLog.debug("start to execute %s" % __file__) + tdSql.init(conn.cursor(), logSql) + tdFindPath.init(__file__) + + def run(self): + tdSql.prepare() + binPath = tdFindPath.getTaosdemoPath() + TDenginePath = tdFindPath.getTDenginePath() + + ## change system time to 2020/10/20 + os.system ('timedatectl set-ntp off') + os.system ('timedatectl set-time 2020-10-20') + + #run taosdemo to insert data. one row per second from 2020/10/11 to 2020/10/20 + #11 data files should be generated + #vnode at TDinternal/community/sim/dnode1/data/vnode + os.system(f"{binPath}taosdemo -f tools/taosdemoAllTest/manual_change_time_1_1_A.json") + commandArray = ['ls', '-l', f'{TDenginePath}/sim/dnode1/data/vnode/vnode2/tsdb/data'] + result = subprocess.run(commandArray, stdout=subprocess.PIPE).stdout.decode('utf-8') + print(result.count('data')) + if result.count('data') != 11: + tdLog.exit('wrong number of files') + else: + tdLog.debug("data file number correct") + + tdSql.query('select first(ts) from stb_0') #check the last data in the database + tdSql.checkData(0,0,datetime(2020,10,11,0,0,0,0)) + + os.system ('timedatectl set-time 2020-10-25') + + #moves 5 days ahead to 2020/10/25 and restart taosd + #4 oldest data file should be removed from tsdb/data + #7 data file should be found + #vnode at TDinternal/community/sim/dnode1/data/vnode + os.system ('timedatectl set-time 2020-10-25') + tdDnodes.stop(1) + tdDnodes.start(1) + tdSql.query('select first(ts) from stb_0') + tdSql.checkData(0,0,datetime(2020,10,14,8,0,0,0)) #check the last data in the database + commandArray = ['ls', '-l', f'{TDenginePath}/sim/dnode1/data/vnode/vnode2/tsdb/data'] + result = subprocess.run(commandArray, stdout=subprocess.PIPE).stdout.decode('utf-8') + print(result.count('data')) + if result.count('data') != 7: + tdLog.exit('wrong number of files') + else: + tdLog.debug("data file number correct") + + + + def stop(self): + os.system('sudo timedatectl set-ntp on') + tdSql.close() + tdLog.success("alter block manual check finish") + + +tdCases.addWindows(__file__, TDTestCase()) +tdCases.addLinux(__file__, TDTestCase()) diff --git a/tests/pytest/cluster/clusterSetup.py b/tests/pytest/cluster/clusterSetup.py index 8a264270219232447a598768b45a37779edba698..87414303f850bcbd78468238e7b76aa3dbb3326e 100644 --- a/tests/pytest/cluster/clusterSetup.py +++ b/tests/pytest/cluster/clusterSetup.py @@ -23,7 +23,8 @@ class Node: self.hostIP = hostIP self.hostName = hostName self.homeDir = homeDir - self.conn = Connection("{}@{}".format(username, hostName), connect_kwargs={"password": "{}".format(password)}) + self.corePath = '/coredump' + self.conn = Connection("{}@{}".format(username, hostName), connect_kwargs={"password": "{}".format(password)}) def buildTaosd(self): try: @@ -126,21 +127,37 @@ class Node: except Exception as e: print("remove taosd error for node %d " % self.index) logging.exception(e) + + + def detectCoredumpFile(self): + try: + result = self.conn.run("find /coredump -name 'core_*' ", hide=True) + output = result.stdout + print("output: %s" % output) + return output + except Exception as e: + print("find coredump file error on node %d " % self.index) + logging.exception(e) + class Nodes: def __init__(self): self.tdnodes = [] - self.tdnodes.append(Node(0, 'root', '52.143.103.7', 'node1', 'a', '/root/')) - self.tdnodes.append(Node(1, 'root', '52.250.48.222', 'node2', 'a', '/root/')) - self.tdnodes.append(Node(2, 'root', '51.141.167.23', 'node3', 'a', '/root/')) - self.tdnodes.append(Node(3, 'root', '52.247.207.173', 'node4', 'a', '/root/')) - self.tdnodes.append(Node(4, 'root', '51.141.166.100', 'node5', 'a', '/root/')) + self.tdnodes.append(Node(0, 'root', '192.168.17.194', 'taosdata', 'r', '/root/')) + # self.tdnodes.append(Node(1, 'root', '52.250.48.222', 'node2', 'a', '/root/')) + # self.tdnodes.append(Node(2, 'root', '51.141.167.23', 'node3', 'a', '/root/')) + # self.tdnodes.append(Node(3, 'root', '52.247.207.173', 'node4', 'a', '/root/')) + # self.tdnodes.append(Node(4, 'root', '51.141.166.100', 'node5', 'a', '/root/')) def stopOneNode(self, index): + self.tdnodes[index].stopTaosd() self.tdnodes[index].forceStopOneTaosd() def startOneNode(self, index): self.tdnodes[index].startOneTaosd() + + def detectCoredumpFile(self, index): + return self.tdnodes[index].detectCoredumpFile() def stopAllTaosd(self): for i in range(len(self.tdnodes)): @@ -166,14 +183,32 @@ class Nodes: for i in range(len(self.tdnodes)): self.tdnodes[i].removeData() -# kill taosd randomly every 10 mins -nodes = Nodes() -loop = 0 -while True: - loop = loop + 1 - index = random.randint(0, 4) - print("loop: %d, kill taosd on node%d" %(loop, index)) - nodes.stopOneNode(index) - time.sleep(60) - nodes.startOneNode(index) - time.sleep(600) \ No newline at end of file +class Test: + def __init__(self): + self.nodes = Nodes() + + # kill taosd randomly every 10 mins + def randomlyKillDnode(self): + loop = 0 + while True: + index = random.randint(0, 4) + print("loop: %d, kill taosd on node%d" %(loop, index)) + self.nodes.stopOneNode(index) + time.sleep(60) + self.nodes.startOneNode(index) + time.sleep(600) + loop = loop + 1 + + def detectCoredump(self): + loop = 0 + while True: + for i in range(len(self.nodes.tdnodes)): + result = self.nodes.detectCoredumpFile(i) + print("core file path is %s" % result) + if result and not result.isspace(): + self.nodes.stopAllTaosd() + print("sleep for 10 mins") + time.sleep(600) + +test = Test() +test.detectCoredump() \ No newline at end of file diff --git a/tests/pytest/fulltest.sh b/tests/pytest/fulltest.sh index 5e4f57e1a2db5984c13fafc8f8a046403914c900..e9dc3762fe9aed0eac8e7e7d70356ba3baa5a450 100755 --- a/tests/pytest/fulltest.sh +++ b/tests/pytest/fulltest.sh @@ -229,7 +229,7 @@ python3 ./test.py -f query/queryFilterTswithDateUnit.py python3 ./test.py -f query/queryTscomputWithNow.py python3 ./test.py -f query/computeErrorinWhere.py python3 ./test.py -f query/queryTsisNull.py - +python3 ./test.py -f query/subqueryFilter.py #stream @@ -256,6 +256,8 @@ python3 ./test.py -f client/client.py python3 ./test.py -f client/version.py python3 ./test.py -f client/alterDatabase.py python3 ./test.py -f client/noConnectionErrorTest.py +python3 test.py -f client/change_time_1_1.py +python3 test.py -f client/change_time_1_2.py # Misc python3 testCompress.py @@ -283,6 +285,7 @@ python3 ./test.py -f topic/topicQuery.py python3 ./test.py -f update/merge_commit_data-0.py # wal python3 ./test.py -f wal/addOldWalTest.py +python3 ./test.py -f wal/sdbComp.py # function python3 ./test.py -f functions/all_null_value.py @@ -314,7 +317,6 @@ python3 ./test.py -f query/last_row_cache.py python3 ./test.py -f account/account_create.py python3 ./test.py -f alter/alter_table.py python3 ./test.py -f query/queryGroupbySort.py -python3 ./test.py -f functions/function_session.py python3 ./test.py -f functions/function_stateWindow.py python3 ./test.py -f insert/unsignedInt.py @@ -338,6 +340,8 @@ python3 test.py -f tools/taosdemoAllTest/taosdemoTestInsertWithJson.py python3 test.py -f tools/taosdemoAllTest/taosdemoTestQueryWithJson.py python3 ./test.py -f tag_lite/drop_auto_create.py python3 test.py -f insert/insert_before_use_db.py +python3 test.py -f alter/alter_keep.py python3 test.py -f alter/alter_cacheLastRow.py python3 test.py -f alter/alter_keep_exception.py +python3 ./test.py -f query/querySession.py #======================p4-end=============== diff --git a/tests/pytest/functions/function_diff.py b/tests/pytest/functions/function_diff.py index 46ea3a86deee75d26f0b635ae0d3b2c5673fb6da..fba3b4c0d4bd16533ab9f67b42b3643449288cac 100644 --- a/tests/pytest/functions/function_diff.py +++ b/tests/pytest/functions/function_diff.py @@ -26,7 +26,20 @@ class TDTestCase: self.rowNum = 10 self.ts = 1537146000000 - + self.perfix = 'dev' + self.tables = 10 + + def insertData(self): + print("==============step1") + tdSql.execute( + "create table if not exists st (ts timestamp, col int) tags(dev nchar(50))") + + for i in range(self.tables): + tdSql.execute("create table %s%d using st tags(%d)" % (self.perfix, i, i)) + rows = 15 + i + for j in range(rows): + tdSql.execute("insert into %s%d values(%d, %d)" %(self.perfix, i, self.ts + i * 20 * 10000 + j * 10000, j)) + def run(self): tdSql.prepare() @@ -99,6 +112,15 @@ class TDTestCase: tdSql.query("select diff(col6) from test1") tdSql.checkRows(10) + + self.insertData() + + tdSql.query("select diff(col) from st group by tbname") + tdSql.checkRows(185) + + tdSql.error("select diff(col) from st group by dev") + + tdSql.error("select diff(col) from st group by col") def stop(self): tdSql.close() diff --git a/tests/pytest/functions/function_diff_restart.py b/tests/pytest/functions/function_diff_restart.py index e03b892477eba46c007163049d91012af236e730..1e00309860d0c6fc1867f067e5124b8077c314c4 100644 --- a/tests/pytest/functions/function_diff_restart.py +++ b/tests/pytest/functions/function_diff_restart.py @@ -97,6 +97,12 @@ class TDTestCase: tdSql.query("select diff(col6) from test1") tdSql.checkRows(10) + + tdSql.query("select diff(col) from st group by tbname") + tdSql.checkRows(185) + + tdSql.error("select diff(col) from st group by dev") + tdSql.error("select diff(col) from st group by col") def stop(self): tdSql.close() diff --git a/tests/pytest/functions/function_session.py b/tests/pytest/functions/function_session.py deleted file mode 100644 index 21b6d088ffd45c3a0e1b867335b8a36d834b93cc..0000000000000000000000000000000000000000 --- a/tests/pytest/functions/function_session.py +++ /dev/null @@ -1,86 +0,0 @@ -################################################################### -# Copyright (c) 2016 by TAOS Technologies, Inc. -# All rights reserved. -# -# This file is proprietary and confidential to TAOS Technologies. -# No part of this file may be reproduced, stored, transmitted, -# disclosed or used in any form or by any means other than as -# expressly provided by the written permission from Jianhui Tao -# -################################################################### - -# -*- coding: utf-8 -*- - -import sys -import taos -from util.log import * -from util.cases import * -from util.sql import * -#import numpy as np - - -class TDTestCase: - def init(self, conn, logSql): - tdLog.debug("start to execute %s" % __file__) - tdSql.init(conn.cursor()) - - self.rowNum = 10 - self.ts = 1537146000000 - - def run(self): - tdSql.prepare() - - tdSql.execute('''create table test(ts timestamp, col1 tinyint, col2 smallint, col3 int, col4 bigint, col5 float, col6 double, - col7 bool, col8 binary(20), col9 nchar(20), col11 tinyint unsigned, col12 smallint unsigned, col13 int unsigned, col14 bigint unsigned) tags(loc nchar(20))''') - tdSql.execute("create table test1 using test tags('beijing')") - for i in range(self.rowNum): - tdSql.execute("insert into test1 values(%d, %d, %d, %d, %d, %f, %f, %d, 'taosdata%d', '涛思数据%d', %d, %d, %d, %d)" - % (self.ts + i, i + 1, i + 1, i + 1, i + 1, i + 0.1, i + 0.1, i % 2, i + 1, i + 1, i + 1, i + 1, i + 1, i + 1)) - - # operation not allowed on super table - tdSql.error("select count(*) from test session(ts, 1s)") - # operation not allowde on col pro - tdSql.error("select * from test1 session(ts, 1s)") - # operation not allowed on col except primary ts - tdSql.error("select * from test1 session(col1, 1s)") - - tdSql.query("select count(*) from test1 session(ts, 1s)") - - tdSql.checkRows(1) - tdSql.checkData(0, 1, 10) - # append more data - - for i in range(self.rowNum): - tdSql.execute("insert into test1 values(%d, %d, %d, %d, %d, %f, %f, %d, 'taosdata%d', '涛思数据%d', %d, %d, %d, %d)" - % (self.ts + 2000, i + 1, i + 1, i + 1, i + 1, i + 0.1, i + 0.1, i % 2, i + 1, i + 1, i + 1, i + 1, i + 1, i + 1)) - - tdSql.query("select count(*) from test1 session(ts, 1s)") - tdSql.checkRows(2) - tdSql.checkData(0, 1, 10) - tdSql.checkData(1, 1, 1) - - tdSql.query("select count(*) from test1 session(ts, 1m)") - tdSql.checkRows(1) - tdSql.checkData(0, 1, 11) - - tdSql.query("select first(col1) from test1 session(ts, 1s)") - tdSql.checkRows(2) - tdSql.checkData(0, 1, 1) - tdSql.checkData(1, 1, 1) - - - tdSql.query("select first(col1), last(col2) from test1 session(ts, 1s)") - tdSql.checkRows(2) - tdSql.checkData(0, 1, 1) - tdSql.checkData(0, 2, 10) - tdSql.checkData(1, 1, 1) - tdSql.checkData(1, 1, 1) - - # add more function - - def stop(self): - tdSql.close() - tdLog.success("%s successfully executed" % __file__) - -tdCases.addWindows(__file__, TDTestCase()) -tdCases.addLinux(__file__, TDTestCase()) diff --git a/tests/pytest/functions/showOfflineThresholdIs864000.py b/tests/pytest/functions/showOfflineThresholdIs864000.py index 6cce869bf2144e37948c9eb6a3c9ca49352584ca..a7a1c2bf3f7d998b1ec0b0cd0e0747381e9bf4fa 100644 --- a/tests/pytest/functions/showOfflineThresholdIs864000.py +++ b/tests/pytest/functions/showOfflineThresholdIs864000.py @@ -25,7 +25,7 @@ class TDTestCase: def run(self): tdSql.query("show variables") - tdSql.checkData(51, 1, 864000) + tdSql.checkData(53, 1, 864000) def stop(self): tdSql.close() @@ -33,4 +33,4 @@ class TDTestCase: tdCases.addWindows(__file__, TDTestCase()) -tdCases.addLinux(__file__, TDTestCase()) \ No newline at end of file +tdCases.addLinux(__file__, TDTestCase()) diff --git a/tests/pytest/manualTest/manual_change_time_2.py b/tests/pytest/manualTest/manual_change_time_2.py new file mode 100644 index 0000000000000000000000000000000000000000..4aeacb9f630a7e36ceb6e34a8a6c40f2d77dd1ca --- /dev/null +++ b/tests/pytest/manualTest/manual_change_time_2.py @@ -0,0 +1,97 @@ +################################################################### +# Copyright (c) 2016 by TAOS Technologies, Inc. +# All rights reserved. +# +# This file is proprietary and confidential to TAOS Technologies. +# No part of this file may be reproduced, stored, transmitted, +# disclosed or used in any form or by any means other than as +# expressly provided by the written permission from Jianhui Tao +# +################################################################### + +# -*- coding: utf-8 -*- +from fabric import Connection +import sys +from util.log import * +from util.cases import * +from util.sql import * +from util.dnodes import tdDnodes +from datetime import datetime +import subprocess +import time +import taos +##TODO: this is now automatic, but not sure if this will run through jenkins + +#the initial time used for this test is 2020/10/20 + +#setting local machine's time for later connecting to the server +os.system('sudo timedatectl set-ntp off') +os.system('sudo timedatectl set-time 2020-10-25') + +#connect to VM lyq-1, and initalize the environment at lyq-1 +conn1 = Connection("{}@{}".format('ubuntu', "192.168.1.125"), connect_kwargs={"password": "{}".format('tbase125!')}) +conn1.run("sudo systemctl stop taosd") +conn1.run('ls -l') +conn1.run('sudo timedatectl set-ntp off') +conn1.run('sudo timedatectl set-time 2020-10-20') + +with conn1.cd('/data/taos/log'): + conn1.run('sudo rm -rf *') + +with conn1.cd('/data/taos/data'): + conn1.run('sudo rm -rf *') + +#lanuch taosd and start taosdemo +conn1.run("sudo systemctl start taosd") +time.sleep(5) +with conn1.cd('~/bschang_test'): + conn1.run('taosdemo -f manual_change_time_1_1_A.json') + +#force everything onto disk +conn1.run("sudo systemctl restart taosd") +time.sleep(10) + +#change lyq-1 to 2020/10/25 for testing if the server +#will send data that is out of time range +conn1.run('sudo timedatectl set-time 2020-10-25') + +#connect to VM lyq-2, initalize the environment at lyq-2, and run taosd +#on that +conn2 = Connection("{}@{}".format('ubuntu', "192.168.1.126"), connect_kwargs={"password": "{}".format('tbase125!')}) +conn2.run('sudo timedatectl set-ntp off') +conn2.run('sudo timedatectl set-time 2020-10-20') +conn2.run("sudo systemctl stop taosd") +with conn2.cd('/data/taos/log'): + conn2.run('sudo rm -rf *') +with conn2.cd('/data/taos/data'): + conn2.run('sudo rm -rf *') +conn2.run("sudo systemctl start taosd") + +#set replica to 2 +connTaos = taos.connect(host = '192.168.1.125', user = 'root', password = 'taosdata', cnfig = '/etc/taos') +c1 = connTaos.cursor() +c1.execute('create dnode \'lyq-2:6030\'') +c1.execute('alter database db replica 2') +c1.close() +connTaos.close() +time.sleep(5) + +#force everything onto the disk for lyq-2 +#stopping taosd on lyq-1 for future testing +conn2.run("sudo systemctl stop taosd") +conn1.run("sudo systemctl stop taosd") + +#reset the time +conn1.run('sudo timedatectl set-ntp on') +conn2.run('sudo timedatectl set-ntp on') +os.system('sudo timedatectl set-ntp on') + +#check if the number of file received is 7 +#the 4 oldest data files should be dropped +#4 files because of moving 5 days ahead +with conn2.cd('/data/taos/data/vnode/vnode3/tsdb/data'): + result = conn2.run('ls -l |grep \'data\' |wc -l') + if result.stdout.strip() != '7': + tdLog.exit('the file number is wrong') + else: + tdLog.success('the file number is the same. test pass') diff --git a/tests/pytest/manualTest/manual_change_time_3.py b/tests/pytest/manualTest/manual_change_time_3.py new file mode 100644 index 0000000000000000000000000000000000000000..a288147b56dd9bd1c98b354e347cfd7ac05fce38 --- /dev/null +++ b/tests/pytest/manualTest/manual_change_time_3.py @@ -0,0 +1,97 @@ +################################################################### +# Copyright (c) 2016 by TAOS Technologies, Inc. +# All rights reserved. +# +# This file is proprietary and confidential to TAOS Technologies. +# No part of this file may be reproduced, stored, transmitted, +# disclosed or used in any form or by any means other than as +# expressly provided by the written permission from Jianhui Tao +# +################################################################### + +# -*- coding: utf-8 -*- +from fabric import Connection +import sys +from util.log import * +from util.cases import * +from util.sql import * +from util.dnodes import tdDnodes +from datetime import datetime +import subprocess +import time +import taos + +##TODO: this is now automatic, but not sure if this will run through jenkins + +#the initial time used for this test is 2020/10/20 + +#setting local machine's time for later connecting to the server +os.system('sudo timedatectl set-ntp off') +os.system('sudo timedatectl set-time 2020-10-20') + +#connect to VM lyq-1, and initalize the environment at lyq-1 +conn1 = Connection("{}@{}".format('ubuntu', "192.168.1.125"), connect_kwargs={"password": "{}".format('tbase125!')}) +conn1.run("sudo systemctl stop taosd") +conn1.run('sudo timedatectl set-ntp off') +conn1.run('sudo timedatectl set-time 2020-10-20') +with conn1.cd('/data/taos/log'): + conn1.run('sudo rm -rf *') + +with conn1.cd('/data/taos/data'): + conn1.run('sudo rm -rf *') + +#lanuch taosd and start taosdemo +conn1.run("sudo systemctl start taosd") +time.sleep(5) +with conn1.cd('~/bschang_test'): + conn1.run('taosdemo -f manual_change_time_1_1_A.json') #the json file is placed in lyq-1 already + +#force everything onto disk +conn1.run("sudo systemctl restart taosd") +time.sleep(10) + +#connect to VM lyq-2, and initalize the environment at lyq-2 +conn2 = Connection("{}@{}".format('ubuntu', "192.168.1.126"), connect_kwargs={"password": "{}".format('tbase125!')}) +conn2.run('sudo timedatectl set-ntp off') +conn2.run('sudo timedatectl set-time 2020-10-20') +conn2.run("sudo systemctl stop taosd") +with conn2.cd('/data/taos/log'): + conn2.run('sudo rm -rf *') +with conn2.cd('/data/taos/data'): + conn2.run('sudo rm -rf *') + +#the date of lyq-2 is going to be set to 2020/10/25 +#for testing if other pnode will accpet file out of local time range +conn2.run("sudo systemctl start taosd") +conn2.run('sudo timedatectl set-time 2020-10-25') + +#set the replica to 2 +connTaos = taos.connect(host = '192.168.1.125', user = 'root', password = 'taosdata', cnfig = '/etc/taos') +c1 = connTaos.cursor() +c1.execute('create dnode \'lyq-2:6030\'') +c1.execute('alter database db replica 2') +time.sleep(5) + +#force everything onto the disk for lyq-2 +#stopping taosd on lyq-1 for future testing +conn2.run("sudo systemctl stop taosd") +conn1.run("sudo systemctl stop taosd") + +#reset the time +conn1.run('sudo timedatectl set-ntp on') +conn2.run('sudo timedatectl set-ntp on') +os.system('sudo timedatectl set-ntp on') + +#check if the number of file received is 7 +#the 4 oldest data files should be dropped +#4 files because of moving 5 days ahead +with conn2.cd('/data/taos/data/vnode/vnode3/tsdb/data'): + result = conn2.run('ls -l |grep \'data\' |wc -l') + if result.stdout.strip() != '7': + tdLog.exit('the file number is wrong') + else: + tdLog.success('the file number is the same. test pass') + +c1.close() +connTaos.close() + diff --git a/tests/pytest/query/in.py b/tests/pytest/query/in.py new file mode 100644 index 0000000000000000000000000000000000000000..8644b74a45099fcaa7c7608d8d33140b0a30f82f --- /dev/null +++ b/tests/pytest/query/in.py @@ -0,0 +1,163 @@ +################################################################### +# Copyright (c) 2016 by TAOS Technologies, Inc. +# All rights reserved. +# +# This file is proprietary and confidential to TAOS Technologies. +# No part of this file may be reproduced, stored, transmitted, +# disclosed or used in any form or by any means other than as +# expressly provided by the written permission from Jianhui Tao +# +################################################################### + +# -*- coding: utf-8 -*- + +import sys +import taos +from util.log import tdLog +from util.cases import tdCases +from util.sql import tdSql +from util.dnodes import tdDnodes + +class TDTestCase: + def init(self, conn, logSql): + tdLog.debug("start to execute %s" % __file__) + tdSql.init(conn.cursor(), logSql) + + self.ts = 1538548685000 + + def run(self): + tdSql.prepare() + + print("==============step1") + tdSql.execute( + "create table if not exists st (ts timestamp, tagtype int) tags(dev nchar(50))") + tdSql.execute( + 'CREATE TABLE if not exists dev_001 using st tags("dev_01")') + tdSql.execute( + 'CREATE TABLE if not exists dev_002 using st tags("dev_02")') + + print("==============step2") + tdSql.error("select * from db.st where ts in ('2020-05-13 10:00:00.000')") + + tdSql.execute( + """INSERT INTO dev_001(ts, tagtype) VALUES('2020-05-13 10:00:00.000', 1), + ('2020-05-13 10:00:00.001', 1) + dev_002 VALUES('2020-05-13 10:00:00.001', 1)""") + + # TAG nchar + tdSql.query('select count(ts) from db.st where dev in ("dev_01")') + tdSql.checkRows(1) + tdSql.checkData(0, 0, 2) + + tdSql.query('select count(ts) from db.st where dev in ("dev_01", "dev_01")') + tdSql.checkRows(1) + tdSql.checkData(0, 0, 2) + + tdSql.query('select count(ts) from db.st where dev in ("dev_01", "dev_01", "dev_02")') + tdSql.checkRows(1) + tdSql.checkData(0, 0, 3) + + + # colume int + tdSql.query("select count(ts) from db.st where tagtype in (1)") + tdSql.checkRows(1) + tdSql.checkData(0, 0, 3) + + tdSql.query("select count(ts) from db.st where tagtype in (1, 2)") + tdSql.checkRows(1) + tdSql.checkData(0, 0, 3) + tdSql.execute( + """INSERT INTO dev_001(ts, tagtype) VALUES('2020-05-13 10:00:01.000', 2), + ('2020-05-13 10:00:02.001', 2) + dev_002 VALUES('2020-05-13 10:00:03.001', 2)""") + + tdSql.query("select count(ts) from db.st where tagtype in (1, 2)") + tdSql.checkRows(1) + tdSql.checkData(0, 0, 6) + + tdSql.execute("create table tb(ts timestamp, c1 int, c2 binary(10), c3 nchar(10), c4 float, c5 bool)") + for i in range(10): + tdSql.execute("insert into tb values(%d, %d, 'binary%d', 'nchar%d', %f, %d)" % (self.ts + i, i, i, i, i + 0.1, i % 2)) + + #binary + tdSql.query('select count(ts) from db.tb where c2 in ("binary1")') + tdSql.checkRows(1) + tdSql.checkData(0, 0, 1) + + tdSql.query('select count(ts) from db.tb where c2 in ("binary1", "binary2", "binary1")') + tdSql.checkRows(1) + tdSql.checkData(0, 0, 2) + + #bool + #tdSql.query('select count(ts) from db.tb where c5 in (true)') + #tdSql.checkRows(1) + #tdSql.checkData(0, 0, 5) + + #float + #tdSql.query('select count(ts) from db.tb where c4 in (0.1)') + #tdSql.checkRows(1) + #tdSql.checkData(0, 0, 1) + + #nchar + tdSql.query('select count(ts) from db.tb where c3 in ("nchar0")') + tdSql.checkRows(1) + tdSql.checkData(0, 0, 1) + + + #tdSql.query("select tbname, dev from dev_001") + #tdSql.checkRows(1) + #tdSql.checkData(0, 0, 'dev_001') + #tdSql.checkData(0, 1, 'dev_01') + + #tdSql.query("select tbname, dev, tagtype from dev_001") + #tdSql.checkRows(2) + + ### test case for https://jira.taosdata.com:18080/browse/TD-1930 + #tdSql.execute("create table tb(ts timestamp, c1 int, c2 binary(10), c3 nchar(10), c4 float, c5 bool)") + #for i in range(10): + # tdSql.execute("insert into tb values(%d, %d, 'binary%d', 'nchar%d', %f, %d)" % (self.ts + i, i, i, i, i + 0.1, i % 2)) + # + #tdSql.error("select * from tb where c2 = binary2") + #tdSql.error("select * from tb where c3 = nchar2") + + #tdSql.query("select * from tb where c2 = 'binary2' ") + #tdSql.checkRows(1) + + #tdSql.query("select * from tb where c3 = 'nchar2' ") + #tdSql.checkRows(1) + + #tdSql.query("select * from tb where c1 = '2' ") + #tdSql.checkRows(1) + + #tdSql.query("select * from tb where c1 = 2 ") + #tdSql.checkRows(1) + + #tdSql.query("select * from tb where c4 = '0.1' ") + #tdSql.checkRows(1) + + #tdSql.query("select * from tb where c4 = 0.1 ") + #tdSql.checkRows(1) + + #tdSql.query("select * from tb where c5 = true ") + #tdSql.checkRows(5) + + #tdSql.query("select * from tb where c5 = 'true' ") + #tdSql.checkRows(5) + + ## For jira: https://jira.taosdata.com:18080/browse/TD-2850 + #tdSql.execute("create database 'Test' ") + #tdSql.execute("use 'Test' ") + #tdSql.execute("create table 'TB'(ts timestamp, 'Col1' int) tags('Tag1' int)") + #tdSql.execute("insert into 'Tb0' using tb tags(1) values(now, 1)") + #tdSql.query("select * from tb") + #tdSql.checkRows(1) + + + + def stop(self): + tdSql.close() + tdLog.success("%s successfully executed" % __file__) + + +tdCases.addWindows(__file__, TDTestCase()) +tdCases.addLinux(__file__, TDTestCase()) diff --git a/tests/pytest/query/last_row_cache.py b/tests/pytest/query/last_row_cache.py index a0e81477096e9c846e109ae71020b40e47b39a84..83153841496b9ef4e0b7d919b44cf0a9e05b02c6 100644 --- a/tests/pytest/query/last_row_cache.py +++ b/tests/pytest/query/last_row_cache.py @@ -25,7 +25,7 @@ class TDTestCase: self.tables = 10 self.rows = 20 - self.columns = 50 + self.columns = 5 self.perfix = 't' self.ts = 1601481600000 @@ -34,7 +34,7 @@ class TDTestCase: sql = "create table st(ts timestamp, " for i in range(self.columns - 1): sql += "c%d int, " % (i + 1) - sql += "c50 int) tags(t1 int)" + sql += "c5 int) tags(t1 int)" tdSql.execute(sql) for i in range(self.tables): @@ -141,28 +141,56 @@ class TDTestCase: def run(self): tdSql.prepare() - print("============== last_row_cache_0.sim") + print("============== Step1: last_row_cache_0.sim") tdSql.execute("create database test1 cachelast 0") tdSql.execute("use test1") self.insertData() self.executeQueries() self.insertData2() self.executeQueries2() - - print("============== alter last cache") + + print("============== Step2: alter database test1 cachelast 1") tdSql.execute("alter database test1 cachelast 1") self.executeQueries2() + + print("============== Step3: alter database test1 cachelast 2") + tdSql.execute("alter database test1 cachelast 2") + self.executeQueries2() + + print("============== Step4: alter database test1 cachelast 3") + tdSql.execute("alter database test1 cachelast 3") + self.executeQueries2() + + + print("============== Step5: alter database test1 cachelast 0 and restart taosd") + tdSql.execute("alter database test1 cachelast 0") + self.executeQueries2() + tdDnodes.stop(1) + tdDnodes.start(1) + self.executeQueries2() + + print("============== Step6: alter database test1 cachelast 1 and restart taosd") + tdSql.execute("alter database test1 cachelast 1") + self.executeQueries2() + tdDnodes.stop(1) + tdDnodes.start(1) + self.executeQueries2() + + print("============== Step7: alter database test1 cachelast 2 and restart taosd") + tdSql.execute("alter database test1 cachelast 2") + self.executeQueries2() tdDnodes.stop(1) tdDnodes.start(1) self.executeQueries2() - tdSql.execute("alter database test1 cachelast 0") + print("============== Step8: alter database test1 cachelast 3 and restart taosd") + tdSql.execute("alter database test1 cachelast 3") self.executeQueries2() tdDnodes.stop(1) tdDnodes.start(1) self.executeQueries2() - print("============== last_row_cache_1.sim") + print("============== Step9: create database test2 cachelast 1") tdSql.execute("create database test2 cachelast 1") tdSql.execute("use test2") self.insertData() @@ -173,18 +201,54 @@ class TDTestCase: tdDnodes.start(1) self.executeQueries2() + print("============== Step8: alter database test2 cachelast 0") tdSql.execute("alter database test2 cachelast 0") + self.executeQueries2() + + print("============== Step9: alter database test2 cachelast 1") + tdSql.execute("alter database test2 cachelast 1") + self.executeQueries2() + + print("============== Step10: alter database test2 cachelast 2") + tdSql.execute("alter database test2 cachelast 2") + self.executeQueries2() + + print("============== Step11: alter database test2 cachelast 3") + tdSql.execute("alter database test2 cachelast 3") self.executeQueries2() + + print("============== Step12: alter database test2 cachelast 0 and restart taosd") + tdSql.execute("alter database test2 cachelast 0") + self.executeQueries2() tdDnodes.stop(1) tdDnodes.start(1) - self.executeQueries2() + self.executeQueries2() + print("============== Step13: alter database test2 cachelast 1 and restart taosd") tdSql.execute("alter database test2 cachelast 1") self.executeQueries2() tdDnodes.stop(1) tdDnodes.start(1) self.executeQueries2() + print("============== Step14: alter database test2 cachelast 2 and restart taosd") + tdSql.execute("alter database test2 cachelast 2") + self.executeQueries2() + tdDnodes.stop(1) + tdDnodes.start(1) + self.executeQueries2() + + print("============== Step15: alter database test2 cachelast 3 and restart taosd") + tdSql.execute("alter database test2 cachelast 3") + self.executeQueries2() + tdDnodes.stop(1) + tdDnodes.start(1) + self.executeQueries2() + + print("============== Step16: select last_row(*) from st group by tbname") + tdSql.query("select last_row(*) from st group by tbname") + tdSql.checkRows(10) + def stop(self): tdSql.close() tdLog.success("%s successfully executed" % __file__) diff --git a/tests/pytest/query/querySession.py b/tests/pytest/query/querySession.py new file mode 100644 index 0000000000000000000000000000000000000000..53d53e2b02efbcc1212f8ef64f3b89a9cce03e13 --- /dev/null +++ b/tests/pytest/query/querySession.py @@ -0,0 +1,129 @@ +################################################################### +# Copyright (c) 2016 by TAOS Technologies, Inc. +# All rights reserved. +# +# This file is proprietary and confidential to TAOS Technologies. +# No part of this file may be reproduced, stored, transmitted, +# disclosed or used in any form or by any means other than as +# expressly provided by the written permission from Jianhui Tao +# +################################################################### + +# -*- coding: utf-8 -*- + +import sys +import taos +from util.log import * +from util.cases import * +from util.sql import * + + +class TDTestCase: + def init(self, conn, logSql): + tdLog.debug("start to execute %s" % __file__) + tdSql.init(conn.cursor()) + + def run(self): + tdSql.prepare() + + print("==============step1") + tdSql.execute( + "create table if not exists st (ts timestamp, tagtype int) tags(dev nchar(50), tag2 binary(16))") + tdSql.execute( + 'CREATE TABLE if not exists dev_001 using st tags("dev_01", "tag_01")') + tdSql.execute( + 'CREATE TABLE if not exists dev_002 using st tags("dev_02", "tag_02")') + + print("==============step2") + + tdSql.execute( + """INSERT INTO dev_001 VALUES('2020-05-13 10:00:00.000', 1)('2020-05-13 10:00:00.005', 2)('2020-05-13 10:00:00.011', 3) + ('2020-05-13 10:00:01.011', 4)('2020-05-13 10:00:01.611', 5)('2020-05-13 10:00:02.612', 6) + ('2020-05-13 10:01:02.612', 7)('2020-05-13 10:02:02.612', 8)('2020-05-13 10:03:02.613', 9) + ('2020-05-13 11:00:00.000', 10)('2020-05-13 12:00:00.000', 11)('2020-05-13 13:00:00.001', 12) + ('2020-05-14 13:00:00.001', 13)('2020-05-15 14:00:00.000', 14)('2020-05-20 10:00:00.000', 15) + ('2020-05-27 10:00:00.001', 16) dev_002 VALUES('2020-05-13 10:00:00.000', 1)('2020-05-13 10:00:00.005', 2)('2020-05-13 10:00:00.009', 3)('2020-05-13 10:00:00.0021', 4) + ('2020-05-13 10:00:00.031', 5)('2020-05-13 10:00:00.036', 6)('2020-05-13 10:00:00.51', 7) + """) + + # session(ts,5a) + tdSql.query("select count(*) from dev_001 session(ts,5a)") + tdSql.checkRows(15) + tdSql.checkData(0, 1, 2) + + + # session(ts,1s) + tdSql.query("select count(*) from dev_001 session(ts,1s)") + tdSql.checkRows(12) + tdSql.checkData(0, 1, 5) + + tdSql.query("select count(*) from dev_001 session(ts,1000a)") + tdSql.checkRows(12) + tdSql.checkData(0, 1, 5) + + # session(ts,1m) + tdSql.query("select count(*) from dev_001 session(ts,1m)") + tdSql.checkRows(9) + tdSql.checkData(0, 1, 8) + + # session(ts,1h) + tdSql.query("select count(*) from dev_001 session(ts,1h)") + tdSql.checkRows(6) + tdSql.checkData(0, 1, 11) + + # session(ts,1d) + tdSql.query("select count(*) from dev_001 session(ts,1d)") + tdSql.checkRows(4) + tdSql.checkData(0, 1, 13) + + # session(ts,1w) + tdSql.query("select count(*) from dev_001 session(ts,1w)") + tdSql.checkRows(2) + tdSql.checkData(0, 1, 15) + + # session with where + tdSql.query("select count(*),first(tagtype),last(tagtype),avg(tagtype),sum(tagtype),min(tagtype),max(tagtype),leastsquares(tagtype, 1, 1),spread(tagtype),stddev(tagtype),percentile(tagtype,0) from dev_001 where ts <'2020-05-20 0:0:0' session(ts,1d)") + tdSql.checkRows(2) + tdSql.checkData(0, 1, 13) + tdSql.checkData(0, 2, 1) + tdSql.checkData(0, 3, 13) + tdSql.checkData(0, 4, 7) + tdSql.checkData(0, 5, 91) + tdSql.checkData(0, 6, 1) + tdSql.checkData(0, 7, 13) + tdSql.checkData(0, 8, '{slop:1.000000, intercept:0.000000}') + tdSql.checkData(0, 9, 12) + tdSql.checkData(0, 10, 3.741657387) + tdSql.checkData(0, 11, 1) + tdSql.checkData(1, 11, 14) + + # tdsql err + tdSql.error("select * from dev_001 session(ts,1w)") + tdSql.error("select count(*) from st session(ts,1w)") + tdSql.error("select count(*) from dev_001 group by tagtype session(ts,1w) ") + tdSql.error("select count(*) from dev_001 session(ts,1n)") + tdSql.error("select count(*) from dev_001 session(ts,1y)") + tdSql.error("select count(*) from dev_001 session(ts,0s)") + tdSql.error("select count(*) from dev_001 session(i,1y)") + tdSql.error("select count(*) from dev_001 session(ts,1d) where ts <'2020-05-20 0:0:0'") + + #test precision us + tdSql.execute("create database test precision 'us'") + tdSql.execute("use test") + tdSql.execute("create table dev_001 (ts timestamp ,i timestamp ,j int)") + tdSql.execute("insert into dev_001 values(1623046993681000,now,1)(1623046993681001,now+1s,2)(1623046993681002,now+2s,3)(1623046993681004,now+5s,4)") + + # session(ts,1u) + tdSql.query("select count(*) from dev_001 session(ts,1u)") + tdSql.checkRows(2) + tdSql.checkData(0, 1, 3) + tdSql.error("select count(*) from dev_001 session(i,1s)") + + + def stop(self): + tdSql.close() + tdLog.success("%s successfully executed" % __file__) + + +tdCases.addWindows(__file__, TDTestCase()) +tdCases.addLinux(__file__, TDTestCase()) diff --git a/tests/pytest/query/subqueryFilter.py b/tests/pytest/query/subqueryFilter.py new file mode 100644 index 0000000000000000000000000000000000000000..5dca08b458dbe33a33dc3c93fd72478758c96915 --- /dev/null +++ b/tests/pytest/query/subqueryFilter.py @@ -0,0 +1,123 @@ +################################################################### +# Copyright (c) 2016 by TAOS Technologies, Inc. +# All rights reserved. +# +# This file is proprietary and confidential to TAOS Technologies. +# No part of this file may be reproduced, stored, transmitted, +# disclosed or used in any form or by any means other than as +# expressly provided by the written permission from Jianhui Tao +# +################################################################### + +# -*- coding: utf-8 -*- + +import sys +import taos +from util.log import tdLog +from util.cases import tdCases +from util.sql import tdSql +from util.dnodes import tdDnodes + +class TDTestCase: + def init(self, conn, logSql): + tdLog.debug("start to execute %s" % __file__) + tdSql.init(conn.cursor(), logSql) + + self.ts = 1601481600000 + self.tables = 10 + self.perfix = 'dev' + + def insertData(self): + print("==============step1") + tdSql.execute( + "create table if not exists st (ts timestamp, tagtype int) tags(dev nchar(50))") + + for i in range(self.tables): + tdSql.execute("create table %s%d using st tags(%d)" % (self.perfix, i, i)) + rows = 15 + i + for j in range(rows): + tdSql.execute("insert into %s%d values(%d, %d)" %(self.perfix, i, self.ts + i * 20 * 10000 + j * 10000, j)) + + def run(self): + tdSql.prepare() + + self.insertData() + + tdSql.query("select count(*) val from st group by tbname") + tdSql.checkRows(10) + + tdSql.query("select * from (select count(*) val from st group by tbname)") + tdSql.checkRows(10) + + tdSql.query("select * from (select count(*) val from st group by tbname) a where a.val < 20") + tdSql.checkRows(5) + + tdSql.query("select * from (select count(*) val from st group by tbname) a where a.val > 20") + tdSql.checkRows(4) + + tdSql.query("select * from (select count(*) val from st group by tbname) a where a.val = 20") + tdSql.checkRows(1) + + tdSql.query("select * from (select count(*) val from st group by tbname) a where a.val <= 20") + tdSql.checkRows(6) + + tdSql.query("select * from (select count(*) val from st group by tbname) a where a.val >= 20") + tdSql.checkRows(5) + + tdSql.query("select count(*) from (select first(tagtype) val from st interval(30s)) a where a.val > 20") + tdSql.checkRows(1) + tdSql.checkData(0, 0, 1) + + tdSql.query("select count(*) from (select first(tagtype) val from st interval(30s)) a where a.val >= 20") + tdSql.checkData(0, 0, 2) + + tdSql.query("select count(*) from (select first(tagtype) val from st interval(30s)) a where a.val < 20") + tdSql.checkData(0, 0, 63) + + tdSql.query("select count(*) from (select first(tagtype) val from st interval(30s)) a where a.val <= 20") + tdSql.checkData(0, 0, 64) + + tdSql.query("select count(*) from (select first(tagtype) val from st interval(30s)) a where a.val = 20") + tdSql.checkData(0, 0, 1) + + tdSql.query("select count(*) from (select first(tagtype) val from st interval(30s)) a where a.val > 20") + tdSql.checkData(0, 0, 1) + + tdSql.query("select count(*) from (select first(tagtype) val from st interval(30s)) a where a.val >= 20") + tdSql.checkData(0, 0, 2) + + tdSql.query("select count(*) from (select first(tagtype) val from st interval(30s)) a where a.val < 20") + tdSql.checkData(0, 0, 63) + + tdSql.query("select count(*) from (select first(tagtype) val from st interval(30s)) a where a.val <= 20") + tdSql.checkData(0, 0, 64) + + tdSql.query("select count(*) from (select first(tagtype) val from st interval(30s)) a where a.val = 20") + tdSql.checkData(0, 0, 1) + + tdSql.query("select count(*) from (select last(tagtype) val from st interval(30s)) a where a.val > 20") + tdSql.checkData(0, 0, 3) + + tdSql.query("select count(*) from (select last(tagtype) val from st interval(30s)) a where a.val >= 20") + tdSql.checkData(0, 0, 5) + + tdSql.query("select count(*) from (select last(tagtype) val from st interval(30s)) a where a.val < 20") + tdSql.checkData(0, 0, 60) + + tdSql.query("select count(*) from (select last(tagtype) val from st interval(30s)) a where a.val <= 20") + tdSql.checkData(0, 0, 62) + + tdSql.query("select count(*) from (select last(tagtype) val from st interval(30s)) a where a.val = 20") + tdSql.checkData(0, 0, 2) + + + + + + def stop(self): + tdSql.close() + tdLog.success("%s successfully executed" % __file__) + + +tdCases.addWindows(__file__, TDTestCase()) +tdCases.addLinux(__file__, TDTestCase()) diff --git a/tests/pytest/stream/table_1.py b/tests/pytest/stream/table_1.py index a9fd57393112177fe0e290cadeaabd97d669daca..b205491fad181a51c991c16da65baa8370174e74 100644 --- a/tests/pytest/stream/table_1.py +++ b/tests/pytest/stream/table_1.py @@ -51,7 +51,7 @@ class TDTestCase: tdSql.execute( "insert into tb%d values (now - %dm, %d, %d)" % (i, 1440 - j, j, j)) - time.sleep(0.1) + time.sleep(1) self.createFuncStream("count(*)", "c1", rowNum) self.createFuncStream("count(tbcol)", "c2", rowNum) diff --git a/tests/pytest/tag_lite/3.py b/tests/pytest/tag_lite/3.py index 373db1c70fcc67eec7f4abae4e6264cad7fddf64..bbdf0868fae6d465525dbe7191172b4145b53f80 100644 --- a/tests/pytest/tag_lite/3.py +++ b/tests/pytest/tag_lite/3.py @@ -60,14 +60,14 @@ class TDTestCase: x = 0 while (x < rowNum): - ms = "%dm" % x - # TSIM: sql insert into $tb values (now + $ms , $x ) + ms = x * 60000 + # TSIM: sql insert into $tb values (1605045600000 + $ms , $x ) tdLog.info( - "insert into %s values (now + %s, %d)" % - (tb, ms, x)) + "insert into %s values (%d, %d)" % + (tb, 1605045600000 + ms, x)) tdSql.execute( - "insert into %s values (now + %s, %d)" % - (tb, ms, x)) + "insert into %s values (%d, %d)" % + (tb, 1605045600000 + ms, x)) x = x + 1 # TSIM: endw i = i + 1 @@ -81,13 +81,13 @@ class TDTestCase: (tb, mt)) x = 0 while (x < rowNum): - ms = "%dm" % x + ms = x * 60000 tdLog.info( - "insert into %s values (now + %s, %d)" % - (tb, ms, x)) + "insert into %s values (%d, %d)" % + (tb, 1605045600000 + ms, x)) tdSql.execute( - "insert into %s values (now + %s, %d)" % - (tb, ms, x)) + "insert into %s values (%d, %d)" % + (tb, 1605045600000 + ms, x)) x = x + 1 # TSIM: endw i = i + 1 @@ -104,36 +104,36 @@ class TDTestCase: # TSIM: return -1 # TSIM: endi # TSIM: - # TSIM: sql select * from %s where ts < now + 4m - tdLog.info('select * from %s where ts < now + 4m' % mt) - tdSql.query('select * from %s where ts < now + 4m' % mt) + # TSIM: sql select * from %s where ts < 1605045600000 + 240001 + tdLog.info('select * from %s where ts < 1605045600000 + 240001' % mt) + tdSql.query('select * from %s where ts < 1605045600000 + 240001' % mt) # TSIM: if $rows != 50 then tdLog.info('tdSql.checkRow(50)') tdSql.checkRows(50) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from %s where ts > now + 4m - tdLog.info('select * from %s where ts > now + 4m' % mt) - tdSql.query('select * from %s where ts > now + 4m' % mt) + # TSIM: sql select * from %s where ts > 1605045600000 + 240001 + tdLog.info('select * from %s where ts > 1605045600000 + 240001' % mt) + tdSql.query('select * from %s where ts > 1605045600000 + 240001' % mt) # TSIM: if $rows != 150 then tdLog.info('tdSql.checkRow(150)') tdSql.checkRows(150) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from %s where ts = now + 4m - tdLog.info('select * from %s where ts = now + 4m' % mt) - tdSql.query('select * from %s where ts = now + 4m' % mt) + # TSIM: sql select * from %s where ts = 1605045600000 + 240001 + tdLog.info('select * from %s where ts = 1605045600000 + 240001' % mt) + tdSql.query('select * from %s where ts = 1605045600000 + 240001' % mt) # TSIM: if $rows != 0 then tdLog.info('tdSql.checkRow(0)') tdSql.checkRows(0) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from %s where ts > now + 4m and ts < now + 5m + # TSIM: sql select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 tdLog.info( - 'select * from %s where ts > now + 4m and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001' % mt) tdSql.query( - 'select * from %s where ts > now + 4m and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001' % mt) tdLog.info('tdSql.checkRow(10)') tdSql.checkRows(10) @@ -267,91 +267,91 @@ class TDTestCase: # TSIM: # TSIM: print =============== step6 tdLog.info('=============== step6') - # TSIM: sql select * from %s where ts > now + 4m and tgcol1 = true + # TSIM: sql select * from %s where ts > 1605045600000 + 240001 and tgcol1 = true tdLog.info( - 'select * from %s where ts > now + 4m and tgcol1 = true' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol1 = true' % mt) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol1 = true' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol1 = true' % mt) tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from %s where ts > now + 4m and tgcol1 <> true + # TSIM: sql select * from %s where ts > 1605045600000 + 240001 and tgcol1 <> true tdLog.info( - 'select * from %s where ts > now + 4m and tgcol1 <> true' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol1 <> true' % mt) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol1 <> true' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol1 <> true' % mt) tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from %s where ts < now + 4m and tgcol1 = false + # TSIM: sql select * from %s where ts < 1605045600000 + 240001 and tgcol1 = false tdLog.info( - 'select * from %s where ts < now + 4m and tgcol1 = false' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol1 = false' % mt) tdSql.query( - 'select * from %s where ts < now + 4m and tgcol1 = false' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol1 = false' % mt) tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from %s where ts < now + 4m and tgcol1 <> false + # TSIM: sql select * from %s where ts < 1605045600000 + 240001 and tgcol1 <> false tdLog.info( - 'select * from %s where ts < now + 4m and tgcol1 <> false' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol1 <> false' % mt) tdSql.query( - 'select * from %s where ts < now + 4m and tgcol1 <> false' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol1 <> false' % mt) tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from %s where ts <= now + 4m and tgcol1 = false + # TSIM: sql select * from %s where ts <= 1605045600000 + 240001 and tgcol1 = false tdLog.info( - 'select * from %s where ts <= now + 4m and tgcol1 = false' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol1 = false' % mt) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol1 = false' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol1 = false' % mt) tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from %s where ts <= now + 4m and tgcol1 <> false + # TSIM: sql select * from %s where ts <= 1605045600000 + 240001 and tgcol1 <> false tdLog.info( - 'select * from %s where ts <= now + 4m and tgcol1 <> false' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol1 <> false' % mt) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol1 <> false' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol1 <> false' % mt) tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from %s where ts > now + 4m and ts < now + 5m and + # TSIM: sql select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and # tgcol1 <> false tdLog.info( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol1 <> false' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol1 <> false' % mt) tdSql.query( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol1 <> false' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol1 <> false' % mt) tdLog.info('tdSql.checkRow(5)') tdSql.checkRows(5) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from %s where ts > now + 4m and tgcol1 <> false - # and ts < now + 5m + # TSIM: sql select * from %s where ts > 1605045600000 + 240001 and tgcol1 <> false + # and ts < 1605045600000 + 300001 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol1 <> false and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol1 <> false and ts < 1605045600000 + 300001' % mt) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol1 <> false and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol1 <> false and ts < 1605045600000 + 300001' % mt) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') @@ -361,84 +361,84 @@ class TDTestCase: # TSIM: # TSIM: print =============== step7 tdLog.info('=============== step7') - # TSIM: sql select * from %s where ts > now + 4m and tgcol2 = 1 - tdLog.info('select * from %s where ts > now + 4m and tgcol2 = 1' % mt) - tdSql.query('select * from %s where ts > now + 4m and tgcol2 = 1' % mt) + # TSIM: sql select * from %s where ts > 1605045600000 + 240001 and tgcol2 = 1 + tdLog.info('select * from %s where ts > 1605045600000 + 240001 and tgcol2 = 1' % mt) + tdSql.query('select * from %s where ts > 1605045600000 + 240001 and tgcol2 = 1' % mt) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from %s where ts > now + 4m and tgcol2 <> 1 - tdLog.info('select * from %s where ts > now + 4m and tgcol2 <> 1' % mt) + # TSIM: sql select * from %s where ts > 1605045600000 + 240001 and tgcol2 <> 1 + tdLog.info('select * from %s where ts > 1605045600000 + 240001 and tgcol2 <> 1' % mt) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol2 <> 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol2 <> 1' % mt) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from %s where ts < now + 4m and tgcol2 = 0 - tdLog.info('select * from %s where ts < now + 4m and tgcol2 = 0' % mt) - tdSql.query('select * from %s where ts < now + 4m and tgcol2 = 0' % mt) + # TSIM: sql select * from %s where ts < 1605045600000 + 240001 and tgcol2 = 0 + tdLog.info('select * from %s where ts < 1605045600000 + 240001 and tgcol2 = 0' % mt) + tdSql.query('select * from %s where ts < 1605045600000 + 240001 and tgcol2 = 0' % mt) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from %s where ts < now + 4m and tgcol2 <> 0 - tdLog.info('select * from %s where ts < now + 4m and tgcol2 <> 0' % mt) + # TSIM: sql select * from %s where ts < 1605045600000 + 240001 and tgcol2 <> 0 + tdLog.info('select * from %s where ts < 1605045600000 + 240001 and tgcol2 <> 0' % mt) tdSql.query( - 'select * from %s where ts < now + 4m and tgcol2 <> 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol2 <> 0' % mt) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from %s where ts <= now + 4m and tgcol2 = 0 - tdLog.info('select * from %s where ts <= now + 4m and tgcol2 = 0' % mt) + # TSIM: sql select * from %s where ts <= 1605045600000 + 240001 and tgcol2 = 0 + tdLog.info('select * from %s where ts <= 1605045600000 + 240001 and tgcol2 = 0' % mt) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol2 = 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol2 = 0' % mt) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from %s where ts <= now + 4m and tgcol2 <> 0 + # TSIM: sql select * from %s where ts <= 1605045600000 + 240001 and tgcol2 <> 0 tdLog.info( - 'select * from %s where ts <= now + 4m and tgcol2 <> 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol2 <> 0' % mt) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol2 <> 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol2 <> 0' % mt) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from %s where ts > now + 4m and ts < now + 5m and + # TSIM: sql select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and # tgcol2 <> 0 tdLog.info( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol2 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol2 <> 0' % mt) tdSql.query( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol2 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol2 <> 0' % mt) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') tdSql.checkRows(5) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from %s where ts > now + 4m and tgcol2 <> 0 and ts - # < now + 5m + # TSIM: sql select * from %s where ts > 1605045600000 + 240001 and tgcol2 <> 0 and ts + # < 1605045600000 + 300001 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol2 <> 0 and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol2 <> 0 and ts < 1605045600000 + 300001' % mt) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol2 <> 0 and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol2 <> 0 and ts < 1605045600000 + 300001' % mt) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') @@ -448,84 +448,84 @@ class TDTestCase: # TSIM: # TSIM: print =============== step8 tdLog.info('=============== step8') - # TSIM: sql select * from %s where ts > now + 4m and tgcol3 = 1 - tdLog.info('select * from %s where ts > now + 4m and tgcol3 = 1' % mt) - tdSql.query('select * from %s where ts > now + 4m and tgcol3 = 1' % mt) + # TSIM: sql select * from %s where ts > 1605045600000 + 240001 and tgcol3 = 1 + tdLog.info('select * from %s where ts > 1605045600000 + 240001 and tgcol3 = 1' % mt) + tdSql.query('select * from %s where ts > 1605045600000 + 240001 and tgcol3 = 1' % mt) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from %s where ts > now + 4m and tgcol3 <> 1 - tdLog.info('select * from %s where ts > now + 4m and tgcol3 <> 1' % mt) + # TSIM: sql select * from %s where ts > 1605045600000 + 240001 and tgcol3 <> 1 + tdLog.info('select * from %s where ts > 1605045600000 + 240001 and tgcol3 <> 1' % mt) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol3 <> 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol3 <> 1' % mt) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from %s where ts < now + 4m and tgcol3 = 0 - tdLog.info('select * from %s where ts < now + 4m and tgcol3 = 0' % mt) - tdSql.query('select * from %s where ts < now + 4m and tgcol3 = 0' % mt) + # TSIM: sql select * from %s where ts < 1605045600000 + 240001 and tgcol3 = 0 + tdLog.info('select * from %s where ts < 1605045600000 + 240001 and tgcol3 = 0' % mt) + tdSql.query('select * from %s where ts < 1605045600000 + 240001 and tgcol3 = 0' % mt) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from %s where ts < now + 4m and tgcol3 <> 0 - tdLog.info('select * from %s where ts < now + 4m and tgcol3 <> 0' % mt) + # TSIM: sql select * from %s where ts < 1605045600000 + 240001 and tgcol3 <> 0 + tdLog.info('select * from %s where ts < 1605045600000 + 240001 and tgcol3 <> 0' % mt) tdSql.query( - 'select * from %s where ts < now + 4m and tgcol3 <> 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol3 <> 0' % mt) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from %s where ts <= now + 4m and tgcol3 = 0 - tdLog.info('select * from %s where ts <= now + 4m and tgcol3 = 0' % mt) + # TSIM: sql select * from %s where ts <= 1605045600000 + 240001 and tgcol3 = 0 + tdLog.info('select * from %s where ts <= 1605045600000 + 240001 and tgcol3 = 0' % mt) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol3 = 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol3 = 0' % mt) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from %s where ts <= now + 4m and tgcol3 <> 0 + # TSIM: sql select * from %s where ts <= 1605045600000 + 240001 and tgcol3 <> 0 tdLog.info( - 'select * from %s where ts <= now + 4m and tgcol3 <> 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol3 <> 0' % mt) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol3 <> 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol3 <> 0' % mt) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from %s where ts > now + 4m and ts < now + 5m and + # TSIM: sql select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and # tgcol3 <> 0 tdLog.info( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol3 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol3 <> 0' % mt) tdSql.query( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol3 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol3 <> 0' % mt) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') tdSql.checkRows(5) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from %s where ts > now + 4m and tgcol3 <> 0 and ts - # < now + 5m + # TSIM: sql select * from %s where ts > 1605045600000 + 240001 and tgcol3 <> 0 and ts + # < 1605045600000 + 300001 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol3 <> 0 and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol3 <> 0 and ts < 1605045600000 + 300001' % mt) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol3 <> 0 and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol3 <> 0 and ts < 1605045600000 + 300001' % mt) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') @@ -535,104 +535,104 @@ class TDTestCase: # TSIM: # TSIM: print =============== step9 tdLog.info('=============== step9') - # TSIM: sql select * from %s where ts > now + 4m and tgcol2 = 1 and + # TSIM: sql select * from %s where ts > 1605045600000 + 240001 and tgcol2 = 1 and # tgcol1 = true tdLog.info( - 'select * from %s where ts > now + 4m and tgcol2 = 1 and tgcol1 = true' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol2 = 1 and tgcol1 = true' % mt) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol2 = 1 and tgcol1 = true' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol2 = 1 and tgcol1 = true' % mt) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from %s where ts > now + 4m and tgcol2 <> 1 and + # TSIM: sql select * from %s where ts > 1605045600000 + 240001 and tgcol2 <> 1 and # tgcol1 <> true tdLog.info( - 'select * from %s where ts > now + 4m and tgcol2 <> 1 and tgcol1 <> true' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol2 <> 1 and tgcol1 <> true' % mt) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol2 <> 1 and tgcol1 <> true' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol2 <> 1 and tgcol1 <> true' % mt) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from %s where ts < now + 4m and tgcol2 = 0 and + # TSIM: sql select * from %s where ts < 1605045600000 + 240001 and tgcol2 = 0 and # tgcol1 = false tdLog.info( - 'select * from %s where ts < now + 4m and tgcol2 = 0 and tgcol1 = false' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol2 = 0 and tgcol1 = false' % mt) tdSql.query( - 'select * from %s where ts < now + 4m and tgcol2 = 0 and tgcol1 = false' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol2 = 0 and tgcol1 = false' % mt) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from %s where ts < now + 4m and tgcol2 <> 0 and + # TSIM: sql select * from %s where ts < 1605045600000 + 240001 and tgcol2 <> 0 and # tgcol1 <> false tdLog.info( - 'select * from %s where ts < now + 4m and tgcol2 <> 0 and tgcol1 <> false' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol2 <> 0 and tgcol1 <> false' % mt) tdSql.query( - 'select * from %s where ts < now + 4m and tgcol2 <> 0 and tgcol1 <> false' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol2 <> 0 and tgcol1 <> false' % mt) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from %s where ts <= now + 4m and tgcol2 = 0 and + # TSIM: sql select * from %s where ts <= 1605045600000 + 240001 and tgcol2 = 0 and # tgcol1 = false tdLog.info( - 'select * from %s where ts <= now + 4m and tgcol2 = 0 and tgcol1 = false' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol2 = 0 and tgcol1 = false' % mt) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol2 = 0 and tgcol1 = false' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol2 = 0 and tgcol1 = false' % mt) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from %s where ts <= now + 4m and tgcol2 <> 0 and + # TSIM: sql select * from %s where ts <= 1605045600000 + 240001 and tgcol2 <> 0 and # tgcol1 <> false tdLog.info( - 'select * from %s where ts <= now + 4m and tgcol2 <> 0 and tgcol1 <> false' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol2 <> 0 and tgcol1 <> false' % mt) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol2 <> 0 and tgcol1 <> false' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol2 <> 0 and tgcol1 <> false' % mt) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from %s where ts > now + 4m and ts < now + 5m and + # TSIM: sql select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and # tgcol2 <> 0 and tgcol1 <> false tdLog.info( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol2 <> 0 and tgcol1 <> false' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol2 <> 0 and tgcol1 <> false' % mt) tdSql.query( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol2 <> 0 and tgcol1 <> false' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol2 <> 0 and tgcol1 <> false' % mt) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') tdSql.checkRows(5) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from %s where ts > now + 4m and tgcol2 <> 0 and ts - # < now + 5m and ts < now + 5m and tgcol1 <> false + # TSIM: sql select * from %s where ts > 1605045600000 + 240001 and tgcol2 <> 0 and ts + # < 1605045600000 + 300001 and ts < 1605045600000 + 300001 and tgcol1 <> false tdLog.info( - 'select * from %s where ts > now + 4m and tgcol2 <> 0 and ts < now + 5m and ts < now + 5m and tgcol1 <> false' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol2 <> 0 and ts < 1605045600000 + 300001 and ts < 1605045600000 + 300001 and tgcol1 <> false' % mt) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol2 <> 0 and ts < now + 5m and ts < now + 5m and tgcol1 <> false' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol2 <> 0 and ts < 1605045600000 + 300001 and ts < 1605045600000 + 300001 and tgcol1 <> false' % mt) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') @@ -642,104 +642,104 @@ class TDTestCase: # TSIM: # TSIM: print =============== step10 tdLog.info('=============== step10') - # TSIM: sql select * from %s where ts > now + 4m and tgcol3 = 1 and + # TSIM: sql select * from %s where ts > 1605045600000 + 240001 and tgcol3 = 1 and # tgcol1 = true tdLog.info( - 'select * from %s where ts > now + 4m and tgcol3 = 1 and tgcol1 = true' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol3 = 1 and tgcol1 = true' % mt) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol3 = 1 and tgcol1 = true' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol3 = 1 and tgcol1 = true' % mt) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from %s where ts > now + 4m and tgcol3 <> 1 and + # TSIM: sql select * from %s where ts > 1605045600000 + 240001 and tgcol3 <> 1 and # tgcol1 <> true tdLog.info( - 'select * from %s where ts > now + 4m and tgcol3 <> 1 and tgcol1 <> true' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol3 <> 1 and tgcol1 <> true' % mt) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol3 <> 1 and tgcol1 <> true' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol3 <> 1 and tgcol1 <> true' % mt) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from %s where ts < now + 4m and tgcol3 = 0 and + # TSIM: sql select * from %s where ts < 1605045600000 + 240001 and tgcol3 = 0 and # tgcol1 = false tdLog.info( - 'select * from %s where ts < now + 4m and tgcol3 = 0 and tgcol1 = false' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol3 = 0 and tgcol1 = false' % mt) tdSql.query( - 'select * from %s where ts < now + 4m and tgcol3 = 0 and tgcol1 = false' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol3 = 0 and tgcol1 = false' % mt) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from %s where ts < now + 4m and tgcol3 <> 0 and + # TSIM: sql select * from %s where ts < 1605045600000 + 240001 and tgcol3 <> 0 and # tgcol1 <> false tdLog.info( - 'select * from %s where ts < now + 4m and tgcol3 <> 0 and tgcol1 <> false' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol3 <> 0 and tgcol1 <> false' % mt) tdSql.query( - 'select * from %s where ts < now + 4m and tgcol3 <> 0 and tgcol1 <> false' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol3 <> 0 and tgcol1 <> false' % mt) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from %s where ts <= now + 4m and tgcol3 = 0 and + # TSIM: sql select * from %s where ts <= 1605045600000 + 240001 and tgcol3 = 0 and # tgcol1 = false tdLog.info( - 'select * from %s where ts <= now + 4m and tgcol3 = 0 and tgcol1 = false' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol3 = 0 and tgcol1 = false' % mt) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol3 = 0 and tgcol1 = false' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol3 = 0 and tgcol1 = false' % mt) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from %s where ts <= now + 4m and tgcol3 <> 0 and + # TSIM: sql select * from %s where ts <= 1605045600000 + 240001 and tgcol3 <> 0 and # tgcol1 <> false tdLog.info( - 'select * from %s where ts <= now + 4m and tgcol3 <> 0 and tgcol1 <> false' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol3 <> 0 and tgcol1 <> false' % mt) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol3 <> 0 and tgcol1 <> false' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol3 <> 0 and tgcol1 <> false' % mt) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from %s where ts > now + 4m and ts < now + 5m and + # TSIM: sql select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and # tgcol3 <> 0 and tgcol1 <> false tdLog.info( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol3 <> 0 and tgcol1 <> false' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol3 <> 0 and tgcol1 <> false' % mt) tdSql.query( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol3 <> 0 and tgcol1 <> false' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol3 <> 0 and tgcol1 <> false' % mt) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') tdSql.checkRows(5) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from %s where ts > now + 4m and tgcol3 <> 0 and ts - # < now + 5m and ts < now + 5m and tgcol1 <> false + # TSIM: sql select * from %s where ts > 1605045600000 + 240001 and tgcol3 <> 0 and ts + # < 1605045600000 + 300001 and ts < 1605045600000 + 300001 and tgcol1 <> false tdLog.info( - 'select * from %s where ts > now + 4m and tgcol3 <> 0 and ts < now + 5m and ts < now + 5m and tgcol1 <> false' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol3 <> 0 and ts < 1605045600000 + 300001 and ts < 1605045600000 + 300001 and tgcol1 <> false' % mt) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol3 <> 0 and ts < now + 5m and ts < now + 5m and tgcol1 <> false' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol3 <> 0 and ts < 1605045600000 + 300001 and ts < 1605045600000 + 300001 and tgcol1 <> false' % mt) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') @@ -749,104 +749,104 @@ class TDTestCase: # TSIM: # TSIM: print =============== step11 tdLog.info('=============== step11') - # TSIM: sql select * from %s where ts > now + 4m and tgcol3 = 1 and + # TSIM: sql select * from %s where ts > 1605045600000 + 240001 and tgcol3 = 1 and # tgcol2 = 1 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol3 = 1 and tgcol2 = 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol3 = 1 and tgcol2 = 1' % mt) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol3 = 1 and tgcol2 = 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol3 = 1 and tgcol2 = 1' % mt) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from %s where ts > now + 4m and tgcol3 <> 1 and + # TSIM: sql select * from %s where ts > 1605045600000 + 240001 and tgcol3 <> 1 and # tgcol2 <> 1 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol3 <> 1 and tgcol2 <> 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol3 <> 1 and tgcol2 <> 1' % mt) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol3 <> 1 and tgcol2 <> 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol3 <> 1 and tgcol2 <> 1' % mt) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from %s where ts < now + 4m and tgcol3 = 0 and + # TSIM: sql select * from %s where ts < 1605045600000 + 240001 and tgcol3 = 0 and # tgcol2 = 0 tdLog.info( - 'select * from %s where ts < now + 4m and tgcol3 = 0 and tgcol2 = 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol3 = 0 and tgcol2 = 0' % mt) tdSql.query( - 'select * from %s where ts < now + 4m and tgcol3 = 0 and tgcol2 = 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol3 = 0 and tgcol2 = 0' % mt) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from %s where ts < now + 4m and tgcol3 <> 0 and + # TSIM: sql select * from %s where ts < 1605045600000 + 240001 and tgcol3 <> 0 and # tgcol2 <> 0 tdLog.info( - 'select * from %s where ts < now + 4m and tgcol3 <> 0 and tgcol2 <> 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol3 <> 0 and tgcol2 <> 0' % mt) tdSql.query( - 'select * from %s where ts < now + 4m and tgcol3 <> 0 and tgcol2 <> 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol3 <> 0 and tgcol2 <> 0' % mt) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from %s where ts <= now + 4m and tgcol3 = 0 and + # TSIM: sql select * from %s where ts <= 1605045600000 + 240001 and tgcol3 = 0 and # tgcol2 = 0 tdLog.info( - 'select * from %s where ts <= now + 4m and tgcol3 = 0 and tgcol2 = 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol3 = 0 and tgcol2 = 0' % mt) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol3 = 0 and tgcol2 = 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol3 = 0 and tgcol2 = 0' % mt) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from %s where ts <= now + 4m and tgcol3 <> 0 and + # TSIM: sql select * from %s where ts <= 1605045600000 + 240001 and tgcol3 <> 0 and # tgcol2 <> 0 tdLog.info( - 'select * from %s where ts <= now + 4m and tgcol3 <> 0 and tgcol2 <> 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol3 <> 0 and tgcol2 <> 0' % mt) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol3 <> 0 and tgcol2 <> 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol3 <> 0 and tgcol2 <> 0' % mt) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from %s where ts > now + 4m and ts < now + 5m and + # TSIM: sql select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and # tgcol3 <> 0 and tgcol2 <> 0 tdLog.info( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol3 <> 0 and tgcol2 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol3 <> 0 and tgcol2 <> 0' % mt) tdSql.query( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol3 <> 0 and tgcol2 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol3 <> 0 and tgcol2 <> 0' % mt) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') tdSql.checkRows(5) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from %s where ts > now + 4m and tgcol3 <> 0 and ts - # < now + 5m and ts < now + 5m and tgcol2 <> 0 + # TSIM: sql select * from %s where ts > 1605045600000 + 240001 and tgcol3 <> 0 and ts + # < 1605045600000 + 300001 and ts < 1605045600000 + 300001 and tgcol2 <> 0 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol3 <> 0 and ts < now + 5m and ts < now + 5m and tgcol2 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol3 <> 0 and ts < 1605045600000 + 300001 and ts < 1605045600000 + 300001 and tgcol2 <> 0' % mt) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol3 <> 0 and ts < now + 5m and ts < now + 5m and tgcol2 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol3 <> 0 and ts < 1605045600000 + 300001 and ts < 1605045600000 + 300001 and tgcol2 <> 0' % mt) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') @@ -856,104 +856,104 @@ class TDTestCase: # TSIM: # TSIM: print =============== step12 tdLog.info('=============== step12') - # TSIM: sql select * from %s where ts > now + 4m and tgcol1 = 1 and + # TSIM: sql select * from %s where ts > 1605045600000 + 240001 and tgcol1 = 1 and # tgcol2 = 1 and tgcol3 = 1 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol1 = 1 and tgcol2 = 1 and tgcol3 = 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol1 = 1 and tgcol2 = 1 and tgcol3 = 1' % mt) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol1 = 1 and tgcol2 = 1 and tgcol3 = 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol1 = 1 and tgcol2 = 1 and tgcol3 = 1' % mt) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from %s where ts > now + 4m and tgcol1 <> 1 and + # TSIM: sql select * from %s where ts > 1605045600000 + 240001 and tgcol1 <> 1 and # tgcol2 <> 1 and tgcol3 <> 1 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol1 <> 1 and tgcol2 <> 1 and tgcol3 <> 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol1 <> 1 and tgcol2 <> 1 and tgcol3 <> 1' % mt) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol1 <> 1 and tgcol2 <> 1 and tgcol3 <> 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol1 <> 1 and tgcol2 <> 1 and tgcol3 <> 1' % mt) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from %s where ts < now + 4m and tgcol1 = 0 and + # TSIM: sql select * from %s where ts < 1605045600000 + 240001 and tgcol1 = 0 and # tgcol2 = 0 and tgcol3 = 0 tdLog.info( - 'select * from %s where ts < now + 4m and tgcol1 = 0 and tgcol2 = 0 and tgcol3 = 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol1 = 0 and tgcol2 = 0 and tgcol3 = 0' % mt) tdSql.query( - 'select * from %s where ts < now + 4m and tgcol1 = 0 and tgcol2 = 0 and tgcol3 = 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol1 = 0 and tgcol2 = 0 and tgcol3 = 0' % mt) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from %s where ts < now + 4m and tgcol1 <> 0 and + # TSIM: sql select * from %s where ts < 1605045600000 + 240001 and tgcol1 <> 0 and # tgcol2 <> 0 and tgcol3 <> 0 tdLog.info( - 'select * from %s where ts < now + 4m and tgcol1 <> 0 and tgcol2 <> 0 and tgcol3 <> 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol1 <> 0 and tgcol2 <> 0 and tgcol3 <> 0' % mt) tdSql.query( - 'select * from %s where ts < now + 4m and tgcol1 <> 0 and tgcol2 <> 0 and tgcol3 <> 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol1 <> 0 and tgcol2 <> 0 and tgcol3 <> 0' % mt) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from %s where ts <= now + 4m and tgcol1 = 0 and + # TSIM: sql select * from %s where ts <= 1605045600000 + 240001 and tgcol1 = 0 and # tgcol2 = 0 and tgcol3 = 0 tdLog.info( - 'select * from %s where ts <= now + 4m and tgcol1 = 0 and tgcol2 = 0 and tgcol3 = 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol1 = 0 and tgcol2 = 0 and tgcol3 = 0' % mt) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol1 = 0 and tgcol2 = 0 and tgcol3 = 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol1 = 0 and tgcol2 = 0 and tgcol3 = 0' % mt) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from %s where ts <= now + 4m and tgcol1 <> 0 and + # TSIM: sql select * from %s where ts <= 1605045600000 + 240001 and tgcol1 <> 0 and # tgcol2 <> 0 and tgcol3 <> 0 tdLog.info( - 'select * from %s where ts <= now + 4m and tgcol1 <> 0 and tgcol2 <> 0 and tgcol3 <> 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol1 <> 0 and tgcol2 <> 0 and tgcol3 <> 0' % mt) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol1 <> 0 and tgcol2 <> 0 and tgcol3 <> 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol1 <> 0 and tgcol2 <> 0 and tgcol3 <> 0' % mt) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from %s where ts > now + 4m and ts < now + 5m and + # TSIM: sql select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and # tgcol1 <> 0 and tgcol2 <> 0 and tgcol3 <> 0 tdLog.info( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol1 <> 0 and tgcol2 <> 0 and tgcol3 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol1 <> 0 and tgcol2 <> 0 and tgcol3 <> 0' % mt) tdSql.query( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol1 <> 0 and tgcol2 <> 0 and tgcol3 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol1 <> 0 and tgcol2 <> 0 and tgcol3 <> 0' % mt) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') tdSql.checkRows(5) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from %s where ts > now + 4m and tgcol1 <> 0 and ts - # < now + 5m and ts < now + 5m and tgcol2 <> 0 and tgcol3 <> 0 + # TSIM: sql select * from %s where ts > 1605045600000 + 240001 and tgcol1 <> 0 and ts + # < 1605045600000 + 300001 and ts < 1605045600000 + 300001 and tgcol2 <> 0 and tgcol3 <> 0 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol1 <> 0 and ts < now + 5m and ts < now + 5m and tgcol2 <> 0 and tgcol3 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol1 <> 0 and ts < 1605045600000 + 300001 and ts < 1605045600000 + 300001 and tgcol2 <> 0 and tgcol3 <> 0' % mt) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol1 <> 0 and ts < now + 5m and ts < now + 5m and tgcol2 <> 0 and tgcol3 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol1 <> 0 and ts < 1605045600000 + 300001 and ts < 1605045600000 + 300001 and tgcol2 <> 0 and tgcol3 <> 0' % mt) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') @@ -1034,12 +1034,12 @@ class TDTestCase: # TSIM: print =============== step15 tdLog.info('=============== step15') # TSIM: sql select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), - # max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m + # max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001 tdLog.info( - 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m' % + 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001' % mt) tdSql.query( - 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m' % + 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001' % mt) # TSIM: print $data00 $data01 $data02 $data03 $data04 $data05 $data06 tdLog.info('$data00 $data01 $data02 $data03 $data04 $data05 $data06') @@ -1050,13 +1050,13 @@ class TDTestCase: # TSIM: endi # TSIM: # TSIM: sql select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), - # max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m and + # max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001 and # tgcol1 = true tdLog.info( - 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m and tgcol1 = true' % + 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001 and tgcol1 = true' % mt) tdSql.query( - 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m and tgcol1 = true' % + 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001 and tgcol1 = true' % mt) # TSIM: print $data00 $data01 $data02 $data03 $data04 $data05 $data06 tdLog.info('$data00 $data01 $data02 $data03 $data04 $data05 $data06') @@ -1067,13 +1067,13 @@ class TDTestCase: # TSIM: endi # TSIM: # TSIM: sql select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), - # max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m and + # max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001 and # tgcol1 = true and tgcol2 = 1 tdLog.info( - 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m and tgcol1 = true and tgcol2 = 1' % + 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001 and tgcol1 = true and tgcol2 = 1' % mt) tdSql.query( - 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m and tgcol1 = true and tgcol2 = 1' % + 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001 and tgcol1 = true and tgcol2 = 1' % mt) # TSIM: print $data00 $data01 $data02 $data03 $data04 $data05 $data06 tdLog.info('$data00 $data01 $data02 $data03 $data04 $data05 $data06') @@ -1084,11 +1084,11 @@ class TDTestCase: # TSIM: endi # TSIM: # TSIM: sql select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), - # max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m and + # max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001 and # tgcol1 = true and tgcol2 = 1 and tgcol3 = 1 - tdLog.info('select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m and tgcol1 = true and tgcol2 = 1 and tgcol3 = 1' % mt) + tdLog.info('select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001 and tgcol1 = true and tgcol2 = 1 and tgcol3 = 1' % mt) tdSql.query( - 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m and tgcol1 = true and tgcol2 = 1 and tgcol3 = 1' % + 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001 and tgcol1 = true and tgcol2 = 1 and tgcol3 = 1' % mt) # TSIM: print $data00 $data01 $data02 $data03 $data04 $data05 $data06 tdLog.info('$data00 $data01 $data02 $data03 $data04 $data05 $data06') @@ -1204,13 +1204,13 @@ class TDTestCase: # TSIM: print =============== step18 tdLog.info('=============== step18') # TSIM: sql select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), - # max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m + # max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001 # group by tgcol2 tdLog.info( - 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m group by tgcol2' % + 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001 group by tgcol2' % mt) tdSql.query( - 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m group by tgcol2' % + 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001 group by tgcol2' % mt) # TSIM: print $data00 $data01 $data02 $data03 $data04 $data05 $data06 tdLog.info('$data00 $data01 $data02 $data03 $data04 $data05 $data06') @@ -1221,13 +1221,13 @@ class TDTestCase: # TSIM: endi # TSIM: # TSIM: sql select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), - # max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m and + # max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001 and # tgcol1 = true group by tgcol2 tdLog.info( - 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m and tgcol1 = true group by tgcol2' % + 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001 and tgcol1 = true group by tgcol2' % mt) tdSql.query( - 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m and tgcol1 = true group by tgcol2' % + 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001 and tgcol1 = true group by tgcol2' % mt) # TSIM: print $data00 $data01 $data02 $data03 $data04 $data05 $data06 tdLog.info('$data00 $data01 $data02 $data03 $data04 $data05 $data06') @@ -1238,11 +1238,11 @@ class TDTestCase: # TSIM: endi # TSIM: # TSIM: sql select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), - # max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m and + # max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001 and # tgcol1 = true and tgcol2 = 1 group by tgcol2 - tdLog.info('select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m and tgcol1 = true and tgcol2 = 1 group by tgcol2' % mt) + tdLog.info('select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001 and tgcol1 = true and tgcol2 = 1 group by tgcol2' % mt) tdSql.query( - 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m and tgcol1 = true and tgcol2 = 1 group by tgcol2' % + 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001 and tgcol1 = true and tgcol2 = 1 group by tgcol2' % mt) # TSIM: print $data00 $data01 $data02 $data03 $data04 $data05 $data06 tdLog.info('$data00 $data01 $data02 $data03 $data04 $data05 $data06') @@ -1253,10 +1253,10 @@ class TDTestCase: # TSIM: endi # TSIM: # TSIM: sql select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), - # max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m and + # max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001 and # tgcol1 = true and tgcol2 = 1 and tgcol3 = 1 group by tgcol2 - tdLog.info('select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m and tgcol1 = true and tgcol2 = 1 and tgcol3 = 1 group by tgcol2' % mt) - tdSql.query('select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m and tgcol1 = true and tgcol2 = 1 and tgcol3 = 1 group by tgcol2' % mt) + tdLog.info('select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001 and tgcol1 = true and tgcol2 = 1 and tgcol3 = 1 group by tgcol2' % mt) + tdSql.query('select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001 and tgcol1 = true and tgcol2 = 1 and tgcol3 = 1 group by tgcol2' % mt) # TSIM: print $data00 $data01 $data02 $data03 $data04 $data05 $data06 tdLog.info('$data00 $data01 $data02 $data03 $data04 $data05 $data06') # TSIM: if $data00 != 25 then diff --git a/tests/pytest/tag_lite/4.py b/tests/pytest/tag_lite/4.py index aae930ecdf67c04040c47115daad3e2b662915e9..df81dd81000c0698ea4ab1fb661d3b7f55059fbb 100644 --- a/tests/pytest/tag_lite/4.py +++ b/tests/pytest/tag_lite/4.py @@ -64,14 +64,14 @@ class TDTestCase: (tb, mt)) x = 0 while (x < rowNum): - ms = "%dm" % x - # TSIM: sql insert into $tb values (now + $ms , $x ) + ms = x * 60000 + # TSIM: sql insert into $tb values (1605045600000 + $ms , $x ) tdLog.info( - "insert into %s values (now + %s, %d)" % - (tb, ms, x)) + "insert into %s values (%d, %d)" % + (tb, 1605045600000 + ms, x)) tdSql.execute( - "insert into %s values (now + %s, %d)" % - (tb, ms, x)) + "insert into %s values (%d, %d)" % + (tb, 1605045600000 + ms, x)) x = x + 1 # TSIM: endw i = i + 1 @@ -87,14 +87,13 @@ class TDTestCase: (tb, mt)) x = 0 while (x < rowNum): - ms = "%dm" % x - # TSIM: sql insert into $tb values (now + $ms , $x ) + ms = x * 60000 tdLog.info( - "insert into %s values (now + %s, %d)" % - (tb, ms, x)) + "insert into %s values (%d, %d)" % + (tb, 1605045600000 + ms, x)) tdSql.execute( - "insert into %s values (now + %s, %d)" % - (tb, ms, x)) + "insert into %s values (%d, %d)" % + (tb, 1605045600000 + ms, x)) x = x + 1 # TSIM: endw i = i + 1 @@ -111,36 +110,36 @@ class TDTestCase: # TSIM: return -1 # TSIM: endi # TSIM: - # TSIM: sql select * from %s where ts < now + 4m - tdLog.info('select * from %s where ts < now + 4m' % mt) - tdSql.query('select * from %s where ts < now + 4m' % mt) + # TSIM: sql select * from %s where ts < 1605045600000 + 240001 + tdLog.info('select * from %s where ts < 1605045600000 + 240001' % mt) + tdSql.query('select * from %s where ts < 1605045600000 + 240001' % mt) # TSIM: if $rows != 50 then tdLog.info('tdSql.checkRow(50)') tdSql.checkRows(50) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from %s where ts > now + 4m - tdLog.info('select * from %s where ts > now + 4m' % mt) - tdSql.query('select * from %s where ts > now + 4m' % mt) + # TSIM: sql select * from %s where ts > 1605045600000 + 240001 + tdLog.info('select * from %s where ts > 1605045600000 + 240001' % mt) + tdSql.query('select * from %s where ts > 1605045600000 + 240001' % mt) # TSIM: if $rows != 150 then tdLog.info('tdSql.checkRow(150)') tdSql.checkRows(150) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from %s where ts = now + 4m - tdLog.info('select * from %s where ts = now + 4m' % mt) - tdSql.query('select * from %s where ts = now + 4m' % mt) + # TSIM: sql select * from %s where ts = 1605045600000 + 240001 + tdLog.info('select * from %s where ts = 1605045600000 + 240001' % mt) + tdSql.query('select * from %s where ts = 1605045600000 + 240001' % mt) # TSIM: if $rows != 0 then tdLog.info('tdSql.checkRow(0)') tdSql.checkRows(0) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from %s where ts > now + 4m and ts < now + 5m + # TSIM: sql select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 tdLog.info( - 'select * from %s where ts > now + 4m and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001' % mt) tdSql.query( - 'select * from %s where ts > now + 4m and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001' % mt) # TSIM: if $rows != 10 then tdLog.info('tdSql.checkRow(10)') @@ -322,84 +321,84 @@ class TDTestCase: # TSIM: # TSIM: print =============== step7 tdLog.info('=============== step7') - # TSIM: sql select * from %s where ts > now + 4m and tgcol1 = 1 - tdLog.info('select * from %s where ts > now + 4m and tgcol1 = 1' % mt) - tdSql.query('select * from %s where ts > now + 4m and tgcol1 = 1' % mt) + # TSIM: sql select * from %s where ts > 1605045600000 + 240001 and tgcol1 = 1 + tdLog.info('select * from %s where ts > 1605045600000 + 240001 and tgcol1 = 1' % mt) + tdSql.query('select * from %s where ts > 1605045600000 + 240001 and tgcol1 = 1' % mt) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from %s where ts > now + 4m and tgcol1 <> 1 - tdLog.info('select * from %s where ts > now + 4m and tgcol1 <> 1' % mt) + # TSIM: sql select * from %s where ts > 1605045600000 + 240001 and tgcol1 <> 1 + tdLog.info('select * from %s where ts > 1605045600000 + 240001 and tgcol1 <> 1' % mt) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol1 <> 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol1 <> 1' % mt) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from %s where ts < now + 4m and tgcol1 = 0 - tdLog.info('select * from %s where ts < now + 4m and tgcol1 = 0' % mt) - tdSql.query('select * from %s where ts < now + 4m and tgcol1 = 0' % mt) + # TSIM: sql select * from %s where ts < 1605045600000 + 240001 and tgcol1 = 0 + tdLog.info('select * from %s where ts < 1605045600000 + 240001 and tgcol1 = 0' % mt) + tdSql.query('select * from %s where ts < 1605045600000 + 240001 and tgcol1 = 0' % mt) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from %s where ts < now + 4m and tgcol1 <> 0 - tdLog.info('select * from %s where ts < now + 4m and tgcol1 <> 0' % mt) + # TSIM: sql select * from %s where ts < 1605045600000 + 240001 and tgcol1 <> 0 + tdLog.info('select * from %s where ts < 1605045600000 + 240001 and tgcol1 <> 0' % mt) tdSql.query( - 'select * from %s where ts < now + 4m and tgcol1 <> 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol1 <> 0' % mt) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from %s where ts <= now + 4m and tgcol1 = 0 - tdLog.info('select * from %s where ts <= now + 4m and tgcol1 = 0' % mt) + # TSIM: sql select * from %s where ts <= 1605045600000 + 240001 and tgcol1 = 0 + tdLog.info('select * from %s where ts <= 1605045600000 + 240001 and tgcol1 = 0' % mt) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol1 = 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol1 = 0' % mt) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from %s where ts <= now + 4m and tgcol1 <> 0 + # TSIM: sql select * from %s where ts <= 1605045600000 + 240001 and tgcol1 <> 0 tdLog.info( - 'select * from %s where ts <= now + 4m and tgcol1 <> 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol1 <> 0' % mt) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol1 <> 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol1 <> 0' % mt) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from %s where ts > now + 4m and ts < now + 5m and + # TSIM: sql select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and # tgcol1 <> 0 tdLog.info( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol1 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol1 <> 0' % mt) tdSql.query( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol1 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol1 <> 0' % mt) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') tdSql.checkRows(5) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from %s where ts > now + 4m and tgcol1 <> 0 and ts - # < now + 5m + # TSIM: sql select * from %s where ts > 1605045600000 + 240001 and tgcol1 <> 0 and ts + # < 1605045600000 + 300001 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol1 <> 0 and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol1 <> 0 and ts < 1605045600000 + 300001' % mt) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol1 <> 0 and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol1 <> 0 and ts < 1605045600000 + 300001' % mt) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') @@ -409,84 +408,84 @@ class TDTestCase: # TSIM: # TSIM: print =============== step8 tdLog.info('=============== step8') - # TSIM: sql select * from %s where ts > now + 4m and tgcol2 = 1 - tdLog.info('select * from %s where ts > now + 4m and tgcol2 = 1' % mt) - tdSql.query('select * from %s where ts > now + 4m and tgcol2 = 1' % mt) + # TSIM: sql select * from %s where ts > 1605045600000 + 240001 and tgcol2 = 1 + tdLog.info('select * from %s where ts > 1605045600000 + 240001 and tgcol2 = 1' % mt) + tdSql.query('select * from %s where ts > 1605045600000 + 240001 and tgcol2 = 1' % mt) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from %s where ts > now + 4m and tgcol2 <> 1 - tdLog.info('select * from %s where ts > now + 4m and tgcol2 <> 1' % mt) + # TSIM: sql select * from %s where ts > 1605045600000 + 240001 and tgcol2 <> 1 + tdLog.info('select * from %s where ts > 1605045600000 + 240001 and tgcol2 <> 1' % mt) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol2 <> 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol2 <> 1' % mt) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from %s where ts < now + 4m and tgcol2 = 0 - tdLog.info('select * from %s where ts < now + 4m and tgcol2 = 0' % mt) - tdSql.query('select * from %s where ts < now + 4m and tgcol2 = 0' % mt) + # TSIM: sql select * from %s where ts < 1605045600000 + 240001 and tgcol2 = 0 + tdLog.info('select * from %s where ts < 1605045600000 + 240001 and tgcol2 = 0' % mt) + tdSql.query('select * from %s where ts < 1605045600000 + 240001 and tgcol2 = 0' % mt) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from %s where ts < now + 4m and tgcol2 <> 0 - tdLog.info('select * from %s where ts < now + 4m and tgcol2 <> 0' % mt) + # TSIM: sql select * from %s where ts < 1605045600000 + 240001 and tgcol2 <> 0 + tdLog.info('select * from %s where ts < 1605045600000 + 240001 and tgcol2 <> 0' % mt) tdSql.query( - 'select * from %s where ts < now + 4m and tgcol2 <> 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol2 <> 0' % mt) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from %s where ts <= now + 4m and tgcol2 = 0 - tdLog.info('select * from %s where ts <= now + 4m and tgcol2 = 0' % mt) + # TSIM: sql select * from %s where ts <= 1605045600000 + 240001 and tgcol2 = 0 + tdLog.info('select * from %s where ts <= 1605045600000 + 240001 and tgcol2 = 0' % mt) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol2 = 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol2 = 0' % mt) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from %s where ts <= now + 4m and tgcol2 <> 0 + # TSIM: sql select * from %s where ts <= 1605045600000 + 240001 and tgcol2 <> 0 tdLog.info( - 'select * from %s where ts <= now + 4m and tgcol2 <> 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol2 <> 0' % mt) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol2 <> 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol2 <> 0' % mt) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from %s where ts > now + 4m and ts < now + 5m and + # TSIM: sql select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and # tgcol2 <> 0 tdLog.info( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol2 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol2 <> 0' % mt) tdSql.query( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol2 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol2 <> 0' % mt) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') tdSql.checkRows(5) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from %s where ts > now + 4m and tgcol2 <> 0 and ts - # < now + 5m + # TSIM: sql select * from %s where ts > 1605045600000 + 240001 and tgcol2 <> 0 and ts + # < 1605045600000 + 300001 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol2 <> 0 and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol2 <> 0 and ts < 1605045600000 + 300001' % mt) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol2 <> 0 and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol2 <> 0 and ts < 1605045600000 + 300001' % mt) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') @@ -496,84 +495,84 @@ class TDTestCase: # TSIM: # TSIM: print =============== step9 tdLog.info('=============== step9') - # TSIM: sql select * from %s where ts > now + 4m and tgcol3 = 1 - tdLog.info('select * from %s where ts > now + 4m and tgcol3 = 1' % mt) - tdSql.query('select * from %s where ts > now + 4m and tgcol3 = 1' % mt) + # TSIM: sql select * from %s where ts > 1605045600000 + 240001 and tgcol3 = 1 + tdLog.info('select * from %s where ts > 1605045600000 + 240001 and tgcol3 = 1' % mt) + tdSql.query('select * from %s where ts > 1605045600000 + 240001 and tgcol3 = 1' % mt) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from %s where ts > now + 4m and tgcol3 <> 1 - tdLog.info('select * from %s where ts > now + 4m and tgcol3 <> 1' % mt) + # TSIM: sql select * from %s where ts > 1605045600000 + 240001 and tgcol3 <> 1 + tdLog.info('select * from %s where ts > 1605045600000 + 240001 and tgcol3 <> 1' % mt) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol3 <> 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol3 <> 1' % mt) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from %s where ts < now + 4m and tgcol3 = 0 - tdLog.info('select * from %s where ts < now + 4m and tgcol3 = 0' % mt) - tdSql.query('select * from %s where ts < now + 4m and tgcol3 = 0' % mt) + # TSIM: sql select * from %s where ts < 1605045600000 + 240001 and tgcol3 = 0 + tdLog.info('select * from %s where ts < 1605045600000 + 240001 and tgcol3 = 0' % mt) + tdSql.query('select * from %s where ts < 1605045600000 + 240001 and tgcol3 = 0' % mt) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from %s where ts < now + 4m and tgcol3 <> 0 - tdLog.info('select * from %s where ts < now + 4m and tgcol3 <> 0' % mt) + # TSIM: sql select * from %s where ts < 1605045600000 + 240001 and tgcol3 <> 0 + tdLog.info('select * from %s where ts < 1605045600000 + 240001 and tgcol3 <> 0' % mt) tdSql.query( - 'select * from %s where ts < now + 4m and tgcol3 <> 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol3 <> 0' % mt) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from %s where ts <= now + 4m and tgcol3 = 0 - tdLog.info('select * from %s where ts <= now + 4m and tgcol3 = 0' % mt) + # TSIM: sql select * from %s where ts <= 1605045600000 + 240001 and tgcol3 = 0 + tdLog.info('select * from %s where ts <= 1605045600000 + 240001 and tgcol3 = 0' % mt) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol3 = 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol3 = 0' % mt) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from %s where ts <= now + 4m and tgcol3 <> 0 + # TSIM: sql select * from %s where ts <= 1605045600000 + 240001 and tgcol3 <> 0 tdLog.info( - 'select * from %s where ts <= now + 4m and tgcol3 <> 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol3 <> 0' % mt) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol3 <> 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol3 <> 0' % mt) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from %s where ts > now + 4m and ts < now + 5m and + # TSIM: sql select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and # tgcol3 <> 0 tdLog.info( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol3 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol3 <> 0' % mt) tdSql.query( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol3 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol3 <> 0' % mt) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') tdSql.checkRows(5) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from %s where ts > now + 4m and tgcol3 <> 0 and ts - # < now + 5m + # TSIM: sql select * from %s where ts > 1605045600000 + 240001 and tgcol3 <> 0 and ts + # < 1605045600000 + 300001 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol3 <> 0 and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol3 <> 0 and ts < 1605045600000 + 300001' % mt) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol3 <> 0 and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol3 <> 0 and ts < 1605045600000 + 300001' % mt) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') @@ -583,84 +582,84 @@ class TDTestCase: # TSIM: # TSIM: print =============== step10 tdLog.info('=============== step10') - # TSIM: sql select * from %s where ts > now + 4m and tgcol4 = 1 - tdLog.info('select * from %s where ts > now + 4m and tgcol4 = 1' % mt) - tdSql.query('select * from %s where ts > now + 4m and tgcol4 = 1' % mt) + # TSIM: sql select * from %s where ts > 1605045600000 + 240001 and tgcol4 = 1 + tdLog.info('select * from %s where ts > 1605045600000 + 240001 and tgcol4 = 1' % mt) + tdSql.query('select * from %s where ts > 1605045600000 + 240001 and tgcol4 = 1' % mt) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from %s where ts > now + 4m and tgcol4 <> 1 - tdLog.info('select * from %s where ts > now + 4m and tgcol4 <> 1' % mt) + # TSIM: sql select * from %s where ts > 1605045600000 + 240001 and tgcol4 <> 1 + tdLog.info('select * from %s where ts > 1605045600000 + 240001 and tgcol4 <> 1' % mt) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol4 <> 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol4 <> 1' % mt) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from %s where ts < now + 4m and tgcol4 = 0 - tdLog.info('select * from %s where ts < now + 4m and tgcol4 = 0' % mt) - tdSql.query('select * from %s where ts < now + 4m and tgcol4 = 0' % mt) + # TSIM: sql select * from %s where ts < 1605045600000 + 240001 and tgcol4 = 0 + tdLog.info('select * from %s where ts < 1605045600000 + 240001 and tgcol4 = 0' % mt) + tdSql.query('select * from %s where ts < 1605045600000 + 240001 and tgcol4 = 0' % mt) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from %s where ts < now + 4m and tgcol4 <> 0 - tdLog.info('select * from %s where ts < now + 4m and tgcol4 <> 0' % mt) + # TSIM: sql select * from %s where ts < 1605045600000 + 240001 and tgcol4 <> 0 + tdLog.info('select * from %s where ts < 1605045600000 + 240001 and tgcol4 <> 0' % mt) tdSql.query( - 'select * from %s where ts < now + 4m and tgcol4 <> 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol4 <> 0' % mt) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from %s where ts <= now + 4m and tgcol4 = 0 - tdLog.info('select * from %s where ts <= now + 4m and tgcol4 = 0' % mt) + # TSIM: sql select * from %s where ts <= 1605045600000 + 240001 and tgcol4 = 0 + tdLog.info('select * from %s where ts <= 1605045600000 + 240001 and tgcol4 = 0' % mt) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol4 = 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol4 = 0' % mt) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from %s where ts <= now + 4m and tgcol4 <> 0 + # TSIM: sql select * from %s where ts <= 1605045600000 + 240001 and tgcol4 <> 0 tdLog.info( - 'select * from %s where ts <= now + 4m and tgcol4 <> 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol4 <> 0' % mt) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol4 <> 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol4 <> 0' % mt) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from %s where ts > now + 4m and ts < now + 5m and + # TSIM: sql select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and # tgcol4 <> 0 tdLog.info( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol4 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol4 <> 0' % mt) tdSql.query( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol4 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol4 <> 0' % mt) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') tdSql.checkRows(5) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from %s where ts > now + 4m and tgcol4 <> 0 and ts - # < now + 5m + # TSIM: sql select * from %s where ts > 1605045600000 + 240001 and tgcol4 <> 0 and ts + # < 1605045600000 + 300001 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol4 <> 0 and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol4 <> 0 and ts < 1605045600000 + 300001' % mt) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol4 <> 0 and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol4 <> 0 and ts < 1605045600000 + 300001' % mt) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') @@ -670,104 +669,104 @@ class TDTestCase: # TSIM: # TSIM: print =============== step11 tdLog.info('=============== step11') - # TSIM: sql select * from %s where ts > now + 4m and tgcol2 = 1 and + # TSIM: sql select * from %s where ts > 1605045600000 + 240001 and tgcol2 = 1 and # tgcol1 = 1 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol2 = 1 and tgcol1 = 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol2 = 1 and tgcol1 = 1' % mt) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol2 = 1 and tgcol1 = 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol2 = 1 and tgcol1 = 1' % mt) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from %s where ts > now + 4m and tgcol2 <> 1 and + # TSIM: sql select * from %s where ts > 1605045600000 + 240001 and tgcol2 <> 1 and # tgcol1 <> 1 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol2 <> 1 and tgcol1 <> 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol2 <> 1 and tgcol1 <> 1' % mt) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol2 <> 1 and tgcol1 <> 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol2 <> 1 and tgcol1 <> 1' % mt) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from %s where ts < now + 4m and tgcol2 = 0 and + # TSIM: sql select * from %s where ts < 1605045600000 + 240001 and tgcol2 = 0 and # tgcol1 = 0 tdLog.info( - 'select * from %s where ts < now + 4m and tgcol2 = 0 and tgcol1 = 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol2 = 0 and tgcol1 = 0' % mt) tdSql.query( - 'select * from %s where ts < now + 4m and tgcol2 = 0 and tgcol1 = 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol2 = 0 and tgcol1 = 0' % mt) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from %s where ts < now + 4m and tgcol2 <> 0 and + # TSIM: sql select * from %s where ts < 1605045600000 + 240001 and tgcol2 <> 0 and # tgcol1 <> 0 tdLog.info( - 'select * from %s where ts < now + 4m and tgcol2 <> 0 and tgcol1 <> 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol2 <> 0 and tgcol1 <> 0' % mt) tdSql.query( - 'select * from %s where ts < now + 4m and tgcol2 <> 0 and tgcol1 <> 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol2 <> 0 and tgcol1 <> 0' % mt) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from %s where ts <= now + 4m and tgcol2 = 0 and + # TSIM: sql select * from %s where ts <= 1605045600000 + 240001 and tgcol2 = 0 and # tgcol1 = 0 tdLog.info( - 'select * from %s where ts <= now + 4m and tgcol2 = 0 and tgcol1 = 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol2 = 0 and tgcol1 = 0' % mt) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol2 = 0 and tgcol1 = 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol2 = 0 and tgcol1 = 0' % mt) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from %s where ts <= now + 4m and tgcol2 <> 0 and + # TSIM: sql select * from %s where ts <= 1605045600000 + 240001 and tgcol2 <> 0 and # tgcol1 <> 0 tdLog.info( - 'select * from %s where ts <= now + 4m and tgcol2 <> 0 and tgcol1 <> 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol2 <> 0 and tgcol1 <> 0' % mt) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol2 <> 0 and tgcol1 <> 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol2 <> 0 and tgcol1 <> 0' % mt) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from %s where ts > now + 4m and ts < now + 5m and + # TSIM: sql select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and # tgcol2 <> 0 and tgcol1 <> 0 tdLog.info( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol2 <> 0 and tgcol1 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol2 <> 0 and tgcol1 <> 0' % mt) tdSql.query( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol2 <> 0 and tgcol1 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol2 <> 0 and tgcol1 <> 0' % mt) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') tdSql.checkRows(5) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from %s where ts > now + 4m and tgcol2 <> 0 and ts - # < now + 5m and ts < now + 5m and tgcol1 <> 0 + # TSIM: sql select * from %s where ts > 1605045600000 + 240001 and tgcol2 <> 0 and ts + # < 1605045600000 + 300001 and ts < 1605045600000 + 300001 and tgcol1 <> 0 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol2 <> 0 and ts < now + 5m and ts < now + 5m and tgcol1 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol2 <> 0 and ts < 1605045600000 + 300001 and ts < 1605045600000 + 300001 and tgcol1 <> 0' % mt) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol2 <> 0 and ts < now + 5m and ts < now + 5m and tgcol1 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol2 <> 0 and ts < 1605045600000 + 300001 and ts < 1605045600000 + 300001 and tgcol1 <> 0' % mt) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') @@ -777,104 +776,104 @@ class TDTestCase: # TSIM: # TSIM: print =============== step12 tdLog.info('=============== step12') - # TSIM: sql select * from %s where ts > now + 4m and tgcol3 = 1 and + # TSIM: sql select * from %s where ts > 1605045600000 + 240001 and tgcol3 = 1 and # tgcol1 = 1 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol3 = 1 and tgcol1 = 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol3 = 1 and tgcol1 = 1' % mt) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol3 = 1 and tgcol1 = 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol3 = 1 and tgcol1 = 1' % mt) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from %s where ts > now + 4m and tgcol3 <> 1 and + # TSIM: sql select * from %s where ts > 1605045600000 + 240001 and tgcol3 <> 1 and # tgcol1 <> 1 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol3 <> 1 and tgcol1 <> 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol3 <> 1 and tgcol1 <> 1' % mt) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol3 <> 1 and tgcol1 <> 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol3 <> 1 and tgcol1 <> 1' % mt) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from %s where ts < now + 4m and tgcol3 = 0 and + # TSIM: sql select * from %s where ts < 1605045600000 + 240001 and tgcol3 = 0 and # tgcol1 = 0 tdLog.info( - 'select * from %s where ts < now + 4m and tgcol3 = 0 and tgcol1 = 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol3 = 0 and tgcol1 = 0' % mt) tdSql.query( - 'select * from %s where ts < now + 4m and tgcol3 = 0 and tgcol1 = 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol3 = 0 and tgcol1 = 0' % mt) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from %s where ts < now + 4m and tgcol3 <> 0 and + # TSIM: sql select * from %s where ts < 1605045600000 + 240001 and tgcol3 <> 0 and # tgcol1 <> 0 tdLog.info( - 'select * from %s where ts < now + 4m and tgcol3 <> 0 and tgcol1 <> 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol3 <> 0 and tgcol1 <> 0' % mt) tdSql.query( - 'select * from %s where ts < now + 4m and tgcol3 <> 0 and tgcol1 <> 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol3 <> 0 and tgcol1 <> 0' % mt) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from %s where ts <= now + 4m and tgcol3 = 0 and + # TSIM: sql select * from %s where ts <= 1605045600000 + 240001 and tgcol3 = 0 and # tgcol1 = 0 tdLog.info( - 'select * from %s where ts <= now + 4m and tgcol3 = 0 and tgcol1 = 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol3 = 0 and tgcol1 = 0' % mt) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol3 = 0 and tgcol1 = 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol3 = 0 and tgcol1 = 0' % mt) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from %s where ts <= now + 4m and tgcol3 <> 0 and + # TSIM: sql select * from %s where ts <= 1605045600000 + 240001 and tgcol3 <> 0 and # tgcol1 <> 0 tdLog.info( - 'select * from %s where ts <= now + 4m and tgcol3 <> 0 and tgcol1 <> 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol3 <> 0 and tgcol1 <> 0' % mt) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol3 <> 0 and tgcol1 <> 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol3 <> 0 and tgcol1 <> 0' % mt) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from %s where ts > now + 4m and ts < now + 5m and + # TSIM: sql select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and # tgcol3 <> 0 and tgcol1 <> 0 tdLog.info( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol3 <> 0 and tgcol1 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol3 <> 0 and tgcol1 <> 0' % mt) tdSql.query( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol3 <> 0 and tgcol1 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol3 <> 0 and tgcol1 <> 0' % mt) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') tdSql.checkRows(5) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from %s where ts > now + 4m and tgcol3 <> 0 and ts - # < now + 5m and ts < now + 5m and tgcol1 <> 0 + # TSIM: sql select * from %s where ts > 1605045600000 + 240001 and tgcol3 <> 0 and ts + # < 1605045600000 + 300001 and ts < 1605045600000 + 300001 and tgcol1 <> 0 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol3 <> 0 and ts < now + 5m and ts < now + 5m and tgcol1 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol3 <> 0 and ts < 1605045600000 + 300001 and ts < 1605045600000 + 300001 and tgcol1 <> 0' % mt) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol3 <> 0 and ts < now + 5m and ts < now + 5m and tgcol1 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol3 <> 0 and ts < 1605045600000 + 300001 and ts < 1605045600000 + 300001 and tgcol1 <> 0' % mt) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') @@ -884,104 +883,104 @@ class TDTestCase: # TSIM: # TSIM: print =============== step13 tdLog.info('=============== step13') - # TSIM: sql select * from %s where ts > now + 4m and tgcol3 = 1 and + # TSIM: sql select * from %s where ts > 1605045600000 + 240001 and tgcol3 = 1 and # tgcol2 = 1 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol3 = 1 and tgcol2 = 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol3 = 1 and tgcol2 = 1' % mt) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol3 = 1 and tgcol2 = 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol3 = 1 and tgcol2 = 1' % mt) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from %s where ts > now + 4m and tgcol3 <> 1 and + # TSIM: sql select * from %s where ts > 1605045600000 + 240001 and tgcol3 <> 1 and # tgcol2 <> 1 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol3 <> 1 and tgcol2 <> 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol3 <> 1 and tgcol2 <> 1' % mt) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol3 <> 1 and tgcol2 <> 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol3 <> 1 and tgcol2 <> 1' % mt) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from %s where ts < now + 4m and tgcol3 = 0 and + # TSIM: sql select * from %s where ts < 1605045600000 + 240001 and tgcol3 = 0 and # tgcol2 = 0 tdLog.info( - 'select * from %s where ts < now + 4m and tgcol3 = 0 and tgcol2 = 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol3 = 0 and tgcol2 = 0' % mt) tdSql.query( - 'select * from %s where ts < now + 4m and tgcol3 = 0 and tgcol2 = 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol3 = 0 and tgcol2 = 0' % mt) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from %s where ts < now + 4m and tgcol3 <> 0 and + # TSIM: sql select * from %s where ts < 1605045600000 + 240001 and tgcol3 <> 0 and # tgcol2 <> 0 tdLog.info( - 'select * from %s where ts < now + 4m and tgcol3 <> 0 and tgcol2 <> 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol3 <> 0 and tgcol2 <> 0' % mt) tdSql.query( - 'select * from %s where ts < now + 4m and tgcol3 <> 0 and tgcol2 <> 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol3 <> 0 and tgcol2 <> 0' % mt) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from %s where ts <= now + 4m and tgcol3 = 0 and + # TSIM: sql select * from %s where ts <= 1605045600000 + 240001 and tgcol3 = 0 and # tgcol2 = 0 tdLog.info( - 'select * from %s where ts <= now + 4m and tgcol3 = 0 and tgcol2 = 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol3 = 0 and tgcol2 = 0' % mt) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol3 = 0 and tgcol2 = 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol3 = 0 and tgcol2 = 0' % mt) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from %s where ts <= now + 4m and tgcol3 <> 0 and + # TSIM: sql select * from %s where ts <= 1605045600000 + 240001 and tgcol3 <> 0 and # tgcol2 <> 0 tdLog.info( - 'select * from %s where ts <= now + 4m and tgcol3 <> 0 and tgcol2 <> 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol3 <> 0 and tgcol2 <> 0' % mt) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol3 <> 0 and tgcol2 <> 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol3 <> 0 and tgcol2 <> 0' % mt) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from %s where ts > now + 4m and ts < now + 5m and + # TSIM: sql select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and # tgcol3 <> 0 and tgcol2 <> 0 tdLog.info( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol3 <> 0 and tgcol2 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol3 <> 0 and tgcol2 <> 0' % mt) tdSql.query( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol3 <> 0 and tgcol2 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol3 <> 0 and tgcol2 <> 0' % mt) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') tdSql.checkRows(5) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from %s where ts > now + 4m and tgcol3 <> 0 and ts - # < now + 5m and ts < now + 5m and tgcol2 <> 0 + # TSIM: sql select * from %s where ts > 1605045600000 + 240001 and tgcol3 <> 0 and ts + # < 1605045600000 + 300001 and ts < 1605045600000 + 300001 and tgcol2 <> 0 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol3 <> 0 and ts < now + 5m and ts < now + 5m and tgcol2 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol3 <> 0 and ts < 1605045600000 + 300001 and ts < 1605045600000 + 300001 and tgcol2 <> 0' % mt) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol3 <> 0 and ts < now + 5m and ts < now + 5m and tgcol2 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol3 <> 0 and ts < 1605045600000 + 300001 and ts < 1605045600000 + 300001 and tgcol2 <> 0' % mt) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') @@ -991,104 +990,104 @@ class TDTestCase: # TSIM: # TSIM: print =============== step14 tdLog.info('=============== step14') - # TSIM: sql select * from %s where ts > now + 4m and tgcol3 = 1 and + # TSIM: sql select * from %s where ts > 1605045600000 + 240001 and tgcol3 = 1 and # tgcol4 = 1 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol3 = 1 and tgcol4 = 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol3 = 1 and tgcol4 = 1' % mt) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol3 = 1 and tgcol4 = 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol3 = 1 and tgcol4 = 1' % mt) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from %s where ts > now + 4m and tgcol3 <> 1 and + # TSIM: sql select * from %s where ts > 1605045600000 + 240001 and tgcol3 <> 1 and # tgcol4 <> 1 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol3 <> 1 and tgcol4 <> 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol3 <> 1 and tgcol4 <> 1' % mt) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol3 <> 1 and tgcol4 <> 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol3 <> 1 and tgcol4 <> 1' % mt) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from %s where ts < now + 4m and tgcol3 = 0 and + # TSIM: sql select * from %s where ts < 1605045600000 + 240001 and tgcol3 = 0 and # tgcol4 = 0 tdLog.info( - 'select * from %s where ts < now + 4m and tgcol3 = 0 and tgcol4 = 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol3 = 0 and tgcol4 = 0' % mt) tdSql.query( - 'select * from %s where ts < now + 4m and tgcol3 = 0 and tgcol4 = 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol3 = 0 and tgcol4 = 0' % mt) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from %s where ts < now + 4m and tgcol3 <> 0 and + # TSIM: sql select * from %s where ts < 1605045600000 + 240001 and tgcol3 <> 0 and # tgcol4 <> 0 tdLog.info( - 'select * from %s where ts < now + 4m and tgcol3 <> 0 and tgcol4 <> 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol3 <> 0 and tgcol4 <> 0' % mt) tdSql.query( - 'select * from %s where ts < now + 4m and tgcol3 <> 0 and tgcol4 <> 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol3 <> 0 and tgcol4 <> 0' % mt) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from %s where ts <= now + 4m and tgcol3 = 0 and + # TSIM: sql select * from %s where ts <= 1605045600000 + 240001 and tgcol3 = 0 and # tgcol4 = 0 tdLog.info( - 'select * from %s where ts <= now + 4m and tgcol3 = 0 and tgcol4 = 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol3 = 0 and tgcol4 = 0' % mt) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol3 = 0 and tgcol4 = 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol3 = 0 and tgcol4 = 0' % mt) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from %s where ts <= now + 4m and tgcol3 <> 0 and + # TSIM: sql select * from %s where ts <= 1605045600000 + 240001 and tgcol3 <> 0 and # tgcol4 <> 0 tdLog.info( - 'select * from %s where ts <= now + 4m and tgcol3 <> 0 and tgcol4 <> 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol3 <> 0 and tgcol4 <> 0' % mt) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol3 <> 0 and tgcol4 <> 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol3 <> 0 and tgcol4 <> 0' % mt) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from %s where ts > now + 4m and ts < now + 5m and + # TSIM: sql select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and # tgcol3 <> 0 and tgcol4 <> 0 tdLog.info( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol3 <> 0 and tgcol4 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol3 <> 0 and tgcol4 <> 0' % mt) tdSql.query( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol3 <> 0 and tgcol4 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol3 <> 0 and tgcol4 <> 0' % mt) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') tdSql.checkRows(5) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from %s where ts > now + 4m and tgcol3 <> 0 and ts - # < now + 5m and ts < now + 5m and tgcol4 <> 0 + # TSIM: sql select * from %s where ts > 1605045600000 + 240001 and tgcol3 <> 0 and ts + # < 1605045600000 + 300001 and ts < 1605045600000 + 300001 and tgcol4 <> 0 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol3 <> 0 and ts < now + 5m and ts < now + 5m and tgcol4 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol3 <> 0 and ts < 1605045600000 + 300001 and ts < 1605045600000 + 300001 and tgcol4 <> 0' % mt) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol3 <> 0 and ts < now + 5m and ts < now + 5m and tgcol4 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol3 <> 0 and ts < 1605045600000 + 300001 and ts < 1605045600000 + 300001 and tgcol4 <> 0' % mt) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') @@ -1098,104 +1097,104 @@ class TDTestCase: # TSIM: # TSIM: print =============== step15 tdLog.info('=============== step15') - # TSIM: sql select * from %s where ts > now + 4m and tgcol1 = 1 and + # TSIM: sql select * from %s where ts > 1605045600000 + 240001 and tgcol1 = 1 and # tgcol2 = 1 and tgcol3 = 1 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol1 = 1 and tgcol2 = 1 and tgcol3 = 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol1 = 1 and tgcol2 = 1 and tgcol3 = 1' % mt) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol1 = 1 and tgcol2 = 1 and tgcol3 = 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol1 = 1 and tgcol2 = 1 and tgcol3 = 1' % mt) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from %s where ts > now + 4m and tgcol1 <> 1 and + # TSIM: sql select * from %s where ts > 1605045600000 + 240001 and tgcol1 <> 1 and # tgcol2 <> 1 and tgcol3 <> 1 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol1 <> 1 and tgcol2 <> 1 and tgcol3 <> 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol1 <> 1 and tgcol2 <> 1 and tgcol3 <> 1' % mt) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol1 <> 1 and tgcol2 <> 1 and tgcol3 <> 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol1 <> 1 and tgcol2 <> 1 and tgcol3 <> 1' % mt) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from %s where ts < now + 4m and tgcol1 = 0 and + # TSIM: sql select * from %s where ts < 1605045600000 + 240001 and tgcol1 = 0 and # tgcol2 = 0 and tgcol3 = 0 tdLog.info( - 'select * from %s where ts < now + 4m and tgcol1 = 0 and tgcol2 = 0 and tgcol3 = 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol1 = 0 and tgcol2 = 0 and tgcol3 = 0' % mt) tdSql.query( - 'select * from %s where ts < now + 4m and tgcol1 = 0 and tgcol2 = 0 and tgcol3 = 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol1 = 0 and tgcol2 = 0 and tgcol3 = 0' % mt) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from %s where ts < now + 4m and tgcol1 <> 0 and + # TSIM: sql select * from %s where ts < 1605045600000 + 240001 and tgcol1 <> 0 and # tgcol2 <> 0 and tgcol3 <> 0 tdLog.info( - 'select * from %s where ts < now + 4m and tgcol1 <> 0 and tgcol2 <> 0 and tgcol3 <> 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol1 <> 0 and tgcol2 <> 0 and tgcol3 <> 0' % mt) tdSql.query( - 'select * from %s where ts < now + 4m and tgcol1 <> 0 and tgcol2 <> 0 and tgcol3 <> 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol1 <> 0 and tgcol2 <> 0 and tgcol3 <> 0' % mt) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from %s where ts <= now + 4m and tgcol1 = 0 and + # TSIM: sql select * from %s where ts <= 1605045600000 + 240001 and tgcol1 = 0 and # tgcol2 = 0 and tgcol3 = 0 tdLog.info( - 'select * from %s where ts <= now + 4m and tgcol1 = 0 and tgcol2 = 0 and tgcol3 = 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol1 = 0 and tgcol2 = 0 and tgcol3 = 0' % mt) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol1 = 0 and tgcol2 = 0 and tgcol3 = 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol1 = 0 and tgcol2 = 0 and tgcol3 = 0' % mt) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from %s where ts <= now + 4m and tgcol1 <> 0 and + # TSIM: sql select * from %s where ts <= 1605045600000 + 240001 and tgcol1 <> 0 and # tgcol2 <> 0 and tgcol3 <> 0 tdLog.info( - 'select * from %s where ts <= now + 4m and tgcol1 <> 0 and tgcol2 <> 0 and tgcol3 <> 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol1 <> 0 and tgcol2 <> 0 and tgcol3 <> 0' % mt) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol1 <> 0 and tgcol2 <> 0 and tgcol3 <> 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol1 <> 0 and tgcol2 <> 0 and tgcol3 <> 0' % mt) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from %s where ts > now + 4m and ts < now + 5m and + # TSIM: sql select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and # tgcol1 <> 0 and tgcol2 <> 0 and tgcol3 <> 0 tdLog.info( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol1 <> 0 and tgcol2 <> 0 and tgcol3 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol1 <> 0 and tgcol2 <> 0 and tgcol3 <> 0' % mt) tdSql.query( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol1 <> 0 and tgcol2 <> 0 and tgcol3 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol1 <> 0 and tgcol2 <> 0 and tgcol3 <> 0' % mt) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') tdSql.checkRows(5) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from %s where ts > now + 4m and tgcol1 <> 0 and ts - # < now + 5m and ts < now + 5m and tgcol2 <> 0 and tgcol3 <> 0 + # TSIM: sql select * from %s where ts > 1605045600000 + 240001 and tgcol1 <> 0 and ts + # < 1605045600000 + 300001 and ts < 1605045600000 + 300001 and tgcol2 <> 0 and tgcol3 <> 0 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol1 <> 0 and ts < now + 5m and ts < now + 5m and tgcol2 <> 0 and tgcol3 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol1 <> 0 and ts < 1605045600000 + 300001 and ts < 1605045600000 + 300001 and tgcol2 <> 0 and tgcol3 <> 0' % mt) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol1 <> 0 and ts < now + 5m and ts < now + 5m and tgcol2 <> 0 and tgcol3 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol1 <> 0 and ts < 1605045600000 + 300001 and ts < 1605045600000 + 300001 and tgcol2 <> 0 and tgcol3 <> 0' % mt) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') @@ -1205,104 +1204,104 @@ class TDTestCase: # TSIM: # TSIM: print =============== step16 tdLog.info('=============== step16') - # TSIM: sql select * from %s where ts > now + 4m and tgcol4 = 1 and + # TSIM: sql select * from %s where ts > 1605045600000 + 240001 and tgcol4 = 1 and # tgcol2 = 1 and tgcol3 = 1 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol4 = 1 and tgcol2 = 1 and tgcol3 = 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol4 = 1 and tgcol2 = 1 and tgcol3 = 1' % mt) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol4 = 1 and tgcol2 = 1 and tgcol3 = 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol4 = 1 and tgcol2 = 1 and tgcol3 = 1' % mt) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from %s where ts > now + 4m and tgcol4 <> 1 and + # TSIM: sql select * from %s where ts > 1605045600000 + 240001 and tgcol4 <> 1 and # tgcol2 <> 1 and tgcol3 <> 1 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol4 <> 1 and tgcol2 <> 1 and tgcol3 <> 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol4 <> 1 and tgcol2 <> 1 and tgcol3 <> 1' % mt) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol4 <> 1 and tgcol2 <> 1 and tgcol3 <> 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol4 <> 1 and tgcol2 <> 1 and tgcol3 <> 1' % mt) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from %s where ts < now + 4m and tgcol4 = 0 and + # TSIM: sql select * from %s where ts < 1605045600000 + 240001 and tgcol4 = 0 and # tgcol2 = 0 and tgcol3 = 0 tdLog.info( - 'select * from %s where ts < now + 4m and tgcol4 = 0 and tgcol2 = 0 and tgcol3 = 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol4 = 0 and tgcol2 = 0 and tgcol3 = 0' % mt) tdSql.query( - 'select * from %s where ts < now + 4m and tgcol4 = 0 and tgcol2 = 0 and tgcol3 = 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol4 = 0 and tgcol2 = 0 and tgcol3 = 0' % mt) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from %s where ts < now + 4m and tgcol4 <> 0 and + # TSIM: sql select * from %s where ts < 1605045600000 + 240001 and tgcol4 <> 0 and # tgcol2 <> 0 and tgcol3 <> 0 tdLog.info( - 'select * from %s where ts < now + 4m and tgcol4 <> 0 and tgcol2 <> 0 and tgcol3 <> 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol4 <> 0 and tgcol2 <> 0 and tgcol3 <> 0' % mt) tdSql.query( - 'select * from %s where ts < now + 4m and tgcol4 <> 0 and tgcol2 <> 0 and tgcol3 <> 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol4 <> 0 and tgcol2 <> 0 and tgcol3 <> 0' % mt) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from %s where ts <= now + 4m and tgcol4 = 0 and + # TSIM: sql select * from %s where ts <= 1605045600000 + 240001 and tgcol4 = 0 and # tgcol2 = 0 and tgcol3 = 0 tdLog.info( - 'select * from %s where ts <= now + 4m and tgcol4 = 0 and tgcol2 = 0 and tgcol3 = 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol4 = 0 and tgcol2 = 0 and tgcol3 = 0' % mt) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol4 = 0 and tgcol2 = 0 and tgcol3 = 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol4 = 0 and tgcol2 = 0 and tgcol3 = 0' % mt) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from %s where ts <= now + 4m and tgcol4 <> 0 and + # TSIM: sql select * from %s where ts <= 1605045600000 + 240001 and tgcol4 <> 0 and # tgcol2 <> 0 and tgcol3 <> 0 tdLog.info( - 'select * from %s where ts <= now + 4m and tgcol4 <> 0 and tgcol2 <> 0 and tgcol3 <> 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol4 <> 0 and tgcol2 <> 0 and tgcol3 <> 0' % mt) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol4 <> 0 and tgcol2 <> 0 and tgcol3 <> 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol4 <> 0 and tgcol2 <> 0 and tgcol3 <> 0' % mt) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from %s where ts > now + 4m and ts < now + 5m and + # TSIM: sql select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and # tgcol4 <> 0 and tgcol2 <> 0 and tgcol3 <> 0 tdLog.info( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol4 <> 0 and tgcol2 <> 0 and tgcol3 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol4 <> 0 and tgcol2 <> 0 and tgcol3 <> 0' % mt) tdSql.query( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol4 <> 0 and tgcol2 <> 0 and tgcol3 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol4 <> 0 and tgcol2 <> 0 and tgcol3 <> 0' % mt) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') tdSql.checkRows(5) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from %s where ts > now + 4m and tgcol4 <> 0 and ts - # < now + 5m and ts < now + 5m and tgcol2 <> 0 and tgcol3 <> 0 + # TSIM: sql select * from %s where ts > 1605045600000 + 240001 and tgcol4 <> 0 and ts + # < 1605045600000 + 300001 and ts < 1605045600000 + 300001 and tgcol2 <> 0 and tgcol3 <> 0 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol4 <> 0 and ts < now + 5m and ts < now + 5m and tgcol2 <> 0 and tgcol3 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol4 <> 0 and ts < 1605045600000 + 300001 and ts < 1605045600000 + 300001 and tgcol2 <> 0 and tgcol3 <> 0' % mt) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol4 <> 0 and ts < now + 5m and ts < now + 5m and tgcol2 <> 0 and tgcol3 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol4 <> 0 and ts < 1605045600000 + 300001 and ts < 1605045600000 + 300001 and tgcol2 <> 0 and tgcol3 <> 0' % mt) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') @@ -1312,105 +1311,105 @@ class TDTestCase: # TSIM: # TSIM: print =============== step17 tdLog.info('=============== step17') - # TSIM: sql select * from %s where ts > now + 4m and tgcol4 = 1 and + # TSIM: sql select * from %s where ts > 1605045600000 + 240001 and tgcol4 = 1 and # tgcol2 = 1 and tgcol3 = 1 and tgcol1 = 1 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol4 = 1 and tgcol2 = 1 and tgcol3 = 1 and tgcol1 = 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol4 = 1 and tgcol2 = 1 and tgcol3 = 1 and tgcol1 = 1' % mt) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol4 = 1 and tgcol2 = 1 and tgcol3 = 1 and tgcol1 = 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol4 = 1 and tgcol2 = 1 and tgcol3 = 1 and tgcol1 = 1' % mt) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from %s where ts > now + 4m and tgcol4 <> 1 and + # TSIM: sql select * from %s where ts > 1605045600000 + 240001 and tgcol4 <> 1 and # tgcol2 <> 1 and tgcol3 <> 1 and tgcol1 <> 1 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol4 <> 1 and tgcol2 <> 1 and tgcol3 <> 1 and tgcol1 <> 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol4 <> 1 and tgcol2 <> 1 and tgcol3 <> 1 and tgcol1 <> 1' % mt) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol4 <> 1 and tgcol2 <> 1 and tgcol3 <> 1 and tgcol1 <> 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol4 <> 1 and tgcol2 <> 1 and tgcol3 <> 1 and tgcol1 <> 1' % mt) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from %s where ts < now + 4m and tgcol4 = 0 and + # TSIM: sql select * from %s where ts < 1605045600000 + 240001 and tgcol4 = 0 and # tgcol2 = 0 and tgcol3 = 0 and tgcol1 = 0 tdLog.info( - 'select * from %s where ts < now + 4m and tgcol4 = 0 and tgcol2 = 0 and tgcol3 = 0 and tgcol1 = 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol4 = 0 and tgcol2 = 0 and tgcol3 = 0 and tgcol1 = 0' % mt) tdSql.query( - 'select * from %s where ts < now + 4m and tgcol4 = 0 and tgcol2 = 0 and tgcol3 = 0 and tgcol1 = 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol4 = 0 and tgcol2 = 0 and tgcol3 = 0 and tgcol1 = 0' % mt) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from %s where ts < now + 4m and tgcol4 <> 0 and + # TSIM: sql select * from %s where ts < 1605045600000 + 240001 and tgcol4 <> 0 and # tgcol2 <> 0 and tgcol3 <> 0 and tgcol1 <> 0 tdLog.info( - 'select * from %s where ts < now + 4m and tgcol4 <> 0 and tgcol2 <> 0 and tgcol3 <> 0 and tgcol1 <> 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol4 <> 0 and tgcol2 <> 0 and tgcol3 <> 0 and tgcol1 <> 0' % mt) tdSql.query( - 'select * from %s where ts < now + 4m and tgcol4 <> 0 and tgcol2 <> 0 and tgcol3 <> 0 and tgcol1 <> 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol4 <> 0 and tgcol2 <> 0 and tgcol3 <> 0 and tgcol1 <> 0' % mt) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from %s where ts <= now + 4m and tgcol4 = 0 and + # TSIM: sql select * from %s where ts <= 1605045600000 + 240001 and tgcol4 = 0 and # tgcol2 = 0 and tgcol3 = 0 and tgcol1 = 0 tdLog.info( - 'select * from %s where ts <= now + 4m and tgcol4 = 0 and tgcol2 = 0 and tgcol3 = 0 and tgcol1 = 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol4 = 0 and tgcol2 = 0 and tgcol3 = 0 and tgcol1 = 0' % mt) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol4 = 0 and tgcol2 = 0 and tgcol3 = 0 and tgcol1 = 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol4 = 0 and tgcol2 = 0 and tgcol3 = 0 and tgcol1 = 0' % mt) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from %s where ts <= now + 4m and tgcol4 <> 0 and + # TSIM: sql select * from %s where ts <= 1605045600000 + 240001 and tgcol4 <> 0 and # tgcol2 <> 0 and tgcol3 <> 0 and tgcol1 <> 0 tdLog.info( - 'select * from %s where ts <= now + 4m and tgcol4 <> 0 and tgcol2 <> 0 and tgcol3 <> 0 and tgcol1 <> 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol4 <> 0 and tgcol2 <> 0 and tgcol3 <> 0 and tgcol1 <> 0' % mt) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol4 <> 0 and tgcol2 <> 0 and tgcol3 <> 0 and tgcol1 <> 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol4 <> 0 and tgcol2 <> 0 and tgcol3 <> 0 and tgcol1 <> 0' % mt) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from %s where ts > now + 4m and ts < now + 5m and + # TSIM: sql select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and # tgcol4 <> 0 and tgcol2 <> 0 and tgcol3 <> 0 and tgcol1 <> 0 tdLog.info( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol4 <> 0 and tgcol2 <> 0 and tgcol3 <> 0 and tgcol1 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol4 <> 0 and tgcol2 <> 0 and tgcol3 <> 0 and tgcol1 <> 0' % mt) tdSql.query( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol4 <> 0 and tgcol2 <> 0 and tgcol3 <> 0 and tgcol1 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol4 <> 0 and tgcol2 <> 0 and tgcol3 <> 0 and tgcol1 <> 0' % mt) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') tdSql.checkRows(5) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from %s where ts > now + 4m and tgcol4 <> 0 and ts - # < now + 5m and ts < now + 5m and tgcol2 <> 0 and tgcol3 <> 0 and + # TSIM: sql select * from %s where ts > 1605045600000 + 240001 and tgcol4 <> 0 and ts + # < 1605045600000 + 300001 and ts < 1605045600000 + 300001 and tgcol2 <> 0 and tgcol3 <> 0 and # tgcol1 <> 0 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol4 <> 0 and ts < now + 5m and ts < now + 5m and tgcol2 <> 0 and tgcol3 <> 0 and tgcol1 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol4 <> 0 and ts < 1605045600000 + 300001 and ts < 1605045600000 + 300001 and tgcol2 <> 0 and tgcol3 <> 0 and tgcol1 <> 0' % mt) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol4 <> 0 and ts < now + 5m and ts < now + 5m and tgcol2 <> 0 and tgcol3 <> 0 and tgcol1 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol4 <> 0 and ts < 1605045600000 + 300001 and ts < 1605045600000 + 300001 and tgcol2 <> 0 and tgcol3 <> 0 and tgcol1 <> 0' % mt) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') @@ -1508,12 +1507,12 @@ class TDTestCase: # TSIM: print =============== step20 tdLog.info('=============== step20') # TSIM: sql select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), - # max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m + # max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001 tdLog.info( - 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m' % + 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001' % mt) tdSql.query( - 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m' % + 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001' % mt) # TSIM: print $data00 $data01 $data02 $data03 $data04 $data05 $data06 tdLog.info('$data00 $data01 $data02 $data03 $data04 $data05 $data06') @@ -1524,13 +1523,13 @@ class TDTestCase: # TSIM: endi # TSIM: # TSIM: sql select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), - # max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m and + # max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001 and # tgcol1 = 1 tdLog.info( - 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m and tgcol1 = 1' % + 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001 and tgcol1 = 1' % mt) tdSql.query( - 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m and tgcol1 = 1' % + 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001 and tgcol1 = 1' % mt) # TSIM: print $data00 $data01 $data02 $data03 $data04 $data05 $data06 tdLog.info('$data00 $data01 $data02 $data03 $data04 $data05 $data06') @@ -1541,13 +1540,13 @@ class TDTestCase: # TSIM: endi # TSIM: # TSIM: sql select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), - # max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m and + # max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001 and # tgcol1 = 1 and tgcol2 = 1 tdLog.info( - 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m and tgcol1 = 1 and tgcol2 = 1' % + 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001 and tgcol1 = 1 and tgcol2 = 1' % mt) tdSql.query( - 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m and tgcol1 = 1 and tgcol2 = 1' % + 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001 and tgcol1 = 1 and tgcol2 = 1' % mt) # TSIM: print $data00 $data01 $data02 $data03 $data04 $data05 $data06 tdLog.info('$data00 $data01 $data02 $data03 $data04 $data05 $data06') @@ -1558,13 +1557,13 @@ class TDTestCase: # TSIM: endi # TSIM: # TSIM: sql select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), - # max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m and + # max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001 and # tgcol1 = 1 and tgcol2 = 1 and tgcol3 = 1 tdLog.info( - 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m and tgcol1 = 1 and tgcol2 = 1 and tgcol3 = 1' % + 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001 and tgcol1 = 1 and tgcol2 = 1 and tgcol3 = 1' % mt) tdSql.query( - 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m and tgcol1 = 1 and tgcol2 = 1 and tgcol3 = 1' % + 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001 and tgcol1 = 1 and tgcol2 = 1 and tgcol3 = 1' % mt) # TSIM: print $data00 $data01 $data02 $data03 $data04 $data05 $data06 tdLog.info('$data00 $data01 $data02 $data03 $data04 $data05 $data06') @@ -1575,10 +1574,10 @@ class TDTestCase: # TSIM: endi # TSIM: # TSIM: sql select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), - # max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m and + # max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001 and # tgcol1 = 1 and tgcol2 = 1 and tgcol3 = 1 and tgcol4 = 1 - tdLog.info('select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m and tgcol1 = 1 and tgcol2 = 1 and tgcol3 = 1 and tgcol4 = 1' % mt) - tdSql.query('select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m and tgcol1 = 1 and tgcol2 = 1 and tgcol3 = 1 and tgcol4 = 1' % mt) + tdLog.info('select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001 and tgcol1 = 1 and tgcol2 = 1 and tgcol3 = 1 and tgcol4 = 1' % mt) + tdSql.query('select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001 and tgcol1 = 1 and tgcol2 = 1 and tgcol3 = 1 and tgcol4 = 1' % mt) # TSIM: print $data00 $data01 $data02 $data03 $data04 $data05 $data06 tdLog.info('$data00 $data01 $data02 $data03 $data04 $data05 $data06') # TSIM: if $data00 != 25 then @@ -1722,13 +1721,13 @@ class TDTestCase: # TSIM: print =============== step23 tdLog.info('=============== step23') # TSIM: sql select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), - # max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m + # max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001 # group by tgcol2 tdLog.info( - 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m group by tgcol2' % + 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001 group by tgcol2' % mt) tdSql.query( - 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m group by tgcol2' % + 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001 group by tgcol2' % mt) # TSIM: print $data00 $data01 $data02 $data03 $data04 $data05 $data06 tdLog.info('$data00 $data01 $data02 $data03 $data04 $data05 $data06') @@ -1739,13 +1738,13 @@ class TDTestCase: # TSIM: endi # TSIM: # TSIM: sql select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), - # max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m and + # max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001 and # tgcol1 = 1 group by tgcol2 tdLog.info( - 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m and tgcol1 = 1 group by tgcol2' % + 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001 and tgcol1 = 1 group by tgcol2' % mt) tdSql.query( - 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m and tgcol1 = 1 group by tgcol2' % + 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001 and tgcol1 = 1 group by tgcol2' % mt) # TSIM: print $data00 $data01 $data02 $data03 $data04 $data05 $data06 tdLog.info('$data00 $data01 $data02 $data03 $data04 $data05 $data06') @@ -1756,11 +1755,11 @@ class TDTestCase: # TSIM: endi # TSIM: # TSIM: sql select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), - # max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m and + # max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001 and # tgcol1 = 1 and tgcol2 = 1 group by tgcol2 - tdLog.info('select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m and tgcol1 = 1 and tgcol2 = 1 group by tgcol2' % mt) + tdLog.info('select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001 and tgcol1 = 1 and tgcol2 = 1 group by tgcol2' % mt) tdSql.query( - 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m and tgcol1 = 1 and tgcol2 = 1 group by tgcol2' % + 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001 and tgcol1 = 1 and tgcol2 = 1 group by tgcol2' % mt) # TSIM: print $data00 $data01 $data02 $data03 $data04 $data05 $data06 tdLog.info('$data00 $data01 $data02 $data03 $data04 $data05 $data06') @@ -1771,10 +1770,10 @@ class TDTestCase: # TSIM: endi # TSIM: # TSIM: sql select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), - # max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m and + # max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001 and # tgcol1 = 1 and tgcol2 = 1 and tgcol3 = 1 group by tgcol2 - tdLog.info('select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m and tgcol1 = 1 and tgcol2 = 1 and tgcol3 = 1 group by tgcol2' % mt) - tdSql.query('select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m and tgcol1 = 1 and tgcol2 = 1 and tgcol3 = 1 group by tgcol2' % mt) + tdLog.info('select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001 and tgcol1 = 1 and tgcol2 = 1 and tgcol3 = 1 group by tgcol2' % mt) + tdSql.query('select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001 and tgcol1 = 1 and tgcol2 = 1 and tgcol3 = 1 group by tgcol2' % mt) # TSIM: print $data00 $data01 $data02 $data03 $data04 $data05 $data06 tdLog.info('$data00 $data01 $data02 $data03 $data04 $data05 $data06') # TSIM: if $data00 != 25 then @@ -1784,11 +1783,11 @@ class TDTestCase: # TSIM: endi # TSIM: # TSIM: sql select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), - # max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m and + # max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001 and # tgcol1 = 1 and tgcol2 = 1 and tgcol3 = 1 and tgcol4 = 1 group by # tgcol2 - tdLog.info('select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m and tgcol1 = 1 and tgcol2 = 1 and tgcol3 = 1 and tgcol4 = 1 group by tgcol2' % mt) - tdSql.query('select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m and tgcol1 = 1 and tgcol2 = 1 and tgcol3 = 1 and tgcol4 = 1 group by tgcol2' % mt) + tdLog.info('select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001 and tgcol1 = 1 and tgcol2 = 1 and tgcol3 = 1 and tgcol4 = 1 group by tgcol2' % mt) + tdSql.query('select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001 and tgcol1 = 1 and tgcol2 = 1 and tgcol3 = 1 and tgcol4 = 1 group by tgcol2' % mt) # TSIM: print $data00 $data01 $data02 $data03 $data04 $data05 $data06 tdLog.info('$data00 $data01 $data02 $data03 $data04 $data05 $data06') # TSIM: if $data00 != 25 then diff --git a/tests/pytest/tag_lite/5.py b/tests/pytest/tag_lite/5.py index b3608bebee649b38b0d1315cc1cb97a43d5365e6..28c8fc125a9c9f27230e63494e9d7f57c5505154 100644 --- a/tests/pytest/tag_lite/5.py +++ b/tests/pytest/tag_lite/5.py @@ -76,14 +76,13 @@ class TDTestCase: # TSIM: while $x < $rowNum while (x < rowNum): # TSIM: $ms = $x . m - ms = "%dm" % x - # TSIM: sql insert into $tb values (now + $ms , $x ) + ms = x * 60000 tdLog.info( - 'insert into %s values (now + %s, %d)' % - (tb, ms, x)) + "insert into %s values (%d, %d)" % + (tb, 1605045600000 + ms, x)) tdSql.execute( - 'insert into %s values (now + %s, %d)' % - (tb, ms, x)) + "insert into %s values (%d, %d)" % + (tb, 1605045600000 + ms, x)) # TSIM: $x = $x + 1 x = x + 1 # TSIM: endw @@ -105,14 +104,13 @@ class TDTestCase: # TSIM: while $x < $rowNum while (x < rowNum): # TSIM: $ms = $x . m - ms = "%dm" % x - # TSIM: sql insert into $tb values (now + $ms , $x ) + ms = x * 60000 tdLog.info( - 'insert into %s values (now + %s, %d)' % - (tb, ms, x)) + "insert into %s values (%d, %d)" % + (tb, 1605045600000 + ms, x)) tdSql.execute( - 'insert into %s values (now + %s, %d)' % - (tb, ms, x)) + "insert into %s values (%d, %d)" % + (tb, 1605045600000 + ms, x)) # TSIM: $x = $x + 1 x = x + 1 # TSIM: endw @@ -131,36 +129,36 @@ class TDTestCase: # TSIM: return -1 # TSIM: endi # TSIM: - # TSIM: sql select * from $mt where ts < now + 4m - tdLog.info('select * from %s where ts < now + 4m' % (mt)) - tdSql.query('select * from %s where ts < now + 4m' % (mt)) + # TSIM: sql select * from $mt where ts < 1605045600000 + 240001 + tdLog.info('select * from %s where ts < 1605045600000 + 240001' % (mt)) + tdSql.query('select * from %s where ts < 1605045600000 + 240001' % (mt)) # TSIM: if $rows != 50 then tdLog.info('tdSql.checkRow(50)') tdSql.checkRows(50) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m - tdLog.info('select * from %s where ts > now + 4m' % (mt)) - tdSql.query('select * from %s where ts > now + 4m' % (mt)) + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 + tdLog.info('select * from %s where ts > 1605045600000 + 240001' % (mt)) + tdSql.query('select * from %s where ts > 1605045600000 + 240001' % (mt)) # TSIM: if $rows != 150 then tdLog.info('tdSql.checkRow(150)') tdSql.checkRows(150) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts = now + 4m - tdLog.info('select * from %s where ts = now + 4m' % (mt)) - tdSql.query('select * from %s where ts = now + 4m' % (mt)) + # TSIM: sql select * from $mt where ts = 1605045600000 + 240001 + tdLog.info('select * from %s where ts = 1605045600000 + 240001' % (mt)) + tdSql.query('select * from %s where ts = 1605045600000 + 240001' % (mt)) # TSIM: if $rows != 0 then tdLog.info('tdSql.checkRow(0)') tdSql.checkRows(0) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and ts < now + 5m + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 tdLog.info( - 'select * from %s where ts > now + 4m and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001' % (mt)) # TSIM: if $rows != 10 then tdLog.info('tdSql.checkRow(10)') @@ -377,98 +375,98 @@ class TDTestCase: # TSIM: # TSIM: print =============== step8 tdLog.info('=============== step8') - # TSIM: sql select * from $mt where ts > now + 4m and tgcol1 = 1 + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol1 = 1 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol1 = 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol1 = 1' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol1 = 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol1 = 1' % (mt)) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and tgcol1 <> 1 + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol1 <> 1 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol1 <> 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol1 <> 1' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol1 <> 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol1 <> 1' % (mt)) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts < now + 4m and tgcol1 = 0 + # TSIM: sql select * from $mt where ts < 1605045600000 + 240001 and tgcol1 = 0 tdLog.info( - 'select * from %s where ts < now + 4m and tgcol1 = 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol1 = 0' % (mt)) tdSql.query( - 'select * from %s where ts < now + 4m and tgcol1 = 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol1 = 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts < now + 4m and tgcol1 <> 0 + # TSIM: sql select * from $mt where ts < 1605045600000 + 240001 and tgcol1 <> 0 tdLog.info( - 'select * from %s where ts < now + 4m and tgcol1 <> 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol1 <> 0' % (mt)) tdSql.query( - 'select * from %s where ts < now + 4m and tgcol1 <> 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol1 <> 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts <= now + 4m and tgcol1 = 0 + # TSIM: sql select * from $mt where ts <= 1605045600000 + 240001 and tgcol1 = 0 tdLog.info( - 'select * from %s where ts <= now + 4m and tgcol1 = 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol1 = 0' % (mt)) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol1 = 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol1 = 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts <= now + 4m and tgcol1 <> 0 + # TSIM: sql select * from $mt where ts <= 1605045600000 + 240001 and tgcol1 <> 0 tdLog.info( - 'select * from %s where ts <= now + 4m and tgcol1 <> 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol1 <> 0' % (mt)) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol1 <> 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol1 <> 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and ts < now + 5m and + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and # tgcol1 <> 0 tdLog.info( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol1 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol1 <> 0' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol1 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol1 <> 0' % (mt)) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') tdSql.checkRows(5) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and tgcol1 <> 0 and - # ts < now + 5m + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol1 <> 0 and + # ts < 1605045600000 + 300001 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol1 <> 0 and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol1 <> 0 and ts < 1605045600000 + 300001' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol1 <> 0 and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol1 <> 0 and ts < 1605045600000 + 300001' % (mt)) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') @@ -478,98 +476,98 @@ class TDTestCase: # TSIM: # TSIM: print =============== step9 tdLog.info('=============== step9') - # TSIM: sql select * from $mt where ts > now + 4m and tgcol2 = 1 + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol2 = 1 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol2 = 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol2 = 1' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol2 = 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol2 = 1' % (mt)) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and tgcol2 <> 1 + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol2 <> 1 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol2 <> 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol2 <> 1' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol2 <> 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol2 <> 1' % (mt)) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts < now + 4m and tgcol2 = 0 + # TSIM: sql select * from $mt where ts < 1605045600000 + 240001 and tgcol2 = 0 tdLog.info( - 'select * from %s where ts < now + 4m and tgcol2 = 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol2 = 0' % (mt)) tdSql.query( - 'select * from %s where ts < now + 4m and tgcol2 = 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol2 = 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts < now + 4m and tgcol2 <> 0 + # TSIM: sql select * from $mt where ts < 1605045600000 + 240001 and tgcol2 <> 0 tdLog.info( - 'select * from %s where ts < now + 4m and tgcol2 <> 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol2 <> 0' % (mt)) tdSql.query( - 'select * from %s where ts < now + 4m and tgcol2 <> 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol2 <> 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts <= now + 4m and tgcol2 = 0 + # TSIM: sql select * from $mt where ts <= 1605045600000 + 240001 and tgcol2 = 0 tdLog.info( - 'select * from %s where ts <= now + 4m and tgcol2 = 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol2 = 0' % (mt)) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol2 = 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol2 = 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts <= now + 4m and tgcol2 <> 0 + # TSIM: sql select * from $mt where ts <= 1605045600000 + 240001 and tgcol2 <> 0 tdLog.info( - 'select * from %s where ts <= now + 4m and tgcol2 <> 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol2 <> 0' % (mt)) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol2 <> 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol2 <> 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and ts < now + 5m and + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and # tgcol2 <> 0 tdLog.info( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol2 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol2 <> 0' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol2 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol2 <> 0' % (mt)) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') tdSql.checkRows(5) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and tgcol2 <> 0 and - # ts < now + 5m + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol2 <> 0 and + # ts < 1605045600000 + 300001 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol2 <> 0 and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol2 <> 0 and ts < 1605045600000 + 300001' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol2 <> 0 and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol2 <> 0 and ts < 1605045600000 + 300001' % (mt)) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') @@ -579,98 +577,98 @@ class TDTestCase: # TSIM: # TSIM: print =============== step10 tdLog.info('=============== step10') - # TSIM: sql select * from $mt where ts > now + 4m and tgcol3 = 1 + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol3 = 1 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol3 = 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol3 = 1' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol3 = 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol3 = 1' % (mt)) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and tgcol3 <> 1 + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol3 <> 1 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol3 <> 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol3 <> 1' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol3 <> 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol3 <> 1' % (mt)) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts < now + 4m and tgcol3 = 0 + # TSIM: sql select * from $mt where ts < 1605045600000 + 240001 and tgcol3 = 0 tdLog.info( - 'select * from %s where ts < now + 4m and tgcol3 = 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol3 = 0' % (mt)) tdSql.query( - 'select * from %s where ts < now + 4m and tgcol3 = 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol3 = 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts < now + 4m and tgcol3 <> 0 + # TSIM: sql select * from $mt where ts < 1605045600000 + 240001 and tgcol3 <> 0 tdLog.info( - 'select * from %s where ts < now + 4m and tgcol3 <> 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol3 <> 0' % (mt)) tdSql.query( - 'select * from %s where ts < now + 4m and tgcol3 <> 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol3 <> 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts <= now + 4m and tgcol3 = 0 + # TSIM: sql select * from $mt where ts <= 1605045600000 + 240001 and tgcol3 = 0 tdLog.info( - 'select * from %s where ts <= now + 4m and tgcol3 = 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol3 = 0' % (mt)) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol3 = 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol3 = 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts <= now + 4m and tgcol3 <> 0 + # TSIM: sql select * from $mt where ts <= 1605045600000 + 240001 and tgcol3 <> 0 tdLog.info( - 'select * from %s where ts <= now + 4m and tgcol3 <> 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol3 <> 0' % (mt)) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol3 <> 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol3 <> 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and ts < now + 5m and + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and # tgcol3 <> 0 tdLog.info( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol3 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol3 <> 0' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol3 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol3 <> 0' % (mt)) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') tdSql.checkRows(5) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and tgcol3 <> 0 and - # ts < now + 5m + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol3 <> 0 and + # ts < 1605045600000 + 300001 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol3 <> 0 and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol3 <> 0 and ts < 1605045600000 + 300001' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol3 <> 0 and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol3 <> 0 and ts < 1605045600000 + 300001' % (mt)) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') @@ -680,98 +678,98 @@ class TDTestCase: # TSIM: # TSIM: print =============== step11 tdLog.info('=============== step11') - # TSIM: sql select * from $mt where ts > now + 4m and tgcol4 = 1 + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol4 = 1 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol4 = 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol4 = 1' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol4 = 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol4 = 1' % (mt)) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and tgcol4 <> 1 + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol4 <> 1 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol4 <> 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol4 <> 1' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol4 <> 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol4 <> 1' % (mt)) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts < now + 4m and tgcol4 = 0 + # TSIM: sql select * from $mt where ts < 1605045600000 + 240001 and tgcol4 = 0 tdLog.info( - 'select * from %s where ts < now + 4m and tgcol4 = 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol4 = 0' % (mt)) tdSql.query( - 'select * from %s where ts < now + 4m and tgcol4 = 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol4 = 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts < now + 4m and tgcol4 <> 0 + # TSIM: sql select * from $mt where ts < 1605045600000 + 240001 and tgcol4 <> 0 tdLog.info( - 'select * from %s where ts < now + 4m and tgcol4 <> 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol4 <> 0' % (mt)) tdSql.query( - 'select * from %s where ts < now + 4m and tgcol4 <> 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol4 <> 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts <= now + 4m and tgcol4 = 0 + # TSIM: sql select * from $mt where ts <= 1605045600000 + 240001 and tgcol4 = 0 tdLog.info( - 'select * from %s where ts <= now + 4m and tgcol4 = 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol4 = 0' % (mt)) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol4 = 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol4 = 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts <= now + 4m and tgcol4 <> 0 + # TSIM: sql select * from $mt where ts <= 1605045600000 + 240001 and tgcol4 <> 0 tdLog.info( - 'select * from %s where ts <= now + 4m and tgcol4 <> 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol4 <> 0' % (mt)) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol4 <> 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol4 <> 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and ts < now + 5m and + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and # tgcol4 <> 0 tdLog.info( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol4 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol4 <> 0' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol4 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol4 <> 0' % (mt)) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') tdSql.checkRows(5) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and tgcol4 <> 0 and - # ts < now + 5m + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol4 <> 0 and + # ts < 1605045600000 + 300001 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol4 <> 0 and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol4 <> 0 and ts < 1605045600000 + 300001' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol4 <> 0 and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol4 <> 0 and ts < 1605045600000 + 300001' % (mt)) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') @@ -781,98 +779,98 @@ class TDTestCase: # TSIM: # TSIM: print =============== step12 tdLog.info('=============== step12') - # TSIM: sql select * from $mt where ts > now + 4m and tgcol5 = 1 + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol5 = 1 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol5 = 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol5 = 1' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol5 = 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol5 = 1' % (mt)) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and tgcol5 <> 1 + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol5 <> 1 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol5 <> 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol5 <> 1' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol5 <> 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol5 <> 1' % (mt)) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts < now + 4m and tgcol5 = 0 + # TSIM: sql select * from $mt where ts < 1605045600000 + 240001 and tgcol5 = 0 tdLog.info( - 'select * from %s where ts < now + 4m and tgcol5 = 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol5 = 0' % (mt)) tdSql.query( - 'select * from %s where ts < now + 4m and tgcol5 = 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol5 = 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts < now + 4m and tgcol5 <> 0 + # TSIM: sql select * from $mt where ts < 1605045600000 + 240001 and tgcol5 <> 0 tdLog.info( - 'select * from %s where ts < now + 4m and tgcol5 <> 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol5 <> 0' % (mt)) tdSql.query( - 'select * from %s where ts < now + 4m and tgcol5 <> 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol5 <> 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts <= now + 4m and tgcol5 = 0 + # TSIM: sql select * from $mt where ts <= 1605045600000 + 240001 and tgcol5 = 0 tdLog.info( - 'select * from %s where ts <= now + 4m and tgcol5 = 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol5 = 0' % (mt)) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol5 = 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol5 = 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts <= now + 4m and tgcol5 <> 0 + # TSIM: sql select * from $mt where ts <= 1605045600000 + 240001 and tgcol5 <> 0 tdLog.info( - 'select * from %s where ts <= now + 4m and tgcol5 <> 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol5 <> 0' % (mt)) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol5 <> 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol5 <> 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and ts < now + 5m and + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and # tgcol5 <> 0 tdLog.info( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol5 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol5 <> 0' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol5 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol5 <> 0' % (mt)) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') tdSql.checkRows(5) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and tgcol5 <> 0 and - # ts < now + 5m + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol5 <> 0 and + # ts < 1605045600000 + 300001 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol5 <> 0 and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol5 <> 0 and ts < 1605045600000 + 300001' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol5 <> 0 and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol5 <> 0 and ts < 1605045600000 + 300001' % (mt)) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') @@ -882,104 +880,104 @@ class TDTestCase: # TSIM: # TSIM: print =============== step13 tdLog.info('=============== step13') - # TSIM: sql select * from $mt where ts > now + 4m and tgcol2 = 1 and + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol2 = 1 and # tgcol1 = 1 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol2 = 1 and tgcol1 = 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol2 = 1 and tgcol1 = 1' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol2 = 1 and tgcol1 = 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol2 = 1 and tgcol1 = 1' % (mt)) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and tgcol2 <> 1 and + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol2 <> 1 and # tgcol1 <> 1 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol2 <> 1 and tgcol1 <> 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol2 <> 1 and tgcol1 <> 1' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol2 <> 1 and tgcol1 <> 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol2 <> 1 and tgcol1 <> 1' % (mt)) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts < now + 4m and tgcol2 = 0 and + # TSIM: sql select * from $mt where ts < 1605045600000 + 240001 and tgcol2 = 0 and # tgcol1 = 0 tdLog.info( - 'select * from %s where ts < now + 4m and tgcol2 = 0 and tgcol1 = 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol2 = 0 and tgcol1 = 0' % (mt)) tdSql.query( - 'select * from %s where ts < now + 4m and tgcol2 = 0 and tgcol1 = 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol2 = 0 and tgcol1 = 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts < now + 4m and tgcol2 <> 0 and + # TSIM: sql select * from $mt where ts < 1605045600000 + 240001 and tgcol2 <> 0 and # tgcol1 <> 0 tdLog.info( - 'select * from %s where ts < now + 4m and tgcol2 <> 0 and tgcol1 <> 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol2 <> 0 and tgcol1 <> 0' % (mt)) tdSql.query( - 'select * from %s where ts < now + 4m and tgcol2 <> 0 and tgcol1 <> 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol2 <> 0 and tgcol1 <> 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts <= now + 4m and tgcol2 = 0 and + # TSIM: sql select * from $mt where ts <= 1605045600000 + 240001 and tgcol2 = 0 and # tgcol1 = 0 tdLog.info( - 'select * from %s where ts <= now + 4m and tgcol2 = 0 and tgcol1 = 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol2 = 0 and tgcol1 = 0' % (mt)) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol2 = 0 and tgcol1 = 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol2 = 0 and tgcol1 = 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts <= now + 4m and tgcol2 <> 0 and + # TSIM: sql select * from $mt where ts <= 1605045600000 + 240001 and tgcol2 <> 0 and # tgcol1 <> 0 tdLog.info( - 'select * from %s where ts <= now + 4m and tgcol2 <> 0 and tgcol1 <> 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol2 <> 0 and tgcol1 <> 0' % (mt)) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol2 <> 0 and tgcol1 <> 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol2 <> 0 and tgcol1 <> 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and ts < now + 5m and + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and # tgcol2 <> 0 and tgcol1 <> 0 tdLog.info( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol2 <> 0 and tgcol1 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol2 <> 0 and tgcol1 <> 0' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol2 <> 0 and tgcol1 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol2 <> 0 and tgcol1 <> 0' % (mt)) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') tdSql.checkRows(5) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and tgcol2 <> 0 and - # ts < now + 5m and ts < now + 5m and tgcol1 <> 0 + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol2 <> 0 and + # ts < 1605045600000 + 300001 and ts < 1605045600000 + 300001 and tgcol1 <> 0 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol2 <> 0 and ts < now + 5m and ts < now + 5m and tgcol1 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol2 <> 0 and ts < 1605045600000 + 300001 and ts < 1605045600000 + 300001 and tgcol1 <> 0' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol2 <> 0 and ts < now + 5m and ts < now + 5m and tgcol1 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol2 <> 0 and ts < 1605045600000 + 300001 and ts < 1605045600000 + 300001 and tgcol1 <> 0' % (mt)) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') @@ -989,104 +987,104 @@ class TDTestCase: # TSIM: # TSIM: print =============== step14 tdLog.info('=============== step14') - # TSIM: sql select * from $mt where ts > now + 4m and tgcol3 = 1 and + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol3 = 1 and # tgcol2 = 1 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol3 = 1 and tgcol2 = 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol3 = 1 and tgcol2 = 1' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol3 = 1 and tgcol2 = 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol3 = 1 and tgcol2 = 1' % (mt)) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and tgcol3 <> 1 and + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol3 <> 1 and # tgcol2 <> 1 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol3 <> 1 and tgcol2 <> 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol3 <> 1 and tgcol2 <> 1' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol3 <> 1 and tgcol2 <> 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol3 <> 1 and tgcol2 <> 1' % (mt)) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts < now + 4m and tgcol3 = 0 and + # TSIM: sql select * from $mt where ts < 1605045600000 + 240001 and tgcol3 = 0 and # tgcol2 = 0 tdLog.info( - 'select * from %s where ts < now + 4m and tgcol3 = 0 and tgcol2 = 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol3 = 0 and tgcol2 = 0' % (mt)) tdSql.query( - 'select * from %s where ts < now + 4m and tgcol3 = 0 and tgcol2 = 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol3 = 0 and tgcol2 = 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts < now + 4m and tgcol3 <> 0 and + # TSIM: sql select * from $mt where ts < 1605045600000 + 240001 and tgcol3 <> 0 and # tgcol2 <> 0 tdLog.info( - 'select * from %s where ts < now + 4m and tgcol3 <> 0 and tgcol2 <> 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol3 <> 0 and tgcol2 <> 0' % (mt)) tdSql.query( - 'select * from %s where ts < now + 4m and tgcol3 <> 0 and tgcol2 <> 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol3 <> 0 and tgcol2 <> 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts <= now + 4m and tgcol3 = 0 and + # TSIM: sql select * from $mt where ts <= 1605045600000 + 240001 and tgcol3 = 0 and # tgcol2 = 0 tdLog.info( - 'select * from %s where ts <= now + 4m and tgcol3 = 0 and tgcol2 = 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol3 = 0 and tgcol2 = 0' % (mt)) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol3 = 0 and tgcol2 = 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol3 = 0 and tgcol2 = 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts <= now + 4m and tgcol3 <> 0 and + # TSIM: sql select * from $mt where ts <= 1605045600000 + 240001 and tgcol3 <> 0 and # tgcol2 <> 0 tdLog.info( - 'select * from %s where ts <= now + 4m and tgcol3 <> 0 and tgcol2 <> 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol3 <> 0 and tgcol2 <> 0' % (mt)) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol3 <> 0 and tgcol2 <> 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol3 <> 0 and tgcol2 <> 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and ts < now + 5m and + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and # tgcol3 <> 0 and tgcol2 <> 0 tdLog.info( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol3 <> 0 and tgcol2 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol3 <> 0 and tgcol2 <> 0' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol3 <> 0 and tgcol2 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol3 <> 0 and tgcol2 <> 0' % (mt)) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') tdSql.checkRows(5) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and tgcol3 <> 0 and - # ts < now + 5m and ts < now + 5m and tgcol2 <> 0 + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol3 <> 0 and + # ts < 1605045600000 + 300001 and ts < 1605045600000 + 300001 and tgcol2 <> 0 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol3 <> 0 and ts < now + 5m and ts < now + 5m and tgcol2 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol3 <> 0 and ts < 1605045600000 + 300001 and ts < 1605045600000 + 300001 and tgcol2 <> 0' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol3 <> 0 and ts < now + 5m and ts < now + 5m and tgcol2 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol3 <> 0 and ts < 1605045600000 + 300001 and ts < 1605045600000 + 300001 and tgcol2 <> 0' % (mt)) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') @@ -1096,104 +1094,104 @@ class TDTestCase: # TSIM: # TSIM: print =============== step15 tdLog.info('=============== step15') - # TSIM: sql select * from $mt where ts > now + 4m and tgcol3 = 1 and + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol3 = 1 and # tgcol4 = 1 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol3 = 1 and tgcol4 = 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol3 = 1 and tgcol4 = 1' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol3 = 1 and tgcol4 = 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol3 = 1 and tgcol4 = 1' % (mt)) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and tgcol3 <> 1 and + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol3 <> 1 and # tgcol4 <> 1 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol3 <> 1 and tgcol4 <> 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol3 <> 1 and tgcol4 <> 1' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol3 <> 1 and tgcol4 <> 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol3 <> 1 and tgcol4 <> 1' % (mt)) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts < now + 4m and tgcol3 = 0 and + # TSIM: sql select * from $mt where ts < 1605045600000 + 240001 and tgcol3 = 0 and # tgcol4 = 0 tdLog.info( - 'select * from %s where ts < now + 4m and tgcol3 = 0 and tgcol4 = 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol3 = 0 and tgcol4 = 0' % (mt)) tdSql.query( - 'select * from %s where ts < now + 4m and tgcol3 = 0 and tgcol4 = 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol3 = 0 and tgcol4 = 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts < now + 4m and tgcol3 <> 0 and + # TSIM: sql select * from $mt where ts < 1605045600000 + 240001 and tgcol3 <> 0 and # tgcol4 <> 0 tdLog.info( - 'select * from %s where ts < now + 4m and tgcol3 <> 0 and tgcol4 <> 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol3 <> 0 and tgcol4 <> 0' % (mt)) tdSql.query( - 'select * from %s where ts < now + 4m and tgcol3 <> 0 and tgcol4 <> 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol3 <> 0 and tgcol4 <> 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts <= now + 4m and tgcol3 = 0 and + # TSIM: sql select * from $mt where ts <= 1605045600000 + 240001 and tgcol3 = 0 and # tgcol4 = 0 tdLog.info( - 'select * from %s where ts <= now + 4m and tgcol3 = 0 and tgcol4 = 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol3 = 0 and tgcol4 = 0' % (mt)) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol3 = 0 and tgcol4 = 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol3 = 0 and tgcol4 = 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts <= now + 4m and tgcol3 <> 0 and + # TSIM: sql select * from $mt where ts <= 1605045600000 + 240001 and tgcol3 <> 0 and # tgcol4 <> 0 tdLog.info( - 'select * from %s where ts <= now + 4m and tgcol3 <> 0 and tgcol4 <> 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol3 <> 0 and tgcol4 <> 0' % (mt)) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol3 <> 0 and tgcol4 <> 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol3 <> 0 and tgcol4 <> 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and ts < now + 5m and + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and # tgcol3 <> 0 and tgcol4 <> 0 tdLog.info( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol3 <> 0 and tgcol4 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol3 <> 0 and tgcol4 <> 0' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol3 <> 0 and tgcol4 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol3 <> 0 and tgcol4 <> 0' % (mt)) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') tdSql.checkRows(5) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and tgcol3 <> 0 and - # ts < now + 5m and ts < now + 5m and tgcol4 <> 0 + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol3 <> 0 and + # ts < 1605045600000 + 300001 and ts < 1605045600000 + 300001 and tgcol4 <> 0 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol3 <> 0 and ts < now + 5m and ts < now + 5m and tgcol4 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol3 <> 0 and ts < 1605045600000 + 300001 and ts < 1605045600000 + 300001 and tgcol4 <> 0' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol3 <> 0 and ts < now + 5m and ts < now + 5m and tgcol4 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol3 <> 0 and ts < 1605045600000 + 300001 and ts < 1605045600000 + 300001 and tgcol4 <> 0' % (mt)) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') @@ -1203,104 +1201,104 @@ class TDTestCase: # TSIM: # TSIM: print =============== step16 tdLog.info('=============== step16') - # TSIM: sql select * from $mt where ts > now + 4m and tgcol5 = 1 and + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol5 = 1 and # tgcol4 = 1 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol5 = 1 and tgcol4 = 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol5 = 1 and tgcol4 = 1' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol5 = 1 and tgcol4 = 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol5 = 1 and tgcol4 = 1' % (mt)) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and tgcol5 <> 1 and + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol5 <> 1 and # tgcol4 <> 1 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol5 <> 1 and tgcol4 <> 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol5 <> 1 and tgcol4 <> 1' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol5 <> 1 and tgcol4 <> 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol5 <> 1 and tgcol4 <> 1' % (mt)) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts < now + 4m and tgcol5 = 0 and + # TSIM: sql select * from $mt where ts < 1605045600000 + 240001 and tgcol5 = 0 and # tgcol4 = 0 tdLog.info( - 'select * from %s where ts < now + 4m and tgcol5 = 0 and tgcol4 = 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol5 = 0 and tgcol4 = 0' % (mt)) tdSql.query( - 'select * from %s where ts < now + 4m and tgcol5 = 0 and tgcol4 = 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol5 = 0 and tgcol4 = 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts < now + 4m and tgcol5 <> 0 and + # TSIM: sql select * from $mt where ts < 1605045600000 + 240001 and tgcol5 <> 0 and # tgcol4 <> 0 tdLog.info( - 'select * from %s where ts < now + 4m and tgcol5 <> 0 and tgcol4 <> 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol5 <> 0 and tgcol4 <> 0' % (mt)) tdSql.query( - 'select * from %s where ts < now + 4m and tgcol5 <> 0 and tgcol4 <> 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol5 <> 0 and tgcol4 <> 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts <= now + 4m and tgcol5 = 0 and + # TSIM: sql select * from $mt where ts <= 1605045600000 + 240001 and tgcol5 = 0 and # tgcol4 = 0 tdLog.info( - 'select * from %s where ts <= now + 4m and tgcol5 = 0 and tgcol4 = 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol5 = 0 and tgcol4 = 0' % (mt)) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol5 = 0 and tgcol4 = 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol5 = 0 and tgcol4 = 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts <= now + 4m and tgcol5 <> 0 and + # TSIM: sql select * from $mt where ts <= 1605045600000 + 240001 and tgcol5 <> 0 and # tgcol4 <> 0 tdLog.info( - 'select * from %s where ts <= now + 4m and tgcol5 <> 0 and tgcol4 <> 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol5 <> 0 and tgcol4 <> 0' % (mt)) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol5 <> 0 and tgcol4 <> 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol5 <> 0 and tgcol4 <> 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and ts < now + 5m and + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and # tgcol5 <> 0 and tgcol4 <> 0 tdLog.info( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol5 <> 0 and tgcol4 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol5 <> 0 and tgcol4 <> 0' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol5 <> 0 and tgcol4 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol5 <> 0 and tgcol4 <> 0' % (mt)) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') tdSql.checkRows(5) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and tgcol5 <> 0 and - # ts < now + 5m and ts < now + 5m and tgcol4 <> 0 + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol5 <> 0 and + # ts < 1605045600000 + 300001 and ts < 1605045600000 + 300001 and tgcol4 <> 0 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol5 <> 0 and ts < now + 5m and ts < now + 5m and tgcol4 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol5 <> 0 and ts < 1605045600000 + 300001 and ts < 1605045600000 + 300001 and tgcol4 <> 0' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol5 <> 0 and ts < now + 5m and ts < now + 5m and tgcol4 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol5 <> 0 and ts < 1605045600000 + 300001 and ts < 1605045600000 + 300001 and tgcol4 <> 0' % (mt)) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') @@ -1310,104 +1308,104 @@ class TDTestCase: # TSIM: # TSIM: print =============== step17 tdLog.info('=============== step17') - # TSIM: sql select * from $mt where ts > now + 4m and tgcol1 = 1 and + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol1 = 1 and # tgcol2 = 1 and tgcol3 = 1 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol1 = 1 and tgcol2 = 1 and tgcol3 = 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol1 = 1 and tgcol2 = 1 and tgcol3 = 1' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol1 = 1 and tgcol2 = 1 and tgcol3 = 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol1 = 1 and tgcol2 = 1 and tgcol3 = 1' % (mt)) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and tgcol1 <> 1 and + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol1 <> 1 and # tgcol2 <> 1 and tgcol3 <> 1 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol1 <> 1 and tgcol2 <> 1 and tgcol3 <> 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol1 <> 1 and tgcol2 <> 1 and tgcol3 <> 1' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol1 <> 1 and tgcol2 <> 1 and tgcol3 <> 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol1 <> 1 and tgcol2 <> 1 and tgcol3 <> 1' % (mt)) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts < now + 4m and tgcol1 = 0 and + # TSIM: sql select * from $mt where ts < 1605045600000 + 240001 and tgcol1 = 0 and # tgcol2 = 0 and tgcol3 = 0 tdLog.info( - 'select * from %s where ts < now + 4m and tgcol1 = 0 and tgcol2 = 0 and tgcol3 = 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol1 = 0 and tgcol2 = 0 and tgcol3 = 0' % (mt)) tdSql.query( - 'select * from %s where ts < now + 4m and tgcol1 = 0 and tgcol2 = 0 and tgcol3 = 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol1 = 0 and tgcol2 = 0 and tgcol3 = 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts < now + 4m and tgcol1 <> 0 and + # TSIM: sql select * from $mt where ts < 1605045600000 + 240001 and tgcol1 <> 0 and # tgcol2 <> 0 and tgcol3 <> 0 tdLog.info( - 'select * from %s where ts < now + 4m and tgcol1 <> 0 and tgcol2 <> 0 and tgcol3 <> 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol1 <> 0 and tgcol2 <> 0 and tgcol3 <> 0' % (mt)) tdSql.query( - 'select * from %s where ts < now + 4m and tgcol1 <> 0 and tgcol2 <> 0 and tgcol3 <> 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol1 <> 0 and tgcol2 <> 0 and tgcol3 <> 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts <= now + 4m and tgcol1 = 0 and + # TSIM: sql select * from $mt where ts <= 1605045600000 + 240001 and tgcol1 = 0 and # tgcol2 = 0 and tgcol3 = 0 tdLog.info( - 'select * from %s where ts <= now + 4m and tgcol1 = 0 and tgcol2 = 0 and tgcol3 = 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol1 = 0 and tgcol2 = 0 and tgcol3 = 0' % (mt)) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol1 = 0 and tgcol2 = 0 and tgcol3 = 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol1 = 0 and tgcol2 = 0 and tgcol3 = 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts <= now + 4m and tgcol1 <> 0 and + # TSIM: sql select * from $mt where ts <= 1605045600000 + 240001 and tgcol1 <> 0 and # tgcol2 <> 0 and tgcol3 <> 0 tdLog.info( - 'select * from %s where ts <= now + 4m and tgcol1 <> 0 and tgcol2 <> 0 and tgcol3 <> 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol1 <> 0 and tgcol2 <> 0 and tgcol3 <> 0' % (mt)) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol1 <> 0 and tgcol2 <> 0 and tgcol3 <> 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol1 <> 0 and tgcol2 <> 0 and tgcol3 <> 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and ts < now + 5m and + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and # tgcol1 <> 0 and tgcol2 <> 0 and tgcol3 <> 0 tdLog.info( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol1 <> 0 and tgcol2 <> 0 and tgcol3 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol1 <> 0 and tgcol2 <> 0 and tgcol3 <> 0' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol1 <> 0 and tgcol2 <> 0 and tgcol3 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol1 <> 0 and tgcol2 <> 0 and tgcol3 <> 0' % (mt)) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') tdSql.checkRows(5) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and tgcol1 <> 0 and - # ts < now + 5m and ts < now + 5m and tgcol2 <> 0 and tgcol3 <> 0 + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol1 <> 0 and + # ts < 1605045600000 + 300001 and ts < 1605045600000 + 300001 and tgcol2 <> 0 and tgcol3 <> 0 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol1 <> 0 and ts < now + 5m and ts < now + 5m and tgcol2 <> 0 and tgcol3 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol1 <> 0 and ts < 1605045600000 + 300001 and ts < 1605045600000 + 300001 and tgcol2 <> 0 and tgcol3 <> 0' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol1 <> 0 and ts < now + 5m and ts < now + 5m and tgcol2 <> 0 and tgcol3 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol1 <> 0 and ts < 1605045600000 + 300001 and ts < 1605045600000 + 300001 and tgcol2 <> 0 and tgcol3 <> 0' % (mt)) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') @@ -1417,104 +1415,104 @@ class TDTestCase: # TSIM: # TSIM: print =============== step18 tdLog.info('=============== step18') - # TSIM: sql select * from $mt where ts > now + 4m and tgcol4 = 1 and + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol4 = 1 and # tgcol2 = 1 and tgcol3 = 1 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol4 = 1 and tgcol2 = 1 and tgcol3 = 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol4 = 1 and tgcol2 = 1 and tgcol3 = 1' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol4 = 1 and tgcol2 = 1 and tgcol3 = 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol4 = 1 and tgcol2 = 1 and tgcol3 = 1' % (mt)) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and tgcol4 <> 1 and + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol4 <> 1 and # tgcol2 <> 1 and tgcol3 <> 1 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol4 <> 1 and tgcol2 <> 1 and tgcol3 <> 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol4 <> 1 and tgcol2 <> 1 and tgcol3 <> 1' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol4 <> 1 and tgcol2 <> 1 and tgcol3 <> 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol4 <> 1 and tgcol2 <> 1 and tgcol3 <> 1' % (mt)) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts < now + 4m and tgcol4 = 0 and + # TSIM: sql select * from $mt where ts < 1605045600000 + 240001 and tgcol4 = 0 and # tgcol2 = 0 and tgcol3 = 0 tdLog.info( - 'select * from %s where ts < now + 4m and tgcol4 = 0 and tgcol2 = 0 and tgcol3 = 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol4 = 0 and tgcol2 = 0 and tgcol3 = 0' % (mt)) tdSql.query( - 'select * from %s where ts < now + 4m and tgcol4 = 0 and tgcol2 = 0 and tgcol3 = 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol4 = 0 and tgcol2 = 0 and tgcol3 = 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts < now + 4m and tgcol4 <> 0 and + # TSIM: sql select * from $mt where ts < 1605045600000 + 240001 and tgcol4 <> 0 and # tgcol2 <> 0 and tgcol3 <> 0 tdLog.info( - 'select * from %s where ts < now + 4m and tgcol4 <> 0 and tgcol2 <> 0 and tgcol3 <> 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol4 <> 0 and tgcol2 <> 0 and tgcol3 <> 0' % (mt)) tdSql.query( - 'select * from %s where ts < now + 4m and tgcol4 <> 0 and tgcol2 <> 0 and tgcol3 <> 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol4 <> 0 and tgcol2 <> 0 and tgcol3 <> 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts <= now + 4m and tgcol4 = 0 and + # TSIM: sql select * from $mt where ts <= 1605045600000 + 240001 and tgcol4 = 0 and # tgcol2 = 0 and tgcol3 = 0 tdLog.info( - 'select * from %s where ts <= now + 4m and tgcol4 = 0 and tgcol2 = 0 and tgcol3 = 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol4 = 0 and tgcol2 = 0 and tgcol3 = 0' % (mt)) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol4 = 0 and tgcol2 = 0 and tgcol3 = 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol4 = 0 and tgcol2 = 0 and tgcol3 = 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts <= now + 4m and tgcol4 <> 0 and + # TSIM: sql select * from $mt where ts <= 1605045600000 + 240001 and tgcol4 <> 0 and # tgcol2 <> 0 and tgcol3 <> 0 tdLog.info( - 'select * from %s where ts <= now + 4m and tgcol4 <> 0 and tgcol2 <> 0 and tgcol3 <> 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol4 <> 0 and tgcol2 <> 0 and tgcol3 <> 0' % (mt)) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol4 <> 0 and tgcol2 <> 0 and tgcol3 <> 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol4 <> 0 and tgcol2 <> 0 and tgcol3 <> 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and ts < now + 5m and + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and # tgcol4 <> 0 and tgcol2 <> 0 and tgcol3 <> 0 tdLog.info( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol4 <> 0 and tgcol2 <> 0 and tgcol3 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol4 <> 0 and tgcol2 <> 0 and tgcol3 <> 0' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol4 <> 0 and tgcol2 <> 0 and tgcol3 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol4 <> 0 and tgcol2 <> 0 and tgcol3 <> 0' % (mt)) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') tdSql.checkRows(5) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and tgcol4 <> 0 and - # ts < now + 5m and ts < now + 5m and tgcol2 <> 0 and tgcol3 <> 0 + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol4 <> 0 and + # ts < 1605045600000 + 300001 and ts < 1605045600000 + 300001 and tgcol2 <> 0 and tgcol3 <> 0 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol4 <> 0 and ts < now + 5m and ts < now + 5m and tgcol2 <> 0 and tgcol3 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol4 <> 0 and ts < 1605045600000 + 300001 and ts < 1605045600000 + 300001 and tgcol2 <> 0 and tgcol3 <> 0' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol4 <> 0 and ts < now + 5m and ts < now + 5m and tgcol2 <> 0 and tgcol3 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol4 <> 0 and ts < 1605045600000 + 300001 and ts < 1605045600000 + 300001 and tgcol2 <> 0 and tgcol3 <> 0' % (mt)) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') @@ -1524,105 +1522,105 @@ class TDTestCase: # TSIM: # TSIM: print =============== step19 tdLog.info('=============== step19') - # TSIM: sql select * from $mt where ts > now + 4m and tgcol4 = 1 and + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol4 = 1 and # tgcol2 = 1 and tgcol3 = 1 and tgcol1 = 1 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol4 = 1 and tgcol2 = 1 and tgcol3 = 1 and tgcol1 = 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol4 = 1 and tgcol2 = 1 and tgcol3 = 1 and tgcol1 = 1' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol4 = 1 and tgcol2 = 1 and tgcol3 = 1 and tgcol1 = 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol4 = 1 and tgcol2 = 1 and tgcol3 = 1 and tgcol1 = 1' % (mt)) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and tgcol4 <> 1 and + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol4 <> 1 and # tgcol2 <> 1 and tgcol3 <> 1 and tgcol1 <> 1 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol4 <> 1 and tgcol2 <> 1 and tgcol3 <> 1 and tgcol1 <> 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol4 <> 1 and tgcol2 <> 1 and tgcol3 <> 1 and tgcol1 <> 1' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol4 <> 1 and tgcol2 <> 1 and tgcol3 <> 1 and tgcol1 <> 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol4 <> 1 and tgcol2 <> 1 and tgcol3 <> 1 and tgcol1 <> 1' % (mt)) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts < now + 4m and tgcol4 = 0 and + # TSIM: sql select * from $mt where ts < 1605045600000 + 240001 and tgcol4 = 0 and # tgcol2 = 0 and tgcol3 = 0 and tgcol1 = 0 tdLog.info( - 'select * from %s where ts < now + 4m and tgcol4 = 0 and tgcol2 = 0 and tgcol3 = 0 and tgcol1 = 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol4 = 0 and tgcol2 = 0 and tgcol3 = 0 and tgcol1 = 0' % (mt)) tdSql.query( - 'select * from %s where ts < now + 4m and tgcol4 = 0 and tgcol2 = 0 and tgcol3 = 0 and tgcol1 = 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol4 = 0 and tgcol2 = 0 and tgcol3 = 0 and tgcol1 = 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts < now + 4m and tgcol4 <> 0 and + # TSIM: sql select * from $mt where ts < 1605045600000 + 240001 and tgcol4 <> 0 and # tgcol2 <> 0 and tgcol3 <> 0 and tgcol1 <> 0 tdLog.info( - 'select * from %s where ts < now + 4m and tgcol4 <> 0 and tgcol2 <> 0 and tgcol3 <> 0 and tgcol1 <> 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol4 <> 0 and tgcol2 <> 0 and tgcol3 <> 0 and tgcol1 <> 0' % (mt)) tdSql.query( - 'select * from %s where ts < now + 4m and tgcol4 <> 0 and tgcol2 <> 0 and tgcol3 <> 0 and tgcol1 <> 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol4 <> 0 and tgcol2 <> 0 and tgcol3 <> 0 and tgcol1 <> 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts <= now + 4m and tgcol4 = 0 and + # TSIM: sql select * from $mt where ts <= 1605045600000 + 240001 and tgcol4 = 0 and # tgcol2 = 0 and tgcol3 = 0 and tgcol1 = 0 tdLog.info( - 'select * from %s where ts <= now + 4m and tgcol4 = 0 and tgcol2 = 0 and tgcol3 = 0 and tgcol1 = 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol4 = 0 and tgcol2 = 0 and tgcol3 = 0 and tgcol1 = 0' % (mt)) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol4 = 0 and tgcol2 = 0 and tgcol3 = 0 and tgcol1 = 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol4 = 0 and tgcol2 = 0 and tgcol3 = 0 and tgcol1 = 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts <= now + 4m and tgcol4 <> 0 and + # TSIM: sql select * from $mt where ts <= 1605045600000 + 240001 and tgcol4 <> 0 and # tgcol2 <> 0 and tgcol3 <> 0 and tgcol1 <> 0 tdLog.info( - 'select * from %s where ts <= now + 4m and tgcol4 <> 0 and tgcol2 <> 0 and tgcol3 <> 0 and tgcol1 <> 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol4 <> 0 and tgcol2 <> 0 and tgcol3 <> 0 and tgcol1 <> 0' % (mt)) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol4 <> 0 and tgcol2 <> 0 and tgcol3 <> 0 and tgcol1 <> 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol4 <> 0 and tgcol2 <> 0 and tgcol3 <> 0 and tgcol1 <> 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and ts < now + 5m and + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and # tgcol4 <> 0 and tgcol2 <> 0 and tgcol3 <> 0 and tgcol1 <> 0 tdLog.info( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol4 <> 0 and tgcol2 <> 0 and tgcol3 <> 0 and tgcol1 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol4 <> 0 and tgcol2 <> 0 and tgcol3 <> 0 and tgcol1 <> 0' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol4 <> 0 and tgcol2 <> 0 and tgcol3 <> 0 and tgcol1 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol4 <> 0 and tgcol2 <> 0 and tgcol3 <> 0 and tgcol1 <> 0' % (mt)) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') tdSql.checkRows(5) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and tgcol4 <> 0 and - # ts < now + 5m and ts < now + 5m and tgcol2 <> 0 and tgcol3 <> 0 and + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol4 <> 0 and + # ts < 1605045600000 + 300001 and ts < 1605045600000 + 300001 and tgcol2 <> 0 and tgcol3 <> 0 and # tgcol1 <> 0 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol4 <> 0 and ts < now + 5m and ts < now + 5m and tgcol2 <> 0 and tgcol3 <> 0 and tgcol1 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol4 <> 0 and ts < 1605045600000 + 300001 and ts < 1605045600000 + 300001 and tgcol2 <> 0 and tgcol3 <> 0 and tgcol1 <> 0' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol4 <> 0 and ts < now + 5m and ts < now + 5m and tgcol2 <> 0 and tgcol3 <> 0 and tgcol1 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol4 <> 0 and ts < 1605045600000 + 300001 and ts < 1605045600000 + 300001 and tgcol2 <> 0 and tgcol3 <> 0 and tgcol1 <> 0' % (mt)) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') @@ -1632,106 +1630,106 @@ class TDTestCase: # TSIM: # TSIM: print =============== step20 tdLog.info('=============== step20') - # TSIM: sql select * from $mt where ts > now + 4m and tgcol4 = 1 and + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol4 = 1 and # tgcol2 = 1 and tgcol3 = 1 and tgcol1 = 1 and tgcol5 = 1 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol4 = 1 and tgcol2 = 1 and tgcol3 = 1 and tgcol1 = 1 and tgcol5 = 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol4 = 1 and tgcol2 = 1 and tgcol3 = 1 and tgcol1 = 1 and tgcol5 = 1' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol4 = 1 and tgcol2 = 1 and tgcol3 = 1 and tgcol1 = 1 and tgcol5 = 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol4 = 1 and tgcol2 = 1 and tgcol3 = 1 and tgcol1 = 1 and tgcol5 = 1' % (mt)) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and tgcol4 <> 1 and + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol4 <> 1 and # tgcol2 <> 1 and tgcol3 <> 1 and tgcol1 <> 1 and tgcol5 <> 1 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol4 <> 1 and tgcol2 <> 1 and tgcol3 <> 1 and tgcol1 <> 1 and tgcol5 <> 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol4 <> 1 and tgcol2 <> 1 and tgcol3 <> 1 and tgcol1 <> 1 and tgcol5 <> 1' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol4 <> 1 and tgcol2 <> 1 and tgcol3 <> 1 and tgcol1 <> 1 and tgcol5 <> 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol4 <> 1 and tgcol2 <> 1 and tgcol3 <> 1 and tgcol1 <> 1 and tgcol5 <> 1' % (mt)) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts < now + 4m and tgcol4 = 0 and + # TSIM: sql select * from $mt where ts < 1605045600000 + 240001 and tgcol4 = 0 and # tgcol2 = 0 and tgcol3 = 0 and tgcol1 = 0 and tgcol5 = 0 tdLog.info( - 'select * from %s where ts < now + 4m and tgcol4 = 0 and tgcol2 = 0 and tgcol3 = 0 and tgcol1 = 0 and tgcol5 = 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol4 = 0 and tgcol2 = 0 and tgcol3 = 0 and tgcol1 = 0 and tgcol5 = 0' % (mt)) tdSql.query( - 'select * from %s where ts < now + 4m and tgcol4 = 0 and tgcol2 = 0 and tgcol3 = 0 and tgcol1 = 0 and tgcol5 = 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol4 = 0 and tgcol2 = 0 and tgcol3 = 0 and tgcol1 = 0 and tgcol5 = 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts < now + 4m and tgcol4 <> 0 and + # TSIM: sql select * from $mt where ts < 1605045600000 + 240001 and tgcol4 <> 0 and # tgcol2 <> 0 and tgcol3 <> 0 and tgcol1 <> 0 and tgcol5 <> 0 tdLog.info( - 'select * from %s where ts < now + 4m and tgcol4 <> 0 and tgcol2 <> 0 and tgcol3 <> 0 and tgcol1 <> 0 and tgcol5 <> 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol4 <> 0 and tgcol2 <> 0 and tgcol3 <> 0 and tgcol1 <> 0 and tgcol5 <> 0' % (mt)) tdSql.query( - 'select * from %s where ts < now + 4m and tgcol4 <> 0 and tgcol2 <> 0 and tgcol3 <> 0 and tgcol1 <> 0 and tgcol5 <> 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol4 <> 0 and tgcol2 <> 0 and tgcol3 <> 0 and tgcol1 <> 0 and tgcol5 <> 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts <= now + 4m and tgcol4 = 0 and + # TSIM: sql select * from $mt where ts <= 1605045600000 + 240001 and tgcol4 = 0 and # tgcol2 = 0 and tgcol3 = 0 and tgcol1 = 0 and tgcol5 = 0 tdLog.info( - 'select * from %s where ts <= now + 4m and tgcol4 = 0 and tgcol2 = 0 and tgcol3 = 0 and tgcol1 = 0 and tgcol5 = 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol4 = 0 and tgcol2 = 0 and tgcol3 = 0 and tgcol1 = 0 and tgcol5 = 0' % (mt)) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol4 = 0 and tgcol2 = 0 and tgcol3 = 0 and tgcol1 = 0 and tgcol5 = 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol4 = 0 and tgcol2 = 0 and tgcol3 = 0 and tgcol1 = 0 and tgcol5 = 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts <= now + 4m and tgcol4 <> 0 and + # TSIM: sql select * from $mt where ts <= 1605045600000 + 240001 and tgcol4 <> 0 and # tgcol2 <> 0 and tgcol3 <> 0 and tgcol1 <> 0 and tgcol5 <> 0 tdLog.info( - 'select * from %s where ts <= now + 4m and tgcol4 <> 0 and tgcol2 <> 0 and tgcol3 <> 0 and tgcol1 <> 0 and tgcol5 <> 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol4 <> 0 and tgcol2 <> 0 and tgcol3 <> 0 and tgcol1 <> 0 and tgcol5 <> 0' % (mt)) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol4 <> 0 and tgcol2 <> 0 and tgcol3 <> 0 and tgcol1 <> 0 and tgcol5 <> 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol4 <> 0 and tgcol2 <> 0 and tgcol3 <> 0 and tgcol1 <> 0 and tgcol5 <> 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and ts < now + 5m and + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and # tgcol4 <> 0 and tgcol2 <> 0 and tgcol3 <> 0 and tgcol1 <> 0 and # tgcol5 <> 0 tdLog.info( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol4 <> 0 and tgcol2 <> 0 and tgcol3 <> 0 and tgcol1 <> 0 and tgcol5 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol4 <> 0 and tgcol2 <> 0 and tgcol3 <> 0 and tgcol1 <> 0 and tgcol5 <> 0' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol4 <> 0 and tgcol2 <> 0 and tgcol3 <> 0 and tgcol1 <> 0 and tgcol5 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol4 <> 0 and tgcol2 <> 0 and tgcol3 <> 0 and tgcol1 <> 0 and tgcol5 <> 0' % (mt)) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') tdSql.checkRows(5) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and tgcol4 <> 0 and - # ts < now + 5m and ts < now + 5m and tgcol2 <> 0 and tgcol3 <> 0 and + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol4 <> 0 and + # ts < 1605045600000 + 300001 and ts < 1605045600000 + 300001 and tgcol2 <> 0 and tgcol3 <> 0 and # tgcol1 <> 0 and tgcol5 <> 0 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol4 <> 0 and ts < now + 5m and ts < now + 5m and tgcol2 <> 0 and tgcol3 <> 0 and tgcol1 <> 0 and tgcol5 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol4 <> 0 and ts < 1605045600000 + 300001 and ts < 1605045600000 + 300001 and tgcol2 <> 0 and tgcol3 <> 0 and tgcol1 <> 0 and tgcol5 <> 0' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol4 <> 0 and ts < now + 5m and ts < now + 5m and tgcol2 <> 0 and tgcol3 <> 0 and tgcol1 <> 0 and tgcol5 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol4 <> 0 and ts < 1605045600000 + 300001 and ts < 1605045600000 + 300001 and tgcol2 <> 0 and tgcol3 <> 0 and tgcol1 <> 0 and tgcol5 <> 0' % (mt)) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') @@ -1844,12 +1842,12 @@ class TDTestCase: # TSIM: print =============== step23 tdLog.info('=============== step23') # TSIM: sql select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), - # max(tbcol), first(tbcol), last(tbcol) from $mt where ts < now + 4m + # max(tbcol), first(tbcol), last(tbcol) from $mt where ts < 1605045600000 + 240001 tdLog.info( - 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m' % + 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001' % (mt)) tdSql.query( - 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m' % + 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001' % (mt)) # TSIM: print $data00 $data01 $data02 $data03 $data04 $data05 $data06 tdLog.info('$data00 $data01 $data02 $data03 $data04 $data05 $data06') @@ -1860,13 +1858,13 @@ class TDTestCase: # TSIM: endi # TSIM: # TSIM: sql select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), - # max(tbcol), first(tbcol), last(tbcol) from $mt where ts < now + 4m + # max(tbcol), first(tbcol), last(tbcol) from $mt where ts < 1605045600000 + 240001 # and tgcol1 = 1 tdLog.info( - 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m and tgcol1 = 1' % + 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001 and tgcol1 = 1' % (mt)) tdSql.query( - 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m and tgcol1 = 1' % + 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001 and tgcol1 = 1' % (mt)) # TSIM: print $data00 $data01 $data02 $data03 $data04 $data05 $data06 tdLog.info('$data00 $data01 $data02 $data03 $data04 $data05 $data06') @@ -1877,13 +1875,13 @@ class TDTestCase: # TSIM: endi # TSIM: # TSIM: sql select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), - # max(tbcol), first(tbcol), last(tbcol) from $mt where ts < now + 4m + # max(tbcol), first(tbcol), last(tbcol) from $mt where ts < 1605045600000 + 240001 # and tgcol1 = 1 and tgcol2 = 1 tdLog.info( - 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m and tgcol1 = 1 and tgcol2 = 1' % + 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001 and tgcol1 = 1 and tgcol2 = 1' % (mt)) tdSql.query( - 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m and tgcol1 = 1 and tgcol2 = 1' % + 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001 and tgcol1 = 1 and tgcol2 = 1' % (mt)) # TSIM: print $data00 $data01 $data02 $data03 $data04 $data05 $data06 tdLog.info('$data00 $data01 $data02 $data03 $data04 $data05 $data06') @@ -1894,13 +1892,13 @@ class TDTestCase: # TSIM: endi # TSIM: # TSIM: sql select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), - # max(tbcol), first(tbcol), last(tbcol) from $mt where ts < now + 4m + # max(tbcol), first(tbcol), last(tbcol) from $mt where ts < 1605045600000 + 240001 # and tgcol1 = 1 and tgcol2 = 1 and tgcol3 = 1 tdLog.info( - 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m and tgcol1 = 1 and tgcol2 = 1 and tgcol3 = 1' % + 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001 and tgcol1 = 1 and tgcol2 = 1 and tgcol3 = 1' % (mt)) tdSql.query( - 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m and tgcol1 = 1 and tgcol2 = 1 and tgcol3 = 1' % + 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001 and tgcol1 = 1 and tgcol2 = 1 and tgcol3 = 1' % (mt)) # TSIM: print $data00 $data01 $data02 $data03 $data04 $data05 $data06 tdLog.info('$data00 $data01 $data02 $data03 $data04 $data05 $data06') @@ -1911,11 +1909,11 @@ class TDTestCase: # TSIM: endi # TSIM: # TSIM: sql select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), - # max(tbcol), first(tbcol), last(tbcol) from $mt where ts < now + 4m + # max(tbcol), first(tbcol), last(tbcol) from $mt where ts < 1605045600000 + 240001 # and tgcol1 = 1 and tgcol2 = 1 and tgcol3 = 1 and tgcol4 = 1 - tdLog.info('select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m and tgcol1 = 1 and tgcol2 = 1 and tgcol3 = 1 and tgcol4 = 1' % (mt)) + tdLog.info('select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001 and tgcol1 = 1 and tgcol2 = 1 and tgcol3 = 1 and tgcol4 = 1' % (mt)) tdSql.query( - 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m and tgcol1 = 1 and tgcol2 = 1 and tgcol3 = 1 and tgcol4 = 1' % + 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001 and tgcol1 = 1 and tgcol2 = 1 and tgcol3 = 1 and tgcol4 = 1' % (mt)) # TSIM: print $data00 $data01 $data02 $data03 $data04 $data05 $data06 tdLog.info('$data00 $data01 $data02 $data03 $data04 $data05 $data06') @@ -1926,11 +1924,11 @@ class TDTestCase: # TSIM: endi # TSIM: # TSIM: sql select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), - # max(tbcol), first(tbcol), last(tbcol) from $mt where ts < now + 4m + # max(tbcol), first(tbcol), last(tbcol) from $mt where ts < 1605045600000 + 240001 # and tgcol1 = 1 and tgcol2 = 1 and tgcol3 = 1 and tgcol4 = 1 and # tgcol5 = 1 - tdLog.info('select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m and tgcol1 = 1 and tgcol2 = 1 and tgcol3 = 1 and tgcol4 = 1 and tgcol5 = 1' % (mt)) - tdSql.query('select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m and tgcol1 = 1 and tgcol2 = 1 and tgcol3 = 1 and tgcol4 = 1 and tgcol5 = 1' % (mt)) + tdLog.info('select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001 and tgcol1 = 1 and tgcol2 = 1 and tgcol3 = 1 and tgcol4 = 1 and tgcol5 = 1' % (mt)) + tdSql.query('select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001 and tgcol1 = 1 and tgcol2 = 1 and tgcol3 = 1 and tgcol4 = 1 and tgcol5 = 1' % (mt)) # TSIM: print $data00 $data01 $data02 $data03 $data04 $data05 $data06 tdLog.info('$data00 $data01 $data02 $data03 $data04 $data05 $data06') # TSIM: if $data00 != 25 then @@ -2106,13 +2104,13 @@ class TDTestCase: # TSIM: print =============== step26 tdLog.info('=============== step26') # TSIM: sql select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), - # max(tbcol), first(tbcol), last(tbcol) from $mt where ts < now + 4m + # max(tbcol), first(tbcol), last(tbcol) from $mt where ts < 1605045600000 + 240001 # group by tgcol2 tdLog.info( - 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m group by tgcol2' % + 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001 group by tgcol2' % (mt)) tdSql.query( - 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m group by tgcol2' % + 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001 group by tgcol2' % (mt)) # TSIM: print $data00 $data01 $data02 $data03 $data04 $data05 $data06 tdLog.info('$data00 $data01 $data02 $data03 $data04 $data05 $data06') @@ -2123,13 +2121,13 @@ class TDTestCase: # TSIM: endi # TSIM: # TSIM: sql select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), - # max(tbcol), first(tbcol), last(tbcol) from $mt where ts < now + 4m + # max(tbcol), first(tbcol), last(tbcol) from $mt where ts < 1605045600000 + 240001 # and tgcol1 = 1 group by tgcol2 tdLog.info( - 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m and tgcol1 = 1 group by tgcol2' % + 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001 and tgcol1 = 1 group by tgcol2' % (mt)) tdSql.query( - 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m and tgcol1 = 1 group by tgcol2' % + 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001 and tgcol1 = 1 group by tgcol2' % (mt)) # TSIM: print $data00 $data01 $data02 $data03 $data04 $data05 $data06 tdLog.info('$data00 $data01 $data02 $data03 $data04 $data05 $data06') @@ -2140,13 +2138,13 @@ class TDTestCase: # TSIM: endi # TSIM: # TSIM: sql select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), - # max(tbcol), first(tbcol), last(tbcol) from $mt where ts < now + 4m + # max(tbcol), first(tbcol), last(tbcol) from $mt where ts < 1605045600000 + 240001 # and tgcol1 = 1 and tgcol2 = 1 group by tgcol2 tdLog.info( - 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m and tgcol1 = 1 and tgcol2 = 1 group by tgcol2' % + 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001 and tgcol1 = 1 and tgcol2 = 1 group by tgcol2' % (mt)) tdSql.query( - 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m and tgcol1 = 1 and tgcol2 = 1 group by tgcol2' % + 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001 and tgcol1 = 1 and tgcol2 = 1 group by tgcol2' % (mt)) # TSIM: print $data00 $data01 $data02 $data03 $data04 $data05 $data06 tdLog.info('$data00 $data01 $data02 $data03 $data04 $data05 $data06') @@ -2157,11 +2155,11 @@ class TDTestCase: # TSIM: endi # TSIM: # TSIM: sql select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), - # max(tbcol), first(tbcol), last(tbcol) from $mt where ts < now + 4m + # max(tbcol), first(tbcol), last(tbcol) from $mt where ts < 1605045600000 + 240001 # and tgcol1 = 1 and tgcol2 = 1 and tgcol3 = 1 group by tgcol2 - tdLog.info('select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m and tgcol1 = 1 and tgcol2 = 1 and tgcol3 = 1 group by tgcol2' % (mt)) + tdLog.info('select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001 and tgcol1 = 1 and tgcol2 = 1 and tgcol3 = 1 group by tgcol2' % (mt)) tdSql.query( - 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m and tgcol1 = 1 and tgcol2 = 1 and tgcol3 = 1 group by tgcol2' % + 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001 and tgcol1 = 1 and tgcol2 = 1 and tgcol3 = 1 group by tgcol2' % (mt)) # TSIM: print $data00 $data01 $data02 $data03 $data04 $data05 $data06 tdLog.info('$data00 $data01 $data02 $data03 $data04 $data05 $data06') @@ -2172,11 +2170,11 @@ class TDTestCase: # TSIM: endi # TSIM: # TSIM: sql select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), - # max(tbcol), first(tbcol), last(tbcol) from $mt where ts < now + 4m + # max(tbcol), first(tbcol), last(tbcol) from $mt where ts < 1605045600000 + 240001 # and tgcol1 = 1 and tgcol2 = 1 and tgcol3 = 1 and tgcol4 = 1 group by # tgcol2 - tdLog.info('select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m and tgcol1 = 1 and tgcol2 = 1 and tgcol3 = 1 and tgcol4 = 1 group by tgcol2' % (mt)) - tdSql.query('select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m and tgcol1 = 1 and tgcol2 = 1 and tgcol3 = 1 and tgcol4 = 1 group by tgcol2' % (mt)) + tdLog.info('select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001 and tgcol1 = 1 and tgcol2 = 1 and tgcol3 = 1 and tgcol4 = 1 group by tgcol2' % (mt)) + tdSql.query('select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001 and tgcol1 = 1 and tgcol2 = 1 and tgcol3 = 1 and tgcol4 = 1 group by tgcol2' % (mt)) # TSIM: print $data00 $data01 $data02 $data03 $data04 $data05 $data06 tdLog.info('$data00 $data01 $data02 $data03 $data04 $data05 $data06') # TSIM: if $data00 != 25 then @@ -2186,11 +2184,11 @@ class TDTestCase: # TSIM: endi # TSIM: # TSIM: sql select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), - # max(tbcol), first(tbcol), last(tbcol) from $mt where ts < now + 4m + # max(tbcol), first(tbcol), last(tbcol) from $mt where ts < 1605045600000 + 240001 # and tgcol1 = 1 and tgcol2 = 1 and tgcol3 = 1 and tgcol4 = 1 and # tgcol5 = 1 group by tgcol2 - tdLog.info('select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m and tgcol1 = 1 and tgcol2 = 1 and tgcol3 = 1 and tgcol4 = 1 and tgcol5 = 1 group by tgcol2' % (mt)) - tdSql.query('select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m and tgcol1 = 1 and tgcol2 = 1 and tgcol3 = 1 and tgcol4 = 1 and tgcol5 = 1 group by tgcol2' % (mt)) + tdLog.info('select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001 and tgcol1 = 1 and tgcol2 = 1 and tgcol3 = 1 and tgcol4 = 1 and tgcol5 = 1 group by tgcol2' % (mt)) + tdSql.query('select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001 and tgcol1 = 1 and tgcol2 = 1 and tgcol3 = 1 and tgcol4 = 1 and tgcol5 = 1 group by tgcol2' % (mt)) # TSIM: print $data00 $data01 $data02 $data03 $data04 $data05 $data06 tdLog.info('$data00 $data01 $data02 $data03 $data04 $data05 $data06') # TSIM: if $data00 != 25 then diff --git a/tests/pytest/tag_lite/6.py b/tests/pytest/tag_lite/6.py index b789e41794449e4ec97d03423bfcd03703f7604b..5cf43f10475181202eaa901d0a7ef1d1d23e86e0 100644 --- a/tests/pytest/tag_lite/6.py +++ b/tests/pytest/tag_lite/6.py @@ -79,14 +79,13 @@ class TDTestCase: # TSIM: while $x < $rowNum while (x < rowNum): # TSIM: $ms = $x . m - ms = "%dm" % x - # TSIM: sql insert into $tb values (now + $ms , $x ) + ms = x * 60000 tdLog.info( - 'insert into %s values (now + %s , %d )' % - (tb, ms, x)) + "insert into %s values (%d, %d)" % + (tb, 1605045600000 + ms, x)) tdSql.execute( - 'insert into %s values (now + %s , %d )' % - (tb, ms, x)) + "insert into %s values (%d, %d)" % + (tb, 1605045600000 + ms, x)) # TSIM: $x = $x + 1 x = x + 1 # TSIM: endw @@ -110,14 +109,13 @@ class TDTestCase: # TSIM: while $x < $rowNum while (x < rowNum): # TSIM: $ms = $x . m - ms = "%dm" % x - # TSIM: sql insert into $tb values (now + $ms , $x ) + ms = x * 60000 tdLog.info( - 'insert into %s values (now + %s , %d )' % - (tb, ms, x)) + "insert into %s values (%d, %d)" % + (tb, 1605045600000 + ms, x)) tdSql.execute( - 'insert into %s values (now + %s , %d )' % - (tb, ms, x)) + "insert into %s values (%d, %d)" % + (tb, 1605045600000 + ms, x)) # TSIM: $x = $x + 1 x = x + 1 # TSIM: endw @@ -136,36 +134,36 @@ class TDTestCase: # TSIM: return -1 # TSIM: endi # TSIM: - # TSIM: sql select * from $mt where ts < now + 4m - tdLog.info('select * from %s where ts < now + 4m' % (mt)) - tdSql.query('select * from %s where ts < now + 4m' % (mt)) + # TSIM: sql select * from $mt where ts < 1605045600000 + 240001 + tdLog.info('select * from %s where ts < 1605045600000 + 240001' % (mt)) + tdSql.query('select * from %s where ts < 1605045600000 + 240001' % (mt)) # TSIM: if $rows != 50 then tdLog.info('tdSql.checkRow(50)') tdSql.checkRows(50) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m - tdLog.info('select * from %s where ts > now + 4m' % (mt)) - tdSql.query('select * from %s where ts > now + 4m' % (mt)) + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 + tdLog.info('select * from %s where ts > 1605045600000 + 240001' % (mt)) + tdSql.query('select * from %s where ts > 1605045600000 + 240001' % (mt)) # TSIM: if $rows != 150 then tdLog.info('tdSql.checkRow(150)') tdSql.checkRows(150) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts = now + 4m - tdLog.info('select * from %s where ts = now + 4m' % (mt)) - tdSql.query('select * from %s where ts = now + 4m' % (mt)) + # TSIM: sql select * from $mt where ts = 1605045600000 + 240001 + tdLog.info('select * from %s where ts = 1605045600000 + 240001' % (mt)) + tdSql.query('select * from %s where ts = 1605045600000 + 240001' % (mt)) # TSIM: if $rows != 0 then tdLog.info('tdSql.checkRow(0)') tdSql.checkRows(0) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and ts < now + 5m + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 tdLog.info( - 'select * from %s where ts > now + 4m and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001' % (mt)) # TSIM: if $rows != 10 then tdLog.info('tdSql.checkRow(10)') @@ -417,98 +415,98 @@ class TDTestCase: # TSIM: # TSIM: print =============== step9 tdLog.info('=============== step9') - # TSIM: sql select * from $mt where ts > now + 4m and tgcol1 = 1 + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol1 = 1 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol1 = 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol1 = 1' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol1 = 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol1 = 1' % (mt)) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and tgcol1 <> 1 + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol1 <> 1 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol1 <> 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol1 <> 1' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol1 <> 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol1 <> 1' % (mt)) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts < now + 4m and tgcol1 = 0 + # TSIM: sql select * from $mt where ts < 1605045600000 + 240001 and tgcol1 = 0 tdLog.info( - 'select * from %s where ts < now + 4m and tgcol1 = 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol1 = 0' % (mt)) tdSql.query( - 'select * from %s where ts < now + 4m and tgcol1 = 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol1 = 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts < now + 4m and tgcol1 <> 0 + # TSIM: sql select * from $mt where ts < 1605045600000 + 240001 and tgcol1 <> 0 tdLog.info( - 'select * from %s where ts < now + 4m and tgcol1 <> 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol1 <> 0' % (mt)) tdSql.query( - 'select * from %s where ts < now + 4m and tgcol1 <> 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol1 <> 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts <= now + 4m and tgcol1 = 0 + # TSIM: sql select * from $mt where ts <= 1605045600000 + 240001 and tgcol1 = 0 tdLog.info( - 'select * from %s where ts <= now + 4m and tgcol1 = 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol1 = 0' % (mt)) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol1 = 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol1 = 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts <= now + 4m and tgcol1 <> 0 + # TSIM: sql select * from $mt where ts <= 1605045600000 + 240001 and tgcol1 <> 0 tdLog.info( - 'select * from %s where ts <= now + 4m and tgcol1 <> 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol1 <> 0' % (mt)) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol1 <> 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol1 <> 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and ts < now + 5m and + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and # tgcol1 <> 0 tdLog.info( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol1 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol1 <> 0' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol1 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol1 <> 0' % (mt)) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') tdSql.checkRows(5) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and tgcol1 <> 0 and - # ts < now + 5m + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol1 <> 0 and + # ts < 1605045600000 + 300001 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol1 <> 0 and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol1 <> 0 and ts < 1605045600000 + 300001' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol1 <> 0 and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol1 <> 0 and ts < 1605045600000 + 300001' % (mt)) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') @@ -518,98 +516,98 @@ class TDTestCase: # TSIM: # TSIM: print =============== step10 tdLog.info('=============== step10') - # TSIM: sql select * from $mt where ts > now + 4m and tgcol2 = 1 + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol2 = 1 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol2 = 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol2 = 1' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol2 = 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol2 = 1' % (mt)) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and tgcol2 <> 1 + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol2 <> 1 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol2 <> 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol2 <> 1' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol2 <> 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol2 <> 1' % (mt)) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts < now + 4m and tgcol2 = 0 + # TSIM: sql select * from $mt where ts < 1605045600000 + 240001 and tgcol2 = 0 tdLog.info( - 'select * from %s where ts < now + 4m and tgcol2 = 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol2 = 0' % (mt)) tdSql.query( - 'select * from %s where ts < now + 4m and tgcol2 = 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol2 = 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts < now + 4m and tgcol2 <> 0 + # TSIM: sql select * from $mt where ts < 1605045600000 + 240001 and tgcol2 <> 0 tdLog.info( - 'select * from %s where ts < now + 4m and tgcol2 <> 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol2 <> 0' % (mt)) tdSql.query( - 'select * from %s where ts < now + 4m and tgcol2 <> 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol2 <> 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts <= now + 4m and tgcol2 = 0 + # TSIM: sql select * from $mt where ts <= 1605045600000 + 240001 and tgcol2 = 0 tdLog.info( - 'select * from %s where ts <= now + 4m and tgcol2 = 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol2 = 0' % (mt)) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol2 = 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol2 = 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts <= now + 4m and tgcol2 <> 0 + # TSIM: sql select * from $mt where ts <= 1605045600000 + 240001 and tgcol2 <> 0 tdLog.info( - 'select * from %s where ts <= now + 4m and tgcol2 <> 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol2 <> 0' % (mt)) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol2 <> 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol2 <> 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and ts < now + 5m and + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and # tgcol2 <> 0 tdLog.info( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol2 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol2 <> 0' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol2 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol2 <> 0' % (mt)) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') tdSql.checkRows(5) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and tgcol2 <> 0 and - # ts < now + 5m + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol2 <> 0 and + # ts < 1605045600000 + 300001 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol2 <> 0 and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol2 <> 0 and ts < 1605045600000 + 300001' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol2 <> 0 and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol2 <> 0 and ts < 1605045600000 + 300001' % (mt)) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') @@ -619,98 +617,98 @@ class TDTestCase: # TSIM: # TSIM: print =============== step11 tdLog.info('=============== step11') - # TSIM: sql select * from $mt where ts > now + 4m and tgcol3 = 1 + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol3 = 1 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol3 = 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol3 = 1' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol3 = 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol3 = 1' % (mt)) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and tgcol3 <> 1 + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol3 <> 1 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol3 <> 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol3 <> 1' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol3 <> 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol3 <> 1' % (mt)) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts < now + 4m and tgcol3 = 0 + # TSIM: sql select * from $mt where ts < 1605045600000 + 240001 and tgcol3 = 0 tdLog.info( - 'select * from %s where ts < now + 4m and tgcol3 = 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol3 = 0' % (mt)) tdSql.query( - 'select * from %s where ts < now + 4m and tgcol3 = 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol3 = 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts < now + 4m and tgcol3 <> 0 + # TSIM: sql select * from $mt where ts < 1605045600000 + 240001 and tgcol3 <> 0 tdLog.info( - 'select * from %s where ts < now + 4m and tgcol3 <> 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol3 <> 0' % (mt)) tdSql.query( - 'select * from %s where ts < now + 4m and tgcol3 <> 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol3 <> 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts <= now + 4m and tgcol3 = 0 + # TSIM: sql select * from $mt where ts <= 1605045600000 + 240001 and tgcol3 = 0 tdLog.info( - 'select * from %s where ts <= now + 4m and tgcol3 = 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol3 = 0' % (mt)) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol3 = 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol3 = 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts <= now + 4m and tgcol3 <> 0 + # TSIM: sql select * from $mt where ts <= 1605045600000 + 240001 and tgcol3 <> 0 tdLog.info( - 'select * from %s where ts <= now + 4m and tgcol3 <> 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol3 <> 0' % (mt)) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol3 <> 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol3 <> 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and ts < now + 5m and + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and # tgcol3 <> 0 tdLog.info( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol3 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol3 <> 0' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol3 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol3 <> 0' % (mt)) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') tdSql.checkRows(5) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and tgcol3 <> 0 and - # ts < now + 5m + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol3 <> 0 and + # ts < 1605045600000 + 300001 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol3 <> 0 and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol3 <> 0 and ts < 1605045600000 + 300001' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol3 <> 0 and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol3 <> 0 and ts < 1605045600000 + 300001' % (mt)) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') @@ -720,98 +718,98 @@ class TDTestCase: # TSIM: # TSIM: print =============== step12 tdLog.info('=============== step12') - # TSIM: sql select * from $mt where ts > now + 4m and tgcol4 = 1 + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol4 = 1 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol4 = 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol4 = 1' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol4 = 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol4 = 1' % (mt)) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and tgcol4 <> 1 + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol4 <> 1 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol4 <> 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol4 <> 1' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol4 <> 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol4 <> 1' % (mt)) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts < now + 4m and tgcol4 = 0 + # TSIM: sql select * from $mt where ts < 1605045600000 + 240001 and tgcol4 = 0 tdLog.info( - 'select * from %s where ts < now + 4m and tgcol4 = 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol4 = 0' % (mt)) tdSql.query( - 'select * from %s where ts < now + 4m and tgcol4 = 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol4 = 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts < now + 4m and tgcol4 <> 0 + # TSIM: sql select * from $mt where ts < 1605045600000 + 240001 and tgcol4 <> 0 tdLog.info( - 'select * from %s where ts < now + 4m and tgcol4 <> 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol4 <> 0' % (mt)) tdSql.query( - 'select * from %s where ts < now + 4m and tgcol4 <> 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol4 <> 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts <= now + 4m and tgcol4 = 0 + # TSIM: sql select * from $mt where ts <= 1605045600000 + 240001 and tgcol4 = 0 tdLog.info( - 'select * from %s where ts <= now + 4m and tgcol4 = 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol4 = 0' % (mt)) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol4 = 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol4 = 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts <= now + 4m and tgcol4 <> 0 + # TSIM: sql select * from $mt where ts <= 1605045600000 + 240001 and tgcol4 <> 0 tdLog.info( - 'select * from %s where ts <= now + 4m and tgcol4 <> 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol4 <> 0' % (mt)) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol4 <> 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol4 <> 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and ts < now + 5m and + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and # tgcol4 <> 0 tdLog.info( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol4 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol4 <> 0' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol4 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol4 <> 0' % (mt)) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') tdSql.checkRows(5) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and tgcol4 <> 0 and - # ts < now + 5m + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol4 <> 0 and + # ts < 1605045600000 + 300001 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol4 <> 0 and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol4 <> 0 and ts < 1605045600000 + 300001' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol4 <> 0 and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol4 <> 0 and ts < 1605045600000 + 300001' % (mt)) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') @@ -821,98 +819,98 @@ class TDTestCase: # TSIM: # TSIM: print =============== step13 tdLog.info('=============== step13') - # TSIM: sql select * from $mt where ts > now + 4m and tgcol5 = 1 + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol5 = 1 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol5 = 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol5 = 1' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol5 = 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol5 = 1' % (mt)) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and tgcol5 <> 1 + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol5 <> 1 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol5 <> 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol5 <> 1' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol5 <> 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol5 <> 1' % (mt)) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts < now + 4m and tgcol5 = 0 + # TSIM: sql select * from $mt where ts < 1605045600000 + 240001 and tgcol5 = 0 tdLog.info( - 'select * from %s where ts < now + 4m and tgcol5 = 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol5 = 0' % (mt)) tdSql.query( - 'select * from %s where ts < now + 4m and tgcol5 = 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol5 = 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts < now + 4m and tgcol5 <> 0 + # TSIM: sql select * from $mt where ts < 1605045600000 + 240001 and tgcol5 <> 0 tdLog.info( - 'select * from %s where ts < now + 4m and tgcol5 <> 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol5 <> 0' % (mt)) tdSql.query( - 'select * from %s where ts < now + 4m and tgcol5 <> 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol5 <> 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts <= now + 4m and tgcol5 = 0 + # TSIM: sql select * from $mt where ts <= 1605045600000 + 240001 and tgcol5 = 0 tdLog.info( - 'select * from %s where ts <= now + 4m and tgcol5 = 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol5 = 0' % (mt)) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol5 = 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol5 = 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts <= now + 4m and tgcol5 <> 0 + # TSIM: sql select * from $mt where ts <= 1605045600000 + 240001 and tgcol5 <> 0 tdLog.info( - 'select * from %s where ts <= now + 4m and tgcol5 <> 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol5 <> 0' % (mt)) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol5 <> 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol5 <> 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and ts < now + 5m and + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and # tgcol5 <> 0 tdLog.info( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol5 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol5 <> 0' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol5 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol5 <> 0' % (mt)) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') tdSql.checkRows(5) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and tgcol5 <> 0 and - # ts < now + 5m + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol5 <> 0 and + # ts < 1605045600000 + 300001 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol5 <> 0 and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol5 <> 0 and ts < 1605045600000 + 300001' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol5 <> 0 and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol5 <> 0 and ts < 1605045600000 + 300001' % (mt)) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') @@ -922,98 +920,98 @@ class TDTestCase: # TSIM: # TSIM: print =============== step14 tdLog.info('=============== step14') - # TSIM: sql select * from $mt where ts > now + 4m and tgcol6 = 1 + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol6 = 1 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol6 = 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol6 = 1' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol6 = 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol6 = 1' % (mt)) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and tgcol6 <> 1 + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol6 <> 1 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol6 <> 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol6 <> 1' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol6 <> 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol6 <> 1' % (mt)) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts < now + 4m and tgcol6 = 0 + # TSIM: sql select * from $mt where ts < 1605045600000 + 240001 and tgcol6 = 0 tdLog.info( - 'select * from %s where ts < now + 4m and tgcol6 = 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol6 = 0' % (mt)) tdSql.query( - 'select * from %s where ts < now + 4m and tgcol6 = 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol6 = 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts < now + 4m and tgcol6 <> 0 + # TSIM: sql select * from $mt where ts < 1605045600000 + 240001 and tgcol6 <> 0 tdLog.info( - 'select * from %s where ts < now + 4m and tgcol6 <> 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol6 <> 0' % (mt)) tdSql.query( - 'select * from %s where ts < now + 4m and tgcol6 <> 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol6 <> 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts <= now + 4m and tgcol6 = 0 + # TSIM: sql select * from $mt where ts <= 1605045600000 + 240001 and tgcol6 = 0 tdLog.info( - 'select * from %s where ts <= now + 4m and tgcol6 = 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol6 = 0' % (mt)) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol6 = 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol6 = 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts <= now + 4m and tgcol6 <> 0 + # TSIM: sql select * from $mt where ts <= 1605045600000 + 240001 and tgcol6 <> 0 tdLog.info( - 'select * from %s where ts <= now + 4m and tgcol6 <> 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol6 <> 0' % (mt)) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol6 <> 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol6 <> 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and ts < now + 5m and + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and # tgcol6 <> 0 tdLog.info( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol6 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol6 <> 0' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol6 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol6 <> 0' % (mt)) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') tdSql.checkRows(5) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and tgcol6 <> 0 and - # ts < now + 5m + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol6 <> 0 and + # ts < 1605045600000 + 300001 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol6 <> 0 and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol6 <> 0 and ts < 1605045600000 + 300001' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol6 <> 0 and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol6 <> 0 and ts < 1605045600000 + 300001' % (mt)) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') @@ -1023,104 +1021,104 @@ class TDTestCase: # TSIM: # TSIM: print =============== step15 tdLog.info('=============== step15') - # TSIM: sql select * from $mt where ts > now + 4m and tgcol2 = 1 and + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol2 = 1 and # tgcol1 = 1 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol2 = 1 and tgcol1 = 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol2 = 1 and tgcol1 = 1' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol2 = 1 and tgcol1 = 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol2 = 1 and tgcol1 = 1' % (mt)) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and tgcol2 <> 1 and + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol2 <> 1 and # tgcol1 <> 1 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol2 <> 1 and tgcol1 <> 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol2 <> 1 and tgcol1 <> 1' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol2 <> 1 and tgcol1 <> 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol2 <> 1 and tgcol1 <> 1' % (mt)) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts < now + 4m and tgcol2 = 0 and + # TSIM: sql select * from $mt where ts < 1605045600000 + 240001 and tgcol2 = 0 and # tgcol1 = 0 tdLog.info( - 'select * from %s where ts < now + 4m and tgcol2 = 0 and tgcol1 = 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol2 = 0 and tgcol1 = 0' % (mt)) tdSql.query( - 'select * from %s where ts < now + 4m and tgcol2 = 0 and tgcol1 = 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol2 = 0 and tgcol1 = 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts < now + 4m and tgcol2 <> 0 and + # TSIM: sql select * from $mt where ts < 1605045600000 + 240001 and tgcol2 <> 0 and # tgcol1 <> 0 tdLog.info( - 'select * from %s where ts < now + 4m and tgcol2 <> 0 and tgcol1 <> 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol2 <> 0 and tgcol1 <> 0' % (mt)) tdSql.query( - 'select * from %s where ts < now + 4m and tgcol2 <> 0 and tgcol1 <> 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol2 <> 0 and tgcol1 <> 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts <= now + 4m and tgcol2 = 0 and + # TSIM: sql select * from $mt where ts <= 1605045600000 + 240001 and tgcol2 = 0 and # tgcol1 = 0 tdLog.info( - 'select * from %s where ts <= now + 4m and tgcol2 = 0 and tgcol1 = 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol2 = 0 and tgcol1 = 0' % (mt)) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol2 = 0 and tgcol1 = 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol2 = 0 and tgcol1 = 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts <= now + 4m and tgcol2 <> 0 and + # TSIM: sql select * from $mt where ts <= 1605045600000 + 240001 and tgcol2 <> 0 and # tgcol1 <> 0 tdLog.info( - 'select * from %s where ts <= now + 4m and tgcol2 <> 0 and tgcol1 <> 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol2 <> 0 and tgcol1 <> 0' % (mt)) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol2 <> 0 and tgcol1 <> 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol2 <> 0 and tgcol1 <> 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and ts < now + 5m and + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and # tgcol2 <> 0 and tgcol1 <> 0 tdLog.info( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol2 <> 0 and tgcol1 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol2 <> 0 and tgcol1 <> 0' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol2 <> 0 and tgcol1 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol2 <> 0 and tgcol1 <> 0' % (mt)) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') tdSql.checkRows(5) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and tgcol2 <> 0 and - # ts < now + 5m and ts < now + 5m and tgcol1 <> 0 + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol2 <> 0 and + # ts < 1605045600000 + 300001 and ts < 1605045600000 + 300001 and tgcol1 <> 0 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol2 <> 0 and ts < now + 5m and ts < now + 5m and tgcol1 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol2 <> 0 and ts < 1605045600000 + 300001 and ts < 1605045600000 + 300001 and tgcol1 <> 0' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol2 <> 0 and ts < now + 5m and ts < now + 5m and tgcol1 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol2 <> 0 and ts < 1605045600000 + 300001 and ts < 1605045600000 + 300001 and tgcol1 <> 0' % (mt)) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') @@ -1130,104 +1128,104 @@ class TDTestCase: # TSIM: # TSIM: print =============== step16 tdLog.info('=============== step16') - # TSIM: sql select * from $mt where ts > now + 4m and tgcol3 = 1 and + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol3 = 1 and # tgcol2 = 1 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol3 = 1 and tgcol2 = 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol3 = 1 and tgcol2 = 1' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol3 = 1 and tgcol2 = 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol3 = 1 and tgcol2 = 1' % (mt)) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and tgcol3 <> 1 and + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol3 <> 1 and # tgcol2 <> 1 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol3 <> 1 and tgcol2 <> 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol3 <> 1 and tgcol2 <> 1' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol3 <> 1 and tgcol2 <> 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol3 <> 1 and tgcol2 <> 1' % (mt)) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts < now + 4m and tgcol3 = 0 and + # TSIM: sql select * from $mt where ts < 1605045600000 + 240001 and tgcol3 = 0 and # tgcol2 = 0 tdLog.info( - 'select * from %s where ts < now + 4m and tgcol3 = 0 and tgcol2 = 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol3 = 0 and tgcol2 = 0' % (mt)) tdSql.query( - 'select * from %s where ts < now + 4m and tgcol3 = 0 and tgcol2 = 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol3 = 0 and tgcol2 = 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts < now + 4m and tgcol3 <> 0 and + # TSIM: sql select * from $mt where ts < 1605045600000 + 240001 and tgcol3 <> 0 and # tgcol2 <> 0 tdLog.info( - 'select * from %s where ts < now + 4m and tgcol3 <> 0 and tgcol2 <> 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol3 <> 0 and tgcol2 <> 0' % (mt)) tdSql.query( - 'select * from %s where ts < now + 4m and tgcol3 <> 0 and tgcol2 <> 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol3 <> 0 and tgcol2 <> 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts <= now + 4m and tgcol3 = 0 and + # TSIM: sql select * from $mt where ts <= 1605045600000 + 240001 and tgcol3 = 0 and # tgcol2 = 0 tdLog.info( - 'select * from %s where ts <= now + 4m and tgcol3 = 0 and tgcol2 = 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol3 = 0 and tgcol2 = 0' % (mt)) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol3 = 0 and tgcol2 = 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol3 = 0 and tgcol2 = 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts <= now + 4m and tgcol3 <> 0 and + # TSIM: sql select * from $mt where ts <= 1605045600000 + 240001 and tgcol3 <> 0 and # tgcol2 <> 0 tdLog.info( - 'select * from %s where ts <= now + 4m and tgcol3 <> 0 and tgcol2 <> 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol3 <> 0 and tgcol2 <> 0' % (mt)) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol3 <> 0 and tgcol2 <> 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol3 <> 0 and tgcol2 <> 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and ts < now + 5m and + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and # tgcol3 <> 0 and tgcol2 <> 0 tdLog.info( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol3 <> 0 and tgcol2 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol3 <> 0 and tgcol2 <> 0' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol3 <> 0 and tgcol2 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol3 <> 0 and tgcol2 <> 0' % (mt)) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') tdSql.checkRows(5) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and tgcol3 <> 0 and - # ts < now + 5m and ts < now + 5m and tgcol2 <> 0 + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol3 <> 0 and + # ts < 1605045600000 + 300001 and ts < 1605045600000 + 300001 and tgcol2 <> 0 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol3 <> 0 and ts < now + 5m and ts < now + 5m and tgcol2 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol3 <> 0 and ts < 1605045600000 + 300001 and ts < 1605045600000 + 300001 and tgcol2 <> 0' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol3 <> 0 and ts < now + 5m and ts < now + 5m and tgcol2 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol3 <> 0 and ts < 1605045600000 + 300001 and ts < 1605045600000 + 300001 and tgcol2 <> 0' % (mt)) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') @@ -1237,104 +1235,104 @@ class TDTestCase: # TSIM: # TSIM: print =============== step17 tdLog.info('=============== step17') - # TSIM: sql select * from $mt where ts > now + 4m and tgcol3 = 1 and + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol3 = 1 and # tgcol4 = 1 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol3 = 1 and tgcol4 = 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol3 = 1 and tgcol4 = 1' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol3 = 1 and tgcol4 = 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol3 = 1 and tgcol4 = 1' % (mt)) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and tgcol3 <> 1 and + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol3 <> 1 and # tgcol4 <> 1 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol3 <> 1 and tgcol4 <> 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol3 <> 1 and tgcol4 <> 1' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol3 <> 1 and tgcol4 <> 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol3 <> 1 and tgcol4 <> 1' % (mt)) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts < now + 4m and tgcol3 = 0 and + # TSIM: sql select * from $mt where ts < 1605045600000 + 240001 and tgcol3 = 0 and # tgcol4 = 0 tdLog.info( - 'select * from %s where ts < now + 4m and tgcol3 = 0 and tgcol4 = 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol3 = 0 and tgcol4 = 0' % (mt)) tdSql.query( - 'select * from %s where ts < now + 4m and tgcol3 = 0 and tgcol4 = 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol3 = 0 and tgcol4 = 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts < now + 4m and tgcol3 <> 0 and + # TSIM: sql select * from $mt where ts < 1605045600000 + 240001 and tgcol3 <> 0 and # tgcol4 <> 0 tdLog.info( - 'select * from %s where ts < now + 4m and tgcol3 <> 0 and tgcol4 <> 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol3 <> 0 and tgcol4 <> 0' % (mt)) tdSql.query( - 'select * from %s where ts < now + 4m and tgcol3 <> 0 and tgcol4 <> 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol3 <> 0 and tgcol4 <> 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts <= now + 4m and tgcol3 = 0 and + # TSIM: sql select * from $mt where ts <= 1605045600000 + 240001 and tgcol3 = 0 and # tgcol4 = 0 tdLog.info( - 'select * from %s where ts <= now + 4m and tgcol3 = 0 and tgcol4 = 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol3 = 0 and tgcol4 = 0' % (mt)) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol3 = 0 and tgcol4 = 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol3 = 0 and tgcol4 = 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts <= now + 4m and tgcol3 <> 0 and + # TSIM: sql select * from $mt where ts <= 1605045600000 + 240001 and tgcol3 <> 0 and # tgcol4 <> 0 tdLog.info( - 'select * from %s where ts <= now + 4m and tgcol3 <> 0 and tgcol4 <> 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol3 <> 0 and tgcol4 <> 0' % (mt)) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol3 <> 0 and tgcol4 <> 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol3 <> 0 and tgcol4 <> 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and ts < now + 5m and + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and # tgcol3 <> 0 and tgcol4 <> 0 tdLog.info( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol3 <> 0 and tgcol4 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol3 <> 0 and tgcol4 <> 0' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol3 <> 0 and tgcol4 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol3 <> 0 and tgcol4 <> 0' % (mt)) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') tdSql.checkRows(5) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and tgcol3 <> 0 and - # ts < now + 5m and ts < now + 5m and tgcol4 <> 0 + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol3 <> 0 and + # ts < 1605045600000 + 300001 and ts < 1605045600000 + 300001 and tgcol4 <> 0 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol3 <> 0 and ts < now + 5m and ts < now + 5m and tgcol4 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol3 <> 0 and ts < 1605045600000 + 300001 and ts < 1605045600000 + 300001 and tgcol4 <> 0' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol3 <> 0 and ts < now + 5m and ts < now + 5m and tgcol4 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol3 <> 0 and ts < 1605045600000 + 300001 and ts < 1605045600000 + 300001 and tgcol4 <> 0' % (mt)) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') @@ -1344,104 +1342,104 @@ class TDTestCase: # TSIM: # TSIM: print =============== step18 tdLog.info('=============== step18') - # TSIM: sql select * from $mt where ts > now + 4m and tgcol5 = 1 and + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol5 = 1 and # tgcol4 = 1 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol5 = 1 and tgcol4 = 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol5 = 1 and tgcol4 = 1' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol5 = 1 and tgcol4 = 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol5 = 1 and tgcol4 = 1' % (mt)) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and tgcol5 <> 1 and + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol5 <> 1 and # tgcol4 <> 1 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol5 <> 1 and tgcol4 <> 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol5 <> 1 and tgcol4 <> 1' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol5 <> 1 and tgcol4 <> 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol5 <> 1 and tgcol4 <> 1' % (mt)) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts < now + 4m and tgcol5 = 0 and + # TSIM: sql select * from $mt where ts < 1605045600000 + 240001 and tgcol5 = 0 and # tgcol4 = 0 tdLog.info( - 'select * from %s where ts < now + 4m and tgcol5 = 0 and tgcol4 = 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol5 = 0 and tgcol4 = 0' % (mt)) tdSql.query( - 'select * from %s where ts < now + 4m and tgcol5 = 0 and tgcol4 = 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol5 = 0 and tgcol4 = 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts < now + 4m and tgcol5 <> 0 and + # TSIM: sql select * from $mt where ts < 1605045600000 + 240001 and tgcol5 <> 0 and # tgcol4 <> 0 tdLog.info( - 'select * from %s where ts < now + 4m and tgcol5 <> 0 and tgcol4 <> 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol5 <> 0 and tgcol4 <> 0' % (mt)) tdSql.query( - 'select * from %s where ts < now + 4m and tgcol5 <> 0 and tgcol4 <> 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol5 <> 0 and tgcol4 <> 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts <= now + 4m and tgcol5 = 0 and + # TSIM: sql select * from $mt where ts <= 1605045600000 + 240001 and tgcol5 = 0 and # tgcol4 = 0 tdLog.info( - 'select * from %s where ts <= now + 4m and tgcol5 = 0 and tgcol4 = 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol5 = 0 and tgcol4 = 0' % (mt)) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol5 = 0 and tgcol4 = 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol5 = 0 and tgcol4 = 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts <= now + 4m and tgcol5 <> 0 and + # TSIM: sql select * from $mt where ts <= 1605045600000 + 240001 and tgcol5 <> 0 and # tgcol4 <> 0 tdLog.info( - 'select * from %s where ts <= now + 4m and tgcol5 <> 0 and tgcol4 <> 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol5 <> 0 and tgcol4 <> 0' % (mt)) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol5 <> 0 and tgcol4 <> 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol5 <> 0 and tgcol4 <> 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and ts < now + 5m and + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and # tgcol5 <> 0 and tgcol4 <> 0 tdLog.info( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol5 <> 0 and tgcol4 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol5 <> 0 and tgcol4 <> 0' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol5 <> 0 and tgcol4 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol5 <> 0 and tgcol4 <> 0' % (mt)) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') tdSql.checkRows(5) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and tgcol5 <> 0 and - # ts < now + 5m and ts < now + 5m and tgcol4 <> 0 + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol5 <> 0 and + # ts < 1605045600000 + 300001 and ts < 1605045600000 + 300001 and tgcol4 <> 0 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol5 <> 0 and ts < now + 5m and ts < now + 5m and tgcol4 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol5 <> 0 and ts < 1605045600000 + 300001 and ts < 1605045600000 + 300001 and tgcol4 <> 0' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol5 <> 0 and ts < now + 5m and ts < now + 5m and tgcol4 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol5 <> 0 and ts < 1605045600000 + 300001 and ts < 1605045600000 + 300001 and tgcol4 <> 0' % (mt)) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') @@ -1451,104 +1449,104 @@ class TDTestCase: # TSIM: # TSIM: print =============== step19 tdLog.info('=============== step19') - # TSIM: sql select * from $mt where ts > now + 4m and tgcol5 = 1 and + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol5 = 1 and # tgcol6 = 1 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol5 = 1 and tgcol6 = 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol5 = 1 and tgcol6 = 1' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol5 = 1 and tgcol6 = 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol5 = 1 and tgcol6 = 1' % (mt)) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and tgcol5 <> 1 and + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol5 <> 1 and # tgcol6 <> 1 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol5 <> 1 and tgcol6 <> 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol5 <> 1 and tgcol6 <> 1' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol5 <> 1 and tgcol6 <> 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol5 <> 1 and tgcol6 <> 1' % (mt)) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts < now + 4m and tgcol5 = 0 and + # TSIM: sql select * from $mt where ts < 1605045600000 + 240001 and tgcol5 = 0 and # tgcol6 = 0 tdLog.info( - 'select * from %s where ts < now + 4m and tgcol5 = 0 and tgcol6 = 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol5 = 0 and tgcol6 = 0' % (mt)) tdSql.query( - 'select * from %s where ts < now + 4m and tgcol5 = 0 and tgcol6 = 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol5 = 0 and tgcol6 = 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts < now + 4m and tgcol5 <> 0 and + # TSIM: sql select * from $mt where ts < 1605045600000 + 240001 and tgcol5 <> 0 and # tgcol6 <> 0 tdLog.info( - 'select * from %s where ts < now + 4m and tgcol5 <> 0 and tgcol6 <> 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol5 <> 0 and tgcol6 <> 0' % (mt)) tdSql.query( - 'select * from %s where ts < now + 4m and tgcol5 <> 0 and tgcol6 <> 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol5 <> 0 and tgcol6 <> 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts <= now + 4m and tgcol5 = 0 and + # TSIM: sql select * from $mt where ts <= 1605045600000 + 240001 and tgcol5 = 0 and # tgcol6 = 0 tdLog.info( - 'select * from %s where ts <= now + 4m and tgcol5 = 0 and tgcol6 = 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol5 = 0 and tgcol6 = 0' % (mt)) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol5 = 0 and tgcol6 = 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol5 = 0 and tgcol6 = 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts <= now + 4m and tgcol5 <> 0 and + # TSIM: sql select * from $mt where ts <= 1605045600000 + 240001 and tgcol5 <> 0 and # tgcol6 <> 0 tdLog.info( - 'select * from %s where ts <= now + 4m and tgcol5 <> 0 and tgcol6 <> 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol5 <> 0 and tgcol6 <> 0' % (mt)) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol5 <> 0 and tgcol6 <> 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol5 <> 0 and tgcol6 <> 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and ts < now + 5m and + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and # tgcol5 <> 0 and tgcol6 <> 0 tdLog.info( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol5 <> 0 and tgcol6 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol5 <> 0 and tgcol6 <> 0' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol5 <> 0 and tgcol6 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol5 <> 0 and tgcol6 <> 0' % (mt)) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') tdSql.checkRows(5) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and tgcol5 <> 0 and - # ts < now + 5m and ts < now + 5m and tgcol6 <> 0 + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol5 <> 0 and + # ts < 1605045600000 + 300001 and ts < 1605045600000 + 300001 and tgcol6 <> 0 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol5 <> 0 and ts < now + 5m and ts < now + 5m and tgcol6 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol5 <> 0 and ts < 1605045600000 + 300001 and ts < 1605045600000 + 300001 and tgcol6 <> 0' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol5 <> 0 and ts < now + 5m and ts < now + 5m and tgcol6 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol5 <> 0 and ts < 1605045600000 + 300001 and ts < 1605045600000 + 300001 and tgcol6 <> 0' % (mt)) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') @@ -1558,104 +1556,104 @@ class TDTestCase: # TSIM: # TSIM: print =============== step20 tdLog.info('=============== step20') - # TSIM: sql select * from $mt where ts > now + 4m and tgcol1 = 1 and + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol1 = 1 and # tgcol2 = 1 and tgcol3 = 1 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol1 = 1 and tgcol2 = 1 and tgcol3 = 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol1 = 1 and tgcol2 = 1 and tgcol3 = 1' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol1 = 1 and tgcol2 = 1 and tgcol3 = 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol1 = 1 and tgcol2 = 1 and tgcol3 = 1' % (mt)) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and tgcol1 <> 1 and + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol1 <> 1 and # tgcol2 <> 1 and tgcol3 <> 1 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol1 <> 1 and tgcol2 <> 1 and tgcol3 <> 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol1 <> 1 and tgcol2 <> 1 and tgcol3 <> 1' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol1 <> 1 and tgcol2 <> 1 and tgcol3 <> 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol1 <> 1 and tgcol2 <> 1 and tgcol3 <> 1' % (mt)) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts < now + 4m and tgcol1 = 0 and + # TSIM: sql select * from $mt where ts < 1605045600000 + 240001 and tgcol1 = 0 and # tgcol2 = 0 and tgcol3 = 0 tdLog.info( - 'select * from %s where ts < now + 4m and tgcol1 = 0 and tgcol2 = 0 and tgcol3 = 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol1 = 0 and tgcol2 = 0 and tgcol3 = 0' % (mt)) tdSql.query( - 'select * from %s where ts < now + 4m and tgcol1 = 0 and tgcol2 = 0 and tgcol3 = 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol1 = 0 and tgcol2 = 0 and tgcol3 = 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts < now + 4m and tgcol1 <> 0 and + # TSIM: sql select * from $mt where ts < 1605045600000 + 240001 and tgcol1 <> 0 and # tgcol2 <> 0 and tgcol3 <> 0 tdLog.info( - 'select * from %s where ts < now + 4m and tgcol1 <> 0 and tgcol2 <> 0 and tgcol3 <> 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol1 <> 0 and tgcol2 <> 0 and tgcol3 <> 0' % (mt)) tdSql.query( - 'select * from %s where ts < now + 4m and tgcol1 <> 0 and tgcol2 <> 0 and tgcol3 <> 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol1 <> 0 and tgcol2 <> 0 and tgcol3 <> 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts <= now + 4m and tgcol1 = 0 and + # TSIM: sql select * from $mt where ts <= 1605045600000 + 240001 and tgcol1 = 0 and # tgcol2 = 0 and tgcol3 = 0 tdLog.info( - 'select * from %s where ts <= now + 4m and tgcol1 = 0 and tgcol2 = 0 and tgcol3 = 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol1 = 0 and tgcol2 = 0 and tgcol3 = 0' % (mt)) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol1 = 0 and tgcol2 = 0 and tgcol3 = 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol1 = 0 and tgcol2 = 0 and tgcol3 = 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts <= now + 4m and tgcol1 <> 0 and + # TSIM: sql select * from $mt where ts <= 1605045600000 + 240001 and tgcol1 <> 0 and # tgcol2 <> 0 and tgcol3 <> 0 tdLog.info( - 'select * from %s where ts <= now + 4m and tgcol1 <> 0 and tgcol2 <> 0 and tgcol3 <> 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol1 <> 0 and tgcol2 <> 0 and tgcol3 <> 0' % (mt)) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol1 <> 0 and tgcol2 <> 0 and tgcol3 <> 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol1 <> 0 and tgcol2 <> 0 and tgcol3 <> 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and ts < now + 5m and + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and # tgcol1 <> 0 and tgcol2 <> 0 and tgcol3 <> 0 tdLog.info( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol1 <> 0 and tgcol2 <> 0 and tgcol3 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol1 <> 0 and tgcol2 <> 0 and tgcol3 <> 0' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol1 <> 0 and tgcol2 <> 0 and tgcol3 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol1 <> 0 and tgcol2 <> 0 and tgcol3 <> 0' % (mt)) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') tdSql.checkRows(5) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and tgcol1 <> 0 and - # ts < now + 5m and ts < now + 5m and tgcol2 <> 0 and tgcol3 <> 0 + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol1 <> 0 and + # ts < 1605045600000 + 300001 and ts < 1605045600000 + 300001 and tgcol2 <> 0 and tgcol3 <> 0 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol1 <> 0 and ts < now + 5m and ts < now + 5m and tgcol2 <> 0 and tgcol3 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol1 <> 0 and ts < 1605045600000 + 300001 and ts < 1605045600000 + 300001 and tgcol2 <> 0 and tgcol3 <> 0' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol1 <> 0 and ts < now + 5m and ts < now + 5m and tgcol2 <> 0 and tgcol3 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol1 <> 0 and ts < 1605045600000 + 300001 and ts < 1605045600000 + 300001 and tgcol2 <> 0 and tgcol3 <> 0' % (mt)) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') @@ -1665,104 +1663,104 @@ class TDTestCase: # TSIM: # TSIM: print =============== step21 tdLog.info('=============== step21') - # TSIM: sql select * from $mt where ts > now + 4m and tgcol4 = 1 and + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol4 = 1 and # tgcol2 = 1 and tgcol3 = 1 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol4 = 1 and tgcol2 = 1 and tgcol3 = 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol4 = 1 and tgcol2 = 1 and tgcol3 = 1' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol4 = 1 and tgcol2 = 1 and tgcol3 = 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol4 = 1 and tgcol2 = 1 and tgcol3 = 1' % (mt)) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and tgcol4 <> 1 and + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol4 <> 1 and # tgcol2 <> 1 and tgcol3 <> 1 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol4 <> 1 and tgcol2 <> 1 and tgcol3 <> 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol4 <> 1 and tgcol2 <> 1 and tgcol3 <> 1' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol4 <> 1 and tgcol2 <> 1 and tgcol3 <> 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol4 <> 1 and tgcol2 <> 1 and tgcol3 <> 1' % (mt)) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts < now + 4m and tgcol4 = 0 and + # TSIM: sql select * from $mt where ts < 1605045600000 + 240001 and tgcol4 = 0 and # tgcol2 = 0 and tgcol3 = 0 tdLog.info( - 'select * from %s where ts < now + 4m and tgcol4 = 0 and tgcol2 = 0 and tgcol3 = 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol4 = 0 and tgcol2 = 0 and tgcol3 = 0' % (mt)) tdSql.query( - 'select * from %s where ts < now + 4m and tgcol4 = 0 and tgcol2 = 0 and tgcol3 = 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol4 = 0 and tgcol2 = 0 and tgcol3 = 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts < now + 4m and tgcol4 <> 0 and + # TSIM: sql select * from $mt where ts < 1605045600000 + 240001 and tgcol4 <> 0 and # tgcol2 <> 0 and tgcol3 <> 0 tdLog.info( - 'select * from %s where ts < now + 4m and tgcol4 <> 0 and tgcol2 <> 0 and tgcol3 <> 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol4 <> 0 and tgcol2 <> 0 and tgcol3 <> 0' % (mt)) tdSql.query( - 'select * from %s where ts < now + 4m and tgcol4 <> 0 and tgcol2 <> 0 and tgcol3 <> 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol4 <> 0 and tgcol2 <> 0 and tgcol3 <> 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts <= now + 4m and tgcol4 = 0 and + # TSIM: sql select * from $mt where ts <= 1605045600000 + 240001 and tgcol4 = 0 and # tgcol2 = 0 and tgcol3 = 0 tdLog.info( - 'select * from %s where ts <= now + 4m and tgcol4 = 0 and tgcol2 = 0 and tgcol3 = 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol4 = 0 and tgcol2 = 0 and tgcol3 = 0' % (mt)) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol4 = 0 and tgcol2 = 0 and tgcol3 = 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol4 = 0 and tgcol2 = 0 and tgcol3 = 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts <= now + 4m and tgcol4 <> 0 and + # TSIM: sql select * from $mt where ts <= 1605045600000 + 240001 and tgcol4 <> 0 and # tgcol2 <> 0 and tgcol3 <> 0 tdLog.info( - 'select * from %s where ts <= now + 4m and tgcol4 <> 0 and tgcol2 <> 0 and tgcol3 <> 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol4 <> 0 and tgcol2 <> 0 and tgcol3 <> 0' % (mt)) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol4 <> 0 and tgcol2 <> 0 and tgcol3 <> 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol4 <> 0 and tgcol2 <> 0 and tgcol3 <> 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and ts < now + 5m and + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and # tgcol4 <> 0 and tgcol2 <> 0 and tgcol3 <> 0 tdLog.info( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol4 <> 0 and tgcol2 <> 0 and tgcol3 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol4 <> 0 and tgcol2 <> 0 and tgcol3 <> 0' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol4 <> 0 and tgcol2 <> 0 and tgcol3 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol4 <> 0 and tgcol2 <> 0 and tgcol3 <> 0' % (mt)) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') tdSql.checkRows(5) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and tgcol4 <> 0 and - # ts < now + 5m and ts < now + 5m and tgcol2 <> 0 and tgcol3 <> 0 + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol4 <> 0 and + # ts < 1605045600000 + 300001 and ts < 1605045600000 + 300001 and tgcol2 <> 0 and tgcol3 <> 0 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol4 <> 0 and ts < now + 5m and ts < now + 5m and tgcol2 <> 0 and tgcol3 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol4 <> 0 and ts < 1605045600000 + 300001 and ts < 1605045600000 + 300001 and tgcol2 <> 0 and tgcol3 <> 0' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol4 <> 0 and ts < now + 5m and ts < now + 5m and tgcol2 <> 0 and tgcol3 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol4 <> 0 and ts < 1605045600000 + 300001 and ts < 1605045600000 + 300001 and tgcol2 <> 0 and tgcol3 <> 0' % (mt)) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') @@ -1772,105 +1770,105 @@ class TDTestCase: # TSIM: # TSIM: print =============== step22 tdLog.info('=============== step22') - # TSIM: sql select * from $mt where ts > now + 4m and tgcol4 = 1 and + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol4 = 1 and # tgcol2 = 1 and tgcol3 = 1 and tgcol1 = 1 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol4 = 1 and tgcol2 = 1 and tgcol3 = 1 and tgcol1 = 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol4 = 1 and tgcol2 = 1 and tgcol3 = 1 and tgcol1 = 1' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol4 = 1 and tgcol2 = 1 and tgcol3 = 1 and tgcol1 = 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol4 = 1 and tgcol2 = 1 and tgcol3 = 1 and tgcol1 = 1' % (mt)) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and tgcol4 <> 1 and + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol4 <> 1 and # tgcol2 <> 1 and tgcol3 <> 1 and tgcol1 <> 1 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol4 <> 1 and tgcol2 <> 1 and tgcol3 <> 1 and tgcol1 <> 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol4 <> 1 and tgcol2 <> 1 and tgcol3 <> 1 and tgcol1 <> 1' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol4 <> 1 and tgcol2 <> 1 and tgcol3 <> 1 and tgcol1 <> 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol4 <> 1 and tgcol2 <> 1 and tgcol3 <> 1 and tgcol1 <> 1' % (mt)) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts < now + 4m and tgcol4 = 0 and + # TSIM: sql select * from $mt where ts < 1605045600000 + 240001 and tgcol4 = 0 and # tgcol2 = 0 and tgcol3 = 0 and tgcol1 = 0 tdLog.info( - 'select * from %s where ts < now + 4m and tgcol4 = 0 and tgcol2 = 0 and tgcol3 = 0 and tgcol1 = 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol4 = 0 and tgcol2 = 0 and tgcol3 = 0 and tgcol1 = 0' % (mt)) tdSql.query( - 'select * from %s where ts < now + 4m and tgcol4 = 0 and tgcol2 = 0 and tgcol3 = 0 and tgcol1 = 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol4 = 0 and tgcol2 = 0 and tgcol3 = 0 and tgcol1 = 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts < now + 4m and tgcol4 <> 0 and + # TSIM: sql select * from $mt where ts < 1605045600000 + 240001 and tgcol4 <> 0 and # tgcol2 <> 0 and tgcol3 <> 0 and tgcol1 <> 0 tdLog.info( - 'select * from %s where ts < now + 4m and tgcol4 <> 0 and tgcol2 <> 0 and tgcol3 <> 0 and tgcol1 <> 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol4 <> 0 and tgcol2 <> 0 and tgcol3 <> 0 and tgcol1 <> 0' % (mt)) tdSql.query( - 'select * from %s where ts < now + 4m and tgcol4 <> 0 and tgcol2 <> 0 and tgcol3 <> 0 and tgcol1 <> 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol4 <> 0 and tgcol2 <> 0 and tgcol3 <> 0 and tgcol1 <> 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts <= now + 4m and tgcol4 = 0 and + # TSIM: sql select * from $mt where ts <= 1605045600000 + 240001 and tgcol4 = 0 and # tgcol2 = 0 and tgcol3 = 0 and tgcol1 = 0 tdLog.info( - 'select * from %s where ts <= now + 4m and tgcol4 = 0 and tgcol2 = 0 and tgcol3 = 0 and tgcol1 = 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol4 = 0 and tgcol2 = 0 and tgcol3 = 0 and tgcol1 = 0' % (mt)) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol4 = 0 and tgcol2 = 0 and tgcol3 = 0 and tgcol1 = 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol4 = 0 and tgcol2 = 0 and tgcol3 = 0 and tgcol1 = 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts <= now + 4m and tgcol4 <> 0 and + # TSIM: sql select * from $mt where ts <= 1605045600000 + 240001 and tgcol4 <> 0 and # tgcol2 <> 0 and tgcol3 <> 0 and tgcol1 <> 0 tdLog.info( - 'select * from %s where ts <= now + 4m and tgcol4 <> 0 and tgcol2 <> 0 and tgcol3 <> 0 and tgcol1 <> 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol4 <> 0 and tgcol2 <> 0 and tgcol3 <> 0 and tgcol1 <> 0' % (mt)) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol4 <> 0 and tgcol2 <> 0 and tgcol3 <> 0 and tgcol1 <> 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol4 <> 0 and tgcol2 <> 0 and tgcol3 <> 0 and tgcol1 <> 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and ts < now + 5m and + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and # tgcol4 <> 0 and tgcol2 <> 0 and tgcol3 <> 0 and tgcol1 <> 0 tdLog.info( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol4 <> 0 and tgcol2 <> 0 and tgcol3 <> 0 and tgcol1 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol4 <> 0 and tgcol2 <> 0 and tgcol3 <> 0 and tgcol1 <> 0' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol4 <> 0 and tgcol2 <> 0 and tgcol3 <> 0 and tgcol1 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol4 <> 0 and tgcol2 <> 0 and tgcol3 <> 0 and tgcol1 <> 0' % (mt)) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') tdSql.checkRows(5) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and tgcol4 <> 0 and - # ts < now + 5m and ts < now + 5m and tgcol2 <> 0 and tgcol3 <> 0 and + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol4 <> 0 and + # ts < 1605045600000 + 300001 and ts < 1605045600000 + 300001 and tgcol2 <> 0 and tgcol3 <> 0 and # tgcol1 <> 0 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol4 <> 0 and ts < now + 5m and ts < now + 5m and tgcol2 <> 0 and tgcol3 <> 0 and tgcol1 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol4 <> 0 and ts < 1605045600000 + 300001 and ts < 1605045600000 + 300001 and tgcol2 <> 0 and tgcol3 <> 0 and tgcol1 <> 0' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol4 <> 0 and ts < now + 5m and ts < now + 5m and tgcol2 <> 0 and tgcol3 <> 0 and tgcol1 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol4 <> 0 and ts < 1605045600000 + 300001 and ts < 1605045600000 + 300001 and tgcol2 <> 0 and tgcol3 <> 0 and tgcol1 <> 0' % (mt)) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') @@ -1880,106 +1878,106 @@ class TDTestCase: # TSIM: # TSIM: print =============== step23 tdLog.info('=============== step23') - # TSIM: sql select * from $mt where ts > now + 4m and tgcol4 = 1 and + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol4 = 1 and # tgcol2 = 1 and tgcol3 = 1 and tgcol1 = 1 and tgcol5 = 1 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol4 = 1 and tgcol2 = 1 and tgcol3 = 1 and tgcol1 = 1 and tgcol5 = 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol4 = 1 and tgcol2 = 1 and tgcol3 = 1 and tgcol1 = 1 and tgcol5 = 1' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol4 = 1 and tgcol2 = 1 and tgcol3 = 1 and tgcol1 = 1 and tgcol5 = 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol4 = 1 and tgcol2 = 1 and tgcol3 = 1 and tgcol1 = 1 and tgcol5 = 1' % (mt)) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and tgcol4 <> 1 and + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol4 <> 1 and # tgcol2 <> 1 and tgcol3 <> 1 and tgcol1 <> 1 and tgcol5 <> 1 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol4 <> 1 and tgcol2 <> 1 and tgcol3 <> 1 and tgcol1 <> 1 and tgcol5 <> 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol4 <> 1 and tgcol2 <> 1 and tgcol3 <> 1 and tgcol1 <> 1 and tgcol5 <> 1' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol4 <> 1 and tgcol2 <> 1 and tgcol3 <> 1 and tgcol1 <> 1 and tgcol5 <> 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol4 <> 1 and tgcol2 <> 1 and tgcol3 <> 1 and tgcol1 <> 1 and tgcol5 <> 1' % (mt)) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts < now + 4m and tgcol4 = 0 and + # TSIM: sql select * from $mt where ts < 1605045600000 + 240001 and tgcol4 = 0 and # tgcol2 = 0 and tgcol3 = 0 and tgcol1 = 0 and tgcol5 = 0 tdLog.info( - 'select * from %s where ts < now + 4m and tgcol4 = 0 and tgcol2 = 0 and tgcol3 = 0 and tgcol1 = 0 and tgcol5 = 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol4 = 0 and tgcol2 = 0 and tgcol3 = 0 and tgcol1 = 0 and tgcol5 = 0' % (mt)) tdSql.query( - 'select * from %s where ts < now + 4m and tgcol4 = 0 and tgcol2 = 0 and tgcol3 = 0 and tgcol1 = 0 and tgcol5 = 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol4 = 0 and tgcol2 = 0 and tgcol3 = 0 and tgcol1 = 0 and tgcol5 = 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts < now + 4m and tgcol4 <> 0 and + # TSIM: sql select * from $mt where ts < 1605045600000 + 240001 and tgcol4 <> 0 and # tgcol2 <> 0 and tgcol3 <> 0 and tgcol1 <> 0 and tgcol5 <> 0 tdLog.info( - 'select * from %s where ts < now + 4m and tgcol4 <> 0 and tgcol2 <> 0 and tgcol3 <> 0 and tgcol1 <> 0 and tgcol5 <> 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol4 <> 0 and tgcol2 <> 0 and tgcol3 <> 0 and tgcol1 <> 0 and tgcol5 <> 0' % (mt)) tdSql.query( - 'select * from %s where ts < now + 4m and tgcol4 <> 0 and tgcol2 <> 0 and tgcol3 <> 0 and tgcol1 <> 0 and tgcol5 <> 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol4 <> 0 and tgcol2 <> 0 and tgcol3 <> 0 and tgcol1 <> 0 and tgcol5 <> 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts <= now + 4m and tgcol4 = 0 and + # TSIM: sql select * from $mt where ts <= 1605045600000 + 240001 and tgcol4 = 0 and # tgcol2 = 0 and tgcol3 = 0 and tgcol1 = 0 and tgcol5 = 0 tdLog.info( - 'select * from %s where ts <= now + 4m and tgcol4 = 0 and tgcol2 = 0 and tgcol3 = 0 and tgcol1 = 0 and tgcol5 = 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol4 = 0 and tgcol2 = 0 and tgcol3 = 0 and tgcol1 = 0 and tgcol5 = 0' % (mt)) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol4 = 0 and tgcol2 = 0 and tgcol3 = 0 and tgcol1 = 0 and tgcol5 = 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol4 = 0 and tgcol2 = 0 and tgcol3 = 0 and tgcol1 = 0 and tgcol5 = 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts <= now + 4m and tgcol4 <> 0 and + # TSIM: sql select * from $mt where ts <= 1605045600000 + 240001 and tgcol4 <> 0 and # tgcol2 <> 0 and tgcol3 <> 0 and tgcol1 <> 0 and tgcol5 <> 0 tdLog.info( - 'select * from %s where ts <= now + 4m and tgcol4 <> 0 and tgcol2 <> 0 and tgcol3 <> 0 and tgcol1 <> 0 and tgcol5 <> 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol4 <> 0 and tgcol2 <> 0 and tgcol3 <> 0 and tgcol1 <> 0 and tgcol5 <> 0' % (mt)) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol4 <> 0 and tgcol2 <> 0 and tgcol3 <> 0 and tgcol1 <> 0 and tgcol5 <> 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol4 <> 0 and tgcol2 <> 0 and tgcol3 <> 0 and tgcol1 <> 0 and tgcol5 <> 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and ts < now + 5m and + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and # tgcol4 <> 0 and tgcol2 <> 0 and tgcol3 <> 0 and tgcol1 <> 0 and # tgcol5 <> 0 tdLog.info( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol4 <> 0 and tgcol2 <> 0 and tgcol3 <> 0 and tgcol1 <> 0 and tgcol5 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol4 <> 0 and tgcol2 <> 0 and tgcol3 <> 0 and tgcol1 <> 0 and tgcol5 <> 0' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol4 <> 0 and tgcol2 <> 0 and tgcol3 <> 0 and tgcol1 <> 0 and tgcol5 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol4 <> 0 and tgcol2 <> 0 and tgcol3 <> 0 and tgcol1 <> 0 and tgcol5 <> 0' % (mt)) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') tdSql.checkRows(5) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and tgcol4 <> 0 and - # ts < now + 5m and ts < now + 5m and tgcol2 <> 0 and tgcol3 <> 0 and + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol4 <> 0 and + # ts < 1605045600000 + 300001 and ts < 1605045600000 + 300001 and tgcol2 <> 0 and tgcol3 <> 0 and # tgcol1 <> 0 and tgcol5 <> 0 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol4 <> 0 and ts < now + 5m and ts < now + 5m and tgcol2 <> 0 and tgcol3 <> 0 and tgcol1 <> 0 and tgcol5 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol4 <> 0 and ts < 1605045600000 + 300001 and ts < 1605045600000 + 300001 and tgcol2 <> 0 and tgcol3 <> 0 and tgcol1 <> 0 and tgcol5 <> 0' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol4 <> 0 and ts < now + 5m and ts < now + 5m and tgcol2 <> 0 and tgcol3 <> 0 and tgcol1 <> 0 and tgcol5 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol4 <> 0 and ts < 1605045600000 + 300001 and ts < 1605045600000 + 300001 and tgcol2 <> 0 and tgcol3 <> 0 and tgcol1 <> 0 and tgcol5 <> 0' % (mt)) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') @@ -1989,112 +1987,112 @@ class TDTestCase: # TSIM: # TSIM: print =============== step24 tdLog.info('=============== step24') - # TSIM: sql select * from $mt where ts > now + 4m and tgcol4 = 1 and + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol4 = 1 and # tgcol2 = 1 and tgcol3 = 1 and tgcol1 = 1 and tgcol5 = 1 and tgcol6 = # 1 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol4 = 1 and tgcol2 = 1 and tgcol3 = 1 and tgcol1 = 1 and tgcol5 = 1 and tgcol6 = 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol4 = 1 and tgcol2 = 1 and tgcol3 = 1 and tgcol1 = 1 and tgcol5 = 1 and tgcol6 = 1' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol4 = 1 and tgcol2 = 1 and tgcol3 = 1 and tgcol1 = 1 and tgcol5 = 1 and tgcol6 = 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol4 = 1 and tgcol2 = 1 and tgcol3 = 1 and tgcol1 = 1 and tgcol5 = 1 and tgcol6 = 1' % (mt)) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and tgcol4 <> 1 and + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol4 <> 1 and # tgcol2 <> 1 and tgcol3 <> 1 and tgcol1 <> 1 and tgcol5 <> 1 and # tgcol6 <> 1 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol4 <> 1 and tgcol2 <> 1 and tgcol3 <> 1 and tgcol1 <> 1 and tgcol5 <> 1 and tgcol6 <> 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol4 <> 1 and tgcol2 <> 1 and tgcol3 <> 1 and tgcol1 <> 1 and tgcol5 <> 1 and tgcol6 <> 1' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol4 <> 1 and tgcol2 <> 1 and tgcol3 <> 1 and tgcol1 <> 1 and tgcol5 <> 1 and tgcol6 <> 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol4 <> 1 and tgcol2 <> 1 and tgcol3 <> 1 and tgcol1 <> 1 and tgcol5 <> 1 and tgcol6 <> 1' % (mt)) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts < now + 4m and tgcol4 = 0 and + # TSIM: sql select * from $mt where ts < 1605045600000 + 240001 and tgcol4 = 0 and # tgcol2 = 0 and tgcol3 = 0 and tgcol1 = 0 and tgcol5 = 0 and tgcol6 = # 0 tdLog.info( - 'select * from %s where ts < now + 4m and tgcol4 = 0 and tgcol2 = 0 and tgcol3 = 0 and tgcol1 = 0 and tgcol5 = 0 and tgcol6 = 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol4 = 0 and tgcol2 = 0 and tgcol3 = 0 and tgcol1 = 0 and tgcol5 = 0 and tgcol6 = 0' % (mt)) tdSql.query( - 'select * from %s where ts < now + 4m and tgcol4 = 0 and tgcol2 = 0 and tgcol3 = 0 and tgcol1 = 0 and tgcol5 = 0 and tgcol6 = 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol4 = 0 and tgcol2 = 0 and tgcol3 = 0 and tgcol1 = 0 and tgcol5 = 0 and tgcol6 = 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts < now + 4m and tgcol4 <> 0 and + # TSIM: sql select * from $mt where ts < 1605045600000 + 240001 and tgcol4 <> 0 and # tgcol2 <> 0 and tgcol3 <> 0 and tgcol1 <> 0 and tgcol5 <> 0 and # tgcol6 <> 0 tdLog.info( - 'select * from %s where ts < now + 4m and tgcol4 <> 0 and tgcol2 <> 0 and tgcol3 <> 0 and tgcol1 <> 0 and tgcol5 <> 0 and tgcol6 <> 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol4 <> 0 and tgcol2 <> 0 and tgcol3 <> 0 and tgcol1 <> 0 and tgcol5 <> 0 and tgcol6 <> 0' % (mt)) tdSql.query( - 'select * from %s where ts < now + 4m and tgcol4 <> 0 and tgcol2 <> 0 and tgcol3 <> 0 and tgcol1 <> 0 and tgcol5 <> 0 and tgcol6 <> 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol4 <> 0 and tgcol2 <> 0 and tgcol3 <> 0 and tgcol1 <> 0 and tgcol5 <> 0 and tgcol6 <> 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts <= now + 4m and tgcol4 = 0 and + # TSIM: sql select * from $mt where ts <= 1605045600000 + 240001 and tgcol4 = 0 and # tgcol2 = 0 and tgcol3 = 0 and tgcol1 = 0 and tgcol5 = 0 and tgcol6 = # 0 tdLog.info( - 'select * from %s where ts <= now + 4m and tgcol4 = 0 and tgcol2 = 0 and tgcol3 = 0 and tgcol1 = 0 and tgcol5 = 0 and tgcol6 = 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol4 = 0 and tgcol2 = 0 and tgcol3 = 0 and tgcol1 = 0 and tgcol5 = 0 and tgcol6 = 0' % (mt)) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol4 = 0 and tgcol2 = 0 and tgcol3 = 0 and tgcol1 = 0 and tgcol5 = 0 and tgcol6 = 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol4 = 0 and tgcol2 = 0 and tgcol3 = 0 and tgcol1 = 0 and tgcol5 = 0 and tgcol6 = 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts <= now + 4m and tgcol4 <> 0 and + # TSIM: sql select * from $mt where ts <= 1605045600000 + 240001 and tgcol4 <> 0 and # tgcol2 <> 0 and tgcol3 <> 0 and tgcol1 <> 0 and tgcol5 <> 0 and # tgcol6 <> 0 tdLog.info( - 'select * from %s where ts <= now + 4m and tgcol4 <> 0 and tgcol2 <> 0 and tgcol3 <> 0 and tgcol1 <> 0 and tgcol5 <> 0 and tgcol6 <> 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol4 <> 0 and tgcol2 <> 0 and tgcol3 <> 0 and tgcol1 <> 0 and tgcol5 <> 0 and tgcol6 <> 0' % (mt)) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol4 <> 0 and tgcol2 <> 0 and tgcol3 <> 0 and tgcol1 <> 0 and tgcol5 <> 0 and tgcol6 <> 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol4 <> 0 and tgcol2 <> 0 and tgcol3 <> 0 and tgcol1 <> 0 and tgcol5 <> 0 and tgcol6 <> 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and ts < now + 5m and + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and # tgcol4 <> 0 and tgcol2 <> 0 and tgcol3 <> 0 and tgcol1 <> 0 and # tgcol5 <> 0 and tgcol6 <> 0 tdLog.info( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol4 <> 0 and tgcol2 <> 0 and tgcol3 <> 0 and tgcol1 <> 0 and tgcol5 <> 0 and tgcol6 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol4 <> 0 and tgcol2 <> 0 and tgcol3 <> 0 and tgcol1 <> 0 and tgcol5 <> 0 and tgcol6 <> 0' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol4 <> 0 and tgcol2 <> 0 and tgcol3 <> 0 and tgcol1 <> 0 and tgcol5 <> 0 and tgcol6 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol4 <> 0 and tgcol2 <> 0 and tgcol3 <> 0 and tgcol1 <> 0 and tgcol5 <> 0 and tgcol6 <> 0' % (mt)) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') tdSql.checkRows(5) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and tgcol4 <> 0 and - # ts < now + 5m and ts < now + 5m and tgcol2 <> 0 and tgcol3 <> 0 and + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol4 <> 0 and + # ts < 1605045600000 + 300001 and ts < 1605045600000 + 300001 and tgcol2 <> 0 and tgcol3 <> 0 and # tgcol1 <> 0 and tgcol5 <> 0 and tgcol6 <> 0 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol4 <> 0 and ts < now + 5m and ts < now + 5m and tgcol2 <> 0 and tgcol3 <> 0 and tgcol1 <> 0 and tgcol5 <> 0 and tgcol6 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol4 <> 0 and ts < 1605045600000 + 300001 and ts < 1605045600000 + 300001 and tgcol2 <> 0 and tgcol3 <> 0 and tgcol1 <> 0 and tgcol5 <> 0 and tgcol6 <> 0' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol4 <> 0 and ts < now + 5m and ts < now + 5m and tgcol2 <> 0 and tgcol3 <> 0 and tgcol1 <> 0 and tgcol5 <> 0 and tgcol6 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol4 <> 0 and ts < 1605045600000 + 300001 and ts < 1605045600000 + 300001 and tgcol2 <> 0 and tgcol3 <> 0 and tgcol1 <> 0 and tgcol5 <> 0 and tgcol6 <> 0' % (mt)) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') @@ -2221,12 +2219,12 @@ class TDTestCase: # TSIM: print =============== step27 tdLog.info('=============== step27') # TSIM: sql select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), - # max(tbcol), first(tbcol), last(tbcol) from $mt where ts < now + 4m + # max(tbcol), first(tbcol), last(tbcol) from $mt where ts < 1605045600000 + 240001 tdLog.info( - 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m' % + 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001' % (mt)) tdSql.query( - 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m' % + 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001' % (mt)) # TSIM: print $data00 $data01 $data02 $data03 $data04 $data05 $data06 tdLog.info('$data00 $data01 $data02 $data03 $data04 $data05 $data06') @@ -2237,13 +2235,13 @@ class TDTestCase: # TSIM: endi # TSIM: # TSIM: sql select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), - # max(tbcol), first(tbcol), last(tbcol) from $mt where ts < now + 4m + # max(tbcol), first(tbcol), last(tbcol) from $mt where ts < 1605045600000 + 240001 # and tgcol1 = 1 tdLog.info( - 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m and tgcol1 = 1' % + 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001 and tgcol1 = 1' % (mt)) tdSql.query( - 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m and tgcol1 = 1' % + 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001 and tgcol1 = 1' % (mt)) # TSIM: print $data00 $data01 $data02 $data03 $data04 $data05 $data06 tdLog.info('$data00 $data01 $data02 $data03 $data04 $data05 $data06') @@ -2254,13 +2252,13 @@ class TDTestCase: # TSIM: endi # TSIM: # TSIM: sql select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), - # max(tbcol), first(tbcol), last(tbcol) from $mt where ts < now + 4m + # max(tbcol), first(tbcol), last(tbcol) from $mt where ts < 1605045600000 + 240001 # and tgcol1 = 1 and tgcol2 = 1 tdLog.info( - 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m and tgcol1 = 1 and tgcol2 = 1' % + 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001 and tgcol1 = 1 and tgcol2 = 1' % (mt)) tdSql.query( - 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m and tgcol1 = 1 and tgcol2 = 1' % + 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001 and tgcol1 = 1 and tgcol2 = 1' % (mt)) # TSIM: print $data00 $data01 $data02 $data03 $data04 $data05 $data06 tdLog.info('$data00 $data01 $data02 $data03 $data04 $data05 $data06') @@ -2271,13 +2269,13 @@ class TDTestCase: # TSIM: endi # TSIM: # TSIM: sql select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), - # max(tbcol), first(tbcol), last(tbcol) from $mt where ts < now + 4m + # max(tbcol), first(tbcol), last(tbcol) from $mt where ts < 1605045600000 + 240001 # and tgcol1 = 1 and tgcol2 = 1 and tgcol3 = 1 tdLog.info( - 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m and tgcol1 = 1 and tgcol2 = 1 and tgcol3 = 1' % + 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001 and tgcol1 = 1 and tgcol2 = 1 and tgcol3 = 1' % (mt)) tdSql.query( - 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m and tgcol1 = 1 and tgcol2 = 1 and tgcol3 = 1' % + 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001 and tgcol1 = 1 and tgcol2 = 1 and tgcol3 = 1' % (mt)) # TSIM: print $data00 $data01 $data02 $data03 $data04 $data05 $data06 tdLog.info('$data00 $data01 $data02 $data03 $data04 $data05 $data06') @@ -2288,11 +2286,11 @@ class TDTestCase: # TSIM: endi # TSIM: # TSIM: sql select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), - # max(tbcol), first(tbcol), last(tbcol) from $mt where ts < now + 4m + # max(tbcol), first(tbcol), last(tbcol) from $mt where ts < 1605045600000 + 240001 # and tgcol1 = 1 and tgcol2 = 1 and tgcol3 = 1 and tgcol4 = 1 - tdLog.info('select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m and tgcol1 = 1 and tgcol2 = 1 and tgcol3 = 1 and tgcol4 = 1' % (mt)) + tdLog.info('select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001 and tgcol1 = 1 and tgcol2 = 1 and tgcol3 = 1 and tgcol4 = 1' % (mt)) tdSql.query( - 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m and tgcol1 = 1 and tgcol2 = 1 and tgcol3 = 1 and tgcol4 = 1' % + 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001 and tgcol1 = 1 and tgcol2 = 1 and tgcol3 = 1 and tgcol4 = 1' % (mt)) # TSIM: print $data00 $data01 $data02 $data03 $data04 $data05 $data06 tdLog.info('$data00 $data01 $data02 $data03 $data04 $data05 $data06') @@ -2303,11 +2301,11 @@ class TDTestCase: # TSIM: endi # TSIM: # TSIM: sql select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), - # max(tbcol), first(tbcol), last(tbcol) from $mt where ts < now + 4m + # max(tbcol), first(tbcol), last(tbcol) from $mt where ts < 1605045600000 + 240001 # and tgcol1 = 1 and tgcol2 = 1 and tgcol3 = 1 and tgcol4 = 1 and # tgcol5 = 1 - tdLog.info('select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m and tgcol1 = 1 and tgcol2 = 1 and tgcol3 = 1 and tgcol4 = 1 and tgcol5 = 1' % (mt)) - tdSql.query('select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m and tgcol1 = 1 and tgcol2 = 1 and tgcol3 = 1 and tgcol4 = 1 and tgcol5 = 1' % (mt)) + tdLog.info('select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001 and tgcol1 = 1 and tgcol2 = 1 and tgcol3 = 1 and tgcol4 = 1 and tgcol5 = 1' % (mt)) + tdSql.query('select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001 and tgcol1 = 1 and tgcol2 = 1 and tgcol3 = 1 and tgcol4 = 1 and tgcol5 = 1' % (mt)) # TSIM: print $data00 $data01 $data02 $data03 $data04 $data05 $data06 tdLog.info('$data00 $data01 $data02 $data03 $data04 $data05 $data06') # TSIM: if $data00 != 25 then @@ -2317,11 +2315,11 @@ class TDTestCase: # TSIM: endi # TSIM: # TSIM: sql select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), - # max(tbcol), first(tbcol), last(tbcol) from $mt where ts < now + 4m + # max(tbcol), first(tbcol), last(tbcol) from $mt where ts < 1605045600000 + 240001 # and tgcol1 = 1 and tgcol2 = 1 and tgcol3 = 1 and tgcol4 = 1 and # tgcol5 = 1 and tgcol6 = 1 - tdLog.info('select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m and tgcol1 = 1 and tgcol2 = 1 and tgcol3 = 1 and tgcol4 = 1 and tgcol5 = 1 and tgcol6 = 1' % (mt)) - tdSql.query('select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m and tgcol1 = 1 and tgcol2 = 1 and tgcol3 = 1 and tgcol4 = 1 and tgcol5 = 1 and tgcol6 = 1' % (mt)) + tdLog.info('select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001 and tgcol1 = 1 and tgcol2 = 1 and tgcol3 = 1 and tgcol4 = 1 and tgcol5 = 1 and tgcol6 = 1' % (mt)) + tdSql.query('select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001 and tgcol1 = 1 and tgcol2 = 1 and tgcol3 = 1 and tgcol4 = 1 and tgcol5 = 1 and tgcol6 = 1' % (mt)) # TSIM: print $data00 $data01 $data02 $data03 $data04 $data05 $data06 tdLog.info('$data00 $data01 $data02 $data03 $data04 $data05 $data06') # TSIM: if $data00 != 25 then @@ -2527,13 +2525,13 @@ class TDTestCase: # TSIM: print =============== step30 tdLog.info('=============== step30') # TSIM: sql select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), - # max(tbcol), first(tbcol), last(tbcol) from $mt where ts < now + 4m + # max(tbcol), first(tbcol), last(tbcol) from $mt where ts < 1605045600000 + 240001 # group by tgcol2 tdLog.info( - 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m group by tgcol2' % + 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001 group by tgcol2' % (mt)) tdSql.query( - 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m group by tgcol2' % + 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001 group by tgcol2' % (mt)) # TSIM: print $data00 $data01 $data02 $data03 $data04 $data05 $data06 tdLog.info('$data00 $data01 $data02 $data03 $data04 $data05 $data06') @@ -2544,13 +2542,13 @@ class TDTestCase: # TSIM: endi # TSIM: # TSIM: sql select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), - # max(tbcol), first(tbcol), last(tbcol) from $mt where ts < now + 4m + # max(tbcol), first(tbcol), last(tbcol) from $mt where ts < 1605045600000 + 240001 # and tgcol1 = 1 group by tgcol2 tdLog.info( - 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m and tgcol1 = 1 group by tgcol2' % + 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001 and tgcol1 = 1 group by tgcol2' % (mt)) tdSql.query( - 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m and tgcol1 = 1 group by tgcol2' % + 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001 and tgcol1 = 1 group by tgcol2' % (mt)) # TSIM: print $data00 $data01 $data02 $data03 $data04 $data05 $data06 tdLog.info('$data00 $data01 $data02 $data03 $data04 $data05 $data06') @@ -2561,13 +2559,13 @@ class TDTestCase: # TSIM: endi # TSIM: # TSIM: sql select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), - # max(tbcol), first(tbcol), last(tbcol) from $mt where ts < now + 4m + # max(tbcol), first(tbcol), last(tbcol) from $mt where ts < 1605045600000 + 240001 # and tgcol1 = 1 and tgcol2 = 1 group by tgcol2 tdLog.info( - 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m and tgcol1 = 1 and tgcol2 = 1 group by tgcol2' % + 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001 and tgcol1 = 1 and tgcol2 = 1 group by tgcol2' % (mt)) tdSql.query( - 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m and tgcol1 = 1 and tgcol2 = 1 group by tgcol2' % + 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001 and tgcol1 = 1 and tgcol2 = 1 group by tgcol2' % (mt)) # TSIM: print $data00 $data01 $data02 $data03 $data04 $data05 $data06 tdLog.info('$data00 $data01 $data02 $data03 $data04 $data05 $data06') @@ -2578,11 +2576,11 @@ class TDTestCase: # TSIM: endi # TSIM: # TSIM: sql select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), - # max(tbcol), first(tbcol), last(tbcol) from $mt where ts < now + 4m + # max(tbcol), first(tbcol), last(tbcol) from $mt where ts < 1605045600000 + 240001 # and tgcol1 = 1 and tgcol2 = 1 and tgcol3 = 1 group by tgcol2 - tdLog.info('select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m and tgcol1 = 1 and tgcol2 = 1 and tgcol3 = 1 group by tgcol2' % (mt)) + tdLog.info('select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001 and tgcol1 = 1 and tgcol2 = 1 and tgcol3 = 1 group by tgcol2' % (mt)) tdSql.query( - 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m and tgcol1 = 1 and tgcol2 = 1 and tgcol3 = 1 group by tgcol2' % + 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001 and tgcol1 = 1 and tgcol2 = 1 and tgcol3 = 1 group by tgcol2' % (mt)) # TSIM: print $data00 $data01 $data02 $data03 $data04 $data05 $data06 tdLog.info('$data00 $data01 $data02 $data03 $data04 $data05 $data06') @@ -2593,11 +2591,11 @@ class TDTestCase: # TSIM: endi # TSIM: # TSIM: sql select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), - # max(tbcol), first(tbcol), last(tbcol) from $mt where ts < now + 4m + # max(tbcol), first(tbcol), last(tbcol) from $mt where ts < 1605045600000 + 240001 # and tgcol1 = 1 and tgcol2 = 1 and tgcol3 = 1 and tgcol4 = 1 group by # tgcol2 - tdLog.info('select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m and tgcol1 = 1 and tgcol2 = 1 and tgcol3 = 1 and tgcol4 = 1 group by tgcol2' % (mt)) - tdSql.query('select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m and tgcol1 = 1 and tgcol2 = 1 and tgcol3 = 1 and tgcol4 = 1 group by tgcol2' % (mt)) + tdLog.info('select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001 and tgcol1 = 1 and tgcol2 = 1 and tgcol3 = 1 and tgcol4 = 1 group by tgcol2' % (mt)) + tdSql.query('select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001 and tgcol1 = 1 and tgcol2 = 1 and tgcol3 = 1 and tgcol4 = 1 group by tgcol2' % (mt)) # TSIM: print $data00 $data01 $data02 $data03 $data04 $data05 $data06 tdLog.info('$data00 $data01 $data02 $data03 $data04 $data05 $data06') # TSIM: if $data00 != 25 then @@ -2607,11 +2605,11 @@ class TDTestCase: # TSIM: endi # TSIM: # TSIM: sql select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), - # max(tbcol), first(tbcol), last(tbcol) from $mt where ts < now + 4m + # max(tbcol), first(tbcol), last(tbcol) from $mt where ts < 1605045600000 + 240001 # and tgcol1 = 1 and tgcol2 = 1 and tgcol3 = 1 and tgcol4 = 1 and # tgcol5 = 1 group by tgcol2 - tdLog.info('select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m and tgcol1 = 1 and tgcol2 = 1 and tgcol3 = 1 and tgcol4 = 1 and tgcol5 = 1 group by tgcol2' % (mt)) - tdSql.query('select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m and tgcol1 = 1 and tgcol2 = 1 and tgcol3 = 1 and tgcol4 = 1 and tgcol5 = 1 group by tgcol2' % (mt)) + tdLog.info('select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001 and tgcol1 = 1 and tgcol2 = 1 and tgcol3 = 1 and tgcol4 = 1 and tgcol5 = 1 group by tgcol2' % (mt)) + tdSql.query('select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001 and tgcol1 = 1 and tgcol2 = 1 and tgcol3 = 1 and tgcol4 = 1 and tgcol5 = 1 group by tgcol2' % (mt)) # TSIM: print $data00 $data01 $data02 $data03 $data04 $data05 $data06 tdLog.info('$data00 $data01 $data02 $data03 $data04 $data05 $data06') # TSIM: if $data00 != 25 then @@ -2621,11 +2619,11 @@ class TDTestCase: # TSIM: endi # TSIM: # TSIM: sql select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), - # max(tbcol), first(tbcol), last(tbcol) from $mt where ts < now + 4m + # max(tbcol), first(tbcol), last(tbcol) from $mt where ts < 1605045600000 + 240001 # and tgcol1 = 1 and tgcol2 = 1 and tgcol3 = 1 and tgcol4 = 1 and # tgcol5 = 1 and tgcol6 = 1 group by tgcol2 - tdLog.info('select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m and tgcol1 = 1 and tgcol2 = 1 and tgcol3 = 1 and tgcol4 = 1 and tgcol5 = 1 and tgcol6 = 1 group by tgcol2' % (mt)) - tdSql.query('select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m and tgcol1 = 1 and tgcol2 = 1 and tgcol3 = 1 and tgcol4 = 1 and tgcol5 = 1 and tgcol6 = 1 group by tgcol2' % (mt)) + tdLog.info('select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001 and tgcol1 = 1 and tgcol2 = 1 and tgcol3 = 1 and tgcol4 = 1 and tgcol5 = 1 and tgcol6 = 1 group by tgcol2' % (mt)) + tdSql.query('select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001 and tgcol1 = 1 and tgcol2 = 1 and tgcol3 = 1 and tgcol4 = 1 and tgcol5 = 1 and tgcol6 = 1 group by tgcol2' % (mt)) # TSIM: print $data00 $data01 $data02 $data03 $data04 $data05 $data06 tdLog.info('$data00 $data01 $data02 $data03 $data04 $data05 $data06') # TSIM: if $data00 != 25 then diff --git a/tests/pytest/tag_lite/bigint.py b/tests/pytest/tag_lite/bigint.py index f83961aaad401f337a1dc4f0d305391f22006b9a..733d30983d07ab9e2c30076b76084edb354e289f 100644 --- a/tests/pytest/tag_lite/bigint.py +++ b/tests/pytest/tag_lite/bigint.py @@ -72,14 +72,13 @@ class TDTestCase: # TSIM: while $x < $rowNum while (x < rowNum): # TSIM: $ms = $x . m - ms = "%dm" % x - # TSIM: sql insert into $tb values (now + $ms , $x ) + ms = x * 60000 tdLog.info( - 'insert into %s values (now + %s , %d )' % - (tb, ms, x)) + "insert into %s values (%d, %d)" % + (tb, 1605045600000 + ms, x)) tdSql.execute( - 'insert into %s values (now + %s , %d )' % - (tb, ms, x)) + "insert into %s values (%d, %d)" % + (tb, 1605045600000 + ms, x)) # TSIM: $x = $x + 1 x = x + 1 # TSIM: endw @@ -98,14 +97,13 @@ class TDTestCase: # TSIM: while $x < $rowNum while (x < rowNum): # TSIM: $ms = $x . m - ms = "%dm" % x - # TSIM: sql insert into $tb values (now + $ms , $x ) + ms = x * 60000 tdLog.info( - 'insert into %s values (now + %s , %d )' % - (tb, ms, x)) + "insert into %s values (%d, %d)" % + (tb, 1605045600000 + ms, x)) tdSql.execute( - 'insert into %s values (now + %s , %d )' % - (tb, ms, x)) + "insert into %s values (%d, %d)" % + (tb, 1605045600000 + ms, x)) # TSIM: $x = $x + 1 x = x + 1 # TSIM: endw @@ -124,56 +122,56 @@ class TDTestCase: tdSql.checkRows(rowNum) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $tb where ts < now + 4m - tdLog.info('select * from %s where ts < now + 4m' % (tb)) - tdSql.query('select * from %s where ts < now + 4m' % (tb)) + # TSIM: sql select * from $tb where ts < 1605045600000 + 240001 + tdLog.info('select * from %s where ts < 1605045600000 + 240001' % (tb)) + tdSql.query('select * from %s where ts < 1605045600000 + 240001' % (tb)) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') tdSql.checkRows(5) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $tb where ts <= now + 4m - tdLog.info('select * from %s where ts <= now + 4m' % (tb)) - tdSql.query('select * from %s where ts <= now + 4m' % (tb)) + # TSIM: sql select * from $tb where ts <= 1605045600000 + 240001 + tdLog.info('select * from %s where ts <= 1605045600000 + 240001' % (tb)) + tdSql.query('select * from %s where ts <= 1605045600000 + 240001' % (tb)) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') tdSql.checkRows(5) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $tb where ts > now + 4m - tdLog.info('select * from %s where ts > now + 4m' % (tb)) - tdSql.query('select * from %s where ts > now + 4m' % (tb)) + # TSIM: sql select * from $tb where ts > 1605045600000 + 240001 + tdLog.info('select * from %s where ts > 1605045600000 + 240001' % (tb)) + tdSql.query('select * from %s where ts > 1605045600000 + 240001' % (tb)) # TSIM: if $rows != 15 then tdLog.info('tdSql.checkRow(15)') tdSql.checkRows(15) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $tb where ts >= now + 4m - tdLog.info('select * from %s where ts >= now + 4m' % (tb)) - tdSql.query('select * from %s where ts >= now + 4m' % (tb)) + # TSIM: sql select * from $tb where ts >= 1605045600000 + 240001 + tdLog.info('select * from %s where ts >= 1605045600000 + 240001' % (tb)) + tdSql.query('select * from %s where ts >= 1605045600000 + 240001' % (tb)) # TSIM: if $rows != 15 then tdLog.info('tdSql.checkRow(15)') tdSql.checkRows(15) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $tb where ts > now + 4m and ts < now + 5m + # TSIM: sql select * from $tb where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 tdLog.info( - 'select * from %s where ts > now + 4m and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001' % (tb)) tdSql.query( - 'select * from %s where ts > now + 4m and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001' % (tb)) # TSIM: if $rows != 1 then tdLog.info('tdSql.checkRow(1)') tdSql.checkRows(1) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $tb where ts < now + 4m and ts > now + 5m + # TSIM: sql select * from $tb where ts < 1605045600000 + 240001 and ts > 1605045600000 + 300001 tdLog.info( - 'select * from %s where ts < now + 4m and ts > now + 5m' % + 'select * from %s where ts < 1605045600000 + 240001 and ts > 1605045600000 + 300001' % (tb)) tdSql.query( - 'select * from %s where ts < now + 4m and ts > now + 5m' % + 'select * from %s where ts < 1605045600000 + 240001 and ts > 1605045600000 + 300001' % (tb)) # TSIM: if $rows != 0 then tdLog.info('tdSql.checkRow(0)') @@ -190,25 +188,25 @@ class TDTestCase: tdSql.checkRows(0) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $tb where ts > now + 4m and ts < now + 3m + # TSIM: sql select * from $tb where ts > 1605045600000 + 240001 and ts < 1605045600000 + 180001 tdLog.info( - 'select * from %s where ts > now + 4m and ts < now + 3m' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 180001' % (tb)) tdSql.query( - 'select * from %s where ts > now + 4m and ts < now + 3m' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 180001' % (tb)) # TSIM: if $rows != 0 then tdLog.info('tdSql.checkRow(0)') tdSql.checkRows(0) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $tb where ts > now + 4m and ts > now + 5m and - # ts < now + 6m + # TSIM: sql select * from $tb where ts > 1605045600000 + 240001 and ts > 1605045600000 + 300001 and + # ts < 1605045600000 + 360001 tdLog.info( - 'select * from %s where ts > now + 4m and ts > now + 5m and ts < now + 6m' % + 'select * from %s where ts > 1605045600000 + 240001 and ts > 1605045600000 + 300001 and ts < 1605045600000 + 360001' % (tb)) tdSql.query( - 'select * from %s where ts > now + 4m and ts > now + 5m and ts < now + 6m' % + 'select * from %s where ts > 1605045600000 + 240001 and ts > 1605045600000 + 300001 and ts < 1605045600000 + 360001' % (tb)) # TSIM: if $rows != 1 then tdLog.info('tdSql.checkRow(1)') @@ -227,36 +225,36 @@ class TDTestCase: # TSIM: return -1 # TSIM: endi # TSIM: - # TSIM: sql select * from $mt where ts < now + 4m - tdLog.info('select * from %s where ts < now + 4m' % (mt)) - tdSql.query('select * from %s where ts < now + 4m' % (mt)) + # TSIM: sql select * from $mt where ts < 1605045600000 + 240001 + tdLog.info('select * from %s where ts < 1605045600000 + 240001' % (mt)) + tdSql.query('select * from %s where ts < 1605045600000 + 240001' % (mt)) # TSIM: if $rows != 50 then tdLog.info('tdSql.checkRow(50)') tdSql.checkRows(50) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m - tdLog.info('select * from %s where ts > now + 4m' % (mt)) - tdSql.query('select * from %s where ts > now + 4m' % (mt)) + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 + tdLog.info('select * from %s where ts > 1605045600000 + 240001' % (mt)) + tdSql.query('select * from %s where ts > 1605045600000 + 240001' % (mt)) # TSIM: if $rows != 150 then tdLog.info('tdSql.checkRow(150)') tdSql.checkRows(150) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts = now + 4m - tdLog.info('select * from %s where ts = now + 4m' % (mt)) - tdSql.query('select * from %s where ts = now + 4m' % (mt)) + # TSIM: sql select * from $mt where ts = 1605045600000 + 240001 + tdLog.info('select * from %s where ts = 1605045600000 + 240001' % (mt)) + tdSql.query('select * from %s where ts = 1605045600000 + 240001' % (mt)) # TSIM: if $rows != 0 then tdLog.info('tdSql.checkRow(0)') tdSql.checkRows(0) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and ts < now + 5m + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 tdLog.info( - 'select * from %s where ts > now + 4m and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001' % (mt)) # TSIM: if $rows != 10 then tdLog.info('tdSql.checkRow(10)') @@ -333,94 +331,94 @@ class TDTestCase: # TSIM: # TSIM: print =============== step5 tdLog.info('=============== step5') - # TSIM: sql select * from $mt where ts > now + 4m and tgcol = 1 - tdLog.info('select * from %s where ts > now + 4m and tgcol = 1' % (mt)) + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol = 1 + tdLog.info('select * from %s where ts > 1605045600000 + 240001 and tgcol = 1' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol = 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol = 1' % (mt)) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and tgcol <> 1 + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol <> 1 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol <> 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol <> 1' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol <> 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol <> 1' % (mt)) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts < now + 4m and tgcol = 0 - tdLog.info('select * from %s where ts < now + 4m and tgcol = 0' % (mt)) + # TSIM: sql select * from $mt where ts < 1605045600000 + 240001 and tgcol = 0 + tdLog.info('select * from %s where ts < 1605045600000 + 240001 and tgcol = 0' % (mt)) tdSql.query( - 'select * from %s where ts < now + 4m and tgcol = 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol = 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts < now + 4m and tgcol <> 0 + # TSIM: sql select * from $mt where ts < 1605045600000 + 240001 and tgcol <> 0 tdLog.info( - 'select * from %s where ts < now + 4m and tgcol <> 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol <> 0' % (mt)) tdSql.query( - 'select * from %s where ts < now + 4m and tgcol <> 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol <> 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts <= now + 4m and tgcol = 0 + # TSIM: sql select * from $mt where ts <= 1605045600000 + 240001 and tgcol = 0 tdLog.info( - 'select * from %s where ts <= now + 4m and tgcol = 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol = 0' % (mt)) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol = 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol = 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts <= now + 4m and tgcol <> 0 + # TSIM: sql select * from $mt where ts <= 1605045600000 + 240001 and tgcol <> 0 tdLog.info( - 'select * from %s where ts <= now + 4m and tgcol <> 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol <> 0' % (mt)) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol <> 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol <> 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and ts < now + 5m and + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and # tgcol <> 0 tdLog.info( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol <> 0' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol <> 0' % (mt)) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') tdSql.checkRows(5) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and tgcol <> 0 and ts - # < now + 5m + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol <> 0 and ts + # < 1605045600000 + 300001 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol <> 0 and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol <> 0 and ts < 1605045600000 + 300001' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol <> 0 and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol <> 0 and ts < 1605045600000 + 300001' % (mt)) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') @@ -467,12 +465,12 @@ class TDTestCase: # TSIM: print =============== step8 tdLog.info('=============== step8') # TSIM: sql select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), - # max(tbcol), first(tbcol), last(tbcol) from $mt where ts < now + 4m + # max(tbcol), first(tbcol), last(tbcol) from $mt where ts < 1605045600000 + 240001 tdLog.info( - 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m' % + 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001' % (mt)) tdSql.query( - 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m' % + 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001' % (mt)) # TSIM: print $data00 $data01 $data02 $data03 $data04 $data05 $data06 tdLog.info('$data00 $data01 $data02 $data03 $data04 $data05 $data06') @@ -522,13 +520,13 @@ class TDTestCase: # TSIM: print =============== step11 tdLog.info('=============== step11') # TSIM: sql select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), - # max(tbcol), first(tbcol), last(tbcol) from $mt where ts < now + 4m + # max(tbcol), first(tbcol), last(tbcol) from $mt where ts < 1605045600000 + 240001 # group by tgcol tdLog.info( - 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m group by tgcol' % + 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001 group by tgcol' % (mt)) tdSql.query( - 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m group by tgcol' % + 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001 group by tgcol' % (mt)) # TSIM: print $data00 $data01 $data02 $data03 $data04 $data05 $data06 tdLog.info('$data00 $data01 $data02 $data03 $data04 $data05 $data06') diff --git a/tests/pytest/tag_lite/binary.py b/tests/pytest/tag_lite/binary.py index 4cbae63bec1ec6a885f015a69bb4192e93cc9629..3825c6637f9357e00bc8491be1d8c2960dde2109 100644 --- a/tests/pytest/tag_lite/binary.py +++ b/tests/pytest/tag_lite/binary.py @@ -72,14 +72,13 @@ class TDTestCase: # TSIM: while $x < $rowNum while (x < rowNum): # TSIM: $ms = $x . m - ms = "%dm" % x - # TSIM: sql insert into $tb values (now + $ms , $x ) + ms = x * 60000 tdLog.info( - 'insert into %s values (now + %s , %d )' % - (tb, ms, x)) + "insert into %s values (%d, %d)" % + (tb, 1605045600000 + ms, x)) tdSql.execute( - 'insert into %s values (now + %s , %d )' % - (tb, ms, x)) + "insert into %s values (%d, %d)" % + (tb, 1605045600000 + ms, x)) # TSIM: $x = $x + 1 x = x + 1 # TSIM: endw @@ -98,14 +97,13 @@ class TDTestCase: # TSIM: while $x < $rowNum while (x < rowNum): # TSIM: $ms = $x . m - ms = "%dm" % x - # TSIM: sql insert into $tb values (now + $ms , $x ) + ms = x * 60000 tdLog.info( - 'insert into %s values (now + %s , %d )' % - (tb, ms, x)) + "insert into %s values (%d, %d)" % + (tb, 1605045600000 + ms, x)) tdSql.execute( - 'insert into %s values (now + %s , %d )' % - (tb, ms, x)) + "insert into %s values (%d, %d)" % + (tb, 1605045600000 + ms, x)) # TSIM: $x = $x + 1 x = x + 1 # TSIM: endw @@ -124,56 +122,56 @@ class TDTestCase: tdSql.checkRows(rowNum) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $tb where ts < now + 4m - tdLog.info('select * from %s where ts < now + 4m' % (tb)) - tdSql.query('select * from %s where ts < now + 4m' % (tb)) + # TSIM: sql select * from $tb where ts < 1605045600000 + 240001 + tdLog.info('select * from %s where ts < 1605045600000 + 240001' % (tb)) + tdSql.query('select * from %s where ts < 1605045600000 + 240001' % (tb)) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') tdSql.checkRows(5) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $tb where ts <= now + 4m - tdLog.info('select * from %s where ts <= now + 4m' % (tb)) - tdSql.query('select * from %s where ts <= now + 4m' % (tb)) + # TSIM: sql select * from $tb where ts <= 1605045600000 + 240001 + tdLog.info('select * from %s where ts <= 1605045600000 + 240001' % (tb)) + tdSql.query('select * from %s where ts <= 1605045600000 + 240001' % (tb)) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') tdSql.checkRows(5) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $tb where ts > now + 4m - tdLog.info('select * from %s where ts > now + 4m' % (tb)) - tdSql.query('select * from %s where ts > now + 4m' % (tb)) + # TSIM: sql select * from $tb where ts > 1605045600000 + 240001 + tdLog.info('select * from %s where ts > 1605045600000 + 240001' % (tb)) + tdSql.query('select * from %s where ts > 1605045600000 + 240001' % (tb)) # TSIM: if $rows != 15 then tdLog.info('tdSql.checkRow(15)') tdSql.checkRows(15) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $tb where ts >= now + 4m - tdLog.info('select * from %s where ts >= now + 4m' % (tb)) - tdSql.query('select * from %s where ts >= now + 4m' % (tb)) + # TSIM: sql select * from $tb where ts >= 1605045600000 + 240001 + tdLog.info('select * from %s where ts >= 1605045600000 + 240001' % (tb)) + tdSql.query('select * from %s where ts >= 1605045600000 + 240001' % (tb)) # TSIM: if $rows != 15 then tdLog.info('tdSql.checkRow(15)') tdSql.checkRows(15) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $tb where ts > now + 4m and ts < now + 5m + # TSIM: sql select * from $tb where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 tdLog.info( - 'select * from %s where ts > now + 4m and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001' % (tb)) tdSql.query( - 'select * from %s where ts > now + 4m and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001' % (tb)) # TSIM: if $rows != 1 then tdLog.info('tdSql.checkRow(1)') tdSql.checkRows(1) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $tb where ts < now + 4m and ts > now + 5m + # TSIM: sql select * from $tb where ts < 1605045600000 + 240001 and ts > 1605045600000 + 300001 tdLog.info( - 'select * from %s where ts < now + 4m and ts > now + 5m' % + 'select * from %s where ts < 1605045600000 + 240001 and ts > 1605045600000 + 300001' % (tb)) tdSql.query( - 'select * from %s where ts < now + 4m and ts > now + 5m' % + 'select * from %s where ts < 1605045600000 + 240001 and ts > 1605045600000 + 300001' % (tb)) # TSIM: if $rows != 0 then tdLog.info('tdSql.checkRow(0)') @@ -190,25 +188,25 @@ class TDTestCase: tdSql.checkRows(0) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $tb where ts > now + 4m and ts < now + 3m + # TSIM: sql select * from $tb where ts > 1605045600000 + 240001 and ts < 1605045600000 + 180001 tdLog.info( - 'select * from %s where ts > now + 4m and ts < now + 3m' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 180001' % (tb)) tdSql.query( - 'select * from %s where ts > now + 4m and ts < now + 3m' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 180001' % (tb)) # TSIM: if $rows != 0 then tdLog.info('tdSql.checkRow(0)') tdSql.checkRows(0) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $tb where ts > now + 4m and ts > now + 5m and - # ts < now + 6m + # TSIM: sql select * from $tb where ts > 1605045600000 + 240001 and ts > 1605045600000 + 300001 and + # ts < 1605045600000 + 360001 tdLog.info( - 'select * from %s where ts > now + 4m and ts > now + 5m and ts < now + 6m' % + 'select * from %s where ts > 1605045600000 + 240001 and ts > 1605045600000 + 300001 and ts < 1605045600000 + 360001' % (tb)) tdSql.query( - 'select * from %s where ts > now + 4m and ts > now + 5m and ts < now + 6m' % + 'select * from %s where ts > 1605045600000 + 240001 and ts > 1605045600000 + 300001 and ts < 1605045600000 + 360001' % (tb)) # TSIM: if $rows != 1 then tdLog.info('tdSql.checkRow(1)') @@ -227,36 +225,36 @@ class TDTestCase: # TSIM: return -1 # TSIM: endi # TSIM: - # TSIM: sql select * from $mt where ts < now + 4m - tdLog.info('select * from %s where ts < now + 4m' % (mt)) - tdSql.query('select * from %s where ts < now + 4m' % (mt)) + # TSIM: sql select * from $mt where ts < 1605045600000 + 240001 + tdLog.info('select * from %s where ts < 1605045600000 + 240001' % (mt)) + tdSql.query('select * from %s where ts < 1605045600000 + 240001' % (mt)) # TSIM: if $rows != 50 then tdLog.info('tdSql.checkRow(50)') tdSql.checkRows(50) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m - tdLog.info('select * from %s where ts > now + 4m' % (mt)) - tdSql.query('select * from %s where ts > now + 4m' % (mt)) + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 + tdLog.info('select * from %s where ts > 1605045600000 + 240001' % (mt)) + tdSql.query('select * from %s where ts > 1605045600000 + 240001' % (mt)) # TSIM: if $rows != 150 then tdLog.info('tdSql.checkRow(150)') tdSql.checkRows(150) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts = now + 4m - tdLog.info('select * from %s where ts = now + 4m' % (mt)) - tdSql.query('select * from %s where ts = now + 4m' % (mt)) + # TSIM: sql select * from $mt where ts = 1605045600000 + 240001 + tdLog.info('select * from %s where ts = 1605045600000 + 240001' % (mt)) + tdSql.query('select * from %s where ts = 1605045600000 + 240001' % (mt)) # TSIM: if $rows != 0 then tdLog.info('tdSql.checkRow(0)') tdSql.checkRows(0) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and ts < now + 5m + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 tdLog.info( - 'select * from %s where ts > now + 4m and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001' % (mt)) # TSIM: if $rows != 10 then tdLog.info('tdSql.checkRow(10)') @@ -333,98 +331,98 @@ class TDTestCase: # TSIM: # TSIM: print =============== step5 tdLog.info('=============== step5') - # TSIM: sql select * from $mt where ts > now + 4m and tgcol = '1' + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol = '1' tdLog.info( - 'select * from %s where ts > now + 4m and tgcol = "1"' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol = "1"' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol = "1"' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol = "1"' % (mt)) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and tgcol <> '1' + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol <> '1' tdLog.info( - 'select * from %s where ts > now + 4m and tgcol <> "1"' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol <> "1"' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol <> "1"' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol <> "1"' % (mt)) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts < now + 4m and tgcol = '0' + # TSIM: sql select * from $mt where ts < 1605045600000 + 240001 and tgcol = '0' tdLog.info( - 'select * from %s where ts < now + 4m and tgcol = "0"' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol = "0"' % (mt)) tdSql.query( - 'select * from %s where ts < now + 4m and tgcol = "0"' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol = "0"' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts < now + 4m and tgcol <> '0' + # TSIM: sql select * from $mt where ts < 1605045600000 + 240001 and tgcol <> '0' tdLog.info( - 'select * from %s where ts < now + 4m and tgcol <> "0"' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol <> "0"' % (mt)) tdSql.query( - 'select * from %s where ts < now + 4m and tgcol <> "0"' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol <> "0"' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts <= now + 4m and tgcol = '0' + # TSIM: sql select * from $mt where ts <= 1605045600000 + 240001 and tgcol = '0' tdLog.info( - 'select * from %s where ts <= now + 4m and tgcol = "0"' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol = "0"' % (mt)) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol = "0"' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol = "0"' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts <= now + 4m and tgcol <> '0' + # TSIM: sql select * from $mt where ts <= 1605045600000 + 240001 and tgcol <> '0' tdLog.info( - 'select * from %s where ts <= now + 4m and tgcol <> "0"' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol <> "0"' % (mt)) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol <> "0"' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol <> "0"' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and ts < now + 5m and + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and # tgcol <> '0' tdLog.info( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol <> "0"' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol <> "0"' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol <> "0"' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol <> "0"' % (mt)) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') tdSql.checkRows(5) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and tgcol <> '0' and - # ts < now + 5m + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol <> '0' and + # ts < 1605045600000 + 300001 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol <> "0" and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol <> "0" and ts < 1605045600000 + 300001' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol <> "0" and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol <> "0" and ts < 1605045600000 + 300001' % (mt)) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') @@ -471,12 +469,12 @@ class TDTestCase: # TSIM: print =============== step8 tdLog.info('=============== step8') # TSIM: sql select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), - # max(tbcol), first(tbcol), last(tbcol) from $mt where ts < now + 4m + # max(tbcol), first(tbcol), last(tbcol) from $mt where ts < 1605045600000 + 240001 tdLog.info( - 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m' % + 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001' % (mt)) tdSql.query( - 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m' % + 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001' % (mt)) # TSIM: print $data00 $data01 $data02 $data03 $data04 $data05 $data06 tdLog.info('$data00 $data01 $data02 $data03 $data04 $data05 $data06') @@ -526,13 +524,13 @@ class TDTestCase: # TSIM: print =============== step11 tdLog.info('=============== step11') # TSIM: sql select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), - # max(tbcol), first(tbcol), last(tbcol) from $mt where ts < now + 4m + # max(tbcol), first(tbcol), last(tbcol) from $mt where ts < 1605045600000 + 240001 # group by tgcol tdLog.info( - 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m group by tgcol' % + 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001 group by tgcol' % (mt)) tdSql.query( - 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m group by tgcol' % + 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001 group by tgcol' % (mt)) # TSIM: print $data00 $data01 $data02 $data03 $data04 $data05 $data06 tdLog.info('$data00 $data01 $data02 $data03 $data04 $data05 $data06') diff --git a/tests/pytest/tag_lite/binary_binary.py b/tests/pytest/tag_lite/binary_binary.py index 9c789eafd655d76362d5bc4729fd4e5da8de2156..2a76238f595ce5b079f0d36453197875d214145c 100644 --- a/tests/pytest/tag_lite/binary_binary.py +++ b/tests/pytest/tag_lite/binary_binary.py @@ -74,14 +74,13 @@ class TDTestCase: # TSIM: while $x < $rowNum while (x < rowNum): # TSIM: $ms = $x . m - ms = "%dm" % x - # TSIM: sql insert into $tb values (now + $ms , $x ) + ms = x * 60000 tdLog.info( - 'insert into %s values (now + %s , %d )' % - (tb, ms, x)) + "insert into %s values (%d, %d)" % + (tb, 1605045600000 + ms, x)) tdSql.execute( - 'insert into %s values (now + %s , %d )' % - (tb, ms, x)) + "insert into %s values (%d, %d)" % + (tb, 1605045600000 + ms, x)) # TSIM: $x = $x + 1 x = x + 1 # TSIM: endw @@ -102,14 +101,13 @@ class TDTestCase: # TSIM: while $x < $rowNum while (x < rowNum): # TSIM: $ms = $x . m - ms = "%dm" % x - # TSIM: sql insert into $tb values (now + $ms , $x ) + ms = x * 60000 tdLog.info( - 'insert into %s values (now + %s , %d )' % - (tb, ms, x)) + "insert into %s values (%d, %d)" % + (tb, 1605045600000 + ms, x)) tdSql.execute( - 'insert into %s values (now + %s , %d )' % - (tb, ms, x)) + "insert into %s values (%d, %d)" % + (tb, 1605045600000 + ms, x)) # TSIM: $x = $x + 1 x = x + 1 # TSIM: endw @@ -128,36 +126,36 @@ class TDTestCase: # TSIM: return -1 # TSIM: endi # TSIM: - # TSIM: sql select * from $mt where ts < now + 4m - tdLog.info('select * from %s where ts < now + 4m' % (mt)) - tdSql.query('select * from %s where ts < now + 4m' % (mt)) + # TSIM: sql select * from $mt where ts < 1605045600000 + 240001 + tdLog.info('select * from %s where ts < 1605045600000 + 240001' % (mt)) + tdSql.query('select * from %s where ts < 1605045600000 + 240001' % (mt)) # TSIM: if $rows != 50 then tdLog.info('tdSql.checkRow(50)') tdSql.checkRows(50) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m - tdLog.info('select * from %s where ts > now + 4m' % (mt)) - tdSql.query('select * from %s where ts > now + 4m' % (mt)) + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 + tdLog.info('select * from %s where ts > 1605045600000 + 240001' % (mt)) + tdSql.query('select * from %s where ts > 1605045600000 + 240001' % (mt)) # TSIM: if $rows != 150 then tdLog.info('tdSql.checkRow(150)') tdSql.checkRows(150) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts = now + 4m - tdLog.info('select * from %s where ts = now + 4m' % (mt)) - tdSql.query('select * from %s where ts = now + 4m' % (mt)) + # TSIM: sql select * from $mt where ts = 1605045600000 + 240001 + tdLog.info('select * from %s where ts = 1605045600000 + 240001' % (mt)) + tdSql.query('select * from %s where ts = 1605045600000 + 240001' % (mt)) # TSIM: if $rows != 0 then tdLog.info('tdSql.checkRow(0)') tdSql.checkRows(0) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and ts < now + 5m + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 tdLog.info( - 'select * from %s where ts > now + 4m and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001' % (mt)) # TSIM: if $rows != 10 then tdLog.info('tdSql.checkRow(10)') @@ -269,98 +267,98 @@ class TDTestCase: # TSIM: # TSIM: print =============== step5 tdLog.info('=============== step5') - # TSIM: sql select * from $mt where ts > now + 4m and tgcol = '1' + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol = '1' tdLog.info( - 'select * from %s where ts > now + 4m and tgcol = "1"' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol = "1"' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol = "1"' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol = "1"' % (mt)) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and tgcol <> '1' + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol <> '1' tdLog.info( - 'select * from %s where ts > now + 4m and tgcol <> "1"' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol <> "1"' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol <> "1"' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol <> "1"' % (mt)) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts < now + 4m and tgcol = '0' + # TSIM: sql select * from $mt where ts < 1605045600000 + 240001 and tgcol = '0' tdLog.info( - 'select * from %s where ts < now + 4m and tgcol = "0"' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol = "0"' % (mt)) tdSql.query( - 'select * from %s where ts < now + 4m and tgcol = "0"' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol = "0"' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts < now + 4m and tgcol <> '0' + # TSIM: sql select * from $mt where ts < 1605045600000 + 240001 and tgcol <> '0' tdLog.info( - 'select * from %s where ts < now + 4m and tgcol <> "0"' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol <> "0"' % (mt)) tdSql.query( - 'select * from %s where ts < now + 4m and tgcol <> "0"' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol <> "0"' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts <= now + 4m and tgcol = '0' + # TSIM: sql select * from $mt where ts <= 1605045600000 + 240001 and tgcol = '0' tdLog.info( - 'select * from %s where ts <= now + 4m and tgcol = "0"' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol = "0"' % (mt)) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol = "0"' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol = "0"' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts <= now + 4m and tgcol <> '0' + # TSIM: sql select * from $mt where ts <= 1605045600000 + 240001 and tgcol <> '0' tdLog.info( - 'select * from %s where ts <= now + 4m and tgcol <> "0"' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol <> "0"' % (mt)) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol <> "0"' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol <> "0"' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and ts < now + 5m and + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and # tgcol <> '0' tdLog.info( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol <> "0"' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol <> "0"' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol <> "0"' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol <> "0"' % (mt)) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') tdSql.checkRows(5) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and tgcol <> '0' and - # ts < now + 5m + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol <> '0' and + # ts < 1605045600000 + 300001 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol <> "0" and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol <> "0" and ts < 1605045600000 + 300001' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol <> "0" and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol <> "0" and ts < 1605045600000 + 300001' % (mt)) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') @@ -370,98 +368,98 @@ class TDTestCase: # TSIM: # TSIM: print =============== step6 tdLog.info('=============== step6') - # TSIM: sql select * from $mt where ts > now + 4m and tgcol2 = '1' + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol2 = '1' tdLog.info( - 'select * from %s where ts > now + 4m and tgcol2 = "1"' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol2 = "1"' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol2 = "1"' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol2 = "1"' % (mt)) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and tgcol2 <> '1' + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol2 <> '1' tdLog.info( - 'select * from %s where ts > now + 4m and tgcol2 <> "1"' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol2 <> "1"' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol2 <> "1"' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol2 <> "1"' % (mt)) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts < now + 4m and tgcol2 = '0' + # TSIM: sql select * from $mt where ts < 1605045600000 + 240001 and tgcol2 = '0' tdLog.info( - 'select * from %s where ts < now + 4m and tgcol2 = "0"' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol2 = "0"' % (mt)) tdSql.query( - 'select * from %s where ts < now + 4m and tgcol2 = "0"' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol2 = "0"' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts < now + 4m and tgcol2 <> '0' + # TSIM: sql select * from $mt where ts < 1605045600000 + 240001 and tgcol2 <> '0' tdLog.info( - 'select * from %s where ts < now + 4m and tgcol2 <> "0"' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol2 <> "0"' % (mt)) tdSql.query( - 'select * from %s where ts < now + 4m and tgcol2 <> "0"' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol2 <> "0"' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts <= now + 4m and tgcol2 = '0' + # TSIM: sql select * from $mt where ts <= 1605045600000 + 240001 and tgcol2 = '0' tdLog.info( - 'select * from %s where ts <= now + 4m and tgcol2 = "0"' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol2 = "0"' % (mt)) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol2 = "0"' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol2 = "0"' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts <= now + 4m and tgcol2 <> '0' + # TSIM: sql select * from $mt where ts <= 1605045600000 + 240001 and tgcol2 <> '0' tdLog.info( - 'select * from %s where ts <= now + 4m and tgcol2 <> "0"' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol2 <> "0"' % (mt)) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol2 <> "0"' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol2 <> "0"' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and ts < now + 5m and + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and # tgcol2 <> '0' tdLog.info( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol2 <> "0"' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol2 <> "0"' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol2 <> "0"' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol2 <> "0"' % (mt)) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') tdSql.checkRows(5) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and tgcol2 <> '0' and - # ts < now + 5m + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol2 <> '0' and + # ts < 1605045600000 + 300001 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol2 <> "0" and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol2 <> "0" and ts < 1605045600000 + 300001' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol2 <> "0" and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol2 <> "0" and ts < 1605045600000 + 300001' % (mt)) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') @@ -471,104 +469,104 @@ class TDTestCase: # TSIM: # TSIM: print =============== step7 tdLog.info('=============== step7') - # TSIM: sql select * from $mt where ts > now + 4m and tgcol2 = '1' and + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol2 = '1' and # tgcol = '1' tdLog.info( - 'select * from %s where ts > now + 4m and tgcol2 = "1" and tgcol = "1"' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol2 = "1" and tgcol = "1"' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol2 = "1" and tgcol = "1"' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol2 = "1" and tgcol = "1"' % (mt)) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and tgcol2 <> '1' and + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol2 <> '1' and # tgcol <> '1' tdLog.info( - 'select * from %s where ts > now + 4m and tgcol2 <> "1" and tgcol <> "1"' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol2 <> "1" and tgcol <> "1"' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol2 <> "1" and tgcol <> "1"' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol2 <> "1" and tgcol <> "1"' % (mt)) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts < now + 4m and tgcol2 = '0' and + # TSIM: sql select * from $mt where ts < 1605045600000 + 240001 and tgcol2 = '0' and # tgcol = '0' tdLog.info( - 'select * from %s where ts < now + 4m and tgcol2 = "0" and tgcol = "0"' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol2 = "0" and tgcol = "0"' % (mt)) tdSql.query( - 'select * from %s where ts < now + 4m and tgcol2 = "0" and tgcol = "0"' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol2 = "0" and tgcol = "0"' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts < now + 4m and tgcol2 <> '0' and + # TSIM: sql select * from $mt where ts < 1605045600000 + 240001 and tgcol2 <> '0' and # tgcol <> '0' tdLog.info( - 'select * from %s where ts < now + 4m and tgcol2 <> "0" and tgcol <> "0"' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol2 <> "0" and tgcol <> "0"' % (mt)) tdSql.query( - 'select * from %s where ts < now + 4m and tgcol2 <> "0" and tgcol <> "0"' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol2 <> "0" and tgcol <> "0"' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts <= now + 4m and tgcol2 = '0' and + # TSIM: sql select * from $mt where ts <= 1605045600000 + 240001 and tgcol2 = '0' and # tgcol = '0' tdLog.info( - 'select * from %s where ts <= now + 4m and tgcol2 = "0" and tgcol = "0"' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol2 = "0" and tgcol = "0"' % (mt)) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol2 = "0" and tgcol = "0"' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol2 = "0" and tgcol = "0"' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts <= now + 4m and tgcol2 <> '0' + # TSIM: sql select * from $mt where ts <= 1605045600000 + 240001 and tgcol2 <> '0' # and tgcol <> '0' tdLog.info( - 'select * from %s where ts <= now + 4m and tgcol2 <> "0" and tgcol <> "0"' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol2 <> "0" and tgcol <> "0"' % (mt)) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol2 <> "0" and tgcol <> "0"' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol2 <> "0" and tgcol <> "0"' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and ts < now + 5m and + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and # tgcol2 <> '0' and tgcol <> '0' tdLog.info( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol2 <> "0" and tgcol <> "0"' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol2 <> "0" and tgcol <> "0"' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol2 <> "0" and tgcol <> "0"' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol2 <> "0" and tgcol <> "0"' % (mt)) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') tdSql.checkRows(5) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and tgcol2 <> '0' and - # ts < now + 5m and ts < now + 5m and tgcol <> '0' + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol2 <> '0' and + # ts < 1605045600000 + 300001 and ts < 1605045600000 + 300001 and tgcol <> '0' tdLog.info( - 'select * from %s where ts > now + 4m and tgcol2 <> "0" and ts < now + 5m and ts < now + 5m and tgcol <> "0"' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol2 <> "0" and ts < 1605045600000 + 300001 and ts < 1605045600000 + 300001 and tgcol <> "0"' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol2 <> "0" and ts < now + 5m and ts < now + 5m and tgcol <> "0"' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol2 <> "0" and ts < 1605045600000 + 300001 and ts < 1605045600000 + 300001 and tgcol <> "0"' % (mt)) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') @@ -648,12 +646,12 @@ class TDTestCase: # TSIM: print =============== step10 tdLog.info('=============== step10') # TSIM: sql select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), - # max(tbcol), first(tbcol), last(tbcol) from $mt where ts < now + 4m + # max(tbcol), first(tbcol), last(tbcol) from $mt where ts < 1605045600000 + 240001 tdLog.info( - 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m' % + 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001' % (mt)) tdSql.query( - 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m' % + 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001' % (mt)) # TSIM: print $data00 $data01 $data02 $data03 $data04 $data05 $data06 tdLog.info('$data00 $data01 $data02 $data03 $data04 $data05 $data06') @@ -738,13 +736,13 @@ class TDTestCase: # TSIM: print =============== step13 tdLog.info('=============== step13') # TSIM: sql select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), - # max(tbcol), first(tbcol), last(tbcol) from $mt where ts < now + 4m + # max(tbcol), first(tbcol), last(tbcol) from $mt where ts < 1605045600000 + 240001 # group by tgcol tdLog.info( - 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m group by tgcol' % + 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001 group by tgcol' % (mt)) tdSql.query( - 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m group by tgcol' % + 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001 group by tgcol' % (mt)) # TSIM: print $data00 $data01 $data02 $data03 $data04 $data05 $data06 tdLog.info('$data00 $data01 $data02 $data03 $data04 $data05 $data06') diff --git a/tests/pytest/tag_lite/bool.py b/tests/pytest/tag_lite/bool.py index 6f2afd262509571187b83cba26d6773dbfde0464..11ce9eb7f8126e9d0adf4bedeaf055e3f4ab2c1b 100644 --- a/tests/pytest/tag_lite/bool.py +++ b/tests/pytest/tag_lite/bool.py @@ -71,14 +71,13 @@ class TDTestCase: # TSIM: while $x < $rowNum while (x < rowNum): # TSIM: $ms = $x . m - ms = "%dm" % x - # TSIM: sql insert into $tb values (now + $ms , $x ) + ms = x * 60000 tdLog.info( - 'insert into %s values (now + %s , %d )' % - (tb, ms, x)) + "insert into %s values (%d, %d)" % + (tb, 1605045600000 + ms, x)) tdSql.execute( - 'insert into %s values (now + %s , %d )' % - (tb, ms, x)) + "insert into %s values (%d, %d)" % + (tb, 1605045600000 + ms, x)) # TSIM: $x = $x + 1 x = x + 1 # TSIM: endw @@ -97,14 +96,13 @@ class TDTestCase: # TSIM: while $x < $rowNum while (x < rowNum): # TSIM: $ms = $x . m - ms = "%dm" % x - # TSIM: sql insert into $tb values (now + $ms , $x ) + ms = x * 60000 tdLog.info( - 'insert into %s values (now + %s , %d )' % - (tb, ms, x)) + "insert into %s values (%d, %d)" % + (tb, 1605045600000 + ms, x)) tdSql.execute( - 'insert into %s values (now + %s , %d )' % - (tb, ms, x)) + "insert into %s values (%d, %d)" % + (tb, 1605045600000 + ms, x)) # TSIM: $x = $x + 1 x = x + 1 # TSIM: endw @@ -123,81 +121,81 @@ class TDTestCase: tdSql.checkRows(rowNum) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $tb where ts < now + 4m - tdLog.info('select * from %s where ts < now + 4m' % (tb)) - tdSql.query('select * from %s where ts < now + 4m' % (tb)) + # TSIM: sql select * from $tb where ts < 1605045600000 + 240001 + tdLog.info('select * from %s where ts < 1605045600000 + 240001' % (tb)) + tdSql.query('select * from %s where ts < 1605045600000 + 240001' % (tb)) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') tdSql.checkRows(5) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $tb where ts <= now + 4m - tdLog.info('select * from %s where ts <= now + 4m' % (tb)) - tdSql.query('select * from %s where ts <= now + 4m' % (tb)) + # TSIM: sql select * from $tb where ts <= 1605045600000 + 240001 + tdLog.info('select * from %s where ts <= 1605045600000 + 240001' % (tb)) + tdSql.query('select * from %s where ts <= 1605045600000 + 240001' % (tb)) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') tdSql.checkRows(5) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $tb where ts > now + 4m - tdLog.info('select * from %s where ts > now + 4m' % (tb)) - tdSql.query('select * from %s where ts > now + 4m' % (tb)) + # TSIM: sql select * from $tb where ts > 1605045600000 + 240001 + tdLog.info('select * from %s where ts > 1605045600000 + 240001' % (tb)) + tdSql.query('select * from %s where ts > 1605045600000 + 240001' % (tb)) # TSIM: if $rows != 15 then tdLog.info('tdSql.checkRow(15)') tdSql.checkRows(15) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $tb where ts >= now + 4m - tdLog.info('select * from %s where ts >= now + 4m' % (tb)) - tdSql.query('select * from %s where ts >= now + 4m' % (tb)) + # TSIM: sql select * from $tb where ts >= 1605045600000 + 240001 + tdLog.info('select * from %s where ts >= 1605045600000 + 240001' % (tb)) + tdSql.query('select * from %s where ts >= 1605045600000 + 240001' % (tb)) # TSIM: if $rows != 15 then tdLog.info('tdSql.checkRow(15)') tdSql.checkRows(15) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $tb where ts > now + 4m and ts < now + 5m + # TSIM: sql select * from $tb where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 tdLog.info( - 'select * from %s where ts > now + 4m and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001' % (tb)) tdSql.query( - 'select * from %s where ts > now + 4m and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001' % (tb)) # TSIM: if $rows != 1 then tdLog.info('tdSql.checkRow(1)') tdSql.checkRows(1) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $tb where ts < now + 4m and ts > now + 5m + # TSIM: sql select * from $tb where ts < 1605045600000 + 240001 and ts > 1605045600000 + 300001 tdLog.info( - 'select * from %s where ts < now + 4m and ts > now + 5m' % + 'select * from %s where ts < 1605045600000 + 240001 and ts > 1605045600000 + 300001' % (tb)) tdSql.query( - 'select * from %s where ts < now + 4m and ts > now + 5m' % + 'select * from %s where ts < 1605045600000 + 240001 and ts > 1605045600000 + 300001' % (tb)) # TSIM: if $rows != 0 then tdLog.info('tdSql.checkRow(0)') tdSql.checkRows(0) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $tb where ts > now + 4m and ts < now + 3m + # TSIM: sql select * from $tb where ts > 1605045600000 + 240001 and ts < 1605045600000 + 180001 tdLog.info( - 'select * from %s where ts > now + 4m and ts < now + 3m' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 180001' % (tb)) tdSql.query( - 'select * from %s where ts > now + 4m and ts < now + 3m' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 180001' % (tb)) # TSIM: if $rows != 0 then tdLog.info('tdSql.checkRow(0)') tdSql.checkRows(0) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $tb where ts > now + 4m and ts > now + 5m and - # ts < now + 6m + # TSIM: sql select * from $tb where ts > 1605045600000 + 240001 and ts > 1605045600000 + 300001 and + # ts < 1605045600000 + 360001 tdLog.info( - 'select * from %s where ts > now + 4m and ts > now + 5m and ts < now + 6m' % + 'select * from %s where ts > 1605045600000 + 240001 and ts > 1605045600000 + 300001 and ts < 1605045600000 + 360001' % (tb)) tdSql.query( - 'select * from %s where ts > now + 4m and ts > now + 5m and ts < now + 6m' % + 'select * from %s where ts > 1605045600000 + 240001 and ts > 1605045600000 + 300001 and ts < 1605045600000 + 360001' % (tb)) # TSIM: if $rows != 1 then tdLog.info('tdSql.checkRow(1)') @@ -216,36 +214,36 @@ class TDTestCase: # TSIM: return -1 # TSIM: endi # TSIM: - # TSIM: sql select * from $mt where ts < now + 4m - tdLog.info('select * from %s where ts < now + 4m' % (mt)) - tdSql.query('select * from %s where ts < now + 4m' % (mt)) + # TSIM: sql select * from $mt where ts < 1605045600000 + 240001 + tdLog.info('select * from %s where ts < 1605045600000 + 240001' % (mt)) + tdSql.query('select * from %s where ts < 1605045600000 + 240001' % (mt)) # TSIM: if $rows != 50 then tdLog.info('tdSql.checkRow(50)') tdSql.checkRows(50) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m - tdLog.info('select * from %s where ts > now + 4m' % (mt)) - tdSql.query('select * from %s where ts > now + 4m' % (mt)) + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 + tdLog.info('select * from %s where ts > 1605045600000 + 240001' % (mt)) + tdSql.query('select * from %s where ts > 1605045600000 + 240001' % (mt)) # TSIM: if $rows != 150 then tdLog.info('tdSql.checkRow(150)') tdSql.checkRows(150) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts = now + 4m - tdLog.info('select * from %s where ts = now + 4m' % (mt)) - tdSql.query('select * from %s where ts = now + 4m' % (mt)) + # TSIM: sql select * from $mt where ts = 1605045600000 + 240001 + tdLog.info('select * from %s where ts = 1605045600000 + 240001' % (mt)) + tdSql.query('select * from %s where ts = 1605045600000 + 240001' % (mt)) # TSIM: if $rows != 0 then tdLog.info('tdSql.checkRow(0)') tdSql.checkRows(0) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and ts < now + 5m + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 tdLog.info( - 'select * from %s where ts > now + 4m and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001' % (mt)) # TSIM: if $rows != 10 then tdLog.info('tdSql.checkRow(10)') @@ -324,98 +322,98 @@ class TDTestCase: # TSIM: # TSIM: print =============== step5 tdLog.info('=============== step5') - # TSIM: sql select * from $mt where ts > now + 4m and tgcol = true + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol = true tdLog.info( - 'select * from %s where ts > now + 4m and tgcol = true' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol = true' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol = true' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol = true' % (mt)) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and tgcol <> true + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol <> true tdLog.info( - 'select * from %s where ts > now + 4m and tgcol <> true' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol <> true' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol <> true' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol <> true' % (mt)) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts < now + 4m and tgcol = false + # TSIM: sql select * from $mt where ts < 1605045600000 + 240001 and tgcol = false tdLog.info( - 'select * from %s where ts < now + 4m and tgcol = false' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol = false' % (mt)) tdSql.query( - 'select * from %s where ts < now + 4m and tgcol = false' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol = false' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts < now + 4m and tgcol <> false + # TSIM: sql select * from $mt where ts < 1605045600000 + 240001 and tgcol <> false tdLog.info( - 'select * from %s where ts < now + 4m and tgcol <> false' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol <> false' % (mt)) tdSql.query( - 'select * from %s where ts < now + 4m and tgcol <> false' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol <> false' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts <= now + 4m and tgcol = false + # TSIM: sql select * from $mt where ts <= 1605045600000 + 240001 and tgcol = false tdLog.info( - 'select * from %s where ts <= now + 4m and tgcol = false' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol = false' % (mt)) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol = false' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol = false' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts <= now + 4m and tgcol <> false + # TSIM: sql select * from $mt where ts <= 1605045600000 + 240001 and tgcol <> false tdLog.info( - 'select * from %s where ts <= now + 4m and tgcol <> false' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol <> false' % (mt)) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol <> false' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol <> false' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and ts < now + 5m and + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and # tgcol <> false tdLog.info( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol <> false' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol <> false' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol <> false' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol <> false' % (mt)) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') tdSql.checkRows(5) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and tgcol <> false - # and ts < now + 5m + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol <> false + # and ts < 1605045600000 + 300001 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol <> false and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol <> false and ts < 1605045600000 + 300001' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol <> false and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol <> false and ts < 1605045600000 + 300001' % (mt)) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') @@ -462,12 +460,12 @@ class TDTestCase: # TSIM: print =============== step8 tdLog.info('=============== step8') # TSIM: sql select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), - # max(tbcol), first(tbcol), last(tbcol) from $mt where ts < now + 4m + # max(tbcol), first(tbcol), last(tbcol) from $mt where ts < 1605045600000 + 240001 tdLog.info( - 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m' % + 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001' % (mt)) tdSql.query( - 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m' % + 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001' % (mt)) # TSIM: print $data00 $data01 $data02 $data03 $data04 $data05 $data06 tdLog.info('$data00 $data01 $data02 $data03 $data04 $data05 $data06') @@ -517,13 +515,13 @@ class TDTestCase: # TSIM: print =============== step11 tdLog.info('=============== step11') # TSIM: sql select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), - # max(tbcol), first(tbcol), last(tbcol) from $mt where ts < now + 4m + # max(tbcol), first(tbcol), last(tbcol) from $mt where ts < 1605045600000 + 240001 # group by tgcol tdLog.info( - 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m group by tgcol' % + 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001 group by tgcol' % (mt)) tdSql.query( - 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m group by tgcol' % + 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001 group by tgcol' % (mt)) # TSIM: print $data00 $data01 $data02 $data03 $data04 $data05 $data06 tdLog.info('$data00 $data01 $data02 $data03 $data04 $data05 $data06') diff --git a/tests/pytest/tag_lite/bool_binary.py b/tests/pytest/tag_lite/bool_binary.py index bfc496e8e4013ab5fb1bf929d7aeb3d37238b343..934d91c9084e7631feb6c34c596b23a7e0314cb7 100644 --- a/tests/pytest/tag_lite/bool_binary.py +++ b/tests/pytest/tag_lite/bool_binary.py @@ -71,14 +71,13 @@ class TDTestCase: # TSIM: while $x < $rowNum while (x < rowNum): # TSIM: $ms = $x . m - ms = "%dm" % x - # TSIM: sql insert into $tb values (now + $ms , $x ) + ms = x * 60000 tdLog.info( - 'insert into %s values (now + %s , %d )' % - (tb, ms, x)) + "insert into %s values (%d, %d)" % + (tb, 1605045600000 + ms, x)) tdSql.execute( - 'insert into %s values (now + %s , %d )' % - (tb, ms, x)) + "insert into %s values (%d, %d)" % + (tb, 1605045600000 + ms, x)) # TSIM: $x = $x + 1 x = x + 1 # TSIM: endw @@ -96,14 +95,13 @@ class TDTestCase: # TSIM: while $x < $rowNum while (x < rowNum): # TSIM: $ms = $x . m - ms = "%dm" % x - # TSIM: sql insert into $tb values (now + $ms , $x ) + ms = x * 60000 tdLog.info( - 'insert into %s values (now + %s , %d )' % - (tb, ms, x)) + "insert into %s values (%d, %d)" % + (tb, 1605045600000 + ms, x)) tdSql.execute( - 'insert into %s values (now + %s , %d )' % - (tb, ms, x)) + "insert into %s values (%d, %d)" % + (tb, 1605045600000 + ms, x)) # TSIM: $x = $x + 1 x = x + 1 # TSIM: endw @@ -122,36 +120,36 @@ class TDTestCase: # TSIM: return -1 # TSIM: endi # TSIM: - # TSIM: sql select * from $mt where ts < now + 4m - tdLog.info('select * from %s where ts < now + 4m' % (mt)) - tdSql.query('select * from %s where ts < now + 4m' % (mt)) + # TSIM: sql select * from $mt where ts < 1605045600000 + 240001 + tdLog.info('select * from %s where ts < 1605045600000 + 240001' % (mt)) + tdSql.query('select * from %s where ts < 1605045600000 + 240001' % (mt)) # TSIM: if $rows != 50 then tdLog.info('tdSql.checkRow(50)') tdSql.checkRows(50) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m - tdLog.info('select * from %s where ts > now + 4m' % (mt)) - tdSql.query('select * from %s where ts > now + 4m' % (mt)) + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 + tdLog.info('select * from %s where ts > 1605045600000 + 240001' % (mt)) + tdSql.query('select * from %s where ts > 1605045600000 + 240001' % (mt)) # TSIM: if $rows != 150 then tdLog.info('tdSql.checkRow(150)') tdSql.checkRows(150) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts = now + 4m - tdLog.info('select * from %s where ts = now + 4m' % (mt)) - tdSql.query('select * from %s where ts = now + 4m' % (mt)) + # TSIM: sql select * from $mt where ts = 1605045600000 + 240001 + tdLog.info('select * from %s where ts = 1605045600000 + 240001' % (mt)) + tdSql.query('select * from %s where ts = 1605045600000 + 240001' % (mt)) # TSIM: if $rows != 0 then tdLog.info('tdSql.checkRow(0)') tdSql.checkRows(0) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and ts < now + 5m + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 tdLog.info( - 'select * from %s where ts > now + 4m and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001' % (mt)) # TSIM: if $rows != 10 then tdLog.info('tdSql.checkRow(10)') @@ -263,98 +261,98 @@ class TDTestCase: # TSIM: # TSIM: print =============== step5 tdLog.info('=============== step5') - # TSIM: sql select * from $mt where ts > now + 4m and tgcol = true + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol = true tdLog.info( - 'select * from %s where ts > now + 4m and tgcol = true' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol = true' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol = true' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol = true' % (mt)) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and tgcol <> true + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol <> true tdLog.info( - 'select * from %s where ts > now + 4m and tgcol <> true' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol <> true' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol <> true' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol <> true' % (mt)) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts < now + 4m and tgcol = false + # TSIM: sql select * from $mt where ts < 1605045600000 + 240001 and tgcol = false tdLog.info( - 'select * from %s where ts < now + 4m and tgcol = false' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol = false' % (mt)) tdSql.query( - 'select * from %s where ts < now + 4m and tgcol = false' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol = false' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts < now + 4m and tgcol <> false + # TSIM: sql select * from $mt where ts < 1605045600000 + 240001 and tgcol <> false tdLog.info( - 'select * from %s where ts < now + 4m and tgcol <> false' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol <> false' % (mt)) tdSql.query( - 'select * from %s where ts < now + 4m and tgcol <> false' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol <> false' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts <= now + 4m and tgcol = false + # TSIM: sql select * from $mt where ts <= 1605045600000 + 240001 and tgcol = false tdLog.info( - 'select * from %s where ts <= now + 4m and tgcol = false' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol = false' % (mt)) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol = false' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol = false' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts <= now + 4m and tgcol <> false + # TSIM: sql select * from $mt where ts <= 1605045600000 + 240001 and tgcol <> false tdLog.info( - 'select * from %s where ts <= now + 4m and tgcol <> false' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol <> false' % (mt)) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol <> false' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol <> false' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and ts < now + 5m and + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and # tgcol <> false tdLog.info( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol <> false' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol <> false' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol <> false' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol <> false' % (mt)) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') tdSql.checkRows(5) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and tgcol <> false - # and ts < now + 5m + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol <> false + # and ts < 1605045600000 + 300001 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol <> false and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol <> false and ts < 1605045600000 + 300001' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol <> false and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol <> false and ts < 1605045600000 + 300001' % (mt)) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') @@ -364,98 +362,98 @@ class TDTestCase: # TSIM: # TSIM: print =============== step6 tdLog.info('=============== step6') - # TSIM: sql select * from $mt where ts > now + 4m and tgcol2 = '1' + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol2 = '1' tdLog.info( - 'select * from %s where ts > now + 4m and tgcol2 = "1"' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol2 = "1"' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol2 = "1"' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol2 = "1"' % (mt)) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and tgcol2 <> '1' + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol2 <> '1' tdLog.info( - 'select * from %s where ts > now + 4m and tgcol2 <> "1"' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol2 <> "1"' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol2 <> "1"' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol2 <> "1"' % (mt)) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts < now + 4m and tgcol2 = '0' + # TSIM: sql select * from $mt where ts < 1605045600000 + 240001 and tgcol2 = '0' tdLog.info( - 'select * from %s where ts < now + 4m and tgcol2 = "0"' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol2 = "0"' % (mt)) tdSql.query( - 'select * from %s where ts < now + 4m and tgcol2 = "0"' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol2 = "0"' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts < now + 4m and tgcol2 <> '0' + # TSIM: sql select * from $mt where ts < 1605045600000 + 240001 and tgcol2 <> '0' tdLog.info( - 'select * from %s where ts < now + 4m and tgcol2 <> "0"' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol2 <> "0"' % (mt)) tdSql.query( - 'select * from %s where ts < now + 4m and tgcol2 <> "0"' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol2 <> "0"' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts <= now + 4m and tgcol2 = '0' + # TSIM: sql select * from $mt where ts <= 1605045600000 + 240001 and tgcol2 = '0' tdLog.info( - 'select * from %s where ts <= now + 4m and tgcol2 = "0"' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol2 = "0"' % (mt)) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol2 = "0"' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol2 = "0"' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts <= now + 4m and tgcol2 <> '0' + # TSIM: sql select * from $mt where ts <= 1605045600000 + 240001 and tgcol2 <> '0' tdLog.info( - 'select * from %s where ts <= now + 4m and tgcol2 <> "0"' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol2 <> "0"' % (mt)) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol2 <> "0"' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol2 <> "0"' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and ts < now + 5m and + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and # tgcol2 <> '0' tdLog.info( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol2 <> "0"' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol2 <> "0"' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol2 <> "0"' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol2 <> "0"' % (mt)) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') tdSql.checkRows(5) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and tgcol2 <> '0' and - # ts < now + 5m + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol2 <> '0' and + # ts < 1605045600000 + 300001 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol2 <> "0" and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol2 <> "0" and ts < 1605045600000 + 300001' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol2 <> "0" and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol2 <> "0" and ts < 1605045600000 + 300001' % (mt)) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') @@ -465,104 +463,104 @@ class TDTestCase: # TSIM: # TSIM: print =============== step7 tdLog.info('=============== step7') - # TSIM: sql select * from $mt where ts > now + 4m and tgcol2 = '1' and + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol2 = '1' and # tgcol = true tdLog.info( - 'select * from %s where ts > now + 4m and tgcol2 = "1" and tgcol = true' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol2 = "1" and tgcol = true' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol2 = "1" and tgcol = true' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol2 = "1" and tgcol = true' % (mt)) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and tgcol2 <> '1' and + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol2 <> '1' and # tgcol <> true tdLog.info( - 'select * from %s where ts > now + 4m and tgcol2 <> "1" and tgcol <> true' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol2 <> "1" and tgcol <> true' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol2 <> "1" and tgcol <> true' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol2 <> "1" and tgcol <> true' % (mt)) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts < now + 4m and tgcol2 = '0' and + # TSIM: sql select * from $mt where ts < 1605045600000 + 240001 and tgcol2 = '0' and # tgcol = false tdLog.info( - 'select * from %s where ts < now + 4m and tgcol2 = "0" and tgcol = false' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol2 = "0" and tgcol = false' % (mt)) tdSql.query( - 'select * from %s where ts < now + 4m and tgcol2 = "0" and tgcol = false' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol2 = "0" and tgcol = false' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts < now + 4m and tgcol2 <> '0' and + # TSIM: sql select * from $mt where ts < 1605045600000 + 240001 and tgcol2 <> '0' and # tgcol <> false tdLog.info( - 'select * from %s where ts < now + 4m and tgcol2 <> "0" and tgcol <> false' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol2 <> "0" and tgcol <> false' % (mt)) tdSql.query( - 'select * from %s where ts < now + 4m and tgcol2 <> "0" and tgcol <> false' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol2 <> "0" and tgcol <> false' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts <= now + 4m and tgcol2 = '0' and + # TSIM: sql select * from $mt where ts <= 1605045600000 + 240001 and tgcol2 = '0' and # tgcol = false tdLog.info( - 'select * from %s where ts <= now + 4m and tgcol2 = "0" and tgcol = false' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol2 = "0" and tgcol = false' % (mt)) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol2 = "0" and tgcol = false' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol2 = "0" and tgcol = false' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts <= now + 4m and tgcol2 <> '0' + # TSIM: sql select * from $mt where ts <= 1605045600000 + 240001 and tgcol2 <> '0' # and tgcol <> false tdLog.info( - 'select * from %s where ts <= now + 4m and tgcol2 <> "0" and tgcol <> false' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol2 <> "0" and tgcol <> false' % (mt)) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol2 <> "0" and tgcol <> false' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol2 <> "0" and tgcol <> false' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and ts < now + 5m and + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and # tgcol2 <> '0' and tgcol <> false tdLog.info( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol2 <> "0" and tgcol <> false' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol2 <> "0" and tgcol <> false' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol2 <> "0" and tgcol <> false' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol2 <> "0" and tgcol <> false' % (mt)) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') tdSql.checkRows(5) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and tgcol2 <> '0' and - # ts < now + 5m and ts < now + 5m and tgcol <> false + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol2 <> '0' and + # ts < 1605045600000 + 300001 and ts < 1605045600000 + 300001 and tgcol <> false tdLog.info( - 'select * from %s where ts > now + 4m and tgcol2 <> "0" and ts < now + 5m and ts < now + 5m and tgcol <> false' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol2 <> "0" and ts < 1605045600000 + 300001 and ts < 1605045600000 + 300001 and tgcol <> false' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol2 <> "0" and ts < now + 5m and ts < now + 5m and tgcol <> false' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol2 <> "0" and ts < 1605045600000 + 300001 and ts < 1605045600000 + 300001 and tgcol <> false' % (mt)) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') @@ -642,12 +640,12 @@ class TDTestCase: # TSIM: print =============== step10 tdLog.info('=============== step10') # TSIM: sql select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), - # max(tbcol), first(tbcol), last(tbcol) from $mt where ts < now + 4m + # max(tbcol), first(tbcol), last(tbcol) from $mt where ts < 1605045600000 + 240001 tdLog.info( - 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m' % + 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001' % (mt)) tdSql.query( - 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m' % + 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001' % (mt)) # TSIM: print $data00 $data01 $data02 $data03 $data04 $data05 $data06 tdLog.info('$data00 $data01 $data02 $data03 $data04 $data05 $data06') @@ -732,13 +730,13 @@ class TDTestCase: # TSIM: print =============== step13 tdLog.info('=============== step13') # TSIM: sql select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), - # max(tbcol), first(tbcol), last(tbcol) from $mt where ts < now + 4m + # max(tbcol), first(tbcol), last(tbcol) from $mt where ts < 1605045600000 + 240001 # group by tgcol tdLog.info( - 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m group by tgcol' % + 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001 group by tgcol' % (mt)) tdSql.query( - 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m group by tgcol' % + 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001 group by tgcol' % (mt)) # TSIM: print $data00 $data01 $data02 $data03 $data04 $data05 $data06 tdLog.info('$data00 $data01 $data02 $data03 $data04 $data05 $data06') diff --git a/tests/pytest/tag_lite/bool_int.py b/tests/pytest/tag_lite/bool_int.py index f7bfc7acef276609c8606185102b5463807d577a..1e857192ede0602c8aa5e279da12ea488559ec07 100644 --- a/tests/pytest/tag_lite/bool_int.py +++ b/tests/pytest/tag_lite/bool_int.py @@ -71,14 +71,13 @@ class TDTestCase: # TSIM: while $x < $rowNum while (x < rowNum): # TSIM: $ms = $x . m - ms = "%dm" % x - # TSIM: sql insert into $tb values (now + $ms , $x ) + ms = x * 60000 tdLog.info( - 'insert into %s values (now + %s , %d )' % - (tb, ms, x)) + "insert into %s values (%d, %d)" % + (tb, 1605045600000 + ms, x)) tdSql.execute( - 'insert into %s values (now + %s , %d )' % - (tb, ms, x)) + "insert into %s values (%d, %d)" % + (tb, 1605045600000 + ms, x)) # TSIM: $x = $x + 1 x = x + 1 # TSIM: endw @@ -96,14 +95,13 @@ class TDTestCase: # TSIM: while $x < $rowNum while (x < rowNum): # TSIM: $ms = $x . m - ms = "%dm" % x - # TSIM: sql insert into $tb values (now + $ms , $x ) + ms = x * 60000 tdLog.info( - 'insert into %s values (now + %s , %d )' % - (tb, ms, x)) + "insert into %s values (%d, %d)" % + (tb, 1605045600000 + ms, x)) tdSql.execute( - 'insert into %s values (now + %s , %d )' % - (tb, ms, x)) + "insert into %s values (%d, %d)" % + (tb, 1605045600000 + ms, x)) # TSIM: $x = $x + 1 x = x + 1 # TSIM: endw @@ -122,36 +120,36 @@ class TDTestCase: # TSIM: return -1 # TSIM: endi # TSIM: - # TSIM: sql select * from $mt where ts < now + 4m - tdLog.info('select * from %s where ts < now + 4m' % (mt)) - tdSql.query('select * from %s where ts < now + 4m' % (mt)) + # TSIM: sql select * from $mt where ts < 1605045600000 + 240001 + tdLog.info('select * from %s where ts < 1605045600000 + 240001' % (mt)) + tdSql.query('select * from %s where ts < 1605045600000 + 240001' % (mt)) # TSIM: if $rows != 50 then tdLog.info('tdSql.checkRow(50)') tdSql.checkRows(50) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m - tdLog.info('select * from %s where ts > now + 4m' % (mt)) - tdSql.query('select * from %s where ts > now + 4m' % (mt)) + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 + tdLog.info('select * from %s where ts > 1605045600000 + 240001' % (mt)) + tdSql.query('select * from %s where ts > 1605045600000 + 240001' % (mt)) # TSIM: if $rows != 150 then tdLog.info('tdSql.checkRow(150)') tdSql.checkRows(150) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts = now + 4m - tdLog.info('select * from %s where ts = now + 4m' % (mt)) - tdSql.query('select * from %s where ts = now + 4m' % (mt)) + # TSIM: sql select * from $mt where ts = 1605045600000 + 240001 + tdLog.info('select * from %s where ts = 1605045600000 + 240001' % (mt)) + tdSql.query('select * from %s where ts = 1605045600000 + 240001' % (mt)) # TSIM: if $rows != 0 then tdLog.info('tdSql.checkRow(0)') tdSql.checkRows(0) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and ts < now + 5m + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 tdLog.info( - 'select * from %s where ts > now + 4m and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001' % (mt)) # TSIM: if $rows != 10 then tdLog.info('tdSql.checkRow(10)') @@ -295,98 +293,98 @@ class TDTestCase: # TSIM: # TSIM: print =============== step5 tdLog.info('=============== step5') - # TSIM: sql select * from $mt where ts > now + 4m and tgcol = true + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol = true tdLog.info( - 'select * from %s where ts > now + 4m and tgcol = true' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol = true' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol = true' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol = true' % (mt)) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and tgcol <> true + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol <> true tdLog.info( - 'select * from %s where ts > now + 4m and tgcol <> true' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol <> true' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol <> true' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol <> true' % (mt)) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts < now + 4m and tgcol = false + # TSIM: sql select * from $mt where ts < 1605045600000 + 240001 and tgcol = false tdLog.info( - 'select * from %s where ts < now + 4m and tgcol = false' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol = false' % (mt)) tdSql.query( - 'select * from %s where ts < now + 4m and tgcol = false' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol = false' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts < now + 4m and tgcol <> false + # TSIM: sql select * from $mt where ts < 1605045600000 + 240001 and tgcol <> false tdLog.info( - 'select * from %s where ts < now + 4m and tgcol <> false' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol <> false' % (mt)) tdSql.query( - 'select * from %s where ts < now + 4m and tgcol <> false' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol <> false' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts <= now + 4m and tgcol = false + # TSIM: sql select * from $mt where ts <= 1605045600000 + 240001 and tgcol = false tdLog.info( - 'select * from %s where ts <= now + 4m and tgcol = false' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol = false' % (mt)) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol = false' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol = false' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts <= now + 4m and tgcol <> false + # TSIM: sql select * from $mt where ts <= 1605045600000 + 240001 and tgcol <> false tdLog.info( - 'select * from %s where ts <= now + 4m and tgcol <> false' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol <> false' % (mt)) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol <> false' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol <> false' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and ts < now + 5m and + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and # tgcol <> false tdLog.info( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol <> false' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol <> false' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol <> false' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol <> false' % (mt)) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') tdSql.checkRows(5) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and tgcol <> false - # and ts < now + 5m + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol <> false + # and ts < 1605045600000 + 300001 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol <> false and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol <> false and ts < 1605045600000 + 300001' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol <> false and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol <> false and ts < 1605045600000 + 300001' % (mt)) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') @@ -396,98 +394,98 @@ class TDTestCase: # TSIM: # TSIM: print =============== step6 tdLog.info('=============== step6') - # TSIM: sql select * from $mt where ts > now + 4m and tgcol2 = 1 + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol2 = 1 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol2 = 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol2 = 1' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol2 = 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol2 = 1' % (mt)) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and tgcol2 <> 1 + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol2 <> 1 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol2 <> 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol2 <> 1' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol2 <> 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol2 <> 1' % (mt)) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts < now + 4m and tgcol2 = 0 + # TSIM: sql select * from $mt where ts < 1605045600000 + 240001 and tgcol2 = 0 tdLog.info( - 'select * from %s where ts < now + 4m and tgcol2 = 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol2 = 0' % (mt)) tdSql.query( - 'select * from %s where ts < now + 4m and tgcol2 = 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol2 = 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts < now + 4m and tgcol2 <> 0 + # TSIM: sql select * from $mt where ts < 1605045600000 + 240001 and tgcol2 <> 0 tdLog.info( - 'select * from %s where ts < now + 4m and tgcol2 <> 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol2 <> 0' % (mt)) tdSql.query( - 'select * from %s where ts < now + 4m and tgcol2 <> 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol2 <> 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts <= now + 4m and tgcol2 = 0 + # TSIM: sql select * from $mt where ts <= 1605045600000 + 240001 and tgcol2 = 0 tdLog.info( - 'select * from %s where ts <= now + 4m and tgcol2 = 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol2 = 0' % (mt)) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol2 = 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol2 = 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts <= now + 4m and tgcol2 <> 0 + # TSIM: sql select * from $mt where ts <= 1605045600000 + 240001 and tgcol2 <> 0 tdLog.info( - 'select * from %s where ts <= now + 4m and tgcol2 <> 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol2 <> 0' % (mt)) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol2 <> 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol2 <> 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and ts < now + 5m and + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and # tgcol2 <> 0 tdLog.info( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol2 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol2 <> 0' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol2 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol2 <> 0' % (mt)) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') tdSql.checkRows(5) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and tgcol2 <> 0 and - # ts < now + 5m + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol2 <> 0 and + # ts < 1605045600000 + 300001 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol2 <> 0 and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol2 <> 0 and ts < 1605045600000 + 300001' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol2 <> 0 and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol2 <> 0 and ts < 1605045600000 + 300001' % (mt)) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') @@ -497,104 +495,104 @@ class TDTestCase: # TSIM: # TSIM: print =============== step7 tdLog.info('=============== step7') - # TSIM: sql select * from $mt where ts > now + 4m and tgcol2 = 1 and + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol2 = 1 and # tgcol = true tdLog.info( - 'select * from %s where ts > now + 4m and tgcol2 = 1 and tgcol = true' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol2 = 1 and tgcol = true' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol2 = 1 and tgcol = true' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol2 = 1 and tgcol = true' % (mt)) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and tgcol2 <> 1 and + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol2 <> 1 and # tgcol <> true tdLog.info( - 'select * from %s where ts > now + 4m and tgcol2 <> 1 and tgcol <> true' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol2 <> 1 and tgcol <> true' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol2 <> 1 and tgcol <> true' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol2 <> 1 and tgcol <> true' % (mt)) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts < now + 4m and tgcol2 = 0 and + # TSIM: sql select * from $mt where ts < 1605045600000 + 240001 and tgcol2 = 0 and # tgcol = false tdLog.info( - 'select * from %s where ts < now + 4m and tgcol2 = 0 and tgcol = false' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol2 = 0 and tgcol = false' % (mt)) tdSql.query( - 'select * from %s where ts < now + 4m and tgcol2 = 0 and tgcol = false' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol2 = 0 and tgcol = false' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts < now + 4m and tgcol2 <> 0 and + # TSIM: sql select * from $mt where ts < 1605045600000 + 240001 and tgcol2 <> 0 and # tgcol <> false tdLog.info( - 'select * from %s where ts < now + 4m and tgcol2 <> 0 and tgcol <> false' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol2 <> 0 and tgcol <> false' % (mt)) tdSql.query( - 'select * from %s where ts < now + 4m and tgcol2 <> 0 and tgcol <> false' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol2 <> 0 and tgcol <> false' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts <= now + 4m and tgcol2 = 0 and + # TSIM: sql select * from $mt where ts <= 1605045600000 + 240001 and tgcol2 = 0 and # tgcol = false tdLog.info( - 'select * from %s where ts <= now + 4m and tgcol2 = 0 and tgcol = false' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol2 = 0 and tgcol = false' % (mt)) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol2 = 0 and tgcol = false' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol2 = 0 and tgcol = false' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts <= now + 4m and tgcol2 <> 0 and + # TSIM: sql select * from $mt where ts <= 1605045600000 + 240001 and tgcol2 <> 0 and # tgcol <> false tdLog.info( - 'select * from %s where ts <= now + 4m and tgcol2 <> 0 and tgcol <> false' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol2 <> 0 and tgcol <> false' % (mt)) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol2 <> 0 and tgcol <> false' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol2 <> 0 and tgcol <> false' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and ts < now + 5m and + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and # tgcol2 <> 0 and tgcol <> false tdLog.info( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol2 <> 0 and tgcol <> false' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol2 <> 0 and tgcol <> false' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol2 <> 0 and tgcol <> false' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol2 <> 0 and tgcol <> false' % (mt)) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') tdSql.checkRows(5) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and tgcol2 <> 0 and - # ts < now + 5m and ts < now + 5m and tgcol <> false + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol2 <> 0 and + # ts < 1605045600000 + 300001 and ts < 1605045600000 + 300001 and tgcol <> false tdLog.info( - 'select * from %s where ts > now + 4m and tgcol2 <> 0 and ts < now + 5m and ts < now + 5m and tgcol <> false' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol2 <> 0 and ts < 1605045600000 + 300001 and ts < 1605045600000 + 300001 and tgcol <> false' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol2 <> 0 and ts < now + 5m and ts < now + 5m and tgcol <> false' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol2 <> 0 and ts < 1605045600000 + 300001 and ts < 1605045600000 + 300001 and tgcol <> false' % (mt)) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') @@ -674,12 +672,12 @@ class TDTestCase: # TSIM: print =============== step10 tdLog.info('=============== step10') # TSIM: sql select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), - # max(tbcol), first(tbcol), last(tbcol) from $mt where ts < now + 4m + # max(tbcol), first(tbcol), last(tbcol) from $mt where ts < 1605045600000 + 240001 tdLog.info( - 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m' % + 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001' % (mt)) tdSql.query( - 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m' % + 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001' % (mt)) # TSIM: print $data00 $data01 $data02 $data03 $data04 $data05 $data06 tdLog.info('$data00 $data01 $data02 $data03 $data04 $data05 $data06') @@ -764,13 +762,13 @@ class TDTestCase: # TSIM: print =============== step13 tdLog.info('=============== step13') # TSIM: sql select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), - # max(tbcol), first(tbcol), last(tbcol) from $mt where ts < now + 4m + # max(tbcol), first(tbcol), last(tbcol) from $mt where ts < 1605045600000 + 240001 # group by tgcol tdLog.info( - 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m group by tgcol' % + 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001 group by tgcol' % (mt)) tdSql.query( - 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m group by tgcol' % + 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001 group by tgcol' % (mt)) # TSIM: print $data00 $data01 $data02 $data03 $data04 $data05 $data06 tdLog.info('$data00 $data01 $data02 $data03 $data04 $data05 $data06') diff --git a/tests/pytest/tag_lite/double.py b/tests/pytest/tag_lite/double.py index b1f29f592e70c582cde9b9eff114ff78843c6fc3..c9d3a5af9e88a0c1faccfabd17245dcaf54b179f 100644 --- a/tests/pytest/tag_lite/double.py +++ b/tests/pytest/tag_lite/double.py @@ -72,14 +72,13 @@ class TDTestCase: # TSIM: while $x < $rowNum while (x < rowNum): # TSIM: $ms = $x . m - ms = "%dm" % x - # TSIM: sql insert into $tb values (now + $ms , $x ) + ms = x * 60000 tdLog.info( - 'insert into %s values (now + %s , %d )' % - (tb, ms, x)) + "insert into %s values (%d, %d)" % + (tb, 1605045600000 + ms, x)) tdSql.execute( - 'insert into %s values (now + %s , %d )' % - (tb, ms, x)) + "insert into %s values (%d, %d)" % + (tb, 1605045600000 + ms, x)) # TSIM: $x = $x + 1 x = x + 1 # TSIM: endw @@ -98,14 +97,13 @@ class TDTestCase: # TSIM: while $x < $rowNum while (x < rowNum): # TSIM: $ms = $x . m - ms = "%dm" % x - # TSIM: sql insert into $tb values (now + $ms , $x ) + ms = x * 60000 tdLog.info( - 'insert into %s values (now + %s , %d )' % - (tb, ms, x)) + "insert into %s values (%d, %d)" % + (tb, 1605045600000 + ms, x)) tdSql.execute( - 'insert into %s values (now + %s , %d )' % - (tb, ms, x)) + "insert into %s values (%d, %d)" % + (tb, 1605045600000 + ms, x)) # TSIM: $x = $x + 1 x = x + 1 # TSIM: endw @@ -124,56 +122,56 @@ class TDTestCase: tdSql.checkRows(rowNum) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $tb where ts < now + 4m - tdLog.info('select * from %s where ts < now + 4m' % (tb)) - tdSql.query('select * from %s where ts < now + 4m' % (tb)) + # TSIM: sql select * from $tb where ts < 1605045600000 + 240001 + tdLog.info('select * from %s where ts < 1605045600000 + 240001' % (tb)) + tdSql.query('select * from %s where ts < 1605045600000 + 240001' % (tb)) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') tdSql.checkRows(5) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $tb where ts <= now + 4m - tdLog.info('select * from %s where ts <= now + 4m' % (tb)) - tdSql.query('select * from %s where ts <= now + 4m' % (tb)) + # TSIM: sql select * from $tb where ts <= 1605045600000 + 240001 + tdLog.info('select * from %s where ts <= 1605045600000 + 240001' % (tb)) + tdSql.query('select * from %s where ts <= 1605045600000 + 240001' % (tb)) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') tdSql.checkRows(5) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $tb where ts > now + 4m - tdLog.info('select * from %s where ts > now + 4m' % (tb)) - tdSql.query('select * from %s where ts > now + 4m' % (tb)) + # TSIM: sql select * from $tb where ts > 1605045600000 + 240001 + tdLog.info('select * from %s where ts > 1605045600000 + 240001' % (tb)) + tdSql.query('select * from %s where ts > 1605045600000 + 240001' % (tb)) # TSIM: if $rows != 15 then tdLog.info('tdSql.checkRow(15)') tdSql.checkRows(15) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $tb where ts >= now + 4m - tdLog.info('select * from %s where ts >= now + 4m' % (tb)) - tdSql.query('select * from %s where ts >= now + 4m' % (tb)) + # TSIM: sql select * from $tb where ts >= 1605045600000 + 240001 + tdLog.info('select * from %s where ts >= 1605045600000 + 240001' % (tb)) + tdSql.query('select * from %s where ts >= 1605045600000 + 240001' % (tb)) # TSIM: if $rows != 15 then tdLog.info('tdSql.checkRow(15)') tdSql.checkRows(15) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $tb where ts > now + 4m and ts < now + 5m + # TSIM: sql select * from $tb where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 tdLog.info( - 'select * from %s where ts > now + 4m and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001' % (tb)) tdSql.query( - 'select * from %s where ts > now + 4m and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001' % (tb)) # TSIM: if $rows != 1 then tdLog.info('tdSql.checkRow(1)') tdSql.checkRows(1) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $tb where ts < now + 4m and ts > now + 5m + # TSIM: sql select * from $tb where ts < 1605045600000 + 240001 and ts > 1605045600000 + 300001 tdLog.info( - 'select * from %s where ts < now + 4m and ts > now + 5m' % + 'select * from %s where ts < 1605045600000 + 240001 and ts > 1605045600000 + 300001' % (tb)) tdSql.query( - 'select * from %s where ts < now + 4m and ts > now + 5m' % + 'select * from %s where ts < 1605045600000 + 240001 and ts > 1605045600000 + 300001' % (tb)) # TSIM: if $rows != 0 then tdLog.info('tdSql.checkRow(0)') @@ -190,25 +188,25 @@ class TDTestCase: tdSql.checkRows(0) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $tb where ts > now + 4m and ts < now + 3m + # TSIM: sql select * from $tb where ts > 1605045600000 + 240001 and ts < 1605045600000 + 180001 tdLog.info( - 'select * from %s where ts > now + 4m and ts < now + 3m' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 180001' % (tb)) tdSql.query( - 'select * from %s where ts > now + 4m and ts < now + 3m' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 180001' % (tb)) # TSIM: if $rows != 0 then tdLog.info('tdSql.checkRow(0)') tdSql.checkRows(0) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $tb where ts > now + 4m and ts > now + 5m and - # ts < now + 6m + # TSIM: sql select * from $tb where ts > 1605045600000 + 240001 and ts > 1605045600000 + 300001 and + # ts < 1605045600000 + 360001 tdLog.info( - 'select * from %s where ts > now + 4m and ts > now + 5m and ts < now + 6m' % + 'select * from %s where ts > 1605045600000 + 240001 and ts > 1605045600000 + 300001 and ts < 1605045600000 + 360001' % (tb)) tdSql.query( - 'select * from %s where ts > now + 4m and ts > now + 5m and ts < now + 6m' % + 'select * from %s where ts > 1605045600000 + 240001 and ts > 1605045600000 + 300001 and ts < 1605045600000 + 360001' % (tb)) # TSIM: if $rows != 1 then tdLog.info('tdSql.checkRow(1)') @@ -227,36 +225,36 @@ class TDTestCase: # TSIM: return -1 # TSIM: endi # TSIM: - # TSIM: sql select * from $mt where ts < now + 4m - tdLog.info('select * from %s where ts < now + 4m' % (mt)) - tdSql.query('select * from %s where ts < now + 4m' % (mt)) + # TSIM: sql select * from $mt where ts < 1605045600000 + 240001 + tdLog.info('select * from %s where ts < 1605045600000 + 240001' % (mt)) + tdSql.query('select * from %s where ts < 1605045600000 + 240001' % (mt)) # TSIM: if $rows != 50 then tdLog.info('tdSql.checkRow(50)') tdSql.checkRows(50) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m - tdLog.info('select * from %s where ts > now + 4m' % (mt)) - tdSql.query('select * from %s where ts > now + 4m' % (mt)) + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 + tdLog.info('select * from %s where ts > 1605045600000 + 240001' % (mt)) + tdSql.query('select * from %s where ts > 1605045600000 + 240001' % (mt)) # TSIM: if $rows != 150 then tdLog.info('tdSql.checkRow(150)') tdSql.checkRows(150) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts = now + 4m - tdLog.info('select * from %s where ts = now + 4m' % (mt)) - tdSql.query('select * from %s where ts = now + 4m' % (mt)) + # TSIM: sql select * from $mt where ts = 1605045600000 + 240001 + tdLog.info('select * from %s where ts = 1605045600000 + 240001' % (mt)) + tdSql.query('select * from %s where ts = 1605045600000 + 240001' % (mt)) # TSIM: if $rows != 0 then tdLog.info('tdSql.checkRow(0)') tdSql.checkRows(0) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and ts < now + 5m + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 tdLog.info( - 'select * from %s where ts > now + 4m and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001' % (mt)) # TSIM: if $rows != 10 then tdLog.info('tdSql.checkRow(10)') @@ -333,94 +331,94 @@ class TDTestCase: # TSIM: # TSIM: print =============== step5 tdLog.info('=============== step5') - # TSIM: sql select * from $mt where ts > now + 4m and tgcol = 1 - tdLog.info('select * from %s where ts > now + 4m and tgcol = 1' % (mt)) + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol = 1 + tdLog.info('select * from %s where ts > 1605045600000 + 240001 and tgcol = 1' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol = 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol = 1' % (mt)) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and tgcol <> 1 + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol <> 1 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol <> 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol <> 1' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol <> 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol <> 1' % (mt)) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts < now + 4m and tgcol = 0 - tdLog.info('select * from %s where ts < now + 4m and tgcol = 0' % (mt)) + # TSIM: sql select * from $mt where ts < 1605045600000 + 240001 and tgcol = 0 + tdLog.info('select * from %s where ts < 1605045600000 + 240001 and tgcol = 0' % (mt)) tdSql.query( - 'select * from %s where ts < now + 4m and tgcol = 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol = 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts < now + 4m and tgcol <> 0 + # TSIM: sql select * from $mt where ts < 1605045600000 + 240001 and tgcol <> 0 tdLog.info( - 'select * from %s where ts < now + 4m and tgcol <> 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol <> 0' % (mt)) tdSql.query( - 'select * from %s where ts < now + 4m and tgcol <> 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol <> 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts <= now + 4m and tgcol = 0 + # TSIM: sql select * from $mt where ts <= 1605045600000 + 240001 and tgcol = 0 tdLog.info( - 'select * from %s where ts <= now + 4m and tgcol = 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol = 0' % (mt)) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol = 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol = 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts <= now + 4m and tgcol <> 0 + # TSIM: sql select * from $mt where ts <= 1605045600000 + 240001 and tgcol <> 0 tdLog.info( - 'select * from %s where ts <= now + 4m and tgcol <> 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol <> 0' % (mt)) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol <> 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol <> 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and ts < now + 5m and + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and # tgcol <> 0 tdLog.info( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol <> 0' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol <> 0' % (mt)) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') tdSql.checkRows(5) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and tgcol <> 0 and ts - # < now + 5m + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol <> 0 and ts + # < 1605045600000 + 300001 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol <> 0 and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol <> 0 and ts < 1605045600000 + 300001' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol <> 0 and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol <> 0 and ts < 1605045600000 + 300001' % (mt)) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') @@ -467,12 +465,12 @@ class TDTestCase: # TSIM: print =============== step8 tdLog.info('=============== step8') # TSIM: sql select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), - # max(tbcol), first(tbcol), last(tbcol) from $mt where ts < now + 4m + # max(tbcol), first(tbcol), last(tbcol) from $mt where ts < 1605045600000 + 240001 tdLog.info( - 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m' % + 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001' % (mt)) tdSql.query( - 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m' % + 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001' % (mt)) # TSIM: print $data00 $data01 $data02 $data03 $data04 $data05 $data06 tdLog.info('$data00 $data01 $data02 $data03 $data04 $data05 $data06') @@ -522,13 +520,13 @@ class TDTestCase: # TSIM: print =============== step11 tdLog.info('=============== step11') # TSIM: sql select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), - # max(tbcol), first(tbcol), last(tbcol) from $mt where ts < now + 4m + # max(tbcol), first(tbcol), last(tbcol) from $mt where ts < 1605045600000 + 240001 # group by tgcol tdLog.info( - 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m group by tgcol' % + 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001 group by tgcol' % (mt)) tdSql.query( - 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m group by tgcol' % + 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001 group by tgcol' % (mt)) # TSIM: print $data00 $data01 $data02 $data03 $data04 $data05 $data06 tdLog.info('$data00 $data01 $data02 $data03 $data04 $data05 $data06') diff --git a/tests/pytest/tag_lite/float.py b/tests/pytest/tag_lite/float.py index 7b93cb0ac91d49299aedfa63e5dcc8571415cdce..589df89ab9e000dae8c953bb64aaeda51ca0c86c 100644 --- a/tests/pytest/tag_lite/float.py +++ b/tests/pytest/tag_lite/float.py @@ -72,14 +72,13 @@ class TDTestCase: # TSIM: while $x < $rowNum while (x < rowNum): # TSIM: $ms = $x . m - ms = "%dm" % x - # TSIM: sql insert into $tb values (now + $ms , $x ) + ms = x * 60000 tdLog.info( - 'insert into %s values (now + %s , %d )' % - (tb, ms, x)) + "insert into %s values (%d, %d)" % + (tb, 1605045600000 + ms, x)) tdSql.execute( - 'insert into %s values (now + %s , %d )' % - (tb, ms, x)) + "insert into %s values (%d, %d)" % + (tb, 1605045600000 + ms, x)) # TSIM: $x = $x + 1 x = x + 1 # TSIM: endw @@ -98,14 +97,13 @@ class TDTestCase: # TSIM: while $x < $rowNum while (x < rowNum): # TSIM: $ms = $x . m - ms = "%dm" % x - # TSIM: sql insert into $tb values (now + $ms , $x ) + ms = x * 60000 tdLog.info( - 'insert into %s values (now + %s , %d )' % - (tb, ms, x)) + "insert into %s values (%d, %d)" % + (tb, 1605045600000 + ms, x)) tdSql.execute( - 'insert into %s values (now + %s , %d )' % - (tb, ms, x)) + "insert into %s values (%d, %d)" % + (tb, 1605045600000 + ms, x)) # TSIM: $x = $x + 1 x = x + 1 # TSIM: endw @@ -124,56 +122,56 @@ class TDTestCase: tdSql.checkRows(rowNum) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $tb where ts < now + 4m - tdLog.info('select * from %s where ts < now + 4m' % (tb)) - tdSql.query('select * from %s where ts < now + 4m' % (tb)) + # TSIM: sql select * from $tb where ts < 1605045600000 + 240001 + tdLog.info('select * from %s where ts < 1605045600000 + 240001' % (tb)) + tdSql.query('select * from %s where ts < 1605045600000 + 240001' % (tb)) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') tdSql.checkRows(5) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $tb where ts <= now + 4m - tdLog.info('select * from %s where ts <= now + 4m' % (tb)) - tdSql.query('select * from %s where ts <= now + 4m' % (tb)) + # TSIM: sql select * from $tb where ts <= 1605045600000 + 240001 + tdLog.info('select * from %s where ts <= 1605045600000 + 240001' % (tb)) + tdSql.query('select * from %s where ts <= 1605045600000 + 240001' % (tb)) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') tdSql.checkRows(5) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $tb where ts > now + 4m - tdLog.info('select * from %s where ts > now + 4m' % (tb)) - tdSql.query('select * from %s where ts > now + 4m' % (tb)) + # TSIM: sql select * from $tb where ts > 1605045600000 + 240001 + tdLog.info('select * from %s where ts > 1605045600000 + 240001' % (tb)) + tdSql.query('select * from %s where ts > 1605045600000 + 240001' % (tb)) # TSIM: if $rows != 15 then tdLog.info('tdSql.checkRow(15)') tdSql.checkRows(15) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $tb where ts >= now + 4m - tdLog.info('select * from %s where ts >= now + 4m' % (tb)) - tdSql.query('select * from %s where ts >= now + 4m' % (tb)) + # TSIM: sql select * from $tb where ts >= 1605045600000 + 240001 + tdLog.info('select * from %s where ts >= 1605045600000 + 240001' % (tb)) + tdSql.query('select * from %s where ts >= 1605045600000 + 240001' % (tb)) # TSIM: if $rows != 15 then tdLog.info('tdSql.checkRow(15)') tdSql.checkRows(15) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $tb where ts > now + 4m and ts < now + 5m + # TSIM: sql select * from $tb where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 tdLog.info( - 'select * from %s where ts > now + 4m and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001' % (tb)) tdSql.query( - 'select * from %s where ts > now + 4m and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001' % (tb)) # TSIM: if $rows != 1 then tdLog.info('tdSql.checkRow(1)') tdSql.checkRows(1) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $tb where ts < now + 4m and ts > now + 5m + # TSIM: sql select * from $tb where ts < 1605045600000 + 240001 and ts > 1605045600000 + 300001 tdLog.info( - 'select * from %s where ts < now + 4m and ts > now + 5m' % + 'select * from %s where ts < 1605045600000 + 240001 and ts > 1605045600000 + 300001' % (tb)) tdSql.query( - 'select * from %s where ts < now + 4m and ts > now + 5m' % + 'select * from %s where ts < 1605045600000 + 240001 and ts > 1605045600000 + 300001' % (tb)) # TSIM: if $rows != 0 then tdLog.info('tdSql.checkRow(0)') @@ -190,25 +188,25 @@ class TDTestCase: tdSql.checkRows(0) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $tb where ts > now + 4m and ts < now + 3m + # TSIM: sql select * from $tb where ts > 1605045600000 + 240001 and ts < 1605045600000 + 180001 tdLog.info( - 'select * from %s where ts > now + 4m and ts < now + 3m' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 180001' % (tb)) tdSql.query( - 'select * from %s where ts > now + 4m and ts < now + 3m' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 180001' % (tb)) # TSIM: if $rows != 0 then tdLog.info('tdSql.checkRow(0)') tdSql.checkRows(0) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $tb where ts > now + 4m and ts > now + 5m and - # ts < now + 6m + # TSIM: sql select * from $tb where ts > 1605045600000 + 240001 and ts > 1605045600000 + 300001 and + # ts < 1605045600000 + 360001 tdLog.info( - 'select * from %s where ts > now + 4m and ts > now + 5m and ts < now + 6m' % + 'select * from %s where ts > 1605045600000 + 240001 and ts > 1605045600000 + 300001 and ts < 1605045600000 + 360001' % (tb)) tdSql.query( - 'select * from %s where ts > now + 4m and ts > now + 5m and ts < now + 6m' % + 'select * from %s where ts > 1605045600000 + 240001 and ts > 1605045600000 + 300001 and ts < 1605045600000 + 360001' % (tb)) # TSIM: if $rows != 1 then tdLog.info('tdSql.checkRow(1)') @@ -227,36 +225,36 @@ class TDTestCase: # TSIM: return -1 # TSIM: endi # TSIM: - # TSIM: sql select * from $mt where ts < now + 4m - tdLog.info('select * from %s where ts < now + 4m' % (mt)) - tdSql.query('select * from %s where ts < now + 4m' % (mt)) + # TSIM: sql select * from $mt where ts < 1605045600000 + 240001 + tdLog.info('select * from %s where ts < 1605045600000 + 240001' % (mt)) + tdSql.query('select * from %s where ts < 1605045600000 + 240001' % (mt)) # TSIM: if $rows != 50 then tdLog.info('tdSql.checkRow(50)') tdSql.checkRows(50) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m - tdLog.info('select * from %s where ts > now + 4m' % (mt)) - tdSql.query('select * from %s where ts > now + 4m' % (mt)) + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 + tdLog.info('select * from %s where ts > 1605045600000 + 240001' % (mt)) + tdSql.query('select * from %s where ts > 1605045600000 + 240001' % (mt)) # TSIM: if $rows != 150 then tdLog.info('tdSql.checkRow(150)') tdSql.checkRows(150) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts = now + 4m - tdLog.info('select * from %s where ts = now + 4m' % (mt)) - tdSql.query('select * from %s where ts = now + 4m' % (mt)) + # TSIM: sql select * from $mt where ts = 1605045600000 + 240001 + tdLog.info('select * from %s where ts = 1605045600000 + 240001' % (mt)) + tdSql.query('select * from %s where ts = 1605045600000 + 240001' % (mt)) # TSIM: if $rows != 0 then tdLog.info('tdSql.checkRow(0)') tdSql.checkRows(0) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and ts < now + 5m + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 tdLog.info( - 'select * from %s where ts > now + 4m and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001' % (mt)) # TSIM: if $rows != 10 then tdLog.info('tdSql.checkRow(10)') @@ -333,94 +331,94 @@ class TDTestCase: # TSIM: # TSIM: print =============== step5 tdLog.info('=============== step5') - # TSIM: sql select * from $mt where ts > now + 4m and tgcol = 1 - tdLog.info('select * from %s where ts > now + 4m and tgcol = 1' % (mt)) + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol = 1 + tdLog.info('select * from %s where ts > 1605045600000 + 240001 and tgcol = 1' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol = 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol = 1' % (mt)) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and tgcol <> 1 + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol <> 1 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol <> 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol <> 1' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol <> 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol <> 1' % (mt)) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts < now + 4m and tgcol = 0 - tdLog.info('select * from %s where ts < now + 4m and tgcol = 0' % (mt)) + # TSIM: sql select * from $mt where ts < 1605045600000 + 240001 and tgcol = 0 + tdLog.info('select * from %s where ts < 1605045600000 + 240001 and tgcol = 0' % (mt)) tdSql.query( - 'select * from %s where ts < now + 4m and tgcol = 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol = 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts < now + 4m and tgcol <> 0 + # TSIM: sql select * from $mt where ts < 1605045600000 + 240001 and tgcol <> 0 tdLog.info( - 'select * from %s where ts < now + 4m and tgcol <> 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol <> 0' % (mt)) tdSql.query( - 'select * from %s where ts < now + 4m and tgcol <> 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol <> 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts <= now + 4m and tgcol = 0 + # TSIM: sql select * from $mt where ts <= 1605045600000 + 240001 and tgcol = 0 tdLog.info( - 'select * from %s where ts <= now + 4m and tgcol = 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol = 0' % (mt)) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol = 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol = 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts <= now + 4m and tgcol <> 0 + # TSIM: sql select * from $mt where ts <= 1605045600000 + 240001 and tgcol <> 0 tdLog.info( - 'select * from %s where ts <= now + 4m and tgcol <> 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol <> 0' % (mt)) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol <> 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol <> 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and ts < now + 5m and + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and # tgcol <> 0 tdLog.info( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol <> 0' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol <> 0' % (mt)) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') tdSql.checkRows(5) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and tgcol <> 0 and ts - # < now + 5m + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol <> 0 and ts + # < 1605045600000 + 300001 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol <> 0 and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol <> 0 and ts < 1605045600000 + 300001' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol <> 0 and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol <> 0 and ts < 1605045600000 + 300001' % (mt)) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') @@ -467,12 +465,12 @@ class TDTestCase: # TSIM: print =============== step8 tdLog.info('=============== step8') # TSIM: sql select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), - # max(tbcol), first(tbcol), last(tbcol) from $mt where ts < now + 4m + # max(tbcol), first(tbcol), last(tbcol) from $mt where ts < 1605045600000 + 240001 tdLog.info( - 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m' % + 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001' % (mt)) tdSql.query( - 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m' % + 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001' % (mt)) # TSIM: print $data00 $data01 $data02 $data03 $data04 $data05 $data06 tdLog.info('$data00 $data01 $data02 $data03 $data04 $data05 $data06') @@ -522,13 +520,13 @@ class TDTestCase: # TSIM: print =============== step11 tdLog.info('=============== step11') # TSIM: sql select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), - # max(tbcol), first(tbcol), last(tbcol) from $mt where ts < now + 4m + # max(tbcol), first(tbcol), last(tbcol) from $mt where ts < 1605045600000 + 240001 # group by tgcol tdLog.info( - 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m group by tgcol' % + 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001 group by tgcol' % (mt)) tdSql.query( - 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m group by tgcol' % + 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001 group by tgcol' % (mt)) # TSIM: print $data00 $data01 $data02 $data03 $data04 $data05 $data06 tdLog.info('$data00 $data01 $data02 $data03 $data04 $data05 $data06') diff --git a/tests/pytest/tag_lite/int.py b/tests/pytest/tag_lite/int.py index d5a69173893c4e5c8341b6235c5dd8465f913111..1297d083a0d9aa30a21c3235c89a31236175a119 100644 --- a/tests/pytest/tag_lite/int.py +++ b/tests/pytest/tag_lite/int.py @@ -71,14 +71,13 @@ class TDTestCase: # TSIM: while $x < $rowNum while (x < rowNum): # TSIM: $ms = $x . m - ms = "%dm" % x - # TSIM: sql insert into $tb values (now + $ms , $x ) + ms = x * 60000 tdLog.info( - 'insert into %s values (now + %s , %d )' % - (tb, ms, x)) + "insert into %s values (%d, %d)" % + (tb, 1605045600000 + ms, x)) tdSql.execute( - 'insert into %s values (now + %s , %d )' % - (tb, ms, x)) + "insert into %s values (%d, %d)" % + (tb, 1605045600000 + ms, x)) # TSIM: $x = $x + 1 x = x + 1 # TSIM: endw @@ -97,14 +96,13 @@ class TDTestCase: # TSIM: while $x < $rowNum while (x < rowNum): # TSIM: $ms = $x . m - ms = "%dm" % x - # TSIM: sql insert into $tb values (now + $ms , $x ) + ms = x * 60000 tdLog.info( - 'insert into %s values (now + %s , %d )' % - (tb, ms, x)) + "insert into %s values (%d, %d)" % + (tb, 1605045600000 + ms, x)) tdSql.execute( - 'insert into %s values (now + %s , %d )' % - (tb, ms, x)) + "insert into %s values (%d, %d)" % + (tb, 1605045600000 + ms, x)) # TSIM: $x = $x + 1 x = x + 1 # TSIM: endw @@ -123,56 +121,56 @@ class TDTestCase: tdSql.checkRows(rowNum) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $tb where ts < now + 4m - tdLog.info('select * from %s where ts < now + 4m' % (tb)) - tdSql.query('select * from %s where ts < now + 4m' % (tb)) + # TSIM: sql select * from $tb where ts < 1605045600000 + 240001 + tdLog.info('select * from %s where ts < 1605045600000 + 240001' % (tb)) + tdSql.query('select * from %s where ts < 1605045600000 + 240001' % (tb)) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') tdSql.checkRows(5) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $tb where ts <= now + 4m - tdLog.info('select * from %s where ts <= now + 4m' % (tb)) - tdSql.query('select * from %s where ts <= now + 4m' % (tb)) + # TSIM: sql select * from $tb where ts <= 1605045600000 + 240001 + tdLog.info('select * from %s where ts <= 1605045600000 + 240001' % (tb)) + tdSql.query('select * from %s where ts <= 1605045600000 + 240001' % (tb)) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') tdSql.checkRows(5) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $tb where ts > now + 4m - tdLog.info('select * from %s where ts > now + 4m' % (tb)) - tdSql.query('select * from %s where ts > now + 4m' % (tb)) + # TSIM: sql select * from $tb where ts > 1605045600000 + 240001 + tdLog.info('select * from %s where ts > 1605045600000 + 240001' % (tb)) + tdSql.query('select * from %s where ts > 1605045600000 + 240001' % (tb)) # TSIM: if $rows != 15 then tdLog.info('tdSql.checkRow(15)') tdSql.checkRows(15) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $tb where ts >= now + 4m - tdLog.info('select * from %s where ts >= now + 4m' % (tb)) - tdSql.query('select * from %s where ts >= now + 4m' % (tb)) + # TSIM: sql select * from $tb where ts >= 1605045600000 + 240001 + tdLog.info('select * from %s where ts >= 1605045600000 + 240001' % (tb)) + tdSql.query('select * from %s where ts >= 1605045600000 + 240001' % (tb)) # TSIM: if $rows != 15 then tdLog.info('tdSql.checkRow(15)') tdSql.checkRows(15) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $tb where ts > now + 4m and ts < now + 5m + # TSIM: sql select * from $tb where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 tdLog.info( - 'select * from %s where ts > now + 4m and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001' % (tb)) tdSql.query( - 'select * from %s where ts > now + 4m and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001' % (tb)) # TSIM: if $rows != 1 then tdLog.info('tdSql.checkRow(1)') tdSql.checkRows(1) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $tb where ts < now + 4m and ts > now + 5m + # TSIM: sql select * from $tb where ts < 1605045600000 + 240001 and ts > 1605045600000 + 300001 tdLog.info( - 'select * from %s where ts < now + 4m and ts > now + 5m' % + 'select * from %s where ts < 1605045600000 + 240001 and ts > 1605045600000 + 300001' % (tb)) tdSql.query( - 'select * from %s where ts < now + 4m and ts > now + 5m' % + 'select * from %s where ts < 1605045600000 + 240001 and ts > 1605045600000 + 300001' % (tb)) # TSIM: if $rows != 0 then tdLog.info('tdSql.checkRow(0)') @@ -189,25 +187,25 @@ class TDTestCase: tdSql.checkRows(0) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $tb where ts > now + 4m and ts < now + 3m + # TSIM: sql select * from $tb where ts > 1605045600000 + 240001 and ts < 1605045600000 + 180001 tdLog.info( - 'select * from %s where ts > now + 4m and ts < now + 3m' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 180001' % (tb)) tdSql.query( - 'select * from %s where ts > now + 4m and ts < now + 3m' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 180001' % (tb)) # TSIM: if $rows != 0 then tdLog.info('tdSql.checkRow(0)') tdSql.checkRows(0) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $tb where ts > now + 4m and ts > now + 5m and - # ts < now + 6m + # TSIM: sql select * from $tb where ts > 1605045600000 + 240001 and ts > 1605045600000 + 300001 and + # ts < 1605045600000 + 360001 tdLog.info( - 'select * from %s where ts > now + 4m and ts > now + 5m and ts < now + 6m' % + 'select * from %s where ts > 1605045600000 + 240001 and ts > 1605045600000 + 300001 and ts < 1605045600000 + 360001' % (tb)) tdSql.query( - 'select * from %s where ts > now + 4m and ts > now + 5m and ts < now + 6m' % + 'select * from %s where ts > 1605045600000 + 240001 and ts > 1605045600000 + 300001 and ts < 1605045600000 + 360001' % (tb)) # TSIM: if $rows != 1 then tdLog.info('tdSql.checkRow(1)') @@ -226,36 +224,36 @@ class TDTestCase: # TSIM: return -1 # TSIM: endi # TSIM: - # TSIM: sql select * from $mt where ts < now + 4m - tdLog.info('select * from %s where ts < now + 4m' % (mt)) - tdSql.query('select * from %s where ts < now + 4m' % (mt)) + # TSIM: sql select * from $mt where ts < 1605045600000 + 240001 + tdLog.info('select * from %s where ts < 1605045600000 + 240001' % (mt)) + tdSql.query('select * from %s where ts < 1605045600000 + 240001' % (mt)) # TSIM: if $rows != 50 then tdLog.info('tdSql.checkRow(50)') tdSql.checkRows(50) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m - tdLog.info('select * from %s where ts > now + 4m' % (mt)) - tdSql.query('select * from %s where ts > now + 4m' % (mt)) + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 + tdLog.info('select * from %s where ts > 1605045600000 + 240001' % (mt)) + tdSql.query('select * from %s where ts > 1605045600000 + 240001' % (mt)) # TSIM: if $rows != 150 then tdLog.info('tdSql.checkRow(150)') tdSql.checkRows(150) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts = now + 4m - tdLog.info('select * from %s where ts = now + 4m' % (mt)) - tdSql.query('select * from %s where ts = now + 4m' % (mt)) + # TSIM: sql select * from $mt where ts = 1605045600000 + 240001 + tdLog.info('select * from %s where ts = 1605045600000 + 240001' % (mt)) + tdSql.query('select * from %s where ts = 1605045600000 + 240001' % (mt)) # TSIM: if $rows != 0 then tdLog.info('tdSql.checkRow(0)') tdSql.checkRows(0) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and ts < now + 5m + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 tdLog.info( - 'select * from %s where ts > now + 4m and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001' % (mt)) # TSIM: if $rows != 10 then tdLog.info('tdSql.checkRow(10)') @@ -332,94 +330,94 @@ class TDTestCase: # TSIM: # TSIM: print =============== step5 tdLog.info('=============== step5') - # TSIM: sql select * from $mt where ts > now + 4m and tgcol = 1 - tdLog.info('select * from %s where ts > now + 4m and tgcol = 1' % (mt)) + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol = 1 + tdLog.info('select * from %s where ts > 1605045600000 + 240001 and tgcol = 1' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol = 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol = 1' % (mt)) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and tgcol <> 1 + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol <> 1 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol <> 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol <> 1' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol <> 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol <> 1' % (mt)) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts < now + 4m and tgcol = 0 - tdLog.info('select * from %s where ts < now + 4m and tgcol = 0' % (mt)) + # TSIM: sql select * from $mt where ts < 1605045600000 + 240001 and tgcol = 0 + tdLog.info('select * from %s where ts < 1605045600000 + 240001 and tgcol = 0' % (mt)) tdSql.query( - 'select * from %s where ts < now + 4m and tgcol = 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol = 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts < now + 4m and tgcol <> 0 + # TSIM: sql select * from $mt where ts < 1605045600000 + 240001 and tgcol <> 0 tdLog.info( - 'select * from %s where ts < now + 4m and tgcol <> 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol <> 0' % (mt)) tdSql.query( - 'select * from %s where ts < now + 4m and tgcol <> 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol <> 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts <= now + 4m and tgcol = 0 + # TSIM: sql select * from $mt where ts <= 1605045600000 + 240001 and tgcol = 0 tdLog.info( - 'select * from %s where ts <= now + 4m and tgcol = 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol = 0' % (mt)) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol = 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol = 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts <= now + 4m and tgcol <> 0 + # TSIM: sql select * from $mt where ts <= 1605045600000 + 240001 and tgcol <> 0 tdLog.info( - 'select * from %s where ts <= now + 4m and tgcol <> 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol <> 0' % (mt)) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol <> 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol <> 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and ts < now + 5m and + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and # tgcol <> 0 tdLog.info( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol <> 0' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol <> 0' % (mt)) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') tdSql.checkRows(5) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and tgcol <> 0 and ts - # < now + 5m + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol <> 0 and ts + # < 1605045600000 + 300001 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol <> 0 and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol <> 0 and ts < 1605045600000 + 300001' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol <> 0 and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol <> 0 and ts < 1605045600000 + 300001' % (mt)) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') @@ -466,12 +464,12 @@ class TDTestCase: # TSIM: print =============== step8 tdLog.info('=============== step8') # TSIM: sql select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), - # max(tbcol), first(tbcol), last(tbcol) from $mt where ts < now + 4m + # max(tbcol), first(tbcol), last(tbcol) from $mt where ts < 1605045600000 + 240001 tdLog.info( - 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m' % + 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001' % (mt)) tdSql.query( - 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m' % + 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001' % (mt)) # TSIM: print $data00 $data01 $data02 $data03 $data04 $data05 $data06 tdLog.info('$data00 $data01 $data02 $data03 $data04 $data05 $data06') @@ -521,13 +519,13 @@ class TDTestCase: # TSIM: print =============== step11 tdLog.info('=============== step11') # TSIM: sql select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), - # max(tbcol), first(tbcol), last(tbcol) from $mt where ts < now + 4m + # max(tbcol), first(tbcol), last(tbcol) from $mt where ts < 1605045600000 + 240001 # group by tgcol tdLog.info( - 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m group by tgcol' % + 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001 group by tgcol' % (mt)) tdSql.query( - 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m group by tgcol' % + 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001 group by tgcol' % (mt)) # TSIM: print $data00 $data01 $data02 $data03 $data04 $data05 $data06 tdLog.info('$data00 $data01 $data02 $data03 $data04 $data05 $data06') diff --git a/tests/pytest/tag_lite/int_binary.py b/tests/pytest/tag_lite/int_binary.py index 7760814f664b4b04d42b67bba3f86ce069928b70..6ce9a9a431f644e1a6c9e7c9dece955dc9f40bfd 100644 --- a/tests/pytest/tag_lite/int_binary.py +++ b/tests/pytest/tag_lite/int_binary.py @@ -72,14 +72,13 @@ class TDTestCase: # TSIM: while $x < $rowNum while (x < rowNum): # TSIM: $ms = $x . m - ms = "%dm" % x - # TSIM: sql insert into $tb values (now + $ms , $x ) + ms = x * 60000 tdLog.info( - 'insert into %s values (now + %s , %d )' % - (tb, ms, x)) + "insert into %s values (%d, %d)" % + (tb, 1605045600000 + ms, x)) tdSql.execute( - 'insert into %s values (now + %s , %d )' % - (tb, ms, x)) + "insert into %s values (%d, %d)" % + (tb, 1605045600000 + ms, x)) # TSIM: $x = $x + 1 x = x + 1 # TSIM: endw @@ -98,14 +97,13 @@ class TDTestCase: # TSIM: while $x < $rowNum while (x < rowNum): # TSIM: $ms = $x . m - ms = "%dm" % x - # TSIM: sql insert into $tb values (now + $ms , $x ) + ms = x * 60000 tdLog.info( - 'insert into %s values (now + %s , %d )' % - (tb, ms, x)) + "insert into %s values (%d, %d)" % + (tb, 1605045600000 + ms, x)) tdSql.execute( - 'insert into %s values (now + %s , %d )' % - (tb, ms, x)) + "insert into %s values (%d, %d)" % + (tb, 1605045600000 + ms, x)) # TSIM: $x = $x + 1 x = x + 1 # TSIM: endw @@ -124,36 +122,36 @@ class TDTestCase: # TSIM: return -1 # TSIM: endi # TSIM: - # TSIM: sql select * from $mt where ts < now + 4m - tdLog.info('select * from %s where ts < now + 4m' % (mt)) - tdSql.query('select * from %s where ts < now + 4m' % (mt)) + # TSIM: sql select * from $mt where ts < 1605045600000 + 240001 + tdLog.info('select * from %s where ts < 1605045600000 + 240001' % (mt)) + tdSql.query('select * from %s where ts < 1605045600000 + 240001' % (mt)) # TSIM: if $rows != 50 then tdLog.info('tdSql.checkRow(50)') tdSql.checkRows(50) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m - tdLog.info('select * from %s where ts > now + 4m' % (mt)) - tdSql.query('select * from %s where ts > now + 4m' % (mt)) + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 + tdLog.info('select * from %s where ts > 1605045600000 + 240001' % (mt)) + tdSql.query('select * from %s where ts > 1605045600000 + 240001' % (mt)) # TSIM: if $rows != 150 then tdLog.info('tdSql.checkRow(150)') tdSql.checkRows(150) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts = now + 4m - tdLog.info('select * from %s where ts = now + 4m' % (mt)) - tdSql.query('select * from %s where ts = now + 4m' % (mt)) + # TSIM: sql select * from $mt where ts = 1605045600000 + 240001 + tdLog.info('select * from %s where ts = 1605045600000 + 240001' % (mt)) + tdSql.query('select * from %s where ts = 1605045600000 + 240001' % (mt)) # TSIM: if $rows != 0 then tdLog.info('tdSql.checkRow(0)') tdSql.checkRows(0) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and ts < now + 5m + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 tdLog.info( - 'select * from %s where ts > now + 4m and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001' % (mt)) # TSIM: if $rows != 10 then tdLog.info('tdSql.checkRow(10)') @@ -265,94 +263,94 @@ class TDTestCase: # TSIM: # TSIM: print =============== step5 tdLog.info('=============== step5') - # TSIM: sql select * from $mt where ts > now + 4m and tgcol = 1 - tdLog.info('select * from %s where ts > now + 4m and tgcol = 1' % (mt)) + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol = 1 + tdLog.info('select * from %s where ts > 1605045600000 + 240001 and tgcol = 1' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol = 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol = 1' % (mt)) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and tgcol <> 1 + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol <> 1 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol <> 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol <> 1' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol <> 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol <> 1' % (mt)) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts < now + 4m and tgcol = 0 - tdLog.info('select * from %s where ts < now + 4m and tgcol = 0' % (mt)) + # TSIM: sql select * from $mt where ts < 1605045600000 + 240001 and tgcol = 0 + tdLog.info('select * from %s where ts < 1605045600000 + 240001 and tgcol = 0' % (mt)) tdSql.query( - 'select * from %s where ts < now + 4m and tgcol = 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol = 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts < now + 4m and tgcol <> 0 + # TSIM: sql select * from $mt where ts < 1605045600000 + 240001 and tgcol <> 0 tdLog.info( - 'select * from %s where ts < now + 4m and tgcol <> 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol <> 0' % (mt)) tdSql.query( - 'select * from %s where ts < now + 4m and tgcol <> 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol <> 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts <= now + 4m and tgcol = 0 + # TSIM: sql select * from $mt where ts <= 1605045600000 + 240001 and tgcol = 0 tdLog.info( - 'select * from %s where ts <= now + 4m and tgcol = 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol = 0' % (mt)) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol = 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol = 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts <= now + 4m and tgcol <> 0 + # TSIM: sql select * from $mt where ts <= 1605045600000 + 240001 and tgcol <> 0 tdLog.info( - 'select * from %s where ts <= now + 4m and tgcol <> 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol <> 0' % (mt)) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol <> 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol <> 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and ts < now + 5m and + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and # tgcol <> 0 tdLog.info( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol <> 0' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol <> 0' % (mt)) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') tdSql.checkRows(5) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and tgcol <> 0 and ts - # < now + 5m + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol <> 0 and ts + # < 1605045600000 + 300001 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol <> 0 and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol <> 0 and ts < 1605045600000 + 300001' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol <> 0 and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol <> 0 and ts < 1605045600000 + 300001' % (mt)) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') @@ -362,98 +360,98 @@ class TDTestCase: # TSIM: # TSIM: print =============== step6 tdLog.info('=============== step6') - # TSIM: sql select * from $mt where ts > now + 4m and tgcol2 = '1' + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol2 = '1' tdLog.info( - 'select * from %s where ts > now + 4m and tgcol2 = "1"' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol2 = "1"' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol2 = "1"' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol2 = "1"' % (mt)) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and tgcol2 <> '1' + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol2 <> '1' tdLog.info( - 'select * from %s where ts > now + 4m and tgcol2 <> "1"' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol2 <> "1"' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol2 <> "1"' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol2 <> "1"' % (mt)) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts < now + 4m and tgcol2 = '0' + # TSIM: sql select * from $mt where ts < 1605045600000 + 240001 and tgcol2 = '0' tdLog.info( - 'select * from %s where ts < now + 4m and tgcol2 = "0"' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol2 = "0"' % (mt)) tdSql.query( - 'select * from %s where ts < now + 4m and tgcol2 = "0"' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol2 = "0"' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts < now + 4m and tgcol2 <> '0' + # TSIM: sql select * from $mt where ts < 1605045600000 + 240001 and tgcol2 <> '0' tdLog.info( - 'select * from %s where ts < now + 4m and tgcol2 <> "0"' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol2 <> "0"' % (mt)) tdSql.query( - 'select * from %s where ts < now + 4m and tgcol2 <> "0"' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol2 <> "0"' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts <= now + 4m and tgcol2 = '0' + # TSIM: sql select * from $mt where ts <= 1605045600000 + 240001 and tgcol2 = '0' tdLog.info( - 'select * from %s where ts <= now + 4m and tgcol2 = "0"' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol2 = "0"' % (mt)) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol2 = "0"' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol2 = "0"' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts <= now + 4m and tgcol2 <> '0' + # TSIM: sql select * from $mt where ts <= 1605045600000 + 240001 and tgcol2 <> '0' tdLog.info( - 'select * from %s where ts <= now + 4m and tgcol2 <> "0"' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol2 <> "0"' % (mt)) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol2 <> "0"' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol2 <> "0"' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and ts < now + 5m and + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and # tgcol2 <> '0' tdLog.info( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol2 <> "0"' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol2 <> "0"' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol2 <> "0"' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol2 <> "0"' % (mt)) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') tdSql.checkRows(5) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and tgcol2 <> '0' and - # ts < now + 5m + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol2 <> '0' and + # ts < 1605045600000 + 300001 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol2 <> "0" and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol2 <> "0" and ts < 1605045600000 + 300001' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol2 <> "0" and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol2 <> "0" and ts < 1605045600000 + 300001' % (mt)) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') @@ -463,104 +461,104 @@ class TDTestCase: # TSIM: # TSIM: print =============== step7 tdLog.info('=============== step7') - # TSIM: sql select * from $mt where ts > now + 4m and tgcol2 = '1' and + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol2 = '1' and # tgcol = 1 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol2 = "1" and tgcol = 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol2 = "1" and tgcol = 1' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol2 = "1" and tgcol = 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol2 = "1" and tgcol = 1' % (mt)) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and tgcol2 <> '1' and + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol2 <> '1' and # tgcol <> 1 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol2 <> "1" and tgcol <> 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol2 <> "1" and tgcol <> 1' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol2 <> "1" and tgcol <> 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol2 <> "1" and tgcol <> 1' % (mt)) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts < now + 4m and tgcol2 = '0' and + # TSIM: sql select * from $mt where ts < 1605045600000 + 240001 and tgcol2 = '0' and # tgcol = 0 tdLog.info( - 'select * from %s where ts < now + 4m and tgcol2 = "0" and tgcol = 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol2 = "0" and tgcol = 0' % (mt)) tdSql.query( - 'select * from %s where ts < now + 4m and tgcol2 = "0" and tgcol = 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol2 = "0" and tgcol = 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts < now + 4m and tgcol2 <> '0' and + # TSIM: sql select * from $mt where ts < 1605045600000 + 240001 and tgcol2 <> '0' and # tgcol <> 0 tdLog.info( - 'select * from %s where ts < now + 4m and tgcol2 <> "0" and tgcol <> 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol2 <> "0" and tgcol <> 0' % (mt)) tdSql.query( - 'select * from %s where ts < now + 4m and tgcol2 <> "0" and tgcol <> 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol2 <> "0" and tgcol <> 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts <= now + 4m and tgcol2 = '0' and + # TSIM: sql select * from $mt where ts <= 1605045600000 + 240001 and tgcol2 = '0' and # tgcol = 0 tdLog.info( - 'select * from %s where ts <= now + 4m and tgcol2 = "0" and tgcol = 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol2 = "0" and tgcol = 0' % (mt)) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol2 = "0" and tgcol = 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol2 = "0" and tgcol = 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts <= now + 4m and tgcol2 <> '0' + # TSIM: sql select * from $mt where ts <= 1605045600000 + 240001 and tgcol2 <> '0' # and tgcol <> 0 tdLog.info( - 'select * from %s where ts <= now + 4m and tgcol2 <> "0" and tgcol <> 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol2 <> "0" and tgcol <> 0' % (mt)) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol2 <> "0" and tgcol <> 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol2 <> "0" and tgcol <> 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and ts < now + 5m and + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and # tgcol2 <> '0' and tgcol <> 0 tdLog.info( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol2 <> "0" and tgcol <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol2 <> "0" and tgcol <> 0' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol2 <> "0" and tgcol <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol2 <> "0" and tgcol <> 0' % (mt)) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') tdSql.checkRows(5) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and tgcol2 <> '0' and - # ts < now + 5m and ts < now + 5m and tgcol <> 0 + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol2 <> '0' and + # ts < 1605045600000 + 300001 and ts < 1605045600000 + 300001 and tgcol <> 0 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol2 <> "0" and ts < now + 5m and ts < now + 5m and tgcol <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol2 <> "0" and ts < 1605045600000 + 300001 and ts < 1605045600000 + 300001 and tgcol <> 0' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol2 <> "0" and ts < now + 5m and ts < now + 5m and tgcol <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol2 <> "0" and ts < 1605045600000 + 300001 and ts < 1605045600000 + 300001 and tgcol <> 0' % (mt)) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') @@ -640,12 +638,12 @@ class TDTestCase: # TSIM: print =============== step10 tdLog.info('=============== step10') # TSIM: sql select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), - # max(tbcol), first(tbcol), last(tbcol) from $mt where ts < now + 4m + # max(tbcol), first(tbcol), last(tbcol) from $mt where ts < 1605045600000 + 240001 tdLog.info( - 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m' % + 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001' % (mt)) tdSql.query( - 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m' % + 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001' % (mt)) # TSIM: print $data00 $data01 $data02 $data03 $data04 $data05 $data06 tdLog.info('$data00 $data01 $data02 $data03 $data04 $data05 $data06') @@ -730,13 +728,13 @@ class TDTestCase: # TSIM: print =============== step13 tdLog.info('=============== step13') # TSIM: sql select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), - # max(tbcol), first(tbcol), last(tbcol) from $mt where ts < now + 4m + # max(tbcol), first(tbcol), last(tbcol) from $mt where ts < 1605045600000 + 240001 # group by tgcol tdLog.info( - 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m group by tgcol' % + 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001 group by tgcol' % (mt)) tdSql.query( - 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m group by tgcol' % + 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001 group by tgcol' % (mt)) # TSIM: print $data00 $data01 $data02 $data03 $data04 $data05 $data06 tdLog.info('$data00 $data01 $data02 $data03 $data04 $data05 $data06') diff --git a/tests/pytest/tag_lite/int_float.py b/tests/pytest/tag_lite/int_float.py index 31c94130ab30e83c68ab017e44cf313202e6b966..341acfd5ae0784c0d0d46a0757490fdfe8bca599 100644 --- a/tests/pytest/tag_lite/int_float.py +++ b/tests/pytest/tag_lite/int_float.py @@ -72,14 +72,13 @@ class TDTestCase: # TSIM: while $x < $rowNum while (x < rowNum): # TSIM: $ms = $x . m - ms = "%dm" % x - # TSIM: sql insert into $tb values (now + $ms , $x ) + ms = x * 60000 tdLog.info( - 'insert into %s values (now + %s , %d )' % - (tb, ms, x)) + "insert into %s values (%d, %d)" % + (tb, 1605045600000 + ms, x)) tdSql.execute( - 'insert into %s values (now + %s , %d )' % - (tb, ms, x)) + "insert into %s values (%d, %d)" % + (tb, 1605045600000 + ms, x)) # TSIM: $x = $x + 1 x = x + 1 # TSIM: endw @@ -98,14 +97,13 @@ class TDTestCase: # TSIM: while $x < $rowNum while (x < rowNum): # TSIM: $ms = $x . m - ms = "%dm" % x - # TSIM: sql insert into $tb values (now + $ms , $x ) + ms = x * 60000 tdLog.info( - 'insert into %s values (now + %s , %d )' % - (tb, ms, x)) + "insert into %s values (%d, %d)" % + (tb, 1605045600000 + ms, x)) tdSql.execute( - 'insert into %s values (now + %s , %d )' % - (tb, ms, x)) + "insert into %s values (%d, %d)" % + (tb, 1605045600000 + ms, x)) # TSIM: $x = $x + 1 x = x + 1 # TSIM: endw @@ -124,36 +122,36 @@ class TDTestCase: # TSIM: return -1 # TSIM: endi # TSIM: - # TSIM: sql select * from $mt where ts < now + 4m - tdLog.info('select * from %s where ts < now + 4m' % (mt)) - tdSql.query('select * from %s where ts < now + 4m' % (mt)) + # TSIM: sql select * from $mt where ts < 1605045600000 + 240001 + tdLog.info('select * from %s where ts < 1605045600000 + 240001' % (mt)) + tdSql.query('select * from %s where ts < 1605045600000 + 240001' % (mt)) # TSIM: if $rows != 50 then tdLog.info('tdSql.checkRow(50)') tdSql.checkRows(50) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m - tdLog.info('select * from %s where ts > now + 4m' % (mt)) - tdSql.query('select * from %s where ts > now + 4m' % (mt)) + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 + tdLog.info('select * from %s where ts > 1605045600000 + 240001' % (mt)) + tdSql.query('select * from %s where ts > 1605045600000 + 240001' % (mt)) # TSIM: if $rows != 150 then tdLog.info('tdSql.checkRow(150)') tdSql.checkRows(150) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts = now + 4m - tdLog.info('select * from %s where ts = now + 4m' % (mt)) - tdSql.query('select * from %s where ts = now + 4m' % (mt)) + # TSIM: sql select * from $mt where ts = 1605045600000 + 240001 + tdLog.info('select * from %s where ts = 1605045600000 + 240001' % (mt)) + tdSql.query('select * from %s where ts = 1605045600000 + 240001' % (mt)) # TSIM: if $rows != 0 then tdLog.info('tdSql.checkRow(0)') tdSql.checkRows(0) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and ts < now + 5m + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 tdLog.info( - 'select * from %s where ts > now + 4m and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001' % (mt)) # TSIM: if $rows != 10 then tdLog.info('tdSql.checkRow(10)') @@ -301,94 +299,94 @@ class TDTestCase: # TSIM: # TSIM: print =============== step5 tdLog.info('=============== step5') - # TSIM: sql select * from $mt where ts > now + 4m and tgcol = 1 - tdLog.info('select * from %s where ts > now + 4m and tgcol = 1' % (mt)) + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol = 1 + tdLog.info('select * from %s where ts > 1605045600000 + 240001 and tgcol = 1' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol = 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol = 1' % (mt)) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and tgcol <> 1 + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol <> 1 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol <> 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol <> 1' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol <> 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol <> 1' % (mt)) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts < now + 4m and tgcol = 0 - tdLog.info('select * from %s where ts < now + 4m and tgcol = 0' % (mt)) + # TSIM: sql select * from $mt where ts < 1605045600000 + 240001 and tgcol = 0 + tdLog.info('select * from %s where ts < 1605045600000 + 240001 and tgcol = 0' % (mt)) tdSql.query( - 'select * from %s where ts < now + 4m and tgcol = 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol = 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts < now + 4m and tgcol <> 0 + # TSIM: sql select * from $mt where ts < 1605045600000 + 240001 and tgcol <> 0 tdLog.info( - 'select * from %s where ts < now + 4m and tgcol <> 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol <> 0' % (mt)) tdSql.query( - 'select * from %s where ts < now + 4m and tgcol <> 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol <> 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts <= now + 4m and tgcol = 0 + # TSIM: sql select * from $mt where ts <= 1605045600000 + 240001 and tgcol = 0 tdLog.info( - 'select * from %s where ts <= now + 4m and tgcol = 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol = 0' % (mt)) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol = 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol = 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts <= now + 4m and tgcol <> 0 + # TSIM: sql select * from $mt where ts <= 1605045600000 + 240001 and tgcol <> 0 tdLog.info( - 'select * from %s where ts <= now + 4m and tgcol <> 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol <> 0' % (mt)) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol <> 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol <> 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and ts < now + 5m and + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and # tgcol <> 0 tdLog.info( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol <> 0' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol <> 0' % (mt)) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') tdSql.checkRows(5) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and tgcol <> 0 and ts - # < now + 5m + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol <> 0 and ts + # < 1605045600000 + 300001 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol <> 0 and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol <> 0 and ts < 1605045600000 + 300001' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol <> 0 and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol <> 0 and ts < 1605045600000 + 300001' % (mt)) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') @@ -398,98 +396,98 @@ class TDTestCase: # TSIM: # TSIM: print =============== step6 tdLog.info('=============== step6') - # TSIM: sql select * from $mt where ts > now + 4m and tgcol2 = 1 + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol2 = 1 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol2 = 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol2 = 1' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol2 = 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol2 = 1' % (mt)) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and tgcol2 <> 1 + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol2 <> 1 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol2 <> 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol2 <> 1' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol2 <> 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol2 <> 1' % (mt)) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts < now + 4m and tgcol2 = 0 + # TSIM: sql select * from $mt where ts < 1605045600000 + 240001 and tgcol2 = 0 tdLog.info( - 'select * from %s where ts < now + 4m and tgcol2 = 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol2 = 0' % (mt)) tdSql.query( - 'select * from %s where ts < now + 4m and tgcol2 = 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol2 = 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts < now + 4m and tgcol2 <> 0 + # TSIM: sql select * from $mt where ts < 1605045600000 + 240001 and tgcol2 <> 0 tdLog.info( - 'select * from %s where ts < now + 4m and tgcol2 <> 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol2 <> 0' % (mt)) tdSql.query( - 'select * from %s where ts < now + 4m and tgcol2 <> 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol2 <> 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts <= now + 4m and tgcol2 = 0 + # TSIM: sql select * from $mt where ts <= 1605045600000 + 240001 and tgcol2 = 0 tdLog.info( - 'select * from %s where ts <= now + 4m and tgcol2 = 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol2 = 0' % (mt)) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol2 = 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol2 = 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts <= now + 4m and tgcol2 <> 0 + # TSIM: sql select * from $mt where ts <= 1605045600000 + 240001 and tgcol2 <> 0 tdLog.info( - 'select * from %s where ts <= now + 4m and tgcol2 <> 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol2 <> 0' % (mt)) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol2 <> 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol2 <> 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and ts < now + 5m and + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and # tgcol2 <> 0 tdLog.info( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol2 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol2 <> 0' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol2 <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol2 <> 0' % (mt)) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') tdSql.checkRows(5) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and tgcol2 <> 0 and - # ts < now + 5m + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol2 <> 0 and + # ts < 1605045600000 + 300001 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol2 <> 0 and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol2 <> 0 and ts < 1605045600000 + 300001' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol2 <> 0 and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol2 <> 0 and ts < 1605045600000 + 300001' % (mt)) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') @@ -499,104 +497,104 @@ class TDTestCase: # TSIM: # TSIM: print =============== step7 tdLog.info('=============== step7') - # TSIM: sql select * from $mt where ts > now + 4m and tgcol2 = 1 and + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol2 = 1 and # tgcol = 1 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol2 = 1 and tgcol = 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol2 = 1 and tgcol = 1' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol2 = 1 and tgcol = 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol2 = 1 and tgcol = 1' % (mt)) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and tgcol2 <> 1 and + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol2 <> 1 and # tgcol <> 1 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol2 <> 1 and tgcol <> 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol2 <> 1 and tgcol <> 1' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol2 <> 1 and tgcol <> 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol2 <> 1 and tgcol <> 1' % (mt)) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts < now + 4m and tgcol2 = 0 and + # TSIM: sql select * from $mt where ts < 1605045600000 + 240001 and tgcol2 = 0 and # tgcol = 0 tdLog.info( - 'select * from %s where ts < now + 4m and tgcol2 = 0 and tgcol = 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol2 = 0 and tgcol = 0' % (mt)) tdSql.query( - 'select * from %s where ts < now + 4m and tgcol2 = 0 and tgcol = 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol2 = 0 and tgcol = 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts < now + 4m and tgcol2 <> 0 and + # TSIM: sql select * from $mt where ts < 1605045600000 + 240001 and tgcol2 <> 0 and # tgcol <> 0 tdLog.info( - 'select * from %s where ts < now + 4m and tgcol2 <> 0 and tgcol <> 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol2 <> 0 and tgcol <> 0' % (mt)) tdSql.query( - 'select * from %s where ts < now + 4m and tgcol2 <> 0 and tgcol <> 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol2 <> 0 and tgcol <> 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts <= now + 4m and tgcol2 = 0 and + # TSIM: sql select * from $mt where ts <= 1605045600000 + 240001 and tgcol2 = 0 and # tgcol = 0 tdLog.info( - 'select * from %s where ts <= now + 4m and tgcol2 = 0 and tgcol = 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol2 = 0 and tgcol = 0' % (mt)) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol2 = 0 and tgcol = 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol2 = 0 and tgcol = 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts <= now + 4m and tgcol2 <> 0 and + # TSIM: sql select * from $mt where ts <= 1605045600000 + 240001 and tgcol2 <> 0 and # tgcol <> 0 tdLog.info( - 'select * from %s where ts <= now + 4m and tgcol2 <> 0 and tgcol <> 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol2 <> 0 and tgcol <> 0' % (mt)) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol2 <> 0 and tgcol <> 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol2 <> 0 and tgcol <> 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and ts < now + 5m and + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and # tgcol2 <> 0 and tgcol <> 0 tdLog.info( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol2 <> 0 and tgcol <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol2 <> 0 and tgcol <> 0' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol2 <> 0 and tgcol <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol2 <> 0 and tgcol <> 0' % (mt)) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') tdSql.checkRows(5) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and tgcol2 <> 0 and - # ts < now + 5m and ts < now + 5m and tgcol <> 0 + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol2 <> 0 and + # ts < 1605045600000 + 300001 and ts < 1605045600000 + 300001 and tgcol <> 0 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol2 <> 0 and ts < now + 5m and ts < now + 5m and tgcol <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol2 <> 0 and ts < 1605045600000 + 300001 and ts < 1605045600000 + 300001 and tgcol <> 0' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol2 <> 0 and ts < now + 5m and ts < now + 5m and tgcol <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol2 <> 0 and ts < 1605045600000 + 300001 and ts < 1605045600000 + 300001 and tgcol <> 0' % (mt)) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') @@ -676,12 +674,12 @@ class TDTestCase: # TSIM: print =============== step10 tdLog.info('=============== step10') # TSIM: sql select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), - # max(tbcol), first(tbcol), last(tbcol) from $mt where ts < now + 4m + # max(tbcol), first(tbcol), last(tbcol) from $mt where ts < 1605045600000 + 240001 tdLog.info( - 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m' % + 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001' % (mt)) tdSql.query( - 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m' % + 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001' % (mt)) # TSIM: print $data00 $data01 $data02 $data03 $data04 $data05 $data06 tdLog.info('$data00 $data01 $data02 $data03 $data04 $data05 $data06') @@ -766,13 +764,13 @@ class TDTestCase: # TSIM: print =============== step13 tdLog.info('=============== step13') # TSIM: sql select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), - # max(tbcol), first(tbcol), last(tbcol) from $mt where ts < now + 4m + # max(tbcol), first(tbcol), last(tbcol) from $mt where ts < 1605045600000 + 240001 # group by tgcol tdLog.info( - 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m group by tgcol' % + 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001 group by tgcol' % (mt)) tdSql.query( - 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m group by tgcol' % + 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001 group by tgcol' % (mt)) # TSIM: print $data00 $data01 $data02 $data03 $data04 $data05 $data06 tdLog.info('$data00 $data01 $data02 $data03 $data04 $data05 $data06') diff --git a/tests/pytest/tag_lite/smallint.py b/tests/pytest/tag_lite/smallint.py index c060e3f82b6b5f2b6d32fd50e5ea8181f655ad9b..93fde22ca92219852426ac18c550231130d23384 100644 --- a/tests/pytest/tag_lite/smallint.py +++ b/tests/pytest/tag_lite/smallint.py @@ -72,14 +72,13 @@ class TDTestCase: # TSIM: while $x < $rowNum while (x < rowNum): # TSIM: $ms = $x . m - ms = "%dm" % x - # TSIM: sql insert into $tb values (now + $ms , $x ) + ms = x * 60000 tdLog.info( - 'insert into %s values (now + %s , %d )' % - (tb, ms, x)) + "insert into %s values (%d, %d)" % + (tb, 1605045600000 + ms, x)) tdSql.execute( - 'insert into %s values (now + %s , %d )' % - (tb, ms, x)) + "insert into %s values (%d, %d)" % + (tb, 1605045600000 + ms, x)) # TSIM: $x = $x + 1 x = x + 1 # TSIM: endw @@ -98,14 +97,13 @@ class TDTestCase: # TSIM: while $x < $rowNum while (x < rowNum): # TSIM: $ms = $x . m - ms = "%dm" % x - # TSIM: sql insert into $tb values (now + $ms , $x ) + ms = x * 60000 tdLog.info( - 'insert into %s values (now + %s , %d )' % - (tb, ms, x)) + "insert into %s values (%d, %d)" % + (tb, 1605045600000 + ms, x)) tdSql.execute( - 'insert into %s values (now + %s , %d )' % - (tb, ms, x)) + "insert into %s values (%d, %d)" % + (tb, 1605045600000 + ms, x)) # TSIM: $x = $x + 1 x = x + 1 # TSIM: endw @@ -124,56 +122,56 @@ class TDTestCase: tdSql.checkRows(rowNum) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $tb where ts < now + 4m - tdLog.info('select * from %s where ts < now + 4m' % (tb)) - tdSql.query('select * from %s where ts < now + 4m' % (tb)) + # TSIM: sql select * from $tb where ts < 1605045600000 + 240001 + tdLog.info('select * from %s where ts < 1605045600000 + 240001' % (tb)) + tdSql.query('select * from %s where ts < 1605045600000 + 240001' % (tb)) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') tdSql.checkRows(5) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $tb where ts <= now + 4m - tdLog.info('select * from %s where ts <= now + 4m' % (tb)) - tdSql.query('select * from %s where ts <= now + 4m' % (tb)) + # TSIM: sql select * from $tb where ts <= 1605045600000 + 240001 + tdLog.info('select * from %s where ts <= 1605045600000 + 240001' % (tb)) + tdSql.query('select * from %s where ts <= 1605045600000 + 240001' % (tb)) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') tdSql.checkRows(5) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $tb where ts > now + 4m - tdLog.info('select * from %s where ts > now + 4m' % (tb)) - tdSql.query('select * from %s where ts > now + 4m' % (tb)) + # TSIM: sql select * from $tb where ts > 1605045600000 + 240001 + tdLog.info('select * from %s where ts > 1605045600000 + 240001' % (tb)) + tdSql.query('select * from %s where ts > 1605045600000 + 240001' % (tb)) # TSIM: if $rows != 15 then tdLog.info('tdSql.checkRow(15)') tdSql.checkRows(15) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $tb where ts >= now + 4m - tdLog.info('select * from %s where ts >= now + 4m' % (tb)) - tdSql.query('select * from %s where ts >= now + 4m' % (tb)) + # TSIM: sql select * from $tb where ts >= 1605045600000 + 240001 + tdLog.info('select * from %s where ts >= 1605045600000 + 240001' % (tb)) + tdSql.query('select * from %s where ts >= 1605045600000 + 240001' % (tb)) # TSIM: if $rows != 15 then tdLog.info('tdSql.checkRow(15)') tdSql.checkRows(15) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $tb where ts > now + 4m and ts < now + 5m + # TSIM: sql select * from $tb where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 tdLog.info( - 'select * from %s where ts > now + 4m and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001' % (tb)) tdSql.query( - 'select * from %s where ts > now + 4m and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001' % (tb)) # TSIM: if $rows != 1 then tdLog.info('tdSql.checkRow(1)') tdSql.checkRows(1) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $tb where ts < now + 4m and ts > now + 5m + # TSIM: sql select * from $tb where ts < 1605045600000 + 240001 and ts > 1605045600000 + 300001 tdLog.info( - 'select * from %s where ts < now + 4m and ts > now + 5m' % + 'select * from %s where ts < 1605045600000 + 240001 and ts > 1605045600000 + 300001' % (tb)) tdSql.query( - 'select * from %s where ts < now + 4m and ts > now + 5m' % + 'select * from %s where ts < 1605045600000 + 240001 and ts > 1605045600000 + 300001' % (tb)) # TSIM: if $rows != 0 then tdLog.info('tdSql.checkRow(0)') @@ -190,25 +188,25 @@ class TDTestCase: tdSql.checkRows(0) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $tb where ts > now + 4m and ts < now + 3m + # TSIM: sql select * from $tb where ts > 1605045600000 + 240001 and ts < 1605045600000 + 180001 tdLog.info( - 'select * from %s where ts > now + 4m and ts < now + 3m' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 180001' % (tb)) tdSql.query( - 'select * from %s where ts > now + 4m and ts < now + 3m' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 180001' % (tb)) # TSIM: if $rows != 0 then tdLog.info('tdSql.checkRow(0)') tdSql.checkRows(0) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $tb where ts > now + 4m and ts > now + 5m and - # ts < now + 6m + # TSIM: sql select * from $tb where ts > 1605045600000 + 240001 and ts > 1605045600000 + 300001 and + # ts < 1605045600000 + 360001 tdLog.info( - 'select * from %s where ts > now + 4m and ts > now + 5m and ts < now + 6m' % + 'select * from %s where ts > 1605045600000 + 240001 and ts > 1605045600000 + 300001 and ts < 1605045600000 + 360001' % (tb)) tdSql.query( - 'select * from %s where ts > now + 4m and ts > now + 5m and ts < now + 6m' % + 'select * from %s where ts > 1605045600000 + 240001 and ts > 1605045600000 + 300001 and ts < 1605045600000 + 360001' % (tb)) # TSIM: if $rows != 1 then tdLog.info('tdSql.checkRow(1)') @@ -227,36 +225,36 @@ class TDTestCase: # TSIM: return -1 # TSIM: endi # TSIM: - # TSIM: sql select * from $mt where ts < now + 4m - tdLog.info('select * from %s where ts < now + 4m' % (mt)) - tdSql.query('select * from %s where ts < now + 4m' % (mt)) + # TSIM: sql select * from $mt where ts < 1605045600000 + 240001 + tdLog.info('select * from %s where ts < 1605045600000 + 240001' % (mt)) + tdSql.query('select * from %s where ts < 1605045600000 + 240001' % (mt)) # TSIM: if $rows != 50 then tdLog.info('tdSql.checkRow(50)') tdSql.checkRows(50) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m - tdLog.info('select * from %s where ts > now + 4m' % (mt)) - tdSql.query('select * from %s where ts > now + 4m' % (mt)) + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 + tdLog.info('select * from %s where ts > 1605045600000 + 240001' % (mt)) + tdSql.query('select * from %s where ts > 1605045600000 + 240001' % (mt)) # TSIM: if $rows != 150 then tdLog.info('tdSql.checkRow(150)') tdSql.checkRows(150) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts = now + 4m - tdLog.info('select * from %s where ts = now + 4m' % (mt)) - tdSql.query('select * from %s where ts = now + 4m' % (mt)) + # TSIM: sql select * from $mt where ts = 1605045600000 + 240001 + tdLog.info('select * from %s where ts = 1605045600000 + 240001' % (mt)) + tdSql.query('select * from %s where ts = 1605045600000 + 240001' % (mt)) # TSIM: if $rows != 0 then tdLog.info('tdSql.checkRow(0)') tdSql.checkRows(0) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and ts < now + 5m + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 tdLog.info( - 'select * from %s where ts > now + 4m and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001' % (mt)) # TSIM: if $rows != 10 then tdLog.info('tdSql.checkRow(10)') @@ -333,94 +331,94 @@ class TDTestCase: # TSIM: # TSIM: print =============== step5 tdLog.info('=============== step5') - # TSIM: sql select * from $mt where ts > now + 4m and tgcol = 1 - tdLog.info('select * from %s where ts > now + 4m and tgcol = 1' % (mt)) + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol = 1 + tdLog.info('select * from %s where ts > 1605045600000 + 240001 and tgcol = 1' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol = 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol = 1' % (mt)) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and tgcol <> 1 + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol <> 1 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol <> 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol <> 1' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol <> 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol <> 1' % (mt)) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts < now + 4m and tgcol = 0 - tdLog.info('select * from %s where ts < now + 4m and tgcol = 0' % (mt)) + # TSIM: sql select * from $mt where ts < 1605045600000 + 240001 and tgcol = 0 + tdLog.info('select * from %s where ts < 1605045600000 + 240001 and tgcol = 0' % (mt)) tdSql.query( - 'select * from %s where ts < now + 4m and tgcol = 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol = 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts < now + 4m and tgcol <> 0 + # TSIM: sql select * from $mt where ts < 1605045600000 + 240001 and tgcol <> 0 tdLog.info( - 'select * from %s where ts < now + 4m and tgcol <> 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol <> 0' % (mt)) tdSql.query( - 'select * from %s where ts < now + 4m and tgcol <> 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol <> 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts <= now + 4m and tgcol = 0 + # TSIM: sql select * from $mt where ts <= 1605045600000 + 240001 and tgcol = 0 tdLog.info( - 'select * from %s where ts <= now + 4m and tgcol = 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol = 0' % (mt)) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol = 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol = 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts <= now + 4m and tgcol <> 0 + # TSIM: sql select * from $mt where ts <= 1605045600000 + 240001 and tgcol <> 0 tdLog.info( - 'select * from %s where ts <= now + 4m and tgcol <> 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol <> 0' % (mt)) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol <> 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol <> 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and ts < now + 5m and + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and # tgcol <> 0 tdLog.info( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol <> 0' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol <> 0' % (mt)) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') tdSql.checkRows(5) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and tgcol <> 0 and ts - # < now + 5m + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol <> 0 and ts + # < 1605045600000 + 300001 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol <> 0 and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol <> 0 and ts < 1605045600000 + 300001' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol <> 0 and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol <> 0 and ts < 1605045600000 + 300001' % (mt)) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') @@ -467,12 +465,12 @@ class TDTestCase: # TSIM: print =============== step8 tdLog.info('=============== step8') # TSIM: sql select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), - # max(tbcol), first(tbcol), last(tbcol) from $mt where ts < now + 4m + # max(tbcol), first(tbcol), last(tbcol) from $mt where ts < 1605045600000 + 240001 tdLog.info( - 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m' % + 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001' % (mt)) tdSql.query( - 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m' % + 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001' % (mt)) # TSIM: print $data00 $data01 $data02 $data03 $data04 $data05 $data06 tdLog.info('$data00 $data01 $data02 $data03 $data04 $data05 $data06') @@ -522,13 +520,13 @@ class TDTestCase: # TSIM: print =============== step11 tdLog.info('=============== step11') # TSIM: sql select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), - # max(tbcol), first(tbcol), last(tbcol) from $mt where ts < now + 4m + # max(tbcol), first(tbcol), last(tbcol) from $mt where ts < 1605045600000 + 240001 # group by tgcol tdLog.info( - 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m group by tgcol' % + 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001 group by tgcol' % (mt)) tdSql.query( - 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m group by tgcol' % + 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001 group by tgcol' % (mt)) # TSIM: print $data00 $data01 $data02 $data03 $data04 $data05 $data06 tdLog.info('$data00 $data01 $data02 $data03 $data04 $data05 $data06') diff --git a/tests/pytest/tag_lite/tinyint.py b/tests/pytest/tag_lite/tinyint.py index 089dd46569578c1ca33d73639cb36a0bba03e0f0..fc4af4ee9648ef6aca5badeada5420063f76050b 100644 --- a/tests/pytest/tag_lite/tinyint.py +++ b/tests/pytest/tag_lite/tinyint.py @@ -72,14 +72,13 @@ class TDTestCase: # TSIM: while $x < $rowNum while (x < rowNum): # TSIM: $ms = $x . m - ms = "%dm" % x - # TSIM: sql insert into $tb values (now + $ms , $x ) + ms = x * 60000 tdLog.info( - 'insert into %s values (now + %s , %d )' % - (tb, ms, x)) + "insert into %s values (%d, %d)" % + (tb, 1605045600000 + ms, x)) tdSql.execute( - 'insert into %s values (now + %s , %d )' % - (tb, ms, x)) + "insert into %s values (%d, %d)" % + (tb, 1605045600000 + ms, x)) # TSIM: $x = $x + 1 x = x + 1 # TSIM: endw @@ -98,14 +97,13 @@ class TDTestCase: # TSIM: while $x < $rowNum while (x < rowNum): # TSIM: $ms = $x . m - ms = "%dm" % x - # TSIM: sql insert into $tb values (now + $ms , $x ) + ms = x * 60000 tdLog.info( - 'insert into %s values (now + %s , %d )' % - (tb, ms, x)) + "insert into %s values (%d, %d)" % + (tb, 1605045600000 + ms, x)) tdSql.execute( - 'insert into %s values (now + %s , %d )' % - (tb, ms, x)) + "insert into %s values (%d, %d)" % + (tb, 1605045600000 + ms, x)) # TSIM: $x = $x + 1 x = x + 1 # TSIM: endw @@ -124,56 +122,56 @@ class TDTestCase: tdSql.checkRows(rowNum) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $tb where ts < now + 4m - tdLog.info('select * from %s where ts < now + 4m' % (tb)) - tdSql.query('select * from %s where ts < now + 4m' % (tb)) + # TSIM: sql select * from $tb where ts < 1605045600000 + 240001 + tdLog.info('select * from %s where ts < 1605045600000 + 240001' % (tb)) + tdSql.query('select * from %s where ts < 1605045600000 + 240001' % (tb)) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') tdSql.checkRows(5) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $tb where ts <= now + 4m - tdLog.info('select * from %s where ts <= now + 4m' % (tb)) - tdSql.query('select * from %s where ts <= now + 4m' % (tb)) + # TSIM: sql select * from $tb where ts <= 1605045600000 + 240001 + tdLog.info('select * from %s where ts <= 1605045600000 + 240001' % (tb)) + tdSql.query('select * from %s where ts <= 1605045600000 + 240001' % (tb)) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') tdSql.checkRows(5) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $tb where ts > now + 4m - tdLog.info('select * from %s where ts > now + 4m' % (tb)) - tdSql.query('select * from %s where ts > now + 4m' % (tb)) + # TSIM: sql select * from $tb where ts > 1605045600000 + 240001 + tdLog.info('select * from %s where ts > 1605045600000 + 240001' % (tb)) + tdSql.query('select * from %s where ts > 1605045600000 + 240001' % (tb)) # TSIM: if $rows != 15 then tdLog.info('tdSql.checkRow(15)') tdSql.checkRows(15) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $tb where ts >= now + 4m - tdLog.info('select * from %s where ts >= now + 4m' % (tb)) - tdSql.query('select * from %s where ts >= now + 4m' % (tb)) + # TSIM: sql select * from $tb where ts >= 1605045600000 + 240001 + tdLog.info('select * from %s where ts >= 1605045600000 + 240001' % (tb)) + tdSql.query('select * from %s where ts >= 1605045600000 + 240001' % (tb)) # TSIM: if $rows != 15 then tdLog.info('tdSql.checkRow(15)') tdSql.checkRows(15) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $tb where ts > now + 4m and ts < now + 5m + # TSIM: sql select * from $tb where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 tdLog.info( - 'select * from %s where ts > now + 4m and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001' % (tb)) tdSql.query( - 'select * from %s where ts > now + 4m and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001' % (tb)) # TSIM: if $rows != 1 then tdLog.info('tdSql.checkRow(1)') tdSql.checkRows(1) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $tb where ts < now + 4m and ts > now + 5m + # TSIM: sql select * from $tb where ts < 1605045600000 + 240001 and ts > 1605045600000 + 300001 tdLog.info( - 'select * from %s where ts < now + 4m and ts > now + 5m' % + 'select * from %s where ts < 1605045600000 + 240001 and ts > 1605045600000 + 300001' % (tb)) tdSql.query( - 'select * from %s where ts < now + 4m and ts > now + 5m' % + 'select * from %s where ts < 1605045600000 + 240001 and ts > 1605045600000 + 300001' % (tb)) # TSIM: if $rows != 0 then tdLog.info('tdSql.checkRow(0)') @@ -190,25 +188,25 @@ class TDTestCase: tdSql.checkRows(0) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $tb where ts > now + 4m and ts < now + 3m + # TSIM: sql select * from $tb where ts > 1605045600000 + 240001 and ts < 1605045600000 + 180001 tdLog.info( - 'select * from %s where ts > now + 4m and ts < now + 3m' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 180001' % (tb)) tdSql.query( - 'select * from %s where ts > now + 4m and ts < now + 3m' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 180001' % (tb)) # TSIM: if $rows != 0 then tdLog.info('tdSql.checkRow(0)') tdSql.checkRows(0) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $tb where ts > now + 4m and ts > now + 5m and - # ts < now + 6m + # TSIM: sql select * from $tb where ts > 1605045600000 + 240001 and ts > 1605045600000 + 300001 and + # ts < 1605045600000 + 360001 tdLog.info( - 'select * from %s where ts > now + 4m and ts > now + 5m and ts < now + 6m' % + 'select * from %s where ts > 1605045600000 + 240001 and ts > 1605045600000 + 300001 and ts < 1605045600000 + 360001' % (tb)) tdSql.query( - 'select * from %s where ts > now + 4m and ts > now + 5m and ts < now + 6m' % + 'select * from %s where ts > 1605045600000 + 240001 and ts > 1605045600000 + 300001 and ts < 1605045600000 + 360001' % (tb)) # TSIM: if $rows != 1 then tdLog.info('tdSql.checkRow(1)') @@ -227,36 +225,36 @@ class TDTestCase: # TSIM: return -1 # TSIM: endi # TSIM: - # TSIM: sql select * from $mt where ts < now + 4m - tdLog.info('select * from %s where ts < now + 4m' % (mt)) - tdSql.query('select * from %s where ts < now + 4m' % (mt)) + # TSIM: sql select * from $mt where ts < 1605045600000 + 240001 + tdLog.info('select * from %s where ts < 1605045600000 + 240001' % (mt)) + tdSql.query('select * from %s where ts < 1605045600000 + 240001' % (mt)) # TSIM: if $rows != 50 then tdLog.info('tdSql.checkRow(50)') tdSql.checkRows(50) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m - tdLog.info('select * from %s where ts > now + 4m' % (mt)) - tdSql.query('select * from %s where ts > now + 4m' % (mt)) + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 + tdLog.info('select * from %s where ts > 1605045600000 + 240001' % (mt)) + tdSql.query('select * from %s where ts > 1605045600000 + 240001' % (mt)) # TSIM: if $rows != 150 then tdLog.info('tdSql.checkRow(150)') tdSql.checkRows(150) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts = now + 4m - tdLog.info('select * from %s where ts = now + 4m' % (mt)) - tdSql.query('select * from %s where ts = now + 4m' % (mt)) + # TSIM: sql select * from $mt where ts = 1605045600000 + 240001 + tdLog.info('select * from %s where ts = 1605045600000 + 240001' % (mt)) + tdSql.query('select * from %s where ts = 1605045600000 + 240001' % (mt)) # TSIM: if $rows != 0 then tdLog.info('tdSql.checkRow(0)') tdSql.checkRows(0) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and ts < now + 5m + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 tdLog.info( - 'select * from %s where ts > now + 4m and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001' % (mt)) # TSIM: if $rows != 10 then tdLog.info('tdSql.checkRow(10)') @@ -333,94 +331,94 @@ class TDTestCase: # TSIM: # TSIM: print =============== step5 tdLog.info('=============== step5') - # TSIM: sql select * from $mt where ts > now + 4m and tgcol = 1 - tdLog.info('select * from %s where ts > now + 4m and tgcol = 1' % (mt)) + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol = 1 + tdLog.info('select * from %s where ts > 1605045600000 + 240001 and tgcol = 1' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol = 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol = 1' % (mt)) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and tgcol <> 1 + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol <> 1 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol <> 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol <> 1' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol <> 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol <> 1' % (mt)) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts < now + 4m and tgcol = 0 - tdLog.info('select * from %s where ts < now + 4m and tgcol = 0' % (mt)) + # TSIM: sql select * from $mt where ts < 1605045600000 + 240001 and tgcol = 0 + tdLog.info('select * from %s where ts < 1605045600000 + 240001 and tgcol = 0' % (mt)) tdSql.query( - 'select * from %s where ts < now + 4m and tgcol = 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol = 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts < now + 4m and tgcol <> 0 + # TSIM: sql select * from $mt where ts < 1605045600000 + 240001 and tgcol <> 0 tdLog.info( - 'select * from %s where ts < now + 4m and tgcol <> 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol <> 0' % (mt)) tdSql.query( - 'select * from %s where ts < now + 4m and tgcol <> 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol <> 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts <= now + 4m and tgcol = 0 + # TSIM: sql select * from $mt where ts <= 1605045600000 + 240001 and tgcol = 0 tdLog.info( - 'select * from %s where ts <= now + 4m and tgcol = 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol = 0' % (mt)) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol = 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol = 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts <= now + 4m and tgcol <> 0 + # TSIM: sql select * from $mt where ts <= 1605045600000 + 240001 and tgcol <> 0 tdLog.info( - 'select * from %s where ts <= now + 4m and tgcol <> 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol <> 0' % (mt)) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol <> 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol <> 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and ts < now + 5m and + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and # tgcol <> 0 tdLog.info( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol <> 0' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol <> 0' % (mt)) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') tdSql.checkRows(5) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and tgcol <> 0 and ts - # < now + 5m + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol <> 0 and ts + # < 1605045600000 + 300001 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol <> 0 and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol <> 0 and ts < 1605045600000 + 300001' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol <> 0 and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol <> 0 and ts < 1605045600000 + 300001' % (mt)) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') @@ -467,12 +465,12 @@ class TDTestCase: # TSIM: print =============== step8 tdLog.info('=============== step8') # TSIM: sql select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), - # max(tbcol), first(tbcol), last(tbcol) from $mt where ts < now + 4m + # max(tbcol), first(tbcol), last(tbcol) from $mt where ts < 1605045600000 + 240001 tdLog.info( - 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m' % + 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001' % (mt)) tdSql.query( - 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m' % + 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001' % (mt)) # TSIM: print $data00 $data01 $data02 $data03 $data04 $data05 $data06 tdLog.info('$data00 $data01 $data02 $data03 $data04 $data05 $data06') @@ -522,13 +520,13 @@ class TDTestCase: # TSIM: print =============== step11 tdLog.info('=============== step11') # TSIM: sql select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), - # max(tbcol), first(tbcol), last(tbcol) from $mt where ts < now + 4m + # max(tbcol), first(tbcol), last(tbcol) from $mt where ts < 1605045600000 + 240001 # group by tgcol tdLog.info( - 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m group by tgcol' % + 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001 group by tgcol' % (mt)) tdSql.query( - 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m group by tgcol' % + 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001 group by tgcol' % (mt)) # TSIM: print $data00 $data01 $data02 $data03 $data04 $data05 $data06 tdLog.info('$data00 $data01 $data02 $data03 $data04 $data05 $data06') diff --git a/tests/pytest/tag_lite/unsignedBigint.py b/tests/pytest/tag_lite/unsignedBigint.py index 032dacd366437c378b0b8c9b553d6495966cd563..6a33812f8839bf8c329c35b9c700bf5479d14a64 100644 --- a/tests/pytest/tag_lite/unsignedBigint.py +++ b/tests/pytest/tag_lite/unsignedBigint.py @@ -72,14 +72,13 @@ class TDTestCase: # TSIM: while $x < $rowNum while (x < rowNum): # TSIM: $ms = $x . m - ms = "%dm" % x - # TSIM: sql insert into $tb values (now + $ms , $x ) + ms = x * 60000 tdLog.info( - 'insert into %s values (now + %s , %d )' % - (tb, ms, x)) + "insert into %s values (%d, %d)" % + (tb, 1605045600000 + ms, x)) tdSql.execute( - 'insert into %s values (now + %s , %d )' % - (tb, ms, x)) + "insert into %s values (%d, %d)" % + (tb, 1605045600000 + ms, x)) # TSIM: $x = $x + 1 x = x + 1 # TSIM: endw @@ -98,14 +97,13 @@ class TDTestCase: # TSIM: while $x < $rowNum while (x < rowNum): # TSIM: $ms = $x . m - ms = "%dm" % x - # TSIM: sql insert into $tb values (now + $ms , $x ) + ms = x * 60000 tdLog.info( - 'insert into %s values (now + %s , %d )' % - (tb, ms, x)) + "insert into %s values (%d, %d)" % + (tb, 1605045600000 + ms, x)) tdSql.execute( - 'insert into %s values (now + %s , %d )' % - (tb, ms, x)) + "insert into %s values (%d, %d)" % + (tb, 1605045600000 + ms, x)) # TSIM: $x = $x + 1 x = x + 1 # TSIM: endw @@ -124,56 +122,56 @@ class TDTestCase: tdSql.checkRows(rowNum) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $tb where ts < now + 4m - tdLog.info('select * from %s where ts < now + 4m' % (tb)) - tdSql.query('select * from %s where ts < now + 4m' % (tb)) + # TSIM: sql select * from $tb where ts < 1605045600000 + 240001 + tdLog.info('select * from %s where ts < 1605045600000 + 240001' % (tb)) + tdSql.query('select * from %s where ts < 1605045600000 + 240001' % (tb)) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') tdSql.checkRows(5) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $tb where ts <= now + 4m - tdLog.info('select * from %s where ts <= now + 4m' % (tb)) - tdSql.query('select * from %s where ts <= now + 4m' % (tb)) + # TSIM: sql select * from $tb where ts <= 1605045600000 + 240001 + tdLog.info('select * from %s where ts <= 1605045600000 + 240001' % (tb)) + tdSql.query('select * from %s where ts <= 1605045600000 + 240001' % (tb)) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') tdSql.checkRows(5) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $tb where ts > now + 4m - tdLog.info('select * from %s where ts > now + 4m' % (tb)) - tdSql.query('select * from %s where ts > now + 4m' % (tb)) + # TSIM: sql select * from $tb where ts > 1605045600000 + 240001 + tdLog.info('select * from %s where ts > 1605045600000 + 240001' % (tb)) + tdSql.query('select * from %s where ts > 1605045600000 + 240001' % (tb)) # TSIM: if $rows != 15 then tdLog.info('tdSql.checkRow(15)') tdSql.checkRows(15) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $tb where ts >= now + 4m - tdLog.info('select * from %s where ts >= now + 4m' % (tb)) - tdSql.query('select * from %s where ts >= now + 4m' % (tb)) + # TSIM: sql select * from $tb where ts >= 1605045600000 + 240001 + tdLog.info('select * from %s where ts >= 1605045600000 + 240001' % (tb)) + tdSql.query('select * from %s where ts >= 1605045600000 + 240001' % (tb)) # TSIM: if $rows != 15 then tdLog.info('tdSql.checkRow(15)') tdSql.checkRows(15) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $tb where ts > now + 4m and ts < now + 5m + # TSIM: sql select * from $tb where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 tdLog.info( - 'select * from %s where ts > now + 4m and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001' % (tb)) tdSql.query( - 'select * from %s where ts > now + 4m and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001' % (tb)) # TSIM: if $rows != 1 then tdLog.info('tdSql.checkRow(1)') tdSql.checkRows(1) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $tb where ts < now + 4m and ts > now + 5m + # TSIM: sql select * from $tb where ts < 1605045600000 + 240001 and ts > 1605045600000 + 300001 tdLog.info( - 'select * from %s where ts < now + 4m and ts > now + 5m' % + 'select * from %s where ts < 1605045600000 + 240001 and ts > 1605045600000 + 300001' % (tb)) tdSql.query( - 'select * from %s where ts < now + 4m and ts > now + 5m' % + 'select * from %s where ts < 1605045600000 + 240001 and ts > 1605045600000 + 300001' % (tb)) # TSIM: if $rows != 0 then tdLog.info('tdSql.checkRow(0)') @@ -190,25 +188,25 @@ class TDTestCase: tdSql.checkRows(0) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $tb where ts > now + 4m and ts < now + 3m + # TSIM: sql select * from $tb where ts > 1605045600000 + 240001 and ts < 1605045600000 + 180001 tdLog.info( - 'select * from %s where ts > now + 4m and ts < now + 3m' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 180001' % (tb)) tdSql.query( - 'select * from %s where ts > now + 4m and ts < now + 3m' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 180001' % (tb)) # TSIM: if $rows != 0 then tdLog.info('tdSql.checkRow(0)') tdSql.checkRows(0) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $tb where ts > now + 4m and ts > now + 5m and - # ts < now + 6m + # TSIM: sql select * from $tb where ts > 1605045600000 + 240001 and ts > 1605045600000 + 300001 and + # ts < 1605045600000 + 360001 tdLog.info( - 'select * from %s where ts > now + 4m and ts > now + 5m and ts < now + 6m' % + 'select * from %s where ts > 1605045600000 + 240001 and ts > 1605045600000 + 300001 and ts < 1605045600000 + 360001' % (tb)) tdSql.query( - 'select * from %s where ts > now + 4m and ts > now + 5m and ts < now + 6m' % + 'select * from %s where ts > 1605045600000 + 240001 and ts > 1605045600000 + 300001 and ts < 1605045600000 + 360001' % (tb)) # TSIM: if $rows != 1 then tdLog.info('tdSql.checkRow(1)') @@ -227,36 +225,36 @@ class TDTestCase: # TSIM: return -1 # TSIM: endi # TSIM: - # TSIM: sql select * from $mt where ts < now + 4m - tdLog.info('select * from %s where ts < now + 4m' % (mt)) - tdSql.query('select * from %s where ts < now + 4m' % (mt)) + # TSIM: sql select * from $mt where ts < 1605045600000 + 240001 + tdLog.info('select * from %s where ts < 1605045600000 + 240001' % (mt)) + tdSql.query('select * from %s where ts < 1605045600000 + 240001' % (mt)) # TSIM: if $rows != 50 then tdLog.info('tdSql.checkRow(50)') tdSql.checkRows(50) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m - tdLog.info('select * from %s where ts > now + 4m' % (mt)) - tdSql.query('select * from %s where ts > now + 4m' % (mt)) + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 + tdLog.info('select * from %s where ts > 1605045600000 + 240001' % (mt)) + tdSql.query('select * from %s where ts > 1605045600000 + 240001' % (mt)) # TSIM: if $rows != 150 then tdLog.info('tdSql.checkRow(150)') tdSql.checkRows(150) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts = now + 4m - tdLog.info('select * from %s where ts = now + 4m' % (mt)) - tdSql.query('select * from %s where ts = now + 4m' % (mt)) + # TSIM: sql select * from $mt where ts = 1605045600000 + 240001 + tdLog.info('select * from %s where ts = 1605045600000 + 240001' % (mt)) + tdSql.query('select * from %s where ts = 1605045600000 + 240001' % (mt)) # TSIM: if $rows != 0 then tdLog.info('tdSql.checkRow(0)') tdSql.checkRows(0) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and ts < now + 5m + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 tdLog.info( - 'select * from %s where ts > now + 4m and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001' % (mt)) # TSIM: if $rows != 10 then tdLog.info('tdSql.checkRow(10)') @@ -333,94 +331,94 @@ class TDTestCase: # TSIM: # TSIM: print =============== step5 tdLog.info('=============== step5') - # TSIM: sql select * from $mt where ts > now + 4m and tgcol = 1 - tdLog.info('select * from %s where ts > now + 4m and tgcol = 1' % (mt)) + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol = 1 + tdLog.info('select * from %s where ts > 1605045600000 + 240001 and tgcol = 1' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol = 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol = 1' % (mt)) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and tgcol <> 1 + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol <> 1 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol <> 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol <> 1' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol <> 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol <> 1' % (mt)) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts < now + 4m and tgcol = 0 - tdLog.info('select * from %s where ts < now + 4m and tgcol = 0' % (mt)) + # TSIM: sql select * from $mt where ts < 1605045600000 + 240001 and tgcol = 0 + tdLog.info('select * from %s where ts < 1605045600000 + 240001 and tgcol = 0' % (mt)) tdSql.query( - 'select * from %s where ts < now + 4m and tgcol = 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol = 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts < now + 4m and tgcol <> 0 + # TSIM: sql select * from $mt where ts < 1605045600000 + 240001 and tgcol <> 0 tdLog.info( - 'select * from %s where ts < now + 4m and tgcol <> 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol <> 0' % (mt)) tdSql.query( - 'select * from %s where ts < now + 4m and tgcol <> 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol <> 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts <= now + 4m and tgcol = 0 + # TSIM: sql select * from $mt where ts <= 1605045600000 + 240001 and tgcol = 0 tdLog.info( - 'select * from %s where ts <= now + 4m and tgcol = 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol = 0' % (mt)) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol = 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol = 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts <= now + 4m and tgcol <> 0 + # TSIM: sql select * from $mt where ts <= 1605045600000 + 240001 and tgcol <> 0 tdLog.info( - 'select * from %s where ts <= now + 4m and tgcol <> 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol <> 0' % (mt)) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol <> 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol <> 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and ts < now + 5m and + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and # tgcol <> 0 tdLog.info( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol <> 0' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol <> 0' % (mt)) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') tdSql.checkRows(5) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and tgcol <> 0 and ts - # < now + 5m + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol <> 0 and ts + # < 1605045600000 + 300001 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol <> 0 and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol <> 0 and ts < 1605045600000 + 300001' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol <> 0 and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol <> 0 and ts < 1605045600000 + 300001' % (mt)) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') @@ -467,12 +465,12 @@ class TDTestCase: # TSIM: print =============== step8 tdLog.info('=============== step8') # TSIM: sql select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), - # max(tbcol), first(tbcol), last(tbcol) from $mt where ts < now + 4m + # max(tbcol), first(tbcol), last(tbcol) from $mt where ts < 1605045600000 + 240001 tdLog.info( - 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m' % + 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001' % (mt)) tdSql.query( - 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m' % + 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001' % (mt)) # TSIM: print $data00 $data01 $data02 $data03 $data04 $data05 $data06 tdLog.info('$data00 $data01 $data02 $data03 $data04 $data05 $data06') @@ -522,13 +520,13 @@ class TDTestCase: # TSIM: print =============== step11 tdLog.info('=============== step11') # TSIM: sql select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), - # max(tbcol), first(tbcol), last(tbcol) from $mt where ts < now + 4m + # max(tbcol), first(tbcol), last(tbcol) from $mt where ts < 1605045600000 + 240001 # group by tgcol tdLog.info( - 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m group by tgcol' % + 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001 group by tgcol' % (mt)) tdSql.query( - 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m group by tgcol' % + 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001 group by tgcol' % (mt)) # TSIM: print $data00 $data01 $data02 $data03 $data04 $data05 $data06 tdLog.info('$data00 $data01 $data02 $data03 $data04 $data05 $data06') diff --git a/tests/pytest/tag_lite/unsignedInt.py b/tests/pytest/tag_lite/unsignedInt.py index 6efe12edf110f70d9c2c0187429a0696372bae49..6e741d351abe5c5608f45e414bcabc6d40dd0980 100644 --- a/tests/pytest/tag_lite/unsignedInt.py +++ b/tests/pytest/tag_lite/unsignedInt.py @@ -4,7 +4,7 @@ import sys from util.log import * from util.cases import * from util.sql import * - +import time class TDTestCase: def init(self, conn, logSql): @@ -72,14 +72,13 @@ class TDTestCase: # TSIM: while $x < $rowNum while (x < rowNum): # TSIM: $ms = $x . m - ms = "%dm" % x - # TSIM: sql insert into $tb values (now + $ms , $x ) + ms = x * 60000 tdLog.info( - 'insert into %s values (now + %s , %d )' % - (tb, ms, x)) + "insert into %s values (%d, %d)" % + (tb, 1605045600000 + ms, x)) tdSql.execute( - 'insert into %s values (now + %s , %d )' % - (tb, ms, x)) + "insert into %s values (%d, %d)" % + (tb, 1605045600000 + ms, x)) # TSIM: $x = $x + 1 x = x + 1 # TSIM: endw @@ -98,14 +97,13 @@ class TDTestCase: # TSIM: while $x < $rowNum while (x < rowNum): # TSIM: $ms = $x . m - ms = "%dm" % x - # TSIM: sql insert into $tb values (now + $ms , $x ) + ms = x * 60000 tdLog.info( - 'insert into %s values (now + %s , %d )' % - (tb, ms, x)) + "insert into %s values (%d, %d)" % + (tb, 1605045600000 + ms, x)) tdSql.execute( - 'insert into %s values (now + %s , %d )' % - (tb, ms, x)) + "insert into %s values (%d, %d)" % + (tb, 1605045600000 + ms, x)) # TSIM: $x = $x + 1 x = x + 1 # TSIM: endw @@ -114,6 +112,7 @@ class TDTestCase: # TSIM: endw # TSIM: # TSIM: print =============== step2 + time.sleep(1) tdLog.info('=============== step2') # TSIM: sleep 100 # TSIM: sql select * from $tb @@ -124,56 +123,56 @@ class TDTestCase: tdSql.checkRows(rowNum) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $tb where ts < now + 4m - tdLog.info('select * from %s where ts < now + 4m' % (tb)) - tdSql.query('select * from %s where ts < now + 4m' % (tb)) + # TSIM: sql select * from $tb where ts < 1605045600000 + 240001 + tdLog.info('select * from %s where ts < 1605045600000 + 240001' % (tb)) + tdSql.query('select * from %s where ts < 1605045600000 + 240001' % (tb)) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') tdSql.checkRows(5) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $tb where ts <= now + 4m - tdLog.info('select * from %s where ts <= now + 4m' % (tb)) - tdSql.query('select * from %s where ts <= now + 4m' % (tb)) + # TSIM: sql select * from $tb where ts <= 1605045600000 + 240001 + tdLog.info('select * from %s where ts <= 1605045600000 + 240001' % (tb)) + tdSql.query('select * from %s where ts <= 1605045600000 + 240001' % (tb)) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') tdSql.checkRows(5) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $tb where ts > now + 4m - tdLog.info('select * from %s where ts > now + 4m' % (tb)) - tdSql.query('select * from %s where ts > now + 4m' % (tb)) + # TSIM: sql select * from $tb where ts > 1605045600000 + 240001 + tdLog.info('select * from %s where ts > 1605045600000 + 240001' % (tb)) + tdSql.query('select * from %s where ts > 1605045600000 + 240001' % (tb)) # TSIM: if $rows != 15 then tdLog.info('tdSql.checkRow(15)') tdSql.checkRows(15) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $tb where ts >= now + 4m - tdLog.info('select * from %s where ts >= now + 4m' % (tb)) - tdSql.query('select * from %s where ts >= now + 4m' % (tb)) + # TSIM: sql select * from $tb where ts >= 1605045600000 + 240001 + tdLog.info('select * from %s where ts >= 1605045600000 + 240001' % (tb)) + tdSql.query('select * from %s where ts >= 1605045600000 + 240001' % (tb)) # TSIM: if $rows != 15 then tdLog.info('tdSql.checkRow(15)') tdSql.checkRows(15) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $tb where ts > now + 4m and ts < now + 5m + # TSIM: sql select * from $tb where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 tdLog.info( - 'select * from %s where ts > now + 4m and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001' % (tb)) tdSql.query( - 'select * from %s where ts > now + 4m and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001' % (tb)) # TSIM: if $rows != 1 then tdLog.info('tdSql.checkRow(1)') tdSql.checkRows(1) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $tb where ts < now + 4m and ts > now + 5m + # TSIM: sql select * from $tb where ts < 1605045600000 + 240001 and ts > 1605045600000 + 300001 tdLog.info( - 'select * from %s where ts < now + 4m and ts > now + 5m' % + 'select * from %s where ts < 1605045600000 + 240001 and ts > 1605045600000 + 300001' % (tb)) tdSql.query( - 'select * from %s where ts < now + 4m and ts > now + 5m' % + 'select * from %s where ts < 1605045600000 + 240001 and ts > 1605045600000 + 300001' % (tb)) # TSIM: if $rows != 0 then tdLog.info('tdSql.checkRow(0)') @@ -190,25 +189,25 @@ class TDTestCase: tdSql.checkRows(0) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $tb where ts > now + 4m and ts < now + 3m + # TSIM: sql select * from $tb where ts > 1605045600000 + 240001 and ts < 1605045600000 + 180001 tdLog.info( - 'select * from %s where ts > now + 4m and ts < now + 3m' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 180001' % (tb)) tdSql.query( - 'select * from %s where ts > now + 4m and ts < now + 3m' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 180001' % (tb)) # TSIM: if $rows != 0 then tdLog.info('tdSql.checkRow(0)') tdSql.checkRows(0) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $tb where ts > now + 4m and ts > now + 5m and - # ts < now + 6m + # TSIM: sql select * from $tb where ts > 1605045600000 + 240001 and ts > 1605045600000 + 300001 and + # ts < 1605045600000 + 360001 tdLog.info( - 'select * from %s where ts > now + 4m and ts > now + 5m and ts < now + 6m' % + 'select * from %s where ts > 1605045600000 + 240001 and ts > 1605045600000 + 300001 and ts < 1605045600000 + 360001' % (tb)) tdSql.query( - 'select * from %s where ts > now + 4m and ts > now + 5m and ts < now + 6m' % + 'select * from %s where ts > 1605045600000 + 240001 and ts > 1605045600000 + 300001 and ts < 1605045600000 + 360001' % (tb)) # TSIM: if $rows != 1 then tdLog.info('tdSql.checkRow(1)') @@ -227,36 +226,36 @@ class TDTestCase: # TSIM: return -1 # TSIM: endi # TSIM: - # TSIM: sql select * from $mt where ts < now + 4m - tdLog.info('select * from %s where ts < now + 4m' % (mt)) - tdSql.query('select * from %s where ts < now + 4m' % (mt)) + # TSIM: sql select * from $mt where ts < 1605045600000 + 240001 + tdLog.info('select * from %s where ts < 1605045600000 + 240001' % (mt)) + tdSql.query('select * from %s where ts < 1605045600000 + 240001' % (mt)) # TSIM: if $rows != 50 then tdLog.info('tdSql.checkRow(50)') tdSql.checkRows(50) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m - tdLog.info('select * from %s where ts > now + 4m' % (mt)) - tdSql.query('select * from %s where ts > now + 4m' % (mt)) + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 + tdLog.info('select * from %s where ts > 1605045600000 + 240001' % (mt)) + tdSql.query('select * from %s where ts > 1605045600000 + 240001' % (mt)) # TSIM: if $rows != 150 then tdLog.info('tdSql.checkRow(150)') tdSql.checkRows(150) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts = now + 4m - tdLog.info('select * from %s where ts = now + 4m' % (mt)) - tdSql.query('select * from %s where ts = now + 4m' % (mt)) + # TSIM: sql select * from $mt where ts = 1605045600000 + 240001 + tdLog.info('select * from %s where ts = 1605045600000 + 240001' % (mt)) + tdSql.query('select * from %s where ts = 1605045600000 + 240001' % (mt)) # TSIM: if $rows != 0 then tdLog.info('tdSql.checkRow(0)') tdSql.checkRows(0) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and ts < now + 5m + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 tdLog.info( - 'select * from %s where ts > now + 4m and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001' % (mt)) # TSIM: if $rows != 10 then tdLog.info('tdSql.checkRow(10)') @@ -333,94 +332,94 @@ class TDTestCase: # TSIM: # TSIM: print =============== step5 tdLog.info('=============== step5') - # TSIM: sql select * from $mt where ts > now + 4m and tgcol = 1 - tdLog.info('select * from %s where ts > now + 4m and tgcol = 1' % (mt)) + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol = 1 + tdLog.info('select * from %s where ts > 1605045600000 + 240001 and tgcol = 1' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol = 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol = 1' % (mt)) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and tgcol <> 1 + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol <> 1 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol <> 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol <> 1' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol <> 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol <> 1' % (mt)) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts < now + 4m and tgcol = 0 - tdLog.info('select * from %s where ts < now + 4m and tgcol = 0' % (mt)) + # TSIM: sql select * from $mt where ts < 1605045600000 + 240001 and tgcol = 0 + tdLog.info('select * from %s where ts < 1605045600000 + 240001 and tgcol = 0' % (mt)) tdSql.query( - 'select * from %s where ts < now + 4m and tgcol = 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol = 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts < now + 4m and tgcol <> 0 + # TSIM: sql select * from $mt where ts < 1605045600000 + 240001 and tgcol <> 0 tdLog.info( - 'select * from %s where ts < now + 4m and tgcol <> 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol <> 0' % (mt)) tdSql.query( - 'select * from %s where ts < now + 4m and tgcol <> 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol <> 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts <= now + 4m and tgcol = 0 + # TSIM: sql select * from $mt where ts <= 1605045600000 + 240001 and tgcol = 0 tdLog.info( - 'select * from %s where ts <= now + 4m and tgcol = 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol = 0' % (mt)) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol = 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol = 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts <= now + 4m and tgcol <> 0 + # TSIM: sql select * from $mt where ts <= 1605045600000 + 240001 and tgcol <> 0 tdLog.info( - 'select * from %s where ts <= now + 4m and tgcol <> 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol <> 0' % (mt)) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol <> 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol <> 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and ts < now + 5m and + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and # tgcol <> 0 tdLog.info( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol <> 0' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol <> 0' % (mt)) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') tdSql.checkRows(5) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and tgcol <> 0 and ts - # < now + 5m + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol <> 0 and ts + # < 1605045600000 + 300001 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol <> 0 and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol <> 0 and ts < 1605045600000 + 300001' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol <> 0 and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol <> 0 and ts < 1605045600000 + 300001' % (mt)) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') @@ -467,12 +466,12 @@ class TDTestCase: # TSIM: print =============== step8 tdLog.info('=============== step8') # TSIM: sql select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), - # max(tbcol), first(tbcol), last(tbcol) from $mt where ts < now + 4m + # max(tbcol), first(tbcol), last(tbcol) from $mt where ts < 1605045600000 + 240001 tdLog.info( - 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m' % + 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001' % (mt)) tdSql.query( - 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m' % + 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001' % (mt)) # TSIM: print $data00 $data01 $data02 $data03 $data04 $data05 $data06 tdLog.info('$data00 $data01 $data02 $data03 $data04 $data05 $data06') @@ -522,13 +521,13 @@ class TDTestCase: # TSIM: print =============== step11 tdLog.info('=============== step11') # TSIM: sql select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), - # max(tbcol), first(tbcol), last(tbcol) from $mt where ts < now + 4m + # max(tbcol), first(tbcol), last(tbcol) from $mt where ts < 1605045600000 + 240001 # group by tgcol tdLog.info( - 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m group by tgcol' % + 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001 group by tgcol' % (mt)) tdSql.query( - 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m group by tgcol' % + 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001 group by tgcol' % (mt)) # TSIM: print $data00 $data01 $data02 $data03 $data04 $data05 $data06 tdLog.info('$data00 $data01 $data02 $data03 $data04 $data05 $data06') diff --git a/tests/pytest/tag_lite/unsignedSmallint.py b/tests/pytest/tag_lite/unsignedSmallint.py index 59cb33dc18eb74b27e9a916e921e10cbabf1b4eb..21c390d9dca81fc6eb6ef87435acb1bf6d12c406 100644 --- a/tests/pytest/tag_lite/unsignedSmallint.py +++ b/tests/pytest/tag_lite/unsignedSmallint.py @@ -72,14 +72,13 @@ class TDTestCase: # TSIM: while $x < $rowNum while (x < rowNum): # TSIM: $ms = $x . m - ms = "%dm" % x - # TSIM: sql insert into $tb values (now + $ms , $x ) + ms = x * 60000 tdLog.info( - 'insert into %s values (now + %s , %d )' % - (tb, ms, x)) + "insert into %s values (%d, %d)" % + (tb, 1605045600000 + ms, x)) tdSql.execute( - 'insert into %s values (now + %s , %d )' % - (tb, ms, x)) + "insert into %s values (%d, %d)" % + (tb, 1605045600000 + ms, x)) # TSIM: $x = $x + 1 x = x + 1 # TSIM: endw @@ -98,14 +97,13 @@ class TDTestCase: # TSIM: while $x < $rowNum while (x < rowNum): # TSIM: $ms = $x . m - ms = "%dm" % x - # TSIM: sql insert into $tb values (now + $ms , $x ) + ms = x * 60000 tdLog.info( - 'insert into %s values (now + %s , %d )' % - (tb, ms, x)) + "insert into %s values (%d, %d)" % + (tb, 1605045600000 + ms, x)) tdSql.execute( - 'insert into %s values (now + %s , %d )' % - (tb, ms, x)) + "insert into %s values (%d, %d)" % + (tb, 1605045600000 + ms, x)) # TSIM: $x = $x + 1 x = x + 1 # TSIM: endw @@ -124,56 +122,56 @@ class TDTestCase: tdSql.checkRows(rowNum) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $tb where ts < now + 4m - tdLog.info('select * from %s where ts < now + 4m' % (tb)) - tdSql.query('select * from %s where ts < now + 4m' % (tb)) + # TSIM: sql select * from $tb where ts < 1605045600000 + 240001 + tdLog.info('select * from %s where ts < 1605045600000 + 240001' % (tb)) + tdSql.query('select * from %s where ts < 1605045600000 + 240001' % (tb)) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') tdSql.checkRows(5) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $tb where ts <= now + 4m - tdLog.info('select * from %s where ts <= now + 4m' % (tb)) - tdSql.query('select * from %s where ts <= now + 4m' % (tb)) + # TSIM: sql select * from $tb where ts <= 1605045600000 + 240001 + tdLog.info('select * from %s where ts <= 1605045600000 + 240001' % (tb)) + tdSql.query('select * from %s where ts <= 1605045600000 + 240001' % (tb)) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') tdSql.checkRows(5) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $tb where ts > now + 4m - tdLog.info('select * from %s where ts > now + 4m' % (tb)) - tdSql.query('select * from %s where ts > now + 4m' % (tb)) + # TSIM: sql select * from $tb where ts > 1605045600000 + 240001 + tdLog.info('select * from %s where ts > 1605045600000 + 240001' % (tb)) + tdSql.query('select * from %s where ts > 1605045600000 + 240001' % (tb)) # TSIM: if $rows != 15 then tdLog.info('tdSql.checkRow(15)') tdSql.checkRows(15) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $tb where ts >= now + 4m - tdLog.info('select * from %s where ts >= now + 4m' % (tb)) - tdSql.query('select * from %s where ts >= now + 4m' % (tb)) + # TSIM: sql select * from $tb where ts >= 1605045600000 + 240001 + tdLog.info('select * from %s where ts >= 1605045600000 + 240001' % (tb)) + tdSql.query('select * from %s where ts >= 1605045600000 + 240001' % (tb)) # TSIM: if $rows != 15 then tdLog.info('tdSql.checkRow(15)') tdSql.checkRows(15) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $tb where ts > now + 4m and ts < now + 5m + # TSIM: sql select * from $tb where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 tdLog.info( - 'select * from %s where ts > now + 4m and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001' % (tb)) tdSql.query( - 'select * from %s where ts > now + 4m and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001' % (tb)) # TSIM: if $rows != 1 then tdLog.info('tdSql.checkRow(1)') tdSql.checkRows(1) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $tb where ts < now + 4m and ts > now + 5m + # TSIM: sql select * from $tb where ts < 1605045600000 + 240001 and ts > 1605045600000 + 300001 tdLog.info( - 'select * from %s where ts < now + 4m and ts > now + 5m' % + 'select * from %s where ts < 1605045600000 + 240001 and ts > 1605045600000 + 300001' % (tb)) tdSql.query( - 'select * from %s where ts < now + 4m and ts > now + 5m' % + 'select * from %s where ts < 1605045600000 + 240001 and ts > 1605045600000 + 300001' % (tb)) # TSIM: if $rows != 0 then tdLog.info('tdSql.checkRow(0)') @@ -190,25 +188,25 @@ class TDTestCase: tdSql.checkRows(0) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $tb where ts > now + 4m and ts < now + 3m + # TSIM: sql select * from $tb where ts > 1605045600000 + 240001 and ts < 1605045600000 + 180001 tdLog.info( - 'select * from %s where ts > now + 4m and ts < now + 3m' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 180001' % (tb)) tdSql.query( - 'select * from %s where ts > now + 4m and ts < now + 3m' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 180001' % (tb)) # TSIM: if $rows != 0 then tdLog.info('tdSql.checkRow(0)') tdSql.checkRows(0) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $tb where ts > now + 4m and ts > now + 5m and - # ts < now + 6m + # TSIM: sql select * from $tb where ts > 1605045600000 + 240001 and ts > 1605045600000 + 300001 and + # ts < 1605045600000 + 360001 tdLog.info( - 'select * from %s where ts > now + 4m and ts > now + 5m and ts < now + 6m' % + 'select * from %s where ts > 1605045600000 + 240001 and ts > 1605045600000 + 300001 and ts < 1605045600000 + 360001' % (tb)) tdSql.query( - 'select * from %s where ts > now + 4m and ts > now + 5m and ts < now + 6m' % + 'select * from %s where ts > 1605045600000 + 240001 and ts > 1605045600000 + 300001 and ts < 1605045600000 + 360001' % (tb)) # TSIM: if $rows != 1 then tdLog.info('tdSql.checkRow(1)') @@ -227,36 +225,36 @@ class TDTestCase: # TSIM: return -1 # TSIM: endi # TSIM: - # TSIM: sql select * from $mt where ts < now + 4m - tdLog.info('select * from %s where ts < now + 4m' % (mt)) - tdSql.query('select * from %s where ts < now + 4m' % (mt)) + # TSIM: sql select * from $mt where ts < 1605045600000 + 240001 + tdLog.info('select * from %s where ts < 1605045600000 + 240001' % (mt)) + tdSql.query('select * from %s where ts < 1605045600000 + 240001' % (mt)) # TSIM: if $rows != 50 then tdLog.info('tdSql.checkRow(50)') tdSql.checkRows(50) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m - tdLog.info('select * from %s where ts > now + 4m' % (mt)) - tdSql.query('select * from %s where ts > now + 4m' % (mt)) + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 + tdLog.info('select * from %s where ts > 1605045600000 + 240001' % (mt)) + tdSql.query('select * from %s where ts > 1605045600000 + 240001' % (mt)) # TSIM: if $rows != 150 then tdLog.info('tdSql.checkRow(150)') tdSql.checkRows(150) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts = now + 4m - tdLog.info('select * from %s where ts = now + 4m' % (mt)) - tdSql.query('select * from %s where ts = now + 4m' % (mt)) + # TSIM: sql select * from $mt where ts = 1605045600000 + 240001 + tdLog.info('select * from %s where ts = 1605045600000 + 240001' % (mt)) + tdSql.query('select * from %s where ts = 1605045600000 + 240001' % (mt)) # TSIM: if $rows != 0 then tdLog.info('tdSql.checkRow(0)') tdSql.checkRows(0) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and ts < now + 5m + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 tdLog.info( - 'select * from %s where ts > now + 4m and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001' % (mt)) # TSIM: if $rows != 10 then tdLog.info('tdSql.checkRow(10)') @@ -333,94 +331,94 @@ class TDTestCase: # TSIM: # TSIM: print =============== step5 tdLog.info('=============== step5') - # TSIM: sql select * from $mt where ts > now + 4m and tgcol = 1 - tdLog.info('select * from %s where ts > now + 4m and tgcol = 1' % (mt)) + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol = 1 + tdLog.info('select * from %s where ts > 1605045600000 + 240001 and tgcol = 1' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol = 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol = 1' % (mt)) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and tgcol <> 1 + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol <> 1 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol <> 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol <> 1' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol <> 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol <> 1' % (mt)) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts < now + 4m and tgcol = 0 - tdLog.info('select * from %s where ts < now + 4m and tgcol = 0' % (mt)) + # TSIM: sql select * from $mt where ts < 1605045600000 + 240001 and tgcol = 0 + tdLog.info('select * from %s where ts < 1605045600000 + 240001 and tgcol = 0' % (mt)) tdSql.query( - 'select * from %s where ts < now + 4m and tgcol = 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol = 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts < now + 4m and tgcol <> 0 + # TSIM: sql select * from $mt where ts < 1605045600000 + 240001 and tgcol <> 0 tdLog.info( - 'select * from %s where ts < now + 4m and tgcol <> 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol <> 0' % (mt)) tdSql.query( - 'select * from %s where ts < now + 4m and tgcol <> 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol <> 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts <= now + 4m and tgcol = 0 + # TSIM: sql select * from $mt where ts <= 1605045600000 + 240001 and tgcol = 0 tdLog.info( - 'select * from %s where ts <= now + 4m and tgcol = 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol = 0' % (mt)) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol = 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol = 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts <= now + 4m and tgcol <> 0 + # TSIM: sql select * from $mt where ts <= 1605045600000 + 240001 and tgcol <> 0 tdLog.info( - 'select * from %s where ts <= now + 4m and tgcol <> 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol <> 0' % (mt)) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol <> 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol <> 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and ts < now + 5m and + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and # tgcol <> 0 tdLog.info( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol <> 0' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol <> 0' % (mt)) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') tdSql.checkRows(5) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and tgcol <> 0 and ts - # < now + 5m + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol <> 0 and ts + # < 1605045600000 + 300001 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol <> 0 and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol <> 0 and ts < 1605045600000 + 300001' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol <> 0 and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol <> 0 and ts < 1605045600000 + 300001' % (mt)) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') @@ -467,12 +465,12 @@ class TDTestCase: # TSIM: print =============== step8 tdLog.info('=============== step8') # TSIM: sql select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), - # max(tbcol), first(tbcol), last(tbcol) from $mt where ts < now + 4m + # max(tbcol), first(tbcol), last(tbcol) from $mt where ts < 1605045600000 + 240001 tdLog.info( - 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m' % + 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001' % (mt)) tdSql.query( - 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m' % + 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001' % (mt)) # TSIM: print $data00 $data01 $data02 $data03 $data04 $data05 $data06 tdLog.info('$data00 $data01 $data02 $data03 $data04 $data05 $data06') @@ -522,13 +520,13 @@ class TDTestCase: # TSIM: print =============== step11 tdLog.info('=============== step11') # TSIM: sql select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), - # max(tbcol), first(tbcol), last(tbcol) from $mt where ts < now + 4m + # max(tbcol), first(tbcol), last(tbcol) from $mt where ts < 1605045600000 + 240001 # group by tgcol tdLog.info( - 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m group by tgcol' % + 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001 group by tgcol' % (mt)) tdSql.query( - 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m group by tgcol' % + 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001 group by tgcol' % (mt)) # TSIM: print $data00 $data01 $data02 $data03 $data04 $data05 $data06 tdLog.info('$data00 $data01 $data02 $data03 $data04 $data05 $data06') diff --git a/tests/pytest/tag_lite/unsignedTinyint.py b/tests/pytest/tag_lite/unsignedTinyint.py index 1250b08d1b8dd4d3cb5f61af424576146ab70967..7ce3a8398444efae63ccdc93062c00c81c644da0 100644 --- a/tests/pytest/tag_lite/unsignedTinyint.py +++ b/tests/pytest/tag_lite/unsignedTinyint.py @@ -72,14 +72,13 @@ class TDTestCase: # TSIM: while $x < $rowNum while (x < rowNum): # TSIM: $ms = $x . m - ms = "%dm" % x - # TSIM: sql insert into $tb values (now + $ms , $x ) + ms = x * 60000 tdLog.info( - 'insert into %s values (now + %s , %d )' % - (tb, ms, x)) + "insert into %s values (%d, %d)" % + (tb, 1605045600000 + ms, x)) tdSql.execute( - 'insert into %s values (now + %s , %d )' % - (tb, ms, x)) + "insert into %s values (%d, %d)" % + (tb, 1605045600000 + ms, x)) # TSIM: $x = $x + 1 x = x + 1 # TSIM: endw @@ -98,14 +97,13 @@ class TDTestCase: # TSIM: while $x < $rowNum while (x < rowNum): # TSIM: $ms = $x . m - ms = "%dm" % x - # TSIM: sql insert into $tb values (now + $ms , $x ) + ms = x * 60000 tdLog.info( - 'insert into %s values (now + %s , %d )' % - (tb, ms, x)) + "insert into %s values (%d, %d)" % + (tb, 1605045600000 + ms, x)) tdSql.execute( - 'insert into %s values (now + %s , %d )' % - (tb, ms, x)) + "insert into %s values (%d, %d)" % + (tb, 1605045600000 + ms, x)) # TSIM: $x = $x + 1 x = x + 1 # TSIM: endw @@ -124,56 +122,56 @@ class TDTestCase: tdSql.checkRows(rowNum) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $tb where ts < now + 4m - tdLog.info('select * from %s where ts < now + 4m' % (tb)) - tdSql.query('select * from %s where ts < now + 4m' % (tb)) + # TSIM: sql select * from $tb where ts < 1605045600000 + 240001 + tdLog.info('select * from %s where ts < 1605045600000 + 240001' % (tb)) + tdSql.query('select * from %s where ts < 1605045600000 + 240001' % (tb)) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') tdSql.checkRows(5) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $tb where ts <= now + 4m - tdLog.info('select * from %s where ts <= now + 4m' % (tb)) - tdSql.query('select * from %s where ts <= now + 4m' % (tb)) + # TSIM: sql select * from $tb where ts <= 1605045600000 + 240001 + tdLog.info('select * from %s where ts <= 1605045600000 + 240001' % (tb)) + tdSql.query('select * from %s where ts <= 1605045600000 + 240001' % (tb)) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') tdSql.checkRows(5) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $tb where ts > now + 4m - tdLog.info('select * from %s where ts > now + 4m' % (tb)) - tdSql.query('select * from %s where ts > now + 4m' % (tb)) + # TSIM: sql select * from $tb where ts > 1605045600000 + 240001 + tdLog.info('select * from %s where ts > 1605045600000 + 240001' % (tb)) + tdSql.query('select * from %s where ts > 1605045600000 + 240001' % (tb)) # TSIM: if $rows != 15 then tdLog.info('tdSql.checkRow(15)') tdSql.checkRows(15) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $tb where ts >= now + 4m - tdLog.info('select * from %s where ts >= now + 4m' % (tb)) - tdSql.query('select * from %s where ts >= now + 4m' % (tb)) + # TSIM: sql select * from $tb where ts >= 1605045600000 + 240001 + tdLog.info('select * from %s where ts >= 1605045600000 + 240001' % (tb)) + tdSql.query('select * from %s where ts >= 1605045600000 + 240001' % (tb)) # TSIM: if $rows != 15 then tdLog.info('tdSql.checkRow(15)') tdSql.checkRows(15) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $tb where ts > now + 4m and ts < now + 5m + # TSIM: sql select * from $tb where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 tdLog.info( - 'select * from %s where ts > now + 4m and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001' % (tb)) tdSql.query( - 'select * from %s where ts > now + 4m and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001' % (tb)) # TSIM: if $rows != 1 then tdLog.info('tdSql.checkRow(1)') tdSql.checkRows(1) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $tb where ts < now + 4m and ts > now + 5m + # TSIM: sql select * from $tb where ts < 1605045600000 + 240001 and ts > 1605045600000 + 300001 tdLog.info( - 'select * from %s where ts < now + 4m and ts > now + 5m' % + 'select * from %s where ts < 1605045600000 + 240001 and ts > 1605045600000 + 300001' % (tb)) tdSql.query( - 'select * from %s where ts < now + 4m and ts > now + 5m' % + 'select * from %s where ts < 1605045600000 + 240001 and ts > 1605045600000 + 300001' % (tb)) # TSIM: if $rows != 0 then tdLog.info('tdSql.checkRow(0)') @@ -190,25 +188,25 @@ class TDTestCase: tdSql.checkRows(0) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $tb where ts > now + 4m and ts < now + 3m + # TSIM: sql select * from $tb where ts > 1605045600000 + 240001 and ts < 1605045600000 + 180001 tdLog.info( - 'select * from %s where ts > now + 4m and ts < now + 3m' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 180001' % (tb)) tdSql.query( - 'select * from %s where ts > now + 4m and ts < now + 3m' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 180001' % (tb)) # TSIM: if $rows != 0 then tdLog.info('tdSql.checkRow(0)') tdSql.checkRows(0) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $tb where ts > now + 4m and ts > now + 5m and - # ts < now + 6m + # TSIM: sql select * from $tb where ts > 1605045600000 + 240001 and ts > 1605045600000 + 300001 and + # ts < 1605045600000 + 360001 tdLog.info( - 'select * from %s where ts > now + 4m and ts > now + 5m and ts < now + 6m' % + 'select * from %s where ts > 1605045600000 + 240001 and ts > 1605045600000 + 300001 and ts < 1605045600000 + 360001' % (tb)) tdSql.query( - 'select * from %s where ts > now + 4m and ts > now + 5m and ts < now + 6m' % + 'select * from %s where ts > 1605045600000 + 240001 and ts > 1605045600000 + 300001 and ts < 1605045600000 + 360001' % (tb)) # TSIM: if $rows != 1 then tdLog.info('tdSql.checkRow(1)') @@ -227,36 +225,36 @@ class TDTestCase: # TSIM: return -1 # TSIM: endi # TSIM: - # TSIM: sql select * from $mt where ts < now + 4m - tdLog.info('select * from %s where ts < now + 4m' % (mt)) - tdSql.query('select * from %s where ts < now + 4m' % (mt)) + # TSIM: sql select * from $mt where ts < 1605045600000 + 240001 + tdLog.info('select * from %s where ts < 1605045600000 + 240001' % (mt)) + tdSql.query('select * from %s where ts < 1605045600000 + 240001' % (mt)) # TSIM: if $rows != 50 then tdLog.info('tdSql.checkRow(50)') tdSql.checkRows(50) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m - tdLog.info('select * from %s where ts > now + 4m' % (mt)) - tdSql.query('select * from %s where ts > now + 4m' % (mt)) + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 + tdLog.info('select * from %s where ts > 1605045600000 + 240001' % (mt)) + tdSql.query('select * from %s where ts > 1605045600000 + 240001' % (mt)) # TSIM: if $rows != 150 then tdLog.info('tdSql.checkRow(150)') tdSql.checkRows(150) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts = now + 4m - tdLog.info('select * from %s where ts = now + 4m' % (mt)) - tdSql.query('select * from %s where ts = now + 4m' % (mt)) + # TSIM: sql select * from $mt where ts = 1605045600000 + 240001 + tdLog.info('select * from %s where ts = 1605045600000 + 240001' % (mt)) + tdSql.query('select * from %s where ts = 1605045600000 + 240001' % (mt)) # TSIM: if $rows != 0 then tdLog.info('tdSql.checkRow(0)') tdSql.checkRows(0) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and ts < now + 5m + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 tdLog.info( - 'select * from %s where ts > now + 4m and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001' % (mt)) # TSIM: if $rows != 10 then tdLog.info('tdSql.checkRow(10)') @@ -333,94 +331,94 @@ class TDTestCase: # TSIM: # TSIM: print =============== step5 tdLog.info('=============== step5') - # TSIM: sql select * from $mt where ts > now + 4m and tgcol = 1 - tdLog.info('select * from %s where ts > now + 4m and tgcol = 1' % (mt)) + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol = 1 + tdLog.info('select * from %s where ts > 1605045600000 + 240001 and tgcol = 1' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol = 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol = 1' % (mt)) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and tgcol <> 1 + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol <> 1 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol <> 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol <> 1' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol <> 1' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol <> 1' % (mt)) # TSIM: if $rows != 75 then tdLog.info('tdSql.checkRow(75)') tdSql.checkRows(75) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts < now + 4m and tgcol = 0 - tdLog.info('select * from %s where ts < now + 4m and tgcol = 0' % (mt)) + # TSIM: sql select * from $mt where ts < 1605045600000 + 240001 and tgcol = 0 + tdLog.info('select * from %s where ts < 1605045600000 + 240001 and tgcol = 0' % (mt)) tdSql.query( - 'select * from %s where ts < now + 4m and tgcol = 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol = 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts < now + 4m and tgcol <> 0 + # TSIM: sql select * from $mt where ts < 1605045600000 + 240001 and tgcol <> 0 tdLog.info( - 'select * from %s where ts < now + 4m and tgcol <> 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol <> 0' % (mt)) tdSql.query( - 'select * from %s where ts < now + 4m and tgcol <> 0' % + 'select * from %s where ts < 1605045600000 + 240001 and tgcol <> 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts <= now + 4m and tgcol = 0 + # TSIM: sql select * from $mt where ts <= 1605045600000 + 240001 and tgcol = 0 tdLog.info( - 'select * from %s where ts <= now + 4m and tgcol = 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol = 0' % (mt)) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol = 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol = 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts <= now + 4m and tgcol <> 0 + # TSIM: sql select * from $mt where ts <= 1605045600000 + 240001 and tgcol <> 0 tdLog.info( - 'select * from %s where ts <= now + 4m and tgcol <> 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol <> 0' % (mt)) tdSql.query( - 'select * from %s where ts <= now + 4m and tgcol <> 0' % + 'select * from %s where ts <= 1605045600000 + 240001 and tgcol <> 0' % (mt)) # TSIM: if $rows != 25 then tdLog.info('tdSql.checkRow(25)') tdSql.checkRows(25) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and ts < now + 5m and + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and # tgcol <> 0 tdLog.info( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol <> 0' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and ts < now + 5m and tgcol <> 0' % + 'select * from %s where ts > 1605045600000 + 240001 and ts < 1605045600000 + 300001 and tgcol <> 0' % (mt)) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') tdSql.checkRows(5) # TSIM: return -1 # TSIM: endi - # TSIM: sql select * from $mt where ts > now + 4m and tgcol <> 0 and ts - # < now + 5m + # TSIM: sql select * from $mt where ts > 1605045600000 + 240001 and tgcol <> 0 and ts + # < 1605045600000 + 300001 tdLog.info( - 'select * from %s where ts > now + 4m and tgcol <> 0 and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol <> 0 and ts < 1605045600000 + 300001' % (mt)) tdSql.query( - 'select * from %s where ts > now + 4m and tgcol <> 0 and ts < now + 5m' % + 'select * from %s where ts > 1605045600000 + 240001 and tgcol <> 0 and ts < 1605045600000 + 300001' % (mt)) # TSIM: if $rows != 5 then tdLog.info('tdSql.checkRow(5)') @@ -467,12 +465,12 @@ class TDTestCase: # TSIM: print =============== step8 tdLog.info('=============== step8') # TSIM: sql select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), - # max(tbcol), first(tbcol), last(tbcol) from $mt where ts < now + 4m + # max(tbcol), first(tbcol), last(tbcol) from $mt where ts < 1605045600000 + 240001 tdLog.info( - 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m' % + 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001' % (mt)) tdSql.query( - 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m' % + 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001' % (mt)) # TSIM: print $data00 $data01 $data02 $data03 $data04 $data05 $data06 tdLog.info('$data00 $data01 $data02 $data03 $data04 $data05 $data06') @@ -522,13 +520,13 @@ class TDTestCase: # TSIM: print =============== step11 tdLog.info('=============== step11') # TSIM: sql select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), - # max(tbcol), first(tbcol), last(tbcol) from $mt where ts < now + 4m + # max(tbcol), first(tbcol), last(tbcol) from $mt where ts < 1605045600000 + 240001 # group by tgcol tdLog.info( - 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m group by tgcol' % + 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001 group by tgcol' % (mt)) tdSql.query( - 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < now + 4m group by tgcol' % + 'select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where ts < 1605045600000 + 240001 group by tgcol' % (mt)) # TSIM: print $data00 $data01 $data02 $data03 $data04 $data05 $data06 tdLog.info('$data00 $data01 $data02 $data03 $data04 $data05 $data06') diff --git a/tests/pytest/tools/taosdemoAllTest/manual_change_time_1_1_A.json b/tests/pytest/tools/taosdemoAllTest/manual_change_time_1_1_A.json new file mode 100644 index 0000000000000000000000000000000000000000..7b8abd6d4e25991d38ff16c737bf8169c7311318 --- /dev/null +++ b/tests/pytest/tools/taosdemoAllTest/manual_change_time_1_1_A.json @@ -0,0 +1,60 @@ +{ + "filetype": "insert", + "cfgdir": "/etc/taos", + "host": "127.0.0.1", + "port": 6030, + "user": "root", + "password": "taosdata", + "thread_count": 4, + "thread_count_create_tbl": 4, + "result_file": "./insert_res.txt", + "confirm_parameter_prompt": "no", + "insert_interval": 0, + "interlace_rows": 100, + "num_of_records_per_req": 32766, + "databases": [{ + "dbinfo": { + "name": "db", + "drop": "yes", + "replica": 1, + "days": 1, + "cache": 4, + "blocks": 3, + "precision": "ms", + "keep": 10, + "minRows": 1000, + "maxRows": 4096, + "comp":2, + "walLevel":1, + "cachelast":0, + "quorum":1, + "fsync":3000, + "update": 0 + }, + "super_tables": [{ + "name": "stb", + "child_table_exists":"no", + "childtable_count": 1, + "childtable_prefix": "stb_", + "auto_create_table": "no", + "batch_create_tbl_num": 20, + "data_source": "rand", + "insert_mode": "taosc", + "insert_rows": 864000, + "childtable_limit": 1, + "childtable_offset":0, + "interlace_rows": 0, + "insert_interval":0, + "max_sql_len": 1024000, + "disorder_ratio": 0, + "disorder_range": 1000, + "timestamp_step": 1000, + "start_timestamp": "2020-10-11 00:00:00.000", + "sample_format": "csv", + "sample_file": "./tools/taosdemoAllTest/sample.csv", + "tags_file": "", + "columns": [{"type": "BINARY", "len": 5120, "count":1}], + "tags": [{"type": "TINYINT", "count":2}] + }] + }] +} \ No newline at end of file diff --git a/tests/pytest/tools/taosdemoAllTest/manual_change_time_1_1_B.json b/tests/pytest/tools/taosdemoAllTest/manual_change_time_1_1_B.json new file mode 100644 index 0000000000000000000000000000000000000000..aeee6322e5c0e6b58c0433be5f345e7c4f84f339 --- /dev/null +++ b/tests/pytest/tools/taosdemoAllTest/manual_change_time_1_1_B.json @@ -0,0 +1,60 @@ +{ + "filetype": "insert", + "cfgdir": "/etc/taos", + "host": "127.0.0.1", + "port": 6030, + "user": "root", + "password": "taosdata", + "thread_count": 4, + "thread_count_create_tbl": 4, + "result_file": "./insert_res.txt", + "confirm_parameter_prompt": "no", + "insert_interval": 0, + "interlace_rows": 100, + "num_of_records_per_req": 32766, + "databases": [{ + "dbinfo": { + "name": "db", + "drop": "no", + "replica": 1, + "days": 1, + "cache": 4, + "blocks": 3, + "precision": "ms", + "keep": 10, + "minRows": 1000, + "maxRows": 4096, + "comp":2, + "walLevel":1, + "cachelast":0, + "quorum":1, + "fsync":3000, + "update": 0 + }, + "super_tables": [{ + "name": "stb", + "child_table_exists":"yes", + "childtable_count": 1, + "childtable_prefix": "stb_", + "auto_create_table": "yes", + "batch_create_tbl_num": 20, + "data_source": "rand", + "insert_mode": "taosc", + "insert_rows": 432000, + "childtable_limit": 1, + "childtable_offset":0, + "interlace_rows": 0, + "insert_interval":0, + "max_sql_len": 1024000, + "disorder_ratio": 0, + "disorder_range": 1000, + "timestamp_step": 1000, + "start_timestamp": "2020-10-16 00:00:00.500", + "sample_format": "csv", + "sample_file": "./tools/taosdemoAllTest/sample.csv", + "tags_file": "", + "columns": [{"type": "BINARY", "len": 5120, "count":1}], + "tags": [{"type": "TINYINT", "count":1}] + }] + }] +} \ No newline at end of file diff --git a/tests/pytest/util/pathFinding.py b/tests/pytest/util/pathFinding.py new file mode 100644 index 0000000000000000000000000000000000000000..9dee5142ce3539c7cd145c3d8364e01c4af25164 --- /dev/null +++ b/tests/pytest/util/pathFinding.py @@ -0,0 +1,83 @@ +################################################################### +# Copyright (c) 2016 by TAOS Technologies, Inc. +# All rights reserved. +# +# This file is proprietary and confidential to TAOS Technologies. +# No part of this file may be reproduced, stored, transmitted, +# disclosed or used in any form or by any means other than as +# expressly provided by the written permission from Jianhui Tao +# +################################################################### + +# -*- coding: utf-8 -*- + + +import os +from util.log import * + + + +class TDFindPath: + """This class is for finding path within TDengine + """ + def __init__(self): + self.file = "" + + + def init(self, file): + """[summary] + + Args: + file (str): the file location you want to start the query. Generally using __file__ + """ + self.file = file + + def getTaosdemoPath(self): + """for finding the path of directory containing taosdemo + + Returns: + str: the path to directory containing taosdemo + """ + selfPath = os.path.dirname(os.path.realpath(self.file)) + + if ("community" in selfPath): + projPath = selfPath[:selfPath.find("community")] + else: + projPath = selfPath[:selfPath.find("tests")] + + for root, dirs, files in os.walk(projPath): + if ("taosd" in files): + rootRealPath = os.path.dirname(os.path.realpath(root)) + if ("packaging" not in rootRealPath): + buildPath = root[:len(root)-len("/build/bin")] + break + if (buildPath == ""): + tdLog.exit("taosd not found!") + else: + tdLog.info(f"taosd found in {buildPath}") + return buildPath + "/build/bin/" + + def getTDenginePath(self): + """for finding the root path of TDengine + + Returns: + str: the root path of TDengine + """ + selfPath = os.path.dirname(os.path.realpath(self.file)) + + if ("community" in selfPath): + projPath = selfPath[:selfPath.find("community")] + else: + projPath = selfPath[:selfPath.find("tests")] + print(projPath) + for root, dirs, files in os.walk(projPath): + if ("sim" in dirs): + print(root) + rootRealPath = os.path.realpath(root) + if (rootRealPath == ""): + tdLog.exit("TDengine not found!") + else: + tdLog.info(f"TDengine found in {rootRealPath}") + return rootRealPath + +tdFindPath = TDFindPath() \ No newline at end of file diff --git a/tests/pytest/wal/insertDataDb1.json b/tests/pytest/wal/insertDataDb1.json new file mode 100644 index 0000000000000000000000000000000000000000..1dce00a4d55aae732ae9c85033f49398a0b1a9be --- /dev/null +++ b/tests/pytest/wal/insertDataDb1.json @@ -0,0 +1,87 @@ +{ + "filetype": "insert", + "cfgdir": "/etc/taos", + "host": "127.0.0.1", + "port": 6030, + "user": "root", + "password": "taosdata", + "thread_count": 4, + "thread_count_create_tbl": 4, + "result_file": "./insert_res.txt", + "confirm_parameter_prompt": "no", + "insert_interval": 0, + "interlace_rows": 10, + "num_of_records_per_req": 1000, + "max_sql_len": 1024000, + "databases": [{ + "dbinfo": { + "name": "db1", + "drop": "yes", + "replica": 1, + "days": 10, + "cache": 50, + "blocks": 8, + "precision": "ms", + "keep": 365, + "minRows": 100, + "maxRows": 4096, + "comp":2, + "walLevel":1, + "cachelast":0, + "quorum":1, + "fsync":3000, + "update": 0 + }, + "super_tables": [{ + "name": "stb0", + "child_table_exists":"no", + "childtable_count": 1000, + "childtable_prefix": "stb00_", + "auto_create_table": "no", + "batch_create_tbl_num": 100, + "data_source": "rand", + "insert_mode": "taosc", + "insert_rows": 100, + "childtable_limit": 0, + "childtable_offset":0, + "interlace_rows": 0, + "insert_interval":0, + "max_sql_len": 1024000, + "disorder_ratio": 0, + "disorder_range": 1000, + "timestamp_step": 1, + "start_timestamp": "2020-10-01 00:00:00.000", + "sample_format": "csv", + "sample_file": "./sample.csv", + "tags_file": "", + "columns": [{"type": "INT"}, {"type": "DOUBLE", "count":1}, {"type": "BINARY", "len": 16, "count":1}, {"type": "BINARY", "len": 32, "count":1}], + "tags": [{"type": "TINYINT", "count":2}, {"type": "BINARY", "len": 16, "count":1}] + }, + { + "name": "stb1", + "child_table_exists":"no", + "childtable_count": 1000, + "childtable_prefix": "stb01_", + "auto_create_table": "no", + "batch_create_tbl_num": 10, + "data_source": "rand", + "insert_mode": "taosc", + "insert_rows": 200, + "childtable_limit": 0, + "childtable_offset":0, + "interlace_rows": 0, + "insert_interval":0, + "max_sql_len": 1024000, + "disorder_ratio": 0, + "disorder_range": 1000, + "timestamp_step": 1, + "start_timestamp": "2020-10-01 00:00:00.000", + "sample_format": "csv", + "sample_file": "./sample.csv", + "tags_file": "", + "columns": [{"type": "INT"}, {"type": "DOUBLE", "count":1}, {"type": "BINARY", "len": 16, "count":1}, {"type": "BINARY", "len": 32, "count":1}], + "tags": [{"type": "TINYINT", "count":2}, {"type": "BINARY", "len": 16, "count":1}] + }] + }] +} + diff --git a/tests/pytest/wal/insertDataDb1Replica2.json b/tests/pytest/wal/insertDataDb1Replica2.json new file mode 100644 index 0000000000000000000000000000000000000000..fec38bcdecd9b441ad1c31891e66e7245c43889f --- /dev/null +++ b/tests/pytest/wal/insertDataDb1Replica2.json @@ -0,0 +1,87 @@ +{ + "filetype": "insert", + "cfgdir": "/etc/taos", + "host": "127.0.0.1", + "port": 6030, + "user": "root", + "password": "taosdata", + "thread_count": 4, + "thread_count_create_tbl": 4, + "result_file": "./insert_res.txt", + "confirm_parameter_prompt": "no", + "insert_interval": 0, + "interlace_rows": 10, + "num_of_records_per_req": 1000, + "max_sql_len": 1024000, + "databases": [{ + "dbinfo": { + "name": "db1", + "drop": "yes", + "replica": 2, + "days": 10, + "cache": 50, + "blocks": 8, + "precision": "ms", + "keep": 365, + "minRows": 100, + "maxRows": 4096, + "comp":2, + "walLevel":1, + "cachelast":0, + "quorum":1, + "fsync":3000, + "update": 0 + }, + "super_tables": [{ + "name": "stb0", + "child_table_exists":"no", + "childtable_count": 1000, + "childtable_prefix": "stb00_", + "auto_create_table": "no", + "batch_create_tbl_num": 100, + "data_source": "rand", + "insert_mode": "taosc", + "insert_rows": 100, + "childtable_limit": 0, + "childtable_offset":0, + "interlace_rows": 0, + "insert_interval":0, + "max_sql_len": 1024000, + "disorder_ratio": 0, + "disorder_range": 1000, + "timestamp_step": 1, + "start_timestamp": "2020-10-01 00:00:00.000", + "sample_format": "csv", + "sample_file": "./sample.csv", + "tags_file": "", + "columns": [{"type": "INT"}, {"type": "DOUBLE", "count":1}, {"type": "BINARY", "len": 16, "count":1}, {"type": "BINARY", "len": 32, "count":1}], + "tags": [{"type": "TINYINT", "count":2}, {"type": "BINARY", "len": 16, "count":1}] + }, + { + "name": "stb1", + "child_table_exists":"no", + "childtable_count": 1000, + "childtable_prefix": "stb01_", + "auto_create_table": "no", + "batch_create_tbl_num": 10, + "data_source": "rand", + "insert_mode": "taosc", + "insert_rows": 200, + "childtable_limit": 0, + "childtable_offset":0, + "interlace_rows": 0, + "insert_interval":0, + "max_sql_len": 1024000, + "disorder_ratio": 0, + "disorder_range": 1000, + "timestamp_step": 1, + "start_timestamp": "2020-10-01 00:00:00.000", + "sample_format": "csv", + "sample_file": "./sample.csv", + "tags_file": "", + "columns": [{"type": "INT"}, {"type": "DOUBLE", "count":1}, {"type": "BINARY", "len": 16, "count":1}, {"type": "BINARY", "len": 32, "count":1}], + "tags": [{"type": "TINYINT", "count":2}, {"type": "BINARY", "len": 16, "count":1}] + }] + }] +} + diff --git a/tests/pytest/wal/insertDataDb2.json b/tests/pytest/wal/insertDataDb2.json new file mode 100644 index 0000000000000000000000000000000000000000..2cf8af580570ac66049ca2248a916337517a6507 --- /dev/null +++ b/tests/pytest/wal/insertDataDb2.json @@ -0,0 +1,86 @@ +{ + "filetype": "insert", + "cfgdir": "/etc/taos", + "host": "127.0.0.1", + "port": 6030, + "user": "root", + "password": "taosdata", + "thread_count": 4, + "thread_count_create_tbl": 4, + "result_file": "./insert_res.txt", + "confirm_parameter_prompt": "no", + "insert_interval": 0, + "interlace_rows": 0, + "num_of_records_per_req": 3000, + "max_sql_len": 1024000, + "databases": [{ + "dbinfo": { + "name": "db2", + "drop": "yes", + "replica": 1, + "days": 10, + "cache": 50, + "blocks": 8, + "precision": "ms", + "keep": 365, + "minRows": 100, + "maxRows": 4096, + "comp":2, + "walLevel":1, + "cachelast":0, + "quorum":1, + "fsync":3000, + "update": 0 + }, + "super_tables": [{ + "name": "stb0", + "child_table_exists":"no", + "childtable_count": 2000, + "childtable_prefix": "stb0_", + "auto_create_table": "no", + "batch_create_tbl_num": 100, + "data_source": "rand", + "insert_mode": "taosc", + "insert_rows": 2000, + "childtable_limit": 0, + "childtable_offset":0, + "interlace_rows": 0, + "insert_interval":0, + "max_sql_len": 1024000, + "disorder_ratio": 0, + "disorder_range": 1000, + "timestamp_step": 1, + "start_timestamp": "2020-10-01 00:00:00.000", + "sample_format": "csv", + "sample_file": "./sample.csv", + "tags_file": "", + "columns": [{"type": "INT"}, {"type": "DOUBLE", "count":1}, {"type": "BINARY", "len": 16, "count":1}, {"type": "BINARY", "len": 32, "count":1}], + "tags": [{"type": "TINYINT", "count":2}, {"type": "BINARY", "len": 16, "count":1}] + }, + { + "name": "stb1", + "child_table_exists":"no", + "childtable_count": 2, + "childtable_prefix": "stb1_", + "auto_create_table": "no", + "batch_create_tbl_num": 10, + "data_source": "rand", + "insert_mode": "taosc", + "insert_rows": 5, + "childtable_limit": 0, + "childtable_offset":0, + "interlace_rows": 0, + "insert_interval":0, + "max_sql_len": 1024000, + "disorder_ratio": 0, + "disorder_range": 1000, + "timestamp_step": 1, + "start_timestamp": "2020-10-01 00:00:00.000", + "sample_format": "csv", + "sample_file": "./sample.csv", + "tags_file": "", + "columns": [{"type": "INT"}, {"type": "DOUBLE", "count":1}, {"type": "BINARY", "len": 16, "count":1}, {"type": "BINARY", "len": 32, "count":1}], + "tags": [{"type": "TINYINT", "count":2}, {"type": "BINARY", "len": 16, "count":1}] + }] + }] +} diff --git a/tests/pytest/wal/insertDataDb2Newstab.json b/tests/pytest/wal/insertDataDb2Newstab.json new file mode 100644 index 0000000000000000000000000000000000000000..f9d0713385265282e938838a10b485ca9cfdd603 --- /dev/null +++ b/tests/pytest/wal/insertDataDb2Newstab.json @@ -0,0 +1,86 @@ +{ + "filetype": "insert", + "cfgdir": "/etc/taos", + "host": "127.0.0.1", + "port": 6030, + "user": "root", + "password": "taosdata", + "thread_count": 4, + "thread_count_create_tbl": 4, + "result_file": "./insert_res.txt", + "confirm_parameter_prompt": "no", + "insert_interval": 0, + "interlace_rows": 0, + "num_of_records_per_req": 3000, + "max_sql_len": 1024000, + "databases": [{ + "dbinfo": { + "name": "db2", + "drop": "no", + "replica": 1, + "days": 10, + "cache": 50, + "blocks": 8, + "precision": "ms", + "keep": 365, + "minRows": 100, + "maxRows": 4096, + "comp":2, + "walLevel":1, + "cachelast":0, + "quorum":1, + "fsync":3000, + "update": 0 + }, + "super_tables": [{ + "name": "stb0", + "child_table_exists":"no", + "childtable_count": 1, + "childtable_prefix": "stb0_", + "auto_create_table": "no", + "batch_create_tbl_num": 100, + "data_source": "rand", + "insert_mode": "taosc", + "insert_rows": 0, + "childtable_limit": -1, + "childtable_offset":0, + "interlace_rows": 0, + "insert_interval":0, + "max_sql_len": 1024000, + "disorder_ratio": 0, + "disorder_range": 1000, + "timestamp_step": 1, + "start_timestamp": "2020-10-01 00:00:00.000", + "sample_format": "csv", + "sample_file": "./sample.csv", + "tags_file": "", + "columns": [{"type": "INT"}, {"type": "DOUBLE", "count":1}, {"type": "BINARY", "len": 16, "count":1}, {"type": "BINARY", "len": 32, "count":1}], + "tags": [{"type": "TINYINT", "count":2}, {"type": "BINARY", "len": 16, "count":1}] + }, + { + "name": "stb1", + "child_table_exists":"yes", + "childtable_count": 1, + "childtable_prefix": "stb01_", + "auto_create_table": "no", + "batch_create_tbl_num": 10, + "data_source": "rand", + "insert_mode": "taosc", + "insert_rows": 10, + "childtable_limit": -1, + "childtable_offset":0, + "interlace_rows": 0, + "insert_interval":0, + "max_sql_len": 1024000, + "disorder_ratio": 0, + "disorder_range": 1000, + "timestamp_step": 1, + "start_timestamp": "2020-11-01 00:00:00.000", + "sample_format": "csv", + "sample_file": "./sample.csv", + "tags_file": "", + "columns": [{"type": "INT"}, {"type": "DOUBLE", "count":1}, {"type": "BINARY", "len": 16, "count":1}], + "tags": [{"type": "TINYINT", "count":2}, {"type": "BINARY", "len": 16, "count":1}] + }] + }] +} diff --git a/tests/pytest/wal/insertDataDb2NewstabReplica2.json b/tests/pytest/wal/insertDataDb2NewstabReplica2.json new file mode 100644 index 0000000000000000000000000000000000000000..e052f2850fc2fe1e15c651f6150b79fa65c531c1 --- /dev/null +++ b/tests/pytest/wal/insertDataDb2NewstabReplica2.json @@ -0,0 +1,86 @@ +{ + "filetype": "insert", + "cfgdir": "/etc/taos", + "host": "127.0.0.1", + "port": 6030, + "user": "root", + "password": "taosdata", + "thread_count": 4, + "thread_count_create_tbl": 4, + "result_file": "./insert_res.txt", + "confirm_parameter_prompt": "no", + "insert_interval": 0, + "interlace_rows": 0, + "num_of_records_per_req": 3000, + "max_sql_len": 1024000, + "databases": [{ + "dbinfo": { + "name": "db2", + "drop": "no", + "replica": 2, + "days": 10, + "cache": 50, + "blocks": 8, + "precision": "ms", + "keep": 365, + "minRows": 100, + "maxRows": 4096, + "comp":2, + "walLevel":1, + "cachelast":0, + "quorum":1, + "fsync":3000, + "update": 0 + }, + "super_tables": [{ + "name": "stb0", + "child_table_exists":"no", + "childtable_count": 1, + "childtable_prefix": "stb0_", + "auto_create_table": "no", + "batch_create_tbl_num": 100, + "data_source": "rand", + "insert_mode": "taosc", + "insert_rows": 0, + "childtable_limit": -1, + "childtable_offset":0, + "interlace_rows": 0, + "insert_interval":0, + "max_sql_len": 1024000, + "disorder_ratio": 0, + "disorder_range": 1000, + "timestamp_step": 1, + "start_timestamp": "2020-10-01 00:00:00.000", + "sample_format": "csv", + "sample_file": "./sample.csv", + "tags_file": "", + "columns": [{"type": "INT"}, {"type": "DOUBLE", "count":1}, {"type": "BINARY", "len": 16, "count":1}, {"type": "BINARY", "len": 32, "count":1}], + "tags": [{"type": "TINYINT", "count":2}, {"type": "BINARY", "len": 16, "count":1}] + }, + { + "name": "stb1", + "child_table_exists":"yes", + "childtable_count": 1, + "childtable_prefix": "stb01_", + "auto_create_table": "no", + "batch_create_tbl_num": 10, + "data_source": "rand", + "insert_mode": "taosc", + "insert_rows": 10, + "childtable_limit": -1, + "childtable_offset":0, + "interlace_rows": 0, + "insert_interval":0, + "max_sql_len": 1024000, + "disorder_ratio": 0, + "disorder_range": 1000, + "timestamp_step": 1, + "start_timestamp": "2020-11-01 00:00:00.000", + "sample_format": "csv", + "sample_file": "./sample.csv", + "tags_file": "", + "columns": [{"type": "INT"}, {"type": "DOUBLE", "count":1}, {"type": "BINARY", "len": 16, "count":1}], + "tags": [{"type": "TINYINT", "count":2}, {"type": "BINARY", "len": 16, "count":1}] + }] + }] +} diff --git a/tests/pytest/wal/insertDataDb2Replica2.json b/tests/pytest/wal/insertDataDb2Replica2.json new file mode 100644 index 0000000000000000000000000000000000000000..121f70956a8f1eff31f92bc7fb904835f6bcd0de --- /dev/null +++ b/tests/pytest/wal/insertDataDb2Replica2.json @@ -0,0 +1,86 @@ +{ + "filetype": "insert", + "cfgdir": "/etc/taos", + "host": "127.0.0.1", + "port": 6030, + "user": "root", + "password": "taosdata", + "thread_count": 4, + "thread_count_create_tbl": 4, + "result_file": "./insert_res.txt", + "confirm_parameter_prompt": "no", + "insert_interval": 0, + "interlace_rows": 0, + "num_of_records_per_req": 3000, + "max_sql_len": 1024000, + "databases": [{ + "dbinfo": { + "name": "db2", + "drop": "yes", + "replica": 2, + "days": 10, + "cache": 50, + "blocks": 8, + "precision": "ms", + "keep": 365, + "minRows": 100, + "maxRows": 4096, + "comp":2, + "walLevel":1, + "cachelast":0, + "quorum":1, + "fsync":3000, + "update": 0 + }, + "super_tables": [{ + "name": "stb0", + "child_table_exists":"no", + "childtable_count": 2000, + "childtable_prefix": "stb0_", + "auto_create_table": "no", + "batch_create_tbl_num": 100, + "data_source": "rand", + "insert_mode": "taosc", + "insert_rows": 2000, + "childtable_limit": 0, + "childtable_offset":0, + "interlace_rows": 0, + "insert_interval":0, + "max_sql_len": 1024000, + "disorder_ratio": 0, + "disorder_range": 1000, + "timestamp_step": 1, + "start_timestamp": "2020-10-01 00:00:00.000", + "sample_format": "csv", + "sample_file": "./sample.csv", + "tags_file": "", + "columns": [{"type": "INT"}, {"type": "DOUBLE", "count":1}, {"type": "BINARY", "len": 16, "count":1}, {"type": "BINARY", "len": 32, "count":1}], + "tags": [{"type": "TINYINT", "count":2}, {"type": "BINARY", "len": 16, "count":1}] + }, + { + "name": "stb1", + "child_table_exists":"no", + "childtable_count": 2, + "childtable_prefix": "stb1_", + "auto_create_table": "no", + "batch_create_tbl_num": 10, + "data_source": "rand", + "insert_mode": "taosc", + "insert_rows": 5, + "childtable_limit": 0, + "childtable_offset":0, + "interlace_rows": 0, + "insert_interval":0, + "max_sql_len": 1024000, + "disorder_ratio": 0, + "disorder_range": 1000, + "timestamp_step": 1, + "start_timestamp": "2020-10-01 00:00:00.000", + "sample_format": "csv", + "sample_file": "./sample.csv", + "tags_file": "", + "columns": [{"type": "INT"}, {"type": "DOUBLE", "count":1}, {"type": "BINARY", "len": 16, "count":1}, {"type": "BINARY", "len": 32, "count":1}], + "tags": [{"type": "TINYINT", "count":2}, {"type": "BINARY", "len": 16, "count":1}] + }] + }] +} diff --git a/tests/pytest/wal/sdbComp.py b/tests/pytest/wal/sdbComp.py new file mode 100644 index 0000000000000000000000000000000000000000..c0ac02610f94dbe7c6bfb4ccd7aacd5ada03f205 --- /dev/null +++ b/tests/pytest/wal/sdbComp.py @@ -0,0 +1,124 @@ +################################################################### +# Copyright (c) 2016 by TAOS Technologies, Inc. +# All rights reserved. +# +# This file is proprietary and confidential to TAOS Technologies. +# No part of this file may be reproduced, stored, transmitted, +# disclosed or used in any form or by any means other than as +# expressly provided by the written permission from Jianhui Tao +# +################################################################### + +# -*- coding: utf-8 -*- + +from distutils.log import debug +import sys +import os +import taos +from util.log import * +from util.cases import * +from util.sql import * +from util.dnodes import * +import subprocess + + +class TDTestCase: + def init(self, conn, logSql): + tdLog.debug("start to execute %s" % __file__) + tdSql.init(conn.cursor(), logSql) + + def getBuildPath(self): + selfPath = os.path.dirname(os.path.realpath(__file__)) + + if ("community" in selfPath): + projPath = selfPath[:selfPath.find("community")] + else: + projPath = selfPath[:selfPath.find("tests")] + + for root, dirs, files in os.walk(projPath): + if ("taosd" in files): + rootRealPath = os.path.dirname(os.path.realpath(root)) + if ("packaging" not in rootRealPath): + buildPath = root[:len(root)-len("/build/bin")] + break + return buildPath + + def run(self): + + # set path para + buildPath = self.getBuildPath() + if (buildPath == ""): + tdLog.exit("taosd not found!") + else: + tdLog.info("taosd found in %s" % buildPath) + + binPath = buildPath+ "/build/bin/" + testPath = buildPath[:buildPath.find("debug")] + walFilePath = testPath + "/sim/dnode1/data/mnode_bak/wal/" + + #new db and insert data + os.system("rm -rf %s/sim/dnode1/data/mnode_tmp/" % testPath) + os.system("rm -rf %s/sim/dnode1/data/mnode_bak/" % testPath) + tdSql.execute("drop database if exists db2") + os.system("%staosdemo -f wal/insertDataDb1.json -y " % binPath) + tdSql.execute("drop database if exists db1") + os.system("%staosdemo -f wal/insertDataDb2.json -y " % binPath) + tdSql.execute("drop table if exists db2.stb0") + os.system("%staosdemo -f wal/insertDataDb2Newstab.json -y " % binPath) + query_pid1 = int(subprocess.getstatusoutput('ps aux|grep taosd |grep -v "grep"|awk \'{print $2}\'')[1]) + print(query_pid1) + tdSql.execute("use db2") + tdSql.execute("drop table if exists stb1_0") + tdSql.execute("drop table if exists stb1_1") + tdSql.execute("insert into stb0_0 values(1614218412000,8637,78.861045,'R','bf3')(1614218422000,8637,98.861045,'R','bf3')") + tdSql.execute("alter table db2.stb0 add column col4 int") + tdSql.execute("alter table db2.stb0 drop column col2") + tdSql.execute("alter table db2.stb0 add tag t3 int;") + tdSql.execute("alter table db2.stb0 drop tag t1") + tdSql.execute("create table if not exists stb2_0 (ts timestamp, col0 int, col1 float) ") + tdSql.execute("insert into stb2_0 values(1614218412000,8637,78.861045)") + tdSql.execute("alter table stb2_0 add column col2 binary(4)") + tdSql.execute("alter table stb2_0 drop column col1") + tdSql.execute("insert into stb2_0 values(1614218422000,8638,'R')") + + # stop taosd and compact wal file + tdDnodes.stop(1) + sleep(10) + os.system("nohup %s/taosd --compact-mnode-wal -c %s/sim/dnode1/cfg/ & " %(binPath,testPath) ) + sleep(5) + assert os.path.exists(walFilePath) , "%s is not generated, compact didn't take effect " % walFilePath + + # use new wal file to start taosd + tdDnodes.start(1) + sleep(5) + tdSql.execute("reset query cache") + query_pid2 = int(subprocess.getstatusoutput('ps aux|grep taosd |grep -v "grep"|awk \'{print $2}\'')[1]) + print(query_pid2) + + # verify that the data is correct + tdSql.execute("use db2") + tdSql.query("select count (tbname) from stb0") + tdSql.checkData(0, 0, 1) + tdSql.query("select count (tbname) from stb1") + tdSql.checkRows(0) + tdSql.query("select count(*) from stb0_0") + tdSql.checkData(0, 0, 2) + tdSql.query("select count(*) from stb0") + tdSql.checkData(0, 0, 2) + tdSql.query("select count(*) from stb2_0") + tdSql.checkData(0, 0, 2) + + # delete useless file + testcaseFilename = os.path.split(__file__)[-1] + os.system("rm -rf ./insert_res.txt") + os.system("rm -rf wal/%s.sql" % testcaseFilename ) + + + + def stop(self): + tdSql.close() + tdLog.success("%s successfully executed" % __file__) + + +tdCases.addWindows(__file__, TDTestCase()) +tdCases.addLinux(__file__, TDTestCase()) diff --git a/tests/pytest/wal/sdbCompCluster.py b/tests/pytest/wal/sdbCompCluster.py new file mode 100644 index 0000000000000000000000000000000000000000..4fa84817ec01c9e5adfdb4a76bc29a4a6c49abfc --- /dev/null +++ b/tests/pytest/wal/sdbCompCluster.py @@ -0,0 +1,135 @@ +################################################################### +# Copyright (c) 2016 by TAOS Technologies, Inc. +# All rights reserved. +# +# This file is proprietary and confidential to TAOS Technologies. +# No part of this file may be reproduced, stored, transmitted, +# disclosed or used in any form or by any means other than as +# expressly provided by the written permission from Jianhui Tao +# +################################################################### + +# -*- coding: utf-8 -*- + +import os +import sys +sys.path.insert(0, os.getcwd()) +from util.log import * +from util.sql import * +from util.dnodes import * +import taos +import threading + + +class TwoClients: + def initConnection(self): + self.host = "chenhaoran02" + self.user = "root" + self.password = "taosdata" + self.config = "/etc/taos/" + self.port =6030 + self.rowNum = 10 + self.ts = 1537146000000 + + def getBuildPath(self): + selfPath = os.path.dirname(os.path.realpath(__file__)) + + if ("community" in selfPath): + projPath = selfPath[:selfPath.find("community")] + else: + projPath = selfPath[:selfPath.find("tests")] + + for root, dirs, files in os.walk(projPath): + if ("taosd" in files): + rootRealPath = os.path.dirname(os.path.realpath(root)) + if ("packaging" not in rootRealPath): + buildPath = root[:len(root)-len("/build/bin")] + break + return buildPath + + def run(self): + buildPath = self.getBuildPath() + if (buildPath == ""): + tdLog.exit("taosd not found!") + else: + tdLog.info("taosd found in %s" % buildPath) + binPath = buildPath+ "/build/bin/" + walFilePath = "/var/lib/taos/mnode_bak/wal/" + + # new taos client + conn1 = taos.connect(host=self.host, user=self.user, password=self.password, config=self.config ) + print(conn1) + cur1 = conn1.cursor() + tdSql.init(cur1, True) + + # new db and insert data + os.system("rm -rf /var/lib/taos/mnode_bak/") + os.system("rm -rf /var/lib/taos/mnode_temp/") + tdSql.execute("drop database if exists db2") + os.system("%staosdemo -f wal/insertDataDb1.json -y " % binPath) + tdSql.execute("drop database if exists db1") + os.system("%staosdemo -f wal/insertDataDb2.json -y " % binPath) + tdSql.execute("drop table if exists db2.stb0") + os.system("%staosdemo -f wal/insertDataDb2Newstab.json -y " % binPath) + query_pid1 = int(subprocess.getstatusoutput('ps aux|grep taosd |grep -v "grep"|awk \'{print $2}\'')[1]) + print(query_pid1) + tdSql.execute("use db2") + tdSql.execute("drop table if exists stb1_0") + tdSql.execute("drop table if exists stb1_1") + tdSql.execute("insert into stb0_0 values(1614218412000,8637,78.861045,'R','bf3')(1614218422000,8637,98.861045,'R','bf3')") + tdSql.execute("alter table db2.stb0 add column col4 int") + tdSql.execute("alter table db2.stb0 drop column col2") + tdSql.execute("alter table db2.stb0 add tag t3 int") + tdSql.execute("alter table db2.stb0 drop tag t1") + tdSql.execute("create table if not exists stb2_0 (ts timestamp, col0 int, col1 float) ") + tdSql.execute("insert into stb2_0 values(1614218412000,8637,78.861045)") + tdSql.execute("alter table stb2_0 add column col2 binary(4)") + tdSql.execute("alter table stb2_0 drop column col1") + tdSql.execute("insert into stb2_0 values(1614218422000,8638,'R')") + + # stop taosd and compact wal file + os.system("ps -ef |grep taosd |grep -v 'grep' |awk '{print $2}'|xargs kill -2") + sleep(10) + os.system("nohup taosd --compact-mnode-wal -c /etc/taos & ") + sleep(10) + os.system("nohup /usr/bin/taosd > /dev/null 2>&1 &") + sleep(4) + tdSql.execute("reset query cache") + query_pid2 = int(subprocess.getstatusoutput('ps aux|grep taosd |grep -v "grep"|awk \'{print $2}\'')[1]) + print(query_pid2) + assert os.path.exists(walFilePath) , "%s is not generated " % walFilePath + + # new taos connecting to server + conn2 = taos.connect(host=self.host, user=self.user, password=self.password, config=self.config ) + print(conn2) + cur2 = conn2.cursor() + tdSql.init(cur2, True) + + # use new wal file to start up tasod + tdSql.query("show databases") + for i in range(tdSql.queryRows): + if tdSql.queryResult[i][0]=="db2": + assert tdSql.queryResult[i][4]==1 , "replica is wrong" + tdSql.execute("use db2") + tdSql.query("select count (tbname) from stb0") + tdSql.checkData(0, 0, 1) + tdSql.query("select count (tbname) from stb1") + tdSql.checkRows(0) + tdSql.query("select count(*) from stb0_0") + tdSql.checkData(0, 0, 2) + tdSql.query("select count(*) from stb0") + tdSql.checkData(0, 0, 2) + tdSql.query("select count(*) from stb2_0") + tdSql.checkData(0, 0, 2) + tdSql.query("select * from stb2_0") + tdSql.checkData(1, 2, 'R') + + # delete useless file + testcaseFilename = os.path.split(__file__)[-1] + os.system("rm -rf ./insert_res.txt") + os.system("rm -rf wal/%s.sql" % testcaseFilename ) + +clients = TwoClients() +clients.initConnection() +# clients.getBuildPath() +clients.run() \ No newline at end of file diff --git a/tests/pytest/wal/sdbCompClusterReplica2.py b/tests/pytest/wal/sdbCompClusterReplica2.py new file mode 100644 index 0000000000000000000000000000000000000000..117da8ca2ffd046e3cf23399174184b1f64e856b --- /dev/null +++ b/tests/pytest/wal/sdbCompClusterReplica2.py @@ -0,0 +1,136 @@ +################################################################### +# Copyright (c) 2016 by TAOS Technologies, Inc. +# All rights reserved. +# +# This file is proprietary and confidential to TAOS Technologies. +# No part of this file may be reproduced, stored, transmitted, +# disclosed or used in any form or by any means other than as +# expressly provided by the written permission from Jianhui Tao +# +################################################################### + +# -*- coding: utf-8 -*- + +import os +import sys +sys.path.insert(0, os.getcwd()) +from util.log import * +from util.sql import * +from util.dnodes import * +import taos +import threading + + +class TwoClients: + def initConnection(self): + self.host = "chenhaoran02" + self.user = "root" + self.password = "taosdata" + self.config = "/etc/taos/" + self.port =6030 + self.rowNum = 10 + self.ts = 1537146000000 + + def getBuildPath(self): + selfPath = os.path.dirname(os.path.realpath(__file__)) + + if ("community" in selfPath): + projPath = selfPath[:selfPath.find("community")] + else: + projPath = selfPath[:selfPath.find("tests")] + + for root, dirs, files in os.walk(projPath): + if ("taosd" in files): + rootRealPath = os.path.dirname(os.path.realpath(root)) + if ("packaging" not in rootRealPath): + buildPath = root[:len(root)-len("/build/bin")] + break + return buildPath + + def run(self): + buildPath = self.getBuildPath() + if (buildPath == ""): + tdLog.exit("taosd not found!") + else: + tdLog.info("taosd found in %s" % buildPath) + binPath = buildPath+ "/build/bin/" + walFilePath = "/var/lib/taos/mnode_bak/wal/" + + # new taos client + conn1 = taos.connect(host=self.host, user=self.user, password=self.password, config=self.config ) + print(conn1) + cur1 = conn1.cursor() + tdSql.init(cur1, True) + + # new db and insert data + os.system("rm -rf /var/lib/taos/mnode_bak/") + os.system("rm -rf /var/lib/taos/mnode_temp/") + tdSql.execute("drop database if exists db2") + os.system("%staosdemo -f wal/insertDataDb1Replica2.json -y " % binPath) + tdSql.execute("drop database if exists db1") + os.system("%staosdemo -f wal/insertDataDb2Replica2.json -y " % binPath) + tdSql.execute("drop table if exists db2.stb0") + os.system("%staosdemo -f wal/insertDataDb2NewstabReplica2.json -y " % binPath) + query_pid1 = int(subprocess.getstatusoutput('ps aux|grep taosd |grep -v "grep"|awk \'{print $2}\'')[1]) + print(query_pid1) + tdSql.execute("use db2") + tdSql.execute("drop table if exists stb1_0") + tdSql.execute("drop table if exists stb1_1") + tdSql.execute("insert into stb0_0 values(1614218412000,8637,78.861045,'R','bf3')(1614218422000,8637,98.861045,'R','bf3')") + tdSql.execute("alter table db2.stb0 add column col4 int") + tdSql.execute("alter table db2.stb0 drop column col2") + tdSql.execute("alter table db2.stb0 add tag t3 int") + tdSql.execute("alter table db2.stb0 drop tag t1") + tdSql.execute("create table if not exists stb2_0 (ts timestamp, col0 int, col1 float) ") + tdSql.execute("insert into stb2_0 values(1614218412000,8637,78.861045)") + tdSql.execute("alter table stb2_0 add column col2 binary(4)") + tdSql.execute("alter table stb2_0 drop column col1") + tdSql.execute("insert into stb2_0 values(1614218422000,8638,'R')") + + + # stop taosd and compact wal file + os.system("ps -ef |grep taosd |grep -v 'grep' |awk '{print $2}'|xargs kill -2") + sleep(10) + os.system("nohup taosd --compact-mnode-wal -c /etc/taos & ") + sleep(10) + os.system("nohup /usr/bin/taosd > /dev/null 2>&1 &") + sleep(4) + tdSql.execute("reset query cache") + query_pid2 = int(subprocess.getstatusoutput('ps aux|grep taosd |grep -v "grep"|awk \'{print $2}\'')[1]) + print(query_pid2) + assert os.path.exists(walFilePath) , "%s is not generated " % walFilePath + + # new taos connecting to server + conn2 = taos.connect(host=self.host, user=self.user, password=self.password, config=self.config ) + print(conn2) + cur2 = conn2.cursor() + tdSql.init(cur2, True) + + # use new wal file to start up tasod + tdSql.query("show databases") + for i in range(tdSql.queryRows): + if tdSql.queryResult[i][0]=="db2": + assert tdSql.queryResult[i][4]==2 , "replica is wrong" + tdSql.execute("use db2") + tdSql.query("select count (tbname) from stb0") + tdSql.checkData(0, 0, 1) + tdSql.query("select count (tbname) from stb1") + tdSql.checkRows(0) + tdSql.query("select count(*) from stb0_0") + tdSql.checkData(0, 0, 2) + tdSql.query("select count(*) from stb0") + tdSql.checkData(0, 0, 2) + tdSql.query("select count(*) from stb2_0") + tdSql.checkData(0, 0, 2) + tdSql.query("select * from stb2_0") + tdSql.checkData(1, 2, 'R') + + # delete useless file + testcaseFilename = os.path.split(__file__)[-1] + os.system("rm -rf ./insert_res.txt") + os.system("rm -rf wal/%s.sql" % testcaseFilename ) + +clients = TwoClients() +clients.initConnection() +# clients.getBuildPath() +clients.run() \ No newline at end of file diff --git a/tests/script/api/batchprepare.c b/tests/script/api/batchprepare.c index 55eb62d9bb4272fe7ab85a96561ebd9c87343ed0..72bb9471db8e2c3043306c332c608f1b4f1df836 100644 --- a/tests/script/api/batchprepare.c +++ b/tests/script/api/batchprepare.c @@ -1458,8 +1458,783 @@ int stmt_funcb_autoctb3(TAOS_STMT *stmt) { + +//1 tables 10 records +int stmt_funcb_autoctb4(TAOS_STMT *stmt) { + struct { + int64_t *ts; + int8_t b[10]; + int8_t v1[10]; + int16_t v2[10]; + int32_t v4[10]; + int64_t v8[10]; + float f4[10]; + double f8[10]; + char bin[10][40]; + } v = {0}; + + v.ts = malloc(sizeof(int64_t) * 1 * 10); + + int *lb = malloc(10 * sizeof(int)); + + TAOS_BIND *tags = calloc(1, sizeof(TAOS_BIND) * 9 * 1); + TAOS_MULTI_BIND *params = calloc(1, sizeof(TAOS_MULTI_BIND) * 1*5); + +// int one_null = 1; + int one_not_null = 0; + + char* is_null = malloc(sizeof(char) * 10); + char* no_null = malloc(sizeof(char) * 10); + + for (int i = 0; i < 10; ++i) { + lb[i] = 40; + no_null[i] = 0; + is_null[i] = (i % 10 == 2) ? 1 : 0; + v.b[i] = (int8_t)(i % 2); + v.v1[i] = (int8_t)((i+1) % 2); + v.v2[i] = (int16_t)i; + v.v4[i] = (int32_t)(i+1); + v.v8[i] = (int64_t)(i+2); + v.f4[i] = (float)(i+3); + v.f8[i] = (double)(i+4); + memset(v.bin[i], '0'+i%10, 40); + } + + for (int i = 0; i < 5; i+=5) { + params[i+0].buffer_type = TSDB_DATA_TYPE_TIMESTAMP; + params[i+0].buffer_length = sizeof(int64_t); + params[i+0].buffer = &v.ts[10*i/10]; + params[i+0].length = NULL; + params[i+0].is_null = no_null; + params[i+0].num = 10; + + params[i+1].buffer_type = TSDB_DATA_TYPE_BOOL; + params[i+1].buffer_length = sizeof(int8_t); + params[i+1].buffer = v.b; + params[i+1].length = NULL; + params[i+1].is_null = is_null; + params[i+1].num = 10; + + params[i+2].buffer_type = TSDB_DATA_TYPE_INT; + params[i+2].buffer_length = sizeof(int32_t); + params[i+2].buffer = v.v4; + params[i+2].length = NULL; + params[i+2].is_null = is_null; + params[i+2].num = 10; + + params[i+3].buffer_type = TSDB_DATA_TYPE_BIGINT; + params[i+3].buffer_length = sizeof(int64_t); + params[i+3].buffer = v.v8; + params[i+3].length = NULL; + params[i+3].is_null = is_null; + params[i+3].num = 10; + + params[i+4].buffer_type = TSDB_DATA_TYPE_DOUBLE; + params[i+4].buffer_length = sizeof(double); + params[i+4].buffer = v.f8; + params[i+4].length = NULL; + params[i+4].is_null = is_null; + params[i+4].num = 10; + } + + int64_t tts = 1591060628000; + for (int i = 0; i < 10; ++i) { + v.ts[i] = tts + i; + } + + + for (int i = 0; i < 1; ++i) { + tags[i+0].buffer_type = TSDB_DATA_TYPE_BOOL; + tags[i+0].buffer = v.b; + tags[i+0].is_null = &one_not_null; + tags[i+0].length = NULL; + + tags[i+1].buffer_type = TSDB_DATA_TYPE_SMALLINT; + tags[i+1].buffer = v.v2; + tags[i+1].is_null = &one_not_null; + tags[i+1].length = NULL; + + tags[i+2].buffer_type = TSDB_DATA_TYPE_FLOAT; + tags[i+2].buffer = v.f4; + tags[i+2].is_null = &one_not_null; + tags[i+2].length = NULL; + + tags[i+3].buffer_type = TSDB_DATA_TYPE_BINARY; + tags[i+3].buffer = v.bin; + tags[i+3].is_null = &one_not_null; + tags[i+3].length = (uintptr_t *)lb; + } + + + unsigned long long starttime = getCurrentTime(); + + char *sql = "insert into ? using stb1 tags(1,?,2,?,4,?,6.0,?,'b') (ts,b,v4,v8,f8) values(?,?,?,?,?)"; + int code = taos_stmt_prepare(stmt, sql, 0); + if (code != 0){ + printf("failed to execute taos_stmt_prepare. code:0x%x\n", code); + exit(1); + } + + int id = 0; + for (int zz = 0; zz < 1; zz++) { + char buf[32]; + sprintf(buf, "m%d", zz); + code = taos_stmt_set_tbname_tags(stmt, buf, tags); + if (code != 0){ + printf("failed to execute taos_stmt_set_tbname_tags. code:0x%x\n", code); + } + + taos_stmt_bind_param_batch(stmt, params + id * 5); + taos_stmt_add_batch(stmt); + } + + if (taos_stmt_execute(stmt) != 0) { + printf("failed to execute insert statement.\n"); + exit(1); + } + + ++id; + + unsigned long long endtime = getCurrentTime(); + printf("insert total %d records, used %u seconds, avg:%u useconds\n", 10, (endtime-starttime)/1000000UL, (endtime-starttime)/(10)); + + free(v.ts); + free(lb); + free(params); + free(is_null); + free(no_null); + free(tags); + + return 0; +} + + + + + +//1 tables 10 records +int stmt_funcb_autoctb_e1(TAOS_STMT *stmt) { + struct { + int64_t *ts; + int8_t b[10]; + int8_t v1[10]; + int16_t v2[10]; + int32_t v4[10]; + int64_t v8[10]; + float f4[10]; + double f8[10]; + char bin[10][40]; + } v = {0}; + + v.ts = malloc(sizeof(int64_t) * 1 * 10); + + int *lb = malloc(10 * sizeof(int)); + + TAOS_BIND *tags = calloc(1, sizeof(TAOS_BIND) * 9 * 1); + TAOS_MULTI_BIND *params = calloc(1, sizeof(TAOS_MULTI_BIND) * 1*10); + +// int one_null = 1; + int one_not_null = 0; + + char* is_null = malloc(sizeof(char) * 10); + char* no_null = malloc(sizeof(char) * 10); + + for (int i = 0; i < 10; ++i) { + lb[i] = 40; + no_null[i] = 0; + is_null[i] = (i % 10 == 2) ? 1 : 0; + v.b[i] = (int8_t)(i % 2); + v.v1[i] = (int8_t)((i+1) % 2); + v.v2[i] = (int16_t)i; + v.v4[i] = (int32_t)(i+1); + v.v8[i] = (int64_t)(i+2); + v.f4[i] = (float)(i+3); + v.f8[i] = (double)(i+4); + memset(v.bin[i], '0'+i%10, 40); + } + + for (int i = 0; i < 10; i+=10) { + params[i+0].buffer_type = TSDB_DATA_TYPE_TIMESTAMP; + params[i+0].buffer_length = sizeof(int64_t); + params[i+0].buffer = &v.ts[10*i/10]; + params[i+0].length = NULL; + params[i+0].is_null = no_null; + params[i+0].num = 10; + + params[i+1].buffer_type = TSDB_DATA_TYPE_BOOL; + params[i+1].buffer_length = sizeof(int8_t); + params[i+1].buffer = v.b; + params[i+1].length = NULL; + params[i+1].is_null = is_null; + params[i+1].num = 10; + + params[i+2].buffer_type = TSDB_DATA_TYPE_TINYINT; + params[i+2].buffer_length = sizeof(int8_t); + params[i+2].buffer = v.v1; + params[i+2].length = NULL; + params[i+2].is_null = is_null; + params[i+2].num = 10; + + params[i+3].buffer_type = TSDB_DATA_TYPE_SMALLINT; + params[i+3].buffer_length = sizeof(int16_t); + params[i+3].buffer = v.v2; + params[i+3].length = NULL; + params[i+3].is_null = is_null; + params[i+3].num = 10; + + params[i+4].buffer_type = TSDB_DATA_TYPE_INT; + params[i+4].buffer_length = sizeof(int32_t); + params[i+4].buffer = v.v4; + params[i+4].length = NULL; + params[i+4].is_null = is_null; + params[i+4].num = 10; + + params[i+5].buffer_type = TSDB_DATA_TYPE_BIGINT; + params[i+5].buffer_length = sizeof(int64_t); + params[i+5].buffer = v.v8; + params[i+5].length = NULL; + params[i+5].is_null = is_null; + params[i+5].num = 10; + + params[i+6].buffer_type = TSDB_DATA_TYPE_FLOAT; + params[i+6].buffer_length = sizeof(float); + params[i+6].buffer = v.f4; + params[i+6].length = NULL; + params[i+6].is_null = is_null; + params[i+6].num = 10; + + params[i+7].buffer_type = TSDB_DATA_TYPE_DOUBLE; + params[i+7].buffer_length = sizeof(double); + params[i+7].buffer = v.f8; + params[i+7].length = NULL; + params[i+7].is_null = is_null; + params[i+7].num = 10; + + params[i+8].buffer_type = TSDB_DATA_TYPE_BINARY; + params[i+8].buffer_length = 40; + params[i+8].buffer = v.bin; + params[i+8].length = lb; + params[i+8].is_null = is_null; + params[i+8].num = 10; + + params[i+9].buffer_type = TSDB_DATA_TYPE_BINARY; + params[i+9].buffer_length = 40; + params[i+9].buffer = v.bin; + params[i+9].length = lb; + params[i+9].is_null = is_null; + params[i+9].num = 10; + + } + + int64_t tts = 1591060628000; + for (int i = 0; i < 10; ++i) { + v.ts[i] = tts + i; + } + + + for (int i = 0; i < 1; ++i) { + tags[i+0].buffer_type = TSDB_DATA_TYPE_BOOL; + tags[i+0].buffer = v.b; + tags[i+0].is_null = &one_not_null; + tags[i+0].length = NULL; + + tags[i+1].buffer_type = TSDB_DATA_TYPE_SMALLINT; + tags[i+1].buffer = v.v2; + tags[i+1].is_null = &one_not_null; + tags[i+1].length = NULL; + + tags[i+2].buffer_type = TSDB_DATA_TYPE_FLOAT; + tags[i+2].buffer = v.f4; + tags[i+2].is_null = &one_not_null; + tags[i+2].length = NULL; + + tags[i+3].buffer_type = TSDB_DATA_TYPE_BINARY; + tags[i+3].buffer = v.bin; + tags[i+3].is_null = &one_not_null; + tags[i+3].length = (uintptr_t *)lb; + } + + + unsigned long long starttime = getCurrentTime(); + + char *sql = "insert into ? using stb1 (id1,id2,id3,id4,id5,id6,id7,id8,id9) tags(1,?,2,?,4,?,6.0,?,'b') values(?,?,?,?,?,?,?,?,?,?)"; + int code = taos_stmt_prepare(stmt, sql, 0); + if (code != 0){ + printf("failed to execute taos_stmt_prepare. error:%s\n", taos_stmt_errstr(stmt)); + return -1; + } + + int id = 0; + for (int zz = 0; zz < 1; zz++) { + char buf[32]; + sprintf(buf, "m%d", zz); + code = taos_stmt_set_tbname_tags(stmt, buf, tags); + if (code != 0){ + printf("failed to execute taos_stmt_set_tbname_tags. code:0x%x\n", code); + } + + taos_stmt_bind_param_batch(stmt, params + id * 10); + taos_stmt_add_batch(stmt); + } + + if (taos_stmt_execute(stmt) != 0) { + printf("failed to execute insert statement.\n"); + exit(1); + } + + ++id; + + unsigned long long endtime = getCurrentTime(); + printf("insert total %d records, used %u seconds, avg:%u useconds\n", 10, (endtime-starttime)/1000000UL, (endtime-starttime)/(10)); + + free(v.ts); + free(lb); + free(params); + free(is_null); + free(no_null); + free(tags); + + return 0; +} + + + + + +//1 tables 10 records +int stmt_funcb_autoctb_e2(TAOS_STMT *stmt) { + struct { + int64_t *ts; + int8_t b[10]; + int8_t v1[10]; + int16_t v2[10]; + int32_t v4[10]; + int64_t v8[10]; + float f4[10]; + double f8[10]; + char bin[10][40]; + } v = {0}; + + v.ts = malloc(sizeof(int64_t) * 1 * 10); + + int *lb = malloc(10 * sizeof(int)); + + TAOS_BIND *tags = calloc(1, sizeof(TAOS_BIND) * 9 * 1); + TAOS_MULTI_BIND *params = calloc(1, sizeof(TAOS_MULTI_BIND) * 1*10); + +// int one_null = 1; + int one_not_null = 0; + + char* is_null = malloc(sizeof(char) * 10); + char* no_null = malloc(sizeof(char) * 10); + + for (int i = 0; i < 10; ++i) { + lb[i] = 40; + no_null[i] = 0; + is_null[i] = (i % 10 == 2) ? 1 : 0; + v.b[i] = (int8_t)(i % 2); + v.v1[i] = (int8_t)((i+1) % 2); + v.v2[i] = (int16_t)i; + v.v4[i] = (int32_t)(i+1); + v.v8[i] = (int64_t)(i+2); + v.f4[i] = (float)(i+3); + v.f8[i] = (double)(i+4); + memset(v.bin[i], '0'+i%10, 40); + } + + for (int i = 0; i < 10; i+=10) { + params[i+0].buffer_type = TSDB_DATA_TYPE_TIMESTAMP; + params[i+0].buffer_length = sizeof(int64_t); + params[i+0].buffer = &v.ts[10*i/10]; + params[i+0].length = NULL; + params[i+0].is_null = no_null; + params[i+0].num = 10; + + params[i+1].buffer_type = TSDB_DATA_TYPE_BOOL; + params[i+1].buffer_length = sizeof(int8_t); + params[i+1].buffer = v.b; + params[i+1].length = NULL; + params[i+1].is_null = is_null; + params[i+1].num = 10; + + params[i+2].buffer_type = TSDB_DATA_TYPE_TINYINT; + params[i+2].buffer_length = sizeof(int8_t); + params[i+2].buffer = v.v1; + params[i+2].length = NULL; + params[i+2].is_null = is_null; + params[i+2].num = 10; + + params[i+3].buffer_type = TSDB_DATA_TYPE_SMALLINT; + params[i+3].buffer_length = sizeof(int16_t); + params[i+3].buffer = v.v2; + params[i+3].length = NULL; + params[i+3].is_null = is_null; + params[i+3].num = 10; + + params[i+4].buffer_type = TSDB_DATA_TYPE_INT; + params[i+4].buffer_length = sizeof(int32_t); + params[i+4].buffer = v.v4; + params[i+4].length = NULL; + params[i+4].is_null = is_null; + params[i+4].num = 10; + + params[i+5].buffer_type = TSDB_DATA_TYPE_BIGINT; + params[i+5].buffer_length = sizeof(int64_t); + params[i+5].buffer = v.v8; + params[i+5].length = NULL; + params[i+5].is_null = is_null; + params[i+5].num = 10; + + params[i+6].buffer_type = TSDB_DATA_TYPE_FLOAT; + params[i+6].buffer_length = sizeof(float); + params[i+6].buffer = v.f4; + params[i+6].length = NULL; + params[i+6].is_null = is_null; + params[i+6].num = 10; + + params[i+7].buffer_type = TSDB_DATA_TYPE_DOUBLE; + params[i+7].buffer_length = sizeof(double); + params[i+7].buffer = v.f8; + params[i+7].length = NULL; + params[i+7].is_null = is_null; + params[i+7].num = 10; + + params[i+8].buffer_type = TSDB_DATA_TYPE_BINARY; + params[i+8].buffer_length = 40; + params[i+8].buffer = v.bin; + params[i+8].length = lb; + params[i+8].is_null = is_null; + params[i+8].num = 10; + + params[i+9].buffer_type = TSDB_DATA_TYPE_BINARY; + params[i+9].buffer_length = 40; + params[i+9].buffer = v.bin; + params[i+9].length = lb; + params[i+9].is_null = is_null; + params[i+9].num = 10; + + } + + int64_t tts = 1591060628000; + for (int i = 0; i < 10; ++i) { + v.ts[i] = tts + i; + } + + + for (int i = 0; i < 1; ++i) { + tags[i+0].buffer_type = TSDB_DATA_TYPE_INT; + tags[i+0].buffer = v.v4; + tags[i+0].is_null = &one_not_null; + tags[i+0].length = NULL; + + tags[i+1].buffer_type = TSDB_DATA_TYPE_BOOL; + tags[i+1].buffer = v.b; + tags[i+1].is_null = &one_not_null; + tags[i+1].length = NULL; + + tags[i+2].buffer_type = TSDB_DATA_TYPE_TINYINT; + tags[i+2].buffer = v.v1; + tags[i+2].is_null = &one_not_null; + tags[i+2].length = NULL; + + tags[i+3].buffer_type = TSDB_DATA_TYPE_SMALLINT; + tags[i+3].buffer = v.v2; + tags[i+3].is_null = &one_not_null; + tags[i+3].length = NULL; + + tags[i+4].buffer_type = TSDB_DATA_TYPE_BIGINT; + tags[i+4].buffer = v.v8; + tags[i+4].is_null = &one_not_null; + tags[i+4].length = NULL; + + tags[i+5].buffer_type = TSDB_DATA_TYPE_FLOAT; + tags[i+5].buffer = v.f4; + tags[i+5].is_null = &one_not_null; + tags[i+5].length = NULL; + + tags[i+6].buffer_type = TSDB_DATA_TYPE_DOUBLE; + tags[i+6].buffer = v.f8; + tags[i+6].is_null = &one_not_null; + tags[i+6].length = NULL; + + tags[i+7].buffer_type = TSDB_DATA_TYPE_BINARY; + tags[i+7].buffer = v.bin; + tags[i+7].is_null = &one_not_null; + tags[i+7].length = (uintptr_t *)lb; + + tags[i+8].buffer_type = TSDB_DATA_TYPE_NCHAR; + tags[i+8].buffer = v.bin; + tags[i+8].is_null = &one_not_null; + tags[i+8].length = (uintptr_t *)lb; + } + + + unsigned long long starttime = getCurrentTime(); + + char *sql = "insert into ? using stb1 tags(?,?,?,?,?,?,?,?,?) values(?,?,?,?,?,?,?,?,?,?)"; + int code = taos_stmt_prepare(stmt, sql, 0); + if (code != 0){ + printf("failed to execute taos_stmt_prepare. code:0x%x\n", code); + exit(1); + } + + int id = 0; + for (int zz = 0; zz < 1; zz++) { + char buf[32]; + sprintf(buf, "m%d", zz); + code = taos_stmt_set_tbname_tags(stmt, buf, NULL); + if (code != 0){ + printf("failed to execute taos_stmt_set_tbname_tags. code:%s\n", taos_stmt_errstr(stmt)); + return -1; + } + + taos_stmt_bind_param_batch(stmt, params + id * 10); + taos_stmt_add_batch(stmt); + } + + if (taos_stmt_execute(stmt) != 0) { + printf("failed to execute insert statement.\n"); + exit(1); + } + + ++id; + + unsigned long long endtime = getCurrentTime(); + printf("insert total %d records, used %u seconds, avg:%u useconds\n", 10, (endtime-starttime)/1000000UL, (endtime-starttime)/(10)); + + free(v.ts); + free(lb); + free(params); + free(is_null); + free(no_null); + free(tags); + + return 0; +} + + + + + + + +//1 tables 10 records +int stmt_funcb_autoctb_e3(TAOS_STMT *stmt) { + struct { + int64_t *ts; + int8_t b[10]; + int8_t v1[10]; + int16_t v2[10]; + int32_t v4[10]; + int64_t v8[10]; + float f4[10]; + double f8[10]; + char bin[10][40]; + } v = {0}; + + v.ts = malloc(sizeof(int64_t) * 1 * 10); + + int *lb = malloc(10 * sizeof(int)); + + TAOS_BIND *tags = calloc(1, sizeof(TAOS_BIND) * 9 * 1); + TAOS_MULTI_BIND *params = calloc(1, sizeof(TAOS_MULTI_BIND) * 1*10); + +// int one_null = 1; + int one_not_null = 0; + + char* is_null = malloc(sizeof(char) * 10); + char* no_null = malloc(sizeof(char) * 10); + + for (int i = 0; i < 10; ++i) { + lb[i] = 40; + no_null[i] = 0; + is_null[i] = (i % 10 == 2) ? 1 : 0; + v.b[i] = (int8_t)(i % 2); + v.v1[i] = (int8_t)((i+1) % 2); + v.v2[i] = (int16_t)i; + v.v4[i] = (int32_t)(i+1); + v.v8[i] = (int64_t)(i+2); + v.f4[i] = (float)(i+3); + v.f8[i] = (double)(i+4); + memset(v.bin[i], '0'+i%10, 40); + } + + for (int i = 0; i < 10; i+=10) { + params[i+0].buffer_type = TSDB_DATA_TYPE_TIMESTAMP; + params[i+0].buffer_length = sizeof(int64_t); + params[i+0].buffer = &v.ts[10*i/10]; + params[i+0].length = NULL; + params[i+0].is_null = no_null; + params[i+0].num = 10; + + params[i+1].buffer_type = TSDB_DATA_TYPE_BOOL; + params[i+1].buffer_length = sizeof(int8_t); + params[i+1].buffer = v.b; + params[i+1].length = NULL; + params[i+1].is_null = is_null; + params[i+1].num = 10; + + params[i+2].buffer_type = TSDB_DATA_TYPE_TINYINT; + params[i+2].buffer_length = sizeof(int8_t); + params[i+2].buffer = v.v1; + params[i+2].length = NULL; + params[i+2].is_null = is_null; + params[i+2].num = 10; + + params[i+3].buffer_type = TSDB_DATA_TYPE_SMALLINT; + params[i+3].buffer_length = sizeof(int16_t); + params[i+3].buffer = v.v2; + params[i+3].length = NULL; + params[i+3].is_null = is_null; + params[i+3].num = 10; + + params[i+4].buffer_type = TSDB_DATA_TYPE_INT; + params[i+4].buffer_length = sizeof(int32_t); + params[i+4].buffer = v.v4; + params[i+4].length = NULL; + params[i+4].is_null = is_null; + params[i+4].num = 10; + + params[i+5].buffer_type = TSDB_DATA_TYPE_BIGINT; + params[i+5].buffer_length = sizeof(int64_t); + params[i+5].buffer = v.v8; + params[i+5].length = NULL; + params[i+5].is_null = is_null; + params[i+5].num = 10; + + params[i+6].buffer_type = TSDB_DATA_TYPE_FLOAT; + params[i+6].buffer_length = sizeof(float); + params[i+6].buffer = v.f4; + params[i+6].length = NULL; + params[i+6].is_null = is_null; + params[i+6].num = 10; + + params[i+7].buffer_type = TSDB_DATA_TYPE_DOUBLE; + params[i+7].buffer_length = sizeof(double); + params[i+7].buffer = v.f8; + params[i+7].length = NULL; + params[i+7].is_null = is_null; + params[i+7].num = 10; + + params[i+8].buffer_type = TSDB_DATA_TYPE_BINARY; + params[i+8].buffer_length = 40; + params[i+8].buffer = v.bin; + params[i+8].length = lb; + params[i+8].is_null = is_null; + params[i+8].num = 10; + + params[i+9].buffer_type = TSDB_DATA_TYPE_BINARY; + params[i+9].buffer_length = 40; + params[i+9].buffer = v.bin; + params[i+9].length = lb; + params[i+9].is_null = is_null; + params[i+9].num = 10; + + } + + int64_t tts = 1591060628000; + for (int i = 0; i < 10; ++i) { + v.ts[i] = tts + i; + } + + + for (int i = 0; i < 1; ++i) { + tags[i+0].buffer_type = TSDB_DATA_TYPE_INT; + tags[i+0].buffer = v.v4; + tags[i+0].is_null = &one_not_null; + tags[i+0].length = NULL; + + tags[i+1].buffer_type = TSDB_DATA_TYPE_BOOL; + tags[i+1].buffer = v.b; + tags[i+1].is_null = &one_not_null; + tags[i+1].length = NULL; + + tags[i+2].buffer_type = TSDB_DATA_TYPE_TINYINT; + tags[i+2].buffer = v.v1; + tags[i+2].is_null = &one_not_null; + tags[i+2].length = NULL; + + tags[i+3].buffer_type = TSDB_DATA_TYPE_SMALLINT; + tags[i+3].buffer = v.v2; + tags[i+3].is_null = &one_not_null; + tags[i+3].length = NULL; + + tags[i+4].buffer_type = TSDB_DATA_TYPE_BIGINT; + tags[i+4].buffer = v.v8; + tags[i+4].is_null = &one_not_null; + tags[i+4].length = NULL; + + tags[i+5].buffer_type = TSDB_DATA_TYPE_FLOAT; + tags[i+5].buffer = v.f4; + tags[i+5].is_null = &one_not_null; + tags[i+5].length = NULL; + + tags[i+6].buffer_type = TSDB_DATA_TYPE_DOUBLE; + tags[i+6].buffer = v.f8; + tags[i+6].is_null = &one_not_null; + tags[i+6].length = NULL; + + tags[i+7].buffer_type = TSDB_DATA_TYPE_BINARY; + tags[i+7].buffer = v.bin; + tags[i+7].is_null = &one_not_null; + tags[i+7].length = (uintptr_t *)lb; + + tags[i+8].buffer_type = TSDB_DATA_TYPE_NCHAR; + tags[i+8].buffer = v.bin; + tags[i+8].is_null = &one_not_null; + tags[i+8].length = (uintptr_t *)lb; + } + + + unsigned long long starttime = getCurrentTime(); + + char *sql = "insert into ? using stb1 (id1,id2,id3,id4,id5,id6,id7,id8,id9) tags(?,?,?,?,?,?,?,?,?) values(?,?,?,?,?,?,?,?,?,?)"; + int code = taos_stmt_prepare(stmt, sql, 0); + if (code != 0){ + printf("failed to execute taos_stmt_prepare. code:%s\n", taos_stmt_errstr(stmt)); + return -1; + //exit(1); + } + + int id = 0; + for (int zz = 0; zz < 1; zz++) { + char buf[32]; + sprintf(buf, "m%d", zz); + code = taos_stmt_set_tbname_tags(stmt, buf, NULL); + if (code != 0){ + printf("failed to execute taos_stmt_set_tbname_tags. code:0x%x\n", code); + return -1; + } + + taos_stmt_bind_param_batch(stmt, params + id * 10); + taos_stmt_add_batch(stmt); + } + + if (taos_stmt_execute(stmt) != 0) { + printf("failed to execute insert statement.\n"); + exit(1); + } + + ++id; + + unsigned long long endtime = getCurrentTime(); + printf("insert total %d records, used %u seconds, avg:%u useconds\n", 10, (endtime-starttime)/1000000UL, (endtime-starttime)/(10)); + + free(v.ts); + free(lb); + free(params); + free(is_null); + free(no_null); + free(tags); + + return 0; +} + + + + //1 tables 10 records -int stmt_funcb_autoctb_e1(TAOS_STMT *stmt) { +int stmt_funcb_autoctb_e4(TAOS_STMT *stmt) { struct { int64_t *ts; int8_t b[10]; @@ -1579,35 +2354,60 @@ int stmt_funcb_autoctb_e1(TAOS_STMT *stmt) { for (int i = 0; i < 1; ++i) { - tags[i+0].buffer_type = TSDB_DATA_TYPE_BOOL; - tags[i+0].buffer = v.b; + tags[i+0].buffer_type = TSDB_DATA_TYPE_INT; + tags[i+0].buffer = v.v4; tags[i+0].is_null = &one_not_null; tags[i+0].length = NULL; - tags[i+1].buffer_type = TSDB_DATA_TYPE_SMALLINT; - tags[i+1].buffer = v.v2; + tags[i+1].buffer_type = TSDB_DATA_TYPE_BOOL; + tags[i+1].buffer = v.b; tags[i+1].is_null = &one_not_null; tags[i+1].length = NULL; - tags[i+2].buffer_type = TSDB_DATA_TYPE_FLOAT; - tags[i+2].buffer = v.f4; + tags[i+2].buffer_type = TSDB_DATA_TYPE_TINYINT; + tags[i+2].buffer = v.v1; tags[i+2].is_null = &one_not_null; tags[i+2].length = NULL; - tags[i+3].buffer_type = TSDB_DATA_TYPE_BINARY; - tags[i+3].buffer = v.bin; + tags[i+3].buffer_type = TSDB_DATA_TYPE_SMALLINT; + tags[i+3].buffer = v.v2; tags[i+3].is_null = &one_not_null; - tags[i+3].length = (uintptr_t *)lb; + tags[i+3].length = NULL; + + tags[i+4].buffer_type = TSDB_DATA_TYPE_BIGINT; + tags[i+4].buffer = v.v8; + tags[i+4].is_null = &one_not_null; + tags[i+4].length = NULL; + + tags[i+5].buffer_type = TSDB_DATA_TYPE_FLOAT; + tags[i+5].buffer = v.f4; + tags[i+5].is_null = &one_not_null; + tags[i+5].length = NULL; + + tags[i+6].buffer_type = TSDB_DATA_TYPE_DOUBLE; + tags[i+6].buffer = v.f8; + tags[i+6].is_null = &one_not_null; + tags[i+6].length = NULL; + + tags[i+7].buffer_type = TSDB_DATA_TYPE_BINARY; + tags[i+7].buffer = v.bin; + tags[i+7].is_null = &one_not_null; + tags[i+7].length = (uintptr_t *)lb; + + tags[i+8].buffer_type = TSDB_DATA_TYPE_NCHAR; + tags[i+8].buffer = v.bin; + tags[i+8].is_null = &one_not_null; + tags[i+8].length = (uintptr_t *)lb; } unsigned long long starttime = getCurrentTime(); - char *sql = "insert into ? using stb1 (id1,id2,id3,id4,id5,id6,id7,id8,id9) tags(1,?,2,?,4,?,6.0,?,'b') values(?,?,?,?,?,?,?,?,?,?)"; + char *sql = "insert into ? using stb1 tags(?,?,?,?,?,?,?,?,?) values(?,?,?,?,?,?,?,?,?,?)"; int code = taos_stmt_prepare(stmt, sql, 0); if (code != 0){ - printf("failed to execute taos_stmt_prepare. code:0x%x\n", code); - return -1; + printf("failed to execute taos_stmt_prepare. code:%s\n", taos_stmt_errstr(stmt)); + exit(1); } int id = 0; @@ -1616,10 +2416,22 @@ int stmt_funcb_autoctb_e1(TAOS_STMT *stmt) { sprintf(buf, "m%d", zz); code = taos_stmt_set_tbname_tags(stmt, buf, tags); if (code != 0){ - printf("failed to execute taos_stmt_set_tbname_tags. code:0x%x\n", code); + printf("failed to execute taos_stmt_set_tbname_tags. error:%s\n", taos_stmt_errstr(stmt)); + exit(1); } - taos_stmt_bind_param_batch(stmt, params + id * 10); + code = taos_stmt_bind_param_batch(stmt, params + id * 10); + if (code != 0) { + printf("failed to execute taos_stmt_bind_param_batch. error:%s\n", taos_stmt_errstr(stmt)); + exit(1); + } + + code = taos_stmt_bind_param_batch(stmt, params + id * 10); + if (code != 0) { + printf("failed to execute taos_stmt_bind_param_batch. error:%s\n", taos_stmt_errstr(stmt)); + return -1; + } + taos_stmt_add_batch(stmt); } @@ -1647,8 +2459,9 @@ int stmt_funcb_autoctb_e1(TAOS_STMT *stmt) { + //1 tables 10 records -int stmt_funcb_autoctb_e2(TAOS_STMT *stmt) { +int stmt_funcb_autoctb_e5(TAOS_STMT *stmt) { struct { int64_t *ts; int8_t b[10]; @@ -1818,23 +2631,34 @@ int stmt_funcb_autoctb_e2(TAOS_STMT *stmt) { unsigned long long starttime = getCurrentTime(); char *sql = "insert into ? using stb1 tags(?,?,?,?,?,?,?,?,?) values(?,?,?,?,?,?,?,?,?,?)"; - int code = taos_stmt_prepare(stmt, sql, 0); + int code = taos_stmt_prepare(NULL, sql, 0); if (code != 0){ - printf("failed to execute taos_stmt_prepare. code:0x%x\n", code); - exit(1); + printf("failed to execute taos_stmt_prepare. code:%s\n", taos_stmt_errstr(NULL)); + return -1; } int id = 0; for (int zz = 0; zz < 1; zz++) { char buf[32]; sprintf(buf, "m%d", zz); - code = taos_stmt_set_tbname_tags(stmt, buf, NULL); + code = taos_stmt_set_tbname_tags(stmt, buf, tags); if (code != 0){ - printf("failed to execute taos_stmt_set_tbname_tags. code:0x%x\n", code); - return -1; + printf("failed to execute taos_stmt_set_tbname_tags. error:%s\n", taos_stmt_errstr(stmt)); + exit(1); } - taos_stmt_bind_param_batch(stmt, params + id * 10); + code = taos_stmt_bind_param_batch(stmt, params + id * 10); + if (code != 0) { + printf("failed to execute taos_stmt_bind_param_batch. error:%s\n", taos_stmt_errstr(stmt)); + exit(1); + } + + code = taos_stmt_bind_param_batch(stmt, params + id * 10); + if (code != 0) { + printf("failed to execute taos_stmt_bind_param_batch. error:%s\n", taos_stmt_errstr(stmt)); + return -1; + } + taos_stmt_add_batch(stmt); } @@ -3375,6 +4199,9 @@ void check_result(TAOS *taos, char *tname, int printr, int expected) { char sql[255] = "SELECT * FROM "; TAOS_RES *result; + //FORCE NO PRINT + printr = 0; + strcat(sql, tname); result = taos_query(taos, sql); @@ -3835,7 +4662,7 @@ void* runcase(void *par) { #endif -#if 1 +#if 1 prepare(taos, 1, 1); stmt = taos_stmt_init(taos); @@ -3859,9 +4686,9 @@ void* runcase(void *par) { stmt = taos_stmt_init(taos); - printf("1t+10r+bm+autoctb start\n"); + printf("1t+10r+bm+autoctb1 start\n"); stmt_funcb_autoctb1(stmt); - printf("1t+10r+bm+autoctb end\n"); + printf("1t+10r+bm+autoctb1 end\n"); printf("check result start\n"); check_result(taos, "m0", 1, 10); printf("check result end\n"); @@ -3874,9 +4701,9 @@ void* runcase(void *par) { stmt = taos_stmt_init(taos); - printf("1t+10r+bm+autoctb start\n"); + printf("1t+10r+bm+autoctb2 start\n"); stmt_funcb_autoctb2(stmt); - printf("1t+10r+bm+autoctb end\n"); + printf("1t+10r+bm+autoctb2 end\n"); printf("check result start\n"); check_result(taos, "m0", 1, 10); printf("check result end\n"); @@ -3890,9 +4717,9 @@ void* runcase(void *par) { stmt = taos_stmt_init(taos); - printf("1t+10r+bm+autoctb start\n"); + printf("1t+10r+bm+autoctb3 start\n"); stmt_funcb_autoctb3(stmt); - printf("1t+10r+bm+autoctb end\n"); + printf("1t+10r+bm+autoctb3 end\n"); printf("check result start\n"); check_result(taos, "m0", 1, 10); printf("check result end\n"); @@ -3900,11 +4727,27 @@ void* runcase(void *par) { #endif + #if 1 prepare(taos, 1, 0); stmt = taos_stmt_init(taos); + printf("1t+10r+bm+autoctb4 start\n"); + stmt_funcb_autoctb4(stmt); + printf("1t+10r+bm+autoctb4 end\n"); + printf("check result start\n"); + check_result(taos, "m0", 1, 10); + printf("check result end\n"); + taos_stmt_close(stmt); +#endif + + +#if 1 + prepare(taos, 1, 0); + + stmt = taos_stmt_init(taos); + printf("1t+10r+bm+autoctb+e1 start\n"); stmt_funcb_autoctb_e1(stmt); printf("1t+10r+bm+autoctb+e1 end\n"); @@ -3930,6 +4773,52 @@ void* runcase(void *par) { #endif +#if 1 + prepare(taos, 1, 0); + + stmt = taos_stmt_init(taos); + + printf("1t+10r+bm+autoctb+e3 start\n"); + stmt_funcb_autoctb_e3(stmt); + printf("1t+10r+bm+autoctb+e3 end\n"); + printf("check result start\n"); + //check_result(taos, "m0", 1, 0); + printf("check result end\n"); + taos_stmt_close(stmt); + +#endif + + +#if 1 + prepare(taos, 1, 0); + + stmt = taos_stmt_init(taos); + + printf("1t+10r+bm+autoctb+e4 start\n"); + stmt_funcb_autoctb_e4(stmt); + printf("1t+10r+bm+autoctb+e4 end\n"); + printf("check result start\n"); + //check_result(taos, "m0", 1, 0); + printf("check result end\n"); + taos_stmt_close(stmt); + +#endif + +#if 1 + prepare(taos, 1, 0); + + stmt = taos_stmt_init(taos); + + printf("1t+10r+bm+autoctb+e5 start\n"); + stmt_funcb_autoctb_e5(stmt); + printf("1t+10r+bm+autoctb+e5 end\n"); + printf("check result start\n"); + //check_result(taos, "m0", 1, 0); + printf("check result end\n"); + taos_stmt_close(stmt); + +#endif + #if 1 prepare(taos, 1, 1); @@ -4138,6 +5027,8 @@ void* runcase(void *par) { #endif + printf("test end\n"); + return NULL; } diff --git a/tests/script/fullGeneralSuite.sim b/tests/script/fullGeneralSuite.sim index 2cd22362005de07eb2a02b1d0fadec9fc8bdca08..937265753323a41e51ddf9a3be0061c66b6c586a 100644 --- a/tests/script/fullGeneralSuite.sim +++ b/tests/script/fullGeneralSuite.sim @@ -135,6 +135,7 @@ run general/parser/tags_dynamically_specifiy.sim run general/parser/set_tag_vals.sim #unsupport run general/parser/repeatAlter.sim #unsupport run general/parser/slimit_alter_tags.sim +run general/parser/precision_ns.sim run general/stable/disk.sim run general/stable/dnode3.sim run general/stable/metrics.sim diff --git a/tests/script/general/db/alter_option.sim b/tests/script/general/db/alter_option.sim index c3bb23855fceb877c1ed39c01524231d27edb4f4..c20a96fd1bd18ba911cce02859d7265d0294b76b 100644 --- a/tests/script/general/db/alter_option.sim +++ b/tests/script/general/db/alter_option.sim @@ -112,21 +112,21 @@ endi sql alter database db keep 30 sql show databases print keep $data7_db -if $data7_db != 20,20,30 then +if $data7_db != 30,30,30 then return -1 endi sql alter database db keep 40 sql show databases print keep $data7_db -if $data7_db != 20,20,40 then +if $data7_db != 40,40,40 then return -1 endi -sql alter database db keep 40 -sql alter database db keep 30 +sql alter database db keep 40,50 +sql alter database db keep 30,31 sql alter database db keep 20 -sql_error alter database db keep 10 +sql_error alter database db keep 10.0 sql_error alter database db keep 9 sql_error alter database db keep 1 sql_error alter database db keep 0 @@ -177,7 +177,7 @@ sql alter database db blocks 20 sql alter database db blocks 10 sql_error alter database db blocks 2 sql_error alter database db blocks 1 -sql alter database db blocks 0 +sql_error alter database db blocks 0 sql_error alter database db blocks -1 sql_error alter database db blocks 10001 diff --git a/tests/script/general/db/topic1.sim b/tests/script/general/db/topic1.sim index 2b4cce5e64bf7076eeb2f0f0e3c1dfbaa224b116..4939e5a0e2274e8ab26465fe04ca99a79f9f9ce0 100644 --- a/tests/script/general/db/topic1.sim +++ b/tests/script/general/db/topic1.sim @@ -367,7 +367,7 @@ sql_error topic db keep 30 sql alter database db keep 30 sql show databases print keep $data7_db -if $data7_db != 20,20,30 then +if $data7_db != 30,30,30 then return -1 endi @@ -375,14 +375,14 @@ sql_error alter topic db keep 40 sql alter database db keep 40 sql show databases print keep $data7_db -if $data7_db != 20,20,40 then +if $data7_db != 40,40,40 then return -1 endi sql alter database db keep 40 sql alter database db keep 30 sql alter database db keep 20 -sql_error alter database db keep 10 +sql_error alter database db keep 10.0 sql_error alter database db keep 9 sql_error alter database db keep 1 sql_error alter database db keep 0 @@ -455,7 +455,7 @@ sql alter database db blocks 20 sql alter database db blocks 10 sql_error alter database db blocks 2 sql_error alter database db blocks 1 -sql alter database db blocks 0 +sql_error alter database db blocks 0 sql_error alter database db blocks -1 sql_error alter database db blocks 10001 diff --git a/tests/script/general/http/restful_full.sim b/tests/script/general/http/restful_full.sim index 8094a943f507a702bb56a7d026da672134188b83..a5d3ac2b862f3b2b72b0453a2c1bb2b578672246 100644 --- a/tests/script/general/http/restful_full.sim +++ b/tests/script/general/http/restful_full.sim @@ -88,7 +88,7 @@ print =============== step2 - no db #11 system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d 'show databases' 127.0.0.1:7111/rest/sql print 11-> $system_content -if $system_content != @{"status":"succ","head":["name","created_time","ntables","vgroups","replica","quorum","days","keep0,keep1,keep(D)","cache(MB)","blocks","minrows","maxrows","wallevel","fsync","comp","cachelast","precision","update","status"],"column_meta":[["name",8,32],["created_time",9,8],["ntables",4,4],["vgroups",4,4],["replica",3,2],["quorum",3,2],["days",3,2],["keep0,keep1,keep(D)",8,24],["cache(MB)",4,4],["blocks",4,4],["minrows",4,4],["maxrows",4,4],["wallevel",2,1],["fsync",4,4],["comp",2,1],["cachelast",2,1],["precision",8,3],["update",2,1],["status",8,10]],"data":[],"rows":0}@ then +if $system_content != @{"status":"succ","head":["name","created_time","ntables","vgroups","replica","quorum","days","keep0,keep1,keep2","cache(MB)","blocks","minrows","maxrows","wallevel","fsync","comp","cachelast","precision","update","status"],"column_meta":[["name",8,32],["created_time",9,8],["ntables",4,4],["vgroups",4,4],["replica",3,2],["quorum",3,2],["days",3,2],["keep0,keep1,keep2",8,24],["cache(MB)",4,4],["blocks",4,4],["minrows",4,4],["maxrows",4,4],["wallevel",2,1],["fsync",4,4],["comp",2,1],["cachelast",2,1],["precision",8,3],["update",2,1],["status",8,10]],"data":[],"rows":0}@ then return -1 endi diff --git a/tests/script/general/parser/alter.sim b/tests/script/general/parser/alter.sim index 6c884973963200fe416fba5a428b7050aa2329c2..d1a4702a69dce22e7de0de005d912e7813648e01 100644 --- a/tests/script/general/parser/alter.sim +++ b/tests/script/general/parser/alter.sim @@ -20,8 +20,82 @@ $db = $dbPrefix . $i $mt = $mtPrefix . $i sql drop database if exists $db -sql create database $db +sql create database $db days 10 keep 20,20,20 sql use $db + +sql_error alter database $db keep "20" +sql_error alter database $db keep "20","20","20" +sql_error alter database $db keep 20,19 +sql_error alter database $db keep 20.0 +sql_error alter database $db keep 20.0,20.0,20.0 +sql_error alter database $db keep 0,0,0 +sql_error alter database $db keep -1,-1,-1 +sql_error alter database $db keep 9,20 +sql_error alter database $db keep 9,9,9 +sql_error alter database $db keep 20,20,19 +sql_error alter database $db keep 20,19,20 +sql_error alter database $db keep 20,19,19 +sql_error alter database $db keep 20,19,18 +sql_error alter database $db keep 20,20,20,20 +sql_error alter database $db keep 365001,365001,365001 +sql alter database $db keep 21 +sql show databases +if $rows != 1 then + return -1 +endi +if $data07 != 21,21,21 then + return -1 +endi +sql alter database $db keep 11,12 +sql show databases +if $rows != 1 then + return -1 +endi +if $data07 != 11,12,12 then + return -1 +endi +sql alter database $db keep 20,20,20 +sql show databases +if $rows != 1 then + return -1 +endi +if $data07 != 20,20,20 then + return -1 +endi +sql alter database $db keep 10,10,10 +sql show databases +if $rows != 1 then + return -1 +endi +if $data07 != 10,10,10 then + return -1 +endi +sql alter database $db keep 10,10,11 +sql show databases +if $rows != 1 then + return -1 +endi +if $data07 != 10,10,11 then + return -1 +endi +sql alter database $db keep 11,12,13 +sql show databases +if $rows != 1 then + return -1 +endi +if $data07 != 11,12,13 then + return -1 +endi +sql alter database $db keep 365000,365000,365000 +sql show databases +if $rows != 1 then + return -1 +endi +if $data07 != 365000,365000,365000 then + return -1 +endi + + ##### alter table test, simeplest case sql create table tb (ts timestamp, c1 int, c2 int, c3 int) sql insert into tb values (now, 1, 1, 1) diff --git a/tests/script/general/parser/alter__for_community_version.sim b/tests/script/general/parser/alter__for_community_version.sim new file mode 100644 index 0000000000000000000000000000000000000000..f55fb812a74eead44e54808b000a48c3db92b66d --- /dev/null +++ b/tests/script/general/parser/alter__for_community_version.sim @@ -0,0 +1,316 @@ +system sh/stop_dnodes.sh + +system sh/deploy.sh -n dnode1 -i 1 +system sh/cfg.sh -n dnode1 -c walLevel -v 1 +system sh/exec.sh -n dnode1 -s start +sleep 100 +sql connect + +$dbPrefix = m_alt_db +$tbPrefix = m_alt_tb +$mtPrefix = m_alt_mt +$tbNum = 10 +$rowNum = 5 +$totalNum = $tbNum * $rowNum +$ts0 = 1537146000000 +$delta = 600000 +print ========== alter.sim +$i = 0 +$db = $dbPrefix . $i +$mt = $mtPrefix . $i + +sql drop database if exists $db +sql create database $db days 10 keep 20 +sql use $db +sql show databases +if $rows != 1 then + return -1 +endi +if $data07 != 20 then + return -1 +endi + +sql_error alter database $db keep "20" +sql_error alter database $db keep "20","20","20" +sql_error alter database $db keep 0 +sql_error alter database $db keep 20.0 +sql_error alter database $db keep 20.0,20.0,20.0 +sql_error alter database $db keep 0,0,0 +sql_error alter database $db keep 3 +sql_error alter database $db keep -1,-1,-1 +sql_error alter database $db keep 20,20 +sql_error alter database $db keep 9,9,9 +sql_error alter database $db keep 20,20,19 +sql_error alter database $db keep 20,19,20 +sql_error alter database $db keep 20,19,19 +sql_error alter database $db keep 20,19,18 +sql_error alter database $db keep 20,20,20,20 +sql_error alter database $db keep 365001,365001,365001 +sql_error alter database $db keep 365001 +sql alter database $db keep 20 +sql show databases +if $rows != 1 then + return -1 +endi +if $data07 != 20 then + return -1 +endi +sql alter database $db keep 10 +sql show databases +if $rows != 1 then + return -1 +endi +if $data07 != 10 then + return -1 +endi +sql alter database $db keep 11 +sql show databases +if $rows != 1 then + return -1 +endi +if $data07 != 11 then + return -1 +endi +sql alter database $db keep 13 +sql show databases +if $rows != 1 then + return -1 +endi +if $data07 != 13 then + return -1 +endi +sql alter database $db keep 365000 +sql show databases +if $rows != 1 then + return -1 +endi +if $data07 != 365000 then + return -1 +endi + + +##### alter table test, simeplest case +sql create table tb (ts timestamp, c1 int, c2 int, c3 int) +sql insert into tb values (now, 1, 1, 1) +sql select * from tb order by ts desc +if $rows != 1 then + return -1 +endi +sql alter table tb drop column c3 +sql select * from tb order by ts desc +if $data01 != 1 then + return -1 +endi +if $data02 != 1 then + return -1 +endi +if $data03 != null then + return -1 +endi +sql alter table tb add column c3 nchar(4) +sql select * from tb order by ts desc +if $rows != 1 then + return -1 +endi +if $data03 != NULL then + return -1 +endi +sql insert into tb values (now, 2, 2, 'taos') +sql select * from tb order by ts desc +if $rows != 2 then + return -1 +endi +print data03 = $data03 +if $data03 != taos then + print expect taos, actual: $data03 + return -1 +endi +sql drop table tb + +##### alter metric test, simplest case +sql create table mt (ts timestamp, c1 int, c2 int, c3 int) tags (t1 int) +sql create table tb using mt tags(1) +sql insert into tb values (now, 1, 1, 1) +sql alter table mt drop column c3 +sql select * from tb order by ts desc +if $data01 != 1 then + return -1 +endi +if $data02 != 1 then + return -1 +endi +if $data03 != null then + return -1 +endi + +sql alter table mt add column c3 nchar(4) +sql select * from tb order by ts desc +if $data03 != NULL then + return -1 +endi +sql insert into tb values (now, 2, 2, 'taos') +sql select * from tb order by ts desc +if $rows != 2 then + return -1 +endi +if $data03 != taos then + return -1 +endi +if $data13 != NULL then + return -1 +endi +sql drop table tb +sql drop table mt + +## [TBASE272] +sql create table tb (ts timestamp, c1 int, c2 int, c3 int) +sql insert into tb values (now, 1, 1, 1) +sql alter table tb drop column c3 +sql alter table tb add column c3 nchar(5) +sql insert into tb values(now, 2, 2, 'taos') +sql drop table tb +sql create table mt (ts timestamp, c1 int, c2 int, c3 int) tags (t1 int) +sql create table tb using mt tags(1) +sql insert into tb values (now, 1, 1, 1) +sql alter table mt drop column c3 +sql select * from tb order by ts desc +if $rows != 1 then + return -1 +endi +sql drop table tb +sql drop table mt + +sleep 100 +### ALTER TABLE WHILE STREAMING [TBASE271] +#sql create table tb1 (ts timestamp, c1 int, c2 nchar(5), c3 int) +#sql create table strm as select count(*), avg(c1), first(c2), sum(c3) from tb1 interval(2s) +#sql select * from strm +#if $rows != 0 then +# return -1 +#endi +##sleep 12000 +#sql insert into tb1 values (now, 1, 'taos', 1) +#sleep 20000 +#sql select * from strm +#print rows = $rows +#if $rows != 1 then +# return -1 +#endi +#if $data04 != 1 then +# return -1 +#endi +#sql alter table tb1 drop column c3 +#sleep 500 +#sql insert into tb1 values (now, 2, 'taos') +#sleep 30000 +#sql select * from strm +#if $rows != 2 then +# return -1 +#endi +#if $data04 != 1 then +# return -1 +#endi +#sql alter table tb1 add column c3 int +#sleep 500 +#sql insert into tb1 values (now, 3, 'taos', 3); +#sleep 100 +#sql select * from strm +#if $rows != 3 then +# return -1 +#endi +#if $data04 != 1 then +# return -1 +#endi + +## ALTER TABLE AND INSERT BY COLUMNS +sql create table mt (ts timestamp, c1 int, c2 int) tags(t1 int) +sql create table tb using mt tags(0) +sql insert into tb values (now-1m, 1, 1) +sql alter table mt drop column c2 +sql_error insert into tb (ts, c1, c2) values (now, 2, 2) +sql insert into tb (ts, c1) values (now, 2) +sql select * from tb order by ts desc +if $rows != 2 then + return -1 +endi +if $data01 != 2 then + return -1 +endi +if $data02 != null then + return -1 +endi +sql alter table mt add column c2 int +sql insert into tb (ts, c2) values (now, 3) +sql select * from tb order by ts desc +if $data02 != 3 then + return -1 +endi + +## ALTER TABLE AND IMPORT +sql drop database $db +sql create database $db +sql use $db +sql create table mt (ts timestamp, c1 int, c2 nchar(7), c3 int) tags (t1 int) +sql create table tb using mt tags(1) +sleep 100 +sql insert into tb values ('2018-11-01 16:30:00.000', 1, 'insert', 1) +sql alter table mt drop column c3 + +sql insert into tb values ('2018-11-01 16:29:59.000', 1, 'insert') +sql import into tb values ('2018-11-01 16:29:59.000', 1, 'import') +sql select * from tb order by ts desc +if $data01 != 1 then + return -1 +endi +if $data02 != insert then + return -1 +endi +sql alter table mt add column c3 nchar(4) +sql select * from tb order by ts desc +if $data03 != NULL then + return -1 +endi + +print ============================>TD-3366 TD-3486 +sql insert into td_3366(ts, c3, c1) using mt(t1) tags(911) values('2018-1-1 11:11:11', 'new1', 12); +sql insert into td_3486(ts, c3, c1) using mt(t1) tags(-12) values('2018-1-1 11:11:11', 'new1', 12); +sql insert into ttxu(ts, c3, c1) using mt(t1) tags('-121') values('2018-1-1 11:11:11', 'new1', 12); + +sql insert into tb(ts, c1, c3) using mt(t1) tags(123) values('2018-11-01 16:29:58.000', 2, 'port') + +sql insert into tb values ('2018-11-01 16:29:58.000', 2, 'import', 3) +sql import into tb values ('2018-11-01 16:29:58.000', 2, 'import', 3) +sql import into tb values ('2018-11-01 16:39:58.000', 2, 'import', 3) +sql select * from tb order by ts desc +if $rows != 4 then + return -1 +endi + +if $data03 != 3 then + return -1 +endi + +##### ILLEGAL OPERATIONS + +# try dropping columns that are defined in metric +sql_error alter table tb drop column c1; + +# try dropping primary key +sql_error alter table mt drop column ts; + +# try modifying two columns in a single statement +sql_error alter table mt add column c5 nchar(3) c6 nchar(4) + +# duplicate columns +sql_error alter table mt add column c1 int + +# drop non-existing columns +sql_error alter table mt drop column c9 + +#sql drop database $db +#sql show databases +#if $rows != 0 then +# return -1 +#endi + +system sh/exec.sh -n dnode1 -s stop -x SIGINT diff --git a/tests/script/general/parser/create_db.sim b/tests/script/general/parser/create_db.sim index 9ca84af136ad16735c9faf4f10ba913775f53103..7881060ad178fe3b3f7a9ea0530a1ac517264a3e 100644 --- a/tests/script/general/parser/create_db.sim +++ b/tests/script/general/parser/create_db.sim @@ -102,7 +102,7 @@ print create_db.sim case5: db_meta_data test # cfg params $replica = 1 # max=3 $days = 10 -$keep = 365 +$keep = 365,365,365 $rows_db = 1000 $cache = 16 # 16MB $ablocks = 100 @@ -150,6 +150,73 @@ sql_error create database $db day 3651 # keep [1, infinity] sql_error create database $db keep 0 +sql_error create database $db keep 0,0,0 +sql_error create database $db keep 3,3,3 +sql_error create database $db keep 11.0 +sql_error create database $db keep 11.0,11.0,11.0 +sql_error create database $db keep "11","11","11" +sql_error create database $db keep "11" +sql_error create database $db keep 13,12,11 +sql_error create database $db keep 11,12,11 +sql_error create database $db keep 12,11,12 +sql_error create database $db keep 8 +sql_error create database $db keep 12,11 +sql_error create database $db keep 365001,365001,365001 +sql create database dbk0 keep 19 +sql show databases +if $rows != 1 then + return -1 +endi +if $data07 != 19,19,19 then + return -1 +endi +sql drop database dbk0 +sql create database dbka keep 19,20 +sql show databases +if $rows != 1 then + return -1 +endi +if $data07 != 19,20,20 then + return -1 +endi +sql drop database dbka + +sql create database dbk1 keep 11,11,11 +sql show databases +if $rows != 1 then + return -1 +endi +if $data07 != 11,11,11 then + return -1 +endi +sql drop database dbk1 +sql create database dbk2 keep 11,12,13 +sql show databases +if $rows != 1 then + return -1 +endi +if $data07 != 11,12,13 then + return -1 +endi +sql drop database dbk2 +sql create database dbk3 keep 11,11,13 +sql show databases +if $rows != 1 then + return -1 +endi +if $data07 != 11,11,13 then + return -1 +endi +sql drop database dbk3 +sql create database dbk4 keep 11,13,13 +sql show databases +if $rows != 1 then + return -1 +endi +if $data07 != 11,13,13 then + return -1 +endi +sql drop database dbk4 #sql_error create database $db keep 3651 # rows [200, 10000] diff --git a/tests/script/general/parser/create_db__for_community_version.sim b/tests/script/general/parser/create_db__for_community_version.sim new file mode 100644 index 0000000000000000000000000000000000000000..406e69b0e6a025c5e733ab753510f65677e4b550 --- /dev/null +++ b/tests/script/general/parser/create_db__for_community_version.sim @@ -0,0 +1,238 @@ +system sh/stop_dnodes.sh + + +system sh/deploy.sh -n dnode1 -i 1 +system sh/cfg.sh -n dnode1 -c walLevel -v 1 +system sh/exec.sh -n dnode1 -s start + +sleep 100 +sql connect +print ======================== dnode1 start + +$dbPrefix = fi_in_db +$tbPrefix = fi_in_tb +$mtPrefix = fi_in_mt +$tbNum = 10 +$rowNum = 20 +$totalNum = 200 + +print excuting test script create_db.sim +print =============== set up +$i = 0 +$db = $dbPrefix . $i +$mt = $mtPrefix . $i + +sql_error createdatabase $db +sql create database $db +sql use $db +sql show databases + +if $rows != 1 then + return -1 +endi +if $data00 != $db then + return -1 +endi +sql drop database $db + +# case1: case_insensitivity test +print =========== create_db.sim case1: case insensitivity test +sql_error CREATEDATABASE $db +sql CREATE DATABASE $db +sql use $db +sql show databases + +if $rows != 1 then + return -1 +endi +if $data00 != $db then + return -1 +endi +sql drop database $db +print case_insensitivity test passed + +# case2: illegal_db_name test +print =========== create_db.sim case2: illegal_db_name test +$illegal_db1 = 1db +$illegal_db2 = d@b + +sql_error create database $illegal_db1 +sql_error create database $illegal_db2 +print illegal_db_name test passed + +# case3: chinese_char_in_db_name test +print ========== create_db.sim case3: chinese_char_in_db_name test +$CN_db1 = 数据库 +$CN_db2 = 数据库1 +$CN_db3 = db数据库1 +sql_error create database $CN_db1 +sql_error create database $CN_db2 +sql_error create database $CN_db3 +#sql show databases +#if $rows != 3 then +# return -1 +#endi +#if $data00 != $CN_db1 then +# return -1 +#endi +#if $data10 != $CN_db2 then +# return -1 +#endi +#if $data20 != $CN_db3 then +# return -1 +#endi +#sql drop database $CN_db1 +#sql drop database $CN_db2 +#sql drop database $CN_db3 +print case_chinese_char_in_db_name test passed + +# case4: db_already_exists +print create_db.sim case4: db_already_exists +sql create database db0 +sql create database db0 +sql show databases +if $rows != 1 then + return -1 +endi +sql drop database db0 +print db_already_exists test passed + +# case5: db_meta_data +print create_db.sim case5: db_meta_data test +# cfg params +$replica = 1 # max=3 +$days = 10 +$keep = 365 +$rows_db = 1000 +$cache = 16 # 16MB +$ablocks = 100 +$tblocks = 32 # max=512, automatically trimmed when exceeding +$ctime = 36000 # 10 hours +$wal = 1 # valid value is 1, 2 +$comp = 1 # max=32, automatically trimmed when exceeding + +sql create database $db replica $replica days $days keep $keep maxrows $rows_db cache $cache blocks 4 ctime $ctime wal $wal comp $comp +sql show databases +if $rows != 1 then + return -1 +endi +if $data00 != $db then + return -1 +endi +if $data04 != $replica then + return -1 +endi +if $data06 != $days then + return -1 +endi +if $data07 != 365 then + return -1 +endi +print data08 = $data07 +if $data08 != $cache then + print expect $cache, actual:$data08 + return -1 +endi +if $data09 != 4 then + return -1 +endi + +sql drop database $db + +## param range tests +# replica [1,3] +#sql_error create database $db replica 0 +sql_error create database $db replica 4 + +# day [1, 3650] +sql_error create database $db day 0 +sql_error create database $db day 3651 + +# keep [1, infinity] +sql_error create database $db keep 0 +sql_error create database $db keep 0,0,0 +sql_error create database $db keep 3,3,3 +sql_error create database $db keep 3 +sql_error create database $db keep 11.0 +sql_error create database $db keep 11.0,11.0,11.0 +sql_error create database $db keep "11","11","11" +sql_error create database $db keep "11" +sql_error create database $db keep 13,12,11 +sql_error create database $db keep 11,12,11 +sql_error create database $db keep 12,11,12 +sql_error create database $db keep 11,12,13 +sql_error create database $db keep 11,12,13,14 +sql_error create database $db keep 11,11 +sql_error create database $db keep 365001,365001,365001 +sql_error create database $db keep 365001 +sql create database dbk1 keep 11 +sql show databases +if $rows != 1 then + return -1 +endi +if $data07 != 11 then + return -1 +endi +sql drop database dbk1 +sql create database dbk2 keep 12 +sql show databases +if $rows != 1 then + return -1 +endi +if $data07 != 12 then + return -1 +endi +sql drop database dbk2 +sql create database dbk3 keep 11 +sql show databases +if $rows != 1 then + return -1 +endi +if $data07 != 11 then + return -1 +endi +sql drop database dbk3 +sql create database dbk4 keep 13 +sql show databases +if $rows != 1 then + return -1 +endi +if $data07 != 13 then + return -1 +endi +sql drop database dbk4 +#sql_error create database $db keep 3651 + +# rows [200, 10000] +sql_error create database $db maxrows 199 +#sql_error create database $db maxrows 10001 + +# cache [100, 10485760] +sql_error create database $db cache 0 +#sql_error create database $db cache 10485761 + + +# blocks [32, 4096 overwriten by 4096 if exceeds, Note added:2018-10-24] +#sql_error create database $db tblocks 31 +#sql_error create database $db tblocks 4097 + +# ctime [30, 40960] +sql_error create database $db ctime 29 +sql_error create database $db ctime 40961 + +# wal {0, 2} +#sql_error create database $db wal 0 +sql_error create database $db wal -1 +sql_error create database $db wal 3 + +# comp {0, 1, 2} +sql_error create database $db comp -1 +sql_error create database $db comp 3 + +sql_error drop database $db +sql show databases +if $rows != 0 then + return -1 +endi + +system sh/exec.sh -n dnode1 -s stop -x SIGINT diff --git a/tests/script/general/parser/first_last.sim b/tests/script/general/parser/first_last.sim index f47f67ddc668c94f423cb3a42d97be3d52c8dcda..09047b4528a68219f27fc3b2e913a62fd567cd42 100644 --- a/tests/script/general/parser/first_last.sim +++ b/tests/script/general/parser/first_last.sim @@ -124,4 +124,4 @@ if $rows != 10000 then return -1 endi -system sh/exec.sh -n dnode1 -s stop -x SIGINT \ No newline at end of file +system sh/exec.sh -n dnode1 -s stop -x SIGINT diff --git a/tests/script/general/parser/function.sim b/tests/script/general/parser/function.sim index 591d5d15351c5b110470287d05127f630d7d1979..6a3e5596c123b8bd7001488d3c09ee0e172f0c67 100644 --- a/tests/script/general/parser/function.sim +++ b/tests/script/general/parser/function.sim @@ -932,3 +932,191 @@ if $data32 != 0.000144445 then return -1 endi +print ===========================> derivative +sql drop table t1 +sql drop table tx; +sql drop table if exists m1; +sql drop table if exists tm0; +sql drop table if exists tm1; + +sql create table tm0(ts timestamp, k double) +sql insert into tm0 values('2015-08-18T00:00:00Z', 2.064) ('2015-08-18T00:06:00Z', 2.116) ('2015-08-18T00:12:00Z', 2.028) +sql insert into tm0 values('2015-08-18T00:18:00Z', 2.126) ('2015-08-18T00:24:00Z', 2.041) ('2015-08-18T00:30:00Z', 2.051) + +sql_error select derivative(ts) from tm0; +sql_error select derivative(k) from tm0; +sql_error select derivative(k, 0, 0) from tm0; +sql_error select derivative(k, 1, 911) from tm0; +sql_error select derivative(kx, 1s, 1) from tm0; +sql_error select derivative(k, -20s, 1) from tm0; +sql_error select derivative(k, 20a, 0) from tm0; +sql_error select derivative(k, 200a, 0) from tm0; +sql_error select derivative(k, 999a, 0) from tm0; +sql_error select derivative(k, 20s, -12) from tm0; + +sql select derivative(k, 1s, 0) from tm0 +if $rows != 5 then + return -1 +endi + +if $data00 != @15-08-18 08:06:00.000@ then + return -1 +endi + +if $data01 != 0.000144444 then + print expect 0.000144444, actual: $data01 + return -1 +endi + +if $data10 != @15-08-18 08:12:00.000@ then + return -1 +endi + +if $data11 != -0.000244444 then + return -1 +endi + +if $data20 != @15-08-18 08:18:00.000@ then + return -1 +endi + +if $data21 != 0.000272222 then + print expect 0.000272222, actual: $data21 + return -1 +endi + +if $data30 != @15-08-18 08:24:00.000@ then + return -1 +endi + +if $data31 != -0.000236111 then + print expect 0.000236111, actual: $data31 + return -1 +endi + +sql select derivative(k, 6m, 0) from tm0; +if $rows != 5 then + return -1 +endi + +if $data00 != @15-08-18 08:06:00.000@ then + return -1 +endi + +if $data01 != 0.052000000 then + print expect 0.052000000, actual: $data01 + return -1 +endi + +if $data10 != @15-08-18 08:12:00.000@ then + return -1 +endi + +if $data11 != -0.088000000 then + return -1 +endi + +if $data20 != @15-08-18 08:18:00.000@ then + return -1 +endi + +if $data21 != 0.098000000 then + return -1 +endi + +if $data30 != @15-08-18 08:24:00.000@ then + return -1 +endi + +if $data31 != -0.085000000 then + return -1 +endi + +sql select derivative(k, 12m, 0) from tm0; +if $rows != 5 then + return -1 +endi + +if $data00 != @15-08-18 08:06:00.000@ then + return -1 +endi + +if $data01 != 0.104000000 then + print expect 0.104000000, actual: $data01 + return -1 +endi + +sql select derivative(k, 6m, 1) from tm0; +if $rows != 3 then + return -1 +endi + +sql_error select derivative(k, 6m, 1) from tm0 interval(1s); +sql_error select derivative(k, 6m, 1) from tm0 session(ts, 1s); +sql_error select derivative(k, 6m, 1) from tm0 group by k; + +sql drop table if exists tm0 +sql drop table if exists m1 + +sql create table m1 (ts timestamp, k double ) tags(a int); +sql create table if not exists t0 using m1 tags(1); +sql create table if not exists t1 using m1 tags(2); + +sql insert into t0 values('2020-1-1 1:1:1', 1); +sql insert into t0 values('2020-1-1 1:1:3', 3); +sql insert into t0 values('2020-1-1 1:2:4', 4); +sql insert into t0 values('2020-1-1 1:2:5', 5); +sql insert into t0 values('2020-1-1 1:2:6', 6); +sql insert into t0 values('2020-1-1 1:3:7', 7); +sql insert into t0 values('2020-1-1 1:3:8', 8); +sql insert into t0 values('2020-1-1 1:3:9', 9); +sql insert into t0 values('2020-1-1 1:4:10', 10); + +sql insert into t1 values('2020-1-1 1:1:2', 2); +sql insert into t1 values('2020-1-1 1:1:4', 20); +sql insert into t1 values('2020-1-1 1:1:6', 200); +sql insert into t1 values('2020-1-1 1:1:8', 2000); +sql insert into t1 values('2020-1-1 1:1:10', 20000); + +sql_error select derivative(k, 1s, 0) from m1; +sql_error select derivative(k, 1s, 0) from m1 group by a; +sql select derivative(k, 1s, 0) from m1 group by tbname +if $rows != 12 then + return -1 +endi + +if $data00 != @20-01-01 01:01:03.000@ then + return -1 +endi + +if $data01 != 1.000000000 then + return -1 +endi + +if $data02 != @t0@ then + return -1 +endi + +if $data10 != @20-01-01 01:02:04.000@ then + return -1 +endi + +if $data11 != 0.016393443 then + return -1 +endi + +if $data12 != t0 then + return -1 +endi + +if $data90 != @20-01-01 01:01:06.000@ then + return -1 +endi + +if $data91 != 90.000000000 then + return -1 +endi + +if $data92 != t1 then + return -1 +endi \ No newline at end of file diff --git a/tests/script/general/parser/join_multitables.sim b/tests/script/general/parser/join_multitables.sim index acb8be10e7cf0f4a3f70828b1054d9552ca864c4..d675499640b890398859243d49cfb04d9e1e7579 100644 --- a/tests/script/general/parser/join_multitables.sim +++ b/tests/script/general/parser/join_multitables.sim @@ -1811,10 +1811,6 @@ if $data09 != 3 then return -1 endi - - - - sql select st0.*,st1.* from st0, st1 where st1.id1=st0.id1 and st0.ts=st1.ts and st1.ts=st0.ts and st0.id1=st1.id1 order by st0.ts limit 5 offset 5 if $rows != 5 then return -1 @@ -2294,7 +2290,6 @@ if $data19 != 9925 then return -1 endi - sql_error select tb0_1.*, tb1_1.* from tb0_1, tb1_1 where tb0_1.f1=tb1_1.f1; sql_error select tb0_1.*, tb1_1.* from tb0_1, tb1_1 where tb0_1.ts=tb1_1.ts and tb0_1.id1=tb1_1.id2; sql_error select tb0_5.*, tb1_5.*,tb2_5.*,tb3_5.*,tb4_5.*,tb5_5.*, tb6_5.*,tb7_5.*,tb8_5.*,tb9_5.*,tba_5.* from tb0_5, tb1_5, tb2_5, tb3_5, tb4_5,tb5_5, tb6_5, tb7_5, tb8_5, tb9_5, tba_5 where tb9_5.ts=tb8_5.ts and tb8_5.ts=tb7_5.ts and tb7_5.ts=tb6_5.ts and tb6_5.ts=tb5_5.ts and tb5_5.ts=tb4_5.ts and tb4_5.ts=tb3_5.ts and tb3_5.ts=tb2_5.ts and tb2_5.ts=tb1_5.ts and tb1_5.ts=tb0_5.ts and tb0_5.ts=tba_5.ts; @@ -2317,10 +2312,4 @@ sql_error select last(*) from st0, st1 where st0.ts=st1.ts and st0.id1=st1.id1 g sql_error select st0.*,st1.*,st2.*,st3.*,st4.*,st5.*,st6.*,st7.*,st8.*,st9.* from st0,st1,st2,st3,st4,st5,st6,st7,st8,st9 where st0.ts=st2.ts and st0.ts=st4.ts and st0.ts=st6.ts and st0.ts=st8.ts and st1.ts=st3.ts and st3.ts=st5.ts and st5.ts=st7.ts and st7.ts=st9.ts and st0.id1=st2.id1 and st0.id1=st4.id1 and st0.id1=st6.id1 and st0.id1=st8.id1 and st1.id1=st3.id1 and st3.id1=st5.id1 and st5.id1=st7.id1 and st7.id1=st9.id1; sql_error select st0.*,st1.*,st2.*,st3.*,st4.*,st5.*,st6.*,st7.*,st8.*,st9.* from st0,st1,st2,st3,st4,st5,st6,st7,st8,st9,sta where st0.ts=st2.ts and st0.ts=st4.ts and st0.ts=st6.ts and st0.ts=st8.ts and st1.ts=st3.ts and st3.ts=st5.ts and st5.ts=st7.ts and st7.ts=st9.ts and st0.ts=st1.ts and st0.id1=st2.id1 and st0.id1=st4.id1 and st0.id1=st6.id1 and st0.id1=st8.id1 and st1.id1=st3.id1 and st3.id1=st5.id1 and st5.id1=st7.id1 and st7.id1=st9.id1 and st0.id1=st1.id1 and st0.id1=sta.id1 and st0.ts=sta.ts; - - - - - - system sh/exec.sh -n dnode1 -s stop -x SIGINT diff --git a/tests/script/general/parser/join_multivnode.sim b/tests/script/general/parser/join_multivnode.sim index c72b2c5b3e4018c892f1194671b0d577c053c7f5..61438241b0cb943cf9d1df09799076cf7dbadeab 100644 --- a/tests/script/general/parser/join_multivnode.sim +++ b/tests/script/general/parser/join_multivnode.sim @@ -367,4 +367,4 @@ if $data35 != 5 then return -1 endi -system sh/exec.sh -n dnode1 -s stop -x SIGINT \ No newline at end of file +system sh/exec.sh -n dnode1 -s stop -x SIGINT diff --git a/tests/script/general/parser/last_cache.sim b/tests/script/general/parser/last_cache.sim index 9d7da9ddbabbd668382740a230ecc9582c27fe84..4b3285871b8e9414877a53aa205ba2e747e9d8e1 100644 --- a/tests/script/general/parser/last_cache.sim +++ b/tests/script/general/parser/last_cache.sim @@ -9,7 +9,7 @@ sql connect print ======================== dnode1 start $db = testdb - +sql drop database if exists $db sql create database $db cachelast 2 sql use $db diff --git a/tests/script/general/parser/nestquery.sim b/tests/script/general/parser/nestquery.sim index 16d190d3fe174e2c19960999584baa7352f555aa..98c0918c0f51683d69f00546b76a2e553b548fdc 100644 --- a/tests/script/general/parser/nestquery.sim +++ b/tests/script/general/parser/nestquery.sim @@ -147,8 +147,57 @@ if $data02 != @nest_tb0@ then endi print ===================> nest query interval +sql_error select ts, avg(c1) from (select ts, c1 from nest_tb0); +sql select avg(c1) from (select * from nest_tb0) interval(3d) +if $rows != 3 then + return -1 +endi + +if $data00 != @20-09-14 00:00:00.000@ then + return -1 +endi + +if $data01 != 49.222222222 then + return -1 +endi + +if $data10 != @20-09-17 00:00:00.000@ then + print expect 20-09-17 00:00:00.000, actual: $data10 + return -1 +endi + +if $data11 != 49.685185185 then + return -1 +endi + +if $data20 != @20-09-20 00:00:00.000@ then + return -1 +endi + +if $data21 != 49.500000000 then + return -1 +endi + +#define TSDB_FUNC_APERCT 7 +#define TSDB_FUNC_LAST_ROW 10 +#define TSDB_FUNC_TWA 14 +#define TSDB_FUNC_LEASTSQR 15 +#define TSDB_FUNC_ARITHM 23 +#define TSDB_FUNC_DIFF 24 +#define TSDB_FUNC_INTERP 28 +#define TSDB_FUNC_RATE 29 +#define TSDB_FUNC_IRATE 30 +#define TSDB_FUNC_DERIVATIVE 32 + +sql_error select stddev(c1) from (select c1 from nest_tb0); +sql_error select percentile(c1, 20) from (select * from nest_tb0); + +sql select avg(c1),sum(c2), max(c3), min(c4), count(*), first(c7), last(c7),spread(c6) from (select * from nest_tb0) interval(1d); + +sql select top(x, 20) from (select c1 x from nest_tb0); +sql select bottom(x, 20) from (select c1 x from nest_tb0) print ===================> complex query diff --git a/tests/script/general/parser/precision_ns.sim b/tests/script/general/parser/precision_ns.sim new file mode 100644 index 0000000000000000000000000000000000000000..3e9a2dd3ffdcd1f15e05c28273af9484e33840d4 --- /dev/null +++ b/tests/script/general/parser/precision_ns.sim @@ -0,0 +1,113 @@ +system sh/stop_dnodes.sh + +system sh/deploy.sh -n dnode1 -i 1 +system sh/cfg.sh -n dnode1 -c walLevel -v 1 +system sh/exec.sh -n dnode1 -s start +sleep 1000 +sql connect + +$dbPrefix = m_di_db_ns +$tbPrefix = m_di_tb +$mtPrefix = m_di_mt +$ntPrefix = m_di_nt +$tbNum = 2 +$rowNum = 200 +$futureTs = 300000000000 + +print =============== step1: create database and tables and insert data +$i = 0 +$db = $dbPrefix . $i +$mt = $mtPrefix . $i +$nt = $ntPrefix . $i + +sql drop database $db -x step1 +step1: +sql create database $db precision 'ns' +sql use $db +sql create table $mt (ts timestamp, tbcol int) TAGS(tgcol int) + +$i = 0 +while $i < $tbNum + $tb = $tbPrefix . $i + sql create table $tb using $mt tags( $i ) + + $x = 0 + while $x < $rowNum + $cc = $futureTs + $x * 100 + 43 + $ns = $cc . b + sql insert into $tb values (now + $ns , $x ) + $x = $x + 1 + endw + + $i = $i + 1 +endw + +sql create table $nt (ts timestamp, tbcol int) +$x = 0 +while $x < $rowNum + $cc = $futureTs + $x * 100 + 43 + $ns = $cc . b + sql insert into $nt values (now + $ns , $x ) + $x = $x + 1 +endw + +sleep 100 + +print =============== step2: select count(*) from tables +$i = 0 +$tb = $tbPrefix . $i + +sql select count(*) from $tb + +if $data00 != $rowNum then + print expect $rowNum, actual:$data00 + return -1 +endi + +$i = 0 +$mt = $mtPrefix . $i +sql select count(*) from $mt + +$mtRowNum = $tbNum * $rowNum +if $data00 != $mtRowNum then + print expect $mtRowNum, actual:$data00 + return -1 +endi + +$i = 0 +$nt = $ntPrefix . $i + +sql select count(*) from $nt + +if $data00 != $rowNum then + print expect $rowNum, actual:$data00 + return -1 +endi + +print =============== step3: check nano second timestamp +$i = 0 +$mt = $mtPrefix . $i +$tb = $tbPrefix . $i +sql insert into $tb values (now-43b , $x ) +sql select count(*) from $tb where tstd-1308 -sql create database db keep 36500; +sql create database db keep 36500 sql use db; sql create table stb (ts timestamp, c1 int, c2 binary(10)) tags(t1 binary(10)); @@ -377,4 +377,4 @@ sql_error select * from ttm2 where k<>null sql_error select * from ttm2 where k like null sql_error select * from ttm2 where k