diff --git a/Jenkinsfile b/Jenkinsfile index d4ecce0bd96e3d32a0bd3951e7543b3547bc97e1..d606479006c50afc976361208175762899c87e5e 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 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/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 e937ea8fde3f889b2c47fbc30aa40710764c8b69..2a67c65c16ea11873e65c87fb6d059ac82dfc9ec 100644 --- a/documentation20/en/08.connector/docs.md +++ b/documentation20/en/08.connector/docs.md @@ -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/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/tools/install.sh b/packaging/tools/install.sh index 555a476558861132deccbc3673b7d8e96df70804..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 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/makepkg.sh b/packaging/tools/makepkg.sh index fdeff01fd8ae7c5f176cd8efe4c8c42202f0d166..89bbbf9370e545d10aa8c8f9a4b16e0319693e30 100755 --- a/packaging/tools/makepkg.sh +++ b/packaging/tools/makepkg.sh @@ -57,6 +57,7 @@ else ${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" @@ -129,7 +130,7 @@ if [ -n "${taostools_bin_files}" ]; then 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 \ + && 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" @@ -295,7 +296,7 @@ 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 !!!" @@ -303,7 +304,7 @@ if [ "$exitcode" != "0" ]; then fi if [ -n "${taostools_bin_files}" ]; then - tar -zcv -f "$(basename ${taostools_pkg_name}).tar.gz" $(basename ${taostools_install_dir}) --remove-files || : + 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 !!!" 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..de3b7a4b3da6971b2c84bcaaaee2478787fc15cc 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); 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/tscSQLParser.c b/src/client/src/tscSQLParser.c index 92ee99f548821fae73b4d420c403a6f318055b69..e1be3bf6a95a26d7b96d803b86d8a5a4f14d829e 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -7948,6 +7948,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; @@ -7995,6 +7996,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 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/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/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 446c03da6df8fe6675c6aba14b1d0766b56e1f08..78519c0c90a261b6a559c6bbe7f3d3b5a7b630b4 160000 --- a/src/kit/taos-tools +++ b/src/kit/taos-tools @@ -1 +1 @@ -Subproject commit 446c03da6df8fe6675c6aba14b1d0766b56e1f08 +Subproject commit 78519c0c90a261b6a559c6bbe7f3d3b5a7b630b4 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/plugins/taosadapter b/src/plugins/taosadapter index 88346a2e4e2e9282d2ec8b8c5264ca1ec23698a1..f108f5240918d0eec90debd1ff469c98ff0f25ac 160000 --- a/src/plugins/taosadapter +++ b/src/plugins/taosadapter @@ -1 +1 @@ -Subproject commit 88346a2e4e2e9282d2ec8b8c5264ca1ec23698a1 +Subproject commit f108f5240918d0eec90debd1ff469c98ff0f25ac 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/tests/develop-test/1-insert/0-sql/basic.py b/tests/develop-test/1-insert/0-sql/basic.py index 72daad7bcae66aec879cb30cde8c786e3e6d14c2..86872eeaa20ce6c8f473342da3da1f17f19bc8cc 100644 --- a/tests/develop-test/1-insert/0-sql/basic.py +++ b/tests/develop-test/1-insert/0-sql/basic.py @@ -18,6 +18,14 @@ from util.sql import * class TDTestCase: + def caseDescription(self): + ''' + insert 倒序插入 + 语法解析错误同时meta请求也发出去了导致callback中处理逻辑失效 + insert语句在values之间加入多个逗号 + ''' + return + def init(self, conn, logSql): tdLog.debug("start to execute %s" % __file__) tdSql.init(conn.cursor(), logSql) diff --git a/tests/develop-test/6-feature/.gitkeep b/tests/develop-test/6-cluster/.gitkeep similarity index 100% rename from tests/develop-test/6-feature/.gitkeep rename to tests/develop-test/6-cluster/.gitkeep diff --git a/tests/develop-test/7-cluster/.gitkeep b/tests/develop-test/7-customer/.gitkeep similarity index 100% rename from tests/develop-test/7-cluster/.gitkeep rename to tests/develop-test/7-customer/.gitkeep 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/fulltest.sh b/tests/pytest/fulltest.sh index d24f30248c8e75d1fa1f499fb812e6fcdf7412a9..47e535cbd81b9cbc9675493342c1b734ccbeeca2 100755 --- a/tests/pytest/fulltest.sh +++ b/tests/pytest/fulltest.sh @@ -45,12 +45,13 @@ 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 -#python3 test.py -f tools/taosdemoAllTest/taosdemoTestInsertWithJsonStmt.py +python3 test.py -f tools/taosdemoAllTest/taosdemoTestInsertWithJsonStmt.py # tag python3 ./test.py -f tag_lite/filter.py @@ -165,13 +166,13 @@ python3 ./test.py -f update/merge_commit_data.py python3 test.py -f tools/taosdumpTest.py python3 test.py -f tools/taosdumpTest2.py -#python3 test.py -f tools/taosdemoTest.py -#python3 test.py -f tools/taosdemoTestWithoutMetric.py -#python3 test.py -f tools/taosdemoTestWithJson.py -#python3 test.py -f tools/taosdemoTestLimitOffset.py -#python3 test.py -f tools/taosdemoTestTblAlt.py -#python3 test.py -f tools/taosdemoTestSampleData.py -#python3 test.py -f tools/taosdemoTestInterlace.py +python3 test.py -f tools/taosdemoTest.py +python3 test.py -f tools/taosdemoTestWithoutMetric.py +python3 test.py -f tools/taosdemoTestWithJson.py +python3 test.py -f tools/taosdemoTestLimitOffset.py +python3 test.py -f tools/taosdemoTestTblAlt.py +python3 test.py -f tools/taosdemoTestSampleData.py +python3 test.py -f tools/taosdemoTestInterlace.py # python3 test.py -f tools/taosdemoTestQuery.py # restful test for python @@ -179,10 +180,10 @@ python3 test.py -f tools/taosdumpTest2.py # python3 test.py -f restful/restful_bind_db2.py # nano support -# python3 test.py -f tools/taosdemoAllTest/NanoTestCase/taosdemoTestSupportNanoInsert.py -#python3 test.py -f tools/taosdemoAllTest/NanoTestCase/taosdemoTestSupportNanoQuery.py -#python3 test.py -f tools/taosdemoAllTest/NanoTestCase/taosdemoTestSupportNanosubscribe.py -#python3 test.py -f tools/taosdemoAllTest/NanoTestCase/taosdemoTestInsertTime_step.py +python3 test.py -f tools/taosdemoAllTest/NanoTestCase/taosdemoTestSupportNanoInsert.py +python3 test.py -f tools/taosdemoAllTest/NanoTestCase/taosdemoTestSupportNanoQuery.py +python3 test.py -f tools/taosdemoAllTest/NanoTestCase/taosdemoTestSupportNanosubscribe.py +python3 test.py -f tools/taosdemoAllTest/NanoTestCase/taosdemoTestInsertTime_step.py python3 test.py -f tools/taosdumpTestNanoSupport.py # @@ -219,9 +220,9 @@ python3 ./test.py -f perfbenchmark/bug3433.py #python3 ./test.py -f perfbenchmark/taosdemoInsert.py #taosdemo -#python3 test.py -f tools/taosdemoAllTest/taosdemoTestInsertWithJson.py -#python3 test.py -f tools/taosdemoAllTest/taosdemoTestQueryWithJson.py -#python3 test.py -f tools/taosdemoAllTest/taosdemoTestInsertAllType.py +python3 test.py -f tools/taosdemoAllTest/taosdemoTestInsertWithJson.py +python3 test.py -f tools/taosdemoAllTest/taosdemoTestQueryWithJson.py +python3 test.py -f tools/taosdemoAllTest/taosdemoTestInsertAllType.py #query python3 test.py -f query/distinctOneColTb.py @@ -394,9 +395,9 @@ python3 ./test.py -f insert/insert_locking.py python3 ./test.py -f alter/alter_debugFlag.py python3 ./test.py -f query/queryBetweenAnd.py 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-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 tag_lite/drop_auto_create.py python3 test.py -f insert/insert_before_use_db.py @@ -420,10 +421,11 @@ 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 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/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/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/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/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/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/taosdemoTestInsertTime_step.py b/tests/pytest/tools/taosdemoAllTest/taosdemoTestInsertTime_step.py deleted file mode 100644 index fd9ee695489dc5fb9d98480e0a81ec5abe275281..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("%staosBenchmark -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("%staosBenchmark -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("%staosBenchmark -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/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/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/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/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/1-insert/0-sql/basic.py b/tests/system-test/1-insert/0-sql/basic.py index 72daad7bcae66aec879cb30cde8c786e3e6d14c2..cddbc3dc9e9b49d0316105eff09c9684bcfd040d 100644 --- a/tests/system-test/1-insert/0-sql/basic.py +++ b/tests/system-test/1-insert/0-sql/basic.py @@ -18,6 +18,13 @@ from util.sql import * class TDTestCase: + def caseDescription(self): + ''' + insert 倒序插入 + 语法解析错误同时meta请求也发出去了导致callback中处理逻辑失效 + insert语句在values之间加入多个逗号 + ''' + return def init(self, conn, logSql): tdLog.debug("start to execute %s" % __file__) tdSql.init(conn.cursor(), logSql) diff --git a/tests/system-test/6-feature/.gitkeep b/tests/system-test/6-cluster/.gitkeep similarity index 100% rename from tests/system-test/6-feature/.gitkeep rename to tests/system-test/6-cluster/.gitkeep diff --git a/tests/system-test/7-cluster/.gitkeep b/tests/system-test/7-customer/.gitkeep similarity index 100% rename from tests/system-test/7-cluster/.gitkeep rename to tests/system-test/7-customer/.gitkeep