diff --git a/.gitignore b/.gitignore index 2c37aa92f77dd14bd274be94568dfe904f48c5f4..0458aa3415dc61005fe77b38c7c3366b1fcf461c 100644 --- a/.gitignore +++ b/.gitignore @@ -82,6 +82,10 @@ tests/comparisonTest/opentsdb/opentsdbtest/.settings/ tests/examples/JDBC/JDBCDemo/.classpath tests/examples/JDBC/JDBCDemo/.project tests/examples/JDBC/JDBCDemo/.settings/ +tests/script/api/batchprepare +tests/script/api/stmt +tests/script/api/stmtBatchTest +tests/script/api/stmtTest # Emacs # -*- mode: gitignore; -*- diff --git a/Jenkinsfile b/Jenkinsfile index 9cc65d24f8aae3a97890e6676ff1091d32f7dc59..297dde63e196ff3ae4083926f51bd6a88c1c9f3a 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -455,17 +455,18 @@ pipeline { npm install td2.0-connector > /dev/null 2>&1 node nodejsChecker.js host=localhost node test1970.js - cd ${WKC}/tests/connectorTest/nodejsTest/nanosupport - npm install td2.0-connector > /dev/null 2>&1 + cd ${WKC}/tests/connectorTest/nodejsTest/nanosupport + npm install td2.0-connector > /dev/null 2>&1 node nanosecondTest.js ''' - - sh ''' - cd ${WKC}/tests/examples/C#/taosdemo - mcs -out:taosdemo *.cs > /dev/null 2>&1 - echo '' |./taosdemo -c /etc/taos - ''' + catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE') { + sh ''' + cd ${WKC}/tests/examples/C#/taosdemo + mcs -out:taosdemo *.cs > /dev/null 2>&1 + echo '' |./taosdemo -c /etc/taos + ''' + } sh ''' cd ${WKC}/tests/gotest bash batchtest.sh diff --git a/cmake/define.inc b/cmake/define.inc index b381853eba57aa7b9efb905790e77b1d1fdcf900..92044b8c2dd3710c5a1808abcecd7d2358230e7a 100755 --- a/cmake/define.inc +++ b/cmake/define.inc @@ -135,6 +135,8 @@ IF ("${BUILD_HTTP}" STREQUAL "") ELSE () SET(BUILD_HTTP "false") ENDIF () + ELSEIF (TD_DARWIN) + SET(BUILD_HTTP "false") ELSE () SET(BUILD_HTTP "true") ENDIF () diff --git a/cmake/platform.inc b/cmake/platform.inc index 328c5f23ee95af54daa7e4a925c33ce09acd3cfb..2a0aace8d08e9dba1451daa051df4b614a21d398 100755 --- a/cmake/platform.inc +++ b/cmake/platform.inc @@ -36,7 +36,13 @@ IF (${CMAKE_SYSTEM_NAME} MATCHES "Linux") # Get OS information and store in variable TD_OS_INFO. # execute_process(COMMAND chmod 777 ${TD_COMMUNITY_DIR}/packaging/tools/get_os.sh) - execute_process(COMMAND sh ${TD_COMMUNITY_DIR}/packaging/tools/get_os.sh "" OUTPUT_VARIABLE TD_OS_INFO) + execute_process(COMMAND readlink /bin/sh OUTPUT_VARIABLE SHELL_LINK) + MESSAGE(STATUS "The shell is: " ${SHELL_LINK}) + IF (${SHELL_LINK} MATCHES "dash") + execute_process(COMMAND ${TD_COMMUNITY_DIR}/packaging/tools/get_os.sh "" OUTPUT_VARIABLE TD_OS_INFO) + ELSE () + execute_process(COMMAND sh ${TD_COMMUNITY_DIR}/packaging/tools/get_os.sh "" OUTPUT_VARIABLE TD_OS_INFO) + ENDIF() MESSAGE(STATUS "The current os is " ${TD_OS_INFO}) SET(TD_LINUX TRUE) diff --git a/cmake/version.inc b/cmake/version.inc index 94ff39f5e655d89b16b57a4b8c8fbe275c82a49a..ee3d1e356d15ba6484aa67df9d8dc09625b777d7 100755 --- a/cmake/version.inc +++ b/cmake/version.inc @@ -4,7 +4,7 @@ PROJECT(TDengine) IF (DEFINED VERNUMBER) SET(TD_VER_NUMBER ${VERNUMBER}) ELSE () - SET(TD_VER_NUMBER "2.3.1.0") + SET(TD_VER_NUMBER "2.3.2.0") ENDIF () IF (DEFINED VERCOMPATIBLE) diff --git a/deps/CMakeLists.txt b/deps/CMakeLists.txt index 773a791a2527712270f569d5c04aa7f8ef066e40..38f36c4ed6678675cecfa9c0da1a3d065b58da86 100644 --- a/deps/CMakeLists.txt +++ b/deps/CMakeLists.txt @@ -55,6 +55,7 @@ IF (TD_LINUX_64 AND JEMALLOC_ENABLED) MESSAGE("") MESSAGE("setup deps/jemalloc, current source dir:" ${CMAKE_CURRENT_SOURCE_DIR}) MESSAGE("binary dir:" ${CMAKE_BINARY_DIR}) + include(ExternalProject) ExternalProject_Add(jemalloc PREFIX "jemalloc" SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/jemalloc @@ -62,6 +63,7 @@ IF (TD_LINUX_64 AND JEMALLOC_ENABLED) CONFIGURE_COMMAND ./autogen.sh COMMAND ./configure --prefix=${CMAKE_BINARY_DIR}/build/ BUILD_COMMAND ${MAKE} ) + INCLUDE_DIRECTORIES(${CMAKE_BINARY_DIR}/build/include) ENDIF () IF (${TSZ_ENABLED} MATCHES "true") diff --git a/documentation20/cn/00.index/docs.md b/documentation20/cn/00.index/docs.md index 70a6b7c5281e1a96f8348ff3a3bb81892b80c93c..a4fba357bbc47bd84ea7c2a6931a64bf274e5d9b 100644 --- a/documentation20/cn/00.index/docs.md +++ b/documentation20/cn/00.index/docs.md @@ -121,10 +121,11 @@ TDengine是一个高效的存储、查询、分析时序大数据的平台,专 * [数据复制](/architecture/replica):支持实时同步、异步复制,保证系统的High Availibility * [技术博客](https://www.taosdata.com/cn/blog/?categories=3):更多的技术分析和架构设计文章 -## [应用 TDengine 快速搭建 IT 运维系统](/devops) +## 应用 TDengine 快速搭建 IT 运维系统 * [devops](/devops/telegraf):使用 TDengine + Telegraf + Grafana 快速搭建 IT 运维系统 * [devops](/devops/collectd):使用 TDengine + collectd_statsd + Grafana 快速搭建 IT 运维系统 +* [最佳实践](/devops/immigrate):OpenTSDB 应用迁移到 TDengine 的最佳实践 ## 常用工具 diff --git a/documentation20/cn/05.insert/docs.md b/documentation20/cn/05.insert/docs.md index 24ac6c52e19e24697c8ad35fdaf822adbd614a0a..a82aecd97c832f9b7f276ec27832097e46845dfc 100644 --- a/documentation20/cn/05.insert/docs.md +++ b/documentation20/cn/05.insert/docs.md @@ -145,27 +145,27 @@ st,t1=3,t2=4,t3=t3 c1=3i64,c6="passit" 1626006833640000000
如果是无模式写入过程中的数据本身错误,应用会得到 TSDB_CODE_TSC_LINE_SYNTAX_ERROR 错误信息,该错误信息表明错误发生在写入文本中。其他的错误码与原系统一致,可以通过 taos_errstr 获取具体的错误原因。 **后续升级计划** -
当前版本只提供了 C 版本的 API,后续将提供 其他高级语言的 API,例如 Java/Go/Python/C# 等。此外,在TDengine v2.3及后续版本中,您还可以通过 BLM v3 采用 REST 的方式直接写入无模式数据。 +
当前版本只提供了 C 版本的 API,后续将提供 其他高级语言的 API,例如 Java/Go/Python/C# 等。此外,在TDengine v2.3及后续版本中,您还可以通过 Taos Adapter 采用 REST 的方式直接写入无模式数据。 ## Prometheus 直接写入 [Prometheus](https://www.prometheus.io/)作为Cloud Native Computing Fundation毕业的项目,在性能监控以及K8S性能监控领域有着非常广泛的应用。TDengine提供一个小工具[Bailongma](https://github.com/taosdata/Bailongma),只需对Prometheus做简单配置,无需任何代码,就可将Prometheus采集的数据直接写入TDengine,并按规则在TDengine自动创建库和相关表项。博文[用Docker容器快速搭建一个Devops监控Demo](https://www.taosdata.com/blog/2020/02/03/1189.html)即是采用Bailongma将Prometheus和Telegraf的数据写入TDengine中的示例,可以参考。 -### 从源代码编译 taosadapter_prometheus +### 从源代码编译 blm_prometheus 用户需要从github下载[Bailongma](https://github.com/taosdata/Bailongma)的源码,使用Golang语言编译器编译生成可执行文件。在开始编译前,需要准备好以下条件: - Linux操作系统的服务器 - 安装好Golang,1.14版本以上 - 对应的TDengine版本。因为用到了TDengine的客户端动态链接库,因此需要安装好和服务端相同版本的TDengine程序;比如服务端版本是TDengine 2.0.0, 则在Bailongma所在的Linux服务器(可以与TDengine在同一台服务器,或者不同服务器) -Bailongma项目中有一个文件夹taosadapter_prometheus,存放了prometheus的写入API程序。编译过程如下: +Bailongma项目中有一个文件夹blm_prometheus,存放了prometheus的写入API程序。编译过程如下: ```bash -cd taosadapter_prometheus +cd blm_prometheus go build ``` -一切正常的情况下,就会在对应的目录下生成一个taosadapter_prometheus的可执行程序。 +一切正常的情况下,就会在对应的目录下生成一个blm_prometheus的可执行程序。 ### 安装 Prometheus @@ -176,23 +176,23 @@ go build 参考Prometheus的[配置文档](https://prometheus.io/docs/prometheus/latest/configuration/configuration/),在Prometheus的配置文件中的部分,增加以下配置: ``` - - url: "bailongma API服务提供的URL"(参考下面的taosadapter_prometheus启动示例章节) + - url: "bailongma API服务提供的URL"(参考下面的blm_prometheus启动示例章节) ``` 启动Prometheus后,可以通过taos客户端查询确认数据是否成功写入。 -### 启动 taosadapter_prometheus 程序 +### 启动 blm_prometheus 程序 -taosadapter_prometheus程序有以下选项,在启动taosadapter_prometheus程序时可以通过设定这些选项来设定taosadapter_prometheus的配置。 +blm_prometheus程序有以下选项,在启动blm_prometheus程序时可以通过设定这些选项来设定blm_prometheus的配置。 ```bash --tdengine-name 如果TDengine安装在一台具备域名的服务器上,也可以通过配置TDengine的域名来访问TDengine。在K8S环境下,可以配置成TDengine所运行的service name。 --batch-size -taosadapter_prometheus会将收到的prometheus的数据拼装成TDengine的写入请求,这个参数控制一次发给TDengine的写入请求中携带的数据条数。 +blm_prometheus会将收到的prometheus的数据拼装成TDengine的写入请求,这个参数控制一次发给TDengine的写入请求中携带的数据条数。 --dbname -设置在TDengine中创建的数据库名称,taosadapter_prometheus会自动在TDengine中创建一个以dbname为名称的数据库,缺省值是prometheus。 +设置在TDengine中创建的数据库名称,blm_prometheus会自动在TDengine中创建一个以dbname为名称的数据库,缺省值是prometheus。 --dbuser 设置访问TDengine的用户名,缺省值是'root'。 @@ -201,16 +201,16 @@ taosadapter_prometheus会将收到的prometheus的数据拼装成TDengine的写 设置访问TDengine的密码,缺省值是'taosdata'。 --port -taosadapter_prometheus对prometheus提供服务的端口号。 +blm_prometheus对prometheus提供服务的端口号。 ``` ### 启动示例 -通过以下命令启动一个taosadapter_prometheus的API服务 +通过以下命令启动一个blm_prometheus的API服务 ```bash -./taosadapter_prometheus -port 8088 +./blm_prometheus -port 8088 ``` -假设taosadapter_prometheus所在服务器的IP地址为"10.1.2.3",则在prometheus的配置文件中部分增加url为 +假设blm_prometheus所在服务器的IP地址为"10.1.2.3",则在prometheus的配置文件中部分增加url为 ```yaml remote_write: - url: "http://10.1.2.3:8088/receive" @@ -235,7 +235,7 @@ prometheus产生的数据格式如下: } } ``` -其中,apiserver_request_latencies_bucket为prometheus采集的时序数据的名称,后面{}中的为该时序数据的标签。taosadapter_prometheus会以时序数据的名称在TDengine中自动创建一个超级表,并将{}中的标签转换成TDengine的tag值,Timestamp作为时间戳,value作为该时序数据的值。因此在TDengine的客户端中,可以通过以下指令查到这个数据是否成功写入。 +其中,apiserver_request_latencies_bucket为prometheus采集的时序数据的名称,后面{}中的为该时序数据的标签。blm_prometheus会以时序数据的名称在TDengine中自动创建一个超级表,并将{}中的标签转换成TDengine的tag值,Timestamp作为时间戳,value作为该时序数据的值。因此在TDengine的客户端中,可以通过以下指令查到这个数据是否成功写入。 ```mysql use prometheus; select * from apiserver_request_latencies_bucket; @@ -314,7 +314,7 @@ taosadapter 相关配置参数请参考 taosadapter --help 命令输出以及相 [Telegraf](https://www.influxdata.com/time-series-platform/telegraf/)是一流行的IT运维数据采集开源工具,TDengine提供一个小工具[Bailongma](https://github.com/taosdata/Bailongma),只需在Telegraf做简单配置,无需任何代码,就可将Telegraf采集的数据直接写入TDengine,并按规则在TDengine自动创建库和相关表项。博文[用Docker容器快速搭建一个Devops监控Demo](https://www.taosdata.com/blog/2020/02/03/1189.html)即是采用bailongma将Prometheus和Telegraf的数据写入TDengine中的示例,可以参考。 -### 从源代码编译 taosadapter_telegraf +### 从源代码编译 blm_telegraf 用户需要从github下载[Bailongma](https://github.com/taosdata/Bailongma)的源码,使用Golang语言编译器编译生成可执行文件。在开始编译前,需要准备好以下条件: @@ -322,14 +322,14 @@ taosadapter 相关配置参数请参考 taosadapter --help 命令输出以及相 - 安装好Golang,1.10版本以上 - 对应的TDengine版本。因为用到了TDengine的客户端动态链接库,因此需要安装好和服务端相同版本的TDengine程序;比如服务端版本是TDengine 2.0.0, 则在Bailongma所在的Linux服务器(可以与TDengine在同一台服务器,或者不同服务器) -Bailongma项目中有一个文件夹taosadapter_telegraf,存放了Telegraf的写入API程序。编译过程如下: +Bailongma项目中有一个文件夹blm_telegraf,存放了Telegraf的写入API程序。编译过程如下: ```bash -cd taosadapter_telegraf +cd blm_telegraf go build ``` -一切正常的情况下,就会在对应的目录下生成一个taosadapter_telegraf的可执行程序。 +一切正常的情况下,就会在对应的目录下生成一个blm_telegraf的可执行程序。 ### 安装 Telegraf @@ -352,19 +352,19 @@ go build 关于如何使用Telegraf采集数据以及更多有关使用Telegraf的信息,请参考Telegraf官方的[文档](https://docs.influxdata.com/telegraf/v1.11/)。 -### 启动 taosadapter_telegraf 程序 +### 启动 blm_telegraf 程序 -taosadapter_telegraf程序有以下选项,在启动taosadapter_telegraf程序时可以通过设定这些选项来设定taosadapter_telegraf的配置。 +blm_telegraf程序有以下选项,在启动blm_telegraf程序时可以通过设定这些选项来设定blm_telegraf的配置。 ```bash --host TDengine服务端的IP地址,缺省值为空。 --batch-size -taosadapter_telegraf会将收到的telegraf的数据拼装成TDengine的写入请求,这个参数控制一次发给TDengine的写入请求中携带的数据条数。 +blm_telegraf会将收到的telegraf的数据拼装成TDengine的写入请求,这个参数控制一次发给TDengine的写入请求中携带的数据条数。 --dbname -设置在TDengine中创建的数据库名称,taosadapter_telegraf会自动在TDengine中创建一个以dbname为名称的数据库,缺省值是prometheus。 +设置在TDengine中创建的数据库名称,blm_telegraf会自动在TDengine中创建一个以dbname为名称的数据库,缺省值是prometheus。 --dbuser 设置访问TDengine的用户名,缺省值是'root'。 @@ -373,17 +373,17 @@ taosadapter_telegraf会将收到的telegraf的数据拼装成TDengine的写入 设置访问TDengine的密码,缺省值是'taosdata'。 --port -taosadapter_telegraf对telegraf提供服务的端口号。 +blm_telegraf对telegraf提供服务的端口号。 ``` ### 启动示例 -通过以下命令启动一个taosadapter_telegraf的API服务: +通过以下命令启动一个blm_telegraf的API服务: ```bash -./taosadapter_telegraf -host 127.0.0.1 -port 8089 +./blm_telegraf -host 127.0.0.1 -port 8089 ``` -假设taosadapter_telegraf所在服务器的IP地址为"10.1.2.3",则在telegraf的配置文件中, 在output plugins部分,增加[[outputs.http]]配置项: +假设blm_telegraf所在服务器的IP地址为"10.1.2.3",则在telegraf的配置文件中, 在output plugins部分,增加[[outputs.http]]配置项: ```yaml url = "http://10.1.2.3:8089/telegraf" @@ -416,7 +416,7 @@ telegraf产生的数据格式如下: } ``` -其中,name字段为telegraf采集的时序数据的名称,tags字段为该时序数据的标签。taosadapter_telegraf会以时序数据的名称在TDengine中自动创建一个超级表,并将tags字段中的标签转换成TDengine的tag值,timestamp作为时间戳,fields字段中的值作为该时序数据的值。因此在TDengine的客户端中,可以通过以下指令查到这个数据是否成功写入。 +其中,name字段为telegraf采集的时序数据的名称,tags字段为该时序数据的标签。blm_telegraf会以时序数据的名称在TDengine中自动创建一个超级表,并将tags字段中的标签转换成TDengine的tag值,timestamp作为时间戳,fields字段中的值作为该时序数据的值。因此在TDengine的客户端中,可以通过以下指令查到这个数据是否成功写入。 ```mysql use telegraf; diff --git a/documentation20/cn/08.connector/docs.md b/documentation20/cn/08.connector/docs.md index b4543111b22008467ba749018fa2c19321f4f18e..a1689151aabd82b93821a11cb6de107090db0fae 100644 --- a/documentation20/cn/08.connector/docs.md +++ b/documentation20/cn/08.connector/docs.md @@ -328,7 +328,7 @@ TDengine的异步API均采用非阻塞调用模式。应用程序可以用多线 除 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) 文件中使用对应函数的方式): +接口相关的具体函数如下(也可以参考 [prepare.c](https://github.com/taosdata/TDengine/blob/develop/tests/examples/c/prepare.c) 文件中使用对应函数的方式): - `TAOS_STMT* taos_stmt_init(TAOS *taos)` diff --git a/documentation20/cn/11.administrator/docs.md b/documentation20/cn/11.administrator/docs.md index 448df75d808e06996ef61814692c7948adb11e32..4ef1c60112018cb29289314e199feda75ca7c2ba 100644 --- a/documentation20/cn/11.administrator/docs.md +++ b/documentation20/cn/11.administrator/docs.md @@ -1,4 +1,4 @@ -# TDengine的运营与运维 +# TDengine的运营与维护 ## 容量规划 @@ -157,7 +157,7 @@ taosd -C | 39 | keep | | **S** | 天 | 数据保留的天数 | | 3650 | | | 40 | minRows | | **S** | | 文件块中记录的最小条数 | | 100 | | | 41 | maxRows | | **S** | | 文件块中记录的最大条数 | | 4096 | | -| 42 | quorum | | **S** | | 异步写入成功所需应答之法定数 | 1-3 | 1 | | +| 42 | quorum | | **S** | | 多副本环境下指令执行的确认数要求 | 1,2 | 1 | | | 43 | comp | | **S** | | 文件压缩标志位 | 0:关闭,1:一阶段压缩,2:两阶段压缩 | 2 | | | 44 | walLevel | | **S** | | WAL级别 | 1:写wal, 但不执行fsync; 2:写wal, 而且执行fsync | 1 | | | 45 | fsync | | **S** | 毫秒 | 当wal设置为2时,执行fsync的周期 | 最小为0,表示每次写入,立即执行fsync;最大为180000(三分钟) | 3000 | | diff --git a/documentation20/cn/12.taos-sql/docs.md b/documentation20/cn/12.taos-sql/docs.md index 4ba496d575e0f680c2dbd2820d3dfc062c56cb1c..18c39d665483997f1680f0253baddd8ceabcf1d9 100644 --- a/documentation20/cn/12.taos-sql/docs.md +++ b/documentation20/cn/12.taos-sql/docs.md @@ -124,7 +124,7 @@ TDengine 缺省的时间戳是毫秒精度,但通过在 CREATE DATABASE 时传 ```mysql ALTER DATABASE db_name QUORUM 2; ``` - QUORUM 参数是指数据写入成功所需要的确认数,取值范围 [1, 2]。对于异步复制,quorum 设为 1,具有 master 角色的虚拟节点自己确认即可。对于同步复制,需要至少大于等于 2。原则上,Quorum >= 1 并且 Quorum <= replica(副本数),这个参数在启动一个同步模块实例时需要提供。 + QUORUM 参数是指数据写入成功所需要的确认数,取值范围 [1, 2]。对于异步复制,quorum 设为 1,具有 master 角色的虚拟节点自己确认即可。对于同步复制,quorum 设为 2。原则上,Quorum >= 1 并且 Quorum <= replica(副本数),这个参数在启动一个同步模块实例时需要提供。 ```mysql ALTER DATABASE db_name BLOCKS 100; @@ -719,7 +719,7 @@ Query OK, 1 row(s) in set (0.001091s) * 暂不支持含列名的四则运算表达式用于条件过滤算子(例如,不支持 `where a*2>6;`,但可以写 `where a>6/2;`)。 * 暂不支持含列名的四则运算表达式作为 SQL 函数的应用对象(例如,不支持 `select min(2*a) from t;`,但可以写 `select 2*min(a) from t;`)。 - WHERE 语句可以使用各种逻辑判断来过滤数字值,或使用通配符来过滤字符串。 -- 输出结果缺省按首列时间戳升序排序,但可以指定按降序排序( _c0 指首列时间戳)。使用 ORDER BY 对其他字段进行排序为非法操作。 +- 输出结果缺省按首列时间戳升序排序,但可以指定按降序排序( _c0 指首列时间戳)。使用 ORDER BY 对其他字段进行排序,排序结果顺序不确定。 - 参数 LIMIT 控制输出条数,OFFSET 指定从第几条开始输出。LIMIT/OFFSET 对结果集的执行顺序在 ORDER BY 之后。且 `LIMIT 5 OFFSET 2` 可以简写为 `LIMIT 2, 5`。 * 在有 GROUP BY 子句的情况下,LIMIT 参数控制的是每个分组中至多允许输出的条数。 - 参数 SLIMIT 控制由 GROUP BY 指令划分的分组中,至多允许输出几个分组的数据。且 `SLIMIT 5 SOFFSET 2` 可以简写为 `SLIMIT 2, 5`。 @@ -743,7 +743,7 @@ Query OK, 1 row(s) in set (0.001091s) 1. <> 算子也可以写为 != ,请注意,这个算子不能用于数据表第一列的 timestamp 字段。 2. like 算子使用通配符字符串进行匹配检查。 - * 在通配符字符串中:'%'(百分号)匹配 0 到任意个字符;'\_'(下划线)匹配单个任意字符。 + * 在通配符字符串中:'%'(百分号)匹配 0 到任意个字符;'\_'(下划线)匹配单个任意ASCII字符。 * 如果希望匹配字符串中原本就带有的 \_(下划线)字符,那么可以在通配符字符串中写作 `\_`,也即加一个反斜线来进行转义。(从 2.2.0.0 版本开始支持) * 通配符字符串最长不能超过 20 字节。(从 2.1.6.1 版本开始,通配符字符串的长度放宽到了 100 字节,并可以通过 taos.cfg 中的 maxWildCardsLength 参数来配置这一长度限制。但不建议使用太长的通配符字符串,将有可能严重影响 LIKE 操作的执行性能。) 3. 同时进行多个字段的范围过滤,需要使用关键词 AND 来连接不同的查询条件,暂不支持 OR 连接的不同列之间的查询过滤条件。 diff --git a/documentation20/cn/14.devops/02.collectd/docs.md b/documentation20/cn/14.devops/02.collectd/docs.md index a35772bb498d426a1f44a9e7eb0bea61b51f92a5..5860e70ceafafadc21c5772c96515e0925897e3a 100644 --- a/documentation20/cn/14.devops/02.collectd/docs.md +++ b/documentation20/cn/14.devops/02.collectd/docs.md @@ -40,7 +40,7 @@ IT 运维监测数据通常都是对时间特性比较敏感的数据,例如 ``` ### 配置 collectd -在 /etc/collectd/collectd.conf 文件中增加如下内容,其中 host 和 port 请填写 TDengine 和 BLM3 配置的实际值: +在 /etc/collectd/collectd.conf 文件中增加如下内容,其中 host 和 port 请填写 TDengine 和 Taos Adapter 配置的实际值: ``` LoadPlugin network @@ -51,7 +51,7 @@ sudo systemctl start collectd ``` ### 配置 StatsD -在 config.js 文件中增加如下内容后启动 StatsD,其中 host 和 port 请填写 TDengine 和 BLM3 配置的实际值: +在 config.js 文件中增加如下内容后启动 StatsD,其中 host 和 port 请填写 TDengine 和 Taos Adapter 配置的实际值: ``` backends 部分添加 "./backends/repeater" repeater 部分添加 { host:'', port: } diff --git a/documentation20/cn/14.devops/03.immigrate/docs.md b/documentation20/cn/14.devops/03.immigrate/docs.md new file mode 100644 index 0000000000000000000000000000000000000000..b2a68e1b15acef2d574600e59d1b18d890938ac6 --- /dev/null +++ b/documentation20/cn/14.devops/03.immigrate/docs.md @@ -0,0 +1,435 @@ +# OpenTSDB 应用迁移到 TDengine 的最佳实践 + +作为一个分布式、可伸缩、基于HBase 的分布式时序数据库系统,得益于其先发优势,OpenTSDB被 DevOps 领域的人员引入并广泛地应用在了运维监控领域。但最近几年,随着云计算、微服务、容器化等新技术快速落地发展,企业级服务种类变得越来越多,架构也越来越复杂,应用运行基础环境日益多样化,给系统和运行监控带来的压力也越来越大。从这一现状出发,使用 OpenTSDB 作为DevOps的监控后端存储,越来越受困于其性能问题以及迟缓的功能升级,以及由此而衍生出来的应用部署成本上升和运行效率降低等问题,这些问题随着系统规模的扩大日益严重。 + +在这一背景下,为满足高速增长的物联网大数据市场和技术需求,在吸取众多传统关系型数据库、NoSQL 数据库、流计算引擎、消息队列等软件的优点之后,涛思数据自主开发出创新型大数据处理产品TDengine。在时序大数据处理上,TDengine 有着自己独特的优势。就 OpenTSDB 当前遇到的问题来说,TDengine 能够有效解决。 + +相对于 OpenTSDB,TDengine 具有如下显著特点: + +- 数据写入和查询的性能远超 OpenTSDB; +- 针对时序数据的高效压缩机制,压缩后在磁盘上的存储空间不到 1/5; +- 安装部署非常简单,单一安装包完成安装部署,除了 taosadapter 需要依赖 Go 运行环境外,不依赖其他的第三方软件,整个安装部署过程秒级搞定; +- 提供的内建函数覆盖 OpenTSDB 支持的全部查询函数,还支持更多的时序数据查询函数、标量函数及聚合函数,支持多种时间窗口聚合、连接查询、表达式运算、多种分组聚合、用户定义排序、以及用户定义函数等高级查询功能。采用类 SQL 的语法规则,更加简单易学,基本上没有学习成本。 +- 支持多达 128 个标签,标签总长度可达到 16 KB; +- 除 HTTP 之外,还提供 Java、Python、C、Rust、Go 等多种语言的接口,支持 JDBC 等多种企业级标准连接器协议。 + +如果我们将原本运行在 OpenTSDB 上的应用迁移到 TDengine 上,不仅可以有效地降低计算和存储资源的占用、减少部署服务器的规模,还能够极大减少运行维护的成本的输出,让运维管理工作更简单、更轻松,大幅降低总拥有成本。与OpenTSDB一样,TDengine也已经进行了开源,不同的是,除了单机版,后者还实现了集群版开源,被厂商绑定的顾虑一扫而空。 + +在下文中我们将就“使用最典型并广泛应用的运维监控(DevOps)场景”来说明,如何在不编码的情况下将 OpenTSDB 的应用快速、安全、可靠地迁移到 TDengine之上。后续的章节会做更深度的介绍,以便于进行非DevOps场景的迁移。 + +## DevOps应用快速迁移 + +### 1、典型应用场景 + +一个典型的 DevOps 应用场景的系统整体的架构如下图(图1) 所示。 + +![IT-DevOps-Solutions-Immigrate-OpenTSDB-Arch](../../images/IT-DevOps-Solutions-Immigrate-OpenTSDB-Arch.jpg) +
图1. DevOps场景中典型架构
+ +在该应用场景中,包含了部署在应用环境中负责收集机器度量(Metrics)、网络度量(Metrics)以及应用度量(Metrics)的 Agent 工具、汇聚agent收集信息的数据收集器,数据持久化存储和管理的系统以及监控数据可视化工具(例如:Grafana等)。 + +其中,部署在应用节点的 Agents 负责向 collectd/Statsd 提供不同来源的运行指标,collectd/StatsD则负责将汇聚的数据推送到 OpenTSDB 集群系统,然后使用可视化看板 Grafana 将数据可视化呈现出来。 + +### 2、迁移服务 + +- **TDengine 安装部署** + +首先是TDengine的安装,从官网上下载TDengine最新稳定版,解压缩后运行install.sh进行安装。各种安装包的使用帮助请参见博客[《 TDengine多种安装包的安装和卸载》](https://www.taosdata.com/blog/2019/08/09/566.html)。 + +注意,安装完成以后,不要立即启动 taosd 服务,在正确配置完成参数以后再启动。 + +- **调整数据收集器配置** + +在 TDengine 2.3 版本中,后台服务 taosd 启动后一个 HTTP 的服务 taosadapter 也会自动启用*。*利用 taosadapter 能够兼容 Influxdb 的 Line Protocol 和 OpenTSDB 的 telnet/Json 写入协议,可以将 collectd 和 StatsD 收集的数据直接推送到TDengine。 + +如果使用 collectd,修改其默认位置 `/etc/collectd/collectd.conf` 的配置文件为指向 taosadapter 部署的节点 IP 地址和端口。假设 taosadapter 的 IP 地址为192.168.1.130,端口为 6046,配置如下: + +```html +LoadPlugin write_tsdb + + + Host "192.168.1.130" + Port "6046" + HostTags "status=production" + StoreRates false + AlwaysAppendDS false + + +``` + +即可让 collectd 将数据使用推送到 OpenTSDB 的插件方式推送到 taosadapter, taosadapter 将调用 API 将数据写入到 taosd 中,从而完成数据的写入工作。如果你使用的是 StatsD 相应地调整配置文件信息。 + +- **调整看板(Dashborad)系统** + +在数据能够正常写入TDengine 后,可以调整适配 Grafana 将写入 TDengine 的数据可视化呈现出来。Grafana 暂时还不能够直接连接 TDengine,在 TDengine 的安装目录下 connector/grafanaplugin 有为 Grafana 提供的连接插件。使用该插件的方式很简单: + +首先将grafanaplugin目录下的dist目录整体拷贝到Grafana的插件目录(默认地址为 `/var/lib/grafana/plugins/`),然后重启 Grafana 即可在 **Add Data Source** 菜单下看见 TDengine 数据源。 + +```shell +sudo cp -r . /var/lib/grafana/plugins/tdengine +sudo chown grafana:grafana -R /var/lib/grafana/plugins/tdengine +echo -e "[plugins]\nallow_loading_unsigned_plugins = taosdata-tdengine-datasource\n" | sudo tee -a /etc/grafana/grafana.ini + +# start grafana service +sudo service grafana-server restart +# or with systemd +sudo systemctl start grafana-server +``` + + + +此外,TDengine 还提供了默认的两套Dashboard 模板,供用户快速查看保存到TDengine库里的信息。你只需要将 Grafana 目录下的模板导入到Grafana中即可激活使用。 + +![](../../images/IT-DevOps-Solutions-Immigrate-OpenTSDB-Dashboard.jpg) + +
图2. 导入Grafana模板
+ +操作完以上步骤后,就完成了将OpenTSDB替换成为TDengine的迁移工作。可以看到整个流程非常简单,不需要写代码,只需要对某些配置文件进行调整即可完成全部的迁移工作。 + +### 3、迁移后架构 + +完成迁移以后,此时的系统整体的架构如下图(图3)所示,而整个过程中采集端、数据写入端、以及监控呈现端均保持了稳定,除了极少的配置调整外,不涉及任何重要的更改和变动。OpenTSDB 大量的应用场景均为 DevOps ,这种场景下,简单的参数设置即可完成 OpenTSDB 到 TDengine 迁移动作,使用上 TDengine 更加强大的处理能力和查询性能。 + +在绝大多数的 DevOps 场景中,如果你拥有一个小规模的 OpenTSDB 集群(3台及以下的节点)作为 DevOps 的存储端,依赖于 OpenTSDB 为系统持久化层提供数据存储和查询功能,那么你可以安全地将其替换为 TDengine,并节约更多的计算和存储资源。在同等计算资源配置情况下,单台 TDengine 即可满足 3 ~ 5 台 OpenTSDB 节点提供的服务能力。如果规模比较大,那便需要采用TDengine集群。 + +如果你的应用特别复杂,或者应用领域并不是 DevOps 场景,你可以继续阅读后续的章节,更加全面深入地了解将 OpenTSDB 的应用迁移到 TDengine 的高级话题。 + +![IT-DevOps-Solutions-Immigrate-TDengine-Arch](../../images/IT-DevOps-Solutions-Immigrate-TDengine-Arch.jpg) + +
图3. 迁移完成后的系统架构
+ +## 其他场景的迁移评估与策略 + +### 1、TDengine 与 OpenTSDB 的差异 + +本章将详细介绍 OpenTSDB 与 TDengine 在系统功能层面上存在的差异。阅读完本章的内容,你可以全面地评估是否能够将某些基于 OpenTSDB 的复杂应用迁移到TDengine上,以及迁移之后应该注意的问题。 + +TDengine 当前只支持 Grafana 的可视化看板呈现,所以如果你的应用中使用了 Grafana 以外的前端看板(例如[TSDash](https://github.com/facebook/tsdash)、[Status Wolf](https://github.com/box/StatusWolf)等),那么前端看板将无法直接迁移到 TDengine,需要将前端看板重新适配到 Grafana 才可以正常运行。 + +截止到 2.3.0.x 版本,TDengine 只能够支持 collectd 和 StatsD 作为数据收集汇聚软件,当然后面会陆续提供更多的数据收集聚合软件的接入支持。如果您的收集端使用了其他类型的数据汇聚器,您的应用需要适配到这两个数据汇聚端系统,才能够将数据正常写入。除了上述两个数据汇聚端软件协议以外,TDengine 还支持通过 InfluxDB 的行协议和 OpenTSDB 的数据写入协议、Json 格式将数据直接写入,您可以重写数据推送端的逻辑,使用 TDengine 支持的行协议来写入数据。 + +此外,如果你的应用中使用了 OpenTSDB 以下特性,在将应用迁移到 TDengine 之前你还需要了解以下注意事项: + +1. ` /api/stats`:如果你的应用中使用了该项特性来监控OpenTSDB的服务状态,并在应用中建立了相关的逻辑来联动处理,那么这部分状态读取和获取的逻辑需要重新适配到TDengine。TDengine 提供了全新的处理集群状态监控机制,来满足你的应用对其进行的监控和维护的需求。 +2. `/api/tree`:如果你依赖于OpenTSDB的该项特性来进行时间线的层级化组织和维护,那么便无法将其直接迁移至TDengine。TDengine 采用了数据库->超级表->子表这样的层级来组织和维护时间线,归属于同一个超级表的所有的时间线在系统中同一个层级,但是可以通过不同标签值的特殊构造来模拟应用逻辑上的多级结构。 +3. `Rollup And PreAggregates`:采用了 Rollup 和 PreAggregates 需要应用来决定在合适的地方访问 Rollup 的结果,在某些场景下又要访问原始的结果,这种结构的不透明性让应用处理逻辑变得极为复杂而且完全不具有移植性。我们认为这种策略是时序数据库无法提供高性能聚合情况下的妥协与折中。TDengine 暂不支持多个时间线的自动降采样和(时间段范围的)预聚合,由于 其拥有的高性能查询处理逻辑,即使不依赖于Rollup 和 (时间段)预聚合计算结果,也能够提供很高性能的查询响应,而且让你的应用查询处理逻辑更加简单。 +4. `Rate`: TDengine提供了两个计算数值变化率的函数,分别是Derivative(其计算结果与InfluxDB的Derivative行为一致)和IRate(其计算结果与Prometheus中的IRate函数计算结果一致)。但是这两个函数的计算结果与 Rate 有细微的差别,但整体上功能更强大。此外,**OpenTSDB提供的所有计算函数,TDengine 均有对应的查询函数支持,并且TDengine的查询函数功能远超过OpenTSDB支持的查询函数,**可以极大地简化你的应用处理逻辑。 + +通过上面的介绍,相信你应该能够了解OpenTSDB迁移到TDengine带来的变化,这些信息也有助于你正确地判断是否可以接受将应用 迁移到TDengine之上,体验TDengine提供的强大的时序数据处理能力和便捷的使用体验。 + +### 2、迁移策略 + +首先将基于OpenTSDB的系统进行迁移涉及到的数据模式设计、系统规模估算、数据写入端改造,进行数据分流、应用适配工作;之后将两个系统并行运行一段时间,再将历史数据迁移到 TDengine 中。当然如果你的应用中有部分功能强依赖于上述OpenTSDB特性,同时又不希望停止使用,可以考虑保持原有的OpenTSDB系统运行,同时启动 TDengine来提供主要的服务。 + +## 数据模型设计 + +一方面,TDengine 要求其入库的数据具有严格的模式定义。另一方面,TDengine 的数据模型相对于 OpenTSDB 来说又更加丰富,多值模型能够兼容全部的单值模型的建立需求。 + +现在让我们假设一个 DevOps 的场景,我们使用了 collectd 收集设备的基础度量(metrics),包含了 memory 、swap、disk 等几个度量,其在 OpenTSDB 中的模式如下: + +| 序号 | 测量(metric) | 值名称 | 类型 | tag1 | tag2 | tag3 | tag4 | tag5 | +| ---- | -------------- | ------ | ------ | ---- | ----------- | -------------------- | --------- | ------ | +| 1 | memory | value | double | host | memory_type | memory_type_instance | source | | +| 2 | swap | value | double | host | swap_type | swap_type_instance | source | | +| 3 | disk | value | double | host | disk_point | disk_instance | disk_type | source | + + + +TDengine 要求存储的数据具有数据模式,即写入数据之前需创建超级表并指定超级表的模式。对于数据模式的建立,你有两种方式来完成此项工作:1)充分利用TDengine对 OpenTSDB 的数据原生写入的支持,调用 TDengine 提供的 API 将(文本行或 JSON 格式)数据写入,并自动化地建立单值模型。采用这种方式不需要对数据写入应用进行较大的调整,也不需要对写入的数据格式进行转换。 + +在 C 语言层面,TDengine提供了 taos_insert_lines 来直接写入OpenTSDB格式的数据(在2.3.x 版本中该函数对应的是 taos_schemaless_insert )。其代码参考示例请参见安装包目录下示例代码 schemaless.c。 + + 2)在充分理解 TDengine 的数据模型基础上,结合生成数据的特点,手动方式建立 OpenTSDB 到 TDengine 的数据模型调整的映射关系。TDengine 能够支持多值模型和单值模型,考虑到OpenTSDB 均为单值映射模型,这里推荐使用单值模型在 TDengine 中进行建模。 + +- **单值模型**。 + +具体步骤如下:将度量(metrics)的名称作为 TDengine 超级表的名称,该超级表建成后具有两个基础的数据列—时间戳(timestamp)和值(value),超级表的标签等效于 度量 的标签信息,标签数量等同于度量 的标签的数量。子表的表名采用具有固定规则的方式进行命名:`metric + '_' + tags1_value + '_' + tag2_value + '_' + tag3_value ... `作为子表名称。 + +在TDengine中建立3个超级表: + +```sql +create stable memory(ts timestamp, val float) tags(host binary(12),memory_type binary(20), memory_type_instance binary(20), source binary(20)); +create stable swap(ts timestamp, val double) tags(host binary(12), swap_type binary(20), swap_type_binary binary(20), source binary(20)); +create stable disk(ts timestamp, val double) tags(host binary(12), disk_point binary(20), disk_instance binary(20), disk_type binary(20), source binary(20)); +``` + + + +对于子表使用动态建表的方式创建如下所示: + +```sql +insert into memory_vm130_memory_bufferred_collectd using memory tags(‘vm130’, ‘memory’, 'buffer', 'collectd') values(1632979445, 3.0656); +``` + +最终系统中会建立 340 个左右的子表,3个超级表。需要注意的是,如果采用串联标签值的方式导致子表名称超过系统限制(191字节),那么需要采用一定的编码方式(例如 MD5)将其转化为可接受长度。 + +- **多值模型** + +如果你想要利用 TDengine 的多值模型能力,需要首先满足以下要求:不同的采集量具有相同的采集频率,且能够通过消息队列**同时到达**数据写入端,从而确保使用SQL语句将多个指标一次性写入。将度量的名称作为超级表的名称,建立具有相同采集频率且能够同时到达的数据多列模型。子表的表名采用具有固定规则的方式进行命名。上述每个度量均只包含一个测量值,因此无法将其转化为多值模型。 + + + +## 数据分流与应用适配 + +从消息队列中订阅数据,并启动调整后的写入程序写入数据。 + +数据开始写入持续一段时间后,可以采用SQL语句检查写入的数据量是否符合预计的写入要求。统计数据量使用如下SQL语句: + +```sql +select count(*) from memory +``` + +完成查询后,如果写入的数据与预期的相比没有差别,同时写入程序本身没有异常的报错信息,那么可用确认数据写入是完整有效的。 + +TDengine不支持采用OpenTSDB的查询语法进行查询或数据获取处理,但是针对OpenTSDB的每种查询都提供对应的支持。你可以用检查附件2获取对应的查询处理的调整和应用使用的方式,如果需要全面了解TDengine支持的查询类型,请参阅TDengine的用户手册。 + +TDengine支持标准的JDBC 3.0接口操纵数据库,你也可以使用其他类型的高级语言的连接器来查询读取数据,以适配你的应用。具体的操作和使用帮助也请参阅用户手册。 + +## 历史数据迁移 + +### 1、使用工具自动迁移数据 + +为了方便历史数据的迁移工作,我们为数据同步工具DataX提供了插件,能够将数据自动写入到TDengine中,需要注意的是DataX的自动化数据迁移只能够支持单值模型的数据迁移过程。 + +DataX 具体的使用方式及如何使用DataX将数据写入TDengine请参见其使用帮助手册 [github.com/taosdata/datax](http://github.com/taosdata/datax)。 + +### 2、手动迁移数据 + +如果你需要使用多值模型进行数据写入,就需要自行开发一个将数据从OpenTSDB导出的工具,然后确认哪些时间线能够合并导入到同一个时间线,再将可以同时导入的时间通过SQL语句的写入到数据库中。 + +手动迁移数据需要注意以下两个问题: + +1)在磁盘中存储导出数据时,磁盘需要有足够的存储空间以便能够充分容纳导出的数据文件。为了避免全量数据导出后导致磁盘文件存储紧张,可以采用部分导入的模式,对于归属于同一个超级表的时间线优先导出,然后将导出部分的数据文件导入到TDengine系统中。 + +2)在系统全负载运行下,如果有足够的剩余计算和IO资源,可以建立多线程的导入机制,最大限度地提升数据迁移的效率。考虑到数据解析对于CPU带来的巨大负载,需要控制最大的并行任务数量,以避免因导入历史数据而触发的系统整体过载。 + +由于TDegnine本身操作简易性,所以不需要在整个过程中进行索引维护、数据格式的变化处理等工作,整个过程只需要顺序执行即可。 + +当历史数据完全导入到TDengine以后,此时两个系统处于同时运行的状态,之后便可以将查询请求切换到TDengine上,从而实现无缝的应用切换。 + +## 附录1: OpenTSDB查询函数对应表 + +**Avg** + +等效函数:avg + +示例: + +SELECT avg(val) FROM (SELECT first(val) FROM super_table WHERE ts >= startTime and ts <= endTime INTERVAL(20s) Fill(linear)) INTERVAL(20s) + +备注: + +1. Interval内的数值与外层查询的 interval 数值需要相同。 +2. 在TDengine中插值处理需要使用子查询来协助完成,如上所示,在内层查询中指明插值类型即可,由于 OpenTSDB 中数值的插值使用了线性插值,因此在插值子句中使用fill(linear) 来声明插值类型。以下有相同插值计算需求的函数,均采用该方法处理。 +3. Interval中参数20s表示将内层查询按照20秒一个时间窗口生成结果。在真实的查询中,需要调整为不同的记录之间的时间间隔。这样可确保等效于原始数据生成了插值结果。 +4. 由于 OpenTSDB 特殊的插值策略和机制,聚合查询(Aggregate)中先插值再计算的方式导致其计算结果与 TDengine 不可能完全一致。但是在降采样(Downsample)的情况下,TDengine 和 OpenTSDB 能够获得一致的结果(由于 OpenTSDB 在聚合查询和降采样查询中采用了完全不同的插值策略)。 + + + +**Count** + +等效函数:count + +示例: + +select count(*) from super_table_name; + + + +**Dev** + +等效函数:stddev + +示例: + +Select stddev(val) from table_name + + + +**Estimated percentiles** + +等效函数:apercentile + +示例: + +Select apercentile(col1, 50, “t-digest”) from table_name + +备注: + +1. 近似查询处理过程中,OpenTSDB默认采用t-digest算法,所以为了获得相同的计算结果,需要在apercentile函数中指明使用的算法。TDengine能够支持两种不同的近似处理算法,分别通过”default”和”t-digest”来声明。 + + + +**First** + +等效函数:first + +示例: + +Select first(col1) from table_name + + + +**Last** + +等效函数:last + +示例: + +Select last(col1) from table_name + + + +**Max** + +等效函数:max + +示例: + +Select max(value) from (select first(val) value from table_name interval(10s) fill(linear)) interval(10s) + +备注:Max函数需要插值,原因见上。 + + + +**Min** + +等效函数:min + +示例: + +Select min(value) from (select first(val) value from table_name interval(10s) fill(linear)) interval(10s); + + + +**MinMax** + +等效函数:max + +Select max(val) from table_name + +备注:该函数无插值需求,因此可用直接计算。 + + + +**MimMin** + +等效函数:min + +Select min(val) from table_name + +备注:该函数无插值需求,因此可用直接计算。 + + + +**Percentile** + +等效函数:percentile + +备注: + + + +**Sum** + +等效函数:sum + +Select max(value) from (select first(val) value from table_name interval(10s) fill(linear)) interval(10s) + +备注:该函数无插值需求,因此可用直接计算。 + + + +**Zimsum** + +等效函数:sum + +Select sum(val) from table_name + +备注:该函数无插值需求,因此可用直接计算。 + + + +完整示例: + +```json +//OpenTSDB查询Json +query = { +“start”:1510560000, +“end”: 1515000009, +“queries”:[{ +“aggregator”: “count”, +“metric”:”cpu.usage_user”, +}] +} + +//等效查询SQL: +SELECT count(*) +FROM `cpu.usage_user` +WHERE ts>=1510560000 AND ts<=1515000009 +``` + + + +## 附录2: 资源估算方法 + +### 数据生成环境 + +我们仍然使用第 4 章中的假设环境,3个测量值。分别是:温度和湿度的数据写入的速率是每 5 秒一条记录,时间线 10万个。空气质量的写入速率是10 秒一条记录,时间线1万个,查询的请求频率 500 QPS。 + +### 存储资源估算 + +假设产生数据并需要存储的传感器设备数量为 `n`,数据生成的频率为` t `条/秒,每条记录的长度为 `L` bytes,则每天产生的数据规模为 `n×t×L` bytes。假设压缩比为 C,则每日产生数据规模为 `(n×t×L)/C` bytes。存储资源预估为能够容纳1.5年的数据规模,生产环境下 TDengine 的压缩比 C 一般在 5 ~ 7 之间,同时为最后结果增加 20% 的冗余,可计算得到需要存储资源: + +```matlab +(n×t×L)×(365×1.5)×(1+20%)/C +``` + +结合以上的计算公式,将参数带入计算公式,在不考虑标签信息的情况下,每年产生的原始数据规模是11.8TB。需要注意的是,由于标签信息在TDengine中关联到每个时间线,并不是每条记录。所以需要记录的数据量规模相对于产生的数据有一定的降低,而这部分标签数据整体上可以忽略不记。假设压缩比为5,则保留的数据规模最终为 2.56 TB。 + +### 存储设备选型考虑 + +硬盘应该选用具有较好随机读性能的硬盘设备,如果能够有SSD,尽可能考虑使用SSD。较好的随机读性能的磁盘对于提升系统查询性能具有极大的帮助,能够整体上提升系统的查询响应性能。为了获得较好的查询性能,硬盘设备的单线程随机读IOPS的性能指标不应该低于1000,能够达到5000 IOPS以上为佳。为了获得当前的设备随机读取的IO性能的评估,建议使用fio软件对其进行运行性能评估(具体的使用方式请参阅附录1),确认其是否能够满足大文件随机读性能要求。 + +硬盘写性能对于TDengine的影响不大。TDengine写入过程采用了追加写的模式,所以只要有较好的顺序写性能即可,一般意义上的SAS硬盘和SSD均能够很好地满足TDengine对于磁盘写入性能的要求。 + +### 计算资源估算 + +由于物联网数据的特殊性,数据产生的频率固定以后,TDengine写入的过程对于(计算和存储)资源消耗都保持一个相对固定的量。《[TDengine的运营与维护](https://www.taosdata.com/cn/documentation/administrator)》上的描述,该系统中每秒 22000个写入,消耗CPU不到 1个核。 + +在针对查询所需要消耗的CPU资源的估算上,假设应用要求数据库提供的QPS为 10000,每次查询消耗的CPU时间约 1 ms,那么每个核每秒提供的查询为 1000 QPS,满足10000 QPS的查询请求,至少需要10个核。为了让系统整体上CPU负载小于 50%,整个集群需要10个核的两倍,即 20 个核。 + +### 内存资源估算 + +数据库默认为每个Vnode分配内存 16MB*3缓冲区,集群系统包括22个CPU核,则默认会建立22个虚拟节点Vnode,每个Vnode包含1000张表,则可以容纳所有的表。则约1个半小时写满一个block,从而触发落盘,可以不做调整。22个Vnode共计需要内存缓存约 1GB。考虑到查询所需要的内存,假设每次查询的内存开销约50MB,则500个查询并发需要的内存约25GB。 + +综上所述,可使用单台16核32GB的机器,或者使用2台 8核 16GB机器构成的集群。 + +## 附录3: 集群部署及启动 + +TDengine提供了丰富的帮助文档说明集群安装、部署的诸多方面的内容,这里提供响应的文档索引,供你参考。 + +### 集群部署 + +首先是安装 TDengine,从官网上下载 TDengine 最新稳定版,解压缩后运行 install.sh 进行安装。各种安装包的使用帮助请参见博客[《 TDengine多种安装包的安装和卸载》](https://www.taosdata.com/blog/2019/08/09/566.html)。 + +注意安装完成以后,不要立即启动taosd服务,在正确配置完成参数以后才启动taosd服务。 + +### 设置运行参数并启动服务 + +为确保系统能够正常获取运行的必要信息。请在服务端正确设置以下关键参数: + +FQDN、firstEp、secondEP、dataDir、logDir、tmpDir、serverPort。各参数的具体含义及设置的要求,可参见文档《[TDengine 集群安装、管理](https://www.taosdata.com/cn/documentation/cluster)》 + +按照相同的步骤,在需要运行的节点上设置参数,并启动taosd服务,然后添加Dnode到集群中。 + +最后启动taos,执行命令 show dnodes,如果能看到所有的加入集群的节点,那么集群顺利搭建完成。具体的操作流程及注意事项,请参阅文档《[TDengine 集群安装、管理](https://www.taosdata.com/cn/documentation/cluster)》 + +## 附录4: 超级表名称 + +由于OpenTSDB的metric名称中带有点号(“.“),例如”cpu.usage_user”这种名称的metric。但是点号在TDengine中具有特殊含义,是用来分隔数据库和表名称的分隔符。TDengine也提供转义符,以允许用户在(超级)表名称中使用关键词或特殊分隔符(如:点号)。为了使用特殊字符,需要采用转义字符将表的名称括起来,例如:`cpu.usage_user`这样就是合法的(超级)表名称。 + +## 附录5:参考文章 + +1. [使用 TDengine + collectd/StatsD + Grafana 快速搭建 IT 运维监控系统](https://www.taosdata.com/cn/documentation20/devops/collectd) +2. [通过 collectd 将采集数据直接写入TDengine](https://www.taosdata.com/cn/documentation20/insert#collectd) diff --git a/documentation20/cn/images/IT-DevOps-Solutions-Immigrate-OpenTSDB-Arch.jpg b/documentation20/cn/images/IT-DevOps-Solutions-Immigrate-OpenTSDB-Arch.jpg new file mode 100644 index 0000000000000000000000000000000000000000..d3de5fb7a10a1cb22693468029bc26ad63a96d71 Binary files /dev/null and b/documentation20/cn/images/IT-DevOps-Solutions-Immigrate-OpenTSDB-Arch.jpg differ diff --git a/documentation20/cn/images/IT-DevOps-Solutions-Immigrate-OpenTSDB-Dashboard.jpg b/documentation20/cn/images/IT-DevOps-Solutions-Immigrate-OpenTSDB-Dashboard.jpg new file mode 100644 index 0000000000000000000000000000000000000000..be3704cb72d6c2614614852bfef17147ce49d061 Binary files /dev/null and b/documentation20/cn/images/IT-DevOps-Solutions-Immigrate-OpenTSDB-Dashboard.jpg differ diff --git a/documentation20/cn/images/IT-DevOps-Solutions-Immigrate-TDengine-Arch.jpg b/documentation20/cn/images/IT-DevOps-Solutions-Immigrate-TDengine-Arch.jpg new file mode 100644 index 0000000000000000000000000000000000000000..fd406a140beea43fbfe2c417c85b872cfd6a2219 Binary files /dev/null and b/documentation20/cn/images/IT-DevOps-Solutions-Immigrate-TDengine-Arch.jpg differ diff --git a/importSampleData/app/main.go b/importSampleData/app/main.go index e45e33e159f8636f8bdc5156b3b9b0947453bab4..3589c8c2a98f31e78c4dac3496f804605a0b2314 100644 --- a/importSampleData/app/main.go +++ b/importSampleData/app/main.go @@ -628,7 +628,7 @@ func insertData(threadIndex, start, end int, wg *sync.WaitGroup, successRows []i buffer.WriteString(",") for _, field := range subTableInfo.config.Fields { - buffer.WriteString(getFieldValue(currentRow[strings.ToLower(field.Name)])) + buffer.WriteString(getFieldValue(currentRow[strings.ToLower(field.Name)],field.Type)) buffer.WriteString(",") } @@ -708,7 +708,10 @@ func executeBatchInsert(insertSql string, connection *sql.DB) int64 { return affected } -func getFieldValue(fieldValue interface{}) string { +func getFieldValue(fieldValue interface{},fieldtype interface{}) string { + if fieldtype == "timestamp" || fieldtype == "bigint" { + return fmt.Sprintf("%v", fieldValue) + } return fmt.Sprintf("'%v'", fieldValue) } diff --git a/importSampleData/config/cfg.toml b/importSampleData/config/cfg.toml index 52a5d5f3169d21ce17039ead956250a636b37a01..545bab071ad66af2f59447b3449c6606e2ff1078 100644 --- a/importSampleData/config/cfg.toml +++ b/importSampleData/config/cfg.toml @@ -18,6 +18,8 @@ tags = [ fields = [ # 字段列表,name 为字段名称,type 为字段类型 + # 除主键外,其他field如果也要设置为timestamp,可以是type ="timestamp" 类型,此时value可同时支持'2006-01-02 15:04:05.000'和millisecond格式 + # 也可以是type = "bigint",此时value只支持millisecond格式 { name = "ts", type = "timestamp" }, { name = "temperature", type = "int" }, { name = "humidity", type = "float" }, diff --git a/packaging/cfg/taos.cfg b/packaging/cfg/taos.cfg index e42212ff0f55420dfa5f23638a69439be795e43a..59f87b0a1f8d3aa192383457a85e1d53b1a3bf54 100644 --- a/packaging/cfg/taos.cfg +++ b/packaging/cfg/taos.cfg @@ -299,8 +299,8 @@ keepColumnName 1 # percent of redundant data in tsdb meta will compact meta data,0 means donot compact # tsdbMetaCompactRatio 0 -# default string type used for storing JSON String, options can be binary/nchar, default is binary -# defaultJSONStrType binary +# default string type used for storing JSON String, options can be binary/nchar, default is nchar +# defaultJSONStrType nchar # force TCP transmission # rpcForceTcp 0 diff --git a/packaging/deb/makedeb.sh b/packaging/deb/makedeb.sh index f753668b3b1a83d15c126ae6b0d94c06e97c80aa..f28d98ba9a6fae4390bfa301760aff9583ba4e40 100755 --- a/packaging/deb/makedeb.sh +++ b/packaging/deb/makedeb.sh @@ -45,10 +45,10 @@ mkdir -p ${pkg_dir}${install_home_path}/script cp ${compile_dir}/../packaging/cfg/taos.cfg ${pkg_dir}${install_home_path}/cfg if [ -f "${compile_dir}/test/cfg/taosadapter.toml" ]; then - cp ${compile_dir}/test/cfg/taosadapter.toml ${pkg_dir}${install_home_path}/cfg + cp ${compile_dir}/test/cfg/taosadapter.toml ${pkg_dir}${install_home_path}/cfg || : fi if [ -f "${compile_dir}/test/cfg/taosadapter.service" ]; then - cp ${compile_dir}/test/cfg/taosadapter.service ${pkg_dir}${install_home_path}/cfg ||: + cp ${compile_dir}/test/cfg/taosadapter.service ${pkg_dir}${install_home_path}/cfg || : fi cp ${compile_dir}/../packaging/deb/taosd ${pkg_dir}${install_home_path}/init.d diff --git a/packaging/release.sh b/packaging/release.sh index b9fe25ec08e8dcd1170867fa20f4a4fe5a1ef2d1..c82d5704ac5c4d89837f5afe4b1f6e27419279cc 100755 --- a/packaging/release.sh +++ b/packaging/release.sh @@ -194,6 +194,7 @@ fi if [[ "$dbName" == "pro" ]]; then sed -i "s/taos config/prodb config/g" ${top_dir}/src/util/src/tconfig.c + sed -i "s/TDengine/ProDB/g" ${top_dir}/src/dnode/src/dnodeSystem.c fi echo "build ${pagMode} package ..." @@ -213,7 +214,12 @@ else exit 1 fi -make -j8 && ${csudo} make install +if [[ "$allocator" == "jemalloc" ]]; then + # jemalloc need compile first, so disable parallel build + make V=1 && ${csudo} make install +else + make -j8 && ${csudo} make install +fi cd ${curr_dir} diff --git a/packaging/tools/install.sh b/packaging/tools/install.sh index 61fcd3e51982dab6a72245fe0ffb9de5ac51a664..dcd4a83da8929d76aa61d848985b5c4ffe46b9c5 100755 --- a/packaging/tools/install.sh +++ b/packaging/tools/install.sh @@ -757,8 +757,12 @@ function install_service_on_systemd() { } function install_taosadapter_service() { - [ -f ${script_dir}/cfg/taosadapter.service ] &&\ - ${csudo} cp ${script_dir}/cfg/taosadapter.service ${service_config_dir}/ + if ((${service_mod}==0)); then + [ -f ${script_dir}/cfg/taosadapter.service ] &&\ + ${csudo} cp ${script_dir}/cfg/taosadapter.service \ + ${service_config_dir}/ || : + ${csudo} systemctl daemon-reload + fi } function install_service() { diff --git a/packaging/tools/make_install.sh b/packaging/tools/make_install.sh index 8309fa516c4ffdcd9e5a17056304427543dad0a9..093b2bb0a7ea8033b7509e231200b8b4ad6901be 100755 --- a/packaging/tools/make_install.sh +++ b/packaging/tools/make_install.sh @@ -62,12 +62,14 @@ NC='\033[0m' csudo="" +service_mod=2 +os_type=0 + if [ "$osType" != "Darwin" ]; then if command -v sudo > /dev/null; then csudo="sudo" fi initd_mod=0 - service_mod=2 if pidof systemd &> /dev/null; then service_mod=0 elif $(which service &> /dev/null); then @@ -91,7 +93,6 @@ if [ "$osType" != "Darwin" ]; then #osinfo=$(awk -F= '/^NAME/{print $2}' /etc/os-release) osinfo=$(cat /etc/os-release | grep "NAME" | cut -d '"' -f2) #echo "osinfo: ${osinfo}" - os_type=0 if echo $osinfo | grep -qwi "ubuntu" ; then echo "this is ubuntu system" os_type=1 @@ -122,7 +123,8 @@ function kill_taosadapter() { } function kill_taosd() { - pid=$(ps -ef | grep "taosd" | grep -v "grep" | awk '{print $2}') + ps -ef | grep "taosd" + pid=$(ps -ef | grep -w "taosd" | grep -v "grep" | awk '{print $2}') if [ -n "$pid" ]; then ${csudo} kill -9 $pid || : fi @@ -202,31 +204,31 @@ function install_jemalloc() { /usr/bin/install -c -d /usr/local/bin if [ -f "${binary_dir}/build/bin/jemalloc-config" ]; then - /usr/bin/install -c -m 755 ${binary_dir}/build/bin/jemalloc-config /usr/local/bin + ${csudo} /usr/bin/install -c -m 755 ${binary_dir}/build/bin/jemalloc-config /usr/local/bin fi if [ -f "${binary_dir}/build/bin/jemalloc.sh" ]; then - /usr/bin/install -c -m 755 ${binary_dir}/build/bin/jemalloc.sh /usr/local/bin + ${csudo} /usr/bin/install -c -m 755 ${binary_dir}/build/bin/jemalloc.sh /usr/local/bin fi if [ -f "${binary_dir}/build/bin/jeprof" ]; then - /usr/bin/install -c -m 755 ${binary_dir}/build/bin/jeprof /usr/local/bin + ${csudo} /usr/bin/install -c -m 755 ${binary_dir}/build/bin/jeprof /usr/local/bin fi if [ -f "${binary_dir}/build/include/jemalloc/jemalloc.h" ]; then - /usr/bin/install -c -d /usr/local/include/jemalloc - /usr/bin/install -c -m 644 ${binary_dir}/build/include/jemalloc/jemalloc.h\ + ${csudo} /usr/bin/install -c -d /usr/local/include/jemalloc + ${csudo} /usr/bin/install -c -m 644 ${binary_dir}/build/include/jemalloc/jemalloc.h\ /usr/local/include/jemalloc fi if [ -f "${binary_dir}/build/lib/libjemalloc.so.2" ]; then - /usr/bin/install -c -d /usr/local/lib - /usr/bin/install -c -m 755 ${binary_dir}/build/lib/libjemalloc.so.2 /usr/local/lib - ln -sf libjemalloc.so.2 /usr/local/lib/libjemalloc.so - /usr/bin/install -c -d /usr/local/lib + ${csudo} /usr/bin/install -c -d /usr/local/lib + ${csudo} /usr/bin/install -c -m 755 ${binary_dir}/build/lib/libjemalloc.so.2 /usr/local/lib + ${csudo} ln -sf libjemalloc.so.2 /usr/local/lib/libjemalloc.so + ${csudo} /usr/bin/install -c -d /usr/local/lib [ -f ${binary_dir}/build/lib/libjemalloc.a ] && - /usr/bin/install -c -m 755 ${binary_dir}/build/lib/libjemalloc.a /usr/local/lib + ${csudo} /usr/bin/install -c -m 755 ${binary_dir}/build/lib/libjemalloc.a /usr/local/lib [ -f ${binary_dir}/build/lib/libjemalloc_pic.a ] && - /usr/bin/install -c -m 755 ${binary_dir}/build/lib/libjemalloc_pic.a /usr/local/lib + ${csudo} /usr/bin/install -c -m 755 ${binary_dir}/build/lib/libjemalloc_pic.a /usr/local/lib if [ -f "${binary_dir}/build/lib/pkgconfig/jemalloc.pc" ]; then - /usr/bin/install -c -d /usr/local/lib/pkgconfig - /usr/bin/install -c -m 644 ${binary_dir}/build/lib/pkgconfig/jemalloc.pc\ + ${csudo} /usr/bin/install -c -d /usr/local/lib/pkgconfig + ${csudo} /usr/bin/install -c -m 644 ${binary_dir}/build/lib/pkgconfig/jemalloc.pc\ /usr/local/lib/pkgconfig fi if [ -d /etc/ld.so.conf.d ]; then @@ -237,29 +239,28 @@ function install_jemalloc() { fi fi if [ -f "${binary_dir}/build/share/doc/jemalloc/jemalloc.html" ]; then - /usr/bin/install -c -d /usr/local/share/doc/jemalloc - /usr/bin/install -c -m 644 ${binary_dir}/build/share/doc/jemalloc/jemalloc.html\ + ${csudo} /usr/bin/install -c -d /usr/local/share/doc/jemalloc + ${csudo} /usr/bin/install -c -m 644 ${binary_dir}/build/share/doc/jemalloc/jemalloc.html\ /usr/local/share/doc/jemalloc fi if [ -f "${binary_dir}/build/share/man/man3/jemalloc.3" ]; then - /usr/bin/install -c -d /usr/local/share/man/man3 - /usr/bin/install -c -m 644 ${binary_dir}/build/share/man/man3/jemalloc.3\ + ${csudo} /usr/bin/install -c -d /usr/local/share/man/man3 + ${csudo} /usr/bin/install -c -m 644 ${binary_dir}/build/share/man/man3/jemalloc.3\ /usr/local/share/man/man3 fi - fi } function install_avro() { if [ "$osType" != "Darwin" ]; then if [ -f "${binary_dir}/build/$1/libavro.so.23.0.0" ]; then - /usr/bin/install -c -d /usr/local/$1 - /usr/bin/install -c -m 755 ${binary_dir}/build/$1/libavro.so.23.0.0 /usr/local/$1 - ln -sf libavro.so.23.0.0 /usr/local/$1/libavro.so.23 - ln -sf libavro.so.23 /usr/local/$1/libavro.so - /usr/bin/install -c -d /usr/local/$1 + ${csudo} /usr/bin/install -c -d /usr/local/$1 + ${csudo} /usr/bin/install -c -m 755 ${binary_dir}/build/$1/libavro.so.23.0.0 /usr/local/$1 + ${csudo} ln -sf libavro.so.23.0.0 /usr/local/$1/libavro.so.23 + ${csudo} ln -sf libavro.so.23 /usr/local/$1/libavro.so + ${csudo} /usr/bin/install -c -d /usr/local/$1 [ -f ${binary_dir}/build/$1/libavro.a ] && - /usr/bin/install -c -m 755 ${binary_dir}/build/$1/libavro.a /usr/local/$1 + ${csudo} /usr/bin/install -c -m 755 ${binary_dir}/build/$1/libavro.a /usr/local/$1 if [ -d /etc/ld.so.conf.d ]; then echo "/usr/local/$1" | ${csudo} tee /etc/ld.so.conf.d/libavro.conf @@ -455,11 +456,11 @@ function install_service_on_sysvinit() { # Install taosd service if ((${os_type}==1)); then - ${csudo} cp -f ${script_dir}/../deb/taosd ${install_main_dir}/init.d - ${csudo} cp ${script_dir}/../deb/taosd ${service_config_dir} && ${csudo} chmod a+x ${service_config_dir}/taosd + ${csudo} cp -f ${script_dir}/../deb/taosd ${install_main_dir}/init.d + ${csudo} cp ${script_dir}/../deb/taosd ${service_config_dir} && ${csudo} chmod a+x ${service_config_dir}/taosd elif ((${os_type}==2)); then - ${csudo} cp -f ${script_dir}/../rpm/taosd ${install_main_dir}/init.d - ${csudo} cp ${script_dir}/../rpm/taosd ${service_config_dir} && ${csudo} chmod a+x ${service_config_dir}/taosd + ${csudo} cp -f ${script_dir}/../rpm/taosd ${install_main_dir}/init.d + ${csudo} cp ${script_dir}/../rpm/taosd ${service_config_dir} && ${csudo} chmod a+x ${service_config_dir}/taosd fi #restart_config_str="taos:2345:respawn:${service_config_dir}/taosd start" @@ -523,9 +524,8 @@ function install_taosadapter_service() { if ((${service_mod}==0)); then [ -f ${binary_dir}/test/cfg/taosadapter.service ] &&\ ${csudo} cp ${binary_dir}/test/cfg/taosadapter.service\ - ${service_config_dir}/ || : - else - kill_taosadapter + ${service_config_dir}/ || : + ${csudo} systemctl daemon-reload fi } @@ -544,7 +544,6 @@ function update_TDengine() { echo -e "${GREEN}Start to update TDengine...${NC}" # Stop the service if running - if [ "$osType" != "Darwin" ]; then if pidof taosd &> /dev/null; then if ((${service_mod}==0)); then ${csudo} systemctl stop taosd || : @@ -556,7 +555,6 @@ function update_TDengine() { fi sleep 1 fi - fi install_main_path @@ -567,50 +565,35 @@ function update_TDengine() { install_examples install_bin - if [ "$osType" != "Darwin" ]; then - install_service - install_taosadapter_service - fi + install_service + install_taosadapter_service install_config install_taosadapter_config - if [ "$osType" != "Darwin" ]; then - echo - echo -e "\033[44;32;1mTDengine is updated successfully!${NC}" - echo - - echo -e "${GREEN_DARK}To configure TDengine ${NC}: edit /etc/taos/taos.cfg" - echo -e "${GREEN_DARK}To configure taosadapter (if has) ${NC}: edit /etc/taos/taosadapter.toml" - if ((${service_mod}==0)); then - echo -e "${GREEN_DARK}To start TDengine ${NC}: ${csudo} systemctl start taosd${NC}" - elif ((${service_mod}==1)); then - echo -e "${GREEN_DARK}To start TDengine ${NC}: ${csudo} service taosd start${NC}" - else - echo -e "${GREEN_DARK}To start TDengine ${NC}: ./taosd${NC}" - fi + echo + echo -e "\033[44;32;1mTDengine is updated successfully!${NC}" + echo - echo -e "${GREEN_DARK}To access TDengine ${NC}: use ${GREEN_UNDERLINE}taos${NC} in shell${NC}" - echo - echo -e "\033[44;32;1mTDengine is updated successfully!${NC}" + echo -e "${GREEN_DARK}To configure TDengine ${NC}: edit /etc/taos/taos.cfg" + echo -e "${GREEN_DARK}To configure Taos Adapter (if has) ${NC}: edit /etc/taos/taosadapter.toml" + if ((${service_mod}==0)); then + echo -e "${GREEN_DARK}To start TDengine ${NC}: ${csudo} systemctl start taosd${NC}" + elif ((${service_mod}==1)); then + echo -e "${GREEN_DARK}To start TDengine ${NC}: ${csudo} service taosd start${NC}" else - echo - echo -e "\033[44;32;1mTDengine Client is updated successfully!${NC}" - echo - - echo -e "${GREEN_DARK}To access TDengine Client ${NC}: use ${GREEN_UNDERLINE}taos${NC} in shell${NC}" - echo - echo -e "\033[44;32;1mTDengine Client is updated successfully!${NC}" + echo -e "${GREEN_DARK}To start Taos Adapter (if has)${NC}: taosadapter &${NC}" + echo -e "${GREEN_DARK}To start TDengine ${NC}: taosd${NC}" fi + + echo -e "${GREEN_DARK}To access TDengine ${NC}: use ${GREEN_UNDERLINE}taos${NC} in shell${NC}" + echo + echo -e "\033[44;32;1mTDengine is updated successfully!${NC}" } function install_TDengine() { # Start to install - if [ "$osType" != "Darwin" ]; then - echo -e "${GREEN}Start to install TDEngine...${NC}" - else - echo -e "${GREEN}Start to install TDEngine Client ...${NC}" - fi + echo -e "${GREEN}Start to install TDengine...${NC}" install_main_path @@ -622,37 +605,29 @@ function install_TDengine() { install_examples install_bin - if [ "$osType" != "Darwin" ]; then - install_service - install_taosadapter_service - fi + install_service + install_taosadapter_service install_config install_taosadapter_config - if [ "$osType" != "Darwin" ]; then - # Ask if to start the service - echo - echo -e "\033[44;32;1mTDengine is installed successfully!${NC}" - echo - echo -e "${GREEN_DARK}To configure TDengine ${NC}: edit /etc/taos/taos.cfg" - echo -e "${GREEN_DARK}To configure taosadapter (if has) ${NC}: edit /etc/taos/taosadapter.toml" - if ((${service_mod}==0)); then - echo -e "${GREEN_DARK}To start TDengine ${NC}: ${csudo} systemctl start taosd${NC}" - elif ((${service_mod}==1)); then - echo -e "${GREEN_DARK}To start TDengine ${NC}: ${csudo} service taosd start${NC}" - else - echo -e "${GREEN_DARK}To start TDengine ${NC}: ./taosd${NC}" - fi - - echo -e "${GREEN_DARK}To access TDengine ${NC}: use ${GREEN_UNDERLINE}taos${NC} in shell${NC}" - echo - echo -e "\033[44;32;1mTDengine is installed successfully!${NC}" + # Ask if to start the service + echo + echo -e "\033[44;32;1mTDengine is installed successfully!${NC}" + echo + echo -e "${GREEN_DARK}To configure TDengine ${NC}: edit /etc/taos/taos.cfg" + echo -e "${GREEN_DARK}To configure taosadapter (if has) ${NC}: edit /etc/taos/taosadapter.toml" + if ((${service_mod}==0)); then + echo -e "${GREEN_DARK}To start TDengine ${NC}: ${csudo} systemctl start taosd${NC}" + elif ((${service_mod}==1)); then + echo -e "${GREEN_DARK}To start TDengine ${NC}: ${csudo} service taosd start${NC}" else - echo -e "${GREEN_DARK}To access TDengine ${NC}: use ${GREEN_UNDERLINE}taos${NC} in shell${NC}" - echo - echo -e "\033[44;32;1mTDengine Client is installed successfully!${NC}" + echo -e "${GREEN_DARK}To start TDengine ${NC}: ./taosd${NC}" fi + + echo -e "${GREEN_DARK}To access TDengine ${NC}: use ${GREEN_UNDERLINE}taos${NC} in shell${NC}" + echo + echo -e "\033[44;32;1mTDengine is installed successfully!${NC}" } ## ==============================Main program starts from here============================ diff --git a/packaging/tools/makepkg.sh b/packaging/tools/makepkg.sh index 05b49ff6a9599c6050d2ccad778f63d285981420..7ad703be86016bd0c0ce55c80b76bf34914c54bb 100755 --- a/packaging/tools/makepkg.sh +++ b/packaging/tools/makepkg.sh @@ -78,7 +78,13 @@ mkdir -p ${install_dir} mkdir -p ${install_dir}/inc && cp ${header_files} ${install_dir}/inc mkdir -p ${install_dir}/cfg && cp ${cfg_dir}/taos.cfg ${install_dir}/cfg/taos.cfg -[ -f ${cfg_dir}/taosadapter.toml ] && cp ${cfg_dir}/taosadapter.toml ${install_dir}/cfg/taosadapter.toml +if [ -f "${compile_dir}/test/cfg/taosadapter.toml" ]; then + cp ${compile_dir}/test/cfg/taosadapter.toml ${install_dir}/cfg || : +fi + +if [ -f "${compile_dir}/test/cfg/taosadapter.service" ]; then + cp ${compile_dir}/test/cfg/taosadapter.service ${install_dir}/cfg || : +fi mkdir -p ${install_dir}/bin && cp ${bin_files} ${install_dir}/bin && chmod a+x ${install_dir}/bin/* || : mkdir -p ${install_dir}/init.d && cp ${init_file_deb} ${install_dir}/init.d/taosd.deb diff --git a/packaging/tools/post.sh b/packaging/tools/post.sh index c3db7e417adb11b92d55464b69c715e3aee2d6bb..2f4b07067fd08ee3a9591f97e7291305307ff498 100755 --- a/packaging/tools/post.sh +++ b/packaging/tools/post.sh @@ -467,7 +467,12 @@ function install_service_on_systemd() { } function install_taosadapter_service() { - [ -f ${cfg_dir}/taosadapter.service ] && ${csudo} cp ${cfg_dir}/taosadapter.service ${service_config_dir} + if ((${service_mod}==0)); then + [ -f ${script_dir}/cfg/taosadapter.service ] &&\ + ${csudo} cp ${script_dir}/cfg/taosadapter.service \ + ${service_config_dir}/ || : + ${csudo} systemctl daemon-reload + fi } function install_service() { diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index 64e3af498cedd25dea90055426110522bc4a4086..66ec851dc945d4897ef40d6a361468dd1d16a5a2 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -1,6 +1,6 @@ name: tdengine base: core20 -version: '2.3.1.0' +version: '2.3.2.0' icon: snap/gui/t-dengine.svg summary: an open-source big data platform designed and optimized for IoT. description: | diff --git a/src/client/inc/tscUtil.h b/src/client/inc/tscUtil.h index 04ee1b7953946565007e8a30f43fa4a600e63b19..b183598fcceff926cfba235e42d8634546b36a48 100644 --- a/src/client/inc/tscUtil.h +++ b/src/client/inc/tscUtil.h @@ -83,6 +83,11 @@ typedef struct SJoinSupporter { int32_t totalLen; int32_t num; SArray* pVgroupTables; + + int16_t fillType; // final result fill type + int64_t * fillVal; // default value for fill + int32_t numOfFillVal; // fill value size + } SJoinSupporter; @@ -119,7 +124,8 @@ typedef struct SBlockKeyInfo { int32_t converToStr(char *str, int type, void *buf, int32_t bufSize, int32_t *len); int32_t tscCreateDataBlock(size_t initialSize, int32_t rowSize, int32_t startOffset, SName* name, STableMeta* pTableMeta, STableDataBlocks** dataBlocks); -void tscDestroyDataBlock(SSqlObj *pSql, STableDataBlocks* pDataBlock, bool removeMeta); +int32_t tscCreateDataBlockData(STableDataBlocks* dataBuf, size_t defaultSize, int32_t rowSize, int32_t startOffset); +void tscDestroyDataBlock(SSqlObj *pSql, STableDataBlocks* pDataBlock, bool removeMeta); void tscSortRemoveDataBlockDupRowsRaw(STableDataBlocks* dataBuf); int tscSortRemoveDataBlockDupRows(STableDataBlocks* dataBuf, SBlockKeyInfo* pBlkKeyInfo); int32_t tsSetBlockInfo(SSubmitBlk *pBlocks, const STableMeta *pTableMeta, int32_t numOfRows); @@ -147,6 +153,7 @@ int32_t tscGetDataBlockFromList(SHashObj* pHashList, int64_t id, int32_t size, i * @return */ bool tscIsPointInterpQuery(SQueryInfo* pQueryInfo); +bool tscGetPointInterpQuery(SQueryInfo* pQueryInfo); bool tscIsTWAQuery(SQueryInfo* pQueryInfo); bool tscIsIrateQuery(SQueryInfo* pQueryInfo); bool tscQueryContainsFunction(SQueryInfo* pQueryInfo, int16_t functionId); diff --git a/src/client/src/tscAsync.c b/src/client/src/tscAsync.c index 08e08cc6599efd0a2f0fe6de0ef52b1fbdfb6d88..2ddae0f903a6c42235343a6dd526d37e53147734 100644 --- a/src/client/src/tscAsync.c +++ b/src/client/src/tscAsync.c @@ -237,7 +237,7 @@ void taos_fetch_rows_a(TAOS_RES *tres, __async_cb_func_t fp, void *param) { return; } - if (pRes->qId == 0) { + if (pRes->qId == 0 && pSql->cmd.command != TSDB_SQL_RETRIEVE_EMPTY_RESULT) { tscError("qhandle is invalid"); pRes->code = TSDB_CODE_TSC_INVALID_QHANDLE; tscAsyncResultOnError(pSql); diff --git a/src/client/src/tscGlobalmerge.c b/src/client/src/tscGlobalmerge.c index 0b660c592c84eb4605a1fb76afd3b180fc5daa07..a6edac0659c9a8f1670b05bd0d53d2ad6ca84e7c 100644 --- a/src/client/src/tscGlobalmerge.c +++ b/src/client/src/tscGlobalmerge.c @@ -968,7 +968,6 @@ SSDataBlock* doGlobalAggregate(void* param, bool* newgroup) { if (pOperator->pRuntimeEnv->pQueryAttr->order.order == TSDB_ORDER_DESC) { SWAP(w->skey, w->ekey, TSKEY); - assert(w->skey <= w->ekey); } } } diff --git a/src/client/src/tscParseInsert.c b/src/client/src/tscParseInsert.c index d7ceee630217acc72f8cebc464b3e38aaf440a4e..94f9a3018aae175f0f27c1c24b735f5a0392102d 100644 --- a/src/client/src/tscParseInsert.c +++ b/src/client/src/tscParseInsert.c @@ -314,8 +314,6 @@ int32_t tsParseOneColumn(SSchema *pSchema, SStrToken *pToken, char *payload, cha ret = tStrToInteger(pToken->z, pToken->type, pToken->n, &iv, false); if (ret != TSDB_CODE_SUCCESS) { return tscInvalidOperationMsg(msg, "invalid unsigned bigint data", pToken->z); - } else if (!IS_VALID_UBIGINT((uint64_t)iv)) { - return tscInvalidOperationMsg(msg, "unsigned bigint data overflow", pToken->z); } *((uint64_t *)payload) = iv; @@ -1419,6 +1417,11 @@ int tsParseInsertSql(SSqlObj *pSql) { goto _clean; } + if (sToken.type == TK_ILLEGAL) { // ,,,, like => insert into t values(now,1),,,,(now+1s,2); + code = tscSQLSyntaxErrMsg(pInsertParam->msg, NULL, str); + goto _clean; + } + /* * if no data has been generated during parsing the sql string, error msg will return * Otherwise, create the first submit block and submit to virtual node. diff --git a/src/client/src/tscParseOpenTSDB.c b/src/client/src/tscParseOpenTSDB.c index e78abf0596447df0ee58db88ca87b19011293c6c..98a836810a9a2501761dfce38b48be1498267561 100644 --- a/src/client/src/tscParseOpenTSDB.c +++ b/src/client/src/tscParseOpenTSDB.c @@ -195,8 +195,9 @@ static int32_t parseTelnetMetricValue(TAOS_SML_KV **pKVs, int *num_kvs, const ch } tfree(value); - pVal->key = tcalloc(sizeof(key), 1); + pVal->key = tcalloc(sizeof(key) + TS_ESCAPE_CHAR_SIZE, 1); memcpy(pVal->key, key, sizeof(key)); + addEscapeCharToString(pVal->key, (int32_t)strlen(pVal->key)); *num_kvs += 1; *index = cur + 1; @@ -881,8 +882,9 @@ static int32_t parseMetricValueFromJSON(cJSON *root, TAOS_SML_KV **pKVs, int *nu return ret; } - pVal->key = tcalloc(sizeof(key), 1); + pVal->key = tcalloc(sizeof(key) + TS_ESCAPE_CHAR_SIZE, 1); memcpy(pVal->key, key, sizeof(key)); + addEscapeCharToString(pVal->key, (int32_t)strlen(pVal->key)); *num_kvs += 1; return TSDB_CODE_SUCCESS; diff --git a/src/client/src/tscPrepare.c b/src/client/src/tscPrepare.c index 04dd7f57cabe8f01ade992cfe1d4a3122a26d130..66286476024d465e2c08bf83f06195640c5315d3 100644 --- a/src/client/src/tscPrepare.c +++ b/src/client/src/tscPrepare.c @@ -48,12 +48,14 @@ typedef struct SMultiTbStmt { bool nameSet; bool tagSet; bool subSet; + bool tagColSet; uint64_t currentUid; char *sqlstr; uint32_t tbNum; SStrToken tbname; SStrToken stbname; SStrToken values; + SStrToken tagCols; SArray *tags; STableDataBlocks *lastBlock; SHashObj *pTableHash; @@ -1250,6 +1252,12 @@ static void insertBatchClean(STscStmt* pStmt) { pCmd->insertParam.pDataBlocks = tscDestroyBlockArrayList(pSql, pCmd->insertParam.pDataBlocks); pCmd->insertParam.numOfTables = 0; + STableDataBlocks** p = taosHashIterate(pCmd->insertParam.pTableBlockHashList, NULL); + while(p) { + tfree((*p)->pData); + p = taosHashIterate(pCmd->insertParam.pTableBlockHashList, p); + } + taosHashClear(pCmd->insertParam.pTableBlockHashList); tscFreeSqlResult(pSql); tscFreeSubobj(pSql); @@ -1343,9 +1351,40 @@ int stmtParseInsertTbTags(SSqlObj* pSql, STscStmt* pStmt) { pStmt->mtb.stbname = sToken; sToken = tStrGetToken(pCmd->insertParam.sql, &index, false); - if (sToken.n <= 0 || sToken.type != TK_TAGS) { - tscError("keyword TAGS expected, sql:%s", pCmd->insertParam.sql); - return tscSQLSyntaxErrMsg(pCmd->payload, "keyword TAGS expected", sToken.z ? sToken.z : pCmd->insertParam.sql); + if (sToken.n <= 0 || ((sToken.type != TK_TAGS) && (sToken.type != TK_LP))) { + tscError("invalid token, sql:%s", pCmd->insertParam.sql); + return tscSQLSyntaxErrMsg(pCmd->payload, "invalid token", sToken.z ? sToken.z : pCmd->insertParam.sql); + } + + // ... (tag_col_list) TAGS(tag_val_list) ... + int32_t tagColsCnt = 0; + if (sToken.type == TK_LP) { + pStmt->mtb.tagColSet = true; + pStmt->mtb.tagCols = sToken; + int32_t tagColsStart = index; + while (1) { + sToken = tStrGetToken(pCmd->insertParam.sql, &index, false); + if (sToken.type == TK_ILLEGAL) { + return tscSQLSyntaxErrMsg(pCmd->payload, "unrecognized token", sToken.z); + } + if (sToken.type == TK_ID) { + ++tagColsCnt; + } + if (sToken.type == TK_RP) { + break; + } + } + if (tagColsCnt == 0) { + tscError("tag column list expected, sql:%s", pCmd->insertParam.sql); + return tscSQLSyntaxErrMsg(pCmd->payload, "tag column list expected", pCmd->insertParam.sql); + } + pStmt->mtb.tagCols.n = index - tagColsStart + 1; + + sToken = tStrGetToken(pCmd->insertParam.sql, &index, false); + if (sToken.n <= 0 || sToken.type != TK_TAGS) { + 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); @@ -1385,6 +1424,11 @@ int stmtParseInsertTbTags(SSqlObj* pSql, STscStmt* pStmt) { return tscSQLSyntaxErrMsg(pCmd->payload, "no tags", pCmd->insertParam.sql); } + if (tagColsCnt > 0 && taosArrayGetSize(pStmt->mtb.tags) != tagColsCnt) { + tscError("not match tags, sql:%s", pCmd->insertParam.sql); + return tscSQLSyntaxErrMsg(pCmd->payload, "not match tags", pCmd->insertParam.sql); + } + sToken = tStrGetToken(pCmd->insertParam.sql, &index, false); if (sToken.n <= 0 || (sToken.type != TK_VALUES && sToken.type != TK_LP)) { tscError("sql error, sql:%s", pCmd->insertParam.sql); @@ -1407,7 +1451,13 @@ int stmtGenInsertStatement(SSqlObj* pSql, STscStmt* pStmt, const char* name, TAO int32_t j = 0; while (1) { - len = (size_t)snprintf(str, size - 1, "insert into %s using %.*s tags(", name, pStmt->mtb.stbname.n, pStmt->mtb.stbname.z); + if (pStmt->mtb.tagColSet) { + len = (size_t)snprintf(str, size - 1, "insert into %s using %.*s %.*s tags(", + name, pStmt->mtb.stbname.n, pStmt->mtb.stbname.z, pStmt->mtb.tagCols.n, pStmt->mtb.tagCols.z); + } else { + len = (size_t)snprintf(str, size - 1, "insert into %s using %.*s tags(", name, pStmt->mtb.stbname.n, pStmt->mtb.stbname.z); + } + if (len >= (size -1)) { size *= 2; free(str); @@ -1659,6 +1709,13 @@ int taos_stmt_set_tbname_tags(TAOS_STMT* stmt, const char* name, TAOS_BIND* tags STMT_RET(TSDB_CODE_TSC_APP_ERROR); } + if ((*t1)->pData == NULL) { + code = tscCreateDataBlockData(*t1, TSDB_PAYLOAD_SIZE, (*t1)->pTableMeta->tableInfo.rowSize, sizeof(SSubmitBlk)); + if (code != TSDB_CODE_SUCCESS) { + STMT_RET(code); + } + } + SSubmitBlk* pBlk = (SSubmitBlk*) (*t1)->pData; pCmd->batchSize = pBlk->numOfRows; if (pBlk->numOfRows == 0) { @@ -1784,7 +1841,6 @@ int taos_stmt_set_tbname_tags(TAOS_STMT* stmt, const char* name, TAOS_BIND* tags STMT_RET(code); } - int taos_stmt_set_sub_tbname(TAOS_STMT* stmt, const char* name) { STscStmt* pStmt = (STscStmt*)stmt; STMT_CHECK @@ -1792,8 +1848,6 @@ int taos_stmt_set_sub_tbname(TAOS_STMT* stmt, const char* name) { return taos_stmt_set_tbname_tags(stmt, name, NULL); } - - int taos_stmt_set_tbname(TAOS_STMT* stmt, const char* name) { STscStmt* pStmt = (STscStmt*)stmt; STMT_CHECK @@ -1801,7 +1855,6 @@ int taos_stmt_set_tbname(TAOS_STMT* stmt, const char* name) { return taos_stmt_set_tbname_tags(stmt, name, NULL); } - int taos_stmt_close(TAOS_STMT* stmt) { STscStmt* pStmt = (STscStmt*)stmt; if (pStmt == NULL || pStmt->taos == NULL) { @@ -1868,7 +1921,6 @@ int taos_stmt_bind_param(TAOS_STMT* stmt, TAOS_BIND* bind) { } } - int taos_stmt_bind_param_batch(TAOS_STMT* stmt, TAOS_MULTI_BIND* bind) { STscStmt* pStmt = (STscStmt*)stmt; @@ -1932,8 +1984,6 @@ int taos_stmt_bind_single_param_batch(TAOS_STMT* stmt, TAOS_MULTI_BIND* bind, in STMT_RET(insertStmtBindParamBatch(pStmt, bind, colIdx)); } - - int taos_stmt_add_batch(TAOS_STMT* stmt) { STscStmt* pStmt = (STscStmt*)stmt; STMT_CHECK @@ -2086,7 +2136,6 @@ int taos_stmt_get_param(TAOS_STMT *stmt, int idx, int *type, int *bytes) { } } - char *taos_stmt_errstr(TAOS_STMT *stmt) { STscStmt* pStmt = (STscStmt*)stmt; @@ -2097,8 +2146,6 @@ char *taos_stmt_errstr(TAOS_STMT *stmt) { return taos_errstr(pStmt->pSql); } - - const char *taos_data_type(int type) { switch (type) { case TSDB_DATA_TYPE_NULL: return "TSDB_DATA_TYPE_NULL"; @@ -2115,4 +2162,3 @@ const char *taos_data_type(int type) { default: return "UNKNOWN"; } } - diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index b82bf7bbd520d0649390715952515bdc1f418eae..b2316bf39e950417ee978d3bf3d106084dc320a4 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -101,6 +101,7 @@ static int32_t addProjectionExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQuery static int32_t validateWhereNode(SQueryInfo* pQueryInfo, tSqlExpr** pExpr, SSqlObj* pSql); static int32_t validateFillNode(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SSqlNode* pSqlNode); +static int32_t validateRangeNode(SSqlObj* pSql, SQueryInfo* pQueryInfo, SSqlNode* pSqlNode); static int32_t validateOrderbyNode(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SSqlNode* pSqlNode, SSchema* pSchema); static int32_t tsRewriteFieldNameIfNecessary(SSqlCmd* pCmd, SQueryInfo* pQueryInfo); @@ -116,7 +117,6 @@ static int32_t setKillInfo(SSqlObj* pSql, struct SSqlInfo* pInfo, int32_t killTy static int32_t setCompactVnodeInfo(SSqlObj* pSql, struct SSqlInfo* pInfo); static int32_t validateOneTag(SSqlCmd* pCmd, TAOS_FIELD* pTagField); -static bool hasTimestampForPointInterpQuery(SQueryInfo* pQueryInfo); static bool hasNormalColumnFilter(SQueryInfo* pQueryInfo); static int32_t validateLimitNode(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SSqlNode* pSqlNode, SSqlObj* pSql); @@ -1120,7 +1120,8 @@ int32_t validateIntervalNode(SSqlObj* pSql, SQueryInfo* pQueryInfo, SSqlNode* pS const char* msg1 = "sliding cannot be used without interval"; const char* msg2 = "interval cannot be less than 1 us"; const char* msg3 = "interval value is too small"; - const char* msg4 = "only point interpolation query requires keyword EVERY"; + const char* msg4 = "invalid usage of EVERY"; + const char* msg5 = "EVERY instead of INTERVAL required for interp clause"; SSqlCmd* pCmd = &pSql->cmd; @@ -1132,6 +1133,12 @@ int32_t validateIntervalNode(SSqlObj* pSql, SQueryInfo* pQueryInfo, SSqlNode* pS return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg1); } + bool interpQuery = tscGetPointInterpQuery(pQueryInfo); + + if (interpQuery) { + return addPrimaryTsColumnForTimeWindowQuery(pQueryInfo, pCmd); + } + return TSDB_CODE_SUCCESS; } @@ -1166,11 +1173,15 @@ int32_t validateIntervalNode(SSqlObj* pSql, SQueryInfo* pQueryInfo, SSqlNode* pS return TSDB_CODE_TSC_INVALID_OPERATION; } - bool interpQuery = tscIsPointInterpQuery(pQueryInfo); - if ((pSqlNode->interval.token == TK_EVERY && (!interpQuery)) || (pSqlNode->interval.token == TK_INTERVAL && interpQuery)) { + bool interpQuery = tscGetPointInterpQuery(pQueryInfo); + if (pSqlNode->interval.token == TK_EVERY && (!interpQuery)) { return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg4); } + if (pSqlNode->interval.token == TK_INTERVAL && interpQuery) { + return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg5); + } + // The following part is used to check for the invalid query expression. return checkInvalidExprForTimeWindow(pCmd, pQueryInfo); } @@ -1182,6 +1193,7 @@ static int32_t validateStateWindowNode(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SS const char* msg3 = "not support state_window with group by "; const char* msg4 = "function not support for super table query"; const char* msg5 = "not support state_window on tag column"; + const char* msg6 = "function not support for state_window"; SStrToken *col = &(pSqlNode->windowstateVal.col) ; if (col->z == NULL || col->n <= 0) { @@ -1227,6 +1239,11 @@ static int32_t validateStateWindowNode(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SS return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg2); } + bool interpQuery = tscGetPointInterpQuery(pQueryInfo); + if (interpQuery) { + return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg6); + } + tscColumnListInsert(pQueryInfo->colList, index.columnIndex, pTableMeta->id.uid, pSchema); SColIndex colIndex = { .colIndex = index.columnIndex, .flag = TSDB_COL_NORMAL, .colId = pSchema->colId }; taosArrayPush(pGroupExpr->columnInfo, &colIndex); @@ -1240,6 +1257,7 @@ int32_t validateSessionNode(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SSqlNode * pS const char* msg2 = "only one type time window allowed"; const char* msg3 = "invalid column name"; const char* msg4 = "invalid time window"; + const char* msg5 = "function not support for session"; STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0); STableComInfo tinfo = tscGetTableInfo(pTableMetaInfo->pTableMeta); @@ -1275,6 +1293,11 @@ int32_t validateSessionNode(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SSqlNode * pS return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg3); } + bool interpQuery = tscGetPointInterpQuery(pQueryInfo); + if (interpQuery) { + return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg5); + } + pQueryInfo->sessionWindow.primaryColId = PRIMARYKEY_TIMESTAMP_COL_INDEX; // The following part is used to check for the invalid query expression. @@ -1285,6 +1308,7 @@ int32_t parseIntervalOffset(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SStrToken* of const char* msg1 = "interval offset cannot be negative"; const char* msg2 = "interval offset should be shorter than interval"; const char* msg3 = "cannot use 'year' as offset when interval is 'month'"; + const char* msg4 = "wrong every format"; STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0); STableComInfo tinfo = tscGetTableInfo(pTableMetaInfo->pTableMeta); @@ -1296,6 +1320,11 @@ int32_t parseIntervalOffset(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SStrToken* of return TSDB_CODE_SUCCESS; } + bool interpQuery = tscIsPointInterpQuery(pQueryInfo); + if (interpQuery) { + return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg4); + } + if (parseNatualDuration(t->z, t->n, &pQueryInfo->interval.offset, &pQueryInfo->interval.offsetUnit, tinfo.precision) != TSDB_CODE_SUCCESS) { return TSDB_CODE_TSC_INVALID_OPERATION; @@ -1334,6 +1363,7 @@ int32_t parseSlidingClause(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SStrToken* pSl const char* msg1 = "sliding value no larger than the interval value"; const char* msg2 = "sliding value can not less than 1% of interval value"; const char* msg3 = "does not support sliding when interval is natural month/year"; + const char* msg4 = "sliding not support for interp query"; const static int32_t INTERVAL_SLIDING_FACTOR = 100; @@ -1347,6 +1377,11 @@ int32_t parseSlidingClause(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SStrToken* pSl return TSDB_CODE_SUCCESS; } + bool interpQuery = tscIsPointInterpQuery(pQueryInfo); + if (interpQuery) { + return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg4); + } + if (pInterval->intervalUnit == 'n' || pInterval->intervalUnit == 'y') { return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg3); } @@ -2019,6 +2054,7 @@ int32_t validateSelectNodeList(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SArray* pS const char* msg8 = "not support distinct in nest query"; const char* msg9 = "_block_dist not support subquery, only support stable/table"; const char* msg10 = "not support group by in block func"; + const char* msg11 = "invalid alias name"; // too many result columns not support order by in query if (taosArrayGetSize(pSelNodeList) > TSDB_MAX_COLUMNS) { @@ -2038,9 +2074,12 @@ int32_t validateSelectNodeList(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SArray* pS int32_t outputIndex = (int32_t)tscNumOfExprs(pQueryInfo); tSqlExprItem* pItem = taosArrayGet(pSelNodeList, i); if (hasDistinct == false) { - hasDistinct = (pItem->distinct == true); - distIdx = hasDistinct ? i : -1; - } + hasDistinct = (pItem->distinct == true); + distIdx = hasDistinct ? i : -1; + } + if(pItem->aliasName != NULL && validateColumnName(pItem->aliasName) != TSDB_CODE_SUCCESS){ + return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg11); + } int32_t type = pItem->pNode->type; if (type == SQL_NODE_SQLFUNCTION) { @@ -2346,6 +2385,12 @@ static int32_t setExprInfoForFunctions(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SS invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg1); return -1; } + } else if (f == TSDB_FUNC_INTERP) { + int32_t t1 = pSchema->type; + if (!IS_NUMERIC_TYPE(t1)) { + invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg1); + return -1; + } } int16_t resType = 0; @@ -3181,6 +3226,7 @@ static int16_t doGetColumnIndex(SQueryInfo* pQueryInfo, int32_t index, SStrToken char tmpTokenBuf[TSDB_MAX_BYTES_PER_ROW] = {0}; // create tmp buf to avoid alter orginal sqlstr strncpy(tmpTokenBuf, pToken->z, pToken->n); + pToken->z = tmpTokenBuf; if (pToken->type == TK_ID) { @@ -3498,8 +3544,8 @@ void tscRestoreFuncForSTableQuery(SQueryInfo* pQueryInfo) { } bool hasUnsupportFunctionsForSTableQuery(SSqlCmd* pCmd, SQueryInfo* pQueryInfo) { - const char* msg1 = "TWA/Diff/Derivative/Irate/CSUM/MAVG/SAMPLE are not allowed to apply to super table directly"; - const char* msg2 = "TWA/Diff/Derivative/Irate/CSUM/MAVG/SAMPLE only support group by tbname for super table query"; + const char* msg1 = "TWA/Diff/Derivative/Irate/CSUM/MAVG/SAMPLE/INTERP are not allowed to apply to super table directly"; + const char* msg2 = "TWA/Diff/Derivative/Irate/CSUM/MAVG/SAMPLE/INTERP only support group by tbname for super table query"; const char* msg3 = "functions not support for super table query"; // filter sql function not supported by metric query yet. @@ -3517,7 +3563,7 @@ bool hasUnsupportFunctionsForSTableQuery(SSqlCmd* pCmd, SQueryInfo* pQueryInfo) } if (tscIsTWAQuery(pQueryInfo) || tscIsDiffDerivLikeQuery(pQueryInfo) || tscIsIrateQuery(pQueryInfo) || - tscQueryContainsFunction(pQueryInfo, TSDB_FUNC_SAMPLE)) { + tscQueryContainsFunction(pQueryInfo, TSDB_FUNC_SAMPLE) || tscGetPointInterpQuery(pQueryInfo)) { if (pQueryInfo->groupbyExpr.numOfGroupCols == 0) { invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg1); return true; @@ -3528,6 +3574,11 @@ bool hasUnsupportFunctionsForSTableQuery(SSqlCmd* pCmd, SQueryInfo* pQueryInfo) invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg2); return true; } + + if (tscGetPointInterpQuery(pQueryInfo) && taosArrayGetSize(pQueryInfo->groupbyExpr.columnInfo) > 1) { + invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg2); + return true; + } } else if (tscIsSessionWindowQuery(pQueryInfo)) { invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg3); return true; @@ -3705,6 +3756,10 @@ int32_t validateGroupbyNode(SQueryInfo* pQueryInfo, SArray* pList, SSqlCmd* pCmd SStrToken token = {pVar->nLen, pVar->nType, pVar->pz}; + if (pVar->nType != TSDB_DATA_TYPE_BINARY){ + return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg2); + } + SColumnIndex index = COLUMN_INDEX_INITIALIZER; if (getColumnIndexByName(&token, pQueryInfo, &index, tscGetErrorMsgPayload(pCmd)) != TSDB_CODE_SUCCESS) { return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg2); @@ -4023,7 +4078,7 @@ static int32_t getColQueryCondExpr(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSqlEx UNUSED(code); // TODO: more error handling } END_TRY - + // add to required table column list STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, i); int64_t uid = pTableMetaInfo->pTableMeta->id.uid; @@ -5208,7 +5263,7 @@ static int32_t getTagQueryCondExpr(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SCondE UNUSED(code); // TODO: more error handling } END_TRY - + // add to required table column list STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, i); int64_t uid = pTableMetaInfo->pTableMeta->id.uid; @@ -5417,7 +5472,7 @@ int32_t validateWhereNode(SQueryInfo* pQueryInfo, tSqlExpr** pExpr, SSqlObj* pSq if (taosArrayGetSize(pQueryInfo->pUpstream) > 0 && condExpr.pTimewindow != NULL) { setNormalExprToCond(&condExpr.pColumnCond, condExpr.pTimewindow, TK_AND); - condExpr.pTimewindow = NULL; + condExpr.pTimewindow = tSqlExprClone(condExpr.pTimewindow); } tSqlExprCompact(pExpr); @@ -5600,13 +5655,14 @@ int32_t validateFillNode(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SSqlNode* pSqlNo const char* msg3 = "top/bottom/sample not support fill"; const char* msg4 = "illegal value or data overflow"; const char* msg5 = "fill only available for interval query"; - const char* msg6 = "not supported function now"; const char* msg7 = "join query not supported fill operation"; - if ((!isTimeWindowQuery(pQueryInfo)) && (!tscIsPointInterpQuery(pQueryInfo))) { + bool pointInterp = tscIsPointInterpQuery(pQueryInfo); + if ((!isTimeWindowQuery(pQueryInfo)) && (!pointInterp)) { return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg5); } - if(QUERY_IS_JOIN_QUERY(pQueryInfo->type)) { + + if (QUERY_IS_JOIN_QUERY(pQueryInfo->type) && (!pointInterp)) { return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg7); } @@ -5614,11 +5670,10 @@ int32_t validateFillNode(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SSqlNode* pSqlNo * fill options are set at the end position, when all columns are set properly * the columns may be increased due to group by operation */ - if (checkQueryRangeForFill(pCmd, pQueryInfo) != TSDB_CODE_SUCCESS) { + if ((!pointInterp) && checkQueryRangeForFill(pCmd, pQueryInfo) != TSDB_CODE_SUCCESS) { return TSDB_CODE_TSC_INVALID_OPERATION; } - if (pItem->pVar.nType != TSDB_DATA_TYPE_BINARY) { return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg2); } @@ -5643,9 +5698,6 @@ int32_t validateFillNode(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SSqlNode* pSqlNo } } else if (strncasecmp(pItem->pVar.pz, "prev", 4) == 0 && pItem->pVar.nLen == 4) { pQueryInfo->fillType = TSDB_FILL_PREV; - if (tscIsPointInterpQuery(pQueryInfo) && pQueryInfo->order.order == TSDB_ORDER_DESC) { - return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg6); - } } else if (strncasecmp(pItem->pVar.pz, "next", 4) == 0 && pItem->pVar.nLen == 4) { pQueryInfo->fillType = TSDB_FILL_NEXT; } else if (strncasecmp(pItem->pVar.pz, "linear", 6) == 0 && pItem->pVar.nLen == 6) { @@ -5662,7 +5714,7 @@ int32_t validateFillNode(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SSqlNode* pSqlNo int32_t numOfFillVal = (int32_t)(num - 1); /* for point interpolation query, we do not have the timestamp column */ - if (tscIsPointInterpQuery(pQueryInfo)) { + if (pointInterp) { startPos = 0; if (numOfFillVal > numOfFields) { @@ -5689,7 +5741,7 @@ int32_t validateFillNode(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SSqlNode* pSqlNo } } - if ((num < numOfFields) || ((num - 1 < numOfFields) && (tscIsPointInterpQuery(pQueryInfo)))) { + if ((num < numOfFields) || ((num - 1 < numOfFields) && pointInterp)) { tVariantListItem* lastItem = taosArrayGetLast(pFillToken); for (int32_t i = numOfFillVal; i < numOfFields; ++i) { @@ -5718,6 +5770,55 @@ int32_t validateFillNode(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SSqlNode* pSqlNo return TSDB_CODE_SUCCESS; } + + +int32_t validateRangeNode(SSqlObj* pSql, SQueryInfo* pQueryInfo, SSqlNode* pSqlNode) { + const char *msg0 = "invalid usage of range clause"; + const char* msg1 = "invalid timestamp in range"; + SSqlCmd* pCmd = &pSql->cmd; + + bool interpQuery = tscIsPointInterpQuery(pQueryInfo); + + if ((!interpQuery) && (pSqlNode->pRange.start || pSqlNode->pRange.end)) { + return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg0); + } + + if (pSqlNode->pRange.start == NULL || pSqlNode->pRange.end == NULL) { + pQueryInfo->range.skey = INT64_MIN; + pQueryInfo->range.ekey = INT64_MIN; + + tscDebug("0x%"PRIx64" range [%"PRId64",%"PRId64"], ts [%"PRId64",%"PRId64"]", pSql->self, pQueryInfo->range.skey, pQueryInfo->range.ekey, pQueryInfo->window.skey, pQueryInfo->window.ekey); + return TSDB_CODE_SUCCESS; + } + + STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0); + STableComInfo tinfo = tscGetTableInfo(pTableMetaInfo->pTableMeta); + + if (getTimeRange(&pQueryInfo->range, pSqlNode->pRange.start, TK_GE, tinfo.precision) != TSDB_CODE_SUCCESS) { + return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg1); + } + + if (getTimeRange(&pQueryInfo->range, pSqlNode->pRange.end, TK_LE, tinfo.precision) != TSDB_CODE_SUCCESS) { + return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg1); + } + + if (pQueryInfo->range.ekey < pQueryInfo->range.skey) { + return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg1); + } + + if ((pQueryInfo->range.skey > pQueryInfo->window.ekey && (pQueryInfo->fillType == TSDB_FILL_NONE || pQueryInfo->fillType == TSDB_FILL_LINEAR || pQueryInfo->fillType == TSDB_FILL_NEXT)) + || (pQueryInfo->range.ekey < pQueryInfo->window.skey && (pQueryInfo->fillType == TSDB_FILL_NONE || pQueryInfo->fillType == TSDB_FILL_LINEAR || pQueryInfo->fillType == TSDB_FILL_PREV))) { + tscDebug("0x%"PRIx64" range [%"PRId64",%"PRId64"], ts [%"PRId64",%"PRId64"], no output result", pSql->self, pQueryInfo->range.skey, pQueryInfo->range.ekey, pQueryInfo->window.skey, pQueryInfo->window.ekey); + pQueryInfo->command = TSDB_SQL_RETRIEVE_EMPTY_RESULT; + return TSDB_CODE_SUCCESS; + } + + tscDebug("0x%"PRIx64" range [%"PRId64",%"PRId64"], ts [%"PRId64",%"PRId64"]", pSql->self, pQueryInfo->range.skey, pQueryInfo->range.ekey, pQueryInfo->window.skey, pQueryInfo->window.ekey); + + return TSDB_CODE_SUCCESS; +} + + static void setDefaultOrderInfo(SQueryInfo* pQueryInfo) { /* set default timestamp order information for all queries */ STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0); @@ -6070,14 +6171,19 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) { STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, DEFAULT_TABLE_INDEX); bool dbIncluded = false; - if (tscValidateName(&(pAlterSQL->name), true, &dbIncluded) != TSDB_CODE_SUCCESS) { + SStrToken tmpToken = pAlterSQL->name; + tmpToken.z= strndup(pAlterSQL->name.z, pAlterSQL->name.n); + if (tscValidateName(&tmpToken, true, &dbIncluded) != TSDB_CODE_SUCCESS) { + free(tmpToken.z); return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg1); } - code = tscSetTableFullName(&pTableMetaInfo->name, &(pAlterSQL->name), pSql, dbIncluded); + code = tscSetTableFullName(&pTableMetaInfo->name, &tmpToken, pSql, dbIncluded); if (code != TSDB_CODE_SUCCESS) { + free(tmpToken.z); return code; } + free(tmpToken.z); code = tscGetTableMeta(pSql, pTableMetaInfo); if (code != TSDB_CODE_SUCCESS) { @@ -6692,18 +6798,6 @@ int32_t validateColumnName(char* name) { return TSDB_CODE_SUCCESS; } -bool hasTimestampForPointInterpQuery(SQueryInfo* pQueryInfo) { - if (!tscIsPointInterpQuery(pQueryInfo)) { - return true; - } - - if (pQueryInfo->window.skey == INT64_MIN || pQueryInfo->window.ekey == INT64_MAX) { - return false; - } - - return !(pQueryInfo->window.skey != pQueryInfo->window.ekey && pQueryInfo->interval.interval == 0); -} - int32_t validateLimitNode(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SSqlNode* pSqlNode, SSqlObj* pSql) { STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0); @@ -7185,7 +7279,7 @@ static int32_t checkUpdateTagPrjFunctions(SQueryInfo* pQueryInfo, char* msg) { continue; } - if ((functionId == TSDB_FUNC_LAST_ROW) || + if ((functionId == TSDB_FUNC_LAST_ROW) || (functionId == TSDB_FUNC_INTERP) || (functionId == TSDB_FUNC_LAST_DST && (pExpr->base.colInfo.flag & TSDB_COL_NULL) != 0)) { // do nothing } else { @@ -7441,6 +7535,10 @@ int32_t doFunctionsCompatibleCheck(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, char* int32_t validateFunctionFromUpstream(SQueryInfo* pQueryInfo, char* msg) { const char* msg1 = "TWA/Diff/Derivative/Irate are not allowed to apply to super table without group by tbname"; + const char* msg2 = "group by not supported in nested interp query"; + const char* msg3 = "order by not supported in nested interp query"; + const char* msg4 = "first column should be timestamp for interp query"; + const char* msg5 = "interp input may be invalid"; int32_t numOfExprs = (int32_t)tscNumOfExprs(pQueryInfo); size_t upNum = taosArrayGetSize(pQueryInfo->pUpstream); @@ -7460,6 +7558,54 @@ int32_t validateFunctionFromUpstream(SQueryInfo* pQueryInfo, char* msg) { } return invalidOperationMsg(msg, msg1); + } else if (f == TSDB_FUNC_INTERP) { + if (pQueryInfo->groupbyExpr.columnInfo) { + return invalidOperationMsg(msg, msg2); + } + + if (pQueryInfo->order.order == TSDB_ORDER_DESC || (pQueryInfo->order.orderColId != INT32_MIN && pQueryInfo->order.orderColId != PRIMARYKEY_TIMESTAMP_COL_INDEX)) { + return invalidOperationMsg(msg, msg3); + } + + for (int32_t j = 0; j < upNum; ++j) { + SQueryInfo* pUp = taosArrayGetP(pQueryInfo->pUpstream, j); + if (pUp->groupbyExpr.columnInfo) { + return invalidOperationMsg(msg, msg2); + } + + if (pUp->order.order == TSDB_ORDER_DESC || (pUp->order.orderColId != INT32_MIN && pUp->order.orderColId != PRIMARYKEY_TIMESTAMP_COL_INDEX)) { + return invalidOperationMsg(msg, msg3); + } + + int32_t exprNum = (int32_t)taosArrayGetSize(pUp->exprList); + if (exprNum > 0) { + SSqlExpr* expr = taosArrayGetP(pUp->exprList, 0); + if (expr->resType != TSDB_DATA_TYPE_TIMESTAMP) { + return invalidOperationMsg(msg, msg4); + } + + STableMetaInfo *pTableMetaInfo = tscGetMetaInfo(pUp, 0); + bool isSTable = UTIL_TABLE_IS_SUPER_TABLE(pTableMetaInfo); + if (!isSTable) { + continue; + } + + if (TSDB_QUERY_HAS_TYPE(pUp->type, TSDB_QUERY_TYPE_PROJECTION_QUERY)) { + return invalidOperationMsg(msg, msg5); + } + + for (int32_t n = 0; n < exprNum; ++n) { + expr = taosArrayGetP(pUp->exprList, n); + if (expr->functionId == TSDB_FUNC_TOP || + expr->functionId == TSDB_FUNC_BOTTOM || + expr->functionId == TSDB_FUNC_SAMPLE) { + if (expr->param[0].i64 > 1) { + return invalidOperationMsg(msg, msg5); + } + } + } + } + } } } @@ -8919,7 +9065,6 @@ static int32_t doValidateSubquery(SSqlNode* pSqlNode, int32_t index, SSqlObj* pS int32_t validateSqlNode(SSqlObj* pSql, SSqlNode* pSqlNode, SQueryInfo* pQueryInfo) { assert(pSqlNode != NULL && (pSqlNode->from == NULL || taosArrayGetSize(pSqlNode->from->list) > 0)); - const char* msg1 = "point interpolation query needs timestamp"; 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"; @@ -8989,7 +9134,7 @@ int32_t validateSqlNode(SSqlObj* pSql, SSqlNode* pSqlNode, SQueryInfo* pQueryInf 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 || f == TSDB_FUNC_INTERP) { + if (f == TSDB_FUNC_STDDEV || f == TSDB_FUNC_PERCT) { return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg6); } @@ -9092,6 +9237,10 @@ int32_t validateSqlNode(SSqlObj* pSql, SSqlNode* pSqlNode, SQueryInfo* pQueryInf if ((code = validateFillNode(pCmd, pQueryInfo, pSqlNode)) != TSDB_CODE_SUCCESS) { return code; } + + if ((code = validateRangeNode(pSql, pQueryInfo, pSqlNode)) != TSDB_CODE_SUCCESS) { + return code; + } } else { pQueryInfo->command = TSDB_SQL_SELECT; @@ -9199,10 +9348,6 @@ int32_t validateSqlNode(SSqlObj* pSql, SSqlNode* pSqlNode, SQueryInfo* pQueryInf return TSDB_CODE_SUCCESS; } - if (!hasTimestampForPointInterpQuery(pQueryInfo)) { - return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg1); - } - // in case of join query, time range is required. if (QUERY_IS_JOIN_QUERY(pQueryInfo->type)) { uint64_t timeRange = (uint64_t)pQueryInfo->window.ekey - pQueryInfo->window.skey; @@ -9226,6 +9371,11 @@ int32_t validateSqlNode(SSqlObj* pSql, SSqlNode* pSqlNode, SQueryInfo* pQueryInf if ((code = validateFillNode(pCmd, pQueryInfo, pSqlNode)) != TSDB_CODE_SUCCESS) { return code; } + + if ((code = validateRangeNode(pSql, pQueryInfo, pSqlNode)) != TSDB_CODE_SUCCESS) { + return code; + } + } { // set the query info diff --git a/src/client/src/tscServer.c b/src/client/src/tscServer.c index 0eba04ffb2e500e0d7a0ab6f005a217b6027f41c..52a918bbe22589d85fc89cbff8249065129f1618 100644 --- a/src/client/src/tscServer.c +++ b/src/client/src/tscServer.c @@ -916,7 +916,9 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) { pQueryMsg->window.skey = htobe64(query.window.skey); pQueryMsg->window.ekey = htobe64(query.window.ekey); - + pQueryMsg->range.skey = htobe64(query.range.skey); + pQueryMsg->range.ekey = htobe64(query.range.ekey); + pQueryMsg->order = htons(query.order.order); pQueryMsg->orderColId = htons(query.order.orderColId); pQueryMsg->fillType = htons(query.fillType); @@ -975,7 +977,7 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) { if (pQueryInfo->colCond && taosArrayGetSize(pQueryInfo->colCond) > 0 && !onlyQueryTags(&query) ) { STblCond *pCond = tsGetTableFilter(pQueryInfo->colCond, pTableMeta->id.uid, 0); if (pCond != NULL && pCond->cond != NULL) { - pQueryMsg->colCondLen = htons(pCond->len); + pQueryMsg->colCondLen = htonl(pCond->len); memcpy(pMsg, pCond->cond, pCond->len); pMsg += pCond->len; @@ -1056,7 +1058,7 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) { SCond *pCond = tsGetSTableQueryCond(pTagCond, pTableMeta->id.uid); if (pCond != NULL && pCond->cond != NULL) { - pQueryMsg->tagCondLen = htons(pCond->len); + pQueryMsg->tagCondLen = htonl(pCond->len); memcpy(pMsg, pCond->cond, pCond->len); pMsg += pCond->len; diff --git a/src/client/src/tscSub.c b/src/client/src/tscSub.c index 5e70c814133fd93b7619022a1d564050c3c0502a..5a26397c5a260f8ee527a05bbfc700b53a23951c 100644 --- a/src/client/src/tscSub.c +++ b/src/client/src/tscSub.c @@ -468,7 +468,7 @@ SSqlObj* recreateSqlObj(SSub* pSub) { } registerSqlObj(pSql); - + pSql->rootObj = pSql; code = tsParseSql(pSql, true); if (code == TSDB_CODE_TSC_ACTION_IN_PROGRESS) { tsem_wait(&pSub->sem); diff --git a/src/client/src/tscSubquery.c b/src/client/src/tscSubquery.c index f5702b4e35d69ced9bf024285f86dfb306900a60..2412b8336efbcf289fc4d2e11796b01b02f8174d 100644 --- a/src/client/src/tscSubquery.c +++ b/src/client/src/tscSubquery.c @@ -394,6 +394,12 @@ SJoinSupporter* tscCreateJoinSupporter(SSqlObj* pSql, int32_t index) { memcpy(&pSupporter->interval, &pQueryInfo->interval, sizeof(pSupporter->interval)); pSupporter->limit = pQueryInfo->limit; + if (tscIsPointInterpQuery(pQueryInfo)) { + pSupporter->fillType = pQueryInfo->fillType; + pSupporter->fillVal = pQueryInfo->fillVal; + pSupporter->numOfFillVal = pQueryInfo->numOfFillVal; + } + STableMetaInfo* pTableMetaInfo = tscGetTableMetaInfoFromCmd(&pSql->cmd, index); pSupporter->uid = pTableMetaInfo->pTableMeta->id.uid; assert (pSupporter->uid != 0); @@ -579,6 +585,13 @@ static int32_t tscLaunchRealSubqueries(SSqlObj* pSql) { pQueryInfo->fieldsInfo = pSupporter->fieldsInfo; pQueryInfo->groupbyExpr = pSupporter->groupInfo; pQueryInfo->pUpstream = taosArrayInit(4, sizeof(POINTER_BYTES)); + + if (tscIsPointInterpQuery(pQueryInfo)) { + pQueryInfo->fillType = pSupporter->fillType; + pQueryInfo->numOfFillVal = pSupporter->numOfFillVal; + pQueryInfo->fillVal = malloc(pQueryInfo->numOfFillVal * sizeof(*pSupporter->fillVal)); + memcpy(pQueryInfo->fillVal, pSupporter->fillVal, sizeof(*pSupporter->fillVal) * pQueryInfo->numOfFillVal); + } assert(pNew->subState.numOfSub == 0 && pQueryInfo->numOfTables == 1); diff --git a/src/client/src/tscUtil.c b/src/client/src/tscUtil.c index b03aef9e188b96d2bd3203720317a68f81c0a960..50b9a8fd7eea703dffe34f8ad5eb204b310f0d7e 100644 --- a/src/client/src/tscUtil.c +++ b/src/client/src/tscUtil.c @@ -187,7 +187,7 @@ bool tscQueryTags(SQueryInfo* pQueryInfo) { continue; } - if (functId != TSDB_FUNC_TAGPRJ && functId != TSDB_FUNC_TID_TAG) { + if (functId != TSDB_FUNC_TAGPRJ && functId != TSDB_FUNC_TID_TAG && functId != TSDB_FUNC_BLKINFO) { return false; } } @@ -367,7 +367,7 @@ bool tscIsPointInterpQuery(SQueryInfo* pQueryInfo) { assert(pExpr != NULL); int32_t functionId = pExpr->base.functionId; - if (functionId == TSDB_FUNC_TAG || functionId == TSDB_FUNC_TS) { + if (functionId == TSDB_FUNC_TAG || functionId == TSDB_FUNC_TAG_DUMMY || functionId == TSDB_FUNC_TS || functionId == TSDB_FUNC_TS_DUMMY) { continue; } @@ -379,6 +379,23 @@ bool tscIsPointInterpQuery(SQueryInfo* pQueryInfo) { return true; } +bool tscGetPointInterpQuery(SQueryInfo* pQueryInfo) { + size_t size = tscNumOfExprs(pQueryInfo); + for (int32_t i = 0; i < size; ++i) { + SExprInfo* pExpr = tscExprGet(pQueryInfo, i); + assert(pExpr != NULL); + + int32_t functionId = pExpr->base.functionId; + + if (functionId == TSDB_FUNC_INTERP) { + return true; + } + } + + return false; +} + + bool tsIsArithmeticQueryOnAggResult(SQueryInfo* pQueryInfo) { if (tscIsProjectionQuery(pQueryInfo)) { return false; @@ -942,23 +959,30 @@ SSDataBlock* doGetDataBlock(void* param, bool* newgroup) { pBlock->info.rows = pRes->numOfRows; if (pRes->numOfRows != 0) { doSetupSDataBlock(pRes, pBlock, pInput->pFilterInfo); - *newgroup = false; - return pBlock; + if (pBlock->info.rows > 0) { + *newgroup = false; + return pBlock; + } } - // No data block exists. So retrieve and transfer it into to SSDataBlock - TAOS_ROW pRow = NULL; - taos_fetch_block(pSql, &pRow); + SSDataBlock* result = NULL; + do { + // No data block exists. So retrieve and transfer it into to SSDataBlock + TAOS_ROW pRow = NULL; + taos_fetch_block(pSql, &pRow); - if (pRes->numOfRows == 0) { - pOperator->status = OP_EXEC_DONE; - return NULL; - } + if (pRes->numOfRows == 0) { + pOperator->status = OP_EXEC_DONE; + result = NULL; + break; + } + pBlock->info.rows = pRes->numOfRows; + doSetupSDataBlock(pRes, pBlock, pInput->pFilterInfo); + *newgroup = false; + result = pBlock; + } while (result->info.rows == 0); - pBlock->info.rows = pRes->numOfRows; - doSetupSDataBlock(pRes, pBlock, pInput->pFilterInfo); - *newgroup = false; - return pBlock; + return result; } static void fetchNextBlockIfCompleted(SOperatorInfo* pOperator, bool* newgroup) { @@ -1838,6 +1862,32 @@ int32_t tscCreateDataBlock(size_t defaultSize, int32_t rowSize, int32_t startOff return TSDB_CODE_TSC_OUT_OF_MEMORY; } + int32_t code = tscCreateDataBlockData(dataBuf, defaultSize, rowSize, startOffset); + if (code != TSDB_CODE_SUCCESS) { + tfree(dataBuf); + return code; + } + + //Here we keep the tableMeta to avoid it to be remove by other threads. + dataBuf->pTableMeta = tscTableMetaDup(pTableMeta); + + SParsedDataColInfo* pColInfo = &dataBuf->boundColumnInfo; + SSchema* pSchema = tscGetTableSchema(dataBuf->pTableMeta); + tscSetBoundColumnInfo(pColInfo, pSchema, dataBuf->pTableMeta->tableInfo.numOfColumns); + + dataBuf->vgId = dataBuf->pTableMeta->vgId; + + tNameAssign(&dataBuf->tableName, name); + + assert(defaultSize > 0 && pTableMeta != NULL && dataBuf->pTableMeta != NULL); + + *dataBlocks = dataBuf; + return TSDB_CODE_SUCCESS; +} + +int32_t tscCreateDataBlockData(STableDataBlocks* dataBuf, size_t defaultSize, int32_t rowSize, int32_t startOffset) { + assert(dataBuf != NULL); + dataBuf->nAllocSize = (uint32_t)defaultSize; dataBuf->headerSize = startOffset; @@ -1850,30 +1900,16 @@ int32_t tscCreateDataBlock(size_t defaultSize, int32_t rowSize, int32_t startOff dataBuf->pData = malloc(dataBuf->nAllocSize); if (dataBuf->pData == NULL) { tscError("failed to allocated memory, reason:%s", strerror(errno)); - tfree(dataBuf); return TSDB_CODE_TSC_OUT_OF_MEMORY; } memset(dataBuf->pData, 0, sizeof(SSubmitBlk)); - //Here we keep the tableMeta to avoid it to be remove by other threads. - dataBuf->pTableMeta = tscTableMetaDup(pTableMeta); - - SParsedDataColInfo* pColInfo = &dataBuf->boundColumnInfo; - SSchema* pSchema = tscGetTableSchema(dataBuf->pTableMeta); - tscSetBoundColumnInfo(pColInfo, pSchema, dataBuf->pTableMeta->tableInfo.numOfColumns); - dataBuf->ordered = true; dataBuf->prevTS = INT64_MIN; dataBuf->rowSize = rowSize; dataBuf->size = startOffset; dataBuf->tsSource = -1; - dataBuf->vgId = dataBuf->pTableMeta->vgId; - - tNameAssign(&dataBuf->tableName, name); - assert(defaultSize > 0 && pTableMeta != NULL && dataBuf->pTableMeta != NULL); - - *dataBlocks = dataBuf; return TSDB_CODE_SUCCESS; } @@ -2953,6 +2989,11 @@ int32_t tscValidateName(SStrToken* pToken, bool escapeEnabled, bool *dbIncluded) } } else if (pToken->type == TK_ID) { tscRmEscapeAndTrimToken(pToken); + + if (pToken->n == 0) { + return TSDB_CODE_TSC_INVALID_OPERATION; + } + return TSDB_CODE_SUCCESS; } else { if (isNumber(pToken)) { @@ -3417,7 +3458,7 @@ int32_t tscQueryInfoCopy(SQueryInfo* pQueryInfo, const SQueryInfo* pSrc) { pQueryInfo->clauseLimit = pSrc->clauseLimit; pQueryInfo->prjOffset = pSrc->prjOffset; pQueryInfo->numOfTables = 0; - pQueryInfo->window = pSrc->window; + pQueryInfo->range = pSrc->range; pQueryInfo->sessionWindow = pSrc->sessionWindow; pQueryInfo->pTableMetaInfo = NULL; pQueryInfo->multigroupResult = pSrc->multigroupResult; @@ -3810,6 +3851,7 @@ SSqlObj* createSubqueryObj(SSqlObj* pSql, int16_t tableIndex, __async_cb_func_t memcpy(&pNewQueryInfo->interval, &pQueryInfo->interval, sizeof(pNewQueryInfo->interval)); pNewQueryInfo->type = pQueryInfo->type; pNewQueryInfo->window = pQueryInfo->window; + pNewQueryInfo->range = pQueryInfo->range; pNewQueryInfo->limit = pQueryInfo->limit; pNewQueryInfo->slimit = pQueryInfo->slimit; pNewQueryInfo->order = pQueryInfo->order; @@ -5029,6 +5071,7 @@ int32_t tscCreateQueryFromQueryInfo(SQueryInfo* pQueryInfo, SQueryAttr* pQueryAt pQueryAttr->fillType = pQueryInfo->fillType; pQueryAttr->havingNum = pQueryInfo->havingFieldNum; pQueryAttr->pUdfInfo = pQueryInfo->pUdfInfo; + pQueryAttr->range = pQueryInfo->range; if (pQueryInfo->order.order == TSDB_ORDER_ASC) { // TODO refactor pQueryAttr->window = pQueryInfo->window; @@ -5328,4 +5371,3 @@ char* cloneCurrentDBName(SSqlObj* pSql) { return p; } - diff --git a/src/common/src/tdataformat.c b/src/common/src/tdataformat.c index bdb4e743a0db92074bdfd45431619019725be2c7..bce9474b6d4fb9f783947ba2e27382d8c1d46429 100644 --- a/src/common/src/tdataformat.c +++ b/src/common/src/tdataformat.c @@ -253,9 +253,10 @@ int dataColAppendVal(SDataCol *pCol, const void *value, int numOfRows, int maxPo } if(tdAllocMemForCol(pCol, maxPoints) < 0) return -1; - if (numOfRows > 0) { + + if (((rowOffset == 0) && (numOfRows > 0)) || ((rowOffset == -1) && (numOfRows >= 0))) { // Find the first not null value, fill all previouse values as NULL - dataColSetNEleNull(pCol, numOfRows); + dataColSetNEleNull(pCol, numOfRows - rowOffset); } } @@ -463,9 +464,7 @@ static void tdAppendDataRowToDataCol(SDataRow row, STSchema *pSchema, SDataCols int rcol = 0; int dcol = 0; - while (dcol < pCols->numOfCols) { - bool setCol = 0; SDataCol *pDataCol = &(pCols->cols[dcol]); if (rcol >= schemaNCols(pSchema)) { dataColAppendVal(pDataCol, getNullValue(pDataCol->type), pCols->numOfRows, pCols->maxPoints, rowOffset); @@ -476,14 +475,22 @@ static void tdAppendDataRowToDataCol(SDataRow row, STSchema *pSchema, SDataCols STColumn *pRowCol = schemaColAt(pSchema, rcol); if (pRowCol->colId == pDataCol->colId) { void *value = tdGetRowDataOfCol(row, pRowCol->type, pRowCol->offset + TD_DATA_ROW_HEAD_SIZE); - if(!isNull(value, pDataCol->type)) setCol = 1; - dataColAppendVal(pDataCol, value, pCols->numOfRows, pCols->maxPoints, rowOffset); + if (rowOffset == 0) { + dataColAppendVal(pDataCol, value, pCols->numOfRows, pCols->maxPoints, rowOffset); + } else if (rowOffset == -1) { + // for update 2 + if (!isNull(value, pDataCol->type)) { + dataColAppendVal(pDataCol, value, pCols->numOfRows, pCols->maxPoints, rowOffset); + } + } else { + ASSERT(0); + } dcol++; rcol++; } else if (pRowCol->colId < pDataCol->colId) { rcol++; } else { - if(forceSetNull || setCol) { + if(forceSetNull) { dataColAppendVal(pDataCol, getNullValue(pDataCol->type), pCols->numOfRows, pCols->maxPoints, rowOffset); } dcol++; @@ -501,7 +508,6 @@ static void tdAppendKvRowToDataCol(SKVRow row, STSchema *pSchema, SDataCols *pCo int nRowCols = kvRowNCols(row); while (dcol < pCols->numOfCols) { - bool setCol = 0; SDataCol *pDataCol = &(pCols->cols[dcol]); if (rcol >= nRowCols || rcol >= schemaNCols(pSchema)) { dataColAppendVal(pDataCol, getNullValue(pDataCol->type), pCols->numOfRows, pCols->maxPoints, rowOffset); @@ -513,14 +519,22 @@ static void tdAppendKvRowToDataCol(SKVRow row, STSchema *pSchema, SDataCols *pCo if (colIdx->colId == pDataCol->colId) { void *value = tdGetKvRowDataOfCol(row, colIdx->offset); - if(!isNull(value, pDataCol->type)) setCol = 1; - dataColAppendVal(pDataCol, value, pCols->numOfRows, pCols->maxPoints, rowOffset); + if (rowOffset == 0) { + dataColAppendVal(pDataCol, value, pCols->numOfRows, pCols->maxPoints, rowOffset); + } else if (rowOffset == -1) { + // for update 2 + if (!isNull(value, pDataCol->type)) { + dataColAppendVal(pDataCol, value, pCols->numOfRows, pCols->maxPoints, rowOffset); + } + } else { + ASSERT(0); + } ++dcol; ++rcol; } else if (colIdx->colId < pDataCol->colId) { ++rcol; } else { - if(forceSetNull || setCol) { + if (forceSetNull) { dataColAppendVal(pDataCol, getNullValue(pDataCol->type), pCols->numOfRows, pCols->maxPoints, rowOffset); } ++dcol; diff --git a/src/common/src/tglobal.c b/src/common/src/tglobal.c index c1a254b4ebd5fdfe1d29e02ab7cacbe3195058f1..f13a35f0b9ae287f04cccf1785fce77f8d5c0678 100644 --- a/src/common/src/tglobal.c +++ b/src/common/src/tglobal.c @@ -73,7 +73,7 @@ int32_t tsMaxBinaryDisplayWidth = 30; * -1: all data are not compressed * other values: if the message payload size is greater than the tsCompressMsgSize, the message will be compressed. */ -int32_t tsCompressMsgSize = -1; +int32_t tsCompressMsgSize = 512 * 1024; /* denote if server needs to compress the retrieved column data before adding to the rpc response message body. * 0: all data are compressed @@ -289,7 +289,7 @@ char Compressor[32] = "ZSTD_COMPRESSOR"; // ZSTD_COMPRESSOR or GZIP_COMPRES int8_t tsDeadLockKillQuery = 0; // default JSON string type -char tsDefaultJSONStrType[7] = "binary"; +char tsDefaultJSONStrType[7] = "nchar"; char tsSmlChildTableName[TSDB_TABLE_NAME_LEN] = ""; //user defined child table name can be specified in tag value. If set to empty system will generate table name using MD5 hash. int32_t (*monStartSystemFp)() = NULL; diff --git a/src/connector/C#/TDengineDriver.cs b/src/connector/C#/TDengineDriver.cs index e6c3a598adc0bc4bcf5ea84953f649b418199555..f9a5890eedb8714616cb4d624f9036ffdeef35fb 100644 --- a/src/connector/C#/TDengineDriver.cs +++ b/src/connector/C#/TDengineDriver.cs @@ -163,8 +163,12 @@ namespace TDengineDriver [DllImport("taos", EntryPoint = "taos_close", CallingConvention = CallingConvention.Cdecl)] static extern public int Close(IntPtr taos); - //get precisionin parameter restultset + //get precision in restultset [DllImport("taos", EntryPoint = "taos_result_precision", CallingConvention = CallingConvention.Cdecl)] static extern public int ResultPrecision(IntPtr taos); + + //schemaless API + [DllImport("taos",SetLastError = true, EntryPoint = "taos_schemaless_insert", CallingConvention = CallingConvention.Cdecl)] + static extern public IntPtr SchemalessInsert(IntPtr taos, string[] lines, int numLines, int protocol, int precision); } } diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/AbstractConnection.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/AbstractConnection.java index 67652b1c7ada63a8336fdc44dc9814f0a266c086..c992cf58ba43eb0e052d9bc80824d94e98b725ca 100644 --- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/AbstractConnection.java +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/AbstractConnection.java @@ -413,8 +413,7 @@ public abstract class AbstractConnection extends WrapperImpl implements Connecti status = future.get(); else status = future.get(timeout, TimeUnit.SECONDS); - } catch (InterruptedException | ExecutionException e) { - e.printStackTrace(); + } catch (InterruptedException | ExecutionException ignored) { } catch (TimeoutException e) { future.cancel(true); status = false; 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 f6ec70fbac555b97b2cb342edfaa5fde56245c5a..6343a802af280415b4d21f56476eb4403b4608ac 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 @@ -597,7 +597,7 @@ public abstract class AbstractDatabaseMetaData extends WrapperImpl implements Da return col4; } - public ResultSet getSchemas() throws SQLException { + public ResultSet getSchemas() { return getEmptyResultSet(); } @@ -629,7 +629,7 @@ 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) { + protected ResultSet getColumns(String catalog, String schemaPattern, String tableNamePattern, String columnNamePattern, Connection conn) throws SQLException { if (catalog == null || catalog.isEmpty()) return null; if (!isAvailableCatalog(conn, catalog)) @@ -682,8 +682,6 @@ public abstract class AbstractDatabaseMetaData extends WrapperImpl implements Da rowIndex++; } resultSet.setRowDataList(rowDataList); - } catch (SQLException e) { - e.printStackTrace(); } return resultSet; } @@ -1220,7 +1218,7 @@ public abstract class AbstractDatabaseMetaData extends WrapperImpl implements Da return col6; } - private boolean isAvailableCatalog(Connection connection, String catalog) { + private boolean isAvailableCatalog(Connection connection, String catalog) throws SQLException { try (Statement stmt = connection.createStatement(); ResultSet databases = stmt.executeQuery("show databases")) { while (databases.next()) { @@ -1229,8 +1227,6 @@ public abstract class AbstractDatabaseMetaData extends WrapperImpl implements Da if (dbname.equalsIgnoreCase(catalog)) return true; } - } catch (SQLException e) { - e.printStackTrace(); } return false; } 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 a5c7f26a266f81e3a7915503d2983efe077765c2..ee2c8141a81bb9dc2aa51ba14247dfbb834ec746 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 @@ -21,6 +21,7 @@ import com.taosdata.jdbc.enums.SchemalessProtocolType; import com.taosdata.jdbc.enums.SchemalessTimestampType; import com.taosdata.jdbc.utils.TaosInfo; +import java.io.UnsupportedEncodingException; import java.nio.ByteBuffer; import java.sql.SQLException; import java.sql.SQLWarning; @@ -107,8 +108,7 @@ public class TSDBJNIConnector { try { pSql = this.executeQueryImp(sql.getBytes(TaosGlobalConfig.getCharset()), this.taos); taosInfo.stmt_count_increment(); - } catch (Exception e) { - e.printStackTrace(); + } catch (UnsupportedEncodingException e) { this.freeResultSetImp(this.taos, pSql); throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_ENCODING); } 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 42ebedf4027b0e333b9e79b8045f1bae0d338ac7..5fd8f181388824bccd4a2ab2b488667af117b172 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 @@ -611,7 +611,7 @@ public class TSDBPreparedStatement extends TSDBStatement implements PreparedStat try { this.tagValueLength += value.getBytes(charset).length; } catch (UnsupportedEncodingException e) { - e.printStackTrace(); + throw new RuntimeException(e.getMessage()); } } @@ -786,7 +786,7 @@ public class TSDBPreparedStatement extends TSDBStatement implements PreparedStat b = val.getBytes(charset); } } catch (UnsupportedEncodingException e) { - e.printStackTrace(); + throw new RuntimeException(e.getMessage()); } tagDataList.put(b); @@ -921,7 +921,7 @@ public class TSDBPreparedStatement extends TSDBStatement implements PreparedStat b = val.getBytes(charset); } } catch (UnsupportedEncodingException e) { - e.printStackTrace(); + throw new RuntimeException(e.getMessage()); } if (val.length() > col1.bytes) { @@ -980,8 +980,10 @@ public class TSDBPreparedStatement extends TSDBStatement implements PreparedStat @Override public void close() throws SQLException { - this.columnDataClearBatchInternal(); - this.columnDataCloseBatch(); + if (this.nativeStmtHandle != 0L) { + this.columnDataClearBatchInternal(); + this.columnDataCloseBatch(); + } super.close(); } } diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBResultSetBlockData.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBResultSetBlockData.java index ff49677b01fa1c3a4d482cebd51269d5f1589e43..e404db64e3dffbdcc0d2c2845279723874f6b5d8 100644 --- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBResultSetBlockData.java +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBResultSetBlockData.java @@ -92,75 +92,71 @@ public class TSDBResultSetBlockData { } public void setByteArray(int col, int length, byte[] value) { - try { - switch (this.columnMetaDataList.get(col).getColType()) { - case TSDBConstants.TSDB_DATA_TYPE_BOOL: { - ByteBuffer buf = ByteBuffer.wrap(value, 0, length); - buf.order(ByteOrder.LITTLE_ENDIAN).asCharBuffer(); - this.colData.set(col, buf); - break; - } - case TSDBConstants.TSDB_DATA_TYPE_UTINYINT: - case TSDBConstants.TSDB_DATA_TYPE_TINYINT: { - ByteBuffer buf = ByteBuffer.wrap(value, 0, length); - buf.order(ByteOrder.LITTLE_ENDIAN); - this.colData.set(col, buf); - break; - } - case TSDBConstants.TSDB_DATA_TYPE_USMALLINT: - case TSDBConstants.TSDB_DATA_TYPE_SMALLINT: { - ByteBuffer buf = ByteBuffer.wrap(value, 0, length); - ShortBuffer sb = buf.order(ByteOrder.LITTLE_ENDIAN).asShortBuffer(); - this.colData.set(col, sb); - break; - } - case TSDBConstants.TSDB_DATA_TYPE_UINT: - case TSDBConstants.TSDB_DATA_TYPE_INT: { - ByteBuffer buf = ByteBuffer.wrap(value, 0, length); - IntBuffer ib = buf.order(ByteOrder.LITTLE_ENDIAN).asIntBuffer(); - this.colData.set(col, ib); - break; - } - case TSDBConstants.TSDB_DATA_TYPE_UBIGINT: - case TSDBConstants.TSDB_DATA_TYPE_BIGINT: { - ByteBuffer buf = ByteBuffer.wrap(value, 0, length); - LongBuffer lb = buf.order(ByteOrder.LITTLE_ENDIAN).asLongBuffer(); - this.colData.set(col, lb); - break; - } - case TSDBConstants.TSDB_DATA_TYPE_FLOAT: { - ByteBuffer buf = ByteBuffer.wrap(value, 0, length); - FloatBuffer fb = buf.order(ByteOrder.LITTLE_ENDIAN).asFloatBuffer(); - this.colData.set(col, fb); - break; - } - case TSDBConstants.TSDB_DATA_TYPE_DOUBLE: { - ByteBuffer buf = ByteBuffer.wrap(value, 0, length); - DoubleBuffer db = buf.order(ByteOrder.LITTLE_ENDIAN).asDoubleBuffer(); - this.colData.set(col, db); - break; - } - case TSDBConstants.TSDB_DATA_TYPE_BINARY: { - ByteBuffer buf = ByteBuffer.wrap(value, 0, length); - buf.order(ByteOrder.LITTLE_ENDIAN); - this.colData.set(col, buf); - break; - } - case TSDBConstants.TSDB_DATA_TYPE_TIMESTAMP: { - ByteBuffer buf = ByteBuffer.wrap(value, 0, length); - LongBuffer lb = buf.order(ByteOrder.LITTLE_ENDIAN).asLongBuffer(); - this.colData.set(col, lb); - break; - } - case TSDBConstants.TSDB_DATA_TYPE_NCHAR: { - ByteBuffer buf = ByteBuffer.wrap(value, 0, length); - buf.order(ByteOrder.LITTLE_ENDIAN); - this.colData.set(col, buf); - break; - } + switch (this.columnMetaDataList.get(col).getColType()) { + case TSDBConstants.TSDB_DATA_TYPE_BOOL: { + ByteBuffer buf = ByteBuffer.wrap(value, 0, length); + buf.order(ByteOrder.LITTLE_ENDIAN).asCharBuffer(); + this.colData.set(col, buf); + break; + } + case TSDBConstants.TSDB_DATA_TYPE_UTINYINT: + case TSDBConstants.TSDB_DATA_TYPE_TINYINT: { + ByteBuffer buf = ByteBuffer.wrap(value, 0, length); + buf.order(ByteOrder.LITTLE_ENDIAN); + this.colData.set(col, buf); + break; + } + case TSDBConstants.TSDB_DATA_TYPE_USMALLINT: + case TSDBConstants.TSDB_DATA_TYPE_SMALLINT: { + ByteBuffer buf = ByteBuffer.wrap(value, 0, length); + ShortBuffer sb = buf.order(ByteOrder.LITTLE_ENDIAN).asShortBuffer(); + this.colData.set(col, sb); + break; + } + case TSDBConstants.TSDB_DATA_TYPE_UINT: + case TSDBConstants.TSDB_DATA_TYPE_INT: { + ByteBuffer buf = ByteBuffer.wrap(value, 0, length); + IntBuffer ib = buf.order(ByteOrder.LITTLE_ENDIAN).asIntBuffer(); + this.colData.set(col, ib); + break; + } + case TSDBConstants.TSDB_DATA_TYPE_UBIGINT: + case TSDBConstants.TSDB_DATA_TYPE_BIGINT: { + ByteBuffer buf = ByteBuffer.wrap(value, 0, length); + LongBuffer lb = buf.order(ByteOrder.LITTLE_ENDIAN).asLongBuffer(); + this.colData.set(col, lb); + break; + } + case TSDBConstants.TSDB_DATA_TYPE_FLOAT: { + ByteBuffer buf = ByteBuffer.wrap(value, 0, length); + FloatBuffer fb = buf.order(ByteOrder.LITTLE_ENDIAN).asFloatBuffer(); + this.colData.set(col, fb); + break; + } + case TSDBConstants.TSDB_DATA_TYPE_DOUBLE: { + ByteBuffer buf = ByteBuffer.wrap(value, 0, length); + DoubleBuffer db = buf.order(ByteOrder.LITTLE_ENDIAN).asDoubleBuffer(); + this.colData.set(col, db); + break; + } + case TSDBConstants.TSDB_DATA_TYPE_BINARY: { + ByteBuffer buf = ByteBuffer.wrap(value, 0, length); + buf.order(ByteOrder.LITTLE_ENDIAN); + this.colData.set(col, buf); + break; + } + case TSDBConstants.TSDB_DATA_TYPE_TIMESTAMP: { + ByteBuffer buf = ByteBuffer.wrap(value, 0, length); + LongBuffer lb = buf.order(ByteOrder.LITTLE_ENDIAN).asLongBuffer(); + this.colData.set(col, lb); + break; + } + case TSDBConstants.TSDB_DATA_TYPE_NCHAR: { + ByteBuffer buf = ByteBuffer.wrap(value, 0, length); + buf.order(ByteOrder.LITTLE_ENDIAN); + this.colData.set(col, buf); + break; } - } catch (Exception e) { - e.printStackTrace(); } } @@ -283,14 +279,8 @@ public class TSDBResultSetBlockData { return 0; } - public Timestamp getTimestamp(int col) { - try { - return new Timestamp(getLong(col)); - } catch (SQLException e) { - e.printStackTrace(); - } - - return null; + public Timestamp getTimestamp(int col) throws SQLException { + return new Timestamp(getLong(col)); } public double getDouble(int col) { @@ -429,7 +419,7 @@ public class TSDBResultSetBlockData { String charset = TaosGlobalConfig.getCharset(); return new String(dest, charset); } catch (UnsupportedEncodingException e) { - e.printStackTrace(); + throw new RuntimeException(e.getMessage()); } } } 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 5cdaa3c70c334bc7bd97be08f2318e6fc548d22a..d8ac10d839651bb476a8688f28917aa356b5b1fe 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 @@ -16,6 +16,7 @@ package com.taosdata.jdbc; import com.taosdata.jdbc.utils.NullType; +import java.io.UnsupportedEncodingException; import java.math.BigDecimal; import java.sql.SQLException; import java.sql.Timestamp; @@ -378,8 +379,8 @@ public class TSDBResultSetRowData { // 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) { - e.printStackTrace(); + } catch (UnsupportedEncodingException e) { + throw new RuntimeException(e.getMessage()); } } diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/utils/HttpClientPoolUtil.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/utils/HttpClientPoolUtil.java index fc116b32c2a154c9479e4933d887ac7ddcedbe9f..cdadcd2d28a03d3db4b490049a4e84f2fc38ea02 100644 --- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/utils/HttpClientPoolUtil.java +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/utils/HttpClientPoolUtil.java @@ -5,6 +5,7 @@ import com.taosdata.jdbc.TSDBErrorNumbers; import org.apache.http.HeaderElement; import org.apache.http.HeaderElementIterator; import org.apache.http.HttpEntity; +import org.apache.http.NoHttpResponseException; import org.apache.http.client.ClientProtocolException; import org.apache.http.client.config.RequestConfig; import org.apache.http.client.methods.*; diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/utils/TaosInfo.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/utils/TaosInfo.java index d4664f2678013b3de87bcd3f0dc24631be511ede..583c2c3236574b8474b834513b28160c37d5b250 100644 --- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/utils/TaosInfo.java +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/utils/TaosInfo.java @@ -16,8 +16,8 @@ public class TaosInfo implements TaosInfoMBean { MBeanServer server = ManagementFactory.getPlatformMBeanServer(); ObjectName name = new ObjectName("TaosInfoMBean:name=TaosInfo"); server.registerMBean(TaosInfo.getInstance(), name); - } catch (MalformedObjectNameException | InstanceAlreadyExistsException | MBeanRegistrationException | NotCompliantMBeanException e) { - e.printStackTrace(); + } catch (MalformedObjectNameException | InstanceAlreadyExistsException | MBeanRegistrationException | NotCompliantMBeanException ignored) { + throw new RuntimeException("registerMBean failed"); } } 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 7cdda572a7e6950005d47798bece6cc5c6fef7d1..64b7ab1cabe2c5815ff87d9881873150f21049c6 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 @@ -30,42 +30,6 @@ public class TSDBConnectionTest { } } - @Test - 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(); - - // 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(); - } - - } - @Test public void prepareStatement() throws SQLException { PreparedStatement pstmt = conn.prepareStatement("select server_status()"); @@ -391,13 +355,9 @@ public class TSDBConnectionTest { } @Test - public void unwrap() { - try { - TSDBConnection tsdbConnection = conn.unwrap(TSDBConnection.class); - Assert.assertNotNull(tsdbConnection); - } catch (SQLException e) { - e.printStackTrace(); - } + public void unwrap() throws SQLException { + TSDBConnection tsdbConnection = conn.unwrap(TSDBConnection.class); + Assert.assertNotNull(tsdbConnection); } @Test @@ -406,32 +366,22 @@ public class TSDBConnectionTest { } @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/log?user=root&password=taosdata", properties); - // create test database for test cases - try (Statement stmt = conn.createStatement()) { - stmt.execute("create database if not exists test"); - } - - } catch (ClassNotFoundException | SQLException e) { - e.printStackTrace(); + public static void beforeClass() throws SQLException { + 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/log?user=root&password=taosdata", properties); + // create test database for test cases + try (Statement stmt = conn.createStatement()) { + stmt.execute("create database if not exists test"); } } @AfterClass - public static void afterClass() { - try { - if (conn != null) - conn.close(); - } catch (SQLException e) { - e.printStackTrace(); - } + public static void afterClass() throws SQLException { + if (conn != null) + conn.close(); } } \ No newline at end of file diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBDriverTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBDriverTest.java index 671ecd723d6fea8d6b9b8ccf94cba06689ce26b8..9f297955d687f3cfcc3acef626e1f905ecee6bdf 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBDriverTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBDriverTest.java @@ -33,7 +33,6 @@ public class TSDBDriverTest { conn = DriverManager.getConnection(url); assertNotNull("failure - connection should not be null", conn); } catch (SQLException e) { - e.printStackTrace(); fail("failure - should not throw Exception"); } } @@ -49,7 +48,6 @@ public class TSDBDriverTest { conn = DriverManager.getConnection(jdbcUrl, connProps); assertNotNull("failure - connection should not be null", conn); } catch (SQLException e) { - e.printStackTrace(); fail("failure - should not throw Exception"); } } @@ -65,7 +63,6 @@ public class TSDBDriverTest { conn = DriverManager.getConnection(jdbcUrl, connProps); assertNotNull("failure - connection should not be null", conn); } catch (SQLException e) { - e.printStackTrace(); fail("failure - should not throw Exception"); } } @@ -157,16 +154,8 @@ public class TSDBDriverTest { } @Test - public void getParentLogger() throws SQLFeatureNotSupportedException { + public void getParentLogger() { assertNull(new TSDBDriver().getParentLogger()); } - @BeforeClass - public static void before() { - try { - Class.forName("com.taosdata.jdbc.TSDBDriver"); - } catch (ClassNotFoundException e) { - e.printStackTrace(); - } - } } \ No newline at end of file diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/AuthenticationTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/AuthenticationTest.java index 0ea46dade29316b99447a6ea4e372bc8057670e8..5b38f9b0640bb6eec6d1c9749db0abf0388c04ce 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/AuthenticationTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/AuthenticationTest.java @@ -57,44 +57,31 @@ public class AuthenticationTest { @Ignore @Test - public void test() { + public void test() throws SQLException { // change password - try { - conn = DriverManager.getConnection("jdbc:TAOS-RS://" + host + ":6041/restful_test?user=" + user + "&password=taosdata"); - Statement stmt = conn.createStatement(); + String url = "jdbc:TAOS-RS://" + host + ":6041/restful_test?user=" + user + "&password=taosdata"; + try (Connection conn = DriverManager.getConnection(url); + Statement stmt = conn.createStatement();) { stmt.execute("alter user " + user + " pass '" + password + "'"); - stmt.close(); - conn.close(); - } catch (SQLException e) { - e.printStackTrace(); } + // use new to login and execute query - try { - conn = DriverManager.getConnection("jdbc:TAOS-RS://" + host + ":6041/restful_test?user=" + user + "&password=" + password); - Statement stmt = conn.createStatement(); + url = "jdbc:TAOS-RS://" + host + ":6041/restful_test?user=" + user + "&password=" + password; + try (Connection conn = DriverManager.getConnection(url); + Statement stmt = conn.createStatement()) { stmt.execute("show databases"); ResultSet rs = stmt.getResultSet(); 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(); } - } catch (SQLException e) { - e.printStackTrace(); } + // change password back - try { - conn = DriverManager.getConnection("jdbc:TAOS-RS://" + host + ":6041/restful_test?user=" + user + "&password=" + password); - Statement stmt = conn.createStatement(); + url = "jdbc:TAOS-RS://" + host + ":6041/restful_test?user=" + user + "&password=" + password; + try (Connection conn = DriverManager.getConnection(url); + Statement stmt = conn.createStatement()) { stmt.execute("alter user " + user + " pass 'taosdata'"); - stmt.close(); - conn.close(); - } catch (SQLException e) { - e.printStackTrace(); } - } @Before diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/BadLocaleSettingTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/BadLocaleSettingTest.java deleted file mode 100644 index 2211e0fa176c67329ac13ee4374daf4667da933b..0000000000000000000000000000000000000000 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/BadLocaleSettingTest.java +++ /dev/null @@ -1,59 +0,0 @@ -package com.taosdata.jdbc.cases; - - -import com.taosdata.jdbc.TSDBDriver; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; - -import java.sql.Connection; -import java.sql.DriverManager; -import java.sql.SQLException; -import java.sql.Statement; -import java.util.Properties; - -public class BadLocaleSettingTest { - - private static final String host = "127.0.0.1"; - private static final String dbName = "bad_locale_test"; - private static Connection conn; - - @Test - public void canSetLocale() { - try { - 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"); - - String url = "jdbc:TAOS://" + host + ":6030/?user=root&password=taosdata"; - conn = DriverManager.getConnection(url, properties); - Statement stmt = conn.createStatement(); - stmt.execute("drop database if exists " + dbName); - stmt.execute("create database if not exists " + dbName); - stmt.execute("use " + dbName); - stmt.execute("drop table if exists weather"); - stmt.execute("create table weather(ts timestamp, temperature float, humidity int)"); - stmt.executeUpdate("insert into weather values(1624071506435, 12.3, 4)"); - stmt.close(); - } catch (SQLException e) { - e.printStackTrace(); - } - } - - @BeforeClass - public static void beforeClass() { - System.setProperty("sun.jnu.encoding", "ANSI_X3.4-1968"); - System.setProperty("file.encoding", "ANSI_X3.4-1968"); - } - - @AfterClass - public static void afterClass() { - try { - if (conn != null) - conn.close(); - } catch (SQLException e) { - e.printStackTrace(); - } - } -} \ No newline at end of file diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/BatchErrorIgnoreTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/BatchErrorIgnoreTest.java index 2934b54b5bd2e7f5450a9a1a00cb5bddca37e945..548c1cff240a811ba998373167588185305a0d59 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/BatchErrorIgnoreTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/BatchErrorIgnoreTest.java @@ -19,16 +19,14 @@ public class BatchErrorIgnoreTest { IntStream.range(1, 6).mapToObj(i -> "insert into test.t" + i + " values(now, " + i + ")").forEach(sql -> { try { stmt.addBatch(sql); - } catch (SQLException e) { - e.printStackTrace(); + } catch (SQLException ignored) { } }); stmt.addBatch("insert into t11 values(now, 11)"); IntStream.range(6, 11).mapToObj(i -> "insert into test.t" + i + " values(now, " + i + "),(now + 1s, " + (10 * i) + ")").forEach(sql -> { try { stmt.addBatch(sql); - } catch (SQLException e) { - e.printStackTrace(); + } catch (SQLException ignored) { } }); stmt.addBatch("select count(*) from test.weather"); @@ -57,23 +55,19 @@ public class BatchErrorIgnoreTest { IntStream.range(1, 6).mapToObj(i -> "insert into test.t" + i + " values(now, " + i + ")").forEach(sql -> { try { stmt.addBatch(sql); - } catch (SQLException e) { - e.printStackTrace(); + } catch (SQLException ignored) { } }); stmt.addBatch("insert into t11 values(now, 11)"); IntStream.range(6, 11).mapToObj(i -> "insert into test.t" + i + " values(now, " + i + "),(now + 1s, " + (10 * i) + ")").forEach(sql -> { try { stmt.addBatch(sql); - } catch (SQLException e) { - e.printStackTrace(); + } catch (SQLException ignored) { } }); stmt.addBatch("select count(*) from test.weather"); results = stmt.executeBatch(); - } catch (SQLException e) { - e.printStackTrace(); } // then @@ -94,10 +88,10 @@ public class BatchErrorIgnoreTest { } @Before - public void before() { - try { - Connection conn = DriverManager.getConnection("jdbc:TAOS://" + host + ":6030/?user=root&password=taosdata"); - Statement stmt = conn.createStatement(); + public void before() throws SQLException { + try (Connection conn = DriverManager.getConnection("jdbc:TAOS://" + host + ":6030/?user=root&password=taosdata"); + Statement stmt = conn.createStatement();) { + stmt.execute("use test"); stmt.execute("drop table if exists weather"); stmt.execute("create table weather (ts timestamp, f1 float) tags(t1 int)"); @@ -108,37 +102,25 @@ public class BatchErrorIgnoreTest { e.printStackTrace(); } }); - stmt.close(); - conn.close(); - } catch (SQLException e) { - e.printStackTrace(); } } @BeforeClass - public static void beforeClass() { - try { - Connection conn = DriverManager.getConnection("jdbc:TAOS://" + host + ":6030/?user=root&password=taosdata"); - Statement stmt = conn.createStatement(); + public static void beforeClass() throws SQLException { + try (Connection conn = DriverManager.getConnection("jdbc:TAOS://" + host + ":6030/?user=root&password=taosdata"); + Statement stmt = conn.createStatement()) { + stmt.execute("drop database if exists test"); stmt.execute("create database if not exists test"); - stmt.close(); - conn.close(); - } catch (SQLException e) { - e.printStackTrace(); } } @AfterClass - public static void afterClass() { - try { - Connection conn = DriverManager.getConnection("jdbc:TAOS://" + host + ":6030/?user=root&password=taosdata"); - Statement stmt = conn.createStatement(); + public static void afterClass() throws SQLException { + try (Connection conn = DriverManager.getConnection("jdbc:TAOS://" + host + ":6030/?user=root&password=taosdata"); + Statement stmt = conn.createStatement()) { + stmt.execute("drop database if exists test"); - stmt.close(); - conn.close(); - } catch (SQLException e) { - e.printStackTrace(); } } } diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/ConnectMultiTaosdByRestfulWithDifferentTokenTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/ConnectMultiTaosdByRestfulWithDifferentTokenTest.java index fcb6ab7aaff2406acf59262a9cdef90b628b8934..8299cfebec6ba54be42dc1fbe8dcff1b14034860 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/ConnectMultiTaosdByRestfulWithDifferentTokenTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/ConnectMultiTaosdByRestfulWithDifferentTokenTest.java @@ -20,22 +20,20 @@ public class ConnectMultiTaosdByRestfulWithDifferentTokenTest { private Connection conn2; @Test - public void test() { + public void test() throws SQLException { //when executeSelectStatus(conn1); executeSelectStatus(conn2); executeSelectStatus(conn1); } - private void executeSelectStatus(Connection connection) { + private void executeSelectStatus(Connection connection) throws SQLException { try (Statement stmt = connection.createStatement()) { ResultSet rs = stmt.executeQuery("select server_status()"); ResultSetMetaData meta = rs.getMetaData(); Assert.assertNotNull(meta); while (rs.next()) { } - } catch (SQLException e) { - e.printStackTrace(); } } diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/ConnectWrongDatabaseTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/ConnectWrongDatabaseTest.java index d8d8f1eae42f555b2bc0be12e8a3a943071da3c6..d60ee14fbc87ba5d2bd2e851b5195b513fc4e028 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/ConnectWrongDatabaseTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/ConnectWrongDatabaseTest.java @@ -1,7 +1,5 @@ package com.taosdata.jdbc.cases; -import com.taosdata.jdbc.TSDBErrorNumbers; -import org.junit.Assert; import org.junit.Test; import java.sql.DriverManager; @@ -9,16 +7,9 @@ import java.sql.SQLException; public class ConnectWrongDatabaseTest { - @Test - public void connect() { - try { - Class.forName("com.taosdata.jdbc.TSDBDriver"); - DriverManager.getConnection("jdbc:TAOS://localhost:6030/wrong_db?user=root&password=taosdata"); - } catch (ClassNotFoundException e) { - e.printStackTrace(); - } catch (SQLException e) { - Assert.assertEquals(TSDBErrorNumbers.ERROR_JNI_CONNECTION_NULL, e.getErrorCode()); - } + @Test(expected = SQLException.class) + public void connect() throws SQLException { + DriverManager.getConnection("jdbc:TAOS://localhost:6030/wrong_db?user=root&password=taosdata"); } } diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/DatetimeBefore1970Test.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/DatetimeBefore1970Test.java index 14c76985484857a92e174955c943caa21bdd2e72..bfffaa4a129dc7fe19a92c34abbcc886d5e4e22f 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/DatetimeBefore1970Test.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/DatetimeBefore1970Test.java @@ -11,7 +11,7 @@ public class DatetimeBefore1970Test { private Connection conn; @Test - public void test() { + public void test() throws SQLException { try (Statement stmt = conn.createStatement()) { // given stmt.executeUpdate("insert into weather(ts) values('1969-12-31 23:59:59.999')"); @@ -45,36 +45,25 @@ public class DatetimeBefore1970Test { // then ts = rs.getTimestamp("ts"); Assert.assertEquals("1970-01-01 07:59:59.999", TimestampUtil.longToDatetime(ts.getTime())); - - } catch (SQLException e) { - e.printStackTrace(); } } @Before - public void before() { - try { - conn = DriverManager.getConnection("jdbc:TAOS://" + host + ":6030/?user=root&password=taosdata"); - Statement stmt = conn.createStatement(); - stmt.execute("drop database if exists test_timestamp"); - stmt.execute("create database if not exists test_timestamp keep 36500"); - stmt.execute("use test_timestamp"); - stmt.execute("create table weather(ts timestamp,f1 float)"); - stmt.close(); - } catch (SQLException e) { - e.printStackTrace(); - } + public void before() throws SQLException { + conn = DriverManager.getConnection("jdbc:TAOS://" + host + ":6030/?user=root&password=taosdata"); + Statement stmt = conn.createStatement(); + stmt.execute("drop database if exists test_timestamp"); + stmt.execute("create database if not exists test_timestamp keep 36500"); + stmt.execute("use test_timestamp"); + stmt.execute("create table weather(ts timestamp,f1 float)"); + stmt.close(); } @After - public void after() { - try { - Statement stmt = conn.createStatement(); - stmt.execute("drop database if exists test_timestamp"); - if (conn != null) - conn.close(); - } catch (SQLException e) { - e.printStackTrace(); - } + public void after() throws SQLException { + Statement stmt = conn.createStatement(); + stmt.execute("drop database if exists test_timestamp"); + if (conn != null) + conn.close(); } } diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/ImportTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/ImportTest.java index 1297a6b4c4eb0eca208950363c13e9bb4d1cd3a9..a8fdf4f2caa88d2651bebf2a1c46b95644b488d2 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/ImportTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/ImportTest.java @@ -17,29 +17,6 @@ public class ImportTest { static String host = "127.0.0.1"; private static long ts; - @BeforeClass - public static void before() { - try { - Properties properties = new Properties(); - properties.setProperty(TSDBDriver.PROPERTY_KEY_USER, "root"); - properties.setProperty(TSDBDriver.PROPERTY_KEY_PASSWORD, "taosdata"); - 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 + ":0/", properties); - - Statement stmt = connection.createStatement(); - stmt.execute("create database if not exists " + dbName); - stmt.execute("create table if not exists " + dbName + "." + tName + " (ts timestamp, k int, v int)"); - stmt.close(); - - ts = System.currentTimeMillis(); - } catch (SQLException e) { - e.printStackTrace(); - } - - } - @Test public void case001_insertData() throws Exception { try (Statement stmt = connection.createStatement()) { @@ -52,28 +29,25 @@ public class ImportTest { } @Test - public void case002_checkSum() { + public void case002_checkSum() throws SQLException { Assert.assertEquals(50, select()); } - private int select() { + private int select() throws SQLException { int count = 0; try (Statement stmt = connection.createStatement()) { - String sql = "select * from " + dbName + "." + tName; ResultSet rs = stmt.executeQuery(sql); while (rs.next()) { count++; } rs.close(); - } catch (SQLException e) { - e.printStackTrace(); } return count; } @Test - public void case003_importData() { + public void case003_importData() throws SQLException { // 避免时间重复 try (Statement stmt = connection.createStatement()) { StringBuilder sqlBuilder = new StringBuilder("import into ").append(dbName).append(".").append(tName).append(" values "); @@ -84,27 +58,40 @@ public class ImportTest { } int rows = stmt.executeUpdate(sqlBuilder.toString()); assertEquals(50, rows); - } catch (SQLException e) { - e.printStackTrace(); } } @Test - public void case004_checkSum() { + public void case004_checkSum() throws SQLException { Assert.assertEquals(100, select()); } + + @BeforeClass + public static void before() throws SQLException { + Properties properties = new Properties(); + properties.setProperty(TSDBDriver.PROPERTY_KEY_USER, "root"); + properties.setProperty(TSDBDriver.PROPERTY_KEY_PASSWORD, "taosdata"); + 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 + ":0/", properties); + + Statement stmt = connection.createStatement(); + stmt.execute("create database if not exists " + dbName); + stmt.execute("create table if not exists " + dbName + "." + tName + " (ts timestamp, k int, v int)"); + stmt.close(); + + ts = System.currentTimeMillis(); + } + @AfterClass - public static void close() { - try { - if (connection != null) { - Statement statement = connection.createStatement(); - statement.executeUpdate("drop database " + dbName); - statement.close(); - connection.close(); - } - } catch (SQLException e) { - e.printStackTrace(); + public static void close() throws SQLException { + if (connection != null) { + Statement statement = connection.createStatement(); + statement.executeUpdate("drop database " + dbName); + statement.close(); + connection.close(); } } } diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/MicroSecondPrecisionRestfulTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/MicroSecondPrecisionRestfulTest.java index 7e9f04cd6360431a3fe6c29a2f0eb61fbdc9e7c4..f418436a4afac5f16b27789eb43081f131bf1f92 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/MicroSecondPrecisionRestfulTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/MicroSecondPrecisionRestfulTest.java @@ -23,7 +23,7 @@ public class MicroSecondPrecisionRestfulTest { private static Connection conn3; @Test - public void testCase1() { + public void testCase1() throws SQLException { try (Statement stmt = conn1.createStatement()) { ResultSet rs = stmt.executeQuery("select last_row(ts) from " + ms_timestamp_db + ".weather"); rs.next(); @@ -31,13 +31,11 @@ public class MicroSecondPrecisionRestfulTest { Assert.assertEquals(timestamp1, ts); ts = rs.getLong(1); Assert.assertEquals(timestamp1, ts); - } catch (SQLException e) { - e.printStackTrace(); } } @Test - public void testCase2() { + public void testCase2() throws SQLException { try (Statement stmt = conn1.createStatement()) { ResultSet rs = stmt.executeQuery("select last_row(ts) from " + us_timestamp_db + ".weather"); rs.next(); @@ -50,13 +48,11 @@ public class MicroSecondPrecisionRestfulTest { ts = rs.getLong(1); Assert.assertEquals(timestamp1, ts); - } catch (SQLException e) { - e.printStackTrace(); } } @Test - public void testCase3() { + public void testCase3() throws SQLException { try (Statement stmt = conn2.createStatement()) { ResultSet rs = stmt.executeQuery("select last_row(ts) from " + ms_timestamp_db + ".weather"); rs.next(); @@ -65,13 +61,11 @@ public class MicroSecondPrecisionRestfulTest { Assert.assertEquals(timestamp1, ts); ts = rs.getLong(1); Assert.assertEquals(timestamp1, ts); - } catch (SQLException e) { - e.printStackTrace(); } } @Test - public void testCase4() { + public void testCase4() throws SQLException { try (Statement stmt = conn2.createStatement()) { ResultSet rs = stmt.executeQuery("select last_row(ts) from " + us_timestamp_db + ".weather"); rs.next(); @@ -84,13 +78,11 @@ public class MicroSecondPrecisionRestfulTest { ts = rs.getLong(1); Assert.assertEquals(timestamp1, ts); - } catch (SQLException e) { - e.printStackTrace(); } } @Test - public void testCase5() { + public void testCase5() throws SQLException { try (Statement stmt = conn3.createStatement()) { ResultSet rs = stmt.executeQuery("select last_row(ts) from " + ms_timestamp_db + ".weather"); rs.next(); @@ -99,13 +91,11 @@ public class MicroSecondPrecisionRestfulTest { Assert.assertEquals(timestamp1, ts); ts = rs.getLong(1); Assert.assertEquals(timestamp1, ts); - } catch (SQLException e) { - e.printStackTrace(); } } @Test - public void testCase6() { + public void testCase6() throws SQLException { try (Statement stmt = conn3.createStatement()) { ResultSet rs = stmt.executeQuery("select last_row(ts) from " + us_timestamp_db + ".weather"); rs.next(); @@ -118,8 +108,6 @@ public class MicroSecondPrecisionRestfulTest { ts = rs.getLong(1); Assert.assertEquals(timestamp1, ts); - } catch (SQLException e) { - e.printStackTrace(); } } @@ -154,16 +142,12 @@ public class MicroSecondPrecisionRestfulTest { } @AfterClass - public static void afterClass() { - try { - if (conn1 != null) - conn1.close(); - if (conn2 != null) - conn2.close(); - if (conn3 != null) - conn3.close(); - } catch (SQLException e) { - e.printStackTrace(); - } + public static void afterClass() throws SQLException { + if (conn1 != null) + conn1.close(); + if (conn2 != null) + conn2.close(); + if (conn3 != null) + conn3.close(); } } diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/MultiConnectionWithDifferentDbTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/MultiConnectionWithDifferentDbTest.java index 18a2c32aca0535567dd42e886bc87ae618596a40..0bf8334079e630bf61b7955a37c74401da24a947 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/MultiConnectionWithDifferentDbTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/MultiConnectionWithDifferentDbTest.java @@ -9,8 +9,7 @@ import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; import java.util.stream.IntStream; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.*; public class MultiConnectionWithDifferentDbTest { @@ -26,16 +25,17 @@ public class MultiConnectionWithDifferentDbTest { @Override public void run() { for (int j = 0; j < 10; j++) { - queryDb(); try { + queryDb(); TimeUnit.SECONDS.sleep(1); - } catch (InterruptedException e) { - e.printStackTrace(); + } catch (InterruptedException ignored) { + } catch (SQLException throwables) { + fail(); } } } - private void queryDb() { + private void queryDb() throws SQLException { String url = "jdbc:TAOS-RS://" + host + ":6041/db" + i + "?user=root&password=taosdata"; try (Connection connection = DriverManager.getConnection(url)) { Statement stmt = connection.createStatement(); @@ -54,8 +54,6 @@ public class MultiConnectionWithDifferentDbTest { assertEquals(loc, loc_actual); stmt.close(); - } catch (SQLException e) { - e.printStackTrace(); } } }, "thread-" + i)).collect(Collectors.toList()); @@ -73,12 +71,10 @@ public class MultiConnectionWithDifferentDbTest { } @Before - public void before() { + public void before() throws SQLException { ts = System.currentTimeMillis(); - try { - Connection conn = DriverManager.getConnection("jdbc:TAOS-RS://" + host + ":6041/?user=root&password=taosdata"); - + try (Connection conn = DriverManager.getConnection("jdbc:TAOS-RS://" + host + ":6041/?user=root&password=taosdata")) { Statement stmt = conn.createStatement(); stmt.execute("drop database if exists " + db1); stmt.execute("create database if not exists " + db1); @@ -91,10 +87,6 @@ public class MultiConnectionWithDifferentDbTest { stmt.execute("use " + db2); stmt.execute("create table weather(ts timestamp, f1 int) tags(loc nchar(10))"); stmt.execute("insert into t1 using weather tags('shanghai') values(" + ts + ", 2)"); - - conn.close(); - } catch (SQLException e) { - e.printStackTrace(); } } diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/MultiThreadsWithSameStatementTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/MultiThreadsWithSameStatementTest.java deleted file mode 100644 index 73da79f357b1c066943e2f39bf9f8bdc86382d7e..0000000000000000000000000000000000000000 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/MultiThreadsWithSameStatementTest.java +++ /dev/null @@ -1,85 +0,0 @@ -package com.taosdata.jdbc.cases; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import java.sql.*; -import java.util.concurrent.TimeUnit; - -public class MultiThreadsWithSameStatementTest { - - private static class Service { - public Connection conn; - public Statement stmt; - - public Service() { - try { - conn = DriverManager.getConnection("jdbc:TAOS://localhost:6030/?user=root&password=taosdata"); - stmt = conn.createStatement(); - stmt.execute("create database if not exists jdbctest"); - stmt.executeUpdate("create table if not exists jdbctest.weather (ts timestamp, f1 int)"); - } catch (SQLException e) { - e.printStackTrace(); - } - } - - public void release() { - try { - stmt.close(); - conn.close(); - } catch (SQLException e) { - e.printStackTrace(); - } - } - } - - @Before - public void before() { - } - - @Test - public void test() { - Thread t1 = new Thread(() -> { - try { - Service service = new Service(); - ResultSet resultSet = service.stmt.executeQuery("select * from jdbctest.weather"); - while (resultSet.next()) { - ResultSetMetaData metaData = resultSet.getMetaData(); - } - resultSet.close(); - service.release(); - } catch (SQLException e) { - e.printStackTrace(); - } - }); - - Thread t2 = new Thread(() -> { - while (true) { - try { - Service service = new Service(); - service.stmt.executeUpdate("insert into jdbctest.weather values(now,1)"); - service.release(); - } catch (SQLException e) { - e.printStackTrace(); - } - } - - }); - t1.start(); - sleep(1000); - t2.start(); - } - - private void sleep(long mills) { - try { - TimeUnit.MILLISECONDS.sleep(mills); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - - @After - public void after() { - } -} diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/NanoSecondTimestampJNITest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/NanoSecondTimestampJNITest.java index 4f2c87966ad6bb8390bab47b795e7d952725baf5..a84f5233974e9bd9acdbbe3ca8ae0404c11b34a1 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/NanoSecondTimestampJNITest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/NanoSecondTimestampJNITest.java @@ -17,7 +17,7 @@ public class NanoSecondTimestampJNITest { private static Connection conn; @Test - public void insertUsingLongValue() { + public void insertUsingLongValue() throws SQLException { // given long ms = System.currentTimeMillis(); long ns = ms * 1000_000 + random.nextInt(1000_000); @@ -26,8 +26,6 @@ public class NanoSecondTimestampJNITest { int ret = 0; try (Statement stmt = conn.createStatement()) { ret = stmt.executeUpdate("insert into weather(ts, temperature, humidity) values(" + ns + ", 12.3, 4)"); - } catch (SQLException e) { - e.printStackTrace(); } // then @@ -35,15 +33,13 @@ public class NanoSecondTimestampJNITest { } @Test - public void insertUsingStringValue() { + public void insertUsingStringValue() throws SQLException { // given // when int ret = 0; try (Statement stmt = conn.createStatement()) { ret = stmt.executeUpdate("insert into weather(ts, temperature, humidity) values('2021-01-01 12:00:00.123456789', 12.3, 4)"); - } catch (SQLException e) { - e.printStackTrace(); } // then @@ -51,7 +47,7 @@ public class NanoSecondTimestampJNITest { } @Test - public void insertUsingTimestampValue() { + public void insertUsingTimestampValue() throws SQLException { // given long epochSec = System.currentTimeMillis() / 1000; long nanoAdjustment = random.nextInt(1000_000_000); @@ -65,8 +61,6 @@ public class NanoSecondTimestampJNITest { pstmt.setFloat(2, 12.34f); pstmt.setInt(3, 55); ret = pstmt.executeUpdate(); - } catch (SQLException e) { - e.printStackTrace(); } // then @@ -85,8 +79,6 @@ public class NanoSecondTimestampJNITest { stmt.executeUpdate("insert into weather(ts, temperature, humidity) values(" + ns + ", 12.3, 4)"); rs = stmt.executeQuery("select * from weather"); rs.next(); - } catch (SQLException e) { - e.printStackTrace(); } // then @@ -102,13 +94,11 @@ public class NanoSecondTimestampJNITest { String timestampStr = "2021-01-01 12:00:00.123456789"; // when - ResultSet rs = null; + ResultSet rs; try (Statement stmt = conn.createStatement()) { stmt.executeUpdate("insert into weather(ts, temperature, humidity) values('" + timestampStr + "', 12.3, 4)"); rs = stmt.executeQuery("select * from weather"); rs.next(); - } catch (SQLException e) { - e.printStackTrace(); } // then @@ -133,8 +123,6 @@ public class NanoSecondTimestampJNITest { pstmt.setFloat(2, 12.34f); pstmt.setInt(3, 55); pstmt.executeUpdate(); - } catch (SQLException e) { - e.printStackTrace(); } // when @@ -142,8 +130,6 @@ public class NanoSecondTimestampJNITest { try (Statement stmt = conn.createStatement()) { rs = stmt.executeQuery("select * from weather"); rs.next(); - } catch (SQLException e) { - e.printStackTrace(); } // then @@ -156,26 +142,21 @@ public class NanoSecondTimestampJNITest { } @Before - public void before() { + public void before() throws SQLException { try (Statement stmt = conn.createStatement()) { stmt.execute("drop table if exists weather"); stmt.execute("create table weather(ts timestamp, temperature float, humidity int)"); - } catch (SQLException e) { - e.printStackTrace(); } } @BeforeClass - public static void beforeClass() { + public static void beforeClass() throws SQLException { final String url = "jdbc:TAOS://" + host + ":6030/?user=root&password=taosdata"; - try { - conn = DriverManager.getConnection(url); - Statement stmt = conn.createStatement(); + conn = DriverManager.getConnection(url); + try (Statement stmt = conn.createStatement()) { stmt.execute("drop database if exists " + dbname); stmt.execute("create database if not exists " + dbname + " precision 'ns'"); stmt.execute("use " + dbname); - } catch (SQLException e) { - e.printStackTrace(); } } diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/NanoSecondTimestampRestfulTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/NanoSecondTimestampRestfulTest.java index 4271f918b9b096000cc59b730d7b70f032a0ab29..c8aaf5c6788d18e782e431ba4ed97fb69f4702ab 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/NanoSecondTimestampRestfulTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/NanoSecondTimestampRestfulTest.java @@ -17,7 +17,7 @@ public class NanoSecondTimestampRestfulTest { private static Connection conn; @Test - public void insertUsingLongValue() { + public void insertUsingLongValue() throws SQLException { // given long ms = System.currentTimeMillis(); long ns = ms * 1000_000 + random.nextInt(1000_000); @@ -26,8 +26,6 @@ public class NanoSecondTimestampRestfulTest { int ret = 0; try (Statement stmt = conn.createStatement()) { ret = stmt.executeUpdate("insert into weather(ts, temperature, humidity) values(" + ns + ", 12.3, 4)"); - } catch (SQLException e) { - e.printStackTrace(); } // then @@ -35,15 +33,13 @@ public class NanoSecondTimestampRestfulTest { } @Test - public void insertUsingStringValue() { + public void insertUsingStringValue() throws SQLException { // given // when int ret = 0; try (Statement stmt = conn.createStatement()) { ret = stmt.executeUpdate("insert into weather(ts, temperature, humidity) values('2021-01-01 12:00:00.123456789', 12.3, 4)"); - } catch (SQLException e) { - e.printStackTrace(); } // then @@ -51,7 +47,7 @@ public class NanoSecondTimestampRestfulTest { } @Test - public void insertUsingTimestampValue() { + public void insertUsingTimestampValue() throws SQLException { // given long epochSec = System.currentTimeMillis() / 1000; long nanoAdjustment = random.nextInt(1000_000_000); @@ -65,8 +61,6 @@ public class NanoSecondTimestampRestfulTest { pstmt.setFloat(2, 12.34f); pstmt.setInt(3, 55); ret = pstmt.executeUpdate(); - } catch (SQLException e) { - e.printStackTrace(); } // then @@ -80,13 +74,11 @@ public class NanoSecondTimestampRestfulTest { long ns = ms * 1000_000L + random.nextInt(1000_000); // when - ResultSet rs = null; + ResultSet rs; try (Statement stmt = conn.createStatement()) { stmt.executeUpdate("insert into weather(ts, temperature, humidity) values(" + ns + ", 12.3, 4)"); rs = stmt.executeQuery("select * from weather"); rs.next(); - } catch (SQLException e) { - e.printStackTrace(); } // then @@ -102,13 +94,11 @@ public class NanoSecondTimestampRestfulTest { String timestampStr = "2021-01-01 12:00:00.123456789"; // when - ResultSet rs = null; + ResultSet rs; try (Statement stmt = conn.createStatement()) { stmt.executeUpdate("insert into weather(ts, temperature, humidity) values('" + timestampStr + "', 12.3, 4)"); rs = stmt.executeQuery("select * from weather"); rs.next(); - } catch (SQLException e) { - e.printStackTrace(); } // then @@ -133,8 +123,6 @@ public class NanoSecondTimestampRestfulTest { pstmt.setFloat(2, 12.34f); pstmt.setInt(3, 55); pstmt.executeUpdate(); - } catch (SQLException e) { - e.printStackTrace(); } // when @@ -142,8 +130,6 @@ public class NanoSecondTimestampRestfulTest { try (Statement stmt = conn.createStatement()) { rs = stmt.executeQuery("select * from weather"); rs.next(); - } catch (SQLException e) { - e.printStackTrace(); } // then @@ -156,26 +142,21 @@ public class NanoSecondTimestampRestfulTest { } @Before - public void before() { + public void before() throws SQLException { try (Statement stmt = conn.createStatement()) { stmt.execute("drop table if exists weather"); stmt.execute("create table weather(ts timestamp, temperature float, humidity int)"); - } catch (SQLException e) { - e.printStackTrace(); } } @BeforeClass - public static void beforeClass() { + public static void beforeClass() throws SQLException { final String url = "jdbc:TAOS-RS://" + host + ":6041/?user=root&password=taosdata"; - try { - conn = DriverManager.getConnection(url); - Statement stmt = conn.createStatement(); + conn = DriverManager.getConnection(url); + try (Statement stmt = conn.createStatement()) { stmt.execute("drop database if exists " + dbname); stmt.execute("create database if not exists " + dbname + " precision 'ns'"); stmt.execute("use " + dbname); - } catch (SQLException e) { - e.printStackTrace(); } } diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/NullValueInResultSetJNITest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/NullValueInResultSetJNITest.java index ae0241bf31eea85083bf102c4123f7e30c2bd693..6efd9f5ebee29a122c2106439117738c44241597 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/NullValueInResultSetJNITest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/NullValueInResultSetJNITest.java @@ -12,15 +12,13 @@ public class NullValueInResultSetJNITest { Connection conn; @Test - public void test() { + public void test() throws SQLException { try (Statement stmt = conn.createStatement()) { ResultSet rs = stmt.executeQuery("select * from weather"); ResultSetMetaData meta = rs.getMetaData(); while (rs.next()) { } - } catch (SQLException e) { - e.printStackTrace(); } } @@ -42,18 +40,12 @@ public class NullValueInResultSetJNITest { stmt.executeUpdate("insert into weather(ts, f7) values(now+7s, true)"); stmt.executeUpdate("insert into weather(ts, f8) values(now+8s, 'hello')"); stmt.executeUpdate("insert into weather(ts, f9) values(now+9s, '涛思数据')"); - } catch (SQLException e) { - e.printStackTrace(); } } @After - public void after() { - try { - if (conn != null) - conn.close(); - } catch (SQLException e) { - e.printStackTrace(); - } + public void after() throws SQLException { + if (conn != null) + conn.close(); } } diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/NullValueInResultSetRestfulTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/NullValueInResultSetRestfulTest.java index 7fbb30a5244a53129807cd76472674ff1cfd6ae4..f331a58583db832124465492d07f24f1772348ce 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/NullValueInResultSetRestfulTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/NullValueInResultSetRestfulTest.java @@ -12,7 +12,7 @@ public class NullValueInResultSetRestfulTest { Connection conn; @Test - public void test() { + public void test() throws SQLException { try (Statement stmt = conn.createStatement()) { ResultSet rs = stmt.executeQuery("select * from weather"); ResultSetMetaData meta = rs.getMetaData(); @@ -21,9 +21,6 @@ public class NullValueInResultSetRestfulTest { Object value = rs.getObject(i); } } - - } catch (SQLException e) { - e.printStackTrace(); } } @@ -45,18 +42,12 @@ public class NullValueInResultSetRestfulTest { stmt.executeUpdate("insert into weather(ts, f7) values(now+7s, true)"); stmt.executeUpdate("insert into weather(ts, f8) values(now+8s, 'hello')"); stmt.executeUpdate("insert into weather(ts, f9) values(now+9s, '涛思数据')"); - } catch (SQLException e) { - e.printStackTrace(); } } @After - public void after() { - try { - if (conn != null) - conn.close(); - } catch (SQLException e) { - e.printStackTrace(); - } + public void after() throws SQLException { + if (conn != null) + conn.close(); } } diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/PreparedStatementBatchInsertRestfulTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/PreparedStatementBatchInsertRestfulTest.java index 90b285381a2ab57b170da327a95dde4c8991ce21..85fbeef1b589434dc17267af20510bc2a8ebd554 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/PreparedStatementBatchInsertRestfulTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/PreparedStatementBatchInsertRestfulTest.java @@ -20,7 +20,7 @@ public class PreparedStatementBatchInsertRestfulTest { private Connection conn; @Test - public void test() { + public void test() throws SQLException { // given long ts = System.currentTimeMillis(); List rows = IntStream.range(0, 10).mapToObj(i -> { @@ -52,7 +52,6 @@ public class PreparedStatementBatchInsertRestfulTest { } pstmt.executeBatch(); } catch (SQLException e) { - e.printStackTrace(); Assert.fail(); } @@ -64,35 +63,25 @@ public class PreparedStatementBatchInsertRestfulTest { count++; } Assert.assertEquals(10, count); - } catch (SQLException e) { - e.printStackTrace(); } } @Before - public void before() { - try { - conn = DriverManager.getConnection("jdbc:TAOS-RS://" + host + ":6041/?user=root&password=taosdata"); - Statement stmt = conn.createStatement(); - stmt.execute("drop database if exists " + dbname); - stmt.execute("create database if not exists " + dbname); - stmt.execute("use " + dbname); - stmt.execute("create table meters(ts timestamp, current float, voltage int, phase int) tags(groupId int)"); - } catch (SQLException e) { - e.printStackTrace(); - } + public void before() throws SQLException { + conn = DriverManager.getConnection("jdbc:TAOS-RS://" + host + ":6041/?user=root&password=taosdata"); + Statement stmt = conn.createStatement(); + stmt.execute("drop database if exists " + dbname); + stmt.execute("create database if not exists " + dbname); + stmt.execute("use " + dbname); + stmt.execute("create table meters(ts timestamp, current float, voltage int, phase int) tags(groupId int)"); } @After - public void after() { - try { - Statement stmt = conn.createStatement(); - stmt.execute("drop database if exists " + dbname); - stmt.close(); - conn.close(); - } catch (SQLException e) { - e.printStackTrace(); - } + public void after() throws SQLException { + Statement stmt = conn.createStatement(); + stmt.execute("drop database if exists " + dbname); + stmt.close(); + conn.close(); } } diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/QueryDataTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/QueryDataTest.java index b4449491a93c2ffc857448b8697e771eabd0f97a..fd74e9433a786f407f75e2a28a9b5672f7373b8b 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/QueryDataTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/QueryDataTest.java @@ -19,26 +19,22 @@ public class QueryDataTest { static String host = "127.0.0.1"; @Before - public void createDatabase() { - try { - Properties properties = new Properties(); - properties.setProperty(TSDBDriver.PROPERTY_KEY_USER, "root"); - properties.setProperty(TSDBDriver.PROPERTY_KEY_PASSWORD, "taosdata"); - 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 + ":0/", properties); - - statement = connection.createStatement(); - statement.executeUpdate("drop database if exists " + dbName); - statement.executeUpdate("create database if not exists " + dbName); - statement.executeUpdate("use " + dbName); - - String createTableSql = "create table " + stbName + "(ts timestamp, name binary(64))"; - statement.executeUpdate(createTableSql); - } catch (SQLException e) { - e.printStackTrace(); - } + public void createDatabase() throws SQLException { + Properties properties = new Properties(); + properties.setProperty(TSDBDriver.PROPERTY_KEY_USER, "root"); + properties.setProperty(TSDBDriver.PROPERTY_KEY_PASSWORD, "taosdata"); + 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 + ":0/", properties); + + statement = connection.createStatement(); + statement.executeUpdate("drop database if exists " + dbName); + statement.executeUpdate("create database if not exists " + dbName); + statement.executeUpdate("use " + dbName); + + String createTableSql = "create table " + stbName + "(ts timestamp, name binary(64))"; + statement.executeUpdate(createTableSql); } @Test @@ -57,15 +53,11 @@ public class QueryDataTest { } @After - public void close() { - try { - if (statement != null) - statement.close(); - if (connection != null) - connection.close(); - } catch (SQLException e) { - e.printStackTrace(); - } + public void close() throws SQLException { + if (statement != null) + statement.close(); + if (connection != null) + connection.close(); } } \ No newline at end of file diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/ResultSetMetaShouldNotBeNullRestfulTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/ResultSetMetaShouldNotBeNullRestfulTest.java index be27b1350781245e3056185db4bbaa8b5105d2f0..ff0dad1bda4b8defa8c515011604deeddf13f95b 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/ResultSetMetaShouldNotBeNullRestfulTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/ResultSetMetaShouldNotBeNullRestfulTest.java @@ -15,19 +15,15 @@ public class ResultSetMetaShouldNotBeNullRestfulTest { private Connection connection; @Test - public void testExecuteQuery() { + public void testExecuteQuery() throws SQLException { // given - ResultSetMetaData metaData = null; - int columnCount = -1; + ResultSetMetaData metaData; + int columnCount; // when - try { - Statement statement = connection.createStatement(); - metaData = statement.executeQuery("select * from weather").getMetaData(); - columnCount = metaData.getColumnCount(); - } catch (SQLException e) { - e.printStackTrace(); - } + Statement statement = connection.createStatement(); + metaData = statement.executeQuery("select * from weather").getMetaData(); + columnCount = metaData.getColumnCount(); // then Assert.assertNotNull(metaData); @@ -35,20 +31,17 @@ public class ResultSetMetaShouldNotBeNullRestfulTest { } @Test - public void testExecute() { + public void testExecute() throws SQLException { // given - ResultSetMetaData metaData = null; - int columnCount = -1; - boolean execute = false; + ResultSetMetaData metaData; + int columnCount; + boolean execute; + // when - try { - Statement statement = connection.createStatement(); - execute = statement.execute("select * from weather"); - metaData = statement.getResultSet().getMetaData(); - columnCount = metaData.getColumnCount(); - } catch (SQLException e) { - e.printStackTrace(); - } + Statement statement = connection.createStatement(); + execute = statement.execute("select * from weather"); + metaData = statement.getResultSet().getMetaData(); + columnCount = metaData.getColumnCount(); // then Assert.assertEquals(true, execute); @@ -57,30 +50,22 @@ public class ResultSetMetaShouldNotBeNullRestfulTest { } @Before - public void before() { - try { - connection = DriverManager.getConnection("jdbc:TAOS-RS://" + host + ":6041/?user=root&password=taosdata"); - Statement stmt = connection.createStatement(); - stmt.execute("drop database if exists " + dbname); - stmt.execute("create database if not exists " + dbname); - stmt.execute("use " + dbname); - stmt.execute("create table weather (ts timestamp, temperature float)"); - stmt.close(); - } catch (SQLException e) { - e.printStackTrace(); - } + public void before() throws SQLException { + connection = DriverManager.getConnection("jdbc:TAOS-RS://" + host + ":6041/?user=root&password=taosdata"); + Statement stmt = connection.createStatement(); + stmt.execute("drop database if exists " + dbname); + stmt.execute("create database if not exists " + dbname); + stmt.execute("use " + dbname); + stmt.execute("create table weather (ts timestamp, temperature float)"); + stmt.close(); } @After - public void after() { - try { - Statement stmt = connection.createStatement(); - stmt.execute("drop database if exists " + dbname); - stmt.close(); - connection.close(); - } catch (SQLException e) { - e.printStackTrace(); - } + public void after() throws SQLException { + Statement stmt = connection.createStatement(); + stmt.execute("drop database if exists " + dbname); + stmt.close(); + connection.close(); } } diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/SelectTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/SelectTest.java index b51c0309be809250839a5241d12296182067dfd3..79e5602e9e6c436d5671cc1c92847e54949d9025 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/SelectTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/SelectTest.java @@ -17,25 +17,20 @@ public class SelectTest { String host = "127.0.0.1"; @Before - public void createDatabaseAndTable() { - try { - Properties properties = new Properties(); - properties.setProperty(TSDBDriver.PROPERTY_KEY_USER, "root"); - properties.setProperty(TSDBDriver.PROPERTY_KEY_PASSWORD, "taosdata"); - 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 + ":0/", properties); - - Statement stmt = connection.createStatement(); - stmt.execute("drop database if exists " + dbName); - stmt.execute("create database if not exists " + dbName); - stmt.execute("create table if not exists " + dbName + "." + tName + " (ts timestamp, k int, v int)"); - stmt.close(); - } catch (SQLException e) { - e.printStackTrace(); - } + public void createDatabaseAndTable() throws SQLException { + Properties properties = new Properties(); + properties.setProperty(TSDBDriver.PROPERTY_KEY_USER, "root"); + properties.setProperty(TSDBDriver.PROPERTY_KEY_PASSWORD, "taosdata"); + 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 + ":0/", properties); + Statement stmt = connection.createStatement(); + stmt.execute("drop database if exists " + dbName); + stmt.execute("create database if not exists " + dbName); + stmt.execute("create table if not exists " + dbName + "." + tName + " (ts timestamp, k int, v int)"); + stmt.close(); } @Test @@ -65,16 +60,12 @@ public class SelectTest { } @After - public void close() { - try { - if (connection != null) { - Statement stmt = connection.createStatement(); - stmt.executeUpdate("drop database " + dbName); - stmt.close(); - connection.close(); - } - } catch (SQLException e) { - e.printStackTrace(); + public void close() throws SQLException { + if (connection != null) { + Statement stmt = connection.createStatement(); + stmt.executeUpdate("drop database " + dbName); + stmt.close(); + connection.close(); } } } diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/TaosInfoMonitorTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/TaosInfoMonitorTest.java deleted file mode 100644 index 7df9f7380704eefb51b26214295624995811c84f..0000000000000000000000000000000000000000 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/TaosInfoMonitorTest.java +++ /dev/null @@ -1,49 +0,0 @@ -package com.taosdata.jdbc.cases; - -import org.junit.Test; - -import java.sql.*; -import java.util.List; -import java.util.concurrent.TimeUnit; -import java.util.stream.Collectors; -import java.util.stream.IntStream; - -public class TaosInfoMonitorTest { - - @Test - public void testCreateTooManyConnection() throws ClassNotFoundException { - Class.forName("com.taosdata.jdbc.TSDBDriver"); - final String url = "jdbc:TAOS://127.0.0.1:6030/?user=root&password=taosdata"; - - List connectionList = IntStream.range(0, 100).mapToObj(i -> { - try { - TimeUnit.MILLISECONDS.sleep(100); - return DriverManager.getConnection(url); - } catch (SQLException | InterruptedException e) { - e.printStackTrace(); - } - return null; - }).collect(Collectors.toList()); - - connectionList.forEach(conn -> { - try (Statement stmt = conn.createStatement()) { - ResultSet rs = stmt.executeQuery("show databases"); - while (rs.next()) { - - } - TimeUnit.MILLISECONDS.sleep(100); - } catch (SQLException | InterruptedException e) { - e.printStackTrace(); - } - }); - - connectionList.forEach(conn -> { - try { - conn.close(); - TimeUnit.MILLISECONDS.sleep(100); - } catch (SQLException | InterruptedException e) { - e.printStackTrace(); - } - }); - } -} diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/TimestampPrecisionInNanoInJniTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/TimestampPrecisionInNanoInJniTest.java index 72734cb0ecdfe67cbd02306acef3ae8625f942b0..2d336135e5d1dc28db010387ab838f17d9b9a9cc 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/TimestampPrecisionInNanoInJniTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/TimestampPrecisionInNanoInJniTest.java @@ -25,7 +25,7 @@ public class TimestampPrecisionInNanoInJniTest { private static final String date4 = format.format(new Date(timestamp1 + 10L)); private static final String date2 = date1 + "123455"; private static final String date3 = date4 + "123456"; - + private static Connection conn; @@ -43,7 +43,7 @@ public class TimestampPrecisionInNanoInJniTest { stmt.execute("drop database if exists " + ns_timestamp_db); stmt.execute("create database if not exists " + ns_timestamp_db + " precision 'ns'"); stmt.execute("create table " + ns_timestamp_db + ".weather(ts timestamp, ts2 timestamp, f1 int)"); - stmt.executeUpdate("insert into " + ns_timestamp_db + ".weather(ts, ts2, f1) values(\"" + date3 + "\", \"" + date3 + "\", 128)"); + stmt.executeUpdate("insert into " + ns_timestamp_db + ".weather(ts, ts2, f1) values(\"" + date3 + "\", \"" + date3 + "\", 128)"); stmt.executeUpdate("insert into " + ns_timestamp_db + ".weather(ts, ts2, f1) values(" + timestamp2 + "," + timestamp2 + ", 127)"); stmt.close(); } @@ -54,7 +54,7 @@ public class TimestampPrecisionInNanoInJniTest { stmt.execute("drop database if exists " + ns_timestamp_db); stmt.execute("create database if not exists " + ns_timestamp_db + " precision 'ns'"); stmt.execute("create table " + ns_timestamp_db + ".weather(ts timestamp, ts2 timestamp, f1 int)"); - stmt.executeUpdate("insert into " + ns_timestamp_db + ".weather(ts, ts2, f1) values(\"" + date3 + "\", \"" + date3 + "\", 128)"); + stmt.executeUpdate("insert into " + ns_timestamp_db + ".weather(ts, ts2, f1) values(\"" + date3 + "\", \"" + date3 + "\", 128)"); stmt.executeUpdate("insert into " + ns_timestamp_db + ".weather(ts, ts2, f1) values(" + timestamp2 + "," + timestamp2 + ", 127)"); stmt.close(); } @@ -105,7 +105,7 @@ public class TimestampPrecisionInNanoInJniTest { @Test public void canImportTimestampAndQueryByEqualToInDateTypeInBothFirstAndSecondCol() { try (Statement stmt = conn.createStatement()) { - stmt.executeUpdate("import into " + ns_timestamp_db + ".weather(ts, ts2, f1) values(\"" + date1 + "123123\", \"" + date1 + "123123\", 127)"); + stmt.executeUpdate("import into " + ns_timestamp_db + ".weather(ts, ts2, f1) values(\"" + date1 + "123123\", \"" + date1 + "123123\", 127)"); ResultSet rs = stmt.executeQuery("select count(*) from " + ns_timestamp_db + ".weather where ts = '" + date1 + "123123'"); checkCount(1l, rs); rs = stmt.executeQuery("select ts from " + ns_timestamp_db + ".weather where ts = '" + date1 + "123123'"); @@ -139,7 +139,7 @@ public class TimestampPrecisionInNanoInJniTest { public void canImportTimestampAndQueryByEqualToInNumberTypeInBothFirstAndSecondCol() { try (Statement stmt = conn.createStatement()) { long timestamp4 = timestamp1 * 1000_000 + 123123; - stmt.executeUpdate("import into " + ns_timestamp_db + ".weather(ts, ts2, f1) values(" + timestamp4 + ", " + timestamp4 + ", 127)"); + stmt.executeUpdate("import into " + ns_timestamp_db + ".weather(ts, ts2, f1) values(" + timestamp4 + ", " + timestamp4 + ", 127)"); ResultSet rs = stmt.executeQuery("select count(*) from " + ns_timestamp_db + ".weather where ts = '" + timestamp4 + "'"); checkCount(1l, rs); rs = stmt.executeQuery("select ts from " + ns_timestamp_db + ".weather where ts = '" + timestamp4 + "'"); @@ -184,300 +184,248 @@ public class TimestampPrecisionInNanoInJniTest { } @Test - public void canSelectFirstRowFromWeatherForSecondCol() { + public void canSelectFirstRowFromWeatherForSecondCol() throws SQLException { try (Statement stmt = conn.createStatement()) { ResultSet rs = stmt.executeQuery("select first(ts2) from " + ns_timestamp_db + ".weather"); checkTime(timestamp2, rs); - } catch (SQLException e) { - e.printStackTrace(); } } @Test - public void canQueryLargerThanInDateTypeForFirstCol() { + public void canQueryLargerThanInDateTypeForFirstCol() throws SQLException { try (Statement stmt = conn.createStatement()) { ResultSet rs = stmt.executeQuery("select count(*) from " + ns_timestamp_db + ".weather where ts > '" + date2 + "'"); checkCount(1l, rs); rs = stmt.executeQuery("select ts from " + ns_timestamp_db + ".weather where ts > '" + date2 + "'"); checkTime(timestamp3, rs); - } catch (SQLException e) { - e.printStackTrace(); } } @Test - public void canQueryLargerThanInDateTypeForSecondCol() { + public void canQueryLargerThanInDateTypeForSecondCol() throws SQLException { try (Statement stmt = conn.createStatement()) { ResultSet rs = stmt.executeQuery("select count(*) from " + ns_timestamp_db + ".weather where ts2 > '" + date2 + "'"); checkCount(1l, rs); rs = stmt.executeQuery("select ts2 from " + ns_timestamp_db + ".weather where ts2 > '" + date2 + "'"); checkTime(timestamp3, rs); - } catch (SQLException e) { - e.printStackTrace(); } - } + } @Test - public void canQueryLargerThanInNumberTypeForFirstCol() { + public void canQueryLargerThanInNumberTypeForFirstCol() throws SQLException { try (Statement stmt = conn.createStatement()) { ResultSet rs = stmt.executeQuery("select count(*) from " + ns_timestamp_db + ".weather where ts > '" + timestamp2 + "'"); checkCount(1l, rs); rs = stmt.executeQuery("select ts from " + ns_timestamp_db + ".weather where ts > '" + timestamp2 + "'"); checkTime(timestamp3, rs); - } catch (SQLException e) { - e.printStackTrace(); } } @Test - public void canQueryLargerThanInNumberTypeForSecondCol() { + public void canQueryLargerThanInNumberTypeForSecondCol() throws SQLException { try (Statement stmt = conn.createStatement()) { ResultSet rs = stmt.executeQuery("select count(*) from " + ns_timestamp_db + ".weather where ts2 > '" + timestamp2 + "'"); checkCount(1l, rs); rs = stmt.executeQuery("select ts2 from " + ns_timestamp_db + ".weather where ts2 > '" + timestamp2 + "'"); checkTime(timestamp3, rs); - } catch (SQLException e) { - e.printStackTrace(); } } @Test - public void canQueryLargerThanOrEqualToInDateTypeForFirstCol() { + public void canQueryLargerThanOrEqualToInDateTypeForFirstCol() throws SQLException { try (Statement stmt = conn.createStatement()) { ResultSet rs = stmt.executeQuery("select count(*) from " + ns_timestamp_db + ".weather where ts >= '" + date2 + "'"); checkCount(2l, rs); - } catch (SQLException e) { - e.printStackTrace(); } } @Test - public void canQueryLargerThanOrEqualToInDateTypeForSecondCol() { + public void canQueryLargerThanOrEqualToInDateTypeForSecondCol() throws SQLException { try (Statement stmt = conn.createStatement()) { ResultSet rs = stmt.executeQuery("select count(*) from " + ns_timestamp_db + ".weather where ts2 >= '" + date2 + "'"); checkCount(2l, rs); - } catch (SQLException e) { - e.printStackTrace(); } } @Test - public void canQueryLargerThanOrEqualToInNumberTypeForFirstCol() { + public void canQueryLargerThanOrEqualToInNumberTypeForFirstCol() throws SQLException { try (Statement stmt = conn.createStatement()) { ResultSet rs = stmt.executeQuery("select count(*) from " + ns_timestamp_db + ".weather where ts >= '" + timestamp2 + "'"); checkCount(2l, rs); - } catch (SQLException e) { - e.printStackTrace(); } } @Test - public void canQueryLargerThanOrEqualToInNumberTypeForSecondCol() { + public void canQueryLargerThanOrEqualToInNumberTypeForSecondCol() throws SQLException { try (Statement stmt = conn.createStatement()) { ResultSet rs = stmt.executeQuery("select count(*) from " + ns_timestamp_db + ".weather where ts2 >= '" + timestamp2 + "'"); checkCount(2l, rs); - } catch (SQLException e) { - e.printStackTrace(); } - } + } @Test - public void canQueryLessThanInDateTypeForFirstCol() { + public void canQueryLessThanInDateTypeForFirstCol() throws SQLException { try (Statement stmt = conn.createStatement()) { ResultSet rs = stmt.executeQuery("select count(*) from " + ns_timestamp_db + ".weather where ts < '" + date3 + "'"); checkCount(1l, rs); rs = stmt.executeQuery("select ts from " + ns_timestamp_db + ".weather where ts < '" + date3 + "'"); checkTime(timestamp2, rs); - } catch (SQLException e) { - e.printStackTrace(); } } @Test - public void canQueryLessThanInDateTypeForSecondCol() { + public void canQueryLessThanInDateTypeForSecondCol() throws SQLException { try (Statement stmt = conn.createStatement()) { ResultSet rs = stmt.executeQuery("select count(*) from " + ns_timestamp_db + ".weather where ts2 < '" + date3 + "'"); checkCount(1l, rs); rs = stmt.executeQuery("select ts2 from " + ns_timestamp_db + ".weather where ts2 < '" + date3 + "'"); checkTime(timestamp2, rs); - } catch (SQLException e) { - e.printStackTrace(); } } @Test - public void canQueryLessThanInNumberTypeForFirstCol() { + public void canQueryLessThanInNumberTypeForFirstCol() throws SQLException { try (Statement stmt = conn.createStatement()) { ResultSet rs = stmt.executeQuery("select count(*) from " + ns_timestamp_db + ".weather where ts < '" + timestamp3 + "'"); checkCount(1l, rs); rs = stmt.executeQuery("select ts from " + ns_timestamp_db + ".weather where ts < '" + timestamp3 + "'"); checkTime(timestamp2, rs); - } catch (SQLException e) { - e.printStackTrace(); } } @Test - public void canQueryLessThanInNumberTypeForSecondCol() { + public void canQueryLessThanInNumberTypeForSecondCol() throws SQLException { try (Statement stmt = conn.createStatement()) { ResultSet rs = stmt.executeQuery("select count(*) from " + ns_timestamp_db + ".weather where ts2 < '" + timestamp3 + "'"); checkCount(1l, rs); rs = stmt.executeQuery("select ts2 from " + ns_timestamp_db + ".weather where ts2 < '" + timestamp3 + "'"); checkTime(timestamp2, rs); - } catch (SQLException e) { - e.printStackTrace(); } } @Test - public void canQueryLessThanOrEqualToInDateTypeForFirstCol() { + public void canQueryLessThanOrEqualToInDateTypeForFirstCol() throws SQLException { try (Statement stmt = conn.createStatement()) { ResultSet rs = stmt.executeQuery("select count(*) from " + ns_timestamp_db + ".weather where ts <= '" + date3 + "'"); checkCount(2l, rs); - } catch (SQLException e) { - e.printStackTrace(); } } @Test - public void canQueryLessThanOrEqualToInDateTypeForSecondCol() { + public void canQueryLessThanOrEqualToInDateTypeForSecondCol() throws SQLException { try (Statement stmt = conn.createStatement()) { ResultSet rs = stmt.executeQuery("select count(*) from " + ns_timestamp_db + ".weather where ts2 <= '" + date3 + "'"); checkCount(2l, rs); - } catch (SQLException e) { - e.printStackTrace(); } - } + } @Test - public void canQueryLessThanOrEqualToInNumberTypeForFirstCol() { + public void canQueryLessThanOrEqualToInNumberTypeForFirstCol() throws SQLException { try (Statement stmt = conn.createStatement()) { ResultSet rs = stmt.executeQuery("select count(*) from " + ns_timestamp_db + ".weather where ts <= '" + timestamp3 + "'"); checkCount(2l, rs); - } catch (SQLException e) { - e.printStackTrace(); } } @Test - public void canQueryLessThanOrEqualToInNumberTypeForSecondCol() { + public void canQueryLessThanOrEqualToInNumberTypeForSecondCol() throws SQLException { try (Statement stmt = conn.createStatement()) { ResultSet rs = stmt.executeQuery("select count(*) from " + ns_timestamp_db + ".weather where ts2 <= '" + timestamp3 + "'"); checkCount(2l, rs); - } catch (SQLException e) { - e.printStackTrace(); } } @Test - public void canQueryBetweenAndInDateTypeForFirstCol() { + public void canQueryBetweenAndInDateTypeForFirstCol() throws SQLException { try (Statement stmt = conn.createStatement()) { ResultSet rs = stmt.executeQuery("select count(*) from " + ns_timestamp_db + ".weather where ts <= '" + date3 + "' AND ts > '" + date2 + "'"); checkCount(1l, rs); rs = stmt.executeQuery("select ts from " + ns_timestamp_db + ".weather where ts <= '" + date3 + "' AND ts > '" + date2 + "'"); checkTime(timestamp3, rs); - } catch (SQLException e) { - e.printStackTrace(); } } @Test - public void canQueryBetweenAndInDateTypeForSecondCol() { + public void canQueryBetweenAndInDateTypeForSecondCol() throws SQLException { try (Statement stmt = conn.createStatement()) { ResultSet rs = stmt.executeQuery("select count(*) from " + ns_timestamp_db + ".weather where ts2 <= '" + date3 + "' AND ts2 > '" + date2 + "'"); checkCount(1l, rs); rs = stmt.executeQuery("select ts2 from " + ns_timestamp_db + ".weather where ts2 <= '" + date3 + "' AND ts2 > '" + date2 + "'"); checkTime(timestamp3, rs); - } catch (SQLException e) { - e.printStackTrace(); } } @Test - public void canQueryBetweenAndInNumberTypeForFirstCol() { + public void canQueryBetweenAndInNumberTypeForFirstCol() throws SQLException { try (Statement stmt = conn.createStatement()) { ResultSet rs = stmt.executeQuery("select count(*) from " + ns_timestamp_db + ".weather where ts <= '" + timestamp3 + "' AND ts > '" + timestamp2 + "'"); checkCount(1l, rs); rs = stmt.executeQuery("select ts from " + ns_timestamp_db + ".weather where ts <= '" + timestamp3 + "' AND ts > '" + timestamp2 + "'"); checkTime(timestamp3, rs); - } catch (SQLException e) { - e.printStackTrace(); } } @Test - public void canQueryBetweenAndInNumberTypeForSecondCol() { + public void canQueryBetweenAndInNumberTypeForSecondCol() throws SQLException { try (Statement stmt = conn.createStatement()) { ResultSet rs = stmt.executeQuery("select count(*) from " + ns_timestamp_db + ".weather where ts2 <= '" + timestamp3 + "' AND ts2 > '" + timestamp2 + "'"); checkCount(1l, rs); rs = stmt.executeQuery("select ts2 from " + ns_timestamp_db + ".weather where ts2 <= '" + timestamp3 + "' AND ts2 > '" + timestamp2 + "'"); checkTime(timestamp3, rs); - } catch (SQLException e) { - e.printStackTrace(); } } @Test - public void canQueryNotEqualToInDateTypeForSecondCol() { + public void canQueryNotEqualToInDateTypeForSecondCol() throws SQLException { try (Statement stmt = conn.createStatement()) { ResultSet rs = stmt.executeQuery("select count(*) from " + ns_timestamp_db + ".weather where ts2 <> '" + date3 + "'"); checkCount(1l, rs); rs = stmt.executeQuery("select ts2 from " + ns_timestamp_db + ".weather where ts2 <> '" + date3 + "'"); checkTime(timestamp2, rs); - } catch (SQLException e) { - e.printStackTrace(); } } @Test - public void canQueryNotEqualToInNumberTypeForSecondCol() { + public void canQueryNotEqualToInNumberTypeForSecondCol() throws SQLException { try (Statement stmt = conn.createStatement()) { ResultSet rs = stmt.executeQuery("select count(*) from " + ns_timestamp_db + ".weather where ts2 <> '" + timestamp3 + "'"); checkCount(1l, rs); rs = stmt.executeQuery("select ts2 from " + ns_timestamp_db + ".weather where ts2 <> '" + timestamp3 + "'"); checkTime(timestamp2, rs); - } catch (SQLException e) { - e.printStackTrace(); } } @Test - public void canQueryNotEqualInDateTypeForSecondCol() { + public void canQueryNotEqualInDateTypeForSecondCol() throws SQLException { try (Statement stmt = conn.createStatement()) { ResultSet rs = stmt.executeQuery("select count(*) from " + ns_timestamp_db + ".weather where ts2 != '" + date3 + "'"); checkCount(1l, rs); rs = stmt.executeQuery("select ts2 from " + ns_timestamp_db + ".weather where ts2 != '" + date3 + "'"); checkTime(timestamp2, rs); - } catch (SQLException e) { - e.printStackTrace(); } } @Test - public void canQueryNotEqualInNumberTypeForSecondCol() { + public void canQueryNotEqualInNumberTypeForSecondCol() throws SQLException { try (Statement stmt = conn.createStatement()) { ResultSet rs = stmt.executeQuery("select count(*) from " + ns_timestamp_db + ".weather where ts2 != '" + timestamp3 + "'"); checkCount(1l, rs); rs = stmt.executeQuery("select ts2 from " + ns_timestamp_db + ".weather where ts2 != '" + timestamp3 + "'"); checkTime(timestamp2, rs); - } catch (SQLException e) { - e.printStackTrace(); } } @Test - public void canInsertTimestampWithNowAndNsOffsetInBothFirstAndSecondCol(){ + public void canInsertTimestampWithNowAndNsOffsetInBothFirstAndSecondCol() throws SQLException { try (Statement stmt = conn.createStatement()) { stmt.executeUpdate("insert into " + ns_timestamp_db + ".weather(ts, ts2, f1) values(now + 1000b, now - 1000b, 128)"); ResultSet rs = stmt.executeQuery("select count(*) from " + ns_timestamp_db + ".weather"); checkCount(3l, rs); - } catch (SQLException e) { - e.printStackTrace(); } } @Test - public void canIntervalAndSlidingAcceptNsUnitForFirstCol(){ + public void canIntervalAndSlidingAcceptNsUnitForFirstCol() throws SQLException { try (Statement stmt = conn.createStatement()) { ResultSet rs = stmt.executeQuery("select sum(f1) from " + ns_timestamp_db + ".weather where ts >= '" + date2 + "' and ts <= '" + date3 + "' interval(10000000b) sliding(10000000b)"); rs.next(); @@ -486,13 +434,11 @@ public class TimestampPrecisionInNanoInJniTest { rs.next(); sum = rs.getLong(2); Assert.assertEquals(128l, sum); - } catch (SQLException e) { - e.printStackTrace(); } } @Test - public void canIntervalAndSlidingAcceptNsUnitForSecondCol(){ + public void canIntervalAndSlidingAcceptNsUnitForSecondCol() throws SQLException { try (Statement stmt = conn.createStatement()) { ResultSet rs = stmt.executeQuery("select sum(f1) from " + ns_timestamp_db + ".weather where ts2 >= '" + date2 + "' and ts <= '" + date3 + "' interval(10000000b) sliding(10000000b)"); rs.next(); @@ -501,8 +447,6 @@ public class TimestampPrecisionInNanoInJniTest { rs.next(); sum = rs.getLong(2); Assert.assertEquals(128l, sum); - } catch (SQLException e) { - e.printStackTrace(); } } @@ -525,46 +469,38 @@ public class TimestampPrecisionInNanoInJniTest { } @Test - public void willAutomaticallyFillToNsUnitWithZerosForFirstCol() { + public void willAutomaticallyFillToNsUnitWithZerosForFirstCol() throws SQLException { try (Statement stmt = conn.createStatement()) { stmt.executeUpdate("insert into " + ns_timestamp_db + ".weather(ts, ts2, f1) values('" + date1 + "', '" + date1 + "', 127)"); ResultSet rs = stmt.executeQuery("select count(*) from " + ns_timestamp_db + ".weather where ts = '" + date1 + "000000'"); checkCount(1l, rs); - } catch (SQLException e) { - e.printStackTrace(); } } @Test - public void willAutomaticallyFillToNsUnitWithZerosForSecondCol() { + public void willAutomaticallyFillToNsUnitWithZerosForSecondCol() throws SQLException { try (Statement stmt = conn.createStatement()) { stmt.executeUpdate("insert into " + ns_timestamp_db + ".weather(ts, ts2, f1) values('" + date1 + "', '" + date1 + "', 127)"); ResultSet rs = stmt.executeQuery("select count(*) from " + ns_timestamp_db + ".weather where ts2 = '" + date1 + "000000'"); checkCount(1l, rs); - } catch (SQLException e) { - e.printStackTrace(); } } @Test - public void willAutomaticallyDropDigitExceedNsDigitNumberForFirstCol() { + public void willAutomaticallyDropDigitExceedNsDigitNumberForFirstCol() throws SQLException { try (Statement stmt = conn.createStatement()) { stmt.executeUpdate("insert into " + ns_timestamp_db + ".weather(ts, ts2, f1) values('" + date1 + "999999999', '" + date1 + "999999999', 127)"); ResultSet rs = stmt.executeQuery("select count(*) from " + ns_timestamp_db + ".weather where ts = '" + date1 + "999999'"); checkCount(1l, rs); - } catch (SQLException e) { - e.printStackTrace(); } } @Test - public void willAutomaticallyDropDigitExceedNsDigitNumberForSecondCol() { + public void willAutomaticallyDropDigitExceedNsDigitNumberForSecondCol() throws SQLException { try (Statement stmt = conn.createStatement()) { stmt.executeUpdate("insert into " + ns_timestamp_db + ".weather(ts, ts2, f1) values('" + date1 + "999999999', '" + date1 + "999999999', 127)"); ResultSet rs = stmt.executeQuery("select count(*) from " + ns_timestamp_db + ".weather where ts2 = '" + date1 + "999999'"); checkCount(1l, rs); - } catch (SQLException e) { - e.printStackTrace(); } } } diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/UnsignedNumberJniTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/UnsignedNumberJniTest.java index e4149793aca46ebe5df47aec002828441fef481d..0be6b90e7a9b5e1e7707b88c1c60d2751b7d245b 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/UnsignedNumberJniTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/UnsignedNumberJniTest.java @@ -15,7 +15,7 @@ public class UnsignedNumberJniTest { private static long ts; @Test - public void testCase001() { + public void testCase001() throws SQLException { try (Statement stmt = conn.createStatement()) { ResultSet rs = stmt.executeQuery("select * from us_table"); ResultSetMetaData meta = rs.getMetaData(); @@ -27,13 +27,11 @@ public class UnsignedNumberJniTest { Assert.assertEquals("2147483647", rs.getString(4)); Assert.assertEquals("9223372036854775807", rs.getString(5)); } - } catch (SQLException e) { - e.printStackTrace(); } } @Test - public void testCase002() { + public void testCase002() throws SQLException { try (Statement stmt = conn.createStatement()) { ResultSet rs = stmt.executeQuery("select * from us_table"); ResultSetMetaData meta = rs.getMetaData(); @@ -46,8 +44,6 @@ public class UnsignedNumberJniTest { Assert.assertEquals(2147483647, rs.getInt(4)); Assert.assertEquals(9223372036854775807L, rs.getLong(5)); } - } catch (SQLException e) { - e.printStackTrace(); } } @@ -140,36 +136,28 @@ public class UnsignedNumberJniTest { } @BeforeClass - public static void beforeClass() { + public static void beforeClass() throws SQLException { 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"); ts = System.currentTimeMillis(); - try { - final String url = "jdbc:TAOS://" + host + ":6030/?user=root&password=taosdata"; - conn = DriverManager.getConnection(url, properties); - Statement stmt = conn.createStatement(); - stmt.execute("drop database if exists unsign_jni"); - stmt.execute("create database if not exists unsign_jni"); - stmt.execute("use unsign_jni"); - stmt.execute("create table us_table(ts timestamp, f1 tinyint unsigned, f2 smallint unsigned, f3 int unsigned, f4 bigint unsigned)"); - stmt.executeUpdate("insert into us_table(ts,f1,f2,f3,f4) values(" + ts + ", 127, 32767,2147483647, 9223372036854775807)"); - stmt.close(); - } catch (SQLException e) { - e.printStackTrace(); - } + final String url = "jdbc:TAOS://" + host + ":6030/?user=root&password=taosdata"; + conn = DriverManager.getConnection(url, properties); + Statement stmt = conn.createStatement(); + stmt.execute("drop database if exists unsign_jni"); + stmt.execute("create database if not exists unsign_jni"); + stmt.execute("use unsign_jni"); + stmt.execute("create table us_table(ts timestamp, f1 tinyint unsigned, f2 smallint unsigned, f3 int unsigned, f4 bigint unsigned)"); + stmt.executeUpdate("insert into us_table(ts,f1,f2,f3,f4) values(" + ts + ", 127, 32767,2147483647, 9223372036854775807)"); + stmt.close(); } @AfterClass - public static void afterClass() { - try { - if (conn != null) - conn.close(); - } catch (SQLException e) { - e.printStackTrace(); - } + public static void afterClass() throws SQLException { + if (conn != null) + conn.close(); } } diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/UnsignedNumberRestfulTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/UnsignedNumberRestfulTest.java index 3bdf5ae4f2404db5f56e27b740d4e4951e10818d..842dbfeff8478115df93b48cfe29fe376c4cff05 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/UnsignedNumberRestfulTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/UnsignedNumberRestfulTest.java @@ -16,7 +16,7 @@ public class UnsignedNumberRestfulTest { private static long ts; @Test - public void testCase001() { + public void testCase001() throws SQLException { try (Statement stmt = conn.createStatement()) { ResultSet rs = stmt.executeQuery("select * from us_table"); ResultSetMetaData meta = rs.getMetaData(); @@ -28,13 +28,11 @@ public class UnsignedNumberRestfulTest { Assert.assertEquals("2147483647", rs.getString(4)); Assert.assertEquals("9223372036854775807", rs.getString(5)); } - } catch (SQLException e) { - e.printStackTrace(); } } @Test - public void testCase002() { + public void testCase002() throws SQLException { try (Statement stmt = conn.createStatement()) { ResultSet rs = stmt.executeQuery("select * from us_table"); ResultSetMetaData meta = rs.getMetaData(); @@ -47,8 +45,6 @@ public class UnsignedNumberRestfulTest { Assert.assertEquals(2147483647, rs.getInt(4)); Assert.assertEquals(9223372036854775807L, rs.getLong(5)); } - } catch (SQLException e) { - e.printStackTrace(); } } diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/UseNowInsertTimestampTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/UseNowInsertTimestampTest.java index fbce021d1bff3655eedcf487dbcbf4747d5f9897..2e0448bc248bb2a962466e632443d4e6d918ab9f 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/UseNowInsertTimestampTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/UseNowInsertTimestampTest.java @@ -1,6 +1,5 @@ package com.taosdata.jdbc.cases; -import org.junit.Before; import org.junit.Test; import java.sql.*; @@ -12,7 +11,7 @@ public class UseNowInsertTimestampTest { String url = "jdbc:TAOS://127.0.0.1:6030/?user=root&password=taosdata"; @Test - public void millisec() { + public void millisec() throws SQLException { try (Connection conn = DriverManager.getConnection(url)) { Statement stmt = conn.createStatement(); stmt.execute("drop database if exists test"); @@ -30,13 +29,11 @@ public class UseNowInsertTimestampTest { assertEquals(0, nanos % 1000_000); stmt.execute("drop database if exists test"); - } catch (SQLException e) { - e.printStackTrace(); } } @Test - public void microsec() { + public void microsec() throws SQLException { try (Connection conn = DriverManager.getConnection(url)) { Statement stmt = conn.createStatement(); stmt.execute("drop database if exists test"); @@ -53,13 +50,11 @@ public class UseNowInsertTimestampTest { assertEquals(0, nanos % 1000); stmt.execute("drop database if exists test"); - } catch (SQLException e) { - e.printStackTrace(); } } @Test - public void nanosec() { + public void nanosec() throws SQLException { try (Connection conn = DriverManager.getConnection(url)) { Statement stmt = conn.createStatement(); stmt.execute("drop database if exists test"); @@ -77,8 +72,6 @@ public class UseNowInsertTimestampTest { assertTrue(nanos % 1000 != 0); stmt.execute("drop database if exists test"); - } catch (SQLException e) { - e.printStackTrace(); } } } diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/confprops/BadLocaleSettingTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/confprops/BadLocaleSettingTest.java new file mode 100644 index 0000000000000000000000000000000000000000..bbf71349b85c7bdc51fde30f293c7cd724de3699 --- /dev/null +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/confprops/BadLocaleSettingTest.java @@ -0,0 +1,51 @@ +package com.taosdata.jdbc.confprops; + + +import com.taosdata.jdbc.TSDBDriver; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.Properties; + +public class BadLocaleSettingTest { + + private static final String host = "127.0.0.1"; + private static final String dbName = "bad_locale_test"; + private static Connection conn; + + @Test + public void canSetLocale() throws SQLException { + 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"); + + String url = "jdbc:TAOS://" + host + ":6030/?user=root&password=taosdata"; + conn = DriverManager.getConnection(url, properties); + Statement stmt = conn.createStatement(); + stmt.execute("drop database if exists " + dbName); + stmt.execute("create database if not exists " + dbName); + stmt.execute("use " + dbName); + stmt.execute("drop table if exists weather"); + stmt.execute("create table weather(ts timestamp, temperature float, humidity int)"); + stmt.executeUpdate("insert into weather values(1624071506435, 12.3, 4)"); + stmt.close(); + } + + @BeforeClass + public static void beforeClass() { + System.setProperty("sun.jnu.encoding", "ANSI_X3.4-1968"); + System.setProperty("file.encoding", "ANSI_X3.4-1968"); + } + + @AfterClass + public static void afterClass() throws SQLException { + if (conn != null) + conn.close(); + } +} \ No newline at end of file diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/confprops/BatchFetchTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/confprops/BatchFetchTest.java new file mode 100644 index 0000000000000000000000000000000000000000..e8c799e86c61c6b4a7cb8b3396c6c3e09548ee0e --- /dev/null +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/confprops/BatchFetchTest.java @@ -0,0 +1,82 @@ +package com.taosdata.jdbc.confprops; + +import org.junit.*; +import org.junit.runners.MethodSorters; + +import java.sql.*; +import java.util.Random; + +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class BatchFetchTest { + + private static String host = "127.0.0.1"; + private long rowFetchCost, batchFetchCost; + + @Test + public void case01_rowFetch() throws SQLException { + String url = "jdbc:TAOS://" + host + ":6030/test?user=root&password=taosdata"; + try (Connection conn = DriverManager.getConnection(url); + Statement stmt = conn.createStatement()) { + + boolean batchfetch = Boolean.parseBoolean(conn.getClientInfo("batchfetch")); + Assert.assertFalse(batchfetch); + + long start = System.currentTimeMillis(); + ResultSet rs = stmt.executeQuery("select * from weather"); + while (rs.next()) { + } + long end = System.currentTimeMillis(); + rowFetchCost = end - start; + } + } + + @Test + public void case02_batchFetch() throws SQLException { + String url = "jdbc:TAOS://" + host + ":6030/test?user=root&password=taosdata&batchfetch=true"; + try (Connection conn = DriverManager.getConnection(url); + Statement stmt = conn.createStatement()) { + + boolean batchfetch = Boolean.parseBoolean(conn.getClientInfo("batchfetch")); + Assert.assertTrue(batchfetch); + + long start = System.currentTimeMillis(); + ResultSet rs = stmt.executeQuery("select * from weather"); + while (rs.next()) { + } + long end = System.currentTimeMillis(); + batchFetchCost = end - start; + } + } + + @Test + public void case03_batchFetchFastThanRowFetch() { + Assert.assertTrue(rowFetchCost - batchFetchCost >= 0); + } + + @BeforeClass + public static void beforeClass() throws SQLException { + String url = "jdbc:TAOS://" + host + ":6030/?user=root&password=taosdata"; + try (Connection conn = DriverManager.getConnection(url); + Statement stmt = conn.createStatement()) { + stmt.execute("drop database if exists test"); + stmt.execute("create database if not exists test"); + stmt.execute("use test"); + stmt.execute("create table weather(ts timestamp, f int) tags(t int)"); + for (int i = 0; i < 1000; i++) { + stmt.execute(generateSql(100, 100)); + } + } + } + + private static String generateSql(int tableSize, int valueSize) { + Random random = new Random(System.currentTimeMillis()); + StringBuilder builder = new StringBuilder("insert into "); + for (int i = 0; i < tableSize; i++) { + builder.append("t" + i).append(" using weather tags(").append(random.nextInt(100)).append(") values"); + for (int j = 0; j < valueSize; j++) { + builder.append(" (now + ").append(i).append("s, ").append(random.nextInt(100)).append(")"); + } + } + return builder.toString(); + } +} diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/confprops/CharsetTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/confprops/CharsetTest.java new file mode 100644 index 0000000000000000000000000000000000000000..e28faeb280a9f9f9ae931e7b610910fb912278b3 --- /dev/null +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/confprops/CharsetTest.java @@ -0,0 +1,40 @@ +package com.taosdata.jdbc.confprops; + +import com.taosdata.jdbc.TSDBDriver; +import org.junit.Assert; +import org.junit.Test; + +import java.sql.*; +import java.util.Properties; + +public class CharsetTest { + private static final String host = "127.0.0.1"; + + @Test + public void test() throws SQLException { + // given + String url = "jdbc:TAOS://" + host + ":6030/?user=root&password=taosdata"; + Properties props = new Properties(); + props.setProperty(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8"); + + try (Connection conn = DriverManager.getConnection(url, props); + Statement stmt = conn.createStatement()) { + + // when + stmt.execute("drop database if exists test"); + stmt.execute("create database if not exists test"); + stmt.execute("use test"); + stmt.execute("create table weather(ts timestamp, temperature nchar(10))"); + stmt.execute("insert into weather values(now, '北京')"); + + // then + ResultSet rs = stmt.executeQuery("select * from weather"); + while (rs.next()) { + Object value = rs.getObject("temperature"); + Assert.assertTrue(value instanceof String); + Assert.assertEquals("北京", value.toString()); + } + } + } + +} diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/HttpKeepAliveTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/confprops/HttpKeepAliveTest.java similarity index 97% rename from src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/HttpKeepAliveTest.java rename to src/connector/jdbc/src/test/java/com/taosdata/jdbc/confprops/HttpKeepAliveTest.java index 30fc2fa76597c30b905db5c9d49815189d71aaa3..7f7979eb01154a85b25bbea7b9d3f042b4f1c104 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/HttpKeepAliveTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/confprops/HttpKeepAliveTest.java @@ -1,4 +1,4 @@ -package com.taosdata.jdbc.rs; +package com.taosdata.jdbc.confprops; import org.junit.Assert; import org.junit.Test; diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/confprops/TaosInfoMonitorTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/confprops/TaosInfoMonitorTest.java new file mode 100644 index 0000000000000000000000000000000000000000..4a919db6f403a9f6ad54e261fdb28f93dddf4958 --- /dev/null +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/confprops/TaosInfoMonitorTest.java @@ -0,0 +1,54 @@ +package com.taosdata.jdbc.confprops; + +import org.junit.Assert; +import org.junit.Test; + +import java.sql.*; +import java.util.List; +import java.util.Random; +import java.util.concurrent.TimeUnit; +import java.util.stream.Collectors; +import java.util.stream.IntStream; + +public class TaosInfoMonitorTest { + + private static final String host = "127.0.0.1"; + private Random random = new Random(System.currentTimeMillis()); + + @Test + public void testCreateTooManyConnection() throws InterruptedException { + + List threads = IntStream.range(1, 11).mapToObj(i -> new Thread(() -> { + final String url = "jdbc:TAOS://" + host + ":6030/?user=root&password=taosdata"; + + int connSize = random.nextInt(10); + for (int j = 0; j < connSize; j++) { + + try { + Connection conn = DriverManager.getConnection(url); + TimeUnit.MILLISECONDS.sleep(random.nextInt(3000)); + + int stmtSize = random.nextInt(100); + for (int k = 0; k < stmtSize; k++) { + Statement stmt = conn.createStatement(); + TimeUnit.MILLISECONDS.sleep(random.nextInt(3000)); + + ResultSet rs = stmt.executeQuery("show databases"); + while (rs.next()) { + } + rs.close(); + stmt.close(); + } + } catch (SQLException | InterruptedException throwables) { + Assert.fail(); + } + } + }, "thread-" + i)).collect(Collectors.toList()); + + threads.forEach(Thread::start); + + for (Thread thread : threads) { + thread.join(); + } + } +} diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/TimeZoneTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/confprops/TimeZoneTest.java similarity index 98% rename from src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/TimeZoneTest.java rename to src/connector/jdbc/src/test/java/com/taosdata/jdbc/confprops/TimeZoneTest.java index 94a175ad5c7fd50fa35d6b45ea59ab26ffc02ce1..6569aa5f085f5d389144a9e8ddc0787786f9fff3 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/TimeZoneTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/confprops/TimeZoneTest.java @@ -1,4 +1,4 @@ -package com.taosdata.jdbc.cases; +package com.taosdata.jdbc.confprops; import com.taosdata.jdbc.TSDBDriver; import org.junit.Test; diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/confprops/TimestampFormatTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/confprops/TimestampFormatTest.java new file mode 100644 index 0000000000000000000000000000000000000000..7e3701c153fa3f45852dd1a5860cf30910dc906d --- /dev/null +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/confprops/TimestampFormatTest.java @@ -0,0 +1,167 @@ +package com.taosdata.jdbc.confprops; + +import com.taosdata.jdbc.TSDBDriver; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import java.sql.*; +import java.time.Instant; +import java.util.Properties; + +public class TimestampFormatTest { + private static final String host = "127.0.0.1"; + private long ts = Instant.now().toEpochMilli(); + + @Test + public void string() throws SQLException { + // given + String url = "jdbc:TAOS-RS://" + host + ":6041/?user=root&password=taosdata"; + + // when + try (Connection conn = DriverManager.getConnection(url); + Statement stmt = conn.createStatement()) { + // then + String actual = conn.getClientInfo(TSDBDriver.PROPERTY_KEY_TIMESTAMP_FORMAT); + Assert.assertEquals("STRING", actual); + + ResultSet rs = stmt.executeQuery("select * from test.weather"); + while (rs.next()) { + String value = rs.getString("ts"); + String expect = new Timestamp(ts).toString(); + Assert.assertEquals(expect, value); + } + } + } + + @Test + public void stringInProperties() throws SQLException { + // given + String url = "jdbc:TAOS-RS://" + host + ":6041/?user=root&password=taosdata"; + + // when + String timestampFormat = "STRING"; + Properties props = new Properties(); + props.setProperty(TSDBDriver.PROPERTY_KEY_TIMESTAMP_FORMAT, timestampFormat); + try (Connection conn = DriverManager.getConnection(url, props); + Statement stmt = conn.createStatement()) { + + // then + String actual = conn.getClientInfo(TSDBDriver.PROPERTY_KEY_TIMESTAMP_FORMAT); + Assert.assertEquals(timestampFormat, actual); + + ResultSet rs = stmt.executeQuery("select * from test.weather"); + while (rs.next()) { + String value = rs.getString("ts"); + String expect = new Timestamp(ts).toString(); + Assert.assertEquals(expect, value); + } + } + } + + @Test + public void timestampInUrl() throws SQLException { + // given + String url = "jdbc:TAOS-RS://" + host + ":6041/?user=root&password=taosdata×tampFormat="; + String timestampFormat = "TIMESTAMP"; + + // when + try (Connection conn = DriverManager.getConnection(url + timestampFormat); + Statement stmt = conn.createStatement()) { + // then + String actual = conn.getClientInfo(TSDBDriver.PROPERTY_KEY_TIMESTAMP_FORMAT); + Assert.assertEquals(timestampFormat, actual); + + ResultSet rs = stmt.executeQuery("select * from test.weather"); + while (rs.next()) { + Object value = rs.getObject("ts"); + String expect = new Timestamp(ts).toString(); + Assert.assertEquals(expect, value.toString()); + } + } + } + + @Test + public void timestampInProperties() throws SQLException { + // given + String url = "jdbc:TAOS-RS://" + host + ":6041/?user=root&password=taosdata"; + String timestampFormat = "TIMESTAMP"; + + // when + Properties props = new Properties(); + props.setProperty(TSDBDriver.PROPERTY_KEY_TIMESTAMP_FORMAT, timestampFormat); + try (Connection conn = DriverManager.getConnection(url, props); + Statement stmt = conn.createStatement()) { + // then + String actual = conn.getClientInfo(TSDBDriver.PROPERTY_KEY_TIMESTAMP_FORMAT); + Assert.assertEquals(timestampFormat, actual); + + ResultSet rs = stmt.executeQuery("select * from test.weather"); + while (rs.next()) { + Object value = rs.getObject("ts"); + String expect = new Timestamp(ts).toString(); + Assert.assertEquals(expect, value.toString()); + } + } + } + + @Test + public void utcInUrl() throws SQLException { + // given + String timestampFormat = "UTC"; + String url = "jdbc:TAOS-RS://" + host + ":6041/?user=root&password=taosdata×tampFormat=" + timestampFormat; + + // when & then + try (Connection conn = DriverManager.getConnection(url); + Statement stmt = conn.createStatement()) { + String actual = conn.getClientInfo(TSDBDriver.PROPERTY_KEY_TIMESTAMP_FORMAT); + Assert.assertEquals(timestampFormat, actual); + ResultSet rs = stmt.executeQuery("select * from test.weather"); + while (rs.next()) { + Object value = rs.getObject("ts"); + Assert.assertTrue(value instanceof Timestamp); + String expect = new Timestamp(ts).toString(); + Assert.assertEquals(expect, value.toString()); + } + } + } + + @Test + public void utcInProperties() throws SQLException { + // given + String timestampFormat = "UTC"; + String url = "jdbc:TAOS-RS://" + host + ":6041/?user=root&password=taosdata"; + + // when + Properties props = new Properties(); + props.setProperty(TSDBDriver.PROPERTY_KEY_TIMESTAMP_FORMAT, timestampFormat); + try (Connection conn = DriverManager.getConnection(url, props); + Statement stmt = conn.createStatement()) { + + // then + String actual = conn.getClientInfo(TSDBDriver.PROPERTY_KEY_TIMESTAMP_FORMAT); + Assert.assertEquals(timestampFormat, actual); + ResultSet rs = stmt.executeQuery("select * from test.weather"); + while (rs.next()) { + Object value = rs.getObject("ts"); + Assert.assertTrue(value instanceof Timestamp); + String expect = new Timestamp(ts).toString(); + Assert.assertEquals(expect, value.toString()); + } + } + } + + @Before + public void before() throws SQLException { + String url = "jdbc:TAOS-RS://" + host + ":6041/?user=root&password=taosdata"; + try (Connection conn = DriverManager.getConnection(url); + Statement stmt = conn.createStatement()) { + stmt.execute("drop database if exists test"); + stmt.execute("create database if not exists test"); + stmt.execute("use test"); + stmt.execute("create table weather(ts timestamp, temperature nchar(10))"); + stmt.execute("insert into weather values(" + ts + ", '北京')"); + } + } + +} diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/RestfulConnectionTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/RestfulConnectionTest.java index 1c5c03aacb5e7ed5683c75414975224a67d49e21..b08f8ff227dc16e1b413391e58a9de8fd0182c42 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/RestfulConnectionTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/RestfulConnectionTest.java @@ -23,14 +23,12 @@ public class RestfulConnectionTest { } @Test - public void createStatement() { + public void createStatement() throws SQLException { try (Statement stmt = conn.createStatement()) { ResultSet rs = stmt.executeQuery("select server_status()"); rs.next(); int status = rs.getInt("server_status()"); assertEquals(1, status); - } catch (SQLException e) { - e.printStackTrace(); } } @@ -359,13 +357,9 @@ public class RestfulConnectionTest { } @Test - public void unwrap() { - try { - RestfulConnection restfulConnection = conn.unwrap(RestfulConnection.class); - Assert.assertNotNull(restfulConnection); - } catch (SQLException e) { - e.printStackTrace(); - } + public void unwrap() throws SQLException { + RestfulConnection restfulConnection = conn.unwrap(RestfulConnection.class); + Assert.assertNotNull(restfulConnection); } @Test @@ -374,32 +368,22 @@ public class RestfulConnectionTest { } @BeforeClass - public static void beforeClass() { - try { - Class.forName("com.taosdata.jdbc.rs.RestfulDriver"); - 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-RS://" + host + ":6041/log?user=root&password=taosdata", properties); - // create test database for test cases - try (Statement stmt = conn.createStatement()) { - stmt.execute("create database if not exists test"); - } - - } catch (ClassNotFoundException | SQLException e) { - e.printStackTrace(); + public static void beforeClass() throws SQLException { + 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-RS://" + host + ":6041/log?user=root&password=taosdata", properties); + // create test database for test cases + try (Statement stmt = conn.createStatement()) { + stmt.execute("create database if not exists test"); } } @AfterClass - public static void afterClass() { - try { - if (conn != null) - conn.close(); - } catch (SQLException e) { - e.printStackTrace(); - } + public static void afterClass() throws SQLException { + if (conn != null) + conn.close(); } } \ No newline at end of file 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 85007db0e555634b25dee4f10446b1041bf19b21..50b0b97d90da255a8995e921d7e3ff22685e3bdb 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 @@ -1085,30 +1085,26 @@ public class RestfulDatabaseMetaDataTest { } @BeforeClass - public static void beforeClass() { - try { - Class.forName("com.taosdata.jdbc.rs.RestfulDriver"); - 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(url, properties); - metaData = connection.getMetaData().unwrap(RestfulDatabaseMetaData.class); - } catch (ClassNotFoundException e) { - e.printStackTrace(); - } catch (SQLException e) { - e.printStackTrace(); - } + public static void beforeClass() throws SQLException { + 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(url, properties); + Statement stmt = connection.createStatement(); + stmt.execute("drop database if exists log"); + stmt.execute("create database if not exists log precision 'us'"); + stmt.execute("use log"); + stmt.execute("create table `dn` (ts TIMESTAMP,cpu_taosd FLOAT,cpu_system FLOAT,cpu_cores INT,mem_taosd FLOAT,mem_system FLOAT,mem_total INT,disk_used FLOAT,disk_total INT,band_speed FLOAT,io_read FLOAT,io_write FLOAT,req_http INT,req_select INT,req_insert INT) TAGS (dnodeid INT,fqdn BINARY(128))"); + stmt.execute("insert into dn1 using dn tags(1,'a') (ts) values(now)"); + + metaData = connection.getMetaData().unwrap(RestfulDatabaseMetaData.class); } @AfterClass - public static void afterClass() { - try { - if (connection != null) - connection.close(); - } catch (SQLException e) { - e.printStackTrace(); - } + public static void afterClass() throws SQLException { + if (connection != null) + connection.close(); } } \ No newline at end of file diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/RestfulJDBCTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/RestfulJDBCTest.java index b07dae8003d6e2fea073c0d240f59fb6db0c593f..858f7b32f0d8a72be5b6cfa68aa120b08909df6c 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/RestfulJDBCTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/RestfulJDBCTest.java @@ -14,7 +14,7 @@ public class RestfulJDBCTest { private Connection connection; @Test - public void testCase001() { + public void testCase001() throws SQLException { // given String sql = "drop database if exists restful_test"; // when @@ -38,7 +38,7 @@ public class RestfulJDBCTest { } @Test - public void testCase002() { + public void testCase002() throws SQLException { // given String sql = "create table weather(ts timestamp, temperature float, humidity int) tags(location nchar(64), groupId int)"; // when @@ -48,7 +48,7 @@ public class RestfulJDBCTest { } @Test - public void testCase004() { + public void testCase004() throws SQLException { for (int i = 1; i <= 100; i++) { // given String sql = "create table t" + i + " using weather tags('beijing', '" + i + "')"; @@ -60,7 +60,7 @@ public class RestfulJDBCTest { } @Test - public void testCase005() { + public void testCase005() throws SQLException { int rows = 0; for (int i = 0; i < 10; i++) { for (int j = 1; j <= 100; j++) { @@ -99,7 +99,7 @@ public class RestfulJDBCTest { } @Test - public void testCase007() { + public void testCase007() throws SQLException { // given String sql = "drop database restful_test"; @@ -110,51 +110,34 @@ public class RestfulJDBCTest { Assert.assertFalse(execute); } - private int executeUpdate(Connection connection, String sql) { + private int executeUpdate(Connection connection, String sql) throws SQLException { try (Statement stmt = connection.createStatement()) { return stmt.executeUpdate(sql); - } catch (SQLException e) { - e.printStackTrace(); } - return 0; } - private boolean execute(Connection connection, String sql) { + private boolean execute(Connection connection, String sql) throws SQLException { try (Statement stmt = connection.createStatement()) { return stmt.execute(sql); - } catch (SQLException e) { - e.printStackTrace(); } - return false; } - private ResultSet executeQuery(Connection connection, String sql) { + private ResultSet executeQuery(Connection connection, String sql) throws SQLException { try (Statement statement = connection.createStatement()) { return statement.executeQuery(sql); - } catch (SQLException e) { - e.printStackTrace(); } - return null; } @Before - public void before() { - try { - connection = DriverManager.getConnection("jdbc:TAOS-RS://" + host + ":6041/restful_test?user=root&password=taosdata"); - } catch (SQLException e) { - e.printStackTrace(); - } + public void before() throws SQLException { + connection = DriverManager.getConnection("jdbc:TAOS-RS://" + host + ":6041/restful_test?user=root&password=taosdata&httpKeepAlive=false"); } @After - public void after() { - try { - if (connection != null) - connection.close(); - } catch (SQLException e) { - e.printStackTrace(); - } + public void after() throws SQLException { + if (connection != null) + connection.close(); } } diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/RestfulStatementTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/RestfulStatementTest.java index a7b3ceb9d3bb243a2a053d5289afe39d3c870d79..83ab2c7263cb61388d6cbdfd31b241d547520f53 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/RestfulStatementTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/RestfulStatementTest.java @@ -17,46 +17,32 @@ public class RestfulStatementTest { private static Statement stmt; @Test - public void executeQuery() { - try { - ResultSet rs = stmt.executeQuery("show databases"); - Assert.assertNotNull(rs); - ResultSetMetaData meta = rs.getMetaData(); - int columnCount = meta.getColumnCount(); - Assert.assertTrue(columnCount > 1); - while (rs.next()) { - Assert.assertEquals("name", meta.getColumnLabel(1)); - Assert.assertNotNull(rs.getString("name")); - } - rs.close(); - } catch (SQLException e) { - e.printStackTrace(); + public void executeQuery() throws SQLException { + ResultSet rs = stmt.executeQuery("show databases"); + Assert.assertNotNull(rs); + ResultSetMetaData meta = rs.getMetaData(); + int columnCount = meta.getColumnCount(); + Assert.assertTrue(columnCount > 1); + while (rs.next()) { + Assert.assertEquals("name", meta.getColumnLabel(1)); + Assert.assertNotNull(rs.getString("name")); } + rs.close(); } @Test - public void executeUpdate() { + public void executeUpdate() throws SQLException { final String dbName = ("test_" + UUID.randomUUID()).replace("-", "_").substring(0, 32); - try { - int affectRows = stmt.executeUpdate("create database " + dbName); - Assert.assertEquals(0, affectRows); - affectRows = stmt.executeUpdate("create table " + dbName + ".weather(ts timestamp, temperature float) tags(loc nchar(64))"); - Assert.assertEquals(0, affectRows); - affectRows = stmt.executeUpdate("insert into " + dbName + ".t1 using " + dbName + ".weather tags('北京') values(now, 22.33)"); - Assert.assertEquals(1, affectRows); - affectRows = stmt.executeUpdate("drop database " + dbName); - Assert.assertEquals(0, affectRows); - } catch (SQLException e) { - e.printStackTrace(); - } + int affectRows = stmt.executeUpdate("create database " + dbName); + Assert.assertEquals(0, affectRows); + affectRows = stmt.executeUpdate("create table " + dbName + ".weather(ts timestamp, temperature float) tags(loc nchar(64))"); + Assert.assertEquals(0, affectRows); + affectRows = stmt.executeUpdate("insert into " + dbName + ".t1 using " + dbName + ".weather tags('北京') values(now, 22.33)"); + Assert.assertEquals(1, affectRows); + affectRows = stmt.executeUpdate("drop database " + dbName); + Assert.assertEquals(0, affectRows); } - @Test - public void close() { - // test in AfterClass method - } - - @Test public void getMaxFieldSize() throws SQLException { Assert.assertEquals(16 * 1024, stmt.getMaxFieldSize()); @@ -64,7 +50,6 @@ public class RestfulStatementTest { @Test(expected = SQLException.class) public void setMaxFieldSize() throws SQLException { - stmt.setMaxFieldSize(0); stmt.setMaxFieldSize(-1); } @@ -118,83 +103,70 @@ public class RestfulStatementTest { } @Test - public void execute() { + public void execute() throws SQLException { final String dbName = ("test_" + UUID.randomUUID()).replace("-", "_").substring(0, 32); - try { - boolean isSelect = stmt.execute("create database if not exists " + dbName); - Assert.assertEquals(false, isSelect); - int affectedRows = stmt.getUpdateCount(); - Assert.assertEquals(0, affectedRows); - - isSelect = stmt.execute("create table if not exists " + dbName + ".weather(ts timestamp, temperature float) tags(loc nchar(64))"); - Assert.assertEquals(false, isSelect); - affectedRows = stmt.getUpdateCount(); - Assert.assertEquals(0, affectedRows); - - isSelect = stmt.execute("insert into " + dbName + ".t1 using " + dbName + ".weather tags('北京') values(now, 22.33)"); - Assert.assertEquals(false, isSelect); - affectedRows = stmt.getUpdateCount(); - Assert.assertEquals(1, affectedRows); - - isSelect = stmt.execute("select * from " + dbName + ".weather"); - Assert.assertEquals(true, isSelect); - - isSelect = stmt.execute("drop database " + dbName); - Assert.assertEquals(false, isSelect); - affectedRows = stmt.getUpdateCount(); - Assert.assertEquals(0, affectedRows); - } catch (SQLException e) { - e.printStackTrace(); - } + boolean isSelect = stmt.execute("create database if not exists " + dbName); + Assert.assertEquals(false, isSelect); + int affectedRows = stmt.getUpdateCount(); + Assert.assertEquals(0, affectedRows); + + isSelect = stmt.execute("create table if not exists " + dbName + ".weather(ts timestamp, temperature float) tags(loc nchar(64))"); + Assert.assertEquals(false, isSelect); + affectedRows = stmt.getUpdateCount(); + Assert.assertEquals(0, affectedRows); + + isSelect = stmt.execute("insert into " + dbName + ".t1 using " + dbName + ".weather tags('北京') values(now, 22.33)"); + Assert.assertEquals(false, isSelect); + affectedRows = stmt.getUpdateCount(); + Assert.assertEquals(1, affectedRows); + + isSelect = stmt.execute("select * from " + dbName + ".weather"); + Assert.assertEquals(true, isSelect); + + isSelect = stmt.execute("drop database " + dbName); + Assert.assertEquals(false, isSelect); + affectedRows = stmt.getUpdateCount(); + Assert.assertEquals(0, affectedRows); } @Test - public void getResultSet() { + public void getResultSet() throws SQLException { final String dbName = ("test_" + UUID.randomUUID()).replace("-", "_").substring(0, 32); - try { - boolean isSelect = stmt.execute("create database if not exists " + dbName); - Assert.assertEquals(false, isSelect); - int affectedRows = stmt.getUpdateCount(); - Assert.assertEquals(0, affectedRows); - - isSelect = stmt.execute("create table if not exists " + dbName + ".weather(ts timestamp, temperature float) tags(loc nchar(64))"); - Assert.assertEquals(false, isSelect); - affectedRows = stmt.getUpdateCount(); - Assert.assertEquals(0, affectedRows); - - isSelect = stmt.execute("insert into " + dbName + ".t1 using " + dbName + ".weather tags('北京') values(now, 22.33)"); - Assert.assertEquals(false, isSelect); - affectedRows = stmt.getUpdateCount(); - Assert.assertEquals(1, affectedRows); - - isSelect = stmt.execute("select * from " + dbName + ".weather"); - Assert.assertEquals(true, isSelect); - ResultSet rs = stmt.getResultSet(); - Assert.assertNotNull(rs); - ResultSetMetaData meta = rs.getMetaData(); - Assert.assertEquals(3, meta.getColumnCount()); - int count = 0; - while (rs.next()) { - Assert.assertEquals("ts", meta.getColumnLabel(1)); - Assert.assertNotNull(rs.getTimestamp(1)); - Assert.assertEquals("temperature", meta.getColumnLabel(2)); - Assert.assertEquals(22.33, rs.getFloat(2), 0.001f); - count++; - } - Assert.assertEquals(1, count); - - isSelect = stmt.execute("drop database " + dbName); - Assert.assertEquals(false, isSelect); - affectedRows = stmt.getUpdateCount(); - Assert.assertEquals(0, affectedRows); - } catch (SQLException e) { - e.printStackTrace(); + boolean isSelect = stmt.execute("create database if not exists " + dbName); + Assert.assertEquals(false, isSelect); + int affectedRows = stmt.getUpdateCount(); + Assert.assertEquals(0, affectedRows); + + isSelect = stmt.execute("create table if not exists " + dbName + ".weather(ts timestamp, temperature float) tags(loc nchar(64))"); + Assert.assertEquals(false, isSelect); + affectedRows = stmt.getUpdateCount(); + Assert.assertEquals(0, affectedRows); + + isSelect = stmt.execute("insert into " + dbName + ".t1 using " + dbName + ".weather tags('北京') values(now, 22.33)"); + Assert.assertEquals(false, isSelect); + affectedRows = stmt.getUpdateCount(); + Assert.assertEquals(1, affectedRows); + + isSelect = stmt.execute("select * from " + dbName + ".weather"); + Assert.assertEquals(true, isSelect); + ResultSet rs = stmt.getResultSet(); + Assert.assertNotNull(rs); + ResultSetMetaData meta = rs.getMetaData(); + Assert.assertEquals(3, meta.getColumnCount()); + int count = 0; + while (rs.next()) { + Assert.assertEquals("ts", meta.getColumnLabel(1)); + Assert.assertNotNull(rs.getTimestamp(1)); + Assert.assertEquals("temperature", meta.getColumnLabel(2)); + Assert.assertEquals(22.33, rs.getFloat(2), 0.001f); + count++; } - } + Assert.assertEquals(1, count); - @Test - public void getUpdateCount() { - // already test in execute method + isSelect = stmt.execute("drop database " + dbName); + Assert.assertEquals(false, isSelect); + affectedRows = stmt.getUpdateCount(); + Assert.assertEquals(0, affectedRows); } @Test @@ -239,64 +211,48 @@ public class RestfulStatementTest { } @Test - public void addBatch() { + public void addBatch() throws SQLException { final String dbName = ("test_" + UUID.randomUUID()).replace("-", "_").substring(0, 32); - try { - stmt.addBatch("create database " + dbName); - stmt.addBatch("create table " + dbName + ".weather(ts timestamp, temperature float) tags(loc nchar(64))"); - stmt.addBatch("insert into " + dbName + ".t1 using " + dbName + ".weather tags('北京') values(now, 22.33)"); - stmt.addBatch("select * from " + dbName + ".weather"); - stmt.addBatch("drop database " + dbName); - } catch (SQLException e) { - e.printStackTrace(); - } + stmt.addBatch("create database " + dbName); + stmt.addBatch("create table " + dbName + ".weather(ts timestamp, temperature float) tags(loc nchar(64))"); + stmt.addBatch("insert into " + dbName + ".t1 using " + dbName + ".weather tags('北京') values(now, 22.33)"); + stmt.addBatch("select * from " + dbName + ".weather"); + stmt.addBatch("drop database " + dbName); } @Test - public void clearBatch() { + public void clearBatch() throws SQLException { final String dbName = ("test_" + UUID.randomUUID()).replace("-", "_").substring(0, 32); - try { - stmt.clearBatch(); - stmt.addBatch("create database " + dbName); - stmt.addBatch("create table " + dbName + ".weather(ts timestamp, temperature float) tags(loc nchar(64))"); - stmt.addBatch("insert into " + dbName + ".t1 using " + dbName + ".weather tags('北京') values(now, 22.33)"); - stmt.addBatch("select * from " + dbName + ".weather"); - stmt.addBatch("drop database " + dbName); - stmt.clearBatch(); - } catch (SQLException e) { - e.printStackTrace(); - } + stmt.clearBatch(); + stmt.addBatch("create database " + dbName); + stmt.addBatch("create table " + dbName + ".weather(ts timestamp, temperature float) tags(loc nchar(64))"); + stmt.addBatch("insert into " + dbName + ".t1 using " + dbName + ".weather tags('北京') values(now, 22.33)"); + stmt.addBatch("select * from " + dbName + ".weather"); + stmt.addBatch("drop database " + dbName); + stmt.clearBatch(); } @Test - public void executeBatch() { + public void executeBatch() throws SQLException { final String dbName = ("test_" + UUID.randomUUID()).replace("-", "_").substring(0, 32); - try { - stmt.addBatch("create database " + dbName); - stmt.addBatch("create table " + dbName + ".weather(ts timestamp, temperature float) tags(loc nchar(64))"); - stmt.addBatch("insert into " + dbName + ".t1 using " + dbName + ".weather tags('北京') values(now, 22.33)"); - stmt.addBatch("select * from " + dbName + ".weather"); - stmt.addBatch("drop database " + dbName); - int[] results = stmt.executeBatch(); - Assert.assertEquals(0, results[0]); - Assert.assertEquals(0, results[1]); - Assert.assertEquals(1, results[2]); - Assert.assertEquals(Statement.SUCCESS_NO_INFO, results[3]); - Assert.assertEquals(0, results[4]); - } catch (SQLException e) { - e.printStackTrace(); - } + stmt.addBatch("create database " + dbName); + stmt.addBatch("create table " + dbName + ".weather(ts timestamp, temperature float) tags(loc nchar(64))"); + stmt.addBatch("insert into " + dbName + ".t1 using " + dbName + ".weather tags('北京') values(now, 22.33)"); + stmt.addBatch("select * from " + dbName + ".weather"); + stmt.addBatch("drop database " + dbName); + int[] results = stmt.executeBatch(); + Assert.assertEquals(0, results[0]); + Assert.assertEquals(0, results[1]); + Assert.assertEquals(1, results[2]); + Assert.assertEquals(Statement.SUCCESS_NO_INFO, results[3]); + Assert.assertEquals(0, results[4]); } @Test - public void getConnection() { - try { - Connection connection = stmt.getConnection(); - Assert.assertNotNull(connection); - Assert.assertTrue(this.conn == connection); - } catch (SQLException e) { - e.printStackTrace(); - } + public void getConnection() throws SQLException { + Connection connection = stmt.getConnection(); + Assert.assertNotNull(connection); + Assert.assertTrue(this.conn == connection); } @Test(expected = SQLFeatureNotSupportedException.class) @@ -346,12 +302,8 @@ public class RestfulStatementTest { } @Test - public void isClosed() { - try { - Assert.assertEquals(false, stmt.isClosed()); - } catch (SQLException e) { - e.printStackTrace(); - } + public void isClosed() throws SQLException { + Assert.assertEquals(false, stmt.isClosed()); } @Test @@ -387,29 +339,21 @@ public class RestfulStatementTest { } @BeforeClass - public static void beforeClass() { - try { - 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-RS://" + host + ":6041/?user=root&password=taosdata", properties); - stmt = conn.createStatement(); - } catch (SQLException e) { - e.printStackTrace(); - } + public static void beforeClass() throws SQLException { + 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-RS://" + host + ":6041/?user=root&password=taosdata", properties); + stmt = conn.createStatement(); } @AfterClass - public static void afterClass() { - try { - if (stmt != null) - stmt.close(); - if (conn != null) - conn.close(); - } catch (SQLException e) { - e.printStackTrace(); - } + public static void afterClass() throws SQLException { + if (stmt != null) + stmt.close(); + if (conn != null) + conn.close(); } } diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/SQLTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/SQLTest.java index 98482ade80656f2e48bc6927953439cfe4b010c1..a28bdbe2e5f6e0d545241a80071d85b0964a4102 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/SQLTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/SQLTest.java @@ -543,15 +543,6 @@ public class SQLTest { Assert.assertNotNull(rs); } - @Test - public void testCase053() { - String sql = "select avg(cpu_taosd), avg(cpu_system), max(cpu_cores), avg(mem_taosd), avg(mem_system), max(mem_total), avg(disk_used), max(disk_total), avg(band_speed), avg(io_read), avg(io_write), sum(req_http), sum(req_select), sum(req_insert) from log.dn1 where ts> now - 60m and ts<= now interval(1m) fill(value, 0)"; - // when - ResultSet rs = executeQuery(connection, sql); - // then - Assert.assertNotNull(rs); - } - private boolean execute(Connection connection, String sql) { try (Statement statement = connection.createStatement()) { return statement.execute(sql); diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/utils/HttpClientPoolUtilTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/utils/HttpClientPoolUtilTest.java index 7ba1607fdd32a594bca22528dee48d902736c703..128a62e5d964bc2276328312eb9998895923547f 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/utils/HttpClientPoolUtilTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/utils/HttpClientPoolUtilTest.java @@ -17,7 +17,6 @@ public class HttpClientPoolUtilTest { String user = "root"; String password = "taosdata"; String host = "127.0.0.1"; -// String host = "master"; @Test public void useLog() { diff --git a/src/inc/taosmsg.h b/src/inc/taosmsg.h index c6d587fe1a296bc40ab804cdef160b70da273fd8..ea6a69aa386261d5742c732794580bbc14daf831 100644 --- a/src/inc/taosmsg.h +++ b/src/inc/taosmsg.h @@ -479,14 +479,15 @@ typedef struct { bool stateWindow; // state window flag STimeWindow window; + STimeWindow range; // result range for interp query int32_t numOfTables; int16_t order; int16_t orderColId; int16_t numOfCols; // the number of columns will be load from vnode SInterval interval; SSessionWindow sw; // session window - uint16_t tagCondLen; // tag length in current query - uint16_t colCondLen; // column length in current query + uint32_t tagCondLen; // tag length in current query + int32_t colCondLen; // column length in current query int16_t numOfGroupCols; // num of group by columns int16_t orderByIdx; int16_t orderType; // used in group by xx order by xxx diff --git a/src/inc/tsdb.h b/src/inc/tsdb.h index 9d82245c2199b5fa0b62d709a08633e5a976b007..f98e7eec31f9cea99505bada1e0e3e8729b8d139 100644 --- a/src/inc/tsdb.h +++ b/src/inc/tsdb.h @@ -405,6 +405,7 @@ void tsdbDestroyCommitQueue(); int tsdbSyncCommit(STsdbRepo *repo); void tsdbIncCommitRef(int vgId); void tsdbDecCommitRef(int vgId); +void tsdbSwitchTable(TsdbQueryHandleT pQueryHandle); // For TSDB file sync int tsdbSyncSend(void *pRepo, SOCKET socketFd); diff --git a/src/inc/ttokendef.h b/src/inc/ttokendef.h index b38dcb0871d7bac99af891c51671e82a68528470..4b6602b4124fe5e16c60700aebf3a1a2d55c77fd 100644 --- a/src/inc/ttokendef.h +++ b/src/inc/ttokendef.h @@ -142,77 +142,78 @@ #define TK_DISTINCT 124 #define TK_FROM 125 #define TK_VARIABLE 126 -#define TK_INTERVAL 127 -#define TK_EVERY 128 -#define TK_SESSION 129 -#define TK_STATE_WINDOW 130 -#define TK_FILL 131 -#define TK_SLIDING 132 -#define TK_ORDER 133 -#define TK_BY 134 -#define TK_ASC 135 -#define TK_GROUP 136 -#define TK_HAVING 137 -#define TK_LIMIT 138 -#define TK_OFFSET 139 -#define TK_SLIMIT 140 -#define TK_SOFFSET 141 -#define TK_WHERE 142 -#define TK_RESET 143 -#define TK_QUERY 144 -#define TK_SYNCDB 145 -#define TK_ADD 146 -#define TK_COLUMN 147 -#define TK_MODIFY 148 -#define TK_TAG 149 -#define TK_CHANGE 150 -#define TK_SET 151 -#define TK_KILL 152 -#define TK_CONNECTION 153 -#define TK_STREAM 154 -#define TK_COLON 155 -#define TK_ABORT 156 -#define TK_AFTER 157 -#define TK_ATTACH 158 -#define TK_BEFORE 159 -#define TK_BEGIN 160 -#define TK_CASCADE 161 -#define TK_CLUSTER 162 -#define TK_CONFLICT 163 -#define TK_COPY 164 -#define TK_DEFERRED 165 -#define TK_DELIMITERS 166 -#define TK_DETACH 167 -#define TK_EACH 168 -#define TK_END 169 -#define TK_EXPLAIN 170 -#define TK_FAIL 171 -#define TK_FOR 172 -#define TK_IGNORE 173 -#define TK_IMMEDIATE 174 -#define TK_INITIALLY 175 -#define TK_INSTEAD 176 -#define TK_KEY 177 -#define TK_OF 178 -#define TK_RAISE 179 -#define TK_REPLACE 180 -#define TK_RESTRICT 181 -#define TK_ROW 182 -#define TK_STATEMENT 183 -#define TK_TRIGGER 184 -#define TK_VIEW 185 -#define TK_IPTOKEN 186 -#define TK_SEMI 187 -#define TK_NONE 188 -#define TK_PREV 189 -#define TK_LINEAR 190 -#define TK_IMPORT 191 -#define TK_TBNAME 192 -#define TK_JOIN 193 -#define TK_INSERT 194 -#define TK_INTO 195 -#define TK_VALUES 196 -#define TK_FILE 197 +#define TK_RANGE 127 +#define TK_INTERVAL 128 +#define TK_EVERY 129 +#define TK_SESSION 130 +#define TK_STATE_WINDOW 131 +#define TK_FILL 132 +#define TK_SLIDING 133 +#define TK_ORDER 134 +#define TK_BY 135 +#define TK_ASC 136 +#define TK_GROUP 137 +#define TK_HAVING 138 +#define TK_LIMIT 139 +#define TK_OFFSET 140 +#define TK_SLIMIT 141 +#define TK_SOFFSET 142 +#define TK_WHERE 143 +#define TK_RESET 144 +#define TK_QUERY 145 +#define TK_SYNCDB 146 +#define TK_ADD 147 +#define TK_COLUMN 148 +#define TK_MODIFY 149 +#define TK_TAG 150 +#define TK_CHANGE 151 +#define TK_SET 152 +#define TK_KILL 153 +#define TK_CONNECTION 154 +#define TK_STREAM 155 +#define TK_COLON 156 +#define TK_ABORT 157 +#define TK_AFTER 158 +#define TK_ATTACH 159 +#define TK_BEFORE 160 +#define TK_BEGIN 161 +#define TK_CASCADE 162 +#define TK_CLUSTER 163 +#define TK_CONFLICT 164 +#define TK_COPY 165 +#define TK_DEFERRED 166 +#define TK_DELIMITERS 167 +#define TK_DETACH 168 +#define TK_EACH 169 +#define TK_END 170 +#define TK_EXPLAIN 171 +#define TK_FAIL 172 +#define TK_FOR 173 +#define TK_IGNORE 174 +#define TK_IMMEDIATE 175 +#define TK_INITIALLY 176 +#define TK_INSTEAD 177 +#define TK_KEY 178 +#define TK_OF 179 +#define TK_RAISE 180 +#define TK_REPLACE 181 +#define TK_RESTRICT 182 +#define TK_ROW 183 +#define TK_STATEMENT 184 +#define TK_TRIGGER 185 +#define TK_VIEW 186 +#define TK_IPTOKEN 187 +#define TK_SEMI 188 +#define TK_NONE 189 +#define TK_PREV 190 +#define TK_LINEAR 191 +#define TK_IMPORT 192 +#define TK_TBNAME 193 +#define TK_JOIN 194 +#define TK_INSERT 195 +#define TK_INTO 196 +#define TK_VALUES 197 +#define TK_FILE 198 diff --git a/src/inc/ttype.h b/src/inc/ttype.h index 3f1606e957564f0a86988a389071957d2204d391..095b593ab7d1fb74effd7991feeeb60f54cbc1b8 100644 --- a/src/inc/ttype.h +++ b/src/inc/ttype.h @@ -50,6 +50,47 @@ typedef struct { #define TSDB_DATA_TYPE_POINTER_ARRAY (1000) #define TSDB_DATA_TYPE_VALUE_ARRAY (1001) +#define COPY_DATA(dst, src) *((int64_t *)(dst)) = *((int64_t *)(src)) + +#define COPY_TYPED_DATA(_v, _type, _data) \ + do { \ + switch (_type) { \ + case TSDB_DATA_TYPE_BOOL: \ + case TSDB_DATA_TYPE_TINYINT: \ + (*(int8_t *)_v) = GET_INT8_VAL(_data); \ + break; \ + case TSDB_DATA_TYPE_UTINYINT: \ + (*(uint8_t *)_v) = GET_UINT8_VAL(_data); \ + break; \ + case TSDB_DATA_TYPE_SMALLINT: \ + (*(int16_t *)_v) = GET_INT16_VAL(_data); \ + break; \ + case TSDB_DATA_TYPE_USMALLINT: \ + (*(uint16_t *)_v) = GET_UINT16_VAL(_data); \ + break; \ + case TSDB_DATA_TYPE_TIMESTAMP: \ + case TSDB_DATA_TYPE_BIGINT: \ + (*(int64_t *)_v) = (GET_INT64_VAL(_data)); \ + break; \ + case TSDB_DATA_TYPE_UBIGINT: \ + (*(uint64_t *)_v) = (GET_UINT64_VAL(_data)); \ + break; \ + case TSDB_DATA_TYPE_FLOAT: \ + (*(float *)_v) = GET_FLOAT_VAL(_data); \ + break; \ + case TSDB_DATA_TYPE_DOUBLE: \ + (*(double *)_v) = GET_DOUBLE_VAL(_data); \ + break; \ + case TSDB_DATA_TYPE_UINT: \ + (*(uint32_t *)_v) = GET_UINT32_VAL(_data); \ + break; \ + default: \ + (*(int32_t *)_v) = GET_INT32_VAL(_data); \ + break; \ + } \ + } while (0) + + #define GET_TYPED_DATA(_v, _finalType, _type, _data) \ do { \ switch (_type) { \ diff --git a/src/kit/shell/src/shellEngine.c b/src/kit/shell/src/shellEngine.c index 40c5a5da8170c43315fe2657a91be64fe8a58b87..8ab9bfcf4e7685081cd6f09990f5365d94c4094b 100644 --- a/src/kit/shell/src/shellEngine.c +++ b/src/kit/shell/src/shellEngine.c @@ -262,7 +262,7 @@ int32_t shellRunCommand(TAOS* con, char* command) { } if (c == '\\') { - if (quote != 0 && (*command == '_' || *command == '\\')) { + if (quote != 0 && (*command == '_' || *command == '%' || *command == '\\')) { //DO nothing } else { esc = true; diff --git a/src/kit/taosdemo/CMakeLists.txt b/src/kit/taosdemo/CMakeLists.txt index 2007be991af3b98fea3930a874e4efb9b6b1997a..57d6242d5343ad727b1706ab614ad0add844ddb6 100644 --- a/src/kit/taosdemo/CMakeLists.txt +++ b/src/kit/taosdemo/CMakeLists.txt @@ -2,12 +2,13 @@ CMAKE_MINIMUM_REQUIRED(VERSION 3.0...3.20) PROJECT(TDengine) INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/client/inc) +INCLUDE_DIRECTORIES(inc) FIND_PACKAGE(Git) IF (GIT_FOUND) MESSAGE("Git found") EXECUTE_PROCESS( - COMMAND ${GIT_EXECUTABLE} log --pretty=oneline -n 1 ${CMAKE_CURRENT_LIST_DIR}/taosdemo.c + COMMAND ${GIT_EXECUTABLE} log --pretty=oneline -n 1 ${CMAKE_CURRENT_LIST_DIR} WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} RESULT_VARIABLE RESULT OUTPUT_VARIABLE TAOSDEMO_COMMIT_SHA1) @@ -18,7 +19,7 @@ IF (GIT_FOUND) STRING(STRIP "${TAOSDEMO_COMMIT_SHA1}" TAOSDEMO_COMMIT_SHA1) ENDIF () EXECUTE_PROCESS( - COMMAND ${GIT_EXECUTABLE} status -z -s ${CMAKE_CURRENT_LIST_DIR}/taosdemo.c + COMMAND ${GIT_EXECUTABLE} status -z -s ${CMAKE_CURRENT_LIST_DIR} RESULT_VARIABLE RESULT OUTPUT_VARIABLE TAOSDEMO_STATUS) IF (TD_LINUX) @@ -64,7 +65,7 @@ ELSE () ENDIF () IF (TD_LINUX) - AUX_SOURCE_DIRECTORY(. SRC) + AUX_SOURCE_DIRECTORY(./src SRC) ADD_EXECUTABLE(taosdemo ${SRC}) IF (TD_SOMODE_STATIC) @@ -73,9 +74,17 @@ IF (TD_LINUX) TARGET_LINK_LIBRARIES(taosdemo taos cJson ${LINK_JEMALLOC}) ENDIF () ELSEIF (TD_WINDOWS) - AUX_SOURCE_DIRECTORY(. SRC) + AUX_SOURCE_DIRECTORY(./src SRC) ADD_EXECUTABLE(taosdemo ${SRC}) - SET_SOURCE_FILES_PROPERTIES(./taosdemo.c PROPERTIES COMPILE_FLAGS -w) + SET_SOURCE_FILES_PROPERTIES(./src/demoUtil.c PROPERTIES COMPILE_FLAGS -w) + SET_SOURCE_FILES_PROPERTIES(./src/demoData.c PROPERTIES COMPILE_FLAGS -w) + SET_SOURCE_FILES_PROPERTIES(./src/demoInsert.c PROPERTIES COMPILE_FLAGS -w) + SET_SOURCE_FILES_PROPERTIES(./src/demoCommandOpt.c PROPERTIES COMPILE_FLAGS -w) + SET_SOURCE_FILES_PROPERTIES(./src/demoQuery.c PROPERTIES COMPILE_FLAGS -w) + SET_SOURCE_FILES_PROPERTIES(./src/demoMain.c PROPERTIES COMPILE_FLAGS -w) + SET_SOURCE_FILES_PROPERTIES(./src/demoSubscribe.c PROPERTIES COMPILE_FLAGS -w) + SET_SOURCE_FILES_PROPERTIES(./src/demoOutput.c PROPERTIES COMPILE_FLAGS -w) + SET_SOURCE_FILES_PROPERTIES(./src/demoJsonOpt.c PROPERTIES COMPILE_FLAGS -w) IF (TD_SOMODE_STATIC) TARGET_LINK_LIBRARIES(taosdemo taos_static cJson lua) ELSE () @@ -83,7 +92,7 @@ ELSEIF (TD_WINDOWS) ENDIF () ELSEIF (TD_DARWIN) # missing a few dependencies, such as - AUX_SOURCE_DIRECTORY(. SRC) + AUX_SOURCE_DIRECTORY(./src SRC) ADD_EXECUTABLE(taosdemo ${SRC}) IF (TD_SOMODE_STATIC) diff --git a/src/kit/taosdemo/inc/demo.h b/src/kit/taosdemo/inc/demo.h new file mode 100644 index 0000000000000000000000000000000000000000..ff605afcbb05d2c27abd382a249456b52763f673 --- /dev/null +++ b/src/kit/taosdemo/inc/demo.h @@ -0,0 +1,644 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#ifndef __DEMO__ +#define __DEMO__ + +#include +#include +#include +#define _GNU_SOURCE +#define CURL_STATICLIB + +#ifdef LINUX +#include +#include +#ifndef _ALPINE +#include +#endif +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#else +#include +#include +#endif + +#include +#include + +// #include "os.h" +#include "taos.h" +#include "taoserror.h" +#include "tutil.h" + +#define REQ_EXTRA_BUF_LEN 1024 +#define RESP_BUF_LEN 4096 +#define SQL_BUFF_LEN 1024 + +extern char configDir[]; + +#define STR_INSERT_INTO "INSERT INTO " + +#define MAX_RECORDS_PER_REQ 32766 + +#define HEAD_BUFF_LEN \ + TSDB_MAX_COLUMNS * 24 // 16*MAX_COLUMNS + (192+32)*2 + insert into .. + +#define BUFFER_SIZE TSDB_MAX_ALLOWED_SQL_LEN +#define FETCH_BUFFER_SIZE 100 * TSDB_MAX_ALLOWED_SQL_LEN +#define COND_BUF_LEN (BUFFER_SIZE - 30) +#define COL_BUFFER_LEN ((TSDB_COL_NAME_LEN + 15) * TSDB_MAX_COLUMNS) + +#define MAX_USERNAME_SIZE 64 +#define MAX_HOSTNAME_SIZE \ + 253 // https://man7.org/linux/man-pages/man7/hostname.7.html +#define MAX_TB_NAME_SIZE 64 +#define MAX_DATA_SIZE \ + (16 * TSDB_MAX_COLUMNS) + 20 // max record len: 16*MAX_COLUMNS, timestamp + // string and ,('') need extra space +#define OPT_ABORT 1 /* –abort */ +#define MAX_FILE_NAME_LEN 256 // max file name length on linux is 255. +#define MAX_PATH_LEN 4096 + +#define DEFAULT_START_TIME 1500000000000 + +#define MAX_PREPARED_RAND 1000000 +#define INT_BUFF_LEN 12 +#define BIGINT_BUFF_LEN 21 +#define SMALLINT_BUFF_LEN 7 +#define TINYINT_BUFF_LEN 5 +#define BOOL_BUFF_LEN 6 +#define FLOAT_BUFF_LEN 22 +#define DOUBLE_BUFF_LEN 42 +#define TIMESTAMP_BUFF_LEN 21 +#define PRINT_STAT_INTERVAL 30 * 1000 + +#define MAX_SAMPLES 10000 +#define MAX_NUM_COLUMNS \ + (TSDB_MAX_COLUMNS - 1) // exclude first column timestamp + +#define MAX_DB_COUNT 8 +#define MAX_SUPER_TABLE_COUNT 200 + +#define MAX_QUERY_SQL_COUNT 100 + +#define MAX_DATABASE_COUNT 256 +#define MAX_JSON_BUFF 6400000 + +#define INPUT_BUF_LEN 256 +#define EXTRA_SQL_LEN 256 +#define TBNAME_PREFIX_LEN \ + (TSDB_TABLE_NAME_LEN - 20) // 20 characters reserved for seq +#define SMALL_BUFF_LEN 8 +#define DATATYPE_BUFF_LEN (SMALL_BUFF_LEN * 3) +#define NOTE_BUFF_LEN (SMALL_BUFF_LEN * 16) + +#define DEFAULT_NTHREADS 8 +#define DEFAULT_TIMESTAMP_STEP 1 +#define DEFAULT_INTERLACE_ROWS 0 +#define DEFAULT_DATATYPE_NUM 1 +#define DEFAULT_CHILDTABLES 10000 +#define DEFAULT_TEST_MODE 0 +#define DEFAULT_METAFILE NULL +#define DEFAULT_SQLFILE NULL +#define DEFAULT_HOST "localhost" +#define DEFAULT_PORT 6030 +#define DEFAULT_IFACE INTERFACE_BUT +#define DEFAULT_DATABASE "test" +#define DEFAULT_REPLICA 1 +#define DEFAULT_TB_PREFIX "d" +#define DEFAULT_ESCAPE_CHAR false +#define DEFAULT_USE_METRIC true +#define DEFAULT_DROP_DB true +#define DEFAULT_AGGR_FUNC false +#define DEFAULT_DEBUG false +#define DEFAULT_VERBOSE false +#define DEFAULT_PERF_STAT false +#define DEFAULT_ANS_YES false +#define DEFAULT_OUTPUT "./output.txt" +#define DEFAULT_SYNC_MODE 0 +#define DEFAULT_DATA_TYPE \ + { TSDB_DATA_TYPE_FLOAT, TSDB_DATA_TYPE_INT, TSDB_DATA_TYPE_FLOAT } +#define DEFAULT_DATATYPE \ + { "FLOAT", "INT", "FLOAT" } +#define DEFAULT_BINWIDTH 64 +#define DEFAULT_COL_COUNT 4 +#define DEFAULT_LEN_ONE_ROW 76 +#define DEFAULT_INSERT_INTERVAL 0 +#define DEFAULT_QUERY_TIME 1 +#define DEFAULT_PREPARED_RAND 10000 +#define DEFAULT_REQ_PER_REQ 30000 +#define DEFAULT_INSERT_ROWS 10000 +#define DEFAULT_ABORT 0 +#define DEFAULT_RATIO 0 +#define DEFAULT_DISORDER_RANGE 1000 +#define DEFAULT_METHOD_DEL 1 +#define DEFAULT_TOTAL_INSERT 0 +#define DEFAULT_TOTAL_AFFECT 0 +#define DEFAULT_DEMO_MODE true +#define DEFAULT_CREATE_BATCH 10 +#define DEFAULT_SUB_INTERVAL 10000 +#define DEFAULT_QUERY_INTERVAL 10000 + +#define SML_LINE_SQL_SYNTAX_OFFSET 7 + +#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) + +#define verbosePrint(fmt, ...) \ + do { \ + if (g_args.verbose_print) fprintf(stderr, "VERB: " fmt, __VA_ARGS__); \ + } while (0) + +#define performancePrint(fmt, ...) \ + do { \ + if (g_args.performance_print) \ + fprintf(stderr, "PERF: " fmt, __VA_ARGS__); \ + } while (0) + +#define errorPrint(fmt, ...) \ + do { \ + fprintf(stderr, "\033[31m"); \ + fprintf(stderr, "%s(%d) ", __FILE__, __LINE__); \ + fprintf(stderr, "ERROR: " fmt, __VA_ARGS__); \ + fprintf(stderr, "\033[0m"); \ + } while (0) + +enum TEST_MODE { + INSERT_TEST, // 0 + QUERY_TEST, // 1 + SUBSCRIBE_TEST, // 2 + INVAID_TEST +}; + +typedef enum CREATE_SUB_TABLE_MOD_EN { + PRE_CREATE_SUBTBL, + AUTO_CREATE_SUBTBL, + NO_CREATE_SUBTBL +} CREATE_SUB_TABLE_MOD_EN; + +typedef enum TABLE_EXISTS_EN { + TBL_NO_EXISTS, + TBL_ALREADY_EXISTS, + TBL_EXISTS_BUTT +} TABLE_EXISTS_EN; + +enum enumSYNC_MODE { SYNC_MODE, ASYNC_MODE, MODE_BUT }; + +enum enum_TAOS_INTERFACE { + TAOSC_IFACE, + REST_IFACE, + STMT_IFACE, + SML_IFACE, + INTERFACE_BUT +}; + +typedef enum enumQUERY_CLASS { + SPECIFIED_CLASS, + STABLE_CLASS, + CLASS_BUT +} QUERY_CLASS; + +typedef enum enum_PROGRESSIVE_OR_INTERLACE { + PROGRESSIVE_INSERT_MODE, + INTERLACE_INSERT_MODE, + INVALID_INSERT_MODE +} PROG_OR_INTERLACE_MODE; + +typedef enum enumQUERY_TYPE { + NO_INSERT_TYPE, + INSERT_TYPE, + QUERY_TYPE_BUT +} QUERY_TYPE; + +enum _show_db_index { + TSDB_SHOW_DB_NAME_INDEX, + TSDB_SHOW_DB_CREATED_TIME_INDEX, + TSDB_SHOW_DB_NTABLES_INDEX, + TSDB_SHOW_DB_VGROUPS_INDEX, + TSDB_SHOW_DB_REPLICA_INDEX, + TSDB_SHOW_DB_QUORUM_INDEX, + TSDB_SHOW_DB_DAYS_INDEX, + TSDB_SHOW_DB_KEEP_INDEX, + TSDB_SHOW_DB_CACHE_INDEX, + TSDB_SHOW_DB_BLOCKS_INDEX, + TSDB_SHOW_DB_MINROWS_INDEX, + TSDB_SHOW_DB_MAXROWS_INDEX, + TSDB_SHOW_DB_WALLEVEL_INDEX, + TSDB_SHOW_DB_FSYNC_INDEX, + TSDB_SHOW_DB_COMP_INDEX, + TSDB_SHOW_DB_CACHELAST_INDEX, + TSDB_SHOW_DB_PRECISION_INDEX, + TSDB_SHOW_DB_UPDATE_INDEX, + TSDB_SHOW_DB_STATUS_INDEX, + TSDB_MAX_SHOW_DB +}; + +// -----------------------------------------SHOW TABLES CONFIGURE +// ------------------------------------- +enum _show_stables_index { + TSDB_SHOW_STABLES_NAME_INDEX, + TSDB_SHOW_STABLES_CREATED_TIME_INDEX, + TSDB_SHOW_STABLES_COLUMNS_INDEX, + TSDB_SHOW_STABLES_METRIC_INDEX, + TSDB_SHOW_STABLES_UID_INDEX, + TSDB_SHOW_STABLES_TID_INDEX, + TSDB_SHOW_STABLES_VGID_INDEX, + TSDB_MAX_SHOW_STABLES +}; + +enum _describe_table_index { + TSDB_DESCRIBE_METRIC_FIELD_INDEX, + TSDB_DESCRIBE_METRIC_TYPE_INDEX, + TSDB_DESCRIBE_METRIC_LENGTH_INDEX, + TSDB_DESCRIBE_METRIC_NOTE_INDEX, + TSDB_MAX_DESCRIBE_METRIC +}; + +typedef struct SArguments_S { + char * metaFile; + uint32_t test_mode; + char * host; + uint16_t port; + uint16_t iface; + char * user; + char password[SHELL_MAX_PASSWORD_LEN]; + char * database; + int replica; + char * tb_prefix; + bool escapeChar; + char * sqlFile; + bool use_metric; + bool drop_database; + bool aggr_func; + bool answer_yes; + bool debug_print; + bool verbose_print; + bool performance_print; + char * output_file; + bool async_mode; + char data_type[MAX_NUM_COLUMNS + 1]; + char * dataType[MAX_NUM_COLUMNS + 1]; + uint32_t binwidth; + uint32_t columnCount; + uint64_t lenOfOneRow; + uint32_t nthreads; + uint64_t insert_interval; + uint64_t timestamp_step; + int64_t query_times; + int64_t prepared_rand; + uint32_t interlaceRows; + uint32_t reqPerReq; // num_of_records_per_req + uint64_t max_sql_len; + int64_t ntables; + int64_t insertRows; + int abort; + uint32_t disorderRatio; // 0: no disorder, >0: x% + int disorderRange; // ms, us or ns. according to database precision + uint32_t method_of_delete; + uint64_t totalInsertRows; + uint64_t totalAffectedRows; + bool demo_mode; // use default column name and semi-random data +} SArguments; + +typedef struct SColumn_S { + char field[TSDB_COL_NAME_LEN]; + char data_type; + char dataType[DATATYPE_BUFF_LEN]; + uint32_t dataLen; + char note[NOTE_BUFF_LEN]; +} StrColumn; + +typedef struct SSuperTable_S { + char stbName[TSDB_TABLE_NAME_LEN]; + char dataSource[SMALL_BUFF_LEN]; // rand_gen or sample + char childTblPrefix[TBNAME_PREFIX_LEN]; + uint16_t childTblExists; + int64_t childTblCount; + uint64_t batchCreateTableNum; // 0: no batch, > 0: batch table number in + // one sql + uint8_t autoCreateTable; // 0: create sub table, 1: auto create sub table + uint16_t iface; // 0: taosc, 1: rest, 2: stmt + uint16_t lineProtocol; + int64_t childTblLimit; + uint64_t childTblOffset; + + // int multiThreadWriteOneTbl; // 0: no, 1: yes + uint32_t interlaceRows; // + int disorderRatio; // 0: no disorder, >0: x% + int disorderRange; // ms, us or ns. according to database precision + uint64_t maxSqlLen; // + + uint64_t insertInterval; // insert interval, will override global insert + // interval + int64_t insertRows; + int64_t timeStampStep; + int tsPrecision; + char startTimestamp[MAX_TB_NAME_SIZE]; + char sampleFormat[SMALL_BUFF_LEN]; // csv, json + char sampleFile[MAX_FILE_NAME_LEN]; + char tagsFile[MAX_FILE_NAME_LEN]; + + uint32_t columnCount; + StrColumn columns[TSDB_MAX_COLUMNS]; + uint32_t tagCount; + StrColumn tags[TSDB_MAX_TAGS]; + + char * childTblName; + bool escapeChar; + char * colsOfCreateChildTable; + uint64_t lenOfOneRow; + uint64_t lenOfTagOfOneRow; + + char *sampleDataBuf; + bool useSampleTs; + + uint32_t tagSource; // 0: rand, 1: tag sample + char * tagDataBuf; + uint32_t tagSampleCount; + uint32_t tagUsePos; + + // bind param batch + char *sampleBindBatchArray; + // statistics + uint64_t totalInsertRows; + uint64_t totalAffectedRows; +} SSuperTable; + +typedef struct { + char name[TSDB_DB_NAME_LEN]; + char create_time[32]; + int64_t ntables; + int32_t vgroups; + int16_t replica; + int16_t quorum; + int16_t days; + char keeplist[64]; + int32_t cache; // MB + int32_t blocks; + int32_t minrows; + int32_t maxrows; + int8_t wallevel; + int32_t fsync; + int8_t comp; + int8_t cachelast; + char precision[SMALL_BUFF_LEN]; // time resolution + int8_t update; + char status[16]; +} SDbInfo; + +typedef struct SDbCfg_S { + // int maxtablesPerVnode; + uint32_t minRows; // 0 means default + uint32_t maxRows; // 0 means default + int comp; + int walLevel; + int cacheLast; + int fsync; + int replica; + int update; + int keep; + int days; + int cache; + int blocks; + int quorum; + char precision[SMALL_BUFF_LEN]; +} SDbCfg; + +typedef struct SDataBase_S { + char dbName[TSDB_DB_NAME_LEN]; + bool drop; // 0: use exists, 1: if exists, drop then new create + SDbCfg dbCfg; + uint64_t superTblCount; + SSuperTable *superTbls; +} SDataBase; + +typedef struct SDbs_S { + char cfgDir[MAX_FILE_NAME_LEN]; + char host[MAX_HOSTNAME_SIZE]; + struct sockaddr_in serv_addr; + + uint16_t port; + char user[MAX_USERNAME_SIZE]; + char password[SHELL_MAX_PASSWORD_LEN]; + char resultFile[MAX_FILE_NAME_LEN]; + bool use_metric; + bool aggr_func; + bool asyncMode; + + uint32_t threadCount; + uint32_t threadCountForCreateTbl; + uint32_t dbCount; + // statistics + uint64_t totalInsertRows; + uint64_t totalAffectedRows; + + SDataBase *db; +} SDbs; + +typedef struct SpecifiedQueryInfo_S { + uint64_t queryInterval; // 0: unlimited > 0 loop/s + uint32_t concurrent; + int sqlCount; + uint32_t asyncMode; // 0: sync, 1: async + uint64_t subscribeInterval; // ms + uint64_t queryTimes; + bool subscribeRestart; + int subscribeKeepProgress; + char sql[MAX_QUERY_SQL_COUNT][BUFFER_SIZE + 1]; + char result[MAX_QUERY_SQL_COUNT][MAX_FILE_NAME_LEN]; + int resubAfterConsume[MAX_QUERY_SQL_COUNT]; + int endAfterConsume[MAX_QUERY_SQL_COUNT]; + TAOS_SUB *tsub[MAX_QUERY_SQL_COUNT]; + char topic[MAX_QUERY_SQL_COUNT][32]; + int consumed[MAX_QUERY_SQL_COUNT]; + TAOS_RES *res[MAX_QUERY_SQL_COUNT]; + uint64_t totalQueried; +} SpecifiedQueryInfo; + +typedef struct SuperQueryInfo_S { + char stbName[TSDB_TABLE_NAME_LEN]; + uint64_t queryInterval; // 0: unlimited > 0 loop/s + uint32_t threadCnt; + uint32_t asyncMode; // 0: sync, 1: async + uint64_t subscribeInterval; // ms + bool subscribeRestart; + int subscribeKeepProgress; + uint64_t queryTimes; + int64_t childTblCount; + char childTblPrefix[TBNAME_PREFIX_LEN]; // 20 characters reserved for seq + int sqlCount; + char sql[MAX_QUERY_SQL_COUNT][BUFFER_SIZE + 1]; + char result[MAX_QUERY_SQL_COUNT][MAX_FILE_NAME_LEN]; + int resubAfterConsume; + int endAfterConsume; + TAOS_SUB *tsub[MAX_QUERY_SQL_COUNT]; + char * childTblName; + uint64_t totalQueried; +} SuperQueryInfo; + +typedef struct SQueryMetaInfo_S { + char cfgDir[MAX_FILE_NAME_LEN]; + char host[MAX_HOSTNAME_SIZE]; + uint16_t port; + struct sockaddr_in serv_addr; + char user[MAX_USERNAME_SIZE]; + char password[SHELL_MAX_PASSWORD_LEN]; + char dbName[TSDB_DB_NAME_LEN]; + char queryMode[SMALL_BUFF_LEN]; // taosc, rest + SpecifiedQueryInfo specifiedQueryInfo; + SuperQueryInfo superQueryInfo; + uint64_t totalQueried; +} SQueryMetaInfo; + +typedef struct SThreadInfo_S { + TAOS * taos; + TAOS_STMT * stmt; + int64_t * bind_ts; + int64_t * bind_ts_array; + char * bindParams; + char * is_null; + int threadID; + char db_name[TSDB_DB_NAME_LEN]; + uint32_t time_precision; + char filePath[MAX_PATH_LEN]; + FILE * fp; + char tb_prefix[TSDB_TABLE_NAME_LEN]; + uint64_t start_table_from; + uint64_t end_table_to; + int64_t ntables; + int64_t tables_created; + uint64_t data_of_rate; + int64_t start_time; + char * cols; + bool use_metric; + SSuperTable *stbInfo; + char * buffer; // sql cmd buffer + + // for async insert + tsem_t lock_sem; + int64_t counter; + uint64_t st; + uint64_t et; + uint64_t lastTs; + + // sample data + int64_t samplePos; + // statistics + uint64_t totalInsertRows; + uint64_t totalAffectedRows; + + // insert delay statistics + uint64_t cntDelay; + uint64_t totalDelay; + uint64_t avgDelay; + uint64_t maxDelay; + uint64_t minDelay; + + // seq of query or subscribe + uint64_t querySeq; // sequence number of sql command + TAOS_SUB *tsub; + + char **lines; + SOCKET sockfd; +} threadInfo; + +/* ************ Global variables ************ */ +extern char * g_aggreFuncDemo[]; +extern char * g_aggreFunc[]; +extern SArguments g_args; +extern SDbs g_Dbs; +extern char * g_dupstr; +extern int64_t g_totalChildTables; +extern int64_t g_actualChildTables; +extern SQueryMetaInfo g_queryInfo; +extern FILE * g_fpOfInsertResult; + +#define min(a, b) (((a) < (b)) ? (a) : (b)) + +/* ************ Function declares ************ */ +/* demoCommandOpt.c */ +int parse_args(int argc, char *argv[]); +void setParaFromArg(); +void querySqlFile(TAOS *taos, char *sqlFile); +void testCmdLine(); +/* demoJsonOpt.c */ +int getInfoFromJsonFile(char *file); +int testMetaFile(); +/* demoUtil.c */ +int isCommentLine(char *line); +void replaceChildTblName(char *inSql, char *outSql, int tblIndex); +void setupForAnsiEscape(void); +void resetAfterAnsiEscape(void); +int taosRandom(); +void tmfree(void *buf); +void tmfclose(FILE *fp); +void fetchResult(TAOS_RES *res, threadInfo *pThreadInfo); +void prompt(); +void ERROR_EXIT(const char *msg); +int postProceSql(char *host, uint16_t port, char *sqlstr, + threadInfo *pThreadInfo); +int queryDbExec(TAOS *taos, char *command, QUERY_TYPE type, bool quiet); +int regexMatch(const char *s, const char *reg, int cflags); +int convertHostToServAddr(char *host, uint16_t port, + struct sockaddr_in *serv_addr); +char *formatTimestamp(char *buf, int64_t val, int precision); +void errorWrongValue(char *program, char *wrong_arg, char *wrong_value); +void errorUnrecognized(char *program, char *wrong_arg); +void errorPrintReqArg(char *program, char *wrong_arg); +void errorPrintReqArg2(char *program, char *wrong_arg); +void errorPrintReqArg3(char *program, char *wrong_arg); +bool isStringNumber(char *input); +int getAllChildNameOfSuperTable(TAOS *taos, char *dbName, char *stbName, + char ** childTblNameOfSuperTbl, + int64_t *childTblCountOfSuperTbl); +int getChildNameOfSuperTableWithLimitAndOffset(TAOS *taos, char *dbName, + char * stbName, + char ** childTblNameOfSuperTbl, + int64_t *childTblCountOfSuperTbl, + int64_t limit, uint64_t offset, + bool escapChar); +/* demoInsert.c */ +int insertTestProcess(); +void postFreeResource(); +/* demoOutput.c */ +void printVersion(); +void printfInsertMeta(); +void printfInsertMetaToFile(FILE *fp); +void printStatPerThread(threadInfo *pThreadInfo); +void appendResultBufToFile(char *resultBuf, threadInfo *pThreadInfo); +void printfQueryMeta(); +void printHelp(); +void printfQuerySystemInfo(TAOS *taos); +/* demoQuery.c */ +int queryTestProcess(); +/* demoSubscribe.c */ +int subscribeTestProcess(); +#endif \ No newline at end of file diff --git a/src/kit/taosdemo/inc/demoData.h b/src/kit/taosdemo/inc/demoData.h new file mode 100644 index 0000000000000000000000000000000000000000..f0ac1f2501fa76d1da6c537328d8dd319bbe3c95 --- /dev/null +++ b/src/kit/taosdemo/inc/demoData.h @@ -0,0 +1,123 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#ifndef __DEMODATA__ +#define __DEMODATA__ +#include "cJSON.h" +#include "demo.h" +/***** Global variables ******/ + +extern char * g_sampleDataBuf; +extern char * g_sampleBindBatchArray; +extern int32_t * g_randint; +extern uint32_t *g_randuint; +extern int64_t * g_randbigint; +extern uint64_t *g_randubigint; +extern float * g_randfloat; +extern double * g_randdouble; +extern char * g_randbool_buff; +extern char * g_randint_buff; +extern char * g_randuint_buff; +extern char * g_rand_voltage_buff; +extern char * g_randbigint_buff; +extern char * g_randubigint_buff; +extern char * g_randsmallint_buff; +extern char * g_randusmallint_buff; +extern char * g_randtinyint_buff; +extern char * g_randutinyint_buff; +extern char * g_randfloat_buff; +extern char * g_rand_current_buff; +extern char * g_rand_phase_buff; +extern char * g_randdouble_buff; +/***** Declare functions *****/ +int init_rand_data(); +char * rand_bool_str(); +int32_t rand_bool(); +char * rand_tinyint_str(); +int32_t rand_tinyint(); +char * rand_utinyint_str(); +int32_t rand_utinyint(); +char * rand_smallint_str(); +int32_t rand_smallint(); +char * rand_usmallint_str(); +int32_t rand_usmallint(); +char * rand_int_str(); +int32_t rand_int(); +char * rand_uint_str(); +int32_t rand_uint(); +char * rand_bigint_str(); +int64_t rand_bigint(); +char * rand_ubigint_str(); +int64_t rand_ubigint(); +char * rand_float_str(); +float rand_float(); +char * demo_current_float_str(); +float UNUSED_FUNC demo_current_float(); +char * demo_voltage_int_str(); +int32_t UNUSED_FUNC demo_voltage_int(); +char * demo_phase_float_str(); +float UNUSED_FUNC demo_phase_float(); +void rand_string(char *str, int size); +char * rand_double_str(); +double rand_double(); + +int generateTagValuesForStb(SSuperTable *stbInfo, int64_t tableSeq, + char *tagsValBuf); +int64_t getTSRandTail(int64_t timeStampStep, int32_t seq, int disorderRatio, + int disorderRange); +int32_t prepareStbStmtBindTag(char *bindArray, SSuperTable *stbInfo, + char *tagsVal, int32_t timePrec); +int32_t prepareStmtWithoutStb(threadInfo *pThreadInfo, char *tableName, + uint32_t batch, int64_t insertRows, + int64_t recordFrom, int64_t startTime); +int32_t generateStbInterlaceData(threadInfo *pThreadInfo, char *tableName, + uint32_t batchPerTbl, uint64_t i, + uint32_t batchPerTblTimes, uint64_t tableSeq, + char *buffer, int64_t insertRows, + int64_t startTime, uint64_t *pRemainderBufLen); +int64_t generateInterlaceDataWithoutStb(char *tableName, uint32_t batch, + uint64_t tableSeq, char *dbName, + char *buffer, int64_t insertRows, + int64_t startTime, + uint64_t *pRemainderBufLen); +int32_t generateStbProgressiveData(SSuperTable *stbInfo, char *tableName, + int64_t tableSeq, char *dbName, char *buffer, + int64_t insertRows, uint64_t recordFrom, + int64_t startTime, int64_t *pSamplePos, + int64_t *pRemainderBufLen); +int32_t generateProgressiveDataWithoutStb( + char *tableName, threadInfo *pThreadInfo, char *buffer, int64_t insertRows, + uint64_t recordFrom, int64_t startTime, int64_t *pRemainderBufLen); +int64_t generateStbRowData(SSuperTable *stbInfo, char *recBuf, + int64_t remainderBufLen, int64_t timestamp); +int prepareSampleForStb(SSuperTable *stbInfo); +int prepareSampleForNtb(); +int parseSamplefileToStmtBatch(SSuperTable *stbInfo); +int parseStbSampleToStmtBatchForThread(threadInfo * pThreadInfo, + SSuperTable *stbInfo, uint32_t timePrec, + uint32_t batch); +int parseNtbSampleToStmtBatchForThread(threadInfo *pThreadInfo, + uint32_t timePrec, uint32_t batch); +int prepareSampleData(); +int32_t generateSmlConstPart(char *sml, SSuperTable *stbInfo, + threadInfo *pThreadInfo, int tbSeq); + +int32_t generateSmlMutablePart(char *line, char *sml, SSuperTable *stbInfo, + threadInfo *pThreadInfo, int64_t timestamp); +int32_t generateSmlJsonTags(cJSON *tagsList, SSuperTable *stbInfo, + threadInfo *pThreadInfo, int tbSeq); +int32_t generateSmlJsonCols(cJSON *array, cJSON *tag, SSuperTable *stbInfo, + threadInfo *pThreadInfo, int64_t timestamp); +#endif \ No newline at end of file diff --git a/src/kit/taosdemo/insert.json b/src/kit/taosdemo/insert.json index 5f152a2d0c257931db4a5c69c007e524247f8fb8..43c729502cbf9ac11e138d9cbea60e459d3c27e5 100644 --- a/src/kit/taosdemo/insert.json +++ b/src/kit/taosdemo/insert.json @@ -21,7 +21,7 @@ "cache": 16, "blocks": 8, "precision": "ms", - "keep": 365, + "keep": 36500, "minRows": 100, "maxRows": 4096, "comp":2, diff --git a/src/kit/taosdemo/src/demoCommandOpt.c b/src/kit/taosdemo/src/demoCommandOpt.c new file mode 100644 index 0000000000000000000000000000000000000000..ede4c71d1de7376c85d681299d35ca2f2075d45b --- /dev/null +++ b/src/kit/taosdemo/src/demoCommandOpt.c @@ -0,0 +1,1804 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#include "demo.h" +#include "demoData.h" + +char *g_aggreFuncDemo[] = {"*", + "count(*)", + "avg(current)", + "sum(current)", + "max(current)", + "min(current)", + "first(current)", + "last(current)"}; +char *g_aggreFunc[] = {"*", "count(*)", "avg(C0)", "sum(C0)", + "max(C0)", "min(C0)", "first(C0)", "last(C0)"}; + +int parse_args(int argc, char *argv[]) { + int32_t code = -1; + for (int i = 1; i < argc; i++) { + if ((0 == strncmp(argv[i], "-f", strlen("-f"))) || + (0 == strncmp(argv[i], "--file", strlen("--file")))) { + g_args.demo_mode = false; + + if (2 == strlen(argv[i])) { + if (i + 1 == argc) { + errorPrintReqArg(argv[0], "f"); + goto end_parse_command; + } + g_args.metaFile = argv[++i]; + } else if (0 == strncmp(argv[i], "-f", strlen("-f"))) { + g_args.metaFile = (char *)(argv[i] + strlen("-f")); + } else if (strlen("--file") == strlen(argv[i])) { + if (i + 1 == argc) { + errorPrintReqArg3(argv[0], "--file"); + goto end_parse_command; + } + g_args.metaFile = argv[++i]; + } else if (0 == strncmp(argv[i], "--file=", strlen("--file="))) { + g_args.metaFile = (char *)(argv[i] + strlen("--file=")); + } else { + errorUnrecognized(argv[0], argv[i]); + goto end_parse_command; + } + } else if ((0 == strncmp(argv[i], "-c", strlen("-c"))) || + (0 == + strncmp(argv[i], "--config-dir", strlen("--config-dir")))) { + if (2 == strlen(argv[i])) { + if (argc == i + 1) { + errorPrintReqArg(argv[0], "c"); + goto end_parse_command; + } + tstrncpy(configDir, argv[++i], TSDB_FILENAME_LEN); + } else if (0 == strncmp(argv[i], "-c", strlen("-c"))) { + tstrncpy(configDir, (char *)(argv[i] + strlen("-c")), + TSDB_FILENAME_LEN); + } else if (strlen("--config-dir") == strlen(argv[i])) { + if (argc == i + 1) { + errorPrintReqArg3(argv[0], "--config-dir"); + goto end_parse_command; + } + tstrncpy(configDir, argv[++i], TSDB_FILENAME_LEN); + } else if (0 == strncmp(argv[i], + "--config-dir=", strlen("--config-dir="))) { + tstrncpy(configDir, (char *)(argv[i] + strlen("--config-dir=")), + TSDB_FILENAME_LEN); + } else { + errorUnrecognized(argv[0], argv[i]); + goto end_parse_command; + } + } else if ((0 == strncmp(argv[i], "-h", strlen("-h"))) || + (0 == strncmp(argv[i], "--host", strlen("--host")))) { + if (2 == strlen(argv[i])) { + if (argc == i + 1) { + errorPrintReqArg(argv[0], "h"); + goto end_parse_command; + } + g_args.host = argv[++i]; + } else if (0 == strncmp(argv[i], "-h", strlen("-h"))) { + g_args.host = (char *)(argv[i] + strlen("-h")); + } else if (strlen("--host") == strlen(argv[i])) { + if (argc == i + 1) { + errorPrintReqArg3(argv[0], "--host"); + goto end_parse_command; + } + g_args.host = argv[++i]; + } else if (0 == strncmp(argv[i], "--host=", strlen("--host="))) { + g_args.host = (char *)(argv[i] + strlen("--host=")); + } else { + errorUnrecognized(argv[0], argv[i]); + goto end_parse_command; + } + } else if (strcmp(argv[i], "-PP") == 0) { + g_args.performance_print = true; + } else if ((0 == strncmp(argv[i], "-P", strlen("-P"))) || + (0 == strncmp(argv[i], "--port", strlen("--port")))) { + uint64_t port; + char strPort[BIGINT_BUFF_LEN]; + + if (2 == strlen(argv[i])) { + if (argc == i + 1) { + errorPrintReqArg(argv[0], "P"); + goto end_parse_command; + } else if (isStringNumber(argv[i + 1])) { + tstrncpy(strPort, argv[++i], BIGINT_BUFF_LEN); + } else { + errorPrintReqArg2(argv[0], "P"); + goto end_parse_command; + } + } else if (0 == strncmp(argv[i], "--port=", strlen("--port="))) { + if (isStringNumber((char *)(argv[i] + strlen("--port=")))) { + tstrncpy(strPort, (char *)(argv[i] + strlen("--port=")), + BIGINT_BUFF_LEN); + } else { + errorPrintReqArg2(argv[0], "--port"); + goto end_parse_command; + } + } else if (0 == strncmp(argv[i], "-P", strlen("-P"))) { + if (isStringNumber((char *)(argv[i] + strlen("-P")))) { + tstrncpy(strPort, (char *)(argv[i] + strlen("-P")), + BIGINT_BUFF_LEN); + } else { + errorPrintReqArg2(argv[0], "--port"); + goto end_parse_command; + } + } else if (strlen("--port") == strlen(argv[i])) { + if (argc == i + 1) { + errorPrintReqArg3(argv[0], "--port"); + goto end_parse_command; + } else if (isStringNumber(argv[i + 1])) { + tstrncpy(strPort, argv[++i], BIGINT_BUFF_LEN); + } else { + errorPrintReqArg2(argv[0], "--port"); + goto end_parse_command; + } + } else { + errorUnrecognized(argv[0], argv[i]); + goto end_parse_command; + } + + port = atoi(strPort); + if (port > 65535) { + errorWrongValue("taosdump", "-P or --port", strPort); + goto end_parse_command; + } + g_args.port = (uint16_t)port; + + } else if ((0 == strncmp(argv[i], "-I", strlen("-I"))) || + (0 == + strncmp(argv[i], "--interface", strlen("--interface")))) { + if (2 == strlen(argv[i])) { + if (argc == i + 1) { + errorPrintReqArg(argv[0], "I"); + goto end_parse_command; + } + if (0 == strcasecmp(argv[i + 1], "taosc")) { + g_args.iface = TAOSC_IFACE; + } else if (0 == strcasecmp(argv[i + 1], "rest")) { + g_args.iface = REST_IFACE; + } else if (0 == strcasecmp(argv[i + 1], "stmt")) { + g_args.iface = STMT_IFACE; + } else if (0 == strcasecmp(argv[i + 1], "sml")) { + g_args.iface = SML_IFACE; + } else { + errorWrongValue(argv[0], "-I", argv[i + 1]); + goto end_parse_command; + } + i++; + } else if (0 == strncmp(argv[i], + "--interface=", strlen("--interface="))) { + if (0 == strcasecmp((char *)(argv[i] + strlen("--interface=")), + "taosc")) { + g_args.iface = TAOSC_IFACE; + } else if (0 == strcasecmp( + (char *)(argv[i] + strlen("--interface=")), + "rest")) { + g_args.iface = REST_IFACE; + } else if (0 == strcasecmp( + (char *)(argv[i] + strlen("--interface=")), + "stmt")) { + g_args.iface = STMT_IFACE; + } else if (0 == strcasecmp( + (char *)(argv[i] + strlen("--interface=")), + "sml")) { + g_args.iface = SML_IFACE; + } else { + errorPrintReqArg3(argv[0], "--interface"); + goto end_parse_command; + } + } else if (0 == strncmp(argv[i], "-I", strlen("-I"))) { + if (0 == + strcasecmp((char *)(argv[i] + strlen("-I")), "taosc")) { + g_args.iface = TAOSC_IFACE; + } else if (0 == strcasecmp((char *)(argv[i] + strlen("-I")), + "rest")) { + g_args.iface = REST_IFACE; + } else if (0 == strcasecmp((char *)(argv[i] + strlen("-I")), + "stmt")) { + g_args.iface = STMT_IFACE; + } else if (0 == strcasecmp((char *)(argv[i] + strlen("-I")), + "sml")) { + g_args.iface = SML_IFACE; + } else { + errorWrongValue(argv[0], "-I", + (char *)(argv[i] + strlen("-I"))); + goto end_parse_command; + } + } else if (strlen("--interface") == strlen(argv[i])) { + if (argc == i + 1) { + errorPrintReqArg3(argv[0], "--interface"); + goto end_parse_command; + } + if (0 == strcasecmp(argv[i + 1], "taosc")) { + g_args.iface = TAOSC_IFACE; + } else if (0 == strcasecmp(argv[i + 1], "rest")) { + g_args.iface = REST_IFACE; + } else if (0 == strcasecmp(argv[i + 1], "stmt")) { + g_args.iface = STMT_IFACE; + } else if (0 == strcasecmp(argv[i + 1], "sml")) { + g_args.iface = SML_IFACE; + } else { + errorWrongValue(argv[0], "--interface", argv[i + 1]); + goto end_parse_command; + } + i++; + } else { + errorUnrecognized(argv[0], argv[i]); + goto end_parse_command; + } + } else if ((0 == strncmp(argv[i], "-u", strlen("-u"))) || + (0 == strncmp(argv[i], "--user", strlen("--user")))) { + if (2 == strlen(argv[i])) { + if (argc == i + 1) { + errorPrintReqArg(argv[0], "u"); + goto end_parse_command; + } + g_args.user = argv[++i]; + } else if (0 == strncmp(argv[i], "-u", strlen("-u"))) { + g_args.user = (char *)(argv[i++] + strlen("-u")); + } else if (0 == strncmp(argv[i], "--user=", strlen("--user="))) { + g_args.user = (char *)(argv[i++] + strlen("--user=")); + } else if (strlen("--user") == strlen(argv[i])) { + if (argc == i + 1) { + errorPrintReqArg3(argv[0], "--user"); + goto end_parse_command; + } + g_args.user = argv[++i]; + } else { + errorUnrecognized(argv[0], argv[i]); + goto end_parse_command; + } + } else if ((0 == strncmp(argv[i], "-p", strlen("-p"))) || + (0 == strcmp(argv[i], "--password"))) { + if ((strlen(argv[i]) == 2) || + (0 == strcmp(argv[i], "--password"))) { + printf("Enter password: "); + taosSetConsoleEcho(false); + if (scanf("%s", g_args.password) > 1) { + fprintf(stderr, "password read error!\n"); + } + taosSetConsoleEcho(true); + } else { + tstrncpy(g_args.password, (char *)(argv[i] + 2), + SHELL_MAX_PASSWORD_LEN); + } + } else if ((0 == strncmp(argv[i], "-o", strlen("-o"))) || + (0 == strncmp(argv[i], "--output", strlen("--output")))) { + if (2 == strlen(argv[i])) { + if (argc == i + 1) { + errorPrintReqArg3(argv[0], "--output"); + goto end_parse_command; + } + g_args.output_file = argv[++i]; + } else if (0 == + strncmp(argv[i], "--output=", strlen("--output="))) { + g_args.output_file = (char *)(argv[i++] + strlen("--output=")); + } else if (0 == strncmp(argv[i], "-o", strlen("-o"))) { + g_args.output_file = (char *)(argv[i++] + strlen("-o")); + } else if (strlen("--output") == strlen(argv[i])) { + if (argc == i + 1) { + errorPrintReqArg3(argv[0], "--output"); + goto end_parse_command; + } + g_args.output_file = argv[++i]; + } else { + errorUnrecognized(argv[0], argv[i]); + goto end_parse_command; + } + } else if ((0 == strncmp(argv[i], "-s", strlen("-s"))) || + (0 == + strncmp(argv[i], "--sql-file", strlen("--sql-file")))) { + if (2 == strlen(argv[i])) { + if (argc == i + 1) { + errorPrintReqArg(argv[0], "s"); + goto end_parse_command; + } + g_args.sqlFile = argv[++i]; + } else if (0 == + strncmp(argv[i], "--sql-file=", strlen("--sql-file="))) { + g_args.sqlFile = (char *)(argv[i++] + strlen("--sql-file=")); + } else if (0 == strncmp(argv[i], "-s", strlen("-s"))) { + g_args.sqlFile = (char *)(argv[i++] + strlen("-s")); + } else if (strlen("--sql-file") == strlen(argv[i])) { + if (argc == i + 1) { + errorPrintReqArg3(argv[0], "--sql-file"); + goto end_parse_command; + } + g_args.sqlFile = argv[++i]; + } else { + errorUnrecognized(argv[0], argv[i]); + goto end_parse_command; + } + } else if ((0 == strncmp(argv[i], "-q", strlen("-q"))) || + (0 == + strncmp(argv[i], "--query-mode", strlen("--query-mode")))) { + if (2 == strlen(argv[i])) { + if (argc == i + 1) { + errorPrintReqArg(argv[0], "q"); + goto end_parse_command; + } else if (!isStringNumber(argv[i + 1])) { + errorPrintReqArg2(argv[0], "q"); + goto end_parse_command; + } + g_args.async_mode = atoi(argv[++i]); + } else if (0 == strncmp(argv[i], + "--query-mode=", strlen("--query-mode="))) { + if (isStringNumber( + (char *)(argv[i] + strlen("--query-mode=")))) { + g_args.async_mode = + atoi((char *)(argv[i] + strlen("--query-mode="))); + } else { + errorPrintReqArg2(argv[0], "--query-mode"); + goto end_parse_command; + } + } else if (0 == strncmp(argv[i], "-q", strlen("-q"))) { + if (isStringNumber((char *)(argv[i] + strlen("-q")))) { + g_args.async_mode = atoi((char *)(argv[i] + strlen("-q"))); + } else { + errorPrintReqArg2(argv[0], "-q"); + goto end_parse_command; + } + } else if (strlen("--query-mode") == strlen(argv[i])) { + if (argc == i + 1) { + errorPrintReqArg3(argv[0], "--query-mode"); + goto end_parse_command; + } else if (!isStringNumber(argv[i + 1])) { + errorPrintReqArg2(argv[0], "--query-mode"); + goto end_parse_command; + } + g_args.async_mode = atoi(argv[++i]); + } else { + errorUnrecognized(argv[0], argv[i]); + goto end_parse_command; + } + } else if ((0 == strncmp(argv[i], "-T", strlen("-T"))) || + (0 == strncmp(argv[i], "--threads", strlen("--threads")))) { + if (2 == strlen(argv[i])) { + if (argc == i + 1) { + errorPrintReqArg(argv[0], "T"); + goto end_parse_command; + } else if (!isStringNumber(argv[i + 1])) { + errorPrintReqArg2(argv[0], "T"); + goto end_parse_command; + } + g_args.nthreads = atoi(argv[++i]); + } else if (0 == + strncmp(argv[i], "--threads=", strlen("--threads="))) { + if (isStringNumber((char *)(argv[i] + strlen("--threads=")))) { + g_args.nthreads = + atoi((char *)(argv[i] + strlen("--threads="))); + } else { + errorPrintReqArg2(argv[0], "--threads"); + goto end_parse_command; + } + } else if (0 == strncmp(argv[i], "-T", strlen("-T"))) { + if (isStringNumber((char *)(argv[i] + strlen("-T")))) { + g_args.nthreads = atoi((char *)(argv[i] + strlen("-T"))); + } else { + errorPrintReqArg2(argv[0], "-T"); + goto end_parse_command; + } + } else if (strlen("--threads") == strlen(argv[i])) { + if (argc == i + 1) { + errorPrintReqArg3(argv[0], "--threads"); + goto end_parse_command; + } else if (!isStringNumber(argv[i + 1])) { + errorPrintReqArg2(argv[0], "--threads"); + goto end_parse_command; + } + g_args.nthreads = atoi(argv[++i]); + } else { + errorUnrecognized(argv[0], argv[i]); + goto end_parse_command; + } + } else if ((0 == strncmp(argv[i], "-i", strlen("-i"))) || + (0 == strncmp(argv[i], "--insert-interval", + strlen("--insert-interval")))) { + if (2 == strlen(argv[i])) { + if (argc == i + 1) { + errorPrintReqArg(argv[0], "i"); + goto end_parse_command; + } else if (!isStringNumber(argv[i + 1])) { + errorPrintReqArg2(argv[0], "i"); + goto end_parse_command; + } + g_args.insert_interval = atoi(argv[++i]); + } else if (0 == strncmp(argv[i], "--insert-interval=", + strlen("--insert-interval="))) { + if (isStringNumber( + (char *)(argv[i] + strlen("--insert-interval=")))) { + g_args.insert_interval = + atoi((char *)(argv[i] + strlen("--insert-interval="))); + } else { + errorPrintReqArg3(argv[0], "--insert-innterval"); + goto end_parse_command; + } + } else if (0 == strncmp(argv[i], "-i", strlen("-i"))) { + if (isStringNumber((char *)(argv[i] + strlen("-i")))) { + g_args.insert_interval = + atoi((char *)(argv[i] + strlen("-i"))); + } else { + errorPrintReqArg3(argv[0], "-i"); + goto end_parse_command; + } + } else if (strlen("--insert-interval") == strlen(argv[i])) { + if (argc == i + 1) { + errorPrintReqArg3(argv[0], "--insert-interval"); + goto end_parse_command; + } else if (!isStringNumber(argv[i + 1])) { + errorPrintReqArg2(argv[0], "--insert-interval"); + goto end_parse_command; + } + g_args.insert_interval = atoi(argv[++i]); + } else { + errorUnrecognized(argv[0], argv[i]); + goto end_parse_command; + } + } else if ((0 == strncmp(argv[i], "-S", strlen("-S"))) || + (0 == + strncmp(argv[i], "--time-step", strlen("--time-step")))) { + if (2 == strlen(argv[i])) { + if (argc == i + 1) { + errorPrintReqArg(argv[0], "S"); + goto end_parse_command; + } else if (!isStringNumber(argv[i + 1])) { + errorPrintReqArg2(argv[0], "S"); + goto end_parse_command; + } + g_args.timestamp_step = atoi(argv[++i]); + } else if (0 == strncmp(argv[i], + "--time-step=", strlen("--time-step="))) { + if (isStringNumber( + (char *)(argv[i] + strlen("--time-step=")))) { + g_args.timestamp_step = + atoi((char *)(argv[i] + strlen("--time-step="))); + } else { + errorPrintReqArg2(argv[0], "--time-step"); + goto end_parse_command; + } + } else if (0 == strncmp(argv[i], "-S", strlen("-S"))) { + if (isStringNumber((char *)(argv[i] + strlen("-S")))) { + g_args.timestamp_step = + atoi((char *)(argv[i] + strlen("-S"))); + } else { + errorPrintReqArg2(argv[0], "-S"); + goto end_parse_command; + } + } else if (strlen("--time-step") == strlen(argv[i])) { + if (argc == i + 1) { + errorPrintReqArg3(argv[0], "--time-step"); + goto end_parse_command; + } else if (!isStringNumber(argv[i + 1])) { + errorPrintReqArg2(argv[0], "--time-step"); + goto end_parse_command; + } + g_args.timestamp_step = atoi(argv[++i]); + } else { + errorUnrecognized(argv[0], argv[i]); + goto end_parse_command; + } + } else if (strcmp(argv[i], "-qt") == 0) { + if ((argc == i + 1) || (!isStringNumber(argv[i + 1]))) { + printHelp(); + errorPrint("%s", "\n\t-qt need a number following!\n"); + goto end_parse_command; + } + g_args.query_times = atoi(argv[++i]); + } else if ((0 == strncmp(argv[i], "-B", strlen("-B"))) || + (0 == strncmp(argv[i], "--interlace-rows", + strlen("--interlace-rows")))) { + if (strlen("-B") == strlen(argv[i])) { + if (argc == i + 1) { + errorPrintReqArg(argv[0], "B"); + goto end_parse_command; + } else if (!isStringNumber(argv[i + 1])) { + errorPrintReqArg2(argv[0], "B"); + goto end_parse_command; + } + g_args.interlaceRows = atoi(argv[++i]); + } else if (0 == strncmp(argv[i], "--interlace-rows=", + strlen("--interlace-rows="))) { + if (isStringNumber( + (char *)(argv[i] + strlen("--interlace-rows=")))) { + g_args.interlaceRows = + atoi((char *)(argv[i] + strlen("--interlace-rows="))); + } else { + errorPrintReqArg2(argv[0], "--interlace-rows"); + goto end_parse_command; + } + } else if (0 == strncmp(argv[i], "-B", strlen("-B"))) { + if (isStringNumber((char *)(argv[i] + strlen("-B")))) { + g_args.interlaceRows = + atoi((char *)(argv[i] + strlen("-B"))); + } else { + errorPrintReqArg2(argv[0], "-B"); + goto end_parse_command; + } + } else if (strlen("--interlace-rows") == strlen(argv[i])) { + if (argc == i + 1) { + errorPrintReqArg3(argv[0], "--interlace-rows"); + goto end_parse_command; + } else if (!isStringNumber(argv[i + 1])) { + errorPrintReqArg2(argv[0], "--interlace-rows"); + goto end_parse_command; + } + g_args.interlaceRows = atoi(argv[++i]); + } else { + errorUnrecognized(argv[0], argv[i]); + goto end_parse_command; + } + } else if ((0 == strncmp(argv[i], "-r", strlen("-r"))) || + (0 == strncmp(argv[i], "--rec-per-req", 13))) { + if (strlen("-r") == strlen(argv[i])) { + if (argc == i + 1) { + errorPrintReqArg(argv[0], "r"); + goto end_parse_command; + } else if (!isStringNumber(argv[i + 1])) { + errorPrintReqArg2(argv[0], "r"); + goto end_parse_command; + } + g_args.reqPerReq = atoi(argv[++i]); + } else if (0 == strncmp(argv[i], "--rec-per-req=", + strlen("--rec-per-req="))) { + if (isStringNumber( + (char *)(argv[i] + strlen("--rec-per-req=")))) { + g_args.reqPerReq = + atoi((char *)(argv[i] + strlen("--rec-per-req="))); + } else { + errorPrintReqArg2(argv[0], "--rec-per-req"); + goto end_parse_command; + } + } else if (0 == strncmp(argv[i], "-r", strlen("-r"))) { + if (isStringNumber((char *)(argv[i] + strlen("-r")))) { + g_args.reqPerReq = atoi((char *)(argv[i] + strlen("-r"))); + } else { + errorPrintReqArg2(argv[0], "-r"); + goto end_parse_command; + } + } else if (strlen("--rec-per-req") == strlen(argv[i])) { + if (argc == i + 1) { + errorPrintReqArg3(argv[0], "--rec-per-req"); + goto end_parse_command; + } else if (!isStringNumber(argv[i + 1])) { + errorPrintReqArg2(argv[0], "--rec-per-req"); + goto end_parse_command; + } + g_args.reqPerReq = atoi(argv[++i]); + } else { + errorUnrecognized(argv[0], argv[i]); + goto end_parse_command; + } + } else if ((0 == strncmp(argv[i], "-t", strlen("-t"))) || + (0 == strncmp(argv[i], "--tables", strlen("--tables")))) { + if (2 == strlen(argv[i])) { + if (argc == i + 1) { + errorPrintReqArg(argv[0], "t"); + goto end_parse_command; + } else if (!isStringNumber(argv[i + 1])) { + errorPrintReqArg2(argv[0], "t"); + goto end_parse_command; + } + g_args.ntables = atoi(argv[++i]); + } else if (0 == + strncmp(argv[i], "--tables=", strlen("--tables="))) { + if (isStringNumber((char *)(argv[i] + strlen("--tables=")))) { + g_args.ntables = + atoi((char *)(argv[i] + strlen("--tables="))); + } else { + errorPrintReqArg2(argv[0], "--tables"); + goto end_parse_command; + } + } else if (0 == strncmp(argv[i], "-t", strlen("-t"))) { + if (isStringNumber((char *)(argv[i] + strlen("-t")))) { + g_args.ntables = atoi((char *)(argv[i] + strlen("-t"))); + } else { + errorPrintReqArg2(argv[0], "-t"); + goto end_parse_command; + } + } else if (strlen("--tables") == strlen(argv[i])) { + if (argc == i + 1) { + errorPrintReqArg3(argv[0], "--tables"); + goto end_parse_command; + } else if (!isStringNumber(argv[i + 1])) { + errorPrintReqArg2(argv[0], "--tables"); + goto end_parse_command; + } + g_args.ntables = atoi(argv[++i]); + } else { + errorUnrecognized(argv[0], argv[i]); + goto end_parse_command; + } + + g_totalChildTables = g_args.ntables; + } else if ((0 == strncmp(argv[i], "-n", strlen("-n"))) || + (0 == strncmp(argv[i], "--records", strlen("--records")))) { + if (2 == strlen(argv[i])) { + if (argc == i + 1) { + errorPrintReqArg(argv[0], "n"); + goto end_parse_command; + } else if (!isStringNumber(argv[i + 1])) { + errorPrintReqArg2(argv[0], "n"); + goto end_parse_command; + } + g_args.insertRows = atoi(argv[++i]); + } else if (0 == + strncmp(argv[i], "--records=", strlen("--records="))) { + if (isStringNumber((char *)(argv[i] + strlen("--records=")))) { + g_args.insertRows = + atoi((char *)(argv[i] + strlen("--records="))); + } else { + errorPrintReqArg2(argv[0], "--records"); + goto end_parse_command; + } + } else if (0 == strncmp(argv[i], "-n", strlen("-n"))) { + if (isStringNumber((char *)(argv[i] + strlen("-n")))) { + g_args.insertRows = atoi((char *)(argv[i] + strlen("-n"))); + } else { + errorPrintReqArg2(argv[0], "-n"); + goto end_parse_command; + } + } else if (strlen("--records") == strlen(argv[i])) { + if (argc == i + 1) { + errorPrintReqArg3(argv[0], "--records"); + goto end_parse_command; + } else if (!isStringNumber(argv[i + 1])) { + errorPrintReqArg2(argv[0], "--records"); + goto end_parse_command; + } + g_args.insertRows = atoi(argv[++i]); + } else { + errorUnrecognized(argv[0], argv[i]); + goto end_parse_command; + } + } else if ((0 == strncmp(argv[i], "-d", strlen("-d"))) || + (0 == + strncmp(argv[i], "--database", strlen("--database")))) { + if (2 == strlen(argv[i])) { + if (argc == i + 1) { + errorPrintReqArg(argv[0], "d"); + goto end_parse_command; + } + g_args.database = argv[++i]; + } else if (0 == + strncmp(argv[i], "--database=", strlen("--database="))) { + g_args.output_file = (char *)(argv[i] + strlen("--database=")); + } else if (0 == strncmp(argv[i], "-d", strlen("-d"))) { + g_args.output_file = (char *)(argv[i] + strlen("-d")); + } else if (strlen("--database") == strlen(argv[i])) { + if (argc == i + 1) { + errorPrintReqArg3(argv[0], "--database"); + goto end_parse_command; + } + g_args.database = argv[++i]; + } else { + errorUnrecognized(argv[0], argv[i]); + goto end_parse_command; + } + } else if ((0 == strncmp(argv[i], "-l", strlen("-l"))) || + (0 == strncmp(argv[i], "--columns", strlen("--columns")))) { + g_args.demo_mode = false; + if (2 == strlen(argv[i])) { + if (argc == i + 1) { + errorPrintReqArg(argv[0], "l"); + goto end_parse_command; + } else if (!isStringNumber(argv[i + 1])) { + errorPrintReqArg2(argv[0], "l"); + goto end_parse_command; + } + g_args.columnCount = atoi(argv[++i]); + } else if (0 == + strncmp(argv[i], "--columns=", strlen("--columns="))) { + if (isStringNumber((char *)(argv[i] + strlen("--columns=")))) { + g_args.columnCount = + atoi((char *)(argv[i] + strlen("--columns="))); + } else { + errorPrintReqArg2(argv[0], "--columns"); + goto end_parse_command; + } + } else if (0 == strncmp(argv[i], "-l", strlen("-l"))) { + if (isStringNumber((char *)(argv[i] + strlen("-l")))) { + g_args.columnCount = atoi((char *)(argv[i] + strlen("-l"))); + } else { + errorPrintReqArg2(argv[0], "-l"); + goto end_parse_command; + } + } else if (strlen("--columns") == strlen(argv[i])) { + if (argc == i + 1) { + errorPrintReqArg3(argv[0], "--columns"); + goto end_parse_command; + } else if (!isStringNumber(argv[i + 1])) { + errorPrintReqArg2(argv[0], "--columns"); + goto end_parse_command; + } + g_args.columnCount = atoi(argv[++i]); + } else { + errorUnrecognized(argv[0], argv[i]); + goto end_parse_command; + } + + if (g_args.columnCount > MAX_NUM_COLUMNS) { + printf("WARNING: max acceptable columns count is %d\n", + MAX_NUM_COLUMNS); + prompt(); + g_args.columnCount = MAX_NUM_COLUMNS; + } + + for (int col = DEFAULT_DATATYPE_NUM; col < g_args.columnCount; + col++) { + g_args.dataType[col] = "INT"; + g_args.data_type[col] = TSDB_DATA_TYPE_INT; + } + for (int col = g_args.columnCount; col < MAX_NUM_COLUMNS; col++) { + g_args.dataType[col] = NULL; + g_args.data_type[col] = TSDB_DATA_TYPE_NULL; + } + } else if ((0 == strncmp(argv[i], "-b", strlen("-b"))) || + (0 == + strncmp(argv[i], "--data-type", strlen("--data-type")))) { + g_args.demo_mode = false; + + char *dataType; + if (2 == strlen(argv[i])) { + if (argc == i + 1) { + errorPrintReqArg(argv[0], "b"); + goto end_parse_command; + } + dataType = argv[++i]; + } else if (0 == strncmp(argv[i], + "--data-type=", strlen("--data-type="))) { + dataType = (char *)(argv[i] + strlen("--data-type=")); + } else if (0 == strncmp(argv[i], "-b", strlen("-b"))) { + dataType = (char *)(argv[i] + strlen("-b")); + } else if (strlen("--data-type") == strlen(argv[i])) { + if (argc == i + 1) { + errorPrintReqArg3(argv[0], "--data-type"); + goto end_parse_command; + } + dataType = argv[++i]; + } else { + errorUnrecognized(argv[0], argv[i]); + goto end_parse_command; + } + + if (strstr(dataType, ",") == NULL) { + // only one col + if (strcasecmp(dataType, "INT") && + strcasecmp(dataType, "FLOAT") && + strcasecmp(dataType, "TINYINT") && + strcasecmp(dataType, "BOOL") && + strcasecmp(dataType, "SMALLINT") && + strcasecmp(dataType, "BIGINT") && + strcasecmp(dataType, "DOUBLE") && + strcasecmp(dataType, "TIMESTAMP") && + !regexMatch(dataType, + "^(NCHAR|BINARY)(\\([1-9][0-9]*\\))?$", + REG_ICASE | REG_EXTENDED) && + strcasecmp(dataType, "UTINYINT") && + strcasecmp(dataType, "USMALLINT") && + strcasecmp(dataType, "UINT") && + strcasecmp(dataType, "UBIGINT")) { + printHelp(); + errorPrint("%s", "-b: Invalid data_type!\n"); + goto end_parse_command; + } + if (0 == strcasecmp(dataType, "INT")) { + g_args.data_type[0] = TSDB_DATA_TYPE_INT; + } else if (0 == strcasecmp(dataType, "TINYINT")) { + g_args.data_type[0] = TSDB_DATA_TYPE_TINYINT; + } else if (0 == strcasecmp(dataType, "SMALLINT")) { + g_args.data_type[0] = TSDB_DATA_TYPE_SMALLINT; + } else if (0 == strcasecmp(dataType, "BIGINT")) { + g_args.data_type[0] = TSDB_DATA_TYPE_BIGINT; + } else if (0 == strcasecmp(dataType, "FLOAT")) { + g_args.data_type[0] = TSDB_DATA_TYPE_FLOAT; + } else if (0 == strcasecmp(dataType, "DOUBLE")) { + g_args.data_type[0] = TSDB_DATA_TYPE_DOUBLE; + } else if (1 == regexMatch(dataType, + "^BINARY(\\([1-9][0-9]*\\))?$", + REG_ICASE | REG_EXTENDED)) { + g_args.data_type[0] = TSDB_DATA_TYPE_BINARY; + } else if (1 == regexMatch(dataType, + "^NCHAR(\\([1-9][0-9]*\\))?$", + REG_ICASE | REG_EXTENDED)) { + g_args.data_type[0] = TSDB_DATA_TYPE_NCHAR; + } else if (0 == strcasecmp(dataType, "BOOL")) { + g_args.data_type[0] = TSDB_DATA_TYPE_BOOL; + } else if (0 == strcasecmp(dataType, "TIMESTAMP")) { + g_args.data_type[0] = TSDB_DATA_TYPE_TIMESTAMP; + } else if (0 == strcasecmp(dataType, "UTINYINT")) { + g_args.data_type[0] = TSDB_DATA_TYPE_UTINYINT; + } else if (0 == strcasecmp(dataType, "USMALLINT")) { + g_args.data_type[0] = TSDB_DATA_TYPE_USMALLINT; + } else if (0 == strcasecmp(dataType, "UINT")) { + g_args.data_type[0] = TSDB_DATA_TYPE_UINT; + } else if (0 == strcasecmp(dataType, "UBIGINT")) { + g_args.data_type[0] = TSDB_DATA_TYPE_UBIGINT; + } else { + g_args.data_type[0] = TSDB_DATA_TYPE_NULL; + } + g_args.dataType[0] = dataType; + g_args.dataType[1] = NULL; + g_args.data_type[1] = TSDB_DATA_TYPE_NULL; + } else { + // more than one col + int index = 0; + g_dupstr = strdup(dataType); + char *running = g_dupstr; + char *token = strsep(&running, ","); + while (token != NULL) { + if (strcasecmp(token, "INT") && + strcasecmp(token, "FLOAT") && + strcasecmp(token, "TINYINT") && + strcasecmp(token, "BOOL") && + strcasecmp(token, "SMALLINT") && + strcasecmp(token, "BIGINT") && + strcasecmp(token, "DOUBLE") && + strcasecmp(token, "TIMESTAMP") && + !regexMatch(token, + "^(NCHAR|BINARY)(\\([1-9][0-9]*\\))?$", + REG_ICASE | REG_EXTENDED) && + strcasecmp(token, "UTINYINT") && + strcasecmp(token, "USMALLINT") && + strcasecmp(token, "UINT") && + strcasecmp(token, "UBIGINT")) { + printHelp(); + errorPrint("%s", "-b: Invalid data_type!\n"); + goto end_parse_command; + } + + if (0 == strcasecmp(token, "INT")) { + g_args.data_type[index] = TSDB_DATA_TYPE_INT; + } else if (0 == strcasecmp(token, "FLOAT")) { + g_args.data_type[index] = TSDB_DATA_TYPE_FLOAT; + } else if (0 == strcasecmp(token, "SMALLINT")) { + g_args.data_type[index] = TSDB_DATA_TYPE_SMALLINT; + } else if (0 == strcasecmp(token, "BIGINT")) { + g_args.data_type[index] = TSDB_DATA_TYPE_BIGINT; + } else if (0 == strcasecmp(token, "DOUBLE")) { + g_args.data_type[index] = TSDB_DATA_TYPE_DOUBLE; + } else if (0 == strcasecmp(token, "TINYINT")) { + g_args.data_type[index] = TSDB_DATA_TYPE_TINYINT; + } else if (1 == regexMatch(token, + "^BINARY(\\([1-9][0-9]*\\))?$", + REG_ICASE | REG_EXTENDED)) { + g_args.data_type[index] = TSDB_DATA_TYPE_BINARY; + } else if (1 == regexMatch(token, + "^NCHAR(\\([1-9][0-9]*\\))?$", + REG_ICASE | REG_EXTENDED)) { + g_args.data_type[index] = TSDB_DATA_TYPE_NCHAR; + } else if (0 == strcasecmp(token, "BOOL")) { + g_args.data_type[index] = TSDB_DATA_TYPE_BOOL; + } else if (0 == strcasecmp(token, "TIMESTAMP")) { + g_args.data_type[index] = TSDB_DATA_TYPE_TIMESTAMP; + } else if (0 == strcasecmp(token, "UTINYINT")) { + g_args.data_type[index] = TSDB_DATA_TYPE_UTINYINT; + } else if (0 == strcasecmp(token, "USMALLINT")) { + g_args.data_type[index] = TSDB_DATA_TYPE_USMALLINT; + } else if (0 == strcasecmp(token, "UINT")) { + g_args.data_type[index] = TSDB_DATA_TYPE_UINT; + } else if (0 == strcasecmp(token, "UBIGINT")) { + g_args.data_type[index] = TSDB_DATA_TYPE_UBIGINT; + } else { + g_args.data_type[index] = TSDB_DATA_TYPE_NULL; + } + g_args.dataType[index] = token; + index++; + token = strsep(&running, ","); + if (index >= MAX_NUM_COLUMNS) break; + } + g_args.dataType[index] = NULL; + g_args.data_type[index] = TSDB_DATA_TYPE_NULL; + } + } else if ((0 == strncmp(argv[i], "-w", strlen("-w"))) || + (0 == + strncmp(argv[i], "--binwidth", strlen("--binwidth")))) { + if (2 == strlen(argv[i])) { + if (argc == i + 1) { + errorPrintReqArg(argv[0], "w"); + goto end_parse_command; + } else if (!isStringNumber(argv[i + 1])) { + errorPrintReqArg2(argv[0], "w"); + goto end_parse_command; + } + g_args.binwidth = atoi(argv[++i]); + } else if (0 == + strncmp(argv[i], "--binwidth=", strlen("--binwidth="))) { + if (isStringNumber((char *)(argv[i] + strlen("--binwidth=")))) { + g_args.binwidth = + atoi((char *)(argv[i] + strlen("--binwidth="))); + } else { + errorPrintReqArg2(argv[0], "--binwidth"); + goto end_parse_command; + } + } else if (0 == strncmp(argv[i], "-w", strlen("-w"))) { + if (isStringNumber((char *)(argv[i] + strlen("-w")))) { + g_args.binwidth = atoi((char *)(argv[i] + strlen("-w"))); + } else { + errorPrintReqArg2(argv[0], "-w"); + goto end_parse_command; + } + } else if (strlen("--binwidth") == strlen(argv[i])) { + if (argc == i + 1) { + errorPrintReqArg3(argv[0], "--binwidth"); + goto end_parse_command; + } else if (!isStringNumber(argv[i + 1])) { + errorPrintReqArg2(argv[0], "--binwidth"); + goto end_parse_command; + } + g_args.binwidth = atoi(argv[++i]); + } else { + errorUnrecognized(argv[0], argv[i]); + goto end_parse_command; + } + } else if ((0 == strncmp(argv[i], "-m", strlen("-m"))) || + (0 == strncmp(argv[i], "--table-prefix", + strlen("--table-prefix")))) { + if (2 == strlen(argv[i])) { + if (argc == i + 1) { + errorPrintReqArg(argv[0], "m"); + goto end_parse_command; + } + g_args.tb_prefix = argv[++i]; + } else if (0 == strncmp(argv[i], "--table-prefix=", + strlen("--table-prefix="))) { + g_args.tb_prefix = + (char *)(argv[i] + strlen("--table-prefix=")); + } else if (0 == strncmp(argv[i], "-m", strlen("-m"))) { + g_args.tb_prefix = (char *)(argv[i] + strlen("-m")); + } else if (strlen("--table-prefix") == strlen(argv[i])) { + if (argc == i + 1) { + errorPrintReqArg3(argv[0], "--table-prefix"); + goto end_parse_command; + } + g_args.tb_prefix = argv[++i]; + } else { + errorUnrecognized(argv[0], argv[i]); + goto end_parse_command; + } + } else if ((0 == strncmp(argv[i], "-E", strlen("-E"))) || + (0 == strncmp(argv[i], "--escape-character", + strlen("--escape-character")))) { + g_args.escapeChar = true; + } else if ((strcmp(argv[i], "-N") == 0) || + (0 == strcmp(argv[i], "--normal-table"))) { + g_args.demo_mode = false; + g_args.use_metric = false; + } else if ((strcmp(argv[i], "-M") == 0) || + (0 == strcmp(argv[i], "--random"))) { + g_args.demo_mode = false; + } else if ((strcmp(argv[i], "-x") == 0) || + (0 == strcmp(argv[i], "--aggr-func"))) { + g_args.aggr_func = true; + } else if ((strcmp(argv[i], "-y") == 0) || + (0 == strcmp(argv[i], "--answer-yes"))) { + g_args.answer_yes = true; + } else if ((strcmp(argv[i], "-g") == 0) || + (0 == strcmp(argv[i], "--debug"))) { + g_args.debug_print = true; + } else if (strcmp(argv[i], "-gg") == 0) { + g_args.verbose_print = true; + } else if ((0 == strncmp(argv[i], "-R", strlen("-R"))) || + (0 == strncmp(argv[i], "--disorder-range", + strlen("--disorder-range")))) { + if (strlen("-R") == strlen(argv[i])) { + if (argc == i + 1) { + errorPrintReqArg(argv[0], "R"); + goto end_parse_command; + } else if (!isStringNumber(argv[i + 1])) { + errorPrintReqArg2(argv[0], "R"); + goto end_parse_command; + } + g_args.disorderRange = atoi(argv[++i]); + } else if (0 == strncmp(argv[i], "--disorder-range=", + strlen("--disorder-range="))) { + if (isStringNumber( + (char *)(argv[i] + strlen("--disorder-range=")))) { + g_args.disorderRange = + atoi((char *)(argv[i] + strlen("--disorder-range="))); + } else { + errorPrintReqArg2(argv[0], "--disorder-range"); + goto end_parse_command; + } + } else if (0 == strncmp(argv[i], "-R", strlen("-R"))) { + if (isStringNumber((char *)(argv[i] + strlen("-R")))) { + g_args.disorderRange = + atoi((char *)(argv[i] + strlen("-R"))); + } else { + errorPrintReqArg2(argv[0], "-R"); + goto end_parse_command; + } + + if (g_args.disorderRange < 0) { + errorPrint("Invalid disorder range %d, will be set to %d\n", + g_args.disorderRange, 1000); + g_args.disorderRange = 1000; + } + } else if (strlen("--disorder-range") == strlen(argv[i])) { + if (argc == i + 1) { + errorPrintReqArg3(argv[0], "--disorder-range"); + goto end_parse_command; + } else if (!isStringNumber(argv[i + 1])) { + errorPrintReqArg2(argv[0], "--disorder-range"); + goto end_parse_command; + } + g_args.disorderRange = atoi(argv[++i]); + } else { + errorUnrecognized(argv[0], argv[i]); + goto end_parse_command; + } + } else if ((0 == strncmp(argv[i], "-O", strlen("-O"))) || + (0 == + strncmp(argv[i], "--disorder", strlen("--disorder")))) { + if (2 == strlen(argv[i])) { + if (argc == i + 1) { + errorPrintReqArg(argv[0], "O"); + goto end_parse_command; + } else if (!isStringNumber(argv[i + 1])) { + errorPrintReqArg2(argv[0], "O"); + goto end_parse_command; + } + g_args.disorderRatio = atoi(argv[++i]); + } else if (0 == + strncmp(argv[i], "--disorder=", strlen("--disorder="))) { + if (isStringNumber((char *)(argv[i] + strlen("--disorder=")))) { + g_args.disorderRatio = + atoi((char *)(argv[i] + strlen("--disorder="))); + } else { + errorPrintReqArg2(argv[0], "--disorder"); + goto end_parse_command; + } + } else if (0 == strncmp(argv[i], "-O", strlen("-O"))) { + if (isStringNumber((char *)(argv[i] + strlen("-O")))) { + g_args.disorderRatio = + atoi((char *)(argv[i] + strlen("-O"))); + } else { + errorPrintReqArg2(argv[0], "-O"); + goto end_parse_command; + } + } else if (strlen("--disorder") == strlen(argv[i])) { + if (argc == i + 1) { + errorPrintReqArg3(argv[0], "--disorder"); + goto end_parse_command; + } else if (!isStringNumber(argv[i + 1])) { + errorPrintReqArg2(argv[0], "--disorder"); + goto end_parse_command; + } + g_args.disorderRatio = atoi(argv[++i]); + } else { + errorUnrecognized(argv[0], argv[i]); + goto end_parse_command; + } + + if (g_args.disorderRatio > 50) { + errorPrint("Invalid disorder ratio %d, will be set to %d\n", + g_args.disorderRatio, 50); + g_args.disorderRatio = 50; + } + } else if ((0 == strncmp(argv[i], "-a", strlen("-a"))) || + (0 == strncmp(argv[i], "--replica", strlen("--replica")))) { + if (2 == strlen(argv[i])) { + if (argc == i + 1) { + errorPrintReqArg(argv[0], "a"); + goto end_parse_command; + } else if (!isStringNumber(argv[i + 1])) { + errorPrintReqArg2(argv[0], "a"); + goto end_parse_command; + } + g_args.replica = atoi(argv[++i]); + } else if (0 == + strncmp(argv[i], "--replica=", strlen("--replica="))) { + if (isStringNumber((char *)(argv[i] + strlen("--replica=")))) { + g_args.replica = + atoi((char *)(argv[i] + strlen("--replica="))); + } else { + errorPrintReqArg2(argv[0], "--replica"); + goto end_parse_command; + } + } else if (0 == strncmp(argv[i], "-a", strlen("-a"))) { + if (isStringNumber((char *)(argv[i] + strlen("-a")))) { + g_args.replica = atoi((char *)(argv[i] + strlen("-a"))); + } else { + errorPrintReqArg2(argv[0], "-a"); + goto end_parse_command; + } + } else if (strlen("--replica") == strlen(argv[i])) { + if (argc == i + 1) { + errorPrintReqArg3(argv[0], "--replica"); + goto end_parse_command; + } else if (!isStringNumber(argv[i + 1])) { + errorPrintReqArg2(argv[0], "--replica"); + goto end_parse_command; + } + g_args.replica = atoi(argv[++i]); + } else { + errorUnrecognized(argv[0], argv[i]); + goto end_parse_command; + } + + if (g_args.replica > 3 || g_args.replica < 1) { + errorPrint("Invalid replica value %d, will be set to %d\n", + g_args.replica, 1); + g_args.replica = 1; + } + } else if (strcmp(argv[i], "-D") == 0) { + g_args.method_of_delete = atoi(argv[++i]); + if (g_args.method_of_delete > 3) { + errorPrint("%s", + "\n\t-D need a value (0~3) number following!\n"); + goto end_parse_command; + } + } else if ((strcmp(argv[i], "--version") == 0) || + (strcmp(argv[i], "-V") == 0)) { + printVersion(); + } else if ((strcmp(argv[i], "--help") == 0) || + (strcmp(argv[i], "-?") == 0)) { + printHelp(); + } else if (strcmp(argv[i], "--usage") == 0) { + printf( + " Usage: taosdemo [-f JSONFILE] [-u USER] [-p PASSWORD] [-c CONFIG_DIR]\n\ + [-h HOST] [-P PORT] [-I INTERFACE] [-d DATABASE] [-a REPLICA]\n\ + [-m TABLEPREFIX] [-s SQLFILE] [-N] [-o OUTPUTFILE] [-q QUERYMODE]\n\ + [-b DATATYPES] [-w WIDTH_OF_BINARY] [-l COLUMNS] [-T THREADNUMBER]\n\ + [-i SLEEPTIME] [-S TIME_STEP] [-B INTERLACE_ROWS] [-t TABLES]\n\ + [-n RECORDS] [-M] [-x] [-y] [-O ORDERMODE] [-R RANGE] [-a REPLIcA][-g]\n\ + [--help] [--usage] [--version]\n"); + exit(EXIT_SUCCESS); + } else { + // to simulate argp_option output + if (strlen(argv[i]) > 2) { + if (0 == strncmp(argv[i], "--", 2)) { + fprintf(stderr, "%s: unrecognized options '%s'\n", argv[0], + argv[i]); + } else if (0 == strncmp(argv[i], "-", 1)) { + char tmp[2] = {0}; + tstrncpy(tmp, argv[i] + 1, 2); + fprintf(stderr, "%s: invalid options -- '%s'\n", argv[0], + tmp); + } else { + fprintf(stderr, "%s: Too many arguments\n", argv[0]); + } + } else { + fprintf(stderr, "%s invalid options -- '%s'\n", argv[0], + (char *)((char *)argv[i]) + 1); + } + fprintf(stderr, + "Try `taosdemo --help' or `taosdemo --usage' for more " + "information.\n"); + goto end_parse_command; + } + } + + int columnCount; + for (columnCount = 0; columnCount < MAX_NUM_COLUMNS; columnCount++) { + if (g_args.dataType[columnCount] == NULL) { + break; + } + } + + if (0 == columnCount) { + errorPrint("%s", "data type error!\n"); + goto end_parse_command; + } + g_args.columnCount = columnCount; + + g_args.lenOfOneRow = TIMESTAMP_BUFF_LEN; // timestamp + for (int c = 0; c < g_args.columnCount; c++) { + switch (g_args.data_type[c]) { + case TSDB_DATA_TYPE_BINARY: + g_args.lenOfOneRow += g_args.binwidth + 3; + break; + + case TSDB_DATA_TYPE_NCHAR: + g_args.lenOfOneRow += g_args.binwidth + 3; + break; + + case TSDB_DATA_TYPE_INT: + case TSDB_DATA_TYPE_UINT: + g_args.lenOfOneRow += INT_BUFF_LEN; + break; + + case TSDB_DATA_TYPE_BIGINT: + case TSDB_DATA_TYPE_UBIGINT: + g_args.lenOfOneRow += BIGINT_BUFF_LEN; + break; + + case TSDB_DATA_TYPE_SMALLINT: + case TSDB_DATA_TYPE_USMALLINT: + g_args.lenOfOneRow += SMALLINT_BUFF_LEN; + break; + + case TSDB_DATA_TYPE_TINYINT: + case TSDB_DATA_TYPE_UTINYINT: + g_args.lenOfOneRow += TINYINT_BUFF_LEN; + break; + + case TSDB_DATA_TYPE_BOOL: + g_args.lenOfOneRow += BOOL_BUFF_LEN; + break; + + case TSDB_DATA_TYPE_FLOAT: + g_args.lenOfOneRow += FLOAT_BUFF_LEN; + break; + + case TSDB_DATA_TYPE_DOUBLE: + g_args.lenOfOneRow += DOUBLE_BUFF_LEN; + break; + + case TSDB_DATA_TYPE_TIMESTAMP: + g_args.lenOfOneRow += TIMESTAMP_BUFF_LEN; + break; + + default: + errorPrint("get error data type : %s\n", g_args.dataType[c]); + goto end_parse_command; + } + } + + if (((g_args.debug_print) && (NULL != g_args.metaFile)) || + g_args.verbose_print) { + printf( + "##################################################################" + "#\n"); + printf("# meta file: %s\n", g_args.metaFile); + printf("# Server IP: %s:%hu\n", + g_args.host == NULL ? "localhost" : g_args.host, g_args.port); + printf("# User: %s\n", g_args.user); + printf("# Password: %s\n", g_args.password); + printf("# Use metric: %s\n", + g_args.use_metric ? "true" : "false"); + if (*(g_args.dataType)) { + printf("# Specified data type: "); + for (int c = 0; c < MAX_NUM_COLUMNS; c++) + if (g_args.dataType[c]) + printf("%s,", g_args.dataType[c]); + else + break; + printf("\n"); + } + printf("# Insertion interval: %" PRIu64 "\n", + g_args.insert_interval); + printf("# Number of records per req: %u\n", g_args.reqPerReq); + printf("# Max SQL length: %" PRIu64 "\n", + g_args.max_sql_len); + printf("# Length of Binary: %d\n", g_args.binwidth); + printf("# Number of Threads: %d\n", g_args.nthreads); + printf("# Number of Tables: %" PRId64 "\n", + g_args.ntables); + printf("# Number of Data per Table: %" PRId64 "\n", + g_args.insertRows); + printf("# Database name: %s\n", g_args.database); + printf("# Table prefix: %s\n", g_args.tb_prefix); + if (g_args.disorderRatio) { + printf("# Data order: %d\n", + g_args.disorderRatio); + printf("# Data out of order rate: %d\n", + g_args.disorderRange); + } + printf("# Delete method: %d\n", + g_args.method_of_delete); + printf("# Answer yes when prompt: %d\n", g_args.answer_yes); + printf("# Print debug info: %d\n", g_args.debug_print); + printf("# Print verbose info: %d\n", + g_args.verbose_print); + printf( + "##################################################################" + "#\n"); + + prompt(); + } + code = 0; +end_parse_command: + return code; +} +void setParaFromArg() { + char type[20]; + char length[20]; + if (g_args.host) { + tstrncpy(g_Dbs.host, g_args.host, MAX_HOSTNAME_SIZE); + } else { + tstrncpy(g_Dbs.host, "127.0.0.1", MAX_HOSTNAME_SIZE); + } + + if (g_args.user) { + tstrncpy(g_Dbs.user, g_args.user, MAX_USERNAME_SIZE); + } + + tstrncpy(g_Dbs.password, g_args.password, SHELL_MAX_PASSWORD_LEN); + + if (g_args.port) { + g_Dbs.port = g_args.port; + } + + g_Dbs.threadCount = g_args.nthreads; + g_Dbs.threadCountForCreateTbl = g_args.nthreads; + + g_Dbs.dbCount = 1; + g_Dbs.db[0].drop = true; + + tstrncpy(g_Dbs.db[0].dbName, g_args.database, TSDB_DB_NAME_LEN); + g_Dbs.db[0].dbCfg.replica = g_args.replica; + tstrncpy(g_Dbs.db[0].dbCfg.precision, "ms", SMALL_BUFF_LEN); + + tstrncpy(g_Dbs.resultFile, g_args.output_file, MAX_FILE_NAME_LEN); + + g_Dbs.use_metric = g_args.use_metric; + g_args.prepared_rand = min(g_args.insertRows, MAX_PREPARED_RAND); + g_Dbs.aggr_func = g_args.aggr_func; + + char dataString[TSDB_MAX_BYTES_PER_ROW]; + char * data_type = g_args.data_type; + char **dataType = g_args.dataType; + + memset(dataString, 0, TSDB_MAX_BYTES_PER_ROW); + + if ((data_type[0] == TSDB_DATA_TYPE_BINARY) || + (data_type[0] == TSDB_DATA_TYPE_BOOL) || + (data_type[0] == TSDB_DATA_TYPE_NCHAR)) { + g_Dbs.aggr_func = false; + } + + if (g_args.use_metric) { + g_Dbs.db[0].superTblCount = 1; + tstrncpy(g_Dbs.db[0].superTbls[0].stbName, "meters", + TSDB_TABLE_NAME_LEN); + g_Dbs.db[0].superTbls[0].childTblCount = g_args.ntables; + g_Dbs.db[0].superTbls[0].escapeChar = g_args.escapeChar; + g_Dbs.threadCount = g_args.nthreads; + g_Dbs.threadCountForCreateTbl = g_args.nthreads; + g_Dbs.asyncMode = g_args.async_mode; + + g_Dbs.db[0].superTbls[0].autoCreateTable = PRE_CREATE_SUBTBL; + g_Dbs.db[0].superTbls[0].childTblExists = TBL_NO_EXISTS; + g_Dbs.db[0].superTbls[0].disorderRange = g_args.disorderRange; + g_Dbs.db[0].superTbls[0].disorderRatio = g_args.disorderRatio; + tstrncpy(g_Dbs.db[0].superTbls[0].childTblPrefix, g_args.tb_prefix, + TBNAME_PREFIX_LEN); + tstrncpy(g_Dbs.db[0].superTbls[0].dataSource, "rand", SMALL_BUFF_LEN); + + if (g_args.iface == INTERFACE_BUT) { + g_Dbs.db[0].superTbls[0].iface = TAOSC_IFACE; + } else { + g_Dbs.db[0].superTbls[0].iface = g_args.iface; + } + g_Dbs.db[0].superTbls[0].lineProtocol = TSDB_SML_LINE_PROTOCOL; + g_Dbs.db[0].superTbls[0].tsPrecision = TSDB_SML_TIMESTAMP_MILLI_SECONDS; + tstrncpy(g_Dbs.db[0].superTbls[0].startTimestamp, + "2017-07-14 10:40:00.000", MAX_TB_NAME_SIZE); + g_Dbs.db[0].superTbls[0].timeStampStep = g_args.timestamp_step; + + g_Dbs.db[0].superTbls[0].insertRows = g_args.insertRows; + g_Dbs.db[0].superTbls[0].maxSqlLen = g_args.max_sql_len; + + g_Dbs.db[0].superTbls[0].columnCount = 0; + for (int i = 0; i < MAX_NUM_COLUMNS; i++) { + if (data_type[i] == TSDB_DATA_TYPE_NULL) { + break; + } + + g_Dbs.db[0].superTbls[0].columns[i].data_type = data_type[i]; + tstrncpy(g_Dbs.db[0].superTbls[0].columns[i].dataType, dataType[i], + min(DATATYPE_BUFF_LEN, strlen(dataType[i]) + 1)); + if (1 == regexMatch(dataType[i], + "^(NCHAR|BINARY)(\\([1-9][0-9]*\\))$", + REG_ICASE | REG_EXTENDED)) { + sscanf(dataType[i], "%[^(](%[^)]", type, length); + g_Dbs.db[0].superTbls[0].columns[i].dataLen = atoi(length); + tstrncpy(g_Dbs.db[0].superTbls[0].columns[i].dataType, type, + min(DATATYPE_BUFF_LEN, strlen(type) + 1)); + } else { + switch (g_Dbs.db[0].superTbls[0].columns[i].data_type) { + case TSDB_DATA_TYPE_BOOL: + case TSDB_DATA_TYPE_UTINYINT: + case TSDB_DATA_TYPE_TINYINT: + g_Dbs.db[0].superTbls[0].columns[i].dataLen = + sizeof(char); + break; + case TSDB_DATA_TYPE_SMALLINT: + case TSDB_DATA_TYPE_USMALLINT: + g_Dbs.db[0].superTbls[0].columns[i].dataLen = + sizeof(int16_t); + break; + case TSDB_DATA_TYPE_INT: + case TSDB_DATA_TYPE_UINT: + g_Dbs.db[0].superTbls[0].columns[i].dataLen = + sizeof(int32_t); + break; + case TSDB_DATA_TYPE_TIMESTAMP: + case TSDB_DATA_TYPE_BIGINT: + case TSDB_DATA_TYPE_UBIGINT: + g_Dbs.db[0].superTbls[0].columns[i].dataLen = + sizeof(int64_t); + break; + case TSDB_DATA_TYPE_FLOAT: + g_Dbs.db[0].superTbls[0].columns[i].dataLen = + sizeof(float); + break; + case TSDB_DATA_TYPE_DOUBLE: + g_Dbs.db[0].superTbls[0].columns[i].dataLen = + sizeof(double); + break; + default: + g_Dbs.db[0].superTbls[0].columns[i].dataLen = + g_args.binwidth; + break; + } + tstrncpy(g_Dbs.db[0].superTbls[0].columns[i].dataType, + dataType[i], + min(DATATYPE_BUFF_LEN, strlen(dataType[i]) + 1)); + } + g_Dbs.db[0].superTbls[0].columnCount++; + } + + if (g_Dbs.db[0].superTbls[0].columnCount > g_args.columnCount) { + g_Dbs.db[0].superTbls[0].columnCount = g_args.columnCount; + } else { + for (int i = g_Dbs.db[0].superTbls[0].columnCount; + i < g_args.columnCount; i++) { + g_Dbs.db[0].superTbls[0].columns[i].data_type = + TSDB_DATA_TYPE_INT; + tstrncpy(g_Dbs.db[0].superTbls[0].columns[i].dataType, "INT", + min(DATATYPE_BUFF_LEN, strlen("INT") + 1)); + g_Dbs.db[0].superTbls[0].columns[i].dataLen = sizeof(int32_t); + g_Dbs.db[0].superTbls[0].columnCount++; + } + } + + tstrncpy(g_Dbs.db[0].superTbls[0].tags[0].dataType, "INT", + min(DATATYPE_BUFF_LEN, strlen("INT") + 1)); + g_Dbs.db[0].superTbls[0].tags[0].data_type = TSDB_DATA_TYPE_INT; + g_Dbs.db[0].superTbls[0].tags[0].dataLen = sizeof(int32_t); + + tstrncpy(g_Dbs.db[0].superTbls[0].tags[1].dataType, "BINARY", + min(DATATYPE_BUFF_LEN, strlen("BINARY") + 1)); + g_Dbs.db[0].superTbls[0].tags[1].data_type = TSDB_DATA_TYPE_BINARY; + g_Dbs.db[0].superTbls[0].tags[1].dataLen = g_args.binwidth; + g_Dbs.db[0].superTbls[0].tagCount = 2; + } else { + g_Dbs.threadCountForCreateTbl = g_args.nthreads; + g_Dbs.db[0].superTbls[0].tagCount = 0; + } +} + +void querySqlFile(TAOS *taos, char *sqlFile) { + FILE *fp = fopen(sqlFile, "r"); + if (fp == NULL) { + printf("failed to open file %s, reason:%s\n", sqlFile, strerror(errno)); + return; + } + + int read_len = 0; + char *cmd = calloc(1, TSDB_MAX_BYTES_PER_ROW); + if (cmd == NULL) { + errorPrint("%s", "failde to allocate memory\n"); + return; + } + size_t cmd_len = 0; + char * line = NULL; + size_t line_len = 0; + + double t = (double)taosGetTimestampMs(); + + while ((read_len = tgetline(&line, &line_len, fp)) != -1) { + if (read_len >= TSDB_MAX_BYTES_PER_ROW) continue; + line[--read_len] = '\0'; + + if (read_len == 0 || isCommentLine(line)) { // line starts with # + continue; + } + + if (line[read_len - 1] == '\\') { + line[read_len - 1] = ' '; + memcpy(cmd + cmd_len, line, read_len); + cmd_len += read_len; + continue; + } + + memcpy(cmd + cmd_len, line, read_len); + if (0 != queryDbExec(taos, cmd, NO_INSERT_TYPE, false)) { + errorPrint("queryDbExec %s failed!\n", cmd); + tmfree(cmd); + tmfree(line); + tmfclose(fp); + return; + } + memset(cmd, 0, TSDB_MAX_BYTES_PER_ROW); + cmd_len = 0; + } + + t = taosGetTimestampMs() - t; + printf("run %s took %.6f second(s)\n\n", sqlFile, t / 1000000); + + tmfree(cmd); + tmfree(line); + tmfclose(fp); + return; +} + +void *queryStableAggrFunc(void *sarg) { + threadInfo *pThreadInfo = (threadInfo *)sarg; + TAOS * taos = pThreadInfo->taos; + setThreadName("queryStableAggrFunc"); + char *command = calloc(1, BUFFER_SIZE); + if (NULL == command) { + errorPrint("%s", "failed to allocate memory\n"); + return NULL; + } + + FILE *fp = fopen(pThreadInfo->filePath, "a"); + if (NULL == fp) { + errorPrint("fopen %s fail, reason:%s.\n", pThreadInfo->filePath, + strerror(errno)); + free(command); + return NULL; + } + + int64_t insertRows = pThreadInfo->stbInfo->insertRows; + int64_t ntables = + pThreadInfo->ntables; // pThreadInfo->end_table_to - + // pThreadInfo->start_table_from + 1; + int64_t totalData = insertRows * ntables; + bool aggr_func = g_Dbs.aggr_func; + + char **aggreFunc; + int n; + + if (g_args.demo_mode) { + aggreFunc = g_aggreFuncDemo; + n = aggr_func ? (sizeof(g_aggreFuncDemo) / sizeof(g_aggreFuncDemo[0])) + : 2; + } else { + aggreFunc = g_aggreFunc; + n = aggr_func ? (sizeof(g_aggreFunc) / sizeof(g_aggreFunc[0])) : 2; + } + + if (!aggr_func) { + printf( + "\nThe first field is either Binary or Bool. Aggregation functions " + "are not supported.\n"); + } + + printf("%" PRId64 " records:\n", totalData); + fprintf(fp, "Querying On %" PRId64 " records:\n", totalData); + + for (int j = 0; j < n; j++) { + char condition[COND_BUF_LEN] = "\0"; + char tempS[64] = "\0"; + + int64_t m = 10 < ntables ? 10 : ntables; + + for (int64_t i = 1; i <= m; i++) { + if (i == 1) { + if (g_args.demo_mode) { + sprintf(tempS, "groupid = %" PRId64 "", i); + } else { + sprintf(tempS, "t0 = %" PRId64 "", i); + } + } else { + if (g_args.demo_mode) { + sprintf(tempS, " or groupid = %" PRId64 " ", i); + } else { + sprintf(tempS, " or t0 = %" PRId64 " ", i); + } + } + strncat(condition, tempS, COND_BUF_LEN - 1); + + sprintf(command, "SELECT %s FROM meters WHERE %s", aggreFunc[j], + condition); + + printf("Where condition: %s\n", condition); + + debugPrint("%s() LN%d, sql command: %s\n", __func__, __LINE__, + command); + fprintf(fp, "%s\n", command); + + double t = (double)taosGetTimestampUs(); + + TAOS_RES *pSql = taos_query(taos, command); + int32_t code = taos_errno(pSql); + + if (code != 0) { + errorPrint("Failed to query:%s\n", taos_errstr(pSql)); + taos_free_result(pSql); + taos_close(taos); + fclose(fp); + free(command); + return NULL; + } + int count = 0; + while (taos_fetch_row(pSql) != NULL) { + count++; + } + t = taosGetTimestampUs() - t; + + fprintf(fp, "| Speed: %12.2f(per s) | Latency: %.4f(ms) |\n", + ntables * insertRows / (t / 1000), t); + printf("select %10s took %.6f second(s)\n\n", aggreFunc[j], + t / 1000000); + + taos_free_result(pSql); + } + fprintf(fp, "\n"); + } + fclose(fp); + free(command); + + return NULL; +} + +void *queryNtableAggrFunc(void *sarg) { + threadInfo *pThreadInfo = (threadInfo *)sarg; + TAOS * taos = pThreadInfo->taos; + setThreadName("queryNtableAggrFunc"); + char *command = calloc(1, BUFFER_SIZE); + if (NULL == command) { + errorPrint("%s", "failed to allocate memory\n"); + return NULL; + } + + uint64_t startTime = pThreadInfo->start_time; + char * tb_prefix = pThreadInfo->tb_prefix; + FILE * fp = fopen(pThreadInfo->filePath, "a"); + if (NULL == fp) { + errorPrint("fopen %s fail, reason:%s.\n", pThreadInfo->filePath, + strerror(errno)); + free(command); + return NULL; + } + + int64_t insertRows; + /* if (pThreadInfo->stbInfo) { + insertRows = pThreadInfo->stbInfo->insertRows; // nrecords_per_table; + } else { + */ + insertRows = g_args.insertRows; + // } + + int64_t ntables = + pThreadInfo->ntables; // pThreadInfo->end_table_to - + // pThreadInfo->start_table_from + 1; + int64_t totalData = insertRows * ntables; + bool aggr_func = g_Dbs.aggr_func; + + char **aggreFunc; + int n; + + if (g_args.demo_mode) { + aggreFunc = g_aggreFuncDemo; + n = aggr_func ? (sizeof(g_aggreFuncDemo) / sizeof(g_aggreFuncDemo[0])) + : 2; + } else { + aggreFunc = g_aggreFunc; + n = aggr_func ? (sizeof(g_aggreFunc) / sizeof(g_aggreFunc[0])) : 2; + } + + if (!aggr_func) { + printf( + "\nThe first field is either Binary or Bool. Aggregation functions " + "are not supported.\n"); + } + printf("%" PRId64 " records:\n", totalData); + fprintf( + fp, + "| QFunctions | QRecords | QSpeed(R/s) | QLatency(ms) |\n"); + + for (int j = 0; j < n; j++) { + double totalT = 0; + uint64_t count = 0; + for (int64_t i = 0; i < ntables; i++) { + sprintf(command, "SELECT %s FROM %s%" PRId64 " WHERE ts>= %" PRIu64, + aggreFunc[j], tb_prefix, i, startTime); + + double t = (double)taosGetTimestampUs(); + debugPrint("%s() LN%d, sql command: %s\n", __func__, __LINE__, + command); + TAOS_RES *pSql = taos_query(taos, command); + int32_t code = taos_errno(pSql); + + if (code != 0) { + errorPrint("Failed to query:%s\n", taos_errstr(pSql)); + taos_free_result(pSql); + taos_close(taos); + fclose(fp); + free(command); + return NULL; + } + + while (taos_fetch_row(pSql) != NULL) { + count++; + } + + t = taosGetTimestampUs() - t; + totalT += t; + + taos_free_result(pSql); + } + + fprintf(fp, "|%10s | %" PRId64 " | %12.2f | %10.2f |\n", + aggreFunc[j][0] == '*' ? " * " : aggreFunc[j], totalData, + (double)(ntables * insertRows) / totalT, totalT / 1000000); + printf("select %10s took %.6f second(s)\n", aggreFunc[j], + totalT / 1000000); + } + fprintf(fp, "\n"); + fclose(fp); + free(command); + return NULL; +} + +void queryAggrFunc() { + // query data + + pthread_t read_id; + threadInfo *pThreadInfo = calloc(1, sizeof(threadInfo)); + if (pThreadInfo == NULL) { + errorPrint("%s", "failde to allocate memory\n"); + return; + } + + pThreadInfo->start_time = DEFAULT_START_TIME; // 2017-07-14 10:40:00.000 + pThreadInfo->start_table_from = 0; + + if (g_args.use_metric) { + pThreadInfo->ntables = g_Dbs.db[0].superTbls[0].childTblCount; + pThreadInfo->end_table_to = g_Dbs.db[0].superTbls[0].childTblCount - 1; + pThreadInfo->stbInfo = &g_Dbs.db[0].superTbls[0]; + tstrncpy(pThreadInfo->tb_prefix, + g_Dbs.db[0].superTbls[0].childTblPrefix, TBNAME_PREFIX_LEN); + } else { + pThreadInfo->ntables = g_args.ntables; + pThreadInfo->end_table_to = g_args.ntables - 1; + tstrncpy(pThreadInfo->tb_prefix, g_args.tb_prefix, TSDB_TABLE_NAME_LEN); + } + + pThreadInfo->taos = taos_connect(g_Dbs.host, g_Dbs.user, g_Dbs.password, + g_Dbs.db[0].dbName, g_Dbs.port); + if (pThreadInfo->taos == NULL) { + free(pThreadInfo); + errorPrint("Failed to connect to TDengine, reason:%s\n", + taos_errstr(NULL)); + exit(EXIT_FAILURE); + } + + tstrncpy(pThreadInfo->filePath, g_Dbs.resultFile, MAX_FILE_NAME_LEN); + + if (!g_Dbs.use_metric) { + pthread_create(&read_id, NULL, queryNtableAggrFunc, pThreadInfo); + } else { + pthread_create(&read_id, NULL, queryStableAggrFunc, pThreadInfo); + } + pthread_join(read_id, NULL); + taos_close(pThreadInfo->taos); + free(pThreadInfo); +} + +void testCmdLine() { + if (strlen(configDir)) { + wordexp_t full_path; + if (wordexp(configDir, &full_path, 0) != 0) { + errorPrint("Invalid path %s\n", configDir); + return; + } + taos_options(TSDB_OPTION_CONFIGDIR, full_path.we_wordv[0]); + wordfree(&full_path); + } + + g_args.test_mode = INSERT_TEST; + insertTestProcess(); + + if (g_Dbs.aggr_func) { + queryAggrFunc(); + } +} \ No newline at end of file diff --git a/src/kit/taosdemo/src/demoData.c b/src/kit/taosdemo/src/demoData.c new file mode 100644 index 0000000000000000000000000000000000000000..39d7954a2488621cf3fdee859777484a1f38601b --- /dev/null +++ b/src/kit/taosdemo/src/demoData.c @@ -0,0 +1,2510 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#include "demoData.h" +#include "demo.h" + +char * g_sampleDataBuf = NULL; +char * g_sampleBindBatchArray = NULL; +int32_t * g_randint = NULL; +uint32_t *g_randuint = NULL; +int64_t * g_randbigint = NULL; +uint64_t *g_randubigint = NULL; +float * g_randfloat = NULL; +double * g_randdouble = NULL; +char * g_randbool_buff = NULL; +char * g_randint_buff = NULL; +char * g_randuint_buff = NULL; +char * g_rand_voltage_buff = NULL; +char * g_randbigint_buff = NULL; +char * g_randubigint_buff = NULL; +char * g_randsmallint_buff = NULL; +char * g_randusmallint_buff = NULL; +char * g_randtinyint_buff = NULL; +char * g_randutinyint_buff = NULL; +char * g_randfloat_buff = NULL; +char * g_rand_current_buff = NULL; +char * g_rand_phase_buff = NULL; +char * g_randdouble_buff = NULL; + +const char charset[] = + "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"; + +char *rand_bool_str() { + static int cursor; + cursor++; + if (cursor > (g_args.prepared_rand - 1)) cursor = 0; + return g_randbool_buff + ((cursor % g_args.prepared_rand) * BOOL_BUFF_LEN); +} + +int32_t rand_bool() { + static int cursor; + cursor++; + if (cursor > (g_args.prepared_rand - 1)) cursor = 0; + return g_randint[cursor % g_args.prepared_rand] % TSDB_DATA_BOOL_NULL; +} + +char *rand_tinyint_str() { + static int cursor; + cursor++; + if (cursor > (g_args.prepared_rand - 1)) cursor = 0; + return g_randtinyint_buff + + ((cursor % g_args.prepared_rand) * TINYINT_BUFF_LEN); +} + +int32_t rand_tinyint() { + static int cursor; + cursor++; + if (cursor > (g_args.prepared_rand - 1)) cursor = 0; + return g_randint[cursor % g_args.prepared_rand] % TSDB_DATA_TINYINT_NULL; +} + +char *rand_utinyint_str() { + static int cursor; + cursor++; + if (cursor > (g_args.prepared_rand - 1)) cursor = 0; + return g_randutinyint_buff + + ((cursor % g_args.prepared_rand) * TINYINT_BUFF_LEN); +} + +int32_t rand_utinyint() { + static int cursor; + cursor++; + if (cursor > (g_args.prepared_rand - 1)) cursor = 0; + return g_randuint[cursor % g_args.prepared_rand] % TSDB_DATA_UTINYINT_NULL; +} + +char *rand_smallint_str() { + static int cursor; + cursor++; + if (cursor > (g_args.prepared_rand - 1)) cursor = 0; + return g_randsmallint_buff + + ((cursor % g_args.prepared_rand) * SMALLINT_BUFF_LEN); +} + +int32_t rand_smallint() { + static int cursor; + cursor++; + if (cursor > (g_args.prepared_rand - 1)) cursor = 0; + return g_randint[cursor % g_args.prepared_rand] % TSDB_DATA_SMALLINT_NULL; +} + +char *rand_usmallint_str() { + static int cursor; + cursor++; + if (cursor > (g_args.prepared_rand - 1)) cursor = 0; + return g_randusmallint_buff + + ((cursor % g_args.prepared_rand) * SMALLINT_BUFF_LEN); +} + +int32_t rand_usmallint() { + static int cursor; + cursor++; + if (cursor > (g_args.prepared_rand - 1)) cursor = 0; + return g_randuint[cursor % g_args.prepared_rand] % TSDB_DATA_USMALLINT_NULL; +} + +char *rand_int_str() { + static int cursor; + cursor++; + if (cursor > (g_args.prepared_rand - 1)) cursor = 0; + return g_randint_buff + ((cursor % g_args.prepared_rand) * INT_BUFF_LEN); +} + +int32_t rand_int() { + static int cursor; + cursor++; + if (cursor > (g_args.prepared_rand - 1)) cursor = 0; + return g_randint[cursor % g_args.prepared_rand]; +} + +char *rand_uint_str() { + static int cursor; + cursor++; + if (cursor > (g_args.prepared_rand - 1)) cursor = 0; + return g_randuint_buff + ((cursor % g_args.prepared_rand) * INT_BUFF_LEN); +} + +int32_t rand_uint() { + static int cursor; + cursor++; + if (cursor > (g_args.prepared_rand - 1)) cursor = 0; + return g_randuint[cursor % g_args.prepared_rand]; +} + +char *rand_bigint_str() { + static int cursor; + cursor++; + if (cursor > (g_args.prepared_rand - 1)) cursor = 0; + return g_randbigint_buff + + ((cursor % g_args.prepared_rand) * BIGINT_BUFF_LEN); +} + +int64_t rand_bigint() { + static int cursor; + cursor++; + if (cursor > (g_args.prepared_rand - 1)) cursor = 0; + return g_randbigint[cursor % g_args.prepared_rand]; +} + +char *rand_ubigint_str() { + static int cursor; + cursor++; + if (cursor > (g_args.prepared_rand - 1)) cursor = 0; + return g_randubigint_buff + + ((cursor % g_args.prepared_rand) * BIGINT_BUFF_LEN); +} + +int64_t rand_ubigint() { + static int cursor; + cursor++; + if (cursor > (g_args.prepared_rand - 1)) cursor = 0; + return g_randubigint[cursor % g_args.prepared_rand]; +} + +char *rand_float_str() { + static int cursor; + cursor++; + if (cursor > (g_args.prepared_rand - 1)) cursor = 0; + return g_randfloat_buff + + ((cursor % g_args.prepared_rand) * FLOAT_BUFF_LEN); +} + +float rand_float() { + static int cursor; + cursor++; + if (cursor > (g_args.prepared_rand - 1)) cursor = 0; + return g_randfloat[cursor % g_args.prepared_rand]; +} + +char *demo_current_float_str() { + static int cursor; + cursor++; + if (cursor > (g_args.prepared_rand - 1)) cursor = 0; + return g_rand_current_buff + + ((cursor % g_args.prepared_rand) * FLOAT_BUFF_LEN); +} + +float UNUSED_FUNC demo_current_float() { + static int cursor; + cursor++; + if (cursor > (g_args.prepared_rand - 1)) cursor = 0; + return (float)(9.8 + + 0.04 * (g_randint[cursor % g_args.prepared_rand] % 10) + + g_randfloat[cursor % g_args.prepared_rand] / 1000000000); +} + +char *demo_voltage_int_str() { + static int cursor; + cursor++; + if (cursor > (g_args.prepared_rand - 1)) cursor = 0; + return g_rand_voltage_buff + + ((cursor % g_args.prepared_rand) * INT_BUFF_LEN); +} + +int32_t UNUSED_FUNC demo_voltage_int() { + static int cursor; + cursor++; + if (cursor > (g_args.prepared_rand - 1)) cursor = 0; + return 215 + g_randint[cursor % g_args.prepared_rand] % 10; +} + +char *demo_phase_float_str() { + static int cursor; + cursor++; + if (cursor > (g_args.prepared_rand - 1)) cursor = 0; + return g_rand_phase_buff + + ((cursor % g_args.prepared_rand) * FLOAT_BUFF_LEN); +} + +float UNUSED_FUNC demo_phase_float() { + static int cursor; + cursor++; + if (cursor > (g_args.prepared_rand - 1)) cursor = 0; + return (float)((115 + g_randint[cursor % g_args.prepared_rand] % 10 + + g_randfloat[cursor % g_args.prepared_rand] / 1000000000) / + 360); +} + +void rand_string(char *str, int size) { + str[0] = 0; + if (size > 0) { + //--size; + int n; + for (n = 0; n < size; n++) { + int key = abs(taosRandom()) % (int)(sizeof(charset) - 1); + str[n] = charset[key]; + } + str[n] = 0; + } +} + +char *rand_double_str() { + static int cursor; + cursor++; + if (cursor > (g_args.prepared_rand - 1)) cursor = 0; + return g_randdouble_buff + (cursor * DOUBLE_BUFF_LEN); +} + +double rand_double() { + static int cursor; + cursor++; + cursor = cursor % g_args.prepared_rand; + return g_randdouble[cursor]; +} + +int init_rand_data() { + int32_t code = -1; + g_randint_buff = calloc(1, INT_BUFF_LEN * g_args.prepared_rand); + if (NULL == g_randint_buff) { + errorPrint("%s", "failed to allocate memory\n"); + goto end_init_rand_data; + } + g_rand_voltage_buff = calloc(1, INT_BUFF_LEN * g_args.prepared_rand); + if (NULL == g_randint_buff) { + errorPrint("%s", "failed to allocate memory\n"); + goto end_init_rand_data; + } + g_randbigint_buff = calloc(1, BIGINT_BUFF_LEN * g_args.prepared_rand); + if (NULL == g_randbigint_buff) { + errorPrint("%s", "failed to allocate memory\n"); + goto end_init_rand_data; + } + g_randsmallint_buff = calloc(1, SMALLINT_BUFF_LEN * g_args.prepared_rand); + if (NULL == g_randsmallint_buff) { + errorPrint("%s", "failed to allocate memory\n"); + goto end_init_rand_data; + } + g_randtinyint_buff = calloc(1, TINYINT_BUFF_LEN * g_args.prepared_rand); + if (NULL == g_randtinyint_buff) { + errorPrint("%s", "failed to allocate memory\n"); + goto end_init_rand_data; + } + g_randbool_buff = calloc(1, BOOL_BUFF_LEN * g_args.prepared_rand); + if (NULL == g_randbool_buff) { + errorPrint("%s", "failed to allocate memory\n"); + goto end_init_rand_data; + } + g_randfloat_buff = calloc(1, FLOAT_BUFF_LEN * g_args.prepared_rand); + if (NULL == g_randfloat_buff) { + errorPrint("%s", "failed to allocate memory\n"); + goto end_init_rand_data; + } + g_rand_current_buff = calloc(1, FLOAT_BUFF_LEN * g_args.prepared_rand); + if (NULL == g_rand_current_buff) { + errorPrint("%s", "failed to allocate memory\n"); + goto end_init_rand_data; + } + g_rand_phase_buff = calloc(1, FLOAT_BUFF_LEN * g_args.prepared_rand); + if (NULL == g_rand_phase_buff) { + errorPrint("%s", "failed to allocate memory\n"); + goto end_init_rand_data; + } + g_randdouble_buff = calloc(1, DOUBLE_BUFF_LEN * g_args.prepared_rand); + if (NULL == g_randdouble_buff) { + errorPrint("%s", "failed to allocate memory\n"); + goto end_init_rand_data; + } + g_randuint_buff = calloc(1, INT_BUFF_LEN * g_args.prepared_rand); + if (NULL == g_randuint_buff) { + errorPrint("%s", "failed to allocate memory\n"); + goto end_init_rand_data; + } + g_randutinyint_buff = calloc(1, TINYINT_BUFF_LEN * g_args.prepared_rand); + if (NULL == g_randutinyint_buff) { + errorPrint("%s", "failed to allocate memory\n"); + goto end_init_rand_data; + } + g_randusmallint_buff = calloc(1, SMALLINT_BUFF_LEN * g_args.prepared_rand); + if (NULL == g_randusmallint_buff) { + errorPrint("%s", "failed to allocate memory\n"); + goto end_init_rand_data; + } + g_randubigint_buff = calloc(1, BIGINT_BUFF_LEN * g_args.prepared_rand); + if (NULL == g_randubigint_buff) { + errorPrint("%s", "failed to allocate memory\n"); + goto end_init_rand_data; + } + g_randint = calloc(1, sizeof(int32_t) * g_args.prepared_rand); + if (NULL == g_randint) { + errorPrint("%s", "failed to allocate memory\n"); + goto end_init_rand_data; + } + g_randuint = calloc(1, sizeof(uint32_t) * g_args.prepared_rand); + if (NULL == g_randuint) { + errorPrint("%s", "failed to allocate memory\n"); + goto end_init_rand_data; + } + g_randbigint = calloc(1, sizeof(int64_t) * g_args.prepared_rand); + if (NULL == g_randbigint) { + errorPrint("%s", "failed to allocate memory\n"); + goto end_init_rand_data; + } + g_randubigint = calloc(1, sizeof(uint64_t) * g_args.prepared_rand); + if (NULL == g_randubigint) { + errorPrint("%s", "failed to allocate memory\n"); + goto end_init_rand_data; + } + g_randfloat = calloc(1, sizeof(float) * g_args.prepared_rand); + if (NULL == g_randfloat) { + errorPrint("%s", "failed to allocate memory\n"); + goto end_init_rand_data; + } + g_randdouble = calloc(1, sizeof(double) * g_args.prepared_rand); + if (NULL == g_randdouble) { + errorPrint("%s", "failed to allocate memory\n"); + goto end_init_rand_data; + } + + for (int i = 0; i < g_args.prepared_rand; i++) { + g_randint[i] = (int)(taosRandom() % RAND_MAX - (RAND_MAX >> 1)); + g_randuint[i] = (int)(taosRandom()); + sprintf(g_randint_buff + i * INT_BUFF_LEN, "%d", g_randint[i]); + sprintf(g_rand_voltage_buff + i * INT_BUFF_LEN, "%d", + 215 + g_randint[i] % 10); + + sprintf(g_randbool_buff + i * BOOL_BUFF_LEN, "%s", + ((g_randint[i] % 2) & 1) ? "true" : "false"); + sprintf(g_randsmallint_buff + i * SMALLINT_BUFF_LEN, "%d", + g_randint[i] % 32768); + sprintf(g_randtinyint_buff + i * TINYINT_BUFF_LEN, "%d", + g_randint[i] % 128); + sprintf(g_randuint_buff + i * INT_BUFF_LEN, "%d", g_randuint[i]); + sprintf(g_randusmallint_buff + i * SMALLINT_BUFF_LEN, "%d", + g_randuint[i] % 65535); + sprintf(g_randutinyint_buff + i * TINYINT_BUFF_LEN, "%d", + g_randuint[i] % 255); + + g_randbigint[i] = (int64_t)(taosRandom() % RAND_MAX - (RAND_MAX >> 1)); + g_randubigint[i] = (uint64_t)(taosRandom()); + sprintf(g_randbigint_buff + i * BIGINT_BUFF_LEN, "%" PRId64 "", + g_randbigint[i]); + sprintf(g_randubigint_buff + i * BIGINT_BUFF_LEN, "%" PRId64 "", + g_randubigint[i]); + + g_randfloat[i] = + (float)(taosRandom() / 1000.0) * (taosRandom() % 2 > 0.5 ? 1 : -1); + sprintf(g_randfloat_buff + i * FLOAT_BUFF_LEN, "%f", g_randfloat[i]); + sprintf(g_rand_current_buff + i * FLOAT_BUFF_LEN, "%f", + (float)(9.8 + 0.04 * (g_randint[i] % 10) + + g_randfloat[i] / 1000000000)); + sprintf( + g_rand_phase_buff + i * FLOAT_BUFF_LEN, "%f", + (float)((115 + g_randint[i] % 10 + g_randfloat[i] / 1000000000) / + 360)); + + g_randdouble[i] = (double)(taosRandom() / 1000000.0) * + (taosRandom() % 2 > 0.5 ? 1 : -1); + sprintf(g_randdouble_buff + i * DOUBLE_BUFF_LEN, "%f", g_randdouble[i]); + } + code = 0; +end_init_rand_data: + return code; +} + +static void generateBinaryNCharTagValues(int64_t tableSeq, uint32_t len, + char *buf) { + if (tableSeq % 2) { + tstrncpy(buf, "beijing", len); + } else { + tstrncpy(buf, "shanghai", len); + } + // rand_string(buf, stbInfo->tags[i].dataLen); +} + +int generateTagValuesForStb(SSuperTable *stbInfo, int64_t tableSeq, + char *tagsValBuf) { + int dataLen = 0; + dataLen += snprintf(tagsValBuf + dataLen, TSDB_MAX_SQL_LEN - dataLen, "("); + for (int i = 0; i < stbInfo->tagCount; i++) { + if ((0 == strncasecmp(stbInfo->tags[i].dataType, "binary", + strlen("binary"))) || + (0 == strncasecmp(stbInfo->tags[i].dataType, "nchar", + strlen("nchar")))) { + if (stbInfo->tags[i].dataLen > TSDB_MAX_BINARY_LEN) { + errorPrint("binary or nchar length overflow, max size:%u\n", + (uint32_t)TSDB_MAX_BINARY_LEN); + return -1; + } + + int32_t tagBufLen = stbInfo->tags[i].dataLen + 1; + char * buf = (char *)calloc(1, tagBufLen); + if (NULL == buf) { + errorPrint("%s", "failed to allocate memory\n"); + return -1; + } + generateBinaryNCharTagValues(tableSeq, tagBufLen, buf); + dataLen += snprintf(tagsValBuf + dataLen, + TSDB_MAX_SQL_LEN - dataLen, "\'%s\',", buf); + tmfree(buf); + } else if (0 == strncasecmp(stbInfo->tags[i].dataType, "int", + strlen("int"))) { + if ((g_args.demo_mode) && (i == 0)) { + dataLen += + snprintf(tagsValBuf + dataLen, TSDB_MAX_SQL_LEN - dataLen, + "%" PRId64 ",", (tableSeq % 10) + 1); + } else { + dataLen += + snprintf(tagsValBuf + dataLen, TSDB_MAX_SQL_LEN - dataLen, + "%" PRId64 ",", tableSeq); + } + } else if (0 == strncasecmp(stbInfo->tags[i].dataType, "bigint", + strlen("bigint"))) { + dataLen += + snprintf(tagsValBuf + dataLen, TSDB_MAX_SQL_LEN - dataLen, + "%" PRId64 ",", rand_bigint()); + } else if (0 == strncasecmp(stbInfo->tags[i].dataType, "float", + strlen("float"))) { + dataLen += + snprintf(tagsValBuf + dataLen, TSDB_MAX_SQL_LEN - dataLen, + "%f,", rand_float()); + } else if (0 == strncasecmp(stbInfo->tags[i].dataType, "double", + strlen("double"))) { + dataLen += + snprintf(tagsValBuf + dataLen, TSDB_MAX_SQL_LEN - dataLen, + "%f,", rand_double()); + } else if (0 == strncasecmp(stbInfo->tags[i].dataType, "smallint", + strlen("smallint"))) { + dataLen += + snprintf(tagsValBuf + dataLen, TSDB_MAX_SQL_LEN - dataLen, + "%d,", rand_smallint()); + } else if (0 == strncasecmp(stbInfo->tags[i].dataType, "tinyint", + strlen("tinyint"))) { + dataLen += + snprintf(tagsValBuf + dataLen, TSDB_MAX_SQL_LEN - dataLen, + "%d,", rand_tinyint()); + } else if (0 == strncasecmp(stbInfo->tags[i].dataType, "bool", + strlen("bool"))) { + dataLen += snprintf(tagsValBuf + dataLen, + TSDB_MAX_SQL_LEN - dataLen, "%d,", rand_bool()); + } else if (0 == strncasecmp(stbInfo->tags[i].dataType, "timestamp", + strlen("timestamp"))) { + dataLen += + snprintf(tagsValBuf + dataLen, TSDB_MAX_SQL_LEN - dataLen, + "%" PRId64 ",", rand_ubigint()); + } else if (0 == strncasecmp(stbInfo->tags[i].dataType, "utinyint", + strlen("utinyint"))) { + dataLen += + snprintf(tagsValBuf + dataLen, TSDB_MAX_SQL_LEN - dataLen, + "%d,", rand_utinyint()); + } else if (0 == strncasecmp(stbInfo->tags[i].dataType, "usmallint", + strlen("usmallint"))) { + dataLen += + snprintf(tagsValBuf + dataLen, TSDB_MAX_SQL_LEN - dataLen, + "%d,", rand_usmallint()); + } else if (0 == strncasecmp(stbInfo->tags[i].dataType, "uint", + strlen("uint"))) { + dataLen += snprintf(tagsValBuf + dataLen, + TSDB_MAX_SQL_LEN - dataLen, "%d,", rand_uint()); + } else if (0 == strncasecmp(stbInfo->tags[i].dataType, "ubigint", + strlen("ubigint"))) { + dataLen += + snprintf(tagsValBuf + dataLen, TSDB_MAX_SQL_LEN - dataLen, + "%" PRId64 ",", rand_ubigint()); + } else { + errorPrint("unsupport data type: %s\n", stbInfo->tags[i].dataType); + return -1; + } + } + + dataLen -= 1; + dataLen += snprintf(tagsValBuf + dataLen, TSDB_MAX_SQL_LEN - dataLen, ")"); + return 0; +} + +static int readTagFromCsvFileToMem(SSuperTable *stbInfo) { + size_t n = 0; + ssize_t readLen = 0; + char * line = NULL; + + FILE *fp = fopen(stbInfo->tagsFile, "r"); + if (fp == NULL) { + printf("Failed to open tags file: %s, reason:%s\n", stbInfo->tagsFile, + strerror(errno)); + return -1; + } + + if (stbInfo->tagDataBuf) { + free(stbInfo->tagDataBuf); + stbInfo->tagDataBuf = NULL; + } + + int tagCount = MAX_SAMPLES; + int count = 0; + char *tagDataBuf = calloc(1, stbInfo->lenOfTagOfOneRow * tagCount); + if (tagDataBuf == NULL) { + printf("Failed to calloc, reason:%s\n", strerror(errno)); + fclose(fp); + return -1; + } + + while ((readLen = tgetline(&line, &n, fp)) != -1) { + if (('\r' == line[readLen - 1]) || ('\n' == line[readLen - 1])) { + line[--readLen] = 0; + } + + if (readLen == 0) { + continue; + } + + memcpy(tagDataBuf + count * stbInfo->lenOfTagOfOneRow, line, readLen); + count++; + + if (count >= tagCount - 1) { + char *tmp = + realloc(tagDataBuf, + (size_t)(tagCount * 1.5 * stbInfo->lenOfTagOfOneRow)); + if (tmp != NULL) { + tagDataBuf = tmp; + tagCount = (int)(tagCount * 1.5); + memset( + tagDataBuf + count * stbInfo->lenOfTagOfOneRow, 0, + (size_t)((tagCount - count) * stbInfo->lenOfTagOfOneRow)); + } else { + // exit, if allocate more memory failed + printf("realloc fail for save tag val from %s\n", + stbInfo->tagsFile); + tmfree(tagDataBuf); + free(line); + fclose(fp); + return -1; + } + } + } + + stbInfo->tagDataBuf = tagDataBuf; + stbInfo->tagSampleCount = count; + + free(line); + fclose(fp); + return 0; +} + +static void getAndSetRowsFromCsvFile(SSuperTable *stbInfo) { + FILE *fp = fopen(stbInfo->sampleFile, "r"); + int line_count = 0; + if (fp == NULL) { + errorPrint("Failed to open sample file: %s, reason:%s\n", + stbInfo->sampleFile, strerror(errno)); + return; + } + char *buf = calloc(1, stbInfo->maxSqlLen); + if (buf == NULL) { + errorPrint("%s", "failed to allocate memory\n"); + return; + } + + while (fgets(buf, (int)stbInfo->maxSqlLen, fp)) { + line_count++; + } + fclose(fp); + tmfree(buf); + stbInfo->insertRows = line_count; +} + +static int generateSampleFromCsvForStb(SSuperTable *stbInfo) { + size_t n = 0; + ssize_t readLen = 0; + char * line = NULL; + int getRows = 0; + + FILE *fp = fopen(stbInfo->sampleFile, "r"); + if (fp == NULL) { + errorPrint("Failed to open sample file: %s, reason:%s\n", + stbInfo->sampleFile, strerror(errno)); + return -1; + } + while (1) { + readLen = tgetline(&line, &n, fp); + if (-1 == readLen) { + if (0 != fseek(fp, 0, SEEK_SET)) { + errorPrint("Failed to fseek file: %s, reason:%s\n", + stbInfo->sampleFile, strerror(errno)); + fclose(fp); + return -1; + } + continue; + } + + if (('\r' == line[readLen - 1]) || ('\n' == line[readLen - 1])) { + line[--readLen] = 0; + } + + if (readLen == 0) { + continue; + } + + if (readLen > stbInfo->lenOfOneRow) { + printf("sample row len[%d] overflow define schema len[%" PRIu64 + "], so discard this row\n", + (int32_t)readLen, stbInfo->lenOfOneRow); + continue; + } + + memcpy(stbInfo->sampleDataBuf + getRows * stbInfo->lenOfOneRow, line, + readLen); + getRows++; + + if (getRows == MAX_SAMPLES) { + break; + } + } + + fclose(fp); + tmfree(line); + return 0; +} + +int prepareSampleData() { + for (int i = 0; i < g_Dbs.dbCount; i++) { + for (int j = 0; j < g_Dbs.db[i].superTblCount; j++) { + if (g_Dbs.db[i].superTbls[j].tagsFile[0] != 0) { + if (readTagFromCsvFileToMem(&g_Dbs.db[i].superTbls[j]) != 0) { + return -1; + } + } + } + } + + return 0; +} + +static int getRowDataFromSample(char *dataBuf, int64_t maxLen, + int64_t timestamp, SSuperTable *stbInfo, + int64_t *sampleUsePos) { + if ((*sampleUsePos) == MAX_SAMPLES) { + *sampleUsePos = 0; + } + + int dataLen = 0; + if (stbInfo->useSampleTs) { + dataLen += snprintf( + dataBuf + dataLen, maxLen - dataLen, "(%s", + stbInfo->sampleDataBuf + stbInfo->lenOfOneRow * (*sampleUsePos)); + } else { + dataLen += snprintf(dataBuf + dataLen, maxLen - dataLen, + "(%" PRId64 ", ", timestamp); + dataLen += snprintf( + dataBuf + dataLen, maxLen - dataLen, "%s", + stbInfo->sampleDataBuf + stbInfo->lenOfOneRow * (*sampleUsePos)); + } + dataLen += snprintf(dataBuf + dataLen, maxLen - dataLen, ")"); + + (*sampleUsePos)++; + + return dataLen; +} + +int64_t generateStbRowData(SSuperTable *stbInfo, char *recBuf, + int64_t remainderBufLen, int64_t timestamp) { + int64_t dataLen = 0; + char * pstr = recBuf; + int64_t maxLen = MAX_DATA_SIZE; + int tmpLen; + + dataLen += + snprintf(pstr + dataLen, maxLen - dataLen, "(%" PRId64 "", timestamp); + + for (int i = 0; i < stbInfo->columnCount; i++) { + tstrncpy(pstr + dataLen, ",", 2); + dataLen += 1; + + if ((stbInfo->columns[i].data_type == TSDB_DATA_TYPE_BINARY) || + (stbInfo->columns[i].data_type == TSDB_DATA_TYPE_NCHAR)) { + if (stbInfo->columns[i].dataLen > TSDB_MAX_BINARY_LEN) { + errorPrint("binary or nchar length overflow, max size:%u\n", + (uint32_t)TSDB_MAX_BINARY_LEN); + return -1; + } + + if ((stbInfo->columns[i].dataLen + 1) > + /* need count 3 extra chars \', \', and , */ + (remainderBufLen - dataLen - 3)) { + return 0; + } + char *buf = (char *)calloc(stbInfo->columns[i].dataLen + 1, 1); + if (NULL == buf) { + errorPrint("%s", "failed to allocate memory\n"); + return -1; + } + rand_string(buf, stbInfo->columns[i].dataLen); + dataLen += + snprintf(pstr + dataLen, maxLen - dataLen, "\'%s\'", buf); + tmfree(buf); + + } else { + char *tmp = NULL; + switch (stbInfo->columns[i].data_type) { + case TSDB_DATA_TYPE_INT: + if ((g_args.demo_mode) && (i == 1)) { + tmp = demo_voltage_int_str(); + } else { + tmp = rand_int_str(); + } + tmpLen = (int)strlen(tmp); + tstrncpy(pstr + dataLen, tmp, + min(tmpLen + 1, INT_BUFF_LEN)); + break; + + case TSDB_DATA_TYPE_UINT: + tmp = rand_uint_str(); + tmpLen = (int)strlen(tmp); + tstrncpy(pstr + dataLen, tmp, + min(tmpLen + 1, INT_BUFF_LEN)); + break; + + case TSDB_DATA_TYPE_BIGINT: + tmp = rand_bigint_str(); + tmpLen = (int)strlen(tmp); + tstrncpy(pstr + dataLen, tmp, + min(tmpLen + 1, BIGINT_BUFF_LEN)); + break; + + case TSDB_DATA_TYPE_UBIGINT: + tmp = rand_ubigint_str(); + tmpLen = (int)strlen(tmp); + tstrncpy(pstr + dataLen, tmp, + min(tmpLen + 1, BIGINT_BUFF_LEN)); + break; + + case TSDB_DATA_TYPE_FLOAT: + if (g_args.demo_mode) { + if (i == 0) { + tmp = demo_current_float_str(); + } else { + tmp = demo_phase_float_str(); + } + } else { + tmp = rand_float_str(); + } + tmpLen = (int)strlen(tmp); + tstrncpy(pstr + dataLen, tmp, + min(tmpLen + 1, FLOAT_BUFF_LEN)); + break; + + case TSDB_DATA_TYPE_DOUBLE: + tmp = rand_double_str(); + tmpLen = (int)strlen(tmp); + tstrncpy(pstr + dataLen, tmp, + min(tmpLen + 1, DOUBLE_BUFF_LEN)); + break; + + case TSDB_DATA_TYPE_SMALLINT: + tmp = rand_smallint_str(); + tmpLen = (int)strlen(tmp); + tstrncpy(pstr + dataLen, tmp, + min(tmpLen + 1, SMALLINT_BUFF_LEN)); + break; + + case TSDB_DATA_TYPE_USMALLINT: + tmp = rand_usmallint_str(); + tmpLen = (int)strlen(tmp); + tstrncpy(pstr + dataLen, tmp, + min(tmpLen + 1, SMALLINT_BUFF_LEN)); + break; + + case TSDB_DATA_TYPE_TINYINT: + tmp = rand_tinyint_str(); + tmpLen = (int)strlen(tmp); + tstrncpy(pstr + dataLen, tmp, + min(tmpLen + 1, TINYINT_BUFF_LEN)); + break; + + case TSDB_DATA_TYPE_UTINYINT: + tmp = rand_utinyint_str(); + tmpLen = (int)strlen(tmp); + tstrncpy(pstr + dataLen, tmp, + min(tmpLen + 1, TINYINT_BUFF_LEN)); + break; + + case TSDB_DATA_TYPE_BOOL: + tmp = rand_bool_str(); + tmpLen = (int)strlen(tmp); + tstrncpy(pstr + dataLen, tmp, + min(tmpLen + 1, BOOL_BUFF_LEN)); + break; + + case TSDB_DATA_TYPE_TIMESTAMP: + tmp = rand_bigint_str(); + tmpLen = (int)strlen(tmp); + tstrncpy(pstr + dataLen, tmp, + min(tmpLen + 1, BIGINT_BUFF_LEN)); + break; + + case TSDB_DATA_TYPE_NULL: + break; + + default: + errorPrint("Not support data type: %s\n", + stbInfo->columns[i].dataType); + exit(EXIT_FAILURE); + } + if (tmp) { + dataLen += tmpLen; + } + } + + if (dataLen > (remainderBufLen - (128))) return 0; + } + + dataLen += snprintf(pstr + dataLen, 2, ")"); + + verbosePrint("%s() LN%d, dataLen:%" PRId64 "\n", __func__, __LINE__, + dataLen); + verbosePrint("%s() LN%d, recBuf:\n\t%s\n", __func__, __LINE__, recBuf); + + return strlen(recBuf); +} + +static int64_t generateData(char *recBuf, char *data_type, int64_t timestamp, + int lenOfBinary) { + memset(recBuf, 0, MAX_DATA_SIZE); + char *pstr = recBuf; + pstr += sprintf(pstr, "(%" PRId64 "", timestamp); + + int columnCount = g_args.columnCount; + + bool b; + char *s; + for (int i = 0; i < columnCount; i++) { + switch (data_type[i]) { + case TSDB_DATA_TYPE_TINYINT: + pstr += sprintf(pstr, ",%d", rand_tinyint()); + break; + + case TSDB_DATA_TYPE_SMALLINT: + pstr += sprintf(pstr, ",%d", rand_smallint()); + break; + + case TSDB_DATA_TYPE_INT: + pstr += sprintf(pstr, ",%d", rand_int()); + break; + + case TSDB_DATA_TYPE_BIGINT: + pstr += sprintf(pstr, ",%" PRId64 "", rand_bigint()); + break; + + case TSDB_DATA_TYPE_TIMESTAMP: + pstr += sprintf(pstr, ",%" PRId64 "", rand_bigint()); + break; + + case TSDB_DATA_TYPE_FLOAT: + pstr += sprintf(pstr, ",%10.4f", rand_float()); + break; + + case TSDB_DATA_TYPE_DOUBLE: + pstr += sprintf(pstr, ",%20.8f", rand_double()); + break; + + case TSDB_DATA_TYPE_BOOL: + b = rand_bool() & 1; + pstr += sprintf(pstr, ",%s", b ? "true" : "false"); + break; + + case TSDB_DATA_TYPE_BINARY: + case TSDB_DATA_TYPE_NCHAR: + s = calloc(1, lenOfBinary + 1); + if (NULL == s) { + errorPrint("%s", "failed to allocate memory\n"); + return -1; + } + + rand_string(s, lenOfBinary); + pstr += sprintf(pstr, ",\"%s\"", s); + free(s); + break; + + case TSDB_DATA_TYPE_UTINYINT: + pstr += sprintf(pstr, ",%d", rand_utinyint()); + break; + + case TSDB_DATA_TYPE_USMALLINT: + pstr += sprintf(pstr, ",%d", rand_usmallint()); + break; + + case TSDB_DATA_TYPE_UINT: + pstr += sprintf(pstr, ",%d", rand_uint()); + break; + + case TSDB_DATA_TYPE_UBIGINT: + pstr += sprintf(pstr, ",%" PRId64 "", rand_ubigint()); + break; + + case TSDB_DATA_TYPE_NULL: + break; + + default: + errorPrint("Unknown data type %d\n", data_type[i]); + return -1; + } + + if (strlen(recBuf) > MAX_DATA_SIZE) { + errorPrint("%s", "column length too long, abort\n"); + return -1; + } + } + + pstr += sprintf(pstr, ")"); + + verbosePrint("%s() LN%d, recBuf:\n\t%s\n", __func__, __LINE__, recBuf); + + return (int32_t)strlen(recBuf); +} + +static int generateSampleFromRand(char *sampleDataBuf, uint64_t lenOfOneRow, + int columnCount, StrColumn *columns) { + char data[MAX_DATA_SIZE]; + memset(data, 0, MAX_DATA_SIZE); + + char *buff = calloc(lenOfOneRow, 1); + if (NULL == buff) { + errorPrint("%s", "failed to allocate memory\n"); + return -1; + } + + for (int i = 0; i < MAX_SAMPLES; i++) { + uint64_t pos = 0; + memset(buff, 0, lenOfOneRow); + + for (int c = 0; c < columnCount; c++) { + char *tmp = NULL; + + uint32_t dataLen; + char data_type = + (columns) ? (columns[c].data_type) : g_args.data_type[c]; + + switch (data_type) { + case TSDB_DATA_TYPE_BINARY: + dataLen = (columns) ? columns[c].dataLen : g_args.binwidth; + rand_string(data, dataLen); + pos += sprintf(buff + pos, "%s,", data); + break; + + case TSDB_DATA_TYPE_NCHAR: + dataLen = (columns) ? columns[c].dataLen : g_args.binwidth; + rand_string(data, dataLen - 1); + pos += sprintf(buff + pos, "%s,", data); + break; + + case TSDB_DATA_TYPE_INT: + if ((g_args.demo_mode) && (c == 1)) { + tmp = demo_voltage_int_str(); + } else { + tmp = rand_int_str(); + } + pos += sprintf(buff + pos, "%s,", tmp); + break; + + case TSDB_DATA_TYPE_UINT: + pos += sprintf(buff + pos, "%s,", rand_uint_str()); + break; + + case TSDB_DATA_TYPE_BIGINT: + pos += sprintf(buff + pos, "%s,", rand_bigint_str()); + break; + + case TSDB_DATA_TYPE_UBIGINT: + pos += sprintf(buff + pos, "%s,", rand_ubigint_str()); + break; + + case TSDB_DATA_TYPE_FLOAT: + if (g_args.demo_mode) { + if (c == 0) { + tmp = demo_current_float_str(); + } else { + tmp = demo_phase_float_str(); + } + } else { + tmp = rand_float_str(); + } + pos += sprintf(buff + pos, "%s,", tmp); + break; + + case TSDB_DATA_TYPE_DOUBLE: + pos += sprintf(buff + pos, "%s,", rand_double_str()); + break; + + case TSDB_DATA_TYPE_SMALLINT: + pos += sprintf(buff + pos, "%s,", rand_smallint_str()); + break; + + case TSDB_DATA_TYPE_USMALLINT: + pos += sprintf(buff + pos, "%s,", rand_usmallint_str()); + break; + + case TSDB_DATA_TYPE_TINYINT: + pos += sprintf(buff + pos, "%s,", rand_tinyint_str()); + break; + + case TSDB_DATA_TYPE_UTINYINT: + pos += sprintf(buff + pos, "%s,", rand_utinyint_str()); + break; + + case TSDB_DATA_TYPE_BOOL: + pos += sprintf(buff + pos, "%s,", rand_bool_str()); + break; + + case TSDB_DATA_TYPE_TIMESTAMP: + pos += sprintf(buff + pos, "%s,", rand_bigint_str()); + break; + + case TSDB_DATA_TYPE_NULL: + break; + + default: + errorPrint( + "%s() LN%d, Unknown data type %s\n", __func__, __LINE__, + (columns) ? (columns[c].dataType) : g_args.dataType[c]); + exit(EXIT_FAILURE); + } + } + + *(buff + pos - 1) = 0; + memcpy(sampleDataBuf + i * lenOfOneRow, buff, pos); + } + + free(buff); + return 0; +} + +static int generateSampleFromRandForNtb() { + return generateSampleFromRand(g_sampleDataBuf, g_args.lenOfOneRow, + g_args.columnCount, NULL); +} + +static int generateSampleFromRandForStb(SSuperTable *stbInfo) { + return generateSampleFromRand(stbInfo->sampleDataBuf, stbInfo->lenOfOneRow, + stbInfo->columnCount, stbInfo->columns); +} + +int prepareSampleForNtb() { + g_sampleDataBuf = calloc(g_args.lenOfOneRow * MAX_SAMPLES, 1); + if (NULL == g_sampleDataBuf) { + errorPrint("%s", "failed to allocate memory\n"); + return -1; + } + + return generateSampleFromRandForNtb(); +} + +int prepareSampleForStb(SSuperTable *stbInfo) { + stbInfo->sampleDataBuf = calloc(stbInfo->lenOfOneRow * MAX_SAMPLES, 1); + if (NULL == stbInfo->sampleDataBuf) { + errorPrint("%s", "failed to allocate memory\n"); + return -1; + } + + int ret; + if (0 == strncasecmp(stbInfo->dataSource, "sample", strlen("sample"))) { + if (stbInfo->useSampleTs) { + getAndSetRowsFromCsvFile(stbInfo); + } + ret = generateSampleFromCsvForStb(stbInfo); + } else { + ret = generateSampleFromRandForStb(stbInfo); + } + + if (0 != ret) { + errorPrint("read sample from %s file failed.\n", stbInfo->sampleFile); + tmfree(stbInfo->sampleDataBuf); + stbInfo->sampleDataBuf = NULL; + return -1; + } + + return 0; +} + +int64_t getTSRandTail(int64_t timeStampStep, int32_t seq, int disorderRatio, + int disorderRange) { + int64_t randTail = timeStampStep * seq; + if (disorderRatio > 0) { + int rand_num = taosRandom() % 100; + if (rand_num < disorderRatio) { + randTail = (randTail + (taosRandom() % disorderRange + 1)) * (-1); + debugPrint("rand data generated, back %" PRId64 "\n", randTail); + } + } + + return randTail; +} + +static int32_t generateDataTailWithoutStb( + uint32_t batch, char *buffer, int64_t remainderBufLen, int64_t insertRows, + uint64_t recordFrom, int64_t startTime, + /* int64_t *pSamplePos, */ int64_t *dataLen) { + uint64_t len = 0; + char * pstr = buffer; + + verbosePrint("%s() LN%d batch=%d\n", __func__, __LINE__, batch); + + int32_t k = 0; + for (k = 0; k < batch;) { + char *data = pstr; + memset(data, 0, MAX_DATA_SIZE); + + int64_t retLen = 0; + + char *data_type = g_args.data_type; + int lenOfBinary = g_args.binwidth; + + if (g_args.disorderRatio) { + retLen = + generateData(data, data_type, + startTime + getTSRandTail(g_args.timestamp_step, k, + g_args.disorderRatio, + g_args.disorderRange), + lenOfBinary); + } else { + retLen = generateData(data, data_type, + startTime + g_args.timestamp_step * k, + lenOfBinary); + } + + if (len > remainderBufLen) break; + + pstr += retLen; + k++; + len += retLen; + remainderBufLen -= retLen; + + verbosePrint("%s() LN%d len=%" PRIu64 " k=%d \nbuffer=%s\n", __func__, + __LINE__, len, k, buffer); + + recordFrom++; + + if (recordFrom >= insertRows) { + break; + } + } + + *dataLen = len; + return k; +} + +static int32_t generateStbDataTail(SSuperTable *stbInfo, uint32_t batch, + char *buffer, int64_t remainderBufLen, + int64_t insertRows, uint64_t recordFrom, + int64_t startTime, int64_t *pSamplePos, + int64_t *dataLen) { + uint64_t len = 0; + + char *pstr = buffer; + + bool tsRand; + if (0 == strncasecmp(stbInfo->dataSource, "rand", strlen("rand"))) { + tsRand = true; + } else { + tsRand = false; + } + verbosePrint("%s() LN%d batch=%u buflen=%" PRId64 "\n", __func__, __LINE__, + batch, remainderBufLen); + + int32_t k; + for (k = 0; k < batch;) { + char *data = pstr; + + int64_t lenOfRow = 0; + + if (tsRand) { + if (stbInfo->disorderRatio > 0) { + lenOfRow = generateStbRowData( + stbInfo, data, remainderBufLen, + startTime + getTSRandTail(stbInfo->timeStampStep, k, + stbInfo->disorderRatio, + stbInfo->disorderRange)); + } else { + lenOfRow = + generateStbRowData(stbInfo, data, remainderBufLen, + startTime + stbInfo->timeStampStep * k); + } + } else { + lenOfRow = getRowDataFromSample( + data, + (remainderBufLen < MAX_DATA_SIZE) ? remainderBufLen + : MAX_DATA_SIZE, + startTime + stbInfo->timeStampStep * k, stbInfo, pSamplePos); + } + + if (lenOfRow == 0) { + data[0] = '\0'; + break; + } + if ((lenOfRow + 1) > remainderBufLen) { + break; + } + + pstr += lenOfRow; + k++; + len += lenOfRow; + remainderBufLen -= lenOfRow; + + verbosePrint("%s() LN%d len=%" PRIu64 " k=%u \nbuffer=%s\n", __func__, + __LINE__, len, k, buffer); + + recordFrom++; + + if (recordFrom >= insertRows) { + break; + } + } + + *dataLen = len; + return k; +} + +static int generateSQLHeadWithoutStb(char *tableName, char *dbName, + char *buffer, int remainderBufLen) { + int len; + + char headBuf[HEAD_BUFF_LEN]; + + len = snprintf(headBuf, HEAD_BUFF_LEN, "%s.%s values", dbName, tableName); + + if (len > remainderBufLen) return -1; + + tstrncpy(buffer, headBuf, len + 1); + + return len; +} + +static int generateStbSQLHead(SSuperTable *stbInfo, char *tableName, + int64_t tableSeq, char *dbName, char *buffer, + int remainderBufLen) { + int len; + + char headBuf[HEAD_BUFF_LEN]; + + if (AUTO_CREATE_SUBTBL == stbInfo->autoCreateTable) { + char *tagsValBuf = (char *)calloc(TSDB_MAX_SQL_LEN + 1, 1); + if (NULL == tagsValBuf) { + errorPrint("%s", "failed to allocate memory\n"); + return -1; + } + + if (0 == stbInfo->tagSource) { + if (generateTagValuesForStb(stbInfo, tableSeq, tagsValBuf)) { + tmfree(tagsValBuf); + return -1; + } + } else { + snprintf( + tagsValBuf, TSDB_MAX_SQL_LEN, "(%s)", + stbInfo->tagDataBuf + stbInfo->lenOfTagOfOneRow * + (tableSeq % stbInfo->tagSampleCount)); + } + + len = + snprintf(headBuf, HEAD_BUFF_LEN, "%s.%s using %s.%s TAGS%s values", + dbName, tableName, dbName, stbInfo->stbName, tagsValBuf); + tmfree(tagsValBuf); + } else if (TBL_ALREADY_EXISTS == stbInfo->childTblExists) { + len = + snprintf(headBuf, HEAD_BUFF_LEN, "%s.%s values", dbName, tableName); + } else { + len = + snprintf(headBuf, HEAD_BUFF_LEN, "%s.%s values", dbName, tableName); + } + + if (len > remainderBufLen) return -1; + + tstrncpy(buffer, headBuf, len + 1); + + return len; +} + +int32_t generateStbInterlaceData(threadInfo *pThreadInfo, char *tableName, + uint32_t batchPerTbl, uint64_t i, + uint32_t batchPerTblTimes, uint64_t tableSeq, + char *buffer, int64_t insertRows, + int64_t startTime, + uint64_t *pRemainderBufLen) { + char *pstr = buffer; + + SSuperTable *stbInfo = pThreadInfo->stbInfo; + int headLen = + generateStbSQLHead(stbInfo, tableName, tableSeq, pThreadInfo->db_name, + pstr, (int)(*pRemainderBufLen)); + + if (headLen <= 0) { + return 0; + } + // generate data buffer + verbosePrint("[%d] %s() LN%d i=%" PRIu64 " buffer:\n%s\n", + pThreadInfo->threadID, __func__, __LINE__, i, buffer); + + pstr += headLen; + *pRemainderBufLen -= headLen; + + int64_t dataLen = 0; + + verbosePrint("[%d] %s() LN%d i=%" PRIu64 + " batchPerTblTimes=%u batchPerTbl = %u\n", + pThreadInfo->threadID, __func__, __LINE__, i, batchPerTblTimes, + batchPerTbl); + + if (0 == strncasecmp(stbInfo->startTimestamp, "now", 3)) { + startTime = taosGetTimestamp(pThreadInfo->time_precision); + } + + int32_t k = generateStbDataTail(stbInfo, batchPerTbl, pstr, + *pRemainderBufLen, insertRows, 0, startTime, + &(pThreadInfo->samplePos), &dataLen); + + if (k == batchPerTbl) { + pstr += dataLen; + *pRemainderBufLen -= dataLen; + } else { + debugPrint( + "%s() LN%d, generated data tail: %u, not equal batch per table: " + "%u\n", + __func__, __LINE__, k, batchPerTbl); + pstr -= headLen; + pstr[0] = '\0'; + k = 0; + } + + return k; +} + +int64_t generateInterlaceDataWithoutStb(char *tableName, uint32_t batch, + uint64_t tableSeq, char *dbName, + char *buffer, int64_t insertRows, + int64_t startTime, + uint64_t *pRemainderBufLen) { + char *pstr = buffer; + + int headLen = generateSQLHeadWithoutStb(tableName, dbName, pstr, + (int)(*pRemainderBufLen)); + + if (headLen <= 0) { + return 0; + } + + pstr += headLen; + *pRemainderBufLen -= headLen; + + int64_t dataLen = 0; + + int32_t k = generateDataTailWithoutStb(batch, pstr, *pRemainderBufLen, + insertRows, 0, startTime, &dataLen); + + if (k == batch) { + pstr += dataLen; + *pRemainderBufLen -= dataLen; + } else { + debugPrint( + "%s() LN%d, generated data tail: %d, not equal batch per table: " + "%u\n", + __func__, __LINE__, k, batch); + pstr -= headLen; + pstr[0] = '\0'; + k = 0; + } + + return k; +} + +static int32_t prepareStmtBindArrayByType(TAOS_BIND *bind, char data_type, + int32_t dataLen, int32_t timePrec, + char *value) { + int32_t * bind_int; + uint32_t *bind_uint; + int64_t * bind_bigint; + uint64_t *bind_ubigint; + float * bind_float; + double * bind_double; + int8_t * bind_bool; + int64_t * bind_ts2; + int16_t * bind_smallint; + uint16_t *bind_usmallint; + int8_t * bind_tinyint; + uint8_t * bind_utinyint; + + switch (data_type) { + case TSDB_DATA_TYPE_BINARY: + if (dataLen > TSDB_MAX_BINARY_LEN) { + errorPrint("binary length overflow, max size:%u\n", + (uint32_t)TSDB_MAX_BINARY_LEN); + return -1; + } + char *bind_binary; + + bind->buffer_type = TSDB_DATA_TYPE_BINARY; + if (value) { + bind_binary = calloc(1, strlen(value) + 1); + strncpy(bind_binary, value, strlen(value)); + bind->buffer_length = strlen(bind_binary); + } else { + bind_binary = calloc(1, dataLen + 1); + rand_string(bind_binary, dataLen); + bind->buffer_length = dataLen; + } + + bind->length = &bind->buffer_length; + bind->buffer = bind_binary; + bind->is_null = NULL; + break; + + case TSDB_DATA_TYPE_NCHAR: + if (dataLen > TSDB_MAX_BINARY_LEN) { + errorPrint("nchar length overflow, max size:%u\n", + (uint32_t)TSDB_MAX_BINARY_LEN); + return -1; + } + char *bind_nchar; + + bind->buffer_type = TSDB_DATA_TYPE_NCHAR; + if (value) { + bind_nchar = calloc(1, strlen(value) + 1); + strncpy(bind_nchar, value, strlen(value)); + } else { + bind_nchar = calloc(1, dataLen + 1); + rand_string(bind_nchar, dataLen); + } + + bind->buffer_length = strlen(bind_nchar); + bind->buffer = bind_nchar; + bind->length = &bind->buffer_length; + bind->is_null = NULL; + break; + + case TSDB_DATA_TYPE_INT: + bind_int = calloc(1, sizeof(int32_t)); + if (value) { + *bind_int = atoi(value); + } else { + *bind_int = rand_int(); + } + bind->buffer_type = TSDB_DATA_TYPE_INT; + bind->buffer_length = sizeof(int32_t); + bind->buffer = bind_int; + bind->length = &bind->buffer_length; + bind->is_null = NULL; + break; + + case TSDB_DATA_TYPE_UINT: + bind_uint = malloc(sizeof(uint32_t)); + + if (value) { + *bind_uint = atoi(value); + } else { + *bind_uint = rand_int(); + } + bind->buffer_type = TSDB_DATA_TYPE_UINT; + bind->buffer_length = sizeof(uint32_t); + bind->buffer = bind_uint; + bind->length = &bind->buffer_length; + bind->is_null = NULL; + break; + + case TSDB_DATA_TYPE_BIGINT: + bind_bigint = malloc(sizeof(int64_t)); + + if (value) { + *bind_bigint = atoll(value); + } else { + *bind_bigint = rand_bigint(); + } + bind->buffer_type = TSDB_DATA_TYPE_BIGINT; + bind->buffer_length = sizeof(int64_t); + bind->buffer = bind_bigint; + bind->length = &bind->buffer_length; + bind->is_null = NULL; + break; + + case TSDB_DATA_TYPE_UBIGINT: + bind_ubigint = malloc(sizeof(uint64_t)); + + if (value) { + *bind_ubigint = atoll(value); + } else { + *bind_ubigint = rand_bigint(); + } + bind->buffer_type = TSDB_DATA_TYPE_UBIGINT; + bind->buffer_length = sizeof(uint64_t); + bind->buffer = bind_ubigint; + bind->length = &bind->buffer_length; + bind->is_null = NULL; + break; + + case TSDB_DATA_TYPE_FLOAT: + bind_float = malloc(sizeof(float)); + + if (value) { + *bind_float = (float)atof(value); + } else { + *bind_float = rand_float(); + } + bind->buffer_type = TSDB_DATA_TYPE_FLOAT; + bind->buffer_length = sizeof(float); + bind->buffer = bind_float; + bind->length = &bind->buffer_length; + bind->is_null = NULL; + break; + + case TSDB_DATA_TYPE_DOUBLE: + bind_double = malloc(sizeof(double)); + + if (value) { + *bind_double = atof(value); + } else { + *bind_double = rand_double(); + } + bind->buffer_type = TSDB_DATA_TYPE_DOUBLE; + bind->buffer_length = sizeof(double); + bind->buffer = bind_double; + bind->length = &bind->buffer_length; + bind->is_null = NULL; + break; + + case TSDB_DATA_TYPE_SMALLINT: + bind_smallint = malloc(sizeof(int16_t)); + + if (value) { + *bind_smallint = (int16_t)atoi(value); + } else { + *bind_smallint = rand_smallint(); + } + bind->buffer_type = TSDB_DATA_TYPE_SMALLINT; + bind->buffer_length = sizeof(int16_t); + bind->buffer = bind_smallint; + bind->length = &bind->buffer_length; + bind->is_null = NULL; + break; + + case TSDB_DATA_TYPE_USMALLINT: + bind_usmallint = malloc(sizeof(uint16_t)); + + if (value) { + *bind_usmallint = (uint16_t)atoi(value); + } else { + *bind_usmallint = rand_smallint(); + } + bind->buffer_type = TSDB_DATA_TYPE_SMALLINT; + bind->buffer_length = sizeof(uint16_t); + bind->buffer = bind_usmallint; + bind->length = &bind->buffer_length; + bind->is_null = NULL; + break; + + case TSDB_DATA_TYPE_TINYINT: + bind_tinyint = malloc(sizeof(int8_t)); + + if (value) { + *bind_tinyint = (int8_t)atoi(value); + } else { + *bind_tinyint = rand_tinyint(); + } + bind->buffer_type = TSDB_DATA_TYPE_TINYINT; + bind->buffer_length = sizeof(int8_t); + bind->buffer = bind_tinyint; + bind->length = &bind->buffer_length; + bind->is_null = NULL; + break; + + case TSDB_DATA_TYPE_UTINYINT: + bind_utinyint = malloc(sizeof(uint8_t)); + + if (value) { + *bind_utinyint = (int8_t)atoi(value); + } else { + *bind_utinyint = rand_tinyint(); + } + bind->buffer_type = TSDB_DATA_TYPE_UTINYINT; + bind->buffer_length = sizeof(uint8_t); + bind->buffer = bind_utinyint; + bind->length = &bind->buffer_length; + bind->is_null = NULL; + break; + + case TSDB_DATA_TYPE_BOOL: + bind_bool = malloc(sizeof(int8_t)); + + if (value) { + if (strncasecmp(value, "true", 4)) { + *bind_bool = true; + } else { + *bind_bool = false; + } + } else { + *bind_bool = rand_bool(); + } + bind->buffer_type = TSDB_DATA_TYPE_BOOL; + bind->buffer_length = sizeof(int8_t); + bind->buffer = bind_bool; + bind->length = &bind->buffer_length; + bind->is_null = NULL; + break; + + case TSDB_DATA_TYPE_TIMESTAMP: + bind_ts2 = malloc(sizeof(int64_t)); + + if (value) { + if (strchr(value, ':') && strchr(value, '-')) { + int i = 0; + while (value[i] != '\0') { + if (value[i] == '\"' || value[i] == '\'') { + value[i] = ' '; + } + i++; + } + int64_t tmpEpoch; + if (TSDB_CODE_SUCCESS != + taosParseTime(value, &tmpEpoch, (int32_t)strlen(value), + timePrec, 0)) { + free(bind_ts2); + errorPrint("Input %s, time format error!\n", value); + return -1; + } + *bind_ts2 = tmpEpoch; + } else { + *bind_ts2 = atoll(value); + } + } else { + *bind_ts2 = rand_bigint(); + } + bind->buffer_type = TSDB_DATA_TYPE_TIMESTAMP; + bind->buffer_length = sizeof(int64_t); + bind->buffer = bind_ts2; + bind->length = &bind->buffer_length; + bind->is_null = NULL; + break; + + case TSDB_DATA_TYPE_NULL: + break; + + default: + errorPrint("Not support data type: %d\n", data_type); + return -1; + } + + return 0; +} + +int32_t prepareStmtWithoutStb(threadInfo *pThreadInfo, char *tableName, + uint32_t batch, int64_t insertRows, + int64_t recordFrom, int64_t startTime) { + TAOS_STMT *stmt = pThreadInfo->stmt; + int ret = taos_stmt_set_tbname(stmt, tableName); + if (ret != 0) { + errorPrint( + "failed to execute taos_stmt_set_tbname(%s). return 0x%x. reason: " + "%s\n", + tableName, ret, taos_stmt_errstr(stmt)); + return ret; + } + + char *data_type = g_args.data_type; + + char *bindArray = malloc(sizeof(TAOS_BIND) * (g_args.columnCount + 1)); + if (bindArray == NULL) { + errorPrint("Failed to allocate %d bind params\n", + (g_args.columnCount + 1)); + return -1; + } + + int32_t k = 0; + for (k = 0; k < batch;) { + /* columnCount + 1 (ts) */ + + TAOS_BIND *bind = (TAOS_BIND *)(bindArray + 0); + + int64_t *bind_ts = pThreadInfo->bind_ts; + + bind->buffer_type = TSDB_DATA_TYPE_TIMESTAMP; + + if (g_args.disorderRatio) { + *bind_ts = startTime + getTSRandTail(g_args.timestamp_step, k, + g_args.disorderRatio, + g_args.disorderRange); + } else { + *bind_ts = startTime + g_args.timestamp_step * k; + } + bind->buffer_length = sizeof(int64_t); + bind->buffer = bind_ts; + bind->length = &bind->buffer_length; + bind->is_null = NULL; + + for (int i = 0; i < g_args.columnCount; i++) { + bind = (TAOS_BIND *)((char *)bindArray + + (sizeof(TAOS_BIND) * (i + 1))); + if (-1 == + prepareStmtBindArrayByType(bind, data_type[i], g_args.binwidth, + pThreadInfo->time_precision, NULL)) { + free(bindArray); + return -1; + } + } + if (taos_stmt_bind_param(stmt, (TAOS_BIND *)bindArray)) { + errorPrint("taos_stmt_bind_param() failed! reason: %s\n", + taos_stmt_errstr(stmt)); + break; + } + // if msg > 3MB, break + if (taos_stmt_add_batch(stmt)) { + errorPrint("taos_stmt_add_batch() failed! reason: %s\n", + taos_stmt_errstr(stmt)); + break; + } + + k++; + recordFrom++; + if (recordFrom >= insertRows) { + break; + } + } + + free(bindArray); + return k; +} + +int32_t prepareStbStmtBindTag(char *bindArray, SSuperTable *stbInfo, + char *tagsVal, int32_t timePrec) { + TAOS_BIND *tag; + + for (int t = 0; t < stbInfo->tagCount; t++) { + tag = (TAOS_BIND *)((char *)bindArray + (sizeof(TAOS_BIND) * t)); + if (prepareStmtBindArrayByType(tag, stbInfo->tags[t].data_type, + stbInfo->tags[t].dataLen, timePrec, + NULL)) { + return -1; + } + } + + return 0; +} + +int parseSamplefileToStmtBatch(SSuperTable *stbInfo) { + int32_t columnCount = (stbInfo) ? stbInfo->columnCount : g_args.columnCount; + char * sampleBindBatchArray = NULL; + + if (stbInfo) { + stbInfo->sampleBindBatchArray = + calloc(1, sizeof(uintptr_t *) * columnCount); + sampleBindBatchArray = stbInfo->sampleBindBatchArray; + } else { + g_sampleBindBatchArray = calloc(1, sizeof(uintptr_t *) * columnCount); + sampleBindBatchArray = g_sampleBindBatchArray; + } + + for (int c = 0; c < columnCount; c++) { + char data_type = + (stbInfo) ? stbInfo->columns[c].data_type : g_args.data_type[c]; + + char *tmpP = NULL; + + switch (data_type) { + case TSDB_DATA_TYPE_INT: + case TSDB_DATA_TYPE_UINT: + tmpP = calloc(1, sizeof(int32_t) * MAX_SAMPLES); + *(uintptr_t *)(sampleBindBatchArray + sizeof(uintptr_t *) * c) = + (uintptr_t)tmpP; + break; + + case TSDB_DATA_TYPE_TINYINT: + case TSDB_DATA_TYPE_UTINYINT: + tmpP = calloc(1, sizeof(char) * MAX_SAMPLES); + *(uintptr_t *)(sampleBindBatchArray + sizeof(uintptr_t *) * c) = + (uintptr_t)tmpP; + break; + + case TSDB_DATA_TYPE_SMALLINT: + case TSDB_DATA_TYPE_USMALLINT: + tmpP = calloc(1, sizeof(int16_t) * MAX_SAMPLES); + *(uintptr_t *)(sampleBindBatchArray + sizeof(uintptr_t *) * c) = + (uintptr_t)tmpP; + break; + + case TSDB_DATA_TYPE_BIGINT: + case TSDB_DATA_TYPE_UBIGINT: + tmpP = calloc(1, sizeof(int64_t) * MAX_SAMPLES); + *(uintptr_t *)(sampleBindBatchArray + sizeof(uintptr_t *) * c) = + (uintptr_t)tmpP; + break; + + case TSDB_DATA_TYPE_BOOL: + tmpP = calloc(1, sizeof(char) * MAX_SAMPLES); + *(uintptr_t *)(sampleBindBatchArray + sizeof(uintptr_t *) * c) = + (uintptr_t)tmpP; + break; + + case TSDB_DATA_TYPE_FLOAT: + tmpP = calloc(1, sizeof(float) * MAX_SAMPLES); + *(uintptr_t *)(sampleBindBatchArray + sizeof(uintptr_t *) * c) = + (uintptr_t)tmpP; + break; + + case TSDB_DATA_TYPE_DOUBLE: + tmpP = calloc(1, sizeof(double) * MAX_SAMPLES); + *(uintptr_t *)(sampleBindBatchArray + sizeof(uintptr_t *) * c) = + (uintptr_t)tmpP; + break; + + case TSDB_DATA_TYPE_BINARY: + case TSDB_DATA_TYPE_NCHAR: + tmpP = calloc( + 1, MAX_SAMPLES * (((stbInfo) ? stbInfo->columns[c].dataLen + : g_args.binwidth) + + 1)); + *(uintptr_t *)(sampleBindBatchArray + sizeof(uintptr_t *) * c) = + (uintptr_t)tmpP; + break; + + case TSDB_DATA_TYPE_TIMESTAMP: + tmpP = calloc(1, sizeof(int64_t) * MAX_SAMPLES); + *(uintptr_t *)(sampleBindBatchArray + sizeof(uintptr_t *) * c) = + (uintptr_t)tmpP; + break; + + default: + errorPrint("Unknown data type: %s\n", + (stbInfo) ? stbInfo->columns[c].dataType + : g_args.dataType[c]); + exit(EXIT_FAILURE); + } + } + + char *sampleDataBuf = (stbInfo) ? stbInfo->sampleDataBuf : g_sampleDataBuf; + int64_t lenOfOneRow = (stbInfo) ? stbInfo->lenOfOneRow : g_args.lenOfOneRow; + + for (int i = 0; i < MAX_SAMPLES; i++) { + int cursor = 0; + + for (int c = 0; c < columnCount; c++) { + char data_type = + (stbInfo) ? stbInfo->columns[c].data_type : g_args.data_type[c]; + char *restStr = sampleDataBuf + lenOfOneRow * i + cursor; + int lengthOfRest = (int)strlen(restStr); + + int index = 0; + for (index = 0; index < lengthOfRest; index++) { + if (restStr[index] == ',') { + break; + } + } + + char *tmpStr = calloc(1, index + 1); + if (NULL == tmpStr) { + errorPrint("%s", "failed to allocate memory\n"); + return -1; + } + + strncpy(tmpStr, restStr, index); + cursor += index + 1; // skip ',' too + char *tmpP; + + switch (data_type) { + case TSDB_DATA_TYPE_INT: + case TSDB_DATA_TYPE_UINT: + *((int32_t *)((uintptr_t) * + (uintptr_t *)(sampleBindBatchArray + + sizeof(char *) * c) + + sizeof(int32_t) * i)) = atoi(tmpStr); + break; + + case TSDB_DATA_TYPE_FLOAT: + *(float *)(((uintptr_t) * + (uintptr_t *)(sampleBindBatchArray + + sizeof(char *) * c) + + sizeof(float) * i)) = (float)atof(tmpStr); + break; + + case TSDB_DATA_TYPE_DOUBLE: + *(double *)(((uintptr_t) * + (uintptr_t *)(sampleBindBatchArray + + sizeof(char *) * c) + + sizeof(double) * i)) = atof(tmpStr); + break; + + case TSDB_DATA_TYPE_TINYINT: + case TSDB_DATA_TYPE_UTINYINT: + *((int8_t *)((uintptr_t) * + (uintptr_t *)(sampleBindBatchArray + + sizeof(char *) * c) + + sizeof(int8_t) * i)) = (int8_t)atoi(tmpStr); + break; + + case TSDB_DATA_TYPE_SMALLINT: + case TSDB_DATA_TYPE_USMALLINT: + *((int16_t *)((uintptr_t) * + (uintptr_t *)(sampleBindBatchArray + + sizeof(char *) * c) + + sizeof(int16_t) * i)) = (int16_t)atoi(tmpStr); + break; + + case TSDB_DATA_TYPE_BIGINT: + case TSDB_DATA_TYPE_UBIGINT: + *((int64_t *)((uintptr_t) * + (uintptr_t *)(sampleBindBatchArray + + sizeof(char *) * c) + + sizeof(int64_t) * i)) = (int64_t)atol(tmpStr); + break; + + case TSDB_DATA_TYPE_BOOL: + *((int8_t *)((uintptr_t) * + (uintptr_t *)(sampleBindBatchArray + + sizeof(char *) * c) + + sizeof(int8_t) * i)) = (int8_t)atoi(tmpStr); + break; + + case TSDB_DATA_TYPE_TIMESTAMP: + *((int64_t *)((uintptr_t) * + (uintptr_t *)(sampleBindBatchArray + + sizeof(char *) * c) + + sizeof(int64_t) * i)) = (int64_t)atol(tmpStr); + break; + + case TSDB_DATA_TYPE_BINARY: + case TSDB_DATA_TYPE_NCHAR: + tmpP = (char *)(*(uintptr_t *)(sampleBindBatchArray + + sizeof(char *) * c)); + strcpy(tmpP + i * (((stbInfo) ? stbInfo->columns[c].dataLen + : g_args.binwidth)), + tmpStr); + break; + + default: + break; + } + + free(tmpStr); + } + } + + return 0; +} + +static int parseSampleToStmtBatchForThread(threadInfo * pThreadInfo, + SSuperTable *stbInfo, + uint32_t timePrec, uint32_t batch) { + uint32_t columnCount = + (stbInfo) ? stbInfo->columnCount : g_args.columnCount; + + pThreadInfo->bind_ts_array = calloc(1, sizeof(int64_t) * batch); + if (NULL == pThreadInfo->bind_ts_array) { + errorPrint("%s", "failed to allocate memory\n"); + return -1; + } + + pThreadInfo->bindParams = + calloc(1, sizeof(TAOS_MULTI_BIND) * (columnCount + 1)); + if (NULL == pThreadInfo->bindParams) { + errorPrint("%s", "failed to allocate memory\n"); + return -1; + } + + pThreadInfo->is_null = calloc(1, batch); + if (NULL == pThreadInfo->is_null) { + errorPrint("%s", "failed to allocate memory\n"); + return -1; + } + + return 0; +} + +int parseStbSampleToStmtBatchForThread(threadInfo * pThreadInfo, + SSuperTable *stbInfo, uint32_t timePrec, + uint32_t batch) { + return parseSampleToStmtBatchForThread(pThreadInfo, stbInfo, timePrec, + batch); +} + +int parseNtbSampleToStmtBatchForThread(threadInfo *pThreadInfo, + uint32_t timePrec, uint32_t batch) { + return parseSampleToStmtBatchForThread(pThreadInfo, NULL, timePrec, batch); +} + +int32_t generateStbProgressiveData(SSuperTable *stbInfo, char *tableName, + int64_t tableSeq, char *dbName, char *buffer, + int64_t insertRows, uint64_t recordFrom, + int64_t startTime, int64_t *pSamplePos, + int64_t *pRemainderBufLen) { + char *pstr = buffer; + + memset(pstr, 0, *pRemainderBufLen); + + int64_t headLen = generateStbSQLHead(stbInfo, tableName, tableSeq, dbName, + buffer, (int)(*pRemainderBufLen)); + + if (headLen <= 0) { + return 0; + } + pstr += headLen; + *pRemainderBufLen -= headLen; + + int64_t dataLen; + + return generateStbDataTail(stbInfo, g_args.reqPerReq, pstr, + *pRemainderBufLen, insertRows, recordFrom, + startTime, pSamplePos, &dataLen); +} + +int32_t generateProgressiveDataWithoutStb( + char *tableName, threadInfo *pThreadInfo, char *buffer, int64_t insertRows, + uint64_t recordFrom, int64_t startTime, int64_t *pRemainderBufLen) { + char *pstr = buffer; + + memset(buffer, 0, *pRemainderBufLen); + + int64_t headLen = generateSQLHeadWithoutStb( + tableName, pThreadInfo->db_name, buffer, (int)(*pRemainderBufLen)); + + if (headLen <= 0) { + return 0; + } + pstr += headLen; + *pRemainderBufLen -= headLen; + + int64_t dataLen; + + return generateDataTailWithoutStb(g_args.reqPerReq, pstr, *pRemainderBufLen, + insertRows, recordFrom, startTime, + /*pSamplePos, */ &dataLen); +} + +int32_t generateSmlConstPart(char *sml, SSuperTable *stbInfo, + threadInfo *pThreadInfo, int tbSeq) { + int64_t dataLen = 0; + uint64_t length = stbInfo->lenOfOneRow; + if (stbInfo->lineProtocol == TSDB_SML_LINE_PROTOCOL) { + dataLen += + snprintf(sml + dataLen, length - dataLen, "%s,id=%s%" PRIu64 "", + stbInfo->stbName, stbInfo->childTblPrefix, + tbSeq + pThreadInfo->start_table_from); + } else if (stbInfo->lineProtocol == TSDB_SML_TELNET_PROTOCOL) { + dataLen += snprintf(sml + dataLen, length - dataLen, "id=%s%" PRIu64 "", + stbInfo->childTblPrefix, + tbSeq + pThreadInfo->start_table_from); + } else { + errorPrint("unsupport schemaless protocol (%d)\n", + stbInfo->lineProtocol); + return -1; + } + + for (int j = 0; j < stbInfo->tagCount; j++) { + tstrncpy(sml + dataLen, + (stbInfo->lineProtocol == TSDB_SML_LINE_PROTOCOL) ? "," : " ", + 2); + dataLen += 1; + switch (stbInfo->tags[j].data_type) { + case TSDB_DATA_TYPE_TIMESTAMP: + errorPrint("Does not support data type %s as tag\n", + stbInfo->tags[j].dataType); + return -1; + case TSDB_DATA_TYPE_BOOL: + dataLen += snprintf(sml + dataLen, length - dataLen, "t%d=%s", + j, rand_bool_str()); + break; + case TSDB_DATA_TYPE_TINYINT: + dataLen += snprintf(sml + dataLen, length - dataLen, "t%d=%s", + j, rand_tinyint_str()); + break; + case TSDB_DATA_TYPE_UTINYINT: + dataLen += snprintf(sml + dataLen, length - dataLen, "t%d=%s", + j, rand_utinyint_str()); + break; + case TSDB_DATA_TYPE_SMALLINT: + dataLen += snprintf(sml + dataLen, length - dataLen, "t%d=%s", + j, rand_smallint_str()); + break; + case TSDB_DATA_TYPE_USMALLINT: + dataLen += snprintf(sml + dataLen, length - dataLen, "t%d=%s", + j, rand_usmallint_str()); + break; + case TSDB_DATA_TYPE_INT: + dataLen += snprintf(sml + dataLen, length - dataLen, "t%d=%s", + j, rand_int_str()); + break; + case TSDB_DATA_TYPE_UINT: + dataLen += snprintf(sml + dataLen, length - dataLen, "t%d=%s", + j, rand_uint_str()); + break; + case TSDB_DATA_TYPE_BIGINT: + dataLen += snprintf(sml + dataLen, length - dataLen, "t%d=%s", + j, rand_bigint_str()); + break; + case TSDB_DATA_TYPE_UBIGINT: + dataLen += snprintf(sml + dataLen, length - dataLen, "t%d=%s", + j, rand_ubigint_str()); + break; + case TSDB_DATA_TYPE_FLOAT: + dataLen += snprintf(sml + dataLen, length - dataLen, "t%d=%s", + j, rand_float_str()); + break; + case TSDB_DATA_TYPE_DOUBLE: + dataLen += snprintf(sml + dataLen, length - dataLen, "t%d=%s", + j, rand_double_str()); + break; + case TSDB_DATA_TYPE_BINARY: + case TSDB_DATA_TYPE_NCHAR: + if (stbInfo->tags[j].dataLen > TSDB_MAX_BINARY_LEN) { + errorPrint("binary or nchar length overflow, maxsize:%u\n", + (uint32_t)TSDB_MAX_BINARY_LEN); + return -1; + } + char *buf = (char *)calloc(stbInfo->tags[j].dataLen + 1, 1); + if (NULL == buf) { + errorPrint("%s", "failed to allocate memory\n"); + return -1; + } + rand_string(buf, stbInfo->tags[j].dataLen); + dataLen += + snprintf(sml + dataLen, length - dataLen, "t%d=%s", j, buf); + tmfree(buf); + break; + + default: + errorPrint("Unsupport data type %s\n", + stbInfo->tags[j].dataType); + return -1; + } + } + return 0; +} + +int32_t generateSmlMutablePart(char *line, char *sml, SSuperTable *stbInfo, + threadInfo *pThreadInfo, int64_t timestamp) { + int dataLen = 0; + uint64_t buffer = stbInfo->lenOfOneRow; + if (stbInfo->lineProtocol == TSDB_SML_LINE_PROTOCOL) { + dataLen = snprintf(line, buffer, "%s ", sml); + for (uint32_t c = 0; c < stbInfo->columnCount; c++) { + if (c != 0) { + tstrncpy(line + dataLen, ",", 2); + dataLen += 1; + } + switch (stbInfo->columns[c].data_type) { + case TSDB_DATA_TYPE_TIMESTAMP: + errorPrint("Does not support data type %s as tag\n", + stbInfo->columns[c].dataType); + return -1; + case TSDB_DATA_TYPE_BOOL: + dataLen += snprintf(line + dataLen, buffer - dataLen, + "c%d=%s", c, rand_bool_str()); + break; + case TSDB_DATA_TYPE_TINYINT: + dataLen += snprintf(line + dataLen, buffer - dataLen, + "c%d=%si8", c, rand_tinyint_str()); + break; + case TSDB_DATA_TYPE_UTINYINT: + dataLen += snprintf(line + dataLen, buffer - dataLen, + "c%d=%su8", c, rand_utinyint_str()); + break; + case TSDB_DATA_TYPE_SMALLINT: + dataLen += snprintf(line + dataLen, buffer - dataLen, + "c%d=%si16", c, rand_smallint_str()); + break; + case TSDB_DATA_TYPE_USMALLINT: + dataLen += snprintf(line + dataLen, buffer - dataLen, + "c%d=%su16", c, rand_usmallint_str()); + break; + case TSDB_DATA_TYPE_INT: + dataLen += snprintf(line + dataLen, buffer - dataLen, + "c%d=%si32", c, rand_int_str()); + break; + case TSDB_DATA_TYPE_UINT: + dataLen += snprintf(line + dataLen, buffer - dataLen, + "c%d=%su32", c, rand_uint_str()); + break; + case TSDB_DATA_TYPE_BIGINT: + dataLen += snprintf(line + dataLen, buffer - dataLen, + "c%d=%si64", c, rand_bigint_str()); + break; + case TSDB_DATA_TYPE_UBIGINT: + dataLen += snprintf(line + dataLen, buffer - dataLen, + "c%d=%su64", c, rand_ubigint_str()); + break; + case TSDB_DATA_TYPE_FLOAT: + dataLen += snprintf(line + dataLen, buffer - dataLen, + "c%d=%sf32", c, rand_float_str()); + break; + case TSDB_DATA_TYPE_DOUBLE: + dataLen += snprintf(line + dataLen, buffer - dataLen, + "c%d=%sf64", c, rand_double_str()); + break; + case TSDB_DATA_TYPE_BINARY: + case TSDB_DATA_TYPE_NCHAR: + if (stbInfo->columns[c].dataLen > TSDB_MAX_BINARY_LEN) { + errorPrint( + "binary or nchar length overflow, maxsize:%u\n", + (uint32_t)TSDB_MAX_BINARY_LEN); + return -1; + } + char *buf = + (char *)calloc(stbInfo->columns[c].dataLen + 1, 1); + if (NULL == buf) { + errorPrint("%s", "failed to allocate memory\n"); + return -1; + } + rand_string(buf, stbInfo->columns[c].dataLen); + if (stbInfo->columns[c].data_type == + TSDB_DATA_TYPE_BINARY) { + dataLen += snprintf(line + dataLen, buffer - dataLen, + "c%d=\"%s\"", c, buf); + } else { + dataLen += snprintf(line + dataLen, buffer - dataLen, + "c%d=L\"%s\"", c, buf); + } + tmfree(buf); + break; + default: + errorPrint("Unsupport data type %s\n", + stbInfo->columns[c].dataType); + return -1; + } + } + dataLen += snprintf(line + dataLen, buffer - dataLen, " %" PRId64 "", + timestamp); + return 0; + } else if (stbInfo->lineProtocol == TSDB_SML_TELNET_PROTOCOL) { + switch (stbInfo->columns[0].data_type) { + case TSDB_DATA_TYPE_BOOL: + snprintf(line, buffer, "%s %" PRId64 " %s %s", stbInfo->stbName, + timestamp, rand_bool_str(), sml); + break; + case TSDB_DATA_TYPE_TINYINT: + snprintf(line, buffer, "%s %" PRId64 " %si8 %s", + stbInfo->stbName, timestamp, rand_tinyint_str(), sml); + break; + case TSDB_DATA_TYPE_UTINYINT: + snprintf(line, buffer, "%s %" PRId64 " %su8 %s", + stbInfo->stbName, timestamp, rand_utinyint_str(), sml); + break; + case TSDB_DATA_TYPE_SMALLINT: + snprintf(line, buffer, "%s %" PRId64 " %si16 %s", + stbInfo->stbName, timestamp, rand_smallint_str(), sml); + break; + case TSDB_DATA_TYPE_USMALLINT: + snprintf(line, buffer, "%s %" PRId64 " %su16 %s", + stbInfo->stbName, timestamp, rand_usmallint_str(), + sml); + break; + case TSDB_DATA_TYPE_INT: + snprintf(line, buffer, "%s %" PRId64 " %si32 %s", + stbInfo->stbName, timestamp, rand_int_str(), sml); + break; + case TSDB_DATA_TYPE_UINT: + snprintf(line, buffer, "%s %" PRId64 " %su32 %s", + stbInfo->stbName, timestamp, rand_uint_str(), sml); + break; + case TSDB_DATA_TYPE_BIGINT: + snprintf(line, buffer, "%s %" PRId64 " %si64 %s", + stbInfo->stbName, timestamp, rand_bigint_str(), sml); + break; + case TSDB_DATA_TYPE_UBIGINT: + snprintf(line, buffer, "%s %" PRId64 " %su64 %s", + stbInfo->stbName, timestamp, rand_ubigint_str(), sml); + break; + case TSDB_DATA_TYPE_FLOAT: + snprintf(line, buffer, "%s %" PRId64 " %sf32 %s", + stbInfo->stbName, timestamp, rand_float_str(), sml); + break; + case TSDB_DATA_TYPE_DOUBLE: + snprintf(line, buffer, "%s %" PRId64 " %sf64 %s", + stbInfo->stbName, timestamp, rand_double_str(), sml); + break; + case TSDB_DATA_TYPE_BINARY: + case TSDB_DATA_TYPE_NCHAR: + if (stbInfo->columns[0].dataLen > TSDB_MAX_BINARY_LEN) { + errorPrint("binary or nchar length overflow, maxsize:%u\n", + (uint32_t)TSDB_MAX_BINARY_LEN); + return -1; + } + char *buf = (char *)calloc(stbInfo->columns[0].dataLen + 1, 1); + if (NULL == buf) { + errorPrint("%s", "failed to allocate memory\n"); + return -1; + } + rand_string(buf, stbInfo->columns[0].dataLen); + if (stbInfo->columns[0].data_type == TSDB_DATA_TYPE_BINARY) { + snprintf(line, buffer, "%s %" PRId64 " \"%s\" %s", + stbInfo->stbName, timestamp, buf, sml); + } else { + snprintf(line, buffer, "%s %" PRId64 " L\"%s\" %s", + stbInfo->stbName, timestamp, buf, sml); + } + tmfree(buf); + break; + default: + errorPrint("Unsupport data type %s\n", + stbInfo->columns[0].dataType); + return -1; + } + return 0; + } else { + errorPrint("unsupport schemaless protocol(%d)\n", + stbInfo->lineProtocol); + return -1; + } +} + +int32_t generateSmlJsonTags(cJSON *tagsList, SSuperTable *stbInfo, + threadInfo *pThreadInfo, int tbSeq) { + cJSON *tags = cJSON_CreateObject(); + char * tbName = calloc(1, TSDB_TABLE_NAME_LEN); + assert(tbName); + snprintf(tbName, TSDB_TABLE_NAME_LEN, "%s%" PRIu64 "", + stbInfo->childTblPrefix, tbSeq + pThreadInfo->start_table_from); + cJSON_AddStringToObject(tags, "id", tbName); + char *tagName = calloc(1, TSDB_MAX_TAGS); + assert(tagName); + for (int i = 0; i < stbInfo->tagCount; i++) { + cJSON *tag = cJSON_CreateObject(); + snprintf(tagName, TSDB_MAX_TAGS, "t%d", i); + switch (stbInfo->tags[i].data_type) { + case TSDB_DATA_TYPE_BOOL: + cJSON_AddNumberToObject(tag, "value", rand_bool()); + cJSON_AddStringToObject(tag, "type", "bool"); + break; + case TSDB_DATA_TYPE_TINYINT: + cJSON_AddNumberToObject(tag, "value", rand_tinyint()); + cJSON_AddStringToObject(tag, "type", "tinyint"); + break; + case TSDB_DATA_TYPE_SMALLINT: + cJSON_AddNumberToObject(tag, "value", rand_smallint()); + cJSON_AddStringToObject(tag, "type", "smallint"); + break; + case TSDB_DATA_TYPE_INT: + cJSON_AddNumberToObject(tag, "value", rand_int()); + cJSON_AddStringToObject(tag, "type", "int"); + break; + case TSDB_DATA_TYPE_BIGINT: + cJSON_AddNumberToObject(tag, "value", (double)rand_bigint()); + cJSON_AddStringToObject(tag, "type", "bigint"); + break; + case TSDB_DATA_TYPE_FLOAT: + cJSON_AddNumberToObject(tag, "value", rand_float()); + cJSON_AddStringToObject(tag, "type", "float"); + break; + case TSDB_DATA_TYPE_DOUBLE: + cJSON_AddNumberToObject(tag, "value", rand_double()); + cJSON_AddStringToObject(tag, "type", "double"); + break; + case TSDB_DATA_TYPE_BINARY: + case TSDB_DATA_TYPE_NCHAR: + if (stbInfo->tags[i].dataLen > TSDB_MAX_BINARY_LEN) { + errorPrint("binary or nchar length overflow, maxsize:%u\n", + (uint32_t)TSDB_MAX_BINARY_LEN); + return -1; + } + char *buf = (char *)calloc(stbInfo->tags[i].dataLen + 1, 1); + if (NULL == buf) { + errorPrint("%s", "failed to allocate memory\n"); + return -1; + } + rand_string(buf, stbInfo->tags[i].dataLen); + if (stbInfo->tags[i].data_type == TSDB_DATA_TYPE_BINARY) { + cJSON_AddStringToObject(tag, "value", buf); + cJSON_AddStringToObject(tag, "type", "binary"); + } else { + cJSON_AddStringToObject(tag, "value", buf); + cJSON_AddStringToObject(tag, "type", "nchar"); + } + tmfree(buf); + break; + default: + errorPrint( + "unsupport data type (%s) for schemaless json protocol\n", + stbInfo->tags[i].dataType); + return -1; + } + cJSON_AddItemToObject(tags, tagName, tag); + } + cJSON_AddItemToArray(tagsList, tags); + tmfree(tagName); + tmfree(tbName); + return 0; +} + +int32_t generateSmlJsonCols(cJSON *array, cJSON *tag, SSuperTable *stbInfo, + threadInfo *pThreadInfo, int64_t timestamp) { + cJSON *record = cJSON_CreateObject(); + cJSON *ts = cJSON_CreateObject(); + cJSON_AddNumberToObject(ts, "value", (double)timestamp); + if (pThreadInfo->time_precision == TSDB_TIME_PRECISION_MILLI) { + cJSON_AddStringToObject(ts, "type", "ms"); + } else if (pThreadInfo->time_precision == TSDB_TIME_PRECISION_MICRO) { + cJSON_AddStringToObject(ts, "type", "us"); + } else if (pThreadInfo->time_precision == TSDB_TIME_PRECISION_NANO) { + cJSON_AddStringToObject(ts, "type", "ns"); + } else { + errorPrint("unsupport time precision %d\n", + pThreadInfo->time_precision); + return -1; + } + cJSON *value = cJSON_CreateObject(); + switch (stbInfo->columns[0].data_type) { + case TSDB_DATA_TYPE_BOOL: + cJSON_AddNumberToObject(value, "value", rand_bool()); + cJSON_AddStringToObject(value, "type", "bool"); + break; + case TSDB_DATA_TYPE_TINYINT: + cJSON_AddNumberToObject(value, "value", rand_tinyint()); + cJSON_AddStringToObject(value, "type", "tinyint"); + break; + case TSDB_DATA_TYPE_SMALLINT: + cJSON_AddNumberToObject(value, "value", rand_smallint()); + cJSON_AddStringToObject(value, "type", "smallint"); + break; + case TSDB_DATA_TYPE_INT: + cJSON_AddNumberToObject(value, "value", rand_int()); + cJSON_AddStringToObject(value, "type", "int"); + break; + case TSDB_DATA_TYPE_BIGINT: + cJSON_AddNumberToObject(value, "value", (double)rand_bigint()); + cJSON_AddStringToObject(value, "type", "bigint"); + break; + case TSDB_DATA_TYPE_FLOAT: + cJSON_AddNumberToObject(value, "value", rand_float()); + cJSON_AddStringToObject(value, "type", "float"); + break; + case TSDB_DATA_TYPE_DOUBLE: + cJSON_AddNumberToObject(value, "value", rand_double()); + cJSON_AddStringToObject(value, "type", "double"); + break; + case TSDB_DATA_TYPE_BINARY: + case TSDB_DATA_TYPE_NCHAR: + if (stbInfo->columns[0].dataLen > TSDB_MAX_BINARY_LEN) { + errorPrint("binary or nchar length overflow, maxsize:%u\n", + (uint32_t)TSDB_MAX_BINARY_LEN); + return -1; + } + char *buf = (char *)calloc(stbInfo->columns[0].dataLen + 1, 1); + if (NULL == buf) { + errorPrint("%s", "failed to allocate memory\n"); + return -1; + } + rand_string(buf, stbInfo->columns[0].dataLen); + if (stbInfo->columns[0].data_type == TSDB_DATA_TYPE_BINARY) { + cJSON_AddStringToObject(value, "value", buf); + cJSON_AddStringToObject(value, "type", "binary"); + } else { + cJSON_AddStringToObject(value, "value", buf); + cJSON_AddStringToObject(value, "type", "nchar"); + } + break; + default: + errorPrint( + "unsupport data type (%s) for schemaless json protocol\n", + stbInfo->columns[0].dataType); + return -1; + } + cJSON_AddItemToObject(record, "timestamp", ts); + cJSON_AddItemToObject(record, "value", value); + cJSON_AddItemToObject(record, "tags", tag); + cJSON_AddStringToObject(record, "metric", stbInfo->stbName); + cJSON_AddItemToArray(array, record); + return 0; +} diff --git a/src/kit/taosdemo/src/demoInsert.c b/src/kit/taosdemo/src/demoInsert.c new file mode 100644 index 0000000000000000000000000000000000000000..4dac128f33a3a9dc4723254f27378a98c90ebf1a --- /dev/null +++ b/src/kit/taosdemo/src/demoInsert.c @@ -0,0 +1,3481 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#include "cJSON.h" +#include "demo.h" +#include "demoData.h" + +static int calcRowLen(SSuperTable *superTbls) { + int colIndex; + int lenOfOneRow = 0; + + for (colIndex = 0; colIndex < superTbls->columnCount; colIndex++) { + char *dataType = superTbls->columns[colIndex].dataType; + + switch (superTbls->columns[colIndex].data_type) { + case TSDB_DATA_TYPE_BINARY: + lenOfOneRow += superTbls->columns[colIndex].dataLen + 3; + break; + + case TSDB_DATA_TYPE_NCHAR: + lenOfOneRow += superTbls->columns[colIndex].dataLen + 3; + break; + + case TSDB_DATA_TYPE_INT: + case TSDB_DATA_TYPE_UINT: + lenOfOneRow += INT_BUFF_LEN; + break; + + case TSDB_DATA_TYPE_BIGINT: + case TSDB_DATA_TYPE_UBIGINT: + lenOfOneRow += BIGINT_BUFF_LEN; + break; + + case TSDB_DATA_TYPE_SMALLINT: + case TSDB_DATA_TYPE_USMALLINT: + lenOfOneRow += SMALLINT_BUFF_LEN; + break; + + case TSDB_DATA_TYPE_TINYINT: + case TSDB_DATA_TYPE_UTINYINT: + lenOfOneRow += TINYINT_BUFF_LEN; + break; + + case TSDB_DATA_TYPE_BOOL: + lenOfOneRow += BOOL_BUFF_LEN; + break; + + case TSDB_DATA_TYPE_FLOAT: + lenOfOneRow += FLOAT_BUFF_LEN; + break; + + case TSDB_DATA_TYPE_DOUBLE: + lenOfOneRow += DOUBLE_BUFF_LEN; + break; + + case TSDB_DATA_TYPE_TIMESTAMP: + lenOfOneRow += TIMESTAMP_BUFF_LEN; + break; + + default: + errorPrint("get error data type : %s\n", dataType); + exit(EXIT_FAILURE); + } + if (superTbls->iface == SML_IFACE) { + lenOfOneRow += SML_LINE_SQL_SYNTAX_OFFSET; + } + } + + superTbls->lenOfOneRow = lenOfOneRow + TIMESTAMP_BUFF_LEN; // timestamp + + int tagIndex; + int lenOfTagOfOneRow = 0; + for (tagIndex = 0; tagIndex < superTbls->tagCount; tagIndex++) { + char *dataType = superTbls->tags[tagIndex].dataType; + switch (superTbls->tags[tagIndex].data_type) { + case TSDB_DATA_TYPE_BINARY: + lenOfTagOfOneRow += superTbls->tags[tagIndex].dataLen + 3; + break; + case TSDB_DATA_TYPE_NCHAR: + lenOfTagOfOneRow += superTbls->tags[tagIndex].dataLen + 3; + break; + case TSDB_DATA_TYPE_INT: + case TSDB_DATA_TYPE_UINT: + lenOfTagOfOneRow += + superTbls->tags[tagIndex].dataLen + INT_BUFF_LEN; + break; + case TSDB_DATA_TYPE_BIGINT: + case TSDB_DATA_TYPE_UBIGINT: + lenOfTagOfOneRow += + superTbls->tags[tagIndex].dataLen + BIGINT_BUFF_LEN; + break; + case TSDB_DATA_TYPE_SMALLINT: + case TSDB_DATA_TYPE_USMALLINT: + lenOfTagOfOneRow += + superTbls->tags[tagIndex].dataLen + SMALLINT_BUFF_LEN; + break; + case TSDB_DATA_TYPE_TINYINT: + case TSDB_DATA_TYPE_UTINYINT: + lenOfTagOfOneRow += + superTbls->tags[tagIndex].dataLen + TINYINT_BUFF_LEN; + break; + case TSDB_DATA_TYPE_BOOL: + lenOfTagOfOneRow += + superTbls->tags[tagIndex].dataLen + BOOL_BUFF_LEN; + break; + case TSDB_DATA_TYPE_FLOAT: + lenOfTagOfOneRow += + superTbls->tags[tagIndex].dataLen + FLOAT_BUFF_LEN; + break; + case TSDB_DATA_TYPE_DOUBLE: + lenOfTagOfOneRow += + superTbls->tags[tagIndex].dataLen + DOUBLE_BUFF_LEN; + break; + default: + errorPrint("get error tag type : %s\n", dataType); + exit(EXIT_FAILURE); + } + if (superTbls->iface == SML_IFACE) { + lenOfOneRow += SML_LINE_SQL_SYNTAX_OFFSET; + } + } + + if (superTbls->iface == SML_IFACE) { + lenOfTagOfOneRow += + 2 * TSDB_TABLE_NAME_LEN * 2 + SML_LINE_SQL_SYNTAX_OFFSET; + superTbls->lenOfOneRow += lenOfTagOfOneRow; + } + + superTbls->lenOfTagOfOneRow = lenOfTagOfOneRow; + + return 0; +} + +static int getSuperTableFromServer(TAOS *taos, char *dbName, + SSuperTable *superTbls) { + char command[SQL_BUFF_LEN] = "\0"; + TAOS_RES *res; + TAOS_ROW row = NULL; + int count = 0; + + // get schema use cmd: describe superTblName; + snprintf(command, SQL_BUFF_LEN, "describe %s.%s", dbName, + superTbls->stbName); + res = taos_query(taos, command); + int32_t code = taos_errno(res); + if (code != 0) { + printf("failed to run command %s, reason: %s\n", command, + taos_errstr(res)); + taos_free_result(res); + return -1; + } + + int tagIndex = 0; + int columnIndex = 0; + TAOS_FIELD *fields = taos_fetch_fields(res); + while ((row = taos_fetch_row(res)) != NULL) { + if (0 == count) { + count++; + continue; + } + + if (strcmp((char *)row[TSDB_DESCRIBE_METRIC_NOTE_INDEX], "TAG") == 0) { + tstrncpy(superTbls->tags[tagIndex].field, + (char *)row[TSDB_DESCRIBE_METRIC_FIELD_INDEX], + fields[TSDB_DESCRIBE_METRIC_FIELD_INDEX].bytes); + if (0 == strncasecmp((char *)row[TSDB_DESCRIBE_METRIC_TYPE_INDEX], + "INT", strlen("INT"))) { + superTbls->tags[tagIndex].data_type = TSDB_DATA_TYPE_INT; + } else if (0 == + strncasecmp((char *)row[TSDB_DESCRIBE_METRIC_TYPE_INDEX], + "TINYINT", strlen("TINYINT"))) { + superTbls->tags[tagIndex].data_type = TSDB_DATA_TYPE_TINYINT; + } else if (0 == + strncasecmp((char *)row[TSDB_DESCRIBE_METRIC_TYPE_INDEX], + "SMALLINT", strlen("SMALLINT"))) { + superTbls->tags[tagIndex].data_type = TSDB_DATA_TYPE_SMALLINT; + } else if (0 == + strncasecmp((char *)row[TSDB_DESCRIBE_METRIC_TYPE_INDEX], + "BIGINT", strlen("BIGINT"))) { + superTbls->tags[tagIndex].data_type = TSDB_DATA_TYPE_BIGINT; + } else if (0 == + strncasecmp((char *)row[TSDB_DESCRIBE_METRIC_TYPE_INDEX], + "FLOAT", strlen("FLOAT"))) { + superTbls->tags[tagIndex].data_type = TSDB_DATA_TYPE_FLOAT; + } else if (0 == + strncasecmp((char *)row[TSDB_DESCRIBE_METRIC_TYPE_INDEX], + "DOUBLE", strlen("DOUBLE"))) { + superTbls->tags[tagIndex].data_type = TSDB_DATA_TYPE_DOUBLE; + } else if (0 == + strncasecmp((char *)row[TSDB_DESCRIBE_METRIC_TYPE_INDEX], + "BINARY", strlen("BINARY"))) { + superTbls->tags[tagIndex].data_type = TSDB_DATA_TYPE_BINARY; + } else if (0 == + strncasecmp((char *)row[TSDB_DESCRIBE_METRIC_TYPE_INDEX], + "NCHAR", strlen("NCHAR"))) { + superTbls->tags[tagIndex].data_type = TSDB_DATA_TYPE_NCHAR; + } else if (0 == + strncasecmp((char *)row[TSDB_DESCRIBE_METRIC_TYPE_INDEX], + "BOOL", strlen("BOOL"))) { + superTbls->tags[tagIndex].data_type = TSDB_DATA_TYPE_BOOL; + } else if (0 == + strncasecmp((char *)row[TSDB_DESCRIBE_METRIC_TYPE_INDEX], + "TIMESTAMP", strlen("TIMESTAMP"))) { + superTbls->tags[tagIndex].data_type = TSDB_DATA_TYPE_TIMESTAMP; + } else if (0 == + strncasecmp((char *)row[TSDB_DESCRIBE_METRIC_TYPE_INDEX], + "TINYINT UNSIGNED", + strlen("TINYINT UNSIGNED"))) { + superTbls->tags[tagIndex].data_type = TSDB_DATA_TYPE_UTINYINT; + tstrncpy(superTbls->tags[tagIndex].dataType, "UTINYINT", + min(DATATYPE_BUFF_LEN, + fields[TSDB_DESCRIBE_METRIC_TYPE_INDEX].bytes) + + 1); + } else if (0 == + strncasecmp((char *)row[TSDB_DESCRIBE_METRIC_TYPE_INDEX], + "SMALLINT UNSIGNED", + strlen("SMALLINT UNSIGNED"))) { + superTbls->tags[tagIndex].data_type = TSDB_DATA_TYPE_USMALLINT; + tstrncpy(superTbls->tags[tagIndex].dataType, "USMALLINT", + min(DATATYPE_BUFF_LEN, + fields[TSDB_DESCRIBE_METRIC_TYPE_INDEX].bytes) + + 1); + } else if (0 == + strncasecmp((char *)row[TSDB_DESCRIBE_METRIC_TYPE_INDEX], + "INT UNSIGNED", strlen("INT UNSIGNED"))) { + superTbls->tags[tagIndex].data_type = TSDB_DATA_TYPE_UINT; + tstrncpy(superTbls->tags[tagIndex].dataType, "UINT", + min(DATATYPE_BUFF_LEN, + fields[TSDB_DESCRIBE_METRIC_TYPE_INDEX].bytes) + + 1); + } else if (0 == strncasecmp( + (char *)row[TSDB_DESCRIBE_METRIC_TYPE_INDEX], + "BIGINT UNSIGNED", strlen("BIGINT UNSIGNED"))) { + superTbls->tags[tagIndex].data_type = TSDB_DATA_TYPE_UBIGINT; + tstrncpy(superTbls->tags[tagIndex].dataType, "UBIGINT", + min(DATATYPE_BUFF_LEN, + fields[TSDB_DESCRIBE_METRIC_TYPE_INDEX].bytes) + + 1); + } else { + superTbls->tags[tagIndex].data_type = TSDB_DATA_TYPE_NULL; + } + superTbls->tags[tagIndex].dataLen = + *((int *)row[TSDB_DESCRIBE_METRIC_LENGTH_INDEX]); + tstrncpy(superTbls->tags[tagIndex].note, + (char *)row[TSDB_DESCRIBE_METRIC_NOTE_INDEX], + min(NOTE_BUFF_LEN, + fields[TSDB_DESCRIBE_METRIC_NOTE_INDEX].bytes) + + 1); + if (strstr((char *)row[TSDB_DESCRIBE_METRIC_TYPE_INDEX], + "UNSIGNED") == NULL) { + tstrncpy(superTbls->tags[tagIndex].dataType, + (char *)row[TSDB_DESCRIBE_METRIC_TYPE_INDEX], + min(DATATYPE_BUFF_LEN, + fields[TSDB_DESCRIBE_METRIC_TYPE_INDEX].bytes) + + 1); + } + tagIndex++; + } else { + tstrncpy(superTbls->columns[columnIndex].field, + (char *)row[TSDB_DESCRIBE_METRIC_FIELD_INDEX], + fields[TSDB_DESCRIBE_METRIC_FIELD_INDEX].bytes); + + if (0 == strncasecmp((char *)row[TSDB_DESCRIBE_METRIC_TYPE_INDEX], + "INT", strlen("INT")) && + strstr((char *)row[TSDB_DESCRIBE_METRIC_TYPE_INDEX], + "UNSIGNED") == NULL) { + superTbls->columns[columnIndex].data_type = TSDB_DATA_TYPE_INT; + } else if (0 == strncasecmp( + (char *)row[TSDB_DESCRIBE_METRIC_TYPE_INDEX], + "TINYINT", strlen("TINYINT")) && + strstr((char *)row[TSDB_DESCRIBE_METRIC_TYPE_INDEX], + "UNSIGNED") == NULL) { + superTbls->columns[columnIndex].data_type = + TSDB_DATA_TYPE_TINYINT; + } else if (0 == strncasecmp( + (char *)row[TSDB_DESCRIBE_METRIC_TYPE_INDEX], + "SMALLINT", strlen("SMALLINT")) && + strstr((char *)row[TSDB_DESCRIBE_METRIC_TYPE_INDEX], + "UNSIGNED") == NULL) { + superTbls->columns[columnIndex].data_type = + TSDB_DATA_TYPE_SMALLINT; + } else if (0 == strncasecmp( + (char *)row[TSDB_DESCRIBE_METRIC_TYPE_INDEX], + "BIGINT", strlen("BIGINT")) && + strstr((char *)row[TSDB_DESCRIBE_METRIC_TYPE_INDEX], + "UNSIGNED") == NULL) { + superTbls->columns[columnIndex].data_type = + TSDB_DATA_TYPE_BIGINT; + } else if (0 == + strncasecmp((char *)row[TSDB_DESCRIBE_METRIC_TYPE_INDEX], + "FLOAT", strlen("FLOAT"))) { + superTbls->columns[columnIndex].data_type = + TSDB_DATA_TYPE_FLOAT; + } else if (0 == + strncasecmp((char *)row[TSDB_DESCRIBE_METRIC_TYPE_INDEX], + "DOUBLE", strlen("DOUBLE"))) { + superTbls->columns[columnIndex].data_type = + TSDB_DATA_TYPE_DOUBLE; + } else if (0 == + strncasecmp((char *)row[TSDB_DESCRIBE_METRIC_TYPE_INDEX], + "BINARY", strlen("BINARY"))) { + superTbls->columns[columnIndex].data_type = + TSDB_DATA_TYPE_BINARY; + } else if (0 == + strncasecmp((char *)row[TSDB_DESCRIBE_METRIC_TYPE_INDEX], + "NCHAR", strlen("NCHAR"))) { + superTbls->columns[columnIndex].data_type = + TSDB_DATA_TYPE_NCHAR; + } else if (0 == + strncasecmp((char *)row[TSDB_DESCRIBE_METRIC_TYPE_INDEX], + "BOOL", strlen("BOOL"))) { + superTbls->columns[columnIndex].data_type = TSDB_DATA_TYPE_BOOL; + } else if (0 == + strncasecmp((char *)row[TSDB_DESCRIBE_METRIC_TYPE_INDEX], + "TIMESTAMP", strlen("TIMESTAMP"))) { + superTbls->columns[columnIndex].data_type = + TSDB_DATA_TYPE_TIMESTAMP; + } else if (0 == + strncasecmp((char *)row[TSDB_DESCRIBE_METRIC_TYPE_INDEX], + "TINYINT UNSIGNED", + strlen("TINYINT UNSIGNED"))) { + superTbls->columns[columnIndex].data_type = + TSDB_DATA_TYPE_UTINYINT; + tstrncpy(superTbls->columns[columnIndex].dataType, "UTINYINT", + min(DATATYPE_BUFF_LEN, + fields[TSDB_DESCRIBE_METRIC_TYPE_INDEX].bytes) + + 1); + } else if (0 == + strncasecmp((char *)row[TSDB_DESCRIBE_METRIC_TYPE_INDEX], + "SMALLINT UNSIGNED", + strlen("SMALLINT UNSIGNED"))) { + superTbls->columns[columnIndex].data_type = + TSDB_DATA_TYPE_USMALLINT; + tstrncpy(superTbls->columns[columnIndex].dataType, "USMALLINT", + min(DATATYPE_BUFF_LEN, + fields[TSDB_DESCRIBE_METRIC_TYPE_INDEX].bytes) + + 1); + } else if (0 == + strncasecmp((char *)row[TSDB_DESCRIBE_METRIC_TYPE_INDEX], + "INT UNSIGNED", strlen("INT UNSIGNED"))) { + superTbls->columns[columnIndex].data_type = TSDB_DATA_TYPE_UINT; + tstrncpy(superTbls->columns[columnIndex].dataType, "UINT", + min(DATATYPE_BUFF_LEN, + fields[TSDB_DESCRIBE_METRIC_TYPE_INDEX].bytes) + + 1); + } else if (0 == strncasecmp( + (char *)row[TSDB_DESCRIBE_METRIC_TYPE_INDEX], + "BIGINT UNSIGNED", strlen("BIGINT UNSIGNED"))) { + superTbls->columns[columnIndex].data_type = + TSDB_DATA_TYPE_UBIGINT; + tstrncpy(superTbls->columns[columnIndex].dataType, "UBIGINT", + min(DATATYPE_BUFF_LEN, + fields[TSDB_DESCRIBE_METRIC_TYPE_INDEX].bytes) + + 1); + } else { + superTbls->columns[columnIndex].data_type = TSDB_DATA_TYPE_NULL; + } + superTbls->columns[columnIndex].dataLen = + *((int *)row[TSDB_DESCRIBE_METRIC_LENGTH_INDEX]); + tstrncpy(superTbls->columns[columnIndex].note, + (char *)row[TSDB_DESCRIBE_METRIC_NOTE_INDEX], + min(NOTE_BUFF_LEN, + fields[TSDB_DESCRIBE_METRIC_NOTE_INDEX].bytes) + + 1); + + if (strstr((char *)row[TSDB_DESCRIBE_METRIC_TYPE_INDEX], + "UNSIGNED") == NULL) { + tstrncpy(superTbls->columns[columnIndex].dataType, + (char *)row[TSDB_DESCRIBE_METRIC_TYPE_INDEX], + min(DATATYPE_BUFF_LEN, + fields[TSDB_DESCRIBE_METRIC_TYPE_INDEX].bytes) + + 1); + } + + columnIndex++; + } + count++; + } + + superTbls->columnCount = columnIndex; + superTbls->tagCount = tagIndex; + taos_free_result(res); + + calcRowLen(superTbls); + return 0; +} + +static int createSuperTable(TAOS *taos, char *dbName, SSuperTable *superTbl, + char *command) { + char cols[COL_BUFFER_LEN] = "\0"; + int len = 0; + + int lenOfOneRow = 0; + + if (superTbl->columnCount == 0) { + errorPrint("super table column count is %d\n", superTbl->columnCount); + return -1; + } + + for (int colIndex = 0; colIndex < superTbl->columnCount; colIndex++) { + switch (superTbl->columns[colIndex].data_type) { + case TSDB_DATA_TYPE_BINARY: + len += snprintf(cols + len, COL_BUFFER_LEN - len, ",C%d %s(%d)", + colIndex, "BINARY", + superTbl->columns[colIndex].dataLen); + lenOfOneRow += superTbl->columns[colIndex].dataLen + 3; + break; + + case TSDB_DATA_TYPE_NCHAR: + len += snprintf(cols + len, COL_BUFFER_LEN - len, ",C%d %s(%d)", + colIndex, "NCHAR", + superTbl->columns[colIndex].dataLen); + lenOfOneRow += superTbl->columns[colIndex].dataLen + 3; + break; + + case TSDB_DATA_TYPE_INT: + if ((g_args.demo_mode) && (colIndex == 1)) { + len += snprintf(cols + len, COL_BUFFER_LEN - len, + ", VOLTAGE INT"); + } else { + len += snprintf(cols + len, COL_BUFFER_LEN - len, ",C%d %s", + colIndex, "INT"); + } + lenOfOneRow += INT_BUFF_LEN; + break; + + case TSDB_DATA_TYPE_BIGINT: + len += snprintf(cols + len, COL_BUFFER_LEN - len, ",C%d %s", + colIndex, "BIGINT"); + lenOfOneRow += BIGINT_BUFF_LEN; + break; + + case TSDB_DATA_TYPE_SMALLINT: + len += snprintf(cols + len, COL_BUFFER_LEN - len, ",C%d %s", + colIndex, "SMALLINT"); + lenOfOneRow += SMALLINT_BUFF_LEN; + break; + + case TSDB_DATA_TYPE_TINYINT: + len += snprintf(cols + len, COL_BUFFER_LEN - len, ",C%d %s", + colIndex, "TINYINT"); + lenOfOneRow += TINYINT_BUFF_LEN; + break; + + case TSDB_DATA_TYPE_BOOL: + len += snprintf(cols + len, COL_BUFFER_LEN - len, ",C%d %s", + colIndex, "BOOL"); + lenOfOneRow += BOOL_BUFF_LEN; + break; + + case TSDB_DATA_TYPE_FLOAT: + if (g_args.demo_mode) { + if (colIndex == 0) { + len += snprintf(cols + len, COL_BUFFER_LEN - len, + ", CURRENT FLOAT"); + } else if (colIndex == 2) { + len += snprintf(cols + len, COL_BUFFER_LEN - len, + ", PHASE FLOAT"); + } + } else { + len += snprintf(cols + len, COL_BUFFER_LEN - len, ",C%d %s", + colIndex, "FLOAT"); + } + + lenOfOneRow += FLOAT_BUFF_LEN; + break; + + case TSDB_DATA_TYPE_DOUBLE: + len += snprintf(cols + len, COL_BUFFER_LEN - len, ",C%d %s", + colIndex, "DOUBLE"); + lenOfOneRow += DOUBLE_BUFF_LEN; + break; + + case TSDB_DATA_TYPE_TIMESTAMP: + len += snprintf(cols + len, COL_BUFFER_LEN - len, ",C%d %s", + colIndex, "TIMESTAMP"); + lenOfOneRow += TIMESTAMP_BUFF_LEN; + break; + + case TSDB_DATA_TYPE_UTINYINT: + len += snprintf(cols + len, COL_BUFFER_LEN - len, ",C%d %s", + colIndex, "TINYINT UNSIGNED"); + lenOfOneRow += TINYINT_BUFF_LEN; + break; + + case TSDB_DATA_TYPE_USMALLINT: + len += snprintf(cols + len, COL_BUFFER_LEN - len, ",C%d %s", + colIndex, "SMALLINT UNSIGNED"); + lenOfOneRow += SMALLINT_BUFF_LEN; + break; + + case TSDB_DATA_TYPE_UINT: + len += snprintf(cols + len, COL_BUFFER_LEN - len, ",C%d %s", + colIndex, "INT UNSIGNED"); + lenOfOneRow += INT_BUFF_LEN; + break; + + case TSDB_DATA_TYPE_UBIGINT: + len += snprintf(cols + len, COL_BUFFER_LEN - len, ",C%d %s", + colIndex, "BIGINT UNSIGNED"); + lenOfOneRow += BIGINT_BUFF_LEN; + break; + + default: + taos_close(taos); + errorPrint("config error data type : %s\n", + superTbl->columns[colIndex].dataType); + return -1; + } + } + + superTbl->lenOfOneRow = lenOfOneRow + TIMESTAMP_BUFF_LEN; // timestamp + + // save for creating child table + superTbl->colsOfCreateChildTable = + (char *)calloc(len + TIMESTAMP_BUFF_LEN, 1); + if (NULL == superTbl->colsOfCreateChildTable) { + taos_close(taos); + errorPrint("%s", "failed to allocate memory\n"); + return -1; + } + + snprintf(superTbl->colsOfCreateChildTable, len + TIMESTAMP_BUFF_LEN, + "(ts timestamp%s)", cols); + verbosePrint("%s() LN%d: %s\n", __func__, __LINE__, + superTbl->colsOfCreateChildTable); + + if (superTbl->tagCount == 0) { + errorPrint("super table tag count is %d\n", superTbl->tagCount); + return -1; + } + + char tags[TSDB_MAX_TAGS_LEN] = "\0"; + int tagIndex; + len = 0; + + int lenOfTagOfOneRow = 0; + len += snprintf(tags + len, TSDB_MAX_TAGS_LEN - len, "("); + for (tagIndex = 0; tagIndex < superTbl->tagCount; tagIndex++) { + char *dataType = superTbl->tags[tagIndex].dataType; + + if (strcasecmp(dataType, "BINARY") == 0) { + if ((g_args.demo_mode) && (tagIndex == 1)) { + len += snprintf(tags + len, TSDB_MAX_TAGS_LEN - len, + "location BINARY(%d),", + superTbl->tags[tagIndex].dataLen); + } else { + len += snprintf(tags + len, TSDB_MAX_TAGS_LEN - len, + "T%d %s(%d),", tagIndex, "BINARY", + superTbl->tags[tagIndex].dataLen); + } + lenOfTagOfOneRow += superTbl->tags[tagIndex].dataLen + 3; + } else if (strcasecmp(dataType, "NCHAR") == 0) { + len += + snprintf(tags + len, TSDB_MAX_TAGS_LEN - len, "T%d %s(%d),", + tagIndex, "NCHAR", superTbl->tags[tagIndex].dataLen); + lenOfTagOfOneRow += superTbl->tags[tagIndex].dataLen + 3; + } else if (strcasecmp(dataType, "INT") == 0) { + if ((g_args.demo_mode) && (tagIndex == 0)) { + len += snprintf(tags + len, TSDB_MAX_TAGS_LEN - len, + "groupId INT, "); + } else { + len += snprintf(tags + len, TSDB_MAX_TAGS_LEN - len, "T%d %s,", + tagIndex, "INT"); + } + lenOfTagOfOneRow += superTbl->tags[tagIndex].dataLen + INT_BUFF_LEN; + } else if (strcasecmp(dataType, "BIGINT") == 0) { + len += snprintf(tags + len, TSDB_MAX_TAGS_LEN - len, "T%d %s,", + tagIndex, "BIGINT"); + lenOfTagOfOneRow += + superTbl->tags[tagIndex].dataLen + BIGINT_BUFF_LEN; + } else if (strcasecmp(dataType, "SMALLINT") == 0) { + len += snprintf(tags + len, TSDB_MAX_TAGS_LEN - len, "T%d %s,", + tagIndex, "SMALLINT"); + lenOfTagOfOneRow += + superTbl->tags[tagIndex].dataLen + SMALLINT_BUFF_LEN; + } else if (strcasecmp(dataType, "TINYINT") == 0) { + len += snprintf(tags + len, TSDB_MAX_TAGS_LEN - len, "T%d %s,", + tagIndex, "TINYINT"); + lenOfTagOfOneRow += + superTbl->tags[tagIndex].dataLen + TINYINT_BUFF_LEN; + } else if (strcasecmp(dataType, "BOOL") == 0) { + len += snprintf(tags + len, TSDB_MAX_TAGS_LEN - len, "T%d %s,", + tagIndex, "BOOL"); + lenOfTagOfOneRow += + superTbl->tags[tagIndex].dataLen + BOOL_BUFF_LEN; + } else if (strcasecmp(dataType, "FLOAT") == 0) { + len += snprintf(tags + len, TSDB_MAX_TAGS_LEN - len, "T%d %s,", + tagIndex, "FLOAT"); + lenOfTagOfOneRow += + superTbl->tags[tagIndex].dataLen + FLOAT_BUFF_LEN; + } else if (strcasecmp(dataType, "DOUBLE") == 0) { + len += snprintf(tags + len, TSDB_MAX_TAGS_LEN - len, "T%d %s,", + tagIndex, "DOUBLE"); + lenOfTagOfOneRow += + superTbl->tags[tagIndex].dataLen + DOUBLE_BUFF_LEN; + } else if (strcasecmp(dataType, "UTINYINT") == 0) { + len += snprintf(tags + len, TSDB_MAX_TAGS_LEN - len, "T%d %s,", + tagIndex, "TINYINT UNSIGNED"); + lenOfTagOfOneRow += + superTbl->tags[tagIndex].dataLen + TINYINT_BUFF_LEN; + } else if (strcasecmp(dataType, "USMALLINT") == 0) { + len += snprintf(tags + len, TSDB_MAX_TAGS_LEN - len, "T%d %s,", + tagIndex, "SMALLINT UNSIGNED"); + lenOfTagOfOneRow += + superTbl->tags[tagIndex].dataLen + SMALLINT_BUFF_LEN; + } else if (strcasecmp(dataType, "UINT") == 0) { + len += snprintf(tags + len, TSDB_MAX_TAGS_LEN - len, "T%d %s,", + tagIndex, "INT UNSIGNED"); + lenOfTagOfOneRow += superTbl->tags[tagIndex].dataLen + INT_BUFF_LEN; + } else if (strcasecmp(dataType, "UBIGINT") == 0) { + len += snprintf(tags + len, TSDB_MAX_TAGS_LEN - len, "T%d %s,", + tagIndex, "BIGINT UNSIGNED"); + lenOfTagOfOneRow += + superTbl->tags[tagIndex].dataLen + BIGINT_BUFF_LEN; + } else if (strcasecmp(dataType, "TIMESTAMP") == 0) { + len += snprintf(tags + len, TSDB_MAX_TAGS_LEN - len, "T%d %s,", + tagIndex, "TIMESTAMP"); + lenOfTagOfOneRow += + superTbl->tags[tagIndex].dataLen + TIMESTAMP_BUFF_LEN; + } else { + taos_close(taos); + errorPrint("config error tag type : %s\n", dataType); + return -1; + } + } + + len -= 1; + len += snprintf(tags + len, TSDB_MAX_TAGS_LEN - len, ")"); + + superTbl->lenOfTagOfOneRow = lenOfTagOfOneRow; + + snprintf(command, BUFFER_SIZE, + superTbl->escapeChar + ? "CREATE TABLE IF NOT EXISTS %s.`%s` (ts TIMESTAMP%s) TAGS %s" + : "CREATE TABLE IF NOT EXISTS %s.%s (ts TIMESTAMP%s) TAGS %s", + dbName, superTbl->stbName, cols, tags); + if (0 != queryDbExec(taos, command, NO_INSERT_TYPE, false)) { + errorPrint("create supertable %s failed!\n\n", superTbl->stbName); + return -1; + } + + debugPrint("create supertable %s success!\n\n", superTbl->stbName); + return 0; +} + +int createDatabasesAndStables(char *command) { + TAOS *taos = NULL; + int ret = 0; + taos = + taos_connect(g_Dbs.host, g_Dbs.user, g_Dbs.password, NULL, g_Dbs.port); + if (taos == NULL) { + errorPrint("Failed to connect to TDengine, reason:%s\n", + taos_errstr(NULL)); + return -1; + } + + for (int i = 0; i < g_Dbs.dbCount; i++) { + if (g_Dbs.db[i].drop) { + sprintf(command, "drop database if exists %s;", g_Dbs.db[i].dbName); + if (0 != queryDbExec(taos, command, NO_INSERT_TYPE, false)) { + taos_close(taos); + return -1; + } + + int dataLen = 0; + dataLen += snprintf(command + dataLen, BUFFER_SIZE - dataLen, + "CREATE DATABASE IF NOT EXISTS %s", + g_Dbs.db[i].dbName); + + if (g_Dbs.db[i].dbCfg.blocks > 0) { + dataLen += snprintf(command + dataLen, BUFFER_SIZE - dataLen, + " BLOCKS %d", g_Dbs.db[i].dbCfg.blocks); + } + if (g_Dbs.db[i].dbCfg.cache > 0) { + dataLen += snprintf(command + dataLen, BUFFER_SIZE - dataLen, + " CACHE %d", g_Dbs.db[i].dbCfg.cache); + } + if (g_Dbs.db[i].dbCfg.days > 0) { + dataLen += snprintf(command + dataLen, BUFFER_SIZE - dataLen, + " DAYS %d", g_Dbs.db[i].dbCfg.days); + } + if (g_Dbs.db[i].dbCfg.keep > 0) { + dataLen += snprintf(command + dataLen, BUFFER_SIZE - dataLen, + " KEEP %d", g_Dbs.db[i].dbCfg.keep); + } + if (g_Dbs.db[i].dbCfg.quorum > 1) { + dataLen += snprintf(command + dataLen, BUFFER_SIZE - dataLen, + " QUORUM %d", g_Dbs.db[i].dbCfg.quorum); + } + if (g_Dbs.db[i].dbCfg.replica > 0) { + dataLen += snprintf(command + dataLen, BUFFER_SIZE - dataLen, + " REPLICA %d", g_Dbs.db[i].dbCfg.replica); + } + if (g_Dbs.db[i].dbCfg.update > 0) { + dataLen += snprintf(command + dataLen, BUFFER_SIZE - dataLen, + " UPDATE %d", g_Dbs.db[i].dbCfg.update); + } + // if (g_Dbs.db[i].dbCfg.maxtablesPerVnode > 0) { + // dataLen += snprintf(command + dataLen, + // BUFFER_SIZE - dataLen, "tables %d ", + // g_Dbs.db[i].dbCfg.maxtablesPerVnode); + //} + if (g_Dbs.db[i].dbCfg.minRows > 0) { + dataLen += snprintf(command + dataLen, BUFFER_SIZE - dataLen, + " MINROWS %d", g_Dbs.db[i].dbCfg.minRows); + } + if (g_Dbs.db[i].dbCfg.maxRows > 0) { + dataLen += snprintf(command + dataLen, BUFFER_SIZE - dataLen, + " MAXROWS %d", g_Dbs.db[i].dbCfg.maxRows); + } + if (g_Dbs.db[i].dbCfg.comp > 0) { + dataLen += snprintf(command + dataLen, BUFFER_SIZE - dataLen, + " COMP %d", g_Dbs.db[i].dbCfg.comp); + } + if (g_Dbs.db[i].dbCfg.walLevel > 0) { + dataLen += snprintf(command + dataLen, BUFFER_SIZE - dataLen, + " wal %d", g_Dbs.db[i].dbCfg.walLevel); + } + if (g_Dbs.db[i].dbCfg.cacheLast > 0) { + dataLen += + snprintf(command + dataLen, BUFFER_SIZE - dataLen, + " CACHELAST %d", g_Dbs.db[i].dbCfg.cacheLast); + } + if (g_Dbs.db[i].dbCfg.fsync > 0) { + dataLen += snprintf(command + dataLen, BUFFER_SIZE - dataLen, + " FSYNC %d", g_Dbs.db[i].dbCfg.fsync); + } + if ((0 == strncasecmp(g_Dbs.db[i].dbCfg.precision, "ms", 2)) || + (0 == strncasecmp(g_Dbs.db[i].dbCfg.precision, "ns", 2)) || + (0 == strncasecmp(g_Dbs.db[i].dbCfg.precision, "us", 2))) { + dataLen += + snprintf(command + dataLen, BUFFER_SIZE - dataLen, + " precision \'%s\';", g_Dbs.db[i].dbCfg.precision); + } + + if (0 != queryDbExec(taos, command, NO_INSERT_TYPE, false)) { + taos_close(taos); + errorPrint("\ncreate database %s failed!\n\n", + g_Dbs.db[i].dbName); + return -1; + } + printf("\ncreate database %s success!\n\n", g_Dbs.db[i].dbName); + } + + debugPrint("%s() LN%d supertbl count:%" PRIu64 "\n", __func__, __LINE__, + g_Dbs.db[i].superTblCount); + + int validStbCount = 0; + + for (uint64_t j = 0; j < g_Dbs.db[i].superTblCount; j++) { + if (g_Dbs.db[i].superTbls[j].iface == SML_IFACE) { + goto skip; + } + + sprintf(command, "describe %s.%s;", g_Dbs.db[i].dbName, + g_Dbs.db[i].superTbls[j].stbName); + ret = queryDbExec(taos, command, NO_INSERT_TYPE, true); + + if ((ret != 0) || (g_Dbs.db[i].drop)) { + char *cmd = calloc(1, BUFFER_SIZE); + if (NULL == cmd) { + errorPrint("%s", "failed to allocate memory\n"); + return -1; + } + + ret = createSuperTable(taos, g_Dbs.db[i].dbName, + &g_Dbs.db[i].superTbls[j], cmd); + tmfree(cmd); + + if (0 != ret) { + errorPrint("create super table %" PRIu64 " failed!\n\n", j); + continue; + } + } else { + ret = getSuperTableFromServer(taos, g_Dbs.db[i].dbName, + &g_Dbs.db[i].superTbls[j]); + if (0 != ret) { + errorPrint("\nget super table %s.%s info failed!\n\n", + g_Dbs.db[i].dbName, + g_Dbs.db[i].superTbls[j].stbName); + continue; + } + } + skip: + validStbCount++; + } + g_Dbs.db[i].superTblCount = validStbCount; + } + + taos_close(taos); + return 0; +} + +static void *createTable(void *sarg) { + threadInfo * pThreadInfo = (threadInfo *)sarg; + SSuperTable *stbInfo = pThreadInfo->stbInfo; + + setThreadName("createTable"); + + uint64_t lastPrintTime = taosGetTimestampMs(); + + int buff_len = BUFFER_SIZE; + + pThreadInfo->buffer = calloc(1, buff_len); + if (NULL == pThreadInfo->buffer) { + errorPrint("%s", "failed to allocate memory\n"); + return NULL; + } + + int len = 0; + int batchNum = 0; + + verbosePrint("%s() LN%d: Creating table from %" PRIu64 " to %" PRIu64 "\n", + __func__, __LINE__, pThreadInfo->start_table_from, + pThreadInfo->end_table_to); + + for (uint64_t i = pThreadInfo->start_table_from; + i <= pThreadInfo->end_table_to; i++) { + if (0 == g_Dbs.use_metric) { + snprintf(pThreadInfo->buffer, buff_len, + g_args.escapeChar + ? "CREATE TABLE IF NOT EXISTS %s.`%s%" PRIu64 "` %s;" + : "CREATE TABLE IF NOT EXISTS %s.%s%" PRIu64 " %s;", + pThreadInfo->db_name, g_args.tb_prefix, i, + pThreadInfo->cols); + batchNum++; + } else { + if (stbInfo == NULL) { + free(pThreadInfo->buffer); + errorPrint( + "%s() LN%d, use metric, but super table info is NULL\n", + __func__, __LINE__); + exit(EXIT_FAILURE); + } else { + if (0 == len) { + batchNum = 0; + memset(pThreadInfo->buffer, 0, buff_len); + len += snprintf(pThreadInfo->buffer + len, buff_len - len, + "CREATE TABLE "); + } + + char *tagsValBuf = (char *)calloc(TSDB_MAX_SQL_LEN + 1, 1); + if (NULL == tagsValBuf) { + errorPrint("%s", "failed to allocate memory\n"); + return NULL; + } + + if (0 == stbInfo->tagSource) { + if (generateTagValuesForStb(stbInfo, i, tagsValBuf)) { + tmfree(tagsValBuf); + tmfree(pThreadInfo->buffer); + exit(EXIT_FAILURE); + } + } else { + snprintf(tagsValBuf, TSDB_MAX_SQL_LEN, "(%s)", + stbInfo->tagDataBuf + + stbInfo->lenOfTagOfOneRow * + (i % stbInfo->tagSampleCount)); + } + len += snprintf( + pThreadInfo->buffer + len, buff_len - len, + stbInfo->escapeChar ? "if not exists %s.`%s%" PRIu64 + "` using %s.`%s` tags %s " + : "if not exists %s.%s%" PRIu64 + " using %s.%s tags %s ", + pThreadInfo->db_name, stbInfo->childTblPrefix, i, + pThreadInfo->db_name, stbInfo->stbName, tagsValBuf); + tmfree(tagsValBuf); + batchNum++; + if ((batchNum < stbInfo->batchCreateTableNum) && + ((buff_len - len) >= + (stbInfo->lenOfTagOfOneRow + EXTRA_SQL_LEN))) { + continue; + } + } + } + + len = 0; + + if (0 != queryDbExec(pThreadInfo->taos, pThreadInfo->buffer, + NO_INSERT_TYPE, false)) { + errorPrint("queryDbExec() failed. buffer:\n%s\n", + pThreadInfo->buffer); + free(pThreadInfo->buffer); + return NULL; + } + pThreadInfo->tables_created += batchNum; + uint64_t currentPrintTime = taosGetTimestampMs(); + if (currentPrintTime - lastPrintTime > PRINT_STAT_INTERVAL) { + printf("thread[%d] already create %" PRIu64 " - %" PRIu64 + " tables\n", + pThreadInfo->threadID, pThreadInfo->start_table_from, i); + lastPrintTime = currentPrintTime; + } + } + + if (0 != len) { + if (0 != queryDbExec(pThreadInfo->taos, pThreadInfo->buffer, + NO_INSERT_TYPE, false)) { + errorPrint("queryDbExec() failed. buffer:\n%s\n", + pThreadInfo->buffer); + } + pThreadInfo->tables_created += batchNum; + } + free(pThreadInfo->buffer); + return NULL; +} + +int startMultiThreadCreateChildTable(char *cols, int threads, + uint64_t tableFrom, int64_t ntables, + char *db_name, SSuperTable *stbInfo) { + pthread_t *pids = calloc(1, threads * sizeof(pthread_t)); + if (NULL == pids) { + errorPrint("%s", "failed to allocate memory\n"); + return -1; + } + threadInfo *infos = calloc(1, threads * sizeof(threadInfo)); + if (NULL == infos) { + errorPrint("%s", "failed to allocate memory\n"); + tmfree(pids); + return -1; + } + + if (threads < 1) { + threads = 1; + } + + int64_t a = ntables / threads; + if (a < 1) { + threads = (int)ntables; + a = 1; + } + + int64_t b = 0; + b = ntables % threads; + + for (int64_t i = 0; i < threads; i++) { + threadInfo *pThreadInfo = infos + i; + pThreadInfo->threadID = (int)i; + tstrncpy(pThreadInfo->db_name, db_name, TSDB_DB_NAME_LEN); + pThreadInfo->stbInfo = stbInfo; + verbosePrint("%s() %d db_name: %s\n", __func__, __LINE__, db_name); + pThreadInfo->taos = taos_connect(g_Dbs.host, g_Dbs.user, g_Dbs.password, + db_name, g_Dbs.port); + if (pThreadInfo->taos == NULL) { + errorPrint("failed to connect to TDengine, reason:%s\n", + taos_errstr(NULL)); + free(pids); + free(infos); + return -1; + } + + pThreadInfo->start_table_from = tableFrom; + pThreadInfo->ntables = i < b ? a + 1 : a; + pThreadInfo->end_table_to = i < b ? tableFrom + a : tableFrom + a - 1; + tableFrom = pThreadInfo->end_table_to + 1; + pThreadInfo->use_metric = true; + pThreadInfo->cols = cols; + pThreadInfo->minDelay = UINT64_MAX; + pThreadInfo->tables_created = 0; + pthread_create(pids + i, NULL, createTable, pThreadInfo); + } + + for (int i = 0; i < threads; i++) { + pthread_join(pids[i], NULL); + } + + for (int i = 0; i < threads; i++) { + threadInfo *pThreadInfo = infos + i; + taos_close(pThreadInfo->taos); + + g_actualChildTables += pThreadInfo->tables_created; + } + + free(pids); + free(infos); + + return 0; +} + +int createChildTables() { + int32_t code = 0; + fprintf(stderr, "creating %" PRId64 " table(s) with %d thread(s)\n\n", + g_totalChildTables, g_Dbs.threadCountForCreateTbl); + if (g_fpOfInsertResult) { + fprintf(g_fpOfInsertResult, + "creating %" PRId64 " table(s) with %d thread(s)\n\n", + g_totalChildTables, g_Dbs.threadCountForCreateTbl); + } + double start = (double)taosGetTimestampMs(); + char tblColsBuf[TSDB_MAX_BYTES_PER_ROW]; + int len; + + for (int i = 0; i < g_Dbs.dbCount; i++) { + if (g_Dbs.use_metric) { + if (g_Dbs.db[i].superTblCount > 0) { + // with super table + for (int j = 0; j < g_Dbs.db[i].superTblCount; j++) { + if ((AUTO_CREATE_SUBTBL == + g_Dbs.db[i].superTbls[j].autoCreateTable) || + (TBL_ALREADY_EXISTS == + g_Dbs.db[i].superTbls[j].childTblExists)) { + continue; + } + verbosePrint( + "%s() LN%d: %s\n", __func__, __LINE__, + g_Dbs.db[i].superTbls[j].colsOfCreateChildTable); + uint64_t startFrom = 0; + + verbosePrint("%s() LN%d: create %" PRId64 + " child tables from %" PRIu64 "\n", + __func__, __LINE__, g_totalChildTables, + startFrom); + + code = startMultiThreadCreateChildTable( + g_Dbs.db[i].superTbls[j].colsOfCreateChildTable, + g_Dbs.threadCountForCreateTbl, startFrom, + g_Dbs.db[i].superTbls[j].childTblCount, + g_Dbs.db[i].dbName, &(g_Dbs.db[i].superTbls[j])); + if (code) { + errorPrint( + "%s() LN%d, startMultiThreadCreateChildTable() " + "failed for db %d stable %d\n", + __func__, __LINE__, i, j); + return code; + } + } + } + } else { + // normal table + len = snprintf(tblColsBuf, TSDB_MAX_BYTES_PER_ROW, "(TS TIMESTAMP"); + for (int j = 0; j < g_args.columnCount; j++) { + if ((strncasecmp(g_args.dataType[j], "BINARY", + strlen("BINARY")) == 0) || + (strncasecmp(g_args.dataType[j], "NCHAR", + strlen("NCHAR")) == 0)) { + snprintf(tblColsBuf + len, TSDB_MAX_BYTES_PER_ROW - len, + ",C%d %s(%d)", j, g_args.dataType[j], + g_args.binwidth); + } else { + snprintf(tblColsBuf + len, TSDB_MAX_BYTES_PER_ROW - len, + ",C%d %s", j, g_args.dataType[j]); + } + len = (int)strlen(tblColsBuf); + } + + snprintf(tblColsBuf + len, TSDB_MAX_BYTES_PER_ROW - len, ")"); + + verbosePrint("%s() LN%d: dbName: %s num of tb: %" PRId64 + " schema: %s\n", + __func__, __LINE__, g_Dbs.db[i].dbName, g_args.ntables, + tblColsBuf); + code = startMultiThreadCreateChildTable( + tblColsBuf, g_Dbs.threadCountForCreateTbl, 0, g_args.ntables, + g_Dbs.db[i].dbName, NULL); + if (code) { + errorPrint( + "%s() LN%d, startMultiThreadCreateChildTable() " + "failed\n", + __func__, __LINE__); + return code; + } + } + } + double end = (double)taosGetTimestampMs(); + fprintf(stderr, + "\nSpent %.4f seconds to create %" PRId64 + " table(s) with %d thread(s), actual %" PRId64 + " table(s) created\n\n", + (end - start) / 1000.0, g_totalChildTables, + g_Dbs.threadCountForCreateTbl, g_actualChildTables); + if (g_fpOfInsertResult) { + fprintf(g_fpOfInsertResult, + "\nSpent %.4f seconds to create %" PRId64 + " table(s) with %d thread(s), actual %" PRId64 + " table(s) created\n\n", + (end - start) / 1000.0, g_totalChildTables, + g_Dbs.threadCountForCreateTbl, g_actualChildTables); + } + return code; +} + +void postFreeResource() { + tmfclose(g_fpOfInsertResult); + tmfree(g_dupstr); + for (int i = 0; i < g_Dbs.dbCount; i++) { + for (uint64_t j = 0; j < g_Dbs.db[i].superTblCount; j++) { + if (0 != g_Dbs.db[i].superTbls[j].colsOfCreateChildTable) { + tmfree(g_Dbs.db[i].superTbls[j].colsOfCreateChildTable); + g_Dbs.db[i].superTbls[j].colsOfCreateChildTable = NULL; + } + if (0 != g_Dbs.db[i].superTbls[j].sampleDataBuf) { + tmfree(g_Dbs.db[i].superTbls[j].sampleDataBuf); + g_Dbs.db[i].superTbls[j].sampleDataBuf = NULL; + } + + for (int c = 0; c < g_Dbs.db[i].superTbls[j].columnCount; c++) { + if (g_Dbs.db[i].superTbls[j].sampleBindBatchArray) { + tmfree((char *)((uintptr_t) * + (uintptr_t *)(g_Dbs.db[i] + .superTbls[j] + .sampleBindBatchArray + + sizeof(char *) * c))); + } + } + tmfree(g_Dbs.db[i].superTbls[j].sampleBindBatchArray); + + if (0 != g_Dbs.db[i].superTbls[j].tagDataBuf) { + tmfree(g_Dbs.db[i].superTbls[j].tagDataBuf); + g_Dbs.db[i].superTbls[j].tagDataBuf = NULL; + } + if (0 != g_Dbs.db[i].superTbls[j].childTblName) { + tmfree(g_Dbs.db[i].superTbls[j].childTblName); + g_Dbs.db[i].superTbls[j].childTblName = NULL; + } + } + tmfree(g_Dbs.db[i].superTbls); + } + tmfree(g_Dbs.db); + tmfree(g_randbool_buff); + tmfree(g_randint_buff); + tmfree(g_rand_voltage_buff); + tmfree(g_randbigint_buff); + tmfree(g_randsmallint_buff); + tmfree(g_randtinyint_buff); + tmfree(g_randfloat_buff); + tmfree(g_rand_current_buff); + tmfree(g_rand_phase_buff); + + tmfree(g_sampleDataBuf); + + for (int l = 0; l < g_args.columnCount; l++) { + if (g_sampleBindBatchArray) { + tmfree((char *)((uintptr_t) * (uintptr_t *)(g_sampleBindBatchArray + + sizeof(char *) * l))); + } + } + tmfree(g_sampleBindBatchArray); +} + +static int32_t execInsert(threadInfo *pThreadInfo, uint32_t k) { + int32_t affectedRows; + SSuperTable *stbInfo = pThreadInfo->stbInfo; + TAOS_RES * res; + int32_t code; + uint16_t iface; + if (stbInfo) + iface = stbInfo->iface; + else { + if (g_args.iface == INTERFACE_BUT) + iface = TAOSC_IFACE; + else + iface = g_args.iface; + } + + debugPrint("[%d] %s() LN%d %s\n", pThreadInfo->threadID, __func__, __LINE__, + (iface == TAOSC_IFACE) ? "taosc" + : (iface == REST_IFACE) ? "rest" + : "stmt"); + + switch (iface) { + case TAOSC_IFACE: + verbosePrint("[%d] %s() LN%d %s\n", pThreadInfo->threadID, __func__, + __LINE__, pThreadInfo->buffer); + + affectedRows = queryDbExec(pThreadInfo->taos, pThreadInfo->buffer, + INSERT_TYPE, false); + break; + + case REST_IFACE: + verbosePrint("[%d] %s() LN%d %s\n", pThreadInfo->threadID, __func__, + __LINE__, pThreadInfo->buffer); + + if (0 != postProceSql(g_Dbs.host, g_Dbs.port, pThreadInfo->buffer, + pThreadInfo)) { + affectedRows = -1; + printf("========restful return fail, threadID[%d]\n", + pThreadInfo->threadID); + } else { + affectedRows = k; + } + break; + + case STMT_IFACE: + debugPrint("%s() LN%d, stmt=%p", __func__, __LINE__, + pThreadInfo->stmt); + if (0 != taos_stmt_execute(pThreadInfo->stmt)) { + errorPrint( + "%s() LN%d, failied to execute insert statement. reason: " + "%s\n", + __func__, __LINE__, taos_stmt_errstr(pThreadInfo->stmt)); + + fprintf(stderr, + "\n\033[31m === Please reduce batch number if WAL size " + "exceeds limit. ===\033[0m\n\n"); + exit(EXIT_FAILURE); + } + affectedRows = k; + break; + case SML_IFACE: + res = taos_schemaless_insert( + pThreadInfo->taos, pThreadInfo->lines, + stbInfo->lineProtocol == TSDB_SML_JSON_PROTOCOL ? 0 : k, + stbInfo->lineProtocol, stbInfo->tsPrecision); + code = taos_errno(res); + affectedRows = taos_affected_rows(res); + if (code != TSDB_CODE_SUCCESS) { + errorPrint( + "%s() LN%d, failed to execute schemaless insert. reason: " + "%s\n", + __func__, __LINE__, taos_errstr(res)); + exit(EXIT_FAILURE); + } + break; + default: + errorPrint("Unknown insert mode: %d\n", stbInfo->iface); + affectedRows = 0; + } + + return affectedRows; +} + +static void getTableName(char *pTblName, threadInfo *pThreadInfo, + uint64_t tableSeq) { + SSuperTable *stbInfo = pThreadInfo->stbInfo; + if (stbInfo) { + if (AUTO_CREATE_SUBTBL != stbInfo->autoCreateTable) { + if (stbInfo->childTblLimit > 0) { + snprintf(pTblName, TSDB_TABLE_NAME_LEN, + stbInfo->escapeChar ? "`%s`" : "%s", + stbInfo->childTblName + + (tableSeq - stbInfo->childTblOffset) * + TSDB_TABLE_NAME_LEN); + } else { + verbosePrint("[%d] %s() LN%d: from=%" PRIu64 " count=%" PRId64 + " seq=%" PRIu64 "\n", + pThreadInfo->threadID, __func__, __LINE__, + pThreadInfo->start_table_from, + pThreadInfo->ntables, tableSeq); + snprintf( + pTblName, TSDB_TABLE_NAME_LEN, + stbInfo->escapeChar ? "`%s`" : "%s", + stbInfo->childTblName + tableSeq * TSDB_TABLE_NAME_LEN); + } + } else { + snprintf(pTblName, TSDB_TABLE_NAME_LEN, + stbInfo->escapeChar ? "`%s%" PRIu64 "`" : "%s%" PRIu64 "", + stbInfo->childTblPrefix, tableSeq); + } + } else { + snprintf(pTblName, TSDB_TABLE_NAME_LEN, + g_args.escapeChar ? "`%s%" PRIu64 "`" : "%s%" PRIu64 "", + g_args.tb_prefix, tableSeq); + } +} + +static int execStbBindParamBatch(threadInfo *pThreadInfo, char *tableName, + int64_t tableSeq, uint32_t batch, + uint64_t insertRows, uint64_t recordFrom, + int64_t startTime, int64_t *pSamplePos) { + TAOS_STMT *stmt = pThreadInfo->stmt; + + SSuperTable *stbInfo = pThreadInfo->stbInfo; + + uint32_t columnCount = pThreadInfo->stbInfo->columnCount; + + uint32_t thisBatch = (uint32_t)(MAX_SAMPLES - (*pSamplePos)); + + if (thisBatch > batch) { + thisBatch = batch; + } + verbosePrint("%s() LN%d, batch=%d pos=%" PRId64 " thisBatch=%d\n", __func__, + __LINE__, batch, *pSamplePos, thisBatch); + + memset(pThreadInfo->bindParams, 0, + (sizeof(TAOS_MULTI_BIND) * (columnCount + 1))); + memset(pThreadInfo->is_null, 0, thisBatch); + + for (int c = 0; c < columnCount + 1; c++) { + TAOS_MULTI_BIND *param = + (TAOS_MULTI_BIND *)(pThreadInfo->bindParams + + sizeof(TAOS_MULTI_BIND) * c); + + char data_type; + + if (c == 0) { + data_type = TSDB_DATA_TYPE_TIMESTAMP; + param->buffer_length = sizeof(int64_t); + param->buffer = pThreadInfo->bind_ts_array; + + } else { + data_type = stbInfo->columns[c - 1].data_type; + + char *tmpP; + + switch (data_type) { + case TSDB_DATA_TYPE_BINARY: + param->buffer_length = stbInfo->columns[c - 1].dataLen; + + tmpP = + (char *)((uintptr_t) * + (uintptr_t *)(stbInfo->sampleBindBatchArray + + sizeof(char *) * (c - 1))); + + verbosePrint("%s() LN%d, tmpP=%p pos=%" PRId64 + " width=%" PRIxPTR " position=%" PRId64 "\n", + __func__, __LINE__, tmpP, *pSamplePos, + param->buffer_length, + (*pSamplePos) * param->buffer_length); + + param->buffer = + (void *)(tmpP + *pSamplePos * param->buffer_length); + break; + + case TSDB_DATA_TYPE_NCHAR: + param->buffer_length = stbInfo->columns[c - 1].dataLen; + + tmpP = + (char *)((uintptr_t) * + (uintptr_t *)(stbInfo->sampleBindBatchArray + + sizeof(char *) * (c - 1))); + + verbosePrint("%s() LN%d, tmpP=%p pos=%" PRId64 + " width=%" PRIxPTR " position=%" PRId64 "\n", + __func__, __LINE__, tmpP, *pSamplePos, + param->buffer_length, + (*pSamplePos) * param->buffer_length); + + param->buffer = + (void *)(tmpP + *pSamplePos * param->buffer_length); + break; + + case TSDB_DATA_TYPE_INT: + case TSDB_DATA_TYPE_UINT: + param->buffer_length = sizeof(int32_t); + param->buffer = + (void *)((uintptr_t) * + (uintptr_t *)(stbInfo + ->sampleBindBatchArray + + sizeof(char *) * (c - 1)) + + stbInfo->columns[c - 1].dataLen * + (*pSamplePos)); + break; + + case TSDB_DATA_TYPE_TINYINT: + case TSDB_DATA_TYPE_UTINYINT: + param->buffer_length = sizeof(int8_t); + param->buffer = + (void *)((uintptr_t) * + (uintptr_t *)(stbInfo + ->sampleBindBatchArray + + sizeof(char *) * (c - 1)) + + stbInfo->columns[c - 1].dataLen * + (*pSamplePos)); + break; + + case TSDB_DATA_TYPE_SMALLINT: + case TSDB_DATA_TYPE_USMALLINT: + param->buffer_length = sizeof(int16_t); + param->buffer = + (void *)((uintptr_t) * + (uintptr_t *)(stbInfo + ->sampleBindBatchArray + + sizeof(char *) * (c - 1)) + + stbInfo->columns[c - 1].dataLen * + (*pSamplePos)); + break; + + case TSDB_DATA_TYPE_BIGINT: + case TSDB_DATA_TYPE_UBIGINT: + param->buffer_length = sizeof(int64_t); + param->buffer = + (void *)((uintptr_t) * + (uintptr_t *)(stbInfo + ->sampleBindBatchArray + + sizeof(char *) * (c - 1)) + + stbInfo->columns[c - 1].dataLen * + (*pSamplePos)); + break; + + case TSDB_DATA_TYPE_BOOL: + param->buffer_length = sizeof(int8_t); + param->buffer = + (void *)((uintptr_t) * + (uintptr_t *)(stbInfo + ->sampleBindBatchArray + + sizeof(char *) * (c - 1)) + + stbInfo->columns[c - 1].dataLen * + (*pSamplePos)); + break; + + case TSDB_DATA_TYPE_FLOAT: + param->buffer_length = sizeof(float); + param->buffer = + (void *)((uintptr_t) * + (uintptr_t *)(stbInfo + ->sampleBindBatchArray + + sizeof(char *) * (c - 1)) + + stbInfo->columns[c - 1].dataLen * + (*pSamplePos)); + break; + + case TSDB_DATA_TYPE_DOUBLE: + param->buffer_length = sizeof(double); + param->buffer = + (void *)((uintptr_t) * + (uintptr_t *)(stbInfo + ->sampleBindBatchArray + + sizeof(char *) * (c - 1)) + + stbInfo->columns[c - 1].dataLen * + (*pSamplePos)); + break; + + case TSDB_DATA_TYPE_TIMESTAMP: + param->buffer_length = sizeof(int64_t); + param->buffer = + (void *)((uintptr_t) * + (uintptr_t *)(stbInfo + ->sampleBindBatchArray + + sizeof(char *) * (c - 1)) + + stbInfo->columns[c - 1].dataLen * + (*pSamplePos)); + break; + + default: + errorPrint("wrong data type: %d\n", data_type); + return -1; + } + } + + param->buffer_type = data_type; + param->length = calloc(1, sizeof(int32_t) * thisBatch); + if (param->length == NULL) { + errorPrint("%s", "failed to allocate memory\n"); + return -1; + } + + for (int b = 0; b < thisBatch; b++) { + if (param->buffer_type == TSDB_DATA_TYPE_NCHAR) { + param->length[b] = (int32_t)strlen( + (char *)param->buffer + b * stbInfo->columns[c].dataLen); + } else { + param->length[b] = (int32_t)param->buffer_length; + } + } + param->is_null = pThreadInfo->is_null; + param->num = thisBatch; + } + + uint32_t k; + for (k = 0; k < thisBatch;) { + /* columnCount + 1 (ts) */ + if (stbInfo->disorderRatio) { + *(pThreadInfo->bind_ts_array + k) = + startTime + getTSRandTail(stbInfo->timeStampStep, k, + stbInfo->disorderRatio, + stbInfo->disorderRange); + } else { + *(pThreadInfo->bind_ts_array + k) = + startTime + stbInfo->timeStampStep * k; + } + + debugPrint("%s() LN%d, k=%d ts=%" PRId64 "\n", __func__, __LINE__, k, + *(pThreadInfo->bind_ts_array + k)); + k++; + recordFrom++; + + (*pSamplePos)++; + if ((*pSamplePos) == MAX_SAMPLES) { + *pSamplePos = 0; + } + + if (recordFrom >= insertRows) { + break; + } + } + + if (taos_stmt_bind_param_batch( + stmt, (TAOS_MULTI_BIND *)pThreadInfo->bindParams)) { + errorPrint("taos_stmt_bind_param_batch() failed! reason: %s\n", + taos_stmt_errstr(stmt)); + return -1; + } + + for (int c = 0; c < stbInfo->columnCount + 1; c++) { + TAOS_MULTI_BIND *param = + (TAOS_MULTI_BIND *)(pThreadInfo->bindParams + + sizeof(TAOS_MULTI_BIND) * c); + free(param->length); + } + + // if msg > 3MB, break + if (taos_stmt_add_batch(stmt)) { + errorPrint("taos_stmt_add_batch() failed! reason: %s\n", + taos_stmt_errstr(stmt)); + return -1; + } + return k; +} + +int32_t prepareStbStmt(threadInfo *pThreadInfo, char *tableName, + int64_t tableSeq, uint32_t batch, uint64_t insertRows, + uint64_t recordFrom, int64_t startTime, + int64_t *pSamplePos) { + SSuperTable *stbInfo = pThreadInfo->stbInfo; + TAOS_STMT * stmt = pThreadInfo->stmt; + + char *tagsArray = calloc(1, sizeof(TAOS_BIND) * stbInfo->tagCount); + if (NULL == tagsArray) { + errorPrint("%s", "failed to allocate memory\n"); + return -1; + } + char *tagsValBuf = (char *)calloc(TSDB_MAX_SQL_LEN + 1, 1); + + if (AUTO_CREATE_SUBTBL == stbInfo->autoCreateTable) { + if (0 == stbInfo->tagSource) { + if (generateTagValuesForStb(stbInfo, tableSeq, tagsValBuf)) { + tmfree(tagsValBuf); + return -1; + } + } else { + snprintf( + tagsValBuf, TSDB_MAX_SQL_LEN, "(%s)", + stbInfo->tagDataBuf + stbInfo->lenOfTagOfOneRow * + (tableSeq % stbInfo->tagSampleCount)); + } + + if (prepareStbStmtBindTag(tagsArray, stbInfo, tagsValBuf, + pThreadInfo->time_precision)) { + tmfree(tagsValBuf); + tmfree(tagsArray); + return -1; + } + + if (taos_stmt_set_tbname_tags(stmt, tableName, + (TAOS_BIND *)tagsArray)) { + errorPrint("taos_stmt_set_tbname_tags() failed! reason: %s\n", + taos_stmt_errstr(stmt)); + return -1; + } + + } else { + if (taos_stmt_set_tbname(stmt, tableName)) { + errorPrint("taos_stmt_set_tbname() failed! reason: %s\n", + taos_stmt_errstr(stmt)); + return -1; + } + } + tmfree(tagsValBuf); + tmfree(tagsArray); + return execStbBindParamBatch(pThreadInfo, tableName, tableSeq, batch, + insertRows, recordFrom, startTime, pSamplePos); +} + +// stmt sync write interlace data +static void *syncWriteInterlaceStmtBatch(threadInfo *pThreadInfo, + uint32_t interlaceRows) { + debugPrint("[%d] %s() LN%d: ### stmt interlace write\n", + pThreadInfo->threadID, __func__, __LINE__); + + int64_t insertRows; + int64_t timeStampStep; + uint64_t insert_interval; + + SSuperTable *stbInfo = pThreadInfo->stbInfo; + + if (stbInfo) { + insertRows = stbInfo->insertRows; + timeStampStep = stbInfo->timeStampStep; + insert_interval = stbInfo->insertInterval; + } else { + insertRows = g_args.insertRows; + timeStampStep = g_args.timestamp_step; + insert_interval = g_args.insert_interval; + } + + debugPrint("[%d] %s() LN%d: start_table_from=%" PRIu64 " ntables=%" PRId64 + " insertRows=%" PRIu64 "\n", + pThreadInfo->threadID, __func__, __LINE__, + pThreadInfo->start_table_from, pThreadInfo->ntables, insertRows); + + uint64_t timesInterlace = (insertRows / interlaceRows) + 1; + uint32_t precalcBatch = interlaceRows; + + if (precalcBatch > g_args.reqPerReq) precalcBatch = g_args.reqPerReq; + + if (precalcBatch > MAX_SAMPLES) precalcBatch = MAX_SAMPLES; + + pThreadInfo->totalInsertRows = 0; + pThreadInfo->totalAffectedRows = 0; + + uint64_t st = 0; + uint64_t et = UINT64_MAX; + + uint64_t lastPrintTime = taosGetTimestampMs(); + uint64_t startTs = taosGetTimestampMs(); + uint64_t endTs; + + uint64_t tableSeq = pThreadInfo->start_table_from; + int64_t startTime; + + bool flagSleep = true; + uint64_t sleepTimeTotal = 0; + + int percentComplete = 0; + int64_t totalRows = insertRows * pThreadInfo->ntables; + pThreadInfo->samplePos = 0; + + for (int64_t interlace = 0; interlace < timesInterlace; interlace++) { + if ((flagSleep) && (insert_interval)) { + st = taosGetTimestampMs(); + flagSleep = false; + } + + int64_t generated = 0; + int64_t samplePos; + + for (; tableSeq < pThreadInfo->start_table_from + pThreadInfo->ntables; + tableSeq++) { + char tableName[TSDB_TABLE_NAME_LEN]; + getTableName(tableName, pThreadInfo, tableSeq); + if (0 == strlen(tableName)) { + errorPrint("[%d] %s() LN%d, getTableName return null\n", + pThreadInfo->threadID, __func__, __LINE__); + return NULL; + } + + samplePos = pThreadInfo->samplePos; + startTime = pThreadInfo->start_time + + interlace * interlaceRows * timeStampStep; + uint64_t remainRecPerTbl = insertRows - interlaceRows * interlace; + uint64_t recPerTbl = 0; + + uint64_t remainPerInterlace; + if (remainRecPerTbl > interlaceRows) { + remainPerInterlace = interlaceRows; + } else { + remainPerInterlace = remainRecPerTbl; + } + + while (remainPerInterlace > 0) { + uint32_t batch; + if (remainPerInterlace > precalcBatch) { + batch = precalcBatch; + } else { + batch = (uint32_t)remainPerInterlace; + } + debugPrint( + "[%d] %s() LN%d, tableName:%s, batch:%d startTime:%" PRId64 + "\n", + pThreadInfo->threadID, __func__, __LINE__, tableName, batch, + startTime); + + if (stbInfo) { + generated = + prepareStbStmt(pThreadInfo, tableName, tableSeq, batch, + insertRows, 0, startTime, &samplePos); + } else { + generated = prepareStmtWithoutStb( + pThreadInfo, tableName, batch, insertRows, + interlaceRows * interlace + recPerTbl, startTime); + } + + debugPrint("[%d] %s() LN%d, generated records is %" PRId64 "\n", + pThreadInfo->threadID, __func__, __LINE__, + generated); + if (generated < 0) { + errorPrint( + "[%d] %s() LN%d, generated records is %" PRId64 "\n", + pThreadInfo->threadID, __func__, __LINE__, generated); + goto free_of_interlace_stmt; + } else if (generated == 0) { + break; + } + + recPerTbl += generated; + remainPerInterlace -= generated; + pThreadInfo->totalInsertRows += generated; + + verbosePrint("[%d] %s() LN%d totalInsertRows=%" PRIu64 "\n", + pThreadInfo->threadID, __func__, __LINE__, + pThreadInfo->totalInsertRows); + + startTs = taosGetTimestampUs(); + + int64_t affectedRows = + execInsert(pThreadInfo, (uint32_t)generated); + + endTs = taosGetTimestampUs(); + uint64_t delay = endTs - startTs; + performancePrint( + "%s() LN%d, insert execution time is %10.2f ms\n", __func__, + __LINE__, delay / 1000.0); + verbosePrint("[%d] %s() LN%d affectedRows=%" PRId64 "\n", + pThreadInfo->threadID, __func__, __LINE__, + affectedRows); + + if (delay > pThreadInfo->maxDelay) + pThreadInfo->maxDelay = delay; + if (delay < pThreadInfo->minDelay) + pThreadInfo->minDelay = delay; + pThreadInfo->cntDelay++; + pThreadInfo->totalDelay += delay; + + if (generated != affectedRows) { + errorPrint("[%d] %s() LN%d execInsert() insert %" PRId64 + ", affected rows: %" PRId64 "\n\n", + pThreadInfo->threadID, __func__, __LINE__, + generated, affectedRows); + goto free_of_interlace_stmt; + } + + pThreadInfo->totalAffectedRows += affectedRows; + + int currentPercent = + (int)(pThreadInfo->totalAffectedRows * 100 / totalRows); + if (currentPercent > percentComplete) { + printf("[%d]:%d%%\n", pThreadInfo->threadID, + currentPercent); + percentComplete = currentPercent; + } + int64_t currentPrintTime = taosGetTimestampMs(); + if (currentPrintTime - lastPrintTime > 30 * 1000) { + printf("thread[%d] has currently inserted rows: %" PRIu64 + ", affected rows: %" PRIu64 "\n", + pThreadInfo->threadID, pThreadInfo->totalInsertRows, + pThreadInfo->totalAffectedRows); + lastPrintTime = currentPrintTime; + } + + startTime += (generated * timeStampStep); + } + } + pThreadInfo->samplePos = samplePos; + + if (tableSeq == pThreadInfo->start_table_from + pThreadInfo->ntables) { + // turn to first table + tableSeq = pThreadInfo->start_table_from; + + flagSleep = true; + } + + if ((insert_interval) && flagSleep) { + et = taosGetTimestampMs(); + + if (insert_interval > (et - st)) { + uint64_t sleepTime = insert_interval - (et - st); + performancePrint("%s() LN%d sleep: %" PRId64 + " ms for insert interval\n", + __func__, __LINE__, sleepTime); + taosMsleep((int32_t)sleepTime); // ms + sleepTimeTotal += insert_interval; + } + } + } + if (percentComplete < 100) + printf("[%d]:%d%%\n", pThreadInfo->threadID, percentComplete); + +free_of_interlace_stmt: + printStatPerThread(pThreadInfo); + return NULL; +} + +void *syncWriteInterlace(threadInfo *pThreadInfo, uint32_t interlaceRows) { + debugPrint("[%d] %s() LN%d: ### interlace write\n", pThreadInfo->threadID, + __func__, __LINE__); + + int64_t insertRows; + uint64_t maxSqlLen; + int64_t timeStampStep; + uint64_t insert_interval; + + SSuperTable *stbInfo = pThreadInfo->stbInfo; + + if (stbInfo) { + insertRows = stbInfo->insertRows; + maxSqlLen = stbInfo->maxSqlLen; + timeStampStep = stbInfo->timeStampStep; + insert_interval = stbInfo->insertInterval; + } else { + insertRows = g_args.insertRows; + maxSqlLen = g_args.max_sql_len; + timeStampStep = g_args.timestamp_step; + insert_interval = g_args.insert_interval; + } + + debugPrint("[%d] %s() LN%d: start_table_from=%" PRIu64 " ntables=%" PRId64 + " insertRows=%" PRIu64 "\n", + pThreadInfo->threadID, __func__, __LINE__, + pThreadInfo->start_table_from, pThreadInfo->ntables, insertRows); + + if (interlaceRows > g_args.reqPerReq) interlaceRows = g_args.reqPerReq; + + uint32_t batchPerTbl = interlaceRows; + uint32_t batchPerTblTimes; + + if ((interlaceRows > 0) && (pThreadInfo->ntables > 1)) { + batchPerTblTimes = g_args.reqPerReq / interlaceRows; + } else { + batchPerTblTimes = 1; + } + pThreadInfo->buffer = calloc(maxSqlLen, 1); + if (NULL == pThreadInfo->buffer) { + errorPrint("%s", "failed to allocate memory\n"); + return NULL; + } + + pThreadInfo->totalInsertRows = 0; + pThreadInfo->totalAffectedRows = 0; + + uint64_t st = 0; + uint64_t et = UINT64_MAX; + + uint64_t lastPrintTime = taosGetTimestampMs(); + uint64_t startTs = taosGetTimestampMs(); + uint64_t endTs; + + uint64_t tableSeq = pThreadInfo->start_table_from; + int64_t startTime = pThreadInfo->start_time; + + uint64_t generatedRecPerTbl = 0; + bool flagSleep = true; + uint64_t sleepTimeTotal = 0; + + int percentComplete = 0; + int64_t totalRows = insertRows * pThreadInfo->ntables; + + while (pThreadInfo->totalInsertRows < pThreadInfo->ntables * insertRows) { + if ((flagSleep) && (insert_interval)) { + st = taosGetTimestampMs(); + flagSleep = false; + } + + // generate data + memset(pThreadInfo->buffer, 0, maxSqlLen); + uint64_t remainderBufLen = maxSqlLen; + + char *pstr = pThreadInfo->buffer; + + int len = + snprintf(pstr, strlen(STR_INSERT_INTO) + 1, "%s", STR_INSERT_INTO); + pstr += len; + remainderBufLen -= len; + + uint32_t recOfBatch = 0; + + int32_t generated; + for (uint64_t i = 0; i < batchPerTblTimes; i++) { + char tableName[TSDB_TABLE_NAME_LEN]; + + getTableName(tableName, pThreadInfo, tableSeq); + if (0 == strlen(tableName)) { + errorPrint("[%d] %s() LN%d, getTableName return null\n", + pThreadInfo->threadID, __func__, __LINE__); + free(pThreadInfo->buffer); + return NULL; + } + + uint64_t oldRemainderLen = remainderBufLen; + + if (stbInfo) { + generated = generateStbInterlaceData( + pThreadInfo, tableName, batchPerTbl, i, batchPerTblTimes, + tableSeq, pstr, insertRows, startTime, &remainderBufLen); + } else { + generated = (int32_t)generateInterlaceDataWithoutStb( + tableName, batchPerTbl, tableSeq, pThreadInfo->db_name, + pstr, insertRows, startTime, &remainderBufLen); + } + + debugPrint("[%d] %s() LN%d, generated records is %d\n", + pThreadInfo->threadID, __func__, __LINE__, generated); + if (generated < 0) { + errorPrint("[%d] %s() LN%d, generated records is %d\n", + pThreadInfo->threadID, __func__, __LINE__, + generated); + goto free_of_interlace; + } else if (generated == 0) { + break; + } + + tableSeq++; + recOfBatch += batchPerTbl; + + pstr += (oldRemainderLen - remainderBufLen); + pThreadInfo->totalInsertRows += batchPerTbl; + + verbosePrint("[%d] %s() LN%d batchPerTbl=%d recOfBatch=%d\n", + pThreadInfo->threadID, __func__, __LINE__, batchPerTbl, + recOfBatch); + + if (tableSeq == + pThreadInfo->start_table_from + pThreadInfo->ntables) { + // turn to first table + tableSeq = pThreadInfo->start_table_from; + generatedRecPerTbl += batchPerTbl; + + startTime = pThreadInfo->start_time + + generatedRecPerTbl * timeStampStep; + + flagSleep = true; + if (generatedRecPerTbl >= insertRows) break; + + int64_t remainRows = insertRows - generatedRecPerTbl; + if ((remainRows > 0) && (batchPerTbl > remainRows)) + batchPerTbl = (uint32_t)remainRows; + + if (pThreadInfo->ntables * batchPerTbl < g_args.reqPerReq) + break; + } + + verbosePrint("[%d] %s() LN%d generatedRecPerTbl=%" PRId64 + " insertRows=%" PRId64 "\n", + pThreadInfo->threadID, __func__, __LINE__, + generatedRecPerTbl, insertRows); + + if ((g_args.reqPerReq - recOfBatch) < batchPerTbl) break; + } + + verbosePrint("[%d] %s() LN%d recOfBatch=%d totalInsertRows=%" PRIu64 + "\n", + pThreadInfo->threadID, __func__, __LINE__, recOfBatch, + pThreadInfo->totalInsertRows); + verbosePrint("[%d] %s() LN%d, buffer=%s\n", pThreadInfo->threadID, + __func__, __LINE__, pThreadInfo->buffer); + + startTs = taosGetTimestampUs(); + + if (recOfBatch == 0) { + errorPrint("[%d] %s() LN%d Failed to insert records of batch %d\n", + pThreadInfo->threadID, __func__, __LINE__, batchPerTbl); + if (batchPerTbl > 0) { + errorPrint( + "\tIf the batch is %d, the length of the SQL to insert a " + "row must be less then %" PRId64 "\n", + batchPerTbl, maxSqlLen / batchPerTbl); + } + errorPrint("\tPlease check if the buffer length(%" PRId64 + ") or batch(%d) is set with proper value!\n", + maxSqlLen, batchPerTbl); + goto free_of_interlace; + } + int64_t affectedRows = execInsert(pThreadInfo, recOfBatch); + + endTs = taosGetTimestampUs(); + uint64_t delay = endTs - startTs; + performancePrint("%s() LN%d, insert execution time is %10.2f ms\n", + __func__, __LINE__, delay / 1000.0); + verbosePrint("[%d] %s() LN%d affectedRows=%" PRId64 "\n", + pThreadInfo->threadID, __func__, __LINE__, affectedRows); + + if (delay > pThreadInfo->maxDelay) pThreadInfo->maxDelay = delay; + if (delay < pThreadInfo->minDelay) pThreadInfo->minDelay = delay; + pThreadInfo->cntDelay++; + pThreadInfo->totalDelay += delay; + + if (recOfBatch != affectedRows) { + errorPrint( + "[%d] %s() LN%d execInsert insert %d, affected rows: %" PRId64 + "\n%s\n", + pThreadInfo->threadID, __func__, __LINE__, recOfBatch, + affectedRows, pThreadInfo->buffer); + goto free_of_interlace; + } + + pThreadInfo->totalAffectedRows += affectedRows; + + int currentPercent = + (int)(pThreadInfo->totalAffectedRows * 100 / totalRows); + if (currentPercent > percentComplete) { + printf("[%d]:%d%%\n", pThreadInfo->threadID, currentPercent); + percentComplete = currentPercent; + } + int64_t currentPrintTime = taosGetTimestampMs(); + if (currentPrintTime - lastPrintTime > 30 * 1000) { + printf("thread[%d] has currently inserted rows: %" PRIu64 + ", affected rows: %" PRIu64 "\n", + pThreadInfo->threadID, pThreadInfo->totalInsertRows, + pThreadInfo->totalAffectedRows); + lastPrintTime = currentPrintTime; + } + + if ((insert_interval) && flagSleep) { + et = taosGetTimestampMs(); + + if (insert_interval > (et - st)) { + uint64_t sleepTime = insert_interval - (et - st); + performancePrint("%s() LN%d sleep: %" PRId64 + " ms for insert interval\n", + __func__, __LINE__, sleepTime); + taosMsleep((int32_t)sleepTime); // ms + sleepTimeTotal += insert_interval; + } + } + } + if (percentComplete < 100) + printf("[%d]:%d%%\n", pThreadInfo->threadID, percentComplete); + +free_of_interlace: + tmfree(pThreadInfo->buffer); + printStatPerThread(pThreadInfo); + return NULL; +} + +static void *syncWriteInterlaceSml(threadInfo *pThreadInfo, + uint32_t interlaceRows) { + debugPrint("[%d] %s() LN%d: ### interlace schemaless write\n", + pThreadInfo->threadID, __func__, __LINE__); + int64_t insertRows; + uint64_t maxSqlLen; + int64_t timeStampStep; + uint64_t insert_interval; + int32_t code = 0; + + SSuperTable *stbInfo = pThreadInfo->stbInfo; + + if (stbInfo) { + insertRows = stbInfo->insertRows; + maxSqlLen = stbInfo->maxSqlLen; + timeStampStep = stbInfo->timeStampStep; + insert_interval = stbInfo->insertInterval; + } else { + insertRows = g_args.insertRows; + maxSqlLen = g_args.max_sql_len; + timeStampStep = g_args.timestamp_step; + insert_interval = g_args.insert_interval; + } + + debugPrint("[%d] %s() LN%d: start_table_from=%" PRIu64 " ntables=%" PRId64 + " insertRows=%" PRIu64 "\n", + pThreadInfo->threadID, __func__, __LINE__, + pThreadInfo->start_table_from, pThreadInfo->ntables, insertRows); + + if (interlaceRows > g_args.reqPerReq) interlaceRows = g_args.reqPerReq; + + uint32_t batchPerTbl = interlaceRows; + uint32_t batchPerTblTimes; + + if ((interlaceRows > 0) && (pThreadInfo->ntables > 1)) { + batchPerTblTimes = g_args.reqPerReq / interlaceRows; + } else { + batchPerTblTimes = 1; + } + + char **smlList; + cJSON *tagsList; + cJSON *jsonArray; + if (stbInfo->lineProtocol == TSDB_SML_LINE_PROTOCOL || + stbInfo->lineProtocol == TSDB_SML_TELNET_PROTOCOL) { + smlList = (char **)calloc(pThreadInfo->ntables, sizeof(char *)); + if (NULL == smlList) { + errorPrint("%s", "failed to allocate memory\n"); + return NULL; + } + + for (int t = 0; t < pThreadInfo->ntables; t++) { + char *sml = (char *)calloc(1, stbInfo->lenOfOneRow); + if (NULL == sml) { + errorPrint("%s", "failed to allocate memory\n"); + goto free_smlheadlist_interlace_sml; + } + code = generateSmlConstPart(sml, stbInfo, pThreadInfo, t); + if (code) { + goto free_smlheadlist_interlace_sml; + } + smlList[t] = sml; + } + + pThreadInfo->lines = calloc(g_args.reqPerReq, sizeof(char *)); + if (NULL == pThreadInfo->lines) { + errorPrint("%s", "failed to allocate memory\n"); + goto free_smlheadlist_interlace_sml; + } + + for (int i = 0; i < g_args.reqPerReq; i++) { + pThreadInfo->lines[i] = calloc(1, stbInfo->lenOfOneRow); + if (NULL == pThreadInfo->lines[i]) { + errorPrint("%s", "failed to allocate memory\n"); + goto free_lines_interlace_sml; + } + } + } else { + jsonArray = cJSON_CreateArray(); + tagsList = cJSON_CreateArray(); + for (int t = 0; t < pThreadInfo->ntables; t++) { + code = generateSmlJsonTags(tagsList, stbInfo, pThreadInfo, t); + if (code) { + goto free_json_interlace_sml; + } + } + + pThreadInfo->lines = (char **)calloc(1, sizeof(char *)); + if (NULL == pThreadInfo->lines) { + errorPrint("%s", "failed to allocate memory\n"); + goto free_json_interlace_sml; + } + } + + pThreadInfo->totalInsertRows = 0; + pThreadInfo->totalAffectedRows = 0; + + uint64_t st = 0; + uint64_t et = UINT64_MAX; + + uint64_t lastPrintTime = taosGetTimestampMs(); + uint64_t startTs = taosGetTimestampMs(); + uint64_t endTs; + + uint64_t tableSeq = pThreadInfo->start_table_from; + int64_t startTime = pThreadInfo->start_time; + + uint64_t generatedRecPerTbl = 0; + bool flagSleep = true; + uint64_t sleepTimeTotal = 0; + + int percentComplete = 0; + int64_t totalRows = insertRows * pThreadInfo->ntables; + + while (pThreadInfo->totalInsertRows < pThreadInfo->ntables * insertRows) { + if ((flagSleep) && (insert_interval)) { + st = taosGetTimestampMs(); + flagSleep = false; + } + // generate data + + uint32_t recOfBatch = 0; + + for (uint64_t i = 0; i < batchPerTblTimes; i++) { + int64_t timestamp = startTime; + for (int j = recOfBatch; j < recOfBatch + batchPerTbl; j++) { + if (stbInfo->lineProtocol == TSDB_SML_JSON_PROTOCOL) { + cJSON *tag = cJSON_Duplicate( + cJSON_GetArrayItem( + tagsList, + (int)(tableSeq - pThreadInfo->start_table_from)), + true); + code = generateSmlJsonCols(jsonArray, tag, stbInfo, + pThreadInfo, timestamp); + if (code) { + goto free_json_interlace_sml; + } + } else { + code = generateSmlMutablePart( + pThreadInfo->lines[j], + smlList[tableSeq - pThreadInfo->start_table_from], + stbInfo, pThreadInfo, timestamp); + if (code) { + goto free_lines_interlace_sml; + } + } + + timestamp += timeStampStep; + } + tableSeq++; + recOfBatch += batchPerTbl; + + pThreadInfo->totalInsertRows += batchPerTbl; + + verbosePrint("[%d] %s() LN%d batchPerTbl=%d recOfBatch=%d\n", + pThreadInfo->threadID, __func__, __LINE__, batchPerTbl, + recOfBatch); + + if (tableSeq == + pThreadInfo->start_table_from + pThreadInfo->ntables) { + // turn to first table + tableSeq = pThreadInfo->start_table_from; + generatedRecPerTbl += batchPerTbl; + + startTime = pThreadInfo->start_time + + generatedRecPerTbl * timeStampStep; + + flagSleep = true; + if (generatedRecPerTbl >= insertRows) { + break; + } + + int64_t remainRows = insertRows - generatedRecPerTbl; + if ((remainRows > 0) && (batchPerTbl > remainRows)) { + batchPerTbl = (uint32_t)remainRows; + } + + if (pThreadInfo->ntables * batchPerTbl < g_args.reqPerReq) { + break; + } + } + + verbosePrint("[%d] %s() LN%d generatedRecPerTbl=%" PRId64 + " insertRows=%" PRId64 "\n", + pThreadInfo->threadID, __func__, __LINE__, + generatedRecPerTbl, insertRows); + + if ((g_args.reqPerReq - recOfBatch) < batchPerTbl) { + break; + } + } + + verbosePrint("[%d] %s() LN%d recOfBatch=%d totalInsertRows=%" PRIu64 + "\n", + pThreadInfo->threadID, __func__, __LINE__, recOfBatch, + pThreadInfo->totalInsertRows); + verbosePrint("[%d] %s() LN%d, buffer=%s\n", pThreadInfo->threadID, + __func__, __LINE__, pThreadInfo->buffer); + + if (stbInfo->lineProtocol == TSDB_SML_JSON_PROTOCOL) { + pThreadInfo->lines[0] = cJSON_Print(jsonArray); + } + + startTs = taosGetTimestampUs(); + + if (recOfBatch == 0) { + errorPrint("Failed to insert records of batch %d\n", batchPerTbl); + if (batchPerTbl > 0) { + errorPrint( + "\tIf the batch is %d, the length of the SQL to insert a " + "row must be less then %" PRId64 "\n", + batchPerTbl, maxSqlLen / batchPerTbl); + } + errorPrint("\tPlease check if the buffer length(%" PRId64 + ") or batch(%d) is set with proper value!\n", + maxSqlLen, batchPerTbl); + goto free_lines_interlace_sml; + } + int64_t affectedRows = execInsert(pThreadInfo, recOfBatch); + + endTs = taosGetTimestampUs(); + uint64_t delay = endTs - startTs; + + if (stbInfo->lineProtocol == TSDB_SML_JSON_PROTOCOL) { + tmfree(pThreadInfo->lines[0]); + cJSON_Delete(jsonArray); + jsonArray = cJSON_CreateArray(); + } + + performancePrint("%s() LN%d, insert execution time is %10.2f ms\n", + __func__, __LINE__, delay / 1000.0); + verbosePrint("[%d] %s() LN%d affectedRows=%" PRId64 "\n", + pThreadInfo->threadID, __func__, __LINE__, affectedRows); + + if (delay > pThreadInfo->maxDelay) pThreadInfo->maxDelay = delay; + if (delay < pThreadInfo->minDelay) pThreadInfo->minDelay = delay; + pThreadInfo->cntDelay++; + pThreadInfo->totalDelay += delay; + + if (recOfBatch != affectedRows) { + errorPrint("execInsert insert %d, affected rows: %" PRId64 "\n%s\n", + recOfBatch, affectedRows, pThreadInfo->buffer); + goto free_lines_interlace_sml; + } + + pThreadInfo->totalAffectedRows += affectedRows; + + int currentPercent = + (int)(pThreadInfo->totalAffectedRows * 100 / totalRows); + if (currentPercent > percentComplete) { + printf("[%d]:%d%%\n", pThreadInfo->threadID, currentPercent); + percentComplete = currentPercent; + } + int64_t currentPrintTime = taosGetTimestampMs(); + if (currentPrintTime - lastPrintTime > 30 * 1000) { + printf("thread[%d] has currently inserted rows: %" PRIu64 + ", affected rows: %" PRIu64 "\n", + pThreadInfo->threadID, pThreadInfo->totalInsertRows, + pThreadInfo->totalAffectedRows); + lastPrintTime = currentPrintTime; + } + + if ((insert_interval) && flagSleep) { + et = taosGetTimestampMs(); + + if (insert_interval > (et - st)) { + uint64_t sleepTime = insert_interval - (et - st); + performancePrint("%s() LN%d sleep: %" PRId64 + " ms for insert interval\n", + __func__, __LINE__, sleepTime); + taosMsleep((int32_t)sleepTime); // ms + sleepTimeTotal += insert_interval; + } + } + } + if (percentComplete < 100) + printf("[%d]:%d%%\n", pThreadInfo->threadID, percentComplete); + + printStatPerThread(pThreadInfo); + if (stbInfo->lineProtocol == TSDB_SML_JSON_PROTOCOL) { + tmfree(pThreadInfo->lines); + free_json_interlace_sml: + if (jsonArray != NULL) { + cJSON_Delete(jsonArray); + } + if (tagsList != NULL) { + cJSON_Delete(tagsList); + } + } else { + free_lines_interlace_sml: + for (int index = 0; index < g_args.reqPerReq; index++) { + tmfree(pThreadInfo->lines[index]); + } + tmfree(pThreadInfo->lines); + free_smlheadlist_interlace_sml: + for (int index = 0; index < pThreadInfo->ntables; index++) { + tmfree(smlList[index]); + } + tmfree(smlList); + } + return NULL; +} + +void *syncWriteProgressiveStmt(threadInfo *pThreadInfo) { + debugPrint("%s() LN%d: ### stmt progressive write\n", __func__, __LINE__); + + SSuperTable *stbInfo = pThreadInfo->stbInfo; + int64_t timeStampStep = + stbInfo ? stbInfo->timeStampStep : g_args.timestamp_step; + int64_t insertRows = (stbInfo) ? stbInfo->insertRows : g_args.insertRows; + verbosePrint("%s() LN%d insertRows=%" PRId64 "\n", __func__, __LINE__, + insertRows); + + uint64_t lastPrintTime = taosGetTimestampMs(); + uint64_t startTs = taosGetTimestampMs(); + uint64_t endTs; + + pThreadInfo->totalInsertRows = 0; + pThreadInfo->totalAffectedRows = 0; + + pThreadInfo->samplePos = 0; + + int percentComplete = 0; + int64_t totalRows = insertRows * pThreadInfo->ntables; + + for (uint64_t tableSeq = pThreadInfo->start_table_from; + tableSeq <= pThreadInfo->end_table_to; tableSeq++) { + int64_t start_time = pThreadInfo->start_time; + + for (uint64_t i = 0; i < insertRows;) { + char tableName[TSDB_TABLE_NAME_LEN]; + getTableName(tableName, pThreadInfo, tableSeq); + verbosePrint("%s() LN%d: tid=%d seq=%" PRId64 " tableName=%s\n", + __func__, __LINE__, pThreadInfo->threadID, tableSeq, + tableName); + if (0 == strlen(tableName)) { + errorPrint("[%d] %s() LN%d, getTableName return null\n", + pThreadInfo->threadID, __func__, __LINE__); + return NULL; + } + + // measure prepare + insert + startTs = taosGetTimestampUs(); + + int32_t generated; + if (stbInfo) { + generated = prepareStbStmt( + pThreadInfo, tableName, tableSeq, + (uint32_t)((g_args.reqPerReq > stbInfo->insertRows) + ? stbInfo->insertRows + : g_args.reqPerReq), + insertRows, i, start_time, &(pThreadInfo->samplePos)); + } else { + generated = prepareStmtWithoutStb(pThreadInfo, tableName, + g_args.reqPerReq, insertRows, + i, start_time); + } + + verbosePrint("[%d] %s() LN%d generated=%d\n", pThreadInfo->threadID, + __func__, __LINE__, generated); + + if (generated > 0) + i += generated; + else + goto free_of_stmt_progressive; + + start_time += generated * timeStampStep; + pThreadInfo->totalInsertRows += generated; + + // only measure insert + // startTs = taosGetTimestampUs(); + + int32_t affectedRows = execInsert(pThreadInfo, generated); + + endTs = taosGetTimestampUs(); + uint64_t delay = endTs - startTs; + performancePrint("%s() LN%d, insert execution time is %10.f ms\n", + __func__, __LINE__, delay / 1000.0); + verbosePrint("[%d] %s() LN%d affectedRows=%d\n", + pThreadInfo->threadID, __func__, __LINE__, + affectedRows); + + if (delay > pThreadInfo->maxDelay) pThreadInfo->maxDelay = delay; + if (delay < pThreadInfo->minDelay) pThreadInfo->minDelay = delay; + pThreadInfo->cntDelay++; + pThreadInfo->totalDelay += delay; + + if (affectedRows < 0) { + errorPrint("affected rows: %d\n", affectedRows); + goto free_of_stmt_progressive; + } + + pThreadInfo->totalAffectedRows += affectedRows; + + int currentPercent = + (int)(pThreadInfo->totalAffectedRows * 100 / totalRows); + if (currentPercent > percentComplete) { + printf("[%d]:%d%%\n", pThreadInfo->threadID, currentPercent); + percentComplete = currentPercent; + } + int64_t currentPrintTime = taosGetTimestampMs(); + if (currentPrintTime - lastPrintTime > 30 * 1000) { + printf("thread[%d] has currently inserted rows: %" PRId64 + ", affected rows: %" PRId64 "\n", + pThreadInfo->threadID, pThreadInfo->totalInsertRows, + pThreadInfo->totalAffectedRows); + lastPrintTime = currentPrintTime; + } + + if (i >= insertRows) break; + } // insertRows + + if ((g_args.verbose_print) && (tableSeq == pThreadInfo->ntables - 1) && + (stbInfo) && + (0 == + strncasecmp(stbInfo->dataSource, "sample", strlen("sample")))) { + verbosePrint("%s() LN%d samplePos=%" PRId64 "\n", __func__, + __LINE__, pThreadInfo->samplePos); + } + } // tableSeq + + if (percentComplete < 100) { + printf("[%d]:%d%%\n", pThreadInfo->threadID, percentComplete); + } + +free_of_stmt_progressive: + tmfree(pThreadInfo->buffer); + printStatPerThread(pThreadInfo); + return NULL; +} + +void *syncWriteProgressive(threadInfo *pThreadInfo) { + debugPrint("%s() LN%d: ### progressive write\n", __func__, __LINE__); + + SSuperTable *stbInfo = pThreadInfo->stbInfo; + uint64_t maxSqlLen = stbInfo ? stbInfo->maxSqlLen : g_args.max_sql_len; + int64_t timeStampStep = + stbInfo ? stbInfo->timeStampStep : g_args.timestamp_step; + int64_t insertRows = (stbInfo) ? stbInfo->insertRows : g_args.insertRows; + verbosePrint("%s() LN%d insertRows=%" PRId64 "\n", __func__, __LINE__, + insertRows); + + pThreadInfo->buffer = calloc(maxSqlLen, 1); + if (NULL == pThreadInfo->buffer) { + errorPrint("%s", "failed to allocate memory\n"); + return NULL; + } + + uint64_t lastPrintTime = taosGetTimestampMs(); + uint64_t startTs = taosGetTimestampMs(); + uint64_t endTs; + + pThreadInfo->totalInsertRows = 0; + pThreadInfo->totalAffectedRows = 0; + + pThreadInfo->samplePos = 0; + + int percentComplete = 0; + int64_t totalRows = insertRows * pThreadInfo->ntables; + + for (uint64_t tableSeq = pThreadInfo->start_table_from; + tableSeq <= pThreadInfo->end_table_to; tableSeq++) { + int64_t start_time = pThreadInfo->start_time; + + for (uint64_t i = 0; i < insertRows;) { + char tableName[TSDB_TABLE_NAME_LEN]; + getTableName(tableName, pThreadInfo, tableSeq); + verbosePrint("%s() LN%d: tid=%d seq=%" PRId64 " tableName=%s\n", + __func__, __LINE__, pThreadInfo->threadID, tableSeq, + tableName); + if (0 == strlen(tableName)) { + errorPrint("[%d] %s() LN%d, getTableName return null\n", + pThreadInfo->threadID, __func__, __LINE__); + free(pThreadInfo->buffer); + return NULL; + } + + int64_t remainderBufLen = maxSqlLen - 2000; + char * pstr = pThreadInfo->buffer; + + int len = snprintf(pstr, strlen(STR_INSERT_INTO) + 1, "%s", + STR_INSERT_INTO); + + pstr += len; + remainderBufLen -= len; + + // measure prepare + insert + startTs = taosGetTimestampUs(); + + int32_t generated; + if (stbInfo) { + if (stbInfo->iface == STMT_IFACE) { + generated = prepareStbStmt( + pThreadInfo, tableName, tableSeq, + (uint32_t)((g_args.reqPerReq > stbInfo->insertRows) + ? stbInfo->insertRows + : g_args.reqPerReq), + insertRows, i, start_time, &(pThreadInfo->samplePos)); + } else { + generated = generateStbProgressiveData( + stbInfo, tableName, tableSeq, pThreadInfo->db_name, + pstr, insertRows, i, start_time, + &(pThreadInfo->samplePos), &remainderBufLen); + } + } else { + if (g_args.iface == STMT_IFACE) { + generated = prepareStmtWithoutStb( + pThreadInfo, tableName, g_args.reqPerReq, insertRows, i, + start_time); + } else { + generated = generateProgressiveDataWithoutStb( + tableName, + /* tableSeq, */ + pThreadInfo, pstr, insertRows, i, start_time, + /* &(pThreadInfo->samplePos), */ + &remainderBufLen); + } + } + + verbosePrint("[%d] %s() LN%d generated=%d\n", pThreadInfo->threadID, + __func__, __LINE__, generated); + + if (generated > 0) + i += generated; + else + goto free_of_progressive; + + start_time += generated * timeStampStep; + pThreadInfo->totalInsertRows += generated; + + // only measure insert + // startTs = taosGetTimestampUs(); + + int32_t affectedRows = execInsert(pThreadInfo, generated); + + endTs = taosGetTimestampUs(); + uint64_t delay = endTs - startTs; + performancePrint("%s() LN%d, insert execution time is %10.f ms\n", + __func__, __LINE__, delay / 1000.0); + verbosePrint("[%d] %s() LN%d affectedRows=%d\n", + pThreadInfo->threadID, __func__, __LINE__, + affectedRows); + + if (delay > pThreadInfo->maxDelay) pThreadInfo->maxDelay = delay; + if (delay < pThreadInfo->minDelay) pThreadInfo->minDelay = delay; + pThreadInfo->cntDelay++; + pThreadInfo->totalDelay += delay; + + if (affectedRows < 0) { + errorPrint("affected rows: %d\n", affectedRows); + goto free_of_progressive; + } + + pThreadInfo->totalAffectedRows += affectedRows; + + int currentPercent = + (int)(pThreadInfo->totalAffectedRows * 100 / totalRows); + if (currentPercent > percentComplete) { + printf("[%d]:%d%%\n", pThreadInfo->threadID, currentPercent); + percentComplete = currentPercent; + } + int64_t currentPrintTime = taosGetTimestampMs(); + if (currentPrintTime - lastPrintTime > 30 * 1000) { + printf("thread[%d] has currently inserted rows: %" PRId64 + ", affected rows: %" PRId64 "\n", + pThreadInfo->threadID, pThreadInfo->totalInsertRows, + pThreadInfo->totalAffectedRows); + lastPrintTime = currentPrintTime; + } + + if (i >= insertRows) break; + } // insertRows + + if ((g_args.verbose_print) && (tableSeq == pThreadInfo->ntables - 1) && + (stbInfo) && + (0 == + strncasecmp(stbInfo->dataSource, "sample", strlen("sample")))) { + verbosePrint("%s() LN%d samplePos=%" PRId64 "\n", __func__, + __LINE__, pThreadInfo->samplePos); + } + } // tableSeq + + if (percentComplete < 100) { + printf("[%d]:%d%%\n", pThreadInfo->threadID, percentComplete); + } + +free_of_progressive: + tmfree(pThreadInfo->buffer); + printStatPerThread(pThreadInfo); + return NULL; +} + +void *syncWriteProgressiveSml(threadInfo *pThreadInfo) { + debugPrint("%s() LN%d: ### sml progressive write\n", __func__, __LINE__); + int32_t code = 0; + SSuperTable *stbInfo = pThreadInfo->stbInfo; + int64_t timeStampStep = stbInfo->timeStampStep; + int64_t insertRows = stbInfo->insertRows; + verbosePrint("%s() LN%d insertRows=%" PRId64 "\n", __func__, __LINE__, + insertRows); + + uint64_t lastPrintTime = taosGetTimestampMs(); + + pThreadInfo->totalInsertRows = 0; + pThreadInfo->totalAffectedRows = 0; + + pThreadInfo->samplePos = 0; + + char **smlList; + cJSON *tagsList; + cJSON *jsonArray; + + if (insertRows < g_args.reqPerReq) { + g_args.reqPerReq = (uint32_t)insertRows; + } + + if (stbInfo->lineProtocol == TSDB_SML_LINE_PROTOCOL || + stbInfo->lineProtocol == TSDB_SML_TELNET_PROTOCOL) { + smlList = (char **)calloc(pThreadInfo->ntables, sizeof(char *)); + if (NULL == smlList) { + errorPrint("%s", "failed to allocate memory\n"); + return NULL; + } + for (int t = 0; t < pThreadInfo->ntables; t++) { + char *sml = (char *)calloc(1, stbInfo->lenOfOneRow); + if (NULL == sml) { + errorPrint("%s", "failed to allocate memory\n"); + goto free_smlheadlist_progressive_sml; + } + code = generateSmlConstPart(sml, stbInfo, pThreadInfo, t); + if (code) { + goto free_smlheadlist_progressive_sml; + } + smlList[t] = sml; + } + + pThreadInfo->lines = (char **)calloc(g_args.reqPerReq, sizeof(char *)); + if (NULL == pThreadInfo->lines) { + errorPrint("%s", "failed to allocate memory\n"); + goto free_smlheadlist_progressive_sml; + } + + for (int i = 0; i < g_args.reqPerReq; i++) { + pThreadInfo->lines[i] = (char *)calloc(1, stbInfo->lenOfOneRow); + if (NULL == pThreadInfo->lines[i]) { + errorPrint("%s", "failed to allocate memory\n"); + goto free_lines_progressive_sml; + } + } + } else { + jsonArray = cJSON_CreateArray(); + tagsList = cJSON_CreateArray(); + for (int t = 0; t < pThreadInfo->ntables; t++) { + code = generateSmlJsonTags(tagsList, stbInfo, pThreadInfo, t); + if (code) { + goto free_json_progressive_sml; + } + } + + pThreadInfo->lines = (char **)calloc(1, sizeof(char *)); + if (NULL == pThreadInfo->lines) { + errorPrint("%s", "failed to allocate memory\n"); + goto free_json_progressive_sml; + } + } + int currentPercent = 0; + int percentComplete = 0; + + for (uint64_t i = 0; i < pThreadInfo->ntables; i++) { + int64_t timestamp = pThreadInfo->start_time; + for (uint64_t j = 0; j < insertRows;) { + for (int k = 0; k < g_args.reqPerReq; k++) { + if (stbInfo->lineProtocol == TSDB_SML_JSON_PROTOCOL) { + cJSON *tag = cJSON_Duplicate( + cJSON_GetArrayItem(tagsList, (int)i), true); + code = generateSmlJsonCols(jsonArray, tag, stbInfo, + pThreadInfo, timestamp); + if (code) { + goto free_json_progressive_sml; + } + } else { + code = generateSmlMutablePart(pThreadInfo->lines[k], + smlList[i], stbInfo, + pThreadInfo, timestamp); + if (code) { + goto free_lines_progressive_sml; + } + } + timestamp += timeStampStep; + j++; + if (j == insertRows) { + break; + } + } + if (stbInfo->lineProtocol == TSDB_SML_JSON_PROTOCOL) { + pThreadInfo->lines[0] = cJSON_Print(jsonArray); + } + uint64_t startTs = taosGetTimestampUs(); + int32_t affectedRows = execInsert(pThreadInfo, g_args.reqPerReq); + uint64_t endTs = taosGetTimestampUs(); + uint64_t delay = endTs - startTs; + if (stbInfo->lineProtocol == TSDB_SML_JSON_PROTOCOL) { + tmfree(pThreadInfo->lines[0]); + cJSON_Delete(jsonArray); + jsonArray = cJSON_CreateArray(); + } + + performancePrint("%s() LN%d, insert execution time is %10.f ms\n", + __func__, __LINE__, delay / 1000.0); + verbosePrint("[%d] %s() LN%d affectedRows=%d\n", + pThreadInfo->threadID, __func__, __LINE__, + affectedRows); + + if (delay > pThreadInfo->maxDelay) { + pThreadInfo->maxDelay = delay; + } + if (delay < pThreadInfo->minDelay) { + pThreadInfo->minDelay = delay; + } + pThreadInfo->cntDelay++; + pThreadInfo->totalDelay += delay; + + pThreadInfo->totalAffectedRows += affectedRows; + pThreadInfo->totalInsertRows += g_args.reqPerReq; + currentPercent = (int)(pThreadInfo->totalAffectedRows * 100 / + (insertRows * pThreadInfo->ntables)); + if (currentPercent > percentComplete) { + printf("[%d]:%d%%\n", pThreadInfo->threadID, currentPercent); + percentComplete = currentPercent; + } + + int64_t currentPrintTime = taosGetTimestampMs(); + if (currentPrintTime - lastPrintTime > 30 * 1000) { + printf("thread[%d] has currently inserted rows: %" PRId64 + ", affected rows: %" PRId64 "\n", + pThreadInfo->threadID, pThreadInfo->totalInsertRows, + pThreadInfo->totalAffectedRows); + lastPrintTime = currentPrintTime; + } + + if (j == insertRows) { + break; + } + } + } + + if (stbInfo->lineProtocol == TSDB_SML_JSON_PROTOCOL) { + tmfree(pThreadInfo->lines); + free_json_progressive_sml: + if (jsonArray != NULL) { + cJSON_Delete(jsonArray); + } + if (tagsList != NULL) { + cJSON_Delete(tagsList); + } + } else { + free_lines_progressive_sml: + for (int index = 0; index < g_args.reqPerReq; index++) { + tmfree(pThreadInfo->lines[index]); + } + tmfree(pThreadInfo->lines); + free_smlheadlist_progressive_sml: + for (int index = 0; index < pThreadInfo->ntables; index++) { + tmfree(smlList[index]); + } + tmfree(smlList); + } + return NULL; +} + +void *syncWrite(void *sarg) { + threadInfo * pThreadInfo = (threadInfo *)sarg; + SSuperTable *stbInfo = pThreadInfo->stbInfo; + + setThreadName("syncWrite"); + + uint32_t interlaceRows = 0; + + if (stbInfo) { + if (stbInfo->interlaceRows < stbInfo->insertRows) + interlaceRows = stbInfo->interlaceRows; + } else { + if (g_args.interlaceRows < g_args.insertRows) + interlaceRows = g_args.interlaceRows; + } + + if (interlaceRows > 0) { + // interlace mode + if (stbInfo) { + if (STMT_IFACE == stbInfo->iface) { + return syncWriteInterlaceStmtBatch(pThreadInfo, interlaceRows); + } else if (SML_IFACE == stbInfo->iface) { + return syncWriteInterlaceSml(pThreadInfo, interlaceRows); + } else { + return syncWriteInterlace(pThreadInfo, interlaceRows); + } + } + } else { + // progressive mode + if (((stbInfo) && (STMT_IFACE == stbInfo->iface)) || + (STMT_IFACE == g_args.iface)) { + return syncWriteProgressiveStmt(pThreadInfo); + } else if (((stbInfo) && (SML_IFACE == stbInfo->iface)) || + (SML_IFACE == g_args.iface)) { + return syncWriteProgressiveSml(pThreadInfo); + } else { + return syncWriteProgressive(pThreadInfo); + } + } + + return NULL; +} + +void callBack(void *param, TAOS_RES *res, int code) { + threadInfo * pThreadInfo = (threadInfo *)param; + SSuperTable *stbInfo = pThreadInfo->stbInfo; + + int insert_interval = + (int)(stbInfo ? stbInfo->insertInterval : g_args.insert_interval); + if (insert_interval) { + pThreadInfo->et = taosGetTimestampMs(); + if ((pThreadInfo->et - pThreadInfo->st) < insert_interval) { + taosMsleep(insert_interval - + (int32_t)(pThreadInfo->et - pThreadInfo->st)); // ms + } + } + + char *buffer = calloc(1, pThreadInfo->stbInfo->maxSqlLen); + char data[MAX_DATA_SIZE]; + char *pstr = buffer; + pstr += sprintf(pstr, "INSERT INTO %s.%s%" PRId64 " VALUES", + pThreadInfo->db_name, pThreadInfo->tb_prefix, + pThreadInfo->start_table_from); + // if (pThreadInfo->counter >= pThreadInfo->stbInfo->insertRows) { + if (pThreadInfo->counter >= g_args.reqPerReq) { + pThreadInfo->start_table_from++; + pThreadInfo->counter = 0; + } + if (pThreadInfo->start_table_from > pThreadInfo->end_table_to) { + tsem_post(&pThreadInfo->lock_sem); + free(buffer); + taos_free_result(res); + return; + } + + for (int i = 0; i < g_args.reqPerReq; i++) { + int rand_num = taosRandom() % 100; + if (0 != pThreadInfo->stbInfo->disorderRatio && + rand_num < pThreadInfo->stbInfo->disorderRatio) { + int64_t d = + pThreadInfo->lastTs - + (taosRandom() % pThreadInfo->stbInfo->disorderRange + 1); + generateStbRowData(pThreadInfo->stbInfo, data, MAX_DATA_SIZE, d); + } else { + generateStbRowData(pThreadInfo->stbInfo, data, MAX_DATA_SIZE, + pThreadInfo->lastTs += 1000); + } + pstr += sprintf(pstr, "%s", data); + pThreadInfo->counter++; + + if (pThreadInfo->counter >= pThreadInfo->stbInfo->insertRows) { + break; + } + } + + if (insert_interval) { + pThreadInfo->st = taosGetTimestampMs(); + } + taos_query_a(pThreadInfo->taos, buffer, callBack, pThreadInfo); + free(buffer); + + taos_free_result(res); +} + +void *asyncWrite(void *sarg) { + threadInfo * pThreadInfo = (threadInfo *)sarg; + SSuperTable *stbInfo = pThreadInfo->stbInfo; + + setThreadName("asyncWrite"); + + pThreadInfo->st = 0; + pThreadInfo->et = 0; + pThreadInfo->lastTs = pThreadInfo->start_time; + + int insert_interval = + (int)(stbInfo ? stbInfo->insertInterval : g_args.insert_interval); + if (insert_interval) { + pThreadInfo->st = taosGetTimestampMs(); + } + taos_query_a(pThreadInfo->taos, "show databases", callBack, pThreadInfo); + + tsem_wait(&(pThreadInfo->lock_sem)); + + return NULL; +} + +int startMultiThreadInsertData(int threads, char *db_name, char *precision, + SSuperTable *stbInfo) { + int32_t timePrec = TSDB_TIME_PRECISION_MILLI; + if (stbInfo) { + stbInfo->tsPrecision = TSDB_SML_TIMESTAMP_MILLI_SECONDS; + } + + if (0 != precision[0]) { + if (0 == strncasecmp(precision, "ms", 2)) { + timePrec = TSDB_TIME_PRECISION_MILLI; + if (stbInfo) { + stbInfo->tsPrecision = TSDB_SML_TIMESTAMP_MILLI_SECONDS; + } + } else if (0 == strncasecmp(precision, "us", 2)) { + timePrec = TSDB_TIME_PRECISION_MICRO; + if (stbInfo) { + stbInfo->tsPrecision = TSDB_SML_TIMESTAMP_MICRO_SECONDS; + } + } else if (0 == strncasecmp(precision, "ns", 2)) { + timePrec = TSDB_TIME_PRECISION_NANO; + if (stbInfo) { + stbInfo->tsPrecision = TSDB_SML_TIMESTAMP_NANO_SECONDS; + } + } else { + errorPrint("Not support precision: %s\n", precision); + return -1; + } + } + if (stbInfo) { + if (stbInfo->iface == SML_IFACE) { + if (stbInfo->lineProtocol != TSDB_SML_LINE_PROTOCOL) { + if (stbInfo->columnCount != 1) { + errorPrint( + "Schemaless telnet/json protocol can only have 1 " + "column " + "instead of %d\n", + stbInfo->columnCount); + return -1; + } + stbInfo->tsPrecision = TSDB_SML_TIMESTAMP_NOT_CONFIGURED; + } + if (stbInfo->lineProtocol != TSDB_SML_JSON_PROTOCOL) { + calcRowLen(stbInfo); + } + } + } + + int64_t startTime; + if (stbInfo) { + if (0 == strncasecmp(stbInfo->startTimestamp, "now", 3)) { + startTime = taosGetTimestamp(timePrec); + } else { + if (TSDB_CODE_SUCCESS != + taosParseTime(stbInfo->startTimestamp, &startTime, + (int32_t)strlen(stbInfo->startTimestamp), + timePrec, 0)) { + errorPrint("failed to parse time %s\n", + stbInfo->startTimestamp); + return -1; + } + } + } else { + startTime = DEFAULT_START_TIME; + } + debugPrint("%s() LN%d, startTime= %" PRId64 "\n", __func__, __LINE__, + startTime); + + // read sample data from file first + int ret; + if (stbInfo && stbInfo->iface != SML_IFACE) { + ret = prepareSampleForStb(stbInfo); + } else { + ret = prepareSampleForNtb(); + } + + if (ret) { + errorPrint("%s", "prepare sample data for stable failed!\n"); + return -1; + } + + TAOS *taos0 = taos_connect(g_Dbs.host, g_Dbs.user, g_Dbs.password, db_name, + g_Dbs.port); + if (NULL == taos0) { + errorPrint("connect to taosd fail , reason: %s\n", taos_errstr(NULL)); + return -1; + } + + int64_t ntables = 0; + uint64_t tableFrom = 0; + + if (stbInfo) { + if (stbInfo->iface != SML_IFACE) { + int64_t limit; + uint64_t offset; + + if ((NULL != g_args.sqlFile) && + (stbInfo->childTblExists == TBL_NO_EXISTS) && + ((stbInfo->childTblOffset != 0) || + (stbInfo->childTblLimit >= 0))) { + printf( + "WARNING: offset and limit will not be used since the " + "child tables not exists!\n"); + } + + if (stbInfo->childTblExists == TBL_ALREADY_EXISTS) { + if ((stbInfo->childTblLimit < 0) || + ((stbInfo->childTblOffset + stbInfo->childTblLimit) > + (stbInfo->childTblCount))) { + if (stbInfo->childTblCount < stbInfo->childTblOffset) { + printf( + "WARNING: offset will not be used since the child " + "tables count is less then offset!\n"); + + stbInfo->childTblOffset = 0; + } + stbInfo->childTblLimit = + stbInfo->childTblCount - stbInfo->childTblOffset; + } + + offset = stbInfo->childTblOffset; + limit = stbInfo->childTblLimit; + } else { + limit = stbInfo->childTblCount; + offset = 0; + } + + ntables = limit; + tableFrom = offset; + + if ((stbInfo->childTblExists != TBL_NO_EXISTS) && + ((stbInfo->childTblOffset + stbInfo->childTblLimit) > + stbInfo->childTblCount)) { + printf( + "WARNING: specified offset + limit > child table count!\n"); + prompt(); + } + + if ((stbInfo->childTblExists != TBL_NO_EXISTS) && + (0 == stbInfo->childTblLimit)) { + printf( + "WARNING: specified limit = 0, which cannot find table " + "name to insert or query! \n"); + prompt(); + } + + stbInfo->childTblName = + (char *)calloc(1, limit * TSDB_TABLE_NAME_LEN); + if (NULL == stbInfo->childTblName) { + errorPrint("%s", "failed to allocate memory\n"); + return -1; + } + + int64_t childTblCount; + getChildNameOfSuperTableWithLimitAndOffset( + taos0, db_name, stbInfo->stbName, &stbInfo->childTblName, + &childTblCount, limit, offset, stbInfo->escapeChar); + ntables = childTblCount; + } else { + ntables = stbInfo->childTblCount; + } + } else { + ntables = g_args.ntables; + tableFrom = 0; + } + + taos_close(taos0); + + int64_t a = ntables / threads; + if (a < 1) { + threads = (int)ntables; + a = 1; + } + + int64_t b = 0; + if (threads != 0) { + b = ntables % threads; + } + + if (g_args.iface == REST_IFACE || + ((stbInfo) && (stbInfo->iface == REST_IFACE))) { + if (convertHostToServAddr(g_Dbs.host, g_Dbs.port, &(g_Dbs.serv_addr)) != + 0) { + errorPrint("%s\n", "convert host to server address"); + return -1; + } + } + + pthread_t *pids = calloc(1, threads * sizeof(pthread_t)); + if (pids == NULL) { + errorPrint("%s", "failed to allocate memory\n"); + return -1; + } + threadInfo *infos = calloc(1, threads * sizeof(threadInfo)); + if (infos == NULL) { + errorPrint("%s", "failed to allocate memory\n"); + tmfree(pids); + return -1; + } + + char *stmtBuffer = calloc(1, BUFFER_SIZE); + if (stmtBuffer == NULL) { + errorPrint("%s", "failed to allocate memory\n"); + tmfree(pids); + tmfree(infos); + return -1; + } + + uint32_t interlaceRows = 0; + uint32_t batch; + + if (stbInfo) { + if (stbInfo->interlaceRows < stbInfo->insertRows) + interlaceRows = stbInfo->interlaceRows; + } else { + if (g_args.interlaceRows < g_args.insertRows) + interlaceRows = g_args.interlaceRows; + } + + if (interlaceRows > 0) { + batch = interlaceRows; + } else { + batch = (uint32_t)((g_args.reqPerReq > g_args.insertRows) + ? g_args.insertRows + : g_args.reqPerReq); + } + + if ((g_args.iface == STMT_IFACE) || + ((stbInfo) && (stbInfo->iface == STMT_IFACE))) { + char *pstr = stmtBuffer; + + if ((stbInfo) && (AUTO_CREATE_SUBTBL == stbInfo->autoCreateTable)) { + pstr += sprintf(pstr, "INSERT INTO ? USING %s TAGS(?", + stbInfo->stbName); + for (int tag = 0; tag < (stbInfo->tagCount - 1); tag++) { + pstr += sprintf(pstr, ",?"); + } + pstr += sprintf(pstr, ") VALUES(?"); + } else { + pstr += sprintf(pstr, "INSERT INTO ? VALUES(?"); + } + + int columnCount = (stbInfo) ? stbInfo->columnCount : g_args.columnCount; + + for (int col = 0; col < columnCount; col++) { + pstr += sprintf(pstr, ",?"); + } + pstr += sprintf(pstr, ")"); + + debugPrint("%s() LN%d, stmtBuffer: %s", __func__, __LINE__, stmtBuffer); + parseSamplefileToStmtBatch(stbInfo); + } + + for (int i = 0; i < threads; i++) { + threadInfo *pThreadInfo = infos + i; + pThreadInfo->threadID = i; + + tstrncpy(pThreadInfo->db_name, db_name, TSDB_DB_NAME_LEN); + pThreadInfo->time_precision = timePrec; + pThreadInfo->stbInfo = stbInfo; + + pThreadInfo->start_time = startTime; + pThreadInfo->minDelay = UINT64_MAX; + + if ((NULL == stbInfo) || (stbInfo->iface != REST_IFACE)) { + // t_info->taos = taos; + pThreadInfo->taos = taos_connect( + g_Dbs.host, g_Dbs.user, g_Dbs.password, db_name, g_Dbs.port); + if (NULL == pThreadInfo->taos) { + free(infos); + errorPrint( + "connect to server fail from insert sub " + "thread,reason:%s\n ", + taos_errstr(NULL)); + return -1; + } + + if ((g_args.iface == STMT_IFACE) || + ((stbInfo) && (stbInfo->iface == STMT_IFACE))) { + pThreadInfo->stmt = taos_stmt_init(pThreadInfo->taos); + if (NULL == pThreadInfo->stmt) { + free(pids); + free(infos); + errorPrint("taos_stmt_init() failed, reason: %s\n", + taos_errstr(NULL)); + return -1; + } + + if (0 != taos_stmt_prepare(pThreadInfo->stmt, stmtBuffer, 0)) { + free(pids); + free(infos); + free(stmtBuffer); + errorPrint( + "failed to execute taos_stmt_prepare. return 0x%x. " + "reason: %s\n", + ret, taos_stmt_errstr(pThreadInfo->stmt)); + return -1; + } + pThreadInfo->bind_ts = malloc(sizeof(int64_t)); + + if (stbInfo) { + parseStbSampleToStmtBatchForThread(pThreadInfo, stbInfo, + timePrec, batch); + + } else { + parseNtbSampleToStmtBatchForThread(pThreadInfo, timePrec, + batch); + } + } + } else { + pThreadInfo->taos = NULL; + } + + /* if ((NULL == stbInfo) + || (0 == stbInfo->multiThreadWriteOneTbl)) { + */ + pThreadInfo->start_table_from = tableFrom; + pThreadInfo->ntables = i < b ? a + 1 : a; + pThreadInfo->end_table_to = i < b ? tableFrom + a : tableFrom + a - 1; + tableFrom = pThreadInfo->end_table_to + 1; + /* } else { + pThreadInfo->start_table_from = 0; + pThreadInfo->ntables = stbInfo->childTblCount; + pThreadInfo->start_time = pThreadInfo->start_time + rand_int() % + 10000 - rand_tinyint(); + } + */ + if (g_args.iface == REST_IFACE || + ((stbInfo) && (stbInfo->iface == REST_IFACE))) { +#ifdef WINDOWS + WSADATA wsaData; + WSAStartup(MAKEWORD(2, 2), &wsaData); + SOCKET sockfd; +#else + int sockfd; +#endif + sockfd = socket(AF_INET, SOCK_STREAM, 0); + if (sockfd < 0) { +#ifdef WINDOWS + errorPrint("Could not create socket : %d", WSAGetLastError()); +#endif + debugPrint("%s() LN%d, sockfd=%d\n", __func__, __LINE__, + sockfd); + errorPrint("%s\n", "failed to create socket"); + return -1; + } + + int retConn = connect(sockfd, (struct sockaddr *)&(g_Dbs.serv_addr), + sizeof(struct sockaddr)); + debugPrint("%s() LN%d connect() return %d\n", __func__, __LINE__, + retConn); + if (retConn < 0) { + errorPrint("%s\n", "failed to connect"); + return -1; + } + pThreadInfo->sockfd = sockfd; + } + + tsem_init(&(pThreadInfo->lock_sem), 0, 0); + if (ASYNC_MODE == g_Dbs.asyncMode) { + pthread_create(pids + i, NULL, asyncWrite, pThreadInfo); + } else { + pthread_create(pids + i, NULL, syncWrite, pThreadInfo); + } + } + + free(stmtBuffer); + + int64_t start = taosGetTimestampUs(); + + for (int i = 0; i < threads; i++) { + pthread_join(pids[i], NULL); + } + + uint64_t totalDelay = 0; + uint64_t maxDelay = 0; + uint64_t minDelay = UINT64_MAX; + uint64_t cntDelay = 0; + double avgDelay = 0; + + for (int i = 0; i < threads; i++) { + threadInfo *pThreadInfo = infos + i; + + tsem_destroy(&(pThreadInfo->lock_sem)); + taos_close(pThreadInfo->taos); + + if (pThreadInfo->stmt) { + taos_stmt_close(pThreadInfo->stmt); + } + + tmfree((char *)pThreadInfo->bind_ts); + + tmfree((char *)pThreadInfo->bind_ts_array); + tmfree(pThreadInfo->bindParams); + tmfree(pThreadInfo->is_null); + if (g_args.iface == REST_IFACE || + ((stbInfo) && (stbInfo->iface == REST_IFACE))) { +#ifdef WINDOWS + closesocket(pThreadInfo->sockfd); + WSACleanup(); +#else + close(pThreadInfo->sockfd); +#endif + } + + debugPrint("%s() LN%d, [%d] totalInsert=%" PRIu64 + " totalAffected=%" PRIu64 "\n", + __func__, __LINE__, pThreadInfo->threadID, + pThreadInfo->totalInsertRows, + pThreadInfo->totalAffectedRows); + if (stbInfo) { + stbInfo->totalAffectedRows += pThreadInfo->totalAffectedRows; + stbInfo->totalInsertRows += pThreadInfo->totalInsertRows; + } else { + g_args.totalAffectedRows += pThreadInfo->totalAffectedRows; + g_args.totalInsertRows += pThreadInfo->totalInsertRows; + } + + totalDelay += pThreadInfo->totalDelay; + cntDelay += pThreadInfo->cntDelay; + if (pThreadInfo->maxDelay > maxDelay) maxDelay = pThreadInfo->maxDelay; + if (pThreadInfo->minDelay < minDelay) minDelay = pThreadInfo->minDelay; + } + + if (cntDelay == 0) cntDelay = 1; + avgDelay = (double)totalDelay / cntDelay; + + int64_t end = taosGetTimestampUs(); + int64_t t = end - start; + if (0 == t) t = 1; + + double tInMs = (double)t / 1000000.0; + + if (stbInfo) { + fprintf(stderr, + "Spent %.4f seconds to insert rows: %" PRIu64 + ", affected rows: %" PRIu64 + " with %d thread(s) into %s.%s. %.2f records/second\n\n", + tInMs, stbInfo->totalInsertRows, stbInfo->totalAffectedRows, + threads, db_name, stbInfo->stbName, + (double)(stbInfo->totalInsertRows / tInMs)); + + if (g_fpOfInsertResult) { + fprintf(g_fpOfInsertResult, + "Spent %.4f seconds to insert rows: %" PRIu64 + ", affected rows: %" PRIu64 + " with %d thread(s) into %s.%s. %.2f records/second\n\n", + tInMs, stbInfo->totalInsertRows, stbInfo->totalAffectedRows, + threads, db_name, stbInfo->stbName, + (double)(stbInfo->totalInsertRows / tInMs)); + } + } else { + fprintf(stderr, + "Spent %.4f seconds to insert rows: %" PRIu64 + ", affected rows: %" PRIu64 + " with %d thread(s) into %s %.2f records/second\n\n", + tInMs, g_args.totalInsertRows, g_args.totalAffectedRows, + threads, db_name, (double)(g_args.totalInsertRows / tInMs)); + if (g_fpOfInsertResult) { + fprintf(g_fpOfInsertResult, + "Spent %.4f seconds to insert rows: %" PRIu64 + ", affected rows: %" PRIu64 + " with %d thread(s) into %s %.2f records/second\n\n", + tInMs, g_args.totalInsertRows, g_args.totalAffectedRows, + threads, db_name, (double)(g_args.totalInsertRows / tInMs)); + } + } + + if (minDelay != UINT64_MAX) { + fprintf(stderr, + "insert delay, avg: %10.2fms, max: %10.2fms, min: %10.2fms\n\n", + (double)avgDelay / 1000.0, (double)maxDelay / 1000.0, + (double)minDelay / 1000.0); + + if (g_fpOfInsertResult) { + fprintf( + g_fpOfInsertResult, + "insert delay, avg:%10.2fms, max: %10.2fms, min: %10.2fms\n\n", + (double)avgDelay / 1000.0, (double)maxDelay / 1000.0, + (double)minDelay / 1000.0); + } + } + + // taos_close(taos); + + free(pids); + free(infos); + return 0; +} + +int insertTestProcess() { + int32_t code = -1; + char * cmdBuffer = calloc(1, BUFFER_SIZE); + if (NULL == cmdBuffer) { + errorPrint("%s", "failed to allocate memory\n"); + goto end_insert_process; + } + + printfInsertMeta(); + + debugPrint("%d result file: %s\n", __LINE__, g_Dbs.resultFile); + g_fpOfInsertResult = fopen(g_Dbs.resultFile, "a"); + if (NULL == g_fpOfInsertResult) { + errorPrint("failed to open %s for save result\n", g_Dbs.resultFile); + goto end_insert_process; + } + + if (g_fpOfInsertResult) { + printfInsertMetaToFile(g_fpOfInsertResult); + } + + prompt(); + + if (init_rand_data()) { + goto end_insert_process; + } + + // create database and super tables + + if (createDatabasesAndStables(cmdBuffer)) { + goto end_insert_process; + } + + // pretreatment + if (prepareSampleData()) { + goto end_insert_process; + } + + if (g_args.iface != SML_IFACE && g_totalChildTables > 0) { + if (createChildTables()) { + goto end_insert_process; + } + } + // create sub threads for inserting data + // start = taosGetTimestampMs(); + for (int i = 0; i < g_Dbs.dbCount; i++) { + if (g_Dbs.use_metric) { + if (g_Dbs.db[i].superTblCount > 0) { + for (uint64_t j = 0; j < g_Dbs.db[i].superTblCount; j++) { + SSuperTable *stbInfo = &g_Dbs.db[i].superTbls[j]; + + if (stbInfo && (stbInfo->insertRows > 0)) { + if (startMultiThreadInsertData( + g_Dbs.threadCount, g_Dbs.db[i].dbName, + g_Dbs.db[i].dbCfg.precision, stbInfo)) { + goto end_insert_process; + } + } + } + } + } else { + if (SML_IFACE == g_args.iface) { + code = -1; + errorPrint("%s\n", "Schemaless insertion must include stable"); + goto end_insert_process; + } else { + if (startMultiThreadInsertData( + g_Dbs.threadCount, g_Dbs.db[i].dbName, + g_Dbs.db[i].dbCfg.precision, NULL)) { + goto end_insert_process; + } + } + } + } + code = 0; +end_insert_process: + tmfree(cmdBuffer); + return code; +} \ No newline at end of file diff --git a/src/kit/taosdemo/src/demoJsonOpt.c b/src/kit/taosdemo/src/demoJsonOpt.c new file mode 100644 index 0000000000000000000000000000000000000000..e74d2906c8f3294f0531145c8f13e5ce776e444f --- /dev/null +++ b/src/kit/taosdemo/src/demoJsonOpt.c @@ -0,0 +1,1777 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#include "cJSON.h" +#include "demo.h" + +int getColumnAndTagTypeFromInsertJsonFile(cJSON * stbInfo, + SSuperTable *superTbls) { + int32_t code = -1; + + // columns + cJSON *columns = cJSON_GetObjectItem(stbInfo, "columns"); + if (columns && columns->type != cJSON_Array) { + errorPrint("%s", "failed to read json, columns not found\n"); + goto PARSE_OVER; + } else if (NULL == columns) { + superTbls->columnCount = 0; + superTbls->tagCount = 0; + return 0; + } + + int columnSize = cJSON_GetArraySize(columns); + if ((columnSize + 1 /* ts */) > TSDB_MAX_COLUMNS) { + errorPrint( + "failed to read json, column size overflow, max column size is " + "%d\n", + TSDB_MAX_COLUMNS); + goto PARSE_OVER; + } + + int count = 1; + int index = 0; + StrColumn columnCase; + + // superTbls->columnCount = columnSize; + for (int k = 0; k < columnSize; ++k) { + cJSON *column = cJSON_GetArrayItem(columns, k); + if (column == NULL) continue; + + count = 1; + cJSON *countObj = cJSON_GetObjectItem(column, "count"); + if (countObj && countObj->type == cJSON_Number) { + count = (int)countObj->valueint; + } else if (countObj && countObj->type != cJSON_Number) { + errorPrint("%s", "failed to read json, column count not found\n"); + goto PARSE_OVER; + } else { + count = 1; + } + + // column info + memset(&columnCase, 0, sizeof(StrColumn)); + cJSON *dataType = cJSON_GetObjectItem(column, "type"); + if (!dataType || dataType->type != cJSON_String || + dataType->valuestring == NULL) { + errorPrint("%s", "failed to read json, column type not found\n"); + goto PARSE_OVER; + } + // tstrncpy(superTbls->columns[k].dataType, dataType->valuestring, + // DATATYPE_BUFF_LEN); + tstrncpy(columnCase.dataType, dataType->valuestring, + min(DATATYPE_BUFF_LEN, strlen(dataType->valuestring) + 1)); + + cJSON *dataLen = cJSON_GetObjectItem(column, "len"); + if (dataLen && dataLen->type == cJSON_Number) { + columnCase.dataLen = (uint32_t)dataLen->valueint; + } else if (dataLen && dataLen->type != cJSON_Number) { + debugPrint("%s() LN%d: failed to read json, column len not found\n", + __func__, __LINE__); + goto PARSE_OVER; + } else { + columnCase.dataLen = SMALL_BUFF_LEN; + } + + for (int n = 0; n < count; ++n) { + tstrncpy(superTbls->columns[index].dataType, columnCase.dataType, + min(DATATYPE_BUFF_LEN, strlen(columnCase.dataType) + 1)); + + superTbls->columns[index].dataLen = columnCase.dataLen; + index++; + } + } + + if ((index + 1 /* ts */) > MAX_NUM_COLUMNS) { + errorPrint( + "failed to read json, column size overflow, allowed max column " + "size is %d\n", + MAX_NUM_COLUMNS); + goto PARSE_OVER; + } + + superTbls->columnCount = index; + + for (int c = 0; c < superTbls->columnCount; c++) { + if (0 == + strncasecmp(superTbls->columns[c].dataType, "INT", strlen("INT"))) { + superTbls->columns[c].data_type = TSDB_DATA_TYPE_INT; + } else if (0 == strncasecmp(superTbls->columns[c].dataType, "TINYINT", + strlen("TINYINT"))) { + superTbls->columns[c].data_type = TSDB_DATA_TYPE_TINYINT; + } else if (0 == strncasecmp(superTbls->columns[c].dataType, "SMALLINT", + strlen("SMALLINT"))) { + superTbls->columns[c].data_type = TSDB_DATA_TYPE_SMALLINT; + } else if (0 == strncasecmp(superTbls->columns[c].dataType, "BIGINT", + strlen("BIGINT"))) { + superTbls->columns[c].data_type = TSDB_DATA_TYPE_BIGINT; + } else if (0 == strncasecmp(superTbls->columns[c].dataType, "FLOAT", + strlen("FLOAT"))) { + superTbls->columns[c].data_type = TSDB_DATA_TYPE_FLOAT; + } else if (0 == strncasecmp(superTbls->columns[c].dataType, "DOUBLE", + strlen("DOUBLE"))) { + superTbls->columns[c].data_type = TSDB_DATA_TYPE_DOUBLE; + } else if (0 == strncasecmp(superTbls->columns[c].dataType, "BINARY", + strlen("BINARY"))) { + superTbls->columns[c].data_type = TSDB_DATA_TYPE_BINARY; + } else if (0 == strncasecmp(superTbls->columns[c].dataType, "NCHAR", + strlen("NCHAR"))) { + superTbls->columns[c].data_type = TSDB_DATA_TYPE_NCHAR; + } else if (0 == strncasecmp(superTbls->columns[c].dataType, "BOOL", + strlen("BOOL"))) { + superTbls->columns[c].data_type = TSDB_DATA_TYPE_BOOL; + } else if (0 == strncasecmp(superTbls->columns[c].dataType, "TIMESTAMP", + strlen("TIMESTAMP"))) { + superTbls->columns[c].data_type = TSDB_DATA_TYPE_TIMESTAMP; + } else if (0 == strncasecmp(superTbls->columns[c].dataType, "UTINYINT", + strlen("UTINYINT"))) { + superTbls->columns[c].data_type = TSDB_DATA_TYPE_UTINYINT; + } else if (0 == strncasecmp(superTbls->columns[c].dataType, "USMALLINT", + strlen("USMALLINT"))) { + superTbls->columns[c].data_type = TSDB_DATA_TYPE_USMALLINT; + } else if (0 == strncasecmp(superTbls->columns[c].dataType, "UINT", + strlen("UINT"))) { + superTbls->columns[c].data_type = TSDB_DATA_TYPE_UINT; + } else if (0 == strncasecmp(superTbls->columns[c].dataType, "UBIGINT", + strlen("UBIGINT"))) { + superTbls->columns[c].data_type = TSDB_DATA_TYPE_UBIGINT; + } else { + superTbls->columns[c].data_type = TSDB_DATA_TYPE_NULL; + } + } + + count = 1; + index = 0; + // tags + cJSON *tags = cJSON_GetObjectItem(stbInfo, "tags"); + if (!tags || tags->type != cJSON_Array) { + errorPrint("%s", "failed to read json, tags not found\n"); + goto PARSE_OVER; + } + + int tagSize = cJSON_GetArraySize(tags); + if (tagSize > TSDB_MAX_TAGS) { + errorPrint( + "failed to read json, tags size overflow, max tag size is %d\n", + TSDB_MAX_TAGS); + goto PARSE_OVER; + } + + // superTbls->tagCount = tagSize; + for (int k = 0; k < tagSize; ++k) { + cJSON *tag = cJSON_GetArrayItem(tags, k); + if (tag == NULL) continue; + + count = 1; + cJSON *countObj = cJSON_GetObjectItem(tag, "count"); + if (countObj && countObj->type == cJSON_Number) { + count = (int)countObj->valueint; + } else if (countObj && countObj->type != cJSON_Number) { + errorPrint("%s", "failed to read json, column count not found\n"); + goto PARSE_OVER; + } else { + count = 1; + } + + // column info + memset(&columnCase, 0, sizeof(StrColumn)); + cJSON *dataType = cJSON_GetObjectItem(tag, "type"); + if (!dataType || dataType->type != cJSON_String || + dataType->valuestring == NULL) { + errorPrint("%s", "failed to read json, tag type not found\n"); + goto PARSE_OVER; + } + tstrncpy(columnCase.dataType, dataType->valuestring, + min(DATATYPE_BUFF_LEN, strlen(dataType->valuestring) + 1)); + + cJSON *dataLen = cJSON_GetObjectItem(tag, "len"); + if (dataLen && dataLen->type == cJSON_Number) { + columnCase.dataLen = (uint32_t)dataLen->valueint; + } else if (dataLen && dataLen->type != cJSON_Number) { + errorPrint("%s", "failed to read json, column len not found\n"); + goto PARSE_OVER; + } else { + columnCase.dataLen = 0; + } + + for (int n = 0; n < count; ++n) { + tstrncpy(superTbls->tags[index].dataType, columnCase.dataType, + min(DATATYPE_BUFF_LEN, strlen(columnCase.dataType) + 1)); + superTbls->tags[index].dataLen = columnCase.dataLen; + index++; + } + } + + if (index > TSDB_MAX_TAGS) { + errorPrint( + "failed to read json, tags size overflow, allowed max tag count is " + "%d\n", + TSDB_MAX_TAGS); + goto PARSE_OVER; + } + + superTbls->tagCount = index; + + for (int t = 0; t < superTbls->tagCount; t++) { + if (0 == + strncasecmp(superTbls->tags[t].dataType, "INT", strlen("INT"))) { + superTbls->tags[t].data_type = TSDB_DATA_TYPE_INT; + } else if (0 == strncasecmp(superTbls->tags[t].dataType, "TINYINT", + strlen("TINYINT"))) { + superTbls->tags[t].data_type = TSDB_DATA_TYPE_TINYINT; + } else if (0 == strncasecmp(superTbls->tags[t].dataType, "SMALLINT", + strlen("SMALLINT"))) { + superTbls->tags[t].data_type = TSDB_DATA_TYPE_SMALLINT; + } else if (0 == strncasecmp(superTbls->tags[t].dataType, "BIGINT", + strlen("BIGINT"))) { + superTbls->tags[t].data_type = TSDB_DATA_TYPE_BIGINT; + } else if (0 == strncasecmp(superTbls->tags[t].dataType, "FLOAT", + strlen("FLOAT"))) { + superTbls->tags[t].data_type = TSDB_DATA_TYPE_FLOAT; + } else if (0 == strncasecmp(superTbls->tags[t].dataType, "DOUBLE", + strlen("DOUBLE"))) { + superTbls->tags[t].data_type = TSDB_DATA_TYPE_DOUBLE; + } else if (0 == strncasecmp(superTbls->tags[t].dataType, "BINARY", + strlen("BINARY"))) { + superTbls->tags[t].data_type = TSDB_DATA_TYPE_BINARY; + } else if (0 == strncasecmp(superTbls->tags[t].dataType, "NCHAR", + strlen("NCHAR"))) { + superTbls->tags[t].data_type = TSDB_DATA_TYPE_NCHAR; + } else if (0 == strncasecmp(superTbls->tags[t].dataType, "BOOL", + strlen("BOOL"))) { + superTbls->tags[t].data_type = TSDB_DATA_TYPE_BOOL; + } else if (0 == strncasecmp(superTbls->tags[t].dataType, "TIMESTAMP", + strlen("TIMESTAMP"))) { + superTbls->tags[t].data_type = TSDB_DATA_TYPE_TIMESTAMP; + } else if (0 == strncasecmp(superTbls->tags[t].dataType, "UTINYINT", + strlen("UTINYINT"))) { + superTbls->tags[t].data_type = TSDB_DATA_TYPE_UTINYINT; + } else if (0 == strncasecmp(superTbls->tags[t].dataType, "USMALLINT", + strlen("USMALLINT"))) { + superTbls->tags[t].data_type = TSDB_DATA_TYPE_USMALLINT; + } else if (0 == strncasecmp(superTbls->tags[t].dataType, "UINT", + strlen("UINT"))) { + superTbls->tags[t].data_type = TSDB_DATA_TYPE_UINT; + } else if (0 == strncasecmp(superTbls->tags[t].dataType, "UBIGINT", + strlen("UBIGINT"))) { + superTbls->tags[t].data_type = TSDB_DATA_TYPE_UBIGINT; + } else { + superTbls->tags[t].data_type = TSDB_DATA_TYPE_NULL; + } + } + + if ((superTbls->columnCount + superTbls->tagCount + 1 /* ts */) > + TSDB_MAX_COLUMNS) { + errorPrint( + "columns + tags is more than allowed max columns count: %d\n", + TSDB_MAX_COLUMNS); + goto PARSE_OVER; + } + code = 0; + +PARSE_OVER: + return code; +} + +int getMetaFromInsertJsonFile(cJSON *root) { + int32_t code = -1; + + cJSON *cfgdir = cJSON_GetObjectItem(root, "cfgdir"); + if (cfgdir && cfgdir->type == cJSON_String && cfgdir->valuestring != NULL) { + tstrncpy(g_Dbs.cfgDir, cfgdir->valuestring, MAX_FILE_NAME_LEN); + } + + cJSON *host = cJSON_GetObjectItem(root, "host"); + if (host && host->type == cJSON_String && host->valuestring != NULL) { + tstrncpy(g_Dbs.host, host->valuestring, MAX_HOSTNAME_SIZE); + } else if (!host) { + tstrncpy(g_Dbs.host, "127.0.0.1", MAX_HOSTNAME_SIZE); + } else { + errorPrint("%s", "failed to read json, host not found\n"); + goto PARSE_OVER; + } + + cJSON *port = cJSON_GetObjectItem(root, "port"); + if (port && port->type == cJSON_Number) { + g_Dbs.port = (uint16_t)port->valueint; + } else if (!port) { + g_Dbs.port = DEFAULT_PORT; + } + + cJSON *user = cJSON_GetObjectItem(root, "user"); + if (user && user->type == cJSON_String && user->valuestring != NULL) { + tstrncpy(g_Dbs.user, user->valuestring, MAX_USERNAME_SIZE); + } else if (!user) { + tstrncpy(g_Dbs.user, TSDB_DEFAULT_USER, MAX_USERNAME_SIZE); + } + + cJSON *password = cJSON_GetObjectItem(root, "password"); + if (password && password->type == cJSON_String && + password->valuestring != NULL) { + tstrncpy(g_Dbs.password, password->valuestring, SHELL_MAX_PASSWORD_LEN); + } else if (!password) { + tstrncpy(g_Dbs.password, TSDB_DEFAULT_PASS, SHELL_MAX_PASSWORD_LEN); + } + + cJSON *resultfile = cJSON_GetObjectItem(root, "result_file"); + if (resultfile && resultfile->type == cJSON_String && + resultfile->valuestring != NULL) { + tstrncpy(g_Dbs.resultFile, resultfile->valuestring, MAX_FILE_NAME_LEN); + } else if (!resultfile) { + tstrncpy(g_Dbs.resultFile, DEFAULT_OUTPUT, MAX_FILE_NAME_LEN); + } + + cJSON *threads = cJSON_GetObjectItem(root, "thread_count"); + if (threads && threads->type == cJSON_Number) { + g_Dbs.threadCount = (uint32_t)threads->valueint; + } else if (!threads) { + g_Dbs.threadCount = DEFAULT_NTHREADS; + } else { + errorPrint("%s", "failed to read json, threads not found\n"); + goto PARSE_OVER; + } + + cJSON *threads2 = cJSON_GetObjectItem(root, "thread_count_create_tbl"); + if (threads2 && threads2->type == cJSON_Number) { + g_Dbs.threadCountForCreateTbl = (uint32_t)threads2->valueint; + } else if (!threads2) { + g_Dbs.threadCountForCreateTbl = DEFAULT_NTHREADS; + } else { + errorPrint("%s", "failed to read json, threads2 not found\n"); + goto PARSE_OVER; + } + + cJSON *gInsertInterval = cJSON_GetObjectItem(root, "insert_interval"); + if (gInsertInterval && gInsertInterval->type == cJSON_Number) { + if (gInsertInterval->valueint < 0) { + errorPrint("%s", + "failed to read json, insert interval input mistake\n"); + goto PARSE_OVER; + } + g_args.insert_interval = gInsertInterval->valueint; + } else if (!gInsertInterval) { + g_args.insert_interval = DEFAULT_INSERT_INTERVAL; + } else { + errorPrint("%s", + "failed to read json, insert_interval input mistake\n"); + goto PARSE_OVER; + } + + cJSON *interlaceRows = cJSON_GetObjectItem(root, "interlace_rows"); + if (interlaceRows && interlaceRows->type == cJSON_Number) { + if (interlaceRows->valueint < 0) { + errorPrint("%s", + "failed to read json, interlaceRows input mistake\n"); + goto PARSE_OVER; + } + g_args.interlaceRows = (uint32_t)interlaceRows->valueint; + } else if (!interlaceRows) { + g_args.interlaceRows = + DEFAULT_INTERLACE_ROWS; // 0 means progressive mode, > 0 mean + // interlace mode. max value is less or equ + // num_of_records_per_req + } else { + errorPrint("%s", "failed to read json, interlaceRows input mistake\n"); + goto PARSE_OVER; + } + + cJSON *maxSqlLen = cJSON_GetObjectItem(root, "max_sql_len"); + if (maxSqlLen && maxSqlLen->type == cJSON_Number) { + if (maxSqlLen->valueint < 0) { + errorPrint( + "%s() LN%d, failed to read json, max_sql_len input mistake\n", + __func__, __LINE__); + goto PARSE_OVER; + } + g_args.max_sql_len = maxSqlLen->valueint; + } else if (!maxSqlLen) { + g_args.max_sql_len = TSDB_MAX_ALLOWED_SQL_LEN; + } else { + errorPrint( + "%s() LN%d, failed to read json, max_sql_len input mistake\n", + __func__, __LINE__); + goto PARSE_OVER; + } + + cJSON *numRecPerReq = cJSON_GetObjectItem(root, "num_of_records_per_req"); + if (numRecPerReq && numRecPerReq->type == cJSON_Number) { + if (numRecPerReq->valueint <= 0) { + errorPrint( + "%s() LN%d, failed to read json, num_of_records_per_req input " + "mistake\n", + __func__, __LINE__); + goto PARSE_OVER; + } else if (numRecPerReq->valueint > MAX_RECORDS_PER_REQ) { + printf("NOTICE: number of records per request value %" PRIu64 + " > %d\n\n", + numRecPerReq->valueint, MAX_RECORDS_PER_REQ); + printf( + " number of records per request value will be set to " + "%d\n\n", + MAX_RECORDS_PER_REQ); + prompt(); + numRecPerReq->valueint = MAX_RECORDS_PER_REQ; + } + g_args.reqPerReq = (uint32_t)numRecPerReq->valueint; + } else if (!numRecPerReq) { + g_args.reqPerReq = MAX_RECORDS_PER_REQ; + } else { + errorPrint( + "%s() LN%d, failed to read json, num_of_records_per_req not " + "found\n", + __func__, __LINE__); + goto PARSE_OVER; + } + + cJSON *prepareRand = cJSON_GetObjectItem(root, "prepared_rand"); + if (prepareRand && prepareRand->type == cJSON_Number) { + if (prepareRand->valueint <= 0) { + errorPrint( + "%s() LN%d, failed to read json, prepared_rand input mistake\n", + __func__, __LINE__); + goto PARSE_OVER; + } + g_args.prepared_rand = prepareRand->valueint; + } else if (!prepareRand) { + g_args.prepared_rand = DEFAULT_PREPARED_RAND; + } else { + errorPrint("%s", "failed to read json, prepared_rand not found\n"); + goto PARSE_OVER; + } + + cJSON *answerPrompt = + cJSON_GetObjectItem(root, "confirm_parameter_prompt"); // yes, no, + if (answerPrompt && answerPrompt->type == cJSON_String && + answerPrompt->valuestring != NULL) { + if (0 == strncasecmp(answerPrompt->valuestring, "yes", 3)) { + g_args.answer_yes = false; + } else if (0 == strncasecmp(answerPrompt->valuestring, "no", 2)) { + g_args.answer_yes = true; + } else { + g_args.answer_yes = DEFAULT_ANS_YES; + } + } else if (!answerPrompt) { + g_args.answer_yes = true; // default is no, mean answer_yes. + } else { + errorPrint( + "%s", + "failed to read json, confirm_parameter_prompt input mistake\n"); + goto PARSE_OVER; + } + + // rows per table need be less than insert batch + if (g_args.interlaceRows > g_args.reqPerReq) { + printf( + "NOTICE: interlace rows value %u > num_of_records_per_req %u\n\n", + g_args.interlaceRows, g_args.reqPerReq); + printf( + " interlace rows value will be set to " + "num_of_records_per_req %u\n\n", + g_args.reqPerReq); + prompt(); + g_args.interlaceRows = g_args.reqPerReq; + } + + cJSON *dbs = cJSON_GetObjectItem(root, "databases"); + if (!dbs || dbs->type != cJSON_Array) { + errorPrint("%s", "failed to read json, databases not found\n"); + goto PARSE_OVER; + } + + int dbSize = cJSON_GetArraySize(dbs); + if (dbSize > MAX_DB_COUNT) { + errorPrint( + "failed to read json, databases size overflow, max database is " + "%d\n", + MAX_DB_COUNT); + goto PARSE_OVER; + } + g_Dbs.db = calloc(1, sizeof(SDataBase) * dbSize); + assert(g_Dbs.db); + g_Dbs.dbCount = dbSize; + for (int i = 0; i < dbSize; ++i) { + cJSON *dbinfos = cJSON_GetArrayItem(dbs, i); + if (dbinfos == NULL) continue; + + // dbinfo + cJSON *dbinfo = cJSON_GetObjectItem(dbinfos, "dbinfo"); + if (!dbinfo || dbinfo->type != cJSON_Object) { + errorPrint("%s", "failed to read json, dbinfo not found\n"); + goto PARSE_OVER; + } + + cJSON *dbName = cJSON_GetObjectItem(dbinfo, "name"); + if (!dbName || dbName->type != cJSON_String || + dbName->valuestring == NULL) { + errorPrint("%s", "failed to read json, db name not found\n"); + goto PARSE_OVER; + } + tstrncpy(g_Dbs.db[i].dbName, dbName->valuestring, TSDB_DB_NAME_LEN); + + cJSON *drop = cJSON_GetObjectItem(dbinfo, "drop"); + if (drop && drop->type == cJSON_String && drop->valuestring != NULL) { + if (0 == strncasecmp(drop->valuestring, "yes", strlen("yes"))) { + g_Dbs.db[i].drop = true; + } else { + g_Dbs.db[i].drop = false; + } + } else if (!drop) { + g_Dbs.db[i].drop = g_args.drop_database; + } else { + errorPrint("%s", "failed to read json, drop input mistake\n"); + goto PARSE_OVER; + } + + cJSON *precision = cJSON_GetObjectItem(dbinfo, "precision"); + if (precision && precision->type == cJSON_String && + precision->valuestring != NULL) { + tstrncpy(g_Dbs.db[i].dbCfg.precision, precision->valuestring, + SMALL_BUFF_LEN); + } else if (!precision) { + memset(g_Dbs.db[i].dbCfg.precision, 0, SMALL_BUFF_LEN); + } else { + errorPrint("%s", "failed to read json, precision not found\n"); + goto PARSE_OVER; + } + + cJSON *update = cJSON_GetObjectItem(dbinfo, "update"); + if (update && update->type == cJSON_Number) { + g_Dbs.db[i].dbCfg.update = (int)update->valueint; + } else if (!update) { + g_Dbs.db[i].dbCfg.update = -1; + } else { + errorPrint("%s", "failed to read json, update not found\n"); + goto PARSE_OVER; + } + + cJSON *replica = cJSON_GetObjectItem(dbinfo, "replica"); + if (replica && replica->type == cJSON_Number) { + g_Dbs.db[i].dbCfg.replica = (int)replica->valueint; + } else if (!replica) { + g_Dbs.db[i].dbCfg.replica = -1; + } else { + errorPrint("%s", "failed to read json, replica not found\n"); + goto PARSE_OVER; + } + + cJSON *keep = cJSON_GetObjectItem(dbinfo, "keep"); + if (keep && keep->type == cJSON_Number) { + g_Dbs.db[i].dbCfg.keep = (int)keep->valueint; + } else if (!keep) { + g_Dbs.db[i].dbCfg.keep = -1; + } else { + errorPrint("%s", "failed to read json, keep not found\n"); + goto PARSE_OVER; + } + + cJSON *days = cJSON_GetObjectItem(dbinfo, "days"); + if (days && days->type == cJSON_Number) { + g_Dbs.db[i].dbCfg.days = (int)days->valueint; + } else if (!days) { + g_Dbs.db[i].dbCfg.days = -1; + } else { + errorPrint("%s", "failed to read json, days not found\n"); + goto PARSE_OVER; + } + + cJSON *cache = cJSON_GetObjectItem(dbinfo, "cache"); + if (cache && cache->type == cJSON_Number) { + g_Dbs.db[i].dbCfg.cache = (int)cache->valueint; + } else if (!cache) { + g_Dbs.db[i].dbCfg.cache = -1; + } else { + errorPrint("%s", "failed to read json, cache not found\n"); + goto PARSE_OVER; + } + + cJSON *blocks = cJSON_GetObjectItem(dbinfo, "blocks"); + if (blocks && blocks->type == cJSON_Number) { + g_Dbs.db[i].dbCfg.blocks = (int)blocks->valueint; + } else if (!blocks) { + g_Dbs.db[i].dbCfg.blocks = -1; + } else { + errorPrint("%s", "failed to read json, block not found\n"); + goto PARSE_OVER; + } + + // cJSON* maxtablesPerVnode= cJSON_GetObjectItem(dbinfo, + // "maxtablesPerVnode"); if (maxtablesPerVnode && + // maxtablesPerVnode->type + // == cJSON_Number) { + // g_Dbs.db[i].dbCfg.maxtablesPerVnode = maxtablesPerVnode->valueint; + //} else if (!maxtablesPerVnode) { + // g_Dbs.db[i].dbCfg.maxtablesPerVnode = TSDB_DEFAULT_TABLES; + //} else { + // printf("failed to read json, maxtablesPerVnode not found"); + // goto PARSE_OVER; + //} + + cJSON *minRows = cJSON_GetObjectItem(dbinfo, "minRows"); + if (minRows && minRows->type == cJSON_Number) { + g_Dbs.db[i].dbCfg.minRows = (uint32_t)minRows->valueint; + } else if (!minRows) { + g_Dbs.db[i].dbCfg.minRows = 0; // 0 means default + } else { + errorPrint("%s", "failed to read json, minRows not found\n"); + goto PARSE_OVER; + } + + cJSON *maxRows = cJSON_GetObjectItem(dbinfo, "maxRows"); + if (maxRows && maxRows->type == cJSON_Number) { + g_Dbs.db[i].dbCfg.maxRows = (uint32_t)maxRows->valueint; + } else if (!maxRows) { + g_Dbs.db[i].dbCfg.maxRows = 0; // 0 means default + } else { + errorPrint("%s", "failed to read json, maxRows not found\n"); + goto PARSE_OVER; + } + + cJSON *comp = cJSON_GetObjectItem(dbinfo, "comp"); + if (comp && comp->type == cJSON_Number) { + g_Dbs.db[i].dbCfg.comp = (int)comp->valueint; + } else if (!comp) { + g_Dbs.db[i].dbCfg.comp = -1; + } else { + errorPrint("%s", "failed to read json, comp not found\n"); + goto PARSE_OVER; + } + + cJSON *walLevel = cJSON_GetObjectItem(dbinfo, "walLevel"); + if (walLevel && walLevel->type == cJSON_Number) { + g_Dbs.db[i].dbCfg.walLevel = (int)walLevel->valueint; + } else if (!walLevel) { + g_Dbs.db[i].dbCfg.walLevel = -1; + } else { + errorPrint("%s", "failed to read json, walLevel not found\n"); + goto PARSE_OVER; + } + + cJSON *cacheLast = cJSON_GetObjectItem(dbinfo, "cachelast"); + if (cacheLast && cacheLast->type == cJSON_Number) { + g_Dbs.db[i].dbCfg.cacheLast = (int)cacheLast->valueint; + } else if (!cacheLast) { + g_Dbs.db[i].dbCfg.cacheLast = -1; + } else { + errorPrint("%s", "failed to read json, cacheLast not found\n"); + goto PARSE_OVER; + } + + cJSON *quorum = cJSON_GetObjectItem(dbinfo, "quorum"); + if (quorum && quorum->type == cJSON_Number) { + g_Dbs.db[i].dbCfg.quorum = (int)quorum->valueint; + } else if (!quorum) { + g_Dbs.db[i].dbCfg.quorum = 1; + } else { + errorPrint("%s", "failed to read json, quorum input mistake"); + goto PARSE_OVER; + } + + cJSON *fsync = cJSON_GetObjectItem(dbinfo, "fsync"); + if (fsync && fsync->type == cJSON_Number) { + g_Dbs.db[i].dbCfg.fsync = (int)fsync->valueint; + } else if (!fsync) { + g_Dbs.db[i].dbCfg.fsync = -1; + } else { + errorPrint("%s", "failed to read json, fsync input mistake\n"); + goto PARSE_OVER; + } + + // super_tables + cJSON *stables = cJSON_GetObjectItem(dbinfos, "super_tables"); + if (!stables || stables->type != cJSON_Array) { + errorPrint("%s", "failed to read json, super_tables not found\n"); + goto PARSE_OVER; + } + + int stbSize = cJSON_GetArraySize(stables); + if (stbSize > MAX_SUPER_TABLE_COUNT) { + errorPrint( + "failed to read json, supertable size overflow, max supertable " + "is %d\n", + MAX_SUPER_TABLE_COUNT); + goto PARSE_OVER; + } + g_Dbs.db[i].superTbls = calloc(1, stbSize * sizeof(SSuperTable)); + assert(g_Dbs.db[i].superTbls); + g_Dbs.db[i].superTblCount = stbSize; + for (int j = 0; j < stbSize; ++j) { + cJSON *stbInfo = cJSON_GetArrayItem(stables, j); + if (stbInfo == NULL) continue; + + // dbinfo + cJSON *stbName = cJSON_GetObjectItem(stbInfo, "name"); + if (!stbName || stbName->type != cJSON_String || + stbName->valuestring == NULL) { + errorPrint("%s", "failed to read json, stb name not found\n"); + goto PARSE_OVER; + } + tstrncpy(g_Dbs.db[i].superTbls[j].stbName, stbName->valuestring, + TSDB_TABLE_NAME_LEN); + + cJSON *prefix = cJSON_GetObjectItem(stbInfo, "childtable_prefix"); + if (!prefix || prefix->type != cJSON_String || + prefix->valuestring == NULL) { + errorPrint( + "%s", "failed to read json, childtable_prefix not found\n"); + goto PARSE_OVER; + } + tstrncpy(g_Dbs.db[i].superTbls[j].childTblPrefix, + prefix->valuestring, TBNAME_PREFIX_LEN); + + cJSON *escapeChar = + cJSON_GetObjectItem(stbInfo, "escape_character"); + if (escapeChar && escapeChar->type == cJSON_String && + escapeChar->valuestring != NULL) { + if ((0 == strncasecmp(escapeChar->valuestring, "yes", 3))) { + g_Dbs.db[i].superTbls[j].escapeChar = true; + } else if (0 == strncasecmp(escapeChar->valuestring, "no", 2)) { + g_Dbs.db[i].superTbls[j].escapeChar = false; + } else { + g_Dbs.db[i].superTbls[j].escapeChar = false; + } + } else if (!escapeChar) { + g_Dbs.db[i].superTbls[j].escapeChar = false; + } else { + errorPrint("%s", + "failed to read json, escape_character not found\n"); + goto PARSE_OVER; + } + + cJSON *autoCreateTbl = + cJSON_GetObjectItem(stbInfo, "auto_create_table"); + if (autoCreateTbl && autoCreateTbl->type == cJSON_String && + autoCreateTbl->valuestring != NULL) { + if ((0 == strncasecmp(autoCreateTbl->valuestring, "yes", 3)) && + (TBL_ALREADY_EXISTS != + g_Dbs.db[i].superTbls[j].childTblExists)) { + g_Dbs.db[i].superTbls[j].autoCreateTable = + AUTO_CREATE_SUBTBL; + } else if (0 == + strncasecmp(autoCreateTbl->valuestring, "no", 2)) { + g_Dbs.db[i].superTbls[j].autoCreateTable = + PRE_CREATE_SUBTBL; + } else { + g_Dbs.db[i].superTbls[j].autoCreateTable = + PRE_CREATE_SUBTBL; + } + } else if (!autoCreateTbl) { + g_Dbs.db[i].superTbls[j].autoCreateTable = PRE_CREATE_SUBTBL; + } else { + errorPrint( + "%s", "failed to read json, auto_create_table not found\n"); + goto PARSE_OVER; + } + + cJSON *batchCreateTbl = + cJSON_GetObjectItem(stbInfo, "batch_create_tbl_num"); + if (batchCreateTbl && batchCreateTbl->type == cJSON_Number) { + g_Dbs.db[i].superTbls[j].batchCreateTableNum = + batchCreateTbl->valueint; + } else if (!batchCreateTbl) { + g_Dbs.db[i].superTbls[j].batchCreateTableNum = + DEFAULT_CREATE_BATCH; + } else { + errorPrint( + "%s", + "failed to read json, batch_create_tbl_num not found\n"); + goto PARSE_OVER; + } + + cJSON *childTblExists = + cJSON_GetObjectItem(stbInfo, "child_table_exists"); // yes, no + if (childTblExists && childTblExists->type == cJSON_String && + childTblExists->valuestring != NULL) { + if ((0 == strncasecmp(childTblExists->valuestring, "yes", 3)) && + (g_Dbs.db[i].drop == false)) { + g_Dbs.db[i].superTbls[j].childTblExists = + TBL_ALREADY_EXISTS; + } else if ((0 == strncasecmp(childTblExists->valuestring, "no", + 2) || + (g_Dbs.db[i].drop == true))) { + g_Dbs.db[i].superTbls[j].childTblExists = TBL_NO_EXISTS; + } else { + g_Dbs.db[i].superTbls[j].childTblExists = TBL_NO_EXISTS; + } + } else if (!childTblExists) { + g_Dbs.db[i].superTbls[j].childTblExists = TBL_NO_EXISTS; + } else { + errorPrint( + "%s", + "failed to read json, child_table_exists not found\n"); + goto PARSE_OVER; + } + + if (TBL_ALREADY_EXISTS == g_Dbs.db[i].superTbls[j].childTblExists) { + g_Dbs.db[i].superTbls[j].autoCreateTable = PRE_CREATE_SUBTBL; + } + + cJSON *count = cJSON_GetObjectItem(stbInfo, "childtable_count"); + if (!count || count->type != cJSON_Number || 0 >= count->valueint) { + errorPrint( + "%s", + "failed to read json, childtable_count input mistake\n"); + goto PARSE_OVER; + } + g_Dbs.db[i].superTbls[j].childTblCount = count->valueint; + g_totalChildTables += g_Dbs.db[i].superTbls[j].childTblCount; + + cJSON *dataSource = cJSON_GetObjectItem(stbInfo, "data_source"); + if (dataSource && dataSource->type == cJSON_String && + dataSource->valuestring != NULL) { + tstrncpy( + g_Dbs.db[i].superTbls[j].dataSource, + dataSource->valuestring, + min(SMALL_BUFF_LEN, strlen(dataSource->valuestring) + 1)); + } else if (!dataSource) { + tstrncpy(g_Dbs.db[i].superTbls[j].dataSource, "rand", + min(SMALL_BUFF_LEN, strlen("rand") + 1)); + } else { + errorPrint("%s", + "failed to read json, data_source not found\n"); + goto PARSE_OVER; + } + + cJSON *stbIface = cJSON_GetObjectItem( + stbInfo, "insert_mode"); // taosc , rest, stmt + if (stbIface && stbIface->type == cJSON_String && + stbIface->valuestring != NULL) { + if (0 == strcasecmp(stbIface->valuestring, "taosc")) { + g_Dbs.db[i].superTbls[j].iface = TAOSC_IFACE; + } else if (0 == strcasecmp(stbIface->valuestring, "rest")) { + g_Dbs.db[i].superTbls[j].iface = REST_IFACE; + } else if (0 == strcasecmp(stbIface->valuestring, "stmt")) { + g_Dbs.db[i].superTbls[j].iface = STMT_IFACE; + } else if (0 == strcasecmp(stbIface->valuestring, "sml")) { + g_Dbs.db[i].superTbls[j].iface = SML_IFACE; + g_args.iface = SML_IFACE; + } else { + errorPrint( + "failed to read json, insert_mode %s not recognized\n", + stbIface->valuestring); + goto PARSE_OVER; + } + } else if (!stbIface) { + g_Dbs.db[i].superTbls[j].iface = TAOSC_IFACE; + } else { + errorPrint("%s", + "failed to read json, insert_mode not found\n"); + goto PARSE_OVER; + } + + cJSON *stbLineProtocol = + cJSON_GetObjectItem(stbInfo, "line_protocol"); + if (stbLineProtocol && stbLineProtocol->type == cJSON_String && + stbLineProtocol->valuestring != NULL) { + if (0 == strcasecmp(stbLineProtocol->valuestring, "line")) { + g_Dbs.db[i].superTbls[j].lineProtocol = + TSDB_SML_LINE_PROTOCOL; + } else if (0 == + strcasecmp(stbLineProtocol->valuestring, "telnet")) { + g_Dbs.db[i].superTbls[j].lineProtocol = + TSDB_SML_TELNET_PROTOCOL; + } else if (0 == + strcasecmp(stbLineProtocol->valuestring, "json")) { + g_Dbs.db[i].superTbls[j].lineProtocol = + TSDB_SML_JSON_PROTOCOL; + } else { + errorPrint( + "failed to read json, line_protocol %s not " + "recognized\n", + stbLineProtocol->valuestring); + goto PARSE_OVER; + } + } else if (!stbLineProtocol) { + g_Dbs.db[i].superTbls[j].lineProtocol = TSDB_SML_LINE_PROTOCOL; + } else { + errorPrint("%s", + "failed to read json, line_protocol not found\n"); + goto PARSE_OVER; + } + + cJSON *childTbl_limit = + cJSON_GetObjectItem(stbInfo, "childtable_limit"); + if ((childTbl_limit) && (g_Dbs.db[i].drop != true) && + (g_Dbs.db[i].superTbls[j].childTblExists == + TBL_ALREADY_EXISTS)) { + if (childTbl_limit->type != cJSON_Number) { + errorPrint("%s", "failed to read json, childtable_limit\n"); + goto PARSE_OVER; + } + g_Dbs.db[i].superTbls[j].childTblLimit = + childTbl_limit->valueint; + } else { + g_Dbs.db[i].superTbls[j].childTblLimit = + -1; // select ... limit -1 means all query result, drop = + // yes mean all table need recreate, limit value is + // invalid. + } + + cJSON *childTbl_offset = + cJSON_GetObjectItem(stbInfo, "childtable_offset"); + if ((childTbl_offset) && (g_Dbs.db[i].drop != true) && + (g_Dbs.db[i].superTbls[j].childTblExists == + TBL_ALREADY_EXISTS)) { + if ((childTbl_offset->type != cJSON_Number) || + (0 > childTbl_offset->valueint)) { + errorPrint("%s", + "failed to read json, childtable_offset\n"); + goto PARSE_OVER; + } + g_Dbs.db[i].superTbls[j].childTblOffset = + childTbl_offset->valueint; + } else { + g_Dbs.db[i].superTbls[j].childTblOffset = 0; + } + + cJSON *ts = cJSON_GetObjectItem(stbInfo, "start_timestamp"); + if (ts && ts->type == cJSON_String && ts->valuestring != NULL) { + tstrncpy(g_Dbs.db[i].superTbls[j].startTimestamp, + ts->valuestring, TSDB_DB_NAME_LEN); + } else if (!ts) { + tstrncpy(g_Dbs.db[i].superTbls[j].startTimestamp, "now", + TSDB_DB_NAME_LEN); + } else { + errorPrint("%s", + "failed to read json, start_timestamp not found\n"); + goto PARSE_OVER; + } + + cJSON *timestampStep = + cJSON_GetObjectItem(stbInfo, "timestamp_step"); + if (timestampStep && timestampStep->type == cJSON_Number) { + g_Dbs.db[i].superTbls[j].timeStampStep = + timestampStep->valueint; + } else if (!timestampStep) { + g_Dbs.db[i].superTbls[j].timeStampStep = g_args.timestamp_step; + } else { + errorPrint("%s", + "failed to read json, timestamp_step not found\n"); + goto PARSE_OVER; + } + + cJSON *sampleFormat = cJSON_GetObjectItem(stbInfo, "sample_format"); + if (sampleFormat && sampleFormat->type == cJSON_String && + sampleFormat->valuestring != NULL) { + tstrncpy( + g_Dbs.db[i].superTbls[j].sampleFormat, + sampleFormat->valuestring, + min(SMALL_BUFF_LEN, strlen(sampleFormat->valuestring) + 1)); + } else if (!sampleFormat) { + tstrncpy(g_Dbs.db[i].superTbls[j].sampleFormat, "csv", + SMALL_BUFF_LEN); + } else { + errorPrint("%s", + "failed to read json, sample_format not found\n"); + goto PARSE_OVER; + } + + cJSON *sampleFile = cJSON_GetObjectItem(stbInfo, "sample_file"); + if (sampleFile && sampleFile->type == cJSON_String && + sampleFile->valuestring != NULL) { + tstrncpy(g_Dbs.db[i].superTbls[j].sampleFile, + sampleFile->valuestring, + min(MAX_FILE_NAME_LEN, + strlen(sampleFile->valuestring) + 1)); + } else if (!sampleFile) { + memset(g_Dbs.db[i].superTbls[j].sampleFile, 0, + MAX_FILE_NAME_LEN); + } else { + errorPrint("%s", + "failed to read json, sample_file not found\n"); + goto PARSE_OVER; + } + + cJSON *useSampleTs = cJSON_GetObjectItem(stbInfo, "use_sample_ts"); + if (useSampleTs && useSampleTs->type == cJSON_String && + useSampleTs->valuestring != NULL) { + if (0 == strncasecmp(useSampleTs->valuestring, "yes", 3)) { + g_Dbs.db[i].superTbls[j].useSampleTs = true; + } else if (0 == + strncasecmp(useSampleTs->valuestring, "no", 2)) { + g_Dbs.db[i].superTbls[j].useSampleTs = false; + } else { + g_Dbs.db[i].superTbls[j].useSampleTs = false; + } + } else if (!useSampleTs) { + g_Dbs.db[i].superTbls[j].useSampleTs = false; + } else { + errorPrint("%s", + "failed to read json, use_sample_ts not found\n"); + goto PARSE_OVER; + } + + cJSON *tagsFile = cJSON_GetObjectItem(stbInfo, "tags_file"); + if ((tagsFile && tagsFile->type == cJSON_String) && + (tagsFile->valuestring != NULL)) { + tstrncpy(g_Dbs.db[i].superTbls[j].tagsFile, + tagsFile->valuestring, MAX_FILE_NAME_LEN); + if (0 == g_Dbs.db[i].superTbls[j].tagsFile[0]) { + g_Dbs.db[i].superTbls[j].tagSource = 0; + } else { + g_Dbs.db[i].superTbls[j].tagSource = 1; + } + } else if (!tagsFile) { + memset(g_Dbs.db[i].superTbls[j].tagsFile, 0, MAX_FILE_NAME_LEN); + g_Dbs.db[i].superTbls[j].tagSource = 0; + } else { + errorPrint("%s", "failed to read json, tags_file not found\n"); + goto PARSE_OVER; + } + + cJSON *stbMaxSqlLen = cJSON_GetObjectItem(stbInfo, "max_sql_len"); + if (stbMaxSqlLen && stbMaxSqlLen->type == cJSON_Number) { + int32_t len = (int32_t)stbMaxSqlLen->valueint; + if (len > TSDB_MAX_ALLOWED_SQL_LEN) { + len = TSDB_MAX_ALLOWED_SQL_LEN; + } else if (len < 5) { + len = 5; + } + g_Dbs.db[i].superTbls[j].maxSqlLen = len; + } else if (!maxSqlLen) { + g_Dbs.db[i].superTbls[j].maxSqlLen = g_args.max_sql_len; + } else { + errorPrint("%s", + "failed to read json, stbMaxSqlLen input mistake\n"); + goto PARSE_OVER; + } + /* + cJSON *multiThreadWriteOneTbl = + cJSON_GetObjectItem(stbInfo, "multi_thread_write_one_tbl"); // no + , yes if (multiThreadWriteOneTbl + && multiThreadWriteOneTbl->type == cJSON_String + && multiThreadWriteOneTbl->valuestring != NULL) { + if (0 == strncasecmp(multiThreadWriteOneTbl->valuestring, "yes", + 3)) { g_Dbs.db[i].superTbls[j].multiThreadWriteOneTbl = 1; } else + { g_Dbs.db[i].superTbls[j].multiThreadWriteOneTbl = 0; + } + } else if (!multiThreadWriteOneTbl) { + g_Dbs.db[i].superTbls[j].multiThreadWriteOneTbl = 0; + } else { + errorPrint("%s", "failed to read json, multiThreadWriteOneTbl not + found\n"); goto PARSE_OVER; + } + */ + cJSON *insertRows = cJSON_GetObjectItem(stbInfo, "insert_rows"); + if (insertRows && insertRows->type == cJSON_Number) { + if (insertRows->valueint < 0) { + errorPrint( + "%s", + "failed to read json, insert_rows input mistake\n"); + goto PARSE_OVER; + } + g_Dbs.db[i].superTbls[j].insertRows = insertRows->valueint; + } else if (!insertRows) { + g_Dbs.db[i].superTbls[j].insertRows = 0x7FFFFFFFFFFFFFFF; + } else { + errorPrint("%s", + "failed to read json, insert_rows input mistake\n"); + goto PARSE_OVER; + } + + cJSON *stbInterlaceRows = + cJSON_GetObjectItem(stbInfo, "interlace_rows"); + if (stbInterlaceRows && stbInterlaceRows->type == cJSON_Number) { + if (stbInterlaceRows->valueint < 0) { + errorPrint( + "%s", + "failed to read json, interlace rows input mistake\n"); + goto PARSE_OVER; + } + g_Dbs.db[i].superTbls[j].interlaceRows = + (uint32_t)stbInterlaceRows->valueint; + + if (g_Dbs.db[i].superTbls[j].interlaceRows > + g_Dbs.db[i].superTbls[j].insertRows) { + printf( + "NOTICE: db[%d].superTbl[%d]'s interlace rows value %u " + "> insert_rows %" PRId64 "\n\n", + i, j, g_Dbs.db[i].superTbls[j].interlaceRows, + g_Dbs.db[i].superTbls[j].insertRows); + printf( + " interlace rows value will be set to " + "insert_rows %" PRId64 "\n\n", + g_Dbs.db[i].superTbls[j].insertRows); + prompt(); + g_Dbs.db[i].superTbls[j].interlaceRows = + (uint32_t)g_Dbs.db[i].superTbls[j].insertRows; + } + } else if (!stbInterlaceRows) { + g_Dbs.db[i].superTbls[j].interlaceRows = + g_args.interlaceRows; // 0 means progressive mode, > 0 mean + // interlace mode. max value is less + // or equ num_of_records_per_req + } else { + errorPrint( + "%s", + "failed to read json, interlace rows input mistake\n"); + goto PARSE_OVER; + } + + cJSON *disorderRatio = + cJSON_GetObjectItem(stbInfo, "disorder_ratio"); + if (disorderRatio && disorderRatio->type == cJSON_Number) { + if (disorderRatio->valueint > 50) disorderRatio->valueint = 50; + + if (disorderRatio->valueint < 0) disorderRatio->valueint = 0; + + g_Dbs.db[i].superTbls[j].disorderRatio = + (int)disorderRatio->valueint; + } else if (!disorderRatio) { + g_Dbs.db[i].superTbls[j].disorderRatio = 0; + } else { + errorPrint("%s", + "failed to read json, disorderRatio not found\n"); + goto PARSE_OVER; + } + + cJSON *disorderRange = + cJSON_GetObjectItem(stbInfo, "disorder_range"); + if (disorderRange && disorderRange->type == cJSON_Number) { + g_Dbs.db[i].superTbls[j].disorderRange = + (int)disorderRange->valueint; + } else if (!disorderRange) { + g_Dbs.db[i].superTbls[j].disorderRange = DEFAULT_DISORDER_RANGE; + } else { + errorPrint("%s", + "failed to read json, disorderRange not found\n"); + goto PARSE_OVER; + } + + cJSON *insertInterval = + cJSON_GetObjectItem(stbInfo, "insert_interval"); + if (insertInterval && insertInterval->type == cJSON_Number) { + g_Dbs.db[i].superTbls[j].insertInterval = + insertInterval->valueint; + if (insertInterval->valueint < 0) { + errorPrint( + "%s", + "failed to read json, insert_interval input mistake\n"); + goto PARSE_OVER; + } + } else if (!insertInterval) { + verbosePrint( + "%s() LN%d: stable insert interval be overrode by global " + "%" PRIu64 ".\n", + __func__, __LINE__, g_args.insert_interval); + g_Dbs.db[i].superTbls[j].insertInterval = + g_args.insert_interval; + } else { + errorPrint( + "%s", + "failed to read json, insert_interval input mistake\n"); + goto PARSE_OVER; + } + + if (getColumnAndTagTypeFromInsertJsonFile( + stbInfo, &g_Dbs.db[i].superTbls[j])) { + goto PARSE_OVER; + } + } + } + + code = 0; + +PARSE_OVER: + return code; +} +int getMetaFromQueryJsonFile(cJSON *root) { + int32_t code = -1; + + cJSON *cfgdir = cJSON_GetObjectItem(root, "cfgdir"); + if (cfgdir && cfgdir->type == cJSON_String && cfgdir->valuestring != NULL) { + tstrncpy(g_queryInfo.cfgDir, cfgdir->valuestring, MAX_FILE_NAME_LEN); + } + + cJSON *host = cJSON_GetObjectItem(root, "host"); + if (host && host->type == cJSON_String && host->valuestring != NULL) { + tstrncpy(g_queryInfo.host, host->valuestring, MAX_HOSTNAME_SIZE); + } else if (!host) { + tstrncpy(g_queryInfo.host, DEFAULT_HOST, MAX_HOSTNAME_SIZE); + } else { + errorPrint("%s", "failed to read json, host not found\n"); + goto PARSE_OVER; + } + + cJSON *port = cJSON_GetObjectItem(root, "port"); + if (port && port->type == cJSON_Number) { + g_queryInfo.port = (uint16_t)port->valueint; + } else if (!port) { + g_queryInfo.port = DEFAULT_PORT; + } + + cJSON *user = cJSON_GetObjectItem(root, "user"); + if (user && user->type == cJSON_String && user->valuestring != NULL) { + tstrncpy(g_queryInfo.user, user->valuestring, MAX_USERNAME_SIZE); + } else if (!user) { + tstrncpy(g_queryInfo.user, TSDB_DEFAULT_USER, MAX_USERNAME_SIZE); + ; + } + + cJSON *password = cJSON_GetObjectItem(root, "password"); + if (password && password->type == cJSON_String && + password->valuestring != NULL) { + tstrncpy(g_queryInfo.password, password->valuestring, + SHELL_MAX_PASSWORD_LEN); + } else if (!password) { + tstrncpy(g_queryInfo.password, TSDB_DEFAULT_PASS, + SHELL_MAX_PASSWORD_LEN); + ; + } + + cJSON *answerPrompt = + cJSON_GetObjectItem(root, "confirm_parameter_prompt"); // yes, no, + if (answerPrompt && answerPrompt->type == cJSON_String && + answerPrompt->valuestring != NULL) { + if (0 == strncasecmp(answerPrompt->valuestring, "yes", 3)) { + g_args.answer_yes = false; + } else if (0 == strncasecmp(answerPrompt->valuestring, "no", 2)) { + g_args.answer_yes = true; + } else { + g_args.answer_yes = false; + } + } else if (!answerPrompt) { + g_args.answer_yes = false; + } else { + errorPrint("%s", + "failed to read json, confirm_parameter_prompt not found\n"); + goto PARSE_OVER; + } + + cJSON *gQueryTimes = cJSON_GetObjectItem(root, "query_times"); + if (gQueryTimes && gQueryTimes->type == cJSON_Number) { + if (gQueryTimes->valueint <= 0) { + errorPrint("%s", + "failed to read json, query_times input mistake\n"); + goto PARSE_OVER; + } + g_args.query_times = gQueryTimes->valueint; + } else if (!gQueryTimes) { + g_args.query_times = DEFAULT_QUERY_TIME; + } else { + errorPrint("%s", "failed to read json, query_times input mistake\n"); + goto PARSE_OVER; + } + + cJSON *dbs = cJSON_GetObjectItem(root, "databases"); + if (dbs && dbs->type == cJSON_String && dbs->valuestring != NULL) { + tstrncpy(g_queryInfo.dbName, dbs->valuestring, TSDB_DB_NAME_LEN); + } else if (!dbs) { + errorPrint("%s", "failed to read json, databases not found\n"); + goto PARSE_OVER; + } + + cJSON *queryMode = cJSON_GetObjectItem(root, "query_mode"); + if (queryMode && queryMode->type == cJSON_String && + queryMode->valuestring != NULL) { + tstrncpy(g_queryInfo.queryMode, queryMode->valuestring, + min(SMALL_BUFF_LEN, strlen(queryMode->valuestring) + 1)); + } else if (!queryMode) { + tstrncpy(g_queryInfo.queryMode, "taosc", + min(SMALL_BUFF_LEN, strlen("taosc") + 1)); + } else { + errorPrint("%s", "failed to read json, query_mode not found\n"); + goto PARSE_OVER; + } + + // specified_table_query + cJSON *specifiedQuery = cJSON_GetObjectItem(root, "specified_table_query"); + if (!specifiedQuery) { + g_queryInfo.specifiedQueryInfo.concurrent = 1; + g_queryInfo.specifiedQueryInfo.sqlCount = 0; + } else if (specifiedQuery->type != cJSON_Object) { + errorPrint("%s", "failed to read json, super_table_query not found\n"); + goto PARSE_OVER; + } else { + cJSON *queryInterval = + cJSON_GetObjectItem(specifiedQuery, "query_interval"); + if (queryInterval && queryInterval->type == cJSON_Number) { + g_queryInfo.specifiedQueryInfo.queryInterval = + queryInterval->valueint; + } else if (!queryInterval) { + g_queryInfo.specifiedQueryInfo.queryInterval = 0; + } + + cJSON *specifiedQueryTimes = + cJSON_GetObjectItem(specifiedQuery, "query_times"); + if (specifiedQueryTimes && specifiedQueryTimes->type == cJSON_Number) { + if (specifiedQueryTimes->valueint <= 0) { + errorPrint("failed to read json, query_times: %" PRId64 + ", need be a valid (>0) number\n", + specifiedQueryTimes->valueint); + goto PARSE_OVER; + } + g_queryInfo.specifiedQueryInfo.queryTimes = + specifiedQueryTimes->valueint; + } else if (!specifiedQueryTimes) { + g_queryInfo.specifiedQueryInfo.queryTimes = g_args.query_times; + } else { + errorPrint( + "%s() LN%d, failed to read json, query_times input mistake\n", + __func__, __LINE__); + goto PARSE_OVER; + } + + cJSON *concurrent = cJSON_GetObjectItem(specifiedQuery, "concurrent"); + if (concurrent && concurrent->type == cJSON_Number) { + if (concurrent->valueint <= 0) { + errorPrint( + "query sqlCount %d or concurrent %d is not correct.\n", + g_queryInfo.specifiedQueryInfo.sqlCount, + g_queryInfo.specifiedQueryInfo.concurrent); + goto PARSE_OVER; + } + g_queryInfo.specifiedQueryInfo.concurrent = + (uint32_t)concurrent->valueint; + } else if (!concurrent) { + g_queryInfo.specifiedQueryInfo.concurrent = 1; + } + + cJSON *specifiedAsyncMode = cJSON_GetObjectItem(specifiedQuery, "mode"); + if (specifiedAsyncMode && specifiedAsyncMode->type == cJSON_String && + specifiedAsyncMode->valuestring != NULL) { + if (0 == strcmp("sync", specifiedAsyncMode->valuestring)) { + g_queryInfo.specifiedQueryInfo.asyncMode = SYNC_MODE; + } else if (0 == strcmp("async", specifiedAsyncMode->valuestring)) { + g_queryInfo.specifiedQueryInfo.asyncMode = ASYNC_MODE; + } else { + errorPrint("%s", + "failed to read json, async mode input error\n"); + goto PARSE_OVER; + } + } else { + g_queryInfo.specifiedQueryInfo.asyncMode = SYNC_MODE; + } + + cJSON *interval = cJSON_GetObjectItem(specifiedQuery, "interval"); + if (interval && interval->type == cJSON_Number) { + g_queryInfo.specifiedQueryInfo.subscribeInterval = + interval->valueint; + } else if (!interval) { + // printf("failed to read json, subscribe interval no found\n"); + // goto PARSE_OVER; + g_queryInfo.specifiedQueryInfo.subscribeInterval = + DEFAULT_SUB_INTERVAL; + } + + cJSON *restart = cJSON_GetObjectItem(specifiedQuery, "restart"); + if (restart && restart->type == cJSON_String && + restart->valuestring != NULL) { + if (0 == strcmp("yes", restart->valuestring)) { + g_queryInfo.specifiedQueryInfo.subscribeRestart = true; + } else if (0 == strcmp("no", restart->valuestring)) { + g_queryInfo.specifiedQueryInfo.subscribeRestart = false; + } else { + errorPrint("%s", + "failed to read json, subscribe restart error\n"); + goto PARSE_OVER; + } + } else { + g_queryInfo.specifiedQueryInfo.subscribeRestart = true; + } + + cJSON *keepProgress = + cJSON_GetObjectItem(specifiedQuery, "keepProgress"); + if (keepProgress && keepProgress->type == cJSON_String && + keepProgress->valuestring != NULL) { + if (0 == strcmp("yes", keepProgress->valuestring)) { + g_queryInfo.specifiedQueryInfo.subscribeKeepProgress = 1; + } else if (0 == strcmp("no", keepProgress->valuestring)) { + g_queryInfo.specifiedQueryInfo.subscribeKeepProgress = 0; + } else { + errorPrint( + "%s", + "failed to read json, subscribe keepProgress error\n"); + goto PARSE_OVER; + } + } else { + g_queryInfo.specifiedQueryInfo.subscribeKeepProgress = 0; + } + + // sqls + cJSON *specifiedSqls = cJSON_GetObjectItem(specifiedQuery, "sqls"); + if (!specifiedSqls) { + g_queryInfo.specifiedQueryInfo.sqlCount = 0; + } else if (specifiedSqls->type != cJSON_Array) { + errorPrint("%s", "failed to read json, super sqls not found\n"); + goto PARSE_OVER; + } else { + int superSqlSize = cJSON_GetArraySize(specifiedSqls); + if (superSqlSize * g_queryInfo.specifiedQueryInfo.concurrent > + MAX_QUERY_SQL_COUNT) { + errorPrint( + "failed to read json, query sql(%d) * concurrent(%d) " + "overflow, max is %d\n", + superSqlSize, g_queryInfo.specifiedQueryInfo.concurrent, + MAX_QUERY_SQL_COUNT); + goto PARSE_OVER; + } + + g_queryInfo.specifiedQueryInfo.sqlCount = superSqlSize; + for (int j = 0; j < superSqlSize; ++j) { + cJSON *sql = cJSON_GetArrayItem(specifiedSqls, j); + if (sql == NULL) continue; + + cJSON *sqlStr = cJSON_GetObjectItem(sql, "sql"); + if (!sqlStr || sqlStr->type != cJSON_String || + sqlStr->valuestring == NULL) { + errorPrint("%s", "failed to read json, sql not found\n"); + goto PARSE_OVER; + } + tstrncpy(g_queryInfo.specifiedQueryInfo.sql[j], + sqlStr->valuestring, BUFFER_SIZE); + + // default value is -1, which mean infinite loop + g_queryInfo.specifiedQueryInfo.endAfterConsume[j] = -1; + cJSON *endAfterConsume = + cJSON_GetObjectItem(specifiedQuery, "endAfterConsume"); + if (endAfterConsume && endAfterConsume->type == cJSON_Number) { + g_queryInfo.specifiedQueryInfo.endAfterConsume[j] = + (int)endAfterConsume->valueint; + } + if (g_queryInfo.specifiedQueryInfo.endAfterConsume[j] < -1) + g_queryInfo.specifiedQueryInfo.endAfterConsume[j] = -1; + + g_queryInfo.specifiedQueryInfo.resubAfterConsume[j] = -1; + cJSON *resubAfterConsume = + cJSON_GetObjectItem(specifiedQuery, "resubAfterConsume"); + if ((resubAfterConsume) && + (resubAfterConsume->type == cJSON_Number) && + (resubAfterConsume->valueint >= 0)) { + g_queryInfo.specifiedQueryInfo.resubAfterConsume[j] = + (int)resubAfterConsume->valueint; + } + + if (g_queryInfo.specifiedQueryInfo.resubAfterConsume[j] < -1) + g_queryInfo.specifiedQueryInfo.resubAfterConsume[j] = -1; + + cJSON *result = cJSON_GetObjectItem(sql, "result"); + if ((NULL != result) && (result->type == cJSON_String) && + (result->valuestring != NULL)) { + tstrncpy(g_queryInfo.specifiedQueryInfo.result[j], + result->valuestring, MAX_FILE_NAME_LEN); + } else if (NULL == result) { + memset(g_queryInfo.specifiedQueryInfo.result[j], 0, + MAX_FILE_NAME_LEN); + } else { + errorPrint("%s", + "failed to read json, super query result file " + "not found\n"); + goto PARSE_OVER; + } + } + } + } + + // super_table_query + cJSON *superQuery = cJSON_GetObjectItem(root, "super_table_query"); + if (!superQuery) { + g_queryInfo.superQueryInfo.threadCnt = 1; + g_queryInfo.superQueryInfo.sqlCount = 0; + } else if (superQuery->type != cJSON_Object) { + errorPrint("%s", "failed to read json, sub_table_query not found\n"); + code = 0; + goto PARSE_OVER; + } else { + cJSON *subrate = cJSON_GetObjectItem(superQuery, "query_interval"); + if (subrate && subrate->type == cJSON_Number) { + g_queryInfo.superQueryInfo.queryInterval = subrate->valueint; + } else if (!subrate) { + g_queryInfo.superQueryInfo.queryInterval = 0; + } + + cJSON *superQueryTimes = cJSON_GetObjectItem(superQuery, "query_times"); + if (superQueryTimes && superQueryTimes->type == cJSON_Number) { + if (superQueryTimes->valueint <= 0) { + errorPrint("failed to read json, query_times: %" PRId64 + ", need be a valid (>0) number\n", + superQueryTimes->valueint); + goto PARSE_OVER; + } + g_queryInfo.superQueryInfo.queryTimes = superQueryTimes->valueint; + } else if (!superQueryTimes) { + g_queryInfo.superQueryInfo.queryTimes = g_args.query_times; + } else { + errorPrint("%s", + "failed to read json, query_times input mistake\n"); + goto PARSE_OVER; + } + + cJSON *threads = cJSON_GetObjectItem(superQuery, "threads"); + if (threads && threads->type == cJSON_Number) { + if (threads->valueint <= 0) { + errorPrint("%s", + "failed to read json, threads input mistake\n"); + goto PARSE_OVER; + } + g_queryInfo.superQueryInfo.threadCnt = (uint32_t)threads->valueint; + } else if (!threads) { + g_queryInfo.superQueryInfo.threadCnt = DEFAULT_NTHREADS; + } + + // cJSON* subTblCnt = cJSON_GetObjectItem(superQuery, + // "childtable_count"); if (subTblCnt && subTblCnt->type == + // cJSON_Number) + // { + // g_queryInfo.superQueryInfo.childTblCount = subTblCnt->valueint; + //} else if (!subTblCnt) { + // g_queryInfo.superQueryInfo.childTblCount = 0; + //} + + cJSON *stblname = cJSON_GetObjectItem(superQuery, "stblname"); + if (stblname && stblname->type == cJSON_String && + stblname->valuestring != NULL) { + tstrncpy(g_queryInfo.superQueryInfo.stbName, stblname->valuestring, + TSDB_TABLE_NAME_LEN); + } else { + errorPrint("%s", + "failed to read json, super table name input error\n"); + goto PARSE_OVER; + } + + cJSON *superAsyncMode = cJSON_GetObjectItem(superQuery, "mode"); + if (superAsyncMode && superAsyncMode->type == cJSON_String && + superAsyncMode->valuestring != NULL) { + if (0 == strcmp("sync", superAsyncMode->valuestring)) { + g_queryInfo.superQueryInfo.asyncMode = SYNC_MODE; + } else if (0 == strcmp("async", superAsyncMode->valuestring)) { + g_queryInfo.superQueryInfo.asyncMode = ASYNC_MODE; + } else { + errorPrint("%s", + "failed to read json, async mode input error\n"); + goto PARSE_OVER; + } + } else { + g_queryInfo.superQueryInfo.asyncMode = SYNC_MODE; + } + + cJSON *superInterval = cJSON_GetObjectItem(superQuery, "interval"); + if (superInterval && superInterval->type == cJSON_Number) { + if (superInterval->valueint < 0) { + errorPrint("%s", + "failed to read json, interval input mistake\n"); + goto PARSE_OVER; + } + g_queryInfo.superQueryInfo.subscribeInterval = + superInterval->valueint; + } else if (!superInterval) { + // printf("failed to read json, subscribe interval no found\n"); + // goto PARSE_OVER; + g_queryInfo.superQueryInfo.subscribeInterval = + DEFAULT_QUERY_INTERVAL; + } + + cJSON *subrestart = cJSON_GetObjectItem(superQuery, "restart"); + if (subrestart && subrestart->type == cJSON_String && + subrestart->valuestring != NULL) { + if (0 == strcmp("yes", subrestart->valuestring)) { + g_queryInfo.superQueryInfo.subscribeRestart = true; + } else if (0 == strcmp("no", subrestart->valuestring)) { + g_queryInfo.superQueryInfo.subscribeRestart = false; + } else { + errorPrint("%s", + "failed to read json, subscribe restart error\n"); + goto PARSE_OVER; + } + } else { + g_queryInfo.superQueryInfo.subscribeRestart = true; + } + + cJSON *superkeepProgress = + cJSON_GetObjectItem(superQuery, "keepProgress"); + if (superkeepProgress && superkeepProgress->type == cJSON_String && + superkeepProgress->valuestring != NULL) { + if (0 == strcmp("yes", superkeepProgress->valuestring)) { + g_queryInfo.superQueryInfo.subscribeKeepProgress = 1; + } else if (0 == strcmp("no", superkeepProgress->valuestring)) { + g_queryInfo.superQueryInfo.subscribeKeepProgress = 0; + } else { + errorPrint("%s", + "failed to read json, subscribe super table " + "keepProgress error\n"); + goto PARSE_OVER; + } + } else { + g_queryInfo.superQueryInfo.subscribeKeepProgress = 0; + } + + // default value is -1, which mean do not resub + g_queryInfo.superQueryInfo.endAfterConsume = -1; + cJSON *superEndAfterConsume = + cJSON_GetObjectItem(superQuery, "endAfterConsume"); + if (superEndAfterConsume && + superEndAfterConsume->type == cJSON_Number) { + g_queryInfo.superQueryInfo.endAfterConsume = + (int)superEndAfterConsume->valueint; + } + if (g_queryInfo.superQueryInfo.endAfterConsume < -1) + g_queryInfo.superQueryInfo.endAfterConsume = -1; + + // default value is -1, which mean do not resub + g_queryInfo.superQueryInfo.resubAfterConsume = -1; + cJSON *superResubAfterConsume = + cJSON_GetObjectItem(superQuery, "resubAfterConsume"); + if ((superResubAfterConsume) && + (superResubAfterConsume->type == cJSON_Number) && + (superResubAfterConsume->valueint >= 0)) { + g_queryInfo.superQueryInfo.resubAfterConsume = + (int)superResubAfterConsume->valueint; + } + if (g_queryInfo.superQueryInfo.resubAfterConsume < -1) + g_queryInfo.superQueryInfo.resubAfterConsume = -1; + + // supert table sqls + cJSON *superSqls = cJSON_GetObjectItem(superQuery, "sqls"); + if (!superSqls) { + g_queryInfo.superQueryInfo.sqlCount = 0; + } else if (superSqls->type != cJSON_Array) { + errorPrint("%s", "failed to read json, super sqls not found\n"); + goto PARSE_OVER; + } else { + int superSqlSize = cJSON_GetArraySize(superSqls); + if (superSqlSize > MAX_QUERY_SQL_COUNT) { + errorPrint( + "failed to read json, query sql size overflow, max is %d\n", + MAX_QUERY_SQL_COUNT); + goto PARSE_OVER; + } + + g_queryInfo.superQueryInfo.sqlCount = superSqlSize; + for (int j = 0; j < superSqlSize; ++j) { + cJSON *sql = cJSON_GetArrayItem(superSqls, j); + if (sql == NULL) continue; + + cJSON *sqlStr = cJSON_GetObjectItem(sql, "sql"); + if (!sqlStr || sqlStr->type != cJSON_String || + sqlStr->valuestring == NULL) { + errorPrint("%s", "failed to read json, sql not found\n"); + goto PARSE_OVER; + } + tstrncpy(g_queryInfo.superQueryInfo.sql[j], sqlStr->valuestring, + BUFFER_SIZE); + + cJSON *result = cJSON_GetObjectItem(sql, "result"); + if (result != NULL && result->type == cJSON_String && + result->valuestring != NULL) { + tstrncpy(g_queryInfo.superQueryInfo.result[j], + result->valuestring, MAX_FILE_NAME_LEN); + } else if (NULL == result) { + memset(g_queryInfo.superQueryInfo.result[j], 0, + MAX_FILE_NAME_LEN); + } else { + errorPrint("%s", + "failed to read json, sub query result file not " + "found\n"); + goto PARSE_OVER; + } + } + } + } + + code = 0; + +PARSE_OVER: + return code; +} + +int getInfoFromJsonFile(char *file) { + debugPrint("%s %d %s\n", __func__, __LINE__, file); + int32_t code = -1; + FILE * fp = fopen(file, "r"); + if (!fp) { + errorPrint("failed to read %s, reason:%s\n", file, strerror(errno)); + return code; + } + + int maxLen = MAX_JSON_BUFF; + char *content = calloc(1, maxLen + 1); + int len = (int)fread(content, 1, maxLen, fp); + if (len <= 0) { + free(content); + fclose(fp); + errorPrint("failed to read %s, content is null", file); + return code; + } + + content[len] = 0; + cJSON *root = cJSON_Parse(content); + if (root == NULL) { + errorPrint("failed to cjson parse %s, invalid json format\n", file); + goto PARSE_OVER; + } + + cJSON *filetype = cJSON_GetObjectItem(root, "filetype"); + if (filetype && filetype->type == cJSON_String && + filetype->valuestring != NULL) { + if (0 == strcasecmp("insert", filetype->valuestring)) { + g_args.test_mode = INSERT_TEST; + } else if (0 == strcasecmp("query", filetype->valuestring)) { + g_args.test_mode = QUERY_TEST; + } else if (0 == strcasecmp("subscribe", filetype->valuestring)) { + g_args.test_mode = SUBSCRIBE_TEST; + } else { + errorPrint("%s", "failed to read json, filetype not support\n"); + goto PARSE_OVER; + } + } else if (!filetype) { + g_args.test_mode = INSERT_TEST; + } else { + errorPrint("%s", "failed to read json, filetype not found\n"); + goto PARSE_OVER; + } + + if (INSERT_TEST == g_args.test_mode) { + memset(&g_Dbs, 0, sizeof(SDbs)); + g_Dbs.use_metric = g_args.use_metric; + code = getMetaFromInsertJsonFile(root); + } else if ((QUERY_TEST == g_args.test_mode) || + (SUBSCRIBE_TEST == g_args.test_mode)) { + memset(&g_queryInfo, 0, sizeof(SQueryMetaInfo)); + code = getMetaFromQueryJsonFile(root); + } else { + errorPrint("%s", + "input json file type error! please input correct file " + "type: insert or query or subscribe\n"); + goto PARSE_OVER; + } +PARSE_OVER: + free(content); + cJSON_Delete(root); + fclose(fp); + return code; +} + +int testMetaFile() { + if (INSERT_TEST == g_args.test_mode) { + if (g_Dbs.cfgDir[0]) { + taos_options(TSDB_OPTION_CONFIGDIR, g_Dbs.cfgDir); + } + return insertTestProcess(); + + } else if (QUERY_TEST == g_args.test_mode) { + if (g_queryInfo.cfgDir[0]) { + taos_options(TSDB_OPTION_CONFIGDIR, g_queryInfo.cfgDir); + } + return queryTestProcess(); + + } else if (SUBSCRIBE_TEST == g_args.test_mode) { + if (g_queryInfo.cfgDir[0]) { + taos_options(TSDB_OPTION_CONFIGDIR, g_queryInfo.cfgDir); + } + return subscribeTestProcess(); + } else { + errorPrint("unsupport test mode (%d)\n", g_args.test_mode); + return -1; + } + return 0; +} \ No newline at end of file diff --git a/src/kit/taosdemo/src/demoMain.c b/src/kit/taosdemo/src/demoMain.c new file mode 100644 index 0000000000000000000000000000000000000000..4940d7188c999f03da0d021327c58d8a7c1a1b9f --- /dev/null +++ b/src/kit/taosdemo/src/demoMain.c @@ -0,0 +1,110 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#include "demo.h" +int64_t g_totalChildTables = DEFAULT_CHILDTABLES; +int64_t g_actualChildTables = 0; +FILE * g_fpOfInsertResult = NULL; +char * g_dupstr = NULL; +SDbs g_Dbs; +SQueryMetaInfo g_queryInfo; + +SArguments g_args = { + DEFAULT_METAFILE, // metaFile + DEFAULT_TEST_MODE, // test_mode + DEFAULT_HOST, // host + DEFAULT_PORT, // port + DEFAULT_IFACE, // iface + TSDB_DEFAULT_USER, // user + TSDB_DEFAULT_PASS, // password + DEFAULT_DATABASE, // database + DEFAULT_REPLICA, // replica + DEFAULT_TB_PREFIX, // tb_prefix + DEFAULT_ESCAPE_CHAR, // escapeChar + DEFAULT_SQLFILE, // sqlFile + DEFAULT_USE_METRIC, // use_metric + DEFAULT_DROP_DB, // drop_database + DEFAULT_AGGR_FUNC, // aggr_func + DEFAULT_DEBUG, // debug_print + DEFAULT_VERBOSE, // verbose_print + DEFAULT_PERF_STAT, // performance statistic print + DEFAULT_ANS_YES, // answer_yes; + DEFAULT_OUTPUT, // output_file + DEFAULT_SYNC_MODE, // mode : sync or async + DEFAULT_DATA_TYPE, // data_type + DEFAULT_DATATYPE, // dataType + DEFAULT_BINWIDTH, // binwidth + DEFAULT_COL_COUNT, // columnCount, timestamp + float + int + float + DEFAULT_LEN_ONE_ROW, // lenOfOneRow + DEFAULT_NTHREADS, // nthreads + DEFAULT_INSERT_INTERVAL, // insert_interval + DEFAULT_TIMESTAMP_STEP, // timestamp_step + DEFAULT_QUERY_TIME, // query_times + DEFAULT_PREPARED_RAND, // prepared_rand + DEFAULT_INTERLACE_ROWS, // interlaceRows; + DEFAULT_REQ_PER_REQ, // reqPerReq + TSDB_MAX_ALLOWED_SQL_LEN, // max_sql_len + DEFAULT_CHILDTABLES, // ntables + DEFAULT_INSERT_ROWS, // insertRows + DEFAULT_ABORT, // abort + DEFAULT_RATIO, // disorderRatio + DEFAULT_DISORDER_RANGE, // disorderRange + DEFAULT_METHOD_DEL, // method_of_delete + DEFAULT_TOTAL_INSERT, // totalInsertRows; + DEFAULT_TOTAL_AFFECT, // totalAffectedRows; + DEFAULT_DEMO_MODE, // demo_mode; +}; + +int main(int argc, char *argv[]) { + if (parse_args(argc, argv)) { + exit(EXIT_FAILURE); + } + debugPrint("meta file: %s\n", g_args.metaFile); + + if (g_args.metaFile) { + g_totalChildTables = 0; + if (getInfoFromJsonFile(g_args.metaFile)) { + exit(EXIT_FAILURE); + } + if (testMetaFile()) { + exit(EXIT_FAILURE); + } + } else { + memset(&g_Dbs, 0, sizeof(SDbs)); + g_Dbs.db = calloc(1, sizeof(SDataBase)); + if (NULL == g_Dbs.db) { + errorPrint("%s", "failed to allocate memory\n"); + } + + g_Dbs.db[0].superTbls = calloc(1, sizeof(SSuperTable)); + if (NULL == g_Dbs.db[0].superTbls) { + errorPrint("%s", "failed to allocate memory\n"); + } + + setParaFromArg(); + + if (NULL != g_args.sqlFile) { + TAOS *qtaos = taos_connect(g_Dbs.host, g_Dbs.user, g_Dbs.password, + g_Dbs.db[0].dbName, g_Dbs.port); + querySqlFile(qtaos, g_args.sqlFile); + taos_close(qtaos); + } else { + testCmdLine(); + } + } + postFreeResource(); + + return 0; +} \ No newline at end of file diff --git a/src/kit/taosdemo/src/demoOutput.c b/src/kit/taosdemo/src/demoOutput.c new file mode 100644 index 0000000000000000000000000000000000000000..026673ca86edb67d752f3cee58de8ea5a6769247 --- /dev/null +++ b/src/kit/taosdemo/src/demoOutput.c @@ -0,0 +1,1052 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#include "demo.h" + +#define SHOW_PARSE_RESULT_START() \ + do { \ + if (g_args.metaFile) \ + printf( \ + "\033[1m\033[40;32m================ %s parse result START " \ + "================\033[0m\n", \ + g_args.metaFile); \ + } while (0) + +#define SHOW_PARSE_RESULT_END() \ + do { \ + if (g_args.metaFile) \ + printf( \ + "\033[1m\033[40;32m================ %s parse result " \ + "END================\033[0m\n", \ + g_args.metaFile); \ + } while (0) + +#define SHOW_PARSE_RESULT_START_TO_FILE(fp) \ + do { \ + if (g_args.metaFile) \ + fprintf(fp, \ + "\033[1m\033[40;32m================ %s parse result " \ + "START ================\033[0m\n", \ + g_args.metaFile); \ + } while (0) + +#define SHOW_PARSE_RESULT_END_TO_FILE(fp) \ + do { \ + if (g_args.metaFile) \ + fprintf(fp, \ + "\033[1m\033[40;32m================ %s parse result " \ + "END================\033[0m\n", \ + g_args.metaFile); \ + } while (0) + +int getDbFromServer(TAOS *taos, SDbInfo **dbInfos) { + TAOS_RES *res; + TAOS_ROW row = NULL; + int count = 0; + + res = taos_query(taos, "show databases;"); + int32_t code = taos_errno(res); + + if (code != 0) { + errorPrint("failed to run , reason: %s\n", + taos_errstr(res)); + return -1; + } + + TAOS_FIELD *fields = taos_fetch_fields(res); + + while ((row = taos_fetch_row(res)) != NULL) { + // sys database name : 'log' + if (strncasecmp(row[TSDB_SHOW_DB_NAME_INDEX], "log", + fields[TSDB_SHOW_DB_NAME_INDEX].bytes) == 0) { + continue; + } + + dbInfos[count] = (SDbInfo *)calloc(1, sizeof(SDbInfo)); + if (dbInfos[count] == NULL) { + errorPrint("failed to allocate memory for some dbInfo[%d]\n", + count); + return -1; + } + + tstrncpy(dbInfos[count]->name, (char *)row[TSDB_SHOW_DB_NAME_INDEX], + fields[TSDB_SHOW_DB_NAME_INDEX].bytes); + formatTimestamp(dbInfos[count]->create_time, + *(int64_t *)row[TSDB_SHOW_DB_CREATED_TIME_INDEX], + TSDB_TIME_PRECISION_MILLI); + dbInfos[count]->ntables = *((int64_t *)row[TSDB_SHOW_DB_NTABLES_INDEX]); + dbInfos[count]->vgroups = *((int32_t *)row[TSDB_SHOW_DB_VGROUPS_INDEX]); + dbInfos[count]->replica = *((int16_t *)row[TSDB_SHOW_DB_REPLICA_INDEX]); + dbInfos[count]->quorum = *((int16_t *)row[TSDB_SHOW_DB_QUORUM_INDEX]); + dbInfos[count]->days = *((int16_t *)row[TSDB_SHOW_DB_DAYS_INDEX]); + + tstrncpy(dbInfos[count]->keeplist, (char *)row[TSDB_SHOW_DB_KEEP_INDEX], + fields[TSDB_SHOW_DB_KEEP_INDEX].bytes); + dbInfos[count]->cache = *((int32_t *)row[TSDB_SHOW_DB_CACHE_INDEX]); + dbInfos[count]->blocks = *((int32_t *)row[TSDB_SHOW_DB_BLOCKS_INDEX]); + dbInfos[count]->minrows = *((int32_t *)row[TSDB_SHOW_DB_MINROWS_INDEX]); + dbInfos[count]->maxrows = *((int32_t *)row[TSDB_SHOW_DB_MAXROWS_INDEX]); + dbInfos[count]->wallevel = + *((int8_t *)row[TSDB_SHOW_DB_WALLEVEL_INDEX]); + dbInfos[count]->fsync = *((int32_t *)row[TSDB_SHOW_DB_FSYNC_INDEX]); + dbInfos[count]->comp = + (int8_t)(*((int8_t *)row[TSDB_SHOW_DB_COMP_INDEX])); + dbInfos[count]->cachelast = + (int8_t)(*((int8_t *)row[TSDB_SHOW_DB_CACHELAST_INDEX])); + + tstrncpy(dbInfos[count]->precision, + (char *)row[TSDB_SHOW_DB_PRECISION_INDEX], + fields[TSDB_SHOW_DB_PRECISION_INDEX].bytes); + dbInfos[count]->update = *((int8_t *)row[TSDB_SHOW_DB_UPDATE_INDEX]); + tstrncpy(dbInfos[count]->status, (char *)row[TSDB_SHOW_DB_STATUS_INDEX], + fields[TSDB_SHOW_DB_STATUS_INDEX].bytes); + + count++; + if (count > MAX_DATABASE_COUNT) { + errorPrint("The database count overflow than %d\n", + MAX_DATABASE_COUNT); + break; + } + } + + return count; +} + +void xDumpFieldToFile(FILE *fp, const char *val, TAOS_FIELD *field, + int32_t length, int precision) { + if (val == NULL) { + fprintf(fp, "%s", TSDB_DATA_NULL_STR); + return; + } + + char buf[TSDB_MAX_BYTES_PER_ROW]; + switch (field->type) { + case TSDB_DATA_TYPE_BOOL: + fprintf(fp, "%d", ((((int32_t)(*((int8_t *)val))) == 1) ? 1 : 0)); + break; + + case TSDB_DATA_TYPE_TINYINT: + fprintf(fp, "%d", *((int8_t *)val)); + break; + + case TSDB_DATA_TYPE_UTINYINT: + fprintf(fp, "%d", *((uint8_t *)val)); + break; + + case TSDB_DATA_TYPE_SMALLINT: + fprintf(fp, "%d", *((int16_t *)val)); + break; + + case TSDB_DATA_TYPE_USMALLINT: + fprintf(fp, "%d", *((uint16_t *)val)); + break; + + case TSDB_DATA_TYPE_INT: + fprintf(fp, "%d", *((int32_t *)val)); + break; + + case TSDB_DATA_TYPE_UINT: + fprintf(fp, "%d", *((uint32_t *)val)); + break; + + case TSDB_DATA_TYPE_BIGINT: + fprintf(fp, "%" PRId64 "", *((int64_t *)val)); + break; + + case TSDB_DATA_TYPE_UBIGINT: + fprintf(fp, "%" PRId64 "", *((uint64_t *)val)); + break; + + case TSDB_DATA_TYPE_FLOAT: + fprintf(fp, "%.5f", GET_FLOAT_VAL(val)); + break; + + case TSDB_DATA_TYPE_DOUBLE: + fprintf(fp, "%.9f", GET_DOUBLE_VAL(val)); + break; + + case TSDB_DATA_TYPE_BINARY: + case TSDB_DATA_TYPE_NCHAR: + memcpy(buf, val, length); + buf[length] = 0; + fprintf(fp, "\'%s\'", buf); + break; + + case TSDB_DATA_TYPE_TIMESTAMP: + formatTimestamp(buf, *(int64_t *)val, precision); + fprintf(fp, "'%s'", buf); + break; + + default: + break; + } +} + +int xDumpResultToFile(const char *fname, TAOS_RES *tres) { + TAOS_ROW row = taos_fetch_row(tres); + if (row == NULL) { + return 0; + } + + FILE *fp = fopen(fname, "at"); + if (fp == NULL) { + errorPrint("failed to open file: %s\n", fname); + return -1; + } + + int num_fields = taos_num_fields(tres); + TAOS_FIELD *fields = taos_fetch_fields(tres); + int precision = taos_result_precision(tres); + + for (int col = 0; col < num_fields; col++) { + if (col > 0) { + fprintf(fp, ","); + } + fprintf(fp, "%s", fields[col].name); + } + fputc('\n', fp); + + int numOfRows = 0; + do { + int32_t *length = taos_fetch_lengths(tres); + for (int i = 0; i < num_fields; i++) { + if (i > 0) { + fputc(',', fp); + } + xDumpFieldToFile(fp, (const char *)row[i], fields + i, length[i], + precision); + } + fputc('\n', fp); + + numOfRows++; + row = taos_fetch_row(tres); + } while (row != NULL); + + fclose(fp); + + return numOfRows; +} + +#ifndef TAOSDEMO_COMMIT_SHA1 +#define TAOSDEMO_COMMIT_SHA1 "unknown" +#endif + +#ifndef TD_VERNUMBER +#define TD_VERNUMBER "unknown" +#endif + +#ifndef TAOSDEMO_STATUS +#define TAOSDEMO_STATUS "unknown" +#endif + +void printVersion() { + char tdengine_ver[] = TD_VERNUMBER; + char taosdemo_ver[] = TAOSDEMO_COMMIT_SHA1; + char taosdemo_status[] = TAOSDEMO_STATUS; + + if (strlen(taosdemo_status) == 0) { + printf("taosdemo version %s-%s\n", tdengine_ver, taosdemo_ver); + } else { + printf("taosdemo version %s-%s, status:%s\n", tdengine_ver, + taosdemo_ver, taosdemo_status); + } + exit(EXIT_SUCCESS); +} + +void printHelp() { + char indent[10] = " "; + printf("%s\n\n", "Usage: taosdemo [OPTION...]"); + printf("%s%s%s%s\n", indent, "-f, --file=FILE", "\t\t", + "The meta file to the execution procedure."); + printf("%s%s%s%s\n", indent, "-u, --user=USER", "\t\t", + "The user name to use when connecting to the server."); +#ifdef _TD_POWER_ + printf("%s%s%s%s\n", indent, "-p, --password", "\t\t", + "The password to use when connecting to the server. By default is " + "'powerdb'"); + printf("%s%s%s%s\n", indent, "-c, --config-dir=CONFIG_DIR", "\t", + "Configuration directory. By default is '/etc/power/'."); +#elif (_TD_TQ_ == true) + printf("%s%s%s%s\n", indent, "-p, --password", "\t\t", + "The password to use when connecting to the server. By default is " + "'tqueue'"); + printf("%s%s%s%s\n", indent, "-c, --config-dir=CONFIG_DIR", "\t", + "Configuration directory. By default is '/etc/tq/'."); +#elif (_TD_PRO_ == true) + printf("%s%s%s%s\n", indent, "-p, --password", "\t\t", + "The password to use when connecting to the server. By default is " + "'prodb'"); + printf("%s%s%s%s\n", indent, "-c, --config-dir=CONFIG_DIR", "\t", + "Configuration directory. By default is '/etc/ProDB/'."); +#else + printf("%s%s%s%s\n", indent, "-p, --password", "\t\t", + "The password to use when connecting to the server."); + printf("%s%s%s%s\n", indent, "-c, --config-dir=CONFIG_DIR", "\t", + "Configuration directory."); +#endif + printf("%s%s%s%s\n", indent, "-h, --host=HOST", "\t\t", + "TDengine server FQDN to connect. The default host is localhost."); + printf("%s%s%s%s\n", indent, "-P, --port=PORT", "\t\t", + "The TCP/IP port number to use for the connection."); + printf("%s%s%s%s\n", indent, "-I, --interface=INTERFACE", "\t", + "The interface (taosc, rest, stmt, and sml(line protocol)) taosdemo " + "uses. By default " + "use 'taosc'."); + printf("%s%s%s%s\n", indent, "-d, --database=DATABASE", "\t", + "Destination database. By default is 'test'."); + printf("%s%s%s%s\n", indent, "-a, --replica=REPLICA", "\t\t", + "Set the replica parameters of the database, By default use 1, min: " + "1, max: 3."); + printf("%s%s%s%s\n", indent, "-m, --table-prefix=TABLEPREFIX", "\t", + "Table prefix name. By default use 'd'."); + printf("%s%s%s%s\n", indent, "-E, --escape-character", "\t", + "Use escape character for Both Stable and normmal table name"); + printf("%s%s%s%s\n", indent, "-s, --sql-file=FILE", "\t\t", + "The select sql file."); + printf("%s%s%s%s\n", indent, "-N, --normal-table", "\t\t", + "Use normal table flag."); + printf("%s%s%s%s\n", indent, "-o, --output=FILE", "\t\t", + "Direct output to the named file. By default use './output.txt'."); + printf("%s%s%s%s\n", indent, "-q, --query-mode=MODE", "\t\t", + "Query mode -- 0: SYNC, 1: ASYNC. By default use SYNC."); + printf("%s%s%s%s\n", indent, "-b, --data-type=DATATYPE", "\t", + "The data_type of columns, By default use: FLOAT,INT,FLOAT. NCHAR " + "and BINARY can also use custom length. Eg: NCHAR(16),BINARY(8)"); + printf("%s%s%s%s%d\n", indent, "-w, --binwidth=WIDTH", "\t\t", + "The width of data_type 'BINARY' or 'NCHAR'. By default use ", + g_args.binwidth); + printf("%s%s%s%s%d%s%d\n", indent, "-l, --columns=COLUMNS", "\t\t", + "The number of columns per record. Demo mode by default is ", + DEFAULT_DATATYPE_NUM, " (float, int, float). Max values is ", + MAX_NUM_COLUMNS); + printf("%s%s%s%s\n", indent, indent, indent, + "\t\t\t\tAll of the new column(s) type is INT. If use -b to specify " + "column type, -l will be ignored."); + printf("%s%s%s%s%d.\n", indent, "-T, --threads=NUMBER", "\t\t", + "The number of threads. By default use ", DEFAULT_NTHREADS); + printf("%s%s%s%s\n", indent, "-i, --insert-interval=NUMBER", "\t", + "The sleep time (ms) between insertion. By default is 0."); + printf("%s%s%s%s%d.\n", indent, "-S, --time-step=TIME_STEP", "\t", + "The timestamp step between insertion. By default is ", + DEFAULT_TIMESTAMP_STEP); + printf("%s%s%s%s%d.\n", indent, "-B, --interlace-rows=NUMBER", "\t", + "The interlace rows of insertion. By default is ", + DEFAULT_INTERLACE_ROWS); + printf("%s%s%s%s\n", indent, "-r, --rec-per-req=NUMBER", "\t", + "The number of records per request. By default is 30000."); + printf("%s%s%s%s\n", indent, "-t, --tables=NUMBER", "\t\t", + "The number of tables. By default is 10000."); + printf("%s%s%s%s\n", indent, "-n, --records=NUMBER", "\t\t", + "The number of records per table. By default is 10000."); + printf("%s%s%s%s\n", indent, "-M, --random", "\t\t\t", + "The value of records generated are totally random."); + printf("%s\n", "\t\t\t\tBy default to simulate power equipment scenario."); + printf("%s%s%s%s\n", indent, "-x, --aggr-func", "\t\t", + "Test aggregation functions after insertion."); + printf("%s%s%s%s\n", indent, "-y, --answer-yes", "\t\t", + "Input yes for prompt."); + printf("%s%s%s%s\n", indent, "-O, --disorder=NUMBER", "\t\t", + "Insert order mode--0: In order, 1 ~ 50: disorder ratio. By default " + "is in order."); + printf("%s%s%s%s\n", indent, "-R, --disorder-range=NUMBER", "\t", + "Out of order data's range. Unit is ms. By default is 1000."); + printf("%s%s%s%s\n", indent, "-g, --debug", "\t\t\t", "Print debug info."); + printf("%s%s%s%s\n", indent, "-?, --help\t", "\t\t", "Give this help list"); + printf("%s%s%s%s\n", indent, " --usage\t", "\t\t", + "Give a short usage message"); + printf("%s%s\n", indent, "-V, --version\t\t\tPrint program version."); + /* printf("%s%s%s%s\n", indent, "-D", indent, + "Delete database if exists. 0: no, 1: yes, default is 1"); + */ + printf( + "\nMandatory or optional arguments to long options are also mandatory or optional\n\ +for any corresponding short options.\n\ +\n\ +Report bugs to .\n"); + exit(EXIT_SUCCESS); +} + +void printfInsertMeta() { + setupForAnsiEscape(); + SHOW_PARSE_RESULT_START(); + + if (g_args.demo_mode) { + printf( + "\ntaosdemo is simulating data generated by power equipment " + "monitoring...\n\n"); + } else { + printf("\ntaosdemo is simulating random data as you request..\n\n"); + } + + if (g_args.iface != INTERFACE_BUT) { + // first time if no iface specified + printf("interface: \033[33m%s\033[0m\n", + (g_args.iface == TAOSC_IFACE) ? "taosc" + : (g_args.iface == REST_IFACE) ? "rest" + : (g_args.iface == STMT_IFACE) ? "stmt" + : "sml"); + } + + printf("host: \033[33m%s:%u\033[0m\n", g_Dbs.host, + g_Dbs.port); + printf("user: \033[33m%s\033[0m\n", g_Dbs.user); + printf("password: \033[33m%s\033[0m\n", g_Dbs.password); + printf("configDir: \033[33m%s\033[0m\n", configDir); + printf("resultFile: \033[33m%s\033[0m\n", g_Dbs.resultFile); + printf("thread num of insert data: \033[33m%d\033[0m\n", + g_Dbs.threadCount); + printf("thread num of create table: \033[33m%d\033[0m\n", + g_Dbs.threadCountForCreateTbl); + printf("top insert interval: \033[33m%" PRIu64 "\033[0m\n", + g_args.insert_interval); + printf("number of records per req: \033[33m%u\033[0m\n", g_args.reqPerReq); + printf("max sql length: \033[33m%" PRIu64 "\033[0m\n", + g_args.max_sql_len); + + printf("database count: \033[33m%d\033[0m\n", g_Dbs.dbCount); + + for (int i = 0; i < g_Dbs.dbCount; i++) { + printf("database[\033[33m%d\033[0m]:\n", i); + printf(" database[%d] name: \033[33m%s\033[0m\n", i, + g_Dbs.db[i].dbName); + if (0 == g_Dbs.db[i].drop) { + printf(" drop: \033[33m no\033[0m\n"); + } else { + printf(" drop: \033[33m yes\033[0m\n"); + } + + if (g_Dbs.db[i].dbCfg.blocks > 0) { + printf(" blocks: \033[33m%d\033[0m\n", + g_Dbs.db[i].dbCfg.blocks); + } + if (g_Dbs.db[i].dbCfg.cache > 0) { + printf(" cache: \033[33m%d\033[0m\n", + g_Dbs.db[i].dbCfg.cache); + } + if (g_Dbs.db[i].dbCfg.days > 0) { + printf(" days: \033[33m%d\033[0m\n", + g_Dbs.db[i].dbCfg.days); + } + if (g_Dbs.db[i].dbCfg.keep > 0) { + printf(" keep: \033[33m%d\033[0m\n", + g_Dbs.db[i].dbCfg.keep); + } + if (g_Dbs.db[i].dbCfg.replica > 0) { + printf(" replica: \033[33m%d\033[0m\n", + g_Dbs.db[i].dbCfg.replica); + } + if (g_Dbs.db[i].dbCfg.update > 0) { + printf(" update: \033[33m%d\033[0m\n", + g_Dbs.db[i].dbCfg.update); + } + if (g_Dbs.db[i].dbCfg.minRows > 0) { + printf(" minRows: \033[33m%d\033[0m\n", + g_Dbs.db[i].dbCfg.minRows); + } + if (g_Dbs.db[i].dbCfg.maxRows > 0) { + printf(" maxRows: \033[33m%d\033[0m\n", + g_Dbs.db[i].dbCfg.maxRows); + } + if (g_Dbs.db[i].dbCfg.comp > 0) { + printf(" comp: \033[33m%d\033[0m\n", + g_Dbs.db[i].dbCfg.comp); + } + if (g_Dbs.db[i].dbCfg.walLevel > 0) { + printf(" walLevel: \033[33m%d\033[0m\n", + g_Dbs.db[i].dbCfg.walLevel); + } + if (g_Dbs.db[i].dbCfg.fsync > 0) { + printf(" fsync: \033[33m%d\033[0m\n", + g_Dbs.db[i].dbCfg.fsync); + } + if (g_Dbs.db[i].dbCfg.quorum > 0) { + printf(" quorum: \033[33m%d\033[0m\n", + g_Dbs.db[i].dbCfg.quorum); + } + if (g_Dbs.db[i].dbCfg.precision[0] != 0) { + if ((0 == strncasecmp(g_Dbs.db[i].dbCfg.precision, "ms", 2)) || + (0 == strncasecmp(g_Dbs.db[i].dbCfg.precision, "us", 2)) || + (0 == strncasecmp(g_Dbs.db[i].dbCfg.precision, "ns", 2))) { + printf(" precision: \033[33m%s\033[0m\n", + g_Dbs.db[i].dbCfg.precision); + } else { + printf("\033[1m\033[40;31m precision error: %s\033[0m\n", + g_Dbs.db[i].dbCfg.precision); + } + } + + if (g_args.use_metric) { + printf(" super table count: \033[33m%" PRIu64 "\033[0m\n", + g_Dbs.db[i].superTblCount); + for (uint64_t j = 0; j < g_Dbs.db[i].superTblCount; j++) { + printf(" super table[\033[33m%" PRIu64 "\033[0m]:\n", j); + + printf(" stbName: \033[33m%s\033[0m\n", + g_Dbs.db[i].superTbls[j].stbName); + + if (PRE_CREATE_SUBTBL == + g_Dbs.db[i].superTbls[j].autoCreateTable) { + printf(" autoCreateTable: \033[33m%s\033[0m\n", + "no"); + } else if (AUTO_CREATE_SUBTBL == + g_Dbs.db[i].superTbls[j].autoCreateTable) { + printf(" autoCreateTable: \033[33m%s\033[0m\n", + "yes"); + } else { + printf(" autoCreateTable: \033[33m%s\033[0m\n", + "error"); + } + + if (TBL_NO_EXISTS == g_Dbs.db[i].superTbls[j].childTblExists) { + printf(" childTblExists: \033[33m%s\033[0m\n", + "no"); + } else if (TBL_ALREADY_EXISTS == + g_Dbs.db[i].superTbls[j].childTblExists) { + printf(" childTblExists: \033[33m%s\033[0m\n", + "yes"); + } else { + printf(" childTblExists: \033[33m%s\033[0m\n", + "error"); + } + + printf(" childTblCount: \033[33m%" PRId64 "\033[0m\n", + g_Dbs.db[i].superTbls[j].childTblCount); + printf(" childTblPrefix: \033[33m%s\033[0m\n", + g_Dbs.db[i].superTbls[j].childTblPrefix); + printf(" dataSource: \033[33m%s\033[0m\n", + g_Dbs.db[i].superTbls[j].dataSource); + printf(" iface: \033[33m%s\033[0m\n", + (g_Dbs.db[i].superTbls[j].iface == TAOSC_IFACE) ? "taosc" + : (g_Dbs.db[i].superTbls[j].iface == REST_IFACE) ? "rest" + : (g_Dbs.db[i].superTbls[j].iface == STMT_IFACE) + ? "stmt" + : "sml"); + if (g_Dbs.db[i].superTbls[j].iface == SML_IFACE) { + printf(" lineProtocol: \033[33m%s\033[0m\n", + (g_Dbs.db[i].superTbls[j].lineProtocol == + TSDB_SML_LINE_PROTOCOL) + ? "line" + : (g_Dbs.db[i].superTbls[j].lineProtocol == + TSDB_SML_TELNET_PROTOCOL) + ? "telnet" + : "json"); + } + + if (g_Dbs.db[i].superTbls[j].childTblLimit > 0) { + printf(" childTblLimit: \033[33m%" PRId64 + "\033[0m\n", + g_Dbs.db[i].superTbls[j].childTblLimit); + } + if (g_Dbs.db[i].superTbls[j].childTblOffset > 0) { + printf(" childTblOffset: \033[33m%" PRIu64 + "\033[0m\n", + g_Dbs.db[i].superTbls[j].childTblOffset); + } + printf(" insertRows: \033[33m%" PRId64 "\033[0m\n", + g_Dbs.db[i].superTbls[j].insertRows); + /* + if (0 == g_Dbs.db[i].superTbls[j].multiThreadWriteOneTbl) { + printf(" multiThreadWriteOneTbl: \033[33m no\033[0m\n"); + }else { + printf(" multiThreadWriteOneTbl: \033[33m yes\033[0m\n"); + } + */ + printf(" interlaceRows: \033[33m%u\033[0m\n", + g_Dbs.db[i].superTbls[j].interlaceRows); + + if (g_Dbs.db[i].superTbls[j].interlaceRows > 0) { + printf(" stable insert interval: \033[33m%" PRIu64 + "\033[0m\n", + g_Dbs.db[i].superTbls[j].insertInterval); + } + + printf(" disorderRange: \033[33m%d\033[0m\n", + g_Dbs.db[i].superTbls[j].disorderRange); + printf(" disorderRatio: \033[33m%d\033[0m\n", + g_Dbs.db[i].superTbls[j].disorderRatio); + printf(" maxSqlLen: \033[33m%" PRIu64 "\033[0m\n", + g_Dbs.db[i].superTbls[j].maxSqlLen); + printf(" timeStampStep: \033[33m%" PRId64 "\033[0m\n", + g_Dbs.db[i].superTbls[j].timeStampStep); + printf(" startTimestamp: \033[33m%s\033[0m\n", + g_Dbs.db[i].superTbls[j].startTimestamp); + printf(" sampleFormat: \033[33m%s\033[0m\n", + g_Dbs.db[i].superTbls[j].sampleFormat); + printf(" sampleFile: \033[33m%s\033[0m\n", + g_Dbs.db[i].superTbls[j].sampleFile); + printf(" useSampleTs: \033[33m%s\033[0m\n", + g_Dbs.db[i].superTbls[j].useSampleTs + ? "yes (warning: disorderRange/disorderRatio is " + "disabled)" + : "no"); + printf(" tagsFile: \033[33m%s\033[0m\n", + g_Dbs.db[i].superTbls[j].tagsFile); + printf(" columnCount: \033[33m%d\033[0m\n ", + g_Dbs.db[i].superTbls[j].columnCount); + for (int k = 0; k < g_Dbs.db[i].superTbls[j].columnCount; k++) { + // printf("dataType:%s, dataLen:%d\t", + // g_Dbs.db[i].superTbls[j].columns[k].dataType, + // g_Dbs.db[i].superTbls[j].columns[k].dataLen); + if ((0 == strncasecmp( + g_Dbs.db[i].superTbls[j].columns[k].dataType, + "binary", 6)) || + (0 == strncasecmp( + g_Dbs.db[i].superTbls[j].columns[k].dataType, + "nchar", 5))) { + printf("column[%d]:\033[33m%s(%d)\033[0m ", k, + g_Dbs.db[i].superTbls[j].columns[k].dataType, + g_Dbs.db[i].superTbls[j].columns[k].dataLen); + } else { + printf("column[%d]:\033[33m%s\033[0m ", k, + g_Dbs.db[i].superTbls[j].columns[k].dataType); + } + } + printf("\n"); + + printf(" tagCount: \033[33m%d\033[0m\n ", + g_Dbs.db[i].superTbls[j].tagCount); + for (int k = 0; k < g_Dbs.db[i].superTbls[j].tagCount; k++) { + // printf("dataType:%s, dataLen:%d\t", + // g_Dbs.db[i].superTbls[j].tags[k].dataType, + // g_Dbs.db[i].superTbls[j].tags[k].dataLen); + if ((0 == + strncasecmp(g_Dbs.db[i].superTbls[j].tags[k].dataType, + "binary", strlen("binary"))) || + (0 == + strncasecmp(g_Dbs.db[i].superTbls[j].tags[k].dataType, + "nchar", strlen("nchar")))) { + printf("tag[%d]:\033[33m%s(%d)\033[0m ", k, + g_Dbs.db[i].superTbls[j].tags[k].dataType, + g_Dbs.db[i].superTbls[j].tags[k].dataLen); + } else { + printf("tag[%d]:\033[33m%s\033[0m ", k, + g_Dbs.db[i].superTbls[j].tags[k].dataType); + } + } + printf("\n"); + } + } else { + printf(" childTblCount: \033[33m%" PRId64 "\033[0m\n", + g_args.ntables); + printf(" insertRows: \033[33m%" PRId64 "\033[0m\n", + g_args.insertRows); + } + printf("\n"); + } + + SHOW_PARSE_RESULT_END(); + resetAfterAnsiEscape(); +} + +void printfInsertMetaToFile(FILE *fp) { + SHOW_PARSE_RESULT_START_TO_FILE(fp); + + fprintf(fp, "host: %s:%u\n", g_Dbs.host, g_Dbs.port); + fprintf(fp, "user: %s\n", g_Dbs.user); + fprintf(fp, "configDir: %s\n", configDir); + fprintf(fp, "resultFile: %s\n", g_Dbs.resultFile); + fprintf(fp, "thread num of insert data: %d\n", g_Dbs.threadCount); + fprintf(fp, "thread num of create table: %d\n", + g_Dbs.threadCountForCreateTbl); + fprintf(fp, "number of records per req: %u\n", g_args.reqPerReq); + fprintf(fp, "max sql length: %" PRIu64 "\n", + g_args.max_sql_len); + fprintf(fp, "database count: %d\n", g_Dbs.dbCount); + + for (int i = 0; i < g_Dbs.dbCount; i++) { + fprintf(fp, "database[%d]:\n", i); + fprintf(fp, " database[%d] name: %s\n", i, g_Dbs.db[i].dbName); + if (0 == g_Dbs.db[i].drop) { + fprintf(fp, " drop: no\n"); + } else { + fprintf(fp, " drop: yes\n"); + } + + if (g_Dbs.db[i].dbCfg.blocks > 0) { + fprintf(fp, " blocks: %d\n", + g_Dbs.db[i].dbCfg.blocks); + } + if (g_Dbs.db[i].dbCfg.cache > 0) { + fprintf(fp, " cache: %d\n", + g_Dbs.db[i].dbCfg.cache); + } + if (g_Dbs.db[i].dbCfg.days > 0) { + fprintf(fp, " days: %d\n", + g_Dbs.db[i].dbCfg.days); + } + if (g_Dbs.db[i].dbCfg.keep > 0) { + fprintf(fp, " keep: %d\n", + g_Dbs.db[i].dbCfg.keep); + } + if (g_Dbs.db[i].dbCfg.replica > 0) { + fprintf(fp, " replica: %d\n", + g_Dbs.db[i].dbCfg.replica); + } + if (g_Dbs.db[i].dbCfg.update > 0) { + fprintf(fp, " update: %d\n", + g_Dbs.db[i].dbCfg.update); + } + if (g_Dbs.db[i].dbCfg.minRows > 0) { + fprintf(fp, " minRows: %d\n", + g_Dbs.db[i].dbCfg.minRows); + } + if (g_Dbs.db[i].dbCfg.maxRows > 0) { + fprintf(fp, " maxRows: %d\n", + g_Dbs.db[i].dbCfg.maxRows); + } + if (g_Dbs.db[i].dbCfg.comp > 0) { + fprintf(fp, " comp: %d\n", + g_Dbs.db[i].dbCfg.comp); + } + if (g_Dbs.db[i].dbCfg.walLevel > 0) { + fprintf(fp, " walLevel: %d\n", + g_Dbs.db[i].dbCfg.walLevel); + } + if (g_Dbs.db[i].dbCfg.fsync > 0) { + fprintf(fp, " fsync: %d\n", + g_Dbs.db[i].dbCfg.fsync); + } + if (g_Dbs.db[i].dbCfg.quorum > 0) { + fprintf(fp, " quorum: %d\n", + g_Dbs.db[i].dbCfg.quorum); + } + if (g_Dbs.db[i].dbCfg.precision[0] != 0) { + if ((0 == strncasecmp(g_Dbs.db[i].dbCfg.precision, "ms", 2)) || + (0 == strncasecmp(g_Dbs.db[i].dbCfg.precision, "ns", 2)) || + (0 == strncasecmp(g_Dbs.db[i].dbCfg.precision, "us", 2))) { + fprintf(fp, " precision: %s\n", + g_Dbs.db[i].dbCfg.precision); + } else { + fprintf(fp, " precision error: %s\n", + g_Dbs.db[i].dbCfg.precision); + } + } + + fprintf(fp, " super table count: %" PRIu64 "\n", + g_Dbs.db[i].superTblCount); + for (int j = 0; j < g_Dbs.db[i].superTblCount; j++) { + fprintf(fp, " super table[%d]:\n", j); + + fprintf(fp, " stbName: %s\n", + g_Dbs.db[i].superTbls[j].stbName); + + if (PRE_CREATE_SUBTBL == g_Dbs.db[i].superTbls[j].autoCreateTable) { + fprintf(fp, " autoCreateTable: %s\n", "no"); + } else if (AUTO_CREATE_SUBTBL == + g_Dbs.db[i].superTbls[j].autoCreateTable) { + fprintf(fp, " autoCreateTable: %s\n", "yes"); + } else { + fprintf(fp, " autoCreateTable: %s\n", "error"); + } + + if (TBL_NO_EXISTS == g_Dbs.db[i].superTbls[j].childTblExists) { + fprintf(fp, " childTblExists: %s\n", "no"); + } else if (TBL_ALREADY_EXISTS == + g_Dbs.db[i].superTbls[j].childTblExists) { + fprintf(fp, " childTblExists: %s\n", "yes"); + } else { + fprintf(fp, " childTblExists: %s\n", "error"); + } + + fprintf(fp, " childTblCount: %" PRId64 "\n", + g_Dbs.db[i].superTbls[j].childTblCount); + fprintf(fp, " childTblPrefix: %s\n", + g_Dbs.db[i].superTbls[j].childTblPrefix); + fprintf(fp, " dataSource: %s\n", + g_Dbs.db[i].superTbls[j].dataSource); + fprintf(fp, " iface: %s\n", + (g_Dbs.db[i].superTbls[j].iface == TAOSC_IFACE) ? "taosc" + : (g_Dbs.db[i].superTbls[j].iface == REST_IFACE) ? "rest" + : (g_Dbs.db[i].superTbls[j].iface == STMT_IFACE) ? "stmt" + : "sml"); + fprintf(fp, " insertRows: %" PRId64 "\n", + g_Dbs.db[i].superTbls[j].insertRows); + fprintf(fp, " interlace rows: %u\n", + g_Dbs.db[i].superTbls[j].interlaceRows); + if (g_Dbs.db[i].superTbls[j].interlaceRows > 0) { + fprintf(fp, " stable insert interval: %" PRIu64 "\n", + g_Dbs.db[i].superTbls[j].insertInterval); + } + /* + if (0 == g_Dbs.db[i].superTbls[j].multiThreadWriteOneTbl) { + fprintf(fp, " multiThreadWriteOneTbl: no\n"); + }else { + fprintf(fp, " multiThreadWriteOneTbl: yes\n"); + } + */ + fprintf(fp, " interlaceRows: %u\n", + g_Dbs.db[i].superTbls[j].interlaceRows); + fprintf(fp, " disorderRange: %d\n", + g_Dbs.db[i].superTbls[j].disorderRange); + fprintf(fp, " disorderRatio: %d\n", + g_Dbs.db[i].superTbls[j].disorderRatio); + fprintf(fp, " maxSqlLen: %" PRIu64 "\n", + g_Dbs.db[i].superTbls[j].maxSqlLen); + + fprintf(fp, " timeStampStep: %" PRId64 "\n", + g_Dbs.db[i].superTbls[j].timeStampStep); + fprintf(fp, " startTimestamp: %s\n", + g_Dbs.db[i].superTbls[j].startTimestamp); + fprintf(fp, " sampleFormat: %s\n", + g_Dbs.db[i].superTbls[j].sampleFormat); + fprintf(fp, " sampleFile: %s\n", + g_Dbs.db[i].superTbls[j].sampleFile); + fprintf(fp, " tagsFile: %s\n", + g_Dbs.db[i].superTbls[j].tagsFile); + + fprintf(fp, " columnCount: %d\n ", + g_Dbs.db[i].superTbls[j].columnCount); + for (int k = 0; k < g_Dbs.db[i].superTbls[j].columnCount; k++) { + // printf("dataType:%s, dataLen:%d\t", + // g_Dbs.db[i].superTbls[j].columns[k].dataType, + // g_Dbs.db[i].superTbls[j].columns[k].dataLen); + if ((0 == + strncasecmp(g_Dbs.db[i].superTbls[j].columns[k].dataType, + "binary", strlen("binary"))) || + (0 == + strncasecmp(g_Dbs.db[i].superTbls[j].columns[k].dataType, + "nchar", strlen("nchar")))) { + fprintf(fp, "column[%d]:%s(%d) ", k, + g_Dbs.db[i].superTbls[j].columns[k].dataType, + g_Dbs.db[i].superTbls[j].columns[k].dataLen); + } else { + fprintf(fp, "column[%d]:%s ", k, + g_Dbs.db[i].superTbls[j].columns[k].dataType); + } + } + fprintf(fp, "\n"); + + fprintf(fp, " tagCount: %d\n ", + g_Dbs.db[i].superTbls[j].tagCount); + for (int k = 0; k < g_Dbs.db[i].superTbls[j].tagCount; k++) { + // printf("dataType:%s, dataLen:%d\t", + // g_Dbs.db[i].superTbls[j].tags[k].dataType, + // g_Dbs.db[i].superTbls[j].tags[k].dataLen); + if ((0 == strncasecmp(g_Dbs.db[i].superTbls[j].tags[k].dataType, + "binary", strlen("binary"))) || + (0 == strncasecmp(g_Dbs.db[i].superTbls[j].tags[k].dataType, + "nchar", strlen("nchar")))) { + fprintf(fp, "tag[%d]:%s(%d) ", k, + g_Dbs.db[i].superTbls[j].tags[k].dataType, + g_Dbs.db[i].superTbls[j].tags[k].dataLen); + } else { + fprintf(fp, "tag[%d]:%s ", k, + g_Dbs.db[i].superTbls[j].tags[k].dataType); + } + } + fprintf(fp, "\n"); + } + fprintf(fp, "\n"); + } + + SHOW_PARSE_RESULT_END_TO_FILE(fp); +} + +void printfQueryMeta() { + setupForAnsiEscape(); + SHOW_PARSE_RESULT_START(); + + printf("host: \033[33m%s:%u\033[0m\n", g_queryInfo.host, + g_queryInfo.port); + printf("user: \033[33m%s\033[0m\n", g_queryInfo.user); + printf("database name: \033[33m%s\033[0m\n", g_queryInfo.dbName); + + printf("\n"); + + if ((SUBSCRIBE_TEST == g_args.test_mode) || + (QUERY_TEST == g_args.test_mode)) { + printf("specified table query info: \n"); + printf("sqlCount: \033[33m%d\033[0m\n", + g_queryInfo.specifiedQueryInfo.sqlCount); + if (g_queryInfo.specifiedQueryInfo.sqlCount > 0) { + printf("specified tbl query times:\n"); + printf(" \033[33m%" PRIu64 "\033[0m\n", + g_queryInfo.specifiedQueryInfo.queryTimes); + printf("query interval: \033[33m%" PRIu64 " ms\033[0m\n", + g_queryInfo.specifiedQueryInfo.queryInterval); + printf("top query times:\033[33m%" PRIu64 "\033[0m\n", + g_args.query_times); + printf("concurrent: \033[33m%d\033[0m\n", + g_queryInfo.specifiedQueryInfo.concurrent); + printf( + "mod: \033[33m%s\033[0m\n", + (g_queryInfo.specifiedQueryInfo.asyncMode) ? "async" : "sync"); + printf("interval: \033[33m%" PRIu64 "\033[0m\n", + g_queryInfo.specifiedQueryInfo.subscribeInterval); + printf("restart: \033[33m%d\033[0m\n", + g_queryInfo.specifiedQueryInfo.subscribeRestart); + printf("keepProgress: \033[33m%d\033[0m\n", + g_queryInfo.specifiedQueryInfo.subscribeKeepProgress); + + for (int i = 0; i < g_queryInfo.specifiedQueryInfo.sqlCount; i++) { + printf(" sql[%d]: \033[33m%s\033[0m\n", i, + g_queryInfo.specifiedQueryInfo.sql[i]); + } + printf("\n"); + } + + printf("super table query info:\n"); + printf("sqlCount: \033[33m%d\033[0m\n", + g_queryInfo.superQueryInfo.sqlCount); + + if (g_queryInfo.superQueryInfo.sqlCount > 0) { + printf("query interval: \033[33m%" PRIu64 "\033[0m\n", + g_queryInfo.superQueryInfo.queryInterval); + printf("threadCnt: \033[33m%d\033[0m\n", + g_queryInfo.superQueryInfo.threadCnt); + printf("childTblCount: \033[33m%" PRId64 "\033[0m\n", + g_queryInfo.superQueryInfo.childTblCount); + printf("stable name: \033[33m%s\033[0m\n", + g_queryInfo.superQueryInfo.stbName); + printf("stb query times:\033[33m%" PRIu64 "\033[0m\n", + g_queryInfo.superQueryInfo.queryTimes); + + printf("mod: \033[33m%s\033[0m\n", + (g_queryInfo.superQueryInfo.asyncMode) ? "async" : "sync"); + printf("interval: \033[33m%" PRIu64 "\033[0m\n", + g_queryInfo.superQueryInfo.subscribeInterval); + printf("restart: \033[33m%d\033[0m\n", + g_queryInfo.superQueryInfo.subscribeRestart); + printf("keepProgress: \033[33m%d\033[0m\n", + g_queryInfo.superQueryInfo.subscribeKeepProgress); + + for (int i = 0; i < g_queryInfo.superQueryInfo.sqlCount; i++) { + printf(" sql[%d]: \033[33m%s\033[0m\n", i, + g_queryInfo.superQueryInfo.sql[i]); + } + printf("\n"); + } + } + + SHOW_PARSE_RESULT_END(); +} + +void printfDbInfoForQueryToFile(char *filename, SDbInfo *dbInfos, int index) { + if (filename[0] == 0) return; + + FILE *fp = fopen(filename, "at"); + if (fp == NULL) { + errorPrint("failed to open file: %s\n", filename); + return; + } + + fprintf(fp, "================ database[%d] ================\n", index); + fprintf(fp, "name: %s\n", dbInfos->name); + fprintf(fp, "created_time: %s\n", dbInfos->create_time); + fprintf(fp, "ntables: %" PRId64 "\n", dbInfos->ntables); + fprintf(fp, "vgroups: %d\n", dbInfos->vgroups); + fprintf(fp, "replica: %d\n", dbInfos->replica); + fprintf(fp, "quorum: %d\n", dbInfos->quorum); + fprintf(fp, "days: %d\n", dbInfos->days); + fprintf(fp, "keep0,keep1,keep(D): %s\n", dbInfos->keeplist); + fprintf(fp, "cache(MB): %d\n", dbInfos->cache); + fprintf(fp, "blocks: %d\n", dbInfos->blocks); + fprintf(fp, "minrows: %d\n", dbInfos->minrows); + fprintf(fp, "maxrows: %d\n", dbInfos->maxrows); + fprintf(fp, "wallevel: %d\n", dbInfos->wallevel); + fprintf(fp, "fsync: %d\n", dbInfos->fsync); + fprintf(fp, "comp: %d\n", dbInfos->comp); + fprintf(fp, "cachelast: %d\n", dbInfos->cachelast); + fprintf(fp, "precision: %s\n", dbInfos->precision); + fprintf(fp, "update: %d\n", dbInfos->update); + fprintf(fp, "status: %s\n", dbInfos->status); + fprintf(fp, "\n"); + + fclose(fp); +} + +void printfQuerySystemInfo(TAOS *taos) { + char filename[MAX_FILE_NAME_LEN] = {0}; + char buffer[SQL_BUFF_LEN] = {0}; + TAOS_RES *res; + + time_t t; + struct tm *lt; + time(&t); + lt = localtime(&t); + snprintf(filename, MAX_FILE_NAME_LEN, "querySystemInfo-%d-%d-%d %d:%d:%d", + lt->tm_year + 1900, lt->tm_mon, lt->tm_mday, lt->tm_hour, + lt->tm_min, lt->tm_sec); + + // show variables + res = taos_query(taos, "show variables;"); + // fetchResult(res, filename); + xDumpResultToFile(filename, res); + + // show dnodes + res = taos_query(taos, "show dnodes;"); + xDumpResultToFile(filename, res); + // fetchResult(res, filename); + + // show databases + res = taos_query(taos, "show databases;"); + SDbInfo **dbInfos = + (SDbInfo **)calloc(MAX_DATABASE_COUNT, sizeof(SDbInfo *)); + if (dbInfos == NULL) { + errorPrint("%s", "failed to allocate memory\n"); + return; + } + int dbCount = getDbFromServer(taos, dbInfos); + if (dbCount <= 0) { + tmfree(dbInfos); + return; + } + + for (int i = 0; i < dbCount; i++) { + // printf database info + printfDbInfoForQueryToFile(filename, dbInfos[i], i); + + // show db.vgroups + snprintf(buffer, SQL_BUFF_LEN, "show %s.vgroups;", dbInfos[i]->name); + res = taos_query(taos, buffer); + xDumpResultToFile(filename, res); + + // show db.stables + snprintf(buffer, SQL_BUFF_LEN, "show %s.stables;", dbInfos[i]->name); + res = taos_query(taos, buffer); + xDumpResultToFile(filename, res); + free(dbInfos[i]); + } + + free(dbInfos); + resetAfterAnsiEscape(); +} + +void printStatPerThread(threadInfo *pThreadInfo) { + if (0 == pThreadInfo->totalDelay) pThreadInfo->totalDelay = 1; + + fprintf(stderr, + "====thread[%d] completed total inserted rows: %" PRIu64 + ", total affected rows: %" PRIu64 ". %.2f records/second====\n", + pThreadInfo->threadID, pThreadInfo->totalInsertRows, + pThreadInfo->totalAffectedRows, + (double)(pThreadInfo->totalAffectedRows / + ((double)pThreadInfo->totalDelay / 1000000.0))); +} + +void appendResultBufToFile(char *resultBuf, threadInfo *pThreadInfo) { + pThreadInfo->fp = fopen(pThreadInfo->filePath, "at"); + if (pThreadInfo->fp == NULL) { + errorPrint( + "%s() LN%d, failed to open result file: %s, result will not save " + "to file\n", + __func__, __LINE__, pThreadInfo->filePath); + return; + } + + fprintf(pThreadInfo->fp, "%s", resultBuf); + tmfclose(pThreadInfo->fp); + pThreadInfo->fp = NULL; +} \ No newline at end of file diff --git a/src/kit/taosdemo/src/demoQuery.c b/src/kit/taosdemo/src/demoQuery.c new file mode 100644 index 0000000000000000000000000000000000000000..d8e8438fa7177db993c6da1cc5ac5cad98ef3010 --- /dev/null +++ b/src/kit/taosdemo/src/demoQuery.c @@ -0,0 +1,446 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#include "demo.h" + +void selectAndGetResult(threadInfo *pThreadInfo, char *command) { + if (0 == strncasecmp(g_queryInfo.queryMode, "taosc", strlen("taosc"))) { + TAOS_RES *res = taos_query(pThreadInfo->taos, command); + if (res == NULL || taos_errno(res) != 0) { + errorPrint("failed to execute sql:%s, reason:%s\n", command, + taos_errstr(res)); + taos_free_result(res); + return; + } + + fetchResult(res, pThreadInfo); + taos_free_result(res); + + } else if (0 == + strncasecmp(g_queryInfo.queryMode, "rest", strlen("rest"))) { + int retCode = postProceSql(g_queryInfo.host, g_queryInfo.port, command, + pThreadInfo); + if (0 != retCode) { + printf("====restful return fail, threadID[%d]\n", + pThreadInfo->threadID); + } + + } else { + errorPrint("unknown query mode: %s\n", g_queryInfo.queryMode); + } +} + +void *specifiedTableQuery(void *sarg) { + threadInfo *pThreadInfo = (threadInfo *)sarg; + + setThreadName("specTableQuery"); + + if (pThreadInfo->taos == NULL) { + TAOS *taos = NULL; + taos = taos_connect(g_queryInfo.host, g_queryInfo.user, + g_queryInfo.password, NULL, g_queryInfo.port); + if (taos == NULL) { + errorPrint("[%d] Failed to connect to TDengine, reason:%s\n", + pThreadInfo->threadID, taos_errstr(NULL)); + return NULL; + } else { + pThreadInfo->taos = taos; + } + } + + char sqlStr[TSDB_DB_NAME_LEN + 5]; + sprintf(sqlStr, "use %s", g_queryInfo.dbName); + if (0 != queryDbExec(pThreadInfo->taos, sqlStr, NO_INSERT_TYPE, false)) { + taos_close(pThreadInfo->taos); + errorPrint("use database %s failed!\n\n", g_queryInfo.dbName); + return NULL; + } + + uint64_t st = 0; + uint64_t et = 0; + + uint64_t queryTimes = g_queryInfo.specifiedQueryInfo.queryTimes; + + uint64_t totalQueried = 0; + uint64_t lastPrintTime = taosGetTimestampMs(); + uint64_t startTs = taosGetTimestampMs(); + + if (g_queryInfo.specifiedQueryInfo.result[pThreadInfo->querySeq][0] != + '\0') { + sprintf(pThreadInfo->filePath, "%s-%d", + g_queryInfo.specifiedQueryInfo.result[pThreadInfo->querySeq], + pThreadInfo->threadID); + } + + while (queryTimes--) { + if (g_queryInfo.specifiedQueryInfo.queryInterval && + (et - st) < (int64_t)g_queryInfo.specifiedQueryInfo.queryInterval) { + taosMsleep((int32_t)(g_queryInfo.specifiedQueryInfo.queryInterval - + (et - st))); // ms + } + + st = taosGetTimestampMs(); + + selectAndGetResult( + pThreadInfo, + g_queryInfo.specifiedQueryInfo.sql[pThreadInfo->querySeq]); + + et = taosGetTimestampMs(); + printf("=thread[%" PRId64 "] use %s complete one sql, Spent %10.3f s\n", + taosGetSelfPthreadId(), g_queryInfo.queryMode, + (et - st) / 1000.0); + + totalQueried++; + g_queryInfo.specifiedQueryInfo.totalQueried++; + + uint64_t currentPrintTime = taosGetTimestampMs(); + uint64_t endTs = taosGetTimestampMs(); + if (currentPrintTime - lastPrintTime > 30 * 1000) { + debugPrint("%s() LN%d, endTs=%" PRIu64 " ms, startTs=%" PRIu64 + " ms\n", + __func__, __LINE__, endTs, startTs); + printf("thread[%d] has currently completed queries: %" PRIu64 + ", QPS: %10.6f\n", + pThreadInfo->threadID, totalQueried, + (double)(totalQueried / ((endTs - startTs) / 1000.0))); + lastPrintTime = currentPrintTime; + } + } + return NULL; +} + +void *superTableQuery(void *sarg) { + char *sqlstr = calloc(1, BUFFER_SIZE); + if (NULL == sqlstr) { + errorPrint("%s", "failed to allocate memory\n"); + return NULL; + } + + threadInfo *pThreadInfo = (threadInfo *)sarg; + + setThreadName("superTableQuery"); + + if (pThreadInfo->taos == NULL) { + TAOS *taos = NULL; + taos = taos_connect(g_queryInfo.host, g_queryInfo.user, + g_queryInfo.password, NULL, g_queryInfo.port); + if (taos == NULL) { + errorPrint("[%d] Failed to connect to TDengine, reason:%s\n", + pThreadInfo->threadID, taos_errstr(NULL)); + free(sqlstr); + return NULL; + } else { + pThreadInfo->taos = taos; + } + } + + uint64_t st = 0; + uint64_t et = (int64_t)g_queryInfo.superQueryInfo.queryInterval; + + uint64_t queryTimes = g_queryInfo.superQueryInfo.queryTimes; + uint64_t totalQueried = 0; + uint64_t startTs = taosGetTimestampMs(); + + uint64_t lastPrintTime = taosGetTimestampMs(); + while (queryTimes--) { + if (g_queryInfo.superQueryInfo.queryInterval && + (et - st) < (int64_t)g_queryInfo.superQueryInfo.queryInterval) { + taosMsleep((int32_t)(g_queryInfo.superQueryInfo.queryInterval - + (et - st))); // ms + // printf("========sleep duration:%"PRId64 "========inserted + // rows:%d, table range:%d - %d\n", (1000 - (et - st)), i, + // pThreadInfo->start_table_from, pThreadInfo->end_table_to); + } + + st = taosGetTimestampMs(); + for (int i = (int)pThreadInfo->start_table_from; + i <= pThreadInfo->end_table_to; i++) { + for (int j = 0; j < g_queryInfo.superQueryInfo.sqlCount; j++) { + memset(sqlstr, 0, BUFFER_SIZE); + replaceChildTblName(g_queryInfo.superQueryInfo.sql[j], sqlstr, + i); + if (g_queryInfo.superQueryInfo.result[j][0] != '\0') { + sprintf(pThreadInfo->filePath, "%s-%d", + g_queryInfo.superQueryInfo.result[j], + pThreadInfo->threadID); + } + selectAndGetResult(pThreadInfo, sqlstr); + + totalQueried++; + g_queryInfo.superQueryInfo.totalQueried++; + + int64_t currentPrintTime = taosGetTimestampMs(); + int64_t endTs = taosGetTimestampMs(); + if (currentPrintTime - lastPrintTime > 30 * 1000) { + printf( + "thread[%d] has currently completed queries: %" PRIu64 + ", QPS: %10.3f\n", + pThreadInfo->threadID, totalQueried, + (double)(totalQueried / ((endTs - startTs) / 1000.0))); + lastPrintTime = currentPrintTime; + } + } + } + et = taosGetTimestampMs(); + printf("####thread[%" PRId64 + "] complete all sqls to allocate all sub-tables[%" PRIu64 + " - %" PRIu64 "] once queries duration:%.4fs\n\n", + taosGetSelfPthreadId(), pThreadInfo->start_table_from, + pThreadInfo->end_table_to, (double)(et - st) / 1000.0); + } + + free(sqlstr); + return NULL; +} + +int queryTestProcess() { + printfQueryMeta(); + + TAOS *taos = NULL; + taos = taos_connect(g_queryInfo.host, g_queryInfo.user, + g_queryInfo.password, NULL, g_queryInfo.port); + if (taos == NULL) { + errorPrint("Failed to connect to TDengine, reason:%s\n", + taos_errstr(NULL)); + exit(EXIT_FAILURE); + } + + if (0 != g_queryInfo.superQueryInfo.sqlCount) { + getAllChildNameOfSuperTable(taos, g_queryInfo.dbName, + g_queryInfo.superQueryInfo.stbName, + &g_queryInfo.superQueryInfo.childTblName, + &g_queryInfo.superQueryInfo.childTblCount); + } + + prompt(); + + if (g_args.debug_print || g_args.verbose_print) { + printfQuerySystemInfo(taos); + } + + if (0 == strncasecmp(g_queryInfo.queryMode, "rest", strlen("rest"))) { + if (convertHostToServAddr(g_queryInfo.host, g_queryInfo.port, + &g_queryInfo.serv_addr) != 0) + ERROR_EXIT("convert host to server address"); + } + + pthread_t * pids = NULL; + threadInfo *infos = NULL; + //==== create sub threads for query from specify table + int nConcurrent = g_queryInfo.specifiedQueryInfo.concurrent; + uint64_t nSqlCount = g_queryInfo.specifiedQueryInfo.sqlCount; + + uint64_t startTs = taosGetTimestampMs(); + + if ((nSqlCount > 0) && (nConcurrent > 0)) { + pids = calloc(1, nConcurrent * nSqlCount * sizeof(pthread_t)); + infos = calloc(1, nConcurrent * nSqlCount * sizeof(threadInfo)); + + if ((NULL == pids) || (NULL == infos)) { + taos_close(taos); + ERROR_EXIT("memory allocation failed for create threads\n"); + } + + for (uint64_t i = 0; i < nSqlCount; i++) { + for (int j = 0; j < nConcurrent; j++) { + uint64_t seq = i * nConcurrent + j; + threadInfo *pThreadInfo = infos + seq; + pThreadInfo->threadID = (int)seq; + pThreadInfo->querySeq = i; + + if (0 == strncasecmp(g_queryInfo.queryMode, "taosc", 5)) { + char sqlStr[TSDB_DB_NAME_LEN + 5]; + sprintf(sqlStr, "USE %s", g_queryInfo.dbName); + if (0 != queryDbExec(taos, sqlStr, NO_INSERT_TYPE, false)) { + taos_close(taos); + free(infos); + free(pids); + errorPrint("use database %s failed!\n\n", + g_queryInfo.dbName); + return -1; + } + } + + if (0 == strncasecmp(g_queryInfo.queryMode, "rest", 4)) { +#ifdef WINDOWS + WSADATA wsaData; + WSAStartup(MAKEWORD(2, 2), &wsaData); + SOCKET sockfd; +#else + int sockfd; +#endif + sockfd = socket(AF_INET, SOCK_STREAM, 0); + if (sockfd < 0) { +#ifdef WINDOWS + errorPrint("Could not create socket : %d", + WSAGetLastError()); +#endif + debugPrint("%s() LN%d, sockfd=%d\n", __func__, __LINE__, + sockfd); + ERROR_EXIT("opening socket"); + } + + int retConn = connect( + sockfd, (struct sockaddr *)&(g_queryInfo.serv_addr), + sizeof(struct sockaddr)); + debugPrint("%s() LN%d connect() return %d\n", __func__, + __LINE__, retConn); + if (retConn < 0) { + ERROR_EXIT("connecting"); + } + pThreadInfo->sockfd = sockfd; + } + pThreadInfo->taos = + NULL; // workaround to use separate taos connection; + + pthread_create(pids + seq, NULL, specifiedTableQuery, + pThreadInfo); + } + } + } else { + g_queryInfo.specifiedQueryInfo.concurrent = 0; + } + + taos_close(taos); + + pthread_t * pidsOfSub = NULL; + threadInfo *infosOfSub = NULL; + //==== create sub threads for query from all sub table of the super table + if ((g_queryInfo.superQueryInfo.sqlCount > 0) && + (g_queryInfo.superQueryInfo.threadCnt > 0)) { + pidsOfSub = + calloc(1, g_queryInfo.superQueryInfo.threadCnt * sizeof(pthread_t)); + infosOfSub = calloc( + 1, g_queryInfo.superQueryInfo.threadCnt * sizeof(threadInfo)); + + if ((NULL == pidsOfSub) || (NULL == infosOfSub)) { + free(infos); + free(pids); + + ERROR_EXIT("memory allocation failed for create threads\n"); + } + + int64_t ntables = g_queryInfo.superQueryInfo.childTblCount; + int threads = g_queryInfo.superQueryInfo.threadCnt; + + int64_t a = ntables / threads; + if (a < 1) { + threads = (int)ntables; + a = 1; + } + + int64_t b = 0; + if (threads != 0) { + b = ntables % threads; + } + + uint64_t tableFrom = 0; + for (int i = 0; i < threads; i++) { + threadInfo *pThreadInfo = infosOfSub + i; + pThreadInfo->threadID = i; + + pThreadInfo->start_table_from = tableFrom; + pThreadInfo->ntables = i < b ? a + 1 : a; + pThreadInfo->end_table_to = + i < b ? tableFrom + a : tableFrom + a - 1; + tableFrom = pThreadInfo->end_table_to + 1; + pThreadInfo->taos = + NULL; // workaround to use separate taos connection; + if (0 == strncasecmp(g_queryInfo.queryMode, "rest", 4)) { +#ifdef WINDOWS + WSADATA wsaData; + WSAStartup(MAKEWORD(2, 2), &wsaData); + SOCKET sockfd; +#else + int sockfd; +#endif + sockfd = socket(AF_INET, SOCK_STREAM, 0); + if (sockfd < 0) { +#ifdef WINDOWS + errorPrint("Could not create socket : %d", + WSAGetLastError()); +#endif + debugPrint("%s() LN%d, sockfd=%d\n", __func__, __LINE__, + sockfd); + ERROR_EXIT("opening socket"); + } + + int retConn = + connect(sockfd, (struct sockaddr *)&(g_queryInfo.serv_addr), + sizeof(struct sockaddr)); + debugPrint("%s() LN%d connect() return %d\n", __func__, + __LINE__, retConn); + if (retConn < 0) { + ERROR_EXIT("connecting"); + } + pThreadInfo->sockfd = sockfd; + } + pthread_create(pidsOfSub + i, NULL, superTableQuery, pThreadInfo); + } + + g_queryInfo.superQueryInfo.threadCnt = threads; + } else { + g_queryInfo.superQueryInfo.threadCnt = 0; + } + + if ((nSqlCount > 0) && (nConcurrent > 0)) { + for (int i = 0; i < nConcurrent; i++) { + for (int j = 0; j < nSqlCount; j++) { + pthread_join(pids[i * nSqlCount + j], NULL); + if (0 == strncasecmp(g_queryInfo.queryMode, "rest", 4)) { + threadInfo *pThreadInfo = infos + i * nSqlCount + j; +#ifdef WINDOWS + closesocket(pThreadInfo->sockfd); + WSACleanup(); +#else + close(pThreadInfo->sockfd); +#endif + } + } + } + } + + tmfree((char *)pids); + tmfree((char *)infos); + + for (int i = 0; i < g_queryInfo.superQueryInfo.threadCnt; i++) { + pthread_join(pidsOfSub[i], NULL); + if (0 == strncasecmp(g_queryInfo.queryMode, "rest", 4)) { + threadInfo *pThreadInfo = infosOfSub + i; +#ifdef WINDOWS + closesocket(pThreadInfo->sockfd); + WSACleanup(); +#else + close(pThreadInfo->sockfd); +#endif + } + } + + tmfree((char *)pidsOfSub); + tmfree((char *)infosOfSub); + + // taos_close(taos);// workaround to use separate taos connection; + uint64_t endTs = taosGetTimestampMs(); + + uint64_t totalQueried = g_queryInfo.specifiedQueryInfo.totalQueried + + g_queryInfo.superQueryInfo.totalQueried; + + fprintf(stderr, + "==== completed total queries: %" PRIu64 + ", the QPS of all threads: %10.3f====\n", + totalQueried, + (double)(totalQueried / ((endTs - startTs) / 1000.0))); + return 0; +} \ No newline at end of file diff --git a/src/kit/taosdemo/src/demoSubscribe.c b/src/kit/taosdemo/src/demoSubscribe.c new file mode 100644 index 0000000000000000000000000000000000000000..1386193f4059ad60eb66c08e7078173a99c29da2 --- /dev/null +++ b/src/kit/taosdemo/src/demoSubscribe.c @@ -0,0 +1,505 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#include "demo.h" + +void stable_sub_callback(TAOS_SUB *tsub, TAOS_RES *res, void *param, int code) { + if (res == NULL || taos_errno(res) != 0) { + errorPrint( + "%s() LN%d, failed to subscribe result, code:%d, reason:%s\n", + __func__, __LINE__, code, taos_errstr(res)); + return; + } + + if (param) fetchResult(res, (threadInfo *)param); + // tao_unsubscribe() will free result. +} + +void specified_sub_callback(TAOS_SUB *tsub, TAOS_RES *res, void *param, + int code) { + if (res == NULL || taos_errno(res) != 0) { + errorPrint( + "%s() LN%d, failed to subscribe result, code:%d, reason:%s\n", + __func__, __LINE__, code, taos_errstr(res)); + return; + } + + if (param) fetchResult(res, (threadInfo *)param); + // tao_unsubscribe() will free result. +} + +TAOS_SUB *subscribeImpl(QUERY_CLASS class, threadInfo *pThreadInfo, char *sql, + char *topic, bool restart, uint64_t interval) { + TAOS_SUB *tsub = NULL; + + if ((SPECIFIED_CLASS == class) && + (ASYNC_MODE == g_queryInfo.specifiedQueryInfo.asyncMode)) { + tsub = taos_subscribe( + pThreadInfo->taos, restart, topic, sql, specified_sub_callback, + (void *)pThreadInfo, + (int)g_queryInfo.specifiedQueryInfo.subscribeInterval); + } else if ((STABLE_CLASS == class) && + (ASYNC_MODE == g_queryInfo.superQueryInfo.asyncMode)) { + tsub = + taos_subscribe(pThreadInfo->taos, restart, topic, sql, + stable_sub_callback, (void *)pThreadInfo, + (int)g_queryInfo.superQueryInfo.subscribeInterval); + } else { + tsub = taos_subscribe(pThreadInfo->taos, restart, topic, sql, NULL, + NULL, (int)interval); + } + + if (tsub == NULL) { + errorPrint("failed to create subscription. topic:%s, sql:%s\n", topic, + sql); + return NULL; + } + + return tsub; +} + +void *specifiedSubscribe(void *sarg) { + threadInfo *pThreadInfo = (threadInfo *)sarg; + // TAOS_SUB* tsub = NULL; + + setThreadName("specSub"); + + if (pThreadInfo->taos == NULL) { + pThreadInfo->taos = taos_connect(g_queryInfo.host, g_queryInfo.user, + g_queryInfo.password, + g_queryInfo.dbName, g_queryInfo.port); + if (pThreadInfo->taos == NULL) { + errorPrint("[%d] Failed to connect to TDengine, reason:%s\n", + pThreadInfo->threadID, taos_errstr(NULL)); + return NULL; + } + } + + char sqlStr[TSDB_DB_NAME_LEN + 5]; + sprintf(sqlStr, "USE %s", g_queryInfo.dbName); + if (0 != queryDbExec(pThreadInfo->taos, sqlStr, NO_INSERT_TYPE, false)) { + taos_close(pThreadInfo->taos); + return NULL; + } + + sprintf(g_queryInfo.specifiedQueryInfo.topic[pThreadInfo->threadID], + "taosdemo-subscribe-%" PRIu64 "-%d", pThreadInfo->querySeq, + pThreadInfo->threadID); + if (g_queryInfo.specifiedQueryInfo.result[pThreadInfo->querySeq][0] != + '\0') { + sprintf(pThreadInfo->filePath, "%s-%d", + g_queryInfo.specifiedQueryInfo.result[pThreadInfo->querySeq], + pThreadInfo->threadID); + } + g_queryInfo.specifiedQueryInfo.tsub[pThreadInfo->threadID] = subscribeImpl( + SPECIFIED_CLASS, pThreadInfo, + g_queryInfo.specifiedQueryInfo.sql[pThreadInfo->querySeq], + g_queryInfo.specifiedQueryInfo.topic[pThreadInfo->threadID], + g_queryInfo.specifiedQueryInfo.subscribeRestart, + g_queryInfo.specifiedQueryInfo.subscribeInterval); + if (NULL == g_queryInfo.specifiedQueryInfo.tsub[pThreadInfo->threadID]) { + taos_close(pThreadInfo->taos); + return NULL; + } + + // start loop to consume result + + g_queryInfo.specifiedQueryInfo.consumed[pThreadInfo->threadID] = 0; + while ((g_queryInfo.specifiedQueryInfo + .endAfterConsume[pThreadInfo->querySeq] == -1) || + (g_queryInfo.specifiedQueryInfo.consumed[pThreadInfo->threadID] < + g_queryInfo.specifiedQueryInfo + .endAfterConsume[pThreadInfo->querySeq])) { + printf("consumed[%d]: %d, endAfterConsum[%" PRId64 "]: %d\n", + pThreadInfo->threadID, + g_queryInfo.specifiedQueryInfo.consumed[pThreadInfo->threadID], + pThreadInfo->querySeq, + g_queryInfo.specifiedQueryInfo + .endAfterConsume[pThreadInfo->querySeq]); + if (ASYNC_MODE == g_queryInfo.specifiedQueryInfo.asyncMode) { + continue; + } + + g_queryInfo.specifiedQueryInfo.res[pThreadInfo->threadID] = + taos_consume( + g_queryInfo.specifiedQueryInfo.tsub[pThreadInfo->threadID]); + if (g_queryInfo.specifiedQueryInfo.res[pThreadInfo->threadID]) { + if (g_queryInfo.specifiedQueryInfo + .result[pThreadInfo->querySeq][0] != 0) { + sprintf(pThreadInfo->filePath, "%s-%d", + g_queryInfo.specifiedQueryInfo + .result[pThreadInfo->querySeq], + pThreadInfo->threadID); + } + fetchResult( + g_queryInfo.specifiedQueryInfo.res[pThreadInfo->threadID], + pThreadInfo); + + g_queryInfo.specifiedQueryInfo.consumed[pThreadInfo->threadID]++; + if ((g_queryInfo.specifiedQueryInfo + .resubAfterConsume[pThreadInfo->querySeq] != -1) && + (g_queryInfo.specifiedQueryInfo + .consumed[pThreadInfo->threadID] >= + g_queryInfo.specifiedQueryInfo + .resubAfterConsume[pThreadInfo->querySeq])) { + printf("keepProgress:%d, resub specified query: %" PRIu64 "\n", + g_queryInfo.specifiedQueryInfo.subscribeKeepProgress, + pThreadInfo->querySeq); + g_queryInfo.specifiedQueryInfo.consumed[pThreadInfo->threadID] = + 0; + taos_unsubscribe( + g_queryInfo.specifiedQueryInfo.tsub[pThreadInfo->threadID], + g_queryInfo.specifiedQueryInfo.subscribeKeepProgress); + g_queryInfo.specifiedQueryInfo + .tsub[pThreadInfo->threadID] = subscribeImpl( + SPECIFIED_CLASS, pThreadInfo, + g_queryInfo.specifiedQueryInfo.sql[pThreadInfo->querySeq], + g_queryInfo.specifiedQueryInfo.topic[pThreadInfo->threadID], + g_queryInfo.specifiedQueryInfo.subscribeRestart, + g_queryInfo.specifiedQueryInfo.subscribeInterval); + if (NULL == g_queryInfo.specifiedQueryInfo + .tsub[pThreadInfo->threadID]) { + taos_close(pThreadInfo->taos); + return NULL; + } + } + } + } + taos_free_result(g_queryInfo.specifiedQueryInfo.res[pThreadInfo->threadID]); + taos_close(pThreadInfo->taos); + + return NULL; +} + +static void *superSubscribe(void *sarg) { + threadInfo *pThreadInfo = (threadInfo *)sarg; + char * subSqlStr = calloc(1, BUFFER_SIZE); + if (NULL == subSqlStr) { + errorPrint("%s", "failed to allocate memory\n"); + } + + TAOS_SUB *tsub[MAX_QUERY_SQL_COUNT] = {0}; + uint64_t tsubSeq; + + setThreadName("superSub"); + + if (pThreadInfo->ntables > MAX_QUERY_SQL_COUNT) { + free(subSqlStr); + errorPrint("The table number(%" PRId64 + ") of the thread is more than max query sql count: %d\n", + pThreadInfo->ntables, MAX_QUERY_SQL_COUNT); + exit(EXIT_FAILURE); + } + + if (pThreadInfo->taos == NULL) { + pThreadInfo->taos = taos_connect(g_queryInfo.host, g_queryInfo.user, + g_queryInfo.password, + g_queryInfo.dbName, g_queryInfo.port); + if (pThreadInfo->taos == NULL) { + errorPrint("[%d] Failed to connect to TDengine, reason:%s\n", + pThreadInfo->threadID, taos_errstr(NULL)); + free(subSqlStr); + return NULL; + } + } + + char sqlStr[TSDB_DB_NAME_LEN + 5]; + sprintf(sqlStr, "USE %s", g_queryInfo.dbName); + if (0 != queryDbExec(pThreadInfo->taos, sqlStr, NO_INSERT_TYPE, false)) { + taos_close(pThreadInfo->taos); + errorPrint("use database %s failed!\n\n", g_queryInfo.dbName); + free(subSqlStr); + return NULL; + } + + char topic[32] = {0}; + for (uint64_t i = pThreadInfo->start_table_from; + i <= pThreadInfo->end_table_to; i++) { + tsubSeq = i - pThreadInfo->start_table_from; + verbosePrint("%s() LN%d, [%d], start=%" PRId64 " end=%" PRId64 + " i=%" PRIu64 "\n", + __func__, __LINE__, pThreadInfo->threadID, + pThreadInfo->start_table_from, pThreadInfo->end_table_to, + i); + sprintf(topic, "taosdemo-subscribe-%" PRIu64 "-%" PRIu64 "", i, + pThreadInfo->querySeq); + memset(subSqlStr, 0, BUFFER_SIZE); + replaceChildTblName( + g_queryInfo.superQueryInfo.sql[pThreadInfo->querySeq], subSqlStr, + (int)i); + if (g_queryInfo.superQueryInfo.result[pThreadInfo->querySeq][0] != 0) { + sprintf(pThreadInfo->filePath, "%s-%d", + g_queryInfo.superQueryInfo.result[pThreadInfo->querySeq], + pThreadInfo->threadID); + } + + verbosePrint("%s() LN%d, [%d] subSqlStr: %s\n", __func__, __LINE__, + pThreadInfo->threadID, subSqlStr); + tsub[tsubSeq] = + subscribeImpl(STABLE_CLASS, pThreadInfo, subSqlStr, topic, + g_queryInfo.superQueryInfo.subscribeRestart, + g_queryInfo.superQueryInfo.subscribeInterval); + if (NULL == tsub[tsubSeq]) { + taos_close(pThreadInfo->taos); + free(subSqlStr); + return NULL; + } + } + + // start loop to consume result + int consumed[MAX_QUERY_SQL_COUNT]; + for (int i = 0; i < MAX_QUERY_SQL_COUNT; i++) { + consumed[i] = 0; + } + TAOS_RES *res = NULL; + + uint64_t st = 0, et = 0; + + while ( + (g_queryInfo.superQueryInfo.endAfterConsume == -1) || + (g_queryInfo.superQueryInfo.endAfterConsume > + consumed[pThreadInfo->end_table_to - pThreadInfo->start_table_from])) { + verbosePrint("super endAfterConsume: %d, consumed: %d\n", + g_queryInfo.superQueryInfo.endAfterConsume, + consumed[pThreadInfo->end_table_to - + pThreadInfo->start_table_from]); + for (uint64_t i = pThreadInfo->start_table_from; + i <= pThreadInfo->end_table_to; i++) { + tsubSeq = i - pThreadInfo->start_table_from; + if (ASYNC_MODE == g_queryInfo.superQueryInfo.asyncMode) { + continue; + } + + st = taosGetTimestampMs(); + performancePrint("st: %" PRIu64 " et: %" PRIu64 " st-et: %" PRIu64 + "\n", + st, et, (st - et)); + res = taos_consume(tsub[tsubSeq]); + et = taosGetTimestampMs(); + performancePrint("st: %" PRIu64 " et: %" PRIu64 " delta: %" PRIu64 + "\n", + st, et, (et - st)); + + if (res) { + if (g_queryInfo.superQueryInfo + .result[pThreadInfo->querySeq][0] != 0) { + sprintf(pThreadInfo->filePath, "%s-%d", + g_queryInfo.superQueryInfo + .result[pThreadInfo->querySeq], + pThreadInfo->threadID); + fetchResult(res, pThreadInfo); + } + consumed[tsubSeq]++; + + if ((g_queryInfo.superQueryInfo.resubAfterConsume != -1) && + (consumed[tsubSeq] >= + g_queryInfo.superQueryInfo.resubAfterConsume)) { + verbosePrint( + "%s() LN%d, keepProgress:%d, resub super table query: " + "%" PRIu64 "\n", + __func__, __LINE__, + g_queryInfo.superQueryInfo.subscribeKeepProgress, + pThreadInfo->querySeq); + taos_unsubscribe( + tsub[tsubSeq], + g_queryInfo.superQueryInfo.subscribeKeepProgress); + consumed[tsubSeq] = 0; + tsub[tsubSeq] = subscribeImpl( + STABLE_CLASS, pThreadInfo, subSqlStr, topic, + g_queryInfo.superQueryInfo.subscribeRestart, + g_queryInfo.superQueryInfo.subscribeInterval); + if (NULL == tsub[tsubSeq]) { + taos_close(pThreadInfo->taos); + free(subSqlStr); + return NULL; + } + } + } + } + } + verbosePrint( + "%s() LN%d, super endAfterConsume: %d, consumed: %d\n", __func__, + __LINE__, g_queryInfo.superQueryInfo.endAfterConsume, + consumed[pThreadInfo->end_table_to - pThreadInfo->start_table_from]); + taos_free_result(res); + + for (uint64_t i = pThreadInfo->start_table_from; + i <= pThreadInfo->end_table_to; i++) { + tsubSeq = i - pThreadInfo->start_table_from; + taos_unsubscribe(tsub[tsubSeq], 0); + } + + taos_close(pThreadInfo->taos); + free(subSqlStr); + return NULL; +} + +int subscribeTestProcess() { + setupForAnsiEscape(); + printfQueryMeta(); + resetAfterAnsiEscape(); + + prompt(); + + TAOS *taos = NULL; + taos = + taos_connect(g_queryInfo.host, g_queryInfo.user, g_queryInfo.password, + g_queryInfo.dbName, g_queryInfo.port); + if (taos == NULL) { + errorPrint("Failed to connect to TDengine, reason:%s\n", + taos_errstr(NULL)); + exit(EXIT_FAILURE); + } + + if (0 != g_queryInfo.superQueryInfo.sqlCount) { + getAllChildNameOfSuperTable(taos, g_queryInfo.dbName, + g_queryInfo.superQueryInfo.stbName, + &g_queryInfo.superQueryInfo.childTblName, + &g_queryInfo.superQueryInfo.childTblCount); + } + + taos_close(taos); // workaround to use separate taos connection; + + pthread_t * pids = NULL; + threadInfo *infos = NULL; + + pthread_t * pidsOfStable = NULL; + threadInfo *infosOfStable = NULL; + + //==== create threads for query for specified table + if (g_queryInfo.specifiedQueryInfo.sqlCount <= 0) { + debugPrint("%s() LN%d, specified query sqlCount %d.\n", __func__, + __LINE__, g_queryInfo.specifiedQueryInfo.sqlCount); + } else { + if (g_queryInfo.specifiedQueryInfo.concurrent <= 0) { + errorPrint("specified query sqlCount %d.\n", + g_queryInfo.specifiedQueryInfo.sqlCount); + exit(EXIT_FAILURE); + } + + pids = calloc(1, g_queryInfo.specifiedQueryInfo.sqlCount * + g_queryInfo.specifiedQueryInfo.concurrent * + sizeof(pthread_t)); + if (pids == NULL) { + errorPrint("%s", "failed to allocate memory\n"); + } + + infos = calloc(1, g_queryInfo.specifiedQueryInfo.sqlCount * + g_queryInfo.specifiedQueryInfo.concurrent * + sizeof(threadInfo)); + + if (infos == NULL) { + errorPrint("%s", "failed to allocate memory\n"); + } + + for (int i = 0; i < g_queryInfo.specifiedQueryInfo.sqlCount; i++) { + for (int j = 0; j < g_queryInfo.specifiedQueryInfo.concurrent; + j++) { + uint64_t seq = + i * g_queryInfo.specifiedQueryInfo.concurrent + j; + threadInfo *pThreadInfo = infos + seq; + pThreadInfo->threadID = (int)seq; + pThreadInfo->querySeq = i; + pThreadInfo->taos = + NULL; // workaround to use separate taos connection; + pthread_create(pids + seq, NULL, specifiedSubscribe, + pThreadInfo); + } + } + } + + //==== create threads for super table query + if (g_queryInfo.superQueryInfo.sqlCount <= 0) { + debugPrint("%s() LN%d, super table query sqlCount %d.\n", __func__, + __LINE__, g_queryInfo.superQueryInfo.sqlCount); + } else { + if ((g_queryInfo.superQueryInfo.sqlCount > 0) && + (g_queryInfo.superQueryInfo.threadCnt > 0)) { + pidsOfStable = calloc(1, g_queryInfo.superQueryInfo.sqlCount * + g_queryInfo.superQueryInfo.threadCnt * + sizeof(pthread_t)); + + if (pidsOfStable) { + errorPrint("%s", "failed to allocate memory\n"); + } + + infosOfStable = calloc(1, g_queryInfo.superQueryInfo.sqlCount * + g_queryInfo.superQueryInfo.threadCnt * + sizeof(threadInfo)); + + if (infosOfStable) { + errorPrint("%s", "failed to allocate memmory\n"); + } + + int64_t ntables = g_queryInfo.superQueryInfo.childTblCount; + int threads = g_queryInfo.superQueryInfo.threadCnt; + + int64_t a = ntables / threads; + if (a < 1) { + threads = (int)ntables; + a = 1; + } + + int64_t b = 0; + if (threads != 0) { + b = ntables % threads; + } + + for (uint64_t i = 0; i < g_queryInfo.superQueryInfo.sqlCount; i++) { + uint64_t tableFrom = 0; + for (int j = 0; j < threads; j++) { + uint64_t seq = i * threads + j; + threadInfo *pThreadInfo = infosOfStable + seq; + pThreadInfo->threadID = (int)seq; + pThreadInfo->querySeq = i; + + pThreadInfo->start_table_from = tableFrom; + pThreadInfo->ntables = j < b ? a + 1 : a; + pThreadInfo->end_table_to = + j < b ? tableFrom + a : tableFrom + a - 1; + tableFrom = pThreadInfo->end_table_to + 1; + pThreadInfo->taos = + NULL; // workaround to use separate taos connection; + pthread_create(pidsOfStable + seq, NULL, superSubscribe, + pThreadInfo); + } + } + + g_queryInfo.superQueryInfo.threadCnt = threads; + + for (int i = 0; i < g_queryInfo.superQueryInfo.sqlCount; i++) { + for (int j = 0; j < threads; j++) { + uint64_t seq = i * threads + j; + pthread_join(pidsOfStable[seq], NULL); + } + } + } + } + + for (int i = 0; i < g_queryInfo.specifiedQueryInfo.sqlCount; i++) { + for (int j = 0; j < g_queryInfo.specifiedQueryInfo.concurrent; j++) { + uint64_t seq = i * g_queryInfo.specifiedQueryInfo.concurrent + j; + pthread_join(pids[seq], NULL); + } + } + + tmfree((char *)pids); + tmfree((char *)infos); + + tmfree((char *)pidsOfStable); + tmfree((char *)infosOfStable); + // taos_close(taos); + return 0; +} \ No newline at end of file diff --git a/src/kit/taosdemo/src/demoUtil.c b/src/kit/taosdemo/src/demoUtil.c new file mode 100644 index 0000000000000000000000000000000000000000..bae2e30f53db95df6024eee4f7c48d601b5240e3 --- /dev/null +++ b/src/kit/taosdemo/src/demoUtil.c @@ -0,0 +1,594 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#include "demo.h" + +void errorWrongValue(char *program, char *wrong_arg, char *wrong_value) { + fprintf(stderr, "%s %s: %s is an invalid value\n", program, wrong_arg, + wrong_value); + fprintf( + stderr, + "Try `taosdemo --help' or `taosdemo --usage' for more information.\n"); +} + +void errorUnrecognized(char *program, char *wrong_arg) { + fprintf(stderr, "%s: unrecognized options '%s'\n", program, wrong_arg); + fprintf( + stderr, + "Try `taosdemo --help' or `taosdemo --usage' for more information.\n"); +} + +void errorPrintReqArg(char *program, char *wrong_arg) { + fprintf(stderr, "%s: option requires an argument -- '%s'\n", program, + wrong_arg); + fprintf( + stderr, + "Try `taosdemo --help' or `taosdemo --usage' for more information.\n"); +} + +void errorPrintReqArg2(char *program, char *wrong_arg) { + fprintf(stderr, "%s: option requires a number argument '-%s'\n", program, + wrong_arg); + fprintf( + stderr, + "Try `taosdemo --help' or `taosdemo --usage' for more information.\n"); +} + +void errorPrintReqArg3(char *program, char *wrong_arg) { + fprintf(stderr, "%s: option '%s' requires an argument\n", program, + wrong_arg); + fprintf( + stderr, + "Try `taosdemo --help' or `taosdemo --usage' for more information.\n"); +} + +void tmfclose(FILE *fp) { + if (NULL != fp) { + fclose(fp); + } +} + +void tmfree(void *buf) { + if (NULL != buf) { + free(buf); + buf = NULL; + } +} + +void ERROR_EXIT(const char *msg) { + errorPrint("%s", msg); + exit(EXIT_FAILURE); +} + +#ifdef WINDOWS +#define _CRT_RAND_S +#include +#include + +typedef unsigned __int32 uint32_t; + +#pragma comment(lib, "ws2_32.lib") +// Some old MinGW/CYGWIN distributions don't define this: +#ifndef ENABLE_VIRTUAL_TERMINAL_PROCESSING +#define ENABLE_VIRTUAL_TERMINAL_PROCESSING 0x0004 +#endif // ENABLE_VIRTUAL_TERMINAL_PROCESSING + +HANDLE g_stdoutHandle; +DWORD g_consoleMode; + +void setupForAnsiEscape(void) { + DWORD mode = 0; + g_stdoutHandle = GetStdHandle(STD_OUTPUT_HANDLE); + + if (g_stdoutHandle == INVALID_HANDLE_VALUE) { + exit(GetLastError()); + } + + if (!GetConsoleMode(g_stdoutHandle, &mode)) { + exit(GetLastError()); + } + + g_consoleMode = mode; + + // Enable ANSI escape codes + mode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING; + + if (!SetConsoleMode(g_stdoutHandle, mode)) { + exit(GetLastError()); + } +} + +void resetAfterAnsiEscape(void) { + // Reset colors + printf("\x1b[0m"); + + // Reset console mode + if (!SetConsoleMode(g_stdoutHandle, g_consoleMode)) { + exit(GetLastError()); + } +} + +int taosRandom() { + int number; + rand_s(&number); + + return number; +} +#else // Not windows +void setupForAnsiEscape(void) {} + +void resetAfterAnsiEscape(void) { + // Reset colors + printf("\x1b[0m"); +} + +#include + +int taosRandom() { return rand(); } + +#endif + +bool isStringNumber(char *input) { + int len = (int)strlen(input); + if (0 == len) { + return false; + } + + for (int i = 0; i < len; i++) { + if (!isdigit(input[i])) return false; + } + + return true; +} + +char *formatTimestamp(char *buf, int64_t val, int precision) { + time_t tt; + if (precision == TSDB_TIME_PRECISION_MICRO) { + tt = (time_t)(val / 1000000); + } + if (precision == TSDB_TIME_PRECISION_NANO) { + tt = (time_t)(val / 1000000000); + } else { + tt = (time_t)(val / 1000); + } + + /* comment out as it make testcases like select_with_tags.sim fail. + but in windows, this may cause the call to localtime crash if tt < 0, + need to find a better solution. + if (tt < 0) { + tt = 0; + } + */ + +#ifdef WINDOWS + if (tt < 0) tt = 0; +#endif + + struct tm *ptm = localtime(&tt); + size_t pos = strftime(buf, 32, "%Y-%m-%d %H:%M:%S", ptm); + + if (precision == TSDB_TIME_PRECISION_MICRO) { + sprintf(buf + pos, ".%06d", (int)(val % 1000000)); + } else if (precision == TSDB_TIME_PRECISION_NANO) { + sprintf(buf + pos, ".%09d", (int)(val % 1000000000)); + } else { + sprintf(buf + pos, ".%03d", (int)(val % 1000)); + } + + return buf; +} + +int getChildNameOfSuperTableWithLimitAndOffset(TAOS *taos, char *dbName, + char * stbName, + char ** childTblNameOfSuperTbl, + int64_t *childTblCountOfSuperTbl, + int64_t limit, uint64_t offset, + bool escapChar) { + char command[SQL_BUFF_LEN] = "\0"; + char limitBuf[100] = "\0"; + + TAOS_RES *res; + TAOS_ROW row = NULL; + int64_t childTblCount = (limit < 0) ? DEFAULT_CHILDTABLES : limit; + int64_t count = 0; + char * childTblName = *childTblNameOfSuperTbl; + + if (childTblName == NULL) { + childTblName = (char *)calloc(1, childTblCount * TSDB_TABLE_NAME_LEN); + if (childTblName == NULL) { + errorPrint("%s", "failed to allocate memory\n"); + } + } + char *pTblName = childTblName; + + snprintf(limitBuf, 100, " limit %" PRId64 " offset %" PRIu64 "", limit, + offset); + + // get all child table name use cmd: select tbname from superTblName; + snprintf(command, SQL_BUFF_LEN, + escapChar ? "select tbname from %s.`%s` %s" + : "select tbname from %s.%s %s", + dbName, stbName, limitBuf); + + res = taos_query(taos, command); + int32_t code = taos_errno(res); + if (code != 0) { + taos_free_result(res); + taos_close(taos); + errorPrint("failed to run command %s, reason: %s\n", command, + taos_errstr(res)); + exit(EXIT_FAILURE); + } + + while ((row = taos_fetch_row(res)) != NULL) { + int32_t *len = taos_fetch_lengths(res); + + if (0 == strlen((char *)row[0])) { + errorPrint("No.%" PRId64 " table return empty name\n", count); + exit(EXIT_FAILURE); + } + + tstrncpy(pTblName, (char *)row[0], len[0] + 1); + // printf("==== sub table name: %s\n", pTblName); + count++; + if (count >= childTblCount - 1) { + char *tmp = realloc( + childTblName, + (size_t)(childTblCount * 1.5 * TSDB_TABLE_NAME_LEN + 1)); + if (tmp != NULL) { + childTblName = tmp; + childTblCount = (int)(childTblCount * 1.5); + memset(childTblName + count * TSDB_TABLE_NAME_LEN, 0, + (size_t)((childTblCount - count) * TSDB_TABLE_NAME_LEN)); + } else { + // exit, if allocate more memory failed + tmfree(childTblName); + taos_free_result(res); + taos_close(taos); + errorPrint( + "%s() LN%d, realloc fail for save child table name of " + "%s.%s\n", + __func__, __LINE__, dbName, stbName); + exit(EXIT_FAILURE); + } + } + pTblName = childTblName + count * TSDB_TABLE_NAME_LEN; + } + + *childTblCountOfSuperTbl = count; + *childTblNameOfSuperTbl = childTblName; + + taos_free_result(res); + return 0; +} + +int getAllChildNameOfSuperTable(TAOS *taos, char *dbName, char *stbName, + char ** childTblNameOfSuperTbl, + int64_t *childTblCountOfSuperTbl) { + return getChildNameOfSuperTableWithLimitAndOffset( + taos, dbName, stbName, childTblNameOfSuperTbl, childTblCountOfSuperTbl, + -1, 0, false); +} + +int convertHostToServAddr(char *host, uint16_t port, + struct sockaddr_in *serv_addr) { + uint16_t rest_port = port + TSDB_PORT_HTTP; + struct hostent *server = gethostbyname(host); + if ((server == NULL) || (server->h_addr == NULL)) { + errorPrint("%s", "no such host"); + return -1; + } + + debugPrint("h_name: %s\nh_addr=%p\nh_addretype: %s\nh_length: %d\n", + server->h_name, server->h_addr, + (server->h_addrtype == AF_INET) ? "ipv4" : "ipv6", + server->h_length); + + memset(serv_addr, 0, sizeof(struct sockaddr_in)); + serv_addr->sin_family = AF_INET; + serv_addr->sin_port = htons(rest_port); +#ifdef WINDOWS + serv_addr->sin_addr.s_addr = inet_addr(host); +#else + memcpy(&(serv_addr->sin_addr.s_addr), server->h_addr, server->h_length); +#endif + return 0; +} + +void prompt() { + if (!g_args.answer_yes) { + printf(" Press enter key to continue or Ctrl-C to stop\n\n"); + (void)getchar(); + } +} + +void replaceChildTblName(char *inSql, char *outSql, int tblIndex) { + char sourceString[32] = "xxxx"; + char subTblName[TSDB_TABLE_NAME_LEN]; + sprintf(subTblName, "%s.%s", g_queryInfo.dbName, + g_queryInfo.superQueryInfo.childTblName + + tblIndex * TSDB_TABLE_NAME_LEN); + + // printf("inSql: %s\n", inSql); + + char *pos = strstr(inSql, sourceString); + if (0 == pos) { + return; + } + + tstrncpy(outSql, inSql, pos - inSql + 1); + // printf("1: %s\n", outSql); + strncat(outSql, subTblName, BUFFER_SIZE - 1); + // printf("2: %s\n", outSql); + strncat(outSql, pos + strlen(sourceString), BUFFER_SIZE - 1); + // printf("3: %s\n", outSql); +} + +int isCommentLine(char *line) { + if (line == NULL) return 1; + + return regexMatch(line, "^\\s*#.*", REG_EXTENDED); +} + +int regexMatch(const char *s, const char *reg, int cflags) { + regex_t regex; + char msgbuf[100] = {0}; + + /* Compile regular expression */ + if (regcomp(®ex, reg, cflags) != 0) { + ERROR_EXIT("Fail to compile regex\n"); + } + + /* Execute regular expression */ + int reti = regexec(®ex, s, 0, NULL, 0); + if (!reti) { + regfree(®ex); + return 1; + } else if (reti == REG_NOMATCH) { + regfree(®ex); + return 0; + } else { + regerror(reti, ®ex, msgbuf, sizeof(msgbuf)); + regfree(®ex); + printf("Regex match failed: %s\n", msgbuf); + exit(EXIT_FAILURE); + } + return 0; +} + +int queryDbExec(TAOS *taos, char *command, QUERY_TYPE type, bool quiet) { + verbosePrint("%s() LN%d - command: %s\n", __func__, __LINE__, command); + + TAOS_RES *res = taos_query(taos, command); + int32_t code = taos_errno(res); + + if (code != 0) { + if (!quiet) { + errorPrint("Failed to execute <%s>, reason: %s\n", command, + taos_errstr(res)); + } + taos_free_result(res); + // taos_close(taos); + return -1; + } + + if (INSERT_TYPE == type) { + int affectedRows = taos_affected_rows(res); + taos_free_result(res); + return affectedRows; + } + + taos_free_result(res); + return 0; +} + +int postProceSql(char *host, uint16_t port, char *sqlstr, + threadInfo *pThreadInfo) { + char *req_fmt = + "POST %s HTTP/1.1\r\nHost: %s:%d\r\nAccept: */*\r\nAuthorization: " + "Basic %s\r\nContent-Length: %d\r\nContent-Type: " + "application/x-www-form-urlencoded\r\n\r\n%s"; + + char *url = "/rest/sql"; + + int bytes, sent, received, req_str_len, resp_len; + char * request_buf; + char response_buf[RESP_BUF_LEN]; + uint16_t rest_port = port + TSDB_PORT_HTTP; + + int req_buf_len = (int)strlen(sqlstr) + REQ_EXTRA_BUF_LEN; + + request_buf = malloc(req_buf_len); + if (NULL == request_buf) { + errorPrint("%s", "cannot allocate memory.\n"); + exit(EXIT_FAILURE); + } + + char userpass_buf[INPUT_BUF_LEN]; + int mod_table[] = {0, 2, 1}; + + static char base64[] = { + 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', + 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', + 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', + 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', + '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/'}; + + if (g_args.test_mode == INSERT_TEST) { + snprintf(userpass_buf, INPUT_BUF_LEN, "%s:%s", g_Dbs.user, + g_Dbs.password); + } else { + snprintf(userpass_buf, INPUT_BUF_LEN, "%s:%s", g_queryInfo.user, + g_queryInfo.password); + } + + size_t userpass_buf_len = strlen(userpass_buf); + size_t encoded_len = 4 * ((userpass_buf_len + 2) / 3); + + char base64_buf[INPUT_BUF_LEN]; + + memset(base64_buf, 0, INPUT_BUF_LEN); + + for (int n = 0, m = 0; n < userpass_buf_len;) { + uint32_t oct_a = + n < userpass_buf_len ? (unsigned char)userpass_buf[n++] : 0; + uint32_t oct_b = + n < userpass_buf_len ? (unsigned char)userpass_buf[n++] : 0; + uint32_t oct_c = + n < userpass_buf_len ? (unsigned char)userpass_buf[n++] : 0; + uint32_t triple = (oct_a << 0x10) + (oct_b << 0x08) + oct_c; + + base64_buf[m++] = base64[(triple >> 3 * 6) & 0x3f]; + base64_buf[m++] = base64[(triple >> 2 * 6) & 0x3f]; + base64_buf[m++] = base64[(triple >> 1 * 6) & 0x3f]; + base64_buf[m++] = base64[(triple >> 0 * 6) & 0x3f]; + } + + for (int l = 0; l < mod_table[userpass_buf_len % 3]; l++) + base64_buf[encoded_len - 1 - l] = '='; + + debugPrint("%s() LN%d: auth string base64 encoded: %s\n", __func__, + __LINE__, base64_buf); + char *auth = base64_buf; + + int r = snprintf(request_buf, req_buf_len, req_fmt, url, host, rest_port, + auth, strlen(sqlstr), sqlstr); + if (r >= req_buf_len) { + free(request_buf); + ERROR_EXIT("too long request"); + } + verbosePrint("%s() LN%d: Request:\n%s\n", __func__, __LINE__, request_buf); + + req_str_len = (int)strlen(request_buf); + sent = 0; + do { +#ifdef WINDOWS + bytes = send(pThreadInfo->sockfd, request_buf + sent, + req_str_len - sent, 0); +#else + bytes = + write(pThreadInfo->sockfd, request_buf + sent, req_str_len - sent); +#endif + if (bytes < 0) ERROR_EXIT("writing message to socket"); + if (bytes == 0) break; + sent += bytes; + } while (sent < req_str_len); + + memset(response_buf, 0, RESP_BUF_LEN); + resp_len = sizeof(response_buf) - 1; + received = 0; + + char resEncodingChunk[] = "Encoding: chunked"; + char resHttp[] = "HTTP/1.1 "; + char resHttpOk[] = "HTTP/1.1 200 OK"; + + do { +#ifdef WINDOWS + bytes = recv(pThreadInfo->sockfd, response_buf + received, + resp_len - received, 0); +#else + bytes = read(pThreadInfo->sockfd, response_buf + received, + resp_len - received); +#endif + verbosePrint("%s() LN%d: bytes:%d\n", __func__, __LINE__, bytes); + if (bytes < 0) { + free(request_buf); + ERROR_EXIT("reading response from socket"); + } + if (bytes == 0) break; + received += bytes; + + verbosePrint("%s() LN%d: received:%d resp_len:%d, response_buf:\n%s\n", + __func__, __LINE__, received, resp_len, response_buf); + + response_buf[RESP_BUF_LEN - 1] = '\0'; + if (strlen(response_buf)) { + verbosePrint( + "%s() LN%d: received:%d resp_len:%d, response_buf:\n%s\n", + __func__, __LINE__, received, resp_len, response_buf); + + if (((NULL != strstr(response_buf, resEncodingChunk)) && + (NULL != strstr(response_buf, resHttp))) || + ((NULL != strstr(response_buf, resHttpOk)) && + (NULL != strstr(response_buf, "\"status\":")))) { + debugPrint( + "%s() LN%d: received:%d resp_len:%d, response_buf:\n%s\n", + __func__, __LINE__, received, resp_len, response_buf); + break; + } + } + } while (received < resp_len); + + if (received == resp_len) { + free(request_buf); + ERROR_EXIT("storing complete response from socket"); + } + + if (strlen(pThreadInfo->filePath) > 0) { + appendResultBufToFile(response_buf, pThreadInfo); + } + + free(request_buf); + + if (NULL == strstr(response_buf, resHttpOk)) { + errorPrint("Response:\n%s\n", response_buf); + return -1; + } + return 0; +} + +void fetchResult(TAOS_RES *res, threadInfo *pThreadInfo) { + TAOS_ROW row = NULL; + int num_rows = 0; + int num_fields = taos_field_count(res); + TAOS_FIELD *fields = taos_fetch_fields(res); + + char *databuf = (char *)calloc(1, FETCH_BUFFER_SIZE); + if (databuf == NULL) { + errorPrint( + "%s() LN%d, failed to malloc, warning: save result to file " + "slowly!\n", + __func__, __LINE__); + return; + } + + int64_t totalLen = 0; + + // fetch the records row by row + while ((row = taos_fetch_row(res))) { + if (totalLen >= (FETCH_BUFFER_SIZE - HEAD_BUFF_LEN * 2)) { + if (strlen(pThreadInfo->filePath) > 0) + appendResultBufToFile(databuf, pThreadInfo); + totalLen = 0; + memset(databuf, 0, FETCH_BUFFER_SIZE); + } + num_rows++; + char temp[HEAD_BUFF_LEN] = {0}; + int len = taos_print_row(temp, row, fields, num_fields); + len += sprintf(temp + len, "\n"); + // printf("query result:%s\n", temp); + memcpy(databuf + totalLen, temp, len); + totalLen += len; + verbosePrint("%s() LN%d, totalLen: %" PRId64 "\n", __func__, __LINE__, + totalLen); + } + + verbosePrint("%s() LN%d, databuf=%s resultFile=%s\n", __func__, __LINE__, + databuf, pThreadInfo->filePath); + if (strlen(pThreadInfo->filePath) > 0) { + appendResultBufToFile(databuf, pThreadInfo); + } + free(databuf); +} \ No newline at end of file diff --git a/src/kit/taosdemo/taosdemo.c b/src/kit/taosdemo/taosdemo.c deleted file mode 100644 index c2b8479f19d778f030101a8d9fb5ac537ca0475c..0000000000000000000000000000000000000000 --- a/src/kit/taosdemo/taosdemo.c +++ /dev/null @@ -1,12940 +0,0 @@ -/* - * Copyright (c) 2019 TAOS Data, Inc. - * - * This program is free software: you can use, redistribute, and/or modify - * it under the terms of the GNU Affero General Public License, version 3 - * or later ("AGPL"), as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - - -/* - when in some thread query return error, thread don't exit, but return, otherwise coredump in other thread. - */ - -#include -#include -#include -#define _GNU_SOURCE -#define CURL_STATICLIB - -#ifdef LINUX -#include -#include -#ifndef _ALPINE -#include -#endif -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#else -#include -#include -#endif - -#include -#include -#include "cJSON.h" - -#include "os.h" -#include "taos.h" -#include "taoserror.h" -#include "tutil.h" - -#define REQ_EXTRA_BUF_LEN 1024 -#define RESP_BUF_LEN 4096 -#define SQL_BUFF_LEN 1024 - -extern char configDir[]; - -#define STR_INSERT_INTO "INSERT INTO " - -#define MAX_RECORDS_PER_REQ 32766 - -#define HEAD_BUFF_LEN TSDB_MAX_COLUMNS*24 // 16*MAX_COLUMNS + (192+32)*2 + insert into .. - -#define BUFFER_SIZE TSDB_MAX_ALLOWED_SQL_LEN -#define FETCH_BUFFER_SIZE 100 * TSDB_MAX_ALLOWED_SQL_LEN -#define COND_BUF_LEN (BUFFER_SIZE - 30) -#define COL_BUFFER_LEN ((TSDB_COL_NAME_LEN + 15) * TSDB_MAX_COLUMNS) - -#define MAX_USERNAME_SIZE 64 -#define MAX_HOSTNAME_SIZE 253 // https://man7.org/linux/man-pages/man7/hostname.7.html -#define MAX_TB_NAME_SIZE 64 -#define MAX_DATA_SIZE (16*TSDB_MAX_COLUMNS)+20 // max record len: 16*MAX_COLUMNS, timestamp string and ,('') need extra space -#define OPT_ABORT 1 /* –abort */ -#define MAX_FILE_NAME_LEN 256 // max file name length on linux is 255. -#define MAX_PATH_LEN 4096 - -#define DEFAULT_START_TIME 1500000000000 - -#define MAX_PREPARED_RAND 1000000 -#define INT_BUFF_LEN 12 -#define BIGINT_BUFF_LEN 21 -#define SMALLINT_BUFF_LEN 7 -#define TINYINT_BUFF_LEN 5 -#define BOOL_BUFF_LEN 6 -#define FLOAT_BUFF_LEN 22 -#define DOUBLE_BUFF_LEN 42 -#define TIMESTAMP_BUFF_LEN 21 -#define PRINT_STAT_INTERVAL 30*1000 - -#define MAX_SAMPLES 10000 -#define MAX_NUM_COLUMNS (TSDB_MAX_COLUMNS - 1) // exclude first column timestamp - -#define MAX_DB_COUNT 8 -#define MAX_SUPER_TABLE_COUNT 200 - -#define MAX_QUERY_SQL_COUNT 100 - -#define MAX_DATABASE_COUNT 256 -#define MAX_JSON_BUFF 6400000 - -#define INPUT_BUF_LEN 256 -#define EXTRA_SQL_LEN 256 -#define TBNAME_PREFIX_LEN (TSDB_TABLE_NAME_LEN - 20) // 20 characters reserved for seq -#define SMALL_BUFF_LEN 8 -#define DATATYPE_BUFF_LEN (SMALL_BUFF_LEN*3) -#define NOTE_BUFF_LEN (SMALL_BUFF_LEN*16) - -#define DEFAULT_NTHREADS 8 -#define DEFAULT_TIMESTAMP_STEP 1 -#define DEFAULT_INTERLACE_ROWS 0 -#define DEFAULT_DATATYPE_NUM 1 -#define DEFAULT_CHILDTABLES 10000 -#define DEFAULT_TEST_MODE 0 -#define DEFAULT_METAFILE NULL -#define DEFAULT_SQLFILE NULL -#define DEFAULT_HOST "localhost" -#define DEFAULT_PORT 6030 -#define DEFAULT_IFACE INTERFACE_BUT -#define DEFAULT_DATABASE "test" -#define DEFAULT_REPLICA 1 -#define DEFAULT_TB_PREFIX "d" -#define DEFAULT_ESCAPE_CHAR false -#define DEFAULT_USE_METRIC true -#define DEFAULT_DROP_DB true -#define DEFAULT_AGGR_FUNC false -#define DEFAULT_DEBUG false -#define DEFAULT_VERBOSE false -#define DEFAULT_PERF_STAT false -#define DEFAULT_ANS_YES false -#define DEFAULT_OUTPUT "./output.txt" -#define DEFAULT_SYNC_MODE 0 -#define DEFAULT_DATA_TYPE {TSDB_DATA_TYPE_FLOAT,TSDB_DATA_TYPE_INT,TSDB_DATA_TYPE_FLOAT} -#define DEFAULT_DATATYPE {"FLOAT","INT","FLOAT"} -#define DEFAULT_BINWIDTH 64 -#define DEFAULT_COL_COUNT 4 -#define DEFAULT_LEN_ONE_ROW 76 -#define DEFAULT_INSERT_INTERVAL 0 -#define DEFAULT_QUERY_TIME 1 -#define DEFAULT_PREPARED_RAND 10000 -#define DEFAULT_REQ_PER_REQ 30000 -#define DEFAULT_INSERT_ROWS 10000 -#define DEFAULT_ABORT 0 -#define DEFAULT_RATIO 0 -#define DEFAULT_DISORDER_RANGE 1000 -#define DEFAULT_METHOD_DEL 1 -#define DEFAULT_TOTAL_INSERT 0 -#define DEFAULT_TOTAL_AFFECT 0 -#define DEFAULT_DEMO_MODE true -#define DEFAULT_CREATE_BATCH 10 -#define DEFAULT_SUB_INTERVAL 10000 -#define DEFAULT_QUERY_INTERVAL 10000 - -#define STMT_BIND_PARAM_BATCH 1 - -char* g_sampleDataBuf = NULL; -#if STMT_BIND_PARAM_BATCH == 1 - // bind param batch -char* g_sampleBindBatchArray = NULL; -#endif - -enum TEST_MODE { - INSERT_TEST, // 0 - QUERY_TEST, // 1 - SUBSCRIBE_TEST, // 2 - INVAID_TEST -}; - -typedef enum CREATE_SUB_TABLE_MOD_EN { - PRE_CREATE_SUBTBL, - AUTO_CREATE_SUBTBL, - NO_CREATE_SUBTBL -} CREATE_SUB_TABLE_MOD_EN; - -typedef enum TABLE_EXISTS_EN { - TBL_NO_EXISTS, - TBL_ALREADY_EXISTS, - TBL_EXISTS_BUTT -} TABLE_EXISTS_EN; - -enum enumSYNC_MODE { - SYNC_MODE, - ASYNC_MODE, - MODE_BUT -}; - -enum enum_TAOS_INTERFACE { - TAOSC_IFACE, - REST_IFACE, - STMT_IFACE, - SML_IFACE, - INTERFACE_BUT -}; - -typedef enum enumQUERY_CLASS { - SPECIFIED_CLASS, - STABLE_CLASS, - CLASS_BUT -} QUERY_CLASS; - -typedef enum enum_PROGRESSIVE_OR_INTERLACE { - PROGRESSIVE_INSERT_MODE, - INTERLACE_INSERT_MODE, - INVALID_INSERT_MODE -} PROG_OR_INTERLACE_MODE; - -typedef enum enumQUERY_TYPE { - NO_INSERT_TYPE, - INSERT_TYPE, - QUERY_TYPE_BUT -} QUERY_TYPE; - -enum _show_db_index { - TSDB_SHOW_DB_NAME_INDEX, - TSDB_SHOW_DB_CREATED_TIME_INDEX, - TSDB_SHOW_DB_NTABLES_INDEX, - TSDB_SHOW_DB_VGROUPS_INDEX, - TSDB_SHOW_DB_REPLICA_INDEX, - TSDB_SHOW_DB_QUORUM_INDEX, - TSDB_SHOW_DB_DAYS_INDEX, - TSDB_SHOW_DB_KEEP_INDEX, - TSDB_SHOW_DB_CACHE_INDEX, - TSDB_SHOW_DB_BLOCKS_INDEX, - TSDB_SHOW_DB_MINROWS_INDEX, - TSDB_SHOW_DB_MAXROWS_INDEX, - TSDB_SHOW_DB_WALLEVEL_INDEX, - TSDB_SHOW_DB_FSYNC_INDEX, - TSDB_SHOW_DB_COMP_INDEX, - TSDB_SHOW_DB_CACHELAST_INDEX, - TSDB_SHOW_DB_PRECISION_INDEX, - TSDB_SHOW_DB_UPDATE_INDEX, - TSDB_SHOW_DB_STATUS_INDEX, - TSDB_MAX_SHOW_DB -}; - -// -----------------------------------------SHOW TABLES CONFIGURE ------------------------------------- -enum _show_stables_index { - TSDB_SHOW_STABLES_NAME_INDEX, - TSDB_SHOW_STABLES_CREATED_TIME_INDEX, - TSDB_SHOW_STABLES_COLUMNS_INDEX, - TSDB_SHOW_STABLES_METRIC_INDEX, - TSDB_SHOW_STABLES_UID_INDEX, - TSDB_SHOW_STABLES_TID_INDEX, - TSDB_SHOW_STABLES_VGID_INDEX, - TSDB_MAX_SHOW_STABLES -}; - -enum _describe_table_index { - TSDB_DESCRIBE_METRIC_FIELD_INDEX, - TSDB_DESCRIBE_METRIC_TYPE_INDEX, - TSDB_DESCRIBE_METRIC_LENGTH_INDEX, - TSDB_DESCRIBE_METRIC_NOTE_INDEX, - TSDB_MAX_DESCRIBE_METRIC -}; - -/* Used by main to communicate with parse_opt. */ -static char *g_dupstr = NULL; - -typedef struct SArguments_S { - char *metaFile; - uint32_t test_mode; - char *host; - uint16_t port; - uint16_t iface; - char * user; - char password[SHELL_MAX_PASSWORD_LEN]; - char * database; - int replica; - char * tb_prefix; - bool escapeChar; - char * sqlFile; - bool use_metric; - bool drop_database; - bool aggr_func; - bool answer_yes; - bool debug_print; - bool verbose_print; - bool performance_print; - char * output_file; - bool async_mode; - char data_type[MAX_NUM_COLUMNS+1]; - char *dataType[MAX_NUM_COLUMNS+1]; - uint32_t binwidth; - uint32_t columnCount; - uint64_t lenOfOneRow; - uint32_t nthreads; - uint64_t insert_interval; - uint64_t timestamp_step; - int64_t query_times; - int64_t prepared_rand; - uint32_t interlaceRows; - uint32_t reqPerReq; // num_of_records_per_req - uint64_t max_sql_len; - int64_t ntables; - int64_t insertRows; - int abort; - uint32_t disorderRatio; // 0: no disorder, >0: x% - int disorderRange; // ms, us or ns. according to database precision - uint32_t method_of_delete; - uint64_t totalInsertRows; - uint64_t totalAffectedRows; - bool demo_mode; // use default column name and semi-random data -} SArguments; - -typedef struct SColumn_S { - char field[TSDB_COL_NAME_LEN]; - char data_type; - char dataType[DATATYPE_BUFF_LEN]; - uint32_t dataLen; - char note[NOTE_BUFF_LEN]; -} StrColumn; - -typedef struct SSuperTable_S { - char stbName[TSDB_TABLE_NAME_LEN]; - char dataSource[SMALL_BUFF_LEN]; // rand_gen or sample - char childTblPrefix[TBNAME_PREFIX_LEN]; - uint16_t childTblExists; - int64_t childTblCount; - uint64_t batchCreateTableNum; // 0: no batch, > 0: batch table number in one sql - uint8_t autoCreateTable; // 0: create sub table, 1: auto create sub table - uint16_t iface; // 0: taosc, 1: rest, 2: stmt - int64_t childTblLimit; - uint64_t childTblOffset; - - // int multiThreadWriteOneTbl; // 0: no, 1: yes - uint32_t interlaceRows; // - int disorderRatio; // 0: no disorder, >0: x% - int disorderRange; // ms, us or ns. according to database precision - uint64_t maxSqlLen; // - - uint64_t insertInterval; // insert interval, will override global insert interval - int64_t insertRows; - int64_t timeStampStep; - char startTimestamp[MAX_TB_NAME_SIZE]; - char sampleFormat[SMALL_BUFF_LEN]; // csv, json - char sampleFile[MAX_FILE_NAME_LEN]; - char tagsFile[MAX_FILE_NAME_LEN]; - - uint32_t columnCount; - StrColumn columns[TSDB_MAX_COLUMNS]; - uint32_t tagCount; - StrColumn tags[TSDB_MAX_TAGS]; - - char* childTblName; - bool escapeChar; - char* colsOfCreateChildTable; - uint64_t lenOfOneRow; - uint64_t lenOfTagOfOneRow; - - char* sampleDataBuf; - bool useSampleTs; - - uint32_t tagSource; // 0: rand, 1: tag sample - char* tagDataBuf; - uint32_t tagSampleCount; - uint32_t tagUsePos; - -#if STMT_BIND_PARAM_BATCH == 1 - // bind param batch - char *sampleBindBatchArray; -#endif - // statistics - uint64_t totalInsertRows; - uint64_t totalAffectedRows; -} SSuperTable; - -typedef struct { - char name[TSDB_DB_NAME_LEN]; - char create_time[32]; - int64_t ntables; - int32_t vgroups; - int16_t replica; - int16_t quorum; - int16_t days; - char keeplist[64]; - int32_t cache; //MB - int32_t blocks; - int32_t minrows; - int32_t maxrows; - int8_t wallevel; - int32_t fsync; - int8_t comp; - int8_t cachelast; - char precision[SMALL_BUFF_LEN]; // time resolution - int8_t update; - char status[16]; -} SDbInfo; - -typedef struct SDbCfg_S { - // int maxtablesPerVnode; - uint32_t minRows; // 0 means default - uint32_t maxRows; // 0 means default - int comp; - int walLevel; - int cacheLast; - int fsync; - int replica; - int update; - int keep; - int days; - int cache; - int blocks; - int quorum; - char precision[SMALL_BUFF_LEN]; -} SDbCfg; - -typedef struct SDataBase_S { - char dbName[TSDB_DB_NAME_LEN]; - bool drop; // 0: use exists, 1: if exists, drop then new create - SDbCfg dbCfg; - uint64_t superTblCount; - SSuperTable* superTbls; -} SDataBase; - -typedef struct SDbs_S { - char cfgDir[MAX_FILE_NAME_LEN]; - char host[MAX_HOSTNAME_SIZE]; - struct sockaddr_in serv_addr; - - uint16_t port; - char user[MAX_USERNAME_SIZE]; - char password[SHELL_MAX_PASSWORD_LEN]; - char resultFile[MAX_FILE_NAME_LEN]; - bool use_metric; - bool aggr_func; - bool asyncMode; - - uint32_t threadCount; - uint32_t threadCountForCreateTbl; - uint32_t dbCount; - // statistics - uint64_t totalInsertRows; - uint64_t totalAffectedRows; - - SDataBase* db; -} SDbs; - -typedef struct SpecifiedQueryInfo_S { - uint64_t queryInterval; // 0: unlimited > 0 loop/s - uint32_t concurrent; - int sqlCount; - uint32_t asyncMode; // 0: sync, 1: async - uint64_t subscribeInterval; // ms - uint64_t queryTimes; - bool subscribeRestart; - int subscribeKeepProgress; - char sql[MAX_QUERY_SQL_COUNT][BUFFER_SIZE+1]; - char result[MAX_QUERY_SQL_COUNT][MAX_FILE_NAME_LEN]; - int resubAfterConsume[MAX_QUERY_SQL_COUNT]; - int endAfterConsume[MAX_QUERY_SQL_COUNT]; - TAOS_SUB* tsub[MAX_QUERY_SQL_COUNT]; - char topic[MAX_QUERY_SQL_COUNT][32]; - int consumed[MAX_QUERY_SQL_COUNT]; - TAOS_RES* res[MAX_QUERY_SQL_COUNT]; - uint64_t totalQueried; -} SpecifiedQueryInfo; - -typedef struct SuperQueryInfo_S { - char stbName[TSDB_TABLE_NAME_LEN]; - uint64_t queryInterval; // 0: unlimited > 0 loop/s - uint32_t threadCnt; - uint32_t asyncMode; // 0: sync, 1: async - uint64_t subscribeInterval; // ms - bool subscribeRestart; - int subscribeKeepProgress; - uint64_t queryTimes; - int64_t childTblCount; - char childTblPrefix[TBNAME_PREFIX_LEN]; // 20 characters reserved for seq - int sqlCount; - char sql[MAX_QUERY_SQL_COUNT][BUFFER_SIZE+1]; - char result[MAX_QUERY_SQL_COUNT][MAX_FILE_NAME_LEN]; - int resubAfterConsume; - int endAfterConsume; - TAOS_SUB* tsub[MAX_QUERY_SQL_COUNT]; - - char* childTblName; - uint64_t totalQueried; -} SuperQueryInfo; - -typedef struct SQueryMetaInfo_S { - char cfgDir[MAX_FILE_NAME_LEN]; - char host[MAX_HOSTNAME_SIZE]; - uint16_t port; - struct sockaddr_in serv_addr; - char user[MAX_USERNAME_SIZE]; - char password[SHELL_MAX_PASSWORD_LEN]; - char dbName[TSDB_DB_NAME_LEN]; - char queryMode[SMALL_BUFF_LEN]; // taosc, rest - - SpecifiedQueryInfo specifiedQueryInfo; - SuperQueryInfo superQueryInfo; - uint64_t totalQueried; -} SQueryMetaInfo; - -typedef struct SThreadInfo_S { - TAOS * taos; - TAOS_STMT *stmt; - int64_t *bind_ts; - -#if STMT_BIND_PARAM_BATCH == 1 - int64_t *bind_ts_array; - char *bindParams; - char *is_null; -#else - char* sampleBindArray; -#endif - - int threadID; - char db_name[TSDB_DB_NAME_LEN]; - uint32_t time_precision; - char filePath[MAX_PATH_LEN]; - FILE *fp; - char tb_prefix[TSDB_TABLE_NAME_LEN]; - uint64_t start_table_from; - uint64_t end_table_to; - int64_t ntables; - int64_t tables_created; - uint64_t data_of_rate; - int64_t start_time; - char* cols; - bool use_metric; - SSuperTable* stbInfo; - char *buffer; // sql cmd buffer - - // for async insert - tsem_t lock_sem; - int64_t counter; - uint64_t st; - uint64_t et; - uint64_t lastTs; - - // sample data - int64_t samplePos; - // statistics - uint64_t totalInsertRows; - uint64_t totalAffectedRows; - - // insert delay statistics - uint64_t cntDelay; - uint64_t totalDelay; - uint64_t avgDelay; - uint64_t maxDelay; - uint64_t minDelay; - - // seq of query or subscribe - uint64_t querySeq; // sequence number of sql command - TAOS_SUB* tsub; - - char** lines; - int sockfd; -} threadInfo; - -#ifdef WINDOWS -#define _CRT_RAND_S - -#include -#include - -typedef unsigned __int32 uint32_t; - -#pragma comment ( lib, "ws2_32.lib" ) -// Some old MinGW/CYGWIN distributions don't define this: -#ifndef ENABLE_VIRTUAL_TERMINAL_PROCESSING -#define ENABLE_VIRTUAL_TERMINAL_PROCESSING 0x0004 -#endif // ENABLE_VIRTUAL_TERMINAL_PROCESSING - -static HANDLE g_stdoutHandle; -static DWORD g_consoleMode; - -static void setupForAnsiEscape(void) { - DWORD mode = 0; - g_stdoutHandle = GetStdHandle(STD_OUTPUT_HANDLE); - - if(g_stdoutHandle == INVALID_HANDLE_VALUE) { - exit(GetLastError()); - } - - if(!GetConsoleMode(g_stdoutHandle, &mode)) { - exit(GetLastError()); - } - - g_consoleMode = mode; - - // Enable ANSI escape codes - mode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING; - - if(!SetConsoleMode(g_stdoutHandle, mode)) { - exit(GetLastError()); - } -} - -static void resetAfterAnsiEscape(void) { - // Reset colors - printf("\x1b[0m"); - - // Reset console mode - if(!SetConsoleMode(g_stdoutHandle, g_consoleMode)) { - exit(GetLastError()); - } -} - -static int taosRandom() -{ - int number; - rand_s(&number); - - return number; -} -#else // Not windows -static void setupForAnsiEscape(void) {} - -static void resetAfterAnsiEscape(void) { - // Reset colors - printf("\x1b[0m"); -} - -#include - -static int taosRandom() -{ - return rand(); -} - -#endif // ifdef Windows - -static void prompt(); -static int createDatabasesAndStables(); -static void createChildTables(); -static int queryDbExec(TAOS *taos, char *command, QUERY_TYPE type, bool quiet); -static int postProceSql(char *host, uint16_t port, char* sqlstr, threadInfo *pThreadInfo); -static int64_t getTSRandTail(int64_t timeStampStep, int32_t seq, - int disorderRatio, int disorderRange); -static bool getInfoFromJsonFile(char* file); -static void init_rand_data(); -static int regexMatch(const char *s, const char *reg, int cflags); - -/* ************ Global variables ************ */ - -int32_t* g_randint; -uint32_t* g_randuint; -int64_t* g_randbigint; -uint64_t* g_randubigint; -float* g_randfloat; -double* g_randdouble; - -char *g_randbool_buff = NULL; -char *g_randint_buff = NULL; -char *g_randuint_buff = NULL; -char *g_rand_voltage_buff = NULL; -char *g_randbigint_buff = NULL; -char *g_randubigint_buff = NULL; -char *g_randsmallint_buff = NULL; -char *g_randusmallint_buff = NULL; -char *g_randtinyint_buff = NULL; -char *g_randutinyint_buff = NULL; -char *g_randfloat_buff = NULL; -char *g_rand_current_buff = NULL; -char *g_rand_phase_buff = NULL; -char *g_randdouble_buff = NULL; - -char *g_aggreFuncDemo[] = {"*", "count(*)", "avg(current)", "sum(current)", - "max(current)", "min(current)", "first(current)", "last(current)"}; - -char *g_aggreFunc[] = {"*", "count(*)", "avg(C0)", "sum(C0)", - "max(C0)", "min(C0)", "first(C0)", "last(C0)"}; - -SArguments g_args = { - DEFAULT_METAFILE, // metaFile - DEFAULT_TEST_MODE, // test_mode - DEFAULT_HOST, // host - DEFAULT_PORT, // port - DEFAULT_IFACE, // iface - TSDB_DEFAULT_USER, // user - TSDB_DEFAULT_PASS, // password - DEFAULT_DATABASE, // database - DEFAULT_REPLICA, // replica - DEFAULT_TB_PREFIX, // tb_prefix - DEFAULT_ESCAPE_CHAR, // escapeChar - DEFAULT_SQLFILE, // sqlFile - DEFAULT_USE_METRIC, // use_metric - DEFAULT_DROP_DB, // drop_database - DEFAULT_AGGR_FUNC, // aggr_func - DEFAULT_DEBUG, // debug_print - DEFAULT_VERBOSE, // verbose_print - DEFAULT_PERF_STAT, // performance statistic print - DEFAULT_ANS_YES, // answer_yes; - DEFAULT_OUTPUT, // output_file - DEFAULT_SYNC_MODE, // mode : sync or async - DEFAULT_DATA_TYPE, // data_type - DEFAULT_DATATYPE, // dataType - DEFAULT_BINWIDTH, // binwidth - DEFAULT_COL_COUNT, // columnCount, timestamp + float + int + float - DEFAULT_LEN_ONE_ROW, // lenOfOneRow - DEFAULT_NTHREADS, // nthreads - DEFAULT_INSERT_INTERVAL, // insert_interval - DEFAULT_TIMESTAMP_STEP, // timestamp_step - DEFAULT_QUERY_TIME, // query_times - DEFAULT_PREPARED_RAND, // prepared_rand - DEFAULT_INTERLACE_ROWS, // interlaceRows; - DEFAULT_REQ_PER_REQ, // reqPerReq - TSDB_MAX_ALLOWED_SQL_LEN, // max_sql_len - DEFAULT_CHILDTABLES, // ntables - DEFAULT_INSERT_ROWS, // insertRows - DEFAULT_ABORT, // abort - DEFAULT_RATIO, // disorderRatio - DEFAULT_DISORDER_RANGE, // disorderRange - DEFAULT_METHOD_DEL, // method_of_delete - DEFAULT_TOTAL_INSERT, // totalInsertRows; - DEFAULT_TOTAL_AFFECT, // totalAffectedRows; - DEFAULT_DEMO_MODE, // demo_mode; -}; - -static SDbs g_Dbs; -static int64_t g_totalChildTables = DEFAULT_CHILDTABLES; -static int64_t g_actualChildTables = 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) - -#define verbosePrint(fmt, ...) \ - do { if (g_args.verbose_print) \ - fprintf(stderr, "VERB: "fmt, __VA_ARGS__); } while(0) - -#define performancePrint(fmt, ...) \ - do { if (g_args.performance_print) \ - fprintf(stderr, "PERF: "fmt, __VA_ARGS__); } while(0) - -#define errorPrint(fmt, ...) \ - do {\ - fprintf(stderr, " \033[31m");\ - fprintf(stderr, "ERROR: "fmt, __VA_ARGS__);\ - fprintf(stderr, " \033[0m");\ - } while(0) - -#define errorPrint2(fmt, ...) \ - do {\ - struct tm Tm, *ptm;\ - struct timeval timeSecs; \ - time_t curTime;\ - gettimeofday(&timeSecs, NULL); \ - curTime = timeSecs.tv_sec;\ - ptm = localtime_r(&curTime, &Tm);\ - fprintf(stderr, " \033[31m");\ - fprintf(stderr, "%02d/%02d %02d:%02d:%02d.%06d %08" PRId64 " ",\ - ptm->tm_mon + 1, ptm->tm_mday, ptm->tm_hour,\ - ptm->tm_min, ptm->tm_sec, (int32_t)timeSecs.tv_usec,\ - taosGetSelfPthreadId());\ - fprintf(stderr, " \033[0m");\ - errorPrint(fmt, __VA_ARGS__);\ - } while(0) - -// for strncpy buffer overflow -#define min(a, b) (((a) < (b)) ? (a) : (b)) - - -/////////////////////////////////////////////////// - -static void ERROR_EXIT(const char *msg) { errorPrint("%s", msg); exit(EXIT_FAILURE); } - -#ifndef TAOSDEMO_COMMIT_SHA1 -#define TAOSDEMO_COMMIT_SHA1 "unknown" -#endif - -#ifndef TD_VERNUMBER -#define TD_VERNUMBER "unknown" -#endif - -#ifndef TAOSDEMO_STATUS -#define TAOSDEMO_STATUS "unknown" -#endif - -static void printVersion() { - char tdengine_ver[] = TD_VERNUMBER; - char taosdemo_ver[] = TAOSDEMO_COMMIT_SHA1; - char taosdemo_status[] = TAOSDEMO_STATUS; - - if (strlen(taosdemo_status) == 0) { - printf("taosdemo version %s-%s\n", - tdengine_ver, taosdemo_ver); - } else { - printf("taosdemo version %s-%s, status:%s\n", - tdengine_ver, taosdemo_ver, taosdemo_status); - } -} - -static void printHelp() { - char indent[10] = " "; - printf("%s\n\n", "Usage: taosdemo [OPTION...]"); - printf("%s%s%s%s\n", indent, "-f, --file=FILE", "\t\t", - "The meta file to the execution procedure."); - printf("%s%s%s%s\n", indent, "-u, --user=USER", "\t\t", - "The user name to use when connecting to the server."); -#ifdef _TD_POWER_ - printf("%s%s%s%s\n", indent, "-p, --password", "\t\t", - "The password to use when connecting to the server. By default is 'powerdb'"); - printf("%s%s%s%s\n", indent, "-c, --config-dir=CONFIG_DIR", "\t", - "Configuration directory. By default is '/etc/power/'."); -#elif (_TD_TQ_ == true) - printf("%s%s%s%s\n", indent, "-p, --password", "\t\t", - "The password to use when connecting to the server. By default is 'tqueue'"); - printf("%s%s%s%s\n", indent, "-c, --config-dir=CONFIG_DIR", "\t", - "Configuration directory. By default is '/etc/tq/'."); -#elif (_TD_PRO_ == true) - printf("%s%s%s%s\n", indent, "-p, --password", "\t\t", - "The password to use when connecting to the server. By default is 'prodb'"); - printf("%s%s%s%s\n", indent, "-c, --config-dir=CONFIG_DIR", "\t", - "Configuration directory. By default is '/etc/ProDB/'."); -#else - printf("%s%s%s%s\n", indent, "-p, --password", "\t\t", - "The password to use when connecting to the server."); - printf("%s%s%s%s\n", indent, "-c, --config-dir=CONFIG_DIR", "\t", - "Configuration directory."); -#endif - printf("%s%s%s%s\n", indent, "-h, --host=HOST", "\t\t", - "TDengine server FQDN to connect. The default host is localhost."); - printf("%s%s%s%s\n", indent, "-P, --port=PORT", "\t\t", - "The TCP/IP port number to use for the connection."); - printf("%s%s%s%s\n", indent, "-I, --interface=INTERFACE", "\t", - "The interface (taosc, rest, and stmt) taosdemo uses. By default use 'taosc'."); - printf("%s%s%s%s\n", indent, "-d, --database=DATABASE", "\t", - "Destination database. By default is 'test'."); - printf("%s%s%s%s\n", indent, "-a, --replica=REPLICA", "\t\t", - "Set the replica parameters of the database, By default use 1, min: 1, max: 3."); - printf("%s%s%s%s\n", indent, "-m, --table-prefix=TABLEPREFIX", "\t", - "Table prefix name. By default use 'd'."); - printf("%s%s%s%s\n", indent, "-E, --escape-character", "\t", - "Use escape character for Both Stable and normmal table name"); - printf("%s%s%s%s\n", indent, "-s, --sql-file=FILE", "\t\t", - "The select sql file."); - printf("%s%s%s%s\n", indent, "-N, --normal-table", "\t\t", "Use normal table flag."); - printf("%s%s%s%s\n", indent, "-o, --output=FILE", "\t\t", - "Direct output to the named file. By default use './output.txt'."); - printf("%s%s%s%s\n", indent, "-q, --query-mode=MODE", "\t\t", - "Query mode -- 0: SYNC, 1: ASYNC. By default use SYNC."); - printf("%s%s%s%s\n", indent, "-b, --data-type=DATATYPE", "\t", - "The data_type of columns, By default use: FLOAT,INT,FLOAT. NCHAR and BINARY can also use custom length. Eg: NCHAR(16),BINARY(8)"); - printf("%s%s%s%s%d\n", indent, "-w, --binwidth=WIDTH", "\t\t", - "The width of data_type 'BINARY' or 'NCHAR'. By default use ", - g_args.binwidth); - printf("%s%s%s%s%d%s%d\n", indent, "-l, --columns=COLUMNS", "\t\t", - "The number of columns per record. Demo mode by default is ", - DEFAULT_DATATYPE_NUM, - " (float, int, float). Max values is ", - MAX_NUM_COLUMNS); - printf("%s%s%s%s\n", indent, indent, indent, - "\t\t\t\tAll of the new column(s) type is INT. If use -b to specify column type, -l will be ignored."); - printf("%s%s%s%s%d.\n", indent, "-T, --threads=NUMBER", "\t\t", - "The number of threads. By default use ", DEFAULT_NTHREADS); - printf("%s%s%s%s\n", indent, "-i, --insert-interval=NUMBER", "\t", - "The sleep time (ms) between insertion. By default is 0."); - printf("%s%s%s%s%d.\n", indent, "-S, --time-step=TIME_STEP", "\t", - "The timestamp step between insertion. By default is ", - DEFAULT_TIMESTAMP_STEP); - printf("%s%s%s%s%d.\n", indent, "-B, --interlace-rows=NUMBER", "\t", - "The interlace rows of insertion. By default is ", - DEFAULT_INTERLACE_ROWS); - printf("%s%s%s%s\n", indent, "-r, --rec-per-req=NUMBER", "\t", - "The number of records per request. By default is 30000."); - printf("%s%s%s%s\n", indent, "-t, --tables=NUMBER", "\t\t", - "The number of tables. By default is 10000."); - printf("%s%s%s%s\n", indent, "-n, --records=NUMBER", "\t\t", - "The number of records per table. By default is 10000."); - printf("%s%s%s%s\n", indent, "-M, --random", "\t\t\t", - "The value of records generated are totally random."); - printf("%s\n", "\t\t\t\tBy default to simulate power equipment scenario."); - printf("%s%s%s%s\n", indent, "-x, --aggr-func", "\t\t", - "Test aggregation functions after insertion."); - printf("%s%s%s%s\n", indent, "-y, --answer-yes", "\t\t", "Input yes for prompt."); - printf("%s%s%s%s\n", indent, "-O, --disorder=NUMBER", "\t\t", - "Insert order mode--0: In order, 1 ~ 50: disorder ratio. By default is in order."); - printf("%s%s%s%s\n", indent, "-R, --disorder-range=NUMBER", "\t", - "Out of order data's range. Unit is ms. By default is 1000."); - printf("%s%s%s%s\n", indent, "-g, --debug", "\t\t\t", - "Print debug info."); - printf("%s%s%s%s\n", indent, "-?, --help\t", "\t\t", - "Give this help list"); - printf("%s%s%s%s\n", indent, " --usage\t", "\t\t", - "Give a short usage message"); - printf("%s%s\n", indent, "-V, --version\t\t\tPrint program version."); - /* printf("%s%s%s%s\n", indent, "-D", indent, - "Delete database if exists. 0: no, 1: yes, default is 1"); - */ - printf("\nMandatory or optional arguments to long options are also mandatory or optional\n\ -for any corresponding short options.\n\ -\n\ -Report bugs to .\n"); -} - -static bool isStringNumber(char *input) -{ - int len = strlen(input); - if (0 == len) { - return false; - } - - for (int i = 0; i < len; i++) { - if (!isdigit(input[i])) - return false; - } - - return true; -} - -static void errorWrongValue(char *program, char *wrong_arg, char *wrong_value) -{ - fprintf(stderr, "%s %s: %s is an invalid value\n", program, wrong_arg, wrong_value); - fprintf(stderr, "Try `taosdemo --help' or `taosdemo --usage' for more information.\n"); -} - -static void errorUnrecognized(char *program, char *wrong_arg) -{ - fprintf(stderr, "%s: unrecognized options '%s'\n", program, wrong_arg); - fprintf(stderr, "Try `taosdemo --help' or `taosdemo --usage' for more information.\n"); -} - -static void errorPrintReqArg(char *program, char *wrong_arg) -{ - fprintf(stderr, - "%s: option requires an argument -- '%s'\n", - program, wrong_arg); - fprintf(stderr, - "Try `taosdemo --help' or `taosdemo --usage' for more information.\n"); -} - -static void errorPrintReqArg2(char *program, char *wrong_arg) -{ - fprintf(stderr, - "%s: option requires a number argument '-%s'\n", - program, wrong_arg); - fprintf(stderr, - "Try `taosdemo --help' or `taosdemo --usage' for more information.\n"); -} - -static void errorPrintReqArg3(char *program, char *wrong_arg) -{ - fprintf(stderr, - "%s: option '%s' requires an argument\n", - program, wrong_arg); - fprintf(stderr, - "Try `taosdemo --help' or `taosdemo --usage' for more information.\n"); -} - -static void parse_args(int argc, char *argv[], SArguments *arguments) { - - for (int i = 1; i < argc; i++) { - if ((0 == strncmp(argv[i], "-f", strlen("-f"))) - || (0 == strncmp(argv[i], "--file", strlen("--file")))) { - arguments->demo_mode = false; - - if (2 == strlen(argv[i])) { - if (i+1 == argc) { - errorPrintReqArg(argv[0], "f"); - exit(EXIT_FAILURE); - } - arguments->metaFile = argv[++i]; - } else if (0 == strncmp(argv[i], "-f", strlen("-f"))) { - arguments->metaFile = (char *)(argv[i] + strlen("-f")); - } else if (strlen("--file") == strlen(argv[i])) { - if (i+1 == argc) { - errorPrintReqArg3(argv[0], "--file"); - exit(EXIT_FAILURE); - } - arguments->metaFile = argv[++i]; - } else if (0 == strncmp(argv[i], "--file=", strlen("--file="))) { - arguments->metaFile = (char *)(argv[i] + strlen("--file=")); - } else { - errorUnrecognized(argv[0], argv[i]); - exit(EXIT_FAILURE); - } - } else if ((0 == strncmp(argv[i], "-c", strlen("-c"))) - || (0 == strncmp(argv[i], "--config-dir", strlen("--config-dir")))) { - if (2 == strlen(argv[i])) { - if (argc == i+1) { - errorPrintReqArg(argv[0], "c"); - exit(EXIT_FAILURE); - } - tstrncpy(configDir, argv[++i], TSDB_FILENAME_LEN); - } else if (0 == strncmp(argv[i], "-c", strlen("-c"))) { - tstrncpy(configDir, (char *)(argv[i] + strlen("-c")), TSDB_FILENAME_LEN); - } else if (strlen("--config-dir") == strlen(argv[i])) { - if (argc == i+1) { - errorPrintReqArg3(argv[0], "--config-dir"); - exit(EXIT_FAILURE); - } - tstrncpy(configDir, argv[++i], TSDB_FILENAME_LEN); - } else if (0 == strncmp(argv[i], "--config-dir=", strlen("--config-dir="))) { - tstrncpy(configDir, (char *)(argv[i] + strlen("--config-dir=")), TSDB_FILENAME_LEN); - } else { - errorUnrecognized(argv[0], argv[i]); - exit(EXIT_FAILURE); - } - } else if ((0 == strncmp(argv[i], "-h", strlen("-h"))) - || (0 == strncmp(argv[i], "--host", strlen("--host")))) { - if (2 == strlen(argv[i])) { - if (argc == i+1) { - errorPrintReqArg(argv[0], "h"); - exit(EXIT_FAILURE); - } - arguments->host = argv[++i]; - } else if (0 == strncmp(argv[i], "-h", strlen("-h"))) { - arguments->host = (char *)(argv[i] + strlen("-h")); - } else if (strlen("--host") == strlen(argv[i])) { - if (argc == i+1) { - errorPrintReqArg3(argv[0], "--host"); - exit(EXIT_FAILURE); - } - arguments->host = argv[++i]; - } else if (0 == strncmp(argv[i], "--host=", strlen("--host="))) { - arguments->host = (char *)(argv[i] + strlen("--host=")); - } else { - errorUnrecognized(argv[0], argv[i]); - exit(EXIT_FAILURE); - } - } else if (strcmp(argv[i], "-PP") == 0) { - arguments->performance_print = true; - } else if ((0 == strncmp(argv[i], "-P", strlen("-P"))) - || (0 == strncmp(argv[i], "--port", strlen("--port")))) { - uint64_t port; - char strPort[BIGINT_BUFF_LEN]; - - if (2 == strlen(argv[i])) { - if (argc == i+1) { - errorPrintReqArg(argv[0], "P"); - exit(EXIT_FAILURE); - } else if (isStringNumber(argv[i+1])) { - tstrncpy(strPort, argv[++i], BIGINT_BUFF_LEN); - } else { - errorPrintReqArg2(argv[0], "P"); - exit(EXIT_FAILURE); - } - } else if (0 == strncmp(argv[i], "--port=", strlen("--port="))) { - if (isStringNumber((char *)(argv[i] + strlen("--port=")))) { - tstrncpy(strPort, (char *)(argv[i]+strlen("--port=")), BIGINT_BUFF_LEN); - } else { - errorPrintReqArg2(argv[0], "--port"); - exit(EXIT_FAILURE); - } - } else if (0 == strncmp(argv[i], "-P", strlen("-P"))) { - if (isStringNumber((char *)(argv[i] + strlen("-P")))) { - tstrncpy(strPort, (char *)(argv[i]+strlen("-P")), BIGINT_BUFF_LEN); - } else { - errorPrintReqArg2(argv[0], "--port"); - exit(EXIT_FAILURE); - } - } else if (strlen("--port") == strlen(argv[i])) { - if (argc == i+1) { - errorPrintReqArg3(argv[0], "--port"); - exit(EXIT_FAILURE); - } else if (isStringNumber(argv[i+1])) { - tstrncpy(strPort, argv[++i], BIGINT_BUFF_LEN); - } else { - errorPrintReqArg2(argv[0], "--port"); - exit(EXIT_FAILURE); - } - } else { - errorUnrecognized(argv[0], argv[i]); - exit(EXIT_FAILURE); - } - - port = atoi(strPort); - if (port > 65535) { - errorWrongValue("taosdump", "-P or --port", strPort); - exit(EXIT_FAILURE); - } - arguments->port = (uint16_t)port; - - } else if ((0 == strncmp(argv[i], "-I", strlen("-I"))) - || (0 == strncmp(argv[i], "--interface", strlen("--interface")))) { - if (2 == strlen(argv[i])) { - if (argc == i+1) { - errorPrintReqArg(argv[0], "I"); - exit(EXIT_FAILURE); - } - if (0 == strcasecmp(argv[i+1], "taosc")) { - arguments->iface = TAOSC_IFACE; - } else if (0 == strcasecmp(argv[i+1], "rest")) { - arguments->iface = REST_IFACE; - } else if (0 == strcasecmp(argv[i+1], "stmt")) { - arguments->iface = STMT_IFACE; - } else if (0 == strcasecmp(argv[i+1], "sml")) { - arguments->iface = SML_IFACE; - } else { - errorWrongValue(argv[0], "-I", argv[i+1]); - exit(EXIT_FAILURE); - } - i++; - } else if (0 == strncmp(argv[i], "--interface=", strlen("--interface="))) { - if (0 == strcasecmp((char *)(argv[i] + strlen("--interface=")), "taosc")) { - arguments->iface = TAOSC_IFACE; - } else if (0 == strcasecmp((char *)(argv[i] + strlen("--interface=")), "rest")) { - arguments->iface = REST_IFACE; - } else if (0 == strcasecmp((char *)(argv[i] + strlen("--interface=")), "stmt")) { - arguments->iface = STMT_IFACE; - } else if (0 == strcasecmp((char *)(argv[i] + strlen("--interface=")), "sml")) { - arguments->iface = SML_IFACE; - } else { - errorPrintReqArg3(argv[0], "--interface"); - exit(EXIT_FAILURE); - } - } else if (0 == strncmp(argv[i], "-I", strlen("-I"))) { - if (0 == strcasecmp((char *)(argv[i] + strlen("-I")), "taosc")) { - arguments->iface = TAOSC_IFACE; - } else if (0 == strcasecmp((char *)(argv[i] + strlen("-I")), "rest")) { - arguments->iface = REST_IFACE; - } else if (0 == strcasecmp((char *)(argv[i] + strlen("-I")), "stmt")) { - arguments->iface = STMT_IFACE; - } else if (0 == strcasecmp((char *)(argv[i] + strlen("-I")), "sml")) { - arguments->iface = SML_IFACE; - } else { - errorWrongValue(argv[0], "-I", - (char *)(argv[i] + strlen("-I"))); - exit(EXIT_FAILURE); - } - } else if (strlen("--interface") == strlen(argv[i])) { - if (argc == i+1) { - errorPrintReqArg3(argv[0], "--interface"); - exit(EXIT_FAILURE); - } - if (0 == strcasecmp(argv[i+1], "taosc")) { - arguments->iface = TAOSC_IFACE; - } else if (0 == strcasecmp(argv[i+1], "rest")) { - arguments->iface = REST_IFACE; - } else if (0 == strcasecmp(argv[i+1], "stmt")) { - arguments->iface = STMT_IFACE; - } else if (0 == strcasecmp(argv[i+1], "sml")) { - arguments->iface = SML_IFACE; - } else { - errorWrongValue(argv[0], "--interface", argv[i+1]); - exit(EXIT_FAILURE); - } - i++; - } else { - errorUnrecognized(argv[0], argv[i]); - exit(EXIT_FAILURE); - } - } else if ((0 == strncmp(argv[i], "-u", strlen("-u"))) - || (0 == strncmp(argv[i], "--user", strlen("--user")))) { - if (2 == strlen(argv[i])) { - if (argc == i+1) { - errorPrintReqArg(argv[0], "u"); - exit(EXIT_FAILURE); - } - arguments->user = argv[++i]; - } else if (0 == strncmp(argv[i], "-u", strlen("-u"))) { - arguments->user = (char *)(argv[i++] + strlen("-u")); - } else if (0 == strncmp(argv[i], "--user=", strlen("--user="))) { - arguments->user = (char *)(argv[i++] + strlen("--user=")); - } else if (strlen("--user") == strlen(argv[i])) { - if (argc == i+1) { - errorPrintReqArg3(argv[0], "--user"); - exit(EXIT_FAILURE); - } - arguments->user = argv[++i]; - } else { - errorUnrecognized(argv[0], argv[i]); - exit(EXIT_FAILURE); - } - } else if ((0 == strncmp(argv[i], "-p", strlen("-p"))) - || (0 == strcmp(argv[i], "--password"))) { - if ((strlen(argv[i]) == 2) || (0 == strcmp(argv[i], "--password"))) { - printf("Enter password: "); - taosSetConsoleEcho(false); - if (scanf("%s", arguments->password) > 1) { - fprintf(stderr, "password read error!\n"); - } - taosSetConsoleEcho(true); - } else { - tstrncpy(arguments->password, (char *)(argv[i] + 2), SHELL_MAX_PASSWORD_LEN); - } - } else if ((0 == strncmp(argv[i], "-o", strlen("-o"))) - || (0 == strncmp(argv[i], "--output", strlen("--output")))) { - if (2 == strlen(argv[i])) { - if (argc == i+1) { - errorPrintReqArg3(argv[0], "--output"); - exit(EXIT_FAILURE); - } - arguments->output_file = argv[++i]; - } else if (0 == strncmp(argv[i], "--output=", strlen("--output="))) { - arguments->output_file = (char *)(argv[i++] + strlen("--output=")); - } else if (0 == strncmp(argv[i], "-o", strlen("-o"))) { - arguments->output_file = (char *)(argv[i++] + strlen("-o")); - } else if (strlen("--output") == strlen(argv[i])) { - if (argc == i+1) { - errorPrintReqArg3(argv[0], "--output"); - exit(EXIT_FAILURE); - } - arguments->output_file = argv[++i]; - } else { - errorUnrecognized(argv[0], argv[i]); - exit(EXIT_FAILURE); - } - } else if ((0 == strncmp(argv[i], "-s", strlen("-s"))) - || (0 == strncmp(argv[i], "--sql-file", strlen("--sql-file")))) { - if (2 == strlen(argv[i])) { - if (argc == i+1) { - errorPrintReqArg(argv[0], "s"); - exit(EXIT_FAILURE); - } - arguments->sqlFile = argv[++i]; - } else if (0 == strncmp(argv[i], "--sql-file=", strlen("--sql-file="))) { - arguments->sqlFile = (char *)(argv[i++] + strlen("--sql-file=")); - } else if (0 == strncmp(argv[i], "-s", strlen("-s"))) { - arguments->sqlFile = (char *)(argv[i++] + strlen("-s")); - } else if (strlen("--sql-file") == strlen(argv[i])) { - if (argc == i+1) { - errorPrintReqArg3(argv[0], "--sql-file"); - exit(EXIT_FAILURE); - } - arguments->sqlFile = argv[++i]; - } else { - errorUnrecognized(argv[0], argv[i]); - exit(EXIT_FAILURE); - } - } else if ((0 == strncmp(argv[i], "-q", strlen("-q"))) - || (0 == strncmp(argv[i], "--query-mode", strlen("--query-mode")))) { - if (2 == strlen(argv[i])) { - if (argc == i+1) { - errorPrintReqArg(argv[0], "q"); - exit(EXIT_FAILURE); - } else if (!isStringNumber(argv[i+1])) { - errorPrintReqArg2(argv[0], "q"); - exit(EXIT_FAILURE); - } - arguments->async_mode = atoi(argv[++i]); - } else if (0 == strncmp(argv[i], "--query-mode=", strlen("--query-mode="))) { - if (isStringNumber((char *)(argv[i] + strlen("--query-mode=")))) { - arguments->async_mode = atoi((char *)(argv[i]+strlen("--query-mode="))); - } else { - errorPrintReqArg2(argv[0], "--query-mode"); - exit(EXIT_FAILURE); - } - } else if (0 == strncmp(argv[i], "-q", strlen("-q"))) { - if (isStringNumber((char *)(argv[i] + strlen("-q")))) { - arguments->async_mode = atoi((char *)(argv[i]+strlen("-q"))); - } else { - errorPrintReqArg2(argv[0], "-q"); - exit(EXIT_FAILURE); - } - } else if (strlen("--query-mode") == strlen(argv[i])) { - if (argc == i+1) { - errorPrintReqArg3(argv[0], "--query-mode"); - exit(EXIT_FAILURE); - } else if (!isStringNumber(argv[i+1])) { - errorPrintReqArg2(argv[0], "--query-mode"); - exit(EXIT_FAILURE); - } - arguments->async_mode = atoi(argv[++i]); - } else { - errorUnrecognized(argv[0], argv[i]); - exit(EXIT_FAILURE); - } - } else if ((0 == strncmp(argv[i], "-T", strlen("-T"))) - || (0 == strncmp(argv[i], "--threads", strlen("--threads")))) { - if (2 == strlen(argv[i])) { - if (argc == i+1) { - errorPrintReqArg(argv[0], "T"); - exit(EXIT_FAILURE); - } else if (!isStringNumber(argv[i+1])) { - errorPrintReqArg2(argv[0], "T"); - exit(EXIT_FAILURE); - } - arguments->nthreads = atoi(argv[++i]); - } else if (0 == strncmp(argv[i], "--threads=", strlen("--threads="))) { - if (isStringNumber((char *)(argv[i] + strlen("--threads=")))) { - arguments->nthreads = atoi((char *)(argv[i]+strlen("--threads="))); - } else { - errorPrintReqArg2(argv[0], "--threads"); - exit(EXIT_FAILURE); - } - } else if (0 == strncmp(argv[i], "-T", strlen("-T"))) { - if (isStringNumber((char *)(argv[i] + strlen("-T")))) { - arguments->nthreads = atoi((char *)(argv[i]+strlen("-T"))); - } else { - errorPrintReqArg2(argv[0], "-T"); - exit(EXIT_FAILURE); - } - } else if (strlen("--threads") == strlen(argv[i])) { - if (argc == i+1) { - errorPrintReqArg3(argv[0], "--threads"); - exit(EXIT_FAILURE); - } else if (!isStringNumber(argv[i+1])) { - errorPrintReqArg2(argv[0], "--threads"); - exit(EXIT_FAILURE); - } - arguments->nthreads = atoi(argv[++i]); - } else { - errorUnrecognized(argv[0], argv[i]); - exit(EXIT_FAILURE); - } - } else if ((0 == strncmp(argv[i], "-i", strlen("-i"))) - || (0 == strncmp(argv[i], "--insert-interval", strlen("--insert-interval")))) { - if (2 == strlen(argv[i])) { - if (argc == i+1) { - errorPrintReqArg(argv[0], "i"); - exit(EXIT_FAILURE); - } else if (!isStringNumber(argv[i+1])) { - errorPrintReqArg2(argv[0], "i"); - exit(EXIT_FAILURE); - } - arguments->insert_interval = atoi(argv[++i]); - } else if (0 == strncmp(argv[i], "--insert-interval=", strlen("--insert-interval="))) { - if (isStringNumber((char *)(argv[i] + strlen("--insert-interval=")))) { - arguments->insert_interval = atoi((char *)(argv[i]+strlen("--insert-interval="))); - } else { - errorPrintReqArg3(argv[0], "--insert-innterval"); - exit(EXIT_FAILURE); - } - } else if (0 == strncmp(argv[i], "-i", strlen("-i"))) { - if (isStringNumber((char *)(argv[i] + strlen("-i")))) { - arguments->insert_interval = atoi((char *)(argv[i]+strlen("-i"))); - } else { - errorPrintReqArg3(argv[0], "-i"); - exit(EXIT_FAILURE); - } - } else if (strlen("--insert-interval")== strlen(argv[i])) { - if (argc == i+1) { - errorPrintReqArg3(argv[0], "--insert-interval"); - exit(EXIT_FAILURE); - } else if (!isStringNumber(argv[i+1])) { - errorPrintReqArg2(argv[0], "--insert-interval"); - exit(EXIT_FAILURE); - } - arguments->insert_interval = atoi(argv[++i]); - } else { - errorUnrecognized(argv[0], argv[i]); - exit(EXIT_FAILURE); - } - } else if ((0 == strncmp(argv[i], "-S", strlen("-S"))) - || (0 == strncmp(argv[i], "--time-step", strlen("--time-step")))) { - if (2 == strlen(argv[i])) { - if (argc == i+1) { - errorPrintReqArg(argv[0], "S"); - exit(EXIT_FAILURE); - } else if (!isStringNumber(argv[i+1])) { - errorPrintReqArg2(argv[0], "S"); - exit(EXIT_FAILURE); - } - arguments->async_mode = atoi(argv[++i]); - } else if (0 == strncmp(argv[i], "--time-step=", strlen("--time-step="))) { - if (isStringNumber((char *)(argv[i] + strlen("--time-step=")))) { - arguments->async_mode = atoi((char *)(argv[i]+strlen("--time-step="))); - } else { - errorPrintReqArg2(argv[0], "--time-step"); - exit(EXIT_FAILURE); - } - } else if (0 == strncmp(argv[i], "-S", strlen("-S"))) { - if (isStringNumber((char *)(argv[i] + strlen("-S")))) { - arguments->async_mode = atoi((char *)(argv[i]+strlen("-S"))); - } else { - errorPrintReqArg2(argv[0], "-S"); - exit(EXIT_FAILURE); - } - } else if (strlen("--time-step") == strlen(argv[i])) { - if (argc == i+1) { - errorPrintReqArg3(argv[0], "--time-step"); - exit(EXIT_FAILURE); - } else if (!isStringNumber(argv[i+1])) { - errorPrintReqArg2(argv[0], "--time-step"); - exit(EXIT_FAILURE); - } - arguments->async_mode = atoi(argv[++i]); - } else { - errorUnrecognized(argv[0], argv[i]); - exit(EXIT_FAILURE); - } - } else if (strcmp(argv[i], "-qt") == 0) { - if ((argc == i+1) - || (!isStringNumber(argv[i+1]))) { - printHelp(); - errorPrint("%s", "\n\t-qt need a number following!\n"); - exit(EXIT_FAILURE); - } - arguments->query_times = atoi(argv[++i]); - } else if ((0 == strncmp(argv[i], "-B", strlen("-B"))) - || (0 == strncmp(argv[i], "--interlace-rows", strlen("--interlace-rows")))) { - if (strlen("-B") == strlen(argv[i])) { - if (argc == i+1) { - errorPrintReqArg(argv[0], "B"); - exit(EXIT_FAILURE); - } else if (!isStringNumber(argv[i+1])) { - errorPrintReqArg2(argv[0], "B"); - exit(EXIT_FAILURE); - } - arguments->interlaceRows = atoi(argv[++i]); - } else if (0 == strncmp(argv[i], "--interlace-rows=", strlen("--interlace-rows="))) { - if (isStringNumber((char *)(argv[i] + strlen("--interlace-rows=")))) { - arguments->interlaceRows = atoi((char *)(argv[i]+strlen("--interlace-rows="))); - } else { - errorPrintReqArg2(argv[0], "--interlace-rows"); - exit(EXIT_FAILURE); - } - } else if (0 == strncmp(argv[i], "-B", strlen("-B"))) { - if (isStringNumber((char *)(argv[i] + strlen("-B")))) { - arguments->interlaceRows = atoi((char *)(argv[i]+strlen("-B"))); - } else { - errorPrintReqArg2(argv[0], "-B"); - exit(EXIT_FAILURE); - } - } else if (strlen("--interlace-rows")== strlen(argv[i])) { - if (argc == i+1) { - errorPrintReqArg3(argv[0], "--interlace-rows"); - exit(EXIT_FAILURE); - } else if (!isStringNumber(argv[i+1])) { - errorPrintReqArg2(argv[0], "--interlace-rows"); - exit(EXIT_FAILURE); - } - arguments->interlaceRows = atoi(argv[++i]); - } else { - errorUnrecognized(argv[0], argv[i]); - exit(EXIT_FAILURE); - } - } else if ((0 == strncmp(argv[i], "-r", strlen("-r"))) - || (0 == strncmp(argv[i], "--rec-per-req", 13))) { - if (strlen("-r") == strlen(argv[i])) { - if (argc == i+1) { - errorPrintReqArg(argv[0], "r"); - exit(EXIT_FAILURE); - } else if (!isStringNumber(argv[i+1])) { - errorPrintReqArg2(argv[0], "r"); - exit(EXIT_FAILURE); - } - arguments->reqPerReq = atoi(argv[++i]); - } else if (0 == strncmp(argv[i], "--rec-per-req=", strlen("--rec-per-req="))) { - if (isStringNumber((char *)(argv[i] + strlen("--rec-per-req=")))) { - arguments->reqPerReq = atoi((char *)(argv[i]+strlen("--rec-per-req="))); - } else { - errorPrintReqArg2(argv[0], "--rec-per-req"); - exit(EXIT_FAILURE); - } - } else if (0 == strncmp(argv[i], "-r", strlen("-r"))) { - if (isStringNumber((char *)(argv[i] + strlen("-r")))) { - arguments->reqPerReq = atoi((char *)(argv[i]+strlen("-r"))); - } else { - errorPrintReqArg2(argv[0], "-r"); - exit(EXIT_FAILURE); - } - } else if (strlen("--rec-per-req")== strlen(argv[i])) { - if (argc == i+1) { - errorPrintReqArg3(argv[0], "--rec-per-req"); - exit(EXIT_FAILURE); - } else if (!isStringNumber(argv[i+1])) { - errorPrintReqArg2(argv[0], "--rec-per-req"); - exit(EXIT_FAILURE); - } - arguments->reqPerReq = atoi(argv[++i]); - } else { - errorUnrecognized(argv[0], argv[i]); - exit(EXIT_FAILURE); - } - } else if ((0 == strncmp(argv[i], "-t", strlen("-t"))) - || (0 == strncmp(argv[i], "--tables", strlen("--tables")))) { - if (2 == strlen(argv[i])) { - if (argc == i+1) { - errorPrintReqArg(argv[0], "t"); - exit(EXIT_FAILURE); - } else if (!isStringNumber(argv[i+1])) { - errorPrintReqArg2(argv[0], "t"); - exit(EXIT_FAILURE); - } - arguments->ntables = atoi(argv[++i]); - } else if (0 == strncmp(argv[i], "--tables=", strlen("--tables="))) { - if (isStringNumber((char *)(argv[i] + strlen("--tables=")))) { - arguments->ntables = atoi((char *)(argv[i]+strlen("--tables="))); - } else { - errorPrintReqArg2(argv[0], "--tables"); - exit(EXIT_FAILURE); - } - } else if (0 == strncmp(argv[i], "-t", strlen("-t"))) { - if (isStringNumber((char *)(argv[i] + strlen("-t")))) { - arguments->ntables = atoi((char *)(argv[i]+strlen("-t"))); - } else { - errorPrintReqArg2(argv[0], "-t"); - exit(EXIT_FAILURE); - } - } else if (strlen("--tables") == strlen(argv[i])) { - if (argc == i+1) { - errorPrintReqArg3(argv[0], "--tables"); - exit(EXIT_FAILURE); - } else if (!isStringNumber(argv[i+1])) { - errorPrintReqArg2(argv[0], "--tables"); - exit(EXIT_FAILURE); - } - arguments->ntables = atoi(argv[++i]); - } else { - errorUnrecognized(argv[0], argv[i]); - exit(EXIT_FAILURE); - } - - g_totalChildTables = arguments->ntables; - } else if ((0 == strncmp(argv[i], "-n", strlen("-n"))) - || (0 == strncmp(argv[i], "--records", strlen("--records")))) { - if (2 == strlen(argv[i])) { - if (argc == i+1) { - errorPrintReqArg(argv[0], "n"); - exit(EXIT_FAILURE); - } else if (!isStringNumber(argv[i+1])) { - errorPrintReqArg2(argv[0], "n"); - exit(EXIT_FAILURE); - } - arguments->insertRows = atoi(argv[++i]); - } else if (0 == strncmp(argv[i], "--records=", strlen("--records="))) { - if (isStringNumber((char *)(argv[i] + strlen("--records=")))) { - arguments->insertRows = atoi((char *)(argv[i]+strlen("--records="))); - } else { - errorPrintReqArg2(argv[0], "--records"); - exit(EXIT_FAILURE); - } - } else if (0 == strncmp(argv[i], "-n", strlen("-n"))) { - if (isStringNumber((char *)(argv[i] + strlen("-n")))) { - arguments->insertRows = atoi((char *)(argv[i]+strlen("-n"))); - } else { - errorPrintReqArg2(argv[0], "-n"); - exit(EXIT_FAILURE); - } - } else if (strlen("--records") == strlen(argv[i])) { - if (argc == i+1) { - errorPrintReqArg3(argv[0], "--records"); - exit(EXIT_FAILURE); - } else if (!isStringNumber(argv[i+1])) { - errorPrintReqArg2(argv[0], "--records"); - exit(EXIT_FAILURE); - } - arguments->insertRows = atoi(argv[++i]); - } else { - errorUnrecognized(argv[0], argv[i]); - exit(EXIT_FAILURE); - } - } else if ((0 == strncmp(argv[i], "-d", strlen("-d"))) - || (0 == strncmp(argv[i], "--database", strlen("--database")))) { - if (2 == strlen(argv[i])) { - if (argc == i+1) { - errorPrintReqArg(argv[0], "d"); - exit(EXIT_FAILURE); - } - arguments->database = argv[++i]; - } else if (0 == strncmp(argv[i], "--database=", strlen("--database="))) { - arguments->output_file = (char *)(argv[i] + strlen("--database=")); - } else if (0 == strncmp(argv[i], "-d", strlen("-d"))) { - arguments->output_file = (char *)(argv[i] + strlen("-d")); - } else if (strlen("--database") == strlen(argv[i])) { - if (argc == i+1) { - errorPrintReqArg3(argv[0], "--database"); - exit(EXIT_FAILURE); - } - arguments->database = argv[++i]; - } else { - errorUnrecognized(argv[0], argv[i]); - exit(EXIT_FAILURE); - } - } else if ((0 == strncmp(argv[i], "-l", strlen("-l"))) - || (0 == strncmp(argv[i], "--columns", strlen("--columns")))) { - arguments->demo_mode = false; - if (2 == strlen(argv[i])) { - if (argc == i+1) { - errorPrintReqArg(argv[0], "l"); - exit(EXIT_FAILURE); - } else if (!isStringNumber(argv[i+1])) { - errorPrintReqArg2(argv[0], "l"); - exit(EXIT_FAILURE); - } - arguments->columnCount = atoi(argv[++i]); - } else if (0 == strncmp(argv[i], "--columns=", strlen("--columns="))) { - if (isStringNumber((char *)(argv[i] + strlen("--columns=")))) { - arguments->columnCount = atoi((char *)(argv[i]+strlen("--columns="))); - } else { - errorPrintReqArg2(argv[0], "--columns"); - exit(EXIT_FAILURE); - } - } else if (0 == strncmp(argv[i], "-l", strlen("-l"))) { - if (isStringNumber((char *)(argv[i] + strlen("-l")))) { - arguments->columnCount = atoi((char *)(argv[i]+strlen("-l"))); - } else { - errorPrintReqArg2(argv[0], "-l"); - exit(EXIT_FAILURE); - } - } else if (strlen("--columns")== strlen(argv[i])) { - if (argc == i+1) { - errorPrintReqArg3(argv[0], "--columns"); - exit(EXIT_FAILURE); - } else if (!isStringNumber(argv[i+1])) { - errorPrintReqArg2(argv[0], "--columns"); - exit(EXIT_FAILURE); - } - arguments->columnCount = atoi(argv[++i]); - } else { - errorUnrecognized(argv[0], argv[i]); - exit(EXIT_FAILURE); - } - - if (arguments->columnCount > MAX_NUM_COLUMNS) { - printf("WARNING: max acceptable columns count is %d\n", MAX_NUM_COLUMNS); - prompt(); - arguments->columnCount = MAX_NUM_COLUMNS; - } - - for (int col = DEFAULT_DATATYPE_NUM; col < arguments->columnCount; col ++) { - arguments->dataType[col] = "INT"; - arguments->data_type[col] = TSDB_DATA_TYPE_INT; - } - for (int col = arguments->columnCount; col < MAX_NUM_COLUMNS; col++) { - arguments->dataType[col] = NULL; - arguments->data_type[col] = TSDB_DATA_TYPE_NULL; - } - } else if ((0 == strncmp(argv[i], "-b", strlen("-b"))) - || (0 == strncmp(argv[i], "--data-type", strlen("--data-type")))) { - arguments->demo_mode = false; - - char *dataType; - if (2 == strlen(argv[i])) { - if (argc == i+1) { - errorPrintReqArg(argv[0], "b"); - exit(EXIT_FAILURE); - } - dataType = argv[++i]; - } else if (0 == strncmp(argv[i], "--data-type=", strlen("--data-type="))) { - dataType = (char *)(argv[i] + strlen("--data-type=")); - } else if (0 == strncmp(argv[i], "-b", strlen("-b"))) { - dataType = (char *)(argv[i] + strlen("-b")); - } else if (strlen("--data-type") == strlen(argv[i])) { - if (argc == i+1) { - errorPrintReqArg3(argv[0], "--data-type"); - exit(EXIT_FAILURE); - } - dataType = argv[++i]; - } else { - errorUnrecognized(argv[0], argv[i]); - exit(EXIT_FAILURE); - } - - if (strstr(dataType, ",") == NULL) { - // only one col - if (strcasecmp(dataType, "INT") - && strcasecmp(dataType, "FLOAT") - && strcasecmp(dataType, "TINYINT") - && strcasecmp(dataType, "BOOL") - && strcasecmp(dataType, "SMALLINT") - && strcasecmp(dataType, "BIGINT") - && strcasecmp(dataType, "DOUBLE") - && strcasecmp(dataType, "TIMESTAMP") - && !regexMatch(dataType, - "^(NCHAR|BINARY)(\\([1-9][0-9]*\\))?$", - REG_ICASE | REG_EXTENDED) - && strcasecmp(dataType, "UTINYINT") - && strcasecmp(dataType, "USMALLINT") - && strcasecmp(dataType, "UINT") - && strcasecmp(dataType, "UBIGINT")) { - printHelp(); - errorPrint("%s", "-b: Invalid data_type!\n"); - exit(EXIT_FAILURE); - } - arguments->dataType[0] = dataType; - if (0 == strcasecmp(dataType, "INT")) { - arguments->data_type[0] = TSDB_DATA_TYPE_INT; - } else if (0 == strcasecmp(dataType, "TINYINT")) { - arguments->data_type[0] = TSDB_DATA_TYPE_TINYINT; - } else if (0 == strcasecmp(dataType, "SMALLINT")) { - arguments->data_type[0] = TSDB_DATA_TYPE_SMALLINT; - } else if (0 == strcasecmp(dataType, "BIGINT")) { - arguments->data_type[0] = TSDB_DATA_TYPE_BIGINT; - } else if (0 == strcasecmp(dataType, "FLOAT")) { - arguments->data_type[0] = TSDB_DATA_TYPE_FLOAT; - } else if (0 == strcasecmp(dataType, "DOUBLE")) { - arguments->data_type[0] = TSDB_DATA_TYPE_DOUBLE; - } else if (1 == regexMatch(dataType, - "^BINARY(\\([1-9][0-9]*\\))?$", - REG_ICASE | REG_EXTENDED)) { - arguments->data_type[0] = TSDB_DATA_TYPE_BINARY; - } else if (1 == regexMatch(dataType, - "^NCHAR(\\([1-9][0-9]*\\))?$", - REG_ICASE | REG_EXTENDED)) { - arguments->data_type[0] = TSDB_DATA_TYPE_NCHAR; - } else if (0 == strcasecmp(dataType, "BOOL")) { - arguments->data_type[0] = TSDB_DATA_TYPE_BOOL; - } else if (0 == strcasecmp(dataType, "TIMESTAMP")) { - arguments->data_type[0] = TSDB_DATA_TYPE_TIMESTAMP; - } else if (0 == strcasecmp(dataType, "UTINYINT")) { - arguments->data_type[0] = TSDB_DATA_TYPE_UTINYINT; - } else if (0 == strcasecmp(dataType, "USMALLINT")) { - arguments->data_type[0] = TSDB_DATA_TYPE_USMALLINT; - } else if (0 == strcasecmp(dataType, "UINT")) { - arguments->data_type[0] = TSDB_DATA_TYPE_UINT; - } else if (0 == strcasecmp(dataType, "UBIGINT")) { - arguments->data_type[0] = TSDB_DATA_TYPE_UBIGINT; - } else { - arguments->data_type[0] = TSDB_DATA_TYPE_NULL; - } - arguments->dataType[1] = NULL; - arguments->data_type[1] = TSDB_DATA_TYPE_NULL; - } else { - // more than one col - int index = 0; - g_dupstr = strdup(dataType); - char *running = g_dupstr; - char *token = strsep(&running, ","); - while(token != NULL) { - if (strcasecmp(token, "INT") - && strcasecmp(token, "FLOAT") - && strcasecmp(token, "TINYINT") - && strcasecmp(token, "BOOL") - && strcasecmp(token, "SMALLINT") - && strcasecmp(token, "BIGINT") - && strcasecmp(token, "DOUBLE") - && strcasecmp(token, "TIMESTAMP") - && !regexMatch(token, "^(NCHAR|BINARY)(\\([1-9][0-9]*\\))?$", REG_ICASE | REG_EXTENDED) - && strcasecmp(token, "UTINYINT") - && strcasecmp(token, "USMALLINT") - && strcasecmp(token, "UINT") - && strcasecmp(token, "UBIGINT")) { - printHelp(); - free(g_dupstr); - errorPrint("%s", "-b: Invalid data_type!\n"); - exit(EXIT_FAILURE); - } - - if (0 == strcasecmp(token, "INT")) { - arguments->data_type[index] = TSDB_DATA_TYPE_INT; - } else if (0 == strcasecmp(token, "FLOAT")) { - arguments->data_type[index] = TSDB_DATA_TYPE_FLOAT; - } else if (0 == strcasecmp(token, "SMALLINT")) { - arguments->data_type[index] = TSDB_DATA_TYPE_SMALLINT; - } else if (0 == strcasecmp(token, "BIGINT")) { - arguments->data_type[index] = TSDB_DATA_TYPE_BIGINT; - } else if (0 == strcasecmp(token, "DOUBLE")) { - arguments->data_type[index] = TSDB_DATA_TYPE_DOUBLE; - } else if (0 == strcasecmp(token, "TINYINT")) { - arguments->data_type[index] = TSDB_DATA_TYPE_TINYINT; - } else if (1 == regexMatch(token, "^BINARY(\\([1-9][0-9]*\\))?$", REG_ICASE | - REG_EXTENDED)) { - arguments->data_type[index] = TSDB_DATA_TYPE_BINARY; - } else if (1 == regexMatch(token, "^NCHAR(\\([1-9][0-9]*\\))?$", REG_ICASE | - REG_EXTENDED)) { - arguments->data_type[index] = TSDB_DATA_TYPE_NCHAR; - } else if (0 == strcasecmp(token, "BOOL")) { - arguments->data_type[index] = TSDB_DATA_TYPE_BOOL; - } else if (0 == strcasecmp(token, "TIMESTAMP")) { - arguments->data_type[index] = TSDB_DATA_TYPE_TIMESTAMP; - } else if (0 == strcasecmp(token, "UTINYINT")) { - arguments->data_type[index] = TSDB_DATA_TYPE_UTINYINT; - } else if (0 == strcasecmp(token, "USMALLINT")) { - arguments->data_type[index] = TSDB_DATA_TYPE_USMALLINT; - } else if (0 == strcasecmp(token, "UINT")) { - arguments->data_type[index] = TSDB_DATA_TYPE_UINT; - } else if (0 == strcasecmp(token, "UBIGINT")) { - arguments->data_type[index] = TSDB_DATA_TYPE_UBIGINT; - } else { - arguments->data_type[index] = TSDB_DATA_TYPE_NULL; - } - arguments->dataType[index] = token; - index ++; - token = strsep(&running, ","); - if (index >= MAX_NUM_COLUMNS) break; - } - arguments->dataType[index] = NULL; - arguments->data_type[index] = TSDB_DATA_TYPE_NULL; - } - } else if ((0 == strncmp(argv[i], "-w", strlen("-w"))) - || (0 == strncmp(argv[i], "--binwidth", strlen("--binwidth")))) { - if (2 == strlen(argv[i])) { - if (argc == i+1) { - errorPrintReqArg(argv[0], "w"); - exit(EXIT_FAILURE); - } else if (!isStringNumber(argv[i+1])) { - errorPrintReqArg2(argv[0], "w"); - exit(EXIT_FAILURE); - } - arguments->binwidth = atoi(argv[++i]); - } else if (0 == strncmp(argv[i], "--binwidth=", strlen("--binwidth="))) { - if (isStringNumber((char *)(argv[i] + strlen("--binwidth=")))) { - arguments->binwidth = atoi((char *)(argv[i]+strlen("--binwidth="))); - } else { - errorPrintReqArg2(argv[0], "--binwidth"); - exit(EXIT_FAILURE); - } - } else if (0 == strncmp(argv[i], "-w", strlen("-w"))) { - if (isStringNumber((char *)(argv[i] + strlen("-w")))) { - arguments->binwidth = atoi((char *)(argv[i]+strlen("-w"))); - } else { - errorPrintReqArg2(argv[0], "-w"); - exit(EXIT_FAILURE); - } - } else if (strlen("--binwidth") == strlen(argv[i])) { - if (argc == i+1) { - errorPrintReqArg3(argv[0], "--binwidth"); - exit(EXIT_FAILURE); - } else if (!isStringNumber(argv[i+1])) { - errorPrintReqArg2(argv[0], "--binwidth"); - exit(EXIT_FAILURE); - } - arguments->binwidth = atoi(argv[++i]); - } else { - errorUnrecognized(argv[0], argv[i]); - exit(EXIT_FAILURE); - } - } else if ((0 == strncmp(argv[i], "-m", strlen("-m"))) - || (0 == strncmp(argv[i], "--table-prefix", strlen("--table-prefix")))) { - if (2 == strlen(argv[i])) { - if (argc == i+1) { - errorPrintReqArg(argv[0], "m"); - exit(EXIT_FAILURE); - } - arguments->tb_prefix = argv[++i]; - } else if (0 == strncmp(argv[i], "--table-prefix=", strlen("--table-prefix="))) { - arguments->tb_prefix = (char *)(argv[i] + strlen("--table-prefix=")); - } else if (0 == strncmp(argv[i], "-m", strlen("-m"))) { - arguments->tb_prefix = (char *)(argv[i] + strlen("-m")); - } else if (strlen("--table-prefix") == strlen(argv[i])) { - if (argc == i+1) { - errorPrintReqArg3(argv[0], "--table-prefix"); - exit(EXIT_FAILURE); - } - arguments->tb_prefix = argv[++i]; - } else { - errorUnrecognized(argv[0], argv[i]); - exit(EXIT_FAILURE); - } - } else if ((0 == strncmp(argv[i], "-E", strlen("-E"))) - || (0 == strncmp(argv[i], "--escape-character", strlen("--escape-character")))) { - arguments->escapeChar = true; - } else if ((strcmp(argv[i], "-N") == 0) - || (0 == strcmp(argv[i], "--normal-table"))) { - arguments->demo_mode = false; - arguments->use_metric = false; - } else if ((strcmp(argv[i], "-M") == 0) - || (0 == strcmp(argv[i], "--random"))) { - arguments->demo_mode = false; - } else if ((strcmp(argv[i], "-x") == 0) - || (0 == strcmp(argv[i], "--aggr-func"))) { - arguments->aggr_func = true; - } else if ((strcmp(argv[i], "-y") == 0) - || (0 == strcmp(argv[i], "--answer-yes"))) { - arguments->answer_yes = true; - } else if ((strcmp(argv[i], "-g") == 0) - || (0 == strcmp(argv[i], "--debug"))) { - arguments->debug_print = true; - } else if (strcmp(argv[i], "-gg") == 0) { - arguments->verbose_print = true; - } else if ((0 == strncmp(argv[i], "-R", strlen("-R"))) - || (0 == strncmp(argv[i], "--disorder-range", - strlen("--disorder-range")))) { - if (strlen("-R") == strlen(argv[i])) { - if (argc == i+1) { - errorPrintReqArg(argv[0], "R"); - exit(EXIT_FAILURE); - } else if (!isStringNumber(argv[i+1])) { - errorPrintReqArg2(argv[0], "R"); - exit(EXIT_FAILURE); - } - arguments->disorderRange = atoi(argv[++i]); - } else if (0 == strncmp(argv[i], "--disorder-range=", - strlen("--disorder-range="))) { - if (isStringNumber((char *)(argv[i] + strlen("--disorder-range=")))) { - arguments->disorderRange = - atoi((char *)(argv[i]+strlen("--disorder-range="))); - } else { - errorPrintReqArg2(argv[0], "--disorder-range"); - exit(EXIT_FAILURE); - } - } else if (0 == strncmp(argv[i], "-R", strlen("-R"))) { - if (isStringNumber((char *)(argv[i] + strlen("-R")))) { - arguments->disorderRange = - atoi((char *)(argv[i]+strlen("-R"))); - } else { - errorPrintReqArg2(argv[0], "-R"); - exit(EXIT_FAILURE); - } - - if (arguments->disorderRange < 0) { - errorPrint("Invalid disorder range %d, will be set to %d\n", - arguments->disorderRange, 1000); - arguments->disorderRange = 1000; - } - } else if (strlen("--disorder-range") == strlen(argv[i])) { - if (argc == i+1) { - errorPrintReqArg3(argv[0], "--disorder-range"); - exit(EXIT_FAILURE); - } else if (!isStringNumber(argv[i+1])) { - errorPrintReqArg2(argv[0], "--disorder-range"); - exit(EXIT_FAILURE); - } - arguments->disorderRange = atoi(argv[++i]); - } else { - errorUnrecognized(argv[0], argv[i]); - exit(EXIT_FAILURE); - } - } else if ((0 == strncmp(argv[i], "-O", strlen("-O"))) - || (0 == strncmp(argv[i], "--disorder", strlen("--disorder")))) { - if (2 == strlen(argv[i])) { - if (argc == i+1) { - errorPrintReqArg(argv[0], "O"); - exit(EXIT_FAILURE); - } else if (!isStringNumber(argv[i+1])) { - errorPrintReqArg2(argv[0], "O"); - exit(EXIT_FAILURE); - } - arguments->disorderRatio = atoi(argv[++i]); - } else if (0 == strncmp(argv[i], "--disorder=", strlen("--disorder="))) { - if (isStringNumber((char *)(argv[i] + strlen("--disorder=")))) { - arguments->disorderRatio = atoi((char *)(argv[i]+strlen("--disorder="))); - } else { - errorPrintReqArg2(argv[0], "--disorder"); - exit(EXIT_FAILURE); - } - } else if (0 == strncmp(argv[i], "-O", strlen("-O"))) { - if (isStringNumber((char *)(argv[i] + strlen("-O")))) { - arguments->disorderRatio = atoi((char *)(argv[i]+strlen("-O"))); - } else { - errorPrintReqArg2(argv[0], "-O"); - exit(EXIT_FAILURE); - } - } else if (strlen("--disorder") == strlen(argv[i])) { - if (argc == i+1) { - errorPrintReqArg3(argv[0], "--disorder"); - exit(EXIT_FAILURE); - } else if (!isStringNumber(argv[i+1])) { - errorPrintReqArg2(argv[0], "--disorder"); - exit(EXIT_FAILURE); - } - arguments->disorderRatio = atoi(argv[++i]); - } else { - errorUnrecognized(argv[0], argv[i]); - exit(EXIT_FAILURE); - } - - if (arguments->disorderRatio > 50) { - errorPrint("Invalid disorder ratio %d, will be set to %d\n", - arguments->disorderRatio, 50); - arguments->disorderRatio = 50; - } - } else if ((0 == strncmp(argv[i], "-a", strlen("-a"))) - || (0 == strncmp(argv[i], "--replica", - strlen("--replica")))) { - if (2 == strlen(argv[i])) { - if (argc == i+1) { - errorPrintReqArg(argv[0], "a"); - exit(EXIT_FAILURE); - } else if (!isStringNumber(argv[i+1])) { - errorPrintReqArg2(argv[0], "a"); - exit(EXIT_FAILURE); - } - arguments->replica = atoi(argv[++i]); - } else if (0 == strncmp(argv[i], "--replica=", - strlen("--replica="))) { - if (isStringNumber((char *)(argv[i] + strlen("--replica=")))) { - arguments->replica = - atoi((char *)(argv[i]+strlen("--replica="))); - } else { - errorPrintReqArg2(argv[0], "--replica"); - exit(EXIT_FAILURE); - } - } else if (0 == strncmp(argv[i], "-a", strlen("-a"))) { - if (isStringNumber((char *)(argv[i] + strlen("-a")))) { - arguments->replica = - atoi((char *)(argv[i]+strlen("-a"))); - } else { - errorPrintReqArg2(argv[0], "-a"); - exit(EXIT_FAILURE); - } - } else if (strlen("--replica") == strlen(argv[i])) { - if (argc == i+1) { - errorPrintReqArg3(argv[0], "--replica"); - exit(EXIT_FAILURE); - } else if (!isStringNumber(argv[i+1])) { - errorPrintReqArg2(argv[0], "--replica"); - exit(EXIT_FAILURE); - } - arguments->replica = atoi(argv[++i]); - } else { - errorUnrecognized(argv[0], argv[i]); - exit(EXIT_FAILURE); - } - - if (arguments->replica > 3 || arguments->replica < 1) { - errorPrint("Invalid replica value %d, will be set to %d\n", - arguments->replica, 1); - arguments->replica = 1; - } - } else if (strcmp(argv[i], "-D") == 0) { - arguments->method_of_delete = atoi(argv[++i]); - if (arguments->method_of_delete > 3) { - errorPrint("%s", "\n\t-D need a value (0~3) number following!\n"); - exit(EXIT_FAILURE); - } - } else if ((strcmp(argv[i], "--version") == 0) - || (strcmp(argv[i], "-V") == 0)) { - printVersion(); - exit(0); - } else if ((strcmp(argv[i], "--help") == 0) - || (strcmp(argv[i], "-?") == 0)) { - printHelp(); - exit(0); - } else if (strcmp(argv[i], "--usage") == 0) { - printf(" Usage: taosdemo [-f JSONFILE] [-u USER] [-p PASSWORD] [-c CONFIG_DIR]\n\ - [-h HOST] [-P PORT] [-I INTERFACE] [-d DATABASE] [-a REPLICA]\n\ - [-m TABLEPREFIX] [-s SQLFILE] [-N] [-o OUTPUTFILE] [-q QUERYMODE]\n\ - [-b DATATYPES] [-w WIDTH_OF_BINARY] [-l COLUMNS] [-T THREADNUMBER]\n\ - [-i SLEEPTIME] [-S TIME_STEP] [-B INTERLACE_ROWS] [-t TABLES]\n\ - [-n RECORDS] [-M] [-x] [-y] [-O ORDERMODE] [-R RANGE] [-a REPLIcA][-g]\n\ - [--help] [--usage] [--version]\n"); - exit(0); - } else { - // to simulate argp_option output - if (strlen(argv[i]) > 2) { - if (0 == strncmp(argv[i], "--", 2)) { - fprintf(stderr, "%s: unrecognized options '%s'\n", argv[0], argv[i]); - } else if (0 == strncmp(argv[i], "-", 1)) { - char tmp[2] = {0}; - tstrncpy(tmp, argv[i]+1, 2); - fprintf(stderr, "%s: invalid options -- '%s'\n", argv[0], tmp); - } else { - fprintf(stderr, "%s: Too many arguments\n", argv[0]); - } - } else { - fprintf(stderr, "%s invalid options -- '%s'\n", argv[0], - (char *)((char *)argv[i])+1); - } - fprintf(stderr, "Try `taosdemo --help' or `taosdemo --usage' for more information.\n"); - exit(EXIT_FAILURE); - } - } - - int columnCount; - for (columnCount = 0; columnCount < MAX_NUM_COLUMNS; columnCount ++) { - if (g_args.dataType[columnCount] == NULL) { - break; - } - } - - if (0 == columnCount) { - ERROR_EXIT("data type error!"); - } - g_args.columnCount = columnCount; - - g_args.lenOfOneRow = TIMESTAMP_BUFF_LEN; // timestamp - for (int c = 0; c < g_args.columnCount; c++) { - switch(g_args.data_type[c]) { - case TSDB_DATA_TYPE_BINARY: - g_args.lenOfOneRow += g_args.binwidth + 3; - break; - - case TSDB_DATA_TYPE_NCHAR: - g_args.lenOfOneRow += g_args.binwidth + 3; - break; - - case TSDB_DATA_TYPE_INT: - case TSDB_DATA_TYPE_UINT: - g_args.lenOfOneRow += INT_BUFF_LEN; - break; - - case TSDB_DATA_TYPE_BIGINT: - case TSDB_DATA_TYPE_UBIGINT: - g_args.lenOfOneRow += BIGINT_BUFF_LEN; - break; - - case TSDB_DATA_TYPE_SMALLINT: - case TSDB_DATA_TYPE_USMALLINT: - g_args.lenOfOneRow += SMALLINT_BUFF_LEN; - break; - - case TSDB_DATA_TYPE_TINYINT: - case TSDB_DATA_TYPE_UTINYINT: - g_args.lenOfOneRow += TINYINT_BUFF_LEN; - break; - - case TSDB_DATA_TYPE_BOOL: - g_args.lenOfOneRow += BOOL_BUFF_LEN; - break; - - case TSDB_DATA_TYPE_FLOAT: - g_args.lenOfOneRow += FLOAT_BUFF_LEN; - break; - - case TSDB_DATA_TYPE_DOUBLE: - g_args.lenOfOneRow += DOUBLE_BUFF_LEN; - break; - - case TSDB_DATA_TYPE_TIMESTAMP: - g_args.lenOfOneRow += TIMESTAMP_BUFF_LEN; - break; - - default: - errorPrint2("get error data type : %s\n", g_args.dataType[c]); - exit(EXIT_FAILURE); - } - } - - if (((arguments->debug_print) && (NULL != arguments->metaFile)) - || arguments->verbose_print) { - printf("###################################################################\n"); - printf("# meta file: %s\n", arguments->metaFile); - printf("# Server IP: %s:%hu\n", - arguments->host == NULL ? "localhost" : arguments->host, - arguments->port ); - printf("# User: %s\n", arguments->user); - printf("# Password: %s\n", arguments->password); - printf("# Use metric: %s\n", - arguments->use_metric ? "true" : "false"); - if (*(arguments->dataType)) { - printf("# Specified data type: "); - for (int c = 0; c < MAX_NUM_COLUMNS; c++) - if (arguments->dataType[c]) - printf("%s,", arguments->dataType[c]); - else - break; - printf("\n"); - } - printf("# Insertion interval: %"PRIu64"\n", - arguments->insert_interval); - printf("# Number of records per req: %u\n", - arguments->reqPerReq); - printf("# Max SQL length: %"PRIu64"\n", - arguments->max_sql_len); - printf("# Length of Binary: %d\n", arguments->binwidth); - printf("# Number of Threads: %d\n", arguments->nthreads); - printf("# Number of Tables: %"PRId64"\n", - arguments->ntables); - printf("# Number of Data per Table: %"PRId64"\n", - arguments->insertRows); - printf("# Database name: %s\n", arguments->database); - printf("# Table prefix: %s\n", arguments->tb_prefix); - if (arguments->disorderRatio) { - printf("# Data order: %d\n", arguments->disorderRatio); - printf("# Data out of order rate: %d\n", arguments->disorderRange); - } - printf("# Delete method: %d\n", arguments->method_of_delete); - printf("# Answer yes when prompt: %d\n", arguments->answer_yes); - printf("# Print debug info: %d\n", arguments->debug_print); - printf("# Print verbose info: %d\n", arguments->verbose_print); - printf("###################################################################\n"); - - prompt(); - } -} - -static void tmfclose(FILE *fp) { - if (NULL != fp) { - fclose(fp); - } -} - -static void tmfree(void *buf) { - if (NULL != buf) { - free(buf); - buf = NULL; - } -} - -static int queryDbExec(TAOS *taos, char *command, QUERY_TYPE type, bool quiet) { - - verbosePrint("%s() LN%d - command: %s\n", __func__, __LINE__, command); - - TAOS_RES *res = taos_query(taos, command); - int32_t code = taos_errno(res); - - if (code != 0) { - if (!quiet) { - errorPrint2("Failed to execute <%s>, reason: %s\n", - command, taos_errstr(res)); - } - taos_free_result(res); - //taos_close(taos); - return -1; - } - - if (INSERT_TYPE == type) { - int affectedRows = taos_affected_rows(res); - taos_free_result(res); - return affectedRows; - } - - taos_free_result(res); - return 0; -} - -static void appendResultBufToFile(char *resultBuf, threadInfo *pThreadInfo) -{ - pThreadInfo->fp = fopen(pThreadInfo->filePath, "at"); - if (pThreadInfo->fp == NULL) { - errorPrint2( - "%s() LN%d, failed to open result file: %s, result will not save to file\n", - __func__, __LINE__, pThreadInfo->filePath); - return; - } - - fprintf(pThreadInfo->fp, "%s", resultBuf); - tmfclose(pThreadInfo->fp); - pThreadInfo->fp = NULL; -} - -static void fetchResult(TAOS_RES *res, threadInfo* pThreadInfo) { - TAOS_ROW row = NULL; - int num_rows = 0; - int num_fields = taos_field_count(res); - TAOS_FIELD *fields = taos_fetch_fields(res); - - char* databuf = (char*) calloc(1, FETCH_BUFFER_SIZE); - if (databuf == NULL) { - errorPrint2("%s() LN%d, failed to malloc, warning: save result to file slowly!\n", - __func__, __LINE__); - return ; - } - - int64_t totalLen = 0; - - // fetch the records row by row - while((row = taos_fetch_row(res))) { - if (totalLen >= (FETCH_BUFFER_SIZE - HEAD_BUFF_LEN*2)) { - if (strlen(pThreadInfo->filePath) > 0) - appendResultBufToFile(databuf, pThreadInfo); - totalLen = 0; - memset(databuf, 0, FETCH_BUFFER_SIZE); - } - num_rows++; - char temp[HEAD_BUFF_LEN] = {0}; - int len = taos_print_row(temp, row, fields, num_fields); - len += sprintf(temp + len, "\n"); - //printf("query result:%s\n", temp); - memcpy(databuf + totalLen, temp, len); - totalLen += len; - verbosePrint("%s() LN%d, totalLen: %"PRId64"\n", - __func__, __LINE__, totalLen); - } - - verbosePrint("%s() LN%d, databuf=%s resultFile=%s\n", - __func__, __LINE__, databuf, pThreadInfo->filePath); - if (strlen(pThreadInfo->filePath) > 0) { - appendResultBufToFile(databuf, pThreadInfo); - } - free(databuf); -} - -static void selectAndGetResult( - threadInfo *pThreadInfo, char *command) -{ - if (0 == strncasecmp(g_queryInfo.queryMode, "taosc", strlen("taosc"))) { - TAOS_RES *res = taos_query(pThreadInfo->taos, command); - if (res == NULL || taos_errno(res) != 0) { - errorPrint2("%s() LN%d, failed to execute sql:%s, reason:%s\n", - __func__, __LINE__, command, taos_errstr(res)); - taos_free_result(res); - return; - } - - fetchResult(res, pThreadInfo); - taos_free_result(res); - - } else if (0 == strncasecmp(g_queryInfo.queryMode, "rest", strlen("rest"))) { - int retCode = postProceSql( - g_queryInfo.host, g_queryInfo.port, - command, - pThreadInfo); - if (0 != retCode) { - printf("====restful return fail, threadID[%d]\n", pThreadInfo->threadID); - } - - } else { - errorPrint2("%s() LN%d, unknown query mode: %s\n", - __func__, __LINE__, g_queryInfo.queryMode); - } -} - -static char *rand_bool_str() { - static int cursor; - cursor++; - if (cursor > (g_args.prepared_rand - 1)) cursor = 0; - return g_randbool_buff + ((cursor % g_args.prepared_rand) * BOOL_BUFF_LEN); -} - -static int32_t rand_bool() { - static int cursor; - cursor++; - if (cursor > (g_args.prepared_rand - 1)) cursor = 0; - return g_randint[cursor % g_args.prepared_rand] % TSDB_DATA_BOOL_NULL; -} - -static char *rand_tinyint_str() -{ - static int cursor; - cursor++; - if (cursor > (g_args.prepared_rand - 1)) cursor = 0; - return g_randtinyint_buff + - ((cursor % g_args.prepared_rand) * TINYINT_BUFF_LEN); -} - -static int32_t rand_tinyint() -{ - static int cursor; - cursor++; - if (cursor > (g_args.prepared_rand - 1)) cursor = 0; - return g_randint[cursor % g_args.prepared_rand] % TSDB_DATA_TINYINT_NULL; -} - -static char *rand_utinyint_str() -{ - static int cursor; - cursor++; - if (cursor > (g_args.prepared_rand - 1)) cursor = 0; - return g_randutinyint_buff + - ((cursor % g_args.prepared_rand) * TINYINT_BUFF_LEN); -} - -static int32_t rand_utinyint() -{ - static int cursor; - cursor++; - if (cursor > (g_args.prepared_rand - 1)) cursor = 0; - return g_randuint[cursor % g_args.prepared_rand] % TSDB_DATA_UTINYINT_NULL; -} - -static char *rand_smallint_str() -{ - static int cursor; - cursor++; - if (cursor > (g_args.prepared_rand - 1)) cursor = 0; - return g_randsmallint_buff + - ((cursor % g_args.prepared_rand) * SMALLINT_BUFF_LEN); -} - -static int32_t rand_smallint() -{ - static int cursor; - cursor++; - if (cursor > (g_args.prepared_rand - 1)) cursor = 0; - return g_randint[cursor % g_args.prepared_rand] % TSDB_DATA_SMALLINT_NULL; -} - -static char *rand_usmallint_str() -{ - static int cursor; - cursor++; - if (cursor > (g_args.prepared_rand - 1)) cursor = 0; - return g_randusmallint_buff + - ((cursor % g_args.prepared_rand) * SMALLINT_BUFF_LEN); -} - -static int32_t rand_usmallint() -{ - static int cursor; - cursor++; - if (cursor > (g_args.prepared_rand - 1)) cursor = 0; - return g_randuint[cursor % g_args.prepared_rand] % TSDB_DATA_USMALLINT_NULL; -} - -static char *rand_int_str() -{ - static int cursor; - cursor++; - if (cursor > (g_args.prepared_rand - 1)) cursor = 0; - return g_randint_buff + ((cursor % g_args.prepared_rand) * INT_BUFF_LEN); -} - -static int32_t rand_int() -{ - static int cursor; - cursor++; - if (cursor > (g_args.prepared_rand - 1)) cursor = 0; - return g_randint[cursor % g_args.prepared_rand]; -} - -static char *rand_uint_str() -{ - static int cursor; - cursor++; - if (cursor > (g_args.prepared_rand - 1)) cursor = 0; - return g_randuint_buff + ((cursor % g_args.prepared_rand) * INT_BUFF_LEN); -} - -static int32_t rand_uint() -{ - static int cursor; - cursor++; - if (cursor > (g_args.prepared_rand - 1)) cursor = 0; - return g_randuint[cursor % g_args.prepared_rand]; -} - -static char *rand_bigint_str() -{ - static int cursor; - cursor++; - if (cursor > (g_args.prepared_rand - 1)) cursor = 0; - return g_randbigint_buff + - ((cursor % g_args.prepared_rand) * BIGINT_BUFF_LEN); -} - -static int64_t rand_bigint() -{ - static int cursor; - cursor++; - if (cursor > (g_args.prepared_rand - 1)) cursor = 0; - return g_randbigint[cursor % g_args.prepared_rand]; -} - -static char *rand_ubigint_str() -{ - static int cursor; - cursor++; - if (cursor > (g_args.prepared_rand - 1)) cursor = 0; - return g_randubigint_buff + - ((cursor % g_args.prepared_rand) * BIGINT_BUFF_LEN); -} - -static int64_t rand_ubigint() -{ - static int cursor; - cursor++; - if (cursor > (g_args.prepared_rand - 1)) cursor = 0; - return g_randubigint[cursor % g_args.prepared_rand]; -} - -static char *rand_float_str() -{ - static int cursor; - cursor++; - if (cursor > (g_args.prepared_rand - 1)) cursor = 0; - return g_randfloat_buff + ((cursor % g_args.prepared_rand) * FLOAT_BUFF_LEN); -} - - -static float rand_float() -{ - static int cursor; - cursor++; - if (cursor > (g_args.prepared_rand - 1)) cursor = 0; - return g_randfloat[cursor % g_args.prepared_rand]; -} - -static char *demo_current_float_str() -{ - static int cursor; - cursor++; - if (cursor > (g_args.prepared_rand - 1)) cursor = 0; - return g_rand_current_buff + - ((cursor % g_args.prepared_rand) * FLOAT_BUFF_LEN); -} - -static float UNUSED_FUNC demo_current_float() -{ - static int cursor; - cursor++; - if (cursor > (g_args.prepared_rand - 1)) cursor = 0; - return (float)(9.8 + 0.04 * (g_randint[cursor % g_args.prepared_rand] % 10) - + g_randfloat[cursor % g_args.prepared_rand]/1000000000); -} - -static char *demo_voltage_int_str() -{ - static int cursor; - cursor++; - if (cursor > (g_args.prepared_rand - 1)) cursor = 0; - return g_rand_voltage_buff + - ((cursor % g_args.prepared_rand) * INT_BUFF_LEN); -} - -static int32_t UNUSED_FUNC demo_voltage_int() -{ - static int cursor; - cursor++; - if (cursor > (g_args.prepared_rand - 1)) cursor = 0; - return 215 + g_randint[cursor % g_args.prepared_rand] % 10; -} - -static char *demo_phase_float_str() { - static int cursor; - cursor++; - if (cursor > (g_args.prepared_rand - 1)) cursor = 0; - return g_rand_phase_buff + ((cursor % g_args.prepared_rand) * FLOAT_BUFF_LEN); -} - -static float UNUSED_FUNC demo_phase_float() { - static int cursor; - cursor++; - if (cursor > (g_args.prepared_rand - 1)) cursor = 0; - return (float)((115 + g_randint[cursor % g_args.prepared_rand] % 10 - + g_randfloat[cursor % g_args.prepared_rand]/1000000000)/360); -} - -#if 0 -static const char charNum[] = "0123456789"; - -static void nonrand_string(char *, int) __attribute__ ((unused)); // reserve for debugging purpose -static void nonrand_string(char *str, int size) -{ - str[0] = 0; - if (size > 0) { - int n; - for (n = 0; n < size; n++) { - str[n] = charNum[n % 10]; - } - str[n] = 0; - } -} -#endif - -static const char charset[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"; - -static void rand_string(char *str, int size) { - str[0] = 0; - if (size > 0) { - //--size; - int n; - for (n = 0; n < size; n++) { - int key = abs(taosRandom()) % (int)(sizeof(charset) - 1); - str[n] = charset[key]; - } - str[n] = 0; - } -} - -static char *rand_double_str() -{ - static int cursor; - cursor++; - if (cursor > (g_args.prepared_rand - 1)) cursor = 0; - return g_randdouble_buff + (cursor * DOUBLE_BUFF_LEN); -} - -static double rand_double() -{ - static int cursor; - cursor++; - cursor = cursor % g_args.prepared_rand; - return g_randdouble[cursor]; -} - -static void init_rand_data() { - - g_randint_buff = calloc(1, INT_BUFF_LEN * g_args.prepared_rand); - assert(g_randint_buff); - g_rand_voltage_buff = calloc(1, INT_BUFF_LEN * g_args.prepared_rand); - assert(g_rand_voltage_buff); - g_randbigint_buff = calloc(1, BIGINT_BUFF_LEN * g_args.prepared_rand); - assert(g_randbigint_buff); - g_randsmallint_buff = calloc(1, SMALLINT_BUFF_LEN * g_args.prepared_rand); - assert(g_randsmallint_buff); - g_randtinyint_buff = calloc(1, TINYINT_BUFF_LEN * g_args.prepared_rand); - assert(g_randtinyint_buff); - g_randbool_buff = calloc(1, BOOL_BUFF_LEN * g_args.prepared_rand); - assert(g_randbool_buff); - g_randfloat_buff = calloc(1, FLOAT_BUFF_LEN * g_args.prepared_rand); - assert(g_randfloat_buff); - g_rand_current_buff = calloc(1, FLOAT_BUFF_LEN * g_args.prepared_rand); - assert(g_rand_current_buff); - g_rand_phase_buff = calloc(1, FLOAT_BUFF_LEN * g_args.prepared_rand); - assert(g_rand_phase_buff); - g_randdouble_buff = calloc(1, DOUBLE_BUFF_LEN * g_args.prepared_rand); - assert(g_randdouble_buff); - g_randuint_buff = calloc(1, INT_BUFF_LEN * g_args.prepared_rand); - assert(g_randuint_buff); - g_randutinyint_buff = calloc(1, TINYINT_BUFF_LEN * g_args.prepared_rand); - assert(g_randutinyint_buff); - g_randusmallint_buff = calloc(1, SMALLINT_BUFF_LEN * g_args.prepared_rand); - assert(g_randusmallint_buff); - g_randubigint_buff = calloc(1, BIGINT_BUFF_LEN * g_args.prepared_rand); - assert(g_randubigint_buff); - g_randint = calloc(1, sizeof(int32_t) * g_args.prepared_rand); - assert(g_randint); - g_randuint = calloc(1, sizeof(uint32_t) * g_args.prepared_rand); - assert(g_randuint); - g_randbigint = calloc(1, sizeof(int64_t) * g_args.prepared_rand); - assert(g_randbigint); - g_randubigint = calloc(1, sizeof(uint64_t) * g_args.prepared_rand); - assert(g_randubigint); - g_randfloat = calloc(1, sizeof(float) * g_args.prepared_rand); - assert(g_randfloat); - g_randdouble = calloc(1, sizeof(double) * g_args.prepared_rand); - assert(g_randdouble); - - for (int i = 0; i < g_args.prepared_rand; i++) { - g_randint[i] = (int)(taosRandom() % RAND_MAX - (RAND_MAX >> 1)); - g_randuint[i] = (int)(taosRandom()); - sprintf(g_randint_buff + i * INT_BUFF_LEN, "%d", - g_randint[i]); - sprintf(g_rand_voltage_buff + i * INT_BUFF_LEN, "%d", - 215 + g_randint[i] % 10); - - sprintf(g_randbool_buff + i * BOOL_BUFF_LEN, "%s", - ((g_randint[i] % 2) & 1)?"true":"false"); - sprintf(g_randsmallint_buff + i * SMALLINT_BUFF_LEN, "%d", - g_randint[i] % 32768); - sprintf(g_randtinyint_buff + i * TINYINT_BUFF_LEN, "%d", - g_randint[i] % 128); - sprintf(g_randuint_buff + i * INT_BUFF_LEN, "%d", - g_randuint[i]); - sprintf(g_randusmallint_buff + i * SMALLINT_BUFF_LEN, "%d", - g_randuint[i] % 65535); - sprintf(g_randutinyint_buff + i * TINYINT_BUFF_LEN, "%d", - g_randuint[i] % 255); - - g_randbigint[i] = (int64_t)(taosRandom() % RAND_MAX - (RAND_MAX >> 1)); - g_randubigint[i] = (uint64_t)(taosRandom()); - sprintf(g_randbigint_buff + i * BIGINT_BUFF_LEN, "%"PRId64"", - g_randbigint[i]); - sprintf(g_randubigint_buff + i * BIGINT_BUFF_LEN, "%"PRId64"", - g_randubigint[i]); - - g_randfloat[i] = (float)(taosRandom() / 1000.0) * (taosRandom() % 2 > 0.5 ? 1 : -1); - sprintf(g_randfloat_buff + i * FLOAT_BUFF_LEN, "%f", - g_randfloat[i]); - sprintf(g_rand_current_buff + i * FLOAT_BUFF_LEN, "%f", - (float)(9.8 + 0.04 * (g_randint[i] % 10) - + g_randfloat[i]/1000000000)); - sprintf(g_rand_phase_buff + i * FLOAT_BUFF_LEN, "%f", - (float)((115 + g_randint[i] % 10 - + g_randfloat[i]/1000000000)/360)); - - g_randdouble[i] = (double)(taosRandom() / 1000000.0) * (taosRandom() % 2 > 0.5 ? 1 : -1); - sprintf(g_randdouble_buff + i * DOUBLE_BUFF_LEN, "%f", - g_randdouble[i]); - } -} - -#define SHOW_PARSE_RESULT_START() \ - do { if (g_args.metaFile) \ - printf("\033[1m\033[40;32m================ %s parse result START ================\033[0m\n", \ - g_args.metaFile); } while(0) - -#define SHOW_PARSE_RESULT_END() \ - do { if (g_args.metaFile) \ - printf("\033[1m\033[40;32m================ %s parse result END================\033[0m\n", \ - g_args.metaFile); } while(0) - -#define SHOW_PARSE_RESULT_START_TO_FILE(fp) \ - do { if (g_args.metaFile) \ - fprintf(fp, "\033[1m\033[40;32m================ %s parse result START ================\033[0m\n", \ - g_args.metaFile); } while(0) - -#define SHOW_PARSE_RESULT_END_TO_FILE(fp) \ - do { if (g_args.metaFile) \ - fprintf(fp, "\033[1m\033[40;32m================ %s parse result END================\033[0m\n", \ - g_args.metaFile); } while(0) - -static int printfInsertMeta() { - SHOW_PARSE_RESULT_START(); - - if (g_args.demo_mode) { - printf("\ntaosdemo is simulating data generated by power equipment monitoring...\n\n"); - } else { - printf("\ntaosdemo is simulating random data as you request..\n\n"); - } - - if (g_args.iface != INTERFACE_BUT) { - // first time if no iface specified - printf("interface: \033[33m%s\033[0m\n", - (g_args.iface==TAOSC_IFACE)?"taosc": - (g_args.iface==REST_IFACE)?"rest": - (g_args.iface==STMT_IFACE)?"stmt":"sml"); - } - - printf("host: \033[33m%s:%u\033[0m\n", - g_Dbs.host, g_Dbs.port); - printf("user: \033[33m%s\033[0m\n", g_Dbs.user); - printf("password: \033[33m%s\033[0m\n", g_Dbs.password); - printf("configDir: \033[33m%s\033[0m\n", configDir); - printf("resultFile: \033[33m%s\033[0m\n", g_Dbs.resultFile); - printf("thread num of insert data: \033[33m%d\033[0m\n", g_Dbs.threadCount); - printf("thread num of create table: \033[33m%d\033[0m\n", - g_Dbs.threadCountForCreateTbl); - printf("top insert interval: \033[33m%"PRIu64"\033[0m\n", - g_args.insert_interval); - printf("number of records per req: \033[33m%u\033[0m\n", - g_args.reqPerReq); - printf("max sql length: \033[33m%"PRIu64"\033[0m\n", - g_args.max_sql_len); - - printf("database count: \033[33m%d\033[0m\n", g_Dbs.dbCount); - - for (int i = 0; i < g_Dbs.dbCount; i++) { - printf("database[\033[33m%d\033[0m]:\n", i); - printf(" database[%d] name: \033[33m%s\033[0m\n", - i, g_Dbs.db[i].dbName); - if (0 == g_Dbs.db[i].drop) { - printf(" drop: \033[33m no\033[0m\n"); - } else { - printf(" drop: \033[33m yes\033[0m\n"); - } - - if (g_Dbs.db[i].dbCfg.blocks > 0) { - printf(" blocks: \033[33m%d\033[0m\n", - g_Dbs.db[i].dbCfg.blocks); - } - if (g_Dbs.db[i].dbCfg.cache > 0) { - printf(" cache: \033[33m%d\033[0m\n", - g_Dbs.db[i].dbCfg.cache); - } - if (g_Dbs.db[i].dbCfg.days > 0) { - printf(" days: \033[33m%d\033[0m\n", - g_Dbs.db[i].dbCfg.days); - } - if (g_Dbs.db[i].dbCfg.keep > 0) { - printf(" keep: \033[33m%d\033[0m\n", - g_Dbs.db[i].dbCfg.keep); - } - if (g_Dbs.db[i].dbCfg.replica > 0) { - printf(" replica: \033[33m%d\033[0m\n", - g_Dbs.db[i].dbCfg.replica); - } - if (g_Dbs.db[i].dbCfg.update > 0) { - printf(" update: \033[33m%d\033[0m\n", - g_Dbs.db[i].dbCfg.update); - } - if (g_Dbs.db[i].dbCfg.minRows > 0) { - printf(" minRows: \033[33m%d\033[0m\n", - g_Dbs.db[i].dbCfg.minRows); - } - if (g_Dbs.db[i].dbCfg.maxRows > 0) { - printf(" maxRows: \033[33m%d\033[0m\n", - g_Dbs.db[i].dbCfg.maxRows); - } - if (g_Dbs.db[i].dbCfg.comp > 0) { - printf(" comp: \033[33m%d\033[0m\n", g_Dbs.db[i].dbCfg.comp); - } - if (g_Dbs.db[i].dbCfg.walLevel > 0) { - printf(" walLevel: \033[33m%d\033[0m\n", - g_Dbs.db[i].dbCfg.walLevel); - } - if (g_Dbs.db[i].dbCfg.fsync > 0) { - printf(" fsync: \033[33m%d\033[0m\n", - g_Dbs.db[i].dbCfg.fsync); - } - if (g_Dbs.db[i].dbCfg.quorum > 0) { - printf(" quorum: \033[33m%d\033[0m\n", - g_Dbs.db[i].dbCfg.quorum); - } - if (g_Dbs.db[i].dbCfg.precision[0] != 0) { - if ((0 == strncasecmp(g_Dbs.db[i].dbCfg.precision, "ms", 2)) - || (0 == strncasecmp(g_Dbs.db[i].dbCfg.precision, "us", 2)) - || (0 == strncasecmp(g_Dbs.db[i].dbCfg.precision, "ns", 2))) { - printf(" precision: \033[33m%s\033[0m\n", - g_Dbs.db[i].dbCfg.precision); - } else { - printf("\033[1m\033[40;31m precision error: %s\033[0m\n", - g_Dbs.db[i].dbCfg.precision); - return -1; - } - } - - - if (g_args.use_metric) { - printf(" super table count: \033[33m%"PRIu64"\033[0m\n", - g_Dbs.db[i].superTblCount); - for (uint64_t j = 0; j < g_Dbs.db[i].superTblCount; j++) { - printf(" super table[\033[33m%"PRIu64"\033[0m]:\n", j); - - printf(" stbName: \033[33m%s\033[0m\n", - g_Dbs.db[i].superTbls[j].stbName); - - if (PRE_CREATE_SUBTBL == g_Dbs.db[i].superTbls[j].autoCreateTable) { - printf(" autoCreateTable: \033[33m%s\033[0m\n", "no"); - } else if (AUTO_CREATE_SUBTBL == - g_Dbs.db[i].superTbls[j].autoCreateTable) { - printf(" autoCreateTable: \033[33m%s\033[0m\n", "yes"); - } else { - printf(" autoCreateTable: \033[33m%s\033[0m\n", "error"); - } - - if (TBL_NO_EXISTS == g_Dbs.db[i].superTbls[j].childTblExists) { - printf(" childTblExists: \033[33m%s\033[0m\n", "no"); - } else if (TBL_ALREADY_EXISTS == g_Dbs.db[i].superTbls[j].childTblExists) { - printf(" childTblExists: \033[33m%s\033[0m\n", "yes"); - } else { - printf(" childTblExists: \033[33m%s\033[0m\n", "error"); - } - - printf(" childTblCount: \033[33m%"PRId64"\033[0m\n", - g_Dbs.db[i].superTbls[j].childTblCount); - printf(" childTblPrefix: \033[33m%s\033[0m\n", - g_Dbs.db[i].superTbls[j].childTblPrefix); - printf(" dataSource: \033[33m%s\033[0m\n", - g_Dbs.db[i].superTbls[j].dataSource); - printf(" iface: \033[33m%s\033[0m\n", - (g_Dbs.db[i].superTbls[j].iface==TAOSC_IFACE)?"taosc": - (g_Dbs.db[i].superTbls[j].iface==REST_IFACE)?"rest": - (g_Dbs.db[i].superTbls[j].iface==STMT_IFACE)?"stmt":"sml"); - if (g_Dbs.db[i].superTbls[j].childTblLimit > 0) { - printf(" childTblLimit: \033[33m%"PRId64"\033[0m\n", - g_Dbs.db[i].superTbls[j].childTblLimit); - } - if (g_Dbs.db[i].superTbls[j].childTblOffset > 0) { - printf(" childTblOffset: \033[33m%"PRIu64"\033[0m\n", - g_Dbs.db[i].superTbls[j].childTblOffset); - } - printf(" insertRows: \033[33m%"PRId64"\033[0m\n", - g_Dbs.db[i].superTbls[j].insertRows); - /* - if (0 == g_Dbs.db[i].superTbls[j].multiThreadWriteOneTbl) { - printf(" multiThreadWriteOneTbl: \033[33m no\033[0m\n"); - }else { - printf(" multiThreadWriteOneTbl: \033[33m yes\033[0m\n"); - } - */ - printf(" interlaceRows: \033[33m%u\033[0m\n", - g_Dbs.db[i].superTbls[j].interlaceRows); - - if (g_Dbs.db[i].superTbls[j].interlaceRows > 0) { - printf(" stable insert interval: \033[33m%"PRIu64"\033[0m\n", - g_Dbs.db[i].superTbls[j].insertInterval); - } - - printf(" disorderRange: \033[33m%d\033[0m\n", - g_Dbs.db[i].superTbls[j].disorderRange); - printf(" disorderRatio: \033[33m%d\033[0m\n", - g_Dbs.db[i].superTbls[j].disorderRatio); - printf(" maxSqlLen: \033[33m%"PRIu64"\033[0m\n", - g_Dbs.db[i].superTbls[j].maxSqlLen); - printf(" timeStampStep: \033[33m%"PRId64"\033[0m\n", - g_Dbs.db[i].superTbls[j].timeStampStep); - printf(" startTimestamp: \033[33m%s\033[0m\n", - g_Dbs.db[i].superTbls[j].startTimestamp); - printf(" sampleFormat: \033[33m%s\033[0m\n", - g_Dbs.db[i].superTbls[j].sampleFormat); - printf(" sampleFile: \033[33m%s\033[0m\n", - g_Dbs.db[i].superTbls[j].sampleFile); - printf(" useSampleTs: \033[33m%s\033[0m\n", - g_Dbs.db[i].superTbls[j].useSampleTs ? "yes (warning: disorderRange/disorderRatio is disabled)" : "no"); - printf(" tagsFile: \033[33m%s\033[0m\n", - g_Dbs.db[i].superTbls[j].tagsFile); - printf(" columnCount: \033[33m%d\033[0m\n ", - g_Dbs.db[i].superTbls[j].columnCount); - for (int k = 0; k < g_Dbs.db[i].superTbls[j].columnCount; k++) { - //printf("dataType:%s, dataLen:%d\t", g_Dbs.db[i].superTbls[j].columns[k].dataType, g_Dbs.db[i].superTbls[j].columns[k].dataLen); - if ((0 == strncasecmp(g_Dbs.db[i].superTbls[j].columns[k].dataType, - "binary", 6)) - || (0 == strncasecmp(g_Dbs.db[i].superTbls[j].columns[k].dataType, - "nchar", 5))) { - printf("column[%d]:\033[33m%s(%d)\033[0m ", k, - g_Dbs.db[i].superTbls[j].columns[k].dataType, - g_Dbs.db[i].superTbls[j].columns[k].dataLen); - } else { - printf("column[%d]:\033[33m%s\033[0m ", k, - g_Dbs.db[i].superTbls[j].columns[k].dataType); - } - } - printf("\n"); - - printf(" tagCount: \033[33m%d\033[0m\n ", - g_Dbs.db[i].superTbls[j].tagCount); - for (int k = 0; k < g_Dbs.db[i].superTbls[j].tagCount; k++) { - //printf("dataType:%s, dataLen:%d\t", g_Dbs.db[i].superTbls[j].tags[k].dataType, g_Dbs.db[i].superTbls[j].tags[k].dataLen); - if ((0 == strncasecmp(g_Dbs.db[i].superTbls[j].tags[k].dataType, - "binary", strlen("binary"))) - || (0 == strncasecmp(g_Dbs.db[i].superTbls[j].tags[k].dataType, - "nchar", strlen("nchar")))) { - printf("tag[%d]:\033[33m%s(%d)\033[0m ", k, - g_Dbs.db[i].superTbls[j].tags[k].dataType, - g_Dbs.db[i].superTbls[j].tags[k].dataLen); - } else { - printf("tag[%d]:\033[33m%s\033[0m ", k, - g_Dbs.db[i].superTbls[j].tags[k].dataType); - } - } - printf("\n"); - } - } else { - printf(" childTblCount: \033[33m%"PRId64"\033[0m\n", - g_args.ntables); - printf(" insertRows: \033[33m%"PRId64"\033[0m\n", - g_args.insertRows); - } - printf("\n"); - } - - SHOW_PARSE_RESULT_END(); - - return 0; -} - -static void printfInsertMetaToFile(FILE* fp) { - - SHOW_PARSE_RESULT_START_TO_FILE(fp); - - fprintf(fp, "host: %s:%u\n", g_Dbs.host, g_Dbs.port); - fprintf(fp, "user: %s\n", g_Dbs.user); - fprintf(fp, "configDir: %s\n", configDir); - fprintf(fp, "resultFile: %s\n", g_Dbs.resultFile); - fprintf(fp, "thread num of insert data: %d\n", g_Dbs.threadCount); - fprintf(fp, "thread num of create table: %d\n", g_Dbs.threadCountForCreateTbl); - fprintf(fp, "number of records per req: %u\n", g_args.reqPerReq); - fprintf(fp, "max sql length: %"PRIu64"\n", g_args.max_sql_len); - fprintf(fp, "database count: %d\n", g_Dbs.dbCount); - - for (int i = 0; i < g_Dbs.dbCount; i++) { - fprintf(fp, "database[%d]:\n", i); - fprintf(fp, " database[%d] name: %s\n", i, g_Dbs.db[i].dbName); - if (0 == g_Dbs.db[i].drop) { - fprintf(fp, " drop: no\n"); - }else { - fprintf(fp, " drop: yes\n"); - } - - if (g_Dbs.db[i].dbCfg.blocks > 0) { - fprintf(fp, " blocks: %d\n", g_Dbs.db[i].dbCfg.blocks); - } - if (g_Dbs.db[i].dbCfg.cache > 0) { - fprintf(fp, " cache: %d\n", g_Dbs.db[i].dbCfg.cache); - } - if (g_Dbs.db[i].dbCfg.days > 0) { - fprintf(fp, " days: %d\n", g_Dbs.db[i].dbCfg.days); - } - if (g_Dbs.db[i].dbCfg.keep > 0) { - fprintf(fp, " keep: %d\n", g_Dbs.db[i].dbCfg.keep); - } - if (g_Dbs.db[i].dbCfg.replica > 0) { - fprintf(fp, " replica: %d\n", g_Dbs.db[i].dbCfg.replica); - } - if (g_Dbs.db[i].dbCfg.update > 0) { - fprintf(fp, " update: %d\n", g_Dbs.db[i].dbCfg.update); - } - if (g_Dbs.db[i].dbCfg.minRows > 0) { - fprintf(fp, " minRows: %d\n", g_Dbs.db[i].dbCfg.minRows); - } - if (g_Dbs.db[i].dbCfg.maxRows > 0) { - fprintf(fp, " maxRows: %d\n", g_Dbs.db[i].dbCfg.maxRows); - } - if (g_Dbs.db[i].dbCfg.comp > 0) { - fprintf(fp, " comp: %d\n", g_Dbs.db[i].dbCfg.comp); - } - if (g_Dbs.db[i].dbCfg.walLevel > 0) { - fprintf(fp, " walLevel: %d\n", g_Dbs.db[i].dbCfg.walLevel); - } - if (g_Dbs.db[i].dbCfg.fsync > 0) { - fprintf(fp, " fsync: %d\n", g_Dbs.db[i].dbCfg.fsync); - } - if (g_Dbs.db[i].dbCfg.quorum > 0) { - fprintf(fp, " quorum: %d\n", g_Dbs.db[i].dbCfg.quorum); - } - if (g_Dbs.db[i].dbCfg.precision[0] != 0) { - if ((0 == strncasecmp(g_Dbs.db[i].dbCfg.precision, "ms", 2)) - || (0 == strncasecmp(g_Dbs.db[i].dbCfg.precision, "ns", 2)) - || (0 == strncasecmp(g_Dbs.db[i].dbCfg.precision, "us", 2))) { - fprintf(fp, " precision: %s\n", - g_Dbs.db[i].dbCfg.precision); - } else { - fprintf(fp, " precision error: %s\n", - g_Dbs.db[i].dbCfg.precision); - } - } - - fprintf(fp, " super table count: %"PRIu64"\n", - g_Dbs.db[i].superTblCount); - for (int j = 0; j < g_Dbs.db[i].superTblCount; j++) { - fprintf(fp, " super table[%d]:\n", j); - - fprintf(fp, " stbName: %s\n", - g_Dbs.db[i].superTbls[j].stbName); - - if (PRE_CREATE_SUBTBL == g_Dbs.db[i].superTbls[j].autoCreateTable) { - fprintf(fp, " autoCreateTable: %s\n", "no"); - } else if (AUTO_CREATE_SUBTBL - == g_Dbs.db[i].superTbls[j].autoCreateTable) { - fprintf(fp, " autoCreateTable: %s\n", "yes"); - } else { - fprintf(fp, " autoCreateTable: %s\n", "error"); - } - - if (TBL_NO_EXISTS == g_Dbs.db[i].superTbls[j].childTblExists) { - fprintf(fp, " childTblExists: %s\n", "no"); - } else if (TBL_ALREADY_EXISTS - == g_Dbs.db[i].superTbls[j].childTblExists) { - fprintf(fp, " childTblExists: %s\n", "yes"); - } else { - fprintf(fp, " childTblExists: %s\n", "error"); - } - - fprintf(fp, " childTblCount: %"PRId64"\n", - g_Dbs.db[i].superTbls[j].childTblCount); - fprintf(fp, " childTblPrefix: %s\n", - g_Dbs.db[i].superTbls[j].childTblPrefix); - fprintf(fp, " dataSource: %s\n", - g_Dbs.db[i].superTbls[j].dataSource); - fprintf(fp, " iface: %s\n", - (g_Dbs.db[i].superTbls[j].iface==TAOSC_IFACE)?"taosc": - (g_Dbs.db[i].superTbls[j].iface==REST_IFACE)?"rest": - (g_Dbs.db[i].superTbls[j].iface==STMT_IFACE)?"stmt":"sml"); - fprintf(fp, " insertRows: %"PRId64"\n", - g_Dbs.db[i].superTbls[j].insertRows); - fprintf(fp, " interlace rows: %u\n", - g_Dbs.db[i].superTbls[j].interlaceRows); - if (g_Dbs.db[i].superTbls[j].interlaceRows > 0) { - fprintf(fp, " stable insert interval: %"PRIu64"\n", - g_Dbs.db[i].superTbls[j].insertInterval); - } - /* - if (0 == g_Dbs.db[i].superTbls[j].multiThreadWriteOneTbl) { - fprintf(fp, " multiThreadWriteOneTbl: no\n"); - }else { - fprintf(fp, " multiThreadWriteOneTbl: yes\n"); - } - */ - fprintf(fp, " interlaceRows: %u\n", - g_Dbs.db[i].superTbls[j].interlaceRows); - fprintf(fp, " disorderRange: %d\n", - g_Dbs.db[i].superTbls[j].disorderRange); - fprintf(fp, " disorderRatio: %d\n", - g_Dbs.db[i].superTbls[j].disorderRatio); - fprintf(fp, " maxSqlLen: %"PRIu64"\n", - g_Dbs.db[i].superTbls[j].maxSqlLen); - - fprintf(fp, " timeStampStep: %"PRId64"\n", - g_Dbs.db[i].superTbls[j].timeStampStep); - fprintf(fp, " startTimestamp: %s\n", - g_Dbs.db[i].superTbls[j].startTimestamp); - fprintf(fp, " sampleFormat: %s\n", - g_Dbs.db[i].superTbls[j].sampleFormat); - fprintf(fp, " sampleFile: %s\n", - g_Dbs.db[i].superTbls[j].sampleFile); - fprintf(fp, " tagsFile: %s\n", - g_Dbs.db[i].superTbls[j].tagsFile); - - fprintf(fp, " columnCount: %d\n ", - g_Dbs.db[i].superTbls[j].columnCount); - for (int k = 0; k < g_Dbs.db[i].superTbls[j].columnCount; k++) { - //printf("dataType:%s, dataLen:%d\t", g_Dbs.db[i].superTbls[j].columns[k].dataType, g_Dbs.db[i].superTbls[j].columns[k].dataLen); - if ((0 == strncasecmp( - g_Dbs.db[i].superTbls[j].columns[k].dataType, - "binary", strlen("binary"))) - || (0 == strncasecmp( - g_Dbs.db[i].superTbls[j].columns[k].dataType, - "nchar", strlen("nchar")))) { - fprintf(fp, "column[%d]:%s(%d) ", k, - g_Dbs.db[i].superTbls[j].columns[k].dataType, - g_Dbs.db[i].superTbls[j].columns[k].dataLen); - } else { - fprintf(fp, "column[%d]:%s ", - k, g_Dbs.db[i].superTbls[j].columns[k].dataType); - } - } - fprintf(fp, "\n"); - - fprintf(fp, " tagCount: %d\n ", - g_Dbs.db[i].superTbls[j].tagCount); - for (int k = 0; k < g_Dbs.db[i].superTbls[j].tagCount; k++) { - //printf("dataType:%s, dataLen:%d\t", g_Dbs.db[i].superTbls[j].tags[k].dataType, g_Dbs.db[i].superTbls[j].tags[k].dataLen); - if ((0 == strncasecmp(g_Dbs.db[i].superTbls[j].tags[k].dataType, - "binary", strlen("binary"))) - || (0 == strncasecmp(g_Dbs.db[i].superTbls[j].tags[k].dataType, - "nchar", strlen("nchar")))) { - fprintf(fp, "tag[%d]:%s(%d) ", - k, g_Dbs.db[i].superTbls[j].tags[k].dataType, - g_Dbs.db[i].superTbls[j].tags[k].dataLen); - } else { - fprintf(fp, "tag[%d]:%s ", k, g_Dbs.db[i].superTbls[j].tags[k].dataType); - } - } - fprintf(fp, "\n"); - } - fprintf(fp, "\n"); - } - - SHOW_PARSE_RESULT_END_TO_FILE(fp); -} - -static void printfQueryMeta() { - - SHOW_PARSE_RESULT_START(); - - printf("host: \033[33m%s:%u\033[0m\n", - g_queryInfo.host, g_queryInfo.port); - printf("user: \033[33m%s\033[0m\n", g_queryInfo.user); - printf("database name: \033[33m%s\033[0m\n", g_queryInfo.dbName); - - printf("\n"); - - if ((SUBSCRIBE_TEST == g_args.test_mode) || (QUERY_TEST == g_args.test_mode)) { - printf("specified table query info: \n"); - printf("sqlCount: \033[33m%d\033[0m\n", - g_queryInfo.specifiedQueryInfo.sqlCount); - if (g_queryInfo.specifiedQueryInfo.sqlCount > 0) { - printf("specified tbl query times:\n"); - printf(" \033[33m%"PRIu64"\033[0m\n", - g_queryInfo.specifiedQueryInfo.queryTimes); - printf("query interval: \033[33m%"PRIu64" ms\033[0m\n", - g_queryInfo.specifiedQueryInfo.queryInterval); - printf("top query times:\033[33m%"PRIu64"\033[0m\n", g_args.query_times); - printf("concurrent: \033[33m%d\033[0m\n", - g_queryInfo.specifiedQueryInfo.concurrent); - printf("mod: \033[33m%s\033[0m\n", - (g_queryInfo.specifiedQueryInfo.asyncMode)?"async":"sync"); - printf("interval: \033[33m%"PRIu64"\033[0m\n", - g_queryInfo.specifiedQueryInfo.subscribeInterval); - printf("restart: \033[33m%d\033[0m\n", - g_queryInfo.specifiedQueryInfo.subscribeRestart); - printf("keepProgress: \033[33m%d\033[0m\n", - g_queryInfo.specifiedQueryInfo.subscribeKeepProgress); - - for (int i = 0; i < g_queryInfo.specifiedQueryInfo.sqlCount; i++) { - printf(" sql[%d]: \033[33m%s\033[0m\n", - i, g_queryInfo.specifiedQueryInfo.sql[i]); - } - printf("\n"); - } - - printf("super table query info:\n"); - printf("sqlCount: \033[33m%d\033[0m\n", - g_queryInfo.superQueryInfo.sqlCount); - - if (g_queryInfo.superQueryInfo.sqlCount > 0) { - printf("query interval: \033[33m%"PRIu64"\033[0m\n", - g_queryInfo.superQueryInfo.queryInterval); - printf("threadCnt: \033[33m%d\033[0m\n", - g_queryInfo.superQueryInfo.threadCnt); - printf("childTblCount: \033[33m%"PRId64"\033[0m\n", - g_queryInfo.superQueryInfo.childTblCount); - printf("stable name: \033[33m%s\033[0m\n", - g_queryInfo.superQueryInfo.stbName); - printf("stb query times:\033[33m%"PRIu64"\033[0m\n", - g_queryInfo.superQueryInfo.queryTimes); - - printf("mod: \033[33m%s\033[0m\n", - (g_queryInfo.superQueryInfo.asyncMode)?"async":"sync"); - printf("interval: \033[33m%"PRIu64"\033[0m\n", - g_queryInfo.superQueryInfo.subscribeInterval); - printf("restart: \033[33m%d\033[0m\n", - g_queryInfo.superQueryInfo.subscribeRestart); - printf("keepProgress: \033[33m%d\033[0m\n", - g_queryInfo.superQueryInfo.subscribeKeepProgress); - - for (int i = 0; i < g_queryInfo.superQueryInfo.sqlCount; i++) { - printf(" sql[%d]: \033[33m%s\033[0m\n", - i, g_queryInfo.superQueryInfo.sql[i]); - } - printf("\n"); - } - } - - SHOW_PARSE_RESULT_END(); -} - -static char* formatTimestamp(char* buf, int64_t val, int precision) { - time_t tt; - if (precision == TSDB_TIME_PRECISION_MICRO) { - tt = (time_t)(val / 1000000); - } if (precision == TSDB_TIME_PRECISION_NANO) { - tt = (time_t)(val / 1000000000); - } else { - tt = (time_t)(val / 1000); - } - - /* comment out as it make testcases like select_with_tags.sim fail. - but in windows, this may cause the call to localtime crash if tt < 0, - need to find a better solution. - if (tt < 0) { - tt = 0; - } - */ - -#ifdef WINDOWS - if (tt < 0) tt = 0; -#endif - - struct tm* ptm = localtime(&tt); - size_t pos = strftime(buf, 32, "%Y-%m-%d %H:%M:%S", ptm); - - if (precision == TSDB_TIME_PRECISION_MICRO) { - sprintf(buf + pos, ".%06d", (int)(val % 1000000)); - } else if (precision == TSDB_TIME_PRECISION_NANO) { - sprintf(buf + pos, ".%09d", (int)(val % 1000000000)); - } else { - sprintf(buf + pos, ".%03d", (int)(val % 1000)); - } - - return buf; -} - -static void xDumpFieldToFile(FILE* fp, const char* val, - TAOS_FIELD* field, int32_t length, int precision) { - - if (val == NULL) { - fprintf(fp, "%s", TSDB_DATA_NULL_STR); - return; - } - - char buf[TSDB_MAX_BYTES_PER_ROW]; - switch (field->type) { - case TSDB_DATA_TYPE_BOOL: - fprintf(fp, "%d", ((((int32_t)(*((int8_t*)val))) == 1) ? 1 : 0)); - break; - - case TSDB_DATA_TYPE_TINYINT: - fprintf(fp, "%d", *((int8_t *)val)); - break; - - case TSDB_DATA_TYPE_UTINYINT: - fprintf(fp, "%d", *((uint8_t *)val)); - break; - - case TSDB_DATA_TYPE_SMALLINT: - fprintf(fp, "%d", *((int16_t *)val)); - break; - - case TSDB_DATA_TYPE_USMALLINT: - fprintf(fp, "%d", *((uint16_t *)val)); - break; - - case TSDB_DATA_TYPE_INT: - fprintf(fp, "%d", *((int32_t *)val)); - break; - - case TSDB_DATA_TYPE_UINT: - fprintf(fp, "%d", *((uint32_t *)val)); - break; - - case TSDB_DATA_TYPE_BIGINT: - fprintf(fp, "%"PRId64"", *((int64_t *)val)); - break; - - case TSDB_DATA_TYPE_UBIGINT: - fprintf(fp, "%"PRId64"", *((uint64_t *)val)); - break; - - case TSDB_DATA_TYPE_FLOAT: - fprintf(fp, "%.5f", GET_FLOAT_VAL(val)); - break; - - case TSDB_DATA_TYPE_DOUBLE: - fprintf(fp, "%.9f", GET_DOUBLE_VAL(val)); - break; - - case TSDB_DATA_TYPE_BINARY: - case TSDB_DATA_TYPE_NCHAR: - memcpy(buf, val, length); - buf[length] = 0; - fprintf(fp, "\'%s\'", buf); - break; - - case TSDB_DATA_TYPE_TIMESTAMP: - formatTimestamp(buf, *(int64_t*)val, precision); - fprintf(fp, "'%s'", buf); - break; - - default: - break; - } -} - -static int xDumpResultToFile(const char* fname, TAOS_RES* tres) { - TAOS_ROW row = taos_fetch_row(tres); - if (row == NULL) { - return 0; - } - - FILE* fp = fopen(fname, "at"); - if (fp == NULL) { - errorPrint2("%s() LN%d, failed to open file: %s\n", - __func__, __LINE__, fname); - return -1; - } - - int num_fields = taos_num_fields(tres); - TAOS_FIELD *fields = taos_fetch_fields(tres); - int precision = taos_result_precision(tres); - - for (int col = 0; col < num_fields; col++) { - if (col > 0) { - fprintf(fp, ","); - } - fprintf(fp, "%s", fields[col].name); - } - fputc('\n', fp); - - int numOfRows = 0; - do { - int32_t* length = taos_fetch_lengths(tres); - for (int i = 0; i < num_fields; i++) { - if (i > 0) { - fputc(',', fp); - } - xDumpFieldToFile(fp, - (const char*)row[i], fields +i, length[i], precision); - } - fputc('\n', fp); - - numOfRows++; - row = taos_fetch_row(tres); - } while( row != NULL); - - fclose(fp); - - return numOfRows; -} - -static int getDbFromServer(TAOS * taos, SDbInfo** dbInfos) { - TAOS_RES * res; - TAOS_ROW row = NULL; - int count = 0; - - res = taos_query(taos, "show databases;"); - int32_t code = taos_errno(res); - - if (code != 0) { - errorPrint2("failed to run , reason: %s\n", - taos_errstr(res)); - return -1; - } - - TAOS_FIELD *fields = taos_fetch_fields(res); - - while((row = taos_fetch_row(res)) != NULL) { - // sys database name : 'log' - if (strncasecmp(row[TSDB_SHOW_DB_NAME_INDEX], "log", - fields[TSDB_SHOW_DB_NAME_INDEX].bytes) == 0) { - continue; - } - - dbInfos[count] = (SDbInfo *)calloc(1, sizeof(SDbInfo)); - if (dbInfos[count] == NULL) { - errorPrint2("failed to allocate memory for some dbInfo[%d]\n", count); - return -1; - } - - tstrncpy(dbInfos[count]->name, (char *)row[TSDB_SHOW_DB_NAME_INDEX], - fields[TSDB_SHOW_DB_NAME_INDEX].bytes); - formatTimestamp(dbInfos[count]->create_time, - *(int64_t*)row[TSDB_SHOW_DB_CREATED_TIME_INDEX], - TSDB_TIME_PRECISION_MILLI); - dbInfos[count]->ntables = *((int64_t *)row[TSDB_SHOW_DB_NTABLES_INDEX]); - dbInfos[count]->vgroups = *((int32_t *)row[TSDB_SHOW_DB_VGROUPS_INDEX]); - dbInfos[count]->replica = *((int16_t *)row[TSDB_SHOW_DB_REPLICA_INDEX]); - dbInfos[count]->quorum = *((int16_t *)row[TSDB_SHOW_DB_QUORUM_INDEX]); - dbInfos[count]->days = *((int16_t *)row[TSDB_SHOW_DB_DAYS_INDEX]); - - tstrncpy(dbInfos[count]->keeplist, (char *)row[TSDB_SHOW_DB_KEEP_INDEX], - fields[TSDB_SHOW_DB_KEEP_INDEX].bytes); - dbInfos[count]->cache = *((int32_t *)row[TSDB_SHOW_DB_CACHE_INDEX]); - dbInfos[count]->blocks = *((int32_t *)row[TSDB_SHOW_DB_BLOCKS_INDEX]); - dbInfos[count]->minrows = *((int32_t *)row[TSDB_SHOW_DB_MINROWS_INDEX]); - dbInfos[count]->maxrows = *((int32_t *)row[TSDB_SHOW_DB_MAXROWS_INDEX]); - dbInfos[count]->wallevel = *((int8_t *)row[TSDB_SHOW_DB_WALLEVEL_INDEX]); - dbInfos[count]->fsync = *((int32_t *)row[TSDB_SHOW_DB_FSYNC_INDEX]); - dbInfos[count]->comp = (int8_t)(*((int8_t *)row[TSDB_SHOW_DB_COMP_INDEX])); - dbInfos[count]->cachelast = - (int8_t)(*((int8_t *)row[TSDB_SHOW_DB_CACHELAST_INDEX])); - - tstrncpy(dbInfos[count]->precision, - (char *)row[TSDB_SHOW_DB_PRECISION_INDEX], - fields[TSDB_SHOW_DB_PRECISION_INDEX].bytes); - dbInfos[count]->update = *((int8_t *)row[TSDB_SHOW_DB_UPDATE_INDEX]); - tstrncpy(dbInfos[count]->status, (char *)row[TSDB_SHOW_DB_STATUS_INDEX], - fields[TSDB_SHOW_DB_STATUS_INDEX].bytes); - - count++; - if (count > MAX_DATABASE_COUNT) { - errorPrint("%s() LN%d, The database count overflow than %d\n", - __func__, __LINE__, MAX_DATABASE_COUNT); - break; - } - } - - return count; -} - -static void printfDbInfoForQueryToFile( - char* filename, SDbInfo* dbInfos, int index) { - - if (filename[0] == 0) - return; - - FILE *fp = fopen(filename, "at"); - if (fp == NULL) { - errorPrint( "failed to open file: %s\n", filename); - return; - } - - fprintf(fp, "================ database[%d] ================\n", index); - fprintf(fp, "name: %s\n", dbInfos->name); - fprintf(fp, "created_time: %s\n", dbInfos->create_time); - fprintf(fp, "ntables: %"PRId64"\n", dbInfos->ntables); - fprintf(fp, "vgroups: %d\n", dbInfos->vgroups); - fprintf(fp, "replica: %d\n", dbInfos->replica); - fprintf(fp, "quorum: %d\n", dbInfos->quorum); - fprintf(fp, "days: %d\n", dbInfos->days); - fprintf(fp, "keep0,keep1,keep(D): %s\n", dbInfos->keeplist); - fprintf(fp, "cache(MB): %d\n", dbInfos->cache); - fprintf(fp, "blocks: %d\n", dbInfos->blocks); - fprintf(fp, "minrows: %d\n", dbInfos->minrows); - fprintf(fp, "maxrows: %d\n", dbInfos->maxrows); - fprintf(fp, "wallevel: %d\n", dbInfos->wallevel); - fprintf(fp, "fsync: %d\n", dbInfos->fsync); - fprintf(fp, "comp: %d\n", dbInfos->comp); - fprintf(fp, "cachelast: %d\n", dbInfos->cachelast); - fprintf(fp, "precision: %s\n", dbInfos->precision); - fprintf(fp, "update: %d\n", dbInfos->update); - fprintf(fp, "status: %s\n", dbInfos->status); - fprintf(fp, "\n"); - - fclose(fp); -} - -static void printfQuerySystemInfo(TAOS * taos) { - char filename[MAX_FILE_NAME_LEN] = {0}; - char buffer[SQL_BUFF_LEN] = {0}; - TAOS_RES* res; - - time_t t; - struct tm* lt; - time(&t); - lt = localtime(&t); - snprintf(filename, MAX_FILE_NAME_LEN, "querySystemInfo-%d-%d-%d %d:%d:%d", - lt->tm_year+1900, lt->tm_mon, lt->tm_mday, lt->tm_hour, lt->tm_min, - lt->tm_sec); - - // show variables - res = taos_query(taos, "show variables;"); - //fetchResult(res, filename); - xDumpResultToFile(filename, res); - - // show dnodes - res = taos_query(taos, "show dnodes;"); - xDumpResultToFile(filename, res); - //fetchResult(res, filename); - - // show databases - res = taos_query(taos, "show databases;"); - SDbInfo** dbInfos = (SDbInfo **)calloc(MAX_DATABASE_COUNT, sizeof(SDbInfo *)); - if (dbInfos == NULL) { - errorPrint("%s() LN%d, failed to allocate memory\n", __func__, __LINE__); - return; - } - int dbCount = getDbFromServer(taos, dbInfos); - if (dbCount <= 0) { - free(dbInfos); - return; - } - - for (int i = 0; i < dbCount; i++) { - // printf database info - printfDbInfoForQueryToFile(filename, dbInfos[i], i); - - // show db.vgroups - snprintf(buffer, SQL_BUFF_LEN, "show %s.vgroups;", dbInfos[i]->name); - res = taos_query(taos, buffer); - xDumpResultToFile(filename, res); - - // show db.stables - snprintf(buffer, SQL_BUFF_LEN, "show %s.stables;", dbInfos[i]->name); - res = taos_query(taos, buffer); - xDumpResultToFile(filename, res); - free(dbInfos[i]); - } - - free(dbInfos); -} - -static int postProceSql(char *host, uint16_t port, - char* sqlstr, threadInfo *pThreadInfo) -{ - char *req_fmt = "POST %s HTTP/1.1\r\nHost: %s:%d\r\nAccept: */*\r\nAuthorization: Basic %s\r\nContent-Length: %d\r\nContent-Type: application/x-www-form-urlencoded\r\n\r\n%s"; - - char *url = "/rest/sql"; - - int bytes, sent, received, req_str_len, resp_len; - char *request_buf; - char response_buf[RESP_BUF_LEN]; - uint16_t rest_port = port + TSDB_PORT_HTTP; - - int req_buf_len = strlen(sqlstr) + REQ_EXTRA_BUF_LEN; - - request_buf = malloc(req_buf_len); - if (NULL == request_buf) { - errorPrint("%s", "cannot allocate memory.\n"); - exit(EXIT_FAILURE); - } - - char userpass_buf[INPUT_BUF_LEN]; - int mod_table[] = {0, 2, 1}; - - static char base64[] = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', - 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', - 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', - 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', - 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', - 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', - 'w', 'x', 'y', 'z', '0', '1', '2', '3', - '4', '5', '6', '7', '8', '9', '+', '/'}; - - if (g_args.test_mode == INSERT_TEST) { - snprintf(userpass_buf, INPUT_BUF_LEN, "%s:%s", - g_Dbs.user, g_Dbs.password); - } else { - snprintf(userpass_buf, INPUT_BUF_LEN, "%s:%s", - g_queryInfo.user, g_queryInfo.password); - } - - size_t userpass_buf_len = strlen(userpass_buf); - size_t encoded_len = 4 * ((userpass_buf_len +2) / 3); - - char base64_buf[INPUT_BUF_LEN]; - - memset(base64_buf, 0, INPUT_BUF_LEN); - - for (int n = 0, m = 0; n < userpass_buf_len;) { - uint32_t oct_a = n < userpass_buf_len ? - (unsigned char) userpass_buf[n++]:0; - uint32_t oct_b = n < userpass_buf_len ? - (unsigned char) userpass_buf[n++]:0; - uint32_t oct_c = n < userpass_buf_len ? - (unsigned char) userpass_buf[n++]:0; - uint32_t triple = (oct_a << 0x10) + (oct_b << 0x08) + oct_c; - - base64_buf[m++] = base64[(triple >> 3* 6) & 0x3f]; - base64_buf[m++] = base64[(triple >> 2* 6) & 0x3f]; - base64_buf[m++] = base64[(triple >> 1* 6) & 0x3f]; - base64_buf[m++] = base64[(triple >> 0* 6) & 0x3f]; - } - - for (int l = 0; l < mod_table[userpass_buf_len % 3]; l++) - base64_buf[encoded_len - 1 - l] = '='; - - debugPrint("%s() LN%d: auth string base64 encoded: %s\n", - __func__, __LINE__, base64_buf); - char *auth = base64_buf; - - int r = snprintf(request_buf, - req_buf_len, - req_fmt, url, host, rest_port, - auth, strlen(sqlstr), sqlstr); - if (r >= req_buf_len) { - free(request_buf); - ERROR_EXIT("too long request"); - } - verbosePrint("%s() LN%d: Request:\n%s\n", __func__, __LINE__, request_buf); - - req_str_len = strlen(request_buf); - sent = 0; - do { -#ifdef WINDOWS - bytes = send(pThreadInfo->sockfd, request_buf + sent, req_str_len - sent, 0); -#else - bytes = write(pThreadInfo->sockfd, request_buf + sent, req_str_len - sent); -#endif - if (bytes < 0) - ERROR_EXIT("writing message to socket"); - if (bytes == 0) - break; - sent+=bytes; - } while(sent < req_str_len); - - memset(response_buf, 0, RESP_BUF_LEN); - resp_len = sizeof(response_buf) - 1; - received = 0; - - char resEncodingChunk[] = "Encoding: chunked"; - char resHttp[] = "HTTP/1.1 "; - char resHttpOk[] = "HTTP/1.1 200 OK"; - - do { -#ifdef WINDOWS - bytes = recv(pThreadInfo->sockfd, response_buf + received, resp_len - received, 0); -#else - bytes = read(pThreadInfo->sockfd, response_buf + received, resp_len - received); -#endif - verbosePrint("%s() LN%d: bytes:%d\n", __func__, __LINE__, bytes); - if (bytes < 0) { - free(request_buf); - ERROR_EXIT("reading response from socket"); - } - if (bytes == 0) - break; - received += bytes; - - verbosePrint("%s() LN%d: received:%d resp_len:%d, response_buf:\n%s\n", - __func__, __LINE__, received, resp_len, response_buf); - - response_buf[RESP_BUF_LEN - 1] = '\0'; - if (strlen(response_buf)) { - verbosePrint("%s() LN%d: received:%d resp_len:%d, response_buf:\n%s\n", - __func__, __LINE__, received, resp_len, response_buf); - - if (((NULL != strstr(response_buf, resEncodingChunk)) - && (NULL != strstr(response_buf, resHttp))) - || ((NULL != strstr(response_buf, resHttpOk)) - && (NULL != strstr(response_buf, "\"status\":")))) { - debugPrint( - "%s() LN%d: received:%d resp_len:%d, response_buf:\n%s\n", - __func__, __LINE__, received, resp_len, response_buf); - break; - } - } - } while(received < resp_len); - - if (received == resp_len) { - free(request_buf); - ERROR_EXIT("storing complete response from socket"); - } - - if (strlen(pThreadInfo->filePath) > 0) { - appendResultBufToFile(response_buf, pThreadInfo); - } - - free(request_buf); - - if (NULL == strstr(response_buf, resHttpOk)) { - errorPrint("%s() LN%d, Response:\n%s\n", - __func__, __LINE__, response_buf); - return -1; - } - return 0; -} - -static char* getTagValueFromTagSample(SSuperTable* stbInfo, int tagUsePos) { - char* dataBuf = (char*)calloc(TSDB_MAX_SQL_LEN+1, 1); - if (NULL == dataBuf) { - errorPrint2("%s() LN%d, calloc failed! size:%d\n", - __func__, __LINE__, TSDB_MAX_SQL_LEN+1); - return NULL; - } - - int dataLen = 0; - dataLen += snprintf(dataBuf + dataLen, TSDB_MAX_SQL_LEN - dataLen, - "(%s)", stbInfo->tagDataBuf + stbInfo->lenOfTagOfOneRow * tagUsePos); - - return dataBuf; -} - -static char *generateBinaryNCharTagValues(int64_t tableSeq, uint32_t len) -{ - char* buf = (char*)calloc(len, 1); - if (NULL == buf) { - printf("calloc failed! size:%d\n", len); - return NULL; - } - - if (tableSeq % 2) { - tstrncpy(buf, "beijing", len); - } else { - tstrncpy(buf, "shanghai", len); - } - //rand_string(buf, stbInfo->tags[i].dataLen); - - return buf; -} - -static char* generateTagValuesForStb(SSuperTable* stbInfo, int64_t tableSeq) { - char* dataBuf = (char*)calloc(TSDB_MAX_SQL_LEN+1, 1); - if (NULL == dataBuf) { - printf("calloc failed! size:%d\n", TSDB_MAX_SQL_LEN+1); - return NULL; - } - - int dataLen = 0; - dataLen += snprintf(dataBuf + dataLen, TSDB_MAX_SQL_LEN - dataLen, "("); - for (int i = 0; i < stbInfo->tagCount; i++) { - if ((0 == strncasecmp(stbInfo->tags[i].dataType, - "binary", strlen("binary"))) - || (0 == strncasecmp(stbInfo->tags[i].dataType, - "nchar", strlen("nchar")))) { - if (stbInfo->tags[i].dataLen > TSDB_MAX_BINARY_LEN) { - printf("binary or nchar length overflow, max size:%u\n", - (uint32_t)TSDB_MAX_BINARY_LEN); - tmfree(dataBuf); - return NULL; - } - - int32_t tagBufLen = stbInfo->tags[i].dataLen + 1; - char *buf = generateBinaryNCharTagValues(tableSeq, tagBufLen); - if (NULL == buf) { - tmfree(dataBuf); - return NULL; - } - dataLen += snprintf(dataBuf + dataLen, TSDB_MAX_SQL_LEN - dataLen, - "\'%s\',", buf); - tmfree(buf); - } else if (0 == strncasecmp(stbInfo->tags[i].dataType, - "int", strlen("int"))) { - if ((g_args.demo_mode) && (i == 0)) { - dataLen += snprintf(dataBuf + dataLen, - TSDB_MAX_SQL_LEN - dataLen, - "%"PRId64",", (tableSeq % 10) + 1); - } else { - dataLen += snprintf(dataBuf + dataLen, - TSDB_MAX_SQL_LEN - dataLen, - "%"PRId64",", tableSeq); - } - } else if (0 == strncasecmp(stbInfo->tags[i].dataType, - "bigint", strlen("bigint"))) { - dataLen += snprintf(dataBuf + dataLen, TSDB_MAX_SQL_LEN - dataLen, - "%"PRId64",", rand_bigint()); - } else if (0 == strncasecmp(stbInfo->tags[i].dataType, - "float", strlen("float"))) { - dataLen += snprintf(dataBuf + dataLen, TSDB_MAX_SQL_LEN - dataLen, - "%f,", rand_float()); - } else if (0 == strncasecmp(stbInfo->tags[i].dataType, - "double", strlen("double"))) { - dataLen += snprintf(dataBuf + dataLen, TSDB_MAX_SQL_LEN - dataLen, - "%f,", rand_double()); - } else if (0 == strncasecmp(stbInfo->tags[i].dataType, - "smallint", strlen("smallint"))) { - dataLen += snprintf(dataBuf + dataLen, TSDB_MAX_SQL_LEN - dataLen, - "%d,", rand_smallint()); - } else if (0 == strncasecmp(stbInfo->tags[i].dataType, - "tinyint", strlen("tinyint"))) { - dataLen += snprintf(dataBuf + dataLen, TSDB_MAX_SQL_LEN - dataLen, - "%d,", rand_tinyint()); - } else if (0 == strncasecmp(stbInfo->tags[i].dataType, - "bool", strlen("bool"))) { - dataLen += snprintf(dataBuf + dataLen, TSDB_MAX_SQL_LEN - dataLen, - "%d,", rand_bool()); - } else if (0 == strncasecmp(stbInfo->tags[i].dataType, - "timestamp", strlen("timestamp"))) { - dataLen += snprintf(dataBuf + dataLen, TSDB_MAX_SQL_LEN - dataLen, - "%"PRId64",", rand_ubigint()); - } else if (0 == strncasecmp(stbInfo->tags[i].dataType, - "utinyint", strlen("utinyint"))) { - dataLen += snprintf(dataBuf + dataLen, TSDB_MAX_SQL_LEN - dataLen, - "%d,", rand_utinyint()); - } else if (0 == strncasecmp(stbInfo->tags[i].dataType, - "usmallint", strlen("usmallint"))) { - dataLen += snprintf(dataBuf + dataLen, TSDB_MAX_SQL_LEN - dataLen, - "%d,", rand_usmallint()); - } else if (0 == strncasecmp(stbInfo->tags[i].dataType, - "uint", strlen("uint"))) { - dataLen += snprintf(dataBuf + dataLen, TSDB_MAX_SQL_LEN - dataLen, - "%d,", rand_uint()); - } else if (0 == strncasecmp(stbInfo->tags[i].dataType, - "ubigint", strlen("ubigint"))) { - dataLen += snprintf(dataBuf + dataLen, TSDB_MAX_SQL_LEN - dataLen, - "%"PRId64",", rand_ubigint()); - } else { - errorPrint2("No support data type: %s\n", stbInfo->tags[i].dataType); - tmfree(dataBuf); - return NULL; - } - } - - dataLen -= 1; - dataLen += snprintf(dataBuf + dataLen, TSDB_MAX_SQL_LEN - dataLen, ")"); - return dataBuf; -} - -static int calcRowLen(SSuperTable* superTbls) { - int colIndex; - int lenOfOneRow = 0; - - for (colIndex = 0; colIndex < superTbls->columnCount; colIndex++) { - char* dataType = superTbls->columns[colIndex].dataType; - - switch(superTbls->columns[colIndex].data_type) { - case TSDB_DATA_TYPE_BINARY: - lenOfOneRow += superTbls->columns[colIndex].dataLen + 3; - break; - - case TSDB_DATA_TYPE_NCHAR: - lenOfOneRow += superTbls->columns[colIndex].dataLen + 3; - break; - - case TSDB_DATA_TYPE_INT: - case TSDB_DATA_TYPE_UINT: - lenOfOneRow += INT_BUFF_LEN; - break; - - case TSDB_DATA_TYPE_BIGINT: - case TSDB_DATA_TYPE_UBIGINT: - lenOfOneRow += BIGINT_BUFF_LEN; - break; - - case TSDB_DATA_TYPE_SMALLINT: - case TSDB_DATA_TYPE_USMALLINT: - lenOfOneRow += SMALLINT_BUFF_LEN; - break; - - case TSDB_DATA_TYPE_TINYINT: - case TSDB_DATA_TYPE_UTINYINT: - lenOfOneRow += TINYINT_BUFF_LEN; - break; - - case TSDB_DATA_TYPE_BOOL: - lenOfOneRow += BOOL_BUFF_LEN; - break; - - case TSDB_DATA_TYPE_FLOAT: - lenOfOneRow += FLOAT_BUFF_LEN; - break; - - case TSDB_DATA_TYPE_DOUBLE: - lenOfOneRow += DOUBLE_BUFF_LEN; - break; - - case TSDB_DATA_TYPE_TIMESTAMP: - lenOfOneRow += TIMESTAMP_BUFF_LEN; - break; - - default: - errorPrint2("get error data type : %s\n", dataType); - exit(EXIT_FAILURE); - } - } - - superTbls->lenOfOneRow = lenOfOneRow + TIMESTAMP_BUFF_LEN; // timestamp - - int tagIndex; - int lenOfTagOfOneRow = 0; - for (tagIndex = 0; tagIndex < superTbls->tagCount; tagIndex++) { - char * dataType = superTbls->tags[tagIndex].dataType; - switch (superTbls->tags[tagIndex].data_type) - { - case TSDB_DATA_TYPE_BINARY: - lenOfTagOfOneRow += superTbls->tags[tagIndex].dataLen + 3; - break; - case TSDB_DATA_TYPE_NCHAR: - lenOfTagOfOneRow += superTbls->tags[tagIndex].dataLen + 3; - break; - case TSDB_DATA_TYPE_INT: - case TSDB_DATA_TYPE_UINT: - lenOfTagOfOneRow += superTbls->tags[tagIndex].dataLen + INT_BUFF_LEN; - break; - case TSDB_DATA_TYPE_BIGINT: - case TSDB_DATA_TYPE_UBIGINT: - lenOfTagOfOneRow += superTbls->tags[tagIndex].dataLen + BIGINT_BUFF_LEN; - break; - case TSDB_DATA_TYPE_SMALLINT: - case TSDB_DATA_TYPE_USMALLINT: - lenOfTagOfOneRow += superTbls->tags[tagIndex].dataLen + SMALLINT_BUFF_LEN; - break; - case TSDB_DATA_TYPE_TINYINT: - case TSDB_DATA_TYPE_UTINYINT: - lenOfTagOfOneRow += superTbls->tags[tagIndex].dataLen + TINYINT_BUFF_LEN; - break; - case TSDB_DATA_TYPE_BOOL: - lenOfTagOfOneRow += superTbls->tags[tagIndex].dataLen + BOOL_BUFF_LEN; - break; - case TSDB_DATA_TYPE_FLOAT: - lenOfTagOfOneRow += superTbls->tags[tagIndex].dataLen + FLOAT_BUFF_LEN; - break; - case TSDB_DATA_TYPE_DOUBLE: - lenOfTagOfOneRow += superTbls->tags[tagIndex].dataLen + DOUBLE_BUFF_LEN; - break; - default: - errorPrint2("get error tag type : %s\n", dataType); - exit(EXIT_FAILURE); - } - } - - superTbls->lenOfTagOfOneRow = lenOfTagOfOneRow; - - return 0; -} - -static int getChildNameOfSuperTableWithLimitAndOffset(TAOS * taos, - char* dbName, char* stbName, char** childTblNameOfSuperTbl, - int64_t* childTblCountOfSuperTbl, int64_t limit, uint64_t offset, bool escapChar) { - - char command[SQL_BUFF_LEN] = "\0"; - char limitBuf[100] = "\0"; - - TAOS_RES * res; - TAOS_ROW row = NULL; - - char* childTblName = *childTblNameOfSuperTbl; - - snprintf(limitBuf, 100, " limit %"PRId64" offset %"PRIu64"", - limit, offset); - - //get all child table name use cmd: select tbname from superTblName; - snprintf(command, SQL_BUFF_LEN, escapChar ? "select tbname from %s.`%s` %s" : - "select tbname from %s.%s %s", dbName, stbName, limitBuf); - - res = taos_query(taos, command); - int32_t code = taos_errno(res); - if (code != 0) { - taos_free_result(res); - taos_close(taos); - errorPrint2("%s() LN%d, failed to run command %s, reason: %s\n", - __func__, __LINE__, command, taos_errstr(res)); - exit(EXIT_FAILURE); - } - - int64_t childTblCount = (limit < 0)?DEFAULT_CHILDTABLES:limit; - int64_t count = 0; - if (childTblName == NULL) { - childTblName = (char*)calloc(1, childTblCount * TSDB_TABLE_NAME_LEN); - if (NULL == childTblName) { - taos_free_result(res); - taos_close(taos); - errorPrint2("%s() LN%d, failed to allocate memory!\n", __func__, __LINE__); - exit(EXIT_FAILURE); - } - } - - char* pTblName = childTblName; - while((row = taos_fetch_row(res)) != NULL) { - int32_t* len = taos_fetch_lengths(res); - - if (0 == strlen((char *)row[0])) { - errorPrint2("%s() LN%d, No.%"PRId64" table return empty name\n", - __func__, __LINE__, count); - exit(EXIT_FAILURE); - } - - tstrncpy(pTblName, (char *)row[0], len[0]+1); - //printf("==== sub table name: %s\n", pTblName); - count++; - if (count >= childTblCount - 1) { - char *tmp = realloc(childTblName, - (size_t)childTblCount*1.5*TSDB_TABLE_NAME_LEN+1); - if (tmp != NULL) { - childTblName = tmp; - childTblCount = (int)(childTblCount*1.5); - memset(childTblName + count*TSDB_TABLE_NAME_LEN, 0, - (size_t)((childTblCount-count)*TSDB_TABLE_NAME_LEN)); - } else { - // exit, if allocate more memory failed - tmfree(childTblName); - taos_free_result(res); - taos_close(taos); - errorPrint2("%s() LN%d, realloc fail for save child table name of %s.%s\n", - __func__, __LINE__, dbName, stbName); - exit(EXIT_FAILURE); - } - } - pTblName = childTblName + count * TSDB_TABLE_NAME_LEN; - } - - *childTblCountOfSuperTbl = count; - *childTblNameOfSuperTbl = childTblName; - - taos_free_result(res); - return 0; -} - -static int getAllChildNameOfSuperTable(TAOS * taos, char* dbName, - char* stbName, char** childTblNameOfSuperTbl, - int64_t* childTblCountOfSuperTbl) { - - return getChildNameOfSuperTableWithLimitAndOffset(taos, dbName, stbName, - childTblNameOfSuperTbl, childTblCountOfSuperTbl, - -1, 0, false); -} - -static int getSuperTableFromServer(TAOS * taos, char* dbName, - SSuperTable* superTbls) { - - char command[SQL_BUFF_LEN] = "\0"; - TAOS_RES * res; - TAOS_ROW row = NULL; - int count = 0; - - //get schema use cmd: describe superTblName; - snprintf(command, SQL_BUFF_LEN, "describe %s.%s", dbName, superTbls->stbName); - res = taos_query(taos, command); - int32_t code = taos_errno(res); - if (code != 0) { - printf("failed to run command %s, reason: %s\n", command, taos_errstr(res)); - taos_free_result(res); - return -1; - } - - int tagIndex = 0; - int columnIndex = 0; - TAOS_FIELD *fields = taos_fetch_fields(res); - while((row = taos_fetch_row(res)) != NULL) { - if (0 == count) { - count++; - continue; - } - - if (strcmp((char *)row[TSDB_DESCRIBE_METRIC_NOTE_INDEX], "TAG") == 0) { - tstrncpy(superTbls->tags[tagIndex].field, - (char *)row[TSDB_DESCRIBE_METRIC_FIELD_INDEX], - fields[TSDB_DESCRIBE_METRIC_FIELD_INDEX].bytes); - if (0 == strncasecmp((char *)row[TSDB_DESCRIBE_METRIC_TYPE_INDEX], - "INT", strlen("INT"))) { - superTbls->tags[tagIndex].data_type = TSDB_DATA_TYPE_INT; - } else if (0 == strncasecmp((char *)row[TSDB_DESCRIBE_METRIC_TYPE_INDEX], - "TINYINT", strlen("TINYINT"))) { - superTbls->tags[tagIndex].data_type = TSDB_DATA_TYPE_TINYINT; - } else if (0 == strncasecmp((char *)row[TSDB_DESCRIBE_METRIC_TYPE_INDEX], - "SMALLINT", strlen("SMALLINT"))) { - superTbls->tags[tagIndex].data_type = TSDB_DATA_TYPE_SMALLINT; - } else if (0 == strncasecmp((char *)row[TSDB_DESCRIBE_METRIC_TYPE_INDEX], - "BIGINT", strlen("BIGINT"))) { - superTbls->tags[tagIndex].data_type = TSDB_DATA_TYPE_BIGINT; - } else if (0 == strncasecmp((char *)row[TSDB_DESCRIBE_METRIC_TYPE_INDEX], - "FLOAT", strlen("FLOAT"))) { - superTbls->tags[tagIndex].data_type = TSDB_DATA_TYPE_FLOAT; - } else if (0 == strncasecmp((char *)row[TSDB_DESCRIBE_METRIC_TYPE_INDEX], - "DOUBLE", strlen("DOUBLE"))) { - superTbls->tags[tagIndex].data_type = TSDB_DATA_TYPE_DOUBLE; - } else if (0 == strncasecmp((char *)row[TSDB_DESCRIBE_METRIC_TYPE_INDEX], - "BINARY", strlen("BINARY"))) { - superTbls->tags[tagIndex].data_type = TSDB_DATA_TYPE_BINARY; - } else if (0 == strncasecmp((char *)row[TSDB_DESCRIBE_METRIC_TYPE_INDEX], - "NCHAR", strlen("NCHAR"))) { - superTbls->tags[tagIndex].data_type = TSDB_DATA_TYPE_NCHAR; - } else if (0 == strncasecmp((char *)row[TSDB_DESCRIBE_METRIC_TYPE_INDEX], - "BOOL", strlen("BOOL"))) { - superTbls->tags[tagIndex].data_type = TSDB_DATA_TYPE_BOOL; - } else if (0 == strncasecmp((char *)row[TSDB_DESCRIBE_METRIC_TYPE_INDEX], - "TIMESTAMP", strlen("TIMESTAMP"))) { - superTbls->tags[tagIndex].data_type = TSDB_DATA_TYPE_TIMESTAMP; - } else if (0 == strncasecmp((char *)row[TSDB_DESCRIBE_METRIC_TYPE_INDEX], - "TINYINT UNSIGNED", strlen("TINYINT UNSIGNED"))) { - superTbls->tags[tagIndex].data_type = TSDB_DATA_TYPE_UTINYINT; - tstrncpy(superTbls->tags[tagIndex].dataType,"UTINYINT", - min(DATATYPE_BUFF_LEN, - fields[TSDB_DESCRIBE_METRIC_TYPE_INDEX].bytes) + 1); - } else if (0 == strncasecmp((char *)row[TSDB_DESCRIBE_METRIC_TYPE_INDEX], - "SMALLINT UNSIGNED", strlen("SMALLINT UNSIGNED"))) { - superTbls->tags[tagIndex].data_type = TSDB_DATA_TYPE_USMALLINT; - tstrncpy(superTbls->tags[tagIndex].dataType,"USMALLINT", - min(DATATYPE_BUFF_LEN, - fields[TSDB_DESCRIBE_METRIC_TYPE_INDEX].bytes) + 1); - } else if (0 == strncasecmp((char *)row[TSDB_DESCRIBE_METRIC_TYPE_INDEX], - "INT UNSIGNED", strlen("INT UNSIGNED"))) { - superTbls->tags[tagIndex].data_type = TSDB_DATA_TYPE_UINT; - tstrncpy(superTbls->tags[tagIndex].dataType,"UINT", - min(DATATYPE_BUFF_LEN, - fields[TSDB_DESCRIBE_METRIC_TYPE_INDEX].bytes) + 1); - }else if (0 == strncasecmp((char *)row[TSDB_DESCRIBE_METRIC_TYPE_INDEX], - "BIGINT UNSIGNED", strlen("BIGINT UNSIGNED"))) { - superTbls->tags[tagIndex].data_type = TSDB_DATA_TYPE_UBIGINT; - tstrncpy(superTbls->tags[tagIndex].dataType,"UBIGINT", - min(DATATYPE_BUFF_LEN, - fields[TSDB_DESCRIBE_METRIC_TYPE_INDEX].bytes) + 1); - } else { - superTbls->tags[tagIndex].data_type = TSDB_DATA_TYPE_NULL; - } - superTbls->tags[tagIndex].dataLen = - *((int *)row[TSDB_DESCRIBE_METRIC_LENGTH_INDEX]); - tstrncpy(superTbls->tags[tagIndex].note, - (char *)row[TSDB_DESCRIBE_METRIC_NOTE_INDEX], - min(NOTE_BUFF_LEN, - fields[TSDB_DESCRIBE_METRIC_NOTE_INDEX].bytes) + 1); - if (strstr((char *)row[TSDB_DESCRIBE_METRIC_TYPE_INDEX], "UNSIGNED") == NULL) - { - tstrncpy(superTbls->tags[tagIndex].dataType, - (char *)row[TSDB_DESCRIBE_METRIC_TYPE_INDEX], - min(DATATYPE_BUFF_LEN, - fields[TSDB_DESCRIBE_METRIC_TYPE_INDEX].bytes) + 1); - } - tagIndex++; - } else { - tstrncpy(superTbls->columns[columnIndex].field, - (char *)row[TSDB_DESCRIBE_METRIC_FIELD_INDEX], - fields[TSDB_DESCRIBE_METRIC_FIELD_INDEX].bytes); - - - if (0 == strncasecmp((char *)row[TSDB_DESCRIBE_METRIC_TYPE_INDEX], - "INT", strlen("INT")) && - strstr((char *)row[TSDB_DESCRIBE_METRIC_TYPE_INDEX], "UNSIGNED") == NULL) { - superTbls->columns[columnIndex].data_type = TSDB_DATA_TYPE_INT; - } else if (0 == strncasecmp((char *)row[TSDB_DESCRIBE_METRIC_TYPE_INDEX], - "TINYINT", strlen("TINYINT")) && - strstr((char *)row[TSDB_DESCRIBE_METRIC_TYPE_INDEX], "UNSIGNED") == NULL) { - superTbls->columns[columnIndex].data_type = TSDB_DATA_TYPE_TINYINT; - } else if (0 == strncasecmp((char *)row[TSDB_DESCRIBE_METRIC_TYPE_INDEX], - "SMALLINT", strlen("SMALLINT")) && - strstr((char *)row[TSDB_DESCRIBE_METRIC_TYPE_INDEX], "UNSIGNED") == NULL) { - superTbls->columns[columnIndex].data_type = TSDB_DATA_TYPE_SMALLINT; - } else if (0 == strncasecmp((char *)row[TSDB_DESCRIBE_METRIC_TYPE_INDEX], - "BIGINT", strlen("BIGINT")) && - strstr((char *)row[TSDB_DESCRIBE_METRIC_TYPE_INDEX], "UNSIGNED") == NULL) { - superTbls->columns[columnIndex].data_type = TSDB_DATA_TYPE_BIGINT; - } else if (0 == strncasecmp((char *)row[TSDB_DESCRIBE_METRIC_TYPE_INDEX], - "FLOAT", strlen("FLOAT"))) { - superTbls->columns[columnIndex].data_type = TSDB_DATA_TYPE_FLOAT; - } else if (0 == strncasecmp((char *)row[TSDB_DESCRIBE_METRIC_TYPE_INDEX], - "DOUBLE", strlen("DOUBLE"))) { - superTbls->columns[columnIndex].data_type = TSDB_DATA_TYPE_DOUBLE; - } else if (0 == strncasecmp((char *)row[TSDB_DESCRIBE_METRIC_TYPE_INDEX], - "BINARY", strlen("BINARY"))) { - superTbls->columns[columnIndex].data_type = TSDB_DATA_TYPE_BINARY; - } else if (0 == strncasecmp((char *)row[TSDB_DESCRIBE_METRIC_TYPE_INDEX], - "NCHAR", strlen("NCHAR"))) { - superTbls->columns[columnIndex].data_type = TSDB_DATA_TYPE_NCHAR; - } else if (0 == strncasecmp((char *)row[TSDB_DESCRIBE_METRIC_TYPE_INDEX], - "BOOL", strlen("BOOL"))) { - superTbls->columns[columnIndex].data_type = TSDB_DATA_TYPE_BOOL; - } else if (0 == strncasecmp((char *)row[TSDB_DESCRIBE_METRIC_TYPE_INDEX], - "TIMESTAMP", strlen("TIMESTAMP"))) { - superTbls->columns[columnIndex].data_type = TSDB_DATA_TYPE_TIMESTAMP; - } else if (0 == strncasecmp((char *)row[TSDB_DESCRIBE_METRIC_TYPE_INDEX], - "TINYINT UNSIGNED", strlen("TINYINT UNSIGNED"))) { - superTbls->columns[columnIndex].data_type = TSDB_DATA_TYPE_UTINYINT; - tstrncpy(superTbls->columns[columnIndex].dataType,"UTINYINT", - min(DATATYPE_BUFF_LEN, - fields[TSDB_DESCRIBE_METRIC_TYPE_INDEX].bytes) + 1); - } else if (0 == strncasecmp((char *)row[TSDB_DESCRIBE_METRIC_TYPE_INDEX], - "SMALLINT UNSIGNED", strlen("SMALLINT UNSIGNED"))) { - superTbls->columns[columnIndex].data_type = TSDB_DATA_TYPE_USMALLINT; - tstrncpy(superTbls->columns[columnIndex].dataType,"USMALLINT", - min(DATATYPE_BUFF_LEN, - fields[TSDB_DESCRIBE_METRIC_TYPE_INDEX].bytes) + 1); - } else if (0 == strncasecmp((char *)row[TSDB_DESCRIBE_METRIC_TYPE_INDEX], - "INT UNSIGNED", strlen("INT UNSIGNED"))) { - superTbls->columns[columnIndex].data_type = TSDB_DATA_TYPE_UINT; - tstrncpy(superTbls->columns[columnIndex].dataType,"UINT", - min(DATATYPE_BUFF_LEN, - fields[TSDB_DESCRIBE_METRIC_TYPE_INDEX].bytes) + 1); - } else if (0 == strncasecmp((char *)row[TSDB_DESCRIBE_METRIC_TYPE_INDEX], - "BIGINT UNSIGNED", strlen("BIGINT UNSIGNED"))) { - superTbls->columns[columnIndex].data_type = TSDB_DATA_TYPE_UBIGINT; - tstrncpy(superTbls->columns[columnIndex].dataType,"UBIGINT", - min(DATATYPE_BUFF_LEN, - fields[TSDB_DESCRIBE_METRIC_TYPE_INDEX].bytes) + 1); - } else { - superTbls->columns[columnIndex].data_type = TSDB_DATA_TYPE_NULL; - } - superTbls->columns[columnIndex].dataLen = - *((int *)row[TSDB_DESCRIBE_METRIC_LENGTH_INDEX]); - tstrncpy(superTbls->columns[columnIndex].note, - (char *)row[TSDB_DESCRIBE_METRIC_NOTE_INDEX], - min(NOTE_BUFF_LEN, - fields[TSDB_DESCRIBE_METRIC_NOTE_INDEX].bytes) + 1); - - if (strstr((char *)row[TSDB_DESCRIBE_METRIC_TYPE_INDEX], "UNSIGNED") == NULL) { - tstrncpy(superTbls->columns[columnIndex].dataType, - (char *)row[TSDB_DESCRIBE_METRIC_TYPE_INDEX], - min(DATATYPE_BUFF_LEN, - fields[TSDB_DESCRIBE_METRIC_TYPE_INDEX].bytes) + 1); - } - - columnIndex++; - } - count++; - } - - superTbls->columnCount = columnIndex; - superTbls->tagCount = tagIndex; - taos_free_result(res); - - calcRowLen(superTbls); - - /* - if (TBL_ALREADY_EXISTS == superTbls->childTblExists) { - //get all child table name use cmd: select tbname from superTblName; - int childTblCount = 10000; - superTbls->childTblName = (char*)calloc(1, childTblCount * TSDB_TABLE_NAME_LEN); - if (superTbls->childTblName == NULL) { - errorPrint2("%s() LN%d, alloc memory failed!\n", __func__, __LINE__); - return -1; - } - getAllChildNameOfSuperTable(taos, dbName, - superTbls->stbName, - &superTbls->childTblName, - &superTbls->childTblCount); - } - */ - return 0; -} - -static int createSuperTable( - TAOS * taos, char* dbName, - SSuperTable* superTbl) { - - char *command = calloc(1, BUFFER_SIZE); - assert(command); - - char cols[COL_BUFFER_LEN] = "\0"; - int len = 0; - - int lenOfOneRow = 0; - - if (superTbl->columnCount == 0) { - errorPrint2("%s() LN%d, super table column count is %d\n", - __func__, __LINE__, superTbl->columnCount); - free(command); - return -1; - } - - for (int colIndex = 0; colIndex < superTbl->columnCount; colIndex++) { - - switch(superTbl->columns[colIndex].data_type) { - case TSDB_DATA_TYPE_BINARY: - len += snprintf(cols + len, COL_BUFFER_LEN - len, - ",C%d %s(%d)", colIndex, "BINARY", - superTbl->columns[colIndex].dataLen); - lenOfOneRow += superTbl->columns[colIndex].dataLen + 3; - break; - - case TSDB_DATA_TYPE_NCHAR: - len += snprintf(cols + len, COL_BUFFER_LEN - len, - ",C%d %s(%d)", colIndex, "NCHAR", - superTbl->columns[colIndex].dataLen); - lenOfOneRow += superTbl->columns[colIndex].dataLen + 3; - break; - - case TSDB_DATA_TYPE_INT: - if ((g_args.demo_mode) && (colIndex == 1)) { - len += snprintf(cols + len, COL_BUFFER_LEN - len, - ", VOLTAGE INT"); - } else { - len += snprintf(cols + len, COL_BUFFER_LEN - len, ",C%d %s", colIndex, "INT"); - } - lenOfOneRow += INT_BUFF_LEN; - break; - - case TSDB_DATA_TYPE_BIGINT: - len += snprintf(cols + len, COL_BUFFER_LEN - len, ",C%d %s", - colIndex, "BIGINT"); - lenOfOneRow += BIGINT_BUFF_LEN; - break; - - case TSDB_DATA_TYPE_SMALLINT: - len += snprintf(cols + len, COL_BUFFER_LEN - len, ",C%d %s", - colIndex, "SMALLINT"); - lenOfOneRow += SMALLINT_BUFF_LEN; - break; - - case TSDB_DATA_TYPE_TINYINT: - len += snprintf(cols + len, COL_BUFFER_LEN - len, ",C%d %s", colIndex, "TINYINT"); - lenOfOneRow += TINYINT_BUFF_LEN; - break; - - case TSDB_DATA_TYPE_BOOL: - len += snprintf(cols + len, COL_BUFFER_LEN - len, ",C%d %s", colIndex, "BOOL"); - lenOfOneRow += BOOL_BUFF_LEN; - break; - - case TSDB_DATA_TYPE_FLOAT: - if (g_args.demo_mode) { - if (colIndex == 0) { - len += snprintf(cols + len, COL_BUFFER_LEN - len, ", CURRENT FLOAT"); - } else if (colIndex == 2) { - len += snprintf(cols + len, COL_BUFFER_LEN - len, ", PHASE FLOAT"); - } - } else { - len += snprintf(cols + len, COL_BUFFER_LEN - len, ",C%d %s", colIndex, "FLOAT"); - } - - lenOfOneRow += FLOAT_BUFF_LEN; - break; - - case TSDB_DATA_TYPE_DOUBLE: - len += snprintf(cols + len, COL_BUFFER_LEN - len, ",C%d %s", - colIndex, "DOUBLE"); - lenOfOneRow += DOUBLE_BUFF_LEN; - break; - - case TSDB_DATA_TYPE_TIMESTAMP: - len += snprintf(cols + len, COL_BUFFER_LEN - len, ",C%d %s", - colIndex, "TIMESTAMP"); - lenOfOneRow += TIMESTAMP_BUFF_LEN; - break; - - case TSDB_DATA_TYPE_UTINYINT: - len += snprintf(cols + len, COL_BUFFER_LEN - len, ",C%d %s", - colIndex, "TINYINT UNSIGNED"); - lenOfOneRow += TINYINT_BUFF_LEN; - break; - - case TSDB_DATA_TYPE_USMALLINT: - len += snprintf(cols + len, COL_BUFFER_LEN - len, ",C%d %s", - colIndex, "SMALLINT UNSIGNED"); - lenOfOneRow += SMALLINT_BUFF_LEN; - break; - - case TSDB_DATA_TYPE_UINT: - len += snprintf(cols + len, COL_BUFFER_LEN - len, ",C%d %s", - colIndex, "INT UNSIGNED"); - lenOfOneRow += INT_BUFF_LEN; - break; - - case TSDB_DATA_TYPE_UBIGINT: - len += snprintf(cols + len, COL_BUFFER_LEN - len, ",C%d %s", - colIndex, "BIGINT UNSIGNED"); - lenOfOneRow += BIGINT_BUFF_LEN; - break; - - default: - taos_close(taos); - free(command); - errorPrint2("%s() LN%d, config error data type : %s\n", - __func__, __LINE__, superTbl->columns[colIndex].dataType); - exit(EXIT_FAILURE); - } - } - - superTbl->lenOfOneRow = lenOfOneRow + TIMESTAMP_BUFF_LEN; // timestamp - - // save for creating child table - superTbl->colsOfCreateChildTable = (char*)calloc(len+TIMESTAMP_BUFF_LEN, 1); - if (NULL == superTbl->colsOfCreateChildTable) { - taos_close(taos); - free(command); - errorPrint2("%s() LN%d, Failed when calloc, size:%d", - __func__, __LINE__, len+1); - exit(EXIT_FAILURE); - } - - snprintf(superTbl->colsOfCreateChildTable, len+TIMESTAMP_BUFF_LEN, "(ts timestamp%s)", cols); - verbosePrint("%s() LN%d: %s\n", - __func__, __LINE__, superTbl->colsOfCreateChildTable); - - if (superTbl->tagCount == 0) { - errorPrint2("%s() LN%d, super table tag count is %d\n", - __func__, __LINE__, superTbl->tagCount); - free(command); - return -1; - } - - char tags[TSDB_MAX_TAGS_LEN] = "\0"; - int tagIndex; - len = 0; - - int lenOfTagOfOneRow = 0; - len += snprintf(tags + len, TSDB_MAX_TAGS_LEN - len, "("); - for (tagIndex = 0; tagIndex < superTbl->tagCount; tagIndex++) { - char* dataType = superTbl->tags[tagIndex].dataType; - - if (strcasecmp(dataType, "BINARY") == 0) { - if ((g_args.demo_mode) && (tagIndex == 1)) { - len += snprintf(tags + len, TSDB_MAX_TAGS_LEN - len, - "location BINARY(%d),", - superTbl->tags[tagIndex].dataLen); - } else { - len += snprintf(tags + len, TSDB_MAX_TAGS_LEN - len, - "T%d %s(%d),", tagIndex, "BINARY", - superTbl->tags[tagIndex].dataLen); - } - lenOfTagOfOneRow += superTbl->tags[tagIndex].dataLen + 3; - } else if (strcasecmp(dataType, "NCHAR") == 0) { - len += snprintf(tags + len, TSDB_MAX_TAGS_LEN - len, - "T%d %s(%d),", tagIndex, - "NCHAR", superTbl->tags[tagIndex].dataLen); - lenOfTagOfOneRow += superTbl->tags[tagIndex].dataLen + 3; - } else if (strcasecmp(dataType, "INT") == 0) { - if ((g_args.demo_mode) && (tagIndex == 0)) { - len += snprintf(tags + len, TSDB_MAX_TAGS_LEN - len, - "groupId INT, "); - } else { - len += snprintf(tags + len, TSDB_MAX_TAGS_LEN - len, - "T%d %s,", tagIndex, "INT"); - } - lenOfTagOfOneRow += superTbl->tags[tagIndex].dataLen + INT_BUFF_LEN; - } else if (strcasecmp(dataType, "BIGINT") == 0) { - len += snprintf(tags + len, TSDB_MAX_TAGS_LEN - len, - "T%d %s,", tagIndex, "BIGINT"); - lenOfTagOfOneRow += superTbl->tags[tagIndex].dataLen + BIGINT_BUFF_LEN; - } else if (strcasecmp(dataType, "SMALLINT") == 0) { - len += snprintf(tags + len, TSDB_MAX_TAGS_LEN - len, - "T%d %s,", tagIndex, "SMALLINT"); - lenOfTagOfOneRow += superTbl->tags[tagIndex].dataLen + SMALLINT_BUFF_LEN; - } else if (strcasecmp(dataType, "TINYINT") == 0) { - len += snprintf(tags + len, TSDB_MAX_TAGS_LEN - len, - "T%d %s,", tagIndex, "TINYINT"); - lenOfTagOfOneRow += superTbl->tags[tagIndex].dataLen + TINYINT_BUFF_LEN; - } else if (strcasecmp(dataType, "BOOL") == 0) { - len += snprintf(tags + len, TSDB_MAX_TAGS_LEN - len, - "T%d %s,", tagIndex, "BOOL"); - lenOfTagOfOneRow += superTbl->tags[tagIndex].dataLen + BOOL_BUFF_LEN; - } else if (strcasecmp(dataType, "FLOAT") == 0) { - len += snprintf(tags + len, TSDB_MAX_TAGS_LEN - len, - "T%d %s,", tagIndex, "FLOAT"); - lenOfTagOfOneRow += superTbl->tags[tagIndex].dataLen + FLOAT_BUFF_LEN; - } else if (strcasecmp(dataType, "DOUBLE") == 0) { - len += snprintf(tags + len, TSDB_MAX_TAGS_LEN - len, - "T%d %s,", tagIndex, "DOUBLE"); - lenOfTagOfOneRow += superTbl->tags[tagIndex].dataLen + DOUBLE_BUFF_LEN; - } else if (strcasecmp(dataType, "UTINYINT") == 0) { - len += snprintf(tags + len, TSDB_MAX_TAGS_LEN - len, - "T%d %s,", tagIndex, "TINYINT UNSIGNED"); - lenOfTagOfOneRow += superTbl->tags[tagIndex].dataLen + TINYINT_BUFF_LEN; - } else if (strcasecmp(dataType, "USMALLINT") == 0) { - len += snprintf(tags + len, TSDB_MAX_TAGS_LEN - len, - "T%d %s,", tagIndex, "SMALLINT UNSIGNED"); - lenOfTagOfOneRow += superTbl->tags[tagIndex].dataLen + SMALLINT_BUFF_LEN; - } else if (strcasecmp(dataType, "UINT") == 0) { - len += snprintf(tags + len, TSDB_MAX_TAGS_LEN - len, - "T%d %s,", tagIndex, "INT UNSIGNED"); - lenOfTagOfOneRow += superTbl->tags[tagIndex].dataLen + INT_BUFF_LEN; - } else if (strcasecmp(dataType, "UBIGINT") == 0) { - len += snprintf(tags + len, TSDB_MAX_TAGS_LEN - len, - "T%d %s,", tagIndex, "BIGINT UNSIGNED"); - lenOfTagOfOneRow += superTbl->tags[tagIndex].dataLen + BIGINT_BUFF_LEN; - } else if (strcasecmp(dataType, "TIMESTAMP") == 0) { - len += snprintf(tags + len, TSDB_MAX_TAGS_LEN - len, - "T%d %s,", tagIndex, "TIMESTAMP"); - lenOfTagOfOneRow += superTbl->tags[tagIndex].dataLen + TIMESTAMP_BUFF_LEN; - } else { - taos_close(taos); - free(command); - errorPrint2("%s() LN%d, config error tag type : %s\n", - __func__, __LINE__, dataType); - exit(EXIT_FAILURE); - } - } - - len -= 1; - len += snprintf(tags + len, TSDB_MAX_TAGS_LEN - len, ")"); - - superTbl->lenOfTagOfOneRow = lenOfTagOfOneRow; - - - snprintf(command, BUFFER_SIZE, - superTbl->escapeChar ? - "CREATE TABLE IF NOT EXISTS %s.`%s` (ts TIMESTAMP%s) TAGS %s": - "CREATE TABLE IF NOT EXISTS %s.%s (ts TIMESTAMP%s) TAGS %s", - dbName, superTbl->stbName, cols, tags); - if (0 != queryDbExec(taos, command, NO_INSERT_TYPE, false)) { - errorPrint2("create supertable %s failed!\n\n", - superTbl->stbName); - free(command); - return -1; - } - - debugPrint("create supertable %s success!\n\n", superTbl->stbName); - free(command); - return 0; -} - -int createDatabasesAndStables(char *command) { - TAOS * taos = NULL; - int ret = 0; - taos = taos_connect(g_Dbs.host, g_Dbs.user, g_Dbs.password, NULL, g_Dbs.port); - if (taos == NULL) { - errorPrint2("Failed to connect to TDengine, reason:%s\n", taos_errstr(NULL)); - return -1; - } - - for (int i = 0; i < g_Dbs.dbCount; i++) { - if (g_Dbs.db[i].drop) { - sprintf(command, "drop database if exists %s;", g_Dbs.db[i].dbName); - if (0 != queryDbExec(taos, command, NO_INSERT_TYPE, false)) { - taos_close(taos); - return -1; - } - - int dataLen = 0; - dataLen += snprintf(command + dataLen, - BUFFER_SIZE - dataLen, "CREATE DATABASE IF NOT EXISTS %s", - g_Dbs.db[i].dbName); - - if (g_Dbs.db[i].dbCfg.blocks > 0) { - dataLen += snprintf(command + dataLen, - BUFFER_SIZE - dataLen, " BLOCKS %d", - g_Dbs.db[i].dbCfg.blocks); - } - if (g_Dbs.db[i].dbCfg.cache > 0) { - dataLen += snprintf(command + dataLen, - BUFFER_SIZE - dataLen, " CACHE %d", - g_Dbs.db[i].dbCfg.cache); - } - if (g_Dbs.db[i].dbCfg.days > 0) { - dataLen += snprintf(command + dataLen, - BUFFER_SIZE - dataLen, " DAYS %d", - g_Dbs.db[i].dbCfg.days); - } - if (g_Dbs.db[i].dbCfg.keep > 0) { - dataLen += snprintf(command + dataLen, - BUFFER_SIZE - dataLen, " KEEP %d", - g_Dbs.db[i].dbCfg.keep); - } - if (g_Dbs.db[i].dbCfg.quorum > 1) { - dataLen += snprintf(command + dataLen, - BUFFER_SIZE - dataLen, " QUORUM %d", - g_Dbs.db[i].dbCfg.quorum); - } - if (g_Dbs.db[i].dbCfg.replica > 0) { - dataLen += snprintf(command + dataLen, - BUFFER_SIZE - dataLen, " REPLICA %d", - g_Dbs.db[i].dbCfg.replica); - } - if (g_Dbs.db[i].dbCfg.update > 0) { - dataLen += snprintf(command + dataLen, - BUFFER_SIZE - dataLen, " UPDATE %d", - g_Dbs.db[i].dbCfg.update); - } - //if (g_Dbs.db[i].dbCfg.maxtablesPerVnode > 0) { - // dataLen += snprintf(command + dataLen, - // BUFFER_SIZE - dataLen, "tables %d ", g_Dbs.db[i].dbCfg.maxtablesPerVnode); - //} - if (g_Dbs.db[i].dbCfg.minRows > 0) { - dataLen += snprintf(command + dataLen, - BUFFER_SIZE - dataLen, " MINROWS %d", - g_Dbs.db[i].dbCfg.minRows); - } - if (g_Dbs.db[i].dbCfg.maxRows > 0) { - dataLen += snprintf(command + dataLen, - BUFFER_SIZE - dataLen, " MAXROWS %d", - g_Dbs.db[i].dbCfg.maxRows); - } - if (g_Dbs.db[i].dbCfg.comp > 0) { - dataLen += snprintf(command + dataLen, - BUFFER_SIZE - dataLen, " COMP %d", - g_Dbs.db[i].dbCfg.comp); - } - if (g_Dbs.db[i].dbCfg.walLevel > 0) { - dataLen += snprintf(command + dataLen, - BUFFER_SIZE - dataLen, " wal %d", - g_Dbs.db[i].dbCfg.walLevel); - } - if (g_Dbs.db[i].dbCfg.cacheLast > 0) { - dataLen += snprintf(command + dataLen, - BUFFER_SIZE - dataLen, " CACHELAST %d", - g_Dbs.db[i].dbCfg.cacheLast); - } - if (g_Dbs.db[i].dbCfg.fsync > 0) { - dataLen += snprintf(command + dataLen, BUFFER_SIZE - dataLen, - " FSYNC %d", g_Dbs.db[i].dbCfg.fsync); - } - if ((0 == strncasecmp(g_Dbs.db[i].dbCfg.precision, "ms", 2)) - || (0 == strncasecmp(g_Dbs.db[i].dbCfg.precision, - "ns", 2)) - || (0 == strncasecmp(g_Dbs.db[i].dbCfg.precision, - "us", 2))) { - dataLen += snprintf(command + dataLen, BUFFER_SIZE - dataLen, - " precision \'%s\';", g_Dbs.db[i].dbCfg.precision); - } - - if (0 != queryDbExec(taos, command, NO_INSERT_TYPE, false)) { - taos_close(taos); - errorPrint("\ncreate database %s failed!\n\n", - g_Dbs.db[i].dbName); - return -1; - } - printf("\ncreate database %s success!\n\n", g_Dbs.db[i].dbName); - } - - debugPrint("%s() LN%d supertbl count:%"PRIu64"\n", - __func__, __LINE__, g_Dbs.db[i].superTblCount); - - int validStbCount = 0; - - for (uint64_t j = 0; j < g_Dbs.db[i].superTblCount; j++) { - if (g_Dbs.db[i].superTbls[j].iface == SML_IFACE) { - goto skip; - } - - sprintf(command, "describe %s.%s;", g_Dbs.db[i].dbName, - g_Dbs.db[i].superTbls[j].stbName); - ret = queryDbExec(taos, command, NO_INSERT_TYPE, true); - - if ((ret != 0) || (g_Dbs.db[i].drop)) { - ret = createSuperTable(taos, g_Dbs.db[i].dbName, - &g_Dbs.db[i].superTbls[j]); - - if (0 != ret) { - errorPrint("create super table %"PRIu64" failed!\n\n", j); - continue; - } - } else { - ret = getSuperTableFromServer(taos, g_Dbs.db[i].dbName, - &g_Dbs.db[i].superTbls[j]); - if (0 != ret) { - errorPrint2("\nget super table %s.%s info failed!\n\n", - g_Dbs.db[i].dbName, g_Dbs.db[i].superTbls[j].stbName); - continue; - } - } - skip: - validStbCount ++; - } - g_Dbs.db[i].superTblCount = validStbCount; - } - - taos_close(taos); - return 0; -} - -static void* createTable(void *sarg) -{ - threadInfo *pThreadInfo = (threadInfo *)sarg; - SSuperTable* stbInfo = pThreadInfo->stbInfo; - - setThreadName("createTable"); - - uint64_t lastPrintTime = taosGetTimestampMs(); - - int buff_len = BUFFER_SIZE; - - pThreadInfo->buffer = calloc(buff_len, 1); - if (pThreadInfo->buffer == NULL) { - errorPrint2("%s() LN%d, Memory allocated failed!\n", __func__, __LINE__); - exit(EXIT_FAILURE); - } - - int len = 0; - int batchNum = 0; - - verbosePrint("%s() LN%d: Creating table from %"PRIu64" to %"PRIu64"\n", - __func__, __LINE__, - pThreadInfo->start_table_from, pThreadInfo->end_table_to); - - for (uint64_t i = pThreadInfo->start_table_from; - i <= pThreadInfo->end_table_to; i++) { - if (0 == g_Dbs.use_metric) { - snprintf(pThreadInfo->buffer, buff_len, - g_args.escapeChar ? - "CREATE TABLE IF NOT EXISTS %s.`%s%"PRIu64"` %s;" : - "CREATE TABLE IF NOT EXISTS %s.%s%"PRIu64" %s;", - pThreadInfo->db_name, - g_args.tb_prefix, i, - pThreadInfo->cols); - batchNum ++; - } else { - if (stbInfo == NULL) { - free(pThreadInfo->buffer); - errorPrint2("%s() LN%d, use metric, but super table info is NULL\n", - __func__, __LINE__); - exit(EXIT_FAILURE); - } else { - if (0 == len) { - batchNum = 0; - memset(pThreadInfo->buffer, 0, buff_len); - len += snprintf(pThreadInfo->buffer + len, - buff_len - len, "CREATE TABLE "); - } - - char* tagsValBuf = NULL; - if (0 == stbInfo->tagSource) { - tagsValBuf = generateTagValuesForStb(stbInfo, i); - } else { - if (0 == stbInfo->tagSampleCount) { - free(pThreadInfo->buffer); - ERROR_EXIT("use sample file for tag, but has no content!\n"); - } - tagsValBuf = getTagValueFromTagSample( - stbInfo, - i % stbInfo->tagSampleCount); - } - - if (NULL == tagsValBuf) { - free(pThreadInfo->buffer); - ERROR_EXIT("use metric, but tag buffer is NULL\n"); - } - len += snprintf(pThreadInfo->buffer + len, - buff_len - len, stbInfo->escapeChar ? - "if not exists %s.`%s%"PRIu64"` using %s.`%s` tags %s " : - "if not exists %s.%s%"PRIu64" using %s.%s tags %s ", - pThreadInfo->db_name, stbInfo->childTblPrefix, - i, pThreadInfo->db_name, - stbInfo->stbName, tagsValBuf); - free(tagsValBuf); - batchNum++; - if ((batchNum < stbInfo->batchCreateTableNum) - && ((buff_len - len) - >= (stbInfo->lenOfTagOfOneRow + EXTRA_SQL_LEN))) { - continue; - } - } - } - - len = 0; - - if (0 != queryDbExec(pThreadInfo->taos, pThreadInfo->buffer, - NO_INSERT_TYPE, false)) { - errorPrint2("queryDbExec() failed. buffer:\n%s\n", pThreadInfo->buffer); - free(pThreadInfo->buffer); - return NULL; - } - pThreadInfo->tables_created += batchNum; - uint64_t currentPrintTime = taosGetTimestampMs(); - if (currentPrintTime - lastPrintTime > PRINT_STAT_INTERVAL) { - printf("thread[%d] already create %"PRIu64" - %"PRIu64" tables\n", - pThreadInfo->threadID, pThreadInfo->start_table_from, i); - lastPrintTime = currentPrintTime; - } - } - - if (0 != len) { - if (0 != queryDbExec(pThreadInfo->taos, pThreadInfo->buffer, - NO_INSERT_TYPE, false)) { - errorPrint2("queryDbExec() failed. buffer:\n%s\n", pThreadInfo->buffer); - } - pThreadInfo->tables_created += batchNum; - } - free(pThreadInfo->buffer); - return NULL; -} - -static int startMultiThreadCreateChildTable( - char* cols, int threads, uint64_t tableFrom, int64_t ntables, - char* db_name, SSuperTable* stbInfo) { - - pthread_t *pids = calloc(1, threads * sizeof(pthread_t)); - threadInfo *infos = calloc(1, threads * sizeof(threadInfo)); - - if ((NULL == pids) || (NULL == infos)) { - ERROR_EXIT("createChildTable malloc failed\n"); - } - - if (threads < 1) { - threads = 1; - } - - int64_t a = ntables / threads; - if (a < 1) { - threads = ntables; - a = 1; - } - - int64_t b = 0; - b = ntables % threads; - - for (int64_t i = 0; i < threads; i++) { - threadInfo *pThreadInfo = infos + i; - pThreadInfo->threadID = i; - tstrncpy(pThreadInfo->db_name, db_name, TSDB_DB_NAME_LEN); - pThreadInfo->stbInfo = stbInfo; - verbosePrint("%s() %d db_name: %s\n", __func__, __LINE__, db_name); - pThreadInfo->taos = taos_connect( - g_Dbs.host, - g_Dbs.user, - g_Dbs.password, - db_name, - g_Dbs.port); - if (pThreadInfo->taos == NULL) { - errorPrint2("%s() LN%d, Failed to connect to TDengine, reason:%s\n", - __func__, __LINE__, taos_errstr(NULL)); - free(pids); - free(infos); - return -1; - } - - pThreadInfo->start_table_from = tableFrom; - pThreadInfo->ntables = iend_table_to = i < b ? tableFrom + a : tableFrom + a - 1; - tableFrom = pThreadInfo->end_table_to + 1; - pThreadInfo->use_metric = true; - pThreadInfo->cols = cols; - pThreadInfo->minDelay = UINT64_MAX; - pThreadInfo->tables_created = 0; - pthread_create(pids + i, NULL, createTable, pThreadInfo); - } - - for (int i = 0; i < threads; i++) { - pthread_join(pids[i], NULL); - } - - for (int i = 0; i < threads; i++) { - threadInfo *pThreadInfo = infos + i; - taos_close(pThreadInfo->taos); - - g_actualChildTables += pThreadInfo->tables_created; - } - - free(pids); - free(infos); - - return 0; -} - -static void createChildTables() { - char tblColsBuf[TSDB_MAX_BYTES_PER_ROW]; - int len; - - for (int i = 0; i < g_Dbs.dbCount; i++) { - if (g_Dbs.use_metric) { - if (g_Dbs.db[i].superTblCount > 0) { - // with super table - for (int j = 0; j < g_Dbs.db[i].superTblCount; j++) { - if ((AUTO_CREATE_SUBTBL - == g_Dbs.db[i].superTbls[j].autoCreateTable) - || (TBL_ALREADY_EXISTS - == g_Dbs.db[i].superTbls[j].childTblExists)) { - continue; - } - verbosePrint("%s() LN%d: %s\n", __func__, __LINE__, - g_Dbs.db[i].superTbls[j].colsOfCreateChildTable); - uint64_t startFrom = 0; - - verbosePrint("%s() LN%d: create %"PRId64" child tables from %"PRIu64"\n", - __func__, __LINE__, g_totalChildTables, startFrom); - - startMultiThreadCreateChildTable( - g_Dbs.db[i].superTbls[j].colsOfCreateChildTable, - g_Dbs.threadCountForCreateTbl, - startFrom, - g_Dbs.db[i].superTbls[j].childTblCount, - g_Dbs.db[i].dbName, &(g_Dbs.db[i].superTbls[j])); - } - } - } else { - // normal table - len = snprintf(tblColsBuf, TSDB_MAX_BYTES_PER_ROW, "(TS TIMESTAMP"); - for (int j = 0; j < g_args.columnCount; j++) { - if ((strncasecmp(g_args.dataType[j], "BINARY", strlen("BINARY")) == 0) - || (strncasecmp(g_args.dataType[j], - "NCHAR", strlen("NCHAR")) == 0)) { - snprintf(tblColsBuf + len, TSDB_MAX_BYTES_PER_ROW - len, - ",C%d %s(%d)", j, g_args.dataType[j], g_args.binwidth); - } else { - snprintf(tblColsBuf + len, TSDB_MAX_BYTES_PER_ROW - len, - ",C%d %s", j, g_args.dataType[j]); - } - len = strlen(tblColsBuf); - } - - snprintf(tblColsBuf + len, TSDB_MAX_BYTES_PER_ROW - len, ")"); - - verbosePrint("%s() LN%d: dbName: %s num of tb: %"PRId64" schema: %s\n", - __func__, __LINE__, - g_Dbs.db[i].dbName, g_args.ntables, tblColsBuf); - startMultiThreadCreateChildTable( - tblColsBuf, - g_Dbs.threadCountForCreateTbl, - 0, - g_args.ntables, - g_Dbs.db[i].dbName, - NULL); - } - } -} - -/* - Read 10000 lines at most. If more than 10000 lines, continue to read after using - */ -static int readTagFromCsvFileToMem(SSuperTable * stbInfo) { - size_t n = 0; - ssize_t readLen = 0; - char * line = NULL; - - FILE *fp = fopen(stbInfo->tagsFile, "r"); - if (fp == NULL) { - printf("Failed to open tags file: %s, reason:%s\n", - stbInfo->tagsFile, strerror(errno)); - return -1; - } - - if (stbInfo->tagDataBuf) { - free(stbInfo->tagDataBuf); - stbInfo->tagDataBuf = NULL; - } - - int tagCount = MAX_SAMPLES; - int count = 0; - char* tagDataBuf = calloc(1, stbInfo->lenOfTagOfOneRow * tagCount); - if (tagDataBuf == NULL) { - printf("Failed to calloc, reason:%s\n", strerror(errno)); - fclose(fp); - return -1; - } - - while((readLen = tgetline(&line, &n, fp)) != -1) { - if (('\r' == line[readLen - 1]) || ('\n' == line[readLen - 1])) { - line[--readLen] = 0; - } - - if (readLen == 0) { - continue; - } - - memcpy(tagDataBuf + count * stbInfo->lenOfTagOfOneRow, line, readLen); - count++; - - if (count >= tagCount - 1) { - char *tmp = realloc(tagDataBuf, - (size_t)tagCount*1.5*stbInfo->lenOfTagOfOneRow); - if (tmp != NULL) { - tagDataBuf = tmp; - tagCount = (int)(tagCount*1.5); - memset(tagDataBuf + count*stbInfo->lenOfTagOfOneRow, - 0, (size_t)((tagCount-count)*stbInfo->lenOfTagOfOneRow)); - } else { - // exit, if allocate more memory failed - printf("realloc fail for save tag val from %s\n", stbInfo->tagsFile); - tmfree(tagDataBuf); - free(line); - fclose(fp); - return -1; - } - } - } - - stbInfo->tagDataBuf = tagDataBuf; - stbInfo->tagSampleCount = count; - - free(line); - fclose(fp); - return 0; -} - -static void getAndSetRowsFromCsvFile(SSuperTable *stbInfo) { - FILE *fp = fopen(stbInfo->sampleFile, "r"); - int line_count = 0; - if (fp == NULL) { - errorPrint("Failed to open sample file: %s, reason:%s\n", - stbInfo->sampleFile, strerror(errno)); - exit(EXIT_FAILURE); - } - char *buf = calloc(1, stbInfo->maxSqlLen); - while (fgets(buf, stbInfo->maxSqlLen, fp)) { - line_count++; - } - fclose(fp); - tmfree(buf); - stbInfo->insertRows = line_count; -} - -/* - Read 10000 lines at most. If more than 10000 lines, continue to read after using - */ -static int generateSampleFromCsvForStb( - SSuperTable* stbInfo) { - size_t n = 0; - ssize_t readLen = 0; - char * line = NULL; - int getRows = 0; - - FILE* fp = fopen(stbInfo->sampleFile, "r"); - if (fp == NULL) { - errorPrint("Failed to open sample file: %s, reason:%s\n", - stbInfo->sampleFile, strerror(errno)); - return -1; - } - - assert(stbInfo->sampleDataBuf); - memset(stbInfo->sampleDataBuf, 0, - MAX_SAMPLES * stbInfo->lenOfOneRow); - while(1) { - readLen = tgetline(&line, &n, fp); - if (-1 == readLen) { - if(0 != fseek(fp, 0, SEEK_SET)) { - errorPrint("Failed to fseek file: %s, reason:%s\n", - stbInfo->sampleFile, strerror(errno)); - fclose(fp); - return -1; - } - continue; - } - - if (('\r' == line[readLen - 1]) || ('\n' == line[readLen - 1])) { - line[--readLen] = 0; - } - - if (readLen == 0) { - continue; - } - - if (readLen > stbInfo->lenOfOneRow) { - printf("sample row len[%d] overflow define schema len[%"PRIu64"], so discard this row\n", - (int32_t)readLen, stbInfo->lenOfOneRow); - continue; - } - - memcpy(stbInfo->sampleDataBuf + getRows * stbInfo->lenOfOneRow, - line, readLen); - getRows++; - - if (getRows == MAX_SAMPLES) { - break; - } - } - - fclose(fp); - tmfree(line); - return 0; -} - -static bool getColumnAndTagTypeFromInsertJsonFile( - cJSON* stbInfo, SSuperTable* superTbls) { - bool ret = false; - - // columns - cJSON *columns = cJSON_GetObjectItem(stbInfo, "columns"); - if (columns && columns->type != cJSON_Array) { - errorPrint("%s", "failed to read json, columns not found\n"); - goto PARSE_OVER; - } else if (NULL == columns) { - superTbls->columnCount = 0; - superTbls->tagCount = 0; - return true; - } - - int columnSize = cJSON_GetArraySize(columns); - if ((columnSize + 1/* ts */) > TSDB_MAX_COLUMNS) { - errorPrint("failed to read json, column size overflow, max column size is %d\n", - TSDB_MAX_COLUMNS); - goto PARSE_OVER; - } - - int count = 1; - int index = 0; - StrColumn columnCase; - - //superTbls->columnCount = columnSize; - for (int k = 0; k < columnSize; ++k) { - cJSON* column = cJSON_GetArrayItem(columns, k); - if (column == NULL) continue; - - count = 1; - cJSON* countObj = cJSON_GetObjectItem(column, "count"); - if (countObj && countObj->type == cJSON_Number) { - count = countObj->valueint; - } else if (countObj && countObj->type != cJSON_Number) { - errorPrint("%s", "failed to read json, column count not found\n"); - goto PARSE_OVER; - } else { - count = 1; - } - - // column info - memset(&columnCase, 0, sizeof(StrColumn)); - cJSON *dataType = cJSON_GetObjectItem(column, "type"); - if (!dataType || dataType->type != cJSON_String - || dataType->valuestring == NULL) { - errorPrint("%s", "failed to read json, column type not found\n"); - goto PARSE_OVER; - } - //tstrncpy(superTbls->columns[k].dataType, dataType->valuestring, DATATYPE_BUFF_LEN); - tstrncpy(columnCase.dataType, dataType->valuestring, - min(DATATYPE_BUFF_LEN, strlen(dataType->valuestring) + 1)); - - cJSON* dataLen = cJSON_GetObjectItem(column, "len"); - if (dataLen && dataLen->type == cJSON_Number) { - columnCase.dataLen = dataLen->valueint; - } else if (dataLen && dataLen->type != cJSON_Number) { - debugPrint("%s() LN%d: failed to read json, column len not found\n", - __func__, __LINE__); - goto PARSE_OVER; - } else { - columnCase.dataLen = SMALL_BUFF_LEN; - } - - for (int n = 0; n < count; ++n) { - tstrncpy(superTbls->columns[index].dataType, - columnCase.dataType, - min(DATATYPE_BUFF_LEN, strlen(columnCase.dataType) + 1)); - - superTbls->columns[index].dataLen = columnCase.dataLen; - index++; - } - } - - if ((index + 1 /* ts */) > MAX_NUM_COLUMNS) { - errorPrint("failed to read json, column size overflow, allowed max column size is %d\n", - MAX_NUM_COLUMNS); - goto PARSE_OVER; - } - - superTbls->columnCount = index; - - for (int c = 0; c < superTbls->columnCount; c++) { - if (0 == strncasecmp(superTbls->columns[c].dataType, - "INT", strlen("INT"))) { - superTbls->columns[c].data_type = TSDB_DATA_TYPE_INT; - } else if (0 == strncasecmp(superTbls->columns[c].dataType, - "TINYINT", strlen("TINYINT"))) { - superTbls->columns[c].data_type = TSDB_DATA_TYPE_TINYINT; - } else if (0 == strncasecmp(superTbls->columns[c].dataType, - "SMALLINT", strlen("SMALLINT"))) { - superTbls->columns[c].data_type = TSDB_DATA_TYPE_SMALLINT; - } else if (0 == strncasecmp(superTbls->columns[c].dataType, - "BIGINT", strlen("BIGINT"))) { - superTbls->columns[c].data_type = TSDB_DATA_TYPE_BIGINT; - } else if (0 == strncasecmp(superTbls->columns[c].dataType, - "FLOAT", strlen("FLOAT"))) { - superTbls->columns[c].data_type = TSDB_DATA_TYPE_FLOAT; - } else if (0 == strncasecmp(superTbls->columns[c].dataType, - "DOUBLE", strlen("DOUBLE"))) { - superTbls->columns[c].data_type = TSDB_DATA_TYPE_DOUBLE; - } else if (0 == strncasecmp(superTbls->columns[c].dataType, - "BINARY", strlen("BINARY"))) { - superTbls->columns[c].data_type = TSDB_DATA_TYPE_BINARY; - } else if (0 == strncasecmp(superTbls->columns[c].dataType, - "NCHAR", strlen("NCHAR"))) { - superTbls->columns[c].data_type = TSDB_DATA_TYPE_NCHAR; - } else if (0 == strncasecmp(superTbls->columns[c].dataType, - "BOOL", strlen("BOOL"))) { - superTbls->columns[c].data_type = TSDB_DATA_TYPE_BOOL; - } else if (0 == strncasecmp(superTbls->columns[c].dataType, - "TIMESTAMP", strlen("TIMESTAMP"))) { - superTbls->columns[c].data_type = TSDB_DATA_TYPE_TIMESTAMP; - } else if (0 == strncasecmp(superTbls->columns[c].dataType, - "UTINYINT", strlen("UTINYINT"))) { - superTbls->columns[c].data_type = TSDB_DATA_TYPE_UTINYINT; - } else if (0 == strncasecmp(superTbls->columns[c].dataType, - "USMALLINT", strlen("USMALLINT"))) { - superTbls->columns[c].data_type = TSDB_DATA_TYPE_USMALLINT; - } else if (0 == strncasecmp(superTbls->columns[c].dataType, - "UINT", strlen("UINT"))) { - superTbls->columns[c].data_type = TSDB_DATA_TYPE_UINT; - } else if (0 == strncasecmp(superTbls->columns[c].dataType, - "UBIGINT", strlen("UBIGINT"))) { - superTbls->columns[c].data_type = TSDB_DATA_TYPE_UBIGINT; - } else { - superTbls->columns[c].data_type = TSDB_DATA_TYPE_NULL; - } - } - - count = 1; - index = 0; - // tags - cJSON *tags = cJSON_GetObjectItem(stbInfo, "tags"); - if (!tags || tags->type != cJSON_Array) { - errorPrint("%s", "failed to read json, tags not found\n"); - goto PARSE_OVER; - } - - int tagSize = cJSON_GetArraySize(tags); - if (tagSize > TSDB_MAX_TAGS) { - errorPrint("failed to read json, tags size overflow, max tag size is %d\n", - TSDB_MAX_TAGS); - goto PARSE_OVER; - } - - //superTbls->tagCount = tagSize; - for (int k = 0; k < tagSize; ++k) { - cJSON* tag = cJSON_GetArrayItem(tags, k); - if (tag == NULL) continue; - - count = 1; - cJSON* countObj = cJSON_GetObjectItem(tag, "count"); - if (countObj && countObj->type == cJSON_Number) { - count = countObj->valueint; - } else if (countObj && countObj->type != cJSON_Number) { - errorPrint("%s", "failed to read json, column count not found\n"); - goto PARSE_OVER; - } else { - count = 1; - } - - // column info - memset(&columnCase, 0, sizeof(StrColumn)); - cJSON *dataType = cJSON_GetObjectItem(tag, "type"); - if (!dataType || dataType->type != cJSON_String - || dataType->valuestring == NULL) { - errorPrint("%s", "failed to read json, tag type not found\n"); - goto PARSE_OVER; - } - tstrncpy(columnCase.dataType, dataType->valuestring, - min(DATATYPE_BUFF_LEN, strlen(dataType->valuestring) + 1)); - - cJSON* dataLen = cJSON_GetObjectItem(tag, "len"); - if (dataLen && dataLen->type == cJSON_Number) { - columnCase.dataLen = dataLen->valueint; - } else if (dataLen && dataLen->type != cJSON_Number) { - errorPrint("%s", "failed to read json, column len not found\n"); - goto PARSE_OVER; - } else { - columnCase.dataLen = 0; - } - - for (int n = 0; n < count; ++n) { - tstrncpy(superTbls->tags[index].dataType, columnCase.dataType, - min(DATATYPE_BUFF_LEN, strlen(columnCase.dataType) + 1)); - superTbls->tags[index].dataLen = columnCase.dataLen; - index++; - } - } - - if (index > TSDB_MAX_TAGS) { - errorPrint("failed to read json, tags size overflow, allowed max tag count is %d\n", - TSDB_MAX_TAGS); - goto PARSE_OVER; - } - - superTbls->tagCount = index; - - for (int t = 0; t < superTbls->tagCount; t++) { - if (0 == strncasecmp(superTbls->tags[t].dataType, - "INT", strlen("INT"))) { - superTbls->tags[t].data_type = TSDB_DATA_TYPE_INT; - } else if (0 == strncasecmp(superTbls->tags[t].dataType, - "TINYINT", strlen("TINYINT"))) { - superTbls->tags[t].data_type = TSDB_DATA_TYPE_TINYINT; - } else if (0 == strncasecmp(superTbls->tags[t].dataType, - "SMALLINT", strlen("SMALLINT"))) { - superTbls->tags[t].data_type = TSDB_DATA_TYPE_SMALLINT; - } else if (0 == strncasecmp(superTbls->tags[t].dataType, - "BIGINT", strlen("BIGINT"))) { - superTbls->tags[t].data_type = TSDB_DATA_TYPE_BIGINT; - } else if (0 == strncasecmp(superTbls->tags[t].dataType, - "FLOAT", strlen("FLOAT"))) { - superTbls->tags[t].data_type = TSDB_DATA_TYPE_FLOAT; - } else if (0 == strncasecmp(superTbls->tags[t].dataType, - "DOUBLE", strlen("DOUBLE"))) { - superTbls->tags[t].data_type = TSDB_DATA_TYPE_DOUBLE; - } else if (0 == strncasecmp(superTbls->tags[t].dataType, - "BINARY", strlen("BINARY"))) { - superTbls->tags[t].data_type = TSDB_DATA_TYPE_BINARY; - } else if (0 == strncasecmp(superTbls->tags[t].dataType, - "NCHAR", strlen("NCHAR"))) { - superTbls->tags[t].data_type = TSDB_DATA_TYPE_NCHAR; - } else if (0 == strncasecmp(superTbls->tags[t].dataType, - "BOOL", strlen("BOOL"))) { - superTbls->tags[t].data_type = TSDB_DATA_TYPE_BOOL; - } else if (0 == strncasecmp(superTbls->tags[t].dataType, - "TIMESTAMP", strlen("TIMESTAMP"))) { - superTbls->tags[t].data_type = TSDB_DATA_TYPE_TIMESTAMP; - } else if (0 == strncasecmp(superTbls->tags[t].dataType, - "UTINYINT", strlen("UTINYINT"))) { - superTbls->tags[t].data_type = TSDB_DATA_TYPE_UTINYINT; - } else if (0 == strncasecmp(superTbls->tags[t].dataType, - "USMALLINT", strlen("USMALLINT"))) { - superTbls->tags[t].data_type = TSDB_DATA_TYPE_USMALLINT; - } else if (0 == strncasecmp(superTbls->tags[t].dataType, - "UINT", strlen("UINT"))) { - superTbls->tags[t].data_type = TSDB_DATA_TYPE_UINT; - } else if (0 == strncasecmp(superTbls->tags[t].dataType, - "UBIGINT", strlen("UBIGINT"))) { - superTbls->tags[t].data_type = TSDB_DATA_TYPE_UBIGINT; - } else { - superTbls->tags[t].data_type = TSDB_DATA_TYPE_NULL; - } - } - - if ((superTbls->columnCount + superTbls->tagCount + 1 /* ts */) > TSDB_MAX_COLUMNS) { - errorPrint("columns + tags is more than allowed max columns count: %d\n", - TSDB_MAX_COLUMNS); - goto PARSE_OVER; - } - ret = true; - -PARSE_OVER: - return ret; -} - -static bool getMetaFromInsertJsonFile(cJSON* root) { - bool ret = false; - - cJSON* cfgdir = cJSON_GetObjectItem(root, "cfgdir"); - if (cfgdir && cfgdir->type == cJSON_String && cfgdir->valuestring != NULL) { - tstrncpy(g_Dbs.cfgDir, cfgdir->valuestring, MAX_FILE_NAME_LEN); - } - - cJSON* host = cJSON_GetObjectItem(root, "host"); - if (host && host->type == cJSON_String && host->valuestring != NULL) { - tstrncpy(g_Dbs.host, host->valuestring, MAX_HOSTNAME_SIZE); - } else if (!host) { - tstrncpy(g_Dbs.host, "127.0.0.1", MAX_HOSTNAME_SIZE); - } else { - errorPrint("%s", "failed to read json, host not found\n"); - goto PARSE_OVER; - } - - cJSON* port = cJSON_GetObjectItem(root, "port"); - if (port && port->type == cJSON_Number) { - g_Dbs.port = port->valueint; - } else if (!port) { - g_Dbs.port = DEFAULT_PORT; - } - - cJSON* user = cJSON_GetObjectItem(root, "user"); - if (user && user->type == cJSON_String && user->valuestring != NULL) { - tstrncpy(g_Dbs.user, user->valuestring, MAX_USERNAME_SIZE); - } else if (!user) { - tstrncpy(g_Dbs.user, TSDB_DEFAULT_USER, MAX_USERNAME_SIZE); - } - - cJSON* password = cJSON_GetObjectItem(root, "password"); - if (password && password->type == cJSON_String && password->valuestring != NULL) { - tstrncpy(g_Dbs.password, password->valuestring, SHELL_MAX_PASSWORD_LEN); - } else if (!password) { - tstrncpy(g_Dbs.password, TSDB_DEFAULT_PASS, SHELL_MAX_PASSWORD_LEN); - } - - cJSON* resultfile = cJSON_GetObjectItem(root, "result_file"); - if (resultfile && resultfile->type == cJSON_String && resultfile->valuestring != NULL) { - tstrncpy(g_Dbs.resultFile, resultfile->valuestring, MAX_FILE_NAME_LEN); - } else if (!resultfile) { - tstrncpy(g_Dbs.resultFile, DEFAULT_OUTPUT, MAX_FILE_NAME_LEN); - } - - cJSON* threads = cJSON_GetObjectItem(root, "thread_count"); - if (threads && threads->type == cJSON_Number) { - g_Dbs.threadCount = threads->valueint; - } else if (!threads) { - g_Dbs.threadCount = DEFAULT_NTHREADS; - } else { - errorPrint("%s", "failed to read json, threads not found\n"); - goto PARSE_OVER; - } - - cJSON* threads2 = cJSON_GetObjectItem(root, "thread_count_create_tbl"); - if (threads2 && threads2->type == cJSON_Number) { - g_Dbs.threadCountForCreateTbl = threads2->valueint; - } else if (!threads2) { - g_Dbs.threadCountForCreateTbl = DEFAULT_NTHREADS; - } else { - errorPrint("%s", "failed to read json, threads2 not found\n"); - goto PARSE_OVER; - } - - cJSON* gInsertInterval = cJSON_GetObjectItem(root, "insert_interval"); - if (gInsertInterval && gInsertInterval->type == cJSON_Number) { - if (gInsertInterval->valueint <0) { - errorPrint("%s", "failed to read json, insert interval input mistake\n"); - goto PARSE_OVER; - } - g_args.insert_interval = gInsertInterval->valueint; - } else if (!gInsertInterval) { - g_args.insert_interval = DEFAULT_INSERT_INTERVAL; - } else { - errorPrint("%s", "failed to read json, insert_interval input mistake\n"); - goto PARSE_OVER; - } - - cJSON* interlaceRows = cJSON_GetObjectItem(root, "interlace_rows"); - if (interlaceRows && interlaceRows->type == cJSON_Number) { - if (interlaceRows->valueint < 0) { - errorPrint("%s", "failed to read json, interlaceRows input mistake\n"); - goto PARSE_OVER; - - } - g_args.interlaceRows = interlaceRows->valueint; - } else if (!interlaceRows) { - g_args.interlaceRows = DEFAULT_INTERLACE_ROWS; // 0 means progressive mode, > 0 mean interlace mode. max value is less or equ num_of_records_per_req - } else { - errorPrint("%s", "failed to read json, interlaceRows input mistake\n"); - goto PARSE_OVER; - } - - cJSON* maxSqlLen = cJSON_GetObjectItem(root, "max_sql_len"); - if (maxSqlLen && maxSqlLen->type == cJSON_Number) { - if (maxSqlLen->valueint < 0) { - errorPrint("%s() LN%d, failed to read json, max_sql_len input mistake\n", - __func__, __LINE__); - goto PARSE_OVER; - } - g_args.max_sql_len = maxSqlLen->valueint; - } else if (!maxSqlLen) { - g_args.max_sql_len = TSDB_MAX_ALLOWED_SQL_LEN; - } else { - errorPrint("%s() LN%d, failed to read json, max_sql_len input mistake\n", - __func__, __LINE__); - goto PARSE_OVER; - } - - cJSON* numRecPerReq = cJSON_GetObjectItem(root, "num_of_records_per_req"); - if (numRecPerReq && numRecPerReq->type == cJSON_Number) { - if (numRecPerReq->valueint <= 0) { - errorPrint("%s() LN%d, failed to read json, num_of_records_per_req input mistake\n", - __func__, __LINE__); - goto PARSE_OVER; - } else if (numRecPerReq->valueint > MAX_RECORDS_PER_REQ) { - printf("NOTICE: number of records per request value %"PRIu64" > %d\n\n", - numRecPerReq->valueint, MAX_RECORDS_PER_REQ); - printf(" number of records per request value will be set to %d\n\n", - MAX_RECORDS_PER_REQ); - prompt(); - numRecPerReq->valueint = MAX_RECORDS_PER_REQ; - } - g_args.reqPerReq = numRecPerReq->valueint; - } else if (!numRecPerReq) { - g_args.reqPerReq = MAX_RECORDS_PER_REQ; - } else { - errorPrint("%s() LN%d, failed to read json, num_of_records_per_req not found\n", - __func__, __LINE__); - goto PARSE_OVER; - } - - cJSON* prepareRand = cJSON_GetObjectItem(root, "prepared_rand"); - if (prepareRand && prepareRand->type == cJSON_Number) { - if (prepareRand->valueint <= 0) { - errorPrint("%s() LN%d, failed to read json, prepared_rand input mistake\n", - __func__, __LINE__); - goto PARSE_OVER; - } - g_args.prepared_rand = prepareRand->valueint; - } else if (!prepareRand) { - g_args.prepared_rand = DEFAULT_PREPARED_RAND; - } else { - errorPrint("%s() LN%d, failed to read json, prepared_rand not found\n", - __func__, __LINE__); - goto PARSE_OVER; - } - - cJSON *answerPrompt = cJSON_GetObjectItem(root, "confirm_parameter_prompt"); // yes, no, - if (answerPrompt - && answerPrompt->type == cJSON_String - && answerPrompt->valuestring != NULL) { - if (0 == strncasecmp(answerPrompt->valuestring, "yes", 3)) { - g_args.answer_yes = false; - } else if (0 == strncasecmp(answerPrompt->valuestring, "no", 2)) { - g_args.answer_yes = true; - } else { - g_args.answer_yes = DEFAULT_ANS_YES; - } - } else if (!answerPrompt) { - g_args.answer_yes = true; // default is no, mean answer_yes. - } else { - errorPrint("%s", "failed to read json, confirm_parameter_prompt input mistake\n"); - goto PARSE_OVER; - } - - // rows per table need be less than insert batch - if (g_args.interlaceRows > g_args.reqPerReq) { - printf("NOTICE: interlace rows value %u > num_of_records_per_req %u\n\n", - g_args.interlaceRows, g_args.reqPerReq); - printf(" interlace rows value will be set to num_of_records_per_req %u\n\n", - g_args.reqPerReq); - prompt(); - g_args.interlaceRows = g_args.reqPerReq; - } - - cJSON* dbs = cJSON_GetObjectItem(root, "databases"); - if (!dbs || dbs->type != cJSON_Array) { - errorPrint("%s", "failed to read json, databases not found\n"); - goto PARSE_OVER; - } - - int dbSize = cJSON_GetArraySize(dbs); - if (dbSize > MAX_DB_COUNT) { - errorPrint( - "failed to read json, databases size overflow, max database is %d\n", - MAX_DB_COUNT); - goto PARSE_OVER; - } - g_Dbs.db = calloc(1, sizeof(SDataBase)*dbSize); - assert(g_Dbs.db); - g_Dbs.dbCount = dbSize; - for (int i = 0; i < dbSize; ++i) { - cJSON* dbinfos = cJSON_GetArrayItem(dbs, i); - if (dbinfos == NULL) continue; - - // dbinfo - cJSON *dbinfo = cJSON_GetObjectItem(dbinfos, "dbinfo"); - if (!dbinfo || dbinfo->type != cJSON_Object) { - errorPrint("%s", "failed to read json, dbinfo not found\n"); - goto PARSE_OVER; - } - - cJSON *dbName = cJSON_GetObjectItem(dbinfo, "name"); - if (!dbName || dbName->type != cJSON_String || dbName->valuestring == NULL) { - errorPrint("%s", "failed to read json, db name not found\n"); - goto PARSE_OVER; - } - tstrncpy(g_Dbs.db[i].dbName, dbName->valuestring, TSDB_DB_NAME_LEN); - - cJSON *drop = cJSON_GetObjectItem(dbinfo, "drop"); - if (drop && drop->type == cJSON_String && drop->valuestring != NULL) { - if (0 == strncasecmp(drop->valuestring, "yes", strlen("yes"))) { - g_Dbs.db[i].drop = true; - } else { - g_Dbs.db[i].drop = false; - } - } else if (!drop) { - g_Dbs.db[i].drop = g_args.drop_database; - } else { - errorPrint("%s", "failed to read json, drop input mistake\n"); - goto PARSE_OVER; - } - - cJSON *precision = cJSON_GetObjectItem(dbinfo, "precision"); - if (precision && precision->type == cJSON_String - && precision->valuestring != NULL) { - tstrncpy(g_Dbs.db[i].dbCfg.precision, precision->valuestring, - SMALL_BUFF_LEN); - } else if (!precision) { - memset(g_Dbs.db[i].dbCfg.precision, 0, SMALL_BUFF_LEN); - } else { - errorPrint("%s", "failed to read json, precision not found\n"); - goto PARSE_OVER; - } - - cJSON* update = cJSON_GetObjectItem(dbinfo, "update"); - if (update && update->type == cJSON_Number) { - g_Dbs.db[i].dbCfg.update = update->valueint; - } else if (!update) { - g_Dbs.db[i].dbCfg.update = -1; - } else { - errorPrint("%s", "failed to read json, update not found\n"); - goto PARSE_OVER; - } - - cJSON* replica = cJSON_GetObjectItem(dbinfo, "replica"); - if (replica && replica->type == cJSON_Number) { - g_Dbs.db[i].dbCfg.replica = replica->valueint; - } else if (!replica) { - g_Dbs.db[i].dbCfg.replica = -1; - } else { - errorPrint("%s", "failed to read json, replica not found\n"); - goto PARSE_OVER; - } - - cJSON* keep = cJSON_GetObjectItem(dbinfo, "keep"); - if (keep && keep->type == cJSON_Number) { - g_Dbs.db[i].dbCfg.keep = keep->valueint; - } else if (!keep) { - g_Dbs.db[i].dbCfg.keep = -1; - } else { - errorPrint("%s", "failed to read json, keep not found\n"); - goto PARSE_OVER; - } - - cJSON* days = cJSON_GetObjectItem(dbinfo, "days"); - if (days && days->type == cJSON_Number) { - g_Dbs.db[i].dbCfg.days = days->valueint; - } else if (!days) { - g_Dbs.db[i].dbCfg.days = -1; - } else { - errorPrint("%s", "failed to read json, days not found\n"); - goto PARSE_OVER; - } - - cJSON* cache = cJSON_GetObjectItem(dbinfo, "cache"); - if (cache && cache->type == cJSON_Number) { - g_Dbs.db[i].dbCfg.cache = cache->valueint; - } else if (!cache) { - g_Dbs.db[i].dbCfg.cache = -1; - } else { - errorPrint("%s", "failed to read json, cache not found\n"); - goto PARSE_OVER; - } - - cJSON* blocks= cJSON_GetObjectItem(dbinfo, "blocks"); - if (blocks && blocks->type == cJSON_Number) { - g_Dbs.db[i].dbCfg.blocks = blocks->valueint; - } else if (!blocks) { - g_Dbs.db[i].dbCfg.blocks = -1; - } else { - errorPrint("%s", "failed to read json, block not found\n"); - goto PARSE_OVER; - } - - //cJSON* maxtablesPerVnode= cJSON_GetObjectItem(dbinfo, "maxtablesPerVnode"); - //if (maxtablesPerVnode && maxtablesPerVnode->type == cJSON_Number) { - // g_Dbs.db[i].dbCfg.maxtablesPerVnode = maxtablesPerVnode->valueint; - //} else if (!maxtablesPerVnode) { - // g_Dbs.db[i].dbCfg.maxtablesPerVnode = TSDB_DEFAULT_TABLES; - //} else { - // printf("failed to read json, maxtablesPerVnode not found"); - // goto PARSE_OVER; - //} - - cJSON* minRows= cJSON_GetObjectItem(dbinfo, "minRows"); - if (minRows && minRows->type == cJSON_Number) { - g_Dbs.db[i].dbCfg.minRows = minRows->valueint; - } else if (!minRows) { - g_Dbs.db[i].dbCfg.minRows = 0; // 0 means default - } else { - errorPrint("%s", "failed to read json, minRows not found\n"); - goto PARSE_OVER; - } - - cJSON* maxRows= cJSON_GetObjectItem(dbinfo, "maxRows"); - if (maxRows && maxRows->type == cJSON_Number) { - g_Dbs.db[i].dbCfg.maxRows = maxRows->valueint; - } else if (!maxRows) { - g_Dbs.db[i].dbCfg.maxRows = 0; // 0 means default - } else { - errorPrint("%s", "failed to read json, maxRows not found\n"); - goto PARSE_OVER; - } - - cJSON* comp= cJSON_GetObjectItem(dbinfo, "comp"); - if (comp && comp->type == cJSON_Number) { - g_Dbs.db[i].dbCfg.comp = comp->valueint; - } else if (!comp) { - g_Dbs.db[i].dbCfg.comp = -1; - } else { - errorPrint("%s", "failed to read json, comp not found\n"); - goto PARSE_OVER; - } - - cJSON* walLevel= cJSON_GetObjectItem(dbinfo, "walLevel"); - if (walLevel && walLevel->type == cJSON_Number) { - g_Dbs.db[i].dbCfg.walLevel = walLevel->valueint; - } else if (!walLevel) { - g_Dbs.db[i].dbCfg.walLevel = -1; - } else { - errorPrint("%s", "failed to read json, walLevel not found\n"); - goto PARSE_OVER; - } - - cJSON* cacheLast= cJSON_GetObjectItem(dbinfo, "cachelast"); - if (cacheLast && cacheLast->type == cJSON_Number) { - g_Dbs.db[i].dbCfg.cacheLast = cacheLast->valueint; - } else if (!cacheLast) { - g_Dbs.db[i].dbCfg.cacheLast = -1; - } else { - errorPrint("%s", "failed to read json, cacheLast not found\n"); - goto PARSE_OVER; - } - - cJSON* quorum= cJSON_GetObjectItem(dbinfo, "quorum"); - if (quorum && quorum->type == cJSON_Number) { - g_Dbs.db[i].dbCfg.quorum = quorum->valueint; - } else if (!quorum) { - g_Dbs.db[i].dbCfg.quorum = 1; - } else { - printf("failed to read json, quorum input mistake"); - goto PARSE_OVER; - } - - cJSON* fsync= cJSON_GetObjectItem(dbinfo, "fsync"); - if (fsync && fsync->type == cJSON_Number) { - g_Dbs.db[i].dbCfg.fsync = fsync->valueint; - } else if (!fsync) { - g_Dbs.db[i].dbCfg.fsync = -1; - } else { - errorPrint("%s", "failed to read json, fsync input mistake\n"); - goto PARSE_OVER; - } - - // super_tables - cJSON *stables = cJSON_GetObjectItem(dbinfos, "super_tables"); - if (!stables || stables->type != cJSON_Array) { - errorPrint("%s", "failed to read json, super_tables not found\n"); - goto PARSE_OVER; - } - - int stbSize = cJSON_GetArraySize(stables); - if (stbSize > MAX_SUPER_TABLE_COUNT) { - errorPrint( - "failed to read json, supertable size overflow, max supertable is %d\n", - MAX_SUPER_TABLE_COUNT); - goto PARSE_OVER; - } - g_Dbs.db[i].superTbls = calloc(1, stbSize * sizeof(SSuperTable)); - assert(g_Dbs.db[i].superTbls); - g_Dbs.db[i].superTblCount = stbSize; - for (int j = 0; j < stbSize; ++j) { - cJSON* stbInfo = cJSON_GetArrayItem(stables, j); - if (stbInfo == NULL) continue; - - // dbinfo - cJSON *stbName = cJSON_GetObjectItem(stbInfo, "name"); - if (!stbName || stbName->type != cJSON_String - || stbName->valuestring == NULL) { - errorPrint("%s", "failed to read json, stb name not found\n"); - goto PARSE_OVER; - } - tstrncpy(g_Dbs.db[i].superTbls[j].stbName, stbName->valuestring, - TSDB_TABLE_NAME_LEN); - - cJSON *prefix = cJSON_GetObjectItem(stbInfo, "childtable_prefix"); - if (!prefix || prefix->type != cJSON_String || prefix->valuestring == NULL) { - errorPrint("%s", "failed to read json, childtable_prefix not found\n"); - goto PARSE_OVER; - } - tstrncpy(g_Dbs.db[i].superTbls[j].childTblPrefix, prefix->valuestring, - TBNAME_PREFIX_LEN); - - cJSON *escapeChar = cJSON_GetObjectItem(stbInfo, "escape_character"); - if (escapeChar - && escapeChar->type == cJSON_String - && escapeChar->valuestring != NULL) { - if ((0 == strncasecmp(escapeChar->valuestring, "yes", 3))) { - g_Dbs.db[i].superTbls[j].escapeChar = true; - } else if (0 == strncasecmp(escapeChar->valuestring, "no", 2)) { - g_Dbs.db[i].superTbls[j].escapeChar = false; - } else { - g_Dbs.db[i].superTbls[j].escapeChar = false; - } - } else if (!escapeChar) { - g_Dbs.db[i].superTbls[j].escapeChar = false; - } else { - errorPrint("%s", "failed to read json, escape_character not found\n"); - goto PARSE_OVER; - } - - cJSON *autoCreateTbl = cJSON_GetObjectItem(stbInfo, "auto_create_table"); - if (autoCreateTbl - && autoCreateTbl->type == cJSON_String - && autoCreateTbl->valuestring != NULL) { - if ((0 == strncasecmp(autoCreateTbl->valuestring, "yes", 3)) - && (TBL_ALREADY_EXISTS != g_Dbs.db[i].superTbls[j].childTblExists)) { - g_Dbs.db[i].superTbls[j].autoCreateTable = AUTO_CREATE_SUBTBL; - } else if (0 == strncasecmp(autoCreateTbl->valuestring, "no", 2)) { - g_Dbs.db[i].superTbls[j].autoCreateTable = PRE_CREATE_SUBTBL; - } else { - g_Dbs.db[i].superTbls[j].autoCreateTable = PRE_CREATE_SUBTBL; - } - } else if (!autoCreateTbl) { - g_Dbs.db[i].superTbls[j].autoCreateTable = PRE_CREATE_SUBTBL; - } else { - errorPrint("%s", "failed to read json, auto_create_table not found\n"); - goto PARSE_OVER; - } - - cJSON* batchCreateTbl = cJSON_GetObjectItem(stbInfo, "batch_create_tbl_num"); - if (batchCreateTbl && batchCreateTbl->type == cJSON_Number) { - g_Dbs.db[i].superTbls[j].batchCreateTableNum = batchCreateTbl->valueint; - } else if (!batchCreateTbl) { - g_Dbs.db[i].superTbls[j].batchCreateTableNum = DEFAULT_CREATE_BATCH; - } else { - errorPrint("%s", "failed to read json, batch_create_tbl_num not found\n"); - goto PARSE_OVER; - } - - cJSON *childTblExists = cJSON_GetObjectItem(stbInfo, "child_table_exists"); // yes, no - if (childTblExists - && childTblExists->type == cJSON_String - && childTblExists->valuestring != NULL) { - if ((0 == strncasecmp(childTblExists->valuestring, "yes", 3)) - && (g_Dbs.db[i].drop == false)) { - g_Dbs.db[i].superTbls[j].childTblExists = TBL_ALREADY_EXISTS; - } else if ((0 == strncasecmp(childTblExists->valuestring, "no", 2) - || (g_Dbs.db[i].drop == true))) { - g_Dbs.db[i].superTbls[j].childTblExists = TBL_NO_EXISTS; - } else { - g_Dbs.db[i].superTbls[j].childTblExists = TBL_NO_EXISTS; - } - } else if (!childTblExists) { - g_Dbs.db[i].superTbls[j].childTblExists = TBL_NO_EXISTS; - } else { - errorPrint("%s", - "failed to read json, child_table_exists not found\n"); - goto PARSE_OVER; - } - - if (TBL_ALREADY_EXISTS == g_Dbs.db[i].superTbls[j].childTblExists) { - g_Dbs.db[i].superTbls[j].autoCreateTable = PRE_CREATE_SUBTBL; - } - - cJSON* count = cJSON_GetObjectItem(stbInfo, "childtable_count"); - if (!count || count->type != cJSON_Number || 0 >= count->valueint) { - errorPrint("%s", - "failed to read json, childtable_count input mistake\n"); - goto PARSE_OVER; - } - g_Dbs.db[i].superTbls[j].childTblCount = count->valueint; - g_totalChildTables += g_Dbs.db[i].superTbls[j].childTblCount; - - cJSON *dataSource = cJSON_GetObjectItem(stbInfo, "data_source"); - if (dataSource && dataSource->type == cJSON_String - && dataSource->valuestring != NULL) { - tstrncpy(g_Dbs.db[i].superTbls[j].dataSource, - dataSource->valuestring, - min(SMALL_BUFF_LEN, strlen(dataSource->valuestring) + 1)); - } else if (!dataSource) { - tstrncpy(g_Dbs.db[i].superTbls[j].dataSource, "rand", - min(SMALL_BUFF_LEN, strlen("rand") + 1)); - } else { - errorPrint("%s", "failed to read json, data_source not found\n"); - goto PARSE_OVER; - } - - cJSON *stbIface = cJSON_GetObjectItem(stbInfo, "insert_mode"); // taosc , rest, stmt - if (stbIface && stbIface->type == cJSON_String - && stbIface->valuestring != NULL) { - if (0 == strcasecmp(stbIface->valuestring, "taosc")) { - g_Dbs.db[i].superTbls[j].iface= TAOSC_IFACE; - } else if (0 == strcasecmp(stbIface->valuestring, "rest")) { - g_Dbs.db[i].superTbls[j].iface= REST_IFACE; - } else if (0 == strcasecmp(stbIface->valuestring, "stmt")) { - g_Dbs.db[i].superTbls[j].iface= STMT_IFACE; - } else if (0 == strcasecmp(stbIface->valuestring, "sml")) { - g_Dbs.db[i].superTbls[j].iface= SML_IFACE; - g_args.iface = SML_IFACE; - } else { - errorPrint("failed to read json, insert_mode %s not recognized\n", - stbIface->valuestring); - goto PARSE_OVER; - } - } else if (!stbIface) { - g_Dbs.db[i].superTbls[j].iface = TAOSC_IFACE; - } else { - errorPrint("%s", "failed to read json, insert_mode not found\n"); - goto PARSE_OVER; - } - - cJSON* childTbl_limit = cJSON_GetObjectItem(stbInfo, "childtable_limit"); - if ((childTbl_limit) && (g_Dbs.db[i].drop != true) - && (g_Dbs.db[i].superTbls[j].childTblExists == TBL_ALREADY_EXISTS)) { - if (childTbl_limit->type != cJSON_Number) { - errorPrint("%s", "failed to read json, childtable_limit\n"); - goto PARSE_OVER; - } - g_Dbs.db[i].superTbls[j].childTblLimit = childTbl_limit->valueint; - } else { - g_Dbs.db[i].superTbls[j].childTblLimit = -1; // select ... limit -1 means all query result, drop = yes mean all table need recreate, limit value is invalid. - } - - cJSON* childTbl_offset = cJSON_GetObjectItem(stbInfo, "childtable_offset"); - if ((childTbl_offset) && (g_Dbs.db[i].drop != true) - && (g_Dbs.db[i].superTbls[j].childTblExists == TBL_ALREADY_EXISTS)) { - if ((childTbl_offset->type != cJSON_Number) - || (0 > childTbl_offset->valueint)) { - errorPrint("%s", "failed to read json, childtable_offset\n"); - goto PARSE_OVER; - } - g_Dbs.db[i].superTbls[j].childTblOffset = childTbl_offset->valueint; - } else { - g_Dbs.db[i].superTbls[j].childTblOffset = 0; - } - - cJSON *ts = cJSON_GetObjectItem(stbInfo, "start_timestamp"); - if (ts && ts->type == cJSON_String && ts->valuestring != NULL) { - tstrncpy(g_Dbs.db[i].superTbls[j].startTimestamp, - ts->valuestring, TSDB_DB_NAME_LEN); - } else if (!ts) { - tstrncpy(g_Dbs.db[i].superTbls[j].startTimestamp, - "now", TSDB_DB_NAME_LEN); - } else { - errorPrint("%s", "failed to read json, start_timestamp not found\n"); - goto PARSE_OVER; - } - - cJSON* timestampStep = cJSON_GetObjectItem(stbInfo, "timestamp_step"); - if (timestampStep && timestampStep->type == cJSON_Number) { - g_Dbs.db[i].superTbls[j].timeStampStep = timestampStep->valueint; - } else if (!timestampStep) { - g_Dbs.db[i].superTbls[j].timeStampStep = g_args.timestamp_step; - } else { - errorPrint("%s", "failed to read json, timestamp_step not found\n"); - goto PARSE_OVER; - } - - cJSON *sampleFormat = cJSON_GetObjectItem(stbInfo, "sample_format"); - if (sampleFormat && sampleFormat->type - == cJSON_String && sampleFormat->valuestring != NULL) { - tstrncpy(g_Dbs.db[i].superTbls[j].sampleFormat, - sampleFormat->valuestring, - min(SMALL_BUFF_LEN, - strlen(sampleFormat->valuestring) + 1)); - } else if (!sampleFormat) { - tstrncpy(g_Dbs.db[i].superTbls[j].sampleFormat, "csv", - SMALL_BUFF_LEN); - } else { - errorPrint("%s", "failed to read json, sample_format not found\n"); - goto PARSE_OVER; - } - - cJSON *sampleFile = cJSON_GetObjectItem(stbInfo, "sample_file"); - if (sampleFile && sampleFile->type == cJSON_String - && sampleFile->valuestring != NULL) { - tstrncpy(g_Dbs.db[i].superTbls[j].sampleFile, - sampleFile->valuestring, - min(MAX_FILE_NAME_LEN, - strlen(sampleFile->valuestring) + 1)); - } else if (!sampleFile) { - memset(g_Dbs.db[i].superTbls[j].sampleFile, 0, - MAX_FILE_NAME_LEN); - } else { - errorPrint("%s", "failed to read json, sample_file not found\n"); - goto PARSE_OVER; - } - - cJSON *useSampleTs = cJSON_GetObjectItem(stbInfo, "use_sample_ts"); - if (useSampleTs && useSampleTs->type == cJSON_String - && useSampleTs->valuestring != NULL) { - if (0 == strncasecmp(useSampleTs->valuestring, "yes", 3)) { - g_Dbs.db[i].superTbls[j].useSampleTs = true; - } else if (0 == strncasecmp(useSampleTs->valuestring, "no", 2)){ - g_Dbs.db[i].superTbls[j].useSampleTs = false; - } else { - g_Dbs.db[i].superTbls[j].useSampleTs = false; - } - } else if (!useSampleTs) { - g_Dbs.db[i].superTbls[j].useSampleTs = false; - } else { - errorPrint("%s", "failed to read json, use_sample_ts not found\n"); - goto PARSE_OVER; - } - - cJSON *tagsFile = cJSON_GetObjectItem(stbInfo, "tags_file"); - if ((tagsFile && tagsFile->type == cJSON_String) - && (tagsFile->valuestring != NULL)) { - tstrncpy(g_Dbs.db[i].superTbls[j].tagsFile, - tagsFile->valuestring, MAX_FILE_NAME_LEN); - if (0 == g_Dbs.db[i].superTbls[j].tagsFile[0]) { - g_Dbs.db[i].superTbls[j].tagSource = 0; - } else { - g_Dbs.db[i].superTbls[j].tagSource = 1; - } - } else if (!tagsFile) { - memset(g_Dbs.db[i].superTbls[j].tagsFile, 0, MAX_FILE_NAME_LEN); - g_Dbs.db[i].superTbls[j].tagSource = 0; - } else { - errorPrint("%s", "failed to read json, tags_file not found\n"); - goto PARSE_OVER; - } - - cJSON* stbMaxSqlLen = cJSON_GetObjectItem(stbInfo, "max_sql_len"); - if (stbMaxSqlLen && stbMaxSqlLen->type == cJSON_Number) { - int32_t len = stbMaxSqlLen->valueint; - if (len > TSDB_MAX_ALLOWED_SQL_LEN) { - len = TSDB_MAX_ALLOWED_SQL_LEN; - } else if (len < 5) { - len = 5; - } - g_Dbs.db[i].superTbls[j].maxSqlLen = len; - } else if (!maxSqlLen) { - g_Dbs.db[i].superTbls[j].maxSqlLen = g_args.max_sql_len; - } else { - errorPrint("%s", "failed to read json, stbMaxSqlLen input mistake\n"); - goto PARSE_OVER; - } - /* - cJSON *multiThreadWriteOneTbl = - cJSON_GetObjectItem(stbInfo, "multi_thread_write_one_tbl"); // no , yes - if (multiThreadWriteOneTbl - && multiThreadWriteOneTbl->type == cJSON_String - && multiThreadWriteOneTbl->valuestring != NULL) { - if (0 == strncasecmp(multiThreadWriteOneTbl->valuestring, "yes", 3)) { - g_Dbs.db[i].superTbls[j].multiThreadWriteOneTbl = 1; - } else { - g_Dbs.db[i].superTbls[j].multiThreadWriteOneTbl = 0; - } - } else if (!multiThreadWriteOneTbl) { - g_Dbs.db[i].superTbls[j].multiThreadWriteOneTbl = 0; - } else { - errorPrint("%s", "failed to read json, multiThreadWriteOneTbl not found\n"); - goto PARSE_OVER; - } - */ - cJSON* insertRows = cJSON_GetObjectItem(stbInfo, "insert_rows"); - if (insertRows && insertRows->type == cJSON_Number) { - if (insertRows->valueint < 0) { - errorPrint("%s", "failed to read json, insert_rows input mistake\n"); - goto PARSE_OVER; - } - g_Dbs.db[i].superTbls[j].insertRows = insertRows->valueint; - } else if (!insertRows) { - g_Dbs.db[i].superTbls[j].insertRows = 0x7FFFFFFFFFFFFFFF; - } else { - errorPrint("%s", "failed to read json, insert_rows input mistake\n"); - goto PARSE_OVER; - } - - cJSON* stbInterlaceRows = cJSON_GetObjectItem(stbInfo, "interlace_rows"); - if (stbInterlaceRows && stbInterlaceRows->type == cJSON_Number) { - if (stbInterlaceRows->valueint < 0) { - errorPrint("%s", "failed to read json, interlace rows input mistake\n"); - goto PARSE_OVER; - } - g_Dbs.db[i].superTbls[j].interlaceRows = stbInterlaceRows->valueint; - - if (g_Dbs.db[i].superTbls[j].interlaceRows > g_Dbs.db[i].superTbls[j].insertRows) { - printf("NOTICE: db[%d].superTbl[%d]'s interlace rows value %u > insert_rows %"PRId64"\n\n", - i, j, g_Dbs.db[i].superTbls[j].interlaceRows, - g_Dbs.db[i].superTbls[j].insertRows); - printf(" interlace rows value will be set to insert_rows %"PRId64"\n\n", - g_Dbs.db[i].superTbls[j].insertRows); - prompt(); - g_Dbs.db[i].superTbls[j].interlaceRows = g_Dbs.db[i].superTbls[j].insertRows; - } - } else if (!stbInterlaceRows) { - g_Dbs.db[i].superTbls[j].interlaceRows = g_args.interlaceRows; // 0 means progressive mode, > 0 mean interlace mode. max value is less or equ num_of_records_per_req - } else { - errorPrint( - "%s", "failed to read json, interlace rows input mistake\n"); - goto PARSE_OVER; - } - - cJSON* disorderRatio = cJSON_GetObjectItem(stbInfo, "disorder_ratio"); - if (disorderRatio && disorderRatio->type == cJSON_Number) { - if (disorderRatio->valueint > 50) - disorderRatio->valueint = 50; - - if (disorderRatio->valueint < 0) - disorderRatio->valueint = 0; - - g_Dbs.db[i].superTbls[j].disorderRatio = disorderRatio->valueint; - } else if (!disorderRatio) { - g_Dbs.db[i].superTbls[j].disorderRatio = 0; - } else { - errorPrint("%s", "failed to read json, disorderRatio not found\n"); - goto PARSE_OVER; - } - - cJSON* disorderRange = cJSON_GetObjectItem(stbInfo, "disorder_range"); - if (disorderRange && disorderRange->type == cJSON_Number) { - g_Dbs.db[i].superTbls[j].disorderRange = disorderRange->valueint; - } else if (!disorderRange) { - g_Dbs.db[i].superTbls[j].disorderRange = DEFAULT_DISORDER_RANGE; - } else { - errorPrint("%s", "failed to read json, disorderRange not found\n"); - goto PARSE_OVER; - } - - cJSON* insertInterval = cJSON_GetObjectItem(stbInfo, "insert_interval"); - if (insertInterval && insertInterval->type == cJSON_Number) { - g_Dbs.db[i].superTbls[j].insertInterval = insertInterval->valueint; - if (insertInterval->valueint < 0) { - errorPrint("%s", "failed to read json, insert_interval input mistake\n"); - goto PARSE_OVER; - } - } else if (!insertInterval) { - verbosePrint("%s() LN%d: stable insert interval be overrode by global %"PRIu64".\n", - __func__, __LINE__, g_args.insert_interval); - g_Dbs.db[i].superTbls[j].insertInterval = g_args.insert_interval; - } else { - errorPrint("%s", "failed to read json, insert_interval input mistake\n"); - goto PARSE_OVER; - } - - int retVal = getColumnAndTagTypeFromInsertJsonFile( - stbInfo, &g_Dbs.db[i].superTbls[j]); - if (false == retVal) { - goto PARSE_OVER; - } - } - } - - ret = true; - -PARSE_OVER: - return ret; -} - -static bool getMetaFromQueryJsonFile(cJSON* root) { - bool ret = false; - - cJSON* cfgdir = cJSON_GetObjectItem(root, "cfgdir"); - if (cfgdir && cfgdir->type == cJSON_String && cfgdir->valuestring != NULL) { - tstrncpy(g_queryInfo.cfgDir, cfgdir->valuestring, MAX_FILE_NAME_LEN); - } - - cJSON* host = cJSON_GetObjectItem(root, "host"); - if (host && host->type == cJSON_String && host->valuestring != NULL) { - tstrncpy(g_queryInfo.host, host->valuestring, MAX_HOSTNAME_SIZE); - } else if (!host) { - tstrncpy(g_queryInfo.host, DEFAULT_HOST, MAX_HOSTNAME_SIZE); - } else { - errorPrint("%s", "failed to read json, host not found\n"); - goto PARSE_OVER; - } - - cJSON* port = cJSON_GetObjectItem(root, "port"); - if (port && port->type == cJSON_Number) { - g_queryInfo.port = port->valueint; - } else if (!port) { - g_queryInfo.port = DEFAULT_PORT; - } - - cJSON* user = cJSON_GetObjectItem(root, "user"); - if (user && user->type == cJSON_String && user->valuestring != NULL) { - tstrncpy(g_queryInfo.user, user->valuestring, MAX_USERNAME_SIZE); - } else if (!user) { - tstrncpy(g_queryInfo.user, TSDB_DEFAULT_USER, MAX_USERNAME_SIZE); ; - } - - cJSON* password = cJSON_GetObjectItem(root, "password"); - if (password && password->type == cJSON_String && password->valuestring != NULL) { - tstrncpy(g_queryInfo.password, password->valuestring, SHELL_MAX_PASSWORD_LEN); - } else if (!password) { - tstrncpy(g_queryInfo.password, TSDB_DEFAULT_PASS, SHELL_MAX_PASSWORD_LEN);; - } - - cJSON *answerPrompt = cJSON_GetObjectItem(root, "confirm_parameter_prompt"); // yes, no, - if (answerPrompt && answerPrompt->type == cJSON_String - && answerPrompt->valuestring != NULL) { - if (0 == strncasecmp(answerPrompt->valuestring, "yes", 3)) { - g_args.answer_yes = false; - } else if (0 == strncasecmp(answerPrompt->valuestring, "no", 2)) { - g_args.answer_yes = true; - } else { - g_args.answer_yes = false; - } - } else if (!answerPrompt) { - g_args.answer_yes = false; - } else { - errorPrint("%s", "failed to read json, confirm_parameter_prompt not found\n"); - goto PARSE_OVER; - } - - cJSON* gQueryTimes = cJSON_GetObjectItem(root, "query_times"); - if (gQueryTimes && gQueryTimes->type == cJSON_Number) { - if (gQueryTimes->valueint <= 0) { - errorPrint("%s()", "failed to read json, query_times input mistake\n"); - goto PARSE_OVER; - } - g_args.query_times = gQueryTimes->valueint; - } else if (!gQueryTimes) { - g_args.query_times = DEFAULT_QUERY_TIME; - } else { - errorPrint("%s", "failed to read json, query_times input mistake\n"); - goto PARSE_OVER; - } - - cJSON* dbs = cJSON_GetObjectItem(root, "databases"); - if (dbs && dbs->type == cJSON_String && dbs->valuestring != NULL) { - tstrncpy(g_queryInfo.dbName, dbs->valuestring, TSDB_DB_NAME_LEN); - } else if (!dbs) { - errorPrint("%s", "failed to read json, databases not found\n"); - goto PARSE_OVER; - } - - cJSON* queryMode = cJSON_GetObjectItem(root, "query_mode"); - if (queryMode - && queryMode->type == cJSON_String - && queryMode->valuestring != NULL) { - tstrncpy(g_queryInfo.queryMode, queryMode->valuestring, - min(SMALL_BUFF_LEN, strlen(queryMode->valuestring) + 1)); - } else if (!queryMode) { - tstrncpy(g_queryInfo.queryMode, "taosc", - min(SMALL_BUFF_LEN, strlen("taosc") + 1)); - } else { - errorPrint("%s", "failed to read json, query_mode not found\n"); - goto PARSE_OVER; - } - - // specified_table_query - cJSON *specifiedQuery = cJSON_GetObjectItem(root, "specified_table_query"); - if (!specifiedQuery) { - g_queryInfo.specifiedQueryInfo.concurrent = 1; - g_queryInfo.specifiedQueryInfo.sqlCount = 0; - } else if (specifiedQuery->type != cJSON_Object) { - errorPrint("%s", "failed to read json, super_table_query not found\n"); - goto PARSE_OVER; - } else { - cJSON* queryInterval = cJSON_GetObjectItem(specifiedQuery, "query_interval"); - if (queryInterval && queryInterval->type == cJSON_Number) { - g_queryInfo.specifiedQueryInfo.queryInterval = queryInterval->valueint; - } else if (!queryInterval) { - g_queryInfo.specifiedQueryInfo.queryInterval = 0; - } - - cJSON* specifiedQueryTimes = cJSON_GetObjectItem(specifiedQuery, - "query_times"); - if (specifiedQueryTimes && specifiedQueryTimes->type == cJSON_Number) { - if (specifiedQueryTimes->valueint <= 0) { - errorPrint( - "failed to read json, query_times: %"PRId64", need be a valid (>0) number\n", - specifiedQueryTimes->valueint); - goto PARSE_OVER; - - } - g_queryInfo.specifiedQueryInfo.queryTimes = specifiedQueryTimes->valueint; - } else if (!specifiedQueryTimes) { - g_queryInfo.specifiedQueryInfo.queryTimes = g_args.query_times; - } else { - errorPrint("%s() LN%d, failed to read json, query_times input mistake\n", - __func__, __LINE__); - goto PARSE_OVER; - } - - cJSON* concurrent = cJSON_GetObjectItem(specifiedQuery, "concurrent"); - if (concurrent && concurrent->type == cJSON_Number) { - if (concurrent->valueint <= 0) { - errorPrint( - "query sqlCount %d or concurrent %d is not correct.\n", - g_queryInfo.specifiedQueryInfo.sqlCount, - g_queryInfo.specifiedQueryInfo.concurrent); - goto PARSE_OVER; - } - g_queryInfo.specifiedQueryInfo.concurrent = concurrent->valueint; - } else if (!concurrent) { - g_queryInfo.specifiedQueryInfo.concurrent = 1; - } - - cJSON* specifiedAsyncMode = cJSON_GetObjectItem(specifiedQuery, "mode"); - if (specifiedAsyncMode && specifiedAsyncMode->type == cJSON_String - && specifiedAsyncMode->valuestring != NULL) { - if (0 == strcmp("sync", specifiedAsyncMode->valuestring)) { - g_queryInfo.specifiedQueryInfo.asyncMode = SYNC_MODE; - } else if (0 == strcmp("async", specifiedAsyncMode->valuestring)) { - g_queryInfo.specifiedQueryInfo.asyncMode = ASYNC_MODE; - } else { - errorPrint("%s", "failed to read json, async mode input error\n"); - goto PARSE_OVER; - } - } else { - g_queryInfo.specifiedQueryInfo.asyncMode = SYNC_MODE; - } - - cJSON* interval = cJSON_GetObjectItem(specifiedQuery, "interval"); - if (interval && interval->type == cJSON_Number) { - g_queryInfo.specifiedQueryInfo.subscribeInterval = interval->valueint; - } else if (!interval) { - //printf("failed to read json, subscribe interval no found\n"); - //goto PARSE_OVER; - g_queryInfo.specifiedQueryInfo.subscribeInterval = DEFAULT_SUB_INTERVAL; - } - - cJSON* restart = cJSON_GetObjectItem(specifiedQuery, "restart"); - if (restart && restart->type == cJSON_String && restart->valuestring != NULL) { - if (0 == strcmp("yes", restart->valuestring)) { - g_queryInfo.specifiedQueryInfo.subscribeRestart = true; - } else if (0 == strcmp("no", restart->valuestring)) { - g_queryInfo.specifiedQueryInfo.subscribeRestart = false; - } else { - errorPrint("%s", "failed to read json, subscribe restart error\n"); - goto PARSE_OVER; - } - } else { - g_queryInfo.specifiedQueryInfo.subscribeRestart = true; - } - - cJSON* keepProgress = cJSON_GetObjectItem(specifiedQuery, "keepProgress"); - if (keepProgress - && keepProgress->type == cJSON_String - && keepProgress->valuestring != NULL) { - if (0 == strcmp("yes", keepProgress->valuestring)) { - g_queryInfo.specifiedQueryInfo.subscribeKeepProgress = 1; - } else if (0 == strcmp("no", keepProgress->valuestring)) { - g_queryInfo.specifiedQueryInfo.subscribeKeepProgress = 0; - } else { - errorPrint("%s", "failed to read json, subscribe keepProgress error\n"); - goto PARSE_OVER; - } - } else { - g_queryInfo.specifiedQueryInfo.subscribeKeepProgress = 0; - } - - // sqls - cJSON* specifiedSqls = cJSON_GetObjectItem(specifiedQuery, "sqls"); - if (!specifiedSqls) { - g_queryInfo.specifiedQueryInfo.sqlCount = 0; - } else if (specifiedSqls->type != cJSON_Array) { - errorPrint("%s", "failed to read json, super sqls not found\n"); - goto PARSE_OVER; - } else { - int superSqlSize = cJSON_GetArraySize(specifiedSqls); - if (superSqlSize * g_queryInfo.specifiedQueryInfo.concurrent - > MAX_QUERY_SQL_COUNT) { - errorPrint("failed to read json, query sql(%d) * concurrent(%d) overflow, max is %d\n", - superSqlSize, - g_queryInfo.specifiedQueryInfo.concurrent, - MAX_QUERY_SQL_COUNT); - goto PARSE_OVER; - } - - g_queryInfo.specifiedQueryInfo.sqlCount = superSqlSize; - for (int j = 0; j < superSqlSize; ++j) { - cJSON* sql = cJSON_GetArrayItem(specifiedSqls, j); - if (sql == NULL) continue; - - cJSON *sqlStr = cJSON_GetObjectItem(sql, "sql"); - if (!sqlStr || sqlStr->type != cJSON_String || sqlStr->valuestring == NULL) { - errorPrint("%s", "failed to read json, sql not found\n"); - goto PARSE_OVER; - } - tstrncpy(g_queryInfo.specifiedQueryInfo.sql[j], - sqlStr->valuestring, BUFFER_SIZE); - - // default value is -1, which mean infinite loop - g_queryInfo.specifiedQueryInfo.endAfterConsume[j] = -1; - cJSON* endAfterConsume = - cJSON_GetObjectItem(specifiedQuery, "endAfterConsume"); - if (endAfterConsume - && endAfterConsume->type == cJSON_Number) { - g_queryInfo.specifiedQueryInfo.endAfterConsume[j] - = endAfterConsume->valueint; - } - if (g_queryInfo.specifiedQueryInfo.endAfterConsume[j] < -1) - g_queryInfo.specifiedQueryInfo.endAfterConsume[j] = -1; - - g_queryInfo.specifiedQueryInfo.resubAfterConsume[j] = -1; - cJSON* resubAfterConsume = - cJSON_GetObjectItem(specifiedQuery, "resubAfterConsume"); - if ((resubAfterConsume) - && (resubAfterConsume->type == cJSON_Number) - && (resubAfterConsume->valueint >= 0)) { - g_queryInfo.specifiedQueryInfo.resubAfterConsume[j] - = resubAfterConsume->valueint; - } - - if (g_queryInfo.specifiedQueryInfo.resubAfterConsume[j] < -1) - g_queryInfo.specifiedQueryInfo.resubAfterConsume[j] = -1; - - cJSON *result = cJSON_GetObjectItem(sql, "result"); - if ((NULL != result) && (result->type == cJSON_String) - && (result->valuestring != NULL)) { - tstrncpy(g_queryInfo.specifiedQueryInfo.result[j], - result->valuestring, MAX_FILE_NAME_LEN); - } else if (NULL == result) { - memset(g_queryInfo.specifiedQueryInfo.result[j], - 0, MAX_FILE_NAME_LEN); - } else { - errorPrint("%s", - "failed to read json, super query result file not found\n"); - goto PARSE_OVER; - } - } - } - } - - // super_table_query - cJSON *superQuery = cJSON_GetObjectItem(root, "super_table_query"); - if (!superQuery) { - g_queryInfo.superQueryInfo.threadCnt = 1; - g_queryInfo.superQueryInfo.sqlCount = 0; - } else if (superQuery->type != cJSON_Object) { - errorPrint("%s", "failed to read json, sub_table_query not found\n"); - ret = true; - goto PARSE_OVER; - } else { - cJSON* subrate = cJSON_GetObjectItem(superQuery, "query_interval"); - if (subrate && subrate->type == cJSON_Number) { - g_queryInfo.superQueryInfo.queryInterval = subrate->valueint; - } else if (!subrate) { - g_queryInfo.superQueryInfo.queryInterval = 0; - } - - cJSON* superQueryTimes = cJSON_GetObjectItem(superQuery, "query_times"); - if (superQueryTimes && superQueryTimes->type == cJSON_Number) { - if (superQueryTimes->valueint <= 0) { - errorPrint("failed to read json, query_times: %"PRId64", need be a valid (>0) number\n", - superQueryTimes->valueint); - goto PARSE_OVER; - } - g_queryInfo.superQueryInfo.queryTimes = superQueryTimes->valueint; - } else if (!superQueryTimes) { - g_queryInfo.superQueryInfo.queryTimes = g_args.query_times; - } else { - errorPrint("%s", "failed to read json, query_times input mistake\n"); - goto PARSE_OVER; - } - - cJSON* threads = cJSON_GetObjectItem(superQuery, "threads"); - if (threads && threads->type == cJSON_Number) { - if (threads->valueint <= 0) { - errorPrint("%s", "failed to read json, threads input mistake\n"); - goto PARSE_OVER; - - } - g_queryInfo.superQueryInfo.threadCnt = threads->valueint; - } else if (!threads) { - g_queryInfo.superQueryInfo.threadCnt = DEFAULT_NTHREADS; - } - - //cJSON* subTblCnt = cJSON_GetObjectItem(superQuery, "childtable_count"); - //if (subTblCnt && subTblCnt->type == cJSON_Number) { - // g_queryInfo.superQueryInfo.childTblCount = subTblCnt->valueint; - //} else if (!subTblCnt) { - // g_queryInfo.superQueryInfo.childTblCount = 0; - //} - - cJSON* stblname = cJSON_GetObjectItem(superQuery, "stblname"); - if (stblname && stblname->type == cJSON_String - && stblname->valuestring != NULL) { - tstrncpy(g_queryInfo.superQueryInfo.stbName, stblname->valuestring, - TSDB_TABLE_NAME_LEN); - } else { - errorPrint("%s", "failed to read json, super table name input error\n"); - goto PARSE_OVER; - } - - cJSON* superAsyncMode = cJSON_GetObjectItem(superQuery, "mode"); - if (superAsyncMode && superAsyncMode->type == cJSON_String - && superAsyncMode->valuestring != NULL) { - if (0 == strcmp("sync", superAsyncMode->valuestring)) { - g_queryInfo.superQueryInfo.asyncMode = SYNC_MODE; - } else if (0 == strcmp("async", superAsyncMode->valuestring)) { - g_queryInfo.superQueryInfo.asyncMode = ASYNC_MODE; - } else { - errorPrint("%s", "failed to read json, async mode input error\n"); - goto PARSE_OVER; - } - } else { - g_queryInfo.superQueryInfo.asyncMode = SYNC_MODE; - } - - cJSON* superInterval = cJSON_GetObjectItem(superQuery, "interval"); - if (superInterval && superInterval->type == cJSON_Number) { - if (superInterval->valueint < 0) { - errorPrint("%s", "failed to read json, interval input mistake\n"); - goto PARSE_OVER; - } - g_queryInfo.superQueryInfo.subscribeInterval = superInterval->valueint; - } else if (!superInterval) { - //printf("failed to read json, subscribe interval no found\n"); - //goto PARSE_OVER; - g_queryInfo.superQueryInfo.subscribeInterval = DEFAULT_QUERY_INTERVAL; - } - - cJSON* subrestart = cJSON_GetObjectItem(superQuery, "restart"); - if (subrestart && subrestart->type == cJSON_String - && subrestart->valuestring != NULL) { - if (0 == strcmp("yes", subrestart->valuestring)) { - g_queryInfo.superQueryInfo.subscribeRestart = true; - } else if (0 == strcmp("no", subrestart->valuestring)) { - g_queryInfo.superQueryInfo.subscribeRestart = false; - } else { - errorPrint("%s", "failed to read json, subscribe restart error\n"); - goto PARSE_OVER; - } - } else { - g_queryInfo.superQueryInfo.subscribeRestart = true; - } - - cJSON* superkeepProgress = cJSON_GetObjectItem(superQuery, "keepProgress"); - if (superkeepProgress && - superkeepProgress->type == cJSON_String - && superkeepProgress->valuestring != NULL) { - if (0 == strcmp("yes", superkeepProgress->valuestring)) { - g_queryInfo.superQueryInfo.subscribeKeepProgress = 1; - } else if (0 == strcmp("no", superkeepProgress->valuestring)) { - g_queryInfo.superQueryInfo.subscribeKeepProgress = 0; - } else { - errorPrint("%s", - "failed to read json, subscribe super table keepProgress error\n"); - goto PARSE_OVER; - } - } else { - g_queryInfo.superQueryInfo.subscribeKeepProgress = 0; - } - - // default value is -1, which mean do not resub - g_queryInfo.superQueryInfo.endAfterConsume = -1; - cJSON* superEndAfterConsume = - cJSON_GetObjectItem(superQuery, "endAfterConsume"); - if (superEndAfterConsume - && superEndAfterConsume->type == cJSON_Number) { - g_queryInfo.superQueryInfo.endAfterConsume = - superEndAfterConsume->valueint; - } - if (g_queryInfo.superQueryInfo.endAfterConsume < -1) - g_queryInfo.superQueryInfo.endAfterConsume = -1; - - // default value is -1, which mean do not resub - g_queryInfo.superQueryInfo.resubAfterConsume = -1; - cJSON* superResubAfterConsume = - cJSON_GetObjectItem(superQuery, "resubAfterConsume"); - if ((superResubAfterConsume) - && (superResubAfterConsume->type == cJSON_Number) - && (superResubAfterConsume->valueint >= 0)) { - g_queryInfo.superQueryInfo.resubAfterConsume = - superResubAfterConsume->valueint; - } - if (g_queryInfo.superQueryInfo.resubAfterConsume < -1) - g_queryInfo.superQueryInfo.resubAfterConsume = -1; - - // supert table sqls - cJSON* superSqls = cJSON_GetObjectItem(superQuery, "sqls"); - if (!superSqls) { - g_queryInfo.superQueryInfo.sqlCount = 0; - } else if (superSqls->type != cJSON_Array) { - errorPrint("%s", "failed to read json, super sqls not found\n"); - goto PARSE_OVER; - } else { - int superSqlSize = cJSON_GetArraySize(superSqls); - if (superSqlSize > MAX_QUERY_SQL_COUNT) { - errorPrint("failed to read json, query sql size overflow, max is %d\n", - MAX_QUERY_SQL_COUNT); - goto PARSE_OVER; - } - - g_queryInfo.superQueryInfo.sqlCount = superSqlSize; - for (int j = 0; j < superSqlSize; ++j) { - cJSON* sql = cJSON_GetArrayItem(superSqls, j); - if (sql == NULL) continue; - - cJSON *sqlStr = cJSON_GetObjectItem(sql, "sql"); - if (!sqlStr || sqlStr->type != cJSON_String - || sqlStr->valuestring == NULL) { - errorPrint("%s", "failed to read json, sql not found\n"); - goto PARSE_OVER; - } - tstrncpy(g_queryInfo.superQueryInfo.sql[j], sqlStr->valuestring, - BUFFER_SIZE); - - cJSON *result = cJSON_GetObjectItem(sql, "result"); - if (result != NULL && result->type == cJSON_String - && result->valuestring != NULL) { - tstrncpy(g_queryInfo.superQueryInfo.result[j], - result->valuestring, MAX_FILE_NAME_LEN); - } else if (NULL == result) { - memset(g_queryInfo.superQueryInfo.result[j], 0, MAX_FILE_NAME_LEN); - } else { - errorPrint("%s", "failed to read json, sub query result file not found\n"); - goto PARSE_OVER; - } - } - } - } - - ret = true; - -PARSE_OVER: - return ret; -} - -static bool getInfoFromJsonFile(char* file) { - debugPrint("%s %d %s\n", __func__, __LINE__, file); - - FILE *fp = fopen(file, "r"); - if (!fp) { - errorPrint("failed to read %s, reason:%s\n", file, strerror(errno)); - return false; - } - - bool ret = false; - int maxLen = MAX_JSON_BUFF; - char *content = calloc(1, maxLen + 1); - int len = fread(content, 1, maxLen, fp); - if (len <= 0) { - free(content); - fclose(fp); - errorPrint("failed to read %s, content is null", file); - return false; - } - - content[len] = 0; - cJSON* root = cJSON_Parse(content); - if (root == NULL) { - errorPrint("failed to cjson parse %s, invalid json format\n", file); - goto PARSE_OVER; - } - - cJSON* filetype = cJSON_GetObjectItem(root, "filetype"); - if (filetype && filetype->type == cJSON_String && filetype->valuestring != NULL) { - if (0 == strcasecmp("insert", filetype->valuestring)) { - g_args.test_mode = INSERT_TEST; - } else if (0 == strcasecmp("query", filetype->valuestring)) { - g_args.test_mode = QUERY_TEST; - } else if (0 == strcasecmp("subscribe", filetype->valuestring)) { - g_args.test_mode = SUBSCRIBE_TEST; - } else { - errorPrint("%s", "failed to read json, filetype not support\n"); - goto PARSE_OVER; - } - } else if (!filetype) { - g_args.test_mode = INSERT_TEST; - } else { - errorPrint("%s", "failed to read json, filetype not found\n"); - goto PARSE_OVER; - } - - if (INSERT_TEST == g_args.test_mode) { - memset(&g_Dbs, 0, sizeof(SDbs)); - g_Dbs.use_metric = g_args.use_metric; - ret = getMetaFromInsertJsonFile(root); - } else if ((QUERY_TEST == g_args.test_mode) - || (SUBSCRIBE_TEST == g_args.test_mode)) { - memset(&g_queryInfo, 0, sizeof(SQueryMetaInfo)); - ret = getMetaFromQueryJsonFile(root); - } else { - errorPrint("%s", - "input json file type error! please input correct file type: insert or query or subscribe\n"); - goto PARSE_OVER; - } - -PARSE_OVER: - free(content); - cJSON_Delete(root); - fclose(fp); - return ret; -} - -static int prepareSampleData() { - for (int i = 0; i < g_Dbs.dbCount; i++) { - for (int j = 0; j < g_Dbs.db[i].superTblCount; j++) { - if (g_Dbs.db[i].superTbls[j].tagsFile[0] != 0) { - if (readTagFromCsvFileToMem(&g_Dbs.db[i].superTbls[j]) != 0) { - return -1; - } - } - } - } - - return 0; -} - -static void postFreeResource() { - tmfclose(g_fpOfInsertResult); - - for (int i = 0; i < g_Dbs.dbCount; i++) { - for (uint64_t j = 0; j < g_Dbs.db[i].superTblCount; j++) { - if (0 != g_Dbs.db[i].superTbls[j].colsOfCreateChildTable) { - tmfree(g_Dbs.db[i].superTbls[j].colsOfCreateChildTable); - g_Dbs.db[i].superTbls[j].colsOfCreateChildTable = NULL; - } - if (0 != g_Dbs.db[i].superTbls[j].sampleDataBuf) { - tmfree(g_Dbs.db[i].superTbls[j].sampleDataBuf); - g_Dbs.db[i].superTbls[j].sampleDataBuf = NULL; - } - -#if STMT_BIND_PARAM_BATCH == 1 - for (int c = 0; - c < g_Dbs.db[i].superTbls[j].columnCount; c ++) { - - if (g_Dbs.db[i].superTbls[j].sampleBindBatchArray) { - - tmfree((char *)((uintptr_t)*(uintptr_t*)( - g_Dbs.db[i].superTbls[j].sampleBindBatchArray - + sizeof(char*) * c))); - } - } - tmfree(g_Dbs.db[i].superTbls[j].sampleBindBatchArray); -#endif - if (0 != g_Dbs.db[i].superTbls[j].tagDataBuf) { - tmfree(g_Dbs.db[i].superTbls[j].tagDataBuf); - g_Dbs.db[i].superTbls[j].tagDataBuf = NULL; - } - if (0 != g_Dbs.db[i].superTbls[j].childTblName) { - tmfree(g_Dbs.db[i].superTbls[j].childTblName); - g_Dbs.db[i].superTbls[j].childTblName = NULL; - } - } - tmfree(g_Dbs.db[i].superTbls); - } - tmfree(g_Dbs.db); - tmfree(g_randbool_buff); - tmfree(g_randint_buff); - tmfree(g_rand_voltage_buff); - tmfree(g_randbigint_buff); - tmfree(g_randsmallint_buff); - tmfree(g_randtinyint_buff); - tmfree(g_randfloat_buff); - tmfree(g_rand_current_buff); - tmfree(g_rand_phase_buff); - - tmfree(g_sampleDataBuf); - -#if STMT_BIND_PARAM_BATCH == 1 - for (int l = 0; - l < g_args.columnCount; l ++) { - if (g_sampleBindBatchArray) { - tmfree((char *)((uintptr_t)*(uintptr_t*)( - g_sampleBindBatchArray - + sizeof(char*) * l))); - } - } - tmfree(g_sampleBindBatchArray); - -#endif -} - -static int getRowDataFromSample( - char* dataBuf, int64_t maxLen, int64_t timestamp, - SSuperTable* stbInfo, int64_t* sampleUsePos) -{ - if ((*sampleUsePos) == MAX_SAMPLES) { - *sampleUsePos = 0; - } - - int dataLen = 0; - if(stbInfo->useSampleTs) { - dataLen += snprintf(dataBuf + dataLen, maxLen - dataLen, - "(%s", - stbInfo->sampleDataBuf - + stbInfo->lenOfOneRow * (*sampleUsePos)); - } else { - dataLen += snprintf(dataBuf + dataLen, maxLen - dataLen, - "(%" PRId64 ", ", timestamp); - dataLen += snprintf(dataBuf + dataLen, maxLen - dataLen, - "%s", - stbInfo->sampleDataBuf - + stbInfo->lenOfOneRow * (*sampleUsePos)); - } - dataLen += snprintf(dataBuf + dataLen, maxLen - dataLen, ")"); - - (*sampleUsePos)++; - - return dataLen; -} - -static int64_t generateStbRowData( - SSuperTable* stbInfo, - char* recBuf, - int64_t remainderBufLen, - int64_t timestamp) -{ - int64_t dataLen = 0; - char *pstr = recBuf; - int64_t maxLen = MAX_DATA_SIZE; - int tmpLen; - - dataLen += snprintf(pstr + dataLen, maxLen - dataLen, - "(%" PRId64 "", timestamp); - - for (int i = 0; i < stbInfo->columnCount; i++) { - tstrncpy(pstr + dataLen, ",", 2); - dataLen += 1; - - if ((stbInfo->columns[i].data_type == TSDB_DATA_TYPE_BINARY) - || (stbInfo->columns[i].data_type == TSDB_DATA_TYPE_NCHAR)) { - if (stbInfo->columns[i].dataLen > TSDB_MAX_BINARY_LEN) { - errorPrint2("binary or nchar length overflow, max size:%u\n", - (uint32_t)TSDB_MAX_BINARY_LEN); - return -1; - } - - if ((stbInfo->columns[i].dataLen + 1) > - /* need count 3 extra chars \', \', and , */ - (remainderBufLen - dataLen - 3)) { - return 0; - } - char* buf = (char*)calloc(stbInfo->columns[i].dataLen+1, 1); - if (NULL == buf) { - errorPrint2("calloc failed! size:%d\n", stbInfo->columns[i].dataLen); - return -1; - } - rand_string(buf, stbInfo->columns[i].dataLen); - dataLen += snprintf(pstr + dataLen, maxLen - dataLen, "\'%s\'", buf); - tmfree(buf); - - } else { - char *tmp = NULL; - switch(stbInfo->columns[i].data_type) { - case TSDB_DATA_TYPE_INT: - if ((g_args.demo_mode) && (i == 1)) { - tmp = demo_voltage_int_str(); - } else { - tmp = rand_int_str(); - } - tmpLen = strlen(tmp); - tstrncpy(pstr + dataLen, tmp, min(tmpLen + 1, INT_BUFF_LEN)); - break; - - case TSDB_DATA_TYPE_UINT: - tmp = rand_uint_str(); - tmpLen = strlen(tmp); - tstrncpy(pstr + dataLen, tmp, min(tmpLen + 1, INT_BUFF_LEN)); - break; - - case TSDB_DATA_TYPE_BIGINT: - tmp = rand_bigint_str(); - tmpLen = strlen(tmp); - tstrncpy(pstr + dataLen, tmp, min(tmpLen + 1, BIGINT_BUFF_LEN)); - break; - - case TSDB_DATA_TYPE_UBIGINT: - tmp = rand_ubigint_str(); - tmpLen = strlen(tmp); - tstrncpy(pstr + dataLen, tmp, min(tmpLen + 1, BIGINT_BUFF_LEN)); - break; - - case TSDB_DATA_TYPE_FLOAT: - if (g_args.demo_mode) { - if (i == 0) { - tmp = demo_current_float_str(); - } else { - tmp = demo_phase_float_str(); - } - } else { - tmp = rand_float_str(); - } - tmpLen = strlen(tmp); - tstrncpy(pstr + dataLen, tmp, min(tmpLen + 1, FLOAT_BUFF_LEN)); - break; - - case TSDB_DATA_TYPE_DOUBLE: - tmp = rand_double_str(); - tmpLen = strlen(tmp); - tstrncpy(pstr + dataLen, tmp, min(tmpLen + 1, DOUBLE_BUFF_LEN)); - break; - - case TSDB_DATA_TYPE_SMALLINT: - tmp = rand_smallint_str(); - tmpLen = strlen(tmp); - tstrncpy(pstr + dataLen, tmp, min(tmpLen + 1, SMALLINT_BUFF_LEN)); - break; - - case TSDB_DATA_TYPE_USMALLINT: - tmp = rand_usmallint_str(); - tmpLen = strlen(tmp); - tstrncpy(pstr + dataLen, tmp, min(tmpLen + 1, SMALLINT_BUFF_LEN)); - break; - - case TSDB_DATA_TYPE_TINYINT: - tmp = rand_tinyint_str(); - tmpLen = strlen(tmp); - tstrncpy(pstr + dataLen, tmp, min(tmpLen + 1, TINYINT_BUFF_LEN)); - break; - - case TSDB_DATA_TYPE_UTINYINT: - tmp = rand_utinyint_str(); - tmpLen = strlen(tmp); - tstrncpy(pstr + dataLen, tmp, min(tmpLen + 1, TINYINT_BUFF_LEN)); - break; - - case TSDB_DATA_TYPE_BOOL: - tmp = rand_bool_str(); - tmpLen = strlen(tmp); - tstrncpy(pstr + dataLen, tmp, min(tmpLen + 1, BOOL_BUFF_LEN)); - break; - - case TSDB_DATA_TYPE_TIMESTAMP: - tmp = rand_bigint_str(); - tmpLen = strlen(tmp); - tstrncpy(pstr + dataLen, tmp, min(tmpLen + 1, BIGINT_BUFF_LEN)); - break; - - case TSDB_DATA_TYPE_NULL: - break; - - default: - errorPrint2("Not support data type: %s\n", - stbInfo->columns[i].dataType); - exit(EXIT_FAILURE); - } - if (tmp) { - dataLen += tmpLen; - } - } - - if (dataLen > (remainderBufLen - (128))) - return 0; - } - - dataLen += snprintf(pstr + dataLen, 2, ")"); - - verbosePrint("%s() LN%d, dataLen:%"PRId64"\n", __func__, __LINE__, dataLen); - verbosePrint("%s() LN%d, recBuf:\n\t%s\n", __func__, __LINE__, recBuf); - - return strlen(recBuf); -} - -static int64_t generateData(char *recBuf, char *data_type, - int64_t timestamp, int lenOfBinary) { - memset(recBuf, 0, MAX_DATA_SIZE); - char *pstr = recBuf; - pstr += sprintf(pstr, "(%"PRId64"", timestamp); - - int columnCount = g_args.columnCount; - - bool b; - char *s; - for (int i = 0; i < columnCount; i++) { - switch (data_type[i]) { - case TSDB_DATA_TYPE_TINYINT: - pstr += sprintf(pstr, ",%d", rand_tinyint() ); - break; - - case TSDB_DATA_TYPE_SMALLINT: - pstr += sprintf(pstr, ",%d", rand_smallint()); - break; - - case TSDB_DATA_TYPE_INT: - pstr += sprintf(pstr, ",%d", rand_int()); - break; - - case TSDB_DATA_TYPE_BIGINT: - pstr += sprintf(pstr, ",%"PRId64"", rand_bigint()); - break; - - case TSDB_DATA_TYPE_TIMESTAMP: - pstr += sprintf(pstr, ",%"PRId64"", rand_bigint()); - break; - - case TSDB_DATA_TYPE_FLOAT: - pstr += sprintf(pstr, ",%10.4f", rand_float()); - break; - - case TSDB_DATA_TYPE_DOUBLE: - pstr += sprintf(pstr, ",%20.8f", rand_double()); - break; - - case TSDB_DATA_TYPE_BOOL: - b = rand_bool() & 1; - pstr += sprintf(pstr, ",%s", b ? "true" : "false"); - break; - - case TSDB_DATA_TYPE_BINARY: - s = malloc(lenOfBinary + 1); - if (s == NULL) { - errorPrint2("%s() LN%d, memory allocation %d bytes failed\n", - __func__, __LINE__, lenOfBinary + 1); - exit(EXIT_FAILURE); - } - rand_string(s, lenOfBinary); - pstr += sprintf(pstr, ",\"%s\"", s); - free(s); - break; - - case TSDB_DATA_TYPE_NCHAR: - s = malloc(lenOfBinary + 1); - if (s == NULL) { - errorPrint2("%s() LN%d, memory allocation %d bytes failed\n", - __func__, __LINE__, lenOfBinary + 1); - exit(EXIT_FAILURE); - } - rand_string(s, lenOfBinary); - pstr += sprintf(pstr, ",\"%s\"", s); - free(s); - break; - - case TSDB_DATA_TYPE_UTINYINT: - pstr += sprintf(pstr, ",%d", rand_utinyint() ); - break; - - case TSDB_DATA_TYPE_USMALLINT: - pstr += sprintf(pstr, ",%d", rand_usmallint()); - break; - - case TSDB_DATA_TYPE_UINT: - pstr += sprintf(pstr, ",%d", rand_uint()); - break; - - case TSDB_DATA_TYPE_UBIGINT: - pstr += sprintf(pstr, ",%"PRId64"", rand_ubigint()); - break; - - case TSDB_DATA_TYPE_NULL: - break; - - default: - errorPrint2("%s() LN%d, Unknown data type %d\n", - __func__, __LINE__, - data_type[i]); - exit(EXIT_FAILURE); - } - - if (strlen(recBuf) > MAX_DATA_SIZE) { - ERROR_EXIT("column length too long, abort"); - } - } - - pstr += sprintf(pstr, ")"); - - verbosePrint("%s() LN%d, recBuf:\n\t%s\n", __func__, __LINE__, recBuf); - - return (int32_t)strlen(recBuf); -} - -static int generateSampleFromRand( - char *sampleDataBuf, - uint64_t lenOfOneRow, - int columnCount, - StrColumn *columns - ) -{ - char data[MAX_DATA_SIZE]; - memset(data, 0, MAX_DATA_SIZE); - - char *buff = malloc(lenOfOneRow); - if (NULL == buff) { - errorPrint2("%s() LN%d, memory allocation %"PRIu64" bytes failed\n", - __func__, __LINE__, lenOfOneRow); - exit(EXIT_FAILURE); - } - - for (int i=0; i < MAX_SAMPLES; i++) { - uint64_t pos = 0; - memset(buff, 0, lenOfOneRow); - - for (int c = 0; c < columnCount; c++) { - char *tmp = NULL; - - uint32_t dataLen; - char data_type = (columns)?(columns[c].data_type):g_args.data_type[c]; - - switch(data_type) { - case TSDB_DATA_TYPE_BINARY: - dataLen = (columns)?columns[c].dataLen:g_args.binwidth; - rand_string(data, dataLen); - pos += sprintf(buff + pos, "%s,", data); - break; - - case TSDB_DATA_TYPE_NCHAR: - dataLen = (columns)?columns[c].dataLen:g_args.binwidth; - rand_string(data, dataLen - 1); - pos += sprintf(buff + pos, "%s,", data); - break; - - case TSDB_DATA_TYPE_INT: - if ((g_args.demo_mode) && (c == 1)) { - tmp = demo_voltage_int_str(); - } else { - tmp = rand_int_str(); - } - pos += sprintf(buff + pos, "%s,", tmp); - break; - - case TSDB_DATA_TYPE_UINT: - pos += sprintf(buff + pos, "%s,", rand_uint_str()); - break; - - case TSDB_DATA_TYPE_BIGINT: - pos += sprintf(buff + pos, "%s,", rand_bigint_str()); - break; - - case TSDB_DATA_TYPE_UBIGINT: - pos += sprintf(buff + pos, "%s,", rand_ubigint_str()); - break; - - case TSDB_DATA_TYPE_FLOAT: - if (g_args.demo_mode) { - if (c == 0) { - tmp = demo_current_float_str(); - } else { - tmp = demo_phase_float_str(); - } - } else { - tmp = rand_float_str(); - } - pos += sprintf(buff + pos, "%s,", tmp); - break; - - case TSDB_DATA_TYPE_DOUBLE: - pos += sprintf(buff + pos, "%s,", rand_double_str()); - break; - - case TSDB_DATA_TYPE_SMALLINT: - pos += sprintf(buff + pos, "%s,", rand_smallint_str()); - break; - - case TSDB_DATA_TYPE_USMALLINT: - pos += sprintf(buff + pos, "%s,", rand_usmallint_str()); - break; - - case TSDB_DATA_TYPE_TINYINT: - pos += sprintf(buff + pos, "%s,", rand_tinyint_str()); - break; - - case TSDB_DATA_TYPE_UTINYINT: - pos += sprintf(buff + pos, "%s,", rand_utinyint_str()); - break; - - case TSDB_DATA_TYPE_BOOL: - pos += sprintf(buff + pos, "%s,", rand_bool_str()); - break; - - case TSDB_DATA_TYPE_TIMESTAMP: - pos += sprintf(buff + pos, "%s,", rand_bigint_str()); - break; - - case TSDB_DATA_TYPE_NULL: - break; - - default: - errorPrint2("%s() LN%d, Unknown data type %s\n", - __func__, __LINE__, - (columns)?(columns[c].dataType):g_args.dataType[c]); - exit(EXIT_FAILURE); - } - } - - *(buff + pos - 1) = 0; - memcpy(sampleDataBuf + i * lenOfOneRow, buff, pos); - } - - free(buff); - return 0; -} - -static int generateSampleFromRandForNtb() -{ - return generateSampleFromRand( - g_sampleDataBuf, - g_args.lenOfOneRow, - g_args.columnCount, - NULL); -} - -static int generateSampleFromRandForStb(SSuperTable *stbInfo) -{ - return generateSampleFromRand( - stbInfo->sampleDataBuf, - stbInfo->lenOfOneRow, - stbInfo->columnCount, - stbInfo->columns); -} - -static int prepareSampleForNtb() { - g_sampleDataBuf = calloc(g_args.lenOfOneRow * MAX_SAMPLES, 1); - if (NULL == g_sampleDataBuf) { - errorPrint2("%s() LN%d, Failed to calloc %"PRIu64" Bytes, reason:%s\n", - __func__, __LINE__, - g_args.lenOfOneRow * MAX_SAMPLES, - strerror(errno)); - return -1; - } - - return generateSampleFromRandForNtb(); -} - -static int prepareSampleForStb(SSuperTable *stbInfo) { - - stbInfo->sampleDataBuf = calloc( - stbInfo->lenOfOneRow * MAX_SAMPLES, 1); - if (NULL == stbInfo->sampleDataBuf) { - errorPrint2("%s() LN%d, Failed to calloc %"PRIu64" Bytes, reason:%s\n", - __func__, __LINE__, - stbInfo->lenOfOneRow * MAX_SAMPLES, - strerror(errno)); - return -1; - } - - int ret; - if (0 == strncasecmp(stbInfo->dataSource, "sample", strlen("sample"))) { - if(stbInfo->useSampleTs) { - getAndSetRowsFromCsvFile(stbInfo); - } - ret = generateSampleFromCsvForStb(stbInfo); - } else { - ret = generateSampleFromRandForStb(stbInfo); - } - - if (0 != ret) { - errorPrint2("%s() LN%d, read sample from csv file failed.\n", - __func__, __LINE__); - tmfree(stbInfo->sampleDataBuf); - stbInfo->sampleDataBuf = NULL; - return -1; - } - - return 0; -} - -static int32_t execInsert(threadInfo *pThreadInfo, uint32_t k) -{ - int32_t affectedRows; - SSuperTable* stbInfo = pThreadInfo->stbInfo; - TAOS_RES* res; - int32_t code; - uint16_t iface; - if (stbInfo) - iface = stbInfo->iface; - else { - if (g_args.iface == INTERFACE_BUT) - iface = TAOSC_IFACE; - else - iface = g_args.iface; - } - - debugPrint("[%d] %s() LN%d %s\n", pThreadInfo->threadID, - __func__, __LINE__, - (iface==TAOSC_IFACE)? - "taosc":(iface==REST_IFACE)?"rest":"stmt"); - - switch(iface) { - case TAOSC_IFACE: - verbosePrint("[%d] %s() LN%d %s\n", pThreadInfo->threadID, - __func__, __LINE__, pThreadInfo->buffer); - - affectedRows = queryDbExec( - pThreadInfo->taos, - pThreadInfo->buffer, INSERT_TYPE, false); - break; - - case REST_IFACE: - verbosePrint("[%d] %s() LN%d %s\n", pThreadInfo->threadID, - __func__, __LINE__, pThreadInfo->buffer); - - if (0 != postProceSql(g_Dbs.host, g_Dbs.port, - pThreadInfo->buffer, pThreadInfo)) { - affectedRows = -1; - printf("========restful return fail, threadID[%d]\n", - pThreadInfo->threadID); - } else { - affectedRows = k; - } - break; - - case STMT_IFACE: - debugPrint("%s() LN%d, stmt=%p", - __func__, __LINE__, pThreadInfo->stmt); - if (0 != taos_stmt_execute(pThreadInfo->stmt)) { - errorPrint2("%s() LN%d, failied to execute insert statement. reason: %s\n", - __func__, __LINE__, taos_stmt_errstr(pThreadInfo->stmt)); - - fprintf(stderr, "\n\033[31m === Please reduce batch number if WAL size exceeds limit. ===\033[0m\n\n"); - exit(EXIT_FAILURE); - } - affectedRows = k; - break; - case SML_IFACE: - res = taos_schemaless_insert(pThreadInfo->taos, pThreadInfo->lines, k, 0, pThreadInfo->time_precision); - code = taos_errno(res); - affectedRows = taos_affected_rows(res); - if (code != TSDB_CODE_SUCCESS) { - errorPrint2("%s() LN%d, failed to execute schemaless insert. reason: %s\n", - __func__, __LINE__, taos_errstr(res)); - exit(EXIT_FAILURE); - } - break; - default: - errorPrint2("%s() LN%d: unknown insert mode: %d\n", - __func__, __LINE__, stbInfo->iface); - affectedRows = 0; - } - - return affectedRows; -} - -static void getTableName(char *pTblName, - threadInfo* pThreadInfo, uint64_t tableSeq) -{ - SSuperTable* stbInfo = pThreadInfo->stbInfo; - if (stbInfo) { - if (AUTO_CREATE_SUBTBL != stbInfo->autoCreateTable) { - if (stbInfo->childTblLimit > 0) { - snprintf(pTblName, TSDB_TABLE_NAME_LEN, - stbInfo->escapeChar ? "`%s`" : "%s", - stbInfo->childTblName + - (tableSeq - stbInfo->childTblOffset) * TSDB_TABLE_NAME_LEN); - } else { - verbosePrint("[%d] %s() LN%d: from=%"PRIu64" count=%"PRId64" seq=%"PRIu64"\n", - pThreadInfo->threadID, __func__, __LINE__, - pThreadInfo->start_table_from, - pThreadInfo->ntables, tableSeq); - snprintf(pTblName, TSDB_TABLE_NAME_LEN, stbInfo->escapeChar ? "`%s`" : "%s", - stbInfo->childTblName + tableSeq * TSDB_TABLE_NAME_LEN); - } - } else { - snprintf(pTblName, TSDB_TABLE_NAME_LEN, - stbInfo->escapeChar ? "`%s%"PRIu64"`" : "%s%"PRIu64"", - stbInfo->childTblPrefix, tableSeq); - } - } else { - snprintf(pTblName, TSDB_TABLE_NAME_LEN, - g_args.escapeChar ? "`%s%"PRIu64"`" : "%s%"PRIu64"", - g_args.tb_prefix, tableSeq); - } -} - -static int32_t generateDataTailWithoutStb( - uint32_t batch, char* buffer, - int64_t remainderBufLen, int64_t insertRows, - uint64_t recordFrom, int64_t startTime, - /* int64_t *pSamplePos, */int64_t *dataLen) { - - uint64_t len = 0; - char *pstr = buffer; - - verbosePrint("%s() LN%d batch=%d\n", __func__, __LINE__, batch); - - int32_t k = 0; - for (k = 0; k < batch;) { - char *data = pstr; - memset(data, 0, MAX_DATA_SIZE); - - int64_t retLen = 0; - - char *data_type = g_args.data_type; - int lenOfBinary = g_args.binwidth; - - if (g_args.disorderRatio) { - retLen = generateData(data, data_type, - startTime + getTSRandTail( - g_args.timestamp_step, k, - g_args.disorderRatio, - g_args.disorderRange), - lenOfBinary); - } else { - retLen = generateData(data, data_type, - startTime + g_args.timestamp_step * k, - lenOfBinary); - } - - if (len > remainderBufLen) - break; - - pstr += retLen; - k++; - len += retLen; - remainderBufLen -= retLen; - - verbosePrint("%s() LN%d len=%"PRIu64" k=%d \nbuffer=%s\n", - __func__, __LINE__, len, k, buffer); - - recordFrom ++; - - if (recordFrom >= insertRows) { - break; - } - } - - *dataLen = len; - return k; -} - -static int64_t getTSRandTail(int64_t timeStampStep, int32_t seq, - int disorderRatio, int disorderRange) -{ - int64_t randTail = timeStampStep * seq; - if (disorderRatio > 0) { - int rand_num = taosRandom() % 100; - if(rand_num < disorderRatio) { - randTail = (randTail + - (taosRandom() % disorderRange + 1)) * (-1); - debugPrint("rand data generated, back %"PRId64"\n", randTail); - } - } - - return randTail; -} - -static int32_t generateStbDataTail( - SSuperTable* stbInfo, - uint32_t batch, char* buffer, - int64_t remainderBufLen, int64_t insertRows, - uint64_t recordFrom, int64_t startTime, - int64_t *pSamplePos, int64_t *dataLen) { - uint64_t len = 0; - - char *pstr = buffer; - - bool tsRand; - if (0 == strncasecmp(stbInfo->dataSource, "rand", strlen("rand"))) { - tsRand = true; - } else { - tsRand = false; - } - verbosePrint("%s() LN%d batch=%u buflen=%"PRId64"\n", - __func__, __LINE__, batch, remainderBufLen); - - int32_t k; - for (k = 0; k < batch;) { - char *data = pstr; - - int64_t lenOfRow = 0; - - if (tsRand) { - if (stbInfo->disorderRatio > 0) { - lenOfRow = generateStbRowData(stbInfo, data, - remainderBufLen, - startTime + getTSRandTail( - stbInfo->timeStampStep, k, - stbInfo->disorderRatio, - stbInfo->disorderRange) - ); - } else { - lenOfRow = generateStbRowData(stbInfo, data, - remainderBufLen, - startTime + stbInfo->timeStampStep * k - ); - } - } else { - lenOfRow = getRowDataFromSample( - data, - (remainderBufLen < MAX_DATA_SIZE)?remainderBufLen:MAX_DATA_SIZE, - startTime + stbInfo->timeStampStep * k, - stbInfo, - pSamplePos); - } - - if (lenOfRow == 0) { - data[0] = '\0'; - break; - } - if ((lenOfRow + 1) > remainderBufLen) { - break; - } - - pstr += lenOfRow; - k++; - len += lenOfRow; - remainderBufLen -= lenOfRow; - - verbosePrint("%s() LN%d len=%"PRIu64" k=%u \nbuffer=%s\n", - __func__, __LINE__, len, k, buffer); - - recordFrom ++; - - if (recordFrom >= insertRows) { - break; - } - } - - *dataLen = len; - return k; -} - - -static int generateSQLHeadWithoutStb(char *tableName, - char *dbName, - char *buffer, int remainderBufLen) -{ - int len; - - char headBuf[HEAD_BUFF_LEN]; - - len = snprintf( - headBuf, - HEAD_BUFF_LEN, - "%s.%s values", - dbName, - tableName); - - if (len > remainderBufLen) - return -1; - - tstrncpy(buffer, headBuf, len + 1); - - return len; -} - -static int generateStbSQLHead( - SSuperTable* stbInfo, - char *tableName, int64_t tableSeq, - char *dbName, - char *buffer, int remainderBufLen) -{ - int len; - - char headBuf[HEAD_BUFF_LEN]; - - if (AUTO_CREATE_SUBTBL == stbInfo->autoCreateTable) { - char* tagsValBuf = NULL; - if (0 == stbInfo->tagSource) { - tagsValBuf = generateTagValuesForStb(stbInfo, tableSeq); - } else { - tagsValBuf = getTagValueFromTagSample( - stbInfo, - tableSeq % stbInfo->tagSampleCount); - } - if (NULL == tagsValBuf) { - errorPrint2("%s() LN%d, tag buf failed to allocate memory\n", - __func__, __LINE__); - return -1; - } - - len = snprintf( - headBuf, - HEAD_BUFF_LEN, - "%s.%s using %s.%s TAGS%s values", - dbName, - tableName, - dbName, - stbInfo->stbName, - tagsValBuf); - tmfree(tagsValBuf); - } else if (TBL_ALREADY_EXISTS == stbInfo->childTblExists) { - len = snprintf( - headBuf, - HEAD_BUFF_LEN, - "%s.%s values", - dbName, - tableName); - } else { - len = snprintf( - headBuf, - HEAD_BUFF_LEN, - "%s.%s values", - dbName, - tableName); - } - - if (len > remainderBufLen) - return -1; - - tstrncpy(buffer, headBuf, len + 1); - - return len; -} - -static int32_t generateStbInterlaceData( - threadInfo *pThreadInfo, - char *tableName, uint32_t batchPerTbl, - uint64_t i, - uint32_t batchPerTblTimes, - uint64_t tableSeq, - char *buffer, - int64_t insertRows, - int64_t startTime, - uint64_t *pRemainderBufLen) -{ - assert(buffer); - char *pstr = buffer; - - SSuperTable *stbInfo = pThreadInfo->stbInfo; - int headLen = generateStbSQLHead( - stbInfo, - tableName, tableSeq, pThreadInfo->db_name, - pstr, *pRemainderBufLen); - - if (headLen <= 0) { - return 0; - } - // generate data buffer - verbosePrint("[%d] %s() LN%d i=%"PRIu64" buffer:\n%s\n", - pThreadInfo->threadID, __func__, __LINE__, i, buffer); - - pstr += headLen; - *pRemainderBufLen -= headLen; - - int64_t dataLen = 0; - - verbosePrint("[%d] %s() LN%d i=%"PRIu64" batchPerTblTimes=%u batchPerTbl = %u\n", - pThreadInfo->threadID, __func__, __LINE__, - i, batchPerTblTimes, batchPerTbl); - - if (0 == strncasecmp(stbInfo->startTimestamp, "now", 3)) { - startTime = taosGetTimestamp(pThreadInfo->time_precision); - } - - int32_t k = generateStbDataTail( - stbInfo, - batchPerTbl, pstr, *pRemainderBufLen, insertRows, 0, - startTime, - &(pThreadInfo->samplePos), &dataLen); - - if (k == batchPerTbl) { - pstr += dataLen; - *pRemainderBufLen -= dataLen; - } else { - debugPrint("%s() LN%d, generated data tail: %u, not equal batch per table: %u\n", - __func__, __LINE__, k, batchPerTbl); - pstr -= headLen; - pstr[0] = '\0'; - k = 0; - } - - return k; -} - -static int64_t generateInterlaceDataWithoutStb( - char *tableName, uint32_t batch, - uint64_t tableSeq, - char *dbName, char *buffer, - int64_t insertRows, - int64_t startTime, - uint64_t *pRemainderBufLen) -{ - assert(buffer); - char *pstr = buffer; - - int headLen = generateSQLHeadWithoutStb( - tableName, dbName, - pstr, *pRemainderBufLen); - - if (headLen <= 0) { - return 0; - } - - pstr += headLen; - *pRemainderBufLen -= headLen; - - int64_t dataLen = 0; - - int32_t k = generateDataTailWithoutStb( - batch, pstr, *pRemainderBufLen, insertRows, 0, - startTime, - &dataLen); - - if (k == batch) { - pstr += dataLen; - *pRemainderBufLen -= dataLen; - } else { - debugPrint("%s() LN%d, generated data tail: %d, not equal batch per table: %u\n", - __func__, __LINE__, k, batch); - pstr -= headLen; - pstr[0] = '\0'; - k = 0; - } - - return k; -} - -static int32_t prepareStmtBindArrayByType( - TAOS_BIND *bind, - char data_type, int32_t dataLen, - int32_t timePrec, - char *value) -{ - int32_t *bind_int; - uint32_t *bind_uint; - int64_t *bind_bigint; - uint64_t *bind_ubigint; - float *bind_float; - double *bind_double; - int8_t *bind_bool; - int64_t *bind_ts2; - int16_t *bind_smallint; - uint16_t *bind_usmallint; - int8_t *bind_tinyint; - uint8_t *bind_utinyint; - - switch(data_type) { - case TSDB_DATA_TYPE_BINARY: - if (dataLen > TSDB_MAX_BINARY_LEN) { - errorPrint2("binary length overflow, max size:%u\n", - (uint32_t)TSDB_MAX_BINARY_LEN); - return -1; - } - char *bind_binary; - - bind->buffer_type = TSDB_DATA_TYPE_BINARY; - if (value) { - bind_binary = calloc(1, strlen(value) + 1); - strncpy(bind_binary, value, strlen(value)); - bind->buffer_length = strlen(bind_binary); - } else { - bind_binary = calloc(1, dataLen + 1); - rand_string(bind_binary, dataLen); - bind->buffer_length = dataLen; - } - - bind->length = &bind->buffer_length; - bind->buffer = bind_binary; - bind->is_null = NULL; - break; - - case TSDB_DATA_TYPE_NCHAR: - if (dataLen > TSDB_MAX_BINARY_LEN) { - errorPrint2("nchar length overflow, max size:%u\n", - (uint32_t)TSDB_MAX_BINARY_LEN); - return -1; - } - char *bind_nchar; - - bind->buffer_type = TSDB_DATA_TYPE_NCHAR; - if (value) { - bind_nchar = calloc(1, strlen(value) + 1); - strncpy(bind_nchar, value, strlen(value)); - } else { - bind_nchar = calloc(1, dataLen + 1); - rand_string(bind_nchar, dataLen); - } - - bind->buffer_length = strlen(bind_nchar); - bind->buffer = bind_nchar; - bind->length = &bind->buffer_length; - bind->is_null = NULL; - break; - - case TSDB_DATA_TYPE_INT: - bind_int = malloc(sizeof(int32_t)); - assert(bind_int); - - if (value) { - *bind_int = atoi(value); - } else { - *bind_int = rand_int(); - } - bind->buffer_type = TSDB_DATA_TYPE_INT; - bind->buffer_length = sizeof(int32_t); - bind->buffer = bind_int; - bind->length = &bind->buffer_length; - bind->is_null = NULL; - break; - - case TSDB_DATA_TYPE_UINT: - bind_uint = malloc(sizeof(uint32_t)); - assert(bind_uint); - - if (value) { - *bind_uint = atoi(value); - } else { - *bind_uint = rand_int(); - } - bind->buffer_type = TSDB_DATA_TYPE_UINT; - bind->buffer_length = sizeof(uint32_t); - bind->buffer = bind_uint; - bind->length = &bind->buffer_length; - bind->is_null = NULL; - break; - - case TSDB_DATA_TYPE_BIGINT: - bind_bigint = malloc(sizeof(int64_t)); - assert(bind_bigint); - - if (value) { - *bind_bigint = atoll(value); - } else { - *bind_bigint = rand_bigint(); - } - bind->buffer_type = TSDB_DATA_TYPE_BIGINT; - bind->buffer_length = sizeof(int64_t); - bind->buffer = bind_bigint; - bind->length = &bind->buffer_length; - bind->is_null = NULL; - break; - - case TSDB_DATA_TYPE_UBIGINT: - bind_ubigint = malloc(sizeof(uint64_t)); - assert(bind_ubigint); - - if (value) { - *bind_ubigint = atoll(value); - } else { - *bind_ubigint = rand_bigint(); - } - bind->buffer_type = TSDB_DATA_TYPE_UBIGINT; - bind->buffer_length = sizeof(uint64_t); - bind->buffer = bind_ubigint; - bind->length = &bind->buffer_length; - bind->is_null = NULL; - break; - - case TSDB_DATA_TYPE_FLOAT: - bind_float = malloc(sizeof(float)); - assert(bind_float); - - if (value) { - *bind_float = (float)atof(value); - } else { - *bind_float = rand_float(); - } - bind->buffer_type = TSDB_DATA_TYPE_FLOAT; - bind->buffer_length = sizeof(float); - bind->buffer = bind_float; - bind->length = &bind->buffer_length; - bind->is_null = NULL; - break; - - case TSDB_DATA_TYPE_DOUBLE: - bind_double = malloc(sizeof(double)); - assert(bind_double); - - if (value) { - *bind_double = atof(value); - } else { - *bind_double = rand_double(); - } - bind->buffer_type = TSDB_DATA_TYPE_DOUBLE; - bind->buffer_length = sizeof(double); - bind->buffer = bind_double; - bind->length = &bind->buffer_length; - bind->is_null = NULL; - break; - - case TSDB_DATA_TYPE_SMALLINT: - bind_smallint = malloc(sizeof(int16_t)); - assert(bind_smallint); - - if (value) { - *bind_smallint = (int16_t)atoi(value); - } else { - *bind_smallint = rand_smallint(); - } - bind->buffer_type = TSDB_DATA_TYPE_SMALLINT; - bind->buffer_length = sizeof(int16_t); - bind->buffer = bind_smallint; - bind->length = &bind->buffer_length; - bind->is_null = NULL; - break; - - case TSDB_DATA_TYPE_USMALLINT: - bind_usmallint = malloc(sizeof(uint16_t)); - assert(bind_usmallint); - - if (value) { - *bind_usmallint = (uint16_t)atoi(value); - } else { - *bind_usmallint = rand_smallint(); - } - bind->buffer_type = TSDB_DATA_TYPE_SMALLINT; - bind->buffer_length = sizeof(uint16_t); - bind->buffer = bind_usmallint; - bind->length = &bind->buffer_length; - bind->is_null = NULL; - break; - - case TSDB_DATA_TYPE_TINYINT: - bind_tinyint = malloc(sizeof(int8_t)); - assert(bind_tinyint); - - if (value) { - *bind_tinyint = (int8_t)atoi(value); - } else { - *bind_tinyint = rand_tinyint(); - } - bind->buffer_type = TSDB_DATA_TYPE_TINYINT; - bind->buffer_length = sizeof(int8_t); - bind->buffer = bind_tinyint; - bind->length = &bind->buffer_length; - bind->is_null = NULL; - break; - - case TSDB_DATA_TYPE_UTINYINT: - bind_utinyint = malloc(sizeof(uint8_t)); - assert(bind_utinyint); - - if (value) { - *bind_utinyint = (int8_t)atoi(value); - } else { - *bind_utinyint = rand_tinyint(); - } - bind->buffer_type = TSDB_DATA_TYPE_UTINYINT; - bind->buffer_length = sizeof(uint8_t); - bind->buffer = bind_utinyint; - bind->length = &bind->buffer_length; - bind->is_null = NULL; - break; - - case TSDB_DATA_TYPE_BOOL: - bind_bool = malloc(sizeof(int8_t)); - assert(bind_bool); - - if (value) { - if (strncasecmp(value, "true", 4)) { - *bind_bool = true; - } else { - *bind_bool = false; - } - } else { - *bind_bool = rand_bool(); - } - bind->buffer_type = TSDB_DATA_TYPE_BOOL; - bind->buffer_length = sizeof(int8_t); - bind->buffer = bind_bool; - bind->length = &bind->buffer_length; - bind->is_null = NULL; - break; - - case TSDB_DATA_TYPE_TIMESTAMP: - bind_ts2 = malloc(sizeof(int64_t)); - assert(bind_ts2); - - if (value) { - if (strchr(value, ':') && strchr(value, '-')) { - int i = 0; - while(value[i] != '\0') { - if (value[i] == '\"' || value[i] == '\'') { - value[i] = ' '; - } - i++; - } - int64_t tmpEpoch; - if (TSDB_CODE_SUCCESS != taosParseTime( - value, &tmpEpoch, strlen(value), - timePrec, 0)) { - free(bind_ts2); - errorPrint2("Input %s, time format error!\n", value); - return -1; - } - *bind_ts2 = tmpEpoch; - } else { - *bind_ts2 = atoll(value); - } - } else { - *bind_ts2 = rand_bigint(); - } - bind->buffer_type = TSDB_DATA_TYPE_TIMESTAMP; - bind->buffer_length = sizeof(int64_t); - bind->buffer = bind_ts2; - bind->length = &bind->buffer_length; - bind->is_null = NULL; - break; - - case TSDB_DATA_TYPE_NULL: - break; - - default: - errorPrint2("Not support data type: %d\n", data_type); - exit(EXIT_FAILURE); - } - - return 0; -} - -static int32_t prepareStmtBindArrayByTypeForRand( - TAOS_BIND *bind, - char data_type, int32_t dataLen, - int32_t timePrec, - char **ptr, - char *value) -{ - int32_t *bind_int; - uint32_t *bind_uint; - int64_t *bind_bigint; - uint64_t *bind_ubigint; - float *bind_float; - double *bind_double; - int16_t *bind_smallint; - uint16_t *bind_usmallint; - int8_t *bind_tinyint; - uint8_t *bind_utinyint; - int8_t *bind_bool; - int64_t *bind_ts2; - - switch(data_type) { - case TSDB_DATA_TYPE_BINARY: - - if (dataLen > TSDB_MAX_BINARY_LEN) { - errorPrint2("binary length overflow, max size:%u\n", - (uint32_t)TSDB_MAX_BINARY_LEN); - return -1; - } - char *bind_binary = (char *)*ptr; - - bind->buffer_type = TSDB_DATA_TYPE_BINARY; - if (value) { - strncpy(bind_binary, value, strlen(value)); - bind->buffer_length = strlen(bind_binary); - } else { - rand_string(bind_binary, dataLen); - bind->buffer_length = dataLen; - } - - bind->length = &bind->buffer_length; - bind->buffer = bind_binary; - bind->is_null = NULL; - - *ptr += bind->buffer_length; - break; - - case TSDB_DATA_TYPE_NCHAR: - if (dataLen > TSDB_MAX_BINARY_LEN) { - errorPrint2("nchar length overflow, max size: %u\n", - (uint32_t)TSDB_MAX_BINARY_LEN); - return -1; - } - char *bind_nchar = (char *)*ptr; - - bind->buffer_type = TSDB_DATA_TYPE_NCHAR; - if (value) { - strncpy(bind_nchar, value, strlen(value)); - } else { - rand_string(bind_nchar, dataLen); - } - - bind->buffer_length = strlen(bind_nchar); - bind->buffer = bind_nchar; - bind->length = &bind->buffer_length; - bind->is_null = NULL; - - *ptr += bind->buffer_length; - break; - - case TSDB_DATA_TYPE_INT: - bind_int = (int32_t *)*ptr; - - if (value) { - *bind_int = atoi(value); - } else { - *bind_int = rand_int(); - } - bind->buffer_type = TSDB_DATA_TYPE_INT; - bind->buffer_length = sizeof(int32_t); - bind->buffer = bind_int; - bind->length = &bind->buffer_length; - bind->is_null = NULL; - - *ptr += bind->buffer_length; - break; - - case TSDB_DATA_TYPE_UINT: - bind_uint = (uint32_t *)*ptr; - - if (value) { - *bind_uint = atoi(value); - } else { - *bind_uint = rand_int(); - } - bind->buffer_type = TSDB_DATA_TYPE_UINT; - bind->buffer_length = sizeof(uint32_t); - bind->buffer = bind_uint; - bind->length = &bind->buffer_length; - bind->is_null = NULL; - - *ptr += bind->buffer_length; - break; - - case TSDB_DATA_TYPE_BIGINT: - bind_bigint = (int64_t *)*ptr; - - if (value) { - *bind_bigint = atoll(value); - } else { - *bind_bigint = rand_bigint(); - } - bind->buffer_type = TSDB_DATA_TYPE_BIGINT; - bind->buffer_length = sizeof(int64_t); - bind->buffer = bind_bigint; - bind->length = &bind->buffer_length; - bind->is_null = NULL; - - *ptr += bind->buffer_length; - break; - - case TSDB_DATA_TYPE_UBIGINT: - bind_ubigint = (uint64_t *)*ptr; - - if (value) { - *bind_ubigint = atoll(value); - } else { - *bind_ubigint = rand_bigint(); - } - bind->buffer_type = TSDB_DATA_TYPE_UBIGINT; - bind->buffer_length = sizeof(uint64_t); - bind->buffer = bind_ubigint; - bind->length = &bind->buffer_length; - bind->is_null = NULL; - - *ptr += bind->buffer_length; - break; - - case TSDB_DATA_TYPE_FLOAT: - bind_float = (float *)*ptr; - - if (value) { - *bind_float = (float)atof(value); - } else { - *bind_float = rand_float(); - } - bind->buffer_type = TSDB_DATA_TYPE_FLOAT; - bind->buffer_length = sizeof(float); - bind->buffer = bind_float; - bind->length = &bind->buffer_length; - bind->is_null = NULL; - - *ptr += bind->buffer_length; - break; - - case TSDB_DATA_TYPE_DOUBLE: - bind_double = (double *)*ptr; - - if (value) { - *bind_double = atof(value); - } else { - *bind_double = rand_double(); - } - bind->buffer_type = TSDB_DATA_TYPE_DOUBLE; - bind->buffer_length = sizeof(double); - bind->buffer = bind_double; - bind->length = &bind->buffer_length; - bind->is_null = NULL; - - *ptr += bind->buffer_length; - break; - - case TSDB_DATA_TYPE_SMALLINT: - bind_smallint = (int16_t *)*ptr; - - if (value) { - *bind_smallint = (int16_t)atoi(value); - } else { - *bind_smallint = rand_smallint(); - } - bind->buffer_type = TSDB_DATA_TYPE_SMALLINT; - bind->buffer_length = sizeof(int16_t); - bind->buffer = bind_smallint; - bind->length = &bind->buffer_length; - bind->is_null = NULL; - - *ptr += bind->buffer_length; - break; - - case TSDB_DATA_TYPE_USMALLINT: - bind_usmallint = (uint16_t *)*ptr; - - if (value) { - *bind_usmallint = (uint16_t)atoi(value); - } else { - *bind_usmallint = rand_smallint(); - } - bind->buffer_type = TSDB_DATA_TYPE_USMALLINT; - bind->buffer_length = sizeof(uint16_t); - bind->buffer = bind_usmallint; - bind->length = &bind->buffer_length; - bind->is_null = NULL; - - *ptr += bind->buffer_length; - break; - - case TSDB_DATA_TYPE_TINYINT: - bind_tinyint = (int8_t *)*ptr; - - if (value) { - *bind_tinyint = (int8_t)atoi(value); - } else { - *bind_tinyint = rand_tinyint(); - } - bind->buffer_type = TSDB_DATA_TYPE_TINYINT; - bind->buffer_length = sizeof(int8_t); - bind->buffer = bind_tinyint; - bind->length = &bind->buffer_length; - bind->is_null = NULL; - - *ptr += bind->buffer_length; - break; - - case TSDB_DATA_TYPE_UTINYINT: - bind_utinyint = (uint8_t *)*ptr; - - if (value) { - *bind_utinyint = (uint8_t)atoi(value); - } else { - *bind_utinyint = rand_tinyint(); - } - bind->buffer_type = TSDB_DATA_TYPE_UTINYINT; - bind->buffer_length = sizeof(uint8_t); - bind->buffer = bind_utinyint; - bind->length = &bind->buffer_length; - bind->is_null = NULL; - - *ptr += bind->buffer_length; - break; - - case TSDB_DATA_TYPE_BOOL: - bind_bool = (int8_t *)*ptr; - - if (value) { - if (strncasecmp(value, "true", 4)) { - *bind_bool = true; - } else { - *bind_bool = false; - } - } else { - *bind_bool = rand_bool(); - } - bind->buffer_type = TSDB_DATA_TYPE_BOOL; - bind->buffer_length = sizeof(int8_t); - bind->buffer = bind_bool; - bind->length = &bind->buffer_length; - bind->is_null = NULL; - - *ptr += bind->buffer_length; - break; - - case TSDB_DATA_TYPE_TIMESTAMP: - bind_ts2 = (int64_t *)*ptr; - - if (value) { - if (strchr(value, ':') && strchr(value, '-')) { - int i = 0; - while(value[i] != '\0') { - if (value[i] == '\"' || value[i] == '\'') { - value[i] = ' '; - } - i++; - } - int64_t tmpEpoch; - if (TSDB_CODE_SUCCESS != taosParseTime( - value, &tmpEpoch, strlen(value), - timePrec, 0)) { - errorPrint2("Input %s, time format error!\n", value); - return -1; - } - *bind_ts2 = tmpEpoch; - } else { - *bind_ts2 = atoll(value); - } - } else { - *bind_ts2 = rand_bigint(); - } - bind->buffer_type = TSDB_DATA_TYPE_TIMESTAMP; - bind->buffer_length = sizeof(int64_t); - bind->buffer = bind_ts2; - bind->length = &bind->buffer_length; - bind->is_null = NULL; - - *ptr += bind->buffer_length; - break; - - default: - errorPrint2("No support data type: %d\n", data_type); - return -1; - } - - return 0; -} - -static int32_t prepareStmtWithoutStb( - threadInfo *pThreadInfo, - char *tableName, - uint32_t batch, - int64_t insertRows, - int64_t recordFrom, - int64_t startTime) -{ - TAOS_STMT *stmt = pThreadInfo->stmt; - int ret = taos_stmt_set_tbname(stmt, tableName); - if (ret != 0) { - errorPrint2("failed to execute taos_stmt_set_tbname(%s). return 0x%x. reason: %s\n", - tableName, ret, taos_stmt_errstr(stmt)); - return ret; - } - - char *data_type = g_args.data_type; - - char *bindArray = malloc(sizeof(TAOS_BIND) * (g_args.columnCount + 1)); - if (bindArray == NULL) { - errorPrint2("Failed to allocate %d bind params\n", - (g_args.columnCount + 1)); - return -1; - } - - int32_t k = 0; - for (k = 0; k < batch;) { - /* columnCount + 1 (ts) */ - - TAOS_BIND *bind = (TAOS_BIND *)(bindArray + 0); - - int64_t *bind_ts = pThreadInfo->bind_ts; - - bind->buffer_type = TSDB_DATA_TYPE_TIMESTAMP; - - if (g_args.disorderRatio) { - *bind_ts = startTime + getTSRandTail( - g_args.timestamp_step, k, - g_args.disorderRatio, - g_args.disorderRange); - } else { - *bind_ts = startTime + g_args.timestamp_step * k; - } - bind->buffer_length = sizeof(int64_t); - bind->buffer = bind_ts; - bind->length = &bind->buffer_length; - bind->is_null = NULL; - - for (int i = 0; i < g_args.columnCount; i ++) { - bind = (TAOS_BIND *)((char *)bindArray - + (sizeof(TAOS_BIND) * (i + 1))); - if ( -1 == prepareStmtBindArrayByType( - bind, - data_type[i], - g_args.binwidth, - pThreadInfo->time_precision, - NULL)) { - free(bindArray); - return -1; - } - } - if (0 != taos_stmt_bind_param(stmt, (TAOS_BIND *)bindArray)) { - errorPrint2("%s() LN%d, stmt_bind_param() failed! reason: %s\n", - __func__, __LINE__, taos_stmt_errstr(stmt)); - break; - } - // if msg > 3MB, break - if (0 != taos_stmt_add_batch(stmt)) { - errorPrint2("%s() LN%d, stmt_add_batch() failed! reason: %s\n", - __func__, __LINE__, taos_stmt_errstr(stmt)); - break; - } - - k++; - recordFrom ++; - if (recordFrom >= insertRows) { - break; - } - } - - free(bindArray); - return k; -} - -static int32_t prepareStbStmtBindTag( - char *bindArray, SSuperTable *stbInfo, - char *tagsVal, - int32_t timePrec) -{ - TAOS_BIND *tag; - - for (int t = 0; t < stbInfo->tagCount; t ++) { - tag = (TAOS_BIND *)((char *)bindArray + (sizeof(TAOS_BIND) * t)); - if ( -1 == prepareStmtBindArrayByType( - tag, - stbInfo->tags[t].data_type, - stbInfo->tags[t].dataLen, - timePrec, - NULL)) { - return -1; - } - } - - return 0; -} - -static int32_t prepareStbStmtBindRand( - int64_t *ts, - char *bindArray, SSuperTable *stbInfo, - int64_t startTime, int32_t recSeq, - int32_t timePrec) -{ - char data[MAX_DATA_SIZE]; - memset(data, 0, MAX_DATA_SIZE); - char *ptr = data; - - TAOS_BIND *bind; - - for (int i = 0; i < stbInfo->columnCount + 1; i ++) { - bind = (TAOS_BIND *)((char *)bindArray + (sizeof(TAOS_BIND) * i)); - - if (i == 0) { - int64_t *bind_ts = ts; - - bind->buffer_type = TSDB_DATA_TYPE_TIMESTAMP; - if (stbInfo->disorderRatio) { - *bind_ts = startTime + getTSRandTail( - stbInfo->timeStampStep, recSeq, - stbInfo->disorderRatio, - stbInfo->disorderRange); - } else { - *bind_ts = startTime + stbInfo->timeStampStep * recSeq; - } - bind->buffer_length = sizeof(int64_t); - bind->buffer = bind_ts; - bind->length = &bind->buffer_length; - bind->is_null = NULL; - - ptr += bind->buffer_length; - } else if ( -1 == prepareStmtBindArrayByTypeForRand( - bind, - stbInfo->columns[i-1].data_type, - stbInfo->columns[i-1].dataLen, - timePrec, - &ptr, - NULL)) { - return -1; - } - } - - return 0; -} - -UNUSED_FUNC static int32_t prepareStbStmtRand( - threadInfo *pThreadInfo, - char *tableName, - int64_t tableSeq, - uint32_t batch, - uint64_t insertRows, - uint64_t recordFrom, - int64_t startTime) -{ - int ret; - SSuperTable *stbInfo = pThreadInfo->stbInfo; - TAOS_STMT *stmt = pThreadInfo->stmt; - - if (AUTO_CREATE_SUBTBL == stbInfo->autoCreateTable) { - char* tagsValBuf = NULL; - - if (0 == stbInfo->tagSource) { - tagsValBuf = generateTagValuesForStb(stbInfo, tableSeq); - } else { - tagsValBuf = getTagValueFromTagSample( - stbInfo, - tableSeq % stbInfo->tagSampleCount); - } - - if (NULL == tagsValBuf) { - errorPrint2("%s() LN%d, tag buf failed to allocate memory\n", - __func__, __LINE__); - return -1; - } - - char *tagsArray = calloc(1, sizeof(TAOS_BIND) * stbInfo->tagCount); - if (NULL == tagsArray) { - tmfree(tagsValBuf); - errorPrint2("%s() LN%d, tag buf failed to allocate memory\n", - __func__, __LINE__); - return -1; - } - - if (-1 == prepareStbStmtBindTag( - tagsArray, stbInfo, tagsValBuf, pThreadInfo->time_precision - /* is tag */)) { - tmfree(tagsValBuf); - tmfree(tagsArray); - return -1; - } - - ret = taos_stmt_set_tbname_tags(stmt, tableName, (TAOS_BIND *)tagsArray); - - tmfree(tagsValBuf); - tmfree(tagsArray); - - if (0 != ret) { - errorPrint2("%s() LN%d, stmt_set_tbname_tags() failed! reason: %s\n", - __func__, __LINE__, taos_stmt_errstr(stmt)); - return -1; - } - } else { - ret = taos_stmt_set_tbname(stmt, tableName); - if (0 != ret) { - errorPrint2("%s() LN%d, stmt_set_tbname() failed! reason: %s\n", - __func__, __LINE__, taos_stmt_errstr(stmt)); - return -1; - } - } - - char *bindArray = calloc(1, sizeof(TAOS_BIND) * (stbInfo->columnCount + 1)); - if (bindArray == NULL) { - errorPrint2("%s() LN%d, Failed to allocate %d bind params\n", - __func__, __LINE__, (stbInfo->columnCount + 1)); - return -1; - } - - uint32_t k; - for (k = 0; k < batch;) { - /* columnCount + 1 (ts) */ - if (-1 == prepareStbStmtBindRand( - pThreadInfo->bind_ts, - bindArray, stbInfo, - startTime, k, - pThreadInfo->time_precision - /* is column */)) { - free(bindArray); - return -1; - } - ret = taos_stmt_bind_param(stmt, (TAOS_BIND *)bindArray); - if (0 != ret) { - errorPrint2("%s() LN%d, stmt_bind_param() failed! reason: %s\n", - __func__, __LINE__, taos_stmt_errstr(stmt)); - free(bindArray); - return -1; - } - // if msg > 3MB, break - ret = taos_stmt_add_batch(stmt); - if (0 != ret) { - errorPrint2("%s() LN%d, stmt_add_batch() failed! reason: %s\n", - __func__, __LINE__, taos_stmt_errstr(stmt)); - free(bindArray); - return -1; - } - - k++; - recordFrom ++; - - if (recordFrom >= insertRows) { - break; - } - } - - free(bindArray); - return k; -} - -#if STMT_BIND_PARAM_BATCH == 1 -static int execStbBindParamBatch( - threadInfo *pThreadInfo, - char *tableName, - int64_t tableSeq, - uint32_t batch, - uint64_t insertRows, - uint64_t recordFrom, - int64_t startTime, - int64_t *pSamplePos) -{ - int ret; - TAOS_STMT *stmt = pThreadInfo->stmt; - - SSuperTable *stbInfo = pThreadInfo->stbInfo; - assert(stbInfo); - - uint32_t columnCount = pThreadInfo->stbInfo->columnCount; - - uint32_t thisBatch = MAX_SAMPLES - (*pSamplePos); - - if (thisBatch > batch) { - thisBatch = batch; - } - verbosePrint("%s() LN%d, batch=%d pos=%"PRId64" thisBatch=%d\n", - __func__, __LINE__, batch, *pSamplePos, thisBatch); - - memset(pThreadInfo->bindParams, 0, - (sizeof(TAOS_MULTI_BIND) * (columnCount + 1))); - memset(pThreadInfo->is_null, 0, thisBatch); - - for (int c = 0; c < columnCount + 1; c ++) { - TAOS_MULTI_BIND *param = (TAOS_MULTI_BIND *)(pThreadInfo->bindParams + sizeof(TAOS_MULTI_BIND) * c); - - char data_type; - - if (c == 0) { - data_type = TSDB_DATA_TYPE_TIMESTAMP; - param->buffer_length = sizeof(int64_t); - param->buffer = pThreadInfo->bind_ts_array; - - } else { - data_type = stbInfo->columns[c-1].data_type; - - char *tmpP; - - switch(data_type) { - case TSDB_DATA_TYPE_BINARY: - param->buffer_length = - stbInfo->columns[c-1].dataLen; - - tmpP = - (char *)((uintptr_t)*(uintptr_t*)(stbInfo->sampleBindBatchArray - +sizeof(char*)*(c-1))); - - verbosePrint("%s() LN%d, tmpP=%p pos=%"PRId64" width=%"PRIxPTR" position=%"PRId64"\n", - __func__, __LINE__, tmpP, *pSamplePos, param->buffer_length, - (*pSamplePos) * param->buffer_length); - - param->buffer = (void *)(tmpP + *pSamplePos * param->buffer_length); - break; - - case TSDB_DATA_TYPE_NCHAR: - param->buffer_length = - stbInfo->columns[c-1].dataLen; - - tmpP = - (char *)((uintptr_t)*(uintptr_t*)(stbInfo->sampleBindBatchArray - +sizeof(char*)*(c-1))); - - verbosePrint("%s() LN%d, tmpP=%p pos=%"PRId64" width=%"PRIxPTR" position=%"PRId64"\n", - __func__, __LINE__, tmpP, *pSamplePos, param->buffer_length, - (*pSamplePos) * param->buffer_length); - - param->buffer = (void *)(tmpP + *pSamplePos * param->buffer_length); - break; - - case TSDB_DATA_TYPE_INT: - case TSDB_DATA_TYPE_UINT: - param->buffer_length = sizeof(int32_t); - param->buffer = - (void *)((uintptr_t)*(uintptr_t*)(stbInfo->sampleBindBatchArray+sizeof(char*)*(c-1)) - + stbInfo->columns[c-1].dataLen * (*pSamplePos)); - break; - - case TSDB_DATA_TYPE_TINYINT: - case TSDB_DATA_TYPE_UTINYINT: - param->buffer_length = sizeof(int8_t); - param->buffer = - (void *)((uintptr_t)*(uintptr_t*)( - stbInfo->sampleBindBatchArray - +sizeof(char*)*(c-1)) - + stbInfo->columns[c-1].dataLen*(*pSamplePos)); - break; - - case TSDB_DATA_TYPE_SMALLINT: - case TSDB_DATA_TYPE_USMALLINT: - param->buffer_length = sizeof(int16_t); - param->buffer = - (void *)((uintptr_t)*(uintptr_t*)(stbInfo->sampleBindBatchArray+sizeof(char*)*(c-1)) - + stbInfo->columns[c-1].dataLen * (*pSamplePos)); - break; - - case TSDB_DATA_TYPE_BIGINT: - case TSDB_DATA_TYPE_UBIGINT: - param->buffer_length = sizeof(int64_t); - param->buffer = - (void *)((uintptr_t)*(uintptr_t*)(stbInfo->sampleBindBatchArray+sizeof(char*)*(c-1)) - + stbInfo->columns[c-1].dataLen * (*pSamplePos)); - break; - - case TSDB_DATA_TYPE_BOOL: - param->buffer_length = sizeof(int8_t); - param->buffer = - (void *)((uintptr_t)*(uintptr_t*)(stbInfo->sampleBindBatchArray+sizeof(char*)*(c-1)) - + stbInfo->columns[c-1].dataLen * (*pSamplePos)); - break; - - case TSDB_DATA_TYPE_FLOAT: - param->buffer_length = sizeof(float); - param->buffer = - (void *)((uintptr_t)*(uintptr_t*)(stbInfo->sampleBindBatchArray+sizeof(char*)*(c-1)) - + stbInfo->columns[c-1].dataLen * (*pSamplePos)); - break; - - case TSDB_DATA_TYPE_DOUBLE: - param->buffer_length = sizeof(double); - param->buffer = - (void *)((uintptr_t)*(uintptr_t*)(stbInfo->sampleBindBatchArray+sizeof(char*)*(c-1)) - + stbInfo->columns[c-1].dataLen * (*pSamplePos)); - break; - - case TSDB_DATA_TYPE_TIMESTAMP: - param->buffer_length = sizeof(int64_t); - param->buffer = - (void *)((uintptr_t)*(uintptr_t*)(stbInfo->sampleBindBatchArray+sizeof(char*)*(c-1)) - + stbInfo->columns[c-1].dataLen * (*pSamplePos)); - break; - - default: - errorPrint("%s() LN%d, wrong data type: %d\n", - __func__, - __LINE__, - data_type); - exit(EXIT_FAILURE); - - } - } - - param->buffer_type = data_type; - param->length = malloc(sizeof(int32_t) * thisBatch); - assert(param->length); - - for (int b = 0; b < thisBatch; b++) { - if (param->buffer_type == TSDB_DATA_TYPE_NCHAR) { - param->length[b] = strlen( - (char *)param->buffer + b * - stbInfo->columns[c].dataLen - ); - } else { - param->length[b] = param->buffer_length; - } - } - param->is_null = pThreadInfo->is_null; - param->num = thisBatch; - } - - uint32_t k; - for (k = 0; k < thisBatch;) { - /* columnCount + 1 (ts) */ - if (stbInfo->disorderRatio) { - *(pThreadInfo->bind_ts_array + k) = startTime + getTSRandTail( - stbInfo->timeStampStep, k, - stbInfo->disorderRatio, - stbInfo->disorderRange); - } else { - *(pThreadInfo->bind_ts_array + k) = startTime + stbInfo->timeStampStep * k; - } - - debugPrint("%s() LN%d, k=%d ts=%"PRId64"\n", - __func__, __LINE__, - k, *(pThreadInfo->bind_ts_array +k)); - k++; - recordFrom ++; - - (*pSamplePos) ++; - if ((*pSamplePos) == MAX_SAMPLES) { - *pSamplePos = 0; - } - - if (recordFrom >= insertRows) { - break; - } - } - - ret = taos_stmt_bind_param_batch(stmt, (TAOS_MULTI_BIND *)pThreadInfo->bindParams); - if (0 != ret) { - errorPrint2("%s() LN%d, stmt_bind_param() failed! reason: %s\n", - __func__, __LINE__, taos_stmt_errstr(stmt)); - return -1; - } - - for (int c = 0; c < stbInfo->columnCount + 1; c ++) { - TAOS_MULTI_BIND *param = (TAOS_MULTI_BIND *)(pThreadInfo->bindParams + sizeof(TAOS_MULTI_BIND) * c); - free(param->length); - } - - // if msg > 3MB, break - ret = taos_stmt_add_batch(stmt); - if (0 != ret) { - errorPrint2("%s() LN%d, stmt_add_batch() failed! reason: %s\n", - __func__, __LINE__, taos_stmt_errstr(stmt)); - return -1; - } - return k; -} - -static int parseSamplefileToStmtBatch( - SSuperTable* stbInfo) -{ - // char *sampleDataBuf = (stbInfo)? - // stbInfo->sampleDataBuf:g_sampleDataBuf; - int32_t columnCount = (stbInfo)?stbInfo->columnCount:g_args.columnCount; - char *sampleBindBatchArray = NULL; - - if (stbInfo) { - stbInfo->sampleBindBatchArray = calloc(1, sizeof(uintptr_t *) * columnCount); - sampleBindBatchArray = stbInfo->sampleBindBatchArray; - } else { - g_sampleBindBatchArray = calloc(1, sizeof(uintptr_t *) * columnCount); - sampleBindBatchArray = g_sampleBindBatchArray; - } - assert(sampleBindBatchArray); - - for (int c = 0; c < columnCount; c++) { - char data_type = (stbInfo)?stbInfo->columns[c].data_type:g_args.data_type[c]; - - char *tmpP = NULL; - - switch(data_type) { - case TSDB_DATA_TYPE_INT: - case TSDB_DATA_TYPE_UINT: - tmpP = calloc(1, sizeof(int) * MAX_SAMPLES); - assert(tmpP); - *(uintptr_t*)(sampleBindBatchArray+ sizeof(uintptr_t*)*c) = (uintptr_t)tmpP; - break; - - case TSDB_DATA_TYPE_TINYINT: - case TSDB_DATA_TYPE_UTINYINT: - tmpP = calloc(1, sizeof(int8_t) * MAX_SAMPLES); - assert(tmpP); - *(uintptr_t*)(sampleBindBatchArray+ sizeof(uintptr_t*)*c) = (uintptr_t)tmpP; - break; - - case TSDB_DATA_TYPE_SMALLINT: - case TSDB_DATA_TYPE_USMALLINT: - tmpP = calloc(1, sizeof(int16_t) * MAX_SAMPLES); - assert(tmpP); - *(uintptr_t*)(sampleBindBatchArray+ sizeof(uintptr_t*)*c) = (uintptr_t)tmpP; - break; - - case TSDB_DATA_TYPE_BIGINT: - case TSDB_DATA_TYPE_UBIGINT: - tmpP = calloc(1, sizeof(int64_t) * MAX_SAMPLES); - assert(tmpP); - *(uintptr_t*)(sampleBindBatchArray+ sizeof(uintptr_t*)*c) = (uintptr_t)tmpP; - break; - - case TSDB_DATA_TYPE_BOOL: - tmpP = calloc(1, sizeof(int8_t) * MAX_SAMPLES); - assert(tmpP); - *(uintptr_t*)(sampleBindBatchArray+ sizeof(uintptr_t*)*c) = (uintptr_t)tmpP; - break; - - case TSDB_DATA_TYPE_FLOAT: - tmpP = calloc(1, sizeof(float) * MAX_SAMPLES); - assert(tmpP); - *(uintptr_t*)(sampleBindBatchArray+ sizeof(uintptr_t*)*c) = (uintptr_t)tmpP; - break; - - case TSDB_DATA_TYPE_DOUBLE: - tmpP = calloc(1, sizeof(double) * MAX_SAMPLES); - assert(tmpP); - *(uintptr_t*)(sampleBindBatchArray+ sizeof(uintptr_t*)*c) = (uintptr_t)tmpP; - break; - - case TSDB_DATA_TYPE_BINARY: - case TSDB_DATA_TYPE_NCHAR: - tmpP = calloc(1, MAX_SAMPLES * - (((stbInfo)?stbInfo->columns[c].dataLen:g_args.binwidth))); - assert(tmpP); - *(uintptr_t*)(sampleBindBatchArray+ sizeof(uintptr_t*)*c) = (uintptr_t)tmpP; - break; - - case TSDB_DATA_TYPE_TIMESTAMP: - tmpP = calloc(1, sizeof(int64_t) * MAX_SAMPLES); - assert(tmpP); - *(uintptr_t*)(sampleBindBatchArray+ sizeof(uintptr_t*)*c) = (uintptr_t)tmpP; - break; - - default: - errorPrint("Unknown data type: %s\n", - (stbInfo)?stbInfo->columns[c].dataType:g_args.dataType[c]); - exit(EXIT_FAILURE); - } - } - - char *sampleDataBuf = (stbInfo)?stbInfo->sampleDataBuf:g_sampleDataBuf; - int64_t lenOfOneRow = (stbInfo)?stbInfo->lenOfOneRow:g_args.lenOfOneRow; - - for (int i=0; i < MAX_SAMPLES; i++) { - int cursor = 0; - - for (int c = 0; c < columnCount; c++) { - char data_type = (stbInfo)? - stbInfo->columns[c].data_type: - g_args.data_type[c]; - char *restStr = sampleDataBuf - + lenOfOneRow * i + cursor; - int lengthOfRest = strlen(restStr); - - int index = 0; - for (index = 0; index < lengthOfRest; index ++) { - if (restStr[index] == ',') { - break; - } - } - - char *tmpStr = calloc(1, index + 1); - if (NULL == tmpStr) { - errorPrint2("%s() LN%d, Failed to allocate %d bind buffer\n", - __func__, __LINE__, index + 1); - return -1; - } - - strncpy(tmpStr, restStr, index); - cursor += index + 1; // skip ',' too - char *tmpP; - - switch(data_type) { - case TSDB_DATA_TYPE_INT: - case TSDB_DATA_TYPE_UINT: - *((int32_t*)((uintptr_t)*(uintptr_t*)(sampleBindBatchArray - +sizeof(char*)*c)+sizeof(int32_t)*i)) = - atoi(tmpStr); - break; - - case TSDB_DATA_TYPE_FLOAT: - *(float*)(((uintptr_t)*(uintptr_t*)(sampleBindBatchArray - +sizeof(char*)*c)+sizeof(float)*i)) = - (float)atof(tmpStr); - break; - - case TSDB_DATA_TYPE_DOUBLE: - *(double*)(((uintptr_t)*(uintptr_t*)(sampleBindBatchArray - +sizeof(char*)*c)+sizeof(double)*i)) = - atof(tmpStr); - break; - - case TSDB_DATA_TYPE_TINYINT: - case TSDB_DATA_TYPE_UTINYINT: - *((int8_t*)((uintptr_t)*(uintptr_t*)(sampleBindBatchArray - +sizeof(char*)*c)+sizeof(int8_t)*i)) = - (int8_t)atoi(tmpStr); - break; - - case TSDB_DATA_TYPE_SMALLINT: - case TSDB_DATA_TYPE_USMALLINT: - *((int16_t*)((uintptr_t)*(uintptr_t*)(sampleBindBatchArray - +sizeof(char*)*c)+sizeof(int16_t)*i)) = - (int16_t)atoi(tmpStr); - break; - - case TSDB_DATA_TYPE_BIGINT: - case TSDB_DATA_TYPE_UBIGINT: - *((int64_t*)((uintptr_t)*(uintptr_t*)(sampleBindBatchArray - +sizeof(char*)*c)+sizeof(int64_t)*i)) = - (int64_t)atol(tmpStr); - break; - - case TSDB_DATA_TYPE_BOOL: - *((int8_t*)((uintptr_t)*(uintptr_t*)(sampleBindBatchArray - +sizeof(char*)*c)+sizeof(int8_t)*i)) = - (int8_t)atoi(tmpStr); - break; - - case TSDB_DATA_TYPE_TIMESTAMP: - *((int64_t*)((uintptr_t)*(uintptr_t*)(sampleBindBatchArray - +sizeof(char*)*c)+sizeof(int64_t)*i)) = - (int64_t)atol(tmpStr); - break; - - case TSDB_DATA_TYPE_BINARY: - case TSDB_DATA_TYPE_NCHAR: - tmpP = (char *)(*(uintptr_t*)(sampleBindBatchArray - +sizeof(char*)*c)); - strcpy(tmpP + i* - (((stbInfo)?stbInfo->columns[c].dataLen:g_args.binwidth)) - , tmpStr); - break; - - default: - break; - } - - free(tmpStr); - } - } - - return 0; -} - -static int parseSampleToStmtBatchForThread( - threadInfo *pThreadInfo, SSuperTable *stbInfo, - uint32_t timePrec, - uint32_t batch) -{ - uint32_t columnCount = (stbInfo)?stbInfo->columnCount:g_args.columnCount; - - pThreadInfo->bind_ts_array = malloc(sizeof(int64_t) * batch); - assert(pThreadInfo->bind_ts_array); - - pThreadInfo->bindParams = malloc(sizeof(TAOS_MULTI_BIND) * (columnCount + 1)); - assert(pThreadInfo->bindParams); - - pThreadInfo->is_null = malloc(batch); - assert(pThreadInfo->is_null); - - return 0; -} - -static int parseStbSampleToStmtBatchForThread( - threadInfo *pThreadInfo, - SSuperTable *stbInfo, - uint32_t timePrec, - uint32_t batch) -{ - return parseSampleToStmtBatchForThread( - pThreadInfo, stbInfo, timePrec, batch); -} - -static int parseNtbSampleToStmtBatchForThread( - threadInfo *pThreadInfo, uint32_t timePrec, uint32_t batch) -{ - return parseSampleToStmtBatchForThread( - pThreadInfo, NULL, timePrec, batch); -} - -#else -static int parseSampleToStmt( - threadInfo *pThreadInfo, - SSuperTable *stbInfo, uint32_t timePrec) -{ - pThreadInfo->sampleBindArray = - (char *)calloc(1, sizeof(char *) * MAX_SAMPLES); - if (pThreadInfo->sampleBindArray == NULL) { - errorPrint2("%s() LN%d, Failed to allocate %"PRIu64" bind array buffer\n", - __func__, __LINE__, - (uint64_t)sizeof(char *) * MAX_SAMPLES); - return -1; - } - - int32_t columnCount = (stbInfo)?stbInfo->columnCount:g_args.columnCount; - char *sampleDataBuf = (stbInfo)?stbInfo->sampleDataBuf:g_sampleDataBuf; - int64_t lenOfOneRow = (stbInfo)?stbInfo->lenOfOneRow:g_args.lenOfOneRow; - - for (int i=0; i < MAX_SAMPLES; i++) { - char *bindArray = - calloc(1, sizeof(TAOS_BIND) * (columnCount + 1)); - if (bindArray == NULL) { - errorPrint2("%s() LN%d, Failed to allocate %d bind params\n", - __func__, __LINE__, (columnCount + 1)); - return -1; - } - - TAOS_BIND *bind; - int cursor = 0; - - for (int c = 0; c < columnCount + 1; c++) { - bind = (TAOS_BIND *)((char *)bindArray + (sizeof(TAOS_BIND) * c)); - - if (c == 0) { - bind->buffer_type = TSDB_DATA_TYPE_TIMESTAMP; - bind->buffer_length = sizeof(int64_t); - bind->buffer = NULL; //bind_ts; - bind->length = &bind->buffer_length; - bind->is_null = NULL; - } else { - char data_type = (stbInfo)? - stbInfo->columns[c-1].data_type: - g_args.data_type[c-1]; - int32_t dataLen = (stbInfo)? - stbInfo->columns[c-1].dataLen: - g_args.binwidth; - char *restStr = sampleDataBuf - + lenOfOneRow * i + cursor; - int lengthOfRest = strlen(restStr); - - int index = 0; - for (index = 0; index < lengthOfRest; index ++) { - if (restStr[index] == ',') { - break; - } - } - - char *bindBuffer = calloc(1, index + 1); - if (bindBuffer == NULL) { - errorPrint2("%s() LN%d, Failed to allocate %d bind buffer\n", - __func__, __LINE__, index + 1); - return -1; - } - - strncpy(bindBuffer, restStr, index); - cursor += index + 1; // skip ',' too - - if (-1 == prepareStmtBindArrayByType( - bind, - data_type, - dataLen, - timePrec, - bindBuffer)) { - free(bindBuffer); - free(bindArray); - return -1; - } - free(bindBuffer); - } - } - *((uintptr_t *)(pThreadInfo->sampleBindArray + (sizeof(char *)) * i)) = - (uintptr_t)bindArray; - } - - return 0; -} - -static int parseStbSampleToStmt( - threadInfo *pThreadInfo, - SSuperTable *stbInfo, uint32_t timePrec) -{ - return parseSampleToStmt( - pThreadInfo, - stbInfo, timePrec); -} - -static int parseNtbSampleToStmt( - threadInfo *pThreadInfo, - uint32_t timePrec) -{ - return parseSampleToStmt( - pThreadInfo, - NULL, - timePrec); -} - -static int32_t prepareStbStmtBindStartTime( - char *tableName, - int64_t *ts, - char *bindArray, SSuperTable *stbInfo, - int64_t startTime, int32_t recSeq) -{ - TAOS_BIND *bind; - - bind = (TAOS_BIND *)bindArray; - - int64_t *bind_ts = ts; - - bind->buffer_type = TSDB_DATA_TYPE_TIMESTAMP; - if (stbInfo->disorderRatio) { - *bind_ts = startTime + getTSRandTail( - stbInfo->timeStampStep, recSeq, - stbInfo->disorderRatio, - stbInfo->disorderRange); - } else { - *bind_ts = startTime + stbInfo->timeStampStep * recSeq; - } - - verbosePrint("%s() LN%d, tableName: %s, bind_ts=%"PRId64"\n", - __func__, __LINE__, tableName, *bind_ts); - - bind->buffer_length = sizeof(int64_t); - bind->buffer = bind_ts; - bind->length = &bind->buffer_length; - bind->is_null = NULL; - - return 0; -} - -static uint32_t execBindParam( - threadInfo *pThreadInfo, - char *tableName, - int64_t tableSeq, - uint32_t batch, - uint64_t insertRows, - uint64_t recordFrom, - int64_t startTime, - int64_t *pSamplePos) -{ - int ret; - SSuperTable *stbInfo = pThreadInfo->stbInfo; - TAOS_STMT *stmt = pThreadInfo->stmt; - - uint32_t k; - for (k = 0; k < batch;) { - char *bindArray = (char *)(*((uintptr_t *) - (pThreadInfo->sampleBindArray + (sizeof(char *)) * (*pSamplePos)))); - /* columnCount + 1 (ts) */ - if (-1 == prepareStbStmtBindStartTime( - tableName, - pThreadInfo->bind_ts, - bindArray, stbInfo, - startTime, k - /* is column */)) { - return -1; - } - ret = taos_stmt_bind_param(stmt, (TAOS_BIND *)bindArray); - if (0 != ret) { - errorPrint2("%s() LN%d, stmt_bind_param() failed! reason: %s\n", - __func__, __LINE__, taos_stmt_errstr(stmt)); - return -1; - } - // if msg > 3MB, break - ret = taos_stmt_add_batch(stmt); - if (0 != ret) { - errorPrint2("%s() LN%d, stmt_add_batch() failed! reason: %s\n", - __func__, __LINE__, taos_stmt_errstr(stmt)); - return -1; - } - - k++; - recordFrom ++; - - (*pSamplePos) ++; - if ((*pSamplePos) == MAX_SAMPLES) { - *pSamplePos = 0; - } - - if (recordFrom >= insertRows) { - break; - } - } - - return k; -} -#endif - -static int32_t prepareStbStmt( - threadInfo *pThreadInfo, - char *tableName, - int64_t tableSeq, - uint32_t batch, - uint64_t insertRows, - uint64_t recordFrom, - int64_t startTime, - int64_t *pSamplePos) -{ - int ret; - SSuperTable *stbInfo = pThreadInfo->stbInfo; - TAOS_STMT *stmt = pThreadInfo->stmt; - - if (AUTO_CREATE_SUBTBL == stbInfo->autoCreateTable) { - char* tagsValBuf = NULL; - - if (0 == stbInfo->tagSource) { - tagsValBuf = generateTagValuesForStb(stbInfo, tableSeq); - } else { - tagsValBuf = getTagValueFromTagSample( - stbInfo, - tableSeq % stbInfo->tagSampleCount); - } - - if (NULL == tagsValBuf) { - errorPrint2("%s() LN%d, tag buf failed to allocate memory\n", - __func__, __LINE__); - return -1; - } - - char *tagsArray = calloc(1, sizeof(TAOS_BIND) * stbInfo->tagCount); - if (NULL == tagsArray) { - tmfree(tagsValBuf); - errorPrint2("%s() LN%d, tag buf failed to allocate memory\n", - __func__, __LINE__); - return -1; - } - - if (-1 == prepareStbStmtBindTag( - tagsArray, stbInfo, tagsValBuf, pThreadInfo->time_precision - /* is tag */)) { - tmfree(tagsValBuf); - tmfree(tagsArray); - return -1; - } - - ret = taos_stmt_set_tbname_tags(stmt, tableName, (TAOS_BIND *)tagsArray); - - tmfree(tagsValBuf); - tmfree(tagsArray); - - if (0 != ret) { - errorPrint2("%s() LN%d, stmt_set_tbname_tags() failed! reason: %s\n", - __func__, __LINE__, taos_stmt_errstr(stmt)); - return -1; - } - } else { - ret = taos_stmt_set_tbname(stmt, tableName); - if (0 != ret) { - errorPrint2("%s() LN%d, stmt_set_tbname() failed! reason: %s\n", - __func__, __LINE__, taos_stmt_errstr(stmt)); - return -1; - } - } - -#if STMT_BIND_PARAM_BATCH == 1 - return execStbBindParamBatch( - pThreadInfo, - tableName, - tableSeq, - batch, - insertRows, - recordFrom, - startTime, - pSamplePos); -#else - return execBindParam( - pThreadInfo, - tableName, - tableSeq, - batch, - insertRows, - recordFrom, - startTime, - pSamplePos); -#endif -} - -static int32_t generateStbProgressiveData( - SSuperTable *stbInfo, - char *tableName, - int64_t tableSeq, - char *dbName, char *buffer, - int64_t insertRows, - uint64_t recordFrom, int64_t startTime, int64_t *pSamplePos, - int64_t *pRemainderBufLen) -{ - assert(buffer != NULL); - char *pstr = buffer; - - memset(pstr, 0, *pRemainderBufLen); - - int64_t headLen = generateStbSQLHead( - stbInfo, - tableName, tableSeq, dbName, - buffer, *pRemainderBufLen); - - if (headLen <= 0) { - return 0; - } - pstr += headLen; - *pRemainderBufLen -= headLen; - - int64_t dataLen; - - return generateStbDataTail(stbInfo, - g_args.reqPerReq, pstr, *pRemainderBufLen, - insertRows, recordFrom, - startTime, - pSamplePos, &dataLen); -} - -static int32_t generateProgressiveDataWithoutStb( - char *tableName, - /* int64_t tableSeq, */ - threadInfo *pThreadInfo, char *buffer, - int64_t insertRows, - uint64_t recordFrom, int64_t startTime, /*int64_t *pSamplePos, */ - int64_t *pRemainderBufLen) -{ - assert(buffer != NULL); - char *pstr = buffer; - - memset(buffer, 0, *pRemainderBufLen); - - int64_t headLen = generateSQLHeadWithoutStb( - tableName, pThreadInfo->db_name, - buffer, *pRemainderBufLen); - - if (headLen <= 0) { - return 0; - } - pstr += headLen; - *pRemainderBufLen -= headLen; - - int64_t dataLen; - - return generateDataTailWithoutStb( - g_args.reqPerReq, pstr, *pRemainderBufLen, insertRows, recordFrom, - startTime, - /*pSamplePos, */&dataLen); -} - -static void printStatPerThread(threadInfo *pThreadInfo) -{ - if (0 == pThreadInfo->totalDelay) - pThreadInfo->totalDelay = 1; - - fprintf(stderr, "====thread[%d] completed total inserted rows: %"PRIu64 ", total affected rows: %"PRIu64". %.2f records/second====\n", - pThreadInfo->threadID, - pThreadInfo->totalInsertRows, - pThreadInfo->totalAffectedRows, - (double)(pThreadInfo->totalAffectedRows/((double)pThreadInfo->totalDelay/1000000.0)) - ); -} - -#if STMT_BIND_PARAM_BATCH == 1 -// stmt sync write interlace data -static void* syncWriteInterlaceStmtBatch(threadInfo *pThreadInfo, uint32_t interlaceRows) { - debugPrint("[%d] %s() LN%d: ### stmt interlace write\n", - pThreadInfo->threadID, __func__, __LINE__); - - int64_t insertRows; - int64_t timeStampStep; - uint64_t insert_interval; - - SSuperTable* stbInfo = pThreadInfo->stbInfo; - - if (stbInfo) { - insertRows = stbInfo->insertRows; - timeStampStep = stbInfo->timeStampStep; - insert_interval = stbInfo->insertInterval; - } else { - insertRows = g_args.insertRows; - timeStampStep = g_args.timestamp_step; - insert_interval = g_args.insert_interval; - } - - debugPrint("[%d] %s() LN%d: start_table_from=%"PRIu64" ntables=%"PRId64" insertRows=%"PRIu64"\n", - pThreadInfo->threadID, __func__, __LINE__, - pThreadInfo->start_table_from, - pThreadInfo->ntables, insertRows); - - uint64_t timesInterlace = (insertRows / interlaceRows) + 1; - uint32_t precalcBatch = interlaceRows; - - if (precalcBatch > g_args.reqPerReq) - precalcBatch = g_args.reqPerReq; - - if (precalcBatch > MAX_SAMPLES) - precalcBatch = MAX_SAMPLES; - - pThreadInfo->totalInsertRows = 0; - pThreadInfo->totalAffectedRows = 0; - - uint64_t st = 0; - uint64_t et = UINT64_MAX; - - uint64_t lastPrintTime = taosGetTimestampMs(); - uint64_t startTs = taosGetTimestampMs(); - uint64_t endTs; - - uint64_t tableSeq = pThreadInfo->start_table_from; - int64_t startTime; - - bool flagSleep = true; - uint64_t sleepTimeTotal = 0; - - int percentComplete = 0; - int64_t totalRows = insertRows * pThreadInfo->ntables; - pThreadInfo->samplePos = 0; - - for (int64_t interlace = 0; - interlace < timesInterlace; interlace ++) { - if ((flagSleep) && (insert_interval)) { - st = taosGetTimestampMs(); - flagSleep = false; - } - - int64_t generated = 0; - int64_t samplePos; - - for (; tableSeq < pThreadInfo->start_table_from + pThreadInfo->ntables; tableSeq ++) { - char tableName[TSDB_TABLE_NAME_LEN]; - getTableName(tableName, pThreadInfo, tableSeq); - if (0 == strlen(tableName)) { - errorPrint2("[%d] %s() LN%d, getTableName return null\n", - pThreadInfo->threadID, __func__, __LINE__); - return NULL; - } - - samplePos = pThreadInfo->samplePos; - startTime = pThreadInfo->start_time - + interlace * interlaceRows * timeStampStep; - uint64_t remainRecPerTbl = - insertRows - interlaceRows * interlace; - uint64_t recPerTbl = 0; - - uint64_t remainPerInterlace; - if (remainRecPerTbl > interlaceRows) { - remainPerInterlace = interlaceRows; - } else { - remainPerInterlace = remainRecPerTbl; - } - - while(remainPerInterlace > 0) { - - uint32_t batch; - if (remainPerInterlace > precalcBatch) { - batch = precalcBatch; - } else { - batch = remainPerInterlace; - } - debugPrint("[%d] %s() LN%d, tableName:%s, batch:%d startTime:%"PRId64"\n", - pThreadInfo->threadID, - __func__, __LINE__, - tableName, batch, startTime); - - if (stbInfo) { - generated = prepareStbStmt( - pThreadInfo, - tableName, - tableSeq, - batch, - insertRows, 0, - startTime, - &samplePos); - } else { - generated = prepareStmtWithoutStb( - pThreadInfo, - tableName, - batch, - insertRows, - interlaceRows * interlace + recPerTbl, - startTime); - } - - debugPrint("[%d] %s() LN%d, generated records is %"PRId64"\n", - pThreadInfo->threadID, __func__, __LINE__, generated); - if (generated < 0) { - errorPrint2("[%d] %s() LN%d, generated records is %"PRId64"\n", - pThreadInfo->threadID, __func__, __LINE__, generated); - goto free_of_interlace_stmt; - } else if (generated == 0) { - break; - } - - recPerTbl += generated; - remainPerInterlace -= generated; - pThreadInfo->totalInsertRows += generated; - - verbosePrint("[%d] %s() LN%d totalInsertRows=%"PRIu64"\n", - pThreadInfo->threadID, __func__, __LINE__, - pThreadInfo->totalInsertRows); - - startTs = taosGetTimestampUs(); - - int64_t affectedRows = execInsert(pThreadInfo, generated); - - endTs = taosGetTimestampUs(); - uint64_t delay = endTs - startTs; - performancePrint("%s() LN%d, insert execution time is %10.2f ms\n", - __func__, __LINE__, delay / 1000.0); - verbosePrint("[%d] %s() LN%d affectedRows=%"PRId64"\n", - pThreadInfo->threadID, - __func__, __LINE__, affectedRows); - - if (delay > pThreadInfo->maxDelay) pThreadInfo->maxDelay = delay; - if (delay < pThreadInfo->minDelay) pThreadInfo->minDelay = delay; - pThreadInfo->cntDelay++; - pThreadInfo->totalDelay += delay; - - if (generated != affectedRows) { - errorPrint2("[%d] %s() LN%d execInsert() insert %"PRId64", affected rows: %"PRId64"\n\n", - pThreadInfo->threadID, __func__, __LINE__, - generated, affectedRows); - goto free_of_interlace_stmt; - } - - pThreadInfo->totalAffectedRows += affectedRows; - - int currentPercent = pThreadInfo->totalAffectedRows * 100 / totalRows; - if (currentPercent > percentComplete ) { - printf("[%d]:%d%%\n", pThreadInfo->threadID, currentPercent); - percentComplete = currentPercent; - } - int64_t currentPrintTime = taosGetTimestampMs(); - if (currentPrintTime - lastPrintTime > 30*1000) { - printf("thread[%d] has currently inserted rows: %"PRIu64 ", affected rows: %"PRIu64 "\n", - pThreadInfo->threadID, - pThreadInfo->totalInsertRows, - pThreadInfo->totalAffectedRows); - lastPrintTime = currentPrintTime; - } - - startTime += (generated * timeStampStep); - } - } - pThreadInfo->samplePos = samplePos; - - if (tableSeq == pThreadInfo->start_table_from - + pThreadInfo->ntables) { - // turn to first table - tableSeq = pThreadInfo->start_table_from; - - flagSleep = true; - } - - if ((insert_interval) && flagSleep) { - et = taosGetTimestampMs(); - - if (insert_interval > (et - st) ) { - uint64_t sleepTime = insert_interval - (et -st); - performancePrint("%s() LN%d sleep: %"PRId64" ms for insert interval\n", - __func__, __LINE__, sleepTime); - taosMsleep(sleepTime); // ms - sleepTimeTotal += insert_interval; - } - } - } - if (percentComplete < 100) - printf("[%d]:%d%%\n", pThreadInfo->threadID, percentComplete); - -free_of_interlace_stmt: - printStatPerThread(pThreadInfo); - return NULL; -} -#else -// stmt sync write interlace data -static void* syncWriteInterlaceStmt(threadInfo *pThreadInfo, uint32_t interlaceRows) { - debugPrint("[%d] %s() LN%d: ### stmt interlace write\n", - pThreadInfo->threadID, __func__, __LINE__); - - int64_t insertRows; - uint64_t maxSqlLen; - int64_t timeStampStep; - uint64_t insert_interval; - - SSuperTable* stbInfo = pThreadInfo->stbInfo; - - if (stbInfo) { - insertRows = stbInfo->insertRows; - maxSqlLen = stbInfo->maxSqlLen; - timeStampStep = stbInfo->timeStampStep; - insert_interval = stbInfo->insertInterval; - } else { - insertRows = g_args.insertRows; - maxSqlLen = g_args.max_sql_len; - timeStampStep = g_args.timestamp_step; - insert_interval = g_args.insert_interval; - } - - debugPrint("[%d] %s() LN%d: start_table_from=%"PRIu64" ntables=%"PRId64" insertRows=%"PRIu64"\n", - pThreadInfo->threadID, __func__, __LINE__, - pThreadInfo->start_table_from, - pThreadInfo->ntables, insertRows); - - uint32_t batchPerTbl = interlaceRows; - uint32_t batchPerTblTimes; - - if (interlaceRows > g_args.reqPerReq) - interlaceRows = g_args.reqPerReq; - - if ((interlaceRows > 0) && (pThreadInfo->ntables > 1)) { - batchPerTblTimes = - g_args.reqPerReq / interlaceRows; - } else { - batchPerTblTimes = 1; - } - - pThreadInfo->totalInsertRows = 0; - pThreadInfo->totalAffectedRows = 0; - - uint64_t st = 0; - uint64_t et = UINT64_MAX; - - uint64_t lastPrintTime = taosGetTimestampMs(); - uint64_t startTs = taosGetTimestampMs(); - uint64_t endTs; - - uint64_t tableSeq = pThreadInfo->start_table_from; - int64_t startTime = pThreadInfo->start_time; - - uint64_t generatedRecPerTbl = 0; - bool flagSleep = true; - uint64_t sleepTimeTotal = 0; - - int percentComplete = 0; - int64_t totalRows = insertRows * pThreadInfo->ntables; - - while(pThreadInfo->totalInsertRows < pThreadInfo->ntables * insertRows) { - if ((flagSleep) && (insert_interval)) { - st = taosGetTimestampMs(); - flagSleep = false; - } - - uint32_t recOfBatch = 0; - - int32_t generated; - for (uint64_t i = 0; i < batchPerTblTimes; i ++) { - char tableName[TSDB_TABLE_NAME_LEN]; - - getTableName(tableName, pThreadInfo, tableSeq); - if (0 == strlen(tableName)) { - errorPrint2("[%d] %s() LN%d, getTableName return null\n", - pThreadInfo->threadID, __func__, __LINE__); - return NULL; - } - - debugPrint("[%d] %s() LN%d, tableName:%s, batch:%d startTime:%"PRId64"\n", - pThreadInfo->threadID, - __func__, __LINE__, - tableName, batchPerTbl, startTime); - if (stbInfo) { - generated = prepareStbStmt( - pThreadInfo, - tableName, - tableSeq, - batchPerTbl, - insertRows, 0, - startTime, - &(pThreadInfo->samplePos)); - } else { - generated = prepareStmtWithoutStb( - pThreadInfo, - tableName, - batchPerTbl, - insertRows, i, - startTime); - } - - debugPrint("[%d] %s() LN%d, generated records is %d\n", - pThreadInfo->threadID, __func__, __LINE__, generated); - if (generated < 0) { - errorPrint2("[%d] %s() LN%d, generated records is %d\n", - pThreadInfo->threadID, __func__, __LINE__, generated); - goto free_of_interlace_stmt; - } else if (generated == 0) { - break; - } - - tableSeq ++; - recOfBatch += batchPerTbl; - - pThreadInfo->totalInsertRows += batchPerTbl; - - verbosePrint("[%d] %s() LN%d batchPerTbl=%d recOfBatch=%d\n", - pThreadInfo->threadID, __func__, __LINE__, - batchPerTbl, recOfBatch); - - if (tableSeq == pThreadInfo->start_table_from + pThreadInfo->ntables) { - // turn to first table - tableSeq = pThreadInfo->start_table_from; - generatedRecPerTbl += batchPerTbl; - - startTime = pThreadInfo->start_time - + generatedRecPerTbl * timeStampStep; - - flagSleep = true; - if (generatedRecPerTbl >= insertRows) - break; - - int64_t remainRows = insertRows - generatedRecPerTbl; - if ((remainRows > 0) && (batchPerTbl > remainRows)) - batchPerTbl = remainRows; - - if (pThreadInfo->ntables * batchPerTbl < g_args.reqPerReq) - break; - } - - verbosePrint("[%d] %s() LN%d generatedRecPerTbl=%"PRId64" insertRows=%"PRId64"\n", - pThreadInfo->threadID, __func__, __LINE__, - generatedRecPerTbl, insertRows); - - if ((g_args.reqPerReq - recOfBatch) < batchPerTbl) - break; - } - - verbosePrint("[%d] %s() LN%d recOfBatch=%d totalInsertRows=%"PRIu64"\n", - pThreadInfo->threadID, __func__, __LINE__, recOfBatch, - pThreadInfo->totalInsertRows); - - startTs = taosGetTimestampUs(); - - if (recOfBatch == 0) { - errorPrint2("[%d] %s() LN%d Failed to insert records of batch %d\n", - pThreadInfo->threadID, __func__, __LINE__, - batchPerTbl); - if (batchPerTbl > 0) { - errorPrint("\tIf the batch is %d, the length of the SQL to insert a row must be less then %"PRId64"\n", - batchPerTbl, maxSqlLen / batchPerTbl); - } - goto free_of_interlace_stmt; - } - int64_t affectedRows = execInsert(pThreadInfo, recOfBatch); - - endTs = taosGetTimestampUs(); - uint64_t delay = endTs - startTs; - performancePrint("%s() LN%d, insert execution time is %10.2f ms\n", - __func__, __LINE__, delay / 1000.0); - verbosePrint("[%d] %s() LN%d affectedRows=%"PRId64"\n", - pThreadInfo->threadID, - __func__, __LINE__, affectedRows); - - if (delay > pThreadInfo->maxDelay) pThreadInfo->maxDelay = delay; - if (delay < pThreadInfo->minDelay) pThreadInfo->minDelay = delay; - pThreadInfo->cntDelay++; - pThreadInfo->totalDelay += delay; - - if (recOfBatch != affectedRows) { - errorPrint2("[%d] %s() LN%d execInsert insert %d, affected rows: %"PRId64"\n\n", - pThreadInfo->threadID, __func__, __LINE__, - recOfBatch, affectedRows); - goto free_of_interlace_stmt; - } - - pThreadInfo->totalAffectedRows += affectedRows; - - int currentPercent = pThreadInfo->totalAffectedRows * 100 / totalRows; - if (currentPercent > percentComplete ) { - printf("[%d]:%d%%\n", pThreadInfo->threadID, currentPercent); - percentComplete = currentPercent; - } - int64_t currentPrintTime = taosGetTimestampMs(); - if (currentPrintTime - lastPrintTime > 30*1000) { - printf("thread[%d] has currently inserted rows: %"PRIu64 ", affected rows: %"PRIu64 "\n", - pThreadInfo->threadID, - pThreadInfo->totalInsertRows, - pThreadInfo->totalAffectedRows); - lastPrintTime = currentPrintTime; - } - - if ((insert_interval) && flagSleep) { - et = taosGetTimestampMs(); - - if (insert_interval > (et - st) ) { - uint64_t sleepTime = insert_interval - (et -st); - performancePrint("%s() LN%d sleep: %"PRId64" ms for insert interval\n", - __func__, __LINE__, sleepTime); - taosMsleep(sleepTime); // ms - sleepTimeTotal += insert_interval; - } - } - } - if (percentComplete < 100) - printf("[%d]:%d%%\n", pThreadInfo->threadID, percentComplete); - -free_of_interlace_stmt: - printStatPerThread(pThreadInfo); - return NULL; -} - -#endif - -static void generateSmlHead(char* smlHead, SSuperTable* stbInfo, threadInfo* pThreadInfo, int tbSeq) { - int64_t dataLen = 0; - dataLen += snprintf(smlHead + dataLen, HEAD_BUFF_LEN - dataLen, - "%s,id=%s%" PRIu64 "", stbInfo->stbName, - stbInfo->childTblPrefix, - tbSeq + pThreadInfo->start_table_from); - for (int j = 0; j < stbInfo->tagCount; j++) { - tstrncpy(smlHead + dataLen, ",", 2); - dataLen += 1; - switch (stbInfo->tags[j].data_type) { - case TSDB_DATA_TYPE_TIMESTAMP: - errorPrint2( - "%s() LN%d, Does not support data type %s as tag\n", - __func__, __LINE__, stbInfo->tags[j].dataType); - exit(EXIT_FAILURE); - case TSDB_DATA_TYPE_BOOL: - dataLen += - snprintf(smlHead + dataLen, HEAD_BUFF_LEN - dataLen, - "T%d=%s", j, rand_bool_str()); - break; - case TSDB_DATA_TYPE_TINYINT: - dataLen += - snprintf(smlHead + dataLen, HEAD_BUFF_LEN - dataLen, - "T%d=%si8", j, rand_tinyint_str()); - break; - case TSDB_DATA_TYPE_UTINYINT: - dataLen += - snprintf(smlHead + dataLen, HEAD_BUFF_LEN - dataLen, - "T%d=%su8", j, rand_utinyint_str()); - break; - case TSDB_DATA_TYPE_SMALLINT: - dataLen += - snprintf(smlHead + dataLen, HEAD_BUFF_LEN - dataLen, - "T%d=%si16", j, rand_smallint_str()); - break; - case TSDB_DATA_TYPE_USMALLINT: - dataLen += - snprintf(smlHead + dataLen, HEAD_BUFF_LEN - dataLen, - "T%d=%su16", j, rand_usmallint_str()); - break; - case TSDB_DATA_TYPE_INT: - dataLen += - snprintf(smlHead + dataLen, HEAD_BUFF_LEN - dataLen, - "T%d=%si32", j, rand_int_str()); - break; - case TSDB_DATA_TYPE_UINT: - dataLen += - snprintf(smlHead + dataLen, HEAD_BUFF_LEN - dataLen, - "T%d=%su32", j, rand_uint_str()); - break; - case TSDB_DATA_TYPE_BIGINT: - dataLen += - snprintf(smlHead + dataLen, HEAD_BUFF_LEN - dataLen, - "T%d=%si64", j, rand_bigint_str()); - break; - case TSDB_DATA_TYPE_UBIGINT: - dataLen += - snprintf(smlHead + dataLen, HEAD_BUFF_LEN - dataLen, - "T%d=%su64", j, rand_ubigint_str()); - break; - case TSDB_DATA_TYPE_FLOAT: - dataLen += - snprintf(smlHead + dataLen, HEAD_BUFF_LEN - dataLen, - "T%d=%sf32", j, rand_float_str()); - break; - case TSDB_DATA_TYPE_DOUBLE: - dataLen += - snprintf(smlHead + dataLen, HEAD_BUFF_LEN - dataLen, - "T%d=%sf64", j, rand_double_str()); - break; - case TSDB_DATA_TYPE_BINARY: - case TSDB_DATA_TYPE_NCHAR: - if (stbInfo->tags[j].dataLen > TSDB_MAX_BINARY_LEN) { - errorPrint2( - "binary or nchar length overflow, maxsize:%u\n", - (uint32_t)TSDB_MAX_BINARY_LEN); - exit(EXIT_FAILURE); - } - char *buf = (char *)calloc(stbInfo->tags[j].dataLen + 1, 1); - if (NULL == buf) { - errorPrint2("calloc failed! size:%d\n", - stbInfo->tags[j].dataLen); - exit(EXIT_FAILURE); - } - rand_string(buf, stbInfo->tags[j].dataLen); - if (stbInfo->tags[j].data_type == TSDB_DATA_TYPE_BINARY) { - dataLen += snprintf(smlHead + dataLen, - HEAD_BUFF_LEN - dataLen, - "T%d=\"%s\"", j, buf); - } else { - dataLen += snprintf(smlHead + dataLen, - HEAD_BUFF_LEN - dataLen, - "T%d=L\"%s\"", j, buf); - } - tmfree(buf); - break; - - default: - errorPrint2("%s() LN%d, Unknown data type %s\n", __func__, - __LINE__, stbInfo->tags[j].dataType); - exit(EXIT_FAILURE); - } - } -} - -static void generateSmlTail(char* line, char* smlHead, SSuperTable* stbInfo, - threadInfo* pThreadInfo, int64_t timestamp) { - int dataLen = 0; - dataLen = snprintf(line, BUFFER_SIZE, "%s ", smlHead); - for (uint32_t c = 0; c < stbInfo->columnCount; c++) { - if (c != 0) { - tstrncpy(line + dataLen, ",", 2); - dataLen += 1; - } - switch (stbInfo->columns[c].data_type) { - case TSDB_DATA_TYPE_TIMESTAMP: - errorPrint2( - "%s() LN%d, Does not support data type %s as tag\n", - __func__, __LINE__, stbInfo->columns[c].dataType); - exit(EXIT_FAILURE); - case TSDB_DATA_TYPE_BOOL: - dataLen += snprintf(line + dataLen, - BUFFER_SIZE - dataLen, "c%d=%s", - c, rand_bool_str()); - break; - case TSDB_DATA_TYPE_TINYINT: - dataLen += snprintf(line + dataLen, - BUFFER_SIZE - dataLen, "c%d=%si8", - c, rand_tinyint_str()); - break; - case TSDB_DATA_TYPE_UTINYINT: - dataLen += snprintf(line + dataLen, - BUFFER_SIZE - dataLen, "c%d=%su8", - c, rand_utinyint_str()); - break; - case TSDB_DATA_TYPE_SMALLINT: - dataLen += snprintf( - line + dataLen, BUFFER_SIZE - dataLen, - "c%d=%si16", c, rand_smallint_str()); - break; - case TSDB_DATA_TYPE_USMALLINT: - dataLen += snprintf( - line + dataLen, BUFFER_SIZE - dataLen, - "c%d=%su16", c, rand_usmallint_str()); - break; - case TSDB_DATA_TYPE_INT: - dataLen += snprintf(line + dataLen, - BUFFER_SIZE - dataLen, - "c%d=%si32", c, rand_int_str()); - break; - case TSDB_DATA_TYPE_UINT: - dataLen += snprintf(line + dataLen, - BUFFER_SIZE - dataLen, - "c%d=%su32", c, rand_uint_str()); - break; - case TSDB_DATA_TYPE_BIGINT: - dataLen += snprintf(line + dataLen, - BUFFER_SIZE - dataLen, - "c%d=%si64", c, rand_bigint_str()); - break; - case TSDB_DATA_TYPE_UBIGINT: - dataLen += snprintf(line + dataLen, - BUFFER_SIZE - dataLen, - "c%d=%su64", c, rand_ubigint_str()); - break; - case TSDB_DATA_TYPE_FLOAT: - dataLen += snprintf(line + dataLen, - BUFFER_SIZE - dataLen, - "c%d=%sf32", c, rand_float_str()); - break; - case TSDB_DATA_TYPE_DOUBLE: - dataLen += snprintf(line + dataLen, - BUFFER_SIZE - dataLen, - "c%d=%sf64", c, rand_double_str()); - break; - case TSDB_DATA_TYPE_BINARY: - case TSDB_DATA_TYPE_NCHAR: - if (stbInfo->columns[c].dataLen > TSDB_MAX_BINARY_LEN) { - errorPrint2( - "binary or nchar length overflow, maxsize:%u\n", - (uint32_t)TSDB_MAX_BINARY_LEN); - exit(EXIT_FAILURE); - } - char *buf = - (char *)calloc(stbInfo->columns[c].dataLen + 1, 1); - if (NULL == buf) { - errorPrint2("calloc failed! size:%d\n", - stbInfo->columns[c].dataLen); - exit(EXIT_FAILURE); - } - rand_string(buf, stbInfo->columns[c].dataLen); - if (stbInfo->columns[c].data_type == - TSDB_DATA_TYPE_BINARY) { - dataLen += snprintf(line + dataLen, - BUFFER_SIZE - dataLen, - "c%d=\"%s\"", c, buf); - } else { - dataLen += snprintf(line + dataLen, - BUFFER_SIZE - dataLen, - "c%d=L\"%s\"", c, buf); - } - tmfree(buf); - break; - default: - errorPrint2("%s() LN%d, Unknown data type %s\n", - __func__, __LINE__, - stbInfo->columns[c].dataType); - exit(EXIT_FAILURE); - } - } - dataLen += snprintf(line + dataLen, BUFFER_SIZE - dataLen," %" PRId64 "", timestamp); -} - -static void* syncWriteInterlaceSml(threadInfo *pThreadInfo, uint32_t interlaceRows) { - debugPrint("[%d] %s() LN%d: ### interlace schemaless write\n", - pThreadInfo->threadID, __func__, __LINE__); - int64_t insertRows; - uint64_t maxSqlLen; - int64_t timeStampStep; - uint64_t insert_interval; - - SSuperTable* stbInfo = pThreadInfo->stbInfo; - - if (stbInfo) { - insertRows = stbInfo->insertRows; - maxSqlLen = stbInfo->maxSqlLen; - timeStampStep = stbInfo->timeStampStep; - insert_interval = stbInfo->insertInterval; - } else { - insertRows = g_args.insertRows; - maxSqlLen = g_args.max_sql_len; - timeStampStep = g_args.timestamp_step; - insert_interval = g_args.insert_interval; - } - - debugPrint("[%d] %s() LN%d: start_table_from=%"PRIu64" ntables=%"PRId64" insertRows=%"PRIu64"\n", - pThreadInfo->threadID, __func__, __LINE__, - pThreadInfo->start_table_from, - pThreadInfo->ntables, insertRows); - - if (interlaceRows > g_args.reqPerReq) - interlaceRows = g_args.reqPerReq; - - uint32_t batchPerTbl = interlaceRows; - uint32_t batchPerTblTimes; - - if ((interlaceRows > 0) && (pThreadInfo->ntables > 1)) { - batchPerTblTimes = - g_args.reqPerReq / interlaceRows; - } else { - batchPerTblTimes = 1; - } - - char **smlHeadList = calloc(pThreadInfo->ntables, sizeof(char *)); - assert(smlHeadList); - for (int t = 0; t < pThreadInfo->ntables; t++) { - char* smlHead = *((char **)smlHeadList + t * sizeof(char *)); - smlHead = (char *)calloc(HEAD_BUFF_LEN, 1); - if (NULL == smlHead) { - errorPrint2("calloc failed! size:%d\n", HEAD_BUFF_LEN); - exit(EXIT_FAILURE); - } - generateSmlHead(smlHead, stbInfo, pThreadInfo, t); - - } - - pThreadInfo->totalInsertRows = 0; - pThreadInfo->totalAffectedRows = 0; - - uint64_t st = 0; - uint64_t et = UINT64_MAX; - - uint64_t lastPrintTime = taosGetTimestampMs(); - uint64_t startTs = taosGetTimestampMs(); - uint64_t endTs; - - uint64_t tableSeq = pThreadInfo->start_table_from; - int64_t startTime = pThreadInfo->start_time; - - uint64_t generatedRecPerTbl = 0; - bool flagSleep = true; - uint64_t sleepTimeTotal = 0; - - int percentComplete = 0; - int64_t totalRows = insertRows * pThreadInfo->ntables; - - pThreadInfo->lines = calloc(g_args.reqPerReq, sizeof(char *)); - if (NULL == pThreadInfo->lines) { - errorPrint2("Failed to alloc %"PRIu64" bytes, reason:%s\n", - g_args.reqPerReq * (uint64_t)sizeof(char *), - strerror(errno)); - return NULL; - } - - while(pThreadInfo->totalInsertRows < pThreadInfo->ntables * insertRows) { - if ((flagSleep) && (insert_interval)) { - st = taosGetTimestampMs(); - flagSleep = false; - } - - // generate data - - uint32_t recOfBatch = 0; - - for (uint64_t i = 0; i < batchPerTblTimes; i++) { - int64_t timestamp = startTime; - for (int j = recOfBatch; j < recOfBatch + batchPerTbl; j++) { - pThreadInfo->lines[j] = calloc(BUFFER_SIZE, 1); - if (NULL == pThreadInfo->lines[j]) { - errorPrint2("Failed to alloc %d bytes, reason:%s\n", - BUFFER_SIZE, strerror(errno)); - } - generateSmlTail(pThreadInfo->lines[j], *((char **)smlHeadList + i * sizeof(char *)), stbInfo, pThreadInfo, timestamp); - timestamp += timeStampStep; - } - tableSeq ++; - recOfBatch += batchPerTbl; - - pThreadInfo->totalInsertRows += batchPerTbl; - - verbosePrint("[%d] %s() LN%d batchPerTbl=%d recOfBatch=%d\n", - pThreadInfo->threadID, __func__, __LINE__, - batchPerTbl, recOfBatch); - - if (tableSeq == pThreadInfo->start_table_from + pThreadInfo->ntables) { - // turn to first table - tableSeq = pThreadInfo->start_table_from; - generatedRecPerTbl += batchPerTbl; - - startTime = pThreadInfo->start_time - + generatedRecPerTbl * timeStampStep; - - flagSleep = true; - if (generatedRecPerTbl >= insertRows) - break; - - int64_t remainRows = insertRows - generatedRecPerTbl; - if ((remainRows > 0) && (batchPerTbl > remainRows)) - batchPerTbl = remainRows; - - if (pThreadInfo->ntables * batchPerTbl < g_args.reqPerReq) - break; - } - - verbosePrint("[%d] %s() LN%d generatedRecPerTbl=%"PRId64" insertRows=%"PRId64"\n", - pThreadInfo->threadID, __func__, __LINE__, - generatedRecPerTbl, insertRows); - - if ((g_args.reqPerReq - recOfBatch) < batchPerTbl) - break; - } - - verbosePrint("[%d] %s() LN%d recOfBatch=%d totalInsertRows=%"PRIu64"\n", - pThreadInfo->threadID, __func__, __LINE__, recOfBatch, - pThreadInfo->totalInsertRows); - verbosePrint("[%d] %s() LN%d, buffer=%s\n", - pThreadInfo->threadID, __func__, __LINE__, pThreadInfo->buffer); - - startTs = taosGetTimestampUs(); - - if (recOfBatch == 0) { - errorPrint2("[%d] %s() LN%d Failed to insert records of batch %d\n", - pThreadInfo->threadID, __func__, __LINE__, - batchPerTbl); - if (batchPerTbl > 0) { - errorPrint("\tIf the batch is %d, the length of the SQL to insert a row must be less then %"PRId64"\n", - batchPerTbl, maxSqlLen / batchPerTbl); - } - errorPrint("\tPlease check if the buffer length(%"PRId64") or batch(%d) is set with proper value!\n", - maxSqlLen, batchPerTbl); - goto free_of_interlace; - } - int64_t affectedRows = execInsert(pThreadInfo, recOfBatch); - - endTs = taosGetTimestampUs(); - uint64_t delay = endTs - startTs; - performancePrint("%s() LN%d, insert execution time is %10.2f ms\n", - __func__, __LINE__, delay / 1000.0); - verbosePrint("[%d] %s() LN%d affectedRows=%"PRId64"\n", - pThreadInfo->threadID, - __func__, __LINE__, affectedRows); - - if (delay > pThreadInfo->maxDelay) pThreadInfo->maxDelay = delay; - if (delay < pThreadInfo->minDelay) pThreadInfo->minDelay = delay; - pThreadInfo->cntDelay++; - pThreadInfo->totalDelay += delay; - - if (recOfBatch != affectedRows) { - errorPrint2("[%d] %s() LN%d execInsert insert %d, affected rows: %"PRId64"\n%s\n", - pThreadInfo->threadID, __func__, __LINE__, - recOfBatch, affectedRows, pThreadInfo->buffer); - goto free_of_interlace; - } - - pThreadInfo->totalAffectedRows += affectedRows; - - int currentPercent = pThreadInfo->totalAffectedRows * 100 / totalRows; - if (currentPercent > percentComplete ) { - printf("[%d]:%d%%\n", pThreadInfo->threadID, currentPercent); - percentComplete = currentPercent; - } - int64_t currentPrintTime = taosGetTimestampMs(); - if (currentPrintTime - lastPrintTime > 30*1000) { - printf("thread[%d] has currently inserted rows: %"PRIu64 ", affected rows: %"PRIu64 "\n", - pThreadInfo->threadID, - pThreadInfo->totalInsertRows, - pThreadInfo->totalAffectedRows); - lastPrintTime = currentPrintTime; - } - - if ((insert_interval) && flagSleep) { - et = taosGetTimestampMs(); - - if (insert_interval > (et - st) ) { - uint64_t sleepTime = insert_interval - (et -st); - performancePrint("%s() LN%d sleep: %"PRId64" ms for insert interval\n", - __func__, __LINE__, sleepTime); - taosMsleep(sleepTime); // ms - sleepTimeTotal += insert_interval; - } - } - for (int index = 0; index < g_args.reqPerReq; index++) { - free(pThreadInfo->lines[index]); - } - } - if (percentComplete < 100) - printf("[%d]:%d%%\n", pThreadInfo->threadID, percentComplete); - -free_of_interlace: - tmfree(pThreadInfo->lines); - for (int index = 0; index < pThreadInfo->ntables; index++) { - tmfree(*(smlHeadList + index*(sizeof(char*)))); - } - tmfree(smlHeadList); - printStatPerThread(pThreadInfo); - return NULL; -} - -// sync write interlace data -static void* syncWriteInterlace(threadInfo *pThreadInfo, uint32_t interlaceRows) { - debugPrint("[%d] %s() LN%d: ### interlace write\n", - pThreadInfo->threadID, __func__, __LINE__); - - int64_t insertRows; - uint64_t maxSqlLen; - int64_t timeStampStep; - uint64_t insert_interval; - - SSuperTable* stbInfo = pThreadInfo->stbInfo; - - if (stbInfo) { - insertRows = stbInfo->insertRows; - maxSqlLen = stbInfo->maxSqlLen; - timeStampStep = stbInfo->timeStampStep; - insert_interval = stbInfo->insertInterval; - } else { - insertRows = g_args.insertRows; - maxSqlLen = g_args.max_sql_len; - timeStampStep = g_args.timestamp_step; - insert_interval = g_args.insert_interval; - } - - debugPrint("[%d] %s() LN%d: start_table_from=%"PRIu64" ntables=%"PRId64" insertRows=%"PRIu64"\n", - pThreadInfo->threadID, __func__, __LINE__, - pThreadInfo->start_table_from, - pThreadInfo->ntables, insertRows); -#if 1 - if (interlaceRows > g_args.reqPerReq) - interlaceRows = g_args.reqPerReq; - - uint32_t batchPerTbl = interlaceRows; - uint32_t batchPerTblTimes; - - if ((interlaceRows > 0) && (pThreadInfo->ntables > 1)) { - batchPerTblTimes = - g_args.reqPerReq / interlaceRows; - } else { - batchPerTblTimes = 1; - } -#else - uint32_t batchPerTbl; - if (interlaceRows > g_args.reqPerReq) - batchPerTbl = g_args.reqPerReq; - else - batchPerTbl = interlaceRows; - - uint32_t batchPerTblTimes; - - if ((interlaceRows > 0) && (pThreadInfo->ntables > 1)) { - batchPerTblTimes = - interlaceRows / batchPerTbl; - } else { - batchPerTblTimes = 1; - } -#endif - pThreadInfo->buffer = calloc(maxSqlLen, 1); - if (NULL == pThreadInfo->buffer) { - errorPrint2( "%s() LN%d, Failed to alloc %"PRIu64" Bytes, reason:%s\n", - __func__, __LINE__, maxSqlLen, strerror(errno)); - return NULL; - } - - pThreadInfo->totalInsertRows = 0; - pThreadInfo->totalAffectedRows = 0; - - uint64_t st = 0; - uint64_t et = UINT64_MAX; - - uint64_t lastPrintTime = taosGetTimestampMs(); - uint64_t startTs = taosGetTimestampMs(); - uint64_t endTs; - - uint64_t tableSeq = pThreadInfo->start_table_from; - int64_t startTime = pThreadInfo->start_time; - - uint64_t generatedRecPerTbl = 0; - bool flagSleep = true; - uint64_t sleepTimeTotal = 0; - - int percentComplete = 0; - int64_t totalRows = insertRows * pThreadInfo->ntables; - - while(pThreadInfo->totalInsertRows < pThreadInfo->ntables * insertRows) { - if ((flagSleep) && (insert_interval)) { - st = taosGetTimestampMs(); - flagSleep = false; - } - - // generate data - memset(pThreadInfo->buffer, 0, maxSqlLen); - uint64_t remainderBufLen = maxSqlLen; - - char *pstr = pThreadInfo->buffer; - - int len = snprintf(pstr, - strlen(STR_INSERT_INTO) + 1, "%s", STR_INSERT_INTO); - pstr += len; - remainderBufLen -= len; - - uint32_t recOfBatch = 0; - - int32_t generated; - for (uint64_t i = 0; i < batchPerTblTimes; i ++) { - char tableName[TSDB_TABLE_NAME_LEN]; - - getTableName(tableName, pThreadInfo, tableSeq); - if (0 == strlen(tableName)) { - errorPrint2("[%d] %s() LN%d, getTableName return null\n", - pThreadInfo->threadID, __func__, __LINE__); - free(pThreadInfo->buffer); - return NULL; - } - - uint64_t oldRemainderLen = remainderBufLen; - - if (stbInfo) { - generated = generateStbInterlaceData( - pThreadInfo, - tableName, batchPerTbl, i, - batchPerTblTimes, - tableSeq, - pstr, - insertRows, - startTime, - &remainderBufLen); - } else { - generated = generateInterlaceDataWithoutStb( - tableName, batchPerTbl, - tableSeq, - pThreadInfo->db_name, pstr, - insertRows, - startTime, - &remainderBufLen); - } - - debugPrint("[%d] %s() LN%d, generated records is %d\n", - pThreadInfo->threadID, __func__, __LINE__, generated); - if (generated < 0) { - errorPrint2("[%d] %s() LN%d, generated records is %d\n", - pThreadInfo->threadID, __func__, __LINE__, generated); - goto free_of_interlace; - } else if (generated == 0) { - break; - } - - tableSeq ++; - recOfBatch += batchPerTbl; - - pstr += (oldRemainderLen - remainderBufLen); - pThreadInfo->totalInsertRows += batchPerTbl; - - verbosePrint("[%d] %s() LN%d batchPerTbl=%d recOfBatch=%d\n", - pThreadInfo->threadID, __func__, __LINE__, - batchPerTbl, recOfBatch); - - if (tableSeq == pThreadInfo->start_table_from + pThreadInfo->ntables) { - // turn to first table - tableSeq = pThreadInfo->start_table_from; - generatedRecPerTbl += batchPerTbl; - - startTime = pThreadInfo->start_time - + generatedRecPerTbl * timeStampStep; - - flagSleep = true; - if (generatedRecPerTbl >= insertRows) - break; - - int64_t remainRows = insertRows - generatedRecPerTbl; - if ((remainRows > 0) && (batchPerTbl > remainRows)) - batchPerTbl = remainRows; - - if (pThreadInfo->ntables * batchPerTbl < g_args.reqPerReq) - break; - } - - verbosePrint("[%d] %s() LN%d generatedRecPerTbl=%"PRId64" insertRows=%"PRId64"\n", - pThreadInfo->threadID, __func__, __LINE__, - generatedRecPerTbl, insertRows); - - if ((g_args.reqPerReq - recOfBatch) < batchPerTbl) - break; - } - - verbosePrint("[%d] %s() LN%d recOfBatch=%d totalInsertRows=%"PRIu64"\n", - pThreadInfo->threadID, __func__, __LINE__, recOfBatch, - pThreadInfo->totalInsertRows); - verbosePrint("[%d] %s() LN%d, buffer=%s\n", - pThreadInfo->threadID, __func__, __LINE__, pThreadInfo->buffer); - - startTs = taosGetTimestampUs(); - - if (recOfBatch == 0) { - errorPrint2("[%d] %s() LN%d Failed to insert records of batch %d\n", - pThreadInfo->threadID, __func__, __LINE__, - batchPerTbl); - if (batchPerTbl > 0) { - errorPrint("\tIf the batch is %d, the length of the SQL to insert a row must be less then %"PRId64"\n", - batchPerTbl, maxSqlLen / batchPerTbl); - } - errorPrint("\tPlease check if the buffer length(%"PRId64") or batch(%d) is set with proper value!\n", - maxSqlLen, batchPerTbl); - goto free_of_interlace; - } - int64_t affectedRows = execInsert(pThreadInfo, recOfBatch); - - endTs = taosGetTimestampUs(); - uint64_t delay = endTs - startTs; - performancePrint("%s() LN%d, insert execution time is %10.2f ms\n", - __func__, __LINE__, delay / 1000.0); - verbosePrint("[%d] %s() LN%d affectedRows=%"PRId64"\n", - pThreadInfo->threadID, - __func__, __LINE__, affectedRows); - - if (delay > pThreadInfo->maxDelay) pThreadInfo->maxDelay = delay; - if (delay < pThreadInfo->minDelay) pThreadInfo->minDelay = delay; - pThreadInfo->cntDelay++; - pThreadInfo->totalDelay += delay; - - if (recOfBatch != affectedRows) { - errorPrint2("[%d] %s() LN%d execInsert insert %d, affected rows: %"PRId64"\n%s\n", - pThreadInfo->threadID, __func__, __LINE__, - recOfBatch, affectedRows, pThreadInfo->buffer); - goto free_of_interlace; - } - - pThreadInfo->totalAffectedRows += affectedRows; - - int currentPercent = pThreadInfo->totalAffectedRows * 100 / totalRows; - if (currentPercent > percentComplete ) { - printf("[%d]:%d%%\n", pThreadInfo->threadID, currentPercent); - percentComplete = currentPercent; - } - int64_t currentPrintTime = taosGetTimestampMs(); - if (currentPrintTime - lastPrintTime > 30*1000) { - printf("thread[%d] has currently inserted rows: %"PRIu64 ", affected rows: %"PRIu64 "\n", - pThreadInfo->threadID, - pThreadInfo->totalInsertRows, - pThreadInfo->totalAffectedRows); - lastPrintTime = currentPrintTime; - } - - if ((insert_interval) && flagSleep) { - et = taosGetTimestampMs(); - - if (insert_interval > (et - st) ) { - uint64_t sleepTime = insert_interval - (et -st); - performancePrint("%s() LN%d sleep: %"PRId64" ms for insert interval\n", - __func__, __LINE__, sleepTime); - taosMsleep(sleepTime); // ms - sleepTimeTotal += insert_interval; - } - } - } - if (percentComplete < 100) - printf("[%d]:%d%%\n", pThreadInfo->threadID, percentComplete); - -free_of_interlace: - tmfree(pThreadInfo->buffer); - printStatPerThread(pThreadInfo); - return NULL; -} - -static void* syncWriteProgressiveStmt(threadInfo *pThreadInfo) { - debugPrint("%s() LN%d: ### stmt progressive write\n", __func__, __LINE__); - - SSuperTable* stbInfo = pThreadInfo->stbInfo; - int64_t timeStampStep = - stbInfo?stbInfo->timeStampStep:g_args.timestamp_step; - int64_t insertRows = - (stbInfo)?stbInfo->insertRows:g_args.insertRows; - verbosePrint("%s() LN%d insertRows=%"PRId64"\n", - __func__, __LINE__, insertRows); - - uint64_t lastPrintTime = taosGetTimestampMs(); - uint64_t startTs = taosGetTimestampMs(); - uint64_t endTs; - - pThreadInfo->totalInsertRows = 0; - pThreadInfo->totalAffectedRows = 0; - - pThreadInfo->samplePos = 0; - - int percentComplete = 0; - int64_t totalRows = insertRows * pThreadInfo->ntables; - - for (uint64_t tableSeq = pThreadInfo->start_table_from; - tableSeq <= pThreadInfo->end_table_to; - tableSeq ++) { - int64_t start_time = pThreadInfo->start_time; - - for (uint64_t i = 0; i < insertRows;) { - char tableName[TSDB_TABLE_NAME_LEN]; - getTableName(tableName, pThreadInfo, tableSeq); - verbosePrint("%s() LN%d: tid=%d seq=%"PRId64" tableName=%s\n", - __func__, __LINE__, - pThreadInfo->threadID, tableSeq, tableName); - if (0 == strlen(tableName)) { - errorPrint2("[%d] %s() LN%d, getTableName return null\n", - pThreadInfo->threadID, __func__, __LINE__); - return NULL; - } - - // measure prepare + insert - startTs = taosGetTimestampUs(); - - int32_t generated; - if (stbInfo) { - generated = prepareStbStmt( - pThreadInfo, - tableName, - tableSeq, - (g_args.reqPerReq>stbInfo->insertRows)? - stbInfo->insertRows: - g_args.reqPerReq, - insertRows, i, start_time, - &(pThreadInfo->samplePos)); - } else { - generated = prepareStmtWithoutStb( - pThreadInfo, - tableName, - g_args.reqPerReq, - insertRows, i, - start_time); - } - - verbosePrint("[%d] %s() LN%d generated=%d\n", - pThreadInfo->threadID, - __func__, __LINE__, generated); - - if (generated > 0) - i += generated; - else - goto free_of_stmt_progressive; - - start_time += generated * timeStampStep; - pThreadInfo->totalInsertRows += generated; - - // only measure insert - // startTs = taosGetTimestampUs(); - - int32_t affectedRows = execInsert(pThreadInfo, generated); - - endTs = taosGetTimestampUs(); - uint64_t delay = endTs - startTs; - performancePrint("%s() LN%d, insert execution time is %10.f ms\n", - __func__, __LINE__, delay/1000.0); - verbosePrint("[%d] %s() LN%d affectedRows=%d\n", - pThreadInfo->threadID, - __func__, __LINE__, affectedRows); - - if (delay > pThreadInfo->maxDelay) pThreadInfo->maxDelay = delay; - if (delay < pThreadInfo->minDelay) pThreadInfo->minDelay = delay; - pThreadInfo->cntDelay++; - pThreadInfo->totalDelay += delay; - - if (affectedRows < 0) { - errorPrint2("%s() LN%d, affected rows: %d\n", - __func__, __LINE__, affectedRows); - goto free_of_stmt_progressive; - } - - pThreadInfo->totalAffectedRows += affectedRows; - - int currentPercent = pThreadInfo->totalAffectedRows * 100 / totalRows; - if (currentPercent > percentComplete ) { - printf("[%d]:%d%%\n", pThreadInfo->threadID, currentPercent); - percentComplete = currentPercent; - } - int64_t currentPrintTime = taosGetTimestampMs(); - if (currentPrintTime - lastPrintTime > 30*1000) { - printf("thread[%d] has currently inserted rows: %"PRId64 ", affected rows: %"PRId64 "\n", - pThreadInfo->threadID, - pThreadInfo->totalInsertRows, - pThreadInfo->totalAffectedRows); - lastPrintTime = currentPrintTime; - } - - if (i >= insertRows) - break; - } // insertRows - - if ((g_args.verbose_print) && - (tableSeq == pThreadInfo->ntables - 1) && (stbInfo) - && (0 == strncasecmp( - stbInfo->dataSource, - "sample", strlen("sample")))) { - verbosePrint("%s() LN%d samplePos=%"PRId64"\n", - __func__, __LINE__, pThreadInfo->samplePos); - } - } // tableSeq - - if (percentComplete < 100) { - printf("[%d]:%d%%\n", pThreadInfo->threadID, percentComplete); - } - -free_of_stmt_progressive: - tmfree(pThreadInfo->buffer); - printStatPerThread(pThreadInfo); - return NULL; -} - -static void* syncWriteProgressiveSml(threadInfo *pThreadInfo) { - debugPrint("%s() LN%d: ### sml progressive write\n", __func__, __LINE__); - - SSuperTable* stbInfo = pThreadInfo->stbInfo; - int64_t timeStampStep = stbInfo->timeStampStep; - int64_t insertRows = stbInfo->insertRows; - verbosePrint("%s() LN%d insertRows=%"PRId64"\n", - __func__, __LINE__, insertRows); - - uint64_t lastPrintTime = taosGetTimestampMs(); - - pThreadInfo->totalInsertRows = 0; - pThreadInfo->totalAffectedRows = 0; - - pThreadInfo->samplePos = 0; - - char *smlHeadList = calloc(pThreadInfo->ntables, sizeof(char *)); - assert(smlHeadList); - for (int t = 0; t < pThreadInfo->ntables; t++) { - char* smlHead = *((char**)smlHeadList + t * sizeof(char *)); - smlHead = (char *)calloc(HEAD_BUFF_LEN, 1); - if (NULL == smlHead) { - errorPrint2("calloc failed! size:%d\n", HEAD_BUFF_LEN); - exit(EXIT_FAILURE); - } - generateSmlHead(smlHead, stbInfo, pThreadInfo, t); - - } - int currentPercent = 0; - int percentComplete = 0; - - if (insertRows < g_args.reqPerReq) { - g_args.reqPerReq = insertRows; - } - pThreadInfo->lines = calloc(g_args.reqPerReq, sizeof(char *)); - if (NULL == pThreadInfo->lines) { - errorPrint2("Failed to alloc %"PRIu64" bytes, reason:%s\n", - g_args.reqPerReq * (uint64_t)sizeof(char *), - strerror(errno)); - return NULL; - } - - for (uint64_t i = 0; i < pThreadInfo->ntables; i++) { - int64_t timestamp = pThreadInfo->start_time; - - for (uint64_t j = 0; j < insertRows;) { - for (int k = 0; k < g_args.reqPerReq; k++) { - pThreadInfo->lines[k] = calloc(BUFFER_SIZE, 1); - if (NULL == pThreadInfo->lines[k]) { - errorPrint2("Failed to alloc %d bytes, reason:%s\n", - BUFFER_SIZE, strerror(errno)); - } - generateSmlTail(pThreadInfo->lines[k], *((char**)smlHeadList + i * sizeof(char *)), stbInfo, pThreadInfo, timestamp); - timestamp += timeStampStep; - j++; - if (j == insertRows) { - break; - } - } - uint64_t startTs = taosGetTimestampUs(); - int32_t affectedRows = execInsert(pThreadInfo, g_args.reqPerReq); - uint64_t endTs = taosGetTimestampUs(); - uint64_t delay = endTs - startTs; - - performancePrint("%s() LN%d, insert execution time is %10.f ms\n", - __func__, __LINE__, delay/1000.0); - verbosePrint("[%d] %s() LN%d affectedRows=%d\n", - pThreadInfo->threadID, - __func__, __LINE__, affectedRows); - - if (delay > pThreadInfo->maxDelay){ - pThreadInfo->maxDelay = delay; - } - if (delay < pThreadInfo->minDelay){ - pThreadInfo->minDelay = delay; - } - pThreadInfo->cntDelay++; - pThreadInfo->totalDelay += delay; - - pThreadInfo->totalAffectedRows += affectedRows; - pThreadInfo->totalInsertRows += g_args.reqPerReq; - currentPercent = - pThreadInfo->totalAffectedRows * g_Dbs.threadCount / insertRows; - if (currentPercent > percentComplete) { - printf("[%d]:%d%%\n", pThreadInfo->threadID, - currentPercent); - percentComplete = currentPercent; - } - - int64_t currentPrintTime = taosGetTimestampMs(); - if (currentPrintTime - lastPrintTime > 30*1000) { - printf("thread[%d] has currently inserted rows: %"PRId64 ", affected rows: %"PRId64 "\n", - pThreadInfo->threadID, - pThreadInfo->totalInsertRows, - pThreadInfo->totalAffectedRows); - lastPrintTime = currentPrintTime; - } - - for (int index = 0; index < g_args.reqPerReq; index++) { - free(pThreadInfo->lines[index]); - } - if (j == insertRows) { - break; - } - } - } - tmfree(pThreadInfo->lines); - for (int index = 0; index < pThreadInfo->ntables; index++) { - free(*((char**)smlHeadList + index * sizeof(char *))); - } - tmfree(smlHeadList); - return NULL; -} - -// sync insertion progressive data -static void* syncWriteProgressive(threadInfo *pThreadInfo) { - debugPrint("%s() LN%d: ### progressive write\n", __func__, __LINE__); - - SSuperTable* stbInfo = pThreadInfo->stbInfo; - uint64_t maxSqlLen = stbInfo?stbInfo->maxSqlLen:g_args.max_sql_len; - int64_t timeStampStep = - stbInfo?stbInfo->timeStampStep:g_args.timestamp_step; - int64_t insertRows = - (stbInfo)?stbInfo->insertRows:g_args.insertRows; - verbosePrint("%s() LN%d insertRows=%"PRId64"\n", - __func__, __LINE__, insertRows); - - pThreadInfo->buffer = calloc(maxSqlLen, 1); - if (NULL == pThreadInfo->buffer) { - errorPrint2("Failed to alloc %"PRIu64" bytes, reason:%s\n", - maxSqlLen, - strerror(errno)); - return NULL; - } - - uint64_t lastPrintTime = taosGetTimestampMs(); - uint64_t startTs = taosGetTimestampMs(); - uint64_t endTs; - - pThreadInfo->totalInsertRows = 0; - pThreadInfo->totalAffectedRows = 0; - - pThreadInfo->samplePos = 0; - - int percentComplete = 0; - int64_t totalRows = insertRows * pThreadInfo->ntables; - - for (uint64_t tableSeq = pThreadInfo->start_table_from; - tableSeq <= pThreadInfo->end_table_to; - tableSeq ++) { - int64_t start_time = pThreadInfo->start_time; - - for (uint64_t i = 0; i < insertRows;) { - char tableName[TSDB_TABLE_NAME_LEN]; - getTableName(tableName, pThreadInfo, tableSeq); - verbosePrint("%s() LN%d: tid=%d seq=%"PRId64" tableName=%s\n", - __func__, __LINE__, - pThreadInfo->threadID, tableSeq, tableName); - if (0 == strlen(tableName)) { - errorPrint2("[%d] %s() LN%d, getTableName return null\n", - pThreadInfo->threadID, __func__, __LINE__); - free(pThreadInfo->buffer); - return NULL; - } - - int64_t remainderBufLen = maxSqlLen - 2000; - char *pstr = pThreadInfo->buffer; - - int len = snprintf(pstr, - strlen(STR_INSERT_INTO) + 1, "%s", STR_INSERT_INTO); - - pstr += len; - remainderBufLen -= len; - - // measure prepare + insert - startTs = taosGetTimestampUs(); - - int32_t generated; - if (stbInfo) { - if (stbInfo->iface == STMT_IFACE) { - generated = prepareStbStmt( - pThreadInfo, - tableName, - tableSeq, - (g_args.reqPerReq>stbInfo->insertRows)? - stbInfo->insertRows: - g_args.reqPerReq, - insertRows, i, start_time, - &(pThreadInfo->samplePos)); - } else { - generated = generateStbProgressiveData( - stbInfo, - tableName, tableSeq, - pThreadInfo->db_name, pstr, - insertRows, i, start_time, - &(pThreadInfo->samplePos), - &remainderBufLen); - } - } else { - if (g_args.iface == STMT_IFACE) { - generated = prepareStmtWithoutStb( - pThreadInfo, - tableName, - g_args.reqPerReq, - insertRows, i, - start_time); - } else { - generated = generateProgressiveDataWithoutStb( - tableName, - /* tableSeq, */ - pThreadInfo, pstr, insertRows, - i, start_time, - /* &(pThreadInfo->samplePos), */ - &remainderBufLen); - } - } - - verbosePrint("[%d] %s() LN%d generated=%d\n", - pThreadInfo->threadID, - __func__, __LINE__, generated); - - if (generated > 0) - i += generated; - else - goto free_of_progressive; - - start_time += generated * timeStampStep; - pThreadInfo->totalInsertRows += generated; - - // only measure insert - // startTs = taosGetTimestampUs(); - - int32_t affectedRows = execInsert(pThreadInfo, generated); - - endTs = taosGetTimestampUs(); - uint64_t delay = endTs - startTs; - performancePrint("%s() LN%d, insert execution time is %10.f ms\n", - __func__, __LINE__, delay/1000.0); - verbosePrint("[%d] %s() LN%d affectedRows=%d\n", - pThreadInfo->threadID, - __func__, __LINE__, affectedRows); - - if (delay > pThreadInfo->maxDelay) pThreadInfo->maxDelay = delay; - if (delay < pThreadInfo->minDelay) pThreadInfo->minDelay = delay; - pThreadInfo->cntDelay++; - pThreadInfo->totalDelay += delay; - - if (affectedRows < 0) { - errorPrint2("%s() LN%d, affected rows: %d\n", - __func__, __LINE__, affectedRows); - goto free_of_progressive; - } - - pThreadInfo->totalAffectedRows += affectedRows; - - int currentPercent = pThreadInfo->totalAffectedRows * 100 / totalRows; - if (currentPercent > percentComplete ) { - printf("[%d]:%d%%\n", pThreadInfo->threadID, currentPercent); - percentComplete = currentPercent; - } - int64_t currentPrintTime = taosGetTimestampMs(); - if (currentPrintTime - lastPrintTime > 30*1000) { - printf("thread[%d] has currently inserted rows: %"PRId64 ", affected rows: %"PRId64 "\n", - pThreadInfo->threadID, - pThreadInfo->totalInsertRows, - pThreadInfo->totalAffectedRows); - lastPrintTime = currentPrintTime; - } - - if (i >= insertRows) - break; - } // insertRows - - if ((g_args.verbose_print) && - (tableSeq == pThreadInfo->ntables - 1) && (stbInfo) - && (0 == strncasecmp( - stbInfo->dataSource, - "sample", strlen("sample")))) { - verbosePrint("%s() LN%d samplePos=%"PRId64"\n", - __func__, __LINE__, pThreadInfo->samplePos); - } - } // tableSeq - - if (percentComplete < 100) { - printf("[%d]:%d%%\n", pThreadInfo->threadID, percentComplete); - } - -free_of_progressive: - tmfree(pThreadInfo->buffer); - printStatPerThread(pThreadInfo); - return NULL; -} - -static void* syncWrite(void *sarg) { - - threadInfo *pThreadInfo = (threadInfo *)sarg; - SSuperTable* stbInfo = pThreadInfo->stbInfo; - - setThreadName("syncWrite"); - - uint32_t interlaceRows = 0; - - if (stbInfo) { - if (stbInfo->interlaceRows < stbInfo->insertRows) - interlaceRows = stbInfo->interlaceRows; - } else { - if (g_args.interlaceRows < g_args.insertRows) - interlaceRows = g_args.interlaceRows; - } - - if (interlaceRows > 0) { - // interlace mode - if (stbInfo) { - if (STMT_IFACE == stbInfo->iface) { -#if STMT_BIND_PARAM_BATCH == 1 - return syncWriteInterlaceStmtBatch(pThreadInfo, interlaceRows); -#else - return syncWriteInterlaceStmt(pThreadInfo, interlaceRows); -#endif - } else if (SML_IFACE == stbInfo->iface) { - return syncWriteInterlaceSml(pThreadInfo, interlaceRows); - } else { - return syncWriteInterlace(pThreadInfo, interlaceRows); - } - } - } else { - // progressive mode - if (((stbInfo) && (STMT_IFACE == stbInfo->iface)) - || (STMT_IFACE == g_args.iface)) { - return syncWriteProgressiveStmt(pThreadInfo); - } else if (((stbInfo) && (SML_IFACE == stbInfo->iface)) - || (SML_IFACE == g_args.iface)) { - return syncWriteProgressiveSml(pThreadInfo); - } else { - return syncWriteProgressive(pThreadInfo); - } - } - - return NULL; -} - -static void callBack(void *param, TAOS_RES *res, int code) { - threadInfo* pThreadInfo = (threadInfo*)param; - SSuperTable* stbInfo = pThreadInfo->stbInfo; - - int insert_interval = - stbInfo?stbInfo->insertInterval:g_args.insert_interval; - if (insert_interval) { - pThreadInfo->et = taosGetTimestampMs(); - if ((pThreadInfo->et - pThreadInfo->st) < insert_interval) { - taosMsleep(insert_interval - (pThreadInfo->et - pThreadInfo->st)); // ms - } - } - - char *buffer = calloc(1, pThreadInfo->stbInfo->maxSqlLen); - char data[MAX_DATA_SIZE]; - char *pstr = buffer; - pstr += sprintf(pstr, "INSERT INTO %s.%s%"PRId64" VALUES", - pThreadInfo->db_name, pThreadInfo->tb_prefix, - pThreadInfo->start_table_from); - // if (pThreadInfo->counter >= pThreadInfo->stbInfo->insertRows) { - if (pThreadInfo->counter >= g_args.reqPerReq) { - pThreadInfo->start_table_from++; - pThreadInfo->counter = 0; - } - if (pThreadInfo->start_table_from > pThreadInfo->end_table_to) { - tsem_post(&pThreadInfo->lock_sem); - free(buffer); - taos_free_result(res); - return; - } - - for (int i = 0; i < g_args.reqPerReq; i++) { - int rand_num = taosRandom() % 100; - if (0 != pThreadInfo->stbInfo->disorderRatio - && rand_num < pThreadInfo->stbInfo->disorderRatio) { - int64_t d = pThreadInfo->lastTs - - (taosRandom() % pThreadInfo->stbInfo->disorderRange + 1); - generateStbRowData(pThreadInfo->stbInfo, data, - MAX_DATA_SIZE, - d); - } else { - generateStbRowData(pThreadInfo->stbInfo, - data, - MAX_DATA_SIZE, - pThreadInfo->lastTs += 1000); - } - pstr += sprintf(pstr, "%s", data); - pThreadInfo->counter++; - - if (pThreadInfo->counter >= pThreadInfo->stbInfo->insertRows) { - break; - } - } - - if (insert_interval) { - pThreadInfo->st = taosGetTimestampMs(); - } - taos_query_a(pThreadInfo->taos, buffer, callBack, pThreadInfo); - free(buffer); - - taos_free_result(res); -} - -static void *asyncWrite(void *sarg) { - threadInfo *pThreadInfo = (threadInfo *)sarg; - SSuperTable* stbInfo = pThreadInfo->stbInfo; - - setThreadName("asyncWrite"); - - pThreadInfo->st = 0; - pThreadInfo->et = 0; - pThreadInfo->lastTs = pThreadInfo->start_time; - - int insert_interval = - stbInfo?stbInfo->insertInterval:g_args.insert_interval; - if (insert_interval) { - pThreadInfo->st = taosGetTimestampMs(); - } - taos_query_a(pThreadInfo->taos, "show databases", callBack, pThreadInfo); - - tsem_wait(&(pThreadInfo->lock_sem)); - - return NULL; -} - -static int convertHostToServAddr(char *host, uint16_t port, struct sockaddr_in *serv_addr) -{ - uint16_t rest_port = port + TSDB_PORT_HTTP; - struct hostent *server = gethostbyname(host); - if ((server == NULL) || (server->h_addr == NULL)) { - errorPrint2("%s", "no such host"); - return -1; - } - - debugPrint("h_name: %s\nh_addr=%p\nh_addretype: %s\nh_length: %d\n", - server->h_name, - server->h_addr, - (server->h_addrtype == AF_INET)?"ipv4":"ipv6", - server->h_length); - - memset(serv_addr, 0, sizeof(struct sockaddr_in)); - serv_addr->sin_family = AF_INET; - serv_addr->sin_port = htons(rest_port); -#ifdef WINDOWS - serv_addr->sin_addr.s_addr = inet_addr(host); -#else - memcpy(&(serv_addr->sin_addr.s_addr), server->h_addr, server->h_length); -#endif - return 0; -} - -static void startMultiThreadInsertData(int threads, char* db_name, - char* precision, SSuperTable* stbInfo) { - - int32_t timePrec = TSDB_TIME_PRECISION_MILLI; - if (0 != precision[0]) { - if (0 == strncasecmp(precision, "ms", 2)) { - timePrec = TSDB_TIME_PRECISION_MILLI; - } else if (0 == strncasecmp(precision, "us", 2)) { - timePrec = TSDB_TIME_PRECISION_MICRO; - } else if (0 == strncasecmp(precision, "ns", 2)) { - timePrec = TSDB_TIME_PRECISION_NANO; - } else { - errorPrint2("Not support precision: %s\n", precision); - exit(EXIT_FAILURE); - } - } - - int64_t startTime; - if (stbInfo) { - if (0 == strncasecmp(stbInfo->startTimestamp, "now", 3)) { - startTime = taosGetTimestamp(timePrec); - } else { - if (TSDB_CODE_SUCCESS != taosParseTime( - stbInfo->startTimestamp, - &startTime, - strlen(stbInfo->startTimestamp), - timePrec, 0)) { - ERROR_EXIT("failed to parse time!\n"); - } - } - } else { - startTime = DEFAULT_START_TIME; - } - debugPrint("%s() LN%d, startTime= %"PRId64"\n", - __func__, __LINE__, startTime); - - // read sample data from file first - int ret; - if (stbInfo && stbInfo->iface != SML_IFACE) { - ret = prepareSampleForStb(stbInfo); - } else { - ret = prepareSampleForNtb(); - } - - if (0 != ret) { - errorPrint2("%s() LN%d, prepare sample data for stable failed!\n", - __func__, __LINE__); - exit(EXIT_FAILURE); - } - - TAOS* taos0 = taos_connect( - g_Dbs.host, g_Dbs.user, - g_Dbs.password, db_name, g_Dbs.port); - if (NULL == taos0) { - errorPrint2("%s() LN%d, connect to server fail , reason: %s\n", - __func__, __LINE__, taos_errstr(NULL)); - exit(EXIT_FAILURE); - } - - int64_t ntables = 0; - uint64_t tableFrom = 0; - - if (stbInfo) { - if (stbInfo->iface != SML_IFACE) { - int64_t limit; - uint64_t offset; - - if ((NULL != g_args.sqlFile) - && (stbInfo->childTblExists == TBL_NO_EXISTS) - && ((stbInfo->childTblOffset != 0) - || (stbInfo->childTblLimit >= 0))) { - printf("WARNING: offset and limit will not be used since the child tables not exists!\n"); - } - - if (stbInfo->childTblExists == TBL_ALREADY_EXISTS) { - if ((stbInfo->childTblLimit < 0) - || ((stbInfo->childTblOffset - + stbInfo->childTblLimit) - > (stbInfo->childTblCount))) { - - if (stbInfo->childTblCount < stbInfo->childTblOffset) { - printf("WARNING: offset will not be used since the child tables count is less then offset!\n"); - - stbInfo->childTblOffset = 0; - } - stbInfo->childTblLimit = - stbInfo->childTblCount - stbInfo->childTblOffset; - } - - offset = stbInfo->childTblOffset; - limit = stbInfo->childTblLimit; - } else { - limit = stbInfo->childTblCount; - offset = 0; - } - - ntables = limit; - tableFrom = offset; - - if ((stbInfo->childTblExists != TBL_NO_EXISTS) - && ((stbInfo->childTblOffset + stbInfo->childTblLimit) - > stbInfo->childTblCount)) { - printf("WARNING: specified offset + limit > child table count!\n"); - prompt(); - } - - if ((stbInfo->childTblExists != TBL_NO_EXISTS) - && (0 == stbInfo->childTblLimit)) { - printf("WARNING: specified limit = 0, which cannot find table name to insert or query! \n"); - prompt(); - } - - stbInfo->childTblName = (char*)calloc(1, - limit * TSDB_TABLE_NAME_LEN); - if (stbInfo->childTblName == NULL) { - taos_close(taos0); - errorPrint2("%s() LN%d, alloc memory failed!\n", __func__, __LINE__); - exit(EXIT_FAILURE); - } - - int64_t childTblCount; - getChildNameOfSuperTableWithLimitAndOffset( - taos0, - db_name, stbInfo->stbName, - &stbInfo->childTblName, &childTblCount, - limit, - offset, stbInfo->escapeChar); - ntables = childTblCount; - } else { - ntables = stbInfo->childTblCount; - } - } else { - ntables = g_args.ntables; - tableFrom = 0; - } - - taos_close(taos0); - - int64_t a = ntables / threads; - if (a < 1) { - threads = ntables; - a = 1; - } - - int64_t b = 0; - if (threads != 0) { - b = ntables % threads; - } - - if (g_args.iface == REST_IFACE || ((stbInfo) && (stbInfo->iface == REST_IFACE))) { - if (convertHostToServAddr( - g_Dbs.host, g_Dbs.port, &(g_Dbs.serv_addr)) != 0) { - ERROR_EXIT("convert host to server address"); - } - } - - pthread_t *pids = calloc(1, threads * sizeof(pthread_t)); - threadInfo *infos = calloc(1, threads * sizeof(threadInfo)); - assert(pids != NULL); - assert(infos != NULL); - - char *stmtBuffer = calloc(1, BUFFER_SIZE); - assert(stmtBuffer); - -#if STMT_BIND_PARAM_BATCH == 1 - uint32_t interlaceRows = 0; - uint32_t batch; - - if (stbInfo) { - if (stbInfo->interlaceRows < stbInfo->insertRows) - interlaceRows = stbInfo->interlaceRows; - } else { - if (g_args.interlaceRows < g_args.insertRows) - interlaceRows = g_args.interlaceRows; - } - - if (interlaceRows > 0) { - batch = interlaceRows; - } else { - batch = (g_args.reqPerReq>g_args.insertRows)? - g_args.insertRows:g_args.reqPerReq; - } - -#endif - - if ((g_args.iface == STMT_IFACE) - || ((stbInfo) - && (stbInfo->iface == STMT_IFACE))) { - char *pstr = stmtBuffer; - - if ((stbInfo) - && (AUTO_CREATE_SUBTBL - == stbInfo->autoCreateTable)) { - pstr += sprintf(pstr, "INSERT INTO ? USING %s TAGS(?", - stbInfo->stbName); - for (int tag = 0; tag < (stbInfo->tagCount - 1); - tag ++ ) { - pstr += sprintf(pstr, ",?"); - } - pstr += sprintf(pstr, ") VALUES(?"); - } else { - pstr += sprintf(pstr, "INSERT INTO ? VALUES(?"); - } - - int columnCount = (stbInfo)? - stbInfo->columnCount: - g_args.columnCount; - - for (int col = 0; col < columnCount; col ++) { - pstr += sprintf(pstr, ",?"); - } - pstr += sprintf(pstr, ")"); - - debugPrint("%s() LN%d, stmtBuffer: %s", __func__, __LINE__, stmtBuffer); -#if STMT_BIND_PARAM_BATCH == 1 - parseSamplefileToStmtBatch(stbInfo); -#endif - } - - for (int i = 0; i < threads; i++) { - threadInfo *pThreadInfo = infos + i; - pThreadInfo->threadID = i; - - tstrncpy(pThreadInfo->db_name, db_name, TSDB_DB_NAME_LEN); - pThreadInfo->time_precision = timePrec; - pThreadInfo->stbInfo = stbInfo; - - pThreadInfo->start_time = startTime; - pThreadInfo->minDelay = UINT64_MAX; - - if ((NULL == stbInfo) || - (stbInfo->iface != REST_IFACE)) { - //t_info->taos = taos; - pThreadInfo->taos = taos_connect( - g_Dbs.host, g_Dbs.user, - g_Dbs.password, db_name, g_Dbs.port); - if (NULL == pThreadInfo->taos) { - free(infos); - errorPrint2( - "%s() LN%d, connect to server fail from insert sub thread, reason: %s\n", - __func__, __LINE__, - taos_errstr(NULL)); - exit(EXIT_FAILURE); - } - - if ((g_args.iface == STMT_IFACE) - || ((stbInfo) - && (stbInfo->iface == STMT_IFACE))) { - - pThreadInfo->stmt = taos_stmt_init(pThreadInfo->taos); - if (NULL == pThreadInfo->stmt) { - free(pids); - free(infos); - errorPrint2( - "%s() LN%d, failed init stmt, reason: %s\n", - __func__, __LINE__, - taos_errstr(NULL)); - exit(EXIT_FAILURE); - } - - if (0 != taos_stmt_prepare(pThreadInfo->stmt, stmtBuffer, 0)) { - free(pids); - free(infos); - free(stmtBuffer); - errorPrint2("failed to execute taos_stmt_prepare. return 0x%x. reason: %s\n", - ret, taos_stmt_errstr(pThreadInfo->stmt)); - exit(EXIT_FAILURE); - } - pThreadInfo->bind_ts = malloc(sizeof(int64_t)); - - if (stbInfo) { -#if STMT_BIND_PARAM_BATCH == 1 - parseStbSampleToStmtBatchForThread( - pThreadInfo, stbInfo, timePrec, batch); -#else - parseStbSampleToStmt(pThreadInfo, stbInfo, timePrec); -#endif - } else { -#if STMT_BIND_PARAM_BATCH == 1 - parseNtbSampleToStmtBatchForThread( - pThreadInfo, timePrec, batch); -#else - parseNtbSampleToStmt(pThreadInfo, timePrec); -#endif - } - } - } else { - pThreadInfo->taos = NULL; - } - - /* if ((NULL == stbInfo) - || (0 == stbInfo->multiThreadWriteOneTbl)) { - */ - pThreadInfo->start_table_from = tableFrom; - pThreadInfo->ntables = iend_table_to = i < b ? tableFrom + a : tableFrom + a - 1; - tableFrom = pThreadInfo->end_table_to + 1; - /* } else { - pThreadInfo->start_table_from = 0; - pThreadInfo->ntables = stbInfo->childTblCount; - pThreadInfo->start_time = pThreadInfo->start_time + rand_int() % 10000 - rand_tinyint(); - } - */ - if (g_args.iface == REST_IFACE || ((stbInfo) && (stbInfo->iface == REST_IFACE))) { -#ifdef WINDOWS - WSADATA wsaData; - WSAStartup(MAKEWORD(2, 2), &wsaData); - SOCKET sockfd; -#else - int sockfd; -#endif - sockfd = socket(AF_INET, SOCK_STREAM, 0); - if (sockfd < 0) { -#ifdef WINDOWS - errorPrint( "Could not create socket : %d" , WSAGetLastError()); -#endif - debugPrint("%s() LN%d, sockfd=%d\n", __func__, __LINE__, sockfd); - ERROR_EXIT("opening socket"); - } - - int retConn = connect(sockfd, (struct sockaddr *)&(g_Dbs.serv_addr), sizeof(struct sockaddr)); - debugPrint("%s() LN%d connect() return %d\n", __func__, __LINE__, retConn); - if (retConn < 0) { - ERROR_EXIT("connecting"); - } - pThreadInfo->sockfd = sockfd; - } - - tsem_init(&(pThreadInfo->lock_sem), 0, 0); - if (ASYNC_MODE == g_Dbs.asyncMode) { - pthread_create(pids + i, NULL, asyncWrite, pThreadInfo); - } else { - pthread_create(pids + i, NULL, syncWrite, pThreadInfo); - } - } - - free(stmtBuffer); - - int64_t start = taosGetTimestampUs(); - - for (int i = 0; i < threads; i++) { - pthread_join(pids[i], NULL); - } - - uint64_t totalDelay = 0; - uint64_t maxDelay = 0; - uint64_t minDelay = UINT64_MAX; - uint64_t cntDelay = 1; - double avgDelay = 0; - - for (int i = 0; i < threads; i++) { - threadInfo *pThreadInfo = infos + i; - - tsem_destroy(&(pThreadInfo->lock_sem)); - taos_close(pThreadInfo->taos); - - if (pThreadInfo->stmt) { - taos_stmt_close(pThreadInfo->stmt); - } - - tmfree((char *)pThreadInfo->bind_ts); -#if STMT_BIND_PARAM_BATCH == 1 - tmfree((char *)pThreadInfo->bind_ts_array); - tmfree(pThreadInfo->bindParams); - tmfree(pThreadInfo->is_null); - if (g_args.iface == REST_IFACE || ((stbInfo) && (stbInfo->iface == REST_IFACE))) { -#ifdef WINDOWS - closesocket(pThreadInfo->sockfd); - WSACleanup(); -#else - close(pThreadInfo->sockfd); -#endif - } -#else - if (pThreadInfo->sampleBindArray) { - for (int k = 0; k < MAX_SAMPLES; k++) { - uintptr_t *tmp = (uintptr_t *)(*(uintptr_t *)( - pThreadInfo->sampleBindArray - + sizeof(uintptr_t *) * k)); - int columnCount = (pThreadInfo->stbInfo)? - pThreadInfo->stbInfo->columnCount: - g_args.columnCount; - for (int c = 1; c < columnCount + 1; c++) { - TAOS_BIND *bind = (TAOS_BIND *)((char *)tmp + (sizeof(TAOS_BIND) * c)); - if (bind) - tmfree(bind->buffer); - } - tmfree((char *)tmp); - } - tmfree(pThreadInfo->sampleBindArray); - } -#endif - - debugPrint("%s() LN%d, [%d] totalInsert=%"PRIu64" totalAffected=%"PRIu64"\n", - __func__, __LINE__, - pThreadInfo->threadID, pThreadInfo->totalInsertRows, - pThreadInfo->totalAffectedRows); - if (stbInfo) { - stbInfo->totalAffectedRows += pThreadInfo->totalAffectedRows; - stbInfo->totalInsertRows += pThreadInfo->totalInsertRows; - } else { - g_args.totalAffectedRows += pThreadInfo->totalAffectedRows; - g_args.totalInsertRows += pThreadInfo->totalInsertRows; - } - - totalDelay += pThreadInfo->totalDelay; - cntDelay += pThreadInfo->cntDelay; - if (pThreadInfo->maxDelay > maxDelay) maxDelay = pThreadInfo->maxDelay; - if (pThreadInfo->minDelay < minDelay) minDelay = pThreadInfo->minDelay; - } - - if (cntDelay == 0) cntDelay = 1; - avgDelay = (double)totalDelay / cntDelay; - - int64_t end = taosGetTimestampUs(); - int64_t t = end - start; - if (0 == t) t = 1; - - double tInMs = (double) t / 1000000.0; - - if (stbInfo) { - fprintf(stderr, "Spent %.4f seconds to insert rows: %"PRIu64", affected rows: %"PRIu64" with %d thread(s) into %s.%s. %.2f records/second\n\n", - tInMs, stbInfo->totalInsertRows, - stbInfo->totalAffectedRows, - threads, db_name, stbInfo->stbName, - (double)(stbInfo->totalInsertRows/tInMs)); - - if (g_fpOfInsertResult) { - fprintf(g_fpOfInsertResult, - "Spent %.4f seconds to insert rows: %"PRIu64", affected rows: %"PRIu64" with %d thread(s) into %s.%s. %.2f records/second\n\n", - tInMs, stbInfo->totalInsertRows, - stbInfo->totalAffectedRows, - threads, db_name, stbInfo->stbName, - (double)(stbInfo->totalInsertRows/tInMs)); - } - } else { - fprintf(stderr, "Spent %.4f seconds to insert rows: %"PRIu64", affected rows: %"PRIu64" with %d thread(s) into %s %.2f records/second\n\n", - tInMs, g_args.totalInsertRows, - g_args.totalAffectedRows, - threads, db_name, - (double)(g_args.totalInsertRows/tInMs)); - if (g_fpOfInsertResult) { - fprintf(g_fpOfInsertResult, - "Spent %.4f seconds to insert rows: %"PRIu64", affected rows: %"PRIu64" with %d thread(s) into %s %.2f records/second\n\n", - tInMs, g_args.totalInsertRows, - g_args.totalAffectedRows, - threads, db_name, - (double)(g_args.totalInsertRows/tInMs)); - } - } - - if (minDelay != UINT64_MAX) { - fprintf(stderr, "insert delay, avg: %10.2fms, max: %10.2fms, min: %10.2fms\n\n", - (double)avgDelay/1000.0, - (double)maxDelay/1000.0, - (double)minDelay/1000.0); - - if (g_fpOfInsertResult) { - fprintf(g_fpOfInsertResult, "insert delay, avg:%10.2fms, max: %10.2fms, min: %10.2fms\n\n", - (double)avgDelay/1000.0, - (double)maxDelay/1000.0, - (double)minDelay/1000.0); - } - } - - //taos_close(taos); - - free(pids); - free(infos); -} - -static void *queryNtableAggrFunc(void *sarg) { - threadInfo *pThreadInfo = (threadInfo *)sarg; - TAOS *taos = pThreadInfo->taos; - setThreadName("queryNtableAggrFunc"); - char *command = calloc(1, BUFFER_SIZE); - assert(command); - - uint64_t startTime = pThreadInfo->start_time; - char *tb_prefix = pThreadInfo->tb_prefix; - FILE *fp = fopen(pThreadInfo->filePath, "a"); - if (NULL == fp) { - errorPrint2("fopen %s fail, reason:%s.\n", pThreadInfo->filePath, strerror(errno)); - free(command); - return NULL; - } - - int64_t insertRows; - /* if (pThreadInfo->stbInfo) { - insertRows = pThreadInfo->stbInfo->insertRows; // nrecords_per_table; - } else { - */ - insertRows = g_args.insertRows; - // } - - int64_t ntables = pThreadInfo->ntables; // pThreadInfo->end_table_to - pThreadInfo->start_table_from + 1; - int64_t totalData = insertRows * ntables; - bool aggr_func = g_Dbs.aggr_func; - - char **aggreFunc; - int n; - - if (g_args.demo_mode) { - aggreFunc = g_aggreFuncDemo; - n = aggr_func?(sizeof(g_aggreFuncDemo) / sizeof(g_aggreFuncDemo[0])) : 2; - } else { - aggreFunc = g_aggreFunc; - n = aggr_func?(sizeof(g_aggreFunc) / sizeof(g_aggreFunc[0])) : 2; - } - - if (!aggr_func) { - printf("\nThe first field is either Binary or Bool. Aggregation functions are not supported.\n"); - } - printf("%"PRId64" records:\n", totalData); - fprintf(fp, "| QFunctions | QRecords | QSpeed(R/s) | QLatency(ms) |\n"); - - for (int j = 0; j < n; j++) { - double totalT = 0; - uint64_t count = 0; - for (int64_t i = 0; i < ntables; i++) { - sprintf(command, "SELECT %s FROM %s%"PRId64" WHERE ts>= %" PRIu64, - aggreFunc[j], tb_prefix, i, startTime); - - double t = taosGetTimestampUs(); - debugPrint("%s() LN%d, sql command: %s\n", - __func__, __LINE__, command); - TAOS_RES *pSql = taos_query(taos, command); - int32_t code = taos_errno(pSql); - - if (code != 0) { - errorPrint2("Failed to query:%s\n", taos_errstr(pSql)); - taos_free_result(pSql); - taos_close(taos); - fclose(fp); - free(command); - return NULL; - } - - while(taos_fetch_row(pSql) != NULL) { - count++; - } - - t = taosGetTimestampUs() - t; - totalT += t; - - taos_free_result(pSql); - } - - fprintf(fp, "|%10s | %"PRId64" | %12.2f | %10.2f |\n", - aggreFunc[j][0] == '*' ? " * " : aggreFunc[j], totalData, - (double)(ntables * insertRows) / totalT, totalT / 1000000); - printf("select %10s took %.6f second(s)\n", aggreFunc[j], totalT / 1000000); - } - fprintf(fp, "\n"); - fclose(fp); - free(command); - return NULL; -} - -static void *queryStableAggrFunc(void *sarg) { - threadInfo *pThreadInfo = (threadInfo *)sarg; - TAOS *taos = pThreadInfo->taos; - setThreadName("queryStableAggrFunc"); - char *command = calloc(1, BUFFER_SIZE); - assert(command); - - FILE *fp = fopen(pThreadInfo->filePath, "a"); - if (NULL == fp) { - printf("fopen %s fail, reason:%s.\n", pThreadInfo->filePath, strerror(errno)); - free(command); - return NULL; - } - - int64_t insertRows = pThreadInfo->stbInfo->insertRows; - int64_t ntables = pThreadInfo->ntables; // pThreadInfo->end_table_to - pThreadInfo->start_table_from + 1; - int64_t totalData = insertRows * ntables; - bool aggr_func = g_Dbs.aggr_func; - - char **aggreFunc; - int n; - - if (g_args.demo_mode) { - aggreFunc = g_aggreFuncDemo; - n = aggr_func?(sizeof(g_aggreFuncDemo) / sizeof(g_aggreFuncDemo[0])) : 2; - } else { - aggreFunc = g_aggreFunc; - n = aggr_func?(sizeof(g_aggreFunc) / sizeof(g_aggreFunc[0])) : 2; - } - - if (!aggr_func) { - printf("\nThe first field is either Binary or Bool. Aggregation functions are not supported.\n"); - } - - printf("%"PRId64" records:\n", totalData); - fprintf(fp, "Querying On %"PRId64" records:\n", totalData); - - for (int j = 0; j < n; j++) { - char condition[COND_BUF_LEN] = "\0"; - char tempS[64] = "\0"; - - int64_t m = 10 < ntables ? 10 : ntables; - - for (int64_t i = 1; i <= m; i++) { - if (i == 1) { - if (g_args.demo_mode) { - sprintf(tempS, "groupid = %"PRId64"", i); - } else { - sprintf(tempS, "t0 = %"PRId64"", i); - } - } else { - if (g_args.demo_mode) { - sprintf(tempS, " or groupid = %"PRId64" ", i); - } else { - sprintf(tempS, " or t0 = %"PRId64" ", i); - } - } - strncat(condition, tempS, COND_BUF_LEN - 1); - - sprintf(command, "SELECT %s FROM meters WHERE %s", aggreFunc[j], condition); - - printf("Where condition: %s\n", condition); - - debugPrint("%s() LN%d, sql command: %s\n", - __func__, __LINE__, command); - fprintf(fp, "%s\n", command); - - double t = taosGetTimestampUs(); - - TAOS_RES *pSql = taos_query(taos, command); - int32_t code = taos_errno(pSql); - - if (code != 0) { - errorPrint2("Failed to query:%s\n", taos_errstr(pSql)); - taos_free_result(pSql); - taos_close(taos); - fclose(fp); - free(command); - return NULL; - } - int count = 0; - while(taos_fetch_row(pSql) != NULL) { - count++; - } - t = taosGetTimestampUs() - t; - - fprintf(fp, "| Speed: %12.2f(per s) | Latency: %.4f(ms) |\n", - ntables * insertRows / (t / 1000), t); - printf("select %10s took %.6f second(s)\n\n", aggreFunc[j], t / 1000000); - - taos_free_result(pSql); - } - fprintf(fp, "\n"); - } - fclose(fp); - free(command); - - return NULL; -} - -static void prompt() -{ - if (!g_args.answer_yes) { - printf(" Press enter key to continue or Ctrl-C to stop\n\n"); - (void)getchar(); - } -} - -static int insertTestProcess() { - - setupForAnsiEscape(); - int ret = printfInsertMeta(); - resetAfterAnsiEscape(); - - if (ret == -1) - exit(EXIT_FAILURE); - - debugPrint("%d result file: %s\n", __LINE__, g_Dbs.resultFile); - g_fpOfInsertResult = fopen(g_Dbs.resultFile, "a"); - if (NULL == g_fpOfInsertResult) { - errorPrint("Failed to open %s for save result\n", g_Dbs.resultFile); - return -1; - } - - if (g_fpOfInsertResult) - printfInsertMetaToFile(g_fpOfInsertResult); - - prompt(); - - init_rand_data(); - - // create database and super tables - char *cmdBuffer = calloc(1, BUFFER_SIZE); - assert(cmdBuffer); - - if(createDatabasesAndStables(cmdBuffer) != 0) { - if (g_fpOfInsertResult) - fclose(g_fpOfInsertResult); - free(cmdBuffer); - return -1; - } - free(cmdBuffer); - - // pretreatment - if (prepareSampleData() != 0) { - if (g_fpOfInsertResult) - fclose(g_fpOfInsertResult); - return -1; - } - - double start; - double end; - - if (g_args.iface != SML_IFACE) { - if (g_totalChildTables > 0) { - fprintf(stderr, - "creating %"PRId64" table(s) with %d thread(s)\n\n", - g_totalChildTables, g_Dbs.threadCountForCreateTbl); - if (g_fpOfInsertResult) { - fprintf(g_fpOfInsertResult, - "creating %"PRId64" table(s) with %d thread(s)\n\n", - g_totalChildTables, g_Dbs.threadCountForCreateTbl); - } - - // create child tables - start = taosGetTimestampMs(); - createChildTables(); - end = taosGetTimestampMs(); - - fprintf(stderr, - "\nSpent %.4f seconds to create %"PRId64" table(s) with %d thread(s), actual %"PRId64" table(s) created\n\n", - (end - start)/1000.0, g_totalChildTables, - g_Dbs.threadCountForCreateTbl, g_actualChildTables); - if (g_fpOfInsertResult) { - fprintf(g_fpOfInsertResult, - "\nSpent %.4f seconds to create %"PRId64" table(s) with %d thread(s), actual %"PRId64" table(s) created\n\n", - (end - start)/1000.0, g_totalChildTables, - g_Dbs.threadCountForCreateTbl, g_actualChildTables); - } - } - } - // create sub threads for inserting data - //start = taosGetTimestampMs(); - for (int i = 0; i < g_Dbs.dbCount; i++) { - if (g_Dbs.use_metric) { - if (g_Dbs.db[i].superTblCount > 0) { - for (uint64_t j = 0; j < g_Dbs.db[i].superTblCount; j++) { - - SSuperTable* stbInfo = &g_Dbs.db[i].superTbls[j]; - - if (stbInfo && (stbInfo->insertRows > 0)) { - startMultiThreadInsertData( - g_Dbs.threadCount, - g_Dbs.db[i].dbName, - g_Dbs.db[i].dbCfg.precision, - stbInfo); - } - } - } - } else { - if (SML_IFACE == g_args.iface) { - errorPrint2("%s\n", "Schemaless insertion must include stable"); - exit(EXIT_FAILURE); - } else { - startMultiThreadInsertData( - g_Dbs.threadCount, - g_Dbs.db[i].dbName, - g_Dbs.db[i].dbCfg.precision, - NULL); - } - } - } - //end = taosGetTimestampMs(); - - //int64_t totalInsertRows = 0; - //int64_t totalAffectedRows = 0; - //for (int i = 0; i < g_Dbs.dbCount; i++) { - // for (int j = 0; j < g_Dbs.db[i].superTblCount; j++) { - // totalInsertRows+= g_Dbs.db[i].superTbls[j].totalInsertRows; - // totalAffectedRows += g_Dbs.db[i].superTbls[j].totalAffectedRows; - //} - //printf("Spent %.4f seconds to insert rows: %"PRId64", affected rows: %"PRId64" with %d thread(s)\n\n", end - start, totalInsertRows, totalAffectedRows, g_Dbs.threadCount); - postFreeResource(); - - return 0; -} - -static void *specifiedTableQuery(void *sarg) { - threadInfo *pThreadInfo = (threadInfo *)sarg; - - setThreadName("specTableQuery"); - - if (pThreadInfo->taos == NULL) { - TAOS * taos = NULL; - taos = taos_connect(g_queryInfo.host, - g_queryInfo.user, - g_queryInfo.password, - NULL, - g_queryInfo.port); - if (taos == NULL) { - errorPrint2("[%d] Failed to connect to TDengine, reason:%s\n", - pThreadInfo->threadID, taos_errstr(NULL)); - return NULL; - } else { - pThreadInfo->taos = taos; - } - } - - char sqlStr[TSDB_DB_NAME_LEN + 5]; - sprintf(sqlStr, "use %s", g_queryInfo.dbName); - if (0 != queryDbExec(pThreadInfo->taos, sqlStr, NO_INSERT_TYPE, false)) { - taos_close(pThreadInfo->taos); - errorPrint("use database %s failed!\n\n", - g_queryInfo.dbName); - return NULL; - } - - uint64_t st = 0; - uint64_t et = 0; - - uint64_t queryTimes = g_queryInfo.specifiedQueryInfo.queryTimes; - - uint64_t totalQueried = 0; - uint64_t lastPrintTime = taosGetTimestampMs(); - uint64_t startTs = taosGetTimestampMs(); - - if (g_queryInfo.specifiedQueryInfo.result[pThreadInfo->querySeq][0] != '\0') { - sprintf(pThreadInfo->filePath, "%s-%d", - g_queryInfo.specifiedQueryInfo.result[pThreadInfo->querySeq], - pThreadInfo->threadID); - } - - while(queryTimes --) { - if (g_queryInfo.specifiedQueryInfo.queryInterval && (et - st) < - (int64_t)g_queryInfo.specifiedQueryInfo.queryInterval) { - taosMsleep(g_queryInfo.specifiedQueryInfo.queryInterval - (et - st)); // ms - } - - st = taosGetTimestampMs(); - - selectAndGetResult(pThreadInfo, - g_queryInfo.specifiedQueryInfo.sql[pThreadInfo->querySeq]); - - et = taosGetTimestampMs(); - printf("=thread[%"PRId64"] use %s complete one sql, Spent %10.3f s\n", - taosGetSelfPthreadId(), g_queryInfo.queryMode, (et - st)/1000.0); - - totalQueried ++; - g_queryInfo.specifiedQueryInfo.totalQueried ++; - - uint64_t currentPrintTime = taosGetTimestampMs(); - uint64_t endTs = taosGetTimestampMs(); - if (currentPrintTime - lastPrintTime > 30*1000) { - debugPrint("%s() LN%d, endTs=%"PRIu64" ms, startTs=%"PRIu64" ms\n", - __func__, __LINE__, endTs, startTs); - printf("thread[%d] has currently completed queries: %"PRIu64", QPS: %10.6f\n", - pThreadInfo->threadID, - totalQueried, - (double)(totalQueried/((endTs-startTs)/1000.0))); - lastPrintTime = currentPrintTime; - } - } - return NULL; -} - -static void replaceChildTblName(char* inSql, char* outSql, int tblIndex) { - char sourceString[32] = "xxxx"; - char subTblName[TSDB_TABLE_NAME_LEN]; - sprintf(subTblName, "%s.%s", - g_queryInfo.dbName, - g_queryInfo.superQueryInfo.childTblName + tblIndex*TSDB_TABLE_NAME_LEN); - - //printf("inSql: %s\n", inSql); - - char* pos = strstr(inSql, sourceString); - if (0 == pos) { - return; - } - - tstrncpy(outSql, inSql, pos - inSql + 1); - //printf("1: %s\n", outSql); - strncat(outSql, subTblName, BUFFER_SIZE - 1); - //printf("2: %s\n", outSql); - strncat(outSql, pos+strlen(sourceString), BUFFER_SIZE - 1); - //printf("3: %s\n", outSql); -} - -static void *superTableQuery(void *sarg) { - char *sqlstr = calloc(1, BUFFER_SIZE); - assert(sqlstr); - - threadInfo *pThreadInfo = (threadInfo *)sarg; - - setThreadName("superTableQuery"); - - if (pThreadInfo->taos == NULL) { - TAOS * taos = NULL; - taos = taos_connect(g_queryInfo.host, - g_queryInfo.user, - g_queryInfo.password, - NULL, - g_queryInfo.port); - if (taos == NULL) { - errorPrint("[%d] Failed to connect to TDengine, reason:%s\n", - pThreadInfo->threadID, taos_errstr(NULL)); - free(sqlstr); - return NULL; - } else { - pThreadInfo->taos = taos; - } - } - - uint64_t st = 0; - uint64_t et = (int64_t)g_queryInfo.superQueryInfo.queryInterval; - - uint64_t queryTimes = g_queryInfo.superQueryInfo.queryTimes; - uint64_t totalQueried = 0; - uint64_t startTs = taosGetTimestampMs(); - - uint64_t lastPrintTime = taosGetTimestampMs(); - while(queryTimes --) { - if (g_queryInfo.superQueryInfo.queryInterval - && (et - st) < (int64_t)g_queryInfo.superQueryInfo.queryInterval) { - taosMsleep(g_queryInfo.superQueryInfo.queryInterval - (et - st)); // ms - //printf("========sleep duration:%"PRId64 "========inserted rows:%d, table range:%d - %d\n", (1000 - (et - st)), i, pThreadInfo->start_table_from, pThreadInfo->end_table_to); - } - - st = taosGetTimestampMs(); - for (int i = pThreadInfo->start_table_from; i <= pThreadInfo->end_table_to; i++) { - for (int j = 0; j < g_queryInfo.superQueryInfo.sqlCount; j++) { - memset(sqlstr, 0, BUFFER_SIZE); - replaceChildTblName(g_queryInfo.superQueryInfo.sql[j], sqlstr, i); - if (g_queryInfo.superQueryInfo.result[j][0] != '\0') { - sprintf(pThreadInfo->filePath, "%s-%d", - g_queryInfo.superQueryInfo.result[j], - pThreadInfo->threadID); - } - selectAndGetResult(pThreadInfo, sqlstr); - - totalQueried++; - g_queryInfo.superQueryInfo.totalQueried ++; - - int64_t currentPrintTime = taosGetTimestampMs(); - int64_t endTs = taosGetTimestampMs(); - if (currentPrintTime - lastPrintTime > 30*1000) { - printf("thread[%d] has currently completed queries: %"PRIu64", QPS: %10.3f\n", - pThreadInfo->threadID, - totalQueried, - (double)(totalQueried/((endTs-startTs)/1000.0))); - lastPrintTime = currentPrintTime; - } - } - } - et = taosGetTimestampMs(); - printf("####thread[%"PRId64"] complete all sqls to allocate all sub-tables[%"PRIu64" - %"PRIu64"] once queries duration:%.4fs\n\n", - taosGetSelfPthreadId(), - pThreadInfo->start_table_from, - pThreadInfo->end_table_to, - (double)(et - st)/1000.0); - } - - free(sqlstr); - return NULL; -} - -static int queryTestProcess() { - - setupForAnsiEscape(); - printfQueryMeta(); - resetAfterAnsiEscape(); - - TAOS * taos = NULL; - taos = taos_connect(g_queryInfo.host, - g_queryInfo.user, - g_queryInfo.password, - NULL, - g_queryInfo.port); - if (taos == NULL) { - errorPrint("Failed to connect to TDengine, reason:%s\n", - taos_errstr(NULL)); - exit(EXIT_FAILURE); - } - - if (0 != g_queryInfo.superQueryInfo.sqlCount) { - getAllChildNameOfSuperTable(taos, - g_queryInfo.dbName, - g_queryInfo.superQueryInfo.stbName, - &g_queryInfo.superQueryInfo.childTblName, - &g_queryInfo.superQueryInfo.childTblCount); - } - - prompt(); - - if (g_args.debug_print || g_args.verbose_print) { - printfQuerySystemInfo(taos); - } - - if (0 == strncasecmp(g_queryInfo.queryMode, "rest", strlen("rest"))) { - if (convertHostToServAddr( - g_queryInfo.host, g_queryInfo.port, &g_queryInfo.serv_addr) != 0) - ERROR_EXIT("convert host to server address"); - } - - pthread_t *pids = NULL; - threadInfo *infos = NULL; - //==== create sub threads for query from specify table - int nConcurrent = g_queryInfo.specifiedQueryInfo.concurrent; - uint64_t nSqlCount = g_queryInfo.specifiedQueryInfo.sqlCount; - - uint64_t startTs = taosGetTimestampMs(); - - if ((nSqlCount > 0) && (nConcurrent > 0)) { - - pids = calloc(1, nConcurrent * nSqlCount * sizeof(pthread_t)); - infos = calloc(1, nConcurrent * nSqlCount * sizeof(threadInfo)); - - if ((NULL == pids) || (NULL == infos)) { - taos_close(taos); - ERROR_EXIT("memory allocation failed for create threads\n"); - } - - for (uint64_t i = 0; i < nSqlCount; i++) { - for (int j = 0; j < nConcurrent; j++) { - uint64_t seq = i * nConcurrent + j; - threadInfo *pThreadInfo = infos + seq; - pThreadInfo->threadID = seq; - pThreadInfo->querySeq = i; - - if (0 == strncasecmp(g_queryInfo.queryMode, "taosc", 5)) { - - char sqlStr[TSDB_DB_NAME_LEN + 5]; - sprintf(sqlStr, "USE %s", g_queryInfo.dbName); - if (0 != queryDbExec(taos, sqlStr, NO_INSERT_TYPE, false)) { - taos_close(taos); - free(infos); - free(pids); - errorPrint2("use database %s failed!\n\n", - g_queryInfo.dbName); - return -1; - } - } - - if (0 == strncasecmp(g_queryInfo.queryMode, "rest", 4)) { -#ifdef WINDOWS - WSADATA wsaData; - WSAStartup(MAKEWORD(2, 2), &wsaData); - SOCKET sockfd; -#else - int sockfd; -#endif - sockfd = socket(AF_INET, SOCK_STREAM, 0); - if (sockfd < 0) { -#ifdef WINDOWS - errorPrint( "Could not create socket : %d" , WSAGetLastError()); -#endif - debugPrint("%s() LN%d, sockfd=%d\n", __func__, __LINE__, sockfd); - ERROR_EXIT("opening socket"); - } - - int retConn = connect(sockfd, (struct sockaddr *)&(g_queryInfo.serv_addr), - sizeof(struct sockaddr)); - debugPrint("%s() LN%d connect() return %d\n", __func__, __LINE__, retConn); - if (retConn < 0) { - ERROR_EXIT("connecting"); - } - pThreadInfo->sockfd = sockfd; - } - pThreadInfo->taos = NULL;// workaround to use separate taos connection; - - pthread_create(pids + seq, NULL, specifiedTableQuery, - pThreadInfo); - } - } - } else { - g_queryInfo.specifiedQueryInfo.concurrent = 0; - } - - taos_close(taos); - - pthread_t *pidsOfSub = NULL; - threadInfo *infosOfSub = NULL; - //==== create sub threads for query from all sub table of the super table - if ((g_queryInfo.superQueryInfo.sqlCount > 0) - && (g_queryInfo.superQueryInfo.threadCnt > 0)) { - pidsOfSub = calloc(1, g_queryInfo.superQueryInfo.threadCnt * sizeof(pthread_t)); - infosOfSub = calloc(1, g_queryInfo.superQueryInfo.threadCnt * sizeof(threadInfo)); - - if ((NULL == pidsOfSub) || (NULL == infosOfSub)) { - free(infos); - free(pids); - - ERROR_EXIT("memory allocation failed for create threads\n"); - } - - int64_t ntables = g_queryInfo.superQueryInfo.childTblCount; - int threads = g_queryInfo.superQueryInfo.threadCnt; - - int64_t a = ntables / threads; - if (a < 1) { - threads = ntables; - a = 1; - } - - int64_t b = 0; - if (threads != 0) { - b = ntables % threads; - } - - uint64_t tableFrom = 0; - for (int i = 0; i < threads; i++) { - threadInfo *pThreadInfo = infosOfSub + i; - pThreadInfo->threadID = i; - - pThreadInfo->start_table_from = tableFrom; - pThreadInfo->ntables = iend_table_to = i < b ? tableFrom + a : tableFrom + a - 1; - tableFrom = pThreadInfo->end_table_to + 1; - pThreadInfo->taos = NULL; // workaround to use separate taos connection; - if (0 == strncasecmp(g_queryInfo.queryMode, "rest", 4)) { -#ifdef WINDOWS - WSADATA wsaData; - WSAStartup(MAKEWORD(2, 2), &wsaData); - SOCKET sockfd; -#else - int sockfd; -#endif - sockfd = socket(AF_INET, SOCK_STREAM, 0); - if (sockfd < 0) { -#ifdef WINDOWS - errorPrint( "Could not create socket : %d" , WSAGetLastError()); -#endif - debugPrint("%s() LN%d, sockfd=%d\n", __func__, __LINE__, sockfd); - ERROR_EXIT("opening socket"); - } - - int retConn = connect(sockfd, (struct sockaddr *)&(g_queryInfo.serv_addr), - sizeof(struct sockaddr)); - debugPrint("%s() LN%d connect() return %d\n", __func__, __LINE__, retConn); - if (retConn < 0) { - ERROR_EXIT("connecting"); - } - pThreadInfo->sockfd = sockfd; - } - pthread_create(pidsOfSub + i, NULL, superTableQuery, pThreadInfo); - } - - g_queryInfo.superQueryInfo.threadCnt = threads; - } else { - g_queryInfo.superQueryInfo.threadCnt = 0; - } - - if ((nSqlCount > 0) && (nConcurrent > 0)) { - for (int i = 0; i < nConcurrent; i++) { - for (int j = 0; j < nSqlCount; j++) { - pthread_join(pids[i * nSqlCount + j], NULL); - if (0 == strncasecmp(g_queryInfo.queryMode, "rest", 4)) { - threadInfo *pThreadInfo = infos + i * nSqlCount + j; -#ifdef WINDOWS - closesocket(pThreadInfo->sockfd); - WSACleanup(); -#else - close(pThreadInfo->sockfd); -#endif - } - } - } - } - - tmfree((char*)pids); - tmfree((char*)infos); - - for (int i = 0; i < g_queryInfo.superQueryInfo.threadCnt; i++) { - pthread_join(pidsOfSub[i], NULL); - if (0 == strncasecmp(g_queryInfo.queryMode, "rest", 4)) { - threadInfo *pThreadInfo = infosOfSub + i; -#ifdef WINDOWS - closesocket(pThreadInfo->sockfd); - WSACleanup(); -#else - close(pThreadInfo->sockfd); -#endif - } - } - - tmfree((char*)pidsOfSub); - tmfree((char*)infosOfSub); - - // taos_close(taos);// workaround to use separate taos connection; - uint64_t endTs = taosGetTimestampMs(); - - uint64_t totalQueried = g_queryInfo.specifiedQueryInfo.totalQueried + - g_queryInfo.superQueryInfo.totalQueried; - - fprintf(stderr, "==== completed total queries: %"PRIu64", the QPS of all threads: %10.3f====\n", - totalQueried, - (double)(totalQueried/((endTs-startTs)/1000.0))); - return 0; -} - -static void stable_sub_callback( - TAOS_SUB* tsub, TAOS_RES *res, void* param, int code) { - if (res == NULL || taos_errno(res) != 0) { - errorPrint2("%s() LN%d, failed to subscribe result, code:%d, reason:%s\n", - __func__, __LINE__, code, taos_errstr(res)); - return; - } - - if (param) - fetchResult(res, (threadInfo *)param); - // tao_unsubscribe() will free result. -} - -static void specified_sub_callback( - TAOS_SUB* tsub, TAOS_RES *res, void* param, int code) { - if (res == NULL || taos_errno(res) != 0) { - errorPrint2("%s() LN%d, failed to subscribe result, code:%d, reason:%s\n", - __func__, __LINE__, code, taos_errstr(res)); - return; - } - - if (param) - fetchResult(res, (threadInfo *)param); - // tao_unsubscribe() will free result. -} - -static TAOS_SUB* subscribeImpl( - QUERY_CLASS class, - threadInfo *pThreadInfo, - char *sql, char* topic, bool restart, uint64_t interval) -{ - TAOS_SUB* tsub = NULL; - - if ((SPECIFIED_CLASS == class) - && (ASYNC_MODE == g_queryInfo.specifiedQueryInfo.asyncMode)) { - tsub = taos_subscribe( - pThreadInfo->taos, - restart, - topic, sql, specified_sub_callback, (void*)pThreadInfo, - g_queryInfo.specifiedQueryInfo.subscribeInterval); - } else if ((STABLE_CLASS == class) - && (ASYNC_MODE == g_queryInfo.superQueryInfo.asyncMode)) { - tsub = taos_subscribe( - pThreadInfo->taos, - restart, - topic, sql, stable_sub_callback, (void*)pThreadInfo, - g_queryInfo.superQueryInfo.subscribeInterval); - } else { - tsub = taos_subscribe( - pThreadInfo->taos, - restart, - topic, sql, NULL, NULL, interval); - } - - if (tsub == NULL) { - errorPrint2("failed to create subscription. topic:%s, sql:%s\n", topic, sql); - return NULL; - } - - return tsub; -} - -static void *superSubscribe(void *sarg) { - threadInfo *pThreadInfo = (threadInfo *)sarg; - char *subSqlStr = calloc(1, BUFFER_SIZE); - assert(subSqlStr); - - TAOS_SUB* tsub[MAX_QUERY_SQL_COUNT] = {0}; - uint64_t tsubSeq; - - setThreadName("superSub"); - - if (pThreadInfo->ntables > MAX_QUERY_SQL_COUNT) { - free(subSqlStr); - errorPrint("The table number(%"PRId64") of the thread is more than max query sql count: %d\n", - pThreadInfo->ntables, MAX_QUERY_SQL_COUNT); - exit(EXIT_FAILURE); - } - - if (pThreadInfo->taos == NULL) { - pThreadInfo->taos = taos_connect(g_queryInfo.host, - g_queryInfo.user, - g_queryInfo.password, - g_queryInfo.dbName, - g_queryInfo.port); - if (pThreadInfo->taos == NULL) { - errorPrint2("[%d] Failed to connect to TDengine, reason:%s\n", - pThreadInfo->threadID, taos_errstr(NULL)); - free(subSqlStr); - return NULL; - } - } - - char sqlStr[TSDB_DB_NAME_LEN + 5]; - sprintf(sqlStr, "USE %s", g_queryInfo.dbName); - if (0 != queryDbExec(pThreadInfo->taos, sqlStr, NO_INSERT_TYPE, false)) { - taos_close(pThreadInfo->taos); - errorPrint2("use database %s failed!\n\n", - g_queryInfo.dbName); - free(subSqlStr); - return NULL; - } - - char topic[32] = {0}; - for (uint64_t i = pThreadInfo->start_table_from; - i <= pThreadInfo->end_table_to; i++) { - tsubSeq = i - pThreadInfo->start_table_from; - verbosePrint("%s() LN%d, [%d], start=%"PRId64" end=%"PRId64" i=%"PRIu64"\n", - __func__, __LINE__, - pThreadInfo->threadID, - pThreadInfo->start_table_from, - pThreadInfo->end_table_to, i); - sprintf(topic, "taosdemo-subscribe-%"PRIu64"-%"PRIu64"", - i, pThreadInfo->querySeq); - memset(subSqlStr, 0, BUFFER_SIZE); - replaceChildTblName( - g_queryInfo.superQueryInfo.sql[pThreadInfo->querySeq], - subSqlStr, i); - if (g_queryInfo.superQueryInfo.result[pThreadInfo->querySeq][0] != 0) { - sprintf(pThreadInfo->filePath, "%s-%d", - g_queryInfo.superQueryInfo.result[pThreadInfo->querySeq], - pThreadInfo->threadID); - } - - verbosePrint("%s() LN%d, [%d] subSqlStr: %s\n", - __func__, __LINE__, pThreadInfo->threadID, subSqlStr); - tsub[tsubSeq] = subscribeImpl( - STABLE_CLASS, - pThreadInfo, subSqlStr, topic, - g_queryInfo.superQueryInfo.subscribeRestart, - g_queryInfo.superQueryInfo.subscribeInterval); - if (NULL == tsub[tsubSeq]) { - taos_close(pThreadInfo->taos); - free(subSqlStr); - return NULL; - } - } - - // start loop to consume result - int consumed[MAX_QUERY_SQL_COUNT]; - for (int i = 0; i < MAX_QUERY_SQL_COUNT; i++) { - consumed[i] = 0; - } - TAOS_RES* res = NULL; - - uint64_t st = 0, et = 0; - - while ((g_queryInfo.superQueryInfo.endAfterConsume == -1) - || (g_queryInfo.superQueryInfo.endAfterConsume > - consumed[pThreadInfo->end_table_to - - pThreadInfo->start_table_from])) { - - verbosePrint("super endAfterConsume: %d, consumed: %d\n", - g_queryInfo.superQueryInfo.endAfterConsume, - consumed[pThreadInfo->end_table_to - - pThreadInfo->start_table_from]); - for (uint64_t i = pThreadInfo->start_table_from; - i <= pThreadInfo->end_table_to; i++) { - tsubSeq = i - pThreadInfo->start_table_from; - if (ASYNC_MODE == g_queryInfo.superQueryInfo.asyncMode) { - continue; - } - - st = taosGetTimestampMs(); - performancePrint("st: %"PRIu64" et: %"PRIu64" st-et: %"PRIu64"\n", st, et, (st - et)); - res = taos_consume(tsub[tsubSeq]); - et = taosGetTimestampMs(); - performancePrint("st: %"PRIu64" et: %"PRIu64" delta: %"PRIu64"\n", st, et, (et - st)); - - if (res) { - if (g_queryInfo.superQueryInfo.result[pThreadInfo->querySeq][0] != 0) { - sprintf(pThreadInfo->filePath, "%s-%d", - g_queryInfo.superQueryInfo.result[pThreadInfo->querySeq], - pThreadInfo->threadID); - fetchResult(res, pThreadInfo); - } - consumed[tsubSeq] ++; - - if ((g_queryInfo.superQueryInfo.resubAfterConsume != -1) - && (consumed[tsubSeq] >= - g_queryInfo.superQueryInfo.resubAfterConsume)) { - verbosePrint("%s() LN%d, keepProgress:%d, resub super table query: %"PRIu64"\n", - __func__, __LINE__, - g_queryInfo.superQueryInfo.subscribeKeepProgress, - pThreadInfo->querySeq); - taos_unsubscribe(tsub[tsubSeq], - g_queryInfo.superQueryInfo.subscribeKeepProgress); - consumed[tsubSeq]= 0; - tsub[tsubSeq] = subscribeImpl( - STABLE_CLASS, - pThreadInfo, subSqlStr, topic, - g_queryInfo.superQueryInfo.subscribeRestart, - g_queryInfo.superQueryInfo.subscribeInterval - ); - if (NULL == tsub[tsubSeq]) { - taos_close(pThreadInfo->taos); - free(subSqlStr); - return NULL; - } - } - } - } - } - verbosePrint("%s() LN%d, super endAfterConsume: %d, consumed: %d\n", - __func__, __LINE__, - g_queryInfo.superQueryInfo.endAfterConsume, - consumed[pThreadInfo->end_table_to - pThreadInfo->start_table_from]); - taos_free_result(res); - - for (uint64_t i = pThreadInfo->start_table_from; - i <= pThreadInfo->end_table_to; i++) { - tsubSeq = i - pThreadInfo->start_table_from; - taos_unsubscribe(tsub[tsubSeq], 0); - } - - taos_close(pThreadInfo->taos); - free(subSqlStr); - return NULL; -} - -static void *specifiedSubscribe(void *sarg) { - threadInfo *pThreadInfo = (threadInfo *)sarg; - // TAOS_SUB* tsub = NULL; - - setThreadName("specSub"); - - if (pThreadInfo->taos == NULL) { - pThreadInfo->taos = taos_connect(g_queryInfo.host, - g_queryInfo.user, - g_queryInfo.password, - g_queryInfo.dbName, - g_queryInfo.port); - if (pThreadInfo->taos == NULL) { - errorPrint2("[%d] Failed to connect to TDengine, reason:%s\n", - pThreadInfo->threadID, taos_errstr(NULL)); - return NULL; - } - } - - char sqlStr[TSDB_DB_NAME_LEN + 5]; - sprintf(sqlStr, "USE %s", g_queryInfo.dbName); - if (0 != queryDbExec(pThreadInfo->taos, sqlStr, NO_INSERT_TYPE, false)) { - taos_close(pThreadInfo->taos); - return NULL; - } - - sprintf(g_queryInfo.specifiedQueryInfo.topic[pThreadInfo->threadID], - "taosdemo-subscribe-%"PRIu64"-%d", - pThreadInfo->querySeq, - pThreadInfo->threadID); - if (g_queryInfo.specifiedQueryInfo.result[pThreadInfo->querySeq][0] != '\0') { - sprintf(pThreadInfo->filePath, "%s-%d", - g_queryInfo.specifiedQueryInfo.result[pThreadInfo->querySeq], - pThreadInfo->threadID); - } - g_queryInfo.specifiedQueryInfo.tsub[pThreadInfo->threadID] = subscribeImpl( - SPECIFIED_CLASS, pThreadInfo, - g_queryInfo.specifiedQueryInfo.sql[pThreadInfo->querySeq], - g_queryInfo.specifiedQueryInfo.topic[pThreadInfo->threadID], - g_queryInfo.specifiedQueryInfo.subscribeRestart, - g_queryInfo.specifiedQueryInfo.subscribeInterval); - if (NULL == g_queryInfo.specifiedQueryInfo.tsub[pThreadInfo->threadID]) { - taos_close(pThreadInfo->taos); - return NULL; - } - - // start loop to consume result - - g_queryInfo.specifiedQueryInfo.consumed[pThreadInfo->threadID] = 0; - while((g_queryInfo.specifiedQueryInfo.endAfterConsume[pThreadInfo->querySeq] == -1) - || (g_queryInfo.specifiedQueryInfo.consumed[pThreadInfo->threadID] < - g_queryInfo.specifiedQueryInfo.endAfterConsume[pThreadInfo->querySeq])) { - - printf("consumed[%d]: %d, endAfterConsum[%"PRId64"]: %d\n", - pThreadInfo->threadID, - g_queryInfo.specifiedQueryInfo.consumed[pThreadInfo->threadID], - pThreadInfo->querySeq, - g_queryInfo.specifiedQueryInfo.endAfterConsume[pThreadInfo->querySeq]); - if (ASYNC_MODE == g_queryInfo.specifiedQueryInfo.asyncMode) { - continue; - } - - g_queryInfo.specifiedQueryInfo.res[pThreadInfo->threadID] = taos_consume( - g_queryInfo.specifiedQueryInfo.tsub[pThreadInfo->threadID]); - if (g_queryInfo.specifiedQueryInfo.res[pThreadInfo->threadID]) { - if (g_queryInfo.specifiedQueryInfo.result[pThreadInfo->querySeq][0] - != 0) { - sprintf(pThreadInfo->filePath, "%s-%d", - g_queryInfo.specifiedQueryInfo.result[pThreadInfo->querySeq], - pThreadInfo->threadID); - } - fetchResult( - g_queryInfo.specifiedQueryInfo.res[pThreadInfo->threadID], - pThreadInfo); - - g_queryInfo.specifiedQueryInfo.consumed[pThreadInfo->threadID] ++; - if ((g_queryInfo.specifiedQueryInfo.resubAfterConsume[pThreadInfo->querySeq] != -1) - && (g_queryInfo.specifiedQueryInfo.consumed[pThreadInfo->threadID] >= - g_queryInfo.specifiedQueryInfo.resubAfterConsume[pThreadInfo->querySeq])) { - printf("keepProgress:%d, resub specified query: %"PRIu64"\n", - g_queryInfo.specifiedQueryInfo.subscribeKeepProgress, - pThreadInfo->querySeq); - g_queryInfo.specifiedQueryInfo.consumed[pThreadInfo->threadID] = 0; - taos_unsubscribe(g_queryInfo.specifiedQueryInfo.tsub[pThreadInfo->threadID], - g_queryInfo.specifiedQueryInfo.subscribeKeepProgress); - g_queryInfo.specifiedQueryInfo.tsub[pThreadInfo->threadID] = - subscribeImpl( - SPECIFIED_CLASS, - pThreadInfo, - g_queryInfo.specifiedQueryInfo.sql[pThreadInfo->querySeq], - g_queryInfo.specifiedQueryInfo.topic[pThreadInfo->threadID], - g_queryInfo.specifiedQueryInfo.subscribeRestart, - g_queryInfo.specifiedQueryInfo.subscribeInterval); - if (NULL == g_queryInfo.specifiedQueryInfo.tsub[pThreadInfo->threadID]) { - taos_close(pThreadInfo->taos); - return NULL; - } - } - } - } - taos_free_result(g_queryInfo.specifiedQueryInfo.res[pThreadInfo->threadID]); - taos_close(pThreadInfo->taos); - - return NULL; -} - -static int subscribeTestProcess() { - setupForAnsiEscape(); - printfQueryMeta(); - resetAfterAnsiEscape(); - - prompt(); - - TAOS * taos = NULL; - taos = taos_connect(g_queryInfo.host, - g_queryInfo.user, - g_queryInfo.password, - g_queryInfo.dbName, - g_queryInfo.port); - if (taos == NULL) { - errorPrint2("Failed to connect to TDengine, reason:%s\n", - taos_errstr(NULL)); - exit(EXIT_FAILURE); - } - - if (0 != g_queryInfo.superQueryInfo.sqlCount) { - getAllChildNameOfSuperTable(taos, - g_queryInfo.dbName, - g_queryInfo.superQueryInfo.stbName, - &g_queryInfo.superQueryInfo.childTblName, - &g_queryInfo.superQueryInfo.childTblCount); - } - - taos_close(taos); // workaround to use separate taos connection; - - pthread_t *pids = NULL; - threadInfo *infos = NULL; - - pthread_t *pidsOfStable = NULL; - threadInfo *infosOfStable = NULL; - - //==== create threads for query for specified table - if (g_queryInfo.specifiedQueryInfo.sqlCount <= 0) { - debugPrint("%s() LN%d, specified query sqlCount %d.\n", - __func__, __LINE__, - g_queryInfo.specifiedQueryInfo.sqlCount); - } else { - if (g_queryInfo.specifiedQueryInfo.concurrent <= 0) { - errorPrint2("%s() LN%d, specified query sqlCount %d.\n", - __func__, __LINE__, - g_queryInfo.specifiedQueryInfo.sqlCount); - exit(EXIT_FAILURE); - } - - pids = calloc( - 1, - g_queryInfo.specifiedQueryInfo.sqlCount * - g_queryInfo.specifiedQueryInfo.concurrent * - sizeof(pthread_t)); - infos = calloc( - 1, - g_queryInfo.specifiedQueryInfo.sqlCount * - g_queryInfo.specifiedQueryInfo.concurrent * - sizeof(threadInfo)); - if ((NULL == pids) || (NULL == infos)) { - errorPrint2("%s() LN%d, malloc failed for create threads\n", __func__, __LINE__); - exit(EXIT_FAILURE); - } - - for (int i = 0; i < g_queryInfo.specifiedQueryInfo.sqlCount; i++) { - for (int j = 0; j < g_queryInfo.specifiedQueryInfo.concurrent; j++) { - uint64_t seq = i * g_queryInfo.specifiedQueryInfo.concurrent + j; - threadInfo *pThreadInfo = infos + seq; - pThreadInfo->threadID = seq; - pThreadInfo->querySeq = i; - pThreadInfo->taos = NULL; // workaround to use separate taos connection; - pthread_create(pids + seq, NULL, specifiedSubscribe, pThreadInfo); - } - } - } - - //==== create threads for super table query - if (g_queryInfo.superQueryInfo.sqlCount <= 0) { - debugPrint("%s() LN%d, super table query sqlCount %d.\n", - __func__, __LINE__, - g_queryInfo.superQueryInfo.sqlCount); - } else { - if ((g_queryInfo.superQueryInfo.sqlCount > 0) - && (g_queryInfo.superQueryInfo.threadCnt > 0)) { - pidsOfStable = calloc( - 1, - g_queryInfo.superQueryInfo.sqlCount * - g_queryInfo.superQueryInfo.threadCnt * - sizeof(pthread_t)); - infosOfStable = calloc( - 1, - g_queryInfo.superQueryInfo.sqlCount * - g_queryInfo.superQueryInfo.threadCnt * - sizeof(threadInfo)); - if ((NULL == pidsOfStable) || (NULL == infosOfStable)) { - errorPrint2("%s() LN%d, malloc failed for create threads\n", - __func__, __LINE__); - // taos_close(taos); - exit(EXIT_FAILURE); - } - - int64_t ntables = g_queryInfo.superQueryInfo.childTblCount; - int threads = g_queryInfo.superQueryInfo.threadCnt; - - int64_t a = ntables / threads; - if (a < 1) { - threads = ntables; - a = 1; - } - - int64_t b = 0; - if (threads != 0) { - b = ntables % threads; - } - - for (uint64_t i = 0; i < g_queryInfo.superQueryInfo.sqlCount; i++) { - uint64_t tableFrom = 0; - for (int j = 0; j < threads; j++) { - uint64_t seq = i * threads + j; - threadInfo *pThreadInfo = infosOfStable + seq; - pThreadInfo->threadID = seq; - pThreadInfo->querySeq = i; - - pThreadInfo->start_table_from = tableFrom; - pThreadInfo->ntables = jend_table_to = jend_table_to + 1; - pThreadInfo->taos = NULL; // workaround to use separate taos connection; - pthread_create(pidsOfStable + seq, - NULL, superSubscribe, pThreadInfo); - } - } - - g_queryInfo.superQueryInfo.threadCnt = threads; - - for (int i = 0; i < g_queryInfo.superQueryInfo.sqlCount; i++) { - for (int j = 0; j < threads; j++) { - uint64_t seq = i * threads + j; - pthread_join(pidsOfStable[seq], NULL); - } - } - } - } - - for (int i = 0; i < g_queryInfo.specifiedQueryInfo.sqlCount; i++) { - for (int j = 0; j < g_queryInfo.specifiedQueryInfo.concurrent; j++) { - uint64_t seq = i * g_queryInfo.specifiedQueryInfo.concurrent + j; - pthread_join(pids[seq], NULL); - } - } - - tmfree((char*)pids); - tmfree((char*)infos); - - tmfree((char*)pidsOfStable); - tmfree((char*)infosOfStable); - // taos_close(taos); - return 0; -} - -static void setParaFromArg() { - char type[20]; - char length[20]; - if (g_args.host) { - tstrncpy(g_Dbs.host, g_args.host, MAX_HOSTNAME_SIZE); - } else { - tstrncpy(g_Dbs.host, "127.0.0.1", MAX_HOSTNAME_SIZE); - } - - if (g_args.user) { - tstrncpy(g_Dbs.user, g_args.user, MAX_USERNAME_SIZE); - } - - tstrncpy(g_Dbs.password, g_args.password, SHELL_MAX_PASSWORD_LEN); - - if (g_args.port) { - g_Dbs.port = g_args.port; - } - - g_Dbs.threadCount = g_args.nthreads; - g_Dbs.threadCountForCreateTbl = g_args.nthreads; - - g_Dbs.dbCount = 1; - g_Dbs.db[0].drop = true; - - tstrncpy(g_Dbs.db[0].dbName, g_args.database, TSDB_DB_NAME_LEN); - g_Dbs.db[0].dbCfg.replica = g_args.replica; - tstrncpy(g_Dbs.db[0].dbCfg.precision, "ms", SMALL_BUFF_LEN); - - tstrncpy(g_Dbs.resultFile, g_args.output_file, MAX_FILE_NAME_LEN); - - g_Dbs.use_metric = g_args.use_metric; - g_args.prepared_rand = min(g_args.insertRows, MAX_PREPARED_RAND); - g_Dbs.aggr_func = g_args.aggr_func; - - char dataString[TSDB_MAX_BYTES_PER_ROW]; - char *data_type = g_args.data_type; - char **dataType = g_args.dataType; - - memset(dataString, 0, TSDB_MAX_BYTES_PER_ROW); - - if ((data_type[0] == TSDB_DATA_TYPE_BINARY) - || (data_type[0] == TSDB_DATA_TYPE_BOOL) - || (data_type[0] == TSDB_DATA_TYPE_NCHAR)) { - g_Dbs.aggr_func = false; - } - - if (g_args.use_metric) { - g_Dbs.db[0].superTblCount = 1; - tstrncpy(g_Dbs.db[0].superTbls[0].stbName, "meters", TSDB_TABLE_NAME_LEN); - g_Dbs.db[0].superTbls[0].childTblCount = g_args.ntables; - g_Dbs.db[0].superTbls[0].escapeChar = g_args.escapeChar; - g_Dbs.threadCount = g_args.nthreads; - g_Dbs.threadCountForCreateTbl = g_args.nthreads; - g_Dbs.asyncMode = g_args.async_mode; - - g_Dbs.db[0].superTbls[0].autoCreateTable = PRE_CREATE_SUBTBL; - g_Dbs.db[0].superTbls[0].childTblExists = TBL_NO_EXISTS; - g_Dbs.db[0].superTbls[0].disorderRange = g_args.disorderRange; - g_Dbs.db[0].superTbls[0].disorderRatio = g_args.disorderRatio; - tstrncpy(g_Dbs.db[0].superTbls[0].childTblPrefix, - g_args.tb_prefix, TBNAME_PREFIX_LEN); - tstrncpy(g_Dbs.db[0].superTbls[0].dataSource, "rand", SMALL_BUFF_LEN); - - if (g_args.iface == INTERFACE_BUT) { - g_Dbs.db[0].superTbls[0].iface = TAOSC_IFACE; - } else { - g_Dbs.db[0].superTbls[0].iface = g_args.iface; - } - tstrncpy(g_Dbs.db[0].superTbls[0].startTimestamp, - "2017-07-14 10:40:00.000", MAX_TB_NAME_SIZE); - g_Dbs.db[0].superTbls[0].timeStampStep = g_args.timestamp_step; - - g_Dbs.db[0].superTbls[0].insertRows = g_args.insertRows; - g_Dbs.db[0].superTbls[0].maxSqlLen = g_args.max_sql_len; - - g_Dbs.db[0].superTbls[0].columnCount = 0; - for (int i = 0; i < MAX_NUM_COLUMNS; i++) { - if (data_type[i] == TSDB_DATA_TYPE_NULL) { - break; - } - - g_Dbs.db[0].superTbls[0].columns[i].data_type = data_type[i]; - tstrncpy(g_Dbs.db[0].superTbls[0].columns[i].dataType, - dataType[i], min(DATATYPE_BUFF_LEN, strlen(dataType[i]) + 1)); - if (1 == regexMatch(dataType[i], "^(NCHAR|BINARY)(\\([1-9][0-9]*\\))$", REG_ICASE | - REG_EXTENDED)) { - sscanf(dataType[i], "%[^(](%[^)]", type, length); - g_Dbs.db[0].superTbls[0].columns[i].dataLen = atoi(length); - tstrncpy(g_Dbs.db[0].superTbls[0].columns[i].dataType, - type, min(DATATYPE_BUFF_LEN, strlen(type) + 1)); - } else { - g_Dbs.db[0].superTbls[0].columns[i].dataLen = g_args.binwidth; - tstrncpy(g_Dbs.db[0].superTbls[0].columns[i].dataType, - dataType[i], min(DATATYPE_BUFF_LEN, strlen(dataType[i]) + 1)); - } - g_Dbs.db[0].superTbls[0].columnCount++; - } - - if (g_Dbs.db[0].superTbls[0].columnCount > g_args.columnCount) { - g_Dbs.db[0].superTbls[0].columnCount = g_args.columnCount; - } else { - for (int i = g_Dbs.db[0].superTbls[0].columnCount; - i < g_args.columnCount; i++) { - g_Dbs.db[0].superTbls[0].columns[i].data_type = TSDB_DATA_TYPE_INT; - tstrncpy(g_Dbs.db[0].superTbls[0].columns[i].dataType, - "INT", min(DATATYPE_BUFF_LEN, strlen("INT") + 1)); - g_Dbs.db[0].superTbls[0].columns[i].dataLen = 0; - g_Dbs.db[0].superTbls[0].columnCount++; - } - } - - tstrncpy(g_Dbs.db[0].superTbls[0].tags[0].dataType, - "INT", min(DATATYPE_BUFF_LEN, strlen("INT") + 1)); - g_Dbs.db[0].superTbls[0].tags[0].data_type = TSDB_DATA_TYPE_INT; - g_Dbs.db[0].superTbls[0].tags[0].dataLen = 0; - - tstrncpy(g_Dbs.db[0].superTbls[0].tags[1].dataType, - "BINARY", min(DATATYPE_BUFF_LEN, strlen("BINARY") + 1)); - g_Dbs.db[0].superTbls[0].tags[1].data_type = TSDB_DATA_TYPE_BINARY; - g_Dbs.db[0].superTbls[0].tags[1].dataLen = g_args.binwidth; - g_Dbs.db[0].superTbls[0].tagCount = 2; - } else { - g_Dbs.threadCountForCreateTbl = g_args.nthreads; - g_Dbs.db[0].superTbls[0].tagCount = 0; - } -} - -/* Function to do regular expression check */ -static int regexMatch(const char *s, const char *reg, int cflags) { - regex_t regex; - char msgbuf[100] = {0}; - - /* Compile regular expression */ - if (regcomp(®ex, reg, cflags) != 0) { - ERROR_EXIT("Fail to compile regex\n"); - } - - /* Execute regular expression */ - int reti = regexec(®ex, s, 0, NULL, 0); - if (!reti) { - regfree(®ex); - return 1; - } else if (reti == REG_NOMATCH) { - regfree(®ex); - return 0; - } else { - regerror(reti, ®ex, msgbuf, sizeof(msgbuf)); - regfree(®ex); - printf("Regex match failed: %s\n", msgbuf); - exit(EXIT_FAILURE); - } - return 0; -} - -static int isCommentLine(char *line) { - if (line == NULL) return 1; - - return regexMatch(line, "^\\s*#.*", REG_EXTENDED); -} - -static void querySqlFile(TAOS* taos, char* sqlFile) -{ - FILE *fp = fopen(sqlFile, "r"); - if (fp == NULL) { - printf("failed to open file %s, reason:%s\n", sqlFile, strerror(errno)); - return; - } - - int read_len = 0; - char * cmd = calloc(1, TSDB_MAX_BYTES_PER_ROW); - size_t cmd_len = 0; - char * line = NULL; - size_t line_len = 0; - - double t = taosGetTimestampMs(); - - while((read_len = tgetline(&line, &line_len, fp)) != -1) { - if (read_len >= TSDB_MAX_BYTES_PER_ROW) continue; - line[--read_len] = '\0'; - - if (read_len == 0 || isCommentLine(line)) { // line starts with # - continue; - } - - if (line[read_len - 1] == '\\') { - line[read_len - 1] = ' '; - memcpy(cmd + cmd_len, line, read_len); - cmd_len += read_len; - continue; - } - - memcpy(cmd + cmd_len, line, read_len); - if (0 != queryDbExec(taos, cmd, NO_INSERT_TYPE, false)) { - errorPrint2("%s() LN%d, queryDbExec %s failed!\n", - __func__, __LINE__, cmd); - tmfree(cmd); - tmfree(line); - tmfclose(fp); - return; - } - memset(cmd, 0, TSDB_MAX_BYTES_PER_ROW); - cmd_len = 0; - } - - t = taosGetTimestampMs() - t; - printf("run %s took %.6f second(s)\n\n", sqlFile, t); - - tmfree(cmd); - tmfree(line); - tmfclose(fp); - return; -} - -static void testMetaFile() { - if (INSERT_TEST == g_args.test_mode) { - if (g_Dbs.cfgDir[0]) - taos_options(TSDB_OPTION_CONFIGDIR, g_Dbs.cfgDir); - - insertTestProcess(); - - } else if (QUERY_TEST == g_args.test_mode) { - if (g_queryInfo.cfgDir[0]) - taos_options(TSDB_OPTION_CONFIGDIR, g_queryInfo.cfgDir); - - queryTestProcess(); - - } else if (SUBSCRIBE_TEST == g_args.test_mode) { - if (g_queryInfo.cfgDir[0]) - taos_options(TSDB_OPTION_CONFIGDIR, g_queryInfo.cfgDir); - - subscribeTestProcess(); - - } else { - ; - } -} - -static void queryAggrFunc() { - // query data - - pthread_t read_id; - threadInfo *pThreadInfo = calloc(1, sizeof(threadInfo)); - assert(pThreadInfo); - pThreadInfo->start_time = DEFAULT_START_TIME; // 2017-07-14 10:40:00.000 - pThreadInfo->start_table_from = 0; - - if (g_args.use_metric) { - pThreadInfo->ntables = g_Dbs.db[0].superTbls[0].childTblCount; - pThreadInfo->end_table_to = g_Dbs.db[0].superTbls[0].childTblCount - 1; - pThreadInfo->stbInfo = &g_Dbs.db[0].superTbls[0]; - tstrncpy(pThreadInfo->tb_prefix, - g_Dbs.db[0].superTbls[0].childTblPrefix, TBNAME_PREFIX_LEN); - } else { - pThreadInfo->ntables = g_args.ntables; - pThreadInfo->end_table_to = g_args.ntables -1; - tstrncpy(pThreadInfo->tb_prefix, g_args.tb_prefix, TSDB_TABLE_NAME_LEN); - } - - pThreadInfo->taos = taos_connect( - g_Dbs.host, - g_Dbs.user, - g_Dbs.password, - g_Dbs.db[0].dbName, - g_Dbs.port); - if (pThreadInfo->taos == NULL) { - free(pThreadInfo); - errorPrint2("Failed to connect to TDengine, reason:%s\n", - taos_errstr(NULL)); - exit(EXIT_FAILURE); - } - - tstrncpy(pThreadInfo->filePath, g_Dbs.resultFile, MAX_FILE_NAME_LEN); - - if (!g_Dbs.use_metric) { - pthread_create(&read_id, NULL, queryNtableAggrFunc, pThreadInfo); - } else { - pthread_create(&read_id, NULL, queryStableAggrFunc, pThreadInfo); - } - pthread_join(read_id, NULL); - taos_close(pThreadInfo->taos); - free(pThreadInfo); -} - -static void testCmdLine() { - - if (strlen(configDir)) { - wordexp_t full_path; - if (wordexp(configDir, &full_path, 0) != 0) { - errorPrint("Invalid path %s\n", configDir); - return; - } - taos_options(TSDB_OPTION_CONFIGDIR, full_path.we_wordv[0]); - wordfree(&full_path); - } - - g_args.test_mode = INSERT_TEST; - insertTestProcess(); - - if (g_Dbs.aggr_func) { - queryAggrFunc(); - } -} - -int main(int argc, char *argv[]) { - parse_args(argc, argv, &g_args); - - debugPrint("meta file: %s\n", g_args.metaFile); - - if (g_args.metaFile) { - g_totalChildTables = 0; - - if (false == getInfoFromJsonFile(g_args.metaFile)) { - printf("Failed to read %s\n", g_args.metaFile); - return 1; - } - - testMetaFile(); - } else { - memset(&g_Dbs, 0, sizeof(SDbs)); - g_Dbs.db = calloc(1, sizeof(SDataBase)); - assert(g_Dbs.db); - g_Dbs.db[0].superTbls = calloc(1, sizeof(SSuperTable)); - assert(g_Dbs.db[0].superTbls); - setParaFromArg(); - - if (NULL != g_args.sqlFile) { - TAOS* qtaos = taos_connect( - g_Dbs.host, - g_Dbs.user, - g_Dbs.password, - g_Dbs.db[0].dbName, - g_Dbs.port); - querySqlFile(qtaos, g_args.sqlFile); - taos_close(qtaos); - - } else { - testCmdLine(); - } - - if (g_dupstr) - free(g_dupstr); - } - - return 0; -} diff --git a/src/mnode/src/mnodeDb.c b/src/mnode/src/mnodeDb.c index 00471bbf042e147a210fb575e7372d9696c33617..13afd1c29894fea07e5c269eee53b36a386ee442 100644 --- a/src/mnode/src/mnodeDb.c +++ b/src/mnode/src/mnodeDb.c @@ -1139,7 +1139,7 @@ static int32_t mnodeAlterDbFp(SMnodeMsg *pMsg) { return sdbUpdateRow(&row); } - //bnNotify(); + bnNotify(); return TSDB_CODE_MND_ACTION_IN_PROGRESS; } diff --git a/src/mnode/src/mnodeShow.c b/src/mnode/src/mnodeShow.c index bbfdb52e058c9e8c4ce3d3fe9d06715e9c0483aa..960987e7ad3b570548d9f8eb93a64ed963a5956b 100644 --- a/src/mnode/src/mnodeShow.c +++ b/src/mnode/src/mnodeShow.c @@ -121,7 +121,7 @@ static int32_t mnodeProcessShowMsg(SMnodeMsg *pMsg) { } if (!tsMnodeShowMetaFp[pShowMsg->type] || !tsMnodeShowRetrieveFp[pShowMsg->type]) { - mError("show type:%s is not support", mnodeGetShowType(pShowMsg->type)); + mWarn("show type:%s is not support", mnodeGetShowType(pShowMsg->type)); return TSDB_CODE_COM_OPS_NOT_SUPPORT; } diff --git a/src/mnode/src/mnodeUser.c b/src/mnode/src/mnodeUser.c index c5c54791cf828661e146b121765806a630ea8baa..e2fda182d7287f61311f658b83134132a4e8d9a1 100644 --- a/src/mnode/src/mnodeUser.c +++ b/src/mnode/src/mnodeUser.c @@ -276,10 +276,10 @@ int32_t mnodeCreateUser(SAcctObj *pAcct, char *name, char *pass, void *pMsg) { code = sdbInsertRow(&row); if (code != TSDB_CODE_SUCCESS && code != TSDB_CODE_MND_ACTION_IN_PROGRESS) { - mError("user:%s, failed to create by %s, reason:%s", pUser->user, mnodeGetUserFromMsg(pMsg), tstrerror(code)); + mError("user:%s, failed to create, reason:%s", pUser->user, tstrerror(code)); tfree(pUser); } else { - mLInfo("user:%s, is created by %s", pUser->user, mnodeGetUserFromMsg(pMsg)); + mLInfo("user:%s, is created successfully", pUser->user); } return code; diff --git a/src/mnode/src/mnodeVgroup.c b/src/mnode/src/mnodeVgroup.c index a32da29124016424ce5fe1436f29cca91da3e546..838aa577ae0fe396f3e80d2fca9066de10d3bc7a 100644 --- a/src/mnode/src/mnodeVgroup.c +++ b/src/mnode/src/mnodeVgroup.c @@ -742,19 +742,6 @@ static int32_t mnodeGetVgroupMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *p return 0; } -static bool mnodeFilterVgroups(SVgObj *pVgroup, STableObj *pTable) { - if (NULL == pTable || pTable->type == TSDB_SUPER_TABLE) { - return true; - } - - SCTableObj *pCTable = (SCTableObj *)pTable; - if (pVgroup->vgId == pCTable->vgId) { - return true; - } else { - return false; - } -} - static int32_t mnodeRetrieveVgroups(SShowObj *pShow, char *data, int32_t rows, void *pConn) { int32_t numOfRows = 0; SVgObj *pVgroup = NULL; @@ -770,11 +757,6 @@ static int32_t mnodeRetrieveVgroups(SShowObj *pShow, char *data, int32_t rows, v return 0; } - STableObj *pTable = NULL; - if (pShow->payloadLen > 0 ) { - pTable = mnodeGetTable(pShow->payload); - } - while (numOfRows < rows) { pShow->pIter = mnodeGetNextVgroup(pShow->pIter, &pVgroup); if (pVgroup == NULL) break; @@ -784,11 +766,6 @@ static int32_t mnodeRetrieveVgroups(SShowObj *pShow, char *data, int32_t rows, v continue; } - if (!mnodeFilterVgroups(pVgroup, pTable)) { - mnodeDecVgroupRef(pVgroup); - continue; - } - cols = 0; pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; @@ -842,7 +819,6 @@ static int32_t mnodeRetrieveVgroups(SShowObj *pShow, char *data, int32_t rows, v mnodeVacuumResult(data, pShow->numOfColumns, numOfRows, rows, pShow); pShow->numOfReads += numOfRows; - mnodeDecTableRef(pTable); mnodeDecDbRef(pDb); return numOfRows; diff --git a/src/os/inc/osTime.h b/src/os/inc/osTime.h index dcb0e4c9b630216600c4f8f017b8154e9bb9dac4..798a08e3e6e16470a750cbd8bfed429539b44d8d 100644 --- a/src/os/inc/osTime.h +++ b/src/os/inc/osTime.h @@ -94,6 +94,8 @@ typedef struct SSessionWindow { } SSessionWindow; int64_t taosTimeAdd(int64_t t, int64_t duration, char unit, int32_t precision); +int64_t taosTimeSub(int64_t t, int64_t duration, char unit, int32_t precision); + int64_t taosTimeTruncate(int64_t t, const SInterval* pInterval, int32_t precision); int32_t taosTimeCountInterval(int64_t skey, int64_t ekey, int64_t interval, char unit, int32_t precision); diff --git a/src/os/src/detail/osTime.c b/src/os/src/detail/osTime.c index ba77885f02dddf6af6ee6ee7478d1087299a563b..73345426c9a266c57ac286efac716f5c5490b8bf 100644 --- a/src/os/src/detail/osTime.c +++ b/src/os/src/detail/osTime.c @@ -424,29 +424,44 @@ int64_t convertTimePrecision(int64_t time, int32_t fromPrecision, int32_t toPrec } } //end switch fromPrecision end_: - if (tempResult > (double)INT64_MAX) return INT64_MAX; - if (tempResult < (double)INT64_MIN) return INT64_MIN + 1; // INT64_MIN means NULL + if (tempResult >= (double)INT64_MAX) return INT64_MAX; + if (tempResult <= (double)INT64_MIN) return INT64_MIN + 1; // INT64_MIN means NULL return time; } static int32_t getDuration(int64_t val, char unit, int64_t* result, int32_t timePrecision) { switch (unit) { - case 's': + case 's':{ + double temp = ((double)val) * MILLISECOND_PER_SECOND; + if (temp >= (double)INT64_MAX || temp <= (double)INT64_MIN) return -1; (*result) = convertTimePrecision(val * MILLISECOND_PER_SECOND, TSDB_TIME_PRECISION_MILLI, timePrecision); break; - case 'm': + } + case 'm':{ + double temp = ((double)val) * MILLISECOND_PER_MINUTE; + if (temp >= (double)INT64_MAX || temp <= (double)INT64_MIN) return -1; (*result) = convertTimePrecision(val * MILLISECOND_PER_MINUTE, TSDB_TIME_PRECISION_MILLI, timePrecision); break; - case 'h': + } + case 'h':{ + double temp = ((double)val) * MILLISECOND_PER_HOUR; + if (temp >= (double)INT64_MAX || temp <= (double)INT64_MIN) return -1; (*result) = convertTimePrecision(val * MILLISECOND_PER_HOUR, TSDB_TIME_PRECISION_MILLI, timePrecision); break; - case 'd': + } + case 'd': { + double temp = ((double)val) * MILLISECOND_PER_DAY; + if (temp >= (double)INT64_MAX || temp <= (double)INT64_MIN) return -1; (*result) = convertTimePrecision(val * MILLISECOND_PER_DAY, TSDB_TIME_PRECISION_MILLI, timePrecision); break; - case 'w': + } + case 'w': { + double temp = ((double)val) * MILLISECOND_PER_WEEK; + if (temp >= (double)INT64_MAX || temp <= (double)INT64_MIN) return -1; (*result) = convertTimePrecision(val * MILLISECOND_PER_WEEK, TSDB_TIME_PRECISION_MILLI, timePrecision); break; + } case 'a': (*result) = convertTimePrecision(val, TSDB_TIME_PRECISION_MILLI, timePrecision); break; @@ -533,6 +548,27 @@ int64_t taosTimeAdd(int64_t t, int64_t duration, char unit, int32_t precision) { return (int64_t)(mktime(&tm) * TSDB_TICK_PER_SECOND(precision)); } +int64_t taosTimeSub(int64_t t, int64_t duration, char unit, int32_t precision) { + if (duration == 0) { + return t; + } + if (unit == 'y') { + duration *= 12; + } else if (unit != 'n') { + return t - duration; + } + + struct tm tm; + time_t tt = (time_t)(t / TSDB_TICK_PER_SECOND(precision)); + localtime_r(&tt, &tm); + int mon = tm.tm_year * 12 + tm.tm_mon - (int)duration; + tm.tm_year = mon / 12; + tm.tm_mon = mon % 12; + + return (int64_t)(mktime(&tm) * TSDB_TICK_PER_SECOND(precision)); +} + + int32_t taosTimeCountInterval(int64_t skey, int64_t ekey, int64_t interval, char unit, int32_t precision) { if (ekey < skey) { int64_t tmp = ekey; diff --git a/src/plugins/CMakeLists.txt b/src/plugins/CMakeLists.txt index 075525a0684b332405a23011b0f7f501658d911e..9e0de204d78cb54bea240a734f2373b709b6c6f9 100644 --- a/src/plugins/CMakeLists.txt +++ b/src/plugins/CMakeLists.txt @@ -29,24 +29,47 @@ ELSE () EXECUTE_PROCESS( COMMAND cd .. ) - include(ExternalProject) - ExternalProject_Add(taosadapter - PREFIX "taosadapter" - SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/taosadapter - BUILD_ALWAYS off - DEPENDS taos - BUILD_IN_SOURCE 1 - CONFIGURE_COMMAND cmake -E echo "taosadapter no need cmake to config" - PATCH_COMMAND - COMMAND git clean -f -d - BUILD_COMMAND CGO_CFLAGS=-I${CMAKE_CURRENT_SOURCE_DIR}/../inc CGO_LDFLAGS=-L${CMAKE_BINARY_DIR}/build/lib go build -ldflags "-s -w -X github.com/taosdata/taosadapter/version.CommitID=${taosadapter_commit_sha1}" - INSTALL_COMMAND - COMMAND curl -sL https://github.com/upx/upx/releases/download/v3.96/upx-3.96-amd64_linux.tar.xz -o upx.tar.xz && tar xvJf upx.tar.xz --strip-components 1 > /dev/null && ./upx taosadapter || : - COMMAND cmake -E copy taosadapter ${CMAKE_BINARY_DIR}/build/bin - COMMAND cmake -E make_directory ${CMAKE_BINARY_DIR}/test/cfg/ - COMMAND cmake -E copy ./example/config/taosadapter.toml ${CMAKE_BINARY_DIR}/test/cfg/ - COMMAND cmake -E copy ./taosadapter.service ${CMAKE_BINARY_DIR}/test/cfg/ - ) + + IF (TD_LINUX) + include(ExternalProject) + ExternalProject_Add(taosadapter + PREFIX "taosadapter" + SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/taosadapter + BUILD_ALWAYS off + DEPENDS taos + BUILD_IN_SOURCE 1 + CONFIGURE_COMMAND cmake -E echo "taosadapter no need cmake to config" + PATCH_COMMAND + COMMAND git clean -f -d + BUILD_COMMAND CGO_CFLAGS=-I${CMAKE_CURRENT_SOURCE_DIR}/../inc CGO_LDFLAGS=-L${CMAKE_BINARY_DIR}/build/lib go build -ldflags "-s -w -X github.com/taosdata/taosadapter/version.CommitID=${taosadapter_commit_sha1}" + INSTALL_COMMAND + COMMAND curl -sL https://github.com/upx/upx/releases/download/v3.96/upx-3.96-amd64_linux.tar.xz -o upx.tar.xz && tar xvJf upx.tar.xz --strip-components 1 > /dev/null && ./upx taosadapter || : + COMMAND cmake -E copy taosadapter ${CMAKE_BINARY_DIR}/build/bin + COMMAND cmake -E make_directory ${CMAKE_BINARY_DIR}/test/cfg/ + COMMAND cmake -E copy ./example/config/taosadapter.toml ${CMAKE_BINARY_DIR}/test/cfg/ + COMMAND cmake -E copy ./taosadapter.service ${CMAKE_BINARY_DIR}/test/cfg/ + ) + ELSEIF (TD_DARWIN) + include(ExternalProject) + ExternalProject_Add(taosadapter + PREFIX "taosadapter" + SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/taosadapter + BUILD_ALWAYS off + DEPENDS taos + BUILD_IN_SOURCE 1 + CONFIGURE_COMMAND cmake -E echo "taosadapter no need cmake to config" + PATCH_COMMAND + COMMAND git clean -f -d + BUILD_COMMAND CGO_CFLAGS=-I${CMAKE_CURRENT_SOURCE_DIR}/../inc CGO_LDFLAGS=-L${CMAKE_BINARY_DIR}/build/lib go build -ldflags "-s -w -X github.com/taosdata/taosadapter/version.CommitID=${taosadapter_commit_sha1}" + INSTALL_COMMAND + COMMAND cmake -E copy taosadapter ${CMAKE_BINARY_DIR}/build/bin + COMMAND cmake -E make_directory ${CMAKE_BINARY_DIR}/test/cfg/ + COMMAND cmake -E copy ./example/config/taosadapter.toml ${CMAKE_BINARY_DIR}/test/cfg/ + COMMAND cmake -E copy ./taosadapter.service ${CMAKE_BINARY_DIR}/test/cfg/ + ) + ELSE () + MESSAGE("${Yellow} Windows system still use original embedded httpd ${ColourReset}") + ENDIF () ENDIF () IF (TD_LINUX AND TD_MQTT) diff --git a/src/plugins/http/inc/httpInt.h b/src/plugins/http/inc/httpInt.h index bf8efd2831e19480615be291d409d53207bb8f63..af0f4c579557d1bd919847ef858af8dc1616bb6f 100644 --- a/src/plugins/http/inc/httpInt.h +++ b/src/plugins/http/inc/httpInt.h @@ -147,7 +147,7 @@ typedef struct HttpContext { int32_t state; uint8_t reqType; uint8_t parsed; - uint8_t error; + bool error; char ipstr[22]; char user[TSDB_USER_LEN]; // parsed from auth token or login message char pass[HTTP_PASSWORD_LEN]; diff --git a/src/plugins/http/src/httpContext.c b/src/plugins/http/src/httpContext.c index f26a4b4c8bdda05f801075b70c1b762882adfd27..4922d98ee492c94e56604d5823e87e4704ddf8e3 100644 --- a/src/plugins/http/src/httpContext.c +++ b/src/plugins/http/src/httpContext.c @@ -120,6 +120,7 @@ HttpContext *httpCreateContext(SOCKET fd) { pContext->lastAccessTime = taosGetTimestampSec(); pContext->state = HTTP_CONTEXT_STATE_READY; pContext->parser = httpCreateParser(pContext); + pContext->error = false; TSDB_CACHE_PTR_TYPE handleVal = (TSDB_CACHE_PTR_TYPE)pContext; HttpContext **ppContext = taosCachePut(tsHttpServer.contextCache, &handleVal, sizeof(TSDB_CACHE_PTR_TYPE), &pContext, diff --git a/src/plugins/http/src/httpResp.c b/src/plugins/http/src/httpResp.c index 1d05b455cb5c66e4f492140e1f337210da04caef..824ce746704b477ee482d82fc617ce37af307a59 100644 --- a/src/plugins/http/src/httpResp.c +++ b/src/plugins/http/src/httpResp.c @@ -24,7 +24,7 @@ const char *httpKeepAliveStr[] = {"", "Connection: Keep-Alive\r\n", "Connection: Close\r\n"}; -const char *httpVersionStr[] = {"HTTP/1.0", "HTTP/1.1", "HTTP/1.2"}; +const char *httpVersionStr[] = {"HTTP/1.0", "HTTP/1.1", "HTTP/2.0"}; /* There is no version 1.2 */ const char *httpRespTemplate[] = { // HTTP_RESPONSE_JSON_OK @@ -52,8 +52,14 @@ static void httpSendErrorRespImp(HttpContext *pContext, int32_t httpCode, char * int8_t httpVersion = 0; int8_t keepAlive = 0; + if (pContext->parser != NULL) { httpVersion = pContext->parser->httpVersion; + } + + if (pContext->error == true) { + keepAlive = HTTP_KEEPALIVE_DISABLE; + } else if (pContext->parser != NULL) { keepAlive = pContext->parser->keepAlive; } diff --git a/src/query/inc/qAggMain.h b/src/query/inc/qAggMain.h index 8bcd8fea42aa46ad3dd2f0857d88a9b4bb76dd4d..4ba6dd2c536d9bbf3b5e2b3430293671a0ecb7b7 100644 --- a/src/query/inc/qAggMain.h +++ b/src/query/inc/qAggMain.h @@ -192,6 +192,7 @@ typedef struct SQLFunctionCtx { char * pOutput; // final result output buffer, point to sdata->data uint8_t currentStage; // record current running step, default: 0 int64_t startTs; // timestamp range of current query when function is executed on a specific data block + int64_t endTs; int32_t numOfParams; tVariant param[4]; // input parameter, e.g., top(k, 20), the number of results for top query is kept in param int64_t *ptsList; // corresponding timestamp array list diff --git a/src/query/inc/qExecutor.h b/src/query/inc/qExecutor.h index ed54723adeafdcd3cdff8b438d2f823a73a04a33..fe4fb6c950d4f3e0186668d957900934ba243e5d 100644 --- a/src/query/inc/qExecutor.h +++ b/src/query/inc/qExecutor.h @@ -63,6 +63,10 @@ enum { QUERY_OVER = 0x4u, }; +enum { + OPTION_SWITCH_TABLE = 1, +}; + typedef struct SResultRowPool { int32_t elemSize; int32_t blockSize; @@ -241,6 +245,7 @@ typedef struct SQueryAttr { int16_t numOfTags; STimeWindow window; + STimeWindow range; SInterval interval; SSessionWindow sw; int16_t precision; @@ -277,6 +282,7 @@ typedef struct SQueryAttr { } SQueryAttr; typedef SSDataBlock* (*__operator_fn_t)(void* param, bool* newgroup); +typedef void (*__operator_notify_fn_t)(void* param, int32_t option); typedef void (*__optr_cleanup_fn_t)(void* param, int32_t num); struct SOperatorInfo; @@ -348,7 +354,7 @@ enum OPERATOR_TYPE_E { OP_Distinct = 20, OP_Join = 21, OP_StateWindow = 22, - OP_AllTimeWindow = 23, + OP_TimeEvery = 23, OP_AllMultiTableTimeInterval = 24, OP_Order = 25, }; @@ -363,10 +369,11 @@ typedef struct SOperatorInfo { SExprInfo *pExpr; SQueryRuntimeEnv *pRuntimeEnv; - struct SOperatorInfo **upstream; // upstream pointer list - int32_t numOfUpstream; // number of upstream. The value is always ONE expect for join operator - __operator_fn_t exec; - __optr_cleanup_fn_t cleanup; + struct SOperatorInfo **upstream; // upstream pointer list + int32_t numOfUpstream; // number of upstream. The value is always ONE expect for join operator + __operator_fn_t exec; + __operator_notify_fn_t notify; + __optr_cleanup_fn_t cleanup; } SOperatorInfo; enum { @@ -479,6 +486,21 @@ typedef struct SProjectOperatorInfo { SSDataBlock *existDataBlock; } SProjectOperatorInfo; +typedef struct STimeEveryOperatorInfo { + SOptrBasicInfo binfo; + int32_t bufCapacity; + uint32_t seed; + + int64_t tableEndKey; + SSDataBlock *lastBlock; + SHashObj *rangeStart; + int32_t lastGroupIdx; + + bool groupDone; + bool allDone; + SSDataBlock *existDataBlock; +} STimeEveryOperatorInfo; + typedef struct SLimitOperatorInfo { int64_t limit; int64_t total; @@ -599,13 +621,12 @@ SOperatorInfo* createAggregateOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOpera SOperatorInfo* createProjectOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOperatorInfo* upstream, SExprInfo* pExpr, int32_t numOfOutput); SOperatorInfo* createLimitOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOperatorInfo* upstream); SOperatorInfo* createTimeIntervalOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOperatorInfo* upstream, SExprInfo* pExpr, int32_t numOfOutput); -SOperatorInfo* createAllTimeIntervalOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOperatorInfo* upstream, SExprInfo* pExpr, int32_t numOfOutput); SOperatorInfo* createSWindowOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOperatorInfo* upstream, SExprInfo* pExpr, int32_t numOfOutput); SOperatorInfo* createFillOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOperatorInfo* upstream, SExprInfo* pExpr, int32_t numOfOutput, bool multigroupResult); SOperatorInfo* createGroupbyOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOperatorInfo* upstream, SExprInfo* pExpr, int32_t numOfOutput); SOperatorInfo* createMultiTableAggOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOperatorInfo* upstream, SExprInfo* pExpr, int32_t numOfOutput); SOperatorInfo* createMultiTableTimeIntervalOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOperatorInfo* upstream, SExprInfo* pExpr, int32_t numOfOutput); -SOperatorInfo* createAllMultiTableTimeIntervalOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOperatorInfo* upstream, SExprInfo* pExpr, int32_t numOfOutput); +SOperatorInfo* createTimeEveryOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOperatorInfo* upstream, SExprInfo* pExpr, int32_t numOfOutput); SOperatorInfo* createTagScanOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SExprInfo* pExpr, int32_t numOfOutput); SOperatorInfo* createDistinctOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOperatorInfo* upstream, SExprInfo* pExpr, int32_t numOfOutput); SOperatorInfo* createTableBlockInfoScanOperator(void* pTsdbQueryHandle, SQueryRuntimeEnv* pRuntimeEnv); @@ -649,7 +670,7 @@ int32_t createQueryFunc(SQueriedTableInfo* pTableInfo, int32_t numOfOutput, SExp int32_t createIndirectQueryFuncExprFromMsg(SQueryTableMsg *pQueryMsg, int32_t numOfOutput, SExprInfo **pExprInfo, SSqlExpr **pExpr, SExprInfo *prevExpr, SUdfInfo *pUdfInfo); -int32_t createQueryFilter(char *data, uint16_t len, void** pFilters); +int32_t createQueryFilter(char *data, int32_t len, void** pFilters); SGroupbyExpr *createGroupbyExprFromMsg(SQueryTableMsg *pQueryMsg, SColIndex *pColIndex, int32_t *code); SQInfo *createQInfoImpl(SQueryTableMsg *pQueryMsg, SGroupbyExpr *pGroupbyExpr, SExprInfo *pExprs, diff --git a/src/query/inc/qFill.h b/src/query/inc/qFill.h index caa0c55b3ff1a805975a6258ca360e5099f4894e..2bf0ca8b556468b18ca0a71071c747f20441a93f 100644 --- a/src/query/inc/qFill.h +++ b/src/query/inc/qFill.h @@ -86,7 +86,7 @@ bool taosFillHasMoreResults(SFillInfo* pFillInfo); int64_t getNumOfResultsAfterFillGap(SFillInfo* pFillInfo, int64_t ekey, int32_t maxNumOfRows); -int32_t taosGetLinearInterpolationVal(SPoint* point, int32_t outputType, SPoint* point1, SPoint* point2, int32_t inputType); +int32_t taosGetLinearInterpolationVal(SPoint* point, int32_t outputType, SPoint* point1, SPoint* point2, int32_t inputType, bool *exceedMax, bool *exceedMin); int64_t taosFillResultDataBlock(SFillInfo* pFillInfo, void** output, int32_t capacity); diff --git a/src/query/inc/qFilter.h b/src/query/inc/qFilter.h index c34a56cc1cd6e135947eee897f87d060880f15c7..e10d7fdfb4f65bb2d9ed2d14ba3e2d04f9d76706 100644 --- a/src/query/inc/qFilter.h +++ b/src/query/inc/qFilter.h @@ -101,14 +101,6 @@ typedef struct SFilterRange { char eflag; } SFilterRange; -typedef struct SFilterColRange { - uint16_t idx; //column field idx - bool isNull; - bool notNull; - bool isRange; - SFilterRange ra; -} SFilterColRange; - typedef bool (*rangeCompFunc) (const void *, const void *, const void *, const void *, __compar_fn_t); typedef int32_t(*filter_desc_compare_func)(const void *, const void *); typedef bool(*filter_exec_func)(void *, int32_t, int8_t**, SDataStatis *, int16_t); @@ -160,37 +152,39 @@ typedef struct SFilterField { } SFilterField; typedef struct SFilterFields { - uint16_t size; - uint16_t num; + uint32_t size; + uint32_t num; SFilterField *fields; } SFilterFields; typedef struct SFilterFieldId { uint16_t type; - uint16_t idx; + uint32_t idx; } SFilterFieldId; typedef struct SFilterGroup { - uint16_t unitSize; - uint16_t unitNum; - uint16_t *unitIdxs; + uint32_t unitSize; + uint32_t unitNum; + uint32_t *unitIdxs; uint8_t *unitFlags; // !unit result } SFilterGroup; typedef struct SFilterColInfo { uint8_t type; int32_t dataType; + uint8_t optr; // for equal operation in the relation of RELATION_IN + int64_t value; // for equal operation in the relation of RELATION_IN void *info; } SFilterColInfo; typedef struct SFilterGroupCtx { - uint16_t colNum; - uint16_t *colIdx; + uint32_t colNum; + uint32_t *colIdx; SFilterColInfo *colInfo; } SFilterGroupCtx; typedef struct SFilterColCtx { - uint16_t colIdx; + uint32_t colIdx; void* ctx; } SFilterColCtx; @@ -227,13 +221,12 @@ typedef struct SFilterPCtx { typedef struct SFilterInfo { uint32_t options; uint32_t status; - uint16_t unitSize; - uint16_t unitNum; - uint16_t groupNum; - uint16_t colRangeNum; + uint32_t unitSize; + uint32_t unitNum; + uint32_t groupNum; + uint32_t colRangeNum; SFilterFields fields[FLD_TYPE_MAX]; SFilterGroup *groups; - uint16_t *cgroups; SFilterUnit *units; SFilterComUnit *cunits; uint8_t *unitRes; // result @@ -241,15 +234,13 @@ typedef struct SFilterInfo { SFilterRangeCtx **colRange; filter_exec_func func; uint8_t blkFlag; - uint16_t blkGroupNum; - uint16_t *blkUnits; + uint32_t blkGroupNum; + uint32_t *blkUnits; int8_t *blkUnitRes; SFilterPCtx pctx; } SFilterInfo; -#define COL_FIELD_SIZE (sizeof(SFilterField) + 2 * sizeof(int64_t)) - #define FILTER_NO_MERGE_DATA_TYPE(t) ((t) == TSDB_DATA_TYPE_BINARY || (t) == TSDB_DATA_TYPE_NCHAR) #define FILTER_NO_MERGE_OPTR(o) ((o) == TSDB_RELATION_ISNULL || (o) == TSDB_RELATION_NOTNULL || (o) == FILTER_DUMMY_EMPTY_OPTR) @@ -266,7 +257,7 @@ typedef struct SFilterInfo { #define FILTER_CLR_FLAG(st, f) st &= (~f) #define SIMPLE_COPY_VALUES(dst, src) *((int64_t *)dst) = *((int64_t *)src) -#define FILTER_PACKAGE_UNIT_HASH_KEY(v, optr, idx1, idx2) do { char *_t = (char *)v; _t[0] = optr; *(uint16_t *)(_t + 1) = idx1; *(uint16_t *)(_t + 3) = idx2; } while (0) +#define FILTER_PACKAGE_UNIT_HASH_KEY(v, optr, idx1, idx2) do { char *_t = (char *)v; _t[0] = optr; *(uint32_t *)(_t + 1) = idx1; *(uint32_t *)(_t + 3) = idx2; } while (0) #define FILTER_GREATER(cr,sflag,eflag) ((cr > 0) || ((cr == 0) && (FILTER_GET_FLAG(sflag,RANGE_FLG_EXCLUDE) || FILTER_GET_FLAG(eflag,RANGE_FLG_EXCLUDE)))) #define FILTER_COPY_RA(dst, src) do { (dst)->sflag = (src)->sflag; (dst)->eflag = (src)->eflag; (dst)->s = (src)->s; (dst)->e = (src)->e; } while (0) @@ -321,7 +312,7 @@ typedef struct SFilterInfo { #define FILTER_PUSH_VAR_HASH(colInfo, ha) do { (colInfo).type = RANGE_TYPE_VAR_HASH; (colInfo).info = ha;} while (0) #define FILTER_PUSH_CTX(colInfo, ctx) do { (colInfo).type = RANGE_TYPE_MR_CTX; (colInfo).info = ctx;} while (0) -#define FILTER_COPY_IDX(dst, src, n) do { *(dst) = malloc(sizeof(uint16_t) * n); memcpy(*(dst), src, sizeof(uint16_t) * n);} while (0) +#define FILTER_COPY_IDX(dst, src, n) do { *(dst) = malloc(sizeof(uint32_t) * n); memcpy(*(dst), src, sizeof(uint32_t) * n);} while (0) #define FILTER_ADD_CTX_TO_GRES(gres, idx, ctx) do { if ((gres)->colCtxs == NULL) { (gres)->colCtxs = taosArrayInit(gres->colNum, sizeof(SFilterColCtx)); } SFilterColCtx cCtx = {idx, ctx}; taosArrayPush((gres)->colCtxs, &cCtx); } while (0) diff --git a/src/query/inc/qSqlparser.h b/src/query/inc/qSqlparser.h index 0ddaabc5fb9bf6eb2c3a16eeedb3b6d952a1f666..da3df98ca337625916471f331858301a28748d0a 100644 --- a/src/query/inc/qSqlparser.h +++ b/src/query/inc/qSqlparser.h @@ -85,6 +85,11 @@ typedef struct SIntervalVal { SStrToken offset; } SIntervalVal; +typedef struct SRangeVal { + void *start; + void *end; +} SRangeVal; + typedef struct SSessionWindowVal { SStrToken col; SStrToken gap; @@ -111,6 +116,7 @@ typedef struct SSqlNode { SLimitVal slimit; // group limit offset [optional] SStrToken sqlstr; // sql string in select clause struct tSqlExpr *pHaving; // having clause [optional] + SRangeVal pRange; // range clause [optional] } SSqlNode; typedef struct SRelElementPair { @@ -272,6 +278,7 @@ typedef struct tSqlExprItem { bool distinct; } tSqlExprItem; + SArray *tVariantListAppend(SArray *pList, tVariant *pVar, uint8_t sortOrder); SArray *tVariantListInsert(SArray *pList, tVariant *pVar, uint8_t sortOrder, int32_t index); SArray *tVariantListAppendToken(SArray *pList, SStrToken *pAliasToken, uint8_t sortOrder); @@ -281,6 +288,7 @@ void *destroyRelationInfo(SRelationInfo* pFromInfo); SRelationInfo *addSubqueryElem(SRelationInfo* pRelationInfo, SArray* pSub, SStrToken* pAlias); // sql expr leaf node +tSqlExpr *tSqlExprCreateTimestamp(SStrToken *pToken, int32_t optrType); tSqlExpr *tSqlExprCreateIdValue(SSqlInfo* pInfo, SStrToken *pToken, int32_t optrType); tSqlExpr *tSqlExprCreateFunction(SArray *pParam, SStrToken *pFuncToken, SStrToken *endToken, int32_t optType); SArray *tStrTokenAppend(SArray *pList, SStrToken *pToken); @@ -296,7 +304,7 @@ void tSqlExprListDestroy(SArray *pList); SSqlNode *tSetQuerySqlNode(SStrToken *pSelectToken, SArray *pSelNodeList, SRelationInfo *pFrom, tSqlExpr *pWhere, SArray *pGroupby, SArray *pSortOrder, SIntervalVal *pInterval, SSessionWindowVal *ps, SWindowStateVal *pw, - SStrToken *pSliding, SArray *pFill, SLimitVal *pLimit, SLimitVal *pgLimit, tSqlExpr *pHaving); + SStrToken *pSliding, SArray *pFill, SLimitVal *pLimit, SLimitVal *pgLimit, tSqlExpr *pHaving, SRangeVal *pRange); int32_t tSqlExprCompare(tSqlExpr *left, tSqlExpr *right); SCreateTableSql *tSetCreateTableInfo(SArray *pCols, SArray *pTags, SSqlNode *pSelect, int32_t type); diff --git a/src/query/inc/qTableMeta.h b/src/query/inc/qTableMeta.h index c1c16267da734ac40cf27276216896e384e294f3..422fdd13a6a6b17d63c35880eab27cad5272621a 100644 --- a/src/query/inc/qTableMeta.h +++ b/src/query/inc/qTableMeta.h @@ -144,6 +144,8 @@ typedef struct SQueryInfo { bool udfCopy; SArray *pUdfInfo; + STimeWindow range; // range for interp + struct SQInfo *pQInfo; // global merge operator struct SQueryAttr *pQueryAttr; // query object diff --git a/src/query/inc/sql.y b/src/query/inc/sql.y index 44898b3c59156c2e4cf9749de47ffa39fa6b53b9..fedf8fead0dd31fc0d71e2b3b1674af92a30f077 100644 --- a/src/query/inc/sql.y +++ b/src/query/inc/sql.y @@ -127,12 +127,6 @@ cmd ::= SHOW dbPrefix(X) VGROUPS. { setShowOptions(pInfo, TSDB_MGMT_TABLE_VGROUP, &token, 0); } -cmd ::= SHOW dbPrefix(X) VGROUPS ids(Y). { - SStrToken token; - tSetDbName(&token, &X); - setShowOptions(pInfo, TSDB_MGMT_TABLE_VGROUP, &token, &Y); -} - //drop configure for tables cmd ::= DROP TABLE ifexists(Y) ids(X) cpxName(Z). { X.n += Z.n; @@ -482,8 +476,8 @@ tagitem(A) ::= PLUS(X) FLOAT(Y). { //////////////////////// The SELECT statement ///////////////////////////////// %type select {SSqlNode*} %destructor select {destroySqlNode($$);} -select(A) ::= SELECT(T) selcollist(W) from(X) where_opt(Y) interval_option(K) sliding_opt(S) session_option(H) windowstate_option(D) fill_opt(F)groupby_opt(P) having_opt(N) orderby_opt(Z) slimit_opt(G) limit_opt(L). { - A = tSetQuerySqlNode(&T, W, X, Y, P, Z, &K, &H, &D, &S, F, &L, &G, N); +select(A) ::= SELECT(T) selcollist(W) from(X) where_opt(Y) range_option(R) interval_option(K) sliding_opt(S) session_option(H) windowstate_option(D) fill_opt(F)groupby_opt(P) having_opt(N) orderby_opt(Z) slimit_opt(G) limit_opt(L). { + A = tSetQuerySqlNode(&T, W, X, Y, P, Z, &K, &H, &D, &S, F, &L, &G, N, &R); } select(A) ::= LP select(B) RP. {A = B;} @@ -501,7 +495,7 @@ cmd ::= union(X). { setSqlInfo(pInfo, X, NULL, TSDB_SQL_SELECT); } // select client_version() // select server_state() select(A) ::= SELECT(T) selcollist(W). { - A = tSetQuerySqlNode(&T, W, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); + A = tSetQuerySqlNode(&T, W, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); } // selcollist is a list of expressions that are to become the return @@ -572,6 +566,22 @@ tablelist(A) ::= tablelist(Y) COMMA ids(X) cpxName(Z) ids(F). { %type tmvar {SStrToken} tmvar(A) ::= VARIABLE(X). {A = X;} + +%type timestamp {tSqlExpr*} +%destructor timestamp {tSqlExprDestroy($$);} + +timestamp(A) ::= INTEGER(X). { A = tSqlExprCreateTimestamp(&X, TK_INTEGER);} +timestamp(A) ::= MINUS(X) INTEGER(Y). { X.n += Y.n; X.type = TK_INTEGER; A = tSqlExprCreateTimestamp(&X, TK_INTEGER);} +timestamp(A) ::= PLUS(X) INTEGER(Y). { X.n += Y.n; X.type = TK_INTEGER; A = tSqlExprCreateTimestamp(&X, TK_INTEGER);} +timestamp(A) ::= STRING(X). { A = tSqlExprCreateTimestamp(&X, TK_STRING);} +timestamp(A) ::= NOW(X). { A = tSqlExprCreateTimestamp(&X, TK_NOW); } +timestamp(A) ::= NOW PLUS VARIABLE(Y). {A = tSqlExprCreateTimestamp(&Y, TK_PLUS); } +timestamp(A) ::= NOW MINUS VARIABLE(Y). {A = tSqlExprCreateTimestamp(&Y, TK_MINUS); } + +%type range_option {SRangeVal} +range_option(N) ::= . {N.start = 0; N.end = 0;} +range_option(N) ::= RANGE LP timestamp(E) COMMA timestamp(X) RP. {N.start = E; N.end = X;} + %type interval_option {SIntervalVal} interval_option(N) ::= intervalKey(A) LP tmvar(E) RP. {N.interval = E; N.offset.n = 0; N.token = A;} interval_option(N) ::= intervalKey(A) LP tmvar(E) COMMA tmvar(X) RP. {N.interval = E; N.offset = X; N.token = A;} diff --git a/src/query/src/qAggMain.c b/src/query/src/qAggMain.c index b0c601c5d86888b8c55d441315632b282e28fe25..3bac631c5466a7d3a1823e6e26882105d983ccc5 100644 --- a/src/query/src/qAggMain.c +++ b/src/query/src/qAggMain.c @@ -28,6 +28,7 @@ #include "qTsbuf.h" #include "queryLog.h" #include "qUdf.h" +#include "tcompare.h" #define GET_INPUT_DATA_LIST(x) ((char *)((x)->pInput)) #define GET_INPUT_DATA(x, y) (GET_INPUT_DATA_LIST(x) + (y) * (x)->inputBytes) @@ -821,7 +822,7 @@ static int32_t lastDistFuncRequired(SQLFunctionCtx *pCtx, STimeWindow* w, int32_ if (pInfo->hasResult != DATA_SET_FLAG) { return BLK_DATA_ALL_NEEDED; } else { - return (pInfo->ts > w->ekey) ? BLK_DATA_NO_NEEDED : BLK_DATA_ALL_NEEDED; + return (pInfo->ts >= w->ekey) ? BLK_DATA_NO_NEEDED : BLK_DATA_ALL_NEEDED; } } @@ -2972,6 +2973,17 @@ static void copy_function(SQLFunctionCtx *pCtx) { assignVal(pCtx->pOutput, pData, pCtx->inputBytes, pCtx->inputType); } +static void full_copy_function(SQLFunctionCtx *pCtx) { + copy_function(pCtx); + + for (int t = 0; t < pCtx->tagInfo.numOfTagCols; ++t) { + SQLFunctionCtx* tagCtx = pCtx->tagInfo.pTagCtxList[t]; + if (tagCtx->functionId == TSDB_FUNC_TAG_DUMMY) { + aAggs[TSDB_FUNC_TAG].xFunction(tagCtx); + } + } +} + enum { INITIAL_VALUE_NOT_ASSIGNED = 0, }; @@ -3895,183 +3907,97 @@ void twa_function_finalizer(SQLFunctionCtx *pCtx) { doFinalizer(pCtx); } -/** - * - * @param pCtx - */ +static void interp_function(SQLFunctionCtx *pCtx) { + int32_t fillType = (int32_t) pCtx->param[2].i64; + //bool ascQuery = (pCtx->order == TSDB_ORDER_ASC); -static void interp_function_impl(SQLFunctionCtx *pCtx) { - int32_t type = (int32_t) pCtx->param[2].i64; - if (type == TSDB_FILL_NONE) { - return; + if (pCtx->start.key == pCtx->startTs) { + assert(pCtx->start.key != INT64_MIN); + + COPY_TYPED_DATA(pCtx->pOutput, pCtx->inputType, &pCtx->start.val); + + goto interp_success_exit; + } else if (pCtx->end.key == pCtx->startTs && pCtx->end.key != INT64_MIN && fillType == TSDB_FILL_NEXT) { + COPY_TYPED_DATA(pCtx->pOutput, pCtx->inputType, &pCtx->end.val); + + goto interp_success_exit; } - bool ascQuery = (pCtx->order == TSDB_ORDER_ASC); + switch (fillType) { + case TSDB_FILL_NULL: + setNull(pCtx->pOutput, pCtx->outputType, pCtx->outputBytes); + break; + + case TSDB_FILL_SET_VALUE: + tVariantDump(&pCtx->param[1], pCtx->pOutput, pCtx->inputType, true); + break; + + case TSDB_FILL_LINEAR: + if (pCtx->start.key == INT64_MIN || pCtx->start.key > pCtx->startTs + || pCtx->end.key == INT64_MIN || pCtx->end.key < pCtx->startTs) { + goto interp_exit; + } + + double v1 = -1, v2 = -1; + GET_TYPED_DATA(v1, double, pCtx->inputType, &pCtx->start.val); + GET_TYPED_DATA(v2, double, pCtx->inputType, &pCtx->end.val); + + SPoint point1 = {.key = pCtx->start.key, .val = &v1}; + SPoint point2 = {.key = pCtx->end.key, .val = &v2}; + SPoint point = {.key = pCtx->startTs, .val = pCtx->pOutput}; - if (pCtx->colId == 0 && pCtx->inputType == TSDB_DATA_TYPE_TIMESTAMP) { - *(TSKEY *)pCtx->pOutput = pCtx->startTs; - } else if (type == TSDB_FILL_NULL) { - setNull(pCtx->pOutput, pCtx->outputType, pCtx->outputBytes); - } else if (type == TSDB_FILL_SET_VALUE) { - tVariantDump(&pCtx->param[1], pCtx->pOutput, pCtx->inputType, true); - } else { - if (pCtx->start.key != INT64_MIN && ((ascQuery && pCtx->start.key <= pCtx->startTs && pCtx->end.key >= pCtx->startTs) || ((!ascQuery) && pCtx->start.key >= pCtx->startTs && pCtx->end.key <= pCtx->startTs))) { - if (type == TSDB_FILL_PREV) { - if (IS_NUMERIC_TYPE(pCtx->inputType) || pCtx->inputType == TSDB_DATA_TYPE_BOOL) { - SET_TYPED_DATA(pCtx->pOutput, pCtx->inputType, pCtx->start.val); - } else { - assignVal(pCtx->pOutput, pCtx->start.ptr, pCtx->outputBytes, pCtx->inputType); - } - } else if (type == TSDB_FILL_NEXT) { - if (IS_NUMERIC_TYPE(pCtx->inputType) || pCtx->inputType == TSDB_DATA_TYPE_BOOL) { - SET_TYPED_DATA(pCtx->pOutput, pCtx->inputType, pCtx->end.val); - } else { - assignVal(pCtx->pOutput, pCtx->end.ptr, pCtx->outputBytes, pCtx->inputType); - } - } else if (type == TSDB_FILL_LINEAR) { - SPoint point1 = {.key = pCtx->start.key, .val = &pCtx->start.val}; - SPoint point2 = {.key = pCtx->end.key, .val = &pCtx->end.val}; - SPoint point = {.key = pCtx->startTs, .val = pCtx->pOutput}; - - int32_t srcType = pCtx->inputType; - if (IS_NUMERIC_TYPE(srcType)) { // TODO should find the not null data? - if (isNull((char *)&pCtx->start.val, srcType) || isNull((char *)&pCtx->end.val, srcType)) { - setNull(pCtx->pOutput, srcType, pCtx->inputBytes); + int32_t srcType = pCtx->inputType; + if (isNull((char *)&pCtx->start.val, srcType) || isNull((char *)&pCtx->end.val, srcType)) { + setNull(pCtx->pOutput, srcType, pCtx->inputBytes); + } else { + bool exceedMax = false, exceedMin = false; + taosGetLinearInterpolationVal(&point, pCtx->outputType, &point1, &point2, TSDB_DATA_TYPE_DOUBLE, &exceedMax, &exceedMin); + if (exceedMax || exceedMin) { + __compar_fn_t func = getComparFunc((int32_t)pCtx->inputType, 0); + if (func(&pCtx->start.val, &pCtx->end.val) <= 0) { + COPY_TYPED_DATA(pCtx->pOutput, pCtx->inputType, exceedMax ? &pCtx->start.val : &pCtx->end.val); } else { - taosGetLinearInterpolationVal(&point, pCtx->outputType, &point1, &point2, TSDB_DATA_TYPE_DOUBLE); + COPY_TYPED_DATA(pCtx->pOutput, pCtx->inputType, exceedMax ? &pCtx->end.val : &pCtx->start.val); } - } else { - setNull(pCtx->pOutput, srcType, pCtx->inputBytes); } } - } else { - if (GET_RES_INFO(pCtx)->numOfRes > 0) { - return; + break; + + case TSDB_FILL_PREV: + if (pCtx->start.key == INT64_MIN || pCtx->start.key > pCtx->startTs) { + goto interp_exit; } - - // no data generated yet - if (pCtx->size < 1) { - return; + + COPY_TYPED_DATA(pCtx->pOutput, pCtx->inputType, &pCtx->start.val); + break; + + case TSDB_FILL_NEXT: + if (pCtx->end.key == INT64_MIN || pCtx->end.key < pCtx->startTs) { + goto interp_exit; } + + COPY_TYPED_DATA(pCtx->pOutput, pCtx->inputType, &pCtx->end.val); + break; - // check the timestamp in input buffer - TSKEY skey = GET_TS_DATA(pCtx, 0); + case TSDB_FILL_NONE: + default: + goto interp_exit; + } - if (type == TSDB_FILL_PREV) { - if ((ascQuery && skey > pCtx->startTs) || ((!ascQuery) && skey < pCtx->startTs)) { - return; - } - if (pCtx->size > 1) { - TSKEY ekey = GET_TS_DATA(pCtx, 1); - if ((ascQuery && ekey > skey && ekey <= pCtx->startTs) || - ((!ascQuery) && ekey < skey && ekey >= pCtx->startTs)){ - skey = ekey; - } - } - assignVal(pCtx->pOutput, pCtx->pInput, pCtx->outputBytes, pCtx->inputType); - } else if (type == TSDB_FILL_NEXT) { - TSKEY ekey = skey; - char* val = NULL; - - if ((ascQuery && ekey < pCtx->startTs) || ((!ascQuery) && ekey > pCtx->startTs)) { - if (pCtx->size > 1) { - ekey = GET_TS_DATA(pCtx, 1); - if ((ascQuery && ekey < pCtx->startTs) || ((!ascQuery) && ekey > pCtx->startTs)) { - setNull(pCtx->pOutput, pCtx->inputType, pCtx->inputBytes); - SET_VAL(pCtx, 1, 1); - return; - } +interp_success_exit: - val = ((char*)pCtx->pInput) + pCtx->inputBytes; - } else { - setNull(pCtx->pOutput, pCtx->inputType, pCtx->inputBytes); - SET_VAL(pCtx, 1, 1); - return; - } - } else { - val = (char*)pCtx->pInput; - } - - assignVal(pCtx->pOutput, val, pCtx->outputBytes, pCtx->inputType); - } else if (type == TSDB_FILL_LINEAR) { - if (pCtx->size <= 1) { - return; - } - - TSKEY ekey = GET_TS_DATA(pCtx, 1); - - // no data generated yet - if ((ascQuery && !(skey <= pCtx->startTs && ekey >= pCtx->startTs)) - || ((!ascQuery) && !(skey >= pCtx->startTs && ekey <= pCtx->startTs))) { - return; - } - - char *start = GET_INPUT_DATA(pCtx, 0); - char *end = GET_INPUT_DATA(pCtx, 1); + *(TSKEY*)pCtx->ptsOutputBuf = pCtx->startTs; - SPoint point1 = {.key = skey, .val = start}; - SPoint point2 = {.key = ekey, .val = end}; - SPoint point = {.key = pCtx->startTs, .val = pCtx->pOutput}; + INC_INIT_VAL(pCtx, 1); - int32_t srcType = pCtx->inputType; - if (IS_NUMERIC_TYPE(srcType)) { // TODO should find the not null data? - if (isNull(start, srcType) || isNull(end, srcType)) { - setNull(pCtx->pOutput, srcType, pCtx->inputBytes); - } else { - taosGetLinearInterpolationVal(&point, pCtx->outputType, &point1, &point2, srcType); - } - } else { - setNull(pCtx->pOutput, srcType, pCtx->inputBytes); - } - } - } - } +interp_exit: - SET_VAL(pCtx, 1, 1); -} + pCtx->start.key = INT64_MIN; + pCtx->end.key = INT64_MIN; + pCtx->endTs = pCtx->startTs; -static void interp_function(SQLFunctionCtx *pCtx) { - // at this point, the value is existed, return directly - if (pCtx->size > 0) { - bool ascQuery = (pCtx->order == TSDB_ORDER_ASC); - TSKEY key; - char *pData; - int32_t typedData = 0; - - if (ascQuery) { - key = GET_TS_DATA(pCtx, 0); - pData = GET_INPUT_DATA(pCtx, 0); - } else { - key = pCtx->start.key; - if (key == INT64_MIN) { - key = GET_TS_DATA(pCtx, 0); - pData = GET_INPUT_DATA(pCtx, 0); - } else { - if (!(IS_NUMERIC_TYPE(pCtx->inputType) || pCtx->inputType == TSDB_DATA_TYPE_BOOL)) { - pData = pCtx->start.ptr; - } else { - typedData = 1; - pData = (char *)&pCtx->start.val; - } - } - } - - //if (key == pCtx->startTs && (ascQuery || !(IS_NUMERIC_TYPE(pCtx->inputType) || pCtx->inputType == TSDB_DATA_TYPE_BOOL))) { - if (key == pCtx->startTs) { - if (typedData) { - SET_TYPED_DATA(pCtx->pOutput, pCtx->inputType, *(double *)pData); - } else { - assignVal(pCtx->pOutput, pData, pCtx->inputBytes, pCtx->inputType); - } - - SET_VAL(pCtx, 1, 1); - } else { - interp_function_impl(pCtx); - } - } else { //no qualified data rows and interpolation is required - interp_function_impl(pCtx); - } + return; } static bool ts_comp_function_setup(SQLFunctionCtx *pCtx, SResultRowCellInfo* pResInfo) { @@ -4459,7 +4385,7 @@ void generateBlockDistResult(STableBlockDist *pTableBlockDist, char* result) { "5th=[%d], 10th=[%d], 20th=[%d], 30th=[%d], 40th=[%d], 50th=[%d]\n\t " "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"], SmallBlocks=[%d], Size=[%.3f(Kb)] Comp=[%.2f]\n\t " + "Rows=[%"PRIu64"], Blocks=[%"PRId64"], SmallBlocks=[%d], Size=[%.3f(Kb)] Comp=[%.5g]\n\t " "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], @@ -4491,230 +4417,182 @@ void blockinfo_func_finalizer(SQLFunctionCtx* pCtx) { ///////////////////////////////////////////////////////////////////////////////////////////////////////////// -#define CFR_SET_VAL(type, data, pCtx, func, i, step, notNullElems) \ +#define CFR_SET_VAL(type, data, pCtx, func, i, step) \ do { \ type *pData = (type *) data; \ type *pOutput = (type *) pCtx->pOutput; \ \ for (; i < pCtx->size && i >= 0; i += step) { \ - if (pCtx->hasNull && isNull((const char*) &pData[i], pCtx->inputType)) { \ - continue; \ + if (pCtx->hasNull && isNull((const char *)&pData[i], pCtx->inputType)) { \ + *pOutput++ = pData[i]; \ + } else { \ + *pOutput++ = (type)func((double)pData[i]); \ } \ - \ - *pOutput++ = (type) func((double) pData[i]); \ - \ - notNullElems++; \ - } \ - } while (0) - -#define CFR_SET_VAL_DOUBLE(data, pCtx, func, i, step, notNullElems) \ - do { \ - 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; \ - } \ - \ - SET_DOUBLE_VAL(pOutput, func(pData[i])); \ - pOutput++; \ - \ - notNullElems++; \ } \ } while (0) static void ceil_function(SQLFunctionCtx *pCtx) { 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; switch (pCtx->inputType) { case TSDB_DATA_TYPE_INT: { - CFR_SET_VAL(int32_t, data, pCtx, ceil, i, step, notNullElems); + CFR_SET_VAL(int32_t, data, pCtx, ceil, i, step); break; }; case TSDB_DATA_TYPE_UINT: { - CFR_SET_VAL(uint32_t, data, pCtx, ceil, i, step, notNullElems); + CFR_SET_VAL(uint32_t, data, pCtx, ceil, i, step); break; }; case TSDB_DATA_TYPE_BIGINT: { - CFR_SET_VAL(int64_t, data, pCtx, ceil, i, step, notNullElems); + CFR_SET_VAL(int64_t, data, pCtx, ceil, i, step); break; } case TSDB_DATA_TYPE_UBIGINT: { - CFR_SET_VAL(uint64_t, data, pCtx, ceil, i, step, notNullElems); + CFR_SET_VAL(uint64_t, data, pCtx, ceil, i, step); break; } case TSDB_DATA_TYPE_DOUBLE: { - CFR_SET_VAL_DOUBLE(data, pCtx, ceil, i, step, notNullElems); + CFR_SET_VAL(double, data, pCtx, ceil, i, step); break; } case TSDB_DATA_TYPE_FLOAT: { - CFR_SET_VAL(float, data, pCtx, ceil, i, step, notNullElems); + CFR_SET_VAL(float, data, pCtx, ceil, i, step); break; } case TSDB_DATA_TYPE_SMALLINT: { - CFR_SET_VAL(int16_t, data, pCtx, ceil, i, step, notNullElems); + CFR_SET_VAL(int16_t, data, pCtx, ceil, i, step); break; } case TSDB_DATA_TYPE_USMALLINT: { - CFR_SET_VAL(uint16_t, data, pCtx, ceil, i, step, notNullElems); + CFR_SET_VAL(uint16_t, data, pCtx, ceil, i, step); break; } case TSDB_DATA_TYPE_TINYINT: { - CFR_SET_VAL(int8_t, data, pCtx, ceil, i, step, notNullElems); + CFR_SET_VAL(int8_t, data, pCtx, ceil, i, step); break; } case TSDB_DATA_TYPE_UTINYINT: { - CFR_SET_VAL(uint8_t, data, pCtx, ceil, i, step, notNullElems); + CFR_SET_VAL(uint8_t, data, pCtx, ceil, i, step); break; } default: qError("error input type"); } - if (notNullElems <= 0) { - /* - * current block may be null value - */ - assert(pCtx->hasNull); - } else { - GET_RES_INFO(pCtx)->numOfRes += notNullElems; - } + GET_RES_INFO(pCtx)->numOfRes += pCtx->size; } static void floor_function(SQLFunctionCtx *pCtx) { 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; switch (pCtx->inputType) { case TSDB_DATA_TYPE_INT: { - CFR_SET_VAL(int32_t, data, pCtx, floor, i, step, notNullElems); + CFR_SET_VAL(int32_t, data, pCtx, floor, i, step); break; }; case TSDB_DATA_TYPE_UINT: { - CFR_SET_VAL(uint32_t, data, pCtx, floor, i, step, notNullElems); + CFR_SET_VAL(uint32_t, data, pCtx, floor, i, step); break; }; case TSDB_DATA_TYPE_BIGINT: { - CFR_SET_VAL(int64_t, data, pCtx, floor, i, step, notNullElems); + CFR_SET_VAL(int64_t, data, pCtx, floor, i, step); break; } case TSDB_DATA_TYPE_UBIGINT: { - CFR_SET_VAL(uint64_t, data, pCtx, floor, i, step, notNullElems); + CFR_SET_VAL(uint64_t, data, pCtx, floor, i, step); break; } case TSDB_DATA_TYPE_DOUBLE: { - CFR_SET_VAL_DOUBLE(data, pCtx, floor, i, step, notNullElems); + CFR_SET_VAL(double, data, pCtx, floor, i, step); break; } case TSDB_DATA_TYPE_FLOAT: { - CFR_SET_VAL(float, data, pCtx, floor, i, step, notNullElems); + CFR_SET_VAL(float, data, pCtx, floor, i, step); break; } case TSDB_DATA_TYPE_SMALLINT: { - CFR_SET_VAL(int16_t, data, pCtx, floor, i, step, notNullElems); + CFR_SET_VAL(int16_t, data, pCtx, floor, i, step); break; } case TSDB_DATA_TYPE_USMALLINT: { - CFR_SET_VAL(uint16_t, data, pCtx, floor, i, step, notNullElems); + CFR_SET_VAL(uint16_t, data, pCtx, floor, i, step); break; } case TSDB_DATA_TYPE_TINYINT: { - CFR_SET_VAL(int8_t, data, pCtx, floor, i, step, notNullElems); + CFR_SET_VAL(int8_t, data, pCtx, floor, i, step); break; } case TSDB_DATA_TYPE_UTINYINT: { - CFR_SET_VAL(uint8_t, data, pCtx, floor, i, step, notNullElems); + CFR_SET_VAL(uint8_t, data, pCtx, floor, i, step); break; } default: qError("error input type"); } - if (notNullElems <= 0) { - /* - * current block may be null value - */ - assert(pCtx->hasNull); - } else { - GET_RES_INFO(pCtx)->numOfRes += notNullElems; - } + GET_RES_INFO(pCtx)->numOfRes += pCtx->size; } static void round_function(SQLFunctionCtx *pCtx) { 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; switch (pCtx->inputType) { case TSDB_DATA_TYPE_INT: { - CFR_SET_VAL(int32_t, data, pCtx, round, i, step, notNullElems); + CFR_SET_VAL(int32_t, data, pCtx, round, i, step); break; }; case TSDB_DATA_TYPE_UINT: { - CFR_SET_VAL(uint32_t, data, pCtx, round, i, step, notNullElems); + CFR_SET_VAL(uint32_t, data, pCtx, round, i, step); break; }; case TSDB_DATA_TYPE_BIGINT: { - CFR_SET_VAL(int64_t, data, pCtx, round, i, step, notNullElems); + CFR_SET_VAL(int64_t, data, pCtx, round, i, step); break; } case TSDB_DATA_TYPE_UBIGINT: { - CFR_SET_VAL(uint64_t, data, pCtx, round, i, step, notNullElems); + CFR_SET_VAL(uint64_t, data, pCtx, round, i, step); break; } case TSDB_DATA_TYPE_DOUBLE: { - CFR_SET_VAL_DOUBLE(data, pCtx, round, i, step, notNullElems); + CFR_SET_VAL(double, data, pCtx, round, i, step); break; } case TSDB_DATA_TYPE_FLOAT: { - CFR_SET_VAL(float, data, pCtx, round, i, step, notNullElems); + CFR_SET_VAL(float, data, pCtx, round, i, step); break; } case TSDB_DATA_TYPE_SMALLINT: { - CFR_SET_VAL(int16_t, data, pCtx, round, i, step, notNullElems); + CFR_SET_VAL(int16_t, data, pCtx, round, i, step); break; } case TSDB_DATA_TYPE_USMALLINT: { - CFR_SET_VAL(uint16_t, data, pCtx, round, i, step, notNullElems); + CFR_SET_VAL(uint16_t, data, pCtx, round, i, step); break; } case TSDB_DATA_TYPE_TINYINT: { - CFR_SET_VAL(int8_t, data, pCtx, round, i, step, notNullElems); + CFR_SET_VAL(int8_t, data, pCtx, round, i, step); break; } case TSDB_DATA_TYPE_UTINYINT: { - CFR_SET_VAL(uint8_t, data, pCtx, round, i, step, notNullElems); + CFR_SET_VAL(uint8_t, data, pCtx, round, i, step); break; } default: qError("error input type"); } - - if (notNullElems <= 0) { - /* - * current block may be null value - */ - assert(pCtx->hasNull); - } else { - GET_RES_INFO(pCtx)->numOfRes += notNullElems; - } + GET_RES_INFO(pCtx)->numOfRes += pCtx->size; } #undef CFR_SET_VAL -#undef CFR_SET_VAL_DOUBLE ////////////////////////////////////////////////////////////////////////////////// //cumulative_sum function @@ -5412,11 +5290,11 @@ SAggFunctionInfo aAggs[] = {{ "interp", TSDB_FUNC_INTERP, TSDB_FUNC_INTERP, - TSDB_FUNCSTATE_SO | TSDB_FUNCSTATE_OF | TSDB_FUNCSTATE_STABLE | TSDB_FUNCSTATE_NEED_TS , + TSDB_FUNCSTATE_SO | TSDB_FUNCSTATE_OF | TSDB_FUNCSTATE_STABLE | TSDB_FUNCSTATE_NEED_TS | TSDB_FUNCSTATE_SELECTIVITY, function_setup, interp_function, doFinalizer, - copy_function, + full_copy_function, dataBlockRequired, }, { diff --git a/src/query/src/qExecutor.c b/src/query/src/qExecutor.c index 0382dd4ee6e7d42d6a1e6060de76795b05a0b5a5..6a89a2f823ad3ff57807561d7ead4b919851b000 100644 --- a/src/query/src/qExecutor.c +++ b/src/query/src/qExecutor.c @@ -277,7 +277,7 @@ static int compareRowData(const void *a, const void *b, const void *userData) { return (in1 != NULL && in2 != NULL) ? supporter->comFunc(in1, in2) : 0; } -static void sortGroupResByOrderList(SGroupResInfo *pGroupResInfo, SQueryRuntimeEnv *pRuntimeEnv, SSDataBlock* pDataBlock) { +static void sortGroupResByOrderList(SGroupResInfo *pGroupResInfo, SQueryRuntimeEnv *pRuntimeEnv, SSDataBlock* pDataBlock, SQLFunctionCtx *pCtx) { SArray *columnOrderList = getOrderCheckColumns(pRuntimeEnv->pQueryAttr); size_t size = taosArrayGetSize(columnOrderList); taosArrayDestroy(columnOrderList); @@ -291,12 +291,23 @@ static void sortGroupResByOrderList(SGroupResInfo *pGroupResInfo, SQueryRuntimeE return; } + int32_t orderIndex = -1; + for (int32_t j = 0; j < pDataBlock->info.numOfCols; ++j) { + if (pCtx[j].colId == orderId) { + orderIndex = j; + break; + } + } + if (orderIndex < 0) { + return; + } + bool found = false; int16_t dataOffset = 0; for (int32_t j = 0; j < pDataBlock->info.numOfCols; ++j) { SColumnInfoData* pColInfoData = (SColumnInfoData *)taosArrayGet(pDataBlock->pDataBlock, j); - if (orderId == j) { + if (orderIndex == j) { found = true; break; } @@ -308,8 +319,7 @@ static void sortGroupResByOrderList(SGroupResInfo *pGroupResInfo, SQueryRuntimeE return; } - int16_t type = pRuntimeEnv->pQueryAttr->pExpr1[orderId].base.resType; - + int16_t type = pRuntimeEnv->pQueryAttr->pExpr1[orderIndex].base.resType; SRowCompSupporter support = {.pRuntimeEnv = pRuntimeEnv, .dataOffset = dataOffset, .comFunc = getComparFunc(type, 0)}; taosArraySortPWithExt(pGroupResInfo->pRows, compareRowData, &support); } @@ -474,44 +484,6 @@ static void prepareResultListBuffer(SResultRowInfo* pResultRowInfo, SQueryRuntim pResultRowInfo->capacity = (int32_t)newCapacity; } -static bool chkResultRowFromKey(SQueryRuntimeEnv *pRuntimeEnv, SResultRowInfo *pResultRowInfo, char *pData, - int16_t bytes, bool masterscan, uint64_t uid) { - bool existed = false; - SET_RES_WINDOW_KEY(pRuntimeEnv->keyBuf, pData, bytes, uid); - - SResultRow **p1 = - (SResultRow **)taosHashGet(pRuntimeEnv->pResultRowHashTable, pRuntimeEnv->keyBuf, GET_RES_WINDOW_KEY_LEN(bytes)); - - // in case of repeat scan/reverse scan, no new time window added. - if (QUERY_IS_INTERVAL_QUERY(pRuntimeEnv->pQueryAttr)) { - if (!masterscan) { // the *p1 may be NULL in case of sliding+offset exists. - return p1 != NULL; - } - - if (p1 != NULL) { - if (pResultRowInfo->size == 0) { - existed = false; - assert(pResultRowInfo->curPos == -1); - } else if (pResultRowInfo->size == 1) { - existed = (pResultRowInfo->pResult[0] == (*p1)); - } else { // check if current pResultRowInfo contains the existed pResultRow - SET_RES_EXT_WINDOW_KEY(pRuntimeEnv->keyBuf, pData, bytes, uid, pResultRowInfo); - int64_t* index = taosHashGet(pRuntimeEnv->pResultRowListSet, pRuntimeEnv->keyBuf, GET_RES_EXT_WINDOW_KEY_LEN(bytes)); - if (index != NULL) { - existed = true; - } else { - existed = false; - } - } - } - - return existed; - } - - return p1 != NULL; -} - - static SResultRow* doSetResultOutBufByKey(SQueryRuntimeEnv* pRuntimeEnv, SResultRowInfo* pResultRowInfo, int64_t tid, char* pData, int16_t bytes, bool masterscan, uint64_t tableGroupId) { bool existed = false; @@ -658,34 +630,6 @@ static STimeWindow getActiveTimeWindow(SResultRowInfo * pResultRowInfo, int64_t return w; } -// get the correct time window according to the handled timestamp -static STimeWindow getCurrentActiveTimeWindow(SResultRowInfo * pResultRowInfo, int64_t ts, SQueryAttr *pQueryAttr) { - STimeWindow w = {0}; - - if (pResultRowInfo->curPos == -1) { // the first window, from the previous stored value - getInitialStartTimeWindow(pQueryAttr, ts, &w); - - if (pQueryAttr->interval.intervalUnit == 'n' || pQueryAttr->interval.intervalUnit == 'y') { - w.ekey = taosTimeAdd(w.skey, pQueryAttr->interval.interval, pQueryAttr->interval.intervalUnit, pQueryAttr->precision) - 1; - } else { - w.ekey = w.skey + pQueryAttr->interval.interval - 1; - } - } else { - w = getResultRow(pResultRowInfo, pResultRowInfo->curPos)->win; - } - - /* - * query border check, skey should not be bounded by the query time range, since the value skey will - * be used as the time window index value. So we only change ekey of time window accordingly. - */ - if (w.ekey > pQueryAttr->window.ekey && QUERY_IS_ASC_QUERY(pQueryAttr)) { - w.ekey = pQueryAttr->window.ekey; - } - - return w; -} - - // a new buffer page for each table. Needs to opt this design static int32_t addNewWindowResultBuf(SResultRow *pWindowRes, SDiskbasedResultBuf *pResultBuf, int32_t tid, uint32_t size) { @@ -732,13 +676,6 @@ static int32_t addNewWindowResultBuf(SResultRow *pWindowRes, SDiskbasedResultBuf return 0; } -static bool chkWindowOutputBufByKey(SQueryRuntimeEnv *pRuntimeEnv, SResultRowInfo *pResultRowInfo, STimeWindow *win, - bool masterscan, SResultRow **pResult, int64_t groupId, SQLFunctionCtx* pCtx, - int32_t numOfOutput, int32_t* rowCellInfoOffset) { - assert(win->skey <= win->ekey); - - return chkResultRowFromKey(pRuntimeEnv, pResultRowInfo, (char *)&win->skey, TSDB_KEYSIZE, masterscan, groupId); -} static int32_t setResultOutputBufByKey(SQueryRuntimeEnv *pRuntimeEnv, SResultRowInfo *pResultRowInfo, int64_t tid, STimeWindow *win, bool masterscan, SResultRow **pResult, int64_t tableGroupId, SQLFunctionCtx* pCtx, @@ -777,15 +714,6 @@ static void setResultRowInterpo(SResultRow* pResult, SResultTsInterpType type) { } } -static void unsetResultRowInterpo(SResultRow* pResult, SResultTsInterpType type) { - assert(pResult != NULL && (type == RESULT_ROW_START_INTERP || type == RESULT_ROW_END_INTERP)); - if (type == RESULT_ROW_START_INTERP) { - pResult->startInterp = false; - } else { - pResult->endInterp = false; - } -} - static bool resultRowInterpolated(SResultRow* pResult, SResultTsInterpType type) { assert(pResult != NULL && (type == RESULT_ROW_START_INTERP || type == RESULT_ROW_END_INTERP)); @@ -1085,11 +1013,6 @@ static int32_t getNextQualifiedWindow(SQueryAttr* pQueryAttr, STimeWindow *pNext } } - /* interp query with fill should not skip time window */ - if (pQueryAttr->pointInterpQuery && pQueryAttr->fillType != TSDB_FILL_NONE) { - return startPos; - } - /* * This time window does not cover any data, try next time window, * this case may happen when the time window is too small @@ -1184,8 +1107,8 @@ static TSKEY getStartTsKey(SQueryAttr* pQueryAttr, STimeWindow* win, const TSKEY static void setArithParams(SArithmeticSupport* sas, SExprInfo *pExprInfo, SSDataBlock* pSDataBlock) { sas->numOfCols = (int32_t) pSDataBlock->info.numOfCols; sas->pExprInfo = pExprInfo; - if (sas->colList != NULL) { - return; + if (sas->colList) { + free(sas->colList); // free pre malloc memory } sas->colList = calloc(1, pSDataBlock->info.numOfCols*sizeof(SColumnInfo)); for(int32_t i = 0; i < sas->numOfCols; ++i) { @@ -1193,6 +1116,9 @@ static void setArithParams(SArithmeticSupport* sas, SExprInfo *pExprInfo, SSData sas->colList[i] = pColData->info; } + if(sas->data) { + free(sas->data); // free pre malloc memory + } sas->data = calloc(sas->numOfCols, POINTER_BYTES); // set the input column data @@ -1341,24 +1267,18 @@ void doTimeWindowInterpolation(SOperatorInfo* pOperator, SOptrBasicInfo* pInfo, int16_t index = pColIndex->colIndex; SColumnInfoData *pColInfo = taosArrayGet(pDataBlock, index); - assert(pColInfo->info.colId == pColIndex->colId && curTs != windowKey); + assert(pColInfo->info.colId <= TSDB_RES_COL_ID || (pColInfo->info.colId >= 0 && pColInfo->info.colId == pColIndex->colId)); double v1 = 0, v2 = 0, v = 0; - if (prevRowIndex == -1) { - GET_TYPED_DATA(v1, double, pColInfo->info.type, (char *)pRuntimeEnv->prevRow[index]); - } else { - GET_TYPED_DATA(v1, double, pColInfo->info.type, (char *)pColInfo->pData + prevRowIndex * pColInfo->info.bytes); - } - - GET_TYPED_DATA(v2, double, pColInfo->info.type, (char *)pColInfo->pData + curRowIndex * pColInfo->info.bytes); - if (functionId == TSDB_FUNC_INTERP) { if (type == RESULT_ROW_START_INTERP) { + if (prevRowIndex == -1) { + COPY_DATA(&pCtx[k].start.val, (char *)pRuntimeEnv->prevRow[index]); + } else { + COPY_DATA(&pCtx[k].start.val, (char *)pColInfo->pData + prevRowIndex * pColInfo->info.bytes); + } + pCtx[k].start.key = prevTs; - pCtx[k].start.val = v1; - - pCtx[k].end.key = curTs; - pCtx[k].end.val = v2; if (pColInfo->info.type == TSDB_DATA_TYPE_BINARY || pColInfo->info.type == TSDB_DATA_TYPE_NCHAR) { if (prevRowIndex == -1) { @@ -1366,16 +1286,38 @@ void doTimeWindowInterpolation(SOperatorInfo* pOperator, SOptrBasicInfo* pInfo, } else { pCtx[k].start.ptr = (char *)pColInfo->pData + prevRowIndex * pColInfo->info.bytes; } + } + + } else { + if (curRowIndex == -1) { + COPY_DATA(&pCtx[k].end.val, pRuntimeEnv->prevRow[index]); + } else { + COPY_DATA(&pCtx[k].end.val, (char *)pColInfo->pData + curRowIndex * pColInfo->info.bytes); + } + + pCtx[k].end.key = curTs; + if (pColInfo->info.type == TSDB_DATA_TYPE_BINARY || pColInfo->info.type == TSDB_DATA_TYPE_NCHAR) { pCtx[k].end.ptr = (char *)pColInfo->pData + curRowIndex * pColInfo->info.bytes; } } } else if (functionId == TSDB_FUNC_TWA) { + assert(curTs != windowKey); + + if (prevRowIndex == -1) { + GET_TYPED_DATA(v1, double, pColInfo->info.type, (char *)pRuntimeEnv->prevRow[index]); + } else { + GET_TYPED_DATA(v1, double, pColInfo->info.type, (char *)pColInfo->pData + prevRowIndex * pColInfo->info.bytes); + } + + GET_TYPED_DATA(v2, double, pColInfo->info.type, (char *)pColInfo->pData + curRowIndex * pColInfo->info.bytes); + SPoint point1 = (SPoint){.key = prevTs, .val = &v1}; SPoint point2 = (SPoint){.key = curTs, .val = &v2}; SPoint point = (SPoint){.key = windowKey, .val = &v }; - taosGetLinearInterpolationVal(&point, TSDB_DATA_TYPE_DOUBLE, &point1, &point2, TSDB_DATA_TYPE_DOUBLE); + bool exceedMax = false, exceedMin = false; + taosGetLinearInterpolationVal(&point, TSDB_DATA_TYPE_DOUBLE, &point1, &point2, TSDB_DATA_TYPE_DOUBLE, &exceedMax, &exceedMin); if (type == RESULT_ROW_START_INTERP) { pCtx[k].start.key = point.key; @@ -1486,11 +1428,6 @@ static void doWindowBorderInterpolation(SOperatorInfo* pOperatorInfo, SSDataBloc setNotInterpoWindowKey(pCtx, pQueryAttr->numOfOutput, RESULT_ROW_START_INTERP); } - // point interpolation does not require the end key time window interpolation. - if (pQueryAttr->pointInterpQuery) { - return; - } - // interpolation query does not generate the time window end interpolation done = resultRowInterpolated(pResult, RESULT_ROW_END_INTERP); if (!done) { @@ -1616,93 +1553,6 @@ static void hashIntervalAgg(SOperatorInfo* pOperatorInfo, SResultRowInfo* pResul } -static void hashAllIntervalAgg(SOperatorInfo* pOperatorInfo, SResultRowInfo* pResultRowInfo, SSDataBlock* pSDataBlock, int32_t tableGroupId) { - STableIntervalOperatorInfo* pInfo = (STableIntervalOperatorInfo*) pOperatorInfo->info; - - SQueryRuntimeEnv* pRuntimeEnv = pOperatorInfo->pRuntimeEnv; - int32_t numOfOutput = pOperatorInfo->numOfOutput; - SQueryAttr* pQueryAttr = pRuntimeEnv->pQueryAttr; - - int32_t step = GET_FORWARD_DIRECTION_FACTOR(pQueryAttr->order.order); - bool ascQuery = QUERY_IS_ASC_QUERY(pQueryAttr); - - TSKEY* tsCols = NULL; - if (pSDataBlock->pDataBlock != NULL) { - SColumnInfoData* pColDataInfo = taosArrayGet(pSDataBlock->pDataBlock, 0); - tsCols = (int64_t*) pColDataInfo->pData; - assert(tsCols[0] == pSDataBlock->info.window.skey && - tsCols[pSDataBlock->info.rows - 1] == pSDataBlock->info.window.ekey); - } - - int32_t startPos = ascQuery? 0 : (pSDataBlock->info.rows - 1); - int32_t ostartPos = 0; - TSKEY ts = getStartTsKey(pQueryAttr, &pSDataBlock->info.window, tsCols, pSDataBlock->info.rows); - - STimeWindow win = getCurrentActiveTimeWindow(pResultRowInfo, ts, pQueryAttr); - bool masterScan = IS_MASTER_SCAN(pRuntimeEnv); - - SResultRow* pResult = NULL; - int32_t forwardStep = 0; - int32_t ret = 0; - //STimeWindow preWin = win; - - while (1) { - // null data, failed to allocate more memory buffer - ret = setResultOutputBufByKey(pRuntimeEnv, pResultRowInfo, pSDataBlock->info.tid, &win, masterScan, &pResult, - tableGroupId, pInfo->pCtx, numOfOutput, pInfo->rowCellInfoOffset); - if (ret != TSDB_CODE_SUCCESS) { - longjmp(pRuntimeEnv->env, TSDB_CODE_QRY_OUT_OF_MEMORY); - } - - TSKEY ekey = reviseWindowEkey(pQueryAttr, &win); - forwardStep = getNumOfRowsInTimeWindow(pRuntimeEnv, &pSDataBlock->info, tsCols, startPos, ekey, binarySearchForKey, true); - - // window start(end) key interpolation - unsetResultRowInterpo(pResult, RESULT_ROW_START_INTERP); - ostartPos = startPos; - - if (!ascQuery) { - startPos += forwardStep * step; - } - - doWindowBorderInterpolation(pOperatorInfo, pSDataBlock, pInfo->pCtx, pResult, &win, startPos, forwardStep); - doApplyFunctions(pRuntimeEnv, pInfo->pCtx, &win, ostartPos, forwardStep, tsCols, pSDataBlock->info.rows, numOfOutput); - - int32_t prevEndPos = (!ascQuery) ? startPos - step : (forwardStep - 1) * step + startPos; - startPos = getNextQualifiedWindow(pQueryAttr, &win, &pSDataBlock->info, tsCols, binarySearchForKey, prevEndPos); - if (startPos < 0) { - if ((ascQuery && win.skey <= pQueryAttr->window.ekey) || ((!ascQuery) && win.ekey >= pQueryAttr->window.ekey)) { - int32_t code = setResultOutputBufByKey(pRuntimeEnv, pResultRowInfo, pSDataBlock->info.tid, &win, masterScan, &pResult, tableGroupId, - pInfo->pCtx, numOfOutput, pInfo->rowCellInfoOffset); - if (code != TSDB_CODE_SUCCESS || pResult == NULL) { - longjmp(pRuntimeEnv->env, TSDB_CODE_QRY_OUT_OF_MEMORY); - } - - if (ascQuery) { - startPos = pSDataBlock->info.rows - 1; - } else { - startPos = 0; - } - - forwardStep = 1; - unsetResultRowInterpo(pResult, RESULT_ROW_START_INTERP); - setNotInterpoWindowKey(pInfo->pCtx, pQueryAttr->numOfOutput, RESULT_ROW_START_INTERP); - doApplyFunctions(pRuntimeEnv, pInfo->pCtx, &win, startPos, forwardStep, tsCols, pSDataBlock->info.rows, numOfOutput); - } - - break; - } - setResultRowInterpo(pResult, RESULT_ROW_END_INTERP); - } - - if (pQueryAttr->timeWindowInterpo) { - int32_t rowIndex = ascQuery? (pSDataBlock->info.rows-1):0; - saveDataBlockLastRow(pRuntimeEnv, &pSDataBlock->info, pSDataBlock->pDataBlock, rowIndex); - } - - updateResultRowInfoActiveIndex(pResultRowInfo, pQueryAttr, pRuntimeEnv->current->lastKey); -} - static void doHashGroupbyAgg(SOperatorInfo* pOperator, SGroupbyOperatorInfo *pInfo, SSDataBlock *pSDataBlock) { @@ -2065,6 +1915,7 @@ static SQLFunctionCtx* createSQLFunctionCtx(SQueryRuntimeEnv* pRuntimeEnv, SExpr pCtx->interBufBytes = pSqlExpr->interBytes; pCtx->start.key = INT64_MIN; pCtx->end.key = INT64_MIN; + pCtx->startTs = INT64_MIN; pCtx->numOfParams = pSqlExpr->numOfParams; for (int32_t j = 0; j < pCtx->numOfParams; ++j) { @@ -2202,12 +2053,6 @@ static int32_t setupQueryRuntimeEnv(SQueryRuntimeEnv *pRuntimeEnv, int32_t numOf setTableScanFilterOperatorInfo(pRuntimeEnv->proot->upstream[0]->info, pRuntimeEnv->proot); break; } - case OP_AllMultiTableTimeInterval: { - pRuntimeEnv->proot = - createAllMultiTableTimeIntervalOperatorInfo(pRuntimeEnv, pRuntimeEnv->proot, pQueryAttr->pExpr1, pQueryAttr->numOfOutput); - setTableScanFilterOperatorInfo(pRuntimeEnv->proot->upstream[0]->info, pRuntimeEnv->proot); - break; - } case OP_TimeWindow: { pRuntimeEnv->proot = createTimeIntervalOperatorInfo(pRuntimeEnv, pRuntimeEnv->proot, pQueryAttr->pExpr1, pQueryAttr->numOfOutput); @@ -2217,9 +2062,9 @@ static int32_t setupQueryRuntimeEnv(SQueryRuntimeEnv *pRuntimeEnv, int32_t numOf } break; } - case OP_AllTimeWindow: { + case OP_TimeEvery: { pRuntimeEnv->proot = - createAllTimeIntervalOperatorInfo(pRuntimeEnv, pRuntimeEnv->proot, pQueryAttr->pExpr1, pQueryAttr->numOfOutput); + createTimeEveryOperatorInfo(pRuntimeEnv, pRuntimeEnv->proot, pQueryAttr->pExpr1, pQueryAttr->numOfOutput); int32_t opType = pRuntimeEnv->proot->upstream[0]->operatorType; if (opType != OP_DummyInput && opType != OP_Join) { setTableScanFilterOperatorInfo(pRuntimeEnv->proot->upstream[0]->info, pRuntimeEnv->proot); @@ -2711,12 +2556,23 @@ static void updateDataCheckOrder(SQInfo *pQInfo, SQueryTableMsg* pQueryMsg, bool if (!QUERY_IS_ASC_QUERY(pQueryAttr)) { qDebug(msg, pQInfo->qId, "interp", pQueryAttr->order.order, TSDB_ORDER_ASC, pQueryAttr->window.skey, pQueryAttr->window.ekey, pQueryAttr->window.ekey, pQueryAttr->window.skey); SWAP(pQueryAttr->window.skey, pQueryAttr->window.ekey, TSKEY); + doUpdateLastKey(pQueryAttr); } pQueryAttr->order.order = TSDB_ORDER_ASC; return; } + if (pQueryAttr->pointInterpQuery && pQueryAttr->interval.interval > 0 && (!QUERY_IS_ASC_QUERY(pQueryAttr)) && pQueryAttr->range.skey == INT64_MIN) { + qDebug(msg, pQInfo->qId, "interp", pQueryAttr->order.order, TSDB_ORDER_ASC, pQueryAttr->window.skey, pQueryAttr->window.ekey, pQueryAttr->window.ekey, pQueryAttr->window.skey); + SWAP(pQueryAttr->window.skey, pQueryAttr->window.ekey, TSKEY); + + pQueryAttr->order.order = TSDB_ORDER_ASC; + doUpdateLastKey(pQueryAttr); + pQueryAttr->needReverseScan = true; + return; + } + if (pQueryAttr->interval.interval == 0) { if (onlyFirstQuery(pQueryAttr)) { if (!QUERY_IS_ASC_QUERY(pQueryAttr)) { @@ -3173,39 +3029,27 @@ int32_t loadDataBlockOnDemand(SQueryRuntimeEnv* pRuntimeEnv, STableScanInfo* pTa // check if this data block is required to load if ((*status) != BLK_DATA_ALL_NEEDED) { - bool needFilter = true; - // the pCtx[i] result is belonged to previous time window since the outputBuf has not been set yet, // the filter result may be incorrect. So in case of interval query, we need to set the correct time output buffer - if (QUERY_IS_INTERVAL_QUERY(pQueryAttr)) { + if (QUERY_IS_INTERVAL_QUERY(pQueryAttr) && (!pQueryAttr->pointInterpQuery)) { SResultRow* pResult = NULL; bool masterScan = IS_MASTER_SCAN(pRuntimeEnv); TSKEY k = ascQuery? pBlock->info.window.skey : pBlock->info.window.ekey; STimeWindow win = getActiveTimeWindow(pTableScanInfo->pResultRowInfo, k, pQueryAttr); - if (pQueryAttr->pointInterpQuery) { - needFilter = chkWindowOutputBufByKey(pRuntimeEnv, pTableScanInfo->pResultRowInfo, &win, masterScan, &pResult, groupId, - pTableScanInfo->pCtx, pTableScanInfo->numOfOutput, - pTableScanInfo->rowCellInfoOffset); - } else { - if (setResultOutputBufByKey(pRuntimeEnv, pTableScanInfo->pResultRowInfo, pBlock->info.tid, &win, masterScan, &pResult, groupId, - pTableScanInfo->pCtx, pTableScanInfo->numOfOutput, - pTableScanInfo->rowCellInfoOffset) != TSDB_CODE_SUCCESS) { - longjmp(pRuntimeEnv->env, TSDB_CODE_QRY_OUT_OF_MEMORY); - } + if (setResultOutputBufByKey(pRuntimeEnv, pTableScanInfo->pResultRowInfo, pBlock->info.tid, &win, masterScan, &pResult, groupId, + pTableScanInfo->pCtx, pTableScanInfo->numOfOutput, + pTableScanInfo->rowCellInfoOffset) != TSDB_CODE_SUCCESS) { + longjmp(pRuntimeEnv->env, TSDB_CODE_QRY_OUT_OF_MEMORY); } - } else if (pQueryAttr->stableQuery && (!pQueryAttr->tsCompQuery) && (!pQueryAttr->diffQuery)) { // stable aggregate, not interval aggregate or normal column aggregate + } else if (pQueryAttr->stableQuery && (!pQueryAttr->tsCompQuery) && (!pQueryAttr->diffQuery) && (!pQueryAttr->pointInterpQuery)) { // stable aggregate, not interval aggregate or normal column aggregate doSetTableGroupOutputBuf(pRuntimeEnv, pTableScanInfo->pResultRowInfo, pTableScanInfo->pCtx, pTableScanInfo->rowCellInfoOffset, pTableScanInfo->numOfOutput, pRuntimeEnv->current->groupIndex); } - if (needFilter) { - (*status) = doFilterByBlockTimeWindow(pTableScanInfo, pBlock); - } else { - (*status) = BLK_DATA_ALL_NEEDED; - } + (*status) = doFilterByBlockTimeWindow(pTableScanInfo, pBlock); } SDataBlockInfo* pBlockInfo = &pBlock->info; @@ -3686,6 +3530,9 @@ void setDefaultOutputBuf(SQueryRuntimeEnv *pRuntimeEnv, SOptrBasicInfo *pInfo, i if (fid == TSDB_FUNC_TOP || fid == TSDB_FUNC_BOTTOM || fid == TSDB_FUNC_DIFF || fid == TSDB_FUNC_DERIVATIVE || fid == TSDB_FUNC_SAMPLE || fid == TSDB_FUNC_MAVG || fid == TSDB_FUNC_CSUM) { if (i > 0) pCtx[i].ptsOutputBuf = pCtx[i-1].pOutput; + } else if (fid == TSDB_FUNC_INTERP) { + assert(pCtx[0].functionId == TSDB_FUNC_TS_DUMMY || pCtx[0].functionId == TSDB_FUNC_TS); + pCtx[i].ptsOutputBuf = pCtx[0].pOutput; } } @@ -3726,12 +3573,15 @@ void updateOutputBuf(SOptrBasicInfo* pBInfo, int32_t *bufCapacity, int32_t numOf functionId == TSDB_FUNC_CSUM || functionId == TSDB_FUNC_MAVG || functionId == TSDB_FUNC_SAMPLE ) { if (i > 0) pBInfo->pCtx[i].ptsOutputBuf = pBInfo->pCtx[i-1].pOutput; + } else if (functionId == TSDB_FUNC_INTERP) { + assert(pBInfo->pCtx[0].functionId == TSDB_FUNC_TS_DUMMY || pBInfo->pCtx[0].functionId == TSDB_FUNC_TS); + pBInfo->pCtx[i].ptsOutputBuf = pBInfo->pCtx[0].pOutput; } } } void copyTsColoum(SSDataBlock* pRes, SQLFunctionCtx* pCtx, int32_t numOfOutput) { - bool needCopyTs = false; + bool interpQuery = false; int32_t tsNum = 0; char *src = NULL; for (int32_t i = 0; i < numOfOutput; i++) { @@ -3739,18 +3589,21 @@ void copyTsColoum(SSDataBlock* pRes, SQLFunctionCtx* pCtx, int32_t numOfOutput) if (functionId == TSDB_FUNC_DIFF || functionId == TSDB_FUNC_DERIVATIVE || functionId == TSDB_FUNC_MAVG || functionId == TSDB_FUNC_CSUM || functionId == TSDB_FUNC_SAMPLE) { - needCopyTs = true; if (i > 0 && pCtx[i-1].functionId == TSDB_FUNC_TS_DUMMY){ SColumnInfoData* pColRes = taosArrayGet(pRes->pDataBlock, i - 1); // find ts data src = pColRes->pData; } - }else if(functionId == TSDB_FUNC_TS_DUMMY) { + } else if(functionId == TSDB_FUNC_INTERP) { + assert(pCtx[0].functionId == TSDB_FUNC_TS); + SColumnInfoData* pColRes = taosArrayGet(pRes->pDataBlock, 0); // find ts data + src = pColRes->pData; + interpQuery = true; + } else if(functionId == TSDB_FUNC_TS_DUMMY) { tsNum++; } } - if (!needCopyTs) return; - if (tsNum < 2) return; + if ((interpQuery == false && tsNum < 2) || (interpQuery && tsNum <= 0)) return; if (src == NULL) return; for (int32_t i = 0; i < numOfOutput; i++) { @@ -4804,7 +4657,7 @@ static int32_t setupQueryHandle(void* tsdb, SQueryRuntimeEnv* pRuntimeEnv, int64 STsdbQueryCond cond = createTsdbQueryCond(pQueryAttr, &pQueryAttr->window); if (pQueryAttr->tsCompQuery || pQueryAttr->pointInterpQuery) { - cond.type = BLOCK_LOAD_TABLE_SEQ_ORDER; + cond.type = BLOCK_LOAD_TABLE_SEQ_ORDER; } if (!isSTableQuery @@ -4931,7 +4784,9 @@ int32_t doInitQInfo(SQInfo* pQInfo, STSBuf* pTsBuf, void* tsdb, void* sourceOptr if (pTsBuf != NULL) { int16_t order = (pQueryAttr->order.order == pRuntimeEnv->pTsBuf->tsOrder) ? TSDB_ORDER_ASC : TSDB_ORDER_DESC; + tsBufResetPos(pRuntimeEnv->pTsBuf); tsBufSetTraverseOrder(pRuntimeEnv->pTsBuf, order); + tsBufNextPos(pTsBuf); } int32_t ps = DEFAULT_PAGE_SIZE; @@ -5036,6 +4891,17 @@ static void doCloseAllTimeWindow(SQueryRuntimeEnv* pRuntimeEnv) { } } +static void notifyTableScan(void* param, int32_t option) { + SOperatorInfo *pOperator = (SOperatorInfo*) param; + STableScanInfo *pTableScanInfo = pOperator->info; + + if (option == OPTION_SWITCH_TABLE) { + tsdbSwitchTable(pTableScanInfo->pQueryHandle); + } + + return; +} + static SSDataBlock* doTableScanImpl(void* param, bool* newgroup) { SOperatorInfo *pOperator = (SOperatorInfo*) param; @@ -5295,13 +5161,18 @@ void setTableScanFilterOperatorInfo(STableScanInfo* pTableScanInfo, SOperatorInf pTableScanInfo->pCtx = pAggInfo->binfo.pCtx; pTableScanInfo->pResultRowInfo = &pAggInfo->binfo.resultRowInfo; pTableScanInfo->rowCellInfoOffset = pAggInfo->binfo.rowCellInfoOffset; - } else if (pDownstream->operatorType == OP_TimeWindow || pDownstream->operatorType == OP_AllTimeWindow) { + } else if (pDownstream->operatorType == OP_TimeWindow) { STableIntervalOperatorInfo *pIntervalInfo = pDownstream->info; pTableScanInfo->pCtx = pIntervalInfo->pCtx; pTableScanInfo->pResultRowInfo = &pIntervalInfo->resultRowInfo; pTableScanInfo->rowCellInfoOffset = pIntervalInfo->rowCellInfoOffset; - + } else if (pDownstream->operatorType == OP_TimeEvery) { + STimeEveryOperatorInfo *pEveryInfo = pDownstream->info; + + pTableScanInfo->pCtx = pEveryInfo->binfo.pCtx; + pTableScanInfo->pResultRowInfo = &pEveryInfo->binfo.resultRowInfo; + pTableScanInfo->rowCellInfoOffset = pEveryInfo->binfo.rowCellInfoOffset; } else if (pDownstream->operatorType == OP_Groupby) { SGroupbyOperatorInfo *pGroupbyInfo = pDownstream->info; @@ -5349,6 +5220,10 @@ SOperatorInfo* createDataBlocksOptScanInfo(void* pTsdbQueryHandle, SQueryRuntime pInfo->current = 0; pInfo->order = pRuntimeEnv->pQueryAttr->order.order; + if (pRuntimeEnv->pQueryAttr->pointInterpQuery) { + pRuntimeEnv->enableGroupData = true; + } + SOperatorInfo* pOptr = calloc(1, sizeof(SOperatorInfo)); pOptr->name = "DataBlocksOptimizedScanOperator"; pOptr->operatorType = OP_DataBlocksOptScan; @@ -5356,6 +5231,7 @@ SOperatorInfo* createDataBlocksOptScanInfo(void* pTsdbQueryHandle, SQueryRuntime pOptr->blockingOptr = false; pOptr->info = pInfo; pOptr->exec = doTableScan; + pOptr->notify = notifyTableScan; return pOptr; } @@ -5834,6 +5710,11 @@ static SSDataBlock* doProjectOperation(void* param, bool* newgroup) { } } + if (pOperator->status == OP_EXEC_DONE) { + *newgroup = false; + return NULL; + } + while(1) { bool prevVal = *newgroup; @@ -5846,7 +5727,7 @@ static SSDataBlock* doProjectOperation(void* param, bool* newgroup) { //assert(*newgroup == false); *newgroup = prevVal; - setQueryStatus(pRuntimeEnv, QUERY_COMPLETED); + doSetOperatorCompleted(pOperator); break; } @@ -6047,127 +5928,477 @@ static SSDataBlock* doIntervalAgg(void* param, bool* newgroup) { return pIntervalInfo->pRes->info.rows == 0? NULL:pIntervalInfo->pRes; } -static SSDataBlock* doAllIntervalAgg(void* param, bool* newgroup) { - SOperatorInfo* pOperator = (SOperatorInfo*) param; - if (pOperator->status == OP_EXEC_DONE) { - return NULL; +static void everyApplyFunctions(SQueryRuntimeEnv *pRuntimeEnv, SQLFunctionCtx *pCtx, int32_t numOfOutput) { + for (int32_t k = 0; k < numOfOutput; ++k) { + if (pCtx[k].functionId < 0) { + // load the script and exec + SUdfInfo* pUdfInfo = pRuntimeEnv->pUdfInfo; + doInvokeUdf(pUdfInfo, &pCtx[k], 0, TSDB_UDF_FUNC_NORMAL); + } else { + aAggs[pCtx[k].functionId].xFunction(&pCtx[k]); + } } +} - STableIntervalOperatorInfo* pIntervalInfo = pOperator->info; +static int64_t getEveryStartTs(bool ascQuery, STimeWindow *range, STimeWindow *blockWin, SQueryAttr *pQueryAttr) { + int64_t startTs = range->skey, ekey = 0; + + assert(range->skey != INT64_MIN); - SQueryRuntimeEnv* pRuntimeEnv = pOperator->pRuntimeEnv; - if (pOperator->status == OP_RES_TO_RETURN) { - toSSDataBlock(&pRuntimeEnv->groupResInfo, pRuntimeEnv, pIntervalInfo->pRes); + if (ascQuery) { + return startTs; + } - if (pIntervalInfo->pRes->info.rows == 0 || !hasRemainDataInCurrentGroup(&pRuntimeEnv->groupResInfo)) { - doSetOperatorCompleted(pOperator); - } + if (range->ekey != INT64_MIN) { + ekey = range->ekey; + } else { + ekey = blockWin->ekey; + } - return pIntervalInfo->pRes; + if (pQueryAttr->interval.interval > 0) { + if (pQueryAttr->interval.intervalUnit == 'n' || pQueryAttr->interval.intervalUnit == 'y') { + int64_t lastTs = startTs; + while (startTs < ekey) { + lastTs = startTs; + startTs = taosTimeAdd(startTs, pQueryAttr->interval.interval, pQueryAttr->interval.intervalUnit, pQueryAttr->precision); + } + startTs = lastTs; + } else { + startTs = startTs + (ekey - startTs)/pQueryAttr->interval.interval * pQueryAttr->interval.interval; + } } + return startTs; +} + +static bool doEveryInterpolation(SOperatorInfo* pOperatorInfo, SSDataBlock* pBlock, bool *needApply) { + SQueryRuntimeEnv* pRuntimeEnv = pOperatorInfo->pRuntimeEnv; + STimeEveryOperatorInfo* pEveryInfo = (STimeEveryOperatorInfo*)pOperatorInfo->info; SQueryAttr* pQueryAttr = pRuntimeEnv->pQueryAttr; - int32_t order = pQueryAttr->order.order; - STimeWindow win = pQueryAttr->window; + bool ascQuery = QUERY_IS_ASC_QUERY(pQueryAttr); + int32_t gidx = pRuntimeEnv->current->groupIndex; + SQLFunctionCtx* pCtx = NULL; - SOperatorInfo* upstream = pOperator->upstream[0]; + *needApply = false; + + if (!pQueryAttr->pointInterpQuery) { + goto group_finished_exit; + } - while(1) { - publishOperatorProfEvent(upstream, QUERY_PROF_BEFORE_OPERATOR_EXEC); - SSDataBlock* pBlock = upstream->exec(upstream, newgroup); - publishOperatorProfEvent(upstream, QUERY_PROF_AFTER_OPERATOR_EXEC); + assert(pOperatorInfo->numOfOutput > 1); + + for (int32_t i = 1; i < pOperatorInfo->numOfOutput; ++i) { + assert(pEveryInfo->binfo.pCtx[i].functionId == TSDB_FUNC_INTERP + || pEveryInfo->binfo.pCtx[i].functionId == TSDB_FUNC_TS_DUMMY + || pEveryInfo->binfo.pCtx[i].functionId == TSDB_FUNC_TAG_DUMMY); - if (pBlock == NULL) { + if (pEveryInfo->binfo.pCtx[i].functionId == TSDB_FUNC_INTERP) { + pCtx = &pEveryInfo->binfo.pCtx[i]; break; } - - setTagValue(pOperator, pRuntimeEnv->current->pTable, pIntervalInfo->pCtx, pOperator->numOfOutput); - - // the pDataBlock are always the same one, no need to call this again - setInputDataBlock(pOperator, pIntervalInfo->pCtx, pBlock, pQueryAttr->order.order); - hashAllIntervalAgg(pOperator, &pIntervalInfo->resultRowInfo, pBlock, 0); + } + + TSKEY* tsCols = NULL; + if (pBlock && pBlock->pDataBlock != NULL) { + SColumnInfoData* pColDataInfo = taosArrayGet(pBlock->pDataBlock, 0); + tsCols = (int64_t*) pColDataInfo->pData; + assert(tsCols[0] == pBlock->info.window.skey && tsCols[pBlock->info.rows - 1] == pBlock->info.window.ekey); } - // restore the value - pQueryAttr->order.order = order; - pQueryAttr->window = win; + if (pCtx->startTs == INT64_MIN) { + if (pQueryAttr->range.skey == INT64_MIN) { + if (NULL == tsCols) { + goto group_finished_exit; + } - pOperator->status = OP_RES_TO_RETURN; - closeAllResultRows(&pIntervalInfo->resultRowInfo); - setQueryStatus(pRuntimeEnv, QUERY_COMPLETED); - finalizeQueryResult(pOperator, pIntervalInfo->pCtx, &pIntervalInfo->resultRowInfo, pIntervalInfo->rowCellInfoOffset); + if (ascQuery) { + if (pQueryAttr->needReverseScan) { + assert(pEveryInfo->rangeStart); + taosHashPut(pEveryInfo->rangeStart, &pBlock->info.tid, sizeof(pBlock->info.tid), tsCols, sizeof(*tsCols)); + goto group_finished_exit; + } else { + pCtx->startTs = tsCols[0]; + } + } else { + assert(pEveryInfo->rangeStart); + TSKEY * rstart = taosHashGet(pEveryInfo->rangeStart, &pBlock->info.tid, sizeof(pBlock->info.tid)); + if (rstart) { + pQueryAttr->range.skey = *rstart; - initGroupResInfo(&pRuntimeEnv->groupResInfo, &pIntervalInfo->resultRowInfo); - toSSDataBlock(&pRuntimeEnv->groupResInfo, pRuntimeEnv, pIntervalInfo->pRes); + pCtx->startTs = getEveryStartTs(ascQuery, &pQueryAttr->range, &pBlock->info.window, pQueryAttr); + } else { + goto group_finished_exit; + } + } + } else { + pCtx->startTs = getEveryStartTs(ascQuery, &pQueryAttr->range, &pBlock->info.window, pQueryAttr); + } - if (pIntervalInfo->pRes->info.rows == 0 || !hasRemainDataInCurrentGroup(&pRuntimeEnv->groupResInfo)) { - pOperator->status = OP_EXEC_DONE; + pCtx->endTs = INT64_MIN; + } else if (pCtx->endTs == pCtx->startTs) { + if (pQueryAttr->interval.interval > 0) { + if (pQueryAttr->interval.intervalUnit == 'n' || pQueryAttr->interval.intervalUnit == 'y') { + if (ascQuery) { + pCtx->startTs = taosTimeAdd(pCtx->startTs, pQueryAttr->interval.interval, pQueryAttr->interval.intervalUnit, pQueryAttr->precision); + } else { + pCtx->startTs = taosTimeSub(pCtx->startTs, pQueryAttr->interval.interval, pQueryAttr->interval.intervalUnit, pQueryAttr->precision); + } + } else { + pCtx->startTs = ascQuery ? pCtx->startTs + pQueryAttr->interval.interval : pCtx->startTs - pQueryAttr->interval.interval; + } + + if (ascQuery && pQueryAttr->range.ekey != INT64_MIN && pCtx->startTs > pQueryAttr->range.ekey) { + goto group_finished_exit; + } + + if ((!ascQuery) && pQueryAttr->range.skey != INT64_MIN && pCtx->startTs < pQueryAttr->range.skey) { + goto group_finished_exit; + } + } else { + goto group_finished_exit; + } + + pCtx->endTs = INT64_MIN; } - return pIntervalInfo->pRes->info.rows == 0? NULL:pIntervalInfo->pRes; + if (tsCols == NULL && ((ascQuery && pCtx->startTs > pEveryInfo->tableEndKey) || ((!ascQuery) && pCtx->startTs < pEveryInfo->tableEndKey))) { + if ((ascQuery && pQueryAttr->range.ekey == INT64_MIN) || ((!ascQuery) && pQueryAttr->range.skey == INT64_MIN)) { + goto group_finished_exit; + } + + if (pQueryAttr->fillType == TSDB_FILL_NONE || pQueryAttr->fillType == TSDB_FILL_LINEAR + || ((ascQuery && pQueryAttr->fillType == TSDB_FILL_NEXT) || ((!ascQuery) && pQueryAttr->fillType == TSDB_FILL_PREV))) { + goto group_finished_exit; + } + + if (ascQuery && pQueryAttr->fillType == TSDB_FILL_PREV) { + TSKEY lastTs = *(TSKEY *) pRuntimeEnv->prevRow[0]; + if (lastTs != INT64_MIN) { + doTimeWindowInterpolation(pOperatorInfo, pOperatorInfo->info, pEveryInfo->binfo.pRes->pDataBlock, lastTs, -1, INT64_MIN, 0, 0, RESULT_ROW_START_INTERP); + } else { + goto group_finished_exit; + } + } else if ((!ascQuery) && pQueryAttr->fillType == TSDB_FILL_NEXT) { + TSKEY lastTs = *(TSKEY *) pRuntimeEnv->prevRow[0]; + if (lastTs != INT64_MIN) { + doTimeWindowInterpolation(pOperatorInfo, pOperatorInfo->info, pEveryInfo->binfo.pRes->pDataBlock, INT64_MIN, 0, lastTs, -1, 0, RESULT_ROW_END_INTERP); + } else { + goto group_finished_exit; + } + } + + *needApply = true; + + for (int32_t i = 0; i < pOperatorInfo->numOfOutput; ++i) { + pEveryInfo->binfo.pCtx[i].startTs = pCtx->startTs; + } + + return false; + } + + + int32_t startPos = binarySearchForKey((char *)tsCols, pBlock->info.rows, pCtx->startTs, pQueryAttr->order.order); + + if (ascQuery && pQueryAttr->fillType != TSDB_FILL_NEXT && pCtx->start.key == INT64_MIN) { + if (startPos < 0) { + saveDataBlockLastRow(pRuntimeEnv, &pBlock->info, pBlock->pDataBlock, pBlock->info.rows - 1); + return true; + } else if (startPos == 0) { + if (tsCols[startPos] == pCtx->startTs) { + doTimeWindowInterpolation(pOperatorInfo, pOperatorInfo->info, pBlock->pDataBlock, pCtx->startTs, startPos, INT64_MIN, 0, 0, RESULT_ROW_START_INTERP); + } else { + TSKEY lastTs = *(TSKEY *) pRuntimeEnv->prevRow[0]; + if (lastTs != INT64_MIN) { + doTimeWindowInterpolation(pOperatorInfo, pOperatorInfo->info, pBlock->pDataBlock, lastTs, -1, INT64_MIN, 0, 0, RESULT_ROW_START_INTERP); + } + } + } else { + if (tsCols[startPos] == pCtx->startTs) { + doTimeWindowInterpolation(pOperatorInfo, pOperatorInfo->info, pBlock->pDataBlock, pCtx->startTs, startPos, INT64_MIN, 0, 0, RESULT_ROW_START_INTERP); + } else { + doTimeWindowInterpolation(pOperatorInfo, pOperatorInfo->info, pBlock->pDataBlock, tsCols[startPos - 1], startPos - 1, INT64_MIN, 0, 0, RESULT_ROW_START_INTERP); + } + } + + if (pQueryAttr->fillType != TSDB_FILL_LINEAR) { + *needApply = true; + } + } + + if ((!ascQuery) && (pQueryAttr->fillType == TSDB_FILL_LINEAR || pQueryAttr->fillType == TSDB_FILL_NEXT) && pCtx->end.key == INT64_MIN) { + if (startPos < 0) { + saveDataBlockLastRow(pRuntimeEnv, &pBlock->info, pBlock->pDataBlock, 0); + return true; + } else if (startPos == (pBlock->info.rows - 1)) { + if (tsCols[startPos] == pCtx->startTs) { + doTimeWindowInterpolation(pOperatorInfo, pOperatorInfo->info, pBlock->pDataBlock, INT64_MIN, 0, pCtx->startTs, startPos, 0, RESULT_ROW_END_INTERP); + } else { + TSKEY lastTs = *(TSKEY *) pRuntimeEnv->prevRow[0]; + if (lastTs != INT64_MIN) { + doTimeWindowInterpolation(pOperatorInfo, pOperatorInfo->info, pBlock->pDataBlock, INT64_MIN, 0, lastTs, -1, 0, RESULT_ROW_END_INTERP); + } + } + } else { + if (tsCols[startPos] == pCtx->startTs) { + doTimeWindowInterpolation(pOperatorInfo, pOperatorInfo->info, pBlock->pDataBlock, INT64_MIN, 0, pCtx->startTs, startPos, 0, RESULT_ROW_END_INTERP); + } else { + doTimeWindowInterpolation(pOperatorInfo, pOperatorInfo->info, pBlock->pDataBlock, INT64_MIN, 0, tsCols[startPos + 1], startPos + 1, 0, RESULT_ROW_END_INTERP); + } + } + + if (pQueryAttr->fillType != TSDB_FILL_LINEAR) { + *needApply = true; + } + } + + if (ascQuery && (pQueryAttr->fillType == TSDB_FILL_LINEAR || pQueryAttr->fillType == TSDB_FILL_NEXT) && pCtx->end.key == INT64_MIN) { + if (startPos < 0) { + return true; + } + + doTimeWindowInterpolation(pOperatorInfo, pOperatorInfo->info, pBlock->pDataBlock, INT64_MIN, 0, tsCols[startPos], startPos, 0, RESULT_ROW_END_INTERP); + + *needApply = true; + } + + if ((!ascQuery) && pQueryAttr->fillType != TSDB_FILL_NEXT && pCtx->start.key == INT64_MIN) { + if (startPos < 0) { + return true; + } + + doTimeWindowInterpolation(pOperatorInfo, pOperatorInfo->info, pBlock->pDataBlock, tsCols[startPos], startPos, INT64_MIN, 0, 0, RESULT_ROW_START_INTERP); + + *needApply = true; + } + + if (*needApply) { + for (int32_t i = 0; i < pOperatorInfo->numOfOutput; ++i) { + pEveryInfo->binfo.pCtx[i].startTs = pCtx->startTs; + } + } + + return false; + +group_finished_exit: + + qDebug("group idx[%d] interp finished", gidx); + + if (pQueryAttr->needReverseScan) { + pQueryAttr->range.skey = INT64_MIN; + } + + pEveryInfo->groupDone = true; + + if (pCtx) { + pCtx->startTs = INT64_MIN; + pCtx->start.key = INT64_MIN; + pCtx->end.key = INT64_MIN; + } + + return true; } -static SSDataBlock* doSTableIntervalAgg(void* param, bool* newgroup) { + + +static void doTimeEveryImpl(SOperatorInfo* pOperator, SQLFunctionCtx *pCtx, SSDataBlock* pBlock, bool newgroup) { + STimeEveryOperatorInfo* pEveryInfo = (STimeEveryOperatorInfo*) pOperator->info; + SQueryRuntimeEnv *pRuntimeEnv = pOperator->pRuntimeEnv; + int32_t numOfOutput = pOperator->numOfOutput; + SQueryAttr* pQueryAttr = pRuntimeEnv->pQueryAttr; + bool finished = false, needApply = false; + bool ascQuery = QUERY_IS_ASC_QUERY(pQueryAttr); + SSDataBlock* pRes = pEveryInfo->binfo.pRes; + TSKEY* tsCols = NULL; + + if (pBlock && pBlock->pDataBlock != NULL) { + SColumnInfoData* pColDataInfo = taosArrayGet(pBlock->pDataBlock, 0); + if (pColDataInfo->info.type != TSDB_DATA_TYPE_TIMESTAMP) { + qError("no ts input for interp, error quit"); + pEveryInfo->allDone = true; + pEveryInfo->groupDone = true; + setQueryStatus(pRuntimeEnv, QUERY_COMPLETED); + return; + } + + tsCols = (int64_t*) pColDataInfo->pData; + assert(tsCols[0] == pBlock->info.window.skey && + tsCols[pBlock->info.rows - 1] == pBlock->info.window.ekey); + + pEveryInfo->tableEndKey = tsCols[ascQuery ? pBlock->info.rows - 1 : 0]; + } + + while (!finished) { + needApply = false; + finished = doEveryInterpolation(pOperator, pBlock, &needApply); + + if (needApply) { + everyApplyFunctions(pRuntimeEnv, pEveryInfo->binfo.pCtx, numOfOutput); + + pRes->info.rows = getNumOfResult(pRuntimeEnv, pEveryInfo->binfo.pCtx, pOperator->numOfOutput); + if (pRes->info.rows >= pRuntimeEnv->resultInfo.threshold) { + pEveryInfo->lastBlock = pBlock; + break; + } + + updateOutputBuf(&pEveryInfo->binfo, &pEveryInfo->bufCapacity, 0); + } + } +} + + + +static SSDataBlock* doTimeEvery(void* param, bool* newgroup) { SOperatorInfo* pOperator = (SOperatorInfo*) param; - if (pOperator->status == OP_EXEC_DONE) { + + STimeEveryOperatorInfo* pEveryInfo = pOperator->info; + SQueryRuntimeEnv* pRuntimeEnv = pOperator->pRuntimeEnv; + SOptrBasicInfo *pInfo = &pEveryInfo->binfo; + + SSDataBlock* pRes = pInfo->pRes; + int32_t order = pRuntimeEnv->pQueryAttr->order.order; + + pRes->info.rows = 0; + + if (!pEveryInfo->groupDone) { + updateOutputBuf(&pEveryInfo->binfo, &pEveryInfo->bufCapacity, 0); + doTimeEveryImpl(pOperator, pInfo->pCtx, pEveryInfo->lastBlock, false); + if (pRes->info.rows >= pRuntimeEnv->resultInfo.threshold) { + copyTsColoum(pRes, pInfo->pCtx, pOperator->numOfOutput); + clearNumOfRes(pInfo->pCtx, pOperator->numOfOutput); + return pInfo->pRes; + } + + if (pRes->info.rows > 0) { + copyTsColoum(pRes, pInfo->pCtx, pOperator->numOfOutput); + clearNumOfRes(pInfo->pCtx, pOperator->numOfOutput); + return pInfo->pRes; + } + } + + if (pEveryInfo->allDone) { + setQueryStatus(pRuntimeEnv, QUERY_COMPLETED); return NULL; } - STableIntervalOperatorInfo* pIntervalInfo = pOperator->info; - SQueryRuntimeEnv* pRuntimeEnv = pOperator->pRuntimeEnv; - if (pOperator->status == OP_RES_TO_RETURN) { - int64_t st = taosGetTimestampUs(); + if (pEveryInfo->existDataBlock) { // TODO refactor + STableQueryInfo* pTableQueryInfo = pRuntimeEnv->current; - copyToSDataBlock(pRuntimeEnv, 3000, pIntervalInfo->pRes, pIntervalInfo->rowCellInfoOffset); - if (pIntervalInfo->pRes->info.rows == 0 || !hasRemainData(&pRuntimeEnv->groupResInfo)) { - doSetOperatorCompleted(pOperator); + SSDataBlock* pBlock = pEveryInfo->existDataBlock; + pEveryInfo->existDataBlock = NULL; + *newgroup = true; + pEveryInfo->groupDone = false; + + // todo dynamic set tags + if (pTableQueryInfo != NULL) { + setTagValue(pOperator, pTableQueryInfo->pTable, pInfo->pCtx, pOperator->numOfOutput); } - SQInfo* pQInfo = pRuntimeEnv->qinfo; - pQInfo->summary.firstStageMergeTime += (taosGetTimestampUs() - st); + // the pDataBlock are always the same one, no need to call this again + setInputDataBlock(pOperator, pInfo->pCtx, pBlock, order); + updateOutputBuf(&pEveryInfo->binfo, &pEveryInfo->bufCapacity, pBlock->info.rows); - return pIntervalInfo->pRes; - } + doTimeEveryImpl(pOperator, pInfo->pCtx, pBlock, *newgroup); + if (pEveryInfo->groupDone && pOperator->upstream[0]->notify) { + pOperator->upstream[0]->notify(pOperator->upstream[0], OPTION_SWITCH_TABLE); + } - SQueryAttr* pQueryAttr = pRuntimeEnv->pQueryAttr; - int32_t order = pQueryAttr->order.order; + if (pRes->info.rows >= pRuntimeEnv->resultInfo.threshold) { + copyTsColoum(pRes, pInfo->pCtx, pOperator->numOfOutput); + clearNumOfRes(pInfo->pCtx, pOperator->numOfOutput); + return pRes; + } + } - SOperatorInfo* upstream = pOperator->upstream[0]; + while(!pEveryInfo->allDone) { + bool prevVal = *newgroup; - while(1) { - publishOperatorProfEvent(upstream, QUERY_PROF_BEFORE_OPERATOR_EXEC); - SSDataBlock* pBlock = upstream->exec(upstream, newgroup); - publishOperatorProfEvent(upstream, QUERY_PROF_AFTER_OPERATOR_EXEC); + // The upstream exec may change the value of the newgroup, so use a local variable instead. + publishOperatorProfEvent(pOperator->upstream[0], QUERY_PROF_BEFORE_OPERATOR_EXEC); + SSDataBlock* pBlock = pOperator->upstream[0]->exec(pOperator->upstream[0], newgroup); + publishOperatorProfEvent(pOperator->upstream[0], QUERY_PROF_AFTER_OPERATOR_EXEC); if (pBlock == NULL) { + if (!pEveryInfo->groupDone) { + pEveryInfo->allDone = true; + + updateOutputBuf(&pEveryInfo->binfo, &pEveryInfo->bufCapacity, 0); + doTimeEveryImpl(pOperator, pInfo->pCtx, NULL, false); + if (pRes->info.rows >= pRuntimeEnv->resultInfo.threshold) { + break; + } + + assert(pEveryInfo->groupDone); + + if (pRes->info.rows > 0) { + break; + } + } + + *newgroup = prevVal; + setQueryStatus(pRuntimeEnv, QUERY_COMPLETED); break; } - // the pDataBlock are always the same one, no need to call this again + // Return result of the previous group in the firstly. + if (*newgroup) { + if (!pEveryInfo->groupDone) { + updateOutputBuf(&pEveryInfo->binfo, &pEveryInfo->bufCapacity, 0); + doTimeEveryImpl(pOperator, pInfo->pCtx, NULL, false); + if (pRes->info.rows >= pRuntimeEnv->resultInfo.threshold) { + pEveryInfo->existDataBlock = pBlock; + break; + } + + assert(pEveryInfo->groupDone); + } + + if (pRes->info.rows > 0) { + pEveryInfo->existDataBlock = pBlock; + break; + } 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); + pEveryInfo->groupDone = false; + } + } + STableQueryInfo* pTableQueryInfo = pRuntimeEnv->current; - setTagValue(pOperator, pTableQueryInfo->pTable, pIntervalInfo->pCtx, pOperator->numOfOutput); - setInputDataBlock(pOperator, pIntervalInfo->pCtx, pBlock, pQueryAttr->order.order); - setIntervalQueryRange(pRuntimeEnv, &pBlock->info.window, pBlock->info.tid); + if (pEveryInfo->groupDone && pTableQueryInfo->groupIndex == pEveryInfo->lastGroupIdx) { + assert(pOperator->upstream[0]->notify == NULL); + continue; + } - hashIntervalAgg(pOperator, &pTableQueryInfo->resInfo, pBlock, pTableQueryInfo->groupIndex); - } + // todo dynamic set tags + if (pTableQueryInfo != NULL) { + setTagValue(pOperator, pTableQueryInfo->pTable, pInfo->pCtx, pOperator->numOfOutput); + } - pOperator->status = OP_RES_TO_RETURN; - pQueryAttr->order.order = order; // TODO : restore the order - doCloseAllTimeWindow(pRuntimeEnv); - setQueryStatus(pRuntimeEnv, QUERY_COMPLETED); + // the pDataBlock are always the same one, no need to call this again + setInputDataBlock(pOperator, pInfo->pCtx, pBlock, order); + updateOutputBuf(&pEveryInfo->binfo, &pEveryInfo->bufCapacity, pBlock->info.rows); - copyToSDataBlock(pRuntimeEnv, 3000, pIntervalInfo->pRes, pIntervalInfo->rowCellInfoOffset); - if (pIntervalInfo->pRes->info.rows == 0 || !hasRemainData(&pRuntimeEnv->groupResInfo)) { - pOperator->status = OP_EXEC_DONE; + pEveryInfo->groupDone = false; + + doTimeEveryImpl(pOperator, pInfo->pCtx, pBlock, *newgroup); + if (pEveryInfo->groupDone && pOperator->upstream[0]->notify) { + pOperator->upstream[0]->notify(pOperator->upstream[0], OPTION_SWITCH_TABLE); + } + + if (pRes->info.rows >= pRuntimeEnv->resultInfo.threshold) { + break; + } } - return pIntervalInfo->pRes; + copyTsColoum(pRes, pInfo->pCtx, pOperator->numOfOutput); + clearNumOfRes(pInfo->pCtx, pOperator->numOfOutput); + return (pInfo->pRes->info.rows > 0)? pInfo->pRes:NULL; } -static SSDataBlock* doAllSTableIntervalAgg(void* param, bool* newgroup) { +static SSDataBlock* doSTableIntervalAgg(void* param, bool* newgroup) { SOperatorInfo* pOperator = (SOperatorInfo*) param; if (pOperator->status == OP_EXEC_DONE) { return NULL; @@ -6177,11 +6408,16 @@ static SSDataBlock* doAllSTableIntervalAgg(void* param, bool* newgroup) { SQueryRuntimeEnv* pRuntimeEnv = pOperator->pRuntimeEnv; if (pOperator->status == OP_RES_TO_RETURN) { + int64_t st = taosGetTimestampUs(); + copyToSDataBlock(pRuntimeEnv, 3000, pIntervalInfo->pRes, pIntervalInfo->rowCellInfoOffset); if (pIntervalInfo->pRes->info.rows == 0 || !hasRemainData(&pRuntimeEnv->groupResInfo)) { - pOperator->status = OP_EXEC_DONE; + doSetOperatorCompleted(pOperator); } + SQInfo* pQInfo = pRuntimeEnv->qinfo; + pQInfo->summary.firstStageMergeTime += (taosGetTimestampUs() - st); + return pIntervalInfo->pRes; } @@ -6204,10 +6440,9 @@ static SSDataBlock* doAllSTableIntervalAgg(void* param, bool* newgroup) { setTagValue(pOperator, pTableQueryInfo->pTable, pIntervalInfo->pCtx, pOperator->numOfOutput); setInputDataBlock(pOperator, pIntervalInfo->pCtx, pBlock, pQueryAttr->order.order); - setIntervalQueryRange(pRuntimeEnv, &pBlock->info.window, pBlock->info.tid); - hashAllIntervalAgg(pOperator, &pTableQueryInfo->resInfo, pBlock, pTableQueryInfo->groupIndex); + hashIntervalAgg(pOperator, &pTableQueryInfo->resInfo, pBlock, pTableQueryInfo->groupIndex); } pOperator->status = OP_RES_TO_RETURN; @@ -6215,15 +6450,11 @@ static SSDataBlock* doAllSTableIntervalAgg(void* param, bool* newgroup) { doCloseAllTimeWindow(pRuntimeEnv); setQueryStatus(pRuntimeEnv, QUERY_COMPLETED); - int64_t st = taosGetTimestampUs(); copyToSDataBlock(pRuntimeEnv, 3000, pIntervalInfo->pRes, pIntervalInfo->rowCellInfoOffset); if (pIntervalInfo->pRes->info.rows == 0 || !hasRemainData(&pRuntimeEnv->groupResInfo)) { pOperator->status = OP_EXEC_DONE; } - SQInfo* pQInfo = pRuntimeEnv->qinfo; - pQInfo->summary.firstStageMergeTime += (taosGetTimestampUs() - st); - return pIntervalInfo->pRes; } @@ -6471,7 +6702,7 @@ static SSDataBlock* hashGroupbyAggregate(void* param, bool* newgroup) { initGroupResInfo(&pRuntimeEnv->groupResInfo, &pInfo->binfo.resultRowInfo); if (!pRuntimeEnv->pQueryAttr->stableQuery) { - sortGroupResByOrderList(&pRuntimeEnv->groupResInfo, pRuntimeEnv, pInfo->binfo.pRes); + sortGroupResByOrderList(&pRuntimeEnv->groupResInfo, pRuntimeEnv, pInfo->binfo.pRes, pInfo->binfo.pCtx); } toSSDataBlock(&pRuntimeEnv->groupResInfo, pRuntimeEnv, pInfo->binfo.pRes); @@ -6696,6 +6927,13 @@ static void destroyProjectOperatorInfo(void* param, int32_t numOfOutput) { doDestroyBasicInfo(&pInfo->binfo, numOfOutput); } +static void destroyTimeEveryOperatorInfo(void* param, int32_t numOfOutput) { + STimeEveryOperatorInfo* pInfo = (STimeEveryOperatorInfo*) param; + doDestroyBasicInfo(&pInfo->binfo, numOfOutput); + taosHashCleanup(pInfo->rangeStart); +} + + static void destroyTagScanOperatorInfo(void* param, int32_t numOfOutput) { STagScanInfo* pInfo = (STagScanInfo*) param; pInfo->pRes = destroyOutputBuf(pInfo->pRes); @@ -6872,30 +7110,44 @@ SOperatorInfo* createTimeIntervalOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOp } -SOperatorInfo* createAllTimeIntervalOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOperatorInfo* upstream, SExprInfo* pExpr, int32_t numOfOutput) { - STableIntervalOperatorInfo* pInfo = calloc(1, sizeof(STableIntervalOperatorInfo)); +SOperatorInfo* createTimeEveryOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOperatorInfo* upstream, SExprInfo* pExpr, int32_t numOfOutput) { + STimeEveryOperatorInfo* pInfo = calloc(1, sizeof(STimeEveryOperatorInfo)); + SQueryAttr* pQueryAttr = pRuntimeEnv->pQueryAttr; - pInfo->pCtx = createSQLFunctionCtx(pRuntimeEnv, pExpr, numOfOutput, &pInfo->rowCellInfoOffset); - pInfo->pRes = createOutputBuf(pExpr, numOfOutput, pRuntimeEnv->resultInfo.capacity); - initResultRowInfo(&pInfo->resultRowInfo, 8, TSDB_DATA_TYPE_INT); + pInfo->seed = rand(); + pInfo->bufCapacity = pRuntimeEnv->resultInfo.capacity; + pInfo->groupDone = true; + pInfo->lastGroupIdx = -1; - SOperatorInfo* pOperator = calloc(1, sizeof(SOperatorInfo)); + SOptrBasicInfo* pBInfo = &pInfo->binfo; + pBInfo->pRes = createOutputBuf(pExpr, numOfOutput, pInfo->bufCapacity); + pBInfo->pCtx = createSQLFunctionCtx(pRuntimeEnv, pExpr, numOfOutput, &pBInfo->rowCellInfoOffset); - pOperator->name = "AllTimeIntervalAggOperator"; - pOperator->operatorType = OP_AllTimeWindow; - pOperator->blockingOptr = true; + if (pQueryAttr->needReverseScan) { + pInfo->rangeStart = taosHashInit(256, taosGetDefaultHashFunction(TSDB_DATA_TYPE_TIMESTAMP), false, false); + } + + initResultRowInfo(&pBInfo->resultRowInfo, 8, TSDB_DATA_TYPE_INT); + setDefaultOutputBuf(pRuntimeEnv, pBInfo, pInfo->seed, MASTER_SCAN); + + SOperatorInfo* pOperator = calloc(1, sizeof(SOperatorInfo)); + pOperator->name = "TimeEveryOperator"; + pOperator->operatorType = OP_TimeEvery; + pOperator->blockingOptr = false; pOperator->status = OP_IN_EXECUTING; + pOperator->info = pInfo; pOperator->pExpr = pExpr; pOperator->numOfOutput = numOfOutput; - pOperator->info = pInfo; pOperator->pRuntimeEnv = pRuntimeEnv; - pOperator->exec = doAllIntervalAgg; - pOperator->cleanup = destroyBasicOperatorInfo; + pOperator->exec = doTimeEvery; + pOperator->cleanup = destroyTimeEveryOperatorInfo; appendUpstream(pOperator, upstream); + return pOperator; } + SOperatorInfo* createStatewindowOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOperatorInfo* upstream, SExprInfo* pExpr, int32_t numOfOutput) { SStateWindowOperatorInfo* pInfo = calloc(1, sizeof(SStateWindowOperatorInfo)); pInfo->colIndex = -1; @@ -6969,31 +7221,6 @@ SOperatorInfo* createMultiTableTimeIntervalOperatorInfo(SQueryRuntimeEnv* pRunti return pOperator; } -SOperatorInfo* createAllMultiTableTimeIntervalOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOperatorInfo* upstream, SExprInfo* pExpr, int32_t numOfOutput) { - STableIntervalOperatorInfo* pInfo = calloc(1, sizeof(STableIntervalOperatorInfo)); - - pInfo->pCtx = createSQLFunctionCtx(pRuntimeEnv, pExpr, numOfOutput, &pInfo->rowCellInfoOffset); - pInfo->pRes = createOutputBuf(pExpr, numOfOutput, pRuntimeEnv->resultInfo.capacity); - initResultRowInfo(&pInfo->resultRowInfo, 8, TSDB_DATA_TYPE_INT); - - SOperatorInfo* pOperator = calloc(1, sizeof(SOperatorInfo)); - pOperator->name = "AllMultiTableTimeIntervalOperator"; - pOperator->operatorType = OP_AllMultiTableTimeInterval; - pOperator->blockingOptr = true; - pOperator->status = OP_IN_EXECUTING; - pOperator->pExpr = pExpr; - pOperator->numOfOutput = numOfOutput; - pOperator->info = pInfo; - pOperator->pRuntimeEnv = pRuntimeEnv; - - pOperator->exec = doAllSTableIntervalAgg; - pOperator->cleanup = destroyBasicOperatorInfo; - - appendUpstream(pOperator, upstream); - - return pOperator; -} - SOperatorInfo* createGroupbyOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOperatorInfo* upstream, SExprInfo* pExpr, int32_t numOfOutput) { SGroupbyOperatorInfo* pInfo = calloc(1, sizeof(SGroupbyOperatorInfo)); @@ -7579,6 +7806,9 @@ int32_t convertQueryMsg(SQueryTableMsg *pQueryMsg, SQueryParam* param) { pQueryMsg->numOfTables = htonl(pQueryMsg->numOfTables); pQueryMsg->window.skey = htobe64(pQueryMsg->window.skey); pQueryMsg->window.ekey = htobe64(pQueryMsg->window.ekey); + pQueryMsg->range.skey = htobe64(pQueryMsg->range.skey); + pQueryMsg->range.ekey = htobe64(pQueryMsg->range.ekey); + pQueryMsg->interval.interval = htobe64(pQueryMsg->interval.interval); pQueryMsg->interval.sliding = htobe64(pQueryMsg->interval.sliding); pQueryMsg->interval.offset = htobe64(pQueryMsg->interval.offset); @@ -7594,8 +7824,8 @@ int32_t convertQueryMsg(SQueryTableMsg *pQueryMsg, SQueryParam* param) { pQueryMsg->numOfOutput = htons(pQueryMsg->numOfOutput); pQueryMsg->numOfGroupCols = htons(pQueryMsg->numOfGroupCols); - pQueryMsg->tagCondLen = htons(pQueryMsg->tagCondLen); - pQueryMsg->colCondLen = htons(pQueryMsg->colCondLen); + pQueryMsg->tagCondLen = htonl(pQueryMsg->tagCondLen); + pQueryMsg->colCondLen = htonl(pQueryMsg->colCondLen); pQueryMsg->tsBuf.tsOffset = htonl(pQueryMsg->tsBuf.tsOffset); pQueryMsg->tsBuf.tsLen = htonl(pQueryMsg->tsBuf.tsLen); @@ -8245,7 +8475,7 @@ int32_t createQueryFunc(SQueriedTableInfo* pTableInfo, int32_t numOfOutput, SExp return TSDB_CODE_SUCCESS; } -int32_t createQueryFilter(char *data, uint16_t len, void** pFilters) { +int32_t createQueryFilter(char *data, int32_t len, void** pFilters) { tExprNode* expr = NULL; TRY(TSDB_MAX_TAG_CONDITIONS) { @@ -8553,6 +8783,7 @@ SQInfo* createQInfoImpl(SQueryTableMsg* pQueryMsg, SGroupbyExpr* pGroupbyExpr, S pQueryAttr->stateWindow = pQueryMsg->stateWindow; pQueryAttr->vgId = vgId; pQueryAttr->pFilters = pFilters; + pQueryAttr->range = pQueryMsg->range; pQueryAttr->tableCols = calloc(numOfCols, sizeof(SSingleColumnFilterInfo)); if (pQueryAttr->tableCols == NULL) { diff --git a/src/query/src/qFill.c b/src/query/src/qFill.c index 144ca4dd794975a161d85c68e8058e3ca105d9c8..b0015e39b96e0754377abece6e12045b0f36a901 100644 --- a/src/query/src/qFill.c +++ b/src/query/src/qFill.c @@ -118,10 +118,11 @@ static void doFillOneRowResult(SFillInfo* pFillInfo, void** data, char** srcData continue; } + bool exceedMax = false, exceedMin = false; point1 = (SPoint){.key = *(TSKEY*)(prev), .val = prev + pCol->col.offset}; point2 = (SPoint){.key = ts, .val = srcData[i] + pFillInfo->index * bytes}; point = (SPoint){.key = pFillInfo->currentKey, .val = val1}; - taosGetLinearInterpolationVal(&point, type, &point1, &point2, type); + taosGetLinearInterpolationVal(&point, type, &point1, &point2, type, &exceedMax, &exceedMin); } } else { setNullValueForRow(pFillInfo, data, pFillInfo->numOfCols, index); @@ -493,12 +494,20 @@ int64_t getNumOfResultsAfterFillGap(SFillInfo* pFillInfo, TSKEY ekey, int32_t ma return (numOfRes > maxNumOfRows) ? maxNumOfRows : numOfRes; } -int32_t taosGetLinearInterpolationVal(SPoint* point, int32_t outputType, SPoint* point1, SPoint* point2, int32_t inputType) { - double v1 = -1, v2 = -1; +int32_t taosGetLinearInterpolationVal(SPoint* point, int32_t outputType, SPoint* point1, SPoint* point2, int32_t inputType, bool *exceedMax, bool *exceedMin) { + double v1 = -1, v2 = -1, vmax = -1, vmin = -1; GET_TYPED_DATA(v1, double, inputType, point1->val); GET_TYPED_DATA(v2, double, inputType, point2->val); - + GET_TYPED_DATA(vmax, double, outputType, getDataMax(outputType)); + GET_TYPED_DATA(vmin, double, outputType, getDataMin(outputType)); + double r = DO_INTERPOLATION(v1, v2, point1->key, point2->key, point->key); + if (r >= vmax) { + *exceedMax = true; + } else if (r <= vmin) { + *exceedMin = true; + } + SET_TYPED_DATA(point->val, outputType, r); return TSDB_CODE_SUCCESS; diff --git a/src/query/src/qFilter.c b/src/query/src/qFilter.c index ac18538e21864dc1ae0d2c028c2f014f93856782..2ce8a49097af6229c36931cbf3db753c04580674 100644 --- a/src/query/src/qFilter.c +++ b/src/query/src/qFilter.c @@ -254,7 +254,7 @@ int32_t filterInitUnitsFields(SFilterInfo *info) { info->fields[FLD_TYPE_COLUMN].num = 0; info->fields[FLD_TYPE_COLUMN].size = FILTER_DEFAULT_FIELD_SIZE; - info->fields[FLD_TYPE_COLUMN].fields = calloc(info->fields[FLD_TYPE_COLUMN].size, COL_FIELD_SIZE); + info->fields[FLD_TYPE_COLUMN].fields = calloc(info->fields[FLD_TYPE_COLUMN].size, sizeof(SFilterField)); info->fields[FLD_TYPE_VALUE].num = 0; info->fields[FLD_TYPE_VALUE].size = FILTER_DEFAULT_FIELD_SIZE; info->fields[FLD_TYPE_VALUE].fields = calloc(info->fields[FLD_TYPE_VALUE].size, sizeof(SFilterField)); @@ -756,7 +756,7 @@ int32_t filterDetachCnfGroups(SArray* group, SArray* left, SArray* right) { } int32_t filterGetFiledByDesc(SFilterFields* fields, int32_t type, void *v) { - for (uint16_t i = 0; i < fields->num; ++i) { + for (uint32_t i = 0; i < fields->num; ++i) { if (0 == gDescCompare[type](fields->fields[i].desc, v)) { return i; } @@ -785,7 +785,7 @@ int32_t filterGetFiledByData(SFilterInfo *info, int32_t type, void *v, int32_t d int32_t filterAddField(SFilterInfo *info, void *desc, void **data, int32_t type, SFilterFieldId *fid, int32_t dataLen, bool freeIfExists) { int32_t idx = -1; - uint16_t *num; + uint32_t *num; num = &info->fields[type].num; @@ -869,7 +869,7 @@ int32_t filterAddFieldFromNode(SFilterInfo *info, tExprNode *node, SFilterFieldI return TSDB_CODE_SUCCESS; } -int32_t filterAddUnit(SFilterInfo *info, uint8_t optr, SFilterFieldId *left, SFilterFieldId *right, uint16_t *uidx) { +int32_t filterAddUnit(SFilterInfo *info, uint8_t optr, SFilterFieldId *left, SFilterFieldId *right, uint32_t *uidx) { if (FILTER_GET_FLAG(info->options, FI_OPTION_NEED_UNIQE)) { if (info->pctx.unitHash == NULL) { info->pctx.unitHash = taosHashInit(FILTER_DEFAULT_GROUP_SIZE * FILTER_DEFAULT_UNIT_SIZE, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, false); @@ -878,14 +878,14 @@ int32_t filterAddUnit(SFilterInfo *info, uint8_t optr, SFilterFieldId *left, SFi FILTER_PACKAGE_UNIT_HASH_KEY(&v, optr, left->idx, right ? right->idx : -1); void *hu = taosHashGet(info->pctx.unitHash, &v, sizeof(v)); if (hu) { - *uidx = *(uint16_t *)hu; + *uidx = *(uint32_t *)hu; return TSDB_CODE_SUCCESS; } } } if (info->unitNum >= info->unitSize) { - uint16_t psize = info->unitSize; + uint32_t psize = info->unitSize; info->unitSize += FILTER_DEFAULT_UNIT_SIZE; info->units = realloc(info->units, info->unitSize * sizeof(SFilterUnit)); memset(info->units + psize, 0, sizeof(*info->units) * FILTER_DEFAULT_UNIT_SIZE); @@ -926,7 +926,7 @@ int32_t filterAddUnit(SFilterInfo *info, uint8_t optr, SFilterFieldId *left, SFi -int32_t filterAddUnitToGroup(SFilterGroup *group, uint16_t unitIdx) { +int32_t filterAddUnitToGroup(SFilterGroup *group, uint32_t unitIdx) { if (group->unitNum >= group->unitSize) { group->unitSize += FILTER_DEFAULT_UNIT_SIZE; group->unitIdxs = realloc(group->unitIdxs, group->unitSize * sizeof(*group->unitIdxs)); @@ -1157,7 +1157,7 @@ int32_t filterAddGroupUnitFromNode(SFilterInfo *info, tExprNode* tree, SArray *g tVariant* var = tree->_node.pRight->pVal; int32_t type = FILTER_GET_COL_FIELD_TYPE(FILTER_GET_FIELD(info, left)); int32_t len = 0; - uint16_t uidx = 0; + uint32_t uidx = 0; if (tree->_node.optr == TSDB_RELATION_IN && (!IS_VAR_DATA_TYPE(type))) { void *data = NULL; @@ -1192,7 +1192,6 @@ int32_t filterAddGroupUnitFromNode(SFilterInfo *info, tExprNode* tree, SArray *g SIMPLE_COPY_VALUES(fdata, key); len = tDataTypes[type].bytes; } - filterAddField(info, NULL, &fdata, FLD_TYPE_VALUE, &right, len, true); filterAddUnit(info, TSDB_RELATION_EQUAL, &left, &right, &uidx); @@ -1221,7 +1220,7 @@ int32_t filterAddGroupUnitFromNode(SFilterInfo *info, tExprNode* tree, SArray *g } -int32_t filterAddUnitFromUnit(SFilterInfo *dst, SFilterInfo *src, SFilterUnit* u, uint16_t *uidx) { +int32_t filterAddUnitFromUnit(SFilterInfo *dst, SFilterInfo *src, SFilterUnit* u, uint32_t *uidx) { SFilterFieldId left, right, *pright = &right; int32_t type = FILTER_UNIT_DATA_TYPE(u); uint16_t flag = FLD_DESC_NO_FREE; @@ -1256,7 +1255,7 @@ int32_t filterAddUnitFromUnit(SFilterInfo *dst, SFilterInfo *src, SFilterUnit* u return filterAddUnit(dst, FILTER_UNIT_OPTR(u), &left, pright, uidx); } -int32_t filterAddUnitRight(SFilterInfo *info, uint8_t optr, SFilterFieldId *right, uint16_t uidx) { +int32_t filterAddUnitRight(SFilterInfo *info, uint8_t optr, SFilterFieldId *right, uint32_t uidx) { SFilterUnit *u = &info->units[uidx]; u->compare.optr2 = optr; @@ -1266,9 +1265,9 @@ int32_t filterAddUnitRight(SFilterInfo *info, uint8_t optr, SFilterFieldId *righ } -int32_t filterAddGroupUnitFromCtx(SFilterInfo *dst, SFilterInfo *src, SFilterRangeCtx *ctx, uint16_t cidx, SFilterGroup *g, int32_t optr, SArray *res) { +int32_t filterAddGroupUnitFromCtx(SFilterInfo *dst, SFilterInfo *src, SFilterRangeCtx *ctx, uint32_t cidx, SFilterGroup *g, int32_t optr, SArray *res) { SFilterFieldId left, right, right2; - uint16_t uidx = 0; + uint32_t uidx = 0; SFilterField *col = FILTER_GET_COL_FIELD(src, cidx); @@ -1495,14 +1494,14 @@ void filterDumpInfoToString(SFilterInfo *info, const char *msg, int32_t options) if (options == 0) { qDebug("%s - FilterInfo:", msg); qDebug("COLUMN Field Num:%u", info->fields[FLD_TYPE_COLUMN].num); - for (uint16_t i = 0; i < info->fields[FLD_TYPE_COLUMN].num; ++i) { + for (uint32_t i = 0; i < info->fields[FLD_TYPE_COLUMN].num; ++i) { SFilterField *field = &info->fields[FLD_TYPE_COLUMN].fields[i]; SSchema *sch = field->desc; qDebug("COL%d => [%d][%s]", i, sch->colId, sch->name); } qDebug("VALUE Field Num:%u", info->fields[FLD_TYPE_VALUE].num); - for (uint16_t i = 0; i < info->fields[FLD_TYPE_VALUE].num; ++i) { + for (uint32_t i = 0; i < info->fields[FLD_TYPE_VALUE].num; ++i) { SFilterField *field = &info->fields[FLD_TYPE_VALUE].fields[i]; if (field->desc) { tVariant *var = field->desc; @@ -1517,7 +1516,7 @@ void filterDumpInfoToString(SFilterInfo *info, const char *msg, int32_t options) } qDebug("UNIT Num:%u", info->unitNum); - for (uint16_t i = 0; i < info->unitNum; ++i) { + for (uint32_t i = 0; i < info->unitNum; ++i) { SFilterUnit *unit = &info->units[i]; int32_t type = FILTER_UNIT_DATA_TYPE(unit); int32_t len = 0; @@ -1563,11 +1562,11 @@ void filterDumpInfoToString(SFilterInfo *info, const char *msg, int32_t options) } qDebug("GROUP Num:%u", info->groupNum); - for (uint16_t i = 0; i < info->groupNum; ++i) { + for (uint32_t i = 0; i < info->groupNum; ++i) { SFilterGroup *group = &info->groups[i]; qDebug("Group%d : unit num[%u]", i, group->unitNum); - for (uint16_t u = 0; u < group->unitNum; ++u) { + for (uint32_t u = 0; u < group->unitNum; ++u) { qDebug("unit id:%u", group->unitIdxs[u]); } } @@ -1579,7 +1578,7 @@ void filterDumpInfoToString(SFilterInfo *info, const char *msg, int32_t options) qDebug("%s - RANGE info:", msg); qDebug("RANGE Num:%u", info->colRangeNum); - for (uint16_t i = 0; i < info->colRangeNum; ++i) { + for (uint32_t i = 0; i < info->colRangeNum; ++i) { SFilterRangeCtx *ctx = info->colRange[i]; qDebug("Column ID[%d] RANGE: isnull[%d],notnull[%d],range[%d]", ctx->colId, ctx->isnull, ctx->notnull, ctx->isrange); if (ctx->isrange) { @@ -1625,11 +1624,11 @@ void filterDumpInfoToString(SFilterInfo *info, const char *msg, int32_t options) } qDebug("GroupNum:%d", info->blkGroupNum); - uint16_t *unitIdx = info->blkUnits; - for (uint16_t i = 0; i < info->blkGroupNum; ++i) { + uint32_t *unitIdx = info->blkUnits; + for (uint32_t i = 0; i < info->blkGroupNum; ++i) { qDebug("Group[%d] UnitNum: %d:", i, *unitIdx); - uint16_t unitNum = *(unitIdx++); - for (uint16_t m = 0; m < unitNum; ++m) { + uint32_t unitNum = *(unitIdx++); + for (uint32_t m = 0; m < unitNum; ++m) { qDebug("uidx[%d]", *(unitIdx++)); } } @@ -1723,14 +1722,14 @@ void filterFreeInfo(SFilterInfo *info) { tfree(info->blkUnits); for (int32_t i = 0; i < FLD_TYPE_MAX; ++i) { - for (uint16_t f = 0; f < info->fields[i].num; ++f) { + for (uint32_t f = 0; f < info->fields[i].num; ++f) { filterFreeField(&info->fields[i].fields[f], i); } tfree(info->fields[i].fields); } - for (int32_t i = 0; i < info->groupNum; ++i) { + for (uint32_t i = 0; i < info->groupNum; ++i) { filterFreeGroup(&info->groups[i]); } @@ -1742,7 +1741,7 @@ void filterFreeInfo(SFilterInfo *info) { tfree(info->unitFlags); - for (uint16_t i = 0; i < info->colRangeNum; ++i) { + for (uint32_t i = 0; i < info->colRangeNum; ++i) { filterFreeRangeCtx(info->colRange[i]); } @@ -1780,7 +1779,7 @@ int32_t filterHandleValueExtInfo(SFilterUnit* unit, char extInfo) { int32_t filterInitValFieldData(SFilterInfo *info) { - for (uint16_t i = 0; i < info->unitNum; ++i) { + for (uint32_t i = 0; i < info->unitNum; ++i) { SFilterUnit* unit = &info->units[i]; if (unit->right.type != FLD_TYPE_VALUE) { assert(unit->compare.optr == TSDB_RELATION_ISNULL || unit->compare.optr == TSDB_RELATION_NOTNULL || unit->compare.optr == FILTER_DUMMY_EMPTY_OPTR); @@ -1980,7 +1979,7 @@ _return: } -int32_t filterMergeUnits(SFilterInfo *info, SFilterGroupCtx* gRes, uint16_t colIdx, bool *empty) { +int32_t filterMergeUnits(SFilterInfo *info, SFilterGroupCtx* gRes, uint32_t colIdx, bool *empty) { SArray* colArray = (SArray *)gRes->colInfo[colIdx].info; int32_t size = (int32_t)taosArrayGetSize(colArray); int32_t type = gRes->colInfo[colIdx].dataType; @@ -1997,6 +1996,10 @@ int32_t filterMergeUnits(SFilterInfo *info, SFilterGroupCtx* gRes, uint16_t colI filterAddUnitRange(info, u, ctx, TSDB_RELATION_AND); CHK_JMP(MR_EMPTY_RES(ctx)); } + if(FILTER_UNIT_OPTR(u) == TSDB_RELATION_EQUAL && !FILTER_NO_MERGE_DATA_TYPE(FILTER_UNIT_DATA_TYPE(u))){ + gRes->colInfo[colIdx].optr = TSDB_RELATION_EQUAL; + SIMPLE_COPY_VALUES(&gRes->colInfo[colIdx].value, FILTER_UNIT_VAL_DATA(info, u)); + } } taosArrayDestroy(colArray); @@ -2017,11 +2020,11 @@ _return: int32_t filterMergeGroupUnits(SFilterInfo *info, SFilterGroupCtx** gRes, int32_t* gResNum) { bool empty = false; - uint16_t *colIdx = malloc(info->fields[FLD_TYPE_COLUMN].num * sizeof(uint16_t)); - uint16_t colIdxi = 0; - uint16_t gResIdx = 0; + uint32_t *colIdx = malloc(info->fields[FLD_TYPE_COLUMN].num * sizeof(uint32_t)); + uint32_t colIdxi = 0; + uint32_t gResIdx = 0; - for (uint16_t i = 0; i < info->groupNum; ++i) { + for (uint32_t i = 0; i < info->groupNum; ++i) { SFilterGroup* g = info->groups + i; gRes[gResIdx] = calloc(1, sizeof(SFilterGroupCtx)); @@ -2029,9 +2032,9 @@ int32_t filterMergeGroupUnits(SFilterInfo *info, SFilterGroupCtx** gRes, int32_t colIdxi = 0; empty = false; - for (uint16_t j = 0; j < g->unitNum; ++j) { + for (uint32_t j = 0; j < g->unitNum; ++j) { SFilterUnit* u = FILTER_GROUP_UNIT(info, g, j); - uint16_t cidx = FILTER_UNIT_COL_IDX(u); + uint32_t cidx = FILTER_UNIT_COL_IDX(u); if (gRes[gResIdx]->colInfo[cidx].info == NULL) { gRes[gResIdx]->colInfo[cidx].info = (SArray *)taosArrayInit(4, POINTER_BYTES); @@ -2047,10 +2050,10 @@ int32_t filterMergeGroupUnits(SFilterInfo *info, SFilterGroupCtx** gRes, int32_t } if (colIdxi > 1) { - qsort(colIdx, colIdxi, sizeof(uint16_t), getComparFunc(TSDB_DATA_TYPE_USMALLINT, 0)); + qsort(colIdx, colIdxi, sizeof(uint32_t), getComparFunc(TSDB_DATA_TYPE_USMALLINT, 0)); } - for (uint16_t l = 0; l < colIdxi; ++l) { + for (uint32_t l = 0; l < colIdxi; ++l) { int32_t type = gRes[gResIdx]->colInfo[colIdx[l]].dataType; if (FILTER_NO_MERGE_DATA_TYPE(type)) { @@ -2089,7 +2092,7 @@ int32_t filterMergeGroupUnits(SFilterInfo *info, SFilterGroupCtx** gRes, int32_t } void filterCheckColConflict(SFilterGroupCtx* gRes1, SFilterGroupCtx* gRes2, bool *conflict) { - uint16_t idx1 = 0, idx2 = 0, m = 0, n = 0; + uint32_t idx1 = 0, idx2 = 0, m = 0, n = 0; bool equal = false; for (; m < gRes1->colNum; ++m) { @@ -2112,6 +2115,15 @@ void filterCheckColConflict(SFilterGroupCtx* gRes1, SFilterGroupCtx* gRes2, bool *conflict = true; return; } + + // for long in operation + if (gRes1->colInfo[idx1].optr == TSDB_RELATION_EQUAL && gRes2->colInfo[idx2].optr == TSDB_RELATION_EQUAL) { + SFilterRangeCtx* ctx = gRes1->colInfo[idx1].info; + if (ctx->pCompareFunc(&gRes1->colInfo[idx1].value, &gRes2->colInfo[idx2].value)){ + *conflict = true; + return; + } + } ++n; equal = true; @@ -2129,7 +2141,7 @@ void filterCheckColConflict(SFilterGroupCtx* gRes1, SFilterGroupCtx* gRes2, bool } -int32_t filterMergeTwoGroupsImpl(SFilterInfo *info, SFilterRangeCtx **ctx, int32_t optr, uint16_t cidx, SFilterGroupCtx* gRes1, SFilterGroupCtx* gRes2, bool *empty, bool *all) { +int32_t filterMergeTwoGroupsImpl(SFilterInfo *info, SFilterRangeCtx **ctx, int32_t optr, uint32_t cidx, SFilterGroupCtx* gRes1, SFilterGroupCtx* gRes2, bool *empty, bool *all) { SFilterField *fi = FILTER_GET_COL_FIELD(info, cidx); int32_t type = FILTER_GET_COL_FIELD_TYPE(fi); @@ -2159,10 +2171,10 @@ int32_t filterMergeTwoGroups(SFilterInfo *info, SFilterGroupCtx** gRes1, SFilter FILTER_SET_FLAG(info->status, FI_STATUS_REWRITE); - uint16_t idx1 = 0, idx2 = 0, m = 0, n = 0; + uint32_t idx1 = 0, idx2 = 0, m = 0, n = 0; bool numEqual = (*gRes1)->colNum == (*gRes2)->colNum; bool equal = false; - uint16_t equal1 = 0, equal2 = 0, merNum = 0; + uint32_t equal1 = 0, equal2 = 0, merNum = 0; SFilterRangeCtx *ctx = NULL; SFilterColCtx colCtx = {0}; SArray* colCtxs = taosArrayInit((*gRes2)->colNum, sizeof(SFilterColCtx)); @@ -2276,7 +2288,7 @@ int32_t filterMergeGroups(SFilterInfo *info, SFilterGroupCtx** gRes, int32_t *gR qsort(gRes, *gResNum, POINTER_BYTES, filterCompareGroupCtx); int32_t pEnd = 0, cStart = 0, cEnd = 0; - uint16_t pColNum = 0, cColNum = 0; + uint32_t pColNum = 0, cColNum = 0; int32_t movedNum = 0; bool all = false; @@ -2342,7 +2354,6 @@ int32_t filterMergeGroups(SFilterInfo *info, SFilterGroupCtx** gRes, int32_t *gR } cStart = i; - cEnd = i; cColNum = gRes[i]->colNum; } @@ -2358,7 +2369,7 @@ _return: int32_t filterConvertGroupFromArray(SFilterInfo *info, SArray* group) { size_t groupSize = taosArrayGetSize(group); - info->groupNum = (uint16_t)groupSize; + info->groupNum = (uint32_t)groupSize; if (info->groupNum > 0) { info->groups = calloc(info->groupNum, sizeof(*info->groups)); @@ -2387,7 +2398,7 @@ int32_t filterRewrite(SFilterInfo *info, SFilterGroupCtx** gRes, int32_t gResNum SFilterGroupCtx *res = NULL; SFilterColInfo *colInfo = NULL; int32_t optr = 0; - uint16_t uidx = 0; + uint32_t uidx = 0; memset(info, 0, sizeof(*info)); @@ -2407,7 +2418,7 @@ int32_t filterRewrite(SFilterInfo *info, SFilterGroupCtx** gRes, int32_t gResNum SFilterGroup ng = {0}; - for (uint16_t m = 0; m < res->colNum; ++m) { + for (uint32_t m = 0; m < res->colNum; ++m) { colInfo = &res->colInfo[res->colIdx[m]]; if (FILTER_NO_MERGE_DATA_TYPE(colInfo->dataType)) { assert(colInfo->type == RANGE_TYPE_UNIT); @@ -2443,13 +2454,13 @@ int32_t filterRewrite(SFilterInfo *info, SFilterGroupCtx** gRes, int32_t gResNum } int32_t filterGenerateColRange(SFilterInfo *info, SFilterGroupCtx** gRes, int32_t gResNum) { - uint16_t *idxs = NULL; - uint16_t colNum = 0; + uint32_t *idxs = NULL; + uint32_t colNum = 0; SFilterGroupCtx *res = NULL; - uint16_t *idxNum = calloc(info->fields[FLD_TYPE_COLUMN].num, sizeof(*idxNum)); + uint32_t *idxNum = calloc(info->fields[FLD_TYPE_COLUMN].num, sizeof(*idxNum)); for (int32_t i = 0; i < gResNum; ++i) { - for (uint16_t m = 0; m < gRes[i]->colNum; ++m) { + for (uint32_t m = 0; m < gRes[i]->colNum; ++m) { SFilterColInfo *colInfo = &gRes[i]->colInfo[gRes[i]->colIdx[m]]; if (FILTER_NO_MERGE_DATA_TYPE(colInfo->dataType)) { continue; @@ -2459,7 +2470,7 @@ int32_t filterGenerateColRange(SFilterInfo *info, SFilterGroupCtx** gRes, int32_ } } - for (uint16_t i = 0; i < info->fields[FLD_TYPE_COLUMN].num; ++i) { + for (uint32_t i = 0; i < info->fields[FLD_TYPE_COLUMN].num; ++i) { if (idxNum[i] < gResNum) { continue; } @@ -2480,9 +2491,9 @@ int32_t filterGenerateColRange(SFilterInfo *info, SFilterGroupCtx** gRes, int32_ for (int32_t i = 0; i < gResNum; ++i) { res = gRes[i]; - uint16_t n = 0; + uint32_t n = 0; - for (uint16_t m = 0; m < info->colRangeNum; ++m) { + for (uint32_t m = 0; m < info->colRangeNum; ++m) { for (; n < res->colNum; ++n) { if (res->colIdx[n] < idxs[m]) { continue; @@ -2530,7 +2541,7 @@ _return: } int32_t filterPostProcessRange(SFilterInfo *info) { - for (uint16_t i = 0; i < info->colRangeNum; ++i) { + for (uint32_t i = 0; i < info->colRangeNum; ++i) { SFilterRangeCtx* ctx = info->colRange[i]; SFilterRangeNode *r = ctx->rs; while (r) { @@ -2548,7 +2559,7 @@ int32_t filterGenerateComInfo(SFilterInfo *info) { info->blkUnitRes = malloc(sizeof(*info->blkUnitRes) * info->unitNum); info->blkUnits = malloc(sizeof(*info->blkUnits) * (info->unitNum + 1) * info->groupNum); - for (uint16_t i = 0; i < info->unitNum; ++i) { + for (uint32_t i = 0; i < info->unitNum; ++i) { SFilterUnit *unit = &info->units[i]; info->cunits[i].func = filterGetCompFuncIdx(FILTER_UNIT_DATA_TYPE(unit), unit->compare.optr); @@ -2576,7 +2587,7 @@ int32_t filterGenerateComInfo(SFilterInfo *info) { } int32_t filterUpdateComUnits(SFilterInfo *info) { - for (uint16_t i = 0; i < info->unitNum; ++i) { + for (uint32_t i = 0; i < info->unitNum; ++i) { SFilterUnit *unit = &info->units[i]; info->cunits[i].colData = FILTER_UNIT_COL_DATA(info, unit, 0); @@ -2591,7 +2602,7 @@ int32_t filterRmUnitByRange(SFilterInfo *info, SDataStatis *pDataStatis, int32_t memset(info->blkUnitRes, 0, sizeof(*info->blkUnitRes) * info->unitNum); - for (int32_t k = 0; k < info->unitNum; ++k) { + for (uint32_t k = 0; k < info->unitNum; ++k) { int32_t index = -1; SFilterComUnit *cunit = &info->cunits[k]; @@ -2708,8 +2719,8 @@ int32_t filterRmUnitByRange(SFilterInfo *info, SDataStatis *pDataStatis, int32_t info->blkGroupNum = info->groupNum; - uint16_t *unitNum = info->blkUnits; - uint16_t *unitIdx = unitNum + 1; + uint32_t *unitNum = info->blkUnits; + uint32_t *unitIdx = unitNum + 1; int32_t all = 0, empty = 0; for (uint32_t g = 0; g < info->groupNum; ++g) { @@ -2719,7 +2730,7 @@ int32_t filterRmUnitByRange(SFilterInfo *info, SDataStatis *pDataStatis, int32_t empty = 0; for (uint32_t u = 0; u < group->unitNum; ++u) { - uint16_t uidx = group->unitIdxs[u]; + uint32_t uidx = group->unitIdxs[u]; if (info->blkUnitRes[uidx] == 1) { --(*unitNum); all = 1; @@ -2766,7 +2777,7 @@ _return: bool filterExecuteBasedOnStatisImpl(void *pinfo, int32_t numOfRows, int8_t** p, SDataStatis *statis, int16_t numOfCols) { SFilterInfo *info = (SFilterInfo *)pinfo; bool all = true; - uint16_t *unitIdx = NULL; + uint32_t *unitIdx = NULL; if (*p == NULL) { *p = calloc(numOfRows, sizeof(int8_t)); @@ -2778,7 +2789,7 @@ bool filterExecuteBasedOnStatisImpl(void *pinfo, int32_t numOfRows, int8_t** p, unitIdx = info->blkUnits; for (uint32_t g = 0; g < info->blkGroupNum; ++g) { - uint16_t unitNum = *(unitIdx++); + uint32_t unitNum = *(unitIdx++); for (uint32_t u = 0; u < unitNum; ++u) { SFilterComUnit *cunit = &info->cunits[*(unitIdx + u)]; void *colData = (char *)cunit->colData + cunit->dataSize * i; @@ -2878,7 +2889,7 @@ static FORCE_INLINE bool filterExecuteImplIsNull(void *pinfo, int32_t numOfRows, } for (int32_t i = 0; i < numOfRows; ++i) { - uint16_t uidx = info->groups[0].unitIdxs[0]; + uint32_t uidx = info->groups[0].unitIdxs[0]; void *colData = (char *)info->cunits[uidx].colData + info->cunits[uidx].dataSize * i; (*p)[i] = ((colData == NULL) || isNull(colData, info->cunits[uidx].dataType)); if ((*p)[i] == 0) { @@ -2901,7 +2912,7 @@ static FORCE_INLINE bool filterExecuteImplNotNull(void *pinfo, int32_t numOfRows } for (int32_t i = 0; i < numOfRows; ++i) { - uint16_t uidx = info->groups[0].unitIdxs[0]; + uint32_t uidx = info->groups[0].unitIdxs[0]; void *colData = (char *)info->cunits[uidx].colData + info->cunits[uidx].dataSize * i; (*p)[i] = ((colData != NULL) && !isNull(colData, info->cunits[uidx].dataType)); if ((*p)[i] == 0) { @@ -2962,7 +2973,7 @@ bool filterExecuteImplMisc(void *pinfo, int32_t numOfRows, int8_t** p, SDataStat } for (int32_t i = 0; i < numOfRows; ++i) { - uint16_t uidx = info->groups[0].unitIdxs[0]; + uint32_t uidx = info->groups[0].unitIdxs[0]; void *colData = (char *)info->cunits[uidx].colData + info->cunits[uidx].dataSize * i; if (colData == NULL || isNull(colData, info->cunits[uidx].dataType)) { (*p)[i] = 0; @@ -3008,7 +3019,7 @@ bool filterExecuteImpl(void *pinfo, int32_t numOfRows, int8_t** p, SDataStatis * for (uint32_t g = 0; g < info->groupNum; ++g) { SFilterGroup *group = &info->groups[g]; for (uint32_t u = 0; u < group->unitNum; ++u) { - uint16_t uidx = group->unitIdxs[u]; + uint32_t uidx = group->unitIdxs[u]; SFilterComUnit *cunit = &info->cunits[uidx]; void *colData = (char *)cunit->colData + cunit->dataSize * i; @@ -3152,7 +3163,7 @@ int32_t filterSetColFieldData(SFilterInfo *info, void *param, filer_get_col_from return TSDB_CODE_SUCCESS; } - for (uint16_t i = 0; i < info->fields[FLD_TYPE_COLUMN].num; ++i) { + for (uint32_t i = 0; i < info->fields[FLD_TYPE_COLUMN].num; ++i) { SFilterField* fi = &info->fields[FLD_TYPE_COLUMN].fields[i]; SSchema* sch = fi->desc; @@ -3240,7 +3251,7 @@ bool filterRangeExecute(SFilterInfo *info, SDataStatis *pDataStatis, int32_t num bool ret = true; void *minVal, *maxVal; - for (int32_t k = 0; k < info->colRangeNum; ++k) { + for (uint32_t k = 0; k < info->colRangeNum; ++k) { int32_t index = -1; SFilterRangeCtx *ctx = info->colRange[k]; for(int32_t i = 0; i < numOfCols; ++i) { @@ -3323,7 +3334,7 @@ int32_t filterGetTimeRange(SFilterInfo *info, STimeWindow *win) { int32_t code = 0; bool empty = false, all = false; - for (int32_t i = 0; i < info->groupNum; ++i) { + for (uint32_t i = 0; i < info->groupNum; ++i) { SFilterGroup *group = &info->groups[i]; if (group->unitNum > 1) { cur = tmpc; @@ -3333,8 +3344,8 @@ int32_t filterGetTimeRange(SFilterInfo *info, STimeWindow *win) { optr = TSDB_RELATION_OR; } - for (int32_t u = 0; u < group->unitNum; ++u) { - uint16_t uidx = group->unitIdxs[u]; + for (uint32_t u = 0; u < group->unitNum; ++u) { + uint32_t uidx = group->unitIdxs[u]; SFilterUnit *unit = &info->units[uidx]; uint8_t raOptr = FILTER_UNIT_OPTR(unit); @@ -3407,7 +3418,7 @@ _return: int32_t filterConverNcharColumns(SFilterInfo* info, int32_t rows, bool *gotNchar) { - for (uint16_t i = 0; i < info->fields[FLD_TYPE_COLUMN].num; ++i) { + for (uint32_t i = 0; i < info->fields[FLD_TYPE_COLUMN].num; ++i) { SFilterField* fi = &info->fields[FLD_TYPE_COLUMN].fields[i]; int32_t type = FILTER_GET_COL_FIELD_TYPE(fi); if (type == TSDB_DATA_TYPE_NCHAR) { @@ -3438,7 +3449,7 @@ int32_t filterConverNcharColumns(SFilterInfo* info, int32_t rows, bool *gotNchar } int32_t filterFreeNcharColumns(SFilterInfo* info) { - for (uint16_t i = 0; i < info->fields[FLD_TYPE_COLUMN].num; ++i) { + for (uint32_t i = 0; i < info->fields[FLD_TYPE_COLUMN].num; ++i) { SFilterField* fi = &info->fields[FLD_TYPE_COLUMN].fields[i]; int32_t type = FILTER_GET_COL_FIELD_TYPE(fi); if (type == TSDB_DATA_TYPE_NCHAR) { diff --git a/src/query/src/qPlan.c b/src/query/src/qPlan.c index abfa20714b333754478e5c48b9265f839b05a4b1..27a22f70832dc9669aa473b03820d84d4736b497 100644 --- a/src/query/src/qPlan.c +++ b/src/query/src/qPlan.c @@ -538,9 +538,9 @@ SArray* createTableScanPlan(SQueryAttr* pQueryAttr) { } else { if (pQueryAttr->queryBlockDist) { op = OP_TableBlockInfoScan; - } else if (pQueryAttr->tsCompQuery || pQueryAttr->pointInterpQuery || pQueryAttr->diffQuery) { + } else if (pQueryAttr->tsCompQuery || pQueryAttr->diffQuery) { op = OP_TableSeqScan; - } else if (pQueryAttr->needReverseScan) { + } else if (pQueryAttr->needReverseScan || pQueryAttr->pointInterpQuery) { op = OP_DataBlocksOptScan; } else { op = OP_TableScan; @@ -564,20 +564,15 @@ SArray* createExecOperatorPlan(SQueryAttr* pQueryAttr) { op = OP_Distinct; taosArrayPush(plan, &op); } + } else if (pQueryAttr->pointInterpQuery) { + op = OP_TimeEvery; + taosArrayPush(plan, &op); } else if (pQueryAttr->interval.interval > 0) { if (pQueryAttr->stableQuery) { - if (pQueryAttr->pointInterpQuery) { - op = OP_AllMultiTableTimeInterval; - } else { - op = OP_MultiTableTimeInterval; - } + op = OP_MultiTableTimeInterval; taosArrayPush(plan, &op); } else { - if (pQueryAttr->pointInterpQuery) { - op = OP_AllTimeWindow; - } else { - op = OP_TimeWindow; - } + op = OP_TimeWindow; taosArrayPush(plan, &op); if (pQueryAttr->pExpr2 != NULL) { @@ -704,7 +699,7 @@ SArray* createGlobalMergePlan(SQueryAttr* pQueryAttr) { } // fill operator - if (pQueryAttr->fillType != TSDB_FILL_NONE && pQueryAttr->interval.interval > 0) { + if (pQueryAttr->fillType != TSDB_FILL_NONE && pQueryAttr->interval.interval > 0 && !pQueryAttr->pointInterpQuery) { op = OP_Fill; taosArrayPush(plan, &op); } diff --git a/src/query/src/qSqlParser.c b/src/query/src/qSqlParser.c index 07ff79b16155eba158e2cffc24be7dbe1c3d098f..21723d6b7190d974c6c519521ebe10949e39c9f8 100644 --- a/src/query/src/qSqlParser.c +++ b/src/query/src/qSqlParser.c @@ -192,6 +192,65 @@ tSqlExpr *tSqlExprCreateIdValue(SSqlInfo* pInfo, SStrToken *pToken, int32_t optr return pSqlExpr; } + +tSqlExpr *tSqlExprCreateTimestamp(SStrToken *pToken, int32_t optrType) { + tSqlExpr *pSqlExpr = calloc(1, sizeof(tSqlExpr)); + + if (pToken != NULL) { + pSqlExpr->exprToken = *pToken; + } + + if (optrType == TK_INTEGER || optrType == TK_STRING) { + if (pToken) { + toTSDBType(pToken->type); + tVariantCreate(&pSqlExpr->value, pToken); + } + pSqlExpr->tokenId = optrType; + pSqlExpr->type = SQL_NODE_VALUE; + } else if (optrType == TK_NOW) { + // 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_NS_TIMESTAMP; + } else if (optrType == TK_PLUS || optrType == TK_MINUS) { + // use nanosecond by default + // TODO set value after getting database precision + if (pToken) { + char unit = 0; + int32_t ret = parseAbsoluteDuration(pToken->z, pToken->n, &pSqlExpr->value.i64, &unit, TSDB_TIME_PRECISION_NANO); + if (ret != TSDB_CODE_SUCCESS) { + terrno = TSDB_CODE_TSC_SQL_SYNTAX_ERROR; + } + } + + if (optrType == TK_PLUS) { + pSqlExpr->value.i64 += taosGetTimestamp(TSDB_TIME_PRECISION_NANO); + } else { + pSqlExpr->value.i64 = taosGetTimestamp(TSDB_TIME_PRECISION_NANO) - pSqlExpr->value.i64; + } + + pSqlExpr->flags |= 1 << EXPR_FLAG_NS_TIMESTAMP; + pSqlExpr->value.nType = TSDB_DATA_TYPE_BIGINT; + pSqlExpr->tokenId = TK_TIMESTAMP; + pSqlExpr->type = SQL_NODE_VALUE; + } else { + // Here it must be the column name (tk_id) if it is not a number or string. + assert(optrType == TK_ID || optrType == TK_ALL); + if (pToken != NULL) { + pSqlExpr->columnName = *pToken; + } + + pSqlExpr->tokenId = optrType; + pSqlExpr->type = SQL_NODE_TABLE_COLUMN; + } + + return pSqlExpr; +} + + + /* * pList is the parameters for function with id(optType) * function name is denoted by pFunctionToken @@ -751,7 +810,7 @@ void tSetColumnType(TAOS_FIELD *pField, SStrToken *type) { SSqlNode *tSetQuerySqlNode(SStrToken *pSelectToken, SArray *pSelNodeList, SRelationInfo *pFrom, tSqlExpr *pWhere, SArray *pGroupby, SArray *pSortOrder, SIntervalVal *pInterval, SSessionWindowVal *pSession, SWindowStateVal *pWindowStateVal, SStrToken *pSliding, SArray *pFill, SLimitVal *pLimit, - SLimitVal *psLimit, tSqlExpr *pHaving) { + SLimitVal *psLimit, tSqlExpr *pHaving, SRangeVal *pRange) { assert(pSelNodeList != NULL); SSqlNode *pSqlNode = calloc(1, sizeof(SSqlNode)); @@ -767,7 +826,10 @@ SSqlNode *tSetQuerySqlNode(SStrToken *pSelectToken, SArray *pSelNodeList, SRelat pSqlNode->pWhere = pWhere; pSqlNode->fillType = pFill; pSqlNode->pHaving = pHaving; - + if (pRange) { + pSqlNode->pRange = *pRange; + } + if (pLimit != NULL) { pSqlNode->limit = *pLimit; } else { diff --git a/src/query/src/sql.c b/src/query/src/sql.c index 4232076fe682fc50ba50eeba937e5e5398ca20c2..eee1880ab92cc938dfd60760ec8e30981d31cf7b 100644 --- a/src/query/src/sql.c +++ b/src/query/src/sql.c @@ -23,6 +23,7 @@ ** input grammar file: */ #include +#include /************ Begin %include sections from the grammar ************************/ #include @@ -76,8 +77,10 @@ ** zero the stack is dynamically sized using realloc() ** ParseARG_SDECL A static variable declaration for the %extra_argument ** ParseARG_PDECL A parameter declaration for the %extra_argument +** ParseARG_PARAM Code to pass %extra_argument as a subroutine parameter ** ParseARG_STORE Code to store %extra_argument into yypParser ** ParseARG_FETCH Code to extract %extra_argument from yypParser +** ParseCTX_* As ParseARG_ except for %extra_context ** YYERRORSYMBOL is the code number of the error symbol. If not ** defined, then do no error processing. ** YYNSTATE the combined number of states. @@ -97,50 +100,59 @@ #endif /************* Begin control #defines *****************************************/ #define YYCODETYPE unsigned short int -#define YYNOCODE 281 +#define YYNOCODE 282 #define YYACTIONTYPE unsigned short int #define ParseTOKENTYPE SStrToken typedef union { int yyinit; ParseTOKENTYPE yy0; - SWindowStateVal yy48; - SCreateTableSql* yy102; - tVariant yy106; - int64_t yy109; - SSessionWindowVal yy139; - SCreateDbInfo yy142; - tSqlExpr* yy146; - SRelationInfo* yy164; - int yy172; - SArray* yy221; + tVariant yy2; + SCreateDbInfo yy10; + int32_t yy40; + SSqlNode* yy68; + SCreatedTableInfo yy72; + SLimitVal yy114; + SRangeVal yy144; + SCreateTableSql* yy170; SIntervalVal yy280; - int32_t yy340; - SSqlNode* yy376; - SCreatedTableInfo yy416; - SLimitVal yy454; - SCreateAcctInfo yy491; - TAOS_FIELD yy503; + int yy281; + SSessionWindowVal yy295; + SArray* yy345; + tSqlExpr* yy418; + SCreateAcctInfo yy427; + SWindowStateVal yy432; + SRelationInfo* yy484; + TAOS_FIELD yy487; + int64_t yy525; } YYMINORTYPE; #ifndef YYSTACKDEPTH #define YYSTACKDEPTH 100 #endif #define ParseARG_SDECL SSqlInfo* pInfo; #define ParseARG_PDECL ,SSqlInfo* pInfo -#define ParseARG_FETCH SSqlInfo* pInfo = yypParser->pInfo -#define ParseARG_STORE yypParser->pInfo = pInfo +#define ParseARG_PARAM ,pInfo +#define ParseARG_FETCH SSqlInfo* pInfo=yypParser->pInfo; +#define ParseARG_STORE yypParser->pInfo=pInfo; +#define ParseCTX_SDECL +#define ParseCTX_PDECL +#define ParseCTX_PARAM +#define ParseCTX_FETCH +#define ParseCTX_STORE #define YYFALLBACK 1 -#define YYNSTATE 368 -#define YYNRULE 294 -#define YYNTOKEN 198 -#define YY_MAX_SHIFT 367 -#define YY_MIN_SHIFTREDUCE 576 -#define YY_MAX_SHIFTREDUCE 869 -#define YY_ERROR_ACTION 870 -#define YY_ACCEPT_ACTION 871 -#define YY_NO_ACTION 872 -#define YY_MIN_REDUCE 873 -#define YY_MAX_REDUCE 1166 +#define YYNSTATE 379 +#define YYNRULE 303 +#define YYNRULE_WITH_ACTION 303 +#define YYNTOKEN 199 +#define YY_MAX_SHIFT 378 +#define YY_MIN_SHIFTREDUCE 594 +#define YY_MAX_SHIFTREDUCE 896 +#define YY_ERROR_ACTION 897 +#define YY_ACCEPT_ACTION 898 +#define YY_NO_ACTION 899 +#define YY_MIN_REDUCE 900 +#define YY_MAX_REDUCE 1202 /************* End control #defines *******************************************/ +#define YY_NLOOKAHEAD ((int)(sizeof(yy_lookahead)/sizeof(yy_lookahead[0]))) /* Define the yytestcase() macro to be a no-op if is not already defined ** otherwise. @@ -205,293 +217,298 @@ typedef union { ** yy_default[] Default action for each state. ** *********** Begin parsing tables **********************************************/ -#define YY_ACTTAB_COUNT (773) +#define YY_ACTTAB_COUNT (791) static const YYACTIONTYPE yy_action[] = { - /* 0 */ 23, 628, 366, 235, 1051, 208, 241, 712, 211, 629, - /* 10 */ 1029, 871, 367, 59, 60, 173, 63, 64, 1042, 1142, - /* 20 */ 255, 53, 52, 51, 628, 62, 324, 67, 65, 68, - /* 30 */ 66, 157, 629, 286, 238, 58, 57, 344, 343, 56, - /* 40 */ 55, 54, 59, 60, 247, 63, 64, 252, 1029, 255, - /* 50 */ 53, 52, 51, 664, 62, 324, 67, 65, 68, 66, - /* 60 */ 999, 1042, 997, 998, 58, 57, 209, 1000, 56, 55, - /* 70 */ 54, 1001, 1048, 1002, 1003, 58, 57, 277, 1015, 56, - /* 80 */ 55, 54, 59, 60, 215, 63, 64, 38, 82, 255, - /* 90 */ 53, 52, 51, 88, 62, 324, 67, 65, 68, 66, - /* 100 */ 284, 283, 249, 752, 58, 57, 1029, 211, 56, 55, - /* 110 */ 54, 322, 59, 61, 806, 63, 64, 1042, 1143, 255, - /* 120 */ 53, 52, 51, 628, 62, 324, 67, 65, 68, 66, - /* 130 */ 45, 629, 237, 239, 58, 57, 1026, 164, 56, 55, - /* 140 */ 54, 60, 1023, 63, 64, 771, 772, 255, 53, 52, - /* 150 */ 51, 628, 62, 324, 67, 65, 68, 66, 812, 629, - /* 160 */ 815, 216, 58, 57, 322, 100, 56, 55, 54, 577, - /* 170 */ 578, 579, 580, 581, 582, 583, 584, 585, 586, 587, - /* 180 */ 588, 589, 590, 155, 164, 236, 63, 64, 756, 248, - /* 190 */ 255, 53, 52, 51, 269, 62, 324, 67, 65, 68, - /* 200 */ 66, 1017, 354, 273, 272, 58, 57, 251, 217, 56, - /* 210 */ 55, 54, 1089, 44, 320, 361, 360, 319, 318, 317, - /* 220 */ 359, 316, 315, 314, 358, 313, 357, 356, 38, 1137, - /* 230 */ 56, 55, 54, 24, 29, 991, 979, 980, 981, 982, - /* 240 */ 983, 984, 985, 986, 987, 988, 989, 990, 992, 993, - /* 250 */ 214, 14, 254, 821, 1136, 96, 810, 222, 813, 1090, - /* 260 */ 816, 296, 97, 139, 138, 137, 221, 211, 254, 821, - /* 270 */ 329, 88, 810, 256, 813, 1135, 816, 1025, 1143, 819, - /* 280 */ 67, 65, 68, 66, 326, 99, 233, 234, 58, 57, - /* 290 */ 325, 164, 56, 55, 54, 1012, 1013, 35, 1016, 811, - /* 300 */ 231, 814, 233, 234, 258, 5, 41, 182, 45, 365, - /* 310 */ 364, 148, 181, 106, 111, 102, 110, 164, 263, 736, - /* 320 */ 38, 1028, 733, 85, 734, 86, 735, 154, 152, 151, - /* 330 */ 276, 309, 80, 211, 38, 69, 123, 117, 128, 229, - /* 340 */ 362, 960, 232, 127, 1143, 133, 136, 126, 202, 200, - /* 350 */ 198, 69, 260, 261, 130, 197, 143, 142, 141, 140, - /* 360 */ 280, 44, 280, 361, 360, 245, 94, 1100, 359, 1026, - /* 370 */ 822, 817, 358, 38, 357, 356, 38, 818, 38, 246, - /* 380 */ 259, 38, 257, 1026, 332, 331, 822, 817, 825, 38, - /* 390 */ 298, 264, 93, 818, 265, 38, 262, 38, 339, 338, - /* 400 */ 38, 264, 178, 264, 922, 125, 788, 81, 932, 3, - /* 410 */ 193, 192, 179, 749, 1027, 192, 212, 354, 333, 73, - /* 420 */ 820, 334, 1026, 335, 923, 1026, 336, 1026, 1, 180, - /* 430 */ 1026, 192, 76, 95, 340, 1162, 737, 738, 1026, 9, - /* 440 */ 341, 1014, 342, 278, 1026, 346, 1026, 83, 768, 1026, - /* 450 */ 778, 779, 722, 808, 301, 724, 303, 39, 253, 723, - /* 460 */ 34, 74, 159, 787, 70, 26, 39, 844, 39, 70, - /* 470 */ 98, 823, 77, 70, 627, 79, 16, 116, 15, 115, - /* 480 */ 6, 25, 18, 213, 17, 25, 274, 741, 25, 742, - /* 490 */ 739, 809, 740, 304, 20, 122, 19, 121, 22, 218, - /* 500 */ 21, 135, 134, 210, 219, 220, 1154, 711, 156, 1099, - /* 510 */ 1050, 224, 225, 226, 223, 207, 243, 1096, 1095, 244, - /* 520 */ 345, 48, 1061, 1058, 1059, 1063, 1082, 158, 163, 1043, - /* 530 */ 281, 153, 292, 1081, 285, 174, 1024, 175, 1022, 176, - /* 540 */ 177, 937, 306, 307, 308, 311, 312, 46, 767, 165, - /* 550 */ 205, 42, 1040, 323, 931, 330, 1161, 113, 1160, 75, - /* 560 */ 1157, 183, 337, 1153, 240, 119, 78, 287, 289, 1152, - /* 570 */ 299, 50, 166, 1149, 184, 297, 957, 167, 43, 40, - /* 580 */ 47, 206, 919, 293, 129, 917, 131, 295, 132, 915, - /* 590 */ 291, 914, 168, 266, 195, 196, 911, 288, 910, 909, - /* 600 */ 908, 907, 906, 905, 199, 201, 902, 900, 898, 896, - /* 610 */ 203, 893, 204, 889, 49, 310, 279, 84, 89, 290, - /* 620 */ 1083, 355, 348, 124, 347, 349, 350, 230, 351, 250, - /* 630 */ 305, 352, 353, 363, 869, 267, 268, 868, 227, 270, - /* 640 */ 271, 228, 107, 936, 935, 108, 867, 850, 275, 849, - /* 650 */ 913, 280, 300, 912, 10, 87, 282, 744, 144, 187, - /* 660 */ 904, 186, 958, 185, 188, 189, 191, 190, 145, 903, - /* 670 */ 959, 146, 995, 2, 147, 30, 895, 169, 170, 894, - /* 680 */ 171, 172, 4, 33, 1005, 90, 769, 160, 162, 780, - /* 690 */ 161, 242, 774, 91, 31, 776, 92, 294, 11, 32, - /* 700 */ 12, 13, 27, 28, 302, 101, 99, 642, 104, 36, - /* 710 */ 103, 675, 37, 677, 105, 674, 673, 671, 670, 669, - /* 720 */ 666, 632, 321, 109, 7, 327, 328, 824, 8, 112, - /* 730 */ 826, 114, 71, 72, 118, 714, 39, 713, 710, 120, - /* 740 */ 658, 656, 648, 654, 650, 652, 646, 644, 680, 679, - /* 750 */ 678, 676, 672, 668, 667, 194, 630, 594, 873, 872, - /* 760 */ 872, 872, 872, 872, 872, 872, 872, 872, 872, 872, - /* 770 */ 872, 149, 150, + /* 0 */ 245, 646, 377, 238, 1056, 23, 214, 730, 1078, 647, + /* 10 */ 682, 898, 378, 59, 60, 251, 63, 64, 1178, 1056, + /* 20 */ 259, 53, 52, 51, 646, 62, 335, 67, 65, 68, + /* 30 */ 66, 159, 647, 337, 175, 58, 57, 355, 354, 56, + /* 40 */ 55, 54, 59, 60, 253, 63, 64, 1055, 1056, 259, + /* 50 */ 53, 52, 51, 297, 62, 335, 67, 65, 68, 66, + /* 60 */ 1026, 1069, 1024, 1025, 58, 57, 1198, 1027, 56, 55, + /* 70 */ 54, 1028, 256, 1029, 1030, 58, 57, 1075, 281, 56, + /* 80 */ 55, 54, 59, 60, 166, 63, 64, 38, 84, 259, + /* 90 */ 53, 52, 51, 90, 62, 335, 67, 65, 68, 66, + /* 100 */ 1069, 288, 287, 646, 58, 57, 333, 29, 56, 55, + /* 110 */ 54, 647, 59, 61, 833, 63, 64, 241, 1042, 259, + /* 120 */ 53, 52, 51, 646, 62, 335, 67, 65, 68, 66, + /* 130 */ 45, 647, 240, 214, 58, 57, 1053, 852, 56, 55, + /* 140 */ 54, 60, 1050, 63, 64, 1179, 282, 259, 53, 52, + /* 150 */ 51, 166, 62, 335, 67, 65, 68, 66, 38, 309, + /* 160 */ 39, 95, 58, 57, 798, 799, 56, 55, 54, 595, + /* 170 */ 596, 597, 598, 599, 600, 601, 602, 603, 604, 605, + /* 180 */ 606, 607, 608, 157, 1069, 239, 63, 64, 770, 252, + /* 190 */ 259, 53, 52, 51, 255, 62, 335, 67, 65, 68, + /* 200 */ 66, 242, 365, 249, 333, 58, 57, 1053, 211, 56, + /* 210 */ 55, 54, 257, 44, 331, 372, 371, 330, 329, 328, + /* 220 */ 370, 327, 326, 325, 369, 324, 368, 367, 1126, 16, + /* 230 */ 307, 15, 166, 24, 6, 1018, 1006, 1007, 1008, 1009, + /* 240 */ 1010, 1011, 1012, 1013, 1014, 1015, 1016, 1017, 1019, 1020, + /* 250 */ 217, 166, 258, 848, 212, 214, 837, 225, 840, 839, + /* 260 */ 843, 842, 99, 141, 140, 139, 224, 1179, 258, 848, + /* 270 */ 340, 90, 837, 774, 840, 273, 843, 56, 55, 54, + /* 280 */ 67, 65, 68, 66, 277, 276, 236, 237, 58, 57, + /* 290 */ 336, 767, 56, 55, 54, 1039, 1040, 35, 1043, 260, + /* 300 */ 373, 987, 236, 237, 5, 41, 185, 268, 45, 1125, + /* 310 */ 38, 184, 108, 113, 104, 112, 754, 9, 181, 751, + /* 320 */ 262, 752, 786, 753, 38, 102, 789, 267, 96, 38, + /* 330 */ 320, 280, 838, 82, 841, 69, 125, 119, 130, 218, + /* 340 */ 232, 949, 118, 129, 117, 135, 138, 128, 195, 264, + /* 350 */ 265, 69, 293, 294, 132, 205, 203, 201, 38, 1052, + /* 360 */ 214, 1044, 200, 145, 144, 143, 142, 127, 38, 250, + /* 370 */ 849, 844, 1179, 1053, 344, 38, 38, 845, 1053, 365, + /* 380 */ 846, 44, 38, 372, 371, 83, 849, 844, 370, 376, + /* 390 */ 375, 150, 369, 845, 368, 367, 38, 263, 38, 261, + /* 400 */ 268, 343, 342, 345, 269, 219, 266, 1053, 350, 349, + /* 410 */ 815, 182, 14, 346, 220, 268, 98, 1053, 87, 1041, + /* 420 */ 347, 351, 88, 97, 1053, 1053, 1054, 352, 156, 154, + /* 430 */ 153, 1053, 959, 755, 756, 950, 34, 243, 85, 195, + /* 440 */ 795, 353, 195, 357, 805, 1053, 101, 1053, 806, 1, + /* 450 */ 183, 3, 196, 847, 161, 284, 292, 291, 70, 284, + /* 460 */ 75, 78, 26, 740, 312, 742, 314, 741, 814, 315, + /* 470 */ 871, 850, 835, 645, 18, 81, 17, 39, 39, 70, + /* 480 */ 100, 70, 137, 136, 25, 25, 759, 25, 760, 20, + /* 490 */ 757, 19, 758, 124, 22, 123, 21, 289, 1173, 1172, + /* 500 */ 1171, 234, 79, 76, 235, 215, 216, 729, 290, 1190, + /* 510 */ 836, 221, 213, 222, 223, 1136, 227, 228, 229, 1135, + /* 520 */ 247, 226, 278, 1132, 210, 1131, 248, 356, 48, 1070, + /* 530 */ 158, 1077, 1088, 1067, 155, 1085, 1086, 285, 1118, 1090, + /* 540 */ 160, 165, 1117, 303, 1051, 177, 283, 86, 178, 1049, + /* 550 */ 179, 180, 964, 785, 317, 318, 296, 319, 322, 323, + /* 560 */ 167, 46, 244, 298, 310, 168, 208, 42, 334, 958, + /* 570 */ 341, 1197, 115, 1196, 1193, 186, 348, 1189, 121, 300, + /* 580 */ 80, 77, 50, 308, 1188, 1185, 169, 306, 187, 304, + /* 590 */ 984, 43, 302, 40, 47, 209, 946, 131, 944, 133, + /* 600 */ 134, 942, 941, 299, 270, 198, 199, 938, 937, 936, + /* 610 */ 935, 934, 933, 932, 202, 204, 929, 927, 925, 923, + /* 620 */ 206, 920, 295, 207, 916, 49, 321, 91, 301, 1119, + /* 630 */ 366, 126, 359, 358, 360, 361, 363, 233, 362, 254, + /* 640 */ 316, 364, 374, 896, 271, 272, 895, 275, 274, 894, + /* 650 */ 876, 230, 963, 231, 109, 962, 110, 877, 279, 284, + /* 660 */ 311, 10, 286, 762, 30, 89, 940, 939, 190, 194, + /* 670 */ 146, 985, 188, 189, 192, 191, 931, 193, 147, 148, + /* 680 */ 930, 4, 149, 1022, 92, 986, 922, 176, 172, 170, + /* 690 */ 173, 171, 174, 33, 921, 794, 2, 73, 792, 791, + /* 700 */ 1032, 788, 787, 74, 164, 796, 162, 246, 807, 163, + /* 710 */ 31, 801, 93, 32, 803, 94, 305, 11, 12, 13, + /* 720 */ 27, 313, 36, 28, 101, 103, 106, 660, 695, 693, + /* 730 */ 692, 105, 691, 689, 688, 37, 107, 687, 684, 650, + /* 740 */ 111, 332, 7, 853, 851, 8, 338, 339, 39, 114, + /* 750 */ 71, 116, 72, 120, 732, 731, 728, 122, 676, 674, + /* 760 */ 666, 672, 668, 670, 664, 662, 698, 697, 696, 694, + /* 770 */ 690, 686, 685, 197, 648, 612, 900, 899, 899, 899, + /* 780 */ 899, 899, 899, 899, 899, 899, 899, 899, 899, 151, + /* 790 */ 152, }; static const YYCODETYPE yy_lookahead[] = { - /* 0 */ 268, 1, 201, 202, 201, 268, 247, 5, 268, 9, - /* 10 */ 251, 199, 200, 13, 14, 255, 16, 17, 249, 279, + /* 0 */ 247, 1, 201, 202, 251, 269, 269, 5, 201, 9, + /* 10 */ 5, 199, 200, 13, 14, 247, 16, 17, 281, 251, /* 20 */ 20, 21, 22, 23, 1, 25, 26, 27, 28, 29, - /* 30 */ 30, 201, 9, 273, 265, 35, 36, 35, 36, 39, - /* 40 */ 40, 41, 13, 14, 247, 16, 17, 208, 251, 20, - /* 50 */ 21, 22, 23, 5, 25, 26, 27, 28, 29, 30, - /* 60 */ 225, 249, 227, 228, 35, 36, 268, 232, 39, 40, - /* 70 */ 41, 236, 269, 238, 239, 35, 36, 265, 0, 39, - /* 80 */ 40, 41, 13, 14, 268, 16, 17, 201, 88, 20, + /* 30 */ 30, 201, 9, 15, 256, 35, 36, 35, 36, 39, + /* 40 */ 40, 41, 13, 14, 247, 16, 17, 251, 251, 20, + /* 50 */ 21, 22, 23, 275, 25, 26, 27, 28, 29, 30, + /* 60 */ 225, 249, 227, 228, 35, 36, 251, 232, 39, 40, + /* 70 */ 41, 236, 208, 238, 239, 35, 36, 270, 266, 39, + /* 80 */ 40, 41, 13, 14, 201, 16, 17, 201, 88, 20, /* 90 */ 21, 22, 23, 84, 25, 26, 27, 28, 29, 30, - /* 100 */ 270, 271, 247, 39, 35, 36, 251, 268, 39, 40, - /* 110 */ 41, 86, 13, 14, 85, 16, 17, 249, 279, 20, + /* 100 */ 249, 271, 272, 1, 35, 36, 86, 84, 39, 40, + /* 110 */ 41, 9, 13, 14, 85, 16, 17, 266, 0, 20, /* 120 */ 21, 22, 23, 1, 25, 26, 27, 28, 29, 30, - /* 130 */ 121, 9, 246, 265, 35, 36, 250, 201, 39, 40, - /* 140 */ 41, 14, 201, 16, 17, 127, 128, 20, 21, 22, - /* 150 */ 23, 1, 25, 26, 27, 28, 29, 30, 5, 9, - /* 160 */ 7, 268, 35, 36, 86, 209, 39, 40, 41, 47, + /* 130 */ 121, 9, 246, 269, 35, 36, 250, 119, 39, 40, + /* 140 */ 41, 14, 201, 16, 17, 281, 85, 20, 21, 22, + /* 150 */ 23, 201, 25, 26, 27, 28, 29, 30, 201, 276, + /* 160 */ 99, 278, 35, 36, 128, 129, 39, 40, 41, 47, /* 170 */ 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, - /* 180 */ 58, 59, 60, 61, 201, 63, 16, 17, 124, 248, - /* 190 */ 20, 21, 22, 23, 144, 25, 26, 27, 28, 29, - /* 200 */ 30, 245, 92, 153, 154, 35, 36, 208, 268, 39, - /* 210 */ 40, 41, 276, 100, 101, 102, 103, 104, 105, 106, - /* 220 */ 107, 108, 109, 110, 111, 112, 113, 114, 201, 268, - /* 230 */ 39, 40, 41, 46, 84, 225, 226, 227, 228, 229, + /* 180 */ 58, 59, 60, 61, 249, 63, 16, 17, 39, 248, + /* 190 */ 20, 21, 22, 23, 208, 25, 26, 27, 28, 29, + /* 200 */ 30, 266, 92, 246, 86, 35, 36, 250, 269, 39, + /* 210 */ 40, 41, 62, 100, 101, 102, 103, 104, 105, 106, + /* 220 */ 107, 108, 109, 110, 111, 112, 113, 114, 278, 148, + /* 230 */ 280, 150, 201, 46, 84, 225, 226, 227, 228, 229, /* 240 */ 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, - /* 250 */ 63, 84, 1, 2, 268, 88, 5, 70, 7, 276, - /* 260 */ 9, 278, 209, 76, 77, 78, 79, 268, 1, 2, - /* 270 */ 83, 84, 5, 208, 7, 268, 9, 250, 279, 126, - /* 280 */ 27, 28, 29, 30, 15, 118, 35, 36, 35, 36, - /* 290 */ 39, 201, 39, 40, 41, 242, 243, 244, 245, 5, - /* 300 */ 268, 7, 35, 36, 70, 64, 65, 66, 121, 67, - /* 310 */ 68, 69, 71, 72, 73, 74, 75, 201, 70, 2, - /* 320 */ 201, 251, 5, 85, 7, 85, 9, 64, 65, 66, - /* 330 */ 143, 90, 145, 268, 201, 84, 64, 65, 66, 152, - /* 340 */ 223, 224, 268, 71, 279, 73, 74, 75, 64, 65, - /* 350 */ 66, 84, 35, 36, 82, 71, 72, 73, 74, 75, - /* 360 */ 122, 100, 122, 102, 103, 246, 276, 241, 107, 250, - /* 370 */ 119, 120, 111, 201, 113, 114, 201, 126, 201, 246, - /* 380 */ 146, 201, 148, 250, 150, 151, 119, 120, 119, 201, - /* 390 */ 274, 201, 276, 126, 146, 201, 148, 201, 150, 151, - /* 400 */ 201, 201, 212, 201, 207, 80, 78, 209, 207, 205, - /* 410 */ 206, 214, 212, 99, 212, 214, 268, 92, 246, 99, - /* 420 */ 126, 246, 250, 246, 207, 250, 246, 250, 210, 211, - /* 430 */ 250, 214, 99, 252, 246, 251, 119, 120, 250, 125, - /* 440 */ 246, 243, 246, 85, 250, 246, 250, 266, 85, 250, - /* 450 */ 85, 85, 85, 1, 85, 85, 85, 99, 62, 85, - /* 460 */ 84, 141, 99, 135, 99, 99, 99, 85, 99, 99, - /* 470 */ 99, 85, 139, 99, 85, 84, 147, 147, 149, 149, - /* 480 */ 84, 99, 147, 268, 149, 99, 201, 5, 99, 7, - /* 490 */ 5, 39, 7, 117, 147, 147, 149, 149, 147, 268, - /* 500 */ 149, 80, 81, 268, 268, 268, 251, 116, 201, 241, - /* 510 */ 201, 268, 268, 268, 268, 268, 241, 241, 241, 241, - /* 520 */ 241, 267, 201, 201, 201, 201, 277, 201, 201, 249, - /* 530 */ 249, 62, 201, 277, 272, 253, 249, 201, 201, 201, - /* 540 */ 201, 201, 201, 201, 201, 201, 201, 201, 126, 263, - /* 550 */ 201, 201, 264, 201, 201, 201, 201, 201, 201, 140, - /* 560 */ 201, 201, 201, 201, 272, 201, 138, 272, 272, 201, - /* 570 */ 133, 137, 262, 201, 201, 136, 201, 261, 201, 201, - /* 580 */ 201, 201, 201, 130, 201, 201, 201, 131, 201, 201, - /* 590 */ 129, 201, 260, 201, 201, 201, 201, 132, 201, 201, - /* 600 */ 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, - /* 610 */ 201, 201, 201, 201, 142, 91, 203, 203, 203, 203, - /* 620 */ 203, 115, 53, 98, 97, 94, 96, 203, 57, 203, - /* 630 */ 203, 95, 93, 86, 5, 155, 5, 5, 203, 155, - /* 640 */ 5, 203, 209, 213, 213, 209, 5, 102, 144, 101, - /* 650 */ 203, 122, 117, 203, 84, 123, 99, 85, 204, 216, - /* 660 */ 203, 220, 222, 221, 219, 217, 215, 218, 204, 203, - /* 670 */ 224, 204, 240, 210, 204, 84, 203, 259, 258, 203, - /* 680 */ 257, 256, 205, 254, 240, 99, 85, 84, 99, 85, - /* 690 */ 84, 1, 85, 84, 99, 85, 84, 84, 134, 99, - /* 700 */ 134, 84, 84, 84, 117, 80, 118, 5, 72, 89, - /* 710 */ 88, 5, 89, 9, 88, 5, 5, 5, 5, 5, - /* 720 */ 5, 87, 15, 80, 84, 26, 61, 85, 84, 149, - /* 730 */ 119, 149, 16, 16, 149, 5, 99, 5, 85, 149, - /* 740 */ 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - /* 750 */ 5, 5, 5, 5, 5, 99, 87, 62, 0, 280, - /* 760 */ 280, 280, 280, 280, 280, 280, 280, 280, 280, 280, - /* 770 */ 280, 21, 21, 280, 280, 280, 280, 280, 280, 280, - /* 780 */ 280, 280, 280, 280, 280, 280, 280, 280, 280, 280, - /* 790 */ 280, 280, 280, 280, 280, 280, 280, 280, 280, 280, - /* 800 */ 280, 280, 280, 280, 280, 280, 280, 280, 280, 280, - /* 810 */ 280, 280, 280, 280, 280, 280, 280, 280, 280, 280, - /* 820 */ 280, 280, 280, 280, 280, 280, 280, 280, 280, 280, - /* 830 */ 280, 280, 280, 280, 280, 280, 280, 280, 280, 280, - /* 840 */ 280, 280, 280, 280, 280, 280, 280, 280, 280, 280, - /* 850 */ 280, 280, 280, 280, 280, 280, 280, 280, 280, 280, - /* 860 */ 280, 280, 280, 280, 280, 280, 280, 280, 280, 280, - /* 870 */ 280, 280, 280, 280, 280, 280, 280, 280, 280, 280, - /* 880 */ 280, 280, 280, 280, 280, 280, 280, 280, 280, 280, - /* 890 */ 280, 280, 280, 280, 280, 280, 280, 280, 280, 280, - /* 900 */ 280, 280, 280, 280, 280, 280, 280, 280, 280, 280, - /* 910 */ 280, 280, 280, 280, 280, 280, 280, 280, 280, 280, - /* 920 */ 280, 280, 280, 280, 280, 280, 280, 280, 280, 280, - /* 930 */ 280, 280, 280, 280, 280, 280, 280, 280, 280, 280, - /* 940 */ 280, 280, 280, 280, 280, 280, 280, 280, 280, 280, - /* 950 */ 280, 280, 280, 280, 280, 280, 280, 280, 280, 280, - /* 960 */ 280, 280, 280, 280, 280, 280, 280, 280, 280, 280, - /* 970 */ 280, + /* 250 */ 63, 201, 1, 2, 269, 269, 5, 70, 7, 5, + /* 260 */ 9, 7, 209, 76, 77, 78, 79, 281, 1, 2, + /* 270 */ 83, 84, 5, 124, 7, 145, 9, 39, 40, 41, + /* 280 */ 27, 28, 29, 30, 154, 155, 35, 36, 35, 36, + /* 290 */ 39, 99, 39, 40, 41, 242, 243, 244, 245, 208, + /* 300 */ 223, 224, 35, 36, 64, 65, 66, 201, 121, 278, + /* 310 */ 201, 71, 72, 73, 74, 75, 2, 125, 212, 5, + /* 320 */ 70, 7, 5, 9, 201, 209, 9, 70, 278, 201, + /* 330 */ 90, 144, 5, 146, 7, 84, 64, 65, 66, 269, + /* 340 */ 153, 207, 148, 71, 150, 73, 74, 75, 214, 35, + /* 350 */ 36, 84, 35, 36, 82, 64, 65, 66, 201, 250, + /* 360 */ 269, 245, 71, 72, 73, 74, 75, 80, 201, 246, + /* 370 */ 119, 120, 281, 250, 246, 201, 201, 126, 250, 92, + /* 380 */ 126, 100, 201, 102, 103, 209, 119, 120, 107, 67, + /* 390 */ 68, 69, 111, 126, 113, 114, 201, 147, 201, 149, + /* 400 */ 201, 151, 152, 246, 147, 269, 149, 250, 151, 152, + /* 410 */ 78, 212, 84, 246, 269, 201, 88, 250, 85, 243, + /* 420 */ 246, 246, 85, 252, 250, 250, 212, 246, 64, 65, + /* 430 */ 66, 250, 207, 119, 120, 207, 84, 120, 267, 214, + /* 440 */ 85, 246, 214, 246, 85, 250, 118, 250, 85, 210, + /* 450 */ 211, 205, 206, 126, 99, 122, 35, 36, 99, 122, + /* 460 */ 99, 99, 99, 85, 85, 85, 85, 85, 136, 117, + /* 470 */ 85, 85, 1, 85, 148, 84, 150, 99, 99, 99, + /* 480 */ 99, 99, 80, 81, 99, 99, 5, 99, 7, 148, + /* 490 */ 5, 150, 7, 148, 148, 150, 150, 274, 269, 269, + /* 500 */ 269, 269, 140, 142, 269, 269, 269, 116, 274, 251, + /* 510 */ 39, 269, 269, 269, 269, 241, 269, 269, 269, 241, + /* 520 */ 241, 269, 201, 241, 269, 241, 241, 241, 268, 249, + /* 530 */ 201, 201, 201, 265, 62, 201, 201, 249, 279, 201, + /* 540 */ 201, 201, 279, 201, 249, 253, 203, 203, 201, 201, + /* 550 */ 201, 201, 201, 126, 201, 201, 273, 201, 201, 201, + /* 560 */ 264, 201, 273, 273, 134, 263, 201, 201, 201, 201, + /* 570 */ 201, 201, 201, 201, 201, 201, 201, 201, 201, 273, + /* 580 */ 139, 141, 138, 137, 201, 201, 262, 132, 201, 131, + /* 590 */ 201, 201, 130, 201, 201, 201, 201, 201, 201, 201, + /* 600 */ 201, 201, 201, 133, 201, 201, 201, 201, 201, 201, + /* 610 */ 201, 201, 201, 201, 201, 201, 201, 201, 201, 201, + /* 620 */ 201, 201, 127, 201, 201, 143, 91, 203, 203, 203, + /* 630 */ 115, 98, 53, 97, 94, 96, 95, 203, 57, 203, + /* 640 */ 203, 93, 86, 5, 156, 5, 5, 5, 156, 5, + /* 650 */ 101, 203, 213, 203, 209, 213, 209, 102, 145, 122, + /* 660 */ 117, 84, 99, 85, 84, 123, 203, 203, 216, 215, + /* 670 */ 204, 222, 221, 220, 217, 219, 203, 218, 204, 204, + /* 680 */ 203, 205, 204, 240, 99, 224, 203, 254, 259, 261, + /* 690 */ 258, 260, 257, 255, 203, 85, 210, 99, 126, 126, + /* 700 */ 240, 5, 5, 84, 99, 85, 84, 1, 85, 84, + /* 710 */ 99, 85, 84, 99, 85, 84, 84, 135, 135, 84, + /* 720 */ 84, 117, 89, 84, 118, 80, 72, 5, 9, 5, + /* 730 */ 5, 88, 5, 5, 5, 89, 88, 5, 5, 87, + /* 740 */ 80, 15, 84, 119, 85, 84, 26, 61, 99, 150, + /* 750 */ 16, 150, 16, 150, 5, 5, 85, 150, 5, 5, + /* 760 */ 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + /* 770 */ 5, 5, 5, 99, 87, 62, 0, 282, 282, 282, + /* 780 */ 282, 282, 282, 282, 282, 282, 282, 282, 282, 21, + /* 790 */ 21, 282, 282, 282, 282, 282, 282, 282, 282, 282, + /* 800 */ 282, 282, 282, 282, 282, 282, 282, 282, 282, 282, + /* 810 */ 282, 282, 282, 282, 282, 282, 282, 282, 282, 282, + /* 820 */ 282, 282, 282, 282, 282, 282, 282, 282, 282, 282, + /* 830 */ 282, 282, 282, 282, 282, 282, 282, 282, 282, 282, + /* 840 */ 282, 282, 282, 282, 282, 282, 282, 282, 282, 282, + /* 850 */ 282, 282, 282, 282, 282, 282, 282, 282, 282, 282, + /* 860 */ 282, 282, 282, 282, 282, 282, 282, 282, 282, 282, + /* 870 */ 282, 282, 282, 282, 282, 282, 282, 282, 282, 282, + /* 880 */ 282, 282, 282, 282, 282, 282, 282, 282, 282, 282, + /* 890 */ 282, 282, 282, 282, 282, 282, 282, 282, 282, 282, + /* 900 */ 282, 282, 282, 282, 282, 282, 282, 282, 282, 282, + /* 910 */ 282, 282, 282, 282, 282, 282, 282, 282, 282, 282, + /* 920 */ 282, 282, 282, 282, 282, 282, 282, 282, 282, 282, + /* 930 */ 282, 282, 282, 282, 282, 282, 282, 282, 282, 282, + /* 940 */ 282, 282, 282, 282, 282, 282, 282, 282, 282, 282, + /* 950 */ 282, 282, 282, 282, 282, 282, 282, 282, 282, 282, + /* 960 */ 282, 282, 282, 282, 282, 282, 282, 282, 282, 282, + /* 970 */ 282, 282, 282, 282, 282, 282, 282, 282, 282, 282, + /* 980 */ 282, 282, 282, 282, 282, 282, 282, 282, 282, 282, }; -#define YY_SHIFT_COUNT (367) +#define YY_SHIFT_COUNT (378) #define YY_SHIFT_MIN (0) -#define YY_SHIFT_MAX (758) +#define YY_SHIFT_MAX (776) static const unsigned short int yy_shift_ofst[] = { - /* 0 */ 187, 113, 113, 261, 261, 25, 251, 267, 267, 150, - /* 10 */ 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, - /* 20 */ 23, 23, 23, 0, 122, 267, 317, 317, 317, 9, - /* 30 */ 9, 23, 23, 18, 23, 78, 23, 23, 23, 23, - /* 40 */ 325, 25, 110, 110, 48, 773, 773, 773, 267, 267, + /* 0 */ 187, 113, 113, 281, 281, 20, 251, 267, 267, 23, + /* 10 */ 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, + /* 20 */ 102, 102, 102, 0, 122, 267, 314, 314, 314, 9, + /* 30 */ 9, 102, 102, 36, 102, 118, 102, 102, 102, 102, + /* 40 */ 287, 20, 110, 110, 5, 791, 791, 791, 267, 267, /* 50 */ 267, 267, 267, 267, 267, 267, 267, 267, 267, 267, /* 60 */ 267, 267, 267, 267, 267, 267, 267, 267, 267, 267, - /* 70 */ 317, 317, 317, 2, 2, 2, 2, 2, 2, 2, - /* 80 */ 23, 23, 23, 64, 23, 23, 23, 9, 9, 23, - /* 90 */ 23, 23, 23, 328, 328, 314, 9, 23, 23, 23, - /* 100 */ 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, - /* 110 */ 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, - /* 120 */ 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, - /* 130 */ 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, - /* 140 */ 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, - /* 150 */ 23, 23, 23, 23, 23, 23, 469, 469, 469, 422, - /* 160 */ 422, 422, 422, 469, 469, 428, 419, 437, 434, 439, - /* 170 */ 456, 453, 461, 465, 472, 469, 469, 469, 524, 524, - /* 180 */ 506, 25, 25, 469, 469, 525, 527, 569, 531, 530, - /* 190 */ 571, 536, 539, 506, 48, 469, 469, 547, 547, 469, - /* 200 */ 547, 469, 547, 469, 469, 773, 773, 29, 69, 69, - /* 210 */ 99, 69, 127, 170, 241, 253, 253, 253, 253, 253, - /* 220 */ 253, 272, 284, 40, 40, 40, 40, 234, 248, 50, - /* 230 */ 167, 191, 191, 153, 294, 242, 263, 358, 238, 240, - /* 240 */ 363, 365, 366, 320, 333, 367, 369, 370, 371, 374, - /* 250 */ 376, 382, 386, 452, 396, 269, 389, 329, 330, 335, - /* 260 */ 482, 485, 347, 348, 391, 351, 421, 629, 480, 631, - /* 270 */ 632, 484, 635, 641, 545, 548, 504, 529, 535, 570, - /* 280 */ 532, 572, 591, 557, 586, 601, 603, 604, 606, 607, - /* 290 */ 589, 609, 610, 612, 690, 613, 595, 564, 600, 566, - /* 300 */ 617, 535, 618, 587, 619, 588, 625, 620, 622, 636, - /* 310 */ 702, 623, 626, 704, 706, 710, 711, 712, 713, 714, - /* 320 */ 715, 634, 707, 643, 640, 642, 611, 644, 699, 665, - /* 330 */ 716, 580, 582, 637, 637, 637, 637, 717, 585, 590, - /* 340 */ 637, 637, 637, 730, 732, 653, 637, 735, 736, 737, - /* 350 */ 738, 739, 740, 741, 742, 743, 744, 745, 746, 747, - /* 360 */ 748, 749, 656, 669, 750, 751, 695, 758, + /* 70 */ 314, 314, 314, 317, 317, 2, 2, 2, 2, 2, + /* 80 */ 2, 2, 102, 102, 102, 149, 102, 102, 102, 9, + /* 90 */ 9, 102, 102, 102, 102, 332, 332, 192, 9, 102, + /* 100 */ 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, + /* 110 */ 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, + /* 120 */ 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, + /* 130 */ 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, + /* 140 */ 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, + /* 150 */ 102, 102, 102, 102, 102, 102, 102, 102, 472, 472, + /* 160 */ 472, 427, 427, 427, 427, 472, 472, 441, 440, 430, + /* 170 */ 444, 446, 455, 458, 462, 470, 495, 482, 472, 472, + /* 180 */ 472, 535, 535, 515, 20, 20, 472, 472, 533, 536, + /* 190 */ 579, 540, 539, 581, 541, 548, 515, 5, 472, 472, + /* 200 */ 556, 556, 472, 556, 472, 556, 472, 472, 791, 791, + /* 210 */ 29, 69, 69, 99, 69, 127, 170, 240, 253, 253, + /* 220 */ 253, 253, 253, 253, 272, 291, 40, 40, 40, 40, + /* 230 */ 250, 257, 130, 328, 238, 238, 254, 327, 322, 364, + /* 240 */ 61, 333, 337, 421, 355, 359, 363, 361, 362, 378, + /* 250 */ 379, 380, 381, 382, 352, 385, 386, 471, 150, 18, + /* 260 */ 388, 81, 194, 326, 481, 485, 341, 345, 391, 346, + /* 270 */ 402, 638, 488, 640, 641, 492, 642, 644, 555, 549, + /* 280 */ 513, 537, 543, 577, 542, 578, 580, 563, 585, 610, + /* 290 */ 598, 572, 573, 696, 697, 619, 620, 622, 623, 625, + /* 300 */ 626, 605, 628, 629, 631, 706, 632, 611, 582, 614, + /* 310 */ 583, 635, 543, 636, 604, 639, 606, 645, 633, 643, + /* 320 */ 654, 722, 646, 648, 719, 724, 725, 727, 728, 729, + /* 330 */ 732, 733, 652, 726, 660, 658, 659, 624, 661, 720, + /* 340 */ 686, 734, 599, 601, 649, 649, 649, 649, 736, 603, + /* 350 */ 607, 649, 649, 649, 749, 750, 671, 649, 753, 754, + /* 360 */ 755, 756, 757, 758, 759, 760, 761, 762, 763, 764, + /* 370 */ 765, 766, 767, 674, 687, 768, 769, 713, 776, }; -#define YY_REDUCE_COUNT (206) -#define YY_REDUCE_MIN (-268) -#define YY_REDUCE_MAX (477) +#define YY_REDUCE_COUNT (209) +#define YY_REDUCE_MIN (-264) +#define YY_REDUCE_MAX (491) static const short yy_reduce_ofst[] = { - /* 0 */ -188, 10, 10, -165, -165, 53, -161, -1, 65, -170, - /* 10 */ -114, -17, 116, 119, 133, 172, 175, 177, 180, 188, - /* 20 */ 194, 196, 199, -197, -199, -260, -241, -203, -145, -231, - /* 30 */ -132, -64, 90, -240, -59, -44, 190, 200, 202, 27, - /* 40 */ 197, 198, 201, 217, 117, 181, 218, 204, -268, -263, - /* 50 */ -202, -184, -107, -60, -39, -14, 7, 32, 74, 148, - /* 60 */ 215, 231, 235, 236, 237, 243, 244, 245, 246, 247, - /* 70 */ 70, 184, 255, 126, 268, 275, 276, 277, 278, 279, - /* 80 */ 285, 307, 309, 254, 321, 322, 323, 280, 281, 324, - /* 90 */ 326, 327, 331, 249, 256, 282, 287, 336, 337, 338, - /* 100 */ 339, 340, 341, 342, 343, 344, 345, 346, 349, 350, - /* 110 */ 352, 353, 354, 355, 356, 357, 359, 360, 361, 362, - /* 120 */ 364, 368, 372, 373, 375, 377, 378, 379, 380, 381, - /* 130 */ 383, 384, 385, 387, 388, 390, 392, 393, 394, 395, - /* 140 */ 397, 398, 399, 400, 401, 402, 403, 404, 405, 406, - /* 150 */ 407, 408, 409, 410, 411, 412, 413, 414, 415, 262, - /* 160 */ 292, 295, 296, 416, 417, 288, 286, 310, 316, 332, - /* 170 */ 418, 420, 423, 425, 429, 424, 426, 427, 430, 431, - /* 180 */ 432, 433, 436, 435, 438, 440, 442, 441, 443, 445, - /* 190 */ 448, 449, 451, 444, 446, 447, 450, 454, 464, 457, - /* 200 */ 467, 466, 470, 473, 476, 463, 477, + /* 0 */ -188, 10, 10, -165, -165, 53, -136, -14, 91, -170, + /* 10 */ -114, -50, -117, -43, 123, 128, 157, 167, 174, 175, + /* 20 */ 181, 195, 197, -193, -199, -263, -247, -232, -203, -149, + /* 30 */ -65, 31, 50, -222, -59, 116, 106, 199, 214, 109, + /* 40 */ 134, 176, 225, 228, 77, 171, 239, 246, -264, -61, + /* 50 */ -15, 70, 136, 145, 229, 230, 231, 232, 235, 236, + /* 60 */ 237, 242, 243, 244, 245, 247, 248, 249, 252, 255, + /* 70 */ -204, -185, 258, 223, 234, 274, 278, 279, 282, 284, + /* 80 */ 285, 286, 321, 329, 330, 260, 331, 334, 335, 280, + /* 90 */ 288, 338, 339, 340, 342, 259, 263, 292, 295, 347, + /* 100 */ 348, 349, 350, 351, 353, 354, 356, 357, 358, 360, + /* 110 */ 365, 366, 367, 368, 369, 370, 371, 372, 373, 374, + /* 120 */ 375, 376, 377, 383, 384, 387, 389, 390, 392, 393, + /* 130 */ 394, 395, 396, 397, 398, 399, 400, 401, 403, 404, + /* 140 */ 405, 406, 407, 408, 409, 410, 411, 412, 413, 414, + /* 150 */ 415, 416, 417, 418, 419, 420, 422, 423, 343, 344, + /* 160 */ 424, 283, 289, 290, 306, 425, 426, 268, 296, 302, + /* 170 */ 324, 428, 431, 429, 432, 435, 438, 433, 434, 436, + /* 180 */ 437, 439, 442, 443, 445, 447, 448, 450, 449, 451, + /* 190 */ 453, 452, 456, 457, 459, 454, 460, 461, 463, 464, + /* 200 */ 466, 474, 473, 475, 477, 478, 483, 491, 486, 476, }; static const YYACTIONTYPE yy_default[] = { - /* 0 */ 870, 994, 933, 1004, 920, 930, 1145, 1145, 1145, 870, - /* 10 */ 870, 870, 870, 870, 870, 870, 870, 870, 870, 870, - /* 20 */ 870, 870, 870, 1052, 890, 1145, 870, 870, 870, 870, - /* 30 */ 870, 870, 870, 1067, 870, 930, 870, 870, 870, 870, - /* 40 */ 940, 930, 940, 940, 870, 1047, 978, 996, 870, 870, - /* 50 */ 870, 870, 870, 870, 870, 870, 870, 870, 870, 870, - /* 60 */ 870, 870, 870, 870, 870, 870, 870, 870, 870, 870, - /* 70 */ 870, 870, 870, 870, 870, 870, 870, 870, 870, 870, - /* 80 */ 870, 870, 870, 1054, 1060, 1057, 870, 870, 870, 1062, - /* 90 */ 870, 870, 870, 1086, 1086, 1045, 870, 870, 870, 870, - /* 100 */ 870, 870, 870, 870, 870, 870, 870, 870, 870, 870, - /* 110 */ 870, 870, 870, 870, 870, 870, 870, 870, 870, 870, - /* 120 */ 870, 870, 870, 870, 870, 870, 870, 870, 870, 918, - /* 130 */ 870, 916, 870, 870, 870, 870, 870, 870, 870, 870, - /* 140 */ 870, 870, 870, 870, 870, 870, 870, 870, 901, 870, - /* 150 */ 870, 870, 870, 870, 870, 888, 892, 892, 892, 870, - /* 160 */ 870, 870, 870, 892, 892, 1093, 1097, 1079, 1091, 1087, - /* 170 */ 1074, 1072, 1070, 1078, 1101, 892, 892, 892, 938, 938, - /* 180 */ 934, 930, 930, 892, 892, 956, 954, 952, 944, 950, - /* 190 */ 946, 948, 942, 921, 870, 892, 892, 928, 928, 892, - /* 200 */ 928, 892, 928, 892, 892, 978, 996, 870, 1102, 1092, - /* 210 */ 870, 1144, 1132, 1131, 870, 1140, 1139, 1138, 1130, 1129, - /* 220 */ 1128, 870, 870, 1124, 1127, 1126, 1125, 870, 870, 870, - /* 230 */ 870, 1134, 1133, 870, 870, 870, 870, 870, 870, 870, - /* 240 */ 870, 870, 870, 1098, 1094, 870, 870, 870, 870, 870, - /* 250 */ 870, 870, 870, 870, 1104, 870, 870, 870, 870, 870, - /* 260 */ 870, 870, 870, 870, 1006, 870, 870, 870, 870, 870, - /* 270 */ 870, 870, 870, 870, 870, 870, 870, 1044, 870, 870, - /* 280 */ 870, 870, 870, 1056, 1055, 870, 870, 870, 870, 870, - /* 290 */ 870, 870, 870, 870, 870, 870, 1088, 870, 1080, 870, - /* 300 */ 870, 1018, 870, 870, 870, 870, 870, 870, 870, 870, - /* 310 */ 870, 870, 870, 870, 870, 870, 870, 870, 870, 870, - /* 320 */ 870, 870, 870, 870, 870, 870, 870, 870, 870, 870, - /* 330 */ 870, 870, 870, 1163, 1158, 1159, 1156, 870, 870, 870, - /* 340 */ 1155, 1150, 1151, 870, 870, 870, 1148, 870, 870, 870, - /* 350 */ 870, 870, 870, 870, 870, 870, 870, 870, 870, 870, - /* 360 */ 870, 870, 962, 870, 899, 897, 870, 870, + /* 0 */ 897, 1021, 960, 1031, 947, 957, 1181, 1181, 1181, 897, + /* 10 */ 897, 897, 897, 897, 897, 897, 897, 897, 897, 897, + /* 20 */ 897, 897, 897, 1079, 917, 1181, 897, 897, 897, 897, + /* 30 */ 897, 897, 897, 1103, 897, 957, 897, 897, 897, 897, + /* 40 */ 967, 957, 967, 967, 897, 1074, 1005, 1023, 897, 897, + /* 50 */ 897, 897, 897, 897, 897, 897, 897, 897, 897, 897, + /* 60 */ 897, 897, 897, 897, 897, 897, 897, 897, 897, 897, + /* 70 */ 897, 897, 897, 897, 897, 897, 897, 897, 897, 897, + /* 80 */ 897, 897, 897, 897, 897, 1081, 1087, 1084, 897, 897, + /* 90 */ 897, 1089, 897, 897, 897, 1122, 1122, 1072, 897, 897, + /* 100 */ 897, 897, 897, 897, 897, 897, 897, 897, 897, 897, + /* 110 */ 897, 897, 897, 897, 897, 897, 897, 897, 897, 897, + /* 120 */ 897, 897, 897, 897, 897, 897, 897, 897, 897, 897, + /* 130 */ 897, 945, 897, 943, 897, 897, 897, 897, 897, 897, + /* 140 */ 897, 897, 897, 897, 897, 897, 897, 897, 897, 897, + /* 150 */ 928, 897, 897, 897, 897, 897, 897, 915, 919, 919, + /* 160 */ 919, 897, 897, 897, 897, 919, 919, 1129, 1133, 1115, + /* 170 */ 1127, 1123, 1110, 1108, 1106, 1114, 1099, 1137, 919, 919, + /* 180 */ 919, 965, 965, 961, 957, 957, 919, 919, 983, 981, + /* 190 */ 979, 971, 977, 973, 975, 969, 948, 897, 919, 919, + /* 200 */ 955, 955, 919, 955, 919, 955, 919, 919, 1005, 1023, + /* 210 */ 897, 1138, 1128, 897, 1180, 1168, 1167, 897, 1176, 1175, + /* 220 */ 1174, 1166, 1165, 1164, 897, 897, 1160, 1163, 1162, 1161, + /* 230 */ 897, 897, 897, 897, 1170, 1169, 897, 897, 897, 897, + /* 240 */ 897, 897, 897, 1096, 897, 897, 897, 1134, 1130, 897, + /* 250 */ 897, 897, 897, 897, 897, 897, 897, 897, 1140, 897, + /* 260 */ 897, 897, 897, 897, 897, 897, 897, 897, 1033, 897, + /* 270 */ 897, 897, 897, 897, 897, 897, 897, 897, 897, 897, + /* 280 */ 897, 1071, 897, 897, 897, 897, 897, 1083, 1082, 897, + /* 290 */ 897, 897, 897, 897, 897, 897, 897, 897, 897, 897, + /* 300 */ 897, 897, 897, 897, 897, 897, 897, 1124, 897, 1116, + /* 310 */ 897, 897, 1045, 897, 897, 897, 897, 897, 897, 897, + /* 320 */ 897, 897, 897, 897, 897, 897, 897, 897, 897, 897, + /* 330 */ 897, 897, 897, 897, 897, 897, 897, 897, 897, 897, + /* 340 */ 897, 897, 897, 897, 1199, 1194, 1195, 1192, 897, 897, + /* 350 */ 897, 1191, 1186, 1187, 897, 897, 897, 1184, 897, 897, + /* 360 */ 897, 897, 897, 897, 897, 897, 897, 897, 897, 897, + /* 370 */ 897, 897, 897, 989, 897, 926, 924, 897, 897, }; /********** End of lemon-generated parsing tables *****************************/ @@ -638,6 +655,7 @@ static const YYCODETYPE yyFallback[] = { 0, /* DISTINCT => nothing */ 0, /* FROM => nothing */ 0, /* VARIABLE => nothing */ + 0, /* RANGE => nothing */ 0, /* INTERVAL => nothing */ 0, /* EVERY => nothing */ 0, /* SESSION => nothing */ @@ -748,6 +766,7 @@ struct yyParser { int yyerrcnt; /* Shifts left before out of the error */ #endif ParseARG_SDECL /* A place to hold %extra_argument */ + ParseCTX_SDECL /* A place to hold %extra_context */ #if YYSTACKDEPTH<=0 int yystksz; /* Current side of the stack */ yyStackEntry *yystack; /* The parser's stack */ @@ -922,78 +941,78 @@ static const char *const yyTokenName[] = { /* 124 */ "DISTINCT", /* 125 */ "FROM", /* 126 */ "VARIABLE", - /* 127 */ "INTERVAL", - /* 128 */ "EVERY", - /* 129 */ "SESSION", - /* 130 */ "STATE_WINDOW", - /* 131 */ "FILL", - /* 132 */ "SLIDING", - /* 133 */ "ORDER", - /* 134 */ "BY", - /* 135 */ "ASC", - /* 136 */ "GROUP", - /* 137 */ "HAVING", - /* 138 */ "LIMIT", - /* 139 */ "OFFSET", - /* 140 */ "SLIMIT", - /* 141 */ "SOFFSET", - /* 142 */ "WHERE", - /* 143 */ "RESET", - /* 144 */ "QUERY", - /* 145 */ "SYNCDB", - /* 146 */ "ADD", - /* 147 */ "COLUMN", - /* 148 */ "MODIFY", - /* 149 */ "TAG", - /* 150 */ "CHANGE", - /* 151 */ "SET", - /* 152 */ "KILL", - /* 153 */ "CONNECTION", - /* 154 */ "STREAM", - /* 155 */ "COLON", - /* 156 */ "ABORT", - /* 157 */ "AFTER", - /* 158 */ "ATTACH", - /* 159 */ "BEFORE", - /* 160 */ "BEGIN", - /* 161 */ "CASCADE", - /* 162 */ "CLUSTER", - /* 163 */ "CONFLICT", - /* 164 */ "COPY", - /* 165 */ "DEFERRED", - /* 166 */ "DELIMITERS", - /* 167 */ "DETACH", - /* 168 */ "EACH", - /* 169 */ "END", - /* 170 */ "EXPLAIN", - /* 171 */ "FAIL", - /* 172 */ "FOR", - /* 173 */ "IGNORE", - /* 174 */ "IMMEDIATE", - /* 175 */ "INITIALLY", - /* 176 */ "INSTEAD", - /* 177 */ "KEY", - /* 178 */ "OF", - /* 179 */ "RAISE", - /* 180 */ "REPLACE", - /* 181 */ "RESTRICT", - /* 182 */ "ROW", - /* 183 */ "STATEMENT", - /* 184 */ "TRIGGER", - /* 185 */ "VIEW", - /* 186 */ "IPTOKEN", - /* 187 */ "SEMI", - /* 188 */ "NONE", - /* 189 */ "PREV", - /* 190 */ "LINEAR", - /* 191 */ "IMPORT", - /* 192 */ "TBNAME", - /* 193 */ "JOIN", - /* 194 */ "INSERT", - /* 195 */ "INTO", - /* 196 */ "VALUES", - /* 197 */ "FILE", - /* 198 */ "error", + /* 127 */ "RANGE", + /* 128 */ "INTERVAL", + /* 129 */ "EVERY", + /* 130 */ "SESSION", + /* 131 */ "STATE_WINDOW", + /* 132 */ "FILL", + /* 133 */ "SLIDING", + /* 134 */ "ORDER", + /* 135 */ "BY", + /* 136 */ "ASC", + /* 137 */ "GROUP", + /* 138 */ "HAVING", + /* 139 */ "LIMIT", + /* 140 */ "OFFSET", + /* 141 */ "SLIMIT", + /* 142 */ "SOFFSET", + /* 143 */ "WHERE", + /* 144 */ "RESET", + /* 145 */ "QUERY", + /* 146 */ "SYNCDB", + /* 147 */ "ADD", + /* 148 */ "COLUMN", + /* 149 */ "MODIFY", + /* 150 */ "TAG", + /* 151 */ "CHANGE", + /* 152 */ "SET", + /* 153 */ "KILL", + /* 154 */ "CONNECTION", + /* 155 */ "STREAM", + /* 156 */ "COLON", + /* 157 */ "ABORT", + /* 158 */ "AFTER", + /* 159 */ "ATTACH", + /* 160 */ "BEFORE", + /* 161 */ "BEGIN", + /* 162 */ "CASCADE", + /* 163 */ "CLUSTER", + /* 164 */ "CONFLICT", + /* 165 */ "COPY", + /* 166 */ "DEFERRED", + /* 167 */ "DELIMITERS", + /* 168 */ "DETACH", + /* 169 */ "EACH", + /* 170 */ "END", + /* 171 */ "EXPLAIN", + /* 172 */ "FAIL", + /* 173 */ "FOR", + /* 174 */ "IGNORE", + /* 175 */ "IMMEDIATE", + /* 176 */ "INITIALLY", + /* 177 */ "INSTEAD", + /* 178 */ "KEY", + /* 179 */ "OF", + /* 180 */ "RAISE", + /* 181 */ "REPLACE", + /* 182 */ "RESTRICT", + /* 183 */ "ROW", + /* 184 */ "STATEMENT", + /* 185 */ "TRIGGER", + /* 186 */ "VIEW", + /* 187 */ "IPTOKEN", + /* 188 */ "SEMI", + /* 189 */ "NONE", + /* 190 */ "PREV", + /* 191 */ "LINEAR", + /* 192 */ "IMPORT", + /* 193 */ "TBNAME", + /* 194 */ "JOIN", + /* 195 */ "INSERT", + /* 196 */ "INTO", + /* 197 */ "VALUES", + /* 198 */ "FILE", /* 199 */ "program", /* 200 */ "cmd", /* 201 */ "ids", @@ -1050,31 +1069,33 @@ static const char *const yyTokenName[] = { /* 252 */ "selcollist", /* 253 */ "from", /* 254 */ "where_opt", - /* 255 */ "interval_option", - /* 256 */ "sliding_opt", - /* 257 */ "session_option", - /* 258 */ "windowstate_option", - /* 259 */ "fill_opt", - /* 260 */ "groupby_opt", - /* 261 */ "having_opt", - /* 262 */ "orderby_opt", - /* 263 */ "slimit_opt", - /* 264 */ "limit_opt", - /* 265 */ "union", - /* 266 */ "sclp", - /* 267 */ "distinct", - /* 268 */ "expr", - /* 269 */ "as", - /* 270 */ "tablelist", - /* 271 */ "sub", - /* 272 */ "tmvar", - /* 273 */ "intervalKey", - /* 274 */ "sortlist", - /* 275 */ "sortitem", - /* 276 */ "item", - /* 277 */ "sortorder", - /* 278 */ "grouplist", - /* 279 */ "expritem", + /* 255 */ "range_option", + /* 256 */ "interval_option", + /* 257 */ "sliding_opt", + /* 258 */ "session_option", + /* 259 */ "windowstate_option", + /* 260 */ "fill_opt", + /* 261 */ "groupby_opt", + /* 262 */ "having_opt", + /* 263 */ "orderby_opt", + /* 264 */ "slimit_opt", + /* 265 */ "limit_opt", + /* 266 */ "union", + /* 267 */ "sclp", + /* 268 */ "distinct", + /* 269 */ "expr", + /* 270 */ "as", + /* 271 */ "tablelist", + /* 272 */ "sub", + /* 273 */ "tmvar", + /* 274 */ "timestamp", + /* 275 */ "intervalKey", + /* 276 */ "sortlist", + /* 277 */ "sortitem", + /* 278 */ "item", + /* 279 */ "sortorder", + /* 280 */ "grouplist", + /* 281 */ "expritem", }; #endif /* defined(YYCOVERAGE) || !defined(NDEBUG) */ @@ -1249,7 +1270,7 @@ static const char *const yyRuleName[] = { /* 164 */ "tagitem ::= MINUS FLOAT", /* 165 */ "tagitem ::= PLUS INTEGER", /* 166 */ "tagitem ::= PLUS FLOAT", - /* 167 */ "select ::= SELECT selcollist from where_opt interval_option sliding_opt session_option windowstate_option fill_opt groupby_opt having_opt orderby_opt slimit_opt limit_opt", + /* 167 */ "select ::= SELECT selcollist from where_opt range_option interval_option sliding_opt session_option windowstate_option fill_opt groupby_opt having_opt orderby_opt slimit_opt limit_opt", /* 168 */ "select ::= LP select RP", /* 169 */ "union ::= select", /* 170 */ "union ::= union UNION ALL select", @@ -1274,108 +1295,117 @@ static const char *const yyRuleName[] = { /* 189 */ "tablelist ::= tablelist COMMA ids cpxName", /* 190 */ "tablelist ::= tablelist COMMA ids cpxName ids", /* 191 */ "tmvar ::= VARIABLE", - /* 192 */ "interval_option ::= intervalKey LP tmvar RP", - /* 193 */ "interval_option ::= intervalKey LP tmvar COMMA tmvar RP", - /* 194 */ "interval_option ::=", - /* 195 */ "intervalKey ::= INTERVAL", - /* 196 */ "intervalKey ::= EVERY", - /* 197 */ "session_option ::=", - /* 198 */ "session_option ::= SESSION LP ids cpxName COMMA tmvar RP", - /* 199 */ "windowstate_option ::=", - /* 200 */ "windowstate_option ::= STATE_WINDOW LP ids RP", - /* 201 */ "fill_opt ::=", - /* 202 */ "fill_opt ::= FILL LP ID COMMA tagitemlist RP", - /* 203 */ "fill_opt ::= FILL LP ID RP", - /* 204 */ "sliding_opt ::= SLIDING LP tmvar RP", - /* 205 */ "sliding_opt ::=", - /* 206 */ "orderby_opt ::=", - /* 207 */ "orderby_opt ::= ORDER BY sortlist", - /* 208 */ "sortlist ::= sortlist COMMA item sortorder", - /* 209 */ "sortlist ::= item sortorder", - /* 210 */ "item ::= ids cpxName", - /* 211 */ "sortorder ::= ASC", - /* 212 */ "sortorder ::= DESC", - /* 213 */ "sortorder ::=", - /* 214 */ "groupby_opt ::=", - /* 215 */ "groupby_opt ::= GROUP BY grouplist", - /* 216 */ "grouplist ::= grouplist COMMA item", - /* 217 */ "grouplist ::= item", - /* 218 */ "having_opt ::=", - /* 219 */ "having_opt ::= HAVING expr", - /* 220 */ "limit_opt ::=", - /* 221 */ "limit_opt ::= LIMIT signed", - /* 222 */ "limit_opt ::= LIMIT signed OFFSET signed", - /* 223 */ "limit_opt ::= LIMIT signed COMMA signed", - /* 224 */ "slimit_opt ::=", - /* 225 */ "slimit_opt ::= SLIMIT signed", - /* 226 */ "slimit_opt ::= SLIMIT signed SOFFSET signed", - /* 227 */ "slimit_opt ::= SLIMIT signed COMMA signed", - /* 228 */ "where_opt ::=", - /* 229 */ "where_opt ::= WHERE expr", - /* 230 */ "expr ::= LP expr RP", - /* 231 */ "expr ::= ID", - /* 232 */ "expr ::= ID DOT ID", - /* 233 */ "expr ::= ID DOT STAR", - /* 234 */ "expr ::= INTEGER", - /* 235 */ "expr ::= MINUS INTEGER", - /* 236 */ "expr ::= PLUS INTEGER", - /* 237 */ "expr ::= FLOAT", - /* 238 */ "expr ::= MINUS FLOAT", - /* 239 */ "expr ::= PLUS FLOAT", - /* 240 */ "expr ::= STRING", - /* 241 */ "expr ::= NOW", - /* 242 */ "expr ::= VARIABLE", - /* 243 */ "expr ::= PLUS VARIABLE", - /* 244 */ "expr ::= MINUS VARIABLE", - /* 245 */ "expr ::= BOOL", - /* 246 */ "expr ::= NULL", - /* 247 */ "expr ::= ID LP exprlist RP", - /* 248 */ "expr ::= ID LP STAR RP", - /* 249 */ "expr ::= expr IS NULL", - /* 250 */ "expr ::= expr IS NOT NULL", - /* 251 */ "expr ::= expr LT expr", - /* 252 */ "expr ::= expr GT expr", - /* 253 */ "expr ::= expr LE expr", - /* 254 */ "expr ::= expr GE expr", - /* 255 */ "expr ::= expr NE expr", - /* 256 */ "expr ::= expr EQ expr", - /* 257 */ "expr ::= expr BETWEEN expr AND expr", - /* 258 */ "expr ::= expr AND expr", - /* 259 */ "expr ::= expr OR expr", - /* 260 */ "expr ::= expr PLUS expr", - /* 261 */ "expr ::= expr MINUS expr", - /* 262 */ "expr ::= expr STAR expr", - /* 263 */ "expr ::= expr SLASH expr", - /* 264 */ "expr ::= expr REM expr", - /* 265 */ "expr ::= expr LIKE expr", - /* 266 */ "expr ::= expr MATCH expr", - /* 267 */ "expr ::= expr NMATCH expr", - /* 268 */ "expr ::= expr IN LP exprlist RP", - /* 269 */ "exprlist ::= exprlist COMMA expritem", - /* 270 */ "exprlist ::= expritem", - /* 271 */ "expritem ::= expr", - /* 272 */ "expritem ::=", - /* 273 */ "cmd ::= RESET QUERY CACHE", - /* 274 */ "cmd ::= SYNCDB ids REPLICA", - /* 275 */ "cmd ::= ALTER TABLE ids cpxName ADD COLUMN columnlist", - /* 276 */ "cmd ::= ALTER TABLE ids cpxName DROP COLUMN ids", - /* 277 */ "cmd ::= ALTER TABLE ids cpxName MODIFY COLUMN columnlist", - /* 278 */ "cmd ::= ALTER TABLE ids cpxName ADD TAG columnlist", - /* 279 */ "cmd ::= ALTER TABLE ids cpxName DROP TAG ids", - /* 280 */ "cmd ::= ALTER TABLE ids cpxName CHANGE TAG ids ids", - /* 281 */ "cmd ::= ALTER TABLE ids cpxName SET TAG ids EQ tagitem", - /* 282 */ "cmd ::= ALTER TABLE ids cpxName MODIFY TAG columnlist", - /* 283 */ "cmd ::= ALTER STABLE ids cpxName ADD COLUMN columnlist", - /* 284 */ "cmd ::= ALTER STABLE ids cpxName DROP COLUMN ids", - /* 285 */ "cmd ::= ALTER STABLE ids cpxName MODIFY COLUMN columnlist", - /* 286 */ "cmd ::= ALTER STABLE ids cpxName ADD TAG columnlist", - /* 287 */ "cmd ::= ALTER STABLE ids cpxName DROP TAG ids", - /* 288 */ "cmd ::= ALTER STABLE ids cpxName CHANGE TAG ids ids", - /* 289 */ "cmd ::= ALTER STABLE ids cpxName SET TAG ids EQ tagitem", - /* 290 */ "cmd ::= ALTER STABLE ids cpxName MODIFY TAG columnlist", - /* 291 */ "cmd ::= KILL CONNECTION INTEGER", - /* 292 */ "cmd ::= KILL STREAM INTEGER COLON INTEGER", - /* 293 */ "cmd ::= KILL QUERY INTEGER COLON INTEGER", + /* 192 */ "timestamp ::= INTEGER", + /* 193 */ "timestamp ::= MINUS INTEGER", + /* 194 */ "timestamp ::= PLUS INTEGER", + /* 195 */ "timestamp ::= STRING", + /* 196 */ "timestamp ::= NOW", + /* 197 */ "timestamp ::= NOW PLUS VARIABLE", + /* 198 */ "timestamp ::= NOW MINUS VARIABLE", + /* 199 */ "range_option ::=", + /* 200 */ "range_option ::= RANGE LP timestamp COMMA timestamp RP", + /* 201 */ "interval_option ::= intervalKey LP tmvar RP", + /* 202 */ "interval_option ::= intervalKey LP tmvar COMMA tmvar RP", + /* 203 */ "interval_option ::=", + /* 204 */ "intervalKey ::= INTERVAL", + /* 205 */ "intervalKey ::= EVERY", + /* 206 */ "session_option ::=", + /* 207 */ "session_option ::= SESSION LP ids cpxName COMMA tmvar RP", + /* 208 */ "windowstate_option ::=", + /* 209 */ "windowstate_option ::= STATE_WINDOW LP ids RP", + /* 210 */ "fill_opt ::=", + /* 211 */ "fill_opt ::= FILL LP ID COMMA tagitemlist RP", + /* 212 */ "fill_opt ::= FILL LP ID RP", + /* 213 */ "sliding_opt ::= SLIDING LP tmvar RP", + /* 214 */ "sliding_opt ::=", + /* 215 */ "orderby_opt ::=", + /* 216 */ "orderby_opt ::= ORDER BY sortlist", + /* 217 */ "sortlist ::= sortlist COMMA item sortorder", + /* 218 */ "sortlist ::= item sortorder", + /* 219 */ "item ::= ids cpxName", + /* 220 */ "sortorder ::= ASC", + /* 221 */ "sortorder ::= DESC", + /* 222 */ "sortorder ::=", + /* 223 */ "groupby_opt ::=", + /* 224 */ "groupby_opt ::= GROUP BY grouplist", + /* 225 */ "grouplist ::= grouplist COMMA item", + /* 226 */ "grouplist ::= item", + /* 227 */ "having_opt ::=", + /* 228 */ "having_opt ::= HAVING expr", + /* 229 */ "limit_opt ::=", + /* 230 */ "limit_opt ::= LIMIT signed", + /* 231 */ "limit_opt ::= LIMIT signed OFFSET signed", + /* 232 */ "limit_opt ::= LIMIT signed COMMA signed", + /* 233 */ "slimit_opt ::=", + /* 234 */ "slimit_opt ::= SLIMIT signed", + /* 235 */ "slimit_opt ::= SLIMIT signed SOFFSET signed", + /* 236 */ "slimit_opt ::= SLIMIT signed COMMA signed", + /* 237 */ "where_opt ::=", + /* 238 */ "where_opt ::= WHERE expr", + /* 239 */ "expr ::= LP expr RP", + /* 240 */ "expr ::= ID", + /* 241 */ "expr ::= ID DOT ID", + /* 242 */ "expr ::= ID DOT STAR", + /* 243 */ "expr ::= INTEGER", + /* 244 */ "expr ::= MINUS INTEGER", + /* 245 */ "expr ::= PLUS INTEGER", + /* 246 */ "expr ::= FLOAT", + /* 247 */ "expr ::= MINUS FLOAT", + /* 248 */ "expr ::= PLUS FLOAT", + /* 249 */ "expr ::= STRING", + /* 250 */ "expr ::= NOW", + /* 251 */ "expr ::= VARIABLE", + /* 252 */ "expr ::= PLUS VARIABLE", + /* 253 */ "expr ::= MINUS VARIABLE", + /* 254 */ "expr ::= BOOL", + /* 255 */ "expr ::= NULL", + /* 256 */ "expr ::= ID LP exprlist RP", + /* 257 */ "expr ::= ID LP STAR RP", + /* 258 */ "expr ::= expr IS NULL", + /* 259 */ "expr ::= expr IS NOT NULL", + /* 260 */ "expr ::= expr LT expr", + /* 261 */ "expr ::= expr GT expr", + /* 262 */ "expr ::= expr LE expr", + /* 263 */ "expr ::= expr GE expr", + /* 264 */ "expr ::= expr NE expr", + /* 265 */ "expr ::= expr EQ expr", + /* 266 */ "expr ::= expr BETWEEN expr AND expr", + /* 267 */ "expr ::= expr AND expr", + /* 268 */ "expr ::= expr OR expr", + /* 269 */ "expr ::= expr PLUS expr", + /* 270 */ "expr ::= expr MINUS expr", + /* 271 */ "expr ::= expr STAR expr", + /* 272 */ "expr ::= expr SLASH expr", + /* 273 */ "expr ::= expr REM expr", + /* 274 */ "expr ::= expr LIKE expr", + /* 275 */ "expr ::= expr MATCH expr", + /* 276 */ "expr ::= expr NMATCH expr", + /* 277 */ "expr ::= expr IN LP exprlist RP", + /* 278 */ "exprlist ::= exprlist COMMA expritem", + /* 279 */ "exprlist ::= expritem", + /* 280 */ "expritem ::= expr", + /* 281 */ "expritem ::=", + /* 282 */ "cmd ::= RESET QUERY CACHE", + /* 283 */ "cmd ::= SYNCDB ids REPLICA", + /* 284 */ "cmd ::= ALTER TABLE ids cpxName ADD COLUMN columnlist", + /* 285 */ "cmd ::= ALTER TABLE ids cpxName DROP COLUMN ids", + /* 286 */ "cmd ::= ALTER TABLE ids cpxName MODIFY COLUMN columnlist", + /* 287 */ "cmd ::= ALTER TABLE ids cpxName ADD TAG columnlist", + /* 288 */ "cmd ::= ALTER TABLE ids cpxName DROP TAG ids", + /* 289 */ "cmd ::= ALTER TABLE ids cpxName CHANGE TAG ids ids", + /* 290 */ "cmd ::= ALTER TABLE ids cpxName SET TAG ids EQ tagitem", + /* 291 */ "cmd ::= ALTER TABLE ids cpxName MODIFY TAG columnlist", + /* 292 */ "cmd ::= ALTER STABLE ids cpxName ADD COLUMN columnlist", + /* 293 */ "cmd ::= ALTER STABLE ids cpxName DROP COLUMN ids", + /* 294 */ "cmd ::= ALTER STABLE ids cpxName MODIFY COLUMN columnlist", + /* 295 */ "cmd ::= ALTER STABLE ids cpxName ADD TAG columnlist", + /* 296 */ "cmd ::= ALTER STABLE ids cpxName DROP TAG ids", + /* 297 */ "cmd ::= ALTER STABLE ids cpxName CHANGE TAG ids ids", + /* 298 */ "cmd ::= ALTER STABLE ids cpxName SET TAG ids EQ tagitem", + /* 299 */ "cmd ::= ALTER STABLE ids cpxName MODIFY TAG columnlist", + /* 300 */ "cmd ::= KILL CONNECTION INTEGER", + /* 301 */ "cmd ::= KILL STREAM INTEGER COLON INTEGER", + /* 302 */ "cmd ::= KILL QUERY INTEGER COLON INTEGER", }; #endif /* NDEBUG */ @@ -1424,28 +1454,29 @@ static int yyGrowStack(yyParser *p){ /* Initialize a new parser that has already been allocated. */ -void ParseInit(void *yypParser){ - yyParser *pParser = (yyParser*)yypParser; +void ParseInit(void *yypRawParser ParseCTX_PDECL){ + yyParser *yypParser = (yyParser*)yypRawParser; + ParseCTX_STORE #ifdef YYTRACKMAXSTACKDEPTH - pParser->yyhwm = 0; + yypParser->yyhwm = 0; #endif #if YYSTACKDEPTH<=0 - pParser->yytos = NULL; - pParser->yystack = NULL; - pParser->yystksz = 0; - if( yyGrowStack(pParser) ){ - pParser->yystack = &pParser->yystk0; - pParser->yystksz = 1; + yypParser->yytos = NULL; + yypParser->yystack = NULL; + yypParser->yystksz = 0; + if( yyGrowStack(yypParser) ){ + yypParser->yystack = &yypParser->yystk0; + yypParser->yystksz = 1; } #endif #ifndef YYNOERRORRECOVERY - pParser->yyerrcnt = -1; + yypParser->yyerrcnt = -1; #endif - pParser->yytos = pParser->yystack; - pParser->yystack[0].stateno = 0; - pParser->yystack[0].major = 0; + yypParser->yytos = yypParser->yystack; + yypParser->yystack[0].stateno = 0; + yypParser->yystack[0].major = 0; #if YYSTACKDEPTH>0 - pParser->yystackEnd = &pParser->yystack[YYSTACKDEPTH-1]; + yypParser->yystackEnd = &yypParser->yystack[YYSTACKDEPTH-1]; #endif } @@ -1462,11 +1493,14 @@ void ParseInit(void *yypParser){ ** A pointer to a parser. This pointer is used in subsequent calls ** to Parse and ParseFree. */ -void *ParseAlloc(void *(*mallocProc)(YYMALLOCARGTYPE)){ - yyParser *pParser; - pParser = (yyParser*)(*mallocProc)( (YYMALLOCARGTYPE)sizeof(yyParser) ); - if( pParser ) ParseInit(pParser); - return pParser; +void *ParseAlloc(void *(*mallocProc)(YYMALLOCARGTYPE) ParseCTX_PDECL){ + yyParser *yypParser; + yypParser = (yyParser*)(*mallocProc)( (YYMALLOCARGTYPE)sizeof(yyParser) ); + if( yypParser ){ + ParseCTX_STORE + ParseInit(yypParser ParseCTX_PARAM); + } + return (void*)yypParser; } #endif /* Parse_ENGINEALWAYSONSTACK */ @@ -1483,7 +1517,8 @@ static void yy_destructor( YYCODETYPE yymajor, /* Type code for object to destroy */ YYMINORTYPE *yypminor /* The object to be destroyed */ ){ - ParseARG_FETCH; + ParseARG_FETCH + ParseCTX_FETCH switch( yymajor ){ /* Here is inserted the actions which take place when a ** terminal or non-terminal is destroyed. This can happen @@ -1498,9 +1533,9 @@ static void yy_destructor( /********* Begin destructor definitions ***************************************/ case 208: /* exprlist */ case 252: /* selcollist */ - case 266: /* sclp */ + case 267: /* sclp */ { -tSqlExprListDestroy((yypminor->yy221)); +tSqlExprListDestroy((yypminor->yy345)); } break; case 223: /* intitemlist */ @@ -1508,48 +1543,49 @@ tSqlExprListDestroy((yypminor->yy221)); case 246: /* columnlist */ case 247: /* tagitemlist */ case 248: /* tagNamelist */ - case 259: /* fill_opt */ - case 260: /* groupby_opt */ - case 262: /* orderby_opt */ - case 274: /* sortlist */ - case 278: /* grouplist */ + case 260: /* fill_opt */ + case 261: /* groupby_opt */ + case 263: /* orderby_opt */ + case 276: /* sortlist */ + case 280: /* grouplist */ { -taosArrayDestroy((yypminor->yy221)); +taosArrayDestroy((yypminor->yy345)); } break; case 244: /* create_table_list */ { -destroyCreateTableSql((yypminor->yy102)); +destroyCreateTableSql((yypminor->yy170)); } break; case 249: /* select */ { -destroySqlNode((yypminor->yy376)); +destroySqlNode((yypminor->yy68)); } break; case 253: /* from */ - case 270: /* tablelist */ - case 271: /* sub */ + case 271: /* tablelist */ + case 272: /* sub */ { -destroyRelationInfo((yypminor->yy164)); +destroyRelationInfo((yypminor->yy484)); } break; case 254: /* where_opt */ - case 261: /* having_opt */ - case 268: /* expr */ - case 279: /* expritem */ + case 262: /* having_opt */ + case 269: /* expr */ + case 274: /* timestamp */ + case 281: /* expritem */ { -tSqlExprDestroy((yypminor->yy146)); +tSqlExprDestroy((yypminor->yy418)); } break; - case 265: /* union */ + case 266: /* union */ { -destroyAllSqlNode((yypminor->yy221)); +destroyAllSqlNode((yypminor->yy345)); } break; - case 275: /* sortitem */ + case 277: /* sortitem */ { -tVariantDestroy(&(yypminor->yy106)); +tVariantDestroy(&(yypminor->yy2)); } break; /********* End destructor definitions *****************************************/ @@ -1661,13 +1697,12 @@ int ParseCoverage(FILE *out){ ** Find the appropriate action for a parser given the terminal ** look-ahead token iLookAhead. */ -static unsigned int yy_find_shift_action( - yyParser *pParser, /* The parser */ - YYCODETYPE iLookAhead /* The look-ahead token */ +static YYACTIONTYPE yy_find_shift_action( + YYCODETYPE iLookAhead, /* The look-ahead token */ + YYACTIONTYPE stateno /* Current state number */ ){ int i; - int stateno = pParser->yytos->stateno; - + if( stateno>YY_MAX_SHIFT ) return stateno; assert( stateno <= YY_SHIFT_COUNT ); #if defined(YYCOVERAGE) @@ -1675,15 +1710,19 @@ static unsigned int yy_find_shift_action( #endif do{ i = yy_shift_ofst[stateno]; - assert( i>=0 && i+YYNTOKEN<=sizeof(yy_lookahead)/sizeof(yy_lookahead[0]) ); + assert( i>=0 ); + assert( i<=YY_ACTTAB_COUNT ); + assert( i+YYNTOKEN<=(int)YY_NLOOKAHEAD ); assert( iLookAhead!=YYNOCODE ); assert( iLookAhead < YYNTOKEN ); i += iLookAhead; + assert( i<(int)YY_NLOOKAHEAD ); if( yy_lookahead[i]!=iLookAhead ){ #ifdef YYFALLBACK YYCODETYPE iFallback; /* Fallback token */ - if( iLookAhead %s\n", @@ -1698,15 +1737,8 @@ static unsigned int yy_find_shift_action( #ifdef YYWILDCARD { int j = i - iLookAhead + YYWILDCARD; - if( -#if YY_SHIFT_MIN+YYWILDCARD<0 - j>=0 && -#endif -#if YY_SHIFT_MAX+YYWILDCARD>=YY_ACTTAB_COUNT - j0 - ){ + assert( j<(int)(sizeof(yy_lookahead)/sizeof(yy_lookahead[0])) ); + if( yy_lookahead[j]==YYWILDCARD && iLookAhead>0 ){ #ifndef NDEBUG if( yyTraceFILE ){ fprintf(yyTraceFILE, "%sWILDCARD %s => %s\n", @@ -1720,6 +1752,7 @@ static unsigned int yy_find_shift_action( #endif /* YYWILDCARD */ return yy_default[stateno]; }else{ + assert( i>=0 && iyytos; - yytos->stateno = (YYACTIONTYPE)yyNewState; - yytos->major = (YYCODETYPE)yyMajor; + yytos->stateno = yyNewState; + yytos->major = yyMajor; yytos->minor.yy0 = yyMinor; yyTraceShift(yypParser, yyNewState, "Shift"); } -/* The following table contains information about every rule that -** is used during the reduce. -*/ -static const struct { - YYCODETYPE lhs; /* Symbol on the left-hand side of the rule */ - signed char nrhs; /* Negative of the number of RHS symbols in the rule */ -} yyRuleInfo[] = { - { 199, -1 }, /* (0) program ::= cmd */ - { 200, -2 }, /* (1) cmd ::= SHOW DATABASES */ - { 200, -2 }, /* (2) cmd ::= SHOW TOPICS */ - { 200, -2 }, /* (3) cmd ::= SHOW FUNCTIONS */ - { 200, -2 }, /* (4) cmd ::= SHOW MNODES */ - { 200, -2 }, /* (5) cmd ::= SHOW DNODES */ - { 200, -2 }, /* (6) cmd ::= SHOW ACCOUNTS */ - { 200, -2 }, /* (7) cmd ::= SHOW USERS */ - { 200, -2 }, /* (8) cmd ::= SHOW MODULES */ - { 200, -2 }, /* (9) cmd ::= SHOW QUERIES */ - { 200, -2 }, /* (10) cmd ::= SHOW CONNECTIONS */ - { 200, -2 }, /* (11) cmd ::= SHOW STREAMS */ - { 200, -2 }, /* (12) cmd ::= SHOW VARIABLES */ - { 200, -2 }, /* (13) cmd ::= SHOW SCORES */ - { 200, -2 }, /* (14) cmd ::= SHOW GRANTS */ - { 200, -2 }, /* (15) cmd ::= SHOW VNODES */ - { 200, -3 }, /* (16) cmd ::= SHOW VNODES ids */ - { 202, 0 }, /* (17) dbPrefix ::= */ - { 202, -2 }, /* (18) dbPrefix ::= ids DOT */ - { 203, 0 }, /* (19) cpxName ::= */ - { 203, -2 }, /* (20) cpxName ::= DOT ids */ - { 200, -5 }, /* (21) cmd ::= SHOW CREATE TABLE ids cpxName */ - { 200, -5 }, /* (22) cmd ::= SHOW CREATE STABLE ids cpxName */ - { 200, -4 }, /* (23) cmd ::= SHOW CREATE DATABASE ids */ - { 200, -3 }, /* (24) cmd ::= SHOW dbPrefix TABLES */ - { 200, -5 }, /* (25) cmd ::= SHOW dbPrefix TABLES LIKE ids */ - { 200, -3 }, /* (26) cmd ::= SHOW dbPrefix STABLES */ - { 200, -5 }, /* (27) cmd ::= SHOW dbPrefix STABLES LIKE ids */ - { 200, -3 }, /* (28) cmd ::= SHOW dbPrefix VGROUPS */ - { 200, -4 }, /* (29) cmd ::= SHOW dbPrefix VGROUPS ids */ - { 200, -5 }, /* (30) cmd ::= DROP TABLE ifexists ids cpxName */ - { 200, -5 }, /* (31) cmd ::= DROP STABLE ifexists ids cpxName */ - { 200, -4 }, /* (32) cmd ::= DROP DATABASE ifexists ids */ - { 200, -4 }, /* (33) cmd ::= DROP TOPIC ifexists ids */ - { 200, -3 }, /* (34) cmd ::= DROP FUNCTION ids */ - { 200, -3 }, /* (35) cmd ::= DROP DNODE ids */ - { 200, -3 }, /* (36) cmd ::= DROP USER ids */ - { 200, -3 }, /* (37) cmd ::= DROP ACCOUNT ids */ - { 200, -2 }, /* (38) cmd ::= USE ids */ - { 200, -3 }, /* (39) cmd ::= DESCRIBE ids cpxName */ - { 200, -3 }, /* (40) cmd ::= DESC ids cpxName */ - { 200, -5 }, /* (41) cmd ::= ALTER USER ids PASS ids */ - { 200, -5 }, /* (42) cmd ::= ALTER USER ids PRIVILEGE ids */ - { 200, -4 }, /* (43) cmd ::= ALTER DNODE ids ids */ - { 200, -5 }, /* (44) cmd ::= ALTER DNODE ids ids ids */ - { 200, -3 }, /* (45) cmd ::= ALTER LOCAL ids */ - { 200, -4 }, /* (46) cmd ::= ALTER LOCAL ids ids */ - { 200, -4 }, /* (47) cmd ::= ALTER DATABASE ids alter_db_optr */ - { 200, -4 }, /* (48) cmd ::= ALTER TOPIC ids alter_topic_optr */ - { 200, -4 }, /* (49) cmd ::= ALTER ACCOUNT ids acct_optr */ - { 200, -6 }, /* (50) cmd ::= ALTER ACCOUNT ids PASS ids acct_optr */ - { 200, -6 }, /* (51) cmd ::= COMPACT VNODES IN LP exprlist RP */ - { 201, -1 }, /* (52) ids ::= ID */ - { 201, -1 }, /* (53) ids ::= STRING */ - { 204, -2 }, /* (54) ifexists ::= IF EXISTS */ - { 204, 0 }, /* (55) ifexists ::= */ - { 209, -3 }, /* (56) ifnotexists ::= IF NOT EXISTS */ - { 209, 0 }, /* (57) ifnotexists ::= */ - { 200, -3 }, /* (58) cmd ::= CREATE DNODE ids */ - { 200, -6 }, /* (59) cmd ::= CREATE ACCOUNT ids PASS ids acct_optr */ - { 200, -5 }, /* (60) cmd ::= CREATE DATABASE ifnotexists ids db_optr */ - { 200, -5 }, /* (61) cmd ::= CREATE TOPIC ifnotexists ids topic_optr */ - { 200, -8 }, /* (62) cmd ::= CREATE FUNCTION ids AS ids OUTPUTTYPE typename bufsize */ - { 200, -9 }, /* (63) cmd ::= CREATE AGGREGATE FUNCTION ids AS ids OUTPUTTYPE typename bufsize */ - { 200, -5 }, /* (64) cmd ::= CREATE USER ids PASS ids */ - { 213, 0 }, /* (65) bufsize ::= */ - { 213, -2 }, /* (66) bufsize ::= BUFSIZE INTEGER */ - { 214, 0 }, /* (67) pps ::= */ - { 214, -2 }, /* (68) pps ::= PPS INTEGER */ - { 215, 0 }, /* (69) tseries ::= */ - { 215, -2 }, /* (70) tseries ::= TSERIES INTEGER */ - { 216, 0 }, /* (71) dbs ::= */ - { 216, -2 }, /* (72) dbs ::= DBS INTEGER */ - { 217, 0 }, /* (73) streams ::= */ - { 217, -2 }, /* (74) streams ::= STREAMS INTEGER */ - { 218, 0 }, /* (75) storage ::= */ - { 218, -2 }, /* (76) storage ::= STORAGE INTEGER */ - { 219, 0 }, /* (77) qtime ::= */ - { 219, -2 }, /* (78) qtime ::= QTIME INTEGER */ - { 220, 0 }, /* (79) users ::= */ - { 220, -2 }, /* (80) users ::= USERS INTEGER */ - { 221, 0 }, /* (81) conns ::= */ - { 221, -2 }, /* (82) conns ::= CONNS INTEGER */ - { 222, 0 }, /* (83) state ::= */ - { 222, -2 }, /* (84) state ::= STATE ids */ - { 207, -9 }, /* (85) acct_optr ::= pps tseries storage streams qtime dbs users conns state */ - { 223, -3 }, /* (86) intitemlist ::= intitemlist COMMA intitem */ - { 223, -1 }, /* (87) intitemlist ::= intitem */ - { 224, -1 }, /* (88) intitem ::= INTEGER */ - { 225, -2 }, /* (89) keep ::= KEEP intitemlist */ - { 226, -2 }, /* (90) cache ::= CACHE INTEGER */ - { 227, -2 }, /* (91) replica ::= REPLICA INTEGER */ - { 228, -2 }, /* (92) quorum ::= QUORUM INTEGER */ - { 229, -2 }, /* (93) days ::= DAYS INTEGER */ - { 230, -2 }, /* (94) minrows ::= MINROWS INTEGER */ - { 231, -2 }, /* (95) maxrows ::= MAXROWS INTEGER */ - { 232, -2 }, /* (96) blocks ::= BLOCKS INTEGER */ - { 233, -2 }, /* (97) ctime ::= CTIME INTEGER */ - { 234, -2 }, /* (98) wal ::= WAL INTEGER */ - { 235, -2 }, /* (99) fsync ::= FSYNC INTEGER */ - { 236, -2 }, /* (100) comp ::= COMP INTEGER */ - { 237, -2 }, /* (101) prec ::= PRECISION STRING */ - { 238, -2 }, /* (102) update ::= UPDATE INTEGER */ - { 239, -2 }, /* (103) cachelast ::= CACHELAST INTEGER */ - { 240, -2 }, /* (104) partitions ::= PARTITIONS INTEGER */ - { 210, 0 }, /* (105) db_optr ::= */ - { 210, -2 }, /* (106) db_optr ::= db_optr cache */ - { 210, -2 }, /* (107) db_optr ::= db_optr replica */ - { 210, -2 }, /* (108) db_optr ::= db_optr quorum */ - { 210, -2 }, /* (109) db_optr ::= db_optr days */ - { 210, -2 }, /* (110) db_optr ::= db_optr minrows */ - { 210, -2 }, /* (111) db_optr ::= db_optr maxrows */ - { 210, -2 }, /* (112) db_optr ::= db_optr blocks */ - { 210, -2 }, /* (113) db_optr ::= db_optr ctime */ - { 210, -2 }, /* (114) db_optr ::= db_optr wal */ - { 210, -2 }, /* (115) db_optr ::= db_optr fsync */ - { 210, -2 }, /* (116) db_optr ::= db_optr comp */ - { 210, -2 }, /* (117) db_optr ::= db_optr prec */ - { 210, -2 }, /* (118) db_optr ::= db_optr keep */ - { 210, -2 }, /* (119) db_optr ::= db_optr update */ - { 210, -2 }, /* (120) db_optr ::= db_optr cachelast */ - { 211, -1 }, /* (121) topic_optr ::= db_optr */ - { 211, -2 }, /* (122) topic_optr ::= topic_optr partitions */ - { 205, 0 }, /* (123) alter_db_optr ::= */ - { 205, -2 }, /* (124) alter_db_optr ::= alter_db_optr replica */ - { 205, -2 }, /* (125) alter_db_optr ::= alter_db_optr quorum */ - { 205, -2 }, /* (126) alter_db_optr ::= alter_db_optr keep */ - { 205, -2 }, /* (127) alter_db_optr ::= alter_db_optr blocks */ - { 205, -2 }, /* (128) alter_db_optr ::= alter_db_optr comp */ - { 205, -2 }, /* (129) alter_db_optr ::= alter_db_optr update */ - { 205, -2 }, /* (130) alter_db_optr ::= alter_db_optr cachelast */ - { 206, -1 }, /* (131) alter_topic_optr ::= alter_db_optr */ - { 206, -2 }, /* (132) alter_topic_optr ::= alter_topic_optr partitions */ - { 212, -1 }, /* (133) typename ::= ids */ - { 212, -4 }, /* (134) typename ::= ids LP signed RP */ - { 212, -2 }, /* (135) typename ::= ids UNSIGNED */ - { 241, -1 }, /* (136) signed ::= INTEGER */ - { 241, -2 }, /* (137) signed ::= PLUS INTEGER */ - { 241, -2 }, /* (138) signed ::= MINUS INTEGER */ - { 200, -3 }, /* (139) cmd ::= CREATE TABLE create_table_args */ - { 200, -3 }, /* (140) cmd ::= CREATE TABLE create_stable_args */ - { 200, -3 }, /* (141) cmd ::= CREATE STABLE create_stable_args */ - { 200, -3 }, /* (142) cmd ::= CREATE TABLE create_table_list */ - { 244, -1 }, /* (143) create_table_list ::= create_from_stable */ - { 244, -2 }, /* (144) create_table_list ::= create_table_list create_from_stable */ - { 242, -6 }, /* (145) create_table_args ::= ifnotexists ids cpxName LP columnlist RP */ - { 243, -10 }, /* (146) create_stable_args ::= ifnotexists ids cpxName LP columnlist RP TAGS LP columnlist RP */ - { 245, -10 }, /* (147) create_from_stable ::= ifnotexists ids cpxName USING ids cpxName TAGS LP tagitemlist RP */ - { 245, -13 }, /* (148) create_from_stable ::= ifnotexists ids cpxName USING ids cpxName LP tagNamelist RP TAGS LP tagitemlist RP */ - { 248, -3 }, /* (149) tagNamelist ::= tagNamelist COMMA ids */ - { 248, -1 }, /* (150) tagNamelist ::= ids */ - { 242, -5 }, /* (151) create_table_args ::= ifnotexists ids cpxName AS select */ - { 246, -3 }, /* (152) columnlist ::= columnlist COMMA column */ - { 246, -1 }, /* (153) columnlist ::= column */ - { 250, -2 }, /* (154) column ::= ids typename */ - { 247, -3 }, /* (155) tagitemlist ::= tagitemlist COMMA tagitem */ - { 247, -1 }, /* (156) tagitemlist ::= tagitem */ - { 251, -1 }, /* (157) tagitem ::= INTEGER */ - { 251, -1 }, /* (158) tagitem ::= FLOAT */ - { 251, -1 }, /* (159) tagitem ::= STRING */ - { 251, -1 }, /* (160) tagitem ::= BOOL */ - { 251, -1 }, /* (161) tagitem ::= NULL */ - { 251, -1 }, /* (162) tagitem ::= NOW */ - { 251, -2 }, /* (163) tagitem ::= MINUS INTEGER */ - { 251, -2 }, /* (164) tagitem ::= MINUS FLOAT */ - { 251, -2 }, /* (165) tagitem ::= PLUS INTEGER */ - { 251, -2 }, /* (166) tagitem ::= PLUS FLOAT */ - { 249, -14 }, /* (167) select ::= SELECT selcollist from where_opt interval_option sliding_opt session_option windowstate_option fill_opt groupby_opt having_opt orderby_opt slimit_opt limit_opt */ - { 249, -3 }, /* (168) select ::= LP select RP */ - { 265, -1 }, /* (169) union ::= select */ - { 265, -4 }, /* (170) union ::= union UNION ALL select */ - { 200, -1 }, /* (171) cmd ::= union */ - { 249, -2 }, /* (172) select ::= SELECT selcollist */ - { 266, -2 }, /* (173) sclp ::= selcollist COMMA */ - { 266, 0 }, /* (174) sclp ::= */ - { 252, -4 }, /* (175) selcollist ::= sclp distinct expr as */ - { 252, -2 }, /* (176) selcollist ::= sclp STAR */ - { 269, -2 }, /* (177) as ::= AS ids */ - { 269, -1 }, /* (178) as ::= ids */ - { 269, 0 }, /* (179) as ::= */ - { 267, -1 }, /* (180) distinct ::= DISTINCT */ - { 267, 0 }, /* (181) distinct ::= */ - { 253, -2 }, /* (182) from ::= FROM tablelist */ - { 253, -2 }, /* (183) from ::= FROM sub */ - { 271, -3 }, /* (184) sub ::= LP union RP */ - { 271, -4 }, /* (185) sub ::= LP union RP ids */ - { 271, -6 }, /* (186) sub ::= sub COMMA LP union RP ids */ - { 270, -2 }, /* (187) tablelist ::= ids cpxName */ - { 270, -3 }, /* (188) tablelist ::= ids cpxName ids */ - { 270, -4 }, /* (189) tablelist ::= tablelist COMMA ids cpxName */ - { 270, -5 }, /* (190) tablelist ::= tablelist COMMA ids cpxName ids */ - { 272, -1 }, /* (191) tmvar ::= VARIABLE */ - { 255, -4 }, /* (192) interval_option ::= intervalKey LP tmvar RP */ - { 255, -6 }, /* (193) interval_option ::= intervalKey LP tmvar COMMA tmvar RP */ - { 255, 0 }, /* (194) interval_option ::= */ - { 273, -1 }, /* (195) intervalKey ::= INTERVAL */ - { 273, -1 }, /* (196) intervalKey ::= EVERY */ - { 257, 0 }, /* (197) session_option ::= */ - { 257, -7 }, /* (198) session_option ::= SESSION LP ids cpxName COMMA tmvar RP */ - { 258, 0 }, /* (199) windowstate_option ::= */ - { 258, -4 }, /* (200) windowstate_option ::= STATE_WINDOW LP ids RP */ - { 259, 0 }, /* (201) fill_opt ::= */ - { 259, -6 }, /* (202) fill_opt ::= FILL LP ID COMMA tagitemlist RP */ - { 259, -4 }, /* (203) fill_opt ::= FILL LP ID RP */ - { 256, -4 }, /* (204) sliding_opt ::= SLIDING LP tmvar RP */ - { 256, 0 }, /* (205) sliding_opt ::= */ - { 262, 0 }, /* (206) orderby_opt ::= */ - { 262, -3 }, /* (207) orderby_opt ::= ORDER BY sortlist */ - { 274, -4 }, /* (208) sortlist ::= sortlist COMMA item sortorder */ - { 274, -2 }, /* (209) sortlist ::= item sortorder */ - { 276, -2 }, /* (210) item ::= ids cpxName */ - { 277, -1 }, /* (211) sortorder ::= ASC */ - { 277, -1 }, /* (212) sortorder ::= DESC */ - { 277, 0 }, /* (213) sortorder ::= */ - { 260, 0 }, /* (214) groupby_opt ::= */ - { 260, -3 }, /* (215) groupby_opt ::= GROUP BY grouplist */ - { 278, -3 }, /* (216) grouplist ::= grouplist COMMA item */ - { 278, -1 }, /* (217) grouplist ::= item */ - { 261, 0 }, /* (218) having_opt ::= */ - { 261, -2 }, /* (219) having_opt ::= HAVING expr */ - { 264, 0 }, /* (220) limit_opt ::= */ - { 264, -2 }, /* (221) limit_opt ::= LIMIT signed */ - { 264, -4 }, /* (222) limit_opt ::= LIMIT signed OFFSET signed */ - { 264, -4 }, /* (223) limit_opt ::= LIMIT signed COMMA signed */ - { 263, 0 }, /* (224) slimit_opt ::= */ - { 263, -2 }, /* (225) slimit_opt ::= SLIMIT signed */ - { 263, -4 }, /* (226) slimit_opt ::= SLIMIT signed SOFFSET signed */ - { 263, -4 }, /* (227) slimit_opt ::= SLIMIT signed COMMA signed */ - { 254, 0 }, /* (228) where_opt ::= */ - { 254, -2 }, /* (229) where_opt ::= WHERE expr */ - { 268, -3 }, /* (230) expr ::= LP expr RP */ - { 268, -1 }, /* (231) expr ::= ID */ - { 268, -3 }, /* (232) expr ::= ID DOT ID */ - { 268, -3 }, /* (233) expr ::= ID DOT STAR */ - { 268, -1 }, /* (234) expr ::= INTEGER */ - { 268, -2 }, /* (235) expr ::= MINUS INTEGER */ - { 268, -2 }, /* (236) expr ::= PLUS INTEGER */ - { 268, -1 }, /* (237) expr ::= FLOAT */ - { 268, -2 }, /* (238) expr ::= MINUS FLOAT */ - { 268, -2 }, /* (239) expr ::= PLUS FLOAT */ - { 268, -1 }, /* (240) expr ::= STRING */ - { 268, -1 }, /* (241) expr ::= NOW */ - { 268, -1 }, /* (242) expr ::= VARIABLE */ - { 268, -2 }, /* (243) expr ::= PLUS VARIABLE */ - { 268, -2 }, /* (244) expr ::= MINUS VARIABLE */ - { 268, -1 }, /* (245) expr ::= BOOL */ - { 268, -1 }, /* (246) expr ::= NULL */ - { 268, -4 }, /* (247) expr ::= ID LP exprlist RP */ - { 268, -4 }, /* (248) expr ::= ID LP STAR RP */ - { 268, -3 }, /* (249) expr ::= expr IS NULL */ - { 268, -4 }, /* (250) expr ::= expr IS NOT NULL */ - { 268, -3 }, /* (251) expr ::= expr LT expr */ - { 268, -3 }, /* (252) expr ::= expr GT expr */ - { 268, -3 }, /* (253) expr ::= expr LE expr */ - { 268, -3 }, /* (254) expr ::= expr GE expr */ - { 268, -3 }, /* (255) expr ::= expr NE expr */ - { 268, -3 }, /* (256) expr ::= expr EQ expr */ - { 268, -5 }, /* (257) expr ::= expr BETWEEN expr AND expr */ - { 268, -3 }, /* (258) expr ::= expr AND expr */ - { 268, -3 }, /* (259) expr ::= expr OR expr */ - { 268, -3 }, /* (260) expr ::= expr PLUS expr */ - { 268, -3 }, /* (261) expr ::= expr MINUS expr */ - { 268, -3 }, /* (262) expr ::= expr STAR expr */ - { 268, -3 }, /* (263) expr ::= expr SLASH expr */ - { 268, -3 }, /* (264) expr ::= expr REM expr */ - { 268, -3 }, /* (265) expr ::= expr LIKE expr */ - { 268, -3 }, /* (266) expr ::= expr MATCH expr */ - { 268, -3 }, /* (267) expr ::= expr NMATCH expr */ - { 268, -5 }, /* (268) expr ::= expr IN LP exprlist RP */ - { 208, -3 }, /* (269) exprlist ::= exprlist COMMA expritem */ - { 208, -1 }, /* (270) exprlist ::= expritem */ - { 279, -1 }, /* (271) expritem ::= expr */ - { 279, 0 }, /* (272) expritem ::= */ - { 200, -3 }, /* (273) cmd ::= RESET QUERY CACHE */ - { 200, -3 }, /* (274) cmd ::= SYNCDB ids REPLICA */ - { 200, -7 }, /* (275) cmd ::= ALTER TABLE ids cpxName ADD COLUMN columnlist */ - { 200, -7 }, /* (276) cmd ::= ALTER TABLE ids cpxName DROP COLUMN ids */ - { 200, -7 }, /* (277) cmd ::= ALTER TABLE ids cpxName MODIFY COLUMN columnlist */ - { 200, -7 }, /* (278) cmd ::= ALTER TABLE ids cpxName ADD TAG columnlist */ - { 200, -7 }, /* (279) cmd ::= ALTER TABLE ids cpxName DROP TAG ids */ - { 200, -8 }, /* (280) cmd ::= ALTER TABLE ids cpxName CHANGE TAG ids ids */ - { 200, -9 }, /* (281) cmd ::= ALTER TABLE ids cpxName SET TAG ids EQ tagitem */ - { 200, -7 }, /* (282) cmd ::= ALTER TABLE ids cpxName MODIFY TAG columnlist */ - { 200, -7 }, /* (283) cmd ::= ALTER STABLE ids cpxName ADD COLUMN columnlist */ - { 200, -7 }, /* (284) cmd ::= ALTER STABLE ids cpxName DROP COLUMN ids */ - { 200, -7 }, /* (285) cmd ::= ALTER STABLE ids cpxName MODIFY COLUMN columnlist */ - { 200, -7 }, /* (286) cmd ::= ALTER STABLE ids cpxName ADD TAG columnlist */ - { 200, -7 }, /* (287) cmd ::= ALTER STABLE ids cpxName DROP TAG ids */ - { 200, -8 }, /* (288) cmd ::= ALTER STABLE ids cpxName CHANGE TAG ids ids */ - { 200, -9 }, /* (289) cmd ::= ALTER STABLE ids cpxName SET TAG ids EQ tagitem */ - { 200, -7 }, /* (290) cmd ::= ALTER STABLE ids cpxName MODIFY TAG columnlist */ - { 200, -3 }, /* (291) cmd ::= KILL CONNECTION INTEGER */ - { 200, -5 }, /* (292) cmd ::= KILL STREAM INTEGER COLON INTEGER */ - { 200, -5 }, /* (293) cmd ::= KILL QUERY INTEGER COLON INTEGER */ +/* For rule J, yyRuleInfoLhs[J] contains the symbol on the left-hand side +** of that rule */ +static const YYCODETYPE yyRuleInfoLhs[] = { + 199, /* (0) program ::= cmd */ + 200, /* (1) cmd ::= SHOW DATABASES */ + 200, /* (2) cmd ::= SHOW TOPICS */ + 200, /* (3) cmd ::= SHOW FUNCTIONS */ + 200, /* (4) cmd ::= SHOW MNODES */ + 200, /* (5) cmd ::= SHOW DNODES */ + 200, /* (6) cmd ::= SHOW ACCOUNTS */ + 200, /* (7) cmd ::= SHOW USERS */ + 200, /* (8) cmd ::= SHOW MODULES */ + 200, /* (9) cmd ::= SHOW QUERIES */ + 200, /* (10) cmd ::= SHOW CONNECTIONS */ + 200, /* (11) cmd ::= SHOW STREAMS */ + 200, /* (12) cmd ::= SHOW VARIABLES */ + 200, /* (13) cmd ::= SHOW SCORES */ + 200, /* (14) cmd ::= SHOW GRANTS */ + 200, /* (15) cmd ::= SHOW VNODES */ + 200, /* (16) cmd ::= SHOW VNODES ids */ + 202, /* (17) dbPrefix ::= */ + 202, /* (18) dbPrefix ::= ids DOT */ + 203, /* (19) cpxName ::= */ + 203, /* (20) cpxName ::= DOT ids */ + 200, /* (21) cmd ::= SHOW CREATE TABLE ids cpxName */ + 200, /* (22) cmd ::= SHOW CREATE STABLE ids cpxName */ + 200, /* (23) cmd ::= SHOW CREATE DATABASE ids */ + 200, /* (24) cmd ::= SHOW dbPrefix TABLES */ + 200, /* (25) cmd ::= SHOW dbPrefix TABLES LIKE ids */ + 200, /* (26) cmd ::= SHOW dbPrefix STABLES */ + 200, /* (27) cmd ::= SHOW dbPrefix STABLES LIKE ids */ + 200, /* (28) cmd ::= SHOW dbPrefix VGROUPS */ + 200, /* (29) cmd ::= SHOW dbPrefix VGROUPS ids */ + 200, /* (30) cmd ::= DROP TABLE ifexists ids cpxName */ + 200, /* (31) cmd ::= DROP STABLE ifexists ids cpxName */ + 200, /* (32) cmd ::= DROP DATABASE ifexists ids */ + 200, /* (33) cmd ::= DROP TOPIC ifexists ids */ + 200, /* (34) cmd ::= DROP FUNCTION ids */ + 200, /* (35) cmd ::= DROP DNODE ids */ + 200, /* (36) cmd ::= DROP USER ids */ + 200, /* (37) cmd ::= DROP ACCOUNT ids */ + 200, /* (38) cmd ::= USE ids */ + 200, /* (39) cmd ::= DESCRIBE ids cpxName */ + 200, /* (40) cmd ::= DESC ids cpxName */ + 200, /* (41) cmd ::= ALTER USER ids PASS ids */ + 200, /* (42) cmd ::= ALTER USER ids PRIVILEGE ids */ + 200, /* (43) cmd ::= ALTER DNODE ids ids */ + 200, /* (44) cmd ::= ALTER DNODE ids ids ids */ + 200, /* (45) cmd ::= ALTER LOCAL ids */ + 200, /* (46) cmd ::= ALTER LOCAL ids ids */ + 200, /* (47) cmd ::= ALTER DATABASE ids alter_db_optr */ + 200, /* (48) cmd ::= ALTER TOPIC ids alter_topic_optr */ + 200, /* (49) cmd ::= ALTER ACCOUNT ids acct_optr */ + 200, /* (50) cmd ::= ALTER ACCOUNT ids PASS ids acct_optr */ + 200, /* (51) cmd ::= COMPACT VNODES IN LP exprlist RP */ + 201, /* (52) ids ::= ID */ + 201, /* (53) ids ::= STRING */ + 204, /* (54) ifexists ::= IF EXISTS */ + 204, /* (55) ifexists ::= */ + 209, /* (56) ifnotexists ::= IF NOT EXISTS */ + 209, /* (57) ifnotexists ::= */ + 200, /* (58) cmd ::= CREATE DNODE ids */ + 200, /* (59) cmd ::= CREATE ACCOUNT ids PASS ids acct_optr */ + 200, /* (60) cmd ::= CREATE DATABASE ifnotexists ids db_optr */ + 200, /* (61) cmd ::= CREATE TOPIC ifnotexists ids topic_optr */ + 200, /* (62) cmd ::= CREATE FUNCTION ids AS ids OUTPUTTYPE typename bufsize */ + 200, /* (63) cmd ::= CREATE AGGREGATE FUNCTION ids AS ids OUTPUTTYPE typename bufsize */ + 200, /* (64) cmd ::= CREATE USER ids PASS ids */ + 213, /* (65) bufsize ::= */ + 213, /* (66) bufsize ::= BUFSIZE INTEGER */ + 214, /* (67) pps ::= */ + 214, /* (68) pps ::= PPS INTEGER */ + 215, /* (69) tseries ::= */ + 215, /* (70) tseries ::= TSERIES INTEGER */ + 216, /* (71) dbs ::= */ + 216, /* (72) dbs ::= DBS INTEGER */ + 217, /* (73) streams ::= */ + 217, /* (74) streams ::= STREAMS INTEGER */ + 218, /* (75) storage ::= */ + 218, /* (76) storage ::= STORAGE INTEGER */ + 219, /* (77) qtime ::= */ + 219, /* (78) qtime ::= QTIME INTEGER */ + 220, /* (79) users ::= */ + 220, /* (80) users ::= USERS INTEGER */ + 221, /* (81) conns ::= */ + 221, /* (82) conns ::= CONNS INTEGER */ + 222, /* (83) state ::= */ + 222, /* (84) state ::= STATE ids */ + 207, /* (85) acct_optr ::= pps tseries storage streams qtime dbs users conns state */ + 223, /* (86) intitemlist ::= intitemlist COMMA intitem */ + 223, /* (87) intitemlist ::= intitem */ + 224, /* (88) intitem ::= INTEGER */ + 225, /* (89) keep ::= KEEP intitemlist */ + 226, /* (90) cache ::= CACHE INTEGER */ + 227, /* (91) replica ::= REPLICA INTEGER */ + 228, /* (92) quorum ::= QUORUM INTEGER */ + 229, /* (93) days ::= DAYS INTEGER */ + 230, /* (94) minrows ::= MINROWS INTEGER */ + 231, /* (95) maxrows ::= MAXROWS INTEGER */ + 232, /* (96) blocks ::= BLOCKS INTEGER */ + 233, /* (97) ctime ::= CTIME INTEGER */ + 234, /* (98) wal ::= WAL INTEGER */ + 235, /* (99) fsync ::= FSYNC INTEGER */ + 236, /* (100) comp ::= COMP INTEGER */ + 237, /* (101) prec ::= PRECISION STRING */ + 238, /* (102) update ::= UPDATE INTEGER */ + 239, /* (103) cachelast ::= CACHELAST INTEGER */ + 240, /* (104) partitions ::= PARTITIONS INTEGER */ + 210, /* (105) db_optr ::= */ + 210, /* (106) db_optr ::= db_optr cache */ + 210, /* (107) db_optr ::= db_optr replica */ + 210, /* (108) db_optr ::= db_optr quorum */ + 210, /* (109) db_optr ::= db_optr days */ + 210, /* (110) db_optr ::= db_optr minrows */ + 210, /* (111) db_optr ::= db_optr maxrows */ + 210, /* (112) db_optr ::= db_optr blocks */ + 210, /* (113) db_optr ::= db_optr ctime */ + 210, /* (114) db_optr ::= db_optr wal */ + 210, /* (115) db_optr ::= db_optr fsync */ + 210, /* (116) db_optr ::= db_optr comp */ + 210, /* (117) db_optr ::= db_optr prec */ + 210, /* (118) db_optr ::= db_optr keep */ + 210, /* (119) db_optr ::= db_optr update */ + 210, /* (120) db_optr ::= db_optr cachelast */ + 211, /* (121) topic_optr ::= db_optr */ + 211, /* (122) topic_optr ::= topic_optr partitions */ + 205, /* (123) alter_db_optr ::= */ + 205, /* (124) alter_db_optr ::= alter_db_optr replica */ + 205, /* (125) alter_db_optr ::= alter_db_optr quorum */ + 205, /* (126) alter_db_optr ::= alter_db_optr keep */ + 205, /* (127) alter_db_optr ::= alter_db_optr blocks */ + 205, /* (128) alter_db_optr ::= alter_db_optr comp */ + 205, /* (129) alter_db_optr ::= alter_db_optr update */ + 205, /* (130) alter_db_optr ::= alter_db_optr cachelast */ + 206, /* (131) alter_topic_optr ::= alter_db_optr */ + 206, /* (132) alter_topic_optr ::= alter_topic_optr partitions */ + 212, /* (133) typename ::= ids */ + 212, /* (134) typename ::= ids LP signed RP */ + 212, /* (135) typename ::= ids UNSIGNED */ + 241, /* (136) signed ::= INTEGER */ + 241, /* (137) signed ::= PLUS INTEGER */ + 241, /* (138) signed ::= MINUS INTEGER */ + 200, /* (139) cmd ::= CREATE TABLE create_table_args */ + 200, /* (140) cmd ::= CREATE TABLE create_stable_args */ + 200, /* (141) cmd ::= CREATE STABLE create_stable_args */ + 200, /* (142) cmd ::= CREATE TABLE create_table_list */ + 244, /* (143) create_table_list ::= create_from_stable */ + 244, /* (144) create_table_list ::= create_table_list create_from_stable */ + 242, /* (145) create_table_args ::= ifnotexists ids cpxName LP columnlist RP */ + 243, /* (146) create_stable_args ::= ifnotexists ids cpxName LP columnlist RP TAGS LP columnlist RP */ + 245, /* (147) create_from_stable ::= ifnotexists ids cpxName USING ids cpxName TAGS LP tagitemlist RP */ + 245, /* (148) create_from_stable ::= ifnotexists ids cpxName USING ids cpxName LP tagNamelist RP TAGS LP tagitemlist RP */ + 248, /* (149) tagNamelist ::= tagNamelist COMMA ids */ + 248, /* (150) tagNamelist ::= ids */ + 242, /* (151) create_table_args ::= ifnotexists ids cpxName AS select */ + 246, /* (152) columnlist ::= columnlist COMMA column */ + 246, /* (153) columnlist ::= column */ + 250, /* (154) column ::= ids typename */ + 247, /* (155) tagitemlist ::= tagitemlist COMMA tagitem */ + 247, /* (156) tagitemlist ::= tagitem */ + 251, /* (157) tagitem ::= INTEGER */ + 251, /* (158) tagitem ::= FLOAT */ + 251, /* (159) tagitem ::= STRING */ + 251, /* (160) tagitem ::= BOOL */ + 251, /* (161) tagitem ::= NULL */ + 251, /* (162) tagitem ::= NOW */ + 251, /* (163) tagitem ::= MINUS INTEGER */ + 251, /* (164) tagitem ::= MINUS FLOAT */ + 251, /* (165) tagitem ::= PLUS INTEGER */ + 251, /* (166) tagitem ::= PLUS FLOAT */ + 249, /* (167) select ::= SELECT selcollist from where_opt range_option interval_option sliding_opt session_option windowstate_option fill_opt groupby_opt having_opt orderby_opt slimit_opt limit_opt */ + 249, /* (168) select ::= LP select RP */ + 266, /* (169) union ::= select */ + 266, /* (170) union ::= union UNION ALL select */ + 200, /* (171) cmd ::= union */ + 249, /* (172) select ::= SELECT selcollist */ + 267, /* (173) sclp ::= selcollist COMMA */ + 267, /* (174) sclp ::= */ + 252, /* (175) selcollist ::= sclp distinct expr as */ + 252, /* (176) selcollist ::= sclp STAR */ + 270, /* (177) as ::= AS ids */ + 270, /* (178) as ::= ids */ + 270, /* (179) as ::= */ + 268, /* (180) distinct ::= DISTINCT */ + 268, /* (181) distinct ::= */ + 253, /* (182) from ::= FROM tablelist */ + 253, /* (183) from ::= FROM sub */ + 272, /* (184) sub ::= LP union RP */ + 272, /* (185) sub ::= LP union RP ids */ + 272, /* (186) sub ::= sub COMMA LP union RP ids */ + 271, /* (187) tablelist ::= ids cpxName */ + 271, /* (188) tablelist ::= ids cpxName ids */ + 271, /* (189) tablelist ::= tablelist COMMA ids cpxName */ + 271, /* (190) tablelist ::= tablelist COMMA ids cpxName ids */ + 273, /* (191) tmvar ::= VARIABLE */ + 274, /* (192) timestamp ::= INTEGER */ + 274, /* (193) timestamp ::= MINUS INTEGER */ + 274, /* (194) timestamp ::= PLUS INTEGER */ + 274, /* (195) timestamp ::= STRING */ + 274, /* (196) timestamp ::= NOW */ + 274, /* (197) timestamp ::= NOW PLUS VARIABLE */ + 274, /* (198) timestamp ::= NOW MINUS VARIABLE */ + 255, /* (199) range_option ::= */ + 255, /* (200) range_option ::= RANGE LP timestamp COMMA timestamp RP */ + 256, /* (201) interval_option ::= intervalKey LP tmvar RP */ + 256, /* (202) interval_option ::= intervalKey LP tmvar COMMA tmvar RP */ + 256, /* (203) interval_option ::= */ + 275, /* (204) intervalKey ::= INTERVAL */ + 275, /* (205) intervalKey ::= EVERY */ + 258, /* (206) session_option ::= */ + 258, /* (207) session_option ::= SESSION LP ids cpxName COMMA tmvar RP */ + 259, /* (208) windowstate_option ::= */ + 259, /* (209) windowstate_option ::= STATE_WINDOW LP ids RP */ + 260, /* (210) fill_opt ::= */ + 260, /* (211) fill_opt ::= FILL LP ID COMMA tagitemlist RP */ + 260, /* (212) fill_opt ::= FILL LP ID RP */ + 257, /* (213) sliding_opt ::= SLIDING LP tmvar RP */ + 257, /* (214) sliding_opt ::= */ + 263, /* (215) orderby_opt ::= */ + 263, /* (216) orderby_opt ::= ORDER BY sortlist */ + 276, /* (217) sortlist ::= sortlist COMMA item sortorder */ + 276, /* (218) sortlist ::= item sortorder */ + 278, /* (219) item ::= ids cpxName */ + 279, /* (220) sortorder ::= ASC */ + 279, /* (221) sortorder ::= DESC */ + 279, /* (222) sortorder ::= */ + 261, /* (223) groupby_opt ::= */ + 261, /* (224) groupby_opt ::= GROUP BY grouplist */ + 280, /* (225) grouplist ::= grouplist COMMA item */ + 280, /* (226) grouplist ::= item */ + 262, /* (227) having_opt ::= */ + 262, /* (228) having_opt ::= HAVING expr */ + 265, /* (229) limit_opt ::= */ + 265, /* (230) limit_opt ::= LIMIT signed */ + 265, /* (231) limit_opt ::= LIMIT signed OFFSET signed */ + 265, /* (232) limit_opt ::= LIMIT signed COMMA signed */ + 264, /* (233) slimit_opt ::= */ + 264, /* (234) slimit_opt ::= SLIMIT signed */ + 264, /* (235) slimit_opt ::= SLIMIT signed SOFFSET signed */ + 264, /* (236) slimit_opt ::= SLIMIT signed COMMA signed */ + 254, /* (237) where_opt ::= */ + 254, /* (238) where_opt ::= WHERE expr */ + 269, /* (239) expr ::= LP expr RP */ + 269, /* (240) expr ::= ID */ + 269, /* (241) expr ::= ID DOT ID */ + 269, /* (242) expr ::= ID DOT STAR */ + 269, /* (243) expr ::= INTEGER */ + 269, /* (244) expr ::= MINUS INTEGER */ + 269, /* (245) expr ::= PLUS INTEGER */ + 269, /* (246) expr ::= FLOAT */ + 269, /* (247) expr ::= MINUS FLOAT */ + 269, /* (248) expr ::= PLUS FLOAT */ + 269, /* (249) expr ::= STRING */ + 269, /* (250) expr ::= NOW */ + 269, /* (251) expr ::= VARIABLE */ + 269, /* (252) expr ::= PLUS VARIABLE */ + 269, /* (253) expr ::= MINUS VARIABLE */ + 269, /* (254) expr ::= BOOL */ + 269, /* (255) expr ::= NULL */ + 269, /* (256) expr ::= ID LP exprlist RP */ + 269, /* (257) expr ::= ID LP STAR RP */ + 269, /* (258) expr ::= expr IS NULL */ + 269, /* (259) expr ::= expr IS NOT NULL */ + 269, /* (260) expr ::= expr LT expr */ + 269, /* (261) expr ::= expr GT expr */ + 269, /* (262) expr ::= expr LE expr */ + 269, /* (263) expr ::= expr GE expr */ + 269, /* (264) expr ::= expr NE expr */ + 269, /* (265) expr ::= expr EQ expr */ + 269, /* (266) expr ::= expr BETWEEN expr AND expr */ + 269, /* (267) expr ::= expr AND expr */ + 269, /* (268) expr ::= expr OR expr */ + 269, /* (269) expr ::= expr PLUS expr */ + 269, /* (270) expr ::= expr MINUS expr */ + 269, /* (271) expr ::= expr STAR expr */ + 269, /* (272) expr ::= expr SLASH expr */ + 269, /* (273) expr ::= expr REM expr */ + 269, /* (274) expr ::= expr LIKE expr */ + 269, /* (275) expr ::= expr MATCH expr */ + 269, /* (276) expr ::= expr NMATCH expr */ + 269, /* (277) expr ::= expr IN LP exprlist RP */ + 208, /* (278) exprlist ::= exprlist COMMA expritem */ + 208, /* (279) exprlist ::= expritem */ + 281, /* (280) expritem ::= expr */ + 281, /* (281) expritem ::= */ + 200, /* (282) cmd ::= RESET QUERY CACHE */ + 200, /* (283) cmd ::= SYNCDB ids REPLICA */ + 200, /* (284) cmd ::= ALTER TABLE ids cpxName ADD COLUMN columnlist */ + 200, /* (285) cmd ::= ALTER TABLE ids cpxName DROP COLUMN ids */ + 200, /* (286) cmd ::= ALTER TABLE ids cpxName MODIFY COLUMN columnlist */ + 200, /* (287) cmd ::= ALTER TABLE ids cpxName ADD TAG columnlist */ + 200, /* (288) cmd ::= ALTER TABLE ids cpxName DROP TAG ids */ + 200, /* (289) cmd ::= ALTER TABLE ids cpxName CHANGE TAG ids ids */ + 200, /* (290) cmd ::= ALTER TABLE ids cpxName SET TAG ids EQ tagitem */ + 200, /* (291) cmd ::= ALTER TABLE ids cpxName MODIFY TAG columnlist */ + 200, /* (292) cmd ::= ALTER STABLE ids cpxName ADD COLUMN columnlist */ + 200, /* (293) cmd ::= ALTER STABLE ids cpxName DROP COLUMN ids */ + 200, /* (294) cmd ::= ALTER STABLE ids cpxName MODIFY COLUMN columnlist */ + 200, /* (295) cmd ::= ALTER STABLE ids cpxName ADD TAG columnlist */ + 200, /* (296) cmd ::= ALTER STABLE ids cpxName DROP TAG ids */ + 200, /* (297) cmd ::= ALTER STABLE ids cpxName CHANGE TAG ids ids */ + 200, /* (298) cmd ::= ALTER STABLE ids cpxName SET TAG ids EQ tagitem */ + 200, /* (299) cmd ::= ALTER STABLE ids cpxName MODIFY TAG columnlist */ + 200, /* (300) cmd ::= KILL CONNECTION INTEGER */ + 200, /* (301) cmd ::= KILL STREAM INTEGER COLON INTEGER */ + 200, /* (302) cmd ::= KILL QUERY INTEGER COLON INTEGER */ +}; + +/* For rule J, yyRuleInfoNRhs[J] contains the negative of the number +** of symbols on the right-hand side of that rule. */ +static const signed char yyRuleInfoNRhs[] = { + -1, /* (0) program ::= cmd */ + -2, /* (1) cmd ::= SHOW DATABASES */ + -2, /* (2) cmd ::= SHOW TOPICS */ + -2, /* (3) cmd ::= SHOW FUNCTIONS */ + -2, /* (4) cmd ::= SHOW MNODES */ + -2, /* (5) cmd ::= SHOW DNODES */ + -2, /* (6) cmd ::= SHOW ACCOUNTS */ + -2, /* (7) cmd ::= SHOW USERS */ + -2, /* (8) cmd ::= SHOW MODULES */ + -2, /* (9) cmd ::= SHOW QUERIES */ + -2, /* (10) cmd ::= SHOW CONNECTIONS */ + -2, /* (11) cmd ::= SHOW STREAMS */ + -2, /* (12) cmd ::= SHOW VARIABLES */ + -2, /* (13) cmd ::= SHOW SCORES */ + -2, /* (14) cmd ::= SHOW GRANTS */ + -2, /* (15) cmd ::= SHOW VNODES */ + -3, /* (16) cmd ::= SHOW VNODES ids */ + 0, /* (17) dbPrefix ::= */ + -2, /* (18) dbPrefix ::= ids DOT */ + 0, /* (19) cpxName ::= */ + -2, /* (20) cpxName ::= DOT ids */ + -5, /* (21) cmd ::= SHOW CREATE TABLE ids cpxName */ + -5, /* (22) cmd ::= SHOW CREATE STABLE ids cpxName */ + -4, /* (23) cmd ::= SHOW CREATE DATABASE ids */ + -3, /* (24) cmd ::= SHOW dbPrefix TABLES */ + -5, /* (25) cmd ::= SHOW dbPrefix TABLES LIKE ids */ + -3, /* (26) cmd ::= SHOW dbPrefix STABLES */ + -5, /* (27) cmd ::= SHOW dbPrefix STABLES LIKE ids */ + -3, /* (28) cmd ::= SHOW dbPrefix VGROUPS */ + -4, /* (29) cmd ::= SHOW dbPrefix VGROUPS ids */ + -5, /* (30) cmd ::= DROP TABLE ifexists ids cpxName */ + -5, /* (31) cmd ::= DROP STABLE ifexists ids cpxName */ + -4, /* (32) cmd ::= DROP DATABASE ifexists ids */ + -4, /* (33) cmd ::= DROP TOPIC ifexists ids */ + -3, /* (34) cmd ::= DROP FUNCTION ids */ + -3, /* (35) cmd ::= DROP DNODE ids */ + -3, /* (36) cmd ::= DROP USER ids */ + -3, /* (37) cmd ::= DROP ACCOUNT ids */ + -2, /* (38) cmd ::= USE ids */ + -3, /* (39) cmd ::= DESCRIBE ids cpxName */ + -3, /* (40) cmd ::= DESC ids cpxName */ + -5, /* (41) cmd ::= ALTER USER ids PASS ids */ + -5, /* (42) cmd ::= ALTER USER ids PRIVILEGE ids */ + -4, /* (43) cmd ::= ALTER DNODE ids ids */ + -5, /* (44) cmd ::= ALTER DNODE ids ids ids */ + -3, /* (45) cmd ::= ALTER LOCAL ids */ + -4, /* (46) cmd ::= ALTER LOCAL ids ids */ + -4, /* (47) cmd ::= ALTER DATABASE ids alter_db_optr */ + -4, /* (48) cmd ::= ALTER TOPIC ids alter_topic_optr */ + -4, /* (49) cmd ::= ALTER ACCOUNT ids acct_optr */ + -6, /* (50) cmd ::= ALTER ACCOUNT ids PASS ids acct_optr */ + -6, /* (51) cmd ::= COMPACT VNODES IN LP exprlist RP */ + -1, /* (52) ids ::= ID */ + -1, /* (53) ids ::= STRING */ + -2, /* (54) ifexists ::= IF EXISTS */ + 0, /* (55) ifexists ::= */ + -3, /* (56) ifnotexists ::= IF NOT EXISTS */ + 0, /* (57) ifnotexists ::= */ + -3, /* (58) cmd ::= CREATE DNODE ids */ + -6, /* (59) cmd ::= CREATE ACCOUNT ids PASS ids acct_optr */ + -5, /* (60) cmd ::= CREATE DATABASE ifnotexists ids db_optr */ + -5, /* (61) cmd ::= CREATE TOPIC ifnotexists ids topic_optr */ + -8, /* (62) cmd ::= CREATE FUNCTION ids AS ids OUTPUTTYPE typename bufsize */ + -9, /* (63) cmd ::= CREATE AGGREGATE FUNCTION ids AS ids OUTPUTTYPE typename bufsize */ + -5, /* (64) cmd ::= CREATE USER ids PASS ids */ + 0, /* (65) bufsize ::= */ + -2, /* (66) bufsize ::= BUFSIZE INTEGER */ + 0, /* (67) pps ::= */ + -2, /* (68) pps ::= PPS INTEGER */ + 0, /* (69) tseries ::= */ + -2, /* (70) tseries ::= TSERIES INTEGER */ + 0, /* (71) dbs ::= */ + -2, /* (72) dbs ::= DBS INTEGER */ + 0, /* (73) streams ::= */ + -2, /* (74) streams ::= STREAMS INTEGER */ + 0, /* (75) storage ::= */ + -2, /* (76) storage ::= STORAGE INTEGER */ + 0, /* (77) qtime ::= */ + -2, /* (78) qtime ::= QTIME INTEGER */ + 0, /* (79) users ::= */ + -2, /* (80) users ::= USERS INTEGER */ + 0, /* (81) conns ::= */ + -2, /* (82) conns ::= CONNS INTEGER */ + 0, /* (83) state ::= */ + -2, /* (84) state ::= STATE ids */ + -9, /* (85) acct_optr ::= pps tseries storage streams qtime dbs users conns state */ + -3, /* (86) intitemlist ::= intitemlist COMMA intitem */ + -1, /* (87) intitemlist ::= intitem */ + -1, /* (88) intitem ::= INTEGER */ + -2, /* (89) keep ::= KEEP intitemlist */ + -2, /* (90) cache ::= CACHE INTEGER */ + -2, /* (91) replica ::= REPLICA INTEGER */ + -2, /* (92) quorum ::= QUORUM INTEGER */ + -2, /* (93) days ::= DAYS INTEGER */ + -2, /* (94) minrows ::= MINROWS INTEGER */ + -2, /* (95) maxrows ::= MAXROWS INTEGER */ + -2, /* (96) blocks ::= BLOCKS INTEGER */ + -2, /* (97) ctime ::= CTIME INTEGER */ + -2, /* (98) wal ::= WAL INTEGER */ + -2, /* (99) fsync ::= FSYNC INTEGER */ + -2, /* (100) comp ::= COMP INTEGER */ + -2, /* (101) prec ::= PRECISION STRING */ + -2, /* (102) update ::= UPDATE INTEGER */ + -2, /* (103) cachelast ::= CACHELAST INTEGER */ + -2, /* (104) partitions ::= PARTITIONS INTEGER */ + 0, /* (105) db_optr ::= */ + -2, /* (106) db_optr ::= db_optr cache */ + -2, /* (107) db_optr ::= db_optr replica */ + -2, /* (108) db_optr ::= db_optr quorum */ + -2, /* (109) db_optr ::= db_optr days */ + -2, /* (110) db_optr ::= db_optr minrows */ + -2, /* (111) db_optr ::= db_optr maxrows */ + -2, /* (112) db_optr ::= db_optr blocks */ + -2, /* (113) db_optr ::= db_optr ctime */ + -2, /* (114) db_optr ::= db_optr wal */ + -2, /* (115) db_optr ::= db_optr fsync */ + -2, /* (116) db_optr ::= db_optr comp */ + -2, /* (117) db_optr ::= db_optr prec */ + -2, /* (118) db_optr ::= db_optr keep */ + -2, /* (119) db_optr ::= db_optr update */ + -2, /* (120) db_optr ::= db_optr cachelast */ + -1, /* (121) topic_optr ::= db_optr */ + -2, /* (122) topic_optr ::= topic_optr partitions */ + 0, /* (123) alter_db_optr ::= */ + -2, /* (124) alter_db_optr ::= alter_db_optr replica */ + -2, /* (125) alter_db_optr ::= alter_db_optr quorum */ + -2, /* (126) alter_db_optr ::= alter_db_optr keep */ + -2, /* (127) alter_db_optr ::= alter_db_optr blocks */ + -2, /* (128) alter_db_optr ::= alter_db_optr comp */ + -2, /* (129) alter_db_optr ::= alter_db_optr update */ + -2, /* (130) alter_db_optr ::= alter_db_optr cachelast */ + -1, /* (131) alter_topic_optr ::= alter_db_optr */ + -2, /* (132) alter_topic_optr ::= alter_topic_optr partitions */ + -1, /* (133) typename ::= ids */ + -4, /* (134) typename ::= ids LP signed RP */ + -2, /* (135) typename ::= ids UNSIGNED */ + -1, /* (136) signed ::= INTEGER */ + -2, /* (137) signed ::= PLUS INTEGER */ + -2, /* (138) signed ::= MINUS INTEGER */ + -3, /* (139) cmd ::= CREATE TABLE create_table_args */ + -3, /* (140) cmd ::= CREATE TABLE create_stable_args */ + -3, /* (141) cmd ::= CREATE STABLE create_stable_args */ + -3, /* (142) cmd ::= CREATE TABLE create_table_list */ + -1, /* (143) create_table_list ::= create_from_stable */ + -2, /* (144) create_table_list ::= create_table_list create_from_stable */ + -6, /* (145) create_table_args ::= ifnotexists ids cpxName LP columnlist RP */ + -10, /* (146) create_stable_args ::= ifnotexists ids cpxName LP columnlist RP TAGS LP columnlist RP */ + -10, /* (147) create_from_stable ::= ifnotexists ids cpxName USING ids cpxName TAGS LP tagitemlist RP */ + -13, /* (148) create_from_stable ::= ifnotexists ids cpxName USING ids cpxName LP tagNamelist RP TAGS LP tagitemlist RP */ + -3, /* (149) tagNamelist ::= tagNamelist COMMA ids */ + -1, /* (150) tagNamelist ::= ids */ + -5, /* (151) create_table_args ::= ifnotexists ids cpxName AS select */ + -3, /* (152) columnlist ::= columnlist COMMA column */ + -1, /* (153) columnlist ::= column */ + -2, /* (154) column ::= ids typename */ + -3, /* (155) tagitemlist ::= tagitemlist COMMA tagitem */ + -1, /* (156) tagitemlist ::= tagitem */ + -1, /* (157) tagitem ::= INTEGER */ + -1, /* (158) tagitem ::= FLOAT */ + -1, /* (159) tagitem ::= STRING */ + -1, /* (160) tagitem ::= BOOL */ + -1, /* (161) tagitem ::= NULL */ + -1, /* (162) tagitem ::= NOW */ + -2, /* (163) tagitem ::= MINUS INTEGER */ + -2, /* (164) tagitem ::= MINUS FLOAT */ + -2, /* (165) tagitem ::= PLUS INTEGER */ + -2, /* (166) tagitem ::= PLUS FLOAT */ + -15, /* (167) select ::= SELECT selcollist from where_opt range_option interval_option sliding_opt session_option windowstate_option fill_opt groupby_opt having_opt orderby_opt slimit_opt limit_opt */ + -3, /* (168) select ::= LP select RP */ + -1, /* (169) union ::= select */ + -4, /* (170) union ::= union UNION ALL select */ + -1, /* (171) cmd ::= union */ + -2, /* (172) select ::= SELECT selcollist */ + -2, /* (173) sclp ::= selcollist COMMA */ + 0, /* (174) sclp ::= */ + -4, /* (175) selcollist ::= sclp distinct expr as */ + -2, /* (176) selcollist ::= sclp STAR */ + -2, /* (177) as ::= AS ids */ + -1, /* (178) as ::= ids */ + 0, /* (179) as ::= */ + -1, /* (180) distinct ::= DISTINCT */ + 0, /* (181) distinct ::= */ + -2, /* (182) from ::= FROM tablelist */ + -2, /* (183) from ::= FROM sub */ + -3, /* (184) sub ::= LP union RP */ + -4, /* (185) sub ::= LP union RP ids */ + -6, /* (186) sub ::= sub COMMA LP union RP ids */ + -2, /* (187) tablelist ::= ids cpxName */ + -3, /* (188) tablelist ::= ids cpxName ids */ + -4, /* (189) tablelist ::= tablelist COMMA ids cpxName */ + -5, /* (190) tablelist ::= tablelist COMMA ids cpxName ids */ + -1, /* (191) tmvar ::= VARIABLE */ + -1, /* (192) timestamp ::= INTEGER */ + -2, /* (193) timestamp ::= MINUS INTEGER */ + -2, /* (194) timestamp ::= PLUS INTEGER */ + -1, /* (195) timestamp ::= STRING */ + -1, /* (196) timestamp ::= NOW */ + -3, /* (197) timestamp ::= NOW PLUS VARIABLE */ + -3, /* (198) timestamp ::= NOW MINUS VARIABLE */ + 0, /* (199) range_option ::= */ + -6, /* (200) range_option ::= RANGE LP timestamp COMMA timestamp RP */ + -4, /* (201) interval_option ::= intervalKey LP tmvar RP */ + -6, /* (202) interval_option ::= intervalKey LP tmvar COMMA tmvar RP */ + 0, /* (203) interval_option ::= */ + -1, /* (204) intervalKey ::= INTERVAL */ + -1, /* (205) intervalKey ::= EVERY */ + 0, /* (206) session_option ::= */ + -7, /* (207) session_option ::= SESSION LP ids cpxName COMMA tmvar RP */ + 0, /* (208) windowstate_option ::= */ + -4, /* (209) windowstate_option ::= STATE_WINDOW LP ids RP */ + 0, /* (210) fill_opt ::= */ + -6, /* (211) fill_opt ::= FILL LP ID COMMA tagitemlist RP */ + -4, /* (212) fill_opt ::= FILL LP ID RP */ + -4, /* (213) sliding_opt ::= SLIDING LP tmvar RP */ + 0, /* (214) sliding_opt ::= */ + 0, /* (215) orderby_opt ::= */ + -3, /* (216) orderby_opt ::= ORDER BY sortlist */ + -4, /* (217) sortlist ::= sortlist COMMA item sortorder */ + -2, /* (218) sortlist ::= item sortorder */ + -2, /* (219) item ::= ids cpxName */ + -1, /* (220) sortorder ::= ASC */ + -1, /* (221) sortorder ::= DESC */ + 0, /* (222) sortorder ::= */ + 0, /* (223) groupby_opt ::= */ + -3, /* (224) groupby_opt ::= GROUP BY grouplist */ + -3, /* (225) grouplist ::= grouplist COMMA item */ + -1, /* (226) grouplist ::= item */ + 0, /* (227) having_opt ::= */ + -2, /* (228) having_opt ::= HAVING expr */ + 0, /* (229) limit_opt ::= */ + -2, /* (230) limit_opt ::= LIMIT signed */ + -4, /* (231) limit_opt ::= LIMIT signed OFFSET signed */ + -4, /* (232) limit_opt ::= LIMIT signed COMMA signed */ + 0, /* (233) slimit_opt ::= */ + -2, /* (234) slimit_opt ::= SLIMIT signed */ + -4, /* (235) slimit_opt ::= SLIMIT signed SOFFSET signed */ + -4, /* (236) slimit_opt ::= SLIMIT signed COMMA signed */ + 0, /* (237) where_opt ::= */ + -2, /* (238) where_opt ::= WHERE expr */ + -3, /* (239) expr ::= LP expr RP */ + -1, /* (240) expr ::= ID */ + -3, /* (241) expr ::= ID DOT ID */ + -3, /* (242) expr ::= ID DOT STAR */ + -1, /* (243) expr ::= INTEGER */ + -2, /* (244) expr ::= MINUS INTEGER */ + -2, /* (245) expr ::= PLUS INTEGER */ + -1, /* (246) expr ::= FLOAT */ + -2, /* (247) expr ::= MINUS FLOAT */ + -2, /* (248) expr ::= PLUS FLOAT */ + -1, /* (249) expr ::= STRING */ + -1, /* (250) expr ::= NOW */ + -1, /* (251) expr ::= VARIABLE */ + -2, /* (252) expr ::= PLUS VARIABLE */ + -2, /* (253) expr ::= MINUS VARIABLE */ + -1, /* (254) expr ::= BOOL */ + -1, /* (255) expr ::= NULL */ + -4, /* (256) expr ::= ID LP exprlist RP */ + -4, /* (257) expr ::= ID LP STAR RP */ + -3, /* (258) expr ::= expr IS NULL */ + -4, /* (259) expr ::= expr IS NOT NULL */ + -3, /* (260) expr ::= expr LT expr */ + -3, /* (261) expr ::= expr GT expr */ + -3, /* (262) expr ::= expr LE expr */ + -3, /* (263) expr ::= expr GE expr */ + -3, /* (264) expr ::= expr NE expr */ + -3, /* (265) expr ::= expr EQ expr */ + -5, /* (266) expr ::= expr BETWEEN expr AND expr */ + -3, /* (267) expr ::= expr AND expr */ + -3, /* (268) expr ::= expr OR expr */ + -3, /* (269) expr ::= expr PLUS expr */ + -3, /* (270) expr ::= expr MINUS expr */ + -3, /* (271) expr ::= expr STAR expr */ + -3, /* (272) expr ::= expr SLASH expr */ + -3, /* (273) expr ::= expr REM expr */ + -3, /* (274) expr ::= expr LIKE expr */ + -3, /* (275) expr ::= expr MATCH expr */ + -3, /* (276) expr ::= expr NMATCH expr */ + -5, /* (277) expr ::= expr IN LP exprlist RP */ + -3, /* (278) exprlist ::= exprlist COMMA expritem */ + -1, /* (279) exprlist ::= expritem */ + -1, /* (280) expritem ::= expr */ + 0, /* (281) expritem ::= */ + -3, /* (282) cmd ::= RESET QUERY CACHE */ + -3, /* (283) cmd ::= SYNCDB ids REPLICA */ + -7, /* (284) cmd ::= ALTER TABLE ids cpxName ADD COLUMN columnlist */ + -7, /* (285) cmd ::= ALTER TABLE ids cpxName DROP COLUMN ids */ + -7, /* (286) cmd ::= ALTER TABLE ids cpxName MODIFY COLUMN columnlist */ + -7, /* (287) cmd ::= ALTER TABLE ids cpxName ADD TAG columnlist */ + -7, /* (288) cmd ::= ALTER TABLE ids cpxName DROP TAG ids */ + -8, /* (289) cmd ::= ALTER TABLE ids cpxName CHANGE TAG ids ids */ + -9, /* (290) cmd ::= ALTER TABLE ids cpxName SET TAG ids EQ tagitem */ + -7, /* (291) cmd ::= ALTER TABLE ids cpxName MODIFY TAG columnlist */ + -7, /* (292) cmd ::= ALTER STABLE ids cpxName ADD COLUMN columnlist */ + -7, /* (293) cmd ::= ALTER STABLE ids cpxName DROP COLUMN ids */ + -7, /* (294) cmd ::= ALTER STABLE ids cpxName MODIFY COLUMN columnlist */ + -7, /* (295) cmd ::= ALTER STABLE ids cpxName ADD TAG columnlist */ + -7, /* (296) cmd ::= ALTER STABLE ids cpxName DROP TAG ids */ + -8, /* (297) cmd ::= ALTER STABLE ids cpxName CHANGE TAG ids ids */ + -9, /* (298) cmd ::= ALTER STABLE ids cpxName SET TAG ids EQ tagitem */ + -7, /* (299) cmd ::= ALTER STABLE ids cpxName MODIFY TAG columnlist */ + -3, /* (300) cmd ::= KILL CONNECTION INTEGER */ + -5, /* (301) cmd ::= KILL STREAM INTEGER COLON INTEGER */ + -5, /* (302) cmd ::= KILL QUERY INTEGER COLON INTEGER */ }; static void yy_accept(yyParser*); /* Forward Declaration */ @@ -2151,30 +2499,34 @@ static void yy_accept(yyParser*); /* Forward Declaration */ ** only called from one place, optimizing compilers will in-line it, which ** means that the extra parameters have no performance impact. */ -static void yy_reduce( +static YYACTIONTYPE yy_reduce( yyParser *yypParser, /* The parser */ unsigned int yyruleno, /* Number of the rule by which to reduce */ int yyLookahead, /* Lookahead token, or YYNOCODE if none */ ParseTOKENTYPE yyLookaheadToken /* Value of the lookahead token */ + ParseCTX_PDECL /* %extra_context */ ){ int yygoto; /* The next state */ - int yyact; /* The next action */ + YYACTIONTYPE yyact; /* The next action */ yyStackEntry *yymsp; /* The top of the parser's stack */ int yysize; /* Amount to pop the stack */ - ParseARG_FETCH; + ParseARG_FETCH (void)yyLookahead; (void)yyLookaheadToken; yymsp = yypParser->yytos; #ifndef NDEBUG if( yyTraceFILE && yyruleno<(int)(sizeof(yyRuleName)/sizeof(yyRuleName[0])) ){ - yysize = yyRuleInfo[yyruleno].nrhs; + yysize = yyRuleInfoNRhs[yyruleno]; if( yysize ){ - fprintf(yyTraceFILE, "%sReduce %d [%s], go to state %d.\n", + fprintf(yyTraceFILE, "%sReduce %d [%s]%s, pop back to state %d.\n", yyTracePrompt, - yyruleno, yyRuleName[yyruleno], yymsp[yysize].stateno); + yyruleno, yyRuleName[yyruleno], + yyrulenoyytos - yypParser->yystack)>yypParser->yyhwm ){ yypParser->yyhwm++; @@ -2192,13 +2544,19 @@ static void yy_reduce( #if YYSTACKDEPTH>0 if( yypParser->yytos>=yypParser->yystackEnd ){ yyStackOverflow(yypParser); - return; + /* The call to yyStackOverflow() above pops the stack until it is + ** empty, causing the main parser loop to exit. So the return value + ** is never used and does not matter. */ + return 0; } #else if( yypParser->yytos>=&yypParser->yystack[yypParser->yystksz-1] ){ if( yyGrowStack(yypParser) ){ yyStackOverflow(yypParser); - return; + /* The call to yyStackOverflow() above pops the stack until it is + ** empty, causing the main parser loop to exit. So the return value + ** is never used and does not matter. */ + return 0; } yymsp = yypParser->yytos; } @@ -2396,16 +2754,16 @@ static void yy_reduce( break; case 47: /* cmd ::= ALTER DATABASE ids alter_db_optr */ case 48: /* cmd ::= ALTER TOPIC ids alter_topic_optr */ yytestcase(yyruleno==48); -{ SStrToken t = {0}; setCreateDbInfo(pInfo, TSDB_SQL_ALTER_DB, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy142, &t);} +{ SStrToken t = {0}; setCreateDbInfo(pInfo, TSDB_SQL_ALTER_DB, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy10, &t);} break; case 49: /* cmd ::= ALTER ACCOUNT ids acct_optr */ -{ setCreateAcctSql(pInfo, TSDB_SQL_ALTER_ACCT, &yymsp[-1].minor.yy0, NULL, &yymsp[0].minor.yy491);} +{ setCreateAcctSql(pInfo, TSDB_SQL_ALTER_ACCT, &yymsp[-1].minor.yy0, NULL, &yymsp[0].minor.yy427);} break; case 50: /* 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.yy491);} +{ setCreateAcctSql(pInfo, TSDB_SQL_ALTER_ACCT, &yymsp[-3].minor.yy0, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy427);} break; case 51: /* cmd ::= COMPACT VNODES IN LP exprlist RP */ -{ setCompactVnodeSql(pInfo, TSDB_SQL_COMPACT_VNODE, yymsp[-1].minor.yy221);} +{ setCompactVnodeSql(pInfo, TSDB_SQL_COMPACT_VNODE, yymsp[-1].minor.yy345);} break; case 52: /* ids ::= ID */ case 53: /* ids ::= STRING */ yytestcase(yyruleno==53); @@ -2427,17 +2785,17 @@ static void yy_reduce( { setDCLSqlElems(pInfo, TSDB_SQL_CREATE_DNODE, 1, &yymsp[0].minor.yy0);} break; case 59: /* 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.yy491);} +{ setCreateAcctSql(pInfo, TSDB_SQL_CREATE_ACCT, &yymsp[-3].minor.yy0, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy427);} break; case 60: /* cmd ::= CREATE DATABASE ifnotexists ids db_optr */ case 61: /* cmd ::= CREATE TOPIC ifnotexists ids topic_optr */ yytestcase(yyruleno==61); -{ setCreateDbInfo(pInfo, TSDB_SQL_CREATE_DB, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy142, &yymsp[-2].minor.yy0);} +{ setCreateDbInfo(pInfo, TSDB_SQL_CREATE_DB, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy10, &yymsp[-2].minor.yy0);} break; case 62: /* cmd ::= CREATE FUNCTION ids AS ids OUTPUTTYPE typename bufsize */ -{ setCreateFuncInfo(pInfo, TSDB_SQL_CREATE_FUNCTION, &yymsp[-5].minor.yy0, &yymsp[-3].minor.yy0, &yymsp[-1].minor.yy503, &yymsp[0].minor.yy0, 1);} +{ setCreateFuncInfo(pInfo, TSDB_SQL_CREATE_FUNCTION, &yymsp[-5].minor.yy0, &yymsp[-3].minor.yy0, &yymsp[-1].minor.yy487, &yymsp[0].minor.yy0, 1);} break; case 63: /* cmd ::= CREATE AGGREGATE FUNCTION ids AS ids OUTPUTTYPE typename bufsize */ -{ setCreateFuncInfo(pInfo, TSDB_SQL_CREATE_FUNCTION, &yymsp[-5].minor.yy0, &yymsp[-3].minor.yy0, &yymsp[-1].minor.yy503, &yymsp[0].minor.yy0, 2);} +{ setCreateFuncInfo(pInfo, TSDB_SQL_CREATE_FUNCTION, &yymsp[-5].minor.yy0, &yymsp[-3].minor.yy0, &yymsp[-1].minor.yy487, &yymsp[0].minor.yy0, 2);} break; case 64: /* cmd ::= CREATE USER ids PASS ids */ { setCreateUserSql(pInfo, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0);} @@ -2468,38 +2826,38 @@ static void yy_reduce( break; case 85: /* acct_optr ::= pps tseries storage streams qtime dbs users conns state */ { - yylhsminor.yy491.maxUsers = (yymsp[-2].minor.yy0.n>0)?atoi(yymsp[-2].minor.yy0.z):-1; - yylhsminor.yy491.maxDbs = (yymsp[-3].minor.yy0.n>0)?atoi(yymsp[-3].minor.yy0.z):-1; - yylhsminor.yy491.maxTimeSeries = (yymsp[-7].minor.yy0.n>0)?atoi(yymsp[-7].minor.yy0.z):-1; - yylhsminor.yy491.maxStreams = (yymsp[-5].minor.yy0.n>0)?atoi(yymsp[-5].minor.yy0.z):-1; - yylhsminor.yy491.maxPointsPerSecond = (yymsp[-8].minor.yy0.n>0)?atoi(yymsp[-8].minor.yy0.z):-1; - yylhsminor.yy491.maxStorage = (yymsp[-6].minor.yy0.n>0)?strtoll(yymsp[-6].minor.yy0.z, NULL, 10):-1; - yylhsminor.yy491.maxQueryTime = (yymsp[-4].minor.yy0.n>0)?strtoll(yymsp[-4].minor.yy0.z, NULL, 10):-1; - yylhsminor.yy491.maxConnections = (yymsp[-1].minor.yy0.n>0)?atoi(yymsp[-1].minor.yy0.z):-1; - yylhsminor.yy491.stat = yymsp[0].minor.yy0; + yylhsminor.yy427.maxUsers = (yymsp[-2].minor.yy0.n>0)?atoi(yymsp[-2].minor.yy0.z):-1; + yylhsminor.yy427.maxDbs = (yymsp[-3].minor.yy0.n>0)?atoi(yymsp[-3].minor.yy0.z):-1; + yylhsminor.yy427.maxTimeSeries = (yymsp[-7].minor.yy0.n>0)?atoi(yymsp[-7].minor.yy0.z):-1; + yylhsminor.yy427.maxStreams = (yymsp[-5].minor.yy0.n>0)?atoi(yymsp[-5].minor.yy0.z):-1; + yylhsminor.yy427.maxPointsPerSecond = (yymsp[-8].minor.yy0.n>0)?atoi(yymsp[-8].minor.yy0.z):-1; + yylhsminor.yy427.maxStorage = (yymsp[-6].minor.yy0.n>0)?strtoll(yymsp[-6].minor.yy0.z, NULL, 10):-1; + yylhsminor.yy427.maxQueryTime = (yymsp[-4].minor.yy0.n>0)?strtoll(yymsp[-4].minor.yy0.z, NULL, 10):-1; + yylhsminor.yy427.maxConnections = (yymsp[-1].minor.yy0.n>0)?atoi(yymsp[-1].minor.yy0.z):-1; + yylhsminor.yy427.stat = yymsp[0].minor.yy0; } - yymsp[-8].minor.yy491 = yylhsminor.yy491; + yymsp[-8].minor.yy427 = yylhsminor.yy427; break; case 86: /* intitemlist ::= intitemlist COMMA intitem */ case 155: /* tagitemlist ::= tagitemlist COMMA tagitem */ yytestcase(yyruleno==155); -{ yylhsminor.yy221 = tVariantListAppend(yymsp[-2].minor.yy221, &yymsp[0].minor.yy106, -1); } - yymsp[-2].minor.yy221 = yylhsminor.yy221; +{ yylhsminor.yy345 = tVariantListAppend(yymsp[-2].minor.yy345, &yymsp[0].minor.yy2, -1); } + yymsp[-2].minor.yy345 = yylhsminor.yy345; break; case 87: /* intitemlist ::= intitem */ case 156: /* tagitemlist ::= tagitem */ yytestcase(yyruleno==156); -{ yylhsminor.yy221 = tVariantListAppend(NULL, &yymsp[0].minor.yy106, -1); } - yymsp[0].minor.yy221 = yylhsminor.yy221; +{ yylhsminor.yy345 = tVariantListAppend(NULL, &yymsp[0].minor.yy2, -1); } + yymsp[0].minor.yy345 = yylhsminor.yy345; break; case 88: /* intitem ::= INTEGER */ case 157: /* tagitem ::= INTEGER */ yytestcase(yyruleno==157); case 158: /* tagitem ::= FLOAT */ yytestcase(yyruleno==158); case 159: /* tagitem ::= STRING */ yytestcase(yyruleno==159); case 160: /* tagitem ::= BOOL */ yytestcase(yyruleno==160); -{ toTSDBType(yymsp[0].minor.yy0.type); tVariantCreate(&yylhsminor.yy106, &yymsp[0].minor.yy0); } - yymsp[0].minor.yy106 = yylhsminor.yy106; +{ toTSDBType(yymsp[0].minor.yy0.type); tVariantCreate(&yylhsminor.yy2, &yymsp[0].minor.yy0); } + yymsp[0].minor.yy2 = yylhsminor.yy2; break; case 89: /* keep ::= KEEP intitemlist */ -{ yymsp[-1].minor.yy221 = yymsp[0].minor.yy221; } +{ yymsp[-1].minor.yy345 = yymsp[0].minor.yy345; } break; case 90: /* cache ::= CACHE INTEGER */ case 91: /* replica ::= REPLICA INTEGER */ yytestcase(yyruleno==91); @@ -2519,221 +2877,221 @@ static void yy_reduce( { yymsp[-1].minor.yy0 = yymsp[0].minor.yy0; } break; case 105: /* db_optr ::= */ -{setDefaultCreateDbOption(&yymsp[1].minor.yy142); yymsp[1].minor.yy142.dbType = TSDB_DB_TYPE_DEFAULT;} +{setDefaultCreateDbOption(&yymsp[1].minor.yy10); yymsp[1].minor.yy10.dbType = TSDB_DB_TYPE_DEFAULT;} break; case 106: /* db_optr ::= db_optr cache */ -{ yylhsminor.yy142 = yymsp[-1].minor.yy142; yylhsminor.yy142.cacheBlockSize = strtol(yymsp[0].minor.yy0.z, NULL, 10); } - yymsp[-1].minor.yy142 = yylhsminor.yy142; +{ yylhsminor.yy10 = yymsp[-1].minor.yy10; yylhsminor.yy10.cacheBlockSize = strtol(yymsp[0].minor.yy0.z, NULL, 10); } + yymsp[-1].minor.yy10 = yylhsminor.yy10; break; case 107: /* db_optr ::= db_optr replica */ case 124: /* alter_db_optr ::= alter_db_optr replica */ yytestcase(yyruleno==124); -{ yylhsminor.yy142 = yymsp[-1].minor.yy142; yylhsminor.yy142.replica = strtol(yymsp[0].minor.yy0.z, NULL, 10); } - yymsp[-1].minor.yy142 = yylhsminor.yy142; +{ yylhsminor.yy10 = yymsp[-1].minor.yy10; yylhsminor.yy10.replica = strtol(yymsp[0].minor.yy0.z, NULL, 10); } + yymsp[-1].minor.yy10 = yylhsminor.yy10; break; case 108: /* db_optr ::= db_optr quorum */ case 125: /* alter_db_optr ::= alter_db_optr quorum */ yytestcase(yyruleno==125); -{ yylhsminor.yy142 = yymsp[-1].minor.yy142; yylhsminor.yy142.quorum = strtol(yymsp[0].minor.yy0.z, NULL, 10); } - yymsp[-1].minor.yy142 = yylhsminor.yy142; +{ yylhsminor.yy10 = yymsp[-1].minor.yy10; yylhsminor.yy10.quorum = strtol(yymsp[0].minor.yy0.z, NULL, 10); } + yymsp[-1].minor.yy10 = yylhsminor.yy10; break; case 109: /* db_optr ::= db_optr days */ -{ yylhsminor.yy142 = yymsp[-1].minor.yy142; yylhsminor.yy142.daysPerFile = strtol(yymsp[0].minor.yy0.z, NULL, 10); } - yymsp[-1].minor.yy142 = yylhsminor.yy142; +{ yylhsminor.yy10 = yymsp[-1].minor.yy10; yylhsminor.yy10.daysPerFile = strtol(yymsp[0].minor.yy0.z, NULL, 10); } + yymsp[-1].minor.yy10 = yylhsminor.yy10; break; case 110: /* db_optr ::= db_optr minrows */ -{ yylhsminor.yy142 = yymsp[-1].minor.yy142; yylhsminor.yy142.minRowsPerBlock = strtod(yymsp[0].minor.yy0.z, NULL); } - yymsp[-1].minor.yy142 = yylhsminor.yy142; +{ yylhsminor.yy10 = yymsp[-1].minor.yy10; yylhsminor.yy10.minRowsPerBlock = strtod(yymsp[0].minor.yy0.z, NULL); } + yymsp[-1].minor.yy10 = yylhsminor.yy10; break; case 111: /* db_optr ::= db_optr maxrows */ -{ yylhsminor.yy142 = yymsp[-1].minor.yy142; yylhsminor.yy142.maxRowsPerBlock = strtod(yymsp[0].minor.yy0.z, NULL); } - yymsp[-1].minor.yy142 = yylhsminor.yy142; +{ yylhsminor.yy10 = yymsp[-1].minor.yy10; yylhsminor.yy10.maxRowsPerBlock = strtod(yymsp[0].minor.yy0.z, NULL); } + yymsp[-1].minor.yy10 = yylhsminor.yy10; break; case 112: /* db_optr ::= db_optr blocks */ case 127: /* alter_db_optr ::= alter_db_optr blocks */ yytestcase(yyruleno==127); -{ yylhsminor.yy142 = yymsp[-1].minor.yy142; yylhsminor.yy142.numOfBlocks = strtol(yymsp[0].minor.yy0.z, NULL, 10); } - yymsp[-1].minor.yy142 = yylhsminor.yy142; +{ yylhsminor.yy10 = yymsp[-1].minor.yy10; yylhsminor.yy10.numOfBlocks = strtol(yymsp[0].minor.yy0.z, NULL, 10); } + yymsp[-1].minor.yy10 = yylhsminor.yy10; break; case 113: /* db_optr ::= db_optr ctime */ -{ yylhsminor.yy142 = yymsp[-1].minor.yy142; yylhsminor.yy142.commitTime = strtol(yymsp[0].minor.yy0.z, NULL, 10); } - yymsp[-1].minor.yy142 = yylhsminor.yy142; +{ yylhsminor.yy10 = yymsp[-1].minor.yy10; yylhsminor.yy10.commitTime = strtol(yymsp[0].minor.yy0.z, NULL, 10); } + yymsp[-1].minor.yy10 = yylhsminor.yy10; break; case 114: /* db_optr ::= db_optr wal */ -{ yylhsminor.yy142 = yymsp[-1].minor.yy142; yylhsminor.yy142.walLevel = strtol(yymsp[0].minor.yy0.z, NULL, 10); } - yymsp[-1].minor.yy142 = yylhsminor.yy142; +{ yylhsminor.yy10 = yymsp[-1].minor.yy10; yylhsminor.yy10.walLevel = strtol(yymsp[0].minor.yy0.z, NULL, 10); } + yymsp[-1].minor.yy10 = yylhsminor.yy10; break; case 115: /* db_optr ::= db_optr fsync */ -{ yylhsminor.yy142 = yymsp[-1].minor.yy142; yylhsminor.yy142.fsyncPeriod = strtol(yymsp[0].minor.yy0.z, NULL, 10); } - yymsp[-1].minor.yy142 = yylhsminor.yy142; +{ yylhsminor.yy10 = yymsp[-1].minor.yy10; yylhsminor.yy10.fsyncPeriod = strtol(yymsp[0].minor.yy0.z, NULL, 10); } + yymsp[-1].minor.yy10 = yylhsminor.yy10; break; case 116: /* db_optr ::= db_optr comp */ case 128: /* alter_db_optr ::= alter_db_optr comp */ yytestcase(yyruleno==128); -{ yylhsminor.yy142 = yymsp[-1].minor.yy142; yylhsminor.yy142.compressionLevel = strtol(yymsp[0].minor.yy0.z, NULL, 10); } - yymsp[-1].minor.yy142 = yylhsminor.yy142; +{ yylhsminor.yy10 = yymsp[-1].minor.yy10; yylhsminor.yy10.compressionLevel = strtol(yymsp[0].minor.yy0.z, NULL, 10); } + yymsp[-1].minor.yy10 = yylhsminor.yy10; break; case 117: /* db_optr ::= db_optr prec */ -{ yylhsminor.yy142 = yymsp[-1].minor.yy142; yylhsminor.yy142.precision = yymsp[0].minor.yy0; } - yymsp[-1].minor.yy142 = yylhsminor.yy142; +{ yylhsminor.yy10 = yymsp[-1].minor.yy10; yylhsminor.yy10.precision = yymsp[0].minor.yy0; } + yymsp[-1].minor.yy10 = yylhsminor.yy10; break; case 118: /* db_optr ::= db_optr keep */ case 126: /* alter_db_optr ::= alter_db_optr keep */ yytestcase(yyruleno==126); -{ yylhsminor.yy142 = yymsp[-1].minor.yy142; yylhsminor.yy142.keep = yymsp[0].minor.yy221; } - yymsp[-1].minor.yy142 = yylhsminor.yy142; +{ yylhsminor.yy10 = yymsp[-1].minor.yy10; yylhsminor.yy10.keep = yymsp[0].minor.yy345; } + yymsp[-1].minor.yy10 = yylhsminor.yy10; break; case 119: /* db_optr ::= db_optr update */ case 129: /* alter_db_optr ::= alter_db_optr update */ yytestcase(yyruleno==129); -{ yylhsminor.yy142 = yymsp[-1].minor.yy142; yylhsminor.yy142.update = strtol(yymsp[0].minor.yy0.z, NULL, 10); } - yymsp[-1].minor.yy142 = yylhsminor.yy142; +{ yylhsminor.yy10 = yymsp[-1].minor.yy10; yylhsminor.yy10.update = strtol(yymsp[0].minor.yy0.z, NULL, 10); } + yymsp[-1].minor.yy10 = yylhsminor.yy10; break; case 120: /* db_optr ::= db_optr cachelast */ case 130: /* alter_db_optr ::= alter_db_optr cachelast */ yytestcase(yyruleno==130); -{ yylhsminor.yy142 = yymsp[-1].minor.yy142; yylhsminor.yy142.cachelast = strtol(yymsp[0].minor.yy0.z, NULL, 10); } - yymsp[-1].minor.yy142 = yylhsminor.yy142; +{ yylhsminor.yy10 = yymsp[-1].minor.yy10; yylhsminor.yy10.cachelast = strtol(yymsp[0].minor.yy0.z, NULL, 10); } + yymsp[-1].minor.yy10 = yylhsminor.yy10; break; case 121: /* topic_optr ::= db_optr */ case 131: /* alter_topic_optr ::= alter_db_optr */ yytestcase(yyruleno==131); -{ yylhsminor.yy142 = yymsp[0].minor.yy142; yylhsminor.yy142.dbType = TSDB_DB_TYPE_TOPIC; } - yymsp[0].minor.yy142 = yylhsminor.yy142; +{ yylhsminor.yy10 = yymsp[0].minor.yy10; yylhsminor.yy10.dbType = TSDB_DB_TYPE_TOPIC; } + yymsp[0].minor.yy10 = yylhsminor.yy10; break; case 122: /* topic_optr ::= topic_optr partitions */ case 132: /* alter_topic_optr ::= alter_topic_optr partitions */ yytestcase(yyruleno==132); -{ yylhsminor.yy142 = yymsp[-1].minor.yy142; yylhsminor.yy142.partitions = strtol(yymsp[0].minor.yy0.z, NULL, 10); } - yymsp[-1].minor.yy142 = yylhsminor.yy142; +{ yylhsminor.yy10 = yymsp[-1].minor.yy10; yylhsminor.yy10.partitions = strtol(yymsp[0].minor.yy0.z, NULL, 10); } + yymsp[-1].minor.yy10 = yylhsminor.yy10; break; case 123: /* alter_db_optr ::= */ -{ setDefaultCreateDbOption(&yymsp[1].minor.yy142); yymsp[1].minor.yy142.dbType = TSDB_DB_TYPE_DEFAULT;} +{ setDefaultCreateDbOption(&yymsp[1].minor.yy10); yymsp[1].minor.yy10.dbType = TSDB_DB_TYPE_DEFAULT;} break; case 133: /* typename ::= ids */ { yymsp[0].minor.yy0.type = 0; - tSetColumnType (&yylhsminor.yy503, &yymsp[0].minor.yy0); + tSetColumnType (&yylhsminor.yy487, &yymsp[0].minor.yy0); } - yymsp[0].minor.yy503 = yylhsminor.yy503; + yymsp[0].minor.yy487 = yylhsminor.yy487; break; case 134: /* typename ::= ids LP signed RP */ { - if (yymsp[-1].minor.yy109 <= 0) { + if (yymsp[-1].minor.yy525 <= 0) { yymsp[-3].minor.yy0.type = 0; - tSetColumnType(&yylhsminor.yy503, &yymsp[-3].minor.yy0); + tSetColumnType(&yylhsminor.yy487, &yymsp[-3].minor.yy0); } else { - yymsp[-3].minor.yy0.type = -yymsp[-1].minor.yy109; // negative value of name length - tSetColumnType(&yylhsminor.yy503, &yymsp[-3].minor.yy0); + yymsp[-3].minor.yy0.type = -yymsp[-1].minor.yy525; // negative value of name length + tSetColumnType(&yylhsminor.yy487, &yymsp[-3].minor.yy0); } } - yymsp[-3].minor.yy503 = yylhsminor.yy503; + yymsp[-3].minor.yy487 = yylhsminor.yy487; break; case 135: /* 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 (&yylhsminor.yy503, &yymsp[-1].minor.yy0); + tSetColumnType (&yylhsminor.yy487, &yymsp[-1].minor.yy0); } - yymsp[-1].minor.yy503 = yylhsminor.yy503; + yymsp[-1].minor.yy487 = yylhsminor.yy487; break; case 136: /* signed ::= INTEGER */ -{ yylhsminor.yy109 = strtol(yymsp[0].minor.yy0.z, NULL, 10); } - yymsp[0].minor.yy109 = yylhsminor.yy109; +{ yylhsminor.yy525 = strtol(yymsp[0].minor.yy0.z, NULL, 10); } + yymsp[0].minor.yy525 = yylhsminor.yy525; break; case 137: /* signed ::= PLUS INTEGER */ -{ yymsp[-1].minor.yy109 = strtol(yymsp[0].minor.yy0.z, NULL, 10); } +{ yymsp[-1].minor.yy525 = strtol(yymsp[0].minor.yy0.z, NULL, 10); } break; case 138: /* signed ::= MINUS INTEGER */ -{ yymsp[-1].minor.yy109 = -strtol(yymsp[0].minor.yy0.z, NULL, 10);} +{ yymsp[-1].minor.yy525 = -strtol(yymsp[0].minor.yy0.z, NULL, 10);} break; case 142: /* cmd ::= CREATE TABLE create_table_list */ -{ pInfo->type = TSDB_SQL_CREATE_TABLE; pInfo->pCreateTableInfo = yymsp[0].minor.yy102;} +{ pInfo->type = TSDB_SQL_CREATE_TABLE; pInfo->pCreateTableInfo = yymsp[0].minor.yy170;} break; case 143: /* create_table_list ::= create_from_stable */ { SCreateTableSql* pCreateTable = calloc(1, sizeof(SCreateTableSql)); pCreateTable->childTableInfo = taosArrayInit(4, sizeof(SCreatedTableInfo)); - taosArrayPush(pCreateTable->childTableInfo, &yymsp[0].minor.yy416); + taosArrayPush(pCreateTable->childTableInfo, &yymsp[0].minor.yy72); pCreateTable->type = TSQL_CREATE_TABLE_FROM_STABLE; - yylhsminor.yy102 = pCreateTable; + yylhsminor.yy170 = pCreateTable; } - yymsp[0].minor.yy102 = yylhsminor.yy102; + yymsp[0].minor.yy170 = yylhsminor.yy170; break; case 144: /* create_table_list ::= create_table_list create_from_stable */ { - taosArrayPush(yymsp[-1].minor.yy102->childTableInfo, &yymsp[0].minor.yy416); - yylhsminor.yy102 = yymsp[-1].minor.yy102; + taosArrayPush(yymsp[-1].minor.yy170->childTableInfo, &yymsp[0].minor.yy72); + yylhsminor.yy170 = yymsp[-1].minor.yy170; } - yymsp[-1].minor.yy102 = yylhsminor.yy102; + yymsp[-1].minor.yy170 = yylhsminor.yy170; break; case 145: /* create_table_args ::= ifnotexists ids cpxName LP columnlist RP */ { - yylhsminor.yy102 = tSetCreateTableInfo(yymsp[-1].minor.yy221, NULL, NULL, TSQL_CREATE_TABLE); - setSqlInfo(pInfo, yylhsminor.yy102, NULL, TSDB_SQL_CREATE_TABLE); + yylhsminor.yy170 = tSetCreateTableInfo(yymsp[-1].minor.yy345, NULL, NULL, TSQL_CREATE_TABLE); + setSqlInfo(pInfo, yylhsminor.yy170, 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); } - yymsp[-5].minor.yy102 = yylhsminor.yy102; + yymsp[-5].minor.yy170 = yylhsminor.yy170; break; case 146: /* create_stable_args ::= ifnotexists ids cpxName LP columnlist RP TAGS LP columnlist RP */ { - yylhsminor.yy102 = tSetCreateTableInfo(yymsp[-5].minor.yy221, yymsp[-1].minor.yy221, NULL, TSQL_CREATE_STABLE); - setSqlInfo(pInfo, yylhsminor.yy102, NULL, TSDB_SQL_CREATE_TABLE); + yylhsminor.yy170 = tSetCreateTableInfo(yymsp[-5].minor.yy345, yymsp[-1].minor.yy345, NULL, TSQL_CREATE_STABLE); + setSqlInfo(pInfo, yylhsminor.yy170, 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); } - yymsp[-9].minor.yy102 = yylhsminor.yy102; + yymsp[-9].minor.yy170 = yylhsminor.yy170; break; case 147: /* 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; - yylhsminor.yy416 = createNewChildTableInfo(&yymsp[-5].minor.yy0, NULL, yymsp[-1].minor.yy221, &yymsp[-8].minor.yy0, &yymsp[-9].minor.yy0); + yylhsminor.yy72 = createNewChildTableInfo(&yymsp[-5].minor.yy0, NULL, yymsp[-1].minor.yy345, &yymsp[-8].minor.yy0, &yymsp[-9].minor.yy0); } - yymsp[-9].minor.yy416 = yylhsminor.yy416; + yymsp[-9].minor.yy72 = yylhsminor.yy72; break; case 148: /* 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; - yylhsminor.yy416 = createNewChildTableInfo(&yymsp[-8].minor.yy0, yymsp[-5].minor.yy221, yymsp[-1].minor.yy221, &yymsp[-11].minor.yy0, &yymsp[-12].minor.yy0); + yylhsminor.yy72 = createNewChildTableInfo(&yymsp[-8].minor.yy0, yymsp[-5].minor.yy345, yymsp[-1].minor.yy345, &yymsp[-11].minor.yy0, &yymsp[-12].minor.yy0); } - yymsp[-12].minor.yy416 = yylhsminor.yy416; + yymsp[-12].minor.yy72 = yylhsminor.yy72; break; case 149: /* tagNamelist ::= tagNamelist COMMA ids */ -{taosArrayPush(yymsp[-2].minor.yy221, &yymsp[0].minor.yy0); yylhsminor.yy221 = yymsp[-2].minor.yy221; } - yymsp[-2].minor.yy221 = yylhsminor.yy221; +{taosArrayPush(yymsp[-2].minor.yy345, &yymsp[0].minor.yy0); yylhsminor.yy345 = yymsp[-2].minor.yy345; } + yymsp[-2].minor.yy345 = yylhsminor.yy345; break; case 150: /* tagNamelist ::= ids */ -{yylhsminor.yy221 = taosArrayInit(4, sizeof(SStrToken)); taosArrayPush(yylhsminor.yy221, &yymsp[0].minor.yy0);} - yymsp[0].minor.yy221 = yylhsminor.yy221; +{yylhsminor.yy345 = taosArrayInit(4, sizeof(SStrToken)); taosArrayPush(yylhsminor.yy345, &yymsp[0].minor.yy0);} + yymsp[0].minor.yy345 = yylhsminor.yy345; break; case 151: /* create_table_args ::= ifnotexists ids cpxName AS select */ { - yylhsminor.yy102 = tSetCreateTableInfo(NULL, NULL, yymsp[0].minor.yy376, TSQL_CREATE_STREAM); - setSqlInfo(pInfo, yylhsminor.yy102, NULL, TSDB_SQL_CREATE_TABLE); + yylhsminor.yy170 = tSetCreateTableInfo(NULL, NULL, yymsp[0].minor.yy68, TSQL_CREATE_STREAM); + setSqlInfo(pInfo, yylhsminor.yy170, 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); } - yymsp[-4].minor.yy102 = yylhsminor.yy102; + yymsp[-4].minor.yy170 = yylhsminor.yy170; break; case 152: /* columnlist ::= columnlist COMMA column */ -{taosArrayPush(yymsp[-2].minor.yy221, &yymsp[0].minor.yy503); yylhsminor.yy221 = yymsp[-2].minor.yy221; } - yymsp[-2].minor.yy221 = yylhsminor.yy221; +{taosArrayPush(yymsp[-2].minor.yy345, &yymsp[0].minor.yy487); yylhsminor.yy345 = yymsp[-2].minor.yy345; } + yymsp[-2].minor.yy345 = yylhsminor.yy345; break; case 153: /* columnlist ::= column */ -{yylhsminor.yy221 = taosArrayInit(4, sizeof(TAOS_FIELD)); taosArrayPush(yylhsminor.yy221, &yymsp[0].minor.yy503);} - yymsp[0].minor.yy221 = yylhsminor.yy221; +{yylhsminor.yy345 = taosArrayInit(4, sizeof(TAOS_FIELD)); taosArrayPush(yylhsminor.yy345, &yymsp[0].minor.yy487);} + yymsp[0].minor.yy345 = yylhsminor.yy345; break; case 154: /* column ::= ids typename */ { - tSetColumnInfo(&yylhsminor.yy503, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy503); + tSetColumnInfo(&yylhsminor.yy487, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy487); } - yymsp[-1].minor.yy503 = yylhsminor.yy503; + yymsp[-1].minor.yy487 = yylhsminor.yy487; break; case 161: /* tagitem ::= NULL */ -{ yymsp[0].minor.yy0.type = 0; tVariantCreate(&yylhsminor.yy106, &yymsp[0].minor.yy0); } - yymsp[0].minor.yy106 = yylhsminor.yy106; +{ yymsp[0].minor.yy0.type = 0; tVariantCreate(&yylhsminor.yy2, &yymsp[0].minor.yy0); } + yymsp[0].minor.yy2 = yylhsminor.yy2; break; case 162: /* tagitem ::= NOW */ -{ yymsp[0].minor.yy0.type = TSDB_DATA_TYPE_TIMESTAMP; tVariantCreate(&yylhsminor.yy106, &yymsp[0].minor.yy0);} - yymsp[0].minor.yy106 = yylhsminor.yy106; +{ yymsp[0].minor.yy0.type = TSDB_DATA_TYPE_TIMESTAMP; tVariantCreate(&yylhsminor.yy2, &yymsp[0].minor.yy0);} + yymsp[0].minor.yy2 = yylhsminor.yy2; break; case 163: /* tagitem ::= MINUS INTEGER */ case 164: /* tagitem ::= MINUS FLOAT */ yytestcase(yyruleno==164); @@ -2743,56 +3101,56 @@ static void yy_reduce( 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(&yylhsminor.yy106, &yymsp[-1].minor.yy0); + tVariantCreate(&yylhsminor.yy2, &yymsp[-1].minor.yy0); } - yymsp[-1].minor.yy106 = yylhsminor.yy106; + yymsp[-1].minor.yy2 = yylhsminor.yy2; break; - case 167: /* select ::= SELECT selcollist from where_opt interval_option sliding_opt session_option windowstate_option fill_opt groupby_opt having_opt orderby_opt slimit_opt limit_opt */ + case 167: /* select ::= SELECT selcollist from where_opt range_option interval_option sliding_opt session_option windowstate_option fill_opt groupby_opt having_opt orderby_opt slimit_opt limit_opt */ { - yylhsminor.yy376 = tSetQuerySqlNode(&yymsp[-13].minor.yy0, yymsp[-12].minor.yy221, yymsp[-11].minor.yy164, yymsp[-10].minor.yy146, yymsp[-4].minor.yy221, yymsp[-2].minor.yy221, &yymsp[-9].minor.yy280, &yymsp[-7].minor.yy139, &yymsp[-6].minor.yy48, &yymsp[-8].minor.yy0, yymsp[-5].minor.yy221, &yymsp[0].minor.yy454, &yymsp[-1].minor.yy454, yymsp[-3].minor.yy146); + yylhsminor.yy68 = tSetQuerySqlNode(&yymsp[-14].minor.yy0, yymsp[-13].minor.yy345, yymsp[-12].minor.yy484, yymsp[-11].minor.yy418, yymsp[-4].minor.yy345, yymsp[-2].minor.yy345, &yymsp[-9].minor.yy280, &yymsp[-7].minor.yy295, &yymsp[-6].minor.yy432, &yymsp[-8].minor.yy0, yymsp[-5].minor.yy345, &yymsp[0].minor.yy114, &yymsp[-1].minor.yy114, yymsp[-3].minor.yy418, &yymsp[-10].minor.yy144); } - yymsp[-13].minor.yy376 = yylhsminor.yy376; + yymsp[-14].minor.yy68 = yylhsminor.yy68; break; case 168: /* select ::= LP select RP */ -{yymsp[-2].minor.yy376 = yymsp[-1].minor.yy376;} +{yymsp[-2].minor.yy68 = yymsp[-1].minor.yy68;} break; case 169: /* union ::= select */ -{ yylhsminor.yy221 = setSubclause(NULL, yymsp[0].minor.yy376); } - yymsp[0].minor.yy221 = yylhsminor.yy221; +{ yylhsminor.yy345 = setSubclause(NULL, yymsp[0].minor.yy68); } + yymsp[0].minor.yy345 = yylhsminor.yy345; break; case 170: /* union ::= union UNION ALL select */ -{ yylhsminor.yy221 = appendSelectClause(yymsp[-3].minor.yy221, yymsp[0].minor.yy376); } - yymsp[-3].minor.yy221 = yylhsminor.yy221; +{ yylhsminor.yy345 = appendSelectClause(yymsp[-3].minor.yy345, yymsp[0].minor.yy68); } + yymsp[-3].minor.yy345 = yylhsminor.yy345; break; case 171: /* cmd ::= union */ -{ setSqlInfo(pInfo, yymsp[0].minor.yy221, NULL, TSDB_SQL_SELECT); } +{ setSqlInfo(pInfo, yymsp[0].minor.yy345, NULL, TSDB_SQL_SELECT); } break; case 172: /* select ::= SELECT selcollist */ { - yylhsminor.yy376 = tSetQuerySqlNode(&yymsp[-1].minor.yy0, yymsp[0].minor.yy221, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); + yylhsminor.yy68 = tSetQuerySqlNode(&yymsp[-1].minor.yy0, yymsp[0].minor.yy345, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); } - yymsp[-1].minor.yy376 = yylhsminor.yy376; + yymsp[-1].minor.yy68 = yylhsminor.yy68; break; case 173: /* sclp ::= selcollist COMMA */ -{yylhsminor.yy221 = yymsp[-1].minor.yy221;} - yymsp[-1].minor.yy221 = yylhsminor.yy221; +{yylhsminor.yy345 = yymsp[-1].minor.yy345;} + yymsp[-1].minor.yy345 = yylhsminor.yy345; break; case 174: /* sclp ::= */ - case 206: /* orderby_opt ::= */ yytestcase(yyruleno==206); -{yymsp[1].minor.yy221 = 0;} + case 215: /* orderby_opt ::= */ yytestcase(yyruleno==215); +{yymsp[1].minor.yy345 = 0;} break; case 175: /* selcollist ::= sclp distinct expr as */ { - yylhsminor.yy221 = tSqlExprListAppend(yymsp[-3].minor.yy221, yymsp[-1].minor.yy146, yymsp[-2].minor.yy0.n? &yymsp[-2].minor.yy0:0, yymsp[0].minor.yy0.n?&yymsp[0].minor.yy0:0); + yylhsminor.yy345 = tSqlExprListAppend(yymsp[-3].minor.yy345, yymsp[-1].minor.yy418, yymsp[-2].minor.yy0.n? &yymsp[-2].minor.yy0:0, yymsp[0].minor.yy0.n?&yymsp[0].minor.yy0:0); } - yymsp[-3].minor.yy221 = yylhsminor.yy221; + yymsp[-3].minor.yy345 = yylhsminor.yy345; break; case 176: /* selcollist ::= sclp STAR */ { tSqlExpr *pNode = tSqlExprCreateIdValue(pInfo, NULL, TK_ALL); - yylhsminor.yy221 = tSqlExprListAppend(yymsp[-1].minor.yy221, pNode, 0, 0); + yylhsminor.yy345 = tSqlExprListAppend(yymsp[-1].minor.yy345, pNode, 0, 0); } - yymsp[-1].minor.yy221 = yylhsminor.yy221; + yymsp[-1].minor.yy345 = yylhsminor.yy345; break; case 177: /* as ::= AS ids */ { yymsp[-1].minor.yy0 = yymsp[0].minor.yy0; } @@ -2810,361 +3168,390 @@ static void yy_reduce( break; case 182: /* from ::= FROM tablelist */ case 183: /* from ::= FROM sub */ yytestcase(yyruleno==183); -{yymsp[-1].minor.yy164 = yymsp[0].minor.yy164;} +{yymsp[-1].minor.yy484 = yymsp[0].minor.yy484;} break; case 184: /* sub ::= LP union RP */ -{yymsp[-2].minor.yy164 = addSubqueryElem(NULL, yymsp[-1].minor.yy221, NULL);} +{yymsp[-2].minor.yy484 = addSubqueryElem(NULL, yymsp[-1].minor.yy345, NULL);} break; case 185: /* sub ::= LP union RP ids */ -{yymsp[-3].minor.yy164 = addSubqueryElem(NULL, yymsp[-2].minor.yy221, &yymsp[0].minor.yy0);} +{yymsp[-3].minor.yy484 = addSubqueryElem(NULL, yymsp[-2].minor.yy345, &yymsp[0].minor.yy0);} break; case 186: /* sub ::= sub COMMA LP union RP ids */ -{yylhsminor.yy164 = addSubqueryElem(yymsp[-5].minor.yy164, yymsp[-2].minor.yy221, &yymsp[0].minor.yy0);} - yymsp[-5].minor.yy164 = yylhsminor.yy164; +{yylhsminor.yy484 = addSubqueryElem(yymsp[-5].minor.yy484, yymsp[-2].minor.yy345, &yymsp[0].minor.yy0);} + yymsp[-5].minor.yy484 = yylhsminor.yy484; break; case 187: /* tablelist ::= ids cpxName */ { yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; - yylhsminor.yy164 = setTableNameList(NULL, &yymsp[-1].minor.yy0, NULL); + yylhsminor.yy484 = setTableNameList(NULL, &yymsp[-1].minor.yy0, NULL); } - yymsp[-1].minor.yy164 = yylhsminor.yy164; + yymsp[-1].minor.yy484 = yylhsminor.yy484; break; case 188: /* tablelist ::= ids cpxName ids */ { yymsp[-2].minor.yy0.n += yymsp[-1].minor.yy0.n; - yylhsminor.yy164 = setTableNameList(NULL, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0); + yylhsminor.yy484 = setTableNameList(NULL, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy164 = yylhsminor.yy164; + yymsp[-2].minor.yy484 = yylhsminor.yy484; break; case 189: /* tablelist ::= tablelist COMMA ids cpxName */ { yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; - yylhsminor.yy164 = setTableNameList(yymsp[-3].minor.yy164, &yymsp[-1].minor.yy0, NULL); + yylhsminor.yy484 = setTableNameList(yymsp[-3].minor.yy484, &yymsp[-1].minor.yy0, NULL); } - yymsp[-3].minor.yy164 = yylhsminor.yy164; + yymsp[-3].minor.yy484 = yylhsminor.yy484; break; case 190: /* tablelist ::= tablelist COMMA ids cpxName ids */ { yymsp[-2].minor.yy0.n += yymsp[-1].minor.yy0.n; - yylhsminor.yy164 = setTableNameList(yymsp[-4].minor.yy164, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0); + yylhsminor.yy484 = setTableNameList(yymsp[-4].minor.yy484, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0); } - yymsp[-4].minor.yy164 = yylhsminor.yy164; + yymsp[-4].minor.yy484 = yylhsminor.yy484; break; case 191: /* tmvar ::= VARIABLE */ {yylhsminor.yy0 = yymsp[0].minor.yy0;} yymsp[0].minor.yy0 = yylhsminor.yy0; break; - case 192: /* interval_option ::= intervalKey LP tmvar RP */ -{yylhsminor.yy280.interval = yymsp[-1].minor.yy0; yylhsminor.yy280.offset.n = 0; yylhsminor.yy280.token = yymsp[-3].minor.yy340;} + case 192: /* timestamp ::= INTEGER */ +{ yylhsminor.yy418 = tSqlExprCreateTimestamp(&yymsp[0].minor.yy0, TK_INTEGER);} + yymsp[0].minor.yy418 = yylhsminor.yy418; + break; + case 193: /* timestamp ::= MINUS INTEGER */ + case 194: /* timestamp ::= PLUS INTEGER */ yytestcase(yyruleno==194); +{ yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; yymsp[-1].minor.yy0.type = TK_INTEGER; yylhsminor.yy418 = tSqlExprCreateTimestamp(&yymsp[-1].minor.yy0, TK_INTEGER);} + yymsp[-1].minor.yy418 = yylhsminor.yy418; + break; + case 195: /* timestamp ::= STRING */ +{ yylhsminor.yy418 = tSqlExprCreateTimestamp(&yymsp[0].minor.yy0, TK_STRING);} + yymsp[0].minor.yy418 = yylhsminor.yy418; + break; + case 196: /* timestamp ::= NOW */ +{ yylhsminor.yy418 = tSqlExprCreateTimestamp(&yymsp[0].minor.yy0, TK_NOW); } + yymsp[0].minor.yy418 = yylhsminor.yy418; + break; + case 197: /* timestamp ::= NOW PLUS VARIABLE */ +{yymsp[-2].minor.yy418 = tSqlExprCreateTimestamp(&yymsp[0].minor.yy0, TK_PLUS); } + break; + case 198: /* timestamp ::= NOW MINUS VARIABLE */ +{yymsp[-2].minor.yy418 = tSqlExprCreateTimestamp(&yymsp[0].minor.yy0, TK_MINUS); } + break; + case 199: /* range_option ::= */ +{yymsp[1].minor.yy144.start = 0; yymsp[1].minor.yy144.end = 0;} + break; + case 200: /* range_option ::= RANGE LP timestamp COMMA timestamp RP */ +{yymsp[-5].minor.yy144.start = yymsp[-3].minor.yy418; yymsp[-5].minor.yy144.end = yymsp[-1].minor.yy418;} + break; + case 201: /* interval_option ::= intervalKey LP tmvar RP */ +{yylhsminor.yy280.interval = yymsp[-1].minor.yy0; yylhsminor.yy280.offset.n = 0; yylhsminor.yy280.token = yymsp[-3].minor.yy40;} yymsp[-3].minor.yy280 = yylhsminor.yy280; break; - case 193: /* interval_option ::= intervalKey LP tmvar COMMA tmvar RP */ -{yylhsminor.yy280.interval = yymsp[-3].minor.yy0; yylhsminor.yy280.offset = yymsp[-1].minor.yy0; yylhsminor.yy280.token = yymsp[-5].minor.yy340;} + case 202: /* interval_option ::= intervalKey LP tmvar COMMA tmvar RP */ +{yylhsminor.yy280.interval = yymsp[-3].minor.yy0; yylhsminor.yy280.offset = yymsp[-1].minor.yy0; yylhsminor.yy280.token = yymsp[-5].minor.yy40;} yymsp[-5].minor.yy280 = yylhsminor.yy280; break; - case 194: /* interval_option ::= */ + case 203: /* interval_option ::= */ {memset(&yymsp[1].minor.yy280, 0, sizeof(yymsp[1].minor.yy280));} break; - case 195: /* intervalKey ::= INTERVAL */ -{yymsp[0].minor.yy340 = TK_INTERVAL;} + case 204: /* intervalKey ::= INTERVAL */ +{yymsp[0].minor.yy40 = TK_INTERVAL;} break; - case 196: /* intervalKey ::= EVERY */ -{yymsp[0].minor.yy340 = TK_EVERY; } + case 205: /* intervalKey ::= EVERY */ +{yymsp[0].minor.yy40 = TK_EVERY; } break; - case 197: /* session_option ::= */ -{yymsp[1].minor.yy139.col.n = 0; yymsp[1].minor.yy139.gap.n = 0;} + case 206: /* session_option ::= */ +{yymsp[1].minor.yy295.col.n = 0; yymsp[1].minor.yy295.gap.n = 0;} break; - case 198: /* session_option ::= SESSION LP ids cpxName COMMA tmvar RP */ + case 207: /* session_option ::= SESSION LP ids cpxName COMMA tmvar RP */ { yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; - yymsp[-6].minor.yy139.col = yymsp[-4].minor.yy0; - yymsp[-6].minor.yy139.gap = yymsp[-1].minor.yy0; + yymsp[-6].minor.yy295.col = yymsp[-4].minor.yy0; + yymsp[-6].minor.yy295.gap = yymsp[-1].minor.yy0; } break; - case 199: /* windowstate_option ::= */ -{ yymsp[1].minor.yy48.col.n = 0; yymsp[1].minor.yy48.col.z = NULL;} + case 208: /* windowstate_option ::= */ +{ yymsp[1].minor.yy432.col.n = 0; yymsp[1].minor.yy432.col.z = NULL;} break; - case 200: /* windowstate_option ::= STATE_WINDOW LP ids RP */ -{ yymsp[-3].minor.yy48.col = yymsp[-1].minor.yy0; } + case 209: /* windowstate_option ::= STATE_WINDOW LP ids RP */ +{ yymsp[-3].minor.yy432.col = yymsp[-1].minor.yy0; } break; - case 201: /* fill_opt ::= */ -{ yymsp[1].minor.yy221 = 0; } + case 210: /* fill_opt ::= */ +{ yymsp[1].minor.yy345 = 0; } break; - case 202: /* fill_opt ::= FILL LP ID COMMA tagitemlist RP */ + case 211: /* 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.yy221, &A, -1, 0); - yymsp[-5].minor.yy221 = yymsp[-1].minor.yy221; + tVariantListInsert(yymsp[-1].minor.yy345, &A, -1, 0); + yymsp[-5].minor.yy345 = yymsp[-1].minor.yy345; } break; - case 203: /* fill_opt ::= FILL LP ID RP */ + case 212: /* fill_opt ::= FILL LP ID RP */ { toTSDBType(yymsp[-1].minor.yy0.type); - yymsp[-3].minor.yy221 = tVariantListAppendToken(NULL, &yymsp[-1].minor.yy0, -1); + yymsp[-3].minor.yy345 = tVariantListAppendToken(NULL, &yymsp[-1].minor.yy0, -1); } break; - case 204: /* sliding_opt ::= SLIDING LP tmvar RP */ + case 213: /* sliding_opt ::= SLIDING LP tmvar RP */ {yymsp[-3].minor.yy0 = yymsp[-1].minor.yy0; } break; - case 205: /* sliding_opt ::= */ + case 214: /* sliding_opt ::= */ {yymsp[1].minor.yy0.n = 0; yymsp[1].minor.yy0.z = NULL; yymsp[1].minor.yy0.type = 0; } break; - case 207: /* orderby_opt ::= ORDER BY sortlist */ -{yymsp[-2].minor.yy221 = yymsp[0].minor.yy221;} + case 216: /* orderby_opt ::= ORDER BY sortlist */ +{yymsp[-2].minor.yy345 = yymsp[0].minor.yy345;} break; - case 208: /* sortlist ::= sortlist COMMA item sortorder */ + case 217: /* sortlist ::= sortlist COMMA item sortorder */ { - yylhsminor.yy221 = tVariantListAppend(yymsp[-3].minor.yy221, &yymsp[-1].minor.yy106, yymsp[0].minor.yy172); + yylhsminor.yy345 = tVariantListAppend(yymsp[-3].minor.yy345, &yymsp[-1].minor.yy2, yymsp[0].minor.yy281); } - yymsp[-3].minor.yy221 = yylhsminor.yy221; + yymsp[-3].minor.yy345 = yylhsminor.yy345; break; - case 209: /* sortlist ::= item sortorder */ + case 218: /* sortlist ::= item sortorder */ { - yylhsminor.yy221 = tVariantListAppend(NULL, &yymsp[-1].minor.yy106, yymsp[0].minor.yy172); + yylhsminor.yy345 = tVariantListAppend(NULL, &yymsp[-1].minor.yy2, yymsp[0].minor.yy281); } - yymsp[-1].minor.yy221 = yylhsminor.yy221; + yymsp[-1].minor.yy345 = yylhsminor.yy345; break; - case 210: /* item ::= ids cpxName */ + case 219: /* item ::= ids cpxName */ { toTSDBType(yymsp[-1].minor.yy0.type); yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; - tVariantCreate(&yylhsminor.yy106, &yymsp[-1].minor.yy0); + tVariantCreate(&yylhsminor.yy2, &yymsp[-1].minor.yy0); } - yymsp[-1].minor.yy106 = yylhsminor.yy106; + yymsp[-1].minor.yy2 = yylhsminor.yy2; break; - case 211: /* sortorder ::= ASC */ -{ yymsp[0].minor.yy172 = TSDB_ORDER_ASC; } + case 220: /* sortorder ::= ASC */ +{ yymsp[0].minor.yy281 = TSDB_ORDER_ASC; } break; - case 212: /* sortorder ::= DESC */ -{ yymsp[0].minor.yy172 = TSDB_ORDER_DESC;} + case 221: /* sortorder ::= DESC */ +{ yymsp[0].minor.yy281 = TSDB_ORDER_DESC;} break; - case 213: /* sortorder ::= */ -{ yymsp[1].minor.yy172 = TSDB_ORDER_ASC; } + case 222: /* sortorder ::= */ +{ yymsp[1].minor.yy281 = TSDB_ORDER_ASC; } break; - case 214: /* groupby_opt ::= */ -{ yymsp[1].minor.yy221 = 0;} + case 223: /* groupby_opt ::= */ +{ yymsp[1].minor.yy345 = 0;} break; - case 215: /* groupby_opt ::= GROUP BY grouplist */ -{ yymsp[-2].minor.yy221 = yymsp[0].minor.yy221;} + case 224: /* groupby_opt ::= GROUP BY grouplist */ +{ yymsp[-2].minor.yy345 = yymsp[0].minor.yy345;} break; - case 216: /* grouplist ::= grouplist COMMA item */ + case 225: /* grouplist ::= grouplist COMMA item */ { - yylhsminor.yy221 = tVariantListAppend(yymsp[-2].minor.yy221, &yymsp[0].minor.yy106, -1); + yylhsminor.yy345 = tVariantListAppend(yymsp[-2].minor.yy345, &yymsp[0].minor.yy2, -1); } - yymsp[-2].minor.yy221 = yylhsminor.yy221; + yymsp[-2].minor.yy345 = yylhsminor.yy345; break; - case 217: /* grouplist ::= item */ + case 226: /* grouplist ::= item */ { - yylhsminor.yy221 = tVariantListAppend(NULL, &yymsp[0].minor.yy106, -1); + yylhsminor.yy345 = tVariantListAppend(NULL, &yymsp[0].minor.yy2, -1); } - yymsp[0].minor.yy221 = yylhsminor.yy221; + yymsp[0].minor.yy345 = yylhsminor.yy345; break; - case 218: /* having_opt ::= */ - case 228: /* where_opt ::= */ yytestcase(yyruleno==228); - case 272: /* expritem ::= */ yytestcase(yyruleno==272); -{yymsp[1].minor.yy146 = 0;} + case 227: /* having_opt ::= */ + case 237: /* where_opt ::= */ yytestcase(yyruleno==237); + case 281: /* expritem ::= */ yytestcase(yyruleno==281); +{yymsp[1].minor.yy418 = 0;} break; - case 219: /* having_opt ::= HAVING expr */ - case 229: /* where_opt ::= WHERE expr */ yytestcase(yyruleno==229); -{yymsp[-1].minor.yy146 = yymsp[0].minor.yy146;} + case 228: /* having_opt ::= HAVING expr */ + case 238: /* where_opt ::= WHERE expr */ yytestcase(yyruleno==238); +{yymsp[-1].minor.yy418 = yymsp[0].minor.yy418;} break; - case 220: /* limit_opt ::= */ - case 224: /* slimit_opt ::= */ yytestcase(yyruleno==224); -{yymsp[1].minor.yy454.limit = -1; yymsp[1].minor.yy454.offset = 0;} + case 229: /* limit_opt ::= */ + case 233: /* slimit_opt ::= */ yytestcase(yyruleno==233); +{yymsp[1].minor.yy114.limit = -1; yymsp[1].minor.yy114.offset = 0;} break; - case 221: /* limit_opt ::= LIMIT signed */ - case 225: /* slimit_opt ::= SLIMIT signed */ yytestcase(yyruleno==225); -{yymsp[-1].minor.yy454.limit = yymsp[0].minor.yy109; yymsp[-1].minor.yy454.offset = 0;} + case 230: /* limit_opt ::= LIMIT signed */ + case 234: /* slimit_opt ::= SLIMIT signed */ yytestcase(yyruleno==234); +{yymsp[-1].minor.yy114.limit = yymsp[0].minor.yy525; yymsp[-1].minor.yy114.offset = 0;} break; - case 222: /* limit_opt ::= LIMIT signed OFFSET signed */ -{ yymsp[-3].minor.yy454.limit = yymsp[-2].minor.yy109; yymsp[-3].minor.yy454.offset = yymsp[0].minor.yy109;} + case 231: /* limit_opt ::= LIMIT signed OFFSET signed */ +{ yymsp[-3].minor.yy114.limit = yymsp[-2].minor.yy525; yymsp[-3].minor.yy114.offset = yymsp[0].minor.yy525;} break; - case 223: /* limit_opt ::= LIMIT signed COMMA signed */ -{ yymsp[-3].minor.yy454.limit = yymsp[0].minor.yy109; yymsp[-3].minor.yy454.offset = yymsp[-2].minor.yy109;} + case 232: /* limit_opt ::= LIMIT signed COMMA signed */ +{ yymsp[-3].minor.yy114.limit = yymsp[0].minor.yy525; yymsp[-3].minor.yy114.offset = yymsp[-2].minor.yy525;} break; - case 226: /* slimit_opt ::= SLIMIT signed SOFFSET signed */ -{yymsp[-3].minor.yy454.limit = yymsp[-2].minor.yy109; yymsp[-3].minor.yy454.offset = yymsp[0].minor.yy109;} + case 235: /* slimit_opt ::= SLIMIT signed SOFFSET signed */ +{yymsp[-3].minor.yy114.limit = yymsp[-2].minor.yy525; yymsp[-3].minor.yy114.offset = yymsp[0].minor.yy525;} break; - case 227: /* slimit_opt ::= SLIMIT signed COMMA signed */ -{yymsp[-3].minor.yy454.limit = yymsp[0].minor.yy109; yymsp[-3].minor.yy454.offset = yymsp[-2].minor.yy109;} + case 236: /* slimit_opt ::= SLIMIT signed COMMA signed */ +{yymsp[-3].minor.yy114.limit = yymsp[0].minor.yy525; yymsp[-3].minor.yy114.offset = yymsp[-2].minor.yy525;} break; - case 230: /* expr ::= LP expr RP */ -{yylhsminor.yy146 = yymsp[-1].minor.yy146; yylhsminor.yy146->exprToken.z = yymsp[-2].minor.yy0.z; yylhsminor.yy146->exprToken.n = (yymsp[0].minor.yy0.z - yymsp[-2].minor.yy0.z + 1);} - yymsp[-2].minor.yy146 = yylhsminor.yy146; + case 239: /* expr ::= LP expr RP */ +{yylhsminor.yy418 = yymsp[-1].minor.yy418; yylhsminor.yy418->exprToken.z = yymsp[-2].minor.yy0.z; yylhsminor.yy418->exprToken.n = (yymsp[0].minor.yy0.z - yymsp[-2].minor.yy0.z + 1);} + yymsp[-2].minor.yy418 = yylhsminor.yy418; break; - case 231: /* expr ::= ID */ -{ yylhsminor.yy146 = tSqlExprCreateIdValue(pInfo, &yymsp[0].minor.yy0, TK_ID);} - yymsp[0].minor.yy146 = yylhsminor.yy146; + case 240: /* expr ::= ID */ +{ yylhsminor.yy418 = tSqlExprCreateIdValue(pInfo, &yymsp[0].minor.yy0, TK_ID);} + yymsp[0].minor.yy418 = yylhsminor.yy418; break; - case 232: /* expr ::= ID DOT ID */ -{ yymsp[-2].minor.yy0.n += (1+yymsp[0].minor.yy0.n); yylhsminor.yy146 = tSqlExprCreateIdValue(pInfo, &yymsp[-2].minor.yy0, TK_ID);} - yymsp[-2].minor.yy146 = yylhsminor.yy146; + case 241: /* expr ::= ID DOT ID */ +{ yymsp[-2].minor.yy0.n += (1+yymsp[0].minor.yy0.n); yylhsminor.yy418 = tSqlExprCreateIdValue(pInfo, &yymsp[-2].minor.yy0, TK_ID);} + yymsp[-2].minor.yy418 = yylhsminor.yy418; break; - case 233: /* expr ::= ID DOT STAR */ -{ yymsp[-2].minor.yy0.n += (1+yymsp[0].minor.yy0.n); yylhsminor.yy146 = tSqlExprCreateIdValue(pInfo, &yymsp[-2].minor.yy0, TK_ALL);} - yymsp[-2].minor.yy146 = yylhsminor.yy146; + case 242: /* expr ::= ID DOT STAR */ +{ yymsp[-2].minor.yy0.n += (1+yymsp[0].minor.yy0.n); yylhsminor.yy418 = tSqlExprCreateIdValue(pInfo, &yymsp[-2].minor.yy0, TK_ALL);} + yymsp[-2].minor.yy418 = yylhsminor.yy418; break; - case 234: /* expr ::= INTEGER */ -{ yylhsminor.yy146 = tSqlExprCreateIdValue(pInfo, &yymsp[0].minor.yy0, TK_INTEGER);} - yymsp[0].minor.yy146 = yylhsminor.yy146; + case 243: /* expr ::= INTEGER */ +{ yylhsminor.yy418 = tSqlExprCreateIdValue(pInfo, &yymsp[0].minor.yy0, TK_INTEGER);} + yymsp[0].minor.yy418 = yylhsminor.yy418; break; - case 235: /* expr ::= MINUS INTEGER */ - case 236: /* expr ::= PLUS INTEGER */ yytestcase(yyruleno==236); -{ yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; yymsp[-1].minor.yy0.type = TK_INTEGER; yylhsminor.yy146 = tSqlExprCreateIdValue(pInfo, &yymsp[-1].minor.yy0, TK_INTEGER);} - yymsp[-1].minor.yy146 = yylhsminor.yy146; + case 244: /* expr ::= MINUS INTEGER */ + case 245: /* expr ::= PLUS INTEGER */ yytestcase(yyruleno==245); +{ yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; yymsp[-1].minor.yy0.type = TK_INTEGER; yylhsminor.yy418 = tSqlExprCreateIdValue(pInfo, &yymsp[-1].minor.yy0, TK_INTEGER);} + yymsp[-1].minor.yy418 = yylhsminor.yy418; break; - case 237: /* expr ::= FLOAT */ -{ yylhsminor.yy146 = tSqlExprCreateIdValue(pInfo, &yymsp[0].minor.yy0, TK_FLOAT);} - yymsp[0].minor.yy146 = yylhsminor.yy146; + case 246: /* expr ::= FLOAT */ +{ yylhsminor.yy418 = tSqlExprCreateIdValue(pInfo, &yymsp[0].minor.yy0, TK_FLOAT);} + yymsp[0].minor.yy418 = yylhsminor.yy418; break; - case 238: /* expr ::= MINUS FLOAT */ - case 239: /* expr ::= PLUS FLOAT */ yytestcase(yyruleno==239); -{ yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; yymsp[-1].minor.yy0.type = TK_FLOAT; yylhsminor.yy146 = tSqlExprCreateIdValue(pInfo, &yymsp[-1].minor.yy0, TK_FLOAT);} - yymsp[-1].minor.yy146 = yylhsminor.yy146; + case 247: /* expr ::= MINUS FLOAT */ + case 248: /* expr ::= PLUS FLOAT */ yytestcase(yyruleno==248); +{ yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; yymsp[-1].minor.yy0.type = TK_FLOAT; yylhsminor.yy418 = tSqlExprCreateIdValue(pInfo, &yymsp[-1].minor.yy0, TK_FLOAT);} + yymsp[-1].minor.yy418 = yylhsminor.yy418; break; - case 240: /* expr ::= STRING */ -{ yylhsminor.yy146 = tSqlExprCreateIdValue(pInfo, &yymsp[0].minor.yy0, TK_STRING);} - yymsp[0].minor.yy146 = yylhsminor.yy146; + case 249: /* expr ::= STRING */ +{ yylhsminor.yy418 = tSqlExprCreateIdValue(pInfo, &yymsp[0].minor.yy0, TK_STRING);} + yymsp[0].minor.yy418 = yylhsminor.yy418; break; - case 241: /* expr ::= NOW */ -{ yylhsminor.yy146 = tSqlExprCreateIdValue(pInfo, &yymsp[0].minor.yy0, TK_NOW); } - yymsp[0].minor.yy146 = yylhsminor.yy146; + case 250: /* expr ::= NOW */ +{ yylhsminor.yy418 = tSqlExprCreateIdValue(pInfo, &yymsp[0].minor.yy0, TK_NOW); } + yymsp[0].minor.yy418 = yylhsminor.yy418; break; - case 242: /* expr ::= VARIABLE */ -{ yylhsminor.yy146 = tSqlExprCreateIdValue(pInfo, &yymsp[0].minor.yy0, TK_VARIABLE);} - yymsp[0].minor.yy146 = yylhsminor.yy146; + case 251: /* expr ::= VARIABLE */ +{ yylhsminor.yy418 = tSqlExprCreateIdValue(pInfo, &yymsp[0].minor.yy0, TK_VARIABLE);} + yymsp[0].minor.yy418 = yylhsminor.yy418; break; - case 243: /* expr ::= PLUS VARIABLE */ - case 244: /* expr ::= MINUS VARIABLE */ yytestcase(yyruleno==244); -{ yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; yymsp[-1].minor.yy0.type = TK_VARIABLE; yylhsminor.yy146 = tSqlExprCreateIdValue(pInfo, &yymsp[-1].minor.yy0, TK_VARIABLE);} - yymsp[-1].minor.yy146 = yylhsminor.yy146; + case 252: /* expr ::= PLUS VARIABLE */ + case 253: /* expr ::= MINUS VARIABLE */ yytestcase(yyruleno==253); +{ yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; yymsp[-1].minor.yy0.type = TK_VARIABLE; yylhsminor.yy418 = tSqlExprCreateIdValue(pInfo, &yymsp[-1].minor.yy0, TK_VARIABLE);} + yymsp[-1].minor.yy418 = yylhsminor.yy418; break; - case 245: /* expr ::= BOOL */ -{ yylhsminor.yy146 = tSqlExprCreateIdValue(pInfo, &yymsp[0].minor.yy0, TK_BOOL);} - yymsp[0].minor.yy146 = yylhsminor.yy146; + case 254: /* expr ::= BOOL */ +{ yylhsminor.yy418 = tSqlExprCreateIdValue(pInfo, &yymsp[0].minor.yy0, TK_BOOL);} + yymsp[0].minor.yy418 = yylhsminor.yy418; break; - case 246: /* expr ::= NULL */ -{ yylhsminor.yy146 = tSqlExprCreateIdValue(pInfo, &yymsp[0].minor.yy0, TK_NULL);} - yymsp[0].minor.yy146 = yylhsminor.yy146; + case 255: /* expr ::= NULL */ +{ yylhsminor.yy418 = tSqlExprCreateIdValue(pInfo, &yymsp[0].minor.yy0, TK_NULL);} + yymsp[0].minor.yy418 = yylhsminor.yy418; break; - case 247: /* expr ::= ID LP exprlist RP */ -{ tStrTokenAppend(pInfo->funcs, &yymsp[-3].minor.yy0); yylhsminor.yy146 = tSqlExprCreateFunction(yymsp[-1].minor.yy221, &yymsp[-3].minor.yy0, &yymsp[0].minor.yy0, yymsp[-3].minor.yy0.type); } - yymsp[-3].minor.yy146 = yylhsminor.yy146; + case 256: /* expr ::= ID LP exprlist RP */ +{ tStrTokenAppend(pInfo->funcs, &yymsp[-3].minor.yy0); yylhsminor.yy418 = tSqlExprCreateFunction(yymsp[-1].minor.yy345, &yymsp[-3].minor.yy0, &yymsp[0].minor.yy0, yymsp[-3].minor.yy0.type); } + yymsp[-3].minor.yy418 = yylhsminor.yy418; break; - case 248: /* expr ::= ID LP STAR RP */ -{ tStrTokenAppend(pInfo->funcs, &yymsp[-3].minor.yy0); yylhsminor.yy146 = tSqlExprCreateFunction(NULL, &yymsp[-3].minor.yy0, &yymsp[0].minor.yy0, yymsp[-3].minor.yy0.type); } - yymsp[-3].minor.yy146 = yylhsminor.yy146; + case 257: /* expr ::= ID LP STAR RP */ +{ tStrTokenAppend(pInfo->funcs, &yymsp[-3].minor.yy0); yylhsminor.yy418 = tSqlExprCreateFunction(NULL, &yymsp[-3].minor.yy0, &yymsp[0].minor.yy0, yymsp[-3].minor.yy0.type); } + yymsp[-3].minor.yy418 = yylhsminor.yy418; break; - case 249: /* expr ::= expr IS NULL */ -{yylhsminor.yy146 = tSqlExprCreate(yymsp[-2].minor.yy146, NULL, TK_ISNULL);} - yymsp[-2].minor.yy146 = yylhsminor.yy146; + case 258: /* expr ::= expr IS NULL */ +{yylhsminor.yy418 = tSqlExprCreate(yymsp[-2].minor.yy418, NULL, TK_ISNULL);} + yymsp[-2].minor.yy418 = yylhsminor.yy418; break; - case 250: /* expr ::= expr IS NOT NULL */ -{yylhsminor.yy146 = tSqlExprCreate(yymsp[-3].minor.yy146, NULL, TK_NOTNULL);} - yymsp[-3].minor.yy146 = yylhsminor.yy146; + case 259: /* expr ::= expr IS NOT NULL */ +{yylhsminor.yy418 = tSqlExprCreate(yymsp[-3].minor.yy418, NULL, TK_NOTNULL);} + yymsp[-3].minor.yy418 = yylhsminor.yy418; break; - case 251: /* expr ::= expr LT expr */ -{yylhsminor.yy146 = tSqlExprCreate(yymsp[-2].minor.yy146, yymsp[0].minor.yy146, TK_LT);} - yymsp[-2].minor.yy146 = yylhsminor.yy146; + case 260: /* expr ::= expr LT expr */ +{yylhsminor.yy418 = tSqlExprCreate(yymsp[-2].minor.yy418, yymsp[0].minor.yy418, TK_LT);} + yymsp[-2].minor.yy418 = yylhsminor.yy418; break; - case 252: /* expr ::= expr GT expr */ -{yylhsminor.yy146 = tSqlExprCreate(yymsp[-2].minor.yy146, yymsp[0].minor.yy146, TK_GT);} - yymsp[-2].minor.yy146 = yylhsminor.yy146; + case 261: /* expr ::= expr GT expr */ +{yylhsminor.yy418 = tSqlExprCreate(yymsp[-2].minor.yy418, yymsp[0].minor.yy418, TK_GT);} + yymsp[-2].minor.yy418 = yylhsminor.yy418; break; - case 253: /* expr ::= expr LE expr */ -{yylhsminor.yy146 = tSqlExprCreate(yymsp[-2].minor.yy146, yymsp[0].minor.yy146, TK_LE);} - yymsp[-2].minor.yy146 = yylhsminor.yy146; + case 262: /* expr ::= expr LE expr */ +{yylhsminor.yy418 = tSqlExprCreate(yymsp[-2].minor.yy418, yymsp[0].minor.yy418, TK_LE);} + yymsp[-2].minor.yy418 = yylhsminor.yy418; break; - case 254: /* expr ::= expr GE expr */ -{yylhsminor.yy146 = tSqlExprCreate(yymsp[-2].minor.yy146, yymsp[0].minor.yy146, TK_GE);} - yymsp[-2].minor.yy146 = yylhsminor.yy146; + case 263: /* expr ::= expr GE expr */ +{yylhsminor.yy418 = tSqlExprCreate(yymsp[-2].minor.yy418, yymsp[0].minor.yy418, TK_GE);} + yymsp[-2].minor.yy418 = yylhsminor.yy418; break; - case 255: /* expr ::= expr NE expr */ -{yylhsminor.yy146 = tSqlExprCreate(yymsp[-2].minor.yy146, yymsp[0].minor.yy146, TK_NE);} - yymsp[-2].minor.yy146 = yylhsminor.yy146; + case 264: /* expr ::= expr NE expr */ +{yylhsminor.yy418 = tSqlExprCreate(yymsp[-2].minor.yy418, yymsp[0].minor.yy418, TK_NE);} + yymsp[-2].minor.yy418 = yylhsminor.yy418; break; - case 256: /* expr ::= expr EQ expr */ -{yylhsminor.yy146 = tSqlExprCreate(yymsp[-2].minor.yy146, yymsp[0].minor.yy146, TK_EQ);} - yymsp[-2].minor.yy146 = yylhsminor.yy146; + case 265: /* expr ::= expr EQ expr */ +{yylhsminor.yy418 = tSqlExprCreate(yymsp[-2].minor.yy418, yymsp[0].minor.yy418, TK_EQ);} + yymsp[-2].minor.yy418 = yylhsminor.yy418; break; - case 257: /* expr ::= expr BETWEEN expr AND expr */ -{ tSqlExpr* X2 = tSqlExprClone(yymsp[-4].minor.yy146); yylhsminor.yy146 = tSqlExprCreate(tSqlExprCreate(yymsp[-4].minor.yy146, yymsp[-2].minor.yy146, TK_GE), tSqlExprCreate(X2, yymsp[0].minor.yy146, TK_LE), TK_AND);} - yymsp[-4].minor.yy146 = yylhsminor.yy146; + case 266: /* expr ::= expr BETWEEN expr AND expr */ +{ tSqlExpr* X2 = tSqlExprClone(yymsp[-4].minor.yy418); yylhsminor.yy418 = tSqlExprCreate(tSqlExprCreate(yymsp[-4].minor.yy418, yymsp[-2].minor.yy418, TK_GE), tSqlExprCreate(X2, yymsp[0].minor.yy418, TK_LE), TK_AND);} + yymsp[-4].minor.yy418 = yylhsminor.yy418; break; - case 258: /* expr ::= expr AND expr */ -{yylhsminor.yy146 = tSqlExprCreate(yymsp[-2].minor.yy146, yymsp[0].minor.yy146, TK_AND);} - yymsp[-2].minor.yy146 = yylhsminor.yy146; + case 267: /* expr ::= expr AND expr */ +{yylhsminor.yy418 = tSqlExprCreate(yymsp[-2].minor.yy418, yymsp[0].minor.yy418, TK_AND);} + yymsp[-2].minor.yy418 = yylhsminor.yy418; break; - case 259: /* expr ::= expr OR expr */ -{yylhsminor.yy146 = tSqlExprCreate(yymsp[-2].minor.yy146, yymsp[0].minor.yy146, TK_OR); } - yymsp[-2].minor.yy146 = yylhsminor.yy146; + case 268: /* expr ::= expr OR expr */ +{yylhsminor.yy418 = tSqlExprCreate(yymsp[-2].minor.yy418, yymsp[0].minor.yy418, TK_OR); } + yymsp[-2].minor.yy418 = yylhsminor.yy418; break; - case 260: /* expr ::= expr PLUS expr */ -{yylhsminor.yy146 = tSqlExprCreate(yymsp[-2].minor.yy146, yymsp[0].minor.yy146, TK_PLUS); } - yymsp[-2].minor.yy146 = yylhsminor.yy146; + case 269: /* expr ::= expr PLUS expr */ +{yylhsminor.yy418 = tSqlExprCreate(yymsp[-2].minor.yy418, yymsp[0].minor.yy418, TK_PLUS); } + yymsp[-2].minor.yy418 = yylhsminor.yy418; break; - case 261: /* expr ::= expr MINUS expr */ -{yylhsminor.yy146 = tSqlExprCreate(yymsp[-2].minor.yy146, yymsp[0].minor.yy146, TK_MINUS); } - yymsp[-2].minor.yy146 = yylhsminor.yy146; + case 270: /* expr ::= expr MINUS expr */ +{yylhsminor.yy418 = tSqlExprCreate(yymsp[-2].minor.yy418, yymsp[0].minor.yy418, TK_MINUS); } + yymsp[-2].minor.yy418 = yylhsminor.yy418; break; - case 262: /* expr ::= expr STAR expr */ -{yylhsminor.yy146 = tSqlExprCreate(yymsp[-2].minor.yy146, yymsp[0].minor.yy146, TK_STAR); } - yymsp[-2].minor.yy146 = yylhsminor.yy146; + case 271: /* expr ::= expr STAR expr */ +{yylhsminor.yy418 = tSqlExprCreate(yymsp[-2].minor.yy418, yymsp[0].minor.yy418, TK_STAR); } + yymsp[-2].minor.yy418 = yylhsminor.yy418; break; - case 263: /* expr ::= expr SLASH expr */ -{yylhsminor.yy146 = tSqlExprCreate(yymsp[-2].minor.yy146, yymsp[0].minor.yy146, TK_DIVIDE);} - yymsp[-2].minor.yy146 = yylhsminor.yy146; + case 272: /* expr ::= expr SLASH expr */ +{yylhsminor.yy418 = tSqlExprCreate(yymsp[-2].minor.yy418, yymsp[0].minor.yy418, TK_DIVIDE);} + yymsp[-2].minor.yy418 = yylhsminor.yy418; break; - case 264: /* expr ::= expr REM expr */ -{yylhsminor.yy146 = tSqlExprCreate(yymsp[-2].minor.yy146, yymsp[0].minor.yy146, TK_REM); } - yymsp[-2].minor.yy146 = yylhsminor.yy146; + case 273: /* expr ::= expr REM expr */ +{yylhsminor.yy418 = tSqlExprCreate(yymsp[-2].minor.yy418, yymsp[0].minor.yy418, TK_REM); } + yymsp[-2].minor.yy418 = yylhsminor.yy418; break; - case 265: /* expr ::= expr LIKE expr */ -{yylhsminor.yy146 = tSqlExprCreate(yymsp[-2].minor.yy146, yymsp[0].minor.yy146, TK_LIKE); } - yymsp[-2].minor.yy146 = yylhsminor.yy146; + case 274: /* expr ::= expr LIKE expr */ +{yylhsminor.yy418 = tSqlExprCreate(yymsp[-2].minor.yy418, yymsp[0].minor.yy418, TK_LIKE); } + yymsp[-2].minor.yy418 = yylhsminor.yy418; break; - case 266: /* expr ::= expr MATCH expr */ -{yylhsminor.yy146 = tSqlExprCreate(yymsp[-2].minor.yy146, yymsp[0].minor.yy146, TK_MATCH); } - yymsp[-2].minor.yy146 = yylhsminor.yy146; + case 275: /* expr ::= expr MATCH expr */ +{yylhsminor.yy418 = tSqlExprCreate(yymsp[-2].minor.yy418, yymsp[0].minor.yy418, TK_MATCH); } + yymsp[-2].minor.yy418 = yylhsminor.yy418; break; - case 267: /* expr ::= expr NMATCH expr */ -{yylhsminor.yy146 = tSqlExprCreate(yymsp[-2].minor.yy146, yymsp[0].minor.yy146, TK_NMATCH); } - yymsp[-2].minor.yy146 = yylhsminor.yy146; + case 276: /* expr ::= expr NMATCH expr */ +{yylhsminor.yy418 = tSqlExprCreate(yymsp[-2].minor.yy418, yymsp[0].minor.yy418, TK_NMATCH); } + yymsp[-2].minor.yy418 = yylhsminor.yy418; break; - case 268: /* expr ::= expr IN LP exprlist RP */ -{yylhsminor.yy146 = tSqlExprCreate(yymsp[-4].minor.yy146, (tSqlExpr*)yymsp[-1].minor.yy221, TK_IN); } - yymsp[-4].minor.yy146 = yylhsminor.yy146; + case 277: /* expr ::= expr IN LP exprlist RP */ +{yylhsminor.yy418 = tSqlExprCreate(yymsp[-4].minor.yy418, (tSqlExpr*)yymsp[-1].minor.yy345, TK_IN); } + yymsp[-4].minor.yy418 = yylhsminor.yy418; break; - case 269: /* exprlist ::= exprlist COMMA expritem */ -{yylhsminor.yy221 = tSqlExprListAppend(yymsp[-2].minor.yy221,yymsp[0].minor.yy146,0, 0);} - yymsp[-2].minor.yy221 = yylhsminor.yy221; + case 278: /* exprlist ::= exprlist COMMA expritem */ +{yylhsminor.yy345 = tSqlExprListAppend(yymsp[-2].minor.yy345,yymsp[0].minor.yy418,0, 0);} + yymsp[-2].minor.yy345 = yylhsminor.yy345; break; - case 270: /* exprlist ::= expritem */ -{yylhsminor.yy221 = tSqlExprListAppend(0,yymsp[0].minor.yy146,0, 0);} - yymsp[0].minor.yy221 = yylhsminor.yy221; + case 279: /* exprlist ::= expritem */ +{yylhsminor.yy345 = tSqlExprListAppend(0,yymsp[0].minor.yy418,0, 0);} + yymsp[0].minor.yy345 = yylhsminor.yy345; break; - case 271: /* expritem ::= expr */ -{yylhsminor.yy146 = yymsp[0].minor.yy146;} - yymsp[0].minor.yy146 = yylhsminor.yy146; + case 280: /* expritem ::= expr */ +{yylhsminor.yy418 = yymsp[0].minor.yy418;} + yymsp[0].minor.yy418 = yylhsminor.yy418; break; - case 273: /* cmd ::= RESET QUERY CACHE */ + case 282: /* cmd ::= RESET QUERY CACHE */ { setDCLSqlElems(pInfo, TSDB_SQL_RESET_CACHE, 0);} break; - case 274: /* cmd ::= SYNCDB ids REPLICA */ + case 283: /* cmd ::= SYNCDB ids REPLICA */ { setDCLSqlElems(pInfo, TSDB_SQL_SYNC_DB_REPLICA, 1, &yymsp[-1].minor.yy0);} break; - case 275: /* cmd ::= ALTER TABLE ids cpxName ADD COLUMN columnlist */ + case 284: /* 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.yy221, NULL, TSDB_ALTER_TABLE_ADD_COLUMN, -1); + SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-4].minor.yy0, yymsp[0].minor.yy345, NULL, TSDB_ALTER_TABLE_ADD_COLUMN, -1); setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 276: /* cmd ::= ALTER TABLE ids cpxName DROP COLUMN ids */ + case 285: /* cmd ::= ALTER TABLE ids cpxName DROP COLUMN ids */ { yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; @@ -3175,21 +3562,21 @@ static void yy_reduce( setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 277: /* cmd ::= ALTER TABLE ids cpxName MODIFY COLUMN columnlist */ + case 286: /* 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.yy221, NULL, TSDB_ALTER_TABLE_CHANGE_COLUMN, -1); + SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-4].minor.yy0, yymsp[0].minor.yy345, NULL, TSDB_ALTER_TABLE_CHANGE_COLUMN, -1); setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 278: /* cmd ::= ALTER TABLE ids cpxName ADD TAG columnlist */ + case 287: /* 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.yy221, NULL, TSDB_ALTER_TABLE_ADD_TAG_COLUMN, -1); + SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-4].minor.yy0, yymsp[0].minor.yy345, NULL, TSDB_ALTER_TABLE_ADD_TAG_COLUMN, -1); setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 279: /* cmd ::= ALTER TABLE ids cpxName DROP TAG ids */ + case 288: /* cmd ::= ALTER TABLE ids cpxName DROP TAG ids */ { yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; @@ -3200,7 +3587,7 @@ static void yy_reduce( setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 280: /* cmd ::= ALTER TABLE ids cpxName CHANGE TAG ids ids */ + case 289: /* cmd ::= ALTER TABLE ids cpxName CHANGE TAG ids ids */ { yymsp[-5].minor.yy0.n += yymsp[-4].minor.yy0.n; @@ -3214,33 +3601,33 @@ static void yy_reduce( setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 281: /* cmd ::= ALTER TABLE ids cpxName SET TAG ids EQ tagitem */ + case 290: /* 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.yy106, -1); + A = tVariantListAppend(A, &yymsp[0].minor.yy2, -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 282: /* cmd ::= ALTER TABLE ids cpxName MODIFY TAG columnlist */ + case 291: /* 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.yy221, NULL, TSDB_ALTER_TABLE_MODIFY_TAG_COLUMN, -1); + SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-4].minor.yy0, yymsp[0].minor.yy345, NULL, TSDB_ALTER_TABLE_MODIFY_TAG_COLUMN, -1); setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 283: /* cmd ::= ALTER STABLE ids cpxName ADD COLUMN columnlist */ + case 292: /* 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.yy221, NULL, TSDB_ALTER_TABLE_ADD_COLUMN, TSDB_SUPER_TABLE); + SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-4].minor.yy0, yymsp[0].minor.yy345, NULL, TSDB_ALTER_TABLE_ADD_COLUMN, TSDB_SUPER_TABLE); setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 284: /* cmd ::= ALTER STABLE ids cpxName DROP COLUMN ids */ + case 293: /* cmd ::= ALTER STABLE ids cpxName DROP COLUMN ids */ { yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; @@ -3251,21 +3638,21 @@ static void yy_reduce( setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 285: /* cmd ::= ALTER STABLE ids cpxName MODIFY COLUMN columnlist */ + case 294: /* 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.yy221, NULL, TSDB_ALTER_TABLE_CHANGE_COLUMN, TSDB_SUPER_TABLE); + SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-4].minor.yy0, yymsp[0].minor.yy345, NULL, TSDB_ALTER_TABLE_CHANGE_COLUMN, TSDB_SUPER_TABLE); setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 286: /* cmd ::= ALTER STABLE ids cpxName ADD TAG columnlist */ + case 295: /* 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.yy221, NULL, TSDB_ALTER_TABLE_ADD_TAG_COLUMN, TSDB_SUPER_TABLE); + SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-4].minor.yy0, yymsp[0].minor.yy345, NULL, TSDB_ALTER_TABLE_ADD_TAG_COLUMN, TSDB_SUPER_TABLE); setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 287: /* cmd ::= ALTER STABLE ids cpxName DROP TAG ids */ + case 296: /* cmd ::= ALTER STABLE ids cpxName DROP TAG ids */ { yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; @@ -3276,7 +3663,7 @@ static void yy_reduce( setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 288: /* cmd ::= ALTER STABLE ids cpxName CHANGE TAG ids ids */ + case 297: /* cmd ::= ALTER STABLE ids cpxName CHANGE TAG ids ids */ { yymsp[-5].minor.yy0.n += yymsp[-4].minor.yy0.n; @@ -3290,41 +3677,41 @@ static void yy_reduce( setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 289: /* cmd ::= ALTER STABLE ids cpxName SET TAG ids EQ tagitem */ + case 298: /* 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.yy106, -1); + A = tVariantListAppend(A, &yymsp[0].minor.yy2, -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 290: /* cmd ::= ALTER STABLE ids cpxName MODIFY TAG columnlist */ + case 299: /* 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.yy221, NULL, TSDB_ALTER_TABLE_MODIFY_TAG_COLUMN, TSDB_SUPER_TABLE); + SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-4].minor.yy0, yymsp[0].minor.yy345, NULL, TSDB_ALTER_TABLE_MODIFY_TAG_COLUMN, TSDB_SUPER_TABLE); setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 291: /* cmd ::= KILL CONNECTION INTEGER */ + case 300: /* cmd ::= KILL CONNECTION INTEGER */ {setKillSql(pInfo, TSDB_SQL_KILL_CONNECTION, &yymsp[0].minor.yy0);} break; - case 292: /* cmd ::= KILL STREAM INTEGER COLON INTEGER */ + case 301: /* 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 293: /* cmd ::= KILL QUERY INTEGER COLON INTEGER */ + case 302: /* 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: break; /********** End reduce actions ************************************************/ }; - assert( yyrulenostateno = (YYACTIONTYPE)yyact; yymsp->major = (YYCODETYPE)yygoto; yyTraceShift(yypParser, yyact, "... then shift"); + return yyact; } /* @@ -3348,7 +3736,8 @@ static void yy_reduce( static void yy_parse_failed( yyParser *yypParser /* The parser */ ){ - ParseARG_FETCH; + ParseARG_FETCH + ParseCTX_FETCH #ifndef NDEBUG if( yyTraceFILE ){ fprintf(yyTraceFILE,"%sFail!\n",yyTracePrompt); @@ -3359,7 +3748,8 @@ static void yy_parse_failed( ** parser fails */ /************ Begin %parse_failure code ***************************************/ /************ End %parse_failure code *****************************************/ - ParseARG_STORE; /* Suppress warning about unused %extra_argument variable */ + ParseARG_STORE /* Suppress warning about unused %extra_argument variable */ + ParseCTX_STORE } #endif /* YYNOERRORRECOVERY */ @@ -3371,7 +3761,8 @@ static void yy_syntax_error( int yymajor, /* The major type of the error token */ ParseTOKENTYPE yyminor /* The minor type of the error token */ ){ - ParseARG_FETCH; + ParseARG_FETCH + ParseCTX_FETCH #define TOKEN yyminor /************ Begin %syntax_error code ****************************************/ @@ -3397,7 +3788,8 @@ static void yy_syntax_error( assert(len <= outputBufLen); /************ End %syntax_error code ******************************************/ - ParseARG_STORE; /* Suppress warning about unused %extra_argument variable */ + ParseARG_STORE /* Suppress warning about unused %extra_argument variable */ + ParseCTX_STORE } /* @@ -3406,7 +3798,8 @@ static void yy_syntax_error( static void yy_accept( yyParser *yypParser /* The parser */ ){ - ParseARG_FETCH; + ParseARG_FETCH + ParseCTX_FETCH #ifndef NDEBUG if( yyTraceFILE ){ fprintf(yyTraceFILE,"%sAccept!\n",yyTracePrompt); @@ -3421,7 +3814,8 @@ static void yy_accept( /*********** Begin %parse_accept code *****************************************/ /*********** End %parse_accept code *******************************************/ - ParseARG_STORE; /* Suppress warning about unused %extra_argument variable */ + ParseARG_STORE /* Suppress warning about unused %extra_argument variable */ + ParseCTX_STORE } /* The main parser program. @@ -3450,45 +3844,47 @@ void Parse( ParseARG_PDECL /* Optional %extra_argument parameter */ ){ YYMINORTYPE yyminorunion; - unsigned int yyact; /* The parser action. */ + YYACTIONTYPE yyact; /* The parser action. */ #if !defined(YYERRORSYMBOL) && !defined(YYNOERRORRECOVERY) int yyendofinput; /* True if we are at the end of input */ #endif #ifdef YYERRORSYMBOL int yyerrorhit = 0; /* True if yymajor has invoked an error */ #endif - yyParser *yypParser; /* The parser */ + yyParser *yypParser = (yyParser*)yyp; /* The parser */ + ParseCTX_FETCH + ParseARG_STORE - yypParser = (yyParser*)yyp; assert( yypParser->yytos!=0 ); #if !defined(YYERRORSYMBOL) && !defined(YYNOERRORRECOVERY) yyendofinput = (yymajor==0); #endif - ParseARG_STORE; + yyact = yypParser->yytos->stateno; #ifndef NDEBUG if( yyTraceFILE ){ - int stateno = yypParser->yytos->stateno; - if( stateno < YY_MIN_REDUCE ){ + if( yyact < YY_MIN_REDUCE ){ fprintf(yyTraceFILE,"%sInput '%s' in state %d\n", - yyTracePrompt,yyTokenName[yymajor],stateno); + yyTracePrompt,yyTokenName[yymajor],yyact); }else{ fprintf(yyTraceFILE,"%sInput '%s' with pending reduce %d\n", - yyTracePrompt,yyTokenName[yymajor],stateno-YY_MIN_REDUCE); + yyTracePrompt,yyTokenName[yymajor],yyact-YY_MIN_REDUCE); } } #endif do{ - yyact = yy_find_shift_action(yypParser,(YYCODETYPE)yymajor); + assert( yyact==yypParser->yytos->stateno ); + yyact = yy_find_shift_action((YYCODETYPE)yymajor,yyact); if( yyact >= YY_MIN_REDUCE ){ - yy_reduce(yypParser,yyact-YY_MIN_REDUCE,yymajor,yyminor); + yyact = yy_reduce(yypParser,yyact-YY_MIN_REDUCE,yymajor, + yyminor ParseCTX_PARAM); }else if( yyact <= YY_MAX_SHIFTREDUCE ){ - yy_shift(yypParser,yyact,yymajor,yyminor); + yy_shift(yypParser,yyact,(YYCODETYPE)yymajor,yyminor); #ifndef YYNOERRORRECOVERY yypParser->yyerrcnt--; #endif - yymajor = YYNOCODE; + break; }else if( yyact==YY_ACCEPT_ACTION ){ yypParser->yytos--; yy_accept(yypParser); @@ -3539,10 +3935,9 @@ void Parse( yymajor = YYNOCODE; }else{ while( yypParser->yytos >= yypParser->yystack - && yymx != YYERRORSYMBOL && (yyact = yy_find_reduce_action( yypParser->yytos->stateno, - YYERRORSYMBOL)) >= YY_MIN_REDUCE + YYERRORSYMBOL)) > YY_MAX_SHIFTREDUCE ){ yy_pop_parser_stack(yypParser); } @@ -3559,6 +3954,8 @@ void Parse( } yypParser->yyerrcnt = 3; yyerrorhit = 1; + if( yymajor==YYNOCODE ) break; + yyact = yypParser->yytos->stateno; #elif defined(YYNOERRORRECOVERY) /* If the YYNOERRORRECOVERY macro is defined, then do not attempt to ** do any kind of error recovery. Instead, simply invoke the syntax @@ -3569,8 +3966,7 @@ void Parse( */ yy_syntax_error(yypParser,yymajor, yyminor); yy_destructor(yypParser,(YYCODETYPE)yymajor,&yyminorunion); - yymajor = YYNOCODE; - + break; #else /* YYERRORSYMBOL is not defined */ /* This is what we do if the grammar does not define ERROR: ** @@ -3592,10 +3988,10 @@ void Parse( yypParser->yyerrcnt = -1; #endif } - yymajor = YYNOCODE; + break; #endif } - }while( yymajor!=YYNOCODE && yypParser->yytos>yypParser->yystack ); + }while( yypParser->yytos>yypParser->yystack ); #ifndef NDEBUG if( yyTraceFILE ){ yyStackEntry *i; @@ -3610,3 +4006,17 @@ void Parse( #endif return; } + +/* +** Return the fallback token corresponding to canonical token iToken, or +** 0 if iToken has no fallback. +*/ +int ParseFallback(int iToken){ +#ifdef YYFALLBACK + assert( iToken<(int)(sizeof(yyFallback)/sizeof(yyFallback[0])) ); + return yyFallback[iToken]; +#else + (void)iToken; + return 0; +#endif +} diff --git a/src/tsdb/src/tsdbFile.c b/src/tsdb/src/tsdbFile.c index 67696e48a572c29d0d6a33d4359236162f50cd28..77d172893e5ee176e636c8f0e5f3ed15ed86be2e 100644 --- a/src/tsdb/src/tsdbFile.c +++ b/src/tsdb/src/tsdbFile.c @@ -79,7 +79,7 @@ void *tsdbDecodeSMFileEx(void *buf, SMFile *pMFile) { char *aname; buf = tsdbDecodeMFInfo(buf, &(pMFile->info)); buf = taosDecodeString(buf, &aname); - strncpy(TSDB_FILE_FULL_NAME(pMFile), aname, TSDB_FILENAME_LEN); + tstrncpy(TSDB_FILE_FULL_NAME(pMFile), aname, TSDB_FILENAME_LEN); TSDB_FILE_SET_CLOSED(pMFile); tfree(aname); @@ -345,7 +345,7 @@ static void *tsdbDecodeSDFileEx(void *buf, SDFile *pDFile) { // The sync module would send DFileSet with latest verion. buf = tsdbDecodeDFInfo(buf, &(pDFile->info), TSDB_LATEST_SFS_VER); buf = taosDecodeString(buf, &aname); - strncpy(TSDB_FILE_FULL_NAME(pDFile), aname, TSDB_FILENAME_LEN); + tstrncpy(TSDB_FILE_FULL_NAME(pDFile), aname, TSDB_FILENAME_LEN); TSDB_FILE_SET_CLOSED(pDFile); tfree(aname); @@ -716,4 +716,4 @@ static void tsdbGetFilename(int vid, int fid, uint32_t ver, TSDB_FILE_T ftype, c snprintf(fname, TSDB_FILENAME_LEN, "vnode/vnode%d/tsdb/%s-ver%" PRIu32, vid, TSDB_FNAME_SUFFIX[ftype], ver); } } -} \ No newline at end of file +} diff --git a/src/tsdb/src/tsdbMeta.c b/src/tsdb/src/tsdbMeta.c index 4621712632a6089e5f52724f72517a7aae2697dc..1bb9733970cf6730366adda7f89ec5f09577df92 100644 --- a/src/tsdb/src/tsdbMeta.c +++ b/src/tsdb/src/tsdbMeta.c @@ -342,7 +342,7 @@ int tsdbUpdateTableTagValue(STsdbRepo *repo, SUpdateTableTagValMsg *pMsg) { tsdbError( "vgId:%d failed to update tag value of table %s since version out of date, client tag version %d server tag " "version %d", - REPO_ID(pRepo), TABLE_CHAR_NAME(pTable), pMsg->tversion, schemaVersion(pTable->tagSchema)); + REPO_ID(pRepo), TABLE_CHAR_NAME(pTable), pMsg->tversion, schemaVersion(pTable->pSuper->tagSchema)); terrno = TSDB_CODE_TDB_TAG_VER_OUT_OF_DATE; return -1; } diff --git a/src/tsdb/src/tsdbRead.c b/src/tsdb/src/tsdbRead.c index bf9206445926b8151861fc3366d8327a0077a87f..9b138bbd02b7a88b9bdaddcafbc2d2290d5c3d2e 100644 --- a/src/tsdb/src/tsdbRead.c +++ b/src/tsdb/src/tsdbRead.c @@ -683,8 +683,8 @@ SArray* tsdbGetQueriedTableList(TsdbQueryHandleT *pHandle) { TsdbQueryHandleT tsdbQueryRowsInExternalWindow(STsdbRepo *tsdb, STsdbQueryCond* pCond, STableGroupInfo *groupList, uint64_t qId, SMemRef* pRef) { STsdbQueryHandle *pQueryHandle = (STsdbQueryHandle*) tsdbQueryTables(tsdb, pCond, groupList, qId, pRef); - pQueryHandle->loadExternalRow = true; - pQueryHandle->currentLoadExternalRows = true; + //pQueryHandle->loadExternalRow = true; + //pQueryHandle->currentLoadExternalRows = true; return pQueryHandle; } @@ -1377,66 +1377,63 @@ static int32_t loadFileDataBlock(STsdbQueryHandle* pQueryHandle, SBlock* pBlock, return code; } -static int doBinarySearchKey(char* pValue, int num, TSKEY key, int order) { - int firstPos, lastPos, midPos = -1; - int numOfRows; - TSKEY* keyList; - - assert(order == TSDB_ORDER_ASC || order == TSDB_ORDER_DESC); - - if (num <= 0) return -1; - - keyList = (TSKEY*)pValue; - firstPos = 0; - lastPos = num - 1; - - if (order == TSDB_ORDER_DESC) { +// search last keyList[ret] < key order asc and keyList[ret] > key order desc +static int doBinarySearchKey(TSKEY* keyList, int num, int pos, TSKEY key, int order) { + // start end posistion + int s, e; + s = pos; + + // check + assert(pos >=0 && pos < num); + assert(num > 0); + + if (order == TSDB_ORDER_ASC) { // find the first position which is smaller than the key + e = num - 1; + if (key < keyList[pos]) + return -1; while (1) { - if (key >= keyList[lastPos]) return lastPos; - if (key == keyList[firstPos]) return firstPos; - if (key < keyList[firstPos]) return firstPos - 1; - - numOfRows = lastPos - firstPos + 1; - midPos = (numOfRows >> 1) + firstPos; - - if (key < keyList[midPos]) { - lastPos = midPos - 1; - } else if (key > keyList[midPos]) { - firstPos = midPos + 1; - } else { - break; - } - } - - } else { + // check can return + if (key >= keyList[e]) + return e; + if (key <= keyList[s]) + return s; + if (e - s <= 1) + return s; + + // change start or end position + int mid = s + (e - s + 1)/2; + if (keyList[mid] > key) + e = mid; + else if(keyList[mid] < key) + s = mid; + else + return mid; + } + } else { // DESC // find the first position which is bigger than the key - while (1) { - if (key <= keyList[firstPos]) return firstPos; - if (key == keyList[lastPos]) return lastPos; - - if (key > keyList[lastPos]) { - lastPos = lastPos + 1; - if (lastPos >= num) - return -1; + e = 0; + if (key > keyList[pos]) + return -1; + while (1) { + // check can return + if (key <= keyList[e]) + return e; + if (key >= keyList[s]) + return s; + if (s - e <= 1) + return s; + + // change start or end position + int mid = s - (s - e + 1)/2; + if (keyList[mid] < key) + e = mid; + else if(keyList[mid] > key) + s = mid; else - return lastPos; - } - - numOfRows = lastPos - firstPos + 1; - midPos = (numOfRows >> 1) + firstPos; - - if (key < keyList[midPos]) { - lastPos = midPos - 1; - } else if (key > keyList[midPos]) { - firstPos = midPos + 1; - } else { - break; - } + return mid; + } } - } - - return midPos; } static int32_t doCopyRowsFromFileBlock(STsdbQueryHandle* pQueryHandle, int32_t capacity, int32_t numOfRows, int32_t start, int32_t end) { @@ -1844,7 +1841,6 @@ static void copyAllRemainRowsFromFileBlock(STsdbQueryHandle* pQueryHandle, STabl int32_t getEndPosInDataBlock(STsdbQueryHandle* pQueryHandle, SDataBlockInfo* pBlockInfo) { // NOTE: reverse the order to find the end position in data block int32_t endPos = -1; - int32_t order = ASCENDING_TRAVERSE(pQueryHandle->order)? TSDB_ORDER_DESC : TSDB_ORDER_ASC; SQueryFilePos* cur = &pQueryHandle->cur; SDataCols* pCols = pQueryHandle->rhelper.pDCols[0]; @@ -1857,7 +1853,9 @@ int32_t getEndPosInDataBlock(STsdbQueryHandle* pQueryHandle, SDataBlockInfo* pBl cur->mixBlock = (cur->pos != pBlockInfo->rows - 1); } else { assert(pCols->numOfRows > 0); - endPos = doBinarySearchKey(pCols->cols[0].pData, pCols->numOfRows, pQueryHandle->window.ekey, order); + int pos = ASCENDING_TRAVERSE(pQueryHandle->order)? 0 : pBlockInfo->rows - 1; + endPos = doBinarySearchKey(pCols->cols[0].pData, pCols->numOfRows, pos, pQueryHandle->window.ekey, pQueryHandle->order); + assert(endPos != -1); cur->mixBlock = true; } @@ -1877,17 +1875,16 @@ static void doMergeTwoLevelData(STsdbQueryHandle* pQueryHandle, STableCheckInfo* assert(pCols->cols[0].type == TSDB_DATA_TYPE_TIMESTAMP && pCols->cols[0].colId == PRIMARYKEY_TIMESTAMP_COL_INDEX && cur->pos >= 0 && cur->pos < pBlock->numOfRows); - TSKEY* tsArray = pCols->cols[0].pData; - assert(pCols->numOfRows == pBlock->numOfRows && tsArray[0] == pBlock->keyFirst && tsArray[pBlock->numOfRows-1] == pBlock->keyLast); - - // for search the endPos, so the order needs to reverse - int32_t order = (pQueryHandle->order == TSDB_ORDER_ASC)? TSDB_ORDER_DESC:TSDB_ORDER_ASC; + // key read from file + TSKEY* keyFile = pCols->cols[0].pData; + assert(pCols->numOfRows == pBlock->numOfRows && keyFile[0] == pBlock->keyFirst && keyFile[pBlock->numOfRows-1] == pBlock->keyLast); int32_t step = ASCENDING_TRAVERSE(pQueryHandle->order)? 1:-1; int32_t numOfCols = (int32_t)(QH_GET_NUM_OF_COLS(pQueryHandle)); STable* pTable = pCheckInfo->pTableObj; int32_t endPos = getEndPosInDataBlock(pQueryHandle, &blockInfo); + tsdbDebug("%p uid:%" PRIu64",tid:%d start merge data block, file block range:%"PRIu64"-%"PRIu64" rows:%d, start:%d," "end:%d, 0x%"PRIx64, @@ -1902,6 +1899,7 @@ static void doMergeTwoLevelData(STsdbQueryHandle* pQueryHandle, STableCheckInfo* STSchema* pSchema1 = NULL; STSchema* pSchema2 = NULL; + // position in file ->fpos int32_t pos = cur->pos; cur->win = TSWINDOW_INITIALIZER; @@ -1918,19 +1916,23 @@ static void doMergeTwoLevelData(STsdbQueryHandle* pQueryHandle, STableCheckInfo* break; } - TSKEY key = memRowKey(row1); - if ((key > pQueryHandle->window.ekey && ASCENDING_TRAVERSE(pQueryHandle->order)) || - (key < pQueryHandle->window.ekey && !ASCENDING_TRAVERSE(pQueryHandle->order))) { + TSKEY keyMem = memRowKey(row1); + if ((keyMem > pQueryHandle->window.ekey && ASCENDING_TRAVERSE(pQueryHandle->order)) || + (keyMem < pQueryHandle->window.ekey && !ASCENDING_TRAVERSE(pQueryHandle->order))) { break; } - if (((pos > endPos || tsArray[pos] > pQueryHandle->window.ekey) && ASCENDING_TRAVERSE(pQueryHandle->order)) || - ((pos < endPos || tsArray[pos] < pQueryHandle->window.ekey) && !ASCENDING_TRAVERSE(pQueryHandle->order))) { - break; + // break if pos not in this block endPos range. note old code when pos is -1 can crash. + if(ASCENDING_TRAVERSE(pQueryHandle->order)) { //ASC + if(pos > endPos || keyFile[pos] > pQueryHandle->window.ekey) + break; + } else { //DESC + if(pos < endPos || keyFile[pos] < pQueryHandle->window.ekey) + break; } - if ((key < tsArray[pos] && ASCENDING_TRAVERSE(pQueryHandle->order)) || - (key > tsArray[pos] && !ASCENDING_TRAVERSE(pQueryHandle->order))) { + if ((keyMem < keyFile[pos] && ASCENDING_TRAVERSE(pQueryHandle->order)) || + (keyMem > keyFile[pos] && !ASCENDING_TRAVERSE(pQueryHandle->order))) { if (rv1 != memRowVersion(row1)) { pSchema1 = tsdbGetTableSchemaByVersion(pTable, memRowVersion(row1), (int8_t)memRowType(row1)); rv1 = memRowVersion(row1); @@ -1942,16 +1944,18 @@ static void doMergeTwoLevelData(STsdbQueryHandle* pQueryHandle, STableCheckInfo* mergeTwoRowFromMem(pQueryHandle, pQueryHandle->outputCapacity, numOfRows, row1, row2, numOfCols, pTable, pSchema1, pSchema2, true); numOfRows += 1; + // record start key with memory key if not if (cur->win.skey == TSKEY_INITIAL_VAL) { - cur->win.skey = key; + cur->win.skey = keyMem; } - cur->win.ekey = key; - cur->lastKey = key + step; + cur->win.ekey = keyMem; + cur->lastKey = keyMem + step; cur->mixBlock = true; moveToNextRowInMem(pCheckInfo); - } else if (key == tsArray[pos]) { // data in buffer has the same timestamp of data in file block, ignore it + // same select mem key if update is true + } else if (keyMem == keyFile[pos]) { if (pCfg->update) { if(pCfg->update == TD_ROW_PARTIAL_UPDATE) { doCopyRowsFromFileBlock(pQueryHandle, pQueryHandle->outputCapacity, numOfRows, pos, pos); @@ -1969,31 +1973,36 @@ static void doMergeTwoLevelData(STsdbQueryHandle* pQueryHandle, STableCheckInfo* mergeTwoRowFromMem(pQueryHandle, pQueryHandle->outputCapacity, numOfRows, row1, row2, numOfCols, pTable, pSchema1, pSchema2, forceSetNull); numOfRows += 1; if (cur->win.skey == TSKEY_INITIAL_VAL) { - cur->win.skey = key; + cur->win.skey = keyMem; } - cur->win.ekey = key; - cur->lastKey = key + step; + cur->win.ekey = keyMem; + cur->lastKey = keyMem + step; cur->mixBlock = true; - + + //mem move next moveToNextRowInMem(pCheckInfo); + //file move next, discard file row pos += step; } else { + // not update, only mem move to next, discard mem row moveToNextRowInMem(pCheckInfo); } - } else if ((key > tsArray[pos] && ASCENDING_TRAVERSE(pQueryHandle->order)) || - (key < tsArray[pos] && !ASCENDING_TRAVERSE(pQueryHandle->order))) { + // put file row + } else if ((keyMem > keyFile[pos] && ASCENDING_TRAVERSE(pQueryHandle->order)) || + (keyMem < keyFile[pos] && !ASCENDING_TRAVERSE(pQueryHandle->order))) { if (cur->win.skey == TSKEY_INITIAL_VAL) { - cur->win.skey = tsArray[pos]; + cur->win.skey = keyFile[pos]; } - int32_t end = doBinarySearchKey(pCols->cols[0].pData, pCols->numOfRows, key, order); + int32_t end = doBinarySearchKey(pCols->cols[0].pData, pCols->numOfRows, pos, keyMem, pQueryHandle->order); assert(end != -1); - if (tsArray[end] == key) { // the value of key in cache equals to the end timestamp value, ignore it + if (keyFile[end] == keyMem) { // the value of key in cache equals to the end timestamp value, ignore it if (pCfg->update == TD_ROW_DISCARD_UPDATE) { moveToNextRowInMem(pCheckInfo); } else { + // can update, don't copy then deal on next loop with keyMem == keyFile[pos] end -= step; } } @@ -2001,10 +2010,17 @@ static void doMergeTwoLevelData(STsdbQueryHandle* pQueryHandle, STableCheckInfo* int32_t qstart = 0, qend = 0; getQualifiedRowsPos(pQueryHandle, pos, end, numOfRows, &qstart, &qend); - numOfRows = doCopyRowsFromFileBlock(pQueryHandle, pQueryHandle->outputCapacity, numOfRows, qstart, qend); - pos += (qend - qstart + 1) * step; - - cur->win.ekey = ASCENDING_TRAVERSE(pQueryHandle->order)? tsArray[qend]:tsArray[qstart]; + if(qend >= qstart) { + // copy qend - qstart + 1 rows from file + numOfRows = doCopyRowsFromFileBlock(pQueryHandle, pQueryHandle->outputCapacity, numOfRows, qstart, qend); + int32_t num = qend - qstart + 1; + pos += num * step; + } else { + // nothing copy from file + pos += step; + } + + cur->win.ekey = ASCENDING_TRAVERSE(pQueryHandle->order)? keyFile[qend] : keyFile[qstart]; cur->lastKey = cur->win.ekey + step; } } while (numOfRows < pQueryHandle->outputCapacity); @@ -2021,7 +2037,7 @@ static void doMergeTwoLevelData(STsdbQueryHandle* pQueryHandle, STableCheckInfo* !ASCENDING_TRAVERSE(pQueryHandle->order))) { // no data in cache or data in cache is greater than the ekey of time window, load data from file block if (cur->win.skey == TSKEY_INITIAL_VAL) { - cur->win.skey = tsArray[pos]; + cur->win.skey = keyFile[pos]; } int32_t start = -1, end = -1; @@ -2030,7 +2046,7 @@ static void doMergeTwoLevelData(STsdbQueryHandle* pQueryHandle, STableCheckInfo* numOfRows = doCopyRowsFromFileBlock(pQueryHandle, pQueryHandle->outputCapacity, numOfRows, start, end); pos += (end - start + 1) * step; - cur->win.ekey = ASCENDING_TRAVERSE(pQueryHandle->order)? tsArray[end]:tsArray[start]; + cur->win.ekey = ASCENDING_TRAVERSE(pQueryHandle->order)? keyFile[end] : keyFile[start]; cur->lastKey = cur->win.ekey + step; cur->mixBlock = true; } @@ -2913,6 +2929,22 @@ static bool loadCachedLast(STsdbQueryHandle* pQueryHandle) { return false; } +void tsdbSwitchTable(TsdbQueryHandleT queryHandle) { + STsdbQueryHandle* pQueryHandle = (STsdbQueryHandle*) queryHandle; + + STableCheckInfo* pCheckInfo = taosArrayGet(pQueryHandle->pTableCheckInfo, pQueryHandle->activeIndex); + pCheckInfo->numOfBlocks = 0; + + pQueryHandle->locateStart = false; + pQueryHandle->checkFiles = true; + pQueryHandle->cur.rows = 0; + pQueryHandle->currentLoadExternalRows = pQueryHandle->loadExternalRow; + + terrno = TSDB_CODE_SUCCESS; + + ++pQueryHandle->activeIndex; +} + static bool loadDataBlockFromTableSeq(STsdbQueryHandle* pQueryHandle) { size_t numOfTables = taosArrayGetSize(pQueryHandle->pTableCheckInfo); @@ -2946,6 +2978,9 @@ static bool loadDataBlockFromTableSeq(STsdbQueryHandle* pQueryHandle) { // handle data in cache situation bool tsdbNextDataBlock(TsdbQueryHandleT pHandle) { STsdbQueryHandle* pQueryHandle = (STsdbQueryHandle*) pHandle; + if (pQueryHandle == NULL) { + return false; + } if (emptyQueryTimewindow(pQueryHandle)) { tsdbDebug("%p query window not overlaps with the data set, no result returned, 0x%"PRIx64, pQueryHandle, pQueryHandle->qId); @@ -3065,6 +3100,9 @@ static int32_t doGetExternalRow(STsdbQueryHandle* pQueryHandle, int16_t type, SM pSecQueryHandle = tsdbQueryTablesImpl(pQueryHandle->pTsdb, &cond, pQueryHandle->qId, pMemRef); tfree(cond.colList); + if (pSecQueryHandle == NULL) { + goto out_of_memory; + } // current table, only one table STableCheckInfo* pCurrent = taosArrayGet(pQueryHandle->pTableCheckInfo, pQueryHandle->activeIndex); diff --git a/src/util/src/tcompare.c b/src/util/src/tcompare.c index 4bed561f71aef6aafcf4ec2af814c0a2c7e6b63f..23bb73ff860a2b0c4bd5a81005089910faa7792a 100644 --- a/src/util/src/tcompare.c +++ b/src/util/src/tcompare.c @@ -278,6 +278,7 @@ int patternMatch(const char *patterStr, const char *str, size_t size, const SPat if (j <= size) { if (c == '\\' && patterStr[i] == '_' && c1 == '_') { i++; continue; } + if (c == '\\' && patterStr[i] == '%' && c1 == '%') { i++; continue; } if (c == c1 || tolower(c) == tolower(c1) || (c == pInfo->matchOne && c1 != 0)) { continue; } diff --git a/src/util/src/ttokenizer.c b/src/util/src/ttokenizer.c index 0c7b65be80685e79312906010f476073f71b350f..5eee3adbc3e83e3d26a2bd93e0b564d21cfc6668 100644 --- a/src/util/src/ttokenizer.c +++ b/src/util/src/ttokenizer.c @@ -229,7 +229,8 @@ static SKeyword keywordTable[] = { {"FUNCTIONS", TK_FUNCTIONS}, {"OUTPUTTYPE", TK_OUTPUTTYPE}, {"AGGREGATE", TK_AGGREGATE}, - {"BUFSIZE", TK_BUFSIZE} + {"BUFSIZE", TK_BUFSIZE}, + {"RANGE", TK_RANGE} }; static const char isIdChar[] = { @@ -626,12 +627,16 @@ SStrToken tStrGetToken(char* str, int32_t* i, bool isPrevOptr) { while (isspace(t) || t == ',') { if (t == ',' && (++numOfComma > 1)) { // comma only allowed once t0.n = 0; + t0.type = TK_ILLEGAL; return t0; } t = str[++(*i)]; } - + if (str[*i] == 0) { + t0.n = 0; + break; + } t0.n = tGetToken(&str[*i], &t0.type); break; diff --git a/src/util/src/tutil.c b/src/util/src/tutil.c index 31556b83d06224d285db29650eba82c4d3acab5e..c8172fc0aff010332de7d13071a28303f37cf7f5 100644 --- a/src/util/src/tutil.c +++ b/src/util/src/tutil.c @@ -64,7 +64,7 @@ int32_t strRmquote(char *z, int32_t len){ int32_t j = 0; for (uint32_t k = 1; k < len - 1; ++k) { if (z[k] == '\\' || (z[k] == delim && z[k + 1] == delim)) { - if (z[k] == '\\' && z[k + 1] == '_') { + if ((z[k] == '\\' && z[k + 1] == '_') || (z[k] == '\\' && z[k + 1] == '%')) { //match '_' self } else { z[j] = z[k + 1]; diff --git a/tests/examples/C#/C#checker/TDengineDriver.cs b/tests/examples/C#/C#checker/TDengineDriver.cs index 2864b7bcdddc6cb5ded1bb1bd54ff818b2181d18..0f6477ff75a9b457069112c477746dd036c71251 100644 --- a/tests/examples/C#/C#checker/TDengineDriver.cs +++ b/tests/examples/C#/C#checker/TDengineDriver.cs @@ -164,8 +164,12 @@ namespace TDengineDriver [DllImport("taos", EntryPoint = "taos_close", CallingConvention = CallingConvention.Cdecl)] static extern public int Close(IntPtr taos); - //get precisionin parameter restultset + //get precision in restultset [DllImport("taos", EntryPoint = "taos_result_precision", CallingConvention = CallingConvention.Cdecl)] static extern public int ResultPrecision(IntPtr taos); + + //schemaless API + [DllImport("taos",SetLastError = true, EntryPoint = "taos_schemaless_insert", CallingConvention = CallingConvention.Cdecl)] + static extern public IntPtr SchemalessInsert(IntPtr taos, string[] lines, int numLines, int protocol, int precision); } } diff --git a/tests/examples/C#/TDengineDriver.cs b/tests/examples/C#/TDengineDriver.cs index 2864b7bcdddc6cb5ded1bb1bd54ff818b2181d18..6e86b692f7edf512c751a49590eca3bf74949091 100644 --- a/tests/examples/C#/TDengineDriver.cs +++ b/tests/examples/C#/TDengineDriver.cs @@ -164,8 +164,12 @@ namespace TDengineDriver [DllImport("taos", EntryPoint = "taos_close", CallingConvention = CallingConvention.Cdecl)] static extern public int Close(IntPtr taos); - //get precisionin parameter restultset + //get precision in restultset [DllImport("taos", EntryPoint = "taos_result_precision", CallingConvention = CallingConvention.Cdecl)] static extern public int ResultPrecision(IntPtr taos); + + //schemaless API + [DllImport("taos",SetLastError = true, EntryPoint = "taos_schemaless_insert", CallingConvention = CallingConvention.Cdecl)] + static extern public IntPtr SchemalessInsert(IntPtr taos, string[] lines, int numLines, int protocol, int precision); } } diff --git a/tests/examples/C#/schemaless/TDengineDriver.cs b/tests/examples/C#/schemaless/TDengineDriver.cs new file mode 100644 index 0000000000000000000000000000000000000000..8dd9ce0c929df66fd82bd40d6ff77a868c630efe --- /dev/null +++ b/tests/examples/C#/schemaless/TDengineDriver.cs @@ -0,0 +1,193 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +using System; +using System.Collections.Generic; +using System.Runtime.InteropServices; + +namespace TDengineDriver +{ + enum TDengineDataType + { + TSDB_DATA_TYPE_NULL = 0, // 1 bytes + TSDB_DATA_TYPE_BOOL = 1, // 1 bytes + TSDB_DATA_TYPE_TINYINT = 2, // 1 bytes + TSDB_DATA_TYPE_SMALLINT = 3, // 2 bytes + TSDB_DATA_TYPE_INT = 4, // 4 bytes + TSDB_DATA_TYPE_BIGINT = 5, // 8 bytes + TSDB_DATA_TYPE_FLOAT = 6, // 4 bytes + TSDB_DATA_TYPE_DOUBLE = 7, // 8 bytes + TSDB_DATA_TYPE_BINARY = 8, // string + TSDB_DATA_TYPE_TIMESTAMP = 9,// 8 bytes + TSDB_DATA_TYPE_NCHAR = 10, // unicode string + TSDB_DATA_TYPE_UTINYINT = 11,// 1 byte + TSDB_DATA_TYPE_USMALLINT = 12,// 2 bytes + TSDB_DATA_TYPE_UINT = 13, // 4 bytes + TSDB_DATA_TYPE_UBIGINT = 14 // 8 bytes + } + + enum TDengineInitOption + { + TSDB_OPTION_LOCALE = 0, + TSDB_OPTION_CHARSET = 1, + TSDB_OPTION_TIMEZONE = 2, + TDDB_OPTION_CONFIGDIR = 3, + TDDB_OPTION_SHELL_ACTIVITY_TIMER = 4 + } + enum TDengineSchemalessProtocol + { + TSDB_SML_UNKNOWN_PROTOCOL = 0, + TSDB_SML_LINE_PROTOCOL = 1, + TSDB_SML_TELNET_PROTOCOL = 2, + TSDB_SML_JSON_PROTOCOL = 3 + + } + enum TDengineSchemalessPrecision + { + TSDB_SML_TIMESTAMP_NOT_CONFIGURED = 0, + TSDB_SML_TIMESTAMP_HOURS = 1, + TSDB_SML_TIMESTAMP_MINUTES = 2, + TSDB_SML_TIMESTAMP_SECONDS = 3, + TSDB_SML_TIMESTAMP_MILLI_SECONDS = 4, + TSDB_SML_TIMESTAMP_MICRO_SECONDS = 5, + TSDB_SML_TIMESTAMP_NANO_SECONDS = 6 + } + + class TDengineMeta + { + public string name; + public short size; + public byte type; + public string TypeName() + { + switch ((TDengineDataType)type) + { + case TDengineDataType.TSDB_DATA_TYPE_BOOL: + return "BOOL"; + case TDengineDataType.TSDB_DATA_TYPE_TINYINT: + return "TINYINT"; + case TDengineDataType.TSDB_DATA_TYPE_SMALLINT: + return "SMALLINT"; + case TDengineDataType.TSDB_DATA_TYPE_INT: + return "INT"; + case TDengineDataType.TSDB_DATA_TYPE_BIGINT: + return "BIGINT"; + case TDengineDataType.TSDB_DATA_TYPE_UTINYINT: + return "TINYINT UNSIGNED"; + case TDengineDataType.TSDB_DATA_TYPE_USMALLINT: + return "SMALLINT UNSIGNED"; + case TDengineDataType.TSDB_DATA_TYPE_UINT: + return "INT UNSIGNED"; + case TDengineDataType.TSDB_DATA_TYPE_UBIGINT: + return "BIGINT UNSIGNED"; + case TDengineDataType.TSDB_DATA_TYPE_FLOAT: + return "FLOAT"; + case TDengineDataType.TSDB_DATA_TYPE_DOUBLE: + return "DOUBLE"; + case TDengineDataType.TSDB_DATA_TYPE_BINARY: + return "STRING"; + case TDengineDataType.TSDB_DATA_TYPE_TIMESTAMP: + return "TIMESTAMP"; + case TDengineDataType.TSDB_DATA_TYPE_NCHAR: + return "NCHAR"; + default: + return "undefine"; + } + } + } + + class TDengine + { + public const int TSDB_CODE_SUCCESS = 0; + + [DllImport("taos", EntryPoint = "taos_init", CallingConvention = CallingConvention.Cdecl)] + static extern public void Init(); + + [DllImport("taos", EntryPoint = "taos_cleanup", CallingConvention = CallingConvention.Cdecl)] + static extern public void Cleanup(); + + [DllImport("taos", EntryPoint = "taos_options", CallingConvention = CallingConvention.Cdecl)] + static extern public void Options(int option, string value); + + [DllImport("taos", EntryPoint = "taos_connect", CallingConvention = CallingConvention.Cdecl)] + static extern public IntPtr Connect(string ip, string user, string password, string db, short port); + + [DllImport("taos", EntryPoint = "taos_errstr", CallingConvention = CallingConvention.Cdecl)] + static extern private IntPtr taos_errstr(IntPtr res); + static public string Error(IntPtr res) + { + IntPtr errPtr = taos_errstr(res); + return Marshal.PtrToStringAnsi(errPtr); + } + + [DllImport("taos", EntryPoint = "taos_errno", CallingConvention = CallingConvention.Cdecl)] + static extern public int ErrorNo(IntPtr res); + + [DllImport("taos", EntryPoint = "taos_query", CallingConvention = CallingConvention.Cdecl)] + static extern public IntPtr Query(IntPtr conn, string sqlstr); + + [DllImport("taos", EntryPoint = "taos_affected_rows", CallingConvention = CallingConvention.Cdecl)] + static extern public int AffectRows(IntPtr res); + + [DllImport("taos", EntryPoint = "taos_field_count", CallingConvention = CallingConvention.Cdecl)] + static extern public int FieldCount(IntPtr res); + + [DllImport("taos", EntryPoint = "taos_fetch_fields", CallingConvention = CallingConvention.Cdecl)] + static extern private IntPtr taos_fetch_fields(IntPtr res); + static public List FetchFields(IntPtr res) + { + const int fieldSize = 68; + + List metas = new List(); + if (res == IntPtr.Zero) + { + return metas; + } + + int fieldCount = FieldCount(res); + IntPtr fieldsPtr = taos_fetch_fields(res); + + for (int i = 0; i < fieldCount; ++i) + { + int offset = i * fieldSize; + + TDengineMeta meta = new TDengineMeta(); + meta.name = Marshal.PtrToStringAnsi(fieldsPtr + offset); + meta.type = Marshal.ReadByte(fieldsPtr + offset + 65); + meta.size = Marshal.ReadInt16(fieldsPtr + offset + 66); + metas.Add(meta); + } + + return metas; + } + + [DllImport("taos", EntryPoint = "taos_fetch_row", CallingConvention = CallingConvention.Cdecl)] + static extern public IntPtr FetchRows(IntPtr res); + + [DllImport("taos", EntryPoint = "taos_free_result", CallingConvention = CallingConvention.Cdecl)] + static extern public IntPtr FreeResult(IntPtr res); + + [DllImport("taos", EntryPoint = "taos_close", CallingConvention = CallingConvention.Cdecl)] + static extern public int Close(IntPtr taos); + + //get precision in restultset + [DllImport("taos", EntryPoint = "taos_result_precision", CallingConvention = CallingConvention.Cdecl)] + static extern public int ResultPrecision(IntPtr taos); + + //schemaless API + [DllImport("taos",SetLastError = true, EntryPoint = "taos_schemaless_insert", CallingConvention = CallingConvention.Cdecl)] + static extern public IntPtr SchemalessInsert(IntPtr taos, string[] lines, int numLines, int protocol, int precision); + } +} diff --git a/tests/examples/C#/schemaless/schemalessSample.cs b/tests/examples/C#/schemaless/schemalessSample.cs new file mode 100644 index 0000000000000000000000000000000000000000..f27ac352a6fc8a3fbbaf84966ae3b82e6036e91a --- /dev/null +++ b/tests/examples/C#/schemaless/schemalessSample.cs @@ -0,0 +1,302 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +using System; +using System.Text; +using System.Collections.Generic; +using System.Runtime.InteropServices; +using System.Collections; + +namespace TDengineDriver +{ + class SchemalessSample + { + // connect parameters + private string host = "127.0.0.1"; + private string configDir = "C:/TDengine/cfg"; + private string user = "root"; + private string passwd = "taosdata"; + private short port = 0; + + private IntPtr conn = IntPtr.Zero; + private string dbName = "csharp"; + private string dbPrecision = "ms"; + + static void Main(string[] args) + { + string[] lines = { + "stg,t1=3i64,t2=4f64,t3=\"t3\" c1=3i64,c3=L\"passit\",c2=false,c4=4f64 1626006833639000000", + "stg,t1=4i64,t3=\"t4\",t2=5f64,t4=5f64 c1=3i64,c3=L\"passitagin\",c2=true,c4=5f64,c5=5f64 1626006833641000000" + }; + string[] jsonStr = { + "{" + +"\"metric\": \"stb0_0\"," + +"\"timestamp\": 1626006833," + +"\"value\": 10," + +"\"tags\": {" + +" \"t1\": true," + +"\"t2\": false," + +"\"t3\": 10," + +"\"t4\": \"123_abc_.!@#$%^&*:;,./?|+-=()[]{}<>\"" + +"}" + +"}" + }; + + SchemalessSample sample = new SchemalessSample(); + sample.InitTDengine(); + sample.ConnectTDengine(); + sample.dropDatabase(); + sample.createDatabase(); + sample.useDatabase(); + sample.schemalessInsert(lines, 2, (int)TDengineSchemalessProtocol.TSDB_SML_LINE_PROTOCOL, (int)TDengineSchemalessPrecision.TSDB_SML_TIMESTAMP_NANO_SECONDS); + sample.checkSelect("stg"); + sample.schemalessInsert(jsonStr,1,(int)TDengineSchemalessProtocol.TSDB_SML_JSON_PROTOCOL,(int)TDengineSchemalessPrecision.TSDB_SML_TIMESTAMP_SECONDS); + sample.checkSelect("stb0_0"); + sample.CloseConnection(); + sample.cleanup(); + } + + public void InitTDengine() + { + TDengine.Options((int)TDengineInitOption.TDDB_OPTION_CONFIGDIR, this.configDir); + TDengine.Options((int)TDengineInitOption.TDDB_OPTION_SHELL_ACTIVITY_TIMER, "60"); + Console.WriteLine("init..."); + TDengine.Init(); + Console.WriteLine("get connection starting..."); + } + + public void ConnectTDengine() + { + string db = ""; + this.conn = TDengine.Connect(host, this.user, this.passwd, db, this.port); + if (this.conn == IntPtr.Zero) + { + Console.WriteLine("connection failed: " + this.host); + ExitProgram(); + } + else + { + Console.WriteLine("[ OK ] Connection established."); + } + } + public void createDatabase() + { + StringBuilder sql = new StringBuilder(); + sql.Append("create database if not exists ").Append(this.dbName).Append(" precision '").Append(this.dbPrecision).Append("'"); + execute(sql.ToString()); + } + public void useDatabase() + { + StringBuilder sql = new StringBuilder(); + sql.Append("use ").Append(this.dbName); + execute(sql.ToString()); + } + public void checkSelect(String tableName) + { + StringBuilder sql = new StringBuilder(); + sql.Append("select * from ").Append(this.dbName).Append(".").Append(tableName); + ExecuteQuery(sql.ToString()); + } + + public void schemalessInsert(string[] sqlstr, int lineCnt, int protocol, int precision) + { + + IntPtr res = TDengine.SchemalessInsert(this.conn, sqlstr, lineCnt, protocol, precision); + + if (TDengine.ErrorNo(res) != 0) + { + Console.WriteLine("schemaless_insert failed:{0}", TDengine.Error(res)); + Console.WriteLine("line string:{0}", sqlstr); + Console.WriteLine(""); + ExitProgram(); + } + else + { + Console.WriteLine("else"); + Console.WriteLine("schemaless insert success:{0}", TDengine.ErrorNo(res)); + } + DisplayRes(res); + } + public void dropDatabase() + { + StringBuilder sql = new StringBuilder(); + sql.Append("drop database if exists ").Append(this.dbName); + execute(sql.ToString()); + } + public void execute(string sql) + { + DateTime dt1 = DateTime.Now; + + IntPtr res = TDengine.Query(this.conn, sql.ToString()); + + DateTime dt2 = DateTime.Now; + TimeSpan span = dt2 - dt1; + + if ((res == IntPtr.Zero) || (TDengine.ErrorNo(res) != 0)) + { + Console.Write(sql.ToString() + " failure, "); + if (res != IntPtr.Zero) + { + Console.Write("reason: " + TDengine.Error(res)); + } + Console.WriteLine(""); + ExitProgram(); + } + else + { + Console.WriteLine(sql.ToString() + " success"); + } + TDengine.FreeResult(res); + } + public void DisplayRes(IntPtr res) + { + long queryRows = 0; + int fieldCount = TDengine.FieldCount(res); + + List metas = TDengine.FetchFields(res); + for (int j = 0; j < metas.Count; j++) + { + TDengineMeta meta = (TDengineMeta)metas[j]; + } + + IntPtr rowdata; + StringBuilder builder = new StringBuilder(); + while ((rowdata = TDengine.FetchRows(res)) != IntPtr.Zero) + { + queryRows++; + for (int fields = 0; fields < fieldCount; ++fields) + { + TDengineMeta meta = metas[fields]; + int offset = IntPtr.Size * fields; + IntPtr data = Marshal.ReadIntPtr(rowdata, offset); + + builder.Append("---"); + + if (data == IntPtr.Zero) + { + builder.Append("NULL"); + continue; + } + + switch ((TDengineDataType)meta.type) + { + case TDengineDataType.TSDB_DATA_TYPE_BOOL: + bool v1 = Marshal.ReadByte(data) == 0 ? false : true; + builder.Append(v1); + break; + case TDengineDataType.TSDB_DATA_TYPE_TINYINT: + byte v2 = Marshal.ReadByte(data); + builder.Append(v2); + break; + case TDengineDataType.TSDB_DATA_TYPE_SMALLINT: + short v3 = Marshal.ReadInt16(data); + builder.Append(v3); + break; + case TDengineDataType.TSDB_DATA_TYPE_INT: + int v4 = Marshal.ReadInt32(data); + builder.Append(v4); + break; + case TDengineDataType.TSDB_DATA_TYPE_BIGINT: + long v5 = Marshal.ReadInt64(data); + builder.Append(v5); + break; + case TDengineDataType.TSDB_DATA_TYPE_FLOAT: + float v6 = (float)Marshal.PtrToStructure(data, typeof(float)); + builder.Append(v6); + break; + case TDengineDataType.TSDB_DATA_TYPE_DOUBLE: + double v7 = (double)Marshal.PtrToStructure(data, typeof(double)); + builder.Append(v7); + break; + case TDengineDataType.TSDB_DATA_TYPE_BINARY: + string v8 = Marshal.PtrToStringAnsi(data); + builder.Append(v8); + break; + case TDengineDataType.TSDB_DATA_TYPE_TIMESTAMP: + long v9 = Marshal.ReadInt64(data); + builder.Append(v9); + break; + case TDengineDataType.TSDB_DATA_TYPE_NCHAR: + string v10 = Marshal.PtrToStringAnsi(data); + builder.Append(v10); + break; + } + } + builder.Append("---"); + + if (queryRows <= 10) + { + Console.WriteLine(builder.ToString()); + } + builder.Clear(); + } + + if (TDengine.ErrorNo(res) != 0) + { + Console.Write("Query is not complete, Error {0:G}", TDengine.ErrorNo(res), TDengine.Error(res)); + } + Console.WriteLine(""); + + TDengine.FreeResult(res); + + } + public void ExecuteQuery(string sql) + { + + DateTime dt1 = DateTime.Now; + + IntPtr res = TDengine.Query(conn, sql); + + DateTime dt2 = DateTime.Now; + TimeSpan span = dt2 - dt1; + + if ((res == IntPtr.Zero) || (TDengine.ErrorNo(res) != 0)) + { + Console.Write(sql.ToString() + " failure, "); + if (res != IntPtr.Zero) + { + Console.Write("reason: " + TDengine.Error(res)); + } + Console.WriteLine(""); + ExitProgram(); + } + + Console.WriteLine("[OK] time cost: " + span.ToString() + "ms, execute statement ====> " + sql.ToString()); + DisplayRes(res); + + } + + public void CloseConnection() + { + if (this.conn != IntPtr.Zero) + { + TDengine.Close(this.conn); + Console.WriteLine("connection closed."); + } + } + + static void ExitProgram() + { + System.Environment.Exit(0); + } + + public void cleanup() + { + Console.WriteLine("clean up..."); + System.Environment.Exit(0); + } + // method to get db precision + } +} diff --git a/tests/examples/JDBC/JDBCDemo/pom.xml b/tests/examples/JDBC/JDBCDemo/pom.xml index 8cf0356721f8ffd568e87fa4a77c86eb0f90a62b..5f0e35fa8f739453651ce3a7af092437531c00c6 100644 --- a/tests/examples/JDBC/JDBCDemo/pom.xml +++ b/tests/examples/JDBC/JDBCDemo/pom.xml @@ -17,7 +17,7 @@ com.taosdata.jdbc taos-jdbcdriver - 2.0.34 + 2.0.35 diff --git a/tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/BatchInsert.java b/tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/BatchInsert.java new file mode 100644 index 0000000000000000000000000000000000000000..a2566bd07e96ddd245c9b548a3192d0e4f343147 --- /dev/null +++ b/tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/BatchInsert.java @@ -0,0 +1,87 @@ +package com.taosdata.example; + +import java.sql.*; +import java.util.*; + +public class BatchInsert { + + private static final String host = "127.0.0.1"; + private static final String user = "root"; + private static final String password = "taosdata"; + + + private static final String dbname = "test"; + private static final String stbname = "stb"; + private static final int tables= 100; + private static final int rows = 500; + private static final long ts = 1604877767000l; + + private Connection conn; + + private void init() { + // final String url = "jdbc:TAOS://" + host + ":6030/?user=" + user + "&password=" + password; + final String url = "jdbc:TAOS-RS://" + host + ":6041/?user=" + user + "&password=" + password; + + // get connection + try { + Properties properties = new Properties(); + properties.setProperty("charset", "UTF-8"); + properties.setProperty("locale", "en_US.UTF-8"); + properties.setProperty("timezone", "UTC-8"); + System.out.println("get connection starting..."); + conn = DriverManager.getConnection(url, properties); + if (conn != null){ + System.out.println("[ OK ] Connection established."); + } + + Statement stmt = conn.createStatement(); + + stmt.execute("drop database if exists " + dbname); + stmt.execute("create database if not exists " + dbname); + stmt.execute("use " + dbname); + stmt.execute("create table " + dbname + "." + stbname + "(ts timestamp, col int) tags(id int)"); + + } catch (SQLException e) { + e.printStackTrace(); + } + } + + private String generateSql() { + StringBuilder sb = new StringBuilder(); + Random rand = new Random(); + sb.append("insert into "); + for (int i = 0; i < tables; i++) { + sb.append(dbname + ".tb" + i + " using " + dbname + "." + stbname + " tags(" + i + ") values"); + for (int j = 0; j < rows; j++) { + sb.append("("); + sb.append(ts + j); + sb.append(","); + sb.append(rand.nextInt(1000)); + sb.append(") "); + } + } + return sb.toString(); + } + + private void executeQuery(String sql) { + try (Statement stmt = conn.createStatement()) { + long start = System.currentTimeMillis(); + stmt.execute(sql); + long end = System.currentTimeMillis(); + + System.out.println("insert " + tables * rows + " records, cost " + (end - start)+ "ms"); + } catch (SQLException ex) { + ex.printStackTrace(); + } + } + + public static void main(String[] args) { + BatchInsert bi = new BatchInsert(); + + String sql = bi.generateSql(); + bi.init(); + bi.executeQuery(sql); + } + + +} diff --git a/tests/examples/nodejs/node-example-raw.js b/tests/examples/nodejs/node-example-raw.js index 058a50c4c3f0f7d44da4bdcc4fc54b81d7e1bc38..80d5cd1bdea23370f1ac03756541eaa96937a6d6 100644 --- a/tests/examples/nodejs/node-example-raw.js +++ b/tests/examples/nodejs/node-example-raw.js @@ -23,43 +23,31 @@ var conn = taos.connect({host:"127.0.0.1", user:"root", password:"taosdata", con // Initialize our TDengineCursor, which we use to interact with TDengine var c1 = conn.cursor(); +//execute the sql +function execute(sql){ + try { + c1.execute(sql); + } + catch(err) { + conn.close(); + throw err; + } +} + // c1.execute(query) will execute the query // Let's create a database named db -try { - c1.execute('create database if not exists db;'); -} -catch(err) { - conn.close(); - throw err; -} +execute('create database if not exists db;') // Now we will use database db -try { - c1.execute('use db;'); -} -catch (err) { - conn.close(); - throw err; -} +execute('use db;') + // Let's create a table called weather // which stores some weather data like humidity, AQI (air quality index), temperature, and some notes as text -try { - c1.execute('create table if not exists weather (ts timestamp, humidity smallint, aqi int, temperature float, notes binary(30));'); -} -catch (err) { - conn.close(); - throw err; -} +execute('create table if not exists weather (ts timestamp, humidity smallint, aqi int, temperature float, notes binary(30));'); // Let's get the description of the table weather -try { - c1.execute('describe db.weather'); -} -catch (err) { - conn.close(); - throw err; -} +execute('describe db.weather'); // To get results, we run the function c1.fetchall() // It only returns the query results as an array of result rows, but also stores the latest results in c1.data diff --git a/tests/pytest/fulltest.sh b/tests/pytest/fulltest.sh index 8af0c4642e7452cf835442b17e28d9d7c498bde0..c23f0614c43ddb5548a305f6761888e9b56b244c 100755 --- a/tests/pytest/fulltest.sh +++ b/tests/pytest/fulltest.sh @@ -279,6 +279,7 @@ python3 ./test.py -f query/queryCnameDisplay.py # python3 ./test.py -f query/long_where_query.py python3 test.py -f query/nestedQuery/queryWithSpread.py python3 ./test.py -f query/bug6586.py +# python3 ./test.py -f query/bug5903.py #stream python3 ./test.py -f stream/metric_1.py @@ -363,7 +364,7 @@ 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/queryTestCases.py +#python3 ./test.py -f functions/queryTestCases.py python3 ./test.py -f functions/function_stateWindow.py python3 ./test.py -f functions/function_derivative.py python3 ./test.py -f functions/function_irate.py diff --git a/tests/pytest/functions/function_ceil.py b/tests/pytest/functions/function_ceil.py index 9197b0eec45a2154c2345a5b2fc469e54b1e41f9..08769c7f7aeff422f955f18efa525b5250be0761 100644 --- a/tests/pytest/functions/function_ceil.py +++ b/tests/pytest/functions/function_ceil.py @@ -1289,6 +1289,34 @@ class TDTestCase: " fill(linear)" ] tdSql.prepare() + #need insert new data --data type is double or float and tests ceil floor round . + tdSql.execute("create table if not exists jsons7(ts timestamp, dataInt int, dataBool bool, datafloat float, datadouble double, dataStr nchar(50)) tags(jtag nchar(128))") + tdSql.execute("insert into jsons7_1 using jsons7 tags('{\"nv\":null,\"tea\":true,\"\":false,\" \":123,\"tea\":false}') values (now,2,'true',0.9,0.1,'123')") + tdSql.query("select * from jsons7") + tdSql.checkRows(1) + tdSql.execute("insert into jsons7_1 values (now+1s,3,'true',-4.8,-5.5,'123') ") + tdSql.execute("insert into jsons7_1 values (now+2s,4,'true',1.9998,2.00001,'123') ") + tdSql.execute("insert into jsons7_2 using jsons7 tags('{\"nv\":null,\"tea\":true,\"\":false,\"tag\":123,\"tea\":false}') values (now,5,'true',4.01,2.2,'123') ") + tdSql.execute("insert into jsons7_2 (ts,datadouble) values (now+3s,-0.9) ") + tdSql.execute("insert into jsons7_2 (ts,datadouble) values (now+4s,-2.9) ") + tdSql.execute("insert into jsons7_2 (ts,datafloat) values (now+1s,-0.9) ") + tdSql.execute("insert into jsons7_2 (ts,datafloat) values (now+2s,-1.9) ") + tdSql.query("select ts,ceil(dataint),ceil(datafloat),ceil(datadouble) from jsons7") + tdSql.checkRows(8) + tdSql.checkData(5, 1, None) + tdSql.checkData(6, 2, None) + tdSql.checkData(7, 3, -2) + tdSql.query("select ceil(dataint),ceil(datafloat),ceil(datadouble) from jsons7") + tdSql.checkRows(8) + tdSql.checkData(5, 1, -1) + tdSql.checkData(5, 2, None) + tdSql.checkData(7, 0, None) + tdSql.checkData(7, 2, -2) + tdSql.query("select ts,floor(dataint),floor(datafloat),floor(datadouble) from jsons7") + tdSql.query("select floor(dataint),floor(datafloat),floor(datadouble) from jsons7") + tdSql.query("select ts,round(dataint),round(datafloat),round(datadouble) from jsons7") + tdSql.query("select round(dataint),round(datafloat),round(datadouble) from jsons7") + tdSql.execute( "create stable super (ts timestamp, timestamp_col timestamp, int_col int, bigint_col bigint, float_col float,\ double_col double, binary_col binary(8), smallint_col smallint, tinyint_col tinyint, bool_col bool, nchar_col nchar(8), \ diff --git a/tests/pytest/functions/function_derivative.py b/tests/pytest/functions/function_derivative.py index e90a7671197ae9abe7c4463308b480849769f2fe..3b79726ed80c206338392cecb8f3d2adf4588e2a 100644 --- a/tests/pytest/functions/function_derivative.py +++ b/tests/pytest/functions/function_derivative.py @@ -68,9 +68,9 @@ class TDTestCase: tdSql.checkData(0, 0, "2018-09-17 09:00:10.000") tdSql.checkData(0, 1, "2018-09-17 09:00:10.000") tdSql.checkData(0, 3, "2018-09-17 09:00:10.000") - tdSql.checkData(1, 0, "2018-09-17 09:00:20.009") - tdSql.checkData(1, 1, "2018-09-17 09:00:20.009") - tdSql.checkData(1, 3, "2018-09-17 09:00:20.009") + tdSql.checkData(1, 0, "2018-09-17 09:00:20.000") + tdSql.checkData(1, 1, "2018-09-17 09:00:20.000") + tdSql.checkData(1, 3, "2018-09-17 09:00:20.000") tdSql.query("select ts from(select ts,derivative(col, 10s, 0) from stb group by tbname)") @@ -150,6 +150,7 @@ class TDTestCase: tdSql.error("select derivative(col, -106752999999999922222d, 0) from stb group by tbname"); #overflow error tdSql.error("select derivative(col, 10y, 0) from stb group by tbname") #TD-10399, DB error: syntax error near '10y, 0) from stb group by tbname;' tdSql.error("select derivative(col, -106752d, 0) from stb group by tbname") #TD-10398 overflow tips + tdSql.error("select derivative(col, 106751991168d, 0) from stb group by tbname") #TD-10398 overflow tips def run(self): tdSql.prepare() diff --git a/tests/pytest/functions/function_interp.py b/tests/pytest/functions/function_interp.py index ff7324d90b57904a8dea8ec5a0b391db839be72f..b3cf42fd275c07745109cf37eb9e1712b67ba7a9 100644 --- a/tests/pytest/functions/function_interp.py +++ b/tests/pytest/functions/function_interp.py @@ -12,137 +12,8387 @@ # -*- coding: utf-8 -*- import sys -from util.dnodes import * import taos +import numpy as np +import string +import os +import time from util.log import * from util.cases import * from util.sql import * -import numpy as np +from util.dnodes import * class TDTestCase: def init(self, conn, logSql): tdLog.debug("start to execute %s" % __file__) - tdSql.init(conn.cursor()) + tdSql.init(conn.cursor(), logSql) + + self.ts = 1630000000000 + self.num = 10 + + def function_introduction(self): + tdLog.info('select * from table|stable[group by tbname]|regular_table') + tdLog.info('select interp_select from table|stable[group by tbname]|regular_table') + tdLog.info('select interp_select from table|stable[group by tbname]|regular_table ORDER BY ts DESC') + tdLog.info('select interp_select from table|stable[group by tbname]|regular_table where ts> ts_min') + tdLog.info('select interp_select from table|stable[group by tbname]|regular_table where ts> ts_max') + tdLog.info('select interp_select from table|stable[group by tbname]|regular_table [range(ts_min,ts_max)]') + tdLog.info('select interp_select from table|stable[group by tbname]|regular_table [EVERY(s)]') + tdLog.info('select interp_select from table|stable[group by tbname]|regular_table [FILL(LINEAR,NEXT,PREV,VALUE,NULL)]') + tdLog.info('select interp_select from table|stable[group by tbname]|regular_table [range(ts_min,ts_max)] [FILL(LINEAR,NEXT,PREV,VALUE,NULL)]') + tdLog.info('select interp_select from table|stable[group by tbname]|regular_table [EVERY(s)] [FILL(LINEAR,NEXT,PREV,VALUE,NULL)]') + tdLog.info('select interp_select from table|stable[group by tbname]|regular_table [range(ts_min,ts_max)] [EVERY(s)] [FILL(LINEAR,NEXT,PREV,VALUE,NULL)]') + tdLog.info('select interp_select from table|stable[group by tbname]|regular_table [where condition] [range(ts_min,ts_max)] [EVERY(s)] [FILL(LINEAR,NEXT,PREV,VALUE,NULL)]') + tdLog.info('select * from (select interp_select from table|stable[group by tbname]|regular_table)') + tdLog.info('select interp_select from (select * from table|stable[group by tbname]|regular_table)') + tdLog.info('select * from (select interp_select from table|stable[group by tbname]|regular_table [where condition] [range(ts_min,ts_max)] [EVERY(s)] [FILL(LINEAR,NEXT,PREV,VALUE,NULL)])') + tdLog.info('select interp_select from (select * from table|stable[group by tbname]|regular_table [where condition] [range(ts_min,ts_max)] [EVERY(s)] [FILL(LINEAR,NEXT,PREV,VALUE,NULL)])') + tdLog.info('select * from (select interp_select from table|stable[group by tbname]|regular_table) [where condition] [range(ts_min,ts_max)] [EVERY(s)] [FILL(LINEAR,NEXT,PREV,VALUE,NULL)]') + tdLog.info('select interp_select from (select * from table|stable[group by tbname]|regular_table) [where condition] [range(ts_min,ts_max)] [EVERY(s)] [FILL(LINEAR,NEXT,PREV,VALUE,NULL)]') + tdLog.info('select * from (select interp_select from table|stable[group by tbname]|regular_table [where condition] [range(ts_min,ts_max)] [EVERY(s)] [FILL(LINEAR,NEXT,PREV,VALUE,NULL)]) a,\ + (select interp_select from table|stable[group by tbname]|regular_table [where condition] [range(ts_min,ts_max)] [EVERY(s)] [FILL(LINEAR,NEXT,PREV,VALUE,NULL)]) b where a.ts=b.ts') + tdLog.info('error select interp_select sql') + + def restartDnodes(self): + tdDnodes.stop(1) + tdDnodes.start(1) + + def dropandcreateDB(self): + tdSql.execute('''drop database if exists db ;''') + tdSql.execute('''create database db keep 36500;''') + tdSql.execute('''use db;''') + + tdSql.execute('''create stable stable_1 + (ts timestamp , q_int int , q_bigint bigint , q_smallint smallint , q_tinyint tinyint, q_float float , q_double double ) + tags(loc nchar(20));''') + tdSql.execute('''create table table_1 using stable_1 tags('table_1')''') + tdSql.execute('''create table table_2 using stable_1 tags('table_2')''') + tdSql.execute('''create table table_3 using stable_1 tags('table_3')''') + tdSql.execute('''create table regular_table_1 + (ts timestamp , q_int int , q_bigint bigint , q_smallint smallint , q_tinyint tinyint , q_float float , q_double double ) ;''') + tdSql.execute('''create table regular_table_2 + (ts timestamp , q_int int , q_bigint bigint , q_smallint smallint , q_tinyint tinyint , q_float float , q_double double ) ;''') + tdSql.execute('''create table regular_table_3 + (ts timestamp , q_int int , q_bigint bigint , q_smallint smallint , q_tinyint tinyint , q_float float , q_double double ) ;''') + + for i in range(self.num): + tdSql.execute('''insert into table_1 values(%d, %d, %d, %d, %d, %f, %f)''' + % (self.ts + i*10000, i, i, i, i, i, i)) + tdSql.execute('''insert into table_1 values(%d, %d, %d, %d, %d, %f, %f)''' + % (self.ts + i*3000, i, i, i, i, i, i)) + tdSql.execute('''insert into regular_table_1 values(%d, %d, %d, %d, %d, %f, %f)''' + % (self.ts + i*10000, i, i, i, i, i, i)) + tdSql.execute('''insert into regular_table_1 values(%d, %d, %d, %d, %d, %f, %f)''' + % (self.ts + i*3000 , i, i, i, i, i, i)) + + tdSql.execute('''insert into table_2 values(%d, %d, %d, %d, %d, %f, %f)''' + % (self.ts + i*10000, 2147483647-i, 9223372036854775807-i, 32767-i, 127-i, i, i)) + tdSql.execute('''insert into table_2 values(%d, %d, %d, %d, %d, %f, %f)''' + % (self.ts + i*3000, 2147483647-i, 9223372036854775807-i, 32767-i, 127-i, i, i)) + tdSql.execute('''insert into regular_table_2 values(%d, %d, %d, %d, %d, %f, %f)''' + % (self.ts + i*10000, 2147483647-i, 9223372036854775807-i, 32767-i, 127-i, i, i)) + tdSql.execute('''insert into regular_table_2 values(%d, %d, %d, %d, %d, %f, %f)''' + % (self.ts + i*3000 , 2147483647-i, 9223372036854775807-i, 32767-i, 127-i, i, i)) + + tdSql.execute('''insert into table_3 values(%d, %d, %d, %d, %d, %f, %f)''' + % (self.ts + i*10000, -2147483647+i, -9223372036854775807+i, -32767+i, -127+i, -i, -i)) + tdSql.execute('''insert into table_3 values(%d, %d, %d, %d, %d, %f, %f)''' + % (self.ts + i*3000, -2147483647+i, -9223372036854775807+i, -32767+i, -127+i, -i, -i)) + tdSql.execute('''insert into regular_table_3 values(%d, %d, %d, %d, %d, %f, %f)''' + % (self.ts + i*10000, -2147483647+i, -9223372036854775807+i, -32767+i, -127+i, -i, -i)) + tdSql.execute('''insert into regular_table_3 values(%d, %d, %d, %d, %d, %f, %f)''' + % (self.ts + i*3000 , -2147483647+i, -9223372036854775807+i, -32767+i, -127+i, -i, -i)) + + def dropandcreateDB_null(self): + tdSql.execute('''drop database if exists db ;''') + tdSql.execute('''create database db keep 36500;''') + tdSql.execute('''use db;''') + + tdSql.execute('''create stable stable_1 + (ts timestamp , q_int int , q_bigint bigint , q_smallint smallint , q_tinyint tinyint, q_float float , q_double double , + q_int_null int , q_bigint_null bigint , q_smallint_null smallint , q_tinyint_null tinyint, q_float_null float , q_double_null double , + q_bool bool , q_binary binary(20) , q_nchar nchar(20) , q_ts timestamp) + tags(loc nchar(20) , t_int int , t_bigint bigint , t_smallint smallint , t_tinyint tinyint, + t_bool bool , t_binary binary(20) , t_nchar nchar(20) ,t_float float , t_double double , t_ts timestamp);''') + tdSql.execute('''create stable stable_2 + (ts timestamp , q_int int , q_bigint bigint , q_smallint smallint , q_tinyint tinyint, q_float float , q_double double , + q_int_null int , q_bigint_null bigint , q_smallint_null smallint , q_tinyint_null tinyint, q_float_null float , q_double_null double ) + tags(loc nchar(20));''') + tdSql.execute('''create table table_1 using stable_1 tags('table_1', '0' , '0' , '0' , '0' , 0 , '0' , '0' , '0' , '0' ,'0')''') + tdSql.execute('''create table table_2 using stable_1 tags('table_2', '2147483647' , '9223372036854775807' , '32767' , '127' , 1 , + 'binary1' , 'nchar1' , '1' , '11' , \'1999-09-09 09:09:09.090\')''') + tdSql.execute('''create table table_3 using stable_1 tags('table_3', '-2147483647' , '-9223372036854775807' , '-32767' , '-127' , false , + 'binary2' , 'nchar2nchar2' , '-2.2' , '-22.22' , \'2099-09-09 09:09:09.090\')''') + tdSql.execute('''create table table_21 using stable_2 tags('table_21')''') + tdSql.execute('''create table regular_table_1 + (ts timestamp , q_int int , q_bigint bigint , q_smallint smallint , q_tinyint tinyint , q_float float , q_double double , + q_int_null int , q_bigint_null bigint , q_smallint_null smallint , q_tinyint_null tinyint, q_float_null float , q_double_null double , + q_bool bool , q_binary binary(20) , q_nchar nchar(20) , q_ts timestamp) ;''') + tdSql.execute('''create table regular_table_2 + (ts timestamp , q_int int , q_bigint bigint , q_smallint smallint , q_tinyint tinyint , q_float float , q_double double , + q_int_null int , q_bigint_null bigint , q_smallint_null smallint , q_tinyint_null tinyint, q_float_null float , q_double_null double , + q_bool bool , q_binary binary(20) , q_nchar nchar(20) , q_ts timestamp) ;''') + tdSql.execute('''create table regular_table_3 + (ts timestamp , q_int int , q_bigint bigint , q_smallint smallint , q_tinyint tinyint , q_float float , q_double double , + q_int_null int , q_bigint_null bigint , q_smallint_null smallint , q_tinyint_null tinyint, q_float_null float , q_double_null double , + q_bool bool , q_binary binary(20) , q_nchar nchar(20) , q_ts timestamp) ;''') + + for i in range(self.num): + tdSql.execute('''insert into table_1 (ts , q_int , q_bigint , q_smallint , q_tinyint , q_float , q_double) values(%d, %d, %d, %d, %d, %f, %f)''' + % (self.ts + i*10000, i, i, i, i, i, i)) + tdSql.execute('''insert into table_1 (ts , q_int , q_bigint , q_smallint , q_tinyint , q_float , q_double) values(%d, %d, %d, %d, %d, %f, %f)''' + % (self.ts + i*3000, i, i, i, i, i, i)) + tdSql.execute('''insert into regular_table_1 (ts , q_int , q_bigint , q_smallint , q_tinyint , q_float , q_double) values(%d, %d, %d, %d, %d, %f, %f)''' + % (self.ts + i*10000, i, i, i, i, i, i)) + tdSql.execute('''insert into regular_table_1 (ts , q_int , q_bigint , q_smallint , q_tinyint , q_float , q_double) values(%d, %d, %d, %d, %d, %f, %f)''' + % (self.ts + i*3000 , i, i, i, i, i, i)) + + tdSql.execute('''insert into table_21 (ts , q_int , q_bigint , q_smallint , q_tinyint , q_float , q_double) values(%d, %d, %d, %d, %d, %f, %f)''' + % (self.ts + i*10000, i, i, i, i, i, i)) + tdSql.execute('''insert into table_21 (ts , q_int , q_bigint , q_smallint , q_tinyint , q_float , q_double) values(%d, %d, %d, %d, %d, %f, %f)''' + % (self.ts + i*3000, i, i, i, i, i, i)) + + tdSql.execute('''insert into table_2 (ts , q_int , q_bigint , q_smallint , q_tinyint , q_float , q_double) values(%d, %d, %d, %d, %d, %f, %f)''' + % (self.ts + i*10000, 2147483647-i, 9223372036854775807-i, 32767-i, 127-i, i, i)) + tdSql.execute('''insert into table_2 (ts , q_int , q_bigint , q_smallint , q_tinyint , q_float , q_double) values(%d, %d, %d, %d, %d, %f, %f)''' + % (self.ts + i*3000, 2147483647-i, 9223372036854775807-i, 32767-i, 127-i, i, i)) + tdSql.execute('''insert into regular_table_2 (ts , q_int , q_bigint , q_smallint , q_tinyint , q_float , q_double) values(%d, %d, %d, %d, %d, %f, %f)''' + % (self.ts + i*10000, 2147483647-i, 9223372036854775807-i, 32767-i, 127-i, i, i)) + tdSql.execute('''insert into regular_table_2 (ts , q_int , q_bigint , q_smallint , q_tinyint , q_float , q_double) values(%d, %d, %d, %d, %d, %f, %f)''' + % (self.ts + i*3000 , 2147483647-i, 9223372036854775807-i, 32767-i, 127-i, i, i)) + + tdSql.execute('''insert into table_3 (ts , q_int , q_bigint , q_smallint , q_tinyint , q_float , q_double) values(%d, %d, %d, %d, %d, %f, %f)''' + % (self.ts + i*10000, -2147483647+i, -9223372036854775807+i, -32767+i, -127+i, -i, -i)) + tdSql.execute('''insert into table_3 (ts , q_int , q_bigint , q_smallint , q_tinyint , q_float , q_double) values(%d, %d, %d, %d, %d, %f, %f)''' + % (self.ts + i*3000, -2147483647+i, -9223372036854775807+i, -32767+i, -127+i, -i, -i)) + tdSql.execute('''insert into regular_table_3 (ts , q_int , q_bigint , q_smallint , q_tinyint , q_float , q_double) values(%d, %d, %d, %d, %d, %f, %f)''' + % (self.ts + i*10000, -2147483647+i, -9223372036854775807+i, -32767+i, -127+i, -i, -i)) + tdSql.execute('''insert into regular_table_3 (ts , q_int , q_bigint , q_smallint , q_tinyint , q_float , q_double) values(%d, %d, %d, %d, %d, %f, %f)''' + % (self.ts + i*3000 , -2147483647+i, -9223372036854775807+i, -32767+i, -127+i, -i, -i)) + + def result_0(self,sql): + tdLog.info(sql) + tdSql.query(sql) + tdSql.checkRows(0) + dcDB = self.dropandcreateDB_null() + + def regular1_checkall_0_base(self,sql): + tdLog.info(sql) + tdSql.query(sql) + tdSql.checkData(0,0,'2021-08-27 01:46:40.000') + tdSql.checkData(0,1,0) + tdSql.checkData(0,2,0) + tdSql.checkData(0,3,0) + tdSql.checkData(0,4,0) + tdSql.checkData(0,5,0) + tdSql.checkData(0,6,0) + tdSql.checkData(0,7,'None') + tdSql.checkData(0,8,'None') + tdSql.checkData(0,9,'None') + tdSql.checkData(0,10,'None') + tdSql.checkData(0,11,'None') + tdSql.checkData(0,12,'None') + + def regular1_checkall_0(self,sql): + tdLog.info(sql) + tdSql.query(sql) + tdSql.checkData(0,0,'2021-08-27 01:46:40.000') + tdSql.checkData(0,1,0) + tdSql.checkData(0,2,0) + tdSql.checkData(0,3,0) + tdSql.checkData(0,4,0) + tdSql.checkData(0,5,0) + tdSql.checkData(0,6,0) + tdSql.checkData(0,7,'None') + tdSql.checkData(0,8,'None') + tdSql.checkData(0,9,'None') + tdSql.checkData(0,10,'None') + tdSql.checkData(0,11,'None') + tdSql.checkData(0,12,'None') + tdSql.checkData(0,13,0) + tdSql.checkData(0,14,0) + tdSql.checkData(0,15,0) + tdSql.checkData(0,16,0) + tdSql.checkData(0,17,0) + tdSql.checkData(0,18,0) + tdSql.checkData(0,19,'None') + tdSql.checkData(0,20,'None') + tdSql.checkData(0,21,'None') + tdSql.checkData(0,22,'None') + tdSql.checkData(0,23,'None') + tdSql.checkData(0,24,'None') + + def regular1_checkall_0_LINEAR(self,sql): + tdLog.info(sql) + tdSql.query(sql) + tdSql.checkData(0,0,'2021-08-27 01:46:41.500') + tdSql.checkData(0,1,0) + tdSql.checkData(0,2,0) + tdSql.checkData(0,3,0) + tdSql.checkData(0,4,0) + tdSql.checkData(0,5,0.5) + tdSql.checkData(0,6,0.5) + tdSql.checkData(0,7,'None') + tdSql.checkData(0,8,'None') + tdSql.checkData(0,9,'None') + tdSql.checkData(0,10,'None') + tdSql.checkData(0,11,'None') + tdSql.checkData(0,12,'None') + tdSql.checkData(0,13,0) + tdSql.checkData(0,14,0) + tdSql.checkData(0,15,0) + tdSql.checkData(0,16,0) + tdSql.checkData(0,17,0.5) + tdSql.checkData(0,18,0.5) + tdSql.checkData(0,19,'None') + tdSql.checkData(0,20,'None') + tdSql.checkData(0,21,'None') + tdSql.checkData(0,22,'None') + tdSql.checkData(0,23,'None') + tdSql.checkData(0,24,'None') + + def regular1_checkall_0_NEXT(self,sql): + tdLog.info(sql) + tdSql.query(sql) + tdSql.checkData(0,0,'2021-08-27 01:46:41.500') + tdSql.checkData(0,1,1) + tdSql.checkData(0,2,1) + tdSql.checkData(0,3,1) + tdSql.checkData(0,4,1) + tdSql.checkData(0,5,1) + tdSql.checkData(0,6,1) + tdSql.checkData(0,7,'None') + tdSql.checkData(0,8,'None') + tdSql.checkData(0,9,'None') + tdSql.checkData(0,10,'None') + tdSql.checkData(0,11,'None') + tdSql.checkData(0,12,'None') + tdSql.checkData(0,13,1) + tdSql.checkData(0,14,1) + tdSql.checkData(0,15,1) + tdSql.checkData(0,16,1) + tdSql.checkData(0,17,1) + tdSql.checkData(0,18,1) + tdSql.checkData(0,19,'None') + tdSql.checkData(0,20,'None') + tdSql.checkData(0,21,'None') + tdSql.checkData(0,22,'None') + tdSql.checkData(0,23,'None') + tdSql.checkData(0,24,'None') + + def regular1_checkall_0_VALUE100(self,sql): + tdLog.info(sql) + tdSql.query(sql) + tdSql.checkData(0,0,'01:46:30.000') + tdSql.checkData(0,1,100) + tdSql.checkData(0,2,100) + tdSql.checkData(0,3,100) + tdSql.checkData(0,4,100) + tdSql.checkData(0,5,100) + tdSql.checkData(0,6,100) + # all data interp 100 + tdSql.checkData(0,7,100) + tdSql.checkData(0,8,100) + tdSql.checkData(0,9,100) + tdSql.checkData(0,10,100) + tdSql.checkData(0,11,100) + tdSql.checkData(0,12,100) + + tdSql.checkData(0,13,100) + tdSql.checkData(0,14,100) + tdSql.checkData(0,15,100) + tdSql.checkData(0,16,100) + tdSql.checkData(0,17,100) + tdSql.checkData(0,17,100) + tdSql.checkData(0,19,100) + tdSql.checkData(0,20,100) + tdSql.checkData(0,21,100) + tdSql.checkData(0,22,100) + tdSql.checkData(0,23,100) + tdSql.checkData(0,24,100) + + def regular1_checkall_0_NULL(self,sql): + tdLog.info(sql) + tdSql.query(sql) + tdSql.checkData(0,0,'01:46:30.000') + tdSql.checkData(0,1,None) + tdSql.checkData(0,2,None) + tdSql.checkData(0,3,None) + tdSql.checkData(0,4,None) + tdSql.checkData(0,5,None) + tdSql.checkData(0,6,None) + tdSql.checkData(0,7,'None') + tdSql.checkData(0,8,'None') + tdSql.checkData(0,9,'None') + tdSql.checkData(0,10,'None') + tdSql.checkData(0,11,'None') + tdSql.checkData(0,12,'None') + tdSql.checkData(0,13,None) + tdSql.checkData(0,14,None) + tdSql.checkData(0,15,None) + tdSql.checkData(0,16,None) + tdSql.checkData(0,17,None) + tdSql.checkData(0,18,None) + tdSql.checkData(0,19,'None') + tdSql.checkData(0,20,'None') + tdSql.checkData(0,21,'None') + tdSql.checkData(0,22,'None') + tdSql.checkData(0,23,'None') + tdSql.checkData(0,24,'None') + + def regular2_checkall_0(self,sql): + tdLog.info(sql) + tdSql.query(sql) + tdSql.checkData(0,0,'2021-08-27 01:46:40.000') + tdSql.checkData(0,1,2147483647) + tdSql.checkData(0,2,9223372036854775807) + tdSql.checkData(0,3,32767) + tdSql.checkData(0,4,127) + tdSql.checkData(0,5,0) + tdSql.checkData(0,6,0) + tdSql.checkData(0,7,'None') + tdSql.checkData(0,8,'None') + tdSql.checkData(0,9,'None') + tdSql.checkData(0,10,'None') + tdSql.checkData(0,11,'None') + tdSql.checkData(0,12,'None') + tdSql.checkData(0,13,2147483647) + tdSql.checkData(0,14,9223372036854775807) + tdSql.checkData(0,15,32767) + tdSql.checkData(0,16,127) + tdSql.checkData(0,17,0) + tdSql.checkData(0,18,0) + tdSql.checkData(0,19,'None') + tdSql.checkData(0,20,'None') + tdSql.checkData(0,21,'None') + tdSql.checkData(0,22,'None') + tdSql.checkData(0,23,'None') + tdSql.checkData(0,24,'None') + + def regular2_checkall_0_LINEAR(self,sql): + tdLog.info(sql) + tdSql.query(sql) + #print(tdSql.queryResult) + tdSql.checkData(0,0,'2021-08-27 01:46:41.500') + tdSql.checkData(0,1,2147483646) + tdSql.checkData(0,2,9223372036854775806) + tdSql.checkData(0,3,32766) + tdSql.checkData(0,4,126) + tdSql.checkData(0,5,0.5) + tdSql.checkData(0,6,0.5) + tdSql.checkData(0,7,'None') + tdSql.checkData(0,8,'None') + tdSql.checkData(0,9,'None') + tdSql.checkData(0,10,'None') + tdSql.checkData(0,11,'None') + tdSql.checkData(0,12,'None') + tdSql.checkData(0,13,2147483646) + tdSql.checkData(0,14,9223372036854775806) + tdSql.checkData(0,15,32766) + tdSql.checkData(0,16,126) + tdSql.checkData(0,17,0.5) + tdSql.checkData(0,18,0.5) + tdSql.checkData(0,19,'None') + tdSql.checkData(0,20,'None') + tdSql.checkData(0,21,'None') + tdSql.checkData(0,22,'None') + tdSql.checkData(0,23,'None') + tdSql.checkData(0,24,'None') + + def regular2_checkall_0_NEXT(self,sql): + tdLog.info(sql) + tdSql.query(sql) + #print(tdSql.queryResult) + tdSql.checkData(0,0,'2021-08-27 01:46:41.500') + tdSql.checkData(0,1,2147483646) + tdSql.checkData(0,2,9223372036854775806) + tdSql.checkData(0,3,32766) + tdSql.checkData(0,4,126) + tdSql.checkData(0,5,1) + tdSql.checkData(0,6,1) + tdSql.checkData(0,7,'None') + tdSql.checkData(0,8,'None') + tdSql.checkData(0,9,'None') + tdSql.checkData(0,10,'None') + tdSql.checkData(0,11,'None') + tdSql.checkData(0,12,'None') + tdSql.checkData(0,13,2147483646) + tdSql.checkData(0,14,9223372036854775806) + tdSql.checkData(0,15,32766) + tdSql.checkData(0,16,126) + tdSql.checkData(0,17,1) + tdSql.checkData(0,18,1) + tdSql.checkData(0,19,'None') + tdSql.checkData(0,20,'None') + tdSql.checkData(0,21,'None') + tdSql.checkData(0,22,'None') + tdSql.checkData(0,23,'None') + tdSql.checkData(0,24,'None') + + def regular3_checkall_0(self,sql): + tdLog.info(sql) + tdSql.query(sql) + tdSql.checkData(0,0,'2021-08-27 01:46:40.000') + tdSql.checkData(0,1,-2147483647) + tdSql.checkData(0,2,-9223372036854775807) + tdSql.checkData(0,3,-32767) + tdSql.checkData(0,4,-127) + tdSql.checkData(0,5,-0) + tdSql.checkData(0,6,-0) + tdSql.checkData(0,7,'None') + tdSql.checkData(0,8,'None') + tdSql.checkData(0,9,'None') + tdSql.checkData(0,10,'None') + tdSql.checkData(0,11,'None') + tdSql.checkData(0,12,'None') + tdSql.checkData(0,13,-2147483647) + tdSql.checkData(0,14,-9223372036854775807) + tdSql.checkData(0,15,-32767) + tdSql.checkData(0,16,-127) + tdSql.checkData(0,17,-0) + tdSql.checkData(0,18,-0) + tdSql.checkData(0,19,'None') + tdSql.checkData(0,20,'None') + tdSql.checkData(0,21,'None') + tdSql.checkData(0,22,'None') + tdSql.checkData(0,23,'None') + tdSql.checkData(0,24,'None') + + def regular3_checkall_0_LINEAR(self,sql): + tdLog.info(sql) + tdSql.query(sql) + #print(tdSql.queryResult) + tdSql.checkData(0,0,'2021-08-27 01:46:41.500') + tdSql.checkData(0,1,-2147483646) + tdSql.checkData(0,2,-9223372036854775806) + tdSql.checkData(0,3,-32766) + tdSql.checkData(0,4,-126) + tdSql.checkData(0,5,-0.5) + tdSql.checkData(0,6,-0.5) + tdSql.checkData(0,7,'None') + tdSql.checkData(0,8,'None') + tdSql.checkData(0,9,'None') + tdSql.checkData(0,10,'None') + tdSql.checkData(0,11,'None') + tdSql.checkData(0,12,'None') + tdSql.checkData(0,13,-2147483646) + tdSql.checkData(0,14,-9223372036854775806) + tdSql.checkData(0,15,-32766) + tdSql.checkData(0,16,-126) + tdSql.checkData(0,17,-0.5) + tdSql.checkData(0,18,-0.5) + tdSql.checkData(0,19,'None') + tdSql.checkData(0,20,'None') + tdSql.checkData(0,21,'None') + tdSql.checkData(0,22,'None') + tdSql.checkData(0,23,'None') + tdSql.checkData(0,24,'None') + + def regular3_checkall_0_NEXT(self,sql): + tdLog.info(sql) + tdSql.query(sql) + #print(tdSql.queryResult) + tdSql.checkData(0,0,'2021-08-27 01:46:41.500') + tdSql.checkData(0,1,-2147483646) + tdSql.checkData(0,2,-9223372036854775806) + tdSql.checkData(0,3,-32766) + tdSql.checkData(0,4,-126) + tdSql.checkData(0,5,-1) + tdSql.checkData(0,6,-1) + tdSql.checkData(0,7,'None') + tdSql.checkData(0,8,'None') + tdSql.checkData(0,9,'None') + tdSql.checkData(0,10,'None') + tdSql.checkData(0,11,'None') + tdSql.checkData(0,12,'None') + tdSql.checkData(0,13,-2147483646) + tdSql.checkData(0,14,-9223372036854775806) + tdSql.checkData(0,15,-32766) + tdSql.checkData(0,16,-126) + tdSql.checkData(0,17,-1) + tdSql.checkData(0,18,-1) + tdSql.checkData(0,19,'None') + tdSql.checkData(0,20,'None') + tdSql.checkData(0,21,'None') + tdSql.checkData(0,22,'None') + tdSql.checkData(0,23,'None') + tdSql.checkData(0,24,'None') + + def regular1_checkall_9(self,sql): + tdLog.info(sql) + tdSql.query(sql) + tdSql.checkData(0,0,'2021-08-27 01:48:10.000') + tdSql.checkData(0,1,9) + tdSql.checkData(0,2,9) + tdSql.checkData(0,3,9) + tdSql.checkData(0,4,9) + tdSql.checkData(0,5,9) + tdSql.checkData(0,6,9) + tdSql.checkData(0,7,'None') + tdSql.checkData(0,8,'None') + tdSql.checkData(0,9,'None') + tdSql.checkData(0,10,'None') + tdSql.checkData(0,11,'None') + tdSql.checkData(0,12,'None') + tdSql.checkData(0,13,9) + tdSql.checkData(0,14,9) + tdSql.checkData(0,15,9) + tdSql.checkData(0,16,9) + tdSql.checkData(0,17,9) + tdSql.checkData(0,18,9) + tdSql.checkData(0,19,'None') + tdSql.checkData(0,20,'None') + tdSql.checkData(0,21,'None') + tdSql.checkData(0,22,'None') + tdSql.checkData(0,23,'None') + tdSql.checkData(0,24,'None') + + def regular2_checkall_9(self,sql): + tdLog.info(sql) + tdSql.query(sql) + tdSql.checkData(0,0,'2021-08-27 01:48:10.000') + tdSql.checkData(0,1,2147483638) + tdSql.checkData(0,2,9223372036854775798) + tdSql.checkData(0,3,32758) + tdSql.checkData(0,4,118) + tdSql.checkData(0,5,9) + tdSql.checkData(0,6,9) + tdSql.checkData(0,7,'None') + tdSql.checkData(0,8,'None') + tdSql.checkData(0,9,'None') + tdSql.checkData(0,10,'None') + tdSql.checkData(0,11,'None') + tdSql.checkData(0,12,'None') + tdSql.checkData(0,13,2147483638) + tdSql.checkData(0,14,9223372036854775798) + tdSql.checkData(0,15,32758) + tdSql.checkData(0,16,118) + tdSql.checkData(0,17,9) + tdSql.checkData(0,18,9) + tdSql.checkData(0,19,'None') + tdSql.checkData(0,20,'None') + tdSql.checkData(0,21,'None') + tdSql.checkData(0,22,'None') + tdSql.checkData(0,23,'None') + tdSql.checkData(0,24,'None') + + def regular3_checkall_9(self,sql): + tdLog.info(sql) + tdSql.query(sql) + tdSql.checkData(0,0,'2021-08-27 01:48:10.000') + tdSql.checkData(0,1,-2147483638) + tdSql.checkData(0,2,-9223372036854775798) + tdSql.checkData(0,3,-32758) + tdSql.checkData(0,4,-118) + tdSql.checkData(0,5,-9) + tdSql.checkData(0,6,-9) + tdSql.checkData(0,7,'None') + tdSql.checkData(0,8,'None') + tdSql.checkData(0,9,'None') + tdSql.checkData(0,10,'None') + tdSql.checkData(0,11,'None') + tdSql.checkData(0,12,'None') + tdSql.checkData(0,13,-2147483638) + tdSql.checkData(0,14,-9223372036854775798) + tdSql.checkData(0,15,-32758) + tdSql.checkData(0,16,-118) + tdSql.checkData(0,17,-9) + tdSql.checkData(0,18,-9) + tdSql.checkData(0,19,'None') + tdSql.checkData(0,20,'None') + tdSql.checkData(0,21,'None') + tdSql.checkData(0,22,'None') + tdSql.checkData(0,23,'None') + tdSql.checkData(0,24,'None') + + def regular1_checkall_20_base(self,sql): + tdLog.info(sql) + tdSql.query(sql) + tdSql.checkData(18,0,'2021-08-27 01:48:10.000') + tdSql.checkData(18,1,9) + tdSql.checkData(18,2,9) + tdSql.checkData(18,3,9) + tdSql.checkData(18,4,9) + tdSql.checkData(18,5,9) + tdSql.checkData(18,6,9) + tdSql.checkData(18,7,'None') + tdSql.checkData(18,8,'None') + tdSql.checkData(18,9,'None') + tdSql.checkData(18,10,'None') + tdSql.checkData(18,11,'None') + tdSql.checkData(18,12,'None') + + def regular1_checkall_20(self,sql): + tdLog.info(sql) + tdSql.query(sql) + tdSql.checkData(18,0,'2021-08-27 01:48:10.000') + tdSql.checkData(18,1,9) + tdSql.checkData(18,2,9) + tdSql.checkData(18,3,9) + tdSql.checkData(18,4,9) + tdSql.checkData(18,5,9) + tdSql.checkData(18,6,9) + tdSql.checkData(18,7,'None') + tdSql.checkData(18,8,'None') + tdSql.checkData(18,9,'None') + tdSql.checkData(18,10,'None') + tdSql.checkData(18,11,'None') + tdSql.checkData(18,12,'None') + tdSql.checkData(18,13,9) + tdSql.checkData(18,14,9) + tdSql.checkData(18,15,9) + tdSql.checkData(18,16,9) + tdSql.checkData(18,17,9) + tdSql.checkData(18,18,9) + tdSql.checkData(18,19,'None') + tdSql.checkData(18,20,'None') + tdSql.checkData(18,21,'None') + tdSql.checkData(18,22,'None') + tdSql.checkData(18,23,'None') + tdSql.checkData(18,24,'None') + + def regular2_checkall_20(self,sql): + tdLog.info(sql) + tdSql.query(sql) + tdSql.checkData(18,0,'2021-08-27 01:48:10.000') + tdSql.checkData(18,1,2147483638) + tdSql.checkData(18,2,9223372036854775798) + tdSql.checkData(18,3,32758) + tdSql.checkData(18,4,118) + tdSql.checkData(18,5,9) + tdSql.checkData(18,6,9) + tdSql.checkData(18,7,'None') + tdSql.checkData(18,8,'None') + tdSql.checkData(18,9,'None') + tdSql.checkData(18,10,'None') + tdSql.checkData(18,11,'None') + tdSql.checkData(18,12,'None') + tdSql.checkData(18,13,2147483638) + tdSql.checkData(18,14,9223372036854775798) + tdSql.checkData(18,15,32758) + tdSql.checkData(18,16,118) + tdSql.checkData(18,17,9) + tdSql.checkData(18,18,9) + tdSql.checkData(18,19,'None') + tdSql.checkData(18,20,'None') + tdSql.checkData(18,21,'None') + tdSql.checkData(18,22,'None') + tdSql.checkData(18,23,'None') + tdSql.checkData(18,24,'None') + + def regular3_checkall_20(self,sql): + tdLog.info(sql) + tdSql.query(sql) + tdSql.checkData(18,0,'2021-08-27 01:48:10.000') + tdSql.checkData(18,1,-2147483638) + tdSql.checkData(18,2,-9223372036854775798) + tdSql.checkData(18,3,-32758) + tdSql.checkData(18,4,-118) + tdSql.checkData(18,5,-9) + tdSql.checkData(18,6,-9) + tdSql.checkData(18,7,'None') + tdSql.checkData(18,8,'None') + tdSql.checkData(18,9,'None') + tdSql.checkData(18,10,'None') + tdSql.checkData(18,11,'None') + tdSql.checkData(18,12,'None') + tdSql.checkData(18,13,-2147483638) + tdSql.checkData(18,14,-9223372036854775798) + tdSql.checkData(18,15,-32758) + tdSql.checkData(18,16,-118) + tdSql.checkData(18,17,-9) + tdSql.checkData(18,18,-9) + tdSql.checkData(18,19,'None') + tdSql.checkData(18,20,'None') + tdSql.checkData(18,21,'None') + tdSql.checkData(18,22,'None') + tdSql.checkData(18,23,'None') + tdSql.checkData(18,24,'None') + + def stable1_checkall_0(self,sql): + self.regular1_checkall_0(sql) - self.rowNum = 10 - self.ts = 1537100000000 def run(self): tdSql.prepare() - tdSql.execute("create table ap1 (ts timestamp, pav float)") - tdSql.execute("create table ap2 (ts timestamp, pav float) tags (t1 float)") - tdSql.execute("create table ap2_sub1 using ap2 tags (2.90799)") - tdSql.execute("create table ap2_sub2 using ap2 tags (2.90799)") - tdSql.execute("create table ap3 (ts timestamp, pav float) tags (t1 float)") - tdSql.execute("create table ap3_sub1 using ap3 tags (2.90799)") - for tb_name in ["ap1", "ap2_sub1", "ap3_sub1"]: - tdSql.execute(f"insert into {tb_name} values ('2021-07-25 02:19:54.119', 2.90799)") - tdSql.execute(f"insert into {tb_name} values ('2021-07-25 02:19:54.317', 3.07399)") - tdSql.execute(f"insert into {tb_name} values ('2021-07-25 02:19:54.517', 0.58117)") - tdSql.execute(f"insert into {tb_name} values ('2021-07-25 02:19:54.717', 0.16150)") - tdSql.execute(f"insert into {tb_name} values ('2021-07-25 02:19:54.918', 1.47885)") - tdSql.execute(f"insert into {tb_name} values ('2021-07-25 02:19:56.569', 1.76472)") - tdSql.execute(f"insert into {tb_name} values ('2021-07-25 02:19:57.381', 2.13722)") - tdSql.execute(f"insert into {tb_name} values ('2021-07-25 02:19:57.574', 4.10256)") - tdSql.execute(f"insert into {tb_name} values ('2021-07-25 02:19:57.776', 3.55345)") - tdSql.execute(f"insert into {tb_name} values ('2021-07-25 02:19:57.976', 1.46624)") - tdSql.execute(f"insert into {tb_name} values ('2021-07-25 02:19:58.187', 0.17943)") - tdSql.execute(f"insert into {tb_name} values ('2021-07-25 02:19:58.372', 2.04101)") - tdSql.execute(f"insert into {tb_name} values ('2021-07-25 02:19:58.573', 3.20924)") - tdSql.execute(f"insert into {tb_name} values ('2021-07-25 02:19:58.768', 1.71807)") - tdSql.execute(f"insert into {tb_name} values ('2021-07-25 02:19:58.964', 4.60900)") - tdSql.execute(f"insert into {tb_name} values ('2021-07-25 02:19:59.155', 4.33907)") - tdSql.execute(f"insert into {tb_name} values ('2021-07-25 02:19:59.359', 0.76940)") - tdSql.execute(f"insert into {tb_name} values ('2021-07-25 02:19:59.553', 0.06458)") - tdSql.execute(f"insert into {tb_name} values ('2021-07-25 02:19:59.742', 4.59857)") - tdSql.execute(f"insert into {tb_name} values ('2021-07-25 02:19:59.938', 1.55081)") - - tdSql.query("select interp(pav) from ap1 where ts = '2021-07-25 02:19:54' FILL (PREV)") - tdSql.checkRows(0) - tdSql.query("select interp(pav) from ap1 where ts = '2021-07-25 02:19:54' FILL (NEXT)") - tdSql.checkRows(0) - tdSql.query("select interp(pav) from ap1 where ts = '2021-07-25 02:19:54' FILL (LINEAR)") - tdSql.checkRows(0) - # check None - tdSql.query("select interp(pav) from ap1 where ts> '2021-07-25 02:19:54' and ts<'2021-07-25 02:20:00' every(1000a) FILL (None)") - tdSql.checkRows(0) - # check NULL - tdSql.query("select interp(pav) from ap1 where ts> '2021-07-25 02:19:54' and ts<'2021-07-25 02:20:00' every(1000a) FILL (NULL)") - tdSql.checkRows(6) - for i in range(5): - tdSql.checkData(i,1,None) - # checkout VALUE - tdSql.query("select interp(pav) from ap1 where ts> '2021-07-25 02:19:54' and ts<'2021-07-25 02:20:00' every(1000a) FILL (VALUE, 1)") - tdSql.checkRows(6) - for i in range(5): - tdSql.checkData(i,1,1.00000) - # check tag group by - tdSql.query("select interp(pav) from ap2 where ts>= '2021-07-25 02:19:54' and ts<'2021-07-25 02:20:00' every(1000a) FILL (VALUE,1) group by t1;") - for i in range(5): - tdSql.checkData(i,1,1.00000) - tdSql.checkData(i,2,2.90799) - # check multi ts lines - tdSql.query("select z1.ts,z1.val1,z2.val2 from (select interp(pav) val1 from ap2 where ts> '2021-07-25 02:19:54' and ts<'2021-07-25 02:20:00' every(1000a) FILL (value,1)) z1,(select interp(pav) val2 from ap3 where ts> '2021-07-25 02:19:54' and ts<'2021-07-25 02:20:00' every(1000a) FILL (value,2)) z2 where z1.ts=z2.ts ;") - for i in range(5): - tdSql.checkData(i,1,1.00000) - tdSql.checkData(i,2,2.00000) - tdSql.query("select interp(pav) from ap1 where ts> '2021-07-25 02:19:54' and ts<'2021-07-25 02:20:00' every(1000a) FILL (LINEAR)") - tdSql.checkRows(6) - tdSql.query("select interp(pav) from ap1 where ts>= '2021-07-25 02:19:54' and ts<'2021-07-25 02:20:00' every(1000a) FILL (NEXT)") - tdSql.checkRows(6) - tdSql.checkData(0,1,2.90799) - tdSql.query("select interp(pav) from ap1 where ts> '2021-07-25 02:19:54' and ts <= '2021-07-25 02:20:00' every(1000a) FILL (PREV)") + os.system("rm -rf functions/function_interp.py.sql") + startTime = time.time() + dcDB = self.dropandcreateDB_null() + + print("==============step1, regualr table ==============") + + interp_select = 'interp(q_int),interp(q_bigint),interp(q_smallint),interp(q_tinyint),interp(q_float),interp(q_double),\ + interp(q_int_null),interp(q_bigint_null),interp(q_smallint_null),interp(q_tinyint_null),interp(q_float_null),interp(q_double_null),\ + interp(q_int,q_bigint,q_smallint,q_tinyint,q_float,q_double),interp(q_int_null,q_bigint_null,q_smallint_null,q_tinyint_null,q_float_null,q_double_null)' + + sql = "select * from regular_table_1 ;" + datacheck = self.regular1_checkall_0_base(sql) + tdSql.checkRows(19) + datacheck = self.regular1_checkall_20_base(sql) + + sql = "select %s from regular_table_1 ;" %interp_select + datacheck = self.regular1_checkall_0(sql) + sql = "select %s from regular_table_2 ;" %interp_select + datacheck = self.regular2_checkall_0(sql) + sql = "select %s from regular_table_3 ;" %interp_select + datacheck = self.regular3_checkall_0(sql) + + sql = "select %s from regular_table_1 ORDER BY ts DESC;" %interp_select + datacheck = self.regular1_checkall_0(sql) + sql = "select %s from regular_table_2 ORDER BY ts DESC;" %interp_select + datacheck = self.regular2_checkall_0(sql) + sql = "select %s from regular_table_3 ORDER BY ts DESC;" %interp_select + datacheck = self.regular3_checkall_0(sql) + + sql = "select %s from regular_table_1 where " %interp_select + sql += "ts > %s ;" % (self.ts - 10) + datacheck = self.regular1_checkall_0(sql) + sql = "select %s from regular_table_2 where " %interp_select + sql += "ts > %s ;" % (self.ts - 10) + datacheck = self.regular2_checkall_0(sql) + sql = "select %s from regular_table_3 where " %interp_select + sql += "ts > %s ;" % (self.ts - 10) + datacheck = self.regular3_checkall_0(sql) + + sql = "select %s from regular_table_1 where " %interp_select + sql += "ts > %s ;" % (self.ts + 85000) + datacheck = self.regular1_checkall_9(sql) + sql = "select %s from regular_table_2 where " %interp_select + sql += "ts > %s ;" % (self.ts + 85000) + datacheck = self.regular2_checkall_9(sql) + sql = "select %s from regular_table_3 where " %interp_select + sql += "ts > %s ;" % (self.ts + 85000) + datacheck = self.regular3_checkall_9(sql) + + # range + sql = "select %s from regular_table_1 " % interp_select + sql += "range('%s' , '%s');" % (self.ts - 10000 , self.ts + 100000) + datacheck = self.result_0(sql) + sql = "select %s from regular_table_2 " % interp_select + sql += "range('%s' , '%s');" % (self.ts - 10000 , self.ts + 100000) + datacheck = self.result_0(sql) + sql = "select %s from regular_table_3 " % interp_select + sql += "range('%s' , '%s');" % (self.ts - 10000 , self.ts + 100000) + datacheck = self.result_0(sql) + + sql = "select %s from regular_table_1 " % interp_select + sql += "range('%s' , '%s');" % (self.ts - 10000 , self.ts - 9900) + datacheck = self.result_0(sql) + sql = "select %s from regular_table_2 " %interp_select + sql += "range('%s' , '%s');" % (self.ts - 10000 , self.ts - 9900) + datacheck = self.result_0(sql) + sql = "select %s from regular_table_3 " %interp_select + sql += "range('%s' , '%s');" % (self.ts - 10000 , self.ts - 9900) + datacheck = self.result_0(sql) + + sql = "select %s from regular_table_1 " %interp_select + sql += "range('%s' , '%s');" % (self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0(sql) + sql = "select %s from regular_table_2 " %interp_select + sql += "range('%s' , '%s');" % (self.ts , self.ts + 200000) + datacheck = self.regular2_checkall_0(sql) + sql = "select %s from regular_table_3 " %interp_select + sql += "range('%s' , '%s');" % (self.ts , self.ts + 200000) + datacheck = self.regular3_checkall_0(sql) + + sql = "select %s from regular_table_1 " %interp_select + sql += "range('%s' , '%s');" % (self.ts + 1500 , self.ts + 2500) + datacheck = self.result_0(sql) + sql = "select %s from regular_table_2 " %interp_select + sql += "range('%s' , '%s');" % (self.ts + 1500 , self.ts + 2500) + datacheck = self.result_0(sql) + sql = "select %s from regular_table_3 " %interp_select + sql += "range('%s' , '%s');" % (self.ts + 1500 , self.ts + 2500) + datacheck = self.result_0(sql) + + sql = "select %s from regular_table_1 " % interp_select + sql += "range('%s' , '%s');" % (self.ts + 150000 , self.ts + 200000) + datacheck = self.result_0(sql) + sql = "select %s from regular_table_2 " % interp_select + sql += "range('%s' , '%s');" % (self.ts + 150000 , self.ts + 200000) + datacheck = self.result_0(sql) + sql = "select %s from regular_table_3 " % interp_select + sql += "range('%s' , '%s');" % (self.ts + 150000 , self.ts + 200000) + datacheck = self.result_0(sql) + + # FILL(LINEAR) + sql = "select %s from regular_table_1 FILL(LINEAR)" %interp_select + datacheck = self.regular1_checkall_0(sql) + sql = "select %s from regular_table_2 FILL(LINEAR)" %interp_select + datacheck = self.regular2_checkall_0(sql) + sql = "select %s from regular_table_3 FILL(LINEAR)" %interp_select + datacheck = self.regular3_checkall_0(sql) + + sql = "select %s from regular_table_1 " % interp_select + sql += "range('%s' , '%s') FILL(LINEAR);" % (self.ts - 10000 , self.ts + 100000) + datacheck = self.result_0(sql) + sql = "select %s from regular_table_2 " % interp_select + sql += "range('%s' , '%s') FILL(LINEAR);" % (self.ts - 10000 , self.ts + 100000) + datacheck = self.result_0(sql) + sql = "select %s from regular_table_3 " % interp_select + sql += "range('%s' , '%s') FILL(LINEAR);" % (self.ts - 10000 , self.ts + 100000) + datacheck = self.result_0(sql) + + sql = "select %s from regular_table_1 " % interp_select + sql += "range('%s' , '%s') FILL(LINEAR);" % (self.ts - 10000 , self.ts - 9900) + datacheck = self.result_0(sql) + sql = "select %s from regular_table_2 " % interp_select + sql += "range('%s' , '%s') FILL(LINEAR);" % (self.ts - 10000 , self.ts - 9900) + datacheck = self.result_0(sql) + sql = "select %s from regular_table_3 " % interp_select + sql += "range('%s' , '%s') FILL(LINEAR);" % (self.ts - 10000 , self.ts - 9900) + datacheck = self.result_0(sql) + + sql = "select %s from regular_table_1 " % interp_select + sql += "range('%s' , '%s') FILL(LINEAR);" % (self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0(sql) + sql = "select %s from regular_table_2 " % interp_select + sql += "range('%s' , '%s') FILL(LINEAR);" % (self.ts , self.ts + 200000) + datacheck = self.regular2_checkall_0(sql) + sql = "select %s from regular_table_3 " % interp_select + sql += "range('%s' , '%s') FILL(LINEAR);" % (self.ts , self.ts + 200000) + datacheck = self.regular3_checkall_0(sql) + + sql = "select %s from regular_table_1 " % interp_select + sql += "range('%s' , '%s') FILL(LINEAR);" % (self.ts + 1500 , self.ts + 2500) + datacheck = self.regular1_checkall_0_LINEAR(sql) + sql = "select %s from regular_table_2 " % interp_select + sql += "range('%s' , '%s') FILL(LINEAR);" % (self.ts + 1500 , self.ts + 2500) + datacheck = self.regular2_checkall_0_LINEAR(sql) + sql = "select %s from regular_table_3 " % interp_select + sql += "range('%s' , '%s') FILL(LINEAR);" % (self.ts + 1500 , self.ts + 2500) + datacheck = self.regular3_checkall_0_LINEAR(sql) + + sql = "select %s from regular_table_1 " % interp_select + sql += "range('%s' , '%s') FILL(LINEAR);" % (self.ts + 150000 , self.ts + 200000) + datacheck = self.result_0(sql) + sql = "select %s from regular_table_2 " % interp_select + sql += "range('%s' , '%s') FILL(LINEAR);" % (self.ts + 150000 , self.ts + 200000) + datacheck = self.result_0(sql) + sql = "select %s from regular_table_3 " % interp_select + sql += "range('%s' , '%s') FILL(LINEAR);" % (self.ts + 150000 , self.ts + 200000) + datacheck = self.result_0(sql) + + # FILL(LINEAR) + EVERY( s) + sql = "select %s from regular_table_1 EVERY(1s) FILL(LINEAR);" %interp_select + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(91) + sql = "select %s from regular_table_2 EVERY(1s) FILL(LINEAR);" %interp_select + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(91) + sql = "select %s from regular_table_3 EVERY(1s) FILL(LINEAR);" %interp_select + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(91) + + sql = "select %s from regular_table_1 EVERY(5s) FILL(LINEAR);" %interp_select + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(19) + sql = "select %s from regular_table_2 EVERY(5s) FILL(LINEAR);" %interp_select + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(19) + sql = "select %s from regular_table_3 EVERY(5s) FILL(LINEAR);" %interp_select + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(19) + + # range + FILL(LINEAR) + EVERY( s) + sql = "select %s from regular_table_1 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(LINEAR);" % (self.ts - 10000 , self.ts + 100000) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(91) + sql = "select %s from regular_table_2 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(LINEAR);" % (self.ts - 10000 , self.ts + 100000) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(91) + sql = "select %s from regular_table_3 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(LINEAR);" % (self.ts - 10000 , self.ts + 100000) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(91) + + sql = "select %s from regular_table_1 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(LINEAR);" % (self.ts - 10000 , self.ts - 9900) + datacheck = self.result_0(sql) + sql = "select %s from regular_table_2 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(LINEAR);" % (self.ts - 10000 , self.ts - 9900) + datacheck = self.result_0(sql) + sql = "select %s from regular_table_3 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(LINEAR);" % (self.ts - 10000 , self.ts - 9900) + datacheck = self.result_0(sql) + + sql = "select %s from regular_table_1 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(LINEAR);" % (self.ts , self.ts) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(1) + sql = "select %s from regular_table_2 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(LINEAR);" % (self.ts , self.ts) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(1) + sql = "select %s from regular_table_3 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(LINEAR);" % (self.ts , self.ts) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(1) + + sql = "select %s from regular_table_1 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(LINEAR);" % (self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(91) + sql = "select %s from regular_table_2 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(LINEAR);" % (self.ts , self.ts + 200000) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(91) + sql = "select %s from regular_table_3 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(LINEAR);" % (self.ts , self.ts + 200000) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(91) + + sql = "select %s from regular_table_1 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(LINEAR) ORDER BY ts DESC;" % (self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_9(sql) + tdSql.checkRows(91) + sql = "select %s from regular_table_2 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(LINEAR) ORDER BY ts DESC;" % (self.ts , self.ts + 200000) + datacheck = self.regular2_checkall_9(sql) + tdSql.checkRows(91) + sql = "select %s from regular_table_3 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(LINEAR) ORDER BY ts DESC;" % (self.ts , self.ts + 200000) + datacheck = self.regular3_checkall_9(sql) + tdSql.checkRows(91) + + sql = "select %s from regular_table_1 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(LINEAR);" % (self.ts + 1500 , self.ts + 2500) + datacheck = self.regular1_checkall_0_LINEAR(sql) + tdSql.checkRows(2) + sql = "select %s from regular_table_2 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(LINEAR);" % (self.ts + 1500 , self.ts + 2500) + datacheck = self.regular2_checkall_0_LINEAR(sql) + tdSql.checkRows(2) + sql = "select %s from regular_table_3 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(LINEAR);" % (self.ts + 1500 , self.ts + 2500) + datacheck = self.regular3_checkall_0_LINEAR(sql) + tdSql.checkRows(2) + + sql = "select %s from regular_table_1 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(LINEAR);" % (self.ts + 150000 , self.ts + 200000) + datacheck = self.result_0(sql) + sql = "select %s from regular_table_2 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(LINEAR);" % (self.ts + 150000 , self.ts + 200000) + datacheck = self.result_0(sql) + sql = "select %s from regular_table_3 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(LINEAR);" % (self.ts + 150000 , self.ts + 200000) + datacheck = self.result_0(sql) + + # where + range + FILL(LINEAR) + EVERY( s) + sql = "select %s from regular_table_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(11) + sql = "select %s from regular_table_2 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(11) + sql = "select %s from regular_table_3 " % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(11) + + sql = "select %s from regular_table_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + datacheck = self.result_0(sql) + sql = "select %s from regular_table_2 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + datacheck = self.result_0(sql) + sql = "select %s from regular_table_3 " % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + datacheck = self.result_0(sql) + + sql = "select %s from regular_table_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR);" % (self.ts , self.ts + 10000 , self.ts , self.ts) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(1) + sql = "select %s from regular_table_2 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR);" % (self.ts , self.ts + 10000 , self.ts , self.ts) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(1) + sql = "select %s from regular_table_3 " % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR);" % (self.ts , self.ts + 10000 , self.ts , self.ts) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(1) + + sql = "select %s from regular_table_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR);" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(11) + sql = "select %s from regular_table_2 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR);" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(11) + sql = "select %s from regular_table_3 " % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR);" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(11) + + sql = "select %s from regular_table_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR) ORDER BY ts DESC;" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0_NEXT(sql) + tdSql.checkRows(11) + sql = "select %s from regular_table_2 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR) ORDER BY ts DESC;" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular2_checkall_0_NEXT(sql) + tdSql.checkRows(11) + sql = "select %s from regular_table_3 " % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR) ORDER BY ts DESC;" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular3_checkall_0_NEXT(sql) + tdSql.checkRows(11) + + sql = "select %s from regular_table_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR);" % (self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + datacheck = self.regular1_checkall_0_LINEAR(sql) + tdSql.checkRows(2) + sql = "select %s from regular_table_2 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR);" % (self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + datacheck = self.regular2_checkall_0_LINEAR(sql) + tdSql.checkRows(2) + sql = "select %s from regular_table_3 " % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR);" % (self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + datacheck = self.regular3_checkall_0_LINEAR(sql) + tdSql.checkRows(2) + + sql = "select %s from regular_table_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR);" % (self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + datacheck = self.result_0(sql) + sql = "select %s from regular_table_2 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR);" % (self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + datacheck = self.result_0(sql) + sql = "select %s from regular_table_3 " % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR);" % (self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + datacheck = self.result_0(sql) + + # FILL(NEXT) + sql = "select %s from regular_table_1 FILL(NEXT)" %interp_select + datacheck = self.regular1_checkall_0(sql) + sql = "select %s from regular_table_2 FILL(NEXT)" %interp_select + datacheck = self.regular2_checkall_0(sql) + sql = "select %s from regular_table_3 FILL(NEXT)" %interp_select + datacheck = self.regular3_checkall_0(sql) + + sql = "select %s from regular_table_1 " % interp_select + sql += "range('%s' , '%s') FILL(NEXT);" % (self.ts - 10000 , self.ts + 100000) + datacheck = self.regular1_checkall_0(sql) + sql = "select %s from regular_table_2 " % interp_select + sql += "range('%s' , '%s') FILL(NEXT);" % (self.ts - 10000 , self.ts + 100000) + datacheck = self.regular2_checkall_0(sql) + sql = "select %s from regular_table_3 " % interp_select + sql += "range('%s' , '%s') FILL(NEXT);" % (self.ts - 10000 , self.ts + 100000) + datacheck = self.regular3_checkall_0(sql) + + sql = "select %s from regular_table_1 " % interp_select + sql += "range('%s' , '%s') FILL(NEXT);" % (self.ts - 10000 , self.ts - 9900) + datacheck = self.regular1_checkall_0(sql) + sql = "select %s from regular_table_2 " % interp_select + sql += "range('%s' , '%s') FILL(NEXT);" % (self.ts - 10000 , self.ts - 9900) + datacheck = self.regular2_checkall_0(sql) + sql = "select %s from regular_table_3 " % interp_select + sql += "range('%s' , '%s') FILL(NEXT);" % (self.ts - 10000 , self.ts - 9900) + datacheck = self.regular3_checkall_0(sql) + + sql = "select %s from regular_table_1 " % interp_select + sql += "range('%s' , '%s') FILL(NEXT);" % (self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0(sql) + sql = "select %s from regular_table_2 " % interp_select + sql += "range('%s' , '%s') FILL(NEXT);" % (self.ts , self.ts + 200000) + datacheck = self.regular2_checkall_0(sql) + sql = "select %s from regular_table_3 " % interp_select + sql += "range('%s' , '%s') FILL(NEXT);" % (self.ts , self.ts + 200000) + datacheck = self.regular3_checkall_0(sql) + + sql = "select %s from regular_table_1 " % interp_select + sql += "range('%s' , '%s') FILL(NEXT);" % (self.ts + 1500 , self.ts + 2500) + datacheck = self.regular1_checkall_0_NEXT(sql) + sql = "select %s from regular_table_2 " % interp_select + sql += "range('%s' , '%s') FILL(NEXT);" % (self.ts + 1500 , self.ts + 2500) + datacheck = self.regular2_checkall_0_NEXT(sql) + sql = "select %s from regular_table_3 " % interp_select + sql += "range('%s' , '%s') FILL(NEXT);" % (self.ts + 1500 , self.ts + 2500) + datacheck = self.regular3_checkall_0_NEXT(sql) + + sql = "select %s from regular_table_1 " % interp_select + sql += "range('%s' , '%s') FILL(NEXT);" % (self.ts + 150000 , self.ts + 200000) + datacheck = self.result_0(sql) + sql = "select %s from regular_table_2 " % interp_select + sql += "range('%s' , '%s') FILL(NEXT);" % (self.ts + 150000 , self.ts + 200000) + datacheck = self.result_0(sql) + sql = "select %s from regular_table_3 " % interp_select + sql += "range('%s' , '%s') FILL(NEXT);" % (self.ts + 150000 , self.ts + 200000) + datacheck = self.result_0(sql) + + # FILL(NEXT) + EVERY( s) + sql = "select %s from regular_table_1 EVERY(1s) FILL(NEXT);" %interp_select + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(91) + sql = "select %s from regular_table_2 EVERY(1s) FILL(NEXT);" %interp_select + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(91) + sql = "select %s from regular_table_3 EVERY(1s) FILL(NEXT);" %interp_select + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(91) + + sql = "select %s from regular_table_1 EVERY(5s) FILL(NEXT);" %interp_select + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(19) + sql = "select %s from regular_table_2 EVERY(5s) FILL(NEXT);" %interp_select + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(19) + sql = "select %s from regular_table_3 EVERY(5s) FILL(NEXT);" %interp_select + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(19) + + # range + FILL(NEXT) + EVERY( s) + sql = "select %s from regular_table_1 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(NEXT);" % (self.ts - 10000 , self.ts + 100000) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(101) + sql = "select %s from regular_table_2 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(NEXT);" % (self.ts - 10000 , self.ts + 100000) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(101) + sql = "select %s from regular_table_3 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(NEXT);" % (self.ts - 10000 , self.ts + 100000) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(101) + + sql = "select %s from regular_table_1 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(NEXT);" % (self.ts - 10000 , self.ts - 9900) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(1) + sql = "select %s from regular_table_2 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(NEXT);" % (self.ts - 10000 , self.ts - 9900) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(1) + sql = "select %s from regular_table_3 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(NEXT);" % (self.ts - 10000 , self.ts - 9900) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(1) + + sql = "select %s from regular_table_1 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(NEXT);" % (self.ts , self.ts) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(1) + sql = "select %s from regular_table_2 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(NEXT);" % (self.ts , self.ts) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(1) + sql = "select %s from regular_table_3 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(NEXT);" % (self.ts , self.ts) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(1) + + sql = "select %s from regular_table_1 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(NEXT);" % (self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(91) + sql = "select %s from regular_table_2 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(NEXT);" % (self.ts , self.ts + 200000) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(91) + sql = "select %s from regular_table_3 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(NEXT);" % (self.ts , self.ts + 200000) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(91) + + sql = "select %s from regular_table_1 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(NEXT) ORDER BY ts DESC;" % (self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_9(sql) + tdSql.checkRows(91) + sql = "select %s from regular_table_2 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(NEXT) ORDER BY ts DESC;" % (self.ts , self.ts + 200000) + datacheck = self.regular2_checkall_9(sql) + tdSql.checkRows(91) + sql = "select %s from regular_table_3 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(NEXT) ORDER BY ts DESC;" % (self.ts , self.ts + 200000) + datacheck = self.regular3_checkall_9(sql) + tdSql.checkRows(91) + + sql = "select %s from regular_table_1 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(NEXT);" % (self.ts + 1500 , self.ts + 2500) + datacheck = self.regular1_checkall_0_NEXT(sql) + tdSql.checkRows(2) + sql = "select %s from regular_table_2 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(NEXT);" % (self.ts + 1500 , self.ts + 2500) + datacheck = self.regular2_checkall_0_NEXT(sql) + tdSql.checkRows(2) + sql = "select %s from regular_table_3 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(NEXT);" % (self.ts + 1500 , self.ts + 2500) + datacheck = self.regular3_checkall_0_NEXT(sql) + tdSql.checkRows(2) + + sql = "select %s from regular_table_1 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(NEXT);" % (self.ts + 150000 , self.ts + 200000) + datacheck = self.result_0(sql) + sql = "select %s from regular_table_2 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(NEXT);" % (self.ts + 150000 , self.ts + 200000) + datacheck = self.result_0(sql) + sql = "select %s from regular_table_3 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(NEXT);" % (self.ts + 150000 , self.ts + 200000) + datacheck = self.result_0(sql) + + # where + range + FILL(NEXT) + EVERY( s) + sql = "select %s from regular_table_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(21) + sql = "select %s from regular_table_2 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(21) + sql = "select %s from regular_table_3 " % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(21) + + sql = "select %s from regular_table_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(1) + sql = "select %s from regular_table_2 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(1) + sql = "select %s from regular_table_3 " % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(1) + + sql = "select %s from regular_table_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT);" % (self.ts , self.ts + 10000 , self.ts , self.ts) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(1) + sql = "select %s from regular_table_2 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT);" % (self.ts , self.ts + 10000 , self.ts , self.ts) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(1) + sql = "select %s from regular_table_3 " % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT);" % (self.ts , self.ts + 10000 , self.ts , self.ts) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(1) + + sql = "select %s from regular_table_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT);" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(11) + sql = "select %s from regular_table_2 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT);" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(11) + sql = "select %s from regular_table_3 " % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT);" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(11) + + sql = "select %s from regular_table_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT) ORDER BY ts DESC;" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0_NEXT(sql) + tdSql.checkRows(11) + sql = "select %s from regular_table_2 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT) ORDER BY ts DESC;" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular2_checkall_0_NEXT(sql) + tdSql.checkRows(11) + sql = "select %s from regular_table_3 " % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT) ORDER BY ts DESC;" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular3_checkall_0_NEXT(sql) + tdSql.checkRows(11) + + sql = "select %s from regular_table_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT);" % (self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + datacheck = self.regular1_checkall_0_NEXT(sql) + tdSql.checkRows(2) + sql = "select %s from regular_table_2 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT);" % (self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + datacheck = self.regular2_checkall_0_NEXT(sql) + tdSql.checkRows(2) + sql = "select %s from regular_table_3 " % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT);" % (self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + datacheck = self.regular3_checkall_0_NEXT(sql) + tdSql.checkRows(2) + + sql = "select %s from regular_table_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT);" % (self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + datacheck = self.result_0(sql) + sql = "select %s from regular_table_2 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT);" % (self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + datacheck = self.result_0(sql) + sql = "select %s from regular_table_3 " % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT);" % (self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + datacheck = self.result_0(sql) + + # FILL(PREV) + sql = "select %s from regular_table_1 FILL(PREV)" %interp_select + datacheck = self.regular1_checkall_0(sql) + sql = "select %s from regular_table_2 FILL(PREV)" %interp_select + datacheck = self.regular2_checkall_0(sql) + sql = "select %s from regular_table_3 FILL(PREV)" %interp_select + datacheck = self.regular3_checkall_0(sql) + + sql = "select %s from regular_table_1 " % interp_select + sql += "range('%s' , '%s') FILL(PREV);" % (self.ts - 10000 , self.ts + 100000) + datacheck = self.result_0(sql) + sql = "select %s from regular_table_2 " % interp_select + sql += "range('%s' , '%s') FILL(PREV);" % (self.ts - 10000 , self.ts + 100000) + datacheck = self.result_0(sql) + sql = "select %s from regular_table_3 " % interp_select + sql += "range('%s' , '%s') FILL(PREV);" % (self.ts - 10000 , self.ts + 100000) + datacheck = self.result_0(sql) + + sql = "select %s from regular_table_1 " % interp_select + sql += "range('%s' , '%s') FILL(PREV);" % (self.ts - 10000 , self.ts - 9900) + datacheck = self.result_0(sql) + sql = "select %s from regular_table_2 " % interp_select + sql += "range('%s' , '%s') FILL(PREV);" % (self.ts - 10000 , self.ts - 9900) + datacheck = self.result_0(sql) + sql = "select %s from regular_table_3 " % interp_select + sql += "range('%s' , '%s') FILL(PREV);" % (self.ts - 10000 , self.ts - 9900) + datacheck = self.result_0(sql) + + sql = "select %s from regular_table_1 " % interp_select + sql += "range('%s' , '%s') FILL(PREV);" % (self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0(sql) + sql = "select %s from regular_table_2 " % interp_select + sql += "range('%s' , '%s') FILL(PREV);" % (self.ts , self.ts + 200000) + datacheck = self.regular2_checkall_0(sql) + sql = "select %s from regular_table_3 " % interp_select + sql += "range('%s' , '%s') FILL(PREV);" % (self.ts , self.ts + 200000) + datacheck = self.regular3_checkall_0(sql) + + sql = "select %s from regular_table_1 " % interp_select + sql += "range('%s' , '%s') FILL(PREV);" % (self.ts + 1500 , self.ts + 2500) + datacheck = self.regular1_checkall_0(sql) + sql = "select %s from regular_table_2 " % interp_select + sql += "range('%s' , '%s') FILL(PREV);" % (self.ts + 1500 , self.ts + 2500) + datacheck = self.regular2_checkall_0(sql) + sql = "select %s from regular_table_3 " % interp_select + sql += "range('%s' , '%s') FILL(PREV);" % (self.ts + 1500 , self.ts + 2500) + datacheck = self.regular3_checkall_0(sql) + + sql = "select %s from regular_table_1 " % interp_select + sql += "range('%s' , '%s') FILL(PREV);" % (self.ts + 150000 , self.ts + 200000) + datacheck = self.regular1_checkall_9(sql) + sql = "select %s from regular_table_2 " % interp_select + sql += "range('%s' , '%s') FILL(PREV);" % (self.ts + 150000 , self.ts + 200000) + datacheck = self.regular2_checkall_9(sql) + sql = "select %s from regular_table_3 " % interp_select + sql += "range('%s' , '%s') FILL(PREV);" % (self.ts + 150000 , self.ts + 200000) + datacheck = self.regular3_checkall_9(sql) + + # FILL(PREV) + EVERY( s) + sql = "select %s from regular_table_1 EVERY(1s) FILL(PREV);" %interp_select + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(91) + sql = "select %s from regular_table_2 EVERY(1s) FILL(PREV);" %interp_select + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(91) + sql = "select %s from regular_table_3 EVERY(1s) FILL(PREV);" %interp_select + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(91) + + sql = "select %s from regular_table_1 EVERY(5s) FILL(PREV);" %interp_select + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(19) + sql = "select %s from regular_table_2 EVERY(5s) FILL(PREV);" %interp_select + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(19) + sql = "select %s from regular_table_3 EVERY(5s) FILL(PREV);" %interp_select + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(19) + + # range + FILL(PREV) + EVERY( s) + sql = "select %s from regular_table_1 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(PREV);" % (self.ts - 10000 , self.ts + 100000) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(101) + sql = "select %s from regular_table_2 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(PREV);" % (self.ts - 10000 , self.ts + 100000) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(101) + sql = "select %s from regular_table_3 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(PREV);" % (self.ts - 10000 , self.ts + 100000) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(101) + + sql = "select %s from regular_table_1 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(PREV);" % (self.ts - 10000 , self.ts - 9900) + datacheck = self.result_0(sql) + sql = "select %s from regular_table_2 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(PREV);" % (self.ts - 10000 , self.ts - 9900) + datacheck = self.result_0(sql) + sql = "select %s from regular_table_3 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(PREV);" % (self.ts - 10000 , self.ts - 9900) + datacheck = self.result_0(sql) + + sql = "select %s from regular_table_1 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(PREV);" % (self.ts , self.ts) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(1) + sql = "select %s from regular_table_2 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(PREV);" % (self.ts , self.ts) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(1) + sql = "select %s from regular_table_3 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(PREV);" % (self.ts , self.ts) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(1) + + sql = "select %s from regular_table_1 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(PREV);" % (self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(201) + sql = "select %s from regular_table_2 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(PREV);" % (self.ts , self.ts + 200000) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(201) + sql = "select %s from regular_table_3 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(PREV);" % (self.ts , self.ts + 200000) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(201) + + sql = "select %s from regular_table_1 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(PREV) ORDER BY ts DESC;" % (self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_9(sql) + tdSql.checkRows(201) + sql = "select %s from regular_table_2 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(PREV) ORDER BY ts DESC;" % (self.ts , self.ts + 200000) + datacheck = self.regular2_checkall_9(sql) + tdSql.checkRows(201) + sql = "select %s from regular_table_3 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(PREV) ORDER BY ts DESC;" % (self.ts , self.ts + 200000) + datacheck = self.regular3_checkall_9(sql) + tdSql.checkRows(201) + + sql = "select %s from regular_table_1 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(PREV);" % (self.ts + 1500 , self.ts + 2500) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(2) + sql = "select %s from regular_table_2 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(PREV);" % (self.ts + 1500 , self.ts + 2500) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(2) + sql = "select %s from regular_table_3 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(PREV);" % (self.ts + 1500 , self.ts + 2500) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(2) + + sql = "select %s from regular_table_1 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(PREV);" % (self.ts + 150000 , self.ts + 200000) + datacheck = self.regular1_checkall_9(sql) + tdSql.checkRows(51) + sql = "select %s from regular_table_2 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(PREV);" % (self.ts + 150000 , self.ts + 200000) + datacheck = self.regular2_checkall_9(sql) + tdSql.checkRows(51) + sql = "select %s from regular_table_3 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(PREV);" % (self.ts + 150000 , self.ts + 200000) + datacheck = self.regular3_checkall_9(sql) + tdSql.checkRows(51) + + # where + range + FILL(PREV) + EVERY( s) + sql = "select %s from regular_table_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(101) + sql = "select %s from regular_table_2 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(101) + sql = "select %s from regular_table_3 " % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(PREV);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(101) + + sql = "select %s from regular_table_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + datacheck = self.result_0(sql) + sql = "select %s from regular_table_2 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + datacheck = self.result_0(sql) + sql = "select %s from regular_table_3 " % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(PREV);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + datacheck = self.result_0(sql) + + sql = "select %s from regular_table_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV);" % (self.ts , self.ts + 10000 , self.ts , self.ts) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(1) + sql = "select %s from regular_table_2 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV);" % (self.ts , self.ts + 10000 , self.ts , self.ts) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(1) + sql = "select %s from regular_table_3 " % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(PREV);" % (self.ts , self.ts + 10000 , self.ts , self.ts) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(1) + + sql = "select %s from regular_table_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV);" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(201) + sql = "select %s from regular_table_2 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV);" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(201) + sql = "select %s from regular_table_3 " % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(PREV);" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(201) + + sql = "select %s from regular_table_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV) ORDER BY ts DESC;" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0_NEXT(sql) + tdSql.checkRows(201) + sql = "select %s from regular_table_2 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV) ORDER BY ts DESC;" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular2_checkall_0_NEXT(sql) + tdSql.checkRows(201) + sql = "select %s from regular_table_3 " % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(PREV) ORDER BY ts DESC;" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular3_checkall_0_NEXT(sql) + tdSql.checkRows(201) + + sql = "select %s from regular_table_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV);" % (self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(2) + sql = "select %s from regular_table_2 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV);" % (self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(2) + sql = "select %s from regular_table_3 " % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(PREV);" % (self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(2) + + sql = "select %s from regular_table_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV);" % (self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + datacheck = self.regular1_checkall_0_NEXT(sql) + tdSql.checkRows(51) + sql = "select %s from regular_table_2 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV);" % (self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + datacheck = self.regular2_checkall_0_NEXT(sql) + tdSql.checkRows(51) + sql = "select %s from regular_table_3 " % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(PREV);" % (self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + datacheck = self.regular3_checkall_0_NEXT(sql) + tdSql.checkRows(51) + + # FILL(VALUE,100) + sql = "select %s from regular_table_1 FILL(VALUE, 100)" %interp_select + datacheck = self.regular1_checkall_0(sql) + sql = "select %s from regular_table_2 FILL(VALUE, 100)" %interp_select + datacheck = self.regular2_checkall_0(sql) + sql = "select %s from regular_table_3 FILL(VALUE, 100)" %interp_select + datacheck = self.regular3_checkall_0(sql) + + sql = "select %s from regular_table_1 " % interp_select + sql += "range('%s' , '%s') FILL(VALUE, 100);" % (self.ts - 10000 , self.ts + 100000) + datacheck = self.regular1_checkall_0_VALUE100(sql) + sql = "select %s from regular_table_2 " % interp_select + sql += "range('%s' , '%s') FILL(VALUE, 100);" % (self.ts - 10000 , self.ts + 100000) + datacheck = self.regular1_checkall_0_VALUE100(sql) + sql = "select %s from regular_table_3 " % interp_select + sql += "range('%s' , '%s') FILL(VALUE, 100);" % (self.ts - 10000 , self.ts + 100000) + datacheck = self.regular1_checkall_0_VALUE100(sql) + + sql = "select %s from regular_table_1 " % interp_select + sql += "range('%s' , '%s') FILL(VALUE, 100);" % (self.ts - 10000 , self.ts - 9900) + datacheck = self.regular1_checkall_0_VALUE100(sql) + sql = "select %s from regular_table_2 " % interp_select + sql += "range('%s' , '%s') FILL(VALUE, 100);" % (self.ts - 10000 , self.ts - 9900) + datacheck = self.regular1_checkall_0_VALUE100(sql) + sql = "select %s from regular_table_3 " % interp_select + sql += "range('%s' , '%s') FILL(VALUE, 100);" % (self.ts - 10000 , self.ts - 9900) + datacheck = self.regular1_checkall_0_VALUE100(sql) + + sql = "select %s from regular_table_1 " % interp_select + sql += "range('%s' , '%s') FILL(VALUE, 100);" % (self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0(sql) + sql = "select %s from regular_table_2 " % interp_select + sql += "range('%s' , '%s') FILL(VALUE, 100);" % (self.ts , self.ts + 200000) + datacheck = self.regular2_checkall_0(sql) + sql = "select %s from regular_table_3 " % interp_select + sql += "range('%s' , '%s') FILL(VALUE, 100);" % (self.ts , self.ts + 200000) + datacheck = self.regular3_checkall_0(sql) + + sql = "select %s from regular_table_1 " % interp_select + sql += "range('%s' , '%s') FILL(VALUE, 100);" % (self.ts + 1500 , self.ts + 2500) + datacheck = self.regular1_checkall_0_VALUE100(sql) + sql = "select %s from regular_table_2 " % interp_select + sql += "range('%s' , '%s') FILL(VALUE, 100);" % (self.ts + 1500 , self.ts + 2500) + datacheck = self.regular1_checkall_0_VALUE100(sql) + sql = "select %s from regular_table_3 " % interp_select + sql += "range('%s' , '%s') FILL(VALUE, 100);" % (self.ts + 1500 , self.ts + 2500) + datacheck = self.regular1_checkall_0_VALUE100(sql) + + sql = "select %s from regular_table_1 " % interp_select + sql += "range('%s' , '%s') FILL(VALUE, 100);" % (self.ts + 150000 , self.ts + 200000) + datacheck = self.regular1_checkall_0_VALUE100(sql) + sql = "select %s from regular_table_2 " % interp_select + sql += "range('%s' , '%s') FILL(VALUE, 100);" % (self.ts + 150000 , self.ts + 200000) + datacheck = self.regular1_checkall_0_VALUE100(sql) + sql = "select %s from regular_table_3 " % interp_select + sql += "range('%s' , '%s') FILL(VALUE, 100);" % (self.ts + 150000 , self.ts + 200000) + datacheck = self.regular1_checkall_0_VALUE100(sql) + + # FILL(VALUE,100) + EVERY( s) + sql = "select %s from regular_table_1 EVERY(1s) FILL(VALUE, 100);" %interp_select + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(91) + sql = "select %s from regular_table_2 EVERY(1s) FILL(VALUE, 100);" %interp_select + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(91) + sql = "select %s from regular_table_3 EVERY(1s) FILL(VALUE, 100);" %interp_select + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(91) + + sql = "select %s from regular_table_1 EVERY(5s) FILL(VALUE, 100);" %interp_select + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(19) + sql = "select %s from regular_table_2 EVERY(5s) FILL(VALUE, 100);" %interp_select + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(19) + sql = "select %s from regular_table_3 EVERY(5s) FILL(VALUE, 100);" %interp_select + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(19) + + # range + FILL(VALUE, 100) + EVERY( s) + sql = "select %s from regular_table_1 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(VALUE, 100);" % (self.ts - 10000 , self.ts + 100000) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(111) + sql = "select %s from regular_table_2 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(VALUE, 100);" % (self.ts - 10000 , self.ts + 100000) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(111) + sql = "select %s from regular_table_3 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(VALUE, 100);" % (self.ts - 10000 , self.ts + 100000) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(111) + + sql = "select %s from regular_table_1 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(VALUE, 100);" % (self.ts - 10000 , self.ts - 9900) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(1) + sql = "select %s from regular_table_2 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(VALUE, 100);" % (self.ts - 10000 , self.ts - 9900) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(1) + sql = "select %s from regular_table_3 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(VALUE, 100);" % (self.ts - 10000 , self.ts - 9900) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(1) + + sql = "select %s from regular_table_1 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(VALUE, 100);" % (self.ts , self.ts) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(1) + sql = "select %s from regular_table_2 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(VALUE, 100);" % (self.ts , self.ts) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(1) + sql = "select %s from regular_table_3 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(VALUE, 100);" % (self.ts , self.ts) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(1) + + sql = "select %s from regular_table_1 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(VALUE, 100);" % (self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(201) + sql = "select %s from regular_table_2 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(VALUE, 100);" % (self.ts , self.ts + 200000) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(201) + sql = "select %s from regular_table_3 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(VALUE, 100);" % (self.ts , self.ts + 200000) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(201) + + sql = "select %s from regular_table_1 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(VALUE, 100) ORDER BY ts DESC;" % (self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(201) + sql = "select %s from regular_table_2 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(VALUE, 100) ORDER BY ts DESC;" % (self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(201) + sql = "select %s from regular_table_3 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(VALUE, 100) ORDER BY ts DESC;" % (self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(201) + + sql = "select %s from regular_table_1 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(VALUE, 100);" % (self.ts + 1500 , self.ts + 2500) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(2) + sql = "select %s from regular_table_2 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(VALUE, 100);" % (self.ts + 1500 , self.ts + 2500) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(2) + sql = "select %s from regular_table_3 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(VALUE, 100);" % (self.ts + 1500 , self.ts + 2500) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(2) + + sql = "select %s from regular_table_1 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(VALUE, 100);" % (self.ts + 150000 , self.ts + 200000) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(51) + sql = "select %s from regular_table_2 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(VALUE, 100);" % (self.ts + 150000 , self.ts + 200000) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(51) + sql = "select %s from regular_table_3 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(VALUE, 100);" % (self.ts + 150000 , self.ts + 200000) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(51) + + # where + range + FILL(VALUE, 100) + EVERY( s) + sql = "select %s from regular_table_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(111) + sql = "select %s from regular_table_2 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(111) + sql = "select %s from regular_table_3 " % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(111) + + sql = "select %s from regular_table_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(1) + sql = "select %s from regular_table_2 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(1) + sql = "select %s from regular_table_3 " % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(1) + + sql = "select %s from regular_table_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100);" % (self.ts , self.ts + 10000 , self.ts , self.ts) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(1) + sql = "select %s from regular_table_2 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100);" % (self.ts , self.ts + 10000 , self.ts , self.ts) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(1) + sql = "select %s from regular_table_3 " % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100);" % (self.ts , self.ts + 10000 , self.ts , self.ts) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(1) + + sql = "select %s from regular_table_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100);" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(201) + sql = "select %s from regular_table_2 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100);" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(201) + sql = "select %s from regular_table_3 " % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100);" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(201) + + sql = "select %s from regular_table_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100) ORDER BY ts DESC;" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(201) + sql = "select %s from regular_table_2 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100) ORDER BY ts DESC;" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(201) + sql = "select %s from regular_table_3 " % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100) ORDER BY ts DESC;" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(201) + + sql = "select %s from regular_table_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100);" % (self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(2) + sql = "select %s from regular_table_2 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100);" % (self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(2) + sql = "select %s from regular_table_3 " % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100);" % (self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(2) + + sql = "select %s from regular_table_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100);" % (self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(51) + sql = "select %s from regular_table_2 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100);" % (self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(51) + sql = "select %s from regular_table_3 " % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100);" % (self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(51) + + # FILL(NULL) + sql = "select %s from regular_table_1 FILL(NULL)" %interp_select + datacheck = self.regular1_checkall_0(sql) + sql = "select %s from regular_table_2 FILL(NULL)" %interp_select + datacheck = self.regular2_checkall_0(sql) + sql = "select %s from regular_table_3 FILL(NULL)" %interp_select + datacheck = self.regular3_checkall_0(sql) + + sql = "select %s from regular_table_1 " % interp_select + sql += "range('%s' , '%s') FILL(NULL);" % (self.ts - 10000 , self.ts + 100000) + datacheck = self.regular1_checkall_0_NULL(sql) + sql = "select %s from regular_table_2 " % interp_select + sql += "range('%s' , '%s') FILL(NULL);" % (self.ts - 10000 , self.ts + 100000) + datacheck = self.regular1_checkall_0_NULL(sql) + sql = "select %s from regular_table_3 " % interp_select + sql += "range('%s' , '%s') FILL(NULL);" % (self.ts - 10000 , self.ts + 100000) + datacheck = self.regular1_checkall_0_NULL(sql) + + sql = "select %s from regular_table_1 " % interp_select + sql += "range('%s' , '%s') FILL(NULL);" % (self.ts - 10000 , self.ts - 9900) + datacheck = self.regular1_checkall_0_NULL(sql) + sql = "select %s from regular_table_2 " % interp_select + sql += "range('%s' , '%s') FILL(NULL);" % (self.ts - 10000 , self.ts - 9900) + datacheck = self.regular1_checkall_0_NULL(sql) + sql = "select %s from regular_table_3 " % interp_select + sql += "range('%s' , '%s') FILL(NULL);" % (self.ts - 10000 , self.ts - 9900) + datacheck = self.regular1_checkall_0_NULL(sql) + + sql = "select %s from regular_table_1 " % interp_select + sql += "range('%s' , '%s') FILL(NULL);" % (self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0(sql) + sql = "select %s from regular_table_2 " % interp_select + sql += "range('%s' , '%s') FILL(NULL);" % (self.ts , self.ts + 200000) + datacheck = self.regular2_checkall_0(sql) + sql = "select %s from regular_table_3 " % interp_select + sql += "range('%s' , '%s') FILL(NULL);" % (self.ts , self.ts + 200000) + datacheck = self.regular3_checkall_0(sql) + + sql = "select %s from regular_table_1 " % interp_select + sql += "range('%s' , '%s') FILL(NULL);" % (self.ts + 1500 , self.ts + 2500) + datacheck = self.regular1_checkall_0_NULL(sql) + sql = "select %s from regular_table_2 " % interp_select + sql += "range('%s' , '%s') FILL(NULL);" % (self.ts + 1500 , self.ts + 2500) + datacheck = self.regular1_checkall_0_NULL(sql) + sql = "select %s from regular_table_3 " % interp_select + sql += "range('%s' , '%s') FILL(NULL);" % (self.ts + 1500 , self.ts + 2500) + datacheck = self.regular1_checkall_0_NULL(sql) + + sql = "select %s from regular_table_1 " % interp_select + sql += "range('%s' , '%s') FILL(NULL);" % (self.ts + 150000 , self.ts + 200000) + datacheck = self.regular1_checkall_0_NULL(sql) + sql = "select %s from regular_table_2 " % interp_select + sql += "range('%s' , '%s') FILL(NULL);" % (self.ts + 150000 , self.ts + 200000) + datacheck = self.regular1_checkall_0_NULL(sql) + sql = "select %s from regular_table_3 " % interp_select + sql += "range('%s' , '%s') FILL(NULL);" % (self.ts + 150000 , self.ts + 200000) + datacheck = self.regular1_checkall_0_NULL(sql) + + + # FILL(NULL) + EVERY( s) + sql = "select %s from regular_table_1 EVERY(1s) FILL(NULL);" %interp_select + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(91) + sql = "select %s from regular_table_2 EVERY(1s) FILL(NULL);" %interp_select + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(91) + sql = "select %s from regular_table_3 EVERY(1s) FILL(NULL);" %interp_select + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(91) + + sql = "select %s from regular_table_1 EVERY(5s) FILL(NULL);" %interp_select + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(19) + sql = "select %s from regular_table_2 EVERY(5s) FILL(NULL);" %interp_select + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(19) + sql = "select %s from regular_table_3 EVERY(5s) FILL(NULL);" %interp_select + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(19) + + # range + FILL(NULL) + EVERY( s) + sql = "select %s from regular_table_1 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(NULL);" % (self.ts - 10000 , self.ts + 100000) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(111) + sql = "select %s from regular_table_2 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(NULL);" % (self.ts - 10000 , self.ts + 100000) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(111) + sql = "select %s from regular_table_3 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(NULL);" % (self.ts - 10000 , self.ts + 100000) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(111) + + sql = "select %s from regular_table_1 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(NULL);" % (self.ts - 10000 , self.ts - 9900) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(1) + sql = "select %s from regular_table_2 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(NULL);" % (self.ts - 10000 , self.ts - 9900) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(1) + sql = "select %s from regular_table_3 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(NULL);" % (self.ts - 10000 , self.ts - 9900) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(1) + + sql = "select %s from regular_table_1 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(NULL);" % (self.ts , self.ts) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(1) + sql = "select %s from regular_table_2 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(NULL);" % (self.ts , self.ts) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(1) + sql = "select %s from regular_table_3 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(NULL);" % (self.ts , self.ts) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(1) + + sql = "select %s from regular_table_1 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(NULL);" % (self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(201) + sql = "select %s from regular_table_2 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(NULL);" % (self.ts , self.ts + 200000) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(201) + sql = "select %s from regular_table_3 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(NULL);" % (self.ts , self.ts + 200000) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(201) + + sql = "select %s from regular_table_1 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(NULL) ORDER BY ts DESC;" % (self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(201) + sql = "select %s from regular_table_2 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(NULL) ORDER BY ts DESC;" % (self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(201) + sql = "select %s from regular_table_3 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(NULL) ORDER BY ts DESC;" % (self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(201) + + sql = "select %s from regular_table_1 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(NULL);" % (self.ts + 1500 , self.ts + 2500) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(2) + sql = "select %s from regular_table_2 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(NULL);" % (self.ts + 1500 , self.ts + 2500) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(2) + sql = "select %s from regular_table_3 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(NULL);" % (self.ts + 1500 , self.ts + 2500) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(2) + + sql = "select %s from regular_table_1 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(NULL);" % (self.ts + 150000 , self.ts + 200000) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(51) + sql = "select %s from regular_table_2 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(NULL);" % (self.ts + 150000 , self.ts + 200000) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(51) + sql = "select %s from regular_table_3 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(NULL);" % (self.ts + 150000 , self.ts + 200000) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(51) + + # where + range + FILL(NULL) + EVERY( s) + sql = "select %s from regular_table_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(111) + sql = "select %s from regular_table_2 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(111) + sql = "select %s from regular_table_3 " % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(NULL);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(111) + + sql = "select %s from regular_table_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(1) + sql = "select %s from regular_table_2 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(1) + sql = "select %s from regular_table_3 " % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(NULL);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(1) + + sql = "select %s from regular_table_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL);" % (self.ts , self.ts + 10000 , self.ts , self.ts) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(1) + sql = "select %s from regular_table_2 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL);" % (self.ts , self.ts + 10000 , self.ts , self.ts) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(1) + sql = "select %s from regular_table_3 " % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(NULL);" % (self.ts , self.ts + 10000 , self.ts , self.ts) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(1) + + sql = "select %s from regular_table_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL);" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(201) + sql = "select %s from regular_table_2 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL);" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(201) + sql = "select %s from regular_table_3 " % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(NULL);" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(201) + + sql = "select %s from regular_table_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL) ORDER BY ts DESC;" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(201) + sql = "select %s from regular_table_2 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL) ORDER BY ts DESC;" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(201) + sql = "select %s from regular_table_3 " % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(NULL) ORDER BY ts DESC;" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(201) + + sql = "select %s from regular_table_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL);" % (self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(2) + sql = "select %s from regular_table_2 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL);" % (self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(2) + sql = "select %s from regular_table_3 " % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(NULL);" % (self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(2) + + sql = "select %s from regular_table_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL);" % (self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(51) + sql = "select %s from regular_table_2 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL);" % (self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(51) + sql = "select %s from regular_table_3 " % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(NULL);" % (self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(51) + + + # EVERY(1s) + sql = "select %s from regular_table_1 EVERY(1s);" %interp_select + datacheck = self.regular1_checkall_0(sql) + datacheck = self.regular1_checkall_20(sql) + sql = "select %s from regular_table_2 EVERY(1s);" %interp_select + datacheck = self.regular2_checkall_0(sql) + datacheck = self.regular2_checkall_20(sql) + sql = "select %s from regular_table_3 EVERY(1s);" %interp_select + datacheck = self.regular3_checkall_0(sql) + datacheck = self.regular3_checkall_20(sql) + + sql = "select %s from regular_table_1 " % interp_select + sql += "range('%s' , '%s') EVERY(1s);" % (self.ts - 10000 , self.ts + 100000) + datacheck = self.regular1_checkall_0(sql) + datacheck = self.regular1_checkall_20(sql) + sql = "select %s from regular_table_2 " % interp_select + sql += "range('%s' , '%s') EVERY(1s);" % (self.ts - 10000 , self.ts + 100000) + datacheck = self.regular2_checkall_0(sql) + datacheck = self.regular2_checkall_20(sql) + sql = "select %s from regular_table_3 " % interp_select + sql += "range('%s' , '%s') EVERY(1s);" % (self.ts - 10000 , self.ts + 100000) + datacheck = self.regular3_checkall_0(sql) + datacheck = self.regular3_checkall_20(sql) + + sql = "select %s from regular_table_1 " % interp_select + sql += "range('%s' , '%s') EVERY(1s);" % (self.ts - 10000 , self.ts - 9900) + datacheck = self.result_0(sql) + sql = "select %s from regular_table_2 " % interp_select + sql += "range('%s' , '%s') EVERY(1s);" % (self.ts - 10000 , self.ts - 9900) + datacheck = self.result_0(sql) + sql = "select %s from regular_table_3 " % interp_select + sql += "range('%s' , '%s') EVERY(1s);" % (self.ts - 10000 , self.ts - 9900) + datacheck = self.result_0(sql) + + sql = "select %s from regular_table_1 " % interp_select + sql += "range('%s' , '%s') EVERY(1s);" % (self.ts , self.ts) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(1) + sql = "select %s from regular_table_2 " % interp_select + sql += "range('%s' , '%s') EVERY(1s);" % (self.ts , self.ts) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(1) + sql = "select %s from regular_table_3 " % interp_select + sql += "range('%s' , '%s') EVERY(1s);" % (self.ts , self.ts) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(1) + + sql = "select %s from regular_table_1 " % interp_select + sql += "range('%s' , '%s') EVERY(1s);" % (self.ts + 10000 , self.ts + 25000) + datacheck = self.regular1_checkall_0_NEXT(sql) tdSql.checkRows(7) - tdSql.checkData(1,1,1.47885) - tdSql.query("select interp(pav) from ap1 where ts>= '2021-07-25 02:19:54' and ts <= '2021-07-25 02:20:00' every(1000a) FILL (LINEAR)") + sql = "select %s from regular_table_2 " % interp_select + sql += "range('%s' , '%s') EVERY(1s);" % (self.ts + 10000 , self.ts + 25000) + datacheck = self.regular2_checkall_0_NEXT(sql) tdSql.checkRows(7) - - # check desc order - tdSql.error("select interp(pav) from ap1 where ts = '2021-07-25 02:19:54' FILL (PREV) order by ts desc") - tdSql.query("select interp(pav) from ap1 where ts = '2021-07-25 02:19:54' FILL (NEXT) order by ts desc") - tdSql.checkRows(0) - tdSql.query("select interp(pav) from ap1 where ts = '2021-07-25 02:19:54' FILL (LINEAR) order by ts desc") - tdSql.checkRows(0) - tdSql.query("select interp(pav) from ap1 where ts> '2021-07-25 02:19:54' and ts<'2021-07-25 02:20:00' every(1000a) FILL (LINEAR) order by ts desc") - tdSql.checkRows(6) - tdSql.query("select interp(pav) from ap1 where ts>= '2021-07-25 02:19:54' and ts<'2021-07-25 02:20:00' every(1000a) FILL (NEXT) order by ts desc") - tdSql.checkRows(6) - tdSql.checkData(0,1,4.60900) - tdSql.error("select interp(pav) from ap1 where ts> '2021-07-25 02:19:54' and ts <= '2021-07-25 02:20:00' every(1000a) FILL (PREV) order by ts desc") - tdSql.query("select interp(pav) from ap1 where ts>= '2021-07-25 02:19:54' and ts <= '2021-07-25 02:20:00' every(1000a) FILL (LINEAR) order by ts desc") + sql = "select %s from regular_table_3 " % interp_select + sql += "range('%s' , '%s') EVERY(1s);" % (self.ts + 10000 , self.ts + 25000) + datacheck = self.regular3_checkall_0_NEXT(sql) tdSql.checkRows(7) - # check exception - tdSql.error("select interp(*) from ap1") - tdSql.error("select interp(*) from ap1 FILL(NEXT)") - tdSql.error("select interp(*) from ap1 ts >= '2021-07-25 02:19:54' FILL(NEXT)") - tdSql.error("select interp(*) from ap1 ts <= '2021-07-25 02:19:54' FILL(NEXT)") - tdSql.error("select interp(*) from ap1 where ts >'2021-07-25 02:19:59.938' and ts < now every(1s) fill(next)") - - # test case for https://jira.taosdata.com:18080/browse/TS-241 - tdSql.execute("create database test minrows 10") - tdSql.execute("use test") - tdSql.execute("create table st(ts timestamp, c1 int) tags(id int)") - tdSql.execute("create table t1 using st tags(1)") - - for i in range(10): - for j in range(10): - tdSql.execute("insert into t1 values(%d, %d)" % (self.ts + i * 3600000 + j, j)) - tdSql.query("select interp(c1) from st where ts >= '2018-09-16 20:00:00.000' and ts <= '2018-09-17 06:00:00.000' every(1h) fill(linear)") - if i==0: - tdSql.checkRows(0) - else: - tdSql.checkRows(11) - - tdDnodes.stop(1) - tdDnodes.start(1) - tdSql.query("select interp(c1) from st where ts >= '2018-09-16 20:00:00.000' and ts <= '2018-09-17 06:00:00.000' every(1h) fill(linear)") - if i==0: - tdSql.checkRows(0) - else: - tdSql.checkRows(11) + sql = "select %s from regular_table_1 " % interp_select + sql += "range('%s' , '%s') EVERY(1s);" % (self.ts + 150000 , self.ts + 200000) + datacheck = self.result_0(sql) + sql = "select %s from regular_table_2 " % interp_select + sql += "range('%s' , '%s') EVERY(1s);" % (self.ts + 150000 , self.ts + 200000) + datacheck = self.result_0(sql) + sql = "select %s from regular_table_3 " % interp_select + sql += "range('%s' , '%s') EVERY(1s);" % (self.ts + 150000 , self.ts + 200000) + datacheck = self.result_0(sql) + + # EVERY(2s) + sql = "select %s from regular_table_1 EVERY(2s);" %interp_select + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(14) + sql = "select %s from regular_table_2 EVERY(2s);" %interp_select + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(14) + sql = "select %s from regular_table_3 EVERY(2s);" %interp_select + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(14) + + sql = "select %s from regular_table_1 " % interp_select + sql += "range('%s' , '%s') EVERY(2s);" % (self.ts - 10000 , self.ts + 100000) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(14) + sql = "select %s from regular_table_2 " % interp_select + sql += "range('%s' , '%s') EVERY(2s);" % (self.ts - 10000 , self.ts + 100000) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(14) + sql = "select %s from regular_table_3 " % interp_select + sql += "range('%s' , '%s') EVERY(2s);" % (self.ts - 10000 , self.ts + 100000) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(14) + + sql = "select %s from regular_table_1 " % interp_select + sql += "range('%s' , '%s') EVERY(2s);" % (self.ts - 10000 , self.ts - 9900) + datacheck = self.result_0(sql) + sql = "select %s from regular_table_2 " % interp_select + sql += "range('%s' , '%s') EVERY(2s);" % (self.ts - 10000 , self.ts - 9900) + datacheck = self.result_0(sql) + sql = "select %s from regular_table_3 " % interp_select + sql += "range('%s' , '%s') EVERY(2s);" % (self.ts - 10000 , self.ts - 9900) + datacheck = self.result_0(sql) + + sql = "select %s from regular_table_1 " % interp_select + sql += "range('%s' , '%s') EVERY(2s);" % (self.ts , self.ts) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(1) + sql = "select %s from regular_table_2 " % interp_select + sql += "range('%s' , '%s') EVERY(2s);" % (self.ts , self.ts) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(1) + sql = "select %s from regular_table_3 " % interp_select + sql += "range('%s' , '%s') EVERY(2s);" % (self.ts , self.ts) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(1) + + sql = "select %s from regular_table_1 " % interp_select + sql += "range('%s' , '%s') EVERY(2s);" % (self.ts + 10000 , self.ts + 25000) + datacheck = self.regular1_checkall_0_NEXT(sql) + tdSql.checkRows(5) + sql = "select %s from regular_table_2 " % interp_select + sql += "range('%s' , '%s') EVERY(2s);" % (self.ts + 10000 , self.ts + 25000) + datacheck = self.regular2_checkall_0_NEXT(sql) + tdSql.checkRows(5) + sql = "select %s from regular_table_3 " % interp_select + sql += "range('%s' , '%s') EVERY(2s);" % (self.ts + 10000 , self.ts + 25000) + datacheck = self.regular3_checkall_0_NEXT(sql) + tdSql.checkRows(5) + + sql = "select %s from regular_table_1 " % interp_select + sql += "range('%s' , '%s') EVERY(2s);" % (self.ts + 150000 , self.ts + 200000) + datacheck = self.result_0(sql) + sql = "select %s from regular_table_2 " % interp_select + sql += "range('%s' , '%s') EVERY(2s);" % (self.ts + 150000 , self.ts + 200000) + datacheck = self.result_0(sql) + sql = "select %s from regular_table_3 " % interp_select + sql += "range('%s' , '%s') EVERY(2s);" % (self.ts + 150000 , self.ts + 200000) + datacheck = self.result_0(sql) + + # EVERY(5s) + sql = "select %s from regular_table_1 EVERY(5s);" %interp_select + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(11) + sql = "select %s from regular_table_2 EVERY(5s);" %interp_select + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(11) + sql = "select %s from regular_table_3 EVERY(5s);" %interp_select + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(11) + + # EVERY(100s) + sql = "select %s from regular_table_1 EVERY(100s);" %interp_select + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(1) + sql = "select %s from regular_table_2 EVERY(100s);" %interp_select + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(1) + sql = "select %s from regular_table_3 EVERY(100s);" %interp_select + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(1) + + + # error + tdSql.error("select interp(*) from regular_table_1") + tdSql.error("select interp(*) from regular_table_2 FILL(NEXT)") + sql = "select interp(*) from regular_table_3 where ts >= '%s' FILL(NULL);" % self.ts + tdSql.error(sql) + sql = "select interp(*) from regular_table_1 where ts <= '%s' FILL(LINEAR);" % self.ts + tdSql.error(sql) + sql = "select interp(*) from regular_table_2 where ts > '%s' and ts < now every(1s) fill(PREV);" % self.ts + tdSql.error(sql) + + sql = "select %s from regular_table_1 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL (LINEAR);" % (self.ts + 150000 , self.ts + 100000) + tdSql.error(sql) + sql = "select %s from regular_table_2 " % interp_select + sql += "range('%s' , '%s') EVERY(2s) FILL (PREV);" % (self.ts + 150000 , self.ts - 100000) + tdSql.error(sql) + sql = "select %s from regular_table_3 " % interp_select + sql += "range('%s' , '%s') EVERY(5s) FILL (NEXT);" % (self.ts - 150000 , self.ts - 200000) + tdSql.error(sql) + + sql = "select %s from regular_table_1 " % interp_select + sql += "range('%s' , '%s') EVERY(10s) FILL (NULL);" % (self.ts + 150000 , self.ts + 100000) + tdSql.error(sql) + sql = "select %s from regular_table_2 " % interp_select + sql += "range('%s' , '%s') EVERY(60s) FILL (VALUE,100);" % (self.ts + 150000 , self.ts - 100000) + tdSql.error(sql) + sql = "select %s from regular_table_3 " % interp_select + sql += "range('%s' , '%s') EVERY(120s) FILL (LINEAR) ORDER BY ts DESC;" % (self.ts - 150000 , self.ts - 200000) + tdSql.error(sql) + + # Nested Query + sql = "select * from (select %s from regular_table_1) ;" % interp_select + datacheck = self.regular1_checkall_0(sql) + sql = "select * from (select %s from regular_table_2) ;" % interp_select + datacheck = self.regular2_checkall_0(sql) + sql = "select * from (select %s from regular_table_3) ;" % interp_select + datacheck = self.regular3_checkall_0(sql) + + sql = "select %s from (select * from regular_table_1) ;" % interp_select + datacheck = self.regular1_checkall_0(sql) + sql = "select %s from (select * from regular_table_2) ;" % interp_select + datacheck = self.regular2_checkall_0(sql) + sql = "select %s from (select * from regular_table_3) ;" % interp_select + datacheck = self.regular3_checkall_0(sql) + + # Nested Query + where + range + FILL(LINEAR) + EVERY( s) (1) + sql = "select * from (select %s from regular_table_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR));" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(11) + sql = "select * from (select %s from regular_table_2 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR));" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(11) + sql = "select * from (select %s from regular_table_3 " % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR));" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(11) + + sql = "select * from (select %s from regular_table_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR));" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + datacheck = self.result_0(sql) + sql = "select * from (select %s from regular_table_2 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR));" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + datacheck = self.result_0(sql) + sql = "select * from (select %s from regular_table_3 " % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR));" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + datacheck = self.result_0(sql) + + sql = "select * from (select %s from regular_table_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR));" % (self.ts , self.ts + 10000 , self.ts , self.ts) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(1) + sql = "select * from (select %s from regular_table_2 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR));" % (self.ts , self.ts + 10000 , self.ts , self.ts) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(1) + sql = "select * from (select %s from regular_table_3 " % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR));" % (self.ts , self.ts + 10000 , self.ts , self.ts) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(1) + + sql = "select * from (select %s from regular_table_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR));" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(11) + sql = "select * from (select %s from regular_table_2 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR));" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(11) + sql = "select * from (select %s from regular_table_3 " % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR));" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(11) + + sql = "select * from (select %s from regular_table_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR) ORDER BY ts DESC);" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0_NEXT(sql) + tdSql.checkRows(11) + sql = "select * from (select %s from regular_table_2 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR) ORDER BY ts DESC);" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular2_checkall_0_NEXT(sql) + tdSql.checkRows(11) + sql = "select * from (select %s from regular_table_3 " % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR) ORDER BY ts DESC);" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular3_checkall_0_NEXT(sql) + tdSql.checkRows(11) + + sql = "select * from (select %s from regular_table_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR));" % (self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + datacheck = self.regular1_checkall_0_LINEAR(sql) + tdSql.checkRows(2) + sql = "select * from (select %s from regular_table_2 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR));" % (self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + datacheck = self.regular2_checkall_0_LINEAR(sql) + tdSql.checkRows(2) + sql = "select * from (select %s from regular_table_3 " % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR));" % (self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + datacheck = self.regular3_checkall_0_LINEAR(sql) + tdSql.checkRows(2) + + sql = "select * from (select %s from regular_table_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR));" % (self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + datacheck = self.result_0(sql) + sql = "select * from (select %s from regular_table_2 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR));" % (self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + datacheck = self.result_0(sql) + sql = "select * from (select %s from regular_table_3 " % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR));" % (self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + datacheck = self.result_0(sql) + + # Nested Query + where + range + FILL(LINEAR) + EVERY( s)(2) + sql = "select %s from (select * from regular_table_1 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(11) + sql = "select %s from (select * from regular_table_2 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(11) + sql = "select %s from (select * from regular_table_3 )" % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(11) + + sql = "select %s from (select * from regular_table_1 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + datacheck = self.result_0(sql) + sql = "select %s from (select * from regular_table_2 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + datacheck = self.result_0(sql) + sql = "select %s from (select * from regular_table_3 )" % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + datacheck = self.result_0(sql) + + sql = "select %s from (select * from regular_table_1 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR);" % (self.ts , self.ts + 10000 , self.ts , self.ts) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(1) + sql = "select %s from (select * from regular_table_2 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR);" % (self.ts , self.ts + 10000 , self.ts , self.ts) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(1) + sql = "select %s from (select * from regular_table_3 )" % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR);" % (self.ts , self.ts + 10000 , self.ts , self.ts) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(1) + + sql = "select %s from (select * from regular_table_1 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR);" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(11) + sql = "select %s from (select * from regular_table_2 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR);" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(11) + sql = "select %s from (select * from regular_table_3 )" % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR);" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(11) + + sql = "select %s from (select * from regular_table_1 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR);" % (self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + datacheck = self.regular1_checkall_0_LINEAR(sql) + tdSql.checkRows(2) + sql = "select %s from (select * from regular_table_2 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR);" % (self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + datacheck = self.regular2_checkall_0_LINEAR(sql) + tdSql.checkRows(2) + sql = "select %s from (select * from regular_table_3 )" % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR);" % (self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + datacheck = self.regular3_checkall_0_LINEAR(sql) + tdSql.checkRows(2) + + sql = "select %s from (select * from regular_table_1 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR);" % (self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + datacheck = self.result_0(sql) + sql = "select %s from (select * from regular_table_2 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR);" % (self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + datacheck = self.result_0(sql) + sql = "select %s from (select * from regular_table_3 )" % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR);" % (self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + datacheck = self.result_0(sql) + + # Nested Query + where + range + FILL(LINEAR) + EVERY( s)(3) + sql = "select * from (select %s from regular_table_1 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR)) z1," % (interp_select , self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + sql += "(select %s from regular_table_2 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR)) z2 where z1.ts=z2.ts ;" % (interp_select , self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(11) + + sql = "select * from (select %s from regular_table_2 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR)) z1," % (interp_select , self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + sql += "(select %s from regular_table_3 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR)) z2 where z1.ts=z2.ts ;" % (interp_select , self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + datacheck = self.result_0(sql) + + sql = "select * from (select %s from regular_table_3 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR)) z1," % (interp_select , self.ts , self.ts + 10000 , self.ts , self.ts) + sql += "(select %s from regular_table_1 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR)) z2 where z1.ts=z2.ts ;" % (interp_select , self.ts , self.ts + 10000 , self.ts , self.ts) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(1) + + sql = "select * from (select %s from regular_table_1 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR)) z1," % (interp_select , self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + sql += "(select %s from regular_table_2 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR)) z2 where z1.ts=z2.ts ;" % (interp_select , self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(11) + + sql = "select * from (select %s from regular_table_2 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR)) z1," % (interp_select , self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + sql += "(select %s from regular_table_3 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR)) z2 where z1.ts=z2.ts ;" % (interp_select , self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + datacheck = self.regular2_checkall_0_LINEAR(sql) + tdSql.checkRows(2) + + sql = "select * from (select %s from regular_table_3 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR)) z1," % (interp_select , self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + sql += "(select %s from regular_table_1 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR)) z2 where z1.ts=z2.ts ;" % (interp_select , self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + datacheck = self.result_0(sql) + + # Nested Query + where + range + FILL(NEXT) + EVERY( s) (1) + sql = "select * from (select %s from regular_table_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT));" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(21) + sql = "select * from (select %s from regular_table_2 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT));" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(21) + sql = "select * from (select %s from regular_table_3 " % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT));" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(21) + + sql = "select * from (select %s from regular_table_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT));" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(1) + sql = "select * from (select %s from regular_table_2 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT));" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(1) + sql = "select * from (select %s from regular_table_3 " % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT));" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(1) + + sql = "select * from (select %s from regular_table_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT));" % (self.ts , self.ts + 10000 , self.ts , self.ts) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(1) + sql = "select * from (select %s from regular_table_2 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT));" % (self.ts , self.ts + 10000 , self.ts , self.ts) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(1) + sql = "select * from (select %s from regular_table_3 " % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT));" % (self.ts , self.ts + 10000 , self.ts , self.ts) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(1) + + sql = "select * from (select %s from regular_table_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT));" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(11) + sql = "select * from (select %s from regular_table_2 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT));" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(11) + sql = "select * from (select %s from regular_table_3 " % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT));" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(11) + + sql = "select * from (select %s from regular_table_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT) ORDER BY ts DESC);" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0_NEXT(sql) + tdSql.checkRows(11) + sql = "select * from (select %s from regular_table_2 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT) ORDER BY ts DESC);" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular2_checkall_0_NEXT(sql) + tdSql.checkRows(11) + sql = "select * from (select %s from regular_table_3 " % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT) ORDER BY ts DESC);" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular3_checkall_0_NEXT(sql) + tdSql.checkRows(11) + + sql = "select * from (select %s from regular_table_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT));" % (self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + datacheck = self.regular1_checkall_0_NEXT(sql) + tdSql.checkRows(2) + sql = "select * from (select %s from regular_table_2 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT));" % (self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + datacheck = self.regular2_checkall_0_NEXT(sql) + tdSql.checkRows(2) + sql = "select * from (select %s from regular_table_3 " % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT));" % (self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + datacheck = self.regular3_checkall_0_NEXT(sql) + tdSql.checkRows(2) + + sql = "select * from (select %s from regular_table_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT));" % (self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + datacheck = self.result_0(sql) + sql = "select * from (select %s from regular_table_2 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT));" % (self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + datacheck = self.result_0(sql) + sql = "select * from (select %s from regular_table_3 " % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT));" % (self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + datacheck = self.result_0(sql) + + # Nested Query + where + range + FILL(NEXT) + EVERY( s)(2) + sql = "select %s from (select * from regular_table_1 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(21) + sql = "select %s from (select * from regular_table_2 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(21) + sql = "select %s from (select * from regular_table_3 )" % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(21) + + sql = "select %s from (select * from regular_table_1 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(1) + sql = "select %s from (select * from regular_table_2 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(1) + sql = "select %s from (select * from regular_table_3 )" % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(1) + + sql = "select %s from (select * from regular_table_1 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT);" % (self.ts , self.ts + 10000 , self.ts , self.ts) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(1) + sql = "select %s from (select * from regular_table_2 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT);" % (self.ts , self.ts + 10000 , self.ts , self.ts) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(1) + sql = "select %s from (select * from regular_table_3 )" % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT);" % (self.ts , self.ts + 10000 , self.ts , self.ts) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(1) + + sql = "select %s from (select * from regular_table_1 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT);" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(11) + sql = "select %s from (select * from regular_table_2 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT);" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(11) + sql = "select %s from (select * from regular_table_3 )" % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT);" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(11) + + sql = "select %s from (select * from regular_table_1 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT);" % (self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + datacheck = self.regular1_checkall_0_NEXT(sql) + tdSql.checkRows(2) + sql = "select %s from (select * from regular_table_2 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT);" % (self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + datacheck = self.regular2_checkall_0_NEXT(sql) + tdSql.checkRows(2) + sql = "select %s from (select * from regular_table_3 )" % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT);" % (self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + datacheck = self.regular3_checkall_0_NEXT(sql) + tdSql.checkRows(2) + + sql = "select %s from (select * from regular_table_1 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT);" % (self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + datacheck = self.result_0(sql) + sql = "select %s from (select * from regular_table_2 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT);" % (self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + datacheck = self.result_0(sql) + sql = "select %s from (select * from regular_table_3 )" % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT);" % (self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + datacheck = self.result_0(sql) + + # Nested Query + where + range + FILL(NEXT) + EVERY( s)(3) + sql = "select * from (select %s from regular_table_1 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT)) z1," % (interp_select , self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + sql += "(select %s from regular_table_2 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT)) z2 where z1.ts=z2.ts ;" % (interp_select , self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(21) + + sql = "select * from (select %s from regular_table_2 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT)) z1," % (interp_select , self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + sql += "(select %s from regular_table_3 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT)) z2 where z1.ts=z2.ts ;" % (interp_select , self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(1) + + sql = "select * from (select %s from regular_table_3 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT)) z1," % (interp_select , self.ts , self.ts + 10000 , self.ts , self.ts) + sql += "(select %s from regular_table_1 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT)) z2 where z1.ts=z2.ts ;" % (interp_select , self.ts , self.ts + 10000 , self.ts , self.ts) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(1) + + sql = "select * from (select %s from regular_table_1 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT)) z1," % (interp_select , self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + sql += "(select %s from regular_table_2 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT)) z2 where z1.ts=z2.ts ;" % (interp_select , self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(11) + + sql = "select * from (select %s from regular_table_2 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT)) z1," % (interp_select , self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + sql += "(select %s from regular_table_3 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT)) z2 where z1.ts=z2.ts ;" % (interp_select , self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + datacheck = self.regular2_checkall_0_NEXT(sql) + tdSql.checkRows(2) + + sql = "select * from (select %s from regular_table_3 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT)) z1," % (interp_select , self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + sql += "(select %s from regular_table_1 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT)) z2 where z1.ts=z2.ts ;" % (interp_select , self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + datacheck = self.result_0(sql) + + # Nested Query + where + range + FILL(PREV) + EVERY( s) (1) + sql = "select * from (select %s from regular_table_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV));" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(101) + sql = "select * from (select %s from regular_table_2 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV));" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(101) + sql = "select * from (select %s from regular_table_3 " % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(PREV));" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(101) + + sql = "select * from (select %s from regular_table_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV));" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + datacheck = self.result_0(sql) + sql = "select * from (select %s from regular_table_2 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV));" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + datacheck = self.result_0(sql) + sql = "select * from (select %s from regular_table_3 " % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(PREV));" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + datacheck = self.result_0(sql) + + sql = "select * from (select %s from regular_table_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV));" % (self.ts , self.ts + 10000 , self.ts , self.ts) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(1) + sql = "select * from (select %s from regular_table_2 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV));" % (self.ts , self.ts + 10000 , self.ts , self.ts) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(1) + sql = "select * from (select %s from regular_table_3 " % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(PREV));" % (self.ts , self.ts + 10000 , self.ts , self.ts) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(1) + + sql = "select * from (select %s from regular_table_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV));" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(201) + sql = "select * from (select %s from regular_table_2 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV));" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(201) + sql = "select * from (select %s from regular_table_3 " % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(PREV));" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(201) + + sql = "select * from (select %s from regular_table_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV) ORDER BY ts DESC);" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0_NEXT(sql) + tdSql.checkRows(201) + sql = "select * from (select %s from regular_table_2 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV) ORDER BY ts DESC);" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular2_checkall_0_NEXT(sql) + tdSql.checkRows(201) + sql = "select * from (select %s from regular_table_3 " % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(PREV) ORDER BY ts DESC);" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular3_checkall_0_NEXT(sql) + tdSql.checkRows(201) + + sql = "select * from (select %s from regular_table_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV));" % (self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(2) + sql = "select * from (select %s from regular_table_2 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV));" % (self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(2) + sql = "select * from (select %s from regular_table_3 " % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(PREV));" % (self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(2) + + sql = "select * from (select %s from regular_table_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV));" % (self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + datacheck = self.regular1_checkall_0_NEXT(sql) + tdSql.checkRows(51) + sql = "select * from (select %s from regular_table_2 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV));" % (self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + datacheck = self.regular2_checkall_0_NEXT(sql) + tdSql.checkRows(51) + sql = "select * from (select %s from regular_table_3 " % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(PREV));" % (self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + datacheck = self.regular3_checkall_0_NEXT(sql) + tdSql.checkRows(51) + + # Nested Query + where + range + FILL(PREV) + EVERY( s)(2) + sql = "select %s from (select * from regular_table_1 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(101) + sql = "select %s from (select * from regular_table_2 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(101) + sql = "select %s from (select * from regular_table_3 )" % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(PREV);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(101) + + sql = "select %s from (select * from regular_table_1 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + datacheck = self.result_0(sql) + sql = "select %s from (select * from regular_table_2 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + datacheck = self.result_0(sql) + sql = "select %s from (select * from regular_table_3 )" % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(PREV);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + datacheck = self.result_0(sql) + + sql = "select %s from (select * from regular_table_1 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV);" % (self.ts , self.ts + 10000 , self.ts , self.ts) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(1) + sql = "select %s from (select * from regular_table_2 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV);" % (self.ts , self.ts + 10000 , self.ts , self.ts) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(1) + sql = "select %s from (select * from regular_table_3 )" % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(PREV);" % (self.ts , self.ts + 10000 , self.ts , self.ts) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(1) + + sql = "select %s from (select * from regular_table_1 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV);" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(201) + sql = "select %s from (select * from regular_table_2 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV);" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(201) + sql = "select %s from (select * from regular_table_3 )" % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(PREV);" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(201) + + sql = "select %s from (select * from regular_table_1 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV);" % (self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(2) + sql = "select %s from (select * from regular_table_2 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV);" % (self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(2) + sql = "select %s from (select * from regular_table_3 )" % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(PREV);" % (self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(2) + + sql = "select %s from (select * from regular_table_1 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV);" % (self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + datacheck = self.regular1_checkall_0_NEXT(sql) + tdSql.checkRows(51) + sql = "select %s from (select * from regular_table_2 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV);" % (self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + datacheck = self.regular2_checkall_0_NEXT(sql) + tdSql.checkRows(51) + sql = "select %s from (select * from regular_table_3 )" % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(PREV);" % (self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + datacheck = self.regular3_checkall_0_NEXT(sql) + tdSql.checkRows(51) + + # Nested Query + where + range + FILL(PREV) + EVERY( s)(3) + sql = "select * from (select %s from regular_table_1 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV)) z1," % (interp_select , self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + sql += "(select %s from regular_table_2 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV)) z2 where z1.ts=z2.ts ;" % (interp_select , self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(101) + + sql = "select * from (select %s from regular_table_2 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV)) z1," % (interp_select , self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + sql += "(select %s from regular_table_3 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV)) z2 where z1.ts=z2.ts ;" % (interp_select , self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + datacheck = self.result_0(sql) + + sql = "select * from (select %s from regular_table_3 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV)) z1," % (interp_select , self.ts , self.ts + 10000 , self.ts , self.ts) + sql += "(select %s from regular_table_1 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV)) z2 where z1.ts=z2.ts ;" % (interp_select , self.ts , self.ts + 10000 , self.ts , self.ts) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(1) + + sql = "select * from (select %s from regular_table_1 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV)) z1," % (interp_select , self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + sql += "(select %s from regular_table_2 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV)) z2 where z1.ts=z2.ts ;" % (interp_select , self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(201) + + sql = "select * from (select %s from regular_table_2 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV)) z1," % (interp_select , self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + sql += "(select %s from regular_table_3 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV)) z2 where z1.ts=z2.ts ;" % (interp_select , self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(2) + + sql = "select * from (select %s from regular_table_3 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV)) z1," % (interp_select , self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + sql += "(select %s from regular_table_1 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV)) z2 where z1.ts=z2.ts ;" % (interp_select , self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + datacheck = self.regular3_checkall_0_NEXT(sql) + tdSql.checkRows(51) + + # Nested Query + where + range + FILL(VALUE, 100) + EVERY( s) (1) + sql = "select * from (select %s from regular_table_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100));" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(111) + sql = "select * from (select %s from regular_table_2 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100));" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(111) + sql = "select * from (select %s from regular_table_3 " % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100));" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(111) + + sql = "select * from (select %s from regular_table_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100));" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(1) + sql = "select * from (select %s from regular_table_2 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100));" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(1) + sql = "select * from (select %s from regular_table_3 " % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100));" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(1) + + sql = "select * from (select %s from regular_table_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100));" % (self.ts , self.ts + 10000 , self.ts , self.ts) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(1) + sql = "select * from (select %s from regular_table_2 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100));" % (self.ts , self.ts + 10000 , self.ts , self.ts) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(1) + sql = "select * from (select %s from regular_table_3 " % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100));" % (self.ts , self.ts + 10000 , self.ts , self.ts) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(1) + + sql = "select * from (select %s from regular_table_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100));" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(201) + sql = "select * from (select %s from regular_table_2 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100));" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(201) + sql = "select * from (select %s from regular_table_3 " % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100));" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(201) + + sql = "select * from (select %s from regular_table_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100) ORDER BY ts DESC);" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(201) + sql = "select * from (select %s from regular_table_2 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100) ORDER BY ts DESC);" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(201) + sql = "select * from (select %s from regular_table_3 " % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100) ORDER BY ts DESC);" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(201) + + sql = "select * from (select %s from regular_table_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100));" % (self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(2) + sql = "select * from (select %s from regular_table_2 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100));" % (self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(2) + sql = "select * from (select %s from regular_table_3 " % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100));" % (self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(2) + + sql = "select * from (select %s from regular_table_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100));" % (self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(51) + sql = "select * from (select %s from regular_table_2 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100));" % (self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(51) + sql = "select * from (select %s from regular_table_3 " % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100));" % (self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(51) + + # Nested Query + where + range + FILL(VALUE, 100) + EVERY( s)(2) + sql = "select %s from (select * from regular_table_1 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(111) + sql = "select %s from (select * from regular_table_2 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(111) + sql = "select %s from (select * from regular_table_3 )" % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(111) + + sql = "select %s from (select * from regular_table_1 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(1) + sql = "select %s from (select * from regular_table_2 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(1) + sql = "select %s from (select * from regular_table_3 )" % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(1) + + sql = "select %s from (select * from regular_table_1 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100);" % (self.ts , self.ts + 10000 , self.ts , self.ts) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(1) + sql = "select %s from (select * from regular_table_2 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100);" % (self.ts , self.ts + 10000 , self.ts , self.ts) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(1) + sql = "select %s from (select * from regular_table_3 )" % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100);" % (self.ts , self.ts + 10000 , self.ts , self.ts) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(1) + + sql = "select %s from (select * from regular_table_1 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100);" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(201) + sql = "select %s from (select * from regular_table_2 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100);" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(201) + sql = "select %s from (select * from regular_table_3 )" % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100);" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(201) + + sql = "select %s from (select * from regular_table_1 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100);" % (self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(2) + sql = "select %s from (select * from regular_table_2 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100);" % (self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(2) + sql = "select %s from (select * from regular_table_3 )" % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100);" % (self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(2) + + sql = "select %s from (select * from regular_table_1 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100);" % (self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(51) + sql = "select %s from (select * from regular_table_2 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100);" % (self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(51) + sql = "select %s from (select * from regular_table_3 )" % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100);" % (self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(51) + + # Nested Query + where + range + FILL(VALUE, 100) + EVERY( s)(3) + sql = "select * from (select %s from regular_table_1 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100)) z1," % (interp_select , self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + sql += "(select %s from regular_table_2 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100)) z2 where z1.ts=z2.ts ;" % (interp_select , self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(111) + + sql = "select * from (select %s from regular_table_2 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100)) z1," % (interp_select , self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + sql += "(select %s from regular_table_3 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100)) z2 where z1.ts=z2.ts ;" % (interp_select , self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(1) + + sql = "select * from (select %s from regular_table_3 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100)) z1," % (interp_select , self.ts , self.ts + 10000 , self.ts , self.ts) + sql += "(select %s from regular_table_1 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100)) z2 where z1.ts=z2.ts ;" % (interp_select , self.ts , self.ts + 10000 , self.ts , self.ts) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(1) + + sql = "select * from (select %s from regular_table_1 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100)) z1," % (interp_select , self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + sql += "(select %s from regular_table_2 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100)) z2 where z1.ts=z2.ts ;" % (interp_select , self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(201) + + sql = "select * from (select %s from regular_table_2 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100)) z1," % (interp_select , self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + sql += "(select %s from regular_table_3 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100)) z2 where z1.ts=z2.ts ;" % (interp_select , self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(2) + + sql = "select * from (select %s from regular_table_3 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100)) z1," % (interp_select , self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + sql += "(select %s from regular_table_1 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100)) z2 where z1.ts=z2.ts ;" % (interp_select , self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(51) + + # Nested Query + where + range + FILL(NULL) + EVERY( s) (1) + sql = "select * from (select %s from regular_table_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL));" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(111) + sql = "select * from (select %s from regular_table_2 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL));" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(111) + sql = "select * from (select %s from regular_table_3 " % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(NULL));" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(111) + + sql = "select * from (select %s from regular_table_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL));" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(1) + sql = "select * from (select %s from regular_table_2 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL));" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(1) + sql = "select * from (select %s from regular_table_3 " % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(NULL));" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(1) + + sql = "select * from (select %s from regular_table_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL));" % (self.ts , self.ts + 10000 , self.ts , self.ts) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(1) + sql = "select * from (select %s from regular_table_2 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL));" % (self.ts , self.ts + 10000 , self.ts , self.ts) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(1) + sql = "select * from (select %s from regular_table_3 " % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(NULL));" % (self.ts , self.ts + 10000 , self.ts , self.ts) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(1) + + sql = "select * from (select %s from regular_table_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL));" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(201) + sql = "select * from (select %s from regular_table_2 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL));" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(201) + sql = "select * from (select %s from regular_table_3 " % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(NULL));" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(201) + + sql = "select * from (select %s from regular_table_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL) ORDER BY ts DESC);" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(201) + sql = "select * from (select %s from regular_table_2 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL) ORDER BY ts DESC);" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(201) + sql = "select * from (select %s from regular_table_3 " % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(NULL) ORDER BY ts DESC);" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(201) + + sql = "select * from (select %s from regular_table_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL));" % (self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(2) + sql = "select * from (select %s from regular_table_2 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL));" % (self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(2) + sql = "select * from (select %s from regular_table_3 " % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(NULL));" % (self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(2) + + sql = "select * from (select %s from regular_table_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL));" % (self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(51) + sql = "select * from (select %s from regular_table_2 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL));" % (self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(51) + sql = "select * from (select %s from regular_table_3 " % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(NULL));" % (self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(51) + + # Nested Query + where + range + FILL(NULL) + EVERY( s)(2) + sql = "select %s from (select * from regular_table_1 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(111) + sql = "select %s from (select * from regular_table_2 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(111) + sql = "select %s from (select * from regular_table_3 )" % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(NULL);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(111) + + sql = "select %s from (select * from regular_table_1 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(1) + sql = "select %s from (select * from regular_table_2 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(1) + sql = "select %s from (select * from regular_table_3 )" % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(NULL);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(1) + + sql = "select %s from (select * from regular_table_1 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL);" % (self.ts , self.ts + 10000 , self.ts , self.ts) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(1) + sql = "select %s from (select * from regular_table_2 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL);" % (self.ts , self.ts + 10000 , self.ts , self.ts) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(1) + sql = "select %s from (select * from regular_table_3 )" % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(NULL);" % (self.ts , self.ts + 10000 , self.ts , self.ts) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(1) + + sql = "select %s from (select * from regular_table_1 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL);" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(201) + sql = "select %s from (select * from regular_table_2 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL);" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(201) + sql = "select %s from (select * from regular_table_3 )" % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(NULL);" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(201) + + sql = "select %s from (select * from regular_table_1 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL);" % (self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(2) + sql = "select %s from (select * from regular_table_2 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL);" % (self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(2) + sql = "select %s from (select * from regular_table_3 )" % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(NULL);" % (self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(2) + + sql = "select %s from (select * from regular_table_1 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL);" % (self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(51) + sql = "select %s from (select * from regular_table_2 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL);" % (self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(51) + sql = "select %s from (select * from regular_table_3 )" % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(NULL);" % (self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(51) + + # Nested Query + where + range + FILL(NULL) + EVERY( s)(3) + sql = "select * from (select %s from regular_table_1 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL)) z1," % (interp_select , self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + sql += "(select %s from regular_table_2 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL)) z2 where z1.ts=z2.ts ;" % (interp_select , self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(111) + + sql = "select * from (select %s from regular_table_2 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL)) z1," % (interp_select , self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + sql += "(select %s from regular_table_3 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL)) z2 where z1.ts=z2.ts ;" % (interp_select , self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(1) + + sql = "select * from (select %s from regular_table_3 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL)) z1," % (interp_select , self.ts , self.ts + 10000 , self.ts , self.ts) + sql += "(select %s from regular_table_1 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL)) z2 where z1.ts=z2.ts ;" % (interp_select , self.ts , self.ts + 10000 , self.ts , self.ts) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(1) + + sql = "select * from (select %s from regular_table_1 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL)) z1," % (interp_select , self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + sql += "(select %s from regular_table_2 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL)) z2 where z1.ts=z2.ts ;" % (interp_select , self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(201) + + sql = "select * from (select %s from regular_table_2 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL)) z1," % (interp_select , self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + sql += "(select %s from regular_table_3 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL)) z2 where z1.ts=z2.ts ;" % (interp_select , self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(2) + + sql = "select * from (select %s from regular_table_3 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL)) z1," % (interp_select , self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + sql += "(select %s from regular_table_1 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL)) z2 where z1.ts=z2.ts ;" % (interp_select , self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(51) + + print("==============step2, super table: child table==============") + + dcDB = self.dropandcreateDB() + + dcDB = self.dropandcreateDB_null() + + dcRestart = self.restartDnodes() + + interp_select = 'interp(q_int),interp(q_bigint),interp(q_smallint),interp(q_tinyint),interp(q_float),interp(q_double),\ + interp(q_int_null),interp(q_bigint_null),interp(q_smallint_null),interp(q_tinyint_null),interp(q_float_null),interp(q_double_null),\ + interp(q_int,q_bigint,q_smallint,q_tinyint,q_float,q_double),interp(q_int_null,q_bigint_null,q_smallint_null,q_tinyint_null,q_float_null,q_double_null),loc' + + sql = "select * from table_1 ;" + datacheck = self.regular1_checkall_0_base(sql) + tdSql.checkRows(19) + datacheck = self.regular1_checkall_20_base(sql) + + sql = "select %s from table_1 ;" % interp_select + datacheck = self.regular1_checkall_0(sql) + sql = "select %s from table_2 ;" % interp_select + datacheck = self.regular2_checkall_0(sql) + sql = "select %s from table_3 ;" % interp_select + datacheck = self.regular3_checkall_0(sql) + + sql = "select %s from table_1 ORDER BY ts DESC;" % interp_select + datacheck = self.regular1_checkall_0(sql) + sql = "select %s from table_2 ORDER BY ts DESC;" % interp_select + datacheck = self.regular2_checkall_0(sql) + sql = "select %s from table_3 ORDER BY ts DESC;" % interp_select + datacheck = self.regular3_checkall_0(sql) + + sql = "select %s from table_1 where " % interp_select + sql += "ts > %s ;" % (self.ts - 10) + datacheck = self.regular1_checkall_0(sql) + sql = "select %s from table_2 where " % interp_select + sql += "ts > %s ;" % (self.ts - 10) + datacheck = self.regular2_checkall_0(sql) + sql = "select %s from table_3 where " % interp_select + sql += "ts > %s ;" % (self.ts - 10) + datacheck = self.regular3_checkall_0(sql) + + sql = "select %s from table_1 where " % interp_select + sql += "ts > %s ;" % (self.ts + 85000) + datacheck = self.regular1_checkall_9(sql) + sql = "select %s from table_2 where " % interp_select + sql += "ts > %s ;" % (self.ts + 85000) + datacheck = self.regular2_checkall_9(sql) + sql = "select %s from table_3 where " % interp_select + sql += "ts > %s ;" % (self.ts + 85000) + datacheck = self.regular3_checkall_9(sql) + + # range + sql = "select %s from table_1 " % interp_select + sql += "range('%s' , '%s');" % (self.ts - 10000 , self.ts + 100000) + datacheck = self.result_0(sql) + sql = "select %s from table_2 " % interp_select + sql += "range('%s' , '%s');" % (self.ts - 10000 , self.ts + 100000) + datacheck = self.result_0(sql) + sql = "select %s from table_3 " % interp_select + sql += "range('%s' , '%s');" % (self.ts - 10000 , self.ts + 100000) + datacheck = self.result_0(sql) + + sql = "select %s from table_1 " % interp_select + sql += "range('%s' , '%s');" % (self.ts - 10000 , self.ts - 9900) + datacheck = self.result_0(sql) + sql = "select %s from table_2 " % interp_select + sql += "range('%s' , '%s');" % (self.ts - 10000 , self.ts - 9900) + datacheck = self.result_0(sql) + sql = "select %s from table_3 " % interp_select + sql += "range('%s' , '%s');" % (self.ts - 10000 , self.ts - 9900) + datacheck = self.result_0(sql) + + sql = "select %s from table_1 " % interp_select + sql += "range('%s' , '%s');" % (self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0(sql) + sql = "select %s from table_2 " % interp_select + sql += "range('%s' , '%s');" % (self.ts , self.ts + 200000) + datacheck = self.regular2_checkall_0(sql) + sql = "select %s from table_3 " % interp_select + sql += "range('%s' , '%s');" % (self.ts , self.ts + 200000) + datacheck = self.regular3_checkall_0(sql) + + sql = "select %s from table_1 " % interp_select + sql += "range('%s' , '%s');" % (self.ts + 1500 , self.ts + 2500) + datacheck = self.result_0(sql) + sql = "select %s from table_2 " % interp_select + sql += "range('%s' , '%s');" % (self.ts + 1500 , self.ts + 2500) + datacheck = self.result_0(sql) + sql = "select %s from table_3 " % interp_select + sql += "range('%s' , '%s');" % (self.ts + 1500 , self.ts + 2500) + datacheck = self.result_0(sql) + + sql = "select %s from table_1 " % interp_select + sql += "range('%s' , '%s');" % (self.ts + 150000 , self.ts + 200000) + datacheck = self.result_0(sql) + sql = "select %s from table_2 " % interp_select + sql += "range('%s' , '%s');" % (self.ts + 150000 , self.ts + 200000) + datacheck = self.result_0(sql) + sql = "select %s from table_3 " % interp_select + sql += "range('%s' , '%s');" % (self.ts + 150000 , self.ts + 200000) + datacheck = self.result_0(sql) + + # FILL(LINEAR) + sql = "select %s from table_1 FILL(LINEAR)" % interp_select + datacheck = self.regular1_checkall_0(sql) + sql = "select %s from table_2 FILL(LINEAR)" % interp_select + datacheck = self.regular2_checkall_0(sql) + sql = "select %s from table_3 FILL(LINEAR)" % interp_select + datacheck = self.regular3_checkall_0(sql) + + sql = "select %s from table_1 " % interp_select + sql += "range('%s' , '%s') FILL(LINEAR);" % (self.ts - 10000 , self.ts + 100000) + datacheck = self.result_0(sql) + sql = "select %s from table_2 " % interp_select + sql += "range('%s' , '%s') FILL(LINEAR);" % (self.ts - 10000 , self.ts + 100000) + datacheck = self.result_0(sql) + sql = "select %s from table_3 " % interp_select + sql += "range('%s' , '%s') FILL(LINEAR);" % (self.ts - 10000 , self.ts + 100000) + datacheck = self.result_0(sql) + + sql = "select %s from table_1 " % interp_select + sql += "range('%s' , '%s') FILL(LINEAR);" % (self.ts - 10000 , self.ts - 9900) + datacheck = self.result_0(sql) + sql = "select %s from table_2 " % interp_select + sql += "range('%s' , '%s') FILL(LINEAR);" % (self.ts - 10000 , self.ts - 9900) + datacheck = self.result_0(sql) + sql = "select %s from table_3 " % interp_select + sql += "range('%s' , '%s') FILL(LINEAR);" % (self.ts - 10000 , self.ts - 9900) + datacheck = self.result_0(sql) + + sql = "select %s from table_1 " % interp_select + sql += "range('%s' , '%s') FILL(LINEAR);" % (self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0(sql) + sql = "select %s from table_2 " % interp_select + sql += "range('%s' , '%s') FILL(LINEAR);" % (self.ts , self.ts + 200000) + datacheck = self.regular2_checkall_0(sql) + sql = "select %s from table_3 " % interp_select + sql += "range('%s' , '%s') FILL(LINEAR);" % (self.ts , self.ts + 200000) + datacheck = self.regular3_checkall_0(sql) + + sql = "select %s from table_1 " % interp_select + sql += "range('%s' , '%s') FILL(LINEAR);" % (self.ts + 1500 , self.ts + 2500) + datacheck = self.regular1_checkall_0_LINEAR(sql) + sql = "select %s from table_2 " % interp_select + sql += "range('%s' , '%s') FILL(LINEAR);" % (self.ts + 1500 , self.ts + 2500) + datacheck = self.regular2_checkall_0_LINEAR(sql) + sql = "select %s from table_3 " % interp_select + sql += "range('%s' , '%s') FILL(LINEAR);" % (self.ts + 1500 , self.ts + 2500) + datacheck = self.regular3_checkall_0_LINEAR(sql) + + sql = "select %s from table_1 " % interp_select + sql += "range('%s' , '%s') FILL(LINEAR);" % (self.ts + 150000 , self.ts + 200000) + datacheck = self.result_0(sql) + sql = "select %s from table_2 " % interp_select + sql += "range('%s' , '%s') FILL(LINEAR);" % (self.ts + 150000 , self.ts + 200000) + datacheck = self.result_0(sql) + sql = "select %s from table_3 " % interp_select + sql += "range('%s' , '%s') FILL(LINEAR);" % (self.ts + 150000 , self.ts + 200000) + datacheck = self.result_0(sql) + + # FILL(LINEAR) + EVERY( s) + sql = "select %s from table_1 EVERY(1s) FILL(LINEAR);" % interp_select + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(91) + sql = "select %s from table_2 EVERY(1s) FILL(LINEAR);" % interp_select + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(91) + sql = "select %s from table_3 EVERY(1s) FILL(LINEAR);" % interp_select + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(91) + + sql = "select %s from table_1 EVERY(5s) FILL(LINEAR);" % interp_select + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(19) + sql = "select %s from table_2 EVERY(5s) FILL(LINEAR);" % interp_select + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(19) + sql = "select %s from table_3 EVERY(5s) FILL(LINEAR);" % interp_select + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(19) + + # range + FILL(LINEAR) + EVERY( s) + sql = "select %s from table_1 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(LINEAR);" % (self.ts - 10000 , self.ts + 100000) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(91) + sql = "select %s from table_2 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(LINEAR);" % (self.ts - 10000 , self.ts + 100000) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(91) + sql = "select %s from table_3 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(LINEAR);" % (self.ts - 10000 , self.ts + 100000) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(91) + + sql = "select %s from table_1 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(LINEAR);" % (self.ts - 10000 , self.ts - 9900) + datacheck = self.result_0(sql) + sql = "select %s from table_2 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(LINEAR);" % (self.ts - 10000 , self.ts - 9900) + datacheck = self.result_0(sql) + sql = "select %s from table_3 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(LINEAR);" % (self.ts - 10000 , self.ts - 9900) + datacheck = self.result_0(sql) + + sql = "select %s from table_1 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(LINEAR);" % (self.ts , self.ts) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(1) + sql = "select %s from table_2 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(LINEAR);" % (self.ts , self.ts) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(1) + sql = "select %s from table_3 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(LINEAR);" % (self.ts , self.ts) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(1) + + sql = "select %s from table_1 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(LINEAR);" % (self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(91) + sql = "select %s from table_2 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(LINEAR);" % (self.ts , self.ts + 200000) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(91) + sql = "select %s from table_3 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(LINEAR);" % (self.ts , self.ts + 200000) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(91) + + sql = "select %s from table_1 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(LINEAR) ORDER BY ts DESC;" % (self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_9(sql) + tdSql.checkRows(91) + sql = "select %s from table_2 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(LINEAR) ORDER BY ts DESC;" % (self.ts , self.ts + 200000) + datacheck = self.regular2_checkall_9(sql) + tdSql.checkRows(91) + sql = "select %s from table_3 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(LINEAR) ORDER BY ts DESC;" % (self.ts , self.ts + 200000) + datacheck = self.regular3_checkall_9(sql) + tdSql.checkRows(91) + + sql = "select %s from table_1 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(LINEAR);" % (self.ts + 1500 , self.ts + 2500) + datacheck = self.regular1_checkall_0_LINEAR(sql) + tdSql.checkRows(2) + sql = "select %s from table_2 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(LINEAR);" % (self.ts + 1500 , self.ts + 2500) + datacheck = self.regular2_checkall_0_LINEAR(sql) + tdSql.checkRows(2) + sql = "select %s from table_3 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(LINEAR);" % (self.ts + 1500 , self.ts + 2500) + datacheck = self.regular3_checkall_0_LINEAR(sql) + tdSql.checkRows(2) + + sql = "select %s from table_1 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(LINEAR);" % (self.ts + 150000 , self.ts + 200000) + datacheck = self.result_0(sql) + sql = "select %s from table_2 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(LINEAR);" % (self.ts + 150000 , self.ts + 200000) + datacheck = self.result_0(sql) + sql = "select %s from table_3 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(LINEAR);" % (self.ts + 150000 , self.ts + 200000) + datacheck = self.result_0(sql) + + # where + range + FILL(LINEAR) + EVERY( s) + sql = "select %s from table_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(11) + sql = "select %s from table_2 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(11) + sql = "select %s from table_3 " % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(11) + + sql = "select %s from table_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + datacheck = self.result_0(sql) + sql = "select %s from table_2 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + datacheck = self.result_0(sql) + sql = "select %s from table_3 " % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + datacheck = self.result_0(sql) + + sql = "select %s from table_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR);" % (self.ts , self.ts + 10000 , self.ts , self.ts) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(1) + sql = "select %s from table_2 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR);" % (self.ts , self.ts + 10000 , self.ts , self.ts) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(1) + sql = "select %s from table_3 " % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR);" % (self.ts , self.ts + 10000 , self.ts , self.ts) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(1) + + sql = "select %s from table_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR);" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(11) + sql = "select %s from table_2 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR);" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(11) + sql = "select %s from table_3 " % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR);" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(11) + + sql = "select %s from table_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR) ORDER BY ts DESC;" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0_NEXT(sql) + tdSql.checkRows(11) + sql = "select %s from table_2 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR) ORDER BY ts DESC;" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular2_checkall_0_NEXT(sql) + tdSql.checkRows(11) + sql = "select %s from table_3 " % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR) ORDER BY ts DESC;" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular3_checkall_0_NEXT(sql) + tdSql.checkRows(11) + + sql = "select %s from table_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR);" % (self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + datacheck = self.regular1_checkall_0_LINEAR(sql) + tdSql.checkRows(2) + sql = "select %s from table_2 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR);" % (self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + datacheck = self.regular2_checkall_0_LINEAR(sql) + tdSql.checkRows(2) + sql = "select %s from table_3 " % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR);" % (self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + datacheck = self.regular3_checkall_0_LINEAR(sql) + tdSql.checkRows(2) + + sql = "select %s from table_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR);" % (self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + datacheck = self.result_0(sql) + sql = "select %s from table_2 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR);" % (self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + datacheck = self.result_0(sql) + sql = "select %s from table_3 " % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR);" % (self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + datacheck = self.result_0(sql) + + # FILL(NEXT) + sql = "select %s from table_1 FILL(NEXT)" % interp_select + datacheck = self.regular1_checkall_0(sql) + sql = "select %s from table_2 FILL(NEXT)" % interp_select + datacheck = self.regular2_checkall_0(sql) + sql = "select %s from table_3 FILL(NEXT)" % interp_select + datacheck = self.regular3_checkall_0(sql) + + sql = "select %s from table_1 " % interp_select + sql += "range('%s' , '%s') FILL(NEXT);" % (self.ts - 10000 , self.ts + 100000) + datacheck = self.regular1_checkall_0(sql) + sql = "select %s from table_2 " % interp_select + sql += "range('%s' , '%s') FILL(NEXT);" % (self.ts - 10000 , self.ts + 100000) + datacheck = self.regular2_checkall_0(sql) + sql = "select %s from table_3 " % interp_select + sql += "range('%s' , '%s') FILL(NEXT);" % (self.ts - 10000 , self.ts + 100000) + datacheck = self.regular3_checkall_0(sql) + + sql = "select %s from table_1 " % interp_select + sql += "range('%s' , '%s') FILL(NEXT);" % (self.ts - 10000 , self.ts - 9900) + datacheck = self.regular1_checkall_0(sql) + sql = "select %s from table_2 " % interp_select + sql += "range('%s' , '%s') FILL(NEXT);" % (self.ts - 10000 , self.ts - 9900) + datacheck = self.regular2_checkall_0(sql) + sql = "select %s from table_3 " % interp_select + sql += "range('%s' , '%s') FILL(NEXT);" % (self.ts - 10000 , self.ts - 9900) + datacheck = self.regular3_checkall_0(sql) + + sql = "select %s from table_1 " % interp_select + sql += "range('%s' , '%s') FILL(NEXT);" % (self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0(sql) + sql = "select %s from table_2 " % interp_select + sql += "range('%s' , '%s') FILL(NEXT);" % (self.ts , self.ts + 200000) + datacheck = self.regular2_checkall_0(sql) + sql = "select %s from table_3 " % interp_select + sql += "range('%s' , '%s') FILL(NEXT);" % (self.ts , self.ts + 200000) + datacheck = self.regular3_checkall_0(sql) + + sql = "select %s from table_1 " % interp_select + sql += "range('%s' , '%s') FILL(NEXT);" % (self.ts + 1500 , self.ts + 2500) + datacheck = self.regular1_checkall_0_NEXT(sql) + sql = "select %s from table_2 " % interp_select + sql += "range('%s' , '%s') FILL(NEXT);" % (self.ts + 1500 , self.ts + 2500) + datacheck = self.regular2_checkall_0_NEXT(sql) + sql = "select %s from table_3 " % interp_select + sql += "range('%s' , '%s') FILL(NEXT);" % (self.ts + 1500 , self.ts + 2500) + datacheck = self.regular3_checkall_0_NEXT(sql) + + sql = "select %s from table_1 " % interp_select + sql += "range('%s' , '%s') FILL(NEXT);" % (self.ts + 150000 , self.ts + 200000) + datacheck = self.result_0(sql) + sql = "select %s from table_2 " % interp_select + sql += "range('%s' , '%s') FILL(NEXT);" % (self.ts + 150000 , self.ts + 200000) + datacheck = self.result_0(sql) + sql = "select %s from table_3 " % interp_select + sql += "range('%s' , '%s') FILL(NEXT);" % (self.ts + 150000 , self.ts + 200000) + datacheck = self.result_0(sql) + + # FILL(NEXT) + EVERY( s) + sql = "select %s from table_1 EVERY(1s) FILL(NEXT);" % interp_select + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(91) + sql = "select %s from table_2 EVERY(1s) FILL(NEXT);" % interp_select + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(91) + sql = "select %s from table_3 EVERY(1s) FILL(NEXT);" % interp_select + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(91) + + sql = "select %s from table_1 EVERY(5s) FILL(NEXT);" % interp_select + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(19) + sql = "select %s from table_2 EVERY(5s) FILL(NEXT);" % interp_select + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(19) + sql = "select %s from table_3 EVERY(5s) FILL(NEXT);" % interp_select + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(19) + + # range + FILL(NEXT) + EVERY( s) + sql = "select %s from table_1 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(NEXT);" % (self.ts - 10000 , self.ts + 100000) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(101) + sql = "select %s from table_2 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(NEXT);" % (self.ts - 10000 , self.ts + 100000) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(101) + sql = "select %s from table_3 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(NEXT);" % (self.ts - 10000 , self.ts + 100000) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(101) + + sql = "select %s from table_1 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(NEXT);" % (self.ts - 10000 , self.ts - 9900) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(1) + sql = "select %s from table_2 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(NEXT);" % (self.ts - 10000 , self.ts - 9900) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(1) + sql = "select %s from table_3 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(NEXT);" % (self.ts - 10000 , self.ts - 9900) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(1) + + sql = "select %s from table_1 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(NEXT);" % (self.ts , self.ts) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(1) + sql = "select %s from table_2 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(NEXT);" % (self.ts , self.ts) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(1) + sql = "select %s from table_3 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(NEXT);" % (self.ts , self.ts) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(1) + + sql = "select %s from table_1 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(NEXT);" % (self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(91) + sql = "select %s from table_2 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(NEXT);" % (self.ts , self.ts + 200000) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(91) + sql = "select %s from table_3 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(NEXT);" % (self.ts , self.ts + 200000) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(91) + + sql = "select %s from table_1 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(NEXT) ORDER BY ts DESC;" % (self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_9(sql) + tdSql.checkRows(91) + sql = "select %s from table_2 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(NEXT) ORDER BY ts DESC;" % (self.ts , self.ts + 200000) + datacheck = self.regular2_checkall_9(sql) + tdSql.checkRows(91) + sql = "select %s from table_3 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(NEXT) ORDER BY ts DESC;" % (self.ts , self.ts + 200000) + datacheck = self.regular3_checkall_9(sql) + tdSql.checkRows(91) + + sql = "select %s from table_1 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(NEXT);" % (self.ts + 1500 , self.ts + 2500) + datacheck = self.regular1_checkall_0_NEXT(sql) + tdSql.checkRows(2) + sql = "select %s from table_2 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(NEXT);" % (self.ts + 1500 , self.ts + 2500) + datacheck = self.regular2_checkall_0_NEXT(sql) + tdSql.checkRows(2) + sql = "select %s from table_3 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(NEXT);" % (self.ts + 1500 , self.ts + 2500) + datacheck = self.regular3_checkall_0_NEXT(sql) + tdSql.checkRows(2) + + sql = "select %s from table_1 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(NEXT);" % (self.ts + 150000 , self.ts + 200000) + datacheck = self.result_0(sql) + sql = "select %s from table_2 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(NEXT);" % (self.ts + 150000 , self.ts + 200000) + datacheck = self.result_0(sql) + sql = "select %s from table_3 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(NEXT);" % (self.ts + 150000 , self.ts + 200000) + datacheck = self.result_0(sql) + + # where + range + FILL(NEXT) + EVERY( s) + sql = "select %s from table_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(21) + sql = "select %s from table_2 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(21) + sql = "select %s from table_3 " % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(21) + + sql = "select %s from table_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(1) + sql = "select %s from table_2 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(1) + sql = "select %s from table_3 " % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(1) + + sql = "select %s from table_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT);" % (self.ts , self.ts + 10000 , self.ts , self.ts) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(1) + sql = "select %s from table_2 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT);" % (self.ts , self.ts + 10000 , self.ts , self.ts) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(1) + sql = "select %s from table_3 " % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT);" % (self.ts , self.ts + 10000 , self.ts , self.ts) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(1) + + sql = "select %s from table_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT);" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(11) + sql = "select %s from table_2 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT);" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(11) + sql = "select %s from table_3 " % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT);" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(11) + + sql = "select %s from table_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT) ORDER BY ts DESC;" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0_NEXT(sql) + tdSql.checkRows(11) + sql = "select %s from table_2 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT) ORDER BY ts DESC;" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular2_checkall_0_NEXT(sql) + tdSql.checkRows(11) + sql = "select %s from table_3 " % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT) ORDER BY ts DESC;" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular3_checkall_0_NEXT(sql) + tdSql.checkRows(11) + + sql = "select %s from table_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT);" % (self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + datacheck = self.regular1_checkall_0_NEXT(sql) + tdSql.checkRows(2) + sql = "select %s from table_2 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT);" % (self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + datacheck = self.regular2_checkall_0_NEXT(sql) + tdSql.checkRows(2) + sql = "select %s from table_3 " % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT);" % (self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + datacheck = self.regular3_checkall_0_NEXT(sql) + tdSql.checkRows(2) + + sql = "select %s from table_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT);" % (self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + datacheck = self.result_0(sql) + sql = "select %s from table_2 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT);" % (self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + datacheck = self.result_0(sql) + sql = "select %s from table_3 " % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT);" % (self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + datacheck = self.result_0(sql) + + # FILL(PREV) + sql = "select %s from table_1 FILL(PREV)" % interp_select + datacheck = self.regular1_checkall_0(sql) + sql = "select %s from table_2 FILL(PREV)" % interp_select + datacheck = self.regular2_checkall_0(sql) + sql = "select %s from table_3 FILL(PREV)" % interp_select + datacheck = self.regular3_checkall_0(sql) + + sql = "select %s from table_1 " % interp_select + sql += "range('%s' , '%s') FILL(PREV);" % (self.ts - 10000 , self.ts + 100000) + datacheck = self.result_0(sql) + sql = "select %s from table_2 " % interp_select + sql += "range('%s' , '%s') FILL(PREV);" % (self.ts - 10000 , self.ts + 100000) + datacheck = self.result_0(sql) + sql = "select %s from table_3 " % interp_select + sql += "range('%s' , '%s') FILL(PREV);" % (self.ts - 10000 , self.ts + 100000) + datacheck = self.result_0(sql) + + sql = "select %s from table_1 " % interp_select + sql += "range('%s' , '%s') FILL(PREV);" % (self.ts - 10000 , self.ts - 9900) + datacheck = self.result_0(sql) + sql = "select %s from table_2 " % interp_select + sql += "range('%s' , '%s') FILL(PREV);" % (self.ts - 10000 , self.ts - 9900) + datacheck = self.result_0(sql) + sql = "select %s from table_3 " % interp_select + sql += "range('%s' , '%s') FILL(PREV);" % (self.ts - 10000 , self.ts - 9900) + datacheck = self.result_0(sql) + + sql = "select %s from table_1 " % interp_select + sql += "range('%s' , '%s') FILL(PREV);" % (self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0(sql) + sql = "select %s from table_2 " % interp_select + sql += "range('%s' , '%s') FILL(PREV);" % (self.ts , self.ts + 200000) + datacheck = self.regular2_checkall_0(sql) + sql = "select %s from table_3 " % interp_select + sql += "range('%s' , '%s') FILL(PREV);" % (self.ts , self.ts + 200000) + datacheck = self.regular3_checkall_0(sql) + + sql = "select %s from table_1 " % interp_select + sql += "range('%s' , '%s') FILL(PREV);" % (self.ts + 1500 , self.ts + 2500) + datacheck = self.regular1_checkall_0(sql) + sql = "select %s from table_2 " % interp_select + sql += "range('%s' , '%s') FILL(PREV);" % (self.ts + 1500 , self.ts + 2500) + datacheck = self.regular2_checkall_0(sql) + sql = "select %s from table_3 " % interp_select + sql += "range('%s' , '%s') FILL(PREV);" % (self.ts + 1500 , self.ts + 2500) + datacheck = self.regular3_checkall_0(sql) + + sql = "select %s from table_1 " % interp_select + sql += "range('%s' , '%s') FILL(PREV);" % (self.ts + 150000 , self.ts + 200000) + datacheck = self.regular1_checkall_9(sql) + sql = "select %s from table_2 " % interp_select + sql += "range('%s' , '%s') FILL(PREV);" % (self.ts + 150000 , self.ts + 200000) + datacheck = self.regular2_checkall_9(sql) + sql = "select %s from table_3 " % interp_select + sql += "range('%s' , '%s') FILL(PREV);" % (self.ts + 150000 , self.ts + 200000) + datacheck = self.regular3_checkall_9(sql) + + # FILL(PREV) + EVERY( s) + sql = "select %s from table_1 EVERY(1s) FILL(PREV);" % interp_select + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(91) + sql = "select %s from table_2 EVERY(1s) FILL(PREV);" % interp_select + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(91) + sql = "select %s from table_3 EVERY(1s) FILL(PREV);" % interp_select + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(91) + + sql = "select %s from table_1 EVERY(5s) FILL(PREV);" % interp_select + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(19) + sql = "select %s from table_2 EVERY(5s) FILL(PREV);" % interp_select + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(19) + sql = "select %s from table_3 EVERY(5s) FILL(PREV);" % interp_select + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(19) + + # range + FILL(PREV) + EVERY( s) + sql = "select %s from table_1 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(PREV);" % (self.ts - 10000 , self.ts + 100000) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(101) + sql = "select %s from table_2 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(PREV);" % (self.ts - 10000 , self.ts + 100000) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(101) + sql = "select %s from table_3 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(PREV);" % (self.ts - 10000 , self.ts + 100000) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(101) + + sql = "select %s from table_1 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(PREV);" % (self.ts - 10000 , self.ts - 9900) + datacheck = self.result_0(sql) + sql = "select %s from table_2 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(PREV);" % (self.ts - 10000 , self.ts - 9900) + datacheck = self.result_0(sql) + sql = "select %s from table_3 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(PREV);" % (self.ts - 10000 , self.ts - 9900) + datacheck = self.result_0(sql) + + sql = "select %s from table_1 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(PREV);" % (self.ts , self.ts) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(1) + sql = "select %s from table_2 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(PREV);" % (self.ts , self.ts) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(1) + sql = "select %s from table_3 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(PREV);" % (self.ts , self.ts) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(1) + + sql = "select %s from table_1 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(PREV);" % (self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(201) + sql = "select %s from table_2 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(PREV);" % (self.ts , self.ts + 200000) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(201) + sql = "select %s from table_3 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(PREV);" % (self.ts , self.ts + 200000) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(201) + + sql = "select %s from table_1 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(PREV) ORDER BY ts DESC;" % (self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_9(sql) + tdSql.checkRows(201) + sql = "select %s from table_2 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(PREV) ORDER BY ts DESC;" % (self.ts , self.ts + 200000) + datacheck = self.regular2_checkall_9(sql) + tdSql.checkRows(201) + sql = "select %s from table_3 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(PREV) ORDER BY ts DESC;" % (self.ts , self.ts + 200000) + datacheck = self.regular3_checkall_9(sql) + tdSql.checkRows(201) + + sql = "select %s from table_1 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(PREV);" % (self.ts + 1500 , self.ts + 2500) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(2) + sql = "select %s from table_2 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(PREV);" % (self.ts + 1500 , self.ts + 2500) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(2) + sql = "select %s from table_3 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(PREV);" % (self.ts + 1500 , self.ts + 2500) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(2) + + sql = "select %s from table_1 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(PREV);" % (self.ts + 150000 , self.ts + 200000) + datacheck = self.regular1_checkall_9(sql) + tdSql.checkRows(51) + sql = "select %s from table_2 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(PREV);" % (self.ts + 150000 , self.ts + 200000) + datacheck = self.regular2_checkall_9(sql) + tdSql.checkRows(51) + sql = "select %s from table_3 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(PREV);" % (self.ts + 150000 , self.ts + 200000) + datacheck = self.regular3_checkall_9(sql) + tdSql.checkRows(51) + + # where + range + FILL(PREV) + EVERY( s) + sql = "select %s from table_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(101) + sql = "select %s from table_2 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(101) + sql = "select %s from table_3 " % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(PREV);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(101) + + sql = "select %s from table_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + datacheck = self.result_0(sql) + sql = "select %s from table_2 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + datacheck = self.result_0(sql) + sql = "select %s from table_3 " % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(PREV);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + datacheck = self.result_0(sql) + + sql = "select %s from table_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV);" % (self.ts , self.ts + 10000 , self.ts , self.ts) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(1) + sql = "select %s from table_2 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV);" % (self.ts , self.ts + 10000 , self.ts , self.ts) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(1) + sql = "select %s from table_3 " % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(PREV);" % (self.ts , self.ts + 10000 , self.ts , self.ts) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(1) + + sql = "select %s from table_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV);" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(201) + sql = "select %s from table_2 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV);" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(201) + sql = "select %s from table_3 " % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(PREV);" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(201) + + sql = "select %s from table_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV) ORDER BY ts DESC;" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0_NEXT(sql) + tdSql.checkRows(201) + sql = "select %s from table_2 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV) ORDER BY ts DESC;" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular2_checkall_0_NEXT(sql) + tdSql.checkRows(201) + sql = "select %s from table_3 " % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(PREV) ORDER BY ts DESC;" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular3_checkall_0_NEXT(sql) + tdSql.checkRows(201) + + sql = "select %s from table_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV);" % (self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(2) + sql = "select %s from table_2 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV);" % (self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(2) + sql = "select %s from table_3 " % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(PREV);" % (self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(2) + + sql = "select %s from table_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV);" % (self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + datacheck = self.regular1_checkall_0_NEXT(sql) + tdSql.checkRows(51) + sql = "select %s from table_2 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV);" % (self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + datacheck = self.regular2_checkall_0_NEXT(sql) + tdSql.checkRows(51) + sql = "select %s from table_3 " % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(PREV);" % (self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + datacheck = self.regular3_checkall_0_NEXT(sql) + tdSql.checkRows(51) + + # FILL(VALUE,100) + sql = "select %s from table_1 FILL(VALUE, 100)" % interp_select + datacheck = self.regular1_checkall_0(sql) + sql = "select %s from table_2 FILL(VALUE, 100)" % interp_select + datacheck = self.regular2_checkall_0(sql) + sql = "select %s from table_3 FILL(VALUE, 100)" % interp_select + datacheck = self.regular3_checkall_0(sql) + + sql = "select %s from table_1 " % interp_select + sql += "range('%s' , '%s') FILL(VALUE, 100);" % (self.ts - 10000 , self.ts + 100000) + datacheck = self.regular1_checkall_0_VALUE100(sql) + sql = "select %s from table_2 " % interp_select + sql += "range('%s' , '%s') FILL(VALUE, 100);" % (self.ts - 10000 , self.ts + 100000) + datacheck = self.regular1_checkall_0_VALUE100(sql) + sql = "select %s from table_3 " % interp_select + sql += "range('%s' , '%s') FILL(VALUE, 100);" % (self.ts - 10000 , self.ts + 100000) + datacheck = self.regular1_checkall_0_VALUE100(sql) + + sql = "select %s from table_1 " % interp_select + sql += "range('%s' , '%s') FILL(VALUE, 100);" % (self.ts - 10000 , self.ts - 9900) + datacheck = self.regular1_checkall_0_VALUE100(sql) + sql = "select %s from table_2 " % interp_select + sql += "range('%s' , '%s') FILL(VALUE, 100);" % (self.ts - 10000 , self.ts - 9900) + datacheck = self.regular1_checkall_0_VALUE100(sql) + sql = "select %s from table_3 " % interp_select + sql += "range('%s' , '%s') FILL(VALUE, 100);" % (self.ts - 10000 , self.ts - 9900) + datacheck = self.regular1_checkall_0_VALUE100(sql) + + sql = "select %s from table_1 " % interp_select + sql += "range('%s' , '%s') FILL(VALUE, 100);" % (self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0(sql) + sql = "select %s from table_2 " % interp_select + sql += "range('%s' , '%s') FILL(VALUE, 100);" % (self.ts , self.ts + 200000) + datacheck = self.regular2_checkall_0(sql) + sql = "select %s from table_3 " % interp_select + sql += "range('%s' , '%s') FILL(VALUE, 100);" % (self.ts , self.ts + 200000) + datacheck = self.regular3_checkall_0(sql) + + sql = "select %s from table_1 " % interp_select + sql += "range('%s' , '%s') FILL(VALUE, 100);" % (self.ts + 1500 , self.ts + 2500) + datacheck = self.regular1_checkall_0_VALUE100(sql) + sql = "select %s from table_2 " % interp_select + sql += "range('%s' , '%s') FILL(VALUE, 100);" % (self.ts + 1500 , self.ts + 2500) + datacheck = self.regular1_checkall_0_VALUE100(sql) + sql = "select %s from table_3 " % interp_select + sql += "range('%s' , '%s') FILL(VALUE, 100);" % (self.ts + 1500 , self.ts + 2500) + datacheck = self.regular1_checkall_0_VALUE100(sql) + + sql = "select %s from table_1 " % interp_select + sql += "range('%s' , '%s') FILL(VALUE, 100);" % (self.ts + 150000 , self.ts + 200000) + datacheck = self.regular1_checkall_0_VALUE100(sql) + sql = "select %s from table_2 " % interp_select + sql += "range('%s' , '%s') FILL(VALUE, 100);" % (self.ts + 150000 , self.ts + 200000) + datacheck = self.regular1_checkall_0_VALUE100(sql) + sql = "select %s from table_3 " % interp_select + sql += "range('%s' , '%s') FILL(VALUE, 100);" % (self.ts + 150000 , self.ts + 200000) + datacheck = self.regular1_checkall_0_VALUE100(sql) + + # FILL(VALUE,100) + EVERY( s) + sql = "select %s from table_1 EVERY(1s) FILL(VALUE, 100);" % interp_select + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(91) + sql = "select %s from table_2 EVERY(1s) FILL(VALUE, 100);" % interp_select + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(91) + sql = "select %s from table_3 EVERY(1s) FILL(VALUE, 100);" % interp_select + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(91) + + sql = "select %s from table_1 EVERY(5s) FILL(VALUE, 100);" % interp_select + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(19) + sql = "select %s from table_2 EVERY(5s) FILL(VALUE, 100);" % interp_select + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(19) + sql = "select %s from table_3 EVERY(5s) FILL(VALUE, 100);" % interp_select + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(19) + + # FILL(NULL) + EVERY( s) + sql = "select %s from table_1 EVERY(1s) FILL(NULL);" % interp_select + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(91) + sql = "select %s from table_2 EVERY(1s) FILL(NULL);" % interp_select + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(91) + sql = "select %s from table_3 EVERY(1s) FILL(NULL);" % interp_select + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(91) + + sql = "select %s from table_1 EVERY(5s) FILL(NULL);" % interp_select + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(19) + sql = "select %s from table_2 EVERY(5s) FILL(NULL);" % interp_select + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(19) + sql = "select %s from table_3 EVERY(5s) FILL(NULL);" % interp_select + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(19) + + # range + FILL(VALUE, 100) + EVERY( s) + sql = "select %s from table_1 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(VALUE, 100);" % (self.ts - 10000 , self.ts + 100000) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(111) + sql = "select %s from table_2 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(VALUE, 100);" % (self.ts - 10000 , self.ts + 100000) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(111) + sql = "select %s from table_3 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(VALUE, 100);" % (self.ts - 10000 , self.ts + 100000) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(111) + + sql = "select %s from table_1 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(VALUE, 100);" % (self.ts - 10000 , self.ts - 9900) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(1) + sql = "select %s from table_2 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(VALUE, 100);" % (self.ts - 10000 , self.ts - 9900) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(1) + sql = "select %s from table_3 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(VALUE, 100);" % (self.ts - 10000 , self.ts - 9900) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(1) + + sql = "select %s from table_1 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(VALUE, 100);" % (self.ts , self.ts) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(1) + sql = "select %s from table_2 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(VALUE, 100);" % (self.ts , self.ts) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(1) + sql = "select %s from table_3 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(VALUE, 100);" % (self.ts , self.ts) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(1) + + sql = "select %s from table_1 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(VALUE, 100);" % (self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(201) + sql = "select %s from table_2 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(VALUE, 100);" % (self.ts , self.ts + 200000) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(201) + sql = "select %s from table_3 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(VALUE, 100);" % (self.ts , self.ts + 200000) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(201) + + sql = "select %s from table_1 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(VALUE, 100) ORDER BY ts DESC;" % (self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(201) + sql = "select %s from table_2 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(VALUE, 100) ORDER BY ts DESC;" % (self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(201) + sql = "select %s from table_3 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(VALUE, 100) ORDER BY ts DESC;" % (self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(201) + + sql = "select %s from table_1 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(VALUE, 100);" % (self.ts + 1500 , self.ts + 2500) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(2) + sql = "select %s from table_2 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(VALUE, 100);" % (self.ts + 1500 , self.ts + 2500) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(2) + sql = "select %s from table_3 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(VALUE, 100);" % (self.ts + 1500 , self.ts + 2500) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(2) + + sql = "select %s from table_1 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(VALUE, 100);" % (self.ts + 150000 , self.ts + 200000) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(51) + sql = "select %s from table_2 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(VALUE, 100);" % (self.ts + 150000 , self.ts + 200000) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(51) + sql = "select %s from table_3 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(VALUE, 100);" % (self.ts + 150000 , self.ts + 200000) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(51) + + # where + range + FILL(VALUE, 100) + EVERY( s) + sql = "select %s from table_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(111) + sql = "select %s from table_2 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(111) + sql = "select %s from table_3 " % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(111) + + sql = "select %s from table_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(1) + sql = "select %s from table_2 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(1) + sql = "select %s from table_3 " % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(1) + + sql = "select %s from table_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100);" % (self.ts , self.ts + 10000 , self.ts , self.ts) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(1) + sql = "select %s from table_2 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100);" % (self.ts , self.ts + 10000 , self.ts , self.ts) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(1) + sql = "select %s from table_3 " % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100);" % (self.ts , self.ts + 10000 , self.ts , self.ts) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(1) + + sql = "select %s from table_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100);" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(201) + sql = "select %s from table_2 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100);" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(201) + sql = "select %s from table_3 " % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100);" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(201) + + sql = "select %s from table_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100) ORDER BY ts DESC;" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(201) + sql = "select %s from table_2 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100) ORDER BY ts DESC;" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(201) + sql = "select %s from table_3 " % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100) ORDER BY ts DESC;" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(201) + + sql = "select %s from table_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100);" % (self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(2) + sql = "select %s from table_2 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100);" % (self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(2) + sql = "select %s from table_3 " % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100);" % (self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(2) + + sql = "select %s from table_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100);" % (self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(51) + sql = "select %s from table_2 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100);" % (self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(51) + sql = "select %s from table_3 " % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100);" % (self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(51) + + # FILL(NULL) + sql = "select %s from table_1 FILL(NULL)" % interp_select + datacheck = self.regular1_checkall_0(sql) + sql = "select %s from table_2 FILL(NULL)" % interp_select + datacheck = self.regular2_checkall_0(sql) + sql = "select %s from table_3 FILL(NULL)" % interp_select + datacheck = self.regular3_checkall_0(sql) + + sql = "select %s from table_1 " % interp_select + sql += "range('%s' , '%s') FILL(NULL);" % (self.ts - 10000 , self.ts + 100000) + datacheck = self.regular1_checkall_0_NULL(sql) + sql = "select %s from table_2 " % interp_select + sql += "range('%s' , '%s') FILL(NULL);" % (self.ts - 10000 , self.ts + 100000) + datacheck = self.regular1_checkall_0_NULL(sql) + sql = "select %s from table_3 " % interp_select + sql += "range('%s' , '%s') FILL(NULL);" % (self.ts - 10000 , self.ts + 100000) + datacheck = self.regular1_checkall_0_NULL(sql) + + sql = "select %s from table_1 " % interp_select + sql += "range('%s' , '%s') FILL(NULL);" % (self.ts - 10000 , self.ts - 9900) + datacheck = self.regular1_checkall_0_NULL(sql) + sql = "select %s from table_2 " % interp_select + sql += "range('%s' , '%s') FILL(NULL);" % (self.ts - 10000 , self.ts - 9900) + datacheck = self.regular1_checkall_0_NULL(sql) + sql = "select %s from table_3 " % interp_select + sql += "range('%s' , '%s') FILL(NULL);" % (self.ts - 10000 , self.ts - 9900) + datacheck = self.regular1_checkall_0_NULL(sql) + + sql = "select %s from table_1 " % interp_select + sql += "range('%s' , '%s') FILL(NULL);" % (self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0(sql) + sql = "select %s from table_2 " % interp_select + sql += "range('%s' , '%s') FILL(NULL);" % (self.ts , self.ts + 200000) + datacheck = self.regular2_checkall_0(sql) + sql = "select %s from table_3 " % interp_select + sql += "range('%s' , '%s') FILL(NULL);" % (self.ts , self.ts + 200000) + datacheck = self.regular3_checkall_0(sql) + + sql = "select %s from table_1 " % interp_select + sql += "range('%s' , '%s') FILL(NULL);" % (self.ts + 1500 , self.ts + 2500) + datacheck = self.regular1_checkall_0_NULL(sql) + sql = "select %s from table_2 " % interp_select + sql += "range('%s' , '%s') FILL(NULL);" % (self.ts + 1500 , self.ts + 2500) + datacheck = self.regular1_checkall_0_NULL(sql) + sql = "select %s from table_3 " % interp_select + sql += "range('%s' , '%s') FILL(NULL);" % (self.ts + 1500 , self.ts + 2500) + datacheck = self.regular1_checkall_0_NULL(sql) + + sql = "select %s from table_1 " % interp_select + sql += "range('%s' , '%s') FILL(NULL);" % (self.ts + 150000 , self.ts + 200000) + datacheck = self.regular1_checkall_0_NULL(sql) + sql = "select %s from table_2 " % interp_select + sql += "range('%s' , '%s') FILL(NULL);" % (self.ts + 150000 , self.ts + 200000) + datacheck = self.regular1_checkall_0_NULL(sql) + sql = "select %s from table_3 " % interp_select + sql += "range('%s' , '%s') FILL(NULL);" % (self.ts + 150000 , self.ts + 200000) + datacheck = self.regular1_checkall_0_NULL(sql) + + # range + FILL(NULL) + EVERY( s) + sql = "select %s from table_1 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(NULL);" % (self.ts - 10000 , self.ts + 100000) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(111) + sql = "select %s from table_2 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(NULL);" % (self.ts - 10000 , self.ts + 100000) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(111) + sql = "select %s from table_3 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(NULL);" % (self.ts - 10000 , self.ts + 100000) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(111) + + sql = "select %s from table_1 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(NULL);" % (self.ts - 10000 , self.ts - 9900) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(1) + sql = "select %s from table_2 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(NULL);" % (self.ts - 10000 , self.ts - 9900) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(1) + sql = "select %s from table_3 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(NULL);" % (self.ts - 10000 , self.ts - 9900) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(1) + + sql = "select %s from table_1 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(NULL);" % (self.ts , self.ts) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(1) + sql = "select %s from table_2 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(NULL);" % (self.ts , self.ts) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(1) + sql = "select %s from table_3 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(NULL);" % (self.ts , self.ts) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(1) + + sql = "select %s from table_1 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(NULL);" % (self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(201) + sql = "select %s from table_2 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(NULL);" % (self.ts , self.ts + 200000) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(201) + sql = "select %s from table_3 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(NULL);" % (self.ts , self.ts + 200000) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(201) + + sql = "select %s from table_1 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(NULL) ORDER BY ts DESC;" % (self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(201) + sql = "select %s from table_2 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(NULL) ORDER BY ts DESC;" % (self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(201) + sql = "select %s from table_3 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(NULL) ORDER BY ts DESC;" % (self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(201) + + sql = "select %s from table_1 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(NULL);" % (self.ts + 1500 , self.ts + 2500) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(2) + sql = "select %s from table_2 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(NULL);" % (self.ts + 1500 , self.ts + 2500) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(2) + sql = "select %s from table_3 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(NULL);" % (self.ts + 1500 , self.ts + 2500) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(2) + + sql = "select %s from table_1 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(NULL);" % (self.ts + 150000 , self.ts + 200000) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(51) + sql = "select %s from table_2 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(NULL);" % (self.ts + 150000 , self.ts + 200000) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(51) + sql = "select %s from table_3 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(NULL);" % (self.ts + 150000 , self.ts + 200000) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(51) + + # where + range + FILL(NULL) + EVERY( s) + sql = "select %s from table_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(111) + sql = "select %s from table_2 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(111) + sql = "select %s from table_3 " % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(NULL);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(111) + + sql = "select %s from table_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(1) + sql = "select %s from table_2 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(1) + sql = "select %s from table_3 " % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(NULL);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(1) + + sql = "select %s from table_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL);" % (self.ts , self.ts + 10000 , self.ts , self.ts) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(1) + sql = "select %s from table_2 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL);" % (self.ts , self.ts + 10000 , self.ts , self.ts) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(1) + sql = "select %s from table_3 " % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(NULL);" % (self.ts , self.ts + 10000 , self.ts , self.ts) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(1) + + sql = "select %s from table_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL);" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(201) + sql = "select %s from table_2 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL);" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(201) + sql = "select %s from table_3 " % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(NULL);" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(201) + + sql = "select %s from table_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL) ORDER BY ts DESC;" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(201) + sql = "select %s from table_2 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL) ORDER BY ts DESC;" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(201) + sql = "select %s from table_3 " % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(NULL) ORDER BY ts DESC;" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(201) + + sql = "select %s from table_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL);" % (self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(2) + sql = "select %s from table_2 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL);" % (self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(2) + sql = "select %s from table_3 " % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(NULL);" % (self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(2) + + sql = "select %s from table_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL);" % (self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(51) + sql = "select %s from table_2 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL);" % (self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(51) + sql = "select %s from table_3 " % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(NULL);" % (self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(51) + + # EVERY(1s) + sql = "select %s from table_1 EVERY(1s);" % interp_select + datacheck = self.regular1_checkall_0(sql) + datacheck = self.regular1_checkall_20(sql) + sql = "select %s from table_2 EVERY(1s);" % interp_select + datacheck = self.regular2_checkall_0(sql) + datacheck = self.regular2_checkall_20(sql) + sql = "select %s from table_3 EVERY(1s);" % interp_select + datacheck = self.regular3_checkall_0(sql) + datacheck = self.regular3_checkall_20(sql) + + sql = "select %s from table_1 " % interp_select + sql += "range('%s' , '%s') EVERY(1s);" % (self.ts - 10000 , self.ts + 100000) + datacheck = self.regular1_checkall_0(sql) + datacheck = self.regular1_checkall_20(sql) + sql = "select %s from table_2 " % interp_select + sql += "range('%s' , '%s') EVERY(1s);" % (self.ts - 10000 , self.ts + 100000) + datacheck = self.regular2_checkall_0(sql) + datacheck = self.regular2_checkall_20(sql) + sql = "select %s from table_3 " % interp_select + sql += "range('%s' , '%s') EVERY(1s);" % (self.ts - 10000 , self.ts + 100000) + datacheck = self.regular3_checkall_0(sql) + datacheck = self.regular3_checkall_20(sql) + + sql = "select %s from table_1 " % interp_select + sql += "range('%s' , '%s') EVERY(1s);" % (self.ts - 10000 , self.ts - 9900) + datacheck = self.result_0(sql) + sql = "select %s from table_2 " % interp_select + sql += "range('%s' , '%s') EVERY(1s);" % (self.ts - 10000 , self.ts - 9900) + datacheck = self.result_0(sql) + sql = "select %s from table_3 " % interp_select + sql += "range('%s' , '%s') EVERY(1s);" % (self.ts - 10000 , self.ts - 9900) + datacheck = self.result_0(sql) + + sql = "select %s from table_1 " % interp_select + sql += "range('%s' , '%s') EVERY(1s);" % (self.ts , self.ts) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(1) + sql = "select %s from table_2 " % interp_select + sql += "range('%s' , '%s') EVERY(1s);" % (self.ts , self.ts) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(1) + sql = "select %s from table_3 " % interp_select + sql += "range('%s' , '%s') EVERY(1s);" % (self.ts , self.ts) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(1) + + sql = "select %s from table_1 " % interp_select + sql += "range('%s' , '%s') EVERY(1s);" % (self.ts + 10000 , self.ts + 25000) + datacheck = self.regular1_checkall_0_NEXT(sql) + tdSql.checkRows(7) + sql = "select %s from table_2 " % interp_select + sql += "range('%s' , '%s') EVERY(1s);" % (self.ts + 10000 , self.ts + 25000) + datacheck = self.regular2_checkall_0_NEXT(sql) + tdSql.checkRows(7) + sql = "select %s from table_3 " % interp_select + sql += "range('%s' , '%s') EVERY(1s);" % (self.ts + 10000 , self.ts + 25000) + datacheck = self.regular3_checkall_0_NEXT(sql) + tdSql.checkRows(7) + + sql = "select %s from table_1 " % interp_select + sql += "range('%s' , '%s') EVERY(1s);" % (self.ts + 150000 , self.ts + 200000) + datacheck = self.result_0(sql) + sql = "select %s from table_2 " % interp_select + sql += "range('%s' , '%s') EVERY(1s);" % (self.ts + 150000 , self.ts + 200000) + datacheck = self.result_0(sql) + sql = "select %s from table_3 " % interp_select + sql += "range('%s' , '%s') EVERY(1s);" % (self.ts + 150000 , self.ts + 200000) + datacheck = self.result_0(sql) + + # EVERY(2s) + sql = "select %s from table_1 EVERY(2s);" % interp_select + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(14) + sql = "select %s from table_2 EVERY(2s);" % interp_select + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(14) + sql = "select %s from table_3 EVERY(2s);" % interp_select + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(14) + + sql = "select %s from table_1 " % interp_select + sql += "range('%s' , '%s') EVERY(2s);" % (self.ts - 10000 , self.ts + 100000) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(14) + sql = "select %s from table_2 " % interp_select + sql += "range('%s' , '%s') EVERY(2s);" % (self.ts - 10000 , self.ts + 100000) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(14) + sql = "select %s from table_3 " % interp_select + sql += "range('%s' , '%s') EVERY(2s);" % (self.ts - 10000 , self.ts + 100000) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(14) + + sql = "select %s from table_1 " % interp_select + sql += "range('%s' , '%s') EVERY(2s);" % (self.ts - 10000 , self.ts - 9900) + datacheck = self.result_0(sql) + sql = "select %s from table_2 " % interp_select + sql += "range('%s' , '%s') EVERY(2s);" % (self.ts - 10000 , self.ts - 9900) + datacheck = self.result_0(sql) + sql = "select %s from table_3 " % interp_select + sql += "range('%s' , '%s') EVERY(2s);" % (self.ts - 10000 , self.ts - 9900) + datacheck = self.result_0(sql) + + sql = "select %s from table_1 " % interp_select + sql += "range('%s' , '%s') EVERY(2s);" % (self.ts , self.ts) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(1) + sql = "select %s from table_2 " % interp_select + sql += "range('%s' , '%s') EVERY(2s);" % (self.ts , self.ts) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(1) + sql = "select %s from table_3 " % interp_select + sql += "range('%s' , '%s') EVERY(2s);" % (self.ts , self.ts) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(1) + + sql = "select %s from table_1 " % interp_select + sql += "range('%s' , '%s') EVERY(2s);" % (self.ts + 10000 , self.ts + 25000) + datacheck = self.regular1_checkall_0_NEXT(sql) + tdSql.checkRows(5) + sql = "select %s from table_2 " % interp_select + sql += "range('%s' , '%s') EVERY(2s);" % (self.ts + 10000 , self.ts + 25000) + datacheck = self.regular2_checkall_0_NEXT(sql) + tdSql.checkRows(5) + sql = "select %s from table_3 " % interp_select + sql += "range('%s' , '%s') EVERY(2s);" % (self.ts + 10000 , self.ts + 25000) + datacheck = self.regular3_checkall_0_NEXT(sql) + tdSql.checkRows(5) + + sql = "select %s from table_1 " % interp_select + sql += "range('%s' , '%s') EVERY(2s);" % (self.ts + 150000 , self.ts + 200000) + datacheck = self.result_0(sql) + sql = "select %s from table_2 " % interp_select + sql += "range('%s' , '%s') EVERY(2s);" % (self.ts + 150000 , self.ts + 200000) + datacheck = self.result_0(sql) + sql = "select %s from table_3 " % interp_select + sql += "range('%s' , '%s') EVERY(2s);" % (self.ts + 150000 , self.ts + 200000) + datacheck = self.result_0(sql) + + # EVERY(5s) + sql = "select %s from table_1 EVERY(5s);" % interp_select + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(11) + sql = "select %s from table_2 EVERY(5s);" % interp_select + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(11) + sql = "select %s from table_3 EVERY(5s);" % interp_select + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(11) + + # EVERY(100s) + sql = "select %s from table_1 EVERY(100s);" % interp_select + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(1) + sql = "select %s from table_2 EVERY(100s);" % interp_select + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(1) + sql = "select %s from table_3 EVERY(100s);" % interp_select + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(1) + + # error + tdSql.error("select interp(*) from table_1") + tdSql.error("select interp(*) from table_2 FILL(NEXT)") + sql = "select interp(*) from table_3 where ts >= '%s' FILL(NULL);" % self.ts + tdSql.error(sql) + sql = "select interp(*) from table_1 where ts <= '%s' FILL(LINEAR);" % self.ts + tdSql.error(sql) + sql = "select interp(*) from table_2 where ts > '%s' and ts < now every(1s) fill(PREV);" % self.ts + tdSql.error(sql) + + sql = "select %s from table_1 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL (LINEAR);" % (self.ts + 150000 , self.ts + 100000) + tdSql.error(sql) + sql = "select %s from table_2 " % interp_select + sql += "range('%s' , '%s') EVERY(2s) FILL (PREV);" % (self.ts + 150000 , self.ts - 100000) + tdSql.error(sql) + sql = "select %s from table_3 " % interp_select + sql += "range('%s' , '%s') EVERY(5s) FILL (NEXT);" % (self.ts - 150000 , self.ts - 200000) + tdSql.error(sql) + + sql = "select %s from table_1 " % interp_select + sql += "range('%s' , '%s') EVERY(10s) FILL (NULL);" % (self.ts + 150000 , self.ts + 100000) + tdSql.error(sql) + sql = "select %s from table_2 " % interp_select + sql += "range('%s' , '%s') EVERY(60s) FILL (VALUE,100);" % (self.ts + 150000 , self.ts - 100000) + tdSql.error(sql) + sql = "select %s from table_3 " % interp_select + sql += "range('%s' , '%s') EVERY(120s) FILL (LINEAR) ORDER BY ts DESC;" % (self.ts - 150000 , self.ts - 200000) + tdSql.error(sql) + + # Nested Query + interp_select = 'interp(q_int),interp(q_bigint),interp(q_smallint),interp(q_tinyint),interp(q_float),interp(q_double),\ + interp(q_int_null),interp(q_bigint_null),interp(q_smallint_null),interp(q_tinyint_null),interp(q_float_null),interp(q_double_null),\ + interp(q_int,q_bigint,q_smallint,q_tinyint,q_float,q_double),interp(q_int_null,q_bigint_null,q_smallint_null,q_tinyint_null,q_float_null,q_double_null)' + + sql = "select * from (select %s from table_1) ;" % interp_select + datacheck = self.regular1_checkall_0(sql) + sql = "select * from (select %s from table_2) ;" % interp_select + datacheck = self.regular2_checkall_0(sql) + sql = "select * from (select %s from table_3) ;" % interp_select + datacheck = self.regular3_checkall_0(sql) + + sql = "select %s from (select * from table_1) ;" % interp_select + datacheck = self.regular1_checkall_0(sql) + sql = "select %s from (select * from table_2) ;" % interp_select + datacheck = self.regular2_checkall_0(sql) + sql = "select %s from (select * from table_3) ;" % interp_select + datacheck = self.regular3_checkall_0(sql) + + # Nested Query + where + range + FILL(LINEAR) + EVERY( s) (1) + sql = "select * from (select %s from table_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR));" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(11) + sql = "select * from (select %s from table_2 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR));" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(11) + sql = "select * from (select %s from table_3 " % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR));" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(11) + + sql = "select * from (select %s from table_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR));" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + datacheck = self.result_0(sql) + sql = "select * from (select %s from table_2 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR));" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + datacheck = self.result_0(sql) + sql = "select * from (select %s from table_3 " % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR));" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + datacheck = self.result_0(sql) + + sql = "select * from (select %s from table_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR));" % (self.ts , self.ts + 10000 , self.ts , self.ts) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(1) + sql = "select * from (select %s from table_2 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR));" % (self.ts , self.ts + 10000 , self.ts , self.ts) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(1) + sql = "select * from (select %s from table_3 " % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR));" % (self.ts , self.ts + 10000 , self.ts , self.ts) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(1) + + sql = "select * from (select %s from table_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR));" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(11) + sql = "select * from (select %s from table_2 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR));" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(11) + sql = "select * from (select %s from table_3 " % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR));" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(11) + + sql = "select * from (select %s from table_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR) ORDER BY ts DESC);" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0_NEXT(sql) + tdSql.checkRows(11) + sql = "select * from (select %s from table_2 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR) ORDER BY ts DESC);" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular2_checkall_0_NEXT(sql) + tdSql.checkRows(11) + sql = "select * from (select %s from table_3 " % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR) ORDER BY ts DESC);" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular3_checkall_0_NEXT(sql) + tdSql.checkRows(11) + + sql = "select * from (select %s from table_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR));" % (self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + datacheck = self.regular1_checkall_0_LINEAR(sql) + tdSql.checkRows(2) + sql = "select * from (select %s from table_2 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR));" % (self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + datacheck = self.regular2_checkall_0_LINEAR(sql) + tdSql.checkRows(2) + sql = "select * from (select %s from table_3 " % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR));" % (self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + datacheck = self.regular3_checkall_0_LINEAR(sql) + tdSql.checkRows(2) + + sql = "select * from (select %s from table_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR));" % (self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + datacheck = self.result_0(sql) + sql = "select * from (select %s from table_2 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR));" % (self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + datacheck = self.result_0(sql) + sql = "select * from (select %s from table_3 " % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR));" % (self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + datacheck = self.result_0(sql) + + # Nested Query + where + range + FILL(LINEAR) + EVERY( s)(2) + sql = "select %s from (select * from table_1 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(11) + sql = "select %s from (select * from table_2 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(11) + sql = "select %s from (select * from table_3 )" % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(11) + + sql = "select %s from (select * from table_1 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + datacheck = self.result_0(sql) + sql = "select %s from (select * from table_2 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + datacheck = self.result_0(sql) + sql = "select %s from (select * from table_3 )" % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + datacheck = self.result_0(sql) + + sql = "select %s from (select * from table_1 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR);" % (self.ts , self.ts + 10000 , self.ts , self.ts) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(1) + sql = "select %s from (select * from table_2 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR);" % (self.ts , self.ts + 10000 , self.ts , self.ts) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(1) + sql = "select %s from (select * from table_3 )" % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR);" % (self.ts , self.ts + 10000 , self.ts , self.ts) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(1) + + sql = "select %s from (select * from table_1 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR);" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(11) + sql = "select %s from (select * from table_2 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR);" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(11) + sql = "select %s from (select * from table_3 )" % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR);" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(11) + + sql = "select %s from (select * from table_1 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR);" % (self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + datacheck = self.regular1_checkall_0_LINEAR(sql) + tdSql.checkRows(2) + sql = "select %s from (select * from table_2 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR);" % (self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + datacheck = self.regular2_checkall_0_LINEAR(sql) + tdSql.checkRows(2) + sql = "select %s from (select * from table_3 )" % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR);" % (self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + datacheck = self.regular3_checkall_0_LINEAR(sql) + tdSql.checkRows(2) + + sql = "select %s from (select * from table_1 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR);" % (self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + datacheck = self.result_0(sql) + sql = "select %s from (select * from table_2 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR);" % (self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + datacheck = self.result_0(sql) + sql = "select %s from (select * from table_3 )" % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR);" % (self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + datacheck = self.result_0(sql) + + # Nested Query + where + range + FILL(LINEAR) + EVERY( s)(3) + sql = "select * from (select %s from table_1 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR)) z1," % (interp_select , self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + sql += "(select %s from table_2 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR)) z2 where z1.ts=z2.ts ;" % (interp_select , self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(11) + + sql = "select * from (select %s from table_2 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR)) z1," % (interp_select , self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + sql += "(select %s from table_3 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR)) z2 where z1.ts=z2.ts ;" % (interp_select , self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + datacheck = self.result_0(sql) + + sql = "select * from (select %s from table_3 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR)) z1," % (interp_select , self.ts , self.ts + 10000 , self.ts , self.ts) + sql += "(select %s from table_1 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR)) z2 where z1.ts=z2.ts ;" % (interp_select , self.ts , self.ts + 10000 , self.ts , self.ts) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(1) + + sql = "select * from (select %s from table_1 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR)) z1," % (interp_select , self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + sql += "(select %s from table_2 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR)) z2 where z1.ts=z2.ts ;" % (interp_select , self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(11) + + sql = "select * from (select %s from table_2 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR)) z1," % (interp_select , self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + sql += "(select %s from table_3 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR)) z2 where z1.ts=z2.ts ;" % (interp_select , self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + datacheck = self.regular2_checkall_0_LINEAR(sql) + tdSql.checkRows(2) + + sql = "select * from (select %s from table_3 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR)) z1," % (interp_select , self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + sql += "(select %s from table_1 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR)) z2 where z1.ts=z2.ts ;" % (interp_select , self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + datacheck = self.result_0(sql) + + # Nested Query + where + range + FILL(NEXT) + EVERY( s) (1) + sql = "select * from (select %s from table_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT));" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(21) + sql = "select * from (select %s from table_2 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT));" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(21) + sql = "select * from (select %s from table_3 " % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT));" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(21) + + sql = "select * from (select %s from table_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT));" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(1) + sql = "select * from (select %s from table_2 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT));" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(1) + sql = "select * from (select %s from table_3 " % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT));" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(1) + + sql = "select * from (select %s from table_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT));" % (self.ts , self.ts + 10000 , self.ts , self.ts) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(1) + sql = "select * from (select %s from table_2 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT));" % (self.ts , self.ts + 10000 , self.ts , self.ts) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(1) + sql = "select * from (select %s from table_3 " % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT));" % (self.ts , self.ts + 10000 , self.ts , self.ts) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(1) + + sql = "select * from (select %s from table_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT));" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(11) + sql = "select * from (select %s from table_2 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT));" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(11) + sql = "select * from (select %s from table_3 " % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT));" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(11) + + sql = "select * from (select %s from table_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT) ORDER BY ts DESC);" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0_NEXT(sql) + tdSql.checkRows(11) + sql = "select * from (select %s from table_2 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT) ORDER BY ts DESC);" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular2_checkall_0_NEXT(sql) + tdSql.checkRows(11) + sql = "select * from (select %s from table_3 " % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT) ORDER BY ts DESC);" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular3_checkall_0_NEXT(sql) + tdSql.checkRows(11) + + sql = "select * from (select %s from table_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT));" % (self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + datacheck = self.regular1_checkall_0_NEXT(sql) + tdSql.checkRows(2) + sql = "select * from (select %s from table_2 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT));" % (self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + datacheck = self.regular2_checkall_0_NEXT(sql) + tdSql.checkRows(2) + sql = "select * from (select %s from table_3 " % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT));" % (self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + datacheck = self.regular3_checkall_0_NEXT(sql) + tdSql.checkRows(2) + + sql = "select * from (select %s from table_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT));" % (self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + datacheck = self.result_0(sql) + sql = "select * from (select %s from table_2 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT));" % (self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + datacheck = self.result_0(sql) + sql = "select * from (select %s from table_3 " % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT));" % (self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + datacheck = self.result_0(sql) + + # Nested Query + where + range + FILL(NEXT) + EVERY( s)(2) + sql = "select %s from (select * from table_1 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(21) + sql = "select %s from (select * from table_2 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(21) + sql = "select %s from (select * from table_3 )" % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(21) + + sql = "select %s from (select * from table_1 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(1) + sql = "select %s from (select * from table_2 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(1) + sql = "select %s from (select * from table_3 )" % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(1) + + sql = "select %s from (select * from table_1 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT);" % (self.ts , self.ts + 10000 , self.ts , self.ts) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(1) + sql = "select %s from (select * from table_2 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT);" % (self.ts , self.ts + 10000 , self.ts , self.ts) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(1) + sql = "select %s from (select * from table_3 )" % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT);" % (self.ts , self.ts + 10000 , self.ts , self.ts) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(1) + + sql = "select %s from (select * from table_1 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT);" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(11) + sql = "select %s from (select * from table_2 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT);" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(11) + sql = "select %s from (select * from table_3 )" % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT);" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(11) + + sql = "select %s from (select * from table_1 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT);" % (self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + datacheck = self.regular1_checkall_0_NEXT(sql) + tdSql.checkRows(2) + sql = "select %s from (select * from table_2 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT);" % (self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + datacheck = self.regular2_checkall_0_NEXT(sql) + tdSql.checkRows(2) + sql = "select %s from (select * from table_3 )" % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT);" % (self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + datacheck = self.regular3_checkall_0_NEXT(sql) + tdSql.checkRows(2) + + sql = "select %s from (select * from table_1 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT);" % (self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + datacheck = self.result_0(sql) + sql = "select %s from (select * from table_2 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT);" % (self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + datacheck = self.result_0(sql) + sql = "select %s from (select * from table_3 )" % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT);" % (self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + datacheck = self.result_0(sql) + + # Nested Query + where + range + FILL(NEXT) + EVERY( s)(3) + sql = "select * from (select %s from table_1 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT)) z1," % (interp_select , self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + sql += "(select %s from table_2 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT)) z2 where z1.ts=z2.ts ;" % (interp_select , self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(21) + + sql = "select * from (select %s from table_2 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT)) z1," % (interp_select , self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + sql += "(select %s from table_3 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT)) z2 where z1.ts=z2.ts ;" % (interp_select , self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(1) + + sql = "select * from (select %s from table_3 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT)) z1," % (interp_select , self.ts , self.ts + 10000 , self.ts , self.ts) + sql += "(select %s from table_1 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT)) z2 where z1.ts=z2.ts ;" % (interp_select , self.ts , self.ts + 10000 , self.ts , self.ts) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(1) + + sql = "select * from (select %s from table_1 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT)) z1," % (interp_select , self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + sql += "(select %s from table_2 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT)) z2 where z1.ts=z2.ts ;" % (interp_select , self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(11) + + sql = "select * from (select %s from table_2 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT)) z1," % (interp_select , self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + sql += "(select %s from table_3 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT)) z2 where z1.ts=z2.ts ;" % (interp_select , self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + datacheck = self.regular2_checkall_0_NEXT(sql) + tdSql.checkRows(2) + + sql = "select * from (select %s from table_3 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT)) z1," % (interp_select , self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + sql += "(select %s from table_1 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT)) z2 where z1.ts=z2.ts ;" % (interp_select , self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + datacheck = self.result_0(sql) + + # Nested Query + where + range + FILL(PREV) + EVERY( s) (1) + sql = "select * from (select %s from table_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV));" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(101) + sql = "select * from (select %s from table_2 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV));" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(101) + sql = "select * from (select %s from table_3 " % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(PREV));" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(101) + + sql = "select * from (select %s from table_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV));" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + datacheck = self.result_0(sql) + sql = "select * from (select %s from table_2 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV));" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + datacheck = self.result_0(sql) + sql = "select * from (select %s from table_3 " % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(PREV));" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + datacheck = self.result_0(sql) + + sql = "select * from (select %s from table_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV));" % (self.ts , self.ts + 10000 , self.ts , self.ts) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(1) + sql = "select * from (select %s from table_2 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV));" % (self.ts , self.ts + 10000 , self.ts , self.ts) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(1) + sql = "select * from (select %s from table_3 " % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(PREV));" % (self.ts , self.ts + 10000 , self.ts , self.ts) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(1) + + sql = "select * from (select %s from table_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV));" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(201) + sql = "select * from (select %s from table_2 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV));" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(201) + sql = "select * from (select %s from table_3 " % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(PREV));" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(201) + + sql = "select * from (select %s from table_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV) ORDER BY ts DESC);" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0_NEXT(sql) + tdSql.checkRows(201) + sql = "select * from (select %s from table_2 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV) ORDER BY ts DESC);" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular2_checkall_0_NEXT(sql) + tdSql.checkRows(201) + sql = "select * from (select %s from table_3 " % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(PREV) ORDER BY ts DESC);" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular3_checkall_0_NEXT(sql) + tdSql.checkRows(201) + + sql = "select * from (select %s from table_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV));" % (self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(2) + sql = "select * from (select %s from table_2 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV));" % (self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(2) + sql = "select * from (select %s from table_3 " % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(PREV));" % (self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(2) + + sql = "select * from (select %s from table_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV));" % (self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + datacheck = self.regular1_checkall_0_NEXT(sql) + tdSql.checkRows(51) + sql = "select * from (select %s from table_2 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV));" % (self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + datacheck = self.regular2_checkall_0_NEXT(sql) + tdSql.checkRows(51) + sql = "select * from (select %s from table_3 " % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(PREV));" % (self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + datacheck = self.regular3_checkall_0_NEXT(sql) + tdSql.checkRows(51) + + # Nested Query + where + range + FILL(PREV) + EVERY( s)(2) + sql = "select %s from (select * from table_1 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(101) + sql = "select %s from (select * from table_2 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(101) + sql = "select %s from (select * from table_3 )" % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(PREV);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(101) + + sql = "select %s from (select * from table_1 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + datacheck = self.result_0(sql) + sql = "select %s from (select * from table_2 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + datacheck = self.result_0(sql) + sql = "select %s from (select * from table_3 )" % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(PREV);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + datacheck = self.result_0(sql) + + sql = "select %s from (select * from table_1 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV);" % (self.ts , self.ts + 10000 , self.ts , self.ts) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(1) + sql = "select %s from (select * from table_2 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV);" % (self.ts , self.ts + 10000 , self.ts , self.ts) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(1) + sql = "select %s from (select * from table_3 )" % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(PREV);" % (self.ts , self.ts + 10000 , self.ts , self.ts) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(1) + + sql = "select %s from (select * from table_1 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV);" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(201) + sql = "select %s from (select * from table_2 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV);" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(201) + sql = "select %s from (select * from table_3 )" % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(PREV);" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(201) + + sql = "select %s from (select * from table_1 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV);" % (self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(2) + sql = "select %s from (select * from table_2 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV);" % (self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(2) + sql = "select %s from (select * from table_3 )" % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(PREV);" % (self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(2) + + sql = "select %s from (select * from table_1 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV);" % (self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + datacheck = self.regular1_checkall_0_NEXT(sql) + tdSql.checkRows(51) + sql = "select %s from (select * from table_2 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV);" % (self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + datacheck = self.regular2_checkall_0_NEXT(sql) + tdSql.checkRows(51) + sql = "select %s from (select * from table_3 )" % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(PREV);" % (self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + datacheck = self.regular3_checkall_0_NEXT(sql) + tdSql.checkRows(51) + + # Nested Query + where + range + FILL(PREV) + EVERY( s)(3) + sql = "select * from (select %s from table_1 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV)) z1," % (interp_select , self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + sql += "(select %s from table_2 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV)) z2 where z1.ts=z2.ts ;" % (interp_select , self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(101) + + sql = "select * from (select %s from table_2 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV)) z1," % (interp_select , self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + sql += "(select %s from table_3 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV)) z2 where z1.ts=z2.ts ;" % (interp_select , self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + datacheck = self.result_0(sql) + + sql = "select * from (select %s from table_3 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV)) z1," % (interp_select , self.ts , self.ts + 10000 , self.ts , self.ts) + sql += "(select %s from table_1 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV)) z2 where z1.ts=z2.ts ;" % (interp_select , self.ts , self.ts + 10000 , self.ts , self.ts) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(1) + + sql = "select * from (select %s from table_1 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV)) z1," % (interp_select , self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + sql += "(select %s from table_2 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV)) z2 where z1.ts=z2.ts ;" % (interp_select , self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(201) + + sql = "select * from (select %s from table_2 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV)) z1," % (interp_select , self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + sql += "(select %s from table_3 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV)) z2 where z1.ts=z2.ts ;" % (interp_select , self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(2) + + sql = "select * from (select %s from table_3 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV)) z1," % (interp_select , self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + sql += "(select %s from table_1 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV)) z2 where z1.ts=z2.ts ;" % (interp_select , self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + datacheck = self.regular3_checkall_0_NEXT(sql) + tdSql.checkRows(51) + + # Nested Query + where + range + FILL(VALUE, 100) + EVERY( s) (1) + sql = "select * from (select %s from table_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100));" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(111) + sql = "select * from (select %s from table_2 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100));" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(111) + sql = "select * from (select %s from table_3 " % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100));" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(111) + + sql = "select * from (select %s from table_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100));" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(1) + sql = "select * from (select %s from table_2 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100));" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(1) + sql = "select * from (select %s from table_3 " % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100));" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(1) + + sql = "select * from (select %s from table_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100));" % (self.ts , self.ts + 10000 , self.ts , self.ts) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(1) + sql = "select * from (select %s from table_2 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100));" % (self.ts , self.ts + 10000 , self.ts , self.ts) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(1) + sql = "select * from (select %s from table_3 " % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100));" % (self.ts , self.ts + 10000 , self.ts , self.ts) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(1) + + sql = "select * from (select %s from table_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100));" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(201) + sql = "select * from (select %s from table_2 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100));" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(201) + sql = "select * from (select %s from table_3 " % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100));" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(201) + + sql = "select * from (select %s from table_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100) ORDER BY ts DESC);" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(201) + sql = "select * from (select %s from table_2 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100) ORDER BY ts DESC);" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(201) + sql = "select * from (select %s from table_3 " % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100) ORDER BY ts DESC);" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(201) + + sql = "select * from (select %s from table_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100));" % (self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(2) + sql = "select * from (select %s from table_2 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100));" % (self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(2) + sql = "select * from (select %s from table_3 " % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100));" % (self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(2) + + sql = "select * from (select %s from table_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100));" % (self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(51) + sql = "select * from (select %s from table_2 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100));" % (self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(51) + sql = "select * from (select %s from table_3 " % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100));" % (self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(51) + + # Nested Query + where + range + FILL(VALUE, 100) + EVERY( s)(2) + sql = "select %s from (select * from table_1 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(111) + sql = "select %s from (select * from table_2 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(111) + sql = "select %s from (select * from table_3 )" % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(111) + + sql = "select %s from (select * from table_1 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(1) + sql = "select %s from (select * from table_2 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(1) + sql = "select %s from (select * from table_3 )" % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(1) + + sql = "select %s from (select * from table_1 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100);" % (self.ts , self.ts + 10000 , self.ts , self.ts) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(1) + sql = "select %s from (select * from table_2 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100);" % (self.ts , self.ts + 10000 , self.ts , self.ts) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(1) + sql = "select %s from (select * from table_3 )" % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100);" % (self.ts , self.ts + 10000 , self.ts , self.ts) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(1) + + sql = "select %s from (select * from table_1 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100);" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(201) + sql = "select %s from (select * from table_2 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100);" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(201) + sql = "select %s from (select * from table_3 )" % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100);" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(201) + + sql = "select %s from (select * from table_1 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100);" % (self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(2) + sql = "select %s from (select * from table_2 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100);" % (self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(2) + sql = "select %s from (select * from table_3 )" % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100);" % (self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(2) + + sql = "select %s from (select * from table_1 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100);" % (self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(51) + sql = "select %s from (select * from table_2 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100);" % (self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(51) + sql = "select %s from (select * from table_3 )" % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100);" % (self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(51) + + # Nested Query + where + range + FILL(VALUE, 100) + EVERY( s)(3) + sql = "select * from (select %s from table_1 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100)) z1," % (interp_select , self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + sql += "(select %s from table_2 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100)) z2 where z1.ts=z2.ts ;" % (interp_select , self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(111) + + sql = "select * from (select %s from table_2 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100)) z1," % (interp_select , self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + sql += "(select %s from table_3 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100)) z2 where z1.ts=z2.ts ;" % (interp_select , self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(1) + + sql = "select * from (select %s from table_3 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100)) z1," % (interp_select , self.ts , self.ts + 10000 , self.ts , self.ts) + sql += "(select %s from table_1 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100)) z2 where z1.ts=z2.ts ;" % (interp_select , self.ts , self.ts + 10000 , self.ts , self.ts) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(1) + + sql = "select * from (select %s from table_1 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100)) z1," % (interp_select , self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + sql += "(select %s from table_2 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100)) z2 where z1.ts=z2.ts ;" % (interp_select , self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(201) + + sql = "select * from (select %s from table_2 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100)) z1," % (interp_select , self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + sql += "(select %s from table_3 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100)) z2 where z1.ts=z2.ts ;" % (interp_select , self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(2) + + sql = "select * from (select %s from table_3 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100)) z1," % (interp_select , self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + sql += "(select %s from table_1 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100)) z2 where z1.ts=z2.ts ;" % (interp_select , self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(51) + + # Nested Query + where + range + FILL(NULL) + EVERY( s) (1) + sql = "select * from (select %s from table_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL));" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(111) + sql = "select * from (select %s from table_2 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL));" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(111) + sql = "select * from (select %s from table_3 " % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(NULL));" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(111) + + sql = "select * from (select %s from table_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL));" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(1) + sql = "select * from (select %s from table_2 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL));" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(1) + sql = "select * from (select %s from table_3 " % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(NULL));" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(1) + + sql = "select * from (select %s from table_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL));" % (self.ts , self.ts + 10000 , self.ts , self.ts) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(1) + sql = "select * from (select %s from table_2 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL));" % (self.ts , self.ts + 10000 , self.ts , self.ts) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(1) + sql = "select * from (select %s from table_3 " % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(NULL));" % (self.ts , self.ts + 10000 , self.ts , self.ts) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(1) + + sql = "select * from (select %s from table_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL));" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(201) + sql = "select * from (select %s from table_2 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL));" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(201) + sql = "select * from (select %s from table_3 " % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(NULL));" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(201) + + sql = "select * from (select %s from table_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL) ORDER BY ts DESC);" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(201) + sql = "select * from (select %s from table_2 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL) ORDER BY ts DESC);" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(201) + sql = "select * from (select %s from table_3 " % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(NULL) ORDER BY ts DESC);" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(201) + + sql = "select * from (select %s from table_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL));" % (self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(2) + sql = "select * from (select %s from table_2 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL));" % (self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(2) + sql = "select * from (select %s from table_3 " % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(NULL));" % (self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(2) + + sql = "select * from (select %s from table_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL));" % (self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(51) + sql = "select * from (select %s from table_2 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL));" % (self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(51) + sql = "select * from (select %s from table_3 " % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(NULL));" % (self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(51) + + # Nested Query + where + range + FILL(NULL) + EVERY( s)(2) + sql = "select %s from (select * from table_1 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(111) + sql = "select %s from (select * from table_2 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(111) + sql = "select %s from (select * from table_3 )" % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(NULL);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(111) + + sql = "select %s from (select * from table_1 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(1) + sql = "select %s from (select * from table_2 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(1) + sql = "select %s from (select * from table_3 )" % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(NULL);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(1) + + sql = "select %s from (select * from table_1 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL);" % (self.ts , self.ts + 10000 , self.ts , self.ts) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(1) + sql = "select %s from (select * from table_2 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL);" % (self.ts , self.ts + 10000 , self.ts , self.ts) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(1) + sql = "select %s from (select * from table_3 )" % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(NULL);" % (self.ts , self.ts + 10000 , self.ts , self.ts) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(1) + + sql = "select %s from (select * from table_1 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL);" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(201) + sql = "select %s from (select * from table_2 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL);" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(201) + sql = "select %s from (select * from table_3 )" % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(NULL);" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(201) + + sql = "select %s from (select * from table_1 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL);" % (self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(2) + sql = "select %s from (select * from table_2 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL);" % (self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(2) + sql = "select %s from (select * from table_3 )" % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(NULL);" % (self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(2) + + sql = "select %s from (select * from table_1 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL);" % (self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(51) + sql = "select %s from (select * from table_2 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL);" % (self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(51) + sql = "select %s from (select * from table_3 )" % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(NULL);" % (self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(51) + + # Nested Query + where + range + FILL(NULL) + EVERY( s)(3) + sql = "select * from (select %s from table_1 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL)) z1," % (interp_select , self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + sql += "(select %s from table_2 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL)) z2 where z1.ts=z2.ts ;" % (interp_select , self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(111) + + sql = "select * from (select %s from table_2 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL)) z1," % (interp_select , self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + sql += "(select %s from table_3 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL)) z2 where z1.ts=z2.ts ;" % (interp_select , self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(1) + + sql = "select * from (select %s from table_3 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL)) z1," % (interp_select , self.ts , self.ts + 10000 , self.ts , self.ts) + sql += "(select %s from table_1 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL)) z2 where z1.ts=z2.ts ;" % (interp_select , self.ts , self.ts + 10000 , self.ts , self.ts) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(1) + + sql = "select * from (select %s from table_1 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL)) z1," % (interp_select , self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + sql += "(select %s from table_2 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL)) z2 where z1.ts=z2.ts ;" % (interp_select , self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(201) + + sql = "select * from (select %s from table_2 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL)) z1," % (interp_select , self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + sql += "(select %s from table_3 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL)) z2 where z1.ts=z2.ts ;" % (interp_select , self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(2) + + sql = "select * from (select %s from table_3 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL)) z1," % (interp_select , self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + sql += "(select %s from table_1 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL)) z2 where z1.ts=z2.ts ;" % (interp_select , self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(51) + + print("==============step3, super table ==============") + + dcDB = self.dropandcreateDB() + + dcRestart = self.restartDnodes() + + dcDB = self.dropandcreateDB_null() + + interp_select = 'interp(q_int),interp(q_bigint),interp(q_smallint),interp(q_tinyint),interp(q_float),interp(q_double),\ + interp(q_int_null),interp(q_bigint_null),interp(q_smallint_null),interp(q_tinyint_null),interp(q_float_null),interp(q_double_null),\ + interp(q_int,q_bigint,q_smallint,q_tinyint,q_float,q_double),interp(q_int_null,q_bigint_null,q_smallint_null,q_tinyint_null,q_float_null,q_double_null),loc' + + sql = "select * from stable_1 ;" + datacheck = self.regular1_checkall_0_base(sql) + tdSql.checkRows(57) + datacheck = self.regular1_checkall_20_base(sql) + + sql = "select %s from stable_1 group by tbname;" % interp_select + datacheck = self.regular1_checkall_0(sql) + sql = "select %s from stable_1 where tbname in ('table_2') group by tbname;" % interp_select + datacheck = self.regular2_checkall_0(sql) + sql = "select %s from stable_1 where tbname in ('table_3') group by tbname;" % interp_select + datacheck = self.regular3_checkall_0(sql) + + sql = "select %s from stable_1 group by tbname ORDER BY ts DESC;" % interp_select + datacheck = self.regular1_checkall_0(sql) + sql = "select %s from stable_1 where tbname in ('table_2') group by tbname ORDER BY ts DESC;" % interp_select + datacheck = self.regular2_checkall_0(sql) + sql = "select %s from stable_1 where tbname in ('table_3') group by tbname ORDER BY ts DESC;" % interp_select + datacheck = self.regular3_checkall_0(sql) + + sql = "select %s from stable_1 where " % interp_select + sql += "ts > %s group by tbname ;" % (self.ts - 10) + datacheck = self.regular1_checkall_0(sql) + sql = "select %s from stable_1 where " % interp_select + sql += "ts > %s and tbname in ('table_2') group by tbname ;" % (self.ts - 10) + datacheck = self.regular2_checkall_0(sql) + sql = "select %s from stable_1 where " % interp_select + sql += "ts > %s and tbname in ('table_3') group by tbname ;" % (self.ts - 10) + datacheck = self.regular3_checkall_0(sql) + + sql = "select %s from stable_1 where " % interp_select + sql += "ts > %s group by tbname ;" % (self.ts + 85000) + datacheck = self.regular1_checkall_9(sql) + sql = "select %s from stable_1 where " % interp_select + sql += "ts > %s and tbname in ('table_2') group by tbname;" % (self.ts + 85000) + datacheck = self.regular2_checkall_9(sql) + sql = "select %s from stable_1 where " % interp_select + sql += "ts > %s and tbname in ('table_3') group by tbname;" % (self.ts + 85000) + datacheck = self.regular3_checkall_9(sql) + + # range + sql = "select %s from stable_1 " % interp_select + sql += "range('%s' , '%s') group by tbname ;" % (self.ts - 10000 , self.ts + 100000) + datacheck = self.result_0(sql) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_2') range('%s' , '%s') group by tbname;" % (self.ts - 10000 , self.ts + 100000) + datacheck = self.result_0(sql) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_3') range('%s' , '%s') group by tbname;" % (self.ts - 10000 , self.ts + 100000) + datacheck = self.result_0(sql) + + sql = "select %s from stable_1 " % interp_select + sql += "range('%s' , '%s') group by tbname ;" % (self.ts - 10000 , self.ts - 9900) + datacheck = self.result_0(sql) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_2') range('%s' , '%s') group by tbname;" % (self.ts - 10000 , self.ts - 9900) + datacheck = self.result_0(sql) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_3') range('%s' , '%s') group by tbname;" % (self.ts - 10000 , self.ts - 9900) + datacheck = self.result_0(sql) + + sql = "select %s from stable_1 " % interp_select + sql += "range('%s' , '%s') group by tbname;" % (self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0(sql) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_2') range('%s' , '%s') group by tbname;" % (self.ts , self.ts + 200000) + datacheck = self.regular2_checkall_0(sql) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_3') range('%s' , '%s') group by tbname;" % (self.ts , self.ts + 200000) + datacheck = self.regular3_checkall_0(sql) + + sql = "select %s from stable_1 " % interp_select + sql += "range('%s' , '%s') group by tbname;" % (self.ts + 1500 , self.ts + 2500) + datacheck = self.result_0(sql) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_2') range('%s' , '%s') group by tbname;" % (self.ts + 1500 , self.ts + 2500) + datacheck = self.result_0(sql) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_3') range('%s' , '%s') group by tbname;" % (self.ts + 1500 , self.ts + 2500) + datacheck = self.result_0(sql) + + sql = "select %s from stable_1 " % interp_select + sql += "range('%s' , '%s') group by tbname;" % (self.ts + 150000 , self.ts + 200000) + datacheck = self.result_0(sql) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_2') range('%s' , '%s') group by tbname;" % (self.ts + 150000 , self.ts + 200000) + datacheck = self.result_0(sql) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_3') range('%s' , '%s') group by tbname;" % (self.ts + 150000 , self.ts + 200000) + datacheck = self.result_0(sql) + + # FILL(LINEAR) + sql = "select %s from stable_1 FILL(LINEAR) group by tbname " % interp_select + datacheck = self.regular1_checkall_0(sql) + sql = "select %s from stable_1 where tbname in ('table_2') FILL(LINEAR) group by tbname " % interp_select + datacheck = self.regular2_checkall_0(sql) + sql = "select %s from stable_1 where tbname in ('table_3') FILL(LINEAR) group by tbname " % interp_select + datacheck = self.regular3_checkall_0(sql) + + sql = "select %s from stable_1 " % interp_select + sql += "range('%s' , '%s') FILL(LINEAR) group by tbname;" % (self.ts - 10000 , self.ts + 100000) + datacheck = self.result_0(sql) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_2') range('%s' , '%s') FILL(LINEAR) group by tbname;" % (self.ts - 10000 , self.ts + 100000) + datacheck = self.result_0(sql) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_3') range('%s' , '%s') FILL(LINEAR) group by tbname;" % (self.ts - 10000 , self.ts + 100000) + datacheck = self.result_0(sql) + + sql = "select %s from stable_1 " % interp_select + sql += "range('%s' , '%s') FILL(LINEAR) group by tbname;" % (self.ts - 10000 , self.ts - 9900) + datacheck = self.result_0(sql) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_2') range('%s' , '%s') FILL(LINEAR) group by tbname;" % (self.ts - 10000 , self.ts - 9900) + datacheck = self.result_0(sql) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_3') range('%s' , '%s') FILL(LINEAR) group by tbname;" % (self.ts - 10000 , self.ts - 9900) + datacheck = self.result_0(sql) + + sql = "select %s from stable_1 " % interp_select + sql += "range('%s' , '%s') FILL(LINEAR) group by tbname;" % (self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0(sql) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_2') range('%s' , '%s') FILL(LINEAR) group by tbname;" % (self.ts , self.ts + 200000) + datacheck = self.regular2_checkall_0(sql) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_3') range('%s' , '%s') FILL(LINEAR) group by tbname;" % (self.ts , self.ts + 200000) + datacheck = self.regular3_checkall_0(sql) + + sql = "select %s from stable_1 " % interp_select + sql += "range('%s' , '%s') FILL(LINEAR) group by tbname;" % (self.ts + 1500 , self.ts + 2500) + datacheck = self.regular1_checkall_0_LINEAR(sql) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_2') range('%s' , '%s') FILL(LINEAR) group by tbname;" % (self.ts + 1500 , self.ts + 2500) + datacheck = self.regular2_checkall_0_LINEAR(sql) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_3') range('%s' , '%s') FILL(LINEAR) group by tbname;" % (self.ts + 1500 , self.ts + 2500) + datacheck = self.regular3_checkall_0_LINEAR(sql) + + sql = "select %s from stable_1 " % interp_select + sql += "range('%s' , '%s') FILL(LINEAR) group by tbname;" % (self.ts + 150000 , self.ts + 200000) + datacheck = self.result_0(sql) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_2') range('%s' , '%s') FILL(LINEAR) group by tbname;" % (self.ts + 150000 , self.ts + 200000) + datacheck = self.result_0(sql) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_3') range('%s' , '%s') FILL(LINEAR) group by tbname;" % (self.ts + 150000 , self.ts + 200000) + datacheck = self.result_0(sql) + + # FILL(LINEAR) + EVERY( s) + sql = "select %s from stable_1 EVERY(1s) FILL(LINEAR) group by tbname;" % interp_select + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(273) + sql = "select %s from stable_1 where tbname in ('table_2') EVERY(1s) FILL(LINEAR) group by tbname;" % interp_select + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(91) + sql = "select %s from stable_1 where tbname in ('table_3') EVERY(1s) FILL(LINEAR) group by tbname;" % interp_select + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(91) + + sql = "select %s from stable_1 EVERY(5s) FILL(LINEAR) group by tbname;" % interp_select + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(57) + sql = "select %s from stable_1 where tbname in ('table_2') EVERY(5s) FILL(LINEAR) group by tbname;" % interp_select + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(19) + sql = "select %s from stable_1 where tbname in ('table_3') EVERY(5s) FILL(LINEAR) group by tbname;" % interp_select + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(19) + + # range + FILL(LINEAR) + EVERY( s) + sql = "select %s from stable_1 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(LINEAR) group by tbname;" % (self.ts - 10000 , self.ts + 100000) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(273) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_2') range('%s' , '%s') EVERY(1s) FILL(LINEAR) group by tbname;" % (self.ts - 10000 , self.ts + 100000) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(91) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_3') range('%s' , '%s') EVERY(1s) FILL(LINEAR) group by tbname;" % (self.ts - 10000 , self.ts + 100000) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(91) + + sql = "select %s from stable_1 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(LINEAR) group by tbname;" % (self.ts - 10000 , self.ts - 9900) + datacheck = self.result_0(sql) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_2') range('%s' , '%s') EVERY(1s) FILL(LINEAR) group by tbname;" % (self.ts - 10000 , self.ts - 9900) + datacheck = self.result_0(sql) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_3') range('%s' , '%s') EVERY(1s) FILL(LINEAR) group by tbname;" % (self.ts - 10000 , self.ts - 9900) + datacheck = self.result_0(sql) + + sql = "select %s from stable_1 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(LINEAR) group by tbname;" % (self.ts , self.ts) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(3) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_2') range('%s' , '%s') EVERY(1s) FILL(LINEAR) group by tbname;" % (self.ts , self.ts) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(1) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_3') range('%s' , '%s') EVERY(1s) FILL(LINEAR) group by tbname;" % (self.ts , self.ts) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(1) + + sql = "select %s from stable_1 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(LINEAR) group by tbname;" % (self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(273) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_2') range('%s' , '%s') EVERY(1s) FILL(LINEAR) group by tbname;" % (self.ts , self.ts + 200000) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(91) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_3') range('%s' , '%s') EVERY(1s) FILL(LINEAR) group by tbname;" % (self.ts , self.ts + 200000) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(91) + + sql = "select %s from stable_1 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(LINEAR) group by tbname ORDER BY ts DESC;" % (self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_9(sql) + tdSql.checkRows(273) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_2') range('%s' , '%s') EVERY(1s) FILL(LINEAR) group by tbname ORDER BY ts DESC;" % (self.ts , self.ts + 200000) + datacheck = self.regular2_checkall_9(sql) + tdSql.checkRows(91) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_3') range('%s' , '%s') EVERY(1s) FILL(LINEAR) group by tbname ORDER BY ts DESC;" % (self.ts , self.ts + 200000) + datacheck = self.regular3_checkall_9(sql) + tdSql.checkRows(91) + + sql = "select %s from stable_1 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(LINEAR) group by tbname ;" % (self.ts + 1500 , self.ts + 2500) + datacheck = self.regular1_checkall_0_LINEAR(sql) + tdSql.checkRows(6) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_2') range('%s' , '%s') EVERY(1s) FILL(LINEAR) group by tbname ;" % (self.ts + 1500 , self.ts + 2500) + datacheck = self.regular2_checkall_0_LINEAR(sql) + tdSql.checkRows(2) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_3') range('%s' , '%s') EVERY(1s) FILL(LINEAR) group by tbname ;" % (self.ts + 1500 , self.ts + 2500) + datacheck = self.regular3_checkall_0_LINEAR(sql) + tdSql.checkRows(2) + + sql = "select %s from stable_1 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(LINEAR) group by tbname ;" % (self.ts + 150000 , self.ts + 200000) + datacheck = self.result_0(sql) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_2') range('%s' , '%s') EVERY(1s) FILL(LINEAR) group by tbname ;" % (self.ts + 150000 , self.ts + 200000) + datacheck = self.result_0(sql) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_3') range('%s' , '%s') EVERY(1s) FILL(LINEAR) group by tbname ;" % (self.ts + 150000 , self.ts + 200000) + datacheck = self.result_0(sql) + + # where + range + FILL(LINEAR) + EVERY( s) + sql = "select %s from stable_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR) group by tbname ;" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(33) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_2') and ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR) group by tbname ;" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(11) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_3') and ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR) group by tbname ;" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(11) + + sql = "select %s from stable_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR) group by tbname ;" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + datacheck = self.result_0(sql) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_2') and ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR) group by tbname ;" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + datacheck = self.result_0(sql) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_3') and ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR) group by tbname ;" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + datacheck = self.result_0(sql) + + sql = "select %s from stable_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR) group by tbname ;" % (self.ts , self.ts + 10000 , self.ts , self.ts) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(3) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_2') and ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR) group by tbname ;" % (self.ts , self.ts + 10000 , self.ts , self.ts) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(1) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_3') and ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR) group by tbname ;" % (self.ts , self.ts + 10000 , self.ts , self.ts) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(1) + + sql = "select %s from stable_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR) group by tbname ;" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(33) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_2') and ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR) group by tbname ;" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(11) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_3') and ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR) group by tbname ;" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(11) + + sql = "select %s from stable_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR) group by tbname ORDER BY ts DESC;" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0_NEXT(sql) + tdSql.checkRows(33) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_2') and ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR) group by tbname ORDER BY ts DESC;" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular2_checkall_0_NEXT(sql) + tdSql.checkRows(11) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_3') and ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR) group by tbname ORDER BY ts DESC;" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular3_checkall_0_NEXT(sql) + tdSql.checkRows(11) + + sql = "select %s from stable_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR) group by tbname ;" % (self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + datacheck = self.regular1_checkall_0_LINEAR(sql) + tdSql.checkRows(6) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_2') and ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR) group by tbname ;" % (self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + datacheck = self.regular2_checkall_0_LINEAR(sql) + tdSql.checkRows(2) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_3') and ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR) group by tbname ;" % (self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + datacheck = self.regular3_checkall_0_LINEAR(sql) + tdSql.checkRows(2) + + sql = "select %s from stable_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR) group by tbname ;" % (self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + datacheck = self.result_0(sql) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_2') and ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR) group by tbname ;" % (self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + datacheck = self.result_0(sql) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_3') and ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR) group by tbname ;" % (self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + datacheck = self.result_0(sql) + + # FILL(NEXT) + sql = "select %s from stable_1 FILL(NEXT) group by tbname " % interp_select + datacheck = self.regular1_checkall_0(sql) + sql = "select %s from stable_1 where tbname in ('table_2') FILL(NEXT) group by tbname " % interp_select + datacheck = self.regular2_checkall_0(sql) + sql = "select %s from stable_1 where tbname in ('table_3') FILL(NEXT) group by tbname " % interp_select + datacheck = self.regular3_checkall_0(sql) + + sql = "select %s from stable_1 " % interp_select + sql += "range('%s' , '%s') FILL(NEXT) group by tbname ;" % (self.ts - 10000 , self.ts + 100000) + datacheck = self.regular1_checkall_0(sql) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_2') range('%s' , '%s') FILL(NEXT) group by tbname ;" % (self.ts - 10000 , self.ts + 100000) + datacheck = self.regular2_checkall_0(sql) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_3') range('%s' , '%s') FILL(NEXT) group by tbname ;" % (self.ts - 10000 , self.ts + 100000) + datacheck = self.regular3_checkall_0(sql) + + sql = "select %s from stable_1 " % interp_select + sql += "range('%s' , '%s') FILL(NEXT) group by tbname ;" % (self.ts - 10000 , self.ts - 9900) + datacheck = self.regular1_checkall_0(sql) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_2') range('%s' , '%s') FILL(NEXT) group by tbname ;" % (self.ts - 10000 , self.ts - 9900) + datacheck = self.regular2_checkall_0(sql) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_3') range('%s' , '%s') FILL(NEXT) group by tbname ;" % (self.ts - 10000 , self.ts - 9900) + datacheck = self.regular3_checkall_0(sql) + + sql = "select %s from stable_1 " % interp_select + sql += "range('%s' , '%s') FILL(NEXT) group by tbname ;" % (self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0(sql) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_2') range('%s' , '%s') FILL(NEXT) group by tbname ;" % (self.ts , self.ts + 200000) + datacheck = self.regular2_checkall_0(sql) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_3') range('%s' , '%s') FILL(NEXT) group by tbname ;" % (self.ts , self.ts + 200000) + datacheck = self.regular3_checkall_0(sql) + + sql = "select %s from stable_1 " % interp_select + sql += "range('%s' , '%s') FILL(NEXT) group by tbname ;" % (self.ts + 1500 , self.ts + 2500) + datacheck = self.regular1_checkall_0_NEXT(sql) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_2') range('%s' , '%s') FILL(NEXT) group by tbname ;" % (self.ts + 1500 , self.ts + 2500) + datacheck = self.regular2_checkall_0_NEXT(sql) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_3') range('%s' , '%s') FILL(NEXT) group by tbname ;" % (self.ts + 1500 , self.ts + 2500) + datacheck = self.regular3_checkall_0_NEXT(sql) + + sql = "select %s from stable_1 " % interp_select + sql += "range('%s' , '%s') FILL(NEXT) group by tbname ;" % (self.ts + 150000 , self.ts + 200000) + datacheck = self.result_0(sql) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_2') range('%s' , '%s') FILL(NEXT) group by tbname ;" % (self.ts + 150000 , self.ts + 200000) + datacheck = self.result_0(sql) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_3') range('%s' , '%s') FILL(NEXT) group by tbname ;" % (self.ts + 150000 , self.ts + 200000) + datacheck = self.result_0(sql) + + # FILL(NEXT) + EVERY( s) + sql = "select %s from stable_1 EVERY(1s) FILL(NEXT) group by tbname ;" % interp_select + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(273) + sql = "select %s from stable_1 where tbname in ('table_2') EVERY(1s) FILL(NEXT) group by tbname ;" % interp_select + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(91) + sql = "select %s from stable_1 where tbname in ('table_3') EVERY(1s) FILL(NEXT) group by tbname ;" % interp_select + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(91) + + sql = "select %s from stable_1 EVERY(5s) FILL(NEXT) group by tbname ;" % interp_select + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(57) + sql = "select %s from stable_1 where tbname in ('table_2') EVERY(5s) FILL(NEXT) group by tbname ;" % interp_select + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(19) + sql = "select %s from stable_1 where tbname in ('table_3') EVERY(5s) FILL(NEXT) group by tbname ;" % interp_select + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(19) + + # range + FILL(NEXT) + EVERY( s) + sql = "select %s from stable_1 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(NEXT) group by tbname ;" % (self.ts - 10000 , self.ts + 100000) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(303) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_2') range('%s' , '%s') EVERY(1s) FILL(NEXT) group by tbname ;" % (self.ts - 10000 , self.ts + 100000) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(101) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_3') range('%s' , '%s') EVERY(1s) FILL(NEXT) group by tbname ;" % (self.ts - 10000 , self.ts + 100000) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(101) + + sql = "select %s from stable_1 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(NEXT) group by tbname ;" % (self.ts - 10000 , self.ts - 9900) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(3) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_2') range('%s' , '%s') EVERY(1s) FILL(NEXT) group by tbname ;" % (self.ts - 10000 , self.ts - 9900) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(1) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_3') range('%s' , '%s') EVERY(1s) FILL(NEXT) group by tbname ;" % (self.ts - 10000 , self.ts - 9900) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(1) + + sql = "select %s from stable_1 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(NEXT) group by tbname ;" % (self.ts , self.ts) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(3) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_2') range('%s' , '%s') EVERY(1s) FILL(NEXT) group by tbname ;" % (self.ts , self.ts) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(1) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_3') range('%s' , '%s') EVERY(1s) FILL(NEXT) group by tbname ;" % (self.ts , self.ts) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(1) + + sql = "select %s from stable_1 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(NEXT) group by tbname ;" % (self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(273) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_2') range('%s' , '%s') EVERY(1s) FILL(NEXT) group by tbname ;" % (self.ts , self.ts + 200000) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(91) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_3') range('%s' , '%s') EVERY(1s) FILL(NEXT) group by tbname ;" % (self.ts , self.ts + 200000) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(91) + + sql = "select %s from stable_1 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(NEXT) group by tbname ORDER BY ts DESC;" % (self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_9(sql) + tdSql.checkRows(273) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_2') range('%s' , '%s') EVERY(1s) FILL(NEXT) group by tbname ORDER BY ts DESC;" % (self.ts , self.ts + 200000) + datacheck = self.regular2_checkall_9(sql) + tdSql.checkRows(91) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_3') range('%s' , '%s') EVERY(1s) FILL(NEXT) group by tbname ORDER BY ts DESC;" % (self.ts , self.ts + 200000) + datacheck = self.regular3_checkall_9(sql) + tdSql.checkRows(91) + + sql = "select %s from stable_1 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(NEXT) group by tbname ;" % (self.ts + 1500 , self.ts + 2500) + datacheck = self.regular1_checkall_0_NEXT(sql) + tdSql.checkRows(6) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_2') range('%s' , '%s') EVERY(1s) FILL(NEXT) group by tbname ;" % (self.ts + 1500 , self.ts + 2500) + datacheck = self.regular2_checkall_0_NEXT(sql) + tdSql.checkRows(2) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_3') range('%s' , '%s') EVERY(1s) FILL(NEXT) group by tbname ;" % (self.ts + 1500 , self.ts + 2500) + datacheck = self.regular3_checkall_0_NEXT(sql) + tdSql.checkRows(2) + + sql = "select %s from stable_1 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(NEXT) group by tbname ;" % (self.ts + 150000 , self.ts + 200000) + datacheck = self.result_0(sql) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_2') range('%s' , '%s') EVERY(1s) FILL(NEXT) group by tbname ;" % (self.ts + 150000 , self.ts + 200000) + datacheck = self.result_0(sql) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_3') range('%s' , '%s') EVERY(1s) FILL(NEXT) group by tbname ;" % (self.ts + 150000 , self.ts + 200000) + datacheck = self.result_0(sql) + + # where + range + FILL(NEXT) + EVERY( s) + sql = "select %s from stable_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT) group by tbname ;" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(63) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_2') and ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT) group by tbname ;" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(21) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_3') and ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT) group by tbname ;" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(21) + + sql = "select %s from stable_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT) group by tbname ;" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(3) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_2') and ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT) group by tbname ;" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(1) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_3') and ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT) group by tbname ;" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(1) + + sql = "select %s from stable_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT) group by tbname ;" % (self.ts , self.ts + 10000 , self.ts , self.ts) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(3) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_2') and ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT) group by tbname ;" % (self.ts , self.ts + 10000 , self.ts , self.ts) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(1) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_3') and ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT) group by tbname ;" % (self.ts , self.ts + 10000 , self.ts , self.ts) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(1) + + sql = "select %s from stable_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT) group by tbname ;" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(33) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_2') and ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT) group by tbname ;" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(11) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_3') and ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT) group by tbname ;" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(11) + + sql = "select %s from stable_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT) group by tbname ORDER BY ts DESC;" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0_NEXT(sql) + tdSql.checkRows(33) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_2') and ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT) group by tbname ORDER BY ts DESC;" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular2_checkall_0_NEXT(sql) + tdSql.checkRows(11) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_3') and ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT) group by tbname ORDER BY ts DESC;" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular3_checkall_0_NEXT(sql) + tdSql.checkRows(11) + + sql = "select %s from stable_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT) group by tbname ;" % (self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + datacheck = self.regular1_checkall_0_NEXT(sql) + tdSql.checkRows(6) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_2') and ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT) group by tbname ;" % (self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + datacheck = self.regular2_checkall_0_NEXT(sql) + tdSql.checkRows(2) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_3') and ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT) group by tbname ;" % (self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + datacheck = self.regular3_checkall_0_NEXT(sql) + tdSql.checkRows(2) + + sql = "select %s from stable_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT) group by tbname ;" % (self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + datacheck = self.result_0(sql) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_2') and ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT) group by tbname ;" % (self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + datacheck = self.result_0(sql) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_3') and ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT) group by tbname ;" % (self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + datacheck = self.result_0(sql) + + # FILL(PREV) + sql = "select %s from stable_1 FILL(PREV) group by tbname " % interp_select + datacheck = self.regular1_checkall_0(sql) + sql = "select %s from stable_1 where tbname in ('table_2') FILL(PREV) group by tbname " % interp_select + datacheck = self.regular2_checkall_0(sql) + sql = "select %s from stable_1 where tbname in ('table_3') FILL(PREV) group by tbname " % interp_select + datacheck = self.regular3_checkall_0(sql) + + sql = "select %s from stable_1 " % interp_select + sql += "range('%s' , '%s') FILL(PREV) group by tbname ;" % (self.ts - 10000 , self.ts + 100000) + datacheck = self.result_0(sql) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_2') range('%s' , '%s') FILL(PREV) group by tbname ;" % (self.ts - 10000 , self.ts + 100000) + datacheck = self.result_0(sql) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_3') range('%s' , '%s') FILL(PREV) group by tbname ;" % (self.ts - 10000 , self.ts + 100000) + datacheck = self.result_0(sql) + + sql = "select %s from stable_1 " % interp_select + sql += "range('%s' , '%s') FILL(PREV) group by tbname ;" % (self.ts - 10000 , self.ts - 9900) + datacheck = self.result_0(sql) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_2') range('%s' , '%s') FILL(PREV) group by tbname ;" % (self.ts - 10000 , self.ts - 9900) + datacheck = self.result_0(sql) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_3') range('%s' , '%s') FILL(PREV) group by tbname ;" % (self.ts - 10000 , self.ts - 9900) + datacheck = self.result_0(sql) + + sql = "select %s from stable_1 " % interp_select + sql += "range('%s' , '%s') FILL(PREV) group by tbname ;" % (self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0(sql) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_2') range('%s' , '%s') FILL(PREV) group by tbname ;" % (self.ts , self.ts + 200000) + datacheck = self.regular2_checkall_0(sql) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_3') range('%s' , '%s') FILL(PREV) group by tbname ;" % (self.ts , self.ts + 200000) + datacheck = self.regular3_checkall_0(sql) + + sql = "select %s from stable_1 " % interp_select + sql += "range('%s' , '%s') FILL(PREV) group by tbname ;" % (self.ts + 1500 , self.ts + 2500) + datacheck = self.regular1_checkall_0(sql) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_2') range('%s' , '%s') FILL(PREV) group by tbname ;" % (self.ts + 1500 , self.ts + 2500) + datacheck = self.regular2_checkall_0(sql) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_3') range('%s' , '%s') FILL(PREV) group by tbname ;" % (self.ts + 1500 , self.ts + 2500) + datacheck = self.regular3_checkall_0(sql) + + sql = "select %s from stable_1 " % interp_select + sql += "range('%s' , '%s') FILL(PREV) group by tbname ;" % (self.ts + 150000 , self.ts + 200000) + datacheck = self.regular1_checkall_9(sql) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_2') range('%s' , '%s') FILL(PREV) group by tbname ;" % (self.ts + 150000 , self.ts + 200000) + datacheck = self.regular2_checkall_9(sql) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_3') range('%s' , '%s') FILL(PREV) group by tbname ;" % (self.ts + 150000 , self.ts + 200000) + datacheck = self.regular3_checkall_9(sql) + + # FILL(PREV) + EVERY( s) + sql = "select %s from stable_1 EVERY(1s) FILL(PREV) group by tbname ;" % interp_select + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(273) + sql = "select %s from stable_1 where tbname in ('table_2') EVERY(1s) FILL(PREV) group by tbname ;" % interp_select + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(91) + sql = "select %s from stable_1 where tbname in ('table_3') EVERY(1s) FILL(PREV) group by tbname ;" % interp_select + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(91) + + sql = "select %s from stable_1 EVERY(5s) FILL(PREV) group by tbname ;" % interp_select + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(57) + sql = "select %s from stable_1 where tbname in ('table_2') EVERY(5s) FILL(PREV) group by tbname ;" % interp_select + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(19) + sql = "select %s from stable_1 where tbname in ('table_3') EVERY(5s) FILL(PREV) group by tbname ;" % interp_select + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(19) + + # range + FILL(PREV) + EVERY( s) + sql = "select %s from stable_1 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(PREV) group by tbname ;" % (self.ts - 10000 , self.ts + 100000) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(303) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_2') range('%s' , '%s') EVERY(1s) FILL(PREV) group by tbname ;" % (self.ts - 10000 , self.ts + 100000) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(101) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_3') range('%s' , '%s') EVERY(1s) FILL(PREV) group by tbname ;" % (self.ts - 10000 , self.ts + 100000) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(101) + + sql = "select %s from stable_1 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(PREV) group by tbname ;" % (self.ts - 10000 , self.ts - 9900) + datacheck = self.result_0(sql) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_2') range('%s' , '%s') EVERY(1s) FILL(PREV) group by tbname ;" % (self.ts - 10000 , self.ts - 9900) + datacheck = self.result_0(sql) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_3') range('%s' , '%s') EVERY(1s) FILL(PREV) group by tbname ;" % (self.ts - 10000 , self.ts - 9900) + datacheck = self.result_0(sql) + + sql = "select %s from stable_1 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(PREV) group by tbname ;" % (self.ts , self.ts) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(3) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_2') range('%s' , '%s') EVERY(1s) FILL(PREV) group by tbname ;" % (self.ts , self.ts) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(1) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_3') range('%s' , '%s') EVERY(1s) FILL(PREV) group by tbname ;" % (self.ts , self.ts) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(1) + + sql = "select %s from stable_1 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(PREV) group by tbname ;" % (self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(603) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_2') range('%s' , '%s') EVERY(1s) FILL(PREV) group by tbname ;" % (self.ts , self.ts + 200000) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(201) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_3') range('%s' , '%s') EVERY(1s) FILL(PREV) group by tbname ;" % (self.ts , self.ts + 200000) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(201) + + sql = "select %s from stable_1 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(PREV) group by tbname ORDER BY ts DESC;" % (self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_9(sql) + tdSql.checkRows(603) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_2') range('%s' , '%s') EVERY(1s) FILL(PREV) group by tbname ORDER BY ts DESC;" % (self.ts , self.ts + 200000) + datacheck = self.regular2_checkall_9(sql) + tdSql.checkRows(201) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_3') range('%s' , '%s') EVERY(1s) FILL(PREV) group by tbname ORDER BY ts DESC;" % (self.ts , self.ts + 200000) + datacheck = self.regular3_checkall_9(sql) + tdSql.checkRows(201) + + sql = "select %s from stable_1 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(PREV) group by tbname ;" % (self.ts + 1500 , self.ts + 2500) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(6) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_2') range('%s' , '%s') EVERY(1s) FILL(PREV) group by tbname ;" % (self.ts + 1500 , self.ts + 2500) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(2) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_3') range('%s' , '%s') EVERY(1s) FILL(PREV) group by tbname ;" % (self.ts + 1500 , self.ts + 2500) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(2) + + sql = "select %s from stable_1 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(PREV) group by tbname ;" % (self.ts + 150000 , self.ts + 200000) + datacheck = self.regular1_checkall_9(sql) + tdSql.checkRows(153) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_2') range('%s' , '%s') EVERY(1s) FILL(PREV) group by tbname ;" % (self.ts + 150000 , self.ts + 200000) + datacheck = self.regular2_checkall_9(sql) + tdSql.checkRows(51) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_3') range('%s' , '%s') EVERY(1s) FILL(PREV) group by tbname ;" % (self.ts + 150000 , self.ts + 200000) + datacheck = self.regular3_checkall_9(sql) + tdSql.checkRows(51) + + # where + range + FILL(PREV) + EVERY( s) + sql = "select %s from stable_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV) group by tbname ;" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(303) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_2') and ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV) group by tbname ;" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(101) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_3') and ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(PREV) group by tbname ;" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(101) + + sql = "select %s from stable_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV) group by tbname ;" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + datacheck = self.result_0(sql) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_2') and ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV) group by tbname ;" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + datacheck = self.result_0(sql) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_2') and ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(PREV) group by tbname ;" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + datacheck = self.result_0(sql) + + sql = "select %s from stable_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV) group by tbname ;" % (self.ts , self.ts + 10000 , self.ts , self.ts) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(3) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_2') and ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV) group by tbname ;" % (self.ts , self.ts + 10000 , self.ts , self.ts) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(1) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_3') and ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(PREV) group by tbname ;" % (self.ts , self.ts + 10000 , self.ts , self.ts) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(1) + + sql = "select %s from stable_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV) group by tbname ;" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(603) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_2') and ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV) group by tbname ;" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(201) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_3') and ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(PREV) group by tbname ;" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(201) + + sql = "select %s from stable_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV) group by tbname ORDER BY ts DESC;" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0_NEXT(sql) + tdSql.checkRows(603) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_2') and ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV) group by tbname ORDER BY ts DESC;" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular2_checkall_0_NEXT(sql) + tdSql.checkRows(201) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_3') and ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(PREV) group by tbname ORDER BY ts DESC;" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular3_checkall_0_NEXT(sql) + tdSql.checkRows(201) + + sql = "select %s from stable_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV) group by tbname ;" % (self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(6) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_2') and ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV) group by tbname ;" % (self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(2) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_3') and ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(PREV) group by tbname ;" % (self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(2) + + sql = "select %s from stable_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV) group by tbname ;" % (self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + datacheck = self.regular1_checkall_0_NEXT(sql) + tdSql.checkRows(153) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_2') and ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV) group by tbname ;" % (self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + datacheck = self.regular2_checkall_0_NEXT(sql) + tdSql.checkRows(51) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_3') and ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(PREV) group by tbname ;" % (self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + datacheck = self.regular3_checkall_0_NEXT(sql) + tdSql.checkRows(51) + + # FILL(VALUE,100) + sql = "select %s from stable_1 FILL(VALUE, 100) group by tbname " % interp_select + datacheck = self.regular1_checkall_0(sql) + sql = "select %s from stable_1 where tbname in ('table_2') FILL(VALUE, 100) group by tbname " % interp_select + datacheck = self.regular2_checkall_0(sql) + sql = "select %s from stable_1 where tbname in ('table_3') FILL(VALUE, 100) group by tbname " % interp_select + datacheck = self.regular3_checkall_0(sql) + + sql = "select %s from stable_1 " % interp_select + sql += "range('%s' , '%s') FILL(VALUE, 100) group by tbname ;" % (self.ts - 10000 , self.ts + 100000) + datacheck = self.regular1_checkall_0_VALUE100(sql) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_2') range('%s' , '%s') FILL(VALUE, 100) group by tbname ;" % (self.ts - 10000 , self.ts + 100000) + datacheck = self.regular1_checkall_0_VALUE100(sql) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_3') range('%s' , '%s') FILL(VALUE, 100) group by tbname ;" % (self.ts - 10000 , self.ts + 100000) + datacheck = self.regular1_checkall_0_VALUE100(sql) + + sql = "select %s from stable_1 " % interp_select + sql += "range('%s' , '%s') FILL(VALUE, 100) group by tbname ;" % (self.ts - 10000 , self.ts - 9900) + datacheck = self.regular1_checkall_0_VALUE100(sql) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_2') range('%s' , '%s') FILL(VALUE, 100) group by tbname ;" % (self.ts - 10000 , self.ts - 9900) + datacheck = self.regular1_checkall_0_VALUE100(sql) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_3') range('%s' , '%s') FILL(VALUE, 100) group by tbname ;" % (self.ts - 10000 , self.ts - 9900) + datacheck = self.regular1_checkall_0_VALUE100(sql) + + sql = "select %s from stable_1 " % interp_select + sql += "range('%s' , '%s') FILL(VALUE, 100) group by tbname ;" % (self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0(sql) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_2') range('%s' , '%s') FILL(VALUE, 100) group by tbname ;" % (self.ts , self.ts + 200000) + datacheck = self.regular2_checkall_0(sql) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_3') range('%s' , '%s') FILL(VALUE, 100) group by tbname ;" % (self.ts , self.ts + 200000) + datacheck = self.regular3_checkall_0(sql) + + sql = "select %s from stable_1 " % interp_select + sql += "range('%s' , '%s') FILL(VALUE, 100) group by tbname ;" % (self.ts + 1500 , self.ts + 2500) + datacheck = self.regular1_checkall_0_VALUE100(sql) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_2') range('%s' , '%s') FILL(VALUE, 100) group by tbname ;" % (self.ts + 1500 , self.ts + 2500) + datacheck = self.regular1_checkall_0_VALUE100(sql) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_3') range('%s' , '%s') FILL(VALUE, 100) group by tbname ;" % (self.ts + 1500 , self.ts + 2500) + datacheck = self.regular1_checkall_0_VALUE100(sql) + + sql = "select %s from stable_1 " % interp_select + sql += "range('%s' , '%s') FILL(VALUE, 100) group by tbname ;" % (self.ts + 150000 , self.ts + 200000) + datacheck = self.regular1_checkall_0_VALUE100(sql) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_2') range('%s' , '%s') FILL(VALUE, 100) group by tbname ;" % (self.ts + 150000 , self.ts + 200000) + datacheck = self.regular1_checkall_0_VALUE100(sql) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_3') range('%s' , '%s') FILL(VALUE, 100) group by tbname ;" % (self.ts + 150000 , self.ts + 200000) + datacheck = self.regular1_checkall_0_VALUE100(sql) + + # FILL(VALUE,100) + EVERY( s) + sql = "select %s from stable_1 EVERY(1s) FILL(VALUE, 100) group by tbname ;" % interp_select + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(273) + sql = "select %s from stable_1 where tbname in ('table_2') EVERY(1s) FILL(VALUE, 100) group by tbname ;" % interp_select + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(91) + sql = "select %s from stable_1 where tbname in ('table_3') EVERY(1s) FILL(VALUE, 100) group by tbname ;" % interp_select + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(91) + + sql = "select %s from stable_1 EVERY(5s) FILL(VALUE, 100) group by tbname ;" % interp_select + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(57) + sql = "select %s from stable_1 where tbname in ('table_2') EVERY(5s) FILL(VALUE, 100) group by tbname ;" % interp_select + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(19) + sql = "select %s from stable_1 where tbname in ('table_3') EVERY(5s) FILL(VALUE, 100) group by tbname ;" % interp_select + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(19) + + # FILL(NULL) + EVERY( s) + sql = "select %s from stable_1 EVERY(1s) FILL(NULL) group by tbname ;" % interp_select + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(273) + sql = "select %s from stable_1 where tbname in ('table_2') EVERY(1s) FILL(NULL) group by tbname ;" % interp_select + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(91) + sql = "select %s from stable_1 where tbname in ('table_3') EVERY(1s) FILL(NULL) group by tbname ;" % interp_select + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(91) + + sql = "select %s from stable_1 EVERY(5s) FILL(NULL) group by tbname ;" % interp_select + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(57) + sql = "select %s from stable_1 where tbname in ('table_2') EVERY(5s) FILL(NULL) group by tbname ;" % interp_select + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(19) + sql = "select %s from stable_1 where tbname in ('table_3') EVERY(5s) FILL(NULL) group by tbname ;" % interp_select + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(19) + + # range + FILL(VALUE, 100) + EVERY( s) + sql = "select %s from stable_1 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(VALUE, 100) group by tbname ;" % (self.ts - 10000 , self.ts + 100000) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(333) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_2') range('%s' , '%s') EVERY(1s) FILL(VALUE, 100) group by tbname ;" % (self.ts - 10000 , self.ts + 100000) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(111) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_3') range('%s' , '%s') EVERY(1s) FILL(VALUE, 100) group by tbname ;" % (self.ts - 10000 , self.ts + 100000) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(111) + + sql = "select %s from stable_1 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(VALUE, 100) group by tbname ;" % (self.ts - 10000 , self.ts - 9900) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(3) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_2') range('%s' , '%s') EVERY(1s) FILL(VALUE, 100) group by tbname ;" % (self.ts - 10000 , self.ts - 9900) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(1) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_3') range('%s' , '%s') EVERY(1s) FILL(VALUE, 100) group by tbname ;" % (self.ts - 10000 , self.ts - 9900) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(1) + + sql = "select %s from stable_1 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(VALUE, 100) group by tbname ;" % (self.ts , self.ts) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(3) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_2') range('%s' , '%s') EVERY(1s) FILL(VALUE, 100) group by tbname ;" % (self.ts , self.ts) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(1) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_3') range('%s' , '%s') EVERY(1s) FILL(VALUE, 100) group by tbname ;" % (self.ts , self.ts) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(1) + + sql = "select %s from stable_1 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(VALUE, 100) group by tbname ;" % (self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(603) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_2') range('%s' , '%s') EVERY(1s) FILL(VALUE, 100) group by tbname ;" % (self.ts , self.ts + 200000) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(201) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_3') range('%s' , '%s') EVERY(1s) FILL(VALUE, 100) group by tbname ;" % (self.ts , self.ts + 200000) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(201) + + sql = "select %s from stable_1 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(VALUE, 100) group by tbname ORDER BY ts DESC;" % (self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(603) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_2') range('%s' , '%s') EVERY(1s) FILL(VALUE, 100) group by tbname ORDER BY ts DESC;" % (self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(201) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_3') range('%s' , '%s') EVERY(1s) FILL(VALUE, 100) group by tbname ORDER BY ts DESC;" % (self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(201) + + sql = "select %s from stable_1 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(VALUE, 100) group by tbname ;" % (self.ts + 1500 , self.ts + 2500) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(6) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_2') range('%s' , '%s') EVERY(1s) FILL(VALUE, 100) group by tbname ;" % (self.ts + 1500 , self.ts + 2500) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(2) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_3') range('%s' , '%s') EVERY(1s) FILL(VALUE, 100) group by tbname ;" % (self.ts + 1500 , self.ts + 2500) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(2) + + sql = "select %s from stable_1 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(VALUE, 100) group by tbname ;" % (self.ts + 150000 , self.ts + 200000) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(153) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_2') range('%s' , '%s') EVERY(1s) FILL(VALUE, 100) group by tbname ;" % (self.ts + 150000 , self.ts + 200000) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(51) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_3') range('%s' , '%s') EVERY(1s) FILL(VALUE, 100) group by tbname ;" % (self.ts + 150000 , self.ts + 200000) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(51) + + # where + range + FILL(VALUE, 100) + EVERY( s) + sql = "select %s from stable_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100) group by tbname ;" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(333) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_2') and ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100) group by tbname ;" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(111) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_3') and ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100) group by tbname ;" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(111) + + sql = "select %s from stable_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100) group by tbname ;" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(3) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_2') and ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100) group by tbname ;" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(1) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_3') and ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100) group by tbname ;" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(1) + + sql = "select %s from stable_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100) group by tbname ;" % (self.ts , self.ts + 10000 , self.ts , self.ts) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(3) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_2') and ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100) group by tbname ;" % (self.ts , self.ts + 10000 , self.ts , self.ts) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(1) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_3') and ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100) group by tbname ;" % (self.ts , self.ts + 10000 , self.ts , self.ts) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(1) + + sql = "select %s from stable_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100) group by tbname ;" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(603) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_2') and ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100) group by tbname ;" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(201) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_3') and ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100) group by tbname ;" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(201) + + sql = "select %s from stable_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100) group by tbname ORDER BY ts DESC;" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(603) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_2') and ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100) group by tbname ORDER BY ts DESC;" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(201) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_3') and ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100) group by tbname ORDER BY ts DESC;" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(201) + + sql = "select %s from stable_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100) group by tbname ;" % (self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(6) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_2') and ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100) group by tbname ;" % (self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(2) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_2') and ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100) group by tbname ;" % (self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(2) + + sql = "select %s from stable_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100) group by tbname ;" % (self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(153) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_2') and ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100) group by tbname ;" % (self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(51) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_3') and ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100) group by tbname ;" % (self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(51) + + # FILL(NULL) + sql = "select %s from stable_1 FILL(NULL) group by tbname " % interp_select + datacheck = self.regular1_checkall_0(sql) + sql = "select %s from stable_1 where tbname in ('table_2') FILL(NULL) group by tbname " % interp_select + datacheck = self.regular2_checkall_0(sql) + sql = "select %s from stable_1 where tbname in ('table_3') FILL(NULL) group by tbname " % interp_select + datacheck = self.regular3_checkall_0(sql) + + sql = "select %s from stable_1 " % interp_select + sql += "range('%s' , '%s') FILL(NULL) group by tbname ;" % (self.ts - 10000 , self.ts + 100000) + datacheck = self.regular1_checkall_0_NULL(sql) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_2') range('%s' , '%s') FILL(NULL) group by tbname ;" % (self.ts - 10000 , self.ts + 100000) + datacheck = self.regular1_checkall_0_NULL(sql) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_3') range('%s' , '%s') FILL(NULL) group by tbname ;" % (self.ts - 10000 , self.ts + 100000) + datacheck = self.regular1_checkall_0_NULL(sql) + + sql = "select %s from stable_1 " % interp_select + sql += "range('%s' , '%s') FILL(NULL) group by tbname ;" % (self.ts - 10000 , self.ts - 9900) + datacheck = self.regular1_checkall_0_NULL(sql) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_2') range('%s' , '%s') FILL(NULL) group by tbname ;" % (self.ts - 10000 , self.ts - 9900) + datacheck = self.regular1_checkall_0_NULL(sql) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_3') range('%s' , '%s') FILL(NULL) group by tbname ;" % (self.ts - 10000 , self.ts - 9900) + datacheck = self.regular1_checkall_0_NULL(sql) + + sql = "select %s from stable_1 " % interp_select + sql += "range('%s' , '%s') FILL(NULL) group by tbname ;" % (self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0(sql) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_2') range('%s' , '%s') FILL(NULL) group by tbname ;" % (self.ts , self.ts + 200000) + datacheck = self.regular2_checkall_0(sql) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_3') range('%s' , '%s') FILL(NULL) group by tbname ;" % (self.ts , self.ts + 200000) + datacheck = self.regular3_checkall_0(sql) + + sql = "select %s from stable_1 " % interp_select + sql += "range('%s' , '%s') FILL(NULL) group by tbname ;" % (self.ts + 1500 , self.ts + 2500) + datacheck = self.regular1_checkall_0_NULL(sql) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_2') range('%s' , '%s') FILL(NULL) group by tbname ;" % (self.ts + 1500 , self.ts + 2500) + datacheck = self.regular1_checkall_0_NULL(sql) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_3') range('%s' , '%s') FILL(NULL) group by tbname ;" % (self.ts + 1500 , self.ts + 2500) + datacheck = self.regular1_checkall_0_NULL(sql) + + sql = "select %s from stable_1 " % interp_select + sql += "range('%s' , '%s') FILL(NULL) group by tbname ;" % (self.ts + 150000 , self.ts + 200000) + datacheck = self.regular1_checkall_0_NULL(sql) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_2') range('%s' , '%s') FILL(NULL) group by tbname ;" % (self.ts + 150000 , self.ts + 200000) + datacheck = self.regular1_checkall_0_NULL(sql) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_3') range('%s' , '%s') FILL(NULL) group by tbname ;" % (self.ts + 150000 , self.ts + 200000) + datacheck = self.regular1_checkall_0_NULL(sql) + + # range + FILL(NULL) + EVERY( s) + sql = "select %s from stable_1 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(NULL) group by tbname ;" % (self.ts - 10000 , self.ts + 100000) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(333) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_2') range('%s' , '%s') EVERY(1s) FILL(NULL) group by tbname ;" % (self.ts - 10000 , self.ts + 100000) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(111) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_3') range('%s' , '%s') EVERY(1s) FILL(NULL) group by tbname ;" % (self.ts - 10000 , self.ts + 100000) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(111) + + sql = "select %s from stable_1 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(NULL) group by tbname ;" % (self.ts - 10000 , self.ts - 9900) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(3) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_2') range('%s' , '%s') EVERY(1s) FILL(NULL) group by tbname ;" % (self.ts - 10000 , self.ts - 9900) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(1) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_3') range('%s' , '%s') EVERY(1s) FILL(NULL) group by tbname ;" % (self.ts - 10000 , self.ts - 9900) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(1) + + sql = "select %s from stable_1 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(NULL) group by tbname ;" % (self.ts , self.ts) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(3) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_2') range('%s' , '%s') EVERY(1s) FILL(NULL) group by tbname ;" % (self.ts , self.ts) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(1) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_3') range('%s' , '%s') EVERY(1s) FILL(NULL) group by tbname ;" % (self.ts , self.ts) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(1) + + sql = "select %s from stable_1 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(NULL) group by tbname ;" % (self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(603) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_2') range('%s' , '%s') EVERY(1s) FILL(NULL) group by tbname ;" % (self.ts , self.ts + 200000) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(201) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_3') range('%s' , '%s') EVERY(1s) FILL(NULL) group by tbname ;" % (self.ts , self.ts + 200000) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(201) + + sql = "select %s from stable_1 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(NULL) group by tbname ORDER BY ts DESC;" % (self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(603) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_2') range('%s' , '%s') EVERY(1s) FILL(NULL) group by tbname ORDER BY ts DESC;" % (self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(201) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_3') range('%s' , '%s') EVERY(1s) FILL(NULL) group by tbname ORDER BY ts DESC;" % (self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(201) + + sql = "select %s from stable_1 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(NULL) group by tbname ;" % (self.ts + 1500 , self.ts + 2500) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(6) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_2') range('%s' , '%s') EVERY(1s) FILL(NULL) group by tbname ;" % (self.ts + 1500 , self.ts + 2500) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(2) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_3') range('%s' , '%s') EVERY(1s) FILL(NULL) group by tbname ;" % (self.ts + 1500 , self.ts + 2500) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(2) + + sql = "select %s from stable_1 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL(NULL) group by tbname ;" % (self.ts + 150000 , self.ts + 200000) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(153) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_2') range('%s' , '%s') EVERY(1s) FILL(NULL) group by tbname ;" % (self.ts + 150000 , self.ts + 200000) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(51) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_3') range('%s' , '%s') EVERY(1s) FILL(NULL) group by tbname ;" % (self.ts + 150000 , self.ts + 200000) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(51) + + # where + range + FILL(NULL) + EVERY( s) + sql = "select %s from stable_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL) group by tbname ;" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(333) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_2') and ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL) group by tbname ;" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(111) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_3') and ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(NULL) group by tbname ;" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(111) + + sql = "select %s from stable_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL) group by tbname ;" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(3) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_2') and ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL) group by tbname ;" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(1) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_3') and ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(NULL) group by tbname ;" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(1) + + sql = "select %s from stable_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL) group by tbname ;" % (self.ts , self.ts + 10000 , self.ts , self.ts) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(3) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_2') and ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL) group by tbname ;" % (self.ts , self.ts + 10000 , self.ts , self.ts) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(1) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_3') and ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(NULL) group by tbname ;" % (self.ts , self.ts + 10000 , self.ts , self.ts) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(1) + + sql = "select %s from stable_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL) group by tbname ;" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(603) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_2') and ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL) group by tbname ;" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(201) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_3') and ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(NULL) group by tbname ;" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(201) + + sql = "select %s from stable_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL) group by tbname ORDER BY ts DESC;" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(603) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_2') and ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL) group by tbname ORDER BY ts DESC;" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(201) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_3') and ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(NULL) group by tbname ORDER BY ts DESC;" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(201) + + sql = "select %s from stable_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL) group by tbname ;" % (self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(6) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_2') and ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL) group by tbname ;" % (self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(2) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_3') and ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(NULL) group by tbname ;" % (self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(2) + + sql = "select %s from stable_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL) group by tbname ;" % (self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(153) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_2') and ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL) group by tbname ;" % (self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(51) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_3') and ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(NULL) group by tbname ;" % (self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(51) + + # EVERY(1s) + sql = "select %s from stable_1 EVERY(1s) group by tbname ;" % interp_select + datacheck = self.regular1_checkall_0(sql) + datacheck = self.regular1_checkall_20(sql) + sql = "select %s from stable_1 where tbname in ('table_2') EVERY(1s) group by tbname ;" % interp_select + datacheck = self.regular2_checkall_0(sql) + datacheck = self.regular2_checkall_20(sql) + sql = "select %s from stable_1 where tbname in ('table_3') EVERY(1s) group by tbname ;" % interp_select + datacheck = self.regular3_checkall_0(sql) + datacheck = self.regular3_checkall_20(sql) + + sql = "select %s from stable_1 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) group by tbname ;" % (self.ts - 10000 , self.ts + 100000) + datacheck = self.regular1_checkall_0(sql) + datacheck = self.regular1_checkall_20(sql) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_2') range('%s' , '%s') EVERY(1s) group by tbname ;" % (self.ts - 10000 , self.ts + 100000) + datacheck = self.regular2_checkall_0(sql) + datacheck = self.regular2_checkall_20(sql) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_3') range('%s' , '%s') EVERY(1s) group by tbname ;" % (self.ts - 10000 , self.ts + 100000) + datacheck = self.regular3_checkall_0(sql) + datacheck = self.regular3_checkall_20(sql) + + sql = "select %s from stable_1 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) group by tbname ;" % (self.ts - 10000 , self.ts - 9900) + datacheck = self.result_0(sql) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_2') range('%s' , '%s') EVERY(1s) group by tbname ;" % (self.ts - 10000 , self.ts - 9900) + datacheck = self.result_0(sql) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_3') range('%s' , '%s') EVERY(1s) group by tbname ;" % (self.ts - 10000 , self.ts - 9900) + datacheck = self.result_0(sql) + + sql = "select %s from stable_1 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) group by tbname ;" % (self.ts , self.ts) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(3) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_2') range('%s' , '%s') EVERY(1s) group by tbname ;" % (self.ts , self.ts) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(1) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_3') range('%s' , '%s') EVERY(1s) group by tbname ;" % (self.ts , self.ts) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(1) + + sql = "select %s from stable_1 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) group by tbname ;" % (self.ts + 10000 , self.ts + 25000) + datacheck = self.regular1_checkall_0_NEXT(sql) + tdSql.checkRows(21) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_2') range('%s' , '%s') EVERY(1s) group by tbname ;" % (self.ts + 10000 , self.ts + 25000) + datacheck = self.regular2_checkall_0_NEXT(sql) + tdSql.checkRows(7) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_3') range('%s' , '%s') EVERY(1s) group by tbname ;" % (self.ts + 10000 , self.ts + 25000) + datacheck = self.regular3_checkall_0_NEXT(sql) + tdSql.checkRows(7) + + sql = "select %s from stable_1 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) group by tbname ;" % (self.ts + 150000 , self.ts + 200000) + datacheck = self.result_0(sql) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_2') range('%s' , '%s') EVERY(1s) group by tbname ;" % (self.ts + 150000 , self.ts + 200000) + datacheck = self.result_0(sql) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_3') range('%s' , '%s') EVERY(1s) group by tbname ;" % (self.ts + 150000 , self.ts + 200000) + datacheck = self.result_0(sql) + + # EVERY(2s) + sql = "select %s from stable_1 EVERY(2s) group by tbname ;" % interp_select + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(42) + sql = "select %s from stable_1 where tbname in ('table_2') EVERY(2s) group by tbname ;" % interp_select + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(14) + sql = "select %s from stable_1 where tbname in ('table_3') EVERY(2s) group by tbname ;" % interp_select + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(14) + + sql = "select %s from stable_1 " % interp_select + sql += "range('%s' , '%s') EVERY(2s) group by tbname ;" % (self.ts - 10000 , self.ts + 100000) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(42) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_2') range('%s' , '%s') EVERY(2s) group by tbname ;" % (self.ts - 10000 , self.ts + 100000) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(14) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_3') range('%s' , '%s') EVERY(2s) group by tbname ;" % (self.ts - 10000 , self.ts + 100000) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(14) + + sql = "select %s from stable_1 " % interp_select + sql += "range('%s' , '%s') EVERY(2s) group by tbname ;" % (self.ts - 10000 , self.ts - 9900) + datacheck = self.result_0(sql) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_2') range('%s' , '%s') EVERY(2s) group by tbname ;" % (self.ts - 10000 , self.ts - 9900) + datacheck = self.result_0(sql) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_3') range('%s' , '%s') EVERY(2s) group by tbname ;" % (self.ts - 10000 , self.ts - 9900) + datacheck = self.result_0(sql) + + sql = "select %s from stable_1 " % interp_select + sql += "range('%s' , '%s') EVERY(2s) group by tbname ;" % (self.ts , self.ts) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(3) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_2') range('%s' , '%s') EVERY(2s) group by tbname ;" % (self.ts , self.ts) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(1) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_3') range('%s' , '%s') EVERY(2s) group by tbname ;" % (self.ts , self.ts) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(1) + + sql = "select %s from stable_1 " % interp_select + sql += "range('%s' , '%s') EVERY(2s) group by tbname ;" % (self.ts + 10000 , self.ts + 25000) + datacheck = self.regular1_checkall_0_NEXT(sql) + tdSql.checkRows(15) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_2') range('%s' , '%s') EVERY(2s) group by tbname ;" % (self.ts + 10000 , self.ts + 25000) + datacheck = self.regular2_checkall_0_NEXT(sql) + tdSql.checkRows(5) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_3') range('%s' , '%s') EVERY(2s) group by tbname ;" % (self.ts + 10000 , self.ts + 25000) + datacheck = self.regular3_checkall_0_NEXT(sql) + tdSql.checkRows(5) + + sql = "select %s from stable_1 " % interp_select + sql += "range('%s' , '%s') EVERY(2s) group by tbname ;" % (self.ts + 150000 , self.ts + 200000) + datacheck = self.result_0(sql) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_2') range('%s' , '%s') EVERY(2s) group by tbname ;" % (self.ts + 150000 , self.ts + 200000) + datacheck = self.result_0(sql) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_3') range('%s' , '%s') EVERY(2s) group by tbname ;" % (self.ts + 150000 , self.ts + 200000) + datacheck = self.result_0(sql) + + # EVERY(5s) + sql = "select %s from stable_1 EVERY(5s) group by tbname ;" % interp_select + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(33) + sql = "select %s from stable_1 where tbname in ('table_2') EVERY(5s) group by tbname ;" % interp_select + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(11) + sql = "select %s from stable_1 where tbname in ('table_3') EVERY(5s) group by tbname ;" % interp_select + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(11) + + # EVERY(100s) + sql = "select %s from stable_1 EVERY(100s) group by tbname ;" % interp_select + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(3) + sql = "select %s from stable_1 where tbname in ('table_2') EVERY(100s) group by tbname ;" % interp_select + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(1) + sql = "select %s from stable_1 where tbname in ('table_3') EVERY(100s) group by tbname ;" % interp_select + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(1) + + # error + tdSql.error("select interp(*) from stable_1 group by tbname ") + tdSql.error("select interp(*) from stable_1 FILL(NEXT) group by tbname ") + sql = "select interp(*) from stable_1 where ts >= '%s' FILL(NULL) group by tbname ;" % self.ts + tdSql.error(sql) + sql = "select interp(*) from stable_1 where ts <= '%s' FILL(LINEAR) group by tbname ;" % self.ts + tdSql.error(sql) + sql = "select interp(*) from stable_1 where ts > '%s' and ts < now every(1s) fill(PREV) group by tbname ;" % self.ts + tdSql.error(sql) + + sql = "select %s from stable_1 " % interp_select + sql += "range('%s' , '%s') EVERY(1s) FILL (LINEAR) group by tbname ;" % (self.ts + 150000 , self.ts + 100000) + tdSql.error(sql) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_2') range('%s' , '%s') EVERY(2s) FILL (PREV) group by tbname ;" % (self.ts + 150000 , self.ts - 100000) + tdSql.error(sql) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_3') range('%s' , '%s') EVERY(5s) FILL (NEXT) group by tbname ;" % (self.ts - 150000 , self.ts - 200000) + tdSql.error(sql) + + sql = "select %s from stable_1 " % interp_select + sql += "range('%s' , '%s') EVERY(10s) FILL (NULL) group by tbname ;" % (self.ts + 150000 , self.ts + 100000) + tdSql.error(sql) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_2') range('%s' , '%s') EVERY(60s) FILL (VALUE,100) group by tbname ;" % (self.ts + 150000 , self.ts - 100000) + tdSql.error(sql) + sql = "select %s from stable_1 " % interp_select + sql += "where tbname in ('table_3') range('%s' , '%s') EVERY(120s) FILL (LINEAR) group by tbname ORDER BY ts DESC;" % (self.ts - 150000 , self.ts - 200000) + tdSql.error(sql) + + # Nested Query + sql = "select * from (select %s from stable_1 group by tbname) ;" % interp_select + datacheck = self.regular1_checkall_0(sql) + sql = "select * from (select %s from stable_1 where tbname in ('table_2') group by tbname) ;" % interp_select + datacheck = self.regular2_checkall_0(sql) + sql = "select * from (select %s from stable_1 where tbname in ('table_3') group by tbname) ;" % interp_select + datacheck = self.regular3_checkall_0(sql) + + sql = "select %s from (select * from stable_1) ;" % interp_select + tdSql.error(sql) + sql = "select %s from (select * from stable_1 where tbname in ('table_2') ) ;" % interp_select + tdSql.error(sql) + sql = "select %s from (select * from stable_1 where tbname in ('table_3') ) ;" % interp_select + tdSql.error(sql) + + # Nested Query + where + range + FILL(LINEAR) + EVERY( s) (1) + sql = "select * from (select %s from stable_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR) group by tbname);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(33) + sql = "select * from (select %s from stable_1 " % interp_select + sql += "where tbname in ('table_2') and ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR) group by tbname);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(11) + sql = "select * from (select %s from stable_1 " % interp_select + sql += "where tbname in ('table_3') and ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR) group by tbname);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(11) + + sql = "select * from (select %s from stable_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR) group by tbname);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + datacheck = self.result_0(sql) + sql = "select * from (select %s from stable_1 " % interp_select + sql += "where tbname in ('table_2') and ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR) group by tbname );" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + datacheck = self.result_0(sql) + sql = "select * from (select %s from stable_1 " % interp_select + sql += "where tbname in ('table_3') and ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR) group by tbname );" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + datacheck = self.result_0(sql) + + sql = "select * from (select %s from stable_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR) group by tbname);" % (self.ts , self.ts + 10000 , self.ts , self.ts) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(3) + sql = "select * from (select %s from stable_1 " % interp_select + sql += "where tbname in ('table_2') and ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR) group by tbname);" % (self.ts , self.ts + 10000 , self.ts , self.ts) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(1) + sql = "select * from (select %s from stable_1 " % interp_select + sql += "where tbname in ('table_3') and ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR) group by tbname);" % (self.ts , self.ts + 10000 , self.ts , self.ts) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(1) + + sql = "select * from (select %s from stable_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR) group by tbname);" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(33) + sql = "select * from (select %s from stable_1 " % interp_select + sql += "where tbname in ('table_2') and ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR) group by tbname);" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(11) + sql = "select * from (select %s from stable_1 " % interp_select + sql += "where tbname in ('table_3') and ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR) group by tbname);" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(11) + + sql = "select * from (select %s from stable_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR) group by tbname ORDER BY ts DESC);" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0_NEXT(sql) + tdSql.checkRows(33) + sql = "select * from (select %s from stable_1 " % interp_select + sql += "where tbname in ('table_2') and ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR) group by tbname ORDER BY ts DESC);" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular2_checkall_0_NEXT(sql) + tdSql.checkRows(11) + sql = "select * from (select %s from stable_1 " % interp_select + sql += "where tbname in ('table_3') and ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR) group by tbname ORDER BY ts DESC);" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular3_checkall_0_NEXT(sql) + tdSql.checkRows(11) + + sql = "select * from (select %s from stable_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR) group by tbname);" % (self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + datacheck = self.regular1_checkall_0_LINEAR(sql) + tdSql.checkRows(6) + sql = "select * from (select %s from stable_1 " % interp_select + sql += "where tbname in ('table_2') and ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR) group by tbname);" % (self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + datacheck = self.regular2_checkall_0_LINEAR(sql) + tdSql.checkRows(2) + sql = "select * from (select %s from stable_1 " % interp_select + sql += "where tbname in ('table_3') and ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR) group by tbname);" % (self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + datacheck = self.regular3_checkall_0_LINEAR(sql) + tdSql.checkRows(2) + + sql = "select * from (select %s from stable_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR) group by tbname);" % (self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + datacheck = self.result_0(sql) + sql = "select * from (select %s from stable_1 " % interp_select + sql += "where tbname in ('table_2') and ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR) group by tbname);" % (self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + datacheck = self.result_0(sql) + sql = "select * from (select %s from stable_1 " % interp_select + sql += "where tbname in ('table_3') and ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR) group by tbname);" % (self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + datacheck = self.result_0(sql) + tdLog.info(sql) + + # Nested Query + where + range + FILL(LINEAR) + EVERY( s)(2-error) + sql = "select %s from (select * from stable_1 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + tdSql.error(sql) + sql = "select %s from (select * from stable_1 where tbname in ('table_2'))" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + tdSql.error(sql) + sql = "select %s from (select * from stable_1 where tbname in ('table_3'))" % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + tdSql.error(sql) + + sql = "select %s from (select * from stable_1 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + tdSql.error(sql) + sql = "select %s from (select * from stable_1 where tbname in ('table_2'))" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + tdSql.error(sql) + sql = "select %s from (select * from stable_1 where tbname in ('table_3'))" % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + tdSql.error(sql) + + sql = "select %s from (select * from stable_1 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR);" % (self.ts , self.ts + 10000 , self.ts , self.ts) + tdSql.error(sql) + sql = "select %s from (select * from stable_1 where tbname in ('table_2'))" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR);" % (self.ts , self.ts + 10000 , self.ts , self.ts) + tdSql.error(sql) + sql = "select %s from (select * from stable_1 where tbname in ('table_3'))" % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR);" % (self.ts , self.ts + 10000 , self.ts , self.ts) + tdSql.error(sql) + + sql = "select %s from (select * from stable_1 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR);" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + tdSql.error(sql) + sql = "select %s from (select * from stable_1 where tbname in ('table_2'))" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR);" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + tdSql.error(sql) + sql = "select %s from (select * from stable_1 where tbname in ('table_3'))" % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR);" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + tdSql.error(sql) + + sql = "select %s from (select * from stable_1 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR);" % (self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + tdSql.error(sql) + sql = "select %s from (select * from stable_1 where tbname in ('table_2'))" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR);" % (self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + tdSql.error(sql) + sql = "select %s from (select * from stable_1 where tbname in ('table_3'))" % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR);" % (self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + tdSql.error(sql) + + sql = "select %s from (select * from stable_1 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR);" % (self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + tdSql.error(sql) + sql = "select %s from (select * from stable_1 where tbname in ('table_2'))" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR);" % (self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + tdSql.error(sql) + sql = "select %s from (select * from stable_1 where tbname in ('table_3'))" % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR);" % (self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + tdSql.error(sql) + + # Nested Query + where + range + FILL(LINEAR) + EVERY( s)(3) + #TD-11096 + # sql = "select * from (select %s from stable_1 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR) group by tbname) z1," % (interp_select , self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + # sql += "(select %s from stable_2 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR) group by tbname) z2 where z1.ts=z2.ts ;" % (interp_select , self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + # datacheck = self.regular1_checkall_0(sql) + # tdSql.checkRows(11) + + # sql = "select * from (select %s from stable_1 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR) group by tbname) z1," % (interp_select , self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + # sql += "(select %s from stable_2 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR) group by tbname) z2 where z1.ts=z2.ts ;" % (interp_select , self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + # datacheck = self.result_0(sql) + + # sql = "select * from (select %s from stable_1 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR) group by tbname) z1," % (interp_select , self.ts , self.ts + 10000 , self.ts , self.ts) + # sql += "(select %s from stable_2 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR) group by tbname) z2 where z1.ts=z2.ts ;" % (interp_select , self.ts , self.ts + 10000 , self.ts , self.ts) + # datacheck = self.regular3_checkall_0(sql) + # tdSql.checkRows(1) + + # sql = "select * from (select %s from stable_1 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR) group by tbname) z1," % (interp_select , self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + # sql += "(select %s from stable_2 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR) group by tbname) z2 where z1.ts=z2.ts ;" % (interp_select , self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + # datacheck = self.regular1_checkall_0(sql) + # tdSql.checkRows(11) + + # sql = "select * from (select %s from stable_1 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR) group by tbname) z1," % (interp_select , self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + # sql += "(select %s from stable_2 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR) group by tbname) z2 where z1.ts=z2.ts ;" % (interp_select , self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + # datacheck = self.regular2_checkall_0_LINEAR(sql) + # tdSql.checkRows(2) + + # sql = "select * from (select %s from stable_1 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR)) z1," % (interp_select , self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + # sql += "(select %s from stable_2 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(LINEAR)) z2 where z1.ts=z2.ts ;" % (interp_select , self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + # datacheck = self.result_0(sql) + + # Nested Query + where + range + FILL(NEXT) + EVERY( s) (1) + sql = "select * from (select %s from stable_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT) group by tbname);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(63) + sql = "select * from (select %s from stable_1 " % interp_select + sql += " where tbname in ('table_2') and ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT) group by tbname);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(21) + sql = "select * from (select %s from stable_1 " % interp_select + sql += " where tbname in ('table_3') and ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT) group by tbname);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(21) + + sql = "select * from (select %s from stable_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT) group by tbname);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(3) + sql = "select * from (select %s from stable_1 " % interp_select + sql += " where tbname in ('table_2') and ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT) group by tbname);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(1) + sql = "select * from (select %s from stable_1 " % interp_select + sql += " where tbname in ('table_3') and ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT) group by tbname);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(1) + + sql = "select * from (select %s from stable_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT) group by tbname);" % (self.ts , self.ts + 10000 , self.ts , self.ts) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(3) + sql = "select * from (select %s from stable_1 " % interp_select + sql += " where tbname in ('table_2') and ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT) group by tbname);" % (self.ts , self.ts + 10000 , self.ts , self.ts) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(1) + sql = "select * from (select %s from stable_1 " % interp_select + sql += " where tbname in ('table_3') and ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT) group by tbname);" % (self.ts , self.ts + 10000 , self.ts , self.ts) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(1) + + sql = "select * from (select %s from stable_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT) group by tbname);" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(33) + sql = "select * from (select %s from stable_1 " % interp_select + sql += " where tbname in ('table_2') and ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT) group by tbname);" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(11) + sql = "select * from (select %s from stable_1 " % interp_select + sql += " where tbname in ('table_3') and ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT) group by tbname);" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(11) + + sql = "select * from (select %s from stable_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT) group by tbname ORDER BY ts DESC);" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0_NEXT(sql) + tdSql.checkRows(33) + sql = "select * from (select %s from stable_1 " % interp_select + sql += " where tbname in ('table_2') and ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT) group by tbname ORDER BY ts DESC);" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular2_checkall_0_NEXT(sql) + tdSql.checkRows(11) + sql = "select * from (select %s from stable_1 " % interp_select + sql += " where tbname in ('table_3') and ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT) group by tbname ORDER BY ts DESC);" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular3_checkall_0_NEXT(sql) + tdSql.checkRows(11) + + sql = "select * from (select %s from stable_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT) group by tbname);" % (self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + datacheck = self.regular1_checkall_0_NEXT(sql) + tdSql.checkRows(6) + sql = "select * from (select %s from stable_1 " % interp_select + sql += " where tbname in ('table_2') and ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT) group by tbname);" % (self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + datacheck = self.regular2_checkall_0_NEXT(sql) + tdSql.checkRows(2) + sql = "select * from (select %s from stable_1 " % interp_select + sql += " where tbname in ('table_3') and ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT) group by tbname);" % (self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + datacheck = self.regular3_checkall_0_NEXT(sql) + tdSql.checkRows(2) + + sql = "select * from (select %s from stable_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT) group by tbname);" % (self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + datacheck = self.result_0(sql) + sql = "select * from (select %s from stable_1 " % interp_select + sql += " where tbname in ('table_2') and ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT) group by tbname);" % (self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + datacheck = self.result_0(sql) + sql = "select * from (select %s from stable_1 " % interp_select + sql += " where tbname in ('table_3') and ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT) group by tbname);" % (self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + datacheck = self.result_0(sql) + + # Nested Query + where + range + FILL(NEXT) + EVERY( s)(2)--error + sql = "select %s from (select * from stable_1 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + tdSql.error(sql) + sql = "select %s from (select * from stable_1 where tbname in ('table_2'))" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + tdSql.error(sql) + sql = "select %s from (select * from stable_1 where tbname in ('table_3'))" % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + tdSql.error(sql) + + sql = "select %s from (select * from stable_1 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + tdSql.error(sql) + sql = "select %s from (select * from stable_1 where tbname in ('table_2'))" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + tdSql.error(sql) + sql = "select %s from (select * from stable_1 where tbname in ('table_3'))" % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + tdSql.error(sql) + + sql = "select %s from (select * from stable_1 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT);" % (self.ts , self.ts + 10000 , self.ts , self.ts) + tdSql.error(sql) + sql = "select %s from (select * from stable_1 where tbname in ('table_2'))" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT);" % (self.ts , self.ts + 10000 , self.ts , self.ts) + tdSql.error(sql) + sql = "select %s from (select * from stable_1 where tbname in ('table_3'))" % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT);" % (self.ts , self.ts + 10000 , self.ts , self.ts) + tdSql.error(sql) + + sql = "select %s from (select * from stable_1 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT);" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + tdSql.error(sql) + sql = "select %s from (select * from stable_1 where tbname in ('table_2'))" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT);" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + tdSql.error(sql) + sql = "select %s from (select * from stable_1 where tbname in ('table_3'))" % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT);" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + tdSql.error(sql) + + sql = "select %s from (select * from stable_1 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT);" % (self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + tdSql.error(sql) + sql = "select %s from (select * from stable_1 where tbname in ('table_2'))" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT);" % (self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + tdSql.error(sql) + sql = "select %s from (select * from stable_1 where tbname in ('table_3'))" % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT);" % (self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + tdSql.error(sql) + + sql = "select %s from (select * from stable_1 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT);" % (self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + tdSql.error(sql) + sql = "select %s from (select * from stable_1 where tbname in ('table_2'))" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT);" % (self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + tdSql.error(sql) + sql = "select %s from (select * from stable_1 where tbname in ('table_3'))" % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT);" % (self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + tdSql.error(sql) + + # Nested Query + where + range + FILL(NEXT) + EVERY( s)(3) + # sql = "select * from (select %s from stable_1 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT) group by tbname) z1," % (interp_select , self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + # sql += "(select %s from stable_1 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT) group by tbname) z2 where z1.ts=z2.ts ;" % (interp_select , self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + # datacheck = self.regular1_checkall_0(sql) + # tdSql.checkRows(21) + + # sql = "select * from (select %s from stable_1 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT) group by tbname) z1," % (interp_select , self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + # sql += "(select %s from stable_1 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT) group by tbname) z2 where z1.ts=z2.ts ;" % (interp_select , self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + # datacheck = self.regular2_checkall_0(sql) + # tdSql.checkRows(1) + + # sql = "select * from (select %s from stable_1 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT) group by tbname) z1," % (interp_select , self.ts , self.ts + 10000 , self.ts , self.ts) + # sql += "(select %s from stable_1 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT) group by tbname) z2 where z1.ts=z2.ts ;" % (interp_select , self.ts , self.ts + 10000 , self.ts , self.ts) + # datacheck = self.regular3_checkall_0(sql) + # tdSql.checkRows(1) + + # sql = "select * from (select %s from stable_1 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT) group by tbname) z1," % (interp_select , self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + # sql += "(select %s from stable_1 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT) group by tbname) z2 where z1.ts=z2.ts ;" % (interp_select , self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + # datacheck = self.regular1_checkall_0(sql) + # tdSql.checkRows(11) + + # sql = "select * from (select %s from stable_1 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT) group by tbname) z1," % (interp_select , self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + # sql += "(select %s from stable_1 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT) group by tbname) z2 where z1.ts=z2.ts ;" % (interp_select , self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + # datacheck = self.regular2_checkall_0_NEXT(sql) + # tdSql.checkRows(2) + + # sql = "select * from (select %s from stable_1 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT) group by tbname) z1," % (interp_select , self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + # sql += "(select %s from stable_1 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NEXT) group by tbname) z2 where z1.ts=z2.ts ;" % (interp_select , self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + # datacheck = self.result_0(sql) + + # Nested Query + where + range + FILL(PREV) + EVERY( s) (1) + sql = "select * from (select %s from stable_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV) group by tbname);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(303) + sql = "select * from (select %s from stable_1 " % interp_select + sql += "where tbname in ('table_2') and ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV) group by tbname);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(101) + sql = "select * from (select %s from stable_1 " % interp_select + sql += "where tbname in ('table_3') and ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(PREV) group by tbname);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(101) + + sql = "select * from (select %s from stable_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV) group by tbname);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + datacheck = self.result_0(sql) + sql = "select * from (select %s from stable_1 " % interp_select + sql += "where tbname in ('table_2') and ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV) group by tbname);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + datacheck = self.result_0(sql) + sql = "select * from (select %s from stable_1 " % interp_select + sql += "where tbname in ('table_3') and ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(PREV) group by tbname);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + datacheck = self.result_0(sql) + + sql = "select * from (select %s from stable_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV) group by tbname);" % (self.ts , self.ts + 10000 , self.ts , self.ts) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(3) + sql = "select * from (select %s from stable_1 " % interp_select + sql += "where tbname in ('table_2') and ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV) group by tbname);" % (self.ts , self.ts + 10000 , self.ts , self.ts) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(1) + sql = "select * from (select %s from stable_1 " % interp_select + sql += "where tbname in ('table_3') and ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(PREV) group by tbname);" % (self.ts , self.ts + 10000 , self.ts , self.ts) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(1) + + sql = "select * from (select %s from stable_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV) group by tbname);" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(603) + sql = "select * from (select %s from stable_1 " % interp_select + sql += "where tbname in ('table_2') and ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV) group by tbname);" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(201) + sql = "select * from (select %s from stable_1 " % interp_select + sql += "where tbname in ('table_3') and ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(PREV) group by tbname);" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(201) + + sql = "select * from (select %s from stable_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV) group by tbname ORDER BY ts DESC);" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0_NEXT(sql) + tdSql.checkRows(603) + sql = "select * from (select %s from stable_1 " % interp_select + sql += "where tbname in ('table_2') and ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV) group by tbname ORDER BY ts DESC);" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular2_checkall_0_NEXT(sql) + tdSql.checkRows(201) + sql = "select * from (select %s from stable_1 " % interp_select + sql += "where tbname in ('table_3') and ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(PREV) group by tbname ORDER BY ts DESC);" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular3_checkall_0_NEXT(sql) + tdSql.checkRows(201) + + sql = "select * from (select %s from stable_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV) group by tbname);" % (self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(6) + sql = "select * from (select %s from stable_1 " % interp_select + sql += "where tbname in ('table_2') and ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV) group by tbname);" % (self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(2) + sql = "select * from (select %s from stable_1 " % interp_select + sql += "where tbname in ('table_3') and ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(PREV) group by tbname);" % (self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(2) + + sql = "select * from (select %s from stable_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV) group by tbname);" % (self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + datacheck = self.regular1_checkall_0_NEXT(sql) + tdSql.checkRows(153) + sql = "select * from (select %s from stable_1 " % interp_select + sql += "where tbname in ('table_2') and ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV) group by tbname);" % (self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + datacheck = self.regular2_checkall_0_NEXT(sql) + tdSql.checkRows(51) + sql = "select * from (select %s from stable_1 " % interp_select + sql += "where tbname in ('table_3') and ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(PREV) group by tbname);" % (self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + datacheck = self.regular3_checkall_0_NEXT(sql) + tdSql.checkRows(51) + + # Nested Query + where + range + FILL(PREV) + EVERY( s)(2) + sql = "select %s from (select * from stable_1 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + datacheck = tdSql.error(sql) + sql = "select %s from (select * from stable_1 where tbname in ('table_2') )" % interp_select + sql += " where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + datacheck = tdSql.error(sql) + sql = "select %s from (select * from stable_1 where tbname in ('table_3') )" % interp_select + sql += " where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(PREV);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + datacheck = tdSql.error(sql) + + sql = "select %s from (select * from stable_1 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + datacheck = tdSql.error(sql) + sql = "select %s from (select * from stable_1 where tbname in ('table_2'))" % interp_select + sql += " where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + datacheck = tdSql.error(sql) + sql = "select %s from (select * from stable_1 where tbname in ('table_3'))" % interp_select + sql += " where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(PREV);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + datacheck = tdSql.error(sql) + + sql = "select %s from (select * from stable_1 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV);" % (self.ts , self.ts + 10000 , self.ts , self.ts) + datacheck = tdSql.error(sql) + sql = "select %s from (select * from stable_1 where tbname in ('table_2'))" % interp_select + sql += " where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV);" % (self.ts , self.ts + 10000 , self.ts , self.ts) + datacheck = tdSql.error(sql) + sql = "select %s from (select * from stable_1 where tbname in ('table_3'))" % interp_select + sql += " where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(PREV);" % (self.ts , self.ts + 10000 , self.ts , self.ts) + datacheck = tdSql.error(sql) + + sql = "select %s from (select * from stable_1 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV);" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = tdSql.error(sql) + sql = "select %s from (select * from stable_1 where tbname in ('table_2'))" % interp_select + sql += " where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV);" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = tdSql.error(sql) + sql = "select %s from (select * from stable_1 where tbname in ('table_3'))" % interp_select + sql += " where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(PREV);" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = tdSql.error(sql) + + sql = "select %s from (select * from stable_1 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV);" % (self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + datacheck = tdSql.error(sql) + sql = "select %s from (select * from stable_1 where tbname in ('table_2'))" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV);" % (self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + datacheck = tdSql.error(sql) + sql = "select %s from (select * from stable_1 where tbname in ('table_3'))" % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(PREV);" % (self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + datacheck = tdSql.error(sql) + + sql = "select %s from (select * from stable_1 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV);" % (self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + datacheck = tdSql.error(sql) + sql = "select %s from (select * from stable_1 where tbname in ('table_2'))" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV);" % (self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + datacheck = tdSql.error(sql) + sql = "select %s from (select * from stable_1 where tbname in ('table_3'))" % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(PREV);" % (self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + datacheck = tdSql.error(sql) + + # Nested Query + where + range + FILL(PREV) + EVERY( s)(3) + # sql = "select * from (select %s from stable_1 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV) group by tbname) z1," % (interp_select , self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + # sql += "(select %s from stable_2 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV) group by tbname) z2 where z1.ts=z2.ts ;" % (interp_select , self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + # datacheck = self.regular1_checkall_0(sql) + # tdSql.checkRows(101) + + # sql = "select * from (select %s from stable_1 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV) group by tbname) z1," % (interp_select , self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + # sql += "(select %s from stable_2 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV) group by tbname) z2 where z1.ts=z2.ts ;" % (interp_select , self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + # datacheck = self.result_0(sql) + + # sql = "select * from (select %s from stable_1 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV) group by tbname) z1," % (interp_select , self.ts , self.ts + 10000 , self.ts , self.ts) + # sql += "(select %s from stable_2 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV) group by tbname) z2 where z1.ts=z2.ts ;" % (interp_select , self.ts , self.ts + 10000 , self.ts , self.ts) + # datacheck = self.regular3_checkall_0(sql) + # tdSql.checkRows(1) + + # sql = "select * from (select %s from stable_1 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV) group by tbname) z1," % (interp_select , self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + # sql += "(select %s from stable_2 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV) group by tbname) z2 where z1.ts=z2.ts ;" % (interp_select , self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + # datacheck = self.regular1_checkall_0(sql) + # tdSql.checkRows(201) + + # sql = "select * from (select %s from stable_1 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV) group by tbname) z1," % (interp_select , self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + # sql += "(select %s from stable_2 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV) group by tbname) z2 where z1.ts=z2.ts ;" % (interp_select , self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + # datacheck = self.regular2_checkall_0(sql) + # tdSql.checkRows(2) + + # sql = "select * from (select %s from stable_1 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV) group by tbname) z1," % (interp_select , self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + # sql += "(select %s from stable_2 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(PREV) group by tbname) z2 where z1.ts=z2.ts ;" % (interp_select , self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + # datacheck = self.regular3_checkall_0_NEXT(sql) + # tdSql.checkRows(51) + + # Nested Query + where + range + FILL(VALUE, 100) + EVERY( s) (1) + sql = "select * from (select %s from stable_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100) group by tbname);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(333) + sql = "select * from (select %s from stable_1 " % interp_select + sql += " where tbname in ('table_2') and ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100) group by tbname);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(111) + sql = "select * from (select %s from stable_1 " % interp_select + sql += " where tbname in ('table_3') and ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100) group by tbname);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(111) + + sql = "select * from (select %s from stable_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100) group by tbname);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(3) + sql = "select * from (select %s from stable_1 " % interp_select + sql += " where tbname in ('table_2') and ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100) group by tbname);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(1) + sql = "select * from (select %s from stable_1 " % interp_select + sql += " where tbname in ('table_3') and ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100) group by tbname);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(1) + + sql = "select * from (select %s from stable_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100) group by tbname);" % (self.ts , self.ts + 10000 , self.ts , self.ts) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(3) + sql = "select * from (select %s from stable_1 " % interp_select + sql += " where tbname in ('table_2') and ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100) group by tbname);" % (self.ts , self.ts + 10000 , self.ts , self.ts) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(1) + sql = "select * from (select %s from stable_1 " % interp_select + sql += " where tbname in ('table_3') and ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100) group by tbname);" % (self.ts , self.ts + 10000 , self.ts , self.ts) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(1) + + sql = "select * from (select %s from stable_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100) group by tbname);" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(603) + sql = "select * from (select %s from stable_1 " % interp_select + sql += " where tbname in ('table_2') and ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100) group by tbname);" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(201) + sql = "select * from (select %s from stable_1 " % interp_select + sql += " where tbname in ('table_3') and ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100) group by tbname);" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(201) + + sql = "select * from (select %s from stable_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100) group by tbname ORDER BY ts DESC);" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(603) + sql = "select * from (select %s from stable_1 " % interp_select + sql += " where tbname in ('table_2') and ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100) group by tbname ORDER BY ts DESC);" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(201) + sql = "select * from (select %s from stable_1 " % interp_select + sql += " where tbname in ('table_3') and ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100) group by tbname ORDER BY ts DESC);" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(201) + + sql = "select * from (select %s from stable_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100) group by tbname);" % (self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(6) + sql = "select * from (select %s from stable_1 " % interp_select + sql += " where tbname in ('table_2') and ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100) group by tbname);" % (self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(2) + sql = "select * from (select %s from stable_1 " % interp_select + sql += " where tbname in ('table_3') and ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100) group by tbname);" % (self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(2) + + sql = "select * from (select %s from stable_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100) group by tbname);" % (self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(153) + sql = "select * from (select %s from stable_1 " % interp_select + sql += " where tbname in ('table_2') and ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100) group by tbname);" % (self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(51) + sql = "select * from (select %s from stable_1 " % interp_select + sql += " where tbname in ('table_3') and ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100) group by tbname);" % (self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + datacheck = self.regular1_checkall_0_VALUE100(sql) + tdSql.checkRows(51) + + # Nested Query + where + range + FILL(VALUE, 100) + EVERY( s)(2) + sql = "select %s from (select * from stable_1 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + datacheck = tdSql.error(sql) + sql = "select %s from (select * from stable_1 where tbname in ('table_2'))" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + datacheck = tdSql.error(sql) + sql = "select %s from (select * from stable_1 where tbname in ('table_3'))" % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + datacheck = tdSql.error(sql) + + sql = "select %s from (select * from stable_1 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + datacheck = tdSql.error(sql) + sql = "select %s from (select * from stable_1 where tbname in ('table_2'))" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + datacheck = tdSql.error(sql) + sql = "select %s from (select * from stable_1 where tbname in ('table_3'))" % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + datacheck = tdSql.error(sql) + + sql = "select %s from (select * from stable_1 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100);" % (self.ts , self.ts + 10000 , self.ts , self.ts) + datacheck = tdSql.error(sql) + sql = "select %s from (select * from stable_1 where tbname in ('table_2'))" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100);" % (self.ts , self.ts + 10000 , self.ts , self.ts) + datacheck = tdSql.error(sql) + sql = "select %s from (select * from stable_1 where tbname in ('table_3'))" % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100);" % (self.ts , self.ts + 10000 , self.ts , self.ts) + datacheck = tdSql.error(sql) + + sql = "select %s from (select * from stable_1 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100);" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = tdSql.error(sql) + sql = "select %s from (select * from stable_1 where tbname in ('table_2'))" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100);" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = tdSql.error(sql) + sql = "select %s from (select * from stable_1 where tbname in ('table_3'))" % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100);" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = tdSql.error(sql) + + sql = "select %s from (select * from stable_1 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100);" % (self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + datacheck = tdSql.error(sql) + sql = "select %s from (select * from stable_1 where tbname in ('table_2'))" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100);" % (self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + datacheck = tdSql.error(sql) + sql = "select %s from (select * from stable_1 where tbname in ('table_3'))" % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100);" % (self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + datacheck = tdSql.error(sql) + + sql = "select %s from (select * from stable_1 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100);" % (self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + datacheck = tdSql.error(sql) + sql = "select %s from (select * from stable_1 where tbname in ('table_2'))" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100);" % (self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + datacheck = tdSql.error(sql) + sql = "select %s from (select * from stable_1 where tbname in ('table_3'))" % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100);" % (self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + datacheck = tdSql.error(sql) + + # Nested Query + where + range + FILL(VALUE, 100) + EVERY( s)(3) + # sql = "select * from (select %s from stable_1 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100) group by tbname) z1," % (interp_select , self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + # sql += "(select %s from stable_2 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100) group by tbname) z2 where z1.ts=z2.ts ;" % (interp_select , self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + # datacheck = self.regular1_checkall_0_VALUE100(sql) + # tdSql.checkRows(111) + + # sql = "select * from (select %s from stable_1 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100) group by tbname) z1," % (interp_select , self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + # sql += "(select %s from stable_2 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100) group by tbname) z2 where z1.ts=z2.ts ;" % (interp_select , self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + # datacheck = self.regular1_checkall_0_VALUE100(sql) + # tdSql.checkRows(1) + + # sql = "select * from (select %s from stable_1 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100) group by tbname) z1," % (interp_select , self.ts , self.ts + 10000 , self.ts , self.ts) + # sql += "(select %s from stable_2 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100) group by tbname) z2 where z1.ts=z2.ts ;" % (interp_select , self.ts , self.ts + 10000 , self.ts , self.ts) + # datacheck = self.regular3_checkall_0(sql) + # tdSql.checkRows(1) + + # sql = "select * from (select %s from stable_1 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100) group by tbname) z1," % (interp_select , self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + # sql += "(select %s from stable_2 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100) group by tbname) z2 where z1.ts=z2.ts ;" % (interp_select , self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + # datacheck = self.regular1_checkall_0(sql) + # tdSql.checkRows(201) + + # sql = "select * from (select %s from stable_1 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100) group by tbname) z1," % (interp_select , self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + # sql += "(select %s from stable_2 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100) group by tbname) z2 where z1.ts=z2.ts ;" % (interp_select , self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + # datacheck = self.regular1_checkall_0_VALUE100(sql) + # tdSql.checkRows(2) + + # sql = "select * from (select %s from stable_1 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100) group by tbname) z1," % (interp_select , self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + # sql += "(select %s from stable_2 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(VALUE, 100) group by tbname) z2 where z1.ts=z2.ts ;" % (interp_select , self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + # datacheck = self.regular1_checkall_0_VALUE100(sql) + # tdSql.checkRows(51) + + # Nested Query + where + range + FILL(NULL) + EVERY( s) (1) + sql = "select * from (select %s from stable_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL) group by tbname);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(333) + sql = "select * from (select %s from stable_1 " % interp_select + sql += " where tbname in ('table_2') and ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL) group by tbname);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(111) + sql = "select * from (select %s from stable_1 " % interp_select + sql += " where tbname in ('table_3') and ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(NULL) group by tbname);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(111) + + sql = "select * from (select %s from stable_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL) group by tbname);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(3) + sql = "select * from (select %s from stable_1 " % interp_select + sql += " where tbname in ('table_2') and ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL) group by tbname);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(1) + sql = "select * from (select %s from stable_1 " % interp_select + sql += " where tbname in ('table_3') and ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(NULL) group by tbname);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(1) + + sql = "select * from (select %s from stable_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL) group by tbname);" % (self.ts , self.ts + 10000 , self.ts , self.ts) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(3) + sql = "select * from (select %s from stable_1 " % interp_select + sql += " where tbname in ('table_2') and ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL) group by tbname);" % (self.ts , self.ts + 10000 , self.ts , self.ts) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(1) + sql = "select * from (select %s from stable_1 " % interp_select + sql += " where tbname in ('table_3') and ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(NULL) group by tbname);" % (self.ts , self.ts + 10000 , self.ts , self.ts) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(1) + + sql = "select * from (select %s from stable_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL) group by tbname);" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0(sql) + tdSql.checkRows(603) + sql = "select * from (select %s from stable_1 " % interp_select + sql += " where tbname in ('table_2') and ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL) group by tbname);" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular2_checkall_0(sql) + tdSql.checkRows(201) + sql = "select * from (select %s from stable_1 " % interp_select + sql += " where tbname in ('table_3') and ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(NULL) group by tbname);" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular3_checkall_0(sql) + tdSql.checkRows(201) + + sql = "select * from (select %s from stable_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL) group by tbname ORDER BY ts DESC);" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(603) + sql = "select * from (select %s from stable_1 " % interp_select + sql += " where tbname in ('table_2') and ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL) group by tbname ORDER BY ts DESC);" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(201) + sql = "select * from (select %s from stable_1 " % interp_select + sql += " where tbname in ('table_3') and ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(NULL) group by tbname ORDER BY ts DESC);" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(201) + + sql = "select * from (select %s from stable_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL) group by tbname );" % (self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(6) + sql = "select * from (select %s from stable_1 " % interp_select + sql += " where tbname in ('table_2') and ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL) group by tbname);" % (self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(2) + sql = "select * from (select %s from stable_1 " % interp_select + sql += " where tbname in ('table_3') and ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(NULL) group by tbname);" % (self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(2) + + sql = "select * from (select %s from stable_1 " % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL) group by tbname);" % (self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(153) + sql = "select * from (select %s from stable_1 " % interp_select + sql += " where tbname in ('table_2') and ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL) group by tbname);" % (self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(51) + sql = "select * from (select %s from stable_1 " % interp_select + sql += " where tbname in ('table_3') and ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(NULL) group by tbname);" % (self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + datacheck = self.regular1_checkall_0_NULL(sql) + tdSql.checkRows(51) + + # Nested Query + where + range + FILL(NULL) + EVERY( s)(2) + sql = "select %s from (select * from stable_1 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + datacheck = tdSql.error(sql) + sql = "select %s from (select * from stable_1 where tbname in ('table_2'))" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + datacheck = tdSql.error(sql) + sql = "select %s from (select * from stable_1 where tbname in ('table_3'))" % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(NULL);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + datacheck = tdSql.error(sql) + + sql = "select %s from (select * from stable_1 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + datacheck = tdSql.error(sql) + sql = "select %s from (select * from stable_1 where tbname in ('table_2'))" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + datacheck = tdSql.error(sql) + sql = "select %s from (select * from stable_1 where tbname in ('table_3'))" % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(NULL);" % (self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + datacheck = tdSql.error(sql) + + sql = "select %s from (select * from stable_1 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL);" % (self.ts , self.ts + 10000 , self.ts , self.ts) + datacheck = tdSql.error(sql) + sql = "select %s from (select * from stable_1 where tbname in ('table_2'))" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL);" % (self.ts , self.ts + 10000 , self.ts , self.ts) + datacheck = tdSql.error(sql) + sql = "select %s from (select * from stable_1 where tbname in ('table_3'))" % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(NULL);" % (self.ts , self.ts + 10000 , self.ts , self.ts) + datacheck = tdSql.error(sql) + + sql = "select %s from (select * from stable_1 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL);" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = tdSql.error(sql) + sql = "select %s from (select * from stable_1 where tbname in ('table_2'))" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL);" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = tdSql.error(sql) + sql = "select %s from (select * from stable_1 where tbname in ('table_3'))" % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(NULL);" % (self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + datacheck = tdSql.error(sql) + + sql = "select %s from (select * from stable_1 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL);" % (self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + datacheck = tdSql.error(sql) + sql = "select %s from (select * from stable_1 where tbname in ('table_2'))" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL);" % (self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + datacheck = tdSql.error(sql) + sql = "select %s from (select * from stable_1 where tbname in ('table_3'))" % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(NULL);" % (self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + datacheck = tdSql.error(sql) + + sql = "select %s from (select * from stable_1 )" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL);" % (self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + datacheck = tdSql.error(sql) + sql = "select %s from (select * from stable_1 where tbname in ('table_2'))" % interp_select + sql += "where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL);" % (self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + datacheck = tdSql.error(sql) + sql = "select %s from (select * from stable_1 where tbname in ('table_3'))" % interp_select + sql += "where ts >= '%s' AND ts <= '%s' range('%s' , '%s') EVERY(1s) FILL(NULL);" % (self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + datacheck = tdSql.error(sql) + + # Nested Query + where + range + FILL(NULL) + EVERY( s)(3) + # sql = "select * from (select %s from stable_1 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL) group by tbname) z1," % (interp_select , self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + # sql += "(select %s from stable_2 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL) group by tbname) z2 where z1.ts=z2.ts ;" % (interp_select , self.ts , self.ts + 10000 , self.ts - 10000 , self.ts + 100000) + # datacheck = self.regular1_checkall_0_NULL(sql) + # tdSql.checkRows(111) + + # sql = "select * from (select %s from stable_1 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL) group by tbname) z1," % (interp_select , self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + # sql += "(select %s from stable_2 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL) group by tbname) z2 where z1.ts=z2.ts ;" % (interp_select , self.ts , self.ts + 10000 , self.ts - 10000 , self.ts - 9900) + # datacheck = self.regular1_checkall_0_NULL(sql) + # tdSql.checkRows(1) + + # sql = "select * from (select %s from stable_1 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL) group by tbname) z1," % (interp_select , self.ts , self.ts + 10000 , self.ts , self.ts) + # sql += "(select %s from stable_2 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL) group by tbname) z2 where z1.ts=z2.ts ;" % (interp_select , self.ts , self.ts + 10000 , self.ts , self.ts) + # datacheck = self.regular3_checkall_0(sql) + # tdSql.checkRows(1) + + # sql = "select * from (select %s from stable_1 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL) group by tbname) z1," % (interp_select , self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + # sql += "(select %s from stable_2 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL) group by tbname) z2 where z1.ts=z2.ts ;" % (interp_select , self.ts , self.ts + 10000 , self.ts , self.ts + 200000) + # datacheck = self.regular1_checkall_0(sql) + # tdSql.checkRows(201) + + # sql = "select * from (select %s from stable_1 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL) group by tbname) z1," % (interp_select , self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + # sql += "(select %s from stable_2 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL) group by tbname) z2 where z1.ts=z2.ts ;" % (interp_select , self.ts , self.ts + 10000 , self.ts + 1500 , self.ts + 2500) + # datacheck = self.regular1_checkall_0_NULL(sql) + # tdSql.checkRows(2) + + # sql = "select * from (select %s from stable_1 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL) group by tbname) z1," % (interp_select , self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + # sql += "(select %s from stable_2 where ts BETWEEN '%s' AND '%s' range('%s' , '%s') EVERY(1s) FILL(NULL) group by tbname) z2 where z1.ts=z2.ts ;" % (interp_select , self.ts , self.ts + 10000 , self.ts + 150000 , self.ts + 200000) + # datacheck = self.regular1_checkall_0_NULL(sql) + # tdSql.checkRows(51) + endTime = time.time() + print("total time %ds" % (endTime - startTime)) def stop(self): tdSql.close() diff --git a/tests/pytest/functions/queryTestCases.py b/tests/pytest/functions/queryTestCases.py index 75e2359bb1c6b03e27e60ea75dbaeb6e77f2cc13..8bdbee09e7f715384f048028e7cccd0010e5642b 100644 --- a/tests/pytest/functions/queryTestCases.py +++ b/tests/pytest/functions/queryTestCases.py @@ -84,7 +84,7 @@ class TDTestCase: index_value = np.dstack((cpms_index[0])).squeeze() tdSql.query("show variables") - tdSql.checkData(index_value, 1, -1) + tdSql.checkData(index_value, 1, 524288) tdSql.query("show dnodes") index = tdSql.getData(0, 0) @@ -1570,7 +1570,7 @@ class TDTestCase: # master branch self.td3690() - self.td4082() + # self.td4082() self.td4288() self.td4724() self.td5935() diff --git a/tests/pytest/insert/basic.py b/tests/pytest/insert/basic.py index f23f38651aa57590a14824077e003812ea10d8bd..72daad7bcae66aec879cb30cde8c786e3e6d14c2 100644 --- a/tests/pytest/insert/basic.py +++ b/tests/pytest/insert/basic.py @@ -45,6 +45,11 @@ class TDTestCase: # test case for https://jira.taosdata.com:18080/browse/TD-3716: tdSql.error("insert into tb(now, 1)") + # test case for TD-10717 + tdSql.error("insert into tb values(now,1),,(now+1s,1)") + tdSql.execute("insert into tb values(now+2s,1),(now+3s,1),(now+4s,1)") + tdSql.query("select * from tb") + tdSql.checkRows(insertRows + 4 +3) def stop(self): tdSql.close() diff --git a/tests/pytest/insert/insertJSONPayload.py b/tests/pytest/insert/insertJSONPayload.py index 81d4b47ef15cb03311943d3d53c2efe25a3b0312..a2e773328a7a346f17d8c256cce79d7beb9628e4 100644 --- a/tests/pytest/insert/insertJSONPayload.py +++ b/tests/pytest/insert/insertJSONPayload.py @@ -686,10 +686,10 @@ class TDTestCase: print("schemaless_insert result {}".format(code)) tdSql.query("describe `1234`") - tdSql.checkRows(8) + tdSql.checkRows(9) - tdSql.query("select * from `123`") - tdSql.checkRows(1) + #tdSql.query("select * from `123`") + #tdSql.checkRows(1) payload = [''' { @@ -711,10 +711,10 @@ class TDTestCase: print("schemaless_insert result {}".format(code)) tdSql.query("describe `int`") - tdSql.checkRows(8) + tdSql.checkRows(9) - tdSql.query("select * from `and`") - tdSql.checkRows(1) + #tdSql.query("select * from `and`") + #tdSql.checkRows(1) payload = [''' { @@ -736,10 +736,10 @@ class TDTestCase: print("schemaless_insert result {}".format(code)) tdSql.query("describe `double`") - tdSql.checkRows(8) + tdSql.checkRows(9) - tdSql.query("select * from `for`") - tdSql.checkRows(1) + #tdSql.query("select * from `for`") + #tdSql.checkRows(1) payload = [''' { @@ -761,10 +761,10 @@ class TDTestCase: print("schemaless_insert result {}".format(code)) tdSql.query("describe `from`") - tdSql.checkRows(8) + tdSql.checkRows(9) - tdSql.query("select * from `!@#.^&`") - tdSql.checkRows(1) + #tdSql.query("select * from `!@#.^&`") + #tdSql.checkRows(1) payload = [''' { @@ -786,10 +786,10 @@ class TDTestCase: print("schemaless_insert result {}".format(code)) tdSql.query("describe `!@#$.%^&*()`") - tdSql.checkRows(8) + tdSql.checkRows(9) - tdSql.query("select * from `none`") - tdSql.checkRows(1) + #tdSql.query("select * from `none`") + #tdSql.checkRows(1) payload = [''' { @@ -836,11 +836,10 @@ class TDTestCase: print("schemaless_insert result {}".format(code)) tdSql.query("describe `stable`") - tdSql.checkRows(8) - - tdSql.query("select * from `key`") - tdSql.checkRows(1) + tdSql.checkRows(9) + #tdSql.query("select * from `key`") + #tdSql.checkRows(1) def stop(self): tdSql.close() diff --git a/tests/pytest/insert/insertTelnetLines.py b/tests/pytest/insert/insertTelnetLines.py index a48351f6c0b162be83f6aca44a87ff9f55b498c8..149e62c362ab802fbbc4f2d939b3bf149cbf7e1b 100644 --- a/tests/pytest/insert/insertTelnetLines.py +++ b/tests/pytest/insert/insertTelnetLines.py @@ -32,10 +32,10 @@ class TDTestCase: ### metric ### print("============= step1 : test metric ================") lines0 = [ - "stb0_0 1626006833639000000ns 4i8 host=\"host0\" interface=\"eth0\"", - "stb0_1 1626006833639000000ns 4i8 host=\"host0\" interface=\"eth0\"", - "stb0_2 1626006833639000000ns 4i8 host=\"host0\" interface=\"eth0\"", - ".stb0.3. 1626006833639000000ns 4i8 host=\"host0\" interface=\"eth0\"", + "stb0_0 1626006833639 4i8 host=\"host0\" interface=\"eth0\"", + "stb0_1 1626006833639 4i8 host=\"host0\" interface=\"eth0\"", + "stb0_2 1626006833639 4i8 host=\"host0\" interface=\"eth0\"", + ".stb0.3. 1626006833639 4i8 host=\"host0\" interface=\"eth0\"", ] code = self._conn.schemaless_insert(lines0, TDSmlProtocolType.TELNET.value, TDSmlTimestampType.NOT_CONFIGURED.value) @@ -287,72 +287,72 @@ class TDTestCase: #tag ID as child table name - lines3_1 = [ - "stb3_1 1626006833610 1 id=child_table1 host=host1", - "stb3_1 1626006833610 2 host=host2 iD=child_table2", - "stb3_1 1626006833610 3 ID=child_table3 host=host3" - ] + #lines3_1 = [ + # "stb3_1 1626006833610 1 id=child_table1 host=host1", + # "stb3_1 1626006833610 2 host=host2 iD=child_table2", + # "stb3_1 1626006833610 3 ID=child_table3 host=host3" + # ] - code = self._conn.schemaless_insert(lines3_1, TDSmlProtocolType.TELNET.value, TDSmlTimestampType.NOT_CONFIGURED.value) - print("schemaless_insert result {}".format(code)) + #code = self._conn.schemaless_insert(lines3_1, TDSmlProtocolType.TELNET.value, TDSmlTimestampType.NOT_CONFIGURED.value) + #print("schemaless_insert result {}".format(code)) - tdSql.query("select * from stb3_1") - tdSql.checkRows(3) + #tdSql.query("select * from stb3_1") + #tdSql.checkRows(3) - tdSql.query("show tables like \"child%\"") - tdSql.checkRows(3) + #tdSql.query("show tables like \"child%\"") + #tdSql.checkRows(3) - tdSql.checkData(0, 0, "child_table1") + #tdSql.checkData(0, 0, "child_table1") ### special characters and keywords ### print("============= step4 : test special characters and keywords ================") lines4_1 = [ - "1234 1626006833610ms 1 id=123 456=true int=true double=false into=1 from=2 !@#$.%^&*()=false", - "int 1626006833610ms 2 id=and 456=true int=true double=false into=1 from=2 !@#$.%^&*()=false", - "double 1626006833610ms 2 id=for 456=true int=true double=false into=1 from=2 !@#$.%^&*()=false", - "from 1626006833610ms 2 id=!@#.^& 456=true int=true double=false into=1 from=2 !@#$.%^&*()=false", - "!@#$.%^&*() 1626006833610ms 2 id=none 456=true int=true double=false into=1 from=2 !@#$.%^&*()=false", - "STABLE 1626006833610ms 2 id=KEY 456=true int=true double=false TAG=1 FROM=2 COLUMN=false", + "1234 1626006833610 1 id=123 456=true int=true double=false into=1 from=2 !@#$.%^&*()=false", + "int 1626006833610 2 id=and 456=true int=true double=false into=1 from=2 !@#$.%^&*()=false", + "double 1626006833610 2 id=for 456=true int=true double=false into=1 from=2 !@#$.%^&*()=false", + "from 1626006833610 2 id=!@#.^& 456=true int=true double=false into=1 from=2 !@#$.%^&*()=false", + "!@#$.%^&*() 1626006833610 2 id=none 456=true int=true double=false into=1 from=2 !@#$.%^&*()=false", + "STABLE 1626006833610 2 id=KEY 456=true int=true double=false TAG=1 FROM=2 COLUMN=false", ] code = self._conn.schemaless_insert(lines4_1, TDSmlProtocolType.TELNET.value, TDSmlTimestampType.NOT_CONFIGURED.value) print("schemaless_insert result {}".format(code)) tdSql.query('describe `1234`') - tdSql.checkRows(8) + tdSql.checkRows(9) tdSql.query('describe `int`') - tdSql.checkRows(8) + tdSql.checkRows(9) tdSql.query('describe `double`') - tdSql.checkRows(8) + tdSql.checkRows(9) tdSql.query('describe `from`') - tdSql.checkRows(8) + tdSql.checkRows(9) tdSql.query('describe `!@#$.%^&*()`') - tdSql.checkRows(8) + tdSql.checkRows(9) tdSql.query('describe `stable`') - tdSql.checkRows(8) + tdSql.checkRows(9) - tdSql.query('select * from `123`') - tdSql.checkRows(1) + #tdSql.query('select * from `123`') + #tdSql.checkRows(1) - tdSql.query('select * from `and`') - tdSql.checkRows(1) + #tdSql.query('select * from `and`') + #tdSql.checkRows(1) - tdSql.query('select * from `for`') - tdSql.checkRows(1) + #tdSql.query('select * from `for`') + #tdSql.checkRows(1) - tdSql.query('select * from `!@#.^&`') - tdSql.checkRows(1) + #tdSql.query('select * from `!@#.^&`') + #tdSql.checkRows(1) - tdSql.query('select * from `none`') - tdSql.checkRows(1) + #tdSql.query('select * from `none`') + #tdSql.checkRows(1) - tdSql.query('select * from `key`') - tdSql.checkRows(1) + #tdSql.query('select * from `key`') + #tdSql.checkRows(1) def stop(self): tdSql.close() diff --git a/tests/pytest/insert/line_insert.py b/tests/pytest/insert/line_insert.py index ff26483aeb323ebd309ba7a41e91ac860af9d222..acc43d80e719065706aaee95c5cdbaf5235ae04b 100644 --- a/tests/pytest/insert/line_insert.py +++ b/tests/pytest/insert/line_insert.py @@ -83,8 +83,8 @@ class TDTestCase: tdSql.query('select tbname, * from sth') tdSql.checkRows(2) - tdSql.query('select tbname, * from childtable') - tdSql.checkRows(1) + #tdSql.query('select tbname, * from childtable') + #tdSql.checkRows(1) ###Special Character and keyss self._conn.schemaless_insert([ @@ -98,40 +98,40 @@ class TDTestCase: tdSql.execute('reset query cache') tdSql.query('describe `1234`') - tdSql.checkRows(9) + tdSql.checkRows(10) tdSql.query('describe `int`') - tdSql.checkRows(8) + tdSql.checkRows(9) tdSql.query('describe `double`') - tdSql.checkRows(8) + tdSql.checkRows(9) tdSql.query('describe `from`') - tdSql.checkRows(8) + tdSql.checkRows(9) tdSql.query('describe `!@#$.%^&*()`') - tdSql.checkRows(8) + tdSql.checkRows(9) tdSql.query('describe `stable`') - tdSql.checkRows(8) + tdSql.checkRows(9) - tdSql.query('select * from `3456`') - tdSql.checkRows(1) + #tdSql.query('select * from `3456`') + #tdSql.checkRows(1) - tdSql.query('select * from `and`') - tdSql.checkRows(1) + #tdSql.query('select * from `and`') + #tdSql.checkRows(1) - tdSql.query('select * from `for`') - tdSql.checkRows(1) + #tdSql.query('select * from `for`') + #tdSql.checkRows(1) - tdSql.query('select * from `!@#$.%^`') - tdSql.checkRows(1) + #tdSql.query('select * from `!@#$.%^`') + #tdSql.checkRows(1) - tdSql.query('select * from `none`') - tdSql.checkRows(1) + #tdSql.query('select * from `none`') + #tdSql.checkRows(1) - tdSql.query('select * from `create`') - tdSql.checkRows(1) + #tdSql.query('select * from `create`') + #tdSql.checkRows(1) def stop(self): tdSql.close() tdLog.success("%s successfully executed" % __file__) diff --git a/tests/pytest/query/bug5903.py b/tests/pytest/query/bug5903.py new file mode 100644 index 0000000000000000000000000000000000000000..a973efbbdf7a0868a4db7910bf57bd5eef8dae06 --- /dev/null +++ b/tests/pytest/query/bug5903.py @@ -0,0 +1,36 @@ +################################################################### +# 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 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 run(self): + # TD-5903 show db.vgroups xxx. xxx is invalid content, but still returns results. + + tdSql.execute("create database if not exists test_5903") + tdSql.execute("show test_5903.vgroups") + tdSql.error("show test_5903.vgroups xxx") + + 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/nestedQuery/nestedQuery.py b/tests/pytest/query/nestedQuery/nestedQuery.py index 545f6429e825c468bdb07524329d6ea49944e379..9260aced9a1d79649802917daad8f36ec9cf249e 100755 --- a/tests/pytest/query/nestedQuery/nestedQuery.py +++ b/tests/pytest/query/nestedQuery/nestedQuery.py @@ -366,7 +366,7 @@ class TDTestCase: calc_select_regular = [ 'PERCENTILE(q_int,10)' ,'PERCENTILE(q_bigint,20)' , 'PERCENTILE(q_smallint,30)' ,'PERCENTILE(q_tinyint,40)' ,'PERCENTILE(q_float,50)' ,'PERCENTILE(q_double,60)'] - calc_select_fill = ['INTERP(q_bool)' ,'INTERP(q_binary)' ,'INTERP(q_nchar)' ,'INTERP(q_ts)', 'INTERP(q_int)' ,'INTERP(*)' ,'INTERP(q_bigint)' ,'INTERP(q_smallint)' ,'INTERP(q_tinyint)', 'INTERP(q_float)' ,'INTERP(q_double)'] + calc_select_fill = ['INTERP(q_int)' ,'INTERP(q_bigint)' ,'INTERP(q_smallint)' ,'INTERP(q_tinyint)', 'INTERP(q_float)' ,'INTERP(q_double)'] interp_where = ['ts = now' , 'ts = \'2020-09-13 20:26:40.000\'' , 'ts = \'2020-09-13 20:26:40.009\'' ,'tbname in (\'table_1\') and ts = now' ,'tbname in (\'table_0\' ,\'table_1\',\'table_2\',\'table_3\',\'table_4\',\'table_5\') and ts = \'2020-09-13 20:26:40.000\'','tbname like \'table%\' and ts = \'2020-09-13 20:26:40.002\''] #two table join @@ -396,8 +396,8 @@ class TDTestCase: 'PERCENTILE(t2.q_int,10)' ,'PERCENTILE(t2.q_bigint,20)' , 'PERCENTILE(t2.q_smallint,30)' ,'PERCENTILE(t2.q_tinyint,40)' ,'PERCENTILE(t2.q_float,50)' ,'PERCENTILE(t2.q_double,60)'] - calc_select_fill_j = ['INTERP(t1.q_bool)' ,'INTERP(t1.q_binary)' ,'INTERP(t1.q_nchar)' ,'INTERP(t1.q_ts)', 'INTERP(t1.q_int)' ,'INTERP(t1.*)' ,'INTERP(t1.q_bigint)' ,'INTERP(t1.q_smallint)' ,'INTERP(t1.q_tinyint)', 'INTERP(t1.q_float)' ,'INTERP(t1.q_double)' , - 'INTERP(t2.q_bool)' ,'INTERP(t2.q_binary)' ,'INTERP(t2.q_nchar)' ,'INTERP(t2.q_ts)', 'INTERP(t2.q_int)' ,'INTERP(t2.*)' ,'INTERP(t2.q_bigint)' ,'INTERP(t2.q_smallint)' ,'INTERP(t2.q_tinyint)', 'INTERP(t2.q_float)' ,'INTERP(t2.q_double)'] + calc_select_fill_j = ['INTERP(t1.q_int)' ,'INTERP(t1.q_bigint)' ,'INTERP(t1.q_smallint)' ,'INTERP(t1.q_tinyint)', 'INTERP(t1.q_float)' ,'INTERP(t1.q_double)' , + 'INTERP(t2.q_int)' ,'INTERP(t2.q_bigint)' ,'INTERP(t2.q_smallint)' ,'INTERP(t2.q_tinyint)', 'INTERP(t2.q_float)' ,'INTERP(t2.q_double)'] interp_where_j = ['t1.ts = now' , 't1.ts = \'2020-09-13 20:26:40.000\'' , 't1.ts = \'2020-09-13 20:26:40.009\'' ,'t2.ts = now' , 't2.ts = \'2020-09-13 20:26:40.000\'' , 't2.ts = \'2020-09-13 20:26:40.009\'' , 't1.tbname in (\'table_1\') and t1.ts = now' ,'t1.tbname in (\'table_0\' ,\'table_1\',\'table_2\',\'table_3\',\'table_4\',\'table_5\') and t1.ts = \'2020-09-13 20:26:40.000\'','t1.tbname like \'table%\' and t1.ts = \'2020-09-13 20:26:40.002\'', 't2.tbname in (\'table_1\') and t2.ts = now' ,'t2.tbname in (\'table_0\' ,\'table_1\',\'table_2\',\'table_3\',\'table_4\',\'table_5\') and t2.ts = \'2020-09-13 20:26:40.000\'','t2.tbname like \'table%\' and t2.ts = \'2020-09-13 20:26:40.002\''] @@ -1996,7 +1996,7 @@ class TDTestCase: sql += ") " tdLog.info(sql) tdLog.info(len(sql)) - tdSql.query(sql) + #tdSql.query(sql) rsDn = self.restartDnodes() tdSql.query("select 20-2 from table_0;") @@ -2014,7 +2014,7 @@ class TDTestCase: sql += ") " tdLog.info(sql) tdLog.info(len(sql)) - tdSql.query(sql) + #tdSql.query(sql) tdSql.query("select 20-2.2 from table_0;") for i in range(self.fornum): @@ -2391,4 +2391,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/query/query.py b/tests/pytest/query/query.py index 8e79fc5f686d77aa276da5bca7d9493ff1a00ffb..31831cca9facea6aba1a6fc88a84a33a66583a5e 100644 --- a/tests/pytest/query/query.py +++ b/tests/pytest/query/query.py @@ -31,13 +31,42 @@ class TDTestCase: tdSql.execute("create database bug6387 ") tdSql.execute("use bug6387 ") tdSql.execute("create table test(ts timestamp, c1 int) tags(t1 int)") + prefix = "insert into " + sql = "" for i in range(5000): - sql = "insert into t%d using test tags(1) values " % i + temp = "t%d using test tags(1) values " % i for j in range(21): - sql = sql + "(now+%ds,%d)" % (j ,j ) - tdSql.execute(sql) + temp = temp + "(now+%ds,%d)" % (j ,j ) + sql = sql + temp + if i % 1000 == 0 : + tdSql.execute(prefix + sql) + sql = "" tdSql.query("select count(*) from test interval(1s) group by tbname") tdSql.checkData(0,1,1) + + def escape_ascii(self): + tdSql.execute('drop database if exists db') + tdSql.execute('create database db') + tdSql.execute('use db') + tdSql.execute("create table car (ts timestamp, s int) tags(j int)") + for i in range(32,127): + if i == 96 : continue #` + sql = 'create table `是否出现%s` using car tags(%d)' % (chr(i), i) + tdSql.execute(sql) + for i in range(32,65): + sql = 'select tbname from car where tbname like "是否出现\%s"' % chr(i) + tdSql.query(sql) + if i == 37 : continue # " ` + tdSql.checkRows(1) + for i in range(91,97): + sql = 'select tbname from car where tbname like "是否出现\%s"' % chr(i) + tdSql.query(sql) + if i == 96: continue # ` + tdSql.checkRows(1) + for i in range(123,127): + sql = 'select tbname from car where tbname like "是否出现\%s"' % chr(i) + tdSql.query(sql) + tdSql.checkRows(1) def run(self): tdSql.prepare() @@ -165,6 +194,10 @@ class TDTestCase: tdSql.query("show create table t1") tdSql.checkRows(1) + #TS-636 + tdLog.info("case for TS-636") + self.escape_ascii() + def stop(self): tdSql.close() tdLog.success("%s successfully executed" % __file__) diff --git a/tests/pytest/query/queryGroupTbname.py b/tests/pytest/query/queryGroupTbname.py index 8665a3f7746aa9e2868cb9f4d4d9d6c9a7e7859c..bb67809e60087f94ad7f92ca7515aa8ddfc43151 100644 --- a/tests/pytest/query/queryGroupTbname.py +++ b/tests/pytest/query/queryGroupTbname.py @@ -10,10 +10,12 @@ ################################################################### # -*- coding: utf-8 -*- +from util.dnodes import tdDnodes from util.log import tdLog from util.cases import tdCases from util.sql import tdSql from util.common import tdCom +import random class TDTestCase: def init(self, conn, logSql): @@ -46,8 +48,53 @@ class TDTestCase: for i in range(100): tdSql.query(f'select {table_name_sub1},{table_name_sub2},{table_name_sub3},{table_name_sub4},{table_name_sub5},{table_name_sub6},{table_name_sub7},{table_name_sub8},{table_name_sub9} from {table_name} where tbname in ("{table_name_sub1}","{table_name_sub2}","{table_name_sub3}","{table_name_sub4}","{table_name_sub5}","{table_name_sub6}","{table_name_sub7}","{table_name_sub8}","{table_name_sub9}") and ts >= "1980-01-01 00:00:00.000"') + tdSql.checkRows(0) + + # TS-634 + tdLog.info("test case for bug TS-634") + tdSql.execute("create database test") + tdSql.execute("use test") + tdSql.execute("create table meters (ts TIMESTAMP,voltage INT) TAGS (tableid INT)") + tdSql.execute("CREATE TABLE t1 USING meters TAGS (1)") + tdSql.execute("CREATE TABLE t2 USING meters TAGS (2)") + + ts = 1605381041000 + for i in range(10): + tdSql.execute("INSERT INTO t1 values(%d, %d)" % (ts + i, random.randint(0, 100))) + tdSql.execute("INSERT INTO t2 values(%d, %d)" % (ts + i, random.randint(0, 100))) + + tdSql.query("select last_row(*), tbname from meters group by tbname order by ts desc") + tdSql.checkRows(2) + + tdSql.execute("INSERT INTO t2 values(now, 2)") + tdSql.query("select last_row(*), tbname from meters group by tbname order by ts desc") + tdSql.checkRows(2) + + # TS-561 null tags group by crash + tdLog.info("test case for TS-561") + tdSql.execute("create database openfalcon") + tdSql.execute("use openfalcon") + tdSql.execute("create table stb (ts timestamp, value double) tags(_endpoint binary(150), _hostname binary(150), _indexname binary(50), _ip binary(50), _q_name binary(150))") + tdSql.execute("create table tb0 using stb tags('root.FTBI', 'CNSZ17VL4774', 'max_mem', '10.116.100.10_8088', 'root.line_volume_predict')") + tdSql.execute("create table tb1 using stb(_endpoint, _hostname, _indexname) tags('root.medium_high_freq', 'CNSZ17VL4775', 'max_mem_1')") + + for i in range(2): + sql = "insert into tb%d values" % i + for j in range(10000): + sql += "(%d, %d)" % (ts + j * 500, random.randint(1, 10000) + random.uniform(1.0, 1000.0)) + tdSql.execute(sql) + + tdSql.query("select avg(value) from openfalcon.stb where ts > '2020-11-15 03:30:00.000' and ts < '2020-11-15 04:30:00.000' group by _hostname, _indexname, _ip, _q_name") + tdSql.checkRows(2) + + tdDnodes.stop(1) + tdDnodes.start(1) + + tdSql.query("select avg(value) from openfalcon.stb where ts > '2020-11-15 03:30:00.000' and ts < '2020-11-15 04:30:00.000' group by _hostname, _indexname, _ip, _q_name") + tdSql.checkRows(2) + def run(self): tdSql.prepare() self.queryGroupTbname() diff --git a/tests/pytest/query/sliding.py b/tests/pytest/query/sliding.py index d7a7c9a36964796dd530f913523f8f4d344d467a..f5c59ec1bae4f54c5e4acad90d5b5172c0fa3b7a 100644 --- a/tests/pytest/query/sliding.py +++ b/tests/pytest/query/sliding.py @@ -54,7 +54,7 @@ class TDTestCase: tdSql.error("select * from meters group by loc sliding(5s)") - # Fix defect: https://jira.taosdata.com:18080/browse/TD-2700 + # TD-2700 tdSql.execute("create database test") tdSql.execute("use test") tdSql.execute("create table t1(ts timestamp, k int)") diff --git a/tests/pytest/query/udf.py b/tests/pytest/query/udf.py index 14429a53f44b1393c9f179cc405ed61fb59e8b02..e9fc42c72edc9d6eee5592852960ddb8d53d124a 100644 --- a/tests/pytest/query/udf.py +++ b/tests/pytest/query/udf.py @@ -73,21 +73,18 @@ class TDTestCase: tdSql.error(sql) sql = 'select abs_max(c2) from db.stb' tdSql.query(sql) - tdSql.checkData(0,0,1410065607) + tdSql.checkData(0,0,10000000199) def test_udf_values(self): tdSql.execute("drop function abs_max") tdSql.execute("create function add_one as '/tmp/add_one.so' outputtype int") tdSql.execute("create aggregate function abs_max as '/tmp/abs_max.so' outputtype bigint;") - tdSql.execute("create aggregate function sum_double as '/tmp/sum_double.so' outputtype int bufsize 128;") + tdSql.execute("create aggregate function sum_double as '/tmp/sum_double.so' outputtype bigint;") - # UDF bug no 1 -> follow 3 cases about this bug ; # tdSql.error("create aggregate function max as '/tmp/abs_max.so' outputtype bigint ;") # tdSql.error("create aggregate function avg as '/tmp/abs_max.so' outputtype bigint ;") # tdSql.error("create aggregate function dbs as '/tmp/abs_max.so' outputtype bigint ;") - - tdSql.execute("drop database if exists test") tdSql.execute("create database test") tdSql.execute("use test") @@ -117,7 +114,7 @@ class TDTestCase: tdSql.execute("insert into bound values(%d, %d , %f, %d , %s)"%(epoch_time+1000,intdata2+1,float(intdata2+1),bigintdata2+1,"'binary"+str(intdata2+1)+"'")) # check super table calculation results - tdSql.query("select add_one(id) from st") + tdSql.query("select add_one(id) test from st") tdSql.checkData(0,0,1) tdSql.checkData(1,0,2) tdSql.checkData(4,0,5) @@ -157,29 +154,266 @@ class TDTestCase: tdLog.info(" ====== unexpected error occured about UDF function =====") sys.exit() - # UDF bug no 2 -> values of abs_max not inconsistent from common table and stable. - # tdSql.query("select abs_max(val) from st") # result is 0 rows - # tdSql.query("select abs_max(val) from tb1") - # tdSql.checkData(0,0,0) # this is error result - # tdSql.query("select sum_double(val) from st") # result is 0 rows - # tdSql.query("select sum_double(val) from tb1") - # tdSql.checkData(0,0,0) # this is error result + tdSql.query("select abs_max(val) from st") + tdSql.query("select abs_max(val) from tb1") + tdSql.checkRows(0) + tdSql.query("select sum_double(val) from st") + tdSql.query("select sum_double(val) from tb1") + tdSql.checkRows(0) - # UDF bug no 3 -> values of abs_max will error for boundary number - # check super table calculation results - # tdSql.query("select abs_max(number) from st") - # tdSql.checkData(0,0,9223372036854775807) + tdSql.query("select abs_max(number) from st") + tdSql.checkData(0,0,9223372036854775807) # check common table calculation results tdSql.query("select abs_max(number) from tb1") tdSql.checkData(0,0,400) tdSql.query("select abs_max(number) from tb2") tdSql.checkData(0,0,400) + tdSql.execute("select add_one(id) from st limit 10 offset 2") + tdSql.query("select add_one(id) from st where ts > 1604298064000 and ts < 1604298064020 ") + tdSql.checkData(0,0,1) + tdSql.checkData(1,0,-2147483644) + tdSql.query("select add_one(id) from tb1 where ts > 1604298064000 and ts < 1604298064020 ") + tdSql.checkData(0,0,1) + tdSql.query("select sum_double(id) from st where ts > 1604298064030 and ts < 1604298064060 ") + tdSql.checkData(0,0,14) + tdSql.query("select sum_double(id) from tb2 where ts > 1604298064030 and ts < 1604298064060 ") + tdSql.checkRows(0) + tdSql.query("select add_one(id) from st where ts = 1604298064000 ") + tdSql.checkData(0,0,-2147483645) + tdSql.query("select add_one(id) from st where ts > 1604298064000 and id in (2,3) and ind =1;") + tdSql.checkData(0,0,3) + tdSql.checkData(1,0,4) + tdSql.query("select id , add_one(id) from tb1 where ts > 1604298064000 and id in (2,3)") + tdSql.checkData(0,0,2) + tdSql.checkData(0,1,3) + tdSql.checkData(1,0,3) + tdSql.checkData(1,1,4) + tdSql.query("select sum_double(id) from tb1 where ts > 1604298064000 and id in (2,3)") + tdSql.checkData(0,0,10) + tdSql.query("select sum_double(id) from st where ts > 1604298064000 and id in (2,3) and ind =1") + tdSql.checkData(0,0,10) + tdSql.query("select abs_max(number) from st where ts > 1604298064000 and id in (2,3) and ind =1") + tdSql.checkData(0,0,300) + tdSql.query("select sum_double(id) from st where ts = 1604298064030 ") + tdSql.checkData(0,0,4) + tdSql.query("select abs_max(number) from st where ts = 1604298064100 ") + tdSql.checkData(0,0,9223372036854775806) + tdSql.query("select abs_max(number) from tb2 where ts = 1604298064100 ") + tdSql.checkData(0,0,400) + tdSql.query("select sum_double(id) from tb2 where ts = 1604298064100 ") + tdSql.checkData(0,0,8) + tdSql.query("select add_one(id) from st where ts >= 1604298064000 and ts <= 1604298064010") + tdSql.checkData(0,0,1) + tdSql.checkData(1,0,-2147483645) + tdSql.checkData(2,0,-2147483644) + tdSql.query("select add_one(id) from tb1 where ts >= 1604298064000 and ts <= 1604298064010") + tdSql.checkData(0,0,1) + tdSql.query("select sum_double(id) from st where ts >= 1604298064030 and ts <= 1604298064050") + tdSql.checkData(0,0,18) + tdSql.query("select sum_double(id) from tb2 where ts >= 1604298064030 and ts <= 1604298064100") + tdSql.checkData(0,0,20) + tdSql.query("select abs_max(number) from tb2 where ts >= 1604298064030 and ts <= 1604298064100") + tdSql.checkData(0,0,400) + tdSql.query("select abs_max(number) from st where ts >= 1604298064030 and ts <= 1604298064100") + tdSql.checkData(0,0,9223372036854775806) + tdSql.query("select id from st where id != 0 and ts >=1604298064070") + tdSql.checkData(0,0,1) + tdSql.query("select add_one(id) from st where id != 0 and ts >=1604298064070") + tdSql.checkData(0,0,2) + tdSql.query("select add_one(id) from st where id <> 0 and ts >=1604298064010") + tdSql.checkData(0,0,2) + tdSql.query("select sum_double(id) from st where id in (2,3,4) and ts >=1604298064070") + tdSql.checkData(0,0,18) + tdSql.query("select sum_double(id) from tb2 where id in (2,3,4) and ts >=1604298064070") + tdSql.checkData(0,0,18) + tdSql.query("select abs_max(number) from st where id in (2,3,4) and ts >=1604298064070") + tdSql.checkData(0,0,400) + tdSql.query("select add_one(id) from st where id = 0 ") + tdSql.checkData(0,0,1) + tdSql.checkData(1,0,1) + tdSql.query("select add_one(id) from tb2 where id = 0 ") + tdSql.checkData(0,0,1) + tdSql.query("select sum_double(id) from st where id = 1") + tdSql.checkData(0,0,4) + tdSql.query("select sum_double(id) from tb2 where id = 1") + tdSql.checkData(0,0,2) + + + tdSql.query("select add_one(id) from st where id is not null and ts >=1604298065000 ") + tdSql.checkData(0,0,None) + tdSql.query("select abs_max(number) from st where id is not null and ts >=1604298065000 ") + tdSql.checkData(0,0,9223372036854775807) + tdSql.query("select abs_max(number) from bound where id is not null and ts >=1604298065000 ") + tdSql.checkData(0,0,9223372036854775807) + tdSql.query("select sum_double(id) from st where id is not null and ts >=1604298064000 and ind = 1 ") + tdSql.checkData(0,0,20) + tdSql.query("select sum_double(id) from tb1 where id is not null and ts >=1604298064000 ") + tdSql.checkData(0,0,20) + tdSql.query("select add_one(id) from st where id is null and ts >=1604298065000 ") + tdSql.checkRows(0) + tdSql.query("select abs_max(number) from st where id is null and ts >=1604298065000 ") + tdSql.checkRows(0) + tdSql.query("select abs_max(number) from tb1 where id is null and ts >=1604298065000 ") + tdSql.checkRows(0) + tdSql.query("select add_one(id) from bound where id is not null and ts >=1604298065000;") + tdSql.checkData(0,0,None) + tdSql.query("select id,add_one(id) from bound;") + tdSql.checkRowCol(4,2) + tdSql.checkData(3,1,None) + tdSql.query("select add_one(id) from st where ts between 1604298064000 and 1604298064010") + tdSql.checkRows(3) + tdSql.query("select add_one(id) from tb1 where ts between 1604298064000 and 1604298064010") + tdSql.checkRows(1) + tdSql.query("select sum_double(id) from st where ts between 1604298064000 and 1604298064010 and id>=0") + tdSql.checkData(0,0,0) + tdSql.query("select sum_double(id) from tb1 where ts between 1604298064000 and 1604298064010 and id>=0") + tdSql.checkData(0,0,0) + tdSql.query("select add_one(id) from st where id in (1,2)") + tdSql.checkData(0,0,2) + tdSql.checkData(1,0,3) + tdSql.checkData(2,0,2) + tdSql.checkData(3,0,3) + tdSql.checkRows(4) + + tdSql.query("select sum_double(id) from st where ts < now and ind =1 interval(1s)") + tdSql.checkData(0,1,20) + tdSql.error("select sum_double(id) from st where ts < now and ind =1 interval(3s) sliding (1s) fill (NULL) ") + tdSql.error("select sum_double(id) from st session(ts, 1s)") + tdSql.query("select sum_double(id) from tb1 session(ts, 1s)") + tdSql.checkData(0,1,20) + + # intervals sliding values calculation + tdSql.query("select sum_double(id) from st where ts < now and ind =1 interval(3s) sliding (1s) limit 2") + tdSql.checkData(0,1,20) + tdSql.checkData(1,1,20) + + # scalar_function can't work when using interval and sliding ========= + tdSql.error("select add_one(id) from st where ts < now and ind =1 interval(3s) sliding (1s) limit 2 ") + tdSql.error("select add_one(id) from st order by ts") + tdSql.error("select ts,id,add_one(id) from st order by ts asc;") + + # # UDF not support order by + tdSql.error("select ts,id,add_one(id) from st order by ts desc;") + + # UDF function union all + tdSql.query("select add_one(id) from tb1 union all select add_one(id) from tb2;") + tdSql.checkRows(10) + tdSql.checkData(0,0,1) + tdSql.checkData(5,0,1) + tdSql.query("select sum_double(id) from tb1 union all select sum_double(id) from tb2;") + tdSql.checkRows(2) + tdSql.checkData(0,0,20) + tdSql.checkData(1,0,20) + tdSql.query("select abs_max(number) from tb1 union all select abs_max(number) from bound;") + tdSql.checkRows(2) + tdSql.checkData(0,0,400) + tdSql.checkData(1,0,9223372036854775807) + tdSql.execute("create stable stb (ts timestamp,id int , val double , number bigint, chars binary(200)) tags (ind int)") + tdSql.execute("create table stb1 using stb tags(3)") + tdSql.execute("insert into stb1 values(1604298064000 , 1 , 1.0 , 10000 ,'chars')") + tdSql.query("select add_one(id) from st union all select add_one(id) from stb;") + tdSql.checkRows(15) + tdSql.checkData(13,0,None) + tdSql.checkData(14,0,2) + tdSql.query("select add_one(id) from st union all select add_one(id) from stb1;") + tdSql.checkRows(15) + tdSql.checkData(13,0,None) + tdSql.checkData(14,0,2) + tdSql.query("select id ,add_one(id) from tb1 union all select id ,add_one(id) from stb1;") + tdSql.checkRows(6) + tdSql.checkData(0,0,0) + tdSql.checkData(0,1,1) + tdSql.checkData(1,0,1) + tdSql.checkData(1,1,2) + + # aggregate union all for different stables + tdSql.query("select sum_double(id) from st union all select sum_double(id) from stb;") + tdSql.checkRows(2) + tdSql.checkData(0,0,44) + tdSql.checkData(1,0,2) + tdSql.query("select id from st union all select id from stb1;") + tdSql.checkRows(15) + tdSql.query("select id from tb1 union all select id from stb1") + tdSql.checkRows(6) + tdSql.query("select sum_double(id) from tb1 union all select sum_double(id) from stb") + tdSql.checkData(0,0,20) + tdSql.checkData(1,0,2) + tdSql.query("select sum_double(id) from st union all select sum_double(id) from stb1;") + tdSql.checkRows(2) + tdSql.checkData(0,0,44) + tdSql.checkData(1,0,2) + tdSql.query("select abs_max(number) from st union all select abs_max(number) from stb;") + tdSql.checkData(0,0,9223372036854775807) + tdSql.query("select abs_max(number) from bound union all select abs_max(number) from stb1;") + tdSql.checkData(0,0,9223372036854775807) + tdSql.checkData(1,0,10000) + tdSql.query("select abs_max(number) from st union all select abs_max(number) from stb1;") + tdSql.checkData(0,0,9223372036854775807) + tdSql.checkData(1,0,10000) + + # group by for aggegate function ; + tdSql.query("select sum_double(id) from st group by tbname;") + tdSql.checkData(0,0,20) + tdSql.checkData(0,1,'tb1') + tdSql.checkData(1,0,20) + tdSql.checkData(1,1,'tb2') + tdSql.query("select sum_double(id) from st group by id;") + tdSql.checkRows(9) + tdSql.query("select sum_double(id) from st group by ts") + tdSql.checkRows(12) + tdSql.query("select sum_double(id) from st group by ind") + tdSql.checkRows(3) + tdSql.query("select sum_double(id) from st group by tbname order by ts asc;") + tdSql.query("select abs_max(number) from st group by id") + tdSql.checkRows(9) + tdSql.checkData(0,0,9223372036854775806) + tdSql.checkData(8,0,9223372036854775807) + tdSql.query("select abs_max(number) from st group by ts") + tdSql.checkRows(12) + tdSql.checkData(11,0,9223372036854775807) + tdSql.checkData(1,0,9223372036854775805) + tdSql.query("select abs_max(number) from st group by ind") + tdSql.checkRows(3) + tdSql.checkData(0,0,400) + tdSql.checkData(2,0,9223372036854775807) + + # UDF join + tdSql.query("select add_one(tb1.id),add_one(bound.id) from tb1,bound where tb1.ts=bound.ts;") + tdSql.checkData(0,0,1) + tdSql.checkData(0,1,-2147483644) + tdSql.query("select stb1.ts,add_one(stb1.id),bound.ts,add_one(bound.id) from stb1,bound where stb1.ts=bound.ts") + tdSql.checkData(0,1,2) + tdSql.checkData(0,3,-2147483645) + tdSql.query("select st.ts,add_one(st.id),stb.ts,add_one(stb.id) from st,stb where st.ts=stb.ts and st.ind=stb.ind") + tdSql.checkData(0,1,-2147483645) + tdSql.checkData(0,3,2) + + tdSql.query("select sum_double(tb1.id),sum_double(bound.id) from tb1,bound where tb1.ts=bound.ts;") + tdSql.checkData(0,0,0) + tdSql.checkData(0,1,-4294967290) + tdSql.query("select sum_double(stb1.id),sum_double(bound.id) from stb1,bound where stb1.ts=bound.ts") + tdSql.checkData(0,0,2) + tdSql.checkData(0,1,-4294967292) + + #UDF join for stables + tdSql.query("select sum_double(st.id),sum_double(stb.id) from st,stb where st.ts=stb.ts and st.ind=stb.ind") + tdSql.checkData(0,0,-4294967292) + tdSql.checkData(0,1,2) + tdSql.query("select abs_max(tb1.number),abs_max(bound.number) from tb1,bound where tb1.ts=bound.ts;") + tdSql.checkData(0,0,0) + tdSql.checkData(0,1,9223372036854775805) + tdSql.query("select abs_max(stb1.number),abs_max(bound.number) from stb1,bound where stb1.ts=bound.ts") + tdSql.checkData(0,0,10000) + tdSql.checkData(0,1,9223372036854775806) + tdSql.query("select abs_max(st.number),abs_max(stb.number) from st,stb where st.ts=stb.ts and st.ind=stb.ind") + tdSql.checkData(0,0,9223372036854775806) + tdSql.checkData(0,1,10000) # check boundary - # tdSql.query("select abs_max(number) from bound") - # tdSql.checkData(0,0,9223372036854775807) + tdSql.query("select abs_max(number) from bound") + tdSql.checkData(0,0,9223372036854775807) tdLog.info("======= UDF function sum_double check =======") @@ -189,14 +423,10 @@ class TDTestCase: tdSql.query("select sum_double(id) from tb1") tdSql.checkData(0,0,20) - # UDF bug no 4 -> values error while two function work : it is limit that udf can't work with build-in functions. - # tdSql.query("select sum_double(id) , abs_max(number) from tb1") - # tdSql.checkData(0,0,20) - # tdSql.checkData(0,0,400) - - # tdSql.query("select sum_double(id) , abs_max(number) from st") - # tdSql.checkData(0,0,44) - # tdSql.checkData(0,0,9223372036854775807) + # only one udf function in SQL can use ,follow errors notice. + tdSql.error("select sum_double(id) , abs_max(number) from tb1") + tdSql.error("select sum_double(id) , abs_max(number) from st") + # UDF not support mix up with build-in functions # it seems like not support scalar_function mix up with aggregate functions @@ -204,147 +434,162 @@ class TDTestCase: tdSql.error("select sum_double(id) ,add_one(id) from tb1") tdSql.error("select sum_double(id) ,max(id) from st") tdSql.error("select sum_double(id) ,max(id) from tb1") + tdSql.error("select twa(id),add_one(id) from st") + tdSql.error("select twa(id),add_one(id) from tb1") # UDF function not support Arithmetic =================== + tdSql.query("select max(id) + 5 from st") tdSql.query("select max(id) + 5 from tb1") tdSql.query("select max(id) + avg(val) from st") + tdSql.query("select abs_max(number)*5 from st") + tdSql.checkData(0,0,46116860184273879040.000000000) + tdSql.query("select abs_max(number)*5 from tb1") + tdSql.checkData(0,0,2000.000000000) tdSql.query("select max(id) + avg(val) from tb1") - tdSql.query("select abs_max(number) + 5 from st") + tdSql.query("select add_one(id) + 5 from st") + tdSql.checkData(4,0,10.000000000) + tdSql.query("select add_one(id)/5 from tb1") + tdSql.checkData(4,0,1.000000000) + tdSql.query("select sum_double(id)-5 from st") + tdSql.checkData(0,0,39.000000000) + tdSql.query("select sum_double(id)*5 from tb1") + tdSql.checkData(0,0,100.000000000) + + tdSql.query("select abs_max(number) + 5 from tb1") tdSql.error("select abs_max(number) + max(id) from st") - tdSql.query("select abs_max(number)*abs_max(val) from st") + tdSql.query("select abs_max(number)*abs_max(val) from st") + tdSql.query("select sum_double(id) + sum_double(id) from st") + tdSql.checkData(0,0,88.000000000) tdLog.info("======= UDF Nested query test =======") tdSql.query("select sum(id) from (select id from st)") tdSql.checkData(0,0,22) - #UDF bug no 5 -> not support Nested query - # tdSql.query("select abs_max(number) from (select number from st)") - # tdSql.checkData(0,0,9223372036854775807) - # tdSql.query("select abs_max(number) from (select number from bound)") - # tdSql.checkData(0,0,9223372036854775807) - # tdSql.query("select sum_double(id) from (select id from st)") - # tdSql.checkData(0,0,44) - # tdSql.query("select sum_double(id) from (select id from tb1)") - # tdSql.checkData(0,0,10) + #UDF bug -> Nested query + # outer nest query + tdSql.query("select abs_max(number) from (select number from st)") + tdSql.checkData(0,0,9223372036854775807) + tdSql.query("select abs_max(number) from (select number from bound)") + tdSql.checkData(0,0,9223372036854775807) + tdSql.query("select sum_double(id) from (select id from st)") + tdSql.checkData(0,0,44) + tdSql.query("select sum_double(id) from (select id from bound)") + tdSql.checkData(0,0,4) + tdSql.query("select add_one(id) from (select id from st);") + tdSql.checkRows(14) + tdSql.checkData(1,0,2) + tdSql.query("select add_one(id) from (select id from bound);") + tdSql.checkRows(4) + tdSql.checkData(1,0,-2147483644) - # UDF bug no 6 -> group by work error - tdLog.info("======= UDF work with group by =======") + # inner nest query + tdSql.query("select id from (select add_one(id) id from st)") + tdSql.checkRows(14) + tdSql.checkData(13,0,None) + tdSql.query("select id from (select add_one(id) id from bound)") + tdSql.checkRows(4) + tdSql.checkData(3,0,None) - # tdSql.query("select sum_double(id) from st group by tbname;") - # tdSql.checkData(0,0,6) - # tdSql.checkData(0,1,'tb1') - # tdSql.checkData(1,0,2) - # tdSql.checkData(1,1,'tb2') - # tdSql.query("select sum_double(id) from st group by id;") - # tdSql.checkRows(2) - # tdSql.query("select sum_double(id) from st group by tbname order by ts asc;") + tdSql.query("select id from (select sum_double(id) id from bound)") + tdSql.checkData(0,0,4) + tdSql.query("select id from (select sum_double(id) id from st)") # it will crash taos shell + tdSql.checkData(0,0,44) + tdSql.query("select id from (select abs_max(number) id from st)") # it will crash taos shell + tdSql.checkData(0,0,9223372036854775807) + tdSql.query("select id from (select abs_max(number) id from bound)") + tdSql.checkData(0,0,9223372036854775807) - tdSql.query("select sum_double(id) from st where ts < now and ind =1 interval(1s)") - tdSql.checkData(0,1,20) - tdSql.error("select sum_double(id) from st session(ts, 1s) interval (10s,1s) sliding(10s) fill (NULL) ") - tdSql.error("select sum_double(id) from st session(ts, 1s)") - tdSql.query("select sum_double(id) from tb1 session(ts, 1s)") - tdSql.checkData(0,1,20) + # inner and outer nest query - # UDF -> bug no 7 : intervals sliding values calculation error - # tdSql.query("select sum_double(id) from st where ts < now and ind =1 interval(3s) sliding (1s) limit 2") - # tdSql.checkData(0,1,20) - # tdSql.checkData(1,1,20) + tdSql.query("select add_one(id) from (select add_one(id) id from st)") + tdSql.checkRows(14) + tdSql.checkData(0,0,2) + tdSql.checkData(1,0,3) + + tdSql.query("select add_one(id) from (select add_one(id) id from tb1)") + tdSql.checkRows(5) + tdSql.checkData(0,0,2) + tdSql.checkData(1,0,3) + + tdSql.query("select sum_double(sumdb) from (select sum_double(id) sumdb from st)") + tdSql.query("select sum_double(sumdb) from (select sum_double(id) sumdb from tb1)") - # scalar_function can't work when using interval and sliding ========= - tdSql.error("select add_one(id) from st where ts < now and ind =1 interval(3s) sliding (1s) limit 2 ") + tdSql.query("select abs_max(number) from (select abs_max(number) number from st)") + tdSql.checkData(0,0,9223372036854775807) + + tdSql.query("select abs_max(number) from (select abs_max(number) number from bound)") + tdSql.checkData(0,0,9223372036854775807) + + # nest inner and outer with build-in func + + tdSql.query("select max(number) from (select abs_max(number) number from st)") + tdSql.checkData(0,0,9223372036854775807) + + tdSql.query("select max(number) from (select abs_max(number) number from bound)") + tdSql.checkData(0,0,9223372036854775807) + + tdSql.query("select sum_double(sumdb) from (select sum_double(id) sumdb from st)") + + tdSql.query("select sum(sumdb) from (select sum_double(id) sumdb from tb1)") + tdSql.checkData(0,0,20) + tdLog.info(" =====================test illegal creation method =====================") - tdSql.execute("drop function add_one") + # tdSql.execute("drop function add_one") tdSql.execute("drop function abs_max") tdSql.execute("drop function sum_double") tdSql.execute("create aggregate function error_use1 as '/tmp/abs_max.so' outputtype bigint ") tdSql.error("select error_use1(number) from st") - # UDF -> bug no 8: error return values when create aggregate functions as an scalar_function + # illega UDF create aggregate functions as an scalar_function # with no aggregate - # tdSql.execute("create function abs_max as '/tmp/abs_max.so' outputtype bigint bufsize 128") - # tdSql.query("select abs_max(number) from st") # this bug will return 3 rows - # tdSql.checkRows(1) - # tdSql.execute("create function sum_double as '/tmp/sum_double.so' outputtype bigint bufsize 128") - # tdSql.execute("select sum_double(id) from st") - # tdSql.checkRows(1) - - # UDF -> bug no 9: give bufsize for scalar_function add_one; - # UDF -> need improve : when outputtype is not match datatype which is defined in function codes - tdSql.execute("create function add_one as '/tmp/add_one.so' outputtype bigint bufsize 128") - # tdSql.error("select add_one(val) from st") # it should return error not [] for not match col datatype - # tdSql.query("select add_one(id) from st") # return error query result - # tdSql.checkData(0,0,1) - # tdSql.checkData(1,0,2) - # tdSql.checkData(5,0,1) - # tdSql.checkData(10,0,-2147483645) - # tdSql.checkData(13,0,None) + tdSql.execute("create function abs_max as '/tmp/abs_max.so' outputtype bigint bufsize 128") + tdSql.error("select abs_max(number) from st") + tdSql.execute("create function sum_double as '/tmp/sum_double.so' outputtype bigint bufsize 128") + tdSql.error("select sum_double(id) from st") # UDF -> improve : aggregate function with no bufsize : it seems with no affect - # tdSql.execute("drop function abs_max") - # tdSql.execute("drop function sum_double") + tdSql.execute("drop function abs_max") + tdSql.execute("drop function sum_double") tdSql.execute("create aggregate function abs_max as '/tmp/abs_max.so' outputtype bigint ") tdSql.execute("create aggregate function sum_double as '/tmp/sum_double.so' outputtype int ") tdSql.query("select sum_double(id) from st") tdSql.checkData(0,0,44) tdSql.query("select sum_double(id) from tb1") tdSql.checkData(0,0,20) - # tdSql.query("select abs_max(number) from st") - # tdSql.checkData(0,0,9223372036854775807) + tdSql.query("select abs_max(number) from st") + tdSql.checkData(0,0,9223372036854775807) tdSql.query("select abs_max(number) from tb1") tdSql.checkData(0,0,400) - - #UDF bug no 10 -> create function datatype of outputtype not match col datatype - tdSql.execute("drop function abs_max") - tdSql.execute("drop function sum_double") - tdSql.execute("drop function add_one") - tdSql.execute("create function add_one as '/tmp/add_one.so' outputtype bigint;") - tdSql.execute("create aggregate function abs_max as '/tmp/abs_max.so' outputtype int bufsize 128;") - tdSql.execute("create aggregate function sum_double as '/tmp/sum_double.so' outputtype double bufsize 128;") - # tdSql.query("select sum_double(id) from st") this bug will return 0.000000 - # tdSql.checkData(0,0,44) - # tdSql.query("select sum_double(id) from tb1") - # tdSql.checkData(0,0,20) this bug will return 0.000000 - # tdSql.query("select add_one(id) from st") this bug will return series error values - # tdSql.checkData(0,0,1) - # tdSql.checkData(1,0,2) - # tdSql.checkData(5,0,1) - # tdSql.checkData(10,0,-2147483645) - # tdSql.checkData(13,0,None) - # tdSql.query("select add_one(id) from tb1") this bug will return series error values - # tdSql.checkData(0,0,1) - # tdSql.checkData(2,0,3) - # tdSql.query("select abs_max(id) from st") - # tdSql.checkData(0,0,9223372036854775807) + tdSql.query("select abs_max(number) from tb1") # it seems work well tdSql.checkData(0,0,400) + # UDF scalar function not support group by + tdSql.error("select add_one(id) from st group by tbname") - # UDF bug no 11 -> follow test case will coredump for taosd and let data lost - # tdSql.query("select add_one(id) from st group by tbname") - - # UDF -> bug no 12: give aggregate for scalar_function add_one ,it will let taosd coredump as data lost - # tdSql.execute("drop function add_one") - # tdSql.execute("create aggregate function add_one as '/tmp/add_one.so' outputtype bigint bufsize 128") - # tdSql.query("select add_one(id) from st") - - # UDF bug no 13 -> follow test case will coredump for taosc - # tdSql.query("select add_one(*) from st ") - # tdSql.query("select add_one(*) from tb1 ") - - # UDF bug no 14 -> follow test case will coredump for taosc - # tdSql.query("select abs_max(id),abs_max(number) from st ") - # tdSql.query("select abs_max(number),abs_max(number) from st ") - # tdSql.query("select sum_double(id),sum_double(id) from st ") + # UDF : give aggregate for scalar_function add_one ,it can't work well + tdSql.execute("drop function add_one") + tdSql.execute("create aggregate function add_one as '/tmp/add_one.so' outputtype bigint bufsize 128") + tdSql.error("select add_one(id) from st") + + # udf must give col list + tdSql.error("select add_one(*) from st ") + tdSql.error("select add_one(*) from tb1 ") + + # one udf function can multi use + tdSql.query("select abs_max(id),abs_max(number) from st ") + tdSql.query("select abs_max(number),abs_max(number)*3 from st ") + tdSql.query("select abs_max(number),abs_max(number)*3 from tb1 ") + tdSql.query("select sum_double(id),sum_double(id) from st ") def run(self): tdSql.prepare() @@ -366,4 +611,4 @@ class TDTestCase: tdCases.addWindows(__file__, TDTestCase()) -tdCases.addLinux(__file__, TDTestCase()) +tdCases.addLinux(__file__, TDTestCase()) \ No newline at end of file diff --git a/tests/pytest/stable/insert.py b/tests/pytest/stable/insert.py index ef5635c77ce04ddd33354e1754dc70b2c9f8b6a5..f46a6bcf4a0becf6cbee54281a9b3ecc862d63ce 100644 --- a/tests/pytest/stable/insert.py +++ b/tests/pytest/stable/insert.py @@ -91,6 +91,12 @@ class TDTestCase: tdSql.query("show stables") tdSql.checkRows(1) + # TS-646 + tdLog.info("test case for TS-646") + tdSql.execute("drop stable if exists db.st") + tdSql.execute("create table stb(ts timestamp, c1 int) tags(t1 int)") + tdSql.error("create table `` using stb tags(1)") + def stop(self): tdSql.close() tdLog.success("%s successfully executed" % __file__) diff --git a/tests/pytest/table/create.py b/tests/pytest/table/create.py index ec9179c5e97356f284b8d11ed006c12518142328..c431e2f6437786b0a9b787428659f029a41fa779 100644 --- a/tests/pytest/table/create.py +++ b/tests/pytest/table/create.py @@ -178,6 +178,8 @@ class TDTestCase: tdSql.checkRows(1) self.tb193new = "table_193~!@#$%^&*()-_+=[]{}':,<.>/?stST0123456789table_192~!@#$%^&*()-_+=[]{}':,<.>/?stST0123456789table_192~!@#$%^&*()-_+=[]{}':,<.>/?stST0123456789table_192~!@#$%^&*()-_+=[]{}':,<.>/?stST123" tdSql.error("create table db.`%s` using db.`%s` tags(1)" %(self.tb193new,self.stb1)) + # case for TD-10691 + tdSql.error("create table ttb1(ts timestamp, file int )") diff --git a/tests/script/api/batchprepare.c b/tests/script/api/batchprepare.c index e1db54e291ac6e02715a80ee852e5d78dc672a87..2cbee8eac91719a4cbff4d9c323f1f304e8e8684 100644 --- a/tests/script/api/batchprepare.c +++ b/tests/script/api/batchprepare.c @@ -1765,7 +1765,7 @@ int stmt_funcb_autoctb_e1(TAOS_STMT *stmt) { 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; + exit(1); } int id = 0; @@ -1801,9 +1801,44 @@ int stmt_funcb_autoctb_e1(TAOS_STMT *stmt) { return 0; } +int stmt_multi_insert_check(TAOS_STMT *stmt) { + char *sql; + // The number of tag column list is not equal to the number of tag value list + sql = "insert into ? using stb1 (id1) tags(1,?) values(?,?,?,?,?,?,?,?,?,?)"; + if (0 == taos_stmt_prepare(stmt, sql, 0)) { + printf("failed to check taos_stmt_prepare. sql:%s\n", sql); + exit(1); + } + + // The number of column list is not equal to the number of value list + sql = "insert into ? using stb1 tags(1,?,2,?,4,?,6.0,?,'b') " + "(ts, b, v1, v2, v4, v8, f4, f8, bin) values(?,?,?,?,?,?,?,?,?,?)"; + if (0 == taos_stmt_prepare(stmt, sql, 0)) { + printf("failed to check taos_stmt_prepare. sql:%s\n", sql); + exit(1); + } + + sql = "insert into ? using stb1 () tags(1,?) values(?,?,?,?,?,?,?,?,?,?)"; + if (0 == taos_stmt_prepare(stmt, sql, 0)) { + printf("failed to check taos_stmt_prepare. sql:%s\n", sql); + exit(1); + } + + sql = "insert into ? using stb1 ( tags(1,?) values(?,?,?,?,?,?,?,?,?,?)"; + if (0 == taos_stmt_prepare(stmt, sql, 0)) { + printf("failed to check taos_stmt_prepare. sql:%s\n", sql); + exit(1); + } + sql = "insert into ? using stb1 ) tags(1,?) values(?,?,?,?,?,?,?,?,?,?)"; + if (0 == taos_stmt_prepare(stmt, sql, 0)) { + printf("failed to check taos_stmt_prepare. sql:%s\n", sql); + exit(1); + } + return 0; +} //1 tables 10 records int stmt_funcb_autoctb_e2(TAOS_STMT *stmt) { @@ -4509,7 +4544,6 @@ void* runcase(void *par) { (void)idx; - #if 1 prepare(taos, 1, 1); @@ -4823,6 +4857,16 @@ void* runcase(void *par) { #endif +#if 1 + prepare(taos, 1, 0); + + stmt = taos_stmt_init(taos); + + printf("stmt_multi_insert_check start\n"); + stmt_multi_insert_check(stmt); + printf("stmt_multi_insert_check end\n"); + taos_stmt_close(stmt); +#endif #if 1 prepare(taos, 1, 1); @@ -5011,7 +5055,6 @@ void* runcase(void *par) { printf("check result end\n"); #endif - #if 1 preparem(taos, 0, idx); diff --git a/tests/script/fullGeneralSuite.sim b/tests/script/fullGeneralSuite.sim index ebc054777940430e9cdb78b55b496dda873f2143..a2b3978ad7fd6c6f2b4adf9f62b9edb4fed2a9e5 100644 --- a/tests/script/fullGeneralSuite.sim +++ b/tests/script/fullGeneralSuite.sim @@ -130,7 +130,7 @@ run general/parser/limit2.sim run general/parser/slimit.sim run general/parser/fill.sim run general/parser/fill_stb.sim -run general/parser/interp.sim +run general/parser/interp_full.sim run general/parser/where.sim run general/parser/join.sim run general/parser/join_multivnode.sim diff --git a/tests/script/general/parser/interp.sim b/tests/script/general/parser/interp.sim deleted file mode 100644 index f192837bb7422046b0fbf05e66b2f2165d7e3c10..0000000000000000000000000000000000000000 --- a/tests/script/general/parser/interp.sim +++ /dev/null @@ -1,83 +0,0 @@ -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 = intp_db -$tbPrefix = intp_tb -$stbPrefix = intp_stb -$tbNum = 4 -$rowNum = 10000 -$totalNum = $tbNum * $rowNum -$ts0 = 1537146000000 -$delta = 600000 -print ========== interp.sim -$i = 0 -$db = $dbPrefix . $i -$stb = $stbPrefix . $i - -sql drop database $db -x step1 -step1: -sql create database $db -print ====== create tables -sql use $db -sql create table $stb (ts timestamp, c1 int, c2 bigint, c3 float, c4 double, c5 smallint, c6 tinyint, c7 bool, c8 binary(10), c9 nchar(10)) tags(t1 int) - -$i = 0 -$ts = $ts0 -$halfNum = $tbNum / 2 -while $i < $halfNum - $tbId = $i + $halfNum - $tb = $tbPrefix . $i - $tb1 = $tbPrefix . $tbId - sql create table $tb using $stb tags( $i ) - sql create table $tb1 using $stb tags( $tbId ) - - $x = 0 - while $x < $rowNum - $xs = $x * $delta - $ts = $ts0 + $xs - $c = $x / 10 - $c = $c * 10 - $c = $x - $c - $binary = 'binary . $c - $binary = $binary . ' - $nchar = 'nchar . $c - $nchar = $nchar . ' - sql insert into $tb values ( $ts , $c , $c , $c , $c , $c , $c , true, $binary , $nchar ) $tb1 values ( $ts , $c , NULL , $c , NULL , $c , $c , true, $binary , $nchar ) - $x = $x + 1 - endw - - $i = $i + 1 -endw -print ====== tables created - -sql create table ap1 (ts timestamp, pav float); -sql INSERT INTO ap1 VALUES ('2021-07-25 02:19:54.100',1) ('2021-07-25 02:19:54.200',2) ('2021-07-25 02:19:54.300',3) ('2021-07-25 02:19:56.500',4) ('2021-07-25 02:19:57.500',5) ('2021-07-25 02:19:57.600',6) ('2021-07-25 02:19:57.900',7) ('2021-07-25 02:19:58.100',8) ('2021-07-25 02:19:58.300',9) ('2021-07-25 02:19:59.100',10) ('2021-07-25 02:19:59.300',11) ('2021-07-25 02:19:59.500',12) ('2021-07-25 02:19:59.700',13) ('2021-07-25 02:19:59.900',14) ('2021-07-25 02:20:05.000', 20) ('2021-07-25 02:25:00.000', 10000); - -run general/parser/interp_test.sim - -print ================== restart server to commit data into disk -system sh/exec.sh -n dnode1 -s stop -x SIGINT -sleep 500 -system sh/exec.sh -n dnode1 -s start -print ================== server restart completed - -run general/parser/interp_test.sim - -print ================= TD-5931 -sql create stable st5931(ts timestamp, f int) tags(t int) -sql create table ct5931 using st5931 tags(1) -sql create table nt5931(ts timestamp, f int) -sql select interp(*) from nt5931 where ts=now -sql select interp(*) from st5931 where ts=now -sql select interp(*) from ct5931 where ts=now - -if $rows != 0 then - return -1 -endi - -system sh/exec.sh -n dnode1 -s stop -x SIGINT diff --git a/tests/script/general/parser/interp_full.sim b/tests/script/general/parser/interp_full.sim new file mode 100644 index 0000000000000000000000000000000000000000..530ce20604d045c5a7510da72b5122bb8c60411b --- /dev/null +++ b/tests/script/general/parser/interp_full.sim @@ -0,0 +1,153 @@ +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/cfg.sh -n dnode1 -c minRows -v 10 +system sh/exec.sh -n dnode1 -s start +sleep 100 +sql connect + +sql create database db; +sql use db; +sql create stable stb1 (ts timestamp, c1 int, c2 float, c3 bigint, c4 smallint, c5 tinyint, c6 double, c7 bool, c8 binary(10), c9 nchar(9)) TAGS(t1 int, t2 binary(10), t3 double) +sql create table tb1 using stb1 tags(1,'1',1.0) +sql create table tb2 using stb1 tags(2,'2',2.0) +sql create table tb3 using stb1 tags(3,'3',3.0) +sql create table tb4 using stb1 tags(4,'4',4.0) + +sql insert into tb1 values ('2021-10-20 10:00:00',0,0.0,0,0,0,0.0,true ,'0','0') +sql insert into tb1 values ('2021-10-20 10:00:01',1,1.0,1,1,1,1.0,true ,'1','1') +sql insert into tb1 values ('2021-10-20 10:00:03',3,3.0,3,3,3,3.0,false,'3','3') +sql insert into tb1 values ('2021-10-20 10:00:06',6,6.0,6,6,6,6.0,false,'6','6') +sql insert into tb1 values ('2021-10-20 10:00:10',10,10.0,10,10,10,10.0,true ,'10','10') +sql insert into tb1 values ('2021-10-20 10:00:15',15,15.0,15,15,15,15.0,true ,'15','15') +sql insert into tb1 values ('2021-10-20 10:00:21',21,21.0,21,21,21,21.0,false,'21','21') + +sql insert into tb2 values ('2021-10-20 10:00:00',0,0.0,0,0,0,0.0,true ,'0','0') +sql insert into tb2 values ('2021-10-20 10:00:02',2,2.0,2,2,2,2.0,true ,'2','2') +sql insert into tb2 values ('2021-10-20 10:00:04',4,4.0,4,4,4,4.0,false,'4','4') +sql insert into tb2 values ('2021-10-20 10:00:06',6,6.0,6,6,6,6.0,false,'6','6') +sql insert into tb2 values ('2021-10-20 10:00:10',10,10.0,10,10,10,10.0,true ,'10','10') +sql insert into tb2 values ('2021-10-20 10:00:12',12,12.0,12,12,12,12.0,true ,'12','12') +sql insert into tb2 values ('2021-10-20 10:00:14',14,14.0,14,14,14,14.0,false,'14','14') + +sql insert into tb3 values ('2021-10-20 10:00:00',0,0.0,0,0,0,0.0,true ,'0','0') +sql insert into tb3 values ('2021-10-20 10:00:01',1,1.0,1,1,1,1.0,true ,'1','1') +sql insert into tb3 values ('2021-10-20 10:00:02',2,2.0,2,2,2,2.0,false,'2','2') +sql insert into tb3 values ('2021-10-20 10:00:06',6,6.0,6,6,6,6.0,false,'6','6') +sql insert into tb3 values ('2021-10-20 10:00:10',10,10.0,10,10,10,10.0,true ,'10','10') +sql insert into tb3 values ('2021-10-20 10:00:18',18,18.0,18,18,18,18.0,true ,'18','18') +sql insert into tb3 values ('2021-10-20 10:00:21',21,21.0,21,21,21,21.0,false,'21','21') + + +sql create stable stb4 (ts timestamp, c1 int, c2 float, c3 bigint, c4 smallint, c5 tinyint, c6 double, c7 bool, c8 binary(10), c9 nchar(9)) TAGS(t1 int, t2 binary(10), t3 double) + +sql create table tb4_0 using stb4 tags(0,'0',0.0) +sql create table tb4_1 using stb4 tags(1,'1',1.0) +sql create table tb4_2 using stb4 tags(2,'2',2.0) + +sql insert into tb4_0 values ('2021-10-20 10:00:00',0,0.0,0,0,0,0.0,true ,'0','0') +sql insert into tb4_0 values ('2021-10-20 10:00:01',1,1.0,1,1,1,1.0,true ,'1','1') +sql insert into tb4_0 values ('2021-10-20 10:00:03',3,3.0,3,3,3,3.0,false,'3','3') +sql insert into tb4_0 values ('2021-10-20 10:00:06',6,6.0,6,6,6,6.0,false,'6','6') +sql insert into tb4_0 values ('2021-10-20 10:00:10',10,10.0,10,10,10,10.0,true ,'10','10') +sql insert into tb4_0 values ('2021-10-20 10:00:15',15,15.0,15,15,15,15.0,true ,'15','15') +sql insert into tb4_0 values ('2021-10-20 10:00:21',21,21.0,21,21,21,21.0,false,'21','21') +sql insert into tb4_0 values ('2021-10-20 10:00:28',28,28.0,28,28,28,28.0,false,'28','28') +sql insert into tb4_0 values ('2021-10-20 10:00:36',36,36.0,36,36,36,36.0,false,'36','36') +sql insert into tb4_0 values ('2021-10-20 10:00:45',45,45.0,45,45,45,45.0,false,'45','45') +sql insert into tb4_0 values ('2021-10-20 10:00:55',55,55.0,55,55,55,55.0,false,'55','55') + +print ================== restart server to commit data into disk +system sh/exec.sh -n dnode1 -s stop -x SIGINT +sleep 500 +system sh/exec.sh -n dnode1 -s start +print ================== server restart completed + +sql insert into tb4_0 values ('2021-10-20 10:01:00',0,0.0,0,0,0,0.0,true ,'0','0') +sql insert into tb4_0 values ('2021-10-20 10:01:01',1,1.0,1,1,1,1.0,true ,'1','1') +sql insert into tb4_0 values ('2021-10-20 10:01:03',3,3.0,3,3,3,3.0,false,'3','3') +sql insert into tb4_0 values ('2021-10-20 10:01:06',6,6.0,6,6,6,6.0,false,'6','6') +sql insert into tb4_0 values ('2021-10-20 10:01:10',10,10.0,10,10,10,10.0,true ,'10','10') +sql insert into tb4_0 values ('2021-10-20 10:01:15',15,15.0,15,15,15,15.0,true ,'15','15') +sql insert into tb4_0 values ('2021-10-20 10:01:21',21,21.0,21,21,21,21.0,false,'21','21') +sql insert into tb4_0 values ('2021-10-20 10:01:28',28,28.0,28,28,28,28.0,false,'28','28') +sql insert into tb4_0 values ('2021-10-20 10:01:36',36,36.0,36,36,36,36.0,false,'36','36') +sql insert into tb4_0 values ('2021-10-20 10:01:45',45,45.0,45,45,45,45.0,false,'45','45') +sql insert into tb4_0 values ('2021-10-20 10:01:55',55,55.0,55,55,55,55.0,false,'55','55') + +print ================== restart server to commit data into disk +system sh/exec.sh -n dnode1 -s stop -x SIGINT +sleep 500 +system sh/exec.sh -n dnode1 -s start +print ================== server restart completed + +sql insert into tb4_0 values ('2021-10-20 10:02:00',0,0.0,0,0,0,0.0,true ,'0','0') +sql insert into tb4_0 values ('2021-10-20 10:02:01',1,1.0,1,1,1,1.0,true ,'1','1') +sql insert into tb4_0 values ('2021-10-20 10:02:03',3,3.0,3,3,3,3.0,false,'3','3') +sql insert into tb4_0 values ('2021-10-20 10:02:06',6,6.0,6,6,6,6.0,false,'6','6') +sql insert into tb4_0 values ('2021-10-20 10:02:10',10,10.0,10,10,10,10.0,true ,'10','10') +sql insert into tb4_0 values ('2021-10-20 10:02:15',15,15.0,15,15,15,15.0,true ,'15','15') +sql insert into tb4_0 values ('2021-10-20 10:02:21',21,21.0,21,21,21,21.0,false,'21','21') +sql insert into tb4_0 values ('2021-10-20 10:02:28',28,28.0,28,28,28,28.0,false,'28','28') +sql insert into tb4_0 values ('2021-10-20 10:02:36',36,36.0,36,36,36,36.0,false,'36','36') +sql insert into tb4_0 values ('2021-10-20 10:02:45',45,45.0,45,45,45,45.0,false,'45','45') +sql insert into tb4_0 values ('2021-10-20 10:02:55',55,55.0,55,55,55,55.0,false,'55','55') + + +print ================== restart server to commit data into disk +system sh/exec.sh -n dnode1 -s stop -x SIGINT +sleep 500 +system sh/exec.sh -n dnode1 -s start +print ================== server restart completed + +sql insert into tb4_0 values ('2021-10-20 10:03:00',0,0.0,0,0,0,0.0,true ,'0','0') +sql insert into tb4_0 values ('2021-10-20 10:03:01',1,1.0,1,1,1,1.0,true ,'1','1') +sql insert into tb4_0 values ('2021-10-20 10:03:03',3,3.0,3,3,3,3.0,false,'3','3') +sql insert into tb4_0 values ('2021-10-20 10:03:06',6,6.0,6,6,6,6.0,false,'6','6') +sql insert into tb4_0 values ('2021-10-20 10:03:10',10,10.0,10,10,10,10.0,true ,'10','10') +sql insert into tb4_0 values ('2021-10-20 10:03:15',15,15.0,15,15,15,15.0,true ,'15','15') +sql insert into tb4_0 values ('2021-10-20 10:03:21',21,21.0,21,21,21,21.0,false,'21','21') +sql insert into tb4_0 values ('2021-10-20 10:03:28',28,28.0,28,28,28,28.0,false,'28','28') +sql insert into tb4_0 values ('2021-10-20 10:03:36',36,36.0,36,36,36,36.0,false,'36','36') +sql insert into tb4_0 values ('2021-10-20 10:03:45',45,45.0,45,45,45,45.0,false,'45','45') +sql insert into tb4_0 values ('2021-10-20 10:03:55',55,55.0,55,55,55,55.0,false,'55','55') + + +print ================== restart server to commit data into disk +system sh/exec.sh -n dnode1 -s stop -x SIGINT +sleep 500 +system sh/exec.sh -n dnode1 -s start +print ================== server restart completed + +sql insert into tb4_0 values ('2021-10-20 10:04:00',0,0.0,0,0,0,0.0,true ,'0','0') +sql insert into tb4_0 values ('2021-10-20 10:04:01',1,1.0,1,1,1,1.0,true ,'1','1') +sql insert into tb4_0 values ('2021-10-20 10:04:03',3,3.0,3,3,3,3.0,false,'3','3') +sql insert into tb4_0 values ('2021-10-20 10:04:06',6,6.0,6,6,6,6.0,false,'6','6') +sql insert into tb4_0 values ('2021-10-20 10:04:10',10,10.0,10,10,10,10.0,true ,'10','10') +sql insert into tb4_0 values ('2021-10-20 10:04:15',15,15.0,15,15,15,15.0,true ,'15','15') +sql insert into tb4_0 values ('2021-10-20 10:04:21',21,21.0,21,21,21,21.0,false,'21','21') +sql insert into tb4_0 values ('2021-10-20 10:04:28',28,28.0,28,28,28,28.0,false,'28','28') +sql insert into tb4_0 values ('2021-10-20 10:04:36',36,36.0,36,36,36,36.0,false,'36','36') +sql insert into tb4_0 values ('2021-10-20 10:04:45',45,45.0,45,45,45,45.0,false,'45','45') +sql insert into tb4_0 values ('2021-10-20 10:04:55',55,55.0,55,55,55,55.0,false,'55','55') + + + +run general/parser/interp_full_test1.sim +run general/parser/interp_full_test2.sim +run general/parser/interp_full_test3.sim +run general/parser/interp_full_test4.sim + +print ================== restart server to commit data into disk +system sh/exec.sh -n dnode1 -s stop -x SIGINT +sleep 500 +system sh/exec.sh -n dnode1 -s start +print ================== server restart completed + +run general/parser/interp_full_test1.sim +run general/parser/interp_full_test2.sim +run general/parser/interp_full_test3.sim +run general/parser/interp_full_test4.sim + +system sh/exec.sh -n dnode1 -s stop -x SIGINT diff --git a/tests/script/general/parser/interp_full_test1.sim b/tests/script/general/parser/interp_full_test1.sim new file mode 100644 index 0000000000000000000000000000000000000000..858d58768bd6c0ab78d6debf0e4208d375080ef8 --- /dev/null +++ b/tests/script/general/parser/interp_full_test1.sim @@ -0,0 +1,2247 @@ +sleep 100 +sql connect + +sql use db; + +sql_error SELECT INTERP(c7) FROM tb1; +sql_error SELECT INTERP(c8) FROM tb1; +sql_error SELECT INTERP(c9) FROM tb1; +sql_error SELECT INTERP(c1,c8) FROM tb1; +sql_error SELECT INTERP(*) FROM tb1; +sql_error SELECT INTERP(c1),INTERP(c8) FROM tb1; +sql_error SELECT INTERP(c1),avg(c1) FROM tb1; +sql_error SELECT INTERP(c1),c1 FROM tb1; +sql_error SELECT INTERP(c1),top(c1,3) FROM tb1; +sql_error SELECT INTERP(c1),first(c1) FROM tb1; +sql_error SELECT INTERP(c1),count(c1) FROM tb1; +sql_error SELECT INTERP(c1),ceil(c1) FROM tb1; +sql_error SELECT c1,c2,interp(c1) FROM tb1; +sql_error SELECT INTERP(c1) FROM stb1; +sql_error SELECT interp(c1) FROM stb1 group by t1; +sql_error SELECT interp(c1) FROM stb1 group by tbname,t1; +sql_error SELECT interp(c1) FROM stb1 group by tbname,ts; +sql_error SELECT interp(c1) FROM stb1 group by tbname,c1; +sql_error SELECT INTERP(c1) FROM tb1 interval(1s); +sql_error SELECT avg(c1) FROM tb1 every(1s); +sql_error SELECT avg(c1) FROM tb1 range(0,1); +sql_error SELECT INTERP(c1) FROM tb1 STATE_WINDOW(c1); +sql_error SELECT INTERP(c1) FROM tb1 SESSION(ts,100s); +sql_error SELECT INTERP(c1) FROM tb1 RANGE('2021-10-20 10:00:11','2021-10-20 10:00:10'); +sql_error SELECT INTERP(c1) FROM tb1 RANGE('2021-10-20 10:00:11','2021-10-20 10:00:10') ORDER BY ts DESC; +sql_error SELECT INTERP(ts) FROM tb1; +sql_error select interp(c1) from tb1 EVERY(1s) sliding(1s); +sql_error select interp(c1) from (select ts,c1 from tb1 order by ts desc); +sql_error select interp(a) from (select top(c1,3) as a from stb1 group by tbname); +sql_error select interp(c1) from (select c1 from tb1 order by ts); +sql_error select interp(c1) from (select c1,ts from tb1 order by ts); +sql_error select interp(a) from (select top(c1,3) as a from stb1 order by ts); +sql_error select interp(a) from (select top(c1,3) as a from tb1 order by ts desc); + +sql SELECT INTERP(c1) FROM tb1; +if $rows != 1 then + return -1 +endi +if $data00 != @21-10-20 10:00:00.000@ then + return -1 +endi +if $data01 != 0 then + return -1 +endi + +sql SELECT ts,INTERP(c1) FROM tb1; +if $rows != 1 then + return -1 +endi +if $data00 != @21-10-20 10:00:00.000@ then + return -1 +endi +if $data01 != @21-10-20 10:00:00.000@ then + return -1 +endi +if $data02 != 0 then + return -1 +endi + + + +sql SELECT INTERP(c1) FROM tb1 where ts > '2021-10-20 10:00:03' +if $rows != 1 then + return -1 +endi +if $data00 != @21-10-20 10:00:06.000@ then + return -1 +endi +if $data01 != 6 then + return -1 +endi + +sql SELECT INTERP(c1,c2,c3,c4,c6,c5) FROM tb1 every(1s); +if $rows != 7 then + return -1 +endi +if $data00 != @21-10-20 10:00:00.000@ then + return -1 +endi +if $data01 != 0 then + return -1 +endi +if $data02 != 0.00000 then + return -1 +endi +if $data03 != 0 then + return -1 +endi +if $data04 != 0 then + return -1 +endi +if $data05 != 0.000000000 then + return -1 +endi +if $data06 != 0 then + return -1 +endi +if $data10 != @21-10-20 10:00:01.000@ then + return -1 +endi +if $data11 != 1 then + return -1 +endi +if $data12 != 1.00000 then + return -1 +endi +if $data13 != 1 then + return -1 +endi +if $data14 != 1 then + return -1 +endi +if $data15 != 1.000000000 then + return -1 +endi +if $data16 != 1 then + return -1 +endi +if $data20 != @21-10-20 10:00:03.000@ then + return -1 +endi +if $data21 != 3 then + return -1 +endi +if $data22 != 3.00000 then + return -1 +endi +if $data23 != 3 then + return -1 +endi +if $data24 != 3 then + return -1 +endi +if $data25 != 3.000000000 then + return -1 +endi +if $data26 != 3 then + return -1 +endi +if $data30 != @21-10-20 10:00:06.000@ then + return -1 +endi +if $data31 != 6 then + return -1 +endi +if $data32 != 6.00000 then + return -1 +endi +if $data33 != 6 then + return -1 +endi +if $data34 != 6 then + return -1 +endi +if $data35 != 6.000000000 then + return -1 +endi +if $data36 != 6 then + return -1 +endi +if $data40 != @21-10-20 10:00:10.000@ then + return -1 +endi +if $data41 != 10 then + return -1 +endi +if $data42 != 10.00000 then + return -1 +endi +if $data43 != 10 then + return -1 +endi +if $data44 != 10 then + return -1 +endi +if $data45 != 10.000000000 then + return -1 +endi +if $data46 != 10 then + return -1 +endi +if $data50 != @21-10-20 10:00:15.000@ then + return -1 +endi +if $data51 != 15 then + return -1 +endi +if $data52 != 15.00000 then + return -1 +endi +if $data53 != 15 then + return -1 +endi +if $data54 != 15 then + return -1 +endi +if $data55 != 15.000000000 then + return -1 +endi +if $data56 != 15 then + return -1 +endi +if $data60 != @21-10-20 10:00:21.000@ then + return -1 +endi +if $data61 != 21 then + return -1 +endi +if $data62 != 21.00000 then + return -1 +endi +if $data63 != 21 then + return -1 +endi +if $data64 != 21 then + return -1 +endi +if $data65 != 21.000000000 then + return -1 +endi +if $data66 != 21 then + return -1 +endi + +sql SELECT INTERP(c1),interp(c2),interp(c3) FROM tb1 every(1s); +if $rows != 7 then + return -1 +endi +if $data00 != @21-10-20 10:00:00.000@ then + return -1 +endi +if $data01 != 0 then + return -1 +endi +if $data02 != 0.00000 then + return -1 +endi +if $data03 != 0 then + return -1 +endi +if $data10 != @21-10-20 10:00:01.000@ then + return -1 +endi +if $data11 != 1 then + return -1 +endi +if $data12 != 1.00000 then + return -1 +endi +if $data13 != 1 then + return -1 +endi +if $data20 != @21-10-20 10:00:03.000@ then + return -1 +endi +if $data21 != 3 then + return -1 +endi +if $data22 != 3.00000 then + return -1 +endi +if $data23 != 3 then + return -1 +endi +if $data30 != @21-10-20 10:00:06.000@ then + return -1 +endi +if $data31 != 6 then + return -1 +endi +if $data32 != 6.00000 then + return -1 +endi +if $data33 != 6 then + return -1 +endi +if $data40 != @21-10-20 10:00:10.000@ then + return -1 +endi +if $data41 != 10 then + return -1 +endi +if $data42 != 10.00000 then + return -1 +endi +if $data43 != 10 then + return -1 +endi +if $data50 != @21-10-20 10:00:15.000@ then + return -1 +endi +if $data51 != 15 then + return -1 +endi +if $data52 != 15.00000 then + return -1 +endi +if $data53 != 15 then + return -1 +endi +if $data60 != @21-10-20 10:00:21.000@ then + return -1 +endi +if $data61 != 21 then + return -1 +endi +if $data62 != 21.00000 then + return -1 +endi +if $data63 != 21 then + return -1 +endi + + +sql SELECT INTERP(c1),ts FROM tb1 every(1s); +if $rows != 7 then + return -1 +endi +if $data00 != @21-10-20 10:00:00.000@ then + return -1 +endi +if $data01 != 0 then + return -1 +endi +if $data02 != @21-10-20 10:00:00.000@ then + return -1 +endi +if $data10 != @21-10-20 10:00:01.000@ then + return -1 +endi +if $data11 != 1 then + return -1 +endi +if $data12 != @21-10-20 10:00:01.000@ then + return -1 +endi +if $data20 != @21-10-20 10:00:03.000@ then + return -1 +endi +if $data21 != 3 then + return -1 +endi +if $data22 != @21-10-20 10:00:03.000@ then + return -1 +endi +if $data30 != @21-10-20 10:00:06.000@ then + return -1 +endi +if $data31 != 6 then + return -1 +endi +if $data32 != @21-10-20 10:00:06.000@ then + return -1 +endi +if $data40 != @21-10-20 10:00:10.000@ then + return -1 +endi +if $data41 != 10 then + return -1 +endi +if $data42 != @21-10-20 10:00:10.000@ then + return -1 +endi +if $data50 != @21-10-20 10:00:15.000@ then + return -1 +endi +if $data51 != 15 then + return -1 +endi +if $data52 != @21-10-20 10:00:15.000@ then + return -1 +endi +if $data60 != @21-10-20 10:00:21.000@ then + return -1 +endi +if $data61 != 21 then + return -1 +endi +if $data62 != @21-10-20 10:00:21.000@ then + return -1 +endi + +sql SELECT INTERP(c1) FROM stb1 every(1s) group by tbname; +if $rows != 21 then + return -1 +endi +if $data00 != @21-10-20 10:00:00.000@ then + return -1 +endi +if $data01 != 0 then + return -1 +endi +if $data02 != tb1 then + return -1 +endi +if $data10 != @21-10-20 10:00:01.000@ then + return -1 +endi +if $data11 != 1 then + return -1 +endi +if $data12 != tb1 then + return -1 +endi +if $data20 != @21-10-20 10:00:03.000@ then + return -1 +endi +if $data21 != 3 then + return -1 +endi +if $data22 != tb1 then + return -1 +endi +if $data30 != @21-10-20 10:00:06.000@ then + return -1 +endi +if $data31 != 6 then + return -1 +endi +if $data32 != tb1 then + return -1 +endi +if $data40 != @21-10-20 10:00:10.000@ then + return -1 +endi +if $data41 != 10 then + return -1 +endi +if $data42 != tb1 then + return -1 +endi +if $data50 != @21-10-20 10:00:15.000@ then + return -1 +endi +if $data51 != 15 then + return -1 +endi +if $data52 != tb1 then + return -1 +endi +if $data60 != @21-10-20 10:00:21.000@ then + return -1 +endi +if $data61 != 21 then + return -1 +endi +if $data62 != tb1 then + return -1 +endi +if $data70 != @21-10-20 10:00:00.000@ then + return -1 +endi +if $data71 != 0 then + return -1 +endi +if $data72 != tb2 then + return -1 +endi +if $data80 != @21-10-20 10:00:02.000@ then + return -1 +endi +if $data81 != 2 then + return -1 +endi +if $data82 != tb2 then + return -1 +endi +if $data90 != @21-10-20 10:00:04.000@ then + return -1 +endi +if $data91 != 4 then + return -1 +endi +if $data92 != tb2 then + return -1 +endi + + + +sql SELECT INTERP(c1) FROM stb1 every(1s) group by tbname limit 5; +if $rows != 15 then + return -1 +endi + +sql SELECT INTERP(c1) FROM stb1 every(1s) group by tbname limit 3; +if $rows != 9 then + return -1 +endi +if $data00 != @21-10-20 10:00:00.000@ then + return -1 +endi +if $data01 != 0 then + return -1 +endi +if $data02 != tb1 then + return -1 +endi +if $data10 != @21-10-20 10:00:01.000@ then + return -1 +endi +if $data11 != 1 then + return -1 +endi +if $data12 != tb1 then + return -1 +endi +if $data20 != @21-10-20 10:00:03.000@ then + return -1 +endi +if $data21 != 3 then + return -1 +endi +if $data22 != tb1 then + return -1 +endi +if $data30 != @21-10-20 10:00:00.000@ then + return -1 +endi +if $data31 != 0 then + return -1 +endi +if $data32 != tb2 then + return -1 +endi +if $data40 != @21-10-20 10:00:02.000@ then + return -1 +endi +if $data41 != 2 then + return -1 +endi +if $data42 != tb2 then + return -1 +endi +if $data50 != @21-10-20 10:00:04.000@ then + return -1 +endi +if $data51 != 4 then + return -1 +endi +if $data52 != tb2 then + return -1 +endi +if $data60 != @21-10-20 10:00:00.000@ then + return -1 +endi +if $data61 != 0 then + return -1 +endi +if $data62 != tb3 then + return -1 +endi +if $data70 != @21-10-20 10:00:01.000@ then + return -1 +endi +if $data71 != 1 then + return -1 +endi +if $data72 != tb3 then + return -1 +endi +if $data80 != @21-10-20 10:00:02.000@ then + return -1 +endi +if $data81 != 2 then + return -1 +endi +if $data82 != tb3 then + return -1 +endi + +sql SELECT INTERP(c1) FROM stb1 every(1s) group by tbname limit 3 offset 6; +if $rows != 3 then + return -1 +endi +if $data00 != @21-10-20 10:00:21.000@ then + return -1 +endi +if $data01 != 21 then + return -1 +endi +if $data02 != tb1 then + return -1 +endi +if $data10 != @21-10-20 10:00:14.000@ then + return -1 +endi +if $data11 != 14 then + return -1 +endi +if $data12 != tb2 then + return -1 +endi +if $data20 != @21-10-20 10:00:21.000@ then + return -1 +endi +if $data21 != 21 then + return -1 +endi +if $data22 != tb3 then + return -1 +endi + +sql SELECT INTERP(c1),t1,interp(c2),t2,interp(c3) FROM stb1 every(1s) group by tbname; +if $rows != 21 then + return -1 +endi +if $data00 != @21-10-20 10:00:00.000@ then + return -1 +endi +if $data01 != 0 then + return -1 +endi +if $data02 != 1 then + return -1 +endi +if $data03 != 0.00000 then + return -1 +endi +if $data04 != 1 then + return -1 +endi +if $data05 != 0 then + return -1 +endi +if $data06 != tb1 then + return -1 +endi +if $data10 != @21-10-20 10:00:01.000@ then + return -1 +endi +if $data11 != 1 then + return -1 +endi +if $data12 != 1 then + return -1 +endi +if $data13 != 1.00000 then + return -1 +endi +if $data14 != 1 then + return -1 +endi +if $data15 != 1 then + return -1 +endi +if $data16 != tb1 then + return -1 +endi +if $data20 != @21-10-20 10:00:03.000@ then + return -1 +endi +if $data21 != 3 then + return -1 +endi +if $data22 != 1 then + return -1 +endi +if $data23 != 3.00000 then + return -1 +endi +if $data24 != 1 then + return -1 +endi +if $data25 != 3 then + return -1 +endi +if $data26 != tb1 then + return -1 +endi +if $data30 != @21-10-20 10:00:06.000@ then + return -1 +endi +if $data31 != 6 then + return -1 +endi +if $data32 != 1 then + return -1 +endi +if $data33 != 6.00000 then + return -1 +endi +if $data34 != 1 then + return -1 +endi +if $data35 != 6 then + return -1 +endi +if $data36 != tb1 then + return -1 +endi +if $data40 != @21-10-20 10:00:10.000@ then + return -1 +endi +if $data41 != 10 then + return -1 +endi +if $data42 != 1 then + return -1 +endi +if $data43 != 10.00000 then + return -1 +endi +if $data44 != 1 then + return -1 +endi +if $data45 != 10 then + return -1 +endi +if $data46 != tb1 then + return -1 +endi +if $data50 != @21-10-20 10:00:15.000@ then + return -1 +endi +if $data51 != 15 then + return -1 +endi +if $data52 != 1 then + return -1 +endi +if $data53 != 15.00000 then + return -1 +endi +if $data54 != 1 then + return -1 +endi +if $data55 != 15 then + return -1 +endi +if $data56 != tb1 then + return -1 +endi +if $data60 != @21-10-20 10:00:21.000@ then + return -1 +endi +if $data61 != 21 then + return -1 +endi +if $data62 != 1 then + return -1 +endi +if $data63 != 21.00000 then + return -1 +endi +if $data64 != 1 then + return -1 +endi +if $data65 != 21 then + return -1 +endi +if $data66 != tb1 then + return -1 +endi +if $data70 != @21-10-20 10:00:00.000@ then + return -1 +endi +if $data71 != 0 then + return -1 +endi +if $data72 != 2 then + return -1 +endi +if $data73 != 0.00000 then + return -1 +endi +if $data74 != 2 then + return -1 +endi +if $data75 != 0 then + return -1 +endi +if $data76 != tb2 then + return -1 +endi +if $data80 != @21-10-20 10:00:02.000@ then + return -1 +endi +if $data81 != 2 then + return -1 +endi +if $data82 != 2 then + return -1 +endi +if $data83 != 2.00000 then + return -1 +endi +if $data84 != 2 then + return -1 +endi +if $data85 != 2 then + return -1 +endi +if $data86 != tb2 then + return -1 +endi +if $data90 != @21-10-20 10:00:04.000@ then + return -1 +endi +if $data91 != 4 then + return -1 +endi +if $data92 != 2 then + return -1 +endi +if $data93 != 4.00000 then + return -1 +endi +if $data94 != 2 then + return -1 +endi +if $data95 != 4 then + return -1 +endi +if $data96 != tb2 then + return -1 +endi + +sql SELECT tbname,INTERP(c1),t1,interp(c2),t2,interp(c3) FROM stb1 every(4s) group by tbname; +if $rows != 5 then + return -1 +endi +if $data00 != @21-10-20 10:00:00.000@ then + return -1 +endi +if $data01 != tb1 then + return -1 +endi +if $data02 != 0 then + return -1 +endi +if $data03 != 1 then + return -1 +endi +if $data04 != 0.00000 then + return -1 +endi +if $data05 != 1 then + return -1 +endi +if $data06 != 0 then + return -1 +endi +if $data07 != tb1 then + return -1 +endi +if $data10 != @21-10-20 10:00:00.000@ then + return -1 +endi +if $data11 != tb2 then + return -1 +endi +if $data12 != 0 then + return -1 +endi +if $data13 != 2 then + return -1 +endi +if $data14 != 0.00000 then + return -1 +endi +if $data15 != 2 then + return -1 +endi +if $data16 != 0 then + return -1 +endi +if $data17 != tb2 then + return -1 +endi +if $data20 != @21-10-20 10:00:04.000@ then + return -1 +endi +if $data21 != tb2 then + return -1 +endi +if $data22 != 4 then + return -1 +endi +if $data23 != 2 then + return -1 +endi +if $data24 != 4.00000 then + return -1 +endi +if $data25 != 2 then + return -1 +endi +if $data26 != 4 then + return -1 +endi +if $data27 != tb2 then + return -1 +endi +if $data30 != @21-10-20 10:00:12.000@ then + return -1 +endi +if $data31 != tb2 then + return -1 +endi +if $data32 != 12 then + return -1 +endi +if $data33 != 2 then + return -1 +endi +if $data34 != 12.00000 then + return -1 +endi +if $data35 != 2 then + return -1 +endi +if $data36 != 12 then + return -1 +endi +if $data37 != tb2 then + return -1 +endi +if $data40 != @21-10-20 10:00:00.000@ then + return -1 +endi +if $data41 != tb3 then + return -1 +endi +if $data42 != 0 then + return -1 +endi +if $data43 != 3 then + return -1 +endi +if $data44 != 0.00000 then + return -1 +endi +if $data45 != 3 then + return -1 +endi +if $data46 != 0 then + return -1 +endi +if $data47 != tb3 then + return -1 +endi + + +sql SELECT INTERP(c1) FROM stb1 range('2021-10-20 10:00:00.000','2021-10-20 10:00:40.000') every(1s) fill(linear) group by tbname; +if $rows != 59 then + return -1 +endi +if $data00 != @21-10-20 10:00:00.000@ then + return -1 +endi +if $data01 != 0 then + return -1 +endi +if $data02 != tb1 then + return -1 +endi +if $data10 != @21-10-20 10:00:01.000@ then + return -1 +endi +if $data11 != 1 then + return -1 +endi +if $data12 != tb1 then + return -1 +endi +if $data20 != @21-10-20 10:00:02.000@ then + return -1 +endi +if $data21 != 2 then + return -1 +endi +if $data22 != tb1 then + return -1 +endi +if $data30 != @21-10-20 10:00:03.000@ then + return -1 +endi +if $data31 != 3 then + return -1 +endi +if $data32 != tb1 then + return -1 +endi +if $data40 != @21-10-20 10:00:04.000@ then + return -1 +endi +if $data41 != 4 then + return -1 +endi +if $data42 != tb1 then + return -1 +endi +if $data50 != @21-10-20 10:00:05.000@ then + return -1 +endi +if $data51 != 5 then + return -1 +endi +if $data52 != tb1 then + return -1 +endi +if $data60 != @21-10-20 10:00:06.000@ then + return -1 +endi +if $data61 != 6 then + return -1 +endi +if $data62 != tb1 then + return -1 +endi +if $data70 != @21-10-20 10:00:07.000@ then + return -1 +endi +if $data71 != 7 then + return -1 +endi +if $data72 != tb1 then + return -1 +endi +if $data80 != @21-10-20 10:00:08.000@ then + return -1 +endi +if $data81 != 8 then + return -1 +endi +if $data82 != tb1 then + return -1 +endi +if $data90 != @21-10-20 10:00:09.000@ then + return -1 +endi +if $data91 != 9 then + return -1 +endi +if $data92 != tb1 then + return -1 +endi + +sql SELECT INTERP(c1) FROM tb1 RANGE('2021-10-20 09:00:00','2021-10-20 14:00:00'); +if $rows != 0 then + return -1 +endi + +sql SELECT INTERP(c1) FROM tb1 RANGE('2021-10-20 09:00:00','2021-10-20 09:00:01') +if $rows != 0 then + return -1 +endi + +sql SELECT INTERP(c1) FROM tb1 RANGE('2021-10-20 10:00:00','2021-10-20 14:00:00'); +if $rows != 1 then + return -1 +endi +if $data00 != @21-10-20 10:00:00.000@ then + return -1 +endi +if $data01 != 0 then + return -1 +endi + +sql SELECT INTERP(c1) FROM tb1 RANGE('2021-10-20 10:00:04','2021-10-20 14:00:00') +if $rows != 0 then + return -1 +endi + +sql SELECT INTERP(c1) FROM tb1 RANGE('2021-10-20 11:00:00','2021-10-20 14:00:00'); +if $rows != 0 then + return -1 +endi + +sql SELECT INTERP(c1) FROM tb1 FILL(LINEAR); +if $rows != 1 then + return -1 +endi +if $data00 != @21-10-20 10:00:00.000@ then + return -1 +endi +if $data01 != 0 then + return -1 +endi + +sql SELECT INTERP(c1) FROM tb1 FILL(NEXT); +if $rows != 1 then + return -1 +endi +if $data00 != @21-10-20 10:00:00.000@ then + return -1 +endi +if $data01 != 0 then + return -1 +endi + +sql SELECT INTERP(c1) FROM tb1 FILL(PREV); +if $rows != 1 then + return -1 +endi +if $data00 != @21-10-20 10:00:00.000@ then + return -1 +endi +if $data01 != 0 then + return -1 +endi + +sql SELECT INTERP(c1) FROM tb1 FILL(VALUE, 100); +if $rows != 1 then + return -1 +endi +if $data00 != @21-10-20 10:00:00.000@ then + return -1 +endi +if $data01 != 0 then + return -1 +endi + +sql SELECT INTERP(c1) FROM tb1 FILL(NULL); +if $rows != 1 then + return -1 +endi +if $data00 != @21-10-20 10:00:00.000@ then + return -1 +endi +if $data01 != 0 then + return -1 +endi + +sql SELECT INTERP(c1) FROM tb1 every(1s); +if $rows != 7 then + return -1 +endi +if $data00 != @21-10-20 10:00:00.000@ then + return -1 +endi +if $data01 != 0 then + return -1 +endi +if $data10 != @21-10-20 10:00:01.000@ then + return -1 +endi +if $data11 != 1 then + return -1 +endi +if $data20 != @21-10-20 10:00:03.000@ then + return -1 +endi +if $data21 != 3 then + return -1 +endi +if $data30 != @21-10-20 10:00:06.000@ then + return -1 +endi +if $data31 != 6 then + return -1 +endi +if $data40 != @21-10-20 10:00:10.000@ then + return -1 +endi +if $data41 != 10 then + return -1 +endi +if $data50 != @21-10-20 10:00:15.000@ then + return -1 +endi +if $data51 != 15 then + return -1 +endi +if $data60 != @21-10-20 10:00:21.000@ then + return -1 +endi +if $data61 != 21 then + return -1 +endi + + +sql SELECT INTERP(c1) FROM tb1 every(2s); +if $rows != 3 then + return -1 +endi +if $data00 != @21-10-20 10:00:00.000@ then + return -1 +endi +if $data01 != 0 then + return -1 +endi +if $data10 != @21-10-20 10:00:06.000@ then + return -1 +endi +if $data11 != 6 then + return -1 +endi +if $data20 != @21-10-20 10:00:10.000@ then + return -1 +endi +if $data21 != 10 then + return -1 +endi + +sql SELECT INTERP(c1) FROM tb1 every(5s); +if $rows != 3 then + return -1 +endi +if $data00 != @21-10-20 10:00:00.000@ then + return -1 +endi +if $data01 != 0 then + return -1 +endi +if $data10 != @21-10-20 10:00:10.000@ then + return -1 +endi +if $data11 != 10 then + return -1 +endi +if $data20 != @21-10-20 10:00:15.000@ then + return -1 +endi +if $data21 != 15 then + return -1 +endi + +sql SELECT INTERP(c1) FROM tb1 every(100s); +if $rows != 1 then + return -1 +endi +if $data00 != @21-10-20 10:00:00.000@ then + return -1 +endi +if $data01 != 0 then + return -1 +endi + +sql SELECT INTERP(c1) FROM tb1 RANGE('2021-10-20 09:00:00','2021-10-20 14:00:00') FILL(LINEAR); +if $rows != 0 then + return -1 +endi + +sql SELECT INTERP(c1) FROM tb1 RANGE('2021-10-20 09:00:00','2021-10-20 09:00:01') FILL(LINEAR); +if $rows != 0 then + return -1 +endi + +sql SELECT INTERP(c1) FROM tb1 RANGE('2021-10-20 10:00:00','2021-10-20 10:00:00') FILL(LINEAR); +if $rows != 1 then + return -1 +endi +if $data00 != @21-10-20 10:00:00.000@ then + return -1 +endi +if $data01 != 0 then + return -1 +endi + +sql SELECT INTERP(c1) FROM tb1 RANGE('2021-10-20 10:00:04','2021-10-20 14:00:00') FILL(LINEAR); +if $rows != 1 then + return -1 +endi +if $data00 != @21-10-20 10:00:04.000@ then + return -1 +endi +if $data01 != 4 then + return -1 +endi + +sql SELECT INTERP(c1) FROM tb1 RANGE('2021-10-20 11:00:00','2021-10-20 14:00:00') FILL(LINEAR); +if $rows != 0 then + return -1 +endi + +sql SELECT INTERP(c1) FROM tb1 RANGE('2021-10-20 09:00:00','2021-10-20 14:00:00') FILL(NEXT); +if $rows != 1 then + return -1 +endi +if $data00 != @21-10-20 09:00:00.000@ then + return -1 +endi +if $data01 != 0 then + return -1 +endi + +sql SELECT INTERP(c1) FROM tb1 RANGE('2021-10-20 09:00:00','2021-10-20 09:00:01') FILL(NEXT); +if $rows != 1 then + return -1 +endi +if $data00 != @21-10-20 09:00:00.000@ then + return -1 +endi +if $data01 != 0 then + return -1 +endi + +sql SELECT INTERP(c1) FROM tb1 RANGE('2021-10-20 10:00:00','2021-10-20 12:00:00') FILL(NEXT); +if $rows != 1 then + return -1 +endi +if $data00 != @21-10-20 10:00:00.000@ then + return -1 +endi +if $data01 != 0 then + return -1 +endi + +sql SELECT INTERP(c1) FROM tb1 RANGE('2021-10-20 10:00:04','2021-10-20 14:00:00') FILL(NEXT); +if $rows != 1 then + return -1 +endi +if $data00 != @21-10-20 10:00:04.000@ then + return -1 +endi +if $data01 != 6 then + return -1 +endi + +sql SELECT INTERP(c1) FROM tb1 RANGE('2021-10-20 11:00:00','2021-10-20 14:00:00') FILL(NEXT); +if $rows != 0 then + return -1 +endi + +sql SELECT INTERP(c1) FROM tb1 RANGE('2021-10-20 09:00:00','2021-10-20 14:00:00') FILL(PREV); +if $rows != 0 then + return -1 +endi + +sql SELECT INTERP(c1) FROM tb1 RANGE('2021-10-20 09:00:00','2021-10-20 09:00:01') FILL(PREV); +if $rows != 0 then + return -1 +endi + +sql SELECT INTERP(c1) FROM tb1 RANGE('2021-10-20 10:00:00','2021-10-20 12:00:00') FILL(PREV); +if $rows != 1 then + return -1 +endi +if $data00 != @21-10-20 10:00:00.000@ then + return -1 +endi +if $data01 != 0 then + return -1 +endi + +sql SELECT INTERP(c1) FROM tb1 RANGE('2021-10-20 10:00:04','2021-10-20 14:00:00') FILL(PREV); +if $rows != 1 then + return -1 +endi +if $data00 != @21-10-20 10:00:04.000@ then + return -1 +endi +if $data01 != 3 then + return -1 +endi + +sql SELECT INTERP(c1) FROM tb1 RANGE('2021-10-20 11:00:00','2021-10-20 14:00:00') FILL(PREV); +if $rows != 1 then + return -1 +endi +if $data00 != @21-10-20 11:00:00.000@ then + return -1 +endi +if $data01 != 21 then + return -1 +endi + +sql SELECT INTERP(c2) FROM tb1 RANGE('2021-10-20 09:00:00','2021-10-20 14:00:00') FILL(VALUE,100); +if $rows != 1 then + return -1 +endi +if $data00 != @21-10-20 09:00:00.000@ then + return -1 +endi +if $data01 != 100.00000 then + return -1 +endi + +sql SELECT INTERP(c1) FROM tb1 RANGE('2021-10-20 09:00:00','2021-10-20 09:00:01') FILL(VALUE,100); +if $rows != 1 then + return -1 +endi +if $data00 != @21-10-20 09:00:00.000@ then + return -1 +endi +if $data01 != 100 then + return -1 +endi + +sql SELECT INTERP(c1) FROM tb1 RANGE('2021-10-20 10:00:00','2021-10-20 12:00:00') FILL(VALUE,100); +if $rows != 1 then + return -1 +endi +if $data00 != @21-10-20 10:00:00.000@ then + return -1 +endi +if $data01 != 0 then + return -1 +endi + +sql SELECT INTERP(c1) FROM tb1 RANGE('2021-10-20 10:00:04','2021-10-20 14:00:00') FILL(VALUE,100); +if $rows != 1 then + return -1 +endi +if $data00 != @21-10-20 10:00:04.000@ then + return -1 +endi +if $data01 != 100 then + return -1 +endi + +sql SELECT INTERP(c1) FROM tb1 RANGE('2021-10-20 11:00:00','2021-10-20 14:00:00') FILL(VALUE,100); +if $rows != 1 then + return -1 +endi +if $data00 != @21-10-20 11:00:00.000@ then + return -1 +endi +if $data01 != 100 then + return -1 +endi + +sql SELECT INTERP(c2) FROM tb1 RANGE('2021-10-20 09:00:00','2021-10-20 14:00:00') FILL(NULL); +if $rows != 1 then + return -1 +endi +if $data00 != @21-10-20 09:00:00.000@ then + return -1 +endi +if $data01 != NULL then + return -1 +endi + +sql SELECT INTERP(c2) FROM tb1 RANGE('2021-10-20 09:00:00','2021-10-20 09:00:01') FILL(NULL); +if $rows != 1 then + return -1 +endi +if $data00 != @21-10-20 09:00:00.000@ then + return -1 +endi +if $data01 != NULL then + return -1 +endi + +sql SELECT INTERP(c2) FROM tb1 RANGE('2021-10-20 10:00:00','2021-10-20 12:00:00') FILL(NULL); +if $rows != 1 then + return -1 +endi +if $data00 != @21-10-20 10:00:00.000@ then + return -1 +endi +if $data01 != 0.00000 then + return -1 +endi + +sql SELECT INTERP(c2) FROM tb1 RANGE('2021-10-20 10:00:04','2021-10-20 14:00:00') FILL(NULL); +if $rows != 1 then + return -1 +endi +if $data00 != @21-10-20 10:00:04.000@ then + return -1 +endi +if $data01 != NULL then + return -1 +endi + +sql SELECT INTERP(c2) FROM tb1 RANGE('2021-10-20 11:00:00','2021-10-20 14:00:00') FILL(NULL); +if $rows != 1 then + return -1 +endi +if $data00 != @21-10-20 11:00:00.000@ then + return -1 +endi +if $data01 != NULL then + return -1 +endi + +sql SELECT INTERP(c1) FROM tb1 RANGE('2021-10-20 09:00:00','2021-10-20 14:00:00') EVERY(1s); +if $rows != 7 then + return -1 +endi +if $data00 != @21-10-20 10:00:00.000@ then + return -1 +endi +if $data01 != 0 then + return -1 +endi +if $data10 != @21-10-20 10:00:01.000@ then + return -1 +endi +if $data11 != 1 then + return -1 +endi +if $data20 != @21-10-20 10:00:03.000@ then + return -1 +endi +if $data21 != 3 then + return -1 +endi +if $data30 != @21-10-20 10:00:06.000@ then + return -1 +endi +if $data31 != 6 then + return -1 +endi +if $data40 != @21-10-20 10:00:10.000@ then + return -1 +endi +if $data41 != 10 then + return -1 +endi +if $data50 != @21-10-20 10:00:15.000@ then + return -1 +endi +if $data51 != 15 then + return -1 +endi +if $data60 != @21-10-20 10:00:21.000@ then + return -1 +endi +if $data61 != 21 then + return -1 +endi + +sql SELECT INTERP(c1) FROM tb1 RANGE('2021-10-20 09:00:00','2021-10-20 09:00:01') EVERY(1s); +if $rows != 0 then + return -1 +endi +sql SELECT INTERP(c1) FROM tb1 RANGE('2021-10-20 10:00:00','2021-10-20 10:00:00') EVERY(1s); +if $rows != 1 then + return -1 +endi +if $data00 != @21-10-20 10:00:00.000@ then + return -1 +endi +if $data01 != 0 then + return -1 +endi +sql SELECT INTERP(c1) FROM tb1 RANGE('2021-10-20 10:00:04','2021-10-20 14:00:00') EVERY(1s); +if $rows != 4 then + return -1 +endi +if $data00 != @21-10-20 10:00:06.000@ then + return -1 +endi +if $data01 != 6 then + return -1 +endi +if $data10 != @21-10-20 10:00:10.000@ then + return -1 +endi +if $data11 != 10 then + return -1 +endi +if $data20 != @21-10-20 10:00:15.000@ then + return -1 +endi +if $data21 != 15 then + return -1 +endi +if $data30 != @21-10-20 10:00:21.000@ then + return -1 +endi +if $data31 != 21 then + return -1 +endi + +sql SELECT INTERP(c1) FROM tb1 RANGE('2021-10-20 11:00:00','2021-10-20 14:00:00') EVERY(1s); +if $rows != 0 then + return -1 +endi + +sql SELECT INTERP(c1) FROM tb1 RANGE('2021-10-20 09:00:00','2021-10-20 14:00:00') EVERY(2s); +if $rows != 3 then + return -1 +endi +if $data00 != @21-10-20 10:00:00.000@ then + return -1 +endi +if $data01 != 0 then + return -1 +endi +if $data10 != @21-10-20 10:00:06.000@ then + return -1 +endi +if $data11 != 6 then + return -1 +endi +if $data20 != @21-10-20 10:00:10.000@ then + return -1 +endi +if $data21 != 10 then + return -1 +endi + + +sql SELECT INTERP(c1) FROM tb1 RANGE('2021-10-20 09:00:00','2021-10-20 09:00:01') EVERY(2s); +if $rows != 0 then + return -1 +endi +sql SELECT INTERP(c1) FROM tb1 RANGE('2021-10-20 10:00:00','2021-10-20 10:00:00') EVERY(2s); +if $rows != 1 then + return -1 +endi +if $data00 != @21-10-20 10:00:00.000@ then + return -1 +endi +if $data01 != 0 then + return -1 +endi +sql SELECT INTERP(c1) FROM tb1 RANGE('2021-10-20 10:00:04','2021-10-20 14:00:00') EVERY(2s); +if $rows != 2 then + return -1 +endi +if $data00 != @21-10-20 10:00:06.000@ then + return -1 +endi +if $data01 != 6 then + return -1 +endi +if $data10 != @21-10-20 10:00:10.000@ then + return -1 +endi +if $data11 != 10 then + return -1 +endi + +sql SELECT INTERP(c1) FROM tb1 RANGE('2021-10-20 11:00:00','2021-10-20 14:00:00') EVERY(2s); +if $rows != 0 then + return -1 +endi + +sql SELECT INTERP(c1) FROM tb1 EVERY(1s) FILL(LINEAR); +if $rows != 22 then + return -1 +endi +if $data00 != @21-10-20 10:00:00.000@ then + return -1 +endi +if $data01 != 0 then + return -1 +endi +if $data10 != @21-10-20 10:00:01.000@ then + return -1 +endi +if $data11 != 1 then + return -1 +endi +if $data20 != @21-10-20 10:00:02.000@ then + return -1 +endi +if $data21 != 2 then + return -1 +endi +if $data80 != @21-10-20 10:00:08.000@ then + return -1 +endi +if $data81 != 8 then + return -1 +endi +if $data90 != @21-10-20 10:00:09.000@ then + return -1 +endi +if $data91 != 9 then + return -1 +endi + + +sql SELECT INTERP(c1) FROM tb1 EVERY(1s) FILL(NEXT); +if $rows != 22 then + return -1 +endi +if $data00 != @21-10-20 10:00:00.000@ then + return -1 +endi +if $data01 != 0 then + return -1 +endi +if $data10 != @21-10-20 10:00:01.000@ then + return -1 +endi +if $data11 != 1 then + return -1 +endi +if $data20 != @21-10-20 10:00:02.000@ then + return -1 +endi +if $data21 != 3 then + return -1 +endi +if $data30 != @21-10-20 10:00:03.000@ then + return -1 +endi +if $data31 != 3 then + return -1 +endi +if $data40 != @21-10-20 10:00:04.000@ then + return -1 +endi +if $data41 != 6 then + return -1 +endi +if $data50 != @21-10-20 10:00:05.000@ then + return -1 +endi +if $data51 != 6 then + return -1 +endi +if $data60 != @21-10-20 10:00:06.000@ then + return -1 +endi +if $data61 != 6 then + return -1 +endi +if $data70 != @21-10-20 10:00:07.000@ then + return -1 +endi +if $data71 != 10 then + return -1 +endi +if $data80 != @21-10-20 10:00:08.000@ then + return -1 +endi +if $data81 != 10 then + return -1 +endi +if $data90 != @21-10-20 10:00:09.000@ then + return -1 +endi +if $data91 != 10 then + return -1 +endi + +sql SELECT INTERP(c1) FROM tb1 EVERY(1s) FILL(NEXT) limit 10 offset 10; +if $rows != 10 then + return -1 +endi +if $data00 != @21-10-20 10:00:10.000@ then + return -1 +endi +if $data01 != 10 then + return -1 +endi +if $data10 != @21-10-20 10:00:11.000@ then + return -1 +endi +if $data11 != 15 then + return -1 +endi +if $data20 != @21-10-20 10:00:12.000@ then + return -1 +endi +if $data21 != 15 then + return -1 +endi +if $data30 != @21-10-20 10:00:13.000@ then + return -1 +endi +if $data31 != 15 then + return -1 +endi +if $data40 != @21-10-20 10:00:14.000@ then + return -1 +endi +if $data41 != 15 then + return -1 +endi +if $data50 != @21-10-20 10:00:15.000@ then + return -1 +endi +if $data51 != 15 then + return -1 +endi +if $data60 != @21-10-20 10:00:16.000@ then + return -1 +endi +if $data61 != 21 then + return -1 +endi +if $data70 != @21-10-20 10:00:17.000@ then + return -1 +endi +if $data71 != 21 then + return -1 +endi +if $data80 != @21-10-20 10:00:18.000@ then + return -1 +endi +if $data81 != 21 then + return -1 +endi +if $data90 != @21-10-20 10:00:19.000@ then + return -1 +endi +if $data91 != 21 then + return -1 +endi + +sql SELECT INTERP(c1) FROM tb1 EVERY(1s) FILL(PREV); +if $rows != 22 then + return -1 +endi +if $data00 != @21-10-20 10:00:00.000@ then + return -1 +endi +if $data01 != 0 then + return -1 +endi +if $data10 != @21-10-20 10:00:01.000@ then + return -1 +endi +if $data11 != 1 then + return -1 +endi +if $data20 != @21-10-20 10:00:02.000@ then + return -1 +endi +if $data21 != 1 then + return -1 +endi +if $data30 != @21-10-20 10:00:03.000@ then + return -1 +endi +if $data31 != 3 then + return -1 +endi +if $data40 != @21-10-20 10:00:04.000@ then + return -1 +endi +if $data41 != 3 then + return -1 +endi +if $data50 != @21-10-20 10:00:05.000@ then + return -1 +endi +if $data51 != 3 then + return -1 +endi +if $data60 != @21-10-20 10:00:06.000@ then + return -1 +endi +if $data61 != 6 then + return -1 +endi +if $data70 != @21-10-20 10:00:07.000@ then + return -1 +endi +if $data71 != 6 then + return -1 +endi +if $data80 != @21-10-20 10:00:08.000@ then + return -1 +endi +if $data81 != 6 then + return -1 +endi +if $data90 != @21-10-20 10:00:09.000@ then + return -1 +endi +if $data91 != 6 then + return -1 +endi + +sql SELECT INTERP(c1) FROM tb1 EVERY(1s) FILL(PREV) limit 10 offset 10; +if $rows != 10 then + return -1 +endi +if $data00 != @21-10-20 10:00:10.000@ then + return -1 +endi +if $data01 != 10 then + return -1 +endi +if $data10 != @21-10-20 10:00:11.000@ then + return -1 +endi +if $data11 != 10 then + return -1 +endi +if $data20 != @21-10-20 10:00:12.000@ then + return -1 +endi +if $data21 != 10 then + return -1 +endi +if $data30 != @21-10-20 10:00:13.000@ then + return -1 +endi +if $data31 != 10 then + return -1 +endi +if $data40 != @21-10-20 10:00:14.000@ then + return -1 +endi +if $data41 != 10 then + return -1 +endi +if $data50 != @21-10-20 10:00:15.000@ then + return -1 +endi +if $data51 != 15 then + return -1 +endi +if $data60 != @21-10-20 10:00:16.000@ then + return -1 +endi +if $data61 != 15 then + return -1 +endi +if $data70 != @21-10-20 10:00:17.000@ then + return -1 +endi +if $data71 != 15 then + return -1 +endi +if $data80 != @21-10-20 10:00:18.000@ then + return -1 +endi +if $data81 != 15 then + return -1 +endi +if $data90 != @21-10-20 10:00:19.000@ then + return -1 +endi +if $data91 != 15 then + return -1 +endi + + +sql SELECT INTERP(c1) FROM tb1 EVERY(1s) FILL(PREV) limit 10 offset 20; +if $rows != 2 then + return -1 +endi +if $data00 != @21-10-20 10:00:20.000@ then + return -1 +endi +if $data01 != 15 then + return -1 +endi +if $data10 != @21-10-20 10:00:21.000@ then + return -1 +endi +if $data11 != 21 then + return -1 +endi + +sql SELECT INTERP(c1) FROM tb1 EVERY(1s) FILL(VALUE,100); +if $rows != 22 then + return -1 +endi +if $data00 != @21-10-20 10:00:00.000@ then + return -1 +endi +if $data01 != 0 then + return -1 +endi +if $data10 != @21-10-20 10:00:01.000@ then + return -1 +endi +if $data11 != 1 then + return -1 +endi +if $data20 != @21-10-20 10:00:02.000@ then + return -1 +endi +if $data21 != 100 then + return -1 +endi +if $data30 != @21-10-20 10:00:03.000@ then + return -1 +endi +if $data31 != 3 then + return -1 +endi +if $data40 != @21-10-20 10:00:04.000@ then + return -1 +endi +if $data41 != 100 then + return -1 +endi +if $data50 != @21-10-20 10:00:05.000@ then + return -1 +endi +if $data51 != 100 then + return -1 +endi +if $data60 != @21-10-20 10:00:06.000@ then + return -1 +endi +if $data61 != 6 then + return -1 +endi +if $data70 != @21-10-20 10:00:07.000@ then + return -1 +endi +if $data71 != 100 then + return -1 +endi +if $data80 != @21-10-20 10:00:08.000@ then + return -1 +endi +if $data81 != 100 then + return -1 +endi +if $data90 != @21-10-20 10:00:09.000@ then + return -1 +endi +if $data91 != 100 then + return -1 +endi + +sql SELECT INTERP(c1) FROM tb1 EVERY(1s) FILL(NULL); +if $rows != 22 then + return -1 +endi +if $data00 != @21-10-20 10:00:00.000@ then + return -1 +endi +if $data01 != 0 then + return -1 +endi +if $data10 != @21-10-20 10:00:01.000@ then + return -1 +endi +if $data11 != 1 then + return -1 +endi +if $data20 != @21-10-20 10:00:02.000@ then + return -1 +endi +if $data21 != NULL then + return -1 +endi +if $data30 != @21-10-20 10:00:03.000@ then + return -1 +endi +if $data31 != 3 then + return -1 +endi +if $data40 != @21-10-20 10:00:04.000@ then + return -1 +endi +if $data41 != NULL then + return -1 +endi +if $data50 != @21-10-20 10:00:05.000@ then + return -1 +endi +if $data51 != NULL then + return -1 +endi +if $data60 != @21-10-20 10:00:06.000@ then + return -1 +endi +if $data61 != 6 then + return -1 +endi +if $data70 != @21-10-20 10:00:07.000@ then + return -1 +endi +if $data71 != NULL then + return -1 +endi +if $data80 != @21-10-20 10:00:08.000@ then + return -1 +endi +if $data81 != NULL then + return -1 +endi +if $data90 != @21-10-20 10:00:09.000@ then + return -1 +endi +if $data91 != NULL then + return -1 +endi + +sql SELECT INTERP(c1) FROM tb1 EVERY(5s) FILL(LINEAR); +if $rows != 5 then + return -1 +endi +if $data00 != @21-10-20 10:00:00.000@ then + return -1 +endi +if $data01 != 0 then + return -1 +endi +if $data10 != @21-10-20 10:00:05.000@ then + return -1 +endi +if $data11 != 5 then + return -1 +endi +if $data20 != @21-10-20 10:00:10.000@ then + return -1 +endi +if $data21 != 10 then + return -1 +endi +if $data30 != @21-10-20 10:00:15.000@ then + return -1 +endi +if $data31 != 15 then + return -1 +endi +if $data40 != @21-10-20 10:00:20.000@ then + return -1 +endi +if $data41 != 20 then + return -1 +endi + + +sql SELECT INTERP(c1) FROM tb1 EVERY(5s) FILL(NEXT); +if $rows != 5 then + return -1 +endi +if $data00 != @21-10-20 10:00:00.000@ then + return -1 +endi +if $data01 != 0 then + return -1 +endi +if $data10 != @21-10-20 10:00:05.000@ then + return -1 +endi +if $data11 != 6 then + return -1 +endi +if $data20 != @21-10-20 10:00:10.000@ then + return -1 +endi +if $data21 != 10 then + return -1 +endi +if $data30 != @21-10-20 10:00:15.000@ then + return -1 +endi +if $data31 != 15 then + return -1 +endi +if $data40 != @21-10-20 10:00:20.000@ then + return -1 +endi +if $data41 != 21 then + return -1 +endi + +sql SELECT INTERP(c1) FROM tb1 EVERY(5s) FILL(PREV); +if $rows != 5 then + return -1 +endi +if $data00 != @21-10-20 10:00:00.000@ then + return -1 +endi +if $data01 != 0 then + return -1 +endi +if $data10 != @21-10-20 10:00:05.000@ then + return -1 +endi +if $data11 != 3 then + return -1 +endi +if $data20 != @21-10-20 10:00:10.000@ then + return -1 +endi +if $data21 != 10 then + return -1 +endi +if $data30 != @21-10-20 10:00:15.000@ then + return -1 +endi +if $data31 != 15 then + return -1 +endi +if $data40 != @21-10-20 10:00:20.000@ then + return -1 +endi +if $data41 != 15 then + return -1 +endi + +sql SELECT INTERP(c1) FROM tb1 EVERY(5s) FILL(VALUE,100); +if $rows != 5 then + return -1 +endi +if $data00 != @21-10-20 10:00:00.000@ then + return -1 +endi +if $data01 != 0 then + return -1 +endi +if $data10 != @21-10-20 10:00:05.000@ then + return -1 +endi +if $data11 != 100 then + return -1 +endi +if $data20 != @21-10-20 10:00:10.000@ then + return -1 +endi +if $data21 != 10 then + return -1 +endi +if $data30 != @21-10-20 10:00:15.000@ then + return -1 +endi +if $data31 != 15 then + return -1 +endi +if $data40 != @21-10-20 10:00:20.000@ then + return -1 +endi +if $data41 != 100 then + return -1 +endi + +sql SELECT INTERP(c1) FROM tb1 EVERY(5s) FILL(NULL); +if $rows != 5 then + return -1 +endi +if $data00 != @21-10-20 10:00:00.000@ then + return -1 +endi +if $data01 != 0 then + return -1 +endi +if $data10 != @21-10-20 10:00:05.000@ then + return -1 +endi +if $data11 != NULL then + return -1 +endi +if $data20 != @21-10-20 10:00:10.000@ then + return -1 +endi +if $data21 != 10 then + return -1 +endi +if $data30 != @21-10-20 10:00:15.000@ then + return -1 +endi +if $data31 != 15 then + return -1 +endi +if $data40 != @21-10-20 10:00:20.000@ then + return -1 +endi +if $data41 != NULL then + return -1 +endi diff --git a/tests/script/general/parser/interp_full_test2.sim b/tests/script/general/parser/interp_full_test2.sim new file mode 100644 index 0000000000000000000000000000000000000000..e044ef572bbb97d7d71ec96821e8f0e65b21389e --- /dev/null +++ b/tests/script/general/parser/interp_full_test2.sim @@ -0,0 +1,2360 @@ +sleep 100 +sql connect + +sql use db; + +sql SELECT INTERP(c1) FROM tb1 RANGE('2021-10-20 09:00:00','2021-10-20 14:00:00') EVERY(1s) FILL(LINEAR); +if $rows != 22 then + return -1 +endi +if $data00 != @21-10-20 10:00:00.000@ then + return -1 +endi +if $data01 != 0 then + return -1 +endi +if $data10 != @21-10-20 10:00:01.000@ then + return -1 +endi +if $data11 != 1 then + return -1 +endi +if $data20 != @21-10-20 10:00:02.000@ then + return -1 +endi +if $data21 != 2 then + return -1 +endi +if $data30 != @21-10-20 10:00:03.000@ then + return -1 +endi +if $data31 != 3 then + return -1 +endi +if $data40 != @21-10-20 10:00:04.000@ then + return -1 +endi +if $data41 != 4 then + return -1 +endi +if $data50 != @21-10-20 10:00:05.000@ then + return -1 +endi +if $data51 != 5 then + return -1 +endi +if $data60 != @21-10-20 10:00:06.000@ then + return -1 +endi +if $data61 != 6 then + return -1 +endi +if $data70 != @21-10-20 10:00:07.000@ then + return -1 +endi +if $data71 != 7 then + return -1 +endi +if $data80 != @21-10-20 10:00:08.000@ then + return -1 +endi +if $data81 != 8 then + return -1 +endi +if $data90 != @21-10-20 10:00:09.000@ then + return -1 +endi +if $data91 != 9 then + return -1 +endi + +sql SELECT INTERP(c1) FROM tb1 RANGE('2021-10-20 09:00:00','2021-10-20 09:00:01') EVERY(1s) FILL(LINEAR); +if $rows != 0 then + return -1 +endi + +sql SELECT INTERP(c1) FROM tb1 RANGE('2021-10-20 10:00:00','2021-10-20 10:00:00') EVERY(1s) FILL(LINEAR); +if $rows != 1 then + return -1 +endi +if $data00 != @21-10-20 10:00:00.000@ then + return -1 +endi +if $data01 != 0 then + return -1 +endi + +sql SELECT INTERP(c1) FROM tb1 RANGE('2021-10-20 10:00:04','2021-10-20 14:00:00') EVERY(1s) FILL(LINEAR); +if $rows != 18 then + return -1 +endi +if $data00 != @21-10-20 10:00:04.000@ then + return -1 +endi +if $data01 != 4 then + return -1 +endi +if $data10 != @21-10-20 10:00:05.000@ then + return -1 +endi +if $data11 != 5 then + return -1 +endi +if $data20 != @21-10-20 10:00:06.000@ then + return -1 +endi +if $data21 != 6 then + return -1 +endi +if $data30 != @21-10-20 10:00:07.000@ then + return -1 +endi +if $data31 != 7 then + return -1 +endi +if $data40 != @21-10-20 10:00:08.000@ then + return -1 +endi +if $data41 != 8 then + return -1 +endi +if $data50 != @21-10-20 10:00:09.000@ then + return -1 +endi +if $data51 != 9 then + return -1 +endi +if $data60 != @21-10-20 10:00:10.000@ then + return -1 +endi +if $data61 != 10 then + return -1 +endi +if $data70 != @21-10-20 10:00:11.000@ then + return -1 +endi +if $data71 != 11 then + return -1 +endi +if $data80 != @21-10-20 10:00:12.000@ then + return -1 +endi +if $data81 != 12 then + return -1 +endi +if $data90 != @21-10-20 10:00:13.000@ then + return -1 +endi +if $data91 != 13 then + return -1 +endi + +sql SELECT INTERP(c1) FROM tb1 RANGE('2021-10-20 11:00:00','2021-10-20 14:00:00') EVERY(1s) FILL(LINEAR); +if $rows != 0 then + return -1 +endi + +sql SELECT INTERP(c1) FROM tb1 RANGE('2021-10-20 09:00:00','2021-10-20 14:00:00') EVERY(1s) FILL(NEXT); +if $rows != 3622 then + return -1 +endi +if $data00 != @21-10-20 09:00:00.000@ then + return -1 +endi +if $data01 != 0 then + return -1 +endi + +sql SELECT INTERP(c1) FROM tb1 RANGE('2021-10-20 09:00:00','2021-10-20 14:00:00') EVERY(1s) FILL(NEXT) limit 10 offset 3612; +if $rows != 10 then + return -1 +endi +if $data00 != @21-10-20 10:00:12.000@ then + return -1 +endi +if $data01 != 15 then + return -1 +endi +if $data10 != @21-10-20 10:00:13.000@ then + return -1 +endi +if $data11 != 15 then + return -1 +endi +if $data20 != @21-10-20 10:00:14.000@ then + return -1 +endi +if $data21 != 15 then + return -1 +endi +if $data30 != @21-10-20 10:00:15.000@ then + return -1 +endi +if $data31 != 15 then + return -1 +endi +if $data40 != @21-10-20 10:00:16.000@ then + return -1 +endi +if $data41 != 21 then + return -1 +endi +if $data50 != @21-10-20 10:00:17.000@ then + return -1 +endi +if $data51 != 21 then + return -1 +endi +if $data60 != @21-10-20 10:00:18.000@ then + return -1 +endi +if $data61 != 21 then + return -1 +endi +if $data70 != @21-10-20 10:00:19.000@ then + return -1 +endi +if $data71 != 21 then + return -1 +endi +if $data80 != @21-10-20 10:00:20.000@ then + return -1 +endi +if $data81 != 21 then + return -1 +endi +if $data90 != @21-10-20 10:00:21.000@ then + return -1 +endi +if $data91 != 21 then + return -1 +endi + +sql SELECT INTERP(c1) FROM tb1 RANGE('2021-10-20 09:00:00','2021-10-20 09:00:01') EVERY(1s) FILL(NEXT); +if $rows != 2 then + return -1 +endi +if $data00 != @21-10-20 09:00:00.000@ then + return -1 +endi +if $data01 != 0 then + return -1 +endi +if $data10 != @21-10-20 09:00:01.000@ then + return -1 +endi +if $data11 != 0 then + return -1 +endi + +sql SELECT INTERP(c1) FROM tb1 RANGE('2021-10-20 10:00:00','2021-10-20 10:00:00') EVERY(1s) FILL(NEXT); +if $rows != 1 then + return -1 +endi +if $data00 != @21-10-20 10:00:00.000@ then + return -1 +endi +if $data01 != 0 then + return -1 +endi + +sql SELECT INTERP(c1) FROM tb1 RANGE('2021-10-20 10:00:04','2021-10-20 14:00:00') EVERY(1s) FILL(NEXT); +if $rows != 18 then + return -1 +endi +if $data00 != @21-10-20 10:00:04.000@ then + return -1 +endi +if $data01 != 6 then + return -1 +endi +if $data10 != @21-10-20 10:00:05.000@ then + return -1 +endi +if $data11 != 6 then + return -1 +endi +if $data20 != @21-10-20 10:00:06.000@ then + return -1 +endi +if $data21 != 6 then + return -1 +endi +if $data30 != @21-10-20 10:00:07.000@ then + return -1 +endi +if $data31 != 10 then + return -1 +endi +if $data40 != @21-10-20 10:00:08.000@ then + return -1 +endi +if $data41 != 10 then + return -1 +endi +if $data50 != @21-10-20 10:00:09.000@ then + return -1 +endi +if $data51 != 10 then + return -1 +endi +if $data60 != @21-10-20 10:00:10.000@ then + return -1 +endi +if $data61 != 10 then + return -1 +endi +if $data70 != @21-10-20 10:00:11.000@ then + return -1 +endi +if $data71 != 15 then + return -1 +endi +if $data80 != @21-10-20 10:00:12.000@ then + return -1 +endi +if $data81 != 15 then + return -1 +endi +if $data90 != @21-10-20 10:00:13.000@ then + return -1 +endi +if $data91 != 15 then + return -1 +endi + +sql SELECT INTERP(c1) FROM tb1 RANGE('2021-10-20 11:00:00','2021-10-20 14:00:00') EVERY(1s) FILL(NEXT); +if $rows != 0 then + return -1 +endi + +sql SELECT INTERP(c1) FROM tb1 RANGE('2021-10-20 09:00:00','2021-10-20 14:00:00') EVERY(1s) FILL(PREV); +if $rows != 14401 then + return -1 +endi +if $data00 != @21-10-20 10:00:00.000@ then + return -1 +endi +if $data01 != 0 then + return -1 +endi +if $data10 != @21-10-20 10:00:01.000@ then + return -1 +endi +if $data11 != 1 then + return -1 +endi +if $data20 != @21-10-20 10:00:02.000@ then + return -1 +endi +if $data21 != 1 then + return -1 +endi +if $data30 != @21-10-20 10:00:03.000@ then + return -1 +endi +if $data31 != 3 then + return -1 +endi +if $data40 != @21-10-20 10:00:04.000@ then + return -1 +endi +if $data41 != 3 then + return -1 +endi +if $data50 != @21-10-20 10:00:05.000@ then + return -1 +endi +if $data51 != 3 then + return -1 +endi +if $data60 != @21-10-20 10:00:06.000@ then + return -1 +endi +if $data61 != 6 then + return -1 +endi +if $data70 != @21-10-20 10:00:07.000@ then + return -1 +endi +if $data71 != 6 then + return -1 +endi +if $data80 != @21-10-20 10:00:08.000@ then + return -1 +endi +if $data81 != 6 then + return -1 +endi +if $data90 != @21-10-20 10:00:09.000@ then + return -1 +endi +if $data91 != 6 then + return -1 +endi + +sql SELECT INTERP(c1) FROM tb1 RANGE('2021-10-20 09:00:00','2021-10-20 14:00:00') EVERY(1s) FILL(PREV) limit 1 offset 14400; +if $rows != 1 then + return -1 +endi +if $data00 != @21-10-20 14:00:00.000@ then + return -1 +endi +if $data01 != 21 then + return -1 +endi + +sql SELECT INTERP(c1) FROM tb1 RANGE('2021-10-20 09:00:00','2021-10-20 09:00:01') EVERY(1s) FILL(PREV); +if $rows != 0 then + return -1 +endi + +sql SELECT INTERP(c1) FROM tb1 RANGE('2021-10-20 10:00:00','2021-10-20 10:00:00') EVERY(1s) FILL(PREV); +if $rows != 1 then + return -1 +endi +if $data00 != @21-10-20 10:00:00.000@ then + return -1 +endi +if $data01 != 0 then + return -1 +endi + +sql SELECT INTERP(c1) FROM tb1 RANGE('2021-10-20 10:00:04','2021-10-20 14:00:00') EVERY(1s) FILL(PREV); +if $rows != 14397 then + return -1 +endi +if $data00 != @21-10-20 10:00:04.000@ then + return -1 +endi +if $data01 != 3 then + return -1 +endi +if $data10 != @21-10-20 10:00:05.000@ then + return -1 +endi +if $data11 != 3 then + return -1 +endi +if $data20 != @21-10-20 10:00:06.000@ then + return -1 +endi +if $data21 != 6 then + return -1 +endi +if $data30 != @21-10-20 10:00:07.000@ then + return -1 +endi +if $data31 != 6 then + return -1 +endi +if $data40 != @21-10-20 10:00:08.000@ then + return -1 +endi +if $data41 != 6 then + return -1 +endi +if $data50 != @21-10-20 10:00:09.000@ then + return -1 +endi +if $data51 != 6 then + return -1 +endi +if $data60 != @21-10-20 10:00:10.000@ then + return -1 +endi +if $data61 != 10 then + return -1 +endi +if $data70 != @21-10-20 10:00:11.000@ then + return -1 +endi +if $data71 != 10 then + return -1 +endi +if $data80 != @21-10-20 10:00:12.000@ then + return -1 +endi +if $data81 != 10 then + return -1 +endi +if $data90 != @21-10-20 10:00:13.000@ then + return -1 +endi +if $data91 != 10 then + return -1 +endi + +sql SELECT INTERP(c1) FROM tb1 RANGE('2021-10-20 10:00:04','2021-10-20 14:00:00') EVERY(1s) FILL(PREV) limit 5 offset 14396; +if $rows != 1 then + return -1 +endi +if $data00 != @21-10-20 14:00:00.000@ then + return -1 +endi +if $data01 != 21 then + return -1 +endi + +sql SELECT INTERP(c1) FROM tb1 RANGE('2021-10-20 11:00:00','2021-10-20 14:00:00') EVERY(1s) FILL(PREV); +if $rows != 10801 then + return -1 +endi +if $data00 != @21-10-20 11:00:00.000@ then + return -1 +endi +if $data01 != 21 then + return -1 +endi +if $data10 != @21-10-20 11:00:01.000@ then + return -1 +endi +if $data11 != 21 then + return -1 +endi + +sql SELECT INTERP(c1) FROM tb1 RANGE('2021-10-20 09:00:00','2021-10-20 14:00:00') EVERY(1s) FILL(VALUE,100); +if $rows != 18001 then + return -1 +endi +if $data00 != @21-10-20 09:00:00.000@ then + return -1 +endi +if $data01 != 100 then + return -1 +endi +if $data10 != @21-10-20 09:00:01.000@ then + return -1 +endi +if $data11 != 100 then + return -1 +endi + +sql SELECT INTERP(c1) FROM tb1 RANGE('2021-10-20 09:00:00','2021-10-20 14:00:00') EVERY(1s) FILL(VALUE,100) limit 20 offset 3600; +if $rows != 20 then + return -1 +endi +if $data00 != @21-10-20 10:00:00.000@ then + return -1 +endi +if $data01 != 0 then + return -1 +endi +if $data10 != @21-10-20 10:00:01.000@ then + return -1 +endi +if $data11 != 1 then + return -1 +endi +if $data20 != @21-10-20 10:00:02.000@ then + return -1 +endi +if $data21 != 100 then + return -1 +endi +if $data30 != @21-10-20 10:00:03.000@ then + return -1 +endi +if $data31 != 3 then + return -1 +endi +if $data40 != @21-10-20 10:00:04.000@ then + return -1 +endi +if $data41 != 100 then + return -1 +endi +if $data50 != @21-10-20 10:00:05.000@ then + return -1 +endi +if $data51 != 100 then + return -1 +endi +if $data60 != @21-10-20 10:00:06.000@ then + return -1 +endi +if $data61 != 6 then + return -1 +endi +if $data70 != @21-10-20 10:00:07.000@ then + return -1 +endi +if $data71 != 100 then + return -1 +endi +if $data80 != @21-10-20 10:00:08.000@ then + return -1 +endi +if $data81 != 100 then + return -1 +endi +if $data90 != @21-10-20 10:00:09.000@ then + return -1 +endi +if $data91 != 100 then + return -1 +endi + +sql SELECT INTERP(c1) FROM tb1 RANGE('2021-10-20 09:00:00','2021-10-20 09:00:01') EVERY(1s) FILL(VALUE,100); +if $rows != 2 then + return -1 +endi +if $data00 != @21-10-20 09:00:00.000@ then + return -1 +endi +if $data01 != 100 then + return -1 +endi +if $data10 != @21-10-20 09:00:01.000@ then + return -1 +endi +if $data11 != 100 then + return -1 +endi + +sql SELECT INTERP(c1) FROM tb1 RANGE('2021-10-20 10:00:00','2021-10-20 10:00:00') EVERY(1s) FILL(VALUE,100); +if $rows != 1 then + return -1 +endi +if $data00 != @21-10-20 10:00:00.000@ then + return -1 +endi +if $data01 != 0 then + return -1 +endi + +sql SELECT INTERP(c1) FROM tb1 RANGE('2021-10-20 10:00:04','2021-10-20 14:00:00') EVERY(1s) FILL(VALUE,100); +if $rows != 14397 then + return -1 +endi +if $data00 != @21-10-20 10:00:04.000@ then + return -1 +endi +if $data01 != 100 then + return -1 +endi +if $data10 != @21-10-20 10:00:05.000@ then + return -1 +endi +if $data11 != 100 then + return -1 +endi +if $data20 != @21-10-20 10:00:06.000@ then + return -1 +endi +if $data21 != 6 then + return -1 +endi +if $data30 != @21-10-20 10:00:07.000@ then + return -1 +endi +if $data31 != 100 then + return -1 +endi +if $data40 != @21-10-20 10:00:08.000@ then + return -1 +endi +if $data41 != 100 then + return -1 +endi +if $data50 != @21-10-20 10:00:09.000@ then + return -1 +endi +if $data51 != 100 then + return -1 +endi +if $data60 != @21-10-20 10:00:10.000@ then + return -1 +endi +if $data61 != 10 then + return -1 +endi +if $data70 != @21-10-20 10:00:11.000@ then + return -1 +endi +if $data71 != 100 then + return -1 +endi +if $data80 != @21-10-20 10:00:12.000@ then + return -1 +endi +if $data81 != 100 then + return -1 +endi +if $data90 != @21-10-20 10:00:13.000@ then + return -1 +endi +if $data91 != 100 then + return -1 +endi + +sql SELECT INTERP(c1) FROM tb1 RANGE('2021-10-20 11:00:00','2021-10-20 14:00:00') EVERY(1s) FILL(VALUE,100); +if $rows != 10801 then + return -1 +endi +if $data00 != @21-10-20 11:00:00.000@ then + return -1 +endi +if $data01 != 100 then + return -1 +endi +if $data10 != @21-10-20 11:00:01.000@ then + return -1 +endi +if $data11 != 100 then + return -1 +endi +if $data90 != @21-10-20 11:00:09.000@ then + return -1 +endi +if $data91 != 100 then + return -1 +endi + +sql SELECT INTERP(c1) FROM tb1 RANGE('2021-10-20 09:00:00','2021-10-20 14:00:00') EVERY(1s) FILL(NULL); +if $rows != 18001 then + return -1 +endi +if $data00 != @21-10-20 09:00:00.000@ then + return -1 +endi +if $data01 != NULL then + return -1 +endi +if $data10 != @21-10-20 09:00:01.000@ then + return -1 +endi +if $data11 != NULL then + return -1 +endi + +sql SELECT INTERP(c1) FROM tb1 RANGE('2021-10-20 09:00:00','2021-10-20 14:00:00') EVERY(1s) FILL(NULL) limit 20 offset 3600; +if $rows != 20 then + return -1 +endi +if $data00 != @21-10-20 10:00:00.000@ then + return -1 +endi +if $data01 != 0 then + return -1 +endi +if $data10 != @21-10-20 10:00:01.000@ then + return -1 +endi +if $data11 != 1 then + return -1 +endi +if $data20 != @21-10-20 10:00:02.000@ then + return -1 +endi +if $data21 != NULL then + return -1 +endi +if $data30 != @21-10-20 10:00:03.000@ then + return -1 +endi +if $data31 != 3 then + return -1 +endi +if $data40 != @21-10-20 10:00:04.000@ then + return -1 +endi +if $data41 != NULL then + return -1 +endi +if $data50 != @21-10-20 10:00:05.000@ then + return -1 +endi +if $data51 != NULL then + return -1 +endi +if $data60 != @21-10-20 10:00:06.000@ then + return -1 +endi +if $data61 != 6 then + return -1 +endi +if $data70 != @21-10-20 10:00:07.000@ then + return -1 +endi +if $data71 != NULL then + return -1 +endi +if $data80 != @21-10-20 10:00:08.000@ then + return -1 +endi +if $data81 != NULL then + return -1 +endi +if $data90 != @21-10-20 10:00:09.000@ then + return -1 +endi +if $data91 != NULL then + return -1 +endi + +sql SELECT INTERP(c1) FROM tb1 RANGE('2021-10-20 09:00:00','2021-10-20 09:00:01') EVERY(1s) FILL(NULL); +if $rows != 2 then + return -1 +endi +if $data00 != @21-10-20 09:00:00.000@ then + return -1 +endi +if $data01 != NULL then + return -1 +endi +if $data10 != @21-10-20 09:00:01.000@ then + return -1 +endi +if $data11 != NULL then + return -1 +endi + +sql SELECT INTERP(c1) FROM tb1 RANGE('2021-10-20 10:00:00','2021-10-20 10:00:00') EVERY(1s) FILL(NULL); +if $rows != 1 then + return -1 +endi +if $data00 != @21-10-20 10:00:00.000@ then + return -1 +endi +if $data01 != 0 then + return -1 +endi + +sql SELECT INTERP(c1) FROM tb1 RANGE('2021-10-20 10:00:04','2021-10-20 14:00:00') EVERY(1s) FILL(NULL); +if $rows != 14397 then + return -1 +endi +if $data00 != @21-10-20 10:00:04.000@ then + return -1 +endi +if $data01 != NULL then + return -1 +endi +if $data10 != @21-10-20 10:00:05.000@ then + return -1 +endi +if $data11 != NULL then + return -1 +endi +if $data20 != @21-10-20 10:00:06.000@ then + return -1 +endi +if $data21 != 6 then + return -1 +endi +if $data30 != @21-10-20 10:00:07.000@ then + return -1 +endi +if $data31 != NULL then + return -1 +endi +if $data40 != @21-10-20 10:00:08.000@ then + return -1 +endi +if $data41 != NULL then + return -1 +endi +if $data50 != @21-10-20 10:00:09.000@ then + return -1 +endi +if $data51 != NULL then + return -1 +endi +if $data60 != @21-10-20 10:00:10.000@ then + return -1 +endi +if $data61 != 10 then + return -1 +endi +if $data70 != @21-10-20 10:00:11.000@ then + return -1 +endi +if $data71 != NULL then + return -1 +endi +if $data80 != @21-10-20 10:00:12.000@ then + return -1 +endi +if $data81 != NULL then + return -1 +endi +if $data90 != @21-10-20 10:00:13.000@ then + return -1 +endi +if $data91 != NULL then + return -1 +endi + +sql SELECT INTERP(c1) FROM tb1 RANGE('2021-10-20 11:00:00','2021-10-20 14:00:00') EVERY(1s) FILL(NULL); +if $rows != 10801 then + return -1 +endi +if $data00 != @21-10-20 11:00:00.000@ then + return -1 +endi +if $data01 != NULL then + return -1 +endi +if $data10 != @21-10-20 11:00:01.000@ then + return -1 +endi +if $data11 != NULL then + return -1 +endi +if $data90 != @21-10-20 11:00:09.000@ then + return -1 +endi +if $data91 != NULL then + return -1 +endi + +sql SELECT INTERP(c1) FROM tb1 RANGE('2021-10-20 10:00:03.500','2021-10-20 14:00:00') EVERY(1s) FILL(LINEAR); +if $rows != 18 then + return -1 +endi +if $data00 != @21-10-20 10:00:03.500@ then + return -1 +endi +if $data01 != 3 then + return -1 +endi +if $data10 != @21-10-20 10:00:04.500@ then + return -1 +endi +if $data11 != 4 then + return -1 +endi +if $data20 != @21-10-20 10:00:05.500@ then + return -1 +endi +if $data21 != 5 then + return -1 +endi +if $data30 != @21-10-20 10:00:06.500@ then + return -1 +endi +if $data31 != 6 then + return -1 +endi +if $data40 != @21-10-20 10:00:07.500@ then + return -1 +endi +if $data41 != 7 then + return -1 +endi +if $data50 != @21-10-20 10:00:08.500@ then + return -1 +endi +if $data51 != 8 then + return -1 +endi +if $data60 != @21-10-20 10:00:09.500@ then + return -1 +endi +if $data61 != 9 then + return -1 +endi +if $data70 != @21-10-20 10:00:10.500@ then + return -1 +endi +if $data71 != 10 then + return -1 +endi +if $data80 != @21-10-20 10:00:11.500@ then + return -1 +endi +if $data81 != 11 then + return -1 +endi +if $data90 != @21-10-20 10:00:12.500@ then + return -1 +endi +if $data91 != 12 then + return -1 +endi + + +sql SELECT INTERP(c2) FROM tb1 RANGE('2021-10-20 10:00:03.500','2021-10-20 14:00:00') EVERY(1s) FILL(LINEAR); +if $rows != 18 then + return -1 +endi +if $data00 != @21-10-20 10:00:03.500@ then + return -1 +endi +if $data01 != 3.50000 then + return -1 +endi +if $data10 != @21-10-20 10:00:04.500@ then + return -1 +endi +if $data11 != 4.50000 then + return -1 +endi +if $data20 != @21-10-20 10:00:05.500@ then + return -1 +endi +if $data21 != 5.50000 then + return -1 +endi +if $data30 != @21-10-20 10:00:06.500@ then + return -1 +endi +if $data31 != 6.50000 then + return -1 +endi +if $data40 != @21-10-20 10:00:07.500@ then + return -1 +endi +if $data41 != 7.50000 then + return -1 +endi +if $data50 != @21-10-20 10:00:08.500@ then + return -1 +endi +if $data51 != 8.50000 then + return -1 +endi +if $data60 != @21-10-20 10:00:09.500@ then + return -1 +endi +if $data61 != 9.50000 then + return -1 +endi +if $data70 != @21-10-20 10:00:10.500@ then + return -1 +endi +if $data71 != 10.50000 then + return -1 +endi +if $data80 != @21-10-20 10:00:11.500@ then + return -1 +endi +if $data81 != 11.50000 then + return -1 +endi +if $data90 != @21-10-20 10:00:12.500@ then + return -1 +endi +if $data91 != 12.50000 then + return -1 +endi + +sql SELECT INTERP(c1) FROM tb1 WHERE ts BETWEEN '2021-10-20 10:00:10' AND '2021-10-20 10:00:15' RANGE('2021-10-20 10:00:00','2021-10-20 14:00:00') EVERY(1s) FILL(LINEAR); +if $rows != 6 then + return -1 +endi +if $data00 != @21-10-20 10:00:10.000@ then + return -1 +endi +if $data01 != 10 then + return -1 +endi +if $data10 != @21-10-20 10:00:11.000@ then + return -1 +endi +if $data11 != 11 then + return -1 +endi +if $data20 != @21-10-20 10:00:12.000@ then + return -1 +endi +if $data21 != 12 then + return -1 +endi +if $data30 != @21-10-20 10:00:13.000@ then + return -1 +endi +if $data31 != 13 then + return -1 +endi +if $data40 != @21-10-20 10:00:14.000@ then + return -1 +endi +if $data41 != 14 then + return -1 +endi +if $data50 != @21-10-20 10:00:15.000@ then + return -1 +endi +if $data51 != 15 then + return -1 +endi + +sql SELECT INTERP(c1) FROM tb1 WHERE ts BETWEEN '2021-10-20 10:00:10' AND '2021-10-20 10:00:11' RANGE('2021-10-20 10:00:00','2021-10-20 14:00:00') EVERY(1s) FILL(LINEAR); +if $rows != 1 then + return -1 +endi +if $data00 != @21-10-20 10:00:10.000@ then + return -1 +endi +if $data01 != 10 then + return -1 +endi + +sql SELECT INTERP(c1) FROM tb1 WHERE ts BETWEEN '2021-10-20 10:00:10' AND '2021-10-20 10:00:15' RANGE('2021-10-20 10:00:00','2021-10-20 14:00:00') EVERY(1s) FILL(NEXT); +if $rows != 16 then + return -1 +endi +if $data00 != @21-10-20 10:00:00.000@ then + return -1 +endi +if $data01 != 10 then + return -1 +endi +if $data10 != @21-10-20 10:00:01.000@ then + return -1 +endi +if $data11 != 10 then + return -1 +endi +if $data20 != @21-10-20 10:00:02.000@ then + return -1 +endi +if $data21 != 10 then + return -1 +endi +if $data30 != @21-10-20 10:00:03.000@ then + return -1 +endi +if $data31 != 10 then + return -1 +endi +if $data40 != @21-10-20 10:00:04.000@ then + return -1 +endi +if $data41 != 10 then + return -1 +endi +if $data50 != @21-10-20 10:00:05.000@ then + return -1 +endi +if $data51 != 10 then + return -1 +endi +if $data60 != @21-10-20 10:00:06.000@ then + return -1 +endi +if $data61 != 10 then + return -1 +endi +if $data70 != @21-10-20 10:00:07.000@ then + return -1 +endi +if $data71 != 10 then + return -1 +endi +if $data80 != @21-10-20 10:00:08.000@ then + return -1 +endi +if $data81 != 10 then + return -1 +endi +if $data90 != @21-10-20 10:00:09.000@ then + return -1 +endi +if $data91 != 10 then + return -1 +endi + +sql SELECT INTERP(c1) FROM tb1 WHERE ts BETWEEN '2021-10-20 10:00:10' AND '2021-10-20 10:00:15' RANGE('2021-10-20 09:00:00','2021-10-20 09:00:10') EVERY(1s) FILL(LINEAR); +if $rows != 0 then + return -1 +endi + +sql SELECT INTERP(c1) FROM tb1 WHERE ts BETWEEN '2021-10-20 10:00:10' AND '2021-10-20 10:00:20' RANGE('2021-10-20 10:00:05','2021-10-20 10:00:16') EVERY(1s) FILL(LINEAR); +if $rows != 6 then + return -1 +endi +if $data00 != @21-10-20 10:00:10.000@ then + return -1 +endi +if $data01 != 10 then + return -1 +endi +if $data10 != @21-10-20 10:00:11.000@ then + return -1 +endi +if $data11 != 11 then + return -1 +endi +if $data20 != @21-10-20 10:00:12.000@ then + return -1 +endi +if $data21 != 12 then + return -1 +endi +if $data30 != @21-10-20 10:00:13.000@ then + return -1 +endi +if $data31 != 13 then + return -1 +endi +if $data40 != @21-10-20 10:00:14.000@ then + return -1 +endi +if $data41 != 14 then + return -1 +endi +if $data50 != @21-10-20 10:00:15.000@ then + return -1 +endi +if $data51 != 15 then + return -1 +endi + +sql SELECT INTERP(c1) FROM tb1 WHERE ts BETWEEN '2021-10-20 10:00:10' AND '2021-10-20 10:00:20' RANGE('2021-10-20 10:00:15','2021-10-20 10:00:25') EVERY(1s) FILL(LINEAR); +if $rows != 1 then + return -1 +endi +if $data00 != @21-10-20 10:00:15.000@ then + return -1 +endi +if $data01 != 15 then + return -1 +endi + +sql SELECT INTERP(c1) FROM tb1 WHERE ts BETWEEN '2021-10-20 10:00:10' AND '2021-10-20 10:00:20' RANGE('2021-10-20 10:00:21','2021-10-20 10:00:30') EVERY(1s) FILL(LINEAR); +if $rows != 0 then + return -1 +endi + +sql SELECT INTERP(c1) FROM tb1 WHERE ts BETWEEN '2021-10-20 10:00:10' AND '2021-10-20 10:00:15' RANGE('2021-10-20 09:00:00','2021-10-20 09:00:10') EVERY(1s) FILL(PREV); +if $rows != 0 then + return -1 +endi + +sql SELECT INTERP(c1) FROM tb1 WHERE ts BETWEEN '2021-10-20 10:00:10' AND '2021-10-20 10:00:20' RANGE('2021-10-20 10:00:05','2021-10-20 10:00:16') EVERY(1s) FILL(PREV); +if $rows != 7 then + return -1 +endi +if $data00 != @21-10-20 10:00:10.000@ then + return -1 +endi +if $data01 != 10 then + return -1 +endi +if $data10 != @21-10-20 10:00:11.000@ then + return -1 +endi +if $data11 != 10 then + return -1 +endi +if $data20 != @21-10-20 10:00:12.000@ then + return -1 +endi +if $data21 != 10 then + return -1 +endi +if $data30 != @21-10-20 10:00:13.000@ then + return -1 +endi +if $data31 != 10 then + return -1 +endi +if $data40 != @21-10-20 10:00:14.000@ then + return -1 +endi +if $data41 != 10 then + return -1 +endi +if $data50 != @21-10-20 10:00:15.000@ then + return -1 +endi +if $data51 != 15 then + return -1 +endi +if $data60 != @21-10-20 10:00:16.000@ then + return -1 +endi +if $data61 != 15 then + return -1 +endi + +sql SELECT INTERP(c1) FROM tb1 WHERE ts BETWEEN '2021-10-20 10:00:10' AND '2021-10-20 10:00:20' RANGE('2021-10-20 10:00:15','2021-10-20 10:00:25') EVERY(1s) FILL(PREV); +if $rows != 11 then + return -1 +endi +if $data00 != @21-10-20 10:00:15.000@ then + return -1 +endi +if $data01 != 15 then + return -1 +endi +if $data10 != @21-10-20 10:00:16.000@ then + return -1 +endi +if $data11 != 15 then + return -1 +endi +if $data20 != @21-10-20 10:00:17.000@ then + return -1 +endi +if $data21 != 15 then + return -1 +endi +if $data30 != @21-10-20 10:00:18.000@ then + return -1 +endi +if $data31 != 15 then + return -1 +endi +if $data40 != @21-10-20 10:00:19.000@ then + return -1 +endi +if $data41 != 15 then + return -1 +endi +if $data50 != @21-10-20 10:00:20.000@ then + return -1 +endi +if $data51 != 15 then + return -1 +endi +if $data60 != @21-10-20 10:00:21.000@ then + return -1 +endi +if $data61 != 15 then + return -1 +endi +if $data70 != @21-10-20 10:00:22.000@ then + return -1 +endi +if $data71 != 15 then + return -1 +endi +if $data80 != @21-10-20 10:00:23.000@ then + return -1 +endi +if $data81 != 15 then + return -1 +endi +if $data90 != @21-10-20 10:00:24.000@ then + return -1 +endi +if $data91 != 15 then + return -1 +endi + +sql SELECT INTERP(c1) FROM tb1 WHERE ts BETWEEN '2021-10-20 10:00:10' AND '2021-10-20 10:00:20' RANGE('2021-10-20 10:00:21','2021-10-20 10:00:30') EVERY(1s) FILL(PREV); +if $rows != 10 then + return -1 +endi +if $data00 != @21-10-20 10:00:21.000@ then + return -1 +endi +if $data01 != 15 then + return -1 +endi +if $data10 != @21-10-20 10:00:22.000@ then + return -1 +endi +if $data11 != 15 then + return -1 +endi +if $data20 != @21-10-20 10:00:23.000@ then + return -1 +endi +if $data21 != 15 then + return -1 +endi +if $data30 != @21-10-20 10:00:24.000@ then + return -1 +endi +if $data31 != 15 then + return -1 +endi +if $data40 != @21-10-20 10:00:25.000@ then + return -1 +endi +if $data41 != 15 then + return -1 +endi +if $data50 != @21-10-20 10:00:26.000@ then + return -1 +endi +if $data51 != 15 then + return -1 +endi +if $data60 != @21-10-20 10:00:27.000@ then + return -1 +endi +if $data61 != 15 then + return -1 +endi +if $data70 != @21-10-20 10:00:28.000@ then + return -1 +endi +if $data71 != 15 then + return -1 +endi +if $data80 != @21-10-20 10:00:29.000@ then + return -1 +endi +if $data81 != 15 then + return -1 +endi +if $data90 != @21-10-20 10:00:30.000@ then + return -1 +endi +if $data91 != 15 then + return -1 +endi + +sql SELECT INTERP(c1) FROM tb1 WHERE ts BETWEEN '2021-10-20 10:00:10' AND '2021-10-20 10:00:15' RANGE('2021-10-20 09:00:00','2021-10-20 09:00:10') EVERY(1s) FILL(NEXT); +if $rows != 11 then + return -1 +endi +if $data00 != @21-10-20 09:00:00.000@ then + return -1 +endi +if $data01 != 10 then + return -1 +endi +if $data10 != @21-10-20 09:00:01.000@ then + return -1 +endi +if $data11 != 10 then + return -1 +endi +if $data20 != @21-10-20 09:00:02.000@ then + return -1 +endi +if $data21 != 10 then + return -1 +endi +if $data30 != @21-10-20 09:00:03.000@ then + return -1 +endi +if $data31 != 10 then + return -1 +endi +if $data40 != @21-10-20 09:00:04.000@ then + return -1 +endi +if $data41 != 10 then + return -1 +endi +if $data50 != @21-10-20 09:00:05.000@ then + return -1 +endi +if $data51 != 10 then + return -1 +endi +if $data60 != @21-10-20 09:00:06.000@ then + return -1 +endi +if $data61 != 10 then + return -1 +endi +if $data70 != @21-10-20 09:00:07.000@ then + return -1 +endi +if $data71 != 10 then + return -1 +endi +if $data80 != @21-10-20 09:00:08.000@ then + return -1 +endi +if $data81 != 10 then + return -1 +endi +if $data90 != @21-10-20 09:00:09.000@ then + return -1 +endi +if $data91 != 10 then + return -1 +endi + +sql SELECT INTERP(c1) FROM tb1 WHERE ts BETWEEN '2021-10-20 10:00:10' AND '2021-10-20 10:00:20' RANGE('2021-10-20 10:00:05','2021-10-20 10:00:16') EVERY(1s) FILL(NEXT); +if $rows != 11 then + return -1 +endi +if $data00 != @21-10-20 10:00:05.000@ then + return -1 +endi +if $data01 != 10 then + return -1 +endi +if $data10 != @21-10-20 10:00:06.000@ then + return -1 +endi +if $data11 != 10 then + return -1 +endi +if $data20 != @21-10-20 10:00:07.000@ then + return -1 +endi +if $data21 != 10 then + return -1 +endi +if $data30 != @21-10-20 10:00:08.000@ then + return -1 +endi +if $data31 != 10 then + return -1 +endi +if $data40 != @21-10-20 10:00:09.000@ then + return -1 +endi +if $data41 != 10 then + return -1 +endi +if $data50 != @21-10-20 10:00:10.000@ then + return -1 +endi +if $data51 != 10 then + return -1 +endi +if $data60 != @21-10-20 10:00:11.000@ then + return -1 +endi +if $data61 != 15 then + return -1 +endi +if $data70 != @21-10-20 10:00:12.000@ then + return -1 +endi +if $data71 != 15 then + return -1 +endi +if $data80 != @21-10-20 10:00:13.000@ then + return -1 +endi +if $data81 != 15 then + return -1 +endi +if $data90 != @21-10-20 10:00:14.000@ then + return -1 +endi +if $data91 != 15 then + return -1 +endi + +sql SELECT INTERP(c1) FROM tb1 WHERE ts BETWEEN '2021-10-20 10:00:10' AND '2021-10-20 10:00:20' RANGE('2021-10-20 10:00:15','2021-10-20 10:00:25') EVERY(1s) FILL(NEXT); +if $rows != 1 then + return -1 +endi +if $data00 != @21-10-20 10:00:15.000@ then + return -1 +endi +if $data01 != 15 then + return -1 +endi + + +sql SELECT INTERP(c1) FROM tb1 WHERE ts BETWEEN '2021-10-20 10:00:10' AND '2021-10-20 10:00:20' RANGE('2021-10-20 10:00:21','2021-10-20 10:00:30') EVERY(1s) FILL(NEXT); +if $rows != 0 then + return -1 +endi + +sql SELECT INTERP(c2) FROM tb4 RANGE('2021-10-20 10:00:00','2021-10-20 12:00:00') FILL(NULL); +if $rows != 0 then + return -1 +endi + +sql SELECT INTERP(c2) FROM tb4 RANGE('2021-10-20 10:00:00','2021-10-20 12:00:00') EVERY(1s) FILL(NULL); +if $rows != 0 then + return -1 +endi + +sql SELECT INTERP(c2) FROM tb4 RANGE('2021-10-20 10:00:00','2021-10-20 12:00:00') EVERY(1s) FILL(LINEAR); +if $rows != 0 then + return -1 +endi + +sql SELECT INTERP(c2) FROM tb4 RANGE('2021-10-20 10:00:00','2021-10-20 12:00:00') EVERY(1s) FILL(PREV); +if $rows != 0 then + return -1 +endi + +sql SELECT INTERP(c2) FROM tb4 RANGE('2021-10-20 10:00:00','2021-10-20 12:00:00') EVERY(1s) FILL(NEXT); +if $rows != 0 then + return -1 +endi + +sql SELECT INTERP(c2) FROM tb4 RANGE('2021-10-20 10:00:00','2021-10-20 12:00:00') EVERY(1s) FILL(VALUE,100); +if $rows != 0 then + return -1 +endi + + + +print ================== start DESC test + +sql SELECT INTERP(c1) FROM tb1 ORDER BY ts DESC; +if $rows != 1 then + return -1 +endi +if $data00 != @21-10-20 10:00:00.000@ then + return -1 +endi +if $data01 != 0 then + return -1 +endi + +sql SELECT ts,INTERP(c1) FROM tb1 ORDER BY ts DESC; +if $rows != 1 then + return -1 +endi +if $data00 != @21-10-20 10:00:00.000@ then + return -1 +endi +if $data01 != @21-10-20 10:00:00.000@ then + return -1 +endi +if $data02 != 0 then + return -1 +endi + +sql SELECT INTERP(c1) FROM tb1 where ts > '2021-10-20 10:00:03' ORDER BY ts DESC; +if $rows != 1 then + return -1 +endi +if $data00 != @21-10-20 10:00:06.000@ then + return -1 +endi +if $data01 != 6 then + return -1 +endi +sql SELECT INTERP(c1,c2,c3,c4,c6,c5) FROM tb1 every(1s) ORDER BY ts DESC; +if $rows != 7 then + return -1 +endi +if $data00 != @21-10-20 10:00:21.000@ then + return -1 +endi +if $data01 != 21 then + return -1 +endi +if $data02 != 21.00000 then + return -1 +endi +if $data03 != 21 then + return -1 +endi +if $data04 != 21 then + return -1 +endi +if $data05 != 21.000000000 then + return -1 +endi +if $data06 != 21 then + return -1 +endi +if $data10 != @21-10-20 10:00:15.000@ then + return -1 +endi +if $data11 != 15 then + return -1 +endi +if $data12 != 15.00000 then + return -1 +endi +if $data13 != 15 then + return -1 +endi +if $data14 != 15 then + return -1 +endi +if $data15 != 15.000000000 then + return -1 +endi +if $data16 != 15 then + return -1 +endi +if $data20 != @21-10-20 10:00:10.000@ then + return -1 +endi +if $data21 != 10 then + return -1 +endi +if $data22 != 10.00000 then + return -1 +endi +if $data23 != 10 then + return -1 +endi +if $data24 != 10 then + return -1 +endi +if $data25 != 10.000000000 then + return -1 +endi +if $data26 != 10 then + return -1 +endi +if $data30 != @21-10-20 10:00:06.000@ then + return -1 +endi +if $data31 != 6 then + return -1 +endi +if $data32 != 6.00000 then + return -1 +endi +if $data33 != 6 then + return -1 +endi +if $data34 != 6 then + return -1 +endi +if $data35 != 6.000000000 then + return -1 +endi +if $data36 != 6 then + return -1 +endi +if $data40 != @21-10-20 10:00:03.000@ then + return -1 +endi +if $data41 != 3 then + return -1 +endi +if $data42 != 3.00000 then + return -1 +endi +if $data43 != 3 then + return -1 +endi +if $data44 != 3 then + return -1 +endi +if $data45 != 3.000000000 then + return -1 +endi +if $data46 != 3 then + return -1 +endi +if $data50 != @21-10-20 10:00:01.000@ then + return -1 +endi +if $data51 != 1 then + return -1 +endi +if $data52 != 1.00000 then + return -1 +endi +if $data53 != 1 then + return -1 +endi +if $data54 != 1 then + return -1 +endi +if $data55 != 1.000000000 then + return -1 +endi +if $data56 != 1 then + return -1 +endi +if $data60 != @21-10-20 10:00:00.000@ then + return -1 +endi +if $data61 != 0 then + return -1 +endi +if $data62 != 0.00000 then + return -1 +endi +if $data63 != 0 then + return -1 +endi +if $data64 != 0 then + return -1 +endi +if $data65 != 0.000000000 then + return -1 +endi +if $data66 != 0 then + return -1 +endi + +sql SELECT INTERP(c1),interp(c2),interp(c3) FROM tb1 every(1s) ORDER BY ts DESC; +if $rows != 7 then + return -1 +endi +if $data60 != @21-10-20 10:00:00.000@ then + return -1 +endi +if $data61 != 0 then + return -1 +endi +if $data62 != 0.00000 then + return -1 +endi +if $data63 != 0 then + return -1 +endi +if $data50 != @21-10-20 10:00:01.000@ then + return -1 +endi +if $data51 != 1 then + return -1 +endi +if $data52 != 1.00000 then + return -1 +endi +if $data53 != 1 then + return -1 +endi +if $data40 != @21-10-20 10:00:03.000@ then + return -1 +endi +if $data41 != 3 then + return -1 +endi +if $data42 != 3.00000 then + return -1 +endi +if $data43 != 3 then + return -1 +endi +if $data30 != @21-10-20 10:00:06.000@ then + return -1 +endi +if $data31 != 6 then + return -1 +endi +if $data32 != 6.00000 then + return -1 +endi +if $data33 != 6 then + return -1 +endi +if $data20 != @21-10-20 10:00:10.000@ then + return -1 +endi +if $data21 != 10 then + return -1 +endi +if $data22 != 10.00000 then + return -1 +endi +if $data23 != 10 then + return -1 +endi +if $data10 != @21-10-20 10:00:15.000@ then + return -1 +endi +if $data11 != 15 then + return -1 +endi +if $data12 != 15.00000 then + return -1 +endi +if $data13 != 15 then + return -1 +endi +if $data00 != @21-10-20 10:00:21.000@ then + return -1 +endi +if $data01 != 21 then + return -1 +endi +if $data02 != 21.00000 then + return -1 +endi +if $data03 != 21 then + return -1 +endi + +sql SELECT INTERP(c1),ts FROM tb1 every(1s) ORDER BY ts DESC; +if $rows != 7 then + return -1 +endi +if $data60 != @21-10-20 10:00:00.000@ then + return -1 +endi +if $data61 != 0 then + return -1 +endi +if $data62 != @21-10-20 10:00:00.000@ then + return -1 +endi +if $data50 != @21-10-20 10:00:01.000@ then + return -1 +endi +if $data51 != 1 then + return -1 +endi +if $data52 != @21-10-20 10:00:01.000@ then + return -1 +endi +if $data40 != @21-10-20 10:00:03.000@ then + return -1 +endi +if $data41 != 3 then + return -1 +endi +if $data42 != @21-10-20 10:00:03.000@ then + return -1 +endi +if $data30 != @21-10-20 10:00:06.000@ then + return -1 +endi +if $data31 != 6 then + return -1 +endi +if $data32 != @21-10-20 10:00:06.000@ then + return -1 +endi +if $data20 != @21-10-20 10:00:10.000@ then + return -1 +endi +if $data21 != 10 then + return -1 +endi +if $data22 != @21-10-20 10:00:10.000@ then + return -1 +endi +if $data10 != @21-10-20 10:00:15.000@ then + return -1 +endi +if $data11 != 15 then + return -1 +endi +if $data12 != @21-10-20 10:00:15.000@ then + return -1 +endi +if $data00 != @21-10-20 10:00:21.000@ then + return -1 +endi +if $data01 != 21 then + return -1 +endi +if $data02 != @21-10-20 10:00:21.000@ then + return -1 +endi + +sql SELECT INTERP(c1) FROM stb1 every(1s) group by tbname ORDER BY ts DESC; +if $rows != 21 then + return -1 +endi +if $data60 != @21-10-20 10:00:00.000@ then + return -1 +endi +if $data61 != 0 then + return -1 +endi +if $data62 != tb1 then + return -1 +endi +if $data50 != @21-10-20 10:00:01.000@ then + return -1 +endi +if $data51 != 1 then + return -1 +endi +if $data52 != tb1 then + return -1 +endi +if $data40 != @21-10-20 10:00:03.000@ then + return -1 +endi +if $data41 != 3 then + return -1 +endi +if $data42 != tb1 then + return -1 +endi +if $data30 != @21-10-20 10:00:06.000@ then + return -1 +endi +if $data31 != 6 then + return -1 +endi +if $data32 != tb1 then + return -1 +endi +if $data20 != @21-10-20 10:00:10.000@ then + return -1 +endi +if $data21 != 10 then + return -1 +endi +if $data22 != tb1 then + return -1 +endi +if $data10 != @21-10-20 10:00:15.000@ then + return -1 +endi +if $data11 != 15 then + return -1 +endi +if $data12 != tb1 then + return -1 +endi +if $data00 != @21-10-20 10:00:21.000@ then + return -1 +endi +if $data01 != 21 then + return -1 +endi +if $data02 != tb1 then + return -1 +endi +if $data70 != @21-10-20 10:00:14.000@ then + return -1 +endi +if $data71 != 14 then + return -1 +endi +if $data72 != tb2 then + return -1 +endi +if $data80 != @21-10-20 10:00:12.000@ then + return -1 +endi +if $data81 != 12 then + return -1 +endi +if $data82 != tb2 then + return -1 +endi +if $data90 != @21-10-20 10:00:10.000@ then + return -1 +endi +if $data91 != 10 then + return -1 +endi +if $data92 != tb2 then + return -1 +endi + +sql SELECT INTERP(c1) FROM stb1 every(1s) group by tbname ORDER BY ts DESC limit 5; +if $rows != 15 then + return -1 +endi + +sql SELECT INTERP(c1) FROM stb1 every(1s) group by tbname ORDER BY ts DESC limit 3; +if $rows != 9 then + return -1 +endi +if $data00 != @21-10-20 10:00:21.000@ then + return -1 +endi +if $data01 != 21 then + return -1 +endi +if $data02 != tb1 then + return -1 +endi +if $data10 != @21-10-20 10:00:15.000@ then + return -1 +endi +if $data11 != 15 then + return -1 +endi +if $data12 != tb1 then + return -1 +endi +if $data20 != @21-10-20 10:00:10.000@ then + return -1 +endi +if $data21 != 10 then + return -1 +endi +if $data22 != tb1 then + return -1 +endi +if $data30 != @21-10-20 10:00:14.000@ then + return -1 +endi +if $data31 != 14 then + return -1 +endi +if $data32 != tb2 then + return -1 +endi +if $data40 != @21-10-20 10:00:12.000@ then + return -1 +endi +if $data41 != 12 then + return -1 +endi +if $data42 != tb2 then + return -1 +endi +if $data50 != @21-10-20 10:00:10.000@ then + return -1 +endi +if $data51 != 10 then + return -1 +endi +if $data52 != tb2 then + return -1 +endi +if $data60 != @21-10-20 10:00:21.000@ then + return -1 +endi +if $data61 != 21 then + return -1 +endi +if $data62 != tb3 then + return -1 +endi +if $data70 != @21-10-20 10:00:18.000@ then + return -1 +endi +if $data71 != 18 then + return -1 +endi +if $data72 != tb3 then + return -1 +endi +if $data80 != @21-10-20 10:00:10.000@ then + return -1 +endi +if $data81 != 10 then + return -1 +endi +if $data82 != tb3 then + return -1 +endi + +sql SELECT INTERP(c1) FROM stb1 every(1s) group by tbname ORDER BY ts DESC limit 3 offset 6; +if $rows != 3 then + return -1 +endi +if $data00 != @21-10-20 10:00:00.000@ then + return -1 +endi +if $data01 != 0 then + return -1 +endi +if $data02 != tb1 then + return -1 +endi +if $data10 != @21-10-20 10:00:00.000@ then + return -1 +endi +if $data11 != 0 then + return -1 +endi +if $data12 != tb2 then + return -1 +endi +if $data20 != @21-10-20 10:00:00.000@ then + return -1 +endi +if $data21 != 0 then + return -1 +endi +if $data22 != tb3 then + return -1 +endi + +sql SELECT INTERP(c1),t1,interp(c2),t2,interp(c3) FROM stb1 every(1s) group by tbname ORDER BY ts DESC; +if $rows != 21 then + return -1 +endi +if $data00 != @21-10-20 10:00:21.000@ then + return -1 +endi +if $data01 != 21 then + return -1 +endi +if $data02 != 1 then + return -1 +endi +if $data03 != 21.00000 then + return -1 +endi +if $data04 != 1 then + return -1 +endi +if $data05 != 21 then + return -1 +endi +if $data06 != tb1 then + return -1 +endi +if $data10 != @21-10-20 10:00:15.000@ then + return -1 +endi +if $data11 != 15 then + return -1 +endi +if $data12 != 1 then + return -1 +endi +if $data13 != 15.00000 then + return -1 +endi +if $data14 != 1 then + return -1 +endi +if $data15 != 15 then + return -1 +endi +if $data16 != tb1 then + return -1 +endi +if $data20 != @21-10-20 10:00:10.000@ then + return -1 +endi +if $data21 != 10 then + return -1 +endi +if $data22 != 1 then + return -1 +endi +if $data23 != 10.00000 then + return -1 +endi +if $data24 != 1 then + return -1 +endi +if $data25 != 10 then + return -1 +endi +if $data26 != tb1 then + return -1 +endi +if $data30 != @21-10-20 10:00:06.000@ then + return -1 +endi +if $data31 != 6 then + return -1 +endi +if $data32 != 1 then + return -1 +endi +if $data33 != 6.00000 then + return -1 +endi +if $data34 != 1 then + return -1 +endi +if $data35 != 6 then + return -1 +endi +if $data36 != tb1 then + return -1 +endi +if $data40 != @21-10-20 10:00:03.000@ then + return -1 +endi +if $data41 != 3 then + return -1 +endi +if $data42 != 1 then + return -1 +endi +if $data43 != 3.00000 then + return -1 +endi +if $data44 != 1 then + return -1 +endi +if $data45 != 3 then + return -1 +endi +if $data46 != tb1 then + return -1 +endi +if $data50 != @21-10-20 10:00:01.000@ then + return -1 +endi +if $data51 != 1 then + return -1 +endi +if $data52 != 1 then + return -1 +endi +if $data53 != 1.00000 then + return -1 +endi +if $data54 != 1 then + return -1 +endi +if $data55 != 1 then + return -1 +endi +if $data56 != tb1 then + return -1 +endi +if $data60 != @21-10-20 10:00:00.000@ then + return -1 +endi +if $data61 != 0 then + return -1 +endi +if $data62 != 1 then + return -1 +endi +if $data63 != 0.00000 then + return -1 +endi +if $data64 != 1 then + return -1 +endi +if $data65 != 0 then + return -1 +endi +if $data66 != tb1 then + return -1 +endi +if $data70 != @21-10-20 10:00:14.000@ then + return -1 +endi +if $data71 != 14 then + return -1 +endi +if $data72 != 2 then + return -1 +endi +if $data73 != 14.00000 then + return -1 +endi +if $data74 != 2 then + return -1 +endi +if $data75 != 14 then + return -1 +endi +if $data76 != tb2 then + return -1 +endi +if $data80 != @21-10-20 10:00:12.000@ then + return -1 +endi +if $data81 != 12 then + return -1 +endi +if $data82 != 2 then + return -1 +endi +if $data83 != 12.00000 then + return -1 +endi +if $data84 != 2 then + return -1 +endi +if $data85 != 12 then + return -1 +endi +if $data86 != tb2 then + return -1 +endi +if $data90 != @21-10-20 10:00:10.000@ then + return -1 +endi +if $data91 != 10 then + return -1 +endi +if $data92 != 2 then + return -1 +endi +if $data93 != 10.00000 then + return -1 +endi +if $data94 != 2 then + return -1 +endi +if $data95 != 10 then + return -1 +endi +if $data96 != tb2 then + return -1 +endi diff --git a/tests/script/general/parser/interp_full_test3.sim b/tests/script/general/parser/interp_full_test3.sim new file mode 100644 index 0000000000000000000000000000000000000000..94745211e4efb71ee96e5e9161f901a2ccb52a71 --- /dev/null +++ b/tests/script/general/parser/interp_full_test3.sim @@ -0,0 +1,2401 @@ +sleep 100 +sql connect + +sql use db; + + +sql SELECT tbname,INTERP(c1),t1,interp(c2),t2,interp(c3) FROM stb1 every(4s) group by tbname ORDER BY ts DESC; +if $rows != 5 then + return -1 +endi +if $data00 != @21-10-20 10:00:00.000@ then + return -1 +endi +if $data01 != tb1 then + return -1 +endi +if $data02 != 0 then + return -1 +endi +if $data03 != 1 then + return -1 +endi +if $data04 != 0.00000 then + return -1 +endi +if $data05 != 1 then + return -1 +endi +if $data06 != 0 then + return -1 +endi +if $data07 != tb1 then + return -1 +endi +if $data30 != @21-10-20 10:00:00.000@ then + return -1 +endi +if $data31 != tb2 then + return -1 +endi +if $data32 != 0 then + return -1 +endi +if $data33 != 2 then + return -1 +endi +if $data34 != 0.00000 then + return -1 +endi +if $data35 != 2 then + return -1 +endi +if $data36 != 0 then + return -1 +endi +if $data37 != tb2 then + return -1 +endi +if $data20 != @21-10-20 10:00:04.000@ then + return -1 +endi +if $data21 != tb2 then + return -1 +endi +if $data22 != 4 then + return -1 +endi +if $data23 != 2 then + return -1 +endi +if $data24 != 4.00000 then + return -1 +endi +if $data25 != 2 then + return -1 +endi +if $data26 != 4 then + return -1 +endi +if $data27 != tb2 then + return -1 +endi +if $data10 != @21-10-20 10:00:12.000@ then + return -1 +endi +if $data11 != tb2 then + return -1 +endi +if $data12 != 12 then + return -1 +endi +if $data13 != 2 then + return -1 +endi +if $data14 != 12.00000 then + return -1 +endi +if $data15 != 2 then + return -1 +endi +if $data16 != 12 then + return -1 +endi +if $data17 != tb2 then + return -1 +endi +if $data40 != @21-10-20 10:00:00.000@ then + return -1 +endi +if $data41 != tb3 then + return -1 +endi +if $data42 != 0 then + return -1 +endi +if $data43 != 3 then + return -1 +endi +if $data44 != 0.00000 then + return -1 +endi +if $data45 != 3 then + return -1 +endi +if $data46 != 0 then + return -1 +endi +if $data47 != tb3 then + return -1 +endi +sql SELECT INTERP(c1) FROM stb1 range('2021-10-20 10:00:00.000','2021-10-20 10:00:40.000') every(1s) fill(linear) group by tbname ORDER BY ts DESC; +if $rows != 59 then + return -1 +endi +if $data00 != @21-10-20 10:00:21.000@ then + return -1 +endi +if $data01 != 21 then + return -1 +endi +if $data02 != tb1 then + return -1 +endi +if $data10 != @21-10-20 10:00:20.000@ then + return -1 +endi +if $data11 != 20 then + return -1 +endi +if $data12 != tb1 then + return -1 +endi +if $data20 != @21-10-20 10:00:19.000@ then + return -1 +endi +if $data21 != 19 then + return -1 +endi +if $data22 != tb1 then + return -1 +endi +if $data30 != @21-10-20 10:00:18.000@ then + return -1 +endi +if $data31 != 18 then + return -1 +endi +if $data32 != tb1 then + return -1 +endi +if $data40 != @21-10-20 10:00:17.000@ then + return -1 +endi +if $data41 != 17 then + return -1 +endi +if $data42 != tb1 then + return -1 +endi +if $data50 != @21-10-20 10:00:16.000@ then + return -1 +endi +if $data51 != 16 then + return -1 +endi +if $data52 != tb1 then + return -1 +endi +if $data60 != @21-10-20 10:00:15.000@ then + return -1 +endi +if $data61 != 15 then + return -1 +endi +if $data62 != tb1 then + return -1 +endi +if $data70 != @21-10-20 10:00:14.000@ then + return -1 +endi +if $data71 != 14 then + return -1 +endi +if $data72 != tb1 then + return -1 +endi +if $data80 != @21-10-20 10:00:13.000@ then + return -1 +endi +if $data81 != 13 then + return -1 +endi +if $data82 != tb1 then + return -1 +endi +if $data90 != @21-10-20 10:00:12.000@ then + return -1 +endi +if $data91 != 12 then + return -1 +endi +if $data92 != tb1 then + return -1 +endi +sql SELECT INTERP(c1) FROM tb1 RANGE('2021-10-20 09:00:00','2021-10-20 14:00:00') ORDER BY ts DESC; +if $rows != 0 then + return -1 +endi + +sql SELECT INTERP(c1) FROM tb1 RANGE('2021-10-20 09:00:00','2021-10-20 09:00:01') ORDER BY ts DESC; +if $rows != 0 then + return -1 +endi + +sql SELECT INTERP(c1) FROM tb1 RANGE('2021-10-20 10:00:00','2021-10-20 14:00:00') ORDER BY ts DESC; +if $rows != 1 then + return -1 +endi +if $data00 != @21-10-20 10:00:00.000@ then + return -1 +endi +if $data01 != 0 then + return -1 +endi + +sql SELECT INTERP(c1) FROM tb1 RANGE('2021-10-20 10:00:04','2021-10-20 14:00:00') ORDER BY ts DESC; +if $rows != 0 then + return -1 +endi + +sql SELECT INTERP(c1) FROM tb1 RANGE('2021-10-20 11:00:00','2021-10-20 14:00:00') ORDER BY ts DESC; +if $rows != 0 then + return -1 +endi + +sql SELECT INTERP(c1) FROM tb1 FILL(LINEAR) ORDER BY ts DESC; +if $rows != 1 then + return -1 +endi +if $data00 != @21-10-20 10:00:00.000@ then + return -1 +endi +if $data01 != 0 then + return -1 +endi + +sql SELECT INTERP(c1) FROM tb1 FILL(NEXT) ORDER BY ts DESC; +if $rows != 1 then + return -1 +endi +if $data00 != @21-10-20 10:00:00.000@ then + return -1 +endi +if $data01 != 0 then + return -1 +endi +sql SELECT INTERP(c1) FROM tb1 FILL(PREV) ORDER BY ts DESC; +if $rows != 1 then + return -1 +endi +if $data00 != @21-10-20 10:00:00.000@ then + return -1 +endi +if $data01 != 0 then + return -1 +endi + +sql SELECT INTERP(c1) FROM tb1 FILL(VALUE, 100) ORDER BY ts DESC; +if $rows != 1 then + return -1 +endi +if $data00 != @21-10-20 10:00:00.000@ then + return -1 +endi +if $data01 != 0 then + return -1 +endi + +sql SELECT INTERP(c1) FROM tb1 FILL(NULL) ORDER BY ts DESC; +if $rows != 1 then + return -1 +endi +if $data00 != @21-10-20 10:00:00.000@ then + return -1 +endi +if $data01 != 0 then + return -1 +endi + +sql SELECT INTERP(c1) FROM tb1 every(1s) ORDER BY ts DESC; +if $rows != 7 then + return -1 +endi +if $data60 != @21-10-20 10:00:00.000@ then + return -1 +endi +if $data61 != 0 then + return -1 +endi +if $data50 != @21-10-20 10:00:01.000@ then + return -1 +endi +if $data51 != 1 then + return -1 +endi +if $data40 != @21-10-20 10:00:03.000@ then + return -1 +endi +if $data41 != 3 then + return -1 +endi +if $data30 != @21-10-20 10:00:06.000@ then + return -1 +endi +if $data31 != 6 then + return -1 +endi +if $data20 != @21-10-20 10:00:10.000@ then + return -1 +endi +if $data21 != 10 then + return -1 +endi +if $data10 != @21-10-20 10:00:15.000@ then + return -1 +endi +if $data11 != 15 then + return -1 +endi +if $data00 != @21-10-20 10:00:21.000@ then + return -1 +endi +if $data01 != 21 then + return -1 +endi + +sql SELECT INTERP(c1) FROM tb1 every(2s) ORDER BY ts DESC; +if $rows != 3 then + return -1 +endi +if $data20 != @21-10-20 10:00:00.000@ then + return -1 +endi +if $data21 != 0 then + return -1 +endi +if $data10 != @21-10-20 10:00:06.000@ then + return -1 +endi +if $data11 != 6 then + return -1 +endi +if $data00 != @21-10-20 10:00:10.000@ then + return -1 +endi +if $data01 != 10 then + return -1 +endi +sql SELECT INTERP(c1) FROM tb1 every(5s) ORDER BY ts DESC; +if $rows != 3 then + return -1 +endi +if $data20 != @21-10-20 10:00:00.000@ then + return -1 +endi +if $data21 != 0 then + return -1 +endi +if $data10 != @21-10-20 10:00:10.000@ then + return -1 +endi +if $data11 != 10 then + return -1 +endi +if $data00 != @21-10-20 10:00:15.000@ then + return -1 +endi +if $data01 != 15 then + return -1 +endi +sql SELECT INTERP(c1) FROM tb1 every(100s) ORDER BY ts DESC; +if $rows != 1 then + return -1 +endi +if $data00 != @21-10-20 10:00:00.000@ then + return -1 +endi +if $data01 != 0 then + return -1 +endi + +sql SELECT INTERP(c1) FROM tb1 RANGE('2021-10-20 09:00:00','2021-10-20 14:00:00') FILL(LINEAR) ORDER BY ts DESC; +if $rows != 0 then + return -1 +endi +sql SELECT INTERP(c1) FROM tb1 RANGE('2021-10-20 09:00:00','2021-10-20 09:00:01') FILL(LINEAR) ORDER BY ts DESC; +if $rows != 0 then + return -1 +endi +sql SELECT INTERP(c1) FROM tb1 RANGE('2021-10-20 10:00:00','2021-10-20 10:00:00') FILL(LINEAR) ORDER BY ts DESC; +if $rows != 1 then + return -1 +endi +if $data00 != @21-10-20 10:00:00.000@ then + return -1 +endi +if $data01 != 0 then + return -1 +endi +sql SELECT INTERP(c1) FROM tb1 RANGE('2021-10-20 10:00:04','2021-10-20 14:00:00') FILL(LINEAR) ORDER BY ts DESC; +if $rows != 1 then + return -1 +endi +if $data00 != @21-10-20 10:00:04.000@ then + return -1 +endi +if $data01 != 4 then + return -1 +endi +sql SELECT INTERP(c1) FROM tb1 RANGE('2021-10-20 11:00:00','2021-10-20 14:00:00') FILL(LINEAR) ORDER BY ts DESC; +if $rows != 0 then + return -1 +endi + +sql SELECT INTERP(c1) FROM tb1 RANGE('2021-10-20 09:00:00','2021-10-20 14:00:00') FILL(NEXT) ORDER BY ts DESC; +if $rows != 1 then + return -1 +endi +if $data00 != @21-10-20 09:00:00.000@ then + return -1 +endi +if $data01 != 0 then + return -1 +endi +sql SELECT INTERP(c1) FROM tb1 RANGE('2021-10-20 09:00:00','2021-10-20 09:00:01') FILL(NEXT) ORDER BY ts DESC; +if $rows != 1 then + return -1 +endi +if $data00 != @21-10-20 09:00:00.000@ then + return -1 +endi +if $data01 != 0 then + return -1 +endi +sql SELECT INTERP(c1) FROM tb1 RANGE('2021-10-20 10:00:00','2021-10-20 12:00:00') FILL(NEXT) ORDER BY ts DESC; +if $rows != 1 then + return -1 +endi +if $data00 != @21-10-20 10:00:00.000@ then + return -1 +endi +if $data01 != 0 then + return -1 +endi +sql SELECT INTERP(c1) FROM tb1 RANGE('2021-10-20 10:00:04','2021-10-20 14:00:00') FILL(NEXT) ORDER BY ts DESC; +if $rows != 1 then + return -1 +endi +if $data00 != @21-10-20 10:00:04.000@ then + return -1 +endi +if $data01 != 6 then + return -1 +endi +sql SELECT INTERP(c1) FROM tb1 RANGE('2021-10-20 11:00:00','2021-10-20 14:00:00') FILL(NEXT) ORDER BY ts DESC; +if $rows != 0 then + return -1 +endi +sql SELECT INTERP(c1) FROM tb1 RANGE('2021-10-20 09:00:00','2021-10-20 14:00:00') FILL(PREV) ORDER BY ts DESC; +if $rows != 0 then + return -1 +endi +sql SELECT INTERP(c1) FROM tb1 RANGE('2021-10-20 09:00:00','2021-10-20 09:00:01') FILL(PREV) ORDER BY ts DESC; +if $rows != 0 then + return -1 +endi +sql SELECT INTERP(c1) FROM tb1 RANGE('2021-10-20 10:00:00','2021-10-20 12:00:00') FILL(PREV) ORDER BY ts DESC; +if $rows != 1 then + return -1 +endi +if $data00 != @21-10-20 10:00:00.000@ then + return -1 +endi +if $data01 != 0 then + return -1 +endi +sql SELECT INTERP(c1) FROM tb1 RANGE('2021-10-20 10:00:04','2021-10-20 14:00:00') FILL(PREV) ORDER BY ts DESC; +if $rows != 1 then + return -1 +endi +if $data00 != @21-10-20 10:00:04.000@ then + return -1 +endi +if $data01 != 3 then + return -1 +endi +sql SELECT INTERP(c1) FROM tb1 RANGE('2021-10-20 11:00:00','2021-10-20 14:00:00') FILL(PREV) ORDER BY ts DESC; +if $rows != 1 then + return -1 +endi +if $data00 != @21-10-20 11:00:00.000@ then + return -1 +endi +if $data01 != 21 then + return -1 +endi +sql SELECT INTERP(c2) FROM tb1 RANGE('2021-10-20 09:00:00','2021-10-20 14:00:00') FILL(VALUE,100) ORDER BY ts DESC; +if $rows != 1 then + return -1 +endi +if $data00 != @21-10-20 09:00:00.000@ then + return -1 +endi +if $data01 != 100.00000 then + return -1 +endi +sql SELECT INTERP(c1) FROM tb1 RANGE('2021-10-20 09:00:00','2021-10-20 09:00:01') FILL(VALUE,100) ORDER BY ts DESC; +if $rows != 1 then + return -1 +endi +if $data00 != @21-10-20 09:00:00.000@ then + return -1 +endi +if $data01 != 100 then + return -1 +endi +sql SELECT INTERP(c1) FROM tb1 RANGE('2021-10-20 10:00:00','2021-10-20 12:00:00') FILL(VALUE,100) ORDER BY ts DESC; +if $rows != 1 then + return -1 +endi +if $data00 != @21-10-20 10:00:00.000@ then + return -1 +endi +if $data01 != 0 then + return -1 +endi +sql SELECT INTERP(c1) FROM tb1 RANGE('2021-10-20 10:00:04','2021-10-20 14:00:00') FILL(VALUE,100) ORDER BY ts DESC; +if $rows != 1 then + return -1 +endi +if $data00 != @21-10-20 10:00:04.000@ then + return -1 +endi +if $data01 != 100 then + return -1 +endi +sql SELECT INTERP(c1) FROM tb1 RANGE('2021-10-20 11:00:00','2021-10-20 14:00:00') FILL(VALUE,100) ORDER BY ts DESC; +if $rows != 1 then + return -1 +endi +if $data00 != @21-10-20 11:00:00.000@ then + return -1 +endi +if $data01 != 100 then + return -1 +endi +sql SELECT INTERP(c2) FROM tb1 RANGE('2021-10-20 09:00:00','2021-10-20 14:00:00') FILL(NULL) ORDER BY ts DESC; +if $rows != 1 then + return -1 +endi +if $data00 != @21-10-20 09:00:00.000@ then + return -1 +endi +if $data01 != NULL then + return -1 +endi +sql SELECT INTERP(c2) FROM tb1 RANGE('2021-10-20 09:00:00','2021-10-20 09:00:01') FILL(NULL) ORDER BY ts DESC; +if $rows != 1 then + return -1 +endi +if $data00 != @21-10-20 09:00:00.000@ then + return -1 +endi +if $data01 != NULL then + return -1 +endi +sql SELECT INTERP(c2) FROM tb1 RANGE('2021-10-20 10:00:00','2021-10-20 12:00:00') FILL(NULL) ORDER BY ts DESC; +if $rows != 1 then + return -1 +endi +if $data00 != @21-10-20 10:00:00.000@ then + return -1 +endi +if $data01 != 0.00000 then + return -1 +endi +sql SELECT INTERP(c2) FROM tb1 RANGE('2021-10-20 10:00:04','2021-10-20 14:00:00') FILL(NULL) ORDER BY ts DESC; +if $rows != 1 then + return -1 +endi +if $data00 != @21-10-20 10:00:04.000@ then + return -1 +endi +if $data01 != NULL then + return -1 +endi +sql SELECT INTERP(c2) FROM tb1 RANGE('2021-10-20 11:00:00','2021-10-20 14:00:00') FILL(NULL) ORDER BY ts DESC; +if $rows != 1 then + return -1 +endi +if $data00 != @21-10-20 11:00:00.000@ then + return -1 +endi +if $data01 != NULL then + return -1 +endi +sql SELECT INTERP(c1) FROM tb1 RANGE('2021-10-20 09:00:00','2021-10-20 14:00:00') EVERY(1s) ORDER BY ts DESC; +if $rows != 7 then + return -1 +endi +if $data60 != @21-10-20 10:00:00.000@ then + return -1 +endi +if $data61 != 0 then + return -1 +endi +if $data50 != @21-10-20 10:00:01.000@ then + return -1 +endi +if $data51 != 1 then + return -1 +endi +if $data40 != @21-10-20 10:00:03.000@ then + return -1 +endi +if $data41 != 3 then + return -1 +endi +if $data30 != @21-10-20 10:00:06.000@ then + return -1 +endi +if $data31 != 6 then + return -1 +endi +if $data20 != @21-10-20 10:00:10.000@ then + return -1 +endi +if $data21 != 10 then + return -1 +endi +if $data10 != @21-10-20 10:00:15.000@ then + return -1 +endi +if $data11 != 15 then + return -1 +endi +if $data00 != @21-10-20 10:00:21.000@ then + return -1 +endi +if $data01 != 21 then + return -1 +endi +sql SELECT INTERP(c1) FROM tb1 RANGE('2021-10-20 09:00:00','2021-10-20 09:00:01') EVERY(1s) ORDER BY ts DESC; +if $rows != 0 then + return -1 +endi +sql SELECT INTERP(c1) FROM tb1 RANGE('2021-10-20 10:00:00','2021-10-20 10:00:00') EVERY(1s) ORDER BY ts DESC; +if $rows != 1 then + return -1 +endi +if $data00 != @21-10-20 10:00:00.000@ then + return -1 +endi +if $data01 != 0 then + return -1 +endi +sql SELECT INTERP(c1) FROM tb1 RANGE('2021-10-20 10:00:04','2021-10-20 14:00:00') EVERY(1s) ORDER BY ts DESC; +if $rows != 4 then + return -1 +endi +if $data30 != @21-10-20 10:00:06.000@ then + return -1 +endi +if $data31 != 6 then + return -1 +endi +if $data20 != @21-10-20 10:00:10.000@ then + return -1 +endi +if $data21 != 10 then + return -1 +endi +if $data10 != @21-10-20 10:00:15.000@ then + return -1 +endi +if $data11 != 15 then + return -1 +endi +if $data00 != @21-10-20 10:00:21.000@ then + return -1 +endi +if $data01 != 21 then + return -1 +endi +sql SELECT INTERP(c1) FROM tb1 RANGE('2021-10-20 11:00:00','2021-10-20 14:00:00') EVERY(1s) ORDER BY ts DESC; +if $rows != 0 then + return -1 +endi +sql SELECT INTERP(c1) FROM tb1 RANGE('2021-10-20 09:00:00','2021-10-20 14:00:00') EVERY(2s) ORDER BY ts DESC; +if $rows != 3 then + return -1 +endi +if $data20 != @21-10-20 10:00:00.000@ then + return -1 +endi +if $data21 != 0 then + return -1 +endi +if $data10 != @21-10-20 10:00:06.000@ then + return -1 +endi +if $data11 != 6 then + return -1 +endi +if $data00 != @21-10-20 10:00:10.000@ then + return -1 +endi +if $data01 != 10 then + return -1 +endi +sql SELECT INTERP(c1) FROM tb1 RANGE('2021-10-20 09:00:00','2021-10-20 09:00:01') EVERY(2s) ORDER BY ts DESC; +if $rows != 0 then + return -1 +endi +sql SELECT INTERP(c1) FROM tb1 RANGE('2021-10-20 10:00:00','2021-10-20 10:00:00') EVERY(2s) ORDER BY ts DESC; +if $rows != 1 then + return -1 +endi +if $data00 != @21-10-20 10:00:00.000@ then + return -1 +endi +if $data01 != 0 then + return -1 +endi +sql SELECT INTERP(c1) FROM tb1 RANGE('2021-10-20 10:00:04','2021-10-20 14:00:00') EVERY(2s) ORDER BY ts DESC; +if $rows != 2 then + return -1 +endi +if $data10 != @21-10-20 10:00:06.000@ then + return -1 +endi +if $data11 != 6 then + return -1 +endi +if $data00 != @21-10-20 10:00:10.000@ then + return -1 +endi +if $data01 != 10 then + return -1 +endi +sql SELECT INTERP(c1) FROM tb1 RANGE('2021-10-20 11:00:00','2021-10-20 14:00:00') EVERY(2s) ORDER BY ts DESC; +if $rows != 0 then + return -1 +endi +sql SELECT INTERP(c1) FROM tb1 EVERY(1s) FILL(LINEAR) ORDER BY ts DESC; +if $rows != 22 then + return -1 +endi +if $data00 != @21-10-20 10:00:21.000@ then + return -1 +endi +if $data01 != 21 then + return -1 +endi +if $data10 != @21-10-20 10:00:20.000@ then + return -1 +endi +if $data11 != 20 then + return -1 +endi +if $data20 != @21-10-20 10:00:19.000@ then + return -1 +endi +if $data21 != 19 then + return -1 +endi +if $data80 != @21-10-20 10:00:13.000@ then + return -1 +endi +if $data81 != 13 then + return -1 +endi +if $data90 != @21-10-20 10:00:12.000@ then + return -1 +endi +if $data91 != 12 then + return -1 +endi +sql SELECT INTERP(c1) FROM tb1 EVERY(1s) FILL(NEXT) ORDER BY ts DESC; +if $rows != 22 then + return -1 +endi +if $data00 != @21-10-20 10:00:21.000@ then + return -1 +endi +if $data01 != 21 then + return -1 +endi +if $data10 != @21-10-20 10:00:20.000@ then + return -1 +endi +if $data11 != 21 then + return -1 +endi +if $data20 != @21-10-20 10:00:19.000@ then + return -1 +endi +if $data21 != 21 then + return -1 +endi +if $data30 != @21-10-20 10:00:18.000@ then + return -1 +endi +if $data31 != 21 then + return -1 +endi +if $data40 != @21-10-20 10:00:17.000@ then + return -1 +endi +if $data41 != 21 then + return -1 +endi +if $data50 != @21-10-20 10:00:16.000@ then + return -1 +endi +if $data51 != 21 then + return -1 +endi +if $data60 != @21-10-20 10:00:15.000@ then + return -1 +endi +if $data61 != 15 then + return -1 +endi +if $data70 != @21-10-20 10:00:14.000@ then + return -1 +endi +if $data71 != 15 then + return -1 +endi +if $data80 != @21-10-20 10:00:13.000@ then + return -1 +endi +if $data81 != 15 then + return -1 +endi +if $data90 != @21-10-20 10:00:12.000@ then + return -1 +endi +if $data91 != 15 then + return -1 +endi +sql SELECT INTERP(c1) FROM tb1 EVERY(1s) FILL(NEXT) ORDER BY ts DESC limit 10 offset 10; +if $rows != 10 then + return -1 +endi +if $data00 != @21-10-20 10:00:11.000@ then + return -1 +endi +if $data01 != 15 then + return -1 +endi +if $data10 != @21-10-20 10:00:10.000@ then + return -1 +endi +if $data11 != 10 then + return -1 +endi +if $data20 != @21-10-20 10:00:09.000@ then + return -1 +endi +if $data21 != 10 then + return -1 +endi +if $data30 != @21-10-20 10:00:08.000@ then + return -1 +endi +if $data31 != 10 then + return -1 +endi +if $data40 != @21-10-20 10:00:07.000@ then + return -1 +endi +if $data41 != 10 then + return -1 +endi +if $data50 != @21-10-20 10:00:06.000@ then + return -1 +endi +if $data51 != 6 then + return -1 +endi +if $data60 != @21-10-20 10:00:05.000@ then + return -1 +endi +if $data61 != 6 then + return -1 +endi +if $data70 != @21-10-20 10:00:04.000@ then + return -1 +endi +if $data71 != 6 then + return -1 +endi +if $data80 != @21-10-20 10:00:03.000@ then + return -1 +endi +if $data81 != 3 then + return -1 +endi +if $data90 != @21-10-20 10:00:02.000@ then + return -1 +endi +if $data91 != 3 then + return -1 +endi +sql SELECT INTERP(c1) FROM tb1 EVERY(1s) FILL(PREV) ORDER BY ts DESC; +if $rows != 22 then + return -1 +endi +if $data00 != @21-10-20 10:00:21.000@ then + return -1 +endi +if $data01 != 21 then + return -1 +endi +if $data10 != @21-10-20 10:00:20.000@ then + return -1 +endi +if $data11 != 15 then + return -1 +endi +if $data20 != @21-10-20 10:00:19.000@ then + return -1 +endi +if $data21 != 15 then + return -1 +endi +if $data30 != @21-10-20 10:00:18.000@ then + return -1 +endi +if $data31 != 15 then + return -1 +endi +if $data40 != @21-10-20 10:00:17.000@ then + return -1 +endi +if $data41 != 15 then + return -1 +endi +if $data50 != @21-10-20 10:00:16.000@ then + return -1 +endi +if $data51 != 15 then + return -1 +endi +if $data60 != @21-10-20 10:00:15.000@ then + return -1 +endi +if $data61 != 15 then + return -1 +endi +if $data70 != @21-10-20 10:00:14.000@ then + return -1 +endi +if $data71 != 10 then + return -1 +endi +if $data80 != @21-10-20 10:00:13.000@ then + return -1 +endi +if $data81 != 10 then + return -1 +endi +if $data90 != @21-10-20 10:00:12.000@ then + return -1 +endi +if $data91 != 10 then + return -1 +endi +sql SELECT INTERP(c1) FROM tb1 EVERY(1s) FILL(PREV) ORDER BY ts DESC limit 10 offset 10; +if $rows != 10 then + return -1 +endi +if $data00 != @21-10-20 10:00:11.000@ then + return -1 +endi +if $data01 != 10 then + return -1 +endi +if $data10 != @21-10-20 10:00:10.000@ then + return -1 +endi +if $data11 != 10 then + return -1 +endi +if $data20 != @21-10-20 10:00:09.000@ then + return -1 +endi +if $data21 != 6 then + return -1 +endi +if $data30 != @21-10-20 10:00:08.000@ then + return -1 +endi +if $data31 != 6 then + return -1 +endi +if $data40 != @21-10-20 10:00:07.000@ then + return -1 +endi +if $data41 != 6 then + return -1 +endi +if $data50 != @21-10-20 10:00:06.000@ then + return -1 +endi +if $data51 != 6 then + return -1 +endi +if $data60 != @21-10-20 10:00:05.000@ then + return -1 +endi +if $data61 != 3 then + return -1 +endi +if $data70 != @21-10-20 10:00:04.000@ then + return -1 +endi +if $data71 != 3 then + return -1 +endi +if $data80 != @21-10-20 10:00:03.000@ then + return -1 +endi +if $data81 != 3 then + return -1 +endi +if $data90 != @21-10-20 10:00:02.000@ then + return -1 +endi +if $data91 != 1 then + return -1 +endi +sql SELECT INTERP(c1) FROM tb1 EVERY(1s) FILL(PREV) ORDER BY ts DESC limit 10 offset 20; +if $rows != 2 then + return -1 +endi +if $data00 != @21-10-20 10:00:01.000@ then + return -1 +endi +if $data01 != 1 then + return -1 +endi +if $data10 != @21-10-20 10:00:00.000@ then + return -1 +endi +if $data11 != 0 then + return -1 +endi +sql SELECT INTERP(c1) FROM tb1 EVERY(1s) FILL(VALUE,100) ORDER BY ts DESC; +if $rows != 22 then + return -1 +endi +if $data00 != @21-10-20 10:00:21.000@ then + return -1 +endi +if $data01 != 21 then + return -1 +endi +if $data10 != @21-10-20 10:00:20.000@ then + return -1 +endi +if $data11 != 100 then + return -1 +endi +if $data20 != @21-10-20 10:00:19.000@ then + return -1 +endi +if $data21 != 100 then + return -1 +endi +if $data30 != @21-10-20 10:00:18.000@ then + return -1 +endi +if $data31 != 100 then + return -1 +endi +if $data40 != @21-10-20 10:00:17.000@ then + return -1 +endi +if $data41 != 100 then + return -1 +endi +if $data50 != @21-10-20 10:00:16.000@ then + return -1 +endi +if $data51 != 100 then + return -1 +endi +if $data60 != @21-10-20 10:00:15.000@ then + return -1 +endi +if $data61 != 15 then + return -1 +endi +if $data70 != @21-10-20 10:00:14.000@ then + return -1 +endi +if $data71 != 100 then + return -1 +endi +if $data80 != @21-10-20 10:00:13.000@ then + return -1 +endi +if $data81 != 100 then + return -1 +endi +if $data90 != @21-10-20 10:00:12.000@ then + return -1 +endi +if $data91 != 100 then + return -1 +endi +sql SELECT INTERP(c1) FROM tb1 EVERY(1s) FILL(NULL) ORDER BY ts DESC; +if $rows != 22 then + return -1 +endi +if $data00 != @21-10-20 10:00:21.000@ then + return -1 +endi +if $data01 != 21 then + return -1 +endi +if $data10 != @21-10-20 10:00:20.000@ then + return -1 +endi +if $data11 != NULL then + return -1 +endi +if $data20 != @21-10-20 10:00:19.000@ then + return -1 +endi +if $data21 != NULL then + return -1 +endi +if $data30 != @21-10-20 10:00:18.000@ then + return -1 +endi +if $data31 != NULL then + return -1 +endi +if $data40 != @21-10-20 10:00:17.000@ then + return -1 +endi +if $data41 != NULL then + return -1 +endi +if $data50 != @21-10-20 10:00:16.000@ then + return -1 +endi +if $data51 != NULL then + return -1 +endi +if $data60 != @21-10-20 10:00:15.000@ then + return -1 +endi +if $data61 != 15 then + return -1 +endi +if $data70 != @21-10-20 10:00:14.000@ then + return -1 +endi +if $data71 != NULL then + return -1 +endi +if $data80 != @21-10-20 10:00:13.000@ then + return -1 +endi +if $data81 != NULL then + return -1 +endi +if $data90 != @21-10-20 10:00:12.000@ then + return -1 +endi +if $data91 != NULL then + return -1 +endi +sql SELECT INTERP(c1) FROM tb1 EVERY(5s) FILL(LINEAR) ORDER BY ts DESC; +if $rows != 5 then + return -1 +endi +if $data40 != @21-10-20 10:00:00.000@ then + return -1 +endi +if $data41 != 0 then + return -1 +endi +if $data30 != @21-10-20 10:00:05.000@ then + return -1 +endi +if $data31 != 5 then + return -1 +endi +if $data20 != @21-10-20 10:00:10.000@ then + return -1 +endi +if $data21 != 10 then + return -1 +endi +if $data10 != @21-10-20 10:00:15.000@ then + return -1 +endi +if $data11 != 15 then + return -1 +endi +if $data00 != @21-10-20 10:00:20.000@ then + return -1 +endi +if $data01 != 20 then + return -1 +endi +sql SELECT INTERP(c1) FROM tb1 EVERY(5s) FILL(NEXT) ORDER BY ts DESC; +if $rows != 5 then + return -1 +endi +if $data40 != @21-10-20 10:00:00.000@ then + return -1 +endi +if $data41 != 0 then + return -1 +endi +if $data30 != @21-10-20 10:00:05.000@ then + return -1 +endi +if $data31 != 6 then + return -1 +endi +if $data20 != @21-10-20 10:00:10.000@ then + return -1 +endi +if $data21 != 10 then + return -1 +endi +if $data10 != @21-10-20 10:00:15.000@ then + return -1 +endi +if $data11 != 15 then + return -1 +endi +if $data00 != @21-10-20 10:00:20.000@ then + return -1 +endi +if $data01 != 21 then + return -1 +endi +sql SELECT INTERP(c1) FROM tb1 EVERY(5s) FILL(PREV) ORDER BY ts DESC; +if $rows != 5 then + return -1 +endi +if $data40 != @21-10-20 10:00:00.000@ then + return -1 +endi +if $data41 != 0 then + return -1 +endi +if $data30 != @21-10-20 10:00:05.000@ then + return -1 +endi +if $data31 != 3 then + return -1 +endi +if $data20 != @21-10-20 10:00:10.000@ then + return -1 +endi +if $data21 != 10 then + return -1 +endi +if $data10 != @21-10-20 10:00:15.000@ then + return -1 +endi +if $data11 != 15 then + return -1 +endi +if $data00 != @21-10-20 10:00:20.000@ then + return -1 +endi +if $data01 != 15 then + return -1 +endi +sql SELECT INTERP(c1) FROM tb1 EVERY(5s) FILL(VALUE,100) ORDER BY ts DESC; +if $rows != 5 then + return -1 +endi +if $data40 != @21-10-20 10:00:00.000@ then + return -1 +endi +if $data41 != 0 then + return -1 +endi +if $data30 != @21-10-20 10:00:05.000@ then + return -1 +endi +if $data31 != 100 then + return -1 +endi +if $data20 != @21-10-20 10:00:10.000@ then + return -1 +endi +if $data21 != 10 then + return -1 +endi +if $data10 != @21-10-20 10:00:15.000@ then + return -1 +endi +if $data11 != 15 then + return -1 +endi +if $data00 != @21-10-20 10:00:20.000@ then + return -1 +endi +if $data01 != 100 then + return -1 +endi + +sql SELECT INTERP(c1) FROM tb1 EVERY(5s) FILL(NULL) ORDER BY ts DESC; +if $rows != 5 then + return -1 +endi +if $data40 != @21-10-20 10:00:00.000@ then + return -1 +endi +if $data41 != 0 then + return -1 +endi +if $data30 != @21-10-20 10:00:05.000@ then + return -1 +endi +if $data31 != NULL then + return -1 +endi +if $data20 != @21-10-20 10:00:10.000@ then + return -1 +endi +if $data21 != 10 then + return -1 +endi +if $data10 != @21-10-20 10:00:15.000@ then + return -1 +endi +if $data11 != 15 then + return -1 +endi +if $data00 != @21-10-20 10:00:20.000@ then + return -1 +endi +if $data01 != NULL then + return -1 +endi +sql SELECT INTERP(c1) FROM tb1 RANGE('2021-10-20 09:00:00','2021-10-20 14:00:00') EVERY(1s) FILL(LINEAR) ORDER BY ts DESC; +if $rows != 22 then + return -1 +endi +if $data00 != @21-10-20 10:00:21.000@ then + return -1 +endi +if $data01 != 21 then + return -1 +endi +if $data10 != @21-10-20 10:00:20.000@ then + return -1 +endi +if $data11 != 20 then + return -1 +endi +if $data20 != @21-10-20 10:00:19.000@ then + return -1 +endi +if $data21 != 19 then + return -1 +endi +if $data30 != @21-10-20 10:00:18.000@ then + return -1 +endi +if $data31 != 18 then + return -1 +endi +if $data40 != @21-10-20 10:00:17.000@ then + return -1 +endi +if $data41 != 17 then + return -1 +endi +if $data50 != @21-10-20 10:00:16.000@ then + return -1 +endi +if $data51 != 16 then + return -1 +endi +if $data60 != @21-10-20 10:00:15.000@ then + return -1 +endi +if $data61 != 15 then + return -1 +endi +if $data70 != @21-10-20 10:00:14.000@ then + return -1 +endi +if $data71 != 14 then + return -1 +endi +if $data80 != @21-10-20 10:00:13.000@ then + return -1 +endi +if $data81 != 13 then + return -1 +endi +if $data90 != @21-10-20 10:00:12.000@ then + return -1 +endi +if $data91 != 12 then + return -1 +endi + +sql SELECT INTERP(c1) FROM tb1 RANGE('2021-10-20 09:00:00','2021-10-20 14:00:00') EVERY(1s) FILL(LINEAR) ORDER BY ts DESC limit 20 offset 10; +if $rows != 12 then + return -1 +endi +if $data00 != @21-10-20 10:00:11.000@ then + return -1 +endi +if $data01 != 11 then + return -1 +endi +if $data10 != @21-10-20 10:00:10.000@ then + return -1 +endi +if $data11 != 10 then + return -1 +endi +if $data20 != @21-10-20 10:00:09.000@ then + return -1 +endi +if $data21 != 9 then + return -1 +endi +if $data30 != @21-10-20 10:00:08.000@ then + return -1 +endi +if $data31 != 8 then + return -1 +endi +if $data40 != @21-10-20 10:00:07.000@ then + return -1 +endi +if $data41 != 7 then + return -1 +endi +if $data50 != @21-10-20 10:00:06.000@ then + return -1 +endi +if $data51 != 6 then + return -1 +endi +if $data60 != @21-10-20 10:00:05.000@ then + return -1 +endi +if $data61 != 5 then + return -1 +endi +if $data70 != @21-10-20 10:00:04.000@ then + return -1 +endi +if $data71 != 4 then + return -1 +endi +if $data80 != @21-10-20 10:00:03.000@ then + return -1 +endi +if $data81 != 3 then + return -1 +endi +if $data90 != @21-10-20 10:00:02.000@ then + return -1 +endi +if $data91 != 2 then + return -1 +endi + +sql SELECT INTERP(c1) FROM tb1 RANGE('2021-10-20 09:00:00','2021-10-20 09:00:01') EVERY(1s) FILL(LINEAR) ORDER BY ts DESC; +if $rows != 0 then + return -1 +endi +sql SELECT INTERP(c1) FROM tb1 RANGE('2021-10-20 10:00:00','2021-10-20 10:00:00') EVERY(1s) FILL(LINEAR) ORDER BY ts DESC; +if $rows != 1 then + return -1 +endi +if $data00 != @21-10-20 10:00:00.000@ then + return -1 +endi +if $data01 != 0 then + return -1 +endi + + +sql SELECT INTERP(c1) FROM tb1 RANGE('2021-10-20 10:00:04','2021-10-20 14:00:00') EVERY(1s) FILL(LINEAR) ORDER BY ts DESC; +if $rows != 18 then + return -1 +endi +if $data00 != @21-10-20 10:00:21.000@ then + return -1 +endi +if $data01 != 21 then + return -1 +endi +if $data10 != @21-10-20 10:00:20.000@ then + return -1 +endi +if $data11 != 20 then + return -1 +endi +if $data20 != @21-10-20 10:00:19.000@ then + return -1 +endi +if $data21 != 19 then + return -1 +endi +if $data30 != @21-10-20 10:00:18.000@ then + return -1 +endi +if $data31 != 18 then + return -1 +endi +if $data40 != @21-10-20 10:00:17.000@ then + return -1 +endi +if $data41 != 17 then + return -1 +endi +if $data50 != @21-10-20 10:00:16.000@ then + return -1 +endi +if $data51 != 16 then + return -1 +endi +if $data60 != @21-10-20 10:00:15.000@ then + return -1 +endi +if $data61 != 15 then + return -1 +endi +if $data70 != @21-10-20 10:00:14.000@ then + return -1 +endi +if $data71 != 14 then + return -1 +endi +if $data80 != @21-10-20 10:00:13.000@ then + return -1 +endi +if $data81 != 13 then + return -1 +endi +if $data90 != @21-10-20 10:00:12.000@ then + return -1 +endi +if $data91 != 12 then + return -1 +endi + +sql SELECT INTERP(c1) FROM tb1 RANGE('2021-10-20 11:00:00','2021-10-20 14:00:00') EVERY(1s) FILL(LINEAR) ORDER BY ts DESC; +if $rows != 0 then + return -1 +endi + +sql SELECT INTERP(c1) FROM tb1 RANGE('2021-10-20 09:00:00','2021-10-20 14:00:00') EVERY(1s) FILL(NEXT) ORDER BY ts DESC; +if $rows != 3622 then + return -1 +endi +if $data00 != @21-10-20 10:00:21.000@ then + return -1 +endi +if $data01 != 21 then + return -1 +endi +if $data10 != @21-10-20 10:00:20.000@ then + return -1 +endi +if $data11 != 21 then + return -1 +endi +if $data20 != @21-10-20 10:00:19.000@ then + return -1 +endi +if $data21 != 21 then + return -1 +endi +if $data30 != @21-10-20 10:00:18.000@ then + return -1 +endi +if $data31 != 21 then + return -1 +endi +if $data40 != @21-10-20 10:00:17.000@ then + return -1 +endi +if $data41 != 21 then + return -1 +endi +if $data50 != @21-10-20 10:00:16.000@ then + return -1 +endi +if $data51 != 21 then + return -1 +endi +if $data60 != @21-10-20 10:00:15.000@ then + return -1 +endi +if $data61 != 15 then + return -1 +endi +if $data70 != @21-10-20 10:00:14.000@ then + return -1 +endi +if $data71 != 15 then + return -1 +endi +if $data80 != @21-10-20 10:00:13.000@ then + return -1 +endi +if $data81 != 15 then + return -1 +endi +if $data90 != @21-10-20 10:00:12.000@ then + return -1 +endi +if $data91 != 15 then + return -1 +endi + +sql SELECT INTERP(c1) FROM tb1 RANGE('2021-10-20 09:00:00','2021-10-20 14:00:00') EVERY(1s) FILL(NEXT) ORDER BY ts DESC limit 20 offset 10 ; +if $rows != 20 then + return -1 +endi +if $data00 != @21-10-20 10:00:11.000@ then + return -1 +endi +if $data01 != 15 then + return -1 +endi +if $data10 != @21-10-20 10:00:10.000@ then + return -1 +endi +if $data11 != 10 then + return -1 +endi +if $data20 != @21-10-20 10:00:09.000@ then + return -1 +endi +if $data21 != 10 then + return -1 +endi +if $data30 != @21-10-20 10:00:08.000@ then + return -1 +endi +if $data31 != 10 then + return -1 +endi +if $data40 != @21-10-20 10:00:07.000@ then + return -1 +endi +if $data41 != 10 then + return -1 +endi +if $data50 != @21-10-20 10:00:06.000@ then + return -1 +endi +if $data51 != 6 then + return -1 +endi +if $data60 != @21-10-20 10:00:05.000@ then + return -1 +endi +if $data61 != 6 then + return -1 +endi +if $data70 != @21-10-20 10:00:04.000@ then + return -1 +endi +if $data71 != 6 then + return -1 +endi +if $data80 != @21-10-20 10:00:03.000@ then + return -1 +endi +if $data81 != 3 then + return -1 +endi +if $data90 != @21-10-20 10:00:02.000@ then + return -1 +endi +if $data91 != 3 then + return -1 +endi + +sql SELECT INTERP(c1) FROM tb1 RANGE('2021-10-20 09:00:00','2021-10-20 14:00:00') EVERY(1s) FILL(NEXT) ORDER BY ts DESC limit 20 offset 20 ; +if $rows != 20 then + return -1 +endi +if $data00 != @21-10-20 10:00:01.000@ then + return -1 +endi +if $data01 != 1 then + return -1 +endi +if $data10 != @21-10-20 10:00:00.000@ then + return -1 +endi +if $data11 != 0 then + return -1 +endi +if $data20 != @21-10-20 09:59:59.000@ then + return -1 +endi +if $data21 != 0 then + return -1 +endi +if $data30 != @21-10-20 09:59:58.000@ then + return -1 +endi +if $data31 != 0 then + return -1 +endi +if $data40 != @21-10-20 09:59:57.000@ then + return -1 +endi +if $data41 != 0 then + return -1 +endi +if $data50 != @21-10-20 09:59:56.000@ then + return -1 +endi +if $data51 != 0 then + return -1 +endi +if $data60 != @21-10-20 09:59:55.000@ then + return -1 +endi +if $data61 != 0 then + return -1 +endi +if $data70 != @21-10-20 09:59:54.000@ then + return -1 +endi +if $data71 != 0 then + return -1 +endi +if $data80 != @21-10-20 09:59:53.000@ then + return -1 +endi +if $data81 != 0 then + return -1 +endi +if $data90 != @21-10-20 09:59:52.000@ then + return -1 +endi +if $data91 != 0 then + return -1 +endi + +sql SELECT INTERP(c1) FROM tb1 RANGE('2021-10-20 09:00:00','2021-10-20 09:00:01') EVERY(1s) FILL(NEXT) ORDER BY ts DESC; +if $rows != 2 then + return -1 +endi +if $data00 != @21-10-20 09:00:01.000@ then + return -1 +endi +if $data01 != 0 then + return -1 +endi +if $data10 != @21-10-20 09:00:00.000@ then + return -1 +endi +if $data11 != 0 then + return -1 +endi + +sql SELECT INTERP(c1) FROM tb1 RANGE('2021-10-20 10:00:00','2021-10-20 10:00:00') EVERY(1s) FILL(NEXT) ORDER BY ts DESC; +if $rows != 1 then + return -1 +endi +if $data00 != @21-10-20 10:00:00.000@ then + return -1 +endi +if $data01 != 0 then + return -1 +endi + +sql SELECT INTERP(c1) FROM tb1 RANGE('2021-10-20 10:00:04','2021-10-20 14:00:00') EVERY(1s) FILL(NEXT) ORDER BY ts DESC; +if $rows != 18 then + return -1 +endi +if $data00 != @21-10-20 10:00:21.000@ then + return -1 +endi +if $data01 != 21 then + return -1 +endi +if $data10 != @21-10-20 10:00:20.000@ then + return -1 +endi +if $data11 != 21 then + return -1 +endi +if $data20 != @21-10-20 10:00:19.000@ then + return -1 +endi +if $data21 != 21 then + return -1 +endi +if $data30 != @21-10-20 10:00:18.000@ then + return -1 +endi +if $data31 != 21 then + return -1 +endi +if $data40 != @21-10-20 10:00:17.000@ then + return -1 +endi +if $data41 != 21 then + return -1 +endi +if $data50 != @21-10-20 10:00:16.000@ then + return -1 +endi +if $data51 != 21 then + return -1 +endi +if $data60 != @21-10-20 10:00:15.000@ then + return -1 +endi +if $data61 != 15 then + return -1 +endi +if $data70 != @21-10-20 10:00:14.000@ then + return -1 +endi +if $data71 != 15 then + return -1 +endi +if $data80 != @21-10-20 10:00:13.000@ then + return -1 +endi +if $data81 != 15 then + return -1 +endi +if $data90 != @21-10-20 10:00:12.000@ then + return -1 +endi +if $data91 != 15 then + return -1 +endi + +sql SELECT INTERP(c1) FROM tb1 RANGE('2021-10-20 11:00:00','2021-10-20 14:00:00') EVERY(1s) FILL(NEXT) ORDER BY ts DESC; +if $rows != 0 then + return -1 +endi + +sql SELECT INTERP(c1) FROM tb1 RANGE('2021-10-20 09:00:00','2021-10-20 14:00:00') EVERY(1s) FILL(PREV) ORDER BY ts DESC; +if $rows != 14401 then + return -1 +endi +if $data00 != @21-10-20 14:00:00.000@ then + return -1 +endi +if $data01 != 21 then + return -1 +endi +if $data10 != @21-10-20 13:59:59.000@ then + return -1 +endi +if $data11 != 21 then + return -1 +endi +if $data20 != @21-10-20 13:59:58.000@ then + return -1 +endi +if $data21 != 21 then + return -1 +endi +if $data30 != @21-10-20 13:59:57.000@ then + return -1 +endi +if $data31 != 21 then + return -1 +endi +if $data40 != @21-10-20 13:59:56.000@ then + return -1 +endi +if $data41 != 21 then + return -1 +endi +if $data50 != @21-10-20 13:59:55.000@ then + return -1 +endi +if $data51 != 21 then + return -1 +endi +if $data60 != @21-10-20 13:59:54.000@ then + return -1 +endi +if $data61 != 21 then + return -1 +endi +if $data70 != @21-10-20 13:59:53.000@ then + return -1 +endi +if $data71 != 21 then + return -1 +endi +if $data80 != @21-10-20 13:59:52.000@ then + return -1 +endi +if $data81 != 21 then + return -1 +endi +if $data90 != @21-10-20 13:59:51.000@ then + return -1 +endi +if $data91 != 21 then + return -1 +endi + +sql SELECT INTERP(c1) FROM tb1 RANGE('2021-10-20 09:00:00','2021-10-20 14:00:00') EVERY(1s) FILL(PREV) ORDER BY ts DESC limit 30 offset 14379; +if $rows != 22 then + return -1 +endi +if $data00 != @21-10-20 10:00:21.000@ then + return -1 +endi +if $data01 != 21 then + return -1 +endi +if $data10 != @21-10-20 10:00:20.000@ then + return -1 +endi +if $data11 != 15 then + return -1 +endi +if $data20 != @21-10-20 10:00:19.000@ then + return -1 +endi +if $data21 != 15 then + return -1 +endi +if $data30 != @21-10-20 10:00:18.000@ then + return -1 +endi +if $data31 != 15 then + return -1 +endi +if $data40 != @21-10-20 10:00:17.000@ then + return -1 +endi +if $data41 != 15 then + return -1 +endi +if $data50 != @21-10-20 10:00:16.000@ then + return -1 +endi +if $data51 != 15 then + return -1 +endi +if $data60 != @21-10-20 10:00:15.000@ then + return -1 +endi +if $data61 != 15 then + return -1 +endi +if $data70 != @21-10-20 10:00:14.000@ then + return -1 +endi +if $data71 != 10 then + return -1 +endi +if $data80 != @21-10-20 10:00:13.000@ then + return -1 +endi +if $data81 != 10 then + return -1 +endi +if $data90 != @21-10-20 10:00:12.000@ then + return -1 +endi +if $data91 != 10 then + return -1 +endi + +sql SELECT INTERP(c1) FROM tb1 RANGE('2021-10-20 09:00:00','2021-10-20 09:00:01') EVERY(1s) FILL(PREV) ORDER BY ts DESC; +if $rows != 0 then + return -1 +endi + +sql SELECT INTERP(c1) FROM tb1 RANGE('2021-10-20 10:00:00','2021-10-20 10:00:00') EVERY(1s) FILL(PREV) ORDER BY ts DESC; +if $rows != 1 then + return -1 +endi +if $data00 != @21-10-20 10:00:00.000@ then + return -1 +endi +if $data01 != 0 then + return -1 +endi + +sql SELECT INTERP(c1) FROM tb1 RANGE('2021-10-20 10:00:04','2021-10-20 14:00:00') EVERY(1s) FILL(PREV) ORDER BY ts DESC; +if $rows != 14397 then + return -1 +endi +if $data00 != @21-10-20 14:00:00.000@ then + return -1 +endi +if $data01 != 21 then + return -1 +endi +if $data10 != @21-10-20 13:59:59.000@ then + return -1 +endi +if $data11 != 21 then + return -1 +endi + + +sql SELECT INTERP(c1) FROM tb1 RANGE('2021-10-20 10:00:04','2021-10-20 14:00:00') EVERY(1s) FILL(PREV) ORDER BY ts DESC limit 20 offset 14387; +if $rows != 10 then + return -1 +endi +if $data00 != @21-10-20 10:00:13.000@ then + return -1 +endi +if $data01 != 10 then + return -1 +endi +if $data10 != @21-10-20 10:00:12.000@ then + return -1 +endi +if $data11 != 10 then + return -1 +endi +if $data20 != @21-10-20 10:00:11.000@ then + return -1 +endi +if $data21 != 10 then + return -1 +endi +if $data30 != @21-10-20 10:00:10.000@ then + return -1 +endi +if $data31 != 10 then + return -1 +endi +if $data40 != @21-10-20 10:00:09.000@ then + return -1 +endi +if $data41 != 6 then + return -1 +endi +if $data50 != @21-10-20 10:00:08.000@ then + return -1 +endi +if $data51 != 6 then + return -1 +endi +if $data60 != @21-10-20 10:00:07.000@ then + return -1 +endi +if $data61 != 6 then + return -1 +endi +if $data70 != @21-10-20 10:00:06.000@ then + return -1 +endi +if $data71 != 6 then + return -1 +endi +if $data80 != @21-10-20 10:00:05.000@ then + return -1 +endi +if $data81 != 3 then + return -1 +endi +if $data90 != @21-10-20 10:00:04.000@ then + return -1 +endi +if $data91 != 3 then + return -1 +endi + +sql SELECT INTERP(c1) FROM tb1 RANGE('2021-10-20 11:00:00','2021-10-20 14:00:00') EVERY(1s) FILL(PREV); +sql SELECT INTERP(c1) FROM tb1 RANGE('2021-10-20 09:00:00','2021-10-20 14:00:00') EVERY(1s) FILL(VALUE,100); +sql SELECT INTERP(c1) FROM tb1 RANGE('2021-10-20 09:00:00','2021-10-20 14:00:00') EVERY(1s) FILL(VALUE,100) limit 20 offset 3600; +sql SELECT INTERP(c1) FROM tb1 RANGE('2021-10-20 09:00:00','2021-10-20 09:00:01') EVERY(1s) FILL(VALUE,100); +sql SELECT INTERP(c1) FROM tb1 RANGE('2021-10-20 10:00:00','2021-10-20 10:00:00') EVERY(1s) FILL(VALUE,100); +sql SELECT INTERP(c1) FROM tb1 RANGE('2021-10-20 10:00:04','2021-10-20 14:00:00') EVERY(1s) FILL(VALUE,100); +sql SELECT INTERP(c1) FROM tb1 RANGE('2021-10-20 11:00:00','2021-10-20 14:00:00') EVERY(1s) FILL(VALUE,100); +sql SELECT INTERP(c1) FROM tb1 RANGE('2021-10-20 09:00:00','2021-10-20 14:00:00') EVERY(1s) FILL(NULL); +sql SELECT INTERP(c1) FROM tb1 RANGE('2021-10-20 09:00:00','2021-10-20 14:00:00') EVERY(1s) FILL(NULL) limit 20 offset 3600; +sql SELECT INTERP(c1) FROM tb1 RANGE('2021-10-20 09:00:00','2021-10-20 09:00:01') EVERY(1s) FILL(NULL); +sql SELECT INTERP(c1) FROM tb1 RANGE('2021-10-20 10:00:00','2021-10-20 10:00:00') EVERY(1s) FILL(NULL); +sql SELECT INTERP(c1) FROM tb1 RANGE('2021-10-20 10:00:04','2021-10-20 14:00:00') EVERY(1s) FILL(NULL); +sql SELECT INTERP(c1) FROM tb1 RANGE('2021-10-20 11:00:00','2021-10-20 14:00:00') EVERY(1s) FILL(NULL); +sql SELECT INTERP(c1) FROM tb1 RANGE('2021-10-20 10:00:03.500','2021-10-20 14:00:00') EVERY(1s) FILL(LINEAR); +sql SELECT INTERP(c2) FROM tb1 RANGE('2021-10-20 10:00:03.500','2021-10-20 14:00:00') EVERY(1s) FILL(LINEAR); +sql SELECT INTERP(c1) FROM tb1 WHERE ts BETWEEN '2021-10-20 10:00:10' AND '2021-10-20 10:00:15' RANGE('2021-10-20 10:00:00','2021-10-20 14:00:00') EVERY(1s) FILL(LINEAR); +sql SELECT INTERP(c1) FROM tb1 WHERE ts BETWEEN '2021-10-20 10:00:10' AND '2021-10-20 10:00:11' RANGE('2021-10-20 10:00:00','2021-10-20 14:00:00') EVERY(1s) FILL(LINEAR); +sql SELECT INTERP(c1) FROM tb1 WHERE ts BETWEEN '2021-10-20 10:00:10' AND '2021-10-20 10:00:15' RANGE('2021-10-20 10:00:00','2021-10-20 14:00:00') EVERY(1s) FILL(NEXT); +sql SELECT INTERP(c1) FROM tb1 WHERE ts BETWEEN '2021-10-20 10:00:10' AND '2021-10-20 10:00:15' RANGE('2021-10-20 09:00:00','2021-10-20 09:00:10') EVERY(1s) FILL(LINEAR); +sql SELECT INTERP(c1) FROM tb1 WHERE ts BETWEEN '2021-10-20 10:00:10' AND '2021-10-20 10:00:20' RANGE('2021-10-20 10:00:05','2021-10-20 10:00:16') EVERY(1s) FILL(LINEAR); +sql SELECT INTERP(c1) FROM tb1 WHERE ts BETWEEN '2021-10-20 10:00:10' AND '2021-10-20 10:00:20' RANGE('2021-10-20 10:00:15','2021-10-20 10:00:25') EVERY(1s) FILL(LINEAR); +sql SELECT INTERP(c1) FROM tb1 WHERE ts BETWEEN '2021-10-20 10:00:10' AND '2021-10-20 10:00:20' RANGE('2021-10-20 10:00:21','2021-10-20 10:00:30') EVERY(1s) FILL(LINEAR); +sql SELECT INTERP(c1) FROM tb1 WHERE ts BETWEEN '2021-10-20 10:00:10' AND '2021-10-20 10:00:15' RANGE('2021-10-20 09:00:00','2021-10-20 09:00:10') EVERY(1s) FILL(PREV); +sql SELECT INTERP(c1) FROM tb1 WHERE ts BETWEEN '2021-10-20 10:00:10' AND '2021-10-20 10:00:20' RANGE('2021-10-20 10:00:05','2021-10-20 10:00:16') EVERY(1s) FILL(PREV); +sql SELECT INTERP(c1) FROM tb1 WHERE ts BETWEEN '2021-10-20 10:00:10' AND '2021-10-20 10:00:20' RANGE('2021-10-20 10:00:15','2021-10-20 10:00:25') EVERY(1s) FILL(PREV); +sql SELECT INTERP(c1) FROM tb1 WHERE ts BETWEEN '2021-10-20 10:00:10' AND '2021-10-20 10:00:20' RANGE('2021-10-20 10:00:21','2021-10-20 10:00:30') EVERY(1s) FILL(PREV); +sql SELECT INTERP(c1) FROM tb1 WHERE ts BETWEEN '2021-10-20 10:00:10' AND '2021-10-20 10:00:15' RANGE('2021-10-20 09:00:00','2021-10-20 09:00:10') EVERY(1s) FILL(NEXT); +sql SELECT INTERP(c1) FROM tb1 WHERE ts BETWEEN '2021-10-20 10:00:10' AND '2021-10-20 10:00:20' RANGE('2021-10-20 10:00:05','2021-10-20 10:00:16') EVERY(1s) FILL(NEXT); +sql SELECT INTERP(c1) FROM tb1 WHERE ts BETWEEN '2021-10-20 10:00:10' AND '2021-10-20 10:00:20' RANGE('2021-10-20 10:00:15','2021-10-20 10:00:25') EVERY(1s) FILL(NEXT); +sql SELECT INTERP(c1) FROM tb1 WHERE ts BETWEEN '2021-10-20 10:00:10' AND '2021-10-20 10:00:20' RANGE('2021-10-20 10:00:21','2021-10-20 10:00:30') EVERY(1s) FILL(NEXT); + +sql SELECT INTERP(c2) FROM tb4 RANGE('2021-10-20 10:00:00','2021-10-20 12:00:00') FILL(NULL) ORDER BY ts DESC; +if $rows != 0 then + return -1 +endi + +sql SELECT INTERP(c2) FROM tb4 RANGE('2021-10-20 10:00:00','2021-10-20 12:00:00') EVERY(1s) FILL(NULL) ORDER BY ts DESC; +if $rows != 0 then + return -1 +endi + +sql SELECT INTERP(c2) FROM tb4 RANGE('2021-10-20 10:00:00','2021-10-20 12:00:00') EVERY(1s) FILL(LINEAR) ORDER BY ts DESC; +if $rows != 0 then + return -1 +endi + +sql SELECT INTERP(c2) FROM tb4 RANGE('2021-10-20 10:00:00','2021-10-20 12:00:00') EVERY(1s) FILL(PREV) ORDER BY ts DESC; +if $rows != 0 then + return -1 +endi + +sql SELECT INTERP(c2) FROM tb4 RANGE('2021-10-20 10:00:00','2021-10-20 12:00:00') EVERY(1s) FILL(NEXT) ORDER BY ts DESC; +if $rows != 0 then + return -1 +endi + +sql SELECT INTERP(c2) FROM tb4 RANGE('2021-10-20 10:00:00','2021-10-20 12:00:00') EVERY(1s) FILL(VALUE,100) ORDER BY ts DESC; +if $rows != 0 then + return -1 +endi + +sql SELECT INTERP(c1) FROM stb1 RANGE('2021-10-20 10:00:00','2021-10-20 10:00:30') EVERY(1s) FILL(LINEAR) GROUP BY TBNAME ORDER BY TBNAME desc; +if $rows != 59 then + return -1 +endi +if $data00 != @21-10-20 10:00:00.000@ then + return -1 +endi +if $data01 != 0 then + return -1 +endi +if $data02 != tb3 then + return -1 +endi +if $data10 != @21-10-20 10:00:01.000@ then + return -1 +endi +if $data11 != 1 then + return -1 +endi +if $data12 != tb3 then + return -1 +endi +if $data20 != @21-10-20 10:00:02.000@ then + return -1 +endi +if $data21 != 2 then + return -1 +endi +if $data22 != tb3 then + return -1 +endi +if $data30 != @21-10-20 10:00:03.000@ then + return -1 +endi +if $data31 != 3 then + return -1 +endi +if $data32 != tb3 then + return -1 +endi +if $data40 != @21-10-20 10:00:04.000@ then + return -1 +endi +if $data41 != 4 then + return -1 +endi +if $data42 != tb3 then + return -1 +endi +if $data50 != @21-10-20 10:00:05.000@ then + return -1 +endi +if $data51 != 5 then + return -1 +endi +if $data52 != tb3 then + return -1 +endi +if $data60 != @21-10-20 10:00:06.000@ then + return -1 +endi +if $data61 != 6 then + return -1 +endi +if $data62 != tb3 then + return -1 +endi +if $data70 != @21-10-20 10:00:07.000@ then + return -1 +endi +if $data71 != 7 then + return -1 +endi +if $data72 != tb3 then + return -1 +endi +if $data80 != @21-10-20 10:00:08.000@ then + return -1 +endi +if $data81 != 8 then + return -1 +endi +if $data82 != tb3 then + return -1 +endi +if $data90 != @21-10-20 10:00:09.000@ then + return -1 +endi +if $data91 != 9 then + return -1 +endi +if $data92 != tb3 then + return -1 +endi + +sql select interp(c1) from tb1,tb2 where tb1.ts=tb2.ts; +if $rows != 1 then + return -1 +endi +if $data00 != @21-10-20 10:00:00.000@ then + return -1 +endi +if $data01 != 0 then + return -1 +endi + +sql select interp(c1) from tb1,tb2 where tb1.ts=tb2.ts range('2021-10-20 10:00:00','2021-10-20 10:00:30'); +if $rows != 1 then + return -1 +endi +if $data00 != @21-10-20 10:00:00.000@ then + return -1 +endi +if $data01 != 0 then + return -1 +endi +sql select interp(c1) from tb1,tb2 where tb1.ts=tb2.ts every(1s); +if $rows != 3 then + return -1 +endi +if $data00 != @21-10-20 10:00:00.000@ then + return -1 +endi +if $data01 != 0 then + return -1 +endi +if $data10 != @21-10-20 10:00:06.000@ then + return -1 +endi +if $data11 != 6 then + return -1 +endi +if $data20 != @21-10-20 10:00:10.000@ then + return -1 +endi +if $data21 != 10 then + return -1 +endi +sql select interp(c1) from tb1,tb2 where tb1.ts=tb2.ts fill(linear); +if $rows != 1 then + return -1 +endi +if $data00 != @21-10-20 10:00:00.000@ then + return -1 +endi +if $data01 != 0 then + return -1 +endi +sql select interp(c1) from tb1,tb2 where tb1.ts=tb2.ts range('2021-10-20 10:00:00','2021-10-20 10:00:30') fill(next); +if $rows != 1 then + return -1 +endi +if $data00 != @21-10-20 10:00:00.000@ then + return -1 +endi +if $data01 != 0 then + return -1 +endi +sql select interp(c1) from tb1,tb2 where tb1.ts=tb2.ts every(1s) fill(prev); +if $rows != 11 then + return -1 +endi +if $data00 != @21-10-20 10:00:00.000@ then + return -1 +endi +if $data01 != 0 then + return -1 +endi +if $data10 != @21-10-20 10:00:01.000@ then + return -1 +endi +if $data11 != 0 then + return -1 +endi +if $data20 != @21-10-20 10:00:02.000@ then + return -1 +endi +if $data21 != 0 then + return -1 +endi +if $data30 != @21-10-20 10:00:03.000@ then + return -1 +endi +if $data31 != 0 then + return -1 +endi +if $data40 != @21-10-20 10:00:04.000@ then + return -1 +endi +if $data41 != 0 then + return -1 +endi +if $data50 != @21-10-20 10:00:05.000@ then + return -1 +endi +if $data51 != 0 then + return -1 +endi +if $data60 != @21-10-20 10:00:06.000@ then + return -1 +endi +if $data61 != 6 then + return -1 +endi +if $data70 != @21-10-20 10:00:07.000@ then + return -1 +endi +if $data71 != 6 then + return -1 +endi +if $data80 != @21-10-20 10:00:08.000@ then + return -1 +endi +if $data81 != 6 then + return -1 +endi +if $data90 != @21-10-20 10:00:09.000@ then + return -1 +endi +if $data91 != 6 then + return -1 +endi + diff --git a/tests/script/general/parser/interp_full_test4.sim b/tests/script/general/parser/interp_full_test4.sim new file mode 100644 index 0000000000000000000000000000000000000000..70796bd8b61bdd0706474b8f1ce58b71ef2aba98 --- /dev/null +++ b/tests/script/general/parser/interp_full_test4.sim @@ -0,0 +1,1499 @@ +sleep 100 +sql connect + +sql use db; + +sql select interp(c1) from tb1,tb2 where tb1.ts=tb2.ts every(1s) fill(prev) order by ts desc; +if $rows != 11 then + return -1 +endi +if $data00 != @21-10-20 10:00:10.000@ then + return -1 +endi +if $data01 != 10 then + return -1 +endi +if $data10 != @21-10-20 10:00:09.000@ then + return -1 +endi +if $data11 != 6 then + return -1 +endi +if $data20 != @21-10-20 10:00:08.000@ then + return -1 +endi +if $data21 != 6 then + return -1 +endi +if $data30 != @21-10-20 10:00:07.000@ then + return -1 +endi +if $data31 != 6 then + return -1 +endi +if $data40 != @21-10-20 10:00:06.000@ then + return -1 +endi +if $data41 != 6 then + return -1 +endi +if $data50 != @21-10-20 10:00:05.000@ then + return -1 +endi +if $data51 != 0 then + return -1 +endi +if $data60 != @21-10-20 10:00:04.000@ then + return -1 +endi +if $data61 != 0 then + return -1 +endi +if $data70 != @21-10-20 10:00:03.000@ then + return -1 +endi +if $data71 != 0 then + return -1 +endi +if $data80 != @21-10-20 10:00:02.000@ then + return -1 +endi +if $data81 != 0 then + return -1 +endi +if $data90 != @21-10-20 10:00:01.000@ then + return -1 +endi +if $data91 != 0 then + return -1 +endi + +sql select interp(c1) from tb1,tb2 where tb1.ts=tb2.ts range('2021-10-20 10:00:00','2021-10-20 10:00:30') every(1s); +if $rows != 3 then + return -1 +endi +if $data00 != @21-10-20 10:00:00.000@ then + return -1 +endi +if $data01 != 0 then + return -1 +endi +if $data10 != @21-10-20 10:00:06.000@ then + return -1 +endi +if $data11 != 6 then + return -1 +endi +if $data20 != @21-10-20 10:00:10.000@ then + return -1 +endi +if $data21 != 10 then + return -1 +endi + +sql select interp(c1) from tb1,tb2 where tb1.ts=tb2.ts range('2021-10-20 10:00:00','2021-10-20 10:00:30') every(1s) fill(linear); +if $rows != 11 then + return -1 +endi +if $data00 != @21-10-20 10:00:00.000@ then + return -1 +endi +if $data01 != 0 then + return -1 +endi +if $data10 != @21-10-20 10:00:01.000@ then + return -1 +endi +if $data11 != 1 then + return -1 +endi +if $data20 != @21-10-20 10:00:02.000@ then + return -1 +endi +if $data21 != 2 then + return -1 +endi +if $data30 != @21-10-20 10:00:03.000@ then + return -1 +endi +if $data31 != 3 then + return -1 +endi +if $data40 != @21-10-20 10:00:04.000@ then + return -1 +endi +if $data41 != 4 then + return -1 +endi +if $data50 != @21-10-20 10:00:05.000@ then + return -1 +endi +if $data51 != 5 then + return -1 +endi +if $data60 != @21-10-20 10:00:06.000@ then + return -1 +endi +if $data61 != 6 then + return -1 +endi +if $data70 != @21-10-20 10:00:07.000@ then + return -1 +endi +if $data71 != 7 then + return -1 +endi +if $data80 != @21-10-20 10:00:08.000@ then + return -1 +endi +if $data81 != 8 then + return -1 +endi +if $data90 != @21-10-20 10:00:09.000@ then + return -1 +endi +if $data91 != 9 then + return -1 +endi + +sql select interp(c1) from tb1,tb2 where tb1.ts=tb2.ts range('2021-10-20 10:00:00','2021-10-20 10:00:30') every(1s) fill(linear) order by ts desc; +if $rows != 11 then + return -1 +endi +if $data00 != @21-10-20 10:00:10.000@ then + return -1 +endi +if $data01 != 10 then + return -1 +endi +if $data10 != @21-10-20 10:00:09.000@ then + return -1 +endi +if $data11 != 9 then + return -1 +endi +if $data20 != @21-10-20 10:00:08.000@ then + return -1 +endi +if $data21 != 8 then + return -1 +endi +if $data30 != @21-10-20 10:00:07.000@ then + return -1 +endi +if $data31 != 7 then + return -1 +endi +if $data40 != @21-10-20 10:00:06.000@ then + return -1 +endi +if $data41 != 6 then + return -1 +endi +if $data50 != @21-10-20 10:00:05.000@ then + return -1 +endi +if $data51 != 5 then + return -1 +endi +if $data60 != @21-10-20 10:00:04.000@ then + return -1 +endi +if $data61 != 4 then + return -1 +endi +if $data70 != @21-10-20 10:00:03.000@ then + return -1 +endi +if $data71 != 3 then + return -1 +endi +if $data80 != @21-10-20 10:00:02.000@ then + return -1 +endi +if $data81 != 2 then + return -1 +endi +if $data90 != @21-10-20 10:00:01.000@ then + return -1 +endi +if $data91 != 1 then + return -1 +endi + +sql select interp(c1) from tb1,tb2 where tb1.ts=tb2.ts range('2021-10-20 10:00:00','2021-10-20 10:00:30') every(1s) fill(prev); +if $rows != 31 then + return -1 +endi +if $data00 != @21-10-20 10:00:00.000@ then + return -1 +endi +if $data01 != 0 then + return -1 +endi +if $data10 != @21-10-20 10:00:01.000@ then + return -1 +endi +if $data11 != 0 then + return -1 +endi +if $data20 != @21-10-20 10:00:02.000@ then + return -1 +endi +if $data21 != 0 then + return -1 +endi +if $data30 != @21-10-20 10:00:03.000@ then + return -1 +endi +if $data31 != 0 then + return -1 +endi +if $data40 != @21-10-20 10:00:04.000@ then + return -1 +endi +if $data41 != 0 then + return -1 +endi +if $data50 != @21-10-20 10:00:05.000@ then + return -1 +endi +if $data51 != 0 then + return -1 +endi +if $data60 != @21-10-20 10:00:06.000@ then + return -1 +endi +if $data61 != 6 then + return -1 +endi +if $data70 != @21-10-20 10:00:07.000@ then + return -1 +endi +if $data71 != 6 then + return -1 +endi +if $data80 != @21-10-20 10:00:08.000@ then + return -1 +endi +if $data81 != 6 then + return -1 +endi +if $data90 != @21-10-20 10:00:09.000@ then + return -1 +endi +if $data91 != 6 then + return -1 +endi +sql select interp(c1) from tb1,tb2 where tb1.ts=tb2.ts range('2021-10-20 10:00:00','2021-10-20 10:00:30') every(1s) fill(prev) limit 30 offset 10; +if $rows != 21 then + return -1 +endi +if $data00 != @21-10-20 10:00:10.000@ then + return -1 +endi +if $data01 != 10 then + return -1 +endi +if $data10 != @21-10-20 10:00:11.000@ then + return -1 +endi +if $data11 != 10 then + return -1 +endi +if $data20 != @21-10-20 10:00:12.000@ then + return -1 +endi +if $data21 != 10 then + return -1 +endi +if $data30 != @21-10-20 10:00:13.000@ then + return -1 +endi +if $data31 != 10 then + return -1 +endi +if $data40 != @21-10-20 10:00:14.000@ then + return -1 +endi +if $data41 != 10 then + return -1 +endi +if $data50 != @21-10-20 10:00:15.000@ then + return -1 +endi +if $data51 != 10 then + return -1 +endi +if $data60 != @21-10-20 10:00:16.000@ then + return -1 +endi +if $data61 != 10 then + return -1 +endi +if $data70 != @21-10-20 10:00:17.000@ then + return -1 +endi +if $data71 != 10 then + return -1 +endi +if $data80 != @21-10-20 10:00:18.000@ then + return -1 +endi +if $data81 != 10 then + return -1 +endi +if $data90 != @21-10-20 10:00:19.000@ then + return -1 +endi +if $data91 != 10 then + return -1 +endi +sql select interp(c1) from tb1,tb2 where tb1.ts=tb2.ts range('2021-10-20 10:00:00','2021-10-20 10:00:30') every(1s) fill(prev) order by ts desc; +if $rows != 31 then + return -1 +endi +if $data00 != @21-10-20 10:00:30.000@ then + return -1 +endi +if $data01 != 10 then + return -1 +endi +if $data10 != @21-10-20 10:00:29.000@ then + return -1 +endi +if $data11 != 10 then + return -1 +endi +if $data20 != @21-10-20 10:00:28.000@ then + return -1 +endi +if $data21 != 10 then + return -1 +endi +if $data30 != @21-10-20 10:00:27.000@ then + return -1 +endi +if $data31 != 10 then + return -1 +endi +if $data40 != @21-10-20 10:00:26.000@ then + return -1 +endi +if $data41 != 10 then + return -1 +endi +if $data50 != @21-10-20 10:00:25.000@ then + return -1 +endi +if $data51 != 10 then + return -1 +endi +if $data60 != @21-10-20 10:00:24.000@ then + return -1 +endi +if $data61 != 10 then + return -1 +endi +if $data70 != @21-10-20 10:00:23.000@ then + return -1 +endi +if $data71 != 10 then + return -1 +endi +if $data80 != @21-10-20 10:00:22.000@ then + return -1 +endi +if $data81 != 10 then + return -1 +endi +if $data90 != @21-10-20 10:00:21.000@ then + return -1 +endi +if $data91 != 10 then + return -1 +endi +sql select interp(c1) from tb1,tb2 where tb1.ts=tb2.ts range('2021-10-20 10:00:00','2021-10-20 10:00:30') every(1s) fill(prev) order by ts desc limit 10 offset 21; +if $rows != 10 then + return -1 +endi +if $data00 != @21-10-20 10:00:09.000@ then + return -1 +endi +if $data01 != 6 then + return -1 +endi +if $data10 != @21-10-20 10:00:08.000@ then + return -1 +endi +if $data11 != 6 then + return -1 +endi +if $data20 != @21-10-20 10:00:07.000@ then + return -1 +endi +if $data21 != 6 then + return -1 +endi +if $data30 != @21-10-20 10:00:06.000@ then + return -1 +endi +if $data31 != 6 then + return -1 +endi +if $data40 != @21-10-20 10:00:05.000@ then + return -1 +endi +if $data41 != 0 then + return -1 +endi +if $data50 != @21-10-20 10:00:04.000@ then + return -1 +endi +if $data51 != 0 then + return -1 +endi +if $data60 != @21-10-20 10:00:03.000@ then + return -1 +endi +if $data61 != 0 then + return -1 +endi +if $data70 != @21-10-20 10:00:02.000@ then + return -1 +endi +if $data71 != 0 then + return -1 +endi +if $data80 != @21-10-20 10:00:01.000@ then + return -1 +endi +if $data81 != 0 then + return -1 +endi +if $data90 != @21-10-20 10:00:00.000@ then + return -1 +endi +if $data91 != 0 then + return -1 +endi +sql select interp(c1) from tb1,tb2 where tb1.ts=tb2.ts range('2021-10-20 10:00:00','2021-10-20 10:00:30') every(1s) fill(next); +if $rows != 11 then + return -1 +endi +if $data00 != @21-10-20 10:00:00.000@ then + return -1 +endi +if $data01 != 0 then + return -1 +endi +if $data10 != @21-10-20 10:00:01.000@ then + return -1 +endi +if $data11 != 6 then + return -1 +endi +if $data20 != @21-10-20 10:00:02.000@ then + return -1 +endi +if $data21 != 6 then + return -1 +endi +if $data30 != @21-10-20 10:00:03.000@ then + return -1 +endi +if $data31 != 6 then + return -1 +endi +if $data40 != @21-10-20 10:00:04.000@ then + return -1 +endi +if $data41 != 6 then + return -1 +endi +if $data50 != @21-10-20 10:00:05.000@ then + return -1 +endi +if $data51 != 6 then + return -1 +endi +if $data60 != @21-10-20 10:00:06.000@ then + return -1 +endi +if $data61 != 6 then + return -1 +endi +if $data70 != @21-10-20 10:00:07.000@ then + return -1 +endi +if $data71 != 10 then + return -1 +endi +if $data80 != @21-10-20 10:00:08.000@ then + return -1 +endi +if $data81 != 10 then + return -1 +endi +if $data90 != @21-10-20 10:00:09.000@ then + return -1 +endi +if $data91 != 10 then + return -1 +endi +sql select interp(c1) from tb1,tb2 where tb1.ts=tb2.ts range('2021-10-20 10:00:00','2021-10-20 10:00:30') every(1s) fill(next) order by ts desc; +if $rows != 11 then + return -1 +endi +if $data00 != @21-10-20 10:00:10.000@ then + return -1 +endi +if $data01 != 10 then + return -1 +endi +if $data10 != @21-10-20 10:00:09.000@ then + return -1 +endi +if $data11 != 10 then + return -1 +endi +if $data20 != @21-10-20 10:00:08.000@ then + return -1 +endi +if $data21 != 10 then + return -1 +endi +if $data30 != @21-10-20 10:00:07.000@ then + return -1 +endi +if $data31 != 10 then + return -1 +endi +if $data40 != @21-10-20 10:00:06.000@ then + return -1 +endi +if $data41 != 6 then + return -1 +endi +if $data50 != @21-10-20 10:00:05.000@ then + return -1 +endi +if $data51 != 6 then + return -1 +endi +if $data60 != @21-10-20 10:00:04.000@ then + return -1 +endi +if $data61 != 6 then + return -1 +endi +if $data70 != @21-10-20 10:00:03.000@ then + return -1 +endi +if $data71 != 6 then + return -1 +endi +if $data80 != @21-10-20 10:00:02.000@ then + return -1 +endi +if $data81 != 6 then + return -1 +endi +if $data90 != @21-10-20 10:00:01.000@ then + return -1 +endi +if $data91 != 6 then + return -1 +endi +sql select interp(c1) from tb1,tb2 where tb1.ts=tb2.ts range('2021-10-20 10:00:00','2021-10-20 10:00:30') every(1s) fill(NULL); +if $rows != 31 then + return -1 +endi +if $data00 != @21-10-20 10:00:00.000@ then + return -1 +endi +if $data01 != 0 then + return -1 +endi +if $data10 != @21-10-20 10:00:01.000@ then + return -1 +endi +if $data11 != NULL then + return -1 +endi +if $data20 != @21-10-20 10:00:02.000@ then + return -1 +endi +if $data21 != NULL then + return -1 +endi +if $data30 != @21-10-20 10:00:03.000@ then + return -1 +endi +if $data31 != NULL then + return -1 +endi +if $data40 != @21-10-20 10:00:04.000@ then + return -1 +endi +if $data41 != NULL then + return -1 +endi +if $data50 != @21-10-20 10:00:05.000@ then + return -1 +endi +if $data51 != NULL then + return -1 +endi +if $data60 != @21-10-20 10:00:06.000@ then + return -1 +endi +if $data61 != 6 then + return -1 +endi +if $data70 != @21-10-20 10:00:07.000@ then + return -1 +endi +if $data71 != NULL then + return -1 +endi +if $data80 != @21-10-20 10:00:08.000@ then + return -1 +endi +if $data81 != NULL then + return -1 +endi +if $data90 != @21-10-20 10:00:09.000@ then + return -1 +endi +if $data91 != NULL then + return -1 +endi +sql select interp(c1) from tb1,tb2 where tb1.ts=tb2.ts range('2021-10-20 10:00:00','2021-10-20 10:00:30') every(1s) fill(NULL) order by ts desc; +if $rows != 31 then + return -1 +endi +if $data00 != @21-10-20 10:00:30.000@ then + return -1 +endi +if $data01 != NULL then + return -1 +endi +if $data10 != @21-10-20 10:00:29.000@ then + return -1 +endi +if $data11 != NULL then + return -1 +endi +if $data20 != @21-10-20 10:00:28.000@ then + return -1 +endi +if $data21 != NULL then + return -1 +endi +if $data30 != @21-10-20 10:00:27.000@ then + return -1 +endi +if $data31 != NULL then + return -1 +endi +if $data40 != @21-10-20 10:00:26.000@ then + return -1 +endi +if $data41 != NULL then + return -1 +endi +if $data50 != @21-10-20 10:00:25.000@ then + return -1 +endi +if $data51 != NULL then + return -1 +endi +if $data60 != @21-10-20 10:00:24.000@ then + return -1 +endi +if $data61 != NULL then + return -1 +endi +if $data70 != @21-10-20 10:00:23.000@ then + return -1 +endi +if $data71 != NULL then + return -1 +endi +if $data80 != @21-10-20 10:00:22.000@ then + return -1 +endi +if $data81 != NULL then + return -1 +endi +if $data90 != @21-10-20 10:00:21.000@ then + return -1 +endi +if $data91 != NULL then + return -1 +endi + +sql select interp(c1) from tb1,tb2 where tb1.ts=tb2.ts range('2021-10-20 10:00:00','2021-10-20 10:00:30') every(1s) fill(NULL) order by ts desc limit 10 offset 21; +if $rows != 10 then + return -1 +endi +if $data00 != @21-10-20 10:00:09.000@ then + return -1 +endi +if $data01 != NULL then + return -1 +endi +if $data10 != @21-10-20 10:00:08.000@ then + return -1 +endi +if $data11 != NULL then + return -1 +endi +if $data20 != @21-10-20 10:00:07.000@ then + return -1 +endi +if $data21 != NULL then + return -1 +endi +if $data30 != @21-10-20 10:00:06.000@ then + return -1 +endi +if $data31 != 6 then + return -1 +endi +if $data40 != @21-10-20 10:00:05.000@ then + return -1 +endi +if $data41 != NULL then + return -1 +endi +if $data50 != @21-10-20 10:00:04.000@ then + return -1 +endi +if $data51 != NULL then + return -1 +endi +if $data60 != @21-10-20 10:00:03.000@ then + return -1 +endi +if $data61 != NULL then + return -1 +endi +if $data70 != @21-10-20 10:00:02.000@ then + return -1 +endi +if $data71 != NULL then + return -1 +endi +if $data80 != @21-10-20 10:00:01.000@ then + return -1 +endi +if $data81 != NULL then + return -1 +endi +if $data90 != @21-10-20 10:00:00.000@ then + return -1 +endi +if $data91 != 0 then + return -1 +endi +sql select interp(c1) from tb1,tb2 where tb1.ts=tb2.ts range('2021-10-20 10:00:00','2021-10-20 10:00:30') every(1s) fill(VALUE,100); +if $rows != 31 then + return -1 +endi +if $data00 != @21-10-20 10:00:00.000@ then + return -1 +endi +if $data01 != 0 then + return -1 +endi +if $data10 != @21-10-20 10:00:01.000@ then + return -1 +endi +if $data11 != 100 then + return -1 +endi +if $data20 != @21-10-20 10:00:02.000@ then + return -1 +endi +if $data21 != 100 then + return -1 +endi +if $data30 != @21-10-20 10:00:03.000@ then + return -1 +endi +if $data31 != 100 then + return -1 +endi +if $data40 != @21-10-20 10:00:04.000@ then + return -1 +endi +if $data41 != 100 then + return -1 +endi +if $data50 != @21-10-20 10:00:05.000@ then + return -1 +endi +if $data51 != 100 then + return -1 +endi +if $data60 != @21-10-20 10:00:06.000@ then + return -1 +endi +if $data61 != 6 then + return -1 +endi +if $data70 != @21-10-20 10:00:07.000@ then + return -1 +endi +if $data71 != 100 then + return -1 +endi +if $data80 != @21-10-20 10:00:08.000@ then + return -1 +endi +if $data81 != 100 then + return -1 +endi +if $data90 != @21-10-20 10:00:09.000@ then + return -1 +endi +if $data91 != 100 then + return -1 +endi +sql select interp(c1) from tb1,tb2 where tb1.ts=tb2.ts range('2021-10-20 10:00:00','2021-10-20 10:00:30') every(1s) fill(VALUE,100) order by ts desc limit 20 offset 20; +if $rows != 11 then + return -1 +endi +if $data00 != @21-10-20 10:00:10.000@ then + return -1 +endi +if $data01 != 10 then + return -1 +endi +if $data10 != @21-10-20 10:00:09.000@ then + return -1 +endi +if $data11 != 100 then + return -1 +endi +if $data20 != @21-10-20 10:00:08.000@ then + return -1 +endi +if $data21 != 100 then + return -1 +endi +if $data30 != @21-10-20 10:00:07.000@ then + return -1 +endi +if $data31 != 100 then + return -1 +endi +if $data40 != @21-10-20 10:00:06.000@ then + return -1 +endi +if $data41 != 6 then + return -1 +endi +if $data50 != @21-10-20 10:00:05.000@ then + return -1 +endi +if $data51 != 100 then + return -1 +endi +if $data60 != @21-10-20 10:00:04.000@ then + return -1 +endi +if $data61 != 100 then + return -1 +endi +if $data70 != @21-10-20 10:00:03.000@ then + return -1 +endi +if $data71 != 100 then + return -1 +endi +if $data80 != @21-10-20 10:00:02.000@ then + return -1 +endi +if $data81 != 100 then + return -1 +endi +if $data90 != @21-10-20 10:00:01.000@ then + return -1 +endi +if $data91 != 100 then + return -1 +endi + +sql select interp(c1) from (select ts,c1 from tb1); +if $rows != 1 then + return -1 +endi +if $data00 != @21-10-20 10:00:00.000@ then + return -1 +endi +if $data01 != 0 then + return -1 +endi + +sql select interp(c1) from (select ts,c1 from tb1 order by ts); +if $rows != 1 then + return -1 +endi +if $data00 != @21-10-20 10:00:00.000@ then + return -1 +endi +if $data01 != 0 then + return -1 +endi + + +sql select interp(a) from (select sum(c1) as a from stb1 interval(1s)); +if $rows != 1 then + return -1 +endi +if $data00 != @21-10-20 10:00:00.000@ then + return -1 +endi +if $data01 != 0 then + return -1 +endi + +sql select interp(a) from (select top(c1,3) as a from tb1 order by ts) every(1s) fill(prev); +if $rows != 12 then + return -1 +endi +if $data00 != @21-10-20 10:00:10.000@ then + return -1 +endi +if $data01 != 10 then + return -1 +endi +if $data10 != @21-10-20 10:00:11.000@ then + return -1 +endi +if $data11 != 10 then + return -1 +endi +if $data20 != @21-10-20 10:00:12.000@ then + return -1 +endi +if $data21 != 10 then + return -1 +endi +if $data30 != @21-10-20 10:00:13.000@ then + return -1 +endi +if $data31 != 10 then + return -1 +endi +if $data40 != @21-10-20 10:00:14.000@ then + return -1 +endi +if $data41 != 10 then + return -1 +endi +if $data50 != @21-10-20 10:00:15.000@ then + return -1 +endi +if $data51 != 15 then + return -1 +endi +if $data60 != @21-10-20 10:00:16.000@ then + return -1 +endi +if $data61 != 15 then + return -1 +endi +if $data70 != @21-10-20 10:00:17.000@ then + return -1 +endi +if $data71 != 15 then + return -1 +endi +if $data80 != @21-10-20 10:00:18.000@ then + return -1 +endi +if $data81 != 15 then + return -1 +endi +if $data90 != @21-10-20 10:00:19.000@ then + return -1 +endi +if $data91 != 15 then + return -1 +endi + +sql select interp(a) from (select max(c1) as a from tb1 interval(6s)) every(1s) fill(next); +if $rows != 19 then + return -1 +endi +if $data00 != @21-10-20 10:00:00.000@ then + return -1 +endi +if $data01 != 3 then + return -1 +endi +if $data10 != @21-10-20 10:00:01.000@ then + return -1 +endi +if $data11 != 10 then + return -1 +endi +if $data20 != @21-10-20 10:00:02.000@ then + return -1 +endi +if $data21 != 10 then + return -1 +endi +if $data30 != @21-10-20 10:00:03.000@ then + return -1 +endi +if $data31 != 10 then + return -1 +endi +if $data40 != @21-10-20 10:00:04.000@ then + return -1 +endi +if $data41 != 10 then + return -1 +endi +if $data50 != @21-10-20 10:00:05.000@ then + return -1 +endi +if $data51 != 10 then + return -1 +endi +if $data60 != @21-10-20 10:00:06.000@ then + return -1 +endi +if $data61 != 10 then + return -1 +endi +if $data70 != @21-10-20 10:00:07.000@ then + return -1 +endi +if $data71 != 15 then + return -1 +endi +if $data80 != @21-10-20 10:00:08.000@ then + return -1 +endi +if $data81 != 15 then + return -1 +endi +if $data90 != @21-10-20 10:00:09.000@ then + return -1 +endi +if $data91 != 15 then + return -1 +endi + +sql select interp(a) from (select diff(c2) as a from tb1) every(1s) fill(linear); +if $rows != 21 then + return -1 +endi +if $data00 != @21-10-20 10:00:01.000@ then + return -1 +endi +if $data01 != 1.00000 then + return -1 +endi +if $data10 != @21-10-20 10:00:02.000@ then + return -1 +endi +if $data11 != 1.50000 then + return -1 +endi +if $data20 != @21-10-20 10:00:03.000@ then + return -1 +endi +if $data21 != 2.00000 then + return -1 +endi +if $data30 != @21-10-20 10:00:04.000@ then + return -1 +endi +if $data31 != 2.33333 then + return -1 +endi +if $data40 != @21-10-20 10:00:05.000@ then + return -1 +endi +if $data41 != 2.66667 then + return -1 +endi +if $data50 != @21-10-20 10:00:06.000@ then + return -1 +endi +if $data51 != 3.00000 then + return -1 +endi +if $data60 != @21-10-20 10:00:07.000@ then + return -1 +endi +if $data61 != 3.25000 then + return -1 +endi +if $data70 != @21-10-20 10:00:08.000@ then + return -1 +endi +if $data71 != 3.50000 then + return -1 +endi +if $data80 != @21-10-20 10:00:09.000@ then + return -1 +endi +if $data81 != 3.75000 then + return -1 +endi +if $data90 != @21-10-20 10:00:10.000@ then + return -1 +endi +if $data91 != 4.00000 then + return -1 +endi + +sql select interp(a) from (select sum(c2) as a from stb1 interval(6s)) RANGE('2021-10-20 10:00:05.000','2021-10-20 10:00:20.000') every(1s) fill(linear); +if $rows != 14 then + return -1 +endi +if $data00 != @21-10-20 10:00:05.000@ then + return -1 +endi +if $data01 != 42.166666667 then + return -1 +endi +if $data10 != @21-10-20 10:00:06.000@ then + return -1 +endi +if $data11 != 48.000000000 then + return -1 +endi +if $data20 != @21-10-20 10:00:07.000@ then + return -1 +endi +if $data21 != 46.833333333 then + return -1 +endi +if $data30 != @21-10-20 10:00:08.000@ then + return -1 +endi +if $data31 != 45.666666667 then + return -1 +endi +if $data40 != @21-10-20 10:00:09.000@ then + return -1 +endi +if $data41 != 44.500000000 then + return -1 +endi +if $data50 != @21-10-20 10:00:10.000@ then + return -1 +endi +if $data51 != 43.333333333 then + return -1 +endi +if $data60 != @21-10-20 10:00:11.000@ then + return -1 +endi +if $data61 != 42.166666667 then + return -1 +endi +if $data70 != @21-10-20 10:00:12.000@ then + return -1 +endi +if $data71 != 41.000000000 then + return -1 +endi +if $data80 != @21-10-20 10:00:13.000@ then + return -1 +endi +if $data81 != 44.166666667 then + return -1 +endi +if $data90 != @21-10-20 10:00:14.000@ then + return -1 +endi +if $data91 != 47.333333333 then + return -1 +endi + +sql select interp(a) from (select interp(c1) b,interp(c2) a from tb1 where ts < '2021-10-20 10:00:15.000' range('2021-10-20 10:00:05.000','2021-10-20 10:00:20.000') every(3s) fill(prev)) where ts between '2021-10-20 10:00:06.000' and '2021-10-20 10:00:18.000' range('2021-10-20 10:00:00.000','2021-10-20 10:00:25.000') every(1s) fill(linear); +if $rows != 10 then + return -1 +endi +if $data00 != @21-10-20 10:00:08.000@ then + return -1 +endi +if $data01 != 6.00000 then + return -1 +endi +if $data10 != @21-10-20 10:00:09.000@ then + return -1 +endi +if $data11 != 7.33333 then + return -1 +endi +if $data20 != @21-10-20 10:00:10.000@ then + return -1 +endi +if $data21 != 8.66667 then + return -1 +endi +if $data30 != @21-10-20 10:00:11.000@ then + return -1 +endi +if $data31 != 10.00000 then + return -1 +endi +if $data40 != @21-10-20 10:00:12.000@ then + return -1 +endi +if $data41 != 10.00000 then + return -1 +endi +if $data50 != @21-10-20 10:00:13.000@ then + return -1 +endi +if $data51 != 10.00000 then + return -1 +endi +if $data60 != @21-10-20 10:00:14.000@ then + return -1 +endi +if $data61 != 10.00000 then + return -1 +endi +if $data70 != @21-10-20 10:00:15.000@ then + return -1 +endi +if $data71 != 10.00000 then + return -1 +endi +if $data80 != @21-10-20 10:00:16.000@ then + return -1 +endi +if $data81 != 10.00000 then + return -1 +endi +if $data90 != @21-10-20 10:00:17.000@ then + return -1 +endi +if $data91 != 10.00000 then + return -1 +endi + +sql select interp(a) from (select interp(c4) a from tb1,tb4_0 where tb1.ts=tb4_0.ts every(3s) fill(linear)) every(4s) fill(prev); +if $rows != 6 then + return -1 +endi +if $data00 != @21-10-20 10:00:00.000@ then + return -1 +endi +if $data01 != 0 then + return -1 +endi +if $data10 != @21-10-20 10:00:04.000@ then + return -1 +endi +if $data11 != 3 then + return -1 +endi +if $data20 != @21-10-20 10:00:08.000@ then + return -1 +endi +if $data21 != 6 then + return -1 +endi +if $data30 != @21-10-20 10:00:12.000@ then + return -1 +endi +if $data31 != 12 then + return -1 +endi +if $data40 != @21-10-20 10:00:16.000@ then + return -1 +endi +if $data41 != 15 then + return -1 +endi +if $data50 != @21-10-20 10:00:20.000@ then + return -1 +endi +if $data51 != 18 then + return -1 +endi + +sql select interp(c4) from tb1 every(7s) fill(linear) union all select interp(c4) from tb4_0 every(33s) fill(prev); +if $rows != 13 then + return -1 +endi +if $data00 != @21-10-20 10:00:00.000@ then + return -1 +endi +if $data01 != 0 then + return -1 +endi +if $data10 != @21-10-20 10:00:07.000@ then + return -1 +endi +if $data11 != 7 then + return -1 +endi +if $data20 != @21-10-20 10:00:14.000@ then + return -1 +endi +if $data21 != 14 then + return -1 +endi +if $data30 != @21-10-20 10:00:21.000@ then + return -1 +endi +if $data31 != 21 then + return -1 +endi +if $data40 != @21-10-20 10:00:00.000@ then + return -1 +endi +if $data41 != 0 then + return -1 +endi +if $data50 != @21-10-20 10:00:33.000@ then + return -1 +endi +if $data51 != 28 then + return -1 +endi +if $data60 != @21-10-20 10:01:06.000@ then + return -1 +endi +if $data61 != 6 then + return -1 +endi +if $data70 != @21-10-20 10:01:39.000@ then + return -1 +endi +if $data71 != 36 then + return -1 +endi +if $data80 != @21-10-20 10:02:12.000@ then + return -1 +endi +if $data81 != 10 then + return -1 +endi +if $data90 != @21-10-20 10:02:45.000@ then + return -1 +endi +if $data91 != 45 then + return -1 +endi + +sql select interp(c3) from tb4_0 every(3s) fill(linear); +if $rows != 99 then + return -1 +endi +if $data00 != @21-10-20 10:00:00.000@ then + return -1 +endi +if $data01 != 0 then + return -1 +endi +if $data10 != @21-10-20 10:00:03.000@ then + return -1 +endi +if $data11 != 3 then + return -1 +endi +if $data20 != @21-10-20 10:00:06.000@ then + return -1 +endi +if $data21 != 6 then + return -1 +endi +if $data30 != @21-10-20 10:00:09.000@ then + return -1 +endi +if $data31 != 9 then + return -1 +endi +if $data40 != @21-10-20 10:00:12.000@ then + return -1 +endi +if $data41 != 12 then + return -1 +endi +if $data50 != @21-10-20 10:00:15.000@ then + return -1 +endi +if $data51 != 15 then + return -1 +endi +if $data60 != @21-10-20 10:00:18.000@ then + return -1 +endi +if $data61 != 18 then + return -1 +endi +if $data70 != @21-10-20 10:00:21.000@ then + return -1 +endi +if $data71 != 21 then + return -1 +endi +if $data80 != @21-10-20 10:00:24.000@ then + return -1 +endi +if $data81 != 24 then + return -1 +endi +if $data90 != @21-10-20 10:00:27.000@ then + return -1 +endi +if $data91 != 27 then + return -1 +endi + +sql select interp(c3) from tb4_0 every(5s) fill(linear) order by ts desc; +if $rows != 60 then + return -1 +endi + + +sql select interp(c3) from tb4_0 where ts > '2021-10-20 10:04:15.000' and ts < '2021-10-20 10:04:55.000' every(5s) fill(linear) order by ts desc; +if $rows != 5 then + return -1 +endi +if $data00 != @21-10-20 10:04:41.000@ then + return -1 +endi +if $data01 != 41 then + return -1 +endi +if $data10 != @21-10-20 10:04:36.000@ then + return -1 +endi +if $data11 != 36 then + return -1 +endi +if $data20 != @21-10-20 10:04:31.000@ then + return -1 +endi +if $data21 != 31 then + return -1 +endi +if $data30 != @21-10-20 10:04:26.000@ then + return -1 +endi +if $data31 != 26 then + return -1 +endi +if $data40 != @21-10-20 10:04:21.000@ then + return -1 +endi +if $data41 != 21 then + return -1 +endi diff --git a/tests/script/general/parser/interp_test.sim b/tests/script/general/parser/interp_test.sim deleted file mode 100644 index 8eac8a41d391508737232a3f068c477922bf77aa..0000000000000000000000000000000000000000 --- a/tests/script/general/parser/interp_test.sim +++ /dev/null @@ -1,2496 +0,0 @@ -sleep 100 -sql connect - -$dbPrefix = intp_db -$tbPrefix = intp_tb -$stbPrefix = intp_stb -$tbNum = 4 -$rowNum = 10000 -$totalNum = $tbNum * $rowNum -$ts0 = 1537146000000 -$delta = 600000 -print ========== intp_test.sim -$i = 0 -$db = $dbPrefix . $i -$stb = $stbPrefix . $i -$tsu = $rowNum * $delta -$tsu = $tsu - $delta -$tsu = $tsu + $ts0 - -print ====== use db -sql use $db - -##### select interp from table -print ====== select intp from table -$tb = $tbPrefix . 0 -## interp(*) from tb -sql select interp(*) from $tb where ts = $ts0 -if $rows != 1 then - return -1 -endi -if $data00 != @18-09-17 09:00:00.000@ then - return -1 -endi -if $data01 != 0 then - return -1 -endi -if $data02 != 0 then - return -1 -endi - -## interp + limit offset -sql select interp(*) from $tb where ts = $ts0 limit 5 offset 1 -if $rows != 0 then - return -1 -endi - -sql select interp(ts), interp(c1), interp(c2), interp(c3), interp(c4), interp(c5), interp(c6), interp(c7), interp(c8), interp(c9) from $tb where ts = $ts0 -if $rows != 1 then - return -1 -endi -if $data00 != @18-09-17 09:00:00.000@ then - return -1 -endi -if $data01 != 0 then - return -1 -endi -if $data02 != 0 then - return -1 -endi -if $data03 != 0.00000 then - return -1 -endi -if $data04 != 0.000000000 then - return -1 -endi -if $data05 != 0 then - return -1 -endi -if $data06 != 0 then - return -1 -endi -if $data07 != 1 then - return -1 -endi -if $data08 != binary0 then - return -1 -endi -if $data09 != nchar0 then - return -1 -endi - -## intp + aggregation functions -$t = $ts0 + $delta -$t = $t + $delta -sql_error select interp(ts), max(c1), min(c2), count(c3), sum(c4), avg(c5), stddev(c6), first(c7), last(c8), interp(c9) from $tb where ts = $t -sql_error select interp(ts) from $tb where ts=$ts0 interval(1s) - -### illegal queries on a table -sql_error select interp(ts), c1 from $tb where ts = $ts0 -sql_error select interp(ts) from $tb where ts >= $ts0 -sql_error select interp(ts), max(c1), min(c2), count(c3), interp(c4), interp(c5), interp(c6), interp(c7), interp(c8), interp(c9) from $tb where ts = $t fill(NULL) - -### interp from tb + fill -$t = $ts0 + 1000 -sql select interp(ts), interp(c1), interp(c2), interp(c3), interp(c4), interp(c5), interp(c6), interp(c7), interp(c8), interp(c9) from $tb where ts = $t -if $rows != 0 then - return -1 -endi - -## fill(none) -sql select interp(ts), interp(c1), interp(c2), interp(c3), interp(c4), interp(c5), interp(c6), interp(c7), interp(c8), interp(c9) from $tb where ts = $t fill(none) -if $rows != 0 then - return -1 -endi -$t = $tsu + 1000 -sql select interp(ts), interp(c1), interp(c2), interp(c3), interp(c4), interp(c5), interp(c6), interp(c7), interp(c8), interp(c9) from $tb where ts = $t fill(none) -if $rows != 0 then - return -1 -endi - -## fill(NULL) -$t = $tsu - 1000 -sql select interp(ts), interp(c1), interp(c2), interp(c3), interp(c4), interp(c5), interp(c6), interp(c7), interp(c8), interp(c9) from $tb where ts = $t fill(value, NULL) order by ts asc -if $rows != 1 then - return -1 -endi -if $data00 != @18-11-25 19:29:59.000@ then - return -1 -endi -if $data01 != NULL then - print expect NULL, actual $data01 - return -1 -endi -if $data02 != NULL then - return -1 -endi -if $data03 != NULL then - return -1 -endi -if $data04 != NULL then - return -1 -endi -if $data05 != NULL then - return -1 -endi -if $data06 != NULL then - return -1 -endi -if $data07 != NULL then - return -1 -endi -if $data08 != NULL then - return -1 -endi -if $data09 != NULL then - return -1 -endi - -$t = $tsu + 1000 -sql select interp(ts), interp(c1), interp(c2), interp(c3), interp(c4), interp(c5), interp(c6), interp(c7), interp(c8), interp(c9) from $tb where ts = $t fill(none) -if $rows != 0 then - return -1 -endi - -## fill(prev) -$t = $ts0 + 1000 -sql select interp(ts), interp(c1), interp(c2), interp(c3), interp(c4), interp(c5), interp(c6), interp(c7), interp(c8), interp(c9) from $tb where ts = $t fill(prev) -if $rows != 1 then - return -1 -endi - -sql select interp(ts), interp(c1), interp(c2), interp(c3), interp(c4), interp(c5), interp(c6), interp(c7), interp(c8), interp(c9) from $tb where ts = $ts0 fill(prev) -if $rows != 1 then - return -1 -endi -if $data00 != @18-09-17 09:00:00.000@ then - return -1 -endi -if $data01 != 0 then - return -1 -endi -if $data02 != 0 then - return -1 -endi -if $data03 != 0.00000 then - return -1 -endi -if $data04 != 0.000000000 then - return -1 -endi -if $data05 != 0 then - return -1 -endi -if $data06 != 0 then - return -1 -endi -if $data07 != 1 then - return -1 -endi -if $data08 != binary0 then - return -1 -endi -if $data09 != nchar0 then - return -1 -endi - -$t = $ts0 - 1000 -sql select interp(ts), interp(c1), interp(c2), interp(c3), interp(c4), interp(c5), interp(c6), interp(c7), interp(c8), interp(c9) from $tb where ts = $t fill(prev) -if $rows != 0 then - return -1 -endi - -$t = $ts0 + 1000 -sql select interp(ts), interp(c1), interp(c2), interp(c3), interp(c4), interp(c5), interp(c6), interp(c7), interp(c8), interp(c9) from intp_tb3 where ts = $t fill(prev) -if $rows != 1 then - return -1 -endi -if $data00 != @18-09-17 09:00:01.000@ then - return -1 -endi -if $data01 != 0 then - return -1 -endi -if $data02 != NULL then - return -1 -endi -if $data03 != 0.00000 then - print expect 0.00000, actual:$data03 - return -1 -endi -# if $data04 != NULL then -# return -1 -# endi - -$t = $tsu + 1000 -sql select interp(ts), interp(c1), interp(c2), interp(c3), interp(c4), interp(c5), interp(c6), interp(c7), interp(c8), interp(c9) from $tb where ts = $t fill(prev) -if $rows != 0 then - return -1 -endi - -## fill(linear) -$t = $ts0 + 1000 -sql select interp(ts), interp(c1), interp(c2), interp(c3), interp(c4), interp(c5), interp(c6), interp(c7), interp(c8), interp(c9) from $tb where ts = $t fill(linear) -print ====== 0:$data00, 1:$data01, 2:$data02, 3:$data03, 4:$data04, 5:$data05, 6:$data06, 7:$data07, 8:$data08, 9:$data09 -if $rows != 1 then - return -1 -endi -if $data00 != @18-09-17 09:00:01.000@ then - return -1 -endi -if $data01 != 0 then - return -1 -endi -if $data02 != 0 then - return -1 -endi -print $data03 -if $data03 != 0.00167 then - return -1 -endi -if $data04 != 0.001666667 then - return -1 -endi -if $data05 != 0 then - return -1 -endi -if $data06 != 0 then - return -1 -endi -if $data07 != NULL then - return -1 -endi -if $data08 != NULL then - return -1 -endi -if $data09 != NULL then - return -1 -endi -# columns contain NULL values -$t = $ts0 + 1000 -sql select interp(ts), interp(c1), interp(c2), interp(c3), interp(c4), interp(c5), interp(c6), interp(c7), interp(c8), interp(c9) from intp_tb3 where ts = $t fill(linear) -print ====== 0:$data00, 1:$data01, 2:$data02, 3:$data03, 4:$data04, 5:$data05, 6:$data06, 7:$data07, 8:$data08, 9:$data09 -if $rows != 1 then - return -1 -endi -if $data00 != @18-09-17 09:00:01.000@ then - return -1 -endi -if $data01 != 0 then - return -1 -endi -if $data02 != NULL then - return -1 -endi -if $data03 != 0.00167 then - return -1 -endi -if $data04 != NULL then - return -1 -endi -if $data05 != 0 then - return -1 -endi -if $data06 != 0 then - return -1 -endi -if $data07 != NULL then - return -1 -endi -if $data08 != NULL then - return -1 -endi -if $data09 != NULL then - return -1 -endi - -print select interp(ts), interp(c1), interp(c2), interp(c3), interp(c4), interp(c5), interp(c6), interp(c7), interp(c8), interp(c9) from $tb where ts = $ts0 fill(linear) - -sql select interp(ts), interp(c1), interp(c2), interp(c3), interp(c4), interp(c5), interp(c6), interp(c7), interp(c8), interp(c9) from $tb where ts = $ts0 fill(linear) -if $rows != 1 then - return -1 -endi -if $data00 != @18-09-17 09:00:00.000@ then - return -1 -endi -if $data01 != 0 then - return -1 -endi -if $data02 != 0 then - return -1 -endi -if $data03 != 0.00000 then - return -1 -endi -if $data04 != 0.000000000 then - return -1 -endi -if $data05 != 0 then - return -1 -endi -if $data06 != 0 then - return -1 -endi -if $data07 != 1 then - return -1 -endi -if $data08 != binary0 then - return -1 -endi -if $data09 != nchar0 then - return -1 -endi -# columns contain NULL values - -print select interp(ts), interp(c1), interp(c2), interp(c3), interp(c4), interp(c5), interp(c6), interp(c7), interp(c8), interp(c9) from intp_tb3 where ts = $ts0 fill(linear) -sql select interp(ts), interp(c1), interp(c2), interp(c3), interp(c4), interp(c5), interp(c6), interp(c7), interp(c8), interp(c9) from intp_tb3 where ts = $ts0 fill(linear) -if $rows != 1 then - return -1 -endi -if $data00 != @18-09-17 09:00:00.000@ then - return -1 -endi -if $data01 != 0 then - return -1 -endi -if $data02 != NULL then - return -1 -endi -if $data03 != 0.00000 then - return -1 -endi -if $data04 != NULL then - return -1 -endi -if $data05 != 0 then - return -1 -endi -if $data06 != 0 then - return -1 -endi -if $data07 != 1 then - return -1 -endi -if $data08 != binary0 then - return -1 -endi -if $data09 != nchar0 then - return -1 -endi - -$t = $ts0 - 1000 -sql select interp(ts), interp(c1), interp(c2), interp(c3), interp(c4), interp(c5), interp(c6), interp(c7), interp(c8), interp(c9) from $tb where ts = $t fill(linear) -if $rows != 0 then - return -1 -endi - -$t = $tsu + 1000 -print select interp(ts), interp(c1), interp(c2), interp(c3), interp(c4), interp(c5), interp(c6), interp(c7), interp(c8), interp(c9) from $tb where ts = $t fill(linear) -sql select interp(ts), interp(c1), interp(c2), interp(c3), interp(c4), interp(c5), interp(c6), interp(c7), interp(c8), interp(c9) from $tb where ts = $t fill(linear) -if $rows != 0 then - return -1 -endi - -## fill(value) -$t = $ts0 + 1000 -print 91 -sql select interp(ts), interp(c1), interp(c2), interp(c3), interp(c4), interp(c5), interp(c6), interp(c7), interp(c8), interp(c9) from $tb where ts = $t fill(value, -1, -2) -if $rows != 1 then - return -1 -endi -if $data00 != @18-09-17 09:00:01.000@ then - return -1 -endi -if $data01 != -2 then - return -1 -endi -if $data02 != -2 then - return -1 -endi -if $data03 != -2.00000 then - return -1 -endi -if $data04 != -2.000000000 then - return -1 -endi -if $data05 != -2 then - return -1 -endi -if $data06 != -2 then - return -1 -endi -if $data07 != 1 then - return -1 -endi -if $data08 != NULL then - return -1 -endi -if $data09 != NULL then - return -1 -endi - -sql select interp(ts), interp(c1), interp(c2), interp(c3), interp(c4), interp(c5), interp(c6), interp(c7), interp(c8), interp(c9) from $tb where ts = $ts0 fill(value, -1, -2, -3) -if $rows != 1 then - return -1 -endi -if $data00 != @18-09-17 09:00:00.000@ then - return -1 -endi -if $data01 != 0 then - return -1 -endi -if $data02 != 0 then - return -1 -endi -if $data03 != 0.00000 then - return -1 -endi -if $data04 != 0.000000000 then - return -1 -endi -if $data05 != 0 then - return -1 -endi -if $data06 != 0 then - return -1 -endi -if $data07 != 1 then - return -1 -endi -if $data08 != binary0 then - return -1 -endi -if $data09 != nchar0 then - return -1 -endi - -# table has NULL columns -sql select interp(ts), interp(c1), interp(c2), interp(c3), interp(c4), interp(c5), interp(c6), interp(c7), interp(c8), interp(c9) from intp_tb3 where ts = $ts0 fill(value, -1, -2, -3) -if $rows != 1 then - return -1 -endi -if $data00 != @18-09-17 09:00:00.000@ then - return -1 -endi -if $data01 != 0 then - return -1 -endi -if $data02 != NULL then - return -1 -endi -if $data03 != 0.00000 then - return -1 -endi -if $data04 != NULL then - return -1 -endi - -$t = $ts0 - 1000 -sql select interp(ts), interp(c1), interp(c2), interp(c3), interp(c4), interp(c5), interp(c6), interp(c7), interp(c8), interp(c9) from $tb where ts = $t fill(value, -1, -2) -if $rows != 0 then - return -1 -endi - -$t = $tsu + 1000 -sql select interp(ts), interp(c1), interp(c2), interp(c3), interp(c4), interp(c5), interp(c6), interp(c7), interp(c8), interp(c9) from $tb where ts = $t fill(value, -1, -2) -if $rows != 0 then - return -1 -endi - -### select interp from stable -## interp(*) from stb -print select interp(*) from $stb where ts = $ts0 -sql select interp(*) from $stb where ts = $ts0 -if $rows != 1 then - return -1 -endi -$t = $ts0 + 1000 -print 92 - -sql select interp(*) from $stb where ts = $t -if $rows != 0 then - return -1 -endi -## interp(*) from stb + group by -sql select interp(ts, c1, c2, c3, c4, c5, c7, c9) from $stb where ts = $ts0 group by tbname order by tbname asc -print ====== select interp(ts, c1, c2, c3, c4, c5, c7, c9) from $stb where ts = $ts0 group by tbname order by tbname asc -print ====== 0:$data00, 1:$data01, 2:$data02, 3:$data03, 4:$data04, 5:$data05, 6:$data06, 7:$data07, 8:$data08, 9:$data09 -print ====== 0:$data20, 1:$data21, 2:$data22, 3:$data23, 4:$data24, 5:$data25, 6:$data26, 7:$data27, 8:$data28, 9:$data29 -if $rows != $tbNum then - return -1 -endi -if $data00 != @18-09-17 09:00:00.000@ then - return -1 -endi -if $data01 != 0 then - return -1 -endi -if $data02 != 0 then - return -1 -endi -if $data04 != 0.000000000 then - return -1 -endi -if $data08 != intp_tb0 then - return -1 -endi -if $data22 != NULL then - return -1 -endi -if $data24 != NULL then - return -1 -endi -if $data28 != intp_tb2 then - return -1 -endi - -## interp(*) from stb + group by + limit offset -sql select interp(*) from $stb where ts = $ts0 group by tbname limit 0 -if $rows != 0 then - return -1 -endi -sql select interp(*) from $stb where ts = $ts0 group by tbname limit 0 offset 1 - -## interp(*) from stb + group by + fill(none) -$t = $ts0 + 1000 -sql select interp(*) from $stb where ts = $t fill(none) group by tbname -if $rows != 0 then - return -1 -endi - -sql select interp(*) from $stb where ts = $ts0 fill(none) group by tbname -if $rows != 4 then - return -1 -endi -if $data01 != 0 then - return -1 -endi -if $data02 != 0 then - return -1 -endi -if $data21 != 0 then - return -1 -endi -if $data22 != NULL then - return -1 -endi -if $data24 != NULL then - return -1 -endi - -## interp(*) from stb + group by + fill(none) -$t = $ts0 + 1000 -sql select interp(*) from $stb where ts = $t fill(NULL) group by tbname -if $rows != $tbNum then - return -1 -endi -if $data00 != @18-09-17 09:00:01.000@ then - return -1 -endi -if $data01 != NULL then - return -1 -endi -if $data12 != NULL then - return -1 -endi -if $data23 != NULL then - return -1 -endi -if $data34 != NULL then - return -1 -endi -if $data05 != NULL then - return -1 -endi -if $data16 != NULL then - return -1 -endi -if $data27 != NULL then - return -1 -endi -if $data38 != NULL then - return -1 -endi -if $data09 != NULL then - return -1 -endi - -sql select interp(*) from $stb where ts = $ts0 fill(NULL) group by tbname -print $rows - -if $rows != 4 then - return -1 -endi - -if $data01 != 0 then - return -1 -endi - -if $data02 != 0 then - return -1 -endi -if $data21 != 0 then - return -1 -endi -if $data22 != NULL then - return -1 -endi -if $data24 != NULL then - return -1 -endi - -## interp(*) from stb + group by + fill(prev) -$t = $ts0 + 1000 -sql select interp(*) from $stb where ts = $t fill(prev) group by tbname -print ====== 0:$data00, 1:$data01, 2:$data02, 3:$data03, 4:$data04, 5:$data05, 6:$data06, 7:$data07, 8:$data08, 9:$data09 -print ====== 0:$data20, 1:$data21, 2:$data22, 3:$data23, 4:$data24, 5:$data25, 6:$data26, 7:$data27, 8:$data28, 9:$data29 -if $rows != $tbNum then - return -1 -endi -if $data00 != @18-09-17 09:00:01.000@ then - return -1 -endi -if $data01 != 0 then - return -1 -endi -if $data02 != 0 then - return -1 -endi -if $data03 != 0.00000 then - return -1 -endi -if $data04 != 0.000000000 then - return -1 -endi -if $data05 != 0 then - return -1 -endi -if $data06 != 0 then - return -1 -endi -if $data07 != 1 then - return -1 -endi -if $data08 != binary0 then - return -1 -endi -if $data09 != nchar0 then - return -1 -endi -if $data20 != @18-09-17 09:00:01.000@ then - return -1 -endi -if $data21 != 0 then - return -1 -endi -if $data22 != NULL then - return -1 -endi -if $data23 != 0.00000 then - return -1 -endi -if $data24 != NULL then - return -1 -endi -if $data25 != 0 then - return -1 -endi -if $data26 != 0 then - return -1 -endi -if $data27 != 1 then - return -1 -endi -if $data28 != binary0 then - return -1 -endi -if $data29 != nchar0 then - return -1 -endi - -## interp(*) from stb + group by + fill(linear) -$t = $ts0 + 1000 -sql select interp(*) from $stb where ts = $t fill(linear) group by tbname -print ====== 0:$data00, 1:$data01, 2:$data02, 3:$data03, 4:$data04, 5:$data05, 6:$data06, 7:$data07, 8:$data08, 9:$data09 -print ====== 0:$data20, 1:$data21, 2:$data22, 3:$data23, 4:$data24, 5:$data25, 6:$data26, 7:$data27, 8:$data28, 9:$data29 -if $rows != $tbNum then - return -1 -endi -if $data00 != @18-09-17 09:00:01.000@ then - return -1 -endi -if $data01 != 0 then - return -1 -endi -if $data02 != 0 then - return -1 -endi -if $data03 != 0.00167 then - return -1 -endi -if $data04 != 0.001666667 then - return -1 -endi -if $data05 != 0 then - return -1 -endi -if $data06 != 0 then - return -1 -endi -if $data07 != NULL then - return -1 -endi -if $data08 != NULL then - return -1 -endi -if $data09 != NULL then - return -1 -endi -if $data20 != @18-09-17 09:00:01.000@ then - return -1 -endi -if $data21 != 0 then - return -1 -endi -if $data22 != NULL then - return -1 -endi -if $data23 != 0.00167 then - return -1 -endi -if $data24 != NULL then - return -1 -endi -if $data25 != 0 then - return -1 -endi -if $data26 != 0 then - return -1 -endi -if $data27 != NULL then - return -1 -endi -if $data28 != NULL then - return -1 -endi -if $data29 != NULL then - return -1 -endi - - ## interp(*) from stb + group by + fill(value) -$t = $ts0 + 1000 -sql select interp(*) from $stb where ts = $t fill(value, -1, -2) group by tbname -print ====== 0:$data00, 1:$data01, 2:$data02, 3:$data03, 4:$data04, 5:$data05, 6:$data06, 7:$data07, 8:$data08, 9:$data09 -print ====== 0:$data20, 1:$data21, 2:$data22, 3:$data23, 4:$data24, 5:$data25, 6:$data26, 7:$data27, 8:$data28, 9:$data29 -if $rows != $tbNum then - return -1 -endi -if $data00 != @18-09-17 09:00:01.000@ then - return -1 -endi -if $data01 != -2 then - return -1 -endi -if $data02 != -2 then - return -1 -endi -if $data03 != -2.00000 then - return -1 -endi -if $data04 != -2.000000000 then - return -1 -endi -if $data05 != -2 then - return -1 -endi -if $data06 != -2 then - return -1 -endi -if $data07 != 1 then - return -1 -endi -if $data08 != NULL then - return -1 -endi -if $data09 != NULL then - return -1 -endi -if $data20 != @18-09-17 09:00:01.000@ then - return -1 -endi -if $data21 != -2 then - return -1 -endi -if $data22 != -2 then - return -1 -endi -if $data23 != -2.00000 then - return -1 -endi -if $data24 != -2.000000000 then - return -1 -endi -if $data25 != -2 then - return -1 -endi -if $data26 != -2 then - return -1 -endi -if $data27 != 1 then - return -1 -endi -if $data28 != NULL then - return -1 -endi -if $data29 != NULL then - return -1 -endi - -sql_error select interp(ts,c1) from intp_tb0 where ts>'2018-11-25 19:19:00' and ts<'2018-11-25 19:19:12'; -sql select interp(ts,c1) from intp_tb0 where ts>'2018-11-25 19:19:00' and ts<'2018-11-25 19:19:12' every(1s) fill(linear); -if $rows != 0 then - return -1 -endi - -sql select interp(c1) from intp_tb0 where ts>'2018-11-25 18:09:00' and ts<'2018-11-25 19:20:12' every(18m); -if $rows != 1 then - return -1 -endi - -if $data00 != @18-11-25 18:30:00.000@ then - return -1 -endi - -if $data01 != 3 then - return -1 -endi - -sql select interp(c1,c3,c4,ts) from intp_tb0 where ts>'2018-11-25 18:09:00' and ts<'2018-11-25 19:20:12' every(18m) fill(linear) -if $rows != 5 then - return -1 -endi - -if $data00 != @18-11-25 17:54:00.000@ then - return -1 -endi - -if $data01 != 0 then - return -1 -endi - -if $data02 != 0.00000 then - return -1 -endi - -if $data03 != 0.000000000 then - return -1 -endi - -if $data04 != @18-11-25 17:54:00.000@ then - return -1 -endi - -if $data10 != @18-11-25 18:12:00.000@ then - return -1 -endi - -if $data11 != 1 then - return -1 -endi - -if $data12 != 1.20000 then - return -1 -endi - -if $data13 != 1.200000000 then - return -1 -endi - -if $data14 != @18-11-25 18:12:00.000@ then - return -1 -endi - -if $data40 != @18-11-25 19:06:00.000@ then - return -1 -endi - -if $data41 != 6 then - return -1 -endi - -if $data42 != 6.60000 then - return -1 -endi - -if $data43 != 6.600000000 then - return -1 -endi - -if $data44 != @18-11-25 19:06:00.000@ then - return -1 -endi - - -sql select interp(c1) from intp_stb0 where ts >= '2018-09-17 20:35:00.000' and ts <= '2018-09-17 20:42:00.000' every(1m) fill(linear); -if $rows != 8 then - return -1 -endi -if $data00 != @18-09-17 20:35:00.000@ then - return -1 -endi -if $data01 != NULL then - return -1 -endi -if $data10 != @18-09-17 20:36:00.000@ then - return -1 -endi -if $data11 != NULL then - return -1 -endi -if $data20 != @18-09-17 20:37:00.000@ then - return -1 -endi -if $data21 != NULL then - return -1 -endi -if $data30 != @18-09-17 20:38:00.000@ then - return -1 -endi -if $data31 != NULL then - return -1 -endi -if $data40 != @18-09-17 20:39:00.000@ then - return -1 -endi -if $data41 != NULL then - return -1 -endi -if $data50 != @18-09-17 20:40:00.000@ then - return -1 -endi -if $data51 != 0 then - return -1 -endi -if $data60 != @18-09-17 20:41:00.000@ then - return -1 -endi -if $data61 != NULL then - return -1 -endi -if $data70 != @18-09-17 20:42:00.000@ then - return -1 -endi -if $data71 != NULL then - return -1 -endi - - -sql select interp(c1) from intp_stb0 where ts >= '2018-09-17 20:35:00.000' and ts <= '2018-09-17 20:42:00.000' every(1m) fill(linear) order by ts desc; -if $rows != 8 then - return -1 -endi -if $data00 != @18-09-17 20:42:00.000@ then - return -1 -endi -if $data01 != NULL then - return -1 -endi -if $data10 != @18-09-17 20:41:00.000@ then - return -1 -endi -if $data11 != NULL then - return -1 -endi -if $data20 != @18-09-17 20:40:00.000@ then - return -1 -endi -if $data21 != 0 then - return -1 -endi -if $data30 != @18-09-17 20:39:00.000@ then - return -1 -endi -if $data31 != NULL then - return -1 -endi -if $data40 != @18-09-17 20:38:00.000@ then - return -1 -endi -if $data41 != NULL then - return -1 -endi -if $data50 != @18-09-17 20:37:00.000@ then - return -1 -endi -if $data51 != NULL then - return -1 -endi -if $data60 != @18-09-17 20:36:00.000@ then - return -1 -endi -if $data61 != NULL then - return -1 -endi -if $data70 != @18-09-17 20:35:00.000@ then - return -1 -endi -if $data71 != NULL then - return -1 -endi - -sql select interp(c3) from intp_stb0 where ts >= '2018-09-17 20:35:00.000' and ts <= '2018-09-17 20:50:00.000' every(2m) fill(linear) order by ts; -if $rows != 9 then - return -1 -endi -if $data00 != @18-09-17 20:34:00.000@ then - return -1 -endi -if $data01 != NULL then - return -1 -endi -if $data10 != @18-09-17 20:36:00.000@ then - return -1 -endi -if $data11 != NULL then - return -1 -endi -if $data20 != @18-09-17 20:38:00.000@ then - return -1 -endi -if $data21 != NULL then - return -1 -endi -if $data30 != @18-09-17 20:40:00.000@ then - return -1 -endi -if $data31 != 0.00000 then - return -1 -endi -if $data40 != @18-09-17 20:42:00.000@ then - return -1 -endi -if $data41 != 0.20000 then - return -1 -endi -if $data50 != @18-09-17 20:44:00.000@ then - return -1 -endi -if $data51 != 0.40000 then - return -1 -endi -if $data60 != @18-09-17 20:46:00.000@ then - return -1 -endi -if $data61 != 0.60000 then - return -1 -endi -if $data70 != @18-09-17 20:48:00.000@ then - return -1 -endi -if $data71 != 0.80000 then - return -1 -endi -if $data80 != @18-09-17 20:50:00.000@ then - return -1 -endi -if $data81 != 1.00000 then - return -1 -endi - - -sql select interp(c3) from intp_stb0 where ts >= '2018-09-17 20:35:00.000' and ts <= '2018-09-17 20:50:00.000' every(3m) fill(linear) order by ts; -if $rows != 6 then - return -1 -endi -if $data00 != @18-09-17 20:33:00.000@ then - return -1 -endi -if $data01 != NULL then - return -1 -endi -if $data10 != @18-09-17 20:36:00.000@ then - return -1 -endi -if $data11 != NULL then - return -1 -endi -if $data20 != @18-09-17 20:39:00.000@ then - return -1 -endi -if $data21 != NULL then - return -1 -endi -if $data30 != @18-09-17 20:42:00.000@ then - return -1 -endi -if $data31 != 0.20000 then - return -1 -endi -if $data40 != @18-09-17 20:45:00.000@ then - return -1 -endi -if $data41 != 0.50000 then - return -1 -endi -if $data50 != @18-09-17 20:48:00.000@ then - return -1 -endi -if $data51 != 0.80000 then - return -1 -endi - -sql select interp(c3) from intp_stb0 where ts >= '2018-09-17 20:35:00.000' and ts <= '2018-09-17 20:50:00.000' every(3m) fill(linear) order by ts desc; -if $rows != 6 then - return -1 -endi -if $data00 != @18-09-17 20:48:00.000@ then - return -1 -endi -if $data01 != 0.80000 then - return -1 -endi -if $data10 != @18-09-17 20:45:00.000@ then - return -1 -endi -if $data11 != 0.50000 then - return -1 -endi -if $data20 != @18-09-17 20:42:00.000@ then - return -1 -endi -if $data21 != 0.20000 then - return -1 -endi -if $data30 != @18-09-17 20:39:00.000@ then - return -1 -endi -if $data31 != NULL then - return -1 -endi -if $data40 != @18-09-17 20:36:00.000@ then - return -1 -endi -if $data41 != NULL then - return -1 -endi -if $data50 != @18-09-17 20:33:00.000@ then - return -1 -endi -if $data51 != NULL then - return -1 -endi - - - -sql select interp(pav) from ap1 where ts> '2021-07-25 02:19:54' and ts<'2021-07-25 02:20:00' every(1s) fill(linear); -if $rows != 6 then - return -1 -endi -if $data00 != @21-07-25 02:19:54.000@ then - return -1 -endi -if $data01 != NULL then - return -1 -endi -if $data10 != @21-07-25 02:19:55.000@ then - return -1 -endi -if $data11 != 3.31818 then - return -1 -endi -if $data20 != @21-07-25 02:19:56.000@ then - return -1 -endi -if $data21 != 3.77273 then - return -1 -endi -if $data30 != @21-07-25 02:19:57.000@ then - return -1 -endi -if $data31 != 4.50000 then - return -1 -endi -if $data40 != @21-07-25 02:19:58.000@ then - return -1 -endi -if $data41 != 7.50000 then - return -1 -endi -if $data50 != @21-07-25 02:19:59.000@ then - return -1 -endi -if $data51 != 9.87500 then - return -1 -endi - -sql select interp(pav) from ap1 where ts> '2021-07-25 02:19:54' and ts<'2021-07-25 02:20:00' every(1s) fill(value, 1); -if $rows != 6 then - return -1 -endi -if $data00 != @21-07-25 02:19:54.000@ then - return -1 -endi -if $data01 != 1.00000 then - return -1 -endi -if $data10 != @21-07-25 02:19:55.000@ then - return -1 -endi -if $data11 != 1.00000 then - return -1 -endi -if $data20 != @21-07-25 02:19:56.000@ then - return -1 -endi -if $data21 != 1.00000 then - return -1 -endi -if $data30 != @21-07-25 02:19:57.000@ then - return -1 -endi -if $data31 != 1.00000 then - return -1 -endi -if $data40 != @21-07-25 02:19:58.000@ then - return -1 -endi -if $data41 != 1.00000 then - return -1 -endi -if $data50 != @21-07-25 02:19:59.000@ then - return -1 -endi -if $data51 != 1.00000 then - return -1 -endi - -sql select interp(pav) from ap1 where ts> '2021-07-25 02:19:54' and ts<'2021-07-25 02:20:00' every(1s) fill(NULL); -if $rows != 6 then - return -1 -endi -if $data00 != @21-07-25 02:19:54.000@ then - return -1 -endi -if $data01 != NULL then - return -1 -endi -if $data10 != @21-07-25 02:19:55.000@ then - return -1 -endi -if $data11 != NULL then - return -1 -endi -if $data20 != @21-07-25 02:19:56.000@ then - return -1 -endi -if $data21 != NULL then - return -1 -endi -if $data30 != @21-07-25 02:19:57.000@ then - return -1 -endi -if $data31 != NULL then - return -1 -endi -if $data40 != @21-07-25 02:19:58.000@ then - return -1 -endi -if $data41 != NULL then - return -1 -endi -if $data50 != @21-07-25 02:19:59.000@ then - return -1 -endi -if $data51 != NULL then - return -1 -endi - -sql select interp(pav) from ap1 where ts> '2021-07-25 02:19:54' and ts<'2021-07-25 02:20:00' every(1s) fill(prev); -if $rows != 6 then - return -1 -endi -if $data00 != @21-07-25 02:19:54.000@ then - return -1 -endi -if $data01 != NULL then - return -1 -endi -if $data10 != @21-07-25 02:19:55.000@ then - return -1 -endi -if $data11 != 3.00000 then - return -1 -endi -if $data20 != @21-07-25 02:19:56.000@ then - return -1 -endi -if $data21 != 3.00000 then - return -1 -endi -if $data30 != @21-07-25 02:19:57.000@ then - return -1 -endi -if $data31 != 4.00000 then - return -1 -endi -if $data40 != @21-07-25 02:19:58.000@ then - return -1 -endi -if $data41 != 7.00000 then - return -1 -endi -if $data50 != @21-07-25 02:19:59.000@ then - return -1 -endi -if $data51 != 9.00000 then - return -1 -endi - -sql select interp(pav) from ap1 where ts> '2021-07-25 02:19:54' and ts<'2021-07-25 02:20:00' every(1s) fill(next); -if $rows != 6 then - return -1 -endi -if $data00 != @21-07-25 02:19:54.000@ then - return -1 -endi -if $data01 != 1.00000 then - return -1 -endi -if $data10 != @21-07-25 02:19:55.000@ then - return -1 -endi -if $data11 != 4.00000 then - return -1 -endi -if $data20 != @21-07-25 02:19:56.000@ then - return -1 -endi -if $data21 != 4.00000 then - return -1 -endi -if $data30 != @21-07-25 02:19:57.000@ then - return -1 -endi -if $data31 != 5.00000 then - return -1 -endi -if $data40 != @21-07-25 02:19:58.000@ then - return -1 -endi -if $data41 != 8.00000 then - return -1 -endi -if $data50 != @21-07-25 02:19:59.000@ then - return -1 -endi -if $data51 != 10.00000 then - return -1 -endi - - -sql select interp(pav) from ap1 where ts> '2021-07-25 02:19:54' and ts<'2021-07-25 02:19:56' every(1s) fill(linear); -if $rows != 0 then - return -1 -endi -sql select interp(pav) from ap1 where ts> '2021-07-25 02:19:54' and ts<'2021-07-25 02:19:56' every(1s) fill(prev); -if $rows != 2 then - return -1 -endi -if $data00 != @21-07-25 02:19:54.000@ then - return -1 -endi -if $data01 != NULL then - return -1 -endi -if $data10 != @21-07-25 02:19:55.000@ then - return -1 -endi -if $data11 != 3.00000 then - return -1 -endi - -sql select interp(pav) from ap1 where ts> '2021-07-25 02:19:54' and ts<'2021-07-25 02:19:56' every(1s) fill(next); -if $rows != 2 then - return -1 -endi -if $data00 != @21-07-25 02:19:54.000@ then - return -1 -endi -if $data01 != 1.00000 then - return -1 -endi -if $data10 != @21-07-25 02:19:55.000@ then - return -1 -endi -if $data11 != NULL then - return -1 -endi - -sql select interp(pav) from ap1 where ts> '2021-07-25 02:19:54' and ts<'2021-07-25 02:19:57' every(1s) fill(linear); -if $rows != 3 then - return -1 -endi -if $data00 != @21-07-25 02:19:54.000@ then - return -1 -endi -if $data01 != NULL then - return -1 -endi -if $data10 != @21-07-25 02:19:55.000@ then - return -1 -endi -if $data11 != 3.31818 then - return -1 -endi -if $data20 != @21-07-25 02:19:56.000@ then - return -1 -endi -if $data21 != 3.77273 then - return -1 -endi - -sql select interp(pav) from ap1 where ts> '2021-07-25 02:19:54' and ts<'2021-07-25 02:19:57' every(1s) fill(prev); -if $rows != 3 then - return -1 -endi -if $data00 != @21-07-25 02:19:54.000@ then - return -1 -endi -if $data01 != NULL then - return -1 -endi -if $data10 != @21-07-25 02:19:55.000@ then - return -1 -endi -if $data11 != 3.00000 then - return -1 -endi -if $data20 != @21-07-25 02:19:56.000@ then - return -1 -endi -if $data21 != 3.00000 then - return -1 -endi - -sql select interp(pav) from ap1 where ts> '2021-07-25 02:19:54' and ts<'2021-07-25 02:19:57' every(1s) fill(next); -if $rows != 3 then - return -1 -endi -if $data00 != @21-07-25 02:19:54.000@ then - return -1 -endi -if $data01 != 1.00000 then - return -1 -endi -if $data10 != @21-07-25 02:19:55.000@ then - return -1 -endi -if $data11 != 4.00000 then - return -1 -endi -if $data20 != @21-07-25 02:19:56.000@ then - return -1 -endi -if $data21 != 4.00000 then - return -1 -endi - -sql select interp(pav) from ap1 where ts> '2021-07-25 02:19:54' and ts<='2021-07-25 02:20:03' every(1s) fill(linear); -if $rows != 10 then - return -1 -endi -if $data00 != @21-07-25 02:19:54.000@ then - return -1 -endi -if $data01 != NULL then - return -1 -endi -if $data10 != @21-07-25 02:19:55.000@ then - return -1 -endi -if $data11 != 3.31818 then - return -1 -endi -if $data20 != @21-07-25 02:19:56.000@ then - return -1 -endi -if $data21 != 3.77273 then - return -1 -endi -if $data30 != @21-07-25 02:19:57.000@ then - return -1 -endi -if $data31 != 4.50000 then - return -1 -endi -if $data40 != @21-07-25 02:19:58.000@ then - return -1 -endi -if $data41 != 7.50000 then - return -1 -endi -if $data50 != @21-07-25 02:19:59.000@ then - return -1 -endi -if $data51 != 9.87500 then - return -1 -endi -if $data60 != @21-07-25 02:20:00.000@ then - return -1 -endi -if $data61 != NULL then - return -1 -endi -if $data70 != @21-07-25 02:20:01.000@ then - return -1 -endi -if $data71 != NULL then - return -1 -endi -if $data80 != @21-07-25 02:20:02.000@ then - return -1 -endi -if $data81 != NULL then - return -1 -endi -if $data90 != @21-07-25 02:20:03.000@ then - return -1 -endi -if $data91 != NULL then - return -1 -endi - -sql select interp(pav) from ap1 where ts> '2021-07-25 02:19:54' and ts<='2021-07-25 02:20:03' every(1s) fill(prev); -if $rows != 10 then - return -1 -endi -if $data00 != @21-07-25 02:19:54.000@ then - return -1 -endi -if $data01 != NULL then - return -1 -endi -if $data10 != @21-07-25 02:19:55.000@ then - return -1 -endi -if $data11 != 3.00000 then - return -1 -endi -if $data20 != @21-07-25 02:19:56.000@ then - return -1 -endi -if $data21 != 3.00000 then - return -1 -endi -if $data30 != @21-07-25 02:19:57.000@ then - return -1 -endi -if $data31 != 4.00000 then - return -1 -endi -if $data40 != @21-07-25 02:19:58.000@ then - return -1 -endi -if $data41 != 7.00000 then - return -1 -endi -if $data50 != @21-07-25 02:19:59.000@ then - return -1 -endi -if $data51 != 9.00000 then - return -1 -endi -if $data60 != @21-07-25 02:20:00.000@ then - return -1 -endi -if $data61 != 14.00000 then - return -1 -endi -if $data70 != @21-07-25 02:20:01.000@ then - return -1 -endi -if $data71 != 14.00000 then - return -1 -endi -if $data80 != @21-07-25 02:20:02.000@ then - return -1 -endi -if $data81 != 14.00000 then - return -1 -endi -if $data90 != @21-07-25 02:20:03.000@ then - return -1 -endi -if $data91 != 14.00000 then - return -1 -endi - -sql select interp(pav) from ap1 where ts> '2021-07-25 02:19:54' and ts<='2021-07-25 02:20:03' every(1s) fill(next); -if $rows != 10 then - return -1 -endi -if $data00 != @21-07-25 02:19:54.000@ then - return -1 -endi -if $data01 != 1.00000 then - return -1 -endi -if $data10 != @21-07-25 02:19:55.000@ then - return -1 -endi -if $data11 != 4.00000 then - return -1 -endi -if $data20 != @21-07-25 02:19:56.000@ then - return -1 -endi -if $data21 != 4.00000 then - return -1 -endi -if $data30 != @21-07-25 02:19:57.000@ then - return -1 -endi -if $data31 != 5.00000 then - return -1 -endi -if $data40 != @21-07-25 02:19:58.000@ then - return -1 -endi -if $data41 != 8.00000 then - return -1 -endi -if $data50 != @21-07-25 02:19:59.000@ then - return -1 -endi -if $data51 != 10.00000 then - return -1 -endi -if $data60 != @21-07-25 02:20:00.000@ then - return -1 -endi -if $data61 != NULL then - return -1 -endi -if $data70 != @21-07-25 02:20:01.000@ then - return -1 -endi -if $data71 != NULL then - return -1 -endi -if $data80 != @21-07-25 02:20:02.000@ then - return -1 -endi -if $data81 != NULL then - return -1 -endi -if $data90 != @21-07-25 02:20:03.000@ then - return -1 -endi -if $data91 != NULL then - return -1 -endi - -sql select interp(pav) from ap1 where ts> '2021-07-25 02:19:54' and ts<='2021-07-25 02:20:05' every(1s) fill(linear); -if $rows != 12 then - return -1 -endi -if $data00 != @21-07-25 02:19:54.000@ then - return -1 -endi -if $data01 != NULL then - return -1 -endi -if $data10 != @21-07-25 02:19:55.000@ then - return -1 -endi -if $data11 != 3.31818 then - return -1 -endi -if $data20 != @21-07-25 02:19:56.000@ then - return -1 -endi -if $data21 != 3.77273 then - return -1 -endi -if $data30 != @21-07-25 02:19:57.000@ then - return -1 -endi -if $data31 != 4.50000 then - return -1 -endi -if $data40 != @21-07-25 02:19:58.000@ then - return -1 -endi -if $data41 != 7.50000 then - return -1 -endi -if $data50 != @21-07-25 02:19:59.000@ then - return -1 -endi -if $data51 != 9.87500 then - return -1 -endi -if $data60 != @21-07-25 02:20:00.000@ then - return -1 -endi -if $data61 != 14.11765 then - return -1 -endi -if $data70 != @21-07-25 02:20:01.000@ then - return -1 -endi -if $data71 != 15.29412 then - return -1 -endi - -sql select interp(pav) from ap1 where ts> '2021-07-25 02:19:54' and ts<='2021-07-25 02:20:05' every(1s) fill(prev); -if $rows != 12 then - return -1 -endi -if $data00 != @21-07-25 02:19:54.000@ then - return -1 -endi -if $data01 != NULL then - return -1 -endi -if $data10 != @21-07-25 02:19:55.000@ then - return -1 -endi -if $data11 != 3.00000 then - return -1 -endi -if $data20 != @21-07-25 02:19:56.000@ then - return -1 -endi -if $data21 != 3.00000 then - return -1 -endi -if $data30 != @21-07-25 02:19:57.000@ then - return -1 -endi -if $data31 != 4.00000 then - return -1 -endi -if $data40 != @21-07-25 02:19:58.000@ then - return -1 -endi -if $data41 != 7.00000 then - return -1 -endi -if $data50 != @21-07-25 02:19:59.000@ then - return -1 -endi -if $data51 != 9.00000 then - return -1 -endi -if $data60 != @21-07-25 02:20:00.000@ then - return -1 -endi -if $data61 != 14.00000 then - return -1 -endi -if $data70 != @21-07-25 02:20:01.000@ then - return -1 -endi -if $data71 != 14.00000 then - return -1 -endi -if $data80 != @21-07-25 02:20:02.000@ then - return -1 -endi -if $data81 != 14.00000 then - return -1 -endi -if $data90 != @21-07-25 02:20:03.000@ then - return -1 -endi -if $data91 != 14.00000 then - return -1 -endi - -sql select interp(pav) from ap1 where ts> '2021-07-25 02:19:54' and ts<='2021-07-25 02:20:05' every(1s) fill(next); -if $rows != 12 then - return -1 -endi -if $data00 != @21-07-25 02:19:54.000@ then - return -1 -endi -if $data01 != 1.00000 then - return -1 -endi -if $data10 != @21-07-25 02:19:55.000@ then - return -1 -endi -if $data11 != 4.00000 then - return -1 -endi -if $data20 != @21-07-25 02:19:56.000@ then - return -1 -endi -if $data21 != 4.00000 then - return -1 -endi -if $data30 != @21-07-25 02:19:57.000@ then - return -1 -endi -if $data31 != 5.00000 then - return -1 -endi -if $data40 != @21-07-25 02:19:58.000@ then - return -1 -endi -if $data41 != 8.00000 then - return -1 -endi -if $data50 != @21-07-25 02:19:59.000@ then - return -1 -endi -if $data51 != 10.00000 then - return -1 -endi -if $data60 != @21-07-25 02:20:00.000@ then - return -1 -endi -if $data61 != 20.00000 then - return -1 -endi -if $data70 != @21-07-25 02:20:01.000@ then - return -1 -endi -if $data71 != 20.00000 then - return -1 -endi -if $data80 != @21-07-25 02:20:02.000@ then - return -1 -endi -if $data81 != 20.00000 then - return -1 -endi -if $data90 != @21-07-25 02:20:03.000@ then - return -1 -endi -if $data91 != 20.00000 then - return -1 -endi - -sql select interp(pav) from ap1 where ts> '2021-07-25 02:20:02' and ts<='2021-07-25 02:20:05' every(1s) fill(value, 1); -if $rows != 4 then - return -1 -endi -if $data00 != @21-07-25 02:20:02.000@ then - return -1 -endi -if $data01 != 1.00000 then - return -1 -endi -if $data10 != @21-07-25 02:20:03.000@ then - return -1 -endi -if $data11 != 1.00000 then - return -1 -endi -if $data20 != @21-07-25 02:20:04.000@ then - return -1 -endi -if $data21 != 1.00000 then - return -1 -endi -if $data30 != @21-07-25 02:20:05.000@ then - return -1 -endi -if $data31 != 20.00000 then - return -1 -endi - -sql select interp(pav) from ap1 where ts> '2021-07-25 02:20:02' and ts<='2021-07-25 02:20:05' every(1s) fill(null); -if $rows != 4 then - return -1 -endi -if $data00 != @21-07-25 02:20:02.000@ then - return -1 -endi -if $data01 != NULL then - return -1 -endi -if $data10 != @21-07-25 02:20:03.000@ then - return -1 -endi -if $data11 != NULL then - return -1 -endi -if $data20 != @21-07-25 02:20:04.000@ then - return -1 -endi -if $data21 != NULL then - return -1 -endi -if $data30 != @21-07-25 02:20:05.000@ then - return -1 -endi -if $data31 != 20.00000 then - return -1 -endi - - -sql select interp(pav) from ap1 where ts> '2021-07-25 02:19:54' and ts<='2021-07-25 02:20:25' every(1s) fill(linear); -if $rows != 32 then - return -1 -endi -if $data00 != @21-07-25 02:19:54.000@ then - return -1 -endi -if $data01 != NULL then - return -1 -endi -if $data10 != @21-07-25 02:19:55.000@ then - return -1 -endi -if $data11 != 3.31818 then - return -1 -endi -if $data20 != @21-07-25 02:19:56.000@ then - return -1 -endi -if $data21 != 3.77273 then - return -1 -endi -if $data30 != @21-07-25 02:19:57.000@ then - return -1 -endi -if $data31 != 4.50000 then - return -1 -endi -if $data40 != @21-07-25 02:19:58.000@ then - return -1 -endi -if $data41 != 7.50000 then - return -1 -endi -if $data50 != @21-07-25 02:19:59.000@ then - return -1 -endi -if $data51 != 9.87500 then - return -1 -endi -if $data60 != @21-07-25 02:20:00.000@ then - return -1 -endi -if $data61 != 14.11765 then - return -1 -endi -if $data70 != @21-07-25 02:20:01.000@ then - return -1 -endi -if $data71 != 15.29412 then - return -1 -endi - -sql select interp(pav) from ap1 where ts> '2021-07-25 02:19:54' and ts<='2021-07-25 02:20:25' every(1s) fill(prev); -if $rows != 32 then - return -1 -endi -if $data00 != @21-07-25 02:19:54.000@ then - return -1 -endi -if $data01 != NULL then - return -1 -endi -if $data10 != @21-07-25 02:19:55.000@ then - return -1 -endi -if $data11 != 3.00000 then - return -1 -endi -if $data20 != @21-07-25 02:19:56.000@ then - return -1 -endi -if $data21 != 3.00000 then - return -1 -endi -if $data30 != @21-07-25 02:19:57.000@ then - return -1 -endi -if $data31 != 4.00000 then - return -1 -endi -if $data40 != @21-07-25 02:19:58.000@ then - return -1 -endi -if $data41 != 7.00000 then - return -1 -endi -if $data50 != @21-07-25 02:19:59.000@ then - return -1 -endi -if $data51 != 9.00000 then - return -1 -endi -if $data60 != @21-07-25 02:20:00.000@ then - return -1 -endi -if $data61 != 14.00000 then - return -1 -endi -if $data70 != @21-07-25 02:20:01.000@ then - return -1 -endi -if $data71 != 14.00000 then - return -1 -endi -if $data80 != @21-07-25 02:20:02.000@ then - return -1 -endi -if $data81 != 14.00000 then - return -1 -endi -if $data90 != @21-07-25 02:20:03.000@ then - return -1 -endi -if $data91 != 14.00000 then - return -1 -endi - -sql select interp(pav) from ap1 where ts> '2021-07-25 02:19:54' and ts<='2021-07-25 02:20:25' every(1s) fill(next); -if $rows != 32 then - return -1 -endi -if $data00 != @21-07-25 02:19:54.000@ then - return -1 -endi -if $data01 != 1.00000 then - return -1 -endi -if $data10 != @21-07-25 02:19:55.000@ then - return -1 -endi -if $data11 != 4.00000 then - return -1 -endi -if $data20 != @21-07-25 02:19:56.000@ then - return -1 -endi -if $data21 != 4.00000 then - return -1 -endi -if $data30 != @21-07-25 02:19:57.000@ then - return -1 -endi -if $data31 != 5.00000 then - return -1 -endi -if $data40 != @21-07-25 02:19:58.000@ then - return -1 -endi -if $data41 != 8.00000 then - return -1 -endi -if $data50 != @21-07-25 02:19:59.000@ then - return -1 -endi -if $data51 != 10.00000 then - return -1 -endi -if $data60 != @21-07-25 02:20:00.000@ then - return -1 -endi -if $data61 != 20.00000 then - return -1 -endi -if $data70 != @21-07-25 02:20:01.000@ then - return -1 -endi -if $data71 != 20.00000 then - return -1 -endi -if $data80 != @21-07-25 02:20:02.000@ then - return -1 -endi -if $data81 != 20.00000 then - return -1 -endi -if $data90 != @21-07-25 02:20:03.000@ then - return -1 -endi -if $data91 != 20.00000 then - return -1 -endi - - -sql select interp(pav) from ap1 where ts> '2021-07-25 02:19:54' and ts<='2021-07-25 02:25:00' every(1s) fill(linear); -if $rows != 307 then - return -1 -endi -if $data00 != @21-07-25 02:19:54.000@ then - return -1 -endi -if $data01 != NULL then - return -1 -endi -if $data10 != @21-07-25 02:19:55.000@ then - return -1 -endi -if $data11 != 3.31818 then - return -1 -endi -if $data20 != @21-07-25 02:19:56.000@ then - return -1 -endi -if $data21 != 3.77273 then - return -1 -endi -if $data30 != @21-07-25 02:19:57.000@ then - return -1 -endi -if $data31 != 4.50000 then - return -1 -endi -if $data40 != @21-07-25 02:19:58.000@ then - return -1 -endi -if $data41 != 7.50000 then - return -1 -endi -if $data50 != @21-07-25 02:19:59.000@ then - return -1 -endi -if $data51 != 9.87500 then - return -1 -endi -if $data60 != @21-07-25 02:20:00.000@ then - return -1 -endi -if $data61 != 14.11765 then - return -1 -endi -if $data70 != @21-07-25 02:20:01.000@ then - return -1 -endi -if $data71 != 15.29412 then - return -1 -endi - -sql select interp(pav) from ap1 where ts> '2021-07-25 02:19:54' and ts<='2021-07-25 02:25:00' every(1s) fill(prev); -if $rows != 307 then - return -1 -endi -if $data00 != @21-07-25 02:19:54.000@ then - return -1 -endi -if $data01 != NULL then - return -1 -endi -if $data10 != @21-07-25 02:19:55.000@ then - return -1 -endi -if $data11 != 3.00000 then - return -1 -endi -if $data20 != @21-07-25 02:19:56.000@ then - return -1 -endi -if $data21 != 3.00000 then - return -1 -endi -if $data30 != @21-07-25 02:19:57.000@ then - return -1 -endi -if $data31 != 4.00000 then - return -1 -endi -if $data40 != @21-07-25 02:19:58.000@ then - return -1 -endi -if $data41 != 7.00000 then - return -1 -endi -if $data50 != @21-07-25 02:19:59.000@ then - return -1 -endi -if $data51 != 9.00000 then - return -1 -endi -if $data60 != @21-07-25 02:20:00.000@ then - return -1 -endi -if $data61 != 14.00000 then - return -1 -endi -if $data70 != @21-07-25 02:20:01.000@ then - return -1 -endi -if $data71 != 14.00000 then - return -1 -endi -if $data80 != @21-07-25 02:20:02.000@ then - return -1 -endi -if $data81 != 14.00000 then - return -1 -endi -if $data90 != @21-07-25 02:20:03.000@ then - return -1 -endi -if $data91 != 14.00000 then - return -1 -endi - -sql select interp(pav) from ap1 where ts> '2021-07-25 02:19:54' and ts<='2021-07-25 02:25:00' every(1s) fill(next); -if $rows != 307 then - return -1 -endi -if $data00 != @21-07-25 02:19:54.000@ then - return -1 -endi -if $data01 != 1.00000 then - return -1 -endi -if $data10 != @21-07-25 02:19:55.000@ then - return -1 -endi -if $data11 != 4.00000 then - return -1 -endi -if $data20 != @21-07-25 02:19:56.000@ then - return -1 -endi -if $data21 != 4.00000 then - return -1 -endi -if $data30 != @21-07-25 02:19:57.000@ then - return -1 -endi -if $data31 != 5.00000 then - return -1 -endi -if $data40 != @21-07-25 02:19:58.000@ then - return -1 -endi -if $data41 != 8.00000 then - return -1 -endi -if $data50 != @21-07-25 02:19:59.000@ then - return -1 -endi -if $data51 != 10.00000 then - return -1 -endi -if $data60 != @21-07-25 02:20:00.000@ then - return -1 -endi -if $data61 != 20.00000 then - return -1 -endi -if $data70 != @21-07-25 02:20:01.000@ then - return -1 -endi -if $data71 != 20.00000 then - return -1 -endi -if $data80 != @21-07-25 02:20:02.000@ then - return -1 -endi -if $data81 != 20.00000 then - return -1 -endi -if $data90 != @21-07-25 02:20:03.000@ then - return -1 -endi -if $data91 != 20.00000 then - return -1 -endi - -sql select interp(pav) from ap1 where ts> '2021-07-25 02:19:54' and ts<='2021-07-25 03:25:00' every(1s) fill(linear); -if $rows != 3907 then - return -1 -endi -if $data00 != @21-07-25 02:19:54.000@ then - return -1 -endi -if $data01 != NULL then - return -1 -endi -if $data10 != @21-07-25 02:19:55.000@ then - return -1 -endi -if $data11 != 3.31818 then - return -1 -endi -if $data20 != @21-07-25 02:19:56.000@ then - return -1 -endi -if $data21 != 3.77273 then - return -1 -endi -if $data30 != @21-07-25 02:19:57.000@ then - return -1 -endi -if $data31 != 4.50000 then - return -1 -endi -if $data40 != @21-07-25 02:19:58.000@ then - return -1 -endi -if $data41 != 7.50000 then - return -1 -endi -if $data50 != @21-07-25 02:19:59.000@ then - return -1 -endi -if $data51 != 9.87500 then - return -1 -endi -if $data60 != @21-07-25 02:20:00.000@ then - return -1 -endi -if $data61 != 14.11765 then - return -1 -endi -if $data70 != @21-07-25 02:20:01.000@ then - return -1 -endi -if $data71 != 15.29412 then - return -1 -endi - - -sql select interp(pav) from ap1 where ts> '2021-07-25 02:19:54' and ts<='2021-07-25 03:25:00' every(1s) fill(prev); -if $rows != 3907 then - return -1 -endi -if $data00 != @21-07-25 02:19:54.000@ then - return -1 -endi -if $data01 != NULL then - return -1 -endi -if $data10 != @21-07-25 02:19:55.000@ then - return -1 -endi -if $data11 != 3.00000 then - return -1 -endi -if $data20 != @21-07-25 02:19:56.000@ then - return -1 -endi -if $data21 != 3.00000 then - return -1 -endi -if $data30 != @21-07-25 02:19:57.000@ then - return -1 -endi -if $data31 != 4.00000 then - return -1 -endi -if $data40 != @21-07-25 02:19:58.000@ then - return -1 -endi -if $data41 != 7.00000 then - return -1 -endi -if $data50 != @21-07-25 02:19:59.000@ then - return -1 -endi -if $data51 != 9.00000 then - return -1 -endi -if $data60 != @21-07-25 02:20:00.000@ then - return -1 -endi -if $data61 != 14.00000 then - return -1 -endi -if $data70 != @21-07-25 02:20:01.000@ then - return -1 -endi -if $data71 != 14.00000 then - return -1 -endi -if $data80 != @21-07-25 02:20:02.000@ then - return -1 -endi -if $data81 != 14.00000 then - return -1 -endi -if $data90 != @21-07-25 02:20:03.000@ then - return -1 -endi -if $data91 != 14.00000 then - return -1 -endi - -sql select interp(pav) from ap1 where ts> '2021-07-25 02:19:54' and ts<='2021-07-25 03:25:00' every(1s) fill(next); -if $rows != 3907 then - return -1 -endi -if $data00 != @21-07-25 02:19:54.000@ then - return -1 -endi -if $data01 != 1.00000 then - return -1 -endi -if $data10 != @21-07-25 02:19:55.000@ then - return -1 -endi -if $data11 != 4.00000 then - return -1 -endi -if $data20 != @21-07-25 02:19:56.000@ then - return -1 -endi -if $data21 != 4.00000 then - return -1 -endi -if $data30 != @21-07-25 02:19:57.000@ then - return -1 -endi -if $data31 != 5.00000 then - return -1 -endi -if $data40 != @21-07-25 02:19:58.000@ then - return -1 -endi -if $data41 != 8.00000 then - return -1 -endi -if $data50 != @21-07-25 02:19:59.000@ then - return -1 -endi -if $data51 != 10.00000 then - return -1 -endi -if $data60 != @21-07-25 02:20:00.000@ then - return -1 -endi -if $data61 != 20.00000 then - return -1 -endi -if $data70 != @21-07-25 02:20:01.000@ then - return -1 -endi -if $data71 != 20.00000 then - return -1 -endi -if $data80 != @21-07-25 02:20:02.000@ then - return -1 -endi -if $data81 != 20.00000 then - return -1 -endi -if $data90 != @21-07-25 02:20:03.000@ then - return -1 -endi -if $data91 != 20.00000 then - return -1 -endi - -sql select interp(pav) from ap1 where ts> '2021-07-25 02:19:54' and ts<'2021-07-25 02:20:07' every(1s); -if $rows != 1 then - return -1 -endi -if $data00 != @21-07-25 02:20:05.000@ then - return -1 -endi -if $data01 != 20.00000 then - return -1 -endi - diff --git a/tests/script/general/parser/like.sim b/tests/script/general/parser/like.sim index fce996ebee37d887e2f86fc2a8566d844e8d04f5..382240c91141a19e28bc4a25d81cea54737b6a55 100644 --- a/tests/script/general/parser/like.sim +++ b/tests/script/general/parser/like.sim @@ -23,7 +23,7 @@ sql create table $table2 (ts timestamp, b binary(20)) sql insert into $table1 values(now, "table_name") sql insert into $table1 values(now-1m, "tablexname") sql insert into $table1 values(now-2m, "tablexxx") -sql insert into $table1 values(now-2m, "table") +sql insert into $table1 values(now-3m, "table") sql select b from $table1 if $rows != 4 then @@ -56,6 +56,45 @@ if $rows != 1 then return -1 endi +sql create database escape_percentage; +sql use escape_percentage; +$table1 = tablename +$table2 = `table%` + +sql create table $table1 (ts timestamp, b binary(20)) +sql create table $table2 (ts timestamp, b binary(20)) + +sql insert into $table1 values(now, "table%name") +sql insert into $table1 values(now-1m, "table%") +sql insert into $table1 values(now-2m, "table%%%") +sql insert into $table1 values(now-3m, "table") + +sql select b from $table1 where b like 'table\%' +print $rows +if $rows != 1 then + return -1 +endi +sql select b from $table1 where b like 'table\%\%\%' +print $rows +if $rows != 1 then + return -1 +endi +sql select b from $table1 where b like 'table%' +print $rows +if $rows != 4 then + return -1 +endi +sql show tables like 'table\%' +print $rows +if $rows != 1 then + return -1 +endi +sql show tables like 'table%' +print $rows +if $rows != 2 then + return -1 +endi +sql drop database escape_percentage system sh/exec.sh -n dnode1 -s stop -x SIGINT diff --git a/tests/script/general/parser/testSuite.sim b/tests/script/general/parser/testSuite.sim index fcd9d49fe555ae749da0fcd799e1866a8a05f656..84c9e89d872679f92f45a522ae3f6483b9ebf77f 100644 --- a/tests/script/general/parser/testSuite.sim +++ b/tests/script/general/parser/testSuite.sim @@ -20,7 +20,7 @@ run general/parser/import_commit3.sim run general/parser/import_file.sim run general/parser/insert_tb.sim run general/parser/tags_dynamically_specifiy.sim -run general/parser/interp.sim +run general/parser/interp_full.sim run general/parser/lastrow.sim run general/parser/limit.sim run general/parser/limit1.sim diff --git a/tests/script/general/parser/udf_dll.sim b/tests/script/general/parser/udf_dll.sim index 61bf5fee6e54d02ccc08218102a43a37821fdd30..c6eff722d5fbcfc79faebca131db5e071bd093c4 100644 --- a/tests/script/general/parser/udf_dll.sim +++ b/tests/script/general/parser/udf_dll.sim @@ -10,7 +10,7 @@ sql connect print ======================== dnode1 start sql create function add_one as '/tmp/add_one.so' outputtype int; -sql create aggregate function sum_double as '/tmp/sum_double.so' outputtype int; +sql create aggregate function sum_double as '/tmp/sum_double.so' outputtype bigint; sql show functions; if $rows != 2 then return -1 diff --git a/tests/script/general/parser/udf_dll_stable.sim b/tests/script/general/parser/udf_dll_stable.sim index cd1dbc8b5374779d13decde5bf8a0fce48d90f0a..d7e987c5fd8f0a46c08b40d84775c2dcfcc221c7 100644 --- a/tests/script/general/parser/udf_dll_stable.sim +++ b/tests/script/general/parser/udf_dll_stable.sim @@ -11,7 +11,7 @@ print ======================== dnode1 start sql create function add_one as '/tmp/add_one.so' outputtype int; sql create function add_one_64232 as '/tmp/add_one_64232.so' outputtype int; -sql create aggregate function sum_double as '/tmp/sum_double.so' outputtype int; +sql create aggregate function sum_double as '/tmp/sum_double.so' outputtype bigint; sql show functions; if $rows != 3 then return -1 diff --git a/tests/script/jenkins/basic.txt b/tests/script/jenkins/basic.txt index 850f3a19467a8748bba56f80033d4fc0b0bc77a3..2696b93acedd8c116dfd0922798012c27c8e8692 100644 --- a/tests/script/jenkins/basic.txt +++ b/tests/script/jenkins/basic.txt @@ -75,7 +75,7 @@ cd ../../../debug; make ./test.sh -f general/parser/where.sim ./test.sh -f general/parser/slimit.sim ./test.sh -f general/parser/select_with_tags.sim -./test.sh -f general/parser/interp.sim +./test.sh -f general/parser/interp_full.sim ./test.sh -f general/parser/tags_dynamically_specifiy.sim ./test.sh -f general/parser/groupby.sim ./test.sh -f general/parser/set_tag_vals.sim diff --git a/tests/script/jenkins/simple.txt b/tests/script/jenkins/simple.txt index 88ff4d660131bea5dee2f5ccd0dad9d81c7bed5f..a0a2f5191768b70638aa45fa9ad97f73c91d4d86 100644 --- a/tests/script/jenkins/simple.txt +++ b/tests/script/jenkins/simple.txt @@ -138,7 +138,7 @@ cd ../../../debug; make ./test.sh -f general/parser/where.sim ./test.sh -f general/parser/slimit.sim ./test.sh -f general/parser/select_with_tags.sim -./test.sh -f general/parser/interp.sim +./test.sh -f general/parser/interp_full.sim ./test.sh -f general/parser/tags_dynamically_specifiy.sim ./test.sh -f general/parser/groupby.sim ./test.sh -f general/parser/set_tag_vals.sim diff --git a/tests/script/jenkins/wbasic.txt b/tests/script/jenkins/wbasic.txt index 984b15fc5a4e49a5e730667782b41afb8bdb6bb8..22fee77344371a634086ebf2a37a9bf5b03a7f6b 100644 --- a/tests/script/jenkins/wbasic.txt +++ b/tests/script/jenkins/wbasic.txt @@ -143,7 +143,7 @@ wtest.bat -f general/parser/fill_stb.sim wtest.bat -f general/parser/where.sim wtest.bat -f general/parser/slimit.sim wtest.bat -f general/parser/select_with_tags.sim -wtest.bat -f general/parser/interp.sim +wtest.bat -f general/parser/interp_full.sim wtest.bat -f general/parser/tags_dynamically_specifiy.sim wtest.bat -f general/parser/groupby.sim wtest.bat -f general/parser/set_tag_vals.sim diff --git a/tests/script/regressionSuite.sim b/tests/script/regressionSuite.sim index faa6672b42be666d17bafe5a6176d95cdbbc27a8..a705601d96f64f2690c3b933228b02b49d59af68 100644 --- a/tests/script/regressionSuite.sim +++ b/tests/script/regressionSuite.sim @@ -129,7 +129,7 @@ run general/parser/limit2.sim run general/parser/slimit.sim run general/parser/fill.sim run general/parser/fill_stb.sim -run general/parser/interp.sim +run general/parser/interp_full.sim run general/parser/where.sim run general/parser/join.sim run general/parser/join_multivnode.sim diff --git a/tests/script/sh/abs_max.c b/tests/script/sh/abs_max.c index e9f11feb414363eb0e741c722f4d4dd79b87e81e..9faea60374766e47f82a70880fe2b1376bbc12dc 100644 --- a/tests/script/sh/abs_max.c +++ b/tests/script/sh/abs_max.c @@ -1,11 +1,12 @@ #include #include #include +#include typedef struct SUdfInit{ int maybe_null; /* 1 if function can return NULL */ int decimals; /* for real functions */ - long long length; /* For string functions */ + int64_t length; /* For string functions */ char *ptr; /* free pointer for function data */ int const_item; /* 0 if result is independent of arguments */ } SUdfInit; @@ -14,31 +15,36 @@ typedef struct SUdfInit{ #define TSDB_DATA_INT_NULL 0x80000000L #define TSDB_DATA_BIGINT_NULL 0x8000000000000000L -void abs_max(char* data, short itype, short ibytes, int numOfRows, long long* ts, char* dataOutput, char* interBuf, char* tsOutput, +void abs_max(char* data, short itype, short ibytes, int numOfRows, int64_t* ts, char* dataOutput, char* interBuf, char* tsOutput, int* numOfOutput, short otype, short obytes, SUdfInit* buf) { int i; - long r = 0; - printf("abs_max input data:%p, type:%d, rows:%d, ts:%p,%lld, dataoutput:%p, tsOutput:%p, numOfOutput:%p, buf:%p\n", data, itype, numOfRows, ts, *ts, dataOutput, tsOutput, numOfOutput, buf); + int64_t r = 0; + // printf("abs_max input data:%p, type:%d, rows:%d, ts:%p, %" PRId64 ", dataoutput:%p, tsOutput:%p, numOfOutput:%p, buf:%p\n", data, itype, numOfRows, ts, *ts, dataOutput, tsOutput, numOfOutput, buf); if (itype == 5) { - r=*(long *)dataOutput; + r=*(int64_t *)dataOutput; *numOfOutput=0; for(i=0;i r) { r = v; } } - *(long *)dataOutput=r; + *(int64_t *)dataOutput=r; - printf("abs_max out, dataoutput:%ld, numOfOutput:%d\n", *(long *)dataOutput, *numOfOutput); - } else { + // printf("abs_max out, dataoutput:%" PRId64", numOfOutput:%d\n", *(int64_t *)dataOutput, *numOfOutput); + }else { *numOfOutput=0; } } @@ -47,44 +53,43 @@ void abs_max(char* data, short itype, short ibytes, int numOfRows, long long* ts void abs_max_finalize(char* dataOutput, char* interBuf, int* numOfOutput, SUdfInit* buf) { int i; - int r = 0; - printf("abs_max_finalize dataoutput:%p:%d, numOfOutput:%d, buf:%p\n", dataOutput, *dataOutput, *numOfOutput, buf); - - printf("abs_max finalize, dataoutput:%ld, numOfOutput:%d\n", *(long *)dataOutput, *numOfOutput); + //int64_t r = 0; + // printf("abs_max_finalize dataoutput:%p:%d, numOfOutput:%d, buf:%p\n", dataOutput, *dataOutput, *numOfOutput, buf); + // *numOfOutput=1; + // printf("abs_max finalize, dataoutput:%" PRId64", numOfOutput:%d\n", *(int64_t *)dataOutput, *numOfOutput); } void abs_max_merge(char* data, int32_t numOfRows, char* dataOutput, int32_t* numOfOutput, SUdfInit* buf) { - int r = 0; + int64_t r = 0; if (numOfRows > 0) { - r = *((long *)data); + r = *((int64_t *)data); } - printf("abs_max_merge numOfRows:%d, dataoutput:%p, buf:%p\n", numOfRows, dataOutput, buf); + // printf("abs_max_merge numOfRows:%d, dataoutput:%p, buf:%p\n", numOfRows, dataOutput, buf); for (int i = 1; i < numOfRows; ++i) { - printf("abs_max_merge %d - %ld\n", i, *((long *)data + i)); - if (*((long*)data + i) > r) { - r= *((long*)data + i); + // printf("abs_max_merge %d - %" PRId64"\n", i, *((int64_t *)data + i)); + if (*((int64_t*)data + i) > r) { + r= *((int64_t*)data + i); } } - *(long*)dataOutput=r; + *(int64_t*)dataOutput=r; if (numOfRows > 0) { *numOfOutput=1; } else { *numOfOutput=0; } - printf("abs_max_merge, dataoutput:%ld, numOfOutput:%d\n", *(long *)dataOutput, *numOfOutput); + // printf("abs_max_merge, dataoutput:%" PRId64", numOfOutput:%d\n", *(int64_t *)dataOutput, *numOfOutput); } int abs_max_init(SUdfInit* buf) { - printf("abs_max init\n"); + // printf("abs_max init\n"); return 0; } void abs_max_destroy(SUdfInit* buf) { - printf("abs_max destroy\n"); -} - + // printf("abs_max destroy\n"); +} \ No newline at end of file diff --git a/tests/script/sh/add_one.c b/tests/script/sh/add_one.c index e12cf8f26f6ddad67f9f7b091c033de46a3f6f50..de2a7d168c88d1a13bf5cbe6a327ea451ddb2546 100644 --- a/tests/script/sh/add_one.c +++ b/tests/script/sh/add_one.c @@ -14,20 +14,18 @@ void add_one(char* data, short itype, short ibytes, int numOfRows, long long* ts int* numOfOutput, short otype, short obytes, SUdfInit* buf) { int i; int r = 0; - printf("add_one input data:%p, type:%d, rows:%d, ts:%p,%lld, dataoutput:%p, tsOutput:%p, numOfOutput:%p, buf:%p\n", data, itype, numOfRows, ts, *ts, dataOutput, tsOutput, numOfOutput, buf); + // printf("add_one input data:%p, type:%d, rows:%d, ts:%p,%lld, dataoutput:%p, tsOutput:%p, numOfOutput:%p, buf:%p\n", data, itype, numOfRows, ts, *ts, dataOutput, tsOutput, numOfOutput, buf); if (itype == 4) { for(i=0;i #include #include +#include typedef struct SUdfInit{ int maybe_null; /* 1 if function can return NULL */ int decimals; /* for real functions */ - long long length; /* For string functions */ + int64_t length; /* For string functions */ char *ptr; /* free pointer for function data */ int const_item; /* 0 if result is independent of arguments */ } SUdfInit; @@ -13,13 +14,13 @@ typedef struct SUdfInit{ #define TSDB_DATA_INT_NULL 0x80000000L -void sum_double(char* data, short itype, short ibytes, int numOfRows, long long* ts, char* dataOutput, char* interBuf, char* tsOutput, +void sum_double(char* data, short itype, short ibytes, int numOfRows, int64_t* ts, char* dataOutput, char* interBuf, char* tsOutput, int* numOfOutput, short otype, short obytes, SUdfInit* buf) { int i; - int r = 0; - printf("sum_double input data:%p, type:%d, rows:%d, ts:%p,%lld, dataoutput:%p, tsOutput:%p, numOfOutput:%p, buf:%p\n", data, itype, numOfRows, ts, *ts, dataOutput, tsOutput, numOfOutput, buf); + int64_t r = 0; + printf("sum_double input data:%p, type:%d, rows:%d, ts:%p,%"PRId64", dataoutput:%p, tsOutput:%p, numOfOutput:%p, buf:%p\n", data, itype, numOfRows, ts, *ts, dataOutput, tsOutput, numOfOutput, buf); if (itype == 4) { - r=*(int *)dataOutput; + r=*(int64_t *)dataOutput; *numOfOutput=0; for(i=0;iptr)=*(int*)dataOutput*2; - *(int*)dataOutput=*(int*)(buf->ptr); - printf("sum_double finalize, dataoutput:%d, numOfOutput:%d\n", *(int *)dataOutput, *numOfOutput); + int64_t r = 0; + // printf("sum_double_finalize dataoutput:%p:%"PRId64", numOfOutput:%d, buf:%p\n", dataOutput, *(int64_t*)dataOutput, *numOfOutput, buf); + // *numOfOutput=1; + *(int64_t*)(buf->ptr)=*(int64_t*)dataOutput*2; + *(int64_t*)dataOutput=*(int64_t*)(buf->ptr); + // printf("sum_double finalize, dataoutput:%"PRId64", numOfOutput:%d\n", *(int64_t *)dataOutput, *numOfOutput); } -void sum_double_merge(char* data, int32_t numOfRows, char* dataOutput, int32_t* numOfOutput, SUdfInit* buf) { +void sum_double_merge(char* data, int32_t numOfRows, char* dataOutput, int* numOfOutput, SUdfInit* buf) { int r = 0; - int sum = 0; + int64_t sum = 0; - printf("sum_double_merge numOfRows:%d, dataoutput:%p, buf:%p\n", numOfRows, dataOutput, buf); + // printf("sum_double_merge numOfRows:%d, dataoutput:%p, buf:%p\n", numOfRows, dataOutput, buf); for (int i = 0; i < numOfRows; ++i) { - printf("sum_double_merge %d - %d\n", i, *((int*)data + i)); - sum +=*((int*)data + i); + // printf("sum_double_merge %d - %"PRId64"\n", i, *((int64_t*)data + i)); + sum +=*((int64_t*)data + i); } - *(int*)dataOutput+=sum; + *(int64_t*)dataOutput+=sum; if (numOfRows > 0) { *numOfOutput=1; } else { *numOfOutput=0; } - printf("sum_double_merge, dataoutput:%d, numOfOutput:%d\n", *(int *)dataOutput, *numOfOutput); + // printf("sum_double_merge, dataoutput:%"PRId64", numOfOutput:%d\n", *(int64_t *)dataOutput, *numOfOutput); } int sum_double_init(SUdfInit* buf) { buf->maybe_null=1; - buf->ptr = malloc(sizeof(int)); - printf("sum_double init\n"); + buf->ptr = malloc(sizeof(int64_t)); + // printf("sum_double init\n"); return 0; } void sum_double_destroy(SUdfInit* buf) { free(buf->ptr); - printf("sum_double destroy\n"); -} - + // printf("sum_double destroy\n"); +} \ No newline at end of file