diff --git a/Jenkinsfile b/Jenkinsfile index 85ba42a96edf68aaaf39d5bb51237fef381be5fb..491e70742825fb9d655ca76321085a133c4aea63 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -38,7 +38,8 @@ def pre_test(){ sudo rmtaos || echo "taosd has not installed" ''' sh ''' - killall -9 taosd ||echo "no taosd running" + kill -9 $(pidof taosd) ||echo "no taosd running" + kill -9 $(pidof taosadapter) ||echo "no taosadapter running" killall -9 gdb || echo "no gdb running" killall -9 python3.8 || echo "no python program running" cd ${WKC} @@ -104,7 +105,7 @@ def pre_test(){ git clean -dfx mkdir debug cd debug - cmake .. > /dev/null + cmake .. -DBUILD_HTTP=false > /dev/null make > /dev/null make install > /dev/null cd ${WKC}/tests @@ -178,7 +179,7 @@ def pre_test_noinstall(){ git clean -dfx mkdir debug cd debug - cmake .. > /dev/null + cmake .. -DBUILD_HTTP=false > /dev/null make ''' return 1 @@ -455,23 +456,42 @@ pipeline { nohup taosd >/dev/null & sleep 10 ''' + sh ''' - cd ${WKC}/tests/examples/nodejs - 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 - node nanosecondTest.js + cd ${WKC}/src/connector/python + export PYTHONPATH=$PWD/ + export LD_LIBRARY_PATH=${WKC}/debug/build/lib + pip3 install pytest + pytest tests/ + python3 examples/bind-multi.py + python3 examples/bind-row.py + python3 examples/demo.py + python3 examples/insert-lines.py + python3 examples/pep-249.py + python3 examples/query-async.py + python3 examples/query-objectively.py + python3 examples/subscribe-sync.py + python3 examples/subscribe-async.py + ''' + + sh ''' + cd ${WKC}/tests/examples/nodejs + 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 + node nanosecondTest.js ''' 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 + dotnet build -c Release + tree | true + ./bin/Release/net5.0/taosdemo -c /etc/taos -y ''' - } + } sh ''' cd ${WKC}/tests/gotest bash batchtest.sh @@ -583,10 +603,15 @@ pipeline { timeout(time: 55, unit: 'MINUTES'){ pre_test() sh ''' + cd ${WKC}/tests + ./test-all.sh develop-test + ''' + sh ''' date cd ${WKC}/tests ./test-all.sh b6fq date''' + } } } @@ -596,6 +621,10 @@ pipeline { timeout(time: 55, unit: 'MINUTES'){ pre_test() sh ''' + cd ${WKC}/tests + ./test-all.sh system-test + ''' + sh ''' date cd ${WKC}/tests ./test-all.sh b7fq diff --git a/README.md b/README.md index fb6eed0267c19259b5e931c8a98c19aff90d8deb..6cf09e1589946cdb752eba2f3e3135af1699fe3c 100644 --- a/README.md +++ b/README.md @@ -100,7 +100,7 @@ sudo dnf install -y maven #### Install build dependencies for taos-tools To build the [taos-tools](https://github.com/taosdata/taos-tools) on CentOS, the following packages need to be installed. ```bash -sudo yum install libz-devel xz-devel snappy-devel jansson-devel pkgconfig libatomic +sudo yum install zlib-devel xz-devel snappy-devel jansson-devel pkgconfig libatomic ``` Note: Since snappy lacks pkg-config support (refer to [link](https://github.com/google/snappy/pull/86)), it lead a cmake prompt libsnappy not found. But snappy will works well. @@ -142,15 +142,15 @@ mkdir debug && cd debug cmake .. && cmake --build . ``` -Note TDengine 2.3.x.0 and later use a component named 'taosadapter' to play http daemon role by default instead of the http daemon embedded in the early version of TDengine. The taosadapter is programmed by go language. If you pull TDengine source code to the latest from an existing codebase, please execute 'git submodule update --init --recursive' to pull taosadapter source code. Please install go language 1.14 or above for compiling taosadapter. If you meet difficulties regarding 'go mod', especially you are from China, you can use a proxy to solve the problem. +Note TDengine 2.3.x.0 and later use a component named 'taosAdapter' to play http daemon role by default instead of the http daemon embedded in the early version of TDengine. The taosAdapter is programmed by go language. If you pull TDengine source code to the latest from an existing codebase, please execute 'git submodule update --init --recursive' to pull taosAdapter source code. Please install go language 1.14 or above for compiling taosAdapter. If you meet difficulties regarding 'go mod', especially you are from China, you can use a proxy to solve the problem. ``` go env -w GO111MODULE=on go env -w GOPROXY=https://goproxy.cn,direct ``` -Or you can use the following command to choose to embed old httpd too. +The embedded http daemon still be built from TDengine source code by default. Or you can use the following command to choose to build taosAdapter. ``` -cmake .. -DBUILD_HTTP=true +cmake .. -DBUILD_HTTP=false ``` You can use Jemalloc as memory allocator instead of glibc: diff --git a/cmake/define.inc b/cmake/define.inc index 7e6293c9a9abdc82313b9d3982692b5d506f2a06..07df84a7f4df5d27020716b4d9986a578b839595 100755 --- a/cmake/define.inc +++ b/cmake/define.inc @@ -136,24 +136,25 @@ IF (TD_ALPINE) MESSAGE(STATUS "aplhine is defined") ENDIF () + IF ("${BUILD_HTTP}" STREQUAL "") IF (TD_LINUX) IF (TD_ARM_32) - SET(BUILD_HTTP "true") + SET(TD_BUILD_HTTP TRUE) ELSE () - SET(BUILD_HTTP "false") + SET(TD_BUILD_HTTP TRUE) ENDIF () ELSEIF (TD_DARWIN) - SET(BUILD_HTTP "false") + SET(TD_BUILD_HTTP TRUE) ELSE () - SET(BUILD_HTTP "true") + SET(TD_BUILD_HTTP TRUE) ENDIF () -ENDIF () - -IF (${BUILD_HTTP} MATCHES "true") - SET(TD_BUILD_HTTP TRUE) ELSEIF (${BUILD_HTTP} MATCHES "false") SET(TD_BUILD_HTTP FALSE) +ELSEIF (${BUILD_HTTP} MATCHES "true") + SET(TD_BUILD_HTTP TRUE) +ELSE () + SET(TD_BUILD_HTTP TRUE) ENDIF () IF (TD_BUILD_HTTP) diff --git a/cmake/input.inc b/cmake/input.inc index 83de94c1e20dde13cc1812d978e91ba04bfc5c7e..14ac795e7edaef2569ea4a01b4da5e3251e6d7ff 100755 --- a/cmake/input.inc +++ b/cmake/input.inc @@ -96,7 +96,7 @@ IF (${BUILD_JDBC} MATCHES "false") SET(TD_BUILD_JDBC FALSE) ENDIF () -SET(TD_BUILD_HTTP FALSE) +SET(TD_BUILD_HTTP TRUE) SET(TD_TAOS_TOOLS TRUE) diff --git a/documentation20/cn/08.connector/docs.md b/documentation20/cn/08.connector/docs.md index 8ab9c6703f6aec0fda9f9cf5720d39b4fe90ff69..9203c2cc9e24a8aaa424bb9e2ee64bd23310cc99 100644 --- a/documentation20/cn/08.connector/docs.md +++ b/documentation20/cn/08.connector/docs.md @@ -145,7 +145,7 @@ taos> | **CPU类型** | x64(64bit) | | | ARM64 | ARM32 | | ------------ | ------------ | -------- | -------- | -------- | ---------- | | **OS类型** | Linux | Win64 | Win32 | Linux | Linux | -| **支持与否** | **支持** | **支持** | **支持** | **支持** | **开发中** | +| **支持与否** | **支持** | **支持** | **支持** | **支持** | **支持** | C/C++的API类似于MySQL的C API。应用程序使用时,需要包含TDengine头文件 *taos.h*,里面列出了提供的API的函数原型。安装后,taos.h位于: diff --git a/documentation20/cn/11.administrator/docs.md b/documentation20/cn/11.administrator/docs.md index a04848553aeef04fc57b2d42b92d4b84ad29c87d..8ce6732efec4da35683913e8f73082f98f88f89d 100644 --- a/documentation20/cn/11.administrator/docs.md +++ b/documentation20/cn/11.administrator/docs.md @@ -557,7 +557,7 @@ KILL STREAM ; TDengine启动后,会自动创建一个监测数据库log,并自动将服务器的CPU、内存、硬盘空间、带宽、请求数、磁盘读写速度、慢查询等信息定时写入该数据库。TDengine还将重要的系统操作(比如登录、创建、删除数据库等)日志以及各种错误报警信息记录下来存放在log库里。系统管理员可以从CLI直接查看这个数据库,也可以在WEB通过图形化界面查看这些监测信息。 -这些监测信息的采集缺省是打开的,但可以修改配置文件里的选项enableMonitor将其关闭或打开。 +这些监测信息的采集缺省是打开的,但可以修改配置文件里的选项monitor将其关闭或打开。 ### TDinsight - 使用监控数据库 + Grafana 对 TDengine 进行监控的解决方案 diff --git a/documentation20/cn/12.taos-sql/docs.md b/documentation20/cn/12.taos-sql/docs.md index 60f183815b5aed212ffd2e01898795e6c7795741..31e1ed4cc1ba7372a276391b2711a56f63b63ecc 100644 --- a/documentation20/cn/12.taos-sql/docs.md +++ b/documentation20/cn/12.taos-sql/docs.md @@ -834,7 +834,7 @@ UNION ALL SELECT ... [UNION ALL SELECT ...] ``` -TDengine 支持 UNION ALL 操作符。也就是说,如果多个 SELECT 子句返回结果集的结构完全相同(列名、列类型、列数、顺序),那么可以通过 UNION ALL 把这些结果集合并到一起。目前只支持 UNION ALL 模式,也即在结果集的合并过程中是不去重的。 +TDengine 支持 UNION ALL 操作符。也就是说,如果多个 SELECT 子句返回结果集的结构完全相同(列名、列类型、列数、顺序),那么可以通过 UNION ALL 把这些结果集合并到一起。目前只支持 UNION ALL 模式,也即在结果集的合并过程中是不去重的。在同一个sql语句中,UNION ALL 最多支持100个。 ### SQL 示例 diff --git a/documentation20/en/00.index/docs.md b/documentation20/en/00.index/docs.md index 15f742e8b2935be70926341499dd357ee957b992..28905c340a99223e480603ca3ba6151772bada47 100644 --- a/documentation20/en/00.index/docs.md +++ b/documentation20/en/00.index/docs.md @@ -113,7 +113,7 @@ TDengine is a highly efficient platform to store, query, and analyze time-series - [System Connection and Task Query Management](/administrator#status): show the system connections, queries, streaming calculation and others - [System Monitor](/administrator#monitoring): monitor TDengine cluster with log database and TDinsight. - [File Directory Structure](/administrator#directories): directories where TDengine data files and configuration files located -- [Parameter Limitss and Reserved Keywords](/administrator#keywords): TDengine’s list of parameter limits and reserved keywords +- [Parameter Limits and Reserved Keywords](/administrator#keywords): TDengine’s list of parameter limits and reserved keywords ## Performance: TDengine vs Others diff --git a/documentation20/en/02.getting-started/02.taosdemo/docs.md b/documentation20/en/02.getting-started/02.taosdemo/docs.md index 318c4d09581672b317f487477e655bdb5bd49d13..750983c85e8ebcd896587df98af83ce20b23ac28 100644 --- a/documentation20/en/02.getting-started/02.taosdemo/docs.md +++ b/documentation20/en/02.getting-started/02.taosdemo/docs.md @@ -1,4 +1,4 @@ -Since TDengine was open sourced in July 2019, it has gained a lot of popularity among time-series database developers with its innovative data modeling design, simple installation mehtod, easy programming interface, and powerful data insertion and query performance. The insertion and querying performance is often astonishing to users who are new to TDengine. In order to help users to experience the high performance and functions of TDengine in the shortest time, we developed an application called taosdemo for insertion and querying performance testing of TDengine. Then user can easily simulate the scenario of a large number of devices generating a very large amount of data. User can easily maniplate the number of columns, data types, disorder ratio, and number of concurrent threads with taosdemo customized parameters. +Since TDengine was open sourced in July 2019, it has gained a lot of popularity among time-series database developers with its innovative data modeling design, simple installation method, easy programming interface, and powerful data insertion and query performance. The insertion and querying performance is often astonishing to users who are new to TDengine. In order to help users to experience the high performance and functions of TDengine in the shortest time, we developed an application called taosdemo for insertion and querying performance testing of TDengine. Then user can easily simulate the scenario of a large number of devices generating a very large amount of data. User can easily manipulate the number of columns, data types, disorder ratio, and number of concurrent threads with taosdemo customized parameters. Running taosdemo is very simple. Just download the TDengine installation package (https://www.taosdata.com/cn/all-downloads/) or compiling the TDengine code yourself (https://github.com/taosdata/TDengine). It can be found and run in the installation directory or in the compiled results directory. @@ -221,7 +221,7 @@ To reach TDengine performance limits, data insertion can be executed by using mu ``` -t, --tables=NUMBER The number of tables. Default is 10000. -n, --records=NUMBER The number of records per table. Default is 10000. --M, --random The value of records generated are totally random. The default is to simulate power equipment senario. +-M, --random The value of records generated are totally random. The default is to simulate power equipment scenario. ``` As mentioned earlier, taosdemo creates 10,000 tables by default, and each table writes 10,000 records. taosdemo can set the number of tables and the number of records in each table by -t and -n. The data generated by default without parameters are simulated real scenarios, and the simulated data are current and voltage phase values with certain jitter, which can more realistically show TDengine's efficient data compression ability. If you need to simulate the generation of completely random data, you can pass the -M parameter. ``` diff --git a/documentation20/en/03.architecture/docs.md b/documentation20/en/03.architecture/docs.md index 3236b8aff8777836af492d2066a530c32a9ab75e..0700c6f9b89d8820fdada2dd37bd2c7ece9f441c 100644 --- a/documentation20/en/03.architecture/docs.md +++ b/documentation20/en/03.architecture/docs.md @@ -193,7 +193,7 @@ A complete TDengine system runs on one or more physical nodes. Logically, it inc **Redirection**: No matter about dnode or TAOSC, the connection to the mnode shall be initiated first, but the mnode is automatically created and maintained by the system, so the user does not know which dnode is running the mnode. TDengine only requires a connection to any working dnode in the system. Because any running dnode maintains the currently running mnode EP List, when receiving a connecting request from the newly started dnode or TAOSC, if it’s not a mnode by self, it will reply to the mnode EP List back. After receiving this list, TAOSC or the newly started dnode will try to establish the connection again. When the mnode EP List changes, each data node quickly obtains the latest list and notifies TAOSC through messaging interaction among nodes. -### A Typical Data Writinfg Process +### A Typical Data Writing Process To explain the relationship between vnode, mnode, TAOSC and application and their respective roles, the following is an analysis of a typical data writing process. @@ -244,7 +244,7 @@ The meta data of each table (including schema, tags, etc.) is also stored in vno ### Data Partitioning -In addition to vnode sharding, TDengine partitions the time-series data by time range. Each data file contains only one time range of time-series data, and the length of the time range is determined by DB's configuration parameter `“days”`. This method of partitioning by time rang is also convenient to efficiently implement the data retention policy. As long as the data file exceeds the specified number of days (system configuration parameter `“keep”`), it will be automatically deleted. Moreover, different time ranges can be stored in different paths and storage media, so as to facilitate the tiered-storage. Cold/hot data can be stored in different storage meida to reduce the storage cost. +In addition to vnode sharding, TDengine partitions the time-series data by time range. Each data file contains only one time range of time-series data, and the length of the time range is determined by DB's configuration parameter `“days”`. This method of partitioning by time rang is also convenient to efficiently implement the data retention policy. As long as the data file exceeds the specified number of days (system configuration parameter `“keep”`), it will be automatically deleted. Moreover, different time ranges can be stored in different paths and storage media, so as to facilitate the tiered-storage. Cold/hot data can be stored in different storage media to reduce the storage cost. In general, **TDengine splits big data by vnode and time range in two dimensions** to manage the data efficiently with horizontal scalability. diff --git a/documentation20/en/05.insert/docs.md b/documentation20/en/05.insert/docs.md index 2e104b980a91c9ee72d93e41fbf0d4276694d1ef..7abecfda380b1219a6c5d407d48e7876eecd55ea 100644 --- a/documentation20/en/05.insert/docs.md +++ b/documentation20/en/05.insert/docs.md @@ -107,11 +107,10 @@ Launch an API service for blm_prometheus with the following command: Assuming that the IP address of the server where blm_prometheus located is "10.1.2. 3", the URL shall be added to the configuration file of Prometheus as: +```yaml remote_write: - -\- url: "http://10.1.2.3:8088/receive" - - + - url: "http://10.1.2.3:8088/receive" +``` ### Query written data of prometheus @@ -183,7 +182,7 @@ In the output plugins section, add the [[outputs.http]] configuration: In agent section: - hostname: The machine name that distinguishes different collection devices, and it is necessary to ensure its uniqueness -- metric_batch_size: 100, which is the max number of records per batch wriiten by Telegraf allowed. Increasing the number can reduce the request sending frequency of Telegraf. +- metric_batch_size: 100, which is the max number of records per batch written by Telegraf allowed. Increasing the number can reduce the request sending frequency of Telegraf. For information on how to use Telegraf to collect data and more about using Telegraf, please refer to the official [document](https://docs.influxdata.com/telegraf/v1.11/) of Telegraf. diff --git a/documentation20/en/06.queries/docs.md b/documentation20/en/06.queries/docs.md index d906443153bb7e83cee69da4588554893ce154a3..5ba73f297fbe346b54469f24a3a43adb617b31a6 100644 --- a/documentation20/en/06.queries/docs.md +++ b/documentation20/en/06.queries/docs.md @@ -11,7 +11,7 @@ TDengine uses SQL as the query language. Applications can send SQL statements th - Time stamp aligned join query (implicit join) operations - Multiple aggregation/calculation functions: count, max, min, avg, sum, twa, stddev, leastsquares, top, bottom, first, last, percentile, apercentile, last_row, spread, diff, etc -For example, in TAOS shell, the records with vlotage > 215 are queried from table d1001, sorted in descending order by timestamps, and only two records are outputted. +For example, in TAOS shell, the records with voltage > 215 are queried from table d1001, sorted in descending order by timestamps, and only two records are outputted. ```mysql taos> select * from d1001 where voltage > 215 order by ts desc limit 2; diff --git a/documentation20/en/07.advanced-features/docs.md b/documentation20/en/07.advanced-features/docs.md index 38c70862b637daf5840606535971e412d938b9e8..0bf10183c6babf82744e073ab0cd892602a381d9 100644 --- a/documentation20/en/07.advanced-features/docs.md +++ b/documentation20/en/07.advanced-features/docs.md @@ -110,10 +110,10 @@ First, use `taos_subscribe` to create a subscription: ```c TAOS_SUB* tsub = NULL; if (async) { -  // create an asynchronized subscription, the callback function will be called every 1s +  // create an asynchronous subscription, the callback function will be called every 1s   tsub = taos_subscribe(taos, restart, topic, sql, subscribe_callback, &blockFetch, 1000); } else { -  // create an synchronized subscription, need to call 'taos_consume' manually +  // create an synchronous subscription, need to call 'taos_consume' manually   tsub = taos_subscribe(taos, restart, topic, sql, NULL, NULL, 0); } ``` @@ -201,7 +201,7 @@ taos_unsubscribe(tsub, keep); Its second parameter is used to decide whether to keep the progress information of subscription on the client. If this parameter is **false** (zero), the subscription can only be restarted no matter what the `restart` parameter is when `taos_subscribe` is called next time. In addition, progress information is saved in the directory {DataDir}/subscribe/. Each subscription has a file with the same name as its `topic`. Deleting a file will also lead to a new start when the corresponding subscription is created next time. -After introducing the code, let's take a look at the actual running effect. For exmaple: +After introducing the code, let's take a look at the actual running effect. For example: - Sample code has been downloaded locally - TDengine has been installed on the same machine diff --git a/documentation20/en/08.connector/01.java/docs.md b/documentation20/en/08.connector/01.java/docs.md index 75cc380c141383cce0bc3c9790c91fa97563e3ca..448921349fc0c051effc8a1d7e1a69496cff1199 100644 --- a/documentation20/en/08.connector/01.java/docs.md +++ b/documentation20/en/08.connector/01.java/docs.md @@ -54,33 +54,33 @@ INSERT INTO test.t1 USING test.weather (ts, temperature) TAGS('beijing') VALUES( ## JDBC driver version and supported TDengine and JDK versions -| taos-jdbcdriver | TDengine | JDK | -| -------------------- | ----------------- | -------- | -| 2.0.33 - 2.0.34 | 2.0.3.0 and above | 1.8.x | -| 2.0.31 - 2.0.32 | 2.1.3.0 and above | 1.8.x | -| 2.0.22 - 2.0.30 | 2.0.18.0 - 2.1.2.x | 1.8.x | -| 2.0.12 - 2.0.21 | 2.0.8.0 - 2.0.17.x | 1.8.x | -| 2.0.4 - 2.0.11 | 2.0.0.0 - 2.0.7.x | 1.8.x | -| 1.0.3 | 1.6.1.x and above | 1.8.x | -| 1.0.2 | 1.6.1.x and above | 1.8.x | -| 1.0.1 | 1.6.1.x and above | 1.8.x | +| taos-jdbcdriver | TDengine | JDK | +| --------------- | ------------------ | ----- | +| 2.0.33 - 2.0.34 | 2.0.3.0 and above | 1.8.x | +| 2.0.31 - 2.0.32 | 2.1.3.0 and above | 1.8.x | +| 2.0.22 - 2.0.30 | 2.0.18.0 - 2.1.2.x | 1.8.x | +| 2.0.12 - 2.0.21 | 2.0.8.0 - 2.0.17.x | 1.8.x | +| 2.0.4 - 2.0.11 | 2.0.0.0 - 2.0.7.x | 1.8.x | +| 1.0.3 | 1.6.1.x and above | 1.8.x | +| 1.0.2 | 1.6.1.x and above | 1.8.x | +| 1.0.1 | 1.6.1.x and above | 1.8.x | ## DataType in TDengine and Java connector The TDengine supports the following data types and Java data types: | TDengine DataType | JDBCType (driver version < 2.0.24) | JDBCType (driver version >= 2.0.24) | -| ----------------- | ------------------ | ------------------ | -| TIMESTAMP | java.lang.Long | java.sql.Timestamp | -| INT | java.lang.Integer | java.lang.Integer | -| BIGINT | java.lang.Long | java.lang.Long | -| FLOAT | java.lang.Float | java.lang.Float | -| DOUBLE | java.lang.Double | java.lang.Double | -| SMALLINT | java.lang.Short | java.lang.Short | -| TINYINT | java.lang.Byte | java.lang.Byte | -| BOOL | java.lang.Boolean | java.lang.Boolean | -| BINARY | java.lang.String | byte array | -| NCHAR | java.lang.String | java.lang.String | +| ----------------- | ---------------------------------- | ----------------------------------- | +| TIMESTAMP | java.lang.Long | java.sql.Timestamp | +| INT | java.lang.Integer | java.lang.Integer | +| BIGINT | java.lang.Long | java.lang.Long | +| FLOAT | java.lang.Float | java.lang.Float | +| DOUBLE | java.lang.Double | java.lang.Double | +| SMALLINT | java.lang.Short | java.lang.Short | +| TINYINT | java.lang.Byte | java.lang.Byte | +| BOOL | java.lang.Boolean | java.lang.Boolean | +| BINARY | java.lang.String | byte array | +| NCHAR | java.lang.String | java.lang.String | ## Install Java connector @@ -448,7 +448,7 @@ public static void main(String[] args) throws SQLException { config.setMinimumIdle(10); //minimum number of idle connection config.setMaximumPoolSize(10); //maximum number of connection in the pool config.setConnectionTimeout(30000); //maximum wait milliseconds for get connection from pool - config.setMaxLifetime(0); // maximum life time for each connection + config.setMaxLifetime(0); // maximum lifetime for each connection config.setIdleTimeout(0); // max idle time for recycle idle connection config.setConnectionTestQuery("select server_status()"); //validation query HikariDataSource ds = new HikariDataSource(config); //create datasource @@ -456,7 +456,7 @@ public static void main(String[] args) throws SQLException { Statement statement = connection.createStatement(); // get statement //query or insert // ... - connection.close(); // put back to conneciton pool + connection.close(); // put back to connection pool } ``` @@ -480,7 +480,7 @@ public static void main(String[] args) throws Exception { Statement statement = connection.createStatement(); // get statement //query or insert // ... - connection.close(); // put back to conneciton pool + connection.close(); // put back to connection pool } ``` diff --git a/documentation20/en/08.connector/02.rust/docs.md b/documentation20/en/08.connector/02.rust/docs.md index ffb6b6ceb3eef79a41557e93dec9b8fff3d084fc..583d8fd2ceb7346ee8143d75898d4e15e8bc7301 100644 --- a/documentation20/en/08.connector/02.rust/docs.md +++ b/documentation20/en/08.connector/02.rust/docs.md @@ -15,7 +15,7 @@ if you use the default features, it'll depend on: - [TDengine Client](https://www.taosdata.com/cn/getting-started/#%E9%80%9A%E8%BF%87%E5%AE%89%E8%A3%85%E5%8C%85%E5%AE%89%E8%A3%85) library and headers. - clang because bindgen will requires the clang AST library. -## Fetures +## Features In-design features: diff --git a/documentation20/en/08.connector/docs.md b/documentation20/en/08.connector/docs.md index da3c455a6dc83f7ee513f23a25793c31ee6c11b0..2a67c65c16ea11873e65c87fb6d059ac82dfc9ec 100644 --- a/documentation20/en/08.connector/docs.md +++ b/documentation20/en/08.connector/docs.md @@ -154,7 +154,7 @@ Under cmd, enter the c:\TDengine directory and directly execute taos.exe, and yo | **CPU Type** | **x64****(****64bit****)** | | | **ARM64** | **ARM32** | | -------------------- | ---------------------------- | ------- | ------- | --------- | ------------------ | | **OS Type** | Linux | Win64 | Win32 | Linux | Linux | -| **Supported or Not** | Yes | **Yes** | **Yes** | **Yes** | **In development** | +| **Supported or Not** | Yes | **Yes** | **Yes** | **Yes** | **Yes** | The C/C++ API is similar to MySQL's C API. When application use it, it needs to include the TDengine header file taos.h (after installed, it is located in/usr/local/taos/include): @@ -884,7 +884,7 @@ dotnet new console ``` cmd dotnet add package TDengine.Connector ``` -* inlucde the TDnengineDriver in you application's namespace +* include the TDnengineDriver in you application's namespace ```C# using TDengineDriver; ``` diff --git a/documentation20/en/12.taos-sql/docs.md b/documentation20/en/12.taos-sql/docs.md index 7f9754e80fcf97962177d2690c233cae23f8d491..8533f92a3b59e27df61c16a2bc86961775bf84da 100644 --- a/documentation20/en/12.taos-sql/docs.md +++ b/documentation20/en/12.taos-sql/docs.md @@ -228,7 +228,7 @@ Note: In 2.0.15.0 and later versions, STABLE reserved words are supported. That ```mysql CREATE STABLE [IF NOT EXISTS] stb_name (timestamp_field_name TIMESTAMP, field1_name data_type1 [, field2_name data_type2 ...]) TAGS (tag1_name tag_type1, tag2_name tag_type2 [, tag3_name tag_type3]); ``` - Similiar to a standard table creation SQL, but you need to specify name and type of TAGS field. + Similar to a standard table creation SQL, but you need to specify name and type of TAGS field. Note: @@ -673,7 +673,7 @@ Query OK, 1 row(s) in set (0.001091s) SELECT * FROM tb1 WHERE ts >= NOW - 1h; ``` -- Look up table tb1 from 2018-06-01 08:00:00. 000 to 2018-06-02 08:00:00. 000, and col3 string is a record ending in'nny ', and the result is in descending order of timestamp: +- Look up table tb1 from 2018-06-01 08:00:00. 000 to 2018-06-02 08:00:00. 000, and col3 string is a record ending in 'nny ', and the result is in descending order of timestamp: ```mysql SELECT * FROM tb1 WHERE ts > '2018-06-01 08:00:00.000' AND ts <= '2018-06-02 08:00:00.000' AND col3 LIKE '%nny' ORDER BY ts DESC; @@ -782,7 +782,7 @@ TDengine supports aggregations over data, they are listed below: Function: return the sum of a statistics/STable. - Return Data Type: long integer INMT64 and Double. + Return Data Type: INT64 and Double. Applicable Fields: All types except timestamp, binary, nchar, bool. @@ -1196,7 +1196,7 @@ SELECT function_list FROM stb_name - FILL statement specifies a filling mode when data missed in a certain interval. Applicable filling modes include the following: - 1. Do not fill: NONE (default filingl mode). + 1. Do not fill: NONE (default filing mode). 2. VALUE filling: Fixed value filling, where the filled value needs to be specified. For example: fill (VALUE, 1.23). 3. NULL filling: Fill the data with NULL. For example: fill (NULL). 4. PREV filling: Filling data with the previous non-NULL value. For example: fill (PREV). diff --git a/documentation20/en/14.devops/03.immigrate/docs.md b/documentation20/en/14.devops/03.immigrate/docs.md index ebba18710f6218ce7043b563a99246ccf62035f9..3a00649d30e0db76ba971b5cc0771fd71e5e9920 100644 --- a/documentation20/en/14.devops/03.immigrate/docs.md +++ b/documentation20/en/14.devops/03.immigrate/docs.md @@ -28,7 +28,7 @@ The overall system architecture of a typical DevOps application scenario is show In this application scenario, there are Agent tools deployed in the application environment to collect machine metrics, network metrics, and application metrics, data collectors to aggregate information collected by agents, systems for data persistence storage and management, and tools for monitoring data visualization (e.g., Grafana, etc.). -Among them, Agents deployed in application nodes are responsible for providing operational metrics from different sources to collectd/Statsd, and collectd/StatsD is responsible for pushing the aggregated data to the OpenTSDB cluster system and then visualizing the data using the visualization kanban board Grafana. +Among them, Agents deployed in application nodes are responsible for providing operational metrics from different sources to collectd/Statsd, and collectd/StatsD is responsible for pushing the aggregated data to the OpenTSDB cluster system and then visualizing the data using the visualization board of Grafana. ### 2. Migration Service @@ -127,11 +127,11 @@ On the one hand, TDengine requires a strict schema definition for its incoming d Now let's assume a DevOps scenario where we use collectd to collect base metrics of devices, including memory, swap, disk, etc. The schema in OpenTSDB is as follows: -| No. | metric | value | type | 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 | +| No. | metric | value | type | 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 | diff --git a/packaging/cfg/taosd.service b/packaging/cfg/taosd.service index fff4b74e62a6da8f2bda9a6306a79132d7585e42..452488b4e951e36c043c823e17cca5ab7dbfd21b 100644 --- a/packaging/cfg/taosd.service +++ b/packaging/cfg/taosd.service @@ -1,7 +1,7 @@ [Unit] Description=TDengine server service -After=network-online.target -Wants=network-online.target +After=network-online.target taosadapter.service +Wants=network-online.target taosadapter.service [Service] Type=simple diff --git a/packaging/deb/makedeb.sh b/packaging/deb/makedeb.sh index de365ae127bfb0509d8a3d67bc37e576bd61dc0f..f2d6dcde4b2eb8e7b5ff8eb06067a8426e1d3f91 100755 --- a/packaging/deb/makedeb.sh +++ b/packaging/deb/makedeb.sh @@ -58,7 +58,6 @@ cp ${compile_dir}/../packaging/tools/startPre.sh ${pkg_dir}${install_home_pat cp ${compile_dir}/../packaging/tools/set_core.sh ${pkg_dir}${install_home_path}/bin cp ${compile_dir}/../packaging/tools/taosd-dump-cfg.gdb ${pkg_dir}${install_home_path}/bin -cp ${compile_dir}/build/bin/taosdemo ${pkg_dir}${install_home_path}/bin cp ${compile_dir}/build/bin/taosd ${pkg_dir}${install_home_path}/bin if [ -f "${compile_dir}/build/bin/taosadapter" ]; then diff --git a/packaging/docker/Dockerfile b/packaging/docker/Dockerfile index c49bc0a8a356c960e27f3231c3e901de6d9a72ef..a54e9ca499330855b22daf523286ea5bbc509bb8 100644 --- a/packaging/docker/Dockerfile +++ b/packaging/docker/Dockerfile @@ -18,5 +18,5 @@ ENV LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/usr/lib" \ LC_ALL=en_US.UTF-8 EXPOSE 6030 6031 6032 6033 6034 6035 6036 6037 6038 6039 6040 6041 6042 -CMD ["taosd"] -VOLUME [ "/var/lib/taos", "/var/log/taos","/etc/taos/" ] \ No newline at end of file +CMD ["run_taosd.sh"] +VOLUME [ "/var/lib/taos", "/var/log/taos","/etc/taos/" ] diff --git a/packaging/release.sh b/packaging/release.sh index 19a0a7702bb25bf60efd9bff4af166a1336d721f..ca8715f68430fc08b86f008936ddfc9409ae58a8 100755 --- a/packaging/release.sh +++ b/packaging/release.sh @@ -3,7 +3,7 @@ # Generate the deb package for ubuntu, or rpm package for centos, or tar.gz package for other linux os set -e -#set -x +set -x # release.sh -v [cluster | edge] # -c [aarch32 | aarch64 | x64 | x86 | mips64 ...] @@ -414,10 +414,14 @@ fi if [[ "$httpdBuild" == "true" ]]; then BUILD_HTTP=true - BUILD_TOOLS=false else BUILD_HTTP=false +fi + +if [[ "$pagMode" == "full" ]]; then BUILD_TOOLS=true +else + BUILD_TOOLS=false fi # check support cpu type @@ -514,15 +518,17 @@ if [ "$osType" != "Darwin" ]; then cd ${script_dir}/deb ${csudo} ./makedeb.sh ${compile_dir} ${output_dir} ${verNumber} ${cpuType} ${osType} ${verMode} ${verType} - if [ -d ${top_dir}/src/kit/taos-tools/packaging/deb ]; then - cd ${top_dir}/src/kit/taos-tools/packaging/deb - [ -z "$taos_tools_ver" ] && taos_tools_ver="0.1.0" + if [[ "$pagMode" == "full" ]]; then + if [ -d ${top_dir}/src/kit/taos-tools/packaging/deb ]; then + cd ${top_dir}/src/kit/taos-tools/packaging/deb + [ -z "$taos_tools_ver" ] && taos_tools_ver="0.1.0" - taos_tools_ver=$(git describe --tags|sed -e 's/ver-//g') - ${csudo} ./make-taos-tools-deb.sh ${top_dir} \ - ${compile_dir} ${output_dir} ${taos_tools_ver} ${cpuType} ${osType} ${verMode} ${verType} + taos_tools_ver=$(git describe --tags|sed -e 's/ver-//g'|awk -F '-' '{print $1}') + ${csudo} ./make-taos-tools-deb.sh ${top_dir} \ + ${compile_dir} ${output_dir} ${taos_tools_ver} ${cpuType} ${osType} ${verMode} ${verType} + fi fi - else + else echo "==========dpkg command not exist, so not release deb package!!!" fi ret='0' @@ -537,15 +543,17 @@ if [ "$osType" != "Darwin" ]; then cd ${script_dir}/rpm ${csudo} ./makerpm.sh ${compile_dir} ${output_dir} ${verNumber} ${cpuType} ${osType} ${verMode} ${verType} - if [ -d ${top_dir}/src/kit/taos-tools/packaging/rpm ]; then - cd ${top_dir}/src/kit/taos-tools/packaging/rpm - [ -z "$taos_tools_ver" ] && taos_tools_ver="0.1.0" + if [[ "$pagMode" == "full" ]]; then + if [ -d ${top_dir}/src/kit/taos-tools/packaging/rpm ]; then + cd ${top_dir}/src/kit/taos-tools/packaging/rpm + [ -z "$taos_tools_ver" ] && taos_tools_ver="0.1.0" - taos_tools_ver=$(git describe --tags|sed -e 's/ver-//g'|sed -e 's/-/_/g') - ${csudo} ./make-taos-tools-rpm.sh ${top_dir} \ - ${compile_dir} ${output_dir} ${taos_tools_ver} ${cpuType} ${osType} ${verMode} ${verType} + taos_tools_ver=$(git describe --tags|sed -e 's/ver-//g'|awk -F '-' '{print $1}'|sed -e 's/-/_/g') + ${csudo} ./make-taos-tools-rpm.sh ${top_dir} \ + ${compile_dir} ${output_dir} ${taos_tools_ver} ${cpuType} ${osType} ${verMode} ${verType} + fi fi - else + else echo "==========rpmbuild command not exist, so not release rpm package!!!" fi fi diff --git a/packaging/rpm/tdengine.spec b/packaging/rpm/tdengine.spec index 31e5e49ab4deef817da89afbefa1b6dd18ad07cd..e1a8a9f9f6aee3ebe7fbcdacd579235cde7165e8 100644 --- a/packaging/rpm/tdengine.spec +++ b/packaging/rpm/tdengine.spec @@ -71,7 +71,6 @@ cp %{_compiledir}/build/bin/taosd %{buildroot}%{homepath}/bin if [ -f %{_compiledir}/build/bin/taosadapter ]; then cp %{_compiledir}/build/bin/taosadapter %{buildroot}%{homepath}/bin ||: fi -cp %{_compiledir}/build/bin/taosdemo %{buildroot}%{homepath}/bin cp %{_compiledir}/build/lib/${libfile} %{buildroot}%{homepath}/driver cp %{_compiledir}/../src/inc/taos.h %{buildroot}%{homepath}/include cp %{_compiledir}/../src/inc/taosdef.h %{buildroot}%{homepath}/include @@ -196,7 +195,6 @@ if [ $1 -eq 0 ];then ${csudo} rm -f ${bin_link_dir}/taos || : ${csudo} rm -f ${bin_link_dir}/taosd || : ${csudo} rm -f ${bin_link_dir}/taosadapter || : - ${csudo} rm -f ${bin_link_dir}/taosdemo || : ${csudo} rm -f ${cfg_link_dir}/* || : ${csudo} rm -f ${inc_link_dir}/taos.h || : ${csudo} rm -f ${inc_link_dir}/taosdef.h || : diff --git a/packaging/tools/install.sh b/packaging/tools/install.sh index 95bf3e7b74f6e0f782a8cd5caefd196510358f87..6d007c0dd1527c281b09bf1f3623eab873b235d6 100755 --- a/packaging/tools/install.sh +++ b/packaging/tools/install.sh @@ -185,23 +185,25 @@ function install_bin() { # Remove links ${csudo} rm -f ${bin_link_dir}/taos || : ${csudo} rm -f ${bin_link_dir}/taosd || : - ${csudo} rm -f ${bin_link_dir}/taosadapter || : + ${csudo} rm -f ${bin_link_dir}/taosadapter || : ${csudo} rm -f ${bin_link_dir}/taosdemo || : ${csudo} rm -f ${bin_link_dir}/taosdump || : ${csudo} rm -f ${bin_link_dir}/rmtaos || : - ${csudo} rm -f ${bin_link_dir}/tarbitrator || : - ${csudo} rm -f ${bin_link_dir}/set_core || : + ${csudo} rm -f ${bin_link_dir}/tarbitrator || : + ${csudo} rm -f ${bin_link_dir}/set_core || : + ${csudo} rm -f ${bin_link_dir}/run_taosd.sh || : ${csudo} cp -r ${script_dir}/bin/* ${install_main_dir}/bin && ${csudo} chmod 0555 ${install_main_dir}/bin/* #Make link [ -x ${install_main_dir}/bin/taos ] && ${csudo} ln -s ${install_main_dir}/bin/taos ${bin_link_dir}/taos || : [ -x ${install_main_dir}/bin/taosd ] && ${csudo} ln -s ${install_main_dir}/bin/taosd ${bin_link_dir}/taosd || : - [ -x ${install_main_dir}/bin/taosadapter ] && ${csudo} ln -s ${install_main_dir}/bin/taosadapter ${bin_link_dir}/taosadapter || : + [ -x ${install_main_dir}/bin/taosadapter ] && ${csudo} ln -s ${install_main_dir}/bin/taosadapter ${bin_link_dir}/taosadapter || : [ -x ${install_main_dir}/bin/taosdemo ] && ${csudo} ln -s ${install_main_dir}/bin/taosdemo ${bin_link_dir}/taosdemo || : [ -x ${install_main_dir}/bin/taosdump ] && ${csudo} ln -s ${install_main_dir}/bin/taosdump ${bin_link_dir}/taosdump || : [ -x ${install_main_dir}/bin/remove.sh ] && ${csudo} ln -s ${install_main_dir}/bin/remove.sh ${bin_link_dir}/rmtaos || : [ -x ${install_main_dir}/bin/set_core.sh ] && ${csudo} ln -s ${install_main_dir}/bin/set_core.sh ${bin_link_dir}/set_core || : + [ -x ${install_main_dir}/bin/run_taosd.sh ] && ${csudo} ln -s ${install_main_dir}/bin/run_taosd.sh ${bin_link_dir}/run_taosd.sh || : [ -x ${install_main_dir}/bin/tarbitrator ] && ${csudo} ln -s ${install_main_dir}/bin/tarbitrator ${bin_link_dir}/tarbitrator || : if [ "$verMode" == "cluster" ]; then @@ -887,8 +889,8 @@ function update_TDengine() { fi tar -zxf taos.tar.gz install_jemalloc - install_avro lib - install_avro lib64 + #install_avro lib + #install_avro lib64 echo -e "${GREEN}Start to update TDengine...${NC}" # Stop the service if running @@ -1001,8 +1003,8 @@ function install_TDengine() { install_header install_lib install_jemalloc - install_avro lib - install_avro lib64 + #install_avro lib + #install_avro lib64 if [ "$pagMode" != "lite" ]; then install_connector diff --git a/packaging/tools/install_client_jh.sh b/packaging/tools/install_client_jh.sh index cccf0a97be053796099d5b5f4a2c3db018c24955..a8599812feaea06120aa3391771e7c94523a53c2 100755 --- a/packaging/tools/install_client_jh.sh +++ b/packaging/tools/install_client_jh.sh @@ -188,9 +188,6 @@ function update() { install_log install_header install_lib - if [ "$pagMode" != "lite" ]; then - install_connector - fi install_examples install_bin install_config @@ -215,9 +212,6 @@ function install() { install_log install_header install_lib - if [ "$pagMode" != "lite" ]; then - install_connector - fi install_examples install_bin install_config diff --git a/packaging/tools/install_client_kh.sh b/packaging/tools/install_client_kh.sh index 210fd27fb6978527d76f0c915d0293370b93cf3e..3e7df18486a20b9ea75dba3d2644d46bee6b423b 100755 --- a/packaging/tools/install_client_kh.sh +++ b/packaging/tools/install_client_kh.sh @@ -189,9 +189,6 @@ function update() { install_log install_header install_lib - if [ "$pagMode" != "lite" ]; then - install_connector - fi install_examples install_bin install_config @@ -216,9 +213,6 @@ function install() { install_log install_header install_lib - if [ "$pagMode" != "lite" ]; then - install_connector - fi install_examples install_bin install_config diff --git a/packaging/tools/install_client_power.sh b/packaging/tools/install_client_power.sh index f96b0134dc34f61425410360d0b0f935da7b39e5..3c9abddb09646ea54f44e28664afea49822055f6 100755 --- a/packaging/tools/install_client_power.sh +++ b/packaging/tools/install_client_power.sh @@ -247,9 +247,6 @@ function update_PowerDB() { install_log install_header install_lib - if [ "$pagMode" != "lite" ]; then - install_connector - fi install_examples install_bin install_config @@ -275,9 +272,6 @@ function install_PowerDB() { install_header install_lib install_jemalloc - if [ "$pagMode" != "lite" ]; then - install_connector - fi install_examples install_bin install_config diff --git a/packaging/tools/install_client_pro.sh b/packaging/tools/install_client_pro.sh index c21f9d2e6aa685096eb55dcc03924bf453906b8f..e34dc6d4ac1d1ef1715ff903b38b1a8735001985 100755 --- a/packaging/tools/install_client_pro.sh +++ b/packaging/tools/install_client_pro.sh @@ -189,9 +189,6 @@ function update_prodb() { install_log install_header install_lib - if [ "$pagMode" != "lite" ]; then - install_connector - fi install_examples install_bin install_config @@ -216,9 +213,6 @@ function install_prodb() { install_log install_header install_lib - if [ "$pagMode" != "lite" ]; then - install_connector - fi install_examples install_bin install_config diff --git a/packaging/tools/install_client_tq.sh b/packaging/tools/install_client_tq.sh index 31a75f4fe74fbb4c68942f226602fa2117e1a01c..b7f10324dcd1c62fee20fe11399fbb61d8a38577 100755 --- a/packaging/tools/install_client_tq.sh +++ b/packaging/tools/install_client_tq.sh @@ -193,9 +193,6 @@ function update_tq() { install_log install_header install_lib - if [ "$pagMode" != "lite" ]; then - install_connector - fi install_examples install_bin install_config @@ -220,9 +217,6 @@ function install_tq() { install_log install_header install_lib - if [ "$pagMode" != "lite" ]; then - install_connector - fi install_examples install_bin install_config diff --git a/packaging/tools/install_jh.sh b/packaging/tools/install_jh.sh index c97a882b37388b3fb364f272140974571291d940..ecc166fba10ef4c3f8e0bacc04ff27ebf717e409 100755 --- a/packaging/tools/install_jh.sh +++ b/packaging/tools/install_jh.sh @@ -172,6 +172,7 @@ function install_bin() { ${csudo} rm -f ${bin_link_dir}/rmjh || : ${csudo} rm -f ${bin_link_dir}/tarbitrator || : ${csudo} rm -f ${bin_link_dir}/set_core || : + ${csudo} rm -f ${bin_link_dir}/run_taosd.sh || : ${csudo} cp -r ${script_dir}/bin/* ${install_main_dir}/bin && ${csudo} chmod 0555 ${install_main_dir}/bin/* @@ -181,6 +182,7 @@ function install_bin() { [ -x ${install_main_dir}/bin/jhdemo ] && ${csudo} ln -s ${install_main_dir}/bin/jhdemo ${bin_link_dir}/jhdemo || : [ -x ${install_main_dir}/bin/remove_jh.sh ] && ${csudo} ln -s ${install_main_dir}/bin/remove_jh.sh ${bin_link_dir}/rmjh || : [ -x ${install_main_dir}/bin/set_core.sh ] && ${csudo} ln -s ${install_main_dir}/bin/set_core.sh ${bin_link_dir}/set_core || : + [ -x ${install_main_dir}/bin/run_taosd.sh ] && ${csudo} ln -s ${install_main_dir}/bin/run_taosd.sh ${bin_link_dir}/run_taosd.sh || : [ -x ${install_main_dir}/bin/tarbitrator ] && ${csudo} ln -s ${install_main_dir}/bin/tarbitrator ${bin_link_dir}/tarbitrator || : if [ "$verMode" == "cluster" ]; then diff --git a/packaging/tools/install_kh.sh b/packaging/tools/install_kh.sh index db7481d5acc88c3bc00db99163023da22e43da36..e53e014351ff9ae64e727151c72f3157a2077043 100755 --- a/packaging/tools/install_kh.sh +++ b/packaging/tools/install_kh.sh @@ -172,6 +172,7 @@ function install_bin() { ${csudo} rm -f ${bin_link_dir}/rmkh || : ${csudo} rm -f ${bin_link_dir}/tarbitrator || : ${csudo} rm -f ${bin_link_dir}/set_core || : + ${csudo} rm -f ${bin_link_dir}/run_taosd.sh || : ${csudo} cp -r ${script_dir}/bin/* ${install_main_dir}/bin && ${csudo} chmod 0555 ${install_main_dir}/bin/* @@ -181,6 +182,7 @@ function install_bin() { [ -x ${install_main_dir}/bin/khdemo ] && ${csudo} ln -s ${install_main_dir}/bin/khdemo ${bin_link_dir}/khdemo || : [ -x ${install_main_dir}/bin/remove_kh.sh ] && ${csudo} ln -s ${install_main_dir}/bin/remove_kh.sh ${bin_link_dir}/rmkh || : [ -x ${install_main_dir}/bin/set_core.sh ] && ${csudo} ln -s ${install_main_dir}/bin/set_core.sh ${bin_link_dir}/set_core || : + [ -x ${install_main_dir}/bin/run_taosd.sh ] && ${csudo} ln -s ${install_main_dir}/bin/run_taosd.sh ${bin_link_dir}/run_taosd.sh || : [ -x ${install_main_dir}/bin/tarbitrator ] && ${csudo} ln -s ${install_main_dir}/bin/tarbitrator ${bin_link_dir}/tarbitrator || : if [ "$verMode" == "cluster" ]; then diff --git a/packaging/tools/install_power.sh b/packaging/tools/install_power.sh index 58096dc040e57ab5ae76cbf9f00e580ed35a8f78..cde33f9b368041d7072bc851d54b68e30a067a95 100755 --- a/packaging/tools/install_power.sh +++ b/packaging/tools/install_power.sh @@ -177,6 +177,7 @@ function install_bin() { ${csudo} rm -f ${bin_link_dir}/rmpower || : ${csudo} rm -f ${bin_link_dir}/tarbitrator || : ${csudo} rm -f ${bin_link_dir}/set_core || : + ${csudo} rm -f ${bin_link_dir}/run_taosd.sh || : ${csudo} cp -r ${script_dir}/bin/* ${install_main_dir}/bin && ${csudo} chmod 0555 ${install_main_dir}/bin/* @@ -186,6 +187,7 @@ function install_bin() { [ -x ${install_main_dir}/bin/powerdemo ] && ${csudo} ln -s ${install_main_dir}/bin/powerdemo ${bin_link_dir}/powerdemo || : [ -x ${install_main_dir}/bin/remove_power.sh ] && ${csudo} ln -s ${install_main_dir}/bin/remove_power.sh ${bin_link_dir}/rmpower || : [ -x ${install_main_dir}/bin/set_core.sh ] && ${csudo} ln -s ${install_main_dir}/bin/set_core.sh ${bin_link_dir}/set_core || : + [ -x ${install_main_dir}/bin/run_taosd.sh ] && ${csudo} ln -s ${install_main_dir}/bin/run_taosd.sh ${bin_link_dir}/run_taosd.sh || : [ -x ${install_main_dir}/bin/tarbitrator ] && ${csudo} ln -s ${install_main_dir}/bin/tarbitrator ${bin_link_dir}/tarbitrator || : if [ "$verMode" == "cluster" ]; then diff --git a/packaging/tools/install_pro.sh b/packaging/tools/install_pro.sh index fbd38875f7dffa651f26ca5969cc06f61b3d0737..44a21abc19f19a1bffc2be42e71db30157d4e220 100755 --- a/packaging/tools/install_pro.sh +++ b/packaging/tools/install_pro.sh @@ -172,6 +172,7 @@ function install_bin() { ${csudo} rm -f ${bin_link_dir}/rmprodb || : ${csudo} rm -f ${bin_link_dir}/tarbitrator || : ${csudo} rm -f ${bin_link_dir}/set_core || : + ${csudo} rm -f ${bin_link_dir}/run_taosd.sh || : ${csudo} cp -r ${script_dir}/bin/* ${install_main_dir}/bin && ${csudo} chmod 0555 ${install_main_dir}/bin/* @@ -181,6 +182,7 @@ function install_bin() { [ -x ${install_main_dir}/bin/prodemo ] && ${csudo} ln -s ${install_main_dir}/bin/prodemo ${bin_link_dir}/prodemo || : [ -x ${install_main_dir}/bin/remove_pro.sh ] && ${csudo} ln -s ${install_main_dir}/bin/remove_pro.sh ${bin_link_dir}/rmprodb || : [ -x ${install_main_dir}/bin/set_core.sh ] && ${csudo} ln -s ${install_main_dir}/bin/set_core.sh ${bin_link_dir}/set_core || : + [ -x ${install_main_dir}/bin/run_taosd.sh ] && ${csudo} ln -s ${install_main_dir}/bin/run_taosd.sh ${bin_link_dir}/run_taosd.sh || : [ -x ${install_main_dir}/bin/tarbitrator ] && ${csudo} ln -s ${install_main_dir}/bin/tarbitrator ${bin_link_dir}/tarbitrator || : if [ "$verMode" == "cluster" ]; then diff --git a/packaging/tools/install_tq.sh b/packaging/tools/install_tq.sh index d335c759008e3df3eab249b3abc1cc9b2291bb53..481cbb19792b654710aab13d99c50ab4b5475be1 100755 --- a/packaging/tools/install_tq.sh +++ b/packaging/tools/install_tq.sh @@ -177,6 +177,7 @@ function install_bin() { ${csudo} rm -f ${bin_link_dir}/rmtq || : ${csudo} rm -f ${bin_link_dir}/tarbitrator || : ${csudo} rm -f ${bin_link_dir}/set_core || : + ${csudo} rm -f ${bin_link_dir}/run_taosd.sh || : ${csudo} cp -r ${script_dir}/bin/* ${install_main_dir}/bin && ${csudo} chmod 0555 ${install_main_dir}/bin/* @@ -186,6 +187,7 @@ function install_bin() { [ -x ${install_main_dir}/bin/tqdemo ] && ${csudo} ln -s ${install_main_dir}/bin/tqdemo ${bin_link_dir}/tqdemo || : [ -x ${install_main_dir}/bin/remove_tq.sh ] && ${csudo} ln -s ${install_main_dir}/bin/remove_tq.sh ${bin_link_dir}/rmtq || : [ -x ${install_main_dir}/bin/set_core.sh ] && ${csudo} ln -s ${install_main_dir}/bin/set_core.sh ${bin_link_dir}/set_core || : + [ -x ${install_main_dir}/bin/run_taosd.sh ] && ${csudo} ln -s ${install_main_dir}/bin/run_taosd.sh ${bin_link_dir}/run_taosd.sh || : [ -x ${install_main_dir}/bin/tarbitrator ] && ${csudo} ln -s ${install_main_dir}/bin/tarbitrator ${bin_link_dir}/tarbitrator || : if [ "$verMode" == "cluster" ]; then diff --git a/packaging/tools/make_install.sh b/packaging/tools/make_install.sh index 07a88f30162b4fb4d6cb6c0bd31cac29420e0bf3..38b45871a6a96887fee19cd460f056410f52fbc5 100755 --- a/packaging/tools/make_install.sh +++ b/packaging/tools/make_install.sh @@ -165,6 +165,7 @@ function install_bin() { if [ "$osType" != "Darwin" ]; then ${csudo} rm -f ${bin_link_dir}/perfMonitor || : ${csudo} rm -f ${bin_link_dir}/set_core || : + ${csudo} rm -f ${bin_link_dir}/run_taosd.sh || : ${csudo} rm -f ${bin_link_dir}/rmtaos || : ${csudo} cp -r ${binary_dir}/build/bin/* ${install_main_dir}/bin @@ -172,6 +173,7 @@ function install_bin() { ${csudo} cp -r ${script_dir}/remove.sh ${install_main_dir}/bin ${csudo} cp -r ${script_dir}/set_core.sh ${install_main_dir}/bin + ${csudo} cp -r ${script_dir}/run_taosd.sh ${install_main_dir}/bin ${csudo} cp -r ${script_dir}/startPre.sh ${install_main_dir}/bin ${csudo} chmod 0555 ${install_main_dir}/bin/* @@ -183,6 +185,7 @@ function install_bin() { [ -x ${install_main_dir}/bin/taosdemo ] && ${csudo} ln -s ${install_main_dir}/bin/taosdemo ${bin_link_dir}/taosdemo || : [ -x ${install_main_dir}/bin/perfMonitor ] && ${csudo} ln -s ${install_main_dir}/bin/perfMonitor ${bin_link_dir}/perfMonitor || : [ -x ${install_main_dir}/set_core.sh ] && ${csudo} ln -s ${install_main_dir}/bin/set_core.sh ${bin_link_dir}/set_core || : + [ -x ${install_main_dir}/run_taosd.sh ] && ${csudo} ln -s ${install_main_dir}/bin/run_taosd.sh ${bin_link_dir}/run_taosd.sh || : [ -x ${install_main_dir}/bin/remove.sh ] && ${csudo} ln -s ${install_main_dir}/bin/remove.sh ${bin_link_dir}/rmtaos || : else diff --git a/packaging/tools/makeclient.sh b/packaging/tools/makeclient.sh index 13172c46ee0458272b7ecb83fcde7a762ccdae2a..278388f39f8a93c4e38ec6b344c7e902dfed549e 100755 --- a/packaging/tools/makeclient.sh +++ b/packaging/tools/makeclient.sh @@ -45,8 +45,9 @@ if [ "$osType" != "Darwin" ]; then strip ${build_dir}/bin/taos bin_files="${build_dir}/bin/taos ${script_dir}/remove_client.sh" else - bin_files="${build_dir}/bin/taos ${build_dir}/bin/taosdemo \ - ${script_dir}/remove_client.sh ${script_dir}/set_core.sh ${script_dir}/get_client.sh ${script_dir}/taosd-dump-cfg.gdb" + bin_files="${script_dir}/remove_client.sh \ + ${script_dir}/set_core.sh \ + ${script_dir}/get_client.sh ${script_dir}/taosd-dump-cfg.gdb" fi lib_files="${build_dir}/lib/libtaos.so.${version}" else diff --git a/packaging/tools/makeclient_jh.sh b/packaging/tools/makeclient_jh.sh index 267d78b953be33c567f8175a369b13f326ee3f5a..ed61cffaf793ede0f774fa1ba2c81d7645f714dc 100755 --- a/packaging/tools/makeclient_jh.sh +++ b/packaging/tools/makeclient_jh.sh @@ -69,10 +69,10 @@ if [ "$osType" != "Darwin" ]; then if [ "$pagMode" == "lite" ]; then strip ${build_dir}/bin/taos cp ${build_dir}/bin/taos ${install_dir}/bin/jh_taos - cp ${script_dir}/remove_jh.sh ${install_dir}/bin + cp ${script_dir}/remove_client_jh.sh ${install_dir}/bin else cp ${build_dir}/bin/taos ${install_dir}/bin/jh_taos - cp ${script_dir}/remove_jh.sh ${install_dir}/bin + cp ${script_dir}/remove_client_jh.sh ${install_dir}/bin cp ${build_dir}/bin/taosdemo ${install_dir}/bin/jhdemo cp ${build_dir}/bin/taosdump ${install_dir}/bin/jh_taosdump cp ${script_dir}/set_core.sh ${install_dir}/bin diff --git a/packaging/tools/makeclient_kh.sh b/packaging/tools/makeclient_kh.sh index b991e2a6fae69a72d678cf5ff8751429a9f88fc6..86d37105a4acd3fcefbfa8d230804d7d2f820fb5 100755 --- a/packaging/tools/makeclient_kh.sh +++ b/packaging/tools/makeclient_kh.sh @@ -69,10 +69,10 @@ if [ "$osType" != "Darwin" ]; then if [ "$pagMode" == "lite" ]; then strip ${build_dir}/bin/taos cp ${build_dir}/bin/taos ${install_dir}/bin/khclient - cp ${script_dir}/remove_kh.sh ${install_dir}/bin + cp ${script_dir}/remove_client_kh.sh ${install_dir}/bin else cp ${build_dir}/bin/taos ${install_dir}/bin/khclient - cp ${script_dir}/remove_kh.sh ${install_dir}/bin + cp ${script_dir}/remove_client_kh.sh ${install_dir}/bin cp ${build_dir}/bin/taosdemo ${install_dir}/bin/khdemo cp ${build_dir}/bin/taosdump ${install_dir}/bin/khdump cp ${script_dir}/set_core.sh ${install_dir}/bin diff --git a/packaging/tools/makeclient_power.sh b/packaging/tools/makeclient_power.sh index 07dc9d30d21e130aff15f1c84a3db7e209867f88..2f01748f5e40925b905a715b3c308692d46e71b0 100755 --- a/packaging/tools/makeclient_power.sh +++ b/packaging/tools/makeclient_power.sh @@ -109,10 +109,10 @@ if [ "$osType" != "Darwin" ]; then if [ "$pagMode" == "lite" ]; then strip ${build_dir}/bin/taos cp ${build_dir}/bin/taos ${install_dir}/bin/power - cp ${script_dir}/remove_power.sh ${install_dir}/bin + cp ${script_dir}/remove_client_power.sh ${install_dir}/bin else cp ${build_dir}/bin/taos ${install_dir}/bin/power - cp ${script_dir}/remove_power.sh ${install_dir}/bin + cp ${script_dir}/remove_client_power.sh ${install_dir}/bin cp ${build_dir}/bin/taosdemo ${install_dir}/bin/powerdemo cp ${build_dir}/bin/taosdump ${install_dir}/bin/powerdump cp ${script_dir}/set_core.sh ${install_dir}/bin diff --git a/packaging/tools/makeclient_pro.sh b/packaging/tools/makeclient_pro.sh index 0c5033d87dd5815e9e3ec309e6b1bb9abe98ca42..769d0274e5eb5198fedb6c6c3a7f1590fd2ff44a 100755 --- a/packaging/tools/makeclient_pro.sh +++ b/packaging/tools/makeclient_pro.sh @@ -69,10 +69,10 @@ if [ "$osType" != "Darwin" ]; then if [ "$pagMode" == "lite" ]; then strip ${build_dir}/bin/taos cp ${build_dir}/bin/taos ${install_dir}/bin/prodbc - cp ${script_dir}/remove_pro.sh ${install_dir}/bin + cp ${script_dir}/remove_client_pro.sh ${install_dir}/bin else cp ${build_dir}/bin/taos ${install_dir}/bin/prodbc - cp ${script_dir}/remove_pro.sh ${install_dir}/bin + cp ${script_dir}/remove_client_pro.sh ${install_dir}/bin cp ${build_dir}/bin/taosdemo ${install_dir}/bin/prodemo cp ${build_dir}/bin/taosdump ${install_dir}/bin/prodump cp ${script_dir}/set_core.sh ${install_dir}/bin diff --git a/packaging/tools/makeclient_tq.sh b/packaging/tools/makeclient_tq.sh index 3ed97520939be51f2f634f8955f16ecf9a46821b..f8d87ba76a9ab32ea729d4999a05712976a32634 100755 --- a/packaging/tools/makeclient_tq.sh +++ b/packaging/tools/makeclient_tq.sh @@ -69,10 +69,10 @@ if [ "$osType" != "Darwin" ]; then if [ "$pagMode" == "lite" ]; then strip ${build_dir}/bin/taos cp ${build_dir}/bin/taos ${install_dir}/bin/tq - cp ${script_dir}/remove_tq.sh ${install_dir}/bin + cp ${script_dir}/remove_client_tq.sh ${install_dir}/bin else cp ${build_dir}/bin/taos ${install_dir}/bin/tq - cp ${script_dir}/remove_tq.sh ${install_dir}/bin + cp ${script_dir}/remove_client_tq.sh ${install_dir}/bin cp ${build_dir}/bin/taosdemo ${install_dir}/bin/tqdemo cp ${build_dir}/bin/taosdump ${install_dir}/bin/tqdump cp ${script_dir}/set_core.sh ${install_dir}/bin diff --git a/packaging/tools/makepkg.sh b/packaging/tools/makepkg.sh index c9555291bc77828da336c6bfe9c6215f208ff178..89bbbf9370e545d10aa8c8f9a4b16e0319693e30 100755 --- a/packaging/tools/makepkg.sh +++ b/packaging/tools/makepkg.sh @@ -31,23 +31,38 @@ else install_dir="${release_dir}/TDengine-server-${version}" fi +if [ -d ${top_dir}/src/kit/taos-tools/packaging/deb ]; then + cd ${top_dir}/src/kit/taos-tools/packaging/deb + [ -z "$taos_tools_ver" ] && taos_tools_ver="0.1.0" + + taostools_ver=$(git describe --tags|sed -e 's/ver-//g'|awk -F '-' '{print $1}') + taostools_install_dir="${release_dir}/taos-tools-${taostools_ver}" + + cd ${curr_dir} +else + taostools_install_dir="${release_dir}/taos-tools-${version}" +fi + # Directories and files if [ "$pagMode" == "lite" ]; then strip ${build_dir}/bin/taosd strip ${build_dir}/bin/taos # lite version doesn't include taosadapter, which will lead to no restful interface bin_files="${build_dir}/bin/taosd ${build_dir}/bin/taos ${script_dir}/remove.sh ${script_dir}/startPre.sh" + taostools_bin_files="" else bin_files="${build_dir}/bin/taosd \ ${build_dir}/bin/taos \ ${build_dir}/bin/taosadapter \ - ${build_dir}/bin/taosdump \ - ${build_dir}/bin/taosdemo \ ${build_dir}/bin/tarbitrator\ ${script_dir}/remove.sh \ ${script_dir}/set_core.sh \ + ${script_dir}/run_taosd.sh \ ${script_dir}/startPre.sh \ ${script_dir}/taosd-dump-cfg.gdb" + + taostools_bin_files=" ${build_dir}/bin/taosdump \ + ${build_dir}/bin/taosBenchmark" fi lib_files="${build_dir}/lib/libtaos.so.${version}" @@ -78,6 +93,7 @@ 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 + if [ -f "${compile_dir}/test/cfg/taosadapter.toml" ]; then cp ${compile_dir}/test/cfg/taosadapter.toml ${install_dir}/cfg || : fi @@ -102,10 +118,29 @@ mkdir -p ${install_dir}/init.d && cp ${init_file_rpm} ${install_dir}/init.d/taos mkdir -p ${install_dir}/init.d && cp ${init_file_tarbitrator_deb} ${install_dir}/init.d/tarbitratord.deb || : mkdir -p ${install_dir}/init.d && cp ${init_file_tarbitrator_rpm} ${install_dir}/init.d/tarbitratord.rpm || : -if [ -f ${build_dir}/lib/libavro.so.23.0.0 ]; then - mkdir -p ${install_dir}/avro/{lib,lib/pkgconfig} - cp ${build_dir}/lib/libavro.* ${install_dir}/avro/lib - cp ${build_dir}/lib/pkgconfig/avro-c.pc ${install_dir}/avro/lib/pkgconfig +if [ -n "${taostools_bin_files}" ]; then + mkdir -p ${taostools_install_dir} || echo -e "failed to create ${taostools_install_dir}" + mkdir -p ${taostools_install_dir}/bin \ + && cp ${taostools_bin_files} ${taostools_install_dir}/bin \ + && chmod a+x ${taostools_install_dir}/bin/* || : + [ -f ${taostools_install_dir}/bin/taosBenchmark ] && \ + ln -sf ${taostools_install_dir}/bin/taosBenchmark \ + ${taostools_install_dir}/bin/taosdemo + + if [ -f ${top_dir}/src/kit/taos-tools/packaging/tools/install-taostools.sh ]; then + cp ${top_dir}/src/kit/taos-tools/packaging/tools/install-taostools.sh \ + ${taostools_install_dir}/ > /dev/null \ + && chmod a+x ${taostools_install_dir}/install-taostools.sh \ + || echo -e "failed to copy install-taostools.sh" + else + echo -e "install-taostools.sh not found" + fi + + if [ -f ${build_dir}/lib/libavro.so.23.0.0 ]; then + mkdir -p ${taostools_install_dir}/avro/{lib,lib/pkgconfig} || echo -e "failed to create ${taostools_install_dir}/avro" + cp ${build_dir}/lib/libavro.* ${taostools_install_dir}/avro/lib + cp ${build_dir}/lib/pkgconfig/avro-c.pc ${taostools_install_dir}/avro/lib/pkgconfig + fi fi if [ -f ${build_dir}/bin/jemalloc-config ]; then @@ -235,6 +270,8 @@ cd ${release_dir} # install_dir has been distinguishes cluster from edege, so comments this code pkg_name=${install_dir}-${osType}-${cpuType} +taostools_pkg_name=${taostools_install_dir}-${osType}-${cpuType} + # if [ "$verMode" == "cluster" ]; then # pkg_name=${install_dir}-${osType}-${cpuType} # elif [ "$verMode" == "edge" ]; then @@ -246,8 +283,10 @@ pkg_name=${install_dir}-${osType}-${cpuType} if [[ "$verType" == "beta" ]] || [[ "$verType" == "preRelease" ]]; then pkg_name=${install_dir}-${verType}-${osType}-${cpuType} + taostools_pkg_name=${taostools_install_dir}-${verType}-${osType}-${cpuType} elif [ "$verType" == "stable" ]; then pkg_name=${pkg_name} + taostools_pkg_name=${taostools_pkg_name} else echo "unknow verType, nor stabel or beta" exit 1 @@ -257,11 +296,20 @@ if [ "$pagMode" == "lite" ]; then pkg_name=${pkg_name}-Lite fi -tar -zcv -f "$(basename ${pkg_name}).tar.gz" $(basename ${install_dir}) --remove-files || : +tar -zcv -f "$(basename ${pkg_name}).tar.gz" "$(basename ${install_dir})" --remove-files || : exitcode=$? if [ "$exitcode" != "0" ]; then echo "tar ${pkg_name}.tar.gz error !!!" exit $exitcode fi +if [ -n "${taostools_bin_files}" ]; then + tar -zcv -f "$(basename ${taostools_pkg_name}).tar.gz" "$(basename ${taostools_install_dir})" --remove-files || : + exitcode=$? + if [ "$exitcode" != "0" ]; then + echo "tar ${taostools_pkg_name}.tar.gz error !!!" + exit $exitcode + fi +fi + cd ${curr_dir} diff --git a/packaging/tools/makepkg_jh.sh b/packaging/tools/makepkg_jh.sh index d7b7746849578b0e2774ddf442566196102ea561..fdc7ba5c79f66bdc5d9567999c644c2a3b4ad1f1 100755 --- a/packaging/tools/makepkg_jh.sh +++ b/packaging/tools/makepkg_jh.sh @@ -56,6 +56,7 @@ else cp ${build_dir}/bin/taosdump ${install_dir}/bin/jh_taosdump cp ${build_dir}/bin/tarbitrator ${install_dir}/bin cp ${script_dir}/set_core.sh ${install_dir}/bin + cp ${script_dir}/run_taosd.sh ${install_dir}/bin cp ${script_dir}/get_client.sh ${install_dir}/bin cp ${script_dir}/startPre.sh ${install_dir}/bin cp ${script_dir}/taosd-dump-cfg.gdb ${install_dir}/bin diff --git a/packaging/tools/makepkg_kh.sh b/packaging/tools/makepkg_kh.sh index 80b7a06041c6c9dca926ecc0f87c8c8a7958c639..35efd2e0d7d4b5dad8bc2b360910eca69118bc6c 100755 --- a/packaging/tools/makepkg_kh.sh +++ b/packaging/tools/makepkg_kh.sh @@ -56,6 +56,7 @@ else cp ${build_dir}/bin/taosdump ${install_dir}/bin/khdump cp ${build_dir}/bin/tarbitrator ${install_dir}/bin cp ${script_dir}/set_core.sh ${install_dir}/bin + cp ${script_dir}/run_taosd.sh ${install_dir}/bin cp ${script_dir}/get_client.sh ${install_dir}/bin cp ${script_dir}/startPre.sh ${install_dir}/bin cp ${script_dir}/taosd-dump-cfg.gdb ${install_dir}/bin diff --git a/packaging/tools/makepkg_power.sh b/packaging/tools/makepkg_power.sh index dadd42c64a990da74d0b696737300b84891df232..ab2a662b118b9a6a62dbf87fc54d78358ab1861f 100755 --- a/packaging/tools/makepkg_power.sh +++ b/packaging/tools/makepkg_power.sh @@ -64,12 +64,13 @@ else # bin_files="${build_dir}/bin/powerd ${build_dir}/bin/power ${build_dir}/bin/powerdemo ${build_dir}/bin/tarbitrator ${script_dir}/remove_power.sh ${script_dir}/set_core.sh" cp ${build_dir}/bin/taos ${install_dir}/bin/power cp ${build_dir}/bin/taosd ${install_dir}/bin/powerd - cp ${build_dir}/bin/taosadapter ${install_dir}/bin/taosadapter ||: + cp ${build_dir}/bin/taosadapter ${install_dir}/bin/taosadapter ||: cp ${script_dir}/remove_power.sh ${install_dir}/bin cp ${build_dir}/bin/taosdemo ${install_dir}/bin/powerdemo cp ${build_dir}/bin/taosdump ${install_dir}/bin/powerdump cp ${build_dir}/bin/tarbitrator ${install_dir}/bin cp ${script_dir}/set_core.sh ${install_dir}/bin + cp ${script_dir}/run_taosd.sh ${install_dir}/bin cp ${script_dir}/get_client.sh ${install_dir}/bin cp ${script_dir}/startPre.sh ${install_dir}/bin cp ${script_dir}/taosd-dump-cfg.gdb ${install_dir}/bin diff --git a/packaging/tools/makepkg_pro.sh b/packaging/tools/makepkg_pro.sh index 3896390068f8152a270e5c00b1b1f402be76bcc8..ea370b2d95437b13f932b1925a4de8d1073cd294 100755 --- a/packaging/tools/makepkg_pro.sh +++ b/packaging/tools/makepkg_pro.sh @@ -56,6 +56,7 @@ else cp ${build_dir}/bin/taosdump ${install_dir}/bin/prodump cp ${build_dir}/bin/tarbitrator ${install_dir}/bin cp ${script_dir}/set_core.sh ${install_dir}/bin + cp ${script_dir}/run_taosd.sh ${install_dir}/bin cp ${script_dir}/get_client.sh ${install_dir}/bin cp ${script_dir}/startPre.sh ${install_dir}/bin cp ${script_dir}/taosd-dump-cfg.gdb ${install_dir}/bin diff --git a/packaging/tools/makepkg_tq.sh b/packaging/tools/makepkg_tq.sh index 94c563ab45e2e82f8cbd485fa17f11541323af17..ff406421eaacf290e2e9269c358176fee20a80bb 100755 --- a/packaging/tools/makepkg_tq.sh +++ b/packaging/tools/makepkg_tq.sh @@ -61,6 +61,7 @@ else cp ${build_dir}/bin/taosdemo ${install_dir}/bin/tqdemo cp ${build_dir}/bin/tarbitrator ${install_dir}/bin cp ${script_dir}/set_core.sh ${install_dir}/bin + cp ${script_dir}/run_taosd.sh ${install_dir}/bin cp ${script_dir}/get_client.sh ${install_dir}/bin cp ${script_dir}/startPre.sh ${install_dir}/bin cp ${script_dir}/taosd-dump-cfg.gdb ${install_dir}/bin diff --git a/packaging/tools/remove.sh b/packaging/tools/remove.sh index 7ace212e6ae93cf1e4b7c0e55962091027e9b15d..4f814692ebaacf8017ede030a977af36528a27c1 100755 --- a/packaging/tools/remove.sh +++ b/packaging/tools/remove.sh @@ -79,12 +79,13 @@ function clean_bin() { # Remove link ${csudo} rm -f ${bin_link_dir}/taos || : ${csudo} rm -f ${bin_link_dir}/taosd || : - ${csudo} rm -f ${bin_link_dir}/taosadapter || : + ${csudo} rm -f ${bin_link_dir}/taosadapter || : ${csudo} rm -f ${bin_link_dir}/taosdemo || : ${csudo} rm -f ${bin_link_dir}/taosdump || : ${csudo} rm -f ${bin_link_dir}/rmtaos || : ${csudo} rm -f ${bin_link_dir}/tarbitrator || : ${csudo} rm -f ${bin_link_dir}/set_core || : + ${csudo} rm -f ${bin_link_dir}/run_taosd.sh || : } function clean_lib() { diff --git a/packaging/tools/remove_jh.sh b/packaging/tools/remove_jh.sh index b962b824fdeeda632be28eeeaa97199adcd6ca2c..6965ba388f99e8a2ac1c33def2f696f8d7c3898e 100755 --- a/packaging/tools/remove_jh.sh +++ b/packaging/tools/remove_jh.sh @@ -70,10 +70,11 @@ function clean_bin() { ${csudo} rm -f ${bin_link_dir}/jh_taos || : ${csudo} rm -f ${bin_link_dir}/jh_taosd || : ${csudo} rm -f ${bin_link_dir}/jhdemo || : - ${csudo} rm -f ${bin_link_dir}/jh_taosdump || : + ${csudo} rm -f ${bin_link_dir}/jh_taosdump || : ${csudo} rm -f ${bin_link_dir}/rmjh || : ${csudo} rm -f ${bin_link_dir}/tarbitrator || : ${csudo} rm -f ${bin_link_dir}/set_core || : + ${csudo} rm -f ${bin_link_dir}/run_taosd.sh || : } function clean_lib() { diff --git a/packaging/tools/remove_kh.sh b/packaging/tools/remove_kh.sh index 0055e043e74a3fa287cebbd325f83c7f8f98ca8a..cf6a93fdf2bf8884bda02b4f44058eb7f8d77210 100755 --- a/packaging/tools/remove_kh.sh +++ b/packaging/tools/remove_kh.sh @@ -74,6 +74,7 @@ function clean_bin() { ${csudo} rm -f ${bin_link_dir}/rmkh || : ${csudo} rm -f ${bin_link_dir}/tarbitrator || : ${csudo} rm -f ${bin_link_dir}/set_core || : + ${csudo} rm -f ${bin_link_dir}/run_taosd.sh || : } function clean_lib() { diff --git a/packaging/tools/remove_power.sh b/packaging/tools/remove_power.sh index 1953458d1040a3f67e27a4cac9c380651b3ec949..70d0095f978f8c7a2578c63110cdd118fef43e30 100755 --- a/packaging/tools/remove_power.sh +++ b/packaging/tools/remove_power.sh @@ -76,6 +76,7 @@ function clean_bin() { ${csudo} rm -f ${bin_link_dir}/rmpower || : ${csudo} rm -f ${bin_link_dir}/tarbitrator || : ${csudo} rm -f ${bin_link_dir}/set_core || : + ${csudo} rm -f ${bin_link_dir}/run_taosd.sh || : } function clean_lib() { diff --git a/packaging/tools/remove_pro.sh b/packaging/tools/remove_pro.sh index f32b4204225b83287c818b80025e4544f75782d6..1572a7f08c6083f7da3d81176f107e4cb977d4f9 100755 --- a/packaging/tools/remove_pro.sh +++ b/packaging/tools/remove_pro.sh @@ -74,6 +74,7 @@ function clean_bin() { ${csudo} rm -f ${bin_link_dir}/rmprodb || : ${csudo} rm -f ${bin_link_dir}/tarbitrator || : ${csudo} rm -f ${bin_link_dir}/set_core || : + ${csudo} rm -f ${bin_link_dir}/run_taosd.sh || : } function clean_lib() { diff --git a/packaging/tools/remove_tq.sh b/packaging/tools/remove_tq.sh index e08ac47f7d866edf9c2e1478947822f350410b85..eb83b92d1a5ef7e9e4ac498d98cc538a34da2a4f 100755 --- a/packaging/tools/remove_tq.sh +++ b/packaging/tools/remove_tq.sh @@ -76,6 +76,7 @@ function clean_bin() { ${csudo} rm -f ${bin_link_dir}/rmtq || : ${csudo} rm -f ${bin_link_dir}/tarbitrator || : ${csudo} rm -f ${bin_link_dir}/set_core || : + ${csudo} rm -f ${bin_link_dir}/run_taosd.sh || : } function clean_lib() { diff --git a/packaging/tools/run_taosd.sh b/packaging/tools/run_taosd.sh new file mode 100755 index 0000000000000000000000000000000000000000..9ab9eb484a4a5bbc4e3d3994d97b61e0f4bd328d --- /dev/null +++ b/packaging/tools/run_taosd.sh @@ -0,0 +1,3 @@ +#!/bin/bash +[[ -x /usr/bin/taosadapter ]] && /usr/bin/taosadapter & +taosd diff --git a/src/client/src/tscLocal.c b/src/client/src/tscLocal.c index 0a7a1a67949a3f0cccf923e745859f7c0692dda3..96aa3ef711c20d7ef75c8fe74187751614a7fe3b 100644 --- a/src/client/src/tscLocal.c +++ b/src/client/src/tscLocal.c @@ -636,9 +636,9 @@ static int32_t tscRebuildDDLForNormalTable(SSqlObj *pSql, const char *tableName, if (type == TSDB_DATA_TYPE_NCHAR) { bytes = bytes/TSDB_NCHAR_SIZE; } - snprintf(result + strlen(result), TSDB_MAX_BINARY_LEN - strlen(result), "%s %s(%d),", pSchema[i].name, tDataTypes[pSchema[i].type].name, bytes); + snprintf(result + strlen(result), TSDB_MAX_BINARY_LEN - strlen(result), "`%s` %s(%d),", pSchema[i].name, tDataTypes[pSchema[i].type].name, bytes); } else { - snprintf(result + strlen(result), TSDB_MAX_BINARY_LEN - strlen(result), "%s %s,", pSchema[i].name, tDataTypes[pSchema[i].type].name); + snprintf(result + strlen(result), TSDB_MAX_BINARY_LEN - strlen(result), "`%s` %s,", pSchema[i].name, tDataTypes[pSchema[i].type].name); } } sprintf(result + strlen(result) - 1, "%s", ")"); @@ -663,9 +663,9 @@ static int32_t tscRebuildDDLForSuperTable(SSqlObj *pSql, const char *tableName, if (type == TSDB_DATA_TYPE_NCHAR) { bytes = bytes/TSDB_NCHAR_SIZE; } - snprintf(result + strlen(result), TSDB_MAX_BINARY_LEN - strlen(result),"%s %s(%d),", pSchema[i].name,tDataTypes[pSchema[i].type].name, bytes); + snprintf(result + strlen(result), TSDB_MAX_BINARY_LEN - strlen(result),"`%s` %s(%d),", pSchema[i].name,tDataTypes[pSchema[i].type].name, bytes); } else { - snprintf(result + strlen(result), TSDB_MAX_BINARY_LEN - strlen(result), "%s %s,", pSchema[i].name, tDataTypes[type].name); + snprintf(result + strlen(result), TSDB_MAX_BINARY_LEN - strlen(result), "`%s` %s,", pSchema[i].name, tDataTypes[type].name); } } snprintf(result + strlen(result) - 1, TSDB_MAX_BINARY_LEN - strlen(result), "%s %s", ")", "TAGS ("); @@ -677,9 +677,9 @@ static int32_t tscRebuildDDLForSuperTable(SSqlObj *pSql, const char *tableName, if (type == TSDB_DATA_TYPE_NCHAR) { bytes = bytes/TSDB_NCHAR_SIZE; } - snprintf(result + strlen(result), TSDB_MAX_BINARY_LEN - strlen(result), "%s %s(%d),", pSchema[i].name,tDataTypes[pSchema[i].type].name, bytes); + snprintf(result + strlen(result), TSDB_MAX_BINARY_LEN - strlen(result), "`%s` %s(%d),", pSchema[i].name,tDataTypes[pSchema[i].type].name, bytes); } else { - snprintf(result + strlen(result), TSDB_MAX_BINARY_LEN - strlen(result), "%s %s,", pSchema[i].name, tDataTypes[type].name); + snprintf(result + strlen(result), TSDB_MAX_BINARY_LEN - strlen(result), "`%s` %s,", pSchema[i].name, tDataTypes[type].name); } } sprintf(result + strlen(result) - 1, "%s", ")"); diff --git a/src/client/src/tscParseLineProtocol.c b/src/client/src/tscParseLineProtocol.c index acf3248518811784bfd9ce5228388075666cc428..98d6ff8e4d6fe3cc4c08691ab027622b7410e32d 100644 --- a/src/client/src/tscParseLineProtocol.c +++ b/src/client/src/tscParseLineProtocol.c @@ -32,6 +32,10 @@ typedef struct { static uint64_t linesSmlHandleId = 0; +static int32_t insertChildTablePointsBatch(void* pVoid, char* name, char* name1, SArray* pArray, SArray* pArray1, + SArray* pArray2, SArray* pArray3, size_t size, SSmlLinesInfo* info); +static int32_t doInsertChildTablePoints(void* pVoid, char* sql, char* name, SArray* pArray, SArray* pArray1, + SSmlLinesInfo* info); uint64_t genLinesSmlId() { uint64_t id; @@ -177,11 +181,10 @@ static int32_t getSmlMd5ChildTableName(TAOS_SML_DATA_POINT* point, char* tableNa MD5Init(&context); MD5Update(&context, (uint8_t *)keyJoined, (uint32_t)len); MD5Final(&context); + uint64_t digest1 = *(uint64_t*)(context.digest); + uint64_t digest2 = *(uint64_t*)(context.digest + 8); *tableNameLen = snprintf(tableName, *tableNameLen, - "t_%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", context.digest[0], - context.digest[1], context.digest[2], context.digest[3], context.digest[4], context.digest[5], context.digest[6], - context.digest[7], context.digest[8], context.digest[9], context.digest[10], context.digest[11], - context.digest[12], context.digest[13], context.digest[14], context.digest[15]); + "t_%016"PRIx64"%016"PRIx64, digest1, digest2); taosStringBuilderDestroy(&sb); tscDebug("SML:0x%"PRIx64" child table name: %s", info->id, tableName); return 0; @@ -198,7 +201,6 @@ static int32_t buildSmlChildTableName(TAOS_SML_DATA_POINT* point, SSmlLinesInfo* return 0; } - static int32_t buildDataPointSchemas(TAOS_SML_DATA_POINT* points, int numPoint, SArray* stableSchemas, SSmlLinesInfo* info) { int32_t code = 0; SHashObj* sname2shema = taosHashInit(32, @@ -219,8 +221,8 @@ static int32_t buildDataPointSchemas(TAOS_SML_DATA_POINT* points, int numPoint, schema.sTableName[stableNameLen] = '\0'; schema.fields = taosArrayInit(64, sizeof(SSchema)); schema.tags = taosArrayInit(8, sizeof(SSchema)); - schema.tagHash = taosHashInit(8, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, false); - schema.fieldHash = taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, false); + schema.tagHash = taosHashInit(16, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, false); + schema.fieldHash = taosHashInit(128, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, false); pStableSchema = taosArrayPush(stableSchemas, &schema); stableIdx = taosArrayGetSize(stableSchemas) - 1; @@ -555,11 +557,75 @@ static int32_t fillDbSchema(STableMeta* tableMeta, char* tableName, SSmlSTableSc return TSDB_CODE_SUCCESS; } +static int32_t getSuperTableMetaFromLocalCache(TAOS* taos, char* tableName, STableMeta** outTableMeta, SSmlLinesInfo* info) { + int32_t code = 0; + STableMeta* tableMeta = NULL; + + SSqlObj* pSql = calloc(1, sizeof(SSqlObj)); + if (pSql == NULL) { + tscError("SML:0x%" PRIx64 " failed to allocate memory, reason:%s", info->id, strerror(errno)); + code = TSDB_CODE_TSC_OUT_OF_MEMORY; + return code; + } + pSql->pTscObj = taos; + pSql->signature = pSql; + pSql->fp = NULL; + + registerSqlObj(pSql); + char tableNameBuf[TSDB_TABLE_NAME_LEN + TS_ESCAPE_CHAR_SIZE] = {0}; + memcpy(tableNameBuf, tableName, strlen(tableName)); + SStrToken tableToken = {.z = tableNameBuf, .n = (uint32_t)strlen(tableName), .type = TK_ID}; + tGetToken(tableNameBuf, &tableToken.type); + bool dbIncluded = false; + // Check if the table name available or not + if (tscValidateName(&tableToken, true, &dbIncluded) != TSDB_CODE_SUCCESS) { + code = TSDB_CODE_TSC_INVALID_TABLE_ID_LENGTH; + sprintf(pSql->cmd.payload, "table name is invalid"); + taosReleaseRef(tscObjRef, pSql->self); + return code; + } + + SName sname = {0}; + if ((code = tscSetTableFullName(&sname, &tableToken, pSql, dbIncluded)) != TSDB_CODE_SUCCESS) { + taosReleaseRef(tscObjRef, pSql->self); + return code; + } + + char fullTableName[TSDB_TABLE_FNAME_LEN] = {0}; + memset(fullTableName, 0, tListLen(fullTableName)); + tNameExtractFullName(&sname, fullTableName); + + size_t size = 0; + taosHashGetCloneExt(UTIL_GET_TABLEMETA(pSql), fullTableName, strlen(fullTableName), NULL, (void**)&tableMeta, &size); + + STableMeta* stableMeta = tableMeta; + if (tableMeta != NULL && tableMeta->tableType == TSDB_CHILD_TABLE) { + taosHashGetCloneExt(UTIL_GET_TABLEMETA(pSql), tableMeta->sTableName, strlen(tableMeta->sTableName), NULL, + (void**)stableMeta, &size); + } + taosReleaseRef(tscObjRef, pSql->self); + + if (stableMeta != tableMeta) { + free(tableMeta); + } + + if (stableMeta != NULL) { + if (outTableMeta != NULL) { + *outTableMeta = stableMeta; + } else { + free(stableMeta); + } + return TSDB_CODE_SUCCESS; + } else { + return TSDB_CODE_TSC_NO_META_CACHED; + } +} + static int32_t retrieveTableMeta(TAOS* taos, char* tableName, STableMeta** pTableMeta, SSmlLinesInfo* info) { int32_t code = 0; int32_t retries = 0; STableMeta* tableMeta = NULL; - while (retries++ < TSDB_MAX_REPLICA && tableMeta == NULL) { + while (retries++ <= TSDB_MAX_REPLICA && tableMeta == NULL) { STscObj* pObj = (STscObj*)taos; if (pObj == NULL || pObj->signature != pObj) { terrno = TSDB_CODE_TSC_DISCONNECTED; @@ -567,55 +633,24 @@ static int32_t retrieveTableMeta(TAOS* taos, char* tableName, STableMeta** pTabl } tscDebug("SML:0x%" PRIx64 " retrieve table meta. super table name: %s", info->id, tableName); - - char sql[256]; - snprintf(sql, 256, "describe %s", tableName); - TAOS_RES* res = taos_query(taos, sql); - code = taos_errno(res); - if (code != 0) { - tscError("SML:0x%" PRIx64 " describe table failure. %s", info->id, taos_errstr(res)); + code = getSuperTableMetaFromLocalCache(taos, tableName, &tableMeta, info); + if (code == TSDB_CODE_SUCCESS) { + tscDebug("SML:0x%" PRIx64 " successfully retrieved table meta. super table name: %s", info->id, tableName); + break; + } else if (code == TSDB_CODE_TSC_NO_META_CACHED) { + char sql[256]; + snprintf(sql, 256, "describe %s", tableName); + TAOS_RES* res = taos_query(taos, sql); + code = taos_errno(res); + if (code != 0) { + tscError("SML:0x%" PRIx64 " describe table failure. %s", info->id, taos_errstr(res)); + taos_free_result(res); + return code; + } taos_free_result(res); + } else { return code; } - taos_free_result(res); - - SSqlObj* pSql = calloc(1, sizeof(SSqlObj)); - if (pSql == NULL) { - tscError("SML:0x%" PRIx64 " failed to allocate memory, reason:%s", info->id, strerror(errno)); - code = TSDB_CODE_TSC_OUT_OF_MEMORY; - return code; - } - pSql->pTscObj = taos; - pSql->signature = pSql; - pSql->fp = NULL; - - registerSqlObj(pSql); - char tableNameBuf[TSDB_TABLE_NAME_LEN + TS_ESCAPE_CHAR_SIZE] = {0}; - memcpy(tableNameBuf, tableName, strlen(tableName)); - SStrToken tableToken = {.z = tableNameBuf, .n = (uint32_t)strlen(tableName), .type = TK_ID}; - tGetToken(tableNameBuf, &tableToken.type); - bool dbIncluded = false; - // Check if the table name available or not - if (tscValidateName(&tableToken, true, &dbIncluded) != TSDB_CODE_SUCCESS) { - code = TSDB_CODE_TSC_INVALID_TABLE_ID_LENGTH; - sprintf(pSql->cmd.payload, "table name is invalid"); - taosReleaseRef(tscObjRef, pSql->self); - return code; - } - - SName sname = {0}; - if ((code = tscSetTableFullName(&sname, &tableToken, pSql, dbIncluded)) != TSDB_CODE_SUCCESS) { - taosReleaseRef(tscObjRef, pSql->self); - return code; - } - - char fullTableName[TSDB_TABLE_FNAME_LEN] = {0}; - memset(fullTableName, 0, tListLen(fullTableName)); - tNameExtractFullName(&sname, fullTableName); - - size_t size = 0; - taosHashGetCloneExt(UTIL_GET_TABLEMETA(pSql), fullTableName, strlen(fullTableName), NULL, (void**)&tableMeta, &size); - taosReleaseRef(tscObjRef, pSql->self); } if (tableMeta != NULL) { @@ -718,72 +753,303 @@ static int32_t modifyDBSchemas(TAOS* taos, SArray* stableSchemas, SSmlLinesInfo* return 0; } -static int32_t creatChildTableIfNotExists(TAOS* taos, const char* cTableName, const char* sTableName, - SArray* tagsSchema, SArray* tagsBind, SSmlLinesInfo* info) { - size_t numTags = taosArrayGetSize(tagsSchema); +static int32_t arrangePointsByChildTableName(TAOS_SML_DATA_POINT* points, int numPoints, + SHashObj* cname2points, SArray* stableSchemas, SSmlLinesInfo* info) { + for (int32_t i = 0; i < numPoints; ++i) { + TAOS_SML_DATA_POINT * point = points + i; + SSmlSTableSchema* stableSchema = taosArrayGet(stableSchemas, point->schemaIdx); + + for (int j = 0; j < point->tagNum; ++j) { + TAOS_SML_KV* kv = point->tags + j; + if (kv->type == TSDB_DATA_TYPE_TIMESTAMP) { + int64_t ts = *(int64_t*)(kv->value); + ts = convertTimePrecision(ts, TSDB_TIME_PRECISION_NANO, stableSchema->precision); + *(int64_t*)(kv->value) = ts; + } + } + + for (int j = 0; j < point->fieldNum; ++j) { + TAOS_SML_KV* kv = point->fields + j; + if (kv->type == TSDB_DATA_TYPE_TIMESTAMP) { + int64_t ts = *(int64_t*)(kv->value); + ts = convertTimePrecision(ts, TSDB_TIME_PRECISION_NANO, stableSchema->precision); + *(int64_t*)(kv->value) = ts; + } + } + + SArray* cTablePoints = NULL; + SArray** pCTablePoints = taosHashGet(cname2points, point->childTableName, strlen(point->childTableName)); + if (pCTablePoints) { + cTablePoints = *pCTablePoints; + } else { + cTablePoints = taosArrayInit(64, sizeof(point)); + taosHashPut(cname2points, point->childTableName, strlen(point->childTableName), &cTablePoints, POINTER_BYTES); + } + taosArrayPush(cTablePoints, &point); + } + + return 0; +} + +static int32_t applyChildTableDataPointsWithInsertSQL(TAOS* taos, char* cTableName, char* sTableName, SSmlSTableSchema* sTableSchema, + SArray* cTablePoints, size_t rowSize, SSmlLinesInfo* info) { + int32_t code = TSDB_CODE_SUCCESS; + size_t numTags = taosArrayGetSize(sTableSchema->tags); + size_t numCols = taosArrayGetSize(sTableSchema->fields); + size_t rows = taosArrayGetSize(cTablePoints); + SArray* tagsSchema = sTableSchema->tags; + SArray* colsSchema = sTableSchema->fields; + + TAOS_SML_KV* tagKVs[TSDB_MAX_TAGS] = {0}; + for (int i= 0; i < rows; ++i) { + TAOS_SML_DATA_POINT * pDataPoint = taosArrayGetP(cTablePoints, i); + for (int j = 0; j < pDataPoint->tagNum; ++j) { + TAOS_SML_KV* kv = pDataPoint->tags + j; + tagKVs[kv->fieldSchemaIdx] = kv; + } + } + char* sql = malloc(tsMaxSQLStringLen+1); if (sql == NULL) { tscError("malloc sql memory error"); return TSDB_CODE_TSC_OUT_OF_MEMORY; } - int freeBytes = tsMaxSQLStringLen + 1; - sprintf(sql, "create table if not exists %s using %s", cTableName, sTableName); - snprintf(sql+strlen(sql), freeBytes-strlen(sql), "("); + int32_t freeBytes = tsMaxSQLStringLen + 1 ; + int32_t totalLen = 0; + totalLen += sprintf(sql, "insert into %s using %s (", cTableName, sTableName); for (int i = 0; i < numTags; ++i) { SSchema* tagSchema = taosArrayGet(tagsSchema, i); - snprintf(sql+strlen(sql), freeBytes-strlen(sql), "%s,", tagSchema->name); + totalLen += snprintf(sql+totalLen, freeBytes-totalLen, "%s,", tagSchema->name); } - snprintf(sql + strlen(sql) - 1, freeBytes-strlen(sql)+1, ")"); + --totalLen; + totalLen += snprintf(sql + totalLen, freeBytes-totalLen, ")"); - snprintf(sql + strlen(sql), freeBytes-strlen(sql), " tags ("); + totalLen += snprintf(sql + totalLen, freeBytes-totalLen, " tags ("); +// for (int i = 0; i < numTags; ++i) { +// snprintf(sql+strlen(sql), freeBytes-strlen(sql), "?,"); +// } for (int i = 0; i < numTags; ++i) { - snprintf(sql+strlen(sql), freeBytes-strlen(sql), "?,"); + if (tagKVs[i] == NULL) { + totalLen += snprintf(sql + totalLen, freeBytes-totalLen, "NULL,"); + } else { + TAOS_SML_KV* kv = tagKVs[i]; + size_t beforeLen = totalLen; + int32_t len = 0; + converToStr(sql+beforeLen, kv->type, kv->value, kv->length, &len); + totalLen += len; + totalLen += snprintf(sql+totalLen, freeBytes-totalLen, ","); + } } - snprintf(sql + strlen(sql) - 1, freeBytes-strlen(sql)+1, ")"); - sql[strlen(sql)] = '\0'; + --totalLen; + totalLen += snprintf(sql + totalLen, freeBytes-totalLen, ") ("); - tscDebug("SML:0x%"PRIx64" create table : %s", info->id, sql); + for (int i = 0; i < numCols; ++i) { + SSchema* colSchema = taosArrayGet(colsSchema, i); + totalLen += snprintf(sql+totalLen, freeBytes-totalLen, "%s,", colSchema->name); + } + --totalLen; + totalLen += snprintf(sql + totalLen, freeBytes-totalLen, ") values "); - TAOS_STMT* stmt = taos_stmt_init(taos); - if (stmt == NULL) { - free(sql); - return TSDB_CODE_TSC_OUT_OF_MEMORY; + TAOS_SML_KV** colKVs = malloc(numCols*sizeof(TAOS_SML_KV*)); + for (int r = 0; r < rows; ++r) { + totalLen += snprintf(sql + totalLen, freeBytes-totalLen, "("); + + memset(colKVs, 0, numCols*sizeof(TAOS_SML_KV*)); + + TAOS_SML_DATA_POINT* point = taosArrayGetP(cTablePoints, r); + for (int i = 0; i < point->fieldNum; ++i) { + TAOS_SML_KV* kv = point->fields + i; + colKVs[kv->fieldSchemaIdx] = kv; + } + + for (int i = 0; i < numCols; ++i) { + if (colKVs[i] == NULL) { + totalLen += snprintf(sql + totalLen, freeBytes-totalLen, "NULL,"); + } else { + TAOS_SML_KV* kv = colKVs[i]; + size_t beforeLen = totalLen; + int32_t len = 0; + converToStr(sql+beforeLen, kv->type, kv->value, kv->length, &len); + totalLen += len; + totalLen += snprintf(sql+totalLen, freeBytes-totalLen, ","); + } + } + --totalLen; + totalLen += snprintf(sql+totalLen, freeBytes - totalLen, ")"); } - int32_t code; - code = taos_stmt_prepare(stmt, sql, (unsigned long)strlen(sql)); + free(colKVs); + sql[totalLen] = '\0'; + + tscDebug("SML:0x%"PRIx64" insert child table table %s of super table %s sql: %s", info->id, cTableName, sTableName, sql); + TAOS_RES* res = taos_query(taos, sql); free(sql); + code = taos_errno(res); + info->affectedRows += taos_affected_rows(res); + taos_free_result(res); + return code; +} - if (code != 0) { - tscError("SML:0x%"PRIx64" taos_stmt_prepare returns %d:%s", info->id, code, tstrerror(code)); - taos_stmt_close(stmt); - return code; +static int32_t applyChildTableDataPointsWithStmt(TAOS* taos, char* cTableName, char* sTableName, SSmlSTableSchema* sTableSchema, + SArray* cTablePoints, size_t rowSize, SSmlLinesInfo* info) { + size_t numTags = taosArrayGetSize(sTableSchema->tags); + size_t numCols = taosArrayGetSize(sTableSchema->fields); + size_t rows = taosArrayGetSize(cTablePoints); + + TAOS_SML_KV* tagKVs[TSDB_MAX_TAGS] = {0}; + for (int i= 0; i < rows; ++i) { + TAOS_SML_DATA_POINT * pDataPoint = taosArrayGetP(cTablePoints, i); + for (int j = 0; j < pDataPoint->tagNum; ++j) { + TAOS_SML_KV* kv = pDataPoint->tags + j; + tagKVs[kv->fieldSchemaIdx] = kv; + } } - code = taos_stmt_bind_param(stmt, TARRAY_GET_START(tagsBind)); - if (code != 0) { - tscError("SML:0x%"PRIx64" taos_stmt_bind_param returns %d:%s", info->id, code, tstrerror(code)); - taos_stmt_close(stmt); - return code; + //tag bind + SArray* tagBinds = taosArrayInit(numTags, sizeof(TAOS_BIND)); + taosArraySetSize(tagBinds, numTags); + int isNullColBind = TSDB_TRUE; + for (int j = 0; j < numTags; ++j) { + TAOS_BIND* bind = taosArrayGet(tagBinds, j); + bind->is_null = &isNullColBind; + } + for (int j = 0; j < numTags; ++j) { + if (tagKVs[j] == NULL) continue; + TAOS_SML_KV* kv = tagKVs[j]; + TAOS_BIND* bind = taosArrayGet(tagBinds, kv->fieldSchemaIdx); + bind->buffer_type = kv->type; + bind->length = malloc(sizeof(uintptr_t*)); + *bind->length = kv->length; + bind->buffer = kv->value; + bind->is_null = NULL; } - code = taos_stmt_execute(stmt); - if (code != 0) { - tscError("SML:0x%"PRIx64" taos_stmt_execute returns %d:%s", info->id, code, tstrerror(code)); - taos_stmt_close(stmt); - return code; + //rows bind + SArray* rowsBind = taosArrayInit(rows, POINTER_BYTES); + for (int i = 0; i < rows; ++i) { + TAOS_SML_DATA_POINT* point = taosArrayGetP(cTablePoints, i); + + TAOS_BIND* colBinds = calloc(numCols, sizeof(TAOS_BIND)); + if (colBinds == NULL) { + tscError("SML:0x%"PRIx64" taos_sml_insert insert points, failed to allocated memory for TAOS_BIND, " + "num of rows: %zu, num of cols: %zu", info->id, rows, numCols); + return TSDB_CODE_TSC_OUT_OF_MEMORY; + } + + for (int j = 0; j < numCols; ++j) { + TAOS_BIND* bind = colBinds + j; + bind->is_null = &isNullColBind; + } + for (int j = 0; j < point->fieldNum; ++j) { + TAOS_SML_KV* kv = point->fields + j; + TAOS_BIND* bind = colBinds + kv->fieldSchemaIdx; + bind->buffer_type = kv->type; + bind->length = malloc(sizeof(uintptr_t*)); + *bind->length = kv->length; + bind->buffer = kv->value; + bind->is_null = NULL; + } + taosArrayPush(rowsBind, &colBinds); } - code = taos_stmt_close(stmt); + int32_t code = 0; + code = insertChildTablePointsBatch(taos, cTableName, sTableName, sTableSchema->tags, tagBinds, sTableSchema->fields, rowsBind, rowSize, info); if (code != 0) { - tscError("SML:0x%"PRIx64" taos_stmt_close return %d:%s", info->id, code, tstrerror(code)); - return code; + tscError("SML:0x%"PRIx64" insert into child table %s failed. error %s", info->id, cTableName, tstrerror(code)); + } + + //free rows bind + for (int i = 0; i < rows; ++i) { + TAOS_BIND* colBinds = taosArrayGetP(rowsBind, i); + for (int j = 0; j < numCols; ++j) { + TAOS_BIND* bind = colBinds + j; + free(bind->length); + } + free(colBinds); + } + taosArrayDestroy(rowsBind); + //free tag bind + for (int i = 0; i < taosArrayGetSize(tagBinds); ++i) { + TAOS_BIND* bind = taosArrayGet(tagBinds, i); + free(bind->length); } + taosArrayDestroy(tagBinds); return code; } -static int32_t doInsertChildTableWithStmt(TAOS* taos, char* sql, char* cTableName, SArray* batchBind, SSmlLinesInfo* info) { +static int32_t insertChildTablePointsBatch(TAOS* taos, char* cTableName, char* sTableName, + SArray* tagsSchema, SArray* tagsBind, + SArray* colsSchema, SArray* rowsBind, + size_t rowSize, SSmlLinesInfo* info) { + size_t numTags = taosArrayGetSize(tagsSchema); + size_t numCols = taosArrayGetSize(colsSchema); + char* sql = malloc(tsMaxSQLStringLen+1); + if (sql == NULL) { + tscError("malloc sql memory error"); + return TSDB_CODE_TSC_OUT_OF_MEMORY; + } + + int32_t freeBytes = tsMaxSQLStringLen + 1 ; + sprintf(sql, "insert into ? using %s (", sTableName); + for (int i = 0; i < numTags; ++i) { + SSchema* tagSchema = taosArrayGet(tagsSchema, i); + snprintf(sql+strlen(sql), freeBytes-strlen(sql), "%s,", tagSchema->name); + } + snprintf(sql + strlen(sql) - 1, freeBytes-strlen(sql)+1, ")"); + + snprintf(sql + strlen(sql), freeBytes-strlen(sql), " tags ("); + + for (int i = 0; i < numTags; ++i) { + snprintf(sql+strlen(sql), freeBytes-strlen(sql), "?,"); + } + snprintf(sql + strlen(sql) - 1, freeBytes-strlen(sql)+1, ") ("); + + for (int i = 0; i < numCols; ++i) { + SSchema* colSchema = taosArrayGet(colsSchema, i); + snprintf(sql+strlen(sql), freeBytes-strlen(sql), "%s,", colSchema->name); + } + snprintf(sql + strlen(sql)-1, freeBytes-strlen(sql)+1, ") values ("); + + for (int i = 0; i < numCols; ++i) { + snprintf(sql+strlen(sql), freeBytes-strlen(sql), "?,"); + } + snprintf(sql + strlen(sql)-1, freeBytes-strlen(sql)+1, ")"); + sql[strlen(sql)] = '\0'; + + tscDebug("SML:0x%"PRIx64" insert child table table %s of super table %s : %s", info->id, cTableName, sTableName, sql); + + size_t rows = taosArrayGetSize(rowsBind); + size_t maxBatchSize = TSDB_MAX_WAL_SIZE/rowSize * 4 / 5; + size_t batchSize = MIN(maxBatchSize, rows); + tscDebug("SML:0x%"PRIx64" insert rows into child table %s. num of rows: %zu, batch size: %zu", + info->id, cTableName, rows, batchSize); + SArray* batchBind = taosArrayInit(batchSize, POINTER_BYTES); + int32_t code = TSDB_CODE_SUCCESS; + for (int i = 0; i < rows;) { + int j = i; + for (; j < i + batchSize && j i) { + tscDebug("SML:0x%"PRIx64" insert child table batch from line %d to line %d.", info->id, i, j - 1); + code = doInsertChildTablePoints(taos, sql, cTableName, tagsBind, batchBind, info); + if (code != 0) { + taosArrayDestroy(batchBind); + tfree(sql); + return code; + } + taosArrayClear(batchBind); + } + i = j; + } + taosArrayDestroy(batchBind); + tfree(sql); + return code; + +} +static int32_t doInsertChildTablePoints(TAOS* taos, char* sql, char* cTableName, SArray* tagsBind, SArray* batchBind, + SSmlLinesInfo* info) { int32_t code = 0; TAOS_STMT* stmt = taos_stmt_init(taos); @@ -802,7 +1068,7 @@ static int32_t doInsertChildTableWithStmt(TAOS* taos, char* sql, char* cTableNam bool tryAgain = false; int32_t try = 0; do { - code = taos_stmt_set_tbname(stmt, cTableName); + code = taos_stmt_set_tbname_tags(stmt, cTableName, TARRAY_GET_START(tagsBind)); if (code != 0) { tscError("SML:0x%"PRIx64" taos_stmt_set_tbname return %d:%s", info->id, code, taos_stmt_errstr(stmt)); @@ -843,7 +1109,7 @@ static int32_t doInsertChildTableWithStmt(TAOS* taos, char* sql, char* cTableNam tscError("SML:0x%"PRIx64" taos_stmt_execute return %d:%s, try:%d", info->id, code, taos_stmt_errstr(stmt), try); } tscDebug("SML:0x%"PRIx64" taos_stmt_execute inserted %d rows", info->id, taos_stmt_affected_rows(stmt)); - + tryAgain = false; if ((code == TSDB_CODE_TDB_INVALID_TABLE_ID || code == TSDB_CODE_VND_INVALID_VGROUP_ID @@ -876,189 +1142,19 @@ static int32_t doInsertChildTableWithStmt(TAOS* taos, char* sql, char* cTableNam taos_stmt_close(stmt); return code; -} - -static int32_t insertChildTableBatch(TAOS* taos, char* cTableName, SArray* colsSchema, SArray* rowsBind, size_t rowSize, SSmlLinesInfo* info) { - size_t numCols = taosArrayGetSize(colsSchema); - char* sql = malloc(tsMaxSQLStringLen+1); - if (sql == NULL) { - tscError("malloc sql memory error"); - return TSDB_CODE_TSC_OUT_OF_MEMORY; - } - - int32_t freeBytes = tsMaxSQLStringLen + 1 ; - sprintf(sql, "insert into ? ("); - - for (int i = 0; i < numCols; ++i) { - SSchema* colSchema = taosArrayGet(colsSchema, i); - snprintf(sql+strlen(sql), freeBytes-strlen(sql), "%s,", colSchema->name); - } - snprintf(sql + strlen(sql)-1, freeBytes-strlen(sql)+1, ") values ("); - - for (int i = 0; i < numCols; ++i) { - snprintf(sql+strlen(sql), freeBytes-strlen(sql), "?,"); - } - snprintf(sql + strlen(sql)-1, freeBytes-strlen(sql)+1, ")"); - sql[strlen(sql)] = '\0'; - - size_t rows = taosArrayGetSize(rowsBind); - size_t maxBatchSize = TSDB_MAX_WAL_SIZE/rowSize * 4 / 5; - size_t batchSize = MIN(maxBatchSize, rows); - tscDebug("SML:0x%"PRIx64" insert rows into child table %s. num of rows: %zu, batch size: %zu", - info->id, cTableName, rows, batchSize); - SArray* batchBind = taosArrayInit(batchSize, POINTER_BYTES); - int32_t code = TSDB_CODE_SUCCESS; - for (int i = 0; i < rows;) { - int j = i; - for (; j < i + batchSize && j i) { - tscDebug("SML:0x%"PRIx64" insert child table batch from line %d to line %d.", info->id, i, j - 1); - code = doInsertChildTableWithStmt(taos, sql, cTableName, batchBind, info); - if (code != 0) { - taosArrayDestroy(batchBind); - tfree(sql); - return code; - } - taosArrayClear(batchBind); - } - i = j; - } - taosArrayDestroy(batchBind); - tfree(sql); - return code; -} - -static int32_t arrangePointsByChildTableName(TAOS_SML_DATA_POINT* points, int numPoints, - SHashObj* cname2points, SArray* stableSchemas, SSmlLinesInfo* info) { - for (int32_t i = 0; i < numPoints; ++i) { - TAOS_SML_DATA_POINT * point = points + i; - SSmlSTableSchema* stableSchema = taosArrayGet(stableSchemas, point->schemaIdx); - - for (int j = 0; j < point->tagNum; ++j) { - TAOS_SML_KV* kv = point->tags + j; - if (kv->type == TSDB_DATA_TYPE_TIMESTAMP) { - int64_t ts = *(int64_t*)(kv->value); - ts = convertTimePrecision(ts, TSDB_TIME_PRECISION_NANO, stableSchema->precision); - *(int64_t*)(kv->value) = ts; - } - } - - for (int j = 0; j < point->fieldNum; ++j) { - TAOS_SML_KV* kv = point->fields + j; - if (kv->type == TSDB_DATA_TYPE_TIMESTAMP) { - int64_t ts = *(int64_t*)(kv->value); - ts = convertTimePrecision(ts, TSDB_TIME_PRECISION_NANO, stableSchema->precision); - *(int64_t*)(kv->value) = ts; - } - } - - SArray* cTablePoints = NULL; - SArray** pCTablePoints = taosHashGet(cname2points, point->childTableName, strlen(point->childTableName)); - if (pCTablePoints) { - cTablePoints = *pCTablePoints; - } else { - cTablePoints = taosArrayInit(64, sizeof(point)); - taosHashPut(cname2points, point->childTableName, strlen(point->childTableName), &cTablePoints, POINTER_BYTES); - } - taosArrayPush(cTablePoints, &point); - } return 0; } -static int32_t applyChildTableTags(TAOS* taos, char* cTableName, char* sTableName, - SSmlSTableSchema* sTableSchema, SArray* cTablePoints, SSmlLinesInfo* info) { - size_t numTags = taosArrayGetSize(sTableSchema->tags); - size_t rows = taosArrayGetSize(cTablePoints); - - TAOS_SML_KV* tagKVs[TSDB_MAX_TAGS] = {0}; - for (int i= 0; i < rows; ++i) { - TAOS_SML_DATA_POINT * pDataPoint = taosArrayGetP(cTablePoints, i); - for (int j = 0; j < pDataPoint->tagNum; ++j) { - TAOS_SML_KV* kv = pDataPoint->tags + j; - tagKVs[kv->fieldSchemaIdx] = kv; - } - } - - SArray* tagBinds = taosArrayInit(numTags, sizeof(TAOS_BIND)); - taosArraySetSize(tagBinds, numTags); - int isNullColBind = TSDB_TRUE; - for (int j = 0; j < numTags; ++j) { - TAOS_BIND* bind = taosArrayGet(tagBinds, j); - bind->is_null = &isNullColBind; - } - for (int j = 0; j < numTags; ++j) { - if (tagKVs[j] == NULL) continue; - TAOS_SML_KV* kv = tagKVs[j]; - TAOS_BIND* bind = taosArrayGet(tagBinds, kv->fieldSchemaIdx); - bind->buffer_type = kv->type; - bind->length = malloc(sizeof(uintptr_t*)); - *bind->length = kv->length; - bind->buffer = kv->value; - bind->is_null = NULL; - } - - int32_t code = creatChildTableIfNotExists(taos, cTableName, sTableName, sTableSchema->tags, tagBinds, info); - - for (int i = 0; i < taosArrayGetSize(tagBinds); ++i) { - TAOS_BIND* bind = taosArrayGet(tagBinds, i); - free(bind->length); - } - taosArrayDestroy(tagBinds); - return code; -} - -static int32_t applyChildTableFields(TAOS* taos, SSmlSTableSchema* sTableSchema, char* cTableName, - SArray* cTablePoints, size_t rowSize, SSmlLinesInfo* info) { +static int32_t applyChildTableDataPoints(TAOS* taos, char* cTableName, char* sTableName, SSmlSTableSchema* sTableSchema, + SArray* cTablePoints, size_t rowSize, SSmlLinesInfo* info) { int32_t code = TSDB_CODE_SUCCESS; - - size_t numCols = taosArrayGetSize(sTableSchema->fields); - size_t rows = taosArrayGetSize(cTablePoints); - SArray* rowsBind = taosArrayInit(rows, POINTER_BYTES); - - int isNullColBind = TSDB_TRUE; - for (int i = 0; i < rows; ++i) { - TAOS_SML_DATA_POINT* point = taosArrayGetP(cTablePoints, i); - - TAOS_BIND* colBinds = calloc(numCols, sizeof(TAOS_BIND)); - if (colBinds == NULL) { - tscError("SML:0x%"PRIx64" taos_sml_insert insert points, failed to allocated memory for TAOS_BIND, " - "num of rows: %zu, num of cols: %zu", info->id, rows, numCols); - return TSDB_CODE_TSC_OUT_OF_MEMORY; - } - - for (int j = 0; j < numCols; ++j) { - TAOS_BIND* bind = colBinds + j; - bind->is_null = &isNullColBind; - } - for (int j = 0; j < point->fieldNum; ++j) { - TAOS_SML_KV* kv = point->fields + j; - TAOS_BIND* bind = colBinds + kv->fieldSchemaIdx; - bind->buffer_type = kv->type; - bind->length = malloc(sizeof(uintptr_t*)); - *bind->length = kv->length; - bind->buffer = kv->value; - bind->is_null = NULL; - } - taosArrayPush(rowsBind, &colBinds); - } - - code = insertChildTableBatch(taos, cTableName, sTableSchema->fields, rowsBind, rowSize, info); - if (code != 0) { - tscError("SML:0x%"PRIx64" insert into child table %s failed. error %s", info->id, cTableName, tstrerror(code)); - } - - for (int i = 0; i < rows; ++i) { - TAOS_BIND* colBinds = taosArrayGetP(rowsBind, i); - for (int j = 0; j < numCols; ++j) { - TAOS_BIND* bind = colBinds + j; - free(bind->length); - } - free(colBinds); + size_t childTableDataPoints = taosArrayGetSize(cTablePoints); + if (childTableDataPoints < 10) { + code = applyChildTableDataPointsWithInsertSQL(taos, cTableName, sTableName, sTableSchema, cTablePoints, rowSize, info); + } else { + code = applyChildTableDataPointsWithStmt(taos, cTableName, sTableName, sTableSchema, cTablePoints, rowSize, info); } - taosArrayDestroy(rowsBind); return code; } @@ -1075,13 +1171,6 @@ static int32_t applyDataPoints(TAOS* taos, TAOS_SML_DATA_POINT* points, int32_t TAOS_SML_DATA_POINT* point = taosArrayGetP(cTablePoints, 0); SSmlSTableSchema* sTableSchema = taosArrayGet(stableSchemas, point->schemaIdx); - tscDebug("SML:0x%"PRIx64" apply child table tags. child table: %s", info->id, point->childTableName); - code = applyChildTableTags(taos, point->childTableName, point->stableName, sTableSchema, cTablePoints, info); - if (code != 0) { - tscError("apply child table tags failed. child table %s, error %s", point->childTableName, tstrerror(code)); - goto cleanup; - } - size_t rowSize = 0; size_t numCols = taosArrayGetSize(sTableSchema->fields); for (int i = 0; i < numCols; ++i) { @@ -1089,10 +1178,11 @@ static int32_t applyDataPoints(TAOS* taos, TAOS_SML_DATA_POINT* points, int32_t rowSize += colSchema->bytes; } - tscDebug("SML:0x%"PRIx64" apply child table points. child table: %s, row size: %zu", info->id, point->childTableName, rowSize); - code = applyChildTableFields(taos, sTableSchema, point->childTableName, cTablePoints, rowSize, info); + tscDebug("SML:0x%"PRIx64" apply child table points. child table: %s of super table %s, row size: %zu", + info->id, point->childTableName, point->stableName, rowSize); + code = applyChildTableDataPoints(taos, point->childTableName, point->stableName, sTableSchema, cTablePoints, rowSize, info); if (code != 0) { - tscError("SML:0x%"PRIx64" Apply child table fields failed. child table %s, error %s", info->id, point->childTableName, tstrerror(code)); + tscError("SML:0x%"PRIx64" Apply child table points failed. child table %s, error %s", info->id, point->childTableName, tstrerror(code)); goto cleanup; } @@ -1112,6 +1202,60 @@ cleanup: return code; } +static int doSmlInsertOneDataPoint(TAOS* taos, TAOS_SML_DATA_POINT* point, SSmlLinesInfo* info) { + int32_t code = TSDB_CODE_SUCCESS; + + if (!point->childTableName) { + int tableNameLen = TSDB_TABLE_NAME_LEN; + point->childTableName = calloc(1, tableNameLen + 1); + getSmlMd5ChildTableName(point, point->childTableName, &tableNameLen, info); + point->childTableName[tableNameLen] = '\0'; + } + + STableMeta* tableMeta = NULL; + int32_t ret = getSuperTableMetaFromLocalCache(taos, point->stableName, &tableMeta, info); + if (ret != TSDB_CODE_SUCCESS) { + return ret; + } + uint8_t precision = tableMeta->tableInfo.precision; + free(tableMeta); + + char* sql = malloc(TSDB_MAX_SQL_LEN + 1); + int freeBytes = TSDB_MAX_SQL_LEN; + int sqlLen = 0; + sqlLen += snprintf(sql + sqlLen, freeBytes - sqlLen, "insert into %s(", point->childTableName); + for (int col = 0; col < point->fieldNum; ++col) { + TAOS_SML_KV* kv = point->fields + col; + sqlLen += snprintf(sql + sqlLen, freeBytes - sqlLen, "%s,", kv->key); + } + --sqlLen; + sqlLen += snprintf(sql + sqlLen, freeBytes - sqlLen, ") values ("); + TAOS_SML_KV* tsField = point->fields + 0; + int64_t ts = *(int64_t*)(tsField->value); + ts = convertTimePrecision(ts, TSDB_TIME_PRECISION_NANO, precision); + sqlLen += snprintf(sql + sqlLen, freeBytes - sqlLen, "%" PRId64 ",", ts); + for (int col = 1; col < point->fieldNum; ++col) { + TAOS_SML_KV* kv = point->fields + col; + int32_t len = 0; + converToStr(sql + sqlLen, kv->type, kv->value, kv->length, &len); + sqlLen += len; + sqlLen += snprintf(sql + sqlLen, freeBytes - sqlLen, ","); + } + --sqlLen; + sqlLen += snprintf(sql + sqlLen, freeBytes - sqlLen, ")"); + sql[sqlLen] = 0; + + tscDebug("SML:0x%" PRIx64 " insert child table table %s of super table %s sql: %s", info->id, + point->childTableName, point->stableName, sql); + TAOS_RES* res = taos_query(taos, sql); + free(sql); + code = taos_errno(res); + info->affectedRows = taos_affected_rows(res); + taos_free_result(res); + + return code; +} + int tscSmlInsert(TAOS* taos, TAOS_SML_DATA_POINT* points, int numPoint, SSmlLinesInfo* info) { tscDebug("SML:0x%"PRIx64" taos_sml_insert. number of points: %d", info->id, numPoint); @@ -1119,6 +1263,14 @@ int tscSmlInsert(TAOS* taos, TAOS_SML_DATA_POINT* points, int numPoint, SSmlLine info->affectedRows = 0; + if (numPoint == 1) { + TAOS_SML_DATA_POINT* point = points + 0; + code = doSmlInsertOneDataPoint(taos, point, info); + if (code == TSDB_CODE_SUCCESS) { + return code; + } + } + tscDebug("SML:0x%"PRIx64" build data point schemas", info->id); SArray* stableSchemas = taosArrayInit(32, sizeof(SSmlSTableSchema)); // SArray code = buildDataPointSchemas(points, numPoint, stableSchemas, info); @@ -1150,14 +1302,6 @@ clean_up: return code; } -int tsc_sml_insert(TAOS* taos, TAOS_SML_DATA_POINT* points, int numPoint) { - SSmlLinesInfo* info = calloc(1, sizeof(SSmlLinesInfo)); - info->id = genLinesSmlId(); - int code = tscSmlInsert(taos, points, numPoint, info); - free(info); - return code; -} - //========================================================================= /* Field Escape charaters diff --git a/src/client/src/tscParseOpenTSDB.c b/src/client/src/tscParseOpenTSDB.c index d064ede134129d796928768910c56573712319d1..82c554ee0a0edb3d9fec32cc4b09ba96e32e9285 100644 --- a/src/client/src/tscParseOpenTSDB.c +++ b/src/client/src/tscParseOpenTSDB.c @@ -125,8 +125,9 @@ static int32_t parseTelnetTimeStamp(TAOS_SML_KV **pTS, int *num_kvs, const char } tfree(value); - (*pTS)->key = tcalloc(sizeof(key), 1); + (*pTS)->key = tcalloc(sizeof(key) + TS_ESCAPE_CHAR_SIZE, 1); memcpy((*pTS)->key, key, sizeof(key)); + addEscapeCharToString((*pTS)->key, (int32_t)strlen(key)); *num_kvs += 1; *index = cur + 1; diff --git a/src/client/src/tscPrepare.c b/src/client/src/tscPrepare.c index 215861295fa0ff94352956fa3fd740ace9e90766..8d1a79e734cabf6694daf30d8887265488bcf630 100644 --- a/src/client/src/tscPrepare.c +++ b/src/client/src/tscPrepare.c @@ -1533,6 +1533,41 @@ int stmtGenInsertStatement(SSqlObj* pSql, STscStmt* pStmt, const char* name, TAO return TSDB_CODE_SUCCESS; } +int32_t stmtValidateValuesFields(SSqlCmd *pCmd, char * sql) { + int32_t loopCont = 1, index0 = 0, values = 0; + SStrToken sToken; + + while (loopCont) { + sToken = tStrGetToken(sql, &index0, false); + if (sToken.n <= 0) { + return TSDB_CODE_SUCCESS; + } + + switch (sToken.type) { + case TK_RP: + if (values) { + return TSDB_CODE_SUCCESS; + } + break; + case TK_VALUES: + values = 1; + break; + case TK_QUESTION: + case TK_LP: + break; + default: + if (values) { + tscError("only ? allowed in values"); + return tscInvalidOperationMsg(pCmd->payload, "only ? allowed in values", NULL); + } + break; + } + } + + return TSDB_CODE_SUCCESS; +} + + //////////////////////////////////////////////////////////////////////////////// // interface functions @@ -1637,6 +1672,11 @@ int taos_stmt_prepare(TAOS_STMT* stmt, const char* sql, unsigned long length) { STMT_RET(ret); } + ret = stmtValidateValuesFields(&pSql->cmd, pSql->sqlstr); + if (ret != TSDB_CODE_SUCCESS) { + STMT_RET(ret); + } + if (pStmt->multiTbInsert) { STMT_RET(TSDB_CODE_SUCCESS); } diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index c70819ef158de6d867a550d7baea838934e5df1a..a92bf7c22bef8cde1546b3cde4da46f9826f02e9 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -3457,7 +3457,9 @@ int32_t setKillInfo(SSqlObj* pSql, struct SSqlInfo* pInfo, int32_t killType) { return TSDB_CODE_TSC_INVALID_OPERATION; } - strncpy(pCmd->payload, idStr->z, idStr->n); + SKillQueryMsg* msg = (SKillQueryMsg*)pCmd->payload; + + strncpy(msg->queryId, idStr->z, idStr->n); const char delim = ':'; char* connIdStr = strtok(idStr->z, &delim); @@ -3465,7 +3467,7 @@ int32_t setKillInfo(SSqlObj* pSql, struct SSqlInfo* pInfo, int32_t killType) { int32_t connId = (int32_t)strtol(connIdStr, NULL, 10); if (connId <= 0) { - memset(pCmd->payload, 0, strlen(pCmd->payload)); + memset(msg, 0, sizeof(*msg)); return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg1); } @@ -3475,7 +3477,7 @@ int32_t setKillInfo(SSqlObj* pSql, struct SSqlInfo* pInfo, int32_t killType) { int32_t queryId = (int32_t)strtol(queryIdStr, NULL, 10); if (queryId <= 0) { - memset(pCmd->payload, 0, strlen(pCmd->payload)); + memset(msg, 0, sizeof(*msg)); if (killType == TSDB_SQL_KILL_QUERY) { return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg2); } else { @@ -6898,17 +6900,15 @@ int32_t validateLimitNode(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SSqlNode* pSqlN // todo refactor if (UTIL_TABLE_IS_SUPER_TABLE(pTableMetaInfo)) { - if (!tscQueryTags(pQueryInfo)) { // local handle the super table tag query - if (tscIsProjectionQueryOnSTable(pQueryInfo, 0)) { - if (pQueryInfo->slimit.limit > 0 || pQueryInfo->slimit.offset > 0) { - return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg2); - } + if (tscIsProjectionQueryOnSTable(pQueryInfo, 0)) { + if (pQueryInfo->slimit.limit > 0 || pQueryInfo->slimit.offset > 0) { + return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg2); + } - // for projection query on super table, all queries are subqueries - if (tscNonOrderedProjectionQueryOnSTable(pQueryInfo, 0) && - !TSDB_QUERY_HAS_TYPE(pQueryInfo->type, TSDB_QUERY_TYPE_JOIN_QUERY)) { - pQueryInfo->type |= TSDB_QUERY_TYPE_SUBQUERY; - } + // for projection query on super table, all queries are subqueries + if (tscNonOrderedProjectionQueryOnSTable(pQueryInfo, 0) && + !TSDB_QUERY_HAS_TYPE(pQueryInfo->type, TSDB_QUERY_TYPE_JOIN_QUERY)) { + pQueryInfo->type |= TSDB_QUERY_TYPE_SUBQUERY; } } @@ -7950,6 +7950,7 @@ int32_t doCheckForCreateFromStable(SSqlObj* pSql, SSqlInfo* pInfo) { const char* msg3 = "tag value too long"; const char* msg4 = "illegal value or data overflow"; const char* msg5 = "tags number not matched"; + const char* msg6 = "create table only from super table is allowed"; SSqlCmd* pCmd = &pSql->cmd; @@ -7997,6 +7998,10 @@ int32_t doCheckForCreateFromStable(SSqlObj* pSql, SSqlInfo* pInfo) { return code; } + if (!UTIL_TABLE_IS_SUPER_TABLE(pStableMetaInfo)) { + return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg6); + } + size_t valSize = taosArrayGetSize(pValList); // too long tag values will return invalid sql, not be truncated automatically @@ -9226,7 +9231,8 @@ int32_t validateSqlNode(SSqlObj* pSql, SSqlNode* pSqlNode, SQueryInfo* pQueryInf SExprInfo* pExpr = tscExprGet(pQueryInfo, i); int32_t f = pExpr->base.functionId; - if (f == TSDB_FUNC_DERIVATIVE || f == TSDB_FUNC_TWA || f == TSDB_FUNC_IRATE || f == TSDB_FUNC_RATE || f== TSDB_FUNC_DIFF) { + if (f == TSDB_FUNC_DERIVATIVE || f == TSDB_FUNC_TWA || f == TSDB_FUNC_IRATE || + f == TSDB_FUNC_RATE || f == TSDB_FUNC_DIFF) { return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg7); } } diff --git a/src/client/src/tscServer.c b/src/client/src/tscServer.c index 9947faf0524c6c3af090f78fb1d3c284cb61e754..896b5361435d78de1551d5bc9e0da61a19fd2e55 100644 --- a/src/client/src/tscServer.c +++ b/src/client/src/tscServer.c @@ -506,7 +506,7 @@ void tscProcessMsgFromServer(SRpcMsg *rpcMsg, SRpcEpSet *pEpSet) { } } - if (pRes->code == TSDB_CODE_SUCCESS && tscProcessMsgRsp[pCmd->command]) { + if (pRes->code == TSDB_CODE_SUCCESS && pCmd->command < TSDB_SQL_MAX && tscProcessMsgRsp[pCmd->command]) { rpcMsg->code = (*tscProcessMsgRsp[pCmd->command])(pSql); } @@ -906,6 +906,7 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) { SArray* queryOperator = createExecOperatorPlan(&query); SQueryTableMsg *pQueryMsg = (SQueryTableMsg *)pCmd->payload; + tstrncpy(pQueryMsg->version, version, tListLen(pQueryMsg->version)); int32_t numOfTags = query.numOfTags; @@ -1146,6 +1147,23 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) { memcpy(pMsg, pSql->sqlstr, sqlLen); pMsg += sqlLen; + +/* + //MSG EXTEND DEMO + pQueryMsg->extend = 1; + + STLV *tlv = (STLV *)pMsg; + tlv->type = htons(TLV_TYPE_DUMMY); + tlv->len = htonl(sizeof(int16_t)); + *(int16_t *)tlv->value = htons(12345); + pMsg += sizeof(*tlv) + ntohl(tlv->len); + + tlv = (STLV *)pMsg; + tlv->len = 0; + pMsg += sizeof(*tlv); + +*/ + int32_t msgLen = (int32_t)(pMsg - pCmd->payload); tscDebug("0x%"PRIx64" msg built success, len:%d bytes", pSql->self, msgLen); @@ -2813,7 +2831,11 @@ static int32_t getTableMetaFromMnode(SSqlObj *pSql, STableMetaInfo *pTableMetaIn tscAddQueryInfo(&pNew->cmd); SQueryInfo *pNewQueryInfo = tscGetQueryInfoS(&pNew->cmd); - if (TSDB_CODE_SUCCESS != tscAllocPayload(&pNew->cmd, TSDB_DEFAULT_PAYLOAD_SIZE + pSql->cmd.payloadLen)) { + int payLoadLen = TSDB_DEFAULT_PAYLOAD_SIZE + pSql->cmd.payloadLen; + if (autocreate && pSql->cmd.insertParam.tagData.dataLen != 0) { + payLoadLen += pSql->cmd.insertParam.tagData.dataLen; + } + if (TSDB_CODE_SUCCESS != tscAllocPayload(&pNew->cmd, payLoadLen)) { tscError("0x%"PRIx64" malloc failed for payload to get table meta", pSql->self); tscFreeSqlObj(pNew); diff --git a/src/client/src/tscUtil.c b/src/client/src/tscUtil.c index 835b32eaaa198445945aff5ddd72cedc444f8318..e6c4e12e34cee28b0402fe3104d298a4080e6e1c 100644 --- a/src/client/src/tscUtil.c +++ b/src/client/src/tscUtil.c @@ -81,23 +81,42 @@ int32_t converToStr(char *str, int type, void *buf, int32_t bufSize, int32_t *le break; case TSDB_DATA_TYPE_FLOAT: - n = sprintf(str, "%e", GET_FLOAT_VAL(buf)); + n = sprintf(str, "%.*e", DECIMAL_DIG, GET_FLOAT_VAL(buf)); break; case TSDB_DATA_TYPE_DOUBLE: - n = sprintf(str, "%e", GET_DOUBLE_VAL(buf)); + n = sprintf(str, "%.*e", DECIMAL_DIG, GET_DOUBLE_VAL(buf)); break; case TSDB_DATA_TYPE_BINARY: + if (bufSize < 0) { + tscError("invalid buf size"); + return TSDB_CODE_TSC_INVALID_VALUE; + } + int32_t escapeSize = 0; + *str++ = '\''; + ++escapeSize; + char* data = buf; + for (int32_t i = 0; i < bufSize; ++i) { + if (data[i] == '\'' || data[i] == '"') { + *str++ = '\\'; + ++escapeSize; + } + *str++ = data[i]; + } + *str = '\''; + ++escapeSize; + n = bufSize + escapeSize; + break; case TSDB_DATA_TYPE_NCHAR: if (bufSize < 0) { tscError("invalid buf size"); return TSDB_CODE_TSC_INVALID_VALUE; } - *str = '"'; + *str = '\''; memcpy(str + 1, buf, bufSize); - *(str + bufSize + 1) = '"'; + *(str + bufSize + 1) = '\''; n = bufSize + 2; break; diff --git a/src/common/inc/tdataformat.h b/src/common/inc/tdataformat.h index 3a5b49e9eee004f8a93121653781c23b5fd347bf..98134c2433b690239cf33608dce92ad3fbbcee62 100644 --- a/src/common/inc/tdataformat.h +++ b/src/common/inc/tdataformat.h @@ -448,13 +448,14 @@ typedef struct { #define kvRowSetNCols(r, n) kvRowNCols(r) = (n) #define kvRowColIdx(r) (SColIdx *)POINTER_SHIFT(r, TD_KV_ROW_HEAD_SIZE) #define kvRowValues(r) POINTER_SHIFT(r, TD_KV_ROW_HEAD_SIZE + sizeof(SColIdx) * kvRowNCols(r)) +#define kvRowKeys(r) POINTER_SHIFT(r, *(uint16_t *)POINTER_SHIFT(r, TD_KV_ROW_HEAD_SIZE + sizeof(int16_t))) #define kvRowCpy(dst, r) memcpy((dst), (r), kvRowLen(r)) #define kvRowColVal(r, colIdx) POINTER_SHIFT(kvRowValues(r), (colIdx)->offset) #define kvRowColIdxAt(r, i) (kvRowColIdx(r) + (i)) #define kvRowFree(r) tfree(r) #define kvRowEnd(r) POINTER_SHIFT(r, kvRowLen(r)) #define kvRowValLen(r) (kvRowLen(r) - TD_KV_ROW_HEAD_SIZE - sizeof(SColIdx) * kvRowNCols(r)) -#define kvRowTKey(r) (*(TKEY *)(kvRowValues(r))) +#define kvRowTKey(r) (*(TKEY *)(kvRowKeys(r))) #define kvRowKey(r) tdGetKey(kvRowTKey(r)) #define kvRowDeleted(r) TKEY_IS_DELETED(kvRowTKey(r)) @@ -652,7 +653,7 @@ static FORCE_INLINE char *memRowEnd(SMemRow row) { #define memRowKvVersion(r) (*(int16_t *)POINTER_SHIFT(r, TD_MEM_ROW_TYPE_SIZE)) #define memRowVersion(r) (isDataRow(r) ? memRowDataVersion(r) : memRowKvVersion(r)) // schema version #define memRowSetKvVersion(r, v) (memRowKvVersion(r) = (v)) -#define memRowTuple(r) (isDataRow(r) ? dataRowTuple(memRowDataBody(r)) : kvRowValues(memRowKvBody(r))) +#define memRowKeys(r) (isDataRow(r) ? dataRowTuple(memRowDataBody(r)) : kvRowKeys(memRowKvBody(r))) #define memRowTKey(r) (isDataRow(r) ? dataRowTKey(memRowDataBody(r)) : kvRowTKey(memRowKvBody(r))) #define memRowKey(r) (isDataRow(r) ? dataRowKey(memRowDataBody(r)) : kvRowKey(memRowKvBody(r))) diff --git a/src/common/src/tglobal.c b/src/common/src/tglobal.c index 83026a3774ab77aa4b5d4998225a4dcc5d10c121..b4bc38d53e517da33a7e71fe6b6b189c3d64d613 100644 --- a/src/common/src/tglobal.c +++ b/src/common/src/tglobal.c @@ -1332,7 +1332,7 @@ static void doInitGlobalConfig(void) { cfg.option = "httpDbNameMandatory"; cfg.ptr = &tsHttpDbNameMandatory; cfg.valType = TAOS_CFG_VTYPE_INT8; - cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG; + cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW; cfg.minValue = 0; cfg.maxValue = 1; cfg.ptrLength = 0; diff --git a/src/connector/C#/TDengineDriver.cs b/src/connector/C#/TDengineDriver.cs deleted file mode 100644 index 14fb240d0c860790b29f957774ee65016aeb5de8..0000000000000000000000000000000000000000 --- a/src/connector/C#/TDengineDriver.cs +++ /dev/null @@ -1,174 +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 . - */ - -using System; -using System.Collections.Generic; -using System.Runtime.InteropServices; - -namespace TDengineDriver -{ - public 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 - } - - public enum TDengineInitOption - { - TSDB_OPTION_LOCALE = 0, - TSDB_OPTION_CHARSET = 1, - TSDB_OPTION_TIMEZONE = 2, - TDDB_OPTION_CONFIGDIR = 3, - TDDB_OPTION_SHELL_ACTIVITY_TIMER = 4 - } - - public 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"; - } - } - } - - public 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/src/connector/C#/csharpTaos.sln b/src/connector/C#/csharpTaos.sln new file mode 100644 index 0000000000000000000000000000000000000000..b18ca230011c1314fb354feeb61166374c822d3d --- /dev/null +++ b/src/connector/C#/csharpTaos.sln @@ -0,0 +1,72 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.30114.105 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{A1FB5B66-E32F-4789-9BE9-042E5BD21087}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TDengineDriver", "src\TDengineDriver\TDengineDriver.csproj", "{5BED7402-0A65-4ED9-A491-C56BFB518045}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{CB8E6458-31E1-4351-B704-1B918E998654}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "XUnitTest", "src\test\XUnitTest\XUnitTest.csproj", "{64C0A478-2591-4459-9F8F-A70F37976A41}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Cases", "src\test\Cases\Cases.csproj", "{19A69D26-66BF-4227-97BE-9B087BC76B2F}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|Any CPU = Release|Any CPU + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {5BED7402-0A65-4ED9-A491-C56BFB518045}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {5BED7402-0A65-4ED9-A491-C56BFB518045}.Debug|Any CPU.Build.0 = Debug|Any CPU + {5BED7402-0A65-4ED9-A491-C56BFB518045}.Debug|x64.ActiveCfg = Debug|Any CPU + {5BED7402-0A65-4ED9-A491-C56BFB518045}.Debug|x64.Build.0 = Debug|Any CPU + {5BED7402-0A65-4ED9-A491-C56BFB518045}.Debug|x86.ActiveCfg = Debug|Any CPU + {5BED7402-0A65-4ED9-A491-C56BFB518045}.Debug|x86.Build.0 = Debug|Any CPU + {5BED7402-0A65-4ED9-A491-C56BFB518045}.Release|Any CPU.ActiveCfg = Release|Any CPU + {5BED7402-0A65-4ED9-A491-C56BFB518045}.Release|Any CPU.Build.0 = Release|Any CPU + {5BED7402-0A65-4ED9-A491-C56BFB518045}.Release|x64.ActiveCfg = Release|Any CPU + {5BED7402-0A65-4ED9-A491-C56BFB518045}.Release|x64.Build.0 = Release|Any CPU + {5BED7402-0A65-4ED9-A491-C56BFB518045}.Release|x86.ActiveCfg = Release|Any CPU + {5BED7402-0A65-4ED9-A491-C56BFB518045}.Release|x86.Build.0 = Release|Any CPU + {64C0A478-2591-4459-9F8F-A70F37976A41}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {64C0A478-2591-4459-9F8F-A70F37976A41}.Debug|Any CPU.Build.0 = Debug|Any CPU + {64C0A478-2591-4459-9F8F-A70F37976A41}.Debug|x64.ActiveCfg = Debug|Any CPU + {64C0A478-2591-4459-9F8F-A70F37976A41}.Debug|x64.Build.0 = Debug|Any CPU + {64C0A478-2591-4459-9F8F-A70F37976A41}.Debug|x86.ActiveCfg = Debug|Any CPU + {64C0A478-2591-4459-9F8F-A70F37976A41}.Debug|x86.Build.0 = Debug|Any CPU + {64C0A478-2591-4459-9F8F-A70F37976A41}.Release|Any CPU.ActiveCfg = Release|Any CPU + {64C0A478-2591-4459-9F8F-A70F37976A41}.Release|Any CPU.Build.0 = Release|Any CPU + {64C0A478-2591-4459-9F8F-A70F37976A41}.Release|x64.ActiveCfg = Release|Any CPU + {64C0A478-2591-4459-9F8F-A70F37976A41}.Release|x64.Build.0 = Release|Any CPU + {64C0A478-2591-4459-9F8F-A70F37976A41}.Release|x86.ActiveCfg = Release|Any CPU + {64C0A478-2591-4459-9F8F-A70F37976A41}.Release|x86.Build.0 = Release|Any CPU + {19A69D26-66BF-4227-97BE-9B087BC76B2F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {19A69D26-66BF-4227-97BE-9B087BC76B2F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {19A69D26-66BF-4227-97BE-9B087BC76B2F}.Debug|x64.ActiveCfg = Debug|Any CPU + {19A69D26-66BF-4227-97BE-9B087BC76B2F}.Debug|x64.Build.0 = Debug|Any CPU + {19A69D26-66BF-4227-97BE-9B087BC76B2F}.Debug|x86.ActiveCfg = Debug|Any CPU + {19A69D26-66BF-4227-97BE-9B087BC76B2F}.Debug|x86.Build.0 = Debug|Any CPU + {19A69D26-66BF-4227-97BE-9B087BC76B2F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {19A69D26-66BF-4227-97BE-9B087BC76B2F}.Release|Any CPU.Build.0 = Release|Any CPU + {19A69D26-66BF-4227-97BE-9B087BC76B2F}.Release|x64.ActiveCfg = Release|Any CPU + {19A69D26-66BF-4227-97BE-9B087BC76B2F}.Release|x64.Build.0 = Release|Any CPU + {19A69D26-66BF-4227-97BE-9B087BC76B2F}.Release|x86.ActiveCfg = Release|Any CPU + {19A69D26-66BF-4227-97BE-9B087BC76B2F}.Release|x86.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {5BED7402-0A65-4ED9-A491-C56BFB518045} = {A1FB5B66-E32F-4789-9BE9-042E5BD21087} + {CB8E6458-31E1-4351-B704-1B918E998654} = {A1FB5B66-E32F-4789-9BE9-042E5BD21087} + {64C0A478-2591-4459-9F8F-A70F37976A41} = {CB8E6458-31E1-4351-B704-1B918E998654} + {19A69D26-66BF-4227-97BE-9B087BC76B2F} = {CB8E6458-31E1-4351-B704-1B918E998654} + EndGlobalSection +EndGlobal diff --git a/src/connector/C#/src/TDengineDriver/TDengineDriver.cs b/src/connector/C#/src/TDengineDriver/TDengineDriver.cs new file mode 100644 index 0000000000000000000000000000000000000000..1bfb8eae0729f9d5d68734209cb4cc5ef36d8c6a --- /dev/null +++ b/src/connector/C#/src/TDengineDriver/TDengineDriver.cs @@ -0,0 +1,399 @@ +/* + * 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 +{ + public 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 + } + + public 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 TaosField + { + STRUCT_SIZE = 68, + NAME_LENGTH = 65, + TYPE_OFFSET = 65, + BYTES_OFFSET = 66, + + } + public 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"; + } + } + } + + [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] + public struct TAOS_BIND + { + // column type + public int buffer_type; + // one column value + public IntPtr buffer; + // unused + public Int32 buffer_length; + // actual value length in buffer + public IntPtr length; + // indicates the column value is null or not + public IntPtr is_null; + // unused + public int is_unsigned; + // unused + public IntPtr error; + public Int64 u; + public uint allocated; + } + + + [StructLayout(LayoutKind.Sequential)] + public struct TAOS_MULTI_BIND + { + // column type + public int buffer_type; + + // array, one or more lines column value + public IntPtr buffer; + + //length of element in TAOS_MULTI_BIND.buffer (for binary and nchar it is the longest element's length) + public ulong buffer_length; + + //array, actual data length for each value + public IntPtr length; + + //array, indicates each column value is null or not + public IntPtr is_null; + + // line number, or the values number in buffer + public int num; + } + + + public 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 * (int)TaosField.STRUCT_SIZE; + TDengineMeta meta = new TDengineMeta(); + meta.name = Marshal.PtrToStringAnsi(fieldsPtr + offset); + meta.type = Marshal.ReadByte(fieldsPtr + offset + (int)TaosField.TYPE_OFFSET); + meta.size = Marshal.ReadInt16(fieldsPtr + offset + (int)TaosField.BYTES_OFFSET); + 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 of restultset + [DllImport("taos", EntryPoint = "taos_result_precision", CallingConvention = CallingConvention.Cdecl)] + static extern public int ResultPrecision(IntPtr taos); + + + + //stmt APIs: + /// + /// init a TAOS_STMT object for later use. + /// + /// a valid taos connection + /// + /// Not NULL returned for success, NULL for failure. And it should be freed with taos_stmt_close. + /// + [DllImport("taos", EntryPoint = "taos_stmt_init", CallingConvention = CallingConvention.Cdecl)] + static extern public IntPtr StmtInit(IntPtr taos); + + /// + /// prepare a sql statement,'sql' should be a valid INSERT/SELECT statement. + /// + /// could be the value returned by 'StmtInit', that may be a valid object or NULL. + /// sql string,used to bind parameters with + /// no used + /// 0 for success, non-zero for failure. + [DllImport("taos", EntryPoint = "taos_stmt_prepare", CallingConvention = CallingConvention.Cdecl)] + static extern public int StmtPrepare(IntPtr stmt, string sql); + + /// + /// For INSERT only. Used to bind table name as a parmeter for the input stmt object. + /// + /// could be the value returned by 'StmtInit', that may be a valid object or NULL. + /// table name you want to bind + /// 0 for success, non-zero for failure. + [DllImport("taos", EntryPoint = "taos_stmt_set_tbname", CallingConvention = CallingConvention.Cdecl)] + static extern public int StmtSetTbname(IntPtr stmt, string name); + + /// + /// For INSERT only. + /// Set a table name for binding table name as parameter. Only used for binding all tables + /// in one stable, user application must call 'loadTableInfo' API to load all table + /// meta before calling this API. If the table meta is not cached locally, it will return error. + /// + /// could be the value returned by 'StmtInit', that may be a valid object or NULL. + /// table name which is belong to an stable + /// 0 for success, non-zero for failure. + [DllImport("taos", EntryPoint = "taos_stmt_set_sub_tbname", CallingConvention = CallingConvention.Cdecl)] + static extern public int StmtSetSubTbname(IntPtr stmt, string name); + + /// + /// For INSERT only. + /// set a table name for binding table name as parameter and tag values for all tag parameters. + /// + /// could be the value returned by 'StmtInit', that may be a valid object or NULL. + /// use to set table name + /// + /// is an array contains all tag values,each item in the array represents a tag column's value. + /// the item number and sequence should keep consistence with that in stable tag definition. + /// + /// 0 for success, non-zero for failure. + [DllImport("taos", EntryPoint = "taos_stmt_set_tbname_tags", CallingConvention = CallingConvention.Cdecl)] + static extern public int StmtSetTbnameTags(IntPtr stmt, string name, TAOS_BIND[] tags); + + /// + /// For both INSERT and SELECT. + /// bind a whole line data. + /// The usage of structure TAOS_BIND is the same with MYSQL_BIND in MySQL. + /// + /// could be the value returned by 'StmtInit', that may be a valid object or NULL. + /// + /// points to an array contains the whole line data. + /// the item number and sequence should keep consistence with columns in sql statement. + /// + /// 0 for success, non-zero for failure. + [DllImport("taos", EntryPoint = "taos_stmt_bind_param", CallingConvention = CallingConvention.Cdecl, SetLastError = true)] + static extern public int StmtBindParam(IntPtr stmt, TAOS_BIND[] bind); + + /// + /// bind a single column's data, INTERNAL used and for INSERT only. + /// + /// could be the value returned by 'StmtInit', that may be a valid object or NULL. + /// points to a column's data which could be the one or more lines. + /// the column's index in prepared sql statement, it starts from 0. + /// 0 for success, non-zero for failure. + [DllImport("taos", EntryPoint = "taos_stmt_bind_single_param_batch", CallingConvention = CallingConvention.Cdecl)] + static extern public int StmtBindSingleParamBatch(IntPtr stmt, ref TAOS_MULTI_BIND bind, int colIdx); + + /// + /// for INSERT only + /// bind one or multiple lines data. The parameter 'bind' + /// + /// could be the value returned by 'StmtInit', that may be a valid object or NULL. + /// + /// points to an array contains one or more lines data.Each item in array represents a column's value(s), + /// the item number and sequence should keep consistence with columns in sql statement. + /// + /// 0 for success, non-zero for failure. + [DllImport("taos", EntryPoint = "taos_stmt_bind_param_batch", CallingConvention = CallingConvention.Cdecl)] + static extern public int StmtBindParamBatch(IntPtr stmt, [In, Out] TAOS_MULTI_BIND[] bind); + + /// + /// For INSERT only. + /// add all current bound parameters to batch process. Must be called after each call to + /// StmtBindParam/StmtBindSingleParamBatch, or all columns binds for one or more lines + /// with StmtBindSingleParamBatch. User application can call any bind parameter + /// API again to bind more data lines after calling to this API. + /// + /// could be the value returned by 'StmtInit', that may be a valid object or NULL. + /// 0 for success, non-zero for failure. + [DllImport("taos", EntryPoint = "taos_stmt_add_batch", CallingConvention = CallingConvention.Cdecl)] + static extern public int StmtAddBatch(IntPtr stmt); + + /// + /// actually execute the INSERT/SELECT sql statement. + /// User application can continue to bind new data after calling to this API. + /// + /// could be the value returned by 'StmtInit', that may be a valid object or NULL. + /// + [DllImport("taos", EntryPoint = "taos_stmt_execute", CallingConvention = CallingConvention.Cdecl)] + static extern public int StmtExecute(IntPtr stmt); + + /// + /// For SELECT only,getting the query result. User application should free it with API 'FreeResult' at the end. + /// + /// could be the value returned by 'StmtInit', that may be a valid object or NULL. + /// Not NULL for success, NULL for failure. + [DllImport("taos", EntryPoint = "taos_stmt_use_result", CallingConvention = CallingConvention.Cdecl)] + static extern public IntPtr StmtUseResult(IntPtr stmt); + + /// + /// close STMT object and free resources. + /// + /// could be the value returned by 'StmtInit', that may be a valid object or NULL. + /// 0 for success, non-zero for failure. + [DllImport("taos", EntryPoint = "taos_stmt_close", CallingConvention = CallingConvention.Cdecl)] + static extern public int StmtClose(IntPtr stmt); + + [DllImport("taos", EntryPoint = "taos_load_table_info", CallingConvention = CallingConvention.Cdecl)] + /// + /// user application must call this API to load all tables meta, + /// + /// taos connection + /// tablelist + /// + static extern private int LoadTableInfoDll(IntPtr taos, string tableList); + + /// + /// user application call this API to load all tables meta,this method call the native + /// method LoadTableInfoDll. + /// this method must be called before StmtSetSubTbname(IntPtr stmt, string name); + /// + /// taos connection + /// tables need to load meta info are form in an array + /// + static public int LoadTableInfo(IntPtr taos, string[] tableList) + { + string listStr = string.Join(",", tableList); + return LoadTableInfoDll(taos, listStr); + } + + /// + /// get detail error message when got failure for any stmt API call. If not failure, the result + /// returned in this API is unknown. + /// + /// could be the value returned by 'StmtInit', that may be a valid object or NULL. + /// piont the error message + [DllImport("taos", EntryPoint = "taos_stmt_errstr", CallingConvention = CallingConvention.Cdecl)] + static extern private IntPtr StmtErrPtr(IntPtr stmt); + + /// + /// get detail error message when got failure for any stmt API call. If not failure, the result + /// returned in this API is unknown. + /// + /// could be the value returned by 'StmtInit', that may be a valid object or NULL. + /// error string + static public string StmtErrorStr(IntPtr stmt) + { + IntPtr stmtErrPrt = StmtErrPtr(stmt); + return Marshal.PtrToStringAnsi(stmtErrPrt); + } + } +} diff --git a/src/connector/C#/src/TDengineDriver/TDengineDriver.csproj b/src/connector/C#/src/TDengineDriver/TDengineDriver.csproj new file mode 100644 index 0000000000000000000000000000000000000000..f208d303c9811fa05807ef8f72685b8ebb536a37 --- /dev/null +++ b/src/connector/C#/src/TDengineDriver/TDengineDriver.csproj @@ -0,0 +1,7 @@ + + + + net5.0 + + + diff --git a/src/connector/C#/src/TDengineDriver/TaosBind.cs b/src/connector/C#/src/TDengineDriver/TaosBind.cs new file mode 100644 index 0000000000000000000000000000000000000000..694dcd900bccedc913ce9d1956650f97957965da --- /dev/null +++ b/src/connector/C#/src/TDengineDriver/TaosBind.cs @@ -0,0 +1,332 @@ +using System; +using System.Runtime.InteropServices; + + +namespace TDengineDriver +{ + /// + /// this class used to get an instance of struct of TAO_BIND or TAOS_MULTI_BIND + /// And the instance is corresponding with TDengine data type. For example, calling + /// "bindBinary" will return a TAOS_BIND object that is corresponding with TDengine's + /// binary type. + /// + public class TaosBind + { + public static TAOS_BIND BindBool(bool val) + { + TAOS_BIND bind = new TAOS_BIND(); + byte[] boolByteArr = BitConverter.GetBytes(val); + int boolByteArrSize = Marshal.SizeOf(boolByteArr[0]) * boolByteArr.Length; + IntPtr bo = Marshal.AllocHGlobal(1); + Marshal.Copy(boolByteArr, 0, bo, boolByteArr.Length); + + int length = sizeof(Boolean); + IntPtr lengPtr = Marshal.AllocHGlobal(sizeof(int)); + Marshal.WriteInt32(lengPtr, length); + + bind.buffer_type = (int)TDengineDataType.TSDB_DATA_TYPE_BOOL; + bind.buffer = bo; + bind.buffer_length = length; + bind.length = lengPtr; + bind.is_null = IntPtr.Zero; + + return bind; + } + public static TAOS_BIND BindTinyInt(sbyte val) + { + TAOS_BIND bind = new TAOS_BIND(); + + byte[] tinyIntByteArr = BitConverter.GetBytes(val); + int tinyIntByteArrSize = Marshal.SizeOf(tinyIntByteArr[0]) * tinyIntByteArr.Length; + IntPtr uManageTinyInt = Marshal.AllocHGlobal(tinyIntByteArrSize); + Marshal.Copy(tinyIntByteArr, 0, uManageTinyInt, tinyIntByteArr.Length); + + int length = sizeof(sbyte); + IntPtr lengPtr = Marshal.AllocHGlobal(sizeof(int)); + Marshal.WriteInt32(lengPtr, length); + + bind.buffer_type = (int)TDengineDataType.TSDB_DATA_TYPE_TINYINT; + bind.buffer = uManageTinyInt; + bind.buffer_length = length; + bind.length = lengPtr; + bind.is_null = IntPtr.Zero; + return bind; + + } + + public static TAOS_BIND BindSmallInt(short val) + { + + TAOS_BIND bind = new TAOS_BIND(); + IntPtr uManageSmallInt = Marshal.AllocHGlobal(sizeof(short)); + Marshal.WriteInt16(uManageSmallInt, val); + + int length = sizeof(short); + IntPtr lengPtr = Marshal.AllocHGlobal(sizeof(int)); + Marshal.WriteInt32(lengPtr, length); + + bind.buffer_type = (int)TDengineDataType.TSDB_DATA_TYPE_SMALLINT; + bind.buffer = uManageSmallInt; + bind.buffer_length = length; + bind.length = lengPtr; + bind.is_null = IntPtr.Zero; + + return bind; + } + + public static TAOS_BIND BindInt(int val) + { + TAOS_BIND bind = new TAOS_BIND(); + IntPtr uManageInt = Marshal.AllocHGlobal(sizeof(int)); + Marshal.WriteInt32(uManageInt, val); + + int length = sizeof(int); + IntPtr lengPtr = Marshal.AllocHGlobal(sizeof(int)); + Marshal.WriteInt32(lengPtr, length); + + bind.buffer_type = (int)TDengineDataType.TSDB_DATA_TYPE_INT; + bind.buffer = uManageInt; + bind.buffer_length = length; + bind.length = lengPtr; + bind.is_null = IntPtr.Zero; + + return bind; + } + + public static TAOS_BIND BindBigInt(long val) + { + + TAOS_BIND bind = new TAOS_BIND(); + IntPtr uManageBigInt = Marshal.AllocHGlobal(sizeof(long)); + Marshal.WriteInt64(uManageBigInt, val); + + int length = sizeof(long); + IntPtr lengPtr = Marshal.AllocHGlobal(sizeof(int)); + Marshal.WriteInt32(lengPtr, length); + + bind.buffer_type = (int)TDengineDataType.TSDB_DATA_TYPE_BIGINT; + bind.buffer = uManageBigInt; + bind.buffer_length = length; + bind.length = lengPtr; + bind.is_null = IntPtr.Zero; + + return bind; + } + + public static TAOS_BIND BindUTinyInt(byte val) + { + TAOS_BIND bind = new TAOS_BIND(); + + IntPtr uManageTinyInt = Marshal.AllocHGlobal(sizeof(byte)); + Marshal.WriteByte(uManageTinyInt, val); + + int length = sizeof(byte); + IntPtr lengPtr = Marshal.AllocHGlobal(sizeof(int)); + Marshal.WriteInt32(lengPtr, length); + + bind.buffer_type = (int)TDengineDataType.TSDB_DATA_TYPE_UTINYINT; + bind.buffer = uManageTinyInt; + bind.buffer_length = length; + bind.length = lengPtr; + bind.is_null = IntPtr.Zero; + + return bind; + } + + public static TAOS_BIND BindUSmallInt(UInt16 val) + { + TAOS_BIND bind = new TAOS_BIND(); + + byte[] uSmallIntByteArr = BitConverter.GetBytes(val); + int usmallSize = Marshal.SizeOf(uSmallIntByteArr[0]) * uSmallIntByteArr.Length; + IntPtr uManageUnsignSmallInt = Marshal.AllocHGlobal(usmallSize); + Marshal.Copy(uSmallIntByteArr, 0, uManageUnsignSmallInt, uSmallIntByteArr.Length); + + int length = sizeof(UInt16); + IntPtr lengPtr = Marshal.AllocHGlobal(sizeof(int)); + Marshal.WriteInt32(lengPtr, length); + + bind.buffer_type = (int)TDengineDataType.TSDB_DATA_TYPE_USMALLINT; + bind.buffer = uManageUnsignSmallInt; + bind.buffer_length = length; + bind.length = lengPtr; + bind.is_null = IntPtr.Zero; + + return bind; + } + + public static TAOS_BIND BindUInt(uint val) + { + TAOS_BIND bind = new TAOS_BIND(); + + byte[] uManageIntByteArr = BitConverter.GetBytes(val); + int usmallSize = Marshal.SizeOf(uManageIntByteArr[0]) * uManageIntByteArr.Length; + IntPtr uManageInt = Marshal.AllocHGlobal(usmallSize); + Marshal.Copy(uManageIntByteArr, 0, uManageInt, uManageIntByteArr.Length); + + int length = sizeof(uint); + IntPtr lengPtr = Marshal.AllocHGlobal(sizeof(int)); + Marshal.WriteInt32(lengPtr, length); + + bind.buffer_type = (int)TDengineDataType.TSDB_DATA_TYPE_UINT; + bind.buffer = uManageInt; + bind.buffer_length = length; + bind.length = lengPtr; + bind.is_null = IntPtr.Zero; + + return bind; + } + + public static TAOS_BIND BindUBigInt(ulong val) + { + TAOS_BIND bind = new TAOS_BIND(); + + byte[] uManageBigIntByteArr = BitConverter.GetBytes(val); + int usmallSize = Marshal.SizeOf(uManageBigIntByteArr[0]) * uManageBigIntByteArr.Length; + IntPtr uManageBigInt = Marshal.AllocHGlobal(usmallSize); + Marshal.Copy(uManageBigIntByteArr, 0, uManageBigInt, uManageBigIntByteArr.Length); + + int length = sizeof(ulong); + IntPtr lengPtr = Marshal.AllocHGlobal(sizeof(int)); + Marshal.WriteInt32(lengPtr, length); + + bind.buffer_type = (int)TDengineDataType.TSDB_DATA_TYPE_UBIGINT; + bind.buffer = uManageBigInt; + bind.buffer_length = length; + bind.length = lengPtr; + bind.is_null = IntPtr.Zero; + + return bind; + } + + public static TAOS_BIND BindFloat(float val) + { + TAOS_BIND bind = new TAOS_BIND(); + + byte[] floatByteArr = BitConverter.GetBytes(val); + int floatByteArrSize = Marshal.SizeOf(floatByteArr[0]) * floatByteArr.Length; + IntPtr uManageFloat = Marshal.AllocHGlobal(floatByteArrSize); + Marshal.Copy(floatByteArr, 0, uManageFloat, floatByteArr.Length); + + int length = sizeof(float); + IntPtr lengPtr = Marshal.AllocHGlobal(sizeof(int)); + Marshal.WriteInt32(lengPtr, length); + + bind.buffer_type = (int)TDengineDataType.TSDB_DATA_TYPE_FLOAT; + bind.buffer = uManageFloat; + bind.buffer_length = length; + bind.length = lengPtr; + bind.is_null = IntPtr.Zero; + + return bind; + } + + public static TAOS_BIND BindDouble(Double val) + { + TAOS_BIND bind = new TAOS_BIND(); + + byte[] doubleByteArr = BitConverter.GetBytes(val); + int doubleByteArrSize = Marshal.SizeOf(doubleByteArr[0]) * doubleByteArr.Length; + IntPtr uManageDouble = Marshal.AllocHGlobal(doubleByteArrSize); + Marshal.Copy(doubleByteArr, 0, uManageDouble, doubleByteArr.Length); + + int length = sizeof(Double); + IntPtr lengPtr = Marshal.AllocHGlobal(sizeof(int)); + Marshal.WriteInt32(lengPtr, length); + + bind.buffer_type = (int)TDengineDataType.TSDB_DATA_TYPE_DOUBLE; + bind.buffer = uManageDouble; + bind.buffer_length = length; + bind.length = lengPtr; + bind.is_null = IntPtr.Zero; + + return bind; + } + + public static TAOS_BIND BindBinary(String val) + { + + TAOS_BIND bind = new TAOS_BIND(); + IntPtr umanageBinary = Marshal.StringToHGlobalAnsi(val); + + int leng = val.Length; + IntPtr lenPtr = Marshal.AllocHGlobal(sizeof(ulong)); + Marshal.WriteInt64(lenPtr, leng); + + bind.buffer_type = (int)TDengineDataType.TSDB_DATA_TYPE_BINARY; + bind.buffer = umanageBinary; + bind.buffer_length = leng; + bind.length = lenPtr; + bind.is_null = IntPtr.Zero; + + return bind; + } + public static TAOS_BIND BindNchar(String val) + { + TAOS_BIND bind = new TAOS_BIND(); + IntPtr umanageNchar = (IntPtr)Marshal.StringToHGlobalAnsi(val); + + int leng = val.Length; + IntPtr lenPtr = Marshal.AllocHGlobal(sizeof(ulong)); + Marshal.WriteInt64(lenPtr, leng); + + bind.buffer_type = (int)TDengineDataType.TSDB_DATA_TYPE_NCHAR; + bind.buffer = umanageNchar; + bind.buffer_length = leng; + bind.length = lenPtr; + bind.is_null = IntPtr.Zero; + + return bind; + } + + public static TAOS_BIND BindNil() + { + TAOS_BIND bind = new TAOS_BIND(); + + int isNull = 1;//IntPtr.Size; + IntPtr lenPtr = Marshal.AllocHGlobal(sizeof(int)); + Marshal.WriteInt32(lenPtr, isNull); + + bind.buffer_type = (int)TDengineDataType.TSDB_DATA_TYPE_NULL; + bind.is_null = lenPtr; + return bind; + } + + public static TAOS_BIND BindTimestamp(long ts) + { + + TAOS_BIND bind = new TAOS_BIND(); + IntPtr uManageTs = Marshal.AllocHGlobal(sizeof(long)); + Marshal.WriteInt64(uManageTs, ts); + + int length = sizeof(long); + IntPtr lengPtr = Marshal.AllocHGlobal(4); + Marshal.WriteInt32(lengPtr, length); + + bind.buffer_type = (int)TDengineDataType.TSDB_DATA_TYPE_TIMESTAMP; + bind.buffer = uManageTs; + bind.buffer_length = length; + bind.length = lengPtr; + bind.is_null = IntPtr.Zero; + + return bind; + + } + + public static void FreeTaosBind(TAOS_BIND[] binds) + { + foreach (TAOS_BIND bind in binds) + { + Marshal.FreeHGlobal(bind.buffer); + Marshal.FreeHGlobal(bind.length); + if (bind.is_null != IntPtr.Zero) + { + // Console.WriteLine(bind.is_null); + Marshal.FreeHGlobal(bind.is_null); + } + + } + } + } + +} \ No newline at end of file diff --git a/src/connector/C#/src/TDengineDriver/TaosMultiBind.cs b/src/connector/C#/src/TDengineDriver/TaosMultiBind.cs new file mode 100644 index 0000000000000000000000000000000000000000..e01558caeb0905826c77fe97ee6d7147ff8b923e --- /dev/null +++ b/src/connector/C#/src/TDengineDriver/TaosMultiBind.cs @@ -0,0 +1,616 @@ +using System; +using System.Text; +using System.Runtime.InteropServices; + + +namespace TDengineDriver +{ + public class TaosMultiBind + { + public static TAOS_MULTI_BIND MultiBindBool(bool?[] arr) + { + TAOS_MULTI_BIND multiBind = new TAOS_MULTI_BIND(); + int elementCount = arr.Length; + //the size of buffer array element + int typeSize = sizeof(bool); + //size of int + int intSize = sizeof(int); + int byteSize = sizeof(byte); + + //TAOS_MULTI_BIND.buffer + IntPtr unmanagedBoolArr = Marshal.AllocHGlobal(elementCount * typeSize); + //TAOS_MULTI_BIND.length + IntPtr lengthArr = Marshal.AllocHGlobal(intSize * elementCount); + //TAOS_MULTI_BIND.is_null + IntPtr nullArr = Marshal.AllocHGlobal(byteSize * elementCount); + + for (int i = 0; i < elementCount; i++) + { + //set TAOS_MULTI_BIND.buffer + Marshal.WriteByte(unmanagedBoolArr, typeSize * i, Convert.ToByte(arr[i] ?? false)); + //set TAOS_MULTI_BIND.length + Marshal.WriteInt32(lengthArr, intSize * i, typeSize); + //set TAOS_MULTI_BIND.is_null + Marshal.WriteByte(nullArr, byteSize * i, Convert.ToByte(arr[i].Equals(null) ? 1 : 0)); + } + //config TAOS_MULTI_BIND + multiBind.buffer_type = (int)TDengineDataType.TSDB_DATA_TYPE_BOOL; + multiBind.buffer = unmanagedBoolArr; + multiBind.buffer_length = (ulong)typeSize; + multiBind.length = lengthArr; + multiBind.is_null = nullArr; + multiBind.num = elementCount; + + return multiBind; + } + public static TAOS_MULTI_BIND MultiBindTinyInt(sbyte?[] arr) + { + TAOS_MULTI_BIND multiBind = new TAOS_MULTI_BIND(); + int elementCount = arr.Length; + //the size of buffer array element + int typeSize = sizeof(byte); + int byteSize = sizeof(byte); + //size of int + int intSize = sizeof(int); + + //TAOS_MULTI_BIND.buffer + IntPtr unmanagedTintIntArr = Marshal.AllocHGlobal(elementCount); + //TAOS_MULTI_BIND.length + IntPtr lengthArr = Marshal.AllocHGlobal(intSize * elementCount); + //TAOS_MULTI_BIND.is_null + IntPtr nullArr = Marshal.AllocHGlobal(intSize * elementCount); + + for (int i = 0; i < elementCount; i++) + { + Byte[] toByteArr = BitConverter.GetBytes(arr[i] ?? sbyte.MinValue); + + //set TAOS_MULTI_BIND.buffer + Marshal.WriteByte(unmanagedTintIntArr, typeSize * i, toByteArr[0]); + //set TAOS_MULTI_BIND.length + Marshal.WriteInt32(lengthArr, intSize * i, typeSize); + //set TAOS_MULTI_BIND.is_null + Marshal.WriteByte(nullArr, byteSize * i, Convert.ToByte(arr[i].Equals(null) ? 1 : 0)); + } + + //config TAOS_MULTI_BIND + multiBind.buffer_type = (int)TDengineDataType.TSDB_DATA_TYPE_TINYINT; + multiBind.buffer = unmanagedTintIntArr; + multiBind.buffer_length = (ulong)typeSize; + multiBind.length = lengthArr; + multiBind.is_null = nullArr; + multiBind.num = elementCount; + + return multiBind; + } + public static TAOS_MULTI_BIND MultiBindSmallInt(short?[] arr) + { + TAOS_MULTI_BIND multiBind = new TAOS_MULTI_BIND(); + int elementCount = arr.Length; + //the size of buffer array element + int typeSize = sizeof(short); + //size of int + int intSize = sizeof(int); + int byteSize = sizeof(byte); + + //TAOS_MULTI_BIND.buffer + IntPtr unmanagedSmallIntArr = Marshal.AllocHGlobal(elementCount * typeSize); + //TAOS_MULTI_BIND.length + IntPtr lengthArr = Marshal.AllocHGlobal(intSize * elementCount); + //TAOS_MULTI_BIND.is_null + IntPtr nullArr = Marshal.AllocHGlobal(byteSize * elementCount); + + for (int i = 0; i < elementCount; i++) + { + //set TAOS_MULTI_BIND.buffer + Marshal.WriteInt16(unmanagedSmallIntArr, typeSize * i, arr[i] ?? short.MinValue); + //set TAOS_MULTI_BIND.length + Marshal.WriteInt32(lengthArr, intSize * i, typeSize); + //set TAOS_MULTI_BIND.is_null + Marshal.WriteByte(nullArr, byteSize * i, Convert.ToByte(arr[i].Equals(null) ? 1 : 0)); + + } + //config TAOS_MULTI_BIND + multiBind.buffer_type = (int)TDengineDataType.TSDB_DATA_TYPE_SMALLINT; + multiBind.buffer = unmanagedSmallIntArr; + multiBind.buffer_length = (ulong)typeSize; + multiBind.length = lengthArr; + multiBind.is_null = nullArr; + multiBind.num = elementCount; + + return multiBind; + } + public static TAOS_MULTI_BIND MultiBindInt(int?[] arr) + { + TAOS_MULTI_BIND multiBind = new TAOS_MULTI_BIND(); + int elementCount = arr.Length; + int typeSize = sizeof(int); + int intSize = sizeof(int); + int byteSize = sizeof(byte); + + //TAOS_MULTI_BIND.buffer + IntPtr intBuff = Marshal.AllocHGlobal(typeSize * elementCount); + //TAOS_MULTI_BIND.length + IntPtr lengthArr = Marshal.AllocHGlobal(intSize * elementCount); + //TAOS_MULTI_BIND.is_null + IntPtr nullArr = Marshal.AllocHGlobal(byteSize * elementCount); + + for (int i = 0; i < elementCount; i++) + { + //set TAOS_MULTI_BIND.buffer + Marshal.WriteInt32(intBuff, typeSize * i, arr[i] ?? int.MinValue); + //set TAOS_MULTI_BIND.length + Marshal.WriteInt32(lengthArr, intSize * i, typeSize); + //set TAOS_MULTI_BIND.is_null + Marshal.WriteByte(nullArr, byteSize * i, Convert.ToByte(arr[i].Equals(null) ? 1 : 0)); + + } + //config TAOS_MULTI_BIND + multiBind.buffer_type = (int)TDengineDataType.TSDB_DATA_TYPE_INT; + multiBind.buffer = intBuff; + multiBind.buffer_length = (ulong)typeSize; + multiBind.length = lengthArr; + multiBind.is_null = nullArr; + multiBind.num = elementCount; + + return multiBind; + } + public static TAOS_MULTI_BIND MultiBindBigint(long?[] arr) + { + TAOS_MULTI_BIND multiBind = new TAOS_MULTI_BIND(); + int elementCount = arr.Length; + int typeSize = sizeof(long); + int intSize = sizeof(int); + int byteSize = sizeof(byte); + + //TAOS_MULTI_BIND.buffer + IntPtr intBuff = Marshal.AllocHGlobal(typeSize * elementCount); + //TAOS_MULTI_BIND.length + IntPtr lengthArr = Marshal.AllocHGlobal(intSize * elementCount); + //TAOS_MULTI_BIND.is_null + IntPtr nullArr = Marshal.AllocHGlobal(byteSize * elementCount); + + for (int i = 0; i < elementCount; i++) + { + //set TAOS_MULTI_BIND.buffer + Marshal.WriteInt64(intBuff, typeSize * i, arr[i] ?? long.MinValue); + //set TAOS_MULTI_BIND.length + Marshal.WriteInt32(lengthArr, intSize * i, typeSize); + //set TAOS_MULTI_BIND.is_null + Marshal.WriteByte(nullArr, byteSize * i, Convert.ToByte(arr[i].Equals(null) ? 1 : 0)); + + + } + //config TAOS_MULTI_BIND + multiBind.buffer_type = (int)TDengineDataType.TSDB_DATA_TYPE_BIGINT; + multiBind.buffer = intBuff; + multiBind.buffer_length = (ulong)typeSize; + multiBind.length = lengthArr; + multiBind.is_null = nullArr; + multiBind.num = elementCount; + + return multiBind; + } + public static TAOS_MULTI_BIND MultiBindFloat(float?[] arr) + { + TAOS_MULTI_BIND multiBind = new TAOS_MULTI_BIND(); + int elementCount = arr.Length; + int typeSize = sizeof(float); + int intSize = sizeof(int); + int byteSize = sizeof(byte); + //used to replace null + float[] arrTmp = new float[elementCount]; + + //TAOS_MULTI_BIND.buffer + IntPtr floatBuff = Marshal.AllocHGlobal(typeSize * elementCount); + //TAOS_MULTI_BIND.length + IntPtr lengthArr = Marshal.AllocHGlobal(intSize * elementCount); + //TAOS_MULTI_BIND.is_null + IntPtr nullArr = Marshal.AllocHGlobal(byteSize * elementCount); + + + for (int i = 0; i < elementCount; i++) + { + arrTmp[i] = arr[i] ?? float.MinValue; + //set TAOS_MULTI_BIND.length + Marshal.WriteInt32(lengthArr, intSize * i, typeSize); + //set TAOS_MULTI_BIND.is_null + Marshal.WriteByte(nullArr, byteSize * i, Convert.ToByte(arr[i].Equals(null) ? 1 : 0)); + } + //set TAOS_MULTI_BIND.buffer + Marshal.Copy(arrTmp, 0, floatBuff, elementCount); + + //config TAOS_MULTI_BIND + multiBind.buffer_type = (int)TDengineDataType.TSDB_DATA_TYPE_FLOAT; + multiBind.buffer = floatBuff; + multiBind.buffer_length = (ulong)typeSize; + multiBind.length = lengthArr; + multiBind.is_null = nullArr; + multiBind.num = elementCount; + + return multiBind; + } + public static TAOS_MULTI_BIND MultiBindDouble(double?[] arr) + { + TAOS_MULTI_BIND multiBind = new TAOS_MULTI_BIND(); + int elementCount = arr.Length; + int typeSize = sizeof(double); + int intSize = sizeof(int); + int byteSize = sizeof(byte); + //used to replace null + double[] arrTmp = new double[elementCount]; + + //TAOS_MULTI_BIND.buffer + IntPtr doubleBuff = Marshal.AllocHGlobal(typeSize * elementCount); + //TAOS_MULTI_BIND.length + IntPtr lengthArr = Marshal.AllocHGlobal(intSize * elementCount); + //TAOS_MULTI_BIND.is_null + IntPtr nullArr = Marshal.AllocHGlobal(byteSize * elementCount); + + + for (int i = 0; i < elementCount; i++) + { + arrTmp[i] = arr[i] ?? double.MinValue; + //set TAOS_MULTI_BIND.length + Marshal.WriteInt32(lengthArr, intSize * i, typeSize); + //set TAOS_MULTI_BIND.is_null + Marshal.WriteByte(nullArr, byteSize * i, Convert.ToByte(arr[i].Equals(null) ? 1 : 0)); + } + //set TAOS_MULTI_BIND.buffer + Marshal.Copy(arrTmp, 0, doubleBuff, elementCount); + + //config TAOS_MULTI_BIND + multiBind.buffer_type = (int)TDengineDataType.TSDB_DATA_TYPE_DOUBLE; + multiBind.buffer = doubleBuff; + multiBind.buffer_length = (ulong)typeSize; + multiBind.length = lengthArr; + multiBind.is_null = nullArr; + multiBind.num = elementCount; + + return multiBind; + } + public static TAOS_MULTI_BIND MultiBindUTinyInt(byte?[] arr) + { + TAOS_MULTI_BIND multiBind = new TAOS_MULTI_BIND(); + int elementCount = arr.Length; + int typeSize = sizeof(byte); + int intSize = sizeof(int); + int byteSize = sizeof(byte); + //used to replace null + + //TAOS_MULTI_BIND.buffer + IntPtr uTinyIntBuff = Marshal.AllocHGlobal(typeSize * elementCount); + //TAOS_MULTI_BIND.length + IntPtr lengthArr = Marshal.AllocHGlobal(intSize * elementCount); + //TAOS_MULTI_BIND.is_null + IntPtr nullArr = Marshal.AllocHGlobal(byteSize * elementCount); + + + for (int i = 0; i < elementCount; i++) + { + //set TAOS_MULTI_BIND.buffer + Marshal.WriteByte(uTinyIntBuff, typeSize * i, arr[i] ?? byte.MaxValue); + //set TAOS_MULTI_BIND.length + Marshal.WriteInt32(lengthArr, intSize * i, typeSize); + //set TAOS_MULTI_BIND.is_null + Marshal.WriteByte(nullArr, byteSize * i, Convert.ToByte(arr[i].Equals(null) ? 1 : 0)); + } + + + //config TAOS_MULTI_BIND + multiBind.buffer_type = (int)TDengineDataType.TSDB_DATA_TYPE_UTINYINT; + multiBind.buffer = uTinyIntBuff; + multiBind.buffer_length = (ulong)typeSize; + multiBind.length = lengthArr; + multiBind.is_null = nullArr; + multiBind.num = elementCount; + + return multiBind; + } + public static TAOS_MULTI_BIND MultiBindUSmallInt(ushort?[] arr) + { + TAOS_MULTI_BIND multiBind = new TAOS_MULTI_BIND(); + int elementCount = arr.Length; + int typeSize = sizeof(ushort); + int intSize = sizeof(int); + int byteSize = sizeof(byte); + //used to replace null + + //TAOS_MULTI_BIND.buffer + IntPtr uSmallIntBuff = Marshal.AllocHGlobal(typeSize * elementCount); + //TAOS_MULTI_BIND.length + IntPtr lengthArr = Marshal.AllocHGlobal(intSize * elementCount); + //TAOS_MULTI_BIND.is_null + IntPtr nullArr = Marshal.AllocHGlobal(byteSize * elementCount); + + + for (int i = 0; i < elementCount; i++) + { + byte[] byteArr = BitConverter.GetBytes(arr[i] ?? ushort.MaxValue); + for (int j = 0; j < byteArr.Length; j++) + { + //set TAOS_MULTI_BIND.buffer + Marshal.WriteByte(uSmallIntBuff, typeSize * i + j * byteSize, byteArr[j]); + } + //set TAOS_MULTI_BIND.length + Marshal.WriteInt32(lengthArr, intSize * i, typeSize); + //set TAOS_MULTI_BIND.is_null + Marshal.WriteByte(nullArr, byteSize * i, Convert.ToByte(arr[i].Equals(null) ? 1 : 0)); + } + + + //config TAOS_MULTI_BIND + multiBind.buffer_type = (int)TDengineDataType.TSDB_DATA_TYPE_USMALLINT; + multiBind.buffer = uSmallIntBuff; + multiBind.buffer_length = (ulong)typeSize; + multiBind.length = lengthArr; + multiBind.is_null = nullArr; + multiBind.num = elementCount; + + return multiBind; + } + public static TAOS_MULTI_BIND MultiBindUInt(uint?[] arr) + { + TAOS_MULTI_BIND multiBind = new TAOS_MULTI_BIND(); + int elementCount = arr.Length; + int typeSize = sizeof(uint); + int intSize = sizeof(int); + int byteSize = sizeof(byte); + //used to replace null + + //TAOS_MULTI_BIND.buffer + IntPtr uIntBuff = Marshal.AllocHGlobal(typeSize * elementCount); + //TAOS_MULTI_BIND.length + IntPtr lengthArr = Marshal.AllocHGlobal(intSize * elementCount); + //TAOS_MULTI_BIND.is_null + IntPtr nullArr = Marshal.AllocHGlobal(byteSize * elementCount); + + + for (int i = 0; i < elementCount; i++) + { + byte[] byteArr = BitConverter.GetBytes(arr[i] ?? uint.MaxValue); + for (int j = 0; j < byteArr.Length; j++) + { + //set TAOS_MULTI_BIND.buffer + Marshal.WriteByte(uIntBuff, typeSize * i + j * byteSize, byteArr[j]); + } + //set TAOS_MULTI_BIND.length + Marshal.WriteInt32(lengthArr, intSize * i, typeSize); + //set TAOS_MULTI_BIND.is_null + Marshal.WriteByte(nullArr, byteSize * i, Convert.ToByte(arr[i].Equals(null) ? 1 : 0)); + } + + + //config TAOS_MULTI_BIND + multiBind.buffer_type = (int)TDengineDataType.TSDB_DATA_TYPE_UINT; + multiBind.buffer = uIntBuff; + multiBind.buffer_length = (ulong)typeSize; + multiBind.length = lengthArr; + multiBind.is_null = nullArr; + multiBind.num = elementCount; + + return multiBind; + } + public static TAOS_MULTI_BIND MultiBindUBigInt(ulong?[] arr) + { + TAOS_MULTI_BIND multiBind = new TAOS_MULTI_BIND(); + int elementCount = arr.Length; + int typeSize = sizeof(ulong); + int intSize = sizeof(int); + int byteSize = sizeof(byte); + //used to replace null + + //TAOS_MULTI_BIND.buffer + IntPtr uBigIntBuff = Marshal.AllocHGlobal(typeSize * elementCount); + //TAOS_MULTI_BIND.length + IntPtr lengthArr = Marshal.AllocHGlobal(intSize * elementCount); + //TAOS_MULTI_BIND.is_null + IntPtr nullArr = Marshal.AllocHGlobal(byteSize * elementCount); + + + for (int i = 0; i < elementCount; i++) + { + byte[] byteArr = BitConverter.GetBytes(arr[i] ?? ulong.MaxValue); + for (int j = 0; j < byteArr.Length; j++) + { + //set TAOS_MULTI_BIND.buffer + Marshal.WriteByte(uBigIntBuff, typeSize * i + j * byteSize, byteArr[j]); + } + //set TAOS_MULTI_BIND.length + Marshal.WriteInt32(lengthArr, intSize * i, typeSize); + //set TAOS_MULTI_BIND.is_null + Marshal.WriteByte(nullArr, byteSize * i, Convert.ToByte(arr[i].Equals(null) ? 1 : 0)); + } + + + //config TAOS_MULTI_BIND + multiBind.buffer_type = (int)TDengineDataType.TSDB_DATA_TYPE_UBIGINT; + multiBind.buffer = uBigIntBuff; + multiBind.buffer_length = (ulong)typeSize; + multiBind.length = lengthArr; + multiBind.is_null = nullArr; + multiBind.num = elementCount; + + return multiBind; + } + public static TAOS_MULTI_BIND MultiBindBinary(string[] arr) + { + TAOS_MULTI_BIND multiBind = new TAOS_MULTI_BIND(); + int elementCount = arr.Length; + int typeSize = MaxElementLength(arr); + int intSize = sizeof(int); + int byteSize = sizeof(byte); + StringBuilder arrStrBuilder = new StringBuilder(); ; + + //TAOS_MULTI_BIND.length + IntPtr lengthArr = Marshal.AllocHGlobal(intSize * elementCount); + //TAOS_MULTI_BIND.is_null + IntPtr nullArr = Marshal.AllocHGlobal(byteSize * elementCount); + + for (int i = 0; i < elementCount; i++) + { + int itemLength = 0; + // if element if not null and element length is less then typeSize + // fill the memory with default char.Since arr element memory need align. + if (!String.IsNullOrEmpty(arr[i]) && typeSize <= arr[i].Length) + { + itemLength = arr[i].Length; + arrStrBuilder.Append(arr[i]); + } + else if (!String.IsNullOrEmpty(arr[i]) && typeSize > arr[i].Length) + { + itemLength = arr[i].Length; + arrStrBuilder.Append(arr[i]); + arrStrBuilder.Append(AlignCharArr(typeSize - arr[i].Length)); + } + else + { + // if is null value,fill the memory with default values. + itemLength = 0; + arrStrBuilder.Append(AlignCharArr(typeSize)); + } + + //set TAOS_MULTI_BIND.length + Marshal.WriteInt32(lengthArr, intSize * i, itemLength); + //set TAOS_MULTI_BIND.is_null + Marshal.WriteByte(nullArr, byteSize * i, Convert.ToByte(String.IsNullOrEmpty(arr[i]) ? 1 : 0)); + } + //set TAOS_MULTI_BIND.buffer + IntPtr uBinaryBuff = (IntPtr)Marshal.StringToHGlobalAnsi(arrStrBuilder.ToString()); + + //config TAOS_MULTI_BIND + multiBind.buffer_type = (int)TDengineDataType.TSDB_DATA_TYPE_BINARY; + multiBind.buffer = uBinaryBuff; + multiBind.buffer_length = (ulong)typeSize; + multiBind.length = lengthArr; + multiBind.is_null = nullArr; + multiBind.num = elementCount; + + return multiBind; + } + + public static TAOS_MULTI_BIND MultiBindNchar(string[] arr) + { + TAOS_MULTI_BIND multiBind = new TAOS_MULTI_BIND(); + int elementCount = arr.Length; + int typeSize = MaxElementLength(arr); + int intSize = sizeof(int); + int byteSize = sizeof(byte); + StringBuilder arrStrBuilder = new StringBuilder(); ; + + //TAOS_MULTI_BIND.length + IntPtr lengthArr = Marshal.AllocHGlobal(intSize * elementCount); + //TAOS_MULTI_BIND.is_null + IntPtr nullArr = Marshal.AllocHGlobal(byteSize * elementCount); + + for (int i = 0; i < elementCount; i++) + { + int itemLength = 0; + // if element if not null and element length is less then typeSize + // fill the memory with default char.Since arr element memory need align. + if (!String.IsNullOrEmpty(arr[i]) && typeSize <= arr[i].Length) + { + itemLength = arr[i].Length; + arrStrBuilder.Append(arr[i]); + } + else if (!String.IsNullOrEmpty(arr[i]) && typeSize > arr[i].Length) + { + itemLength = arr[i].Length; + arrStrBuilder.Append(arr[i]); + arrStrBuilder.Append(AlignCharArr(typeSize - arr[i].Length)); + } + else + { + // if is null value,fill the memory with default values. + itemLength = 0; + arrStrBuilder.Append(AlignCharArr(typeSize)); + } + + //set TAOS_MULTI_BIND.length + Marshal.WriteInt32(lengthArr, intSize * i, itemLength); + //set TAOS_MULTI_BIND.is_null + Marshal.WriteByte(nullArr, byteSize * i, Convert.ToByte(String.IsNullOrEmpty(arr[i]) ? 1 : 0)); + } + //set TAOS_MULTI_BIND.buffer + IntPtr uNcharBuff = (IntPtr)Marshal.StringToHGlobalAnsi(arrStrBuilder.ToString()); + + //config TAOS_MULTI_BIND + multiBind.buffer_type = (int)TDengineDataType.TSDB_DATA_TYPE_NCHAR; + multiBind.buffer = uNcharBuff; + multiBind.buffer_length = (ulong)typeSize; + multiBind.length = lengthArr; + multiBind.is_null = nullArr; + multiBind.num = elementCount; + + return multiBind; + } + + public static TAOS_MULTI_BIND MultiBindTimestamp(long[] arr) + { + TAOS_MULTI_BIND multiBind = new TAOS_MULTI_BIND(); + int elementCount = arr.Length; + int typeSize = sizeof(long); + int intSize = sizeof(int); + int byteSize = sizeof(byte); + //TAOS_MULTI_BIND.buffer + IntPtr unmanagedTsArr = Marshal.AllocHGlobal(typeSize * elementCount); + //TAOS_MULTI_BIND.length + IntPtr lengthArr = Marshal.AllocHGlobal(intSize * elementCount); + //TAOS_MULTI_BIND.is_null + IntPtr nullArr = Marshal.AllocHGlobal(byteSize * elementCount); + + for (int i = 0; i < elementCount; i++) + { + //set TAOS_MULTI_BIND.buffer + Marshal.WriteInt64(unmanagedTsArr, typeSize * i, arr[i]); + //set TAOS_MULTI_BIND.length + Marshal.WriteInt32(lengthArr, intSize * i, typeSize); + //set TAOS_MULTI_BIND.is_null + Marshal.WriteByte(nullArr, byteSize * i, 0); + } + + //config TAOS_MULTI_BIND + multiBind.buffer_type = (int)TDengineDataType.TSDB_DATA_TYPE_TIMESTAMP; + multiBind.buffer = unmanagedTsArr; + multiBind.buffer_length = (ulong)typeSize; + multiBind.length = lengthArr; + multiBind.is_null = nullArr; + multiBind.num = elementCount; + + return multiBind; + } + + public static void FreeTaosBind(TAOS_MULTI_BIND[] mBinds) + { + foreach (TAOS_MULTI_BIND bind in mBinds) + { + Marshal.FreeHGlobal(bind.buffer); + Marshal.FreeHGlobal(bind.length); + Marshal.FreeHGlobal(bind.is_null); + } + } + + private static char[] AlignCharArr(int offSet) + { + char[] alignChar = new char[offSet]; + for (int i = 0; i < offSet; i++) + { + alignChar[i] = char.MinValue; + } + return alignChar; + } + + private static int MaxElementLength(String[] strArr) + { + int max = 0; + for (int i = 0; i < strArr.Length; i++) + { + if (!String.IsNullOrEmpty(strArr[i]) && max < strArr[i].Length) + { + max = strArr[i].Length; + } + } + return max; + } + } + +} \ No newline at end of file diff --git a/src/connector/C#/src/test/Cases/Cases.csproj b/src/connector/C#/src/test/Cases/Cases.csproj new file mode 100644 index 0000000000000000000000000000000000000000..f2ae6938fb4b8c58d9bb657e5fb504814068e92e --- /dev/null +++ b/src/connector/C#/src/test/Cases/Cases.csproj @@ -0,0 +1,12 @@ + + + + + + + + Exe + net5.0 + + + diff --git a/src/connector/C#/src/test/Cases/DataSource.cs b/src/connector/C#/src/test/Cases/DataSource.cs new file mode 100644 index 0000000000000000000000000000000000000000..e422c70bf1d4b45a752984e3290fa8751d8ff41c --- /dev/null +++ b/src/connector/C#/src/test/Cases/DataSource.cs @@ -0,0 +1,103 @@ +using System; +using Test.UtilsTools; +using TDengineDriver; + +namespace Test.UtilsTools.DataSource +{ + public class DataSource + { + public static long[] tsArr = new long[5] { 1637064040000, 1637064041000, 1637064042000, 1637064043000, 1637064044000 }; + public static bool?[] boolArr = new bool?[5] { true, false, null, true, true }; + public static sbyte?[] tinyIntArr = new sbyte?[5] { -127, 0, null, 8, 127 }; + public static short?[] shortArr = new short?[5] { short.MinValue + 1, -200, null, 100, short.MaxValue }; + public static int?[] intArr = new int?[5] { -200, -100, null, 0, 300 }; + public static long?[] longArr = new long?[5] { long.MinValue + 1, -2000, null, 1000, long.MaxValue }; + public static float?[] floatArr = new float?[5] { float.MinValue + 1, -12.1F, null, 0F, float.MaxValue }; + public static double?[] doubleArr = new double?[5] { double.MinValue + 1, -19.112D, null, 0D, double.MaxValue }; + public static byte?[] uTinyIntArr = new byte?[5] { byte.MinValue, 12, null, 89, byte.MaxValue - 1 }; + public static ushort?[] uShortArr = new ushort?[5] { ushort.MinValue, 200, null, 400, ushort.MaxValue - 1 }; + public static uint?[] uIntArr = new uint?[5] { uint.MinValue, 100, null, 2, uint.MaxValue - 1 }; + public static ulong?[] uLongArr = new ulong?[5] { ulong.MinValue, 2000, null, 1000, long.MaxValue - 1 }; + public static string[] binaryArr = new string[5] { "1234567890~!@#$%^&*()_+=-`[]{}:,./<>?", String.Empty, null, "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM", "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM1234567890~!@#$%^&*()_+=-`[]{}:,./<>?" }; + public static string[] ncharArr = new string[5] { "1234567890~!@#$%^&*()_+=-`[]{}:,./<>?", null, "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM", "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM1234567890~!@#$%^&*()_+=-`[]{}:,./<>?", string.Empty }; + + + public static TAOS_BIND[] getTags() + { + TAOS_BIND[] binds = new TAOS_BIND[13]; + binds[0] = TaosBind.BindBool(true); + binds[1] = TaosBind.BindTinyInt(-2); + binds[2] = TaosBind.BindSmallInt(short.MaxValue); + binds[3] = TaosBind.BindInt(int.MaxValue); + binds[4] = TaosBind.BindBigInt(Int64.MaxValue); + binds[5] = TaosBind.BindUTinyInt(byte.MaxValue - 1); + binds[6] = TaosBind.BindUSmallInt(UInt16.MaxValue - 1); + binds[7] = TaosBind.BindUInt(uint.MinValue + 1); + binds[8] = TaosBind.BindUBigInt(UInt64.MinValue + 1); + binds[9] = TaosBind.BindFloat(11.11F); + binds[10] = TaosBind.BindDouble(22.22D); + binds[11] = TaosBind.BindBinary("qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKZXCVBNM`1234567890-=+_)(*&^%$#@!~[];,./<>?:{}"); + binds[12] = TaosBind.BindNchar("qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKZXCVBNM`1234567890-=+_)(*&^%$#@!~[];,./<>?:{}"); + return binds; + } + public static TAOS_BIND[] getNtableRow() + { + TAOS_BIND[] binds = new TAOS_BIND[15]; + binds[0] = TaosBind.BindTimestamp(1637064040000); + binds[1] = TaosBind.BindTinyInt(-2); + binds[2] = TaosBind.BindSmallInt(short.MaxValue); + binds[3] = TaosBind.BindInt(int.MaxValue); + binds[4] = TaosBind.BindBigInt(Int64.MaxValue); + binds[5] = TaosBind.BindUTinyInt(byte.MaxValue - 1); + binds[6] = TaosBind.BindUSmallInt(UInt16.MaxValue - 1); + binds[7] = TaosBind.BindUInt(uint.MinValue + 1); + binds[8] = TaosBind.BindUBigInt(UInt64.MinValue + 1); + binds[9] = TaosBind.BindFloat(11.11F); + binds[10] = TaosBind.BindDouble(22.22D); + binds[11] = TaosBind.BindBinary("qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKZXCVBNM`1234567890-=+_)(*&^%$#@!~[];,./<>?:{}"); + binds[12] = TaosBind.BindNchar("qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKZXCVBNM`1234567890-=+_)(*&^%$#@!~[];,./<>?:{}"); + binds[13] = TaosBind.BindBool(true); + binds[14] = TaosBind.BindNil(); + return binds; + } + + public static TAOS_MULTI_BIND[] GetMultiBindArr() + { + TAOS_MULTI_BIND[] mBinds = new TAOS_MULTI_BIND[14]; + mBinds[0] = TaosMultiBind.MultiBindTimestamp(tsArr); + mBinds[1] = TaosMultiBind.MultiBindBool(boolArr); + mBinds[2] = TaosMultiBind.MultiBindTinyInt(tinyIntArr); + mBinds[3] = TaosMultiBind.MultiBindSmallInt(shortArr); + mBinds[4] = TaosMultiBind.MultiBindInt(intArr); + mBinds[5] = TaosMultiBind.MultiBindBigint(longArr); + mBinds[6] = TaosMultiBind.MultiBindFloat(floatArr); + mBinds[7] = TaosMultiBind.MultiBindDouble(doubleArr); + mBinds[8] = TaosMultiBind.MultiBindUTinyInt(uTinyIntArr); + mBinds[9] = TaosMultiBind.MultiBindUSmallInt(uShortArr); + mBinds[10] = TaosMultiBind.MultiBindUInt(uIntArr); + mBinds[11] = TaosMultiBind.MultiBindUBigInt(uLongArr); + mBinds[12] = TaosMultiBind.MultiBindBinary(binaryArr); + mBinds[13] = TaosMultiBind.MultiBindNchar(ncharArr); + return mBinds; + } + public static TAOS_BIND[] GetQueryCondition() + { + TAOS_BIND[] queryCondition = new TAOS_BIND[2]; + queryCondition[0] = TaosBind.BindTinyInt(0); + queryCondition[1] = TaosBind.BindInt(1000); + return queryCondition; + + } + public static void FreeTaosBind(TAOS_BIND[] binds) + { + TaosBind.FreeTaosBind(binds); + } + + public static void FreeTaosMBind(TAOS_MULTI_BIND[] mbinds) + { + TaosMultiBind.FreeTaosBind(mbinds); + } + + + } +} \ No newline at end of file diff --git a/src/connector/C#/src/test/Cases/Program.cs b/src/connector/C#/src/test/Cases/Program.cs new file mode 100644 index 0000000000000000000000000000000000000000..3d3b765b5bfb80c61b85d974bcc240d7a234d75d --- /dev/null +++ b/src/connector/C#/src/test/Cases/Program.cs @@ -0,0 +1,59 @@ +using System; +using Test.UtilsTools; +using Cases; + +namespace Cases.EntryPoint +{ + class Program + { + + static void Main(string[] args) + { + IntPtr conn = IntPtr.Zero; + IntPtr stmt = IntPtr.Zero; + IntPtr res = IntPtr.Zero; + + conn = UtilsTools.TDConnection("127.0.0.1", "root", "taosdata", "", 0); + UtilsTools.ExecuteQuery(conn, "drop database if exists csharp"); + UtilsTools.ExecuteQuery(conn, "create database if not exists csharp keep 3650"); + UtilsTools.ExecuteQuery(conn, "use csharp"); + + Console.WriteLine("====================StableColumnByColumn==================="); + StableColumnByColumn columnByColumn = new StableColumnByColumn(); + columnByColumn.Test(conn, "stablecolumnbycolumn"); + Console.WriteLine("====================StmtStableQuery==================="); + StmtStableQuery stmtStableQuery = new StmtStableQuery(); + stmtStableQuery.Test(conn, "stablecolumnbycolumn"); + + Console.WriteLine("====================StableMutipleLine==================="); + StableMutipleLine mutipleLine = new StableMutipleLine(); + mutipleLine.Test(conn, "stablemutipleline"); + + //================================================================================ + + Console.WriteLine("====================NtableSingleLine==================="); + NtableSingleLine ntableSingleLine = new NtableSingleLine(); + ntableSingleLine.Test(conn, "stablesingleline"); + + Console.WriteLine("====================NtableMutipleLine==================="); + NtableMutipleLine ntableMutipleLine = new NtableMutipleLine(); + ntableMutipleLine.Test(conn, "ntablemutipleline"); + Console.WriteLine("====================StmtNtableQuery==================="); + StmtNtableQuery stmtNtableQuery = new StmtNtableQuery(); + stmtNtableQuery.Test(conn, "ntablemutipleline"); + + Console.WriteLine("====================NtableColumnByColumn==================="); + NtableColumnByColumn ntableColumnByColumn = new NtableColumnByColumn(); + ntableColumnByColumn.Test(conn, "ntablecolumnbycolumn"); + + Console.WriteLine("====================fetchfeilds==================="); + FetchFields fetchFields = new FetchFields(); + fetchFields.Test(conn, "fetchfeilds"); + + UtilsTools.ExecuteQuery(conn, "drop database if exists csharp"); + UtilsTools.CloseConnection(conn); + UtilsTools.ExitProgram(); + + } + } +} diff --git a/src/connector/C#/src/test/Cases/StmtNormalTable.cs b/src/connector/C#/src/test/Cases/StmtNormalTable.cs new file mode 100644 index 0000000000000000000000000000000000000000..a918f6bada153bc64d0c31d10597526503d696f8 --- /dev/null +++ b/src/connector/C#/src/test/Cases/StmtNormalTable.cs @@ -0,0 +1,89 @@ +using System; +using Test.UtilsTools; +using TDengineDriver; +using Test.UtilsTools.DataSource; + +namespace Cases +{ + public class NtableSingleLine + { + + public void Test(IntPtr conn, string tableName) + { + String createTb = "create table " + tableName + "(ts timestamp,tt tinyint,si smallint,ii int,bi bigint,tu tinyint unsigned,su smallint unsigned,iu int unsigned,bu bigint unsigned,ff float ,dd double ,bb binary(200),nc nchar(200),bo bool,nullVal int);"; + String insertSql = "insert into ? values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"; + TAOS_BIND[] valuesRow = DataSource.getNtableRow(); + UtilsTools.ExecuteQuery(conn, createTb); + + IntPtr stmt = StmtUtilTools.StmtInit(conn); + StmtUtilTools.StmtPrepare(stmt, insertSql); + StmtUtilTools.SetTableName(stmt, tableName); + StmtUtilTools.BindParam(stmt, valuesRow); + StmtUtilTools.AddBatch(stmt); + StmtUtilTools.StmtExecute(stmt); + StmtUtilTools.StmtClose(stmt); + DataSource.FreeTaosBind(valuesRow); + } + } + + public class NtableMutipleLine + { + TAOS_MULTI_BIND[] mbind = DataSource.GetMultiBindArr(); + public void Test(IntPtr conn, string tableName) + { + String createTb = "create table " + tableName + " (ts timestamp ,b bool,v1 tinyint,v2 smallint,v4 int,v8 bigint,f4 float,f8 double,u1 tinyint unsigned,u2 smallint unsigned,u4 int unsigned,u8 bigint unsigned,bin binary(200),blob nchar(200));"; + String insertSql = "insert into ? values(?,?,?,?,?,?,?,?,?,?,?,?,?,?)"; + + UtilsTools.ExecuteQuery(conn, createTb); + String[] loadList = { tableName }; + IntPtr stmt = StmtUtilTools.StmtInit(conn); + StmtUtilTools.loadTableInfo(conn, loadList); + StmtUtilTools.StmtPrepare(stmt, insertSql); + StmtUtilTools.SetTableName(stmt, tableName); + StmtUtilTools.BindParamBatch(stmt, mbind); + StmtUtilTools.AddBatch(stmt); + StmtUtilTools.StmtExecute(stmt); + StmtUtilTools.StmtClose(stmt); + DataSource.FreeTaosMBind(mbind); + } + } + public class NtableColumnByColumn + { + DataSource data = new DataSource(); + TAOS_MULTI_BIND[] mbind = DataSource.GetMultiBindArr(); + public void Test(IntPtr conn, string tableName) + { + String createTb = "create table " + tableName + " (ts timestamp ,b bool,v1 tinyint,v2 smallint,v4 int,v8 bigint,f4 float,f8 double,u1 tinyint unsigned,u2 smallint unsigned,u4 int unsigned,u8 bigint unsigned,bin binary(200),blob nchar(200));"; + String insertSql = "insert into ? values(?,?,?,?,?,?,?,?,?,?,?,?,?,?)"; + + + UtilsTools.ExecuteQuery(conn, createTb); + IntPtr stmt = StmtUtilTools.StmtInit(conn); + + StmtUtilTools.StmtPrepare(stmt, insertSql); + + StmtUtilTools.SetTableName(stmt, tableName); + StmtUtilTools.BindSingleParamBatch(stmt, mbind[0], 0); + StmtUtilTools.BindSingleParamBatch(stmt, mbind[1], 1); + StmtUtilTools.BindSingleParamBatch(stmt, mbind[2], 2); + StmtUtilTools.BindSingleParamBatch(stmt, mbind[3], 3); + StmtUtilTools.BindSingleParamBatch(stmt, mbind[4], 4); + StmtUtilTools.BindSingleParamBatch(stmt, mbind[5], 5); + StmtUtilTools.BindSingleParamBatch(stmt, mbind[6], 6); + StmtUtilTools.BindSingleParamBatch(stmt, mbind[7], 7); + StmtUtilTools.BindSingleParamBatch(stmt, mbind[8], 8); + StmtUtilTools.BindSingleParamBatch(stmt, mbind[9], 9); + StmtUtilTools.BindSingleParamBatch(stmt, mbind[10], 10); + StmtUtilTools.BindSingleParamBatch(stmt, mbind[11], 11); + StmtUtilTools.BindSingleParamBatch(stmt, mbind[12], 12); + StmtUtilTools.BindSingleParamBatch(stmt, mbind[13], 13); + + StmtUtilTools.AddBatch(stmt); + StmtUtilTools.StmtExecute(stmt); + StmtUtilTools.StmtClose(stmt); + + DataSource.FreeTaosMBind(mbind); + + } + } +} \ No newline at end of file diff --git a/src/connector/C#/src/test/Cases/StmtQuery.cs b/src/connector/C#/src/test/Cases/StmtQuery.cs new file mode 100644 index 0000000000000000000000000000000000000000..7909376ad8d2166acc51e9f683bfbbac1dcd652e --- /dev/null +++ b/src/connector/C#/src/test/Cases/StmtQuery.cs @@ -0,0 +1,49 @@ +using System; +using Test.UtilsTools; +using TDengineDriver; +using Test.UtilsTools.DataSource; + +namespace Cases +{ + public class StmtStableQuery + { + public void Test(IntPtr conn, string tableName) + { + string selectSql = "SELECT * FROM " + tableName + " WHERE v1 > ? AND v4 < ?"; + TAOS_BIND[] queryCondition = DataSource.GetQueryCondition(); + + IntPtr stmt = StmtUtilTools.StmtInit(conn); + StmtUtilTools.StmtPrepare(stmt, selectSql); + + StmtUtilTools.BindParam(stmt, queryCondition); + StmtUtilTools.StmtExecute(stmt); + IntPtr res = StmtUtilTools.StmtUseResult(stmt); + UtilsTools.DisplayRes(res); + + StmtUtilTools.StmtClose(stmt); + DataSource.FreeTaosBind(queryCondition); + + } + } + + public class StmtNtableQuery + { + public void Test(IntPtr conn, string tableName) + { + string selectSql = "SELECT * FROM " + tableName + " WHERE v1 > ? AND v4 < ?"; + TAOS_BIND[] queryCondition = DataSource.GetQueryCondition(); + + IntPtr stmt = StmtUtilTools.StmtInit(conn); + StmtUtilTools.StmtPrepare(stmt, selectSql); + + StmtUtilTools.BindParam(stmt, queryCondition); + StmtUtilTools.StmtExecute(stmt); + IntPtr res = StmtUtilTools.StmtUseResult(stmt); + UtilsTools.DisplayRes(res); + + StmtUtilTools.StmtClose(stmt); + DataSource.FreeTaosBind(queryCondition); + + } + } +} \ No newline at end of file diff --git a/src/connector/C#/src/test/Cases/StmtStable.cs b/src/connector/C#/src/test/Cases/StmtStable.cs new file mode 100644 index 0000000000000000000000000000000000000000..f6024909d04b2a239f0b49ba5bba65eba3d2a718 --- /dev/null +++ b/src/connector/C#/src/test/Cases/StmtStable.cs @@ -0,0 +1,76 @@ +using System; +using Test.UtilsTools; +using TDengineDriver; +using Test.UtilsTools.DataSource; + +namespace Cases +{ + + public class StableMutipleLine + { + TAOS_BIND[] tags = DataSource.getTags(); + TAOS_MULTI_BIND[] mbind = DataSource.GetMultiBindArr(); + public void Test(IntPtr conn, string tableName) + { + String createTb = "create stable " + tableName + " (ts timestamp ,b bool,v1 tinyint,v2 smallint,v4 int,v8 bigint,f4 float,f8 double,u1 tinyint unsigned,u2 smallint unsigned,u4 int unsigned,u8 bigint unsigned,bin binary(200),blob nchar(200))tags(bo bool,tt tinyint,si smallint,ii int,bi bigint,tu tinyint unsigned,su smallint unsigned,iu int unsigned,bu bigint unsigned,ff float ,dd double ,bb binary(200),nc nchar(200));"; + String insertSql = "insert into ? using " + tableName + " tags(?,?,?,?,?,?,?,?,?,?,?,?,?) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?)"; + + UtilsTools.ExecuteQuery(conn, createTb); + String[] loadList = { tableName }; + IntPtr stmt = StmtUtilTools.StmtInit(conn); + StmtUtilTools.loadTableInfo(conn, loadList); + + StmtUtilTools.StmtPrepare(stmt, insertSql); + StmtUtilTools.SetTableNameTags(stmt, tableName + "_t1", tags); + StmtUtilTools.BindParamBatch(stmt, mbind); + StmtUtilTools.AddBatch(stmt); + StmtUtilTools.StmtExecute(stmt); + + StmtUtilTools.StmtClose(stmt); + DataSource.FreeTaosBind(tags); + DataSource.FreeTaosMBind(mbind); + } + } + public class StableColumnByColumn + { + DataSource data = new DataSource(); + + TAOS_BIND[] tags = DataSource.getTags(); + TAOS_MULTI_BIND[] mbind = DataSource.GetMultiBindArr(); + public void Test(IntPtr conn, string tableName) + { + String createTb = "create stable " + tableName + " (ts timestamp ,b bool,v1 tinyint,v2 smallint,v4 int,v8 bigint,f4 float,f8 double,u1 tinyint unsigned,u2 smallint unsigned,u4 int unsigned,u8 bigint unsigned,bin binary(200),blob nchar(200))tags(bo bool,tt tinyint,si smallint,ii int,bi bigint,tu tinyint unsigned,su smallint unsigned,iu int unsigned,bu bigint unsigned,ff float ,dd double ,bb binary(200),nc nchar(200));"; + String insertSql = "insert into ? using " + tableName + " tags(?,?,?,?,?,?,?,?,?,?,?,?,?) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?)"; + + + UtilsTools.ExecuteQuery(conn, createTb); + IntPtr stmt = StmtUtilTools.StmtInit(conn); + + StmtUtilTools.StmtPrepare(stmt, insertSql); + + StmtUtilTools.SetTableNameTags(stmt, tableName + "_t1", tags); + StmtUtilTools.BindSingleParamBatch(stmt, mbind[0], 0); + StmtUtilTools.BindSingleParamBatch(stmt, mbind[1], 1); + StmtUtilTools.BindSingleParamBatch(stmt, mbind[2], 2); + StmtUtilTools.BindSingleParamBatch(stmt, mbind[3], 3); + StmtUtilTools.BindSingleParamBatch(stmt, mbind[4], 4); + StmtUtilTools.BindSingleParamBatch(stmt, mbind[5], 5); + StmtUtilTools.BindSingleParamBatch(stmt, mbind[6], 6); + StmtUtilTools.BindSingleParamBatch(stmt, mbind[7], 7); + StmtUtilTools.BindSingleParamBatch(stmt, mbind[8], 8); + StmtUtilTools.BindSingleParamBatch(stmt, mbind[9], 9); + StmtUtilTools.BindSingleParamBatch(stmt, mbind[10], 10); + StmtUtilTools.BindSingleParamBatch(stmt, mbind[11], 11); + StmtUtilTools.BindSingleParamBatch(stmt, mbind[12], 12); + StmtUtilTools.BindSingleParamBatch(stmt, mbind[13], 13); + StmtUtilTools.AddBatch(stmt); + StmtUtilTools.StmtExecute(stmt); + StmtUtilTools.StmtClose(stmt); + + DataSource.FreeTaosBind(tags); + DataSource.FreeTaosMBind(mbind); + + } + } + +} \ No newline at end of file diff --git a/src/connector/C#/src/test/Cases/StmtUtil.cs b/src/connector/C#/src/test/Cases/StmtUtil.cs new file mode 100644 index 0000000000000000000000000000000000000000..8f68157e095fd3aa3e47bb5aa19dc08d42be4628 --- /dev/null +++ b/src/connector/C#/src/test/Cases/StmtUtil.cs @@ -0,0 +1,198 @@ +using System; +using TDengineDriver; +using System.Runtime.InteropServices; + +namespace Test.UtilsTools +{ + public class StmtUtilTools + { + public static IntPtr StmtInit(IntPtr conn) + { + IntPtr stmt = TDengine.StmtInit(conn); + if (stmt == IntPtr.Zero) + { + Console.WriteLine("Init stmt failed"); + UtilsTools.CloseConnection(conn); + UtilsTools.ExitProgram(); + } + else + { + Console.WriteLine("Init stmt success"); + } + return stmt; + } + + public static void StmtPrepare(IntPtr stmt, string sql) + { + int res = TDengine.StmtPrepare(stmt, sql); + if (res == 0) + { + Console.WriteLine("stmt prepare success"); + } + else + { + Console.WriteLine("stmt prepare failed " + TDengine.StmtErrorStr(stmt)); + StmtClose(stmt); + } + } + + public static void SetTableName(IntPtr stmt, String tableName) + { + int res = TDengine.StmtSetTbname(stmt, tableName); + if (res == 0) + { + Console.WriteLine("set_tbname success"); + } + else + { + Console.Write("set_tbname failed, " + TDengine.StmtErrorStr(stmt)); + StmtClose(stmt); + } + } + + public static void SetTableNameTags(IntPtr stmt, String tableName, TAOS_BIND[] tags) + { + int res = TDengine.StmtSetTbnameTags(stmt, tableName, tags); + if (res == 0) + { + Console.WriteLine("set tbname && tags success"); + + } + else + { + Console.Write("set tbname && tags failed, " + TDengine.StmtErrorStr(stmt)); + StmtClose(stmt); + } + } + + public static void SetSubTableName(IntPtr stmt, string name) + { + int res = TDengine.StmtSetSubTbname(stmt, name); + if (res == 0) + { + Console.WriteLine("set subtable name success"); + } + else + { + Console.Write("set subtable name failed, " + TDengine.StmtErrorStr(stmt)); + StmtClose(stmt); + } + + } + + public static void BindParam(IntPtr stmt, TAOS_BIND[] binds) + { + int res = TDengine.StmtBindParam(stmt, binds); + if (res == 0) + { + Console.WriteLine("bind para success"); + } + else + { + Console.Write("bind para failed, " + TDengine.StmtErrorStr(stmt)); + StmtClose(stmt); + } + } + + public static void BindSingleParamBatch(IntPtr stmt, TAOS_MULTI_BIND bind, int index) + { + int res = TDengine.StmtBindSingleParamBatch(stmt, ref bind, index); + if (res == 0) + { + Console.WriteLine("single bind batch success"); + } + else + { + Console.Write("single bind batch failed: " + TDengine.StmtErrorStr(stmt)); + StmtClose(stmt); + } + } + + public static void BindParamBatch(IntPtr stmt, TAOS_MULTI_BIND[] bind) + { + int res = TDengine.StmtBindParamBatch(stmt, bind); + if (res == 0) + { + Console.WriteLine("bind parameter batch success"); + } + else + { + Console.WriteLine("bind parameter batch failed, " + TDengine.StmtErrorStr(stmt)); + StmtClose(stmt); + } + } + + public static void AddBatch(IntPtr stmt) + { + int res = TDengine.StmtAddBatch(stmt); + if (res == 0) + { + Console.WriteLine("stmt add batch success"); + } + else + { + Console.Write("stmt add batch failed,reason: " + TDengine.StmtErrorStr(stmt)); + StmtClose(stmt); + } + } + public static void StmtExecute(IntPtr stmt) + { + int res = TDengine.StmtExecute(stmt); + if (res == 0) + { + Console.WriteLine("Execute stmt success"); + } + else + { + Console.Write("Execute stmt failed,reason: " + TDengine.StmtErrorStr(stmt)); + StmtClose(stmt); + } + } + public static void StmtClose(IntPtr stmt) + { + int res = TDengine.StmtClose(stmt); + if (res == 0) + { + Console.WriteLine("close stmt success"); + } + else + { + Console.WriteLine("close stmt failed, " + TDengine.StmtErrorStr(stmt)); + StmtClose(stmt); + } + } + + public static IntPtr StmtUseResult(IntPtr stmt) + { + IntPtr res = TDengine.StmtUseResult(stmt); + if ((res == IntPtr.Zero) || (TDengine.ErrorNo(res) != 0)) + { + if (res != IntPtr.Zero) + { + Console.Write("reason: " + TDengine.Error(res)); + } + Console.WriteLine(""); + StmtClose(stmt); + } + else + { + Console.WriteLine("StmtUseResult success"); + + } + return res; + } + + public static void loadTableInfo(IntPtr conn, string[] arr) + { + if (TDengine.LoadTableInfo(conn, arr) == 0) + { + Console.WriteLine("load table info success"); + } + else + { + Console.WriteLine("load table info failed"); + } + } + + } +} \ No newline at end of file diff --git a/src/connector/C#/src/test/Cases/TaosFeild.cs b/src/connector/C#/src/test/Cases/TaosFeild.cs new file mode 100644 index 0000000000000000000000000000000000000000..b8c6d37ef5e3f14640d5e87504148c4ea7748e23 --- /dev/null +++ b/src/connector/C#/src/test/Cases/TaosFeild.cs @@ -0,0 +1,37 @@ +using System; +using Test.UtilsTools; +using TDengineDriver; +using System.Collections.Generic; +using System.Runtime.InteropServices; +namespace Cases +{ + public class FetchFields + { + public void Test(IntPtr conn, string tableName) + { + IntPtr res = IntPtr.Zero; + String createTb = "create stable " + tableName + " (ts timestamp ,b bool,v1 tinyint,v2 smallint,v4 int,v8 bigint,f4 float,f8 double,u1 tinyint unsigned,u2 smallint unsigned,u4 int unsigned,u8 bigint unsigned,bin binary(200),blob nchar(200))tags(id int);"; + String insertSql = "insert into " + tableName + "_t1 using " + tableName + " tags(1) values(1637064040000,true,1,2,3,4,5,6,7,8,9,10,'XI','XII')"; + String selectSql = "select * from " + tableName; + String dropSql = "drop table " + tableName; + UtilsTools.ExecuteQuery(conn, createTb); + UtilsTools.ExecuteQuery(conn, insertSql); + res = UtilsTools.ExecuteQuery(conn, selectSql); + UtilsTools.ExecuteQuery(conn, dropSql); + + List metas = new List(); + metas = TDengine.FetchFields(res); + if (metas.Capacity == 0) + { + Console.WriteLine("empty result"); + } + else + { + foreach(TDengineMeta meta in metas){ + Console.WriteLine("col_name:{0},col_type_code:{1},col_type:{2}({3})",meta.name,meta.type,meta.TypeName(),meta.size); + } + } + + } + } +} \ No newline at end of file diff --git a/src/connector/C#/src/test/Cases/Utils.cs b/src/connector/C#/src/test/Cases/Utils.cs new file mode 100644 index 0000000000000000000000000000000000000000..26414c91f9e6b65f58b0405786ced54fa4b61bcd --- /dev/null +++ b/src/connector/C#/src/test/Cases/Utils.cs @@ -0,0 +1,166 @@ +using System; +using TDengineDriver; +using System.Runtime.InteropServices; +using System.Text; +using System.Collections.Generic; +namespace Test.UtilsTools +{ + public class UtilsTools + { + + static string configDir = "C:/TDengine/cfg"; + + public static IntPtr TDConnection(string ip, string user, string password, string db, short port) + { + TDengine.Options((int)TDengineInitOption.TDDB_OPTION_CONFIGDIR, configDir); + TDengine.Options((int)TDengineInitOption.TDDB_OPTION_SHELL_ACTIVITY_TIMER, "60"); + TDengine.Init(); + return TDengine.Connect(ip, user, password, db, port); + } + + public static IntPtr ExecuteQuery(IntPtr conn, String sql) + { + IntPtr res = TDengine.Query(conn, sql); + 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"); + + } + return res; + } + public static void DisplayRes(IntPtr res) + { + long queryRows = 0; + if ((res == IntPtr.Zero) || (TDengine.ErrorNo(res) != 0)) + { + if (res != IntPtr.Zero) + { + Console.Write("reason: " + TDengine.Error(res)); + } + Console.WriteLine(""); + ExitProgram(); + } + + 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)); + } + TDengine.FreeResult(res); Console.WriteLine(""); + } + + public static void CloseConnection(IntPtr conn) + { + if (conn != IntPtr.Zero) + { + if (TDengine.Close(conn) == 0) + { + Console.WriteLine("close connection sucess"); + } + else + { + Console.WriteLine("close Connection failed"); + } + } + } + public static List getField(IntPtr res) + { + List metas = TDengine.FetchFields(res); + return metas; + } + public static void ExitProgram() + { + TDengine.Cleanup(); + System.Environment.Exit(0); + } + } +} \ No newline at end of file diff --git a/src/connector/C#/src/test/XUnitTest/TestTDengineMeta.cs b/src/connector/C#/src/test/XUnitTest/TestTDengineMeta.cs new file mode 100644 index 0000000000000000000000000000000000000000..fcf86c994e9097168786c1803901866918806098 --- /dev/null +++ b/src/connector/C#/src/test/XUnitTest/TestTDengineMeta.cs @@ -0,0 +1,177 @@ +using System; +using Xunit; +using TDengineDriver; + +namespace TDengineDriver.Test +{ + public class TestTDengineMeta + { + [Fact] + public void TestTypeNameBool() + { + string typeName = "BOOL"; + TDengineDriver.TDengineMeta meta = new TDengineDriver.TDengineMeta(); + meta.type = 1; + string metaTypeName = meta.TypeName(); + + Assert.Equal(metaTypeName, typeName); + + } + + [Fact] + public void TestTypeNameTINYINT() + { + string typeName = "TINYINT"; + TDengineDriver.TDengineMeta meta = new TDengineDriver.TDengineMeta(); + meta.type = 2; + string metaTypeName = meta.TypeName(); + + Assert.Equal(metaTypeName, typeName); + + } + [Fact] + public void TestTypeNameSMALLINT() + { + string typeName = "SMALLINT"; + TDengineDriver.TDengineMeta meta = new TDengineDriver.TDengineMeta(); + meta.type = 3; + string metaTypeName = meta.TypeName(); + + Assert.Equal(metaTypeName, typeName); + + } + [Fact] + public void TestTypeNameINT() + { + string typeName = "INT"; + TDengineDriver.TDengineMeta meta = new TDengineDriver.TDengineMeta(); + meta.type = 4; + string metaTypeName = meta.TypeName(); + + Assert.Equal(metaTypeName, typeName); + + } + [Fact] + public void TestTypeNameBIGINT() + { + string typeName = "BIGINT"; + TDengineDriver.TDengineMeta meta = new TDengineDriver.TDengineMeta(); + meta.type = 5; + string metaTypeName = meta.TypeName(); + + Assert.Equal(metaTypeName, typeName); + + } + [Fact] + public void TestTypeNameUTINYINT() + { + string typeName = "TINYINT UNSIGNED"; + TDengineDriver.TDengineMeta meta = new TDengineDriver.TDengineMeta(); + meta.type = 11; + string metaTypeName = meta.TypeName(); + + Assert.Equal(metaTypeName, typeName); + + } + [Fact] + public void TestTypeNameUSMALLINT() + { + string typeName = "SMALLINT UNSIGNED"; + TDengineDriver.TDengineMeta meta = new TDengineDriver.TDengineMeta(); + meta.type = 12; + string metaTypeName = meta.TypeName(); + + Assert.Equal(metaTypeName, typeName); + + } + [Fact] + public void TestTypeNameUINT() + { + string typeName = "INT UNSIGNED"; + TDengineDriver.TDengineMeta meta = new TDengineDriver.TDengineMeta(); + meta.type = 13; + string metaTypeName = meta.TypeName(); + + Assert.Equal(metaTypeName, typeName); + + } + [Fact] + public void TestTypeNameUBIGINT() + { + string typeName = "BIGINT UNSIGNED"; + TDengineDriver.TDengineMeta meta = new TDengineDriver.TDengineMeta(); + meta.type = 14; + string metaTypeName = meta.TypeName(); + + Assert.Equal(metaTypeName, typeName); + + } + + [Fact] + public void TestTypeNameFLOAT() + { + string typeName = "FLOAT"; + TDengineDriver.TDengineMeta meta = new TDengineDriver.TDengineMeta(); + meta.type = 6; + string metaTypeName = meta.TypeName(); + + Assert.Equal(metaTypeName, typeName); + + } + [Fact] + public void TestTypeNameDOUBLE() + { + string typeName = "DOUBLE"; + TDengineDriver.TDengineMeta meta = new TDengineDriver.TDengineMeta(); + meta.type = 7; + string metaTypeName = meta.TypeName(); + + Assert.Equal(metaTypeName, typeName); + + } + [Fact] + public void TestTypeNameSTRING() + { + string typeName = "STRING"; + TDengineDriver.TDengineMeta meta = new TDengineDriver.TDengineMeta(); + meta.type = 8; + string metaTypeName = meta.TypeName(); + + Assert.Equal(metaTypeName, typeName); + + } + [Fact] + public void TestTypeNameTIMESTAMP() + { + string typeName = "TIMESTAMP"; + TDengineDriver.TDengineMeta meta = new TDengineDriver.TDengineMeta(); + meta.type = 9; + string metaTypeName = meta.TypeName(); + + Assert.Equal(metaTypeName, typeName); + + } + [Fact] + public void TestTypeNameNCHAR() + { + string typeName = "NCHAR"; + TDengineDriver.TDengineMeta meta = new TDengineDriver.TDengineMeta(); + meta.type = 10; + string metaTypeName = meta.TypeName(); + + Assert.Equal(metaTypeName, typeName); + + } + [Fact] + public void TestTypeNameUndefined() + { + string typeName = "undefine"; + TDengineDriver.TDengineMeta meta = new TDengineDriver.TDengineMeta(); + + string metaTypeName = meta.TypeName(); + + Assert.Equal(metaTypeName, typeName); + + } + } +} diff --git a/src/connector/C#/src/test/XUnitTest/TestTaosBind.cs b/src/connector/C#/src/test/XUnitTest/TestTaosBind.cs new file mode 100644 index 0000000000000000000000000000000000000000..208bdcc02cf84db4af149ddc314d67db7b92b848 --- /dev/null +++ b/src/connector/C#/src/test/XUnitTest/TestTaosBind.cs @@ -0,0 +1,863 @@ +using System; +using Xunit; +using TDengineDriver; +using System.Runtime.InteropServices; + +namespace TDengineDriver.Test +{ + public class TestTaosBind + { + [Fact] + public void TestBindBoolTrue() + { + int bufferType = 1; + bool buffer = true; + int bufferLength = sizeof(bool); + int length = sizeof(bool); + + TDengineDriver.TAOS_BIND bind = TaosBind.BindBool(true); + int BindLengPtr = Marshal.ReadInt32(bind.length); + bool bindBuffer = Convert.ToBoolean(Marshal.ReadByte(bind.buffer)); + Console.WriteLine("bind.buffer_type:{0},bufferType:{1}", bind.buffer_type, bufferType); + + Assert.Equal(bind.buffer_type, bufferType); + Assert.Equal(bindBuffer, buffer); + Assert.Equal(bind.buffer_length, bufferLength); + Assert.Equal(BindLengPtr, length); + + Marshal.FreeHGlobal(bind.buffer); + Marshal.FreeHGlobal(bind.length); + + } + + [Fact] + public void TestBindBoolFalse() + { + int bufferType = 1; + bool buffer = false; + int bufferLength = sizeof(bool); + int length = sizeof(bool); + + TDengineDriver.TAOS_BIND bind = TaosBind.BindBool(false); + int BindLengPtr = Marshal.ReadInt32(bind.length); + bool bindBuffer = Convert.ToBoolean(Marshal.ReadByte(bind.buffer)); + Console.WriteLine("bind.buffer_type:{0},bufferType:{1}", bind.buffer_type, bufferType); + + Assert.Equal(bind.buffer_type, bufferType); + Assert.Equal(bindBuffer, buffer); + Assert.Equal(bind.buffer_length, bufferLength); + Assert.Equal(BindLengPtr, length); + + Marshal.FreeHGlobal(bind.buffer); + Marshal.FreeHGlobal(bind.length); + + } + + [Fact] + public void TestBindTinyIntZero() + { + + int bufferType = 2; + sbyte buffer = 0; + int bufferLength = sizeof(sbyte); + int length = sizeof(sbyte); + + TDengineDriver.TAOS_BIND bind = TaosBind.BindTinyInt(0); + int BindLengPtr = Marshal.ReadInt32(bind.length); + sbyte bindBuffer = Convert.ToSByte(Marshal.ReadByte(bind.buffer)); + Console.WriteLine("bind.buffer_type:{0},bufferType:{1}", bind.buffer_type, bufferType); + + Assert.Equal(bind.buffer_type, bufferType); + Assert.Equal(bindBuffer, buffer); + Assert.Equal(bind.buffer_length, bufferLength); + Assert.Equal(BindLengPtr, length); + + Marshal.FreeHGlobal(bind.buffer); + Marshal.FreeHGlobal(bind.length); + } + + [Fact] + public void TestBindTinyIntPositive() + { + + int bufferType = 2; + sbyte buffer = sbyte.MaxValue; + int bufferLength = sizeof(sbyte); + int length = sizeof(sbyte); + + TDengineDriver.TAOS_BIND bind = TaosBind.BindTinyInt(sbyte.MaxValue); + int BindLengPtr = Marshal.ReadInt32(bind.length); + sbyte bindBuffer = Convert.ToSByte(Marshal.ReadByte(bind.buffer)); + Console.WriteLine("bind.buffer_type:{0},bufferType:{1}", bind.buffer_type, bufferType); + + Assert.Equal(bind.buffer_type, bufferType); + Assert.Equal(bindBuffer, buffer); + Assert.Equal(bind.buffer_length, bufferLength); + Assert.Equal(BindLengPtr, length); + + Marshal.FreeHGlobal(bind.buffer); + Marshal.FreeHGlobal(bind.length); + } + + [Fact] + public void TestBindTinyIntNegative() + { + + int bufferType = 2; + short buffer = sbyte.MinValue; + int bufferLength = sizeof(sbyte); + int length = sizeof(sbyte); + + TDengineDriver.TAOS_BIND bind = TaosBind.BindTinyInt(sbyte.MinValue); + int BindLengPtr = Marshal.ReadInt32(bind.length); + short bindBuffer = Marshal.ReadInt16(bind.buffer); + Console.WriteLine("bind.buffer_type:{0},bufferType:{1}", bind.buffer_type, bufferType); + + Assert.Equal(bind.buffer_type, bufferType); + Assert.Equal(bindBuffer, buffer); + Assert.Equal(bind.buffer_length, bufferLength); + Assert.Equal(BindLengPtr, length); + + Marshal.FreeHGlobal(bind.buffer); + Marshal.FreeHGlobal(bind.length); + } + + [Fact] + public void TestBindSmallIntNegative() + { + + int bufferType = 3; + short buffer = short.MinValue; + int bufferLength = sizeof(short); + int length = sizeof(short); + + TDengineDriver.TAOS_BIND bind = TaosBind.BindSmallInt(short.MinValue); + int BindLengPtr = Marshal.ReadInt32(bind.length); + short bindBuffer = Marshal.ReadInt16(bind.buffer); + Console.WriteLine("bind.buffer_type:{0},bufferType:{1}", bind.buffer_type, bufferType); + + Assert.Equal(bind.buffer_type, bufferType); + Assert.Equal(bindBuffer, buffer); + Assert.Equal(bind.buffer_length, bufferLength); + Assert.Equal(BindLengPtr, length); + + Marshal.FreeHGlobal(bind.buffer); + Marshal.FreeHGlobal(bind.length); + } + + [Fact] + public void TestBindSmallIntZero() + { + + int bufferType = 3; + short buffer = 0; + int bufferLength = sizeof(short); + int length = sizeof(short); + + TDengineDriver.TAOS_BIND bind = TaosBind.BindSmallInt(0); + int BindLengPtr = Marshal.ReadInt32(bind.length); + short bindBuffer = Marshal.ReadInt16(bind.buffer); + Console.WriteLine("bind.buffer_type:{0},bufferType:{1}", bind.buffer_type, bufferType); + + Assert.Equal(bind.buffer_type, bufferType); + Assert.Equal(bindBuffer, buffer); + Assert.Equal(bind.buffer_length, bufferLength); + Assert.Equal(BindLengPtr, length); + + Marshal.FreeHGlobal(bind.buffer); + Marshal.FreeHGlobal(bind.length); + } + + [Fact] + public void TestBindSmallIntPositive() + { + + int bufferType = 3; + short buffer = short.MaxValue; + int bufferLength = sizeof(short); + int length = sizeof(short); + + TDengineDriver.TAOS_BIND bind = TaosBind.BindSmallInt(short.MaxValue); + int BindLengPtr = Marshal.ReadInt32(bind.length); + short bindBuffer = Marshal.ReadInt16(bind.buffer); + Console.WriteLine("bind.buffer_type:{0},bufferType:{1}", bind.buffer_type, bufferType); + + Assert.Equal(bind.buffer_type, bufferType); + Assert.Equal(bindBuffer, buffer); + Assert.Equal(bind.buffer_length, bufferLength); + Assert.Equal(BindLengPtr, length); + + Marshal.FreeHGlobal(bind.buffer); + Marshal.FreeHGlobal(bind.length); + } + + [Fact] + public void TestBindIntNegative() + { + + int bufferType = 4; + int buffer = int.MinValue; + int bufferLength = sizeof(int); + int length = sizeof(int); + + TDengineDriver.TAOS_BIND bind = TaosBind.BindInt(int.MinValue); + int BindLengPtr = Marshal.ReadInt32(bind.length); + int bindBuffer = Marshal.ReadInt32(bind.buffer); + Console.WriteLine("bind.buffer_type:{0},bufferType:{1}", bind.buffer_type, bufferType); + + Assert.Equal(bind.buffer_type, bufferType); + Assert.Equal(bindBuffer, buffer); + Assert.Equal(bind.buffer_length, bufferLength); + Assert.Equal(BindLengPtr, length); + + Marshal.FreeHGlobal(bind.buffer); + Marshal.FreeHGlobal(bind.length); + } + + [Fact] + public void TestBindIntZero() + { + + int bufferType = 4; + int buffer = 0; + int bufferLength = sizeof(int); + int length = sizeof(int); + + TDengineDriver.TAOS_BIND bind = TaosBind.BindInt(0); + int BindLengPtr = Marshal.ReadInt32(bind.length); + int bindBuffer = Marshal.ReadInt32(bind.buffer); + Console.WriteLine("bind.buffer_type:{0},bufferType:{1}", bind.buffer_type, bufferType); + + Assert.Equal(bind.buffer_type, bufferType); + Assert.Equal(bindBuffer, buffer); + Assert.Equal(bind.buffer_length, bufferLength); + Assert.Equal(BindLengPtr, length); + + Marshal.FreeHGlobal(bind.buffer); + Marshal.FreeHGlobal(bind.length); + } + + [Fact] + public void TestBindIntPositive() + { + + int bufferType = 4; + int buffer = int.MaxValue; + int bufferLength = sizeof(int); + int length = sizeof(int); + + TDengineDriver.TAOS_BIND bind = TaosBind.BindInt(int.MaxValue); + int BindLengPtr = Marshal.ReadInt32(bind.length); + int bindBuffer = Marshal.ReadInt32(bind.buffer); + Console.WriteLine("bind.buffer_type:{0},bufferType:{1}", bind.buffer_type, bufferType); + + Assert.Equal(bind.buffer_type, bufferType); + Assert.Equal(bindBuffer, buffer); + Assert.Equal(bind.buffer_length, bufferLength); + Assert.Equal(BindLengPtr, length); + + Marshal.FreeHGlobal(bind.buffer); + Marshal.FreeHGlobal(bind.length); + } + + [Fact] + public void TestBindBigIntNegative() + { + + int bufferType = 5; + long buffer = long.MinValue; + int bufferLength = sizeof(long); + int length = sizeof(long); + + TDengineDriver.TAOS_BIND bind = TaosBind.BindBigInt(long.MinValue); + int BindLengPtr = Marshal.ReadInt32(bind.length); + long bindBuffer = Marshal.ReadInt64(bind.buffer); + Console.WriteLine("bind.buffer_type:{0},bufferType:{1}", bind.buffer_type, bufferType); + + Assert.Equal(bind.buffer_type, bufferType); + Assert.Equal(bindBuffer, buffer); + Assert.Equal(bind.buffer_length, bufferLength); + Assert.Equal(BindLengPtr, length); + + Marshal.FreeHGlobal(bind.buffer); + Marshal.FreeHGlobal(bind.length); + } + [Fact] + public void TestBindBigIntZero() + { + + int bufferType = 5; + long buffer = 0; + int bufferLength = sizeof(long); + int length = sizeof(long); + + TDengineDriver.TAOS_BIND bind = TaosBind.BindBigInt(0); + int BindLengPtr = Marshal.ReadInt32(bind.length); + long bindBuffer = Marshal.ReadInt64(bind.buffer); + Console.WriteLine("bind.buffer_type:{0},bufferType:{1}", bind.buffer_type, bufferType); + + Assert.Equal(bind.buffer_type, bufferType); + Assert.Equal(bindBuffer, buffer); + Assert.Equal(bind.buffer_length, bufferLength); + Assert.Equal(BindLengPtr, length); + + Marshal.FreeHGlobal(bind.buffer); + Marshal.FreeHGlobal(bind.length); + } + + [Fact] + public void TestBindBigIntPositive() + { + + int bufferType = 5; + long buffer = long.MaxValue; + int bufferLength = sizeof(long); + int length = sizeof(long); + + TDengineDriver.TAOS_BIND bind = TaosBind.BindBigInt(long.MaxValue); + int BindLengPtr = Marshal.ReadInt32(bind.length); + long bindBuffer = Marshal.ReadInt64(bind.buffer); + Console.WriteLine("bind.buffer_type:{0},bufferType:{1}", bind.buffer_type, bufferType); + + Assert.Equal(bind.buffer_type, bufferType); + Assert.Equal(bindBuffer, buffer); + Assert.Equal(bind.buffer_length, bufferLength); + Assert.Equal(BindLengPtr, length); + + Marshal.FreeHGlobal(bind.buffer); + Marshal.FreeHGlobal(bind.length); + } + + [Fact] + public void TestBindUTinyZero() + { + + + int bufferType = 11; + byte buffer = 0; + int bufferLength = sizeof(sbyte); + int length = sizeof(sbyte); + + TDengineDriver.TAOS_BIND bind = TaosBind.BindUTinyInt(0); + int BindLengPtr = Marshal.ReadInt32(bind.length); + byte bindBuffer = Marshal.ReadByte(bind.buffer); + Console.WriteLine("bind.buffer_type:{0},bufferType:{1}", bind.buffer_type, bufferType); + + Assert.Equal(bind.buffer_type, bufferType); + Assert.Equal(bindBuffer, buffer); + Assert.Equal(bind.buffer_length, bufferLength); + Assert.Equal(BindLengPtr, length); + + Marshal.FreeHGlobal(bind.buffer); + Marshal.FreeHGlobal(bind.length); + } + + [Fact] + public void TestBindUTinyPositive() + { + + + int bufferType = 11; + byte buffer = byte.MaxValue; + int bufferLength = sizeof(sbyte); + int length = sizeof(sbyte); + + TDengineDriver.TAOS_BIND bind = TaosBind.BindUTinyInt(byte.MaxValue); + int BindLengPtr = Marshal.ReadInt32(bind.length); + byte bindBuffer = Marshal.ReadByte(bind.buffer); + Console.WriteLine("bind.buffer_type:{0},bufferType:{1}", bind.buffer_type, bufferType); + + Assert.Equal(bind.buffer_type, bufferType); + Assert.Equal(bindBuffer, buffer); + Assert.Equal(bind.buffer_length, bufferLength); + Assert.Equal(BindLengPtr, length); + + Marshal.FreeHGlobal(bind.buffer); + Marshal.FreeHGlobal(bind.length); + } + + [Fact] + public void TestBindUSmallIntZero() + { + + int bufferType = 12; + ushort buffer = ushort.MinValue; + int bufferLength = sizeof(ushort); + int length = sizeof(ushort); + + TDengineDriver.TAOS_BIND bind = TaosBind.BindUSmallInt(ushort.MinValue); + int BindLengPtr = Marshal.ReadInt32(bind.length); + ushort bindBuffer = (ushort)Marshal.ReadInt16(bind.buffer); + Console.WriteLine("bind.buffer_type:{0},bufferType:{1}", bind.buffer_type, bufferType); + + Assert.Equal(bind.buffer_type, bufferType); + Assert.Equal(bindBuffer, buffer); + Assert.Equal(bind.buffer_length, bufferLength); + Assert.Equal(BindLengPtr, length); + + Marshal.FreeHGlobal(bind.buffer); + Marshal.FreeHGlobal(bind.length); + } + [Fact] + public void TestBindUSmallIntPositive() + { + + int bufferType = 12; + ushort buffer = ushort.MaxValue; + int bufferLength = sizeof(ushort); + int length = sizeof(ushort); + + TDengineDriver.TAOS_BIND bind = TaosBind.BindUSmallInt(ushort.MaxValue); + int BindLengPtr = Marshal.ReadInt32(bind.length); + ushort bindBuffer = (ushort)Marshal.ReadInt16(bind.buffer); + Console.WriteLine("bind.buffer_type:{0},bufferType:{1}", bind.buffer_type, bufferType); + + Assert.Equal(bind.buffer_type, bufferType); + Assert.Equal(bindBuffer, buffer); + Assert.Equal(bind.buffer_length, bufferLength); + Assert.Equal(BindLengPtr, length); + + Marshal.FreeHGlobal(bind.buffer); + Marshal.FreeHGlobal(bind.length); + } + + [Fact] + public void TestBindUIntZero() + { + int bufferType = 13; + uint buffer = uint.MinValue; + int bufferLength = sizeof(uint); + int length = sizeof(uint); + + TDengineDriver.TAOS_BIND bind = TaosBind.BindUInt(uint.MinValue); + int BindLengPtr = Marshal.ReadInt32(bind.length); + uint bindBuffer = (uint)Marshal.ReadInt32(bind.buffer); + Console.WriteLine("bind.buffer_type:{0},bufferType:{1}", bind.buffer_type, bufferType); + + Assert.Equal(bind.buffer_type, bufferType); + Assert.Equal(bindBuffer, buffer); + Assert.Equal(bind.buffer_length, bufferLength); + Assert.Equal(BindLengPtr, length); + + Marshal.FreeHGlobal(bind.buffer); + Marshal.FreeHGlobal(bind.length); + } + + [Fact] + public void TestBindUIntPositive() + { + int bufferType = 13; + uint buffer = uint.MaxValue; + int bufferLength = sizeof(uint); + int length = sizeof(uint); + + TDengineDriver.TAOS_BIND bind = TaosBind.BindUInt(uint.MaxValue); + int BindLengPtr = Marshal.ReadInt32(bind.length); + uint bindBuffer = (uint)Marshal.ReadInt32(bind.buffer); + Console.WriteLine("bind.buffer_type:{0},bufferType:{1}", bind.buffer_type, bufferType); + + Assert.Equal(bind.buffer_type, bufferType); + Assert.Equal(bindBuffer, buffer); + Assert.Equal(bind.buffer_length, bufferLength); + Assert.Equal(BindLengPtr, length); + + Marshal.FreeHGlobal(bind.buffer); + Marshal.FreeHGlobal(bind.length); + } + + [Fact] + public void TestBindUBigIntZero() + { + int bufferType = 14; + ulong buffer = ulong.MinValue; + int bufferLength = sizeof(ulong); + int length = sizeof(ulong); + + TDengineDriver.TAOS_BIND bind = TaosBind.BindUBigInt(ulong.MinValue); + int BindLengPtr = Marshal.ReadInt32(bind.length); + ulong bindBuffer = (ulong)Marshal.ReadInt64(bind.buffer); + Console.WriteLine("bind.buffer_type:{0},bufferType:{1}", bind.buffer_type, bufferType); + + Assert.Equal(bind.buffer_type, bufferType); + Assert.Equal(bindBuffer, buffer); + Assert.Equal(bind.buffer_length, bufferLength); + Assert.Equal(BindLengPtr, length); + + Marshal.FreeHGlobal(bind.buffer); + Marshal.FreeHGlobal(bind.length); + } + + [Fact] + public void TestBindUBigIntPositive() + { + int bufferType = 14; + ulong buffer = ulong.MaxValue; + int bufferLength = sizeof(ulong); + int length = sizeof(ulong); + + TDengineDriver.TAOS_BIND bind = TaosBind.BindUBigInt(ulong.MaxValue); + int BindLengPtr = Marshal.ReadInt32(bind.length); + ulong bindBuffer = (ulong)Marshal.ReadInt64(bind.buffer); + Console.WriteLine("bind.buffer_type:{0},bufferType:{1}", bind.buffer_type, bufferType); + + Assert.Equal(bind.buffer_type, bufferType); + Assert.Equal(bindBuffer, buffer); + Assert.Equal(bind.buffer_length, bufferLength); + Assert.Equal(BindLengPtr, length); + + Marshal.FreeHGlobal(bind.buffer); + Marshal.FreeHGlobal(bind.length); + } + + [Fact] + public void TestBindFloatNegative() + { + int bufferType = 6; + float buffer = float.MinValue; + int bufferLength = sizeof(float); + int length = sizeof(float); + + TDengineDriver.TAOS_BIND bind = TaosBind.BindFloat(float.MinValue); + int BindLengPtr = Marshal.ReadInt32(bind.length); + float[] bindBufferArr = new float[1]; + Marshal.Copy(bind.buffer, bindBufferArr, 0, bindBufferArr.Length); + Console.WriteLine("bind.buffer_type:{0},bufferType:{1}", bind.buffer_type, bufferType); + + Assert.Equal(bind.buffer_type, bufferType); + Assert.Equal(bindBufferArr[0], buffer); + Assert.Equal(bind.buffer_length, bufferLength); + Assert.Equal(BindLengPtr, length); + + Marshal.FreeHGlobal(bind.buffer); + Marshal.FreeHGlobal(bind.length); + } + + [Fact] + public void TestBindFloatZero() + { + int bufferType = 6; + float buffer = 0; + int bufferLength = sizeof(float); + int length = sizeof(float); + + TDengineDriver.TAOS_BIND bind = TaosBind.BindFloat(0F); + int BindLengPtr = Marshal.ReadInt32(bind.length); + float[] bindBufferArr = new float[1]; + Marshal.Copy(bind.buffer, bindBufferArr, 0, bindBufferArr.Length); + Console.WriteLine("bind.buffer_type:{0},bufferType:{1}", bind.buffer_type, bufferType); + + Assert.Equal(bind.buffer_type, bufferType); + Assert.Equal(bindBufferArr[0], buffer); + Assert.Equal(bind.buffer_length, bufferLength); + Assert.Equal(BindLengPtr, length); + + Marshal.FreeHGlobal(bind.buffer); + Marshal.FreeHGlobal(bind.length); + } + + [Fact] + public void TestBindFloatPositive() + { + int bufferType = 6; + float buffer = float.MaxValue; + int bufferLength = sizeof(float); + int length = sizeof(float); + + TDengineDriver.TAOS_BIND bind = TaosBind.BindFloat(float.MaxValue); + int BindLengPtr = Marshal.ReadInt32(bind.length); + float[] bindBufferArr = new float[1]; + Marshal.Copy(bind.buffer, bindBufferArr, 0, bindBufferArr.Length); + Console.WriteLine("bind.buffer_type:{0},bufferType:{1}", bind.buffer_type, bufferType); + + Assert.Equal(bind.buffer_type, bufferType); + Assert.Equal(bindBufferArr[0], buffer); + Assert.Equal(bind.buffer_length, bufferLength); + Assert.Equal(BindLengPtr, length); + + Marshal.FreeHGlobal(bind.buffer); + Marshal.FreeHGlobal(bind.length); + } + + [Fact] + public void TestBindDoubleZero() + { + int bufferType = 7; + double buffer = 0; + int bufferLength = sizeof(double); + int length = sizeof(double); + + TDengineDriver.TAOS_BIND bind = TaosBind.BindDouble(0D); + int BindLengPtr = Marshal.ReadInt32(bind.length); + double[] bindBufferArr = new double[1]; + Marshal.Copy(bind.buffer, bindBufferArr, 0, bindBufferArr.Length); + Console.WriteLine("bind.buffer_type:{0},bufferType:{1}", bind.buffer_type, bufferType); + + Assert.Equal(bind.buffer_type, bufferType); + Assert.Equal(bindBufferArr[0], buffer); + Assert.Equal(bind.buffer_length, bufferLength); + Assert.Equal(BindLengPtr, length); + + Marshal.FreeHGlobal(bind.buffer); + Marshal.FreeHGlobal(bind.length); + } + + [Fact] + public void TestBindDoublePositive() + { + int bufferType = 7; + double buffer = double.MaxValue; + int bufferLength = sizeof(double); + int length = sizeof(double); + + TDengineDriver.TAOS_BIND bind = TaosBind.BindDouble(double.MaxValue); + int BindLengPtr = Marshal.ReadInt32(bind.length); + double[] bindBufferArr = new double[1]; + Marshal.Copy(bind.buffer, bindBufferArr, 0, bindBufferArr.Length); + Console.WriteLine("bind.buffer_type:{0},bufferType:{1}", bind.buffer_type, bufferType); + + Assert.Equal(bind.buffer_type, bufferType); + Assert.Equal(bindBufferArr[0], buffer); + Assert.Equal(bind.buffer_length, bufferLength); + Assert.Equal(BindLengPtr, length); + + Marshal.FreeHGlobal(bind.buffer); + Marshal.FreeHGlobal(bind.length); + } + + [Fact] + public void TestBindDoubleNegative() + { + int bufferType = 7; + double buffer = double.MinValue; + int bufferLength = sizeof(double); + int length = sizeof(double); + + TDengineDriver.TAOS_BIND bind = TaosBind.BindDouble(double.MinValue); + int BindLengPtr = Marshal.ReadInt32(bind.length); + double[] bindBufferArr = new double[1]; + Marshal.Copy(bind.buffer, bindBufferArr, 0, bindBufferArr.Length); + Console.WriteLine("bind.buffer_type:{0},bufferType:{1}", bind.buffer_type, bufferType); + + Assert.Equal(bind.buffer_type, bufferType); + Assert.Equal(bindBufferArr[0], buffer); + Assert.Equal(bind.buffer_length, bufferLength); + Assert.Equal(BindLengPtr, length); + + Marshal.FreeHGlobal(bind.buffer); + Marshal.FreeHGlobal(bind.length); + } + + [Fact] + public void TestBindBinaryEn() + { + int bufferType = 8; + String buffer = "qwertyuiopasdghjklzxcvbnm<>?:\"{}+_)(*&^%$#@!~QWERTYUIOP[]\\ASDFGHJKL;'ZXCVBNM,./`1234567890-="; + int bufferLength = buffer.Length; + int length = buffer.Length; + + TDengineDriver.TAOS_BIND bind = TaosBind.BindBinary("qwertyuiopasdghjklzxcvbnm<>?:\"{}+_)(*&^%$#@!~QWERTYUIOP[]\\ASDFGHJKL;'ZXCVBNM,./`1234567890-="); + int BindLengPtr = Marshal.ReadInt32(bind.length); + string bindBuffer = Marshal.PtrToStringAnsi(bind.buffer); + Console.WriteLine("bind.buffer_type:{0},bufferType:{1}", bind.buffer_type, bufferType); + + Assert.Equal(bind.buffer_type, bufferType); + Assert.Equal(bindBuffer, buffer); + Assert.Equal(bind.buffer_length, bufferLength); + Assert.Equal(BindLengPtr, length); + + Marshal.FreeHGlobal(bind.buffer); + Marshal.FreeHGlobal(bind.length); + } + + [Fact] + public void TestBindBinaryCn() + { + int bufferType = 8; + String buffer = "一二两三四五六七八九十廿毛另壹贰叁肆伍陆柒捌玖拾佰仟万亿元角分零整1234567890`~!@#$%^&*()_+[]{};':<>?,./"; + int bufferLength = buffer.Length; + int length = buffer.Length; + + TDengineDriver.TAOS_BIND bind = TaosBind.BindBinary("一二两三四五六七八九十廿毛另壹贰叁肆伍陆柒捌玖拾佰仟万亿元角分零整1234567890`~!@#$%^&*()_+[]{};':<>?,./"); + int BindLengPtr = Marshal.ReadInt32(bind.length); + string bindBuffer = Marshal.PtrToStringAnsi(bind.buffer); + Console.WriteLine("bind.buffer_type:{0},bufferType:{1}", bind.buffer_type, bufferType); + + Assert.Equal(bind.buffer_type, bufferType); + Assert.Equal(bindBuffer, buffer); + Assert.Equal(bind.buffer_length, bufferLength); + Assert.Equal(BindLengPtr, length); + + Marshal.FreeHGlobal(bind.buffer); + Marshal.FreeHGlobal(bind.length); + } + + [Fact] + public void TestBindBinaryCnAndEn() + { + int bufferType = 8; + String buffer = "一二两三四五六七八九十廿毛另壹贰叁肆伍陆柒捌玖拾佰仟万亿元角分零整1234567890`~!@#$%^&*()_+[]{};':<>?,./qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM"; + int bufferLength = buffer.Length; + int length = buffer.Length; + + TDengineDriver.TAOS_BIND bind = TaosBind.BindBinary("一二两三四五六七八九十廿毛另壹贰叁肆伍陆柒捌玖拾佰仟万亿元角分零整1234567890`~!@#$%^&*()_+[]{};':<>?,./qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM"); + int BindLengPtr = Marshal.ReadInt32(bind.length); + string bindBuffer = Marshal.PtrToStringAnsi(bind.buffer); + Console.WriteLine("bind.buffer_type:{0},bufferType:{1}", bind.buffer_type, bufferType); + + Assert.Equal(bind.buffer_type, bufferType); + Assert.Equal(bindBuffer, buffer); + Assert.Equal(bind.buffer_length, bufferLength); + Assert.Equal(BindLengPtr, length); + + Marshal.FreeHGlobal(bind.buffer); + Marshal.FreeHGlobal(bind.length); + } + + [Fact] + public void TestBindNcharEn() + { + int bufferType = 10; + String buffer = "qwertyuiopasdghjklzxcvbnm<>?:\"{}+_)(*&^%$#@!~QWERTYUIOP[]\\ASDFGHJKL;'ZXCVBNM,./`1234567890-="; + int bufferLength = buffer.Length; + int length = buffer.Length; + + TDengineDriver.TAOS_BIND bind = TaosBind.BindNchar("qwertyuiopasdghjklzxcvbnm<>?:\"{}+_)(*&^%$#@!~QWERTYUIOP[]\\ASDFGHJKL;'ZXCVBNM,./`1234567890-="); + int BindLengPtr = Marshal.ReadInt32(bind.length); + string bindBuffer = Marshal.PtrToStringAnsi(bind.buffer); + Console.WriteLine("bind.buffer_type:{0},bufferType:{1}", bind.buffer_type, bufferType); + + Assert.Equal(bind.buffer_type, bufferType); + Assert.Equal(bindBuffer, buffer); + Assert.Equal(bind.buffer_length, bufferLength); + Assert.Equal(BindLengPtr, length); + + Marshal.FreeHGlobal(bind.buffer); + Marshal.FreeHGlobal(bind.length); + } + [Fact] + public void TestBindNcharCn() + { + int bufferType = 10; + String buffer = "一二两三四五六七八九十廿毛另壹贰叁肆伍陆柒捌玖拾佰仟万亿元角分零整1234567890`~!@#$%^&*()_+[]{};':<>?,./"; + int bufferLength = buffer.Length; + int length = buffer.Length; + + TDengineDriver.TAOS_BIND bind = TaosBind.BindNchar("一二两三四五六七八九十廿毛另壹贰叁肆伍陆柒捌玖拾佰仟万亿元角分零整1234567890`~!@#$%^&*()_+[]{};':<>?,./"); + int BindLengPtr = Marshal.ReadInt32(bind.length); + string bindBuffer = Marshal.PtrToStringAnsi(bind.buffer); + Console.WriteLine("bind.buffer_type:{0},bufferType:{1}", bind.buffer_type, bufferType); + + Assert.Equal(bind.buffer_type, bufferType); + Assert.Equal(bindBuffer, buffer); + Assert.Equal(bind.buffer_length, bufferLength); + Assert.Equal(BindLengPtr, length); + + Marshal.FreeHGlobal(bind.buffer); + Marshal.FreeHGlobal(bind.length); + } + [Fact] + public void TestBindNcharCnAndEn() + { + int bufferType = 10; + String buffer = "一二两三四五六七八九十廿毛另壹贰叁肆伍陆柒捌玖拾佰仟万亿元角分零整1234567890`~!@#$%^&*()_+[]{};':<>?,./qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM"; + int bufferLength = buffer.Length; + int length = buffer.Length; + + TDengineDriver.TAOS_BIND bind = TaosBind.BindNchar("一二两三四五六七八九十廿毛另壹贰叁肆伍陆柒捌玖拾佰仟万亿元角分零整1234567890`~!@#$%^&*()_+[]{};':<>?,./qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM"); + int BindLengPtr = Marshal.ReadInt32(bind.length); + string bindBuffer = Marshal.PtrToStringAnsi(bind.buffer); + Console.WriteLine("bind.buffer_type:{0},bufferType:{1}", bind.buffer_type, bufferType); + + Assert.Equal(bind.buffer_type, bufferType); + Assert.Equal(bindBuffer, buffer); + Assert.Equal(bind.buffer_length, bufferLength); + Assert.Equal(BindLengPtr, length); + + Marshal.FreeHGlobal(bind.buffer); + Marshal.FreeHGlobal(bind.length); + } + + [Fact] + public void TestBindNil() + { + int bufferType = 0; + int isNull = 1; + + TDengineDriver.TAOS_BIND bind = TaosBind.BindNil(); + + int bindIsNull = Marshal.ReadInt32(bind.is_null); + Console.WriteLine("bind.buffer_type:{0},bufferType:{1}", bind.buffer_type, bufferType); + + Assert.Equal(bind.buffer_type, bufferType); + Assert.Equal(bindIsNull, isNull); + + Marshal.FreeHGlobal(bind.buffer); + Marshal.FreeHGlobal(bind.length); + } + + [Fact] + public void TestBindTimestampNegative() + { + int bufferType = 9; + long buffer = long.MinValue; + int bufferLength = sizeof(long); + int length = sizeof(long); + + TDengineDriver.TAOS_BIND bind = TaosBind.BindTimestamp(long.MinValue); + int BindLengPtr = Marshal.ReadInt32(bind.length); + long bindBuffer = Marshal.ReadInt64(bind.buffer); + Console.WriteLine("bind.buffer_type:{0},bufferType:{1}", bind.buffer_type, bufferType); + + Assert.Equal(bind.buffer_type, bufferType); + Assert.Equal(bindBuffer, buffer); + Assert.Equal(bind.buffer_length, bufferLength); + Assert.Equal(BindLengPtr, length); + + Marshal.FreeHGlobal(bind.buffer); + Marshal.FreeHGlobal(bind.length); + } + [Fact] + public void TestBindTimestampZero() + { + int bufferType = 9; + long buffer = 0; + int bufferLength = sizeof(long); + int length = sizeof(long); + + TDengineDriver.TAOS_BIND bind = TaosBind.BindTimestamp(0); + int BindLengPtr = Marshal.ReadInt32(bind.length); + long bindBuffer = Marshal.ReadInt64(bind.buffer); + Console.WriteLine("bind.buffer_type:{0},bufferType:{1}", bind.buffer_type, bufferType); + + Assert.Equal(bind.buffer_type, bufferType); + Assert.Equal(bindBuffer, buffer); + Assert.Equal(bind.buffer_length, bufferLength); + Assert.Equal(BindLengPtr, length); + + Marshal.FreeHGlobal(bind.buffer); + Marshal.FreeHGlobal(bind.length); + } + [Fact] + public void TestBindTimestampPositive() + { + int bufferType = 9; + long buffer = long.MaxValue; + int bufferLength = sizeof(long); + int length = sizeof(long); + + TDengineDriver.TAOS_BIND bind = TaosBind.BindTimestamp(long.MaxValue); + int BindLengPtr = Marshal.ReadInt32(bind.length); + long bindBuffer = Marshal.ReadInt64(bind.buffer); + Console.WriteLine("bind.buffer_type:{0},bufferType:{1}", bind.buffer_type, bufferType); + + Assert.Equal(bind.buffer_type, bufferType); + Assert.Equal(bindBuffer, buffer); + Assert.Equal(bind.buffer_length, bufferLength); + Assert.Equal(BindLengPtr, length); + + Marshal.FreeHGlobal(bind.buffer); + Marshal.FreeHGlobal(bind.length); + } + + } +} \ No newline at end of file diff --git a/src/connector/C#/src/test/XUnitTest/XUnitTest.csproj b/src/connector/C#/src/test/XUnitTest/XUnitTest.csproj new file mode 100644 index 0000000000000000000000000000000000000000..97d13e5e9e74abada2efa27d64e57adbe5459023 --- /dev/null +++ b/src/connector/C#/src/test/XUnitTest/XUnitTest.csproj @@ -0,0 +1,30 @@ + + + + net5.0 + + false + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + + + + + + diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/AbstractResultSet.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/AbstractResultSet.java index e17548055c792e900a1e2fb5b510de8bf65de7a7..07553d7ef4e1ea0745d25523d0fd1612086c3826 100644 --- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/AbstractResultSet.java +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/AbstractResultSet.java @@ -11,6 +11,11 @@ import java.util.Map; public abstract class AbstractResultSet extends WrapperImpl implements ResultSet { private int fetchSize; protected boolean wasNull; + protected int timestampPrecision; + + public void setTimestampPrecision(int timestampPrecision) { + this.timestampPrecision = timestampPrecision; + } protected void checkAvailability(int columnIndex, int bounds) throws SQLException { if (isClosed()) diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBResultSet.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBResultSet.java index 3814186f779203741001943efe47b85c0be83acb..003324d27a57c3557f0bb3205fcee208aa776ed5 100644 --- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBResultSet.java +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBResultSet.java @@ -74,9 +74,8 @@ public class TSDBResultSet extends AbstractResultSet implements ResultSet { public boolean next() throws SQLException { if (this.getBatchFetch()) { - if (this.blockData.forward()) { + if (this.blockData.forward()) return true; - } int code = this.jniConnector.fetchBlock(this.resultSetPointer, this.blockData); this.blockData.reset(); @@ -214,7 +213,18 @@ public class TSDBResultSet extends AbstractResultSet implements ResultSet { if (!lastWasNull) { Object value = this.rowData.getObject(columnIndex); if (value instanceof Timestamp) { - res = ((Timestamp) value).getTime(); + Timestamp ts = (Timestamp) value; + long epochSec = ts.getTime() / 1000; + long nanoAdjustment = ts.getNanos(); + switch (this.timestampPrecision) { + case 0: + default: // ms + return ts.getTime(); + case 1: // us + return epochSec * 1000_000L + nanoAdjustment / 1000L; + case 2: // ns + return epochSec * 1000_000_000L + nanoAdjustment; + } } else { int nativeType = this.columnMetaDataList.get(columnIndex - 1).getColType(); res = this.rowData.getLong(columnIndex, nativeType); diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBStatement.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBStatement.java index 2c77df2981e18931d6cb56cca84bb2115716b349..ce877987e6e9073defbff62e283910ee34366c4d 100644 --- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBStatement.java +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBStatement.java @@ -47,6 +47,8 @@ public class TSDBStatement extends AbstractStatement { throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_INVALID_WITH_EXECUTEQUERY); } TSDBResultSet res = new TSDBResultSet(this, this.connection.getConnector(), pSql); + int timestampPrecision = this.connection.getConnector().getResultTimePrecision(pSql); + res.setTimestampPrecision(timestampPrecision); res.setBatchFetch(this.connection.getBatchFetch()); return res; } diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/enums/TimestampPrecision.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/enums/TimestampPrecision.java index 79350076c7f4b31743ab9fb61226e506186f0f17..4558dfa84bfccacf9f0d4fa2d7991c8bd0546b30 100644 --- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/enums/TimestampPrecision.java +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/enums/TimestampPrecision.java @@ -1,8 +1,7 @@ package com.taosdata.jdbc.enums; -public enum TimestampPrecision { - MS, - US, - NS, - UNKNOWN +public class TimestampPrecision { + public static final int MS = 0; + public static final int US = 1; + public static final int NS = 2; } diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulResultSet.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulResultSet.java index f3e3f138df8fc854817c0adf57c5f5453f52bf05..d4c30115f851aa0f8b6f80994bbece609649428d 100644 --- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulResultSet.java +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulResultSet.java @@ -168,11 +168,22 @@ public class RestfulResultSet extends AbstractResultSet implements ResultSet { case TIMESTAMP: { Long value = row.getLong(colIndex); //TODO: this implementation has bug if the timestamp bigger than 9999_9999_9999_9 - if (value < 1_0000_0000_0000_0L) + if (value < 1_0000_0000_0000_0L) { + this.timestampPrecision = TimestampPrecision.MS; return new Timestamp(value); - long epochSec = value / 1000_000L; - long nanoAdjustment = value % 1000_000L * 1000L; - return Timestamp.from(Instant.ofEpochSecond(epochSec, nanoAdjustment)); + } + if (value >= 1_0000_0000_0000_0L && value < 1_000_000_000_000_000_0l) { + this.timestampPrecision = TimestampPrecision.US; + long epochSec = value / 1000_000L; + long nanoAdjustment = value % 1000_000L * 1000L; + return Timestamp.from(Instant.ofEpochSecond(epochSec, nanoAdjustment)); + } + if (value >= 1_000_000_000_000_000_0l) { + this.timestampPrecision = TimestampPrecision.NS; + long epochSec = value / 1000_000_000L; + long nanoAdjustment = value % 1000_000_000L; + return Timestamp.from(Instant.ofEpochSecond(epochSec, nanoAdjustment)); + } } case UTC: { String value = row.getString(colIndex); @@ -182,12 +193,15 @@ public class RestfulResultSet extends AbstractResultSet implements ResultSet { if (value.length() > 31) { // ns timestamp: yyyy-MM-ddTHH:mm:ss.SSSSSSSSS+0x00 nanoAdjustment = fractionalSec; + this.timestampPrecision = TimestampPrecision.NS; } else if (value.length() > 28) { // ms timestamp: yyyy-MM-ddTHH:mm:ss.SSSSSS+0x00 nanoAdjustment = fractionalSec * 1000L; + this.timestampPrecision = TimestampPrecision.US; } else { // ms timestamp: yyyy-MM-ddTHH:mm:ss.SSS+0x00 nanoAdjustment = fractionalSec * 1000_000L; + this.timestampPrecision = TimestampPrecision.MS; } ZoneOffset zoneOffset = ZoneOffset.of(value.substring(value.length() - 5)); Instant instant = Instant.ofEpochSecond(epochSec, nanoAdjustment).atOffset(zoneOffset).toInstant(); @@ -196,7 +210,9 @@ public class RestfulResultSet extends AbstractResultSet implements ResultSet { case STRING: default: { String value = row.getString(colIndex); - TimestampPrecision precision = Utils.guessTimestampPrecision(value); + int precision = Utils.guessTimestampPrecision(value); + this.timestampPrecision = precision; + if (precision == TimestampPrecision.MS) { // ms timestamp: yyyy-MM-dd HH:mm:ss.SSS return row.getTimestamp(colIndex); @@ -338,8 +354,18 @@ public class RestfulResultSet extends AbstractResultSet implements ResultSet { wasNull = value == null; if (value == null) return 0; - if (value instanceof Timestamp) - return ((Timestamp) value).getTime(); + if (value instanceof Timestamp) { + Timestamp ts = (Timestamp) value; + switch (this.timestampPrecision) { + case TimestampPrecision.MS: + default: + return ts.getTime(); + case TimestampPrecision.US: + return ts.getTime() * 1000 + ts.getNanos() / 1000 % 1000; + case TimestampPrecision.NS: + return ts.getTime() * 1000_000 + ts.getNanos() % 1000_000; + } + } long valueAsLong = 0; try { valueAsLong = Long.parseLong(value.toString()); diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/utils/Utils.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/utils/Utils.java index 6cd1ff7200962b7347969e0b8b10443083505912..6ec76fffd93751b0cb57e116085de9da550f214e 100644 --- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/utils/Utils.java +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/utils/Utils.java @@ -194,14 +194,14 @@ public class Utils { return timestamp.toLocalDateTime().format(milliSecFormatter); } - public static TimestampPrecision guessTimestampPrecision(String value) { + public static int guessTimestampPrecision(String value) { if (isMilliSecFormat(value)) return TimestampPrecision.MS; if (isMicroSecFormat(value)) return TimestampPrecision.US; if (isNanoSecFormat(value)) return TimestampPrecision.NS; - return TimestampPrecision.UNKNOWN; + return TimestampPrecision.MS; } private static boolean isMilliSecFormat(String timestampStr) { diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/GetLongWithDifferentTimestampPrecision.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/GetLongWithDifferentTimestampPrecision.java new file mode 100644 index 0000000000000000000000000000000000000000..1ba7bdc4057e5c9e2977d3723fe329e761e7258c --- /dev/null +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/GetLongWithDifferentTimestampPrecision.java @@ -0,0 +1,59 @@ +package com.taosdata.jdbc.cases; + +import org.junit.Assert; +import org.junit.Test; + +import java.sql.*; +import java.text.SimpleDateFormat; + +public class GetLongWithDifferentTimestampPrecision { + + private final String host = "127.0.0.1"; + + @Test + public void testRestful() throws SQLException { + // given + String url = "jdbc:TAOS-RS://" + host + ":6041/"; + Connection conn = DriverManager.getConnection(url, "root", "taosdata"); + long ts = System.currentTimeMillis(); + + // when and then + assertResultSet(conn, "ms", ts, ts); + assertResultSet(conn, "us", ts, ts * 1000); + assertResultSet(conn, "ns", ts, ts * 1000_000); + } + + @Test + public void testJni() throws SQLException { + // given + String url = "jdbc:TAOS://" + host + ":6030/"; + Connection conn = DriverManager.getConnection(url, "root", "taosdata"); + long ts = System.currentTimeMillis(); + + // when and then + assertResultSet(conn, "ms", ts, ts); + assertResultSet(conn, "us", ts, ts * 1000); + assertResultSet(conn, "ns", ts, ts * 1000_000); + } + + private void assertResultSet(Connection conn, String precision, long timestamp, long expect) throws SQLException { + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS"); + + try (Statement stmt = conn.createStatement()) { + stmt.execute("drop database if exists test"); + stmt.execute("create database if not exists test precision '" + precision + "'"); + stmt.execute("create table test.weather(ts timestamp, f1 int)"); + + String dateTimeStr = sdf.format(new Date(timestamp)); + stmt.execute("insert into test.weather values('" + dateTimeStr + "', 1)"); + + ResultSet rs = stmt.executeQuery("select * from test.weather"); + rs.next(); + long actual = rs.getLong("ts"); + Assert.assertEquals(expect, actual); + stmt.execute("drop database if exists test"); + } + } + + +} 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 5de1655ee48776b6798619814fe2729625282764..da30bbd568c7043af493baeecc118f256ad73b10 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 @@ -9,29 +9,29 @@ import java.util.Random; @FixMethodOrder(MethodSorters.NAME_ASCENDING) public class RestfulJDBCTest { - // private static final String host = "127.0.0.1"; - private static final String host = "master"; + private static final String host = "127.0.0.1"; private static final Random random = new Random(System.currentTimeMillis()); private static Connection connection; + private static final String dbname = "restful_test"; @Test public void testCase001() throws SQLException { // given - String sql = "drop database if exists restful_test"; + String sql = "drop database if exists " + dbname; // when boolean execute = execute(connection, sql); // then Assert.assertFalse(execute); // given - sql = "create database if not exists restful_test"; + sql = "create database if not exists " + dbname; // when execute = execute(connection, sql); // then Assert.assertFalse(execute); // given - sql = "use restful_test"; + sql = "use " + dbname; // when execute = execute(connection, sql); // then @@ -41,7 +41,7 @@ public class RestfulJDBCTest { @Test public void testCase002() throws SQLException { // given - String sql = "create table weather(ts timestamp, temperature float, humidity int) tags(location nchar(64), groupId int)"; + String sql = "create table " + dbname + ".weather(ts timestamp, temperature float, humidity int) tags(location nchar(64), groupId int)"; // when boolean execute = execute(connection, sql); // then @@ -52,7 +52,7 @@ public class RestfulJDBCTest { public void testCase004() throws SQLException { for (int i = 1; i <= 100; i++) { // given - String sql = "create table t" + i + " using weather tags('beijing', '" + i + "')"; + String sql = "create table " + dbname + ".t" + i + " using " + dbname + ".weather tags('beijing', '" + i + "')"; // when boolean execute = execute(connection, sql); // then @@ -68,7 +68,7 @@ public class RestfulJDBCTest { // given long currentTimeMillis = System.currentTimeMillis(); - String sql = "insert into t" + j + " values(" + currentTimeMillis + "," + (random.nextFloat() * 50) + "," + random.nextInt(100) + ")"; + String sql = "insert into " + dbname + ".t" + j + " values(" + currentTimeMillis + "," + (random.nextFloat() * 50) + "," + random.nextInt(100) + ")"; // when int affectRows = executeUpdate(connection, sql); // then @@ -83,7 +83,7 @@ public class RestfulJDBCTest { @Test public void testCase006() throws SQLException { // given - String sql = "select * from weather"; + String sql = "select * from " + dbname + ".weather"; // when ResultSet rs = executeQuery(connection, sql); ResultSetMetaData meta = rs.getMetaData(); @@ -102,7 +102,7 @@ public class RestfulJDBCTest { @Test public void testCase007() throws SQLException { // given - String sql = "drop database restful_test"; + String sql = "drop database " + dbname; // when boolean execute = execute(connection, sql); @@ -143,7 +143,7 @@ public class RestfulJDBCTest { public static void afterClass() throws SQLException { if (connection != null) { Statement stmt = connection.createStatement(); - stmt.execute("drop database if exists restful_test"); + stmt.execute("drop database if exists " + dbname); stmt.close(); connection.close(); } diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/RestfulResultSetTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/RestfulResultSetTest.java index 4058dd8b550b6e9ac5553144de92d908d804dce1..c1ca31ae388f577a33cc6f3a6bc943ce52112507 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/RestfulResultSetTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/RestfulResultSetTest.java @@ -17,12 +17,25 @@ import java.text.SimpleDateFormat; public class RestfulResultSetTest { - // private static final String host = "127.0.0.1"; - private static final String host = "master"; + private static final String host = "127.0.0.1"; private static Connection conn; private static Statement stmt; private static ResultSet rs; + @BeforeClass + public static void beforeClass() throws SQLException { + conn = DriverManager.getConnection("jdbc:TAOS-RS://" + host + ":6041/?user=root&password=taosdata"); + stmt = conn.createStatement(); + stmt.execute("drop database if exists restful_test"); + stmt.execute("create database if not exists restful_test"); + stmt.execute("use restful_test"); + stmt.execute("drop table if exists weather"); + stmt.execute("create table if not exists weather(f1 timestamp, f2 int, f3 bigint, f4 float, f5 double, f6 binary(64), f7 smallint, f8 tinyint, f9 bool, f10 nchar(64))"); + stmt.execute("insert into restful_test.weather values('2021-01-01 00:00:00.000', 1, 100, 3.1415, 3.1415926, 'abc', 10, 10, true, '涛思数据')"); + rs = stmt.executeQuery("select * from restful_test.weather"); + rs.next(); + } + @Test public void wasNull() throws SQLException { Assert.assertFalse(rs.wasNull()); @@ -658,20 +671,6 @@ public class RestfulResultSetTest { Assert.assertTrue(rs.isWrapperFor(RestfulResultSet.class)); } - @BeforeClass - public static void beforeClass() throws SQLException { - conn = DriverManager.getConnection("jdbc:TAOS-RS://" + host + ":6041/?user=root&password=taosdata"); - stmt = conn.createStatement(); - stmt.execute("drop database if exists restful_test"); - stmt.execute("create database if not exists restful_test"); - stmt.execute("use restful_test"); - stmt.execute("drop table if exists weather"); - stmt.execute("create table if not exists weather(f1 timestamp, f2 int, f3 bigint, f4 float, f5 double, f6 binary(64), f7 smallint, f8 tinyint, f9 bool, f10 nchar(64))"); - stmt.execute("insert into restful_test.weather values('2021-01-01 00:00:00.000', 1, 100, 3.1415, 3.1415926, 'abc', 10, 10, true, '涛思数据')"); - rs = stmt.executeQuery("select * from restful_test.weather"); - rs.next(); - } - @AfterClass public static void afterClass() throws SQLException { if (rs != null) diff --git a/src/connector/python/examples/subscribe-async.py b/src/connector/python/examples/subscribe-async.py index 3782ce5505152e78838406e313094eb911bea4a2..49156de7edfb4322d7888727c28b76868cf6a16a 100644 --- a/src/connector/python/examples/subscribe-async.py +++ b/src/connector/python/examples/subscribe-async.py @@ -7,7 +7,7 @@ import time def subscribe_callback(p_sub, p_result, p_param, errno): # type: (c_void_p, c_void_p, c_void_p, c_int) -> None print("# fetch in callback") - result = TaosResult(p_result) + result = TaosResult(c_void_p(p_result)) result.check_error(errno) for row in result.rows_iter(): ts, n = row() @@ -18,18 +18,21 @@ def test_subscribe_callback(conn): # type: (TaosConnection) -> None dbname = "pytest_taos_subscribe_callback" try: + print("drop if exists") conn.execute("drop database if exists %s" % dbname) + print("create database") conn.execute("create database if not exists %s" % dbname) - conn.select_db(dbname) - conn.execute("create table if not exists log(ts timestamp, n int)") + print("create table") + # conn.execute("use %s" % dbname) + conn.execute("create table if not exists %s.log(ts timestamp, n int)" % dbname) print("# subscribe with callback") - sub = conn.subscribe(False, "test", "select * from log", 1000, subscribe_callback) + sub = conn.subscribe(False, "test", "select * from %s.log" % dbname, 1000, subscribe_callback) for i in range(10): - conn.execute("insert into log values(now, %d)" % i) + conn.execute("insert into %s.log values(now, %d)" % (dbname, i)) time.sleep(0.7) - # sub.close() + sub.close() conn.execute("drop database if exists %s" % dbname) # conn.close() diff --git a/src/connector/python/taos/cinterface.py b/src/connector/python/taos/cinterface.py index 37bc90d4c63fe3f75b12d46bb1bf535441869938..740af5838235a6abc41ae27e7c6a462c30977616 100644 --- a/src/connector/python/taos/cinterface.py +++ b/src/connector/python/taos/cinterface.py @@ -110,7 +110,7 @@ _libtaos.taos_get_client_info.restype = c_char_p def taos_get_client_info(): # type: () -> str """Get client version info.""" - return _libtaos.taos_get_client_info().decode() + return _libtaos.taos_get_client_info().decode("utf-8") _libtaos.taos_get_server_info.restype = c_char_p @@ -120,7 +120,7 @@ _libtaos.taos_get_server_info.argtypes = (c_void_p,) def taos_get_server_info(connection): # type: (c_void_p) -> str """Get server version as string.""" - return _libtaos.taos_get_server_info(connection).decode() + return _libtaos.taos_get_server_info(connection).decode("utf-8") _libtaos.taos_close.restype = None @@ -308,16 +308,14 @@ def taos_subscribe(connection, restart, topic, sql, interval, callback=None, par """ if callback != None: callback = subscribe_callback_type(callback) - if param != None: - param = c_void_p(param) return c_void_p( _libtaos.taos_subscribe( connection, 1 if restart else 0, c_char_p(topic.encode("utf-8")), c_char_p(sql.encode("utf-8")), - callback or None, - param, + callback, + c_void_p(param), interval, ) ) diff --git a/src/connector/python/taos/field.py b/src/connector/python/taos/field.py index b0bec58b932f2136b868739bb28fca04de759e3f..f6fa28e8336fa53a137ce7bd9a25b99a32263f1b 100644 --- a/src/connector/python/taos/field.py +++ b/src/connector/python/taos/field.py @@ -144,7 +144,7 @@ def _crow_nchar_to_python(data, num_of_rows, nbytes=None, precision=FieldType.C_ try: if num_of_rows >= 0: tmpstr = ctypes.c_char_p(data) - res.append(tmpstr.value.decode()) + res.append(tmpstr.value.decode("utf-8")) else: res.append( ( @@ -172,7 +172,7 @@ def _crow_binary_to_python_block(data, num_of_rows, nbytes=None, precision=Field if rbyte == 1 and buffer[0] == b'\xff': res.append(None) else: - res.append(cast(buffer, c_char_p).value.decode()) + res.append(cast(buffer, c_char_p).value.decode("utf-8")) return res @@ -188,7 +188,7 @@ def _crow_nchar_to_python_block(data, num_of_rows, nbytes=None, precision=FieldT if rbyte == 4 and buffer[:4] == b'\xff'*4: res.append(None) else: - res.append(cast(buffer, c_char_p).value.decode()) + res.append(cast(buffer, c_char_p).value.decode("utf-8")) return res diff --git a/src/connector/python/taos/result.py b/src/connector/python/taos/result.py index c9feb4d6502515cc6e3e2d4be688f2e7fcd895b2..8b8a0cf108cf7c941d0a6476d8a9c1e2c5a41b84 100644 --- a/src/connector/python/taos/result.py +++ b/src/connector/python/taos/result.py @@ -3,6 +3,8 @@ from .cinterface import * # from .connection import TaosConnection from .error import * +from ctypes import c_void_p + class TaosResult(object): """TDengine result interface""" @@ -12,7 +14,11 @@ class TaosResult(object): # to make the __del__ order right self._conn = conn self._close_after = close_after - self._result = result + if isinstance(result, c_void_p): + self._result = result + else: + self._result = c_void_p(result) + self._fields = None self._field_count = None self._precision = None diff --git a/src/connector/python/tests/test_stream.py b/src/connector/python/tests/test_stream.py index de6e20928b176e51bc6d350fb01268459f4e7f95..32ec4c5999c975be907cf69a42a04b5f4dd5d54c 100644 --- a/src/connector/python/tests/test_stream.py +++ b/src/connector/python/tests/test_stream.py @@ -20,7 +20,8 @@ def stream_callback(p_param, p_result, p_row): result = TaosResult(p_result) row = TaosRow(result, p_row) try: - ts, count = row() + ts, count = row.as_tuple() + print(ts, count) p = cast(p_param, POINTER(Counter)) p.contents.count += count print("[%s] inserted %d in 5s, total count: %d" % (ts.strftime("%Y-%m-%d %H:%M:%S"), count, p.contents.count)) diff --git a/src/connector/python/tests/test_subscribe.py b/src/connector/python/tests/test_subscribe.py index 99fe5b263625c63200f416ec98fcb561773becd8..d8acd60e4f3b32bb87a9663b3f7dc43a73f2877b 100644 --- a/src/connector/python/tests/test_subscribe.py +++ b/src/connector/python/tests/test_subscribe.py @@ -63,7 +63,7 @@ def test_subscribe(conn): def subscribe_callback(p_sub, p_result, p_param, errno): # type: (c_void_p, c_void_p, c_void_p, c_int) -> None print("callback") - result = TaosResult(p_result) + result = TaosResult(c_void_p(p_result)) result.check_error(errno) for row in result.rows_iter(): ts, n = row() @@ -76,7 +76,7 @@ def test_subscribe_callback(conn): try: conn.execute("drop database if exists %s" % dbname) conn.execute("create database if not exists %s" % dbname) - conn.select_db(dbname) + conn.execute("use %s" % dbname) conn.execute("create table if not exists log(ts timestamp, n int)") print("# subscribe with callback") diff --git a/src/dnode/src/dnodeShell.c b/src/dnode/src/dnodeShell.c index f62e0c0df41f2fe399d0f4c1c8e661fcd0ef91b9..7676343b37d242c1d174a31959ea4be25a9d5af2 100644 --- a/src/dnode/src/dnodeShell.c +++ b/src/dnode/src/dnodeShell.c @@ -120,6 +120,14 @@ static void dnodeProcessMsgFromShell(SRpcMsg *pMsg, SRpcEpSet *pEpSet) { if (pMsg->pCont == NULL) return; + if (pMsg->msgType >= TSDB_MSG_TYPE_MAX) { + dError("RPC %p, shell msg type:%d is not processed", pMsg->handle, pMsg->msgType); + rpcMsg.code = TSDB_CODE_DND_MSG_NOT_PROCESSED; + rpcSendResponse(&rpcMsg); + rpcFreeCont(pMsg->pCont); + return; + } + SRunStatus dnodeStatus = dnodeGetRunStatus(); if (dnodeStatus == TSDB_RUN_STATUS_STOPPED) { dError("RPC %p, shell msg:%s is ignored since dnode exiting", pMsg->handle, taosMsg[pMsg->msgType]); diff --git a/src/inc/taosmsg.h b/src/inc/taosmsg.h index 84491e0a438fdb3b5dd2905acffaf32c76b23c9b..1db66f0387b02c3d02f50eef04110b23ce2d9e64 100644 --- a/src/inc/taosmsg.h +++ b/src/inc/taosmsg.h @@ -230,6 +230,7 @@ typedef struct SSubmitBlk { // Submit message for this TSDB typedef struct SSubmitMsg { SMsgHead header; + int8_t extend; int32_t length; int32_t numOfBlocks; char blocks[]; @@ -243,6 +244,7 @@ typedef struct { } SShellSubmitRspBlock; typedef struct { + int8_t extend; int32_t code; // 0-success, > 0 error code int32_t numOfRows; // number of records the client is trying to write int32_t affectedRows; // number of records actually written @@ -278,6 +280,7 @@ typedef struct { } SMDCreateTableMsg; typedef struct { + int8_t extend; int32_t len; // one create table message char tableName[TSDB_TABLE_FNAME_LEN]; int8_t igExists; @@ -290,11 +293,13 @@ typedef struct { } SCreateTableMsg; typedef struct { + int8_t extend; int32_t numOfTables; int32_t contLen; } SCMCreateTableMsg; typedef struct { + int8_t extend; char name[TSDB_TABLE_FNAME_LEN]; // if user specify DROP STABLE, this flag will be set. And an error will be returned if it is not a super table int8_t supertable; @@ -302,6 +307,7 @@ typedef struct { } SCMDropTableMsg; typedef struct { + int8_t extend; char tableFname[TSDB_TABLE_FNAME_LEN]; char db[TSDB_ACCT_ID_LEN + TSDB_DB_NAME_LEN]; int16_t type; /* operation type */ @@ -314,6 +320,7 @@ typedef struct { typedef struct { SMsgHead head; + int8_t extend; int64_t uid; int32_t tid; int16_t tversion; @@ -327,6 +334,7 @@ typedef struct { } SUpdateTableTagValMsg; typedef struct { + int8_t extend; char clientVersion[TSDB_VERSION_LEN]; char msgVersion[TSDB_VERSION_LEN]; char db[TSDB_TABLE_FNAME_LEN]; @@ -335,6 +343,7 @@ typedef struct { } SConnectMsg; typedef struct { + int8_t extend; char acctId[TSDB_ACCT_ID_LEN]; char serverVersion[TSDB_VERSION_LEN]; char clusterId[TSDB_CLUSTER_ID_LEN]; @@ -361,16 +370,19 @@ typedef struct { } SAcctCfg; typedef struct { + int8_t extend; char user[TSDB_USER_LEN]; char pass[TSDB_KEY_LEN]; SAcctCfg cfg; } SCreateAcctMsg, SAlterAcctMsg; typedef struct { - char user[TSDB_USER_LEN]; + int8_t extend; + char user[TSDB_USER_LEN]; } SDropUserMsg, SDropAcctMsg; typedef struct { + int8_t extend; char user[TSDB_USER_LEN]; char pass[TSDB_KEY_LEN]; int8_t privilege; @@ -462,6 +474,7 @@ typedef struct { typedef struct { SMsgHead head; + int8_t extend; char version[TSDB_VERSION_LEN]; bool stableQuery; // super table query or not @@ -514,6 +527,7 @@ typedef struct { } SQueryTableMsg; typedef struct { + int8_t extend; int32_t code; union{uint64_t qhandle; uint64_t qId;}; // query handle } SQueryTableRsp; @@ -521,11 +535,13 @@ typedef struct { // todo: the show handle should be replaced with id typedef struct { SMsgHead header; + int8_t extend; union{uint64_t qhandle; uint64_t qId;}; // query handle uint16_t free; } SRetrieveTableMsg; typedef struct SRetrieveTableRsp { + int8_t extend; int32_t numOfRows; int8_t completed; // all results are returned to client int16_t precision; @@ -551,6 +567,7 @@ typedef struct { } SVnodeLoad; typedef struct { + int8_t extend; char db[TSDB_ACCT_ID_LEN + TSDB_DB_NAME_LEN]; int32_t cacheBlockSize; //MB int32_t totalBlocks; @@ -577,6 +594,7 @@ typedef struct { } SCreateDbMsg, SAlterDbMsg; typedef struct { + int8_t extend; char name[TSDB_FUNC_NAME_LEN]; char path[PATH_MAX]; int32_t funcType; @@ -588,11 +606,13 @@ typedef struct { } SCreateFuncMsg; typedef struct { + int8_t extend; int32_t num; char name[]; } SRetrieveFuncMsg; typedef struct { + int8_t extend; char name[TSDB_FUNC_NAME_LEN]; int32_t funcType; int8_t resType; @@ -603,15 +623,18 @@ typedef struct { } SFunctionInfoMsg; typedef struct { + int8_t extend; int32_t num; char content[]; } SUdfFuncMsg; typedef struct { + int8_t extend; char name[TSDB_FUNC_NAME_LEN]; } SDropFuncMsg; typedef struct { + int8_t extend; char db[TSDB_TABLE_FNAME_LEN]; uint8_t ignoreNotExists; } SDropDbMsg, SUseDbMsg, SSyncDbMsg; @@ -744,12 +767,14 @@ typedef struct { } SCreateVnodeMsg, SAlterVnodeMsg; typedef struct { + int8_t extend; char tableFname[TSDB_TABLE_FNAME_LEN]; int16_t createFlag; char tags[]; } STableInfoMsg; typedef struct { + int8_t extend; uint8_t metaClone; // create local clone of the cached table meta int32_t numOfVgroups; int32_t numOfTables; @@ -758,21 +783,25 @@ typedef struct { } SMultiTableInfoMsg; typedef struct SSTableVgroupMsg { + int8_t extend; int32_t numOfTables; } SSTableVgroupMsg, SSTableVgroupRspMsg; typedef struct { + int8_t extend; int32_t vgId; int8_t numOfEps; SEpAddrMsg epAddr[TSDB_MAX_REPLICA]; } SVgroupMsg, SVgroupInfo; typedef struct { + int8_t extend; int32_t numOfVgroups; SVgroupMsg vgroups[]; } SVgroupsMsg, SVgroupsInfo; typedef struct STableMetaMsg { + int8_t extend; int32_t contLen; char tableFname[TSDB_TABLE_FNAME_LEN]; // table id uint8_t numOfTags; @@ -792,6 +821,7 @@ typedef struct STableMetaMsg { } STableMetaMsg; typedef struct SMultiTableMeta { + int8_t extend; int32_t numOfTables; int32_t numOfVgroup; int32_t numOfUdf; @@ -814,6 +844,7 @@ typedef struct { * payloadLen is the length of payload */ typedef struct { + int8_t extend; int8_t type; char db[TSDB_ACCT_ID_LEN + TSDB_DB_NAME_LEN]; uint16_t payloadLen; @@ -821,17 +852,20 @@ typedef struct { } SShowMsg; typedef struct { + int8_t extend; char db[TSDB_ACCT_ID_LEN + TSDB_DB_NAME_LEN]; int32_t numOfVgroup; int32_t vgid[]; } SCompactMsg; typedef struct SShowRsp { + int8_t extend; uint64_t qhandle; STableMetaMsg tableMeta; } SShowRsp; typedef struct { + int8_t extend; char ep[TSDB_EP_LEN]; // end point, hostname:port } SCreateDnodeMsg, SDropDnodeMsg; @@ -853,6 +887,7 @@ typedef struct { } SConfigVnodeMsg; typedef struct { + int8_t extend; char ep[TSDB_EP_LEN]; // end point, hostname:port char config[64]; } SCfgDnodeMsg; @@ -884,6 +919,7 @@ typedef struct { } SStreamDesc; typedef struct { + int8_t extend; char clientVer[TSDB_VERSION_LEN]; uint32_t connId; int32_t pid; @@ -894,6 +930,7 @@ typedef struct { } SHeartBeatMsg; typedef struct { + int8_t extend; uint32_t queryId; uint32_t streamId; uint32_t totalDnodes; @@ -904,10 +941,12 @@ typedef struct { } SHeartBeatRsp; typedef struct { + int8_t extend; char queryId[TSDB_KILL_MSG_LEN + 1]; } SKillQueryMsg, SKillStreamMsg, SKillConnMsg; typedef struct { + int8_t extend; int32_t vnode; int32_t sid; uint64_t uid; @@ -932,6 +971,16 @@ typedef struct { char reserved2[64]; } SStartupStep; +typedef struct { + int16_t type; + int32_t len; + char value[]; +} STLV; + +enum { + TLV_TYPE_DUMMY = 1, +}; + #pragma pack(pop) #ifdef __cplusplus diff --git a/src/kit/shell/src/shellCheck.c b/src/kit/shell/src/shellCheck.c index 5821281a036674e7a60edc2f63500822a358b1bc..43256719e125a712e6a52ddadaa9637498278092 100644 --- a/src/kit/shell/src/shellCheck.c +++ b/src/kit/shell/src/shellCheck.c @@ -36,6 +36,7 @@ typedef struct { int totalThreads; void * taos; char * db; + int code; } ShellThreadObj; static int32_t shellUseDb(TAOS *con, char *db) { @@ -112,10 +113,10 @@ static void *shellCheckThreadFp(void *arg) { int32_t end = (pThread->threadIndex + 1) * interval; if (start >= tbNum) return NULL; - if (end > tbNum) end = tbNum + 1; + if (end > tbNum) end = tbNum; char file[32] = {0}; - snprintf(file, 32, "tb%d.txt", pThread->threadIndex); + snprintf(file, 32, "tb%d.sql", pThread->threadIndex); FILE *fp = fopen(file, "w"); if (!fp) { @@ -123,16 +124,19 @@ static void *shellCheckThreadFp(void *arg) { return NULL; } + ASSERT(pThread->code != 0); + char sql[SHELL_SQL_LEN]; for (int32_t t = start; t < end; ++t) { char *tbname = tbNames[t]; if (tbname == NULL) break; - snprintf(sql, SHELL_SQL_LEN, "select * from %s limit 1", tbname); + snprintf(sql, SHELL_SQL_LEN, "select last_row(_c0) from %s;", tbname); TAOS_RES *pSql = taos_query(pThread->taos, sql); int32_t code = taos_errno(pSql); - if (code != 0) { + // -k: -1 means check all errors, while other non-zero values means check specific errors. + if ((code == pThread->code) || ((pThread->code == -1) && (code != 0))) { int32_t len = snprintf(sql, SHELL_SQL_LEN, "drop table %s.%s;\n", pThread->db, tbname); fwrite(sql, 1, len, fp); atomic_add_fetch_32(&errorNum, 1); @@ -161,6 +165,7 @@ static void shellRunCheckThreads(TAOS *con, SShellArguments *_args) { pThread->totalThreads = _args->threadNum; pThread->taos = con; pThread->db = _args->database; + pThread->code = _args->check; pthread_attr_init(&thattr); pthread_attr_setdetachstate(&thattr, PTHREAD_CREATE_JOINABLE); diff --git a/src/kit/taos-tools b/src/kit/taos-tools index b76b5a76756a5c6530ba1d418de51fd336ae23b1..75339c5192ae0bf8e14dad7604d1d913a29d6c9b 160000 --- a/src/kit/taos-tools +++ b/src/kit/taos-tools @@ -1 +1 @@ -Subproject commit b76b5a76756a5c6530ba1d418de51fd336ae23b1 +Subproject commit 75339c5192ae0bf8e14dad7604d1d913a29d6c9b diff --git a/src/mnode/src/mnodeTable.c b/src/mnode/src/mnodeTable.c index 960dab6a5bd74f5f49afa42cf3b1f3583d37ac84..9ba0afa90ee2f23573275baf3d11d4b7727c34cb 100644 --- a/src/mnode/src/mnodeTable.c +++ b/src/mnode/src/mnodeTable.c @@ -3092,7 +3092,7 @@ static int32_t mnodeProcessMultiTableMetaMsg(SMnodeMsg *pMsg) { // add the user-defined-function information for(int32_t i = 0; i < pInfo->numOfUdfs; ++i, ++t) { char buf[TSDB_FUNC_NAME_LEN] = {0}; - strcpy(buf, nameList[t]); + tstrncpy(buf, nameList[t], TSDB_FUNC_NAME_LEN); SFuncObj* pFuncObj = mnodeGetFunc(buf); if (pFuncObj == NULL) { diff --git a/src/os/src/detail/osSysinfo.c b/src/os/src/detail/osSysinfo.c index af8f2dcdaf1568ba5e10656aacb7d0958155dde2..0542407c3ba8e8d17c79f16ef0f3560e3bc10693 100644 --- a/src/os/src/detail/osSysinfo.c +++ b/src/os/src/detail/osSysinfo.c @@ -379,9 +379,9 @@ bool taosGetCardInfo(int64_t *bytes, int64_t *rbytes, int64_t *tbytes) { "%s %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64, nouse0, &o_rbytes, &rpackets, &nouse1, &nouse2, &nouse3, &nouse4, &nouse5, &nouse6, &o_tbytes, &tpackets); - if (rbytes) *rbytes = o_rbytes; - if (tbytes) *tbytes = o_tbytes; - if (bytes) *bytes += (o_rbytes + o_tbytes); + if (rbytes) *rbytes += o_rbytes; + if (tbytes) *tbytes += o_tbytes; + if (bytes) *bytes += (o_rbytes + o_tbytes); } tfree(line); diff --git a/src/plugins/http/src/httpServer.c b/src/plugins/http/src/httpServer.c index 7f350a6f1599ba857a4249f500ffcb59bd50985e..c00d8bdebdcead98943628a22d4b886a03532f15 100644 --- a/src/plugins/http/src/httpServer.c +++ b/src/plugins/http/src/httpServer.c @@ -409,6 +409,7 @@ static bool httpReadData(HttpContext *pContext) { continue; } else if (errno == EAGAIN || errno == EWOULDBLOCK) { httpDebug("context:%p, fd:%d, read from socket error:%d, wait another event", pContext, pContext->fd, errno); + httpReleaseContext(pContext/*, false */); return false; } else { httpError("context:%p, fd:%d, read from socket error:%d, close connect", pContext, pContext->fd, errno); diff --git a/src/query/src/qExecutor.c b/src/query/src/qExecutor.c index 251e210600198de0ba9aec34d322de6839a621b2..b83926414f39bec3ac2c3d1d94459d0f6d27ea37 100644 --- a/src/query/src/qExecutor.c +++ b/src/query/src/qExecutor.c @@ -137,7 +137,7 @@ do { \ uint64_t queryHandleId = 0; int32_t getMaximumIdleDurationSec() { - return tsShellActivityTimer * 2; + return tsShellActivityTimer * 10; } int64_t genQueryId(void) { int64_t uid = 0; @@ -8145,6 +8145,32 @@ int32_t convertQueryMsg(SQueryTableMsg *pQueryMsg, SQueryParam* param) { goto _cleanup; } + + +/* + //MSG EXTEND DEMO + if (pQueryMsg->extend) { + pMsg += pQueryMsg->sqlstrLen; + + STLV *tlv = NULL; + while (1) { + tlv = (STLV *)pMsg; + tlv->type = ntohs(tlv->type); + tlv->len = ntohl(tlv->len); + if (tlv->len > 0) { + *(int16_t *)tlv->value = ntohs(*(int16_t *)tlv->value); + qDebug("Got TLV,type:%d,len:%d,value:%d", tlv->type, tlv->len, *(int16_t*)tlv->value); + pMsg += sizeof(*tlv) + tlv->len; + continue; + } + + break; + } + } + +*/ + + qDebug("qmsg:%p query %d tables, type:%d, qrange:%" PRId64 "-%" PRId64 ", numOfGroupbyTagCols:%d, order:%d, " "outputCols:%d, numOfCols:%d, interval:%" PRId64 ", fillType:%d, comptsLen:%d, compNumOfBlocks:%d, limit:%" PRId64 ", offset:%" PRId64, pQueryMsg, pQueryMsg->numOfTables, pQueryMsg->queryType, pQueryMsg->window.skey, pQueryMsg->window.ekey, pQueryMsg->numOfGroupCols, diff --git a/src/query/src/queryMain.c b/src/query/src/queryMain.c index fce7f649892f87d075c8dd64e4d1160e5d05bf77..2a2ccf9cae0f9e2aab60bddca7c27a8ceb719239 100644 --- a/src/query/src/queryMain.c +++ b/src/query/src/queryMain.c @@ -279,6 +279,7 @@ bool qTableQuery(qinfo_t qinfo, uint64_t *qId) { if (isQueryKilled(pQInfo)) { qDebug("QInfo:0x%"PRIx64" it is already killed, abort", pQInfo->qId); + pQInfo->runtimeEnv.outputBuf = NULL; return doBuildResCheck(pQInfo); } diff --git a/src/rpc/src/rpcTcp.c b/src/rpc/src/rpcTcp.c index 25495182498f7c1a82f9f9459290e44f082f5eb2..740a1e2b7d2784347b19be328319fc19f417f25d 100644 --- a/src/rpc/src/rpcTcp.c +++ b/src/rpc/src/rpcTcp.c @@ -488,6 +488,12 @@ static int taosReadTcpData(SFdObj *pFdObj, SRecvInfo *pInfo) { msgLen = (int32_t)htonl((uint32_t)rpcHead.msgLen); int32_t size = msgLen + tsRpcOverhead; + // TODO: reason not found yet, workaround to avoid first + if (msgLen <= 0 || size < 0) { + tError("%s %p invalid size for malloc, msgLen:%d, size:%d", pThreadObj->label, pFdObj->thandle, msgLen, size); + return -1; + } + buffer = malloc(size); if (NULL == buffer) { tError("%s %p TCP malloc(size:%d) fail", pThreadObj->label, pFdObj->thandle, msgLen); diff --git a/src/sync/src/syncMain.c b/src/sync/src/syncMain.c index 68bafb09ca82a7a55b8eb3cd94c24138f5ef3a6c..a8b5a8f403cb9ca0c897d77db280e5a331c1f32e 100644 --- a/src/sync/src/syncMain.c +++ b/src/sync/src/syncMain.c @@ -1502,7 +1502,10 @@ static int32_t syncForwardToPeerImpl(SSyncNode *pNode, void *data, void *mhandle } } - int32_t retLen = taosWriteMsg(pPeer->peerFd, pSyncHead, fwdLen); + SOCKET peerFd = pPeer->peerFd; + pthread_mutex_unlock(&pNode->mutex); + int32_t retLen = taosWriteMsg(peerFd, pSyncHead, fwdLen); + pthread_mutex_lock(&pNode->mutex); if (retLen == fwdLen) { sTrace("%s, forward is sent, role:%s sstatus:%s hver:%" PRIu64 " contLen:%d", pPeer->id, syncRole[pPeer->role], syncStatus[pPeer->sstatus], pWalHead->version, pWalHead->len); diff --git a/src/tsdb/src/tsdbMain.c b/src/tsdb/src/tsdbMain.c index 5e1c2bc69e6aad67cae979713ea9e3caa3b73584..45872b1dcef5904e269b2fda6fb4aa5cb3b26a9b 100644 --- a/src/tsdb/src/tsdbMain.c +++ b/src/tsdb/src/tsdbMain.c @@ -512,6 +512,7 @@ static int32_t tsdbCheckAndSetDefaultCfg(STsdbCfg *pCfg) { } // Check keep +#if 0 // already checked and set in mnodeSetDefaultDbCfg if (pCfg->keep == -1) { pCfg->keep = TSDB_DEFAULT_KEEP; } else { @@ -532,7 +533,25 @@ static int32_t tsdbCheckAndSetDefaultCfg(STsdbCfg *pCfg) { if (pCfg->keep2 == 0) { pCfg->keep2 = pCfg->keep; } +#endif + + int32_t keepMin = pCfg->keep1; + int32_t keepMid = pCfg->keep2; + int32_t keepMax = pCfg->keep; + + if (keepMin > keepMid) { + SWAP(keepMin, keepMid, int32_t); + } + if (keepMin > keepMax) { + SWAP(keepMin, keepMax, int32_t); + } + if (keepMid > keepMax) { + SWAP(keepMid, keepMax, int32_t); + } + pCfg->keep = keepMax; + pCfg->keep1 = keepMin; + pCfg->keep2 = keepMid; // update check if (pCfg->update < TD_ROW_DISCARD_UPDATE || pCfg->update > TD_ROW_PARTIAL_UPDATE) pCfg->update = TD_ROW_DISCARD_UPDATE; diff --git a/src/tsdb/src/tsdbMemTable.c b/src/tsdb/src/tsdbMemTable.c index 7cf6f7150dea442e024e0fab663c9ea38dce728b..8958df3ced9a1577735660293eda0717b46db49a 100644 --- a/src/tsdb/src/tsdbMemTable.c +++ b/src/tsdb/src/tsdbMemTable.c @@ -564,7 +564,7 @@ static void tsdbFreeTableData(STableData *pTableData) { } } -static char *tsdbGetTsTupleKey(const void *data) { return memRowTuple((SMemRow)data); } +static char *tsdbGetTsTupleKey(const void *data) { return memRowKeys((SMemRow)data); } static int tsdbAdjustMemMaxTables(SMemTable *pMemTable, int maxTables) { ASSERT(pMemTable->maxTables < maxTables); diff --git a/tests/develop-test/0-management/0-database/.gitkeep b/tests/develop-test/0-management/0-database/.gitkeep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/tests/develop-test/0-management/1-stable/.gitkeep b/tests/develop-test/0-management/1-stable/.gitkeep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/tests/develop-test/0-management/2-table/.gitkeep b/tests/develop-test/0-management/2-table/.gitkeep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/tests/develop-test/0-management/3-tag/.gitkeep b/tests/develop-test/0-management/3-tag/.gitkeep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/tests/develop-test/0-management/4-others/.gitkeep b/tests/develop-test/0-management/4-others/.gitkeep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/tests/develop-test/1-insert/0-sql/.gitkeep b/tests/develop-test/1-insert/0-sql/.gitkeep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/tests/develop-test/1-insert/0-sql/basic.py b/tests/develop-test/1-insert/0-sql/basic.py new file mode 100644 index 0000000000000000000000000000000000000000..a123db1855bf4f470abfb3b176316f843e06c119 --- /dev/null +++ b/tests/develop-test/1-insert/0-sql/basic.py @@ -0,0 +1,68 @@ +################################################################### +# Copyright (c) 2016 by TAOS Technologies, Inc. +# All rights reserved. +# +# This file is proprietary and confidential to TAOS Technologies. +# No part of this file may be reproduced, stored, transmitted, +# disclosed or used in any form or by any means other than as +# expressly provided by the written permission from Jianhui Tao +# +################################################################### + +# -*- coding: utf-8 -*- + +import sys +from util.log import * +from util.cases import * +from util.sql import * + + +class TDTestCase: + def caseDescription(self): + ''' + case1: insert 倒序插入 + case2: 语法解析错误同时meta请求也发出去了导致callback中处理逻辑失效 + case3: [TD-XXXX]insert语句在values之间加入多个逗号 + ''' + return + + def init(self, conn, logSql): + tdLog.debug("start to execute %s" % __file__) + tdSql.init(conn.cursor(), logSql) + + def run(self): + tdSql.prepare() + + ret = tdSql.execute('create table tb (ts timestamp, speed int)') + + insertRows = 10 + tdLog.info("insert %d rows" % (insertRows)) + for i in range(0, insertRows): + ret = tdSql.execute( + 'insert into tb values (now + %dm, %d)' % + (i, i)) + + tdLog.info("insert earlier data") + tdSql.execute('insert into tb values (now - 5m , 10)') + tdSql.execute('insert into tb values (now - 6m , 10)') + tdSql.execute('insert into tb values (now - 7m , 10)') + tdSql.execute('insert into tb values (now - 8m , 10)') + + tdSql.query("select * from tb") + tdSql.checkRows(insertRows + 4) + + # 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() + tdLog.success("%s successfully executed" % __file__) + + +tdCases.addWindows(__file__, TDTestCase()) +tdCases.addLinux(__file__, TDTestCase()) diff --git a/tests/develop-test/1-insert/1-stmt/.gitkeep b/tests/develop-test/1-insert/1-stmt/.gitkeep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/tests/develop-test/1-insert/2-schemaless/json/.gitkeep b/tests/develop-test/1-insert/2-schemaless/json/.gitkeep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/tests/develop-test/1-insert/2-schemaless/line/.gitkeep b/tests/develop-test/1-insert/2-schemaless/line/.gitkeep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/tests/develop-test/1-insert/2-schemaless/telnet/.gitkeep b/tests/develop-test/1-insert/2-schemaless/telnet/.gitkeep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/tests/develop-test/2-query/0-aggregate/.gitkeep b/tests/develop-test/2-query/0-aggregate/.gitkeep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/tests/develop-test/2-query/1-select/.gitkeep b/tests/develop-test/2-query/1-select/.gitkeep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/tests/develop-test/2-query/2-compute/.gitkeep b/tests/develop-test/2-query/2-compute/.gitkeep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/tests/develop-test/2-query/3-join/.gitkeep b/tests/develop-test/2-query/3-join/.gitkeep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/tests/develop-test/2-query/4-union/.gitkeep b/tests/develop-test/2-query/4-union/.gitkeep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/tests/develop-test/2-query/5-session/.gitkeep b/tests/develop-test/2-query/5-session/.gitkeep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/tests/develop-test/2-query/6-state_window/.gitkeep b/tests/develop-test/2-query/6-state_window/.gitkeep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/tests/develop-test/2-query/7-nest/.gitkeep b/tests/develop-test/2-query/7-nest/.gitkeep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/tests/develop-test/2-query/8-udf/.gitkeep b/tests/develop-test/2-query/8-udf/.gitkeep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/tests/develop-test/2-query/9-others/.gitkeep b/tests/develop-test/2-query/9-others/.gitkeep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/tests/develop-test/3-connectors/c#/.gitkeep b/tests/develop-test/3-connectors/c#/.gitkeep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/tests/develop-test/3-connectors/go/.gitkeep b/tests/develop-test/3-connectors/go/.gitkeep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/tests/develop-test/3-connectors/java/.gitkeep b/tests/develop-test/3-connectors/java/.gitkeep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/tests/develop-test/3-connectors/nodejs/.gitkeep b/tests/develop-test/3-connectors/nodejs/.gitkeep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/tests/develop-test/3-connectors/restful/.gitkeep b/tests/develop-test/3-connectors/restful/.gitkeep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/tests/develop-test/3-connectors/rust/.gitkeep b/tests/develop-test/3-connectors/rust/.gitkeep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/tests/develop-test/4-taosAdapter/.gitkeep b/tests/develop-test/4-taosAdapter/.gitkeep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/tests/develop-test/5-taos-tools/taosbenchmark/.gitkeep b/tests/develop-test/5-taos-tools/taosbenchmark/.gitkeep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/tests/develop-test/5-taos-tools/taosdump/.gitkeep b/tests/develop-test/5-taos-tools/taosdump/.gitkeep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/tests/develop-test/6-cluster/.gitkeep b/tests/develop-test/6-cluster/.gitkeep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/tests/develop-test/7-customer/.gitkeep b/tests/develop-test/7-customer/.gitkeep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/tests/develop-test/fulltest.sh b/tests/develop-test/fulltest.sh new file mode 100755 index 0000000000000000000000000000000000000000..e71a25659b1e5a2eed92e615f63eb18ace64de92 --- /dev/null +++ b/tests/develop-test/fulltest.sh @@ -0,0 +1 @@ +python3 test.py -f 1-insert/0-sql/basic.py \ No newline at end of file diff --git a/tests/develop-test/test.py b/tests/develop-test/test.py new file mode 100644 index 0000000000000000000000000000000000000000..b39b95c9030e14a2442883991cadb7d21e5e7a5d --- /dev/null +++ b/tests/develop-test/test.py @@ -0,0 +1,198 @@ +#!/usr/bin/python +################################################################### +# 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 +# +################################################################### +# install pip +# pip install src/connector/python/ + +# -*- coding: utf-8 -*- +import sys +import getopt +import subprocess +import time +from distutils.log import warn as printf +from fabric2 import Connection +sys.path.append("../pytest") +from util.log import * +from util.dnodes import * +from util.cases import * + +import taos + + +if __name__ == "__main__": + + fileName = "all" + deployPath = "" + masterIp = "" + testCluster = False + valgrind = 0 + logSql = True + stop = 0 + restart = False + windows = 0 + opts, args = getopt.gnu_getopt(sys.argv[1:], 'f:p:m:l:scghrw', [ + 'file=', 'path=', 'master', 'logSql', 'stop', 'cluster', 'valgrind', 'help', 'windows']) + for key, value in opts: + if key in ['-h', '--help']: + tdLog.printNoPrefix( + 'A collection of test cases written using Python') + tdLog.printNoPrefix('-f Name of test case file written by Python') + tdLog.printNoPrefix('-p Deploy Path for Simulator') + tdLog.printNoPrefix('-m Master Ip for Simulator') + tdLog.printNoPrefix('-l logSql Flag') + tdLog.printNoPrefix('-s stop All dnodes') + tdLog.printNoPrefix('-c Test Cluster Flag') + tdLog.printNoPrefix('-g valgrind Test Flag') + tdLog.printNoPrefix('-r taosd restart test') + tdLog.printNoPrefix('-w taos on windows') + sys.exit(0) + + if key in ['-r', '--restart']: + restart = True + + if key in ['-f', '--file']: + fileName = value + + if key in ['-p', '--path']: + deployPath = value + + if key in ['-m', '--master']: + masterIp = value + + if key in ['-l', '--logSql']: + if (value.upper() == "TRUE"): + logSql = True + elif (value.upper() == "FALSE"): + logSql = False + else: + tdLog.printNoPrefix("logSql value %s is invalid" % logSql) + sys.exit(0) + + if key in ['-c', '--cluster']: + testCluster = True + + if key in ['-g', '--valgrind']: + valgrind = 1 + + if key in ['-s', '--stop']: + stop = 1 + + if key in ['-w', '--windows']: + windows = 1 + + if (stop != 0): + if (valgrind == 0): + toBeKilled = "taosd" + else: + toBeKilled = "valgrind.bin" + + killCmd = "ps -ef|grep -w %s| grep -v grep | awk '{print $2}' | xargs kill -TERM > /dev/null 2>&1" % toBeKilled + + psCmd = "ps -ef|grep -w %s| grep -v grep | awk '{print $2}'" % toBeKilled + processID = subprocess.check_output(psCmd, shell=True) + + while(processID): + os.system(killCmd) + time.sleep(1) + processID = subprocess.check_output(psCmd, shell=True) + + for port in range(6030, 6041): + usePortPID = "lsof -i tcp:%d | grep LISTEn | awk '{print $2}'" % port + processID = subprocess.check_output(usePortPID, shell=True) + + if processID: + killCmd = "kill -TERM %s" % processID + os.system(killCmd) + fuserCmd = "fuser -k -n tcp %d" % port + os.system(fuserCmd) + if valgrind: + time.sleep(2) + + tdLog.info('stop All dnodes') + + if masterIp == "": + host = '127.0.0.1' + else: + host = masterIp + + tdLog.info("Procedures for tdengine deployed in %s" % (host)) + if windows: + tdCases.logSql(logSql) + tdLog.info("Procedures for testing self-deployment") + td_clinet = TDSimClient("C:\\TDengine") + td_clinet.deploy() + remote_conn = Connection("root@%s"%host) + with remote_conn.cd('/var/lib/jenkins/workspace/TDinternal/community/tests/pytest'): + remote_conn.run("python3 ./test.py") + conn = taos.connect( + host="%s"%(host), + config=td_clinet.cfgDir) + tdCases.runOneWindows(conn, fileName) + else: + tdDnodes.init(deployPath) + tdDnodes.setTestCluster(testCluster) + tdDnodes.setValgrind(valgrind) + tdDnodes.stopAll() + is_test_framework = 0 + key_word = 'tdCases.addLinux' + try: + if key_word in open(fileName).read(): + is_test_framework = 1 + except: + pass + if is_test_framework: + moduleName = fileName.replace(".py", "").replace("/", ".") + uModule = importlib.import_module(moduleName) + try: + ucase = uModule.TDTestCase() + tdDnodes.deploy(1,ucase.updatecfgDict) + except : + tdDnodes.deploy(1,{}) + else: + pass + tdDnodes.deploy(1,{}) + tdDnodes.start(1) + + + + tdCases.logSql(logSql) + + if testCluster: + tdLog.info("Procedures for testing cluster") + if fileName == "all": + tdCases.runAllCluster() + else: + tdCases.runOneCluster(fileName) + else: + tdLog.info("Procedures for testing self-deployment") + conn = taos.connect( + host, + config=tdDnodes.getSimCfgPath()) + if fileName == "all": + tdCases.runAllLinux(conn) + else: + tdCases.runOneWindows(conn, fileName) + if restart: + if fileName == "all": + tdLog.info("not need to query ") + else: + sp = fileName.rsplit(".", 1) + if len(sp) == 2 and sp[1] == "py": + tdDnodes.stopAll() + tdDnodes.start(1) + time.sleep(1) + conn = taos.connect( host, config=tdDnodes.getSimCfgPath()) + tdLog.info("Procedures for tdengine deployed in %s" % (host)) + tdLog.info("query test after taosd restart") + tdCases.runOneLinux(conn, sp[0] + "_" + "restart.py") + else: + tdLog.info("not need to query") + conn.close() diff --git a/tests/examples/C#/stmt/StmtDemo.cs b/tests/examples/C#/stmt/StmtDemo.cs new file mode 100644 index 0000000000000000000000000000000000000000..c2b299140976ed36f245f5693a2a047607c5b5be --- /dev/null +++ b/tests/examples/C#/stmt/StmtDemo.cs @@ -0,0 +1,549 @@ +/* + * 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 +{ + public class StmtDemo + { + //connection 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 IntPtr stmt = IntPtr.Zero; + + static void Main(string[] args) + { + string dropDB = "drop database if exists csharp"; + string createDB = "create database if not exists csharp keep 36500"; + string selectDB = "use csharp"; + string stmtSql = "insert into ? using stmtdemo tags(?,?,?,?,?,?,?,?,?,?,?,?,?) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?)"; + string createTable = "create stable stmtdemo (ts timestamp " + + ",b bool" + + ",v1 tinyint" + + ",v2 smallint" + + ",v4 int" + + ",v8 bigint" + + ",f4 float" + + ",f8 double" + + ",u1 tinyint unsigned" + + ",u2 smallint unsigned" + + ",u4 int unsigned" + + ",u8 bigint unsigned" + + ",bin binary(200)" + + ",blob nchar(200)" + + ")tags(" + + "bo bool" + + ",tt tinyint" + + ",si smallint" + + ",ii int" + + ",bi bigint" + + ",tu tinyint unsigned" + + ",su smallint unsigned" + + ",iu int unsigned" + + ",bu bigint unsigned" + + ",ff float " + + ",dd double " + + ",bb binary(200)" + + ",nc nchar(200)" + + ")"; + + string dropTable = "drop table if exists stmtdemo"; + + string tableName = "t1"; + StmtDemo stmtDemo = new StmtDemo(); + Console.WriteLine("---------------------------------------------------------------"); + Console.WriteLine("Start StmtDemo insert Testing..."); + Console.WriteLine("---------------------------------------------------------------"); + stmtDemo.InitTDengine(); + //TDengine connect + stmtDemo.ConnectTDengine(); + + //before stmt + stmtDemo.ExecuteQuery(dropDB); + stmtDemo.ExecuteQuery(createDB); + stmtDemo.ExecuteQuery(selectDB); + stmtDemo.ExecuteQuery(dropTable); + stmtDemo.ExecuteQuery(createTable); + + stmtDemo.StmtInit(); + string[] tableList = { "stmtdemo" }; + stmtDemo.loadTableInfo(tableList); + + stmtDemo.StmtPrepare(stmtSql); + TAOS_BIND[] binds = stmtDemo.InitBindArr(); + TAOS_MULTI_BIND[] mbinds = stmtDemo.InitMultBindArr(); + stmtDemo.SetTableNameTags(tableName, binds); + stmtDemo.BindParamBatch(mbinds); + stmtDemo.AddBatch(); + stmtDemo.StmtExecute(); + TaosBind.FreeTaosBind(binds); + TaosMultiBind.FreeTaosBind(mbinds); + stmtDemo.StmtClose(); + + Console.WriteLine("---------------------------------------------------------------"); + Console.WriteLine("start StmtDemo select Testing..."); + Console.WriteLine("---------------------------------------------------------------"); + + stmtDemo.StmtInit(); + string selectSql = "SELECT * FROM stmtdemo WHERE v1 > ? AND v4 < ?"; + + stmtDemo.StmtPrepare(selectSql); + + TAOS_BIND[] queryCondition = new TAOS_BIND[2]; + queryCondition[0] = TaosBind.BindTinyInt(0); + queryCondition[1] = TaosBind.BindInt(1000); + + Console.WriteLine(selectSql); + stmtDemo.BindParam(queryCondition); + stmtDemo.StmtExecute(); + + stmtDemo.StmtUseResult(); + + stmtDemo.StmtClose(); + TaosBind.FreeTaosBind(queryCondition); + Console.WriteLine("---------------------------------------------------------------"); + Console.WriteLine("Stop StmtDemo Testing..."); + Console.WriteLine("---------------------------------------------------------------"); + + stmtDemo.CloseConnection(); + } + public TAOS_BIND[] InitBindArr() + { + TAOS_BIND[] binds = new TAOS_BIND[13]; + binds[0] = TaosBind.BindBool(true); + binds[1] = TaosBind.BindTinyInt(-2); + binds[2] = TaosBind.BindSmallInt(short.MaxValue); + binds[3] = TaosBind.BindInt(int.MaxValue); + binds[4] = TaosBind.BindBigInt(Int64.MaxValue); + binds[5] = TaosBind.BindUTinyInt(byte.MaxValue - 1); + binds[6] = TaosBind.BindUSmallInt(UInt16.MaxValue - 1); + binds[7] = TaosBind.BindUInt(uint.MinValue + 1); + binds[8] = TaosBind.BindUBigInt(UInt64.MinValue + 1); + binds[9] = TaosBind.BindFloat(11.11F); + binds[10] = TaosBind.BindDouble(22.22D); + binds[11] = TaosBind.BindBinary("qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM`1234567890-=+_)(*&^%$#@!~[];,./<>?:{}"); + binds[12] = TaosBind.BindNchar("qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKZXCVBNM`1234567890-=+_)(*&^%$#@!~[];,./<>?:{}"); + return binds; + } + + public TAOS_MULTI_BIND[] InitMultBindArr() + { + TAOS_MULTI_BIND[] mBinds = new TAOS_MULTI_BIND[14]; + long[] tsArr = new long[5] { 1637064040000, 1637064041000, 1637064042000, 1637064043000, 1637064044000 }; + bool?[] boolArr = new bool?[5] { true, false, null, true, true }; + sbyte?[] tinyIntArr = new sbyte?[5] { -127, 0, null, 8, 127 }; + short?[] shortArr = new short?[5] { short.MinValue + 1, -200, null, 100, short.MaxValue }; + int?[] intArr = new int?[5] { -200, -100, null, 0, 300 }; + long?[] longArr = new long?[5] { long.MinValue + 1, -2000, null, 1000, long.MaxValue }; + float?[] floatArr = new float?[5] { float.MinValue + 1, -12.1F, null, 0F, float.MaxValue }; + double?[] doubleArr = new double?[5] { double.MinValue + 1, -19.112D, null, 0D, double.MaxValue }; + byte?[] uTinyIntArr = new byte?[5] { byte.MinValue, 12, null, 89, byte.MaxValue - 1 }; + ushort?[] uShortArr = new ushort?[5] { ushort.MinValue, 200, null, 400, ushort.MaxValue - 1 }; + uint?[] uIntArr = new uint?[5] { uint.MinValue, 100, null, 2, uint.MaxValue - 1 }; + ulong?[] uLongArr = new ulong?[5] { ulong.MinValue, 2000, null, 1000, long.MaxValue - 1 }; + string[] binaryArr = new string[5] { "1234567890~!@#$%^&*()_+=-`[]{}:,./<>?", String.Empty, null, "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM", "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM1234567890~!@#$%^&*()_+=-`[]{}:,./<>?" }; + string[] ncharArr = new string[5] { "1234567890~!@#$%^&*()_+=-`[]{}:,./<>?", null, "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM", "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM1234567890~!@#$%^&*()_+=-`[]{}:,./<>?", string.Empty }; + mBinds[0] = TaosMultiBind.MultiBindTimestamp(tsArr); + mBinds[1] = TaosMultiBind.MultiBindBool(boolArr); + mBinds[2] = TaosMultiBind.MultiBindTinyInt(tinyIntArr); + mBinds[3] = TaosMultiBind.MultiBindSmallInt(shortArr); + mBinds[4] = TaosMultiBind.MultiBindInt(intArr); + mBinds[5] = TaosMultiBind.MultiBindBigint(longArr); + mBinds[6] = TaosMultiBind.MultiBindFloat(floatArr); + mBinds[7] = TaosMultiBind.MultiBindDouble(doubleArr); + mBinds[8] = TaosMultiBind.MultiBindUTinyInt(uTinyIntArr); + mBinds[9] = TaosMultiBind.MultiBindUSmallInt(uShortArr); + mBinds[10] = TaosMultiBind.MultiBindUInt(uIntArr); + mBinds[11] = TaosMultiBind.MultiBindUBigInt(uLongArr); + mBinds[12] = TaosMultiBind.MultiBindBinary(binaryArr); + mBinds[13] = TaosMultiBind.MultiBindNchar(ncharArr); + return mBinds; + } + + public void loadTableInfo(string[] arr) + { + if (TDengine.LoadTableInfo(this.conn, arr) == 0) + { + Console.WriteLine("load table info success"); + } + else + { + Console.WriteLine("load table info failed"); + ExitProgram(); + } + } + + public void InitTDengine() + { + TDengine.Options((int)TDengineInitOption.TDDB_OPTION_CONFIGDIR, this.configDir); + TDengine.Options((int)TDengineInitOption.TDDB_OPTION_SHELL_ACTIVITY_TIMER, "60"); + TDengine.Init(); + Console.WriteLine("TDengine Initialization finished"); + } + + public void ConnectTDengine() + { + string db = ""; + this.conn = TDengine.Connect(this.host, this.user, this.passwd, db, this.port); + if (this.conn == IntPtr.Zero) + { + Console.WriteLine("Connect to TDengine failed"); + ExitProgram(); + } + else + { + Console.WriteLine("Connect to TDengine success"); + } + } + + public void ExecuteQuery(String sql) + { + IntPtr res = TDengine.Query(conn, sql); + 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 StmtInit() + { + this.stmt = TDengine.StmtInit(conn); + if (this.stmt == IntPtr.Zero) + { + Console.WriteLine("Init stmt failed"); + ExitProgram(); + } + else + { + Console.WriteLine("Init stmt success"); + } + } + + public void StmtPrepare(string sql) + { + int res = TDengine.StmtPrepare(this.stmt, sql); + if (res == 0) + { + Console.WriteLine("stmt prepare success"); + } + else + { + Console.WriteLine("stmt prepare failed " + TDengine.StmtErrorStr(stmt)); + ExitProgram(); + } + } + + public void SetTableName(String tableName) + { + int res = TDengine.StmtSetTbname(this.stmt, tableName); + Console.WriteLine("setTableName():" + res); + if (res == 0) + { + Console.WriteLine("set_tbname success"); + } + else + { + Console.Write("set_tbname failed, " + TDengine.StmtErrorStr(stmt)); + StmtClose(); + ExitProgram(); + } + } + + public void SetTableNameTags(String tableName, TAOS_BIND[] tags) + { + int res = TDengine.StmtSetTbnameTags(this.stmt, tableName, tags); + if (res == 0) + { + Console.WriteLine("set tbname && tags success"); + + } + else + { + Console.Write("set tbname && tags failed, " + TDengine.StmtErrorStr(stmt)); + StmtClose(); + ExitProgram(); + } + } + + public void SetSubTableName(string name) + { + int res = TDengine.StmtSetSubTbname(this.stmt, name); + if (res == 0) + { + Console.WriteLine("set subtable name success"); + } + else + { + Console.Write("set subtable name failed, " + TDengine.StmtErrorStr(stmt)); + StmtClose(); + ExitProgram(); + } + + } + + public void BindParam(TAOS_BIND[] binds) + { + Console.WriteLine("in bindParam()"); + + int res = TDengine.StmtBindParam(this.stmt, binds); + if (res == 0) + { + Console.WriteLine("bind para success"); + } + else + { + Console.Write("bind para failed, " + TDengine.StmtErrorStr(stmt)); + StmtClose(); + ExitProgram(); + } + } + + public void BindSingleParamBatch(TAOS_MULTI_BIND bind, int index) + { + int res = TDengine.StmtBindSingleParamBatch(this.stmt,ref bind, index); + if (res == 0) + { + Console.WriteLine("single bind batch success"); + } + else + { + Console.Write("single bind batch failed: " + TDengine.StmtErrorStr(stmt)); + StmtClose(); + ExitProgram(); + } + } + + public void BindParamBatch(TAOS_MULTI_BIND[] bind) + { + int res = TDengine.StmtBindParamBatch(this.stmt, bind); + if (res == 0) + { + Console.WriteLine("bind parameter batch success"); + } + else + { + Console.WriteLine("bind parameter batch failed, " + TDengine.StmtErrorStr(stmt)); + StmtClose(); + ExitProgram(); + } + } + + public void AddBatch() + { + int res = TDengine.StmtAddBatch(this.stmt); + if (res == 0) + { + Console.WriteLine("stmt add batch success"); + } + else + { + Console.Write("stmt add batch failed,reason: " + TDengine.StmtErrorStr(stmt)); + StmtClose(); + ExitProgram(); + } + } + public void StmtExecute() + { + int res = TDengine.StmtExecute(this.stmt); + if (res == 0) + { + Console.WriteLine("Execute stmt success"); + } + else + { + Console.Write("Execute stmt failed,reason: " + TDengine.StmtErrorStr(stmt)); + StmtClose(); + ExitProgram(); + } + } + public void StmtClose() + { + int res = TDengine.StmtClose(this.stmt); + if (res == 0) + { + Console.WriteLine("close stmt success"); + } + else + { + Console.WriteLine("close stmt failed, " + TDengine.StmtErrorStr(stmt)); + StmtClose(); + ExitProgram(); + } + } + public void CloseConnection() + { + if (this.conn != IntPtr.Zero) + { + if (TDengine.Close(this.conn) == 0) + { + Console.WriteLine("close connection sucess"); + } + else + { + Console.WriteLine("close Connection failed"); + } + } + } + + //select only + public void StmtUseResult() + { + IntPtr res = TDengine.StmtUseResult(this.stmt); + if ((res == IntPtr.Zero) || (TDengine.ErrorNo(res) != 0)) + { + if (res != IntPtr.Zero) + { + Console.Write("reason: " + TDengine.Error(res)); + } + Console.WriteLine(""); + StmtClose(); + CloseConnection(); + ExitProgram(); + } + else + { + Console.WriteLine("{0},query success"); + DisplayRes(res); + TDengine.FreeResult(res); + } + + } + + public void DisplayRes(IntPtr res) + { + + long queryRows = 0; + if ((res == IntPtr.Zero) || (TDengine.ErrorNo(res) != 0)) + { + if (res != IntPtr.Zero) + { + Console.Write("reason: " + TDengine.Error(res)); + } + Console.WriteLine(""); + ExitProgram(); + } + + 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(""); + + } + public static void ExitProgram() + { + TDengine.Cleanup(); + System.Environment.Exit(0); + } + } +} diff --git a/tests/examples/C#/stmt/stmt.csproj b/tests/examples/C#/stmt/stmt.csproj new file mode 100644 index 0000000000000000000000000000000000000000..bc14850edbf9023e885436016141f24d6d042127 --- /dev/null +++ b/tests/examples/C#/stmt/stmt.csproj @@ -0,0 +1,12 @@ + + + + + + + + Exe + net5.0 + + + diff --git a/tests/examples/c/schemaless.c b/tests/examples/c/schemaless.c index 9a2d2f063573d26093bd5032e2f68cc54fc5f908..0b46d2ff134689992d648065511dd5c21766759e 100644 --- a/tests/examples/c/schemaless.c +++ b/tests/examples/c/schemaless.c @@ -8,7 +8,8 @@ #include #include -#define MAX_THREAD_LINE_BATCHES 1024 +bool verbose = false; + void printThreadId(pthread_t id, char* buf) { @@ -30,11 +31,10 @@ typedef struct { typedef struct { TAOS* taos; + int protocol; int numBatches; - SThreadLinesBatch batches[MAX_THREAD_LINE_BATCHES]; + SThreadLinesBatch *batches; int64_t costTime; - int tsPrecision; - int lineProtocol; } SThreadInsertArgs; static void* insertLines(void* args) { @@ -43,27 +43,33 @@ static void* insertLines(void* args) { printThreadId(pthread_self(), tidBuf); for (int i = 0; i < insertArgs->numBatches; ++i) { SThreadLinesBatch* batch = insertArgs->batches + i; - printf("%s, thread: 0x%s\n", "begin taos_insert_lines", tidBuf); + if (verbose) printf("%s, thread: 0x%s\n", "begin taos_insert_lines", tidBuf); int64_t begin = getTimeInUs(); - TAOS_RES *res = taos_schemaless_insert(insertArgs->taos, batch->lines, batch->numLines, insertArgs->lineProtocol, insertArgs->tsPrecision); + //int32_t code = taos_insert_lines(insertArgs->taos, batch->lines, batch->numLines); + TAOS_RES * res = taos_schemaless_insert(insertArgs->taos, batch->lines, batch->numLines, insertArgs->protocol, TSDB_SML_TIMESTAMP_MILLI_SECONDS); int32_t code = taos_errno(res); int64_t end = getTimeInUs(); insertArgs->costTime += end - begin; - printf("code: %d, %s. affected lines:%d time used:%"PRId64", thread: 0x%s\n", code, taos_errstr(res), taos_affected_rows(res), end - begin, tidBuf); - taos_free_result(res); + if (verbose) printf("code: %d, %s. time used:%"PRId64", thread: 0x%s\n", code, tstrerror(code), end - begin, tidBuf); } return NULL; } +int32_t getTelenetTemplate(char* lineTemplate, int templateLen) { + char* sample = "sta%d %lld 44.3 t0=False t1=127i8 t2=32 t3=%di32 t4=9223372036854775807i64 t5=11.12345f32 t6=22.123456789f64 t7=\"hpxzrdiw\" t8=\"ncharTagValue\" t9=127i8"; + snprintf(lineTemplate, templateLen, "%s", sample); + return 0; +} + int32_t getLineTemplate(char* lineTemplate, int templateLen, int numFields) { if (numFields <= 4) { - char* sample = "sta%d,t3=%di32 c3=2147483647i32,c4=9223372036854775807i64,c9=11.12345f32,c10=22.123456789f64 %lldms"; + char* sample = "sta%d,t3=%di32 c3=2147483647i32,c4=9223372036854775807i64,c9=11.12345f32,c10=22.123456789f64 %lld"; snprintf(lineTemplate, templateLen, "%s", sample); return 0; } if (numFields <= 13) { - char* sample = "sta%d,t0=true,t1=127i8,t2=32767i16,t3=%di32,t4=9223372036854775807i64,t9=11.12345f32,t10=22.123456789f64,t11=\"binaryTagValue\",t12=L\"ncharTagValue\" c0=true,c1=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c5=254u8,c6=32770u16,c7=2147483699u32,c8=9223372036854775899u64,c9=11.12345f32,c10=22.123456789f64,c11=\"binaryValue\",c12=L\"ncharValue\" %lldms"; + char* sample = "sta%d,t0=true,t1=127i8,t2=32767i16,t3=%di32,t4=9223372036854775807i64,t9=11.12345f32,t10=22.123456789f64,t11=\"binaryTagValue\",t12=L\"ncharTagValue\" c0=true,c1=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c5=254u8,c6=32770u16,c7=2147483699u32,c8=9223372036854775899u64,c9=11.12345f32,c10=22.123456789f64,c11=\"binaryValue\",c12=L\"ncharValue\" %lld"; snprintf(lineTemplate, templateLen, "%s", sample); return 0; } @@ -84,14 +90,24 @@ int32_t getLineTemplate(char* lineTemplate, int templateLen, int numFields) { for (int i = offset[1]+1; i < offset[2]; ++i) { snprintf(lineTemplate+strlen(lineTemplate), templateLen-strlen(lineTemplate), "c%d=\"%d\",", i, i); } - char* lineFormatTs = " %lldms"; + char* lineFormatTs = " %lld"; snprintf(lineTemplate+strlen(lineTemplate)-1, templateLen-strlen(lineTemplate)+1, "%s", lineFormatTs); return 0; } +int32_t generateLine(char* line, int lineLen, char* lineTemplate, int protocol, int superTable, int childTable, int64_t ts) { + if (protocol == TSDB_SML_LINE_PROTOCOL) { + snprintf(line, lineLen, lineTemplate, superTable, childTable, ts); + } else if (protocol == TSDB_SML_TELNET_PROTOCOL) { + snprintf(line, lineLen, lineTemplate, superTable, ts, childTable); + } + return TSDB_CODE_SUCCESS; +} + int main(int argc, char* argv[]) { int numThreads = 8; + int maxBatchesPerThread = 1024; int numSuperTables = 1; int numChildTables = 256; @@ -99,11 +115,11 @@ int main(int argc, char* argv[]) { int numFields = 13; int maxLinesPerBatch = 16384; - int tsPrecision = TSDB_SML_TIMESTAMP_NOT_CONFIGURED; - int lineProtocol = TSDB_SML_UNKNOWN_PROTOCOL; + + int protocol = TSDB_SML_TELNET_PROTOCOL; int opt; - while ((opt = getopt(argc, argv, "s:c:r:f:t:m:p:P:h")) != -1) { + while ((opt = getopt(argc, argv, "s:c:r:f:t:b:p:hv")) != -1) { switch (opt) { case 's': numSuperTables = atoi(optarg); @@ -120,28 +136,35 @@ int main(int argc, char* argv[]) { case 't': numThreads = atoi(optarg); break; - case 'm': + case 'b': maxLinesPerBatch = atoi(optarg); break; - case 'p': - tsPrecision = atoi(optarg); + case 'v': + verbose = true; break; - case 'P': - lineProtocol = atoi(optarg); + case 'p': + if (optarg[0] == 't') { + protocol = TSDB_SML_TELNET_PROTOCOL; + } else if (optarg[0] == 'l') { + protocol = TSDB_SML_LINE_PROTOCOL; + } else if (optarg[0] == 'j') { + protocol = TSDB_SML_JSON_PROTOCOL; + } break; case 'h': - fprintf(stderr, "Usage: %s -s supertable -c childtable -r rows -f fields -t threads -m maxlines_per_batch\n", + fprintf(stderr, "Usage: %s -s supertable -c childtable -r rows -f fields -t threads -b maxlines_per_batch -p [t|l|j] -v\n", argv[0]); exit(0); default: /* '?' */ - fprintf(stderr, "Usage: %s -s supertable -c childtable -r rows -f fields -t threads -m maxlines_per_batch\n", + fprintf(stderr, "Usage: %s -s supertable -c childtable -r rows -f fields -t threads -b maxlines_per_batch -p [t|l|j] -v\n", argv[0]); exit(-1); } } TAOS_RES* result; - const char* host = "127.0.0.1"; + //const char* host = "127.0.0.1"; + const char* host = NULL; const char* user = "root"; const char* passwd = "taosdata"; @@ -152,10 +175,7 @@ int main(int argc, char* argv[]) { exit(1); } - if (numThreads * MAX_THREAD_LINE_BATCHES* maxLinesPerBatch < numSuperTables*numChildTables*numRowsPerChildTable) { - printf("too many rows to be handle by threads with %d batches", MAX_THREAD_LINE_BATCHES); - exit(2); - } + maxBatchesPerThread = (numSuperTables*numChildTables*numRowsPerChildTable)/(numThreads * maxLinesPerBatch) + 1; char* info = taos_get_server_info(taos); printf("server info: %s\n", info); @@ -171,28 +191,33 @@ int main(int argc, char* argv[]) { (void)taos_select_db(taos, "db"); time_t ct = time(0); - int64_t ts = ct * 1000; + int64_t ts = ct * 1000 ; char* lineTemplate = calloc(65536, sizeof(char)); - getLineTemplate(lineTemplate, 65535, numFields); + if (protocol == TSDB_SML_LINE_PROTOCOL) { + getLineTemplate(lineTemplate, 65535, numFields); + } else if (protocol == TSDB_SML_TELNET_PROTOCOL ) { + getTelenetTemplate(lineTemplate, 65535); + } printf("setup supertables..."); { char** linesStb = calloc(numSuperTables, sizeof(char*)); for (int i = 0; i < numSuperTables; i++) { char* lineStb = calloc(strlen(lineTemplate)+128, 1); - snprintf(lineStb, strlen(lineTemplate)+128, lineTemplate, i, + generateLine(lineStb, strlen(lineTemplate)+128, lineTemplate, protocol, i, numSuperTables * numChildTables, ts + numSuperTables * numChildTables * numRowsPerChildTable); linesStb[i] = lineStb; } SThreadInsertArgs args = {0}; + args.protocol = protocol; + args.batches = calloc(maxBatchesPerThread, sizeof(maxBatchesPerThread)); args.taos = taos; args.batches[0].lines = linesStb; args.batches[0].numLines = numSuperTables; - args.tsPrecision = tsPrecision; - args.lineProtocol = lineProtocol; insertLines(&args); + free(args.batches); for (int i = 0; i < numSuperTables; ++i) { free(linesStb[i]); } @@ -203,8 +228,10 @@ int main(int argc, char* argv[]) { pthread_t* tids = calloc(numThreads, sizeof(pthread_t)); SThreadInsertArgs* argsThread = calloc(numThreads, sizeof(SThreadInsertArgs)); for (int i = 0; i < numThreads; ++i) { + argsThread[i].batches = calloc(maxBatchesPerThread, sizeof(SThreadLinesBatch)); argsThread[i].taos = taos; argsThread[i].numBatches = 0; + argsThread[i].protocol = protocol; } int64_t totalLines = numSuperTables * numChildTables * numRowsPerChildTable; @@ -229,7 +256,7 @@ int main(int argc, char* argv[]) { int stIdx = i; int ctIdx = numSuperTables*numChildTables + j; char* line = calloc(strlen(lineTemplate)+128, 1); - snprintf(line, strlen(lineTemplate)+128, lineTemplate, stIdx, ctIdx, ts + l); + generateLine(line, strlen(lineTemplate)+128, lineTemplate, protocol, stIdx, ctIdx, ts + l); int batchNo = l / maxLinesPerBatch; int lineNo = l % maxLinesPerBatch; allBatches[batchNo][lineNo] = line; @@ -262,6 +289,9 @@ int main(int argc, char* argv[]) { } free(allBatches); + for (int i = 0; i < numThreads; i++) { + free(argsThread[i].batches); + } free(argsThread); free(tids); diff --git a/tests/get_catalog.py b/tests/get_catalog.py new file mode 100644 index 0000000000000000000000000000000000000000..e1449ed78dcbc24bb66f0339862f9c50e6a5d749 --- /dev/null +++ b/tests/get_catalog.py @@ -0,0 +1,133 @@ +#!/usr/bin/python +################################################################### +# 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 +# +################################################################### +# install pip +# pip install src/connector/python/ + +# -*- coding: utf-8 -*- +import sys +import getopt +import os +from fabric2 import Connection +sys.path.append("pytest") +import importlib + +class CatalogGen: + def __init__(self, CaseDirList, CatalogName, DirDepth): + self.CaseDirList = CaseDirList + self.CatalogName = CatalogName + self.blacklist = [] + self.DirDepth = DirDepth + + def CatalogGen(self): + for i in self.CaseDirList: + self.GetCatalog(i) + self.CollectLog(i) + print('Catalog Generation done') + + def CollectLog(self, CaseDir): + DirorFiles = os.listdir(CaseDir) + for loop in range(self.DirDepth): + for i in DirorFiles: + fileName = os.path.join(CaseDir, i) + if os.path.isdir(fileName): + self.CollectLog(fileName) + else: + if i == self.CatalogName and fileName not in self.blacklist: + self.blacklist.append(fileName) + with open(fileName, "r") as f : + Catalog = f.read() + title = CaseDir.split("/")[-1] + TitleLevel = CaseDir.count("/") + with open(os.path.dirname(CaseDir) + '/' + self.CatalogName, "a") as f : + f.write("#" * TitleLevel + ' %s\n' % title) + f.write(Catalog) + + def GetCatalog(self, CaseDir): + for root, dirs, files in os.walk(CaseDir): + for file in files: + if file.endswith(".py"): + fileName = os.path.join(root, file) + moduleName = fileName.replace(".py", "").replace("/", ".") + uModule = importlib.import_module(moduleName) + title = file.split('.')[0] + TitleLevel = root.count('/') + 1 + try: + ucase = uModule.TDTestCase() + with open(root + '/' + self.CatalogName, 'a') as f: + f.write('#'*TitleLevel + ' %s\n' % title) + for i in ucase.caseDescription.__doc__.split('\n'): + if i.lstrip() == '':continue + f.write('* ' + i.strip()+'\n') + except : + print(fileName) + + def CleanCatalog(self): + for i in self.CaseDirList: + for root, dirs, files in os.walk(i): + for file in files: + if file == self.CatalogName: + os.remove(root + '/' + self.CatalogName) + print('clean is done') + +if __name__ == "__main__": + CaseDirList = [] + CatalogName = '' + DirDepth = 0 + generate = True + delete = True + opts, args = getopt.gnu_getopt(sys.argv[1:], 'd:c:v:n:th') + for key, value in opts: + if key in ['-h', '--help']: + print( + 'A collection of test cases catalog written using Python') + print("-d root dir of test case files written by Python, default: system-test,develop-test") + print('-c catalog file name, default: catalog.md') + print('-v dir depth of test cases.default: 5') + print('-n generate') + print('-r delete') + sys.exit(0) + + if key in ['-d']: + CaseDirList = value.split(',') + + if key in ['-c']: + CatalogName = value + + if key in ['-v']: + DirDepth = int(value) + + if key in ['-n']: + if (value.upper() == "TRUE"): + generate = True + elif (value.upper() == "FALSE"): + generate = False + + if key in ['-r']: + if (value.upper() == "TRUE"): + delete = True + elif (value.upper() == "FALSE"): + delete = False + + print(CaseDirList, CatalogName) + if CaseDirList == [] : + CaseDirList = ['system-test', 'develop-test'] + if CatalogName == '' : + CatalogName = 'catalog.md' + if DirDepth == 0: + DirDepth = 5 + print('opt:\n\tcatalogname: %s\n\tcasedirlist: %s\n\tdepth: %d\n\tgenerate: %s\n\tdelete: %s' + % (CatalogName, ','.join(CaseDirList), DirDepth, generate, delete)) + f = CatalogGen(CaseDirList, CatalogName, DirDepth) + if delete: + f.CleanCatalog() + if generate: + f.CatalogGen() diff --git a/tests/pytest/alter/alter_cacheLastRow.py b/tests/pytest/alter/alter_cacheLastRow.py index 36a2864d0f91cf485505ee105870a98df71c4df8..1112a6a99a71d25b1bf146d7f6eea13104787121 100644 --- a/tests/pytest/alter/alter_cacheLastRow.py +++ b/tests/pytest/alter/alter_cacheLastRow.py @@ -52,7 +52,7 @@ class TDTestCase: #write 5M rows into db, then restart to force the data move into disk. #create 500 tables - os.system("%staosdemo -f tools/taosdemoAllTest/insert_5M_rows.json -y " % binPath) + os.system("%staosBenchmark -f tools/taosdemoAllTest/insert_5M_rows.json -y " % binPath) tdDnodes.stop(1) tdDnodes.start(1) tdSql.execute('use db') diff --git a/tests/pytest/client/change_time_1_1.py b/tests/pytest/client/change_time_1_1.py index acdea17fbf1d093cef522d9a99ec17f80b9a4d3b..c66871119b582a133b32f2f57c8c4d95723c5734 100644 --- a/tests/pytest/client/change_time_1_1.py +++ b/tests/pytest/client/change_time_1_1.py @@ -42,7 +42,7 @@ class TDTestCase: #11 data files should be generated #vnode at TDinternal/community/sim/dnode1/data/vnode try: - os.system(f"{binPath}taosdemo -f tools/taosdemoAllTest/manual_change_time_1_1_A.json") + os.system(f"{binPath}taosBenchmark -f tools/taosdemoAllTest/manual_change_time_1_1_A.json") commandArray = ['ls', '-l', f'{TDenginePath}/sim/dnode1/data/vnode/vnode2/tsdb/data'] result = subprocess.run(commandArray, stdout=subprocess.PIPE).stdout.decode('utf-8') except BaseException: @@ -59,7 +59,7 @@ class TDTestCase: #leaving 7 data files. try: os.system ('timedatectl set-time 2020-10-25') - os.system(f"{binPath}taosdemo -f tools/taosdemoAllTest/manual_change_time_1_1_B.json") + os.system(f"{binPath}taosBenchmark -f tools/taosdemoAllTest/manual_change_time_1_1_B.json") except BaseException: os.system('sudo timedatectl set-ntp on') tdLog.sleep(10) diff --git a/tests/pytest/client/change_time_1_2.py b/tests/pytest/client/change_time_1_2.py index ec483b00be34ad52c2b22f77ed8d81fdfc43c068..58fca4e4356b4e198bbb23cabb3fc5072ec003d8 100644 --- a/tests/pytest/client/change_time_1_2.py +++ b/tests/pytest/client/change_time_1_2.py @@ -41,7 +41,7 @@ class TDTestCase: #11 data files should be generated #vnode at TDinternal/community/sim/dnode1/data/vnode try: - os.system(f"{binPath}taosdemo -f tools/taosdemoAllTest/manual_change_time_1_1_A.json") + os.system(f"{binPath}taosBenchmark -f tools/taosdemoAllTest/manual_change_time_1_1_A.json") commandArray = ['ls', '-l', f'{TDenginePath}/sim/dnode1/data/vnode/vnode2/tsdb/data'] result = subprocess.run(commandArray, stdout=subprocess.PIPE).stdout.decode('utf-8') except BaseException: diff --git a/tests/pytest/cluster/TD-3693/multClient.py b/tests/pytest/cluster/TD-3693/multClient.py index 24c27d9de9ff383f412af33e8d5f8318d1032f63..6eae7310fae902f0bb1114e60ef86e6d11370e8b 100644 --- a/tests/pytest/cluster/TD-3693/multClient.py +++ b/tests/pytest/cluster/TD-3693/multClient.py @@ -51,9 +51,9 @@ class TDTestCase: binPath = buildPath+ "/build/bin/" # insert data to cluster'db - os.system("%staosdemo -f cluster/TD-3693/insert1Data.json -y " % binPath) + os.system("%staosBenchmark -f cluster/TD-3693/insert1Data.json -y " % binPath) # multiple new and cloes connection with query data - os.system("%staosdemo -f cluster/TD-3693/insert2Data.json -y " % binPath) + os.system("%staosBenchmark -f cluster/TD-3693/insert2Data.json -y " % binPath) os.system("nohup %staosdemoMul -f cluster/TD-3693/queryCount.json -y & " % binPath) diff --git a/tests/pytest/compress/compressChangeVersion.py b/tests/pytest/compress/compressChangeVersion.py index b7b9ebe6b35dc4729e0dcae705ac7d93c73010e7..ad1c50149bdc0ffa5db8be4d9c4cc191b021e250 100644 --- a/tests/pytest/compress/compressChangeVersion.py +++ b/tests/pytest/compress/compressChangeVersion.py @@ -66,7 +66,7 @@ class TwoClients: # create backgroud db and tb tdSql.execute("drop database if exists db1") - os.system("%staosdemo -f compress/insertDataDb1.json -y " % binPath) + os.system("%staosBenchmark -f compress/insertDataDb1.json -y " % binPath) # create foreground db and tb tdSql.execute("drop database if exists foredb") tdSql.execute("create database foredb") diff --git a/tests/pytest/dockerCluster/taosdemoWrapper.py b/tests/pytest/dockerCluster/taosdemoWrapper.py index 457dd4ee5aa5919951adbcea834d34cd367d3080..f2bd7bbc2307e2676a083c77f573609720c52450 100644 --- a/tests/pytest/dockerCluster/taosdemoWrapper.py +++ b/tests/pytest/dockerCluster/taosdemoWrapper.py @@ -35,11 +35,11 @@ class taosdemoWrapper: def run(self): if self.metadata is None: - os.system("taosdemo -h %s -d %s -t %d -T %d -c %s -a %d -b %s -n %d -t %d -O %d -R %d -w %d -x -y" + os.system("%staosBenchmark -h %s -d %s -t %d -T %d -c %s -a %d -b %s -n %d -t %d -O %d -R %d -w %d -x -y" % (self.host, self.database, self.tables, self.threads, self.configDir, self.replica, self.columnType, self.rowsPerTable, self.disorderRatio, self.disorderRange, self.charTypeLen)) else: - os.system("taosdemo -f %s" % self.metadata) + os.system("%staosBenchmark -f %s" % self.metadata) parser = argparse.ArgumentParser() diff --git a/tests/pytest/fulltest.sh b/tests/pytest/fulltest.sh index 3359931d5437a6007973b8522bb7cc7fe66fbc78..47e535cbd81b9cbc9675493342c1b734ccbeeca2 100755 --- a/tests/pytest/fulltest.sh +++ b/tests/pytest/fulltest.sh @@ -29,6 +29,7 @@ python3 ./test.py -f insert/in_function.py python3 ./test.py -f insert/modify_column.py #python3 ./test.py -f insert/line_insert.py python3 ./test.py -f insert/specialSql.py +python3 ./test.py -f insert/timestamp.py # timezone @@ -44,8 +45,9 @@ python3 ./test.py -f table/tablename-boundary.py python3 ./test.py -f table/max_table_length.py python3 ./test.py -f table/alter_column.py python3 ./test.py -f table/boundary.py -python3 ./test.py -f table/create.py +#python3 ./test.py -f table/create.py python3 ./test.py -f table/del_stable.py +python3 ./test.py -f table/create_db_from_normal_db.py #stable python3 ./test.py -f stable/insert.py @@ -215,7 +217,7 @@ python3 ./test.py -f stable/query_after_reset.py # perfbenchmark python3 ./test.py -f perfbenchmark/bug3433.py #python3 ./test.py -f perfbenchmark/bug3589.py -python3 ./test.py -f perfbenchmark/taosdemoInsert.py +#python3 ./test.py -f perfbenchmark/taosdemoInsert.py #taosdemo python3 test.py -f tools/taosdemoAllTest/taosdemoTestInsertWithJson.py @@ -396,7 +398,7 @@ python3 ./test.py -f tag_lite/alter_tag.py python3 test.py -f tools/taosdemoAllTest/TD-4985/query-limit-offset.py python3 test.py -f tools/taosdemoAllTest/TD-5213/insert4096columns_not_use_taosdemo.py python3 test.py -f tools/taosdemoAllTest/TD-5213/insertSigcolumnsNum4096.py -python3 test.py -f tools/taosdemoAllTest/TD-10539/create_taosdemo.py +#python3 test.py -f tools/taosdemoAllTest/TD-10539/create_taosdemo.py python3 ./test.py -f tag_lite/drop_auto_create.py python3 test.py -f insert/insert_before_use_db.py python3 test.py -f alter/alter_keep.py @@ -421,8 +423,9 @@ python3 ./test.py -f insert/verifyMemToDiskCrash.py python3 ./test.py -f query/queryRegex.py python3 ./test.py -f tools/taosdemoTestdatatype.py #python3 ./test.py -f insert/schemalessInsert.py -#python3 ./test.py -f insert/openTsdbTelnetLinesInsert.py #python3 ./test.py -f insert/openTsdbJsonInsert.py +python3 ./test.py -f insert/openTsdbTelnetLinesInsert.py +python3 ./test.py -f functions/variable_httpDbNameMandatory.py #======================p4-end=============== diff --git a/tests/pytest/functions/variable_httpDbNameMandatory.py b/tests/pytest/functions/variable_httpDbNameMandatory.py new file mode 100644 index 0000000000000000000000000000000000000000..3be620ad1e1631126697d93e388df82be3e9d57c --- /dev/null +++ b/tests/pytest/functions/variable_httpDbNameMandatory.py @@ -0,0 +1,146 @@ +################################################################### +# Copyright (c) 2016 by TAOS Technologies, Inc. +# All rights reserved. +# +# This file is proprietary and confidential to TAOS Technologies. +# No part of this file may be reproduced, stored, transmitted, +# disclosed or used in any form or by any means other than as +# expressly provided by the written permission from Jianhui Tao +# +################################################################### + +# -*- coding: utf-8 -*- + +import sys +import subprocess +import random +import math +import numpy as np +import inspect + +from util.log import * +from util.cases import * +from util.sql import * +from util.dnodes import * +from requests.auth import HTTPBasicAuth +import requests +import json + + +class TDTestCase: + def init(self, conn, logSql): + tdLog.debug(f"start to execute {__file__}") + tdSql.init(conn.cursor(), logSql) + + def getBuildPath(self) -> str: + selfPath = os.path.dirname(os.path.realpath(__file__)) + + if ("community" in selfPath): + projPath = selfPath[:selfPath.find("community")] + else: + projPath = selfPath[:selfPath.find("tests")] + + for root, dirs, files in os.walk(projPath): + if ("taosd" in files): + rootRealPath = os.path.dirname(os.path.realpath(root)) + if ("packaging" not in rootRealPath): + buildPath = root[:len(root) - len("/debug/build/bin")] + break + return buildPath + + def getCfgDir(self) -> str: + selfPath = os.path.dirname(os.path.realpath(__file__)) + + if ("community" in selfPath): + cfgDir = self.getBuildPath() + "/community/sim/dnode1/cfg" + else: + cfgDir = self.getBuildPath() + "/sim/dnode1/cfg" + return cfgDir + + def getCfgFile(self) -> str: + return self.getCfgDir()+"/taos.cfg" + + def rest_query(self,sql,db=''): + host = '127.0.0.1' + user = 'root' + password = 'taosdata' + port =6041 + if db == '': + url = "http://{}:{}/rest/sql".format(host, port ) + else: + url = "http://{}:{}/rest/sql/{}".format(host, port, db ) + try: + r = requests.post(url, + data = 'use db' , + auth = HTTPBasicAuth('root', 'taosdata')) + r = requests.post(url, + data = sql, + auth = HTTPBasicAuth('root', 'taosdata')) + except: + print("REST API Failure (TODO: more info here)") + raise + rj = dict(r.json()['data']) + return rj + + def TS834(self): + tdLog.printNoPrefix("==========TS-782==========") + tdSql.prepare() + + cfgfile = self.getCfgFile() + + tdSql.execute("show variables") + res_com = tdSql.cursor.fetchall() + rescomlist = np.array(res_com) + cpms_index = np.where(rescomlist == "httpDbNameMandatory") + index_value = np.dstack((cpms_index[0])).squeeze() + + tdSql.query("show variables") + tdSql.checkData(index_value, 1, 0) + + rj = self.rest_query("show variables") + if 'httpDbNameMandatory' not in rj: + tdLog.info('has no httpDbNameMandatory shown') + tdLog.exit(1) + if rj['httpDbNameMandatory'] != '0': + tdLog.info('httpDbNameMandatory data:%s == expect:0'%rj['httpDbNameMandatory']) + tdLog.exit(1) + tdLog.info("httpDbNameMandatory by restful query data:%s == expect:0" % (rj['httpDbNameMandatory'])) + + tdSql.query("show dnodes") + index = tdSql.getData(0, 0) + tdLog.info("restart taosd ") + tdDnodes.stop(index) + cmd = f"echo 'httpDbNameMandatory 1' >> {cfgfile} " + try: + _ = subprocess.check_output(cmd, shell=True).decode("utf-8") + except Exception as e: + raise e + + tdDnodes.start(index) + tdSql.query("show variables") + tdSql.checkData(index_value, 1, 1) + + rj = self.rest_query("show variables", 'db') + if 'httpDbNameMandatory' not in rj: + tdLog.info('has no httpDbNameMandatory shown') + tdLog.exit(1) + if rj['httpDbNameMandatory'] != '1': + tdLog.info('httpDbNameMandatory data:%s == expect:0'%rj['httpDbNameMandatory']) + tdLog.exit(1) + tdLog.info("httpDbNameMandatory by restful query data:%s == expect:1" % (rj['httpDbNameMandatory'])) + + def run(self): + + #TS-834 https://jira.taosdata.com:18080/browse/TS-834 + self.TS834() + + def stop(self): + tdSql.close() + tdLog.success(f"{__file__} successfully executed") + + +tdCases.addWindows(__file__, TDTestCase()) +tdCases.addLinux(__file__, TDTestCase()) + + + diff --git a/tests/pytest/import_merge/import_update_0.py b/tests/pytest/import_merge/import_update_0.py index 66e0d7d14420251a227e5f0c2bacec219273d032..269f2e88bbb25c64ef512de9f21cea31196b5c75 100644 --- a/tests/pytest/import_merge/import_update_0.py +++ b/tests/pytest/import_merge/import_update_0.py @@ -1055,7 +1055,7 @@ class TDTestCase: else: tdLog.info("taosd found in %s" % buildPath) binPath = buildPath+ "/build/bin/" - os.system("%staosdemo -N -d taosdemo -t 100 -n 100 -l 1000 -y" % binPath) + os.system("%staosBenchmark -N -d taosdemo -t 100 -n 100 -l 1000 -y" % binPath) tdSql.execute('''insert into table_2 values( %d , NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);''' %(self.ts - 200)) sql = '''select * from table_2 where ts = %d ;''' %(self.ts - 200) diff --git a/tests/pytest/import_merge/import_update_1.py b/tests/pytest/import_merge/import_update_1.py index 7edfd610c2e6eac6588ae78f81c939118845973d..ec204f0e38b7ef48c74105cd3174a379bb2f6df8 100644 --- a/tests/pytest/import_merge/import_update_1.py +++ b/tests/pytest/import_merge/import_update_1.py @@ -1055,7 +1055,7 @@ class TDTestCase: else: tdLog.info("taosd found in %s" % buildPath) binPath = buildPath+ "/build/bin/" - os.system("%staosdemo -N -d taosdemo -t 100 -n 100 -l 1000 -y" % binPath) + os.system("%staosBenchmark -N -d taosdemo -t 100 -n 100 -l 1000 -y" % binPath) tdSql.execute('''insert into table_2 values( %d , NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);''' %(self.ts - 200)) sql = '''select * from table_2 where ts = %d ;''' %(self.ts - 200) diff --git a/tests/pytest/import_merge/import_update_2.py b/tests/pytest/import_merge/import_update_2.py index a0efe31ab25f68a898a124e0be22c369fedabf7f..5baeec674056ee98b18158bfff9e573808e31652 100644 --- a/tests/pytest/import_merge/import_update_2.py +++ b/tests/pytest/import_merge/import_update_2.py @@ -1181,7 +1181,7 @@ class TDTestCase: else: tdLog.info("taosd found in %s" % buildPath) binPath = buildPath+ "/build/bin/" - os.system("%staosdemo -N -d taosdemo -t 100 -n 100 -l 1000 -y" % binPath) + os.system("%staosBenchmark -N -d taosdemo -t 100 -n 100 -l 1000 -y" % binPath) tdLog.info("========== stable ==========") tdSql.execute('''insert into table_2 values( %d , NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);''' %(self.ts - 200)) diff --git a/tests/pytest/insert/openTsdbTelnetLinesInsert.py b/tests/pytest/insert/openTsdbTelnetLinesInsert.py index de27ff7a08cb46a7d7219edaa186edad6f662716..c6a84c7def8301fa6ecd1752f9238731ce922338 100644 --- a/tests/pytest/insert/openTsdbTelnetLinesInsert.py +++ b/tests/pytest/insert/openTsdbTelnetLinesInsert.py @@ -28,6 +28,7 @@ class TDTestCase: tdLog.debug("start to execute %s" % __file__) tdSql.init(conn.cursor(), logSql) self._conn = conn + self.smlChildTableName_value = tdSql.getVariable("smlChildTableName")[0].upper() def createDb(self, name="test", db_update_tag=0): if db_update_tag == 0: @@ -159,14 +160,27 @@ class TDTestCase: td_col_type_list = [] for elm in stb_tag_list: - if "id=" in elm.lower(): - tb_name = elm.split('=')[1] + if self.smlChildTableName_value == "ID": + if "id=" in elm.lower(): + tb_name = elm.split('=')[1] + else: + tag_name_list.append(elm.split("=")[0].lower()) + tag_value_list.append(elm.split("=")[1]) + tb_name = "" + td_tag_value_list.append(self.getTdTypeValue(elm.split("=")[1], "tag")[1]) + td_tag_type_list.append(self.getTdTypeValue(elm.split("=")[1], "tag")[0]) else: - tag_name_list.append(elm.split("=")[0].lower()) - tag_value_list.append(elm.split("=")[1]) - tb_name = "" - td_tag_value_list.append(self.getTdTypeValue(elm.split("=")[1], "tag")[1]) - td_tag_type_list.append(self.getTdTypeValue(elm.split("=")[1], "tag")[0]) + if "id" == elm.split("=")[0].lower(): + tag_name_list.insert(0, elm.split("=")[0]) + tag_value_list.insert(0, elm.split("=")[1]) + td_tag_value_list.insert(0, self.getTdTypeValue(elm.split("=")[1], "tag")[1]) + td_tag_type_list.insert(0, self.getTdTypeValue(elm.split("=")[1], "tag")[0]) + else: + tag_name_list.append(elm.split("=")[0]) + tag_value_list.append(elm.split("=")[1]) + tb_name = "" + td_tag_value_list.append(self.getTdTypeValue(elm.split("=")[1], "tag")[1]) + td_tag_type_list.append(self.getTdTypeValue(elm.split("=")[1], "tag")[0]) col_name_list.append('value') col_value_list.append(stb_col_value) @@ -201,7 +215,7 @@ class TDTestCase: if tb_name == "": tb_name = f'{stb_name}_{random.randint(0, 65535)}_{random.randint(0, 65535)}' if t0 == "": - t0 = random.choice(["f", "F", "false", "False", "t", "T", "true", "True", "TRUE", "FALSE"]) + t0 = "t" if value == "": value = random.choice(["f", "F", "false", "False", "t", "T", "true", "True", "TRUE", "FALSE"]) if id_upper_tag is not None: @@ -232,7 +246,7 @@ class TDTestCase: if c_blank_tag is not None: sql_seq = f'{stb_name} {ts} {id}={tb_name} t0={t0} t1={t1} t2={t2} t3={t3} t4={t4} t5={t5} t6={t6} t7={t7} t8={t8}' if t_blank_tag is not None: - sql_seq = f'{stb_name} {ts} {value} {id}={tb_name}' + sql_seq = f'{stb_name} {ts} {value}' if chinese_tag is not None: sql_seq = f'{stb_name} {ts} L"涛思数据" t0={t0} t1=L"涛思数据"' if multi_field_tag is not None: @@ -260,11 +274,10 @@ class TDTestCase: def genLongSql(self, tag_count): stb_name = tdCom.getLongName(7, mode="letters") - tb_name = f'{stb_name}_1' tag_str = self.genMulTagColStr("tag", tag_count) col_str = self.genMulTagColStr("col") ts = "1626006833641" - long_sql = stb_name + ' ' + ts + ' ' + col_str + ' ' + f'id={tb_name}' + ' ' + tag_str + long_sql = stb_name + ' ' + ts + ' ' + col_str + ' ' + ' ' + tag_str return long_sql, stb_name def getNoIdTbName(self, stb_name): @@ -451,11 +464,11 @@ class TDTestCase: def stbTbNameCheckCase(self): """ test illegal id name - mix "`~!@#$¥%^&*()-+={}|[]、「」【】\:;《》<>?" + mix "`~!@#$¥%^&*()-+{}|[]、「」【】:;《》<>?" """ tdLog.info(f'{sys._getframe().f_code.co_name}() function is running') tdCom.cleanTb() - rstr = list("~!@#$¥%^&*()-+={}|[]、「」【】\:;《》<>?") + rstr = list("~!@#$¥%^&*()-+{}|[]、「」【】:;《》<>?") for i in rstr: input_sql, stb_name = self.genFullTypeSql(tb_name=f"\"aaa{i}bbb\"") self.resCmp(input_sql, f'`{stb_name}`') @@ -524,16 +537,25 @@ class TDTestCase: self.resCmp(input_sql, stb_name) tdSql.query(f'select * from {stb_name}') tdSql.checkRows(1) - for input_sql in [self.genFullTypeSql(stb_name=tdCom.getLongName(len=193, mode="letters"), tb_name=tdCom.getLongName(len=5, mode="letters"))[0], self.genFullTypeSql(tb_name=tdCom.getLongName(len=193, mode="letters"))[0]]: + if self.smlChildTableName_value == "ID": + for input_sql in [self.genFullTypeSql(stb_name=tdCom.getLongName(len=193, mode="letters"), tb_name=tdCom.getLongName(len=5, mode="letters"))[0], self.genFullTypeSql(tb_name=tdCom.getLongName(len=193, mode="letters"))[0]]: + try: + self._conn.schemaless_insert([input_sql], TDSmlProtocolType.TELNET.value, None) + raise Exception("should not reach here") + except SchemalessError as err: + tdSql.checkNotEqual(err.errno, 0) + input_sql = 'Abcdffgg 1626006833640 False T1=127i8 id=Abcddd' + else: + input_sql = self.genFullTypeSql(stb_name=tdCom.getLongName(len=193, mode="letters"), tb_name=tdCom.getLongName(len=5, mode="letters"))[0] try: self._conn.schemaless_insert([input_sql], TDSmlProtocolType.TELNET.value, None) raise Exception("should not reach here") except SchemalessError as err: tdSql.checkNotEqual(err.errno, 0) - - input_sql = 'Abcdffgg 1626006833640 False T1=127i8 id=Abcddd' - stb_name = "Abcdffgg" + input_sql = 'Abcdffgg 1626006833640 False T1=127i8' + stb_name = f'`{input_sql.split(" ")[0]}`' self.resCmp(input_sql, stb_name) + tdSql.execute('drop table `Abcdffgg`') def tagNameLengthCheckCase(self): """ @@ -766,6 +788,7 @@ class TDTestCase: tdSql.checkNotEqual(err.errno, 0) ##### stb exist ##### + @tdCom.smlPass def noIdStbExistCheckCase(self): """ case no id when stb exist @@ -790,6 +813,7 @@ class TDTestCase: self._conn.schemaless_insert([input_sql], TDSmlProtocolType.TELNET.value, None) self.resCmp(input_sql, stb_name) + @tdCom.smlPass def tagColBinaryNcharLengthCheckCase(self): """ check length increase @@ -802,6 +826,7 @@ class TDTestCase: input_sql, stb_name = self.genFullTypeSql(stb_name=stb_name, tb_name=tb_name,t7="\"binaryTagValuebinaryTagValue\"", t8="L\"ncharTagValuencharTagValue\"") self.resCmp(input_sql, stb_name, condition=f'where tbname like "{tb_name}"') + @tdCom.smlPass def tagColAddDupIDCheckCase(self): """ check tag count add, stb and tb duplicate @@ -833,6 +858,7 @@ class TDTestCase: tdSql.checkData(0, 12, None) self.createDb() + @tdCom.smlPass def tagColAddCheckCase(self): """ check tag count add @@ -880,8 +906,7 @@ class TDTestCase: tdLog.info(f'{sys._getframe().f_code.co_name}() function is running') tdCom.cleanTb() stb_name = tdCom.getLongName(7, "letters") - tb_name = f'{stb_name}_1' - input_sql = f'{stb_name} 1626006833640 f id={tb_name} t2={tdCom.getLongName(1, "letters")}' + input_sql = f'{stb_name} 1626006833640 f t2={tdCom.getLongName(1, "letters")}' self._conn.schemaless_insert([input_sql], TDSmlProtocolType.TELNET.value, None) # * legal nchar could not be larger than 16374/4 @@ -1062,15 +1087,24 @@ class TDTestCase: def tbnameTagsColsNameCheckCase(self): tdLog.info(f'{sys._getframe().f_code.co_name}() function is running') tdCom.cleanTb() - input_sql = 'rFa$sta 1626006834 9223372036854775807 id=rFas$ta_1 Tt!0=true tT@1=127Ii8 t#2=32767i16 "t$3"=2147483647i32 t%4=9223372036854775807i64 t^5=11.12345f32 t&6=22.123456789f64 t*7=\"ddzhiksj\" t!@#$%^&*()_+[];:<>?,9=L\"ncharTagValue\"' - self._conn.schemaless_insert([input_sql], TDSmlProtocolType.TELNET.value, None) - query_sql = 'select * from `rfa$sta`' - query_res = tdSql.query(query_sql, True) - tdSql.checkEqual(query_res, [(datetime.datetime(2021, 7, 11, 20, 33, 54), 9.223372036854776e+18, 'true', '127Ii8', '32767i16', '2147483647i32', '9223372036854775807i64', '11.12345f32', '22.123456789f64', '"ddzhiksj"', 'L"ncharTagValue"')]) - col_tag_res = tdSql.getColNameList(query_sql) - tdSql.checkEqual(col_tag_res, ['ts', 'value', 'tt!0', 'tt@1', 't#2', '"t$3"', 't%4', 't^5', 't&6', 't*7', 't!@#$%^&*()_+[];:<>?,9']) - tdSql.execute('drop table `rfa$sta`') - + if self.smlChildTableName_value == "ID": + input_sql = 'rFa$sta 1626006834 9223372036854775807 id=rFas$ta_1 Tt!0=true tT@1=127Ii8 t#2=32767i16 "t$3"=2147483647i32 t%4=9223372036854775807i64 t^5=11.12345f32 t&6=22.123456789f64 t*7=\"ddzhiksj\" t!@#$%^&*()_+[];:<>?,9=L\"ncharTagValue\"' + self._conn.schemaless_insert([input_sql], TDSmlProtocolType.TELNET.value, None) + query_sql = 'select * from `rFa$sta`' + query_res = tdSql.query(query_sql, True) + tdSql.checkEqual(query_res, [(datetime.datetime(2021, 7, 11, 20, 33, 54), 9.223372036854776e+18, 'true', '127Ii8', '32767i16', '2147483647i32', '9223372036854775807i64', '11.12345f32', '22.123456789f64', '"ddzhiksj"', 'L"ncharTagValue"')]) + col_tag_res = tdSql.getColNameList(query_sql) + tdSql.checkEqual(col_tag_res, ['ts', 'value', 'tt!0', 'tt@1', 't#2', '"t$3"', 't%4', 't^5', 't&6', 't*7', 't!@#$%^&*()_+[];:<>?,9']) + tdSql.execute('drop table `rFa$sta`') + else: + input_sql = 'rFa$sta 1626006834 9223372036854775807 Tt!0=true tT@1=127Ii8 t#2=32767i16 "t$3"=2147483647i32 t%4=9223372036854775807i64 t^5=11.12345f32 t&6=22.123456789f64 t*7=\"ddzhiksj\" t!@#$%^&*()_+[];:<>?,9=L\"ncharTagValue\"' + self._conn.schemaless_insert([input_sql], TDSmlProtocolType.TELNET.value, None) + query_sql = 'select * from `rFa$sta`' + query_res = tdSql.query(query_sql, True) + tdSql.checkEqual(query_res, [(datetime.datetime(2021, 7, 11, 20, 33, 54), 9.223372036854776e+18, '2147483647i32', 'L"ncharTagValue"', '32767i16', '9223372036854775807i64', '22.123456789f64', '"ddzhiksj"', '11.12345f32', 'true', '127Ii8')]) + col_tag_res = tdSql.getColNameList(query_sql) + tdSql.checkEqual(col_tag_res, ['ts', 'value', '"t$3"', 't!@#$%^&*()_+[];:<>?,9', 't#2', 't%4', 't&6', 't*7', 't^5', 'Tt!0', 'tT@1']) + tdSql.execute('drop table `rFa$sta`') def genSqlList(self, count=5, stb_name="", tb_name=""): """ stb --> supertable @@ -1153,11 +1187,12 @@ class TDTestCase: s_stb_s_tb_list = self.genSqlList(stb_name=stb_name, tb_name=tb_name)[1] self.multiThreadRun(self.genMultiThreadSeq(s_stb_s_tb_list)) tdSql.query(f"show tables;") - tdSql.checkRows(1) - expected_tb_name = self.getNoIdTbName(stb_name)[0] - tdSql.checkEqual(tb_name, expected_tb_name) + tdSql.checkRows(1) if self.smlChildTableName_value == "ID" else tdSql.checkRows(6) + if self.smlChildTableName_value == "ID": + expected_tb_name = self.getNoIdTbName(stb_name)[0] + tdSql.checkEqual(tb_name, expected_tb_name) tdSql.query(f"select * from {stb_name};") - tdSql.checkRows(1) + tdSql.checkRows(1) if self.smlChildTableName_value == "ID" else tdSql.checkRows(6) def sStbStbDdataAtInsertMultiThreadCheckCase(self): """ @@ -1171,11 +1206,12 @@ class TDTestCase: s_stb_s_tb_a_tag_list = self.genSqlList(stb_name=stb_name, tb_name=tb_name)[2] self.multiThreadRun(self.genMultiThreadSeq(s_stb_s_tb_a_tag_list)) tdSql.query(f"show tables;") - tdSql.checkRows(1) - expected_tb_name = self.getNoIdTbName(stb_name)[0] - tdSql.checkEqual(tb_name, expected_tb_name) + tdSql.checkRows(1) if self.smlChildTableName_value == "ID" else tdSql.checkRows(6) + if self.smlChildTableName_value == "ID": + expected_tb_name = self.getNoIdTbName(stb_name)[0] + tdSql.checkEqual(tb_name, expected_tb_name) tdSql.query(f"select * from {stb_name};") - tdSql.checkRows(1) + tdSql.checkRows(1) if self.smlChildTableName_value == "ID" else tdSql.checkRows(6) def sStbStbDdataMtInsertMultiThreadCheckCase(self): """ @@ -1189,11 +1225,12 @@ class TDTestCase: s_stb_s_tb_m_tag_list = self.genSqlList(stb_name=stb_name, tb_name=tb_name)[3] self.multiThreadRun(self.genMultiThreadSeq(s_stb_s_tb_m_tag_list)) tdSql.query(f"show tables;") - tdSql.checkRows(1) - expected_tb_name = self.getNoIdTbName(stb_name)[0] - tdSql.checkEqual(tb_name, expected_tb_name) + tdSql.checkRows(1) if self.smlChildTableName_value == "ID" else tdSql.checkRows(2) + if self.smlChildTableName_value == "ID": + expected_tb_name = self.getNoIdTbName(stb_name)[0] + tdSql.checkEqual(tb_name, expected_tb_name) tdSql.query(f"select * from {stb_name};") - tdSql.checkRows(1) + tdSql.checkRows(1) if self.smlChildTableName_value == "ID" else tdSql.checkRows(2) def sStbDtbDdataInsertMultiThreadCheckCase(self): """ @@ -1254,7 +1291,7 @@ class TDTestCase: (f'{stb_name} 0 "jitwseso" id={tb_name} t0=T t1=127i8 t2=32767i16 t3=2147483647i32 t4=9223372036854775807i64 t5=11.12345f32 t6=22.123456789f64 t7="yhlwkddq" t8=L"ncharTagValue"', 'dwpthv')] self.multiThreadRun(self.genMultiThreadSeq(s_stb_s_tb_d_ts_list)) tdSql.query(f"show tables;") - tdSql.checkRows(1) + tdSql.checkRows(1) if self.smlChildTableName_value == "ID" else tdSql.checkRows(6) tdSql.query(f"select * from {stb_name}") tdSql.checkRows(6) @@ -1270,11 +1307,11 @@ class TDTestCase: s_stb_s_tb_d_ts_m_tag_list = self.genSqlList(stb_name=stb_name, tb_name=tb_name)[8] self.multiThreadRun(self.genMultiThreadSeq(s_stb_s_tb_d_ts_m_tag_list)) tdSql.query(f"show tables;") - tdSql.checkRows(1) + tdSql.checkRows(1) if self.smlChildTableName_value == "ID" else tdSql.checkRows(2) tdSql.query(f"select * from {stb_name}") tdSql.checkRows(6) tdSql.query(f"select * from {stb_name} where t8 is not NULL") - tdSql.checkRows(6) + tdSql.checkRows(6) if self.smlChildTableName_value == "ID" else tdSql.checkRows(1) def sStbStbDdataDtsAtInsertMultiThreadCheckCase(self): """ @@ -1292,12 +1329,12 @@ class TDTestCase: (f'{stb_name} 0 "tlvzwjes" id={tb_name} t0=true t1=127i8 t2=32767i16 t3=2147483647i32 t4=9223372036854775807i64 t5=11.12345f32 t6=22.123456789f64 t7="enwrlrtj" t8=L"ncharTagValue" t11=127i8 t10=L"ncharTagValue"', 'bokaxl')] self.multiThreadRun(self.genMultiThreadSeq(s_stb_s_tb_d_ts_a_tag_list)) tdSql.query(f"show tables;") - tdSql.checkRows(1) + tdSql.checkRows(1) if self.smlChildTableName_value == "ID" else tdSql.checkRows(6) tdSql.query(f"select * from {stb_name}") tdSql.checkRows(6) for t in ["t10", "t11"]: tdSql.query(f"select * from {stb_name} where {t} is not NULL;") - tdSql.checkRows(0) + tdSql.checkRows(0) if self.smlChildTableName_value == "ID" else tdSql.checkRows(5) def sStbDtbDdataDtsInsertMultiThreadCheckCase(self): """ @@ -1386,7 +1423,7 @@ class TDTestCase: self.sStbDtbDdataMtInsertMultiThreadCheckCase() self.sStbDtbDdataAtInsertMultiThreadCheckCase() self.sStbStbDdataDtsInsertMultiThreadCheckCase() - self.sStbStbDdataDtsMtInsertMultiThreadCheckCase() + # self.sStbStbDdataDtsMtInsertMultiThreadCheckCase() self.sStbStbDdataDtsAtInsertMultiThreadCheckCase() self.sStbDtbDdataDtsInsertMultiThreadCheckCase() self.sStbDtbDdataDtsMtInsertMultiThreadCheckCase() @@ -1395,6 +1432,7 @@ class TDTestCase: print("running {}".format(__file__)) self.createDb() try: + # self.blankTagInsertCheckCase() self.runAll() except Exception as err: print(''.join(traceback.format_exception(None, err, err.__traceback__))) diff --git a/tests/pytest/insert/openTsdbTelnetTaosadapterInsert.py b/tests/pytest/insert/openTsdbTelnetTaosadapterInsert.py new file mode 100644 index 0000000000000000000000000000000000000000..ca8af6c566c60517f9a2e2a72c1aab1e01be5b82 --- /dev/null +++ b/tests/pytest/insert/openTsdbTelnetTaosadapterInsert.py @@ -0,0 +1,1390 @@ +################################################################### +# Copyright (c) 2021 by TAOS Technologies, Inc. +# All rights reserved. +# +# This file is proprietary and confidential to TAOS Technologies. +# No part of this file may be reproduced, stored, transmitted, +# disclosed or used in any form or by any means other than as +# expressly provided by the written permission from Jianhui Tao +# +################################################################### + +# -*- coding: utf-8 -*- + +import traceback +import random +from taos.error import SchemalessError +import time +import numpy as np +from util.log import * +from util.cases import * +from util.sql import * +from util.common import tdCom +from util.types import TDSmlProtocolType, TDSmlTimestampType +import threading +import requests + +class TDTestCase: + def init(self, conn, logSql): + tdLog.debug("start to execute %s" % __file__) + tdSql.init(conn.cursor(), logSql) + self._conn = conn + self.smlChildTableName_value = tdSql.getVariable("smlChildTableName")[0].upper() + + def timeTrans(self, time_value): + if int(time_value) == 0: + ts = time.time() + else: + if len(time_value) == 13: + ts = int(''.join(list(filter(str.isdigit, time_value))))/1000 + elif len(time_value) == 10: + ts = int(''.join(list(filter(str.isdigit, time_value))))/1 + ulsec = repr(ts).split('.')[1][:6] + if len(ulsec) < 6 and int(ulsec) != 0: + ulsec = int(ulsec) * (10 ** (6 - len(ulsec))) + elif int(ulsec) == 0: + ulsec *= 6 + # * follow two rows added for tsCheckCase + td_ts = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(ts)) + return td_ts + #td_ts = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(ts)) + td_ts = time.strftime("%Y-%m-%d %H:%M:%S.{}".format(ulsec), time.localtime(ts)) + return td_ts + #return repr(datetime.datetime.strptime(td_ts, "%Y-%m-%d %H:%M:%S.%f")) + + def getTdTypeValue(self, value, vtype="col"): + if vtype == "col": + if value.lower().endswith("i8"): + td_type = "TINYINT" + td_tag_value = ''.join(list(value)[:-2]) + elif value.lower().endswith("i16"): + td_type = "SMALLINT" + td_tag_value = ''.join(list(value)[:-3]) + elif value.lower().endswith("i32"): + td_type = "INT" + td_tag_value = ''.join(list(value)[:-3]) + elif value.lower().endswith("i64"): + td_type = "BIGINT" + td_tag_value = ''.join(list(value)[:-3]) + elif value.lower().endswith("u64"): + td_type = "BIGINT UNSIGNED" + td_tag_value = ''.join(list(value)[:-3]) + elif value.lower().endswith("f32"): + td_type = "FLOAT" + td_tag_value = ''.join(list(value)[:-3]) + td_tag_value = '{}'.format(np.float32(td_tag_value)) + elif value.lower().endswith("f64"): + td_type = "DOUBLE" + td_tag_value = ''.join(list(value)[:-3]) + if "e" in value.lower(): + td_tag_value = str(float(td_tag_value)) + elif value.lower().startswith('l"'): + td_type = "NCHAR" + td_tag_value = ''.join(list(value)[2:-1]) + elif value.startswith('"') and value.endswith('"'): + td_type = "BINARY" + td_tag_value = ''.join(list(value)[1:-1]) + elif value.lower() == "t" or value.lower() == "true": + td_type = "BOOL" + td_tag_value = "True" + elif value.lower() == "f" or value.lower() == "false": + td_type = "BOOL" + td_tag_value = "False" + elif value.isdigit(): + td_type = "DOUBLE" + td_tag_value = str(float(value)) + else: + td_type = "DOUBLE" + if "e" in value.lower(): + td_tag_value = str(float(value)) + else: + td_tag_value = value + elif vtype == "tag": + td_type = "NCHAR" + td_tag_value = str(value) + return td_type, td_tag_value + + def typeTrans(self, type_list): + type_num_list = [] + for tp in type_list: + if tp.upper() == "TIMESTAMP": + type_num_list.append(9) + elif tp.upper() == "BOOL": + type_num_list.append(1) + elif tp.upper() == "TINYINT": + type_num_list.append(2) + elif tp.upper() == "SMALLINT": + type_num_list.append(3) + elif tp.upper() == "INT": + type_num_list.append(4) + elif tp.upper() == "BIGINT": + type_num_list.append(5) + elif tp.upper() == "FLOAT": + type_num_list.append(6) + elif tp.upper() == "DOUBLE": + type_num_list.append(7) + elif tp.upper() == "BINARY": + type_num_list.append(8) + elif tp.upper() == "NCHAR": + type_num_list.append(10) + elif tp.upper() == "BIGINT UNSIGNED": + type_num_list.append(14) + return type_num_list + + def inputHandle(self, input_sql): + input_sql_split_list = input_sql.split(" ") + stb_name = input_sql_split_list[0] + stb_tag_list = input_sql_split_list[3:] + stb_col_value = input_sql_split_list[2] + ts_value = self.timeTrans(input_sql_split_list[1]) + + tag_name_list = [] + tag_value_list = [] + td_tag_value_list = [] + td_tag_type_list = [] + + col_name_list = [] + col_value_list = [] + td_col_value_list = [] + td_col_type_list = [] + + for elm in stb_tag_list: + if self.smlChildTableName_value == "ID": + if "id=" in elm.lower(): + tb_name = elm.split('=')[1] + else: + tag_name_list.append(elm.split("=")[0]) + tag_value_list.append(elm.split("=")[1]) + tb_name = "" + td_tag_value_list.append(self.getTdTypeValue(elm.split("=")[1], "tag")[1]) + td_tag_type_list.append(self.getTdTypeValue(elm.split("=")[1], "tag")[0]) + else: + if "id" == elm.split("=")[0].lower(): + tag_name_list.insert(0, elm.split("=")[0]) + tag_value_list.insert(0, elm.split("=")[1]) + td_tag_value_list.insert(0, self.getTdTypeValue(elm.split("=")[1], "tag")[1]) + td_tag_type_list.insert(0, self.getTdTypeValue(elm.split("=")[1], "tag")[0]) + else: + tag_name_list.append(elm.split("=")[0]) + tag_value_list.append(elm.split("=")[1]) + tb_name = "" + td_tag_value_list.append(self.getTdTypeValue(elm.split("=")[1], "tag")[1]) + td_tag_type_list.append(self.getTdTypeValue(elm.split("=")[1], "tag")[0]) + + col_name_list.append('value') + col_value_list.append(stb_col_value) + + td_col_value_list.append(self.getTdTypeValue(stb_col_value)[1]) + td_col_type_list.append(self.getTdTypeValue(stb_col_value)[0]) + + final_field_list = [] + final_field_list.extend(col_name_list) + final_field_list.extend(tag_name_list) + + final_type_list = [] + final_type_list.append("TIMESTAMP") + final_type_list.extend(td_col_type_list) + final_type_list.extend(td_tag_type_list) + final_type_list = self.typeTrans(final_type_list) + + final_value_list = [] + final_value_list.append(ts_value) + final_value_list.extend(td_col_value_list) + final_value_list.extend(td_tag_value_list) + return final_value_list, final_field_list, final_type_list, stb_name, tb_name + + def genFullTypeSql(self, stb_name="", tb_name="", value="", t0="", t1="127i8", t2="32767i16", t3="2147483647i32", + t4="9223372036854775807i64", t5="11.12345f32", t6="22.123456789f64", t7="\"binaryTagValue\"", + t8="L\"ncharTagValue\"", ts="1626006833641", + id_noexist_tag=None, id_change_tag=None, id_upper_tag=None, id_mixul_tag=None, id_double_tag=None, + t_add_tag=None, t_mul_tag=None, c_multi_tag=None, c_blank_tag=None, t_blank_tag=None, + chinese_tag=None, multi_field_tag=None, point_trans_tag=None): + if stb_name == "": + stb_name = tdCom.getLongName(len=6, mode="letters") + if tb_name == "": + tb_name = f'{stb_name}_{random.randint(0, 65535)}_{random.randint(0, 65535)}' + if t0 == "": + t0 = "t" + if value == "": + value = random.choice(["f", "F", "false", "False", "t", "T", "true", "True", "TRUE", "FALSE"]) + if id_upper_tag is not None: + id = "ID" + else: + id = "id" + if id_mixul_tag is not None: + id = random.choice(["iD", "Id"]) + else: + id = "id" + sql_seq = f'{stb_name} {ts} {value} {id}={tb_name} t0={t0} t1={t1} t2={t2} t3={t3} t4={t4} t5={t5} t6={t6} t7={t7} t8={t8}' + if id_noexist_tag is not None: + sql_seq = f'{stb_name} {ts} {value} t0={t0} t1={t1} t2={t2} t3={t3} t4={t4} t5={t5} t6={t6} t7={t7} t8={t8}' + if t_add_tag is not None: + sql_seq = f'{stb_name} {ts} {value} t0={t0} t1={t1} t2={t2} t3={t3} t4={t4} t5={t5} t6={t6} t7={t7} t8={t8} t9={t8}' + if id_change_tag is not None: + sql_seq = f'{stb_name} {ts} {value} t0={t0} {id}={tb_name} t1={t1} t2={t2} t3={t3} t4={t4} t5={t5} t6={t6} t7={t7} t8={t8}' + if id_double_tag is not None: + sql_seq = f'{stb_name} {ts} {value} {id}=\"{tb_name}_1\" t0={t0} t1={t1} {id}=\"{tb_name}_2\" t2={t2} t3={t3} t4={t4} t5={t5} t6={t6} t7={t7} t8={t8}' + if t_add_tag is not None: + sql_seq = f'{stb_name} {ts} {value} {id}={tb_name} t0={t0} t1={t1} t2={t2} t3={t3} t4={t4} t5={t5} t6={t6} t7={t7} t8={t8} t11={t1} t10={t8}' + if t_mul_tag is not None: + sql_seq = f'{stb_name} {ts} {value} {id}={tb_name} t0={t0} t1={t1} t2={t2} t3={t3} t4={t4} t5={t5} t6={t6}' + if id_noexist_tag is not None: + sql_seq = f'{stb_name} {ts} {value} t0={t0} t1={t1} t2={t2} t3={t3} t4={t4} t5={t5} t6={t6}' + if c_multi_tag is not None: + sql_seq = f'{stb_name} {ts} {value} {value} {id}={tb_name} t0={t0} t1={t1} t2={t2} t3={t3} t4={t4} t5={t5} t6={t6}' + if c_blank_tag is not None: + sql_seq = f'{stb_name} {ts} {id}={tb_name} t0={t0} t1={t1} t2={t2} t3={t3} t4={t4} t5={t5} t6={t6} t7={t7} t8={t8}' + if t_blank_tag is not None: + sql_seq = f'{stb_name} {ts} {value}' + if chinese_tag is not None: + sql_seq = f'{stb_name} {ts} L"涛思数据" t0={t0} t1=L"涛思数据"' + if multi_field_tag is not None: + sql_seq = f'{stb_name} {ts} {value} {id}={tb_name} t0={t0} {value}' + if point_trans_tag is not None: + sql_seq = f'.point.trans.test {ts} {value} t0={t0}' + return sql_seq, stb_name + + def genMulTagColStr(self, genType, count=1): + """ + genType must be tag/col + """ + tag_str = "" + col_str = "" + if genType == "tag": + for i in range(0, count): + if i < (count-1): + tag_str += f't{i}=f ' + else: + tag_str += f't{i}=f' + return tag_str + if genType == "col": + col_str = "t" + return col_str + + def genLongSql(self, tag_count): + stb_name = tdCom.getLongName(7, mode="letters") + tag_str = self.genMulTagColStr("tag", tag_count) + col_str = self.genMulTagColStr("col") + ts = "1626006833641" + long_sql = stb_name + ' ' + ts + ' ' + col_str + ' ' + ' ' + tag_str + return long_sql, stb_name + + def getNoIdTbName(self, stb_name): + query_sql = f"select tbname from {stb_name}" + tb_name = self.resHandle(query_sql, True)[0][0] + return tb_name + + def resHandle(self, query_sql, query_tag): + tdSql.execute('reset query cache') + row_info = tdSql.query(query_sql, query_tag) + col_info = tdSql.getColNameList(query_sql, query_tag) + res_row_list = [] + sub_list = [] + for row_mem in row_info: + for i in row_mem: + sub_list.append(str(i)) + res_row_list.append(sub_list) + res_field_list_without_ts = col_info[0][1:] + res_type_list = col_info[1] + return res_row_list, res_field_list_without_ts, res_type_list + + def resCmp(self, input_sql, stb_name, query_sql="select * from", condition="", ts=None, none_check_tag=None, precision=None): + expect_list = self.inputHandle(input_sql) + res = tdCom.schemalessApiPost(sql=input_sql, url_type="telnet") + query_sql = f"{query_sql} {stb_name} {condition}" + res_row_list, res_field_list_without_ts, res_type_list = self.resHandle(query_sql, True) + if ts == 0: + res_ts = tdCom.dateToTs(res_row_list[0][0]) + current_time = time.time() + if current_time - res_ts < 60: + tdSql.checkEqual(res_row_list[0][1:], expect_list[0][1:]) + else: + print("timeout") + tdSql.checkEqual(res_row_list[0], expect_list[0]) + else: + if none_check_tag is not None: + none_index_list = [i for i,x in enumerate(res_row_list[0]) if x=="None"] + none_index_list.reverse() + for j in none_index_list: + res_row_list[0].pop(j) + expect_list[0].pop(j) + tdSql.checkEqual(res_row_list[0], expect_list[0]) + tdSql.checkEqual(res_field_list_without_ts, expect_list[1]) + for i in range(len(res_type_list)): + tdSql.checkEqual(res_type_list[i], expect_list[2][i]) + tdSql.checkEqual(res.status_code, 200) + + def initCheckCase(self): + """ + normal tags and cols, one for every elm + """ + tdLog.info(f'{sys._getframe().f_code.co_name}() function is running') + tdCom.cleanTb(type="restful") + input_sql, stb_name = self.genFullTypeSql() + self.resCmp(input_sql, stb_name) + + def boolTypeCheckCase(self): + """ + check all normal type + """ + tdLog.info(f'{sys._getframe().f_code.co_name}() function is running') + tdCom.cleanTb(type="restful") + full_type_list = ["f", "F", "false", "False", "t", "T", "true", "True"] + for t_type in full_type_list: + input_sql, stb_name = self.genFullTypeSql(t0=t_type) + self.resCmp(input_sql, stb_name) + + def symbolsCheckCase(self): + """ + check symbols = `~!@#$%^&*()_-+={[}]\|:;'\",<.>/? + """ + ''' + please test : + binary_symbols = '\"abcd`~!@#$%^&*()_-{[}]|:;<.>?lfjal"\'\'"\"' + ''' + tdLog.info(f'{sys._getframe().f_code.co_name}() function is running') + tdCom.cleanTb(type="restful") + binary_symbols = '"abcd`~!@#$%^&*()_-{[}]|:;<.>?lfjal"' + nchar_symbols = f'L{binary_symbols}' + input_sql1, stb_name1 = self.genFullTypeSql(value=binary_symbols, t7=binary_symbols, t8=nchar_symbols) + input_sql2, stb_name2 = self.genFullTypeSql(value=nchar_symbols, t7=binary_symbols, t8=nchar_symbols) + self.resCmp(input_sql1, stb_name1) + self.resCmp(input_sql2, stb_name2) + + def tsCheckCase(self): + """ + test ts list --> ["1626006833640ms", "1626006834s", "1626006822639022"] + """ + tdLog.info(f'{sys._getframe().f_code.co_name}() function is running') + tdCom.cleanTb(type="restful") + input_sql, stb_name = self.genFullTypeSql(ts=1626006833640) + self.resCmp(input_sql, stb_name) + input_sql, stb_name = self.genFullTypeSql(ts=1626006833640) + self.resCmp(input_sql, stb_name) + input_sql, stb_name = self.genFullTypeSql(ts=1626006834) + self.resCmp(input_sql, stb_name) + + tdCom.restApiPost("drop database if exists test_ts") + tdCom.restApiPost("create database if not exists test_ts precision 'ms'") + tdSql.execute("use test_ts") + input_sql = 'test_ms 1626006833640 t t0=t\ntest_ms 1626006833641 f t0=t' + tdCom.schemalessApiPost(input_sql, url_type="telnet", dbname="test_ts") + res = tdSql.query('select * from test_ms', True) + tdSql.checkEqual(str(res[0][0]), "2021-07-11 20:33:53.640000") + tdSql.checkEqual(str(res[1][0]), "2021-07-11 20:33:53.641000") + tdCom.createDb(api_type="restful") + + def openTstbTelnetTsCheckCase(self): + tdLog.info(f'{sys._getframe().f_code.co_name}() function is running') + tdCom.cleanTb(type="restful") + input_sql = f'{tdCom.getLongName(len=10, mode="letters")} 0 127 t0=127 t1=32767I16 t2=2147483647I32 t3=9223372036854775807 t4=11.12345027923584F32 t5=22.123456789F64' + stb_name = input_sql.split(" ")[0] + self.resCmp(input_sql, stb_name, ts=0) + input_sql = f'{tdCom.getLongName(len=10, mode="letters")} 1626006833640 127 t0=127 t1=32767I16 t2=2147483647I32 t3=9223372036854775807 t4=11.12345027923584F32 t5=22.123456789F64' + stb_name = input_sql.split(" ")[0] + self.resCmp(input_sql, stb_name) + input_sql = f'{tdCom.getLongName(len=10, mode="letters")} 1626006834 127 t0=127 t1=32767I16 t2=2147483647I32 t3=9223372036854775807 t4=11.12345027923584F32 t5=22.123456789F64' + stb_name = input_sql.split(" ")[0] + self.resCmp(input_sql, stb_name) + for ts in [1, 12, 123, 1234, 12345, 123456, 1234567, 12345678, 162600683, 16260068341, 162600683412, 16260068336401]: + input_sql = f'{tdCom.getLongName(len=10, mode="letters")} {ts} 127 t0=127 t1=32767I16 t2=2147483647I32 t3=9223372036854775807 t4=11.12345027923584F32 t5=22.123456789F64' + res = tdCom.schemalessApiPost(sql=input_sql, url_type="telnet") + tdSql.checkEqual(res.status_code, 500) + tdSql.checkIn("Invalid combination of client/service time", res.text) + + + def idSeqCheckCase(self): + """ + check id.index in tags + eg: t0=**,id=**,t1=** + """ + tdLog.info(f'{sys._getframe().f_code.co_name}() function is running') + tdCom.cleanTb(type="restful") + input_sql, stb_name = self.genFullTypeSql(id_change_tag=True) + self.resCmp(input_sql, stb_name) + + @tdCom.smlPass + def idLetterCheckCase(self): + """ + check id param + eg: id and ID + """ + tdLog.info(f'{sys._getframe().f_code.co_name}() function is running') + tdCom.cleanTb(type="restful") + input_sql, stb_name = self.genFullTypeSql(id_upper_tag=True) + self.resCmp(input_sql, stb_name) + input_sql, stb_name = self.genFullTypeSql(id_mixul_tag=True) + self.resCmp(input_sql, stb_name) + input_sql, stb_name = self.genFullTypeSql(id_change_tag=True, id_upper_tag=True) + self.resCmp(input_sql, stb_name) + + def noIdCheckCase(self): + """ + id not exist + """ + tdLog.info(f'{sys._getframe().f_code.co_name}() function is running') + tdCom.cleanTb(type="restful") + input_sql, stb_name = self.genFullTypeSql(id_noexist_tag=True) + self.resCmp(input_sql, stb_name) + query_sql = f"select tbname from {stb_name}" + res_row_list = self.resHandle(query_sql, True)[0] + if len(res_row_list[0][0]) > 0: + tdSql.checkColNameList(res_row_list, res_row_list) + else: + tdSql.checkColNameList(res_row_list, "please check noIdCheckCase") + + def maxColTagCheckCase(self): + """ + max tag count is 128 + """ + tdLog.info(f'{sys._getframe().f_code.co_name}() function is running') + for input_sql in [self.genLongSql(128)[0]]: + tdCom.cleanTb(type="restful") + tdCom.schemalessApiPost(sql=input_sql, url_type="telnet") + for input_sql in [self.genLongSql(129)[0]]: + tdCom.cleanTb(type="restful") + res = tdCom.schemalessApiPost(sql=input_sql, url_type="telnet") + tdSql.checkEqual(res.status_code, 500) + tdSql.checkIn("Table does not exist", res.text) + + def stbTbNameCheckCase(self): + """ + test illegal id name + mix "`~!@#$¥%^&*()-+{}|[]、「」【】:;《》<>?" + """ + tdLog.info(f'{sys._getframe().f_code.co_name}() function is running') + tdCom.cleanTb(type="restful") + rstr = list("~!@#$¥%^&*()-+{}|[]、「」【】:;《》<>?") + for i in rstr: + input_sql, stb_name = self.genFullTypeSql(tb_name=f"\"aaa{i}bbb\"") + self.resCmp(input_sql, f'`{stb_name}`') + tdCom.restApiPost(f'drop table if exists `{stb_name}`') + + def idStartWithNumCheckCase(self): + """ + id is start with num + """ + tdLog.info(f'{sys._getframe().f_code.co_name}() function is running') + tdCom.cleanTb(type="restful") + input_sql, stb_name = self.genFullTypeSql(tb_name="1aaabbb") + self.resCmp(input_sql, stb_name) + + def nowTsCheckCase(self): + """ + check now unsupported + """ + tdLog.info(f'{sys._getframe().f_code.co_name}() function is running') + tdCom.cleanTb(type="restful") + input_sql = self.genFullTypeSql(ts="now")[0] + res = tdCom.schemalessApiPost(sql=input_sql, url_type="telnet") + tdSql.checkEqual(res.status_code, 500) + tdSql.checkIn("Invalid combination of client/service time", res.text) + + def dateFormatTsCheckCase(self): + """ + check date format ts unsupported + """ + tdLog.info(f'{sys._getframe().f_code.co_name}() function is running') + tdCom.cleanTb(type="restful") + input_sql = self.genFullTypeSql(ts="2021-07-21\ 19:01:46.920")[0] + res = tdCom.schemalessApiPost(sql=input_sql, url_type="telnet") + tdSql.checkEqual(res.status_code, 500) + tdSql.checkIn("Invalid combination of client/service time", res.text) + + def illegalTsCheckCase(self): + """ + check ts format like 16260068336390us19 + """ + tdLog.info(f'{sys._getframe().f_code.co_name}() function is running') + tdCom.cleanTb(type="restful") + input_sql = self.genFullTypeSql(ts="16260068336390us19")[0] + res = tdCom.schemalessApiPost(sql=input_sql, url_type="telnet") + tdSql.checkEqual(res.status_code, 500) + tdSql.checkIn("Invalid combination of client/service time", res.text) + + def tbnameCheckCase(self): + """ + check length 192 + check upper tbname + chech upper tag + length of stb_name tb_name <= 192 + """ + tdLog.info(f'{sys._getframe().f_code.co_name}() function is running') + stb_name_192 = tdCom.getLongName(len=192, mode="letters") + tb_name_192 = tdCom.getLongName(len=192, mode="letters") + tdCom.cleanTb(type="restful") + input_sql, stb_name = self.genFullTypeSql(stb_name=stb_name_192, tb_name=tb_name_192) + self.resCmp(input_sql, stb_name) + tdSql.query(f'select * from {stb_name}') + tdSql.checkRows(1) + if self.smlChildTableName_value == "ID": + for input_sql in [self.genFullTypeSql(stb_name=tdCom.getLongName(len=193, mode="letters"), tb_name=tdCom.getLongName(len=5, mode="letters"))[0], self.genFullTypeSql(tb_name=tdCom.getLongName(len=193, mode="letters"))[0]]: + res = tdCom.schemalessApiPost(sql=input_sql, url_type="telnet") + tdSql.checkEqual(res.status_code, 500) + tdSql.checkIn("Table name too long", res.text) + input_sql = 'Abcdffgg 1626006833640 False T1=127i8 id=Abcddd' + else: + input_sql = self.genFullTypeSql(stb_name=tdCom.getLongName(len=193, mode="letters"), tb_name=tdCom.getLongName(len=5, mode="letters"))[0] + res = tdCom.schemalessApiPost(sql=input_sql, url_type="telnet") + tdSql.checkEqual(res.status_code, 500) + tdSql.checkIn("Table name too long", res.text) + input_sql = 'Abcdffgg 1626006833640 False T1=127i8' + stb_name = f'`{input_sql.split(" ")[0]}`' + self.resCmp(input_sql, stb_name) + tdCom.restApiPost('drop table `Abcdffgg`') + + def tagNameLengthCheckCase(self): + """ + check tag name limit <= 62 + """ + tdLog.info(f'{sys._getframe().f_code.co_name}() function is running') + tdCom.cleanTb(type="restful") + tag_name = tdCom.getLongName(61, "letters") + tag_name = f'T{tag_name}' + stb_name = tdCom.getLongName(7, "letters") + input_sql = f'{stb_name} 1626006833640 L"bcdaaa" {tag_name}=f' + self.resCmp(input_sql, stb_name) + input_sql = f'{stb_name} 1626006833640 L"gggcdaaa" {tdCom.getLongName(65, "letters")}=f' + res = tdCom.schemalessApiPost(sql=input_sql, url_type="telnet") + tdSql.checkEqual(res.status_code, 500) + tdSql.checkIn("Invalid column length", res.text) + + def tagValueLengthCheckCase(self): + """ + check full type tag value limit + """ + tdLog.info(f'{sys._getframe().f_code.co_name}() function is running') + tdCom.cleanTb(type="restful") + # nchar + # * legal nchar could not be larger than 16374/4 + stb_name = tdCom.getLongName(7, "letters") + input_sql = f'{stb_name} 1626006833640 t t0=t t1={tdCom.getLongName(4093, "letters")}' + tdCom.schemalessApiPost(sql=input_sql, url_type="telnet") + + input_sql = f'{stb_name} 1626006833640 t t0=t t1={tdCom.getLongName(4094, "letters")}' + res = tdCom.schemalessApiPost(sql=input_sql, url_type="telnet") + tdSql.checkEqual(res.status_code, 500) + tdSql.checkIn("Invalid operation", res.text) + + def colValueLengthCheckCase(self): + """ + check full type col value limit + """ + tdLog.info(f'{sys._getframe().f_code.co_name}() function is running') + tdCom.cleanTb(type="restful") + # i8 + for value in ["-127i8", "127i8"]: + input_sql, stb_name = self.genFullTypeSql(value=value) + self.resCmp(input_sql, stb_name) + tdCom.cleanTb(type="restful") + for value in ["-128i8", "128i8"]: + input_sql = self.genFullTypeSql(value=value)[0] + res = tdCom.schemalessApiPost(sql=input_sql, url_type="telnet") + tdSql.checkEqual(res.status_code, 500) + tdSql.checkIn("Invalid value in client", res.text) + # i16 + tdCom.cleanTb(type="restful") + for value in ["-32767i16"]: + input_sql, stb_name = self.genFullTypeSql(value=value) + self.resCmp(input_sql, stb_name) + tdCom.cleanTb(type="restful") + for value in ["-32768i16", "32768i16"]: + input_sql = self.genFullTypeSql(value=value)[0] + res = tdCom.schemalessApiPost(sql=input_sql, url_type="telnet") + tdSql.checkEqual(res.status_code, 500) + tdSql.checkIn("Invalid value in client", res.text) + + # i32 + tdCom.cleanTb(type="restful") + for value in ["-2147483647i32"]: + input_sql, stb_name = self.genFullTypeSql(value=value) + self.resCmp(input_sql, stb_name) + tdCom.cleanTb(type="restful") + for value in ["-2147483648i32", "2147483648i32"]: + input_sql = self.genFullTypeSql(value=value)[0] + res = tdCom.schemalessApiPost(sql=input_sql, url_type="telnet") + tdSql.checkEqual(res.status_code, 500) + tdSql.checkIn("Invalid value in client", res.text) + + # i64 + tdCom.cleanTb(type="restful") + for value in ["-9223372036854775807i64"]: + input_sql, stb_name = self.genFullTypeSql(value=value) + self.resCmp(input_sql, stb_name) + tdCom.cleanTb(type="restful") + for value in ["-9223372036854775808i64", "9223372036854775808i64"]: + input_sql = self.genFullTypeSql(value=value)[0] + res = tdCom.schemalessApiPost(sql=input_sql, url_type="telnet") + tdSql.checkEqual(res.status_code, 500) + tdSql.checkIn("Invalid value in client", res.text) + + # f32 + tdCom.cleanTb(type="restful") + for value in [f"{-3.4028234663852885981170418348451692544*(10**38)}f32", f"{3.4028234663852885981170418348451692544*(10**38)}f32"]: + input_sql, stb_name = self.genFullTypeSql(value=value) + self.resCmp(input_sql, stb_name) + # * limit set to 4028234664*(10**38) + tdCom.cleanTb(type="restful") + for value in [f"{-3.4028234664*(10**38)}f32", f"{3.4028234664*(10**38)}f32"]: + input_sql = self.genFullTypeSql(value=value)[0] + res = tdCom.schemalessApiPost(sql=input_sql, url_type="telnet") + tdSql.checkEqual(res.status_code, 500) + tdSql.checkIn("Invalid value in client", res.text) + + # f64 + tdCom.cleanTb(type="restful") + for value in [f'{-1.79769313486231570814527423731704356798070567525844996598917476803157260780*(10**308)}f64', f'{-1.79769313486231570814527423731704356798070567525844996598917476803157260780*(10**308)}f64']: + input_sql, stb_name = self.genFullTypeSql(value=value) + self.resCmp(input_sql, stb_name) + # * limit set to 1.797693134862316*(10**308) + tdCom.cleanTb(type="restful") + for value in [f'{-1.797693134862316*(10**308)}f64', f'{-1.797693134862316*(10**308)}f64']: + input_sql = self.genFullTypeSql(value=value)[0] + res = tdCom.schemalessApiPost(sql=input_sql, url_type="telnet") + tdSql.checkEqual(res.status_code, 500) + tdSql.checkIn("Invalid value in client", res.text) + + # # binary + tdCom.cleanTb(type="restful") + stb_name = tdCom.getLongName(7, "letters") + input_sql = f'{stb_name} 1626006833640 "{tdCom.getLongName(16374, "letters")}" t0=t' + tdCom.schemalessApiPost(sql=input_sql, url_type="telnet") + + tdCom.cleanTb(type="restful") + input_sql = f'{stb_name} 1626006833640 "{tdCom.getLongName(16375, "letters")}" t0=t' + res = tdCom.schemalessApiPost(sql=input_sql, url_type="telnet") + tdSql.checkEqual(res.status_code, 500) + tdSql.checkIn("Table does not exist", res.text) + + # nchar + # * legal nchar could not be larger than 16374/4 + tdCom.cleanTb(type="restful") + stb_name = tdCom.getLongName(7, "letters") + input_sql = f'{stb_name} 1626006833640 L"{tdCom.getLongName(4093, "letters")}" t0=t' + tdCom.schemalessApiPost(sql=input_sql, url_type="telnet") + + tdCom.cleanTb(type="restful") + input_sql = f'{stb_name} 1626006833640 L"{tdCom.getLongName(4094, "letters")}" t0=t' + res = tdCom.schemalessApiPost(sql=input_sql, url_type="telnet") + tdSql.checkEqual(res.status_code, 500) + tdSql.checkIn("Table does not exist", res.text) + + def tagColIllegalValueCheckCase(self): + + """ + test illegal tag col value + """ + tdLog.info(f'{sys._getframe().f_code.co_name}() function is running') + tdCom.cleanTb(type="restful") + # bool + for i in ["TrUe", "tRue", "trUe", "truE", "FalsE", "fAlse", "faLse", "falSe", "falsE"]: + input_sql1, stb_name = self.genFullTypeSql(t0=i) + self.resCmp(input_sql1, stb_name) + input_sql2, stb_name = self.genFullTypeSql(value=i) + self.resCmp(input_sql2, stb_name) + + # i8 i16 i32 i64 f32 f64 + for input_sql in [ + self.genFullTypeSql(value="1s2i8")[0], + self.genFullTypeSql(value="1s2i16")[0], + self.genFullTypeSql(value="1s2i32")[0], + self.genFullTypeSql(value="1s2i64")[0], + self.genFullTypeSql(value="11.1s45f32")[0], + self.genFullTypeSql(value="11.1s45f64")[0], + ]: + res = tdCom.schemalessApiPost(sql=input_sql, url_type="telnet") + tdSql.checkEqual(res.status_code, 500) + tdSql.checkIn("Invalid value in client", res.text) + + # check accepted binary and nchar symbols + # # * ~!@#$¥%^&*()-+={}|[]、「」:; + for symbol in list('~!@#$¥%^&*()-+{}|[]、「」:;'): + input_sql1 = f'{tdCom.getLongName(7, "letters")} 1626006833640 "abc{symbol}aaa" t0=t' + input_sql2 = f'{tdCom.getLongName(7, "letters")} 1626006833640 t t0=t t1="abc{symbol}aaa"' + self.resCmp(input_sql1, input_sql1.split(" ")[0]) + self.resCmp(input_sql2, input_sql2.split(" ")[0]) + + def blankCheckCase(self): + ''' + check blank case + ''' + tdLog.info(f'{sys._getframe().f_code.co_name}() function is running') + tdCom.cleanTb(type="restful") + input_sql_list = [f'{tdCom.getLongName(7, "letters")} 1626006833640 "abc aaa" t0=t', + f'{tdCom.getLongName(7, "letters")} 1626006833640 t t0="abaaa"', + f'{tdCom.getLongName(7, "letters")} 1626006833640 t t0=L"abaaa"', + f'{tdCom.getLongName(7, "letters")} 1626006833640 L"aba aa" t0=L"abcaaa3" '] + for input_sql in input_sql_list: + stb_name = input_sql.split(" ")[0] + tdCom.schemalessApiPost(sql=input_sql, url_type="telnet") + tdSql.query(f'select * from {stb_name}') + tdSql.checkRows(1) + + def duplicateIdTagColInsertCheckCase(self): + """ + check duplicate Id Tag Col + """ + tdLog.info(f'{sys._getframe().f_code.co_name}() function is running') + tdCom.cleanTb(type="restful") + input_sql_id = self.genFullTypeSql(id_double_tag=True)[0] + res = tdCom.schemalessApiPost(sql=input_sql_id, url_type="telnet") + tdSql.checkEqual(res.status_code, 500) + tdSql.checkIn("duplicated tag names", res.text) + + input_sql = self.genFullTypeSql()[0] + input_sql_tag = input_sql.replace("t5", "t6") + res = tdCom.schemalessApiPost(sql=input_sql_tag, url_type="telnet") + tdSql.checkEqual(res.status_code, 500) + tdSql.checkIn("duplicated tag names", res.text) + + ##### stb exist ##### + @tdCom.smlPass + def noIdStbExistCheckCase(self): + """ + case no id when stb exist + """ + tdLog.info(f'{sys._getframe().f_code.co_name}() function is running') + tdCom.cleanTb(type="restful") + input_sql, stb_name = self.genFullTypeSql(tb_name="sub_table_0123456", t0="f", value="f") + self.resCmp(input_sql, stb_name) + input_sql, stb_name = self.genFullTypeSql(stb_name=stb_name, id_noexist_tag=True, t0="f", value="f") + self.resCmp(input_sql, stb_name, condition='where tbname like "t_%"') + tdSql.query(f"select * from {stb_name}") + tdSql.checkRows(2) + + def duplicateInsertExistCheckCase(self): + """ + check duplicate insert when stb exist + """ + tdLog.info(f'{sys._getframe().f_code.co_name}() function is running') + tdCom.cleanTb(type="restful") + input_sql, stb_name = self.genFullTypeSql() + self.resCmp(input_sql, stb_name) + tdCom.schemalessApiPost(sql=input_sql, url_type="telnet") + self.resCmp(input_sql, stb_name) + + @tdCom.smlPass + def tagColBinaryNcharLengthCheckCase(self): + """ + check length increase + """ + tdLog.info(f'{sys._getframe().f_code.co_name}() function is running') + tdCom.cleanTb(type="restful") + input_sql, stb_name = self.genFullTypeSql() + self.resCmp(input_sql, stb_name) + tb_name = tdCom.getLongName(5, "letters") + input_sql, stb_name = self.genFullTypeSql(stb_name=stb_name, tb_name=tb_name,t7="\"binaryTagValuebinaryTagValue\"", t8="L\"ncharTagValuencharTagValue\"") + self.resCmp(input_sql, stb_name, condition=f'where tbname like "{tb_name}"') + + @tdCom.smlPass + def tagColAddDupIDCheckCase(self): + """ + check tag count add, stb and tb duplicate + * tag: alter table ... + * col: when update==0 and ts is same, unchange + * so this case tag&&value will be added, + * col is added without value when update==0 + * col is added with value when update==1 + """ + tdLog.info(f'{sys._getframe().f_code.co_name}() function is running') + tdCom.cleanTb(type="restful") + tb_name = tdCom.getLongName(7, "letters") + for db_update_tag in [0, 1]: + if db_update_tag == 1 : + tdCom.createDb("test_update", db_update_tag=db_update_tag, api_type="restful") + input_sql, stb_name = self.genFullTypeSql(tb_name=tb_name, t0="t", value="t") + self.resCmp(input_sql, stb_name) + input_sql, stb_name = self.genFullTypeSql(stb_name=stb_name, tb_name=tb_name, t0="t", value="f", t_add_tag=True) + if db_update_tag == 1 : + self.resCmp(input_sql, stb_name, condition=f'where tbname like "{tb_name}"', none_check_tag=True) + tdSql.query(f'select * from {stb_name} where tbname like "{tb_name}"') + tdSql.checkData(0, 11, None) + tdSql.checkData(0, 12, None) + else: + tdCom.schemalessApiPost(sql=input_sql, url_type="telnet") + tdSql.query(f'select * from {stb_name} where tbname like "{tb_name}"') + tdSql.checkData(0, 1, True) + tdSql.checkData(0, 11, None) + tdSql.checkData(0, 12, None) + tdCom.createDb(api_type="restful") + + @tdCom.smlPass + def tagColAddCheckCase(self): + """ + check tag count add + """ + tdLog.info(f'{sys._getframe().f_code.co_name}() function is running') + tdCom.cleanTb(type="restful") + tb_name = tdCom.getLongName(7, "letters") + input_sql, stb_name = self.genFullTypeSql(tb_name=tb_name, t0="f", value="f") + self.resCmp(input_sql, stb_name) + tb_name_1 = tdCom.getLongName(7, "letters") + input_sql, stb_name = self.genFullTypeSql(stb_name=stb_name, tb_name=tb_name_1, t0="f", value="f", t_add_tag=True) + self.resCmp(input_sql, stb_name, condition=f'where tbname like "{tb_name_1}"') + res_row_list = self.resHandle(f"select t10,t11 from {tb_name}", True)[0] + tdSql.checkEqual(res_row_list[0], ['None', 'None']) + self.resCmp(input_sql, stb_name, condition=f'where tbname like "{tb_name}"', none_check_tag=True) + + def tagMd5Check(self): + """ + condition: stb not change + insert two table, keep tag unchange, change col + """ + tdLog.info(f'{sys._getframe().f_code.co_name}() function is running') + tdCom.cleanTb(type="restful") + input_sql, stb_name = self.genFullTypeSql(t0="f", value="f", id_noexist_tag=True) + self.resCmp(input_sql, stb_name) + tb_name1 = self.getNoIdTbName(stb_name) + input_sql, stb_name = self.genFullTypeSql(stb_name=stb_name, t0="f", value="f", id_noexist_tag=True) + self.resCmp(input_sql, stb_name) + tb_name2 = self.getNoIdTbName(stb_name) + tdSql.query(f"select * from {stb_name}") + tdSql.checkRows(1) + tdSql.checkEqual(tb_name1, tb_name2) + input_sql, stb_name = self.genFullTypeSql(stb_name=stb_name, t0="f", value="f", id_noexist_tag=True, t_add_tag=True) + tdCom.schemalessApiPost(sql=input_sql, url_type="telnet") + tb_name3 = self.getNoIdTbName(stb_name) + tdSql.query(f"select * from {stb_name}") + tdSql.checkRows(2) + tdSql.checkNotEqual(tb_name1, tb_name3) + + # * tag nchar max is 16374/4, col+ts nchar max 49151 + def tagColNcharMaxLengthCheckCase(self): + """ + check nchar length limit + """ + tdLog.info(f'{sys._getframe().f_code.co_name}() function is running') + tdCom.cleanTb(type="restful") + stb_name = tdCom.getLongName(7, "letters") + tb_name = f'{stb_name}_1' + input_sql = f'{stb_name} 1626006833640 f t2={tdCom.getLongName(1, "letters")}' + tdCom.schemalessApiPost(sql=input_sql, url_type="telnet") + + # * legal nchar could not be larger than 16374/4 + input_sql = f'{stb_name} 1626006833640 f t1={tdCom.getLongName(4093, "letters")} t2={tdCom.getLongName(1, "letters")}' + res = tdCom.schemalessApiPost(sql=input_sql, url_type="telnet") + print(res) + tdSql.query(f"select * from {stb_name}") + tdSql.checkRows(2) + input_sql = f'{stb_name} 1626006833640 f t1={tdCom.getLongName(4093, "letters")} t2={tdCom.getLongName(2, "letters")}' + res = tdCom.schemalessApiPost(sql=input_sql, url_type="telnet") + tdSql.checkEqual(res.status_code, 500) + tdSql.checkIn("Invalid operation", res.text) + + tdSql.query(f"select * from {stb_name}") + tdSql.checkRows(2) + + def batchInsertCheckCase(self): + """ + test batch insert + """ + tdLog.info(f'{sys._getframe().f_code.co_name}() function is running') + tdCom.cleanTb(type="restful") + stb_name = tdCom.getLongName(8, "letters") + tdCom.restApiPost(f'create stable {stb_name}(ts timestamp, f int) tags(t1 bigint)') + + lines = f'st123456 1626006833640 1i64 t1=3i64 t2=4f64 t3=\"t3\"\n\ +st123456 1626006833641 2i64 t1=4i64 t3=\"t4\" t2=5f64 t4=5f64\n\ +{stb_name} 1626006833642 3i64 t2=5f64 t3=L\"ste\"\n\ +stf567890 1626006833643 4i64 t1=4i64 t3=\"t4\" t2=5f64 t4=5f64\n\ +st123456 1626006833644 5i64 t1=4i64 t2=5f64 t3=\"t4\"\n\ +{stb_name} 1626006833645 6i64 t2=5f64 t3=L\"ste2\"\n\ +{stb_name} 1626006833646 7i64 t2=5f64 t3=L\"ste2\"\n\ +st123456 1626006833647 8i64 t1=4i64 t3=\"t4\" t2=5f64 t4=5f64\n\ +st123456 1626006833648 9i64 t1=4i64 t3=\"t4\" t2=5f64 t4=5f64' + + res = tdCom.schemalessApiPost(sql=lines, url_type="telnet") + tdSql.checkEqual(res.status_code, 200) + tdSql.query('show stables') + tdSql.checkRows(3) + tdSql.query('show tables') + tdSql.checkRows(6) + tdSql.query('select * from st123456') + tdSql.checkRows(5) + + def multiInsertCheckCase(self, count): + """ + test multi insert + """ + tdLog.info(f'{sys._getframe().f_code.co_name}() function is running') + tdCom.cleanTb(type="restful") + long_sql = '' + stb_name = tdCom.getLongName(8, "letters") + tdCom.restApiPost(f'create stable {stb_name}(ts timestamp, f int) tags(t1 nchar(10))') + for i in range(count): + input_sql = self.genFullTypeSql(stb_name=stb_name, t7=f'"{tdCom.getLongName(8, "letters")}"', value=f'"{tdCom.getLongName(8, "letters")}"', id_noexist_tag=True)[0] + long_sql += f'{input_sql}\n' + res = tdCom.schemalessApiPost(sql=long_sql, url_type="telnet") + tdSql.checkEqual(res.status_code, 200) + tdSql.query('show tables') + tdSql.checkRows(count) + + def batchErrorInsertCheckCase(self): + """ + test batch error insert + """ + tdLog.info(f'{sys._getframe().f_code.co_name}() function is running') + tdCom.cleanTb(type="restful") + stb_name = tdCom.getLongName(8, "letters") + lines = f"st123456 1626006833640 3i 64 t1=3i64 t2=4f64 t3=\"t3\"\n\ + {stb_name} 1626056811823316532ns tRue t2=5f64 t3=L\"ste\"" + res = tdCom.schemalessApiPost(sql=lines, url_type="telnet") + tdSql.checkEqual(res.status_code, 500) + tdSql.checkIn("Invalid combination of client/service time", res.text) + + def multiColsInsertCheckCase(self): + """ + test multi cols insert + """ + tdLog.info(f'{sys._getframe().f_code.co_name}() function is running') + tdCom.cleanTb(type="restful") + input_sql = self.genFullTypeSql(c_multi_tag=True)[0] + res = tdCom.schemalessApiPost(sql=input_sql, url_type="telnet") + tdSql.checkEqual(res.status_code, 500) + tdSql.checkIn("Syntax error in Line", res.text) + + def blankColInsertCheckCase(self): + """ + test blank col insert + """ + tdLog.info(f'{sys._getframe().f_code.co_name}() function is running') + tdCom.cleanTb(type="restful") + input_sql = self.genFullTypeSql(c_blank_tag=True)[0] + res = tdCom.schemalessApiPost(sql=input_sql, url_type="telnet") + tdSql.checkEqual(res.status_code, 500) + tdSql.checkIn("Invalid value in client", res.text) + + def blankTagInsertCheckCase(self): + """ + test blank tag insert + """ + tdLog.info(f'{sys._getframe().f_code.co_name}() function is running') + tdCom.cleanTb(type="restful") + input_sql = self.genFullTypeSql(t_blank_tag=True)[0] + print(input_sql) + res = tdCom.schemalessApiPost(sql=input_sql, url_type="telnet") + tdSql.checkEqual(res.status_code, 500) + tdSql.checkIn("Syntax error in Line", res.text) + + def chineseCheckCase(self): + """ + check nchar ---> chinese + """ + tdLog.info(f'{sys._getframe().f_code.co_name}() function is running') + tdCom.cleanTb(type="restful") + input_sql, stb_name = self.genFullTypeSql(chinese_tag=True) + self.resCmp(input_sql, stb_name) + + def multiFieldCheckCase(self): + ''' + multi_field + ''' + tdLog.info(f'{sys._getframe().f_code.co_name}() function is running') + tdCom.cleanTb(type="restful") + input_sql = self.genFullTypeSql(multi_field_tag=True)[0] + res = tdCom.schemalessApiPost(sql=input_sql, url_type="telnet") + tdSql.checkEqual(res.status_code, 500) + tdSql.checkIn("Syntax error in Line", res.text) + + def spellCheckCase(self): + tdLog.info(f'{sys._getframe().f_code.co_name}() function is running') + tdCom.cleanTb(type="restful") + stb_name = tdCom.getLongName(8, "letters") + input_sql_list = [f'{stb_name}_1 1626006833640 127I8 t0=127I8 t1=32767I16 t2=2147483647I32 t3=9223372036854775807I64 t4=11.12345027923584F32 t5=22.123456789F64', + f'{stb_name}_2 1626006833640 32767I16 t0=127I8 t1=32767I16 t2=2147483647I32 t3=9223372036854775807I64 t4=11.12345027923584F32 t5=22.123456789F64', + f'{stb_name}_3 1626006833640 2147483647I32 t0=127I8 t1=32767I16 t2=2147483647I32 t3=9223372036854775807I64 t4=11.12345027923584F32 t5=22.123456789F64', + f'{stb_name}_4 1626006833640 9223372036854775807I64 t0=127I8 t1=32767I16 t2=2147483647I32 t3=9223372036854775807I64 t4=11.12345027923584F32 t5=22.123456789F64', + f'{stb_name}_5 1626006833640 11.12345027923584F32 t0=127I8 t1=32767I16 t2=2147483647I32 t3=9223372036854775807I64 t4=11.12345027923584F32 t5=22.123456789F64', + f'{stb_name}_6 1626006833640 22.123456789F64 t0=127I8 t1=32767I16 t2=2147483647I32 t3=9223372036854775807I64 t4=11.12345027923584F32 t5=22.123456789F64', + f'{stb_name}_7 1626006833640 22.123456789F64 t0=127I8 t1=32767I16 t2=2147483647I32 t3=9223372036854775807I64 t4=11.12345027923584F32 t5=22.123456789F64', + f'{stb_name}_8 1626006833640 22.123456789F64 t0=127I8 t1=32767I16 t2=2147483647I32 t3=9223372036854775807I64 t4=11.12345027923584F32 t5=22.123456789F64', + f'{stb_name}_9 1626006833640 22.123456789F64 t0=127I8 t1=32767I16 t2=2147483647I32 t3=9223372036854775807I64 t4=11.12345027923584F32 t5=22.123456789F64', + f'{stb_name}_10 1626006833640 22.123456789F64 t0=127I8 t1=32767I16 t2=2147483647I32 t3=9223372036854775807I64 t4=11.12345027923584F32 t5=22.123456789F64'] + for input_sql in input_sql_list: + stb_name = input_sql.split(' ')[0] + self.resCmp(input_sql, stb_name) + + def pointTransCheckCase(self): + """ + metric value "." trans to "_" + """ + tdLog.info(f'{sys._getframe().f_code.co_name}() function is running') + tdCom.cleanTb(type="restful") + input_sql = self.genFullTypeSql(point_trans_tag=True)[0] + stb_name = f'`{input_sql.split(" ")[0]}`' + self.resCmp(input_sql, stb_name) + tdCom.restApiPost("drop table `.point.trans.test`") + + def defaultTypeCheckCase(self): + tdLog.info(f'{sys._getframe().f_code.co_name}() function is running') + tdCom.cleanTb(type="restful") + stb_name = tdCom.getLongName(8, "letters") + input_sql_list = [f'{stb_name}_1 1626006833640 9223372036854775807 t0=f t1=127 t2=32767i16 t3=2147483647i32 t4=9223372036854775807 t5=11.12345f32 t6=22.123456789f64 t7="vozamcts" t8=L"ncharTagValue"', \ + f'{stb_name}_2 1626006833641 22.123456789 t0=f t1=127i8 t2=32767I16 t3=2147483647i32 t4=9223372036854775807i64 t5=11.12345f32 t6=22.123456789 t7="vozamcts" t8=L"ncharTagValue"', \ + f'{stb_name}_3 1626006833642 10e5F32 t0=f t1=127i8 t2=32767I16 t3=2147483647i32 t4=9223372036854775807i64 t5=11.12345f32 t6=10e5F64 t7="vozamcts" t8=L"ncharTagValue"', \ + f'{stb_name}_4 1626006833643 10.0e5F64 t0=f t1=127i8 t2=32767I16 t3=2147483647i32 t4=9223372036854775807i64 t5=11.12345f32 t6=10.0e5F32 t7="vozamcts" t8=L"ncharTagValue"', \ + f'{stb_name}_5 1626006833644 -10.0e5 t0=f t1=127i8 t2=32767I16 t3=2147483647i32 t4=9223372036854775807i64 t5=11.12345f32 t6=-10.0e5 t7="vozamcts" t8=L"ncharTagValue"'] + for input_sql in input_sql_list: + stb_name = input_sql.split(" ")[0] + self.resCmp(input_sql, stb_name) + + def tbnameTagsColsNameCheckCase(self): + tdLog.info(f'{sys._getframe().f_code.co_name}() function is running') + tdCom.cleanTb(type="restful") + if self.smlChildTableName_value == "ID": + input_sql = 'rFa$sta 1626006834 9223372036854775807 id=rFas$ta_1 Tt!0=true tT@1=127Ii8 t#2=32767i16 "t$3"=2147483647i32 t%4=9223372036854775807i64 t^5=11.12345f32 t&6=22.123456789f64 t*7=\"ddzhiksj\" t!@#$%^&*()_+[];:<>?,9=L\"ncharTagValue\"' + tdCom.schemalessApiPost(sql=input_sql, url_type="telnet") + query_sql = 'select * from `rFa$sta`' + query_res = tdSql.query(query_sql, True) + tdSql.checkEqual(query_res, [(datetime.datetime(2021, 7, 11, 20, 33, 54), 9.223372036854776e+18, 'true', '127Ii8', '32767i16', '2147483647i32', '9223372036854775807i64', '11.12345f32', '22.123456789f64', '"ddzhiksj"', 'L"ncharTagValue"')]) + col_tag_res = tdSql.getColNameList(query_sql) + tdSql.checkEqual(col_tag_res, ['ts', 'value', 'tt!0', 'tt@1', 't#2', '"t$3"', 't%4', 't^5', 't&6', 't*7', 't!@#$%^&*()_+[];:<>?,9']) + else: + input_sql = 'rFa$sta 1626006834 9223372036854775807 Tt!0=true tT@1=127Ii8 t#2=32767i16 "t$3"=2147483647i32 t%4=9223372036854775807i64 t^5=11.12345f32 t&6=22.123456789f64 t*7=\"ddzhiksj\" t!@#$%^&*()_+[];:<>?,9=L\"ncharTagValue\"' + tdCom.schemalessApiPost(sql=input_sql, url_type="telnet") + query_sql = 'select * from `rFa$sta`' + query_res = tdSql.query(query_sql, True) + tdSql.checkEqual(query_res, [(datetime.datetime(2021, 7, 11, 20, 33, 54), 9.223372036854776e+18, '2147483647i32', 'L"ncharTagValue"', '32767i16', '9223372036854775807i64', '22.123456789f64', '"ddzhiksj"', '11.12345f32', 'true', '127Ii8')]) + col_tag_res = tdSql.getColNameList(query_sql) + tdSql.checkEqual(col_tag_res, ['ts', 'value', '"t$3"', 't!@#$%^&*()_+[];:<>?,9', 't#2', 't%4', 't&6', 't*7', 't^5', 'Tt!0', 'tT@1']) + tdCom.restApiPost('drop table `rFa$sta`') + + def genSqlList(self, count=5, stb_name="", tb_name=""): + """ + stb --> supertable + tb --> table + ts --> timestamp, same default + col --> column, same default + tag --> tag, same default + d --> different + s --> same + a --> add + m --> minus + """ + d_stb_d_tb_list = list() + s_stb_s_tb_list = list() + s_stb_s_tb_a_tag_list = list() + s_stb_s_tb_m_tag_list = list() + s_stb_d_tb_list = list() + s_stb_d_tb_m_tag_list = list() + s_stb_d_tb_a_tag_list = list() + s_stb_s_tb_d_ts_list = list() + s_stb_s_tb_d_ts_m_tag_list = list() + s_stb_s_tb_d_ts_a_tag_list = list() + s_stb_d_tb_d_ts_list = list() + s_stb_d_tb_d_ts_m_tag_list = list() + s_stb_d_tb_d_ts_a_tag_list = list() + for i in range(count): + d_stb_d_tb_list.append(self.genFullTypeSql(t0="f", value="f")) + s_stb_s_tb_list.append(self.genFullTypeSql(stb_name=stb_name, tb_name=tb_name, t7=f'"{tdCom.getLongName(8, "letters")}"', value=f'"{tdCom.getLongName(8, "letters")}"')) + s_stb_s_tb_a_tag_list.append(self.genFullTypeSql(stb_name=stb_name, tb_name=tb_name, t7=f'"{tdCom.getLongName(8, "letters")}"', value=f'"{tdCom.getLongName(8, "letters")}"', t_add_tag=True)) + s_stb_s_tb_m_tag_list.append(self.genFullTypeSql(stb_name=stb_name, tb_name=tb_name, t7=f'"{tdCom.getLongName(8, "letters")}"', value=f'"{tdCom.getLongName(8, "letters")}"', t_mul_tag=True)) + s_stb_d_tb_list.append(self.genFullTypeSql(stb_name=stb_name, t7=f'"{tdCom.getLongName(8, "letters")}"', value=f'"{tdCom.getLongName(8, "letters")}"', id_noexist_tag=True)) + s_stb_d_tb_m_tag_list.append(self.genFullTypeSql(stb_name=stb_name, t7=f'"{tdCom.getLongName(8, "letters")}"', value=f'"{tdCom.getLongName(8, "letters")}"', id_noexist_tag=True, t_mul_tag=True)) + s_stb_d_tb_a_tag_list.append(self.genFullTypeSql(stb_name=stb_name, t7=f'"{tdCom.getLongName(8, "letters")}"', value=f'"{tdCom.getLongName(8, "letters")}"', id_noexist_tag=True, t_add_tag=True)) + s_stb_s_tb_d_ts_list.append(self.genFullTypeSql(stb_name=stb_name, tb_name=tb_name, t7=f'"{tdCom.getLongName(8, "letters")}"', value=f'"{tdCom.getLongName(8, "letters")}"', ts=0)) + s_stb_s_tb_d_ts_m_tag_list.append(self.genFullTypeSql(stb_name=stb_name, tb_name=tb_name, t7=f'"{tdCom.getLongName(8, "letters")}"', value=f'"{tdCom.getLongName(8, "letters")}"', ts=0, t_mul_tag=True)) + s_stb_s_tb_d_ts_a_tag_list.append(self.genFullTypeSql(stb_name=stb_name, tb_name=tb_name, t7=f'"{tdCom.getLongName(8, "letters")}"', value=f'"{tdCom.getLongName(8, "letters")}"', ts=0, t_add_tag=True)) + s_stb_d_tb_d_ts_list.append(self.genFullTypeSql(stb_name=stb_name, t7=f'"{tdCom.getLongName(8, "letters")}"', value=f'"{tdCom.getLongName(8, "letters")}"', id_noexist_tag=True, ts=0)) + s_stb_d_tb_d_ts_m_tag_list.append(self.genFullTypeSql(stb_name=stb_name, t7=f'"{tdCom.getLongName(8, "letters")}"', value=f'"{tdCom.getLongName(8, "letters")}"', id_noexist_tag=True, ts=0, t_mul_tag=True)) + s_stb_d_tb_d_ts_a_tag_list.append(self.genFullTypeSql(stb_name=stb_name, t7=f'"{tdCom.getLongName(8, "letters")}"', value=f'"{tdCom.getLongName(8, "letters")}"', id_noexist_tag=True, ts=0, t_add_tag=True)) + + return d_stb_d_tb_list, s_stb_s_tb_list, s_stb_s_tb_a_tag_list, s_stb_s_tb_m_tag_list, \ + s_stb_d_tb_list, s_stb_d_tb_m_tag_list, s_stb_d_tb_a_tag_list, s_stb_s_tb_d_ts_list, \ + s_stb_s_tb_d_ts_m_tag_list, s_stb_s_tb_d_ts_a_tag_list, s_stb_d_tb_d_ts_list, \ + s_stb_d_tb_d_ts_m_tag_list, s_stb_d_tb_d_ts_a_tag_list + + + def genMultiThreadSeq(self, sql_list): + tlist = list() + for insert_sql in sql_list: + t = threading.Thread(target=tdCom.schemalessApiPost,args=(insert_sql[0], "telnet")) + tlist.append(t) + return tlist + + def multiThreadRun(self, tlist): + for t in tlist: + t.start() + for t in tlist: + t.join() + + def stbInsertMultiThreadCheckCase(self): + """ + thread input different stb + """ + tdLog.info(f'{sys._getframe().f_code.co_name}() function is running') + tdCom.cleanTb(type="restful") + input_sql = self.genSqlList()[0] + self.multiThreadRun(self.genMultiThreadSeq(input_sql)) + tdSql.query(f"show tables;") + tdSql.checkRows(5) + + def sStbStbDdataInsertMultiThreadCheckCase(self): + """ + thread input same stb tb, different data, result keep first data + """ + tdLog.info(f'{sys._getframe().f_code.co_name}() function is running') + tdCom.cleanTb(type="restful") + tb_name = tdCom.getLongName(7, "letters") + input_sql, stb_name = self.genFullTypeSql(tb_name=tb_name, value="\"binaryTagValue\"") + self.resCmp(input_sql, stb_name) + s_stb_s_tb_list = self.genSqlList(stb_name=stb_name, tb_name=tb_name)[1] + self.multiThreadRun(self.genMultiThreadSeq(s_stb_s_tb_list)) + tdSql.query(f"show tables;") + tdSql.checkRows(1) if self.smlChildTableName_value == "ID" else tdSql.checkRows(6) + if self.smlChildTableName_value == "ID": + expected_tb_name = self.getNoIdTbName(stb_name)[0] + tdSql.checkEqual(tb_name, expected_tb_name) + tdSql.query(f"select * from {stb_name};") + tdSql.checkRows(1) if self.smlChildTableName_value == "ID" else tdSql.checkRows(6) + + def sStbStbDdataAtInsertMultiThreadCheckCase(self): + """ + thread input same stb tb, different data, add columes and tags, result keep first data + """ + tdLog.info(f'{sys._getframe().f_code.co_name}() function is running') + tdCom.cleanTb(type="restful") + tb_name = tdCom.getLongName(7, "letters") + input_sql, stb_name = self.genFullTypeSql(tb_name=tb_name, value="\"binaryTagValue\"") + self.resCmp(input_sql, stb_name) + s_stb_s_tb_a_tag_list = self.genSqlList(stb_name=stb_name, tb_name=tb_name)[2] + self.multiThreadRun(self.genMultiThreadSeq(s_stb_s_tb_a_tag_list)) + tdSql.query(f"show tables;") + tdSql.checkRows(1) if self.smlChildTableName_value == "ID" else tdSql.checkRows(6) + if self.smlChildTableName_value == "ID": + expected_tb_name = self.getNoIdTbName(stb_name)[0] + tdSql.checkEqual(tb_name, expected_tb_name) + tdSql.query(f"select * from {stb_name};") + tdSql.checkRows(1) if self.smlChildTableName_value == "ID" else tdSql.checkRows(6) + + def sStbStbDdataMtInsertMultiThreadCheckCase(self): + """ + thread input same stb tb, different data, minus columes and tags, result keep first data + """ + tdLog.info(f'{sys._getframe().f_code.co_name}() function is running') + tdCom.cleanTb(type="restful") + tb_name = tdCom.getLongName(7, "letters") + input_sql, stb_name = self.genFullTypeSql(tb_name=tb_name, value="\"binaryTagValue\"") + self.resCmp(input_sql, stb_name) + s_stb_s_tb_m_tag_list = self.genSqlList(stb_name=stb_name, tb_name=tb_name)[3] + print(s_stb_s_tb_m_tag_list) + self.multiThreadRun(self.genMultiThreadSeq(s_stb_s_tb_m_tag_list)) + tdSql.query(f"show tables;") + tdSql.checkRows(1) if self.smlChildTableName_value == "ID" else tdSql.checkRows(2) + if self.smlChildTableName_value == "ID": + expected_tb_name = self.getNoIdTbName(stb_name)[0] + tdSql.checkEqual(tb_name, expected_tb_name) + tdSql.query(f"select * from {stb_name};") + tdSql.checkRows(1) if self.smlChildTableName_value == "ID" else tdSql.checkRows(2) + + def sStbDtbDdataInsertMultiThreadCheckCase(self): + """ + thread input same stb, different tb, different data + """ + tdLog.info(f'{sys._getframe().f_code.co_name}() function is running') + tdCom.cleanTb(type="restful") + input_sql, stb_name = self.genFullTypeSql(value="\"binaryTagValue\"") + self.resCmp(input_sql, stb_name) + s_stb_d_tb_list = self.genSqlList(stb_name=stb_name)[4] + self.multiThreadRun(self.genMultiThreadSeq(s_stb_d_tb_list)) + tdSql.query(f"show tables;") + tdSql.checkRows(6) + + def sStbDtbDdataMtInsertMultiThreadCheckCase(self): + """ + thread input same stb, different tb, different data, add col, mul tag + """ + tdLog.info(f'{sys._getframe().f_code.co_name}() function is running') + tdCom.cleanTb(type="restful") + input_sql, stb_name = self.genFullTypeSql(value="\"binaryTagValue\"") + self.resCmp(input_sql, stb_name) + s_stb_d_tb_m_tag_list = [(f'{stb_name} 1626006833640 "omfdhyom" t0=F t1=127i8 t2=32767i16 t3=2147483647i32 t4=9223372036854775807i64 t5=11.12345f32 t6=22.123456789f64', 'yzwswz'), \ + (f'{stb_name} 1626006833640 "vqowydbc" t0=F t1=127i8 t2=32767i16 t3=2147483647i32 t4=9223372036854775807i64 t5=11.12345f32 t6=22.123456789f64', 'yzwswz'), \ + (f'{stb_name} 1626006833640 "plgkckpv" t0=F t1=127i8 t2=32767i16 t3=2147483647i32 t4=9223372036854775807i64 t5=11.12345f32 t6=22.123456789f64', 'yzwswz'), \ + (f'{stb_name} 1626006833640 "cujyqvlj" t0=F t1=127i8 t2=32767i16 t3=2147483647i32 t4=9223372036854775807i64 t5=11.12345f32 t6=22.123456789f64', 'yzwswz'), \ + (f'{stb_name} 1626006833640 "twjxisat" t0=T t1=127i8 t2=32767i16 t3=2147483647i32 t4=9223372036854775807i64 t5=11.12345f32 t6=22.123456789f64', 'yzwswz')] + self.multiThreadRun(self.genMultiThreadSeq(s_stb_d_tb_m_tag_list)) + tdSql.query(f"show tables;") + tdSql.checkRows(3) + + def sStbDtbDdataAtInsertMultiThreadCheckCase(self): + """ + thread input same stb, different tb, different data, add tag, mul col + """ + tdLog.info(f'{sys._getframe().f_code.co_name}() function is running') + tdCom.cleanTb(type="restful") + input_sql, stb_name = self.genFullTypeSql(value="\"binaryTagValue\"") + self.resCmp(input_sql, stb_name) + s_stb_d_tb_a_tag_list = self.genSqlList(stb_name=stb_name)[6] + self.multiThreadRun(self.genMultiThreadSeq(s_stb_d_tb_a_tag_list)) + tdSql.query(f"show tables;") + tdSql.checkRows(6) + + def sStbStbDdataDtsInsertMultiThreadCheckCase(self): + """ + thread input same stb tb, different ts + """ + tdLog.info(f'{sys._getframe().f_code.co_name}() function is running') + tdCom.cleanTb(type="restful") + tb_name = tdCom.getLongName(7, "letters") + input_sql, stb_name = self.genFullTypeSql(tb_name=tb_name, value="\"binaryTagValue\"") + self.resCmp(input_sql, stb_name) + s_stb_s_tb_d_ts_list = [(f'{stb_name} 0 "hkgjiwdj" id={tb_name} t0=f t1=127i8 t2=32767i16 t3=2147483647i32 t4=9223372036854775807i64 t5=11.12345f32 t6=22.123456789f64 t7="vozamcts" t8=L"ncharTagValue"', 'dwpthv'), \ + (f'{stb_name} 0 "rljjrrul" id={tb_name} t0=False t1=127i8 t2=32767i16 t3=2147483647i32 t4=9223372036854775807i64 t5=11.12345f32 t6=22.123456789f64 t7="bmcanhbs" t8=L"ncharTagValue"', 'dwpthv'), \ + (f'{stb_name} 0 "basanglx" id={tb_name} t0=False t1=127i8 t2=32767i16 t3=2147483647i32 t4=9223372036854775807i64 t5=11.12345f32 t6=22.123456789f64 t7="enqkyvmb" t8=L"ncharTagValue"', 'dwpthv'), \ + (f'{stb_name} 0 "clsajzpp" id={tb_name} t0=F t1=127i8 t2=32767i16 t3=2147483647i32 t4=9223372036854775807i64 t5=11.12345f32 t6=22.123456789f64 t7="eivaegjk" t8=L"ncharTagValue"', 'dwpthv'), \ + (f'{stb_name} 0 "jitwseso" id={tb_name} t0=T t1=127i8 t2=32767i16 t3=2147483647i32 t4=9223372036854775807i64 t5=11.12345f32 t6=22.123456789f64 t7="yhlwkddq" t8=L"ncharTagValue"', 'dwpthv')] + self.multiThreadRun(self.genMultiThreadSeq(s_stb_s_tb_d_ts_list)) + tdSql.query(f"show tables;") + tdSql.checkRows(1) if self.smlChildTableName_value == "ID" else tdSql.checkRows(6) + tdSql.query(f"select * from {stb_name}") + tdSql.checkRows(6) + + def sStbStbDdataDtsMtInsertMultiThreadCheckCase(self): + """ + thread input same stb tb, different ts, add col, mul tag + """ + tdLog.info(f'{sys._getframe().f_code.co_name}() function is running') + tdCom.cleanTb(type="restful") + tb_name = tdCom.getLongName(7, "letters") + input_sql, stb_name = self.genFullTypeSql(tb_name=tb_name, value="\"binaryTagValue\"") + self.resCmp(input_sql, stb_name) + s_stb_s_tb_d_ts_m_tag_list = self.genSqlList(stb_name=stb_name, tb_name=tb_name)[8] + self.multiThreadRun(self.genMultiThreadSeq(s_stb_s_tb_d_ts_m_tag_list)) + tdSql.query(f"show tables;") + tdSql.checkRows(1) if self.smlChildTableName_value == "ID" else tdSql.checkRows(2) + tdSql.query(f"select * from {stb_name}") + tdSql.checkRows(6) + tdSql.query(f"select * from {stb_name} where t8 is not NULL") + tdSql.checkRows(6) if self.smlChildTableName_value == "ID" else tdSql.checkRows(1) + + def sStbStbDdataDtsAtInsertMultiThreadCheckCase(self): + """ + thread input same stb tb, different ts, add tag, mul col + """ + tdLog.info(f'{sys._getframe().f_code.co_name}() function is running') + tdCom.cleanTb(type="restful") + tb_name = tdCom.getLongName(7, "letters") + input_sql, stb_name = self.genFullTypeSql(tb_name=tb_name, value="\"binaryTagValue\"") + self.resCmp(input_sql, stb_name) + s_stb_s_tb_d_ts_a_tag_list = [(f'{stb_name} 0 "clummqfy" id={tb_name} t0=False t1=127i8 t2=32767i16 t3=2147483647i32 t4=9223372036854775807i64 t5=11.12345f32 t6=22.123456789f64 t7="hpxzrdiw" t8=L"ncharTagValue" t11=127i8 t10=L"ncharTagValue"', 'bokaxl'), \ + (f'{stb_name} 0 "yqeztggb" id={tb_name} t0=F t1=127i8 t2=32767i16 t3=2147483647i32 t4=9223372036854775807i64 t5=11.12345f32 t6=22.123456789f64 t7="gdtblmrc" t8=L"ncharTagValue" t11=127i8 t10=L"ncharTagValue"', 'bokaxl'), \ + (f'{stb_name} 0 "gbkinqdk" id={tb_name} t0=f t1=127i8 t2=32767i16 t3=2147483647i32 t4=9223372036854775807i64 t5=11.12345f32 t6=22.123456789f64 t7="iqniuvco" t8=L"ncharTagValue" t11=127i8 t10=L"ncharTagValue"', 'bokaxl'), \ + (f'{stb_name} 0 "ldxxejbd" id={tb_name} t0=f t1=127i8 t2=32767i16 t3=2147483647i32 t4=9223372036854775807i64 t5=11.12345f32 t6=22.123456789f64 t7="vxkipags" t8=L"ncharTagValue" t11=127i8 t10=L"ncharTagValue"', 'bokaxl'), \ + (f'{stb_name} 0 "tlvzwjes" id={tb_name} t0=true t1=127i8 t2=32767i16 t3=2147483647i32 t4=9223372036854775807i64 t5=11.12345f32 t6=22.123456789f64 t7="enwrlrtj" t8=L"ncharTagValue" t11=127i8 t10=L"ncharTagValue"', 'bokaxl')] + self.multiThreadRun(self.genMultiThreadSeq(s_stb_s_tb_d_ts_a_tag_list)) + tdSql.query(f"show tables;") + tdSql.checkRows(1) if self.smlChildTableName_value == "ID" else tdSql.checkRows(6) + tdSql.query(f"select * from {stb_name}") + tdSql.checkRows(6) + for t in ["t10", "t11"]: + tdSql.query(f"select * from {stb_name} where {t} is not NULL;") + tdSql.checkRows(0) if self.smlChildTableName_value == "ID" else tdSql.checkRows(5) + + def sStbDtbDdataDtsInsertMultiThreadCheckCase(self): + """ + thread input same stb, different tb, data, ts + """ + tdLog.info(f'{sys._getframe().f_code.co_name}() function is running') + tdCom.cleanTb(type="restful") + input_sql, stb_name = self.genFullTypeSql(value="\"binaryTagValue\"") + self.resCmp(input_sql, stb_name) + s_stb_d_tb_d_ts_list = self.genSqlList(stb_name=stb_name)[10] + self.multiThreadRun(self.genMultiThreadSeq(s_stb_d_tb_d_ts_list)) + tdSql.query(f"show tables;") + tdSql.checkRows(6) + + def sStbDtbDdataDtsMtInsertMultiThreadCheckCase(self): + """ + thread input same stb, different tb, data, ts, add col, mul tag + """ + tdLog.info(f'{sys._getframe().f_code.co_name}() function is running') + tdCom.cleanTb(type="restful") + input_sql, stb_name = self.genFullTypeSql(value="\"binaryTagValue\"") + self.resCmp(input_sql, stb_name) + s_stb_d_tb_d_ts_m_tag_list = [(f'{stb_name} 0 "mnpmtzul" t0=False t1=127i8 t2=32767i16 t3=2147483647i32 t4=9223372036854775807i64 t5=11.12345f32 t6=22.123456789f64', 'pcppkg'), \ + (f'{stb_name} 0 "zbvwckcd" t0=True t1=126i8 t2=32767i16 t3=2147483647i32 t4=9223372036854775807i64 t5=11.12345f32 t6=22.123456789f64', 'pcppkg'), \ + (f'{stb_name} 0 "vymcjfwc" t0=False t1=125i8 t2=32767i16 t3=2147483647i32 t4=9223372036854775807i64 t5=11.12345f32 t6=22.123456789f64', 'pcppkg'), \ + (f'{stb_name} 0 "laumkwfn" t0=False t1=124i8 t2=32767i16 t3=2147483647i32 t4=9223372036854775807i64 t5=11.12345f32 t6=22.123456789f64', 'pcppkg'), \ + (f'{stb_name} 0 "nyultzxr" t0=false t1=123i8 t2=32767i16 t3=2147483647i32 t4=9223372036854775807i64 t5=11.12345f32 t6=22.123456789f64', 'pcppkg')] + self.multiThreadRun(self.genMultiThreadSeq(s_stb_d_tb_d_ts_m_tag_list)) + tdSql.query(f"show tables;") + tdSql.checkRows(6) + + def test(self): + try: + input_sql = f'test_nchar 0 L"涛思数据" t0=f t1=L"涛思数据" t2=32767i16 t3=2147483647i32 t4=9223372036854775807i64 t5=11.12345f32 t6=22.123456789f64' + tdCom.schemalessApiPost(sql=input_sql, url_type="telnet") + except SchemalessError as err: + print(err.errno) + + def runAll(self): + self.initCheckCase() + self.boolTypeCheckCase() + self.symbolsCheckCase() + self.tsCheckCase() + self.openTstbTelnetTsCheckCase() + self.idSeqCheckCase() + self.idLetterCheckCase() + self.noIdCheckCase() + self.maxColTagCheckCase() + self.stbTbNameCheckCase() + self.idStartWithNumCheckCase() + self.nowTsCheckCase() + self.dateFormatTsCheckCase() + self.illegalTsCheckCase() + self.tbnameCheckCase() + self.tagNameLengthCheckCase() + self.tagValueLengthCheckCase() + self.colValueLengthCheckCase() + self.tagColIllegalValueCheckCase() + self.blankCheckCase() + self.duplicateIdTagColInsertCheckCase() + self.noIdStbExistCheckCase() + self.duplicateInsertExistCheckCase() + self.tagColBinaryNcharLengthCheckCase() + self.tagColAddDupIDCheckCase() + self.tagColAddCheckCase() + self.tagMd5Check() + self.tagColNcharMaxLengthCheckCase() + self.batchInsertCheckCase() + self.multiInsertCheckCase(10) + self.batchErrorInsertCheckCase() + self.multiColsInsertCheckCase() + self.blankColInsertCheckCase() + self.blankTagInsertCheckCase() + self.chineseCheckCase() + self.multiFieldCheckCase() + self.spellCheckCase() + self.pointTransCheckCase() + self.defaultTypeCheckCase() + self.tbnameTagsColsNameCheckCase() + # # MultiThreads + self.stbInsertMultiThreadCheckCase() + self.sStbStbDdataInsertMultiThreadCheckCase() + self.sStbStbDdataAtInsertMultiThreadCheckCase() + self.sStbStbDdataMtInsertMultiThreadCheckCase() + self.sStbDtbDdataInsertMultiThreadCheckCase() + self.sStbDtbDdataMtInsertMultiThreadCheckCase() + self.sStbDtbDdataAtInsertMultiThreadCheckCase() + self.sStbStbDdataDtsInsertMultiThreadCheckCase() + # self.sStbStbDdataDtsMtInsertMultiThreadCheckCase() + self.sStbStbDdataDtsAtInsertMultiThreadCheckCase() + self.sStbDtbDdataDtsInsertMultiThreadCheckCase() + self.sStbDtbDdataDtsMtInsertMultiThreadCheckCase() + + def run(self): + print("running {}".format(__file__)) + tdCom.createDb(api_type="restful") + try: + self.runAll() + except Exception as err: + print(''.join(traceback.format_exception(None, err, err.__traceback__))) + raise err + + def stop(self): + tdSql.close() + tdLog.success("%s successfully executed" % __file__) + +tdCases.addWindows(__file__, TDTestCase()) +tdCases.addLinux(__file__, TDTestCase()) diff --git a/tests/pytest/insert/timestamp.py b/tests/pytest/insert/timestamp.py new file mode 100644 index 0000000000000000000000000000000000000000..4c9cf36f40e31a792b550a557937d25d968f4fe2 --- /dev/null +++ b/tests/pytest/insert/timestamp.py @@ -0,0 +1,81 @@ +################################################################### +# Copyright (c) 2016 by TAOS Technologies, Inc. +# All rights reserved. +# +# This file is proprietary and confidential to TAOS Technologies. +# No part of this file may be reproduced, stored, transmitted, +# disclosed or used in any form or by any means other than as +# expressly provided by the written permission from Jianhui Tao +# +################################################################### + +# -*- coding: utf-8 -*- + +import sys + +from util.log import * +from util.cases import * +from util.sql import * +from util.dnodes import * + + +class TDTestCase: + def init(self, conn, logSql): + tdLog.debug("start to execute %s" % __file__) + tdSql.init(conn.cursor(), logSql) + self.ts = 1607281690000 + + def run(self): + tdSql.prepare() + + # TS-806 + tdLog.info("test case for TS-806") + + # Case 1 + tdSql.execute("create table t1(ts timestamp, c1 int)") + tdSql.execute("insert into t1(c1, ts) values(1, %d)" % self.ts) + tdSql.query("select * from t1") + tdSql.checkRows(1) + + # Case 2 + tdSql.execute("insert into t1(c1, ts) values(2, %d)(3, %d)" % (self.ts + 1000, self.ts + 2000)) + tdSql.query("select * from t1") + tdSql.checkRows(3) + + # Case 3 + tdSql.execute("create table t2(ts timestamp, c1 timestamp)") + tdSql.execute(" insert into t2(c1, ts) values(%d, %d)" % (self.ts, self.ts + 5000)) + tdSql.query("select * from t2") + tdSql.checkRows(1) + + tdSql.execute(" insert into t2(c1, ts) values(%d, %d)(%d, %d)" % (self.ts, self.ts + 6000, self.ts + 3000, self.ts + 8000)) + tdSql.query("select * from t2") + tdSql.checkRows(3) + + # Case 4 + tdSql.execute("create table stb(ts timestamp, c1 int, c2 binary(20)) tags(tstag timestamp, t1 int)") + tdSql.execute("insert into tb1(c2, ts, c1) using stb(t1, tstag) tags(1, now) values('test', %d, 1)" % self.ts) + tdSql.query("select * from stb") + tdSql.checkRows(1) + + # Case 5 + tdSql.execute("insert into tb1(c2, ts, c1) using stb(t1, tstag) tags(1, now) values('test', now, 1) tb2(c1, ts) using stb tags(now + 2m, 1000) values(1, now - 1h)") + tdSql.query("select * from stb") + tdSql.checkRows(3) + + tdSql.execute(" insert into tb1(c2, ts, c1) using stb(t1, tstag) tags(1, now) values('test', now + 10s, 1) tb2(c1, ts) using stb(tstag) tags(now + 2m) values(1, now - 3h)(2, now - 2h)") + tdSql.query("select * from stb") + tdSql.checkRows(6) + + # Case 6 + tdSql.execute("create table stb2 (ts timestamp, c1 timestamp, c2 timestamp) tags(t1 timestamp, t2 timestamp)") + tdSql.execute(" insert into tb4(c1, c2, ts) using stb2(t2, t1) tags(now, now + 1h) values(now + 1s, now + 2s, now + 3s)(now -1s, now - 2s, now - 3s) tb5(c2, ts, c1) using stb2(t2) tags(now + 1h) values(now, now, now)") + tdSql.query("select * from stb2") + tdSql.checkRows(3) + + def stop(self): + tdSql.close() + tdLog.success("%s successfully executed" % __file__) + +tdCases.addWindows(__file__, TDTestCase()) +tdCases.addLinux(__file__, TDTestCase()) diff --git a/tests/pytest/manualTest/TD-5114/continueCreateDn.py b/tests/pytest/manualTest/TD-5114/continueCreateDn.py index 9494ee5f3685d3ddaeb1848a58878d63fa7a54b6..e1d6f5193a3c3045f669815d8b98516d64def6e1 100644 --- a/tests/pytest/manualTest/TD-5114/continueCreateDn.py +++ b/tests/pytest/manualTest/TD-5114/continueCreateDn.py @@ -44,7 +44,7 @@ class TwoClients: # insert data with c connector for i in range(10): - os.system("taosdemo -f manualTest/TD-5114/insertDataDb3Replica2.json -y ") + os.system("%staosBenchmark -f manualTest/TD-5114/insertDataDb3Replica2.json -y ") # # check data correct tdSql.execute("show databases") tdSql.execute("use db3") diff --git a/tests/pytest/manualTest/manual_alter_block.py b/tests/pytest/manualTest/manual_alter_block.py index ccd98b1421400a765d85a35cf3a0b13b15f35f8e..14663b79cb9f604c251682263ab1189bc9e9c2b9 100644 --- a/tests/pytest/manualTest/manual_alter_block.py +++ b/tests/pytest/manualTest/manual_alter_block.py @@ -55,7 +55,7 @@ class TDTestCase: tdSql.checkData(0,9,3) #run taosdemo to occupy all cache, need to manually check memory consumption - os.system("%staosdemo -f tools/taosdemoAllTest/manual_block1_comp.json" % binPath) + os.system("%staosBenchmark -f tools/taosdemoAllTest/manual_block1_comp.json" % binPath) input("please check memory usage for taosd. After checking, press enter") #alter cache block to 8, then check alter @@ -64,7 +64,7 @@ class TDTestCase: tdSql.checkData(0,9,8) #run taosdemo to occupy all cache, need to manually check memory consumption - os.system("%staosdemo -f tools/taosdemoAllTest/manual_block2.json" % binPath) + os.system("%staosBenchmark -f tools/taosdemoAllTest/manual_block2.json" % binPath) input("please check memory usage for taosd. After checking, press enter") ##expected result the peak memory consumption should increase by around 80MB = 5 blocks of cache diff --git a/tests/pytest/manualTest/manual_alter_comp.py b/tests/pytest/manualTest/manual_alter_comp.py index 6c3e0fc29606caae32b981c662daaacbd31b15be..978279c29a64ee4f413a5eef79fb7a48e359fc3b 100644 --- a/tests/pytest/manualTest/manual_alter_comp.py +++ b/tests/pytest/manualTest/manual_alter_comp.py @@ -74,7 +74,7 @@ class TDTestCase: tdSql.query('show databases') tdSql.execute('alter database db blocks 3') # minimize the data in cache tdSql.checkData(0,14,2) - os.system("%staosdemo -f tools/taosdemoAllTest/manual_block1_comp.json" % binPath) + os.system("%staosBenchmark -f tools/taosdemoAllTest/manual_block1_comp.json" % binPath) print("default location is at /home/bryan/Documents/Github/TDengine/sim/dnode1/data/vnode") print('comp = 2') input("please check disk usage for taosd. After checking, press enter") @@ -91,7 +91,7 @@ class TDTestCase: tdSql.execute('alter database db comp 0') tdSql.query('show databases') tdSql.checkData(0,14,0) - os.system("%staosdemo -f tools/taosdemoAllTest/manual_block1_comp.json" % binPath) + os.system("%staosBenchmark -f tools/taosdemoAllTest/manual_block1_comp.json" % binPath) print("default location is at /home/bryan/Documents/Github/TDengine/sim/dnode1/data") print('comp = 0') input("please check disk usage for taosd. After checking, press enter") @@ -108,7 +108,7 @@ class TDTestCase: tdSql.execute('alter database db comp 1') tdSql.query('show databases') tdSql.checkData(0,14,1) - os.system("%staosdemo -f tools/taosdemoAllTest/manual_block1_comp.json" % binPath) + os.system("%staosBenchmark -f tools/taosdemoAllTest/manual_block1_comp.json" % binPath) print("default location is at /home/bryan/Documents/Github/TDengine/sim/dnode1/data") print('comp = 1') input("please check disk usage for taosd. After checking, press enter") diff --git a/tests/pytest/perfbenchmark/bug3433.py b/tests/pytest/perfbenchmark/bug3433.py index e4480df6b6753df88e3526930ac4bee087264d35..2f17e0bd3ada7ece5f8544033192758fd4747b52 100644 --- a/tests/pytest/perfbenchmark/bug3433.py +++ b/tests/pytest/perfbenchmark/bug3433.py @@ -211,7 +211,7 @@ class TDTestCase: tdLog.info(f"taosd found in {buildPath}") binPath = buildPath + "/build/bin/" - create_table_cmd = f"{binPath}taosdemo -f {filepath} > /dev/null 2>&1" + create_table_cmd = f"{binPath}taosBenchmark -f {filepath} > /dev/null 2>&1" _ = subprocess.check_output(create_table_cmd, shell=True).decode("utf-8") def droptmpfile(self): diff --git a/tests/pytest/perfbenchmark/bug3589.py b/tests/pytest/perfbenchmark/bug3589.py index c54ef8595d0bea1c4984b3f90e282f09659576c3..e01bb998d8b59fd06c65288c520b08d932ae8447 100644 --- a/tests/pytest/perfbenchmark/bug3589.py +++ b/tests/pytest/perfbenchmark/bug3589.py @@ -89,7 +89,7 @@ class TDTestCase: tdLog.info(f"taosd found in {buildPath}") binPath = buildPath + "/debug/build/bin/" - query_table_cmd = f"yes | {binPath}taosdemo -f {filepath}" + query_table_cmd = f"yes | {binPath}taosBenchmark -f {filepath}" _ = subprocess.check_output(query_table_cmd, shell=True).decode("utf-8") def checkqueryresult(self, expectrows): diff --git a/tests/pytest/query/nestedQuery/nestedQuery.py b/tests/pytest/query/nestedQuery/nestedQuery.py index 9260aced9a1d79649802917daad8f36ec9cf249e..89751bb7b808002b42e09d4a6bee2ef16e7ac775 100755 --- a/tests/pytest/query/nestedQuery/nestedQuery.py +++ b/tests/pytest/query/nestedQuery/nestedQuery.py @@ -2220,7 +2220,7 @@ class TDTestCase: binPath = buildPath+ "/build/bin/" # regualr-table - os.system("%staosdemo -N -d regular -t 2 -n 1000 -l 4095 -y" % binPath) + os.system("%staosBenchmark -N -d regular -t 2 -n 1000 -l 4095 -y" % binPath) tdSql.execute("use regular") tdSql.query("select * from d0;") tdSql.checkCols(4096) @@ -2281,7 +2281,7 @@ class TDTestCase: tdSql.checkRows(1000) #stable - os.system("%staosdemo -d super -t 2 -n 1000 -l 4093 -y" % binPath) + os.system("%staosBenchmark -d super -t 2 -n 1000 -l 4093 -y" % binPath) tdSql.execute("use super") tdSql.query("select * from meters;") tdSql.checkCols(4096) diff --git a/tests/pytest/query/nestedQuery/nestedQueryJson.py b/tests/pytest/query/nestedQuery/nestedQueryJson.py index 36a231a9165a15cb46cbc0c1d37152f90e54b03e..fa12713f3603e80329416ce2edf9f518d7f91cc3 100644 --- a/tests/pytest/query/nestedQuery/nestedQueryJson.py +++ b/tests/pytest/query/nestedQuery/nestedQueryJson.py @@ -49,7 +49,7 @@ class TDTestCase: binPath = buildPath+ "/build/bin/" # insert: create one or mutiple tables per sql and insert multiple rows per sql - os.system("%staosdemo -f query/nestedQuery/insertData.json -y " % binPath) + os.system("%staosBenchmark -f query/nestedQuery/insertData.json -y " % binPath) tdSql.execute("use db") tdSql.query("select count (tbname) from stb0") tdSql.checkData(0, 0, 1000) diff --git a/tests/pytest/query/querySort.py b/tests/pytest/query/querySort.py index 31d53ea0041b0656c52ebf0afe3954290f8763d4..a50b9cbf8afd7052a78e1f6ef85b8c464e816e71 100644 --- a/tests/pytest/query/querySort.py +++ b/tests/pytest/query/querySort.py @@ -132,6 +132,25 @@ class TDTestCase: tdSql.error("select top(tbcol1, 12) from st order by ts, tbcol1") tdSql.error("select top(tbcol1, 2) from st1 group by tbcol1 order by tbcol2") + fun_list = ['avg','count','twa','sum','stddev','leastsquares','min', + 'max','first','last','top','bottom','percentile','apercentile', + 'last_row','diff','spread','distinct'] + key = ['tbol','tagcol'] + for i in range(1,15): + for k in key: + for j in fun_list: + if j == 'leastsquares': + pick_func=j+'('+ k + str(i) +',1,1)' + elif j == 'top' or j == 'bottom' : continue + elif j == 'percentile' or j == 'apercentile': + pick_func=j+'('+ k + str(i) +',1)' + else: + pick_func=j+'('+ k + str(i) +')' + sql = 'select %s from st group by %s order by %s' % (pick_func , k+str(i), k+str(i)) + tdSql.error(sql) + sql = 'select %s from st6 group by %s order by %s ' % (pick_func , k+str(i), k+str(i)) + tdSql.error(sql) + tdSql.query("select top(tbcol1, 2) from st1 group by tbcol2 order by tbcol2") tdSql.query("select top(tbcol1, 12) from st order by tbcol1, ts") diff --git a/tests/pytest/query/unionAllTest.py b/tests/pytest/query/unionAllTest.py index 9a7aedc763db05ebb11da33dc65fa74b2ba8daa3..eaef5d2d573ba3c0ab08ed7ede991d25913c2454 100644 --- a/tests/pytest/query/unionAllTest.py +++ b/tests/pytest/query/unionAllTest.py @@ -116,10 +116,41 @@ class TDTestCase: sql += f"union all select last(*) from sub{i} " tdSql.execute("create table sub%d using st2 tags('nchar%d')" % (i, i)) - tdSql.execute("insert into sub%d values(%d, %d, %d, %d)" % (i, self.ts + i, i, i, i)) + tdSql.execute("insert into sub%d values(%d, %d, %d, %d)(%d, %d, %d, %d)" % (i, self.ts + i, i, i, i,self.ts + i + 101, i + 101, i + 101, i + 101)) tdSql.error(sql) + # TS-795 + tdLog.info("test case for TS-795") + + functions = ["*", "count", "avg", "twa", "irate", "sum", "stddev", "leastsquares", "min", "max", "first", "last", "top", "bottom", "percentile", "apercentile", "last_row"] + + for func in functions: + expr = func + if func == "top" or func == "bottom": + expr += "(c1, 1)" + elif func == "percentile" or func == "apercentile": + expr += "(c1, 0.5)" + elif func == "leastsquares": + expr = func + "(c1, 1, 1)" + elif func == "*": + expr = func + else: + expr += "(c1)" + + for i in range(100): + if i == 0: + sql = f"select {expr} from sub0 " + else: + sql += f"union all select {expr} from sub{i} " + + tdSql.query(sql) + if func == "*": + tdSql.checkRows(200) + else: + tdSql.checkRows(100) + + def stop(self): tdSql.close() tdLog.success("%s successfully executed" % __file__) diff --git a/tests/pytest/stream/stream2.py b/tests/pytest/stream/stream2.py index 9b4eb8725c96f95196f251c55b0b773cd68e9ed5..95f5d233855bbb743eaf0390d6c145258fd8f84d 100644 --- a/tests/pytest/stream/stream2.py +++ b/tests/pytest/stream/stream2.py @@ -153,10 +153,14 @@ class TDTestCase: tdSql.checkRows(2) tdSql.checkData(0, 2, 's1') tdSql.checkData(1, 2, 's0') + tdSql.execute('kill stream %s ;' % tdSql.queryResult[0][0]) + time.sleep(5) + tdSql.query("show streams") + tdSql.checkRows(1) def stop(self): - tdSql.close() + #tdSql.close() tdLog.success("%s successfully executed" % __file__) diff --git a/tests/pytest/table/create_db_from_normal_db.py b/tests/pytest/table/create_db_from_normal_db.py new file mode 100644 index 0000000000000000000000000000000000000000..8b5182c3b16ca31b2bbf966df294e2c4e4c12ff3 --- /dev/null +++ b/tests/pytest/table/create_db_from_normal_db.py @@ -0,0 +1,45 @@ +################################################################### +# Copyright (c) 2016 by TAOS Technologies, Inc. +# All rights reserved. +# +# This file is proprietary and confidential to TAOS Technologies. +# No part of this file may be reproduced, stored, transmitted, +# disclosed or used in any form or by any means other than as +# expressly provided by the written permission from Jianhui Tao +# +################################################################### + +# -*- coding: utf-8 -*- + +import sys +import taos +from util.log import tdLog +from util.cases import tdCases +from util.sql import tdSql + + +class TDTestCase: + def init(self, conn, logSql): + tdLog.debug("start to execute %s" % __file__) + tdSql.init(conn.cursor(), logSql) + + def run(self): + tdSql.prepare() + + print("test case for TS-783") + tdSql.execute("drop table if exists db.state1;") + tdSql.execute("create table db.state1 (ts timestamp, c1 int);") + tdSql.error("create table db.test1 using db.state1 tags('tt');") + + tdSql.execute("drop table if exists db.state2;") + tdSql.execute("create table db.state2 (ts timestamp, c1 int) tags (t binary(20));") + tdSql.query("create table db.test2 using db.state2 tags('tt');") + tdSql.error("create table db.test22 using db.test2 tags('tt');") + + def stop(self): + tdSql.close() + tdLog.success("%s successfully executed" % __file__) + + +tdCases.addWindows(__file__, TDTestCase()) +tdCases.addLinux(__file__, TDTestCase()) diff --git a/tests/pytest/tools/taosdemoAllTest/NanoTestCase/taosdemoTestInsertTime_step.py b/tests/pytest/tools/taosdemoAllTest/NanoTestCase/taosdemoTestInsertTime_step.py index b248eda6b0ce42d8cb681a74d5c807d0275e6e14..36221e4b7ff21b82ccf72451cfea8472952b622d 100644 --- a/tests/pytest/tools/taosdemoAllTest/NanoTestCase/taosdemoTestInsertTime_step.py +++ b/tests/pytest/tools/taosdemoAllTest/NanoTestCase/taosdemoTestInsertTime_step.py @@ -51,7 +51,7 @@ class TDTestCase: # insert: create one or mutiple tables per sql and insert multiple rows per sql # check the params of taosdemo about time_step is nano - os.system("%staosdemo -f tools/taosdemoAllTest/NanoTestCase/taosdemoInsertNanoDB.json -y " % binPath) + os.system("%staosBenchmark -f tools/taosdemoAllTest/NanoTestCase/taosdemoInsertNanoDB.json -y " % binPath) tdSql.execute("use testdb1") tdSql.query("show stables") tdSql.checkData(0, 4, 100) @@ -68,7 +68,7 @@ class TDTestCase: tdSql.checkData(0, 0,"2021-07-01 00:00:00.000099000") # check the params of taosdemo about time_step is us - os.system("%staosdemo -f tools/taosdemoAllTest/NanoTestCase/taosdemoInsertUSDB.json -y " % binPath) + os.system("%staosBenchmark -f tools/taosdemoAllTest/NanoTestCase/taosdemoInsertUSDB.json -y " % binPath) tdSql.execute("use testdb2") tdSql.query("show stables") tdSql.checkData(0, 4, 100) @@ -85,7 +85,7 @@ class TDTestCase: tdSql.checkData(0, 0,"2021-07-01 00:00:00.099000") # check the params of taosdemo about time_step is ms - os.system("%staosdemo -f tools/taosdemoAllTest/NanoTestCase/taosdemoInsertMSDB.json -y " % binPath) + os.system("%staosBenchmark -f tools/taosdemoAllTest/NanoTestCase/taosdemoInsertMSDB.json -y " % binPath) tdSql.execute("use testdb3") tdSql.query("show stables") tdSql.checkData(0, 4, 100) diff --git a/tests/pytest/tools/taosdemoAllTest/NanoTestCase/taosdemoTestSupportNanoInsert.py b/tests/pytest/tools/taosdemoAllTest/NanoTestCase/taosdemoTestSupportNanoInsert.py index f069bb8f7030dbd8d4eec8c9c741d246f261671b..34acbb2c0112b56cee6a637b9e1fbd5ddb42ddf7 100644 --- a/tests/pytest/tools/taosdemoAllTest/NanoTestCase/taosdemoTestSupportNanoInsert.py +++ b/tests/pytest/tools/taosdemoAllTest/NanoTestCase/taosdemoTestSupportNanoInsert.py @@ -53,7 +53,7 @@ class TDTestCase: # check stable stb0 os.system( - "%staosdemo -f tools/taosdemoAllTest/NanoTestCase/taosdemoTestNanoDatabase.json -y " % + "%staosBenchmark -f tools/taosdemoAllTest/NanoTestCase/taosdemoTestNanoDatabase.json -y " % binPath) tdSql.execute("use nsdb") tdSql.query("show stables") @@ -88,7 +88,7 @@ class TDTestCase: # check stable stb0 os.system( - "%staosdemo -f tools/taosdemoAllTest/NanoTestCase/taosdemoTestNanoDatabaseNow.json -y " % + "%staosBenchmark -f tools/taosdemoAllTest/NanoTestCase/taosdemoTestNanoDatabaseNow.json -y " % binPath) tdSql.execute("use nsdb2") @@ -108,7 +108,7 @@ class TDTestCase: # cols os.system( - "%staosdemo -f tools/taosdemoAllTest/NanoTestCase/taosdemoTestNanoDatabasecsv.json -y " % + "%staosBenchmark -f tools/taosdemoAllTest/NanoTestCase/taosdemoTestNanoDatabasecsv.json -y " % binPath) tdSql.execute("use nsdbcsv") tdSql.query("show stables") @@ -130,7 +130,7 @@ class TDTestCase: # taosdemo test insert with command and parameter , detals show # taosdemo --help os.system( - "%staosdemo -u root -ptaosdata -P 6030 -a 1 -m pre -n 10 -T 20 -t 60 -o res.txt -y " % + "%staosBenchmark -u root -ptaosdata -P 6030 -a 1 -m pre -n 10 -T 20 -t 60 -o res.txt -y " % binPath) tdSql.query("select count(*) from test.meters") tdSql.checkData(0, 0, 600) @@ -152,7 +152,7 @@ class TDTestCase: sleep(10) - os.system("%staosdemo -s taosdemoTestNanoCreateDB.sql -y " % binPath) + os.system("%staosBenchmark -s taosdemoTestNanoCreateDB.sql -y " % binPath) tdSql.query("select count(*) from nsdbsql.meters") tdSql.checkData(0, 0, 2) diff --git a/tests/pytest/tools/taosdemoAllTest/NanoTestCase/taosdemoTestSupportNanoQuery.py b/tests/pytest/tools/taosdemoAllTest/NanoTestCase/taosdemoTestSupportNanoQuery.py index 6c3e4d6c8a0d72a4b468cca22b2b1a6a25659db5..137cbe724310260254591c874e7bc0362f1e7f2f 100644 --- a/tests/pytest/tools/taosdemoAllTest/NanoTestCase/taosdemoTestSupportNanoQuery.py +++ b/tests/pytest/tools/taosdemoAllTest/NanoTestCase/taosdemoTestSupportNanoQuery.py @@ -1,4 +1,4 @@ -################################################################### +''################################################################### # Copyright (c) 2016 by TAOS Technologies, Inc. # All rights reserved. # @@ -49,7 +49,7 @@ class TDTestCase: binPath = buildPath+ "/build/bin/" # query: query test for nanoSecond with where and max min groupby order - os.system("%staosdemo -f tools/taosdemoAllTest/NanoTestCase/taosdemoTestNanoDatabase.json -y " % binPath) + os.system("%staosBenchmark -f tools/taosdemoAllTest/NanoTestCase/taosdemoTestNanoDatabase.json -y " % binPath) tdSql.execute("use nsdb") @@ -92,10 +92,10 @@ class TDTestCase: # query : query above sqls by taosdemo and continuously - os.system("%staosdemo -f tools/taosdemoAllTest/NanoTestCase/taosdemoTestSupportNanoQuery.json -y " % binPath) + os.system("%staosBenchmark -f tools/taosdemoAllTest/NanoTestCase/taosdemoTestSupportNanoQuery.json -y " % binPath) - os.system("%staosdemo -f tools/taosdemoAllTest/NanoTestCase/taosdemoTestNanoDatabasecsv.json -y " % binPath) + os.system("%staosBenchmark -f tools/taosdemoAllTest/NanoTestCase/taosdemoTestNanoDatabasecsv.json -y " % binPath) tdSql.execute("use nsdbcsv") tdSql.query("show stables") tdSql.checkData(0, 4, 100) @@ -140,7 +140,7 @@ class TDTestCase: tdSql.checkRows(10) # query : query above sqls by taosdemo and continuously - os.system("%staosdemo -f tools/taosdemoAllTest/NanoTestCase/taosdemoTestSupportNanoQuerycsv.json -y " % binPath) + os.system("%staosBenchmark -f tools/taosdemoAllTest/NanoTestCase/taosdemoTestSupportNanoQuerycsv.json -y " % binPath) os.system("rm -rf ./query_res*.txt*") os.system("rm -rf tools/taosdemoAllTest/NanoTestCase/*.py.sql") diff --git a/tests/pytest/tools/taosdemoAllTest/NanoTestCase/taosdemoTestSupportNanosubscribe.py b/tests/pytest/tools/taosdemoAllTest/NanoTestCase/taosdemoTestSupportNanosubscribe.py index 95c1a731bcde4c78d0aa272183bd2e7b7a4b168b..44a25801210c3bc8e74c576626ec974eb20dc70b 100644 --- a/tests/pytest/tools/taosdemoAllTest/NanoTestCase/taosdemoTestSupportNanosubscribe.py +++ b/tests/pytest/tools/taosdemoAllTest/NanoTestCase/taosdemoTestSupportNanosubscribe.py @@ -73,8 +73,8 @@ class TDTestCase: # insert data - os.system("%staosdemo -f tools/taosdemoAllTest/NanoTestCase/taosdemoTestNanoDatabaseInsertForSub.json" % binPath) - os.system("nohup %staosdemo -f tools/taosdemoAllTest/NanoTestCase/taosdemoTestSupportNanoSubscribe.json &" % binPath) + os.system("%staosBenchmark -f tools/taosdemoAllTest/NanoTestCase/taosdemoTestNanoDatabaseInsertForSub.json" % binPath) + os.system("nohup %staosBenchmark -f tools/taosdemoAllTest/NanoTestCase/taosdemoTestSupportNanoSubscribe.json &" % binPath) query_pid = int(subprocess.getstatusoutput('ps aux|grep "taosdemoAllTest/NanoTestCase/taosdemoTestSupportNanoSubscribe.json" |grep -v "grep"|awk \'{print $2}\'')[1]) diff --git a/tests/pytest/tools/taosdemoAllTest/TD-10539/create_taosdemo.py b/tests/pytest/tools/taosdemoAllTest/TD-10539/create_taosdemo.py index 6e722d3243c4a69b921e7dbe17d38c7339c847e9..e498e74bf1fe72519676d6a329dab226d1e41ee4 100644 --- a/tests/pytest/tools/taosdemoAllTest/TD-10539/create_taosdemo.py +++ b/tests/pytest/tools/taosdemoAllTest/TD-10539/create_taosdemo.py @@ -56,7 +56,7 @@ class TDTestCase: #print("==============taosdemo,#create stable,table; insert table; show table; select table; drop table") self.tsdemo = "tsdemo~!.@#$%^*[]-_=+{,?.}" #this escape character is not support in shell . include & () <> | / - os.system("%staosdemo -d test -E -m %s -t 10 -n 100 -l 10 -y " % (binPath,self.tsdemo)) + os.system("%staosBenchmark -d test -E -m %s -t 10 -n 100 -l 10 -y " % (binPath,self.tsdemo)) tdSql.execute("use test ;" ) tdSql.query("select count(*) from meters") tdSql.checkData(0, 0, 1000) @@ -91,14 +91,14 @@ class TDTestCase: tdSql.error("select * from test.`%s2` ; " %self.tsdemo) # Exception - os.system("%staosdemo -d test -m %s -t 10 -n 100 -l 10 -y " % (binPath,self.tsdemo)) + os.system("%staosBenchmark -d test -m %s -t 10 -n 100 -l 10 -y " % (binPath,self.tsdemo)) tdSql.query("show test.tables ") tdSql.checkRows(0) #print("==============taosdemo,#create regular table; insert table; show table; select table; drop table") self.tsdemo = "tsdemo~!.@#$%^*[]-_=+{,?.}" #this escape character is not support in shell . include & () <> | / - os.system("%staosdemo -N -E -m %s -t 10 -n 100 -l 10 -y " % (binPath,self.tsdemo)) + os.system("%staosBenchmark -N -E -m %s -t 10 -n 100 -l 10 -y " % (binPath,self.tsdemo)) tdSql.execute("use test ;" ) tdSql.query("select count(*) from `%s1`" %self.tsdemo) tdSql.checkData(0, 0, 100) @@ -125,13 +125,13 @@ class TDTestCase: tdSql.checkRows(9) # Exception - os.system("%staosdemo -N -m %s -t 10 -n 100 -l 10 -y " % (binPath,self.tsdemo)) + os.system("%staosBenchmark -N -m %s -t 10 -n 100 -l 10 -y " % (binPath,self.tsdemo)) tdSql.query("show test.tables ") tdSql.checkRows(0) #print("==============taosdemo——json_yes,#create stable,table; insert table; show table; select table; drop table") - os.system("%staosdemo -f tools/taosdemoAllTest/TD-10539/create_taosdemo_yes.json -y " % binPath) + os.system("%staosBenchmark -f tools/taosdemoAllTest/TD-10539/create_taosdemo_yes.json -y " % binPath) tdSql.execute("use dbyes") self.tsdemo_stable = "tsdemo_stable~!.@#$%^*[]-_=+{,?.}" @@ -171,7 +171,7 @@ class TDTestCase: #print("==============taosdemo——json_no,#create stable,table; insert table; show table; select table; drop table") - os.system("%staosdemo -f tools/taosdemoAllTest/TD-10539/create_taosdemo_no.json -y " % binPath) + os.system("%staosBenchmark -f tools/taosdemoAllTest/TD-10539/create_taosdemo_no.json -y " % binPath) tdSql.query("show dbno.tables;") tdSql.checkRows(0) diff --git a/tests/pytest/tools/taosdemoAllTest/TD-3453/query-interrupt.py b/tests/pytest/tools/taosdemoAllTest/TD-3453/query-interrupt.py index fe29409f296b310012773b9d78ca8735cfd52a13..e8e65b68b89c35f33e239b4121f4d99b84c796a0 100644 --- a/tests/pytest/tools/taosdemoAllTest/TD-3453/query-interrupt.py +++ b/tests/pytest/tools/taosdemoAllTest/TD-3453/query-interrupt.py @@ -52,13 +52,13 @@ class TDTestCase: binPath = buildPath+ "/build/bin/" # # insert 1000w rows in stb0 - os.system("%staosdemo -f tools/taosdemoAllTest/TD-3453/query-interrupt.json -y " % binPath) + os.system("%staosBenchmark -f tools/taosdemoAllTest/TD-3453/query-interrupt.json -y " % binPath) tdSql.execute("use db") tdSql.query("select count (tbname) from stb0") tdSql.checkData(0, 0,60) tdSql.query("select count(*) from stb0") tdSql.checkData(0, 0, 6000000) - os.system('%staosdemo -f tools/taosdemoAllTest/TD-3453/queryall.json -y & ' % binPath) + os.system('%staosBenchmark -f tools/taosdemoAllTest/TD-3453/queryall.json -y & ' % binPath) time.sleep(2) query_pid = int(subprocess.getstatusoutput('ps aux|grep "TD-3453/queryall.json" |grep -v "grep"|awk \'{print $2}\'')[1]) taosd_cpu_load_1 = float(subprocess.getstatusoutput('top -n 1 -b -p $(ps aux|grep "bin/taosd -c"|grep -v "grep" |awk \'{print $2}\')|awk \'END{print}\' |awk \'{print $9}\'')[1]) diff --git a/tests/pytest/tools/taosdemoAllTest/TD-4985/query-limit-offset.py b/tests/pytest/tools/taosdemoAllTest/TD-4985/query-limit-offset.py index f5e2d7ce08b4804d8c5ad9745e775f0fa1ebbc1b..987dd1bfa4771b505023bdeab78994ba488d671a 100644 --- a/tests/pytest/tools/taosdemoAllTest/TD-4985/query-limit-offset.py +++ b/tests/pytest/tools/taosdemoAllTest/TD-4985/query-limit-offset.py @@ -55,7 +55,7 @@ class TDTestCase: # insert: create one or mutiple tables per sql and insert multiple rows per sql # test case for https://jira.taosdata.com:18080/browse/TD-4985 os.system("rm -rf tools/taosdemoAllTest/TD-4985/query-limit-offset.py.sql") - os.system("%staosdemo -f tools/taosdemoAllTest/TD-4985/query-limit-offset.json -y " % binPath) + os.system("%staosBenchmark -f tools/taosdemoAllTest/TD-4985/query-limit-offset.json -y " % binPath) tdSql.execute("use db") tdSql.query("select count (tbname) from stb0") tdSql.checkData(0, 0, 10000) diff --git a/tests/pytest/tools/taosdemoAllTest/TD-5213/insertSigcolumnsNum4096.py b/tests/pytest/tools/taosdemoAllTest/TD-5213/insertSigcolumnsNum4096.py index eb844b6fe24338b0301c45b918967faec7debcc0..ce3f6ca4c2be3210cc84e8b3f13683b0dd268fa4 100755 --- a/tests/pytest/tools/taosdemoAllTest/TD-5213/insertSigcolumnsNum4096.py +++ b/tests/pytest/tools/taosdemoAllTest/TD-5213/insertSigcolumnsNum4096.py @@ -52,7 +52,7 @@ class TDTestCase: #-N:regular table -d:database name -t:table num -n:rows num per table -l:col num -y:force #regular old && new startTime = time.time() - os.system("%staosdemo -N -d regular_old -t 1 -n 10 -l 1023 -y" % binPath) + os.system("%staosBenchmark -N -d regular_old -t 1 -n 10 -l 1023 -y" % binPath) tdSql.execute("use regular_old") tdSql.query("show tables;") tdSql.checkRows(1) @@ -61,7 +61,7 @@ class TDTestCase: tdSql.query("describe d0;") tdSql.checkRows(1024) - os.system("%staosdemo -N -d regular_new -t 1 -n 10 -l 4095 -y" % binPath) + os.system("%staosBenchmark -N -d regular_new -t 1 -n 10 -l 4095 -y" % binPath) tdSql.execute("use regular_new") tdSql.query("show tables;") tdSql.checkRows(1) @@ -71,7 +71,7 @@ class TDTestCase: tdSql.checkRows(4096) #super table -d:database name -t:table num -n:rows num per table -l:col num -y:force - os.system("%staosdemo -d super_old -t 1 -n 10 -l 1021 -y" % binPath) + os.system("%staosBenchmark -d super_old -t 1 -n 10 -l 1021 -y" % binPath) tdSql.execute("use super_old") tdSql.query("show tables;") tdSql.checkRows(1) @@ -84,7 +84,7 @@ class TDTestCase: tdSql.query("describe d0;") tdSql.checkRows(1024) - os.system("%staosdemo -d super_new -t 1 -n 10 -l 4093 -y" % binPath) + os.system("%staosBenchmark -d super_new -t 1 -n 10 -l 4093 -y" % binPath) tdSql.execute("use super_new") tdSql.query("show tables;") tdSql.checkRows(1) @@ -104,7 +104,7 @@ class TDTestCase: # insert: create one or mutiple tables per sql and insert multiple rows per sql # test case for https://jira.taosdata.com:18080/browse/TD-5213 - os.system("%staosdemo -f tools/taosdemoAllTest/TD-5213/insertSigcolumnsNum4096.json -y " % binPath) + os.system("%staosBenchmark -f tools/taosdemoAllTest/TD-5213/insertSigcolumnsNum4096.json -y " % binPath) tdSql.execute("use json") tdSql.query("select count (tbname) from stb_old") tdSql.checkData(0, 0, 1) diff --git a/tests/pytest/tools/taosdemoAllTest/moredemo-insert-offset.py b/tests/pytest/tools/taosdemoAllTest/moredemo-insert-offset.py index 077ced5d02c792b1c3344ea3e8b129038652b4b8..955545ac2cb2578089b705e67a97d99678182154 100644 --- a/tests/pytest/tools/taosdemoAllTest/moredemo-insert-offset.py +++ b/tests/pytest/tools/taosdemoAllTest/moredemo-insert-offset.py @@ -50,10 +50,10 @@ class TDTestCase: # insert: drop and child_table_exists combination test # insert: using parament "childtable_offset and childtable_limit" to control table'offset point and offset - os.system("%staosdemo -f tools/taosdemoAllTest/moredemo-offset-newdb.json" % binPath) - os.system("%staosdemo -f tools/taosdemoAllTest/moredemo-offset-limit1.json & " % binPath) - os.system("%staosdemo -f tools/taosdemoAllTest/moredemo-offset-limit94.json & " % binPath) - os.system("%staosdemo -f tools/taosdemoAllTest/moredemo-offset-limit5.json & " % binPath) + os.system("%staosBenchmark -f tools/taosdemoAllTest/moredemo-offset-newdb.json" % binPath) + os.system("%staosBenchmark -f tools/taosdemoAllTest/moredemo-offset-limit1.json & " % binPath) + os.system("%staosBenchmark -f tools/taosdemoAllTest/moredemo-offset-limit94.json & " % binPath) + os.system("%staosBenchmark -f tools/taosdemoAllTest/moredemo-offset-limit5.json & " % binPath) sleep(15) tdSql.execute("use db") tdSql.query("select count(*) from stb0") diff --git a/tests/pytest/tools/taosdemoAllTest/nano_samples.csv b/tests/pytest/tools/taosdemoAllTest/nano_samples.csv deleted file mode 100644 index 5fc779b41b44eda002d246d9554f0abcea03c8d3..0000000000000000000000000000000000000000 --- a/tests/pytest/tools/taosdemoAllTest/nano_samples.csv +++ /dev/null @@ -1,100 +0,0 @@ -8.855,"binary_str0" ,1626870128248246976 -8.75,"binary_str1" ,1626870128249060032 -5.44,"binary_str2" ,1626870128249067968 -8.45,"binary_str3" ,1626870128249072064 -4.07,"binary_str4" ,1626870128249075904 -6.97,"binary_str5" ,1626870128249078976 -6.86,"binary_str6" ,1626870128249082048 -1.585,"binary_str7" ,1626870128249085120 -1.4,"binary_str8" ,1626870128249087936 -5.135,"binary_str9" ,1626870128249092032 -3.15,"binary_str10" ,1626870128249095104 -1.765,"binary_str11" ,1626870128249097920 -7.71,"binary_str12" ,1626870128249100992 -3.91,"binary_str13" ,1626870128249104064 -5.615,"binary_str14" ,1626870128249106880 -9.495,"binary_str15" ,1626870128249109952 -3.825,"binary_str16" ,1626870128249113024 -1.94,"binary_str17" ,1626870128249117120 -5.385,"binary_str18" ,1626870128249119936 -7.075,"binary_str19" ,1626870128249123008 -5.715,"binary_str20" ,1626870128249126080 -1.83,"binary_str21" ,1626870128249128896 -6.365,"binary_str22" ,1626870128249131968 -6.55,"binary_str23" ,1626870128249135040 -6.315,"binary_str24" ,1626870128249138112 -3.82,"binary_str25" ,1626870128249140928 -2.455,"binary_str26" ,1626870128249145024 -7.795,"binary_str27" ,1626870128249148096 -2.47,"binary_str28" ,1626870128249150912 -1.37,"binary_str29" ,1626870128249155008 -5.39,"binary_str30" ,1626870128249158080 -5.13,"binary_str31" ,1626870128249160896 -4.09,"binary_str32" ,1626870128249163968 -5.855,"binary_str33" ,1626870128249167040 -0.17,"binary_str34" ,1626870128249170112 -1.955,"binary_str35" ,1626870128249173952 -0.585,"binary_str36" ,1626870128249178048 -0.33,"binary_str37" ,1626870128249181120 -7.925,"binary_str38" ,1626870128249183936 -9.685,"binary_str39" ,1626870128249187008 -2.6,"binary_str40" ,1626870128249191104 -5.705,"binary_str41" ,1626870128249193920 -3.965,"binary_str42" ,1626870128249196992 -4.43,"binary_str43" ,1626870128249200064 -8.73,"binary_str44" ,1626870128249202880 -3.105,"binary_str45" ,1626870128249205952 -9.39,"binary_str46" ,1626870128249209024 -2.825,"binary_str47" ,1626870128249212096 -9.675,"binary_str48" ,1626870128249214912 -9.99,"binary_str49" ,1626870128249217984 -4.51,"binary_str50" ,1626870128249221056 -4.94,"binary_str51" ,1626870128249223872 -7.72,"binary_str52" ,1626870128249226944 -4.135,"binary_str53" ,1626870128249231040 -2.325,"binary_str54" ,1626870128249234112 -4.585,"binary_str55" ,1626870128249236928 -8.76,"binary_str56" ,1626870128249240000 -4.715,"binary_str57" ,1626870128249243072 -0.56,"binary_str58" ,1626870128249245888 -5.35,"binary_str59" ,1626870128249249984 -5.075,"binary_str60" ,1626870128249253056 -6.665,"binary_str61" ,1626870128249256128 -7.13,"binary_str62" ,1626870128249258944 -2.775,"binary_str63" ,1626870128249262016 -5.775,"binary_str64" ,1626870128249265088 -1.62,"binary_str65" ,1626870128249267904 -1.625,"binary_str66" ,1626870128249270976 -8.15,"binary_str67" ,1626870128249274048 -0.75,"binary_str68" ,1626870128249277120 -3.265,"binary_str69" ,1626870128249280960 -8.585,"binary_str70" ,1626870128249284032 -1.88,"binary_str71" ,1626870128249287104 -8.44,"binary_str72" ,1626870128249289920 -5.12,"binary_str73" ,1626870128249295040 -2.58,"binary_str74" ,1626870128249298112 -9.42,"binary_str75" ,1626870128249300928 -1.765,"binary_str76" ,1626870128249304000 -2.66,"binary_str77" ,1626870128249308096 -1.405,"binary_str78" ,1626870128249310912 -5.595,"binary_str79" ,1626870128249315008 -2.28,"binary_str80" ,1626870128249318080 -9.24,"binary_str81" ,1626870128249320896 -9.03,"binary_str82" ,1626870128249323968 -6.055,"binary_str83" ,1626870128249327040 -1.74,"binary_str84" ,1626870128249330112 -5.77,"binary_str85" ,1626870128249332928 -1.97,"binary_str86" ,1626870128249336000 -0.3,"binary_str87" ,1626870128249339072 -7.145,"binary_str88" ,1626870128249342912 -0.88,"binary_str89" ,1626870128249345984 -8.025,"binary_str90" ,1626870128249349056 -4.81,"binary_str91" ,1626870128249351872 -0.725,"binary_str92" ,1626870128249355968 -3.85,"binary_str93" ,1626870128249359040 -9.455,"binary_str94" ,1626870128249362112 -2.265,"binary_str95" ,1626870128249364928 -3.985,"binary_str96" ,1626870128249368000 -9.375,"binary_str97" ,1626870128249371072 -0.2,"binary_str98" ,1626870128249373888 -6.95,"binary_str99" ,1626870128249377984 diff --git a/tests/pytest/tools/taosdemoAllTest/nano_sampletags.csv b/tests/pytest/tools/taosdemoAllTest/nano_sampletags.csv deleted file mode 100644 index 18fb855d6d9f55c29325c6ea6f77120effa72884..0000000000000000000000000000000000000000 --- a/tests/pytest/tools/taosdemoAllTest/nano_sampletags.csv +++ /dev/null @@ -1,100 +0,0 @@ -"string0",7,8.615 -"string1",4,9.895 -"string2",3,2.92 -"string3",3,5.62 -"string4",7,1.615 -"string5",6,1.45 -"string6",5,7.48 -"string7",7,3.01 -"string8",5,4.76 -"string9",10,7.09 -"string10",2,8.38 -"string11",7,8.65 -"string12",5,5.025 -"string13",10,5.765 -"string14",2,4.57 -"string15",2,1.03 -"string16",7,6.98 -"string17",10,0.23 -"string18",7,5.815 -"string19",1,2.37 -"string20",10,8.865 -"string21",3,1.235 -"string22",2,8.62 -"string23",9,1.045 -"string24",8,4.34 -"string25",1,5.455 -"string26",2,4.475 -"string27",1,6.95 -"string28",2,3.39 -"string29",3,6.79 -"string30",7,9.735 -"string31",1,9.79 -"string32",10,9.955 -"string33",1,5.095 -"string34",3,3.86 -"string35",9,5.105 -"string36",10,4.22 -"string37",1,2.78 -"string38",9,6.345 -"string39",1,0.975 -"string40",5,6.16 -"string41",4,7.735 -"string42",5,6.6 -"string43",8,2.845 -"string44",1,0.655 -"string45",3,2.995 -"string46",9,3.6 -"string47",8,3.47 -"string48",3,7.98 -"string49",6,2.225 -"string50",9,5.44 -"string51",4,6.335 -"string52",3,2.955 -"string53",1,0.565 -"string54",6,5.575 -"string55",6,9.905 -"string56",9,6.025 -"string57",8,0.94 -"string58",10,0.15 -"string59",8,1.555 -"string60",4,2.28 -"string61",2,8.29 -"string62",9,6.22 -"string63",6,3.35 -"string64",10,6.7 -"string65",3,9.345 -"string66",7,9.815 -"string67",1,5.365 -"string68",10,3.81 -"string69",1,6.405 -"string70",8,2.715 -"string71",3,8.58 -"string72",8,6.34 -"string73",2,7.49 -"string74",4,8.64 -"string75",3,8.995 -"string76",7,3.465 -"string77",1,7.64 -"string78",6,3.65 -"string79",6,1.4 -"string80",6,5.875 -"string81",2,1.22 -"string82",5,7.87 -"string83",9,8.41 -"string84",9,8.9 -"string85",9,3.89 -"string86",2,5.0 -"string87",2,4.495 -"string88",4,2.835 -"string89",3,5.895 -"string90",7,8.41 -"string91",5,5.125 -"string92",7,9.165 -"string93",5,8.315 -"string94",10,7.485 -"string95",7,4.635 -"string96",2,6.015 -"string97",8,0.595 -"string98",3,8.79 -"string99",4,1.72 diff --git a/tests/pytest/tools/taosdemoAllTest/query-interrupt.py b/tests/pytest/tools/taosdemoAllTest/query-interrupt.py index 270bfd8b60f559c370eb921cf74fe4f7b82ae06e..df021cbe3be5da9a0a28b78bbafef548c24697fa 100644 --- a/tests/pytest/tools/taosdemoAllTest/query-interrupt.py +++ b/tests/pytest/tools/taosdemoAllTest/query-interrupt.py @@ -52,13 +52,13 @@ class TDTestCase: binPath = buildPath+ "/build/bin/" # # insert 1000w rows in stb0 - os.system("%staosdemo -f tools/taosdemoAllTest/query-interrupt.json -y " % binPath) + os.system("%staosBenchmark -f tools/taosdemoAllTest/query-interrupt.json -y " % binPath) tdSql.execute("use db") tdSql.query("select count (tbname) from stb0") tdSql.checkData(0, 0,60) tdSql.query("select count(*) from stb0") tdSql.checkData(0, 0, 6000000) - os.system('%staosdemo -f tools/taosdemoAllTest/queryall.json -y & ' % binPath) + os.system('%staosBenchmark -f tools/taosdemoAllTest/queryall.json -y & ' % binPath) time.sleep(2) query_pid = int(subprocess.getstatusoutput('ps aux|grep "taosdemoAllTest/queryall.json" |grep -v "grep"|awk \'{print $2}\'')[1]) taosd_cpu_load_1 = float(subprocess.getstatusoutput('top -n 1 -b -p $(ps aux|grep "bin/taosd -c"|grep -v "grep" |awk \'{print $2}\')|awk \'END{print}\' |awk \'{print $9}\'')[1]) diff --git a/tests/pytest/tools/taosdemoAllTest/subscribeNoResult.py b/tests/pytest/tools/taosdemoAllTest/subscribeNoResult.py index 270eea17cb6c913719fb67c4b8f33065b0a0445d..e1a9f647fa2b5d1f561e50a06b9755d78bebfa79 100644 --- a/tests/pytest/tools/taosdemoAllTest/subscribeNoResult.py +++ b/tests/pytest/tools/taosdemoAllTest/subscribeNoResult.py @@ -68,7 +68,7 @@ class TDTestCase: binPath = buildPath+ "/build/bin/" - os.system("%staosdemo -f tools/taosdemoAllTest/sub_no_result.json -g 2>&1 | tee sub_no_result.log" % binPath) + os.system("%staosBenchmark -f tools/taosdemoAllTest/sub_no_result.json -g 2>&1 | tee sub_no_result.log" % binPath) test_line = int(self.execCmdAndGetOutput("cat sub_no_result.log | wc -l")) if(test_line < 1100024): tdLog.exit("failed test subscribeNoResult: %d != expected(1100024)" % test_line) diff --git a/tests/pytest/tools/taosdemoAllTest/taosdemoInsertMSDB.json b/tests/pytest/tools/taosdemoAllTest/taosdemoInsertMSDB.json deleted file mode 100644 index fd458a88d1a434c22958d5086949009cdd6080bf..0000000000000000000000000000000000000000 --- a/tests/pytest/tools/taosdemoAllTest/taosdemoInsertMSDB.json +++ /dev/null @@ -1,63 +0,0 @@ -{ - "filetype": "insert", - "cfgdir": "/etc/taos", - "host": "127.0.0.1", - "port": 6030, - "user": "root", - "password": "taosdata", - "thread_count": 10, - "thread_count_create_tbl": 10, - "result_file": "./insert_res.txt", - "confirm_parameter_prompt": "no", - "insert_interval": 0, - "interlace_rows": 100, - "num_of_records_per_req": 1000, - "max_sql_len": 1024000, - "databases": [{ - "dbinfo": { - "name": "testdb3", - "drop": "yes", - "replica": 1, - "days": 10, - "cache": 50, - "blocks": 8, - "precision": "ms", - "keep": 36500, - "minRows": 100, - "maxRows": 4096, - "comp":2, - "walLevel":1, - "cachelast":0, - "quorum":1, - "fsync":3000, - "update": 0 - }, - "super_tables": [{ - "name": "stb0", - "child_table_exists":"no", - "childtable_count": 100, - "childtable_prefix": "tb0_", - "auto_create_table": "no", - "batch_create_tbl_num": 20, - "data_source": "rand", - "insert_mode": "taosc", - "insert_rows": 100, - "childtable_offset":0, - "multi_thread_write_one_tbl": "no", - "insert_interval":0, - "max_sql_len": 1024000, - "disorder_ratio": 0, - "disorder_range": 1000, - "timestamp_step": 1000, - "start_timestamp": "2021-07-01 00:00:00.000", - "sample_format": "", - "sample_file": "", - "tags_file": "", - "columns": [{"type": "INT"}, {"type": "DOUBLE", "count":3}, {"type": "BINARY", "len": 16, "count":2}, {"type": "BINARY", "len": 32, "count":2}, - {"type": "TIMESTAMP"}, {"type": "BIGINT", "count":3},{"type": "FLOAT", "count":1},{"type": "SMALLINT", "count":1},{"type": "TINYINT", "count":1}, - {"type": "BOOL"},{"type": "NCHAR","len":16}], - "tags": [{"type": "TINYINT", "count":2}, {"type": "BINARY", "len": 16, "count":5},{"type": "NCHAR","len":16, "count":1}] - }] - }] -} - diff --git a/tests/pytest/tools/taosdemoAllTest/taosdemoInsertUSDB.json b/tests/pytest/tools/taosdemoAllTest/taosdemoInsertUSDB.json deleted file mode 100644 index 14bb9e9be07d9bd61dc089af0bb34acd523155d9..0000000000000000000000000000000000000000 --- a/tests/pytest/tools/taosdemoAllTest/taosdemoInsertUSDB.json +++ /dev/null @@ -1,63 +0,0 @@ -{ - "filetype": "insert", - "cfgdir": "/etc/taos", - "host": "127.0.0.1", - "port": 6030, - "user": "root", - "password": "taosdata", - "thread_count": 10, - "thread_count_create_tbl": 10, - "result_file": "./insert_res.txt", - "confirm_parameter_prompt": "no", - "insert_interval": 0, - "interlace_rows": 100, - "num_of_records_per_req": 1000, - "max_sql_len": 1024000, - "databases": [{ - "dbinfo": { - "name": "testdb2", - "drop": "yes", - "replica": 1, - "days": 10, - "cache": 50, - "blocks": 8, - "precision": "us", - "keep": 36500, - "minRows": 100, - "maxRows": 4096, - "comp":2, - "walLevel":1, - "cachelast":0, - "quorum":1, - "fsync":3000, - "update": 0 - }, - "super_tables": [{ - "name": "stb0", - "child_table_exists":"no", - "childtable_count": 100, - "childtable_prefix": "tb0_", - "auto_create_table": "no", - "batch_create_tbl_num": 20, - "data_source": "rand", - "insert_mode": "taosc", - "insert_rows": 100, - "childtable_offset":0, - "multi_thread_write_one_tbl": "no", - "insert_interval":0, - "max_sql_len": 1024000, - "disorder_ratio": 0, - "disorder_range": 1000, - "timestamp_step": 1000, - "start_timestamp": "2021-07-01 00:00:00.000", - "sample_format": "", - "sample_file": "", - "tags_file": "", - "columns": [{"type": "INT"}, {"type": "DOUBLE", "count":3}, {"type": "BINARY", "len": 16, "count":2}, {"type": "BINARY", "len": 32, "count":2}, - {"type": "TIMESTAMP"}, {"type": "BIGINT", "count":3},{"type": "FLOAT", "count":1},{"type": "SMALLINT", "count":1},{"type": "TINYINT", "count":1}, - {"type": "BOOL"},{"type": "NCHAR","len":16}], - "tags": [{"type": "TINYINT", "count":2}, {"type": "BINARY", "len": 16, "count":5},{"type": "NCHAR","len":16, "count":1}] - }] - }] -} - diff --git a/tests/pytest/tools/taosdemoAllTest/taosdemoTestInsertAllType.py b/tests/pytest/tools/taosdemoAllTest/taosdemoTestInsertAllType.py index 7a9cbc231e4a9072d8e70ea2ae133833b13ab100..a2c274007075bcec20914e92bcc28ca37d1ea770 100644 --- a/tests/pytest/tools/taosdemoAllTest/taosdemoTestInsertAllType.py +++ b/tests/pytest/tools/taosdemoAllTest/taosdemoTestInsertAllType.py @@ -49,7 +49,7 @@ class TDTestCase: binPath = buildPath+ "/build/bin/" # insert: create one or mutiple tables per sql and insert multiple rows per sql - os.system("%staosdemo -f tools/taosdemoAllTest/insert-allDataType.json -y " % binPath) + os.system("%staosBenchmark -f tools/taosdemoAllTest/insert-allDataType.json -y " % binPath) tdSql.execute("use db") tdSql.query("select count (tbname) from stb0") tdSql.checkData(0, 0, 1000) @@ -65,7 +65,7 @@ class TDTestCase: tdSql.checkData(0, 0, 200000) # stmt interface - os.system("%staosdemo -f tools/taosdemoAllTest/stmt/insert-allDataType-stmt.json -y " % binPath) + os.system("%staosBenchmark -f tools/taosdemoAllTest/stmt/insert-allDataType-stmt.json -y " % binPath) tdSql.execute("use db") tdSql.query("select count (tbname) from stb0") tdSql.checkData(0, 0, 1000) @@ -135,7 +135,7 @@ class TDTestCase: # taosdemo command line - os.system("%staosdemo -t 1000 -n 100 -T 10 -b INT,TIMESTAMP,BIGINT,FLOAT,DOUBLE,SMALLINT,TINYINT,BOOL,NCHAR,UINT,UBIGINT,UTINYINT,USMALLINT,BINARY -y " % binPath) + os.system("%staosBenchmark -t 1000 -n 100 -T 10 -b INT,TIMESTAMP,BIGINT,FLOAT,DOUBLE,SMALLINT,TINYINT,BOOL,NCHAR,UINT,UBIGINT,UTINYINT,USMALLINT,BINARY -y " % binPath) tdSql.execute("use test") tdSql.query("select count (tbname) from meters") tdSql.checkData(0, 0, 1000) diff --git a/tests/pytest/tools/taosdemoAllTest/taosdemoTestInsertTime_step.py b/tests/pytest/tools/taosdemoAllTest/taosdemoTestInsertTime_step.py deleted file mode 100644 index 7b3b865df91f87622737eede640ec79e880e433b..0000000000000000000000000000000000000000 --- a/tests/pytest/tools/taosdemoAllTest/taosdemoTestInsertTime_step.py +++ /dev/null @@ -1,115 +0,0 @@ -################################################################### -# Copyright (c) 2016 by TAOS Technologies, Inc. -# All rights reserved. -# -# This file is proprietary and confidential to TAOS Technologies. -# No part of this file may be reproduced, stored, transmitted, -# disclosed or used in any form or by any means other than as -# expressly provided by the written permission from Jianhui Tao -# -################################################################### - -# -*- coding: utf-8 -*- - -import sys -import os -from util.log import * -from util.cases import * -from util.sql import * -from util.dnodes import * - - -class TDTestCase: - def init(self, conn, logSql): - tdLog.debug("start to execute %s" % __file__) - tdSql.init(conn.cursor(), logSql) - - def getBuildPath(self): - selfPath = os.path.dirname(os.path.realpath(__file__)) - - if ("community" in selfPath): - projPath = selfPath[:selfPath.find("community")] - else: - projPath = selfPath[:selfPath.find("tests")] - - for root, dirs, files in os.walk(projPath): - if ("taosd" in files): - rootRealPath = os.path.dirname(os.path.realpath(root)) - if ("packaging" not in rootRealPath): - buildPath = root[:len(root)-len("/build/bin")] - break - return buildPath - - def run(self): - buildPath = self.getBuildPath() - if (buildPath == ""): - tdLog.exit("taosd not found!") - else: - tdLog.info("taosd found in %s" % buildPath) - binPath = buildPath+ "/build/bin/" - - # insert: create one or mutiple tables per sql and insert multiple rows per sql - - # check the params of taosdemo about time_step is nano - os.system("%staosdemo -f tools/taosdemoAllTest/taosdemoInsertNanoDB.json -y " % binPath) - tdSql.execute("use testdb1") - tdSql.query("show stables") - tdSql.checkData(0, 4, 100) - tdSql.query("select count (tbname) from stb0") - tdSql.checkData(0, 0, 100) - tdSql.query("select count(*) from tb0_0") - tdSql.checkData(0, 0, 100) - tdSql.query("select count(*) from stb0") - tdSql.checkData(0, 0, 10000) - tdSql.query("describe stb0") - tdSql.getData(9, 1) - tdSql.checkDataType(9, 1,"TIMESTAMP") - tdSql.query("select last(ts) from stb0") - tdSql.checkData(0, 0,"2021-07-01 00:00:00.000099000") - - # check the params of taosdemo about time_step is us - os.system("%staosdemo -f tools/taosdemoAllTest/taosdemoInsertUSDB.json -y " % binPath) - tdSql.execute("use testdb2") - tdSql.query("show stables") - tdSql.checkData(0, 4, 100) - tdSql.query("select count (tbname) from stb0") - tdSql.checkData(0, 0, 100) - tdSql.query("select count(*) from tb0_0") - tdSql.checkData(0, 0, 100) - tdSql.query("select count(*) from stb0") - tdSql.checkData(0, 0, 10000) - tdSql.query("describe stb0") - tdSql.getData(9, 1) - tdSql.checkDataType(9, 1,"TIMESTAMP") - tdSql.query("select last(ts) from stb0") - tdSql.checkData(0, 0,"2021-07-01 00:00:00.099000") - - # check the params of taosdemo about time_step is ms - os.system("%staosdemo -f tools/taosdemoAllTest/taosdemoInsertMSDB.json -y " % binPath) - tdSql.execute("use testdb3") - tdSql.query("show stables") - tdSql.checkData(0, 4, 100) - tdSql.query("select count (tbname) from stb0") - tdSql.checkData(0, 0, 100) - tdSql.query("select count(*) from tb0_0") - tdSql.checkData(0, 0, 100) - tdSql.query("select count(*) from stb0") - tdSql.checkData(0, 0, 10000) - tdSql.query("describe stb0") - tdSql.checkDataType(9, 1,"TIMESTAMP") - tdSql.query("select last(ts) from stb0") - tdSql.checkData(0, 0,"2021-07-01 00:01:39.000") - - - os.system("rm -rf ./res.txt") - os.system("rm -rf ./*.py.sql") - - - - def stop(self): - tdSql.close() - tdLog.success("%s successfully executed" % __file__) - - -tdCases.addWindows(__file__, TDTestCase()) -tdCases.addLinux(__file__, TDTestCase()) diff --git a/tests/pytest/tools/taosdemoAllTest/taosdemoTestInsertWithJsonSml.py b/tests/pytest/tools/taosdemoAllTest/taosdemoTestInsertWithJsonSml.py index 4d9116cc985cb76b4e1e15482cf6158711ed6cc2..18901d508d93906acfa870b38d2ddbaec45195cf 100644 --- a/tests/pytest/tools/taosdemoAllTest/taosdemoTestInsertWithJsonSml.py +++ b/tests/pytest/tools/taosdemoAllTest/taosdemoTestInsertWithJsonSml.py @@ -50,7 +50,7 @@ class TDTestCase: # insert: create one or mutiple tables per sql and insert multiple rows per sql # line_protocol——telnet and json - os.system("%staosdemo -f tools/taosdemoAllTest/sml/insert-1s1tnt1r-sml.json -y " % binPath) + os.system("%staosBenchmark -f tools/taosdemoAllTest/sml/insert-1s1tnt1r-sml.json -y " % binPath) tdSql.execute("use db") tdSql.query("select count (tbname) from stb0") tdSql.checkData(0, 0, 10) @@ -67,7 +67,7 @@ class TDTestCase: # insert: create mutiple tables per sql and insert one rows per sql . - os.system("%staosdemo -f tools/taosdemoAllTest/sml/insert-1s1tntmr-sml.json -y " % binPath) + os.system("%staosBenchmark -f tools/taosdemoAllTest/sml/insert-1s1tntmr-sml.json -y " % binPath) tdSql.execute("use db") tdSql.query("select count (tbname) from stb0") tdSql.checkData(0, 0, 10) @@ -84,7 +84,7 @@ class TDTestCase: # insert: using parament "insert_interval to controls spped of insert. # but We need to have accurate methods to control the speed, such as getting the speed value, checking the count and so on。 - os.system("%staosdemo -f tools/taosdemoAllTest/sml/insert-interval-speed-sml.json -y" % binPath) + os.system("%staosBenchmark -f tools/taosdemoAllTest/sml/insert-interval-speed-sml.json -y" % binPath) tdSql.execute("use db") tdSql.query("select tbname from stb0") tdSql.checkRows(100 ) @@ -103,9 +103,9 @@ class TDTestCase: # insert: drop and child_table_exists combination test # insert: sml can't support parament "childtable_offset and childtable_limit" \ drop=no or child_table_exists = yes - # os.system("%staosdemo -f tools/taosdemoAllTest/sml/insert-nodbnodrop-sml.json -y" % binPath) + # os.system("%staosBenchmark -f tools/taosdemoAllTest/sml/insert-nodbnodrop-sml.json -y" % binPath) # tdSql.error("show dbno.stables") - os.system("%staosdemo -f tools/taosdemoAllTest/sml/insert-newdb-sml.json -y" % binPath) + os.system("%staosBenchmark -f tools/taosdemoAllTest/sml/insert-newdb-sml.json -y" % binPath) tdSql.execute("use db") tdSql.query("select count (tbname) from stb0") tdSql.checkData(0, 0, 5) @@ -117,7 +117,7 @@ class TDTestCase: tdSql.checkData(0, 0, 8) tdSql.query("select count (tbname) from stb4") tdSql.checkData(0, 0, 8) - os.system("%staosdemo -f tools/taosdemoAllTest/sml/insert-renewdb-sml.json -y" % binPath) + os.system("%staosBenchmark -f tools/taosdemoAllTest/sml/insert-renewdb-sml.json -y" % binPath) tdSql.execute("use db") tdSql.query("select count(*) from stb0") tdSql.checkData(0, 0, 50) @@ -133,29 +133,29 @@ class TDTestCase: # insert: let parament in json file is illegal, it'll expect error. tdSql.execute("drop database if exists db") - os.system("%staosdemo -f tools/taosdemoAllTest/sml/insertColumnsAndTagNumLarge4096-sml.json -y " % binPath) + os.system("%staosBenchmark -f tools/taosdemoAllTest/sml/insertColumnsAndTagNumLarge4096-sml.json -y " % binPath) tdSql.error("use db") tdSql.execute("drop database if exists db") - os.system("%staosdemo -f tools/taosdemoAllTest/sml/insertSigcolumnsNum4096-sml.json -y " % binPath) + os.system("%staosBenchmark -f tools/taosdemoAllTest/sml/insertSigcolumnsNum4096-sml.json -y " % binPath) tdSql.error("select * from db.stb0") # tdSql.execute("drop database if exists db") - # os.system("%staosdemo -f tools/taosdemoAllTest/sml/insertColumnsAndTagNum4096-sml.json -y " % binPath) + # os.system("%staosBenchmark -f tools/taosdemoAllTest/sml/insertColumnsAndTagNum4096-sml.json -y " % binPath) # tdSql.query("select count(*) from db.stb0") # tdSql.checkData(0, 0, 10000) tdSql.execute("drop database if exists db") - os.system("%staosdemo -f tools/taosdemoAllTest/sml/insertInterlaceRowsLarge1M-sml.json -y " % binPath) + os.system("%staosBenchmark -f tools/taosdemoAllTest/sml/insertInterlaceRowsLarge1M-sml.json -y " % binPath) tdSql.query("select count(*) from db.stb0") tdSql.checkRows(0) tdSql.execute("drop database if exists db") - os.system("%staosdemo -f tools/taosdemoAllTest/sml/insertColumnsNum0-sml.json -y " % binPath) + os.system("%staosBenchmark -f tools/taosdemoAllTest/sml/insertColumnsNum0-sml.json -y " % binPath) tdSql.execute("use db") tdSql.query("show stables like 'stb0%' ") tdSql.checkData(0, 2, 11) tdSql.execute("drop database if exists db") - os.system("%staosdemo -f tools/taosdemoAllTest/sml/insertTagsNumLarge128-sml.json -y " % binPath) + os.system("%staosBenchmark -f tools/taosdemoAllTest/sml/insertTagsNumLarge128-sml.json -y " % binPath) tdSql.error("use db1") tdSql.execute("drop database if exists db") - os.system("%staosdemo -f tools/taosdemoAllTest/sml/insertBinaryLenLarge16374AllcolLar49151-sml.json -y " % binPath) + os.system("%staosBenchmark -f tools/taosdemoAllTest/sml/insertBinaryLenLarge16374AllcolLar49151-sml.json -y " % binPath) tdSql.query("select count(*) from db.stb0") tdSql.checkRows(1) tdSql.query("select count(*) from db.stb1") @@ -165,21 +165,21 @@ class TDTestCase: tdSql.query("select count(*) from db.stb3") tdSql.checkRows(1) tdSql.execute("drop database if exists db") - os.system("%staosdemo -f tools/taosdemoAllTest/sml/insertNumOfrecordPerReq0-sml.json -y " % binPath) + os.system("%staosBenchmark -f tools/taosdemoAllTest/sml/insertNumOfrecordPerReq0-sml.json -y " % binPath) tdSql.error("select count(*) from db.stb0") tdSql.execute("drop database if exists db") - os.system("%staosdemo -f tools/taosdemoAllTest/sml/insertNumOfrecordPerReqless0-sml.json -y " % binPath) + os.system("%staosBenchmark -f tools/taosdemoAllTest/sml/insertNumOfrecordPerReqless0-sml.json -y " % binPath) tdSql.error("use db") tdSql.execute("drop database if exists db") - os.system("%staosdemo -f tools/taosdemoAllTest/sml/insertChildTab0-sml.json -y " % binPath) + os.system("%staosBenchmark -f tools/taosdemoAllTest/sml/insertChildTab0-sml.json -y " % binPath) tdSql.error("use db") tdSql.execute("drop database if exists db") - os.system("%staosdemo -f tools/taosdemoAllTest/sml/insertChildTabLess0-sml.json -y " % binPath) + os.system("%staosBenchmark -f tools/taosdemoAllTest/sml/insertChildTabLess0-sml.json -y " % binPath) tdSql.error("use db") tdSql.execute("drop database if exists blf") # child table name is invalid reading,so - # os.system("%staosdemo -f tools/taosdemoAllTest/sml/insertTimestepMulRowsLargeint16-sml.json -y " % binPath) + # os.system("%staosBenchmark -f tools/taosdemoAllTest/sml/insertTimestepMulRowsLargeint16-sml.json -y " % binPath) # tdSql.execute("use blf") # tdSql.query("select ts from blf.p_0_topics_7 limit 262800,1") # tdSql.checkData(0, 0, "2020-03-31 12:00:00.000") @@ -189,13 +189,13 @@ class TDTestCase: # tdSql.checkData(0, 0, "2020-09-29 23:59:00") # it will be commented in ci because it spend too much time to insert data, but when you can excute it when you want to test this case. - # os.system("%staosdemo -f tools/taosdemoAllTest/sml/insertMaxNumPerReq-sml.json -y " % binPath) + # os.system("%staosBenchmark -f tools/taosdemoAllTest/sml/insertMaxNumPerReq-sml.json -y " % binPath) # tdSql.execute("use db") # tdSql.query("select count(*) from stb0") # tdSql.checkData(0, 0, 5000000) # tdSql.query("select count(*) from stb1") # tdSql.checkData(0, 0, 5000000) - # os.system("%staosdemo -f tools/taosdemoAllTest/sml/insertMaxNumPerReq-sml-telnet.json -y " % binPath) + # os.system("%staosBenchmark -f tools/taosdemoAllTest/sml/insertMaxNumPerReq-sml-telnet.json -y " % binPath) # tdSql.execute("use db") # tdSql.query("select count(*) from stb0") # tdSql.checkData(0, 0, 5000000) @@ -205,7 +205,7 @@ class TDTestCase: # insert: timestamp and step - os.system("%staosdemo -f tools/taosdemoAllTest/sml/insert-timestep-sml.json -y " % binPath) + os.system("%staosBenchmark -f tools/taosdemoAllTest/sml/insert-timestep-sml.json -y " % binPath) tdSql.execute("use db") tdSql.query("select count (tbname) from stb0") tdSql.checkData(0, 0, 10) @@ -221,7 +221,7 @@ class TDTestCase: tdSql.checkData(0, 0, 400) # # insert: disorder_ratio - os.system("%staosdemo -f tools/taosdemoAllTest/sml/insert-disorder-sml.json 2>&1 -y " % binPath) + os.system("%staosBenchmark -f tools/taosdemoAllTest/sml/insert-disorder-sml.json 2>&1 -y " % binPath) tdSql.execute("use db") tdSql.query("select count (tbname) from stb0") tdSql.checkData(0, 0, 1) @@ -233,7 +233,7 @@ class TDTestCase: tdSql.checkData(0, 0, 10) # insert: doesn‘t currently supported sample json - assert os.system("%staosdemo -f tools/taosdemoAllTest/sml/insert-sample-sml.json -y " % binPath) != 0 + assert os.system("%staosBenchmark -f tools/taosdemoAllTest/sml/insert-sample-sml.json -y " % binPath) != 0 # tdSql.execute("use dbtest123") # tdSql.query("select c2 from stb0") # tdSql.checkData(0, 0, 2147483647) @@ -245,7 +245,7 @@ class TDTestCase: # tdSql.checkRows(10) # insert: test interlace parament - os.system("%staosdemo -f tools/taosdemoAllTest/sml/insert-interlace-row-sml.json -y " % binPath) + os.system("%staosBenchmark -f tools/taosdemoAllTest/sml/insert-interlace-row-sml.json -y " % binPath) tdSql.execute("use db") tdSql.query("select count (tbname) from stb0") tdSql.checkData(0, 0, 100) diff --git a/tests/pytest/tools/taosdemoAllTest/taosdemoTestInsertWithJsonStmt.py b/tests/pytest/tools/taosdemoAllTest/taosdemoTestInsertWithJsonStmt.py index f09880ab727d9a197fb602663da1dc4c6fff7bb7..5dba103ef9eafaf15d3159cae94e2b3a264cd8a9 100644 --- a/tests/pytest/tools/taosdemoAllTest/taosdemoTestInsertWithJsonStmt.py +++ b/tests/pytest/tools/taosdemoAllTest/taosdemoTestInsertWithJsonStmt.py @@ -49,7 +49,7 @@ class TDTestCase: binPath = buildPath+ "/build/bin/" # insert: create one or mutiple tables per sql and insert multiple rows per sql - os.system("%staosdemo -f tools/taosdemoAllTest/stmt/insert-1s1tnt1r-stmt.json -y " % binPath) + os.system("%staosBenchmark -f tools/taosdemoAllTest/stmt/insert-1s1tnt1r-stmt.json -y " % binPath) tdSql.execute("use db") tdSql.query("select count (tbname) from stb0") tdSql.checkData(0, 0, 1000) @@ -66,7 +66,7 @@ class TDTestCase: # insert: create mutiple tables per sql and insert one rows per sql . - os.system("%staosdemo -f tools/taosdemoAllTest/stmt/insert-1s1tntmr-stmt.json -y " % binPath) + os.system("%staosBenchmark -f tools/taosdemoAllTest/stmt/insert-1s1tntmr-stmt.json -y " % binPath) tdSql.execute("use db") tdSql.query("select count (tbname) from stb0") tdSql.checkData(0, 0, 10) @@ -83,7 +83,7 @@ class TDTestCase: # insert: using parament "insert_interval to controls spped of insert. # but We need to have accurate methods to control the speed, such as getting the speed value, checking the count and so on。 - os.system("%staosdemo -f tools/taosdemoAllTest/stmt/insert-interval-speed-stmt.json -y" % binPath) + os.system("%staosBenchmark -f tools/taosdemoAllTest/stmt/insert-interval-speed-stmt.json -y" % binPath) tdSql.execute("use db") tdSql.query("show stables") tdSql.checkData(0, 4, 100) @@ -101,9 +101,9 @@ class TDTestCase: # spend 2min30s for 3 testcases. # insert: drop and child_table_exists combination test # insert: using parament "childtable_offset and childtable_limit" to control table'offset point and offset - os.system("%staosdemo -f tools/taosdemoAllTest/stmt/insert-nodbnodrop-stmt.json -y" % binPath) + os.system("%staosBenchmark -f tools/taosdemoAllTest/stmt/insert-nodbnodrop-stmt.json -y" % binPath) tdSql.error("show dbno.stables") - os.system("%staosdemo -f tools/taosdemoAllTest/stmt/insert-newdb-stmt.json -y" % binPath) + os.system("%staosBenchmark -f tools/taosdemoAllTest/stmt/insert-newdb-stmt.json -y" % binPath) tdSql.execute("use db") tdSql.query("select count (tbname) from stb0") tdSql.checkData(0, 0, 5) @@ -115,7 +115,7 @@ class TDTestCase: tdSql.checkData(0, 0, 8) tdSql.query("select count (tbname) from stb4") tdSql.checkData(0, 0, 8) - os.system("%staosdemo -f tools/taosdemoAllTest/stmt/insert-offset-stmt.json -y" % binPath) + os.system("%staosBenchmark -f tools/taosdemoAllTest/stmt/insert-offset-stmt.json -y" % binPath) tdSql.execute("use db") tdSql.query("select count(*) from stb0") tdSql.checkData(0, 0, 50) @@ -127,7 +127,7 @@ class TDTestCase: tdSql.checkData(0, 0, 180) tdSql.query("select count(*) from stb4") tdSql.checkData(0, 0, 160) - os.system("%staosdemo -f tools/taosdemoAllTest/stmt/insert-newtable-stmt.json -y" % binPath) + os.system("%staosBenchmark -f tools/taosdemoAllTest/stmt/insert-newtable-stmt.json -y" % binPath) tdSql.execute("use db") tdSql.query("select count(*) from stb0") tdSql.checkData(0, 0, 150) @@ -139,7 +139,7 @@ class TDTestCase: tdSql.checkData(0, 0, 340) tdSql.query("select count(*) from stb4") tdSql.checkData(0, 0, 400) - os.system("%staosdemo -f tools/taosdemoAllTest/stmt/insert-renewdb-stmt.json -y" % binPath) + os.system("%staosBenchmark -f tools/taosdemoAllTest/stmt/insert-renewdb-stmt.json -y" % binPath) tdSql.execute("use db") tdSql.query("select count(*) from stb0") tdSql.checkData(0, 0, 50) @@ -155,29 +155,29 @@ class TDTestCase: # insert: let parament in json file is illegal, it'll expect error. tdSql.execute("drop database if exists db") - os.system("%staosdemo -f tools/taosdemoAllTest/stmt/insertColumnsAndTagNumLarge4096-stmt.json -y " % binPath) + os.system("%staosBenchmark -f tools/taosdemoAllTest/stmt/insertColumnsAndTagNumLarge4096-stmt.json -y " % binPath) tdSql.error("use db") tdSql.execute("drop database if exists db") - os.system("%staosdemo -f tools/taosdemoAllTest/stmt/insertSigcolumnsNum4096-stmt.json -y " % binPath) + os.system("%staosBenchmark -f tools/taosdemoAllTest/stmt/insertSigcolumnsNum4096-stmt.json -y " % binPath) tdSql.error("select * from db.stb0") # tdSql.execute("drop database if exists db") - # os.system("%staosdemo -f tools/taosdemoAllTest/stmt/insertColumnsAndTagNum4096-stmt.json -y " % binPath) + # os.system("%staosBenchmark -f tools/taosdemoAllTest/stmt/insertColumnsAndTagNum4096-stmt.json -y " % binPath) # tdSql.query("select count(*) from db.stb0") # tdSql.checkData(0, 0, 10000) tdSql.execute("drop database if exists db") - os.system("%staosdemo -f tools/taosdemoAllTest/stmt/insertInterlaceRowsLarge1M-stmt.json -y " % binPath) + os.system("%staosBenchmark -f tools/taosdemoAllTest/stmt/insertInterlaceRowsLarge1M-stmt.json -y " % binPath) tdSql.query("select count(*) from db.stb0") tdSql.checkRows(0) tdSql.execute("drop database if exists db") - os.system("%staosdemo -f tools/taosdemoAllTest/stmt/insertColumnsNum0-stmt.json -y " % binPath) + os.system("%staosBenchmark -f tools/taosdemoAllTest/stmt/insertColumnsNum0-stmt.json -y " % binPath) tdSql.execute("use db") tdSql.query("show stables like 'stb0%' ") tdSql.checkData(0, 2, 11) tdSql.execute("drop database if exists db") - os.system("%staosdemo -f tools/taosdemoAllTest/stmt/insertTagsNumLarge128-stmt.json -y " % binPath) + os.system("%staosBenchmark -f tools/taosdemoAllTest/stmt/insertTagsNumLarge128-stmt.json -y " % binPath) tdSql.error("use db1") tdSql.execute("drop database if exists db") - os.system("%staosdemo -f tools/taosdemoAllTest/stmt/insertBinaryLenLarge16374AllcolLar49151-stmt.json -y " % binPath) + os.system("%staosBenchmark -f tools/taosdemoAllTest/stmt/insertBinaryLenLarge16374AllcolLar49151-stmt.json -y " % binPath) tdSql.query("select count(*) from db.stb0") tdSql.checkRows(1) tdSql.query("select count(*) from db.stb1") @@ -187,19 +187,19 @@ class TDTestCase: tdSql.query("select count(*) from db.stb3") tdSql.checkRows(1) tdSql.execute("drop database if exists db") - os.system("%staosdemo -f tools/taosdemoAllTest/stmt/insertNumOfrecordPerReq0-stmt.json -y " % binPath) + os.system("%staosBenchmark -f tools/taosdemoAllTest/stmt/insertNumOfrecordPerReq0-stmt.json -y " % binPath) tdSql.error("select count(*) from db.stb0") tdSql.execute("drop database if exists db") - os.system("%staosdemo -f tools/taosdemoAllTest/stmt/insertNumOfrecordPerReqless0-stmt.json -y " % binPath) + os.system("%staosBenchmark -f tools/taosdemoAllTest/stmt/insertNumOfrecordPerReqless0-stmt.json -y " % binPath) tdSql.error("use db") tdSql.execute("drop database if exists db") - os.system("%staosdemo -f tools/taosdemoAllTest/stmt/insertChildTab0-stmt.json -y " % binPath) + os.system("%staosBenchmark -f tools/taosdemoAllTest/stmt/insertChildTab0-stmt.json -y " % binPath) tdSql.error("use db") tdSql.execute("drop database if exists db") - os.system("%staosdemo -f tools/taosdemoAllTest/stmt/insertChildTabLess0-stmt.json -y " % binPath) + os.system("%staosBenchmark -f tools/taosdemoAllTest/stmt/insertChildTabLess0-stmt.json -y " % binPath) tdSql.error("use db") tdSql.execute("drop database if exists blf") - os.system("%staosdemo -f tools/taosdemoAllTest/stmt/insertTimestepMulRowsLargeint16-stmt.json -y " % binPath) + os.system("%staosBenchmark -f tools/taosdemoAllTest/stmt/insertTimestepMulRowsLargeint16-stmt.json -y " % binPath) tdSql.execute("use blf") tdSql.query("select ts from blf.p_0_topics_7 limit 262800,1") tdSql.checkData(0, 0, "2020-03-31 12:00:00.000") @@ -207,7 +207,7 @@ class TDTestCase: tdSql.checkData(0, 0, "2019-10-01 00:00:00") tdSql.query("select last(ts) from blf.p_0_topics_6 ") tdSql.checkData(0, 0, "2020-09-29 23:59:00") - os.system("%staosdemo -f tools/taosdemoAllTest/stmt/insertMaxNumPerReq-stmt.json -y " % binPath) + os.system("%staosBenchmark -f tools/taosdemoAllTest/stmt/insertMaxNumPerReq-stmt.json -y " % binPath) tdSql.execute("use db") tdSql.query("select count(*) from stb0") tdSql.checkData(0, 0, 5000000) @@ -216,7 +216,7 @@ class TDTestCase: # insert: sample json - os.system("%staosdemo -f tools/taosdemoAllTest/stmt/insert-sample-ts-stmt.json -y " % binPath) + os.system("%staosBenchmark -f tools/taosdemoAllTest/stmt/insert-sample-ts-stmt.json -y " % binPath) tdSql.execute("use dbtest123") tdSql.query("select c2 from stb0") tdSql.checkData(0, 0, 2147483647) @@ -235,7 +235,7 @@ class TDTestCase: tdSql.checkRows(10) # insert: timestamp and step - os.system("%staosdemo -f tools/taosdemoAllTest/stmt/insert-timestep-stmt.json -y " % binPath) + os.system("%staosBenchmark -f tools/taosdemoAllTest/stmt/insert-timestep-stmt.json -y " % binPath) tdSql.execute("use db") tdSql.query("show stables") tdSql.query("select count (tbname) from stb0") @@ -252,7 +252,7 @@ class TDTestCase: tdSql.checkData(0, 0, 400) # # insert: disorder_ratio - os.system("%staosdemo -f tools/taosdemoAllTest/stmt/insert-disorder-stmt.json 2>&1 -y " % binPath) + os.system("%staosBenchmark -f tools/taosdemoAllTest/stmt/insert-disorder-stmt.json 2>&1 -y " % binPath) tdSql.execute("use db") tdSql.query("select count (tbname) from stb0") tdSql.checkData(0, 0, 1) @@ -264,7 +264,7 @@ class TDTestCase: tdSql.checkData(0, 0, 10) # insert: sample json - os.system("%staosdemo -f tools/taosdemoAllTest/stmt/insert-sample-stmt.json -y " % binPath) + os.system("%staosBenchmark -f tools/taosdemoAllTest/stmt/insert-sample-stmt.json -y " % binPath) tdSql.execute("use dbtest123") tdSql.query("select c2 from stb0") tdSql.checkData(0, 0, 2147483647) @@ -276,7 +276,7 @@ class TDTestCase: tdSql.checkRows(10) # insert: test interlace parament - os.system("%staosdemo -f tools/taosdemoAllTest/stmt/insert-interlace-row-stmt.json -y " % binPath) + os.system("%staosBenchmark -f tools/taosdemoAllTest/stmt/insert-interlace-row-stmt.json -y " % binPath) tdSql.execute("use db") tdSql.query("select count (tbname) from stb0") tdSql.checkData(0, 0, 100) @@ -289,7 +289,7 @@ class TDTestCase: tdSql.execute('drop database if exists db') tdSql.execute('create database db') tdSql.execute('use db') - os.system("%staosdemo -y -f tools/taosdemoAllTest/stmt/insert-drop-exist-auto-N00-stmt.json " % binPath) # drop = no, child_table_exists, auto_create_table varies + os.system("%staosBenchmark -y -f tools/taosdemoAllTest/stmt/insert-drop-exist-auto-N00-stmt.json " % binPath) # drop = no, child_table_exists, auto_create_table varies tdSql.execute('use db') tdSql.query('show tables like \'NN123%\'') #child_table_exists = no, auto_create_table varies = 123 tdSql.checkRows(20) @@ -305,7 +305,7 @@ class TDTestCase: tdSql.checkRows(0) tdSql.execute('drop database if exists db') - os.system("%staosdemo -y -f tools/taosdemoAllTest/stmt/insert-drop-exist-auto-Y00-stmt.json " % binPath) # drop = yes, child_table_exists, auto_create_table varies + os.system("%staosBenchmark -y -f tools/taosdemoAllTest/stmt/insert-drop-exist-auto-Y00-stmt.json " % binPath) # drop = yes, child_table_exists, auto_create_table varies tdSql.execute('use db') tdSql.query('show tables like \'YN123%\'') #child_table_exists = no, auto_create_table varies = 123 tdSql.checkRows(20) diff --git a/tests/pytest/tools/taosdemoAllTest/taosdemoTestInsertWithJsonStmtPerformance.py b/tests/pytest/tools/taosdemoAllTest/taosdemoTestInsertWithJsonStmtPerformance.py index bc8cf74ab21c20be24dcd4c9c53d9dc01b49f1c4..ff22ffe5a56bf69559d77bc202f289d4349e1e38 100644 --- a/tests/pytest/tools/taosdemoAllTest/taosdemoTestInsertWithJsonStmtPerformance.py +++ b/tests/pytest/tools/taosdemoAllTest/taosdemoTestInsertWithJsonStmtPerformance.py @@ -49,16 +49,16 @@ class TDTestCase: binPath = buildPath+ "/build/bin/" # insert: create one or mutiple tables per sql and insert multiple rows per sql - os.system("%staosdemo -f tools/taosdemoAllTest/stmt/1174-small-stmt-random.json -y " % binPath) + os.system("%staosBenchmark -f tools/taosdemoAllTest/stmt/1174-small-stmt-random.json -y " % binPath) # sleep(60) - # os.system("%staosdemo -f tools/taosdemoAllTest/stmt/1174-small-taosc.json -y " % binPath) + # os.system("%staosBenchmark -f tools/taosdemoAllTest/stmt/1174-small-taosc.json -y " % binPath) # sleep(60) - # os.system("%staosdemo -f tools/taosdemoAllTest/stmt/1174-small-stmt.json -y " % binPath) + # os.system("%staosBenchmark -f tools/taosdemoAllTest/stmt/1174-small-stmt.json -y " % binPath) # sleep(60) - # os.system("%staosdemo -f tools/taosdemoAllTest/stmt/1174-large-taosc.json -y " % binPath) + # os.system("%staosBenchmark -f tools/taosdemoAllTest/stmt/1174-large-taosc.json -y " % binPath) # sleep(60) - # os.system("%staosdemo -f tools/taosdemoAllTest/stmt/1174-large-stmt.json -y " % binPath) + # os.system("%staosBenchmark -f tools/taosdemoAllTest/stmt/1174-large-stmt.json -y " % binPath) # tdSql.execute("use db") # tdSql.query("select count (tbname) from stb0") diff --git a/tests/pytest/tools/taosdemoAllTest/taosdemoTestNanoDatabase.json b/tests/pytest/tools/taosdemoAllTest/taosdemoTestNanoDatabase.json deleted file mode 100644 index e6c4b3205a77e20714067733bfa6f6c4053f087c..0000000000000000000000000000000000000000 --- a/tests/pytest/tools/taosdemoAllTest/taosdemoTestNanoDatabase.json +++ /dev/null @@ -1,88 +0,0 @@ -{ - "filetype": "insert", - "cfgdir": "/etc/taos", - "host": "127.0.0.1", - "port": 6030, - "user": "root", - "password": "taosdata", - "thread_count": 10, - "thread_count_create_tbl": 10, - "result_file": "./insert_res.txt", - "confirm_parameter_prompt": "no", - "insert_interval": 0, - "interlace_rows": 100, - "num_of_records_per_req": 1000, - "max_sql_len": 1024000, - "databases": [{ - "dbinfo": { - "name": "nsdb", - "drop": "yes", - "replica": 1, - "days": 10, - "cache": 50, - "blocks": 8, - "precision": "ns", - "keep": 36500, - "minRows": 100, - "maxRows": 4096, - "comp":2, - "walLevel":1, - "cachelast":0, - "quorum":1, - "fsync":3000, - "update": 0 - }, - "super_tables": [{ - "name": "stb0", - "child_table_exists":"no", - "childtable_count": 100, - "childtable_prefix": "tb0_", - "auto_create_table": "no", - "batch_create_tbl_num": 20, - "data_source": "rand", - "insert_mode": "taosc", - "insert_rows": 100, - "childtable_offset":0, - "multi_thread_write_one_tbl": "no", - "insert_interval":0, - "max_sql_len": 1024000, - "disorder_ratio": 0, - "disorder_range": 1000, - "timestamp_step": 10000000, - "start_timestamp": "2021-07-01 00:00:00.000", - "sample_format": "", - "sample_file": "", - "tags_file": "", - "columns": [{"type": "INT"}, {"type": "DOUBLE", "count":3}, {"type": "BINARY", "len": 16, "count":2}, {"type": "BINARY", "len": 32, "count":2}, - {"type": "TIMESTAMP"}, {"type": "BIGINT", "count":3},{"type": "FLOAT", "count":1},{"type": "SMALLINT", "count":1},{"type": "TINYINT", "count":1}, - {"type": "BOOL"},{"type": "NCHAR","len":16}], - "tags": [{"type": "TINYINT", "count":2}, {"type": "BINARY", "len": 16, "count":5},{"type": "NCHAR","len":16, "count":1}] - }, - { - "name": "stb1", - "child_table_exists":"no", - "childtable_count": 100, - "childtable_prefix": "tb1_", - "auto_create_table": "no", - "batch_create_tbl_num": 20, - "data_source": "rand", - "insert_mode": "taosc", - "insert_rows": 100, - "childtable_offset":0, - "multi_thread_write_one_tbl": "no", - "insert_interval":0, - "max_sql_len": 1024000, - "disorder_ratio": 10, - "disorder_range": 1000, - "timestamp_step": 10000000, - "start_timestamp": "2021-07-01 00:00:00.000", - "sample_format": "", - "sample_file": "", - "tags_file": "", - "columns": [{"type": "INT"}, {"type": "DOUBLE", "count":3}, {"type": "BINARY", "len": 16, "count":2}, {"type": "BINARY", "len": 32, "count":2}, - {"type": "TIMESTAMP"}, {"type": "BIGINT", "count":3},{"type": "FLOAT", "count":1},{"type": "SMALLINT", "count":1},{"type": "TINYINT", "count":1}, - {"type": "BOOL"},{"type": "NCHAR","len":16}], - "tags": [{"type": "TINYINT", "count":2}, {"type": "BINARY", "len": 16, "count":5},{"type": "NCHAR","len":16, "count":1}] - }] - }] -} diff --git a/tests/pytest/tools/taosdemoAllTest/taosdemoTestNanoDatabaseInsertForSub.json b/tests/pytest/tools/taosdemoAllTest/taosdemoTestNanoDatabaseInsertForSub.json deleted file mode 100644 index a19132b1da9c99b8fe3792a1c2d475fd4f18ef91..0000000000000000000000000000000000000000 --- a/tests/pytest/tools/taosdemoAllTest/taosdemoTestNanoDatabaseInsertForSub.json +++ /dev/null @@ -1,84 +0,0 @@ -{ - "filetype": "insert", - "cfgdir": "/etc/taos", - "host": "127.0.0.1", - "port": 6030, - "user": "root", - "password": "taosdata", - "thread_count": 10, - "thread_count_create_tbl": 10, - "result_file": "./insert_res.txt", - "confirm_parameter_prompt": "no", - "insert_interval": 0, - "interlace_rows": 100, - "num_of_records_per_req": 1000, - "max_sql_len": 1024000, - "databases": [{ - "dbinfo": { - "name": "subnsdb", - "drop": "yes", - "replica": 1, - "days": 10, - "cache": 50, - "blocks": 8, - "precision": "ns", - "keep": 36500, - "minRows": 100, - "maxRows": 4096, - "comp":2, - "walLevel":1, - "cachelast":0, - "quorum":1, - "fsync":3000, - "update": 0 - }, - "super_tables": [{ - "name": "stb0", - "child_table_exists":"no", - "childtable_count": 10, - "childtable_prefix": "tb0_", - "auto_create_table": "no", - "batch_create_tbl_num": 20, - "data_source": "samples", - "insert_mode": "taosc", - "insert_rows": 10, - "childtable_offset":0, - "multi_thread_write_one_tbl": "no", - "insert_interval":0, - "max_sql_len": 1024000, - "disorder_ratio": 0, - "disorder_range": 1000, - "timestamp_step": 10000000, - "start_timestamp": "2021-07-01 00:00:00.000", - "sample_format": "csv", - "sample_file": "./tools/taosdemoAllTest/nano_samples.csv", - "tags_file": "./tools/taosdemoAllTest/nano_sampletags.csv", - "columns": [{"type": "DOUBLE"}, {"type": "BINARY", "len": 64, "count":1}, {"type": "TIMESTAMP", "count":1}], - "tags": [{"type": "BINARY", "len": 16, "count":1},{"type": "INT"},{"type": "DOUBLE"}] - }, - { - "name": "stb1", - "child_table_exists":"no", - "childtable_count": 10, - "childtable_prefix": "tb1_", - "auto_create_table": "no", - "batch_create_tbl_num": 20, - "data_source": "samples", - "insert_mode": "taosc", - "insert_rows": 10, - "childtable_offset":0, - "multi_thread_write_one_tbl": "no", - "insert_interval":0, - "max_sql_len": 1024000, - "disorder_ratio": 10, - "disorder_range": 1000, - "timestamp_step": 10000000, - "start_timestamp": "2021-07-01 00:00:00.000", - "sample_format": "csv", - "sample_file": "./tools/taosdemoAllTest/nano_samples.csv", - "tags_file": "./tools/taosdemoAllTest/nano_sampletags.csv", - "columns": [{"type": "DOUBLE"}, {"type": "BINARY", "len": 64, "count":1}, {"type": "TIMESTAMP", "count":1}], - "tags": [{"type": "BINARY", "len": 16, "count":1},{"type": "INT"},{"type": "DOUBLE"}] - }] - }] -} diff --git a/tests/pytest/tools/taosdemoAllTest/taosdemoTestNanoDatabaseNow.json b/tests/pytest/tools/taosdemoAllTest/taosdemoTestNanoDatabaseNow.json deleted file mode 100644 index 3b4c43d5d05ee1a1b26ee4016b1c38aade592b56..0000000000000000000000000000000000000000 --- a/tests/pytest/tools/taosdemoAllTest/taosdemoTestNanoDatabaseNow.json +++ /dev/null @@ -1,62 +0,0 @@ -{ - "filetype": "insert", - "cfgdir": "/etc/taos", - "host": "127.0.0.1", - "port": 6030, - "user": "root", - "password": "taosdata", - "thread_count": 10, - "thread_count_create_tbl": 10, - "result_file": "./insert_res.txt", - "confirm_parameter_prompt": "no", - "insert_interval": 0, - "interlace_rows": 100, - "num_of_records_per_req": 1000, - "max_sql_len": 1024000, - "databases": [{ - "dbinfo": { - "name": "nsdb2", - "drop": "yes", - "replica": 1, - "days": 10, - "cache": 50, - "blocks": 8, - "precision": "ns", - "keep": 36500, - "minRows": 100, - "maxRows": 4096, - "comp":2, - "walLevel":1, - "cachelast":0, - "quorum":1, - "fsync":3000, - "update": 0 - }, - "super_tables": [{ - "name": "stb0", - "child_table_exists":"no", - "childtable_count": 100, - "childtable_prefix": "tb0_", - "auto_create_table": "no", - "batch_create_tbl_num": 20, - "data_source": "rand", - "insert_mode": "taosc", - "insert_rows": 100, - "childtable_offset":0, - "multi_thread_write_one_tbl": "no", - "insert_interval":0, - "max_sql_len": 1024000, - "disorder_ratio": 0, - "disorder_range": 1000, - "timestamp_step": 10, - "start_timestamp": "now", - "sample_format": "", - "sample_file": "", - "tags_file": "", - "columns": [{"type": "INT"}, {"type": "DOUBLE", "count":3}, {"type": "BINARY", "len": 16, "count":2}, {"type": "BINARY", "len": 32, "count":2}, - {"type": "TIMESTAMP"}, {"type": "BIGINT", "count":3},{"type": "FLOAT", "count":1},{"type": "SMALLINT", "count":1},{"type": "TINYINT", "count":1}, - {"type": "BOOL"},{"type": "NCHAR","len":16}], - "tags": [{"type": "TINYINT", "count":2}, {"type": "BINARY", "len": 16, "count":5},{"type": "NCHAR","len":16, "count":1}] - }] - }] -} diff --git a/tests/pytest/tools/taosdemoAllTest/taosdemoTestNanoDatabasecsv.json b/tests/pytest/tools/taosdemoAllTest/taosdemoTestNanoDatabasecsv.json deleted file mode 100644 index 7fb90727ef6fa38da73639ebe11125924b9ed507..0000000000000000000000000000000000000000 --- a/tests/pytest/tools/taosdemoAllTest/taosdemoTestNanoDatabasecsv.json +++ /dev/null @@ -1,84 +0,0 @@ -{ - "filetype": "insert", - "cfgdir": "/etc/taos", - "host": "127.0.0.1", - "port": 6030, - "user": "root", - "password": "taosdata", - "thread_count": 10, - "thread_count_create_tbl": 10, - "result_file": "./insert_res.txt", - "confirm_parameter_prompt": "no", - "insert_interval": 0, - "interlace_rows": 100, - "num_of_records_per_req": 1000, - "max_sql_len": 1024000, - "databases": [{ - "dbinfo": { - "name": "nsdbcsv", - "drop": "yes", - "replica": 1, - "days": 10, - "cache": 50, - "blocks": 8, - "precision": "ns", - "keep": 36500, - "minRows": 100, - "maxRows": 4096, - "comp":2, - "walLevel":1, - "cachelast":0, - "quorum":1, - "fsync":3000, - "update": 0 - }, - "super_tables": [{ - "name": "stb0", - "child_table_exists":"no", - "childtable_count": 100, - "childtable_prefix": "tb0_", - "auto_create_table": "no", - "batch_create_tbl_num": 20, - "data_source": "samples", - "insert_mode": "taosc", - "insert_rows": 100, - "childtable_offset":0, - "multi_thread_write_one_tbl": "no", - "insert_interval":0, - "max_sql_len": 1024000, - "disorder_ratio": 0, - "disorder_range": 1000, - "timestamp_step": 10000000, - "start_timestamp": "2021-07-01 00:00:00.000", - "sample_format": "csv", - "sample_file": "./tools/taosdemoAllTest/nano_samples.csv", - "tags_file": "./tools/taosdemoAllTest/nano_sampletags.csv", - "columns": [{"type": "DOUBLE"}, {"type": "BINARY", "len": 64, "count":1}, {"type": "TIMESTAMP", "count":1}], - "tags": [{"type": "BINARY", "len": 16, "count":1},{"type": "INT"},{"type": "DOUBLE"}] - }, - { - "name": "stb1", - "child_table_exists":"no", - "childtable_count": 100, - "childtable_prefix": "tb1_", - "auto_create_table": "no", - "batch_create_tbl_num": 20, - "data_source": "samples", - "insert_mode": "taosc", - "insert_rows": 100, - "childtable_offset":0, - "multi_thread_write_one_tbl": "no", - "insert_interval":0, - "max_sql_len": 1024000, - "disorder_ratio": 10, - "disorder_range": 1000, - "timestamp_step": 10000000, - "start_timestamp": "2021-07-01 00:00:00.000", - "sample_format": "csv", - "sample_file": "./tools/taosdemoAllTest/nano_samples.csv", - "tags_file": "./tools/taosdemoAllTest/nano_sampletags.csv", - "columns": [{"type": "DOUBLE"}, {"type": "BINARY", "len": 64, "count":1}, {"type": "TIMESTAMP", "count":1}], - "tags": [{"type": "BINARY", "len": 16, "count":1},{"type": "INT"},{"type": "DOUBLE"}] - }] - }] -} diff --git a/tests/pytest/tools/taosdemoAllTest/taosdemoTestQueryWithJson.py b/tests/pytest/tools/taosdemoAllTest/taosdemoTestQueryWithJson.py index 4025e023809d773d750314c8fa635be664b2ff76..e0b56b93ba0ed2c1e0a3e25bdc176059ea1ef61a 100644 --- a/tests/pytest/tools/taosdemoAllTest/taosdemoTestQueryWithJson.py +++ b/tests/pytest/tools/taosdemoAllTest/taosdemoTestQueryWithJson.py @@ -108,10 +108,10 @@ class TDTestCase: # taosc query: query specified table and query super table os.system( - "%staosdemo -f tools/taosdemoAllTest/queryInsertdata.json" % + "%staosBenchmark -f tools/taosdemoAllTest/queryInsertdata.json" % binPath) os.system( - "%staosdemo -f tools/taosdemoAllTest/queryTaosc.json" % + "%staosBenchmark -f tools/taosdemoAllTest/queryTaosc.json" % binPath) os.system("cat query_res0.txt* > all_query_res0_taosc.txt") os.system("cat query_res1.txt* > all_query_res1_taosc.txt") @@ -138,10 +138,10 @@ class TDTestCase: # use restful api to query os.system( - "%staosdemo -f tools/taosdemoAllTest/queryInsertrestdata.json" % + "%staosBenchmark -f tools/taosdemoAllTest/queryInsertrestdata.json" % binPath) os.system( - "%staosdemo -f tools/taosdemoAllTest/queryRestful.json" % + "%staosBenchmark -f tools/taosdemoAllTest/queryRestful.json" % binPath) os.system("cat query_res0.txt* > all_query_res0_rest.txt") os.system("cat query_res1.txt* > all_query_res1_rest.txt") @@ -175,55 +175,55 @@ class TDTestCase: # query times less than or equal to 100 os.system( - "%staosdemo -f tools/taosdemoAllTest/queryInsertdata.json" % + "%staosBenchmark -f tools/taosdemoAllTest/queryInsertdata.json" % binPath) os.system( - "%staosdemo -f tools/taosdemoAllTest/querySpeciMutisql100.json" % + "%staosBenchmark -f tools/taosdemoAllTest/querySpeciMutisql100.json" % binPath) os.system( - "%staosdemo -f tools/taosdemoAllTest/querySuperMutisql100.json" % + "%staosBenchmark -f tools/taosdemoAllTest/querySuperMutisql100.json" % binPath) # query result print QPS os.system( - "%staosdemo -f tools/taosdemoAllTest/queryInsertdata.json" % + "%staosBenchmark -f tools/taosdemoAllTest/queryInsertdata.json" % binPath) exceptcode = os.system( - "%staosdemo -f tools/taosdemoAllTest/queryQps.json" % + "%staosBenchmark -f tools/taosdemoAllTest/queryQps.json" % binPath) assert exceptcode == 0 # use illegal or out of range parameters query json file os.system( - "%staosdemo -f tools/taosdemoAllTest/queryInsertdata.json" % + "%staosBenchmark -f tools/taosdemoAllTest/queryInsertdata.json" % binPath) exceptcode = os.system( - "%staosdemo -f tools/taosdemoAllTest/queryTimes0.json" % + "%staosBenchmark -f tools/taosdemoAllTest/queryTimes0.json" % binPath) assert exceptcode != 0 exceptcode0 = os.system( - "%staosdemo -f tools/taosdemoAllTest/queryTimesless0.json" % + "%staosBenchmark -f tools/taosdemoAllTest/queryTimesless0.json" % binPath) assert exceptcode0 != 0 exceptcode1 = os.system( - "%staosdemo -f tools/taosdemoAllTest/queryConcurrentless0.json" % + "%staosBenchmark -f tools/taosdemoAllTest/queryConcurrentless0.json" % binPath) assert exceptcode1 != 0 exceptcode2 = os.system( - "%staosdemo -f tools/taosdemoAllTest/queryConcurrent0.json" % + "%staosBenchmark -f tools/taosdemoAllTest/queryConcurrent0.json" % binPath) assert exceptcode2 != 0 exceptcode3 = os.system( - "%staosdemo -f tools/taosdemoAllTest/querrThreadsless0.json" % + "%staosBenchmark -f tools/taosdemoAllTest/querrThreadsless0.json" % binPath) assert exceptcode3 != 0 exceptcode4 = os.system( - "%staosdemo -f tools/taosdemoAllTest/querrThreads0.json" % + "%staosBenchmark -f tools/taosdemoAllTest/querrThreads0.json" % binPath) assert exceptcode4 != 0 diff --git a/tests/pytest/tools/taosdemoAllTest/taosdemoTestSubWithJson.py b/tests/pytest/tools/taosdemoAllTest/taosdemoTestSubWithJson.py index 3e967581a4491da4108b981ccd83949751406b82..265f50237bf2b5dae80eccc94aad885a7b84f5f2 100644 --- a/tests/pytest/tools/taosdemoAllTest/taosdemoTestSubWithJson.py +++ b/tests/pytest/tools/taosdemoAllTest/taosdemoTestSubWithJson.py @@ -74,8 +74,8 @@ class TDTestCase: os.system("rm -rf ./all_subscribe_res*") sleep(2) # subscribe: sync - os.system("%staosdemo -f tools/taosdemoAllTest/subInsertdata.json" % binPath) - os.system("nohup %staosdemo -f tools/taosdemoAllTest/subSync.json &" % binPath) + os.system("%staosBenchmark -f tools/taosdemoAllTest/subInsertdata.json" % binPath) + os.system("nohup %staosBenchmark -f tools/taosdemoAllTest/subSync.json &" % binPath) query_pid = int(subprocess.getstatusoutput('ps aux|grep "taosdemoAllTest/subSync.json" |grep -v "grep"|awk \'{print $2}\'')[1]) # insert extral data @@ -112,21 +112,21 @@ class TDTestCase: os.system("rm -rf ./all_subscribe*") # # sql number lager 100 - os.system("%staosdemo -f tools/taosdemoAllTest/subInsertdataMaxsql100.json" % binPath) - assert os.system("%staosdemo -f tools/taosdemoAllTest/subSyncSpecMaxsql100.json" % binPath) != 0 - assert os.system("%staosdemo -f tools/taosdemoAllTest/subSyncSuperMaxsql100.json" % binPath) != 0 + os.system("%staosBenchmark -f tools/taosdemoAllTest/subInsertdataMaxsql100.json" % binPath) + assert os.system("%staosBenchmark -f tools/taosdemoAllTest/subSyncSpecMaxsql100.json" % binPath) != 0 + assert os.system("%staosBenchmark -f tools/taosdemoAllTest/subSyncSuperMaxsql100.json" % binPath) != 0 # # result files is null - # os.system("%staosdemo -f tools/taosdemoAllTest/subInsertdataMaxsql100.json" % binPath) - # os.system("%staosdemo -f tools/taosdemoAllTest/subSyncResFileNull.json" % binPath) - # # assert os.system("%staosdemo -f tools/taosdemoAllTest/subSyncResFileNull.json" % binPath) != 0 + # os.system("%staosBenchmark -f tools/taosdemoAllTest/subInsertdataMaxsql100.json" % binPath) + # os.system("%staosBenchmark -f tools/taosdemoAllTest/subSyncResFileNull.json" % binPath) + # # assert os.system("%staosBenchmark -f tools/taosdemoAllTest/subSyncResFileNull.json" % binPath) != 0 # resubAfterConsume= -1 endAfter=-1 ; os.system('kill -9 `ps aux|grep "subSyncResubACMinus1.json" |grep -v "grep"|awk \'{print $2}\'` ') - os.system("nohup %staosdemo -f tools/taosdemoAllTest/Resubjson/subSyncResubACMinus1.json & " % binPath) + os.system("nohup %staosBenchmark -f tools/taosdemoAllTest/Resubjson/subSyncResubACMinus1.json & " % binPath) sleep(2) query_pid1 = int(subprocess.getstatusoutput('ps aux|grep "subSyncResubACMinus1.json" |grep -v "grep"|awk \'{print $2}\'')[1]) print("get sub1 process'pid") @@ -144,9 +144,9 @@ class TDTestCase: os.system("rm -rf ./subscribe_res*") # # resubAfterConsume= -1 endAfter=0 ; - # os.system("%staosdemo -f tools/taosdemoAllTest/subInsertdataMaxsql100.json" % binPath) + # os.system("%staosBenchmark -f tools/taosdemoAllTest/subInsertdataMaxsql100.json" % binPath) # os.system('kill -9 `ps aux|grep "subSyncResubACMinus1endAfter0.json" |grep -v "grep"|awk \'{print $2}\'` ') - # os.system("nohup %staosdemo -f tools/taosdemoAllTest/Resubjson/subSyncResubACMinus1endAfter0.json & " % binPath) + # os.system("nohup %staosBenchmark -f tools/taosdemoAllTest/Resubjson/subSyncResubACMinus1endAfter0.json & " % binPath) # sleep(2) # query_pid1 = int(subprocess.getstatusoutput('ps aux|grep "subSyncResubACMinus1endAfter0.json" |grep -v "grep"|awk \'{print $2}\'')[1]) # print("get sub2 process'pid") @@ -185,8 +185,8 @@ class TDTestCase: # self.assertCheck("all_subscribe_res2.txt",subTimes2 ,1900) - # os.system("%staosdemo -f tools/taosdemoAllTest/subSupermaxsql100.json" % binPath) - # os.system("%staosdemo -f tools/taosdemoAllTest/subSupermaxsql100.json" % binPath) + # os.system("%staosBenchmark -f tools/taosdemoAllTest/subSupermaxsql100.json" % binPath) + # os.system("%staosBenchmark -f tools/taosdemoAllTest/subSupermaxsql100.json" % binPath) diff --git a/tests/pytest/tools/taosdemoAllTest/taosdemoTestSubWithJsonAsync.py b/tests/pytest/tools/taosdemoAllTest/taosdemoTestSubWithJsonAsync.py index f2aa01e8703d9703d647507736130de2dd582bfb..b236b2b48b93f210f0e73ebb5be240413f82d878 100644 --- a/tests/pytest/tools/taosdemoAllTest/taosdemoTestSubWithJsonAsync.py +++ b/tests/pytest/tools/taosdemoAllTest/taosdemoTestSubWithJsonAsync.py @@ -72,8 +72,8 @@ class TDTestCase: os.system("rm -rf ./all_subscribe_res*") # subscribe: resultfile - os.system("%staosdemo -f tools/taosdemoAllTest/subInsertdata.json" % binPath) - os.system("nohup %staosdemo -f tools/taosdemoAllTest/subAsync.json &" % binPath) + os.system("%staosBenchmark -f tools/taosdemoAllTest/subInsertdata.json" % binPath) + os.system("nohup %staosBenchmark -f tools/taosdemoAllTest/subAsync.json &" % binPath) query_pid = int(subprocess.getstatusoutput('ps aux|grep "taosdemoAllTest/subAsync.json" |grep -v "grep"|awk \'{print $2}\'')[1]) # insert extral data @@ -106,9 +106,9 @@ class TDTestCase: os.system("kill -9 %d" % query_pid) # # query times less than or equal to 100 - os.system("%staosdemo -f tools/taosdemoAllTest/subInsertdataMaxsql100.json" % binPath) - assert os.system("%staosdemo -f tools/taosdemoAllTest/subSyncSpecMaxsql100.json" % binPath) != 0 - assert os.system("%staosdemo -f tools/taosdemoAllTest/subSyncSuperMaxsql100.json" % binPath) != 0 + os.system("%staosBenchmark -f tools/taosdemoAllTest/subInsertdataMaxsql100.json" % binPath) + assert os.system("%staosBenchmark -f tools/taosdemoAllTest/subSyncSpecMaxsql100.json" % binPath) != 0 + assert os.system("%staosBenchmark -f tools/taosdemoAllTest/subSyncSuperMaxsql100.json" % binPath) != 0 # delete useless files os.system("rm -rf ./insert_res.txt") diff --git a/tests/pytest/tools/taosdemoAllTest/taosdemoTestSupportNanoInsert.py b/tests/pytest/tools/taosdemoAllTest/taosdemoTestSupportNanoInsert.py deleted file mode 100644 index d8c68af0f9b43443744d7d799db6f5ee1e1dacaa..0000000000000000000000000000000000000000 --- a/tests/pytest/tools/taosdemoAllTest/taosdemoTestSupportNanoInsert.py +++ /dev/null @@ -1,168 +0,0 @@ -################################################################### -# Copyright (c) 2016 by TAOS Technologies, Inc. -# All rights reserved. -# -# This file is proprietary and confidential to TAOS Technologies. -# No part of this file may be reproduced, stored, transmitted, -# disclosed or used in any form or by any means other than as -# expressly provided by the written permission from Jianhui Tao -# -################################################################### - -# -*- coding: utf-8 -*- - -import sys -import os -from util.log import * -from util.cases import * -from util.sql import * -from util.dnodes import * - - -class TDTestCase: - def init(self, conn, logSql): - tdLog.debug("start to execute %s" % __file__) - tdSql.init(conn.cursor(), logSql) - - def getBuildPath(self): - selfPath = os.path.dirname(os.path.realpath(__file__)) - - if ("community" in selfPath): - projPath = selfPath[:selfPath.find("community")] - else: - projPath = selfPath[:selfPath.find("tests")] - - for root, dirs, files in os.walk(projPath): - if ("taosd" in files): - rootRealPath = os.path.dirname(os.path.realpath(root)) - if ("packaging" not in rootRealPath): - buildPath = root[:len(root) - len("/build/bin")] - break - return buildPath - - def run(self): - buildPath = self.getBuildPath() - if (buildPath == ""): - tdLog.exit("taosd not found!") - else: - tdLog.info("taosd found in %s" % buildPath) - binPath = buildPath + "/build/bin/" - - # insert: create one or mutiple tables per sql and insert multiple rows per sql - # insert data from a special timestamp - # check stable stb0 - - os.system( - "%staosdemo -f tools/taosdemoAllTest/taosdemoTestNanoDatabase.json -y " % - binPath) - tdSql.execute("use nsdb") - tdSql.query("show stables") - tdSql.checkData(0, 4, 100) - tdSql.query("select count (tbname) from stb0") - tdSql.checkData(0, 0, 100) - tdSql.query("select count(*) from tb0_0") - tdSql.checkData(0, 0, 100) - tdSql.query("select count(*) from stb0") - tdSql.checkData(0, 0, 10000) - tdSql.query("describe stb0") - tdSql.checkDataType(9, 1, "TIMESTAMP") - tdSql.query("select last(ts) from stb0") - tdSql.checkData(0, 0, "2021-07-01 00:00:00.990000000") - - # check stable stb1 which is insert with disord - - tdSql.query("select count (tbname) from stb1") - tdSql.checkData(0, 0, 100) - tdSql.query("select count(*) from tb1_0") - tdSql.checkData(0, 0, 100) - tdSql.query("select count(*) from stb1") - tdSql.checkData(0, 0, 10000) - # check c8 is an nano timestamp - tdSql.query("describe stb1") - tdSql.checkDataType(9, 1, "TIMESTAMP") - # check insert timestamp_step is nano_second - tdSql.query("select last(ts) from stb1") - tdSql.checkData(0, 0, "2021-07-01 00:00:00.990000000") - - # insert data from now time - - # check stable stb0 - os.system( - "%staosdemo -f tools/taosdemoAllTest/taosdemoTestNanoDatabaseNow.json -y " % - binPath) - - tdSql.execute("use nsdb2") - tdSql.query("show stables") - tdSql.checkData(0, 4, 100) - tdSql.query("select count (tbname) from stb0") - tdSql.checkData(0, 0, 100) - tdSql.query("select count(*) from tb0_0") - tdSql.checkData(0, 0, 100) - tdSql.query("select count(*) from stb0") - tdSql.checkData(0, 0, 10000) - # check c8 is an nano timestamp - tdSql.query("describe stb0") - tdSql.checkDataType(9, 1, "TIMESTAMP") - - # insert by csv files and timetamp is long int , strings in ts and - # cols - - os.system( - "%staosdemo -f tools/taosdemoAllTest/taosdemoTestNanoDatabasecsv.json -y " % - binPath) - tdSql.execute("use nsdbcsv") - tdSql.query("show stables") - tdSql.checkData(0, 4, 100) - tdSql.query("select count(*) from stb0") - tdSql.checkData(0, 0, 10000) - tdSql.query("describe stb0") - tdSql.checkDataType(3, 1, "TIMESTAMP") - tdSql.query( - "select count(*) from stb0 where ts > \"2021-07-01 00:00:00.490000000\"") - tdSql.checkData(0, 0, 5000) - tdSql.query("select count(*) from stb0 where ts < 1626918583000000000") - tdSql.checkData(0, 0, 10000) - - os.system("rm -rf ./insert_res.txt") - os.system("rm -rf tools/taosdemoAllTest/taosdemoTestSupportNano*.py.sql") - - # taosdemo test insert with command and parameter , detals show - # taosdemo --help - os.system( - "%staosdemo -u root -ptaosdata -P 6030 -a 1 -m pre -n 10 -T 20 -t 60 -o res.txt -y " % - binPath) - tdSql.query("select count(*) from test.meters") - tdSql.checkData(0, 0, 600) - # check taosdemo -s - - sqls_ls = [ - 'drop database if exists nsdbsql;', - 'create database nsdbsql precision "ns" keep 36500 days 6 update 1;', - 'use nsdbsql;', - 'CREATE STABLE meters (ts timestamp, current float, voltage int, phase float) TAGS (location binary(64), groupdId int);', - 'CREATE TABLE d1001 USING meters TAGS ("Beijing.Chaoyang", 2);', - 'INSERT INTO d1001 USING METERS TAGS ("Beijng.Chaoyang", 2) VALUES (now, 10.2, 219, 0.32);', - 'INSERT INTO d1001 USING METERS TAGS ("Beijng.Chaoyang", 2) VALUES (now, 85, 32, 0.76);'] - - with open("./taosdemoTestNanoCreateDB.sql", mode="a") as sql_files: - for sql in sqls_ls: - sql_files.write(sql + "\n") - sql_files.close() - - sleep(10) - - os.system("%staosdemo -s taosdemoTestNanoCreateDB.sql -y " % binPath) - tdSql.query("select count(*) from nsdbsql.meters") - tdSql.checkData(0, 0, 2) - - os.system("rm -rf ./res.txt") - os.system("rm -rf ./*.py.sql") - os.system("rm -rf ./taosdemoTestNanoCreateDB.sql") - - def stop(self): - tdSql.close() - tdLog.success("%s successfully executed" % __file__) - - -tdCases.addWindows(__file__, TDTestCase()) -tdCases.addLinux(__file__, TDTestCase()) diff --git a/tests/pytest/tools/taosdemoAllTest/taosdemoTestSupportNanoQuery.json b/tests/pytest/tools/taosdemoAllTest/taosdemoTestSupportNanoQuery.json deleted file mode 100644 index fff1017588bb10f55a82aa2bd7bc6997df71abfd..0000000000000000000000000000000000000000 --- a/tests/pytest/tools/taosdemoAllTest/taosdemoTestSupportNanoQuery.json +++ /dev/null @@ -1,92 +0,0 @@ -{ - "filetype": "query", - "cfgdir": "/etc/taos", - "host": "127.0.0.1", - "port": 6030, - "user": "root", - "password": "taosdata", - "confirm_parameter_prompt": "no", - "databases": "nsdb", - "query_times": 10, - "query_mode": "taosc", - "specified_table_query": { - "query_interval": 1, - "concurrent": 2, - "sqls": [ - { - "sql": "select count(*) from stb0 where ts>\"2021-07-01 00:01:00.000000000 \" ;", - "result": "./query_res0.txt" - }, - { - "sql": "select count(*) from stb0 where ts>\"2021-07-01 00:01:00.000000000\" and ts <=\"2021-07-01 00:01:10.000000000\" ;", - "result": "./query_res1.txt" - }, - { - "sql": "select count(*) from stb0 where ts>now-20d ;", - "result": "./query_res2.txt" - }, - { - "sql": "select max(c10) from stb0;", - "result": "./query_res3.txt" - }, - { - "sql": "select min(c1) from stb0;", - "result": "./query_res4.txt" - }, - { - "sql": "select avg(c1) from stb0;", - "result": "./query_res5.txt" - }, - { - "sql":"select count(*) from stb0 group by tbname;", - "result":"./query_res6.txt" - } - - ] - }, - "super_table_query": { - "stblname": "stb0", - "query_interval": 0, - "threads": 4, - "sqls": [ - { - "sql": "select count(*) from xxxx where ts>\"2021-07-01 00:01:00.000000000 \" ;", - "result": "./query_res_tb0.txt" - }, - { - "sql":"select count(*) from xxxx where ts>\"2021-07-01 00:01:00.000000000\" and ts <=\"2021-07-01 00:01:10.000000000\" ;", - "result": "./query_res_tb1.txt" - }, - { - "sql":"select first(*) from xxxx ;", - "result": "./query_res_tb2.txt" - }, - { - "sql":"select last(*) from xxxx;", - "result": "./query_res_tb3.txt" - - }, - { - "sql":"select last_row(*) from xxxx ;", - "result": "./query_res_tb4.txt" - - }, - { - "sql":"select max(c10) from xxxx ;", - "result": "./query_res_tb5.txt" - - }, - { - "sql":"select min(c1) from xxxx ;", - "result": "./query_res_tb6.txt" - - }, - { - "sql":"select avg(c10) from xxxx ;", - "result": "./query_res_tb7.txt" - - } - - ] - } - } \ No newline at end of file diff --git a/tests/pytest/tools/taosdemoAllTest/taosdemoTestSupportNanoQuery.py b/tests/pytest/tools/taosdemoAllTest/taosdemoTestSupportNanoQuery.py deleted file mode 100644 index 5a37cf9c7cf3153a7bcabb0bc9258063e5f05f09..0000000000000000000000000000000000000000 --- a/tests/pytest/tools/taosdemoAllTest/taosdemoTestSupportNanoQuery.py +++ /dev/null @@ -1,157 +0,0 @@ -################################################################### -# Copyright (c) 2016 by TAOS Technologies, Inc. -# All rights reserved. -# -# This file is proprietary and confidential to TAOS Technologies. -# No part of this file may be reproduced, stored, transmitted, -# disclosed or used in any form or by any means other than as -# expressly provided by the written permission from Jianhui Tao -# -################################################################### - -# -*- coding: utf-8 -*- - -import sys -import os -from util.log import * -from util.cases import * -from util.sql import * -from util.dnodes import * - - -class TDTestCase: - def init(self, conn, logSql): - tdLog.debug("start to execute %s" % __file__) - tdSql.init(conn.cursor(), logSql) - - def getBuildPath(self): - selfPath = os.path.dirname(os.path.realpath(__file__)) - - if ("community" in selfPath): - projPath = selfPath[:selfPath.find("community")] - else: - projPath = selfPath[:selfPath.find("tests")] - - for root, dirs, files in os.walk(projPath): - if ("taosd" in files): - rootRealPath = os.path.dirname(os.path.realpath(root)) - if ("packaging" not in rootRealPath): - buildPath = root[:len(root)-len("/build/bin")] - break - return buildPath - - def run(self): - buildPath = self.getBuildPath() - if (buildPath == ""): - tdLog.exit("taosd not found!") - else: - tdLog.info("taosd found in %s" % buildPath) - binPath = buildPath+ "/build/bin/" - - # query: query test for nanoSecond with where and max min groupby order - os.system("%staosdemo -f tools/taosdemoAllTest/taosdemoTestNanoDatabase.json -y " % binPath) - - tdSql.execute("use nsdb") - - # use where to filter - - tdSql.query("select count(*) from stb0 where ts>\"2021-07-01 00:00:00.590000000 \" ") - tdSql.checkData(0, 0, 4000) - tdSql.query("select count(*) from stb0 where ts>\"2021-07-01 00:00:00.000000000\" and ts <=\"2021-07-01 00:00:00.590000000\" ") - tdSql.checkData(0, 0, 5900) - - tdSql.query("select count(*) from tb0_0 where ts>\"2021-07-01 00:00:00.590000000 \" ;") - tdSql.checkData(0, 0, 40) - tdSql.query("select count(*) from tb0_0 where ts>\"2021-07-01 00:00:00.000000000\" and ts <=\"2021-07-01 00:00:00.590000000\" ") - tdSql.checkData(0, 0, 59) - - - # select max min avg from special col - tdSql.query("select max(c10) from stb0;") - print("select max(c10) from stb0 : " , tdSql.getData(0, 0)) - - tdSql.query("select max(c10) from tb0_0;") - print("select max(c10) from tb0_0 : " , tdSql.getData(0, 0)) - - - tdSql.query("select min(c1) from stb0;") - print( "select min(c1) from stb0 : " , tdSql.getData(0, 0)) - - tdSql.query("select min(c1) from tb0_0;") - print( "select min(c1) from tb0_0 : " , tdSql.getData(0, 0)) - - tdSql.query("select avg(c1) from stb0;") - print( "select avg(c1) from stb0 : " , tdSql.getData(0, 0)) - - tdSql.query("select avg(c1) from tb0_0;") - print( "select avg(c1) from tb0_0 : " , tdSql.getData(0, 0)) - - tdSql.query("select count(*) from stb0 group by tbname;") - tdSql.checkData(0, 0, 100) - tdSql.checkData(10, 0, 100) - - # query : query above sqls by taosdemo and continuously - - os.system("%staosdemo -f tools/taosdemoAllTest/taosdemoTestSupportNanoQuery.json -y " % binPath) - - - os.system("%staosdemo -f tools/taosdemoAllTest/taosdemoTestNanoDatabasecsv.json -y " % binPath) - tdSql.execute("use nsdbcsv") - tdSql.query("show stables") - tdSql.checkData(0, 4, 100) - tdSql.query("select count(*) from stb0") - tdSql.checkData(0, 0, 10000) - tdSql.query("describe stb0") - tdSql.checkDataType(3, 1, "TIMESTAMP") - tdSql.query("select count(*) from stb0 where ts >\"2021-07-01 00:00:00.490000000\"") - tdSql.checkData(0, 0, 5000) - tdSql.query("select count(*) from stb0 where ts 162687012800000000') - tdSql.execute('select count(*) from stb0 where c2 < 162687012800000000') - tdSql.execute('select count(*) from stb0 where c2 = 162687012800000000') - tdSql.execute('select count(*) from stb0 where c2 != 162687012800000000') - tdSql.execute('select count(*) from stb0 where c2 <> 162687012800000000') - tdSql.execute('select count(*) from stb0 where c2 > "2021-07-21 20:22:08.248246976"') - tdSql.execute('select count(*) from stb0 where c2 < "2021-07-21 20:22:08.248246976"') - tdSql.execute('select count(*) from stb0 where c2 = "2021-07-21 20:22:08.248246976"') - tdSql.execute('select count(*) from stb0 where c2 != "2021-07-21 20:22:08.248246976"') - tdSql.execute('select count(*) from stb0 where c2 <> "2021-07-21 20:22:08.248246976"') - tdSql.execute('select count(*) from stb0 where ts between "2021-07-01 00:00:00.000000000" and "2021-07-01 00:00:00.990000000"') - tdSql.execute('select count(*) from stb0 where ts between 1625068800000000000 and 1625068801000000000') - tdSql.query('select avg(c0) from stb0 interval(5000000000b)') - tdSql.checkRows(1) - - tdSql.query('select avg(c0) from stb0 interval(100000000b)') - tdSql.checkRows(10) - - tdSql.error('select avg(c0) from stb0 interval(1b)') - tdSql.error('select avg(c0) from stb0 interval(999b)') - - tdSql.query('select avg(c0) from stb0 interval(1000b)') - tdSql.checkRows(100) - - tdSql.query('select avg(c0) from stb0 interval(1u)') - tdSql.checkRows(100) - - tdSql.query('select avg(c0) from stb0 interval(100000000b) sliding (100000000b)') - tdSql.checkRows(10) - - # query : query above sqls by taosdemo and continuously - os.system("%staosdemo -f tools/taosdemoAllTest/taosdemoTestSupportNanoQuerycsv.json -y " % binPath) - - os.system("rm -rf ./query_res*.txt*") - os.system("rm -rf tools/taosdemoAllTest/*.py.sql") - - - - - def stop(self): - tdSql.close() - tdLog.success("%s successfully executed" % __file__) - - -tdCases.addWindows(__file__, TDTestCase()) -tdCases.addLinux(__file__, TDTestCase()) diff --git a/tests/pytest/tools/taosdemoAllTest/taosdemoTestSupportNanoQuerycsv.json b/tests/pytest/tools/taosdemoAllTest/taosdemoTestSupportNanoQuerycsv.json deleted file mode 100644 index a3b3c75efa6680aa0d1da0ca7986d863408ee515..0000000000000000000000000000000000000000 --- a/tests/pytest/tools/taosdemoAllTest/taosdemoTestSupportNanoQuerycsv.json +++ /dev/null @@ -1,110 +0,0 @@ -{ - "filetype": "query", - "cfgdir": "/etc/taos", - "host": "127.0.0.1", - "port": 6030, - "user": "root", - "password": "taosdata", - "confirm_parameter_prompt": "no", - "databases": "nsdbcsv", - "query_times": 10, - "query_mode": "taosc", - "specified_table_query": { - "query_interval": 1, - "concurrent": 2, - "sqls": [ - { - "sql": "select count(*) from stb0 where ts> \"2021-07-01 00:00:00.490000000\" ;", - "result": "./query_res0.txt" - }, - { - "sql": "select count(*) from stb0 where ts < now -22d-1h-3s ;", - "result": "./query_res1.txt" - }, - { - "sql": "select count(*) from stb0 where ts < 1626918583000000000 ;", - "result": "./query_res2.txt" - }, - { - "sql": "select count(*) from stb0 where c2 <> 162687012800000000';", - "result": "./query_res3.txt" - }, - { - "sql": "select count(*) from stb0 where c2 != \"2021-07-21 20:22:08.248246976\";", - "result": "./query_res4.txt" - }, - { - "sql": "select count(*) from stb0 where ts between \"2021-07-01 00:00:00.000000000\" and \"2021-07-01 00:00:00.990000000\";", - "result": "./query_res5.txt" - }, - { - "sql":"select count(*) from stb0 group by tbname;", - "result":"./query_res6.txt" - }, - { - "sql":"select count(*) from stb0 where ts between 1625068800000000000 and 1625068801000000000;", - "result":"./query_res7.txt" - }, - { - "sql":"select avg(c0) from stb0 interval(5000000000b);", - "result":"./query_res8.txt" - }, - { - "sql":"select avg(c0) from stb0 interval(100000000b) sliding (100000000b);", - "result":"./query_res9.txt" - } - - ] - }, - "super_table_query": { - "stblname": "stb0", - "query_interval": 0, - "threads": 4, - "sqls": [ - { - "sql": "select count(*) from xxxx where ts > \"2021-07-01 00:00:00.490000000\" ;", - "result": "./query_res_tb0.txt" - }, - { - "sql":"select count(*) from xxxx where ts between \"2021-07-01 00:00:00.000000000\" and \"2021-07-01 00:00:00.990000000\" ;", - "result": "./query_res_tb1.txt" - }, - { - "sql":"select first(*) from xxxx ;", - "result": "./query_res_tb2.txt" - }, - { - "sql":"select last(*) from xxxx;", - "result": "./query_res_tb3.txt" - - }, - { - "sql":"select last_row(*) from xxxx ;", - "result": "./query_res_tb4.txt" - - }, - { - "sql":"select max(c0) from xxxx ;", - "result": "./query_res_tb5.txt" - - }, - { - "sql":"select min(c0) from xxxx ;", - "result": "./query_res_tb6.txt" - - }, - { - "sql":"select avg(c0) from xxxx ;", - "result": "./query_res_tb7.txt" - - }, - { - "sql":"select avg(c0) from xxxx interval(100000000b) sliding (100000000b) ;", - "result": "./query_res_tb8.txt" - - } - - - ] - } - } \ No newline at end of file diff --git a/tests/pytest/tools/taosdemoAllTest/taosdemoTestSupportNanoSubscribe.json b/tests/pytest/tools/taosdemoAllTest/taosdemoTestSupportNanoSubscribe.json deleted file mode 100644 index 1cc834164e7c966a9ce565f1ce481d823b1ed2d1..0000000000000000000000000000000000000000 --- a/tests/pytest/tools/taosdemoAllTest/taosdemoTestSupportNanoSubscribe.json +++ /dev/null @@ -1,32 +0,0 @@ -{ - "filetype":"subscribe", - "cfgdir": "/etc/taos", - "host": "127.0.0.1", - "port": 6030, - "user": "root", - "password": "taosdata", - "databases": "subnsdb", - "confirm_parameter_prompt": "no", - "specified_table_query": - { - "concurrent":2, - "mode":"sync", - "interval":10000, - "restart":"yes", - "keepProgress":"yes", - "sqls": [ - { - "sql": "select * from stb0 where ts>= \"2021-07-01 00:00:00.000000000\" ;", - "result": "./subscribe_res0.txt" - }, - { - "sql": "select * from stb0 where ts < now -2d-1h-3s ;", - "result": "./subscribe_res1.txt" - }, - { - "sql": "select * from stb0 where ts < 1626918583000000000 ;", - "result": "./subscribe_res2.txt" - }] - - } -} diff --git a/tests/pytest/tools/taosdemoAllTest/taosdemoTestSupportNanosubscribe.py b/tests/pytest/tools/taosdemoAllTest/taosdemoTestSupportNanosubscribe.py deleted file mode 100644 index da02f45fa1141a028cfc305bae9babb1856ccb40..0000000000000000000000000000000000000000 --- a/tests/pytest/tools/taosdemoAllTest/taosdemoTestSupportNanosubscribe.py +++ /dev/null @@ -1,124 +0,0 @@ -################################################################### -# Copyright (c) 2016 by TAOS Technologies, Inc. -# All rights reserved. -# -# This file is proprietary and confidential to TAOS Technologies. -# No part of this file may be reproduced, stored, transmitted, -# disclosed or used in any form or by any means other than as -# expressly provided by the written permission from Jianhui Tao -# -################################################################### - -# -*- coding: utf-8 -*- - -import sys -import os -from util.log import * -from util.cases import * -from util.sql import * -from util.dnodes import * -import time -from datetime import datetime -import subprocess - - -class TDTestCase: - def init(self, conn, logSql): - tdLog.debug("start to execute %s" % __file__) - tdSql.init(conn.cursor(), logSql) - - def getBuildPath(self): - selfPath = os.path.dirname(os.path.realpath(__file__)) - - if ("community" in selfPath): - projPath = selfPath[:selfPath.find("community")] - else: - projPath = selfPath[:selfPath.find("tests")] - - for root, dirs, files in os.walk(projPath): - if ("taosd" in files): - rootRealPath = os.path.dirname(os.path.realpath(root)) - if ("packaging" not in rootRealPath): - buildPath = root[:len(root)-len("/build/bin")] - break - return buildPath - - # get the number of subscriptions - def subTimes(self,filename): - self.filename = filename - command = 'cat %s |wc -l'% filename - times = int(subprocess.getstatusoutput(command)[1]) - return times - - # assert results - def assertCheck(self,filename,subResult,expectResult): - self.filename = filename - self.subResult = subResult - self.expectResult = expectResult - args0 = (filename, subResult, expectResult) - assert subResult == expectResult , "Queryfile:%s ,result is %s != expect: %s" % args0 - - def run(self): - buildPath = self.getBuildPath() - if (buildPath == ""): - tdLog.exit("taosd not found!") - else: - tdLog.info("taosd found in %s" % buildPath) - binPath = buildPath+ "/build/bin/" - - # clear env - os.system("ps -ef |grep 'taosdemoAllTest/taosdemoTestSupportNanoSubscribe.json' |grep -v 'grep' |awk '{print $2}'|xargs kill -9") - os.system("rm -rf ./subscribe_res*") - os.system("rm -rf ./all_subscribe_res*") - - - # insert data - os.system("%staosdemo -f tools/taosdemoAllTest/taosdemoTestNanoDatabaseInsertForSub.json" % binPath) - os.system("nohup %staosdemo -f tools/taosdemoAllTest/taosdemoTestSupportNanoSubscribe.json &" % binPath) - query_pid = int(subprocess.getstatusoutput('ps aux|grep "taosdemoAllTest/taosdemoTestSupportNanoSubscribe.json" |grep -v "grep"|awk \'{print $2}\'')[1]) - - - # merge result files - sleep(5) - os.system("cat subscribe_res0.txt* > all_subscribe_res0.txt") - os.system("cat subscribe_res1.txt* > all_subscribe_res1.txt") - os.system("cat subscribe_res2.txt* > all_subscribe_res2.txt") - - - # correct subscribeTimes testcase - subTimes0 = self.subTimes("all_subscribe_res0.txt") - self.assertCheck("all_subscribe_res0.txt",subTimes0 ,200) - - subTimes1 = self.subTimes("all_subscribe_res1.txt") - self.assertCheck("all_subscribe_res1.txt",subTimes1 ,200) - - subTimes2 = self.subTimes("all_subscribe_res2.txt") - self.assertCheck("all_subscribe_res2.txt",subTimes2 ,200) - - - # insert extral data - tdSql.execute("use subnsdb") - tdSql.execute("insert into tb0_0 values(now,100.1000,'subtest1',now-1s)") - sleep(15) - - os.system("cat subscribe_res0.txt* > all_subscribe_res0.txt") - subTimes0 = self.subTimes("all_subscribe_res0.txt") - self.assertCheck("all_subscribe_res0.txt",subTimes0 ,202) - - - - # correct data testcase - os.system("kill -9 %d" % query_pid) - sleep(3) - os.system("rm -rf ./subscribe_res*") - os.system("rm -rf ./all_subscribe*") - os.system("rm -rf ./*.py.sql") - - - - def stop(self): - tdSql.close() - tdLog.success("%s successfully executed" % __file__) - -tdCases.addWindows(__file__, TDTestCase()) -tdCases.addLinux(__file__, TDTestCase()) diff --git a/tests/pytest/tools/taosdemoTest.py b/tests/pytest/tools/taosdemoTest.py index 3cdcdcef5afcb14c04204d2489571bdfed937080..54e0906672637c1187cb8b078f1e8496e461e150 100644 --- a/tests/pytest/tools/taosdemoTest.py +++ b/tests/pytest/tools/taosdemoTest.py @@ -51,7 +51,7 @@ class TDTestCase: else: tdLog.info("taosdemo found in %s" % buildPath) binPath = buildPath + "/build/bin/" - os.system("%staosdemo -y -t %d -n %d -b INT,INT,INT,INT" % + os.system("%staosBenchmark -y -t %d -n %d -b INT,INT,INT,INT" % (binPath, self.numberOfTables, self.numberOfRecords)) tdSql.execute("use test") diff --git a/tests/pytest/tools/taosdemoTestInterlace.py b/tests/pytest/tools/taosdemoTestInterlace.py index 30c04729b7966660bdb4851ad1b971130d08f726..5b9f6f319f6a451284b01e75a3714d44da1ce7c3 100644 --- a/tests/pytest/tools/taosdemoTestInterlace.py +++ b/tests/pytest/tools/taosdemoTestInterlace.py @@ -49,7 +49,7 @@ class TDTestCase: else: tdLog.info("taosd found in %s" % buildPath) binPath = buildPath + "/build/bin/" - taosdemoCmd = "%staosdemo -f tools/insert-interlace.json -PP 2>&1 | grep sleep | wc -l" % binPath + taosdemoCmd = "%staosBenchmark -f tools/insert-interlace.json -PP 2>&1 | grep sleep | wc -l" % binPath sleepTimes = subprocess.check_output( taosdemoCmd, shell=True).decode("utf-8") print("sleep times: %d" % int(sleepTimes)) diff --git a/tests/pytest/tools/taosdemoTestLimitOffset.py b/tests/pytest/tools/taosdemoTestLimitOffset.py index dd8a1bee701da0ffd2f764cdbedcf12f9dbedb3c..e69098b7f562f996b2bad58b10df63fdaf8a8398 100644 --- a/tests/pytest/tools/taosdemoTestLimitOffset.py +++ b/tests/pytest/tools/taosdemoTestLimitOffset.py @@ -51,8 +51,8 @@ class TDTestCase: else: tdLog.info("taosd found in %s" % buildPath) binPath = buildPath+ "/build/bin/" - os.system("%staosdemo -f tools/insert-tblimit-tboffset-createdb.json" % binPath) - os.system("%staosdemo -f tools/insert-tblimit-tboffset-insertrec.json" % binPath) + os.system("%staosBenchmark -f tools/insert-tblimit-tboffset-createdb.json" % binPath) + os.system("%staosBenchmark -f tools/insert-tblimit-tboffset-insertrec.json" % binPath) tdSql.execute("use db") tdSql.query("select count(tbname) from db.stb") @@ -60,8 +60,8 @@ class TDTestCase: tdSql.query("select count(*) from db.stb") tdSql.checkData(0, 0, 33000) - os.system("%staosdemo -f tools/insert-tblimit-tboffset-createdb.json" % binPath) - os.system("%staosdemo -f tools/insert-tblimit-tboffset0.json" % binPath) + os.system("%staosBenchmark -f tools/insert-tblimit-tboffset-createdb.json" % binPath) + os.system("%staosBenchmark -f tools/insert-tblimit-tboffset0.json" % binPath) tdSql.execute("reset query cache") tdSql.execute("use db") @@ -70,8 +70,8 @@ class TDTestCase: tdSql.query("select count(*) from db.stb") tdSql.checkData(0, 0, 20000) - os.system("%staosdemo -f tools/insert-tblimit-tboffset-createdb.json" % binPath) - os.system("%staosdemo -f tools/insert-tblimit1-tboffset.json" % binPath) + os.system("%staosBenchmark -f tools/insert-tblimit-tboffset-createdb.json" % binPath) + os.system("%staosBenchmark -f tools/insert-tblimit1-tboffset.json" % binPath) tdSql.execute("reset query cache") tdSql.execute("use db") diff --git a/tests/pytest/tools/taosdemoTestQuery.py b/tests/pytest/tools/taosdemoTestQuery.py index bb2bb85052a9b21dc9181887622ec2019707256b..c77688aefaf93898ae33044408dd4027d71b07e9 100644 --- a/tests/pytest/tools/taosdemoTestQuery.py +++ b/tests/pytest/tools/taosdemoTestQuery.py @@ -53,12 +53,12 @@ class TDTestCase: else: tdLog.info("taosd found in %s" % buildPath) binPath = buildPath + "/build/bin/" - os.system("%staosdemo -y -t %d -n %d" % + os.system("%staosBenchmark -y -t %d -n %d" % (binPath, self.numberOfTables, self.numberOfRecords)) print("Sleep 2 seconds..") time.sleep(2) - os.system('%staosdemo -f tools/query.json ' % binPath) -# taosdemoCmd = '%staosdemo -f tools/query.json ' % binPath + os.system('%staosBenchmark -f tools/query.json ' % binPath) +# taosdemoCmd = '%staosBenchmark -f tools/query.json ' % binPath # threads = subprocess.check_output( # taosdemoCmd, shell=True).decode("utf-8") # print("threads: %d" % int(threads)) diff --git a/tests/pytest/tools/taosdemoTestSampleData.py b/tests/pytest/tools/taosdemoTestSampleData.py index a8710a9df36358199e567de2efeb90e88b675312..09a2e6c43b68d8271cb0472b288279b54789fded 100644 --- a/tests/pytest/tools/taosdemoTestSampleData.py +++ b/tests/pytest/tools/taosdemoTestSampleData.py @@ -51,7 +51,7 @@ class TDTestCase: else: tdLog.info("taosd found in %s" % buildPath) binPath = buildPath+ "/build/bin/" - os.system("%staosdemo -f tools/taosdemo-sampledata.json" % binPath) + os.system("%staosBenchmark -f tools/taosdemo-sampledata.json" % binPath) tdSql.execute("use db") tdSql.query("select count(tbname) from db.stb") diff --git a/tests/pytest/tools/taosdemoTestTblAlt.py b/tests/pytest/tools/taosdemoTestTblAlt.py index 89c1b92e140cb1e19b549d3248693153e116c52e..7587ab9eb3e89275451864d28ccf985bcaac949a 100644 --- a/tests/pytest/tools/taosdemoTestTblAlt.py +++ b/tests/pytest/tools/taosdemoTestTblAlt.py @@ -54,9 +54,9 @@ class TDTestCase: binPath = buildPath + "/build/bin/" if(threadID == 0): - print("%staosdemo -y -t %d -n %d -b INT,INT,INT,INT" % + print("%staosBenchmark -y -t %d -n %d -b INT,INT,INT,INT" % (binPath, self.numberOfTables, self.numberOfRecords)) - os.system("%staosdemo -y -t %d -n %d -b INT,INT,INT,INT" % + os.system("%staosBenchmark -y -t %d -n %d -b INT,INT,INT,INT" % (binPath, self.numberOfTables, self.numberOfRecords)) if(threadID == 1): time.sleep(2) diff --git a/tests/pytest/tools/taosdemoTestWithJson.py b/tests/pytest/tools/taosdemoTestWithJson.py index b2ecd5497620bf5a0f90dd2e8529890423fd82a1..0868d07fd99f7731424a3f11883ae52d12f1e878 100644 --- a/tests/pytest/tools/taosdemoTestWithJson.py +++ b/tests/pytest/tools/taosdemoTestWithJson.py @@ -48,7 +48,7 @@ class TDTestCase: else: tdLog.info("taosd found in %s" % buildPath) binPath = buildPath + "/build/bin/" - os.system("%staosdemo -f tools/insert.json -y" % binPath) + os.system("%staosBenchmark -f tools/insert.json -y" % binPath) tdSql.execute("use db01") tdSql.query("select count(*) from stb01") diff --git a/tests/pytest/tools/taosdemoTestWithoutMetric.py b/tests/pytest/tools/taosdemoTestWithoutMetric.py index 01e19355d9dfde5c536ac1e28e1f190f33ab966e..a92a4519e2d716b85df0ec29c9cf49abb0812b47 100644 --- a/tests/pytest/tools/taosdemoTestWithoutMetric.py +++ b/tests/pytest/tools/taosdemoTestWithoutMetric.py @@ -50,7 +50,7 @@ class TDTestCase: else: tdLog.info("taosd found in %s" % buildPath) binPath = buildPath + "/build/bin/" - os.system("%staosdemo -N -y -t %d -n %d" % + os.system("%staosBenchmark -N -y -t %d -n %d" % (binPath, self.numberOfTables, self.numberOfRecords)) tdSql.query("show databases") diff --git a/tests/pytest/tools/taosdemoTestdatatype.py b/tests/pytest/tools/taosdemoTestdatatype.py index e32d895571da7d2a101dc32201ebba4754ec4740..ba99b0c532af3497de2daf4d0757b9105405dc1d 100644 --- a/tests/pytest/tools/taosdemoTestdatatype.py +++ b/tests/pytest/tools/taosdemoTestdatatype.py @@ -50,7 +50,7 @@ class TDTestCase: tdLog.info("taosdemo found in %s" % buildPath) binPath = buildPath + "/build/bin/" - os.system("%staosdemo -d test002 -y -t %d -n %d -b INT,nchar\\(8\\),binary\\(16\\),binary,nchar -w 8" % + os.system("%staosBenchmark -d test002 -y -t %d -n %d -b INT,nchar\\(8\\),binary\\(16\\),binary,nchar -w 8" % (binPath, self.numberOfTables, self.numberOfRecords)) tdSql.execute('use test002') @@ -68,7 +68,7 @@ class TDTestCase: tdSql.error('insert into d1 values(now,100,"abcd","abcd"') tdSql.error('insert into d1 values(now,100,100,100)') - os.system("%staosdemo -d test002 -y -t %d -n %d --data-type INT,nchar\\(8\\),binary\\(16\\),binary,nchar -w 8" % + os.system("%staosBenchmark -d test002 -y -t %d -n %d --data-type INT,nchar\\(8\\),binary\\(16\\),binary,nchar -w 8" % (binPath, self.numberOfTables, self.numberOfRecords)) tdSql.execute('use test002') @@ -76,7 +76,7 @@ class TDTestCase: tdSql.checkData(0, 0, self.numberOfTables * self.numberOfRecords) - os.system("%staosdemo -d test002 -y -t %d -n %d -bINT,nchar\\(8\\),binary\\(16\\),binary,nchar -w 8" % + os.system("%staosBenchmark -d test002 -y -t %d -n %d -bINT,nchar\\(8\\),binary\\(16\\),binary,nchar -w 8" % (binPath, self.numberOfTables, self.numberOfRecords)) tdSql.execute('use test002') diff --git a/tests/pytest/tsdb/tsdbComp.py b/tests/pytest/tsdb/tsdbComp.py index 3563655efe4e69fab4c51a40818da205efb29837..b01d9680c0f0147526676a8d3b124e187625e52a 100644 --- a/tests/pytest/tsdb/tsdbComp.py +++ b/tests/pytest/tsdb/tsdbComp.py @@ -59,11 +59,11 @@ class TDTestCase: #new db and insert data tdSql.execute("drop database if exists db2") - os.system("%staosdemo -f tsdb/insertDataDb1.json -y " % binPath) + os.system("%staosBenchmark -f tsdb/insertDataDb1.json -y " % binPath) tdSql.execute("drop database if exists db1") - os.system("%staosdemo -f tsdb/insertDataDb2.json -y " % binPath) + os.system("%staosBenchmark -f tsdb/insertDataDb2.json -y " % binPath) tdSql.execute("drop table if exists db2.stb0") - os.system("%staosdemo -f tsdb/insertDataDb2Newstab.json -y " % binPath) + os.system("%staosBenchmark -f tsdb/insertDataDb2Newstab.json -y " % binPath) tdSql.execute("use db2") tdSql.execute("drop table if exists stb1_0") diff --git a/tests/pytest/tsdb/tsdbCompCluster.py b/tests/pytest/tsdb/tsdbCompCluster.py index 3df4c9a9d47744bcf729e3d6b01c3b515626058b..c1c1181453c4ea0c34041f47e4b0f613d51d8f23 100644 --- a/tests/pytest/tsdb/tsdbCompCluster.py +++ b/tests/pytest/tsdb/tsdbCompCluster.py @@ -66,11 +66,11 @@ class TwoClients: # new db ,new super tables , child tables, and insert data tdSql.execute("drop database if exists db2") - os.system("%staosdemo -f tsdb/insertDataDb1.json -y " % binPath) + os.system("%staosBenchmark -f tsdb/insertDataDb1.json -y " % binPath) tdSql.execute("drop database if exists db1") - os.system("%staosdemo -f tsdb/insertDataDb2.json -y " % binPath) + os.system("%staosBenchmark -f tsdb/insertDataDb2.json -y " % binPath) tdSql.execute("drop table if exists db2.stb0") - os.system("%staosdemo -f tsdb/insertDataDb2Newstab.json -y " % binPath) + os.system("%staosBenchmark -f tsdb/insertDataDb2Newstab.json -y " % binPath) # new general tables and modify general tables; tdSql.execute("use db2") diff --git a/tests/pytest/tsdb/tsdbCompClusterReplica2.py b/tests/pytest/tsdb/tsdbCompClusterReplica2.py index cfda271497cde59e8dbe60150ddf935ba63fd9be..6c2b3993294c16859f548fa83b78f4af72f6d851 100644 --- a/tests/pytest/tsdb/tsdbCompClusterReplica2.py +++ b/tests/pytest/tsdb/tsdbCompClusterReplica2.py @@ -65,11 +65,11 @@ class TwoClients: # new db ,new super tables , child tables, and insert data tdSql.execute("drop database if exists db2") - os.system("%staosdemo -f tsdb/insertDataDb1Replica2.json -y " % binPath) + os.system("%staosBenchmark -f tsdb/insertDataDb1Replica2.json -y " % binPath) tdSql.execute("drop database if exists db1") - os.system("%staosdemo -f tsdb/insertDataDb2Replica2.json -y " % binPath) + os.system("%staosBenchmark -f tsdb/insertDataDb2Replica2.json -y " % binPath) tdSql.execute("drop table if exists db2.stb0") - os.system("%staosdemo -f tsdb/insertDataDb2NewstabReplica2.json -y " % binPath) + os.system("%staosBenchmark -f tsdb/insertDataDb2NewstabReplica2.json -y " % binPath) # new general tables and modify general tables; tdSql.execute("use db2") diff --git a/tests/pytest/util/common.py b/tests/pytest/util/common.py index adf9026e7808dd1fd6715db26f70db56ce339cd5..adfec12cb2a0aafe19b5d125164b583a7dbd288f 100644 --- a/tests/pytest/util/common.py +++ b/tests/pytest/util/common.py @@ -15,22 +15,76 @@ import random import string from util.sql import tdSql from util.dnodes import tdDnodes +import requests +import time class TDCom: def init(self, conn, logSql): tdSql.init(conn.cursor(), logSql) - def cleanTb(self): + def preDefine(self): + header = {'Authorization': 'Basic cm9vdDp0YW9zZGF0YQ=='} + sql_url = "http://127.0.0.1:6041/rest/sql" + sqlt_url = "http://127.0.0.1:6041/rest/sqlt" + sqlutc_url = "http://127.0.0.1:6041/rest/sqlutc" + influx_url = "http://127.0.0.1:6041/influxdb/v1/write" + telnet_url = "http://127.0.0.1:6041/opentsdb/v1/put/telnet" + return header, sql_url, sqlt_url, sqlutc_url, influx_url, telnet_url + + def restApiPost(self, sql): + requests.post(self.preDefine()[1], sql.encode("utf-8"), headers = self.preDefine()[0]) + + def createDb(self, dbname="test", db_update_tag=0, api_type="taosc"): + if api_type == "taosc": + if db_update_tag == 0: + tdSql.execute(f"drop database if exists {dbname}") + tdSql.execute(f"create database if not exists {dbname} precision 'us'") + else: + tdSql.execute(f"drop database if exists {dbname}") + tdSql.execute(f"create database if not exists {dbname} precision 'us' update 1") + elif api_type == "restful": + if db_update_tag == 0: + self.restApiPost(f"drop database if exists {dbname}") + self.restApiPost(f"create database if not exists {dbname} precision 'us'") + else: + self.restApiPost(f"drop database if exists {dbname}") + self.restApiPost(f"create database if not exists {dbname} precision 'us' update 1") + tdSql.execute(f'use {dbname}') + + def genUrl(self, url_type, dbname, precision): + if url_type == "influxdb": + if precision is None: + url = self.preDefine()[4] + "?" + "db=" + dbname + else: + url = self.preDefine()[4] + "?" + "db=" + dbname + "&precision=" + precision + elif url_type == "telnet": + url = self.preDefine()[5] + "/" + dbname + else: + url = self.preDefine()[1] + return url + + def schemalessApiPost(self, sql, url_type="influxdb", dbname="test", precision=None): + if url_type == "influxdb": + url = self.genUrl(url_type, dbname, precision) + elif url_type == "telnet": + url = self.genUrl(url_type, dbname, precision) + res = requests.post(url, sql.encode("utf-8"), headers = self.preDefine()[0]) + return res + + def cleanTb(self, type="taosc"): + ''' + type is taosc or restful + ''' query_sql = "show stables" res_row_list = tdSql.query(query_sql, True) stb_list = map(lambda x: x[0], res_row_list) for stb in stb_list: - tdSql.execute(f'drop table if exists {stb}') + if type == "taosc": + tdSql.execute(f'drop table if exists {stb}') + elif type == "restful": + self.restApiPost(f"drop table if exists {stb}") - query_sql = "show tables" - res_row_list = tdSql.query(query_sql, True) - tb_list = map(lambda x: x[0], res_row_list) - for tb in tb_list: - tdSql.execute(f'drop table if exists {tb}') + def dateToTs(self, datetime_input): + return int(time.mktime(time.strptime(datetime_input, "%Y-%m-%d %H:%M:%S.%f"))) def getLongName(self, len, mode = "mixed"): """ @@ -83,6 +137,14 @@ class TDCom: letters += i return nums, letters + def smlPass(self, func): + def wrapper(*args): + if tdSql.getVariable("smlChildTableName")[0].upper() == "ID": + return func(*args) + else: + pass + return wrapper + def close(self): self.cursor.close() diff --git a/tests/pytest/util/sql.py b/tests/pytest/util/sql.py index 6a70a84221c5c566cd8a0aa0ad2ea806dbbb9bc6..a7cc0ccc7b8768407f87981a32ab479a74ebbf84 100644 --- a/tests/pytest/util/sql.py +++ b/tests/pytest/util/sql.py @@ -332,6 +332,14 @@ class TDSql: args = (caller.filename, caller.lineno, self.sql, elm, expect_elm) tdLog.exit("%s(%d) failed: sql:%s, elm:%s == expect_elm:%s" % args) + def checkIn(self, sub, res): + if sub in res: + tdLog.info("sql:%s, sub:%s in result:%s" % (self.sql, sub, res)) + else: + caller = inspect.getframeinfo(inspect.stack()[1][0]) + args = (caller.filename, caller.lineno, self.sql, sub, res) + tdLog.exit("%s(%d) failed: sql:%s, sub:%s not in result:%s" % args) + def taosdStatus(self, state): tdLog.sleep(5) pstate = 0 diff --git a/tests/pytest/wal/sdbComp.py b/tests/pytest/wal/sdbComp.py index 428fbc9a145c0c3bae4507e33242ff3670c85024..90993014349e28f4d0e6a07646729e8ab04b319c 100644 --- a/tests/pytest/wal/sdbComp.py +++ b/tests/pytest/wal/sdbComp.py @@ -61,11 +61,11 @@ class TDTestCase: os.system("rm -rf %s/sim/dnode1/data/mnode_tmp/" % testPath) os.system("rm -rf %s/sim/dnode1/data/mnode_bak/" % testPath) tdSql.execute("drop database if exists db2") - os.system("%staosdemo -f wal/insertDataDb1.json -y " % binPath) + os.system("%staosBenchmark -f wal/insertDataDb1.json -y " % binPath) tdSql.execute("drop database if exists db1") - os.system("%staosdemo -f wal/insertDataDb2.json -y " % binPath) + os.system("%staosBenchmark -f wal/insertDataDb2.json -y " % binPath) tdSql.execute("drop table if exists db2.stb0") - os.system("%staosdemo -f wal/insertDataDb2Newstab.json -y " % binPath) + os.system("%staosBenchmark -f wal/insertDataDb2Newstab.json -y " % binPath) query_pid1 = int(subprocess.getstatusoutput('ps aux|grep taosd |grep -v "grep"|awk \'{print $2}\'')[1]) print(query_pid1) tdSql.execute("use db2") diff --git a/tests/pytest/wal/sdbCompCluster.py b/tests/pytest/wal/sdbCompCluster.py index 4fa84817ec01c9e5adfdb4a76bc29a4a6c49abfc..0be0f441d032a6a7ec5083472d02c7976a84c75f 100644 --- a/tests/pytest/wal/sdbCompCluster.py +++ b/tests/pytest/wal/sdbCompCluster.py @@ -66,11 +66,11 @@ class TwoClients: os.system("rm -rf /var/lib/taos/mnode_bak/") os.system("rm -rf /var/lib/taos/mnode_temp/") tdSql.execute("drop database if exists db2") - os.system("%staosdemo -f wal/insertDataDb1.json -y " % binPath) + os.system("%staosBenchmark -f wal/insertDataDb1.json -y " % binPath) tdSql.execute("drop database if exists db1") - os.system("%staosdemo -f wal/insertDataDb2.json -y " % binPath) + os.system("%staosBenchmark -f wal/insertDataDb2.json -y " % binPath) tdSql.execute("drop table if exists db2.stb0") - os.system("%staosdemo -f wal/insertDataDb2Newstab.json -y " % binPath) + os.system("%staosBenchmark -f wal/insertDataDb2Newstab.json -y " % binPath) query_pid1 = int(subprocess.getstatusoutput('ps aux|grep taosd |grep -v "grep"|awk \'{print $2}\'')[1]) print(query_pid1) tdSql.execute("use db2") diff --git a/tests/pytest/wal/sdbCompClusterReplica2.py b/tests/pytest/wal/sdbCompClusterReplica2.py index ba80e3864aed27c091dd5ec72ca9f09ea2c36126..1a9354c61e1f4986a399a8684ccd3678c8bfaa7e 100644 --- a/tests/pytest/wal/sdbCompClusterReplica2.py +++ b/tests/pytest/wal/sdbCompClusterReplica2.py @@ -66,11 +66,11 @@ class TwoClients: os.system("rm -rf /var/lib/taos/mnode_bak/") os.system("rm -rf /var/lib/taos/mnode_temp/") tdSql.execute("drop database if exists db2") - os.system("%staosdemo -f wal/insertDataDb1Replica2.json -y " % binPath) + os.system("%staosBenchmark -f wal/insertDataDb1Replica2.json -y " % binPath) tdSql.execute("drop database if exists db1") - os.system("%staosdemo -f wal/insertDataDb2Replica2.json -y " % binPath) + os.system("%staosBenchmark -f wal/insertDataDb2Replica2.json -y " % binPath) tdSql.execute("drop table if exists db2.stb0") - os.system("%staosdemo -f wal/insertDataDb2NewstabReplica2.json -y " % binPath) + os.system("%staosBenchmark -f wal/insertDataDb2NewstabReplica2.json -y " % binPath) query_pid1 = int(subprocess.getstatusoutput('ps aux|grep taosd |grep -v "grep"|awk \'{print $2}\'')[1]) print(query_pid1) tdSql.execute("use db2") diff --git a/tests/script/api/batchprepare.c b/tests/script/api/batchprepare.c index 2cbee8eac91719a4cbff4d9c323f1f304e8e8684..8931f2021f16674140844a1d4bf76cb9d7168b45 100644 --- a/tests/script/api/batchprepare.c +++ b/tests/script/api/batchprepare.c @@ -2722,6 +2722,38 @@ int stmt_funcb_autoctb_e5(TAOS_STMT *stmt) { } +int stmt_funcb_autoctb_e6(TAOS_STMT *stmt) { + char *sql = "insert into ? using stb1 tags(?,?,?,?,?,?,?,?,?) values(now,?,?,?,?,?,?,?,?,?)"; + int code = taos_stmt_prepare(stmt, sql, 0); + if (code != 0){ + printf("case success:failed to execute taos_stmt_prepare. code:%s\n", taos_stmt_errstr(stmt)); + } + + return 0; +} + + +int stmt_funcb_autoctb_e7(TAOS_STMT *stmt) { + char *sql = "insert into ? using stb1 tags(?,?,?,?,?,?,?,?,?) values(?,true,?,?,?,?,?,?,?,?)"; + int code = taos_stmt_prepare(stmt, sql, 0); + if (code != 0){ + printf("case success:failed to execute taos_stmt_prepare. code:%s\n", taos_stmt_errstr(stmt)); + } + + return 0; +} + + +int stmt_funcb_autoctb_e8(TAOS_STMT *stmt) { + char *sql = "insert into ? using stb1 tags(?,?,?,?,?,?,?,?,?) values(?,?,1,?,?,?,?,?,?,?)"; + int code = taos_stmt_prepare(stmt, sql, 0); + if (code != 0){ + printf("case success:failed to execute taos_stmt_prepare. code:%s\n", taos_stmt_errstr(stmt)); + } + + return 0; +} + //300 tables 60 records int stmt_funcb1(TAOS_STMT *stmt) { @@ -4857,6 +4889,44 @@ void* runcase(void *par) { #endif + +#if 1 + prepare(taos, 1, 0); + + stmt = taos_stmt_init(taos); + + printf("e6 start\n"); + stmt_funcb_autoctb_e6(stmt); + printf("e6 end\n"); + taos_stmt_close(stmt); + +#endif + +#if 1 + prepare(taos, 1, 0); + + stmt = taos_stmt_init(taos); + + printf("e7 start\n"); + stmt_funcb_autoctb_e7(stmt); + printf("e7 end\n"); + taos_stmt_close(stmt); + +#endif + +#if 1 + prepare(taos, 1, 0); + + stmt = taos_stmt_init(taos); + + printf("e8 start\n"); + stmt_funcb_autoctb_e8(stmt); + printf("e8 end\n"); + taos_stmt_close(stmt); + +#endif + + #if 1 prepare(taos, 1, 0); diff --git a/tests/script/general/parser/columnName_escape.sim b/tests/script/general/parser/columnName_escape.sim index dd3278d0dc98fa5378b7aed122dc39f6717372d5..13ad184518f18096d0d2088957fca28c19fbd86c 100644 --- a/tests/script/general/parser/columnName_escape.sim +++ b/tests/script/general/parser/columnName_escape.sim @@ -423,4 +423,48 @@ if $data04 != 1 then return -1 endi +print ======================= test show create table/stable +sql create table tb3 (ts timestamp, `123` int, `123 456` int, `123.abc` int) +sql create table stb3 (ts timestamp, `123` int, `123 456` int, `123.abc` int) tags (t1 int) +sql create table ctb3 using stb3 tags (1) + +sql show create table tb3; +if $rows != 1 then + return -1 +endi + +if $data00 != @tb3@ then + return -1 +endi + +if $data01 != @create table `tb3` (`ts` TIMESTAMP,`123` INT,`123 456` INT,`123.abc` INT)@ then + return -1 +endi + +sql show create stable stb3; +if $rows != 1 then + return -1 +endi + +if $data00 != @stb3@ then + return -1 +endi + +if $data01 != @create table `stb3` (`ts` TIMESTAMP,`123` INT,`123 456` INT,`123.abc` INT) TAGS (`t1` INT)@ then + return -1 +endi + +sql show create table ctb3; +if $rows != 1 then + return -1 +endi + +if $data00 != @ctb3@ then + return -1 +endi + +if $data01 != @CREATE TABLE `ctb3` USING `stb3` TAGS (1)@ then + return -1 +endi + system sh/exec.sh -n dnode1 -s stop -x SIGINT diff --git a/tests/script/general/parser/nestquery.sim b/tests/script/general/parser/nestquery.sim index 7654146b6cb1bbf8f4ebb6cce1c239b1c6f9fa20..16803ea0965a66107a90aaf7ad37d715314a8258 100644 --- a/tests/script/general/parser/nestquery.sim +++ b/tests/script/general/parser/nestquery.sim @@ -419,12 +419,14 @@ if $data03 != @20-09-15 00:00:00.000@ then return -1 endi +sql_error select diff(val) from (select c1 val from nest_tb0); + sql select diff(val) from (select ts,c1 val from nest_tb0); if $rows != 9999 then return -1 endi -if $data00 != @70-01-01 08:00:00.000@ then +if $data00 != @20-09-15 00:01:00.000@ then return -1 endi diff --git a/tests/script/general/parser/slimit_query.sim b/tests/script/general/parser/slimit_query.sim index 0a793f0611a5875f53ac75644f3156ad9aa6cc65..0dbcffa0a43b596d542c8799a9a94170e6f71f5a 100644 --- a/tests/script/general/parser/slimit_query.sim +++ b/tests/script/general/parser/slimit_query.sim @@ -31,6 +31,8 @@ $tsu = $tsu + $ts0 #sql_error select top(c1, 1) from $stb where ts >= $ts0 and ts <= $tsu slimit 5 offset 1 #sql_error select bottom(c1, 1) from $stb where ts >= $ts0 and ts <= $tsu slimit 5 offset 1 +sql_error select t1 from $stb slimit 5 offset 1; + ### select from stb + group by + slimit offset sql select max(c1), min(c2), avg(c3), sum(c4), spread(c5), sum(c6), count(c7), first(c8), last(c9) from $stb group by t1 slimit 5 soffset 0 if $rows != 5 then diff --git a/tests/script/general/parser/tagName_escape.sim b/tests/script/general/parser/tagName_escape.sim index 1dc9121a45ea23201d63dedfb7a6c446ee7b0e87..79073c335ef307770419f3b99736a70f94d73360 100644 --- a/tests/script/general/parser/tagName_escape.sim +++ b/tests/script/general/parser/tagName_escape.sim @@ -203,5 +203,35 @@ if $data24 != NULL then return -1 endi +print ======================= test show create table/stable +sql create stable stb3 (ts timestamp, c0 int) tags (`123` int, `123 456` int, `123.abc` int) +sql create table ctb3 using stb3 (`123`, `123 456`, `123.abc`) tags (1, 1, 1) + +sql show create table stb3; +if $rows != 1 then + return -1 +endi + +if $data00 != @stb3@ then + return -1 +endi + +if $data01 != @create table `stb3` (`ts` TIMESTAMP,`c0` INT) TAGS (`123` INT,`123 456` INT,`123.abc` INT)@ then + return -1 +endi + +sql show create table ctb3; +if $rows != 1 then + return -1 +endi + +if $data00 != @ctb3@ then + return -1 +endi + +if $data01 != @CREATE TABLE `ctb3` USING `stb3` TAGS (1,1,1)@ then + return -1 +endi + system sh/exec.sh -n dnode1 -s stop -x SIGINT diff --git a/tests/system-test/0-management/0-database/.gitkeep b/tests/system-test/0-management/0-database/.gitkeep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/tests/system-test/0-management/1-stable/.gitkeep b/tests/system-test/0-management/1-stable/.gitkeep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/tests/system-test/0-management/1-stable/create_col_tag.py b/tests/system-test/0-management/1-stable/create_col_tag.py new file mode 100644 index 0000000000000000000000000000000000000000..d195e73321ea24a8b9de1f2ca5f9c07f9182dd65 --- /dev/null +++ b/tests/system-test/0-management/1-stable/create_col_tag.py @@ -0,0 +1,853 @@ +################################################################### +# Copyright (c) 2016 by TAOS Technologies, Inc. +# All rights reserved. +# +# This file is proprietary and confidential to TAOS Technologies. +# No part of this file may be reproduced, stored, transmitted, +# disclosed or used in any form or by any means other than as +# expressly provided by the written permission from Jianhui Tao +# +################################################################### + +# -*- coding: utf-8 -*- + +import sys +import taos +import time +import os +from util.log import tdLog +from util.cases import tdCases +from util.sql import tdSql + + +class TDTestCase: + def caseDescription(self): + ''' + case1:The escape char "`" can be used for both tag name and column name + case2:create stable(column&tag); insert data; show stable; show create table; add stable(column&tag);change stable(tag);drop stable(column&tag);modify stable(column&tag)(binary和nchar);drop stable; + case3:create stable_child; insert data; show stable_child; show create stable_child; drop stable_child; + case4:create regular_table(column); insert data; show regular_table; show create regular_table; add regular_table(column);drop regular_table(column);modify regular_table(column)(binary和nchar);drop regular_table; + ''' + return + + def init(self, conn, logSql): + tdLog.debug("start to execute %s" % __file__) + tdSql.init(conn.cursor(), logSql) + + now = time.time() + self.ts = int(round(now * 1000)) + + def table1_checkall(self,sql): + tdLog.info(sql) + tdSql.query(sql) + tdSql.checkData(0,1,1) + tdSql.checkData(0,2,2) + tdSql.checkData(0,3,3) + tdSql.checkData(0,4,4) + tdSql.checkData(0,5,'True') + tdSql.checkData(0,6,6) + tdSql.checkData(0,7,7) + tdSql.checkData(0,8,8) + tdSql.checkData(0,9,9) + tdSql.checkData(0,10,'1970-01-01 08:00:00.010') + + def table1_checkall_1(self,sql): + tdSql.query(sql) + tdSql.checkData(0,1,1) + + def table1_checkall_2(self,sql): + self.table1_checkall_1(sql) + tdSql.checkData(0,2,2) + + def table1_checkall_3(self,sql): + self.table1_checkall_2(sql) + tdSql.checkData(0,3,3) + + def table1_checkall_4(self,sql): + self.table1_checkall_3(sql) + tdSql.checkData(0,4,4) + + def table1_checkall_5(self,sql): + self.table1_checkall_4(sql) + tdSql.checkData(0,5,'True') + + def table1_checkall_6(self,sql): + self.table1_checkall_5(sql) + tdSql.checkData(0,6,6) + + def table1_checkall_7(self,sql): + self.table1_checkall_6(sql) + tdSql.checkData(0,7,7) + + def table1_checkall_8(self,sql): + self.table1_checkall_7(sql) + tdSql.checkData(0,8,8) + + def table1_checkall_9(self,sql): + self.table1_checkall_8(sql) + tdSql.checkData(0,9,9) + + def table1_checkall_10(self,sql): + self.table1_checkall_9(sql) + tdSql.checkData(0,10,'1970-01-01 08:00:00.010') + + def run(self): + + testcaseFilename = os.path.split(__file__)[-1] + os.system("rm -rf 0-management/1-stable/%s.sql" % testcaseFilename ) + tdSql.prepare() + + print("==============step1") + print("prepare data") + + # case for defect: https://jira.taosdata.com:18080/browse/TD-2693 + tdSql.execute("create database db2") + tdSql.execute("use db2") + + print("==============new version [escape character] for stable==============") + print("==============step1,#create db.stable,db.table; insert db.table; show db.table; select db.table; drop db.table;") + print("prepare data") + + self.stb1 = "stable_1~!@#$%^&*()-_+=[]{}':,<.>/?stST13579" + self.tb1 = "table_1~!@#$%^&*()-_+=[]{}':,<.>/?stST13579" + + self.col_base = "123~!@#$%^&*()-_+=[]{}':,<.>/?stST13579" + + self.col_int = "stable_col_int%s" %self.col_base + print(self.col_int) + self.col_bigint = "stable_col_bigint%s" %self.col_base + self.col_smallint = "stable_col_smallint%s" %self.col_base + self.col_tinyint = "stable_col_tinyint%s" %self.col_base + self.col_bool = "stable_col_bool%s" %self.col_base + self.col_binary = "stable_col_binary%s" %self.col_base + self.col_nchar = "stable_col_nchar%s" %self.col_base + self.col_float = "stable_col_float%s" %self.col_base + self.col_double = "stable_col_double%s" %self.col_base + self.col_ts = "stable_col_ts%s" %self.col_base + + self.tag_base = "abc~!@#$%^&*()-_+=[]{}':,<.>/?stST13579" + self.tag_int = "stable_tag_int%s" %self.tag_base + self.tag_bigint = "stable_tag_bigint%s" %self.tag_base + self.tag_smallint = "stable_tag_smallint%s" %self.tag_base + self.tag_tinyint = "stable_tag_tinyint%s" %self.tag_base + self.tag_bool = "stable_tag_bool%s" %self.tag_base + self.tag_binary = "stable_tag_binary%s" %self.tag_base + self.tag_nchar = "stable_tag_nchar%s" %self.tag_base + self.tag_float = "stable_tag_float%s" %self.tag_base + self.tag_double = "stable_tag_double%s" %self.tag_base + self.tag_ts = "stable_tag_ts%s" %self.tag_base + + tdSql.execute('''create stable db.`%s` (ts timestamp, `%s` int , `%s` bigint , `%s` smallint , `%s` tinyint, `%s` bool , + `%s` binary(20) , `%s` nchar(20) ,`%s` float , `%s` double , `%s` timestamp) + tags(loc nchar(20), `%s` int , `%s` bigint , `%s` smallint , `%s` tinyint, `%s` bool , + `%s` binary(20) , `%s` nchar(20) ,`%s` float , `%s` double , `%s` timestamp);''' + %(self.stb1, self.col_int, self.col_bigint, self.col_smallint, self.col_tinyint, self.col_bool, + self.col_binary, self.col_nchar, self.col_float, self.col_double, self.col_ts, + self.tag_int, self.tag_bigint, self.tag_smallint, self.tag_tinyint, self.tag_bool, + self.tag_binary, self.tag_nchar, self.tag_float, self.tag_double, self.tag_ts)) + tdSql.query("describe db.`%s` ; " %self.stb1) + tdSql.checkRows(22) + + tdSql.query("select _block_dist() from db.`%s` ; " %self.stb1) + tdSql.checkRows(0) + + tdSql.query("show create stable db.`%s` ; " %self.stb1) + tdSql.checkData(0, 0, self.stb1) + tdSql.checkData(0, 1, "create table `%s` (`ts` TIMESTAMP,`%s` INT,`%s` BIGINT,`%s` SMALLINT,`%s` TINYINT,`%s` BOOL,`%s` BINARY(20),`%s` NCHAR(20),`%s` FLOAT,`%s` DOUBLE,`%s` TIMESTAMP)\ + TAGS (`loc` NCHAR(20),`%s` INT,`%s` BIGINT,`%s` SMALLINT,`%s` TINYINT,`%s` BOOL,`%s` BINARY(20),`%s` NCHAR(20),`%s` FLOAT,`%s` DOUBLE,`%s` TIMESTAMP)" + %(self.stb1, self.col_int, self.col_bigint, self.col_smallint, self.col_tinyint, self.col_bool, + self.col_binary, self.col_nchar, self.col_float, self.col_double, self.col_ts, + self.tag_int, self.tag_bigint, self.tag_smallint, self.tag_tinyint, self.tag_bool, + self.tag_binary, self.tag_nchar, self.tag_float, self.tag_double, self.tag_ts)) + + tdSql.execute("create table db.`table!1` using db.`%s` tags('table_1' , '0' , '0' , '0' , '0' , 0 , '0' , '0' , '0' , '0' ,'0')" %self.stb1) + tdSql.query("describe db.`table!1` ; ") + tdSql.checkRows(22) + + time.sleep(10) + tdSql.query("show create table db.`table!1` ; ") + tdSql.checkData(0, 0, "table!1") + tdSql.checkData(0, 1, "CREATE TABLE `table!1` USING `%s` TAGS (\"table_1\",0,0,0,0,false,\"0\",\"0\",0.000000,0.000000,\"0\")" %self.stb1) + + tdSql.execute("insert into db.`table!1` values(now, 1 , 2, 3, 4, 5, 6 ,7 ,8 ,9 ,10)") + sql = " select * from db.`table!1`; " + datacheck = self.table1_checkall(sql) + tdSql.checkRows(1) + sql = '''select ts ,`%s`,`%s`,`%s`,`%s`,`%s`,`%s`,`%s`,`%s`,`%s`,`%s` from db.`table!1`; '''\ + %(self.col_int, self.col_bigint, self.col_smallint, self.col_tinyint, self.col_bool, self.col_binary, self.col_nchar, self.col_float, self.col_double, self.col_ts) + datacheck = self.table1_checkall(sql) + tdSql.checkRows(1) + + time.sleep(1) + tdSql.execute('''insert into db.`table!1`(ts ,`%s`,`%s`,`%s`,`%s`,`%s`,`%s`,`%s`,`%s`,`%s`,`%s`) values(now, 1 , 2, 3, 4, 5, 6 ,7 ,8 ,9 ,10)'''\ + %(self.col_int, self.col_bigint, self.col_smallint, self.col_tinyint, self.col_bool, self.col_binary, self.col_nchar, self.col_float, self.col_double, self.col_ts) ) + sql = " select * from db.`table!1`; " + datacheck = self.table1_checkall(sql) + tdSql.checkRows(2) + + tdSql.query("select count(*) from db.`table!1`; ") + tdSql.checkData(0, 0, 2) + tdSql.query("select _block_dist() from db.`%s` ; " %self.stb1) + tdSql.checkRows(1) + + tdSql.execute("create table db.`%s` using db.`%s` TAGS (\"table_2\",2,2,2,2,true,\"2\",\"2\",2.000000,2.000000,\"2\")" %(self.tb1,self.stb1)) + tdSql.query("describe db.`%s` ; " %self.tb1) + tdSql.checkRows(22) + tdSql.query("show create table db.`%s` ; " %self.tb1) + tdSql.checkData(0, 0, self.tb1) + tdSql.checkData(0, 1, "CREATE TABLE `%s` USING `%s` TAGS (\"table_2\",2,2,2,2,true,\"2\",\"2\",2.000000,2.000000,\"2\")" %(self.tb1,self.stb1)) + + tdSql.execute("insert into db.`%s` values(now, 1 , 2, 3, 4, 5, 6 ,7 ,8 ,9 ,10)" %self.tb1) + sql = "select * from db.`%s` ; " %self.tb1 + datacheck = self.table1_checkall(sql) + tdSql.checkRows(1) + sql = '''select ts ,`%s`,`%s`,`%s`,`%s`,`%s`,`%s`,`%s`,`%s`,`%s`,`%s`,`%s`,`%s`,`%s`,`%s`,`%s`,`%s`,`%s`,`%s`,`%s`,`%s` from db.`%s` ; '''\ + %(self.col_int, self.col_bigint, self.col_smallint, self.col_tinyint, self.col_bool, self.col_binary, self.col_nchar, self.col_float, self.col_double, self.col_ts,\ + self.tag_int, self.tag_bigint, self.tag_smallint, self.tag_tinyint, self.tag_bool, self.tag_binary, self.tag_nchar, self.tag_float, self.tag_double, self.tag_ts, self.tb1) + datacheck = self.table1_checkall(sql) + tdSql.checkRows(1) + + time.sleep(1) + tdSql.execute('''insert into db.`%s`(ts ,`%s`,`%s`,`%s`,`%s`,`%s`,`%s`,`%s`,`%s`,`%s`,`%s`) values(now, 1 , 2, 3, 4, 5, 6 ,7 ,8 ,9 ,10)'''\ + %(self.tb1, self.col_int, self.col_bigint, self.col_smallint, self.col_tinyint, self.col_bool, self.col_binary, self.col_nchar, self.col_float, self.col_double, self.col_ts) ) + sql = " select * from db.`%s` ; " %self.tb1 + datacheck = self.table1_checkall(sql) + tdSql.checkRows(2) + + sql = " select * from db.`%s` where `%s`=1 and `%s`=2 and `%s`=3 and `%s`=4 and `%s`='True' and `%s`=6 and `%s`=7 and `%s`=8 and `%s`=9 and `%s`=10; " \ + %(self.tb1, self.col_int, self.col_bigint, self.col_smallint, self.col_tinyint, self.col_bool, self.col_binary, self.col_nchar, self.col_float, self.col_double, self.col_ts) + datacheck = self.table1_checkall(sql) + tdSql.checkRows(2) + + tdSql.query("select count(*) from db.`%s`; " %self.tb1) + tdSql.checkData(0, 0, 2) + sql = "select * from db.`%s` ; " %self.stb1 + datacheck = self.table1_checkall(sql) + tdSql.checkRows(4) + tdSql.query("select count(*) from db.`%s`; " %self.stb1) + tdSql.checkData(0, 0, 4) + + sql = "select * from (select * from db.`%s`) ; " %self.stb1 + datacheck = self.table1_checkall(sql) + tdSql.checkRows(4) + tdSql.query("select count(*) from (select * from db.`%s`) ; " %self.stb1) + tdSql.checkData(0, 0, 4) + + sql = "select * from (select ts ,`%s`,`%s`,`%s`,`%s`,`%s`,`%s`,`%s`,`%s`,`%s`,`%s` from db.`%s`) ; " \ + %(self.col_int, self.col_bigint, self.col_smallint, self.col_tinyint, self.col_bool, self.col_binary, self.col_nchar, self.col_float, self.col_double, self.col_ts, self.stb1) + datacheck = self.table1_checkall(sql) + tdSql.checkRows(4) + + sql = "select ts ,`%s`,`%s`,`%s`,`%s`,`%s`,`%s`,`%s`,`%s`,`%s`,`%s` from (select ts ,`%s`,`%s`,`%s`,`%s`,`%s`,`%s`,`%s`,`%s`,`%s`,`%s` from db.`%s`) ; " \ + %(self.col_int, self.col_bigint, self.col_smallint, self.col_tinyint, self.col_bool, self.col_binary, self.col_nchar, self.col_float, self.col_double, self.col_ts,\ + self.col_int, self.col_bigint, self.col_smallint, self.col_tinyint, self.col_bool, self.col_binary, self.col_nchar, self.col_float, self.col_double, self.col_ts, self.stb1) + datacheck = self.table1_checkall(sql) + tdSql.checkRows(4) + + sql = "select ts ,`%s`,`%s`,`%s`,`%s`,`%s`,`%s`,`%s`,`%s`,`%s`,`%s` from (select ts ,`%s`,`%s`,`%s`,`%s`,`%s`,`%s`,`%s`,`%s`,`%s`,`%s` from db.`%s`\ + where `%s`=1 and `%s`=2 and `%s`=3 and `%s`=4 and `%s`='True' and `%s`=6 and `%s`=7 and `%s`=8 and `%s`=9 and `%s`=10 ) ; " \ + %(self.col_int, self.col_bigint, self.col_smallint, self.col_tinyint, self.col_bool, self.col_binary, self.col_nchar, self.col_float, self.col_double, self.col_ts,\ + self.col_int, self.col_bigint, self.col_smallint, self.col_tinyint, self.col_bool, self.col_binary, self.col_nchar, self.col_float, self.col_double, self.col_ts, self.stb1, \ + self.col_int, self.col_bigint, self.col_smallint, self.col_tinyint, self.col_bool, self.col_binary, self.col_nchar, self.col_float, self.col_double, self.col_ts) + datacheck = self.table1_checkall(sql) + tdSql.checkRows(4) + + tdSql.query("show db.stables like 'stable_1%' ") + tdSql.checkRows(1) + tdSql.query("show db.tables like 'table%' ") + tdSql.checkRows(2) + + self.cr_tb1 = "create_table_1~!@#$%^&*()-_+=[]{}':,<.>/?stST13579" + tdSql.execute("create table db.`%s` as select avg(`%s`) from db.`%s` where ts > now interval(1m) sliding(30s);" %(self.cr_tb1,self.col_bigint,self.stb1)) + tdSql.query("show db.tables like 'create_table_%' ") + tdSql.checkRows(1) + + print("==============drop\ add\ change\ modify column or tag") + print("==============drop==============") + tdSql.execute("ALTER TABLE db.`%s` DROP TAG `%s`; " %(self.stb1, self.tag_ts)) + sql = " select * from db.`%s`; " %self.stb1 + datacheck = self.table1_checkall(sql) + tdSql.query("describe db.`%s` ; " %self.tb1) + tdSql.checkRows(21) + tdSql.execute("ALTER TABLE db.`%s` DROP TAG `%s`; " %(self.stb1, self.tag_double)) + sql = " select * from db.`%s`; " %self.stb1 + datacheck = self.table1_checkall(sql) + tdSql.query("describe db.`%s` ; " %self.tb1) + tdSql.checkRows(20) + tdSql.execute("ALTER TABLE db.`%s` DROP TAG `%s`; " %(self.stb1, self.tag_float)) + sql = " select * from db.`%s`; " %self.stb1 + datacheck = self.table1_checkall(sql) + tdSql.query("describe db.`%s` ; " %self.tb1) + tdSql.checkRows(19) + tdSql.execute("ALTER TABLE db.`%s` DROP TAG `%s`; " %(self.stb1, self.tag_nchar)) + sql = " select * from db.`%s`; " %self.stb1 + datacheck = self.table1_checkall(sql) + tdSql.query("describe db.`%s` ; " %self.tb1) + tdSql.checkRows(18) + tdSql.execute("ALTER TABLE db.`%s` DROP TAG `%s`; " %(self.stb1, self.tag_binary)) + sql = " select * from db.`%s`; " %self.stb1 + datacheck = self.table1_checkall(sql) + tdSql.query("describe db.`%s` ; " %self.tb1) + tdSql.checkRows(17) + tdSql.execute("ALTER TABLE db.`%s` DROP TAG `%s`; " %(self.stb1, self.tag_bool)) + sql = " select * from db.`%s`; " %self.stb1 + datacheck = self.table1_checkall(sql) + tdSql.query("describe db.`%s` ; " %self.tb1) + tdSql.checkRows(16) + tdSql.execute("ALTER TABLE db.`%s` DROP TAG `%s`; " %(self.stb1, self.tag_tinyint)) + sql = " select * from db.`%s`; " %self.stb1 + datacheck = self.table1_checkall(sql) + tdSql.query("describe db.`%s` ; " %self.tb1) + tdSql.checkRows(15) + tdSql.execute("ALTER TABLE db.`%s` DROP TAG `%s`; " %(self.stb1, self.tag_smallint)) + sql = " select * from db.`%s`; " %self.stb1 + datacheck = self.table1_checkall(sql) + tdSql.query("describe db.`%s` ; " %self.tb1) + tdSql.checkRows(14) + tdSql.execute("ALTER TABLE db.`%s` DROP TAG `%s`; " %(self.stb1, self.tag_bigint)) + sql = " select * from db.`%s`; " %self.stb1 + datacheck = self.table1_checkall(sql) + tdSql.query("describe db.`%s` ; " %self.tb1) + tdSql.checkRows(13) + tdSql.execute("ALTER TABLE db.`%s` DROP TAG `%s`; " %(self.stb1, self.tag_int)) + sql = " select * from db.`%s`; " %self.stb1 + datacheck = self.table1_checkall(sql) + tdSql.query("describe db.`%s` ; " %self.tb1) + tdSql.checkRows(12) + + tdSql.execute("ALTER TABLE db.`%s` DROP COLUMN `%s`; " %(self.stb1, self.col_ts)) + sql = " select * from db.`%s`; " %self.stb1 + datacheck = self.table1_checkall_9(sql) + tdSql.query("describe db.`%s` ; " %self.tb1) + tdSql.checkRows(11) + tdSql.execute("ALTER TABLE db.`%s` DROP COLUMN `%s`; " %(self.stb1, self.col_double)) + sql = " select * from db.`%s`; " %self.stb1 + datacheck = self.table1_checkall_8(sql) + tdSql.query("describe db.`%s` ; " %self.tb1) + tdSql.checkRows(10) + tdSql.execute("ALTER TABLE db.`%s` DROP COLUMN `%s`; " %(self.stb1, self.col_float)) + sql = " select * from db.`%s`; " %self.stb1 + datacheck = self.table1_checkall_7(sql) + tdSql.query("describe db.`%s` ; " %self.tb1) + tdSql.checkRows(9) + tdSql.execute("ALTER TABLE db.`%s` DROP COLUMN `%s`; " %(self.stb1, self.col_nchar)) + sql = " select * from db.`%s`; " %self.stb1 + datacheck = self.table1_checkall_6(sql) + tdSql.query("describe db.`%s` ; " %self.tb1) + tdSql.checkRows(8) + tdSql.execute("ALTER TABLE db.`%s` DROP COLUMN `%s`; " %(self.stb1, self.col_binary)) + sql = " select * from db.`%s`; " %self.stb1 + datacheck = self.table1_checkall_5(sql) + tdSql.query("describe db.`%s` ; " %self.tb1) + tdSql.checkRows(7) + tdSql.execute("ALTER TABLE db.`%s` DROP COLUMN `%s`; " %(self.stb1, self.col_bool)) + sql = " select * from db.`%s`; " %self.stb1 + datacheck = self.table1_checkall_4(sql) + tdSql.query("describe db.`%s` ; " %self.tb1) + tdSql.checkRows(6) + tdSql.execute("ALTER TABLE db.`%s` DROP COLUMN `%s`; " %(self.stb1, self.col_tinyint)) + sql = " select * from db.`%s`; " %self.stb1 + datacheck = self.table1_checkall_3(sql) + tdSql.query("describe db.`%s` ; " %self.tb1) + tdSql.checkRows(5) + tdSql.execute("ALTER TABLE db.`%s` DROP COLUMN `%s`; " %(self.stb1, self.col_smallint)) + sql = " select * from db.`%s`; " %self.stb1 + datacheck = self.table1_checkall_2(sql) + tdSql.query("describe db.`%s` ; " %self.tb1) + tdSql.checkRows(4) + tdSql.execute("ALTER TABLE db.`%s` DROP COLUMN `%s`; " %(self.stb1, self.col_bigint)) + sql = " select * from db.`%s`; " %self.stb1 + datacheck = self.table1_checkall_1(sql) + tdSql.query("describe db.`%s` ; " %self.tb1) + tdSql.checkRows(3) + tdSql.error("ALTER TABLE db.`%s` DROP COLUMN `%s`; " %(self.stb1, self.col_int)) + tdSql.query("describe db.`%s` ; " %self.tb1) + tdSql.checkRows(3) + + print("==============add==============") + tdSql.execute("ALTER TABLE db.`%s` ADD COLUMN `%s` bigint; " %(self.stb1, self.col_bigint)) + tdSql.query("describe db.`%s` ; " %self.tb1) + tdSql.checkRows(4) + tdSql.execute("ALTER TABLE db.`%s` ADD COLUMN `%s` smallint; " %(self.stb1, self.col_smallint)) + tdSql.query("describe db.`%s` ; " %self.tb1) + tdSql.checkRows(5) + tdSql.execute("ALTER TABLE db.`%s` ADD COLUMN `%s` tinyint; " %(self.stb1, self.col_tinyint)) + tdSql.query("describe db.`%s` ; " %self.tb1) + tdSql.checkRows(6) + tdSql.execute("ALTER TABLE db.`%s` ADD COLUMN `%s` bool; " %(self.stb1, self.col_bool)) + tdSql.query("describe db.`%s` ; " %self.tb1) + tdSql.checkRows(7) + tdSql.execute("ALTER TABLE db.`%s` ADD COLUMN `%s` binary(20); " %(self.stb1, self.col_binary)) + tdSql.query("describe db.`%s` ; " %self.tb1) + tdSql.checkRows(8) + + tdSql.execute("insert into db.`%s` values(now, 1 , 2, 3, 4, 5, 6)" %self.tb1) + sql = "select * from db.`%s` order by ts desc; " %self.tb1 + datacheck = self.table1_checkall_5(sql) + + tdSql.execute("ALTER TABLE db.`%s` ADD COLUMN `%s` nchar(20); " %(self.stb1, self.col_nchar)) + tdSql.query("describe db.`%s` ; " %self.tb1) + tdSql.checkRows(9) + tdSql.execute("ALTER TABLE db.`%s` ADD COLUMN `%s` float; " %(self.stb1, self.col_float)) + tdSql.query("describe db.`%s` ; " %self.tb1) + tdSql.checkRows(10) + tdSql.execute("ALTER TABLE db.`%s` ADD COLUMN `%s` double; " %(self.stb1, self.col_double)) + tdSql.query("describe db.`%s` ; " %self.tb1) + tdSql.checkRows(11) + tdSql.execute("ALTER TABLE db.`%s` ADD COLUMN `%s` timestamp; " %(self.stb1, self.col_ts)) + tdSql.query("describe db.`%s` ; " %self.tb1) + tdSql.checkRows(12) + + tdSql.execute("insert into db.`%s` values(now, 1 , 2, 3, 4, 5, 6 ,7 ,8 ,9 ,10)" %self.tb1) + sql = "select * from db.`%s` order by ts desc; " %self.tb1 + datacheck = self.table1_checkall(sql) + + tdSql.execute("ALTER TABLE db.`%s` ADD TAG `%s` int; " %(self.stb1, self.tag_int)) + sql = " select * from db.`%s` order by ts desc; " %self.stb1 + datacheck = self.table1_checkall(sql) + tdSql.query("describe db.`%s` ; " %self.tb1) + tdSql.checkRows(13) + tdSql.execute("ALTER TABLE db.`%s` ADD TAG `%s` bigint; " %(self.stb1, self.tag_bigint)) + sql = " select * from db.`%s` order by ts desc; " %self.stb1 + datacheck = self.table1_checkall(sql) + tdSql.query("describe db.`%s` ; " %self.tb1) + tdSql.checkRows(14) + tdSql.execute("ALTER TABLE db.`%s` ADD TAG `%s` smallint; " %(self.stb1, self.tag_smallint)) + sql = " select * from db.`%s` order by ts desc; " %self.stb1 + datacheck = self.table1_checkall(sql) + tdSql.query("describe db.`%s` ; " %self.tb1) + tdSql.checkRows(15) + tdSql.execute("ALTER TABLE db.`%s` ADD TAG `%s` tinyint; " %(self.stb1, self.tag_tinyint)) + sql = " select * from db.`%s` order by ts desc; " %self.stb1 + datacheck = self.table1_checkall(sql) + tdSql.query("describe db.`%s` ; " %self.tb1) + tdSql.checkRows(16) + tdSql.execute("ALTER TABLE db.`%s` ADD TAG `%s` bool; " %(self.stb1, self.tag_bool)) + sql = " select * from db.`%s` order by ts desc; " %self.stb1 + datacheck = self.table1_checkall(sql) + tdSql.query("describe db.`%s` ; " %self.tb1) + tdSql.checkRows(17) + tdSql.execute("ALTER TABLE db.`%s` ADD TAG `%s` binary(20); " %(self.stb1, self.tag_binary)) + sql = " select * from db.`%s` order by ts desc; " %self.stb1 + datacheck = self.table1_checkall(sql) + tdSql.query("describe db.`%s` ; " %self.tb1) + tdSql.checkRows(18) + tdSql.execute("ALTER TABLE db.`%s` ADD TAG `%s` nchar(20); " %(self.stb1, self.tag_nchar)) + sql = " select * from db.`%s` order by ts desc; " %self.stb1 + datacheck = self.table1_checkall(sql) + tdSql.query("describe db.`%s` ; " %self.tb1) + tdSql.checkRows(19) + tdSql.execute("ALTER TABLE db.`%s` ADD TAG `%s` float; " %(self.stb1, self.tag_float)) + sql = " select * from db.`%s` order by ts desc; " %self.stb1 + datacheck = self.table1_checkall(sql) + tdSql.query("describe db.`%s` ; " %self.tb1) + tdSql.checkRows(20) + tdSql.execute("ALTER TABLE db.`%s` ADD TAG `%s` double; " %(self.stb1, self.tag_double)) + sql = " select * from db.`%s` order by ts desc; " %self.stb1 + datacheck = self.table1_checkall(sql) + tdSql.query("describe db.`%s` ; " %self.tb1) + tdSql.checkRows(21) + tdSql.execute("ALTER TABLE db.`%s` ADD TAG `%s` timestamp; " %(self.stb1, self.tag_ts)) + sql = " select * from db.`%s` order by ts desc; " %self.stb1 + datacheck = self.table1_checkall(sql) + tdSql.query("describe db.`%s` ; " %self.tb1) + tdSql.checkRows(22) + + print("==============change==============") + self.tag_base_change = "abcdas" + self.tag_int_change = "stable_tag_int%s" %self.tag_base_change + self.tag_bigint_change = "stable_tag_bigint%s" %self.tag_base_change + self.tag_smallint_change = "stable_tag_smallint%s" %self.tag_base_change + self.tag_tinyint_change = "stable_tag_tinyint%s" %self.tag_base_change + self.tag_bool_change = "stable_tag_bool%s" %self.tag_base_change + self.tag_binary_change = "stable_tag_binary%s" %self.tag_base_change + self.tag_nchar_change = "stable_tag_nchar%s" %self.tag_base_change + self.tag_float_change = "stable_tag_float%s" %self.tag_base_change + self.tag_double_change = "stable_tag_double%s" %self.tag_base_change + self.tag_ts_change = "stable_tag_ts%s" %self.tag_base_change + + tdSql.execute("ALTER TABLE db.`%s` CHANGE TAG `%s` `%s`; " %(self.stb1, self.tag_int, self.tag_int_change)) + sql = " select * from db.`%s` order by ts desc; " %self.stb1 + datacheck = self.table1_checkall(sql) + tdSql.query("describe db.`%s` ; " %self.tb1) + tdSql.checkRows(22) + tdSql.execute("ALTER TABLE db.`%s` CHANGE TAG `%s` `%s`; " %(self.stb1, self.tag_bigint, self.tag_bigint_change)) + sql = " select * from db.`%s` order by ts desc; " %self.stb1 + datacheck = self.table1_checkall(sql) + tdSql.query("describe db.`%s` ; " %self.tb1) + tdSql.checkRows(22) + tdSql.execute("ALTER TABLE db.`%s` CHANGE TAG `%s` `%s`; " %(self.stb1, self.tag_smallint, self.tag_smallint_change)) + sql = " select * from db.`%s` order by ts desc; " %self.stb1 + datacheck = self.table1_checkall(sql) + tdSql.query("describe db.`%s` ; " %self.tb1) + tdSql.checkRows(22) + tdSql.execute("ALTER TABLE db.`%s` CHANGE TAG `%s` `%s`; " %(self.stb1, self.tag_tinyint, self.tag_tinyint_change)) + sql = " select * from db.`%s` order by ts desc; " %self.stb1 + datacheck = self.table1_checkall(sql) + tdSql.query("describe db.`%s` ; " %self.tb1) + tdSql.checkRows(22) + tdSql.execute("ALTER TABLE db.`%s` CHANGE TAG `%s` `%s`; " %(self.stb1, self.tag_bool, self.tag_bool_change)) + sql = " select * from db.`%s` order by ts desc; " %self.stb1 + datacheck = self.table1_checkall(sql) + tdSql.query("describe db.`%s` ; " %self.tb1) + tdSql.checkRows(22) + tdSql.execute("ALTER TABLE db.`%s` CHANGE TAG `%s` `%s`; " %(self.stb1, self.tag_binary, self.tag_binary_change)) + sql = " select * from db.`%s` order by ts desc; " %self.stb1 + datacheck = self.table1_checkall(sql) + tdSql.query("describe db.`%s` ; " %self.tb1) + tdSql.checkRows(22) + tdSql.execute("ALTER TABLE db.`%s` CHANGE TAG `%s` `%s`; " %(self.stb1, self.tag_nchar, self.tag_nchar_change)) + sql = " select * from db.`%s` order by ts desc; " %self.stb1 + datacheck = self.table1_checkall(sql) + tdSql.query("describe db.`%s` ; " %self.tb1) + tdSql.checkRows(22) + tdSql.execute("ALTER TABLE db.`%s` CHANGE TAG `%s` `%s`; " %(self.stb1, self.tag_float, self.tag_float_change)) + sql = " select * from db.`%s` order by ts desc; " %self.stb1 + datacheck = self.table1_checkall(sql) + tdSql.query("describe db.`%s` ; " %self.tb1) + tdSql.checkRows(22) + tdSql.execute("ALTER TABLE db.`%s` CHANGE TAG `%s` `%s`; " %(self.stb1, self.tag_double, self.tag_double_change)) + sql = " select * from db.`%s` order by ts desc; " %self.stb1 + datacheck = self.table1_checkall(sql) + tdSql.query("describe db.`%s` ; " %self.tb1) + tdSql.checkRows(22) + tdSql.execute("ALTER TABLE db.`%s` CHANGE TAG `%s` `%s`; " %(self.stb1, self.tag_ts, self.tag_ts_change)) + sql = " select * from db.`%s` order by ts desc; " %self.stb1 + datacheck = self.table1_checkall(sql) + tdSql.query("describe db.`%s` ; " %self.tb1) + tdSql.checkRows(22) + + print("==============modify==============") + # TD-10810 + tdSql.execute("ALTER STABLE db.`%s` MODIFY TAG `%s` binary(30); ; " %(self.stb1, self.tag_binary_change)) + sql = " select * from db.`%s` order by ts desc; " %self.stb1 + datacheck = self.table1_checkall(sql) + tdSql.query("describe db.`%s` ; " %self.tb1) + tdSql.checkRows(22) + tdSql.execute("ALTER STABLE db.`%s` MODIFY TAG `%s` nchar(30); ; " %(self.stb1, self.tag_nchar_change)) + sql = " select * from db.`%s` order by ts desc; " %self.stb1 + datacheck = self.table1_checkall(sql) + tdSql.query("describe db.`%s` ; " %self.tb1) + tdSql.checkRows(22) + + tdSql.execute("ALTER STABLE db.`%s` MODIFY COLUMN `%s` binary(30); ; " %(self.stb1, self.col_binary)) + sql = " select * from db.`%s` order by ts desc; " %self.stb1 + datacheck = self.table1_checkall(sql) + tdSql.query("describe db.`%s` ; " %self.tb1) + tdSql.checkRows(22) + tdSql.execute("ALTER STABLE db.`%s` MODIFY COLUMN `%s` nchar(30); ; " %(self.stb1, self.col_nchar)) + sql = " select * from db.`%s` order by ts desc; " %self.stb1 + datacheck = self.table1_checkall(sql) + tdSql.query("describe db.`%s` ; " %self.tb1) + tdSql.checkRows(22) + + print("==============drop table\stable") + try: + tdSql.execute("drop table db.`%s` " %self.tb1) + except Exception as e: + tdLog.exit(e) + + tdSql.error("select * from db.`%s`" %self.tb1) + tdSql.query("show db.stables like 'stable_1%' ") + tdSql.checkRows(1) + + try: + tdSql.execute("drop table db.`%s` " %self.stb1) + except Exception as e: + tdLog.exit(e) + + tdSql.error("select * from db.`%s`" %self.tb1) + tdSql.error("select * from db.`%s`" %self.stb1) + + + print("==============step2,#create stable,table; insert table; show table; select table; drop table") + + self.stb2 = "stable_2~!@#$%^&*()-_+=[]{}';:,<.>/?stST24680~!@#$%^&*()-_+=[]{}" + self.tb2 = "table_2~!@#$%^&*()-_+=[]{}';:,<.>/?stST24680~!@#$%^&*()-_+=[]{}" + + tdSql.execute("create stable `%s` (ts timestamp, i int) tags(j int);" %self.stb2) + tdSql.query("describe `%s` ; "%self.stb2) + tdSql.checkRows(3) + + tdSql.query("select _block_dist() from `%s` ; " %self.stb2) + tdSql.checkRows(0) + + tdSql.query("show create stable `%s` ; " %self.stb2) + tdSql.checkData(0, 0, self.stb2) + tdSql.checkData(0, 1, "create table `%s` (`ts` TIMESTAMP,`i` INT) TAGS (`j` INT)" %self.stb2) + + tdSql.execute("create table `table!2` using `%s` tags(1)" %self.stb2) + tdSql.query("describe `table!2` ; ") + tdSql.checkRows(3) + + time.sleep(10) + + tdSql.query("show create table `table!2` ; ") + tdSql.checkData(0, 0, "table!2") + tdSql.checkData(0, 1, "CREATE TABLE `table!2` USING `%s` TAGS (1)" %self.stb2) + tdSql.execute("insert into `table!2` values(now, 1)") + tdSql.query("select * from `table!2`; ") + tdSql.checkRows(1) + tdSql.query("select count(*) from `table!2`; ") + tdSql.checkData(0, 0, 1) + tdSql.query("select _block_dist() from `%s` ; " %self.stb2) + tdSql.checkRows(1) + + tdSql.execute("create table `%s` using `%s` tags(1)" %(self.tb2,self.stb2)) + tdSql.query("describe `%s` ; " %self.tb2) + tdSql.checkRows(3) + tdSql.query("show create table `%s` ; " %self.tb2) + tdSql.checkData(0, 0, self.tb2) + tdSql.checkData(0, 1, "CREATE TABLE `%s` USING `%s` TAGS (1)" %(self.tb2,self.stb2)) + tdSql.execute("insert into `%s` values(now, 1)" %self.tb2) + tdSql.query("select * from `%s` ; " %self.tb2) + tdSql.checkRows(1) + tdSql.query("select count(*) from `%s`; " %self.tb2) + tdSql.checkData(0, 0, 1) + tdSql.query("select * from `%s` ; " %self.stb2) + tdSql.checkRows(2) + tdSql.query("select count(*) from `%s`; " %self.stb2) + tdSql.checkData(0, 0, 2) + + tdSql.query("select * from (select * from `%s`) ; " %self.stb2) + tdSql.checkRows(2) + tdSql.query("select count(*) from (select * from `%s` ); " %self.stb2) + tdSql.checkData(0, 0, 2) + + tdSql.query("show stables like 'stable_2%' ") + tdSql.checkRows(1) + tdSql.query("show tables like 'table%' ") + tdSql.checkRows(2) + + + #TD-10536 + self.cr_tb2 = "create_table_2~!@#$%^&*()-_+=[]{}';:,<.>/?stST24680~!@#$%^&*()-_+=[]{}" + tdSql.execute("create table `%s` as select * from `%s` ;" %(self.cr_tb2,self.stb2)) + tdSql.query("show db.tables like 'create_table_%' ") + tdSql.checkRows(1) + + print("==============drop table\stable") + try: + tdSql.execute("drop table `%s` " %self.tb2) + except Exception as e: + tdLog.exit(e) + + tdSql.error("select * from `%s`" %self.tb2) + tdSql.query("show stables like 'stable_2%' ") + tdSql.checkRows(1) + + try: + tdSql.execute("drop table `%s` " %self.stb2) + except Exception as e: + tdLog.exit(e) + + tdSql.error("select * from `%s`" %self.tb2) + tdSql.error("select * from `%s`" %self.stb2) + + + print("==============step3,#create regular_table; insert regular_table; show regular_table; select regular_table; drop regular_table") + self.regular_table = "regular_table~!@#$%^&*()-_+=[]{}';:,<.>/?stST24680~!@#$%^&*()-_+=[]{}" + + self.regular_col_base = "123@#$%^&*()-_+=[]{};:,<.>/?~!$%^" + + self.col_int = "regular_table_col_int%s" %self.regular_col_base + print(self.col_int) + self.col_bigint = "regular_table_col_bigint%s" %self.regular_col_base + self.col_smallint = "regular_table_col_smallint%s" %self.regular_col_base + self.col_tinyint = "regular_table_col_tinyint%s" %self.regular_col_base + self.col_bool = "regular_table_col_bool%s" %self.regular_col_base + self.col_binary = "regular_table_col_binary%s" %self.regular_col_base + self.col_nchar = "regular_table_col_nchar%s" %self.regular_col_base + self.col_float = "regular_table_col_float%s" %self.regular_col_base + self.col_double = "regular_table_col_double%s" %self.regular_col_base + self.col_ts = "regular_table_col_ts%s" %self.regular_col_base + + tdSql.execute("create table `%s` (ts timestamp,`%s` int , `%s` bigint , `%s` smallint , `%s` tinyint, `%s` bool , \ + `%s` binary(20) , `%s` nchar(20) ,`%s` float , `%s` double , `%s` timestamp) ;"\ + %(self.regular_table, self.col_int, self.col_bigint, self.col_smallint, self.col_tinyint, self.col_bool, + self.col_binary, self.col_nchar, self.col_float, self.col_double, self.col_ts)) + tdSql.query("describe `%s` ; "%self.regular_table) + tdSql.checkRows(11) + + tdSql.query("select _block_dist() from `%s` ; " %self.regular_table) + tdSql.checkRows(1) + + tdSql.query("show create table `%s` ; " %self.regular_table) + tdSql.checkData(0, 0, self.regular_table) + tdSql.checkData(0, 1, "create table `%s` (`ts` TIMESTAMP,`%s` INT,`%s` BIGINT,`%s` SMALLINT,`%s` TINYINT,`%s` BOOL,`%s` BINARY(20),`%s` NCHAR(20),`%s` FLOAT,`%s` DOUBLE,`%s` TIMESTAMP)" + %(self.regular_table, self.col_int, self.col_bigint, self.col_smallint, self.col_tinyint, self.col_bool, + self.col_binary, self.col_nchar, self.col_float, self.col_double, self.col_ts)) + + tdSql.execute("insert into `%s` values(now, 1 , 2, 3, 4, 5, 6 ,7 ,8 ,9 ,10)" %self.regular_table) + sql = "select * from `%s` ; " %self.regular_table + datacheck = self.table1_checkall(sql) + tdSql.checkRows(1) + sql = '''select ts ,`%s`,`%s`,`%s`,`%s`,`%s`,`%s`,`%s`,`%s`,`%s`,`%s` from db2.`%s`; '''\ + %(self.col_int, self.col_bigint, self.col_smallint, self.col_tinyint, self.col_bool, self.col_binary, self.col_nchar, self.col_float, self.col_double, self.col_ts, self.regular_table) + datacheck = self.table1_checkall(sql) + tdSql.checkRows(1) + + time.sleep(1) + tdSql.execute('''insert into db2.`%s` (ts ,`%s`,`%s`,`%s`,`%s`,`%s`,`%s`,`%s`,`%s`,`%s`,`%s`) values(now, 1 , 2, 3, 4, 5, 6 ,7 ,8 ,9 ,10)'''\ + %(self.regular_table, self.col_int, self.col_bigint, self.col_smallint, self.col_tinyint, self.col_bool, self.col_binary, self.col_nchar, self.col_float, self.col_double, self.col_ts) ) + sql = " select * from db2.`%s`; " %self.regular_table + datacheck = self.table1_checkall(sql) + tdSql.checkRows(2) + + sql = " select * from db2.`%s` where `%s`=1 and `%s`=2 and `%s`=3 and `%s`=4 and `%s`='True' and `%s`=6 and `%s`=7 and `%s`=8 and `%s`=9 and `%s`=10; " \ + %(self.regular_table, self.col_int, self.col_bigint, self.col_smallint, self.col_tinyint, self.col_bool, self.col_binary, self.col_nchar, self.col_float, self.col_double, self.col_ts) + datacheck = self.table1_checkall(sql) + tdSql.checkRows(2) + + tdSql.query("select count(*) from `%s`; " %self.regular_table) + tdSql.checkData(0, 0, 2) + tdSql.query("select _block_dist() from `%s` ; " %self.regular_table) + tdSql.checkRows(1) + + sql = "select * from (select * from `%s`) ; " %self.regular_table + datacheck = self.table1_checkall(sql) + tdSql.checkRows(2) + + sql = "select ts ,`%s`,`%s`,`%s`,`%s`,`%s`,`%s`,`%s`,`%s`,`%s`,`%s` from (select ts ,`%s`,`%s`,`%s`,`%s`,`%s`,`%s`,`%s`,`%s`,`%s`,`%s` from db2.`%s`\ + where `%s`=1 and `%s`=2 and `%s`=3 and `%s`=4 and `%s`='True' and `%s`=6 and `%s`=7 and `%s`=8 and `%s`=9 and `%s`=10 ) ; " \ + %(self.col_int, self.col_bigint, self.col_smallint, self.col_tinyint, self.col_bool, self.col_binary, self.col_nchar, self.col_float, self.col_double, self.col_ts,\ + self.col_int, self.col_bigint, self.col_smallint, self.col_tinyint, self.col_bool, self.col_binary, self.col_nchar, self.col_float, self.col_double, self.col_ts, self.regular_table, \ + self.col_int, self.col_bigint, self.col_smallint, self.col_tinyint, self.col_bool, self.col_binary, self.col_nchar, self.col_float, self.col_double, self.col_ts) + datacheck = self.table1_checkall(sql) + tdSql.checkRows(2) + + tdSql.query("select count(*) from (select * from `%s` ); " %self.regular_table) + tdSql.checkData(0, 0, 2) + + tdSql.query("show tables like 'regular_table%' ") + tdSql.checkRows(1) + + self.crr_tb = "create_r_table~!@#$%^&*()-_+=[]{}';:,<.>/?stST24680~!@#$%^&*()-_+=[]{}" + tdSql.execute("create table `%s` as select * from `%s` ;" %(self.crr_tb,self.regular_table)) + tdSql.query("show db2.tables like 'create_r_table%' ") + tdSql.checkRows(1) + + + print("==============drop\ add\ change\ modify column ") + print("==============drop==============") + tdSql.execute("ALTER TABLE db2.`%s` DROP COLUMN `%s`; " %(self.regular_table, self.col_ts)) + sql = " select * from db2.`%s`; " %self.regular_table + datacheck = self.table1_checkall_9(sql) + tdSql.query("describe db2.`%s` ; " %self.regular_table) + tdSql.checkRows(10) + tdSql.execute("ALTER TABLE `%s` DROP COLUMN `%s`; " %(self.regular_table, self.col_double)) + sql = " select * from `%s`; " %self.regular_table + datacheck = self.table1_checkall_8(sql) + tdSql.query("describe `%s` ; " %self.regular_table) + tdSql.checkRows(9) + tdSql.execute("ALTER TABLE db2.`%s` DROP COLUMN `%s`; " %(self.regular_table, self.col_float)) + sql = " select * from db2.`%s`; " %self.regular_table + datacheck = self.table1_checkall_7(sql) + tdSql.query("describe db2.`%s` ; " %self.regular_table) + tdSql.checkRows(8) + tdSql.execute("ALTER TABLE `%s` DROP COLUMN `%s`; " %(self.regular_table, self.col_nchar)) + sql = " select * from `%s`; " %self.regular_table + datacheck = self.table1_checkall_6(sql) + tdSql.query("describe `%s` ; " %self.regular_table) + tdSql.checkRows(7) + tdSql.execute("ALTER TABLE db2.`%s` DROP COLUMN `%s`; " %(self.regular_table, self.col_binary)) + sql = " select * from db2.`%s`; " %self.regular_table + datacheck = self.table1_checkall_5(sql) + tdSql.query("describe db2.`%s` ; " %self.regular_table) + tdSql.checkRows(6) + tdSql.execute("ALTER TABLE `%s` DROP COLUMN `%s`; " %(self.regular_table, self.col_bool)) + sql = " select * from `%s`; " %self.regular_table + datacheck = self.table1_checkall_4(sql) + tdSql.query("describe `%s` ; " %self.regular_table) + tdSql.checkRows(5) + tdSql.execute("ALTER TABLE db2.`%s` DROP COLUMN `%s`; " %(self.regular_table, self.col_tinyint)) + sql = " select * from db2.`%s`; " %self.regular_table + datacheck = self.table1_checkall_3(sql) + tdSql.query("describe db2.`%s` ; " %self.regular_table) + tdSql.checkRows(4) + tdSql.execute("ALTER TABLE `%s` DROP COLUMN `%s`; " %(self.regular_table, self.col_smallint)) + sql = " select * from `%s`; " %self.regular_table + datacheck = self.table1_checkall_2(sql) + tdSql.query("describe `%s` ; " %self.regular_table) + tdSql.checkRows(3) + tdSql.execute("ALTER TABLE db2.`%s` DROP COLUMN `%s`; " %(self.regular_table, self.col_bigint)) + sql = " select * from db2.`%s`; " %self.regular_table + datacheck = self.table1_checkall_1(sql) + tdSql.query("describe db2.`%s` ; " %self.regular_table) + tdSql.checkRows(2) + tdSql.error("ALTER TABLE db2.`%s` DROP COLUMN `%s`; " %(self.regular_table, self.col_int)) + tdSql.query("describe `%s` ; " %self.regular_table) + tdSql.checkRows(2) + + print("==============add==============") + tdSql.execute("ALTER TABLE db2.`%s` ADD COLUMN `%s` bigint; " %(self.regular_table, self.col_bigint)) + tdSql.query("describe db2.`%s` ; " %self.regular_table) + tdSql.checkRows(3) + tdSql.execute("ALTER TABLE db2.`%s` ADD COLUMN `%s` smallint; " %(self.regular_table, self.col_smallint)) + tdSql.query("describe db2.`%s` ; " %self.regular_table) + tdSql.checkRows(4) + tdSql.execute("ALTER TABLE db2.`%s` ADD COLUMN `%s` tinyint; " %(self.regular_table, self.col_tinyint)) + tdSql.query("describe db2.`%s` ; " %self.regular_table) + tdSql.checkRows(5) + tdSql.execute("ALTER TABLE db2.`%s` ADD COLUMN `%s` bool; " %(self.regular_table, self.col_bool)) + tdSql.query("describe db2.`%s` ; " %self.regular_table) + tdSql.checkRows(6) + tdSql.execute("ALTER TABLE db2.`%s` ADD COLUMN `%s` binary(20); " %(self.regular_table, self.col_binary)) + tdSql.query("describe db2.`%s` ; " %self.regular_table) + tdSql.checkRows(7) + + tdSql.execute("insert into db2.`%s` values(now, 1 , 2, 3, 4, 5, 6)" %self.regular_table) + sql = "select * from db2.`%s` order by ts desc; " %self.regular_table + datacheck = self.table1_checkall_5(sql) + + tdSql.execute("ALTER TABLE db2.`%s` ADD COLUMN `%s` nchar(20); " %(self.regular_table, self.col_nchar)) + tdSql.query("describe db2.`%s` ; " %self.regular_table) + tdSql.checkRows(8) + tdSql.execute("ALTER TABLE db2.`%s` ADD COLUMN `%s` float; " %(self.regular_table, self.col_float)) + tdSql.query("describe db2.`%s` ; " %self.regular_table) + tdSql.checkRows(9) + tdSql.execute("ALTER TABLE db2.`%s` ADD COLUMN `%s` double; " %(self.regular_table, self.col_double)) + tdSql.query("describe db2.`%s` ; " %self.regular_table) + tdSql.checkRows(10) + tdSql.execute("ALTER TABLE db2.`%s` ADD COLUMN `%s` timestamp; " %(self.regular_table, self.col_ts)) + tdSql.query("describe db2.`%s` ; " %self.regular_table) + tdSql.checkRows(11) + + tdSql.execute("insert into db2.`%s` values(now, 1 , 2, 3, 4, 5, 6 ,7 ,8 ,9 ,10)" %self.regular_table) + sql = "select * from db2.`%s` order by ts desc; " %self.regular_table + datacheck = self.table1_checkall(sql) + + + print("==============change, regular not support==============") + + + print("==============modify==============") + # TD-10810 + tdSql.execute("ALTER TABLE db2.`%s` MODIFY COLUMN `%s` binary(30); ; " %(self.regular_table, self.col_binary)) + sql = " select * from db2.`%s` order by ts desc; " %self.regular_table + datacheck = self.table1_checkall(sql) + tdSql.query("describe db2.`%s` ; " %self.regular_table) + tdSql.checkRows(11) + tdSql.execute("ALTER TABLE `%s` MODIFY COLUMN `%s` nchar(30); ; " %(self.regular_table, self.col_nchar)) + sql = " select * from `%s` order by ts desc; " %self.regular_table + datacheck = self.table1_checkall(sql) + tdSql.query("describe `%s` ; " %self.regular_table) + tdSql.checkRows(11) + + + print("==============drop table\stable") + try: + tdSql.execute("drop table `%s` " %self.regular_table) + except Exception as e: + tdLog.exit(e) + + tdSql.error("select * from `%s`" %self.regular_table) + + + def stop(self): + tdSql.close() + tdLog.success("%s successfully executed" % __file__) + + +tdCases.addWindows(__file__, TDTestCase()) +tdCases.addLinux(__file__, TDTestCase()) diff --git a/tests/system-test/0-management/2-table/.gitkeep b/tests/system-test/0-management/2-table/.gitkeep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/tests/system-test/0-management/3-tag/.gitkeep b/tests/system-test/0-management/3-tag/.gitkeep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/tests/system-test/0-management/4-others/.gitkeep b/tests/system-test/0-management/4-others/.gitkeep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/tests/system-test/1-insert/0-sql/.gitkeep b/tests/system-test/1-insert/0-sql/.gitkeep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/tests/system-test/1-insert/0-sql/basic.py b/tests/system-test/1-insert/0-sql/basic.py new file mode 100644 index 0000000000000000000000000000000000000000..23e93d6e05fe78959e58a0a44308e4e1b2dafd4b --- /dev/null +++ b/tests/system-test/1-insert/0-sql/basic.py @@ -0,0 +1,67 @@ +################################################################### +# Copyright (c) 2016 by TAOS Technologies, Inc. +# All rights reserved. +# +# This file is proprietary and confidential to TAOS Technologies. +# No part of this file may be reproduced, stored, transmitted, +# disclosed or used in any form or by any means other than as +# expressly provided by the written permission from Jianhui Tao +# +################################################################### + +# -*- coding: utf-8 -*- + +import sys +from util.log import * +from util.cases import * +from util.sql import * + + +class TDTestCase: + def caseDescription(self): + ''' + case1: insert 倒序插入 + case2: 语法解析错误同时meta请求也发出去了导致callback中处理逻辑失效 + case3: [TD-XXXX]insert语句在values之间加入多个逗号 + ''' + return + def init(self, conn, logSql): + tdLog.debug("start to execute %s" % __file__) + tdSql.init(conn.cursor(), logSql) + + def run(self): + tdSql.prepare() + + ret = tdSql.execute('create table tb (ts timestamp, speed int)') + + insertRows = 10 + tdLog.info("insert %d rows" % (insertRows)) + for i in range(0, insertRows): + ret = tdSql.execute( + 'insert into tb values (now + %dm, %d)' % + (i, i)) + + tdLog.info("insert earlier data") + tdSql.execute('insert into tb values (now - 5m , 10)') + tdSql.execute('insert into tb values (now - 6m , 10)') + tdSql.execute('insert into tb values (now - 7m , 10)') + tdSql.execute('insert into tb values (now - 8m , 10)') + + tdSql.query("select * from tb") + tdSql.checkRows(insertRows + 4) + + # 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() + tdLog.success("%s successfully executed" % __file__) + + +tdCases.addWindows(__file__, TDTestCase()) +tdCases.addLinux(__file__, TDTestCase()) diff --git a/tests/system-test/1-insert/1-stmt/.gitkeep b/tests/system-test/1-insert/1-stmt/.gitkeep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/tests/system-test/1-insert/2-schemaless/json/.gitkeep b/tests/system-test/1-insert/2-schemaless/json/.gitkeep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/tests/system-test/1-insert/2-schemaless/line/.gitkeep b/tests/system-test/1-insert/2-schemaless/line/.gitkeep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/tests/system-test/1-insert/2-schemaless/telnet/.gitkeep b/tests/system-test/1-insert/2-schemaless/telnet/.gitkeep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/tests/system-test/2-query/0-aggregate/.gitkeep b/tests/system-test/2-query/0-aggregate/.gitkeep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/tests/system-test/2-query/1-select/.gitkeep b/tests/system-test/2-query/1-select/.gitkeep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/tests/system-test/2-query/2-compute/.gitkeep b/tests/system-test/2-query/2-compute/.gitkeep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/tests/system-test/2-query/3-join/.gitkeep b/tests/system-test/2-query/3-join/.gitkeep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/tests/system-test/2-query/4-union/.gitkeep b/tests/system-test/2-query/4-union/.gitkeep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/tests/system-test/2-query/5-session/.gitkeep b/tests/system-test/2-query/5-session/.gitkeep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/tests/system-test/2-query/6-state_window/.gitkeep b/tests/system-test/2-query/6-state_window/.gitkeep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/tests/system-test/2-query/7-nest/.gitkeep b/tests/system-test/2-query/7-nest/.gitkeep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/tests/system-test/2-query/8-udf/.gitkeep b/tests/system-test/2-query/8-udf/.gitkeep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/tests/system-test/2-query/9-others/.gitkeep b/tests/system-test/2-query/9-others/.gitkeep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/tests/system-test/3-connectors/c#/.gitkeep b/tests/system-test/3-connectors/c#/.gitkeep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/tests/system-test/3-connectors/go/.gitkeep b/tests/system-test/3-connectors/go/.gitkeep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/tests/system-test/3-connectors/java/.gitkeep b/tests/system-test/3-connectors/java/.gitkeep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/tests/system-test/3-connectors/nodejs/.gitkeep b/tests/system-test/3-connectors/nodejs/.gitkeep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/tests/system-test/3-connectors/restful/.gitkeep b/tests/system-test/3-connectors/restful/.gitkeep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/tests/system-test/3-connectors/rust/.gitkeep b/tests/system-test/3-connectors/rust/.gitkeep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/tests/system-test/4-taosAdapter/.gitkeep b/tests/system-test/4-taosAdapter/.gitkeep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/tests/system-test/5-taos-tools/taosbenchmark/.gitkeep b/tests/system-test/5-taos-tools/taosbenchmark/.gitkeep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/tests/system-test/5-taos-tools/taosdump/.gitkeep b/tests/system-test/5-taos-tools/taosdump/.gitkeep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/tests/system-test/6-cluster/.gitkeep b/tests/system-test/6-cluster/.gitkeep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/tests/system-test/7-customer/.gitkeep b/tests/system-test/7-customer/.gitkeep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/tests/system-test/fulltest.sh b/tests/system-test/fulltest.sh new file mode 100755 index 0000000000000000000000000000000000000000..5040747d3ae4a21ec8fda32793bf06dae98e09e2 --- /dev/null +++ b/tests/system-test/fulltest.sh @@ -0,0 +1,2 @@ +python3 test.py -f 1-insert/0-sql/basic.py +python3 test.py -f 0-management/1-stable/create_col_tag.py \ No newline at end of file diff --git a/tests/system-test/test.py b/tests/system-test/test.py new file mode 100644 index 0000000000000000000000000000000000000000..b39b95c9030e14a2442883991cadb7d21e5e7a5d --- /dev/null +++ b/tests/system-test/test.py @@ -0,0 +1,198 @@ +#!/usr/bin/python +################################################################### +# 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 +# +################################################################### +# install pip +# pip install src/connector/python/ + +# -*- coding: utf-8 -*- +import sys +import getopt +import subprocess +import time +from distutils.log import warn as printf +from fabric2 import Connection +sys.path.append("../pytest") +from util.log import * +from util.dnodes import * +from util.cases import * + +import taos + + +if __name__ == "__main__": + + fileName = "all" + deployPath = "" + masterIp = "" + testCluster = False + valgrind = 0 + logSql = True + stop = 0 + restart = False + windows = 0 + opts, args = getopt.gnu_getopt(sys.argv[1:], 'f:p:m:l:scghrw', [ + 'file=', 'path=', 'master', 'logSql', 'stop', 'cluster', 'valgrind', 'help', 'windows']) + for key, value in opts: + if key in ['-h', '--help']: + tdLog.printNoPrefix( + 'A collection of test cases written using Python') + tdLog.printNoPrefix('-f Name of test case file written by Python') + tdLog.printNoPrefix('-p Deploy Path for Simulator') + tdLog.printNoPrefix('-m Master Ip for Simulator') + tdLog.printNoPrefix('-l logSql Flag') + tdLog.printNoPrefix('-s stop All dnodes') + tdLog.printNoPrefix('-c Test Cluster Flag') + tdLog.printNoPrefix('-g valgrind Test Flag') + tdLog.printNoPrefix('-r taosd restart test') + tdLog.printNoPrefix('-w taos on windows') + sys.exit(0) + + if key in ['-r', '--restart']: + restart = True + + if key in ['-f', '--file']: + fileName = value + + if key in ['-p', '--path']: + deployPath = value + + if key in ['-m', '--master']: + masterIp = value + + if key in ['-l', '--logSql']: + if (value.upper() == "TRUE"): + logSql = True + elif (value.upper() == "FALSE"): + logSql = False + else: + tdLog.printNoPrefix("logSql value %s is invalid" % logSql) + sys.exit(0) + + if key in ['-c', '--cluster']: + testCluster = True + + if key in ['-g', '--valgrind']: + valgrind = 1 + + if key in ['-s', '--stop']: + stop = 1 + + if key in ['-w', '--windows']: + windows = 1 + + if (stop != 0): + if (valgrind == 0): + toBeKilled = "taosd" + else: + toBeKilled = "valgrind.bin" + + killCmd = "ps -ef|grep -w %s| grep -v grep | awk '{print $2}' | xargs kill -TERM > /dev/null 2>&1" % toBeKilled + + psCmd = "ps -ef|grep -w %s| grep -v grep | awk '{print $2}'" % toBeKilled + processID = subprocess.check_output(psCmd, shell=True) + + while(processID): + os.system(killCmd) + time.sleep(1) + processID = subprocess.check_output(psCmd, shell=True) + + for port in range(6030, 6041): + usePortPID = "lsof -i tcp:%d | grep LISTEn | awk '{print $2}'" % port + processID = subprocess.check_output(usePortPID, shell=True) + + if processID: + killCmd = "kill -TERM %s" % processID + os.system(killCmd) + fuserCmd = "fuser -k -n tcp %d" % port + os.system(fuserCmd) + if valgrind: + time.sleep(2) + + tdLog.info('stop All dnodes') + + if masterIp == "": + host = '127.0.0.1' + else: + host = masterIp + + tdLog.info("Procedures for tdengine deployed in %s" % (host)) + if windows: + tdCases.logSql(logSql) + tdLog.info("Procedures for testing self-deployment") + td_clinet = TDSimClient("C:\\TDengine") + td_clinet.deploy() + remote_conn = Connection("root@%s"%host) + with remote_conn.cd('/var/lib/jenkins/workspace/TDinternal/community/tests/pytest'): + remote_conn.run("python3 ./test.py") + conn = taos.connect( + host="%s"%(host), + config=td_clinet.cfgDir) + tdCases.runOneWindows(conn, fileName) + else: + tdDnodes.init(deployPath) + tdDnodes.setTestCluster(testCluster) + tdDnodes.setValgrind(valgrind) + tdDnodes.stopAll() + is_test_framework = 0 + key_word = 'tdCases.addLinux' + try: + if key_word in open(fileName).read(): + is_test_framework = 1 + except: + pass + if is_test_framework: + moduleName = fileName.replace(".py", "").replace("/", ".") + uModule = importlib.import_module(moduleName) + try: + ucase = uModule.TDTestCase() + tdDnodes.deploy(1,ucase.updatecfgDict) + except : + tdDnodes.deploy(1,{}) + else: + pass + tdDnodes.deploy(1,{}) + tdDnodes.start(1) + + + + tdCases.logSql(logSql) + + if testCluster: + tdLog.info("Procedures for testing cluster") + if fileName == "all": + tdCases.runAllCluster() + else: + tdCases.runOneCluster(fileName) + else: + tdLog.info("Procedures for testing self-deployment") + conn = taos.connect( + host, + config=tdDnodes.getSimCfgPath()) + if fileName == "all": + tdCases.runAllLinux(conn) + else: + tdCases.runOneWindows(conn, fileName) + if restart: + if fileName == "all": + tdLog.info("not need to query ") + else: + sp = fileName.rsplit(".", 1) + if len(sp) == 2 and sp[1] == "py": + tdDnodes.stopAll() + tdDnodes.start(1) + time.sleep(1) + conn = taos.connect( host, config=tdDnodes.getSimCfgPath()) + tdLog.info("Procedures for tdengine deployed in %s" % (host)) + tdLog.info("query test after taosd restart") + tdCases.runOneLinux(conn, sp[0] + "_" + "restart.py") + else: + tdLog.info("not need to query") + conn.close() diff --git a/tests/test-all.sh b/tests/test-all.sh index 266dac85b0eddde932dd8e71d660dc16d9437904..bfd2b04f027084d348f65a2d858427c3389c0774 100755 --- a/tests/test-all.sh +++ b/tests/test-all.sh @@ -158,7 +158,13 @@ function runPyCaseOneByOne { } function runPyCaseOneByOnefq() { - cd $tests_dir/pytest + if [[ $3 =~ system ]] ; then + cd $tests_dir/system-test + elif [[ $3 =~ develop ]] ; then + cd $tests_dir/develop-test + else + cd $tests_dir/pytest + fi if [[ $1 =~ full ]] ; then start=1 end=`sed -n '$=' fulltest.sh` @@ -361,6 +367,12 @@ if [ "$2" != "sim" ] && [ "$2" != "jdbc" ] && [ "$2" != "unit" ] && [ "$2" != " elif [ "$1" == "p4" ]; then echo "### run Python_4 test ###" runPyCaseOneByOnefq p4 1 + elif [ "$1" == "system-test" ]; then + echo "### run system-test test ###" + runPyCaseOneByOnefq full 1 system + elif [ "$1" == "develop-test" ]; then + echo "### run develop-test test ###" + runPyCaseOneByOnefq full 1 develop elif [ "$1" == "b2" ] || [ "$1" == "b3" ]; then exit $(($totalFailed + $totalPyFailed)) elif [ "$1" == "smoke" ] || [ -z "$1" ]; then